web3-react-dcent-biometric-connector
Version:
A simple, maximally extensible, dependency minimized framework for building modern Ethereum dApps
3 lines (2 loc) • 6.99 kB
JavaScript
;function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}var e=require("@web3-react/abstract-connector"),n=r(require("web3-provider-engine")),t=r(require("web3-provider-engine/subproviders/hooked-wallet")),o=r(require("dcent-web-connector")),i=r(require("web3-provider-engine/subproviders/cache.js")),u=require("@0x/subproviders/lib/src/subproviders/rpc_subprovider");function c(r,e){r.prototype=Object.create(e.prototype),r.prototype.constructor=r,(Object.setPrototypeOf||function(r,e){return r.__proto__=e,r})(r,e)}const s=function(){function r(){}return r.prototype.then=function(e,n){const t=new r,o=this.s;if(o){const r=1&o?e:n;if(r){try{a(t,1,r(this.v))}catch(r){a(t,2,r)}return t}return this}return this.o=function(r){try{const o=r.v;1&r.s?a(t,1,e?e(o):o):n?a(t,1,n(o)):a(t,2,o)}catch(r){a(t,2,r)}},t},r}();function a(r,e,n){if(!r.s){if(n instanceof s){if(!n.s)return void(n.o=a.bind(null,r,e));1&e&&(e=n.s),n=n.v}if(n&&n.then)return void n.then(a.bind(null,r,e),a.bind(null,r,2));r.s=e,r.v=n;const t=r.o;t&&t(r)}}function f(r){return r instanceof s&&1&r.s}const h="undefined"!=typeof Symbol?Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator")):"@@iterator";function d(r,e){try{var n=r()}catch(r){return e(r)}return n&&n.then?n.then(void 0,e):n}function l(r,e){try{var n=r()}catch(r){return e(!0,r)}return n&&n.then?n.then(e.bind(null,!1),e.bind(null,!0)):e(!1,n)}"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var v,p={},m=function(r){try{for(var e in p)if(e.toLowerCase()===r.toLowerCase())return Promise.resolve(p[e]);return Promise.resolve()}catch(r){return Promise.reject(r)}},y=function(){try{return Promise.resolve(o.dcentPopupWindow()).then((function(r){if(null!=r&&"error"===r.header.status)throw new Error(r.body.error.message);return r}))}catch(r){return Promise.reject(r)}},w=function r(){try{if(!o.popupWindow||o.popupWindow.closed)throw new Error("popup_closed");return Promise.resolve(o.info()).then((function(e){var n=function(){if(!e.body.parameter.isUsbAttached)return Promise.resolve(new Promise((function(e,n){setTimeout((function(){r().then((function(){e()})).catch((function(r){n(r)}))}),500)}))).then((function(){}))}();if(n&&n.then)return n.then((function(){}))}))}catch(r){return Promise.reject(r)}},b=function(){try{return Object.keys(p).length>0?Promise.resolve(Object.keys(p)):Promise.resolve(y()).then((function(){return Promise.resolve(w()).then((function(){return Promise.resolve(o.getAccountInfo()).then((function(r){function e(){return o.popupWindowClose(),i}var n=r.body.parameter.account.filter((function(r){return r.coin_name===o.coinGroup.ETHEREUM})),t=[];n.forEach((function(r){t.push(r.address_path)})),0===t.length&&(t.push("m/44'/60'/0'/0/0"),console.warn("[D'CENT] cannot find exists ethereum accounts. use default path"));var i=[],u=function(r,e,n){if("function"==typeof r[h]){var t,o,i,u=r[h]();if(function r(n){try{for(;!(t=u.next()).done;)if((n=e(t.value))&&n.then){if(!f(n))return void n.then(r,i||(i=a.bind(null,o=new s,2)));n=n.v}o?a(o,1,n):o=n}catch(r){a(o||(o=new s),2,r)}}(),u.return){var c=function(r){try{t.done||u.return()}catch(r){}return r};if(o&&o.then)return o.then(c,(function(r){throw c(r)}));c()}return o}if(!("length"in r))throw new TypeError("Object is not iterable");for(var d=[],l=0;l<r.length;l++)d.push(r[l]);return function(r,e,n){var t,o,i=-1;return function n(u){try{for(;++i<r.length;)if((u=e(i))&&u.then){if(!f(u))return void u.then(n,o||(o=a.bind(null,t=new s,2)));u=u.v}t?a(t,1,u):t=u}catch(r){a(t||(t=new s),2,r)}}(),t}(d,(function(r){return e(d[r])}))}(t,(function(r){return Promise.resolve(o.getAddress(o.coinType.ETHEREUM,r)).then((function(e){p[e.body.parameter.address]=r,i.push(e.body.parameter.address)}))}));return u&&u.then?u.then(e):e()}))}))}))}catch(r){return Promise.reject(r)}},P=function(r,e){if(void 0===e)return g(r);g(r).then((function(r){e(null,r)})).catch((function(r){e(r,null)}))},g=function(r){try{return Promise.resolve(y()).then((function(){return Promise.resolve(w()).then((function(){return Promise.resolve(m(r.from)).then((function(e){var n;function t(r){return"0x"+n.body.parameter.signed}if(!e)throw new Error("address unknown '"+r.from+"'");var i=l((function(){return d((function(){return Promise.resolve(o.getEthereumSignedTransaction(o.coinType.ETHEREUM,r.nonce,r.gasPrice,r.gas,r.to,r.value||"0",r.data||"0x",e,v)).then((function(r){n=r}))}),(function(r){if("wam"===r.header.response_from)throw new Error("no_device");if(r.body.error.code)throw new Error(r.body.error.code);throw r}))}),(function(r,e){if(o.popupWindowClose(),r)throw e;return e}));return i&&i.then?i.then(t):t()}))}))}))}catch(r){return Promise.reject(r)}},E=function(r,e){if(void 0===e)return j(r);j(r).then((function(r){e(null,r)})).catch((function(r){e(r,null)}))},j=function(r){try{return Promise.resolve(y()).then((function(){return Promise.resolve(w()).then((function(){return Promise.resolve(m(r.from)).then((function(e){var n;function t(r){return n.body.parameter.sign}if(!e)throw new Error("address unknown '"+r.from+"'");var i=l((function(){return d((function(){return Promise.resolve(o.getEthereumSignedMessage(r.data,e)).then((function(r){n=r}))}),(function(r){if("wam"===r.header.response_from)throw new Error("no_device");if(r.body.error.code)throw new Error(r.body.error.code);throw r}))}),(function(r,e){if(o.popupWindowClose(),r)throw e;return e}));return i&&i.then?i.then(t):t()}))}))}))}catch(r){return Promise.reject(r)}},I=function(r){function e(e){void 0===e&&(e={});var n=Object.assign(e,{signTransaction:P,signPersonalMessage:E,signMessage:E});return v=e.networkId,r.call(this,n)||this}return c(e,r),e.prototype.getAccounts=function(r){if(!r)return b();b().then((function(e){r(null,e)})).catch((function(e){r(e,null)}))},e}(t);exports.DcentConnector=function(r){function e(e){var n,t=e.chainId,o=e.url,i=e.pollingInterval,u=e.requestTimeoutMs;return(n=r.call(this,{supportedChainIds:[t]})||this).chainId=t,n.url=o,n.pollingInterval=i,n.requestTimeoutMs=u,n}c(e,r);var t=e.prototype;return t.activate=function(){try{if(!this.provider){var r=new n({pollingInterval:this.pollingInterval});r.addProvider(new I({networkId:this.chainId})),r.addProvider(new i),r.addProvider(new u.RPCSubprovider(this.url,this.requestTimeoutMs)),this.provider=r}return this.provider.start(),Promise.resolve({provider:this.provider,chainId:this.chainId})}catch(r){return Promise.reject(r)}},t.getProvider=function(){try{return Promise.resolve(this.provider)}catch(r){return Promise.reject(r)}},t.getChainId=function(){try{return Promise.resolve(this.chainId)}catch(r){return Promise.reject(r)}},t.getAccount=function(){try{return Promise.resolve(this.provider._providers[0].getAccounts().then((function(r){return r[0]})))}catch(r){return Promise.reject(r)}},t.deactivate=function(){this.provider.stop()},e}(e.AbstractConnector);
//# sourceMappingURL=web3-react-dcent-biometric-connector.cjs.production.min.js.map