ethjs-provider-signer
Version:
A simple web3 standard provider object that signs raw transactions.
1 lines • 5.08 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("SignerProvider",[],t):"object"==typeof exports?exports.SignerProvider=t():e.SignerProvider=t()}(this,function(){return function(e){function t(o){if(r[o])return r[o].exports;var n=r[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,t),n.l=!0,n.exports}var r={};return t.m=e,t.c=r,t.i=function(e){return e},t.d=function(e,t,r){Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=4)}([function(e,t,r){"use strict";function o(e,t){if(!(this instanceof o))throw Error('[ethjs-provider-signer] the SignerProvider instance requires the "new" flag in order to function normally (e.g. `const eth = new Eth(new SignerProvider(...));`).');if("object"!=typeof t)throw Error("[ethjs-provider-signer] the SignerProvider requires an options object be provided with the 'privateKey' property specified, you provided type "+typeof t+".");if("function"!=typeof t.signTransaction)throw Error("[ethjs-provider-signer] the SignerProvider requires an options object be provided with the 'signTransaction' property specified, you provided type "+typeof t.privateKey+" (e.g. 'const eth = new Eth(new SignerProvider(\"http://ropsten.infura.io\", { privateKey: (account, cb) => cb(null, 'some private key') }));').");var r=this;r.options=Object.assign({provider:n},t),r.timeout=t.timeout||0,r.provider=new r.options.provider(e,r.timeout),r.rpc=new i(r.provider)}var n=r(1),i=r(2);e.exports=o,o.prototype.sendAsync=function(e,t){var r=this;"eth_accounts"===e.method&&r.options.accounts?r.options.accounts(function(r,o){var n=Object.assign({},{id:e.id,jsonrpc:e.jsonrpc,result:o});t(r,n)}):"eth_sendTransaction"===e.method?r.rpc.sendAsync({method:"eth_getTransactionCount",params:[e.params[0].from,"latest"]},function(o,n){return o?t(Error("[ethjs-provider-signer] while getting nonce: "+o),null):void r.rpc.sendAsync({method:"eth_gasPrice"},function(o,i){if(o)return t(Error("[ethjs-provider-signer] while getting gasPrice: "+o),null);var s=Object.assign({nonce:n,gasPrice:i},e.params[0]);r.options.signTransaction(s,function(o,n){if(o)t(Error("[ethjs-provider-signer] while signing your transaction payload: "+JSON.stringify(o)),null);else{var i=Object.assign({},{id:e.id,jsonrpc:e.jsonrpc,method:"eth_sendRawTransaction",params:[n]});r.provider.sendAsync(i,t)}})})}):r.provider.sendAsync(e,t)}},function(e,t,r){"use strict";function o(e,t){var r=e&&e.error&&e.error.message?"[ethjs-provider-http] "+e.error.message:"[ethjs-provider-http] Invalid JSON RPC response from host provider "+t+": "+JSON.stringify(e,null,2);return Error(r)}function n(e,t){if(!(this instanceof n))throw Error('[ethjs-provider-http] the HttpProvider instance requires the "new" flag in order to function normally (e.g. `const eth = new Eth(new HttpProvider());`).');if("string"!=typeof e)throw Error('[ethjs-provider-http] the HttpProvider instance requires that the host be specified (e.g. `new HttpProvider("http://localhost:8545")` or via service like infura `new HttpProvider("http://ropsten.infura.io")`)');var r=this;r.host=e,r.timeout=t||0}var i=r(3);n.prototype.sendAsync=function(e,t){var r=this,n=new i;n.timeout=r.timeout,n.open("POST",r.host,!0),n.setRequestHeader("Content-Type","application/json"),n.onreadystatechange=function(){if(4===n.readyState&&1!==n.timeout){var e=n.responseText,i=null;try{e=JSON.parse(e)}catch(s){i=o(n.responseText,r.host)}t(i,e)}},n.ontimeout=function(){t("[ethjs-provider-http] CONNECTION TIMEOUT: http request timeout after "+r.timeout+" ms. (i.e. your connect has timed out for whatever reason, check your provider).",null)};try{n.send(JSON.stringify(e))}catch(s){t("[ethjs-provider-http] CONNECTION ERROR: Couldn't connect to node '"+r.host+"': "+JSON.stringify(s,null,2),null)}},e.exports=n},function(e,t){"use strict";function r(e,t){var o=this,n=t||{};if(!(this instanceof r))throw Error('[ethjs-rpc] the EthRPC object requires the "new" flag in order to function normally (i.e. `const eth = new EthRPC(provider);`).');o.options=Object.assign({jsonSpace:n.jsonSpace||0,max:n.max||9999999999999}),o.idCounter=Math.floor(Math.random()*o.options.max),(o.setProvider=function(e){if("object"!=typeof e)throw Error("[ethjs-rpc] the EthRPC object requires that the first input 'provider' must be an object, got '"+typeof e+"' (i.e. 'const eth = new EthRPC(provider);')");o.currentProvider=e})(e)}function o(e,t){return Object.assign({id:t,jsonrpc:"2.0",params:[]},e)}e.exports=r,r.prototype.sendAsync=function(e,t){var r=this;r.idCounter=r.idCounter%r.options.max,r.currentProvider.sendAsync(o(e,r.idCounter++),function(o,n){var i=n||{};if(o||i.error){var s="[ethjs-rpc] "+(i.error&&"rpc"||"")+" error with payload "+JSON.stringify(e,null,r.options.jsonSpace)+" "+(o||JSON.stringify(i.error,null,r.options.jsonSpace));return t(Error(s),null)}return t(null,i.result)})}},function(e,t){e.exports=XMLHttpRequest},function(e,t,r){e.exports=r(0)}])});