-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test-vectors from vc-di-eddsa spec.
- Loading branch information
Showing
4 changed files
with
166 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*! | ||
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
/* Note: This file contains data generated from the vc-di-eddsa specification | ||
test vectors. */ | ||
|
||
/* eslint-disable max-len */ | ||
/* eslint-disable quote-props */ | ||
/* eslint-disable quotes */ | ||
export const keyMaterial = { | ||
"publicKeyMultibase": "z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2", | ||
"secretKeyMultibase": "z3u2en7t5LR2WtQH5PfFqMqwVHBeXouLzo6haApm8XHqvjxq" | ||
}; | ||
|
||
// public key above converted to multikey format + controller doc: | ||
export const publicKey = { | ||
'@context': 'https://w3id.org/security/multikey/v1', | ||
id: 'did:key:z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2#z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2', | ||
type: 'Multikey', | ||
controller: 'did:key:z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2', | ||
publicKeyMultibase: 'z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2' | ||
}; | ||
export const controllerDoc = { | ||
'@context': [ | ||
'https://www.w3.org/ns/did/v1', | ||
'https://w3id.org/security/multikey/v1' | ||
], | ||
id: publicKey.controller, | ||
assertionMethod: [publicKey] | ||
}; | ||
|
||
export const signedFixture = { | ||
"@context": [ | ||
"https://www.w3.org/ns/credentials/v2", | ||
"https://www.w3.org/ns/credentials/examples/v2" | ||
], | ||
"id": "urn:uuid:58172aac-d8ba-11ed-83dd-0b3aef56cc33", | ||
"type": [ | ||
"VerifiableCredential", | ||
"AlumniCredential" | ||
], | ||
"name": "Alumni Credential", | ||
"description": "A minimum viable example of an Alumni Credential.", | ||
"issuer": "https://vc.example/issuers/5678", | ||
"validFrom": "2023-01-01T00:00:00Z", | ||
"credentialSubject": { | ||
"id": "did:example:abcdefgh", | ||
"alumniOf": "The School of Examples" | ||
}, | ||
"proof": { | ||
"type": "DataIntegrityProof", | ||
"cryptosuite": "eddsa-rdfc-2022", | ||
"created": "2023-02-24T23:36:38Z", | ||
"verificationMethod": "https://vc.example/issuers/5678#z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2", | ||
"proofPurpose": "assertionMethod", | ||
"proofValue": "z21EVs3eXERqTn4acNHT9viboqgzUaQ3kTmhPT3eA8qrVPE7CrQq78WkzctnMX5W4CrzcKnHw8V6dvy5pgWYCU5e9" | ||
} | ||
}; | ||
/* eslint-enable quotes */ | ||
/* eslint-enable quote-props */ | ||
/* eslint-enable max-len */ |
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,66 @@ | ||
/*! | ||
* Copyright (c) 2023-2024 Digital Bazaar, Inc. All rights reserved. | ||
*/ | ||
import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey'; | ||
import {cryptosuite} from '../lib/index.js'; | ||
import {DataIntegrityProof} from '@digitalbazaar/data-integrity'; | ||
import {expect} from 'chai'; | ||
import jsigs from 'jsonld-signatures'; | ||
import {loader} from './documentLoader.js'; | ||
|
||
import * as testVectors from './test-vectors.js'; | ||
|
||
const {purposes: {AssertionProofPurpose}} = jsigs; | ||
|
||
const documentLoader = loader.build(); | ||
|
||
describe('test vectors', () => { | ||
let keyPair; | ||
before(async () => { | ||
const {keyMaterial} = testVectors; | ||
keyPair = await Ed25519Multikey.from(keyMaterial); | ||
keyPair.controller = `did:key:${keyPair.publicKeyMultibase}`; | ||
keyPair.id = `${keyPair.controller}#${keyPair.publicKeyMultibase}`; | ||
|
||
// FIXME: test fixture should be updated to use `did:key` | ||
keyPair.controller = 'https://vc.example/issuers/5678'; | ||
keyPair.id = keyPair.controller + | ||
'#z6MkrJVnaZkeFzdQyMZu1cgjg7k1pZZ6pvBQ7XJPt4swbTQ2'; | ||
}); | ||
|
||
it('should create proof', async () => { | ||
const {signedFixture} = testVectors; | ||
const unsigned = {...signedFixture}; | ||
delete unsigned.proof; | ||
|
||
const signer = keyPair.signer(); | ||
const date = new Date(signedFixture.proof.created); | ||
|
||
let error; | ||
let signed; | ||
try { | ||
signed = await jsigs.sign(unsigned, { | ||
suite: new DataIntegrityProof({cryptosuite, signer, date}), | ||
purpose: new AssertionProofPurpose(), | ||
documentLoader | ||
}); | ||
} catch(e) { | ||
error = e; | ||
} | ||
|
||
expect(error).to.not.exist; | ||
expect(signed).to.deep.equal(signedFixture); | ||
}); | ||
|
||
it('should verify signed fixture', async () => { | ||
const {signedFixture} = testVectors; | ||
|
||
const result = await jsigs.verify(signedFixture, { | ||
suite: new DataIntegrityProof({cryptosuite}), | ||
purpose: new AssertionProofPurpose(), | ||
documentLoader | ||
}); | ||
|
||
expect(result.verified).to.be.true; | ||
}); | ||
}); |