@keplr-wallet/background 0.13.13 → 0.13.15-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/build/chains/convert.d.ts +7 -0
  2. package/build/chains/convert.js +109 -0
  3. package/build/chains/convert.js.map +1 -0
  4. package/build/chains/handler.js +1 -1
  5. package/build/chains/handler.js.map +1 -1
  6. package/build/chains/index.d.ts +1 -0
  7. package/build/chains/index.js +1 -0
  8. package/build/chains/index.js.map +1 -1
  9. package/build/chains/messages.d.ts +1 -1
  10. package/build/chains/service.d.ts +3 -9
  11. package/build/chains/service.js +45 -79
  12. package/build/chains/service.js.map +1 -1
  13. package/build/chains-ui/service.d.ts +2 -2
  14. package/build/chains-ui/service.js +5 -6
  15. package/build/chains-ui/service.js.map +1 -1
  16. package/build/chains-update/service.js +2 -2
  17. package/build/chains-update/service.js.map +1 -1
  18. package/build/keyring/handler.js +21 -15
  19. package/build/keyring/handler.js.map +1 -1
  20. package/build/keyring/service.d.ts +0 -1
  21. package/build/keyring/service.js +103 -78
  22. package/build/keyring/service.js.map +1 -1
  23. package/build/keyring-bitcoin/service.js +2 -2
  24. package/build/keyring-bitcoin/service.js.map +1 -1
  25. package/build/keyring-cosmos/service.js +31 -18
  26. package/build/keyring-cosmos/service.js.map +1 -1
  27. package/build/keyring-ethereum/service.js +19 -19
  28. package/build/keyring-ethereum/service.js.map +1 -1
  29. package/build/keyring-ledger/service.js +8 -7
  30. package/build/keyring-ledger/service.js.map +1 -1
  31. package/build/keyring-starknet/service.js +7 -7
  32. package/build/keyring-starknet/service.js.map +1 -1
  33. package/build/manage-view-asset-token/service.d.ts +1 -2
  34. package/build/manage-view-asset-token/service.js +2 -2
  35. package/build/manage-view-asset-token/service.js.map +1 -1
  36. package/build/permission/service.d.ts +1 -2
  37. package/build/permission/service.js +2 -2
  38. package/build/permission/service.js.map +1 -1
  39. package/build/recent-send-history/service.d.ts +4 -4
  40. package/build/recent-send-history/service.js +101 -73
  41. package/build/recent-send-history/service.js.map +1 -1
  42. package/build/secret-wasm/service.d.ts +3 -3
  43. package/build/secret-wasm/service.js +29 -29
  44. package/build/secret-wasm/service.js.map +1 -1
  45. package/build/token-cw20/service.d.ts +6 -6
  46. package/build/token-cw20/service.js +28 -21
  47. package/build/token-cw20/service.js.map +1 -1
  48. package/build/token-erc20/service.d.ts +2 -3
  49. package/build/token-erc20/service.js +10 -15
  50. package/build/token-erc20/service.js.map +1 -1
  51. package/build/token-scan/service.js +27 -23
  52. package/build/token-scan/service.js.map +1 -1
  53. package/build/tx/service.d.ts +1 -0
  54. package/build/tx/service.js +41 -10
  55. package/build/tx/service.js.map +1 -1
  56. package/build/tx-ethereum/service.js +5 -9
  57. package/build/tx-ethereum/service.js.map +1 -1
  58. package/build/tx-executor/service.js +2 -7
  59. package/build/tx-executor/service.js.map +1 -1
  60. package/build/tx-executor/types.d.ts +7 -1
  61. package/build/tx-executor/types.js.map +1 -1
  62. package/build/tx-executor/utils/evm.d.ts +2 -2
  63. package/build/tx-executor/utils/evm.js +75 -26
  64. package/build/tx-executor/utils/evm.js.map +1 -1
  65. package/package.json +13 -13
  66. package/src/chains/convert.ts +126 -0
  67. package/src/chains/handler.ts +1 -1
  68. package/src/chains/index.ts +1 -0
  69. package/src/chains/messages.ts +1 -1
  70. package/src/chains/service.ts +64 -97
  71. package/src/chains-ui/service.ts +8 -7
  72. package/src/chains-update/service.ts +2 -2
  73. package/src/keyring/handler.ts +34 -19
  74. package/src/keyring/service.ts +137 -96
  75. package/src/keyring-bitcoin/service.ts +2 -2
  76. package/src/keyring-cosmos/service.ts +46 -18
  77. package/src/keyring-ethereum/service.ts +24 -17
  78. package/src/keyring-ledger/service.ts +10 -10
  79. package/src/keyring-starknet/service.ts +7 -7
  80. package/src/manage-view-asset-token/service.ts +2 -3
  81. package/src/permission/service.ts +3 -7
  82. package/src/recent-send-history/service.ts +141 -95
  83. package/src/secret-wasm/service.ts +39 -45
  84. package/src/token-cw20/service.ts +36 -30
  85. package/src/token-erc20/service.ts +15 -18
  86. package/src/token-scan/service.ts +34 -21
  87. package/src/tx/service.ts +60 -12
  88. package/src/tx-ethereum/service.ts +8 -8
  89. package/src/tx-executor/service.ts +4 -6
  90. package/src/tx-executor/types.ts +9 -1
  91. package/src/tx-executor/utils/evm.ts +92 -32
  92. package/tsconfig.check.json +2 -0
@@ -31,9 +31,9 @@ import {
31
31
  import { Buffer } from "buffer/";
32
32
  import {
33
33
  AppCurrency,
34
- ChainInfo,
35
34
  EthTxReceipt,
36
35
  EthTxStatus,
36
+ ModularChainInfo,
37
37
  } from "@keplr-wallet/types";
38
38
  import { CoinPretty } from "@keplr-wallet/unit";
39
39
  import { id } from "@ethersproject/hash";
@@ -310,24 +310,28 @@ export class RecentSendHistoryService {
310
310
  },
311
311
  shouldLegacyTrack: boolean = false
312
312
  ): Promise<Uint8Array> {
313
- const sourceChainInfo =
314
- this.chainsService.getChainInfoOrThrow(sourceChainId);
315
- Bech32Address.validate(
316
- sender,
317
- sourceChainInfo.bech32Config?.bech32PrefixAccAddr
318
- );
313
+ const sourceModularChainInfo =
314
+ this.chainsService.getModularChainInfoOrThrow(sourceChainId);
315
+ const sourceBech32Prefix =
316
+ sourceModularChainInfo.type === "cosmos" ||
317
+ sourceModularChainInfo.type === "ethermint"
318
+ ? sourceModularChainInfo.cosmos.bech32Config?.bech32PrefixAccAddr
319
+ : undefined;
320
+ Bech32Address.validate(sender, sourceBech32Prefix);
319
321
 
320
- const destinationChainInfo =
321
- this.chainsService.getChainInfoOrThrow(destinationChainId);
322
+ const destModularChainInfo =
323
+ this.chainsService.getModularChainInfoOrThrow(destinationChainId);
322
324
  if (recipient.startsWith("0x")) {
323
325
  if (!recipient.match(/^0x[0-9A-Fa-f]*$/) || recipient.length !== 42) {
324
326
  throw new Error("Recipient address is not valid hex address");
325
327
  }
326
328
  } else {
327
- Bech32Address.validate(
328
- recipient,
329
- destinationChainInfo.bech32Config?.bech32PrefixAccAddr
330
- );
329
+ const destBech32Prefix =
330
+ destModularChainInfo.type === "cosmos" ||
331
+ destModularChainInfo.type === "ethermint"
332
+ ? destModularChainInfo.cosmos.bech32Config?.bech32PrefixAccAddr
333
+ : undefined;
334
+ Bech32Address.validate(recipient, destBech32Prefix);
331
335
  }
332
336
 
333
337
  const txHash = await this.txService.sendTx(sourceChainId, tx, mode, {
@@ -449,14 +453,16 @@ export class RecentSendHistoryService {
449
453
  },
450
454
  shouldLegacyTrack: boolean = false
451
455
  ): Promise<Uint8Array> {
452
- const sourceChainInfo =
453
- this.chainsService.getChainInfoOrThrow(sourceChainId);
454
- Bech32Address.validate(
455
- sender,
456
- sourceChainInfo.bech32Config?.bech32PrefixAccAddr
457
- );
456
+ const sourceModularChainInfo =
457
+ this.chainsService.getModularChainInfoOrThrow(sourceChainId);
458
+ const sourceBech32Prefix =
459
+ sourceModularChainInfo.type === "cosmos" ||
460
+ sourceModularChainInfo.type === "ethermint"
461
+ ? sourceModularChainInfo.cosmos.bech32Config?.bech32PrefixAccAddr
462
+ : undefined;
463
+ Bech32Address.validate(sender, sourceBech32Prefix);
458
464
 
459
- this.chainsService.getChainInfoOrThrow(destinationChainId);
465
+ this.chainsService.getModularChainInfoOrThrow(destinationChainId);
460
466
 
461
467
  const txHash = await this.txService.sendTx(sourceChainId, tx, mode, {
462
468
  silent,
@@ -635,17 +641,19 @@ export class RecentSendHistoryService {
635
641
 
636
642
  getRecentIBCHistories(): IBCHistory[] {
637
643
  return Array.from(this.recentIBCHistoryMap.values()).filter((history) => {
638
- if (!this.chainsService.hasChainInfo(history.chainId)) {
644
+ if (!this.chainsService.hasModularChainInfo(history.chainId)) {
639
645
  return false;
640
646
  }
641
647
 
642
- if (!this.chainsService.hasChainInfo(history.destinationChainId)) {
648
+ if (!this.chainsService.hasModularChainInfo(history.destinationChainId)) {
643
649
  return false;
644
650
  }
645
651
 
646
652
  if (
647
653
  history.ibcHistory.some((history) => {
648
- return !this.chainsService.hasChainInfo(history.counterpartyChainId);
654
+ return !this.chainsService.hasModularChainInfo(
655
+ history.counterpartyChainId
656
+ );
649
657
  })
650
658
  ) {
651
659
  return false;
@@ -816,10 +824,10 @@ export class RecentSendHistoryService {
816
824
  history.notified = true;
817
825
  });
818
826
 
819
- const chainInfo = this.chainsService.getChainInfo(
827
+ const modularChainInfo = this.chainsService.getModularChainInfo(
820
828
  history.destinationChainId
821
829
  );
822
- if (chainInfo) {
830
+ if (modularChainInfo) {
823
831
  if ("swapType" in history) {
824
832
  if (history.resAmount.length > 0) {
825
833
  const amount = history.resAmount[history.resAmount.length - 1];
@@ -845,7 +853,7 @@ export class RecentSendHistoryService {
845
853
  iconRelativeUrl: "assets/logo-256.png",
846
854
  title: "IBC Swap Succeeded",
847
855
  message: `${assetsText.join(", ")} received on ${
848
- chainInfo.chainName
856
+ modularChainInfo.chainName
849
857
  }`,
850
858
  });
851
859
  }
@@ -873,7 +881,7 @@ export class RecentSendHistoryService {
873
881
  iconRelativeUrl: "assets/logo-256.png",
874
882
  title: "IBC Transfer Succeeded",
875
883
  message: `${assetsText.join(", ")} sent to ${
876
- chainInfo.chainName
884
+ modularChainInfo.chainName
877
885
  }`,
878
886
  });
879
887
  }
@@ -925,13 +933,13 @@ export class RecentSendHistoryService {
925
933
  onError: () => void;
926
934
  }): void => {
927
935
  const { chainId, txHash, onSuccess, onPending, onFailed, onError } = params;
928
- const chainInfo = this.chainsService.getChainInfo(chainId);
929
- if (!chainInfo) {
936
+ const modularChainInfo = this.chainsService.getModularChainInfo(chainId);
937
+ if (!modularChainInfo) {
930
938
  onFailed();
931
939
  return;
932
940
  }
933
941
 
934
- this.resolveTxExecutionStatus(chainInfo, chainId, txHash)
942
+ this.resolveTxExecutionStatus(modularChainInfo, chainId, txHash)
935
943
  .then((status) => {
936
944
  switch (status) {
937
945
  case "success":
@@ -954,18 +962,20 @@ export class RecentSendHistoryService {
954
962
  };
955
963
 
956
964
  protected async resolveTxExecutionStatus(
957
- chainInfo: ChainInfo,
965
+ modularChainInfo: ModularChainInfo,
958
966
  chainId: string,
959
967
  txHash: string
960
968
  ): Promise<"success" | "failed" | "pending" | "error"> {
961
969
  if (this.chainsService.isEvmChain(chainId)) {
962
- const evmInfo = chainInfo.evm;
963
- if (!evmInfo) {
970
+ if (
971
+ modularChainInfo.type !== "evm" &&
972
+ modularChainInfo.type !== "ethermint"
973
+ ) {
964
974
  return Promise.resolve("error");
965
975
  }
966
976
 
967
977
  const res = await requestEthTxReceipt({
968
- rpc: evmInfo.rpc,
978
+ rpc: modularChainInfo.evm.rpc,
969
979
  txHash,
970
980
  origin,
971
981
  });
@@ -985,7 +995,17 @@ export class RecentSendHistoryService {
985
995
  return "failed";
986
996
  }
987
997
 
988
- const txTracer = new TendermintTxTracer(chainInfo.rpc, "/websocket");
998
+ if (
999
+ modularChainInfo.type !== "cosmos" &&
1000
+ modularChainInfo.type !== "ethermint"
1001
+ ) {
1002
+ return Promise.resolve("error");
1003
+ }
1004
+
1005
+ const txTracer = new TendermintTxTracer(
1006
+ modularChainInfo.cosmos.rpc,
1007
+ "/websocket"
1008
+ );
989
1009
  txTracer.addEventListener("error", () => {
990
1010
  txTracer.close();
991
1011
  });
@@ -1040,8 +1060,8 @@ export class RecentSendHistoryService {
1040
1060
  onFulfill,
1041
1061
  } = params;
1042
1062
 
1043
- const chainInfo = this.chainsService.getChainInfo(chainId);
1044
- if (!chainInfo) {
1063
+ const modularChainInfo = this.chainsService.getModularChainInfo(chainId);
1064
+ if (!modularChainInfo) {
1045
1065
  onFulfill();
1046
1066
  return;
1047
1067
  }
@@ -1065,8 +1085,16 @@ export class RecentSendHistoryService {
1065
1085
  return;
1066
1086
  }
1067
1087
 
1088
+ if (
1089
+ modularChainInfo.type !== "cosmos" &&
1090
+ modularChainInfo.type !== "ethermint"
1091
+ ) {
1092
+ onFulfill();
1093
+ return;
1094
+ }
1095
+
1068
1096
  this.traceCosmosTransactionResult({
1069
- chainInfo,
1097
+ rpc: modularChainInfo.cosmos.rpc,
1070
1098
  txHash,
1071
1099
  recipient,
1072
1100
  onResult,
@@ -1075,14 +1103,14 @@ export class RecentSendHistoryService {
1075
1103
  }
1076
1104
 
1077
1105
  protected traceCosmosTransactionResult(params: {
1078
- chainInfo: ChainInfo;
1106
+ rpc: string;
1079
1107
  txHash: string;
1080
1108
  recipient: string;
1081
1109
  onResult: (resAmount: { amount: string; denom: string }[]) => void;
1082
1110
  onFulfill: () => void;
1083
1111
  }) {
1084
- const { chainInfo, txHash, recipient, onResult, onFulfill } = params;
1085
- const txTracer = new TendermintTxTracer(chainInfo.rpc, "/websocket");
1112
+ const { rpc, txHash, recipient, onResult, onFulfill } = params;
1113
+ const txTracer = new TendermintTxTracer(rpc, "/websocket");
1086
1114
  txTracer.addEventListener("error", () => onFulfill());
1087
1115
  txTracer
1088
1116
  .queryTx({
@@ -1128,28 +1156,24 @@ export class RecentSendHistoryService {
1128
1156
  const { chainId, txHash, recipient, targetDenom, onResult, onFulfill } =
1129
1157
  params;
1130
1158
 
1131
- const chainInfo = this.chainsService.getChainInfo(chainId);
1132
- if (!chainInfo) {
1159
+ const modularChainInfo = this.chainsService.getModularChainInfo(chainId);
1160
+ if (!modularChainInfo) {
1133
1161
  onResult({ success: false });
1134
1162
  onFulfill();
1135
1163
  return;
1136
1164
  }
1137
1165
 
1138
- if (!this.chainsService.isEvmChain(chainId)) {
1166
+ if (
1167
+ modularChainInfo.type !== "evm" &&
1168
+ modularChainInfo.type !== "ethermint"
1169
+ ) {
1139
1170
  onResult({ success: false, error: "Not an EVM chain" });
1140
1171
  onFulfill();
1141
1172
  return;
1142
1173
  }
1143
1174
 
1144
- const evmInfo = chainInfo.evm;
1145
- if (!evmInfo) {
1146
- onResult({ success: false });
1147
- onFulfill();
1148
- return;
1149
- }
1150
-
1151
1175
  requestEthTxReceipt({
1152
- rpc: evmInfo.rpc,
1176
+ rpc: modularChainInfo.evm.rpc,
1153
1177
  txHash,
1154
1178
  origin,
1155
1179
  })
@@ -1161,7 +1185,7 @@ export class RecentSendHistoryService {
1161
1185
  }
1162
1186
 
1163
1187
  requestEthTxTrace({
1164
- rpc: evmInfo.rpc,
1188
+ rpc: modularChainInfo.evm.rpc,
1165
1189
  txHash,
1166
1190
  origin,
1167
1191
  }).then((traceRes) => {
@@ -1382,17 +1406,17 @@ export class RecentSendHistoryService {
1382
1406
 
1383
1407
  getRecentSkipHistories(): SkipHistory[] {
1384
1408
  return Array.from(this.recentSkipHistoryMap.values()).filter((history) => {
1385
- if (!this.chainsService.hasChainInfo(history.chainId)) {
1409
+ if (!this.chainsService.hasModularChainInfo(history.chainId)) {
1386
1410
  return false;
1387
1411
  }
1388
1412
 
1389
- if (!this.chainsService.hasChainInfo(history.destinationChainId)) {
1413
+ if (!this.chainsService.hasModularChainInfo(history.destinationChainId)) {
1390
1414
  return false;
1391
1415
  }
1392
1416
 
1393
1417
  if (
1394
1418
  history.simpleRoute.some((route) => {
1395
- return !this.chainsService.hasChainInfo(route.chainId);
1419
+ return !this.chainsService.hasModularChainInfo(route.chainId);
1396
1420
  })
1397
1421
  ) {
1398
1422
  return false;
@@ -1866,10 +1890,10 @@ export class RecentSendHistoryService {
1866
1890
  return;
1867
1891
  }
1868
1892
 
1869
- const chainInfo = this.chainsService.getChainInfo(
1893
+ const modularChainInfo = this.chainsService.getModularChainInfo(
1870
1894
  history.destinationChainId
1871
1895
  );
1872
- if (!chainInfo) {
1896
+ if (!modularChainInfo) {
1873
1897
  onFulfill();
1874
1898
  return;
1875
1899
  }
@@ -2412,8 +2436,9 @@ export class RecentSendHistoryService {
2412
2436
  return;
2413
2437
  }
2414
2438
 
2415
- const chainInfo = this.chainsService.getChainInfo(targetChainId);
2416
- if (!chainInfo) {
2439
+ const modularChainInfo =
2440
+ this.chainsService.getModularChainInfo(targetChainId);
2441
+ if (!modularChainInfo) {
2417
2442
  onFulfill();
2418
2443
  return;
2419
2444
  }
@@ -2457,17 +2482,17 @@ export class RecentSendHistoryService {
2457
2482
  getRecentSwapV2Histories(): SwapV2History[] {
2458
2483
  return Array.from(this.recentSwapV2HistoryMap.values()).filter(
2459
2484
  (history) => {
2460
- if (!this.chainsService.hasChainInfo(history.fromChainId)) {
2485
+ if (!this.chainsService.hasModularChainInfo(history.fromChainId)) {
2461
2486
  return false;
2462
2487
  }
2463
2488
 
2464
- if (!this.chainsService.hasChainInfo(history.toChainId)) {
2489
+ if (!this.chainsService.hasModularChainInfo(history.toChainId)) {
2465
2490
  return false;
2466
2491
  }
2467
2492
 
2468
2493
  if (
2469
2494
  history.simpleRoute.some((route) => {
2470
- return !this.chainsService.hasChainInfo(route.chainId);
2495
+ return !this.chainsService.hasModularChainInfo(route.chainId);
2471
2496
  })
2472
2497
  ) {
2473
2498
  return false;
@@ -2526,8 +2551,10 @@ export class RecentSendHistoryService {
2526
2551
  return;
2527
2552
  }
2528
2553
 
2529
- const chainInfo = this.chainsService.getChainInfo(history.toChainId);
2530
- if (!chainInfo) {
2554
+ const modularChainInfo = this.chainsService.getModularChainInfo(
2555
+ history.toChainId
2556
+ );
2557
+ if (!modularChainInfo) {
2531
2558
  return;
2532
2559
  }
2533
2560
 
@@ -2560,7 +2587,9 @@ export class RecentSendHistoryService {
2560
2587
  this.notification.create({
2561
2588
  iconRelativeUrl: "assets/logo-256.png",
2562
2589
  title: "Swap Succeeded",
2563
- message: `${assetsText.join(", ")} received on ${chainInfo.chainName}`,
2590
+ message: `${assetsText.join(", ")} received on ${
2591
+ modularChainInfo.chainName
2592
+ }`,
2564
2593
  });
2565
2594
  }
2566
2595
 
@@ -2959,13 +2988,20 @@ export class RecentSendHistoryService {
2959
2988
  onError,
2960
2989
  } = params;
2961
2990
 
2962
- const chainInfo = this.chainsService.getChainInfo(chainId);
2963
- if (!chainInfo) {
2991
+ const modularChainInfo = this.chainsService.getModularChainInfo(chainId);
2992
+ if (
2993
+ !modularChainInfo ||
2994
+ (modularChainInfo.type !== "cosmos" &&
2995
+ modularChainInfo.type !== "ethermint")
2996
+ ) {
2964
2997
  onFulfill();
2965
2998
  return;
2966
2999
  }
2967
3000
 
2968
- const txTracer = new TendermintTxTracer(chainInfo.rpc, "/websocket");
3001
+ const txTracer = new TendermintTxTracer(
3002
+ modularChainInfo.cosmos.rpc,
3003
+ "/websocket"
3004
+ );
2969
3005
  txTracer.addEventListener("close", onClose);
2970
3006
  txTracer.addEventListener("error", onError);
2971
3007
 
@@ -3071,26 +3107,26 @@ export class RecentSendHistoryService {
3071
3107
  );
3072
3108
  if (targetChannel !== undefined && targetChannel.sequence !== undefined) {
3073
3109
  const targetSequence = targetChannel.sequence;
3074
- const prevChainInfo = (() => {
3110
+ const prevChain = (() => {
3075
3111
  const targetChannelIndex = ibcHistory.findIndex(
3076
3112
  (h) => h === targetChannel
3077
3113
  );
3078
3114
  if (targetChannelIndex < 0) {
3079
3115
  return undefined;
3080
3116
  }
3081
- if (targetChannelIndex === 0) {
3082
- return this.chainsService.getChainInfo(sourceChainId);
3117
+ const prevChainId =
3118
+ targetChannelIndex === 0
3119
+ ? sourceChainId
3120
+ : ibcHistory[targetChannelIndex - 1].counterpartyChainId;
3121
+ const m = this.chainsService.getModularChainInfo(prevChainId);
3122
+ if (m && (m.type === "cosmos" || m.type === "ethermint")) {
3123
+ return { chainId: m.chainId, rpc: m.cosmos.rpc };
3083
3124
  }
3084
- return this.chainsService.getChainInfo(
3085
- ibcHistory[targetChannelIndex - 1].counterpartyChainId
3086
- );
3125
+ return undefined;
3087
3126
  })();
3088
3127
 
3089
- if (prevChainInfo) {
3090
- const txTracer = new TendermintTxTracer(
3091
- prevChainInfo.rpc,
3092
- "/websocket"
3093
- );
3128
+ if (prevChain) {
3129
+ const txTracer = new TendermintTxTracer(prevChain.rpc, "/websocket");
3094
3130
  txTracer.addEventListener("close", onClose);
3095
3131
  txTracer.addEventListener("error", onError);
3096
3132
  txTracer
@@ -3166,7 +3202,7 @@ export class RecentSendHistoryService {
3166
3202
  );
3167
3203
 
3168
3204
  swapContext.setSwapRefundInfo?.({
3169
- chainId: prevChainInfo.chainId,
3205
+ chainId: prevChain.chainId,
3170
3206
  amount: refunded,
3171
3207
  });
3172
3208
 
@@ -3400,8 +3436,13 @@ export class RecentSendHistoryService {
3400
3436
  prevChainId = sourceChainId;
3401
3437
  }
3402
3438
  if (prevChainId) {
3403
- const prevChainInfo = this.chainsService.getChainInfo(prevChainId);
3404
- if (prevChainInfo) {
3439
+ const prevModularChainInfo =
3440
+ this.chainsService.getModularChainInfo(prevChainId);
3441
+ if (
3442
+ prevModularChainInfo &&
3443
+ (prevModularChainInfo.type === "cosmos" ||
3444
+ prevModularChainInfo.type === "ethermint")
3445
+ ) {
3405
3446
  const queryEvents: any = {
3406
3447
  // acknowledge_packet과는 다르게 timeout_packet은 이전의 체인의 이벤트로부터만 알 수 있다.
3407
3448
  // 방법이 없기 때문에 여기서 이전의 체인으로부터 subscribe를 해서 이벤트를 받아야 한다.
@@ -3413,7 +3454,7 @@ export class RecentSendHistoryService {
3413
3454
  };
3414
3455
 
3415
3456
  const txTracer = new TendermintTxTracer(
3416
- prevChainInfo.rpc,
3457
+ prevModularChainInfo.cosmos.rpc,
3417
3458
  "/websocket"
3418
3459
  );
3419
3460
  registerClosable(txTracer);
@@ -3487,11 +3528,15 @@ export class RecentSendHistoryService {
3487
3528
  }
3488
3529
  const sequence = targetChannel.sequence;
3489
3530
 
3490
- const counterpartyChainInfo = this.chainsService.getChainInfo(
3531
+ const counterpartyModularChainInfo = this.chainsService.getModularChainInfo(
3491
3532
  targetChannel.counterpartyChainId
3492
3533
  );
3493
3534
 
3494
- if (!counterpartyChainInfo) {
3535
+ if (
3536
+ !counterpartyModularChainInfo ||
3537
+ (counterpartyModularChainInfo.type !== "cosmos" &&
3538
+ counterpartyModularChainInfo.type !== "ethermint")
3539
+ ) {
3495
3540
  onFulfill();
3496
3541
  return;
3497
3542
  }
@@ -3503,7 +3548,7 @@ export class RecentSendHistoryService {
3503
3548
  };
3504
3549
 
3505
3550
  const txTracer = new TendermintTxTracer(
3506
- counterpartyChainInfo.rpc,
3551
+ counterpartyModularChainInfo.cosmos.rpc,
3507
3552
  "/websocket"
3508
3553
  );
3509
3554
  txTracer.addEventListener("close", onClose);
@@ -3533,7 +3578,9 @@ export class RecentSendHistoryService {
3533
3578
 
3534
3579
  const tx = matchedTx || txs[0];
3535
3580
 
3536
- targetChannel.completed = true;
3581
+ runInAction(() => {
3582
+ targetChannel.completed = true;
3583
+ });
3537
3584
 
3538
3585
  let resAmount: { amount: string; denom: string }[] | undefined;
3539
3586
  const receiverIndex = targetChannelIndex + 1;
@@ -3604,15 +3651,14 @@ export class RecentSendHistoryService {
3604
3651
  // 예를 들어, source chain -> osmosis (swap) -> destination chain으로 이동하는 경우,
3605
3652
  // osmosis에서 IBC wrapped token이 destination chain으로 전송되고,
3606
3653
  // destination chain에서 IBC wrapped token을 unwrap하는 케이스가 있을 수 있다.
3607
- const destinationChainInfo = this.chainsService.getChainInfo(
3608
- destinationAsset.chainId
3609
- );
3654
+ const destinationModularChainInfo =
3655
+ this.chainsService.getModularChainInfo(destinationAsset.chainId);
3610
3656
 
3611
- if (destinationChainInfo) {
3657
+ if (destinationModularChainInfo) {
3612
3658
  onDynamicHopDetected({
3613
3659
  portId: "transfer", // CHECK: transfer를 하드코딩해도 되는지 확인
3614
3660
  channelId: lastSendPacket.srcChannel,
3615
- counterpartyChainId: destinationChainInfo.chainId,
3661
+ counterpartyChainId: destinationModularChainInfo.chainId,
3616
3662
  sequence: lastSendPacket.sequence,
3617
3663
  dstChannelId: lastSendPacket.dstChannel,
3618
3664
  packetData: lastSendPacket.packetData,
@@ -4416,8 +4462,8 @@ export class RecentSendHistoryService {
4416
4462
  // ============================================================================
4417
4463
  // Chain removed handler
4418
4464
  // ============================================================================
4419
- protected readonly onChainRemoved = (chainInfo: ChainInfo) => {
4420
- const chainIdentifier = ChainIdHelper.parse(chainInfo.chainId).identifier;
4465
+ protected readonly onChainRemoved = (chainId: string) => {
4466
+ const chainIdentifier = ChainIdHelper.parse(chainId).identifier;
4421
4467
  try {
4422
4468
  this.removeIBCHistoriesByChainIdentifier(chainIdentifier);
4423
4469
  this.removeSkipHistoriesByChainIdentifier(chainIdentifier);
@@ -1,7 +1,6 @@
1
1
  import { EnigmaUtils } from "./enigma-utils";
2
2
  import { ChainsService } from "../chains";
3
3
  import { KVStore } from "@keplr-wallet/common";
4
- import { ChainInfo } from "@keplr-wallet/types";
5
4
  import { ChainIdHelper } from "@keplr-wallet/cosmos";
6
5
  import { Buffer } from "buffer/";
7
6
  import { KeyRingCosmosService } from "../keyring-cosmos";
@@ -54,12 +53,22 @@ export class SecretWasmService {
54
53
  this.cacheEnigmaUtils = new Map();
55
54
  };
56
55
 
57
- async getPubkey(chainId: string): Promise<Uint8Array> {
58
- const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
59
-
60
- const seed = await this.getSeed(chainInfo);
56
+ protected getCosmosRest(chainId: string): string {
57
+ const modularChainInfo =
58
+ this.chainsService.getModularChainInfoOrThrow(chainId);
59
+ if (
60
+ modularChainInfo.type !== "cosmos" &&
61
+ modularChainInfo.type !== "ethermint"
62
+ ) {
63
+ throw new Error(`Not a cosmos chain: ${chainId}`);
64
+ }
65
+ return modularChainInfo.cosmos.rest;
66
+ }
61
67
 
62
- const utils = this.getEnigmaUtils(chainInfo, seed);
68
+ async getPubkey(chainId: string): Promise<Uint8Array> {
69
+ const rest = this.getCosmosRest(chainId);
70
+ const seed = await this.getSeed(chainId);
71
+ const utils = this.getEnigmaUtils(chainId, rest, seed);
63
72
  return utils.pubkey;
64
73
  }
65
74
 
@@ -67,11 +76,9 @@ export class SecretWasmService {
67
76
  chainId: string,
68
77
  nonce: Uint8Array
69
78
  ): Promise<Uint8Array> {
70
- const chainInfo = await this.chainsService.getChainInfoOrThrow(chainId);
71
-
72
- const seed = await this.getSeed(chainInfo);
73
-
74
- const utils = this.getEnigmaUtils(chainInfo, seed);
79
+ const rest = this.getCosmosRest(chainId);
80
+ const seed = await this.getSeed(chainId);
81
+ const utils = this.getEnigmaUtils(chainId, rest, seed);
75
82
  return utils.getTxEncryptionKey(nonce);
76
83
  }
77
84
 
@@ -81,16 +88,9 @@ export class SecretWasmService {
81
88
  // eslint-disable-next-line @typescript-eslint/ban-types
82
89
  msg: object
83
90
  ): Promise<Uint8Array> {
84
- const chainInfo = await this.chainsService.getChainInfoOrThrow(chainId);
85
-
86
- // XXX: Keplr should generate the seed deterministically according to the account.
87
- // Otherwise, it will lost the encryption/decryption key if Keplr is uninstalled or local storage is cleared.
88
- // For now, use the signature of some string to generate the seed.
89
- // It need to more research.
90
- const seed = await this.getSeed(chainInfo);
91
-
92
- const utils = this.getEnigmaUtils(chainInfo, seed);
93
-
91
+ const rest = this.getCosmosRest(chainId);
92
+ const seed = await this.getSeed(chainId);
93
+ const utils = this.getEnigmaUtils(chainId, rest, seed);
94
94
  return await utils.encrypt(contractCodeHash, msg);
95
95
  }
96
96
 
@@ -99,52 +99,46 @@ export class SecretWasmService {
99
99
  ciphertext: Uint8Array,
100
100
  nonce: Uint8Array
101
101
  ): Promise<Uint8Array> {
102
- const chainInfo = await this.chainsService.getChainInfoOrThrow(chainId);
103
-
104
- // XXX: Keplr should generate the seed deterministically according to the account.
105
- // Otherwise, it will lost the encryption/decryption key if Keplr is uninstalled or local storage is cleared.
106
- // For now, use the signature of some string to generate the seed.
107
- // It need to more research.
108
- const seed = await this.getSeed(chainInfo);
109
-
110
- const utils = this.getEnigmaUtils(chainInfo, seed);
111
-
102
+ const rest = this.getCosmosRest(chainId);
103
+ const seed = await this.getSeed(chainId);
104
+ const utils = this.getEnigmaUtils(chainId, rest, seed);
112
105
  return await utils.decrypt(ciphertext, nonce);
113
106
  }
114
107
 
115
- private getEnigmaUtils(chainInfo: ChainInfo, seed: Uint8Array): EnigmaUtils {
116
- const key = `${chainInfo.chainId}-${Buffer.from(seed).toString("hex")}`;
108
+ private getEnigmaUtils(
109
+ chainId: string,
110
+ rest: string,
111
+ seed: Uint8Array
112
+ ): EnigmaUtils {
113
+ const key = `${chainId}-${Buffer.from(seed).toString("hex")}`;
117
114
 
118
115
  if (this.cacheEnigmaUtils.has(key)) {
119
116
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
120
117
  return this.cacheEnigmaUtils.get(key)!;
121
118
  }
122
119
 
123
- const utils = new EnigmaUtils(chainInfo.rest, seed, chainInfo.rest);
120
+ const utils = new EnigmaUtils(rest, seed, rest);
124
121
  this.cacheEnigmaUtils.set(key, utils);
125
122
 
126
123
  return utils;
127
124
  }
128
125
 
129
- protected async getSeed(chainInfo: ChainInfo): Promise<Uint8Array> {
130
- const key = await this.keyRingCosmosService.getKeySelected(
131
- chainInfo.chainId
132
- );
133
-
134
- return await this.getSeedInner(chainInfo, key);
126
+ protected async getSeed(chainId: string): Promise<Uint8Array> {
127
+ const key = await this.keyRingCosmosService.getKeySelected(chainId);
128
+ return await this.getSeedInner(chainId, key);
135
129
  }
136
130
 
137
131
  protected async getSeedInner(
138
- chainInfo: ChainInfo,
132
+ chainId: string,
139
133
  key: {
140
134
  readonly bech32Address: string;
141
135
  readonly isNanoLedger: boolean;
142
136
  readonly isKeystone: boolean;
143
137
  }
144
138
  ): Promise<Uint8Array> {
145
- const cacheKey = `seed-${
146
- ChainIdHelper.parse(chainInfo.chainId).identifier
147
- }-${key.bech32Address}`;
139
+ const cacheKey = `seed-${ChainIdHelper.parse(chainId).identifier}-${
140
+ key.bech32Address
141
+ }`;
148
142
 
149
143
  const cached = this.seedMap.get(cacheKey);
150
144
  if (cached) {
@@ -160,7 +154,7 @@ export class SecretWasmService {
160
154
 
161
155
  return Hash.sha256(
162
156
  await this.keyRingCosmosService.legacySignArbitraryInternal(
163
- chainInfo.chainId,
157
+ chainId,
164
158
  "Create Keplr Secret encryption key. Only approve requests by Keplr."
165
159
  )
166
160
  );