@@ -144,6 +144,7 @@ class SignedXml {
144144 String ? keyInfo;
145145 final idAttributes = ['Id' , 'ID' , 'id' ];
146146 late List <String > implicitTransforms;
147+ final customSignatureChilds = < String > [];
147148
148149 /// Xml signature implementation
149150 ///
@@ -596,6 +597,10 @@ class SignedXml {
596597 isEmptyUri));
597598 }
598599
600+ void addCustomSignatureChild (String node) {
601+ customSignatureChilds.add (node);
602+ }
603+
599604 /// Compute the signature of the given xml (using the already defined settings)
600605 ///
601606 /// Options:
@@ -670,6 +675,7 @@ class SignedXml {
670675 StringBuffer ('<${currentPrefix }Signature ${signatureAttrs .join (' ' )}>' )
671676 ..write (_createSignedInfo (doc, prefix))
672677 ..write (_getKeyInfo (prefix))
678+ ..write (customSignatureChilds.join ('' ))
673679 ..write ('</${currentPrefix }Signature>' );
674680
675681 _originalXmlWithIds = doc.toString ();
@@ -801,8 +807,18 @@ class SignedXml {
801807 for (final ref in references) {
802808 final nodes = XmlXPath .node (doc).query (ref.xpath ?? '' );
803809 if (nodes.nodes.isEmpty) {
804- throw ArgumentError (
805- 'the following xpath cannot be signed because it was not found: ${ref .xpath }' );
810+ //Search if the xpath is in customSignatureChilds
811+ for (final customSignatureChild in customSignatureChilds) {
812+ final customSignatureChildXml = parseFromString (customSignatureChild);
813+ final customSignatureChildQuery = XmlXPath .node (customSignatureChildXml).query (ref.xpath ?? '' );
814+ if (customSignatureChildQuery.nodes.isNotEmpty) {
815+ nodes.nodes.add (customSignatureChildQuery.node! );
816+ }
817+ }
818+
819+ if (nodes.nodes.isEmpty) {
820+ throw ArgumentError ('the following xpath cannot be signed because it was not found: ${ref .xpath }' );
821+ }
806822 }
807823
808824 for (final node in nodes.nodes) {
0 commit comments