@talismn/on-chain-id 0.1.0 → 0.1.2

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.
@@ -1,10 +1,11 @@
1
- import { StorageHelper, RpcStateQueryHelper } from '@talismn/balances';
2
- import { decodeAnyAddress, isEthereumAddress } from '@talismn/util';
1
+ import { isEthereumAddress, throwAfter } from '@talismn/util';
3
2
  import anylogger from 'anylogger';
3
+ import { Abi } from '@polkadot/api-contract';
4
+ import { u8aToHex, u8aConcatStrict } from '@polkadot/util';
4
5
 
5
6
  var packageJson = {
6
7
  name: "@talismn/on-chain-id",
7
- version: "0.1.0",
8
+ version: "0.1.2",
8
9
  author: "Talisman",
9
10
  homepage: "https://talisman.xyz",
10
11
  license: "GPL-3.0-or-later",
@@ -27,7 +28,7 @@ var packageJson = {
27
28
  scripts: {
28
29
  test: "jest",
29
30
  lint: "eslint src --max-warnings 0",
30
- clean: "rm -rf dist && rm -rf .turbo rm -rf node_modules"
31
+ clean: "rm -rf dist .turbo node_modules"
31
32
  },
32
33
  dependencies: {
33
34
  "@talismn/balances": "workspace:*",
@@ -35,17 +36,23 @@ var packageJson = {
35
36
  anylogger: "^1.0.11"
36
37
  },
37
38
  devDependencies: {
38
- "@polkadot/types": "^10.9.1",
39
+ "@polkadot/api-contract": "15.8.1",
40
+ "@polkadot/rpc-provider": "15.8.1",
41
+ "@polkadot/types": "15.8.1",
42
+ "@polkadot/util": "13.4.3",
39
43
  "@talismn/eslint-config": "workspace:*",
40
44
  "@talismn/tsconfig": "workspace:*",
41
- "@types/jest": "^27.5.1",
42
- eslint: "^8.52.0",
45
+ "@types/jest": "^29.5.14",
46
+ eslint: "^8.57.1",
43
47
  jest: "^29.7.0",
44
- "ts-jest": "^29.1.1",
45
- typescript: "^5.2.2"
48
+ "ts-jest": "^29.2.5",
49
+ typescript: "^5.6.3"
46
50
  },
47
51
  peerDependencies: {
48
- "@polkadot/types": "10.x"
52
+ "@polkadot/api-contract": "*",
53
+ "@polkadot/rpc-provider": "*",
54
+ "@polkadot/types": "*",
55
+ "@polkadot/util": "*"
49
56
  },
50
57
  eslintConfig: {
51
58
  root: true,
@@ -57,150 +64,1539 @@ var packageJson = {
57
64
 
58
65
  var log = anylogger(packageJson.name);
59
66
 
60
- const isPotentialEns = name => typeof name === "string" && /^.+\..+$/.test(name);
61
-
62
- class OnChainId {
63
- constructor(
64
- // TODO: Create a package for `/apps/extension/src/core/util/getTypeRegistry.ts` which
65
- // can be used from outside of the wallet.
66
- polkadotRegistry, chainConnectors, chainIdPolkadot = "polkadot", networkIdEthereum = "1") {
67
- this.polkadotRegistry = polkadotRegistry;
68
- this.chainConnectors = chainConnectors;
69
- this.chainIdPolkadot = chainIdPolkadot;
70
- this.networkIdEthereum = networkIdEthereum;
71
- }
67
+ var aznsRouterAbiJson = {
68
+ source: {
69
+ hash: "0x63308c1311af44bb47082327c301fce559ca28f6bb010a61b9884d9246746abf",
70
+ language: "ink! 4.2.1",
71
+ compiler: "rustc 1.68.0-nightly",
72
+ build_info: {
73
+ build_mode: "Release",
74
+ cargo_contract_version: "3.0.1",
75
+ rust_toolchain: "nightly-aarch64-apple-darwin",
76
+ wasm_opt_settings: {
77
+ keep_debug_symbols: false,
78
+ optimization_passes: "Z"
79
+ }
80
+ }
81
+ },
82
+ contract: {
83
+ name: "azns_router",
84
+ version: "1.0.0",
85
+ authors: [
86
+ "AZERO.ID <hello@azero.id>"
87
+ ]
88
+ },
89
+ spec: {
90
+ constructors: [
91
+ {
92
+ args: [
93
+ {
94
+ label: "admin",
95
+ type: {
96
+ displayName: [
97
+ "AccountId"
98
+ ],
99
+ type: 0
100
+ }
101
+ }
102
+ ],
103
+ "default": false,
104
+ docs: [
105
+ ],
106
+ label: "new",
107
+ payable: false,
108
+ returnType: {
109
+ displayName: [
110
+ "ink_primitives",
111
+ "ConstructorResult"
112
+ ],
113
+ type: 6
114
+ },
115
+ selector: "0x9bae9d5e"
116
+ }
117
+ ],
118
+ docs: [
119
+ ],
120
+ environment: {
121
+ accountId: {
122
+ displayName: [
123
+ "AccountId"
124
+ ],
125
+ type: 0
126
+ },
127
+ balance: {
128
+ displayName: [
129
+ "Balance"
130
+ ],
131
+ type: 25
132
+ },
133
+ blockNumber: {
134
+ displayName: [
135
+ "BlockNumber"
136
+ ],
137
+ type: 28
138
+ },
139
+ chainExtension: {
140
+ displayName: [
141
+ "ChainExtension"
142
+ ],
143
+ type: 29
144
+ },
145
+ hash: {
146
+ displayName: [
147
+ "Hash"
148
+ ],
149
+ type: 26
150
+ },
151
+ maxEventTopics: 4,
152
+ timestamp: {
153
+ displayName: [
154
+ "Timestamp"
155
+ ],
156
+ type: 27
157
+ }
158
+ },
159
+ events: [
160
+ ],
161
+ lang_error: {
162
+ displayName: [
163
+ "ink",
164
+ "LangError"
165
+ ],
166
+ type: 8
167
+ },
168
+ messages: [
169
+ {
170
+ args: [
171
+ {
172
+ label: "tld",
173
+ type: {
174
+ displayName: [
175
+ "Vec"
176
+ ],
177
+ type: 4
178
+ }
179
+ },
180
+ {
181
+ label: "registry_addr",
182
+ type: {
183
+ displayName: [
184
+ "AccountId"
185
+ ],
186
+ type: 0
187
+ }
188
+ }
189
+ ],
190
+ "default": false,
191
+ docs: [
192
+ ],
193
+ label: "add_registry",
194
+ mutates: true,
195
+ payable: false,
196
+ returnType: {
197
+ displayName: [
198
+ "ink",
199
+ "MessageResult"
200
+ ],
201
+ type: 9
202
+ },
203
+ selector: "0xc997efe3"
204
+ },
205
+ {
206
+ args: [
207
+ {
208
+ label: "tld",
209
+ type: {
210
+ displayName: [
211
+ "Vec"
212
+ ],
213
+ type: 4
214
+ }
215
+ },
216
+ {
217
+ label: "registry_addr",
218
+ type: {
219
+ displayName: [
220
+ "AccountId"
221
+ ],
222
+ type: 0
223
+ }
224
+ }
225
+ ],
226
+ "default": false,
227
+ docs: [
228
+ ],
229
+ label: "update_registry",
230
+ mutates: true,
231
+ payable: false,
232
+ returnType: {
233
+ displayName: [
234
+ "ink",
235
+ "MessageResult"
236
+ ],
237
+ type: 9
238
+ },
239
+ selector: "0x562de86b"
240
+ },
241
+ {
242
+ args: [
243
+ {
244
+ label: "registry_addr",
245
+ type: {
246
+ displayName: [
247
+ "AccountId"
248
+ ],
249
+ type: 0
250
+ }
251
+ }
252
+ ],
253
+ "default": false,
254
+ docs: [
255
+ ],
256
+ label: "remove_registry_address",
257
+ mutates: true,
258
+ payable: false,
259
+ returnType: {
260
+ displayName: [
261
+ "ink",
262
+ "MessageResult"
263
+ ],
264
+ type: 9
265
+ },
266
+ selector: "0xcc78aead"
267
+ },
268
+ {
269
+ args: [
270
+ ],
271
+ "default": false,
272
+ docs: [
273
+ ],
274
+ label: "get_all_registries",
275
+ mutates: false,
276
+ payable: false,
277
+ returnType: {
278
+ displayName: [
279
+ "ink",
280
+ "MessageResult"
281
+ ],
282
+ type: 12
283
+ },
284
+ selector: "0xe6da7bf0"
285
+ },
286
+ {
287
+ args: [
288
+ ],
289
+ "default": false,
290
+ docs: [
291
+ ],
292
+ label: "get_all_tlds",
293
+ mutates: false,
294
+ payable: false,
295
+ returnType: {
296
+ displayName: [
297
+ "ink",
298
+ "MessageResult"
299
+ ],
300
+ type: 15
301
+ },
302
+ selector: "0xf1a7af41"
303
+ },
304
+ {
305
+ args: [
306
+ {
307
+ label: "registry_addr",
308
+ type: {
309
+ displayName: [
310
+ "AccountId"
311
+ ],
312
+ type: 0
313
+ }
314
+ }
315
+ ],
316
+ "default": false,
317
+ docs: [
318
+ ],
319
+ label: "get_associated_tlds",
320
+ mutates: false,
321
+ payable: false,
322
+ returnType: {
323
+ displayName: [
324
+ "ink",
325
+ "MessageResult"
326
+ ],
327
+ type: 15
328
+ },
329
+ selector: "0xcb18f821"
330
+ },
331
+ {
332
+ args: [
333
+ {
334
+ label: "tld",
335
+ type: {
336
+ displayName: [
337
+ "String"
338
+ ],
339
+ type: 5
340
+ }
341
+ }
342
+ ],
343
+ "default": false,
344
+ docs: [
345
+ ],
346
+ label: "get_registry",
347
+ mutates: false,
348
+ payable: false,
349
+ returnType: {
350
+ displayName: [
351
+ "ink",
352
+ "MessageResult"
353
+ ],
354
+ type: 16
355
+ },
356
+ selector: "0x15a5d20a"
357
+ },
358
+ {
359
+ args: [
360
+ {
361
+ label: "domain",
362
+ type: {
363
+ displayName: [
364
+ "String"
365
+ ],
366
+ type: 5
367
+ }
368
+ }
369
+ ],
370
+ "default": false,
371
+ docs: [
372
+ ],
373
+ label: "get_address",
374
+ mutates: false,
375
+ payable: false,
376
+ returnType: {
377
+ displayName: [
378
+ "ink",
379
+ "MessageResult"
380
+ ],
381
+ type: 18
382
+ },
383
+ selector: "0xd259f7ba"
384
+ },
385
+ {
386
+ args: [
387
+ {
388
+ label: "account",
389
+ type: {
390
+ displayName: [
391
+ "AccountId"
392
+ ],
393
+ type: 0
394
+ }
395
+ },
396
+ {
397
+ label: "tld",
398
+ type: {
399
+ displayName: [
400
+ "Option"
401
+ ],
402
+ type: 20
403
+ }
404
+ }
405
+ ],
406
+ "default": false,
407
+ docs: [
408
+ " @returns list of (registry-address, primary-domain) for given account"
409
+ ],
410
+ label: "get_primary_domains",
411
+ mutates: false,
412
+ payable: false,
413
+ returnType: {
414
+ displayName: [
415
+ "ink",
416
+ "MessageResult"
417
+ ],
418
+ type: 21
419
+ },
420
+ selector: "0xdf3a358e"
421
+ },
422
+ {
423
+ args: [
424
+ ],
425
+ "default": false,
426
+ docs: [
427
+ ],
428
+ label: "get_admin",
429
+ mutates: false,
430
+ payable: false,
431
+ returnType: {
432
+ displayName: [
433
+ "ink",
434
+ "MessageResult"
435
+ ],
436
+ type: 24
437
+ },
438
+ selector: "0x57b8a8a7"
439
+ },
440
+ {
441
+ args: [
442
+ ],
443
+ "default": false,
444
+ docs: [
445
+ ],
446
+ label: "get_pending_admin",
447
+ mutates: false,
448
+ payable: false,
449
+ returnType: {
450
+ displayName: [
451
+ "ink",
452
+ "MessageResult"
453
+ ],
454
+ type: 16
455
+ },
456
+ selector: "0xbcd31d76"
457
+ },
458
+ {
459
+ args: [
460
+ {
461
+ label: "account",
462
+ type: {
463
+ displayName: [
464
+ "Option"
465
+ ],
466
+ type: 17
467
+ }
468
+ }
469
+ ],
470
+ "default": false,
471
+ docs: [
472
+ ],
473
+ label: "transfer_ownership",
474
+ mutates: true,
475
+ payable: false,
476
+ returnType: {
477
+ displayName: [
478
+ "ink",
479
+ "MessageResult"
480
+ ],
481
+ type: 9
482
+ },
483
+ selector: "0x107e33ea"
484
+ },
485
+ {
486
+ args: [
487
+ ],
488
+ "default": false,
489
+ docs: [
490
+ ],
491
+ label: "accept_ownership",
492
+ mutates: true,
493
+ payable: false,
494
+ returnType: {
495
+ displayName: [
496
+ "ink",
497
+ "MessageResult"
498
+ ],
499
+ type: 9
500
+ },
501
+ selector: "0xb55be9f0"
502
+ },
503
+ {
504
+ args: [
505
+ {
506
+ label: "code_hash",
507
+ type: {
508
+ displayName: [
509
+ ],
510
+ type: 1
511
+ }
512
+ }
513
+ ],
514
+ "default": false,
515
+ docs: [
516
+ ],
517
+ label: "upgrade_contract",
518
+ mutates: true,
519
+ payable: false,
520
+ returnType: {
521
+ displayName: [
522
+ "ink",
523
+ "MessageResult"
524
+ ],
525
+ type: 6
526
+ },
527
+ selector: "0x1345543d"
528
+ }
529
+ ]
530
+ },
531
+ storage: {
532
+ root: {
533
+ layout: {
534
+ struct: {
535
+ fields: [
536
+ {
537
+ layout: {
538
+ leaf: {
539
+ key: "0x00000000",
540
+ ty: 0
541
+ }
542
+ },
543
+ name: "admin"
544
+ },
545
+ {
546
+ layout: {
547
+ "enum": {
548
+ dispatchKey: "0x00000000",
549
+ name: "Option",
550
+ variants: {
551
+ "0": {
552
+ fields: [
553
+ ],
554
+ name: "None"
555
+ },
556
+ "1": {
557
+ fields: [
558
+ {
559
+ layout: {
560
+ leaf: {
561
+ key: "0x00000000",
562
+ ty: 0
563
+ }
564
+ },
565
+ name: "0"
566
+ }
567
+ ],
568
+ name: "Some"
569
+ }
570
+ }
571
+ }
572
+ },
573
+ name: "pending_admin"
574
+ },
575
+ {
576
+ layout: {
577
+ leaf: {
578
+ key: "0x00000000",
579
+ ty: 3
580
+ }
581
+ },
582
+ name: "registry"
583
+ },
584
+ {
585
+ layout: {
586
+ root: {
587
+ layout: {
588
+ leaf: {
589
+ key: "0x00000064",
590
+ ty: 0
591
+ }
592
+ },
593
+ root_key: "0x00000064"
594
+ }
595
+ },
596
+ name: "routes"
597
+ },
598
+ {
599
+ layout: {
600
+ root: {
601
+ layout: {
602
+ leaf: {
603
+ key: "0x00000065",
604
+ ty: 4
605
+ }
606
+ },
607
+ root_key: "0x00000065"
608
+ }
609
+ },
610
+ name: "associated_tlds"
611
+ }
612
+ ],
613
+ name: "Router"
614
+ }
615
+ },
616
+ root_key: "0x00000000"
617
+ }
618
+ },
619
+ types: [
620
+ {
621
+ id: 0,
622
+ type: {
623
+ def: {
624
+ composite: {
625
+ fields: [
626
+ {
627
+ type: 1,
628
+ typeName: "[u8; 32]"
629
+ }
630
+ ]
631
+ }
632
+ },
633
+ path: [
634
+ "ink_primitives",
635
+ "types",
636
+ "AccountId"
637
+ ]
638
+ }
639
+ },
640
+ {
641
+ id: 1,
642
+ type: {
643
+ def: {
644
+ array: {
645
+ len: 32,
646
+ type: 2
647
+ }
648
+ }
649
+ }
650
+ },
651
+ {
652
+ id: 2,
653
+ type: {
654
+ def: {
655
+ primitive: "u8"
656
+ }
657
+ }
658
+ },
659
+ {
660
+ id: 3,
661
+ type: {
662
+ def: {
663
+ sequence: {
664
+ type: 0
665
+ }
666
+ }
667
+ }
668
+ },
669
+ {
670
+ id: 4,
671
+ type: {
672
+ def: {
673
+ sequence: {
674
+ type: 5
675
+ }
676
+ }
677
+ }
678
+ },
679
+ {
680
+ id: 5,
681
+ type: {
682
+ def: {
683
+ primitive: "str"
684
+ }
685
+ }
686
+ },
687
+ {
688
+ id: 6,
689
+ type: {
690
+ def: {
691
+ variant: {
692
+ variants: [
693
+ {
694
+ fields: [
695
+ {
696
+ type: 7
697
+ }
698
+ ],
699
+ index: 0,
700
+ name: "Ok"
701
+ },
702
+ {
703
+ fields: [
704
+ {
705
+ type: 8
706
+ }
707
+ ],
708
+ index: 1,
709
+ name: "Err"
710
+ }
711
+ ]
712
+ }
713
+ },
714
+ params: [
715
+ {
716
+ name: "T",
717
+ type: 7
718
+ },
719
+ {
720
+ name: "E",
721
+ type: 8
722
+ }
723
+ ],
724
+ path: [
725
+ "Result"
726
+ ]
727
+ }
728
+ },
729
+ {
730
+ id: 7,
731
+ type: {
732
+ def: {
733
+ tuple: [
734
+ ]
735
+ }
736
+ }
737
+ },
738
+ {
739
+ id: 8,
740
+ type: {
741
+ def: {
742
+ variant: {
743
+ variants: [
744
+ {
745
+ index: 1,
746
+ name: "CouldNotReadInput"
747
+ }
748
+ ]
749
+ }
750
+ },
751
+ path: [
752
+ "ink_primitives",
753
+ "LangError"
754
+ ]
755
+ }
756
+ },
757
+ {
758
+ id: 9,
759
+ type: {
760
+ def: {
761
+ variant: {
762
+ variants: [
763
+ {
764
+ fields: [
765
+ {
766
+ type: 10
767
+ }
768
+ ],
769
+ index: 0,
770
+ name: "Ok"
771
+ },
772
+ {
773
+ fields: [
774
+ {
775
+ type: 8
776
+ }
777
+ ],
778
+ index: 1,
779
+ name: "Err"
780
+ }
781
+ ]
782
+ }
783
+ },
784
+ params: [
785
+ {
786
+ name: "T",
787
+ type: 10
788
+ },
789
+ {
790
+ name: "E",
791
+ type: 8
792
+ }
793
+ ],
794
+ path: [
795
+ "Result"
796
+ ]
797
+ }
798
+ },
799
+ {
800
+ id: 10,
801
+ type: {
802
+ def: {
803
+ variant: {
804
+ variants: [
805
+ {
806
+ fields: [
807
+ {
808
+ type: 7
809
+ }
810
+ ],
811
+ index: 0,
812
+ name: "Ok"
813
+ },
814
+ {
815
+ fields: [
816
+ {
817
+ type: 11
818
+ }
819
+ ],
820
+ index: 1,
821
+ name: "Err"
822
+ }
823
+ ]
824
+ }
825
+ },
826
+ params: [
827
+ {
828
+ name: "T",
829
+ type: 7
830
+ },
831
+ {
832
+ name: "E",
833
+ type: 11
834
+ }
835
+ ],
836
+ path: [
837
+ "Result"
838
+ ]
839
+ }
840
+ },
841
+ {
842
+ id: 11,
843
+ type: {
844
+ def: {
845
+ variant: {
846
+ variants: [
847
+ {
848
+ index: 0,
849
+ name: "NotAdmin"
850
+ },
851
+ {
852
+ index: 1,
853
+ name: "InvalidRegistryAddress"
854
+ },
855
+ {
856
+ fields: [
857
+ {
858
+ type: 5,
859
+ typeName: "String"
860
+ }
861
+ ],
862
+ index: 2,
863
+ name: "TldAlreadyInUse"
864
+ },
865
+ {
866
+ fields: [
867
+ {
868
+ type: 5,
869
+ typeName: "String"
870
+ }
871
+ ],
872
+ index: 3,
873
+ name: "TldNotFound"
874
+ },
875
+ {
876
+ index: 4,
877
+ name: "CouldNotResolveDomain"
878
+ },
879
+ {
880
+ index: 5,
881
+ name: "InvalidDomainName"
882
+ },
883
+ {
884
+ index: 6,
885
+ name: "EmptyList"
886
+ }
887
+ ]
888
+ }
889
+ },
890
+ path: [
891
+ "azns_router",
892
+ "azns_router",
893
+ "Error"
894
+ ]
895
+ }
896
+ },
897
+ {
898
+ id: 12,
899
+ type: {
900
+ def: {
901
+ variant: {
902
+ variants: [
903
+ {
904
+ fields: [
905
+ {
906
+ type: 13
907
+ }
908
+ ],
909
+ index: 0,
910
+ name: "Ok"
911
+ },
912
+ {
913
+ fields: [
914
+ {
915
+ type: 8
916
+ }
917
+ ],
918
+ index: 1,
919
+ name: "Err"
920
+ }
921
+ ]
922
+ }
923
+ },
924
+ params: [
925
+ {
926
+ name: "T",
927
+ type: 13
928
+ },
929
+ {
930
+ name: "E",
931
+ type: 8
932
+ }
933
+ ],
934
+ path: [
935
+ "Result"
936
+ ]
937
+ }
938
+ },
939
+ {
940
+ id: 13,
941
+ type: {
942
+ def: {
943
+ sequence: {
944
+ type: 14
945
+ }
946
+ }
947
+ }
948
+ },
949
+ {
950
+ id: 14,
951
+ type: {
952
+ def: {
953
+ tuple: [
954
+ 0,
955
+ 4
956
+ ]
957
+ }
958
+ }
959
+ },
960
+ {
961
+ id: 15,
962
+ type: {
963
+ def: {
964
+ variant: {
965
+ variants: [
966
+ {
967
+ fields: [
968
+ {
969
+ type: 4
970
+ }
971
+ ],
972
+ index: 0,
973
+ name: "Ok"
974
+ },
975
+ {
976
+ fields: [
977
+ {
978
+ type: 8
979
+ }
980
+ ],
981
+ index: 1,
982
+ name: "Err"
983
+ }
984
+ ]
985
+ }
986
+ },
987
+ params: [
988
+ {
989
+ name: "T",
990
+ type: 4
991
+ },
992
+ {
993
+ name: "E",
994
+ type: 8
995
+ }
996
+ ],
997
+ path: [
998
+ "Result"
999
+ ]
1000
+ }
1001
+ },
1002
+ {
1003
+ id: 16,
1004
+ type: {
1005
+ def: {
1006
+ variant: {
1007
+ variants: [
1008
+ {
1009
+ fields: [
1010
+ {
1011
+ type: 17
1012
+ }
1013
+ ],
1014
+ index: 0,
1015
+ name: "Ok"
1016
+ },
1017
+ {
1018
+ fields: [
1019
+ {
1020
+ type: 8
1021
+ }
1022
+ ],
1023
+ index: 1,
1024
+ name: "Err"
1025
+ }
1026
+ ]
1027
+ }
1028
+ },
1029
+ params: [
1030
+ {
1031
+ name: "T",
1032
+ type: 17
1033
+ },
1034
+ {
1035
+ name: "E",
1036
+ type: 8
1037
+ }
1038
+ ],
1039
+ path: [
1040
+ "Result"
1041
+ ]
1042
+ }
1043
+ },
1044
+ {
1045
+ id: 17,
1046
+ type: {
1047
+ def: {
1048
+ variant: {
1049
+ variants: [
1050
+ {
1051
+ index: 0,
1052
+ name: "None"
1053
+ },
1054
+ {
1055
+ fields: [
1056
+ {
1057
+ type: 0
1058
+ }
1059
+ ],
1060
+ index: 1,
1061
+ name: "Some"
1062
+ }
1063
+ ]
1064
+ }
1065
+ },
1066
+ params: [
1067
+ {
1068
+ name: "T",
1069
+ type: 0
1070
+ }
1071
+ ],
1072
+ path: [
1073
+ "Option"
1074
+ ]
1075
+ }
1076
+ },
1077
+ {
1078
+ id: 18,
1079
+ type: {
1080
+ def: {
1081
+ variant: {
1082
+ variants: [
1083
+ {
1084
+ fields: [
1085
+ {
1086
+ type: 19
1087
+ }
1088
+ ],
1089
+ index: 0,
1090
+ name: "Ok"
1091
+ },
1092
+ {
1093
+ fields: [
1094
+ {
1095
+ type: 8
1096
+ }
1097
+ ],
1098
+ index: 1,
1099
+ name: "Err"
1100
+ }
1101
+ ]
1102
+ }
1103
+ },
1104
+ params: [
1105
+ {
1106
+ name: "T",
1107
+ type: 19
1108
+ },
1109
+ {
1110
+ name: "E",
1111
+ type: 8
1112
+ }
1113
+ ],
1114
+ path: [
1115
+ "Result"
1116
+ ]
1117
+ }
1118
+ },
1119
+ {
1120
+ id: 19,
1121
+ type: {
1122
+ def: {
1123
+ variant: {
1124
+ variants: [
1125
+ {
1126
+ fields: [
1127
+ {
1128
+ type: 0
1129
+ }
1130
+ ],
1131
+ index: 0,
1132
+ name: "Ok"
1133
+ },
1134
+ {
1135
+ fields: [
1136
+ {
1137
+ type: 11
1138
+ }
1139
+ ],
1140
+ index: 1,
1141
+ name: "Err"
1142
+ }
1143
+ ]
1144
+ }
1145
+ },
1146
+ params: [
1147
+ {
1148
+ name: "T",
1149
+ type: 0
1150
+ },
1151
+ {
1152
+ name: "E",
1153
+ type: 11
1154
+ }
1155
+ ],
1156
+ path: [
1157
+ "Result"
1158
+ ]
1159
+ }
1160
+ },
1161
+ {
1162
+ id: 20,
1163
+ type: {
1164
+ def: {
1165
+ variant: {
1166
+ variants: [
1167
+ {
1168
+ index: 0,
1169
+ name: "None"
1170
+ },
1171
+ {
1172
+ fields: [
1173
+ {
1174
+ type: 5
1175
+ }
1176
+ ],
1177
+ index: 1,
1178
+ name: "Some"
1179
+ }
1180
+ ]
1181
+ }
1182
+ },
1183
+ params: [
1184
+ {
1185
+ name: "T",
1186
+ type: 5
1187
+ }
1188
+ ],
1189
+ path: [
1190
+ "Option"
1191
+ ]
1192
+ }
1193
+ },
1194
+ {
1195
+ id: 21,
1196
+ type: {
1197
+ def: {
1198
+ variant: {
1199
+ variants: [
1200
+ {
1201
+ fields: [
1202
+ {
1203
+ type: 22
1204
+ }
1205
+ ],
1206
+ index: 0,
1207
+ name: "Ok"
1208
+ },
1209
+ {
1210
+ fields: [
1211
+ {
1212
+ type: 8
1213
+ }
1214
+ ],
1215
+ index: 1,
1216
+ name: "Err"
1217
+ }
1218
+ ]
1219
+ }
1220
+ },
1221
+ params: [
1222
+ {
1223
+ name: "T",
1224
+ type: 22
1225
+ },
1226
+ {
1227
+ name: "E",
1228
+ type: 8
1229
+ }
1230
+ ],
1231
+ path: [
1232
+ "Result"
1233
+ ]
1234
+ }
1235
+ },
1236
+ {
1237
+ id: 22,
1238
+ type: {
1239
+ def: {
1240
+ sequence: {
1241
+ type: 23
1242
+ }
1243
+ }
1244
+ }
1245
+ },
1246
+ {
1247
+ id: 23,
1248
+ type: {
1249
+ def: {
1250
+ tuple: [
1251
+ 0,
1252
+ 5
1253
+ ]
1254
+ }
1255
+ }
1256
+ },
1257
+ {
1258
+ id: 24,
1259
+ type: {
1260
+ def: {
1261
+ variant: {
1262
+ variants: [
1263
+ {
1264
+ fields: [
1265
+ {
1266
+ type: 0
1267
+ }
1268
+ ],
1269
+ index: 0,
1270
+ name: "Ok"
1271
+ },
1272
+ {
1273
+ fields: [
1274
+ {
1275
+ type: 8
1276
+ }
1277
+ ],
1278
+ index: 1,
1279
+ name: "Err"
1280
+ }
1281
+ ]
1282
+ }
1283
+ },
1284
+ params: [
1285
+ {
1286
+ name: "T",
1287
+ type: 0
1288
+ },
1289
+ {
1290
+ name: "E",
1291
+ type: 8
1292
+ }
1293
+ ],
1294
+ path: [
1295
+ "Result"
1296
+ ]
1297
+ }
1298
+ },
1299
+ {
1300
+ id: 25,
1301
+ type: {
1302
+ def: {
1303
+ primitive: "u128"
1304
+ }
1305
+ }
1306
+ },
1307
+ {
1308
+ id: 26,
1309
+ type: {
1310
+ def: {
1311
+ composite: {
1312
+ fields: [
1313
+ {
1314
+ type: 1,
1315
+ typeName: "[u8; 32]"
1316
+ }
1317
+ ]
1318
+ }
1319
+ },
1320
+ path: [
1321
+ "ink_primitives",
1322
+ "types",
1323
+ "Hash"
1324
+ ]
1325
+ }
1326
+ },
1327
+ {
1328
+ id: 27,
1329
+ type: {
1330
+ def: {
1331
+ primitive: "u64"
1332
+ }
1333
+ }
1334
+ },
1335
+ {
1336
+ id: 28,
1337
+ type: {
1338
+ def: {
1339
+ primitive: "u32"
1340
+ }
1341
+ }
1342
+ },
1343
+ {
1344
+ id: 29,
1345
+ type: {
1346
+ def: {
1347
+ variant: {
1348
+ }
1349
+ },
1350
+ path: [
1351
+ "ink_env",
1352
+ "types",
1353
+ "NoChainExtension"
1354
+ ]
1355
+ }
1356
+ }
1357
+ ],
1358
+ version: "4"
1359
+ };
72
1360
 
73
- /**
74
- * Looks up the addresses for some ENS domains.
75
- */
76
- async resolveNames(names) {
77
- const resolvedNames = new Map(names.map(name => [name, null]));
78
- const client = await this.chainConnectors.evm?.getPublicClientForEvmNetwork(this.networkIdEthereum);
79
- if (!client) {
80
- log.warn(`Could not find Ethereum client in OnChainId::resolveNames`);
81
- return resolvedNames;
82
- }
83
- const results = await Promise.allSettled(names.map(async name => {
84
- try {
85
- const address = await client.getEnsAddress({
86
- name
87
- });
88
- name !== null && resolvedNames.set(name, address);
89
- } catch (cause) {
90
- throw new Error(`Failed to resolve address for ENS domain '${name}'`, {
91
- cause
92
- });
93
- }
94
- }));
95
- results.forEach(result => result.status === "rejected" && log.warn(result.reason));
96
- return resolvedNames;
1361
+ const ROUTER_ABI = new Abi(aznsRouterAbiJson);
1362
+ const ROUTER_ADDRESS = {
1363
+ "alephzero": "5FfRtDtpS3Vcr7BTChjPiQNrcAKu3VLv4E1NGF6ng6j3ZopJ",
1364
+ "alephzero-testnet": "5HXjj3xhtRMqRYCRaXTDcVPz3Mez2XBruyujw6UEkvn8PCiA"
1365
+ };
1366
+ const readContract = async (provider, registry, from, contractAddress, data) => {
1367
+ const rawResult = await provider.send("state_call", ["ContractsApi_call", u8aToHex(u8aConcatStrict([
1368
+ // origin
1369
+ registry.createType("AccountId", from).toU8a(),
1370
+ // dest
1371
+ registry.createType("AccountId", contractAddress).toU8a(),
1372
+ // value
1373
+ registry.createType("Balance", 0).toU8a(),
1374
+ // gasLimit
1375
+ registry.createType("Option<WeightV2>").toU8a(),
1376
+ // storageDepositLimit
1377
+ registry.createType("Option<Balance>").toU8a(),
1378
+ // inputData
1379
+ data]))]);
1380
+ return registry.createType("ContractExecResult", rawResult);
1381
+ };
1382
+ const resolveDomainToAddress = async (domain, {
1383
+ provider,
1384
+ registry,
1385
+ chainId
1386
+ }) => {
1387
+ try {
1388
+ const routerAddress = ROUTER_ADDRESS[chainId];
1389
+ if (!routerAddress) throw new Error(`No azns router address found for chainId: ${chainId}`);
1390
+ const message = ROUTER_ABI.findMessage("get_address");
1391
+ if (!message) throw new Error(`No get_address message found in aznsRouter abi`);
1392
+ const {
1393
+ result
1394
+ } = await readContract(provider, registry, routerAddress, routerAddress, message.toU8a([domain]));
1395
+ if (!result.isOk) throw result.asErr;
1396
+ const resultType = message.returnType.lookupName ?? message.returnType.type;
1397
+ const returnValue = registry.createTypeUnsafe(resultType, [result.asOk.data.toU8a(true)], {
1398
+ isPedantic: true
1399
+ });
1400
+ if (!returnValue.isOk) throw returnValue.asErr;
1401
+ if (!returnValue.asOk.isOk) throw returnValue.asOk.asErr;
1402
+ return returnValue.asOk.asOk.toString();
1403
+ } catch (cause) {
1404
+ throw new Error(`Failed to resolve azns domain ${domain} on ${chainId}`, {
1405
+ cause
1406
+ });
97
1407
  }
98
-
99
- /**
100
- * Looks up the on-chain identifiers for some addresses.
101
- *
102
- * Prefers ENS, then falls back to Polkadot identities.
103
- *
104
- * Requires a TypeRegistry which has been instantiated on the Polkadot relay chain.
105
- * Talisman Wallet developers can build one by using `/apps/extension/src/core/util/getTypeRegistry.ts`.
106
- */
107
- async lookupAddresses(addresses) {
108
- const onChainIds = new Map(addresses.map(address => [address, null]));
109
- const [polkadotIdentities, ensDomains] = await Promise.all([this.lookupPolkadotAddresses(addresses), this.lookupEnsAddresses(addresses)]);
110
- polkadotIdentities.forEach((polkadotIdentity, address) => {
111
- if (!polkadotIdentity) return;
112
- onChainIds.set(address, polkadotIdentity);
1408
+ };
1409
+ const resolveAddressToDomain = async (address, {
1410
+ provider,
1411
+ registry,
1412
+ chainId
1413
+ }) => {
1414
+ try {
1415
+ const routerAddress = ROUTER_ADDRESS[chainId];
1416
+ if (!routerAddress) throw new Error(`No azns router address found for chainId: ${chainId}`);
1417
+ const message = ROUTER_ABI.findMessage("get_primary_domains");
1418
+ if (!message) throw new Error(`No get_address get_primary_domains found in aznsRouter abi`);
1419
+ const {
1420
+ result
1421
+ } = await readContract(provider, registry, routerAddress, routerAddress, message.toU8a([address, undefined]));
1422
+ if (!result.isOk) throw result.asErr;
1423
+ const resultType = message.returnType.lookupName ?? message.returnType.type;
1424
+ const returnValue = registry.createTypeUnsafe(resultType, [result.asOk.data.toU8a(true)], {
1425
+ isPedantic: true
113
1426
  });
114
- ensDomains.forEach((domain, address) => {
115
- if (!domain) return;
116
- onChainIds.set(address, domain);
1427
+ if (!returnValue.isOk) throw returnValue.asErr;
1428
+ return returnValue.asOk[0]?.[1]?.toString() ?? null;
1429
+ } catch (cause) {
1430
+ throw new Error(`Failed to lookup azns domain for ${address} on ${chainId}`, {
1431
+ cause
117
1432
  });
1433
+ }
1434
+ };
1435
+
1436
+ /**
1437
+ * Looks up the on-chain identifiers for some addresses.
1438
+ * Supports ENS and AZNS.
1439
+ */
1440
+ const lookupAddresses = async (config, addresses) => {
1441
+ const onChainIds = new Map(addresses.map(address => [address, null]));
1442
+ const [aznsDomains, ensDomains] = await Promise.all([lookupAznsAddresses(config, addresses), lookupEnsAddresses(config, addresses)]);
1443
+ aznsDomains.forEach((domain, address) => {
1444
+ if (!domain) return;
1445
+ onChainIds.set(address, domain);
1446
+ });
1447
+ ensDomains.forEach((domain, address) => {
1448
+ if (!domain) return;
1449
+ onChainIds.set(address, domain);
1450
+ });
1451
+ return onChainIds;
1452
+ };
1453
+
1454
+ /**
1455
+ * Looks up the on-chain AZNS domains for some addresses.
1456
+ */
1457
+ const lookupAznsAddresses = async (config, addresses) => {
1458
+ const onChainIds = new Map(addresses.map(address => [address, null]));
1459
+ if (!config.chainConnectors.substrate) {
1460
+ log.warn(`Could not find Substrate chainConnector in OnChainId::lookupAznsAddresses`);
118
1461
  return onChainIds;
119
1462
  }
1463
+ const provider = config.chainConnectors.substrate.asProvider(config.chainIdAlephZero);
1464
+ const results = await Promise.allSettled(addresses.map(async address => {
1465
+ // no need to do AZNS lookup for ethereum addresses
1466
+ if (isEthereumAddress(address)) return;
1467
+ const domain = await resolveAddressToDomain(address, {
1468
+ chainId: config.aznsSupportedChainIdAlephZero,
1469
+ registry: config.registryAlephZero,
1470
+ provider
1471
+ });
1472
+ if (domain) onChainIds.set(address, domain);
1473
+ }));
1474
+ results.forEach(result => result.status === "rejected" && log.warn(result.reason));
1475
+ return onChainIds;
1476
+ };
120
1477
 
121
- /**
122
- * Looks up the on-chain Polkadot identities for some addresses.
123
- *
124
- * Requires a TypeRegistry which has been instantiated on the Polkadot relay chain.
125
- * Talisman Wallet developers can build one by using `/apps/extension/src/core/util/getTypeRegistry.ts`.
126
- */
127
- async lookupPolkadotAddresses(addresses) {
128
- const onChainIds = new Map(addresses.map(address => [address, null]));
129
- if (!this.chainConnectors.substrate) {
130
- log.warn(`Could not find Substrate chainConnector in OnChainId::lookupPolkadotAddresses`);
131
- return onChainIds;
1478
+ /**
1479
+ * Looks up the on-chain ENS domains for some addresses.
1480
+ */
1481
+ const lookupEnsAddresses = async (config, addresses) => {
1482
+ const onChainIds = new Map(addresses.map(address => [address, null]));
1483
+ const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(config.networkIdEthereum);
1484
+ if (!client) {
1485
+ log.warn(`Could not find Ethereum client in OnChainId::lookupEnsAddresses`);
1486
+ return onChainIds;
1487
+ }
1488
+ const results = await Promise.allSettled(addresses.map(async address => {
1489
+ // no need to do ENS lookup for polkadot addresses
1490
+ if (!isEthereumAddress(address)) return;
1491
+ try {
1492
+ const domain = await client.getEnsName({
1493
+ address
1494
+ });
1495
+ domain !== null && onChainIds.set(address, domain);
1496
+ } catch (cause) {
1497
+ throw new Error(`Failed to resolve ENS domain for address '${address}': ${String(cause)}`, {
1498
+ cause
1499
+ });
132
1500
  }
133
- const queries = addresses.flatMap(address => {
134
- const storageHelper = new StorageHelper(this.polkadotRegistry, "identity", "identityOf", decodeAnyAddress(address));
1501
+ }));
1502
+ results.forEach(result => result.status === "rejected" && log.warn(result.reason));
1503
+ return onChainIds;
1504
+ };
135
1505
 
136
- // filter out queries which we failed to encode (e.g. an invalid address was input)
137
- const stateKey = storageHelper.stateKey;
138
- if (!stateKey) return [];
139
- const decodeResult = change => {
140
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
141
- const decoded = storageHelper.decode(change);
1506
+ /** dot separated string with `azero` or `tzero` suffix e.g. `fontbois.tzero` or `talisman.tzero` */
1507
+ const isPotentialAzns = name => typeof name === "string" && /^.+\.(([ta]zero)|(a0))$/.test(name);
142
1508
 
143
- // explicit null is required here to ensure the frontend knows that the address has been queried
144
- const bytes = decoded?.value?.info?.display?.value;
145
- const bytesDecoded = new TextDecoder().decode(bytes);
146
- const judgements =
147
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
148
- decoded?.value?.judgements?.flatMap?.(judgement => {
149
- if (judgement?.[1]?.isErroneous) return "Erroneous";
150
- if (judgement?.[1]?.isFeePaid) return "FeePaid";
151
- if (judgement?.[1]?.isKnownGood) return "KnownGood";
152
- if (judgement?.[1]?.isLowQuality) return "LowQuality";
153
- if (judgement?.[1]?.isOutOfDate) return "OutOfDate";
154
- if (judgement?.[1]?.isReasonable) return "Reasonable";
155
- if (judgement?.[1]?.isUnknown) return "Unknown";
156
- log.warn(`Unknown judgement type ${judgement?.toJSON?.() ?? String(judgement)}`);
157
- return [];
158
- }) ?? [];
159
- if (judgements.length < 1) judgements.push("NoJudgement");
160
- const display = bytes ? `${bytesDecoded} (${judgements.join(", ")})` : null;
161
- return [address, display];
162
- };
163
- return {
164
- chainId: this.chainIdPolkadot,
165
- stateKey,
166
- decodeResult
167
- };
168
- });
169
- const identities = await new RpcStateQueryHelper(this.chainConnectors.substrate, queries).fetch();
170
- identities.forEach(([address, polkadotIdentity]) => {
171
- if (!polkadotIdentity) return;
172
- onChainIds.set(address, polkadotIdentity);
173
- });
174
- return onChainIds;
1509
+ /** dot separated string e.g. `ens.eth` or `hello.lol`, but not ending with `.azero` nor `.tzero` */
1510
+ const isPotentialEns = name => typeof name === "string" && /^.+\..+$/.test(name) && !isPotentialAzns(name);
1511
+
1512
+ const resolveNames = async (config, names) => {
1513
+ const resolvedNames = new Map(names.map(name => [name, null]));
1514
+ const [aznsNames, ensNames] = await Promise.all([resolveAznsNames(config, names), resolveEnsNames(config, names)]);
1515
+ aznsNames.forEach((lookup, name) => {
1516
+ if (!lookup) return;
1517
+ const [address, lookupType] = lookup;
1518
+ if (!address) return;
1519
+ resolvedNames.set(name, [address, lookupType]);
1520
+ });
1521
+ ensNames.forEach((lookup, name) => {
1522
+ if (!lookup) return;
1523
+ const [address, lookupType] = lookup;
1524
+ if (!address) return;
1525
+ resolvedNames.set(name, [address, lookupType]);
1526
+ });
1527
+ return resolvedNames;
1528
+ };
1529
+
1530
+ /**
1531
+ * Looks up the addresses for some azns (azero.id) domains.
1532
+ */
1533
+ const resolveAznsNames = async (config, names) => {
1534
+ const resolvedNames = new Map(names.map(name => [name, null]));
1535
+ if (names.every(name => !isPotentialAzns(name))) return resolvedNames;
1536
+ if (!config.chainConnectors.substrate) {
1537
+ log.warn(`Could not find Substrate chainConnector in OnChainId::resolveAznsNames`);
1538
+ return resolvedNames;
175
1539
  }
1540
+ const provider = config.chainConnectors.substrate.asProvider(config.chainIdAlephZero);
1541
+ const results = await Promise.allSettled(names.map(async name => {
1542
+ if (!isPotentialAzns(name)) return;
1543
+ const address = await resolveDomainToAddress(name, {
1544
+ chainId: config.aznsSupportedChainIdAlephZero,
1545
+ registry: config.registryAlephZero,
1546
+ provider
1547
+ });
1548
+ if (address) resolvedNames.set(name, [address, "azns"]);
1549
+ }));
1550
+ results.forEach(result => result.status === "rejected" && log.warn(result.reason));
1551
+ return resolvedNames;
1552
+ };
176
1553
 
177
- /**
178
- * Looks up the on-chain ENS domains for some addresses.
179
- */
180
- async lookupEnsAddresses(addresses) {
181
- const onChainIds = new Map(addresses.map(address => [address, null]));
182
- const client = await this.chainConnectors.evm?.getPublicClientForEvmNetwork(this.networkIdEthereum);
183
- if (!client) {
184
- log.warn(`Could not find Ethereum client in OnChainId::lookupEnsAddresses`);
185
- return onChainIds;
1554
+ /**
1555
+ * Looks up the addresses for some ens (ens.domains) domains.
1556
+ */
1557
+ const resolveEnsNames = async (config, names) => {
1558
+ const resolvedNames = new Map(names.map(name => [name, null]));
1559
+ if (names.every(name => !isPotentialEns(name))) return resolvedNames;
1560
+ const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(config.networkIdEthereum);
1561
+ if (!client) {
1562
+ log.warn(`Could not find Ethereum client in OnChainId::resolveNames`);
1563
+ return resolvedNames;
1564
+ }
1565
+ const results = await Promise.allSettled(names.map(async name => {
1566
+ if (!isPotentialEns(name)) return;
1567
+ try {
1568
+ const address = await Promise.race([
1569
+ // this hangs forever in some cases (ex: try agyle.e first, then agyle.et => hangs) - couldn't explain it
1570
+ client.getEnsAddress({
1571
+ name
1572
+ }), throwAfter(10_000, "Timeout")]);
1573
+ address !== null && resolvedNames.set(name, [address, "ens"]);
1574
+ } catch (cause) {
1575
+ throw new Error(`Failed to resolve address for ens domain '${name}'`, {
1576
+ cause
1577
+ });
186
1578
  }
187
- const results = await Promise.allSettled(addresses.map(async address => {
188
- // no need to do ENS lookup for polkadot addresses
189
- if (!isEthereumAddress(address)) return;
190
- try {
191
- const domain = await client.getEnsName({
192
- address
193
- });
194
- domain !== null && onChainIds.set(address, domain);
195
- } catch (cause) {
196
- throw new Error(`Failed to resolve ENS domain for address '${address}': ${String(cause)}`, {
197
- cause
198
- });
199
- }
200
- }));
201
- results.forEach(result => result.status === "rejected" && log.warn(result.reason));
202
- return onChainIds;
1579
+ }));
1580
+ results.forEach(result => result.status === "rejected" && log.warn(result.reason));
1581
+ return resolvedNames;
1582
+ };
1583
+
1584
+ class OnChainId {
1585
+ #config;
1586
+ constructor(config) {
1587
+ this.#config = {
1588
+ ...config,
1589
+ chainIdAlephZero: config.chainIdAlephZero ?? "aleph-zero",
1590
+ aznsSupportedChainIdAlephZero: config.aznsSupportedChainIdAlephZero ?? "alephzero",
1591
+ networkIdEthereum: config.networkIdEthereum ?? "1"
1592
+ };
203
1593
  }
1594
+ resolveNames = (...args) => resolveNames(this.#config, ...args);
1595
+ resolveEnsNames = (...args) => resolveEnsNames(this.#config, ...args);
1596
+ resolveAznsNames = (...args) => resolveAznsNames(this.#config, ...args);
1597
+ lookupAddresses = (...args) => lookupAddresses(this.#config, ...args);
1598
+ lookupAznsAddresses = (...args) => lookupAznsAddresses(this.#config, ...args);
1599
+ lookupEnsAddresses = (...args) => lookupEnsAddresses(this.#config, ...args);
204
1600
  }
205
1601
 
206
- export { OnChainId, isPotentialEns };
1602
+ export { OnChainId, isPotentialAzns, isPotentialEns };