@dorafactory/maci-sdk 0.0.2 → 0.0.4
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/README.md +113 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +38 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -14
- package/dist/index.mjs.map +1 -1
- package/dist/libs/contract/utils.d.ts +0 -9
- package/dist/utils/index.d.ts +16 -0
- package/package.json +1 -11
- package/src/index.ts +1 -0
- package/src/libs/contract/contract.ts +4 -3
- package/src/libs/contract/utils.ts +0 -25
- package/src/utils/index.ts +43 -27
package/README.md
CHANGED
|
@@ -1 +1,113 @@
|
|
|
1
|
-
# Maci
|
|
1
|
+
# Maci Client
|
|
2
|
+
|
|
3
|
+
MACI (Minimal Anti-Collusion Infrastructure) client SDK for interacting with MACI contracts.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @dorafactory/maci-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### Initialize Client
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { MaciClient } from '@dorafactory/maci-sdk';
|
|
17
|
+
|
|
18
|
+
const client = new MaciClient({
|
|
19
|
+
network: 'testnet', // or 'mainnet'
|
|
20
|
+
});
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Query Functions
|
|
24
|
+
|
|
25
|
+
#### Query Account Balance
|
|
26
|
+
```typescript
|
|
27
|
+
const balance = await client.balanceOf('dora1...');
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
#### Query Round Information
|
|
31
|
+
```typescript
|
|
32
|
+
// Query round by ID
|
|
33
|
+
const round = await client.getRoundById('dora1...');
|
|
34
|
+
|
|
35
|
+
// Get list of rounds
|
|
36
|
+
const rounds = await client.getRounds('first', 10);
|
|
37
|
+
|
|
38
|
+
// Query rounds by status
|
|
39
|
+
const roundsByStatus = await client.getRoundsByStatus('Created', 'first', 10);
|
|
40
|
+
|
|
41
|
+
// Query rounds by circuit name
|
|
42
|
+
const roundsByCircuit = await client.getRoundsByCircuitName('amaci-qv', 'first', 10);
|
|
43
|
+
|
|
44
|
+
// Query rounds by operator address
|
|
45
|
+
const roundsByOperator = await client.getRoundsByOperator('dora1...', 'first', 10);
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
#### Query Operator Information
|
|
49
|
+
```typescript
|
|
50
|
+
// Query operator by address
|
|
51
|
+
const operator = await client.getOperatorByAddress('dora1...');
|
|
52
|
+
|
|
53
|
+
// Get list of operators
|
|
54
|
+
const operators = await client.getOperators('first', 10);
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
#### Query Circuit Information
|
|
58
|
+
```typescript
|
|
59
|
+
// Query circuit by name
|
|
60
|
+
const circuit = await client.getCircuitByName('amaci-qv');
|
|
61
|
+
|
|
62
|
+
// Get all circuits
|
|
63
|
+
const circuits = await client.getCircuits();
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
#### Query Transaction Information
|
|
67
|
+
```typescript
|
|
68
|
+
// Query transaction by hash
|
|
69
|
+
const transaction = await client.getTransactionByHash('HASH...');
|
|
70
|
+
|
|
71
|
+
// Get list of transactions
|
|
72
|
+
const transactions = await client.getTransactions('first', 10);
|
|
73
|
+
|
|
74
|
+
// Query transactions by contract address
|
|
75
|
+
const txByContract = await client.getTransactionsByContractAddress('dora1...', 'first', 10);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
#### Query Proof Information
|
|
79
|
+
```typescript
|
|
80
|
+
const proof = await client.getProofByContractAddress('dora1...');
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Contract Interactions
|
|
84
|
+
|
|
85
|
+
#### Create New Voting Round
|
|
86
|
+
```typescript
|
|
87
|
+
const wallet = await DirectSecp256k1Wallet.fromKey(
|
|
88
|
+
Buffer.from(privateKey, 'hex'),
|
|
89
|
+
'dora'
|
|
90
|
+
);
|
|
91
|
+
|
|
92
|
+
const newRound = await client.createOracleMaciRound({
|
|
93
|
+
signer: wallet,
|
|
94
|
+
operatorPubkey: '0e752c...',
|
|
95
|
+
startVoting: new Date(),
|
|
96
|
+
endVoting: new Date(new Date().getTime() + 1 * 60 * 1000),
|
|
97
|
+
title: 'test',
|
|
98
|
+
description: 'test',
|
|
99
|
+
link: 'test',
|
|
100
|
+
maxVoter: '5',
|
|
101
|
+
maxOption: '5',
|
|
102
|
+
circuitType: MaciCircuitType.IP1V,
|
|
103
|
+
whitelistBackendPubkey: 'AoYo...',
|
|
104
|
+
whitelistEcosystem: 'cosmoshub',
|
|
105
|
+
whitelistSnapshotHeight: '0',
|
|
106
|
+
whitelistVotingPowerArgs: {
|
|
107
|
+
mode: 'slope',
|
|
108
|
+
slope: '1000000',
|
|
109
|
+
threshold: '1000000',
|
|
110
|
+
},
|
|
111
|
+
feegrantOperator: 'dora1...',
|
|
112
|
+
});
|
|
113
|
+
```
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -34,7 +34,11 @@ __export(src_exports, {
|
|
|
34
34
|
Round: () => Round,
|
|
35
35
|
Transaction: () => Transaction,
|
|
36
36
|
circuits: () => circuits,
|
|
37
|
+
compressPublicKey: () => compressPublicKey,
|
|
38
|
+
decompressPublicKey: () => decompressPublicKey,
|
|
37
39
|
getDefaultParams: () => getDefaultParams,
|
|
40
|
+
hexToDecimalString: () => hexToDecimalString,
|
|
41
|
+
isValidAddress: () => isValidAddress,
|
|
38
42
|
validator_operator_set: () => validator_operator_set
|
|
39
43
|
});
|
|
40
44
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -557,6 +561,34 @@ function verifyIsBech32(address) {
|
|
|
557
561
|
function isValidAddress(address) {
|
|
558
562
|
return address.startsWith("dora") && verifyIsBech32(address) === void 0;
|
|
559
563
|
}
|
|
564
|
+
function hexToDecimalString(hexString) {
|
|
565
|
+
const decimalString = BigInt("0x" + hexString).toString(10);
|
|
566
|
+
return decimalString;
|
|
567
|
+
}
|
|
568
|
+
function padWithZerosIfNeeded(inputString) {
|
|
569
|
+
if (inputString.length === 64) {
|
|
570
|
+
return inputString;
|
|
571
|
+
} else if (inputString.length < 64) {
|
|
572
|
+
const zerosToAdd = 64 - inputString.length;
|
|
573
|
+
const zeroPadding = "0".repeat(zerosToAdd);
|
|
574
|
+
return zeroPadding + inputString;
|
|
575
|
+
}
|
|
576
|
+
throw new Error("Invalid input string length");
|
|
577
|
+
}
|
|
578
|
+
function decompressPublicKey(compressedPubkey) {
|
|
579
|
+
const x = compressedPubkey.slice(0, 64);
|
|
580
|
+
const y = compressedPubkey.slice(64);
|
|
581
|
+
return {
|
|
582
|
+
x: hexToDecimalString(x),
|
|
583
|
+
y: hexToDecimalString(y)
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
function compressPublicKey(decompressedPubkey) {
|
|
587
|
+
const x = decompressedPubkey[0];
|
|
588
|
+
const y = decompressedPubkey[1];
|
|
589
|
+
const compressedPubkey = padWithZerosIfNeeded(x.toString(16)) + padWithZerosIfNeeded(y.toString(16));
|
|
590
|
+
return compressedPubkey;
|
|
591
|
+
}
|
|
560
592
|
|
|
561
593
|
// src/libs/query/operator.ts
|
|
562
594
|
var Operator = class {
|
|
@@ -3669,18 +3701,6 @@ function getContractParams(type, circuitType, proofSystem, maxVoter, maxOption)
|
|
|
3669
3701
|
};
|
|
3670
3702
|
}
|
|
3671
3703
|
}
|
|
3672
|
-
function hexToDecimalString(hexString) {
|
|
3673
|
-
const decimalString = BigInt("0x" + hexString).toString(10);
|
|
3674
|
-
return decimalString;
|
|
3675
|
-
}
|
|
3676
|
-
function parsePubkey(publickKey) {
|
|
3677
|
-
const x = publickKey.slice(0, 64);
|
|
3678
|
-
const y = publickKey.slice(64);
|
|
3679
|
-
return {
|
|
3680
|
-
x: hexToDecimalString(x),
|
|
3681
|
-
y: hexToDecimalString(y)
|
|
3682
|
-
};
|
|
3683
|
-
}
|
|
3684
3704
|
|
|
3685
3705
|
// src/libs/contract/contract.ts
|
|
3686
3706
|
var Contract = class {
|
|
@@ -3769,7 +3789,7 @@ var Contract = class {
|
|
|
3769
3789
|
const end_time = (endVoting.getTime() * 10 ** 6).toString();
|
|
3770
3790
|
const [{ address }] = await signer.getAccounts();
|
|
3771
3791
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
3772
|
-
const { x: operatorPubkeyX, y: operatorPubkeyY } =
|
|
3792
|
+
const { x: operatorPubkeyX, y: operatorPubkeyY } = decompressPublicKey(operatorPubkey);
|
|
3773
3793
|
const {
|
|
3774
3794
|
parameters,
|
|
3775
3795
|
groth16ProcessVkey,
|
|
@@ -3835,7 +3855,7 @@ var Contract = class {
|
|
|
3835
3855
|
const end_time = (endVoting.getTime() * 1e6).toString();
|
|
3836
3856
|
const [{ address }] = await signer.getAccounts();
|
|
3837
3857
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
3838
|
-
const { x: operatorPubkeyX, y: operatorPubkeyY } =
|
|
3858
|
+
const { x: operatorPubkeyX, y: operatorPubkeyY } = decompressPublicKey(operatorPubkey);
|
|
3839
3859
|
const {
|
|
3840
3860
|
parameters,
|
|
3841
3861
|
groth16ProcessVkey,
|
|
@@ -4175,7 +4195,11 @@ var MaciClient2 = class {
|
|
|
4175
4195
|
Round,
|
|
4176
4196
|
Transaction,
|
|
4177
4197
|
circuits,
|
|
4198
|
+
compressPublicKey,
|
|
4199
|
+
decompressPublicKey,
|
|
4178
4200
|
getDefaultParams,
|
|
4201
|
+
hexToDecimalString,
|
|
4202
|
+
isValidAddress,
|
|
4179
4203
|
validator_operator_set
|
|
4180
4204
|
});
|
|
4181
4205
|
//# sourceMappingURL=index.js.map
|