Skip to content

Commit

Permalink
Example updates.
Browse files Browse the repository at this point in the history
- Use verify suite.
- Add multikey resolver.
  • Loading branch information
davidlehn committed Nov 30, 2023
1 parent 24a2e4f commit cf75691
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
32 changes: 21 additions & 11 deletions examples/rt.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import * as vc from '../lib/index.js';
import {DataIntegrityProof} from '@digitalbazaar/data-integrity';
import {driver} from '@digitalbazaar/did-method-key';

// document loader support
// setup document loader
import {CachedResolver} from '@digitalbazaar/did-io';
import {securityLoader} from '@digitalbazaar/security-document-loader';

//import secCtx from '@digitalbazaar/security-context';
Expand All @@ -41,17 +42,20 @@ loader.addStatic(
}
/* eslint-enable quotes, quote-props, max-len */
);
const resolver = new CachedResolver();
const didKeyDriverMultikey = driver();

didKeyDriverMultikey.use({
multibaseMultikeyHeader: 'zDna',
fromMultibase: EcdsaMultikey.from
});
resolver.use(didKeyDriverMultikey);
loader.setDidResolver(resolver);

const documentLoader = loader.build();

async function main({credential, documentLoader}) {
// generate example ecdsa keypair
const didKeyDriverMultikey = driver();

didKeyDriverMultikey.use({
multibaseMultikeyHeader: 'zDna',
fromMultibase: EcdsaMultikey.from
});

const ecdsaKeyPair = await EcdsaMultikey.generate({curve: 'P-256'});

Expand All @@ -63,8 +67,8 @@ async function main({credential, documentLoader}) {
ecdsaKeyPair.id = didDocument.assertionMethod[0];
ecdsaKeyPair.controller = didDocument.id;

// setup ecdsa-rdfc-2019 suite
const suite = new DataIntegrityProof({
// setup ecdsa-rdfc-2019 signing suite
const signingSuite = new DataIntegrityProof({
signer: ecdsaKeyPair.signer(),
// date: '2023-01-01T01:01:01Z',
cryptosuite: ecdsaRdfc2019Cryptosuite
Expand All @@ -75,13 +79,19 @@ async function main({credential, documentLoader}) {
// sign credential
const verifiableCredential = await vc.issue({
credential,
suite,
suite: signingSuite,
documentLoader
});

// setup ecdsa-rdfc-2019 verifying suite
const verifyingSuite = new DataIntegrityProof({
cryptosuite: ecdsaRdfc2019Cryptosuite
});

// verify signed credential
const verifyResult = await vc.verifyCredential({
credential: verifiableCredential,
suite,
suite: verifyingSuite,
documentLoader
});

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@digitalbazaar/credentials-examples-context": "^1.0.0",
"@digitalbazaar/data-integrity": "^2.0.0",
"@digitalbazaar/data-integrity-context": "^2.0.0",
"@digitalbazaar/did-io": "^2.0.0",
"@digitalbazaar/did-method-key": "^5.1.0",
"@digitalbazaar/ecdsa-multikey": "^1.6.0",
"@digitalbazaar/ecdsa-rdfc-2019-cryptosuite": "^1.0.1",
Expand Down

0 comments on commit cf75691

Please sign in to comment.