Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b10a651
feat: add support for inserting and signing Object elements inside th…
shunkica Jun 20, 2025
b5aa833
add XAdES test/example
shunkica Jun 21, 2025
95a4f47
update docs
shunkica Jun 21, 2025
014b0fb
feat: add id and type attributes to Reference elements in XML signature
shunkica Jun 23, 2025
71988ee
Update README.md
shunkica Jul 8, 2025
c539438
refactor!: convert getObjectContent from function to static objects p…
shunkica Aug 15, 2025
8aac540
refactor!: remove necessity for isSignatureReference property by trac…
shunkica Aug 15, 2025
55dc24d
refactor: resolve review comments
shunkica Aug 15, 2025
9fd58a5
fix: wrong import path
shunkica Aug 15, 2025
eafbfc3
tests: add and refactor tests, remove redundant comments
shunkica Aug 15, 2025
e761453
tests: further refactoring of tests
shunkica Aug 15, 2025
ece496b
tests: remove redundant test and improve xades test
shunkica Aug 15, 2025
3b5893d
refactor: rewrite tests, use namespaces for select, remove redundant …
shunkica Aug 16, 2025
230d4c5
fix: process signature references after signature has been appended t…
shunkica Aug 16, 2025
04a1de4
fix: prevent signature self-reference
shunkica Aug 17, 2025
38c552b
refactor: utils import, make it clear why we use signatureDoc in proc…
shunkica Aug 17, 2025
aa9b086
mark references as processed (however this flag could be removed if i…
shunkica Aug 17, 2025
d7b205c
Merge branch 'master' into signature-object
cjbarth Oct 17, 2025
48a9f9b
Remove `wasProcessed` property
cjbarth Oct 20, 2025
114e2f7
Merge branch 'master' into signature-object
cjbarth Oct 20, 2025
86da2b7
refactor: unify reference creation functions, generate missing attrib…
shunkica Oct 21, 2025
9cdc22d
refactor: reuse signedInfoNode, use assertIsElementNode instead of ca…
shunkica Oct 21, 2025
5ceb807
Minor cleanups
cjbarth Oct 22, 2025
7546fae
lint
cjbarth Oct 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
"codecov",
"feide",
"HMAC",
"posteb",
"preeb",
"reserialization",
"stricttextualmsg",
"wsfederation",
"wssecurity"
"wssecurity",
"xades"
]
}
41 changes: 40 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,17 +262,20 @@ The `SignedXml` constructor provides an abstraction for sign and verify xml docu
- `keyInfoAttributes` - object - default `{}` - a hash of attributes and values `attrName: value` to add to the KeyInfo node
- `getKeyInfoContent` - function - default `noop` - a function that returns the content of the KeyInfo node
- `getCertFromKeyInfo` - function - default `SignedXml.getCertFromKeyInfo` - a function that returns the certificate from the `<KeyInfo />` node
- `objects` - array - default `undefined` - an array of objects defining the content of the `<Object/>` nodes

#### API

A `SignedXml` object provides the following methods:

To sign xml documents:

- `addReference(xpath, transforms, digestAlgorithm)` - adds a reference to a xml element where:
- `addReference({ xpath, transforms, digestAlgorithm, id, type })` - adds a reference to a xml element where:
- `xpath` - a string containing a XPath expression referencing a xml element
- `transforms` - an array of [transform algorithms](#canonicalization-and-transformation-algorithms), the referenced element will be transformed for each value in the array
- `digestAlgorithm` - one of the supported [hashing algorithms](#hashing-algorithms)
- `id` - an optional `Id` attribute to add to the reference element
- `type` - the optional `Type` attribute to add to the reference element (represented as a URI)
- `computeSignature(xml, [options])` - compute the signature of the given xml where:
- `xml` - a string containing a xml document
- `options` - an object with the following properties:
Expand Down Expand Up @@ -535,6 +538,42 @@ sig.computeSignature(xml, {
});
```

### How to add custom Objects to the signature

Use the `objects` option when creating a SignedXml instance to add custom Objects to the signature.

```javascript
var SignedXml = require("xml-crypto").SignedXml,
fs = require("fs");

var xml = "<library>" + "<book>" + "<name>Harry Potter</name>" + "</book>" + "</library>";

const sig = new SignedXml({
privateKey: fs.readFileSync("client.pem"),
canonicalizationAlgorithm: "http://www.w3.org/2001/10/xml-exc-c14n#",
signatureAlgorithm: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
objects: [
{
content: "<TestObject>Test data in Object</TestObject>",
attributes: {
Id: "Object1",
MimeType: "text/xml",
},
},
],
});

// Add a reference to the Object element
sig.addReference({
xpath: "//*[@Id='Object1']",
digestAlgorithm: "http://www.w3.org/2000/09/xmldsig#sha1",
transforms: ["http://www.w3.org/2001/10/xml-exc-c14n#"],
});

sig.computeSignature(xml);
fs.writeFileSync("signed.xml", sig.getSignedXml());
```

### more examples (_coming soon_)

## Development
Expand Down
Loading