UNPKG

@signumjs/wallets

Version:

Wallets communication package for DApps in the Signum Network

62 lines 2.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenericExtensionWallet = void 0; const extensionAdapterFactory_1 = require("./extensionAdapterFactory"); const walletConnection_1 = require("./walletConnection"); class GenericExtensionWallet { adapter; _connection = null; constructor(adapter = extensionAdapterFactory_1.ExtensionAdapterFactory.getAdapter()) { this.adapter = adapter; } assertConnection() { if (!this.connection) { throw new Error('Wallet not connected'); } } async fetchPermission(network, appName) { try { const { availableNodeHosts, accountId, publicKey, currentNodeHost, watchOnly } = await this.adapter.requestPermission({ network: network, appMeta: { name: appName }, }); return new walletConnection_1.WalletConnection(accountId, publicKey, watchOnly, availableNodeHosts, currentNodeHost, this.adapter); } catch (e) { console.error(e); throw e; } } get connection() { return this._connection; } async connect(args) { this._connection = null; await this.adapter.assertWalletAvailable(); const { appName, networkName } = args; this._connection = await this.fetchPermission(networkName, appName); return this._connection; } async confirm(unsignedTransaction) { this.assertConnection(); const result = await this.adapter.requestSign({ unsignedTransaction, }); return { ...result }; } async sendEncryptedMessage(args) { this.assertConnection(); const feeSigna = args.feeSigna === 'number' ? args.feeSigna.toString() : args.feeSigna; const result = await this.adapter.requestSendEncryptedMessage({ plainMessage: args.message || args.hexMessage, messageIsText: !!args.message, recipientPublicKey: args.recipientPublicKey, feeSigna, }); return { ...result }; } } exports.GenericExtensionWallet = GenericExtensionWallet; //# sourceMappingURL=genericExtensionWallet.js.map