@fatsolutions/privacy-pools-core-starknet-sdk 0.0.44 → 0.0.46
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/abis/ERC20.abi.js +145 -145
- package/dist/abis/EntryPoint.abi.d.ts +35 -12
- package/dist/abis/EntryPoint.abi.js +262 -230
- package/dist/abis/EntryPoint.abi.js.map +1 -1
- package/dist/abis/PrivacyPool.abi.d.ts +69 -8
- package/dist/abis/PrivacyPool.abi.js +228 -146
- package/dist/abis/PrivacyPool.abi.js.map +1 -1
- package/dist/account.service.d.ts +16 -0
- package/dist/account.service.js +31 -0
- package/dist/account.service.js.map +1 -0
- package/dist/auditor.d.ts +31 -0
- package/dist/auditor.js +146 -0
- package/dist/auditor.js.map +1 -0
- package/dist/contracts/contracts.service.d.ts +3 -3
- package/dist/contracts/contracts.service.js +71 -19
- package/dist/contracts/contracts.service.js.map +1 -1
- package/dist/contracts/index.js.map +1 -1
- package/dist/contracts/transactionHandler.d.ts +1 -1
- package/dist/contracts/transactionHandler.js +2 -4
- package/dist/contracts/transactionHandler.js.map +1 -1
- package/dist/data.service.d.ts +20 -6
- package/dist/data.service.js +50 -7
- package/dist/data.service.js.map +1 -1
- package/dist/errors/contracts.errors.js +1 -1
- package/dist/errors/index.js.map +1 -1
- package/dist/garaga.js +9 -3
- package/dist/garaga.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/sdk.js +4 -4
- package/dist/sdk.js.map +1 -1
- package/dist/types/conversions.js.map +1 -1
- package/dist/types/entrypoint.d.ts +2 -0
- package/dist/types/entrypoint.js +50 -30
- package/dist/types/entrypoint.js.map +1 -1
- package/dist/types/snarkjs.d.ts +7 -46
- package/dist/utils.d.ts +4 -1
- package/dist/utils.js +11 -2
- package/dist/utils.js.map +1 -1
- package/package.json +14 -3
- package/src/abis/ERC20.abi.ts +145 -145
- package/src/abis/EntryPoint.abi.ts +262 -230
- package/src/abis/PrivacyPool.abi.ts +228 -146
- package/src/abis/index.ts +1 -1
- package/src/account.service.ts +47 -0
- package/src/auditor.ts +219 -0
- package/src/contracts/contracts.service.ts +325 -73
- package/src/contracts/index.ts +2 -2
- package/src/contracts/transactionHandler.ts +16 -7
- package/src/data.service.ts +123 -146
- package/src/errors/contracts.errors.ts +6 -6
- package/src/errors/index.ts +18 -24
- package/src/garaga.ts +10 -4
- package/src/index.ts +17 -27
- package/src/sdk.ts +39 -26
- package/src/types/conversions.ts +11 -12
- package/src/types/entrypoint.ts +74 -41
- package/src/types/garaga.ts +32 -32
- package/src/types/index.ts +1 -1
- package/src/types/snarkjs.ts +8 -20
- package/src/utils.ts +33 -12
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { WithdrawalProof } from "@0xbow/privacy-pools-core-sdk";
|
|
2
2
|
import { poseidonHashMany } from "@scure/starknet";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
BigNumberish,
|
|
5
|
+
cairo,
|
|
6
|
+
CairoOption,
|
|
7
|
+
CairoOptionVariant,
|
|
8
|
+
num,
|
|
9
|
+
uint256,
|
|
10
|
+
Uint256,
|
|
11
|
+
validateAndParseAddress
|
|
12
|
+
} from "starknet";
|
|
4
13
|
|
|
5
14
|
import { getGroth16CallData } from "./garaga.js";
|
|
6
15
|
import { snarkJsKeyIntoGaraga, snarkJsProofIntoGaraga } from "./types/conversions.js";
|
|
@@ -11,11 +20,11 @@ const { toBigInt } = num;
|
|
|
11
20
|
|
|
12
21
|
/**
|
|
13
22
|
* Computes a unique scope identifier for a privacy pool.
|
|
14
|
-
*
|
|
23
|
+
*
|
|
15
24
|
* The scope is calculated using Poseidon hash of the pool address, chain ID, and asset address.
|
|
16
25
|
* This creates a unique identifier that can be used to distinguish different privacy pools
|
|
17
26
|
* across different chains and assets.
|
|
18
|
-
*
|
|
27
|
+
*
|
|
19
28
|
* @param poolAddress - The address of the privacy pool contract
|
|
20
29
|
* @param chainId - The chain ID where the pool is deployed
|
|
21
30
|
* @param assetAddress - The address of the asset (token) used in the pool
|
|
@@ -27,11 +36,11 @@ export function computeScope(poolAddress: BigNumberish, chainId: BigNumberish, a
|
|
|
27
36
|
|
|
28
37
|
/**
|
|
29
38
|
* Computes a context hash for withdrawal transactions.
|
|
30
|
-
*
|
|
39
|
+
*
|
|
31
40
|
* The context combines the serialized withdrawal data with the scope to create
|
|
32
41
|
* a unique identifier for the withdrawal context. This is used in privacy pool
|
|
33
42
|
* operations to ensure proper transaction validation.
|
|
34
|
-
*
|
|
43
|
+
*
|
|
35
44
|
* @param withdrawal - The withdrawal data to include in the context
|
|
36
45
|
* @param scope - The scope identifier of the privacy pool
|
|
37
46
|
* @returns The computed context as a Poseidon hash
|
|
@@ -44,23 +53,23 @@ export function computeContext(withdrawal: Withdrawal, scope: BigNumberish) {
|
|
|
44
53
|
|
|
45
54
|
/**
|
|
46
55
|
* Parses a raw verification key from Uint8Array to SnarkJS format.
|
|
47
|
-
*
|
|
56
|
+
*
|
|
48
57
|
* @param vkeyRaw - The raw verification key as bytes
|
|
49
58
|
* @returns The parsed verification key in SnarkJS format
|
|
50
59
|
* @throws {Error} If the raw key cannot be parsed as valid JSON
|
|
51
60
|
*/
|
|
52
61
|
export function rawKeyIntoSnarkJs(vkeyRaw: Uint8Array): SnarkJsVkey {
|
|
53
|
-
const vkeyString =
|
|
54
|
-
return JSON.parse(vkeyString);
|
|
62
|
+
const vkeyString = new TextDecoder("utf-8").decode(vkeyRaw);
|
|
63
|
+
return JSON.parse(vkeyString) as SnarkJsVkey;
|
|
55
64
|
}
|
|
56
65
|
|
|
57
66
|
/**
|
|
58
67
|
* Converts a withdrawal proof to Garaga-compatible calldata format.
|
|
59
|
-
*
|
|
68
|
+
*
|
|
60
69
|
* This function takes a withdrawal proof and verification key, converts them
|
|
61
70
|
* to Garaga format, and generates the calldata needed for Starknet contract calls.
|
|
62
71
|
* The resulting calldata can be used directly with Garaga's Groth16 verifier.
|
|
63
|
-
*
|
|
72
|
+
*
|
|
64
73
|
* @param withdrawalProof - The withdrawal proof from the core SDK
|
|
65
74
|
* @param vkeyRaw - The raw verification key as bytes
|
|
66
75
|
* @returns Promise resolving to calldata array (excluding the first element)
|
|
@@ -76,10 +85,10 @@ export async function withdrawalProofToGaragaCalldata(withdrawalProof: Withdrawa
|
|
|
76
85
|
|
|
77
86
|
/**
|
|
78
87
|
* Safely converts various numeric types to BigInt.
|
|
79
|
-
*
|
|
88
|
+
*
|
|
80
89
|
* This utility handles the conversion of different Starknet numeric types
|
|
81
90
|
* (including Uint256 structs) to standard BigInt values.
|
|
82
|
-
*
|
|
91
|
+
*
|
|
83
92
|
* @param x - The value to convert (number, bigint, or Uint256)
|
|
84
93
|
* @returns The value as a BigInt
|
|
85
94
|
*/
|
|
@@ -94,3 +103,15 @@ export function castBigInt(x: number | bigint | Uint256 | BigNumberish) {
|
|
|
94
103
|
export function toAddress(x: BigNumberish): StarknetAddress {
|
|
95
104
|
return validateAndParseAddress(x) as StarknetAddress;
|
|
96
105
|
}
|
|
106
|
+
|
|
107
|
+
export const Some = <T>(t: T): CairoOption<T> => {
|
|
108
|
+
return new CairoOption<T>(CairoOptionVariant.Some, t);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
export const None = <T>(): CairoOption<T> => {
|
|
112
|
+
return new CairoOption<T>(CairoOptionVariant.None);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export const toCairoOption = <T>(t?: T): CairoOption<T> => {
|
|
116
|
+
return t === undefined ? None() : Some(t);
|
|
117
|
+
};
|