@@ -1099,13 +1099,8 @@ export class SignedXml {
10991099 const signatureNamespace = "http://www.w3.org/2000/09/xmldsig#" ;
11001100
11011101 // Find the SignedInfo element to append to
1102- const signedInfoNode = xpath . select1 (
1103- `./*[local-name(.)='SignedInfo']` ,
1104- signatureElem ,
1105- ) as Element ;
1106- if ( ! signedInfoNode ) {
1107- throw new Error ( "Could not find SignedInfo element in signature" ) ;
1108- }
1102+ const signedInfoNode = xpath . select1 ( `./*[local-name(.)='SignedInfo']` , signatureElem ) ;
1103+ isDomNode . assertIsElementNode ( signedInfoNode ) ; // Type-safe assertion
11091104
11101105 // Signature document is technically the same document as the one we are signing,
11111106 // but we will extract it here for clarity (and also make it support detached signatures in the future)
@@ -1128,12 +1123,12 @@ export class SignedXml {
11281123 // Process the reference
11291124 for ( const node of nodes ) {
11301125 isDomNode . assertIsElementNode ( node ) ;
1126+
11311127 // Must not be a reference to Signature, SignedInfo, or a child of SignedInfo
1132- const signedInfo = utils . findChildren ( signatureElem , "SignedInfo" ) [ 0 ] ;
11331128 if (
11341129 node === signatureElem ||
1135- node === signedInfo ||
1136- utils . isDescendantOf ( node , signedInfo )
1130+ node === signedInfoNode ||
1131+ utils . isDescendantOf ( node , signedInfoNode )
11371132 ) {
11381133 throw new Error (
11391134 `Cannot sign a reference to the Signature or SignedInfo element itself: ${ ref . xpath } ` ,
0 commit comments