@dorafactory/maci-sdk 0.0.41 → 0.0.51

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.
@@ -53,11 +53,11 @@ export declare const batchGenMessage: (stateIdx: number, keypair: Keypair, coord
53
53
  encPubkeys: PubKey<bigint>;
54
54
  }[];
55
55
  export declare const privateKeyFromTxt: (txt: string) => Keypair | undefined;
56
- export declare const genAddKeyProof: (depth: number, { coordPubKey, oldKey, deactivates, }: {
56
+ export declare const genAddKeyInput: (depth: number, { coordPubKey, oldKey, deactivates, }: {
57
57
  coordPubKey: PubKey;
58
58
  oldKey: Keypair;
59
59
  deactivates: bigint[][];
60
- }) => Promise<{
60
+ }) => {
61
61
  inputHash: bigint;
62
62
  coordPubKey: PubKey;
63
63
  deactivateRoot: bigint;
@@ -71,5 +71,5 @@ export declare const genAddKeyProof: (depth: number, { coordPubKey, oldKey, deac
71
71
  deactivateLeafPathElements: bigint[][];
72
72
  nullifier: bigint;
73
73
  oldPrivateKey: bigint;
74
- } | null>;
74
+ } | null;
75
75
  export declare const genRandomKey: () => string;
@@ -8,6 +8,7 @@ import { StdFee } from '@cosmjs/stargate';
8
8
  import { CertificateEcosystem, ErrorResponse, RoundType } from '../../types';
9
9
  import { SignatureResponse } from '../oracle-certificate/types';
10
10
  import { OracleWhitelistConfig } from '../contract/ts/OracleMaci.types';
11
+ import { Groth16ProofType } from '../contract/ts/Maci.types';
11
12
  export declare function isErrorResponse(response: unknown): response is ErrorResponse;
12
13
  export declare class MACI {
13
14
  contract: Contract;
@@ -42,7 +43,7 @@ export declare class MACI {
42
43
  address: string;
43
44
  contractAddress: string;
44
45
  }): Promise<boolean>;
45
- queryWhitelistBalanceOf({ signer, address, contractAddress, certificate, mode, }: {
46
+ queryWhitelistBalanceOf({ signer, address, contractAddress, certificate, }: {
46
47
  signer: OfflineSigner;
47
48
  address?: string;
48
49
  contractAddress: string;
@@ -50,7 +51,6 @@ export declare class MACI {
50
51
  signature: string;
51
52
  amount: string;
52
53
  };
53
- mode?: 'maci' | 'amaci';
54
54
  }): Promise<string>;
55
55
  isWhitelisted({ signer, address, contractAddress, }: {
56
56
  signer: OfflineSigner;
@@ -152,9 +152,44 @@ export declare class MACI {
152
152
  gasStation?: boolean;
153
153
  fee?: StdFee;
154
154
  }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
155
+ deactivate({ signer, address, maciKeypair, contractAddress, gasStation, fee, }: {
156
+ signer: OfflineSigner;
157
+ address?: string;
158
+ maciKeypair?: Keypair;
159
+ contractAddress: string;
160
+ gasStation?: boolean;
161
+ fee?: StdFee;
162
+ }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
155
163
  fetchAllDeactivateLogs({ contractAddress, }: {
156
164
  contractAddress: string;
157
165
  }): Promise<import("../../types").DeactivateMessage[]>;
166
+ genAddKeyInput({ maciKeypair, contractAddress, }: {
167
+ maciKeypair: Keypair;
168
+ contractAddress: string;
169
+ }): Promise<{
170
+ inputHash: bigint;
171
+ coordPubKey: PubKey;
172
+ deactivateRoot: bigint;
173
+ deactivateIndex: number;
174
+ deactivateLeaf: bigint;
175
+ c1: bigint[];
176
+ c2: bigint[];
177
+ randomVal: bigint;
178
+ d1: bigint[];
179
+ d2: bigint[];
180
+ deactivateLeafPathElements: bigint[][];
181
+ nullifier: bigint;
182
+ oldPrivateKey: bigint;
183
+ } | null>;
184
+ addNewKey({ signer, contractAddress, d, proof, nullifier, newMaciKeypair, fee, }: {
185
+ signer: OfflineSigner;
186
+ contractAddress: string;
187
+ d: string[];
188
+ proof: Groth16ProofType;
189
+ nullifier: bigint;
190
+ newMaciKeypair: Keypair;
191
+ fee?: number | StdFee | 'auto';
192
+ }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
158
193
  claimAMaciRound({ signer, contractAddress, fee, }: {
159
194
  signer: OfflineSigner;
160
195
  contractAddress: string;
package/dist/maci.d.ts CHANGED
@@ -6,6 +6,7 @@ import { Keypair, PubKey } from './libs/crypto';
6
6
  import { OracleWhitelistConfig } from './libs/contract/ts/OracleMaci.types';
7
7
  import { SignatureResponse } from './libs/oracle-certificate/types';
8
8
  import { StdFee } from '@cosmjs/amino';
9
+ import { Groth16ProofType } from './libs/contract/ts/Maci.types';
9
10
  /**
10
11
  * @class MaciClient
11
12
  * @description This class is used to interact with Maci Client.
@@ -82,7 +83,7 @@ export declare class MaciClient {
82
83
  }): Promise<string>;
83
84
  getStateIdxByPubKey({ contractAddress, pubKey, }: {
84
85
  contractAddress: string;
85
- pubKey: bigint[];
86
+ pubKey?: bigint[];
86
87
  }): Promise<number>;
87
88
  feegrantAllowance({ signer, address, contractAddress, }: {
88
89
  signer?: OfflineSigner;
@@ -94,7 +95,7 @@ export declare class MaciClient {
94
95
  address?: string;
95
96
  contractAddress: string;
96
97
  }): Promise<boolean>;
97
- queryWhitelistBalanceOf({ signer, address, contractAddress, certificate, mode, }: {
98
+ queryWhitelistBalanceOf({ signer, address, contractAddress, certificate, }: {
98
99
  signer?: OfflineSigner;
99
100
  address?: string;
100
101
  contractAddress: string;
@@ -102,7 +103,6 @@ export declare class MaciClient {
102
103
  signature: string;
103
104
  amount: string;
104
105
  };
105
- mode?: 'maci' | 'amaci';
106
106
  }): Promise<string>;
107
107
  isWhitelisted({ signer, address, contractAddress, }: {
108
108
  signer?: OfflineSigner;
@@ -173,6 +173,41 @@ export declare class MaciClient {
173
173
  maciKeypair?: Keypair;
174
174
  gasStation?: boolean;
175
175
  }): Promise<import("@cosmjs/stargate").DeliverTxResponse>;
176
+ deactivate({ signer, address, contractAddress, gasStation, maciKeypair, fee, }: {
177
+ signer?: OfflineSigner;
178
+ address?: string;
179
+ contractAddress: string;
180
+ gasStation?: boolean;
181
+ maciKeypair?: Keypair;
182
+ fee?: StdFee;
183
+ }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
184
+ genAddKeyInput({ contractAddress, maciKeypair, }: {
185
+ contractAddress: string;
186
+ maciKeypair?: Keypair;
187
+ }): Promise<{
188
+ inputHash: bigint;
189
+ coordPubKey: PubKey;
190
+ deactivateRoot: bigint;
191
+ deactivateIndex: number;
192
+ deactivateLeaf: bigint;
193
+ c1: bigint[];
194
+ c2: bigint[];
195
+ randomVal: bigint;
196
+ d1: bigint[];
197
+ d2: bigint[];
198
+ deactivateLeafPathElements: bigint[][];
199
+ nullifier: bigint;
200
+ oldPrivateKey: bigint;
201
+ } | null>;
202
+ addNewKey({ signer, contractAddress, d, proof, nullifier, newMaciKeypair, fee, }: {
203
+ signer?: OfflineSigner;
204
+ contractAddress: string;
205
+ d: string[];
206
+ proof: Groth16ProofType;
207
+ nullifier: bigint;
208
+ newMaciKeypair: Keypair;
209
+ fee?: number | StdFee | 'auto';
210
+ }): Promise<import("@cosmjs/cosmwasm-stargate").ExecuteResult>;
176
211
  claimAMaciRound({ signer, contractAddress, fee, }: {
177
212
  signer?: OfflineSigner;
178
213
  contractAddress: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dorafactory/maci-sdk",
3
- "version": "0.0.41",
3
+ "version": "0.0.51",
4
4
  "description": "SDK for interacting with maci",
5
5
  "keywords": [
6
6
  "maci",
@@ -39,12 +39,14 @@
39
39
  "assert": "^2.1.0",
40
40
  "bech32": "1.1.4",
41
41
  "cosmjs-types": "^0.9.0",
42
+ "crypto-js": "^4.2.0",
42
43
  "ethers": "^6.13.4"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@commitlint/cli": "^18.0.0",
46
47
  "@commitlint/config-conventional": "^18.0.0",
47
48
  "@commitlint/prompt-cli": "^18.0.0",
49
+ "@types/crypto-js": "^4.2.2",
48
50
  "@types/node": "^20.8.7",
49
51
  "@types/tmp": "^0.2.5",
50
52
  "@typescript-eslint/eslint-plugin": "^6.8.0",
@@ -59,7 +59,7 @@ export interface QuinaryTreeRoot {
59
59
  Uint256,
60
60
  Uint256,
61
61
  Uint256,
62
- Uint256
62
+ Uint256,
63
63
  ];
64
64
  }
65
65
  export interface RoundInfo {
@@ -65,7 +65,7 @@ export interface QuinaryTreeRoot {
65
65
  Uint256,
66
66
  Uint256,
67
67
  Uint256,
68
- Uint256
68
+ Uint256,
69
69
  ];
70
70
  }
71
71
  export interface RoundInfo {
@@ -1,9 +1,9 @@
1
- import assert from "assert";
2
- import { randomBytes } from "crypto";
1
+ import assert from 'assert';
2
+ import CryptoJS from 'crypto-js';
3
3
 
4
- import type { PrivKey } from "./types";
4
+ import type { PrivKey } from './types';
5
5
 
6
- import { SNARK_FIELD_SIZE } from "./constants";
6
+ import { SNARK_FIELD_SIZE } from './constants';
7
7
 
8
8
  /**
9
9
  * @notice A class representing a point on the first group (G1)
@@ -20,8 +20,8 @@ export class G1Point {
20
20
  * @param y the y coordinate
21
21
  */
22
22
  constructor(x: bigint, y: bigint) {
23
- assert(x < SNARK_FIELD_SIZE && x >= 0, "G1Point x out of range");
24
- assert(y < SNARK_FIELD_SIZE && y >= 0, "G1Point y out of range");
23
+ assert(x < SNARK_FIELD_SIZE && x >= 0, 'G1Point x out of range');
24
+ assert(y < SNARK_FIELD_SIZE && y >= 0, 'G1Point y out of range');
25
25
  this.x = x;
26
26
  this.y = y;
27
27
  }
@@ -63,8 +63,8 @@ export class G2Point {
63
63
  * @param y the y coordinate
64
64
  */
65
65
  constructor(x: bigint[], y: bigint[]) {
66
- this.checkPointsRange(x, "x");
67
- this.checkPointsRange(y, "y");
66
+ this.checkPointsRange(x, 'x');
67
+ this.checkPointsRange(y, 'y');
68
68
 
69
69
  this.x = x;
70
70
  this.y = y;
@@ -76,7 +76,12 @@ export class G2Point {
76
76
  * @returns whether they are equal or not
77
77
  */
78
78
  equals(pt: G2Point): boolean {
79
- return this.x[0] === pt.x[0] && this.x[1] === pt.x[1] && this.y[0] === pt.y[0] && this.y[1] === pt.y[1];
79
+ return (
80
+ this.x[0] === pt.x[0] &&
81
+ this.x[1] === pt.x[1] &&
82
+ this.y[0] === pt.y[0] &&
83
+ this.y[1] === pt.y[1]
84
+ );
80
85
  }
81
86
 
82
87
  /**
@@ -95,10 +100,10 @@ export class G2Point {
95
100
  * @param x the x coordinate
96
101
  * @param type the type of the coordinate
97
102
  */
98
- private checkPointsRange(x: bigint[], type: "x" | "y") {
103
+ private checkPointsRange(x: bigint[], type: 'x' | 'y') {
99
104
  assert(
100
105
  x.every((n) => n < SNARK_FIELD_SIZE && n >= 0),
101
- `G2Point ${type} out of range`,
106
+ `G2Point ${type} out of range`
102
107
  );
103
108
  }
104
109
  }
@@ -116,12 +121,16 @@ export const genRandomBabyJubValue = (): bigint => {
116
121
  // Prevent modulo bias
117
122
  // const lim = BigInt('0x10000000000000000000000000000000000000000000000000000000000000000')
118
123
  // const min = (lim - SNARK_FIELD_SIZE) % SNARK_FIELD_SIZE
119
- const min = BigInt("6350874878119819312338956282401532410528162663560392320966563075034087161851");
124
+ const min = BigInt(
125
+ '6350874878119819312338956282401532410528162663560392320966563075034087161851'
126
+ );
120
127
 
121
128
  let privKey: PrivKey = SNARK_FIELD_SIZE;
122
129
 
123
130
  do {
124
- const rand = BigInt(`0x${randomBytes(32).toString("hex")}`);
131
+ const rand = BigInt(
132
+ `0x${CryptoJS.lib.WordArray.random(32).toString(CryptoJS.enc.Hex)}`
133
+ );
125
134
 
126
135
  if (rand >= min) {
127
136
  privKey = rand % SNARK_FIELD_SIZE;
@@ -1,4 +1,4 @@
1
- import { randomBytes } from 'crypto';
1
+ import CryptoJS from 'crypto-js';
2
2
  import { bigInt2Buffer, stringizing } from './bigintUtils';
3
3
  import { poseidonEncrypt } from '@zk-kit/poseidon-cipher';
4
4
  import * as BabyJub from '@zk-kit/baby-jubjub';
@@ -27,7 +27,7 @@ const SNARK_FIELD_SIZE =
27
27
  * @returns A random seed for a private key.
28
28
  */
29
29
  export const genPrivKey = (): bigint =>
30
- BigInt(`0x${randomBytes(32).toString('hex')}`);
30
+ BigInt(`0x${CryptoJS.lib.WordArray.random(32).toString(CryptoJS.enc.Hex)}`);
31
31
 
32
32
  /**
33
33
  * Generate a random value
@@ -116,7 +116,9 @@ export const genMessageFactory =
116
116
  ): bigint[] => {
117
117
  if (!salt) {
118
118
  // uint56
119
- salt = BigInt('0x' + randomBytes(7).toString('hex'));
119
+ salt = BigInt(
120
+ `0x${CryptoJS.lib.WordArray.random(7).toString(CryptoJS.enc.Hex)}`
121
+ );
120
122
  }
121
123
 
122
124
  const packaged =
@@ -223,7 +225,7 @@ const rerandomize = (
223
225
  } as { d1: bigint[]; d2: bigint[] };
224
226
  };
225
227
 
226
- export const genAddKeyProof = async (
228
+ export const genAddKeyInput = (
227
229
  depth: number,
228
230
  {
229
231
  coordPubKey,
@@ -1,5 +1,9 @@
1
1
  export class BaseError extends Error {
2
- constructor(message: string, public code: number, public type: string) {
2
+ constructor(
3
+ message: string,
4
+ public code: number,
5
+ public type: string
6
+ ) {
3
7
  super(message);
4
8
  this.name = this.constructor.name;
5
9
  }