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