Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@types/flat": "^5.0.2",
"@types/lodash": "^4.14.195",
"bs58": "5.0.0",
"crypto-wasm-new": "npm:@docknetwork/crypto-wasm@0.33.0",
"crypto-wasm-new": "npm:@docknetwork/crypto-wasm@0.34.0",
"flat": "^5.0.2",
"json-pointer": "^0.6.2",
"json-stringify-deterministic": "^1.0.11",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
TYPE_STR
} from './types-and-consts';
import { Versioned } from './versioned';
import { ISignatureParams } from '../types'

type Credential = BBSCredential | BBSPlusCredential | PSCredential;

Expand Down Expand Up @@ -698,8 +699,8 @@ export class BBDT16BlindedCredentialRequestBuilder extends BlindedCredentialRequ
}
}

export class BBSPlusBlinding extends BytearrayWrapper {}
export class BBSPlusBlinding extends BytearrayWrapper { }

export class BBDT16Blinding extends BytearrayWrapper {}
export class BBDT16Blinding extends BytearrayWrapper { }

// TODO: Add for PS as well
4 changes: 2 additions & 2 deletions src/anonymous-credentials/presentation-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1442,11 +1442,11 @@ export class PresentationBuilder extends Versioned {
) {
if (param instanceof BoundCheckSmcWithKVProverParams) {
if (!setupParamsTrk.isTrackingParam(paramId)) {
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParams(param));
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParamsKV(param));
}
} else if (param instanceof BoundCheckSmcWithKVProverParamsUncompressed) {
if (!setupParamsTrk.isTrackingParam(paramId)) {
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParamsUncompressed(param));
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParamsKVUncompressed(param));
}
} else {
throw new Error(
Expand Down
7 changes: 3 additions & 4 deletions src/anonymous-credentials/presentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,7 @@ export class Presentation extends Versioned {

const ctx = buildContextForProof(this.version, this.spec, this.context);
const proofSpec = new QuasiProofSpec(statements, metaStatements, setupParamsTrk.setupParams, ctx);
const presVersionGt9 = semver.gt(this.version, '0.9.0');
return this.proof.verifyUsingQuasiProofSpec(proofSpec, this.nonce, presVersionGt9);
return this.proof.verifyUsingQuasiProofSpec(proofSpec, this.nonce);
}

/**
Expand Down Expand Up @@ -1434,11 +1433,11 @@ export class Presentation extends Versioned {
) {
if (param instanceof BoundCheckSmcWithKVVerifierParams) {
if (!setupParamsTrk.isTrackingParam(paramId)) {
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParamsWithSk(param));
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParamsKVWithSk(param));
}
} else if (param instanceof BoundCheckSmcWithKVVerifierParamsUncompressed) {
if (!setupParamsTrk.isTrackingParam(paramId)) {
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParamsWithSkUncompressed(param));
setupParamsTrk.addForParamId(paramId, SetupParam.smcSetupParamsKVWithSkUncompressed(param));
}
} else {
throw new Error(
Expand Down
21 changes: 10 additions & 11 deletions src/bound-check/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import {
boundCheckSmcSetup,
decompressBppParams,
decompressSmcParams,
decompressSmcParamsKV,
boundCheckSmcWithKVSetup,
decompressSmcParamsAndSk
decompressSmcParamsKVAndSk
} from 'crypto-wasm-new';
import { LegoProvingKey } from '../legosnark';
import { BytearrayWrapper } from '../bytearray-wrapper';
Expand Down Expand Up @@ -41,7 +42,7 @@ export function BoundCheckSmcWithKVSetup(
/**
* Uncompressed version of `BoundCheckBppParams`
*/
export class BoundCheckBppParamsUncompressed extends BytearrayWrapper implements IUncompressed {}
export class BoundCheckBppParamsUncompressed extends BytearrayWrapper implements IUncompressed { }

/**
* Setup params for verifying bounds of a message, i.e. range proof using Bulletproofs++
Expand Down Expand Up @@ -70,7 +71,7 @@ export class BoundCheckBppParams extends BytearrayWrapper implements ICompressed
/**
* Uncompressed version of `BoundCheckSmcParams`
*/
export class BoundCheckSmcParamsUncompressed extends BytearrayWrapper implements IUncompressed {}
export class BoundCheckSmcParamsUncompressed extends BytearrayWrapper implements IUncompressed { }

/**
* Setup params for verifying bounds of a message, i.e. range proof using set-membership check
Expand Down Expand Up @@ -98,34 +99,32 @@ export class BoundCheckSmcParams extends BytearrayWrapper implements ICompressed
/**
* Uncompressed version of `BoundCheckSmcWithKVVerifierParams`
*/
export class BoundCheckSmcWithKVProverParamsUncompressed extends BytearrayWrapper implements IUncompressed {}
export class BoundCheckSmcWithKVProverParamsUncompressed extends BytearrayWrapper implements IUncompressed { }

/**
* Params used by the prover for set-membership check based range proof with keyed verification
*/
export class BoundCheckSmcWithKVProverParams
extends BytearrayWrapper
implements ICompressed<BoundCheckSmcWithKVProverParamsUncompressed>
{
implements ICompressed<BoundCheckSmcWithKVProverParamsUncompressed> {
decompress(): BoundCheckSmcWithKVProverParamsUncompressed {
return new BoundCheckSmcWithKVProverParamsUncompressed(decompressSmcParams(this.value));
return new BoundCheckSmcWithKVProverParamsUncompressed(decompressSmcParamsKV(this.value));
}
}

/**
* Uncompressed version of `BoundCheckSmcWithKVVerifierParams`
*/
export class BoundCheckSmcWithKVVerifierParamsUncompressed extends BytearrayWrapper implements IUncompressed {}
export class BoundCheckSmcWithKVVerifierParamsUncompressed extends BytearrayWrapper implements IUncompressed { }

/**
* Params used by the verifier for set-membership check based range proof with keyed verification. The verifier should not share these
* with anyone as they contain a secret
*/
export class BoundCheckSmcWithKVVerifierParams
extends BytearrayWrapper
implements ICompressed<BoundCheckSmcWithKVVerifierParamsUncompressed>
{
implements ICompressed<BoundCheckSmcWithKVVerifierParamsUncompressed> {
decompress(): BoundCheckSmcWithKVVerifierParamsUncompressed {
return new BoundCheckSmcWithKVVerifierParamsUncompressed(decompressSmcParamsAndSk(this.value));
return new BoundCheckSmcWithKVVerifierParamsUncompressed(decompressSmcParamsKVAndSk(this.value));
}
}
30 changes: 9 additions & 21 deletions src/composite-proof/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
saverGetCiphertextsFromProof,
verifyCompositeProofG1,
verifyCompositeProofG1WithDeconstructedProofSpec,
verifyCompositeProofG1WithDeconstructedProofSpecOld,
VerifyResult
} from 'crypto-wasm-new';
import {
Expand Down Expand Up @@ -72,14 +71,13 @@ export class CompositeProof extends BytearrayWrapper {
* @param proofSpec
* @param nonce
*/
verifyUsingQuasiProofSpec(proofSpec: QuasiProofSpec, nonce?: Uint8Array, presVersionGt9 = true): VerifyResult {
verifyUsingQuasiProofSpec(proofSpec: QuasiProofSpec, nonce?: Uint8Array): VerifyResult {
return this.verifyWithDeconstructedProofSpec(
proofSpec.statements,
proofSpec.metaStatements,
proofSpec.setupParams,
proofSpec.context,
nonce,
presVersionGt9
);
}

Expand Down Expand Up @@ -124,26 +122,16 @@ export class CompositeProof extends BytearrayWrapper {
setupParams?: SetupParam[],
context?: Uint8Array,
nonce?: Uint8Array,
presVersionGt9 = true
): VerifyResult {
const params = (setupParams ?? new Array<SetupParam>()).map((s) => s.value);
return presVersionGt9
? verifyCompositeProofG1WithDeconstructedProofSpec(
this.value,
statements.values,
metaStatements.values,
params,
context,
nonce
)
: verifyCompositeProofG1WithDeconstructedProofSpecOld(
this.value,
statements.values,
metaStatements.values,
params,
context,
nonce
);
return verifyCompositeProofG1WithDeconstructedProofSpec(
this.value,
statements.values,
metaStatements.values,
params,
context,
nonce
);
}

/**
Expand Down
19 changes: 14 additions & 5 deletions src/composite-proof/setup-param.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import {
generateSetupParamForFieldElemVec,
generateSetupParamForBppParams,
generateSetupParamForSmcParams,
generateSetupParamForSmcParamsAndSk,
generateSetupParamForSmcParamsKV,
generateSetupParamForSmcParamsKVAndSk,
generateSetupParamForBDDT16MacParameters
} from 'crypto-wasm-new';
import { BBSPlusPublicKeyG2, BBSPlusSignatureParamsG1 } from '../bbs-plus';
Expand Down Expand Up @@ -202,12 +203,20 @@ export class SetupParam extends BytearrayWrapper {
return new SetupParam(generateSetupParamForSmcParams(params.value, true));
}

static smcSetupParamsWithSk(params: BoundCheckSmcWithKVVerifierParams): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsAndSk(params.value, false));
static smcSetupParamsKV(params: BoundCheckSmcParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKV(params.value, false));
}

static smcSetupParamsWithSkUncompressed(params: BoundCheckSmcWithKVVerifierParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsAndSk(params.value, true));
static smcSetupParamsKVUncompressed(params: BoundCheckSmcParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKV(params.value, true));
}

static smcSetupParamsKVWithSk(params: BoundCheckSmcWithKVVerifierParams): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKVAndSk(params.value, false));
}

static smcSetupParamsKVWithSkUncompressed(params: BoundCheckSmcWithKVVerifierParamsUncompressed): SetupParam {
return new SetupParam(generateSetupParamForSmcParamsKVAndSk(params.value, true));
}

static pedCommKeyG1(commKey: PederCommKey): SetupParam {
Expand Down
5 changes: 3 additions & 2 deletions tests/anonymous-credentials/blind-issuance.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
isBBS,
isPS, isKvac, CredentialBuilder
} from '../scheme';
import { ISignatureParams } from '../../src/types';

import {
checkCiphertext,
Expand Down Expand Up @@ -97,7 +98,7 @@ function finalize(reqBuilder) {
function newReqBuilder(
schema: CredentialSchema,
subjectToBlind: object
): BlindedCredentialRequestBuilder<SignatureParams> {
): BlindedCredentialRequestBuilder<ISignatureParams> {
const reqBuilder = isKvac() ? new BBDT16BlindedCredentialRequestBuilder() : isBBS() ? new BBSBlindedCredentialRequestBuilder() : new BBSPlusBlindedCredentialRequestBuilder();
reqBuilder.schema = schema;
reqBuilder.subjectToBlind = subjectToBlind;
Expand Down Expand Up @@ -139,7 +140,7 @@ function checkBlindedCredJson(blindedCred: BlindedCredential<any>, sk: SecretKey
// @ts-ignore
const cred = isBBS()
? // @ts-ignore
recreatedCred.toCredential(blindedSubject, blindedStatus, blindedTopLevelFields)
recreatedCred.toCredential(blindedSubject, blindedStatus, blindedTopLevelFields)
// @ts-ignore
: recreatedCred.toCredential(blindedSubject, blinding, blindedStatus, blindedTopLevelFields);
verifyCred(cred, pk, sk);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading