Skip to content

Commit

Permalink
Require keyRef for dispute and acknowledgement.
Browse files Browse the repository at this point in the history
Load key directly and don't use issuer for those status updates.
  • Loading branch information
jasny committed Jul 26, 2023
1 parent 48659e6 commit fa2a764
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/lto-credential-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
IKey,
IIdentifier,
IssuerType,
IKeyManager,
} from '@veramo/core';
import canonicalize from 'canonicalize';
import { sha256 } from '@noble/hashes/sha256';
Expand All @@ -41,7 +42,9 @@ interface LtoCredentialStatusUpdateArgs extends CredentialStatusUpdateArgs {
};
}

export type ManagerAgentContext = IAgentContext<Pick<IDIDManager, 'didManagerGet'>>;
export type ManagerAgentContext = IAgentContext<
Pick<IDIDManager, 'didManagerGet'> & Pick<IKeyManager, 'keyManagerGet'>
>;

enum StatusStatementType {
issue = 0x10,
Expand Down Expand Up @@ -90,7 +93,7 @@ export class LtoCredentialPlugin implements IAgentPlugin {
issuer: IssuerType,
agent: TAgent<Pick<IDIDManager, 'didManagerGet'>>,
): Promise<IIdentifier> {
if (!agent || !agent.didManagerGet) {
if (!agent?.didManagerGet) {
throw new Error('invalid_setup: your agent does not seem to have IDIDManager plugin installed');
}

Expand Down Expand Up @@ -195,10 +198,22 @@ export class LtoCredentialPlugin implements IAgentPlugin {
const id = base58.decode(vc.credentialStatus.id);
const statementType = StatusStatementType[status];

const identifier = await this.getIdentifier(vc.issuer, context?.agent);
const key = this.pickSigningKey(identifier, args.options.keyRef);
let key: IKey;

await this.submitStatus(id, StatusStatementType.issue, key);
if (statementType === StatusStatementType.dispute || statementType === StatusStatementType.acknowledge) {
if (!context?.agent.keyManagerGet) {
throw new Error('invalid_setup: your agent does not seem to have IKeyManager plugin installed');
}
if (!options?.keyRef) throw new Error('The keyRef option is required for dispute and acknowledge statements');

key = await context.agent.keyManagerGet({ kid: options.keyRef });
if (!key) throw Error(`key_not_found: No key with kid ${options.keyRef}`);
} else {
const identifier = await this.getIdentifier(vc.issuer, context?.agent);
key = this.pickSigningKey(identifier, options?.keyRef);
}

await this.submitStatus(id, statementType, key);
}

async credentialStatusTypes() {
Expand Down

0 comments on commit fa2a764

Please sign in to comment.