Skip to content

Commit

Permalink
import eddsa using JWK
Browse files Browse the repository at this point in the history
  • Loading branch information
albertolerda committed Nov 7, 2023
1 parent 6e2eec7 commit d184b1a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions pkg/wallet/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
7 changes: 4 additions & 3 deletions pkg/wallet/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -34,14 +34,15 @@ const hasher: HasherConfig = {
};

const createVCSDJWT = async (ctx: PluginContext): Promise<PluginResult> => {
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);

Expand Down
25 changes: 21 additions & 4 deletions pkg/wallet/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

This comment has been minimized.

Copy link
@jaromil

jaromil Nov 7, 2023

Member

How comes this sentence mentions 'object' and 'fields' but in no other place of the zencode these objects are mentioned? This is counter-intuitive as it is unclear from the Zencode where they come from.
If they are implicitly created by the statement, then they need no naming...

This comment has been minimized.

Copy link
@albertolerda

albertolerda Nov 7, 2023

Author Member

yes, this is a bug we have to look at in the core.

`;
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',
Expand Down

0 comments on commit d184b1a

Please sign in to comment.