@keplr-wallet/provider 0.12.0-alpha.0 → 0.12.0-alpha.3
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/core-types.d.ts +3 -0
- package/build/core-types.js +3 -0
- package/build/core-types.js.map +1 -0
- package/build/core.d.ts +26 -13
- package/build/core.js +136 -94
- package/build/core.js.map +1 -1
- package/build/cosmjs.d.ts +3 -9
- package/build/cosmjs.js +0 -2
- package/build/cosmjs.js.map +1 -1
- package/build/enigma.d.ts +1 -2
- package/build/enigma.js.map +1 -1
- package/build/index.js +5 -1
- package/build/index.js.map +1 -1
- package/build/inject.d.ts +27 -11
- package/build/inject.js +126 -21
- package/build/inject.js.map +1 -1
- package/package.json +6 -10
- package/src/core-types.ts +3 -0
- package/src/core.ts +295 -160
- package/src/cosmjs.ts +10 -12
- package/src/enigma.ts +1 -2
- package/src/inject.ts +166 -18
- package/build/types/index.d.ts +0 -1
- package/build/types/index.js +0 -14
- package/build/types/index.js.map +0 -1
- package/build/types/msgs.d.ts +0 -150
- package/build/types/msgs.js +0 -390
- package/build/types/msgs.js.map +0 -1
- package/src/types/index.ts +0 -1
- package/src/types/msgs.ts +0 -493
package/src/types/msgs.ts
DELETED
@@ -1,493 +0,0 @@
|
|
1
|
-
import { Message } from "@keplr-wallet/router";
|
2
|
-
import {
|
3
|
-
ChainInfo,
|
4
|
-
EthSignType,
|
5
|
-
KeplrSignOptions,
|
6
|
-
Key,
|
7
|
-
} from "@keplr-wallet/types";
|
8
|
-
import { AminoSignResponse, StdSignature, StdSignDoc } from "@cosmjs/launchpad";
|
9
|
-
|
10
|
-
export class EnableAccessMsg extends Message<void> {
|
11
|
-
public static type() {
|
12
|
-
return "enable-access";
|
13
|
-
}
|
14
|
-
|
15
|
-
constructor(public readonly chainIds: string[]) {
|
16
|
-
super();
|
17
|
-
}
|
18
|
-
|
19
|
-
validateBasic(): void {
|
20
|
-
if (!this.chainIds || this.chainIds.length === 0) {
|
21
|
-
throw new Error("chain id not set");
|
22
|
-
}
|
23
|
-
}
|
24
|
-
|
25
|
-
route(): string {
|
26
|
-
return "permission";
|
27
|
-
}
|
28
|
-
|
29
|
-
type(): string {
|
30
|
-
return EnableAccessMsg.type();
|
31
|
-
}
|
32
|
-
}
|
33
|
-
|
34
|
-
export class GetKeyMsg extends Message<Key> {
|
35
|
-
public static type() {
|
36
|
-
return "get-key";
|
37
|
-
}
|
38
|
-
|
39
|
-
constructor(public readonly chainId: string) {
|
40
|
-
super();
|
41
|
-
}
|
42
|
-
|
43
|
-
validateBasic(): void {
|
44
|
-
if (!this.chainId) {
|
45
|
-
throw new Error("chain id not set");
|
46
|
-
}
|
47
|
-
}
|
48
|
-
|
49
|
-
route(): string {
|
50
|
-
return "keyring";
|
51
|
-
}
|
52
|
-
|
53
|
-
type(): string {
|
54
|
-
return GetKeyMsg.type();
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
export class SuggestChainInfoMsg extends Message<void> {
|
59
|
-
public static type() {
|
60
|
-
return "suggest-chain-info";
|
61
|
-
}
|
62
|
-
|
63
|
-
constructor(public readonly chainInfo: ChainInfo) {
|
64
|
-
super();
|
65
|
-
}
|
66
|
-
|
67
|
-
validateBasic(): void {
|
68
|
-
if (!this.chainInfo) {
|
69
|
-
throw new Error("chain info not set");
|
70
|
-
}
|
71
|
-
}
|
72
|
-
|
73
|
-
route(): string {
|
74
|
-
return "chains";
|
75
|
-
}
|
76
|
-
|
77
|
-
type(): string {
|
78
|
-
return SuggestChainInfoMsg.type();
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
export class SuggestTokenMsg extends Message<void> {
|
83
|
-
public static type() {
|
84
|
-
return "suggest-token";
|
85
|
-
}
|
86
|
-
|
87
|
-
constructor(
|
88
|
-
public readonly chainId: string,
|
89
|
-
public readonly contractAddress: string,
|
90
|
-
public readonly viewingKey?: string
|
91
|
-
) {
|
92
|
-
super();
|
93
|
-
}
|
94
|
-
|
95
|
-
validateBasic(): void {
|
96
|
-
if (!this.chainId) {
|
97
|
-
throw new Error("Chain id is empty");
|
98
|
-
}
|
99
|
-
|
100
|
-
if (!this.contractAddress) {
|
101
|
-
throw new Error("Contract address is empty");
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
route(): string {
|
106
|
-
return "tokens";
|
107
|
-
}
|
108
|
-
|
109
|
-
type(): string {
|
110
|
-
return SuggestTokenMsg.type();
|
111
|
-
}
|
112
|
-
}
|
113
|
-
|
114
|
-
// Return the tx hash
|
115
|
-
export class SendTxMsg extends Message<Uint8Array> {
|
116
|
-
public static type() {
|
117
|
-
return "send-tx-to-background";
|
118
|
-
}
|
119
|
-
|
120
|
-
constructor(
|
121
|
-
public readonly chainId: string,
|
122
|
-
public readonly tx: unknown,
|
123
|
-
public readonly mode: "async" | "sync" | "block"
|
124
|
-
) {
|
125
|
-
super();
|
126
|
-
}
|
127
|
-
|
128
|
-
validateBasic(): void {
|
129
|
-
if (!this.chainId) {
|
130
|
-
throw new Error("chain id is empty");
|
131
|
-
}
|
132
|
-
|
133
|
-
if (!this.tx) {
|
134
|
-
throw new Error("tx is empty");
|
135
|
-
}
|
136
|
-
|
137
|
-
if (
|
138
|
-
!this.mode ||
|
139
|
-
(this.mode !== "sync" && this.mode !== "async" && this.mode !== "block")
|
140
|
-
) {
|
141
|
-
throw new Error("invalid mode");
|
142
|
-
}
|
143
|
-
}
|
144
|
-
|
145
|
-
route(): string {
|
146
|
-
return "background-tx";
|
147
|
-
}
|
148
|
-
|
149
|
-
type(): string {
|
150
|
-
return SendTxMsg.type();
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
export class GetSecret20ViewingKey extends Message<string> {
|
155
|
-
public static type() {
|
156
|
-
return "get-secret20-viewing-key";
|
157
|
-
}
|
158
|
-
|
159
|
-
constructor(
|
160
|
-
public readonly chainId: string,
|
161
|
-
public readonly contractAddress: string
|
162
|
-
) {
|
163
|
-
super();
|
164
|
-
}
|
165
|
-
|
166
|
-
validateBasic(): void {
|
167
|
-
if (!this.chainId) {
|
168
|
-
throw new Error("Chain id is empty");
|
169
|
-
}
|
170
|
-
|
171
|
-
if (!this.contractAddress) {
|
172
|
-
throw new Error("Contract address is empty");
|
173
|
-
}
|
174
|
-
}
|
175
|
-
|
176
|
-
route(): string {
|
177
|
-
return "tokens";
|
178
|
-
}
|
179
|
-
|
180
|
-
type(): string {
|
181
|
-
return GetSecret20ViewingKey.type();
|
182
|
-
}
|
183
|
-
}
|
184
|
-
|
185
|
-
export class RequestSignAminoMsg extends Message<AminoSignResponse> {
|
186
|
-
public static type() {
|
187
|
-
return "request-sign-amino";
|
188
|
-
}
|
189
|
-
|
190
|
-
constructor(
|
191
|
-
public readonly chainId: string,
|
192
|
-
public readonly signer: string,
|
193
|
-
public readonly signDoc: StdSignDoc,
|
194
|
-
public readonly signOptions: KeplrSignOptions & {
|
195
|
-
// Hack option field to detect the sign arbitrary for string
|
196
|
-
isADR36WithString?: boolean;
|
197
|
-
ethSignType?: EthSignType;
|
198
|
-
} = {}
|
199
|
-
) {
|
200
|
-
super();
|
201
|
-
}
|
202
|
-
|
203
|
-
validateBasic(): void {
|
204
|
-
if (!this.chainId) {
|
205
|
-
throw new Error("chain id not set");
|
206
|
-
}
|
207
|
-
|
208
|
-
if (!this.signer) {
|
209
|
-
throw new Error("signer not set");
|
210
|
-
}
|
211
|
-
|
212
|
-
// It is not important to check this on the client side as opposed to increasing the bundle size.
|
213
|
-
// Validate bech32 address.
|
214
|
-
// Bech32Address.validate(this.signer);
|
215
|
-
|
216
|
-
const signDoc = this.signDoc;
|
217
|
-
|
218
|
-
// Check that the sign doc is for ADR-36,
|
219
|
-
// the validation should be performed on the background.
|
220
|
-
const hasOnlyMsgSignData = (() => {
|
221
|
-
if (
|
222
|
-
signDoc &&
|
223
|
-
signDoc.msgs &&
|
224
|
-
Array.isArray(signDoc.msgs) &&
|
225
|
-
signDoc.msgs.length === 1
|
226
|
-
) {
|
227
|
-
const msg = signDoc.msgs[0];
|
228
|
-
return msg.type === "sign/MsgSignData";
|
229
|
-
} else {
|
230
|
-
return false;
|
231
|
-
}
|
232
|
-
})();
|
233
|
-
|
234
|
-
// If the sign doc is expected to be for ADR-36,
|
235
|
-
// it doesn't have to have the chain id in the sign doc.
|
236
|
-
if (!hasOnlyMsgSignData && signDoc.chain_id !== this.chainId) {
|
237
|
-
throw new Error(
|
238
|
-
"Chain id in the message is not matched with the requested chain id"
|
239
|
-
);
|
240
|
-
}
|
241
|
-
|
242
|
-
if (!this.signOptions) {
|
243
|
-
throw new Error("Sign options are null");
|
244
|
-
}
|
245
|
-
}
|
246
|
-
|
247
|
-
route(): string {
|
248
|
-
return "keyring";
|
249
|
-
}
|
250
|
-
|
251
|
-
type(): string {
|
252
|
-
return RequestSignAminoMsg.type();
|
253
|
-
}
|
254
|
-
}
|
255
|
-
|
256
|
-
export class RequestVerifyADR36AminoSignDoc extends Message<boolean> {
|
257
|
-
public static type() {
|
258
|
-
return "request-verify-adr-36-amino-doc";
|
259
|
-
}
|
260
|
-
|
261
|
-
constructor(
|
262
|
-
public readonly chainId: string,
|
263
|
-
public readonly signer: string,
|
264
|
-
public readonly data: Uint8Array,
|
265
|
-
public readonly signature: StdSignature
|
266
|
-
) {
|
267
|
-
super();
|
268
|
-
}
|
269
|
-
|
270
|
-
validateBasic(): void {
|
271
|
-
if (!this.chainId) {
|
272
|
-
throw new Error("chain id not set");
|
273
|
-
}
|
274
|
-
|
275
|
-
if (!this.signer) {
|
276
|
-
throw new Error("signer not set");
|
277
|
-
}
|
278
|
-
|
279
|
-
if (!this.signature) {
|
280
|
-
throw new Error("Signature not set");
|
281
|
-
}
|
282
|
-
|
283
|
-
// It is not important to check this on the client side as opposed to increasing the bundle size.
|
284
|
-
// Validate bech32 address.
|
285
|
-
// Bech32Address.validate(this.signer);
|
286
|
-
}
|
287
|
-
|
288
|
-
route(): string {
|
289
|
-
return "keyring";
|
290
|
-
}
|
291
|
-
|
292
|
-
type(): string {
|
293
|
-
return RequestVerifyADR36AminoSignDoc.type();
|
294
|
-
}
|
295
|
-
}
|
296
|
-
|
297
|
-
export class RequestSignDirectMsg extends Message<{
|
298
|
-
readonly signed: {
|
299
|
-
bodyBytes: Uint8Array;
|
300
|
-
authInfoBytes: Uint8Array;
|
301
|
-
chainId: string;
|
302
|
-
accountNumber: string;
|
303
|
-
};
|
304
|
-
readonly signature: StdSignature;
|
305
|
-
}> {
|
306
|
-
public static type() {
|
307
|
-
return "request-sign-direct";
|
308
|
-
}
|
309
|
-
|
310
|
-
constructor(
|
311
|
-
public readonly chainId: string,
|
312
|
-
public readonly signer: string,
|
313
|
-
public readonly signDoc: {
|
314
|
-
bodyBytes?: Uint8Array | null;
|
315
|
-
authInfoBytes?: Uint8Array | null;
|
316
|
-
chainId?: string | null;
|
317
|
-
accountNumber?: string | null;
|
318
|
-
},
|
319
|
-
public readonly signOptions: KeplrSignOptions = {}
|
320
|
-
) {
|
321
|
-
super();
|
322
|
-
}
|
323
|
-
|
324
|
-
validateBasic(): void {
|
325
|
-
if (!this.chainId) {
|
326
|
-
throw new Error("chain id not set");
|
327
|
-
}
|
328
|
-
|
329
|
-
if (!this.signer) {
|
330
|
-
throw new Error("signer not set");
|
331
|
-
}
|
332
|
-
|
333
|
-
// It is not important to check this on the client side as opposed to increasing the bundle size.
|
334
|
-
// Validate bech32 address.
|
335
|
-
// Bech32Address.validate(this.signer);
|
336
|
-
|
337
|
-
// const signDoc = cosmos.tx.v1beta1.SignDoc.create({
|
338
|
-
// bodyBytes: this.signDoc.bodyBytes,
|
339
|
-
// authInfoBytes: this.signDoc.authInfoBytes,
|
340
|
-
// chainId: this.signDoc.chainId,
|
341
|
-
// accountNumber: this.signDoc.accountNumber
|
342
|
-
// ? Long.fromString(this.signDoc.accountNumber)
|
343
|
-
// : undefined,
|
344
|
-
// });
|
345
|
-
//
|
346
|
-
// if (signDoc.chainId !== this.chainId) {
|
347
|
-
// throw new Error(
|
348
|
-
// "Chain id in the message is not matched with the requested chain id"
|
349
|
-
// );
|
350
|
-
// }
|
351
|
-
|
352
|
-
if (!this.signOptions) {
|
353
|
-
throw new Error("Sign options are null");
|
354
|
-
}
|
355
|
-
}
|
356
|
-
|
357
|
-
route(): string {
|
358
|
-
return "keyring";
|
359
|
-
}
|
360
|
-
|
361
|
-
type(): string {
|
362
|
-
return RequestSignDirectMsg.type();
|
363
|
-
}
|
364
|
-
}
|
365
|
-
|
366
|
-
export class GetPubkeyMsg extends Message<Uint8Array> {
|
367
|
-
public static type() {
|
368
|
-
return "get-pubkey-msg";
|
369
|
-
}
|
370
|
-
|
371
|
-
constructor(public readonly chainId: string) {
|
372
|
-
super();
|
373
|
-
}
|
374
|
-
|
375
|
-
validateBasic(): void {
|
376
|
-
if (!this.chainId) {
|
377
|
-
throw new Error("chain id not set");
|
378
|
-
}
|
379
|
-
}
|
380
|
-
|
381
|
-
route(): string {
|
382
|
-
return "secret-wasm";
|
383
|
-
}
|
384
|
-
|
385
|
-
type(): string {
|
386
|
-
return GetPubkeyMsg.type();
|
387
|
-
}
|
388
|
-
}
|
389
|
-
|
390
|
-
export class ReqeustEncryptMsg extends Message<Uint8Array> {
|
391
|
-
public static type() {
|
392
|
-
return "request-encrypt-msg";
|
393
|
-
}
|
394
|
-
|
395
|
-
constructor(
|
396
|
-
public readonly chainId: string,
|
397
|
-
public readonly contractCodeHash: string,
|
398
|
-
// eslint-disable-next-line @typescript-eslint/ban-types
|
399
|
-
public readonly msg: object
|
400
|
-
) {
|
401
|
-
super();
|
402
|
-
}
|
403
|
-
|
404
|
-
validateBasic(): void {
|
405
|
-
if (!this.chainId) {
|
406
|
-
throw new Error("chain id not set");
|
407
|
-
}
|
408
|
-
|
409
|
-
if (!this.contractCodeHash) {
|
410
|
-
throw new Error("contract code hash not set");
|
411
|
-
}
|
412
|
-
|
413
|
-
if (!this.msg) {
|
414
|
-
throw new Error("msg not set");
|
415
|
-
}
|
416
|
-
}
|
417
|
-
|
418
|
-
route(): string {
|
419
|
-
return "secret-wasm";
|
420
|
-
}
|
421
|
-
|
422
|
-
type(): string {
|
423
|
-
return ReqeustEncryptMsg.type();
|
424
|
-
}
|
425
|
-
}
|
426
|
-
|
427
|
-
export class RequestDecryptMsg extends Message<Uint8Array> {
|
428
|
-
public static type() {
|
429
|
-
return "request-decrypt-msg";
|
430
|
-
}
|
431
|
-
|
432
|
-
constructor(
|
433
|
-
public readonly chainId: string,
|
434
|
-
public readonly cipherText: Uint8Array,
|
435
|
-
public readonly nonce: Uint8Array
|
436
|
-
) {
|
437
|
-
super();
|
438
|
-
}
|
439
|
-
|
440
|
-
validateBasic(): void {
|
441
|
-
if (!this.chainId) {
|
442
|
-
throw new Error("chain id not set");
|
443
|
-
}
|
444
|
-
|
445
|
-
if (!this.cipherText || this.cipherText.length === 0) {
|
446
|
-
throw new Error("ciphertext not set");
|
447
|
-
}
|
448
|
-
|
449
|
-
if (!this.nonce || this.nonce.length === 0) {
|
450
|
-
throw new Error("nonce not set");
|
451
|
-
}
|
452
|
-
}
|
453
|
-
|
454
|
-
route(): string {
|
455
|
-
return "secret-wasm";
|
456
|
-
}
|
457
|
-
|
458
|
-
type(): string {
|
459
|
-
return RequestDecryptMsg.type();
|
460
|
-
}
|
461
|
-
}
|
462
|
-
|
463
|
-
export class GetTxEncryptionKeyMsg extends Message<Uint8Array> {
|
464
|
-
public static type() {
|
465
|
-
return "get-tx-encryption-key-msg";
|
466
|
-
}
|
467
|
-
|
468
|
-
constructor(
|
469
|
-
public readonly chainId: string,
|
470
|
-
public readonly nonce: Uint8Array
|
471
|
-
) {
|
472
|
-
super();
|
473
|
-
}
|
474
|
-
|
475
|
-
validateBasic(): void {
|
476
|
-
if (!this.chainId) {
|
477
|
-
throw new Error("chain id not set");
|
478
|
-
}
|
479
|
-
|
480
|
-
if (!this.nonce) {
|
481
|
-
// Nonce of zero length is permitted.
|
482
|
-
throw new Error("nonce is null");
|
483
|
-
}
|
484
|
-
}
|
485
|
-
|
486
|
-
route(): string {
|
487
|
-
return "secret-wasm";
|
488
|
-
}
|
489
|
-
|
490
|
-
type(): string {
|
491
|
-
return GetTxEncryptionKeyMsg.type();
|
492
|
-
}
|
493
|
-
}
|