UNPKG

@metamask/keyring-snap-client

Version:
91 lines 3.99 kB
"use strict"; var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) { if (kind === "m") throw new TypeError("Private method is not writable"); if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter"); 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"); return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value; }; var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); 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"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _KeyringClient_sender; Object.defineProperty(exports, "__esModule", { value: true }); exports.KeyringClient = void 0; const v2_1 = require("@metamask/keyring-api/v2"); const keyring_utils_1 = require("@metamask/keyring-utils"); const superstruct_1 = require("@metamask/superstruct"); const uuid_1 = require("uuid"); class KeyringClient { /** * Create a new instance of `KeyringClient`. * * @param sender - The `Sender` instance to use to send requests to the snap. */ constructor(sender) { _KeyringClient_sender.set(this, void 0); __classPrivateFieldSet(this, _KeyringClient_sender, sender, "f"); } /** * Send a request to the Snap and return the response. * * @param request - A partial JSON-RPC request (method and params). * @returns A promise that resolves to the response to the request. */ async send(request) { return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({ ...request, }); } async getAccounts() { return (0, keyring_utils_1.strictMask)(await this.send({ jsonrpc: '2.0', id: (0, uuid_1.v4)(), method: v2_1.KeyringRpcMethod.GetAccounts, }), v2_1.GetAccountsResponseStruct); } async getAccount(id) { return (0, keyring_utils_1.strictMask)(await this.send({ jsonrpc: '2.0', id: (0, uuid_1.v4)(), method: v2_1.KeyringRpcMethod.GetAccount, params: { id }, }), v2_1.GetAccountResponseStruct); } async createAccounts(params) { return (0, keyring_utils_1.strictMask)(await this.send({ jsonrpc: '2.0', id: (0, uuid_1.v4)(), method: v2_1.KeyringRpcMethod.CreateAccounts, params, }), v2_1.CreateAccountsResponseStruct); } async exportAccount(id, options) { return (0, keyring_utils_1.strictMask)(await this.send({ jsonrpc: '2.0', id: (0, uuid_1.v4)(), method: v2_1.KeyringRpcMethod.ExportAccount, params: { id, ...(options && { options }) }, }), v2_1.ExportAccountResponseStruct); } async deleteAccount(id) { (0, superstruct_1.assert)(await this.send({ jsonrpc: '2.0', id: (0, uuid_1.v4)(), method: v2_1.KeyringRpcMethod.DeleteAccount, params: { id }, }), v2_1.DeleteAccountResponseStruct); } async submitRequest(request) { return (0, keyring_utils_1.strictMask)(await this.send({ jsonrpc: '2.0', id: (0, uuid_1.v4)(), method: v2_1.KeyringRpcMethod.SubmitRequest, params: request, }), v2_1.SubmitRequestResponseStruct); } } exports.KeyringClient = KeyringClient; _KeyringClient_sender = new WeakMap(); //# sourceMappingURL=KeyringClient.cjs.map