@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/core.ts CHANGED
@@ -17,29 +17,13 @@ import {
17
17
  ICNSAdr36Signatures,
18
18
  ChainInfoWithoutEndpoints,
19
19
  SecretUtils,
20
+ SettledResponses,
20
21
  } from "@keplr-wallet/types";
21
- import { BACKGROUND_PORT, MessageRequester } from "@keplr-wallet/router";
22
22
  import {
23
- EnableAccessMsg,
24
- SuggestChainInfoMsg,
25
- GetKeyMsg,
26
- SuggestTokenMsg,
27
- SendTxMsg,
28
- GetSecret20ViewingKey,
29
- RequestSignAminoMsg,
30
- RequestSignDirectMsg,
31
- GetPubkeyMsg,
32
- ReqeustEncryptMsg,
33
- RequestDecryptMsg,
34
- GetTxEncryptionKeyMsg,
35
- RequestVerifyADR36AminoSignDoc,
36
- RequestSignEIP712CosmosTxMsg_v0,
37
- GetAnalyticsIdMsg,
38
- RequestICNSAdr36SignaturesMsg,
39
- GetChainInfosWithoutEndpointsMsg,
40
- DisableAccessMsg,
41
- ChangeKeyRingNameMsg,
42
- } from "./types";
23
+ BACKGROUND_PORT,
24
+ MessageRequester,
25
+ sendSimpleMessage,
26
+ } from "@keplr-wallet/router";
43
27
 
44
28
  import { KeplrEnigmaUtils } from "./enigma";
45
29
 
@@ -65,9 +49,14 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
65
49
  chainIds = [chainIds];
66
50
  }
67
51
 
68
- await this.requester.sendMessage(
52
+ await sendSimpleMessage(
53
+ this.requester,
69
54
  BACKGROUND_PORT,
70
- new EnableAccessMsg(chainIds)
55
+ "permission-interactive",
56
+ "enable-access",
57
+ {
58
+ chainIds,
59
+ }
71
60
  );
72
61
  }
73
62
 
@@ -76,9 +65,14 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
76
65
  chainIds = [chainIds];
77
66
  }
78
67
 
79
- await this.requester.sendMessage(
68
+ await sendSimpleMessage(
69
+ this.requester,
80
70
  BACKGROUND_PORT,
81
- new DisableAccessMsg(chainIds ?? [])
71
+ "permission-interactive",
72
+ "disable-access",
73
+ {
74
+ chainIds: chainIds ?? [],
75
+ }
82
76
  );
83
77
  }
84
78
 
@@ -98,13 +92,15 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
98
92
  const gasPriceStep = { ...chainInfo.gasPriceStep };
99
93
  for (const feeCurrency of chainInfo.feeCurrencies) {
100
94
  if (!feeCurrency.gasPriceStep) {
101
- (feeCurrency as {
102
- gasPriceStep?: {
103
- readonly low: number;
104
- readonly average: number;
105
- readonly high: number;
106
- };
107
- }).gasPriceStep = gasPriceStep;
95
+ (
96
+ feeCurrency as {
97
+ gasPriceStep?: {
98
+ readonly low: number;
99
+ readonly average: number;
100
+ readonly high: number;
101
+ };
102
+ }
103
+ ).gasPriceStep = gasPriceStep;
108
104
  }
109
105
  }
110
106
  delete chainInfo.gasPriceStep;
@@ -114,18 +110,58 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
114
110
  );
115
111
  }
116
112
 
117
- const msg = new SuggestChainInfoMsg(chainInfo);
118
- await this.requester.sendMessage(BACKGROUND_PORT, msg);
113
+ if ((chainInfo as any).coinType) {
114
+ console.warn(
115
+ "The `coinType` field of the `ChainInfo` is removed. This is automatically handled as of right now, but the upcoming update would potentially cause errors."
116
+ );
117
+ delete (chainInfo as any).coinType;
118
+ }
119
+
120
+ return await sendSimpleMessage(
121
+ this.requester,
122
+ BACKGROUND_PORT,
123
+ "chains",
124
+ "suggest-chain-info",
125
+ {
126
+ chainInfo,
127
+ }
128
+ );
119
129
  }
120
130
 
121
131
  async getKey(chainId: string): Promise<Key> {
122
- const msg = new GetKeyMsg(chainId);
123
- return await this.requester.sendMessage(BACKGROUND_PORT, msg);
132
+ return await sendSimpleMessage(
133
+ this.requester,
134
+ BACKGROUND_PORT,
135
+ "keyring-cosmos",
136
+ "get-cosmos-key",
137
+ {
138
+ chainId,
139
+ }
140
+ );
141
+ }
142
+
143
+ async getKeysSettled(chainIds: string[]): Promise<SettledResponses<Key>> {
144
+ return await sendSimpleMessage(
145
+ this.requester,
146
+ BACKGROUND_PORT,
147
+ "keyring-cosmos",
148
+ "get-cosmos-keys-settled",
149
+ {
150
+ chainIds,
151
+ }
152
+ );
124
153
  }
125
154
 
126
155
  async getChainInfosWithoutEndpoints(): Promise<ChainInfoWithoutEndpoints[]> {
127
- const msg = new GetChainInfosWithoutEndpointsMsg();
128
- return (await this.requester.sendMessage(BACKGROUND_PORT, msg)).chainInfos;
156
+ return (
157
+ await sendSimpleMessage(
158
+ this.requester,
159
+ BACKGROUND_PORT,
160
+ "chains",
161
+ "get-chain-infos-without-endpoints",
162
+ {}
163
+ )
164
+ ).chainInfos;
129
165
  }
130
166
 
131
167
  async sendTx(
@@ -133,8 +169,17 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
133
169
  tx: StdTx | Uint8Array,
134
170
  mode: BroadcastMode
135
171
  ): Promise<Uint8Array> {
136
- const msg = new SendTxMsg(chainId, tx, mode);
137
- return await this.requester.sendMessage(BACKGROUND_PORT, msg);
172
+ return await sendSimpleMessage(
173
+ this.requester,
174
+ BACKGROUND_PORT,
175
+ "background-tx",
176
+ "send-tx-to-background",
177
+ {
178
+ chainId,
179
+ tx,
180
+ mode,
181
+ }
182
+ );
138
183
  }
139
184
 
140
185
  async signAmino(
@@ -143,13 +188,18 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
143
188
  signDoc: StdSignDoc,
144
189
  signOptions: KeplrSignOptions = {}
145
190
  ): Promise<AminoSignResponse> {
146
- const msg = new RequestSignAminoMsg(
147
- chainId,
148
- signer,
149
- signDoc,
150
- deepmerge(this.defaultOptions.sign ?? {}, signOptions)
191
+ return await sendSimpleMessage(
192
+ this.requester,
193
+ BACKGROUND_PORT,
194
+ "keyring-cosmos",
195
+ "request-cosmos-sign-amino",
196
+ {
197
+ chainId,
198
+ signer,
199
+ signDoc,
200
+ signOptions: deepmerge(this.defaultOptions.sign ?? {}, signOptions),
201
+ }
151
202
  );
152
- return await this.requester.sendMessage(BACKGROUND_PORT, msg);
153
203
  }
154
204
 
155
205
  async signDirect(
@@ -163,20 +213,25 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
163
213
  },
164
214
  signOptions: KeplrSignOptions = {}
165
215
  ): Promise<DirectSignResponse> {
166
- const msg = new RequestSignDirectMsg(
167
- chainId,
168
- signer,
216
+ const response = await sendSimpleMessage(
217
+ this.requester,
218
+ BACKGROUND_PORT,
219
+ "keyring-cosmos",
220
+ "request-cosmos-sign-direct",
169
221
  {
170
- bodyBytes: signDoc.bodyBytes,
171
- authInfoBytes: signDoc.authInfoBytes,
172
- chainId: signDoc.chainId,
173
- accountNumber: signDoc.accountNumber
174
- ? signDoc.accountNumber.toString()
175
- : null,
176
- },
177
- deepmerge(this.defaultOptions.sign ?? {}, signOptions)
222
+ chainId,
223
+ signer,
224
+ signDoc: {
225
+ bodyBytes: signDoc.bodyBytes,
226
+ authInfoBytes: signDoc.authInfoBytes,
227
+ chainId: signDoc.chainId,
228
+ accountNumber: signDoc.accountNumber
229
+ ? signDoc.accountNumber.toString()
230
+ : null,
231
+ },
232
+ signOptions: deepmerge(this.defaultOptions.sign ?? {}, signOptions),
233
+ }
178
234
  );
179
- const response = await this.requester.sendMessage(BACKGROUND_PORT, msg);
180
235
 
181
236
  return {
182
237
  signed: {
@@ -194,14 +249,20 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
194
249
  signer: string,
195
250
  data: string | Uint8Array
196
251
  ): Promise<StdSignature> {
197
- let isADR36WithString: boolean;
198
- [data, isADR36WithString] = this.getDataForADR36(data);
199
- const signDoc = this.getADR36SignDoc(signer, data);
200
-
201
- const msg = new RequestSignAminoMsg(chainId, signer, signDoc, {
202
- isADR36WithString,
203
- });
204
- return (await this.requester.sendMessage(BACKGROUND_PORT, msg)).signature;
252
+ return await sendSimpleMessage(
253
+ this.requester,
254
+ BACKGROUND_PORT,
255
+ "keyring-cosmos",
256
+ "request-cosmos-sign-amino-adr-36",
257
+ {
258
+ chainId,
259
+ signer,
260
+ data: typeof data === "string" ? Buffer.from(data) : data,
261
+ signOptions: {
262
+ isADR36WithString: typeof data === "string",
263
+ },
264
+ }
265
+ );
205
266
  }
206
267
 
207
268
  async verifyArbitrary(
@@ -214,51 +275,48 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
214
275
  data = Buffer.from(data);
215
276
  }
216
277
 
217
- return await this.requester.sendMessage(
278
+ return await sendSimpleMessage(
279
+ this.requester,
218
280
  BACKGROUND_PORT,
219
- new RequestVerifyADR36AminoSignDoc(chainId, signer, data, signature)
281
+ "keyring-cosmos",
282
+ "verify-cosmos-sign-amino-adr-36",
283
+ {
284
+ chainId,
285
+ signer,
286
+ data,
287
+ signature,
288
+ }
220
289
  );
221
290
  }
222
291
 
223
292
  async signEthereum(
224
- chainId: string,
225
- signer: string,
226
- data: string | Uint8Array,
227
- type: EthSignType
293
+ _chainId: string,
294
+ _signer: string,
295
+ _data: string | Uint8Array,
296
+ _type: EthSignType
228
297
  ): Promise<Uint8Array> {
229
- let isADR36WithString: boolean;
230
- [data, isADR36WithString] = this.getDataForADR36(data);
231
- const signDoc = this.getADR36SignDoc(signer, data);
232
-
233
- if (data === "") {
234
- throw new Error("Signing empty data is not supported.");
235
- }
236
-
237
- const msg = new RequestSignAminoMsg(chainId, signer, signDoc, {
238
- isADR36WithString,
239
- ethSignType: type,
240
- });
241
- const signature = (await this.requester.sendMessage(BACKGROUND_PORT, msg))
242
- .signature;
243
- return Buffer.from(signature.signature, "base64");
298
+ throw new Error("TODO");
244
299
  }
245
300
 
246
- signICNSAdr36(
301
+ async signICNSAdr36(
247
302
  chainId: string,
248
303
  contractAddress: string,
249
304
  owner: string,
250
305
  username: string,
251
306
  addressChainIds: string[]
252
307
  ): Promise<ICNSAdr36Signatures> {
253
- return this.requester.sendMessage(
308
+ return await sendSimpleMessage(
309
+ this.requester,
254
310
  BACKGROUND_PORT,
255
- new RequestICNSAdr36SignaturesMsg(
311
+ "keyring-cosmos",
312
+ "request-icns-adr-36-signatures-v2",
313
+ {
256
314
  chainId,
257
315
  contractAddress,
258
316
  owner,
259
317
  username,
260
- addressChainIds
261
- )
318
+ addressChainIds,
319
+ }
262
320
  );
263
321
  }
264
322
 
@@ -285,22 +343,44 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
285
343
  contractAddress: string,
286
344
  viewingKey?: string
287
345
  ): Promise<void> {
288
- const msg = new SuggestTokenMsg(chainId, contractAddress, viewingKey);
289
- await this.requester.sendMessage(BACKGROUND_PORT, msg);
346
+ return await sendSimpleMessage(
347
+ this.requester,
348
+ BACKGROUND_PORT,
349
+ "token-cw20",
350
+ "SuggestTokenMsg",
351
+ {
352
+ chainId,
353
+ contractAddress,
354
+ viewingKey,
355
+ }
356
+ );
290
357
  }
291
358
 
292
359
  async getSecret20ViewingKey(
293
360
  chainId: string,
294
361
  contractAddress: string
295
362
  ): Promise<string> {
296
- const msg = new GetSecret20ViewingKey(chainId, contractAddress);
297
- return await this.requester.sendMessage(BACKGROUND_PORT, msg);
363
+ return await sendSimpleMessage(
364
+ this.requester,
365
+ BACKGROUND_PORT,
366
+ "token-cw20",
367
+ "get-secret20-viewing-key",
368
+ {
369
+ chainId,
370
+ contractAddress,
371
+ }
372
+ );
298
373
  }
299
374
 
300
375
  async getEnigmaPubKey(chainId: string): Promise<Uint8Array> {
301
- return await this.requester.sendMessage(
376
+ return await sendSimpleMessage(
377
+ this.requester,
302
378
  BACKGROUND_PORT,
303
- new GetPubkeyMsg(chainId)
379
+ "secret-wasm",
380
+ "get-pubkey-msg",
381
+ {
382
+ chainId,
383
+ }
304
384
  );
305
385
  }
306
386
 
@@ -308,9 +388,15 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
308
388
  chainId: string,
309
389
  nonce: Uint8Array
310
390
  ): Promise<Uint8Array> {
311
- return await this.requester.sendMessage(
391
+ return await sendSimpleMessage(
392
+ this.requester,
312
393
  BACKGROUND_PORT,
313
- new GetTxEncryptionKeyMsg(chainId, nonce)
394
+ "secret-wasm",
395
+ "get-tx-encryption-key-msg",
396
+ {
397
+ chainId,
398
+ nonce,
399
+ }
314
400
  );
315
401
  }
316
402
 
@@ -320,24 +406,38 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
320
406
  // eslint-disable-next-line @typescript-eslint/ban-types
321
407
  msg: object
322
408
  ): Promise<Uint8Array> {
323
- return await this.requester.sendMessage(
409
+ return await sendSimpleMessage(
410
+ this.requester,
324
411
  BACKGROUND_PORT,
325
- new ReqeustEncryptMsg(chainId, contractCodeHash, msg)
412
+ "secret-wasm",
413
+ "request-encrypt-msg",
414
+ {
415
+ chainId,
416
+ contractCodeHash,
417
+ msg,
418
+ }
326
419
  );
327
420
  }
328
421
 
329
422
  async enigmaDecrypt(
330
423
  chainId: string,
331
- ciphertext: Uint8Array,
424
+ cipherText: Uint8Array,
332
425
  nonce: Uint8Array
333
426
  ): Promise<Uint8Array> {
334
- if (!ciphertext || ciphertext.length === 0) {
427
+ if (!cipherText || cipherText.length === 0) {
335
428
  return new Uint8Array();
336
429
  }
337
430
 
338
- return await this.requester.sendMessage(
431
+ return await sendSimpleMessage(
432
+ this.requester,
339
433
  BACKGROUND_PORT,
340
- new RequestDecryptMsg(chainId, ciphertext, nonce)
434
+ "secret-wasm",
435
+ "request-decrypt-msg",
436
+ {
437
+ chainId,
438
+ cipherText,
439
+ nonce,
440
+ }
341
441
  );
342
442
  }
343
443
 
@@ -363,52 +463,29 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
363
463
  signDoc: StdSignDoc,
364
464
  signOptions: KeplrSignOptions = {}
365
465
  ): Promise<AminoSignResponse> {
366
- const msg = new RequestSignEIP712CosmosTxMsg_v0(
367
- chainId,
368
- signer,
369
- eip712,
370
- signDoc,
371
- deepmerge(this.defaultOptions.sign ?? {}, signOptions)
466
+ return await sendSimpleMessage(
467
+ this.requester,
468
+ BACKGROUND_PORT,
469
+ "keyring-cosmos",
470
+ "request-sign-eip-712-cosmos-tx-v0",
471
+ {
472
+ chainId,
473
+ signer,
474
+ eip712,
475
+ signDoc,
476
+ signOptions: deepmerge(this.defaultOptions.sign ?? {}, signOptions),
477
+ }
372
478
  );
373
- return await this.requester.sendMessage(BACKGROUND_PORT, msg);
374
- }
375
-
376
- protected getDataForADR36(data: string | Uint8Array): [string, boolean] {
377
- let isADR36WithString = false;
378
- if (typeof data === "string") {
379
- data = Buffer.from(data).toString("base64");
380
- isADR36WithString = true;
381
- } else {
382
- data = Buffer.from(data).toString("base64");
383
- }
384
- return [data, isADR36WithString];
385
479
  }
386
480
 
387
- protected getADR36SignDoc(signer: string, data: string): StdSignDoc {
388
- return {
389
- chain_id: "",
390
- account_number: "0",
391
- sequence: "0",
392
- fee: {
393
- gas: "0",
394
- amount: [],
395
- },
396
- msgs: [
397
- {
398
- type: "sign/MsgSignData",
399
- value: {
400
- signer,
401
- data,
402
- },
403
- },
404
- ],
405
- memo: "",
406
- };
407
- }
408
-
409
- __core__getAnalyticsId(): Promise<string> {
410
- const msg = new GetAnalyticsIdMsg();
411
- return this.requester.sendMessage(BACKGROUND_PORT, msg);
481
+ async __core__getAnalyticsId(): Promise<string> {
482
+ return await sendSimpleMessage(
483
+ this.requester,
484
+ BACKGROUND_PORT,
485
+ "analytics",
486
+ "get-analytics-id",
487
+ {}
488
+ );
412
489
  }
413
490
 
414
491
  async changeKeyRingName({
@@ -418,8 +495,15 @@ export class Keplr implements IKeplr, KeplrCoreTypes {
418
495
  defaultName: string;
419
496
  editable?: boolean;
420
497
  }): Promise<string> {
421
- const msg = new ChangeKeyRingNameMsg(defaultName, editable);
422
-
423
- return await this.requester.sendMessage(BACKGROUND_PORT, msg);
498
+ return await sendSimpleMessage(
499
+ this.requester,
500
+ BACKGROUND_PORT,
501
+ "keyring-v2",
502
+ "change-keyring-name-interactive",
503
+ {
504
+ defaultName,
505
+ editable,
506
+ }
507
+ );
424
508
  }
425
509
  }
package/src/cosmjs.ts CHANGED
@@ -56,11 +56,9 @@ export class CosmJSOfflineSignerOnlyAmino implements OfflineAminoSigner {
56
56
 
57
57
  export class CosmJSOfflineSigner
58
58
  extends CosmJSOfflineSignerOnlyAmino
59
- implements OfflineAminoSigner, OfflineDirectSigner {
60
- constructor(
61
- protected readonly chainId: string,
62
- protected readonly keplr: Keplr
63
- ) {
59
+ implements OfflineAminoSigner, OfflineDirectSigner
60
+ {
61
+ constructor(chainId: string, keplr: Keplr) {
64
62
  super(chainId, keplr);
65
63
  }
66
64
 
package/src/inject.ts CHANGED
@@ -18,8 +18,10 @@ import {
18
18
  ICNSAdr36Signatures,
19
19
  ChainInfoWithoutEndpoints,
20
20
  SecretUtils,
21
+ SettledResponses,
21
22
  } from "@keplr-wallet/types";
22
- import { Result, JSONUint8Array } from "@keplr-wallet/router";
23
+ import { Result } from "@keplr-wallet/router";
24
+ import { JSONUint8Array } from "@keplr-wallet/common";
23
25
  import { KeplrEnigmaUtils } from "./enigma";
24
26
  import { CosmJSOfflineSigner, CosmJSOfflineSignerOnlyAmino } from "./cosmjs";
25
27
  import deepmerge from "deepmerge";
@@ -353,6 +355,10 @@ export class InjectedKeplr implements IKeplr, KeplrCoreTypes {
353
355
  return await this.requestMethod("getKey", [chainId]);
354
356
  }
355
357
 
358
+ async getKeysSettled(chainIds: string[]): Promise<SettledResponses<Key>> {
359
+ return await this.requestMethod("getKeysSettled", [chainIds]);
360
+ }
361
+
356
362
  async sendTx(
357
363
  chainId: string,
358
364
  tx: StdTx | Uint8Array,
@@ -1 +0,0 @@
1
- export * from "./msgs";
@@ -1,14 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./msgs"), exports);
14
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yCAAuB"}