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