x402z-shared-web 0.0.18 → 0.0.19

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/index.mjs CHANGED
@@ -1,187 +1,1420 @@
1
1
  // src/core/abi.ts
2
2
  var confidentialTokenAbi = [
3
3
  {
4
- inputs: [
5
- { internalType: "address", name: "to", type: "address" },
6
- { internalType: "bytes32", name: "encryptedAmountInput", type: "bytes32" },
7
- { internalType: "bytes", name: "inputProof", type: "bytes" }
4
+ "inputs": [
5
+ {
6
+ "internalType": "string",
7
+ "name": "name_",
8
+ "type": "string"
9
+ },
10
+ {
11
+ "internalType": "string",
12
+ "name": "symbol_",
13
+ "type": "string"
14
+ },
15
+ {
16
+ "internalType": "string",
17
+ "name": "contractURI_",
18
+ "type": "string"
19
+ },
20
+ {
21
+ "internalType": "contract IERC20",
22
+ "name": "underlying_",
23
+ "type": "address"
24
+ }
25
+ ],
26
+ "stateMutability": "nonpayable",
27
+ "type": "constructor"
28
+ },
29
+ {
30
+ "inputs": [],
31
+ "name": "AuthorizationExpired",
32
+ "type": "error"
33
+ },
34
+ {
35
+ "inputs": [],
36
+ "name": "ECDSAInvalidSignature",
37
+ "type": "error"
38
+ },
39
+ {
40
+ "inputs": [
41
+ {
42
+ "internalType": "uint256",
43
+ "name": "length",
44
+ "type": "uint256"
45
+ }
46
+ ],
47
+ "name": "ECDSAInvalidSignatureLength",
48
+ "type": "error"
49
+ },
50
+ {
51
+ "inputs": [
52
+ {
53
+ "internalType": "bytes32",
54
+ "name": "s",
55
+ "type": "bytes32"
56
+ }
57
+ ],
58
+ "name": "ECDSAInvalidSignatureS",
59
+ "type": "error"
60
+ },
61
+ {
62
+ "inputs": [
63
+ {
64
+ "internalType": "uint256",
65
+ "name": "requestId",
66
+ "type": "uint256"
67
+ }
68
+ ],
69
+ "name": "ERC7984InvalidGatewayRequest",
70
+ "type": "error"
71
+ },
72
+ {
73
+ "inputs": [
74
+ {
75
+ "internalType": "address",
76
+ "name": "receiver",
77
+ "type": "address"
78
+ }
79
+ ],
80
+ "name": "ERC7984InvalidReceiver",
81
+ "type": "error"
82
+ },
83
+ {
84
+ "inputs": [
85
+ {
86
+ "internalType": "address",
87
+ "name": "sender",
88
+ "type": "address"
89
+ }
90
+ ],
91
+ "name": "ERC7984InvalidSender",
92
+ "type": "error"
93
+ },
94
+ {
95
+ "inputs": [],
96
+ "name": "ERC7984TotalSupplyOverflow",
97
+ "type": "error"
98
+ },
99
+ {
100
+ "inputs": [
101
+ {
102
+ "internalType": "address",
103
+ "name": "caller",
104
+ "type": "address"
105
+ }
106
+ ],
107
+ "name": "ERC7984UnauthorizedCaller",
108
+ "type": "error"
109
+ },
110
+ {
111
+ "inputs": [
112
+ {
113
+ "internalType": "address",
114
+ "name": "holder",
115
+ "type": "address"
116
+ },
117
+ {
118
+ "internalType": "address",
119
+ "name": "spender",
120
+ "type": "address"
121
+ }
122
+ ],
123
+ "name": "ERC7984UnauthorizedSpender",
124
+ "type": "error"
125
+ },
126
+ {
127
+ "inputs": [
128
+ {
129
+ "internalType": "euint64",
130
+ "name": "amount",
131
+ "type": "bytes32"
132
+ },
133
+ {
134
+ "internalType": "address",
135
+ "name": "user",
136
+ "type": "address"
137
+ }
138
+ ],
139
+ "name": "ERC7984UnauthorizedUseOfEncryptedAmount",
140
+ "type": "error"
141
+ },
142
+ {
143
+ "inputs": [
144
+ {
145
+ "internalType": "address",
146
+ "name": "holder",
147
+ "type": "address"
148
+ }
149
+ ],
150
+ "name": "ERC7984ZeroBalance",
151
+ "type": "error"
152
+ },
153
+ {
154
+ "inputs": [],
155
+ "name": "EncryptedAmountMismatch",
156
+ "type": "error"
157
+ },
158
+ {
159
+ "inputs": [],
160
+ "name": "InvalidHolder",
161
+ "type": "error"
162
+ },
163
+ {
164
+ "inputs": [],
165
+ "name": "InvalidKMSSignatures",
166
+ "type": "error"
167
+ },
168
+ {
169
+ "inputs": [],
170
+ "name": "InvalidPayee",
171
+ "type": "error"
172
+ },
173
+ {
174
+ "inputs": [],
175
+ "name": "InvalidRecipient",
176
+ "type": "error"
177
+ },
178
+ {
179
+ "inputs": [],
180
+ "name": "InvalidShortString",
181
+ "type": "error"
182
+ },
183
+ {
184
+ "inputs": [],
185
+ "name": "InvalidSignature",
186
+ "type": "error"
187
+ },
188
+ {
189
+ "inputs": [
190
+ {
191
+ "internalType": "euint64",
192
+ "name": "amount",
193
+ "type": "bytes32"
194
+ }
195
+ ],
196
+ "name": "InvalidUnwrapRequest",
197
+ "type": "error"
198
+ },
199
+ {
200
+ "inputs": [],
201
+ "name": "NonceAlreadyUsed",
202
+ "type": "error"
203
+ },
204
+ {
205
+ "inputs": [],
206
+ "name": "NotYetValid",
207
+ "type": "error"
208
+ },
209
+ {
210
+ "inputs": [
211
+ {
212
+ "internalType": "uint8",
213
+ "name": "bits",
214
+ "type": "uint8"
215
+ },
216
+ {
217
+ "internalType": "uint256",
218
+ "name": "value",
219
+ "type": "uint256"
220
+ }
221
+ ],
222
+ "name": "SafeCastOverflowedUintDowncast",
223
+ "type": "error"
224
+ },
225
+ {
226
+ "inputs": [
227
+ {
228
+ "internalType": "address",
229
+ "name": "token",
230
+ "type": "address"
231
+ }
232
+ ],
233
+ "name": "SafeERC20FailedOperation",
234
+ "type": "error"
235
+ },
236
+ {
237
+ "inputs": [
238
+ {
239
+ "internalType": "bytes32",
240
+ "name": "handle",
241
+ "type": "bytes32"
242
+ },
243
+ {
244
+ "internalType": "address",
245
+ "name": "sender",
246
+ "type": "address"
247
+ }
248
+ ],
249
+ "name": "SenderNotAllowedToUseHandle",
250
+ "type": "error"
251
+ },
252
+ {
253
+ "inputs": [
254
+ {
255
+ "internalType": "string",
256
+ "name": "str",
257
+ "type": "string"
258
+ }
259
+ ],
260
+ "name": "StringTooLong",
261
+ "type": "error"
262
+ },
263
+ {
264
+ "inputs": [],
265
+ "name": "Unauthorized",
266
+ "type": "error"
267
+ },
268
+ {
269
+ "inputs": [],
270
+ "name": "ZamaProtocolUnsupported",
271
+ "type": "error"
272
+ },
273
+ {
274
+ "anonymous": false,
275
+ "inputs": [
276
+ {
277
+ "indexed": true,
278
+ "internalType": "euint64",
279
+ "name": "encryptedAmount",
280
+ "type": "bytes32"
281
+ },
282
+ {
283
+ "indexed": true,
284
+ "internalType": "address",
285
+ "name": "requester",
286
+ "type": "address"
287
+ }
288
+ ],
289
+ "name": "AmountDiscloseRequested",
290
+ "type": "event"
291
+ },
292
+ {
293
+ "anonymous": false,
294
+ "inputs": [
295
+ {
296
+ "indexed": true,
297
+ "internalType": "euint64",
298
+ "name": "encryptedAmount",
299
+ "type": "bytes32"
300
+ },
301
+ {
302
+ "indexed": false,
303
+ "internalType": "uint64",
304
+ "name": "amount",
305
+ "type": "uint64"
306
+ }
307
+ ],
308
+ "name": "AmountDisclosed",
309
+ "type": "event"
310
+ },
311
+ {
312
+ "anonymous": false,
313
+ "inputs": [
314
+ {
315
+ "indexed": true,
316
+ "internalType": "address",
317
+ "name": "holder",
318
+ "type": "address"
319
+ },
320
+ {
321
+ "indexed": true,
322
+ "internalType": "address",
323
+ "name": "payee",
324
+ "type": "address"
325
+ },
326
+ {
327
+ "indexed": false,
328
+ "internalType": "uint256",
329
+ "name": "maxClearAmount",
330
+ "type": "uint256"
331
+ },
332
+ {
333
+ "indexed": true,
334
+ "internalType": "bytes32",
335
+ "name": "resourceHash",
336
+ "type": "bytes32"
337
+ },
338
+ {
339
+ "indexed": false,
340
+ "internalType": "bytes32",
341
+ "name": "nonce",
342
+ "type": "bytes32"
343
+ },
344
+ {
345
+ "indexed": false,
346
+ "internalType": "euint64",
347
+ "name": "transferredAmount",
348
+ "type": "bytes32"
349
+ }
350
+ ],
351
+ "name": "ConfidentialPaymentExecuted",
352
+ "type": "event"
353
+ },
354
+ {
355
+ "anonymous": false,
356
+ "inputs": [
357
+ {
358
+ "indexed": true,
359
+ "internalType": "address",
360
+ "name": "from",
361
+ "type": "address"
362
+ },
363
+ {
364
+ "indexed": true,
365
+ "internalType": "address",
366
+ "name": "to",
367
+ "type": "address"
368
+ },
369
+ {
370
+ "indexed": true,
371
+ "internalType": "euint64",
372
+ "name": "amount",
373
+ "type": "bytes32"
374
+ }
375
+ ],
376
+ "name": "ConfidentialTransfer",
377
+ "type": "event"
378
+ },
379
+ {
380
+ "anonymous": false,
381
+ "inputs": [],
382
+ "name": "EIP712DomainChanged",
383
+ "type": "event"
384
+ },
385
+ {
386
+ "anonymous": false,
387
+ "inputs": [
388
+ {
389
+ "indexed": false,
390
+ "internalType": "address",
391
+ "name": "account",
392
+ "type": "address"
393
+ },
394
+ {
395
+ "indexed": false,
396
+ "internalType": "address",
397
+ "name": "oldObserver",
398
+ "type": "address"
399
+ },
400
+ {
401
+ "indexed": false,
402
+ "internalType": "address",
403
+ "name": "newObserver",
404
+ "type": "address"
405
+ }
406
+ ],
407
+ "name": "ERC7984ObserverAccessObserverSet",
408
+ "type": "event"
409
+ },
410
+ {
411
+ "anonymous": false,
412
+ "inputs": [
413
+ {
414
+ "indexed": true,
415
+ "internalType": "address",
416
+ "name": "holder",
417
+ "type": "address"
418
+ },
419
+ {
420
+ "indexed": true,
421
+ "internalType": "address",
422
+ "name": "operator",
423
+ "type": "address"
424
+ },
425
+ {
426
+ "indexed": false,
427
+ "internalType": "uint48",
428
+ "name": "until",
429
+ "type": "uint48"
430
+ }
431
+ ],
432
+ "name": "OperatorSet",
433
+ "type": "event"
434
+ },
435
+ {
436
+ "anonymous": false,
437
+ "inputs": [
438
+ {
439
+ "indexed": false,
440
+ "internalType": "bytes32[]",
441
+ "name": "handlesList",
442
+ "type": "bytes32[]"
443
+ },
444
+ {
445
+ "indexed": false,
446
+ "internalType": "bytes",
447
+ "name": "abiEncodedCleartexts",
448
+ "type": "bytes"
449
+ }
450
+ ],
451
+ "name": "PublicDecryptionVerified",
452
+ "type": "event"
453
+ },
454
+ {
455
+ "anonymous": false,
456
+ "inputs": [
457
+ {
458
+ "indexed": true,
459
+ "internalType": "address",
460
+ "name": "receiver",
461
+ "type": "address"
462
+ },
463
+ {
464
+ "indexed": false,
465
+ "internalType": "euint64",
466
+ "name": "encryptedAmount",
467
+ "type": "bytes32"
468
+ },
469
+ {
470
+ "indexed": false,
471
+ "internalType": "uint64",
472
+ "name": "cleartextAmount",
473
+ "type": "uint64"
474
+ }
475
+ ],
476
+ "name": "UnwrapFinalized",
477
+ "type": "event"
478
+ },
479
+ {
480
+ "anonymous": false,
481
+ "inputs": [
482
+ {
483
+ "indexed": true,
484
+ "internalType": "address",
485
+ "name": "receiver",
486
+ "type": "address"
487
+ },
488
+ {
489
+ "indexed": false,
490
+ "internalType": "euint64",
491
+ "name": "amount",
492
+ "type": "bytes32"
493
+ }
494
+ ],
495
+ "name": "UnwrapRequested",
496
+ "type": "event"
497
+ },
498
+ {
499
+ "anonymous": false,
500
+ "inputs": [
501
+ {
502
+ "indexed": true,
503
+ "internalType": "address",
504
+ "name": "holder",
505
+ "type": "address"
506
+ },
507
+ {
508
+ "indexed": true,
509
+ "internalType": "address",
510
+ "name": "to",
511
+ "type": "address"
512
+ },
513
+ {
514
+ "indexed": false,
515
+ "internalType": "bytes32",
516
+ "name": "nonce",
517
+ "type": "bytes32"
518
+ },
519
+ {
520
+ "indexed": false,
521
+ "internalType": "bytes32",
522
+ "name": "encryptedAmountHandle",
523
+ "type": "bytes32"
524
+ }
525
+ ],
526
+ "name": "UnwrapWithAuthorizationExecuted",
527
+ "type": "event"
528
+ },
529
+ {
530
+ "inputs": [],
531
+ "name": "CONFIDENTIAL_PAYMENT_TYPEHASH",
532
+ "outputs": [
533
+ {
534
+ "internalType": "bytes32",
535
+ "name": "",
536
+ "type": "bytes32"
537
+ }
538
+ ],
539
+ "stateMutability": "view",
540
+ "type": "function"
541
+ },
542
+ {
543
+ "inputs": [],
544
+ "name": "UNWRAP_AUTHORIZATION_TYPEHASH",
545
+ "outputs": [
546
+ {
547
+ "internalType": "bytes32",
548
+ "name": "",
549
+ "type": "bytes32"
550
+ }
551
+ ],
552
+ "stateMutability": "view",
553
+ "type": "function"
554
+ },
555
+ {
556
+ "inputs": [
557
+ {
558
+ "internalType": "address",
559
+ "name": "account",
560
+ "type": "address"
561
+ }
562
+ ],
563
+ "name": "confidentialBalanceOf",
564
+ "outputs": [
565
+ {
566
+ "internalType": "euint64",
567
+ "name": "",
568
+ "type": "bytes32"
569
+ }
570
+ ],
571
+ "stateMutability": "view",
572
+ "type": "function"
573
+ },
574
+ {
575
+ "inputs": [],
576
+ "name": "confidentialProtocolId",
577
+ "outputs": [
578
+ {
579
+ "internalType": "uint256",
580
+ "name": "",
581
+ "type": "uint256"
582
+ }
583
+ ],
584
+ "stateMutability": "view",
585
+ "type": "function"
586
+ },
587
+ {
588
+ "inputs": [],
589
+ "name": "confidentialTotalSupply",
590
+ "outputs": [
591
+ {
592
+ "internalType": "euint64",
593
+ "name": "",
594
+ "type": "bytes32"
595
+ }
596
+ ],
597
+ "stateMutability": "view",
598
+ "type": "function"
599
+ },
600
+ {
601
+ "inputs": [
602
+ {
603
+ "internalType": "address",
604
+ "name": "to",
605
+ "type": "address"
606
+ },
607
+ {
608
+ "internalType": "externalEuint64",
609
+ "name": "encryptedAmount",
610
+ "type": "bytes32"
611
+ },
612
+ {
613
+ "internalType": "bytes",
614
+ "name": "inputProof",
615
+ "type": "bytes"
616
+ }
617
+ ],
618
+ "name": "confidentialTransfer",
619
+ "outputs": [
620
+ {
621
+ "internalType": "euint64",
622
+ "name": "",
623
+ "type": "bytes32"
624
+ }
625
+ ],
626
+ "stateMutability": "nonpayable",
627
+ "type": "function"
628
+ },
629
+ {
630
+ "inputs": [
631
+ {
632
+ "internalType": "address",
633
+ "name": "to",
634
+ "type": "address"
635
+ },
636
+ {
637
+ "internalType": "euint64",
638
+ "name": "amount",
639
+ "type": "bytes32"
640
+ }
641
+ ],
642
+ "name": "confidentialTransfer",
643
+ "outputs": [
644
+ {
645
+ "internalType": "euint64",
646
+ "name": "",
647
+ "type": "bytes32"
648
+ }
649
+ ],
650
+ "stateMutability": "nonpayable",
651
+ "type": "function"
652
+ },
653
+ {
654
+ "inputs": [
655
+ {
656
+ "internalType": "address",
657
+ "name": "to",
658
+ "type": "address"
659
+ },
660
+ {
661
+ "internalType": "euint64",
662
+ "name": "amount",
663
+ "type": "bytes32"
664
+ },
665
+ {
666
+ "internalType": "bytes",
667
+ "name": "data",
668
+ "type": "bytes"
669
+ }
670
+ ],
671
+ "name": "confidentialTransferAndCall",
672
+ "outputs": [
673
+ {
674
+ "internalType": "euint64",
675
+ "name": "transferred",
676
+ "type": "bytes32"
677
+ }
678
+ ],
679
+ "stateMutability": "nonpayable",
680
+ "type": "function"
681
+ },
682
+ {
683
+ "inputs": [
684
+ {
685
+ "internalType": "address",
686
+ "name": "to",
687
+ "type": "address"
688
+ },
689
+ {
690
+ "internalType": "externalEuint64",
691
+ "name": "encryptedAmount",
692
+ "type": "bytes32"
693
+ },
694
+ {
695
+ "internalType": "bytes",
696
+ "name": "inputProof",
697
+ "type": "bytes"
698
+ },
699
+ {
700
+ "internalType": "bytes",
701
+ "name": "data",
702
+ "type": "bytes"
703
+ }
704
+ ],
705
+ "name": "confidentialTransferAndCall",
706
+ "outputs": [
707
+ {
708
+ "internalType": "euint64",
709
+ "name": "transferred",
710
+ "type": "bytes32"
711
+ }
712
+ ],
713
+ "stateMutability": "nonpayable",
714
+ "type": "function"
715
+ },
716
+ {
717
+ "inputs": [
718
+ {
719
+ "internalType": "address",
720
+ "name": "from",
721
+ "type": "address"
722
+ },
723
+ {
724
+ "internalType": "address",
725
+ "name": "to",
726
+ "type": "address"
727
+ },
728
+ {
729
+ "internalType": "externalEuint64",
730
+ "name": "encryptedAmount",
731
+ "type": "bytes32"
732
+ },
733
+ {
734
+ "internalType": "bytes",
735
+ "name": "inputProof",
736
+ "type": "bytes"
737
+ }
738
+ ],
739
+ "name": "confidentialTransferFrom",
740
+ "outputs": [
741
+ {
742
+ "internalType": "euint64",
743
+ "name": "transferred",
744
+ "type": "bytes32"
745
+ }
746
+ ],
747
+ "stateMutability": "nonpayable",
748
+ "type": "function"
749
+ },
750
+ {
751
+ "inputs": [
752
+ {
753
+ "internalType": "address",
754
+ "name": "from",
755
+ "type": "address"
756
+ },
757
+ {
758
+ "internalType": "address",
759
+ "name": "to",
760
+ "type": "address"
761
+ },
762
+ {
763
+ "internalType": "euint64",
764
+ "name": "amount",
765
+ "type": "bytes32"
766
+ }
767
+ ],
768
+ "name": "confidentialTransferFrom",
769
+ "outputs": [
770
+ {
771
+ "internalType": "euint64",
772
+ "name": "transferred",
773
+ "type": "bytes32"
774
+ }
775
+ ],
776
+ "stateMutability": "nonpayable",
777
+ "type": "function"
778
+ },
779
+ {
780
+ "inputs": [
781
+ {
782
+ "internalType": "address",
783
+ "name": "from",
784
+ "type": "address"
785
+ },
786
+ {
787
+ "internalType": "address",
788
+ "name": "to",
789
+ "type": "address"
790
+ },
791
+ {
792
+ "internalType": "externalEuint64",
793
+ "name": "encryptedAmount",
794
+ "type": "bytes32"
795
+ },
796
+ {
797
+ "internalType": "bytes",
798
+ "name": "inputProof",
799
+ "type": "bytes"
800
+ },
801
+ {
802
+ "internalType": "bytes",
803
+ "name": "data",
804
+ "type": "bytes"
805
+ }
806
+ ],
807
+ "name": "confidentialTransferFromAndCall",
808
+ "outputs": [
809
+ {
810
+ "internalType": "euint64",
811
+ "name": "transferred",
812
+ "type": "bytes32"
813
+ }
814
+ ],
815
+ "stateMutability": "nonpayable",
816
+ "type": "function"
817
+ },
818
+ {
819
+ "inputs": [
820
+ {
821
+ "internalType": "address",
822
+ "name": "from",
823
+ "type": "address"
824
+ },
825
+ {
826
+ "internalType": "address",
827
+ "name": "to",
828
+ "type": "address"
829
+ },
830
+ {
831
+ "internalType": "euint64",
832
+ "name": "amount",
833
+ "type": "bytes32"
834
+ },
835
+ {
836
+ "internalType": "bytes",
837
+ "name": "data",
838
+ "type": "bytes"
839
+ }
840
+ ],
841
+ "name": "confidentialTransferFromAndCall",
842
+ "outputs": [
843
+ {
844
+ "internalType": "euint64",
845
+ "name": "transferred",
846
+ "type": "bytes32"
847
+ }
848
+ ],
849
+ "stateMutability": "nonpayable",
850
+ "type": "function"
851
+ },
852
+ {
853
+ "inputs": [
854
+ {
855
+ "components": [
856
+ {
857
+ "internalType": "address",
858
+ "name": "holder",
859
+ "type": "address"
860
+ },
861
+ {
862
+ "internalType": "address",
863
+ "name": "payee",
864
+ "type": "address"
865
+ },
866
+ {
867
+ "internalType": "uint256",
868
+ "name": "maxClearAmount",
869
+ "type": "uint256"
870
+ },
871
+ {
872
+ "internalType": "bytes32",
873
+ "name": "resourceHash",
874
+ "type": "bytes32"
875
+ },
876
+ {
877
+ "internalType": "uint48",
878
+ "name": "validAfter",
879
+ "type": "uint48"
880
+ },
881
+ {
882
+ "internalType": "uint48",
883
+ "name": "validBefore",
884
+ "type": "uint48"
885
+ },
886
+ {
887
+ "internalType": "bytes32",
888
+ "name": "nonce",
889
+ "type": "bytes32"
890
+ },
891
+ {
892
+ "internalType": "bytes32",
893
+ "name": "encryptedAmountHash",
894
+ "type": "bytes32"
895
+ }
896
+ ],
897
+ "internalType": "struct FHEToken.ConfidentialPayment",
898
+ "name": "p",
899
+ "type": "tuple"
900
+ },
901
+ {
902
+ "internalType": "externalEuint64",
903
+ "name": "encryptedAmountInput",
904
+ "type": "bytes32"
905
+ },
906
+ {
907
+ "internalType": "bytes",
908
+ "name": "inputProof",
909
+ "type": "bytes"
910
+ },
911
+ {
912
+ "internalType": "bytes",
913
+ "name": "sig",
914
+ "type": "bytes"
915
+ }
8
916
  ],
9
- name: "confidentialTransfer",
10
- outputs: [{ internalType: "euint64", name: "transferred", type: "bytes32" }],
11
- stateMutability: "nonpayable",
12
- type: "function"
917
+ "name": "confidentialTransferWithAuthorization",
918
+ "outputs": [
919
+ {
920
+ "internalType": "euint64",
921
+ "name": "transferred",
922
+ "type": "bytes32"
923
+ }
924
+ ],
925
+ "stateMutability": "nonpayable",
926
+ "type": "function"
13
927
  },
14
928
  {
15
- inputs: [
929
+ "inputs": [],
930
+ "name": "contractURI",
931
+ "outputs": [
16
932
  {
17
- components: [
18
- { internalType: "address", name: "holder", type: "address" },
19
- { internalType: "address", name: "payee", type: "address" },
20
- { internalType: "uint256", name: "maxClearAmount", type: "uint256" },
21
- { internalType: "bytes32", name: "resourceHash", type: "bytes32" },
22
- { internalType: "uint48", name: "validAfter", type: "uint48" },
23
- { internalType: "uint48", name: "validBefore", type: "uint48" },
24
- { internalType: "bytes32", name: "nonce", type: "bytes32" },
25
- { internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" }
26
- ],
27
- internalType: "struct FHEToken.ConfidentialPayment",
28
- name: "p",
29
- type: "tuple"
933
+ "internalType": "string",
934
+ "name": "",
935
+ "type": "string"
936
+ }
937
+ ],
938
+ "stateMutability": "view",
939
+ "type": "function"
940
+ },
941
+ {
942
+ "inputs": [],
943
+ "name": "decimals",
944
+ "outputs": [
945
+ {
946
+ "internalType": "uint8",
947
+ "name": "",
948
+ "type": "uint8"
949
+ }
950
+ ],
951
+ "stateMutability": "view",
952
+ "type": "function"
953
+ },
954
+ {
955
+ "inputs": [
956
+ {
957
+ "internalType": "euint64",
958
+ "name": "encryptedAmount",
959
+ "type": "bytes32"
960
+ },
961
+ {
962
+ "internalType": "uint64",
963
+ "name": "cleartextAmount",
964
+ "type": "uint64"
30
965
  },
31
- { internalType: "externalEuint64", name: "encryptedAmountInput", type: "bytes32" },
32
- { internalType: "bytes", name: "inputProof", type: "bytes" },
33
- { internalType: "bytes", name: "sig", type: "bytes" }
966
+ {
967
+ "internalType": "bytes",
968
+ "name": "decryptionProof",
969
+ "type": "bytes"
970
+ }
34
971
  ],
35
- name: "confidentialTransferWithAuthorization",
36
- outputs: [{ internalType: "euint64", name: "transferred", type: "bytes32" }],
37
- stateMutability: "nonpayable",
38
- type: "function"
972
+ "name": "discloseEncryptedAmount",
973
+ "outputs": [],
974
+ "stateMutability": "nonpayable",
975
+ "type": "function"
39
976
  },
40
977
  {
41
- inputs: [
42
- { internalType: "address", name: "to", type: "address" },
43
- { internalType: "uint256", name: "amount", type: "uint256" }
978
+ "inputs": [],
979
+ "name": "eip712Domain",
980
+ "outputs": [
981
+ {
982
+ "internalType": "bytes1",
983
+ "name": "fields",
984
+ "type": "bytes1"
985
+ },
986
+ {
987
+ "internalType": "string",
988
+ "name": "name",
989
+ "type": "string"
990
+ },
991
+ {
992
+ "internalType": "string",
993
+ "name": "version",
994
+ "type": "string"
995
+ },
996
+ {
997
+ "internalType": "uint256",
998
+ "name": "chainId",
999
+ "type": "uint256"
1000
+ },
1001
+ {
1002
+ "internalType": "address",
1003
+ "name": "verifyingContract",
1004
+ "type": "address"
1005
+ },
1006
+ {
1007
+ "internalType": "bytes32",
1008
+ "name": "salt",
1009
+ "type": "bytes32"
1010
+ },
1011
+ {
1012
+ "internalType": "uint256[]",
1013
+ "name": "extensions",
1014
+ "type": "uint256[]"
1015
+ }
44
1016
  ],
45
- name: "wrap",
46
- outputs: [],
47
- stateMutability: "nonpayable",
48
- type: "function"
1017
+ "stateMutability": "view",
1018
+ "type": "function"
49
1019
  },
50
1020
  {
51
- inputs: [
52
- { internalType: "address", name: "from", type: "address" },
53
- { internalType: "address", name: "to", type: "address" },
54
- { internalType: "bytes32", name: "encryptedAmountInput", type: "bytes32" },
55
- { internalType: "bytes", name: "inputProof", type: "bytes" }
1021
+ "inputs": [
1022
+ {
1023
+ "internalType": "euint64",
1024
+ "name": "burntAmount",
1025
+ "type": "bytes32"
1026
+ },
1027
+ {
1028
+ "internalType": "uint64",
1029
+ "name": "burntAmountCleartext",
1030
+ "type": "uint64"
1031
+ },
1032
+ {
1033
+ "internalType": "bytes",
1034
+ "name": "decryptionProof",
1035
+ "type": "bytes"
1036
+ }
56
1037
  ],
57
- name: "unwrap",
58
- outputs: [],
59
- stateMutability: "nonpayable",
60
- type: "function"
1038
+ "name": "finalizeUnwrap",
1039
+ "outputs": [],
1040
+ "stateMutability": "nonpayable",
1041
+ "type": "function"
61
1042
  },
62
1043
  {
63
- inputs: [
64
- { internalType: "address", name: "from", type: "address" },
65
- { internalType: "address", name: "to", type: "address" },
66
- { internalType: "euint64", name: "amount", type: "bytes32" }
1044
+ "inputs": [],
1045
+ "name": "inferredTotalSupply",
1046
+ "outputs": [
1047
+ {
1048
+ "internalType": "uint256",
1049
+ "name": "",
1050
+ "type": "uint256"
1051
+ }
67
1052
  ],
68
- name: "unwrap",
69
- outputs: [],
70
- stateMutability: "nonpayable",
71
- type: "function"
1053
+ "stateMutability": "view",
1054
+ "type": "function"
72
1055
  },
73
1056
  {
74
- inputs: [
1057
+ "inputs": [
75
1058
  {
76
- components: [
77
- { internalType: "address", name: "holder", type: "address" },
78
- { internalType: "address", name: "to", type: "address" },
79
- { internalType: "uint48", name: "validAfter", type: "uint48" },
80
- { internalType: "uint48", name: "validBefore", type: "uint48" },
81
- { internalType: "bytes32", name: "nonce", type: "bytes32" },
82
- { internalType: "bytes32", name: "encryptedAmountHash", type: "bytes32" }
83
- ],
84
- internalType: "struct FHEToken.UnwrapAuthorization",
85
- name: "p",
86
- type: "tuple"
1059
+ "internalType": "address",
1060
+ "name": "holder",
1061
+ "type": "address"
1062
+ },
1063
+ {
1064
+ "internalType": "address",
1065
+ "name": "spender",
1066
+ "type": "address"
1067
+ }
1068
+ ],
1069
+ "name": "isOperator",
1070
+ "outputs": [
1071
+ {
1072
+ "internalType": "bool",
1073
+ "name": "",
1074
+ "type": "bool"
1075
+ }
1076
+ ],
1077
+ "stateMutability": "view",
1078
+ "type": "function"
1079
+ },
1080
+ {
1081
+ "inputs": [],
1082
+ "name": "maxTotalSupply",
1083
+ "outputs": [
1084
+ {
1085
+ "internalType": "uint256",
1086
+ "name": "",
1087
+ "type": "uint256"
1088
+ }
1089
+ ],
1090
+ "stateMutability": "view",
1091
+ "type": "function"
1092
+ },
1093
+ {
1094
+ "inputs": [],
1095
+ "name": "name",
1096
+ "outputs": [
1097
+ {
1098
+ "internalType": "string",
1099
+ "name": "",
1100
+ "type": "string"
1101
+ }
1102
+ ],
1103
+ "stateMutability": "view",
1104
+ "type": "function"
1105
+ },
1106
+ {
1107
+ "inputs": [
1108
+ {
1109
+ "internalType": "address",
1110
+ "name": "account",
1111
+ "type": "address"
1112
+ }
1113
+ ],
1114
+ "name": "observer",
1115
+ "outputs": [
1116
+ {
1117
+ "internalType": "address",
1118
+ "name": "",
1119
+ "type": "address"
1120
+ }
1121
+ ],
1122
+ "stateMutability": "view",
1123
+ "type": "function"
1124
+ },
1125
+ {
1126
+ "inputs": [
1127
+ {
1128
+ "internalType": "address",
1129
+ "name": "",
1130
+ "type": "address"
1131
+ },
1132
+ {
1133
+ "internalType": "address",
1134
+ "name": "from",
1135
+ "type": "address"
87
1136
  },
88
1137
  {
89
- internalType: "externalEuint64",
90
- name: "encryptedAmountInput",
91
- type: "bytes32"
1138
+ "internalType": "uint256",
1139
+ "name": "amount",
1140
+ "type": "uint256"
92
1141
  },
93
- { internalType: "bytes", name: "inputProof", type: "bytes" },
94
- { internalType: "bytes", name: "sig", type: "bytes" }
1142
+ {
1143
+ "internalType": "bytes",
1144
+ "name": "data",
1145
+ "type": "bytes"
1146
+ }
95
1147
  ],
96
- name: "unwrapWithAuthorization",
97
- outputs: [],
98
- stateMutability: "nonpayable",
99
- type: "function"
1148
+ "name": "onTransferReceived",
1149
+ "outputs": [
1150
+ {
1151
+ "internalType": "bytes4",
1152
+ "name": "",
1153
+ "type": "bytes4"
1154
+ }
1155
+ ],
1156
+ "stateMutability": "nonpayable",
1157
+ "type": "function"
100
1158
  },
101
1159
  {
102
- inputs: [
103
- { internalType: "euint64", name: "burntAmount", type: "bytes32" },
104
- { internalType: "uint64", name: "burntAmountCleartext", type: "uint64" },
105
- { internalType: "bytes", name: "decryptionProof", type: "bytes" }
1160
+ "inputs": [],
1161
+ "name": "rate",
1162
+ "outputs": [
1163
+ {
1164
+ "internalType": "uint256",
1165
+ "name": "",
1166
+ "type": "uint256"
1167
+ }
106
1168
  ],
107
- name: "finalizeUnwrap",
108
- outputs: [],
109
- stateMutability: "nonpayable",
110
- type: "function"
1169
+ "stateMutability": "view",
1170
+ "type": "function"
111
1171
  },
112
1172
  {
113
- inputs: [{ internalType: "address", name: "account", type: "address" }],
114
- name: "confidentialBalanceOf",
115
- outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
116
- stateMutability: "view",
117
- type: "function"
1173
+ "inputs": [
1174
+ {
1175
+ "internalType": "euint64",
1176
+ "name": "encryptedAmount",
1177
+ "type": "bytes32"
1178
+ }
1179
+ ],
1180
+ "name": "requestDiscloseEncryptedAmount",
1181
+ "outputs": [],
1182
+ "stateMutability": "nonpayable",
1183
+ "type": "function"
118
1184
  },
119
1185
  {
120
- anonymous: false,
121
- inputs: [
122
- { indexed: true, internalType: "address", name: "holder", type: "address" },
123
- { indexed: true, internalType: "address", name: "payee", type: "address" },
124
- { indexed: false, internalType: "uint256", name: "maxClearAmount", type: "uint256" },
125
- { indexed: true, internalType: "bytes32", name: "resourceHash", type: "bytes32" },
126
- { indexed: false, internalType: "bytes32", name: "nonce", type: "bytes32" },
127
- { indexed: false, internalType: "bytes32", name: "transferredAmount", type: "bytes32" }
1186
+ "inputs": [
1187
+ {
1188
+ "internalType": "address",
1189
+ "name": "account",
1190
+ "type": "address"
1191
+ },
1192
+ {
1193
+ "internalType": "address",
1194
+ "name": "newObserver",
1195
+ "type": "address"
1196
+ }
128
1197
  ],
129
- name: "ConfidentialPaymentExecuted",
130
- type: "event"
1198
+ "name": "setObserver",
1199
+ "outputs": [],
1200
+ "stateMutability": "nonpayable",
1201
+ "type": "function"
131
1202
  },
132
1203
  {
133
- inputs: [
134
- { indexed: true, internalType: "address", name: "receiver", type: "address" },
135
- { indexed: false, internalType: "bytes32", name: "encryptedAmount", type: "bytes32" },
136
- { indexed: false, internalType: "uint64", name: "cleartextAmount", type: "uint64" }
1204
+ "inputs": [
1205
+ {
1206
+ "internalType": "address",
1207
+ "name": "operator",
1208
+ "type": "address"
1209
+ },
1210
+ {
1211
+ "internalType": "uint48",
1212
+ "name": "until",
1213
+ "type": "uint48"
1214
+ }
137
1215
  ],
138
- name: "UnwrapFinalized",
139
- type: "event"
1216
+ "name": "setOperator",
1217
+ "outputs": [],
1218
+ "stateMutability": "nonpayable",
1219
+ "type": "function"
140
1220
  },
141
1221
  {
142
- inputs: [
143
- { indexed: true, internalType: "address", name: "receiver", type: "address" },
144
- { indexed: false, internalType: "bytes32", name: "amount", type: "bytes32" }
1222
+ "inputs": [
1223
+ {
1224
+ "internalType": "bytes4",
1225
+ "name": "interfaceId",
1226
+ "type": "bytes4"
1227
+ }
1228
+ ],
1229
+ "name": "supportsInterface",
1230
+ "outputs": [
1231
+ {
1232
+ "internalType": "bool",
1233
+ "name": "",
1234
+ "type": "bool"
1235
+ }
145
1236
  ],
146
- name: "UnwrapRequested",
147
- type: "event"
1237
+ "stateMutability": "view",
1238
+ "type": "function"
148
1239
  },
149
1240
  {
150
- inputs: [
151
- { indexed: true, internalType: "address", name: "holder", type: "address" },
152
- { indexed: true, internalType: "address", name: "to", type: "address" },
153
- { indexed: false, internalType: "bytes32", name: "nonce", type: "bytes32" },
154
- { indexed: false, internalType: "bytes32", name: "encryptedAmountHandle", type: "bytes32" }
1241
+ "inputs": [],
1242
+ "name": "symbol",
1243
+ "outputs": [
1244
+ {
1245
+ "internalType": "string",
1246
+ "name": "",
1247
+ "type": "string"
1248
+ }
155
1249
  ],
156
- name: "UnwrapWithAuthorizationExecuted",
157
- type: "event"
1250
+ "stateMutability": "view",
1251
+ "type": "function"
158
1252
  },
159
1253
  {
160
- inputs: [
161
- { internalType: "address", name: "", type: "address" },
162
- { internalType: "bytes32", name: "", type: "bytes32" }
1254
+ "inputs": [],
1255
+ "name": "underlying",
1256
+ "outputs": [
1257
+ {
1258
+ "internalType": "contract IERC20",
1259
+ "name": "",
1260
+ "type": "address"
1261
+ }
163
1262
  ],
164
- name: "usedNonces",
165
- outputs: [{ internalType: "bool", name: "", type: "bool" }],
166
- stateMutability: "view",
167
- type: "function"
1263
+ "stateMutability": "view",
1264
+ "type": "function"
168
1265
  },
169
1266
  {
170
- inputs: [{ internalType: "address", name: "account", type: "address" }],
171
- name: "observer",
172
- outputs: [{ internalType: "address", name: "", type: "address" }],
173
- stateMutability: "view",
174
- type: "function"
1267
+ "inputs": [
1268
+ {
1269
+ "internalType": "address",
1270
+ "name": "from",
1271
+ "type": "address"
1272
+ },
1273
+ {
1274
+ "internalType": "address",
1275
+ "name": "to",
1276
+ "type": "address"
1277
+ },
1278
+ {
1279
+ "internalType": "externalEuint64",
1280
+ "name": "encryptedAmount",
1281
+ "type": "bytes32"
1282
+ },
1283
+ {
1284
+ "internalType": "bytes",
1285
+ "name": "inputProof",
1286
+ "type": "bytes"
1287
+ }
1288
+ ],
1289
+ "name": "unwrap",
1290
+ "outputs": [],
1291
+ "stateMutability": "nonpayable",
1292
+ "type": "function"
175
1293
  },
176
1294
  {
177
- inputs: [
178
- { internalType: "address", name: "account", type: "address" },
179
- { internalType: "address", name: "newObserver", type: "address" }
1295
+ "inputs": [
1296
+ {
1297
+ "internalType": "address",
1298
+ "name": "from",
1299
+ "type": "address"
1300
+ },
1301
+ {
1302
+ "internalType": "address",
1303
+ "name": "to",
1304
+ "type": "address"
1305
+ },
1306
+ {
1307
+ "internalType": "euint64",
1308
+ "name": "amount",
1309
+ "type": "bytes32"
1310
+ }
180
1311
  ],
181
- name: "setObserver",
182
- outputs: [],
183
- stateMutability: "nonpayable",
184
- type: "function"
1312
+ "name": "unwrap",
1313
+ "outputs": [],
1314
+ "stateMutability": "nonpayable",
1315
+ "type": "function"
1316
+ },
1317
+ {
1318
+ "inputs": [
1319
+ {
1320
+ "components": [
1321
+ {
1322
+ "internalType": "address",
1323
+ "name": "holder",
1324
+ "type": "address"
1325
+ },
1326
+ {
1327
+ "internalType": "address",
1328
+ "name": "to",
1329
+ "type": "address"
1330
+ },
1331
+ {
1332
+ "internalType": "uint48",
1333
+ "name": "validAfter",
1334
+ "type": "uint48"
1335
+ },
1336
+ {
1337
+ "internalType": "uint48",
1338
+ "name": "validBefore",
1339
+ "type": "uint48"
1340
+ },
1341
+ {
1342
+ "internalType": "bytes32",
1343
+ "name": "nonce",
1344
+ "type": "bytes32"
1345
+ },
1346
+ {
1347
+ "internalType": "bytes32",
1348
+ "name": "encryptedAmountHash",
1349
+ "type": "bytes32"
1350
+ }
1351
+ ],
1352
+ "internalType": "struct FHEToken.UnwrapAuthorization",
1353
+ "name": "p",
1354
+ "type": "tuple"
1355
+ },
1356
+ {
1357
+ "internalType": "externalEuint64",
1358
+ "name": "encryptedAmountInput",
1359
+ "type": "bytes32"
1360
+ },
1361
+ {
1362
+ "internalType": "bytes",
1363
+ "name": "inputProof",
1364
+ "type": "bytes"
1365
+ },
1366
+ {
1367
+ "internalType": "bytes",
1368
+ "name": "sig",
1369
+ "type": "bytes"
1370
+ }
1371
+ ],
1372
+ "name": "unwrapWithAuthorization",
1373
+ "outputs": [],
1374
+ "stateMutability": "nonpayable",
1375
+ "type": "function"
1376
+ },
1377
+ {
1378
+ "inputs": [
1379
+ {
1380
+ "internalType": "address",
1381
+ "name": "",
1382
+ "type": "address"
1383
+ },
1384
+ {
1385
+ "internalType": "bytes32",
1386
+ "name": "",
1387
+ "type": "bytes32"
1388
+ }
1389
+ ],
1390
+ "name": "usedNonces",
1391
+ "outputs": [
1392
+ {
1393
+ "internalType": "bool",
1394
+ "name": "",
1395
+ "type": "bool"
1396
+ }
1397
+ ],
1398
+ "stateMutability": "view",
1399
+ "type": "function"
1400
+ },
1401
+ {
1402
+ "inputs": [
1403
+ {
1404
+ "internalType": "address",
1405
+ "name": "to",
1406
+ "type": "address"
1407
+ },
1408
+ {
1409
+ "internalType": "uint256",
1410
+ "name": "amount",
1411
+ "type": "uint256"
1412
+ }
1413
+ ],
1414
+ "name": "wrap",
1415
+ "outputs": [],
1416
+ "stateMutability": "nonpayable",
1417
+ "type": "function"
185
1418
  }
186
1419
  ];
187
1420
 
@@ -313,10 +1546,12 @@ async function createEncryptedAmountInput(relayer, contractAddress, callerAddres
313
1546
  };
314
1547
  }
315
1548
  async function decryptEuint64(relayer, handle, contractAddress, signer, options) {
1549
+ const normalizedContract = getAddress(contractAddress);
1550
+ const signerAddress = getAddress(signer.address);
316
1551
  const keypair = relayer.generateKeypair();
317
1552
  const startTimestamp = options?.startTimestamp ?? Math.floor(Date.now() / 1e3);
318
1553
  const durationDays = options?.durationDays ?? 10;
319
- const contractAddresses = [contractAddress];
1554
+ const contractAddresses = [normalizedContract];
320
1555
  const eip712 = relayer.createEIP712(keypair.publicKey, contractAddresses, startTimestamp, durationDays);
321
1556
  const types = { UserDecryptRequestVerification: eip712.types.UserDecryptRequestVerification };
322
1557
  const sign = signer.signTypedData;
@@ -327,12 +1562,12 @@ async function decryptEuint64(relayer, handle, contractAddress, signer, options)
327
1562
  message: eip712.message
328
1563
  });
329
1564
  const result = await relayer.userDecrypt(
330
- [{ handle, contractAddress }],
1565
+ [{ handle, contractAddress: normalizedContract }],
331
1566
  keypair.privateKey,
332
1567
  keypair.publicKey,
333
1568
  signature.replace("0x", ""),
334
1569
  contractAddresses,
335
- signer.address,
1570
+ signerAddress,
336
1571
  startTimestamp,
337
1572
  durationDays
338
1573
  );
@@ -346,8 +1581,233 @@ async function publicDecrypt(relayer, handles) {
346
1581
  };
347
1582
  }
348
1583
 
1584
+ // src/unwrap.ts
1585
+ import { createPublicClient, decodeEventLog, getAddress as getAddress2, http, toHex as toHex3 } from "viem";
1586
+ async function getTokenEip712Domain(params) {
1587
+ const tokenAddress = getAddress2(params.tokenAddress);
1588
+ const publicClient = createPublicClient({ transport: http(params.rpcUrl) });
1589
+ let name = params.fallbackName;
1590
+ let version = params.fallbackVersion;
1591
+ let chainId;
1592
+ let verifyingContract = tokenAddress;
1593
+ try {
1594
+ const domain = await publicClient.readContract({
1595
+ address: tokenAddress,
1596
+ abi: [
1597
+ {
1598
+ name: "eip712Domain",
1599
+ type: "function",
1600
+ stateMutability: "view",
1601
+ inputs: [],
1602
+ outputs: [
1603
+ { type: "bytes1" },
1604
+ { type: "string" },
1605
+ { type: "string" },
1606
+ { type: "uint256" },
1607
+ { type: "address" },
1608
+ { type: "bytes32" },
1609
+ { type: "uint256[]" }
1610
+ ]
1611
+ }
1612
+ ],
1613
+ functionName: "eip712Domain"
1614
+ });
1615
+ const [, domainName, domainVersion, domainChainId, domainVerifying] = domain;
1616
+ name = domainName || name;
1617
+ version = domainVersion || version;
1618
+ chainId = Number(domainChainId);
1619
+ verifyingContract = domainVerifying || verifyingContract;
1620
+ } catch {
1621
+ }
1622
+ if (!name || !version) {
1623
+ try {
1624
+ name = await publicClient.readContract({
1625
+ address: tokenAddress,
1626
+ abi: [{ name: "name", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] }],
1627
+ functionName: "name"
1628
+ });
1629
+ } catch {
1630
+ }
1631
+ try {
1632
+ version = await publicClient.readContract({
1633
+ address: tokenAddress,
1634
+ abi: [{ name: "version", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] }],
1635
+ functionName: "version"
1636
+ });
1637
+ } catch {
1638
+ }
1639
+ }
1640
+ if (!chainId) {
1641
+ chainId = await publicClient.getChainId();
1642
+ }
1643
+ if (!name || !version) {
1644
+ throw new Error("Missing EIP-712 name/version for unwrap authorization");
1645
+ }
1646
+ return {
1647
+ name,
1648
+ version,
1649
+ chainId,
1650
+ verifyingContract
1651
+ };
1652
+ }
1653
+ async function prepareUnwrapAuthorization(params) {
1654
+ const tokenAddress = getAddress2(params.tokenAddress);
1655
+ const holderAddress = getAddress2(params.signer.address);
1656
+ const callerAddress = getAddress2(params.callerAddress);
1657
+ const now = Math.floor(Date.now() / 1e3);
1658
+ const validAfter = params.validAfter ?? now - 60;
1659
+ const validBefore = params.validBefore ?? now + 300;
1660
+ const nonce = params.nonce ?? createNonce();
1661
+ const encrypted = await params.relayer.createEncryptedInput(tokenAddress, callerAddress).add64(Number(params.amount)).encrypt();
1662
+ const handle = typeof encrypted.handles[0] === "string" ? encrypted.handles[0] : toHex3(encrypted.handles[0]);
1663
+ const inputProof = typeof encrypted.inputProof === "string" ? encrypted.inputProof : toHex3(encrypted.inputProof);
1664
+ const authorization = {
1665
+ holder: holderAddress,
1666
+ to: callerAddress,
1667
+ validAfter,
1668
+ validBefore,
1669
+ nonce,
1670
+ encryptedAmountHash: hashEncryptedAmountInput(handle)
1671
+ };
1672
+ const signature = await params.signer.signTypedData({
1673
+ domain: {
1674
+ name: params.domain.name,
1675
+ version: params.domain.version,
1676
+ chainId: params.domain.chainId,
1677
+ verifyingContract: params.domain.verifyingContract
1678
+ },
1679
+ types: {
1680
+ UnwrapAuthorization: [
1681
+ { name: "holder", type: "address" },
1682
+ { name: "to", type: "address" },
1683
+ { name: "validAfter", type: "uint48" },
1684
+ { name: "validBefore", type: "uint48" },
1685
+ { name: "nonce", type: "bytes32" },
1686
+ { name: "encryptedAmountHash", type: "bytes32" }
1687
+ ]
1688
+ },
1689
+ primaryType: "UnwrapAuthorization",
1690
+ message: {
1691
+ holder: authorization.holder,
1692
+ to: authorization.to,
1693
+ validAfter: BigInt(validAfter),
1694
+ validBefore: BigInt(validBefore),
1695
+ nonce: authorization.nonce,
1696
+ encryptedAmountHash: authorization.encryptedAmountHash
1697
+ }
1698
+ });
1699
+ return {
1700
+ authorization,
1701
+ handle,
1702
+ inputProof,
1703
+ signature
1704
+ };
1705
+ }
1706
+ function getUnwrapHandleFromLogs(params) {
1707
+ const tokenAddress = getAddress2(params.tokenAddress).toLowerCase();
1708
+ for (const logEntry of params.logs) {
1709
+ if (!logEntry.address || logEntry.address.toLowerCase() !== tokenAddress) {
1710
+ continue;
1711
+ }
1712
+ try {
1713
+ if (logEntry.topics.length === 0) {
1714
+ continue;
1715
+ }
1716
+ const topics = [
1717
+ logEntry.topics[0],
1718
+ ...logEntry.topics.slice(1)
1719
+ ];
1720
+ const decoded = decodeEventLog({
1721
+ abi: confidentialTokenAbi,
1722
+ eventName: "UnwrapRequested",
1723
+ data: logEntry.data,
1724
+ topics
1725
+ });
1726
+ const args = decoded.args;
1727
+ if (args.amount) {
1728
+ return args.amount;
1729
+ }
1730
+ } catch {
1731
+ }
1732
+ }
1733
+ return params.fallbackHandle ?? null;
1734
+ }
1735
+
1736
+ // src/wrap.ts
1737
+ import { createPublicClient as createPublicClient2, getAddress as getAddress3, http as http2 } from "viem";
1738
+ var fhetokenViewAbi = [
1739
+ {
1740
+ inputs: [],
1741
+ name: "underlying",
1742
+ outputs: [{ internalType: "address", name: "", type: "address" }],
1743
+ stateMutability: "view",
1744
+ type: "function"
1745
+ }
1746
+ ];
1747
+ var erc20Abi = [
1748
+ {
1749
+ inputs: [
1750
+ { internalType: "address", name: "owner", type: "address" },
1751
+ { internalType: "address", name: "spender", type: "address" }
1752
+ ],
1753
+ name: "allowance",
1754
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
1755
+ stateMutability: "view",
1756
+ type: "function"
1757
+ },
1758
+ {
1759
+ inputs: [
1760
+ { internalType: "address", name: "spender", type: "address" },
1761
+ { internalType: "uint256", name: "amount", type: "uint256" }
1762
+ ],
1763
+ name: "approve",
1764
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
1765
+ stateMutability: "nonpayable",
1766
+ type: "function"
1767
+ }
1768
+ ];
1769
+ async function getUnderlyingTokenAddress(params) {
1770
+ const tokenAddress = getAddress3(params.tokenAddress);
1771
+ const publicClient = createPublicClient2({ transport: http2(params.rpcUrl) });
1772
+ return publicClient.readContract({
1773
+ address: tokenAddress,
1774
+ abi: fhetokenViewAbi,
1775
+ functionName: "underlying"
1776
+ });
1777
+ }
1778
+ async function ensureUnderlyingAllowance(params) {
1779
+ const tokenAddress = getAddress3(params.tokenAddress);
1780
+ const owner = getAddress3(params.owner);
1781
+ const spender = getAddress3(params.spender ?? tokenAddress);
1782
+ const publicClient = createPublicClient2({ transport: http2(params.rpcUrl) });
1783
+ const underlying = await publicClient.readContract({
1784
+ address: tokenAddress,
1785
+ abi: fhetokenViewAbi,
1786
+ functionName: "underlying"
1787
+ });
1788
+ const allowance = await publicClient.readContract({
1789
+ address: underlying,
1790
+ abi: erc20Abi,
1791
+ functionName: "allowance",
1792
+ args: [owner, spender]
1793
+ });
1794
+ if (allowance >= params.amount) {
1795
+ return { underlying, allowance, approved: false };
1796
+ }
1797
+ const txHash = await params.writeContract({
1798
+ address: underlying,
1799
+ abi: erc20Abi,
1800
+ functionName: "approve",
1801
+ args: [spender, params.amount]
1802
+ });
1803
+ if (params.waitForReceipt) {
1804
+ await params.waitForReceipt(txHash);
1805
+ }
1806
+ return { underlying, allowance, approved: true, txHash };
1807
+ }
1808
+
349
1809
  // src/token/transfer.ts
350
- import { createPublicClient, decodeEventLog, getAddress as getAddress2, http, isAddress, isHex, isAddressEqual } from "viem";
1810
+ import { createPublicClient as createPublicClient3, decodeEventLog as decodeEventLog2, getAddress as getAddress4, http as http3, isAddress, isHex, isAddressEqual } from "viem";
351
1811
  async function getTransferAmounts(options) {
352
1812
  if (!isAddress(options.tokenAddress)) {
353
1813
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
@@ -361,18 +1821,18 @@ async function getTransferAmounts(options) {
361
1821
  if (options.to && !isAddress(options.to)) {
362
1822
  throw new Error(`Invalid to address: ${options.to}`);
363
1823
  }
364
- const publicClient = createPublicClient({ transport: http(options.rpcUrl) });
1824
+ const publicClient = createPublicClient3({ transport: http3(options.rpcUrl) });
365
1825
  const receipt = await publicClient.getTransactionReceipt({
366
1826
  hash: options.txHash
367
1827
  });
368
- const tokenAddress = getAddress2(options.tokenAddress);
369
- const fromFilter = options.from ? getAddress2(options.from) : void 0;
370
- const toFilter = options.to ? getAddress2(options.to) : void 0;
371
- const logs = receipt.logs.filter((log) => getAddress2(log.address) === tokenAddress);
1828
+ const tokenAddress = getAddress4(options.tokenAddress);
1829
+ const fromFilter = options.from ? getAddress4(options.from) : void 0;
1830
+ const toFilter = options.to ? getAddress4(options.to) : void 0;
1831
+ const logs = receipt.logs.filter((log) => getAddress4(log.address) === tokenAddress);
372
1832
  const transfers = [];
373
1833
  for (const log of logs) {
374
1834
  try {
375
- const decoded = decodeEventLog({
1835
+ const decoded = decodeEventLog2({
376
1836
  abi: confidentialTokenAbi,
377
1837
  eventName: "ConfidentialPaymentExecuted",
378
1838
  data: log.data,
@@ -380,8 +1840,8 @@ async function getTransferAmounts(options) {
380
1840
  });
381
1841
  const args = decoded.args;
382
1842
  const entry = {
383
- holder: getAddress2(args.holder),
384
- payee: getAddress2(args.payee),
1843
+ holder: getAddress4(args.holder),
1844
+ payee: getAddress4(args.payee),
385
1845
  maxClearAmount: BigInt(args.maxClearAmount),
386
1846
  resourceHash: args.resourceHash,
387
1847
  nonce: args.nonce,
@@ -398,9 +1858,9 @@ async function getTransferAmounts(options) {
398
1858
  if (!options.signer) {
399
1859
  throw new Error("Missing signer for decryption");
400
1860
  }
401
- const signerAddress = getAddress2(options.signer.address);
402
- const holderAddress = getAddress2(entry.holder);
403
- const payeeAddress = getAddress2(entry.payee);
1861
+ const signerAddress = getAddress4(options.signer.address);
1862
+ const holderAddress = getAddress4(entry.holder);
1863
+ const payeeAddress = getAddress4(entry.payee);
404
1864
  if (!isAddressEqual(signerAddress, holderAddress) && !isAddressEqual(signerAddress, payeeAddress)) {
405
1865
  const [holderObserver, payeeObserver] = await Promise.all([
406
1866
  publicClient.readContract({
@@ -439,10 +1899,10 @@ async function getTransferAmounts(options) {
439
1899
  }
440
1900
 
441
1901
  // src/token/token.ts
442
- import { getAddress as getAddress5, isAddress as isAddress4 } from "viem";
1902
+ import { getAddress as getAddress7, isAddress as isAddress4 } from "viem";
443
1903
 
444
1904
  // src/token/balance.ts
445
- import { createPublicClient as createPublicClient2, getAddress as getAddress3, http as http2, isAddress as isAddress2, isAddressEqual as isAddressEqual2 } from "viem";
1905
+ import { createPublicClient as createPublicClient4, getAddress as getAddress5, http as http4, isAddress as isAddress2, isAddressEqual as isAddressEqual2 } from "viem";
446
1906
  var ZERO_HANDLE = "0x" + "00".repeat(32);
447
1907
  async function readBalance(options) {
448
1908
  if (!isAddress2(options.tokenAddress)) {
@@ -452,7 +1912,7 @@ async function readBalance(options) {
452
1912
  if (!account || !isAddress2(account)) {
453
1913
  throw new Error(`Invalid account address: ${account ?? "undefined"}`);
454
1914
  }
455
- const publicClient = createPublicClient2({ transport: http2(options.rpcUrl) });
1915
+ const publicClient = createPublicClient4({ transport: http4(options.rpcUrl) });
456
1916
  const confidentialBalanceAbi = [
457
1917
  {
458
1918
  inputs: [{ internalType: "address", name: "account", type: "address" }],
@@ -475,8 +1935,8 @@ async function readBalance(options) {
475
1935
  if (!options.signer) {
476
1936
  throw new Error("Missing signer for decryption");
477
1937
  }
478
- const signerAddress = getAddress3(options.signer.address);
479
- if (!isAddressEqual2(signerAddress, getAddress3(account))) {
1938
+ const signerAddress = getAddress5(options.signer.address);
1939
+ if (!isAddressEqual2(signerAddress, getAddress5(account))) {
480
1940
  const observer = await publicClient.readContract({
481
1941
  address: options.tokenAddress,
482
1942
  abi: confidentialTokenAbi,
@@ -495,7 +1955,7 @@ async function readBalance(options) {
495
1955
  }
496
1956
 
497
1957
  // src/token/observer.ts
498
- import { getAddress as getAddress4, isAddress as isAddress3 } from "viem";
1958
+ import { getAddress as getAddress6, isAddress as isAddress3 } from "viem";
499
1959
  async function setObserver(options) {
500
1960
  if (!isAddress3(options.tokenAddress)) {
501
1961
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
@@ -507,10 +1967,10 @@ async function setObserver(options) {
507
1967
  throw new Error(`Invalid observer address: ${options.observer}`);
508
1968
  }
509
1969
  return options.walletClient.writeContract({
510
- address: getAddress4(options.tokenAddress),
1970
+ address: getAddress6(options.tokenAddress),
511
1971
  abi: confidentialTokenAbi,
512
1972
  functionName: "setObserver",
513
- args: [getAddress4(options.account), getAddress4(options.observer)],
1973
+ args: [getAddress6(options.account), getAddress6(options.observer)],
514
1974
  chain: options.walletClient.chain ?? null,
515
1975
  account: options.signer ?? options.walletClient.account ?? null
516
1976
  });
@@ -521,7 +1981,7 @@ function assertAddress(value, label) {
521
1981
  if (!isAddress4(value)) {
522
1982
  throw new Error(`Invalid ${label}: ${value}`);
523
1983
  }
524
- return getAddress5(value);
1984
+ return getAddress7(value);
525
1985
  }
526
1986
  function resolveSignerAddress(signer, walletClient) {
527
1987
  if (signer?.address) {
@@ -681,11 +2141,16 @@ export {
681
2141
  createNonce,
682
2142
  createRelayer,
683
2143
  decryptEuint64,
2144
+ ensureUnderlyingAllowance,
684
2145
  getBrowserEthereumProvider,
685
2146
  getSepoliaConfig,
2147
+ getTokenEip712Domain,
686
2148
  getTransferAmounts,
2149
+ getUnderlyingTokenAddress,
2150
+ getUnwrapHandleFromLogs,
687
2151
  hashEncryptedAmountInput,
688
2152
  initSDK2 as initSDK,
689
2153
  normalizeAmount,
2154
+ prepareUnwrapAuthorization,
690
2155
  publicDecrypt
691
2156
  };