@@ -55,6 +55,8 @@ export class SignedXml {
55
55
keyInfoAttributes : { [ attrName : string ] : string } = { } ;
56
56
getKeyInfoContent = SignedXml . getKeyInfoContent ;
57
57
getCertFromKeyInfo = SignedXml . getCertFromKeyInfo ;
58
+ //xadesQualifyingProperties?: null;
59
+ xadesQualifyingProperties : ( ( ) => string ) | null ;
58
60
59
61
// Internal state
60
62
private id = 0 ;
@@ -151,6 +153,7 @@ export class SignedXml {
151
153
this . keyInfoAttributes = keyInfoAttributes ?? this . keyInfoAttributes ;
152
154
this . getKeyInfoContent = getKeyInfoContent ?? SignedXml . noop ;
153
155
this . getCertFromKeyInfo = getCertFromKeyInfo ?? this . getCertFromKeyInfo ;
156
+ this . xadesQualifyingProperties = null ;
154
157
this . CanonicalizationAlgorithms ;
155
158
this . HashAlgorithms ;
156
159
this . SignatureAlgorithms ;
@@ -802,6 +805,9 @@ export class SignedXml {
802
805
803
806
signatureXml += this . createSignedInfo ( doc , prefix ) ;
804
807
signatureXml += this . getKeyInfo ( prefix ) ;
808
+ if ( this . xadesQualifyingProperties != null ) {
809
+ signatureXml += `<${ currentPrefix } Object>${ this . xadesQualifyingProperties ( ) } </${ currentPrefix } Object>` ;
810
+ }
805
811
signatureXml += `</${ currentPrefix } Signature>` ;
806
812
807
813
this . originalXmlWithIds = doc . toString ( ) ;
@@ -918,21 +924,34 @@ export class SignedXml {
918
924
prefix = prefix ? `${ prefix } :` : prefix ;
919
925
920
926
for ( const ref of this . getReferences ( ) ) {
921
- const nodes = xpath . selectWithResolver ( ref . xpath ?? "" , doc , this . namespaceResolver ) ;
927
+ let nodes = xpath . selectWithResolver ( ref . xpath ?? "" , doc , this . namespaceResolver ) ;
922
928
923
929
if ( ! utils . isArrayHasLength ( nodes ) ) {
924
- throw new Error (
925
- `the following xpath cannot be signed because it was not found: ${ ref . xpath } ` ,
926
- ) ;
930
+ if ( this . xadesQualifyingProperties != null ) {
931
+ nodes = xpath . selectWithResolver (
932
+ ref . xpath ?? "" ,
933
+ new xmldom . DOMParser ( ) . parseFromString ( this . xadesQualifyingProperties ( ) ) ,
934
+ this . namespaceResolver ,
935
+ ) ;
936
+ }
937
+ if ( ! utils . isArrayHasLength ( nodes ) ) {
938
+ throw new Error (
939
+ `the following xpath cannot be signed because it was not found: ${ ref . xpath } ` ,
940
+ ) ;
941
+ }
927
942
}
928
943
929
944
for ( const node of nodes ) {
945
+ let addattr = "" ;
946
+ if ( node [ "localName" ] === "SignedProperties" ) {
947
+ addattr = ' Type="http://uri.etsi.org/01903#SignedProperties"' ;
948
+ }
930
949
if ( ref . isEmptyUri ) {
931
- res += `<${ prefix } Reference URI="">` ;
950
+ res += `<${ prefix } Reference URI=""${ addattr } >` ;
932
951
} else {
933
952
const id = this . ensureHasId ( node ) ;
934
953
ref . uri = id ;
935
- res += `<${ prefix } Reference URI="#${ id } ">` ;
954
+ res += `<${ prefix } Reference URI="#${ id } "${ addattr } >` ;
936
955
}
937
956
res += `<${ prefix } Transforms>` ;
938
957
for ( const trans of ref . transforms || [ ] ) {
0 commit comments