@keplr-wallet/background 0.12.272 → 0.12.273-alpha.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.
- package/build/chains/service.js +24 -3
- package/build/chains/service.js.map +1 -1
- package/build/keyring/handler.js +3 -3
- package/build/keyring/handler.js.map +1 -1
- package/build/keyring/service.d.ts +17 -6
- package/build/keyring/service.js +154 -145
- package/build/keyring/service.js.map +1 -1
- package/build/keyring/types.d.ts +7 -1
- package/build/keyring-cosmos/handler.js +1 -1
- package/build/keyring-cosmos/handler.js.map +1 -1
- package/build/keyring-cosmos/service.js +49 -35
- package/build/keyring-cosmos/service.js.map +1 -1
- package/build/keyring-ethereum/service.js +26 -9
- package/build/keyring-ethereum/service.js.map +1 -1
- package/build/keyring-keystone/service.d.ts +4 -1
- package/build/keyring-keystone/service.js +4 -1
- package/build/keyring-keystone/service.js.map +1 -1
- package/build/keyring-ledger/service.d.ts +4 -1
- package/build/keyring-ledger/service.js +12 -5
- package/build/keyring-ledger/service.js.map +1 -1
- package/build/keyring-mnemonic/service.d.ts +4 -1
- package/build/keyring-mnemonic/service.js +8 -2
- package/build/keyring-mnemonic/service.js.map +1 -1
- package/build/keyring-private-key/service.d.ts +4 -1
- package/build/keyring-private-key/service.js +4 -1
- package/build/keyring-private-key/service.js.map +1 -1
- package/build/keyring-starknet/service.js +2 -1
- package/build/keyring-starknet/service.js.map +1 -1
- package/build/token-scan/service.js +4 -1
- package/build/token-scan/service.js.map +1 -1
- package/package.json +13 -13
- package/src/chains/service.ts +27 -0
- package/src/keyring/handler.ts +2 -2
- package/src/keyring/service.ts +137 -113
- package/src/keyring/types.ts +3 -1
- package/src/keyring-cosmos/handler.ts +1 -1
- package/src/keyring-cosmos/service.ts +58 -39
- package/src/keyring-ethereum/service.ts +38 -8
- package/src/keyring-keystone/service.ts +12 -2
- package/src/keyring-ledger/service.ts +17 -8
- package/src/keyring-mnemonic/service.ts +13 -3
- package/src/keyring-private-key/service.ts +5 -2
- package/src/keyring-starknet/service.ts +2 -1
- package/src/token-scan/service.ts +4 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChainsService } from "../chains";
|
|
2
|
-
import {
|
|
2
|
+
import { DEFAULT_BIP44_PURPOSE, KeyRingService } from "../keyring";
|
|
3
3
|
import {
|
|
4
4
|
AminoSignResponse,
|
|
5
5
|
ChainInfo,
|
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
Bech32Address,
|
|
16
16
|
ChainIdHelper,
|
|
17
17
|
checkAndValidateADR36AminoSignDoc,
|
|
18
|
+
encodePubKey,
|
|
18
19
|
encodeSecp256k1Pubkey,
|
|
19
20
|
encodeSecp256k1Signature,
|
|
20
21
|
EthermintChainIdHelper,
|
|
@@ -108,29 +109,25 @@ export class KeyRingCosmosService {
|
|
|
108
109
|
|
|
109
110
|
const pubKey = await this.keyRingService.getPubKey(chainId, vaultId);
|
|
110
111
|
|
|
111
|
-
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);
|
|
112
|
-
const evmInfo = ChainsService.getEVMInfo(chainInfo);
|
|
113
|
-
const forceEVMLedger = chainInfo.features?.includes(
|
|
114
|
-
"force-enable-evm-ledger"
|
|
115
|
-
);
|
|
116
|
-
|
|
117
112
|
const keyInfo = this.keyRingService.getKeyInfo(vaultId);
|
|
118
113
|
if (!keyInfo) {
|
|
119
114
|
throw new Error("Null key info");
|
|
120
115
|
}
|
|
121
116
|
|
|
122
|
-
|
|
117
|
+
const isEthermintLike = pubKey.coinType === 60;
|
|
118
|
+
|
|
119
|
+
if (isEthermintLike && keyInfo.type === "ledger") {
|
|
123
120
|
KeyRingCosmosService.throwErrorIfEthermintWithLedgerButNotSupported(
|
|
124
121
|
chainId
|
|
125
122
|
);
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
const address = (() => {
|
|
129
|
-
if (isEthermintLike
|
|
130
|
-
return pubKey.getEthAddress();
|
|
126
|
+
if (isEthermintLike) {
|
|
127
|
+
return pubKey.pubKey.getEthAddress();
|
|
131
128
|
}
|
|
132
129
|
|
|
133
|
-
return pubKey.getCosmosAddress();
|
|
130
|
+
return pubKey.pubKey.getCosmosAddress();
|
|
134
131
|
})();
|
|
135
132
|
|
|
136
133
|
const bech32Address = new Bech32Address(address);
|
|
@@ -138,7 +135,7 @@ export class KeyRingCosmosService {
|
|
|
138
135
|
return {
|
|
139
136
|
name: this.keyRingService.getKeyRingName(vaultId),
|
|
140
137
|
algo: isEthermintLike ? "ethsecp256k1" : "secp256k1",
|
|
141
|
-
pubKey: pubKey.toBytes(),
|
|
138
|
+
pubKey: pubKey.pubKey.toBytes(),
|
|
142
139
|
address,
|
|
143
140
|
bech32Address: bech32Address.toBech32(
|
|
144
141
|
chainInfo.bech32Config?.bech32PrefixAccAddr ?? ""
|
|
@@ -165,15 +162,13 @@ export class KeyRingCosmosService {
|
|
|
165
162
|
coinTypes.push(...chainInfo.alternativeBIP44s.map((alt) => alt.coinType));
|
|
166
163
|
}
|
|
167
164
|
|
|
168
|
-
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);
|
|
169
|
-
|
|
170
165
|
const res: {
|
|
171
166
|
coinType: number;
|
|
172
167
|
bech32Address: string;
|
|
173
168
|
}[] = [];
|
|
174
169
|
|
|
175
170
|
for (const coinType of coinTypes) {
|
|
176
|
-
let pubKey: PubKeySecp256k1;
|
|
171
|
+
let pubKey: { pubKey: PubKeySecp256k1; coinType: number | undefined };
|
|
177
172
|
try {
|
|
178
173
|
pubKey = await this.keyRingService.getPubKeyWithNotFinalizedCoinType(
|
|
179
174
|
chainId,
|
|
@@ -181,17 +176,21 @@ export class KeyRingCosmosService {
|
|
|
181
176
|
DEFAULT_BIP44_PURPOSE,
|
|
182
177
|
coinType
|
|
183
178
|
);
|
|
179
|
+
// coin type이 명시되지 않는다면 coin type을 처리할 수 없는 keyring이라고 가정하고 처리하지 않는다.
|
|
180
|
+
if (pubKey.coinType == null) {
|
|
181
|
+
return [];
|
|
182
|
+
}
|
|
184
183
|
} catch (e) {
|
|
185
184
|
console.log(e);
|
|
186
185
|
continue;
|
|
187
186
|
}
|
|
188
187
|
|
|
189
188
|
const address = (() => {
|
|
190
|
-
if (
|
|
191
|
-
return pubKey.getEthAddress();
|
|
189
|
+
if (pubKey.coinType === 60) {
|
|
190
|
+
return pubKey.pubKey.getEthAddress();
|
|
192
191
|
}
|
|
193
192
|
|
|
194
|
-
return pubKey.getCosmosAddress();
|
|
193
|
+
return pubKey.pubKey.getCosmosAddress();
|
|
195
194
|
})();
|
|
196
195
|
|
|
197
196
|
const bech32Address = new Bech32Address(address);
|
|
@@ -239,7 +238,8 @@ export class KeyRingCosmosService {
|
|
|
239
238
|
if (chainInfo.hideInUI) {
|
|
240
239
|
throw new Error("Can't sign for hidden chain");
|
|
241
240
|
}
|
|
242
|
-
const
|
|
241
|
+
const key = await this.getKey(vaultId, chainId);
|
|
242
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
243
243
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
244
244
|
"force-enable-evm-ledger"
|
|
245
245
|
);
|
|
@@ -263,7 +263,6 @@ export class KeyRingCosmosService {
|
|
|
263
263
|
signDoc = trimAminoSignDoc(signDoc);
|
|
264
264
|
signDoc = sortObjectByKey(signDoc);
|
|
265
265
|
|
|
266
|
-
const key = await this.getKey(vaultId, chainId);
|
|
267
266
|
const bech32Prefix =
|
|
268
267
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
269
268
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -307,6 +306,7 @@ export class KeyRingCosmosService {
|
|
|
307
306
|
signOptions,
|
|
308
307
|
keyType: keyInfo.type,
|
|
309
308
|
keyInsensitive: keyInfo.insensitive,
|
|
309
|
+
isEthermintLike,
|
|
310
310
|
},
|
|
311
311
|
async (res: { newSignDoc: StdSignDoc; signature?: Uint8Array }) => {
|
|
312
312
|
let newSignDoc = res.newSignDoc;
|
|
@@ -385,7 +385,8 @@ export class KeyRingCosmosService {
|
|
|
385
385
|
|
|
386
386
|
const vaultId = this.keyRingService.selectedVaultId;
|
|
387
387
|
|
|
388
|
-
const
|
|
388
|
+
const key = await this.getKey(vaultId, chainId);
|
|
389
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
389
390
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
390
391
|
"force-enable-evm-ledger"
|
|
391
392
|
);
|
|
@@ -409,7 +410,6 @@ export class KeyRingCosmosService {
|
|
|
409
410
|
signDoc = trimAminoSignDoc(signDoc);
|
|
410
411
|
signDoc = sortObjectByKey(signDoc);
|
|
411
412
|
|
|
412
|
-
const key = await this.getKey(vaultId, chainId);
|
|
413
413
|
const bech32Prefix =
|
|
414
414
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
415
415
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -488,7 +488,8 @@ export class KeyRingCosmosService {
|
|
|
488
488
|
|
|
489
489
|
const vaultId = this.keyRingService.selectedVaultId;
|
|
490
490
|
|
|
491
|
-
const
|
|
491
|
+
const key = await this.getKey(vaultId, chainId);
|
|
492
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
492
493
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
493
494
|
"force-enable-evm-ledger"
|
|
494
495
|
);
|
|
@@ -512,7 +513,6 @@ export class KeyRingCosmosService {
|
|
|
512
513
|
signDoc = trimAminoSignDoc(signDoc);
|
|
513
514
|
signDoc = sortObjectByKey(signDoc);
|
|
514
515
|
|
|
515
|
-
const key = await this.getKey(vaultId, chainId);
|
|
516
516
|
const bech32Prefix =
|
|
517
517
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
518
518
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -625,7 +625,8 @@ export class KeyRingCosmosService {
|
|
|
625
625
|
|
|
626
626
|
const vaultId = this.keyRingService.selectedVaultId;
|
|
627
627
|
|
|
628
|
-
const
|
|
628
|
+
const key = await this.getKey(vaultId, chainId);
|
|
629
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
629
630
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
630
631
|
"force-enable-evm-ledger"
|
|
631
632
|
);
|
|
@@ -649,7 +650,6 @@ export class KeyRingCosmosService {
|
|
|
649
650
|
signDoc = trimAminoSignDoc(signDoc);
|
|
650
651
|
signDoc = sortObjectByKey(signDoc);
|
|
651
652
|
|
|
652
|
-
const key = await this.getKey(vaultId, chainId);
|
|
653
653
|
const bech32Prefix =
|
|
654
654
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
655
655
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -747,7 +747,8 @@ export class KeyRingCosmosService {
|
|
|
747
747
|
if (chainInfo.hideInUI) {
|
|
748
748
|
throw new Error("Can't sign for hidden chain");
|
|
749
749
|
}
|
|
750
|
-
const
|
|
750
|
+
const key = await this.getKey(vaultId, chainId);
|
|
751
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
751
752
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
752
753
|
"force-enable-evm-ledger"
|
|
753
754
|
);
|
|
@@ -763,7 +764,6 @@ export class KeyRingCosmosService {
|
|
|
763
764
|
);
|
|
764
765
|
}
|
|
765
766
|
|
|
766
|
-
const key = await this.getKey(vaultId, chainId);
|
|
767
767
|
const bech32Prefix =
|
|
768
768
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
769
769
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -787,6 +787,7 @@ export class KeyRingCosmosService {
|
|
|
787
787
|
signOptions,
|
|
788
788
|
keyType: keyInfo.type,
|
|
789
789
|
keyInsensitive: keyInfo.insensitive,
|
|
790
|
+
isEthermintLike,
|
|
790
791
|
},
|
|
791
792
|
async (res: { newSignDoc: StdSignDoc; signature?: Uint8Array }) => {
|
|
792
793
|
const newSignDoc = res.newSignDoc;
|
|
@@ -846,7 +847,8 @@ export class KeyRingCosmosService {
|
|
|
846
847
|
if (chainInfo.hideInUI) {
|
|
847
848
|
throw new Error("Can't sign for hidden chain");
|
|
848
849
|
}
|
|
849
|
-
const
|
|
850
|
+
const key = await this.getKey(vaultId, chainId);
|
|
851
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
850
852
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
851
853
|
"force-enable-evm-ledger"
|
|
852
854
|
);
|
|
@@ -862,7 +864,24 @@ export class KeyRingCosmosService {
|
|
|
862
864
|
);
|
|
863
865
|
}
|
|
864
866
|
|
|
865
|
-
|
|
867
|
+
if (!env.isInternalMsg && key.algo === "ethsecp256k1") {
|
|
868
|
+
const authInfo = AuthInfo.decode(signDoc.authInfoBytes);
|
|
869
|
+
if (
|
|
870
|
+
authInfo.signerInfos.length === 1 &&
|
|
871
|
+
authInfo.signerInfos[0].publicKey?.typeUrl ===
|
|
872
|
+
"/cosmos.crypto.secp256k1.PubKey"
|
|
873
|
+
) {
|
|
874
|
+
signDoc.authInfoBytes = AuthInfo.encode({
|
|
875
|
+
...authInfo,
|
|
876
|
+
signerInfos: [
|
|
877
|
+
{
|
|
878
|
+
...authInfo.signerInfos[0],
|
|
879
|
+
publicKey: encodePubKey(chainInfo, true, key.pubKey),
|
|
880
|
+
},
|
|
881
|
+
],
|
|
882
|
+
}).finish();
|
|
883
|
+
}
|
|
884
|
+
}
|
|
866
885
|
const bech32Prefix =
|
|
867
886
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
868
887
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -885,6 +904,7 @@ export class KeyRingCosmosService {
|
|
|
885
904
|
signOptions,
|
|
886
905
|
keyType: keyInfo.type,
|
|
887
906
|
keyInsensitive: keyInfo.insensitive,
|
|
907
|
+
isEthermintLike,
|
|
888
908
|
},
|
|
889
909
|
async (res: { newSignDocBytes: Uint8Array; signature?: Uint8Array }) => {
|
|
890
910
|
const newSignDocBytes = res.newSignDocBytes;
|
|
@@ -986,7 +1006,8 @@ export class KeyRingCosmosService {
|
|
|
986
1006
|
if (chainInfo.hideInUI) {
|
|
987
1007
|
throw new Error("Can't sign for hidden chain");
|
|
988
1008
|
}
|
|
989
|
-
const
|
|
1009
|
+
const key = await this.getKey(vaultId, chainId);
|
|
1010
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
990
1011
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
991
1012
|
"force-enable-evm-ledger"
|
|
992
1013
|
);
|
|
@@ -1002,7 +1023,6 @@ export class KeyRingCosmosService {
|
|
|
1002
1023
|
);
|
|
1003
1024
|
}
|
|
1004
1025
|
|
|
1005
|
-
const key = await this.getKey(vaultId, chainId);
|
|
1006
1026
|
const bech32Prefix =
|
|
1007
1027
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
1008
1028
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -1124,9 +1144,9 @@ export class KeyRingCosmosService {
|
|
|
1124
1144
|
signature: StdSignature
|
|
1125
1145
|
): Promise<boolean> {
|
|
1126
1146
|
const chainInfo = this.chainsService.getChainInfoOrThrow(chainId);
|
|
1127
|
-
const isEthermintLike = KeyRingService.isEthermintLike(chainInfo);
|
|
1128
|
-
|
|
1129
1147
|
const key = await this.getKey(vaultId, chainId);
|
|
1148
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
1149
|
+
|
|
1130
1150
|
const bech32Prefix = chainInfo.bech32Config?.bech32PrefixAccAddr ?? "";
|
|
1131
1151
|
const bech32Address = new Bech32Address(key.address).toBech32(bech32Prefix);
|
|
1132
1152
|
if (signer !== bech32Address) {
|
|
@@ -1195,7 +1215,8 @@ export class KeyRingCosmosService {
|
|
|
1195
1215
|
if (chainInfo.hideInUI) {
|
|
1196
1216
|
throw new Error("Can't sign for hidden chain");
|
|
1197
1217
|
}
|
|
1198
|
-
const
|
|
1218
|
+
const key = await this.getKey(vaultId, chainId);
|
|
1219
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
1199
1220
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
1200
1221
|
"force-enable-evm-ledger"
|
|
1201
1222
|
);
|
|
@@ -1247,7 +1268,6 @@ export class KeyRingCosmosService {
|
|
|
1247
1268
|
signDoc = trimAminoSignDoc(signDoc);
|
|
1248
1269
|
signDoc = sortObjectByKey(signDoc);
|
|
1249
1270
|
|
|
1250
|
-
const key = await this.getKey(vaultId, chainId);
|
|
1251
1271
|
const bech32Prefix =
|
|
1252
1272
|
this.chainsService.getChainInfoOrThrow(chainId).bech32Config
|
|
1253
1273
|
?.bech32PrefixAccAddr ?? "";
|
|
@@ -1436,9 +1456,8 @@ export class KeyRingCosmosService {
|
|
|
1436
1456
|
|
|
1437
1457
|
const ownerBech32 = Bech32Address.fromBech32(owner);
|
|
1438
1458
|
for (const accountInfo of interactionInfo.accountInfos) {
|
|
1439
|
-
const
|
|
1440
|
-
|
|
1441
|
-
);
|
|
1459
|
+
const key = await this.getKey(vaultId, chainId);
|
|
1460
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
1442
1461
|
|
|
1443
1462
|
if (
|
|
1444
1463
|
ownerBech32.toHex(false) !==
|
|
@@ -87,7 +87,8 @@ export class KeyRingEthereumService {
|
|
|
87
87
|
if (chainInfo.hideInUI) {
|
|
88
88
|
throw new Error("Can't sign for hidden chain");
|
|
89
89
|
}
|
|
90
|
-
const
|
|
90
|
+
const key = await this.keyRingCosmosService.getKey(vaultId, chainId);
|
|
91
|
+
const isEthermintLike = key.algo === "ethsecp256k1";
|
|
91
92
|
const evmInfo = ChainsService.getEVMInfo(chainInfo);
|
|
92
93
|
const forceEVMLedger = chainInfo.features?.includes(
|
|
93
94
|
"force-enable-evm-ledger"
|
|
@@ -124,7 +125,6 @@ export class KeyRingEthereumService {
|
|
|
124
125
|
).toLowerCase();
|
|
125
126
|
}
|
|
126
127
|
|
|
127
|
-
const key = await this.keyRingCosmosService.getKey(vaultId, chainId);
|
|
128
128
|
if (
|
|
129
129
|
signer !== key.bech32Address &&
|
|
130
130
|
signer !== key.ethereumHexAddress.toLowerCase()
|
|
@@ -348,8 +348,13 @@ export class KeyRingEthereumService {
|
|
|
348
348
|
const pubkey = await this.keyRingService.getPubKeySelected(
|
|
349
349
|
currentChainId
|
|
350
350
|
);
|
|
351
|
+
if (pubkey.coinType !== 60) {
|
|
352
|
+
throw new Error(
|
|
353
|
+
"Can't use ethereum json rpc if coin type is not 60"
|
|
354
|
+
);
|
|
355
|
+
}
|
|
351
356
|
const selectedAddress = `0x${Buffer.from(
|
|
352
|
-
pubkey.getEthAddress()
|
|
357
|
+
pubkey.pubKey.getEthAddress()
|
|
353
358
|
).toString("hex")}`;
|
|
354
359
|
|
|
355
360
|
return {
|
|
@@ -368,8 +373,13 @@ export class KeyRingEthereumService {
|
|
|
368
373
|
const pubkey = await this.keyRingService.getPubKeySelected(
|
|
369
374
|
currentChainId
|
|
370
375
|
);
|
|
376
|
+
if (pubkey.coinType !== 60) {
|
|
377
|
+
throw new Error(
|
|
378
|
+
"Can't use ethereum json rpc if coin type is not 60"
|
|
379
|
+
);
|
|
380
|
+
}
|
|
371
381
|
const selectedAddress = `0x${Buffer.from(
|
|
372
|
-
pubkey.getEthAddress()
|
|
382
|
+
pubkey.pubKey.getEthAddress()
|
|
373
383
|
).toString("hex")}`;
|
|
374
384
|
|
|
375
385
|
return {
|
|
@@ -402,8 +412,13 @@ export class KeyRingEthereumService {
|
|
|
402
412
|
const pubkey = await this.keyRingService.getPubKeySelected(
|
|
403
413
|
currentChainId
|
|
404
414
|
);
|
|
415
|
+
if (pubkey.coinType !== 60) {
|
|
416
|
+
throw new Error(
|
|
417
|
+
"Can't use ethereum json rpc if coin type is not 60"
|
|
418
|
+
);
|
|
419
|
+
}
|
|
405
420
|
const selectedAddress = `0x${Buffer.from(
|
|
406
|
-
pubkey.getEthAddress()
|
|
421
|
+
pubkey.pubKey.getEthAddress()
|
|
407
422
|
).toString("hex")}`;
|
|
408
423
|
|
|
409
424
|
return [selectedAddress];
|
|
@@ -413,8 +428,13 @@ export class KeyRingEthereumService {
|
|
|
413
428
|
const pubkey = await this.keyRingService.getPubKeySelected(
|
|
414
429
|
currentChainId
|
|
415
430
|
);
|
|
431
|
+
if (pubkey.coinType !== 60) {
|
|
432
|
+
throw new Error(
|
|
433
|
+
"Can't use ethereum json rpc if coin type is not 60"
|
|
434
|
+
);
|
|
435
|
+
}
|
|
416
436
|
const selectedAddress = `0x${Buffer.from(
|
|
417
|
-
pubkey.getEthAddress()
|
|
437
|
+
pubkey.pubKey.getEthAddress()
|
|
418
438
|
).toString("hex")}`;
|
|
419
439
|
|
|
420
440
|
return [selectedAddress];
|
|
@@ -477,8 +497,13 @@ export class KeyRingEthereumService {
|
|
|
477
497
|
const pubkey = await this.keyRingService.getPubKeySelected(
|
|
478
498
|
currentChainId
|
|
479
499
|
);
|
|
500
|
+
if (pubkey.coinType !== 60) {
|
|
501
|
+
throw new Error(
|
|
502
|
+
"Can't use ethereum json rpc if coin type is not 60"
|
|
503
|
+
);
|
|
504
|
+
}
|
|
480
505
|
const selectedAddress = `0x${Buffer.from(
|
|
481
|
-
pubkey.getEthAddress()
|
|
506
|
+
pubkey.pubKey.getEthAddress()
|
|
482
507
|
).toString("hex")}`;
|
|
483
508
|
|
|
484
509
|
const transactionCount = await this.request(
|
|
@@ -598,8 +623,13 @@ export class KeyRingEthereumService {
|
|
|
598
623
|
const pubkey = await this.keyRingService.getPubKeySelected(
|
|
599
624
|
currentChainId
|
|
600
625
|
);
|
|
626
|
+
if (pubkey.coinType !== 60) {
|
|
627
|
+
throw new Error(
|
|
628
|
+
"Can't use ethereum json rpc if coin type is not 60"
|
|
629
|
+
);
|
|
630
|
+
}
|
|
601
631
|
const selectedAddress = `0x${Buffer.from(
|
|
602
|
-
pubkey.getEthAddress()
|
|
632
|
+
pubkey.pubKey.getEthAddress()
|
|
603
633
|
).toString("hex")}`;
|
|
604
634
|
|
|
605
635
|
const transactionCount = await this.request(
|
|
@@ -38,7 +38,14 @@ export class KeyRingKeystoneService {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
getPubKey(
|
|
41
|
+
getPubKey(
|
|
42
|
+
vault: Vault,
|
|
43
|
+
purpose: number,
|
|
44
|
+
coinType: number
|
|
45
|
+
): {
|
|
46
|
+
pubKey: PubKeySecp256k1;
|
|
47
|
+
coinType: number;
|
|
48
|
+
} {
|
|
42
49
|
let bytes;
|
|
43
50
|
if (vault.insensitive["keys"]) {
|
|
44
51
|
const path = Object.keys(vault.insensitive["keys"]).find((path) => {
|
|
@@ -59,7 +66,10 @@ export class KeyRingKeystoneService {
|
|
|
59
66
|
} else {
|
|
60
67
|
throw new Error(`Keystone is not initialized.`);
|
|
61
68
|
}
|
|
62
|
-
return
|
|
69
|
+
return {
|
|
70
|
+
pubKey: new PubKeySecp256k1(bytes),
|
|
71
|
+
coinType,
|
|
72
|
+
};
|
|
63
73
|
}
|
|
64
74
|
|
|
65
75
|
sign(): {
|
|
@@ -3,10 +3,10 @@ import { Buffer } from "buffer/";
|
|
|
3
3
|
import { PubKeySecp256k1, PubKeyStarknet } from "@keplr-wallet/crypto";
|
|
4
4
|
import { KeplrError } from "@keplr-wallet/router";
|
|
5
5
|
import { ModularChainInfo } from "@keplr-wallet/types";
|
|
6
|
-
import { KeyRingService } from "../keyring";
|
|
7
6
|
import { Network as BitcoinNetwork } from "bitcoinjs-lib";
|
|
8
7
|
import { PubKeyBitcoinCompatible } from "@keplr-wallet/crypto";
|
|
9
8
|
import { Descriptor } from "../keyring-bitcoin";
|
|
9
|
+
import { App, AppCoinType } from "@keplr-wallet/ledger-cosmos";
|
|
10
10
|
|
|
11
11
|
export class KeyRingLedgerService {
|
|
12
12
|
async init(): Promise<void> {
|
|
@@ -43,9 +43,12 @@ export class KeyRingLedgerService {
|
|
|
43
43
|
getPubKey(
|
|
44
44
|
vault: Vault,
|
|
45
45
|
_purpose: number,
|
|
46
|
-
|
|
46
|
+
coinType: number,
|
|
47
47
|
modularChainInfo: ModularChainInfo
|
|
48
|
-
):
|
|
48
|
+
): {
|
|
49
|
+
pubKey: PubKeySecp256k1;
|
|
50
|
+
coinType: number;
|
|
51
|
+
} {
|
|
49
52
|
if ("starknet" in modularChainInfo) {
|
|
50
53
|
throw new Error(
|
|
51
54
|
"'getPubKeyStarknet' should be called for Starknet chain"
|
|
@@ -58,10 +61,7 @@ export class KeyRingLedgerService {
|
|
|
58
61
|
|
|
59
62
|
let app = "Cosmos";
|
|
60
63
|
|
|
61
|
-
|
|
62
|
-
modularChainInfo.cosmos
|
|
63
|
-
);
|
|
64
|
-
if (isEthermintLike) {
|
|
64
|
+
if (coinType === 60) {
|
|
65
65
|
app = "Ethereum";
|
|
66
66
|
if (!vault.insensitive[app]) {
|
|
67
67
|
throw new KeplrError(
|
|
@@ -83,6 +83,12 @@ export class KeyRingLedgerService {
|
|
|
83
83
|
if (vault.insensitive["THORChain"]) {
|
|
84
84
|
app = "THORChain";
|
|
85
85
|
}
|
|
86
|
+
|
|
87
|
+
const appCoinType = AppCoinType[app as App];
|
|
88
|
+
if (appCoinType == null) {
|
|
89
|
+
throw new Error(`CoinType is null: ${app}`);
|
|
90
|
+
}
|
|
91
|
+
coinType = appCoinType;
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
if (!vault.insensitive[app]) {
|
|
@@ -93,7 +99,10 @@ export class KeyRingLedgerService {
|
|
|
93
99
|
(vault.insensitive[app] as any)["pubKey"] as string,
|
|
94
100
|
"hex"
|
|
95
101
|
);
|
|
96
|
-
return
|
|
102
|
+
return {
|
|
103
|
+
pubKey: new PubKeySecp256k1(bytes),
|
|
104
|
+
coinType,
|
|
105
|
+
};
|
|
97
106
|
}
|
|
98
107
|
|
|
99
108
|
getPubKeyStarknet(
|
|
@@ -65,14 +65,21 @@ export class KeyRingMnemonicService {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
getPubKey(
|
|
68
|
+
getPubKey(
|
|
69
|
+
vault: Vault,
|
|
70
|
+
purpose: number,
|
|
71
|
+
coinType: number
|
|
72
|
+
): { pubKey: PubKeySecp256k1; coinType: number } {
|
|
69
73
|
const bip44Path = this.getBIP44PathFromVault(vault);
|
|
70
74
|
|
|
71
75
|
const tag = `pubKey-m/${purpose}'/${coinType}'/${bip44Path.account}'/${bip44Path.change}/${bip44Path.addressIndex}`;
|
|
72
76
|
|
|
73
77
|
if (vault.insensitive[tag]) {
|
|
74
78
|
const pubKey = Buffer.from(vault.insensitive[tag] as string, "hex");
|
|
75
|
-
return
|
|
79
|
+
return {
|
|
80
|
+
coinType,
|
|
81
|
+
pubKey: new PubKeySecp256k1(pubKey),
|
|
82
|
+
};
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
const privKey = this.getPrivKey(vault, purpose, coinType);
|
|
@@ -84,7 +91,10 @@ export class KeyRingMnemonicService {
|
|
|
84
91
|
[tag]: pubKeyText,
|
|
85
92
|
});
|
|
86
93
|
|
|
87
|
-
return
|
|
94
|
+
return {
|
|
95
|
+
coinType,
|
|
96
|
+
pubKey,
|
|
97
|
+
};
|
|
88
98
|
}
|
|
89
99
|
|
|
90
100
|
getPubKeyBitcoin(
|
|
@@ -44,13 +44,16 @@ export class KeyRingPrivateKeyService {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
getPubKey(vault: Vault): PubKeySecp256k1 {
|
|
47
|
+
getPubKey(vault: Vault): { pubKey: PubKeySecp256k1; coinType: undefined } {
|
|
48
48
|
const publicKeyBytes = Buffer.from(
|
|
49
49
|
vault.insensitive["publicKey"] as string,
|
|
50
50
|
"hex"
|
|
51
51
|
);
|
|
52
52
|
|
|
53
|
-
return
|
|
53
|
+
return {
|
|
54
|
+
pubKey: new PubKeySecp256k1(publicKeyBytes),
|
|
55
|
+
coinType: undefined,
|
|
56
|
+
};
|
|
54
57
|
}
|
|
55
58
|
|
|
56
59
|
sign(
|
|
@@ -197,7 +197,8 @@ export class KeyRingStarknetService {
|
|
|
197
197
|
);
|
|
198
198
|
|
|
199
199
|
return {
|
|
200
|
-
pubKey: await this.keyRingService.getPubKey(chainId, vaultId)
|
|
200
|
+
pubKey: (await this.keyRingService.getPubKey(chainId, vaultId))
|
|
201
|
+
.pubKey,
|
|
201
202
|
salt: Hash.sha256(Buffer.concat([sig.r, sig.s])).slice(0, 24),
|
|
202
203
|
classHash: Buffer.from(EthAccountUpgradeableClassHash, "hex"),
|
|
203
204
|
};
|
|
@@ -325,8 +325,11 @@ export class TokenScanService {
|
|
|
325
325
|
if (this.chainsService.isEvmOnlyChain(chainId)) {
|
|
326
326
|
const evmInfo = this.chainsService.getEVMInfoOrThrow(chainId);
|
|
327
327
|
const pubkey = await this.keyRingService.getPubKey(chainId, vaultId);
|
|
328
|
+
if (pubkey.coinType !== 60) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
328
331
|
const ethereumHexAddress = `0x${Buffer.from(
|
|
329
|
-
pubkey.getEthAddress()
|
|
332
|
+
pubkey.pubKey.getEthAddress()
|
|
330
333
|
).toString("hex")}`;
|
|
331
334
|
|
|
332
335
|
const res = await simpleFetch<{
|