@dorafactory/maci-sdk 0.1.3-pre.46.beta.15 → 0.1.3-pre.46.beta.16
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.js +295 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +295 -3
- package/dist/index.mjs.map +1 -1
- package/dist/libs/contract/contract.d.ts +46 -0
- package/dist/maci.d.ts +30 -0
- package/dist/voter.d.ts +30 -0
- package/package.json +1 -1
- package/src/libs/contract/contract.ts +230 -0
- package/src/libs/maci/maci.ts +44 -3
- package/src/maci.ts +48 -0
- package/src/voter.ts +50 -0
package/dist/index.js
CHANGED
|
@@ -5161,6 +5161,198 @@ var Contract = class {
|
|
|
5161
5161
|
pollId
|
|
5162
5162
|
};
|
|
5163
5163
|
}
|
|
5164
|
+
async signupViaSaas({
|
|
5165
|
+
signer,
|
|
5166
|
+
contractAddress,
|
|
5167
|
+
pubkey,
|
|
5168
|
+
certificate,
|
|
5169
|
+
amount,
|
|
5170
|
+
granter,
|
|
5171
|
+
fee = 1.8
|
|
5172
|
+
}) {
|
|
5173
|
+
const client = await createApiSaasClientBy({
|
|
5174
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5175
|
+
wallet: signer,
|
|
5176
|
+
contractAddress: this.apiSaasAddress
|
|
5177
|
+
});
|
|
5178
|
+
const saasGranter = granter || this.apiSaasAddress;
|
|
5179
|
+
const signUpParams = {
|
|
5180
|
+
contractAddr: contractAddress,
|
|
5181
|
+
pubkey,
|
|
5182
|
+
certificate,
|
|
5183
|
+
amount
|
|
5184
|
+
};
|
|
5185
|
+
if (typeof fee !== "object") {
|
|
5186
|
+
const [{ address }] = await signer.getAccounts();
|
|
5187
|
+
const contractClient = await this.contractClient({ signer });
|
|
5188
|
+
const msg = {
|
|
5189
|
+
sign_up: {
|
|
5190
|
+
contract_addr: contractAddress,
|
|
5191
|
+
pubkey,
|
|
5192
|
+
certificate: certificate ?? null,
|
|
5193
|
+
amount: amount ?? null
|
|
5194
|
+
}
|
|
5195
|
+
};
|
|
5196
|
+
const gasEstimation = await contractClient.simulate(
|
|
5197
|
+
address,
|
|
5198
|
+
[
|
|
5199
|
+
{
|
|
5200
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5201
|
+
value: {
|
|
5202
|
+
sender: address,
|
|
5203
|
+
contract: this.apiSaasAddress,
|
|
5204
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5205
|
+
}
|
|
5206
|
+
}
|
|
5207
|
+
],
|
|
5208
|
+
""
|
|
5209
|
+
);
|
|
5210
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5211
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5212
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5213
|
+
const grantFee2 = {
|
|
5214
|
+
amount: calculatedFee.amount,
|
|
5215
|
+
gas: calculatedFee.gas,
|
|
5216
|
+
granter: saasGranter
|
|
5217
|
+
};
|
|
5218
|
+
return client.signUp(signUpParams, grantFee2);
|
|
5219
|
+
}
|
|
5220
|
+
const grantFee = {
|
|
5221
|
+
...fee,
|
|
5222
|
+
granter: saasGranter
|
|
5223
|
+
};
|
|
5224
|
+
return client.signUp(signUpParams, grantFee);
|
|
5225
|
+
}
|
|
5226
|
+
async preAddNewKeyViaSaas({
|
|
5227
|
+
signer,
|
|
5228
|
+
contractAddress,
|
|
5229
|
+
pubkey,
|
|
5230
|
+
nullifier,
|
|
5231
|
+
d,
|
|
5232
|
+
groth16Proof,
|
|
5233
|
+
granter,
|
|
5234
|
+
fee = 1.8
|
|
5235
|
+
}) {
|
|
5236
|
+
const client = await createApiSaasClientBy({
|
|
5237
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5238
|
+
wallet: signer,
|
|
5239
|
+
contractAddress: this.apiSaasAddress
|
|
5240
|
+
});
|
|
5241
|
+
const saasGranter = granter || this.apiSaasAddress;
|
|
5242
|
+
const keyParams = {
|
|
5243
|
+
contractAddr: contractAddress,
|
|
5244
|
+
pubkey,
|
|
5245
|
+
nullifier,
|
|
5246
|
+
d,
|
|
5247
|
+
groth16Proof
|
|
5248
|
+
};
|
|
5249
|
+
if (typeof fee !== "object") {
|
|
5250
|
+
const [{ address }] = await signer.getAccounts();
|
|
5251
|
+
const contractClient = await this.contractClient({ signer });
|
|
5252
|
+
const msg = {
|
|
5253
|
+
pre_add_new_key: {
|
|
5254
|
+
contract_addr: contractAddress,
|
|
5255
|
+
pubkey,
|
|
5256
|
+
nullifier,
|
|
5257
|
+
d,
|
|
5258
|
+
groth16_proof: groth16Proof
|
|
5259
|
+
}
|
|
5260
|
+
};
|
|
5261
|
+
const gasEstimation = await contractClient.simulate(
|
|
5262
|
+
address,
|
|
5263
|
+
[
|
|
5264
|
+
{
|
|
5265
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5266
|
+
value: {
|
|
5267
|
+
sender: address,
|
|
5268
|
+
contract: this.apiSaasAddress,
|
|
5269
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5270
|
+
}
|
|
5271
|
+
}
|
|
5272
|
+
],
|
|
5273
|
+
""
|
|
5274
|
+
);
|
|
5275
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5276
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5277
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5278
|
+
const grantFee2 = {
|
|
5279
|
+
amount: calculatedFee.amount,
|
|
5280
|
+
gas: calculatedFee.gas,
|
|
5281
|
+
granter: saasGranter
|
|
5282
|
+
};
|
|
5283
|
+
return client.preAddNewKey(keyParams, grantFee2);
|
|
5284
|
+
}
|
|
5285
|
+
const grantFee = {
|
|
5286
|
+
...fee,
|
|
5287
|
+
granter: saasGranter
|
|
5288
|
+
};
|
|
5289
|
+
return client.preAddNewKey(keyParams, grantFee);
|
|
5290
|
+
}
|
|
5291
|
+
async addNewKeyViaSaas({
|
|
5292
|
+
signer,
|
|
5293
|
+
contractAddress,
|
|
5294
|
+
pubkey,
|
|
5295
|
+
nullifier,
|
|
5296
|
+
d,
|
|
5297
|
+
groth16Proof,
|
|
5298
|
+
granter,
|
|
5299
|
+
fee = 1.8
|
|
5300
|
+
}) {
|
|
5301
|
+
const client = await createApiSaasClientBy({
|
|
5302
|
+
rpcEndpoint: this.rpcEndpoint,
|
|
5303
|
+
wallet: signer,
|
|
5304
|
+
contractAddress: this.apiSaasAddress
|
|
5305
|
+
});
|
|
5306
|
+
const saasGranter = granter || this.apiSaasAddress;
|
|
5307
|
+
const keyParams = {
|
|
5308
|
+
contractAddr: contractAddress,
|
|
5309
|
+
pubkey,
|
|
5310
|
+
nullifier,
|
|
5311
|
+
d,
|
|
5312
|
+
groth16Proof
|
|
5313
|
+
};
|
|
5314
|
+
if (typeof fee !== "object") {
|
|
5315
|
+
const [{ address }] = await signer.getAccounts();
|
|
5316
|
+
const contractClient = await this.contractClient({ signer });
|
|
5317
|
+
const msg = {
|
|
5318
|
+
add_new_key: {
|
|
5319
|
+
contract_addr: contractAddress,
|
|
5320
|
+
pubkey,
|
|
5321
|
+
nullifier,
|
|
5322
|
+
d,
|
|
5323
|
+
groth16_proof: groth16Proof
|
|
5324
|
+
}
|
|
5325
|
+
};
|
|
5326
|
+
const gasEstimation = await contractClient.simulate(
|
|
5327
|
+
address,
|
|
5328
|
+
[
|
|
5329
|
+
{
|
|
5330
|
+
typeUrl: "/cosmwasm.wasm.v1.MsgExecuteContract",
|
|
5331
|
+
value: {
|
|
5332
|
+
sender: address,
|
|
5333
|
+
contract: this.apiSaasAddress,
|
|
5334
|
+
msg: new TextEncoder().encode(JSON.stringify(msg))
|
|
5335
|
+
}
|
|
5336
|
+
}
|
|
5337
|
+
],
|
|
5338
|
+
""
|
|
5339
|
+
);
|
|
5340
|
+
const multiplier = typeof fee === "number" ? fee : 1.8;
|
|
5341
|
+
const gasPrice = import_stargate2.GasPrice.fromString("10000000000peaka");
|
|
5342
|
+
const calculatedFee = (0, import_stargate2.calculateFee)(Math.round(gasEstimation * multiplier), gasPrice);
|
|
5343
|
+
const grantFee2 = {
|
|
5344
|
+
amount: calculatedFee.amount,
|
|
5345
|
+
gas: calculatedFee.gas,
|
|
5346
|
+
granter: saasGranter
|
|
5347
|
+
};
|
|
5348
|
+
return client.addNewKey(keyParams, grantFee2);
|
|
5349
|
+
}
|
|
5350
|
+
const grantFee = {
|
|
5351
|
+
...fee,
|
|
5352
|
+
granter: saasGranter
|
|
5353
|
+
};
|
|
5354
|
+
return client.addNewKey(keyParams, grantFee);
|
|
5355
|
+
}
|
|
5164
5356
|
async publishMessageViaSaas({
|
|
5165
5357
|
signer,
|
|
5166
5358
|
contractAddress,
|
|
@@ -5714,7 +5906,20 @@ var MACI = class {
|
|
|
5714
5906
|
}
|
|
5715
5907
|
};
|
|
5716
5908
|
const signupFunds = [{ denom: FEE_DENOM, amount: this.feeConfig.signupFee }];
|
|
5717
|
-
if (gasStation === true &&
|
|
5909
|
+
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
5910
|
+
return this.contract.signupViaSaas({
|
|
5911
|
+
signer,
|
|
5912
|
+
contractAddress,
|
|
5913
|
+
pubkey: {
|
|
5914
|
+
x: pubKey[0].toString(),
|
|
5915
|
+
y: pubKey[1].toString()
|
|
5916
|
+
},
|
|
5917
|
+
certificate: oracleCertificate?.signature,
|
|
5918
|
+
amount: oracleCertificate?.amount,
|
|
5919
|
+
granter,
|
|
5920
|
+
fee
|
|
5921
|
+
});
|
|
5922
|
+
} else if (gasStation === true && typeof fee !== "object") {
|
|
5718
5923
|
const gasEstimation = await client.simulate(
|
|
5719
5924
|
address,
|
|
5720
5925
|
[
|
|
@@ -6316,7 +6521,18 @@ var MACI = class {
|
|
|
6316
6521
|
y: newPubkey[1].toString()
|
|
6317
6522
|
}
|
|
6318
6523
|
};
|
|
6319
|
-
if (gasStation === true &&
|
|
6524
|
+
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
6525
|
+
return this.contract.addNewKeyViaSaas({
|
|
6526
|
+
signer,
|
|
6527
|
+
contractAddress,
|
|
6528
|
+
pubkey: keyParams.pubkey,
|
|
6529
|
+
nullifier: keyParams.nullifier,
|
|
6530
|
+
d,
|
|
6531
|
+
groth16Proof: proof,
|
|
6532
|
+
granter,
|
|
6533
|
+
fee
|
|
6534
|
+
});
|
|
6535
|
+
} else if (gasStation === true && typeof fee !== "object") {
|
|
6320
6536
|
const [{ address }] = await signer.getAccounts();
|
|
6321
6537
|
const contractClient = await this.contract.contractClient({ signer });
|
|
6322
6538
|
const msg = {
|
|
@@ -6388,7 +6604,18 @@ var MACI = class {
|
|
|
6388
6604
|
y: newPubkey[1].toString()
|
|
6389
6605
|
}
|
|
6390
6606
|
};
|
|
6391
|
-
if (gasStation === true &&
|
|
6607
|
+
if (gasStation === true && granter === this.contract.apiSaasAddress) {
|
|
6608
|
+
return this.contract.preAddNewKeyViaSaas({
|
|
6609
|
+
signer,
|
|
6610
|
+
contractAddress,
|
|
6611
|
+
pubkey: keyParams.pubkey,
|
|
6612
|
+
nullifier: keyParams.nullifier,
|
|
6613
|
+
d,
|
|
6614
|
+
groth16Proof: proof,
|
|
6615
|
+
granter,
|
|
6616
|
+
fee
|
|
6617
|
+
});
|
|
6618
|
+
} else if (gasStation === true && typeof fee !== "object") {
|
|
6392
6619
|
const [{ address }] = await signer.getAccounts();
|
|
6393
6620
|
const contractClient = await this.contract.contractClient({ signer });
|
|
6394
6621
|
const msg = {
|
|
@@ -7020,6 +7247,38 @@ var MaciClient = class {
|
|
|
7020
7247
|
}
|
|
7021
7248
|
return this.saasApiClient;
|
|
7022
7249
|
}
|
|
7250
|
+
/**
|
|
7251
|
+
* Poll the chain REST endpoint until the given transaction is committed on-chain,
|
|
7252
|
+
* then return its `tx_response` object with an added `status` field.
|
|
7253
|
+
*
|
|
7254
|
+
* @param txHash - On-chain transaction hash to wait for.
|
|
7255
|
+
* @param options.timeout - Max wait time in milliseconds (default: 60 000 ms).
|
|
7256
|
+
* @param options.interval - Polling interval in milliseconds (default: 2 000 ms).
|
|
7257
|
+
* @returns The Cosmos `tx_response` record plus `status`: `'success'` when `code === 0`, `'failed'` otherwise.
|
|
7258
|
+
* @throws If the transaction is not found within the timeout period.
|
|
7259
|
+
*/
|
|
7260
|
+
async waitForTransaction(txHash, options = {}) {
|
|
7261
|
+
const timeout = options.timeout ?? 6e4;
|
|
7262
|
+
const interval = options.interval ?? 2e3;
|
|
7263
|
+
const deadline = Date.now() + timeout;
|
|
7264
|
+
while (Date.now() < deadline) {
|
|
7265
|
+
try {
|
|
7266
|
+
const data = await this.http.fetchRest(`/cosmos/tx/v1beta1/txs/${txHash}`);
|
|
7267
|
+
if (data?.tx_response) {
|
|
7268
|
+
const txResponse = data.tx_response;
|
|
7269
|
+
return {
|
|
7270
|
+
...txResponse,
|
|
7271
|
+
status: txResponse.code === 0 ? "success" : "failed"
|
|
7272
|
+
};
|
|
7273
|
+
}
|
|
7274
|
+
} catch {
|
|
7275
|
+
}
|
|
7276
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
7277
|
+
}
|
|
7278
|
+
throw new Error(
|
|
7279
|
+
`waitForTransaction: transaction ${txHash} not found on chain within ${timeout}ms`
|
|
7280
|
+
);
|
|
7281
|
+
}
|
|
7023
7282
|
getMaciKeypair() {
|
|
7024
7283
|
return this.maciKeypair;
|
|
7025
7284
|
}
|
|
@@ -8862,6 +9121,39 @@ var VoterClient = class _VoterClient {
|
|
|
8862
9121
|
}
|
|
8863
9122
|
return await this.saasApiClient.preAddNewKey(params);
|
|
8864
9123
|
}
|
|
9124
|
+
// ==================== Transaction Utilities ====================
|
|
9125
|
+
/**
|
|
9126
|
+
* Poll the chain REST endpoint until the given transaction is committed on-chain,
|
|
9127
|
+
* then return its `tx_response` object with an added `status` field.
|
|
9128
|
+
*
|
|
9129
|
+
* @param txHash - On-chain transaction hash to wait for.
|
|
9130
|
+
* @param options.timeout - Max wait time in milliseconds (default: 60 000 ms).
|
|
9131
|
+
* @param options.interval - Polling interval in milliseconds (default: 2 000 ms).
|
|
9132
|
+
* @returns The Cosmos `tx_response` record plus `status`: `'success'` when `code === 0`, `'failed'` otherwise.
|
|
9133
|
+
* @throws If the transaction is not found within the timeout period.
|
|
9134
|
+
*/
|
|
9135
|
+
async waitForTransaction(txHash, options = {}) {
|
|
9136
|
+
const timeout = options.timeout ?? 6e4;
|
|
9137
|
+
const interval = options.interval ?? 2e3;
|
|
9138
|
+
const deadline = Date.now() + timeout;
|
|
9139
|
+
while (Date.now() < deadline) {
|
|
9140
|
+
try {
|
|
9141
|
+
const data = await this.http.fetchRest(`/cosmos/tx/v1beta1/txs/${txHash}`);
|
|
9142
|
+
if (data?.tx_response) {
|
|
9143
|
+
const txResponse = data.tx_response;
|
|
9144
|
+
return {
|
|
9145
|
+
...txResponse,
|
|
9146
|
+
status: txResponse.code === 0 ? "success" : "failed"
|
|
9147
|
+
};
|
|
9148
|
+
}
|
|
9149
|
+
} catch {
|
|
9150
|
+
}
|
|
9151
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
9152
|
+
}
|
|
9153
|
+
throw new Error(
|
|
9154
|
+
`waitForTransaction: transaction ${txHash} not found on chain within ${timeout}ms`
|
|
9155
|
+
);
|
|
9156
|
+
}
|
|
8865
9157
|
// ==================== Maci Voter Methods ====================
|
|
8866
9158
|
/**
|
|
8867
9159
|
* Pre-create a new account for AMACI voting (pre-deactivate mode).
|