11import {
2- publicInfoForWitnessUpdate ,
32 updateMembershipWitnessesPostBatchUpdates ,
43 updateMembershipWitnessPostAdd ,
54 updateMembershipWitnessPostRemove ,
@@ -11,34 +10,34 @@ import {
1110 updateNonMembershipWitnessUsingPublicInfoAfterBatchUpdate ,
1211 updateNonMembershipWitnessUsingPublicInfoAfterMultipleBatchUpdates
1312} from 'crypto-wasm-new' ;
14- import { getUint8ArraysFromObject , jsonObjToUint8Array } from '../util' ;
13+ import { getUint8ArraysFromObject } from '../util' ;
1514import { AccumulatorSecretKey } from './params-and-keys' ;
16- import { BytearrayWrapper } from '../bytearray-wrapper ' ;
15+ import { VBWitnessUpdateInfo , WitnessUpdateInfo } from './witness-update-info ' ;
1716
18- export abstract class AccumulatorWitness {
17+ export abstract class AccumulatorWitness < V > {
1918 value : Uint8Array | object ;
2019
2120 constructor ( value : Uint8Array | object ) {
2221 this . value = value ;
2322 }
2423
25- abstract updatePostAdd ( addition : Uint8Array , element : Uint8Array , accumulatorValueBeforeAddition : Uint8Array ) : void ;
26- abstract updatePostRemove ( removal : Uint8Array , element : Uint8Array , accumulatorValueAfterRemoval : Uint8Array ) : void ;
24+ abstract updatePostAdd ( addition : Uint8Array , element : Uint8Array , accumulatorValueBeforeAddition : V ) : void ;
25+ abstract updatePostRemove ( removal : Uint8Array , element : Uint8Array , accumulatorValueAfterRemoval : V ) : void ;
2726 abstract updateUsingPublicInfoPostBatchUpdate (
2827 element : Uint8Array ,
2928 additions : Uint8Array [ ] ,
3029 removals : Uint8Array [ ] ,
31- publicInfo : VBWitnessUpdatePublicInfo
30+ publicInfo : WitnessUpdateInfo
3231 ) : void ;
3332 abstract updateUsingPublicInfoPostMultipleBatchUpdates (
3433 element : Uint8Array ,
3534 additions : Uint8Array [ ] [ ] ,
3635 removals : Uint8Array [ ] [ ] ,
37- publicInfo : VBWitnessUpdatePublicInfo [ ]
36+ publicInfo : WitnessUpdateInfo [ ]
3837 ) : void ;
3938}
4039
41- export class VBMembershipWitness extends AccumulatorWitness {
40+ export class VBMembershipWitness extends AccumulatorWitness < Uint8Array > {
4241 // @ts -ignore
4342 value : Uint8Array ;
4443
@@ -73,7 +72,7 @@ export class VBMembershipWitness extends AccumulatorWitness {
7372 member : Uint8Array ,
7473 additions : Uint8Array [ ] ,
7574 removals : Uint8Array [ ] ,
76- publicInfo : VBWitnessUpdatePublicInfo
75+ publicInfo : VBWitnessUpdateInfo
7776 ) {
7877 this . value = updateMembershipWitnessUsingPublicInfoAfterBatchUpdate (
7978 this . value ,
@@ -96,7 +95,7 @@ export class VBMembershipWitness extends AccumulatorWitness {
9695 member : Uint8Array ,
9796 additions : Uint8Array [ ] [ ] ,
9897 removals : Uint8Array [ ] [ ] ,
99- publicInfo : VBWitnessUpdatePublicInfo [ ]
98+ publicInfo : VBWitnessUpdateInfo [ ]
10099 ) {
101100 const info = publicInfo . map ( ( i ) => i . value ) ;
102101 this . value = updateMembershipWitnessUsingPublicInfoAfterMultipleBatchUpdates (
@@ -149,7 +148,7 @@ export class VBMembershipWitness extends AccumulatorWitness {
149148 }
150149}
151150
152- export class VBNonMembershipWitness extends AccumulatorWitness {
151+ export class VBNonMembershipWitness extends AccumulatorWitness < Uint8Array > {
153152 // @ts -ignore
154153 value : { d : Uint8Array ; C : Uint8Array } ;
155154
@@ -184,7 +183,7 @@ export class VBNonMembershipWitness extends AccumulatorWitness {
184183 nonMember : Uint8Array ,
185184 additions : Uint8Array [ ] ,
186185 removals : Uint8Array [ ] ,
187- publicInfo : VBWitnessUpdatePublicInfo
186+ publicInfo : VBWitnessUpdateInfo
188187 ) {
189188 this . value = updateNonMembershipWitnessUsingPublicInfoAfterBatchUpdate (
190189 this . value ,
@@ -207,7 +206,7 @@ export class VBNonMembershipWitness extends AccumulatorWitness {
207206 nonMember : Uint8Array ,
208207 additions : Uint8Array [ ] [ ] ,
209208 removals : Uint8Array [ ] [ ] ,
210- publicInfo : VBWitnessUpdatePublicInfo [ ]
209+ publicInfo : VBWitnessUpdateInfo [ ]
211210 ) {
212211 const info = publicInfo . map ( ( i ) => i . value ) ;
213212 this . value = updateNonMembershipWitnessUsingPublicInfoAfterMultipleBatchUpdates (
@@ -259,35 +258,3 @@ export class VBNonMembershipWitness extends AccumulatorWitness {
259258 return new VBNonMembershipWitness ( { d, C } ) ;
260259 }
261260}
262-
263- /**
264- * Public info published by the accumulator manager used to update witnesses after several additions and removals.
265- */
266- export class VBWitnessUpdatePublicInfo extends BytearrayWrapper {
267- toJSON ( ) : string {
268- return JSON . stringify ( {
269- value : this . value
270- } ) ;
271- }
272-
273- fromJSON ( json : string ) : VBWitnessUpdatePublicInfo {
274- return new VBWitnessUpdatePublicInfo ( jsonObjToUint8Array ( json ) ) ;
275- }
276-
277- /**
278- * Accumulator manager creates the witness update info corresponding to the additions and removals.
279- * @param accumulatorValueBeforeUpdates - accumulator value before the additions and removals
280- * @param additions
281- * @param removals
282- * @param sk
283- */
284- static new (
285- accumulatorValueBeforeUpdates : Uint8Array ,
286- additions : Uint8Array [ ] ,
287- removals : Uint8Array [ ] ,
288- sk : AccumulatorSecretKey
289- ) : VBWitnessUpdatePublicInfo {
290- const value = publicInfoForWitnessUpdate ( accumulatorValueBeforeUpdates , additions , removals , sk . value ) ;
291- return new VBWitnessUpdatePublicInfo ( value ) ;
292- }
293- }
0 commit comments