Skip to content

Commit 17c628c

Browse files
committed
Basic xades support
1 parent 5a0d317 commit 17c628c

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/signed-xml.ts

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,9 @@ export class SignedXml {
802802

803803
signatureXml += this.createSignedInfo(doc, prefix);
804804
signatureXml += this.getKeyInfo(prefix);
805+
if (this.xadesQualifyingProperties != null) {
806+
signatureXml += `<${currentPrefix}Object>${this.xadesQualifyingProperties()}</${currentPrefix}Object>`;
807+
}
805808
signatureXml += `</${currentPrefix}Signature>`;
806809

807810
this.originalXmlWithIds = doc.toString();
@@ -918,21 +921,29 @@ export class SignedXml {
918921
prefix = prefix ? `${prefix}:` : prefix;
919922

920923
for (const ref of this.getReferences()) {
921-
const nodes = xpath.selectWithResolver(ref.xpath ?? "", doc, this.namespaceResolver);
924+
let nodes = xpath.selectWithResolver(ref.xpath ?? "", doc, this.namespaceResolver);
922925

923926
if (!utils.isArrayHasLength(nodes)) {
924-
throw new Error(
925-
`the following xpath cannot be signed because it was not found: ${ref.xpath}`,
926-
);
927+
if (this.xadesQualifyingProperties != null){
928+
nodes = xpath.selectWithResolver(ref.xpath ?? "", new xmldom.DOMParser().parseFromString(this.xadesQualifyingProperties()), this.namespaceResolver);
929+
}
930+
if (!utils.isArrayHasLength(nodes)) {
931+
throw new Error(
932+
`the following xpath cannot be signed because it was not found: ${ref.xpath}`,
933+
);
934+
}
927935
}
928936

929937
for (const node of nodes) {
938+
let addattr="";
939+
if (node.localName=="SignedProperties") addattr=' Type="http://uri.etsi.org/01903#SignedProperties"';
930940
if (ref.isEmptyUri) {
931-
res += `<${prefix}Reference URI="">`;
932-
} else {
933-
const id = this.ensureHasId(node);
934-
ref.uri = id;
935-
res += `<${prefix}Reference URI="#${id}">`;
941+
res += `<${prefix}Reference URI=""${addattr}>`;
942+
}
943+
else {
944+
const id = this.ensureHasId(node);
945+
ref.uri = id;
946+
res += `<${prefix}Reference URI="#${id}"${addattr}>`;
936947
}
937948
res += `<${prefix}Transforms>`;
938949
for (const trans of ref.transforms || []) {

0 commit comments

Comments
 (0)