UNPKG

@metamask/keyring-snap-client

Version:
154 lines 6.78 kB
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; import { ApproveRequestResponseStruct, CreateAccountResponseStruct, CreateAccountsResponseStruct, DeleteAccountResponseStruct, ExportAccountResponseStruct, FilterAccountChainsResponseStruct, GetAccountBalancesResponseStruct, GetAccountResponseStruct, GetRequestResponseStruct, ListAccountsResponseStruct, ListAccountTransactionsResponseStruct, ListAccountAssetsResponseStruct, ListRequestsResponseStruct, RejectRequestResponseStruct, SubmitRequestResponseStruct, UpdateAccountResponseStruct, KeyringRpcMethod, ResolveAccountAddressResponseStruct, DiscoverAccountsResponseStruct, SetSelectedAccountsResponseStruct } from "@metamask/keyring-api"; import { strictMask } from "@metamask/keyring-utils"; import { assert } from "@metamask/superstruct"; import { v4 as uuid } from "uuid"; export 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: uuid(), ...partial, }); } async listAccounts() { return strictMask(await this.send({ method: KeyringRpcMethod.ListAccounts, }), ListAccountsResponseStruct); } async getAccount(id) { return strictMask(await this.send({ method: KeyringRpcMethod.GetAccount, params: { id }, }), GetAccountResponseStruct); } async getAccountBalances(id, assets) { return strictMask(await this.send({ method: KeyringRpcMethod.GetAccountBalances, params: { id, assets }, }), GetAccountBalancesResponseStruct); } async createAccount(options = {}) { return strictMask(await this.send({ method: KeyringRpcMethod.CreateAccount, params: { options }, }), CreateAccountResponseStruct); } async createAccounts(options) { return strictMask(await this.send({ method: KeyringRpcMethod.CreateAccounts, params: { options }, }), CreateAccountsResponseStruct); } async discoverAccounts(scopes, entropySource, groupIndex) { return strictMask(await this.send({ method: KeyringRpcMethod.DiscoverAccounts, params: { scopes, entropySource, groupIndex }, }), DiscoverAccountsResponseStruct); } async listAccountTransactions(id, pagination) { return strictMask(await this.send({ method: KeyringRpcMethod.ListAccountTransactions, params: { id, pagination }, }), ListAccountTransactionsResponseStruct); } async listAccountAssets(id) { return strictMask(await this.send({ method: KeyringRpcMethod.ListAccountAssets, params: { id }, }), ListAccountAssetsResponseStruct); } async resolveAccountAddress(scope, request) { return strictMask(await this.send({ method: KeyringRpcMethod.ResolveAccountAddress, params: { scope, request }, }), ResolveAccountAddressResponseStruct); } async setSelectedAccounts(accounts) { strictMask(await this.send({ method: KeyringRpcMethod.SetSelectedAccounts, params: { accounts }, }), SetSelectedAccountsResponseStruct); } async filterAccountChains(id, chains) { return strictMask(await this.send({ method: KeyringRpcMethod.FilterAccountChains, params: { id, chains }, }), FilterAccountChainsResponseStruct); } async updateAccount(account) { assert(await this.send({ method: KeyringRpcMethod.UpdateAccount, params: { account }, }), UpdateAccountResponseStruct); } async deleteAccount(id) { assert(await this.send({ method: KeyringRpcMethod.DeleteAccount, params: { id }, }), DeleteAccountResponseStruct); } async exportAccount(id) { return strictMask(await this.send({ method: KeyringRpcMethod.ExportAccount, params: { id }, }), ExportAccountResponseStruct); } async listRequests() { return strictMask(await this.send({ method: KeyringRpcMethod.ListRequests, }), ListRequestsResponseStruct); } async getRequest(id) { return strictMask(await this.send({ method: KeyringRpcMethod.GetRequest, params: { id }, }), GetRequestResponseStruct); } async submitRequest(request) { return strictMask(await this.send({ method: KeyringRpcMethod.SubmitRequest, params: request, }), SubmitRequestResponseStruct); } async approveRequest(id, data = {}) { assert(await this.send({ method: KeyringRpcMethod.ApproveRequest, params: { id, data }, }), ApproveRequestResponseStruct); } async rejectRequest(id) { assert(await this.send({ method: KeyringRpcMethod.RejectRequest, params: { id }, }), RejectRequestResponseStruct); } } _KeyringClient_sender = new WeakMap(); //# sourceMappingURL=KeyringClient.mjs.map