UNPKG

@colony/purser-metamask

Version:

A javascript library to interact with a Metamask based Ethereum wallet

69 lines (53 loc) 1.86 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.verifyMessage = exports.signTransaction = exports.signMessage = exports.getTransaction = void 0; /* * This is just to provide a nicer function name to the injected metamask * methods that we call. * * This assumes you do detection before trying to call them. */ var getTransaction = function getTransaction() { var _global$web3$eth; return (_global$web3$eth = global.web3.eth).getTransaction.apply(_global$web3$eth, arguments); }; /** * Sign a message. Is a wrapper for web3.personal.sign * * @method signMessage */ exports.getTransaction = getTransaction; var signMessage = function signMessage() { var _global$web3$eth$pers; return (_global$web3$eth$pers = global.web3.eth.personal).sign.apply(_global$web3$eth$pers, arguments); }; /** * Sign transaction. Is a wrapper for web3.eth.signTransaction * * This not only signs, but also sends the transaction, we can't have it any * other way with metamask (for the time being at least...) * * @method signTransaction */ exports.signMessage = signMessage; var signTransaction = function signTransaction() { var _global$web3$eth2; return (_global$web3$eth2 = global.web3.eth).sendTransaction.apply(_global$web3$eth2, arguments); }; /** * Verify a signed message. Is a wrapper for web3.personal.ecRecover * * This takes in a message and a signature, and tries to recover the address * that initially signed this message. You than have to compare it to the * current address. * * @method verifyMessage */ exports.signTransaction = signTransaction; var verifyMessage = function verifyMessage() { var _global$web3$eth$pers2; return (_global$web3$eth$pers2 = global.web3.eth.personal).ecRecover.apply(_global$web3$eth$pers2, arguments); }; exports.verifyMessage = verifyMessage;