Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion lib/tdf3/src/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ export type AssertionPayload = {
* @returns the hexadecimal string representation of the hash
*/
export async function hash(a: Assertion): Promise<string> {
const result = canonicalizeEx(a, { exclude: ['binding', 'hash', 'sign', 'verify'] });
const result = canonicalizeEx(a, {
exclude: ['binding', 'hash', 'sign', 'verify', 'signingKey'],
});

const hash = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(result));
return hex.encodeArrayBuffer(hash);
Expand Down
29 changes: 29 additions & 0 deletions lib/tests/mocha/unit/assertions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,34 @@ describe('assertions', () => {
})
).to.be.true;
});

it('normalizes assertions', async () => {
let assertion: any = {
appliesToState: 'unencrypted',
id: 'system-metadata',
binding: {
method: 'jws',
signature: 'test-signature',
},
signingKey: {
alg: 'ES256',
key: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]),
},
scope: 'payload',
statement: {
format: 'json',
schema: 'system-metadata-v1',
value:
'{"tdf_spec_version":"4.3.0","creation_date":"2025-07-23T09:25:51.255364+02:00","operating_system":"Mac OS X","sdk_version":"Java-0.8.2-SNAPSHOT","java_version":"17.0.14","architecture":"aarch64"}',
},
type: 'other',
};

let h1 = await assertions.hash(assertion);
delete assertion.signingKey;
let h2 = await assertions.hash(assertion);

expect(h1).to.equal(h2);
});
});
});
Loading