Skip to content

Commit 6caa897

Browse files
committed
Add documentation
1 parent e83f346 commit 6caa897

File tree

6 files changed

+246
-27
lines changed

6 files changed

+246
-27
lines changed

docs/pages/verifiable-presentations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This document describes how to create v1 verifiable presentations and how to ver
1818
The SDK contains a helper to create statements about identities, which can
1919
then be proven.
2020

21-
To do so, use the CredentialStatementBuilder, to build a statement:
21+
To do so, use the _presentation request statement builder_, to build a statement:
2222

2323
{@codeblock ~~:nodejs/common/verifiable-credential-statements.ts#documentation-snippet}
2424

packages/sdk/src/types/VerifiablePresentation.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@ import JSONBigInt from 'json-bigint';
22

33
import { AtomicProof, GenericAtomicStatement } from '../commonProofTypes.js';
44
import { HexString } from '../types.js';
5-
import {
6-
AccountCommitmentInput,
7-
AttributeType,
8-
CredentialsInputsAccount,
9-
CredentialsInputsWeb3,
10-
DIDString,
11-
Web3IssuerCommitmentInput,
12-
} from '../web3-id/types.js';
5+
import { AttributeType, DIDString } from '../web3-id/types.js';
136

147
/**
158
* A proof that establishes that the owner of the credential has indeed created

packages/sdk/src/wasm/VerifiablePresentationV1/proof.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,28 @@ export type Context = {
4949
requested: GivenContext[];
5050
};
5151

52+
/**
53+
* Statement proving attributes from an account credential.
54+
* Contains the account credential DID and atomic statements about account attributes.
55+
*/
5256
export type AccountStatement = { id: DIDString; statement: AtomicStatementV2<AttributeKey>[] };
57+
58+
/**
59+
* Statement proving attributes from an identity credential issued by an identity provider.
60+
* Contains the identity DID and atomic statements about identity attributes.
61+
*/
5362
export type IdentityStatement = { id: DIDString; statement: AtomicStatementV2<AttributeKey>[] };
63+
64+
/**
65+
* Statement proving attributes from a Web3 ID credential.
66+
* Contains the Web3 ID DID, atomic statements about Web3 attributes, and credential type information.
67+
*/
5468
export type Web3IdStatement = { id: DIDString; statement: AtomicStatementV2<string>[]; type: string[] };
5569

70+
/**
71+
* Union type representing all supported statement types in a verifiable presentation.
72+
* Each statement contains proofs about specific credential attributes.
73+
*/
5674
export type Statement = IdentityStatement | Web3IdStatement | AccountStatement;
5775

5876
function isSpecifiedAccountCredentialStatement(statement: Statement): statement is AccountStatement {
@@ -256,6 +274,11 @@ export function fromJSON(value: JSON): VerifiablePresentationV1 {
256274
return new VerifiablePresentationV1(presentationContext, value.verifiableCredential, value.proof);
257275
}
258276

277+
/**
278+
* Union type of all commitment input types used for generating zero-knowledge proofs.
279+
* These inputs contain the secret information needed to create proofs without revealing
280+
* the actual credential data.
281+
*/
259282
export type CommitmentInput = IdentityCommitmentInput | Web3IssuerCommitmentInput | AccountCommitmentInput;
260283

261284
/**
@@ -400,6 +423,10 @@ export function create(
400423
*/
401424
export type VerificationResult = { type: 'success' } | { type: 'failed'; error: Error };
402425

426+
/**
427+
* Union type of all credential input types used for verification.
428+
* These inputs contain the public credential data needed to verify proofs.
429+
*/
403430
export type CredentialsInputs = CredentialsInputsWeb3 | CredentialsInputsAccount | CredentialsInputsIdentity;
404431

405432
/**

packages/sdk/src/wasm/VerifiablePresentationV1/request.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,26 +186,54 @@ export type JSON = {
186186
transactionRef: TransactionHash.JSON;
187187
};
188188

189+
/**
190+
* Type of identity credential source that can be used for proving attributes.
191+
*/
189192
type IdentityCredType = 'identity' | 'account';
190193

194+
/**
195+
* Statement requesting proofs from identity credentials issued by identity providers.
196+
* Can specify whether to accept proofs from identity credentials, account credentials, or both.
197+
*/
191198
export type IdentityStatement = {
199+
/** Type discriminator for identity statements */
192200
type: 'identity';
193-
source: IdentityCredType[]; // Should never be empty, and always maximum all values from `IdentityCredType`.
201+
/** Source types accepted for this statement (identity credential, account credential, or both) */
202+
source: IdentityCredType[];
203+
/** Atomic statements about identity attributes to prove */
194204
statement: AtomicStatementV2<AttributeKey>[];
205+
/** Valid identity provider issuers for this statement */
195206
issuers: IdentityProviderDID[];
196207
};
197208

209+
/**
210+
* Statement requesting proofs from Web3 ID credentials issued by smart contracts.
211+
*/
198212
export type Web3IdStatement = {
213+
/** Type discriminator for Web3 ID statements */
199214
type: 'web3Id';
215+
/** Atomic statements about Web3 ID attributes to prove */
200216
statement: AtomicStatementV2<string>[];
217+
/** Valid smart contract issuers for this statement */
201218
issuers: ContractInstanceDID[];
202219
};
203220

221+
/**
222+
* Union type representing all supported statement types in a verifiable presentation request.
223+
*/
204224
export type Statement = IdentityStatement | Web3IdStatement;
225+
226+
/**
227+
* JSON representation of statements with issuer DIDs serialized as strings.
228+
*/
205229
type StatementJSON = (Omit<IdentityStatement, 'issuers'> | Omit<Web3IdStatement, 'issuers'>) & {
206230
issuers: DIDString[];
207231
};
208232

233+
/**
234+
* Builder class for constructing credential statement requests.
235+
* Provides methods to add different types of credential statements with their requirements.
236+
*/
209237
class StatementBuilder {
210238
/** Array of credential statements being built. */
211239
private statements: Statement[] = [];
@@ -312,6 +340,11 @@ class StatementBuilder {
312340
}
313341
}
314342

343+
/**
344+
* Creates a new statement builder for constructing credential requests.
345+
*
346+
* @returns A new statement builder instance
347+
*/
315348
export function statementBuilder(): StatementBuilder {
316349
return new StatementBuilder();
317350
}

packages/sdk/src/web3-id/proofs.ts

Lines changed: 98 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ function getAccountCredentialQualifier(validIdentityProviders: number[]): Identi
292292
};
293293
}
294294

295+
/**
296+
* Builder class for constructing atomic statements about credential attributes.
297+
* Provides a fluent API for adding range, membership, and reveal statements with validation.
298+
*/
295299
export class AtomicStatementBuilder<AttributeKey = string> implements InternalBuilder<AttributeKey> {
296300
/** Array of atomic statements being built. */
297301
statements: AtomicStatementV2<AttributeKey>[];
@@ -395,6 +399,11 @@ export class AtomicStatementBuilder<AttributeKey = string> implements InternalBu
395399
}
396400
}
397401

402+
/**
403+
* Specialized builder for account/identity credential statements.
404+
* Extends AtomicStatementBuilder with convenience methods for common identity attributes
405+
* like age, residency, and document expiry.
406+
*/
398407
export class AccountStatementBuild extends AtomicStatementBuilder<AttributeKey> {
399408
/**
400409
* Add to the statement that the age is at minimum the given value.
@@ -456,7 +465,11 @@ export class AccountStatementBuild extends AtomicStatementBuilder<AttributeKey>
456465

457466
/** Internal type alias for statement builders. */
458467
type InternalBuilder<AttributeKey> = StatementBuilder<StatementAttributeType, AttributeKey>;
459-
/** Builder class for constructing credential statements with different credential types. */
468+
469+
/**
470+
* Builder class for constructing credential statements for the original verifiable presentation protocol.
471+
* Supports both Web3 ID credentials and account/identity credentials with issuer qualifiers.
472+
*/
460473
export class Web3StatementBuilder {
461474
/** Array of credential statements being built. */
462475
private statements: CredentialStatements = [];
@@ -516,7 +529,14 @@ export class Web3StatementBuilder {
516529
}
517530

518531
/**
519-
* Create a DID string for a web3id credential. Used to build a request for a verifiable credential.
532+
* Creates a DID string for a Web3 ID credential.
533+
* Used to build a request for a verifiable credential issued by a smart contract.
534+
*
535+
* @param network - The Concordium network
536+
* @param publicKey - The public key of the credential holder
537+
* @param index - The contract index
538+
* @param subindex - The contract subindex
539+
* @returns DID string in format: did:ccd:{network}:sci:{index}:{subindex}/credentialEntry/{publicKey}
520540
*/
521541
export function createWeb3IdDID(network: Network, publicKey: string, index: bigint, subindex: bigint): DIDString {
522542
return (
@@ -532,22 +552,40 @@ export function createWeb3IdDID(network: Network, publicKey: string, index: bigi
532552
}
533553

534554
/**
535-
* Create a DID string for a web3id credential. Used to build a request for a verifiable credential.
555+
* Creates a DID string for an account credential.
556+
* Used to build a request for a verifiable credential based on an account credential.
557+
*
558+
* @param network - The Concordium network
559+
* @param credId - The credential ID (registration ID)
560+
* @returns DID string in format: did:ccd:{network}:cred:{credId}
536561
*/
537562
export function createAccountDID(network: Network, credId: string): DIDString {
538563
return 'did:ccd:' + network.toLowerCase() + ':cred:' + credId;
539564
}
540565

541566
/**
542-
* Create a DID string for an identity credential. Used to build a request for a verifiable credential.
567+
* Creates a DID string for an identity credential.
568+
* Used to build a request for a verifiable credential based on an identity object.
569+
*
570+
* @param network - The Concordium network
571+
* @param identityProviderIndex - The index of the identity provider that issued the identity
572+
* @param identityIndex - The index of the identity
573+
* @returns DID string in format: did:ccd:{network}:id:{identityProviderIndex}:{identityIndex}
543574
*/
544575
// TODO: figure out if this matches the identifier.
545576
export function createIdentityDID(network: Network, identityProviderIndex: number, identityIndex: number): DIDString {
546577
return 'did:ccd:' + network.toLowerCase() + ':id:' + identityProviderIndex + ':' + identityIndex;
547578
}
548579

549580
/**
550-
* Create the commitment input required to create a proof for the given statements, using an account credential.
581+
* Creates the commitment input required to generate a proof for account credential statements.
582+
* The commitment input contains the attribute values and randomness needed for zero-knowledge proofs.
583+
*
584+
* @param statements - The atomic statements to prove
585+
* @param identityProvider - The identity provider index that issued the credential
586+
* @param attributes - The credential holder's attributes
587+
* @param randomness - Randomness values for commitments, keyed by attribute index
588+
* @returns Account commitment input for proof generation
551589
*/
552590
export function createAccountCommitmentInput(
553591
statements: AtomicStatementV2[],
@@ -571,8 +609,16 @@ export function createAccountCommitmentInput(
571609
}
572610

573611
/**
574-
* Create the commitment input required to create a proof for the given statements, using an account credential.
575-
* Uses a ConcordiumHdWallet to get randomness needed.
612+
* Creates the commitment input required to generate a proof for account credential statements.
613+
* Uses a ConcordiumHdWallet to derive the necessary randomness values.
614+
*
615+
* @param statements - The atomic statements to prove
616+
* @param identityProvider - The identity provider index that issued the credential
617+
* @param attributes - The credential holder's attributes
618+
* @param wallet - The HD wallet for deriving randomness
619+
* @param identityIndex - The identity index in the wallet
620+
* @param credIndex - The credential index in the wallet
621+
* @returns Account commitment input for proof generation
576622
*/
577623
export function createAccountCommitmentInputWithHdWallet(
578624
statements: AtomicStatementV2[],
@@ -597,7 +643,14 @@ export function createAccountCommitmentInputWithHdWallet(
597643
}
598644

599645
/**
600-
* Create the commitment input required to create a proof for the given statements, using an web3Id credential.
646+
* Creates the commitment input required to generate a proof for Web3 ID credential statements.
647+
* The commitment input contains the attribute values, randomness, and signature needed for proofs.
648+
*
649+
* @param verifiableCredentialPrivateKey - The private key for signing the credential
650+
* @param credentialSubject - The credential subject with attributes
651+
* @param randomness - Randomness values for commitments, keyed by attribute name
652+
* @param signature - The credential signature
653+
* @returns Web3 issuer commitment input for proof generation
601654
*/
602655
export function createWeb3CommitmentInput(
603656
verifiableCredentialPrivateKey: HexString,
@@ -615,8 +668,16 @@ export function createWeb3CommitmentInput(
615668
}
616669

617670
/**
618-
* Create the commitment input required to create a proof for the given statements, using an web3Id credential.
619-
* Uses a ConcordiumHdWallet to supply the public key and the signing key of the credential.
671+
* Creates the commitment input required to generate a proof for Web3 ID credential statements.
672+
* Uses a ConcordiumHdWallet to derive the credential signing key.
673+
*
674+
* @param wallet - The HD wallet for deriving the signing key
675+
* @param issuer - The contract address of the credential issuer
676+
* @param credentialIndex - The credential index in the wallet
677+
* @param credentialSubject - The credential subject with attributes
678+
* @param randomness - Randomness values for commitments, keyed by attribute name
679+
* @param signature - The credential signature
680+
* @returns Web3 issuer commitment input for proof generation
620681
*/
621682
export function createWeb3CommitmentInputWithHdWallet(
622683
wallet: ConcordiumHdWallet,
@@ -635,7 +696,13 @@ export function createWeb3CommitmentInputWithHdWallet(
635696
}
636697

637698
/**
638-
* Create the commitment input required to create a proof for the given statements, using an identity credential.
699+
* Creates the commitment input required to generate a proof for identity credential statements.
700+
* The commitment input contains the identity object and secrets needed for zero-knowledge proofs.
701+
*
702+
* @param identityProvider - The identity provider that issued the identity
703+
* @param idObject - The identity object containing identity information
704+
* @param idObjectUseData - Additional data required for using the identity object
705+
* @returns Identity commitment input for proof generation
639706
*/
640707
export function createIdentityCommitmentInput(
641708
identityProvider: IdentityProvider,
@@ -657,8 +724,14 @@ export function createIdentityCommitmentInput(
657724
}
658725

659726
/**
660-
* Create the commitment input required to create a proof for the given statements, using an identity credential.
661-
* Uses a ConcordiumHdWallet to get values for the {@linkcode IdObjectUseData}.
727+
* Creates the commitment input required to generate a proof for identity credential statements.
728+
* Uses a ConcordiumHdWallet to derive the identity secrets (PRF key, ID cred secret, randomness).
729+
*
730+
* @param idObject - The identity object containing identity information
731+
* @param identityProvider - The identity provider that issued the identity
732+
* @param identityIndex - The identity index in the wallet
733+
* @param wallet - The HD wallet for deriving identity secrets
734+
* @returns Identity commitment input for proof generation
662735
*/
663736
export function createIdentityCommitmentInputWithHdWallet(
664737
idObject: IdentityObjectV1,
@@ -712,7 +785,12 @@ function isInSet(value: AttributeType, set: AttributeType[]) {
712785
}
713786

714787
/**
715-
* Given an atomic statement and a prover's attributes, determine whether the statement is fulfilled.
788+
* Checks whether a prover can fulfill an atomic statement with their attributes.
789+
* Validates that the prover has the required attribute and that it satisfies the statement constraints.
790+
*
791+
* @param statement - The atomic statement to check
792+
* @param attributes - The prover's attributes
793+
* @returns True if the statement can be proven with the given attributes
716794
*/
717795
export function canProveAtomicStatement(
718796
statement: AtomicStatementV2,
@@ -739,7 +817,12 @@ export function canProveAtomicStatement(
739817
}
740818

741819
/**
742-
* Given a credential statement and a prover's attributes, determine whether the statements are fulfilled.
820+
* Checks whether a prover can fulfill all atomic statements in a credential statement.
821+
* Returns true only if all atomic statements can be proven with the given attributes.
822+
*
823+
* @param credentialStatement - The credential statement containing multiple atomic statements
824+
* @param attributes - The prover's attributes
825+
* @returns True if all statements can be proven with the given attributes
743826
*/
744827
export function canProveCredentialStatement(
745828
credentialStatement: CredentialStatement,

0 commit comments

Comments
 (0)