Skip to content

Commit 254697a

Browse files
committed
Extend from bytearray class at a few more places
Signed-off-by: lovesh <lovesh.bond@gmail.com>
1 parent 829d17e commit 254697a

File tree

6 files changed

+16
-70
lines changed

6 files changed

+16
-70
lines changed

src/accumulator/accumulatorWitness.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
} from '@docknetwork/crypto-wasm';
1414
import { getUint8ArraysFromObject, jsonObjToUint8Array } from '../util';
1515
import { AccumulatorSecretKey } from './params-and-keys';
16+
import { BytearrayWrapper } from '../bytearray-wrapper';
1617

1718
export abstract class AccumulatorWitness {
1819
value: Uint8Array | object;
@@ -262,13 +263,7 @@ export class NonMembershipWitness extends AccumulatorWitness {
262263
/**
263264
* Public info published by the accumulator manager used to update witnesses after several additions and removals.
264265
*/
265-
export class WitnessUpdatePublicInfo {
266-
value: Uint8Array;
267-
268-
constructor(info: Uint8Array) {
269-
this.value = info;
270-
}
271-
266+
export class WitnessUpdatePublicInfo extends BytearrayWrapper {
272267
toJSON(): string {
273268
return JSON.stringify({
274269
value: this.value

src/accumulator/proof.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,9 @@ import {
1919
MembershipProvingKey,
2020
NonMembershipProvingKey
2121
} from './params-and-keys';
22+
import { BytearrayWrapper } from '../bytearray-wrapper';
2223

23-
export class MembershipProofProtocol {
24-
value: Uint8Array;
25-
26-
constructor(protocol: Uint8Array) {
27-
this.value = protocol;
28-
}
29-
24+
export class MembershipProofProtocol extends BytearrayWrapper {
3025
static initialize(
3126
member: Uint8Array,
3227
witness: MembershipWitness,
@@ -68,13 +63,7 @@ export class MembershipProofProtocol {
6863
}
6964
}
7065

71-
export class NonMembershipProofProtocol {
72-
value: Uint8Array;
73-
74-
constructor(protocol: Uint8Array) {
75-
this.value = protocol;
76-
}
77-
66+
export class NonMembershipProofProtocol extends BytearrayWrapper {
7867
static initialize(
7968
nonMember: Uint8Array,
8069
witness: NonMembershipWitness,
@@ -116,13 +105,7 @@ export class NonMembershipProofProtocol {
116105
}
117106
}
118107

119-
export class MembershipProof {
120-
value: Uint8Array;
121-
122-
constructor(proof: Uint8Array) {
123-
this.value = proof;
124-
}
125-
108+
export class MembershipProof extends BytearrayWrapper {
126109
verify(
127110
accumulated: Uint8Array,
128111
challenge: Uint8Array,
@@ -156,13 +139,7 @@ export class MembershipProof {
156139
}
157140
}
158141

159-
export class NonMembershipProof {
160-
value: Uint8Array;
161-
162-
constructor(proof: Uint8Array) {
163-
this.value = proof;
164-
}
165-
142+
export class NonMembershipProof extends BytearrayWrapper {
166143
verify(
167144
accumulated: Uint8Array,
168145
challenge: Uint8Array,

src/bbs-plus/proof.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
bbsVerifyProofOfKnowledgeOfSignature
1313
} from '@docknetwork/crypto-wasm';
1414
import { BBSPlusPublicKeyG2 } from './keys';
15+
import { BytearrayWrapper } from '../bytearray-wrapper';
1516

1617
export class PoKSigProtocol {
1718
value: BbsPoKSigProtocol;
@@ -62,13 +63,7 @@ export class PoKSigProtocol {
6263
}
6364
}
6465

65-
export class PoKSigProof {
66-
value: Uint8Array;
67-
68-
constructor(proof: Uint8Array) {
69-
this.value = proof;
70-
}
71-
66+
export class PoKSigProof extends BytearrayWrapper {
7267
verify(
7368
challenge: Uint8Array,
7469
publicKey: BBSPlusPublicKeyG2,

src/bbs-plus/signature.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,9 @@ import {
1010
} from '@docknetwork/crypto-wasm';
1111
import { BBSPlusPublicKeyG2, BBSPlusSecretKey } from './keys';
1212
import { ensurePositiveIntegerOfSize } from '../util';
13+
import { BytearrayWrapper } from '../bytearray-wrapper';
1314

14-
export abstract class Signature {
15-
value: Uint8Array;
16-
17-
constructor(value: Uint8Array) {
18-
this.value = value;
19-
}
20-
15+
export abstract class Signature extends BytearrayWrapper {
2116
/**
2217
* This is an irreversible encoding as a hash function is used to convert a message of
2318
* arbitrary length to a fixed length encoding.
@@ -134,13 +129,7 @@ export class SignatureG1 extends Signature {
134129
}
135130
}
136131

137-
export abstract class BlindSignature {
138-
value: Uint8Array;
139-
140-
constructor(value: Uint8Array) {
141-
this.value = value;
142-
}
143-
132+
export abstract class BlindSignature extends BytearrayWrapper {
144133
/**
145134
* Generate blinding for creating the commitment used in the request for blind signature
146135
* @param seed - Optional seed to serve as entropy for the blinding.

src/composite-proof/proof.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,12 @@ import { Witnesses } from './witness';
1111
import { SetupParam } from './setup-param';
1212
import { SaverCiphertext } from '../saver';
1313
import { ProofSpecG1, QuasiProofSpecG1 } from './proof-spec';
14+
import { BytearrayWrapper } from '../bytearray-wrapper';
1415

1516
/**
1617
* A proof of 1 or more statements and meta statements.
1718
*/
18-
export class CompositeProofG1 {
19-
value: Uint8Array;
20-
21-
constructor(proof: Uint8Array) {
22-
this.value = proof;
23-
}
24-
19+
export class CompositeProofG1 extends BytearrayWrapper {
2520
/**
2621
* Generate the composite proof using a `ProofSpec`
2722
* @param proofSpec

src/composite-proof/setup-param.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,14 @@ import {
3434
LegoVerifyingKeyUncompressed
3535
} from '../legosnark';
3636
import { AccumulatorParams, AccumulatorPublicKey, MembershipProvingKey, NonMembershipProvingKey } from '../accumulator';
37+
import { BytearrayWrapper } from '../bytearray-wrapper';
3738

3839
/**
3940
* Represents (public) setup parameters of different protocols. Different setup parameters can be wrapped in this and
4041
* then a reference to this is passed to the `Statement`. This is helpful when the same setup parameter needs
4142
* to be passed to several `Statement`s as it avoids the need of having several copies of the setup parameter.
4243
*/
43-
export class SetupParam {
44-
readonly value: Uint8Array;
45-
46-
constructor(param: Uint8Array) {
47-
this.value = param;
48-
}
49-
44+
export class SetupParam extends BytearrayWrapper {
5045
static bbsSignatureParamsG1(params: SignatureParamsG1): SetupParam {
5146
return new SetupParam(generateSetupParamForBBSSignatureParametersG1(params.value));
5247
}

0 commit comments

Comments
 (0)