@fatsolutions/privacy-pools-core-starknet-sdk 0.0.43 → 0.0.45

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.
Files changed (62) hide show
  1. package/dist/abis/ERC20.abi.js +145 -145
  2. package/dist/abis/EntryPoint.abi.d.ts +44 -21
  3. package/dist/abis/EntryPoint.abi.js +267 -235
  4. package/dist/abis/EntryPoint.abi.js.map +1 -1
  5. package/dist/abis/PrivacyPool.abi.d.ts +72 -11
  6. package/dist/abis/PrivacyPool.abi.js +227 -145
  7. package/dist/abis/PrivacyPool.abi.js.map +1 -1
  8. package/dist/account.service.d.ts +16 -0
  9. package/dist/account.service.js +31 -0
  10. package/dist/account.service.js.map +1 -0
  11. package/dist/auditor.d.ts +31 -0
  12. package/dist/auditor.js +146 -0
  13. package/dist/auditor.js.map +1 -0
  14. package/dist/contracts/contracts.service.d.ts +3 -3
  15. package/dist/contracts/contracts.service.js +71 -19
  16. package/dist/contracts/contracts.service.js.map +1 -1
  17. package/dist/contracts/index.js.map +1 -1
  18. package/dist/contracts/transactionHandler.d.ts +1 -1
  19. package/dist/contracts/transactionHandler.js +2 -4
  20. package/dist/contracts/transactionHandler.js.map +1 -1
  21. package/dist/data.service.d.ts +20 -6
  22. package/dist/data.service.js +50 -7
  23. package/dist/data.service.js.map +1 -1
  24. package/dist/errors/contracts.errors.js +1 -1
  25. package/dist/errors/index.js.map +1 -1
  26. package/dist/garaga.js +9 -3
  27. package/dist/garaga.js.map +1 -1
  28. package/dist/index.d.ts +3 -1
  29. package/dist/index.js +4 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/sdk.js +4 -4
  32. package/dist/sdk.js.map +1 -1
  33. package/dist/types/conversions.js.map +1 -1
  34. package/dist/types/entrypoint.d.ts +2 -0
  35. package/dist/types/entrypoint.js +50 -30
  36. package/dist/types/entrypoint.js.map +1 -1
  37. package/dist/types/snarkjs.d.ts +7 -46
  38. package/dist/utils.d.ts +5 -2
  39. package/dist/utils.js +11 -2
  40. package/dist/utils.js.map +1 -1
  41. package/package.json +14 -3
  42. package/src/abis/ERC20.abi.ts +145 -145
  43. package/src/abis/EntryPoint.abi.ts +267 -235
  44. package/src/abis/PrivacyPool.abi.ts +227 -145
  45. package/src/abis/index.ts +1 -1
  46. package/src/account.service.ts +47 -0
  47. package/src/auditor.ts +219 -0
  48. package/src/contracts/contracts.service.ts +325 -73
  49. package/src/contracts/index.ts +2 -2
  50. package/src/contracts/transactionHandler.ts +16 -7
  51. package/src/data.service.ts +123 -146
  52. package/src/errors/contracts.errors.ts +6 -6
  53. package/src/errors/index.ts +18 -24
  54. package/src/garaga.ts +10 -4
  55. package/src/index.ts +17 -27
  56. package/src/sdk.ts +39 -26
  57. package/src/types/conversions.ts +11 -12
  58. package/src/types/entrypoint.ts +74 -41
  59. package/src/types/garaga.ts +32 -32
  60. package/src/types/index.ts +1 -1
  61. package/src/types/snarkjs.ts +8 -20
  62. package/src/utils.ts +34 -13
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 { BigNumberish, cairo, num, uint256, Uint256, validateAndParseAddress, validateChecksumAddress } from "starknet";
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 = (new TextDecoder("utf-8")).decode(vkeyRaw);
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,14 +85,14 @@ 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
  */
86
- export function castBigInt(x: number | bigint | Uint256) {
95
+ export function castBigInt(x: number | bigint | Uint256 | BigNumberish) {
87
96
  if (num.isBigNumberish(x)) {
88
97
  return num.toBigInt(x);
89
98
  } else {
@@ -94,3 +103,15 @@ export function castBigInt(x: number | bigint | Uint256) {
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
+ };