UNPKG

@metamask/keyring-snap-client

Version:
146 lines 6.74 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 keyring_api_1 = require("@metamask/keyring-api"); 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 partial - A partial JSON-RPC request (method and params). * @returns A promise that resolves to the response to the request. */ async send(partial) { return __classPrivateFieldGet(this, _KeyringClient_sender, "f").send({ jsonrpc: '2.0', id: (0, uuid_1.v4)(), ...partial, }); } async listAccounts() { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.ListAccounts, }), keyring_api_1.ListAccountsResponseStruct); } async getAccount(id) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.GetAccount, params: { id }, }), keyring_api_1.GetAccountResponseStruct); } async getAccountBalances(id, assets) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.GetAccountBalances, params: { id, assets }, }), keyring_api_1.GetAccountBalancesResponseStruct); } async createAccount(options = {}) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.CreateAccount, params: { options }, }), keyring_api_1.CreateAccountResponseStruct); } async discoverAccounts(scopes, entropySource, groupIndex) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.DiscoverAccounts, params: { scopes, entropySource, groupIndex }, }), keyring_api_1.DiscoverAccountsResponseStruct); } async listAccountTransactions(id, pagination) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.ListAccountTransactions, params: { id, pagination }, }), keyring_api_1.ListAccountTransactionsResponseStruct); } async listAccountAssets(id) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.ListAccountAssets, params: { id }, }), keyring_api_1.ListAccountAssetsResponseStruct); } async resolveAccountAddress(scope, request) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.ResolveAccountAddress, params: { scope, request }, }), keyring_api_1.ResolveAccountAddressResponseStruct); } async filterAccountChains(id, chains) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.FilterAccountChains, params: { id, chains }, }), keyring_api_1.FilterAccountChainsResponseStruct); } async updateAccount(account) { (0, superstruct_1.assert)(await this.send({ method: keyring_api_1.KeyringRpcMethod.UpdateAccount, params: { account }, }), keyring_api_1.UpdateAccountResponseStruct); } async deleteAccount(id) { (0, superstruct_1.assert)(await this.send({ method: keyring_api_1.KeyringRpcMethod.DeleteAccount, params: { id }, }), keyring_api_1.DeleteAccountResponseStruct); } async exportAccount(id) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.ExportAccount, params: { id }, }), keyring_api_1.ExportAccountResponseStruct); } async listRequests() { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.ListRequests, }), keyring_api_1.ListRequestsResponseStruct); } async getRequest(id) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.GetRequest, params: { id }, }), keyring_api_1.GetRequestResponseStruct); } async submitRequest(request) { return (0, keyring_utils_1.strictMask)(await this.send({ method: keyring_api_1.KeyringRpcMethod.SubmitRequest, params: request, }), keyring_api_1.SubmitRequestResponseStruct); } async approveRequest(id, data = {}) { (0, superstruct_1.assert)(await this.send({ method: keyring_api_1.KeyringRpcMethod.ApproveRequest, params: { id, data }, }), keyring_api_1.ApproveRequestResponseStruct); } async rejectRequest(id) { (0, superstruct_1.assert)(await this.send({ method: keyring_api_1.KeyringRpcMethod.RejectRequest, params: { id }, }), keyring_api_1.RejectRequestResponseStruct); } } exports.KeyringClient = KeyringClient; _KeyringClient_sender = new WeakMap(); //# sourceMappingURL=KeyringClient.cjs.map