@dorafactory/maci-sdk 0.0.35 → 0.0.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +14 -2234
- package/dist/index.js +748 -348
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +722 -350
- package/dist/index.mjs.map +1 -1
- package/dist/libs/const.d.ts +118 -0
- package/dist/libs/contract/config.d.ts +29 -0
- package/dist/libs/contract/contract.d.ts +57 -0
- package/dist/libs/contract/index.d.ts +1 -0
- package/dist/libs/contract/ts/AMaci.client.d.ts +216 -0
- package/dist/libs/contract/ts/AMaci.types.d.ts +221 -0
- package/dist/libs/contract/ts/Maci.client.d.ts +180 -0
- package/dist/libs/contract/ts/Maci.types.d.ts +226 -0
- package/dist/libs/contract/ts/OracleMaci.client.d.ts +206 -0
- package/dist/libs/contract/ts/OracleMaci.types.d.ts +263 -0
- package/dist/libs/contract/ts/Registry.client.d.ts +128 -0
- package/dist/libs/contract/ts/Registry.types.d.ts +110 -0
- package/dist/libs/contract/types.d.ts +39 -0
- package/dist/libs/contract/utils.d.ts +63 -0
- package/dist/libs/contract/vars.d.ts +63 -0
- package/dist/libs/crypto/babyjub.d.ts +73 -0
- package/dist/libs/crypto/bigintUtils.d.ts +6 -0
- package/dist/libs/crypto/constants.d.ts +3 -0
- package/dist/libs/crypto/hashing.d.ts +69 -0
- package/dist/libs/crypto/index.d.ts +9 -0
- package/dist/libs/crypto/keys.d.ts +74 -0
- package/dist/libs/crypto/sign.d.ts +9 -0
- package/dist/libs/crypto/tree.d.ts +23 -0
- package/dist/libs/crypto/types.d.ts +55 -0
- package/dist/libs/errors/index.d.ts +28 -0
- package/dist/libs/errors/types.d.ts +19 -0
- package/dist/libs/http/http.d.ts +16 -0
- package/dist/libs/http/index.d.ts +1 -0
- package/dist/libs/index.d.ts +7 -0
- package/dist/libs/indexer/index.d.ts +1 -0
- package/dist/libs/indexer/indexer.d.ts +152 -0
- package/dist/libs/indexer/types.d.ts +7 -0
- package/dist/libs/maci/index.d.ts +1 -0
- package/dist/libs/maci/maci.d.ts +182 -0
- package/dist/libs/maci/types.d.ts +6 -0
- package/dist/libs/oracle-certificate/index.d.ts +1 -0
- package/dist/libs/oracle-certificate/oracle-certificate.d.ts +9 -0
- package/dist/libs/oracle-certificate/types.d.ts +40 -0
- package/dist/libs/query/account.d.ts +7 -0
- package/dist/libs/query/circuit.d.ts +8 -0
- package/dist/libs/query/event.d.ts +7 -0
- package/dist/libs/query/index.d.ts +7 -0
- package/dist/libs/query/operator.d.ts +11 -0
- package/dist/libs/query/proof.d.ts +7 -0
- package/dist/libs/query/round.d.ts +18 -0
- package/dist/libs/query/transaction.d.ts +9 -0
- package/dist/maci.d.ts +190 -0
- package/dist/types/index.d.ts +383 -0
- package/dist/utils/index.d.ts +7 -0
- package/package.json +18 -24
- package/src/index.ts +1 -3
- package/src/libs/contract/contract.ts +14 -13
- package/src/libs/contract/types.ts +3 -3
- package/src/libs/crypto/babyjub.ts +132 -0
- package/src/libs/crypto/bigintUtils.ts +31 -0
- package/src/libs/crypto/constants.ts +22 -0
- package/src/libs/crypto/hashing.ts +167 -0
- package/src/libs/crypto/index.ts +9 -0
- package/src/libs/{circom/circomlib.ts → crypto/keys.ts} +104 -114
- package/src/libs/crypto/sign.ts +91 -0
- package/src/libs/crypto/tree.ts +176 -0
- package/src/libs/crypto/types.ts +101 -0
- package/src/libs/index.ts +1 -1
- package/src/libs/maci/maci.ts +28 -29
- package/src/maci.ts +132 -67
- package/src/types/index.ts +7 -0
- package/src/utils/index.ts +22 -22
- package/dist/browser.d.mts +0 -2233
- package/dist/browser.d.ts +0 -2233
- package/dist/browser.js +0 -31620
- package/dist/browser.js.map +0 -1
- package/dist/browser.mjs +0 -31631
- package/dist/browser.mjs.map +0 -1
- package/dist/index.d.mts +0 -2234
- package/src/browser.ts +0 -17
- package/src/libs/circom/index.ts +0 -98
- package/src/libs/circom/types.ts +0 -8
- package/src/polyfills/browser-polyfills.ts +0 -9
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OfflineSigner,
|
|
3
|
+
OfflineDirectSigner,
|
|
4
|
+
isOfflineDirectSigner,
|
|
5
|
+
} from '@cosmjs/proto-signing';
|
|
6
|
+
import { StdSignDoc } from '@cosmjs/amino';
|
|
7
|
+
import { SignDoc } from 'cosmjs-types/cosmos/tx/v1beta1/tx';
|
|
8
|
+
import { getDefaultParams } from '../const';
|
|
9
|
+
import { genKeypair } from './keys';
|
|
10
|
+
import { SignResult } from './types';
|
|
11
|
+
|
|
12
|
+
export async function signMessage(
|
|
13
|
+
signer: OfflineSigner,
|
|
14
|
+
address: string,
|
|
15
|
+
message: string,
|
|
16
|
+
network: 'mainnet' | 'testnet'
|
|
17
|
+
): Promise<SignResult> {
|
|
18
|
+
const accounts = await signer.getAccounts();
|
|
19
|
+
const account = accounts.find((acc) => acc.address === address);
|
|
20
|
+
const chainId = getDefaultParams(network).chainId;
|
|
21
|
+
|
|
22
|
+
if (!account) {
|
|
23
|
+
throw new Error(`Address ${address} not found in wallet`);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (isOfflineDirectSigner(signer)) {
|
|
27
|
+
// Direct
|
|
28
|
+
const signDoc: SignDoc = {
|
|
29
|
+
bodyBytes: new TextEncoder().encode(message),
|
|
30
|
+
authInfoBytes: new Uint8Array(),
|
|
31
|
+
chainId,
|
|
32
|
+
accountNumber: BigInt(0),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const { signature } = await signer.signDirect(address, signDoc);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
signature: signature.signature,
|
|
39
|
+
pubkey: account.pubkey,
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
// Amino
|
|
43
|
+
const signDoc: StdSignDoc = {
|
|
44
|
+
chain_id: chainId,
|
|
45
|
+
account_number: '0',
|
|
46
|
+
sequence: '0',
|
|
47
|
+
fee: {
|
|
48
|
+
gas: '0',
|
|
49
|
+
amount: [],
|
|
50
|
+
},
|
|
51
|
+
msgs: [],
|
|
52
|
+
memo: message,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const { signature } = await signer.signAmino(address, signDoc);
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
signature: signature.signature,
|
|
59
|
+
pubkey: account.pubkey,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function genKeypairFromSignature(signature: string) {
|
|
65
|
+
const sign = BigInt('0x' + Buffer.from(signature, 'base64').toString('hex'));
|
|
66
|
+
|
|
67
|
+
return genKeypair(sign);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function genKeypairFromSign({
|
|
71
|
+
signer,
|
|
72
|
+
address,
|
|
73
|
+
network,
|
|
74
|
+
}: {
|
|
75
|
+
signer: OfflineSigner;
|
|
76
|
+
address?: string;
|
|
77
|
+
network: 'mainnet' | 'testnet';
|
|
78
|
+
}) {
|
|
79
|
+
if (!address) {
|
|
80
|
+
[{ address }] = await signer.getAccounts();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const sig = await signMessage(
|
|
84
|
+
signer,
|
|
85
|
+
address,
|
|
86
|
+
'Generate_MACI_Private_Key',
|
|
87
|
+
network
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
return genKeypairFromSignature(sig.signature);
|
|
91
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { poseidon } from './hashing';
|
|
2
|
+
|
|
3
|
+
export class Tree {
|
|
4
|
+
private DEPTH: number;
|
|
5
|
+
private HEIGHT: number;
|
|
6
|
+
private DEGREE: number;
|
|
7
|
+
private LEAVES_COUNT: number;
|
|
8
|
+
private LEAVES_IDX_0: number;
|
|
9
|
+
private NODES_COUNT: number;
|
|
10
|
+
private zeros!: bigint[];
|
|
11
|
+
private nodes!: bigint[];
|
|
12
|
+
|
|
13
|
+
constructor(degree: number, depth: number, zero: bigint) {
|
|
14
|
+
this.DEPTH = depth;
|
|
15
|
+
this.HEIGHT = depth + 1;
|
|
16
|
+
this.DEGREE = degree;
|
|
17
|
+
|
|
18
|
+
this.LEAVES_COUNT = degree ** depth;
|
|
19
|
+
this.LEAVES_IDX_0 = (degree ** depth - 1) / (degree - 1);
|
|
20
|
+
this.NODES_COUNT = (degree ** (depth + 1) - 1) / (degree - 1);
|
|
21
|
+
|
|
22
|
+
this.initZero(zero);
|
|
23
|
+
this.initNodes();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get root(): bigint {
|
|
27
|
+
return this.nodes[0];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private async initZero(zero: bigint): Promise<void> {
|
|
31
|
+
this.zeros = new Array<bigint>(this.HEIGHT);
|
|
32
|
+
this.zeros[0] = zero;
|
|
33
|
+
for (let i = 1; i < this.zeros.length; i++) {
|
|
34
|
+
this.zeros[i] = await poseidon([this.zeros[i - 1], this.zeros[i - 1]]);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private async initNodes(): Promise<void> {
|
|
39
|
+
const DEGREE = this.DEGREE;
|
|
40
|
+
|
|
41
|
+
this.nodes = new Array<bigint>(this.NODES_COUNT);
|
|
42
|
+
|
|
43
|
+
for (let d = this.DEPTH; d >= 0; d--) {
|
|
44
|
+
const size = DEGREE ** d;
|
|
45
|
+
const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
|
|
46
|
+
const zero = this.zeros[this.DEPTH - d];
|
|
47
|
+
for (let i = 0; i < size; i++) {
|
|
48
|
+
this.nodes[idx0 + i] = zero;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
initLeaves(leaves: (bigint | string | number)[]): void {
|
|
54
|
+
const DEGREE = this.DEGREE;
|
|
55
|
+
for (let i = 0; i < leaves.length; i++) {
|
|
56
|
+
if (i >= this.LEAVES_COUNT) {
|
|
57
|
+
console.error('OVERFLOW');
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
this.nodes[this.LEAVES_IDX_0 + i] = BigInt(leaves[i]);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
for (let d = this.DEPTH - 1; d >= 0; d--) {
|
|
64
|
+
const size = DEGREE ** d;
|
|
65
|
+
const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
|
|
66
|
+
for (let i = 0; i < size / DEGREE; i++) {
|
|
67
|
+
const start = (idx0 + i) * DEGREE + 1;
|
|
68
|
+
const children = this.nodes.slice(start, start + DEGREE);
|
|
69
|
+
this.nodes[idx0 + i] = poseidon(children);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
leaf(leafIdx: number): bigint {
|
|
75
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
76
|
+
throw new Error('wrong leaf index');
|
|
77
|
+
}
|
|
78
|
+
const nodeIdx = this.LEAVES_IDX_0 + leafIdx;
|
|
79
|
+
return this.nodes[nodeIdx];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
leaves(): bigint[] {
|
|
83
|
+
return this.nodes.slice(this.LEAVES_IDX_0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
updateLeaf(leafIdx: number, leaf: bigint): void {
|
|
87
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
88
|
+
throw new Error('wrong leaf index');
|
|
89
|
+
}
|
|
90
|
+
const nodeIdx = this.LEAVES_IDX_0 + leafIdx;
|
|
91
|
+
this.nodes[nodeIdx] = leaf;
|
|
92
|
+
|
|
93
|
+
this._update(nodeIdx);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
pathIdxOf(leafIdx: number): number[] {
|
|
97
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
98
|
+
throw new Error('wrong leaf index');
|
|
99
|
+
}
|
|
100
|
+
let idx = this.LEAVES_IDX_0 + leafIdx;
|
|
101
|
+
const pathIdx: number[] = [];
|
|
102
|
+
|
|
103
|
+
for (let i = 0; i < this.DEPTH; i++) {
|
|
104
|
+
const parentIdx = Math.floor((idx - 1) / this.DEGREE);
|
|
105
|
+
const childrenIdx0 = parentIdx * this.DEGREE + 1;
|
|
106
|
+
|
|
107
|
+
pathIdx.push(idx - childrenIdx0);
|
|
108
|
+
|
|
109
|
+
idx = parentIdx;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return pathIdx;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
pathElementOf(leafIdx: number): bigint[][] {
|
|
116
|
+
if (leafIdx > this.LEAVES_COUNT || leafIdx < 0) {
|
|
117
|
+
throw new Error('wrong leaf index');
|
|
118
|
+
}
|
|
119
|
+
let idx = this.LEAVES_IDX_0 + leafIdx;
|
|
120
|
+
const pathElement: bigint[][] = [];
|
|
121
|
+
|
|
122
|
+
for (let h = 0; h < this.DEPTH; h++) {
|
|
123
|
+
const parentIdx = Math.floor((idx - 1) / this.DEGREE);
|
|
124
|
+
const childrenIdx0 = parentIdx * this.DEGREE + 1;
|
|
125
|
+
|
|
126
|
+
const el: bigint[] = [];
|
|
127
|
+
for (let i = childrenIdx0; i < childrenIdx0 + this.DEGREE; i++) {
|
|
128
|
+
if (i === idx) continue;
|
|
129
|
+
el.push(this.nodes[i]);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
pathElement.push(el);
|
|
133
|
+
|
|
134
|
+
idx = parentIdx;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return pathElement;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
subTree(length: number): Tree {
|
|
141
|
+
const subTree = new Tree(this.DEGREE, this.DEPTH, this.zeros[0]);
|
|
142
|
+
const nodes = [...this.nodes];
|
|
143
|
+
|
|
144
|
+
const DEGREE = this.DEGREE;
|
|
145
|
+
let tail = length;
|
|
146
|
+
for (let d = this.DEPTH; d >= 0; d--) {
|
|
147
|
+
const size = DEGREE ** d;
|
|
148
|
+
const idx0 = (DEGREE ** d - 1) / (DEGREE - 1);
|
|
149
|
+
const zero = this.zeros[this.DEPTH - d];
|
|
150
|
+
for (let i = tail; i < size; i++) {
|
|
151
|
+
nodes[idx0 + i] = zero;
|
|
152
|
+
}
|
|
153
|
+
tail = Math.ceil(tail / DEGREE);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
subTree.nodes = nodes;
|
|
157
|
+
subTree._update(this.LEAVES_IDX_0 + length - 1);
|
|
158
|
+
|
|
159
|
+
return subTree;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
private async _update(nodeIdx: number): Promise<void> {
|
|
163
|
+
let idx = nodeIdx;
|
|
164
|
+
while (idx > 0) {
|
|
165
|
+
const parentIdx = Math.floor((idx - 1) / this.DEGREE);
|
|
166
|
+
const childrenIdx0 = parentIdx * this.DEGREE + 1;
|
|
167
|
+
this.nodes[parentIdx] = await poseidon(
|
|
168
|
+
this.nodes.slice(childrenIdx0, childrenIdx0 + this.DEGREE)
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
idx = parentIdx;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export default Tree;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export type SignResult = {
|
|
2
|
+
signature: string;
|
|
3
|
+
pubkey: Uint8Array;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// we define a bignumber as either a bigint or a string
|
|
7
|
+
// which is what we use the most in MACI
|
|
8
|
+
export type SnarkBigNumber = bigint;
|
|
9
|
+
|
|
10
|
+
// a private key is a single BigNumber
|
|
11
|
+
export type PrivKey = SnarkBigNumber;
|
|
12
|
+
|
|
13
|
+
// a public key is a pair of BigNumbers
|
|
14
|
+
export type PubKey<N = bigint> = [N, N];
|
|
15
|
+
|
|
16
|
+
// a shared key is a pair of BigNumbers
|
|
17
|
+
export type EcdhSharedKey<N = bigint> = [N, N];
|
|
18
|
+
|
|
19
|
+
// a point is a pair of BigNumbers
|
|
20
|
+
export type Point<N = SnarkBigNumber> = [N, N];
|
|
21
|
+
|
|
22
|
+
// a plaintext is an array of BigNumbers
|
|
23
|
+
export type Plaintext<N = bigint> = N[];
|
|
24
|
+
|
|
25
|
+
// a ciphertext is an array of BigNumbers
|
|
26
|
+
export type Ciphertext<N = bigint> = N[];
|
|
27
|
+
|
|
28
|
+
// a merkle tree path elements
|
|
29
|
+
export type PathElements = bigint[][];
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* A acc queue
|
|
33
|
+
*/
|
|
34
|
+
export interface Queue {
|
|
35
|
+
levels: Map<number, Map<number, bigint>>;
|
|
36
|
+
indices: number[];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A private key and a public key
|
|
41
|
+
*/
|
|
42
|
+
export interface Keypair {
|
|
43
|
+
privKey: PrivKey;
|
|
44
|
+
pubKey: PubKey;
|
|
45
|
+
formatedPrivKey: PrivKey;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// An EdDSA signature.
|
|
49
|
+
// R8 is a Baby Jubjub elliptic curve point and S is an element of the finite
|
|
50
|
+
// field of order `l` where `l` is the large prime number dividing the order of
|
|
51
|
+
// Baby Jubjub: see
|
|
52
|
+
// https://iden3-docs.readthedocs.io/en/latest/_downloads/a04267077fb3fdbf2b608e014706e004/Ed-DSA.pdf
|
|
53
|
+
export interface Signature<N = SnarkBigNumber> {
|
|
54
|
+
R8: Point<N>;
|
|
55
|
+
S: N;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* A interface for poseidon hash functions
|
|
60
|
+
*/
|
|
61
|
+
export interface PoseidonFuncs {
|
|
62
|
+
[key: number]: (inputs: bigint[]) => bigint;
|
|
63
|
+
2: (inputs: bigint[]) => bigint;
|
|
64
|
+
3: (inputs: bigint[]) => bigint;
|
|
65
|
+
4: (inputs: bigint[]) => bigint;
|
|
66
|
+
5: (inputs: bigint[]) => bigint;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// a leaf is a single BigNumber
|
|
70
|
+
export type Leaf = bigint;
|
|
71
|
+
|
|
72
|
+
// a node is a leaf or subroot in a quinary merkle tree
|
|
73
|
+
export type Node = Record<number, Leaf>;
|
|
74
|
+
|
|
75
|
+
// a merkle proof is a set of path elements, path indices, and a root
|
|
76
|
+
export interface IMerkleProof {
|
|
77
|
+
pathElements: Leaf[][];
|
|
78
|
+
pathIndices: number[];
|
|
79
|
+
root: Leaf;
|
|
80
|
+
leaf: Leaf;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export type StringifiedBigInts =
|
|
84
|
+
| StringifiedBigInts[]
|
|
85
|
+
| string
|
|
86
|
+
| string[]
|
|
87
|
+
| string[][]
|
|
88
|
+
| string[][][]
|
|
89
|
+
| { [key: string]: StringifiedBigInts }
|
|
90
|
+
| null;
|
|
91
|
+
|
|
92
|
+
export type BigIntVariants =
|
|
93
|
+
| BigIntVariants[]
|
|
94
|
+
| StringifiedBigInts
|
|
95
|
+
| bigint
|
|
96
|
+
| bigint[]
|
|
97
|
+
| bigint[][]
|
|
98
|
+
| bigint[][][]
|
|
99
|
+
| { [key: string]: BigIntVariants }
|
|
100
|
+
| Uint8Array
|
|
101
|
+
| null;
|
package/src/libs/index.ts
CHANGED
package/src/libs/maci/maci.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { OfflineSigner } from '@cosmjs/proto-signing';
|
|
2
|
-
import {
|
|
3
|
-
Account,
|
|
4
|
-
batchGenMessage,
|
|
5
|
-
Circom,
|
|
6
|
-
PublicKey,
|
|
7
|
-
stringizing,
|
|
8
|
-
} from '../circom';
|
|
2
|
+
import { Keypair, batchGenMessage, PubKey, stringizing } from '../crypto';
|
|
9
3
|
import { Contract } from '../contract';
|
|
10
4
|
import { Indexer } from '../indexer';
|
|
11
5
|
import { OracleCertificate } from '../oracle-certificate';
|
|
@@ -31,25 +25,25 @@ export function isErrorResponse(response: unknown): response is ErrorResponse {
|
|
|
31
25
|
}
|
|
32
26
|
|
|
33
27
|
export class MACI {
|
|
34
|
-
public circom: Circom;
|
|
35
28
|
public contract: Contract;
|
|
36
29
|
public indexer: Indexer;
|
|
37
30
|
public oracleCertificate: OracleCertificate;
|
|
31
|
+
public maciKeypair: Keypair;
|
|
38
32
|
constructor({
|
|
39
|
-
circom,
|
|
40
33
|
contract,
|
|
41
34
|
indexer,
|
|
42
35
|
oracleCertificate,
|
|
36
|
+
maciKeypair,
|
|
43
37
|
}: {
|
|
44
|
-
circom: Circom;
|
|
45
38
|
contract: Contract;
|
|
46
39
|
indexer: Indexer;
|
|
47
40
|
oracleCertificate: OracleCertificate;
|
|
41
|
+
maciKeypair: Keypair;
|
|
48
42
|
}) {
|
|
49
|
-
this.circom = circom;
|
|
50
43
|
this.contract = contract;
|
|
51
44
|
this.indexer = indexer;
|
|
52
45
|
this.oracleCertificate = oracleCertificate;
|
|
46
|
+
this.maciKeypair = maciKeypair;
|
|
53
47
|
}
|
|
54
48
|
|
|
55
49
|
async getStateIdxInc({
|
|
@@ -163,7 +157,10 @@ export class MACI {
|
|
|
163
157
|
signer: OfflineSigner;
|
|
164
158
|
address?: string;
|
|
165
159
|
contractAddress: string;
|
|
166
|
-
certificate?:
|
|
160
|
+
certificate?: {
|
|
161
|
+
signature: string;
|
|
162
|
+
amount: string;
|
|
163
|
+
};
|
|
167
164
|
mode?: 'maci' | 'amaci';
|
|
168
165
|
}): Promise<string> {
|
|
169
166
|
if (!address) {
|
|
@@ -205,8 +202,8 @@ export class MACI {
|
|
|
205
202
|
});
|
|
206
203
|
|
|
207
204
|
const balance = await client.whiteBalanceOf({
|
|
208
|
-
amount:
|
|
209
|
-
certificate,
|
|
205
|
+
amount: certificate.amount,
|
|
206
|
+
certificate: certificate.signature,
|
|
210
207
|
sender: address,
|
|
211
208
|
});
|
|
212
209
|
|
|
@@ -444,14 +441,14 @@ export class MACI {
|
|
|
444
441
|
signer,
|
|
445
442
|
address,
|
|
446
443
|
contractAddress,
|
|
447
|
-
|
|
444
|
+
maciKeypair,
|
|
448
445
|
oracleCertificate,
|
|
449
446
|
gasStation = false,
|
|
450
447
|
}: {
|
|
451
448
|
signer: OfflineSigner;
|
|
452
449
|
address?: string;
|
|
453
450
|
contractAddress: string;
|
|
454
|
-
|
|
451
|
+
maciKeypair?: Keypair;
|
|
455
452
|
oracleCertificate?: {
|
|
456
453
|
amount: string;
|
|
457
454
|
signature: string;
|
|
@@ -463,8 +460,9 @@ export class MACI {
|
|
|
463
460
|
address = (await signer.getAccounts())[0].address;
|
|
464
461
|
}
|
|
465
462
|
|
|
466
|
-
if (
|
|
467
|
-
|
|
463
|
+
if (maciKeypair === undefined) {
|
|
464
|
+
maciKeypair = this.maciKeypair;
|
|
465
|
+
// maciKeypair = await this.crypto.genKeypairFromSign(signer, address);
|
|
468
466
|
}
|
|
469
467
|
|
|
470
468
|
const client = await this.contract.contractClient({
|
|
@@ -475,7 +473,7 @@ export class MACI {
|
|
|
475
473
|
return await this.signupOracle({
|
|
476
474
|
client,
|
|
477
475
|
address,
|
|
478
|
-
pubKey:
|
|
476
|
+
pubKey: maciKeypair.pubKey,
|
|
479
477
|
contractAddress,
|
|
480
478
|
oracleCertificate,
|
|
481
479
|
gasStation,
|
|
@@ -484,7 +482,7 @@ export class MACI {
|
|
|
484
482
|
return await this.signupSimple({
|
|
485
483
|
client,
|
|
486
484
|
address,
|
|
487
|
-
pubKey:
|
|
485
|
+
pubKey: maciKeypair.pubKey,
|
|
488
486
|
contractAddress,
|
|
489
487
|
gasStation,
|
|
490
488
|
});
|
|
@@ -540,7 +538,7 @@ export class MACI {
|
|
|
540
538
|
contractAddress,
|
|
541
539
|
selectedOptions,
|
|
542
540
|
operatorCoordPubKey,
|
|
543
|
-
|
|
541
|
+
maciKeypair,
|
|
544
542
|
gasStation = false,
|
|
545
543
|
}: {
|
|
546
544
|
signer: OfflineSigner;
|
|
@@ -551,8 +549,8 @@ export class MACI {
|
|
|
551
549
|
idx: number;
|
|
552
550
|
vc: number;
|
|
553
551
|
}[];
|
|
554
|
-
operatorCoordPubKey:
|
|
555
|
-
|
|
552
|
+
operatorCoordPubKey: PubKey;
|
|
553
|
+
maciKeypair?: Keypair;
|
|
556
554
|
gasStation?: boolean;
|
|
557
555
|
}) {
|
|
558
556
|
if (stateIdx === -1) {
|
|
@@ -576,8 +574,9 @@ export class MACI {
|
|
|
576
574
|
address = (await signer.getAccounts())[0].address;
|
|
577
575
|
}
|
|
578
576
|
|
|
579
|
-
if (
|
|
580
|
-
|
|
577
|
+
if (maciKeypair === undefined) {
|
|
578
|
+
maciKeypair = this.maciKeypair;
|
|
579
|
+
// maciKeypair = await this.crypto.genKeypairFromSign(signer, address);
|
|
581
580
|
}
|
|
582
581
|
|
|
583
582
|
const plan = options.map((o) => {
|
|
@@ -586,7 +585,7 @@ export class MACI {
|
|
|
586
585
|
|
|
587
586
|
const payload = batchGenMessage(
|
|
588
587
|
stateIdx,
|
|
589
|
-
|
|
588
|
+
maciKeypair,
|
|
590
589
|
operatorCoordPubKey,
|
|
591
590
|
plan
|
|
592
591
|
);
|
|
@@ -618,7 +617,7 @@ export class MACI {
|
|
|
618
617
|
address: string;
|
|
619
618
|
payload: {
|
|
620
619
|
msg: bigint[];
|
|
621
|
-
encPubkeys:
|
|
620
|
+
encPubkeys: PubKey;
|
|
622
621
|
}[];
|
|
623
622
|
contractAddress: string;
|
|
624
623
|
gasStation: boolean;
|
|
@@ -671,7 +670,7 @@ export class MACI {
|
|
|
671
670
|
}: {
|
|
672
671
|
client: SigningCosmWasmClient;
|
|
673
672
|
address: string;
|
|
674
|
-
pubKey:
|
|
673
|
+
pubKey: PubKey;
|
|
675
674
|
contractAddress: string;
|
|
676
675
|
gasStation?: boolean;
|
|
677
676
|
}) {
|
|
@@ -724,7 +723,7 @@ export class MACI {
|
|
|
724
723
|
}: {
|
|
725
724
|
client: SigningCosmWasmClient;
|
|
726
725
|
address: string;
|
|
727
|
-
pubKey:
|
|
726
|
+
pubKey: PubKey;
|
|
728
727
|
contractAddress: string;
|
|
729
728
|
oracleCertificate: {
|
|
730
729
|
amount: string;
|