@keplr-wallet/provider 0.11.64 → 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/src/types/msgs.ts DELETED
@@ -1,709 +0,0 @@
1
- import { Message } from "@keplr-wallet/router";
2
- import {
3
- ChainInfo,
4
- EthSignType,
5
- KeplrSignOptions,
6
- Key,
7
- AminoSignResponse,
8
- StdSignature,
9
- StdSignDoc,
10
- ChainInfoWithoutEndpoints,
11
- } from "@keplr-wallet/types";
12
-
13
- export class EnableAccessMsg extends Message<void> {
14
- public static type() {
15
- return "enable-access";
16
- }
17
-
18
- constructor(public readonly chainIds: string[]) {
19
- super();
20
- }
21
-
22
- validateBasic(): void {
23
- if (!this.chainIds || this.chainIds.length === 0) {
24
- throw new Error("chain id not set");
25
- }
26
- }
27
-
28
- route(): string {
29
- return "permission";
30
- }
31
-
32
- type(): string {
33
- return EnableAccessMsg.type();
34
- }
35
- }
36
-
37
- export class DisableAccessMsg extends Message<void> {
38
- public static type() {
39
- return "disable-access";
40
- }
41
-
42
- constructor(public readonly chainIds: string[]) {
43
- super();
44
- }
45
-
46
- validateBasic(): void {
47
- if (!this.chainIds) {
48
- throw new Error("chain id not set");
49
- }
50
- }
51
-
52
- route(): string {
53
- return "permission";
54
- }
55
-
56
- type(): string {
57
- return DisableAccessMsg.type();
58
- }
59
- }
60
-
61
- export class GetKeyMsg extends Message<Key> {
62
- public static type() {
63
- return "get-key";
64
- }
65
-
66
- constructor(public readonly chainId: string) {
67
- super();
68
- }
69
-
70
- validateBasic(): void {
71
- if (!this.chainId) {
72
- throw new Error("chain id not set");
73
- }
74
- }
75
-
76
- route(): string {
77
- return "keyring";
78
- }
79
-
80
- type(): string {
81
- return GetKeyMsg.type();
82
- }
83
- }
84
-
85
- export class SuggestChainInfoMsg extends Message<void> {
86
- public static type() {
87
- return "suggest-chain-info";
88
- }
89
-
90
- constructor(public readonly chainInfo: ChainInfo) {
91
- super();
92
- }
93
-
94
- validateBasic(): void {
95
- if (!this.chainInfo) {
96
- throw new Error("chain info not set");
97
- }
98
- }
99
-
100
- route(): string {
101
- return "chains";
102
- }
103
-
104
- type(): string {
105
- return SuggestChainInfoMsg.type();
106
- }
107
- }
108
-
109
- export class SuggestTokenMsg extends Message<void> {
110
- public static type() {
111
- return "suggest-token";
112
- }
113
-
114
- constructor(
115
- public readonly chainId: string,
116
- public readonly contractAddress: string,
117
- public readonly viewingKey?: string
118
- ) {
119
- super();
120
- }
121
-
122
- validateBasic(): void {
123
- if (!this.chainId) {
124
- throw new Error("Chain id is empty");
125
- }
126
-
127
- if (!this.contractAddress) {
128
- throw new Error("Contract address is empty");
129
- }
130
- }
131
-
132
- route(): string {
133
- return "tokens";
134
- }
135
-
136
- type(): string {
137
- return SuggestTokenMsg.type();
138
- }
139
- }
140
-
141
- // Return the tx hash
142
- export class SendTxMsg extends Message<Uint8Array> {
143
- public static type() {
144
- return "send-tx-to-background";
145
- }
146
-
147
- constructor(
148
- public readonly chainId: string,
149
- public readonly tx: unknown,
150
- public readonly mode: "async" | "sync" | "block"
151
- ) {
152
- super();
153
- }
154
-
155
- validateBasic(): void {
156
- if (!this.chainId) {
157
- throw new Error("chain id is empty");
158
- }
159
-
160
- if (!this.tx) {
161
- throw new Error("tx is empty");
162
- }
163
-
164
- if (
165
- !this.mode ||
166
- (this.mode !== "sync" && this.mode !== "async" && this.mode !== "block")
167
- ) {
168
- throw new Error("invalid mode");
169
- }
170
- }
171
-
172
- route(): string {
173
- return "background-tx";
174
- }
175
-
176
- type(): string {
177
- return SendTxMsg.type();
178
- }
179
- }
180
-
181
- export class GetSecret20ViewingKey extends Message<string> {
182
- public static type() {
183
- return "get-secret20-viewing-key";
184
- }
185
-
186
- constructor(
187
- public readonly chainId: string,
188
- public readonly contractAddress: string
189
- ) {
190
- super();
191
- }
192
-
193
- validateBasic(): void {
194
- if (!this.chainId) {
195
- throw new Error("Chain id is empty");
196
- }
197
-
198
- if (!this.contractAddress) {
199
- throw new Error("Contract address is empty");
200
- }
201
- }
202
-
203
- route(): string {
204
- return "tokens";
205
- }
206
-
207
- type(): string {
208
- return GetSecret20ViewingKey.type();
209
- }
210
- }
211
-
212
- export class RequestSignAminoMsg extends Message<AminoSignResponse> {
213
- public static type() {
214
- return "request-sign-amino";
215
- }
216
-
217
- constructor(
218
- public readonly chainId: string,
219
- public readonly signer: string,
220
- public readonly signDoc: StdSignDoc,
221
- public readonly signOptions: KeplrSignOptions & {
222
- // Hack option field to detect the sign arbitrary for string
223
- isADR36WithString?: boolean;
224
- ethSignType?: EthSignType;
225
- } = {}
226
- ) {
227
- super();
228
- }
229
-
230
- validateBasic(): void {
231
- if (!this.chainId) {
232
- throw new Error("chain id not set");
233
- }
234
-
235
- if (!this.signer) {
236
- throw new Error("signer not set");
237
- }
238
-
239
- // It is not important to check this on the client side as opposed to increasing the bundle size.
240
- // Validate bech32 address.
241
- // Bech32Address.validate(this.signer);
242
-
243
- const signDoc = this.signDoc;
244
-
245
- // Check that the sign doc is for ADR-36,
246
- // the validation should be performed on the background.
247
- const hasOnlyMsgSignData = (() => {
248
- if (
249
- signDoc &&
250
- signDoc.msgs &&
251
- Array.isArray(signDoc.msgs) &&
252
- signDoc.msgs.length === 1
253
- ) {
254
- const msg = signDoc.msgs[0];
255
- return msg.type === "sign/MsgSignData";
256
- } else {
257
- return false;
258
- }
259
- })();
260
-
261
- // If the sign doc is expected to be for ADR-36,
262
- // it doesn't have to have the chain id in the sign doc.
263
- if (!hasOnlyMsgSignData && signDoc.chain_id !== this.chainId) {
264
- throw new Error(
265
- "Chain id in the message is not matched with the requested chain id"
266
- );
267
- }
268
-
269
- if (!this.signOptions) {
270
- throw new Error("Sign options are null");
271
- }
272
- }
273
-
274
- route(): string {
275
- return "keyring";
276
- }
277
-
278
- type(): string {
279
- return RequestSignAminoMsg.type();
280
- }
281
- }
282
-
283
- export class RequestSignEIP712CosmosTxMsg_v0 extends Message<AminoSignResponse> {
284
- public static type() {
285
- return "request-sign-eip-712-cosmos-tx-v0";
286
- }
287
-
288
- constructor(
289
- public readonly chainId: string,
290
- public readonly signer: string,
291
- public readonly eip712: {
292
- types: Record<string, { name: string; type: string }[] | undefined>;
293
- domain: Record<string, any>;
294
- primaryType: string;
295
- },
296
- public readonly signDoc: StdSignDoc,
297
- public readonly signOptions: KeplrSignOptions
298
- ) {
299
- super();
300
- }
301
-
302
- validateBasic(): void {
303
- if (!this.chainId) {
304
- throw new Error("chain id not set");
305
- }
306
-
307
- if (!this.signer) {
308
- throw new Error("signer not set");
309
- }
310
-
311
- if (this.signDoc.chain_id !== this.chainId) {
312
- throw new Error(
313
- "Chain id in the message is not matched with the requested chain id"
314
- );
315
- }
316
-
317
- if (!this.signOptions) {
318
- throw new Error("Sign options are null");
319
- }
320
- }
321
-
322
- approveExternal(): boolean {
323
- return true;
324
- }
325
-
326
- route(): string {
327
- return "keyring";
328
- }
329
-
330
- type(): string {
331
- return RequestSignEIP712CosmosTxMsg_v0.type();
332
- }
333
- }
334
-
335
- export class RequestICNSAdr36SignaturesMsg extends Message<
336
- {
337
- chainId: string;
338
- bech32Prefix: string;
339
- bech32Address: string;
340
- addressHash: "cosmos" | "ethereum";
341
- pubKey: Uint8Array;
342
- signatureSalt: number;
343
- signature: Uint8Array;
344
- }[]
345
- > {
346
- public static type() {
347
- return "request-icns-adr-36-signatures";
348
- }
349
-
350
- constructor(
351
- readonly chainId: string,
352
- readonly contractAddress: string,
353
- readonly owner: string,
354
- readonly username: string,
355
- readonly addressChainIds: string[]
356
- ) {
357
- super();
358
- }
359
-
360
- validateBasic(): void {
361
- if (!this.chainId) {
362
- throw new Error("chain id not set");
363
- }
364
-
365
- if (!this.contractAddress) {
366
- throw new Error("contract address not set");
367
- }
368
-
369
- if (!this.owner) {
370
- throw new Error("signer not set");
371
- }
372
-
373
- // Validate bech32 address.
374
- // Bech32Address.validate(this.signer);
375
-
376
- if (!this.username) {
377
- throw new Error("username not set");
378
- }
379
-
380
- if (!this.addressChainIds || this.addressChainIds.length === 0) {
381
- throw new Error("address chain ids not set");
382
- }
383
- }
384
-
385
- approveExternal(): boolean {
386
- return true;
387
- }
388
-
389
- route(): string {
390
- return "keyring";
391
- }
392
-
393
- type(): string {
394
- return RequestICNSAdr36SignaturesMsg.type();
395
- }
396
- }
397
-
398
- export class RequestVerifyADR36AminoSignDoc extends Message<boolean> {
399
- public static type() {
400
- return "request-verify-adr-36-amino-doc";
401
- }
402
-
403
- constructor(
404
- public readonly chainId: string,
405
- public readonly signer: string,
406
- public readonly data: Uint8Array,
407
- public readonly signature: StdSignature
408
- ) {
409
- super();
410
- }
411
-
412
- validateBasic(): void {
413
- if (!this.chainId) {
414
- throw new Error("chain id not set");
415
- }
416
-
417
- if (!this.signer) {
418
- throw new Error("signer not set");
419
- }
420
-
421
- if (!this.signature) {
422
- throw new Error("Signature not set");
423
- }
424
-
425
- // It is not important to check this on the client side as opposed to increasing the bundle size.
426
- // Validate bech32 address.
427
- // Bech32Address.validate(this.signer);
428
- }
429
-
430
- route(): string {
431
- return "keyring";
432
- }
433
-
434
- type(): string {
435
- return RequestVerifyADR36AminoSignDoc.type();
436
- }
437
- }
438
-
439
- export class RequestSignDirectMsg extends Message<{
440
- readonly signed: {
441
- bodyBytes: Uint8Array;
442
- authInfoBytes: Uint8Array;
443
- chainId: string;
444
- accountNumber: string;
445
- };
446
- readonly signature: StdSignature;
447
- }> {
448
- public static type() {
449
- return "request-sign-direct";
450
- }
451
-
452
- constructor(
453
- public readonly chainId: string,
454
- public readonly signer: string,
455
- public readonly signDoc: {
456
- bodyBytes?: Uint8Array | null;
457
- authInfoBytes?: Uint8Array | null;
458
- chainId?: string | null;
459
- accountNumber?: string | null;
460
- },
461
- public readonly signOptions: KeplrSignOptions = {}
462
- ) {
463
- super();
464
- }
465
-
466
- validateBasic(): void {
467
- if (!this.chainId) {
468
- throw new Error("chain id not set");
469
- }
470
-
471
- if (!this.signer) {
472
- throw new Error("signer not set");
473
- }
474
-
475
- // It is not important to check this on the client side as opposed to increasing the bundle size.
476
- // Validate bech32 address.
477
- // Bech32Address.validate(this.signer);
478
-
479
- // const signDoc = cosmos.tx.v1beta1.SignDoc.create({
480
- // bodyBytes: this.signDoc.bodyBytes,
481
- // authInfoBytes: this.signDoc.authInfoBytes,
482
- // chainId: this.signDoc.chainId,
483
- // accountNumber: this.signDoc.accountNumber
484
- // ? Long.fromString(this.signDoc.accountNumber)
485
- // : undefined,
486
- // });
487
- //
488
- // if (signDoc.chainId !== this.chainId) {
489
- // throw new Error(
490
- // "Chain id in the message is not matched with the requested chain id"
491
- // );
492
- // }
493
-
494
- if (!this.signOptions) {
495
- throw new Error("Sign options are null");
496
- }
497
- }
498
-
499
- route(): string {
500
- return "keyring";
501
- }
502
-
503
- type(): string {
504
- return RequestSignDirectMsg.type();
505
- }
506
- }
507
-
508
- export class GetPubkeyMsg extends Message<Uint8Array> {
509
- public static type() {
510
- return "get-pubkey-msg";
511
- }
512
-
513
- constructor(public readonly chainId: string) {
514
- super();
515
- }
516
-
517
- validateBasic(): void {
518
- if (!this.chainId) {
519
- throw new Error("chain id not set");
520
- }
521
- }
522
-
523
- route(): string {
524
- return "secret-wasm";
525
- }
526
-
527
- type(): string {
528
- return GetPubkeyMsg.type();
529
- }
530
- }
531
-
532
- export class ReqeustEncryptMsg extends Message<Uint8Array> {
533
- public static type() {
534
- return "request-encrypt-msg";
535
- }
536
-
537
- constructor(
538
- public readonly chainId: string,
539
- public readonly contractCodeHash: string,
540
- // eslint-disable-next-line @typescript-eslint/ban-types
541
- public readonly msg: object
542
- ) {
543
- super();
544
- }
545
-
546
- validateBasic(): void {
547
- if (!this.chainId) {
548
- throw new Error("chain id not set");
549
- }
550
-
551
- if (!this.contractCodeHash) {
552
- throw new Error("contract code hash not set");
553
- }
554
-
555
- if (!this.msg) {
556
- throw new Error("msg not set");
557
- }
558
- }
559
-
560
- route(): string {
561
- return "secret-wasm";
562
- }
563
-
564
- type(): string {
565
- return ReqeustEncryptMsg.type();
566
- }
567
- }
568
-
569
- export class RequestDecryptMsg extends Message<Uint8Array> {
570
- public static type() {
571
- return "request-decrypt-msg";
572
- }
573
-
574
- constructor(
575
- public readonly chainId: string,
576
- public readonly cipherText: Uint8Array,
577
- public readonly nonce: Uint8Array
578
- ) {
579
- super();
580
- }
581
-
582
- validateBasic(): void {
583
- if (!this.chainId) {
584
- throw new Error("chain id not set");
585
- }
586
-
587
- if (!this.cipherText || this.cipherText.length === 0) {
588
- throw new Error("ciphertext not set");
589
- }
590
-
591
- if (!this.nonce || this.nonce.length === 0) {
592
- throw new Error("nonce not set");
593
- }
594
- }
595
-
596
- route(): string {
597
- return "secret-wasm";
598
- }
599
-
600
- type(): string {
601
- return RequestDecryptMsg.type();
602
- }
603
- }
604
-
605
- export class GetTxEncryptionKeyMsg extends Message<Uint8Array> {
606
- public static type() {
607
- return "get-tx-encryption-key-msg";
608
- }
609
-
610
- constructor(
611
- public readonly chainId: string,
612
- public readonly nonce: Uint8Array
613
- ) {
614
- super();
615
- }
616
-
617
- validateBasic(): void {
618
- if (!this.chainId) {
619
- throw new Error("chain id not set");
620
- }
621
-
622
- if (!this.nonce) {
623
- // Nonce of zero length is permitted.
624
- throw new Error("nonce is null");
625
- }
626
- }
627
-
628
- route(): string {
629
- return "secret-wasm";
630
- }
631
-
632
- type(): string {
633
- return GetTxEncryptionKeyMsg.type();
634
- }
635
- }
636
-
637
- export class GetChainInfosWithoutEndpointsMsg extends Message<{
638
- chainInfos: ChainInfoWithoutEndpoints[];
639
- }> {
640
- public static type() {
641
- return "get-chain-infos-without-endpoints";
642
- }
643
-
644
- validateBasic(): void {
645
- // noop
646
- }
647
-
648
- route(): string {
649
- return "chains";
650
- }
651
-
652
- type(): string {
653
- return GetChainInfosWithoutEndpointsMsg.type();
654
- }
655
- }
656
-
657
- export class GetAnalyticsIdMsg extends Message<string> {
658
- public static type() {
659
- return "get-analytics-id";
660
- }
661
-
662
- constructor() {
663
- super();
664
- }
665
-
666
- validateBasic(): void {
667
- // noop
668
- }
669
-
670
- approveExternal(): boolean {
671
- return true;
672
- }
673
-
674
- route(): string {
675
- return "analytics";
676
- }
677
-
678
- type(): string {
679
- return GetAnalyticsIdMsg.type();
680
- }
681
- }
682
-
683
- export class ChangeKeyRingNameMsg extends Message<string> {
684
- public static type() {
685
- return "change-keyring-name-msg";
686
- }
687
-
688
- constructor(
689
- public readonly defaultName: string,
690
- public readonly editable: boolean
691
- ) {
692
- super();
693
- }
694
-
695
- validateBasic(): void {
696
- // Not allow empty name.
697
- if (!this.defaultName) {
698
- throw new Error("default name not set");
699
- }
700
- }
701
-
702
- route(): string {
703
- return "keyring";
704
- }
705
-
706
- type(): string {
707
- return ChangeKeyRingNameMsg.type();
708
- }
709
- }