UNPKG

glip-wallet-sdk

Version:

Guide for installation and usage of Glip's Web3 Wallet.\ Glip Wallet through its SDK provides a signer using which a user's transaction can be signed.\ It also contains a iframe based UI element which can be embedded into any webpage.\ The UI contains

59 lines (58 loc) 2.22 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CroakSigner = void 0; const ethers_1 = require("ethers"); const SIGNER_EXTENSION_URL = 'wallet-confirmation/'; class CroakSigner extends ethers_1.Signer { constructor(address, walletURI, isMobile, provider, chain) { super(); this.isMobile = true; this.chain = ''; if (provider && !ethers_1.providers.Provider.isProvider(provider)) { throw (`invalid provider provided`); } this.provider = provider; this.address = address; this.walletURI = walletURI + SIGNER_EXTENSION_URL; this.isMobile = isMobile; this.chain = chain; } connect(provider) { this.provider = provider; if (provider && !ethers_1.providers.Provider.isProvider(provider)) { throw (`invalid provider provided`); } return this; } getAddress() { return Promise.resolve(this.address); } async signMessage(message) { let message_stringify = JSON.stringify(message); let that = this; let finalURL = this.walletURI; return new Promise(function (resolve, reject) { that.signedMessageCB = resolve; that.signedMessageRejectCB = reject; window.open(finalURL, '_blank', 'height=720,width=550'); }); } async signTransaction(transaction) { let tx = await ethers_1.utils.resolveProperties(transaction); if (tx.from != null) { if (ethers_1.utils.getAddress(tx.from) !== this.address) { delete tx.from; } return Promise.resolve(''); } let stringifyied_tx = JSON.stringify(tx); let that = this; let finalURL = this.walletURI + `?signTransaction=${stringifyied_tx}&chain=${this.chain}&lastLocation=${window.location.href}`; return new Promise(function (resolve, reject) { that.signedTransactionCB = resolve; that.signedTransactionRejectCB = reject; window.location = finalURL; }); } } exports.CroakSigner = CroakSigner;