@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/index.ts CHANGED
@@ -1,43 +1,38 @@
1
1
  /**
2
2
  * @fileoverview Privacy Pool Starknet SDK
3
- *
3
+ *
4
4
  * This SDK provides a Starknet-specific implementation for interacting with Privacy Pool contracts.
5
5
  * It extends the core Privacy Pool SDK with Starknet-specific functionality, including:
6
- *
6
+ *
7
7
  * - Garaga proof format conversion for efficient Groth16 verification on Starknet
8
8
  * - Contract interaction services with simulation and execution modes
9
9
  * - Event fetching and data parsing from Starknet networks
10
10
  * - Type-safe interfaces for all Privacy Pool operations
11
11
  * - Comprehensive error handling with detailed error codes
12
- *
12
+ *
13
13
  * @example Basic Usage
14
14
  * ```typescript
15
15
  * import { PrivacyPoolStarknetSDK, StarknetDataService } from '@fatsolutions/privacy-pools-core-starknet-sdk';
16
- *
16
+ *
17
17
  * // Initialize SDK with circuits
18
18
  * const sdk = new PrivacyPoolStarknetSDK(circuits);
19
- *
19
+ *
20
20
  * // Create contract service
21
21
  * const contractService = sdk.createSNContractInstance(entrypointAddress, account);
22
- *
22
+ *
23
23
  * // Deposit funds
24
24
  * const depositCall = await contractService.depositETH(amount, precommitment);
25
- *
25
+ *
26
26
  * // Generate and execute withdrawal
27
27
  * const { withdrawalProof, calldata } = await sdk.proveWithdrawalSN(commitment, input);
28
28
  * const withdrawResult = await contractService.withdraw(withdrawal, calldata, scope, { mode: Mode.EXECUTE });
29
29
  * ```
30
- *
30
+ *
31
31
  * @author Fat Solutions
32
32
  * @version 0.0.1
33
33
  */
34
34
 
35
- export {
36
- generateMerkleProof,
37
- getCommitment,
38
- hashPrecommitment,
39
- Circuits
40
- } from "@0xbow/privacy-pools-core-sdk";
35
+ export { generateMerkleProof, getCommitment, hashPrecommitment, Circuits } from "@0xbow/privacy-pools-core-sdk";
41
36
 
42
37
  export type { WithdrawalProof } from "@0xbow/privacy-pools-core-sdk";
43
38
 
@@ -51,18 +46,10 @@ export { PrivacyPoolStarknetSDK } from "./sdk.js";
51
46
  export * from "./contracts/index.js";
52
47
 
53
48
  // Types and interfaces - rename conflicting exports
54
- export type {
55
- Withdrawal as StarknetWithdrawal,
56
- RelayData
57
- } from "./types/entrypoint.js";
49
+ export type { Withdrawal as StarknetWithdrawal, RelayData } from "./types/entrypoint.js";
58
50
 
59
51
  // Functions from entrypoint types
60
- export {
61
- parseRelayData,
62
- parseWithdrawal,
63
- serializeRelayData,
64
- serializeWithdrawal
65
- } from "./types/entrypoint.js";
52
+ export { parseRelayData, parseWithdrawal, serializeRelayData, serializeWithdrawal } from "./types/entrypoint.js";
66
53
  export * from "./types/conversions.js";
67
54
  export * from "./types/garaga.js";
68
55
  export * from "./types/snarkjs.js";
@@ -80,8 +67,11 @@ export * from "./utils.js";
80
67
  export * from "./constants.js";
81
68
 
82
69
  // Data service
83
- export {
84
- StarknetDataService,
85
- } from "./data.service.js";
70
+ export { StarknetDataService } from "./data.service.js";
86
71
 
87
72
  export { type StarknetAddress } from "./types/starknet.js";
73
+
74
+ // Auditor
75
+ export * from "./auditor.js";
76
+
77
+ export * from "./account.service.js";
package/src/sdk.ts CHANGED
@@ -1,4 +1,12 @@
1
- import { CircuitName, CircuitsInterface, Commitment, CommitmentProof, PrivacyPoolSDK, WithdrawalProof, WithdrawalProofInput } from "@0xbow/privacy-pools-core-sdk";
1
+ import {
2
+ CircuitName,
3
+ CircuitsInterface,
4
+ Commitment,
5
+ CommitmentProof,
6
+ PrivacyPoolSDK,
7
+ WithdrawalProof,
8
+ WithdrawalProofInput,
9
+ } from "@0xbow/privacy-pools-core-sdk";
2
10
  import { RpcProvider, Account as SNAccount } from "starknet";
3
11
 
4
12
  import { SNContractInteractionsService } from "./contracts/contracts.service.js";
@@ -7,18 +15,18 @@ import { withdrawalProofToGaragaCalldata } from "./utils.js";
7
15
 
8
16
  /**
9
17
  * Starknet-specific implementation of the Privacy Pool SDK.
10
- *
18
+ *
11
19
  * This class extends the base PrivacyPoolSDK to provide Starknet-specific functionality,
12
20
  * including proof generation optimized for Garaga verification and contract interaction services.
13
- *
21
+ *
14
22
  * @example
15
23
  * ```typescript
16
24
  * const circuits = new CircuitsImplementation();
17
25
  * const sdk = new PrivacyPoolStarknetSDK(circuits);
18
- *
26
+ *
19
27
  * // Create contract service
20
28
  * const contractService = sdk.createSNContractInstance(entrypointAddress, account);
21
- *
29
+ *
22
30
  * // Generate withdrawal proof with Starknet calldata
23
31
  * const { withdrawalProof, calldata } = await sdk.proveWithdrawalSN(commitment, input);
24
32
  * ```
@@ -28,7 +36,7 @@ export class PrivacyPoolStarknetSDK extends PrivacyPoolSDK {
28
36
 
29
37
  /**
30
38
  * Creates a new Starknet Privacy Pool SDK instance.
31
- *
39
+ *
32
40
  * @param circuits - Interface for circuit operations and verification key management
33
41
  */
34
42
  constructor(circuits: CircuitsInterface) {
@@ -38,68 +46,74 @@ export class PrivacyPoolStarknetSDK extends PrivacyPoolSDK {
38
46
 
39
47
  /**
40
48
  * Creates a new Starknet contract interactions service instance.
41
- *
49
+ *
42
50
  * @param entrypointAddress - The address of the EntryPoint contract on Starknet
43
51
  * @param providerOrAccount - Either a Starknet Account for signing transactions or RpcProvider for read-only operations
44
52
  * @returns A configured contract service instance for interacting with Privacy Pool contracts
45
53
  */
46
54
  public createSNContractInstance(
47
55
  entrypointAddress: StarknetAddress,
48
- providerOrAccount: SNAccount | RpcProvider,
56
+ providerOrAccount: SNAccount | RpcProvider
49
57
  ): SNContractInteractionsService {
50
- return new SNContractInteractionsService(
51
- entrypointAddress,
52
- providerOrAccount
53
- );
58
+ return new SNContractInteractionsService(entrypointAddress, providerOrAccount);
54
59
  }
55
60
 
56
61
  /**
57
62
  * Generates a withdrawal proof optimized for Starknet/Garaga verification.
58
- *
63
+ *
59
64
  * This method creates a withdrawal proof and converts it to the calldata format
60
65
  * required by Garaga's Groth16 verifier on Starknet.
61
- *
66
+ *
62
67
  * @param commitment - The commitment to prove withdrawal for
63
68
  * @param input - The withdrawal proof input containing nullifier and other required data
64
69
  * @returns Object containing the withdrawal proof and Garaga-formatted calldata
65
70
  * @throws {Error} If proof generation fails or verification key cannot be retrieved
66
71
  */
67
- async proveWithdrawalSN(commitment: Commitment, input: WithdrawalProofInput): Promise<{ withdrawalProof: WithdrawalProof, calldata: bigint[]; }> {
72
+ async proveWithdrawalSN(
73
+ commitment: Commitment,
74
+ input: WithdrawalProofInput
75
+ ): Promise<{ withdrawalProof: WithdrawalProof; calldata: bigint[] }> {
68
76
  const withdrawalProof: WithdrawalProof = await super.proveWithdrawal(commitment, input);
69
77
  const vkeyRaw = await this.circuits.getVerificationKey(CircuitName.Withdraw);
70
78
  return {
71
79
  withdrawalProof,
72
- calldata: await withdrawalProofToGaragaCalldata(withdrawalProof, vkeyRaw)
80
+ calldata: await withdrawalProofToGaragaCalldata(withdrawalProof, vkeyRaw),
73
81
  };
74
82
  }
75
83
 
76
84
  /**
77
85
  * Generates a commitment proof optimized for Starknet/Garaga verification.
78
- *
86
+ *
79
87
  * This method creates a commitment proof and converts it to the calldata format
80
88
  * required by Garaga's Groth16 verifier on Starknet.
81
- *
89
+ *
82
90
  * @param commitment - The commitment to generate proof for
83
91
  * @returns Object containing the commitment proof and Garaga-formatted calldata
84
92
  * @throws {Error} If proof generation fails or verification key cannot be retrieved
85
93
  */
86
- async proveCommitmentSN(commitment: Commitment): Promise<{ commitmentProof: CommitmentProof, calldata: bigint[]; }> {
87
- const { preimage: { label, value, precommitment: { nullifier, secret } } } = commitment;
94
+ async proveCommitmentSN(commitment: Commitment): Promise<{ commitmentProof: CommitmentProof; calldata: bigint[] }> {
95
+ const {
96
+ preimage: {
97
+ label,
98
+ value,
99
+ precommitment: { nullifier, secret },
100
+ },
101
+ } = commitment;
88
102
  const commitmentProof: WithdrawalProof = await super.proveCommitment(value, label, nullifier, secret);
89
103
  const vkeyRaw = await this.circuits.getVerificationKey(CircuitName.Commitment);
90
104
  return {
91
105
  commitmentProof,
92
- calldata: await withdrawalProofToGaragaCalldata(commitmentProof, vkeyRaw)
106
+ calldata: await withdrawalProofToGaragaCalldata(commitmentProof, vkeyRaw),
93
107
  };
94
108
  }
95
109
 
96
110
  /**
97
111
  * Converts a withdrawal proof to Garaga-formatted calldata.
98
- *
112
+ *
99
113
  * This utility method takes an existing withdrawal proof and converts it to the calldata format
100
114
  * required by Garaga's Groth16 verifier on Starknet. Useful when you already have a withdrawal
101
115
  * proof and need to format it for Starknet contract calls without regenerating the proof.
102
- *
116
+ *
103
117
  * @param withdrawalProof - The withdrawal proof to convert
104
118
  * @returns Promise resolving to Garaga-formatted calldata as an array of bigints
105
119
  * @throws {Error} If verification key cannot be retrieved or conversion fails
@@ -111,11 +125,11 @@ export class PrivacyPoolStarknetSDK extends PrivacyPoolSDK {
111
125
 
112
126
  /**
113
127
  * Converts a commitment proof to Garaga-formatted calldata.
114
- *
128
+ *
115
129
  * This utility method takes an existing commitment proof and converts it to the calldata format
116
130
  * required by Garaga's Groth16 verifier on Starknet. Useful when you already have a commitment
117
131
  * proof and need to format it for Starknet contract calls without regenerating the proof.
118
- *
132
+ *
119
133
  * @param commitmentProof - The commitment proof to convert
120
134
  * @returns Promise resolving to Garaga-formatted calldata as an array of bigints
121
135
  * @throws {Error} If verification key cannot be retrieved or conversion fails
@@ -124,5 +138,4 @@ export class PrivacyPoolStarknetSDK extends PrivacyPoolSDK {
124
138
  const vkeyRaw = await this.circuits.getVerificationKey(CircuitName.Commitment);
125
139
  return await withdrawalProofToGaragaCalldata(commitmentProof, vkeyRaw);
126
140
  }
127
-
128
141
  }
@@ -4,7 +4,7 @@ import { SnarkJsGroth16Proof, SnarkJsVkey } from "./snarkjs.js";
4
4
 
5
5
  /**
6
6
  * Converts a G1 point from SnarkJS string array format to Garaga format.
7
- *
7
+ *
8
8
  * @param s - Array containing x and y coordinates as strings
9
9
  * @returns G1 point in Garaga format with BigInt coordinates
10
10
  * @throws {SNFormatError} If the input array doesn't contain exactly 2 coordinates
@@ -22,9 +22,9 @@ export function G1StoG1G(s: string[]): G1Point$1 {
22
22
 
23
23
  /**
24
24
  * Converts a G2 point from SnarkJS nested string array format to Garaga format.
25
- *
25
+ *
26
26
  * G2 points have coordinates in the extension field Fp2, represented as pairs of field elements.
27
- *
27
+ *
28
28
  * @param s - Nested array containing [[x0, x1], [y0, y1]] coordinates as strings
29
29
  * @returns G2 point in Garaga format with BigInt coordinate pairs
30
30
  * @throws {SNFormatError} If the input structure is invalid or coordinates are missing
@@ -40,7 +40,9 @@ export function G2StoG2G(s: string[][]): G2Point$1 {
40
40
  const [y0, y1] = y;
41
41
 
42
42
  if (x0 === undefined || x1 === undefined || y0 === undefined || y1 === undefined) {
43
- throw SNFormatError.conversion(`Invalid G2 point: incomplete coordinate pair. Input ((${x0}, ${x1}), (${y0}, ${y1}))`);
43
+ throw SNFormatError.conversion(
44
+ `Invalid G2 point: incomplete coordinate pair. Input ((${x0}, ${x1}), (${y0}, ${y1}))`
45
+ );
44
46
  }
45
47
 
46
48
  return {
@@ -52,10 +54,10 @@ export function G2StoG2G(s: string[][]): G2Point$1 {
52
54
 
53
55
  /**
54
56
  * Converts a SnarkJS verification key to Garaga format.
55
- *
57
+ *
56
58
  * This function transforms the verification key structure from SnarkJS format
57
59
  * (with string coordinates) to Garaga format (with BigInt coordinates and proper typing).
58
- *
60
+ *
59
61
  * @param vkey - SnarkJS verification key
60
62
  * @returns Verification key in Garaga format
61
63
  */
@@ -71,18 +73,15 @@ export function snarkJsKeyIntoGaraga(vkey: SnarkJsVkey): Groth16VerifyingKey {
71
73
 
72
74
  /**
73
75
  * Converts a SnarkJS Groth16 proof to Garaga format.
74
- *
76
+ *
75
77
  * This function transforms the proof structure from SnarkJS format
76
78
  * (with string coordinates) to Garaga format (with BigInt coordinates and proper typing).
77
- *
79
+ *
78
80
  * @param proof - SnarkJS Groth16 proof containing pi_a, pi_b, and pi_c points
79
81
  * @param publicInputs - Array of public inputs as strings
80
82
  * @returns Groth16 proof in Garaga format
81
83
  */
82
- export function snarkJsProofIntoGaraga(
83
- proof: SnarkJsGroth16Proof,
84
- publicInputs: string[]
85
- ): Groth16Proof {
84
+ export function snarkJsProofIntoGaraga(proof: SnarkJsGroth16Proof, publicInputs: string[]): Groth16Proof {
86
85
  return {
87
86
  a: G1StoG1G(proof.pi_a),
88
87
  b: G2StoG2G(proof.pi_b),
@@ -1,37 +1,38 @@
1
- import { BigNumberish, cairo, CallData, num } from "starknet";
1
+ import { BigNumberish, cairo, CallData, num, CairoOption, byteArray } from "starknet";
2
2
 
3
3
  import { EntryPointABI } from "../abis/index.js";
4
4
  import { SNFormatError } from "../errors/index.js";
5
5
  import { StarknetAddress } from "./starknet.js";
6
+ import { AuditorData } from "../auditor.js";
6
7
 
7
8
  const RelayDataAbi = [
8
9
  {
9
- "type": "interface",
10
+ type: "interface",
10
11
  },
11
12
  {
12
- "type": "struct",
13
- "name": "privacy_pools::interfaces::IEntryPoint::RelayData",
14
- "members": [
13
+ type: "struct",
14
+ name: "privacy_pools::interfaces::IEntryPoint::RelayData",
15
+ members: [
15
16
  {
16
- "name": "recipient",
17
- "type": "core::starknet::contract_address::ContractAddress"
17
+ name: "recipient",
18
+ type: "core::starknet::contract_address::ContractAddress",
18
19
  },
19
20
  {
20
- "name": "feeRecipient",
21
- "type": "core::starknet::contract_address::ContractAddress"
21
+ name: "feeRecipient",
22
+ type: "core::starknet::contract_address::ContractAddress",
22
23
  },
23
24
  {
24
- "name": "relayFeeBPS",
25
- "type": "core::integer::u256"
25
+ name: "relayFeeBPS",
26
+ type: "core::integer::u256",
26
27
  },
27
- ]
28
+ ],
28
29
  },
29
30
  ];
30
31
 
31
32
  export interface AssetConfig {
32
- pool: StarknetAddress,
33
- maxRelayFeeBPS: bigint,
34
- minimumDepositAmount: bigint,
33
+ pool: StarknetAddress;
34
+ maxRelayFeeBPS: bigint;
35
+ minimumDepositAmount: bigint;
35
36
  vettingFeeBPS: bigint;
36
37
  }
37
38
 
@@ -45,7 +46,8 @@ const entrypointCd = new CallData(EntryPointABI);
45
46
  */
46
47
  export interface Withdrawal {
47
48
  /** The address of the processor handling this withdrawal */
48
- processor: BigNumberish,
49
+ processor: BigNumberish;
50
+ auditorData?: AuditorData;
49
51
  /** Additional data required for processing the withdrawal */
50
52
  data: BigNumberish[];
51
53
  }
@@ -57,11 +59,11 @@ export interface Withdrawal {
57
59
  */
58
60
  export interface RelayData {
59
61
  /** The address that will receive the withdrawn funds */
60
- recipient: BigNumberish,
62
+ recipient: BigNumberish;
61
63
  /** The address that will receive relay fees */
62
- feeRecipient: BigNumberish,
64
+ feeRecipient: BigNumberish;
63
65
  /** The relay fee in basis points (BPS) */
64
- relayFeeBPS: BigNumberish,
66
+ relayFeeBPS: BigNumberish;
65
67
  }
66
68
 
67
69
  /**
@@ -77,15 +79,20 @@ export function serializeRelayData(data: RelayData): `0x${string}`[] {
77
79
  num.toHex64(recipient) as `0x${string}`,
78
80
  num.toHex64(feeRecipient) as `0x${string}`,
79
81
  num.toHex64(low) as `0x${string}`,
80
- num.toHex64(high) as `0x${string}`
82
+ num.toHex64(high) as `0x${string}`,
81
83
  ];
82
84
  }
83
85
 
84
86
  function isRelayData(data: unknown): data is RelayData {
85
87
  const _data = data as RelayData;
86
- return (_data.feeRecipient !== undefined && num.isBigNumberish(_data.feeRecipient))
87
- && (_data.recipient !== undefined && num.isBigNumberish(_data.recipient))
88
- && (_data.relayFeeBPS !== undefined && num.isBigNumberish(_data.relayFeeBPS));
88
+ return (
89
+ _data.feeRecipient !== undefined &&
90
+ num.isBigNumberish(_data.feeRecipient) &&
91
+ _data.recipient !== undefined &&
92
+ num.isBigNumberish(_data.recipient) &&
93
+ _data.relayFeeBPS !== undefined &&
94
+ num.isBigNumberish(_data.relayFeeBPS)
95
+ );
89
96
  }
90
97
 
91
98
  /**
@@ -97,13 +104,12 @@ function isRelayData(data: unknown): data is RelayData {
97
104
  */
98
105
  export function parseRelayData(rawData: string[]): RelayData {
99
106
  if (!rawData.every(num.isBigNumberish)) {
100
- throw SNFormatError.parse(`Can't parse RelayData from ${rawData}. Some values are not BigNumberish`);
107
+ throw SNFormatError.parse(`Can't parse RelayData from ${rawData.toString()}. Some values are not BigNumberish`);
101
108
  }
102
109
  const structName = "privacy_pools::interfaces::IEntryPoint::RelayData";
103
110
  const result = relayDataCd.decodeParameters(structName, rawData) as unknown;
104
- if (isRelayData(result))
105
- return result;
106
- throw SNFormatError.parse(`Can't parse RelayData from ${rawData}`);
111
+ if (isRelayData(result)) return result;
112
+ throw SNFormatError.parse(`Can't parse RelayData from ${rawData.toString()}`);
107
113
  }
108
114
 
109
115
  /**
@@ -113,18 +119,44 @@ export function parseRelayData(rawData: string[]): RelayData {
113
119
  * @returns Array of string representations of the withdrawal fields
114
120
  */
115
121
  export function serializeWithdrawal(withdrawal: Withdrawal): `0x${string}`[] {
116
- const { processor, data } = withdrawal;
117
- return [
118
- num.toHex64(processor) as `0x${string}`,
119
- num.toHex64(data.length) as `0x${string}`,
120
- ...data.map(x => num.toHex64(x) as `0x${string}`)
121
- ];
122
+ const result: `0x${string}`[] = [];
123
+ const { processor, auditorData, data } = withdrawal;
124
+
125
+ result.push(num.toHex64(processor) as `0x${string}`);
126
+
127
+ if (auditorData === undefined) {
128
+ result.push(num.toHex64(1) as `0x${string}`);
129
+ } else {
130
+ result.push(num.toHex64(0) as `0x${string}`);
131
+ const { tag, ciphertext } = auditorData;
132
+ const { low, high } = cairo.uint256(tag);
133
+ result.push(num.toHex64(low) as `0x${string}`);
134
+ result.push(num.toHex64(high) as `0x${string}`);
135
+
136
+ const array = CallData.compile([byteArray.byteArrayFromString(ciphertext)]);
137
+ array.forEach((x) => result.push(num.toHex64(x) as `0x${string}`));
138
+ }
139
+
140
+ result.push(num.toHex64(data.length) as `0x${string}`);
141
+ data.forEach((x) => result.push(num.toHex64(x) as `0x${string}`));
142
+ return result;
122
143
  }
123
144
 
124
- function isWithdrawal(data: unknown): data is Withdrawal {
125
- const _data = data as Withdrawal;
126
- return (_data.processor !== undefined && num.isBigNumberish(_data.processor))
127
- && (_data.data !== undefined && _data.data.every(num.isBigNumberish));
145
+ type CairoWithdrawal = {
146
+ processor: BigNumberish;
147
+ data: BigNumberish[];
148
+ auditorData: CairoOption<AuditorData>;
149
+ };
150
+ function isWithdrawal(data: unknown): data is CairoWithdrawal {
151
+ const _data = data as CairoWithdrawal;
152
+ return (
153
+ _data.processor !== undefined &&
154
+ num.isBigNumberish(_data.processor) &&
155
+ _data.data !== undefined &&
156
+ _data.data.every(num.isBigNumberish) &&
157
+ ((_data.auditorData.Some?.ciphertext !== undefined && _data.auditorData.Some?.tag !== undefined) ||
158
+ _data.auditorData.None !== undefined)
159
+ );
128
160
  }
129
161
 
130
162
  /**
@@ -136,11 +168,12 @@ function isWithdrawal(data: unknown): data is Withdrawal {
136
168
  */
137
169
  export function parseWithdrawal(rawData: string[]): Withdrawal {
138
170
  if (!rawData.every(num.isBigNumberish)) {
139
- throw SNFormatError.parse(`Can't parse Withdrawal from ${rawData}. Some values are not BigNumberish`);
171
+ throw SNFormatError.parse(`Can't parse Withdrawal from ${rawData.toString()}. Some values are not BigNumberish`);
140
172
  }
141
173
  const structName = "privacy_pools::interfaces::Structs::Withdrawal";
142
174
  const result = entrypointCd.decodeParameters(structName, rawData);
143
- if (isWithdrawal(result))
144
- return result;
145
- throw SNFormatError.parse(`Can't parse Withdrawal from ${rawData}`);
175
+ if (isWithdrawal(result)) {
176
+ return { ...result, auditorData: result.auditorData.unwrap() };
177
+ }
178
+ throw SNFormatError.parse(`Can't parse Withdrawal from ${rawData.toString()}`);
146
179
  }
@@ -6,12 +6,12 @@ type CurveId = 0;
6
6
  * Used in Garaga's Groth16 verification system.
7
7
  */
8
8
  export interface G1Point$1 {
9
- /** The x-coordinate of the point */
10
- x: bigint;
11
- /** The y-coordinate of the point */
12
- y: bigint;
13
- /** The curve identifier (always 0 for BN254) */
14
- curveId: CurveId;
9
+ /** The x-coordinate of the point */
10
+ x: bigint;
11
+ /** The y-coordinate of the point */
12
+ y: bigint;
13
+ /** The curve identifier (always 0 for BN254) */
14
+ curveId: CurveId;
15
15
  }
16
16
 
17
17
  /**
@@ -19,12 +19,12 @@ export interface G1Point$1 {
19
19
  * G2 points have coordinates in the extension field Fp2.
20
20
  */
21
21
  export interface G2Point$1 {
22
- /** The x-coordinate as a pair of field elements [x0, x1] */
23
- x: [bigint, bigint];
24
- /** The y-coordinate as a pair of field elements [y0, y1] */
25
- y: [bigint, bigint];
26
- /** The curve identifier (always 0 for BN254) */
27
- curveId: CurveId;
22
+ /** The x-coordinate as a pair of field elements [x0, x1] */
23
+ x: [bigint, bigint];
24
+ /** The y-coordinate as a pair of field elements [y0, y1] */
25
+ y: [bigint, bigint];
26
+ /** The curve identifier (always 0 for BN254) */
27
+ curveId: CurveId;
28
28
  }
29
29
 
30
30
  /**
@@ -32,16 +32,16 @@ export interface G2Point$1 {
32
32
  * Contains the proof points and public inputs.
33
33
  */
34
34
  export interface Groth16Proof {
35
- /** The A point of the Groth16 proof (G1 point) */
36
- a: G1Point$1;
37
- /** The B point of the Groth16 proof (G2 point) */
38
- b: G2Point$1;
39
- /** The C point of the Groth16 proof (G1 point) */
40
- c: G1Point$1;
41
- /** The public inputs to the circuit */
42
- publicInputs: bigint[];
43
- /** Optional curve identifier */
44
- curveId?: CurveId;
35
+ /** The A point of the Groth16 proof (G1 point) */
36
+ a: G1Point$1;
37
+ /** The B point of the Groth16 proof (G2 point) */
38
+ b: G2Point$1;
39
+ /** The C point of the Groth16 proof (G1 point) */
40
+ c: G1Point$1;
41
+ /** The public inputs to the circuit */
42
+ publicInputs: bigint[];
43
+ /** Optional curve identifier */
44
+ curveId?: CurveId;
45
45
  }
46
46
 
47
47
  /**
@@ -49,14 +49,14 @@ export interface Groth16Proof {
49
49
  * Contains the cryptographic parameters needed for proof verification.
50
50
  */
51
51
  export interface Groth16VerifyingKey {
52
- /** The alpha parameter (G1 point) */
53
- alpha: G1Point$1;
54
- /** The beta parameter (G2 point) */
55
- beta: G2Point$1;
56
- /** The gamma parameter (G2 point) */
57
- gamma: G2Point$1;
58
- /** The delta parameter (G2 point) */
59
- delta: G2Point$1;
60
- /** Array of IC parameters (G1 points) for public inputs */
61
- ic: G1Point$1[];
52
+ /** The alpha parameter (G1 point) */
53
+ alpha: G1Point$1;
54
+ /** The beta parameter (G2 point) */
55
+ beta: G2Point$1;
56
+ /** The gamma parameter (G2 point) */
57
+ gamma: G2Point$1;
58
+ /** The delta parameter (G2 point) */
59
+ delta: G2Point$1;
60
+ /** Array of IC parameters (G1 points) for public inputs */
61
+ ic: G1Point$1[];
62
62
  }
@@ -1,4 +1,4 @@
1
1
  export * from "./conversions.js";
2
2
  export * from "./entrypoint.js";
3
3
  export * from "./garaga.js";
4
- export * from "./snarkjs.js";
4
+ export * from "./snarkjs.js";
@@ -3,24 +3,12 @@ import { type Groth16Proof } from "snarkjs";
3
3
  export type SnarkJsGroth16Proof = Groth16Proof;
4
4
 
5
5
  export interface SnarkJsVkey {
6
- protocol: 'groth16',
7
- curve: 'bn128',
8
- nPublic: number,
9
- vk_alpha_1: [string, string, '1'],
10
- vk_beta_2: [
11
- [string, string],
12
- [string, string,],
13
- ['1', '0']
14
- ],
15
- vk_gamma_2: [
16
- [string, string],
17
- [string, string],
18
- ['1', '0']
19
- ],
20
- vk_delta_2: [
21
- [string, string],
22
- [string, string],
23
- ['1', '0']
24
- ],
25
- IC: [string, string, '1'][];
6
+ protocol: "groth16";
7
+ curve: "bn128";
8
+ nPublic: number;
9
+ vk_alpha_1: [string, string, "1"];
10
+ vk_beta_2: [[string, string], [string, string], ["1", "0"]];
11
+ vk_gamma_2: [[string, string], [string, string], ["1", "0"]];
12
+ vk_delta_2: [[string, string], [string, string], ["1", "0"]];
13
+ IC: [string, string, "1"][];
26
14
  }