@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.
@@ -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 {};
@@ -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.2",
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
@@ -10,3 +10,4 @@ export { Circuit } from './libs/query';
10
10
  export { Operator } from './libs/query';
11
11
  export { Proof } from './libs/query';
12
12
  export { Transaction } from './libs/query';
13
+ export * from './utils';
@@ -27,9 +27,10 @@ import {
27
27
  CreateMaciRoundParams,
28
28
  CreateOracleMaciRoundParams,
29
29
  } from './types';
30
- import { getContractParams, parsePubkey } from './utils';
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
- parsePubkey(operatorPubkey);
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
- parsePubkey(operatorPubkey);
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
- }
@@ -15,30 +15,46 @@ export function isValidAddress(address: string): boolean {
15
15
  return address.startsWith('dora') && verifyIsBech32(address) === undefined;
16
16
  }
17
17
 
18
- // export async function fetchBaseUrl(url: string) {
19
- // const response = await fetch(url);
20
- // return response;
21
- // }
22
-
23
- // export async function fetchPages<T>(
24
- // query: string,
25
- // after: string,
26
- // limit: number | null = 10
27
- // ): Promise<T> {
28
- // const isFirstPage = after === 'first';
29
- // // after = isFirstPage ? null : after;
30
-
31
- // const response = await fetch(apiEndpoint, {
32
- // method: 'POST',
33
- // headers: {
34
- // 'Content-Type': 'application/json',
35
- // Accept: 'application/json',
36
- // },
37
- // body: JSON.stringify({
38
- // query,
39
- // variables: { limit, after: isFirstPage ? undefined : after },
40
- // }),
41
- // }).then((res) => res.json());
42
-
43
- // return response;
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
+ }