@keplr-wallet/provider 0.9.4 → 0.9.9
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/core.d.ts +10 -4
- package/build/core.js +29 -16
- package/build/core.js.map +1 -1
- package/build/cosmjs.d.ts +2 -2
- package/build/cosmjs.js.map +1 -1
- package/build/index.d.ts +0 -1
- package/build/index.js +0 -1
- package/build/index.js.map +1 -1
- package/build/inject.d.ts +24 -5
- package/build/inject.js +76 -27
- package/build/inject.js.map +1 -1
- package/build/types/index.d.ts +1 -0
- package/build/types/index.js +14 -0
- package/build/types/index.js.map +1 -0
- package/build/types/msgs.d.ts +133 -0
- package/build/types/msgs.js +340 -0
- package/build/types/msgs.js.map +1 -0
- package/package.json +6 -10
- package/src/core.ts +24 -5
- package/src/cosmjs.ts +2 -2
- package/src/index.ts +0 -1
- package/src/inject.ts +119 -27
- package/src/types/index.ts +1 -0
- package/src/types/msgs.ts +423 -0
- package/build/mock.d.ts +0 -43
- package/build/mock.js +0 -106
- package/build/mock.js.map +0 -1
- package/src/mock.ts +0 -161
package/src/inject.ts
CHANGED
@@ -3,10 +3,11 @@ import {
|
|
3
3
|
Keplr,
|
4
4
|
Keplr as IKeplr,
|
5
5
|
KeplrIntereactionOptions,
|
6
|
+
KeplrMode,
|
6
7
|
KeplrSignOptions,
|
7
8
|
Key,
|
8
9
|
} from "@keplr-wallet/types";
|
9
|
-
import { Result } from "@keplr-wallet/router";
|
10
|
+
import { Result, JSONUint8Array } from "@keplr-wallet/router";
|
10
11
|
import {
|
11
12
|
BroadcastMode,
|
12
13
|
AminoSignResponse,
|
@@ -14,15 +15,14 @@ import {
|
|
14
15
|
StdTx,
|
15
16
|
OfflineSigner,
|
16
17
|
} from "@cosmjs/launchpad";
|
17
|
-
import { cosmos } from "@keplr-wallet/cosmos";
|
18
18
|
import { SecretUtils } from "secretjs/types/enigmautils";
|
19
19
|
|
20
20
|
import { KeplrEnigmaUtils } from "./enigma";
|
21
21
|
import { DirectSignResponse, OfflineDirectSigner } from "@cosmjs/proto-signing";
|
22
22
|
|
23
|
-
import { JSONUint8Array } from "@keplr-wallet/router/build/json-uint8-array";
|
24
23
|
import { CosmJSOfflineSigner, CosmJSOfflineSignerOnlyAmino } from "./cosmjs";
|
25
24
|
import deepmerge from "deepmerge";
|
25
|
+
import Long from "long";
|
26
26
|
|
27
27
|
export interface ProxyRequest {
|
28
28
|
type: "proxy-request";
|
@@ -44,9 +44,23 @@ export interface ProxyRequestResponse {
|
|
44
44
|
* This will use `window.postMessage` to interact with the content script.
|
45
45
|
*/
|
46
46
|
export class InjectedKeplr implements IKeplr {
|
47
|
-
static startProxy(
|
48
|
-
|
49
|
-
|
47
|
+
static startProxy(
|
48
|
+
keplr: IKeplr,
|
49
|
+
eventListener: {
|
50
|
+
addMessageListener: (fn: (e: any) => void) => void;
|
51
|
+
postMessage: (message: any) => void;
|
52
|
+
} = {
|
53
|
+
addMessageListener: (fn: (e: any) => void) =>
|
54
|
+
window.addEventListener("message", fn),
|
55
|
+
postMessage: (message) =>
|
56
|
+
window.postMessage(message, window.location.origin),
|
57
|
+
},
|
58
|
+
parseMessage?: (message: any) => any
|
59
|
+
) {
|
60
|
+
eventListener.addMessageListener(async (e: any) => {
|
61
|
+
const message: ProxyRequest = parseMessage
|
62
|
+
? parseMessage(e.data)
|
63
|
+
: e.data;
|
50
64
|
if (!message || message.type !== "proxy-request") {
|
51
65
|
return;
|
52
66
|
}
|
@@ -60,6 +74,10 @@ export class InjectedKeplr implements IKeplr {
|
|
60
74
|
throw new Error("Version is not function");
|
61
75
|
}
|
62
76
|
|
77
|
+
if (message.method === "mode") {
|
78
|
+
throw new Error("Mode is not function");
|
79
|
+
}
|
80
|
+
|
63
81
|
if (message.method === "defaultOptions") {
|
64
82
|
throw new Error("DefaultOptions is not function");
|
65
83
|
}
|
@@ -89,11 +107,45 @@ export class InjectedKeplr implements IKeplr {
|
|
89
107
|
throw new Error("GetEnigmaUtils method can't be proxy request");
|
90
108
|
}
|
91
109
|
|
92
|
-
const result =
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
110
|
+
const result =
|
111
|
+
message.method === "signDirect"
|
112
|
+
? await (async () => {
|
113
|
+
const receivedSignDoc: {
|
114
|
+
bodyBytes?: Uint8Array | null;
|
115
|
+
authInfoBytes?: Uint8Array | null;
|
116
|
+
chainId?: string | null;
|
117
|
+
accountNumber?: string | null;
|
118
|
+
} = message.args[2];
|
119
|
+
|
120
|
+
const result = await keplr.signDirect(
|
121
|
+
message.args[0],
|
122
|
+
message.args[1],
|
123
|
+
{
|
124
|
+
bodyBytes: receivedSignDoc.bodyBytes,
|
125
|
+
authInfoBytes: receivedSignDoc.authInfoBytes,
|
126
|
+
chainId: receivedSignDoc.chainId,
|
127
|
+
accountNumber: receivedSignDoc.accountNumber
|
128
|
+
? Long.fromString(receivedSignDoc.accountNumber)
|
129
|
+
: null,
|
130
|
+
},
|
131
|
+
message.args[3]
|
132
|
+
);
|
133
|
+
|
134
|
+
return {
|
135
|
+
signed: {
|
136
|
+
bodyBytes: result.signed.bodyBytes,
|
137
|
+
authInfoBytes: result.signed.authInfoBytes,
|
138
|
+
chainId: result.signed.chainId,
|
139
|
+
accountNumber: result.signed.accountNumber.toString(),
|
140
|
+
},
|
141
|
+
signature: result.signature,
|
142
|
+
};
|
143
|
+
})()
|
144
|
+
: await keplr[message.method](
|
145
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
146
|
+
// @ts-ignore
|
147
|
+
...JSONUint8Array.unwrap(message.args)
|
148
|
+
);
|
97
149
|
|
98
150
|
const proxyResponse: ProxyRequestResponse = {
|
99
151
|
type: "proxy-request-response",
|
@@ -103,7 +155,7 @@ export class InjectedKeplr implements IKeplr {
|
|
103
155
|
},
|
104
156
|
};
|
105
157
|
|
106
|
-
|
158
|
+
eventListener.postMessage(proxyResponse);
|
107
159
|
} catch (e) {
|
108
160
|
const proxyResponse: ProxyRequestResponse = {
|
109
161
|
type: "proxy-request-response",
|
@@ -113,7 +165,7 @@ export class InjectedKeplr implements IKeplr {
|
|
113
165
|
},
|
114
166
|
};
|
115
167
|
|
116
|
-
|
168
|
+
eventListener.postMessage(proxyResponse);
|
117
169
|
}
|
118
170
|
});
|
119
171
|
}
|
@@ -135,7 +187,9 @@ export class InjectedKeplr implements IKeplr {
|
|
135
187
|
|
136
188
|
return new Promise((resolve, reject) => {
|
137
189
|
const receiveResponse = (e: any) => {
|
138
|
-
const proxyResponse: ProxyRequestResponse =
|
190
|
+
const proxyResponse: ProxyRequestResponse = this.parseMessage
|
191
|
+
? this.parseMessage(e.data)
|
192
|
+
: e.data;
|
139
193
|
|
140
194
|
if (!proxyResponse || proxyResponse.type !== "proxy-request-response") {
|
141
195
|
return;
|
@@ -145,7 +199,7 @@ export class InjectedKeplr implements IKeplr {
|
|
145
199
|
return;
|
146
200
|
}
|
147
201
|
|
148
|
-
|
202
|
+
this.eventListener.removeMessageListener(receiveResponse);
|
149
203
|
|
150
204
|
const result = JSONUint8Array.unwrap(proxyResponse.result);
|
151
205
|
|
@@ -162,9 +216,9 @@ export class InjectedKeplr implements IKeplr {
|
|
162
216
|
resolve(result.return);
|
163
217
|
};
|
164
218
|
|
165
|
-
|
219
|
+
this.eventListener.addMessageListener(receiveResponse);
|
166
220
|
|
167
|
-
|
221
|
+
this.eventListener.postMessage(proxyMessage);
|
168
222
|
});
|
169
223
|
}
|
170
224
|
|
@@ -172,7 +226,23 @@ export class InjectedKeplr implements IKeplr {
|
|
172
226
|
|
173
227
|
public defaultOptions: KeplrIntereactionOptions = {};
|
174
228
|
|
175
|
-
constructor(
|
229
|
+
constructor(
|
230
|
+
public readonly version: string,
|
231
|
+
public readonly mode: KeplrMode,
|
232
|
+
protected readonly eventListener: {
|
233
|
+
addMessageListener: (fn: (e: any) => void) => void;
|
234
|
+
removeMessageListener: (fn: (e: any) => void) => void;
|
235
|
+
postMessage: (message: any) => void;
|
236
|
+
} = {
|
237
|
+
addMessageListener: (fn: (e: any) => void) =>
|
238
|
+
window.addEventListener("message", fn),
|
239
|
+
removeMessageListener: (fn: (e: any) => void) =>
|
240
|
+
window.removeEventListener("message", fn),
|
241
|
+
postMessage: (message) =>
|
242
|
+
window.postMessage(message, window.location.origin),
|
243
|
+
},
|
244
|
+
protected readonly parseMessage?: (message: any) => any
|
245
|
+
) {}
|
176
246
|
|
177
247
|
async enable(chainIds: string | string[]): Promise<void> {
|
178
248
|
await this.requestMethod("enable", [chainIds]);
|
@@ -211,24 +281,46 @@ export class InjectedKeplr implements IKeplr {
|
|
211
281
|
async signDirect(
|
212
282
|
chainId: string,
|
213
283
|
signer: string,
|
214
|
-
signDoc:
|
284
|
+
signDoc: {
|
285
|
+
bodyBytes?: Uint8Array | null;
|
286
|
+
authInfoBytes?: Uint8Array | null;
|
287
|
+
chainId?: string | null;
|
288
|
+
accountNumber?: Long | null;
|
289
|
+
},
|
215
290
|
signOptions: KeplrSignOptions = {}
|
216
291
|
): Promise<DirectSignResponse> {
|
217
292
|
const result = await this.requestMethod("signDirect", [
|
218
293
|
chainId,
|
219
294
|
signer,
|
220
|
-
|
295
|
+
// We can't send the `Long` with remaing the type.
|
296
|
+
// Receiver should change the `string` to `Long`.
|
297
|
+
{
|
298
|
+
bodyBytes: signDoc.bodyBytes,
|
299
|
+
authInfoBytes: signDoc.authInfoBytes,
|
300
|
+
chainId: signDoc.chainId,
|
301
|
+
accountNumber: signDoc.accountNumber
|
302
|
+
? signDoc.accountNumber.toString()
|
303
|
+
: null,
|
304
|
+
},
|
221
305
|
deepmerge(this.defaultOptions.sign ?? {}, signOptions),
|
222
306
|
]);
|
223
307
|
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
308
|
+
const signed: {
|
309
|
+
bodyBytes: Uint8Array;
|
310
|
+
authInfoBytes: Uint8Array;
|
311
|
+
chainId: string;
|
312
|
+
accountNumber: string;
|
313
|
+
} = result.signed;
|
314
|
+
|
230
315
|
return {
|
231
|
-
signed:
|
316
|
+
signed: {
|
317
|
+
bodyBytes: signed.bodyBytes,
|
318
|
+
authInfoBytes: signed.authInfoBytes,
|
319
|
+
chainId: signed.chainId,
|
320
|
+
// We can't send the `Long` with remaing the type.
|
321
|
+
// Sender should change the `Long` to `string`.
|
322
|
+
accountNumber: Long.fromString(signed.accountNumber),
|
323
|
+
},
|
232
324
|
signature: result.signature,
|
233
325
|
};
|
234
326
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * from "./msgs";
|
@@ -0,0 +1,423 @@
|
|
1
|
+
import { Message } from "@keplr-wallet/router";
|
2
|
+
import { ChainInfo, KeplrSignOptions, Key } from "@keplr-wallet/types";
|
3
|
+
import { AminoSignResponse, StdSignature, StdSignDoc } from "@cosmjs/launchpad";
|
4
|
+
|
5
|
+
export class EnableAccessMsg extends Message<void> {
|
6
|
+
public static type() {
|
7
|
+
return "enable-access";
|
8
|
+
}
|
9
|
+
|
10
|
+
constructor(public readonly chainIds: string[]) {
|
11
|
+
super();
|
12
|
+
}
|
13
|
+
|
14
|
+
validateBasic(): void {
|
15
|
+
if (!this.chainIds || this.chainIds.length === 0) {
|
16
|
+
throw new Error("chain id not set");
|
17
|
+
}
|
18
|
+
}
|
19
|
+
|
20
|
+
route(): string {
|
21
|
+
return "permission";
|
22
|
+
}
|
23
|
+
|
24
|
+
type(): string {
|
25
|
+
return EnableAccessMsg.type();
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
export class GetKeyMsg extends Message<Key> {
|
30
|
+
public static type() {
|
31
|
+
return "get-key";
|
32
|
+
}
|
33
|
+
|
34
|
+
constructor(public readonly chainId: string) {
|
35
|
+
super();
|
36
|
+
}
|
37
|
+
|
38
|
+
validateBasic(): void {
|
39
|
+
if (!this.chainId) {
|
40
|
+
throw new Error("chain id not set");
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
route(): string {
|
45
|
+
return "keyring";
|
46
|
+
}
|
47
|
+
|
48
|
+
type(): string {
|
49
|
+
return GetKeyMsg.type();
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
export class SuggestChainInfoMsg extends Message<void> {
|
54
|
+
public static type() {
|
55
|
+
return "suggest-chain-info";
|
56
|
+
}
|
57
|
+
|
58
|
+
constructor(public readonly chainInfo: ChainInfo) {
|
59
|
+
super();
|
60
|
+
}
|
61
|
+
|
62
|
+
validateBasic(): void {
|
63
|
+
if (!this.chainInfo) {
|
64
|
+
throw new Error("chain info not set");
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
route(): string {
|
69
|
+
return "chains";
|
70
|
+
}
|
71
|
+
|
72
|
+
type(): string {
|
73
|
+
return SuggestChainInfoMsg.type();
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
export class SuggestTokenMsg extends Message<void> {
|
78
|
+
public static type() {
|
79
|
+
return "suggest-token";
|
80
|
+
}
|
81
|
+
|
82
|
+
constructor(
|
83
|
+
public readonly chainId: string,
|
84
|
+
public readonly contractAddress: string,
|
85
|
+
public readonly viewingKey?: string
|
86
|
+
) {
|
87
|
+
super();
|
88
|
+
}
|
89
|
+
|
90
|
+
validateBasic(): void {
|
91
|
+
if (!this.chainId) {
|
92
|
+
throw new Error("Chain id is empty");
|
93
|
+
}
|
94
|
+
|
95
|
+
if (!this.contractAddress) {
|
96
|
+
throw new Error("Contract address is empty");
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
route(): string {
|
101
|
+
return "tokens";
|
102
|
+
}
|
103
|
+
|
104
|
+
type(): string {
|
105
|
+
return SuggestTokenMsg.type();
|
106
|
+
}
|
107
|
+
}
|
108
|
+
|
109
|
+
// Return the tx hash
|
110
|
+
export class SendTxMsg extends Message<Uint8Array> {
|
111
|
+
public static type() {
|
112
|
+
return "send-tx-to-background";
|
113
|
+
}
|
114
|
+
|
115
|
+
constructor(
|
116
|
+
public readonly chainId: string,
|
117
|
+
public readonly tx: unknown,
|
118
|
+
public readonly mode: "async" | "sync" | "block"
|
119
|
+
) {
|
120
|
+
super();
|
121
|
+
}
|
122
|
+
|
123
|
+
validateBasic(): void {
|
124
|
+
if (!this.chainId) {
|
125
|
+
throw new Error("chain id is empty");
|
126
|
+
}
|
127
|
+
|
128
|
+
if (!this.tx) {
|
129
|
+
throw new Error("tx is empty");
|
130
|
+
}
|
131
|
+
|
132
|
+
if (
|
133
|
+
!this.mode ||
|
134
|
+
(this.mode !== "sync" && this.mode !== "async" && this.mode !== "block")
|
135
|
+
) {
|
136
|
+
throw new Error("invalid mode");
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
route(): string {
|
141
|
+
return "background-tx";
|
142
|
+
}
|
143
|
+
|
144
|
+
type(): string {
|
145
|
+
return SendTxMsg.type();
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
export class GetSecret20ViewingKey extends Message<string> {
|
150
|
+
public static type() {
|
151
|
+
return "get-secret20-viewing-key";
|
152
|
+
}
|
153
|
+
|
154
|
+
constructor(
|
155
|
+
public readonly chainId: string,
|
156
|
+
public readonly contractAddress: string
|
157
|
+
) {
|
158
|
+
super();
|
159
|
+
}
|
160
|
+
|
161
|
+
validateBasic(): void {
|
162
|
+
if (!this.chainId) {
|
163
|
+
throw new Error("Chain id is empty");
|
164
|
+
}
|
165
|
+
|
166
|
+
if (!this.contractAddress) {
|
167
|
+
throw new Error("Contract address is empty");
|
168
|
+
}
|
169
|
+
}
|
170
|
+
|
171
|
+
route(): string {
|
172
|
+
return "tokens";
|
173
|
+
}
|
174
|
+
|
175
|
+
type(): string {
|
176
|
+
return GetSecret20ViewingKey.type();
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
180
|
+
export class RequestSignAminoMsg extends Message<AminoSignResponse> {
|
181
|
+
public static type() {
|
182
|
+
return "request-sign-amino";
|
183
|
+
}
|
184
|
+
|
185
|
+
constructor(
|
186
|
+
public readonly chainId: string,
|
187
|
+
public readonly signer: string,
|
188
|
+
public readonly signDoc: StdSignDoc,
|
189
|
+
public readonly signOptions: KeplrSignOptions = {}
|
190
|
+
) {
|
191
|
+
super();
|
192
|
+
}
|
193
|
+
|
194
|
+
validateBasic(): void {
|
195
|
+
if (!this.chainId) {
|
196
|
+
throw new Error("chain id not set");
|
197
|
+
}
|
198
|
+
|
199
|
+
if (!this.signer) {
|
200
|
+
throw new Error("signer not set");
|
201
|
+
}
|
202
|
+
|
203
|
+
// It is not important to check this on the client side as opposed to increasing the bundle size.
|
204
|
+
// Validate bech32 address.
|
205
|
+
// Bech32Address.validate(this.signer);
|
206
|
+
|
207
|
+
if (this.signDoc.chain_id !== this.chainId) {
|
208
|
+
throw new Error(
|
209
|
+
"Chain id in the message is not matched with the requested chain id"
|
210
|
+
);
|
211
|
+
}
|
212
|
+
|
213
|
+
if (!this.signOptions) {
|
214
|
+
throw new Error("Sign options are null");
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
route(): string {
|
219
|
+
return "keyring";
|
220
|
+
}
|
221
|
+
|
222
|
+
type(): string {
|
223
|
+
return RequestSignAminoMsg.type();
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
export class RequestSignDirectMsg extends Message<{
|
228
|
+
readonly signed: {
|
229
|
+
bodyBytes: Uint8Array;
|
230
|
+
authInfoBytes: Uint8Array;
|
231
|
+
chainId: string;
|
232
|
+
accountNumber: string;
|
233
|
+
};
|
234
|
+
readonly signature: StdSignature;
|
235
|
+
}> {
|
236
|
+
public static type() {
|
237
|
+
return "request-sign-direct";
|
238
|
+
}
|
239
|
+
|
240
|
+
constructor(
|
241
|
+
public readonly chainId: string,
|
242
|
+
public readonly signer: string,
|
243
|
+
public readonly signDoc: {
|
244
|
+
bodyBytes?: Uint8Array | null;
|
245
|
+
authInfoBytes?: Uint8Array | null;
|
246
|
+
chainId?: string | null;
|
247
|
+
accountNumber?: string | null;
|
248
|
+
},
|
249
|
+
public readonly signOptions: KeplrSignOptions = {}
|
250
|
+
) {
|
251
|
+
super();
|
252
|
+
}
|
253
|
+
|
254
|
+
validateBasic(): void {
|
255
|
+
if (!this.chainId) {
|
256
|
+
throw new Error("chain id not set");
|
257
|
+
}
|
258
|
+
|
259
|
+
if (!this.signer) {
|
260
|
+
throw new Error("signer not set");
|
261
|
+
}
|
262
|
+
|
263
|
+
// It is not important to check this on the client side as opposed to increasing the bundle size.
|
264
|
+
// Validate bech32 address.
|
265
|
+
// Bech32Address.validate(this.signer);
|
266
|
+
|
267
|
+
// const signDoc = cosmos.tx.v1beta1.SignDoc.create({
|
268
|
+
// bodyBytes: this.signDoc.bodyBytes,
|
269
|
+
// authInfoBytes: this.signDoc.authInfoBytes,
|
270
|
+
// chainId: this.signDoc.chainId,
|
271
|
+
// accountNumber: this.signDoc.accountNumber
|
272
|
+
// ? Long.fromString(this.signDoc.accountNumber)
|
273
|
+
// : undefined,
|
274
|
+
// });
|
275
|
+
//
|
276
|
+
// if (signDoc.chainId !== this.chainId) {
|
277
|
+
// throw new Error(
|
278
|
+
// "Chain id in the message is not matched with the requested chain id"
|
279
|
+
// );
|
280
|
+
// }
|
281
|
+
|
282
|
+
if (!this.signOptions) {
|
283
|
+
throw new Error("Sign options are null");
|
284
|
+
}
|
285
|
+
}
|
286
|
+
|
287
|
+
route(): string {
|
288
|
+
return "keyring";
|
289
|
+
}
|
290
|
+
|
291
|
+
type(): string {
|
292
|
+
return RequestSignDirectMsg.type();
|
293
|
+
}
|
294
|
+
}
|
295
|
+
|
296
|
+
export class GetPubkeyMsg extends Message<Uint8Array> {
|
297
|
+
public static type() {
|
298
|
+
return "get-pubkey-msg";
|
299
|
+
}
|
300
|
+
|
301
|
+
constructor(public readonly chainId: string) {
|
302
|
+
super();
|
303
|
+
}
|
304
|
+
|
305
|
+
validateBasic(): void {
|
306
|
+
if (!this.chainId) {
|
307
|
+
throw new Error("chain id not set");
|
308
|
+
}
|
309
|
+
}
|
310
|
+
|
311
|
+
route(): string {
|
312
|
+
return "secret-wasm";
|
313
|
+
}
|
314
|
+
|
315
|
+
type(): string {
|
316
|
+
return GetPubkeyMsg.type();
|
317
|
+
}
|
318
|
+
}
|
319
|
+
|
320
|
+
export class ReqeustEncryptMsg extends Message<Uint8Array> {
|
321
|
+
public static type() {
|
322
|
+
return "request-encrypt-msg";
|
323
|
+
}
|
324
|
+
|
325
|
+
constructor(
|
326
|
+
public readonly chainId: string,
|
327
|
+
public readonly contractCodeHash: string,
|
328
|
+
// eslint-disable-next-line @typescript-eslint/ban-types
|
329
|
+
public readonly msg: object
|
330
|
+
) {
|
331
|
+
super();
|
332
|
+
}
|
333
|
+
|
334
|
+
validateBasic(): void {
|
335
|
+
if (!this.chainId) {
|
336
|
+
throw new Error("chain id not set");
|
337
|
+
}
|
338
|
+
|
339
|
+
if (!this.contractCodeHash) {
|
340
|
+
throw new Error("contract code hash not set");
|
341
|
+
}
|
342
|
+
|
343
|
+
if (!this.msg) {
|
344
|
+
throw new Error("msg not set");
|
345
|
+
}
|
346
|
+
}
|
347
|
+
|
348
|
+
route(): string {
|
349
|
+
return "secret-wasm";
|
350
|
+
}
|
351
|
+
|
352
|
+
type(): string {
|
353
|
+
return ReqeustEncryptMsg.type();
|
354
|
+
}
|
355
|
+
}
|
356
|
+
|
357
|
+
export class RequestDecryptMsg extends Message<Uint8Array> {
|
358
|
+
public static type() {
|
359
|
+
return "request-decrypt-msg";
|
360
|
+
}
|
361
|
+
|
362
|
+
constructor(
|
363
|
+
public readonly chainId: string,
|
364
|
+
public readonly cipherText: Uint8Array,
|
365
|
+
public readonly nonce: Uint8Array
|
366
|
+
) {
|
367
|
+
super();
|
368
|
+
}
|
369
|
+
|
370
|
+
validateBasic(): void {
|
371
|
+
if (!this.chainId) {
|
372
|
+
throw new Error("chain id not set");
|
373
|
+
}
|
374
|
+
|
375
|
+
if (!this.cipherText || this.cipherText.length === 0) {
|
376
|
+
throw new Error("ciphertext not set");
|
377
|
+
}
|
378
|
+
|
379
|
+
if (!this.nonce || this.nonce.length === 0) {
|
380
|
+
throw new Error("nonce not set");
|
381
|
+
}
|
382
|
+
}
|
383
|
+
|
384
|
+
route(): string {
|
385
|
+
return "secret-wasm";
|
386
|
+
}
|
387
|
+
|
388
|
+
type(): string {
|
389
|
+
return RequestDecryptMsg.type();
|
390
|
+
}
|
391
|
+
}
|
392
|
+
|
393
|
+
export class GetTxEncryptionKeyMsg extends Message<Uint8Array> {
|
394
|
+
public static type() {
|
395
|
+
return "get-tx-encryption-key-msg";
|
396
|
+
}
|
397
|
+
|
398
|
+
constructor(
|
399
|
+
public readonly chainId: string,
|
400
|
+
public readonly nonce: Uint8Array
|
401
|
+
) {
|
402
|
+
super();
|
403
|
+
}
|
404
|
+
|
405
|
+
validateBasic(): void {
|
406
|
+
if (!this.chainId) {
|
407
|
+
throw new Error("chain id not set");
|
408
|
+
}
|
409
|
+
|
410
|
+
if (!this.nonce) {
|
411
|
+
// Nonce of zero length is permitted.
|
412
|
+
throw new Error("nonce is null");
|
413
|
+
}
|
414
|
+
}
|
415
|
+
|
416
|
+
route(): string {
|
417
|
+
return "secret-wasm";
|
418
|
+
}
|
419
|
+
|
420
|
+
type(): string {
|
421
|
+
return GetTxEncryptionKeyMsg.type();
|
422
|
+
}
|
423
|
+
}
|
package/build/mock.d.ts
DELETED
@@ -1,43 +0,0 @@
|
|
1
|
-
import { Keplr, KeplrIntereactionOptions, KeplrSignOptions, Key } from "@keplr-wallet/types";
|
2
|
-
import { AminoSignResponse, BroadcastMode, OfflineSigner, Secp256k1HdWallet, StdSignDoc, StdTx } from "@cosmjs/launchpad";
|
3
|
-
import { SecretUtils } from "secretjs/types/enigmautils";
|
4
|
-
import { OfflineDirectSigner } from "@cosmjs/proto-signing";
|
5
|
-
import { DirectSignResponse } from "@cosmjs/proto-signing/build/signer";
|
6
|
-
export declare class MockKeplr implements Keplr {
|
7
|
-
readonly sendTxFn: (chainId: string, stdTx: StdTx, mode: BroadcastMode) => Promise<Uint8Array>;
|
8
|
-
readonly chainInfos: {
|
9
|
-
readonly chainId: string;
|
10
|
-
readonly bech32Config: {
|
11
|
-
readonly bech32PrefixAccAddr: string;
|
12
|
-
};
|
13
|
-
}[];
|
14
|
-
readonly mnemonic: string;
|
15
|
-
readonly version: string;
|
16
|
-
defaultOptions: KeplrIntereactionOptions;
|
17
|
-
readonly walletMap: {
|
18
|
-
[chainId: string]: Secp256k1HdWallet | undefined;
|
19
|
-
};
|
20
|
-
getHdWallet(chainId: string): Promise<Secp256k1HdWallet>;
|
21
|
-
constructor(sendTxFn: (chainId: string, stdTx: StdTx, mode: BroadcastMode) => Promise<Uint8Array>, chainInfos: {
|
22
|
-
readonly chainId: string;
|
23
|
-
readonly bech32Config: {
|
24
|
-
readonly bech32PrefixAccAddr: string;
|
25
|
-
};
|
26
|
-
}[], mnemonic: string);
|
27
|
-
enable(): Promise<void>;
|
28
|
-
enigmaDecrypt(): Promise<Uint8Array>;
|
29
|
-
enigmaEncrypt(): Promise<Uint8Array>;
|
30
|
-
experimentalSuggestChain(): Promise<void>;
|
31
|
-
getEnigmaPubKey(): Promise<Uint8Array>;
|
32
|
-
getEnigmaUtils(): SecretUtils;
|
33
|
-
getKey(chainId: string): Promise<Key>;
|
34
|
-
getOfflineSigner(chainId: string): OfflineSigner & OfflineDirectSigner;
|
35
|
-
getSecret20ViewingKey(): Promise<string>;
|
36
|
-
sendTx(chainId: string, stdTx: StdTx, mode: BroadcastMode): Promise<Uint8Array>;
|
37
|
-
signAmino(chainId: string, signer: string, signDoc: StdSignDoc, _?: KeplrSignOptions): Promise<AminoSignResponse>;
|
38
|
-
signDirect(): Promise<DirectSignResponse>;
|
39
|
-
suggestToken(): Promise<void>;
|
40
|
-
getEnigmaTxEncryptionKey(_chainId: string, _nonce: Uint8Array): Promise<Uint8Array>;
|
41
|
-
getOfflineSignerAuto(_chainId: string): Promise<OfflineSigner | OfflineDirectSigner>;
|
42
|
-
getOfflineSignerOnlyAmino(_chainId: string): OfflineSigner;
|
43
|
-
}
|