@keplr-wallet/background 0.12.272 → 0.12.273-alpha.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.
Files changed (44) hide show
  1. package/build/chains/service.js +24 -3
  2. package/build/chains/service.js.map +1 -1
  3. package/build/keyring/handler.js +3 -3
  4. package/build/keyring/handler.js.map +1 -1
  5. package/build/keyring/service.d.ts +17 -6
  6. package/build/keyring/service.js +154 -145
  7. package/build/keyring/service.js.map +1 -1
  8. package/build/keyring/types.d.ts +7 -1
  9. package/build/keyring-cosmos/handler.js +1 -1
  10. package/build/keyring-cosmos/handler.js.map +1 -1
  11. package/build/keyring-cosmos/service.js +49 -35
  12. package/build/keyring-cosmos/service.js.map +1 -1
  13. package/build/keyring-ethereum/service.js +26 -9
  14. package/build/keyring-ethereum/service.js.map +1 -1
  15. package/build/keyring-keystone/service.d.ts +4 -1
  16. package/build/keyring-keystone/service.js +4 -1
  17. package/build/keyring-keystone/service.js.map +1 -1
  18. package/build/keyring-ledger/service.d.ts +4 -1
  19. package/build/keyring-ledger/service.js +12 -5
  20. package/build/keyring-ledger/service.js.map +1 -1
  21. package/build/keyring-mnemonic/service.d.ts +4 -1
  22. package/build/keyring-mnemonic/service.js +8 -2
  23. package/build/keyring-mnemonic/service.js.map +1 -1
  24. package/build/keyring-private-key/service.d.ts +4 -1
  25. package/build/keyring-private-key/service.js +4 -1
  26. package/build/keyring-private-key/service.js.map +1 -1
  27. package/build/keyring-starknet/service.js +2 -1
  28. package/build/keyring-starknet/service.js.map +1 -1
  29. package/build/token-scan/service.js +4 -1
  30. package/build/token-scan/service.js.map +1 -1
  31. package/package.json +13 -13
  32. package/src/chains/service.ts +27 -0
  33. package/src/keyring/handler.ts +2 -2
  34. package/src/keyring/service.ts +137 -113
  35. package/src/keyring/types.ts +3 -1
  36. package/src/keyring-cosmos/handler.ts +1 -1
  37. package/src/keyring-cosmos/service.ts +58 -39
  38. package/src/keyring-ethereum/service.ts +38 -8
  39. package/src/keyring-keystone/service.ts +12 -2
  40. package/src/keyring-ledger/service.ts +17 -8
  41. package/src/keyring-mnemonic/service.ts +13 -3
  42. package/src/keyring-private-key/service.ts +5 -2
  43. package/src/keyring-starknet/service.ts +2 -1
  44. package/src/token-scan/service.ts +4 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keplr-wallet/background",
3
- "version": "0.12.272",
3
+ "version": "0.12.273-alpha.1",
4
4
  "main": "build/index.js",
5
5
  "author": "chainapsis",
6
6
  "license": "Apache-2.0",
@@ -28,17 +28,17 @@
28
28
  "@ethersproject/hash": "^5.7.0",
29
29
  "@ethersproject/transactions": "^5.7.0",
30
30
  "@ethersproject/wallet": "^5.7.0",
31
- "@keplr-wallet/chain-validator": "0.12.272",
32
- "@keplr-wallet/common": "0.12.272",
33
- "@keplr-wallet/cosmos": "0.12.272",
34
- "@keplr-wallet/crypto": "0.12.272",
35
- "@keplr-wallet/ledger-cosmos": "0.12.272",
36
- "@keplr-wallet/popup": "0.12.272",
37
- "@keplr-wallet/proto-types": "0.12.272",
38
- "@keplr-wallet/router": "0.12.272",
39
- "@keplr-wallet/simple-fetch": "0.12.272",
40
- "@keplr-wallet/types": "0.12.272",
41
- "@keplr-wallet/unit": "0.12.272",
31
+ "@keplr-wallet/chain-validator": "0.12.273-alpha.1",
32
+ "@keplr-wallet/common": "0.12.273-alpha.1",
33
+ "@keplr-wallet/cosmos": "0.12.273-alpha.1",
34
+ "@keplr-wallet/crypto": "0.12.273-alpha.1",
35
+ "@keplr-wallet/ledger-cosmos": "0.12.273-alpha.1",
36
+ "@keplr-wallet/popup": "0.12.273-alpha.1",
37
+ "@keplr-wallet/proto-types": "0.12.273-alpha.1",
38
+ "@keplr-wallet/router": "0.12.273-alpha.1",
39
+ "@keplr-wallet/simple-fetch": "0.12.273-alpha.1",
40
+ "@keplr-wallet/types": "0.12.273-alpha.1",
41
+ "@keplr-wallet/unit": "0.12.273-alpha.1",
42
42
  "@ledgerhq/hw-app-eth": "^6.40.3",
43
43
  "@ledgerhq/hw-app-starknet": "^2.5.2",
44
44
  "@ledgerhq/hw-transport": "^6.31.4",
@@ -65,5 +65,5 @@
65
65
  "mobx-utils": "^6",
66
66
  "starknet": "^7"
67
67
  },
68
- "gitHead": "6e41576f45372d14806724238d5d45f9a7d3f1ff"
68
+ "gitHead": "1eb0b05baebffae0d009daf99dee7cd4e70783ea"
69
69
  }
@@ -1063,6 +1063,7 @@ export class ChainsService {
1063
1063
  };
1064
1064
  }
1065
1065
 
1066
+ // TODO
1066
1067
  // Reduce the confusion from different coin type on ecosystem.
1067
1068
  // Unite coin type for all chain to 118 with allowing alternatives.
1068
1069
  // (If coin type is 60, it is probably to be compatible with metamask. So, in this case, do nothing.)
@@ -1086,8 +1087,33 @@ export class ChainsService {
1086
1087
  };
1087
1088
  }
1088
1089
 
1090
+ let features = [...(newChainInfo.features ?? [])];
1091
+ if (features.includes("evm-feemarket")) {
1092
+ // evm-feemarket and feemarket is incompatible.
1093
+ features = features.filter((f) => f !== "feemarket");
1094
+ }
1095
+
1089
1096
  newChainInfo = {
1090
1097
  ...newChainInfo,
1098
+ ...(() => {
1099
+ if (
1100
+ newChainInfo.chainId === "mantra-1" ||
1101
+ newChainInfo.chainId === "mantra-dukong-1"
1102
+ ) {
1103
+ return {
1104
+ bip44: {
1105
+ coinType: 60,
1106
+ },
1107
+ alternativeBIP44s: [
1108
+ {
1109
+ coinType: 118,
1110
+ },
1111
+ ],
1112
+ };
1113
+ }
1114
+
1115
+ return {};
1116
+ })(),
1091
1117
  currencies: newChainInfo.currencies.map((currency) => {
1092
1118
  // Normalize coinMinimalDenom for all currencies.
1093
1119
  const coinMinimalDenom = DenomHelper.normalizeDenom(
@@ -1128,6 +1154,7 @@ export class ChainsService {
1128
1154
  coinMinimalDenom,
1129
1155
  };
1130
1156
  }),
1157
+ features,
1131
1158
  };
1132
1159
  return newChainInfo;
1133
1160
  });
@@ -431,7 +431,7 @@ const handleExportKeyRingVaultsMsg: (
431
431
  const handleSearchKeyRingsMsg: (
432
432
  service: KeyRingService
433
433
  ) => InternalHandler<SearchKeyRingsMsg> = (service) => {
434
- return (_, msg) => {
435
- return service.searchKeyRings(msg.searchText);
434
+ return async (_, msg) => {
435
+ return await service.searchKeyRings(msg.searchText);
436
436
  };
437
437
  };
@@ -469,7 +469,12 @@ export class KeyRingService {
469
469
  continue;
470
470
  }
471
471
 
472
- if (KeyRingService.isEthermintLike(chainInfo) && !hasEthereum) {
472
+ if (
473
+ chainInfo.bip44.coinType === 60 ||
474
+ !!chainInfo.features?.includes("eth-address-gen") ||
475
+ (!!chainInfo.features?.includes("eth-key-sign") &&
476
+ !hasEthereum)
477
+ ) {
473
478
  continue;
474
479
  }
475
480
 
@@ -509,7 +514,11 @@ export class KeyRingService {
509
514
  continue;
510
515
  }
511
516
 
512
- if (KeyRingService.isEthermintLike(chainInfo)) {
517
+ if (
518
+ chainInfo.bip44.coinType === 60 ||
519
+ !!chainInfo.features?.includes("eth-address-gen") ||
520
+ !!chainInfo.features?.includes("eth-key-sign")
521
+ ) {
513
522
  continue;
514
523
  }
515
524
 
@@ -996,7 +1005,9 @@ export class KeyRingService {
996
1005
  },
997
1006
  });
998
1007
  }
999
- getPubKeySelected(chainId: string): Promise<PubKeySecp256k1> {
1008
+ getPubKeySelected(
1009
+ chainId: string
1010
+ ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
1000
1011
  return this.getPubKey(chainId, this.selectedVaultId);
1001
1012
  }
1002
1013
 
@@ -1122,7 +1133,10 @@ export class KeyRingService {
1122
1133
  return this.sign(chainId, this.selectedVaultId, data, digestMethod);
1123
1134
  }
1124
1135
 
1125
- getPubKey(chainId: string, vaultId: string): Promise<PubKeySecp256k1> {
1136
+ getPubKey(
1137
+ chainId: string,
1138
+ vaultId: string
1139
+ ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
1126
1140
  if (this.vaultService.isLocked) {
1127
1141
  throw new Error("KeyRing is locked");
1128
1142
  }
@@ -1245,7 +1259,7 @@ export class KeyRingService {
1245
1259
  vaultId: string,
1246
1260
  purpose: number,
1247
1261
  coinType: number
1248
- ): Promise<PubKeySecp256k1> {
1262
+ ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
1249
1263
  if (this.vaultService.isLocked) {
1250
1264
  throw new Error("KeyRing is locked");
1251
1265
  }
@@ -1490,7 +1504,7 @@ export class KeyRingService {
1490
1504
  purpose: number,
1491
1505
  coinType: number,
1492
1506
  modularChainInfo: ModularChainInfo
1493
- ): Promise<PubKeySecp256k1> {
1507
+ ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
1494
1508
  if (this.vaultService.isLocked) {
1495
1509
  throw new Error("KeyRing is locked");
1496
1510
  }
@@ -1520,7 +1534,7 @@ export class KeyRingService {
1520
1534
  (async () =>
1521
1535
  (
1522
1536
  await keyRing.getPubKey(vault, purpose, coinType, modularChainInfo)
1523
- ).toBitcoinPubKey(network))()
1537
+ ).pubKey.toBitcoinPubKey(network))()
1524
1538
  );
1525
1539
  }
1526
1540
 
@@ -1799,10 +1813,10 @@ export class KeyRingService {
1799
1813
  throw new Error(`Unsupported keyRing ${type}`);
1800
1814
  }
1801
1815
 
1802
- searchKeyRings(
1816
+ async searchKeyRings(
1803
1817
  searchText: string,
1804
1818
  ignoreChainEnabled: boolean = false
1805
- ): KeyInfo[] {
1819
+ ): Promise<KeyInfo[]> {
1806
1820
  searchText = searchText.trim();
1807
1821
 
1808
1822
  const keyInfos = this.getKeyInfos();
@@ -1831,53 +1845,62 @@ export class KeyRingService {
1831
1845
  })();
1832
1846
 
1833
1847
  if (isHex) {
1834
- hexAddressSearchKeyInfos = keyInfos.filter((keyInfo) => {
1835
- const modularChainInfos =
1836
- this.chainsUIService.enabledModularChainInfosForVault(keyInfo.id);
1837
- // TODO: 다른 체인도 지원하기
1838
- const chainInfos = modularChainInfos
1839
- .filter((c) => "cosmos" in c)
1840
- .map((c) => {
1841
- if (!("cosmos" in c)) {
1842
- throw new Error("Unsupported chain");
1843
- }
1844
- return c.cosmos;
1845
- });
1848
+ const asyncFilter = await Promise.all(
1849
+ keyInfos.map(async (keyInfo) => {
1850
+ const modularChainInfos =
1851
+ this.chainsUIService.enabledModularChainInfosForVault(keyInfo.id);
1852
+ // TODO: 다른 체인도 지원하기
1853
+ const chainInfos = modularChainInfos
1854
+ .filter((c) => "cosmos" in c)
1855
+ .map((c) => {
1856
+ if (!("cosmos" in c)) {
1857
+ throw new Error("Unsupported chain");
1858
+ }
1859
+ return c.cosmos;
1860
+ });
1846
1861
 
1847
- let evmEnabled = false;
1848
- for (const chainInfo of chainInfos) {
1849
- if (KeyRingService.isEthermintLike(chainInfo)) {
1850
- evmEnabled = true;
1862
+ let evmEnabled = false;
1863
+ for (const chainInfo of chainInfos) {
1864
+ const pubKey = await this.getPubKey(
1865
+ chainInfo.chainId,
1866
+ keyInfo.id
1867
+ );
1868
+ if (pubKey.coinType === 60) {
1869
+ evmEnabled = true;
1870
+ }
1871
+ }
1872
+ if (!evmEnabled && !ignoreChainEnabled) {
1873
+ return false;
1851
1874
  }
1852
- }
1853
- if (!evmEnabled && !ignoreChainEnabled) {
1854
- return false;
1855
- }
1856
1875
 
1857
- for (const [key, value] of Object.entries(keyInfo.insensitive)) {
1858
- for (const chainInfo of chainInfos) {
1859
- try {
1860
- const hexAddress =
1861
- KeyRingService.getAddressHexStringFromKeyInfo(
1862
- chainInfo,
1863
- keyInfo,
1864
- key,
1865
- value,
1866
- true
1867
- );
1876
+ for (const [key, value] of Object.entries(keyInfo.insensitive)) {
1877
+ for (const chainInfo of chainInfos) {
1878
+ try {
1879
+ const hexAddress =
1880
+ KeyRingService.getAddressHexStringFromKeyInfo(
1881
+ chainInfo,
1882
+ keyInfo,
1883
+ key,
1884
+ value,
1885
+ true
1886
+ );
1868
1887
 
1869
- if (
1870
- hexAddress.includes(
1871
- searchText.replace("0x", "").toLowerCase()
1872
- )
1873
- ) {
1874
- return true;
1888
+ if (
1889
+ hexAddress.includes(
1890
+ searchText.replace("0x", "").toLowerCase()
1891
+ )
1892
+ ) {
1893
+ return true;
1894
+ }
1895
+ } catch {
1896
+ // noop
1875
1897
  }
1876
- } catch {
1877
- // noop
1878
1898
  }
1879
1899
  }
1880
- }
1900
+ })
1901
+ );
1902
+ hexAddressSearchKeyInfos = keyInfos.filter((_, i) => {
1903
+ return asyncFilter[i];
1881
1904
  });
1882
1905
  }
1883
1906
  }
@@ -1911,69 +1934,78 @@ export class KeyRingService {
1911
1934
  return result;
1912
1935
  })();
1913
1936
 
1914
- bech32AddressSearchKeyInfos = keyInfos.filter((keyInfo) => {
1915
- if (!ignoreChainEnabled) {
1916
- targetChainInfos = targetChainInfos.filter((chainInfo) => {
1917
- return this.chainsUIService.isEnabled(
1918
- keyInfo.id,
1919
- chainInfo.chainId
1920
- );
1921
- });
1922
- }
1923
-
1924
- const chainInfos = (() => {
1925
- if (ignoreChainEnabled) {
1926
- return this.chainsService.getChainInfos();
1937
+ const asyncFilter = await Promise.all(
1938
+ keyInfos.map(async (keyInfo) => {
1939
+ if (!ignoreChainEnabled) {
1940
+ targetChainInfos = targetChainInfos.filter((chainInfo) => {
1941
+ return this.chainsUIService.isEnabled(
1942
+ keyInfo.id,
1943
+ chainInfo.chainId
1944
+ );
1945
+ });
1927
1946
  }
1928
- return targetChainInfos.length > 0
1929
- ? targetChainInfos
1930
- : (() => {
1931
- const modularChainInfos =
1932
- this.chainsUIService.enabledModularChainInfosForVault(
1933
- keyInfo.id
1934
- );
1935
- // TODO: 다른 체인도 지원하기
1936
- return modularChainInfos
1937
- .filter((c) => "cosmos" in c)
1938
- .map((c) => {
1939
- if (!("cosmos" in c)) {
1940
- throw new Error("Unsupported chain");
1941
- }
1942
- return c.cosmos;
1943
- });
1944
- })();
1945
- })();
1946
-
1947
- for (const chainInfo of chainInfos) {
1948
- for (const [key, value] of Object.entries(keyInfo.insensitive)) {
1949
- try {
1950
- const isEVM = KeyRingService.isEthermintLike(chainInfo);
1951
-
1952
- const hexAddress =
1953
- KeyRingService.getAddressHexStringFromKeyInfo(
1954
- chainInfo,
1955
- keyInfo,
1956
- key,
1957
- value,
1958
- isEVM
1947
+
1948
+ const chainInfos = (() => {
1949
+ if (ignoreChainEnabled) {
1950
+ return this.chainsService.getChainInfos();
1951
+ }
1952
+ return targetChainInfos.length > 0
1953
+ ? targetChainInfos
1954
+ : (() => {
1955
+ const modularChainInfos =
1956
+ this.chainsUIService.enabledModularChainInfosForVault(
1957
+ keyInfo.id
1958
+ );
1959
+ // TODO: 다른 체인도 지원하기
1960
+ return modularChainInfos
1961
+ .filter((c) => "cosmos" in c)
1962
+ .map((c) => {
1963
+ if (!("cosmos" in c)) {
1964
+ throw new Error("Unsupported chain");
1965
+ }
1966
+ return c.cosmos;
1967
+ });
1968
+ })();
1969
+ })();
1970
+
1971
+ for (const chainInfo of chainInfos) {
1972
+ for (const [key, value] of Object.entries(keyInfo.insensitive)) {
1973
+ try {
1974
+ const pubKey = await this.getPubKey(
1975
+ chainInfo.chainId,
1976
+ keyInfo.id
1959
1977
  );
1978
+ const isEVM = pubKey.coinType === 60;
1979
+
1980
+ const hexAddress =
1981
+ KeyRingService.getAddressHexStringFromKeyInfo(
1982
+ chainInfo,
1983
+ keyInfo,
1984
+ key,
1985
+ value,
1986
+ isEVM
1987
+ );
1960
1988
 
1961
- if (chainInfo.bech32Config == null) {
1962
- return false;
1963
- }
1989
+ if (chainInfo.bech32Config == null) {
1990
+ return false;
1991
+ }
1964
1992
 
1965
- const bech32Address = this.getKeySearchBech32FromHex(
1966
- chainInfo.bech32Config.bech32PrefixAccAddr,
1967
- hexAddress
1968
- );
1969
- if (bech32Address.includes(searchText.toLowerCase())) {
1970
- return true;
1993
+ const bech32Address = this.getKeySearchBech32FromHex(
1994
+ chainInfo.bech32Config.bech32PrefixAccAddr,
1995
+ hexAddress
1996
+ );
1997
+ if (bech32Address.includes(searchText.toLowerCase())) {
1998
+ return true;
1999
+ }
2000
+ } catch {
2001
+ // noop
1971
2002
  }
1972
- } catch {
1973
- // noop
1974
2003
  }
1975
2004
  }
1976
- }
2005
+ })
2006
+ );
2007
+ bech32AddressSearchKeyInfos = keyInfos.filter((_, i) => {
2008
+ return asyncFilter[i];
1977
2009
  });
1978
2010
  }
1979
2011
  }
@@ -2109,12 +2141,4 @@ export class KeyRingService {
2109
2141
  throw new Error("Invalid address index in hd path");
2110
2142
  }
2111
2143
  }
2112
-
2113
- static isEthermintLike(chainInfo: ChainInfo): boolean {
2114
- return (
2115
- chainInfo.bip44.coinType === 60 ||
2116
- !!chainInfo.features?.includes("eth-address-gen") ||
2117
- !!chainInfo.features?.includes("eth-key-sign")
2118
- );
2119
- }
2120
2144
  }
@@ -41,7 +41,9 @@ export interface KeyRing {
41
41
  purpose: number,
42
42
  coinType: number,
43
43
  modularChainInfo: ModularChainInfo
44
- ): PubKeySecp256k1 | Promise<PubKeySecp256k1>;
44
+ ):
45
+ | { pubKey: PubKeySecp256k1; coinType: number | undefined }
46
+ | Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }>;
45
47
  // This method should only be implemented for Ledger keyring.
46
48
  getPubKeyStarknet?(
47
49
  vault: Vault,
@@ -358,7 +358,7 @@ const handleGetCosmosKeysForEachVaultWithSearchSettledMsg: (
358
358
  service
359
359
  ) => {
360
360
  return async (_, msg) => {
361
- const searched = service.keyRingService.searchKeyRings(
361
+ const searched = await service.keyRingService.searchKeyRings(
362
362
  msg.searchText,
363
363
  true
364
364
  );