diff --git a/pkg/wallet/src/parser.ts b/pkg/wallet/src/parser.ts index 3a4f5734..ebe7918e 100644 --- a/pkg/wallet/src/parser.ts +++ b/pkg/wallet/src/parser.ts @@ -2,6 +2,7 @@ import { Parser } from '@slangroom/core'; export function parser(this: Parser) { this.RULE('walletPhrase', () => { + this.sendpass('jwk'); this.sendpass1('holder'); this.sendpass2('object'); this.sendpassn(3, 'fields'); diff --git a/pkg/wallet/src/plugin.ts b/pkg/wallet/src/plugin.ts index 418d310e..a04678e3 100644 --- a/pkg/wallet/src/plugin.ts +++ b/pkg/wallet/src/plugin.ts @@ -4,7 +4,7 @@ import { parser } from '@slangroom/wallet'; import bs58 from 'bs58' import { DisclosureFrame, Hasher, Signer, base64encode } from '@meeco/sd-jwt'; import { createHash } from 'crypto'; -import { JWTHeaderParameters, JWTPayload, KeyLike, SignJWT, exportJWK, generateKeyPair } from 'jose'; +import { JWTHeaderParameters, JWTPayload, KeyLike, SignJWT, exportJWK, importJWK } from 'jose'; import { CreateSDJWTPayload, HasherConfig, @@ -34,14 +34,15 @@ const hasher: HasherConfig = { }; const createVCSDJWT = async (ctx: PluginContext): Promise => { + const jwk = ctx.fetch('jwk') as JsonableObject const object = ctx.fetch('object') as JsonableObject const holder = ctx.fetch('holder') as string const fields = ctx.fetch('fields') as JsonableArray // TODO: generate in another statement - const keyPair = await generateKeyPair(supportedAlgorithm.EdDSA); + const sk = await importJWK(jwk) const signer: SignerConfig = { alg: supportedAlgorithm.EdDSA, - callback: signerCallbackFn(keyPair.privateKey), + callback: signerCallbackFn(sk), }; const issuer = new Issuer(signer, hasher); diff --git a/pkg/wallet/test/e2e.ts b/pkg/wallet/test/e2e.ts index a879ee46..8f3067db 100644 --- a/pkg/wallet/test/e2e.ts +++ b/pkg/wallet/test/e2e.ts @@ -6,15 +6,32 @@ test('Create VC SD JWT', async (t) => { t; const script = ` Rule caller restroom-mw +Scenario 'eddsa': Create the public key -Given I send holder 'holder' and send object 'object' and send fields 'fields' and create vc sd jwt and output into 'vcsdjwt' -Given I have a 'string' named 'vcsdjwt' -When done -Then print data +Given I have the 'keyring' +Given I have a 'string' named 'crv' +Given I have a 'string' named 'kty' + +When I create the eddsa public key +When I pickup from path 'keyring.eddsa' +When I rename 'eddsa' to 'd' +When I rename 'eddsa public key' to 'x' + +Then print the 'x' as 'url64' in 'jwk' +Then print the 'd' as 'url64' in 'jwk' +Then print the 'crv' as 'string' in 'jwk' +Then print the 'kty' as 'string' in 'jwk' + +Then I send jwk 'jwk' and send holder 'holder' and send object 'object' and send fields 'fields' and create vc sd jwt and output into 'vcsdjwt' `; const slangroom = new Slangroom(wallet); const res = await slangroom.execute(script, { keys: { + keyring: { + eddsa: "6c7zvt8NvhLEXFACvkJW5DVqZzutuFDkxCxCZ8mzGzSP" + }, + crv: "Ed25519", + kty: "OKP", holder: "DXXa2upAr7hgseAtFfz2NuSfmFrmx6iySvmG9PHHRq6D", object: { name: 'test person',