From 47049ba77ef8fa25f6a2b45986b4b03b82b0853a Mon Sep 17 00:00:00 2001 From: Yeferson Licet Date: Fri, 4 Oct 2024 18:02:13 -0300 Subject: [PATCH] Build new nonce support --- android/lib/src/main/res/raw/trust_min.js | 2 +- packages/ios-web3-provider/swift/trust-min.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/android/lib/src/main/res/raw/trust_min.js b/android/lib/src/main/res/raw/trust_min.js index a5a4d5f5..e970975b 100644 --- a/android/lib/src/main/res/raw/trust_min.js +++ b/android/lib/src/main/res/raw/trust_min.js @@ -31,4 +31,4 @@ address: `+r),e.application&&(n+=` application: `+i),e.chainId&&(n+=` chainId: `+this.chainId),n+=` message: `+e.message,n+=` -nonce: `+e.nonce;const s=ie.Buffer.from(n),o=Xc.bufferToHex(s);return this.request({method:"signMessage",params:{data:o}}).then(a=>({address:r,application:i,chainId:this.chainId,fullMessage:n,message:e.message,nonce:e.nonce,prefix:t,signature:a}))}async signAndSubmitTransaction(e){const t=await this.signTransaction(e),r=await this.request({method:"sendTransaction",params:{tx:t}});return{hash:Xc.messageToBuffer(r).toString()}}async signTransaction(e){const t=await this.request({method:"signTransaction",params:{data:e}});return JSON.parse(Xc.messageToBuffer(t).toString())}};let IE=Xc;IE.NETWORK="aptos";var YM=Object.defineProperty,XM=Object.defineProperties,JM=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,RE=Object.prototype.hasOwnProperty,TE=Object.prototype.propertyIsEnumerable,kE=(e,t,r)=>t in e?YM(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,$p=(e,t)=>{for(var r in t||(t={}))RE.call(t,r)&&kE(e,r,t[r]);if(Al)for(var r of Al(t))TE.call(t,r)&&kE(e,r,t[r]);return e},QM=(e,t)=>XM(e,JM(t)),eN=(e,t)=>{var r={};for(var n in e)RE.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&Al)for(var n of Al(e))t.indexOf(n)<0&&TE.call(e,n)&&(r[n]=e[n]);return r};class Op{constructor(t){this.provider=t}static mapToCamelCase(t){return $p($p({},t),t!=null&&t.messages?{messages:(t?.messages||[]).map(r=>{var n=r,{state_init:i}=n,s=eN(n,["state_init"]);return QM($p({},s),{stateInit:i})})}:{})}async request(t,r){switch(t){case"tonConnect_connect":{const i=await this.provider.internalRequest("requestAccounts",r);return JSON.parse(i)}case"tonConnect_reconnect":{const i=await this.provider.internalRequest("tonConnect_reconnect",r);return JSON.parse(i)}case"ton_rawSign":return this.provider.internalRequest("signMessage",r);case"ton_sendTransaction":case"tonConnect_sendTransaction":const n=await this.provider.internalRequest("signTransaction",Op.mapToCamelCase(r[0]));return parseInt(n,10);case"ton_requestAccounts":{const i=await this.provider.internalRequest("requestAccounts",r),[{nonBounceable:s}]=JSON.parse(i);return[s]}case"ton_requestWallets":{const i=await this.provider.internalRequest("requestAccounts",r),[{nonBounceable:s,publicKey:o}]=JSON.parse(i);return[{address:s,publicKey:o,version:this.provider.version}]}default:return this.provider.internalRequest(t,r)}}}const CE=class extends sf{constructor(e){super(),this.version="v4R2",e&&e.version&&(this.version=e.version),e!=null&&e.disableMobileAdapter||(this.mobileAdapter=new Op(this))}disconnect(){return this.send("tonConnect_disconnect",{})}isConnected(){return Promise.resolve(!0)}async send(e,t){const r=()=>this.internalRequest(e,t);return this.mobileAdapter?await this.mobileAdapter.request(e,t):await r()}internalRequest(e,t){return super.request({method:e,params:t})}getNetwork(){return CE.NETWORK}};let LE=CE;LE.NETWORK="ton";class Mp extends Error{constructor(t,r){super(t),this.code=r}}const $E=e=>{var t;return{event:"connect_error",payload:{code:(t=e.code)!=null?t:0,message:e.message}}};class tN{constructor(t,r){this.protocolVersion=2,this.isWalletBrowser=!0,this.callbacks=[],this.listen=n=>(this.callbacks.push(n),()=>{this.callbacks=this.callbacks.filter(i=>i!=n)}),t&&(typeof t.isWalletBrowser<"u"&&(this.isWalletBrowser=t.isWalletBrowser),t.walletInfo&&(this.walletInfo=t.walletInfo),t.deviceInfo&&(this.deviceInfo=t.deviceInfo)),this.provider=r}async connect(t,r){t>this.protocolVersion&&new Mp("Unsupported protocol version",1);const n=await this.provider.send("tonConnect_connect",r);return this.emit({event:"connect",payload:{items:n,device:this.deviceInfo}})}async disconnect(){return await this.provider.send("tonConnect_disconnect",{}),this.emit({event:"disconnect",payload:{}})}emit(t){return this.callbacks.forEach(r=>r(t)),t}async restoreConnection(){var t;try{const r=await this.provider.send("tonConnect_reconnect",[{name:"ton_addr"}]);return this.emit({event:"connect",payload:{items:r,device:this.deviceInfo}})}catch(r){return r instanceof Mp?this.emit($E(r)):this.emit($E(new Mp((t=r.message)!=null?t:"Unknown error")))}}async send(t){try{return{result:await this.provider.send(`tonConnect_${t.method}`,t.params.map(r=>JSON.parse(r))),id:t.id.toString()}}catch(r){return{error:r,id:String(t.id)}}}}const rN=(e,t)=>new nx({strategy:e,handler:t}),nN=e=>new K1(e),iN=e=>new gE(e),sN=e=>new hE(e),oN=e=>new IE(e),aN=e=>new LE(e),cN=(e,t)=>new tN(e,t);window.trustwallet={core:rN,solana:nN,cosmos:iN,ethereum:sN,aptos:oN,ton:aN,tonBridge:cN}}); +nonce: `+e.nonce;const s=ie.Buffer.from(n),o=Xc.bufferToHex(s);return this.request({method:"signMessage",params:{data:o}}).then(a=>({address:r,application:i,chainId:this.chainId,fullMessage:n,message:e.message,nonce:e.nonce,prefix:t,signature:a}))}async signAndSubmitTransaction(e){const t=await this.signTransaction(e),r=await this.request({method:"sendTransaction",params:{tx:t}});return{hash:Xc.messageToBuffer(r).toString()}}async signTransaction(e){const t=await this.request({method:"signTransaction",params:{data:e}});return JSON.parse(Xc.messageToBuffer(t).toString())}};let IE=Xc;IE.NETWORK="aptos";var YM=Object.defineProperty,XM=Object.defineProperties,JM=Object.getOwnPropertyDescriptors,Al=Object.getOwnPropertySymbols,RE=Object.prototype.hasOwnProperty,TE=Object.prototype.propertyIsEnumerable,kE=(e,t,r)=>t in e?YM(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,$p=(e,t)=>{for(var r in t||(t={}))RE.call(t,r)&&kE(e,r,t[r]);if(Al)for(var r of Al(t))TE.call(t,r)&&kE(e,r,t[r]);return e},QM=(e,t)=>XM(e,JM(t)),eN=(e,t)=>{var r={};for(var n in e)RE.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&Al)for(var n of Al(e))t.indexOf(n)<0&&TE.call(e,n)&&(r[n]=e[n]);return r};class Op{constructor(t){this.provider=t}static mapToCamelCase(t){return $p($p({},t),t!=null&&t.messages?{messages:(t?.messages||[]).map(r=>{var n=r,{state_init:i}=n,s=eN(n,["state_init"]);return QM($p({},s),{stateInit:i})})}:{})}async request(t,r){switch(t){case"tonConnect_connect":{const o=await this.provider.internalRequest("requestAccounts",r);return JSON.parse(o)}case"tonConnect_reconnect":{const o=await this.provider.internalRequest("tonConnect_reconnect",r);return JSON.parse(o)}case"ton_rawSign":return this.provider.internalRequest("signMessage",r);case"ton_sendTransaction":case"tonConnect_sendTransaction":const n=await this.provider.internalRequest("signTransaction",Op.mapToCamelCase(r[0])),{nonce:i,hash:s}=JSON.parse(n);return t==="ton_sendTransaction"?i:s;case"ton_requestAccounts":{const o=await this.provider.internalRequest("requestAccounts",r),[{nonBounceable:a}]=JSON.parse(o);return[a]}case"ton_requestWallets":{const o=await this.provider.internalRequest("requestAccounts",r),[{nonBounceable:a,publicKey:c}]=JSON.parse(o);return[{address:a,publicKey:c,version:this.provider.version}]}default:return this.provider.internalRequest(t,r)}}}const CE=class extends sf{constructor(e){super(),this.version="v4R2",e&&e.version&&(this.version=e.version),e!=null&&e.disableMobileAdapter||(this.mobileAdapter=new Op(this))}disconnect(){return this.send("tonConnect_disconnect",{})}isConnected(){return Promise.resolve(!0)}async send(e,t){const r=()=>this.internalRequest(e,t);return this.mobileAdapter?await this.mobileAdapter.request(e,t):await r()}internalRequest(e,t){return super.request({method:e,params:t})}getNetwork(){return CE.NETWORK}};let LE=CE;LE.NETWORK="ton";class Mp extends Error{constructor(t,r){super(t),this.code=r}}const $E=e=>{var t;return{event:"connect_error",payload:{code:(t=e.code)!=null?t:0,message:e.message}}};class tN{constructor(t,r){this.protocolVersion=2,this.isWalletBrowser=!0,this.callbacks=[],this.listen=n=>(this.callbacks.push(n),()=>{this.callbacks=this.callbacks.filter(i=>i!=n)}),t&&(typeof t.isWalletBrowser<"u"&&(this.isWalletBrowser=t.isWalletBrowser),t.walletInfo&&(this.walletInfo=t.walletInfo),t.deviceInfo&&(this.deviceInfo=t.deviceInfo)),this.provider=r}async connect(t,r){t>this.protocolVersion&&new Mp("Unsupported protocol version",1);const n=await this.provider.send("tonConnect_connect",r);return this.emit({event:"connect",payload:{items:n,device:this.deviceInfo}})}async disconnect(){return await this.provider.send("tonConnect_disconnect",{}),this.emit({event:"disconnect",payload:{}})}emit(t){return this.callbacks.forEach(r=>r(t)),t}async restoreConnection(){var t;try{const r=await this.provider.send("tonConnect_reconnect",[{name:"ton_addr"}]);return this.emit({event:"connect",payload:{items:r,device:this.deviceInfo}})}catch(r){return r instanceof Mp?this.emit($E(r)):this.emit($E(new Mp((t=r.message)!=null?t:"Unknown error")))}}async send(t){try{return{result:await this.provider.send(`tonConnect_${t.method}`,t.params.map(r=>JSON.parse(r))),id:t.id.toString()}}catch(r){return{error:r,id:String(t.id)}}}}const rN=(e,t)=>new nx({strategy:e,handler:t}),nN=e=>new K1(e),iN=e=>new gE(e),sN=e=>new hE(e),oN=e=>new IE(e),aN=e=>new LE(e),cN=(e,t)=>new tN(e,t);window.trustwallet={core:rN,solana:nN,cosmos:iN,ethereum:sN,aptos:oN,ton:aN,tonBridge:cN}}); diff --git a/packages/ios-web3-provider/swift/trust-min.js b/packages/ios-web3-provider/swift/trust-min.js index f987ab7a..52f87abf 100644 --- a/packages/ios-web3-provider/swift/trust-min.js +++ b/packages/ios-web3-provider/swift/trust-min.js @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c33a5fb09ea593ed3a5b5126671447dce7a21952274fdc83f285cdbd732870ae -size 678407 +oid sha256:6c79dcf0c35185e2eb0c76af76c664661e291abf0b2c85285af15f01ec32ed10 +size 678453