Skip to content

Commit

Permalink
feat(credential-w3c): added support bbs proofformat (#1383)
Browse files Browse the repository at this point in the history
  • Loading branch information
veromassera authored Jun 13, 2024
1 parent 6029625 commit 83cc115
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/core-types/src/types/ICredentialIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { UsingResolutionOptions } from './ICredentialVerifier.js'
*
* @public
*/
export type ProofFormat = 'jwt' | 'lds' | 'EthereumEip712Signature2021'
export type ProofFormat = 'jwt' | 'lds' | 'EthereumEip712Signature2021' | 'bbs'

/**
* Encapsulates the parameters required to create a
Expand Down
76 changes: 68 additions & 8 deletions packages/credential-w3c/src/action-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const enum DocumentFormat {
JWT,
JSONLD,
EIP712,
BBS
}

const debug = Debug('veramo:w3c:action-handler')
Expand Down Expand Up @@ -139,8 +140,15 @@ export class CredentialPlugin implements IAgentPlugin {
const key = pickSigningKey(identifier, keyRef)

let verifiablePresentation: VerifiablePresentation

if (proofFormat === 'lds') {
if (proofFormat === 'bbs') {
if (typeof context.agent.createVerifiablePresentationBbs === 'function') {
verifiablePresentation = await context. agent.createVerifiablePresentationBbs({ ...args, presentation })
}
else {
throw new Error('invalid_setup: your agent does not seem to have ICredentialIssuerBbs plugin installed')
}
}
else if (proofFormat === 'lds') {
if (typeof context.agent.createVerifiablePresentationLD === 'function') {
verifiablePresentation = await context.agent.createVerifiablePresentationLD({ ...args, presentation })
} else {
Expand Down Expand Up @@ -225,7 +233,15 @@ export class CredentialPlugin implements IAgentPlugin {
}
try {
let verifiableCredential: VerifiableCredential
if (proofFormat === 'lds') {
if (proofFormat === 'bbs') {
if (typeof context.agent.createVerifiableCredentialBbs === 'function') {
verifiableCredential = await context.agent.createVerifiableCredentialBbs({ ...args, credential })
}
else {
throw new Error('invalid_setup: your agent does not seem to have ICredentialIssuerBbs plugin installed')
}
}
else if (proofFormat === 'lds') {
if (typeof context.agent.createVerifiableCredentialLD === 'function') {
verifiableCredential = await context.agent.createVerifiableCredentialLD({ ...args, credential })
} else {
Expand Down Expand Up @@ -372,7 +388,26 @@ export class CredentialPlugin implements IAgentPlugin {

verificationResult = await context.agent.verifyCredentialLD({ ...args, now: policies?.now })
verifiedCredential = <VerifiableCredential>credential
} else {
} else if (type == DocumentFormat.BBS) {
if (typeof context.agent.verifyCredentialBbs!== 'function') {
throw new Error('invalid_setup: your agent does not seem to have ICredentialIssuerBbs plugin installed')
}
try {
verificationResult = await context.agent.verifyCredentialBbs({ ...args, now: policies?.now })
verifiedCredential = <VerifiableCredential>credential
}
catch (e) {
debug('encountered error while verifying BBS credential: %o', e)
const { message, errorCode } = e
return {
verified: false,
error: {
message,
errorCode: errorCode ? errorCode : e.message.split(':')[0],
},
}
}
} else {
throw new Error('invalid_argument: Unknown credential type.')
}

Expand Down Expand Up @@ -478,11 +513,31 @@ export class CredentialPlugin implements IAgentPlugin {
verified: false,
error: {
message,
errorCode: errorCode ? errorCode : e.message.split(':')[0],
},
}
errorCode: errorCode ? errorCode : e.message.split(':')[0],
},
};
}
}
} else {
else if (type === DocumentFormat.BBS) {
//Bbs
if (typeof context.agent.verifyPresentationBbs !== 'function') {
throw new Error('invalid_setup: your agent does not seem to have ICredentialIssuerBbs plugin installed')
}
try {
const result = await context.agent.verifyPresentationBbs(args)
return result;
}
catch (e) {
const { message, errorCode } = e;
return {
verified: false,
error: {
message,
errorCode: errorCode ? errorCode : e.message.split(':')[0],
},
}
}
} else {
// JSON-LD
if (typeof context.agent.verifyPresentationLD === 'function') {
const result = await context.agent.verifyPresentationLD({ ...args, now: policies?.now })
Expand Down Expand Up @@ -534,6 +589,11 @@ export class CredentialPlugin implements IAgentPlugin {
signingOptions.push('EthereumEip712Signature2021')
}
}
if (context.agent.availableMethods().includes('matchKeyForBbs')) {
if (await context.agent.matchKeyForBbs(key)) {
signingOptions.push('bbs');
}
}
}
return signingOptions
}
Expand Down

0 comments on commit 83cc115

Please sign in to comment.