From 96e571e84c8db6816a98abd987d75a09b988902c Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Fri, 19 Jul 2024 18:15:41 +0000 Subject: [PATCH] Increment key id urls & registerKey + export keyDoc. --- test/mocks/keyPairs.js | 123 ++++++++++++++++++++++------------------- 1 file changed, 66 insertions(+), 57 deletions(-) diff --git a/test/mocks/keyPairs.js b/test/mocks/keyPairs.js index 8528f3ea..218073ea 100644 --- a/test/mocks/keyPairs.js +++ b/test/mocks/keyPairs.js @@ -8,7 +8,10 @@ import * as ecdsaRdfc2019Cryptosuite from '@digitalbazaar/ecdsa-rdfc-2019-cryptosuite'; import * as ecdsaSd2023Cryptosuite from '@digitalbazaar/ecdsa-sd-2023-cryptosuite'; -import {assertionController} from './mocks/assertionController.js'; +import * as EddsaMultikey from '@digitalbazaar/ed25519-multikey'; +import * as eddsaRdfc2020Cryptosuite from + '@digitalbazaar/eddsa-rdfc-2022-cryptosuite'; +import {assertionController} from './assertionController.js'; import {DataIntegrityProof} from '@digitalbazaar/data-integrity'; import {Ed25519Signature2018} from '@digitalbazaar/ed25519-signature-2018'; import { @@ -21,64 +24,41 @@ export async function setupKeyPairs() { ['Ed25519VerificationKey2018', await ed25519KeyPair()], ['ecdsa-rdfc-2019', await ecdsaRdfc2019()], ['ecdsa-sd-2023', await ecdsaP256KeyPair()], + ['eddsa-rdfc-2022', await eddsaRdfc2022()], ['bbs-2023', await bbs2023()] ]); } -async function ecdsaRdfc2019() { +async function eddsaRdfc2022() { + const keyId = 'https://example.edu/issuers/keys/5'; // set up the ECDSA key pair that will be signing and verifying - const keyPair = await EcdsaMultikey.generate({ - curve: 'P-256', - id: 'https://example.edu/issuers/keys/2', + const keyPair = await EddsaMultikey.generate({ + id: keyId, controller: 'https://example.edu/issuers/565049' }); - - // add the key to the controller doc (authorizes its use for assertion) - assertionController.assertionMethod.push(keyPair.id); - // register the key document with documentLoader - remoteDocuments.set( - 'https://example.edu/issuers/keys/2', - await keyPair.export({publicKey: true})); + const keyDoc = await keyPair.export({publicKey: true}); + registerKey({keyDoc}); return { keyPair, - cryptosuite: ecdsaRdfc2019Cryptosuite, + cryptosuite: eddsaRdfc2020Cryptosuite, Suite: DataIntegrityProof, derived: false }; } -async function ed25519KeyPair() { - // set up the Ed25519 key pair that will be signing and verifying - const keyPair = await Ed25519VerificationKey2018.generate({ - id: 'https://example.edu/issuers/keys/1', +async function ecdsaRdfc2019() { + // set up the ECDSA key pair that will be signing and verifying + const keyPair = await EcdsaMultikey.generate({ + curve: 'P-256', + id: 'https://example.edu/issuers/keys/4', controller: 'https://example.edu/issuers/565049' }); - - // add the key to the controller doc (authorizes its use for assertion) - assertionController.assertionMethod.push(keyPair.id); - // also add the key for authentication (VP) purposes - // FIXME: this shortcut to reuse the same key and sign VPs as issuer can - // confuse developers trying to learn from the test suite and it should - // be changed - assertionController.authentication.push(keyPair.id); - - // register the controller document and the key document with documentLoader - remoteDocuments.set( - 'https://example.edu/issuers/565049', assertionController); - remoteDocuments.set( - 'https://example.edu/issuers/keys/1', - await keyPair.export({publicKey: true})); - - // set up the signature suite, using the generated key - suite = new Ed25519Signature2018({ - verificationMethod: 'https://example.edu/issuers/keys/1', - key: keyPair - }); + const keyDoc = await keyPair.export({publicKey: true}); + registerKey({keyDoc}); return { keyPair, - suite, - cryptosuite: Ed25519Signature2018, - Suite: Ed25519Signature2018, + cryptosuite: ecdsaRdfc2019Cryptosuite, + Suite: DataIntegrityProof, derived: false }; } @@ -88,16 +68,11 @@ async function ecdsaP256KeyPair() { // set up the ECDSA key pair that will be signing and verifying const keyPair = await EcdsaMultikey.generate({ curve: 'P-256', - id: 'https://example.edu/issuers/keys/2', + id: 'https://example.edu/issuers/keys/3', controller: 'https://example.edu/issuers/565049' }); - - // add the key to the controller doc (authorizes its use for assertion) - assertionController.assertionMethod.push(keyPair.id); - // register the key document with documentLoader - remoteDocuments.set( - 'https://example.edu/issuers/keys/2', - await keyPair.export({publicKey: true})); + const keyDoc = await keyPair.export({publicKey: true}); + registerKey({keyDoc}); return { keyPair, cryptosuite: ecdsaSd2023Cryptosuite, @@ -111,20 +86,54 @@ async function bbs2023() { // set up the BBS key pair that will be signing and verifying const keyPair = await Bls12381Multikey.generateBbsKeyPair({ algorithm: 'BBS-BLS12-381-SHA-256', - id: 'https://example.edu/issuers/keys/3', + id: 'https://example.edu/issuers/keys/2', controller: 'https://example.edu/issuers/565049' }); - - // add the key to the controller doc (authorizes its use for assertion) - assertionController.assertionMethod.push(keyPair.id); - // register the key document with documentLoader - remoteDocuments.set( - 'https://example.edu/issuers/keys/3', - await keyPair.export({publicKey: true})); + const keyDoc = keyPair.export({publicKey: true}); + registerKey({keyDoc}); return { + keyDoc, keyPair, cryptosuite: bbs2023Cryptosuite, derived: true, Suite: DataIntegrityProof }; } + +async function ed25519KeyPair() { + // set up the Ed25519 key pair that will be signing and verifying + const keyPair = await Ed25519VerificationKey2018.generate({ + id: 'https://example.edu/issuers/keys/1', + controller: 'https://example.edu/issuers/565049' + }); + + // also add the key for authentication (VP) purposes + // FIXME: this shortcut to reuse the same key and sign VPs as issuer can + // confuse developers trying to learn from the test suite and it should + // be changed + assertionController.authentication.push(keyPair.id); + // register the controller document and the key document with documentLoader + remoteDocuments.set( + 'https://example.edu/issuers/565049', assertionController); + const keyDoc = await keyPair.export({publicKey: true}); + registerKey({keyDoc}); + const suite = new Ed25519Signature2018({ + verificationMethod: 'https://example.edu/issuers/keys/1', + key: keyPair + }); + return { + keyDoc, + keyPair, + suite, + cryptosuite: Ed25519Signature2018, + Suite: Ed25519Signature2018, + derived: false + }; +} + +function registerKey({keyDoc}) { + // add the key to the controller doc (authorizes its use for assertion) + assertionController.assertionMethod.push(keyDoc.id); + // register the key document with documentLoader + remoteDocuments.set(keyDoc.id, keyDoc); +}