Skip to content

Commit c93228b

Browse files
committed
Update universal accumulator initialization
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent cdfb882 commit c93228b

File tree

5 files changed

+38
-16
lines changed

5 files changed

+38
-16
lines changed

.github/workspaces/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
name: test
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request: {}
48

59
jobs:
610
build_test:

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@docknetwork/crypto-wasm-ts",
3-
"version": "0.7.0",
3+
"version": "0.8.0",
44
"description": "Typescript abstractions over Dock's Rust crypto library's WASM wrapper",
55
"homepage": "https://github.com/docknetwork/crypto-wasm-ts",
66
"main": "lib/crypto-wasm-ts/src/index.js",
@@ -10,7 +10,8 @@
1010
"clean": "rm -rf lib/",
1111
"prepare": "husky install",
1212
"pretty": "prettier --config .prettierrc 'src/**/*.ts' --write",
13-
"test": "jest"
13+
"test": "jest",
14+
"publish": "yarn build & npm publish"
1415
},
1516
"license": "Apache-2.0",
1617
"private": false,
@@ -21,7 +22,7 @@
2122
"lib": "lib"
2223
},
2324
"dependencies": {
24-
"@docknetwork/crypto-wasm": "0.6.0"
25+
"@docknetwork/crypto-wasm": "0.7.0"
2526
},
2627
"devDependencies": {
2728
"eslint-config-prettier": "^8.3.0",

src/accumulator/accumulator.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ import {
3737
generateRandomFieldElement,
3838
universalAccumulatorCombineMultipleD,
3939
generateFieldElementFromBytes,
40-
generateFieldElementFromNumber
40+
generateFieldElementFromNumber,
41+
universalAccumulatorFixedInitialElements
4142
} from '@docknetwork/crypto-wasm';
4243
import { MembershipWitness, NonMembershipWitness } from './accumulatorWitness';
4344
import { getUint8ArraysFromObject } from '../util';
@@ -620,15 +621,26 @@ export class UniversalAccumulator extends Accumulator {
620621
initialElementsStore?: IInitialElementsStore,
621622
batchSize = 100
622623
): Promise<UniversalAccumulator> {
623-
// store a batch of generated elements and take the product once the batch is full
624-
let currentBatch = [];
624+
const storePresent = initialElementsStore !== undefined;
625+
625626
// store the products of each batch
626627
const products: Uint8Array[] = [];
628+
// The first batch of products is the elements fixed for each curve, in this case it's for BLS12-381
629+
const fixed = universalAccumulatorFixedInitialElements();
630+
if (storePresent) {
631+
for (const i of fixed) {
632+
await initialElementsStore.add(i);
633+
}
634+
}
635+
products.push(universalAccumulatorComputeInitialFv(fixed, secretKey));
636+
637+
// store a batch of generated elements and take the product once the batch is full
638+
let currentBatch = [];
627639
// Accumulate 1 more than the maximum number of allowed members as specified in the paper
628640
for (let i = 0; i <= maxSize; i++) {
629641
const e = generateRandomFieldElement();
630642
currentBatch.push(e);
631-
if (initialElementsStore !== undefined) {
643+
if (storePresent) {
632644
await initialElementsStore.add(e);
633645
}
634646
if (currentBatch.length == batchSize) {

tests/accumulator.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { generateRandomFieldElement, IKeypair, initializeWasm } from '@docknetwork/crypto-wasm';
1+
import {
2+
generateRandomFieldElement,
3+
IKeypair,
4+
initializeWasm,
5+
universalAccumulatorFixedInitialElements
6+
} from '@docknetwork/crypto-wasm';
27
import {
38
IInitialElementsStore,
49
Accumulator,
@@ -227,6 +232,12 @@ describe('Accumulators type', () => {
227232
const keypair1 = UniversalAccumulator.generateKeypair(params1);
228233
const store = new InMemoryInitialElementsStore();
229234
const accumulator1 = await UniversalAccumulator.initialize(20, params1, keypair1.secret_key, store);
235+
236+
const fixed = universalAccumulatorFixedInitialElements();
237+
expect(store.store.size).toEqual(20 + fixed.length + 1);
238+
for (const i of fixed) {
239+
expect(store.store.has(i));
240+
}
230241
const state1 = new InMemoryUniversalState();
231242
await runCommonTests(keypair1, params1, accumulator1, state1, store);
232243
});

tests/demo.spec.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,13 +216,7 @@ describe('A demo showing combined use of BBS+ signatures and accumulators using
216216
Accum3Pk = keypair.public_key;
217217
const maxSize = 100;
218218

219-
const initialElements = [];
220-
for (let i = 0; i < maxSize; i++) {
221-
initialElements.push(generateRandomFieldElement());
222-
}
223-
224-
const fV = UniversalAccumulator.initialElementsProduct(initialElements, Accum3Sk);
225-
Accum3 = UniversalAccumulator.initializeGivenInitialElementsProduct(maxSize, fV, Accum3Params);
219+
Accum3 = await UniversalAccumulator.initialize(maxSize, Accum3Params, Accum3Sk);
226220
Accum3NonMemPrk = Accumulator.generateNonMembershipProvingKey(stringToBytes('Another public label'));
227221
Accum3MemPrk = Accumulator.deriveMembershipKeyFromNonMembershipProvingKey(Accum3NonMemPrk);
228222
}

0 commit comments

Comments
 (0)