-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #422 from docknetwork/feat/ed25519-2020-support
Support Ed255192020 keys, open badges example
- Loading branch information
Showing
11 changed files
with
191 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import VerifiableCredential from '../src/verifiable-credential'; | ||
import { DIDKeyResolver } from '../src/resolver'; | ||
|
||
// Sample credential data from https://gist.githubusercontent.com/ottonomy/6f72f5055220cfa8c6926e1a753f1870/raw/e7882e4a6eebb503359cce4bdc8978331d47544c/asu-tln-unconference-example-credential.json | ||
const credentialJSON = { | ||
"@context": [ | ||
"https://www.w3.org/2018/credentials/v1", | ||
"https://purl.imsglobal.org/spec/ob/v3p0/context-3.0.3.json", | ||
"https://w3id.org/security/suites/ed25519-2020/v1" | ||
], | ||
"type": [ | ||
"VerifiableCredential", | ||
"OpenBadgeCredential" | ||
], | ||
"issuer": { | ||
"type": "Profile", | ||
"id": "did:key:z6MkoowWdLogChc6mRp18YcKBd2yYTNnQLeHdiT73wjL1h6z", | ||
"name": "Trusted Learner Network (TLN) Unconference Issuer", | ||
"url": "https://tln.asu.edu/", | ||
"image": { | ||
"id": "https://plugfest3-assets-20230928.s3.amazonaws.com/TLN+Gold+Circle.png", | ||
"type": "Image" | ||
} | ||
}, | ||
"issuanceDate": "2024-04-04T16:43:31.485Z", | ||
"name": "2024 TLN Unconference Change Agent", | ||
"credentialSubject": { | ||
"type": "AchievementSubject", | ||
"id": "did:key:7af28a8b2b9684073a0884aacd8c31eb5908baf4a1ba7e2ca60582bf585c68ad", | ||
"achievement": { | ||
"id": "https://tln.asu.edu/achievement/369435906932948", | ||
"type": "Achievement", | ||
"name": "2024 TLN Unconference Change Agent", | ||
"description": "This credential certifies attendance, participation, and knowledge-sharing at the 2024 Trusted Learner Network (TLN) Unconference.", | ||
"criteria": { | ||
"type": "Criteria", | ||
"narrative": "* Demonstrates initiative and passion for digital credentialing\n* Shares knowledge, skills and experience to broaden and deepen the community's collective understanding and competency\n* Engages in complex problems by collaborating with others\n* Creates connections and builds coalition to advance the ecosystem" | ||
} | ||
} | ||
}, | ||
"id": "https://tln.asu.edu/achievement/369435906932948", | ||
"proof": { | ||
"type": "Ed25519Signature2020", | ||
"created": "2024-04-04T16:43:31Z", | ||
"verificationMethod": "did:key:z6MkoowWdLogChc6mRp18YcKBd2yYTNnQLeHdiT73wjL1h6z#z6MkoowWdLogChc6mRp18YcKBd2yYTNnQLeHdiT73wjL1h6z", | ||
"proofPurpose": "assertionMethod", | ||
"proofValue": "z23JQwSmJKnWXw1HWDMBv1yoZDVyfUsRWihQFsrSLpb8cENqbuqpdnaSY72VmCkY3WQ4GovpNRZPNLRaatXeDJE8G" | ||
} | ||
}; | ||
|
||
const resolver = new DIDKeyResolver(); | ||
|
||
async function main() { | ||
// Incrementally build a verifiable credential | ||
const credential = VerifiableCredential.fromJSON(credentialJSON); | ||
|
||
// Verify the credential | ||
const verifyResult = await credential.verify({ | ||
resolver, | ||
compactProof: true, | ||
}); | ||
if (verifyResult.verified) { | ||
console.log('Credential has been verified! Result:', verifyResult); | ||
} else { | ||
console.error('Credential could not be verified!. Got error', verifyResult.error); | ||
process.exit(1); | ||
} | ||
|
||
// Exit | ||
process.exit(0); | ||
} | ||
|
||
main(); |
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,41 @@ | ||
import { Ed255192020SigName, Ed255192020VerKeyName } from './constants'; | ||
import Ed25519VerificationKey2020 from './Ed25519VerificationKey2020'; | ||
import CustomLinkedDataSignature from './common/CustomLinkedDataSignature'; | ||
|
||
const SUITE_CONTEXT_URL = 'https://w3id.org/security/suites/ed25519-2020/v1'; | ||
|
||
export default class Ed25519Signature2020 extends CustomLinkedDataSignature { | ||
/** | ||
* Creates a new Ed25519Signature2020 instance | ||
* @constructor | ||
* @param {object} config - Configuration options | ||
*/ | ||
constructor({ | ||
keypair, verificationMethod, verifier, signer, | ||
} = {}) { | ||
super({ | ||
type: Ed255192020SigName, | ||
LDKeyClass: Ed25519VerificationKey2020, | ||
contextUrl: SUITE_CONTEXT_URL, | ||
alg: 'EdDSA', | ||
signer: signer || Ed25519Signature2020.signerFactory(keypair, verificationMethod), | ||
verifier, | ||
}); | ||
this.requiredKeyType = Ed255192020VerKeyName; | ||
} | ||
|
||
/** | ||
* Generate object with `sign` method | ||
* @param keypair | ||
* @param verificationMethod | ||
* @returns {object} | ||
*/ | ||
static signerFactory(keypair, verificationMethod) { | ||
return { | ||
id: verificationMethod, | ||
async sign({ data }) { | ||
return keypair.sign(data); | ||
}, | ||
}; | ||
} | ||
} |
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,31 @@ | ||
import b58 from 'bs58'; | ||
import * as base64 from '@juanelas/base64'; | ||
import { Ed25519VerKeyName, Ed255192020VerKeyName } from './constants'; | ||
import Ed25519VerificationKey2018 from './Ed25519VerificationKey2018'; | ||
|
||
export default class Ed25519VerificationKey2020 extends Ed25519VerificationKey2018 { | ||
/** | ||
* Construct the public key object from the verification method | ||
* @param verificationMethod | ||
* @returns {Ed25519VerificationKey2020} | ||
*/ | ||
static from(verificationMethod) { | ||
const isEd25519Type = verificationMethod.type.indexOf(Ed255192020VerKeyName) !== -1 | ||
|| verificationMethod.type.indexOf(Ed25519VerKeyName) !== -1; | ||
if (!verificationMethod.type || !isEd25519Type) { | ||
throw new Error(`verification method should have type ${Ed255192020VerKeyName} - got: ${verificationMethod.type}`); | ||
} | ||
|
||
if (verificationMethod.publicKeyBase58) { | ||
return new this(b58.decode(verificationMethod.publicKeyBase58)); | ||
} | ||
|
||
if (verificationMethod.publicKeyBase64) { | ||
return new this(base64.decode(verificationMethod.publicKeyBase64)); | ||
} | ||
|
||
throw new Error(`Unsupported signature encoding for ${Ed255192020VerKeyName}`); | ||
} | ||
|
||
// NOTE: Ed255192020 has the same cryptography as Ed255192018, so we inherit the verifier methods | ||
} |
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