@idosgames/wallet 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/dist/{bridge-BSTHFExV.d.ts → bridge-CcNWVuIE.d.ts} +1 -1
- package/dist/{bridge-f3pZbjqs.d.cts → bridge-ZHrosWG-.d.cts} +1 -1
- package/dist/{types-CeUVf1tr.d.cts → chains-B2jQ-L0B.d.cts} +64 -1
- package/dist/{types-CeUVf1tr.d.ts → chains-B2jQ-L0B.d.ts} +64 -1
- package/dist/chunk-D2ZPJ33L.js +1 -0
- package/dist/chunk-K3THMWU2.js +2 -0
- package/dist/chunk-MLIXKTS6.js +1 -0
- package/dist/chunk-XJV2C5QX.js +1 -0
- package/dist/{chunk-FFBRTCQK.js → chunk-YTTVLBAW.js} +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.d.cts +8 -90
- package/dist/index.d.ts +8 -90
- package/dist/index.js +1 -1
- package/dist/platformWalletLogin-DNC2Ajle.d.ts +106 -0
- package/dist/platformWalletLogin-Ysdf-Tt8.d.cts +106 -0
- package/dist/react/index.cjs +2 -2
- package/dist/react/index.d.cts +3 -3
- package/dist/react/index.d.ts +3 -3
- package/dist/react/index.js +1 -1
- package/dist/react/lazyIndex.cjs +2 -2
- package/dist/react/lazyIndex.d.cts +7 -4
- package/dist/react/lazyIndex.d.ts +7 -4
- package/dist/react/lazyIndex.js +1 -1
- package/dist/react/solanaIndex.cjs +2 -2
- package/dist/react/solanaIndex.d.cts +46 -13
- package/dist/react/solanaIndex.d.ts +46 -13
- package/dist/react/solanaIndex.js +1 -1
- package/dist/{withdraw-BKVcklPB.d.ts → withdraw-BPbJQVNt.d.ts} +1 -1
- package/dist/{withdraw-C5y67V7i.d.cts → withdraw-DttqktSS.d.cts} +1 -1
- package/package.json +11 -1
- package/dist/chains-B_P3u8_S.d.cts +0 -64
- package/dist/chains-B_P3u8_S.d.ts +0 -64
- package/dist/chunk-3VONNSCN.js +0 -1
- package/dist/chunk-IEWZH6XD.js +0 -2
- package/dist/chunk-QST6UVX7.js +0 -1
- package/dist/chunk-UMGI2JW7.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import {b,a as a$1,c,d}from'../chunk-QST6UVX7.js';import {a,c as c$2,b as b$2}from'../chunk-UMGI2JW7.js';import {u,b as b$1,c as c$1}from'../chunk-IEWZH6XD.js';export{v as solanaDevnet,u as solanaMainnet}from'../chunk-IEWZH6XD.js';import {SolanaAdapter}from'@reown/appkit-adapter-solana';import {createAppKit,useAppKitAccount,useAppKitProvider}from'@reown/appkit/react';import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';function ee(e){let{walletConnectProjectId:o,appName:n,appUrl:r,appIcon:a$1,wallets:t}=e,u$1=e.networks??[u],i=r??(typeof window<"u"?window.location.origin:""),s={name:n??"iDosGames",description:n??"iDosGames game",url:i,icons:a$1?[a$1]:[]},l=new SolanaAdapter(t?{wallets:t}:{});return a(createAppKit({adapters:[l],networks:u$1,projectId:o,metadata:s,features:{analytics:false,email:false,socials:false}})),l}var F="Wallet not connected.";function oe(e,o,n){let{address:r}=useAppKitAccount(),{walletProvider:a}=useAppKitProvider("solana"),t=r??null,u=a?.signMessage?.bind(a);return {connected:!!t,account:t,loginWithWallet:(i,s)=>{let l=s??t;return l?u?c({client:e,networkID:i,walletAddress:l,signMessage:u}):Promise.resolve(c$1("sign","The connected wallet does not support message signing.")):Promise.resolve(c$1("challenge",F))},depositToken:i=>a$1({client:e,adapter:n,titleID:o,...i}),withdrawToken:i=>{let s=i.walletAddress??t;return s?b({client:e,adapter:n,...i,walletAddress:s}):Promise.resolve(b$1("request",F))}}}var ie=18e4,H=9e4;function se(e){try{let n=e?.session?.peer?.metadata?.redirect,r=n?.native||n?.universal;return !r||typeof window>"u"?!1:(window.location.href=r,!0)}catch{return false}}function J(e,o){return new Promise((n,r)=>{let a=setTimeout(()=>r(new Error("The wallet request timed out.")),o);e.then(t=>{clearTimeout(a),n(t);},t=>{clearTimeout(a),r(t instanceof Error?t:new Error(String(t)));});})}function le(e){let o="Wallet sign-in failed. Please try again.";return e instanceof Error?/user (rejected|denied|cancelled|canceled)|rejected the request/i.test(e.message)?"Request declined in the wallet.":/timed? ?out/i.test(e.message)?"The wallet did not respond. Open your wallet and try again.":o:o}function pe(e){let{client:o,networkID:n,onAuthenticated:r,disabled:a,label:t,style:u,autoStart:i,mode:s="login",onLinked:l}=e,{address:c$1,isConnected:w}=useAppKitAccount(),{walletProvider:p}=useAppKitProvider("solana"),[V,g]=useState(false),[E,d$1]=useState(null),[B,W]=useState(false),[L,O]=useState(false),S=useRef(null),M=useRef(0),m=useCallback(()=>{S.current&&clearTimeout(S.current),S.current=null;},[]);useEffect(()=>m,[m]);let h=useRef(false),C=useCallback(async()=>{let k=++M.current,y=()=>M.current===k,v=p?.signMessage?.bind(p);if(!c$1||!v){d$1("The connected wallet cannot sign messages."),g(false);return}g(true),d$1(null);try{if(O(!0),s==="link"){let A=await J(d({client:o,networkID:n,walletAddress:c$1,signMessage:v}),H);if(!y())return;if(A.ok){l?.(A.data.PlayAccess??null);return}d$1(A.stage==="sign"?"Signature declined.":c$2(A.error,"Could not link the wallet."));return}let f=await J(c({client:o,networkID:n,walletAddress:c$1,signMessage:v}),H);if(!y())return;if(f.ok){r();return}d$1(f.stage==="sign"?"Signature declined.":c$2(f.error,"Wallet sign-in failed."));}catch(f){if(!y())return;console.error("[idosgames/wallet] solana sign-in failed:",f),d$1(le(f));}finally{y()&&(g(false),O(false));}},[c$1,p,o,n,r,s,l]),X=useCallback(()=>{se(p)||b$2()?.open();},[p]);useEffect(()=>{!B||!w||!c$1||!p||(W(false),m(),C());},[B,w,c$1,p,C,m]);let G=()=>{if(L){X();return}if(d$1(null),h.current=true,w&&c$1&&p){C();return}let k=b$2();if(!k){d$1("Wallet sign-in is not configured for this title.");return}g(true),W(true),m(),S.current=setTimeout(()=>{W(false),g(false),d$1("No wallet was connected.");},ie),k.open();};return useEffect(()=>{!i||h.current||(h.current=true,G());},[i]),jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:G,disabled:a,style:{...de,...a?{opacity:.6,cursor:"default"}:null,...u},children:L?"Waiting for signature \u2014 tap to open wallet":V?"Check your wallet\u2026":w?t??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),E&&jsx("span",{role:"alert",style:ce,children:E})]})}var de={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ce={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{pe as SolanaWalletLogin,ee as createSolanaWalletConfig,oe as useSolanaBridge};
|
|
1
|
+
import {b,a as a$1,c,d}from'../chunk-MLIXKTS6.js';import {a,c as c$2,b as b$2,d as d$1}from'../chunk-XJV2C5QX.js';import {v,b as b$1,c as c$1,w}from'../chunk-K3THMWU2.js';export{w as solanaDevnet,v as solanaMainnet}from'../chunk-K3THMWU2.js';import {SolanaAdapter}from'@reown/appkit-adapter-solana';import {createAppKit,useAppKitAccount,useAppKitProvider}from'@reown/appkit/react';import {useState,useRef,useCallback,useEffect,useMemo}from'react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {parseUnits}from'viem';import {PublicKey,Connection,Transaction,Ed25519Program,TransactionInstruction,SYSVAR_INSTRUCTIONS_PUBKEY,SystemProgram}from'@solana/web3.js';import {Buffer}from'buffer';var se=new Map;function $(t){let{walletConnectProjectId:e,appName:o,appUrl:r,appIcon:a$1,wallets:n}=t,i=se.get(e);if(i)return i;let p=t.networks??[v],s=r??(typeof window<"u"?window.location.origin:""),l={name:o??"iDosGames",description:o??"iDosGames game",url:s,icons:a$1?[a$1]:[]},c=new SolanaAdapter(n?{wallets:n}:{});return a(createAppKit({adapters:[c],networks:p,projectId:e,metadata:l,features:{analytics:false,email:false,socials:false}})),se.set(e,c),c}var le="Wallet not connected.";function Ie(t,e,o){let{address:r}=useAppKitAccount(),{walletProvider:a}=useAppKitProvider("solana"),n=r??null,i=a?.signMessage?.bind(a);return {connected:!!n,account:n,loginWithWallet:(p,s)=>{let l=s??n;return l?i?c({client:t,networkID:p,walletAddress:l,signMessage:i}):Promise.resolve(c$1("sign","The connected wallet does not support message signing.")):Promise.resolve(c$1("challenge",le))},depositToken:p=>a$1({client:t,adapter:o,titleID:e,...p}),withdrawToken:p=>{let s=p.walletAddress??n;return s?b({client:t,adapter:o,...p,walletAddress:s}):Promise.resolve(b$1("request",le))}}}var Ae=18e4,ce=9e4;function he(t){try{let o=t?.session?.peer?.metadata?.redirect,r=o?.native||o?.universal;return !r||typeof window>"u"?!1:(window.location.href=r,!0)}catch{return false}}function pe(t,e){return new Promise((o,r)=>{let a=setTimeout(()=>r(new Error("The wallet request timed out.")),e);t.then(n=>{clearTimeout(a),o(n);},n=>{clearTimeout(a),r(n instanceof Error?n:new Error(String(n)));});})}function We(t){let e="Wallet sign-in failed. Please try again.";return t instanceof Error?/user (rejected|denied|cancelled|canceled)|rejected the request/i.test(t.message)?"Request declined in the wallet.":/timed? ?out/i.test(t.message)?"The wallet did not respond. Open your wallet and try again.":e:e}function Ee(t){let{client:e,networkID:o,onAuthenticated:r,disabled:a,label:n,style:i,autoStart:p,mode:s="login",onLinked:l}=t,{address:c$1,isConnected:S}=useAppKitAccount(),{walletProvider:u}=useAppKitProvider("solana"),[b,m]=useState(false),[f,g]=useState(null),[y,I]=useState(false),[ee,te]=useState(false),_=useRef(null),ne=useRef(0),C=useCallback(()=>{_.current&&clearTimeout(_.current),_.current=null;},[]);useEffect(()=>C,[C]);let G=useRef(false),F=useCallback(async()=>{let N=++ne.current,R=()=>ne.current===N,H=u?.signMessage?.bind(u);if(!c$1||!H){g("The connected wallet cannot sign messages."),m(false);return}m(true),g(null);try{if(te(!0),s==="link"){let x=await pe(d({client:e,networkID:o,walletAddress:c$1,signMessage:H}),ce);if(!R())return;if(x.ok){l?.(x.data.PlayAccess??null);return}g(x.stage==="sign"?"Signature declined.":c$2(x.error,"Could not link the wallet."));return}let k=await pe(c({client:e,networkID:o,walletAddress:c$1,signMessage:H}),ce);if(!R())return;if(k.ok){r();return}g(k.stage==="sign"?"Signature declined.":c$2(k.error,"Wallet sign-in failed."));}catch(k){if(!R())return;console.error("[idosgames/wallet] solana sign-in failed:",k),g(We(k));}finally{R()&&(m(false),te(false));}},[c$1,u,e,o,r,s,l]),Se=useCallback(()=>{he(u)||b$2()?.open();},[u]);useEffect(()=>{!y||!S||!c$1||!u||(I(false),C(),F());},[y,S,c$1,u,F,C]);let re=()=>{if(ee){Se();return}if(g(null),G.current=true,S&&c$1&&u){F();return}let N=b$2();if(!N){g("Wallet sign-in is not configured for this title.");return}m(true),I(true),C(),_.current=setTimeout(()=>{I(false),m(false),g("No wallet was connected.");},Ae),N.open();};return useEffect(()=>{!p||G.current||(G.current=true,re());},[p]),jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:re,disabled:a,style:{...De,...a?{opacity:.6,cursor:"default"}:null,...i},children:ee?"Waiting for signature \u2014 tap to open wallet":b?"Check your wallet\u2026":S?n??(s==="link"?"Link wallet":"Sign in with wallet"):"Connect wallet"}),f&&jsx("span",{role:"alert",style:Ce,children:f})]})}var De={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},Ce={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};var Ke="e000c6afc62f69cc",ve="b59a5e563e7306ba",Be="d668e18c1bdc33f1",M=new PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"),Le="1nc1nerator11111111111111111111111111111111",de=177,fe=40,ge=4,me=fe+32*ge,Ue=me+8,P=class extends Error{constructor(o,r){super(r);this.code=o;this.name="PlatformPoolError";}code};function U(t){let e=(t??"").replace(/^0x/i,""),o=new Uint8Array(e.length>>1);for(let r=0;r<o.length;r++)o[r]=parseInt(e.slice(r*2,r*2+2),16);return o}function h(t){let e=Buffer.alloc(8);return e.writeBigUInt64LE(BigInt(t||0)),e}function Me(t){let e=Buffer.alloc(8);return e.writeBigInt64LE(BigInt(t||0)),e}function E(t){let e=Buffer.from(t??"","utf8"),o=Buffer.alloc(4);return o.writeUInt32LE(e.length),Buffer.concat([o,e])}function Ge(t){return Buffer.concat([Buffer.from(Ke,"hex"),h(t.amountRaw),E(t.userID),E(t.titleID),E(t.category)])}function Fe(t){let e=t.Splits??[],o=Buffer.alloc(4);return o.writeUInt32LE(e.length),Buffer.concat([Buffer.from(t.Domain==="SPL_DEV"?Be:ve,"hex"),h(t.Amount),h(t.BurnAmount),h(t.Nonce),Me(t.ExpiresAt),o,...e.map(r=>Buffer.concat([Buffer.from(new PublicKey(r.To??"").toBytes()),h(r.Amount)])),E(t.UserID),E(t.TitleID),E(t.Category),Buffer.from([t.SigIxIndex??0])])}function W(t,e,o){return PublicKey.findProgramAddressSync([e.toBuffer(),o.toBuffer(),t.toBuffer()],M)[0]}function He(t,e,o,r,a){return new TransactionInstruction({programId:M,keys:[{pubkey:t,isSigner:true,isWritable:true},{pubkey:e,isSigner:false,isWritable:true},{pubkey:o,isSigner:false,isWritable:false},{pubkey:r,isSigner:false,isWritable:false},{pubkey:SystemProgram.programId,isSigner:false,isWritable:false},{pubkey:a,isSigner:false,isWritable:false}],data:Buffer.from([1])})}function D(t,...e){return PublicKey.findProgramAddressSync(e,t)[0]}function Ve(t){let{programId:e,user:o,mint:r,tokenProgram:a}=t,n=D(e,Buffer.from("vault"));return new TransactionInstruction({programId:e,keys:[{pubkey:D(e,Buffer.from("config")),isSigner:false,isWritable:false},{pubkey:n,isSigner:false,isWritable:true},{pubkey:r,isSigner:false,isWritable:false},{pubkey:o,isSigner:true,isWritable:true},{pubkey:W(r,o,a),isSigner:false,isWritable:true},{pubkey:W(r,n,a),isSigner:false,isWritable:true},{pubkey:a,isSigner:false,isWritable:false},{pubkey:M,isSigner:false,isWritable:false},{pubkey:SystemProgram.programId,isSigner:false,isWritable:false}],data:Ge(t)})}function je(t){let{sig:e,payer:o,tokenProgram:r}=t,a=new PublicKey(e.ProgramID??""),n=new PublicKey(e.Mint??""),i=new PublicKey(e.WalletAddress??""),p=D(a,Buffer.from("vault")),s=new PublicKey(Le),l=(e.Splits??[]).map(m=>new PublicKey(m.To??"")),c=l.map(m=>W(n,m,r)),S=Ed25519Program.createInstructionWithPublicKey({publicKey:U(e.Ed25519PublicKey),message:U(e.Ed25519Message),signature:U(e.SignatureHex)}),u=l.map((m,f)=>He(o,c[f],m,n,r)),b=new TransactionInstruction({programId:a,keys:[{pubkey:D(a,Buffer.from("config")),isSigner:false,isWritable:false},{pubkey:o,isSigner:true,isWritable:true},{pubkey:p,isSigner:false,isWritable:true},{pubkey:D(a,Buffer.from("nonce"),h(e.Nonce)),isSigner:false,isWritable:true},{pubkey:n,isSigner:false,isWritable:false},{pubkey:i,isSigner:false,isWritable:false},{pubkey:W(n,p,r),isSigner:false,isWritable:true},{pubkey:W(n,i,r),isSigner:false,isWritable:true},{pubkey:s,isSigner:false,isWritable:false},{pubkey:W(n,s,r),isSigner:false,isWritable:true},{pubkey:SYSVAR_INSTRUCTIONS_PUBKEY,isSigner:false,isWritable:false},{pubkey:r,isSigner:false,isWritable:false},{pubkey:M,isSigner:false,isWritable:false},{pubkey:SystemProgram.programId,isSigner:false,isWritable:false},...c.map(m=>({pubkey:m,isSigner:false,isWritable:true}))],data:Fe(e)});return [S,...u,b]}function X(t){let{connection:e,signTransaction:o}=t;async function r(n){let i=await e.getAccountInfo(n);if(!i)throw new P("MINT_NOT_FOUND",`mint ${n.toBase58()} not found`);return i.owner}async function a(n,i){let{blockhash:p,lastValidBlockHeight:s}=await e.getLatestBlockhash("confirmed"),l=new Transaction;l.feePayer=n,l.recentBlockhash=p,l.add(...i);let c=await o(l),S=await e.sendRawTransaction(c.serialize());return await e.confirmTransaction({signature:S,blockhash:p,lastValidBlockHeight:s},"confirmed"),S}return {async depositSpl({mint:n,amountRaw:i,userID:p,titleID:s,category:l}){let c=new PublicKey(t.owner),S=new PublicKey(n),u=await r(S);return a(c,[Ve({programId:new PublicKey(t.programId),user:c,mint:S,tokenProgram:u,amountRaw:i,userID:p,titleID:s,category:l})])},async submitWithdrawal(n){if(!n.ProgramID||!n.Mint||!n.WalletAddress)throw new P("BAD_VOUCHER","the voucher has no program, mint or wallet");let i=new PublicKey(t.owner),p=new PublicKey(n.ProgramID),s=await e.getAccountInfo(D(p,Buffer.from("config")));if(!s)throw new P("POOL_NOT_ON_THIS_CLUSTER","the pool's config account is not on this cluster");if(s.data.length!==de)throw new P("POOL_NOT_MIGRATED",`config is ${s.data.length} bytes, expected ${de} (migrate_config not run)`);let l=Buffer.from(s.data);if(l[Ue]===1)throw new P("POOL_PAUSED","pool withdrawals are paused");let c=l.readBigUInt64LE(me);if(c!==BigInt(n.SignatureEpoch||0))throw new P("VOUCHER_REVOKED",`signature epoch mismatch: voucher ${n.SignatureEpoch}, on-chain ${c}`);let S=Buffer.from(U(n.Ed25519PublicKey)),u=false;for(let m=0;m<ge;m++){let f=fe+m*32;S.equals(l.subarray(f,f+32))&&(u=true);}if(!u)throw new P("SIGNER_NOT_TRUSTED","the voucher's signer is not in the pool's server_pubkeys");let b=await r(new PublicKey(n.Mint));return a(i,je({sig:n,payer:i,tokenProgram:b}))}}}var Xe=103;function et(t){return (t.ChainID===Xe?w:v).rpcUrls.default.http[0]}function tt(t){let{client:e,walletConnectProjectId:o,appName:r,onClose:a,style:n}=t,[i,p]=useState(o??"");useEffect(()=>{if(o)return;let f=true;return (async()=>{let g=await e.blockchain.getDefinitions();if(!f||!g.ok)return;let y=g.data.Blockchain?.WalletLogin?.WalletConnectProjectId;y&&p(y);})(),()=>{f=false;}},[e,o]);let s=useMemo(()=>i?($({walletConnectProjectId:i,appName:r}),true):false,[i,r]),{address:l,isConnected:c}=useAppKitAccount(),{walletProvider:S}=useAppKitProvider("solana"),u=c&&l?l:null,b$3=(f,g)=>X({connection:new Connection(et(f),"confirmed"),owner:g,programId:f.RewardPoolAddress??"",signTransaction:async y=>{if(!S)throw new Error("Wallet not connected.");return S.signTransaction(y)}});return jsx(d$1,{client:e,engine:{networkType:"Solana",address:u,connectChoices:s?[{key:"appkit",label:"Connect wallet",connect:()=>{b$2()?.open();}}]:[],disconnect:()=>{b$2()?.disconnect("solana");},deposit:async({network:f,binding:g,amount:y})=>{if(!u)return b$1("deposit-onchain","Wallet not connected.");if(!g.ContractAddress)return b$1("deposit-onchain","This token cannot be deposited.");if(!f.RewardPoolAddress)return b$1("deposit-onchain","POOL_NOT_IN_REGISTRY");let I;try{I=parseUnits(y,g.Decimals??9);}catch{return b$1("deposit-onchain","Invalid amount.")}return a$1({client:e,adapter:b$3(f,u),network:f,mint:g.ContractAddress,amountRaw:I,titleID:e.titleID})},withdraw:async({network:f,networkID:g,currencyID:y,amount:I})=>u?b({client:e,adapter:b$3(f,u),currencyID:y,networkID:g,walletAddress:u,amount:I}):b$1("request","Wallet not connected.")},onClose:a,style:n})}export{P as PlatformPoolError,Ee as SolanaWalletLogin,tt as SolanaWalletPanel,X as createPlatformPoolAdapter,$ as createSolanaWalletConfig,Ie as useSolanaBridge};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicClient, WalletClient, Address, Abi, ContractFunctionName, ContractFunctionArgs, Hex } from 'viem';
|
|
2
2
|
import { IDosGamesClient, BlockchainNetworkDefinition, DepositNFTResponse, DepositTokenResponse, WithdrawalSignatureResponse, NFTWithdrawalResponse, TokenWithdrawalResponse } from '@idosgames/core';
|
|
3
|
-
import { B as BridgeResult } from './
|
|
3
|
+
import { B as BridgeResult } from './chains-B2jQ-L0B.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PublicClient, WalletClient, Address, Abi, ContractFunctionName, ContractFunctionArgs, Hex } from 'viem';
|
|
2
2
|
import { IDosGamesClient, BlockchainNetworkDefinition, DepositNFTResponse, DepositTokenResponse, WithdrawalSignatureResponse, NFTWithdrawalResponse, TokenWithdrawalResponse } from '@idosgames/core';
|
|
3
|
-
import { B as BridgeResult } from './
|
|
3
|
+
import { B as BridgeResult } from './chains-B2jQ-L0B.cjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idosgames/wallet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Wallet-bridge companion to @idosgames/core: connect browser & mobile wallets (EVM via wagmi/viem/WalletConnect, Solana via wallet-adapter) and move tokens/NFTs in and out of the game through client.blockchain.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -78,7 +78,9 @@
|
|
|
78
78
|
"@reown/appkit-adapter-solana": "^1.8.23",
|
|
79
79
|
"@reown/appkit-adapter-wagmi": "^1.8.23",
|
|
80
80
|
"@solana/wallet-adapter-base": "^0.9.27",
|
|
81
|
+
"@solana/web3.js": "^1.98.4",
|
|
81
82
|
"@tanstack/react-query": "^5.101.2",
|
|
83
|
+
"buffer": "^6.0.3",
|
|
82
84
|
"react": "^18.3.1 || ^19.0.0",
|
|
83
85
|
"wagmi": "^3.0.0"
|
|
84
86
|
},
|
|
@@ -103,6 +105,12 @@
|
|
|
103
105
|
},
|
|
104
106
|
"@reown/appkit-adapter-solana": {
|
|
105
107
|
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"@solana/web3.js": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"buffer": {
|
|
113
|
+
"optional": true
|
|
106
114
|
}
|
|
107
115
|
},
|
|
108
116
|
"devDependencies": {
|
|
@@ -111,8 +119,10 @@
|
|
|
111
119
|
"@reown/appkit-adapter-wagmi": "^1.8.23",
|
|
112
120
|
"@solana/wallet-adapter-base": "^0.9.27",
|
|
113
121
|
"@solana/wallet-adapter-react": "^0.15.39",
|
|
122
|
+
"@solana/web3.js": "^1.98.4",
|
|
114
123
|
"@tanstack/react-query": "^5.101.2",
|
|
115
124
|
"@types/react": "^19.2.17",
|
|
125
|
+
"buffer": "^6.0.3",
|
|
116
126
|
"react": "^19.2.7",
|
|
117
127
|
"wagmi": "^3.7.2"
|
|
118
128
|
}
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Chain } from 'viem';
|
|
2
|
-
|
|
3
|
-
declare const mainnet: Chain;
|
|
4
|
-
declare const bsc: Chain;
|
|
5
|
-
declare const polygon: Chain;
|
|
6
|
-
declare const base: Chain;
|
|
7
|
-
declare const arbitrum: Chain;
|
|
8
|
-
declare const optimism: Chain;
|
|
9
|
-
declare const sepolia: Chain;
|
|
10
|
-
declare const polygonAmoy: Chain;
|
|
11
|
-
/** Every chain declared here, keyed by NetworkID-style name — handy for a title-driven picker. */
|
|
12
|
-
declare const idosChains: {
|
|
13
|
-
readonly mainnet: Chain;
|
|
14
|
-
readonly bsc: Chain;
|
|
15
|
-
readonly polygon: Chain;
|
|
16
|
-
readonly base: Chain;
|
|
17
|
-
readonly arbitrum: Chain;
|
|
18
|
-
readonly optimism: Chain;
|
|
19
|
-
readonly sepolia: Chain;
|
|
20
|
-
readonly polygonAmoy: Chain;
|
|
21
|
-
};
|
|
22
|
-
/** Look up a declared chain by its EVM chain id (e.g. from the title's blockchain config). */
|
|
23
|
-
declare function chainById(id: number): Chain | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* A chain in the CAIP shape Reown AppKit expects.
|
|
26
|
-
*
|
|
27
|
-
* AppKit ships its own network list at `@reown/appkit/networks`, but that module is
|
|
28
|
-
* `export * from "viem/chains"` — the very barrel this file exists to avoid. Converting our own
|
|
29
|
-
* chains keeps AppKit working without dragging `tempo`/`ox` (and its BigInt `**`) into the bundle.
|
|
30
|
-
*/
|
|
31
|
-
type AppKitEvmNetwork = Chain & {
|
|
32
|
-
chainNamespace: "eip155";
|
|
33
|
-
caipNetworkId: `eip155:${number}`;
|
|
34
|
-
};
|
|
35
|
-
/** Wraps a chain in the CAIP fields AppKit needs. */
|
|
36
|
-
declare function toAppKitNetwork(chain: Chain): AppKitEvmNetwork;
|
|
37
|
-
interface AppKitSolanaNetwork {
|
|
38
|
-
id: string;
|
|
39
|
-
name: string;
|
|
40
|
-
network: string;
|
|
41
|
-
nativeCurrency: {
|
|
42
|
-
name: string;
|
|
43
|
-
symbol: string;
|
|
44
|
-
decimals: number;
|
|
45
|
-
};
|
|
46
|
-
rpcUrls: {
|
|
47
|
-
default: {
|
|
48
|
-
http: string[];
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
blockExplorers?: {
|
|
52
|
-
default: {
|
|
53
|
-
name: string;
|
|
54
|
-
url: string;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
testnet: boolean;
|
|
58
|
-
chainNamespace: "solana";
|
|
59
|
-
caipNetworkId: `solana:${string}`;
|
|
60
|
-
}
|
|
61
|
-
declare const solanaMainnet: AppKitSolanaNetwork;
|
|
62
|
-
declare const solanaDevnet: AppKitSolanaNetwork;
|
|
63
|
-
|
|
64
|
-
export { type AppKitEvmNetwork as A, type AppKitSolanaNetwork as a, arbitrum as b, base as c, bsc as d, chainById as e, polygonAmoy as f, solanaDevnet as g, solanaMainnet as h, idosChains as i, mainnet as m, optimism as o, polygon as p, sepolia as s, toAppKitNetwork as t };
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { Chain } from 'viem';
|
|
2
|
-
|
|
3
|
-
declare const mainnet: Chain;
|
|
4
|
-
declare const bsc: Chain;
|
|
5
|
-
declare const polygon: Chain;
|
|
6
|
-
declare const base: Chain;
|
|
7
|
-
declare const arbitrum: Chain;
|
|
8
|
-
declare const optimism: Chain;
|
|
9
|
-
declare const sepolia: Chain;
|
|
10
|
-
declare const polygonAmoy: Chain;
|
|
11
|
-
/** Every chain declared here, keyed by NetworkID-style name — handy for a title-driven picker. */
|
|
12
|
-
declare const idosChains: {
|
|
13
|
-
readonly mainnet: Chain;
|
|
14
|
-
readonly bsc: Chain;
|
|
15
|
-
readonly polygon: Chain;
|
|
16
|
-
readonly base: Chain;
|
|
17
|
-
readonly arbitrum: Chain;
|
|
18
|
-
readonly optimism: Chain;
|
|
19
|
-
readonly sepolia: Chain;
|
|
20
|
-
readonly polygonAmoy: Chain;
|
|
21
|
-
};
|
|
22
|
-
/** Look up a declared chain by its EVM chain id (e.g. from the title's blockchain config). */
|
|
23
|
-
declare function chainById(id: number): Chain | undefined;
|
|
24
|
-
/**
|
|
25
|
-
* A chain in the CAIP shape Reown AppKit expects.
|
|
26
|
-
*
|
|
27
|
-
* AppKit ships its own network list at `@reown/appkit/networks`, but that module is
|
|
28
|
-
* `export * from "viem/chains"` — the very barrel this file exists to avoid. Converting our own
|
|
29
|
-
* chains keeps AppKit working without dragging `tempo`/`ox` (and its BigInt `**`) into the bundle.
|
|
30
|
-
*/
|
|
31
|
-
type AppKitEvmNetwork = Chain & {
|
|
32
|
-
chainNamespace: "eip155";
|
|
33
|
-
caipNetworkId: `eip155:${number}`;
|
|
34
|
-
};
|
|
35
|
-
/** Wraps a chain in the CAIP fields AppKit needs. */
|
|
36
|
-
declare function toAppKitNetwork(chain: Chain): AppKitEvmNetwork;
|
|
37
|
-
interface AppKitSolanaNetwork {
|
|
38
|
-
id: string;
|
|
39
|
-
name: string;
|
|
40
|
-
network: string;
|
|
41
|
-
nativeCurrency: {
|
|
42
|
-
name: string;
|
|
43
|
-
symbol: string;
|
|
44
|
-
decimals: number;
|
|
45
|
-
};
|
|
46
|
-
rpcUrls: {
|
|
47
|
-
default: {
|
|
48
|
-
http: string[];
|
|
49
|
-
};
|
|
50
|
-
};
|
|
51
|
-
blockExplorers?: {
|
|
52
|
-
default: {
|
|
53
|
-
name: string;
|
|
54
|
-
url: string;
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
testnet: boolean;
|
|
58
|
-
chainNamespace: "solana";
|
|
59
|
-
caipNetworkId: `solana:${string}`;
|
|
60
|
-
}
|
|
61
|
-
declare const solanaMainnet: AppKitSolanaNetwork;
|
|
62
|
-
declare const solanaDevnet: AppKitSolanaNetwork;
|
|
63
|
-
|
|
64
|
-
export { type AppKitEvmNetwork as A, type AppKitSolanaNetwork as a, arbitrum as b, base as c, bsc as d, chainById as e, polygonAmoy as f, solanaDevnet as g, solanaMainnet as h, idosChains as i, mainnet as m, optimism as o, polygon as p, sepolia as s, toAppKitNetwork as t };
|
package/dist/chunk-3VONNSCN.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {c as c$1}from'./chunk-IEWZH6XD.js';import {isPlatformParentOrigin,PLATFORM_ORIGINS}from'@idosgames/core';var c={addressRequest:"IDOS_PLATFORM_WALLET_ADDRESS_REQUEST",addressResponse:"IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE",signRequest:"IDOS_PLATFORM_WALLET_SIGN_REQUEST",signResponse:"IDOS_PLATFORM_WALLET_SIGN_RESPONSE",ack:"IDOS_PLATFORM_WALLET_ACK"},m="PLATFORM_WALLET_UNAVAILABLE",P=5e3,S=18e4;function T(){let r=[...PLATFORM_ORIGINS],t=window.location.ancestorOrigins?.[0];return t&&!r.includes(t)&&isPlatformParentOrigin(t)&&r.push(t),r}function R(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function L(r,t,i){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:m});let s=window.parent;if(!s)return Promise.resolve({ok:false,error:m});let e=R();return new Promise(f=>{let l=false,a,g=o=>{l||(l=true,window.removeEventListener("message",u),clearTimeout(a),f(o));},u=o=>{if(!isPlatformParentOrigin(o.origin))return;let n=o.data;if(!(!n||n.requestId!==e)){if(n.type===c.ack){clearTimeout(a),a=setTimeout(()=>g({ok:false,error:"TIMEOUT"}),S);return}n.type===t&&g({ok:n.ok===true,error:typeof n.error=="string"?n.error:void 0,address:typeof n.address=="string"?n.address:void 0,signature:typeof n.signature=="string"?n.signature:void 0});}};a=setTimeout(()=>g({ok:false,error:m}),P),window.addEventListener("message",u);for(let o of T())try{s.postMessage({type:r,requestId:e,...i},o);}catch{}})}async function p(r){let{client:t,networkID:i}=r;return k(r,async s=>{let e=await t.auth.requestWalletChallenge(s,i);return e.ok?{ok:true,message:e.data.Message}:{ok:false,error:e.error}},(s,e)=>t.auth.loginWithWallet(s,i,e))}async function E(r){let{client:t,networkID:i}=r;return k(r,async s=>{let e=await t.auth.linkWallet(s,i);return e.ok?e.data.Challenge?{ok:true,message:e.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:e.error}},(s,e)=>t.auth.linkWallet(s,i,e))}async function k(r,t,i){let{client:s,family:e}=r,f=s.titleID,l=await L(c.addressRequest,c.addressResponse,{titleID:f,family:e});if(!l.ok||!l.address)return c$1("challenge",l.error??"NO_WALLET");let a=l.address,g=await t(a);if(!g.ok)return c$1("challenge",g.error);let u=await L(c.signRequest,c.signResponse,{titleID:f,family:e,address:a,message:g.message});if(!u.ok||!u.signature)return c$1("sign",u.error??"SIGN_FAILED");let o=await i(a,u.signature);return o.ok?{ok:true,data:o.data}:c$1("login",o.error)}export{c as a,m as b,p as c,E as d};
|
package/dist/chunk-IEWZH6XD.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import {BaseError}from'viem';import {PLATFORM_ORIGINS}from'@idosgames/core';function x(e){return e instanceof BaseError?e.shortMessage:e instanceof Error?e.message:String(e)}function a(e,t,n){return {ok:false,stage:e,error:t,...n}}function r(e,t){return {ok:false,stage:e,error:t}}var o="WALLET_USE_SITE_PANEL";function k(){if(typeof window>"u")return false;try{return window.self!==window.top}catch{return true}}function L(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function C(e){return a(e,o)}function v(e){return r(e,o)}var l=PLATFORM_ORIGINS;function B(e){if(typeof window>"u")return ()=>{};let t=n=>{l.includes(n.origin)&&n.data?.type==="IDOS_WALLET_BALANCE_CHANGED"&&e();};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)}var p={id:1,name:"Ethereum",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://eth.llamarpc.com"]}},blockExplorers:{default:{name:"Etherscan",url:"https://etherscan.io"}}},c={id:56,name:"BNB Smart Chain",nativeCurrency:{name:"BNB",symbol:"BNB",decimals:18},rpcUrls:{default:{http:["https://bsc-dataseed.binance.org"]}},blockExplorers:{default:{name:"BscScan",url:"https://bscscan.com"}}},u={id:137,name:"Polygon",nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://polygon-rpc.com"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://polygonscan.com"}}},d={id:8453,name:"Base",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.base.org"]}},blockExplorers:{default:{name:"BaseScan",url:"https://basescan.org"}}},m={id:42161,name:"Arbitrum One",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://arb1.arbitrum.io/rpc"]}},blockExplorers:{default:{name:"Arbiscan",url:"https://arbiscan.io"}}},g={id:10,name:"OP Mainnet",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://mainnet.optimism.io"]}},blockExplorers:{default:{name:"Optimistic Etherscan",url:"https://optimistic.etherscan.io"}}},h={id:11155111,name:"Sepolia",testnet:true,nativeCurrency:{name:"Sepolia Ether",symbol:"ETH",decimals:18},rpcUrls:{default:{http:["https://rpc.sepolia.org"]}},blockExplorers:{default:{name:"Etherscan",url:"https://sepolia.etherscan.io"}}},f={id:80002,name:"Polygon Amoy",testnet:true,nativeCurrency:{name:"POL",symbol:"POL",decimals:18},rpcUrls:{default:{http:["https://rpc-amoy.polygon.technology"]}},blockExplorers:{default:{name:"PolygonScan",url:"https://amoy.polygonscan.com"}}},y={mainnet:p,bsc:c,polygon:u,base:d,arbitrum:m,optimism:g,sepolia:h,polygonAmoy:f};function T(e){return Object.values(y).find(t=>t.id===e)}function A(e){return {...e,chainNamespace:"eip155",caipNetworkId:`eip155:${e.id}`}}var F={id:"5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",name:"Solana",network:"solana-mainnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.mainnet-beta.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:false,chainNamespace:"solana",caipNetworkId:"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"},W={id:"EtWTRABZaYq6iMfeYKouRu166VU2xqa1",name:"Solana Devnet",network:"solana-devnet",nativeCurrency:{name:"Solana",symbol:"SOL",decimals:9},rpcUrls:{default:{http:["https://api.devnet.solana.com"]}},blockExplorers:{default:{name:"Solscan",url:"https://solscan.io"}},testnet:true,chainNamespace:"solana",caipNetworkId:"solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1"};
|
|
2
|
-
export{x as a,a as b,r as c,o as d,k as e,L as f,C as g,v as h,B as i,p as j,c as k,u as l,d as m,m as n,g as o,h as p,f as q,y as r,T as s,A as t,F as u,W as v};
|
package/dist/chunk-QST6UVX7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import {e,g,b,a,h,c}from'./chunk-IEWZH6XD.js';import {normalizeBlockchainCategory}from'@idosgames/core';async function T(i){let{client:t,adapter:n,network:s,mint:d,amountRaw:a$1,titleID:l,category:r}=i;if(e())return g("deposit-onchain");let e$1=t.auth.context?.userID;if(!e$1)return b("deposit-onchain","Not logged in.");if(a$1<=0n)return b("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:d,amountRaw:a$1,userID:e$1,titleID:l,category:normalizeBlockchainCategory(r)});}catch(m){return b("deposit-onchain",a(m))}let c=await t.blockchain.depositToken(s.NetworkID??"",u);return c.ok?{ok:true,onChainTxHash:u,data:c.data}:b("report",c.error,{onChainTxHash:u})}async function D(i){let{client:t,adapter:n,currencyID:s,networkID:d,walletAddress:a$1,amount:l,category:r}=i;if(e())return g("request");let e$1=await t.blockchain.requestTokenWithdrawal(s,d,a$1,l,r);if(!e$1.ok)return b("request",e$1.error);let u=e$1.data.SolanaSignature,c=e$1.data.TitleTransactionID??void 0;if(!u)return b("request","Withdrawal response carried no Solana signature.",{titleTransactionID:c});let m;try{m=await n.submitWithdrawal(u);}catch(W){return b("withdraw-onchain",a(W),{titleTransactionID:c})}if(!c)return b("confirm","Missing TitleTransactionID.",{onChainTxHash:m});let w=await t.blockchain.confirmWithdrawal(c,m);return w.ok?{ok:true,onChainTxHash:m,data:e$1.data}:b("confirm",w.error,{onChainTxHash:m,titleTransactionID:c})}async function x(i){let{client:t,networkID:n,walletAddress:s,signMessage:d}=i;if(e())return h("challenge");let a$1=await t.auth.requestWalletChallenge(s,n);if(!a$1.ok)return c("challenge",a$1.error);let l;try{let e=await d(new TextEncoder().encode(a$1.data.Message));l=S(e);}catch(e){return c("sign",a(e))}let r=await t.auth.loginWithWallet(s,n,l);return r.ok?{ok:true,data:r.data}:c("login",r.error)}async function I(i){let{client:t,networkID:n,walletAddress:s,signMessage:d}=i;if(e())return h("challenge");let a$1=await t.auth.linkWallet(s,n);if(!a$1.ok)return c("challenge",a$1.error);if(!a$1.data.Challenge)return c("challenge","No challenge was issued.");let l;try{let e=await d(new TextEncoder().encode(a$1.data.Challenge));l=S(e);}catch(e){return c("sign",a(e))}let r=await t.auth.linkWallet(s,n,l);return r.ok?{ok:true,data:r.data}:c("login",r.error)}function S(i){let t="0x";for(let n of i)t+=n.toString(16).padStart(2,"0");return t}export{T as a,D as b,x as c,I as d};
|
package/dist/chunk-UMGI2JW7.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var t=null;function n(e){t=e;}function r(){return t}function s(e,a){switch(e){case null:case void 0:case "":return a;case "PLAY_ACCESS_WALLET_USED_BY_ANOTHER_ACCOUNT":return "This wallet already plays with another account.";case "WALLET_UNLINK_COOLDOWN":return "This wallet was unlinked from another account less than 7 days ago. Try again after the 7 days.";case "WALLET_CHANGES_TOO_FREQUENT":return "Too many wallets were changed this week. Try again in a few days.";case "PLAY_ACCESS_WALLET_LOGIN_ONLY":return "This game is played with a wallet login only.";case "INVALID_WALLET_SIGNATURE":return "The signature does not match the wallet. Please try again.";case "WALLET_CHALLENGE_EXPIRED":return "The request expired. Please try again.";default:return e}}export{n as a,r as b,s as c};
|