Skip to content

Commit a405d81

Browse files
committed
feat(sdk): update pre deactivate config
1 parent e0ac773 commit a405d81

File tree

19 files changed

+620
-81
lines changed

19 files changed

+620
-81
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,6 @@ pnpm-lock.yaml
4444
# claude only
4545
.claude
4646
CLAUDE.md
47+
48+
# zkey files
49+
add-new-key_v3/

packages/sdk/src/libs/contract/contract.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export class Contract {
7272
voiceCreditAmount,
7373
circuitType,
7474
preDeactivateRoot,
75+
preDeactivateCoordinator,
7576
oracleWhitelistPubkey,
7677
fee = 'auto',
7778
}: CreateAMaciRoundParams & { signer: OfflineSigner }) {
@@ -90,10 +91,33 @@ export class Contract {
9091
);
9192

9293
preDeactivateRoot = preDeactivateRoot || '0';
94+
95+
// Convert preDeactivateCoordinator to {x, y} format if provided
96+
let preDeactivateCoordinatorPubKey: { x: string; y: string } | undefined =
97+
undefined;
98+
if (preDeactivateCoordinator !== undefined) {
99+
let coordinatorX: bigint;
100+
let coordinatorY: bigint;
101+
102+
if (typeof preDeactivateCoordinator === 'bigint') {
103+
// If it's a packed bigint, unpack it
104+
[coordinatorX, coordinatorY] = unpackPubKey(preDeactivateCoordinator);
105+
} else {
106+
// If it's already a PubKey array [x, y]
107+
[coordinatorX, coordinatorY] = preDeactivateCoordinator;
108+
}
109+
110+
preDeactivateCoordinatorPubKey = {
111+
x: coordinatorX.toString(),
112+
y: coordinatorY.toString(),
113+
};
114+
}
115+
93116
const res = await client.createRound(
94117
{
95118
operator,
96119
preDeactivateRoot,
120+
preDeactivateCoordinator: preDeactivateCoordinatorPubKey,
97121
voiceCreditAmount,
98122
whitelist,
99123
roundInfo: {
@@ -1513,6 +1537,7 @@ export class Contract {
15131537
whitelist,
15141538
voiceCreditAmount,
15151539
preDeactivateRoot,
1540+
preDeactivateCoordinator,
15161541
oracleWhitelistPubkey,
15171542
circuitType,
15181543
gasStation = false,
@@ -1527,13 +1552,35 @@ export class Contract {
15271552
contractAddress: this.apiSaasAddress,
15281553
});
15291554

1555+
// Convert preDeactivateCoordinator to {x, y} format if provided
1556+
let preDeactivateCoordinatorPubKey: { x: string; y: string } | undefined =
1557+
undefined;
1558+
if (preDeactivateCoordinator !== undefined) {
1559+
let coordinatorX: bigint;
1560+
let coordinatorY: bigint;
1561+
1562+
if (typeof preDeactivateCoordinator === 'bigint') {
1563+
// If it's a packed bigint, unpack it
1564+
[coordinatorX, coordinatorY] = unpackPubKey(preDeactivateCoordinator);
1565+
} else {
1566+
// If it's already a PubKey array [x, y]
1567+
[coordinatorX, coordinatorY] = preDeactivateCoordinator;
1568+
}
1569+
1570+
preDeactivateCoordinatorPubKey = {
1571+
x: coordinatorX.toString(),
1572+
y: coordinatorY.toString(),
1573+
};
1574+
}
1575+
15301576
const roundParams = {
15311577
certificationSystem: '0',
15321578
circuitType: circuitType.toString(),
15331579
maxVoter: maxVoter.toString(),
15341580
operator,
15351581
oracleWhitelistPubkey,
15361582
preDeactivateRoot: preDeactivateRoot || '0',
1583+
preDeactivateCoordinator: preDeactivateCoordinatorPubKey,
15371584
roundInfo: {
15381585
title,
15391586
description: description || '',
@@ -1562,6 +1609,7 @@ export class Contract {
15621609
operator,
15631610
oracle_whitelist_pubkey: oracleWhitelistPubkey,
15641611
pre_deactivate_root: preDeactivateRoot || '0',
1612+
pre_deactivate_coordinator: preDeactivateCoordinatorPubKey,
15651613
round_info: roundParams.roundInfo,
15661614
voice_credit_amount: voiceCreditAmount,
15671615
vote_option_map: voteOptionMap,

packages/sdk/src/libs/contract/ts/AMaci.client.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
Period,
3535
TallyDelayInfo,
3636
NullableString,
37+
NullableUint256,
3738
Uint128,
3839
ArrayOfString,
3940
Whitelist,
@@ -68,6 +69,7 @@ export interface AMaciReadOnlyInterface {
6869
queryCircuitType: () => Promise<Uint256>;
6970
queryCertSystem: () => Promise<Uint256>;
7071
queryPreDeactivateRoot: () => Promise<Uint256>;
72+
queryPreDeactivateCoordinatorHash: () => Promise<NullableUint256>;
7173
getDelayRecords: () => Promise<DelayRecords>;
7274
getTallyDelay: () => Promise<TallyDelayInfo>;
7375
queryOracleWhitelistConfig: () => Promise<NullableString>;
@@ -119,6 +121,8 @@ export class AMaciQueryClient implements AMaciReadOnlyInterface {
119121
this.queryCircuitType = this.queryCircuitType.bind(this);
120122
this.queryCertSystem = this.queryCertSystem.bind(this);
121123
this.queryPreDeactivateRoot = this.queryPreDeactivateRoot.bind(this);
124+
this.queryPreDeactivateCoordinatorHash =
125+
this.queryPreDeactivateCoordinatorHash.bind(this);
122126
this.getDelayRecords = this.getDelayRecords.bind(this);
123127
this.getTallyDelay = this.getTallyDelay.bind(this);
124128
this.queryOracleWhitelistConfig =
@@ -279,6 +283,11 @@ export class AMaciQueryClient implements AMaciReadOnlyInterface {
279283
query_pre_deactivate_root: {},
280284
});
281285
};
286+
queryPreDeactivateCoordinatorHash = async (): Promise<NullableUint256> => {
287+
return this.client.queryContractSmart(this.contractAddress, {
288+
query_pre_deactivate_coordinator_hash: {},
289+
});
290+
};
282291
getDelayRecords = async (): Promise<DelayRecords> => {
283292
return this.client.queryContractSmart(this.contractAddress, {
284293
get_delay_records: {},

packages/sdk/src/libs/contract/ts/AMaci.types.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface InstantiateMsg {
1717
operator: Addr;
1818
oracle_whitelist_pubkey?: string | null;
1919
parameters: MaciParameters;
20+
pre_deactivate_coordinator?: PubKey | null;
2021
pre_deactivate_root: Uint256;
2122
round_info: RoundInfo;
2223
voice_credit_amount: Uint256;
@@ -238,6 +239,9 @@ export type QueryMsg =
238239
| {
239240
query_pre_deactivate_root: {};
240241
}
242+
| {
243+
query_pre_deactivate_coordinator_hash: {};
244+
}
241245
| {
242246
get_delay_records: {};
243247
}
@@ -288,6 +292,7 @@ export interface TallyDelayInfo {
288292
total_work: number;
289293
}
290294
export type NullableString = string | null;
295+
export type NullableUint256 = Uint256 | null;
291296
export type Uint128 = string;
292297
export type ArrayOfString = string[];
293298
export interface Whitelist {

packages/sdk/src/libs/contract/ts/ApiSaas.client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ export interface ApiSaasInterface extends ApiSaasReadOnlyInterface {
189189
maxVoter,
190190
operator,
191191
oracleWhitelistPubkey,
192+
preDeactivateCoordinator,
192193
preDeactivateRoot,
193194
roundInfo,
194195
voiceCreditAmount,
@@ -201,6 +202,7 @@ export interface ApiSaasInterface extends ApiSaasReadOnlyInterface {
201202
maxVoter: Uint256;
202203
operator: Addr;
203204
oracleWhitelistPubkey?: string;
205+
preDeactivateCoordinator?: PubKey;
204206
preDeactivateRoot: Uint256;
205207
roundInfo: RoundInfo;
206208
voiceCreditAmount: Uint256;
@@ -480,6 +482,7 @@ export class ApiSaasClient
480482
maxVoter,
481483
operator,
482484
oracleWhitelistPubkey,
485+
preDeactivateCoordinator,
483486
preDeactivateRoot,
484487
roundInfo,
485488
voiceCreditAmount,
@@ -492,6 +495,7 @@ export class ApiSaasClient
492495
maxVoter: Uint256;
493496
operator: Addr;
494497
oracleWhitelistPubkey?: string;
498+
preDeactivateCoordinator?: PubKey;
495499
preDeactivateRoot: Uint256;
496500
roundInfo: RoundInfo;
497501
voiceCreditAmount: Uint256;
@@ -513,6 +517,7 @@ export class ApiSaasClient
513517
max_voter: maxVoter,
514518
operator,
515519
oracle_whitelist_pubkey: oracleWhitelistPubkey,
520+
pre_deactivate_coordinator: preDeactivateCoordinator,
516521
pre_deactivate_root: preDeactivateRoot,
517522
round_info: roundInfo,
518523
voice_credit_amount: voiceCreditAmount,

packages/sdk/src/libs/contract/ts/ApiSaas.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export type ExecuteMsg =
6868
max_voter: Uint256;
6969
operator: Addr;
7070
oracle_whitelist_pubkey?: string | null;
71+
pre_deactivate_coordinator?: PubKey | null;
7172
pre_deactivate_root: Uint256;
7273
round_info: RoundInfo;
7374
voice_credit_amount: Uint256;

packages/sdk/src/libs/contract/ts/Registry.client.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export interface RegistryInterface extends RegistryReadOnlyInterface {
166166
maxVoter,
167167
operator,
168168
oracleWhitelistPubkey,
169+
preDeactivateCoordinator,
169170
preDeactivateRoot,
170171
roundInfo,
171172
voiceCreditAmount,
@@ -178,6 +179,7 @@ export interface RegistryInterface extends RegistryReadOnlyInterface {
178179
maxVoter: Uint256;
179180
operator: Addr;
180181
oracleWhitelistPubkey?: string;
182+
preDeactivateCoordinator?: PubKey;
181183
preDeactivateRoot: Uint256;
182184
roundInfo: RoundInfo;
183185
voiceCreditAmount: Uint256;
@@ -342,6 +344,7 @@ export class RegistryClient
342344
maxVoter,
343345
operator,
344346
oracleWhitelistPubkey,
347+
preDeactivateCoordinator,
345348
preDeactivateRoot,
346349
roundInfo,
347350
voiceCreditAmount,
@@ -354,6 +357,7 @@ export class RegistryClient
354357
maxVoter: Uint256;
355358
operator: Addr;
356359
oracleWhitelistPubkey?: string;
360+
preDeactivateCoordinator?: PubKey;
357361
preDeactivateRoot: Uint256;
358362
roundInfo: RoundInfo;
359363
voiceCreditAmount: Uint256;
@@ -375,6 +379,7 @@ export class RegistryClient
375379
max_voter: maxVoter,
376380
operator,
377381
oracle_whitelist_pubkey: oracleWhitelistPubkey,
382+
pre_deactivate_coordinator: preDeactivateCoordinator,
378383
pre_deactivate_root: preDeactivateRoot,
379384
round_info: roundInfo,
380385
voice_credit_amount: voiceCreditAmount,

packages/sdk/src/libs/contract/ts/Registry.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type ExecuteMsg =
3333
max_voter: Uint256;
3434
operator: Addr;
3535
oracle_whitelist_pubkey?: string | null;
36+
pre_deactivate_coordinator?: PubKey | null;
3637
pre_deactivate_root: Uint256;
3738
round_info: RoundInfo;
3839
voice_credit_amount: Uint256;

packages/sdk/src/libs/contract/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
MaciCertSystemType,
99
CertificateEcosystem,
1010
} from '../../types';
11+
import { PubKey } from '../crypto';
1112

1213
export type CreateRoundParams = {
1314
signer?: OfflineSigner;
@@ -27,6 +28,7 @@ export type CreateAMaciRoundParams = {
2728
whitelist?: RegistryWhitelist;
2829
voiceCreditAmount: string;
2930
preDeactivateRoot?: string;
31+
preDeactivateCoordinator?: PubKey | bigint;
3032
oracleWhitelistPubkey?: string;
3133
} & CreateRoundParams;
3234

@@ -67,6 +69,7 @@ export type CreateApiSaasAmaciRoundParams = {
6769
whitelist?: RegistryWhitelist;
6870
voiceCreditAmount: string;
6971
preDeactivateRoot?: string;
72+
preDeactivateCoordinator?: PubKey | bigint;
7073
oracleWhitelistPubkey?: string;
7174
gasStation?: boolean;
7275
fee?: StdFee | 'auto' | number;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { genAccounts, VoterClient } from '../src';
2+
import dotenv from 'dotenv';
3+
4+
dotenv.config();
5+
6+
import * as path from 'path';
7+
8+
async function main() {
9+
const secretKey = process.env.ADMIN_PRIVATE_KEY;
10+
if (!secretKey) {
11+
throw new Error('ADMIN_PRIVATE_KEY not found in environment variables');
12+
}
13+
14+
const coordinator = new VoterClient({
15+
secretKey,
16+
});
17+
console.log('coordinator', coordinator.getPubkey().toPackedData());
18+
const { deactivates, root, leaves, tree } = coordinator
19+
.getSigner()
20+
.genDeactivateRoot(
21+
[
22+
62071628452838807843875387950635179100467701723619568550128325247586768602836n, // voter pubkey
23+
8488296638481981615643178142445511165715108699929572315723118360556015787681n,
24+
59183419265525843263552876017551249941309839147094892945935225919011194818766n,
25+
],
26+
2
27+
);
28+
29+
console.log(root);
30+
31+
const voterClient = new VoterClient({
32+
mnemonic: process.env.VOTER_MNEMONIC,
33+
});
34+
35+
const circuitPower = '2-1-1-5';
36+
const genProof = await voterClient.buildPreAddNewKeyPayload({
37+
stateTreeDepth: 2,
38+
operatorPubkey:
39+
15985671812509037697999452079047723323214510694838922960102081803756551067669n,
40+
deactivates,
41+
wasmFile: path.join(
42+
process.cwd(),
43+
`add-new-key_v3/${circuitPower}/addKey.wasm`
44+
),
45+
zkeyFile: path.join(
46+
process.cwd(),
47+
`add-new-key_v3/${circuitPower}/addKey.zkey`
48+
),
49+
});
50+
51+
console.log(genProof);
52+
}
53+
54+
main();

0 commit comments

Comments
 (0)