-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(credential-ld): add
Ed25519Signature2020
& `JsonWebSignature20…
- Loading branch information
1 parent
33c7cee
commit fbf7d48
Showing
18 changed files
with
680 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
packages/credential-ld/src/contexts/ed25519-signature-2020-v1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"@context": { | ||
"id": "@id", | ||
"type": "@type", | ||
"@protected": true, | ||
"proof": { | ||
"@id": "https://w3id.org/security#proof", | ||
"@type": "@id", | ||
"@container": "@graph" | ||
}, | ||
"Ed25519VerificationKey2020": { | ||
"@id": "https://w3id.org/security#Ed25519VerificationKey2020" | ||
}, | ||
"Ed25519Signature2020": { | ||
"@id": "https://w3id.org/security#Ed25519Signature2020", | ||
"@context": { | ||
"@protected": true, | ||
"id": "@id", | ||
"type": "@type", | ||
"challenge": "https://w3id.org/security#challenge", | ||
"created": { | ||
"@id": "http://purl.org/dc/terms/created", | ||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime" | ||
}, | ||
"domain": "https://w3id.org/security#domain", | ||
"expires": { | ||
"@id": "https://w3id.org/security#expiration", | ||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime" | ||
}, | ||
"nonce": "https://w3id.org/security#nonce", | ||
"proofPurpose": { | ||
"@id": "https://w3id.org/security#proofPurpose", | ||
"@type": "@vocab", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
"id": "@id", | ||
"type": "@type", | ||
"assertionMethod": { | ||
"@id": "https://w3id.org/security#assertionMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"authentication": { | ||
"@id": "https://w3id.org/security#authenticationMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"capabilityInvocation": { | ||
"@id": "https://w3id.org/security#capabilityInvocationMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"capabilityDelegation": { | ||
"@id": "https://w3id.org/security#capabilityDelegationMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"keyAgreement": { | ||
"@id": "https://w3id.org/security#keyAgreementMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
} | ||
} | ||
}, | ||
"proofValue": { | ||
"@id": "https://w3id.org/security#proofValue", | ||
"@type": "https://w3id.org/security#multibase" | ||
}, | ||
"verificationMethod": { | ||
"@id": "https://w3id.org/security#verificationMethod", | ||
"@type": "@id" | ||
} | ||
} | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
packages/credential-ld/src/contexts/json-web-signature-2020-v1.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
{ | ||
"@context": { | ||
"@version": 1.1, | ||
"id": "@id", | ||
"type": "@type", | ||
"@protected": true, | ||
"JsonWebKey2020": { | ||
"@id": "https://w3id.org/security#JsonWebKey2020" | ||
}, | ||
"JsonWebSignature2020": { | ||
"@id": "https://w3id.org/security#JsonWebSignature2020", | ||
"@context": { | ||
"@version": 1.1, | ||
"id": "@id", | ||
"type": "@type", | ||
"@protected": true, | ||
"challenge": "https://w3id.org/security#challenge", | ||
"created": { | ||
"@id": "http://purl.org/dc/terms/created", | ||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime" | ||
}, | ||
"domain": "https://w3id.org/security#domain", | ||
"expires": { | ||
"@id": "https://w3id.org/security#expiration", | ||
"@type": "http://www.w3.org/2001/XMLSchema#dateTime" | ||
}, | ||
"jws": "https://w3id.org/security#jws", | ||
"nonce": "https://w3id.org/security#nonce", | ||
"proofPurpose": { | ||
"@id": "https://w3id.org/security#proofPurpose", | ||
"@type": "@vocab", | ||
"@context": { | ||
"@version": 1.1, | ||
"@protected": true, | ||
"id": "@id", | ||
"type": "@type", | ||
"assertionMethod": { | ||
"@id": "https://w3id.org/security#assertionMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"authentication": { | ||
"@id": "https://w3id.org/security#authenticationMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"capabilityInvocation": { | ||
"@id": "https://w3id.org/security#capabilityInvocationMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"capabilityDelegation": { | ||
"@id": "https://w3id.org/security#capabilityDelegationMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
}, | ||
"keyAgreement": { | ||
"@id": "https://w3id.org/security#keyAgreementMethod", | ||
"@type": "@id", | ||
"@container": "@set" | ||
} | ||
} | ||
}, | ||
"verificationMethod": { | ||
"@id": "https://w3id.org/security#verificationMethod", | ||
"@type": "@id" | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { RequiredAgentMethods, VeramoLdSignature } from '../ld-suites' | ||
import { CredentialPayload, DIDDocument, IAgentContext, IKey, TKeyType } from '@veramo/core' | ||
import * as u8a from 'uint8arrays' | ||
import { Ed25519Signature2020 } from '@digitalcredentials/ed25519-signature-2020' | ||
import { Ed25519VerificationKey2020 } from '@digitalcredentials/ed25519-verification-key-2020' | ||
import { TextEncoder } from 'util' | ||
/** | ||
* Veramo wrapper for the Ed25519Signature2020 suite by digitalcredentials | ||
* | ||
* @alpha This API is experimental and is very likely to change or disappear in future releases without notice. | ||
*/ | ||
export class VeramoEd25519Signature2020 extends VeramoLdSignature { | ||
private readonly MULTIBASE_BASE58BTC_PREFIX = 'z' | ||
private readonly MULTICODEC_PREFIX = [0xed, 0x01] | ||
|
||
getSupportedVerificationType(): string { | ||
return 'Ed25519VerificationKey2020' | ||
} | ||
|
||
getSupportedVeramoKeyType(): TKeyType { | ||
return 'Ed25519' | ||
} | ||
|
||
getSuiteForSigning( | ||
key: IKey, | ||
issuerDid: string, | ||
verificationMethodId: string, | ||
context: IAgentContext<RequiredAgentMethods>, | ||
): Promise<any> { | ||
const controller = issuerDid | ||
|
||
// DID Key ID | ||
let id = verificationMethodId | ||
|
||
const signer = { | ||
// returns signatureBytes | ||
sign: async (args: { data: Uint8Array }): Promise<Uint8Array> => { | ||
const messageString = u8a.toString(args.data, 'base64') | ||
const signature = await context.agent.keyManagerSign({ | ||
keyRef: key.kid, | ||
data: messageString, | ||
encoding: 'base64', | ||
}) | ||
const utf8Encode = new TextEncoder() | ||
return utf8Encode.encode(signature) | ||
}, | ||
} | ||
|
||
const verificationKey = new Ed25519VerificationKey2020({ | ||
id, | ||
controller, | ||
publicKeyMultibase: this.preSigningKeyModification(u8a.fromString(key.publicKeyHex, 'hex')), | ||
signer: ()=> signer, | ||
type: this.getSupportedVerificationType(), | ||
}) | ||
// overwrite the signer since we're not passing the private key | ||
verificationKey.signer = () => signer as any | ||
return new Ed25519Signature2020({ | ||
key: verificationKey, | ||
signer: signer | ||
}) | ||
} | ||
|
||
getSuiteForVerification(): any { | ||
return new Ed25519Signature2020() | ||
} | ||
|
||
preSigningCredModification(credential: CredentialPayload): void { | ||
// nothing to do here | ||
} | ||
|
||
preDidResolutionModification(didUrl: string, didDoc: DIDDocument): void { | ||
// nothing to do here | ||
} | ||
|
||
preSigningKeyModification(key: Uint8Array): string { | ||
const modifiedKey = Uint8Array.from([...this.MULTICODEC_PREFIX, ...key]) | ||
return `${this.MULTIBASE_BASE58BTC_PREFIX}${u8a.toString(modifiedKey, 'base58btc')}` | ||
} | ||
} |
Oops, something went wrong.