@keplr-wallet/background 0.12.273-alpha.2 → 0.12.273

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 +1 -17
  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 +6 -17
  6. package/build/keyring/service.js +145 -154
  7. package/build/keyring/service.js.map +1 -1
  8. package/build/keyring/types.d.ts +1 -7
  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 +35 -49
  12. package/build/keyring-cosmos/service.js.map +1 -1
  13. package/build/keyring-ethereum/service.js +9 -26
  14. package/build/keyring-ethereum/service.js.map +1 -1
  15. package/build/keyring-keystone/service.d.ts +1 -4
  16. package/build/keyring-keystone/service.js +1 -4
  17. package/build/keyring-keystone/service.js.map +1 -1
  18. package/build/keyring-ledger/service.d.ts +1 -4
  19. package/build/keyring-ledger/service.js +5 -12
  20. package/build/keyring-ledger/service.js.map +1 -1
  21. package/build/keyring-mnemonic/service.d.ts +1 -4
  22. package/build/keyring-mnemonic/service.js +2 -8
  23. package/build/keyring-mnemonic/service.js.map +1 -1
  24. package/build/keyring-private-key/service.d.ts +1 -4
  25. package/build/keyring-private-key/service.js +1 -4
  26. package/build/keyring-private-key/service.js.map +1 -1
  27. package/build/keyring-starknet/service.js +1 -2
  28. package/build/keyring-starknet/service.js.map +1 -1
  29. package/build/token-scan/service.js +1 -4
  30. package/build/token-scan/service.js.map +1 -1
  31. package/package.json +13 -13
  32. package/src/chains/service.ts +0 -20
  33. package/src/keyring/handler.ts +2 -2
  34. package/src/keyring/service.ts +113 -137
  35. package/src/keyring/types.ts +1 -3
  36. package/src/keyring-cosmos/handler.ts +1 -1
  37. package/src/keyring-cosmos/service.ts +39 -58
  38. package/src/keyring-ethereum/service.ts +8 -38
  39. package/src/keyring-keystone/service.ts +2 -12
  40. package/src/keyring-ledger/service.ts +8 -17
  41. package/src/keyring-mnemonic/service.ts +3 -13
  42. package/src/keyring-private-key/service.ts +2 -5
  43. package/src/keyring-starknet/service.ts +1 -2
  44. package/src/token-scan/service.ts +1 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keplr-wallet/background",
3
- "version": "0.12.273-alpha.2",
3
+ "version": "0.12.273",
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.273-alpha.2",
32
- "@keplr-wallet/common": "0.12.273-alpha.2",
33
- "@keplr-wallet/cosmos": "0.12.273-alpha.2",
34
- "@keplr-wallet/crypto": "0.12.273-alpha.2",
35
- "@keplr-wallet/ledger-cosmos": "0.12.273-alpha.2",
36
- "@keplr-wallet/popup": "0.12.273-alpha.2",
37
- "@keplr-wallet/proto-types": "0.12.273-alpha.2",
38
- "@keplr-wallet/router": "0.12.273-alpha.2",
39
- "@keplr-wallet/simple-fetch": "0.12.273-alpha.2",
40
- "@keplr-wallet/types": "0.12.273-alpha.2",
41
- "@keplr-wallet/unit": "0.12.273-alpha.2",
31
+ "@keplr-wallet/chain-validator": "0.12.273",
32
+ "@keplr-wallet/common": "0.12.273",
33
+ "@keplr-wallet/cosmos": "0.12.273",
34
+ "@keplr-wallet/crypto": "0.12.273",
35
+ "@keplr-wallet/ledger-cosmos": "0.12.273",
36
+ "@keplr-wallet/popup": "0.12.273",
37
+ "@keplr-wallet/proto-types": "0.12.273",
38
+ "@keplr-wallet/router": "0.12.273",
39
+ "@keplr-wallet/simple-fetch": "0.12.273",
40
+ "@keplr-wallet/types": "0.12.273",
41
+ "@keplr-wallet/unit": "0.12.273",
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": "c965bae914526b008c8a495ac186227e357fb12a"
68
+ "gitHead": "6b9b19d8c4cc163b7cf8877247a0221dfd032d29"
69
69
  }
@@ -1063,7 +1063,6 @@ export class ChainsService {
1063
1063
  };
1064
1064
  }
1065
1065
 
1066
- // TODO
1067
1066
  // Reduce the confusion from different coin type on ecosystem.
1068
1067
  // Unite coin type for all chain to 118 with allowing alternatives.
1069
1068
  // (If coin type is 60, it is probably to be compatible with metamask. So, in this case, do nothing.)
@@ -1095,25 +1094,6 @@ export class ChainsService {
1095
1094
 
1096
1095
  newChainInfo = {
1097
1096
  ...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
- })(),
1117
1097
  currencies: newChainInfo.currencies.map((currency) => {
1118
1098
  // Normalize coinMinimalDenom for all currencies.
1119
1099
  const coinMinimalDenom = DenomHelper.normalizeDenom(
@@ -431,7 +431,7 @@ const handleExportKeyRingVaultsMsg: (
431
431
  const handleSearchKeyRingsMsg: (
432
432
  service: KeyRingService
433
433
  ) => InternalHandler<SearchKeyRingsMsg> = (service) => {
434
- return async (_, msg) => {
435
- return await service.searchKeyRings(msg.searchText);
434
+ return (_, msg) => {
435
+ return service.searchKeyRings(msg.searchText);
436
436
  };
437
437
  };
@@ -469,12 +469,7 @@ export class KeyRingService {
469
469
  continue;
470
470
  }
471
471
 
472
- if (
473
- chainInfo.bip44.coinType === 60 ||
474
- !!chainInfo.features?.includes("eth-address-gen") ||
475
- (!!chainInfo.features?.includes("eth-key-sign") &&
476
- !hasEthereum)
477
- ) {
472
+ if (KeyRingService.isEthermintLike(chainInfo) && !hasEthereum) {
478
473
  continue;
479
474
  }
480
475
 
@@ -514,11 +509,7 @@ export class KeyRingService {
514
509
  continue;
515
510
  }
516
511
 
517
- if (
518
- chainInfo.bip44.coinType === 60 ||
519
- !!chainInfo.features?.includes("eth-address-gen") ||
520
- !!chainInfo.features?.includes("eth-key-sign")
521
- ) {
512
+ if (KeyRingService.isEthermintLike(chainInfo)) {
522
513
  continue;
523
514
  }
524
515
 
@@ -1005,9 +996,7 @@ export class KeyRingService {
1005
996
  },
1006
997
  });
1007
998
  }
1008
- getPubKeySelected(
1009
- chainId: string
1010
- ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
999
+ getPubKeySelected(chainId: string): Promise<PubKeySecp256k1> {
1011
1000
  return this.getPubKey(chainId, this.selectedVaultId);
1012
1001
  }
1013
1002
 
@@ -1133,10 +1122,7 @@ export class KeyRingService {
1133
1122
  return this.sign(chainId, this.selectedVaultId, data, digestMethod);
1134
1123
  }
1135
1124
 
1136
- getPubKey(
1137
- chainId: string,
1138
- vaultId: string
1139
- ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
1125
+ getPubKey(chainId: string, vaultId: string): Promise<PubKeySecp256k1> {
1140
1126
  if (this.vaultService.isLocked) {
1141
1127
  throw new Error("KeyRing is locked");
1142
1128
  }
@@ -1259,7 +1245,7 @@ export class KeyRingService {
1259
1245
  vaultId: string,
1260
1246
  purpose: number,
1261
1247
  coinType: number
1262
- ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
1248
+ ): Promise<PubKeySecp256k1> {
1263
1249
  if (this.vaultService.isLocked) {
1264
1250
  throw new Error("KeyRing is locked");
1265
1251
  }
@@ -1504,7 +1490,7 @@ export class KeyRingService {
1504
1490
  purpose: number,
1505
1491
  coinType: number,
1506
1492
  modularChainInfo: ModularChainInfo
1507
- ): Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }> {
1493
+ ): Promise<PubKeySecp256k1> {
1508
1494
  if (this.vaultService.isLocked) {
1509
1495
  throw new Error("KeyRing is locked");
1510
1496
  }
@@ -1534,7 +1520,7 @@ export class KeyRingService {
1534
1520
  (async () =>
1535
1521
  (
1536
1522
  await keyRing.getPubKey(vault, purpose, coinType, modularChainInfo)
1537
- ).pubKey.toBitcoinPubKey(network))()
1523
+ ).toBitcoinPubKey(network))()
1538
1524
  );
1539
1525
  }
1540
1526
 
@@ -1813,10 +1799,10 @@ export class KeyRingService {
1813
1799
  throw new Error(`Unsupported keyRing ${type}`);
1814
1800
  }
1815
1801
 
1816
- async searchKeyRings(
1802
+ searchKeyRings(
1817
1803
  searchText: string,
1818
1804
  ignoreChainEnabled: boolean = false
1819
- ): Promise<KeyInfo[]> {
1805
+ ): KeyInfo[] {
1820
1806
  searchText = searchText.trim();
1821
1807
 
1822
1808
  const keyInfos = this.getKeyInfos();
@@ -1845,62 +1831,53 @@ export class KeyRingService {
1845
1831
  })();
1846
1832
 
1847
1833
  if (isHex) {
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
- });
1861
-
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;
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");
1870
1843
  }
1844
+ return c.cosmos;
1845
+ });
1846
+
1847
+ let evmEnabled = false;
1848
+ for (const chainInfo of chainInfos) {
1849
+ if (KeyRingService.isEthermintLike(chainInfo)) {
1850
+ evmEnabled = true;
1871
1851
  }
1872
- if (!evmEnabled && !ignoreChainEnabled) {
1873
- return false;
1874
- }
1852
+ }
1853
+ if (!evmEnabled && !ignoreChainEnabled) {
1854
+ return false;
1855
+ }
1875
1856
 
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
- );
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
+ );
1887
1868
 
1888
- if (
1889
- hexAddress.includes(
1890
- searchText.replace("0x", "").toLowerCase()
1891
- )
1892
- ) {
1893
- return true;
1894
- }
1895
- } catch {
1896
- // noop
1869
+ if (
1870
+ hexAddress.includes(
1871
+ searchText.replace("0x", "").toLowerCase()
1872
+ )
1873
+ ) {
1874
+ return true;
1897
1875
  }
1876
+ } catch {
1877
+ // noop
1898
1878
  }
1899
1879
  }
1900
- })
1901
- );
1902
- hexAddressSearchKeyInfos = keyInfos.filter((_, i) => {
1903
- return asyncFilter[i];
1880
+ }
1904
1881
  });
1905
1882
  }
1906
1883
  }
@@ -1934,78 +1911,69 @@ export class KeyRingService {
1934
1911
  return result;
1935
1912
  })();
1936
1913
 
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
- });
1946
- }
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
- })();
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
+ }
1970
1923
 
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
1977
- );
1978
- const isEVM = pubKey.coinType === 60;
1979
-
1980
- const hexAddress =
1981
- KeyRingService.getAddressHexStringFromKeyInfo(
1982
- chainInfo,
1983
- keyInfo,
1984
- key,
1985
- value,
1986
- isEVM
1924
+ const chainInfos = (() => {
1925
+ if (ignoreChainEnabled) {
1926
+ return this.chainsService.getChainInfos();
1927
+ }
1928
+ return targetChainInfos.length > 0
1929
+ ? targetChainInfos
1930
+ : (() => {
1931
+ const modularChainInfos =
1932
+ this.chainsUIService.enabledModularChainInfosForVault(
1933
+ keyInfo.id
1987
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
1959
+ );
1988
1960
 
1989
- if (chainInfo.bech32Config == null) {
1990
- return false;
1991
- }
1961
+ if (chainInfo.bech32Config == null) {
1962
+ return false;
1963
+ }
1992
1964
 
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
1965
+ const bech32Address = this.getKeySearchBech32FromHex(
1966
+ chainInfo.bech32Config.bech32PrefixAccAddr,
1967
+ hexAddress
1968
+ );
1969
+ if (bech32Address.includes(searchText.toLowerCase())) {
1970
+ return true;
2002
1971
  }
1972
+ } catch {
1973
+ // noop
2003
1974
  }
2004
1975
  }
2005
- })
2006
- );
2007
- bech32AddressSearchKeyInfos = keyInfos.filter((_, i) => {
2008
- return asyncFilter[i];
1976
+ }
2009
1977
  });
2010
1978
  }
2011
1979
  }
@@ -2141,4 +2109,12 @@ export class KeyRingService {
2141
2109
  throw new Error("Invalid address index in hd path");
2142
2110
  }
2143
2111
  }
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
+ }
2144
2120
  }
@@ -41,9 +41,7 @@ export interface KeyRing {
41
41
  purpose: number,
42
42
  coinType: number,
43
43
  modularChainInfo: ModularChainInfo
44
- ):
45
- | { pubKey: PubKeySecp256k1; coinType: number | undefined }
46
- | Promise<{ pubKey: PubKeySecp256k1; coinType: number | undefined }>;
44
+ ): PubKeySecp256k1 | Promise<PubKeySecp256k1>;
47
45
  // This method should only be implemented for Ledger keyring.
48
46
  getPubKeyStarknet?(
49
47
  vault: Vault,
@@ -358,7 +358,7 @@ const handleGetCosmosKeysForEachVaultWithSearchSettledMsg: (
358
358
  service
359
359
  ) => {
360
360
  return async (_, msg) => {
361
- const searched = await service.keyRingService.searchKeyRings(
361
+ const searched = service.keyRingService.searchKeyRings(
362
362
  msg.searchText,
363
363
  true
364
364
  );