@talismn/on-chain-id 0.1.0 → 0.1.1

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