@quirks/core
Version:
2 lines (1 loc) • 5.11 kB
JavaScript
;var h=Object.create;var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var f=Object.getPrototypeOf,p=Object.prototype.hasOwnProperty;var A=(r,e,s,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of m(e))!p.call(r,n)&&n!==s&&l(r,n,{get:()=>e[n],enumerable:!(t=y(e,n))||t.enumerable});return r};var b=(r,e,s)=>(s=r!=null?h(f(r)):{},A(e||!r||!r.__esModule?l(s,"default",{value:r,enumerable:!0}):s,r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("./index2.cjs"),a=require("base64-js"),g=require("./index6.cjs"),c=require("./index8.cjs");class I extends v.Wallet{constructor(e){super(e),this.injected=!0}async init(e){const s=(await import("@walletconnect/universal-provider")).UniversalProvider;try{return this.client=await s.init(e),this.client&&this.addListeners(),this.client}catch(t){this.injectionError=t}}removeListeners(){if(super.removeListeners(),this.client)for(const e of this.wcEventNames)this.client.removeListener(e,()=>{})}addListeners(){if(this.removeListeners(),this.client){for(const e of this.wcEventNames)this.client.on(e,s=>{this.events.emit(e,s),e==="accountsChanged"&&this.events.emit("keystorechange")});this.events.on("display_uri",e=>{this.pairingURI=e})}}async generateURI(e){return c.assertIsDefined(this.client,"client is undefined"),this.client.connect({...e})}async enable(){console.debug("enable method not implemented")}async disable(){c.assertIsDefined(this.client,"client is undefined"),this.client.session&&await this.client.disconnect(),await this.client.cleanupPendingPairings()}async getAccount(e){var i,d;c.assertIsDefined(this.client,"client is undefined");const s=(d=(i=this.client.session)==null?void 0:i.namespaces)==null?void 0:d.cosmos,t=s==null?void 0:s.accounts.map(o=>o.split(":")).find(([,o])=>o===e);let n="";return t&&(n=t.pop()??""),{name:"",pubKey:null,address:null,bech32Address:n??"",algo:"unknown",isKeystone:null,isNanoLedger:null}}async getAccounts(e){c.assertIsDefined(this.client,"client is undefined");const s=[];for(const t of e){const n=await this.getAccount(t);s.push(n)}return s}async getSignerAccounts(){var t,n;return c.assertIsDefined(this.client,"client is undefined"),(n=(t=this.client.session)==null?void 0:t.sessionProperties)!=null&&n.keys?JSON.parse(this.client.session.sessionProperties.keys).map(o=>({address:o.bech32Address,algo:o.algo,pubkey:a.toByteArray(o.pubKey)})):(await this.client.request({method:"cosmos_getAccounts"})).map(i=>({address:i.address,algo:i.algo,pubkey:a.toByteArray(i.pubkey)}))}async getOfflineSigner(e){return c.assertIsDefined(this.client,"client is undefined"),{getAccounts:async()=>this.getSignerAccounts(),signAmino:(s,t)=>this.signAmino(e,s,t),signDirect:(s,t)=>this.signDirect(e,s,t)}}async getOfflineSignerOnlyAmino(e){return c.assertIsDefined(this.client,"client is undefined"),{getAccounts:async()=>this.getSignerAccounts(),signAmino:(s,t)=>this.signAmino(e,s,t)}}async getOfflineSignerAuto(e){return c.assertIsDefined(this.client,"client is undefined"),{getAccounts:async()=>this.getSignerAccounts(),signAmino:(s,t)=>this.signAmino(e,s,t),signDirect:(s,t)=>this.signDirect(e,s,t)}}async signAmino(e,s,t){return c.assertIsDefined(this.client,"client is undefined"),this.client.request({method:"cosmos_signAmino",params:{signerAddress:s,signDoc:t}},`cosmos:${e}`)}async signDirect(e,s,t){c.assertIsDefined(this.client,"client is undefined");const n={signerAddress:s,signDoc:{chainId:t.chainId,bodyBytes:a.fromByteArray(t.bodyBytes),authInfoBytes:a.fromByteArray(t.authInfoBytes),accountNumber:t.accountNumber.toString()}},i=await this.client.request({method:"cosmos_signDirect",params:n},`cosmos:${e}`);return{...i,signed:{chainId:i.signed.chainId,accountNumber:BigInt(i.signed.accountNumber),authInfoBytes:a.toByteArray(i.signed.authInfoBytes),bodyBytes:a.toByteArray(i.signed.bodyBytes)}}}async signArbitrary(e,s,t){return c.assertIsDefined(this.client,"client is undefined"),{...(await this.client.request({method:"cosmos_signAmino",params:{signerAddress:s,signDoc:{chain_id:"",account_number:"0",sequence:"0",fee:{gas:"0",amount:[]},msgs:[{type:"sign/MsgSignData",value:{signer:s,data:typeof t=="string"?btoa(t):a.fromByteArray(t)}}],memo:""}}},`cosmos:${e}`)).signature}}async verifyArbitrary(){throw new Error("[Quirks]: Method not implemented.")}async suggestTokens(){console.debug("suggestTokens method not implemented.")}async suggestChains(){console.debug("suggestChains method not implemented.")}get wcEventNames(){return[...Object.keys(g.WcEventTypes),...Object.keys(g.WcProviderEventType)]}get deeplinks(){var t,n,i,d,o,u;const{mobile:e,wallet_connect:s}=this.options;if(!(!e||!s))return{ios:`${(t=e.ios)==null?void 0:t.schema}://${(i=(n=s.deeplink)==null?void 0:n.path)==null?void 0:i.ios}`,android:`${(d=e.android)==null?void 0:d.schema}://${(u=(o=s.deeplink)==null?void 0:o.path)==null?void 0:u.android}`}}get pairingDeeplinks(){if(this.deeplinks)return{ios:`${this.deeplinks.ios}?${this.pairingURI}`,android:`${this.deeplinks.android}?${this.pairingURI}`}}}exports.WCWallet=I;