Skip to content

Commit 5ec19e6

Browse files
committed
Initial draft of id cred presentations
1 parent 3982ac7 commit 5ec19e6

File tree

5 files changed

+177
-0
lines changed

5 files changed

+177
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as VerifiablePresentationV1 from './proof.js';
2+
import * as VerifiablePresentationRequestV1 from './request.js';
3+
4+
export { VerifiablePresentationRequestV1, VerifiablePresentationV1 };
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import * as Request from './request.js';
2+
import { AccountCredDID, GivenContext, IdCredentialStatement, IdentityProviderDID } from './shared.js';
3+
4+
// Context for the proof part.
5+
// NOTE: renamed from FilledContextInformation
6+
export type Context = {
7+
type: 'ConcordiumContextInformationV1';
8+
given: GivenContext[];
9+
requested: GivenContext[];
10+
};
11+
12+
// Fails if not given the full amount of requested context.
13+
export function createContext(context: Request.Context, requestedContextData: GivenContext[]): Context {
14+
throw new Error('not implemented');
15+
}
16+
17+
type ConcordiumZKProofV4 = {
18+
type: 'ConcordiumZKProofV4';
19+
createdAt: Date; // Explicit type, JSON: ISO format
20+
proofValue: Uint8Array; // Explicit type, JSON: hex encoding of proof + aux data
21+
};
22+
23+
type WeakLinkingProofV1 = {
24+
type: 'ConcordiumWeakLinkingProofV1';
25+
created: Date;
26+
proofValue: Uint8Array[];
27+
};
28+
29+
type IDCredPubEncryption = Uint8Array; // right??
30+
31+
type IDBasedCredential = {
32+
type: ['VerifiableCredential', 'ConcordiumVerifiableCredentialV1', 'ConcordiumIDBasedCredential'];
33+
// The person this statement is about
34+
credentialSubject: {
35+
// The identity disclosure information also acts as ephemeral ID
36+
id: IDCredPubEncryption;
37+
// Statements (should match request)
38+
statements: IdCredentialStatement[];
39+
};
40+
// The zero-knowledge proof for attestation.
41+
proof: ConcordiumZKProofV4;
42+
// Issuer of the orignal ID credential
43+
issuer: IdentityProviderDID;
44+
};
45+
46+
type AccountBasedCredential = {
47+
type: ['VerifiableCredential', 'ConcordiumVerifiableCredentialV1', 'ConcordiumAccountBaseCredential'];
48+
// The person this statement is about
49+
credentialSubject: {
50+
// The id is the account credential identifier
51+
id: AccountCredDID;
52+
// Statements (should match request)
53+
statements: IdCredentialStatement[];
54+
};
55+
// The zero-knowledge proof for attestation.
56+
proof: ConcordiumZKProofV4;
57+
// The issuer of the ID credential used to open the account credential.
58+
issuer: IdentityProviderDID;
59+
};
60+
61+
type VerifiableCredential = IDBasedCredential | AccountBasedCredential;
62+
63+
// TODO: Should match the w3c spec for a verifiable presentation
64+
type JSON = void;
65+
66+
class VerifiablePresentationV1 {
67+
type = ['VerifiablePresentation', 'ConcordiumVerifiablePresentationV1'];
68+
69+
constructor(
70+
public readonly presentationContext: Context,
71+
public readonly verifiableCredential: VerifiableCredential[],
72+
public readonly proof?: WeakLinkingProofV1
73+
) {}
74+
75+
public toJSON(): JSON {}
76+
}
77+
78+
export type Type = VerifiablePresentationV1;
79+
80+
// TODO: what's the input here?
81+
export function create(request: Request.Type): VerifiablePresentationV1 {
82+
// NOTE: this calls into concordium-base bindings to generate the proof
83+
throw new Error('not implemented');
84+
}
85+
86+
export function fromJSON(json: JSON): VerifiablePresentationV1 {
87+
throw new Error('not implemented');
88+
}
89+
90+
// TODO: what's the input/output here?
91+
export function verify(request: Request.Type): unknown {
92+
// NOTE: this calls into concordium-base bindings to verify the proof
93+
throw new Error('not implemented');
94+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { TransactionHash } from '../../types/index.js';
2+
import { GivenContext, IdCredentialStatement, IdPresentationContextLabel } from './shared.js';
3+
4+
// NOTE: renamed from ContextInformation
5+
export type Context = {
6+
type: 'ConcordiumContextInformationV1';
7+
given: GivenContext[];
8+
requested: IdPresentationContextLabel[];
9+
};
10+
11+
export function getAnchor(context: Context, credentialStatements: IdCredentialStatement): Uint8Array {
12+
// NOTE: this calls into concordium-base bindings to compute the presentation anchor.
13+
throw new Error('not implemented');
14+
}
15+
16+
// TODO: Should match the w3c spec for a verifiable presentation request
17+
type JSON = void;
18+
19+
class VerifiablePresentationRequestV1 {
20+
type = 'ConcordiumVPRequestV1';
21+
22+
constructor(
23+
public readonly context: Context,
24+
public readonly credentialStatements: IdCredentialStatement[],
25+
public readonly transactionRef: TransactionHash.Type // renamed from requestTX
26+
) {}
27+
28+
public toJSON(): JSON {
29+
throw new Error('not implemented');
30+
}
31+
}
32+
33+
export type Type = VerifiablePresentationRequestV1;
34+
35+
export function fromJSON(json: JSON): VerifiablePresentationRequestV1 {
36+
throw new Error('not implemented');
37+
}
38+
39+
export function create(
40+
context: Context,
41+
credentialStatements: IdCredentialStatement[],
42+
transactionRef: TransactionHash.Type
43+
): VerifiablePresentationRequestV1 {
44+
return new VerifiablePresentationRequestV1(context, credentialStatements, transactionRef);
45+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { IdStatement } from '../../index.js';
2+
import { AccountAddress, BlockHash } from '../../types/index.js';
3+
4+
export type IdPresentationContextLabel =
5+
| 'ContextString'
6+
| 'ResourceID'
7+
| 'BlockHash'
8+
| 'PaymentHash'
9+
| 'ConnectionID'
10+
| 'Nonce';
11+
12+
export type GivenContext = {
13+
label: IdPresentationContextLabel;
14+
context: Uint8Array | string | BlockHash.Type; // TODO: make explicit variants with unknown represented as hex string.
15+
};
16+
17+
type CredType = 'IdentityCredential' | 'AccountCredential' | 'IdentityOrAccountCredential'; // whats the use of the last one here?
18+
19+
// TODO: figure out the correct way to represent as DID.
20+
export type IdentityProviderDID = number;
21+
22+
// TODO: figure out the correct way to represent as DID.
23+
export type AccountCredDID = AccountAddress.Type;
24+
25+
type IdCredentialQualifier = {
26+
type: CredType;
27+
issuers: IdentityProviderDID[];
28+
};
29+
30+
export type IdCredentialStatement = {
31+
statement: IdStatement; // we reuse the id statement as there should not be any difference here?
32+
idQualifier: IdCredentialQualifier;
33+
};

packages/sdk/src/wasm/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './HdWallet.js';
99
export * from './identity.js';
1010
export * from './credentialDeploymentTransactions.js';
1111
export * from './web3Id.js';
12+
export * from './VerifiablePresentationV1/index.js';

0 commit comments

Comments
 (0)