Socket
Socket
Sign inDemoInstall

@blocto/sdk

Package Overview
Dependencies
Maintainers
2
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocto/sdk - npm Package Compare versions

Comparing version 0.0.8 to 0.0.9

79

dist/blocto-sdk.js

@@ -1705,59 +1705,68 @@ function _defineProperty(obj, key, value) {

case 2:
_context.prev = 2;
if (this.connected) {
_context.next = 5;
break;
}
_context.next = 5;
return this.enable();
case 5:
_context.prev = 5;
response = null;
result = null;
_context.t0 = payload.method;
_context.next = _context.t0 === "eth_accounts" ? 8 : _context.t0 === "eth_coinbase" ? 12 : _context.t0 === "eth_chainId" ? 17 : _context.t0 === "net_version" ? 20 : _context.t0 === "eth_sign" ? 23 : _context.t0 === "eth_sendTransaction" ? 28 : _context.t0 === "eth_signTransaction" ? 32 : _context.t0 === "eth_sendRawTransaction" ? 32 : 34;
_context.next = _context.t0 === "eth_accounts" ? 11 : _context.t0 === "eth_coinbase" ? 15 : _context.t0 === "eth_chainId" ? 20 : _context.t0 === "net_version" ? 23 : _context.t0 === "eth_sign" ? 26 : _context.t0 === "eth_sendTransaction" ? 31 : _context.t0 === "eth_signTransaction" ? 35 : _context.t0 === "eth_sendRawTransaction" ? 35 : 37;
break;
case 8:
_context.next = 10;
case 11:
_context.next = 13;
return this.fetchAccounts();
case 10:
case 13:
result = _context.sent;
return _context.abrupt("break", 37);
return _context.abrupt("break", 40);
case 12:
_context.next = 14;
case 15:
_context.next = 17;
return this.fetchAccounts();
case 14:
case 17:
accounts = _context.sent;
result = accounts[0];
return _context.abrupt("break", 37);
return _context.abrupt("break", 40);
case 17:
case 20:
result = this.chainId;
result = "0x" + result.toString(16);
return _context.abrupt("break", 37);
return _context.abrupt("break", 40);
case 20:
case 23:
result = this.networkId || this.chainId;
result = "0x" + result.toString(16);
return _context.abrupt("break", 37);
return _context.abrupt("break", 40);
case 23:
_context.next = 25;
case 26:
_context.next = 28;
return this.handleSign(payload);
case 25:
case 28:
result = _context.sent;
result = result.signature;
return _context.abrupt("break", 37);
return _context.abrupt("break", 40);
case 28:
_context.next = 30;
case 31:
_context.next = 33;
return this.handleSendTransaction(payload);
case 30:
case 33:
result = _context.sent;
return _context.abrupt("break", 37);
return _context.abrupt("break", 40);
case 32:
case 35:
result = null;
return _context.abrupt("break", 37);
return _context.abrupt("break", 40);
case 34:
_context.next = 36;
case 37:
_context.next = 39;
return this.handleReadRequests(_objectSpread2({

@@ -1768,8 +1777,8 @@ id: 1,

case 36:
case 39:
response = _context.sent;
case 37:
case 40:
if (!response) {
_context.next = 39;
_context.next = 42;
break;

@@ -1780,8 +1789,8 @@ }

case 39:
case 42:
return _context.abrupt("return", result);
case 42:
_context.prev = 42;
_context.t1 = _context["catch"](2);
case 45:
_context.prev = 45;
_context.t1 = _context["catch"](5);
console.error(_context.t1); // this.emit("error", error);

@@ -1791,3 +1800,3 @@

case 46:
case 49:
case "end":

@@ -1797,3 +1806,3 @@ return _context.stop();

}
}, _callee, this, [[2, 42]]);
}, _callee, this, [[5, 45]]);
}));

@@ -1800,0 +1809,0 @@

@@ -1,1 +0,1 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).BloctoProvider=t()}(this,(function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?e(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function n(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function r(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var a=e.apply(t,r);function s(e){n(a,o,i,s,c,"next",e)}function c(e){n(a,o,i,s,c,"throw",e)}s(void 0)}))}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var s="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function c(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}var h=c,l=u;function f(e){if(h===setTimeout)return setTimeout(e,0);if((h===c||!h)&&setTimeout)return h=setTimeout,setTimeout(e,0);try{return h(e,0)}catch(t){try{return h.call(null,e,0)}catch(t){return h.call(this,e,0)}}}"function"==typeof s.setTimeout&&(h=setTimeout),"function"==typeof s.clearTimeout&&(l=clearTimeout);var p,d=[],m=!1,v=-1;function b(){m&&p&&(m=!1,p.length?d=p.concat(d):v=-1,d.length&&w())}function w(){if(!m){var e=f(b);m=!0;for(var t=d.length;t;){for(p=d,d=[];++v<t;)p&&p[v].run();v=-1,t=d.length}p=null,m=!1,function(e){if(l===clearTimeout)return clearTimeout(e);if((l===u||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(e);try{l(e)}catch(t){try{return l.call(null,e)}catch(t){return l.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}g.prototype.run=function(){this.fun.apply(null,this.array)};function y(){}var E=y,k=y,T=y,j=y,O=y,x=y,I=y;var A=s.performance||{},P=A.now||A.mozNow||A.msNow||A.oNow||A.webkitNow||function(){return(new Date).getTime()};var C=new Date;var _={nextTick:function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];d.push(new g(e,t)),1!==d.length||m||f(w)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:E,addListener:k,once:T,off:j,removeListener:O,removeAllListeners:x,emit:I,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var t=.001*P.call(A),n=Math.floor(t),r=Math.floor(t%1*1e9);return e&&(n-=e[0],(r-=e[1])<0&&(n--,r+=1e9)),[n,r]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-C)/1e3}},N=function(e,t,n,r,o,i,a,s){if("production"!==_.env.NODE_ENV&&void 0===t)throw new Error("invariant requires an error message argument");if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,r,o,i,a,s],h=0;(c=new Error(t.replace(/%s/g,(function(){return u[h++]})))).name="Invariant Violation"}throw c.framesToPop=1,c}},S=Object.freeze({__proto__:null,default:{}});function R(e,t){for(var n=0,r=e.length-1;r>=0;r--){var o=e[r];"."===o?e.splice(r,1):".."===o?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}var L=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,D=function(e){return L.exec(e).slice(1)};function z(){for(var e="",t=!1,n=arguments.length-1;n>=-1&&!t;n--){var r=n>=0?arguments[n]:"/";if("string"!=typeof r)throw new TypeError("Arguments to path.resolve must be strings");r&&(e=r+"/"+e,t="/"===r.charAt(0))}return(t?"/":"")+(e=R(F(e.split("/"),(function(e){return!!e})),!t).join("/"))||"."}function B(e){var t=q(e),n="/"===X(e,-1);return(e=R(F(e.split("/"),(function(e){return!!e})),!t).join("/"))||t||(e="."),e&&n&&(e+="/"),(t?"/":"")+e}function q(e){return"/"===e.charAt(0)}function V(){var e=Array.prototype.slice.call(arguments,0);return B(F(e,(function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e})).join("/"))}function M(e,t){function n(e){for(var t=0;t<e.length&&""===e[t];t++);for(var n=e.length-1;n>=0&&""===e[n];n--);return t>n?[]:e.slice(t,n-t+1)}e=z(e).substr(1),t=z(t).substr(1);for(var r=n(e.split("/")),o=n(t.split("/")),i=Math.min(r.length,o.length),a=i,s=0;s<i;s++)if(r[s]!==o[s]){a=s;break}var c=[];for(s=a;s<r.length;s++)c.push("..");return(c=c.concat(o.slice(a))).join("/")}function U(e){var t=D(e),n=t[0],r=t[1];return n||r?(r&&(r=r.substr(0,r.length-1)),n+r):"."}function $(e,t){var n=D(e)[2];return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n}function G(e){return D(e)[3]}var J={extname:G,basename:$,dirname:U,sep:"/",delimiter:":",relative:M,join:V,isAbsolute:q,normalize:B,resolve:z};function F(e,t){if(e.filter)return e.filter(t);for(var n=[],r=0;r<e.length;r++)t(e[r],r,e)&&n.push(e[r]);return n}var H,X="b"==="ab".substr(-1)?function(e,t,n){return e.substr(t,n)}:function(e,t,n){return t<0&&(t=e.length+t),e.substr(t,n)},K=Object.freeze({__proto__:null,resolve:z,normalize:B,isAbsolute:q,join:V,relative:M,sep:"/",delimiter:":",dirname:U,basename:$,extname:G,default:J});function Q(){if(void 0===H){var e=new ArrayBuffer(2),t=new Uint8Array(e),n=new Uint16Array(e);if(t[0]=1,t[1]=2,258===n[0])H="BE";else{if(513!==n[0])throw new Error("unable to figure out endianess");H="LE"}}return H}function W(){return void 0!==s.location?s.location.hostname:""}function Y(){return[]}function Z(){return 0}function ee(){return Number.MAX_VALUE}function te(){return Number.MAX_VALUE}function ne(){return[]}function re(){return"Browser"}function oe(){return void 0!==s.navigator?s.navigator.appVersion:""}function ie(){}function ae(){}function se(){return"/tmp"}var ce=se,ue={EOL:"\n",tmpdir:ce,tmpDir:se,networkInterfaces:ie,getNetworkInterfaces:ae,release:oe,type:re,cpus:ne,totalmem:te,freemem:ee,uptime:Z,loadavg:Y,hostname:W,endianness:Q},he=Object.freeze({__proto__:null,endianness:Q,hostname:W,loadavg:Y,uptime:Z,freemem:ee,totalmem:te,cpus:ne,type:re,release:oe,networkInterfaces:ie,getNetworkInterfaces:ae,arch:function(){return"javascript"},platform:function(){return"browser"},tmpDir:se,tmpdir:ce,EOL:"\n",default:ue});function le(e){return e&&e.default||e}var fe=le(S),pe=le(K),de=le(he);function me(e){console.log(`[dotenv][DEBUG] ${e}`)}const ve=/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/,be=/\\n/g,we=/\r\n|\n|\r/;function ge(e,t){const n=Boolean(t&&t.debug),r={};return e.toString().split(we).forEach((function(e,t){const o=e.match(ve);if(null!=o){const e=o[1];let t=o[2]||"";const n=t.length-1,i='"'===t[0]&&'"'===t[n];"'"===t[0]&&"'"===t[n]||i?(t=t.substring(1,n),i&&(t=t.replace(be,"\n"))):t=t.trim(),r[e]=t}else n&&me(`did not match key and value when parsing line ${t+1}: ${e}`)})),r}function ye(e){return new Promise((function(t){return setTimeout(t,e)}))}({config:function(e){let t=pe.resolve(_.cwd(),".env"),n="utf8",r=!1;var o;e&&(null!=e.path&&(t="~"===(o=e.path)[0]?pe.join(de.homedir(),o.slice(1)):o),null!=e.encoding&&(n=e.encoding),null!=e.debug&&(r=!0));try{const e=ge(fe.readFileSync(t,{encoding:n}),{debug:r});return Object.keys(e).forEach((function(t){Object.prototype.hasOwnProperty.call(_.env,t)?r&&me(`"${t}" is already defined in \`process.env\` and will not be overwritten`):_.env[t]=e[t]})),{parsed:e}}catch(e){return{error:e}}},parse:ge}).config();var Ee="width:100vw;height:100vh;position:fixed;top:0;left:0;z-index:1000;border:none;",ke={56:"https://bsc-dataseed1.binance.org",97:"https://data-seed-prebsc-1-s1.binance.org:8545"},Te={1:"ethereum",4:"ethereum",56:"bsc",97:"bsc"},je={1:"mainnet",4:"rinkeby",56:"mainnet",97:"testnet"},Oe={1:"https://wallet.blocto.app",4:"https://wallet-testnet.blocto.app",56:"https://wallet.blocto.app",97:"https://wallet-testnet.blocto.app"};return function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.chainId,r=t.rpc,i=t.server,s=t.appId;o(this,e),a(this,"isBlocto",!0),a(this,"isConnecting",!1),a(this,"connected",!1),a(this,"chainId",null),a(this,"networkId",null),a(this,"chain",null),a(this,"net",null),a(this,"rpc",null),a(this,"server",null),a(this,"appId",null),N(n,"'chainId' is required"),"number"==typeof n?this.chainId=n:n.includes("0x")?this.chainId=parseInt(n,16):this.chainId=parseInt(n,10),this.networkId=this.chainId,this.chain=Te[this.chainId],this.net=je[this.chainId],N(this.chain,"unsupported 'chainId': ".concat(this.chainId)),this.rpc=process.env.RPC||r||ke[this.chainId],N(this.rpc,"'rpc' is required for Ethereum"),this.server=process.env.SERVER||i||Oe[this.chainId],this.appId=process.env.APP_ID||s}var n,s,c,u,h,l,f,p;return n=e,(s=[{key:"request",value:(p=r(regeneratorRuntime.mark((function e(n){var r,o,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!window.ethereum||!window.ethereum.isBlocto){e.next=2;break}return e.abrupt("return",window.ethereum.request(n));case 2:e.prev=2,r=null,o=null,e.t0=n.method,e.next="eth_accounts"===e.t0?8:"eth_coinbase"===e.t0?12:"eth_chainId"===e.t0?17:"net_version"===e.t0?20:"eth_sign"===e.t0?23:"eth_sendTransaction"===e.t0?28:"eth_signTransaction"===e.t0||"eth_sendRawTransaction"===e.t0?32:34;break;case 8:return e.next=10,this.fetchAccounts();case 10:return o=e.sent,e.abrupt("break",37);case 12:return e.next=14,this.fetchAccounts();case 14:return i=e.sent,o=i[0],e.abrupt("break",37);case 17:return o="0x"+(o=this.chainId).toString(16),e.abrupt("break",37);case 20:return o="0x"+(o=this.networkId||this.chainId).toString(16),e.abrupt("break",37);case 23:return e.next=25,this.handleSign(n);case 25:return o=(o=e.sent).signature,e.abrupt("break",37);case 28:return e.next=30,this.handleSendTransaction(n);case 30:return o=e.sent,e.abrupt("break",37);case 32:return o=null,e.abrupt("break",37);case 34:return e.next=36,this.handleReadRequests(t({id:1,jsonrpc:"2.0"},n));case 36:r=e.sent;case 37:if(!r){e.next=39;break}return e.abrupt("return",r.result);case 39:return e.abrupt("return",o);case 42:throw e.prev=42,e.t1=e.catch(2),console.error(e.t1),e.t1;case 46:case"end":return e.stop()}}),e,this,[[2,42]])}))),function(e){return p.apply(this,arguments)})},{key:"enable",value:function(){var e=this;return window.ethereum&&window.ethereum.isBlocto?window.ethereum.enable():new Promise((function(t,n){"undefined"==typeof window&&n("Currently only supported in browser");var r=document.createElement("iframe");r.setAttribute("src","".concat(e.server,"/authn?l6n=").concat(encodeURIComponent(window.location.origin),"&chain=").concat(e.chain)),r.setAttribute("style",Ee),document.body.appendChild(r);var o=null;o=window.addEventListener("message",(function(i){i.origin===e.server&&("FCL::CHALLENGE::RESPONSE"===i.data.type&&(window.removeEventListener("message",o),r.parentNode.removeChild(r),e.code=i.data.code,e.connected=!0,t([i.data.addr])),"FCL::CHALLENGE::CANCEL"===i.data.type&&(window.removeEventListener("message",o),r.parentNode.removeChild(r),n()))}))}))}},{key:"fetchAccounts",value:(f=r(regeneratorRuntime.mark((function e(){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch("".concat(this.server,"/api/").concat(this.chain,"/accounts?code=").concat(this.code)).then((function(e){return e.json()}));case 2:return t=e.sent,n=t.accounts,e.abrupt("return",n);case 5:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"handleReadRequests",value:(l=r(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((function(e){return e.json()}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"handleSign",value:(h=r(regeneratorRuntime.mark((function e(t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.params,e.next=3,fetch("".concat(this.server,"/api/").concat(this.chain,"/sign?code=").concat(this.code),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:n[1]})}).then((function(e){return e.json()}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"handleSendTransaction",value:(u=r(regeneratorRuntime.mark((function e(n){var r,o,i,a,s,c,u,h,l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.params,e.next=3,fetch("".concat(this.server,"/api/").concat(this.chain,"/estimatePoint?code=").concat(this.code),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0])}).then((function(e){return e.json()}));case 3:return o=e.sent,i=o.cost,e.next=7,fetch("".concat(this.server,"/api/").concat(this.chain,"/authz?code=").concat(this.code),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t(t({},r[0]),{},{point:i}))}).then((function(e){return e.json()}));case 7:if(a=e.sent,s=a.authorizationId,"undefined"!=typeof window){e.next=11;break}throw new Error("Currently only supported in browser");case 11:(c=document.createElement("iframe")).setAttribute("src","".concat(this.server,"/authz/").concat(this.chain,"/").concat(s)),c.setAttribute("style",Ee),document.body.appendChild(c);case 15:return e.next=18,fetch("".concat(this.server,"/api/").concat(this.chain,"/authz?authorizationId=").concat(s),{method:"GET",headers:{"Content-Type":"application/json"}}).then((function(e){return e.json()}));case 18:if(u=e.sent,h=u.status,l=u.transactionHash,"APPROVED"!==h){e.next=24;break}return c.parentNode.removeChild(c),e.abrupt("return",l);case 24:if("DECLINED"!==h){e.next=27;break}throw c.parentNode.removeChild(c),new Error("Transaction Canceled");case 27:return e.next=29,ye(1e3);case 29:e.next=15;break;case 31:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})}])&&i(n.prototype,s),c&&i(n,c),e}()}));
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).BloctoProvider=t()}(this,(function(){"use strict";function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function t(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?e(Object(r),!0).forEach((function(e){a(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function n(e,t,n,r,o,i,a){try{var s=e[i](a),c=s.value}catch(e){return void n(e)}s.done?t(c):Promise.resolve(c).then(r,o)}function r(e){return function(){var t=this,r=arguments;return new Promise((function(o,i){var a=e.apply(t,r);function s(e){n(a,o,i,s,c,"next",e)}function c(e){n(a,o,i,s,c,"throw",e)}s(void 0)}))}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var s="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{};function c(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}var h=c,l=u;function f(e){if(h===setTimeout)return setTimeout(e,0);if((h===c||!h)&&setTimeout)return h=setTimeout,setTimeout(e,0);try{return h(e,0)}catch(t){try{return h.call(null,e,0)}catch(t){return h.call(this,e,0)}}}"function"==typeof s.setTimeout&&(h=setTimeout),"function"==typeof s.clearTimeout&&(l=clearTimeout);var p,d=[],m=!1,v=-1;function b(){m&&p&&(m=!1,p.length?d=p.concat(d):v=-1,d.length&&w())}function w(){if(!m){var e=f(b);m=!0;for(var t=d.length;t;){for(p=d,d=[];++v<t;)p&&p[v].run();v=-1,t=d.length}p=null,m=!1,function(e){if(l===clearTimeout)return clearTimeout(e);if((l===u||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(e);try{l(e)}catch(t){try{return l.call(null,e)}catch(t){return l.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}g.prototype.run=function(){this.fun.apply(null,this.array)};function y(){}var E=y,k=y,T=y,j=y,x=y,O=y,I=y;var A=s.performance||{},P=A.now||A.mozNow||A.msNow||A.oNow||A.webkitNow||function(){return(new Date).getTime()};var C=new Date;var _={nextTick:function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];d.push(new g(e,t)),1!==d.length||m||f(w)},title:"browser",browser:!0,env:{},argv:[],version:"",versions:{},on:E,addListener:k,once:T,off:j,removeListener:x,removeAllListeners:O,emit:I,binding:function(e){throw new Error("process.binding is not supported")},cwd:function(){return"/"},chdir:function(e){throw new Error("process.chdir is not supported")},umask:function(){return 0},hrtime:function(e){var t=.001*P.call(A),n=Math.floor(t),r=Math.floor(t%1*1e9);return e&&(n-=e[0],(r-=e[1])<0&&(n--,r+=1e9)),[n,r]},platform:"browser",release:{},config:{},uptime:function(){return(new Date-C)/1e3}},N=function(e,t,n,r,o,i,a,s){if("production"!==_.env.NODE_ENV&&void 0===t)throw new Error("invariant requires an error message argument");if(!e){var c;if(void 0===t)c=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,r,o,i,a,s],h=0;(c=new Error(t.replace(/%s/g,(function(){return u[h++]})))).name="Invariant Violation"}throw c.framesToPop=1,c}},S=Object.freeze({__proto__:null,default:{}});function R(e,t){for(var n=0,r=e.length-1;r>=0;r--){var o=e[r];"."===o?e.splice(r,1):".."===o?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n--;n)e.unshift("..");return e}var L=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,D=function(e){return L.exec(e).slice(1)};function z(){for(var e="",t=!1,n=arguments.length-1;n>=-1&&!t;n--){var r=n>=0?arguments[n]:"/";if("string"!=typeof r)throw new TypeError("Arguments to path.resolve must be strings");r&&(e=r+"/"+e,t="/"===r.charAt(0))}return(t?"/":"")+(e=R(F(e.split("/"),(function(e){return!!e})),!t).join("/"))||"."}function B(e){var t=q(e),n="/"===X(e,-1);return(e=R(F(e.split("/"),(function(e){return!!e})),!t).join("/"))||t||(e="."),e&&n&&(e+="/"),(t?"/":"")+e}function q(e){return"/"===e.charAt(0)}function V(){var e=Array.prototype.slice.call(arguments,0);return B(F(e,(function(e,t){if("string"!=typeof e)throw new TypeError("Arguments to path.join must be strings");return e})).join("/"))}function M(e,t){function n(e){for(var t=0;t<e.length&&""===e[t];t++);for(var n=e.length-1;n>=0&&""===e[n];n--);return t>n?[]:e.slice(t,n-t+1)}e=z(e).substr(1),t=z(t).substr(1);for(var r=n(e.split("/")),o=n(t.split("/")),i=Math.min(r.length,o.length),a=i,s=0;s<i;s++)if(r[s]!==o[s]){a=s;break}var c=[];for(s=a;s<r.length;s++)c.push("..");return(c=c.concat(o.slice(a))).join("/")}function U(e){var t=D(e),n=t[0],r=t[1];return n||r?(r&&(r=r.substr(0,r.length-1)),n+r):"."}function $(e,t){var n=D(e)[2];return t&&n.substr(-1*t.length)===t&&(n=n.substr(0,n.length-t.length)),n}function G(e){return D(e)[3]}var J={extname:G,basename:$,dirname:U,sep:"/",delimiter:":",relative:M,join:V,isAbsolute:q,normalize:B,resolve:z};function F(e,t){if(e.filter)return e.filter(t);for(var n=[],r=0;r<e.length;r++)t(e[r],r,e)&&n.push(e[r]);return n}var H,X="b"==="ab".substr(-1)?function(e,t,n){return e.substr(t,n)}:function(e,t,n){return t<0&&(t=e.length+t),e.substr(t,n)},K=Object.freeze({__proto__:null,resolve:z,normalize:B,isAbsolute:q,join:V,relative:M,sep:"/",delimiter:":",dirname:U,basename:$,extname:G,default:J});function Q(){if(void 0===H){var e=new ArrayBuffer(2),t=new Uint8Array(e),n=new Uint16Array(e);if(t[0]=1,t[1]=2,258===n[0])H="BE";else{if(513!==n[0])throw new Error("unable to figure out endianess");H="LE"}}return H}function W(){return void 0!==s.location?s.location.hostname:""}function Y(){return[]}function Z(){return 0}function ee(){return Number.MAX_VALUE}function te(){return Number.MAX_VALUE}function ne(){return[]}function re(){return"Browser"}function oe(){return void 0!==s.navigator?s.navigator.appVersion:""}function ie(){}function ae(){}function se(){return"/tmp"}var ce=se,ue={EOL:"\n",tmpdir:ce,tmpDir:se,networkInterfaces:ie,getNetworkInterfaces:ae,release:oe,type:re,cpus:ne,totalmem:te,freemem:ee,uptime:Z,loadavg:Y,hostname:W,endianness:Q},he=Object.freeze({__proto__:null,endianness:Q,hostname:W,loadavg:Y,uptime:Z,freemem:ee,totalmem:te,cpus:ne,type:re,release:oe,networkInterfaces:ie,getNetworkInterfaces:ae,arch:function(){return"javascript"},platform:function(){return"browser"},tmpDir:se,tmpdir:ce,EOL:"\n",default:ue});function le(e){return e&&e.default||e}var fe=le(S),pe=le(K),de=le(he);function me(e){console.log(`[dotenv][DEBUG] ${e}`)}const ve=/^\s*([\w.-]+)\s*=\s*(.*)?\s*$/,be=/\\n/g,we=/\r\n|\n|\r/;function ge(e,t){const n=Boolean(t&&t.debug),r={};return e.toString().split(we).forEach((function(e,t){const o=e.match(ve);if(null!=o){const e=o[1];let t=o[2]||"";const n=t.length-1,i='"'===t[0]&&'"'===t[n];"'"===t[0]&&"'"===t[n]||i?(t=t.substring(1,n),i&&(t=t.replace(be,"\n"))):t=t.trim(),r[e]=t}else n&&me(`did not match key and value when parsing line ${t+1}: ${e}`)})),r}function ye(e){return new Promise((function(t){return setTimeout(t,e)}))}({config:function(e){let t=pe.resolve(_.cwd(),".env"),n="utf8",r=!1;var o;e&&(null!=e.path&&(t="~"===(o=e.path)[0]?pe.join(de.homedir(),o.slice(1)):o),null!=e.encoding&&(n=e.encoding),null!=e.debug&&(r=!0));try{const e=ge(fe.readFileSync(t,{encoding:n}),{debug:r});return Object.keys(e).forEach((function(t){Object.prototype.hasOwnProperty.call(_.env,t)?r&&me(`"${t}" is already defined in \`process.env\` and will not be overwritten`):_.env[t]=e[t]})),{parsed:e}}catch(e){return{error:e}}},parse:ge}).config();var Ee="width:100vw;height:100vh;position:fixed;top:0;left:0;z-index:1000;border:none;",ke={56:"https://bsc-dataseed1.binance.org",97:"https://data-seed-prebsc-1-s1.binance.org:8545"},Te={1:"ethereum",4:"ethereum",56:"bsc",97:"bsc"},je={1:"mainnet",4:"rinkeby",56:"mainnet",97:"testnet"},xe={1:"https://wallet.blocto.app",4:"https://wallet-testnet.blocto.app",56:"https://wallet.blocto.app",97:"https://wallet-testnet.blocto.app"};return function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=t.chainId,r=t.rpc,i=t.server,s=t.appId;o(this,e),a(this,"isBlocto",!0),a(this,"isConnecting",!1),a(this,"connected",!1),a(this,"chainId",null),a(this,"networkId",null),a(this,"chain",null),a(this,"net",null),a(this,"rpc",null),a(this,"server",null),a(this,"appId",null),N(n,"'chainId' is required"),"number"==typeof n?this.chainId=n:n.includes("0x")?this.chainId=parseInt(n,16):this.chainId=parseInt(n,10),this.networkId=this.chainId,this.chain=Te[this.chainId],this.net=je[this.chainId],N(this.chain,"unsupported 'chainId': ".concat(this.chainId)),this.rpc=process.env.RPC||r||ke[this.chainId],N(this.rpc,"'rpc' is required for Ethereum"),this.server=process.env.SERVER||i||xe[this.chainId],this.appId=process.env.APP_ID||s}var n,s,c,u,h,l,f,p;return n=e,(s=[{key:"request",value:(p=r(regeneratorRuntime.mark((function e(n){var r,o,i;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!window.ethereum||!window.ethereum.isBlocto){e.next=2;break}return e.abrupt("return",window.ethereum.request(n));case 2:if(this.connected){e.next=5;break}return e.next=5,this.enable();case 5:e.prev=5,r=null,o=null,e.t0=n.method,e.next="eth_accounts"===e.t0?11:"eth_coinbase"===e.t0?15:"eth_chainId"===e.t0?20:"net_version"===e.t0?23:"eth_sign"===e.t0?26:"eth_sendTransaction"===e.t0?31:"eth_signTransaction"===e.t0||"eth_sendRawTransaction"===e.t0?35:37;break;case 11:return e.next=13,this.fetchAccounts();case 13:return o=e.sent,e.abrupt("break",40);case 15:return e.next=17,this.fetchAccounts();case 17:return i=e.sent,o=i[0],e.abrupt("break",40);case 20:return o="0x"+(o=this.chainId).toString(16),e.abrupt("break",40);case 23:return o="0x"+(o=this.networkId||this.chainId).toString(16),e.abrupt("break",40);case 26:return e.next=28,this.handleSign(n);case 28:return o=(o=e.sent).signature,e.abrupt("break",40);case 31:return e.next=33,this.handleSendTransaction(n);case 33:return o=e.sent,e.abrupt("break",40);case 35:return o=null,e.abrupt("break",40);case 37:return e.next=39,this.handleReadRequests(t({id:1,jsonrpc:"2.0"},n));case 39:r=e.sent;case 40:if(!r){e.next=42;break}return e.abrupt("return",r.result);case 42:return e.abrupt("return",o);case 45:throw e.prev=45,e.t1=e.catch(5),console.error(e.t1),e.t1;case 49:case"end":return e.stop()}}),e,this,[[5,45]])}))),function(e){return p.apply(this,arguments)})},{key:"enable",value:function(){var e=this;return window.ethereum&&window.ethereum.isBlocto?window.ethereum.enable():new Promise((function(t,n){"undefined"==typeof window&&n("Currently only supported in browser");var r=document.createElement("iframe");r.setAttribute("src","".concat(e.server,"/authn?l6n=").concat(encodeURIComponent(window.location.origin),"&chain=").concat(e.chain)),r.setAttribute("style",Ee),document.body.appendChild(r);var o=null;o=window.addEventListener("message",(function(i){i.origin===e.server&&("FCL::CHALLENGE::RESPONSE"===i.data.type&&(window.removeEventListener("message",o),r.parentNode.removeChild(r),e.code=i.data.code,e.connected=!0,t([i.data.addr])),"FCL::CHALLENGE::CANCEL"===i.data.type&&(window.removeEventListener("message",o),r.parentNode.removeChild(r),n()))}))}))}},{key:"fetchAccounts",value:(f=r(regeneratorRuntime.mark((function e(){var t,n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch("".concat(this.server,"/api/").concat(this.chain,"/accounts?code=").concat(this.code)).then((function(e){return e.json()}));case 2:return t=e.sent,n=t.accounts,e.abrupt("return",n);case 5:case"end":return e.stop()}}),e,this)}))),function(){return f.apply(this,arguments)})},{key:"handleReadRequests",value:(l=r(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch(this.rpc,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).then((function(e){return e.json()}));case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}}),e,this)}))),function(e){return l.apply(this,arguments)})},{key:"handleSign",value:(h=r(regeneratorRuntime.mark((function e(t){var n;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=t.params,e.next=3,fetch("".concat(this.server,"/api/").concat(this.chain,"/sign?code=").concat(this.code),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:n[1]})}).then((function(e){return e.json()}));case 3:return e.abrupt("return",e.sent);case 4:case"end":return e.stop()}}),e,this)}))),function(e){return h.apply(this,arguments)})},{key:"handleSendTransaction",value:(u=r(regeneratorRuntime.mark((function e(n){var r,o,i,a,s,c,u,h,l;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.params,e.next=3,fetch("".concat(this.server,"/api/").concat(this.chain,"/estimatePoint?code=").concat(this.code),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(r[0])}).then((function(e){return e.json()}));case 3:return o=e.sent,i=o.cost,e.next=7,fetch("".concat(this.server,"/api/").concat(this.chain,"/authz?code=").concat(this.code),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t(t({},r[0]),{},{point:i}))}).then((function(e){return e.json()}));case 7:if(a=e.sent,s=a.authorizationId,"undefined"!=typeof window){e.next=11;break}throw new Error("Currently only supported in browser");case 11:(c=document.createElement("iframe")).setAttribute("src","".concat(this.server,"/authz/").concat(this.chain,"/").concat(s)),c.setAttribute("style",Ee),document.body.appendChild(c);case 15:return e.next=18,fetch("".concat(this.server,"/api/").concat(this.chain,"/authz?authorizationId=").concat(s),{method:"GET",headers:{"Content-Type":"application/json"}}).then((function(e){return e.json()}));case 18:if(u=e.sent,h=u.status,l=u.transactionHash,"APPROVED"!==h){e.next=24;break}return c.parentNode.removeChild(c),e.abrupt("return",l);case 24:if("DECLINED"!==h){e.next=27;break}throw c.parentNode.removeChild(c),new Error("Transaction Canceled");case 27:return e.next=29,ye(1e3);case 29:e.next=15;break;case 31:case"end":return e.stop()}}),e,this)}))),function(e){return u.apply(this,arguments)})}])&&i(n.prototype,s),c&&i(n,c),e}()}));
{
"name": "@blocto/sdk",
"version": "0.0.8",
"version": "0.0.9",
"author": "Yang Lin",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -90,2 +90,6 @@ import invariant from 'invariant'

if (!this.connected) {
await this.enable();
}
try {

@@ -92,0 +96,0 @@ let response = null;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc