Skip to content

Commit

Permalink
Allow proof purpose of assertionMethod
Browse files Browse the repository at this point in the history
  • Loading branch information
brianorwhatever committed Oct 25, 2024
1 parent 67b6b2c commit ccd6b84
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const documentStateIsValid = async (doc: any, updateKeys: string[], witne
if (proof.type !== 'DataIntegrityProof') {
throw new Error(`Unknown proof type ${proof.type}`);
}
if (proof.proofPurpose !== 'authentication') {
if (proof.proofPurpose !== 'authentication' && proof.proofPurpose !== 'assertionMethod') {
throw new Error(`Unknown proof purpose ${proof.proofPurpose}`);
}
if (proof.cryptosuite !== 'eddsa-jcs-2022') {
Expand Down
4 changes: 2 additions & 2 deletions src/cryptography.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const createSigner = (vm: VerificationMethod, useStatic: boolean = true)
cryptosuite: 'eddsa-jcs-2022',
verificationMethod: useStatic ? `did:key:${vm.publicKeyMultibase}#${vm.publicKeyMultibase}` : vm.id,
created: createDate(),
proofPurpose: 'authentication'
proofPurpose: 'assertionMethod'
}
const dataHash = createHash('sha256').update(canonicalize(doc)).digest();
const proofHash = createHash('sha256').update(canonicalize(proof)).digest();
Expand All @@ -41,7 +41,7 @@ export const generateEd25519VerificationMethod = async (): Promise<VerificationM
type: "Multikey",
publicKeyMultibase,
secretKeyMultibase,
purpose: 'authentication'
purpose: 'assertionMethod'
};
}

Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/not-authorized.log
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{"versionId":"1-QmX2pKGjDG6NTXFnPTHkBJ7Mmc2iwJQkvi35xEw5Qu34x7","versionTime":"2024-10-16T19:49:14Z","parameters":{"method":"did:tdw:0.4","scid":"QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb","updateKeys":["z6MkimixB3LLRtw2X8t8TachAsvP8ozrr1duC9kcgEFXSLW2"],"portable":false,"prerotation":false,"nextKeyHashes":[],"witnesses":[],"witnessThreshold":0,"deactivated":false},"state":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1"],"id":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com","controller":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com","authentication":["did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#gEFXSLW2","did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#drUP7r5G"],"verificationMethod":[{"id":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#gEFXSLW2","controller":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com","type":"Multikey","publicKeyMultibase":"z6MkimixB3LLRtw2X8t8TachAsvP8ozrr1duC9kcgEFXSLW2"},{"id":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#drUP7r5G","controller":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com","type":"Multikey","publicKeyMultibase":"z6MkjebqPXBJ8FFog66DKBFCan4g9iPnG1dbjY5adrUP7r5G"}]},"proof":[{"type":"DataIntegrityProof","cryptosuite":"eddsa-jcs-2022","verificationMethod":"did:key:z6MkimixB3LLRtw2X8t8TachAsvP8ozrr1duC9kcgEFXSLW2#z6MkimixB3LLRtw2X8t8TachAsvP8ozrr1duC9kcgEFXSLW2","created":"2024-10-16T19:49:14Z","proofPurpose":"authentication","proofValue":"z4or9CsM7NMyeLid5SENnbfCHGFd1hZamHvdm9iAEaoGK3bAagkxCQceNrxvQxYxCraMPWstSUrjn9XJY3WrxnzWU"}]}
{"versionId":"2-Qmbwu3Vrr3zdSjD994m1pu4BQSGZGXtMZrfuQh4GmXqUMd","versionTime":"2024-10-16T19:49:14Z","parameters":{"witnesses":[],"witnessThreshold":0},"state":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1"],"id":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com","controller":["did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com"],"authentication":["did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#GV4js1Ua","did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#G9AguCS3"],"verificationMethod":[{"id":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#GV4js1Ua","controller":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com","type":"Multikey","publicKeyMultibase":"z6MkgNAsxqZoFt6dbEGCcZ6NZsFtHQpdCjUgmcG3GV4js1Ua"},{"id":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com#G9AguCS3","controller":"did:tdw:QmdM16VTQBmiy8Errf87Vkp6XGx6CspGTrfVDkXi1BRHbb:example.com","type":"Multikey","publicKeyMultibase":"z6Mkvm7Wxo58rHambdmSiMTxQF7m1pLxvCK7iAMmG9AguCS3"}]},"proof":[{"type":"DataIntegrityProof","cryptosuite":"eddsa-jcs-2022","verificationMethod":"did:key:z6MkjebqPXBJ8FFog66DKBFCan4g9iPnG1dbjY5adrUP7r5G#z6MkjebqPXBJ8FFog66DKBFCan4g9iPnG1dbjY5adrUP7r5G","created":"2024-10-16T19:49:14Z","proofPurpose":"authentication","proofValue":"z3GQFTrs8cudPLizGHWbSuMpqFoWcCxBFpCQGHLG1U9jwiDm5zQuhMyQHLJsD5sPz13k9fEBgM5EaXneTNAbc7G4a"}]}
{"versionId":"1-QmbHUDLxTJCeKX3oACyabxT41b59dBeyVmGFUbYHheyXzZ","versionTime":"2024-10-25T18:45:30Z","parameters":{"method":"did:tdw:0.4","scid":"QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q","updateKeys":["z6MkmGhgCBEntnVBDJxRuzmiQegAW9CjxiNBghfQkuXz1KAL"],"portable":false,"prerotation":false,"nextKeyHashes":[],"witnesses":[],"witnessThreshold":0,"deactivated":false},"state":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1"],"id":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com","controller":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com","assertionMethod":["did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#kuXz1KAL","did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#zZHqtfrA"],"verificationMethod":[{"id":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#kuXz1KAL","controller":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com","type":"Multikey","publicKeyMultibase":"z6MkmGhgCBEntnVBDJxRuzmiQegAW9CjxiNBghfQkuXz1KAL"},{"id":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#zZHqtfrA","controller":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com","type":"Multikey","publicKeyMultibase":"z6MkoQuMZHARUzhqbFyz8R4S4XZtrZdXDNGvsPoMzZHqtfrA"}]},"proof":[{"type":"DataIntegrityProof","cryptosuite":"eddsa-jcs-2022","verificationMethod":"did:key:z6MkmGhgCBEntnVBDJxRuzmiQegAW9CjxiNBghfQkuXz1KAL#z6MkmGhgCBEntnVBDJxRuzmiQegAW9CjxiNBghfQkuXz1KAL","created":"2024-10-25T18:45:30Z","proofPurpose":"assertionMethod","proofValue":"z4gL79eB3tnnHm8UPnxRPf4Q6P2E8t3YSxbF76MX2TG3acDDY8ZdjFo8XdbVPPqt49j5KacX5zVbawNmqBZb1rrdK"}]}
{"versionId":"2-Qmdxp9ccKBcsCvWS1J4CZJLSLb7xwbVDnbrVK9vvVdk8hk","versionTime":"2024-10-25T18:45:30Z","parameters":{"witnesses":[],"witnessThreshold":0},"state":{"@context":["https://www.w3.org/ns/did/v1","https://w3id.org/security/multikey/v1"],"id":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com","controller":["did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com"],"assertionMethod":["did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#t9eqqUNt","did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#aKfrG3z9"],"verificationMethod":[{"id":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#t9eqqUNt","controller":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com","type":"Multikey","publicKeyMultibase":"z6MknCCJKC4F9JkRPpCiAVq7zJjU68yuvvj2x9ght9eqqUNt"},{"id":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com#aKfrG3z9","controller":"did:tdw:QmZnNM9Fzy5DU61AXBxtHbReZFMoEuS636s9HsxfJZbF9q:example.com","type":"Multikey","publicKeyMultibase":"z6Mkpec8gRmSA83WzQj36Tuhaa4mQLXuyuB76QipaKfrG3z9"}]},"proof":[{"type":"DataIntegrityProof","cryptosuite":"eddsa-jcs-2022","verificationMethod":"did:key:z6MkoQuMZHARUzhqbFyz8R4S4XZtrZdXDNGvsPoMzZHqtfrA#z6MkoQuMZHARUzhqbFyz8R4S4XZtrZdXDNGvsPoMzZHqtfrA","created":"2024-10-25T18:45:30Z","proofPurpose":"assertionMethod","proofValue":"z3yyXeh9y4bibGaJWkrWBi7A3fG2TnRDtuoWUzvZFo91yUBqs8vuZEEqRTT27FjMpusJU1VWf8WWJu7N3LBLphtyZ"}]}
2 changes: 1 addition & 1 deletion test/happy-path.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ test("Update DID (add external controller)", async () => {
didLog = [...updatedLog];
expect(updatedDID).toBe(did);
expect(updatedDoc.controller).toContain(externalAuthKey.controller);
expect(updatedDoc.authentication[1]).toContain(externalAuthKey.controller!.slice(-6));
expect(updatedDoc.assertionMethod[1]).toContain(externalAuthKey.controller!.slice(-6));
expect(updatedDoc.verificationMethod[1].controller).toBe(externalAuthKey.controller);

expect(meta.versionId.split('-')[0]).toBe("5");
Expand Down

0 comments on commit ccd6b84

Please sign in to comment.