Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@haechi-labs/face-sdk

Package Overview
Dependencies
Maintainers
2
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@haechi-labs/face-sdk - npm Package Compare versions

Comparing version 1.9.3 to 1.9.4-alpha.0

dist/cjs/src/__tests__/face.test.d.ts

2

dist/cjs/index.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@haechi-labs/face-types"),e=require("@noble/hashes/sha3"),n=require("aptos"),r=require("ethers"),i=require("near-api-js"),o=require("@solana/web3.js");function s(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var a=s(i),c=function(t,e){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},c(t,e)};function u(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function h(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}var l=function(){function t(t){this.internal=t}return t.prototype.login=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.internal.loginWithCredential()]}))}))},t.prototype.directSocialLogin=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){return[2,this.internal.directSocialLogin(t)]}))}))},t.prototype.getIdToken=function(t,e){return u(this,void 0,void 0,(function(){return h(this,(function(n){return[2,this.internal.getIdToken(t,e)]}))}))},t.prototype.loginWithIdToken=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){return[2,this.internal.loginWithIdToken(t)]}))}))},t.prototype.logout=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){switch(t.label){case 0:return[4,this.internal.logout()];case 1:return t.sent(),[2]}}))}))},t.prototype.getCurrentUser=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){switch(t.label){case 0:return[4,this.internal.getCurrentUser()];case 1:return[2,t.sent()]}}))}))},t.prototype.isLoggedIn=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){switch(t.label){case 0:return[4,this.internal.isLoggedIn()];case 1:return[2,t.sent()]}}))}))},t}(),d=function(){function r(t){this.internal=t}return r.prototype.getPublicKeys=function(){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.APTOS)];case 1:return[2,e.sent().map((function(t){return n.HexString.ensure(t)}))]}}))}))},r.prototype.getAddresses=function(){return u(this,void 0,void 0,(function(){return h(this,(function(r){switch(r.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.APTOS)];case 1:return[2,r.sent().map((function(t){var r=Uint8Array.from(t.substring(2).match(/.{1,2}/g).map((function(t){return parseInt(t,16)}))),i=new Uint8Array(r.length+1);i.set(r),i.set([0],r.length);var o=e.sha3_256.create();return o.update(i),n.HexString.fromUint8Array(o.digest())}))]}}))}))},r.prototype.signMultiAgentTransaction=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.sendRpc({method:"aptos_signMultiAgentTransaction",params:[n.BCS.bcsToBytes(t)]})];case 1:return[2,e.sent()]}}))}))},r}(),f=function(){function t(t){this.internal=t}return t.prototype.getProvider=function(){return new d(this.internal)},t}(),p=function(){function t(t){this.internal=t}return t.prototype.connect=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.boraConnect(t)];case 1:return[2,e.sent()]}}))}))},t.prototype.isConnected=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.boraIsConnected(t)];case 1:return[2,e.sent()]}}))}))},t}(),v=function(){function e(t){this.internal=t}return e.prototype.getPublicKeys=function(){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.NEAR)];case 1:return[2,e.sent().map((function(t){return a.utils.PublicKey.fromString(a.utils.serialize.base_encode(Buffer.from(t,"hex")))}))]}}))}))},e.prototype.getBalance=function(e,n){return u(this,void 0,void 0,(function(){var i;return h(this,(function(o){switch(o.label){case 0:return[4,this.internal.sendRpc({method:t.JsonRpcMethod.near_get_balance,params:[e,n]})];case 1:return i=o.sent(),[2,r.BigNumber.from(i)]}}))}))},e.prototype.signAndSendTransaction=function(t){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return e={serializedHex:Buffer.from(a.utils.serialize.serialize(a.transactions.SCHEMA,t)).toString("hex")},[4,this.internal.sendRpc({method:"near_broadcast_tx_async",params:[e]})];case 1:return[2,n.sent()]}}))}))},e}(),w=function(){function t(t){this.internal=t}return t.prototype.getProvider=function(){return new v(this.internal)},t}(),m=function(){function e(t){this.internal=t}return e.prototype.getPublicKeys=function(){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.SOLANA)];case 1:return[2,e.sent().map((function(t){return new o.PublicKey(r.ethers.utils.base58.decode(t))}))]}}))}))},e.prototype.signAndSendTransaction=function(t){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return e={serializedHex:t.serialize({requireAllSignatures:!1,verifySignatures:!1}).toString("hex")},[4,this.internal.sendRpc({method:"solana_sendTransaction",params:[e]})];case 1:return[2,n.sent()]}}))}))},e}(),y=function(){function t(t){this.internal=t}return t.prototype.getProvider=function(){return new m(this.internal)},t}(),k={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};var g=function(){var t=this;this._isCompleted=!1,this._eventListeners=Array(),this.complete=function(){t._isCompleted=!0,t._eventListeners.forEach((function(t){return t()}))},this.add=function(e){t._eventListeners.push(e)},this.isCompleted=function(){return t._isCompleted}},E=function(){function e(t,e,n,r){var i=this;this._ready=new g,this.requestIndex=0,this.activeElement=null,this._blockchain=e,this._env=n;var o=Math.random().toString();if(this.randomPrefix=o.substring(o.length-6),document.getElementById("face-iframe"))throw new Error("Face is already initialized, Face can be initialized once.");window.addEventListener("message",(function(t){return u(i,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return t.origin!==r?[2]:[4,this.processMessage(t.data)];case 1:return e.sent(),[2]}}))}))})),this._iframe=new Promise((function(i){var o=function(){if(!document.getElementById("face-iframe")){var o=document.createElement("iframe");o.id="face-iframe",o.title="Secure Modal",o.src=new URL("".concat(r,"?api_key=").concat(t,"&blockchain=").concat(e,"&env=").concat(n)).href,o.allow="clipboard-read; clipboard-write",function(t){for(var e=0,n=Object.entries(k);e<n.length;e++){var r=n[e],i=r[0],o=r[1];t.style[i]=o}}(o),document.body.appendChild(o),i(o)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}))}return e.prototype.sendChildMessage=function(e){var n,r;return u(this,void 0,void 0,(function(){var i;return h(this,(function(o){switch(o.label){case 0:return[4,this.ready()];case 1:return o.sent(),this.requestIndex+=1,i="".concat(this.randomPrefix,"-").concat(this.requestIndex),e.id=i,e.from=t.JsonRpcSource.FACE_SDK,[4,this._iframe];case 2:return null===(r=null===(n=o.sent())||void 0===n?void 0:n.contentWindow)||void 0===r||r.postMessage(e,"*"),[2,i]}}))}))},e.prototype.waitForResponse=function(t){return new Promise((function(e,n){var r=function(i){var o=i.data;t&&o.id!==t||(window.removeEventListener("message",r),o.error?n(o.error):e(o.result))};window.addEventListener("message",r)}))},e.prototype.processMessage=function(e){return u(this,void 0,void 0,(function(){return h(this,(function(n){switch(n.label){case 0:switch(e.method){case t.JsonRpcMethod.face_ready:return[3,1];case t.JsonRpcMethod.face_openIframe:return[3,2];case t.JsonRpcMethod.face_closeIframe:return[3,4]}return[3,6];case 1:return this._ready.complete(),[3,6];case 2:return[4,this.showOverlay()];case 3:case 5:return n.sent(),[3,6];case 4:return[4,this.hideOverlay()];case 6:return[2]}}))}))},e.prototype.ready=function(){return u(this,void 0,void 0,(function(){var t=this;return h(this,(function(e){return[2,new Promise((function(e){return u(t,void 0,void 0,(function(){return h(this,(function(t){return this._ready.isCompleted()?(e(),[2]):(this._ready.add((function(){e()})),[2])}))}))}))]}))}))},e.prototype.showOverlay=function(){return u(this,void 0,void 0,(function(){var t;return h(this,(function(e){switch(e.label){case 0:return[4,this.ready()];case 1:return e.sent(),[4,this._iframe];case 2:return(t=e.sent()).style.display="block",this.activeElement=document.activeElement,t.focus(),[2]}}))}))},e.prototype.hideOverlay=function(){var t;return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.ready()];case 1:return e.sent(),[4,this._iframe];case 2:return e.sent().style.display="none",(null===(t=this.activeElement)||void 0===t?void 0:t.focus)&&this.activeElement.focus(),this.activeElement=null,[2]}}))}))},e.prototype.setBlockchain=function(t){this._blockchain=t},e.prototype.throwExceptionUnsupportedBlockchain=function(e){if(e.includes(this._blockchain))throw t.unsupportedChainError()},e.prototype.getBlockchain=function(){return this._blockchain},e}();function b(e){switch(e){case t.Network.ETHEREUM:case t.Network.POLYGON:case t.Network.BNB_SMART_CHAIN:case t.Network.KLAYTN:case t.Network.SOLANA:case t.Network.BORA:case t.Network.NEAR:return!0;default:return!1}}function N(e){switch(e){case t.Network.ETHEREUM:case t.Network.GOERLI:return t.Blockchain.ETHEREUM;case t.Network.POLYGON:case t.Network.MUMBAI:return t.Blockchain.POLYGON;case t.Network.BNB_SMART_CHAIN:case t.Network.BNB_SMART_CHAIN_TESTNET:return t.Blockchain.BNB_SMART_CHAIN;case t.Network.KLAYTN:case t.Network.BAOBAB:return t.Blockchain.KLAYTN;case t.Network.SOLANA:case t.Network.SOLANA_DEVNET:return t.Blockchain.SOLANA;case t.Network.BORA:case t.Network.BORA_TESTNET:return t.Blockchain.BORA;case t.Network.NEAR:case t.Network.NEAR_TESTNET:return t.Blockchain.NEAR;case t.Network.APTOS:case t.Network.APTOS_TESTNET:return t.Blockchain.APTOS;case t.Network.MEVERSE:case t.Network.MEVERSE_TESTNET:return t.Blockchain.MEVERSE;default:return t.Blockchain.ETHEREUM}}var A=r.BigNumber.from(1e5).toHexString(),_=function(){function e(e){var n=e.apiKey,r=e.network,i=e.env,o=e.iframeUrl,s=e.face;this.network=r||t.Network.ETHEREUM;var a=N(this.network);this.env=null!=i?i:function(e){return!e||e!==t.Network.GOERLI&&e!==t.Network.MUMBAI&&e!==t.Network.BAOBAB&&e!==t.Network.BNB_SMART_CHAIN_TESTNET&&e!==t.Network.BORA_TESTNET&&e!==t.Network.SOLANA_DEVNET&&e!==t.Network.NEAR_TESTNET&&e!==t.Network.APTOS_TESTNET&&e!==t.Network.MEVERSE_TESTNET?t.Env.ProdMainnet:t.Env.ProdTest}(r),this.iframe=new E(n,a,this.env,function(e,n){if(null!=n)return n;switch(e){case t.Env.Local:return"http://localhost:3333";case t.Env.Dev:return"https://app.dev.facewallet.xyz";case t.Env.StageTest:return"https://app.stage-test.facewallet.xyz";case t.Env.ProdTest:return"https://app.test.facewallet.xyz";case t.Env.StageMainnet:return"https://app.stage.facewallet.xyz";case t.Env.ProdMainnet:default:return"https://app.facewallet.xyz"}}(this.env,o)),this.face=s}return e.prototype.getAddresses=function(e){return u(this,void 0,void 0,(function(){var n,r;return h(this,(function(i){switch(i.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_accounts,params:[e]})];case 1:return n=i.sent(),[4,this.iframe.waitForResponse(n)];case 2:return(r=i.sent())?[2,r]:[2,Promise.reject(new Error("get address failed"))]}}))}))},e.prototype.estimateGas=function(t){return u(this,void 0,void 0,(function(){var e=this;return h(this,(function(n){switch(n.label){case 0:return[4,Promise.all(t.params.map((function(t){return u(e,void 0,void 0,(function(){var e,n,r,i,o,s,a;return h(this,(function(c){switch(c.label){case 0:return t.from?t.data?(e=["function transfer(address to, uint256 value) public returns (bool success)"],[4,this.decodeData(t.data,e).catch((function(){return{}}))]):[3,5]:[3,7];case 1:return n=c.sent(),r=n.name,(null==(i=n.args)?void 0:i.to)&&(null==i?void 0:i.value)?[4,this.getBalance(t.from,t.to)]:[3,4];case 2:return a=c.sent(),o={to:i.to,value:i.value},a.sub(o.value).lt(0)&&(o.value="0x0"),s=t,[4,this.encodeData(e,r,[o.to,o.value])];case 3:s.data=c.sent(),c.label=4;case 4:return[3,7];case 5:return[4,this.getBalance(t.from)];case 6:(a=c.sent()).sub(t.value).lt(0)&&(t.value="0x0"),c.label=7;case 7:return[2]}}))}))})))];case 1:return n.sent(),[4,this.sendRpc(t).catch((function(){return A}))];case 2:return[2,n.sent()]}}))}))},e.prototype.getBalance=function(e,n){return u(this,void 0,void 0,(function(){var i,o,s,a;return h(this,(function(c){switch(c.label){case 0:return n?[4,this.encodeData(["function balanceOf(address owner) view returns (uint256)"],"balanceOf",[e])]:[3,3];case 1:return i=c.sent(),[4,this.sendRpc({method:t.JsonRpcMethod.eth_call,params:[{to:n,data:i},"latest"]})];case 2:return o=c.sent(),[2,r.BigNumber.from(o)];case 3:return a=(s=r.BigNumber).from,[4,this.sendRpc({method:t.JsonRpcMethod.eth_getBalance,params:[e,"latest"]})];case 4:return[2,a.apply(s,[c.sent()])]}}))}))},e.prototype.ownerOf=function(e,n){return u(this,void 0,void 0,(function(){var r;return h(this,(function(i){switch(i.label){case 0:return[4,this.encodeData(["function ownerOf(uint256 tokenId) view returns (address)"],"ownerOf",[n])];case 1:return r=i.sent(),[4,this.sendRpc({method:t.JsonRpcMethod.eth_call,params:[{to:e,data:r},"latest"]})];case 2:return[2,("0x"+i.sent().substring(26)).toLowerCase()]}}))}))},e.prototype.logout=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_logOut})];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return n.sent(),[2]}}))}))},e.prototype.getCurrentUser=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_currentUser})];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return[2,n.sent()]}}))}))},e.prototype.isLoggedIn=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_loggedIn})];case 1:return n.sent(),[4,this.iframe.waitForResponse()];case 2:return(e=n.sent())?[2,e]:[2,!1]}}))}))},e.prototype.ready=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.iframe.ready()]}))}))},e.prototype.loginWithCredential=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_logInSignUp})];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return[2,n.sent()]}}))}))},e.prototype.directSocialLogin=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_directSocialLogin,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e.prototype.getIdToken=function(e,n){return u(this,void 0,void 0,(function(){var r;return h(this,(function(i){switch(i.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_getIdToken,params:[e,n]})];case 1:return r=i.sent(),[4,this.iframe.waitForResponse(r)];case 2:return[2,i.sent()]}}))}))},e.prototype.loginWithIdToken=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_loginWithIdToken,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e.prototype.openWalletConnect=function(e,n){return u(this,void 0,void 0,(function(){return h(this,(function(r){switch(r.label){case 0:return this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.NEAR,t.Blockchain.SOLANA]),[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_openWalletConnect,params:[e,n]})];case 1:return r.sent(),[2]}}))}))},e.prototype.openHome=function(e){return u(this,void 0,void 0,(function(){var n,r;return h(this,(function(i){switch(i.label){case 0:if(this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.SOLANA,t.Blockchain.NEAR,t.Blockchain.MEVERSE]),n=b(this.network),(null==e?void 0:e.networks)&&e.networks.some((function(t){return b(t)!==n})))throw r="You initialized the Face SDK with ".concat(n?"Mainnet":"Testnet",". Please open the wallet home in the same environment as the initialized network."),new Error(r);return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_openHome,params:[e]})];case 1:return i.sent(),[2]}}))}))},e.prototype.sendRpc=function(t){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage(t)];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return[2,n.sent()]}}))}))},e.prototype.decodeData=function(t,e){return u(this,void 0,void 0,(function(){var n,i,o,s;return h(this,(function(a){return n=new r.ethers.utils.Interface(e),i=n.parseTransaction({data:t}),o=i.name,s=i.args,[2,{name:o,args:s}]}))}))},e.prototype.encodeData=function(t,e,n){return u(this,void 0,void 0,(function(){return h(this,(function(i){return[2,new r.ethers.utils.Interface(t).encodeFunctionData(e,n)]}))}))},e.prototype.switchNetwork=function(e){return u(this,void 0,void 0,(function(){var n,r,i;return h(this,(function(o){switch(o.label){case 0:return n=N(e),r={method:t.JsonRpcMethod.face_switchNetwork,params:[{blockchain:n}]},[4,this.sendRpc(r)];case 1:return i=o.sent(),this.face.setNetwork(e),this.iframe.setBlockchain(n),[2,i]}}))}))},e.prototype.boraIsConnected=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.NEAR,t.Blockchain.KLAYTN,t.Blockchain.BNB_SMART_CHAIN,t.Blockchain.ETHEREUM,t.Blockchain.MEVERSE,t.Blockchain.SOLANA,t.Blockchain.POLYGON]),[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.bora_isConnected,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e.prototype.boraConnect=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.NEAR,t.Blockchain.KLAYTN,t.Blockchain.BNB_SMART_CHAIN,t.Blockchain.ETHEREUM,t.Blockchain.MEVERSE,t.Blockchain.SOLANA,t.Blockchain.POLYGON]),[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.bora_connect,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e}(),B=function(e){function n(t){var n=e.call(this)||this;return n.internal=t,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,e),n.prototype.request=function(e){return u(this,void 0,void 0,(function(){var n,r=this;return h(this,(function(i){if(Array.isArray(e))return[2,Promise.all(e.map((function(t){return r.internal.sendRpc(t)})))];switch(e.method){case t.JsonRpcMethod.wallet_switchEthereumChain:return n=t.NetworkChainIdMap[e.params[0].chainId],[2,this.internal.switchNetwork(n)];case t.JsonRpcMethod.eth_estimateGas:return[2,this.internal.estimateGas(e)];case"personal_listAccounts":case"eth_accounts":return[2,this.internal.getAddresses()];default:return[2,this.internal.sendRpc(e)]}return[2]}))}))},n}((function(){this.sendAsync=function(t,e){}})),R=function(){function t(t){this.internal=t}return t.prototype.close=function(){this.internal.iframe.hideOverlay()},t.prototype.home=function(t){var e;return u(this,void 0,void 0,(function(){return h(this,(function(n){if(0===(null===(e=null==t?void 0:t.networks)||void 0===e?void 0:e.length))throw new Error("The 'networks' should select at least one network.");return[2,this.internal.openHome(t)]}))}))},t}(),T=function(){function t(t){this.internal=t}return t.prototype.connectOpensea=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.connect("OpenSea",t?"https://opensea.io/collection/"+t:"https://opensea.io")];case 1:return e.sent(),[2]}}))}))},t.prototype.connect=function(t,e){return u(this,void 0,void 0,(function(){return h(this,(function(n){switch(n.label){case 0:return[4,this.internal.openWalletConnect(t,e)];case 1:return n.sent(),[2]}}))}))},t}(),M=function(){function e(e){var n=this,r=e.apiKey,i=e.network,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(e,["apiKey","network"]);if(this.getAddresses=function(t){return u(n,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.getAddresses(t)];case 1:return[2,e.sent()]}}))}))},this.setNetwork=function(t){n.network=t},this.getNetwork=function(){return n.network},this.getChainId=function(){return u(n,void 0,void 0,(function(){var t;return h(this,(function(e){switch(e.label){case 0:return t=Number,[4,this.internal.sendRpc({method:"eth_chainId",params:[]})];case 1:return[2,t.apply(void 0,[e.sent()])]}}))}))},i=i||t.Network.ETHEREUM,!t.isSupportedNetwork(i))throw t.unsupportedChainError();this.network=i,this.internal=new _({apiKey:r,network:i,env:o.env,iframeUrl:o.iframeUrl,face:this}),this.auth=new l(this.internal),this.wc=new T(this.internal),this.solana=new y(this.internal),this.near=new w(this.internal),this.wallet=new R(this.internal),this.bora=new p(this.internal),this.aptos=new f(this.internal)}return e.prototype.ready=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.internal.ready()]}))}))},e.prototype.getEthLikeProvider=function(){if(!t.isEthlikeBlockchain(t.networkToBlockchain(this.network)))throw t.unsupportedChainError();return new B(this.internal)},e.prototype.switchNetwork=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){return[2,this.internal.switchNetwork(t)]}))}))},e}();Object.defineProperty(exports,"Network",{enumerable:!0,get:function(){return t.Network}}),exports.Face=M;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("@haechi-labs/face-types"),e=require("@noble/hashes/sha3"),n=require("aptos"),r=require("ethers"),i=require("near-api-js"),o=require("@solana/web3.js");function s(t){if(t&&t.__esModule)return t;var e=Object.create(null);return t&&Object.keys(t).forEach((function(n){if("default"!==n){var r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,r.get?r:{enumerable:!0,get:function(){return t[n]}})}})),e.default=t,Object.freeze(e)}var a=s(i),c=function(t,e){return c=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},c(t,e)};function u(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))}function h(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(c){return function(a){if(n)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)try{if(n=1,r&&(i=2&a[0]?r.return:a[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,a[1])).done)return i;switch(r=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return s.label++,{value:a[1],done:!1};case 5:s.label++,r=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=e.call(t,s)}catch(t){a=[6,t],r=0}finally{n=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,c])}}}var l=function(){function e(t){this.internal=t}return e.prototype.login=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.internal.loginWithCredential()]}))}))},e.prototype.directSocialLogin=function(e){return u(this,void 0,void 0,(function(){return h(this,(function(n){return t.assertArgument(e,"string"==typeof e,"provider"),[2,this.internal.directSocialLogin(e)]}))}))},e.prototype.getIdToken=function(e,n){return u(this,void 0,void 0,(function(){return h(this,(function(r){return t.assertArgument(e,"string"==typeof e,"provider"),t.assertArgument(n,"string"==typeof n,"accessToken"),[2,this.internal.getIdToken(e,n)]}))}))},e.prototype.loginWithIdToken=function(e){return u(this,void 0,void 0,(function(){return h(this,(function(n){return t.assertArgument(e,e.idToken&&e.sig,"loginWithIdTokenRequest"),[2,this.internal.loginWithIdToken(e)]}))}))},e.prototype.logout=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){switch(t.label){case 0:return[4,this.internal.logout()];case 1:return t.sent(),[2]}}))}))},e.prototype.getCurrentUser=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){switch(t.label){case 0:return[4,this.internal.getCurrentUser()];case 1:return[2,t.sent()]}}))}))},e.prototype.isLoggedIn=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){switch(t.label){case 0:return[4,this.internal.isLoggedIn()];case 1:return[2,t.sent()]}}))}))},e}(),d=function(){function r(t){this.internal=t}return r.prototype.getPublicKeys=function(){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.APTOS)];case 1:return[2,e.sent().map((function(t){return n.HexString.ensure(t)}))]}}))}))},r.prototype.getAddresses=function(){return u(this,void 0,void 0,(function(){return h(this,(function(r){switch(r.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.APTOS)];case 1:return[2,r.sent().map((function(t){var r=Uint8Array.from(t.substring(2).match(/.{1,2}/g).map((function(t){return parseInt(t,16)}))),i=new Uint8Array(r.length+1);i.set(r),i.set([0],r.length);var o=e.sha3_256.create();return o.update(i),n.HexString.fromUint8Array(o.digest())}))]}}))}))},r.prototype.signMultiAgentTransaction=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.sendRpc({method:"aptos_signMultiAgentTransaction",params:[n.BCS.bcsToBytes(t)]})];case 1:return[2,e.sent()]}}))}))},r}(),f=function(){function t(t){this.internal=t}return t.prototype.getProvider=function(){return new d(this.internal)},t}(),p=function(){function e(t){this.internal=t}return e.prototype.connect=function(e){return u(this,void 0,void 0,(function(){return h(this,(function(n){switch(n.label){case 0:return t.assertArgument(e,e.bappUsn&&e.signature,"request"),[4,this.internal.boraConnect(e)];case 1:return[2,n.sent()]}}))}))},e.prototype.isConnected=function(e){return u(this,void 0,void 0,(function(){return h(this,(function(n){switch(n.label){case 0:return t.assertArgument(e,"string"==typeof e,"bappUsn"),[4,this.internal.boraIsConnected(e)];case 1:return[2,n.sent()]}}))}))},e}(),v=function(){function e(t){this.internal=t}return e.prototype.getPublicKeys=function(){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.NEAR)];case 1:return[2,e.sent().map((function(t){return a.utils.PublicKey.fromString(a.utils.serialize.base_encode(Buffer.from(t,"hex")))}))]}}))}))},e.prototype.getBalance=function(e,n){return u(this,void 0,void 0,(function(){var i;return h(this,(function(o){switch(o.label){case 0:return t.assertArgument(e,"string"==typeof e,"address"),t.assertArgument(n,"string"==typeof n,"contractAddress",!1),[4,this.internal.sendRpc({method:t.JsonRpcMethod.near_get_balance,params:[e,n]})];case 1:return i=o.sent(),[2,r.BigNumber.from(i)]}}))}))},e.prototype.signAndSendTransaction=function(t){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return e={serializedHex:Buffer.from(a.utils.serialize.serialize(a.transactions.SCHEMA,t)).toString("hex")},[4,this.internal.sendRpc({method:"near_broadcast_tx_async",params:[e]})];case 1:return[2,n.sent()]}}))}))},e}(),w=function(){function t(t){this.internal=t}return t.prototype.getProvider=function(){return new v(this.internal)},t}(),m=function(){function e(t){this.internal=t}return e.prototype.getPublicKeys=function(){return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.internal.getAddresses(t.Blockchain.SOLANA)];case 1:return[2,e.sent().map((function(t){return new o.PublicKey(r.ethers.utils.base58.decode(t))}))]}}))}))},e.prototype.signAndSendTransaction=function(t){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return e={serializedHex:t.serialize({requireAllSignatures:!1,verifySignatures:!1}).toString("hex")},[4,this.internal.sendRpc({method:"solana_sendTransaction",params:[e]})];case 1:return[2,n.sent()]}}))}))},e}(),y=function(){function t(t){this.internal=t}return t.prototype.getProvider=function(){return new m(this.internal)},t}(),g={display:"none",position:"fixed",top:"0",right:"0",width:"100%",height:"100%",borderRadius:"0",border:"none",zIndex:"2147483647"};var k=function(){var t=this;this._isCompleted=!1,this._eventListeners=Array(),this.complete=function(){t._isCompleted=!0,t._eventListeners.forEach((function(t){return t()}))},this.add=function(e){t._eventListeners.push(e)},this.isCompleted=function(){return t._isCompleted}},b=function(){function e(t,e,n,r){var i=this;this._ready=new k,this.requestIndex=0,this.activeElement=null,this._blockchain=e,this._env=n;var o=Math.random().toString();if(this.randomPrefix=o.substring(o.length-6),document.getElementById("face-iframe"))throw new Error("Face is already initialized, Face can be initialized once.");window.addEventListener("message",(function(t){return u(i,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return t.origin!==r?[2]:[4,this.processMessage(t.data)];case 1:return e.sent(),[2]}}))}))})),this._iframe=new Promise((function(i){var o=function(){if(!document.getElementById("face-iframe")){var o=document.createElement("iframe");o.id="face-iframe",o.title="Secure Modal",o.src=new URL("".concat(r,"?api_key=").concat(t,"&blockchain=").concat(e,"&env=").concat(n)).href,o.allow="clipboard-read; clipboard-write",function(t){for(var e=0,n=Object.entries(g);e<n.length;e++){var r=n[e],i=r[0],o=r[1];t.style[i]=o}}(o),document.body.appendChild(o),i(o)}};["loaded","interactive","complete"].includes(document.readyState)?o():window.addEventListener("load",o,!1)}))}return e.prototype.sendChildMessage=function(e){var n,r;return u(this,void 0,void 0,(function(){var i;return h(this,(function(o){switch(o.label){case 0:return[4,this.ready()];case 1:return o.sent(),this.requestIndex+=1,i="".concat(this.randomPrefix,"-").concat(this.requestIndex),e.id=i,e.from=t.JsonRpcSource.FACE_SDK,[4,this._iframe];case 2:return null===(r=null===(n=o.sent())||void 0===n?void 0:n.contentWindow)||void 0===r||r.postMessage(e,"*"),[2,i]}}))}))},e.prototype.waitForResponse=function(t){return new Promise((function(e,n){var r=function(i){var o=i.data;t&&o.id!==t||(window.removeEventListener("message",r),o.error?n(o.error):e(o.result))};window.addEventListener("message",r)}))},e.prototype.processMessage=function(e){return u(this,void 0,void 0,(function(){return h(this,(function(n){switch(n.label){case 0:switch(e.method){case t.JsonRpcMethod.face_ready:return[3,1];case t.JsonRpcMethod.face_openIframe:return[3,2];case t.JsonRpcMethod.face_closeIframe:return[3,4]}return[3,6];case 1:return this._ready.complete(),[3,6];case 2:return[4,this.showOverlay()];case 3:case 5:return n.sent(),[3,6];case 4:return[4,this.hideOverlay()];case 6:return[2]}}))}))},e.prototype.ready=function(){return u(this,void 0,void 0,(function(){var t=this;return h(this,(function(e){return[2,new Promise((function(e){return u(t,void 0,void 0,(function(){return h(this,(function(t){return this._ready.isCompleted()?(e(),[2]):(this._ready.add((function(){e()})),[2])}))}))}))]}))}))},e.prototype.showOverlay=function(){return u(this,void 0,void 0,(function(){var t;return h(this,(function(e){switch(e.label){case 0:return[4,this.ready()];case 1:return e.sent(),[4,this._iframe];case 2:return(t=e.sent()).style.display="block",this.activeElement=document.activeElement,t.focus(),[2]}}))}))},e.prototype.hideOverlay=function(){var t;return u(this,void 0,void 0,(function(){return h(this,(function(e){switch(e.label){case 0:return[4,this.ready()];case 1:return e.sent(),[4,this._iframe];case 2:return e.sent().style.display="none",(null===(t=this.activeElement)||void 0===t?void 0:t.focus)&&this.activeElement.focus(),this.activeElement=null,[2]}}))}))},e.prototype.setBlockchain=function(t){this._blockchain=t},e.prototype.throwExceptionUnsupportedBlockchain=function(e){if(e.includes(this._blockchain))throw t.unsupportedChainError()},e.prototype.getBlockchain=function(){return this._blockchain},e}();function E(e){switch(e){case t.Network.ETHEREUM:case t.Network.POLYGON:case t.Network.BNB_SMART_CHAIN:case t.Network.KLAYTN:case t.Network.SOLANA:case t.Network.BORA:case t.Network.NEAR:return!0;default:return!1}}function A(e){switch(e){case t.Network.ETHEREUM:case t.Network.GOERLI:return t.Blockchain.ETHEREUM;case t.Network.POLYGON:case t.Network.MUMBAI:return t.Blockchain.POLYGON;case t.Network.BNB_SMART_CHAIN:case t.Network.BNB_SMART_CHAIN_TESTNET:return t.Blockchain.BNB_SMART_CHAIN;case t.Network.KLAYTN:case t.Network.BAOBAB:return t.Blockchain.KLAYTN;case t.Network.SOLANA:case t.Network.SOLANA_DEVNET:return t.Blockchain.SOLANA;case t.Network.BORA:case t.Network.BORA_TESTNET:return t.Blockchain.BORA;case t.Network.NEAR:case t.Network.NEAR_TESTNET:return t.Blockchain.NEAR;case t.Network.APTOS:case t.Network.APTOS_TESTNET:return t.Blockchain.APTOS;case t.Network.MEVERSE:case t.Network.MEVERSE_TESTNET:return t.Blockchain.MEVERSE;default:return t.Blockchain.ETHEREUM}}r.BigNumber.from(1e5).toHexString();var N=function(){function e(e){var n=e.apiKey,r=e.network,i=e.env,o=e.iframeUrl,s=e.face;this.network=r||t.Network.ETHEREUM;var a=A(this.network);this.env=null!=i?i:function(e){return!e||e!==t.Network.GOERLI&&e!==t.Network.MUMBAI&&e!==t.Network.BAOBAB&&e!==t.Network.BNB_SMART_CHAIN_TESTNET&&e!==t.Network.BORA_TESTNET&&e!==t.Network.SOLANA_DEVNET&&e!==t.Network.NEAR_TESTNET&&e!==t.Network.APTOS_TESTNET&&e!==t.Network.MEVERSE_TESTNET?t.Env.ProdMainnet:t.Env.ProdTest}(r),this.iframe=new b(n,a,this.env,function(e,n){if(null!=n)return n;switch(e){case t.Env.Local:return"http://localhost:3333";case t.Env.Dev:return"https://app.dev.facewallet.xyz";case t.Env.StageTest:return"https://app.stage-test.facewallet.xyz";case t.Env.ProdTest:return"https://app.test.facewallet.xyz";case t.Env.StageMainnet:return"https://app.stage.facewallet.xyz";case t.Env.ProdMainnet:default:return"https://app.facewallet.xyz"}}(this.env,o)),this.face=s}return e.prototype.getAddresses=function(e){return u(this,void 0,void 0,(function(){var n,r;return h(this,(function(i){switch(i.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_accounts,params:[e]})];case 1:return n=i.sent(),[4,this.iframe.waitForResponse(n)];case 2:return(r=i.sent())?[2,r]:[2,Promise.reject(new Error("get address failed"))]}}))}))},e.prototype.estimateGas=function(t){return u(this,void 0,void 0,(function(){return h(this,(function(t){return[2,0]}))}))},e.prototype.getBalance=function(e,n){return u(this,void 0,void 0,(function(){var i,o,s,a;return h(this,(function(c){switch(c.label){case 0:return n?[4,this.encodeData(["function balanceOf(address owner) view returns (uint256)"],"balanceOf",[e])]:[3,3];case 1:return i=c.sent(),[4,this.sendRpc({method:t.JsonRpcMethod.eth_call,params:[{to:n,data:i},"latest"]})];case 2:return o=c.sent(),[2,r.BigNumber.from(o)];case 3:return a=(s=r.BigNumber).from,[4,this.sendRpc({method:t.JsonRpcMethod.eth_getBalance,params:[e,"latest"]})];case 4:return[2,a.apply(s,[c.sent()])]}}))}))},e.prototype.ownerOf=function(e,n){return u(this,void 0,void 0,(function(){var r;return h(this,(function(i){switch(i.label){case 0:return[4,this.encodeData(["function ownerOf(uint256 tokenId) view returns (address)"],"ownerOf",[n])];case 1:return r=i.sent(),[4,this.sendRpc({method:t.JsonRpcMethod.eth_call,params:[{to:e,data:r},"latest"]})];case 2:return[2,("0x"+i.sent().substring(26)).toLowerCase()]}}))}))},e.prototype.logout=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_logOut})];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return n.sent(),[2]}}))}))},e.prototype.getCurrentUser=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_currentUser})];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return[2,n.sent()]}}))}))},e.prototype.isLoggedIn=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_loggedIn})];case 1:return n.sent(),[4,this.iframe.waitForResponse()];case 2:return(e=n.sent())?[2,e]:[2,!1]}}))}))},e.prototype.ready=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.iframe.ready()]}))}))},e.prototype.loginWithCredential=function(){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_logInSignUp})];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return[2,n.sent()]}}))}))},e.prototype.directSocialLogin=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_directSocialLogin,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e.prototype.getIdToken=function(e,n){return u(this,void 0,void 0,(function(){var r;return h(this,(function(i){switch(i.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_getIdToken,params:[e,n]})];case 1:return r=i.sent(),[4,this.iframe.waitForResponse(r)];case 2:return[2,i.sent()]}}))}))},e.prototype.loginWithIdToken=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_loginWithIdToken,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e.prototype.openWalletConnect=function(e,n){return u(this,void 0,void 0,(function(){var r;return h(this,(function(i){switch(i.label){case 0:return this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.NEAR,t.Blockchain.SOLANA]),[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_openWalletConnect,params:[e,n]})];case 1:return r=i.sent(),[4,this.iframe.waitForResponse(r)];case 2:return[2,i.sent()]}}))}))},e.prototype.openHome=function(e){return u(this,void 0,void 0,(function(){var n,r,i;return h(this,(function(o){switch(o.label){case 0:if(this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.SOLANA,t.Blockchain.NEAR]),n=E(this.network),(null==e?void 0:e.networks)&&e.networks.some((function(t){return E(t)!==n})))throw r="You initialized the Face SDK with ".concat(n?"Mainnet":"Testnet",". Please open the wallet home in the same environment as the initialized network."),new Error(r);return[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.face_openHome,params:[e]})];case 1:return i=o.sent(),[2,this.iframe.waitForResponse(i)]}}))}))},e.prototype.sendRpc=function(t){return u(this,void 0,void 0,(function(){var e;return h(this,(function(n){switch(n.label){case 0:return[4,this.iframe.sendChildMessage(t)];case 1:return e=n.sent(),[4,this.iframe.waitForResponse(e)];case 2:return[2,n.sent()]}}))}))},e.prototype.decodeData=function(t,e){return u(this,void 0,void 0,(function(){var n,i,o,s;return h(this,(function(a){return n=new r.ethers.utils.Interface(e),i=n.parseTransaction({data:t}),o=i.name,s=i.args,[2,{name:o,args:s}]}))}))},e.prototype.encodeData=function(t,e,n){return u(this,void 0,void 0,(function(){return h(this,(function(i){return[2,new r.ethers.utils.Interface(t).encodeFunctionData(e,n)]}))}))},e.prototype.switchNetwork=function(e){return u(this,void 0,void 0,(function(){var n,r,i;return h(this,(function(o){switch(o.label){case 0:return n=A(e),r={method:t.JsonRpcMethod.face_switchNetwork,params:[{blockchain:n}]},[4,this.sendRpc(r)];case 1:return i=o.sent(),this.face.setNetwork(e),this.iframe.setBlockchain(n),[2,i]}}))}))},e.prototype.boraIsConnected=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.NEAR,t.Blockchain.KLAYTN,t.Blockchain.BNB_SMART_CHAIN,t.Blockchain.ETHEREUM,t.Blockchain.MEVERSE,t.Blockchain.SOLANA,t.Blockchain.POLYGON]),[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.bora_isConnected,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e.prototype.boraConnect=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){switch(r.label){case 0:return this.iframe.throwExceptionUnsupportedBlockchain([t.Blockchain.APTOS,t.Blockchain.NEAR,t.Blockchain.KLAYTN,t.Blockchain.BNB_SMART_CHAIN,t.Blockchain.ETHEREUM,t.Blockchain.MEVERSE,t.Blockchain.SOLANA,t.Blockchain.POLYGON]),[4,this.iframe.sendChildMessage({method:t.JsonRpcMethod.bora_connect,params:[e]})];case 1:return n=r.sent(),[4,this.iframe.waitForResponse(n)];case 2:return[2,r.sent()]}}))}))},e}(),_=function(e){function n(t){var n=e.call(this)||this;return n.internal=t,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}c(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(n,e),n.prototype.request=function(e){return u(this,void 0,void 0,(function(){var n,r=this;return h(this,(function(i){if(Array.isArray(e))return[2,Promise.all(e.map((function(t){return r.internal.sendRpc(t)})))];switch(e.method){case t.JsonRpcMethod.wallet_switchEthereumChain:return n=t.NetworkChainIdMap[e.params[0].chainId],[2,this.internal.switchNetwork(n)];case t.JsonRpcMethod.eth_estimateGas:return[2,this.internal.estimateGas(e)];case"personal_listAccounts":case"eth_accounts":return[2,this.internal.getAddresses()];default:return[2,this.internal.sendRpc(e)]}return[2]}))}))},n}((function(){this.sendAsync=function(t,e){}})),R=function(){function e(t){this.internal=t}return e.prototype.close=function(){this.internal.iframe.hideOverlay()},e.prototype.home=function(e){var n;return u(this,void 0,void 0,(function(){return h(this,(function(r){return t.assertArgument(null==e?void 0:e.networks,null===(n=null==e?void 0:e.networks)||void 0===n?void 0:n.length,"options.networks",!1),[2,this.internal.openHome(e)]}))}))},e}(),B=function(){function e(t){this.internal=t}return e.prototype.connectOpensea=function(e){return u(this,void 0,void 0,(function(){return h(this,(function(n){switch(n.label){case 0:return t.assertArgument(e,"string"==typeof e,"collectionName",!1),[4,this.connect("OpenSea",e?"https://opensea.io/collection/"+e:"https://opensea.io")];case 1:return n.sent(),[2]}}))}))},e.prototype.connect=function(e,n){return u(this,void 0,void 0,(function(){return h(this,(function(r){switch(r.label){case 0:return t.assertArgument(e,"string"==typeof e,"name"),t.assertArgument(n,"string"==typeof n,"url"),[4,this.internal.openWalletConnect(e,n)];case 1:return r.sent(),[2]}}))}))},e}(),T=function(){function e(e){var n=this,r=e.apiKey,i=e.network,o=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]])}return n}(e,["apiKey","network"]);this.getAddresses=function(e){return u(n,void 0,void 0,(function(){return h(this,(function(n){switch(n.label){case 0:return t.assertArgument(e,e&&t.Blockchain[e],"blockchain",!1),[4,this.internal.getAddresses(e)];case 1:return[2,n.sent()]}}))}))},this.setNetwork=function(e){t.assertArgument(e,t.isSupportedNetwork(e),"network"),n.network=e},this.getNetwork=function(){return n.network},this.getChainId=function(){return u(n,void 0,void 0,(function(){var t;return h(this,(function(e){switch(e.label){case 0:return t=Number,[4,this.internal.sendRpc({method:"eth_chainId",params:[]})];case 1:return[2,t.apply(void 0,[e.sent()])]}}))}))},t.assertArgument(r,"string"==typeof r,"apiKey"),t.assertArgument(i,!0,"network");var s="number"==typeof i?t.NetworkChainIdMap[i]:i;t.assert(t.isSupportedNetwork(s),t.unsupportedChainError),this.network=s,this.internal=new N({apiKey:r,network:s,env:null==o?void 0:o.env,iframeUrl:null==o?void 0:o.iframeUrl,face:this}),this.auth=new l(this.internal),this.wc=new B(this.internal),this.solana=new y(this.internal),this.near=new w(this.internal),this.wallet=new R(this.internal),this.bora=new p(this.internal),this.aptos=new f(this.internal)}return e.prototype.ready=function(){return u(this,void 0,void 0,(function(){return h(this,(function(t){return[2,this.internal.ready()]}))}))},e.prototype.getEthLikeProvider=function(){return t.assert(t.isEthlikeBlockchain(t.networkToBlockchain(this.network)),t.unsupportedChainError),new _(this.internal)},e.prototype.switchNetwork=function(e){return u(this,void 0,void 0,(function(){var n;return h(this,(function(r){return n="number"==typeof e?t.NetworkChainIdMap[e]:e,t.assertArgument(e,t.isSupportedNetwork(n),"network"),[2,this.internal.switchNetwork(n)]}))}))},e}();Object.defineProperty(exports,"Network",{enumerable:!0,get:function(){return t.Network}}),exports.Face=T;
//# sourceMappingURL=index.js.map

@@ -13,3 +13,3 @@ import { Blockchain, Network } from '@haechi-labs/face-types';

apiKey: string;
network?: Network;
network?: Network | number;
}

@@ -33,4 +33,4 @@ export declare class Face {

getChainId: () => Promise<number>;
switchNetwork(network: Network): Promise<unknown>;
switchNetwork(network: Network | number): Promise<unknown>;
}
//# sourceMappingURL=face.d.ts.map

@@ -19,3 +19,3 @@ import { Blockchain, BoraPortalConnectRequest, BoraPortalConnectStatusResponse, Env, FaceIdTokenResponse, FaceLoginResponse, HomeOptions, JsonRpcRequestPayload, JsonRpcResponsePayload, LoginProviderType, LoginWithIdTokenRequest } from '@haechi-labs/face-types';

getAddresses(blockchain?: Blockchain): Promise<string[]>;
estimateGas(request: JsonRpcRequestPayload): Promise<unknown>;
estimateGas(request: JsonRpcRequestPayload): Promise<number>;
getBalance(address: string, contractAddress?: string): Promise<BigNumber>;

@@ -22,0 +22,0 @@ ownerOf(contractAddress: string, tokenId: string): Promise<string>;

@@ -13,3 +13,3 @@ import { Blockchain, Network } from '@haechi-labs/face-types';

apiKey: string;
network?: Network;
network?: Network | number;
}

@@ -33,4 +33,4 @@ export declare class Face {

getChainId: () => Promise<number>;
switchNetwork(network: Network): Promise<unknown>;
switchNetwork(network: Network | number): Promise<unknown>;
}
//# sourceMappingURL=face.d.ts.map

@@ -19,3 +19,3 @@ import { Blockchain, BoraPortalConnectRequest, BoraPortalConnectStatusResponse, Env, FaceIdTokenResponse, FaceLoginResponse, HomeOptions, JsonRpcRequestPayload, JsonRpcResponsePayload, LoginProviderType, LoginWithIdTokenRequest } from '@haechi-labs/face-types';

getAddresses(blockchain?: Blockchain): Promise<string[]>;
estimateGas(request: JsonRpcRequestPayload): Promise<unknown>;
estimateGas(request: JsonRpcRequestPayload): Promise<number>;
getBalance(address: string, contractAddress?: string): Promise<BigNumber>;

@@ -22,0 +22,0 @@ ownerOf(contractAddress: string, tokenId: string): Promise<string>;

@@ -42,3 +42,3 @@ import { Blockchain, Env, JsonRpcRequestPayload, FaceLoginResponse, LoginProviderType, FaceIdTokenResponse, LoginWithIdTokenRequest, HomeOptions, JsonRpcResponsePayload, Network, BoraPortalConnectStatusResponse, BoraPortalConnectRequest } from '@haechi-labs/face-types';

getAddresses(blockchain?: Blockchain): Promise<string[]>;
estimateGas(request: JsonRpcRequestPayload): Promise<unknown>;
estimateGas(request: JsonRpcRequestPayload): Promise<number>;
getBalance(address: string, contractAddress?: string): Promise<BigNumber>;

@@ -160,3 +160,3 @@ ownerOf(contractAddress: string, tokenId: string): Promise<string>;

apiKey: string;
network?: Network;
network?: Network | number;
}

@@ -180,5 +180,5 @@ declare class Face {

getChainId: () => Promise<number>;
switchNetwork(network: Network): Promise<unknown>;
switchNetwork(network: Network | number): Promise<unknown>;
}
export { Face, FaceConfig };
{
"name": "@haechi-labs/face-sdk",
"version": "1.9.3",
"version": "1.9.4-alpha.0",
"description": "",

@@ -23,3 +23,4 @@ "license": "ISC",

"build:watch": "rollup -c -w",
"dev": "yarn run build:watch"
"dev": "yarn run build:watch",
"test": "jest"
},

@@ -32,3 +33,3 @@ "dependencies": {

"devDependencies": {
"@haechi-labs/face-types": "^1.9.3",
"@haechi-labs/face-types": "^1.9.4-alpha.0",
"@rollup/plugin-commonjs": "^24.0.1",

@@ -38,4 +39,7 @@ "@rollup/plugin-json": "^6.0.0",

"@tsconfig/node16": "^1.0.2",
"@types/jest": "^29.4.1",
"@types/node": "^17.0.33",
"ethers": "^5.6.8",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"rollup": "^2.78.0",

@@ -45,2 +49,3 @@ "rollup-plugin-dts": "^5.1.1",

"rollup-plugin-typescript2": "^0.34.1",
"ts-jest": "^29.0.5",
"typescript": "^4.9.5"

@@ -52,3 +57,3 @@ },

},
"gitHead": "1d87b8eb8929bb012dd380867a422dfb05698683",
"gitHead": "0f7550c849d6d3ddd5894e13a58b6b597338ea6a",
"publishConfig": {

@@ -55,0 +60,0 @@ "access": "public"

import {
assertArgument,
FaceIdTokenResponse,

@@ -22,2 +23,4 @@ FaceLoginResponse,

async directSocialLogin(provider: LoginProviderType): Promise<FaceLoginResponse | null> {
assertArgument(provider, typeof provider === 'string', 'provider');
return this.internal.directSocialLogin(provider);

@@ -30,2 +33,5 @@ }

): Promise<FaceIdTokenResponse | null> {
assertArgument(provider, typeof provider === 'string', 'provider');
assertArgument(accessToken, typeof accessToken === 'string', 'accessToken');
return this.internal.getIdToken(provider, accessToken);

@@ -37,2 +43,8 @@ }

): Promise<FaceLoginResponse | null> {
assertArgument(
loginWithIdTokenRequest,
loginWithIdTokenRequest.idToken && loginWithIdTokenRequest.sig,
'loginWithIdTokenRequest'
);
return this.internal.loginWithIdToken(loginWithIdTokenRequest);

@@ -39,0 +51,0 @@ }

@@ -42,2 +42,4 @@ import { Blockchain } from '@haechi-labs/face-types';

async signMultiAgentTransaction(rawTransaction: TxnBuilderTypes.MultiAgentRawTransaction) {
// TODO: rawTransaction 유효성 검사
const result = await this.internal.sendRpc<string>({

@@ -44,0 +46,0 @@ method: 'aptos_signMultiAgentTransaction',

@@ -1,2 +0,6 @@

import { BoraPortalConnectRequest, BoraPortalConnectStatusResponse } from '@haechi-labs/face-types';
import {
assertArgument,
BoraPortalConnectRequest,
BoraPortalConnectStatusResponse,
} from '@haechi-labs/face-types';

@@ -15,2 +19,4 @@ import { Internal } from '../internal';

): Promise<BoraPortalConnectStatusResponse | null> {
assertArgument(request, request.bappUsn && request.signature, 'request');
return await this.internal.boraConnect(request);

@@ -20,4 +26,6 @@ }

async isConnected(bappUsn: string): Promise<BoraPortalConnectStatusResponse | null> {
assertArgument(bappUsn, typeof bappUsn === 'string', 'bappUsn');
return await this.internal.boraIsConnected(bappUsn);
}
}
import {
assertArgument,
Blockchain,

@@ -28,2 +29,5 @@ FaceSolanaNearTransactionPayload,

async getBalance(address: string, contractAddress?: string): Promise<BigNumber> {
assertArgument(address, typeof address === 'string', 'address');
assertArgument(contractAddress, typeof contractAddress === 'string', 'contractAddress', false);
const res = await this.internal.sendRpc({

@@ -38,2 +42,4 @@ method: JsonRpcMethod.near_get_balance,

async signAndSendTransaction(transaction: nearAPI.transactions.Transaction): Promise<string> {
// TODO: transaction 유효성 검사
const txPayload: FaceSolanaNearTransactionPayload = {

@@ -40,0 +46,0 @@ serializedHex: Buffer.from(

@@ -22,2 +22,4 @@ import { Blockchain, FaceSolanaNearTransactionPayload } from '@haechi-labs/face-types';

async signAndSendTransaction(transaction: Transaction): Promise<string> {
// TODO: transaction 유효성 검사
const txPayload: FaceSolanaNearTransactionPayload = {

@@ -24,0 +26,0 @@ serializedHex: transaction

import {
assert,
assertArgument,
Blockchain,

@@ -7,2 +9,3 @@ Env,

Network,
NetworkChainIdMap,
networkToBlockchain,

@@ -26,3 +29,3 @@ unsupportedChainError,

apiKey: string;
network?: Network;
network?: Network | number;
}

@@ -42,12 +45,15 @@

constructor({ apiKey, network, ...rest }: FaceConfig) {
network = network ? network : Network.ETHEREUM;
if (!isSupportedNetwork(network)) {
throw unsupportedChainError();
}
this.network = network;
assertArgument(apiKey, typeof apiKey === 'string', 'apiKey');
assertArgument(network, true, 'network');
const _network: Network =
typeof network === 'number' ? (NetworkChainIdMap[network] as Network) : network!;
assert(isSupportedNetwork(_network), unsupportedChainError);
this.network = _network!;
this.internal = new Internal({
apiKey,
network,
env: (rest as { env?: Env }).env,
iframeUrl: (rest as { iframeUrl?: string }).iframeUrl,
network: _network,
env: (rest as { env?: Env })?.env,
iframeUrl: (rest as { iframeUrl?: string })?.iframeUrl,
face: this,

@@ -69,5 +75,3 @@ });

getEthLikeProvider(): Provider {
if (!isEthlikeBlockchain(networkToBlockchain(this.network))) {
throw unsupportedChainError();
}
assert(isEthlikeBlockchain(networkToBlockchain(this.network)), unsupportedChainError);

@@ -78,2 +82,4 @@ return new Provider(this.internal);

getAddresses = async (blockchain?: Blockchain): Promise<string[]> => {
assertArgument(blockchain, blockchain && Blockchain[blockchain], 'blockchain', false);
return await this.internal.getAddresses(blockchain);

@@ -83,2 +89,4 @@ };

setNetwork = (network: Network) => {
assertArgument(network, isSupportedNetwork(network), 'network');
this.network = network;

@@ -95,5 +103,9 @@ };

async switchNetwork(network: Network) {
return this.internal.switchNetwork(network);
async switchNetwork(network: Network | number) {
const _network: Network =
typeof network === 'number' ? (NetworkChainIdMap[network] as Network) : network!;
assertArgument(network, isSupportedNetwork(_network), 'network');
return this.internal.switchNetwork(_network);
}
}

@@ -58,38 +58,6 @@ import {

// SDK에서 estimateGas를 호출하는 대부분의 경우는 트랜잭션을 보내는 상황에서 ethers가 호출하는 것
// 이 상황에서는 0으로 리턴하고 iframe 안에서 덮어씌우는 게 유저 경험이 더 좋음
async estimateGas(request: JsonRpcRequestPayload) {
await Promise.all(
request.params.map(
async (param: { from: string; to: string; value: string; data?: string }) => {
if (param.from) {
if (param.data) {
const abi = [
'function transfer(address to, uint256 value) public returns (bool success)',
];
const { name, args } = await this.decodeData(param.data, abi).catch(
() => ({} as any)
);
if (args?.to && args?.value) {
const balance = await this.getBalance(param.from, param.to);
const newData = { to: args.to, value: args.value };
if (balance.sub(newData.value).lt(0)) {
newData.value = '0x0';
}
param.data = await this.encodeData(abi, name, [newData.to, newData.value]);
}
} else {
// platform coin
const balance = await this.getBalance(param.from);
if (balance.sub(param.value).lt(0)) {
param.value = '0x0';
}
}
}
}
)
);
return await this.sendRpc(request).catch(() => DEFAULT_ETH_GAS_PRICE);
return 0;
}

@@ -219,6 +187,7 @@

await this.iframe.sendChildMessage({
const requestId = await this.iframe.sendChildMessage({
method: JsonRpcMethod.face_openWalletConnect,
params: [name, url],
});
return await this.iframe.waitForResponse<void>(requestId);
}

@@ -231,3 +200,2 @@

Blockchain.NEAR,
Blockchain.MEVERSE,
]);

@@ -246,6 +214,7 @@

await this.iframe.sendChildMessage({
const requestId = await this.iframe.sendChildMessage({
method: JsonRpcMethod.face_openHome,
params: [options],
});
return this.iframe.waitForResponse(requestId);
}

@@ -252,0 +221,0 @@

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

import { HomeOptions } from '@haechi-labs/face-types';
import { assertArgument, HomeOptions } from '@haechi-labs/face-types';

@@ -20,5 +20,3 @@ import { Internal } from './internal';

async home(options?: HomeOptions) {
if (options?.networks?.length === 0) {
throw new Error("The 'networks' should select at least one network.");
}
assertArgument(options?.networks, options?.networks?.length, 'options.networks', false);

@@ -25,0 +23,0 @@ return this.internal.openHome(options);

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

import { assertArgument } from '@haechi-labs/face-types';
import { Internal } from './internal';

@@ -11,2 +13,4 @@

async connectOpensea(collectionName?: string): Promise<void> {
assertArgument(collectionName, typeof collectionName === 'string', 'collectionName', false);
await this.connect(

@@ -20,4 +24,7 @@ 'OpenSea',

private async connect(name: string, url: string) {
assertArgument(name, typeof name === 'string', 'name');
assertArgument(url, typeof url === 'string', 'url');
await this.internal.openWalletConnect(name, url);
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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