Skip to content

Commit

Permalink
Improve canProveCredentialStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjort committed Aug 15, 2023
1 parent cadc3a7 commit 5c48fea
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/common/src/web3ProofTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,16 @@ export type CredentialStatement = {
export type RequestStatement = {
id: string;
statement: AtomicStatementV2[];
/** The type field is present iff the request is for a verifiable credential */
type?: string[];
};

export function isVerifiableCredentialRequestStatement(
statement: RequestStatement
): boolean {
return Boolean(statement.type);
}

export type CredentialStatements = CredentialStatement[];

export type CredentialSubject = {
Expand Down
14 changes: 6 additions & 8 deletions packages/common/src/web3Proofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,14 +560,13 @@ export function createWeb3CommitmentInputWithHdWallet(
}

/**
* Given an atomic statement and an identity's attributes, determine whether the identity fulfills the statement.
* Given an atomic statement and a prover's attributes, determine whether the statement is fulfilled.
*/
export function canProveAtomicStatement(
statement: AtomicStatementV2,
attributeList: AttributeList
attributes: Record<string, string | bigint>
): boolean {
const attribute =
attributeList.chosenAttributes[statement.attributeTag as AttributeKey];
const attribute = attributes[statement.attributeTag];
switch (statement.type) {
case StatementTypes.AttributeInSet:
return statement.set.includes(attribute);
Expand All @@ -585,14 +584,13 @@ export function canProveAtomicStatement(
}

/**
* Given a credential statement and an identity's attributes, determine whether the identity fulfills the statement.
* TODO fix this
* Given a credential statement and a prover's attributes, determine whether the statements are fulfilled.
*/
export function canProveCredentialStatement(
credentialStatement: CredentialStatement,
attributeList: AttributeList
attributes: Record<string, string | bigint>
): boolean {
return credentialStatement.statement.every((statement) =>
canProveAtomicStatement(statement, attributeList)
canProveAtomicStatement(statement, attributes)
);
}

0 comments on commit 5c48fea

Please sign in to comment.