@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
|
@@ -55,13 +55,4 @@ export declare function getContractParams(type: MaciRoundType, circuitType: Maci
|
|
|
55
55
|
maciVoteType?: undefined;
|
|
56
56
|
maciCertSystem?: undefined;
|
|
57
57
|
};
|
|
58
|
-
/**
|
|
59
|
-
* Parses a public key string into its x and y coordinates.
|
|
60
|
-
* @param publickKey - The public key string to parse (128 characters long).
|
|
61
|
-
* @returns An object containing the x and y coordinates as decimal strings.
|
|
62
|
-
*/
|
|
63
|
-
export declare function parsePubkey(publickKey: string): {
|
|
64
|
-
x: string;
|
|
65
|
-
y: string;
|
|
66
|
-
};
|
|
67
58
|
export {};
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1 +1,17 @@
|
|
|
1
1
|
export declare function isValidAddress(address: string): boolean;
|
|
2
|
+
/**
|
|
3
|
+
* Converts a hexadecimal string to a decimal string.
|
|
4
|
+
* @param hexString - The hexadecimal string to convert.
|
|
5
|
+
* @returns The decimal string representation of the input.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hexToDecimalString(hexString: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Parses a public key string into its x and y coordinates.
|
|
10
|
+
* @param publickKey - The public key string to parse (128 characters long).
|
|
11
|
+
* @returns An object containing the x and y coordinates as decimal strings.
|
|
12
|
+
*/
|
|
13
|
+
export declare function decompressPublicKey(compressedPubkey: string): {
|
|
14
|
+
x: string;
|
|
15
|
+
y: string;
|
|
16
|
+
};
|
|
17
|
+
export declare function compressPublicKey(decompressedPubkey: any[]): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dorafactory/maci-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.4",
|
|
4
4
|
"description": "SDK for interacting with maci",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"maci",
|
|
@@ -23,16 +23,6 @@
|
|
|
23
23
|
"main": "./dist/index.js",
|
|
24
24
|
"module": "./dist/index.mjs",
|
|
25
25
|
"types": "./dist/index.d.ts",
|
|
26
|
-
"exports": {
|
|
27
|
-
".": {
|
|
28
|
-
"source": "./src/index.ts",
|
|
29
|
-
"import": "./dist/index.mjs",
|
|
30
|
-
"require": "./dist/index.js"
|
|
31
|
-
},
|
|
32
|
-
"./types": "./src/types/index.ts",
|
|
33
|
-
"./client": "./src/indexer.ts",
|
|
34
|
-
"./const": "./src/libs/const.ts"
|
|
35
|
-
},
|
|
36
26
|
"files": [
|
|
37
27
|
"dist",
|
|
38
28
|
"src"
|
package/src/index.ts
CHANGED
|
@@ -27,9 +27,10 @@ import {
|
|
|
27
27
|
CreateMaciRoundParams,
|
|
28
28
|
CreateOracleMaciRoundParams,
|
|
29
29
|
} from './types';
|
|
30
|
-
import { getContractParams
|
|
30
|
+
import { getContractParams } from './utils';
|
|
31
31
|
import { QTR_LIB } from './vars';
|
|
32
32
|
import { MaciRoundType, MaciCertSystemType } from '../../types';
|
|
33
|
+
import { decompressPublicKey } from '../../utils';
|
|
33
34
|
|
|
34
35
|
export const prefix = 'dora';
|
|
35
36
|
|
|
@@ -131,7 +132,7 @@ export class Contract {
|
|
|
131
132
|
const [{ address }] = await signer.getAccounts();
|
|
132
133
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
133
134
|
const { x: operatorPubkeyX, y: operatorPubkeyY } =
|
|
134
|
-
|
|
135
|
+
decompressPublicKey(operatorPubkey);
|
|
135
136
|
const {
|
|
136
137
|
parameters,
|
|
137
138
|
groth16ProcessVkey,
|
|
@@ -200,7 +201,7 @@ export class Contract {
|
|
|
200
201
|
const [{ address }] = await signer.getAccounts();
|
|
201
202
|
const client = await createContractClientByWallet(this.rpcEndpoint, signer);
|
|
202
203
|
const { x: operatorPubkeyX, y: operatorPubkeyY } =
|
|
203
|
-
|
|
204
|
+
decompressPublicKey(operatorPubkey);
|
|
204
205
|
const {
|
|
205
206
|
parameters,
|
|
206
207
|
groth16ProcessVkey,
|
|
@@ -152,28 +152,3 @@ export function getContractParams(
|
|
|
152
152
|
};
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Converts a hexadecimal string to a decimal string.
|
|
158
|
-
* @param hexString - The hexadecimal string to convert.
|
|
159
|
-
* @returns The decimal string representation of the input.
|
|
160
|
-
*/
|
|
161
|
-
function hexToDecimalString(hexString: string) {
|
|
162
|
-
const decimalString = BigInt('0x' + hexString).toString(10);
|
|
163
|
-
return decimalString;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Parses a public key string into its x and y coordinates.
|
|
168
|
-
* @param publickKey - The public key string to parse (128 characters long).
|
|
169
|
-
* @returns An object containing the x and y coordinates as decimal strings.
|
|
170
|
-
*/
|
|
171
|
-
export function parsePubkey(publickKey: string) {
|
|
172
|
-
const x = publickKey.slice(0, 64);
|
|
173
|
-
const y = publickKey.slice(64);
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
x: hexToDecimalString(x),
|
|
177
|
-
y: hexToDecimalString(y),
|
|
178
|
-
};
|
|
179
|
-
}
|
package/src/utils/index.ts
CHANGED
|
@@ -15,30 +15,46 @@ export function isValidAddress(address: string): boolean {
|
|
|
15
15
|
return address.startsWith('dora') && verifyIsBech32(address) === undefined;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Converts a hexadecimal string to a decimal string.
|
|
20
|
+
* @param hexString - The hexadecimal string to convert.
|
|
21
|
+
* @returns The decimal string representation of the input.
|
|
22
|
+
*/
|
|
23
|
+
export function hexToDecimalString(hexString: string) {
|
|
24
|
+
const decimalString = BigInt('0x' + hexString).toString(10);
|
|
25
|
+
return decimalString;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function padWithZerosIfNeeded(inputString: string) {
|
|
29
|
+
if (inputString.length === 64) {
|
|
30
|
+
return inputString;
|
|
31
|
+
} else if (inputString.length < 64) {
|
|
32
|
+
const zerosToAdd = 64 - inputString.length;
|
|
33
|
+
const zeroPadding = '0'.repeat(zerosToAdd);
|
|
34
|
+
return zeroPadding + inputString;
|
|
35
|
+
}
|
|
36
|
+
throw new Error('Invalid input string length');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Parses a public key string into its x and y coordinates.
|
|
41
|
+
* @param publickKey - The public key string to parse (128 characters long).
|
|
42
|
+
* @returns An object containing the x and y coordinates as decimal strings.
|
|
43
|
+
*/
|
|
44
|
+
export function decompressPublicKey(compressedPubkey: string) {
|
|
45
|
+
const x = compressedPubkey.slice(0, 64);
|
|
46
|
+
const y = compressedPubkey.slice(64);
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
x: hexToDecimalString(x),
|
|
50
|
+
y: hexToDecimalString(y),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function compressPublicKey(decompressedPubkey: any[]) {
|
|
55
|
+
const x = decompressedPubkey[0];
|
|
56
|
+
const y = decompressedPubkey[1];
|
|
57
|
+
const compressedPubkey =
|
|
58
|
+
padWithZerosIfNeeded(x.toString(16)) + padWithZerosIfNeeded(y.toString(16));
|
|
59
|
+
return compressedPubkey;
|
|
60
|
+
}
|