@metamask-previews/keyring-snap-client 8.2.1-c26e419 → 8.2.1-ea8175e
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/CHANGELOG.md +9 -0
- package/dist/v2/KeyringClient.cjs +91 -0
- package/dist/v2/KeyringClient.cjs.map +1 -0
- package/dist/v2/KeyringClient.d.cts +29 -0
- package/dist/v2/KeyringClient.d.cts.map +1 -0
- package/dist/v2/KeyringClient.d.mts +29 -0
- package/dist/v2/KeyringClient.d.mts.map +1 -0
- package/dist/v2/KeyringClient.mjs +87 -0
- package/dist/v2/KeyringClient.mjs.map +1 -0
- package/dist/v2/index.cjs +18 -0
- package/dist/v2/index.cjs.map +1 -0
- package/dist/v2/index.d.cts +2 -0
- package/dist/v2/index.d.cts.map +1 -0
- package/dist/v2/index.d.mts +2 -0
- package/dist/v2/index.d.mts.map +1 -0
- package/dist/v2/index.mjs +2 -0
- package/dist/v2/index.mjs.map +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Add `KeyringClientV2` class implementing the keyring v2 RPC client ([#408](https://github.com/MetaMask/accounts/pull/408))
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- **BREAKING:** Move and rename `KeyringClientV2` to the new `./v2` subpath export ([#513](https://github.com/MetaMask/accounts/pull/513))
|
|
17
|
+
- `KeyringClientV2` is now `KeyringClient` from `@metamask/keyring-snap-client/v2`.
|
|
18
|
+
|
|
10
19
|
## [8.2.1]
|
|
11
20
|
|
|
12
21
|
### Changed
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _KeyringClient_sender;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.KeyringClient = void 0;
|
|
16
|
+
const v2_1 = require("@metamask/keyring-api/v2");
|
|
17
|
+
const keyring_utils_1 = require("@metamask/keyring-utils");
|
|
18
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
19
|
+
const uuid_1 = require("uuid");
|
|
20
|
+
class KeyringClient {
|
|
21
|
+
/**
|
|
22
|
+
* Create a new instance of `KeyringClient`.
|
|
23
|
+
*
|
|
24
|
+
* @param sender - The `Sender` instance to use to send requests to the snap.
|
|
25
|
+
*/
|
|
26
|
+
constructor(sender) {
|
|
27
|
+
_KeyringClient_sender.set(this, void 0);
|
|
28
|
+
__classPrivateFieldSet(this, _KeyringClient_sender, sender, "f");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Send a request to the Snap and return the response.
|
|
32
|
+
*
|
|
33
|
+
* @param request - A partial JSON-RPC request (method and params).
|
|
34
|
+
* @returns A promise that resolves to the response to the request.
|
|
35
|
+
*/
|
|
36
|
+
async send(request) {
|
|
37
|
+
return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
|
|
38
|
+
...request,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
async getAccounts() {
|
|
42
|
+
return (0, keyring_utils_1.strictMask)(await this.send({
|
|
43
|
+
jsonrpc: '2.0',
|
|
44
|
+
id: (0, uuid_1.v4)(),
|
|
45
|
+
method: v2_1.KeyringRpcMethod.GetAccounts,
|
|
46
|
+
}), v2_1.GetAccountsResponseStruct);
|
|
47
|
+
}
|
|
48
|
+
async getAccount(id) {
|
|
49
|
+
return (0, keyring_utils_1.strictMask)(await this.send({
|
|
50
|
+
jsonrpc: '2.0',
|
|
51
|
+
id: (0, uuid_1.v4)(),
|
|
52
|
+
method: v2_1.KeyringRpcMethod.GetAccount,
|
|
53
|
+
params: { id },
|
|
54
|
+
}), v2_1.GetAccountResponseStruct);
|
|
55
|
+
}
|
|
56
|
+
async createAccounts(params) {
|
|
57
|
+
return (0, keyring_utils_1.strictMask)(await this.send({
|
|
58
|
+
jsonrpc: '2.0',
|
|
59
|
+
id: (0, uuid_1.v4)(),
|
|
60
|
+
method: v2_1.KeyringRpcMethod.CreateAccounts,
|
|
61
|
+
params,
|
|
62
|
+
}), v2_1.CreateAccountsResponseStruct);
|
|
63
|
+
}
|
|
64
|
+
async exportAccount(id, options) {
|
|
65
|
+
return (0, keyring_utils_1.strictMask)(await this.send({
|
|
66
|
+
jsonrpc: '2.0',
|
|
67
|
+
id: (0, uuid_1.v4)(),
|
|
68
|
+
method: v2_1.KeyringRpcMethod.ExportAccount,
|
|
69
|
+
params: { id, ...(options && { options }) },
|
|
70
|
+
}), v2_1.ExportAccountResponseStruct);
|
|
71
|
+
}
|
|
72
|
+
async deleteAccount(id) {
|
|
73
|
+
(0, superstruct_1.assert)(await this.send({
|
|
74
|
+
jsonrpc: '2.0',
|
|
75
|
+
id: (0, uuid_1.v4)(),
|
|
76
|
+
method: v2_1.KeyringRpcMethod.DeleteAccount,
|
|
77
|
+
params: { id },
|
|
78
|
+
}), v2_1.DeleteAccountResponseStruct);
|
|
79
|
+
}
|
|
80
|
+
async submitRequest(request) {
|
|
81
|
+
return (0, keyring_utils_1.strictMask)(await this.send({
|
|
82
|
+
jsonrpc: '2.0',
|
|
83
|
+
id: (0, uuid_1.v4)(),
|
|
84
|
+
method: v2_1.KeyringRpcMethod.SubmitRequest,
|
|
85
|
+
params: request,
|
|
86
|
+
}), v2_1.SubmitRequestResponseStruct);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
exports.KeyringClient = KeyringClient;
|
|
90
|
+
_KeyringClient_sender = new WeakMap();
|
|
91
|
+
//# sourceMappingURL=KeyringClient.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringClient.cjs","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,iDAQkC;AASlC,2DAAqD;AACrD,uDAA+C;AAE/C,+BAAkC;AAIlC,MAAa,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,IAAI,CAClB,OAAyC;QAEzC,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;YACvB,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAA,SAAI,GAAE;YACV,MAAM,EAAE,qBAAgB,CAAC,WAAW;SACrC,CAAC,EACF,8BAAyB,CAC1B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,IAAA,0BAAU,EACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,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AAa;YACtC,MAAM,EAAE,OAAO;SAChB,CAAC,EACF,gCAA2B,CAC5B,CAAC;IACJ,CAAC;CACF;AArGD,sCAqGC","sourcesContent":["import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n CreateAccountsResponseStruct,\n DeleteAccountResponseStruct,\n GetAccountResponseStruct,\n GetAccountsResponseStruct,\n SubmitRequestResponseStruct,\n KeyringRpcMethod,\n ExportAccountResponseStruct,\n} from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringRpc,\n KeyringRpcRequest,\n} from '@metamask/keyring-api/v2';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Sender } from '../KeyringClient';\n\nexport class KeyringClient implements KeyringRpc {\n readonly #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the Snap and return the response.\n *\n * @param request - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n protected async send<RequestMethod extends KeyringRpcMethod>(\n request: KeyringRpcRequest<RequestMethod>,\n ): Promise<Json> {\n return this.#sender.send({\n ...request,\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccounts,\n }),\n GetAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async createAccounts(\n params: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.CreateAccounts,\n params,\n }),\n CreateAccountsResponseStruct,\n );\n }\n\n async exportAccount(\n id: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.ExportAccount,\n params: { id, ...(options && { options }) },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: AccountId): Promise<void> {\n assert(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<Json> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
|
|
2
|
+
import { KeyringRpcMethod } from "@metamask/keyring-api/v2";
|
|
3
|
+
import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringRpc, KeyringRpcRequest } from "@metamask/keyring-api/v2";
|
|
4
|
+
import type { AccountId } from "@metamask/keyring-utils";
|
|
5
|
+
import type { Json } from "@metamask/utils";
|
|
6
|
+
import type { Sender } from "../KeyringClient.cjs";
|
|
7
|
+
export declare class KeyringClient implements KeyringRpc {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new instance of `KeyringClient`.
|
|
11
|
+
*
|
|
12
|
+
* @param sender - The `Sender` instance to use to send requests to the snap.
|
|
13
|
+
*/
|
|
14
|
+
constructor(sender: Sender);
|
|
15
|
+
/**
|
|
16
|
+
* Send a request to the Snap and return the response.
|
|
17
|
+
*
|
|
18
|
+
* @param request - A partial JSON-RPC request (method and params).
|
|
19
|
+
* @returns A promise that resolves to the response to the request.
|
|
20
|
+
*/
|
|
21
|
+
protected send<RequestMethod extends KeyringRpcMethod>(request: KeyringRpcRequest<RequestMethod>): Promise<Json>;
|
|
22
|
+
getAccounts(): Promise<KeyringAccount[]>;
|
|
23
|
+
getAccount(id: string): Promise<KeyringAccount>;
|
|
24
|
+
createAccounts(params: CreateAccountOptions): Promise<KeyringAccount[]>;
|
|
25
|
+
exportAccount(id: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
|
|
26
|
+
deleteAccount(id: AccountId): Promise<void>;
|
|
27
|
+
submitRequest(request: KeyringRequest): Promise<Json>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=KeyringClient.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringClient.d.cts","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAC5E,OAAO,EAML,gBAAgB,EAEjB,iCAAiC;AAClC,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,iCAAiC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,MAAM,EAAE,6BAAyB;AAE/C,qBAAa,aAAc,YAAW,UAAU;;IAG9C;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;OAKG;cACa,IAAI,CAAC,aAAa,SAAS,gBAAgB,EACzD,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC;IAMV,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAWxC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAY/C,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,cAAc,EAAE,CAAC;IAYtB,aAAa,CACjB,EAAE,EAAE,SAAS,EACb,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAYrB,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAY3C,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAW5D"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { KeyringAccount, KeyringRequest } from "@metamask/keyring-api";
|
|
2
|
+
import { KeyringRpcMethod } from "@metamask/keyring-api/v2";
|
|
3
|
+
import type { CreateAccountOptions, ExportAccountOptions, ExportedAccount, KeyringRpc, KeyringRpcRequest } from "@metamask/keyring-api/v2";
|
|
4
|
+
import type { AccountId } from "@metamask/keyring-utils";
|
|
5
|
+
import type { Json } from "@metamask/utils";
|
|
6
|
+
import type { Sender } from "../KeyringClient.mjs";
|
|
7
|
+
export declare class KeyringClient implements KeyringRpc {
|
|
8
|
+
#private;
|
|
9
|
+
/**
|
|
10
|
+
* Create a new instance of `KeyringClient`.
|
|
11
|
+
*
|
|
12
|
+
* @param sender - The `Sender` instance to use to send requests to the snap.
|
|
13
|
+
*/
|
|
14
|
+
constructor(sender: Sender);
|
|
15
|
+
/**
|
|
16
|
+
* Send a request to the Snap and return the response.
|
|
17
|
+
*
|
|
18
|
+
* @param request - A partial JSON-RPC request (method and params).
|
|
19
|
+
* @returns A promise that resolves to the response to the request.
|
|
20
|
+
*/
|
|
21
|
+
protected send<RequestMethod extends KeyringRpcMethod>(request: KeyringRpcRequest<RequestMethod>): Promise<Json>;
|
|
22
|
+
getAccounts(): Promise<KeyringAccount[]>;
|
|
23
|
+
getAccount(id: string): Promise<KeyringAccount>;
|
|
24
|
+
createAccounts(params: CreateAccountOptions): Promise<KeyringAccount[]>;
|
|
25
|
+
exportAccount(id: AccountId, options?: ExportAccountOptions): Promise<ExportedAccount>;
|
|
26
|
+
deleteAccount(id: AccountId): Promise<void>;
|
|
27
|
+
submitRequest(request: KeyringRequest): Promise<Json>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=KeyringClient.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringClient.d.mts","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,8BAA8B;AAC5E,OAAO,EAML,gBAAgB,EAEjB,iCAAiC;AAClC,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACpB,eAAe,EACf,UAAU,EACV,iBAAiB,EAClB,iCAAiC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,gCAAgC;AAGzD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAG5C,OAAO,KAAK,EAAE,MAAM,EAAE,6BAAyB;AAE/C,qBAAa,aAAc,YAAW,UAAU;;IAG9C;;;;OAIG;gBACS,MAAM,EAAE,MAAM;IAI1B;;;;;OAKG;cACa,IAAI,CAAC,aAAa,SAAS,gBAAgB,EACzD,OAAO,EAAE,iBAAiB,CAAC,aAAa,CAAC,GACxC,OAAO,CAAC,IAAI,CAAC;IAMV,WAAW,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAWxC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAY/C,cAAc,CAClB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,cAAc,EAAE,CAAC;IAYtB,aAAa,CACjB,EAAE,EAAE,SAAS,EACb,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,eAAe,CAAC;IAYrB,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAY3C,aAAa,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAW5D"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _KeyringClient_sender;
|
|
13
|
+
import { CreateAccountsResponseStruct, DeleteAccountResponseStruct, GetAccountResponseStruct, GetAccountsResponseStruct, SubmitRequestResponseStruct, KeyringRpcMethod, ExportAccountResponseStruct } from "@metamask/keyring-api/v2";
|
|
14
|
+
import { strictMask } from "@metamask/keyring-utils";
|
|
15
|
+
import { assert } from "@metamask/superstruct";
|
|
16
|
+
import { v4 as uuid } from "uuid";
|
|
17
|
+
export class KeyringClient {
|
|
18
|
+
/**
|
|
19
|
+
* Create a new instance of `KeyringClient`.
|
|
20
|
+
*
|
|
21
|
+
* @param sender - The `Sender` instance to use to send requests to the snap.
|
|
22
|
+
*/
|
|
23
|
+
constructor(sender) {
|
|
24
|
+
_KeyringClient_sender.set(this, void 0);
|
|
25
|
+
__classPrivateFieldSet(this, _KeyringClient_sender, sender, "f");
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Send a request to the Snap and return the response.
|
|
29
|
+
*
|
|
30
|
+
* @param request - A partial JSON-RPC request (method and params).
|
|
31
|
+
* @returns A promise that resolves to the response to the request.
|
|
32
|
+
*/
|
|
33
|
+
async send(request) {
|
|
34
|
+
return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({
|
|
35
|
+
...request,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async getAccounts() {
|
|
39
|
+
return strictMask(await this.send({
|
|
40
|
+
jsonrpc: '2.0',
|
|
41
|
+
id: uuid(),
|
|
42
|
+
method: KeyringRpcMethod.GetAccounts,
|
|
43
|
+
}), GetAccountsResponseStruct);
|
|
44
|
+
}
|
|
45
|
+
async getAccount(id) {
|
|
46
|
+
return strictMask(await this.send({
|
|
47
|
+
jsonrpc: '2.0',
|
|
48
|
+
id: uuid(),
|
|
49
|
+
method: KeyringRpcMethod.GetAccount,
|
|
50
|
+
params: { id },
|
|
51
|
+
}), GetAccountResponseStruct);
|
|
52
|
+
}
|
|
53
|
+
async createAccounts(params) {
|
|
54
|
+
return strictMask(await this.send({
|
|
55
|
+
jsonrpc: '2.0',
|
|
56
|
+
id: uuid(),
|
|
57
|
+
method: KeyringRpcMethod.CreateAccounts,
|
|
58
|
+
params,
|
|
59
|
+
}), CreateAccountsResponseStruct);
|
|
60
|
+
}
|
|
61
|
+
async exportAccount(id, options) {
|
|
62
|
+
return strictMask(await this.send({
|
|
63
|
+
jsonrpc: '2.0',
|
|
64
|
+
id: uuid(),
|
|
65
|
+
method: KeyringRpcMethod.ExportAccount,
|
|
66
|
+
params: { id, ...(options && { options }) },
|
|
67
|
+
}), ExportAccountResponseStruct);
|
|
68
|
+
}
|
|
69
|
+
async deleteAccount(id) {
|
|
70
|
+
assert(await this.send({
|
|
71
|
+
jsonrpc: '2.0',
|
|
72
|
+
id: uuid(),
|
|
73
|
+
method: KeyringRpcMethod.DeleteAccount,
|
|
74
|
+
params: { id },
|
|
75
|
+
}), DeleteAccountResponseStruct);
|
|
76
|
+
}
|
|
77
|
+
async submitRequest(request) {
|
|
78
|
+
return strictMask(await this.send({
|
|
79
|
+
jsonrpc: '2.0',
|
|
80
|
+
id: uuid(),
|
|
81
|
+
method: KeyringRpcMethod.SubmitRequest,
|
|
82
|
+
params: request,
|
|
83
|
+
}), SubmitRequestResponseStruct);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
_KeyringClient_sender = new WeakMap();
|
|
87
|
+
//# sourceMappingURL=KeyringClient.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyringClient.mjs","sourceRoot":"","sources":["../../src/v2/KeyringClient.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,OAAO,EACL,4BAA4B,EAC5B,2BAA2B,EAC3B,wBAAwB,EACxB,yBAAyB,EACzB,2BAA2B,EAC3B,gBAAgB,EAChB,2BAA2B,EAC5B,iCAAiC;AASlC,OAAO,EAAE,UAAU,EAAE,gCAAgC;AACrD,OAAO,EAAE,MAAM,EAAE,8BAA8B;AAE/C,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAIlC,MAAM,OAAO,aAAa;IAGxB;;;;OAIG;IACH,YAAY,MAAc;QAPjB,wCAAgB;QAQvB,uBAAA,IAAI,yBAAW,MAAM,MAAA,CAAC;IACxB,CAAC;IAED;;;;;OAKG;IACO,KAAK,CAAC,IAAI,CAClB,OAAyC;QAEzC,OAAO,uBAAA,IAAI,6BAAQ,CAAC,IAAI,CAAC;YACvB,GAAG,OAAO;SACX,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,WAAW;QACf,OAAO,UAAU,CACf,MAAM,IAAI,CAAC,IAAI,CAAC;YACd,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,IAAI,EAAE;YACV,MAAM,EAAE,gBAAgB,CAAC,WAAW;SACrC,CAAC,EACF,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,EAAU;QACzB,OAAO,UAAU,CACf,MA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O;SAChB,CAAC,EACF,2BAA2B,CAC5B,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { KeyringAccount, KeyringRequest } from '@metamask/keyring-api';\nimport {\n CreateAccountsResponseStruct,\n DeleteAccountResponseStruct,\n GetAccountResponseStruct,\n GetAccountsResponseStruct,\n SubmitRequestResponseStruct,\n KeyringRpcMethod,\n ExportAccountResponseStruct,\n} from '@metamask/keyring-api/v2';\nimport type {\n CreateAccountOptions,\n ExportAccountOptions,\n ExportedAccount,\n KeyringRpc,\n KeyringRpcRequest,\n} from '@metamask/keyring-api/v2';\nimport type { AccountId } from '@metamask/keyring-utils';\nimport { strictMask } from '@metamask/keyring-utils';\nimport { assert } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { v4 as uuid } from 'uuid';\n\nimport type { Sender } from '../KeyringClient';\n\nexport class KeyringClient implements KeyringRpc {\n readonly #sender: Sender;\n\n /**\n * Create a new instance of `KeyringClient`.\n *\n * @param sender - The `Sender` instance to use to send requests to the snap.\n */\n constructor(sender: Sender) {\n this.#sender = sender;\n }\n\n /**\n * Send a request to the Snap and return the response.\n *\n * @param request - A partial JSON-RPC request (method and params).\n * @returns A promise that resolves to the response to the request.\n */\n protected async send<RequestMethod extends KeyringRpcMethod>(\n request: KeyringRpcRequest<RequestMethod>,\n ): Promise<Json> {\n return this.#sender.send({\n ...request,\n });\n }\n\n async getAccounts(): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccounts,\n }),\n GetAccountsResponseStruct,\n );\n }\n\n async getAccount(id: string): Promise<KeyringAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.GetAccount,\n params: { id },\n }),\n GetAccountResponseStruct,\n );\n }\n\n async createAccounts(\n params: CreateAccountOptions,\n ): Promise<KeyringAccount[]> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.CreateAccounts,\n params,\n }),\n CreateAccountsResponseStruct,\n );\n }\n\n async exportAccount(\n id: AccountId,\n options?: ExportAccountOptions,\n ): Promise<ExportedAccount> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.ExportAccount,\n params: { id, ...(options && { options }) },\n }),\n ExportAccountResponseStruct,\n );\n }\n\n async deleteAccount(id: AccountId): Promise<void> {\n assert(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.DeleteAccount,\n params: { id },\n }),\n DeleteAccountResponseStruct,\n );\n }\n\n async submitRequest(request: KeyringRequest): Promise<Json> {\n return strictMask(\n await this.send({\n jsonrpc: '2.0',\n id: uuid(),\n method: KeyringRpcMethod.SubmitRequest,\n params: request,\n }),\n SubmitRequestResponseStruct,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
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);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./KeyringClient.cjs"), exports);
|
|
18
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAgC","sourcesContent":["export * from './KeyringClient';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,oCAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,oCAAgC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/v2/index.ts"],"names":[],"mappings":"AAAA,oCAAgC","sourcesContent":["export * from './KeyringClient';\n"]}
|