@provex/utils 1.2.3 → 1.2.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.
Files changed (99) hide show
  1. package/package.json +51 -51
  2. package/dist/scripts/convert-svg.d.ts +0 -1
  3. package/dist/scripts/convert-svg.js +0 -17
  4. package/dist/src/endpoints.d.ts +0 -51
  5. package/dist/src/endpoints.js +0 -70
  6. package/dist/src/endpoints.test.d.ts +0 -1
  7. package/dist/src/endpoints.test.js +0 -54
  8. package/dist/src/normalization.d.ts +0 -224
  9. package/dist/src/normalization.js +0 -119
  10. package/dist/src/normalization.test.d.ts +0 -1
  11. package/dist/src/normalization.test.js +0 -284
  12. package/dist/src/zkp2p-types.d.ts +0 -317
  13. package/dist/src/zkp2p-types.js +0 -169
  14. package/dist/tsconfig.tsbuildinfo +0 -1
  15. /package/dist/{src/chain.d.ts → chain.d.ts} +0 -0
  16. /package/dist/{src/chain.js → chain.js} +0 -0
  17. /package/dist/{src/chain.test.d.ts → chain.test.d.ts} +0 -0
  18. /package/dist/{src/chain.test.js → chain.test.js} +0 -0
  19. /package/dist/{src/contracts.d.ts → contracts.d.ts} +0 -0
  20. /package/dist/{src/contracts.js → contracts.js} +0 -0
  21. /package/dist/{src/contracts.test.d.ts → contracts.test.d.ts} +0 -0
  22. /package/dist/{src/contracts.test.js → contracts.test.js} +0 -0
  23. /package/dist/{src/conversionRates.d.ts → conversionRates.d.ts} +0 -0
  24. /package/dist/{src/conversionRates.js → conversionRates.js} +0 -0
  25. /package/dist/{src/conversionRates.test.d.ts → conversionRates.test.d.ts} +0 -0
  26. /package/dist/{src/conversionRates.test.js → conversionRates.test.js} +0 -0
  27. /package/dist/{src/currencies.d.ts → currencies.d.ts} +0 -0
  28. /package/dist/{src/currencies.js → currencies.js} +0 -0
  29. /package/dist/{src/currencies.test.d.ts → currencies.test.d.ts} +0 -0
  30. /package/dist/{src/currencies.test.js → currencies.test.js} +0 -0
  31. /package/dist/{src/data → data}/countries.json +0 -0
  32. /package/dist/{src/deposit.d.ts → deposit.d.ts} +0 -0
  33. /package/dist/{src/deposit.js → deposit.js} +0 -0
  34. /package/dist/{src/depositKeys.d.ts → depositKeys.d.ts} +0 -0
  35. /package/dist/{src/depositKeys.js → depositKeys.js} +0 -0
  36. /package/dist/{src/depositKeys.test.d.ts → depositKeys.test.d.ts} +0 -0
  37. /package/dist/{src/depositKeys.test.js → depositKeys.test.js} +0 -0
  38. /package/dist/{src/events.d.ts → events.d.ts} +0 -0
  39. /package/dist/{src/events.js → events.js} +0 -0
  40. /package/dist/{src/events.test.d.ts → events.test.d.ts} +0 -0
  41. /package/dist/{src/events.test.js → events.test.js} +0 -0
  42. /package/dist/{src/fees.d.ts → fees.d.ts} +0 -0
  43. /package/dist/{src/fees.js → fees.js} +0 -0
  44. /package/dist/{src/fees.test.d.ts → fees.test.d.ts} +0 -0
  45. /package/dist/{src/fees.test.js → fees.test.js} +0 -0
  46. /package/dist/{src/flags.d.ts → flags.d.ts} +0 -0
  47. /package/dist/{src/flags.js → flags.js} +0 -0
  48. /package/dist/{src/ids.d.ts → ids.d.ts} +0 -0
  49. /package/dist/{src/ids.js → ids.js} +0 -0
  50. /package/dist/{src/ids.test.d.ts → ids.test.d.ts} +0 -0
  51. /package/dist/{src/ids.test.js → ids.test.js} +0 -0
  52. /package/dist/{src/index.d.ts → index.d.ts} +0 -0
  53. /package/dist/{src/index.js → index.js} +0 -0
  54. /package/dist/{src/input.d.ts → input.d.ts} +0 -0
  55. /package/dist/{src/input.js → input.js} +0 -0
  56. /package/dist/{src/intent.d.ts → intent.d.ts} +0 -0
  57. /package/dist/{src/intent.js → intent.js} +0 -0
  58. /package/dist/{src/intent.test.d.ts → intent.test.d.ts} +0 -0
  59. /package/dist/{src/intent.test.js → intent.test.js} +0 -0
  60. /package/dist/{src/json.d.ts → json.d.ts} +0 -0
  61. /package/dist/{src/json.js → json.js} +0 -0
  62. /package/dist/{src/participants.d.ts → participants.d.ts} +0 -0
  63. /package/dist/{src/participants.js → participants.js} +0 -0
  64. /package/dist/{src/payment.d.ts → payment.d.ts} +0 -0
  65. /package/dist/{src/payment.js → payment.js} +0 -0
  66. /package/dist/{src/payment.test.d.ts → payment.test.d.ts} +0 -0
  67. /package/dist/{src/payment.test.js → payment.test.js} +0 -0
  68. /package/dist/{src/peer-types.d.ts → peer-types.d.ts} +0 -0
  69. /package/dist/{src/peer-types.js → peer-types.js} +0 -0
  70. /package/dist/{src/profit.d.ts → profit.d.ts} +0 -0
  71. /package/dist/{src/profit.js → profit.js} +0 -0
  72. /package/dist/{src/profit.test.d.ts → profit.test.d.ts} +0 -0
  73. /package/dist/{src/profit.test.js → profit.test.js} +0 -0
  74. /package/dist/{src/reputation.d.ts → reputation.d.ts} +0 -0
  75. /package/dist/{src/reputation.js → reputation.js} +0 -0
  76. /package/dist/{src/reputation.test.d.ts → reputation.test.d.ts} +0 -0
  77. /package/dist/{src/reputation.test.js → reputation.test.js} +0 -0
  78. /package/dist/{src/sort.d.ts → sort.d.ts} +0 -0
  79. /package/dist/{src/sort.js → sort.js} +0 -0
  80. /package/dist/{src/sort.test.d.ts → sort.test.d.ts} +0 -0
  81. /package/dist/{src/sort.test.js → sort.test.js} +0 -0
  82. /package/dist/{src/stateKey.d.ts → stateKey.d.ts} +0 -0
  83. /package/dist/{src/stateKey.js → stateKey.js} +0 -0
  84. /package/dist/{src/stats.d.ts → stats.d.ts} +0 -0
  85. /package/dist/{src/stats.js → stats.js} +0 -0
  86. /package/dist/{src/stats.test.d.ts → stats.test.d.ts} +0 -0
  87. /package/dist/{src/stats.test.js → stats.test.js} +0 -0
  88. /package/dist/{src/time.d.ts → time.d.ts} +0 -0
  89. /package/dist/{src/time.js → time.js} +0 -0
  90. /package/dist/{src/time.test.d.ts → time.test.d.ts} +0 -0
  91. /package/dist/{src/time.test.js → time.test.js} +0 -0
  92. /package/dist/{src/tokens.d.ts → tokens.d.ts} +0 -0
  93. /package/dist/{src/tokens.js → tokens.js} +0 -0
  94. /package/dist/{src/tokens.test.d.ts → tokens.test.d.ts} +0 -0
  95. /package/dist/{src/tokens.test.js → tokens.test.js} +0 -0
  96. /package/dist/{src/units.d.ts → units.d.ts} +0 -0
  97. /package/dist/{src/units.js → units.js} +0 -0
  98. /package/dist/{src/units.test.d.ts → units.test.d.ts} +0 -0
  99. /package/dist/{src/units.test.js → units.test.js} +0 -0
@@ -1,317 +0,0 @@
1
- /**
2
- * @fileoverview ZKP2P protocol types for attestation and proof verification.
3
- *
4
- * This module defines the type system for the V3 attestation flow, including:
5
- * - Notarized proofs from the PeerAuth browser extension
6
- * - Attestation requests/responses from the zkp2p service
7
- * - EIP-712 typed data structures for on-chain verification
8
- * - Payment proof encoding for the UnifiedPaymentVerifier contract
9
- *
10
- * @remarks
11
- * **V3 Attestation Flow:**
12
- * 1. Buyer generates zkTLS proof via PeerAuth extension (NotarizedProofData)
13
- * 2. Proof + intent data sent to attestation service (V3AttestationRequest)
14
- * 3. Service validates and returns EIP-712 signed attestation (V3AttestationResponse)
15
- * 4. Attestation encoded as paymentProof bytes (encodeV3PaymentProof)
16
- * 5. Buyer calls fulfillIntent() with encoded proof
17
- *
18
- * **Type Aliases:**
19
- * For cleaner imports, V3-prefixed types have unprefixed aliases:
20
- * - AttestationOptions = V3AttestationOptions
21
- * - AttestationResponse = V3AttestationResponse
22
- * - IntentData = V3IntentData
23
- *
24
- * @see {@link intent} for intent data structures
25
- * @see {@link payment} for provider definitions
26
- */
27
- import { type Hex } from "viem";
28
- import type { ProviderKey, SubProviderKey, ValidationDepositData } from "./payment.js";
29
- /**
30
- * Options for validating a depositor's payee details with the zkp2p gating service.
31
- */
32
- export type ValidationOptions = {
33
- providerKey: ProviderKey;
34
- telegramHandle: string;
35
- providerId: string;
36
- };
37
- export type Zkp2pResponse<T> = {
38
- success: boolean;
39
- message: string;
40
- statusCode: number;
41
- responseObject: T;
42
- };
43
- export type CreateResponse = {
44
- id: number;
45
- processorName: string;
46
- depositData: string;
47
- hashedOnchainId: Hex;
48
- createdAt: string;
49
- };
50
- export type PayeeDetails = {
51
- id: number;
52
- processorName: string;
53
- createdAt: string;
54
- hashedOnchainId: Hex;
55
- depositData: ValidationDepositData;
56
- };
57
- export type IntentValidationOptions = {
58
- processorName: ProviderKey;
59
- depositId: string;
60
- /** Token amount (was tokenAmount, renamed to amount for v2 API) */
61
- amount: string;
62
- payeeDetails: Hex;
63
- toAddress: Hex;
64
- /** Payment method bytes32 hash */
65
- paymentMethod: Hex;
66
- /** Fiat currency bytes32 hash */
67
- fiatCurrency: Hex;
68
- /** Conversion rate as string */
69
- conversionRate: string;
70
- chainId: string;
71
- /** Orchestrator contract address */
72
- orchestratorAddress: Hex;
73
- /** Escrow contract address */
74
- escrowAddress: Hex;
75
- /** Optional sub-provider for providers like Zelle that have multiple banks (e.g., 'zelle-chase', 'zelle-bofa') */
76
- subProvider?: SubProviderKey;
77
- };
78
- export type IntentValidation = {
79
- signedIntent: Hex;
80
- intentData: {
81
- depositId: string;
82
- tokenAmount: string;
83
- recipientAddress: Hex;
84
- verifierAddress: Hex;
85
- currencyCodeHash: Hex;
86
- gatingServiceSignature: Hex;
87
- };
88
- depositData: ValidationDepositData;
89
- };
90
- /**
91
- * Notarized proof from PeerAuth extension.
92
- * This is the zkTLS proof that proves a payment transaction occurred.
93
- * Mirrors the NotarizedProof type from @provex/extension-react.
94
- */
95
- export type NotarizedProofData = {
96
- claim: {
97
- context: string;
98
- epoch: number;
99
- identifier: Hex;
100
- owner: Hex;
101
- parameters: string;
102
- provider: string;
103
- timestampS: number;
104
- };
105
- signatures: {
106
- attestorAddress: Hex;
107
- claimSignature: Record<number, number>;
108
- resultSignature: Record<number, number>;
109
- };
110
- };
111
- /**
112
- * Intent data required by zkp2p attestation service.
113
- * This contains all the on-chain intent parameters needed to verify
114
- * that the off-chain payment matches the signaled intent.
115
- */
116
- export type V3IntentData = {
117
- /** The intent hash from signalIntent */
118
- intentHash: Hex;
119
- /** Token amount in smallest unit (e.g., USDC with 6 decimals) */
120
- amount: string;
121
- /** Intent timestamp in milliseconds */
122
- timestampMs: string;
123
- /** Payment method bytes32 hash */
124
- paymentMethod: Hex;
125
- /** Fiat currency bytes32 hash */
126
- fiatCurrency: Hex;
127
- /** Conversion rate as string (scaled by 1e18) */
128
- conversionRate: string;
129
- /** Payee details hash */
130
- payeeDetails: Hex;
131
- /** Optional timestamp buffer in milliseconds (default: 3000) */
132
- timestampBufferMs?: string;
133
- };
134
- /**
135
- * V3 attestation request sent to zkp2p attestation service.
136
- * The service validates Reclaim proofs and returns an EIP-712 signed attestation.
137
- *
138
- * Endpoint: POST /verify/{platform}/{action_type}
139
- * Example: POST /verify/chase/transfer_zelle
140
- */
141
- export type V3AttestationRequest = {
142
- /** Type of proof being submitted */
143
- proofType: 'reclaim';
144
- /** JSON stringified array of Reclaim proofs */
145
- proof: string;
146
- /** Chain ID (e.g., 8453 for Base) */
147
- chainId: number;
148
- /** UnifiedPaymentVerifier contract address */
149
- verifyingContract: Hex;
150
- /** Intent data from on-chain signalIntent */
151
- intent: V3IntentData;
152
- };
153
- /**
154
- * Options passed to the v3 getAttestation API.
155
- * These are transformed into V3AttestationRequest format.
156
- */
157
- export type V3AttestationOptions = {
158
- /** Platform for the attestation service path (e.g., 'chase') */
159
- platform: string;
160
- /** Action type for the attestation service path (e.g., 'transfer_zelle') */
161
- actionType: string;
162
- /** Chain ID */
163
- chainId: number;
164
- /** UnifiedPaymentVerifier contract address */
165
- verifyingContract: Hex;
166
- /** Array of Reclaim proofs from PeerAuth */
167
- proofs: NotarizedProofData[];
168
- /** Intent data from on-chain intent */
169
- intent: V3IntentData;
170
- };
171
- /**
172
- * EIP-712 typed data specification from attestation service.
173
- */
174
- export type V3TypedDataSpec = {
175
- primaryType: string;
176
- types: Record<string, Array<{
177
- name: string;
178
- type: string;
179
- }>>;
180
- };
181
- /**
182
- * EIP-712 typed data values from attestation service.
183
- * These are the actual values that were signed.
184
- */
185
- export type V3TypedDataValue = {
186
- intentHash: Hex;
187
- releaseAmount: string;
188
- dataHash: Hex;
189
- };
190
- /**
191
- * Response object from zkp2p attestation service.
192
- * Contains the EIP-712 signed attestation for on-chain verification.
193
- */
194
- export type V3AttestationResponseObject = {
195
- /** EIP-712 signature to submit to fulfillIntent as paymentProof */
196
- signature: Hex;
197
- /** Address of the attestation signer */
198
- signer: Hex;
199
- /** EIP-712 domain separator */
200
- domainSeparator: Hex;
201
- /** EIP-712 type hash */
202
- typeHash: Hex;
203
- /** EIP-712 type specification */
204
- typedDataSpec: V3TypedDataSpec;
205
- /** The actual values that were signed */
206
- typedDataValue: V3TypedDataValue;
207
- /** ABI-encoded payment details for on-chain verification */
208
- encodedPaymentDetails: Hex;
209
- /** Additional metadata */
210
- metadata: Hex;
211
- /** Original proof input (for debugging) */
212
- proofInput: string;
213
- /** Platform used (e.g., 'chase') */
214
- platform: string;
215
- /** Action type (e.g., 'transfer_zelle') */
216
- actionType: string;
217
- };
218
- /**
219
- * Full response from zkp2p attestation service.
220
- * Wrapped in standard Zkp2pResponse format.
221
- */
222
- export type V3AttestationResponse = Zkp2pResponse<V3AttestationResponseObject>;
223
- /**
224
- * @deprecated Use V3AttestationResponseObject for the inner response data
225
- */
226
- export type V3PaymentAttestation = {
227
- depositor: Hex;
228
- depositId: string;
229
- amount: string;
230
- paymentId: string;
231
- timestamp: number;
232
- };
233
- export type V3IntentSignalOptions = {
234
- depositId: string;
235
- amount: string;
236
- attestation: V3AttestationResponse;
237
- chainId: number;
238
- };
239
- export type V3IntentFulfillOptions = {
240
- intentId: string;
241
- chainId: number;
242
- };
243
- /**
244
- * EIP-712 domain separator fields.
245
- * Used for typed structured data hashing and signing per EIP-712.
246
- * @see https://eips.ethereum.org/EIPS/eip-712
247
- */
248
- export type EIP712Domain = {
249
- /** Human-readable name of the signing domain (e.g., "ZKP2P") */
250
- name: string;
251
- /** Version of the signing domain (e.g., "1") */
252
- version: string;
253
- /** Chain ID of the network where the contract is deployed */
254
- chainId: number;
255
- /** Address of the contract that will verify the signature */
256
- verifyingContract: Hex;
257
- };
258
- /**
259
- * A payment attestation with its EIP-712 signature.
260
- * This is the complete attestation package sent to the contract for verification.
261
- */
262
- export type SignedAttestation = {
263
- /** The payment attestation data */
264
- attestation: V3PaymentAttestation;
265
- /** EIP-712 typed signature of the attestation */
266
- signature: Hex;
267
- };
268
- /**
269
- * Encodes a V3 attestation response into the paymentProof bytes format
270
- * expected by the UnifiedPaymentVerifier contract's fulfillIntent function.
271
- *
272
- * The encoded struct contains (wrapped in outer tuple for offset prefix):
273
- * - PaymentAttestation: { intentHash, releaseAmount, dataHash }
274
- * - signatures: [signature] (array with the EIP-712 signature)
275
- * - encodedPaymentDetails: payment details for on-chain verification
276
- * - metadata: additional metadata bytes
277
- * - attestorAddresses: [signer] (array with the attestor address)
278
- *
279
- * @param attestation - The V3AttestationResponseObject from the attestation service
280
- * @returns ABI-encoded bytes to pass as paymentProof in fulfillIntent
281
- */
282
- export declare function encodeV3PaymentProof(attestation: V3AttestationResponseObject): Hex;
283
- /**
284
- * Extracts the Reclaim attestor address from the attestation proofInput.
285
- * This is needed for the verificationData field in fulfillIntent.
286
- *
287
- * @param attestation - The V3AttestationResponseObject from the attestation service
288
- * @returns The Reclaim attestor address as Hex, or null if not found
289
- */
290
- export declare function extractReclaimAttestorAddress(attestation: V3AttestationResponseObject): Hex | null;
291
- /**
292
- * Extracts the nullifier from a V3 attestation response.
293
- *
294
- * The nullifier is NOT directly stored in `encodedPaymentDetails`. Instead, it's derived
295
- * from `paymentMethod` and `paymentId` using:
296
- * `keccak256(abi.encodePacked(paymentMethod, paymentId))`
297
- *
298
- * The `encodedPaymentDetails` contains a tuple of `(PaymentDetails, IntentSnapshot)`.
299
- * This function decodes the PaymentDetails struct to extract paymentMethod and paymentId,
300
- * then derives the nullifier.
301
- *
302
- * @param attestation - The V3AttestationResponseObject from the attestation service
303
- * @returns The derived nullifier as Hex, or null if extraction fails
304
- */
305
- export declare function extractNullifier(attestation: V3AttestationResponseObject): Hex | null;
306
- /** @alias V3AttestationOptions */
307
- export type AttestationOptions = V3AttestationOptions;
308
- /** @alias V3AttestationRequest */
309
- export type AttestationRequest = V3AttestationRequest;
310
- /** @alias V3AttestationResponse */
311
- export type AttestationResponse = V3AttestationResponse;
312
- /** @alias V3AttestationResponseObject */
313
- export type AttestationResponseObject = V3AttestationResponseObject;
314
- /** @alias V3PaymentAttestation - @deprecated use V3AttestationResponseObject */
315
- export type PaymentAttestation = V3PaymentAttestation;
316
- /** @alias V3IntentData */
317
- export type IntentData = V3IntentData;
@@ -1,169 +0,0 @@
1
- /**
2
- * @fileoverview ZKP2P protocol types for attestation and proof verification.
3
- *
4
- * This module defines the type system for the V3 attestation flow, including:
5
- * - Notarized proofs from the PeerAuth browser extension
6
- * - Attestation requests/responses from the zkp2p service
7
- * - EIP-712 typed data structures for on-chain verification
8
- * - Payment proof encoding for the UnifiedPaymentVerifier contract
9
- *
10
- * @remarks
11
- * **V3 Attestation Flow:**
12
- * 1. Buyer generates zkTLS proof via PeerAuth extension (NotarizedProofData)
13
- * 2. Proof + intent data sent to attestation service (V3AttestationRequest)
14
- * 3. Service validates and returns EIP-712 signed attestation (V3AttestationResponse)
15
- * 4. Attestation encoded as paymentProof bytes (encodeV3PaymentProof)
16
- * 5. Buyer calls fulfillIntent() with encoded proof
17
- *
18
- * **Type Aliases:**
19
- * For cleaner imports, V3-prefixed types have unprefixed aliases:
20
- * - AttestationOptions = V3AttestationOptions
21
- * - AttestationResponse = V3AttestationResponse
22
- * - IntentData = V3IntentData
23
- *
24
- * @see {@link intent} for intent data structures
25
- * @see {@link payment} for provider definitions
26
- */
27
- import { encodeAbiParameters, decodeAbiParameters, keccak256, encodePacked } from "viem";
28
- // ============================================================================
29
- // V3 Payment Proof Encoding
30
- // ============================================================================
31
- /**
32
- * ABI parameter definition for the V3 payment proof struct.
33
- *
34
- * IMPORTANT: The struct must be wrapped in an outer tuple to match zkp2p's encoding.
35
- * This causes ABI encoding to add an offset prefix (0x20) at the start.
36
- *
37
- * Structure:
38
- * - Outer tuple wrapper (adds 0x20 offset prefix)
39
- * - PaymentAttestation tuple (intentHash, releaseAmount, dataHash)
40
- * - signatures[] array of EIP-712 signatures
41
- * - encodedPaymentDetails bytes
42
- * - metadata bytes
43
- * - attestorAddresses[] array of signer addresses
44
- */
45
- const V3_PAYMENT_PROOF_ABI = [
46
- {
47
- type: 'tuple',
48
- components: [
49
- {
50
- type: 'tuple',
51
- name: 'attestation',
52
- components: [
53
- { name: 'intentHash', type: 'bytes32' },
54
- { name: 'releaseAmount', type: 'uint256' },
55
- { name: 'dataHash', type: 'bytes32' }
56
- ]
57
- },
58
- { type: 'bytes[]', name: 'signatures' },
59
- { type: 'bytes', name: 'encodedPaymentDetails' },
60
- { type: 'bytes', name: 'metadata' },
61
- { type: 'address[]', name: 'attestorAddresses' }
62
- ]
63
- }
64
- ];
65
- /**
66
- * Encodes a V3 attestation response into the paymentProof bytes format
67
- * expected by the UnifiedPaymentVerifier contract's fulfillIntent function.
68
- *
69
- * The encoded struct contains (wrapped in outer tuple for offset prefix):
70
- * - PaymentAttestation: { intentHash, releaseAmount, dataHash }
71
- * - signatures: [signature] (array with the EIP-712 signature)
72
- * - encodedPaymentDetails: payment details for on-chain verification
73
- * - metadata: additional metadata bytes
74
- * - attestorAddresses: [signer] (array with the attestor address)
75
- *
76
- * @param attestation - The V3AttestationResponseObject from the attestation service
77
- * @returns ABI-encoded bytes to pass as paymentProof in fulfillIntent
78
- */
79
- export function encodeV3PaymentProof(attestation) {
80
- return encodeAbiParameters(V3_PAYMENT_PROOF_ABI, [
81
- {
82
- attestation: {
83
- intentHash: attestation.typedDataValue.intentHash,
84
- releaseAmount: BigInt(attestation.typedDataValue.releaseAmount),
85
- dataHash: attestation.typedDataValue.dataHash
86
- },
87
- signatures: [attestation.signature],
88
- encodedPaymentDetails: attestation.encodedPaymentDetails,
89
- metadata: attestation.metadata,
90
- attestorAddresses: [attestation.signer]
91
- }
92
- ]);
93
- }
94
- /**
95
- * Extracts the Reclaim attestor address from the attestation proofInput.
96
- * This is needed for the verificationData field in fulfillIntent.
97
- *
98
- * @param attestation - The V3AttestationResponseObject from the attestation service
99
- * @returns The Reclaim attestor address as Hex, or null if not found
100
- */
101
- export function extractReclaimAttestorAddress(attestation) {
102
- try {
103
- const proofInput = JSON.parse(attestation.proofInput);
104
- const proofs = JSON.parse(proofInput.proof);
105
- if (Array.isArray(proofs) && proofs.length > 0) {
106
- const attestorAddress = proofs[0]?.signatures?.attestorAddress;
107
- if (attestorAddress && typeof attestorAddress === 'string') {
108
- return attestorAddress;
109
- }
110
- }
111
- return null;
112
- }
113
- catch {
114
- return null;
115
- }
116
- }
117
- /**
118
- * Extracts the nullifier from a V3 attestation response.
119
- *
120
- * The nullifier is NOT directly stored in `encodedPaymentDetails`. Instead, it's derived
121
- * from `paymentMethod` and `paymentId` using:
122
- * `keccak256(abi.encodePacked(paymentMethod, paymentId))`
123
- *
124
- * The `encodedPaymentDetails` contains a tuple of `(PaymentDetails, IntentSnapshot)`.
125
- * This function decodes the PaymentDetails struct to extract paymentMethod and paymentId,
126
- * then derives the nullifier.
127
- *
128
- * @param attestation - The V3AttestationResponseObject from the attestation service
129
- * @returns The derived nullifier as Hex, or null if extraction fails
130
- */
131
- export function extractNullifier(attestation) {
132
- try {
133
- // Decode encodedPaymentDetails as (PaymentDetails, IntentSnapshot) tuple
134
- // PaymentDetails struct: { paymentMethod, payeeId, amount, currency, timestamp, paymentId }
135
- // IntentSnapshot struct: { paymentMethod, currency, payeeId, conversionRate, timestamp, unknown }
136
- const decoded = decodeAbiParameters([
137
- {
138
- type: 'tuple',
139
- components: [
140
- { type: 'bytes32', name: 'paymentMethod' },
141
- { type: 'bytes32', name: 'payeeId' },
142
- { type: 'uint256', name: 'amount' },
143
- { type: 'bytes32', name: 'currency' },
144
- { type: 'uint256', name: 'timestamp' },
145
- { type: 'bytes32', name: 'paymentId' },
146
- ],
147
- },
148
- {
149
- type: 'tuple',
150
- components: [
151
- { type: 'bytes32', name: 'paymentMethod' },
152
- { type: 'bytes32', name: 'currency' },
153
- { type: 'bytes32', name: 'payeeId' },
154
- { type: 'uint256', name: 'conversionRate' },
155
- { type: 'uint256', name: 'timestamp' },
156
- { type: 'uint256', name: 'unknown' },
157
- ],
158
- },
159
- ], attestation.encodedPaymentDetails);
160
- const paymentDetails = decoded[0];
161
- // Derive nullifier: keccak256(abi.encodePacked(paymentMethod, paymentId))
162
- const nullifier = keccak256(encodePacked(['bytes32', 'bytes32'], [paymentDetails.paymentMethod, paymentDetails.paymentId]));
163
- return nullifier;
164
- }
165
- catch (error) {
166
- console.error('Failed to extract nullifier:', error);
167
- return null;
168
- }
169
- }