@keplr-wallet/provider-mock 0.12.0-alpha.0 → 0.12.0-alpha.2
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/LICENSE +8 -2
- package/build/index.js +5 -1
- package/build/index.js.map +1 -1
- package/build/mock.d.ts +35 -12
- package/build/mock.js +89 -28
- package/build/mock.js.map +1 -1
- package/package.json +9 -10
- package/src/mock.ts +163 -33
package/LICENSE
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
License: Apache2.0
|
1
|
+
License: Apache2.0 (Extension) / All rights reserved (Mobile)
|
2
|
+
|
3
|
+
## Keplr Extension License:
|
2
4
|
|
3
5
|
Apache License
|
4
6
|
Version 2.0, January 2004
|
@@ -200,4 +202,8 @@ License: Apache2.0
|
|
200
202
|
distributed under the License is distributed on an "AS IS" BASIS,
|
201
203
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
202
204
|
See the License for the specific language governing permissions and
|
203
|
-
limitations under the License.
|
205
|
+
limitations under the License.
|
206
|
+
|
207
|
+
## Keplr Mobile License
|
208
|
+
|
209
|
+
Copyright (c) 2021 Chainapsis Inc. All rights reserved.
|
package/build/index.js
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
"use strict";
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
3
|
if (k2 === undefined) k2 = k;
|
4
|
-
Object.
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
7
|
+
}
|
8
|
+
Object.defineProperty(o, k2, desc);
|
5
9
|
}) : (function(o, m, k, k2) {
|
6
10
|
if (k2 === undefined) k2 = k;
|
7
11
|
o[k2] = m[k];
|
package/build/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,yCAAuB"}
|
package/build/mock.d.ts
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
import { EthSignType, Keplr, KeplrIntereactionOptions, KeplrMode, KeplrSignOptions, Key } from "@keplr-wallet/types";
|
2
|
-
import {
|
3
|
-
import
|
4
|
-
import { OfflineDirectSigner } from "@cosmjs/proto-signing";
|
5
|
-
import { DirectSignResponse } from "@cosmjs/proto-signing/build/signer";
|
1
|
+
import { EthSignType, Keplr, KeplrIntereactionOptions, KeplrMode, KeplrSignOptions, Key, AminoSignResponse, BroadcastMode, StdSignature, StdSignDoc, OfflineAminoSigner, OfflineDirectSigner, DirectSignResponse, ICNSAdr36Signatures, ChainInfoWithoutEndpoints, SecretUtils, SettledResponses } from "@keplr-wallet/types";
|
2
|
+
import { PrivKeySecp256k1 } from "@keplr-wallet/crypto";
|
3
|
+
import Long from "long";
|
6
4
|
export declare class MockKeplr implements Keplr {
|
7
5
|
readonly sendTxFn: (chainId: string, stdTx: Uint8Array, mode: BroadcastMode) => Promise<Uint8Array>;
|
8
6
|
readonly chainInfos: {
|
@@ -16,9 +14,9 @@ export declare class MockKeplr implements Keplr {
|
|
16
14
|
readonly mode: KeplrMode;
|
17
15
|
defaultOptions: KeplrIntereactionOptions;
|
18
16
|
readonly walletMap: {
|
19
|
-
[chainId: string]:
|
17
|
+
[chainId: string]: PrivKeySecp256k1 | undefined;
|
20
18
|
};
|
21
|
-
|
19
|
+
getWallet(chainId: string): PrivKeySecp256k1;
|
22
20
|
constructor(sendTxFn: (chainId: string, stdTx: Uint8Array, mode: BroadcastMode) => Promise<Uint8Array>, chainInfos: {
|
23
21
|
readonly chainId: string;
|
24
22
|
readonly bech32Config: {
|
@@ -30,18 +28,43 @@ export declare class MockKeplr implements Keplr {
|
|
30
28
|
enigmaEncrypt(): Promise<Uint8Array>;
|
31
29
|
experimentalSuggestChain(): Promise<void>;
|
32
30
|
getEnigmaPubKey(): Promise<Uint8Array>;
|
33
|
-
getEnigmaUtils(): SecretUtils;
|
31
|
+
getEnigmaUtils(_chainId: string): SecretUtils;
|
34
32
|
getKey(chainId: string): Promise<Key>;
|
33
|
+
getKeysSettled(chainIds: string[]): Promise<SettledResponses<Key>>;
|
35
34
|
signArbitrary(_chainId: string, _signer: string, _data: string | Uint8Array): Promise<StdSignature>;
|
36
35
|
verifyArbitrary(_chainId: string, _signer: string, _data: string | Uint8Array, _signature: StdSignature): Promise<boolean>;
|
37
36
|
signEthereum(_chainId: string, _signer: string, _data: string | Uint8Array, _type: EthSignType): Promise<Uint8Array>;
|
38
|
-
|
37
|
+
signICNSAdr36(_chainId: string, _contractAddress: string, _owner: string, _username: string, _addressChainIds: string[]): Promise<ICNSAdr36Signatures>;
|
38
|
+
getOfflineSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner;
|
39
39
|
getSecret20ViewingKey(): Promise<string>;
|
40
40
|
sendTx(chainId: string, stdTx: Uint8Array, mode: BroadcastMode): Promise<Uint8Array>;
|
41
41
|
signAmino(chainId: string, signer: string, signDoc: StdSignDoc, _?: KeplrSignOptions): Promise<AminoSignResponse>;
|
42
|
-
signDirect(
|
42
|
+
signDirect(chainId: string, signer: string, signDoc: {
|
43
|
+
/** SignDoc bodyBytes */
|
44
|
+
bodyBytes?: Uint8Array | null;
|
45
|
+
/** SignDoc authInfoBytes */
|
46
|
+
authInfoBytes?: Uint8Array | null;
|
47
|
+
/** SignDoc chainId */
|
48
|
+
chainId?: string | null;
|
49
|
+
/** SignDoc accountNumber */
|
50
|
+
accountNumber?: Long | null;
|
51
|
+
}, _?: KeplrSignOptions): Promise<DirectSignResponse>;
|
43
52
|
suggestToken(): Promise<void>;
|
44
53
|
getEnigmaTxEncryptionKey(_chainId: string, _nonce: Uint8Array): Promise<Uint8Array>;
|
45
|
-
getOfflineSignerAuto(_chainId: string): Promise<
|
46
|
-
getOfflineSignerOnlyAmino(
|
54
|
+
getOfflineSignerAuto(_chainId: string): Promise<OfflineAminoSigner | OfflineDirectSigner>;
|
55
|
+
getOfflineSignerOnlyAmino(chainId: string): OfflineAminoSigner;
|
56
|
+
experimentalSignEIP712CosmosTx_v0(_chainId: string, _signer: string, _eip712: {
|
57
|
+
types: Record<string, {
|
58
|
+
name: string;
|
59
|
+
type: string;
|
60
|
+
}[] | undefined>;
|
61
|
+
domain: Record<string, any>;
|
62
|
+
primaryType: string;
|
63
|
+
}, _signDoc: StdSignDoc, _signOptions?: KeplrSignOptions): Promise<AminoSignResponse>;
|
64
|
+
getChainInfosWithoutEndpoints(): Promise<ChainInfoWithoutEndpoints[]>;
|
65
|
+
disable(_chainIds?: string | string[]): Promise<void>;
|
66
|
+
changeKeyRingName(_opts: {
|
67
|
+
defaultName: string;
|
68
|
+
editable?: boolean | undefined;
|
69
|
+
}): Promise<string>;
|
47
70
|
}
|
package/build/mock.js
CHANGED
@@ -10,10 +10,22 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
12
|
exports.MockKeplr = void 0;
|
13
|
-
const launchpad_1 = require("@cosmjs/launchpad");
|
14
13
|
const cosmos_1 = require("@keplr-wallet/cosmos");
|
15
14
|
const provider_1 = require("@keplr-wallet/provider");
|
15
|
+
const crypto_1 = require("@keplr-wallet/crypto");
|
16
|
+
const tx_1 = require("@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx");
|
16
17
|
class MockKeplr {
|
18
|
+
getWallet(chainId) {
|
19
|
+
if (!this.walletMap[chainId]) {
|
20
|
+
const chainInfo = this.chainInfos.find((info) => info.chainId === chainId);
|
21
|
+
if (!chainInfo) {
|
22
|
+
throw new Error("Unknown chain");
|
23
|
+
}
|
24
|
+
this.walletMap[chainId] = new crypto_1.PrivKeySecp256k1(crypto_1.Mnemonic.generateWalletFromMnemonic(this.mnemonic));
|
25
|
+
}
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
27
|
+
return this.walletMap[chainId];
|
28
|
+
}
|
17
29
|
constructor(sendTxFn, chainInfos, mnemonic) {
|
18
30
|
this.sendTxFn = sendTxFn;
|
19
31
|
this.chainInfos = chainInfos;
|
@@ -23,19 +35,6 @@ class MockKeplr {
|
|
23
35
|
this.defaultOptions = {};
|
24
36
|
this.walletMap = {};
|
25
37
|
}
|
26
|
-
getHdWallet(chainId) {
|
27
|
-
return __awaiter(this, void 0, void 0, function* () {
|
28
|
-
if (!this.walletMap[chainId]) {
|
29
|
-
const chainInfo = this.chainInfos.find((info) => info.chainId === chainId);
|
30
|
-
if (!chainInfo) {
|
31
|
-
throw new Error("Unknown chain");
|
32
|
-
}
|
33
|
-
this.walletMap[chainId] = yield launchpad_1.Secp256k1HdWallet.fromMnemonic(this.mnemonic, launchpad_1.makeCosmoshubPath(0), chainInfo.bech32Config.bech32PrefixAccAddr);
|
34
|
-
}
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
36
|
-
return this.walletMap[chainId];
|
37
|
-
});
|
38
|
-
}
|
39
38
|
enable() {
|
40
39
|
// noop.
|
41
40
|
return Promise.resolve(undefined);
|
@@ -52,22 +51,44 @@ class MockKeplr {
|
|
52
51
|
getEnigmaPubKey() {
|
53
52
|
throw new Error("Not implemented");
|
54
53
|
}
|
55
|
-
getEnigmaUtils() {
|
54
|
+
getEnigmaUtils(_chainId) {
|
56
55
|
throw new Error("Not implemented");
|
57
56
|
}
|
58
57
|
getKey(chainId) {
|
59
58
|
return __awaiter(this, void 0, void 0, function* () {
|
60
|
-
const
|
59
|
+
const wallet = this.getWallet(chainId);
|
61
60
|
return {
|
62
|
-
name: "",
|
61
|
+
name: "mock",
|
63
62
|
algo: "secp256k1",
|
64
|
-
pubKey:
|
65
|
-
address:
|
66
|
-
bech32Address:
|
63
|
+
pubKey: wallet.getPubKey().toBytes(),
|
64
|
+
address: wallet.getPubKey().getCosmosAddress(),
|
65
|
+
bech32Address: new cosmos_1.Bech32Address(wallet.getPubKey().getCosmosAddress()).toBech32(this.chainInfos.find((c) => c.chainId === chainId).bech32Config
|
66
|
+
.bech32PrefixAccAddr),
|
67
67
|
isNanoLedger: false,
|
68
|
+
isKeystone: false,
|
68
69
|
};
|
69
70
|
});
|
70
71
|
}
|
72
|
+
getKeysSettled(chainIds) {
|
73
|
+
return __awaiter(this, void 0, void 0, function* () {
|
74
|
+
return chainIds.map((chainId) => {
|
75
|
+
const wallet = this.getWallet(chainId);
|
76
|
+
return {
|
77
|
+
status: "fulfilled",
|
78
|
+
value: {
|
79
|
+
name: "mock",
|
80
|
+
algo: "secp256k1",
|
81
|
+
pubKey: wallet.getPubKey().toBytes(),
|
82
|
+
address: wallet.getPubKey().getCosmosAddress(),
|
83
|
+
bech32Address: new cosmos_1.Bech32Address(wallet.getPubKey().getCosmosAddress()).toBech32(this.chainInfos.find((c) => c.chainId === chainId).bech32Config
|
84
|
+
.bech32PrefixAccAddr),
|
85
|
+
isNanoLedger: false,
|
86
|
+
isKeystone: false,
|
87
|
+
},
|
88
|
+
};
|
89
|
+
});
|
90
|
+
});
|
91
|
+
}
|
71
92
|
signArbitrary(_chainId, _signer, _data) {
|
72
93
|
throw new Error("Not implemented");
|
73
94
|
}
|
@@ -77,6 +98,9 @@ class MockKeplr {
|
|
77
98
|
signEthereum(_chainId, _signer, _data, _type) {
|
78
99
|
throw new Error("Not implemented");
|
79
100
|
}
|
101
|
+
signICNSAdr36(_chainId, _contractAddress, _owner, _username, _addressChainIds) {
|
102
|
+
throw new Error("Not implemented");
|
103
|
+
}
|
80
104
|
getOfflineSigner(chainId) {
|
81
105
|
return new provider_1.CosmJSOfflineSigner(chainId, this);
|
82
106
|
}
|
@@ -88,16 +112,41 @@ class MockKeplr {
|
|
88
112
|
}
|
89
113
|
signAmino(chainId, signer, signDoc, _) {
|
90
114
|
return __awaiter(this, void 0, void 0, function* () {
|
91
|
-
const
|
92
|
-
const
|
93
|
-
if (
|
115
|
+
const wallet = yield this.getWallet(chainId);
|
116
|
+
const key = yield this.getKey(chainId);
|
117
|
+
if (signer !== key.bech32Address) {
|
94
118
|
throw new Error("Unmatched signer");
|
95
119
|
}
|
96
|
-
|
120
|
+
const signature = wallet.sign((0, cosmos_1.serializeSignDoc)(signDoc));
|
121
|
+
return {
|
122
|
+
signed: signDoc,
|
123
|
+
signature: (0, cosmos_1.encodeSecp256k1Signature)(wallet.getPubKey().toBytes(), signature),
|
124
|
+
};
|
97
125
|
});
|
98
126
|
}
|
99
|
-
signDirect() {
|
100
|
-
|
127
|
+
signDirect(chainId, signer, signDoc, _) {
|
128
|
+
return __awaiter(this, void 0, void 0, function* () {
|
129
|
+
const wallet = yield this.getWallet(chainId);
|
130
|
+
const key = yield this.getKey(chainId);
|
131
|
+
if (signer !== key.bech32Address) {
|
132
|
+
throw new Error("Unmatched signer");
|
133
|
+
}
|
134
|
+
const signature = wallet.sign(tx_1.SignDoc.encode(tx_1.SignDoc.fromPartial({
|
135
|
+
bodyBytes: signDoc.bodyBytes,
|
136
|
+
authInfoBytes: signDoc.authInfoBytes,
|
137
|
+
chainId: signDoc.chainId,
|
138
|
+
accountNumber: signDoc.accountNumber.toString(),
|
139
|
+
})).finish());
|
140
|
+
return {
|
141
|
+
signed: {
|
142
|
+
bodyBytes: signDoc.bodyBytes,
|
143
|
+
authInfoBytes: signDoc.authInfoBytes,
|
144
|
+
chainId: signDoc.chainId,
|
145
|
+
accountNumber: signDoc.accountNumber,
|
146
|
+
},
|
147
|
+
signature: (0, cosmos_1.encodeSecp256k1Signature)(wallet.getPubKey().toBytes(), signature),
|
148
|
+
};
|
149
|
+
});
|
101
150
|
}
|
102
151
|
suggestToken() {
|
103
152
|
throw new Error("Not implemented");
|
@@ -108,8 +157,20 @@ class MockKeplr {
|
|
108
157
|
getOfflineSignerAuto(_chainId) {
|
109
158
|
throw new Error("Not implemented");
|
110
159
|
}
|
111
|
-
getOfflineSignerOnlyAmino(
|
112
|
-
|
160
|
+
getOfflineSignerOnlyAmino(chainId) {
|
161
|
+
return new provider_1.CosmJSOfflineSignerOnlyAmino(chainId, this);
|
162
|
+
}
|
163
|
+
experimentalSignEIP712CosmosTx_v0(_chainId, _signer, _eip712, _signDoc, _signOptions = {}) {
|
164
|
+
throw new Error("Not yet implemented");
|
165
|
+
}
|
166
|
+
getChainInfosWithoutEndpoints() {
|
167
|
+
throw new Error("Not yet implemented");
|
168
|
+
}
|
169
|
+
disable(_chainIds) {
|
170
|
+
throw new Error("Not yet implemented");
|
171
|
+
}
|
172
|
+
changeKeyRingName(_opts) {
|
173
|
+
throw new Error("Not yet implemented");
|
113
174
|
}
|
114
175
|
}
|
115
176
|
exports.MockKeplr = MockKeplr;
|
package/build/mock.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;;;;;;;;;;;AAmBA,iDAI8B;AAC9B,qDAGgC;AAChC,iDAAkE;AAElE,uEAAyE;AAEzE,MAAa,SAAS;IAUpB,SAAS,CAAC,OAAe;QACvB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;YAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CACpC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,OAAO,KAAK,OAAO,CACnC,CAAC;YAEF,IAAI,CAAC,SAAS,EAAE;gBACd,MAAM,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC;aAClC;YAED,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,GAAG,IAAI,yBAAgB,CAC5C,iBAAQ,CAAC,0BAA0B,CAAC,IAAI,CAAC,QAAQ,CAAC,CACnD,CAAC;SACH;QAED,oEAA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,eAAiC,EAAE;QAEnC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,6BAA6B;QAC3B,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,OAAO,CAAC,SAA6B;QACnC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;IAED,iBAAiB,CAAC,KAGjB;QACC,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACzC,CAAC;CACF;AA/RD,8BA+RC"}
|
package/package.json
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@keplr-wallet/provider-mock",
|
3
|
-
"version": "0.12.0-alpha.
|
3
|
+
"version": "0.12.0-alpha.2",
|
4
4
|
"main": "build/index.js",
|
5
5
|
"author": "chainapsis",
|
6
6
|
"license": "Apache-2.0",
|
7
|
-
"private": false,
|
8
7
|
"publishConfig": {
|
9
8
|
"access": "public"
|
10
9
|
},
|
@@ -17,15 +16,15 @@
|
|
17
16
|
"lint-fix": "eslint --fix \"src/**/*\" && prettier --write \"src/**/*\""
|
18
17
|
},
|
19
18
|
"dependencies": {
|
20
|
-
"@
|
21
|
-
"@
|
22
|
-
"@keplr-wallet/
|
23
|
-
"@keplr-wallet/provider": "0.12.0-alpha.
|
24
|
-
"@keplr-wallet/router": "0.12.0-alpha.
|
25
|
-
"@keplr-wallet/types": "0.12.0-alpha.
|
19
|
+
"@keplr-wallet/cosmos": "0.12.0-alpha.2",
|
20
|
+
"@keplr-wallet/crypto": "0.12.0-alpha.2",
|
21
|
+
"@keplr-wallet/proto-types": "0.12.0-alpha.2",
|
22
|
+
"@keplr-wallet/provider": "0.12.0-alpha.2",
|
23
|
+
"@keplr-wallet/router": "0.12.0-alpha.2",
|
24
|
+
"@keplr-wallet/types": "0.12.0-alpha.2",
|
26
25
|
"buffer": "^6.0.3",
|
27
26
|
"deepmerge": "^4.2.2",
|
28
|
-
"
|
27
|
+
"long": "^4.0.0"
|
29
28
|
},
|
30
|
-
"gitHead": "
|
29
|
+
"gitHead": "ac984666c53de8f9325d02ff62f1a0febcafa310"
|
31
30
|
}
|
package/src/mock.ts
CHANGED
@@ -5,21 +5,30 @@ import {
|
|
5
5
|
KeplrMode,
|
6
6
|
KeplrSignOptions,
|
7
7
|
Key,
|
8
|
-
} from "@keplr-wallet/types";
|
9
|
-
import {
|
10
8
|
AminoSignResponse,
|
11
9
|
BroadcastMode,
|
12
|
-
makeCosmoshubPath,
|
13
|
-
OfflineSigner,
|
14
|
-
Secp256k1HdWallet,
|
15
10
|
StdSignature,
|
16
11
|
StdSignDoc,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
12
|
+
OfflineAminoSigner,
|
13
|
+
OfflineDirectSigner,
|
14
|
+
DirectSignResponse,
|
15
|
+
ICNSAdr36Signatures,
|
16
|
+
ChainInfoWithoutEndpoints,
|
17
|
+
SecretUtils,
|
18
|
+
SettledResponses,
|
19
|
+
} from "@keplr-wallet/types";
|
20
|
+
import {
|
21
|
+
Bech32Address,
|
22
|
+
encodeSecp256k1Signature,
|
23
|
+
serializeSignDoc,
|
24
|
+
} from "@keplr-wallet/cosmos";
|
25
|
+
import {
|
26
|
+
CosmJSOfflineSigner,
|
27
|
+
CosmJSOfflineSignerOnlyAmino,
|
28
|
+
} from "@keplr-wallet/provider";
|
29
|
+
import { Mnemonic, PrivKeySecp256k1 } from "@keplr-wallet/crypto";
|
30
|
+
import Long from "long";
|
31
|
+
import { SignDoc } from "@keplr-wallet/proto-types/cosmos/tx/v1beta1/tx";
|
23
32
|
|
24
33
|
export class MockKeplr implements Keplr {
|
25
34
|
readonly version: string = "0.0.1";
|
@@ -28,10 +37,10 @@ export class MockKeplr implements Keplr {
|
|
28
37
|
public defaultOptions: KeplrIntereactionOptions = {};
|
29
38
|
|
30
39
|
public readonly walletMap: {
|
31
|
-
[chainId: string]:
|
40
|
+
[chainId: string]: PrivKeySecp256k1 | undefined;
|
32
41
|
} = {};
|
33
42
|
|
34
|
-
|
43
|
+
getWallet(chainId: string): PrivKeySecp256k1 {
|
35
44
|
if (!this.walletMap[chainId]) {
|
36
45
|
const chainInfo = this.chainInfos.find(
|
37
46
|
(info) => info.chainId === chainId
|
@@ -41,10 +50,8 @@ export class MockKeplr implements Keplr {
|
|
41
50
|
throw new Error("Unknown chain");
|
42
51
|
}
|
43
52
|
|
44
|
-
this.walletMap[chainId] =
|
45
|
-
this.mnemonic
|
46
|
-
makeCosmoshubPath(0),
|
47
|
-
chainInfo.bech32Config.bech32PrefixAccAddr
|
53
|
+
this.walletMap[chainId] = new PrivKeySecp256k1(
|
54
|
+
Mnemonic.generateWalletFromMnemonic(this.mnemonic)
|
48
55
|
);
|
49
56
|
}
|
50
57
|
|
@@ -88,23 +95,53 @@ export class MockKeplr implements Keplr {
|
|
88
95
|
throw new Error("Not implemented");
|
89
96
|
}
|
90
97
|
|
91
|
-
getEnigmaUtils(): SecretUtils {
|
98
|
+
getEnigmaUtils(_chainId: string): SecretUtils {
|
92
99
|
throw new Error("Not implemented");
|
93
100
|
}
|
94
101
|
|
95
102
|
async getKey(chainId: string): Promise<Key> {
|
96
|
-
const
|
103
|
+
const wallet = this.getWallet(chainId);
|
97
104
|
|
98
105
|
return {
|
99
|
-
name: "",
|
106
|
+
name: "mock",
|
100
107
|
algo: "secp256k1",
|
101
|
-
pubKey:
|
102
|
-
address:
|
103
|
-
bech32Address:
|
108
|
+
pubKey: wallet.getPubKey().toBytes(),
|
109
|
+
address: wallet.getPubKey().getCosmosAddress(),
|
110
|
+
bech32Address: new Bech32Address(
|
111
|
+
wallet.getPubKey().getCosmosAddress()
|
112
|
+
).toBech32(
|
113
|
+
this.chainInfos.find((c) => c.chainId === chainId)!.bech32Config
|
114
|
+
.bech32PrefixAccAddr
|
115
|
+
),
|
104
116
|
isNanoLedger: false,
|
117
|
+
isKeystone: false,
|
105
118
|
};
|
106
119
|
}
|
107
120
|
|
121
|
+
async getKeysSettled(chainIds: string[]): Promise<SettledResponses<Key>> {
|
122
|
+
return chainIds.map((chainId) => {
|
123
|
+
const wallet = this.getWallet(chainId);
|
124
|
+
|
125
|
+
return {
|
126
|
+
status: "fulfilled",
|
127
|
+
value: {
|
128
|
+
name: "mock",
|
129
|
+
algo: "secp256k1",
|
130
|
+
pubKey: wallet.getPubKey().toBytes(),
|
131
|
+
address: wallet.getPubKey().getCosmosAddress(),
|
132
|
+
bech32Address: new Bech32Address(
|
133
|
+
wallet.getPubKey().getCosmosAddress()
|
134
|
+
).toBech32(
|
135
|
+
this.chainInfos.find((c) => c.chainId === chainId)!.bech32Config
|
136
|
+
.bech32PrefixAccAddr
|
137
|
+
),
|
138
|
+
isNanoLedger: false,
|
139
|
+
isKeystone: false,
|
140
|
+
},
|
141
|
+
};
|
142
|
+
});
|
143
|
+
}
|
144
|
+
|
108
145
|
signArbitrary(
|
109
146
|
_chainId: string,
|
110
147
|
_signer: string,
|
@@ -131,7 +168,17 @@ export class MockKeplr implements Keplr {
|
|
131
168
|
throw new Error("Not implemented");
|
132
169
|
}
|
133
170
|
|
134
|
-
|
171
|
+
signICNSAdr36(
|
172
|
+
_chainId: string,
|
173
|
+
_contractAddress: string,
|
174
|
+
_owner: string,
|
175
|
+
_username: string,
|
176
|
+
_addressChainIds: string[]
|
177
|
+
): Promise<ICNSAdr36Signatures> {
|
178
|
+
throw new Error("Not implemented");
|
179
|
+
}
|
180
|
+
|
181
|
+
getOfflineSigner(chainId: string): OfflineAminoSigner & OfflineDirectSigner {
|
135
182
|
return new CosmJSOfflineSigner(chainId, this);
|
136
183
|
}
|
137
184
|
|
@@ -153,18 +200,72 @@ export class MockKeplr implements Keplr {
|
|
153
200
|
signDoc: StdSignDoc,
|
154
201
|
_?: KeplrSignOptions
|
155
202
|
): Promise<AminoSignResponse> {
|
156
|
-
const
|
203
|
+
const wallet = await this.getWallet(chainId);
|
157
204
|
|
158
|
-
const
|
159
|
-
if (
|
205
|
+
const key = await this.getKey(chainId);
|
206
|
+
if (signer !== key.bech32Address) {
|
160
207
|
throw new Error("Unmatched signer");
|
161
208
|
}
|
162
209
|
|
163
|
-
|
210
|
+
const signature = wallet.sign(serializeSignDoc(signDoc));
|
211
|
+
|
212
|
+
return {
|
213
|
+
signed: signDoc,
|
214
|
+
signature: encodeSecp256k1Signature(
|
215
|
+
wallet.getPubKey().toBytes(),
|
216
|
+
signature
|
217
|
+
),
|
218
|
+
};
|
164
219
|
}
|
165
220
|
|
166
|
-
signDirect(
|
167
|
-
|
221
|
+
async signDirect(
|
222
|
+
chainId: string,
|
223
|
+
signer: string,
|
224
|
+
signDoc: {
|
225
|
+
/** SignDoc bodyBytes */
|
226
|
+
bodyBytes?: Uint8Array | null;
|
227
|
+
|
228
|
+
/** SignDoc authInfoBytes */
|
229
|
+
authInfoBytes?: Uint8Array | null;
|
230
|
+
|
231
|
+
/** SignDoc chainId */
|
232
|
+
chainId?: string | null;
|
233
|
+
|
234
|
+
/** SignDoc accountNumber */
|
235
|
+
accountNumber?: Long | null;
|
236
|
+
},
|
237
|
+
_?: KeplrSignOptions
|
238
|
+
): Promise<DirectSignResponse> {
|
239
|
+
const wallet = await this.getWallet(chainId);
|
240
|
+
|
241
|
+
const key = await this.getKey(chainId);
|
242
|
+
if (signer !== key.bech32Address) {
|
243
|
+
throw new Error("Unmatched signer");
|
244
|
+
}
|
245
|
+
|
246
|
+
const signature = wallet.sign(
|
247
|
+
SignDoc.encode(
|
248
|
+
SignDoc.fromPartial({
|
249
|
+
bodyBytes: signDoc.bodyBytes!,
|
250
|
+
authInfoBytes: signDoc.authInfoBytes!,
|
251
|
+
chainId: signDoc.chainId!,
|
252
|
+
accountNumber: signDoc.accountNumber!.toString(),
|
253
|
+
})
|
254
|
+
).finish()
|
255
|
+
);
|
256
|
+
|
257
|
+
return {
|
258
|
+
signed: {
|
259
|
+
bodyBytes: signDoc.bodyBytes!,
|
260
|
+
authInfoBytes: signDoc.authInfoBytes!,
|
261
|
+
chainId: signDoc.chainId!,
|
262
|
+
accountNumber: signDoc.accountNumber!,
|
263
|
+
},
|
264
|
+
signature: encodeSecp256k1Signature(
|
265
|
+
wallet.getPubKey().toBytes(),
|
266
|
+
signature
|
267
|
+
),
|
268
|
+
};
|
168
269
|
}
|
169
270
|
|
170
271
|
suggestToken(): Promise<void> {
|
@@ -180,11 +281,40 @@ export class MockKeplr implements Keplr {
|
|
180
281
|
|
181
282
|
getOfflineSignerAuto(
|
182
283
|
_chainId: string
|
183
|
-
): Promise<
|
284
|
+
): Promise<OfflineAminoSigner | OfflineDirectSigner> {
|
184
285
|
throw new Error("Not implemented");
|
185
286
|
}
|
186
287
|
|
187
|
-
getOfflineSignerOnlyAmino(
|
188
|
-
|
288
|
+
getOfflineSignerOnlyAmino(chainId: string): OfflineAminoSigner {
|
289
|
+
return new CosmJSOfflineSignerOnlyAmino(chainId, this);
|
290
|
+
}
|
291
|
+
|
292
|
+
experimentalSignEIP712CosmosTx_v0(
|
293
|
+
_chainId: string,
|
294
|
+
_signer: string,
|
295
|
+
_eip712: {
|
296
|
+
types: Record<string, { name: string; type: string }[] | undefined>;
|
297
|
+
domain: Record<string, any>;
|
298
|
+
primaryType: string;
|
299
|
+
},
|
300
|
+
_signDoc: StdSignDoc,
|
301
|
+
_signOptions: KeplrSignOptions = {}
|
302
|
+
): Promise<AminoSignResponse> {
|
303
|
+
throw new Error("Not yet implemented");
|
304
|
+
}
|
305
|
+
|
306
|
+
getChainInfosWithoutEndpoints(): Promise<ChainInfoWithoutEndpoints[]> {
|
307
|
+
throw new Error("Not yet implemented");
|
308
|
+
}
|
309
|
+
|
310
|
+
disable(_chainIds?: string | string[]): Promise<void> {
|
311
|
+
throw new Error("Not yet implemented");
|
312
|
+
}
|
313
|
+
|
314
|
+
changeKeyRingName(_opts: {
|
315
|
+
defaultName: string;
|
316
|
+
editable?: boolean | undefined;
|
317
|
+
}): Promise<string> {
|
318
|
+
throw new Error("Not yet implemented");
|
189
319
|
}
|
190
320
|
}
|