Skip to content

Commit

Permalink
Support Circom predicates involving multiple credentials
Browse files Browse the repository at this point in the history
Signed-off-by: lovesh <lovesh.bond@gmail.com>
  • Loading branch information
lovesh committed Oct 31, 2023
1 parent be1ddb5 commit c2bff4d
Show file tree
Hide file tree
Showing 15 changed files with 1,308 additions and 584 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/crypto-wasm-ts",
"version": "0.49.0",
"version": "0.50.0",
"description": "Typescript abstractions over Dock's Rust crypto library's WASM wrapper",
"homepage": "https://github.com/docknetwork/crypto-wasm-ts",
"main": "lib/index.js",
Expand Down
40 changes: 31 additions & 9 deletions src/anonymous-credentials/blinded-credential-request-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import {
BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES,
BBS_SIGNATURE_PARAMS_LABEL_BYTES,
BlindedAttributeEquality,
BlindSignatureTypes,
BlindSignatureType,
BoundCheckParamType,
BoundType,
PublicKey,
SignatureParams,
SUBJECT_STR,
VerifiableEncryptionProtocols
VerifiableEncryptionProtocol
} from './types-and-consts';
import { AccumulatorPublicKey, AccumulatorWitness } from '../accumulator';
import { LegoProvingKey, LegoProvingKeyUncompressed } from '../legosnark';
Expand All @@ -36,7 +36,7 @@ import { BBSSignatureParams } from '../bbs';
import { BBSPlusSignatureParamsG1 } from '../bbs-plus';
import { BytearrayWrapper } from '../bytearray-wrapper';
import {
IPresentedAttributeBounds,
IPresentedAttributeBound,
IPresentedAttributeInequality,
IPresentedAttributeVE
} from './presentation-specification';
Expand Down Expand Up @@ -72,7 +72,7 @@ export abstract class BlindedCredentialRequestBuilder<SigParams> extends Version
attributeInequalities: Map<string, [IPresentedAttributeInequality, Uint8Array][]>;

// Bounds on blinded attributes
bounds: Map<string, IPresentedAttributeBounds[]>;
bounds: Map<string, IPresentedAttributeBound[]>;

// Encryption of blinded attributes
verifEnc: Map<string, IPresentedAttributeVE[]>;
Expand Down Expand Up @@ -127,7 +127,7 @@ export abstract class BlindedCredentialRequestBuilder<SigParams> extends Version

abstract getBlinding(): Uint8Array | undefined;

static getSigType(): BlindSignatureTypes {
static getSigType(): BlindSignatureType {
throw new Error('This method should be implemented by extending class');
}

Expand Down Expand Up @@ -222,6 +222,28 @@ export abstract class BlindedCredentialRequestBuilder<SigParams> extends Version
);
}

enforceCircomPredicateAcrossMultipleCredentials(
// For each circuit private variable name, give its corresponding credential index and attribute name
circuitPrivateVars: [string, [number, string] | [number, string][]][],
// For each circuit public variable name, give its corresponding values
circuitPublicVars: [string, Uint8Array | Uint8Array[]][],
circuitId: string,
provingKeyId: string,
r1cs?: R1CS | ParsedR1CSFile,
wasmBytes?: Uint8Array,
provingKey?: LegoProvingKey | LegoProvingKeyUncompressed
) {
this.presentationBuilder.enforceCircomPredicateAcrossMultipleCredentials(
circuitPrivateVars,
circuitPublicVars,
circuitId,
provingKeyId,
r1cs,
wasmBytes,
provingKey
);
}

addUnboundedPseudonym(baseForSecretKey: Uint8Array, secretKey: Uint8Array): number {
return this.presentationBuilder.addUnboundedPseudonym(baseForSecretKey, secretKey);
}
Expand Down Expand Up @@ -440,8 +462,8 @@ export class BBSBlindedCredentialRequestBuilder extends BlindedCredentialRequest
return undefined;
}

static getSigType(): BlindSignatureTypes {
return BlindSignatureTypes.Bbs;
static getSigType(): BlindSignatureType {
return BlindSignatureType.Bbs;
}
}

Expand Down Expand Up @@ -482,8 +504,8 @@ export class BBSPlusBlindedCredentialRequestBuilder extends BlindedCredentialReq
return commitment;
}

static getSigType(): BlindSignatureTypes {
return BlindSignatureTypes.BbsPlus;
static getSigType(): BlindSignatureType {
return BlindSignatureType.BbsPlus;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/anonymous-credentials/credential-builder-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
ID_STR,
MEM_CHECK_STR,
NON_MEM_CHECK_STR,
RevocationStatusProtocols,
RevocationStatusProtocol,
REV_CHECK_STR,
REV_ID_STR,
SCHEMA_STR,
Expand Down Expand Up @@ -64,7 +64,7 @@ export abstract class CredentialBuilderCommon extends Versioned {
throw new Error(`Revocation check should be either ${MEM_CHECK_STR} or ${NON_MEM_CHECK_STR} but was ${revCheck}`);
}
this._credStatus = {
[TYPE_STR]: RevocationStatusProtocols.Vb22,
[TYPE_STR]: RevocationStatusProtocol.Vb22,
[ID_STR]: registryId,
[REV_CHECK_STR]: revCheck,
[REV_ID_STR]: memberValue
Expand Down
16 changes: 8 additions & 8 deletions src/anonymous-credentials/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
BBS_PLUS_SIGNATURE_PARAMS_LABEL_BYTES,
BBS_SIGNATURE_PARAMS_LABEL_BYTES,
CRYPTO_VERSION_STR,
SignatureTypes,
SignatureType,
PROOF_STR,
PS_CRED_PROOF_TYPE,
PS_SIGNATURE_PARAMS_LABEL_BYTES,
Expand Down Expand Up @@ -71,7 +71,7 @@ export abstract class Credential<PublicKey, Signature, SignatureParams> extends
}
}

static getSigType(): SignatureTypes {
static getSigType(): SignatureType {
throw new Error('This method should be implemented by extending class');
}
}
Expand Down Expand Up @@ -116,8 +116,8 @@ export class BBSCredential extends Credential<BBSPublicKey, BBSSignature, BBSSig
);
}

static getSigType(): SignatureTypes {
return SignatureTypes.Bbs;
static getSigType(): SignatureType {
return SignatureType.Bbs;
}
}

Expand Down Expand Up @@ -161,8 +161,8 @@ export class BBSPlusCredential extends Credential<BBSPlusPublicKeyG2, BBSPlusSig
);
}

static getSigType(): SignatureTypes {
return SignatureTypes.BbsPlus;
static getSigType(): SignatureType {
return SignatureType.BbsPlus;
}
}

Expand Down Expand Up @@ -206,7 +206,7 @@ export class PSCredential extends Credential<PSPublicKey, PSSignature, PSSignatu
);
}

static getSigType(): SignatureTypes {
return SignatureTypes.Ps;
static getSigType(): SignatureType {
return SignatureType.Ps;
}
}
Loading

0 comments on commit c2bff4d

Please sign in to comment.