Skip to content

Commit

Permalink
Add KVAC
Browse files Browse the repository at this point in the history
Signed-off-by: lovesh <lovesh.bond@gmail.com>
  • Loading branch information
lovesh committed Mar 4, 2024
1 parent c2bff4d commit b9292ba
Show file tree
Hide file tree
Showing 112 changed files with 3,586 additions and 1,976 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
},
plugins: [
'@typescript-eslint',
'unused-imports'
],
extends: [
'eslint:recommended',
Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@docknetwork/crypto-wasm-ts",
"version": "0.50.0",
"version": "0.52.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 All @@ -16,7 +16,8 @@
"test-bbs": "TEST_SIGNATURE_SCHEME=BBS yarn jest",
"test-bbs+": "TEST_SIGNATURE_SCHEME=BBS+ yarn jest",
"test-ps": "TEST_SIGNATURE_SCHEME=PS yarn jest",
"test-all": "TEST_SIGNATURE_SCHEME=BBS yarn jest; TEST_SIGNATURE_SCHEME=BBS+ yarn jest; TEST_SIGNATURE_SCHEME=PS yarn jest"
"test-bddt16": "TEST_SIGNATURE_SCHEME=BDDT16 yarn jest",
"test-all": "TEST_SIGNATURE_SCHEME=BBS yarn jest; TEST_SIGNATURE_SCHEME=BBS+ yarn jest; TEST_SIGNATURE_SCHEME=PS yarn jest; TEST_SIGNATURE_SCHEME=BDDT16 yarn jest"
},
"license": "Apache-2.0",
"private": false,
Expand All @@ -27,10 +28,11 @@
"lib": "lib"
},
"dependencies": {
"@docknetwork/crypto-wasm": "0.23.0",
"@types/flat": "^5.0.2",
"@types/lodash": "^4.14.195",
"bs58": "5.0.0",
"crypto-wasm-new": "npm:@docknetwork/crypto-wasm@0.24.0",
"crypto-wasm-old": "npm:@docknetwork/crypto-wasm@0.23.0",
"flat": "^5.0.2",
"json-pointer": "^0.6.2",
"json-stringify-deterministic": "^1.0.11",
Expand All @@ -48,6 +50,7 @@
"eslint": "^8.42.0",
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-import": "^2.27.5",
"eslint-plugin-unused-imports": "^3.1.0",
"husky": "^7.0.4",
"jest": "^29.1.0",
"jsonld": "6.0.0",
Expand All @@ -56,6 +59,6 @@
"r1csfile": "^0.0.41",
"ts-jest": "^29.1.0",
"ts-node": "^10.9.1",
"typescript": "5.1.3"
"typescript": "5.3.3"
}
}
2 changes: 1 addition & 1 deletion src/Pseudonym.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pedersenCommitmentG1, generateRandomG1Element } from '@docknetwork/crypto-wasm';
import { pedersenCommitmentG1, generateRandomG1Element } from 'crypto-wasm-new';
import { BytearrayWrapper } from './bytearray-wrapper';
import { base58ToBytearray, bytearrayToBase58 } from './util';

Expand Down
48 changes: 24 additions & 24 deletions src/accumulator/accumulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import {
universalAccumulatorRemoveBatch,
universalAccumulatorVerifyMembership,
universalAccumulatorVerifyNonMembership
} from '@docknetwork/crypto-wasm';
import { MembershipWitness, NonMembershipWitness } from './accumulatorWitness';
} from 'crypto-wasm-new';
import { VBMembershipWitness, VBNonMembershipWitness } from './accumulatorWitness';
import { getUint8ArraysFromObject } from '../util';
import { IAccumulatorState, IUniversalAccumulatorState } from './IAccumulatorState';
import { IInitialElementsStore } from './IInitialElementsStore';
Expand Down Expand Up @@ -261,7 +261,7 @@ export abstract class Accumulator {
element: Uint8Array,
secretKey?: AccumulatorSecretKey,
state?: IAccumulatorState
): Promise<MembershipWitness>;
): Promise<VBMembershipWitness>;

/**
* Calculate the membership witnesses for the given batch of elements
Expand All @@ -273,7 +273,7 @@ export abstract class Accumulator {
elements: Uint8Array[],
secretKey?: AccumulatorSecretKey,
state?: IAccumulatorState
): Promise<MembershipWitness[]>;
): Promise<VBMembershipWitness[]>;

/**
* Verify the membership witness.
Expand All @@ -284,7 +284,7 @@ export abstract class Accumulator {
*/
abstract verifyMembershipWitness(
member: Uint8Array,
witness: MembershipWitness,
witness: VBMembershipWitness,
pk: AccumulatorPublicKey,
params?: AccumulatorParams
): boolean;
Expand Down Expand Up @@ -508,11 +508,11 @@ export class PositiveAccumulator extends Accumulator {
member: Uint8Array,
secretKey?: AccumulatorSecretKey,
state?: IAccumulatorState
): Promise<MembershipWitness> {
): Promise<VBMembershipWitness> {
await this.ensurePresence(member, state);
const sk = this.getSecretKey(secretKey);
const wit = positiveAccumulatorMembershipWitness(this.value, member, sk.value);
return new MembershipWitness(wit);
return new VBMembershipWitness(wit);
}

/**
Expand All @@ -526,11 +526,11 @@ export class PositiveAccumulator extends Accumulator {
members: Uint8Array[],
secretKey?: AccumulatorSecretKey,
state?: IAccumulatorState
): Promise<MembershipWitness[]> {
): Promise<VBMembershipWitness[]> {
await this.ensurePresenceOfBatch(members, state);
const sk = this.getSecretKey(secretKey);
return positiveAccumulatorMembershipWitnessesForBatch(this.value, members, sk.value).map(
(m) => new MembershipWitness(m)
(m) => new VBMembershipWitness(m)
);
}

Expand All @@ -544,7 +544,7 @@ export class PositiveAccumulator extends Accumulator {
*/
verifyMembershipWitness(
member: Uint8Array,
witness: MembershipWitness,
witness: VBMembershipWitness,
publicKey: AccumulatorPublicKey,
params?: AccumulatorParams
): boolean {
Expand Down Expand Up @@ -750,25 +750,25 @@ export class UniversalAccumulator extends Accumulator {
secretKey?: AccumulatorSecretKey,
state?: IAccumulatorState,
initialElementsStore?: IInitialElementsStore
): Promise<MembershipWitness> {
): Promise<VBMembershipWitness> {
await this.checkElementAcceptable(member, initialElementsStore);
await this.ensurePresence(member, state);
const sk = this.getSecretKey(secretKey);
const wit = universalAccumulatorMembershipWitness(this.value, member, sk.value);
return new MembershipWitness(wit);
return new VBMembershipWitness(wit);
}

async membershipWitnessesForBatch(
members: Uint8Array[],
secretKey?: AccumulatorSecretKey,
state?: IAccumulatorState,
initialElementsStore?: IInitialElementsStore
): Promise<MembershipWitness[]> {
): Promise<VBMembershipWitness[]> {
await this.checkElementBatchAcceptable(members, initialElementsStore);
await this.ensurePresenceOfBatch(members, state);
const sk = this.getSecretKey(secretKey);
return universalAccumulatorMembershipWitnessesForBatch(this.value, members, sk.value).map(
(m) => new MembershipWitness(m)
(m) => new VBMembershipWitness(m)
);
}

Expand All @@ -790,7 +790,7 @@ export class UniversalAccumulator extends Accumulator {
params?: AccumulatorParams,
initialElementsStore?: IInitialElementsStore,
batchSize = 100
): Promise<NonMembershipWitness> {
): Promise<VBNonMembershipWitness> {
await this.checkElementAcceptable(nonMember, initialElementsStore);
await this.ensureAbsence(nonMember, state);
const sk = this.getSecretKey(secretKey);
Expand All @@ -810,7 +810,7 @@ export class UniversalAccumulator extends Accumulator {
}
const d = universalAccumulatorCombineMultipleD(ds);
const wit = universalAccumulatorNonMembershipWitness(this.value, d, nonMember, sk.value, params_.value);
return new NonMembershipWitness(wit);
return new VBNonMembershipWitness(wit);
}

/**
Expand All @@ -830,13 +830,13 @@ export class UniversalAccumulator extends Accumulator {
params?: AccumulatorParams,
state?: IUniversalAccumulatorState,
initialElementsStore?: IInitialElementsStore
): Promise<NonMembershipWitness> {
): Promise<VBNonMembershipWitness> {
await this.checkElementAcceptable(nonMember, initialElementsStore);
await this.ensureAbsence(nonMember, state);
const sk = this.getSecretKey(secretKey);
const params_ = this.getParams(params);
const wit = universalAccumulatorNonMembershipWitness(this.value, d, nonMember, sk.value, params_.value);
return new NonMembershipWitness(wit);
return new VBNonMembershipWitness(wit);
}

/**
Expand All @@ -856,7 +856,7 @@ export class UniversalAccumulator extends Accumulator {
params?: AccumulatorParams,
initialElementsStore?: IInitialElementsStore,
batchSize = 100
): Promise<NonMembershipWitness[]> {
): Promise<VBNonMembershipWitness[]> {
await this.checkElementBatchAcceptable(nonMembers, initialElementsStore);
await this.ensureAbsenceOfBatch(nonMembers, state);
const sk = this.getSecretKey(secretKey);
Expand Down Expand Up @@ -894,7 +894,7 @@ export class UniversalAccumulator extends Accumulator {
ds[i] = universalAccumulatorCombineMultipleD(dsForAll[i]);
}
return universalAccumulatorNonMembershipWitnessesForBatch(this.value, ds, nonMembers, sk.value, params_.value).map(
(m) => new NonMembershipWitness(m)
(m) => new VBNonMembershipWitness(m)
);
}

Expand All @@ -915,19 +915,19 @@ export class UniversalAccumulator extends Accumulator {
params?: AccumulatorParams,
state?: IUniversalAccumulatorState,
initialElementsStore?: IInitialElementsStore
): Promise<NonMembershipWitness[]> {
): Promise<VBNonMembershipWitness[]> {
await this.checkElementBatchAcceptable(nonMembers, initialElementsStore);
await this.ensureAbsenceOfBatch(nonMembers, state);
const sk = this.getSecretKey(secretKey);
const params_ = this.getParams(params);
return universalAccumulatorNonMembershipWitnessesForBatch(this.value, d, nonMembers, sk.value, params_.value).map(
(m) => new NonMembershipWitness(m)
(m) => new VBNonMembershipWitness(m)
);
}

verifyMembershipWitness(
member: Uint8Array,
witness: MembershipWitness,
witness: VBMembershipWitness,
pk: AccumulatorPublicKey,
params?: AccumulatorParams
): boolean {
Expand All @@ -937,7 +937,7 @@ export class UniversalAccumulator extends Accumulator {

verifyNonMembershipWitness(
nonMember: Uint8Array,
witness: NonMembershipWitness,
witness: VBNonMembershipWitness,
pk: AccumulatorPublicKey,
params?: AccumulatorParams
): boolean {
Expand Down
Loading

0 comments on commit b9292ba

Please sign in to comment.