UNPKG

@signumjs/wallets

Version:

Wallets communication package for DApps in the Signum Network

68 lines 2.73 kB
"use strict"; /** * Original work Copyright (c) 2022, 2026 Signum Network */ Object.defineProperty(exports, "__esModule", { value: true }); exports.DesktopWallet = void 0; /* globals window */ const standards_1 = require("@signumjs/standards"); const isNodeJS_1 = require("../isNodeJS"); const util_1 = require("@signumjs/util"); /** * This wallet (proxy) allows interacting with SIP22 compatible deep linkable desktop wallets (Phoenix Wallet). */ class DesktopWallet { redirectProxy; openInBrowser; constructor(options) { this.openInBrowser = options?.openInBrowser === undefined ? true : options.openInBrowser; this.redirectProxy = options?.redirectProxy || 'https://burst-balance-alert.vercel.app/api/redirect?url='; if ((0, isNodeJS_1.isNodeJS)()) { this.openInBrowser = false; } } eventuallyOpenInBrowser(url) { if (this.openInBrowser) { window?.open(this.redirectProxy + url, 'SignumJS Deeplinking', 'noopener noreferrer'); } return Promise.resolve(url); } mountDeeplink(action, payload) { const link = standards_1.src22.createDeeplink({ action, payload }); return encodeURIComponent(link); } /** * Confirms a transaction by opening a deeplink for signing. * * @param {string} unsignedTransactionBytes - The unsigned transaction data in bytes to be confirmed. * @return {Promise<string>} A promise that resolves to a string indicating the result of the process. */ confirm(unsignedTransactionBytes) { return this.eventuallyOpenInBrowser(this.mountDeeplink('sign', { unsignedTransactionBytes })); } /** * Initiates a payment operation with the specified parameters. * * @param args - An object containing the parameters for the payment. See {@link DesktopWalletPayArgs}. * @return A promise that resolves to a string representing the final payment deeplink. */ pay(args) { const { amount = util_1.Amount.Zero(), encrypt = false, fee = util_1.Amount.fromPlanck(util_1.FeeQuantPlanck), message, hexMessage, recipient, deadline = 1440, readonly = false } = args; const payload = { recipient: recipient.getNumericId(), amountPlanck: amount.getPlanck(), feePlanck: fee.getPlanck(), message: message || hexMessage, messageIsText: hexMessage === undefined, immutable: readonly, deadline, encrypt }; return this.eventuallyOpenInBrowser(this.mountDeeplink('pay', payload)); } } exports.DesktopWallet = DesktopWallet; //# sourceMappingURL=desktopWallet.js.map