Skip to content

Commit a5e2893

Browse files
committed
A little bit of renaming + usability improvements
1 parent 5b3ea25 commit a5e2893

File tree

8 files changed

+124
-102
lines changed

8 files changed

+124
-102
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
- renamed `VerifiableCredentialQualifier` to `Web3IdCredentialQualifier`
1313
- renamed `VerifiableCredentialStatement` to `Web3IdCredentialStatement`
1414
- renamed `IdentityQualifier` to `AccountCredentialQualifier`
15-
- renamed `RequestStatement` to `CredentialRequestStatement`, which is now a union of
16-
`AccountCredentialStatement | Web3IdCredentialStatement | IdentityCredentialStatement` instead of the corresponding
17-
old dynamic version.
15+
- renamed `RequestStatement` to `SpecifiedCredentialStatement`, which is now a union of
16+
`SpecifiedAccountCredentialStatement | SpecifiedWeb3IdCredentialStatement | SpecifiedIdentityCredentialStatement`
17+
instead of the corresponding old dynamic version.
1818

1919
### Added
2020

2121
- `Web3StatementBuilder.forIdentityCredentials`, used for statements for identity credentials without tying it to an account
2222
- types `IdentityCredentialQualifier`, `IdentityCommitmentInput`, and `CredentialsInputsIdentity` which have been added
2323
to the respective union types that reflect the possible variants.
2424
- helper functions `createIdentityCommitmentInput` and `createIdentityCommitmentInputWithHdWallet`
25+
- helper function `createIdentityDID`
2526

2627
- types `VerifiablePresentationV1` and `VerifiablePresentationRequestV1` to be used with the new zero-knowledge proof
2728
protocol
@@ -32,6 +33,8 @@
3233
- `VerifiablePresentationV1.createFromAnchor` which is a GRPC helper function for creating a verifiable presentation
3334
from a minimal set of values. This also creates the `VerifiablePresentation.Context` from the corresponding
3435
`VerifiablePresentationRequestV1.Context`.
36+
- `VerifiablePresentationV1.verify`, and the corresponding GRPC helper `VerifiablePresentationV1.verifyWithNode` for
37+
verification of the proof.
3538
- **Please note**: some functionality related to this is currently either stubbed or routed into the old verifiable
3639
presentation computation functions for now.
3740

packages/sdk/src/commonProofTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface StatementBuilder<ValueType, AttributeType> {
1+
export interface StatementBuilder<AttributeType, ValueType> {
22
addRange(attribute: AttributeType, lower: ValueType, upper: ValueType): this;
33

44
addMembership(attribute: AttributeType, set: ValueType[]): this;

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

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import { bail } from '../../util.js';
2222
import {
2323
AtomicStatementV2,
2424
CommitmentInput,
25-
CredentialRequestStatement,
2625
CredentialsInputs,
2726
DIDString,
2827
IdentityCommitmentInput,
29-
IdentityCredentialRequestStatement,
30-
isAccountCredentialRequestStatement,
31-
isIdentityCredentialRequestStatement,
28+
SpecifiedCredentialStatement,
29+
SpecifiedIdentityCredentialStatement,
30+
isSpecifiedAccountCredentialStatement,
31+
isSpecifiedIdentityCredentialStatement,
3232
} from '../../web3-id/index.js';
3333
import { Web3IdProofRequest, getVerifiablePresentation } from '../web3Id.js';
3434
import { GivenContextJSON, givenContextFromJSON, givenContextToJSON } from './internal.js';
@@ -72,7 +72,7 @@ export type IdentityBasedCredential = {
7272
};
7373

7474
function createIdentityCredentialStub(
75-
{ id, statement }: IdentityCredentialRequestStatement,
75+
{ id, statement }: SpecifiedIdentityCredentialStatement,
7676
ipIndex: number
7777
): IdentityBasedCredential {
7878
const network = id.split(':')[1] as Network;
@@ -170,11 +170,11 @@ export function fromJSON(value: JSON): VerifiablePresentationV1 {
170170
export async function createFromAnchor(
171171
grpc: ConcordiumGRPCClient,
172172
presentationRequest: Request.Type,
173-
requestStatements: CredentialRequestStatement[],
173+
statements: SpecifiedCredentialStatement[],
174174
inputs: CommitmentInput[],
175-
additionalContext: GivenContext[],
176-
globalContext: CryptographicParameters
175+
additionalContext: GivenContext[]
177176
): Promise<VerifiablePresentationV1> {
177+
const globalContext = await grpc.getCryptographicParameters();
178178
const transaction = await grpc.getBlockItemStatus(presentationRequest.transactionRef);
179179
if (transaction.status !== TransactionStatusEnum.Finalized) {
180180
throw new Error('anchor reference not finalized');
@@ -201,24 +201,24 @@ export async function createFromAnchor(
201201

202202
const blockContext: GivenContext = { label: 'BlockHash', context: blockHash };
203203
const proofContext = createContext(presentationRequest.requestContext, [...additionalContext, blockContext]);
204-
return create(requestStatements, inputs, proofContext, globalContext);
204+
return create(statements, inputs, proofContext, globalContext);
205205
}
206206

207207
// TODO: this entire function should call a function in @concordium/rust-bindings to create the verifiable
208208
// presentation from the function arguments. For now, we hack something together from the old protocol which
209209
// means filtering and mapping the input/output.
210210
export function create(
211-
requestStatements: CredentialRequestStatement[],
211+
requestStatements: SpecifiedCredentialStatement[],
212212
inputs: CommitmentInput[],
213213
proofContext: Context,
214214
globalContext: CryptographicParameters
215215
): VerifiablePresentationV1 {
216216
// first we filter out the id statements, as they're not compatible with the current implementation
217217
// in concordium-base
218-
const idStatements: [number, IdentityCredentialRequestStatement][] = [];
219-
const compatibleStatements: Exclude<CredentialRequestStatement, IdentityCredentialRequestStatement>[] = [];
218+
const idStatements: [number, SpecifiedIdentityCredentialStatement][] = [];
219+
const compatibleStatements: Exclude<SpecifiedCredentialStatement, SpecifiedIdentityCredentialStatement>[] = [];
220220
requestStatements.forEach((s, i) => {
221-
if (isIdentityCredentialRequestStatement(s)) idStatements.push([i, s]);
221+
if (isSpecifiedIdentityCredentialStatement(s)) idStatements.push([i, s]);
222222
else compatibleStatements.push(s);
223223
});
224224

@@ -240,7 +240,7 @@ export function create(
240240
const compatibleCredentials: Credential[] = verifiableCredential.map<Credential>((c, i) => {
241241
const { proof, ...credentialSubject } = c.credentialSubject;
242242
const { created, type: _type, ...proofValues } = proof;
243-
const type = isAccountCredentialRequestStatement(compatibleStatements[i])
243+
const type = isSpecifiedAccountCredentialStatement(compatibleStatements[i])
244244
? 'ConcordiumAccountBasedCredential'
245245
: 'ConcordiumWeb3BasedCredential';
246246
return {
@@ -281,3 +281,12 @@ export function verify(
281281
): true | Error {
282282
return true;
283283
}
284+
285+
export async function verifyWithNode(
286+
presentation: VerifiablePresentationV1,
287+
request: Request.Type,
288+
grpc: ConcordiumGRPCClient,
289+
network: Network
290+
): Promise<true | Error> {
291+
return true;
292+
}

packages/sdk/src/wasm/web3Id.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import { VerifiablePresentation } from '../types/VerifiablePresentation.js';
66
import { VerifyWeb3IdCredentialSignatureInput } from '../web3-id/helpers.js';
77
import {
88
CommitmentInput,
9-
CredentialRequestStatement,
109
CredentialsInputs,
11-
isIdentityCredentialRequestStatement,
10+
SpecifiedCredentialStatement,
11+
isSpecifiedIdentityCredentialStatement,
1212
} from '../web3-id/types.js';
1313

1414
/**
@@ -21,7 +21,7 @@ export function verifyWeb3IdCredentialSignature(input: VerifyWeb3IdCredentialSig
2121

2222
export type Web3IdProofRequest = {
2323
challenge: string;
24-
credentialStatements: CredentialRequestStatement[];
24+
credentialStatements: SpecifiedCredentialStatement[];
2525
};
2626

2727
export type Web3IdProofInput = {
@@ -35,7 +35,7 @@ export type Web3IdProofInput = {
3535
*/
3636
export function getVerifiablePresentation(input: Web3IdProofInput): VerifiablePresentation {
3737
// validate that we don't pass any unsupported credentials in
38-
if (input.request.credentialStatements.some((statement) => isIdentityCredentialRequestStatement(statement)))
38+
if (input.request.credentialStatements.some((statement) => isSpecifiedIdentityCredentialStatement(statement)))
3939
throw new Error('Identity proofs are not supported for this verifiable presentation protocol');
4040

4141
try {

0 commit comments

Comments
 (0)