x402z-shared 0.0.15 → 0.1.0

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
+ }
916
+ ],
917
+ "name": "confidentialTransferWithAuthorization",
918
+ "outputs": [
919
+ {
920
+ "internalType": "euint64",
921
+ "name": "transferred",
922
+ "type": "bytes32"
923
+ }
924
+ ],
925
+ "stateMutability": "nonpayable",
926
+ "type": "function"
927
+ },
928
+ {
929
+ "inputs": [],
930
+ "name": "contractURI",
931
+ "outputs": [
932
+ {
933
+ "internalType": "string",
934
+ "name": "",
935
+ "type": "string"
936
+ }
8
937
  ],
9
- name: "confidentialTransfer",
10
- outputs: [{ internalType: "euint64", name: "transferred", type: "bytes32" }],
11
- stateMutability: "nonpayable",
12
- type: "function"
938
+ "stateMutability": "view",
939
+ "type": "function"
13
940
  },
14
941
  {
15
- inputs: [
942
+ "inputs": [],
943
+ "name": "decimals",
944
+ "outputs": [
16
945
  {
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"
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
 
@@ -284,8 +1517,252 @@ async function publicDecrypt(relayer, handles) {
284
1517
  };
285
1518
  }
286
1519
 
1520
+ // src/unwrap.ts
1521
+ import { createPublicClient, decodeEventLog, getAddress as getAddress2, http } from "viem";
1522
+ async function getTokenEip712Domain(params) {
1523
+ const tokenAddress = getAddress2(params.tokenAddress);
1524
+ const publicClient = createPublicClient({ transport: http(params.rpcUrl) });
1525
+ let name = params.fallbackName;
1526
+ let version = params.fallbackVersion;
1527
+ let chainId;
1528
+ let verifyingContract = tokenAddress;
1529
+ try {
1530
+ const domain = await publicClient.readContract({
1531
+ address: tokenAddress,
1532
+ abi: [
1533
+ {
1534
+ name: "eip712Domain",
1535
+ type: "function",
1536
+ stateMutability: "view",
1537
+ inputs: [],
1538
+ outputs: [
1539
+ { type: "bytes1" },
1540
+ { type: "string" },
1541
+ { type: "string" },
1542
+ { type: "uint256" },
1543
+ { type: "address" },
1544
+ { type: "bytes32" },
1545
+ { type: "uint256[]" }
1546
+ ]
1547
+ }
1548
+ ],
1549
+ functionName: "eip712Domain"
1550
+ });
1551
+ const [, domainName, domainVersion, domainChainId, domainVerifying] = domain;
1552
+ name = domainName || name;
1553
+ version = domainVersion || version;
1554
+ chainId = Number(domainChainId);
1555
+ verifyingContract = domainVerifying || verifyingContract;
1556
+ } catch {
1557
+ }
1558
+ if (!name || !version) {
1559
+ try {
1560
+ name = await publicClient.readContract({
1561
+ address: tokenAddress,
1562
+ abi: [{ name: "name", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] }],
1563
+ functionName: "name"
1564
+ });
1565
+ } catch {
1566
+ }
1567
+ try {
1568
+ version = await publicClient.readContract({
1569
+ address: tokenAddress,
1570
+ abi: [{ name: "version", type: "function", stateMutability: "view", inputs: [], outputs: [{ type: "string" }] }],
1571
+ functionName: "version"
1572
+ });
1573
+ } catch {
1574
+ }
1575
+ }
1576
+ if (!chainId) {
1577
+ chainId = await publicClient.getChainId();
1578
+ }
1579
+ if (!name || !version) {
1580
+ throw new Error("Missing EIP-712 name/version for unwrap authorization");
1581
+ }
1582
+ return {
1583
+ name,
1584
+ version,
1585
+ chainId,
1586
+ verifyingContract
1587
+ };
1588
+ }
1589
+ async function prepareUnwrapAuthorization(params) {
1590
+ const tokenAddress = getAddress2(params.tokenAddress);
1591
+ const holderAddress = getAddress2(params.signer.address);
1592
+ const callerAddress = getAddress2(params.callerAddress);
1593
+ const amount = Number(params.amount);
1594
+ if (!Number.isSafeInteger(amount)) {
1595
+ throw new Error("Unwrap amount must be a safe integer");
1596
+ }
1597
+ const now = Math.floor(Date.now() / 1e3);
1598
+ const validAfter = params.validAfter ?? now - 60;
1599
+ const validBefore = params.validBefore ?? now + 300;
1600
+ const nonce = params.nonce ?? createNonce();
1601
+ const { handle, inputProof } = await createEncryptedAmountInput(
1602
+ params.relayer,
1603
+ tokenAddress,
1604
+ callerAddress,
1605
+ amount
1606
+ );
1607
+ const authorization = {
1608
+ holder: holderAddress,
1609
+ to: callerAddress,
1610
+ validAfter,
1611
+ validBefore,
1612
+ nonce,
1613
+ encryptedAmountHash: hashEncryptedAmountInput(handle)
1614
+ };
1615
+ const types = {
1616
+ UnwrapAuthorization: [
1617
+ { name: "holder", type: "address" },
1618
+ { name: "to", type: "address" },
1619
+ { name: "validAfter", type: "uint48" },
1620
+ { name: "validBefore", type: "uint48" },
1621
+ { name: "nonce", type: "bytes32" },
1622
+ { name: "encryptedAmountHash", type: "bytes32" }
1623
+ ]
1624
+ };
1625
+ const message = {
1626
+ holder: authorization.holder,
1627
+ to: authorization.to,
1628
+ validAfter: BigInt(validAfter),
1629
+ validBefore: BigInt(validBefore),
1630
+ nonce: authorization.nonce,
1631
+ encryptedAmountHash: authorization.encryptedAmountHash
1632
+ };
1633
+ const sign = params.signer.signTypedData;
1634
+ const signature = sign.length >= 3 ? await sign(
1635
+ {
1636
+ name: params.domain.name,
1637
+ version: params.domain.version,
1638
+ chainId: params.domain.chainId,
1639
+ verifyingContract: params.domain.verifyingContract
1640
+ },
1641
+ types,
1642
+ message
1643
+ ) : await sign({
1644
+ domain: {
1645
+ name: params.domain.name,
1646
+ version: params.domain.version,
1647
+ chainId: params.domain.chainId,
1648
+ verifyingContract: params.domain.verifyingContract
1649
+ },
1650
+ types,
1651
+ primaryType: "UnwrapAuthorization",
1652
+ message
1653
+ });
1654
+ return {
1655
+ authorization,
1656
+ handle,
1657
+ inputProof,
1658
+ signature
1659
+ };
1660
+ }
1661
+ function getUnwrapHandleFromLogs(params) {
1662
+ const tokenAddress = getAddress2(params.tokenAddress).toLowerCase();
1663
+ for (const logEntry of params.logs) {
1664
+ if (!logEntry.address || logEntry.address.toLowerCase() !== tokenAddress) {
1665
+ continue;
1666
+ }
1667
+ try {
1668
+ if (logEntry.topics.length === 0) {
1669
+ continue;
1670
+ }
1671
+ const topics = [
1672
+ logEntry.topics[0],
1673
+ ...logEntry.topics.slice(1)
1674
+ ];
1675
+ const decoded = decodeEventLog({
1676
+ abi: confidentialTokenAbi,
1677
+ eventName: "UnwrapRequested",
1678
+ data: logEntry.data,
1679
+ topics
1680
+ });
1681
+ const args = decoded.args;
1682
+ if (args.amount) {
1683
+ return args.amount;
1684
+ }
1685
+ } catch {
1686
+ }
1687
+ }
1688
+ return params.fallbackHandle ?? null;
1689
+ }
1690
+
1691
+ // src/wrap.ts
1692
+ import { createPublicClient as createPublicClient2, getAddress as getAddress3, http as http2 } from "viem";
1693
+ var fhetokenViewAbi = [
1694
+ {
1695
+ inputs: [],
1696
+ name: "underlying",
1697
+ outputs: [{ internalType: "address", name: "", type: "address" }],
1698
+ stateMutability: "view",
1699
+ type: "function"
1700
+ }
1701
+ ];
1702
+ var erc20Abi = [
1703
+ {
1704
+ inputs: [
1705
+ { internalType: "address", name: "owner", type: "address" },
1706
+ { internalType: "address", name: "spender", type: "address" }
1707
+ ],
1708
+ name: "allowance",
1709
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
1710
+ stateMutability: "view",
1711
+ type: "function"
1712
+ },
1713
+ {
1714
+ inputs: [
1715
+ { internalType: "address", name: "spender", type: "address" },
1716
+ { internalType: "uint256", name: "amount", type: "uint256" }
1717
+ ],
1718
+ name: "approve",
1719
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
1720
+ stateMutability: "nonpayable",
1721
+ type: "function"
1722
+ }
1723
+ ];
1724
+ async function getUnderlyingTokenAddress(params) {
1725
+ const tokenAddress = getAddress3(params.tokenAddress);
1726
+ const publicClient = createPublicClient2({ transport: http2(params.rpcUrl) });
1727
+ return publicClient.readContract({
1728
+ address: tokenAddress,
1729
+ abi: fhetokenViewAbi,
1730
+ functionName: "underlying"
1731
+ });
1732
+ }
1733
+ async function ensureUnderlyingAllowance(params) {
1734
+ const tokenAddress = getAddress3(params.tokenAddress);
1735
+ const owner = getAddress3(params.owner);
1736
+ const spender = getAddress3(params.spender ?? tokenAddress);
1737
+ const publicClient = createPublicClient2({ transport: http2(params.rpcUrl) });
1738
+ const underlying = await publicClient.readContract({
1739
+ address: tokenAddress,
1740
+ abi: fhetokenViewAbi,
1741
+ functionName: "underlying"
1742
+ });
1743
+ const allowance = await publicClient.readContract({
1744
+ address: underlying,
1745
+ abi: erc20Abi,
1746
+ functionName: "allowance",
1747
+ args: [owner, spender]
1748
+ });
1749
+ if (allowance >= params.amount) {
1750
+ return { underlying, allowance, approved: false };
1751
+ }
1752
+ const txHash = await params.writeContract({
1753
+ address: underlying,
1754
+ abi: erc20Abi,
1755
+ functionName: "approve",
1756
+ args: [spender, params.amount]
1757
+ });
1758
+ if (params.waitForReceipt) {
1759
+ await params.waitForReceipt(txHash);
1760
+ }
1761
+ return { underlying, allowance, approved: true, txHash };
1762
+ }
1763
+
287
1764
  // src/token/transfer.ts
288
- import { createPublicClient, decodeEventLog, getAddress as getAddress2, http, isAddress, isHex, isAddressEqual } from "viem";
1765
+ import { createPublicClient as createPublicClient3, decodeEventLog as decodeEventLog2, getAddress as getAddress4, http as http3, isAddress, isHex, isAddressEqual } from "viem";
289
1766
  async function getTransferAmounts(options) {
290
1767
  if (!isAddress(options.tokenAddress)) {
291
1768
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
@@ -299,18 +1776,18 @@ async function getTransferAmounts(options) {
299
1776
  if (options.to && !isAddress(options.to)) {
300
1777
  throw new Error(`Invalid to address: ${options.to}`);
301
1778
  }
302
- const publicClient = createPublicClient({ transport: http(options.rpcUrl) });
1779
+ const publicClient = createPublicClient3({ transport: http3(options.rpcUrl) });
303
1780
  const receipt = await publicClient.getTransactionReceipt({
304
1781
  hash: options.txHash
305
1782
  });
306
- const tokenAddress = getAddress2(options.tokenAddress);
307
- const fromFilter = options.from ? getAddress2(options.from) : void 0;
308
- const toFilter = options.to ? getAddress2(options.to) : void 0;
309
- const logs = receipt.logs.filter((log) => getAddress2(log.address) === tokenAddress);
1783
+ const tokenAddress = getAddress4(options.tokenAddress);
1784
+ const fromFilter = options.from ? getAddress4(options.from) : void 0;
1785
+ const toFilter = options.to ? getAddress4(options.to) : void 0;
1786
+ const logs = receipt.logs.filter((log) => getAddress4(log.address) === tokenAddress);
310
1787
  const transfers = [];
311
1788
  for (const log of logs) {
312
1789
  try {
313
- const decoded = decodeEventLog({
1790
+ const decoded = decodeEventLog2({
314
1791
  abi: confidentialTokenAbi,
315
1792
  eventName: "ConfidentialPaymentExecuted",
316
1793
  data: log.data,
@@ -318,8 +1795,8 @@ async function getTransferAmounts(options) {
318
1795
  });
319
1796
  const args = decoded.args;
320
1797
  const entry = {
321
- holder: getAddress2(args.holder),
322
- payee: getAddress2(args.payee),
1798
+ holder: getAddress4(args.holder),
1799
+ payee: getAddress4(args.payee),
323
1800
  maxClearAmount: BigInt(args.maxClearAmount),
324
1801
  resourceHash: args.resourceHash,
325
1802
  nonce: args.nonce,
@@ -336,9 +1813,9 @@ async function getTransferAmounts(options) {
336
1813
  if (!options.signer) {
337
1814
  throw new Error("Missing signer for decryption");
338
1815
  }
339
- const signerAddress = getAddress2(options.signer.address);
340
- const holderAddress = getAddress2(entry.holder);
341
- const payeeAddress = getAddress2(entry.payee);
1816
+ const signerAddress = getAddress4(options.signer.address);
1817
+ const holderAddress = getAddress4(entry.holder);
1818
+ const payeeAddress = getAddress4(entry.payee);
342
1819
  if (!isAddressEqual(signerAddress, holderAddress) && !isAddressEqual(signerAddress, payeeAddress)) {
343
1820
  const [holderObserver, payeeObserver] = await Promise.all([
344
1821
  publicClient.readContract({
@@ -377,10 +1854,10 @@ async function getTransferAmounts(options) {
377
1854
  }
378
1855
 
379
1856
  // src/token/token.ts
380
- import { getAddress as getAddress5, isAddress as isAddress4 } from "viem";
1857
+ import { getAddress as getAddress7, isAddress as isAddress4 } from "viem";
381
1858
 
382
1859
  // src/token/balance.ts
383
- import { createPublicClient as createPublicClient2, getAddress as getAddress3, http as http2, isAddress as isAddress2, isAddressEqual as isAddressEqual2 } from "viem";
1860
+ import { createPublicClient as createPublicClient4, getAddress as getAddress5, http as http4, isAddress as isAddress2, isAddressEqual as isAddressEqual2 } from "viem";
384
1861
  var ZERO_HANDLE = "0x" + "00".repeat(32);
385
1862
  async function readBalance(options) {
386
1863
  if (!isAddress2(options.tokenAddress)) {
@@ -390,7 +1867,7 @@ async function readBalance(options) {
390
1867
  if (!account || !isAddress2(account)) {
391
1868
  throw new Error(`Invalid account address: ${account ?? "undefined"}`);
392
1869
  }
393
- const publicClient = createPublicClient2({ transport: http2(options.rpcUrl) });
1870
+ const publicClient = createPublicClient4({ transport: http4(options.rpcUrl) });
394
1871
  const confidentialBalanceAbi = [
395
1872
  {
396
1873
  inputs: [{ internalType: "address", name: "account", type: "address" }],
@@ -413,8 +1890,8 @@ async function readBalance(options) {
413
1890
  if (!options.signer) {
414
1891
  throw new Error("Missing signer for decryption");
415
1892
  }
416
- const signerAddress = getAddress3(options.signer.address);
417
- if (!isAddressEqual2(signerAddress, getAddress3(account))) {
1893
+ const signerAddress = getAddress5(options.signer.address);
1894
+ if (!isAddressEqual2(signerAddress, getAddress5(account))) {
418
1895
  const observer = await publicClient.readContract({
419
1896
  address: options.tokenAddress,
420
1897
  abi: confidentialTokenAbi,
@@ -438,7 +1915,7 @@ async function readBalance(options) {
438
1915
  }
439
1916
 
440
1917
  // src/token/observer.ts
441
- import { createPublicClient as createPublicClient3, getAddress as getAddress4, http as http3, isAddress as isAddress3 } from "viem";
1918
+ import { createPublicClient as createPublicClient5, getAddress as getAddress6, http as http5, isAddress as isAddress3 } from "viem";
442
1919
  async function setObserver(options) {
443
1920
  if (!isAddress3(options.tokenAddress)) {
444
1921
  throw new Error(`Invalid token address: ${options.tokenAddress}`);
@@ -449,17 +1926,17 @@ async function setObserver(options) {
449
1926
  if (!isAddress3(options.observer)) {
450
1927
  throw new Error(`Invalid observer address: ${options.observer}`);
451
1928
  }
452
- const tokenAddress = getAddress4(options.tokenAddress);
453
- const account = getAddress4(options.account);
454
- const observer = getAddress4(options.observer);
455
- const publicClient = createPublicClient3({ transport: http3(options.rpcUrl) });
1929
+ const tokenAddress = getAddress6(options.tokenAddress);
1930
+ const account = getAddress6(options.account);
1931
+ const observer = getAddress6(options.observer);
1932
+ const publicClient = createPublicClient5({ transport: http5(options.rpcUrl) });
456
1933
  const existing = await publicClient.readContract({
457
1934
  address: tokenAddress,
458
1935
  abi: confidentialTokenAbi,
459
1936
  functionName: "observer",
460
1937
  args: [account]
461
1938
  });
462
- if (existing && isAddress3(existing) && getAddress4(existing) === observer) {
1939
+ if (existing && isAddress3(existing) && getAddress6(existing) === observer) {
463
1940
  return "0x" + "00".repeat(32);
464
1941
  }
465
1942
  return options.signer.writeContract({
@@ -475,7 +1952,7 @@ function assertAddress(value, label) {
475
1952
  if (!isAddress4(value)) {
476
1953
  throw new Error(`Invalid ${label}: ${value}`);
477
1954
  }
478
- return getAddress5(value);
1955
+ return getAddress7(value);
479
1956
  }
480
1957
  function requireWriteContract(signer) {
481
1958
  if (!signer.writeContract) {
@@ -612,8 +2089,13 @@ export {
612
2089
  createNonce,
613
2090
  createRelayer,
614
2091
  decryptEuint64,
2092
+ ensureUnderlyingAllowance,
2093
+ getTokenEip712Domain,
615
2094
  getTransferAmounts,
2095
+ getUnderlyingTokenAddress,
2096
+ getUnwrapHandleFromLogs,
616
2097
  hashEncryptedAmountInput,
617
2098
  normalizeAmount,
2099
+ prepareUnwrapAuthorization,
618
2100
  publicDecrypt
619
2101
  };