Skip to content

Commit

Permalink
feat: allow secp256r1 key type for JWT VC issuance (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
martines3000 authored Jun 27, 2023
1 parent e2d7966 commit 2ce7056
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/credential-w3c/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class CredentialPlugin implements IAgentPlugin {
throw new Error('invalid_argument: presentation.holder must be a DID managed by this agent')
}
//FIXME: `args` should allow picking a key or key type
const key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519')
const key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519' || k.type === 'Secp256r1')
if (!key) throw Error('key_not_found: No signing key for ' + identifier.did)

let verifiablePresentation: VerifiablePresentation
Expand Down Expand Up @@ -165,9 +165,11 @@ export class CredentialPlugin implements IAgentPlugin {
let alg = 'ES256K'
if (key.type === 'Ed25519') {
alg = 'EdDSA'
} else if (key.type === 'Secp256r1') {
alg = 'ES256'
}
const signer = wrapSigner(context, key, alg)

const signer = wrapSigner(context, key, alg)
const jwt = await createVerifiablePresentationJwt(
presentation as any,
{ did: identifier.did, signer, alg },
Expand Down Expand Up @@ -236,14 +238,17 @@ export class CredentialPlugin implements IAgentPlugin {
}
} else {
//FIXME: `args` should allow picking a key or key type
const key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519')
const key = identifier.keys.find((k) => k.type === 'Secp256k1' || k.type === 'Ed25519' || k.type === 'Secp256r1')
if (!key) throw Error('No signing key for ' + identifier.did)

debug('Signing VC with', identifier.did)
let alg = 'ES256K'
if (key.type === 'Ed25519') {
alg = 'EdDSA'
} else if (key.type === 'Secp256r1') {
alg = 'ES256'
}

const signer = wrapSigner(context, key, alg)
const jwt = await createVerifiableCredentialJwt(
credential as any,
Expand Down

0 comments on commit 2ce7056

Please sign in to comment.