@idosgames/wallet 0.5.2 → 0.6.1

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 CHANGED
@@ -56,6 +56,22 @@ is to pass no `chains` to either. `LazyWalletPanel` takes the authenticated
56
56
  `client` as a prop (like the login button), plus optional `appName` /
57
57
  `onClose` / `style` / `walletConnectProjectId`.
58
58
 
59
+ `LazyWalletPanel` is ONE panel for both chains: it reads the title's networks
60
+ and loads the EVM panel (`WalletPanel`) or the Solana one (`SolanaWalletPanel`,
61
+ `/react/solana`). Both render the same form (`walletPanelView.tsx`: connect,
62
+ network, token, in-game balance, amount, Deposit / Withdraw) — a chain only
63
+ supplies how it connects and moves tokens. On Solana that is Reown AppKit for
64
+ the wallet and `createPlatformPoolAdapter` (`deposit_spl` / `withdraw_spl`
65
+ against the platform pool, `network.RewardPoolAddress` from the engine only);
66
+ transactions go to the title's cluster (ChainID 103 → devnet, else mainnet).
67
+ `createSolanaWalletConfig` is memoised per project id too, so a Solana wallet
68
+ connected at sign-in stays connected in the panel.
69
+
70
+ Inside the idosgames.com frame a game's wallet button calls
71
+ `openPlatformWalletPanel()` (also on `/react/lazy`, with `isEmbeddedInPlatform`
72
+ / `isEmbeddedOnForeignSite`): the site shows its own wallet card — crypto in a
73
+ frame goes through the site only.
74
+
59
75
  Every subpath declares a `browser` export condition pointing at the ESM build.
60
76
  That is load-bearing, not cosmetic: some browser bundlers (CodeSandbox's
61
77
  classic Sandpack bundler among them) rank the `require` condition above
@@ -1,5 +1,5 @@
1
1
  import { SolanaWithdrawalSignature, IDosGamesClient, BlockchainNetworkDefinition, DepositTokenResponse, TokenWithdrawalResponse } from '@idosgames/core';
2
- import { B as BridgeResult } from './types-CeUVf1tr.js';
2
+ import { B as BridgeResult } from './chains-B2jQ-L0B.js';
3
3
 
4
4
  /**
5
5
  * The on-chain half of the Solana bridge, delegated to the title's own program integration.
@@ -1,5 +1,5 @@
1
1
  import { SolanaWithdrawalSignature, IDosGamesClient, BlockchainNetworkDefinition, DepositTokenResponse, TokenWithdrawalResponse } from '@idosgames/core';
2
- import { B as BridgeResult } from './types-CeUVf1tr.cjs';
2
+ import { B as BridgeResult } from './chains-B2jQ-L0B.cjs';
3
3
 
4
4
  /**
5
5
  * The on-chain half of the Solana bridge, delegated to the title's own program integration.
@@ -1,3 +1,5 @@
1
+ import { Chain } from 'viem';
2
+
1
3
  /**
2
4
  * Where a multi-step bridge flow stopped. Deposits run approve → deposit-onchain → report;
3
5
  * withdrawals run request → withdraw-onchain → confirm. Knowing the stage lets a UI recover
@@ -54,4 +56,65 @@ interface WalletLoginFailure {
54
56
  type WalletLoginResult<T> = WalletLoginSuccess<T> | WalletLoginFailure;
55
57
  declare function walletLoginFail(stage: WalletLoginStage, error: string): WalletLoginFailure;
56
58
 
57
- export { type BridgeResult as B, type WalletLoginResult as W, type BridgeFailure as a, type BridgeStage as b, type BridgeSuccess as c, type WalletLoginFailure as d, type WalletLoginStage as e, type WalletLoginSuccess as f, bridgeFail as g, toErrorMessage as t, walletLoginFail as w };
59
+ declare const mainnet: Chain;
60
+ declare const bsc: Chain;
61
+ declare const polygon: Chain;
62
+ declare const base: Chain;
63
+ declare const arbitrum: Chain;
64
+ declare const optimism: Chain;
65
+ declare const sepolia: Chain;
66
+ declare const polygonAmoy: Chain;
67
+ /** Every chain declared here, keyed by NetworkID-style name — handy for a title-driven picker. */
68
+ declare const idosChains: {
69
+ readonly mainnet: Chain;
70
+ readonly bsc: Chain;
71
+ readonly polygon: Chain;
72
+ readonly base: Chain;
73
+ readonly arbitrum: Chain;
74
+ readonly optimism: Chain;
75
+ readonly sepolia: Chain;
76
+ readonly polygonAmoy: Chain;
77
+ };
78
+ /** Look up a declared chain by its EVM chain id (e.g. from the title's blockchain config). */
79
+ declare function chainById(id: number): Chain | undefined;
80
+ /**
81
+ * A chain in the CAIP shape Reown AppKit expects.
82
+ *
83
+ * AppKit ships its own network list at `@reown/appkit/networks`, but that module is
84
+ * `export * from "viem/chains"` — the very barrel this file exists to avoid. Converting our own
85
+ * chains keeps AppKit working without dragging `tempo`/`ox` (and its BigInt `**`) into the bundle.
86
+ */
87
+ type AppKitEvmNetwork = Chain & {
88
+ chainNamespace: "eip155";
89
+ caipNetworkId: `eip155:${number}`;
90
+ };
91
+ /** Wraps a chain in the CAIP fields AppKit needs. */
92
+ declare function toAppKitNetwork(chain: Chain): AppKitEvmNetwork;
93
+ interface AppKitSolanaNetwork {
94
+ id: string;
95
+ name: string;
96
+ network: string;
97
+ nativeCurrency: {
98
+ name: string;
99
+ symbol: string;
100
+ decimals: number;
101
+ };
102
+ rpcUrls: {
103
+ default: {
104
+ http: string[];
105
+ };
106
+ };
107
+ blockExplorers?: {
108
+ default: {
109
+ name: string;
110
+ url: string;
111
+ };
112
+ };
113
+ testnet: boolean;
114
+ chainNamespace: "solana";
115
+ caipNetworkId: `solana:${string}`;
116
+ }
117
+ declare const solanaMainnet: AppKitSolanaNetwork;
118
+ declare const solanaDevnet: AppKitSolanaNetwork;
119
+
120
+ export { type AppKitEvmNetwork as A, type BridgeResult as B, type WalletLoginResult as W, type AppKitSolanaNetwork as a, type BridgeFailure as b, type BridgeStage as c, type BridgeSuccess as d, type WalletLoginFailure as e, type WalletLoginStage as f, type WalletLoginSuccess as g, arbitrum as h, base as i, bridgeFail as j, bsc as k, chainById as l, idosChains as m, mainnet as n, optimism as o, polygon as p, polygonAmoy as q, solanaDevnet as r, sepolia as s, solanaMainnet as t, toAppKitNetwork as u, toErrorMessage as v, walletLoginFail as w };
@@ -1,3 +1,5 @@
1
+ import { Chain } from 'viem';
2
+
1
3
  /**
2
4
  * Where a multi-step bridge flow stopped. Deposits run approve → deposit-onchain → report;
3
5
  * withdrawals run request → withdraw-onchain → confirm. Knowing the stage lets a UI recover
@@ -54,4 +56,65 @@ interface WalletLoginFailure {
54
56
  type WalletLoginResult<T> = WalletLoginSuccess<T> | WalletLoginFailure;
55
57
  declare function walletLoginFail(stage: WalletLoginStage, error: string): WalletLoginFailure;
56
58
 
57
- export { type BridgeResult as B, type WalletLoginResult as W, type BridgeFailure as a, type BridgeStage as b, type BridgeSuccess as c, type WalletLoginFailure as d, type WalletLoginStage as e, type WalletLoginSuccess as f, bridgeFail as g, toErrorMessage as t, walletLoginFail as w };
59
+ declare const mainnet: Chain;
60
+ declare const bsc: Chain;
61
+ declare const polygon: Chain;
62
+ declare const base: Chain;
63
+ declare const arbitrum: Chain;
64
+ declare const optimism: Chain;
65
+ declare const sepolia: Chain;
66
+ declare const polygonAmoy: Chain;
67
+ /** Every chain declared here, keyed by NetworkID-style name — handy for a title-driven picker. */
68
+ declare const idosChains: {
69
+ readonly mainnet: Chain;
70
+ readonly bsc: Chain;
71
+ readonly polygon: Chain;
72
+ readonly base: Chain;
73
+ readonly arbitrum: Chain;
74
+ readonly optimism: Chain;
75
+ readonly sepolia: Chain;
76
+ readonly polygonAmoy: Chain;
77
+ };
78
+ /** Look up a declared chain by its EVM chain id (e.g. from the title's blockchain config). */
79
+ declare function chainById(id: number): Chain | undefined;
80
+ /**
81
+ * A chain in the CAIP shape Reown AppKit expects.
82
+ *
83
+ * AppKit ships its own network list at `@reown/appkit/networks`, but that module is
84
+ * `export * from "viem/chains"` — the very barrel this file exists to avoid. Converting our own
85
+ * chains keeps AppKit working without dragging `tempo`/`ox` (and its BigInt `**`) into the bundle.
86
+ */
87
+ type AppKitEvmNetwork = Chain & {
88
+ chainNamespace: "eip155";
89
+ caipNetworkId: `eip155:${number}`;
90
+ };
91
+ /** Wraps a chain in the CAIP fields AppKit needs. */
92
+ declare function toAppKitNetwork(chain: Chain): AppKitEvmNetwork;
93
+ interface AppKitSolanaNetwork {
94
+ id: string;
95
+ name: string;
96
+ network: string;
97
+ nativeCurrency: {
98
+ name: string;
99
+ symbol: string;
100
+ decimals: number;
101
+ };
102
+ rpcUrls: {
103
+ default: {
104
+ http: string[];
105
+ };
106
+ };
107
+ blockExplorers?: {
108
+ default: {
109
+ name: string;
110
+ url: string;
111
+ };
112
+ };
113
+ testnet: boolean;
114
+ chainNamespace: "solana";
115
+ caipNetworkId: `solana:${string}`;
116
+ }
117
+ declare const solanaMainnet: AppKitSolanaNetwork;
118
+ declare const solanaDevnet: AppKitSolanaNetwork;
119
+
120
+ export { type AppKitEvmNetwork as A, type BridgeResult as B, type WalletLoginResult as W, type AppKitSolanaNetwork as a, type BridgeFailure as b, type BridgeStage as c, type BridgeSuccess as d, type WalletLoginFailure as e, type WalletLoginStage as f, type WalletLoginSuccess as g, arbitrum as h, base as i, bridgeFail as j, bsc as k, chainById as l, idosChains as m, mainnet as n, optimism as o, polygon as p, polygonAmoy as q, solanaDevnet as r, sepolia as s, solanaMainnet as t, toAppKitNetwork as u, toErrorMessage as v, walletLoginFail as w };
@@ -0,0 +1 @@
1
+ import {c}from'./chunk-K3THMWU2.js';import {isPlatformParentOrigin,PLATFORM_ORIGINS}from'@idosgames/core';var d={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",openRequest:"IDOS_PLATFORM_WALLET_OPEN_REQUEST",openResponse:"IDOS_PLATFORM_WALLET_OPEN_RESPONSE"},m="PLATFORM_WALLET_UNAVAILABLE",p=5e3,A=18e4;function S(){let t=[...PLATFORM_ORIGINS],r=window.location.ancestorOrigins?.[0];return r&&!t.includes(r)&&isPlatformParentOrigin(r)&&t.push(r),t}function T(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function L(t,r,i){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:m});let n=window.parent;if(!n)return Promise.resolve({ok:false,error:m});let e=T();return new Promise(f=>{let l=false,a,u=o=>{l||(l=true,window.removeEventListener("message",g),clearTimeout(a),f(o));},g=o=>{if(!isPlatformParentOrigin(o.origin))return;let s=o.data;if(!(!s||s.requestId!==e)){if(s.type===d.ack){clearTimeout(a),a=setTimeout(()=>u({ok:false,error:"TIMEOUT"}),A);return}s.type===r&&u({ok:s.ok===true,error:typeof s.error=="string"?s.error:void 0,address:typeof s.address=="string"?s.address:void 0,signature:typeof s.signature=="string"?s.signature:void 0});}};a=setTimeout(()=>u({ok:false,error:m}),p),window.addEventListener("message",g);for(let o of S())try{n.postMessage({type:t,requestId:e,...i},o);}catch{}})}async function W(){return (await L(d.openRequest,d.openResponse,{})).ok}async function k(t){let{client:r,networkID:i}=t;return R(t,async n=>{let e=await r.auth.requestWalletChallenge(n,i);return e.ok?{ok:true,message:e.data.Message}:{ok:false,error:e.error}},(n,e)=>r.auth.loginWithWallet(n,i,e))}async function O(t){let{client:r,networkID:i}=t;return R(t,async n=>{let e=await r.auth.linkWallet(n,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}},(n,e)=>r.auth.linkWallet(n,i,e))}async function R(t,r,i){let{client:n,family:e}=t,f=n.titleID,l=await L(d.addressRequest,d.addressResponse,{titleID:f,family:e});if(!l.ok||!l.address)return c("challenge",l.error??"NO_WALLET");let a=l.address,u=await r(a);if(!u.ok)return c("challenge",u.error);let g=await L(d.signRequest,d.signResponse,{titleID:f,family:e,address:a,message:u.message});if(!g.ok||!g.signature)return c("sign",g.error??"SIGN_FAILED");let o=await i(a,g.signature);return o.ok?{ok:true,data:o.data}:c("login",o.error)}export{d as a,m as b,W as c,k as d,O as e};
@@ -0,0 +1 @@
1
+ import {useReducer,useState,useEffect,useMemo}from'react';import {jsxs,jsx,Fragment}from'react/jsx-runtime';var E=null;function M(t){E=t;}function q(){return E}function Q(t,o){switch(t){case null:case void 0:case "":return o;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 t}}var j={pointerEvents:"auto",background:"#04276bf5",border:"1px solid #1e59c8",borderRadius:12,padding:16,color:"#fff",width:320,boxSizing:"border-box",fontFamily:"system-ui, sans-serif",display:"flex",flexDirection:"column",gap:10,maxHeight:"80vh",overflow:"auto"},z={fontWeight:700,fontSize:16},a={fontSize:12,opacity:.7},v={background:"#052e7e",border:"1px solid #1e59c8",borderRadius:8,color:"#fff",padding:"8px 10px",width:"100%",boxSizing:"border-box"},H={background:"#0d66fe",color:"#fff",border:"none",borderRadius:8,padding:"9px 14px",fontWeight:700,cursor:"pointer"},f={background:"#1e59c8",color:"#fff",border:"none",borderRadius:8,padding:"7px 12px",fontWeight:600,cursor:"pointer"},m={display:"flex",gap:8};function J({client:t,engine:o,onClose:S,style:L}){let[,I]=useReducer(e=>e+1,0),[g,_]=useState({}),[k,B]=useState({}),[l,x]=useState(""),[s,N]=useState(""),[w,W]=useState(""),[p,D]=useState(false),[T,A]=useState(null);useEffect(()=>{let e=true;return (async()=>{let r=await t.blockchain.getDefinitions();if(await t.blockchain.getUserState(),!e||!r.ok)return;let u={};for(let[K,R]of Object.entries(r.data.Blockchain?.Networks??{}))R.Type===o.networkType&&(u[K]=R);_(u),B(r.data.CryptoCurrencies??{}),x(Object.keys(u)[0]??"");})(),()=>{e=false;}},[t,o.networkType]),useEffect(()=>t.on("user:anyUpdated",I),[t]);let d=useMemo(()=>Object.entries(k).filter(([,e])=>e.Networks?.some(r=>r.NetworkID===l&&!!r.ContractAddress)),[k,l]);useEffect(()=>{let e=d[0]?.[0]??"";N(r=>d.some(([u])=>u===r)?r:e);},[d]);let y=l?g[l]:void 0,b=s?k[s]?.Networks?.find(e=>e.NetworkID===l):void 0,O=s?t.data.user.getCryptoCurrencyAmount(s):"0",C=!!o.address;async function P(e){D(true),A(null);try{let r=await e();A(r),r.ok&&await t.blockchain.getUserState();}finally{D(false);}}return jsxs("div",{style:{...j,...L},children:[jsxs("div",{style:{...m,justifyContent:"space-between"},children:[jsx("span",{style:z,children:"Crypto wallet"}),S&&jsx("button",{type:"button",style:f,onClick:S,children:"\u2715"})]}),C?jsxs("div",{style:m,children:[jsxs("span",{style:{...a,flex:1,alignSelf:"center"},children:[o.address.slice(0,6),"\u2026",o.address.slice(-4)]}),jsx("button",{type:"button",style:f,onClick:o.disconnect,children:"Disconnect"})]}):jsxs("div",{style:{display:"flex",flexDirection:"column",gap:6},children:[jsx("span",{style:a,children:"Connect a browser or mobile wallet"}),o.connectChoices.length===0?jsx("span",{style:a,children:"Wallet connection is not configured for this title."}):o.connectChoices.map(e=>jsx("button",{type:"button",style:f,onClick:e.connect,children:e.label},e.key))]}),Object.keys(g).length===0?jsxs("span",{style:a,children:["No ",o.networkType," networks configured for this title."]}):jsxs(Fragment,{children:[jsxs("div",{children:[jsx("div",{style:a,children:"Network"}),jsx("select",{style:v,value:l,onChange:e=>x(e.target.value),children:Object.entries(g).map(([e,r])=>jsx("option",{value:e,children:r.DisplayName??e},e))})]}),jsxs("div",{children:[jsx("div",{style:a,children:"Token"}),jsxs("select",{style:v,value:s,onChange:e=>N(e.target.value),children:[d.length===0&&jsx("option",{value:"",children:"\u2014 no depositable tokens \u2014"}),d.map(([e,r])=>jsx("option",{value:e,children:r.DisplayName??e},e))]})]}),jsxs("div",{style:a,children:["In-game balance: ",jsx("b",{children:O})," ",s]}),jsxs("div",{children:[jsx("div",{style:a,children:"Amount"}),jsx("input",{style:v,inputMode:"decimal",placeholder:"0.0",value:w,onChange:e=>W(e.target.value)})]}),jsxs("div",{style:m,children:[jsx("button",{type:"button",style:{...H,flex:1,opacity:p?.6:1},disabled:p||!C||!b?.ContractAddress,onClick:()=>{!y||!b||P(()=>o.deposit({network:y,binding:b,currencyID:s,amount:w||"0"}));},children:"Deposit"}),jsx("button",{type:"button",style:{...f,flex:1,opacity:p?.6:1},disabled:p||!C||!s,onClick:()=>{y&&P(()=>o.withdraw({network:y,networkID:l,currencyID:s,amount:w||"0"}));},children:"Withdraw"})]})]}),T&&jsx(V,{result:T})]})}function V({result:t}){let o={fontSize:12,borderRadius:8,padding:"8px 10px",background:t.ok?"#1e3a2a":"#3a1e28",color:t.ok?"#8ef0b0":"#f2a0b4",wordBreak:"break-all"};return t.ok?jsxs("div",{style:o,children:["\u2713 Done \xB7 tx ",t.onChainTxHash]}):jsxs("div",{style:o,children:["\u2715 [",t.stage,"] ",t.error,t.titleTransactionID?` \xB7 already debited (tx ${t.titleTransactionID}) \u2014 retry/confirm, don't re-request`:""]})}export{M as a,q as b,Q as c,J as d};
package/dist/index.cjs CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var viem=require('viem'),core=require('@idosgames/core');function f(t){return t instanceof viem.BaseError?t.shortMessage:t instanceof Error?t.message:String(t)}function s(t,e,n){return {ok:false,stage:t,error:e,...n}}function g(t,e){return {ok:false,stage:t,error:e}}var C="WALLET_USE_SITE_PANEL",$=/^[a-z0-9]{8}-preview\.idos\.games$/;function N(t=typeof window>"u"?"":window.location.hostname){let e=t.toLowerCase();return $.test(e)?true:e!=="localhost"&&e!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function y(){if(typeof window>"u"||N())return false;try{return window.self!==window.top}catch{return true}}function Y(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function w(t){return s(t,C)}function E(t){return g(t,C)}var z=core.PLATFORM_ORIGINS;function Z(t){if(typeof window>"u")return ()=>{};let e=n=>{z.includes(n.origin)&&n.data?.type==="IDOS_WALLET_BALANCE_CHANGED"&&t();};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)}var A={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"},T="PLATFORM_WALLET_UNAVAILABLE",Q=5e3,j=18e4;function X(){let t=[...core.PLATFORM_ORIGINS],e=window.location.ancestorOrigins?.[0];return e&&!t.includes(e)&&core.isPlatformParentOrigin(e)&&t.push(e),t}function ee(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function B(t,e,n){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:T});let r=window.parent;if(!r)return Promise.resolve({ok:false,error:T});let o=ee();return new Promise(i=>{let p=false,l,a=d=>{p||(p=true,window.removeEventListener("message",u),clearTimeout(l),i(d));},u=d=>{if(!core.isPlatformParentOrigin(d.origin))return;let c=d.data;if(!(!c||c.requestId!==o)){if(c.type===A.ack){clearTimeout(l),l=setTimeout(()=>a({ok:false,error:"TIMEOUT"}),j);return}c.type===e&&a({ok:c.ok===true,error:typeof c.error=="string"?c.error:void 0,address:typeof c.address=="string"?c.address:void 0,signature:typeof c.signature=="string"?c.signature:void 0});}};l=setTimeout(()=>a({ok:false,error:T}),Q),window.addEventListener("message",u);for(let d of X())try{r.postMessage({type:t,requestId:o,...n},d);}catch{}})}async function te(t){let{client:e,networkID:n}=t;return M(t,async r=>{let o=await e.auth.requestWalletChallenge(r,n);return o.ok?{ok:true,message:o.data.Message}:{ok:false,error:o.error}},(r,o)=>e.auth.loginWithWallet(r,n,o))}async function ne(t){let{client:e,networkID:n}=t;return M(t,async r=>{let o=await e.auth.linkWallet(r,n);return o.ok?o.data.Challenge?{ok:true,message:o.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:o.error}},(r,o)=>e.auth.linkWallet(r,n,o))}async function M(t,e,n){let{client:r,family:o}=t,i=r.titleID,p=await B(A.addressRequest,A.addressResponse,{titleID:i,family:o});if(!p.ok||!p.address)return g("challenge",p.error??"NO_WALLET");let l=p.address,a=await e(l);if(!a.ok)return g("challenge",a.error);let u=await B(A.signRequest,A.signResponse,{titleID:i,family:o,address:l,message:a.message});if(!u.ok||!u.signature)return g("sign",u.error??"SIGN_FAILED");let d=await n(l,u.signature);return d.ok?{ok:true,data:d.data}:g("login",d.error)}var ae={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"}}},re={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"}}},oe={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"}}},ie={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"}}},se={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"}}},le={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"}}},de={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"}}},ce={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"}}},pe={mainnet:ae,bsc:re,polygon:oe,base:ie,arbitrum:se,optimism:le,sepolia:de,polygonAmoy:ce};function _e(t){return Object.values(pe).find(e=>e.id===t)}function Oe(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var He={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"},Ge={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"};var b=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],D=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],x=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],P=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}],v=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]}];function I(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function k(t,e){let{walletClient:n,publicClient:r,account:o}=t,i=await n.writeContract({address:e.address,abi:e.abi,functionName:e.functionName,args:e.args,account:o,chain:n.chain,value:e.value});if((await r.waitForTransactionReceipt({hash:i})).status==="reverted")throw new Error(`On-chain transaction reverted (${i}).`);return i}function S(t){let e=t.RewardPoolAddress;return e||null}async function L(t,e,n,r){return await t.publicClient.readContract({address:e,abi:x,functionName:"allowance",args:[t.account,n]})>=r?null:k(t,{address:e,abi:x,functionName:"approve",args:[n,r]})}async function R(t){let{client:e,clients:n,network:r,tokenAddress:o,amount:i,titleID:p,category:l}=t;if(y())return w("approve");let a=e.auth.context?.userID;if(!a)return s("approve","Not logged in.");let u=S(r);if(!u)return s("approve","Network has no RewardPoolAddress.");if(i<=0n)return s("approve","Amount must be positive.");try{await L(n,o,u,i);}catch(m){return s("approve",f(m))}let d;try{d=await k(n,{address:u,abi:b,functionName:"depositERC20",args:[o,i,a,p,l??""]});}catch(m){return s("deposit-onchain",f(m))}let c=await e.blockchain.depositToken(r.NetworkID??"",d);return c.ok?{ok:true,onChainTxHash:d,data:c.data}:s("report",c.error,{onChainTxHash:d})}async function ge(t){let{clients:e,poolAddress:n,tokenAddress:r,amount:o,userID:i,titleID:p,category:l}=t;if(y())return w("approve");if(!i)return s("approve","userID is required.");if(o<=0n)return s("approve","Amount must be positive.");try{await L(e,r,n,o);}catch(a){return s("approve",f(a))}try{let a=await k(e,{address:n,abi:b,functionName:"depositERC20",args:[r,o,i,p,l??""]});return {ok:!0,onChainTxHash:a,data:{txHash:a}}}catch(a){return s("deposit-onchain",f(a))}}async function fe(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,amount:p,titleID:l,category:a}=t;if(y())return w("deposit-onchain");let u=e.auth.context?.userID;if(!u)return s("deposit-onchain","Not logged in.");let d=S(r);if(!d)return s("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return s("deposit-onchain","Amount must be positive.");let c=I(u,l,a),m;try{m=await k(n,{address:o,abi:P,functionName:"safeTransferFrom",args:[n.account,d,i,p,c]});}catch(W){return s("deposit-onchain",f(W))}let h=await e.blockchain.depositNFT(r.NetworkID??"",m);return h.ok?{ok:true,onChainTxHash:m,data:h.data}:s("report",h.error,{onChainTxHash:m})}async function ye(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");let u=S(r);if(!u)return s("deposit-onchain","Network has no RewardPoolAddress.");let d=I(a,p,l),c;try{c=await k(n,{address:o,abi:v,functionName:"safeTransferFrom",args:[n.account,u,i,d]});}catch(h){return s("deposit-onchain",f(h))}let m=await e.blockchain.depositNFT(r.NetworkID??"",c);return m.ok?{ok:true,onChainTxHash:c,data:m.data}:s("report",m.error,{onChainTxHash:c})}function _(t){return (t.Splits??[]).map(e=>({to:e.To,amount:BigInt(e.Amount??"0")}))}async function O(t,e){return k(t,{address:e.ContractAddress,abi:b,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),_(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function H(t,e){return k(t,{address:e.ContractAddress,abi:D,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),_(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function he(t,e){return k(t,{address:e.ContractAddress,abi:D,functionName:"withdrawERC721Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function we(t){let{client:e,clients:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await O(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await G(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function ke(t){let{client:e,clients:n,itemID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestNFTWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await H(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await G(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function G(t,e,n){if(!e)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await t.blockchain.confirmWithdrawal(e,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:s("confirm",r.error,{onChainTxHash:n,titleTransactionID:e})}async function Ee(t){let{client:e,clients:n,networkID:r}=t;if(y())return E("challenge");let o=t.walletAddress??n.account,i=await e.auth.requestWalletChallenge(o,r);if(!i.ok)return g("challenge",i.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Message});}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function Ae(t){let{client:e,clients:n,networkID:r}=t;if(y())return E("challenge");let o=t.walletAddress??n.account,i=await e.auth.linkWallet(o,r);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Challenge});}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function We(t){let{client:e,clients:n,network:r,tokenAddress:o,decimals:i,titleID:p,shortfall:l,completePurchase:a,bufferRatio:u=0,category:d}=t;if(y())return w("approve");if(l.missing<=0)return s("approve","Nothing to deposit.");let c=l.missing*(1+Math.max(0,u)),m;try{m=viem.parseUnits(Te(c,i),i);}catch(q){return s("approve",f(q))}let h=await R({client:e,clients:n,network:r,tokenAddress:o,amount:m,titleID:p,category:d});if(!h.ok)return h;let W=await a();return W.ok?{ok:true,onChainTxHash:h.onChainTxHash,data:W.data}:s("report",W.error,{onChainTxHash:h.onChainTxHash})}function Te(t,e){return t.toFixed(Math.min(e,18)).replace(/0+$/,"").replace(/\.$/,"")||"0"}async function Ie(t){let{client:e,adapter:n,network:r,mint:o,amountRaw:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");if(i<=0n)return s("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:o,amountRaw:i,userID:a,titleID:p,category:core.normalizeBlockchainCategory(l)});}catch(c){return s("deposit-onchain",f(c))}let d=await e.blockchain.depositToken(r.NetworkID??"",u);return d.ok?{ok:true,onChainTxHash:u,data:d.data}:s("report",d.error,{onChainTxHash:u})}async function Ce(t){let{client:e,adapter:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.SolanaSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no Solana signature.",{titleTransactionID:d});let c;try{c=await n.submitWithdrawal(u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}if(!d)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:c});let m=await e.blockchain.confirmWithdrawal(d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:s("confirm",m.error,{onChainTxHash:c,titleTransactionID:d})}async function De(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return E("challenge");let i=await e.auth.requestWalletChallenge(r,n);if(!i.ok)return g("challenge",i.error);let p;try{let a=await o(new TextEncoder().encode(i.data.Message));p=U(a);}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function Pe(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return E("challenge");let i=await e.auth.linkWallet(r,n);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{let a=await o(new TextEncoder().encode(i.data.Challenge));p=U(a);}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}function U(t){let e="0x";for(let n of t)e+=n.toString(16).padStart(2,"0");return e}
2
- exports.PLATFORM_WALLET_MESSAGES=A;exports.PLATFORM_WALLET_UNAVAILABLE=T;exports.WALLET_USE_SITE_PANEL=C;exports.arbitrum=se;exports.base=ie;exports.bridgeFail=s;exports.bsc=re;exports.chainById=_e;exports.depositNftEvm=fe;exports.depositNftEvm721=ye;exports.depositTokenEvm=R;exports.depositTokenOnChainEvm=ge;exports.depositTokenSolana=Ie;exports.encodeNftDepositData=I;exports.ensureErc20Allowance=L;exports.erc1155Abi=P;exports.erc20Abi=x;exports.erc721Abi=v;exports.idosChains=pe;exports.isAiCoderPreview=N;exports.isEmbeddedInPlatform=y;exports.isEmbeddedOnForeignSite=Y;exports.linkWalletEvm=Ae;exports.linkWalletSolana=Pe;exports.linkWalletViaPlatform=ne;exports.loginWithWalletEvm=Ee;exports.loginWithWalletSolana=De;exports.loginWithWalletViaPlatform=te;exports.mainnet=ae;exports.onWalletBalanceChanged=Z;exports.optimism=le;exports.payWithWalletEvm=We;exports.polygon=oe;exports.polygonAmoy=ce;exports.rewardPoolAbi=b;exports.sepolia=de;exports.solanaDevnet=Ge;exports.solanaMainnet=He;exports.submitEvmNftWithdrawal=H;exports.submitEvmNftWithdrawal721=he;exports.submitEvmTokenWithdrawal=O;exports.toAppKitNetwork=Oe;exports.toErrorMessage=f;exports.walletLoginFail=g;exports.withdrawNftEvm=ke;exports.withdrawTokenEvm=we;exports.withdrawTokenSolana=Ce;exports.writeAndWait=k;
1
+ 'use strict';var viem=require('viem'),core=require('@idosgames/core');function f(t){return t instanceof viem.BaseError?t.shortMessage:t instanceof Error?t.message:String(t)}function s(t,e,n){return {ok:false,stage:t,error:e,...n}}function g(t,e){return {ok:false,stage:t,error:e}}var C="WALLET_USE_SITE_PANEL",$=/^[a-z0-9]{8}-preview\.idos\.games$/;function B(t=typeof window>"u"?"":window.location.hostname){let e=t.toLowerCase();return $.test(e)?true:e!=="localhost"&&e!=="127.0.0.1"?false:globalThis.__IDOS_PREVIEW__!=null}function y(){if(typeof window>"u"||B())return false;try{return window.self!==window.top}catch{return true}}function Y(){if(typeof window>"u")return false;try{return window.parent!==window.top}catch{return true}}function w(t){return s(t,C)}function A(t){return g(t,C)}var z=core.PLATFORM_ORIGINS;function Z(t){if(typeof window>"u")return ()=>{};let e=n=>{z.includes(n.origin)&&n.data?.type==="IDOS_WALLET_BALANCE_CHANGED"&&t();};return window.addEventListener("message",e),()=>window.removeEventListener("message",e)}var E={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",openRequest:"IDOS_PLATFORM_WALLET_OPEN_REQUEST",openResponse:"IDOS_PLATFORM_WALLET_OPEN_RESPONSE"},T="PLATFORM_WALLET_UNAVAILABLE",J=5e3,j=18e4;function X(){let t=[...core.PLATFORM_ORIGINS],e=window.location.ancestorOrigins?.[0];return e&&!t.includes(e)&&core.isPlatformParentOrigin(e)&&t.push(e),t}function ee(){return `wallet-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}function D(t,e,n){if(typeof window>"u"||window.self===window.top)return Promise.resolve({ok:false,error:T});let r=window.parent;if(!r)return Promise.resolve({ok:false,error:T});let o=ee();return new Promise(i=>{let p=false,l,a=d=>{p||(p=true,window.removeEventListener("message",u),clearTimeout(l),i(d));},u=d=>{if(!core.isPlatformParentOrigin(d.origin))return;let c=d.data;if(!(!c||c.requestId!==o)){if(c.type===E.ack){clearTimeout(l),l=setTimeout(()=>a({ok:false,error:"TIMEOUT"}),j);return}c.type===e&&a({ok:c.ok===true,error:typeof c.error=="string"?c.error:void 0,address:typeof c.address=="string"?c.address:void 0,signature:typeof c.signature=="string"?c.signature:void 0});}};l=setTimeout(()=>a({ok:false,error:T}),J),window.addEventListener("message",u);for(let d of X())try{r.postMessage({type:t,requestId:o,...n},d);}catch{}})}async function te(){return (await D(E.openRequest,E.openResponse,{})).ok}async function ne(t){let{client:e,networkID:n}=t;return M(t,async r=>{let o=await e.auth.requestWalletChallenge(r,n);return o.ok?{ok:true,message:o.data.Message}:{ok:false,error:o.error}},(r,o)=>e.auth.loginWithWallet(r,n,o))}async function ae(t){let{client:e,networkID:n}=t;return M(t,async r=>{let o=await e.auth.linkWallet(r,n);return o.ok?o.data.Challenge?{ok:true,message:o.data.Challenge}:{ok:false,error:"No challenge was issued."}:{ok:false,error:o.error}},(r,o)=>e.auth.linkWallet(r,n,o))}async function M(t,e,n){let{client:r,family:o}=t,i=r.titleID,p=await D(E.addressRequest,E.addressResponse,{titleID:i,family:o});if(!p.ok||!p.address)return g("challenge",p.error??"NO_WALLET");let l=p.address,a=await e(l);if(!a.ok)return g("challenge",a.error);let u=await D(E.signRequest,E.signResponse,{titleID:i,family:o,address:l,message:a.message});if(!u.ok||!u.signature)return g("sign",u.error??"SIGN_FAILED");let d=await n(l,u.signature);return d.ok?{ok:true,data:d.data}:g("login",d.error)}var re={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"}}},oe={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"}}},ie={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"}}},se={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"}}},le={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"}}},de={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"}}},ce={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"}}},pe={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"}}},ue={mainnet:re,bsc:oe,polygon:ie,base:se,arbitrum:le,optimism:de,sepolia:ce,polygonAmoy:pe};function Oe(t){return Object.values(ue).find(e=>e.id===t)}function He(t){return {...t,chainNamespace:"eip155",caipNetworkId:`eip155:${t.id}`}}var Ge={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"},qe={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"};var b=[{type:"function",name:"depositERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"amount",type:"uint256"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"withdrawERC20",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"amount",type:"uint256"},{name:"burnAmount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC1155",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721",stateMutability:"nonpayable",inputs:[{name:"token",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],P=[{type:"function",name:"withdrawERC1155Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"splits",type:"tuple[]",components:[{name:"to",type:"address"},{name:"amount",type:"uint256"}]},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]},{type:"function",name:"withdrawERC721Mint",stateMutability:"nonpayable",inputs:[{name:"collection",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"nonce",type:"uint256"},{name:"signature",type:"bytes"},{name:"userID",type:"string"},{name:"titleID",type:"string"},{name:"category",type:"string"},{name:"deadline",type:"uint256"}],outputs:[]}],x=[{type:"function",name:"approve",stateMutability:"nonpayable",inputs:[{name:"spender",type:"address"},{name:"amount",type:"uint256"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"allowance",stateMutability:"view",inputs:[{name:"owner",type:"address"},{name:"spender",type:"address"}],outputs:[{name:"",type:"uint256"}]},{type:"function",name:"decimals",stateMutability:"view",inputs:[],outputs:[{name:"",type:"uint8"}]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"}],outputs:[{name:"",type:"uint256"}]}],v=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"id",type:"uint256"},{name:"amount",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]},{type:"function",name:"isApprovedForAll",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"operator",type:"address"}],outputs:[{name:"",type:"bool"}]},{type:"function",name:"setApprovalForAll",stateMutability:"nonpayable",inputs:[{name:"operator",type:"address"},{name:"approved",type:"bool"}],outputs:[]},{type:"function",name:"balanceOf",stateMutability:"view",inputs:[{name:"account",type:"address"},{name:"id",type:"uint256"}],outputs:[{name:"",type:"uint256"}]}],S=[{type:"function",name:"safeTransferFrom",stateMutability:"nonpayable",inputs:[{name:"from",type:"address"},{name:"to",type:"address"},{name:"tokenId",type:"uint256"},{name:"data",type:"bytes"}],outputs:[]}];function I(t,e,n){return viem.encodeAbiParameters([{type:"string"},{type:"string"},{type:"string"}],[t,e,core.normalizeBlockchainCategory(n)])}async function k(t,e){let{walletClient:n,publicClient:r,account:o}=t,i=await n.writeContract({address:e.address,abi:e.abi,functionName:e.functionName,args:e.args,account:o,chain:n.chain,value:e.value});if((await r.waitForTransactionReceipt({hash:i})).status==="reverted")throw new Error(`On-chain transaction reverted (${i}).`);return i}function R(t){let e=t.RewardPoolAddress;return e||null}async function L(t,e,n,r){return await t.publicClient.readContract({address:e,abi:x,functionName:"allowance",args:[t.account,n]})>=r?null:k(t,{address:e,abi:x,functionName:"approve",args:[n,r]})}async function N(t){let{client:e,clients:n,network:r,tokenAddress:o,amount:i,titleID:p,category:l}=t;if(y())return w("approve");let a=e.auth.context?.userID;if(!a)return s("approve","Not logged in.");let u=R(r);if(!u)return s("approve","Network has no RewardPoolAddress.");if(i<=0n)return s("approve","Amount must be positive.");try{await L(n,o,u,i);}catch(m){return s("approve",f(m))}let d;try{d=await k(n,{address:u,abi:b,functionName:"depositERC20",args:[o,i,a,p,l??""]});}catch(m){return s("deposit-onchain",f(m))}let c=await e.blockchain.depositToken(r.NetworkID??"",d);return c.ok?{ok:true,onChainTxHash:d,data:c.data}:s("report",c.error,{onChainTxHash:d})}async function fe(t){let{clients:e,poolAddress:n,tokenAddress:r,amount:o,userID:i,titleID:p,category:l}=t;if(y())return w("approve");if(!i)return s("approve","userID is required.");if(o<=0n)return s("approve","Amount must be positive.");try{await L(e,r,n,o);}catch(a){return s("approve",f(a))}try{let a=await k(e,{address:n,abi:b,functionName:"depositERC20",args:[r,o,i,p,l??""]});return {ok:!0,onChainTxHash:a,data:{txHash:a}}}catch(a){return s("deposit-onchain",f(a))}}async function ye(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,amount:p,titleID:l,category:a}=t;if(y())return w("deposit-onchain");let u=e.auth.context?.userID;if(!u)return s("deposit-onchain","Not logged in.");let d=R(r);if(!d)return s("deposit-onchain","Network has no RewardPoolAddress.");if(p<=0n)return s("deposit-onchain","Amount must be positive.");let c=I(u,l,a),m;try{m=await k(n,{address:o,abi:v,functionName:"safeTransferFrom",args:[n.account,d,i,p,c]});}catch(W){return s("deposit-onchain",f(W))}let h=await e.blockchain.depositNFT(r.NetworkID??"",m);return h.ok?{ok:true,onChainTxHash:m,data:h.data}:s("report",h.error,{onChainTxHash:m})}async function he(t){let{client:e,clients:n,network:r,nftContractAddress:o,tokenId:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");let u=R(r);if(!u)return s("deposit-onchain","Network has no RewardPoolAddress.");let d=I(a,p,l),c;try{c=await k(n,{address:o,abi:S,functionName:"safeTransferFrom",args:[n.account,u,i,d]});}catch(h){return s("deposit-onchain",f(h))}let m=await e.blockchain.depositNFT(r.NetworkID??"",c);return m.ok?{ok:true,onChainTxHash:c,data:m.data}:s("report",m.error,{onChainTxHash:c})}function _(t){return (t.Splits??[]).map(e=>({to:e.To,amount:BigInt(e.Amount??"0")}))}async function O(t,e){return k(t,{address:e.ContractAddress,abi:b,functionName:"withdrawERC20",args:[e.TokenAddress,e.WalletAddress,BigInt(e.Amount??"0"),BigInt(e.BurnAmount??"0"),_(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function H(t,e){return k(t,{address:e.ContractAddress,abi:P,functionName:"withdrawERC1155Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Amount??"0"),_(e),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function we(t,e){return k(t,{address:e.ContractAddress,abi:P,functionName:"withdrawERC721Mint",args:[e.TokenAddress,e.WalletAddress,BigInt(e.TokenId??"0"),BigInt(e.Nonce??"0"),e.Signature??"0x",e.UserID??"",e.TitleID??"",e.Category??"",BigInt(e.Deadline??"0")]})}async function ke(t){let{client:e,clients:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await O(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await G(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function Ee(t){let{client:e,clients:n,itemID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestNFTWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.EvmSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no EVM signature.",{titleTransactionID:d});let c;try{c=await H(n,u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}let m=await G(e,d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:m}async function G(t,e,n){if(!e)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:n});let r=await t.blockchain.confirmWithdrawal(e,n);return r.ok?{ok:true,onChainTxHash:n,data:r.data}:s("confirm",r.error,{onChainTxHash:n,titleTransactionID:e})}async function Ae(t){let{client:e,clients:n,networkID:r}=t;if(y())return A("challenge");let o=t.walletAddress??n.account,i=await e.auth.requestWalletChallenge(o,r);if(!i.ok)return g("challenge",i.error);let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Message});}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function be(t){let{client:e,clients:n,networkID:r}=t;if(y())return A("challenge");let o=t.walletAddress??n.account,i=await e.auth.linkWallet(o,r);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{p=await n.walletClient.signMessage({account:n.account,message:i.data.Challenge});}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(o,r,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function Te(t){let{client:e,clients:n,network:r,tokenAddress:o,decimals:i,titleID:p,shortfall:l,completePurchase:a,bufferRatio:u=0,category:d}=t;if(y())return w("approve");if(l.missing<=0)return s("approve","Nothing to deposit.");let c=l.missing*(1+Math.max(0,u)),m;try{m=viem.parseUnits(xe(c,i),i);}catch(U){return s("approve",f(U))}let h=await N({client:e,clients:n,network:r,tokenAddress:o,amount:m,titleID:p,category:d});if(!h.ok)return h;let W=await a();return W.ok?{ok:true,onChainTxHash:h.onChainTxHash,data:W.data}:s("report",W.error,{onChainTxHash:h.onChainTxHash})}function xe(t,e){return t.toFixed(Math.min(e,18)).replace(/0+$/,"").replace(/\.$/,"")||"0"}async function Ce(t){let{client:e,adapter:n,network:r,mint:o,amountRaw:i,titleID:p,category:l}=t;if(y())return w("deposit-onchain");let a=e.auth.context?.userID;if(!a)return s("deposit-onchain","Not logged in.");if(i<=0n)return s("deposit-onchain","Amount must be positive.");let u;try{u=await n.depositSpl({mint:o,amountRaw:i,userID:a,titleID:p,category:core.normalizeBlockchainCategory(l)});}catch(c){return s("deposit-onchain",f(c))}let d=await e.blockchain.depositToken(r.NetworkID??"",u);return d.ok?{ok:true,onChainTxHash:u,data:d.data}:s("report",d.error,{onChainTxHash:u})}async function De(t){let{client:e,adapter:n,currencyID:r,networkID:o,walletAddress:i,amount:p,category:l}=t;if(y())return w("request");let a=await e.blockchain.requestTokenWithdrawal(r,o,i,p,l);if(!a.ok)return s("request",a.error);let u=a.data.SolanaSignature,d=a.data.TitleTransactionID??void 0;if(!u)return s("request","Withdrawal response carried no Solana signature.",{titleTransactionID:d});let c;try{c=await n.submitWithdrawal(u);}catch(h){return s("withdraw-onchain",f(h),{titleTransactionID:d})}if(!d)return s("confirm","Missing TitleTransactionID.",{onChainTxHash:c});let m=await e.blockchain.confirmWithdrawal(d,c);return m.ok?{ok:true,onChainTxHash:c,data:a.data}:s("confirm",m.error,{onChainTxHash:c,titleTransactionID:d})}async function Pe(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return A("challenge");let i=await e.auth.requestWalletChallenge(r,n);if(!i.ok)return g("challenge",i.error);let p;try{let a=await o(new TextEncoder().encode(i.data.Message));p=q(a);}catch(a){return g("sign",f(a))}let l=await e.auth.loginWithWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}async function ve(t){let{client:e,networkID:n,walletAddress:r,signMessage:o}=t;if(y())return A("challenge");let i=await e.auth.linkWallet(r,n);if(!i.ok)return g("challenge",i.error);if(!i.data.Challenge)return g("challenge","No challenge was issued.");let p;try{let a=await o(new TextEncoder().encode(i.data.Challenge));p=q(a);}catch(a){return g("sign",f(a))}let l=await e.auth.linkWallet(r,n,p);return l.ok?{ok:true,data:l.data}:g("login",l.error)}function q(t){let e="0x";for(let n of t)e+=n.toString(16).padStart(2,"0");return e}
2
+ exports.PLATFORM_WALLET_MESSAGES=E;exports.PLATFORM_WALLET_UNAVAILABLE=T;exports.WALLET_USE_SITE_PANEL=C;exports.arbitrum=le;exports.base=se;exports.bridgeFail=s;exports.bsc=oe;exports.chainById=Oe;exports.depositNftEvm=ye;exports.depositNftEvm721=he;exports.depositTokenEvm=N;exports.depositTokenOnChainEvm=fe;exports.depositTokenSolana=Ce;exports.encodeNftDepositData=I;exports.ensureErc20Allowance=L;exports.erc1155Abi=v;exports.erc20Abi=x;exports.erc721Abi=S;exports.idosChains=ue;exports.isAiCoderPreview=B;exports.isEmbeddedInPlatform=y;exports.isEmbeddedOnForeignSite=Y;exports.linkWalletEvm=be;exports.linkWalletSolana=ve;exports.linkWalletViaPlatform=ae;exports.loginWithWalletEvm=Ae;exports.loginWithWalletSolana=Pe;exports.loginWithWalletViaPlatform=ne;exports.mainnet=re;exports.onWalletBalanceChanged=Z;exports.openPlatformWalletPanel=te;exports.optimism=de;exports.payWithWalletEvm=Te;exports.polygon=ie;exports.polygonAmoy=pe;exports.rewardPoolAbi=b;exports.sepolia=ce;exports.solanaDevnet=qe;exports.solanaMainnet=Ge;exports.submitEvmNftWithdrawal=H;exports.submitEvmNftWithdrawal721=we;exports.submitEvmTokenWithdrawal=O;exports.toAppKitNetwork=He;exports.toErrorMessage=f;exports.walletLoginFail=g;exports.withdrawNftEvm=Ee;exports.withdrawTokenEvm=ke;exports.withdrawTokenSolana=De;exports.writeAndWait=k;
package/dist/index.d.cts CHANGED
@@ -1,103 +1,11 @@
1
- import { W as WalletLoginResult, B as BridgeResult } from './types-CeUVf1tr.cjs';
2
- export { a as BridgeFailure, b as BridgeStage, c as BridgeSuccess, d as WalletLoginFailure, e as WalletLoginStage, f as WalletLoginSuccess, g as bridgeFail, t as toErrorMessage, w as walletLoginFail } from './types-CeUVf1tr.cjs';
3
- import { IDosGamesClient, WalletLinkResponse, ClientState, BlockchainNetworkDefinition, CryptoShortfall, OperationResult } from '@idosgames/core';
4
- export { A as AppKitEvmNetwork, a as AppKitSolanaNetwork, b as arbitrum, c as base, d as bsc, e as chainById, i as idosChains, m as mainnet, o as optimism, p as polygon, f as polygonAmoy, s as sepolia, g as solanaDevnet, h as solanaMainnet, t as toAppKitNetwork } from './chains-B_P3u8_S.cjs';
1
+ import { W as WalletLoginResult, B as BridgeResult } from './chains-B2jQ-L0B.cjs';
2
+ export { A as AppKitEvmNetwork, a as AppKitSolanaNetwork, b as BridgeFailure, c as BridgeStage, d as BridgeSuccess, e as WalletLoginFailure, f as WalletLoginStage, g as WalletLoginSuccess, h as arbitrum, i as base, j as bridgeFail, k as bsc, l as chainById, m as idosChains, n as mainnet, o as optimism, p as polygon, q as polygonAmoy, s as sepolia, r as solanaDevnet, t as solanaMainnet, u as toAppKitNetwork, v as toErrorMessage, w as walletLoginFail } from './chains-B2jQ-L0B.cjs';
3
+ export { L as LoginWithWalletViaPlatformParams, P as PLATFORM_WALLET_MESSAGES, a as PLATFORM_WALLET_UNAVAILABLE, b as PlatformWalletFamily, W as WALLET_USE_SITE_PANEL, i as isAiCoderPreview, c as isEmbeddedInPlatform, d as isEmbeddedOnForeignSite, l as linkWalletViaPlatform, e as loginWithWalletViaPlatform, o as onWalletBalanceChanged, f as openPlatformWalletPanel } from './platformWalletLogin-Ysdf-Tt8.cjs';
5
4
  import { Hex, Address } from 'viem';
6
- import { E as EvmBridgeClients } from './withdraw-C5y67V7i.cjs';
7
- export { D as DepositNft721EvmParams, a as DepositNftEvmParams, b as DepositTokenEvmParams, c as DepositTokenOnChainParams, W as WithdrawNftEvmParams, d as WithdrawTokenEvmParams, e as depositNftEvm, f as depositNftEvm721, g as depositTokenEvm, h as depositTokenOnChainEvm, i as ensureErc20Allowance, s as submitEvmNftWithdrawal, j as submitEvmNftWithdrawal721, k as submitEvmTokenWithdrawal, w as withdrawNftEvm, l as withdrawTokenEvm, m as writeAndWait } from './withdraw-C5y67V7i.cjs';
8
- export { D as DepositTokenSolanaParams, S as SolanaProgramAdapter, W as WithdrawTokenSolanaParams, d as depositTokenSolana, w as withdrawTokenSolana } from './bridge-f3pZbjqs.cjs';
9
-
10
- /**
11
- * `error`/`stage` every wallet flow in this package refuses with when the page is embedded — a
12
- * game can `if (result.error === WALLET_USE_SITE_PANEL)` to show its own "use the site panel"
13
- * message instead of a generic failure.
14
- */
15
- declare const WALLET_USE_SITE_PANEL = "WALLET_USE_SITE_PANEL";
16
- /**
17
- * The page is the AI Coder's live preview, so the game's own wallet flows are allowed in its iframe.
18
- *
19
- * Decided by the page's HOSTNAME, not by a global: a game on its own address embedded on
20
- * idosgames.com can set any global it likes, but it cannot make itself run under a `-preview` host —
21
- * that host serves only the preview runtime and is framed only by the dashboard. The one extra case
22
- * is the local preview stand on a loopback address (`npm run preview:dev`), recognised by the marker
23
- * the preview runtime sets: on a developer's own machine there is nothing to protect.
24
- */
25
- declare function isAiCoderPreview(hostname?: string): boolean;
26
- /**
27
- * The page is inside an iframe. `window.self !== window.top` is the standard cross-origin-safe
28
- * check — it never throws, unlike reading `window.parent.location`, which is exactly why it works
29
- * the same whether the parent is idosgames.com or (in an exotic embedding this package cannot and
30
- * should not try to distinguish) anything else. Any iframe means "don't prompt for a signature
31
- * here" — that is a reasonable default even outside the platform's own embedding.
32
- */
33
- declare function isEmbeddedInPlatform(): boolean;
34
- /**
35
- * The page is embedded on SOMEBODY ELSE'S site, not on a platform page of our own.
36
- *
37
- * The platform offers a game to other sites through `idosgames.com/embed/{id}`, a thin page that
38
- * frames the game — so on a foreign site the game sits TWO frames deep (their page → our embed page
39
- * → the game), while on the platform's own app page it sits exactly one (`/app/{id}` → the game).
40
- * `window.parent !== window.top` is that difference, and it is the only signal available here: both
41
- * are cross-origin Window proxies, so they can be compared but not read.
42
- *
43
- * Why it matters (owner's decision, 2026-09-22): the "deposit and withdraw on idosgames.com" notice
44
- * belongs next to the site's own wallet panel — on OUR page, where that panel is right there on
45
- * screen. On a stranger's blog there is no panel, nothing the player can act on, and a wallet
46
- * message inside a small embedded window is noise at best. So there the wallet UI shows nothing at
47
- * all. Nothing about the actual barrier changes: wallet flows refuse in every iframe either way
48
- * ({@link isEmbeddedInPlatform}).
49
- */
50
- declare function isEmbeddedOnForeignSite(): boolean;
51
- /**
52
- * The site's wallet panel is the ONLY place a player can deposit/withdraw while this game is
53
- * embedded (see the module docblock above). After it completes an operation it posts
54
- * `{type: "IDOS_WALLET_BALANCE_CHANGED"}` to this page — a game that wants its on-screen balance
55
- * to update without the player reloading should call this once (e.g. in its HUD/wallet-display
56
- * setup) and refresh from `client.blockchain.getUserState()` when it fires. A no-op when not
57
- * embedded (the site panel doesn't exist there to send it) or outside the browser.
58
- *
59
- * Returns an unsubscribe function.
60
- */
61
- declare function onWalletBalanceChanged(callback: () => void): () => void;
62
-
63
- /** Message names. Shared with `GameWalletLoginBridge` on the website — keep both in step. */
64
- declare const PLATFORM_WALLET_MESSAGES: {
65
- readonly addressRequest: "IDOS_PLATFORM_WALLET_ADDRESS_REQUEST";
66
- readonly addressResponse: "IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE";
67
- readonly signRequest: "IDOS_PLATFORM_WALLET_SIGN_REQUEST";
68
- readonly signResponse: "IDOS_PLATFORM_WALLET_SIGN_RESPONSE";
69
- /** Sent by the site the moment it receives a request — "I am here, the player is choosing". */
70
- readonly ack: "IDOS_PLATFORM_WALLET_ACK";
71
- };
72
- /** Which of the site's wallets signs: its EVM connection or its Solana adapter. */
73
- type PlatformWalletFamily = "evm" | "solana";
74
- /**
75
- * The page around the game did not answer at all — an old site build without the bridge, or a
76
- * parent that is not the platform. The button shows a plain "not available here" for it.
77
- */
78
- declare const PLATFORM_WALLET_UNAVAILABLE = "PLATFORM_WALLET_UNAVAILABLE";
79
- interface LoginWithWalletViaPlatformParams {
80
- /** The (not yet authenticated) shared client. */
81
- client: IDosGamesClient;
82
- /** NetworkID (key of cfg.Blockchain.Networks) the wallet proves ownership on. */
83
- networkID: string;
84
- /** Which of the site's wallets to use. */
85
- family: PlatformWalletFamily;
86
- }
87
- /**
88
- * Full wallet sign-in for a game embedded on idosgames.com, signed by the site's own wallet
89
- * connection. Same result shape and stages as `loginWithWalletEvm` / `loginWithWalletSolana`:
90
- * `challenge` covers getting the address and the engine's message, `sign` the site's signature,
91
- * `login` the exchange for a session.
92
- */
93
- declare function loginWithWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<ClientState>>;
94
- /**
95
- * Attach a wallet to the LOGGED-IN account inside the idosgames.com frame — the site's wallet signs
96
- * the engine's link challenge (same message template as login, so the site's check accepts it). Used
97
- * by the play-access screen of a gated title; `data.PlayAccess` is the pass checked against this
98
- * wallet.
99
- */
100
- declare function linkWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<WalletLinkResponse>>;
5
+ import { E as EvmBridgeClients } from './withdraw-DttqktSS.cjs';
6
+ export { D as DepositNft721EvmParams, a as DepositNftEvmParams, b as DepositTokenEvmParams, c as DepositTokenOnChainParams, W as WithdrawNftEvmParams, d as WithdrawTokenEvmParams, e as depositNftEvm, f as depositNftEvm721, g as depositTokenEvm, h as depositTokenOnChainEvm, i as ensureErc20Allowance, s as submitEvmNftWithdrawal, j as submitEvmNftWithdrawal721, k as submitEvmTokenWithdrawal, w as withdrawNftEvm, l as withdrawTokenEvm, m as writeAndWait } from './withdraw-DttqktSS.cjs';
7
+ import { IDosGamesClient, WalletLinkResponse, ClientState, BlockchainNetworkDefinition, CryptoShortfall, OperationResult } from '@idosgames/core';
8
+ export { D as DepositTokenSolanaParams, S as SolanaProgramAdapter, W as WithdrawTokenSolanaParams, d as depositTokenSolana, w as withdrawTokenSolana } from './bridge-ZHrosWG-.cjs';
101
9
 
102
10
  declare const rewardPoolAbi: readonly [{
103
11
  readonly type: "function";
@@ -499,4 +407,4 @@ declare function loginWithWalletSolana(params: LoginWithWalletSolanaParams): Pro
499
407
  */
500
408
  declare function linkWalletSolana(params: LoginWithWalletSolanaParams): Promise<WalletLoginResult<WalletLinkResponse>>;
501
409
 
502
- export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type LoginWithWalletViaPlatformParams, PLATFORM_WALLET_MESSAGES, PLATFORM_WALLET_UNAVAILABLE, type PayWithWalletParams, type PlatformWalletFamily, type SolanaMessageSigner, WALLET_USE_SITE_PANEL, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, isAiCoderPreview, isEmbeddedInPlatform, isEmbeddedOnForeignSite, linkWalletEvm, linkWalletSolana, linkWalletViaPlatform, loginWithWalletEvm, loginWithWalletSolana, loginWithWalletViaPlatform, onWalletBalanceChanged, payWithWalletEvm, rewardPoolAbi };
410
+ export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type PayWithWalletParams, type SolanaMessageSigner, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, linkWalletEvm, linkWalletSolana, loginWithWalletEvm, loginWithWalletSolana, payWithWalletEvm, rewardPoolAbi };
package/dist/index.d.ts CHANGED
@@ -1,103 +1,11 @@
1
- import { W as WalletLoginResult, B as BridgeResult } from './types-CeUVf1tr.js';
2
- export { a as BridgeFailure, b as BridgeStage, c as BridgeSuccess, d as WalletLoginFailure, e as WalletLoginStage, f as WalletLoginSuccess, g as bridgeFail, t as toErrorMessage, w as walletLoginFail } from './types-CeUVf1tr.js';
3
- import { IDosGamesClient, WalletLinkResponse, ClientState, BlockchainNetworkDefinition, CryptoShortfall, OperationResult } from '@idosgames/core';
4
- export { A as AppKitEvmNetwork, a as AppKitSolanaNetwork, b as arbitrum, c as base, d as bsc, e as chainById, i as idosChains, m as mainnet, o as optimism, p as polygon, f as polygonAmoy, s as sepolia, g as solanaDevnet, h as solanaMainnet, t as toAppKitNetwork } from './chains-B_P3u8_S.js';
1
+ import { W as WalletLoginResult, B as BridgeResult } from './chains-B2jQ-L0B.js';
2
+ export { A as AppKitEvmNetwork, a as AppKitSolanaNetwork, b as BridgeFailure, c as BridgeStage, d as BridgeSuccess, e as WalletLoginFailure, f as WalletLoginStage, g as WalletLoginSuccess, h as arbitrum, i as base, j as bridgeFail, k as bsc, l as chainById, m as idosChains, n as mainnet, o as optimism, p as polygon, q as polygonAmoy, s as sepolia, r as solanaDevnet, t as solanaMainnet, u as toAppKitNetwork, v as toErrorMessage, w as walletLoginFail } from './chains-B2jQ-L0B.js';
3
+ export { L as LoginWithWalletViaPlatformParams, P as PLATFORM_WALLET_MESSAGES, a as PLATFORM_WALLET_UNAVAILABLE, b as PlatformWalletFamily, W as WALLET_USE_SITE_PANEL, i as isAiCoderPreview, c as isEmbeddedInPlatform, d as isEmbeddedOnForeignSite, l as linkWalletViaPlatform, e as loginWithWalletViaPlatform, o as onWalletBalanceChanged, f as openPlatformWalletPanel } from './platformWalletLogin-DNC2Ajle.js';
5
4
  import { Hex, Address } from 'viem';
6
- import { E as EvmBridgeClients } from './withdraw-BKVcklPB.js';
7
- export { D as DepositNft721EvmParams, a as DepositNftEvmParams, b as DepositTokenEvmParams, c as DepositTokenOnChainParams, W as WithdrawNftEvmParams, d as WithdrawTokenEvmParams, e as depositNftEvm, f as depositNftEvm721, g as depositTokenEvm, h as depositTokenOnChainEvm, i as ensureErc20Allowance, s as submitEvmNftWithdrawal, j as submitEvmNftWithdrawal721, k as submitEvmTokenWithdrawal, w as withdrawNftEvm, l as withdrawTokenEvm, m as writeAndWait } from './withdraw-BKVcklPB.js';
8
- export { D as DepositTokenSolanaParams, S as SolanaProgramAdapter, W as WithdrawTokenSolanaParams, d as depositTokenSolana, w as withdrawTokenSolana } from './bridge-BSTHFExV.js';
9
-
10
- /**
11
- * `error`/`stage` every wallet flow in this package refuses with when the page is embedded — a
12
- * game can `if (result.error === WALLET_USE_SITE_PANEL)` to show its own "use the site panel"
13
- * message instead of a generic failure.
14
- */
15
- declare const WALLET_USE_SITE_PANEL = "WALLET_USE_SITE_PANEL";
16
- /**
17
- * The page is the AI Coder's live preview, so the game's own wallet flows are allowed in its iframe.
18
- *
19
- * Decided by the page's HOSTNAME, not by a global: a game on its own address embedded on
20
- * idosgames.com can set any global it likes, but it cannot make itself run under a `-preview` host —
21
- * that host serves only the preview runtime and is framed only by the dashboard. The one extra case
22
- * is the local preview stand on a loopback address (`npm run preview:dev`), recognised by the marker
23
- * the preview runtime sets: on a developer's own machine there is nothing to protect.
24
- */
25
- declare function isAiCoderPreview(hostname?: string): boolean;
26
- /**
27
- * The page is inside an iframe. `window.self !== window.top` is the standard cross-origin-safe
28
- * check — it never throws, unlike reading `window.parent.location`, which is exactly why it works
29
- * the same whether the parent is idosgames.com or (in an exotic embedding this package cannot and
30
- * should not try to distinguish) anything else. Any iframe means "don't prompt for a signature
31
- * here" — that is a reasonable default even outside the platform's own embedding.
32
- */
33
- declare function isEmbeddedInPlatform(): boolean;
34
- /**
35
- * The page is embedded on SOMEBODY ELSE'S site, not on a platform page of our own.
36
- *
37
- * The platform offers a game to other sites through `idosgames.com/embed/{id}`, a thin page that
38
- * frames the game — so on a foreign site the game sits TWO frames deep (their page → our embed page
39
- * → the game), while on the platform's own app page it sits exactly one (`/app/{id}` → the game).
40
- * `window.parent !== window.top` is that difference, and it is the only signal available here: both
41
- * are cross-origin Window proxies, so they can be compared but not read.
42
- *
43
- * Why it matters (owner's decision, 2026-09-22): the "deposit and withdraw on idosgames.com" notice
44
- * belongs next to the site's own wallet panel — on OUR page, where that panel is right there on
45
- * screen. On a stranger's blog there is no panel, nothing the player can act on, and a wallet
46
- * message inside a small embedded window is noise at best. So there the wallet UI shows nothing at
47
- * all. Nothing about the actual barrier changes: wallet flows refuse in every iframe either way
48
- * ({@link isEmbeddedInPlatform}).
49
- */
50
- declare function isEmbeddedOnForeignSite(): boolean;
51
- /**
52
- * The site's wallet panel is the ONLY place a player can deposit/withdraw while this game is
53
- * embedded (see the module docblock above). After it completes an operation it posts
54
- * `{type: "IDOS_WALLET_BALANCE_CHANGED"}` to this page — a game that wants its on-screen balance
55
- * to update without the player reloading should call this once (e.g. in its HUD/wallet-display
56
- * setup) and refresh from `client.blockchain.getUserState()` when it fires. A no-op when not
57
- * embedded (the site panel doesn't exist there to send it) or outside the browser.
58
- *
59
- * Returns an unsubscribe function.
60
- */
61
- declare function onWalletBalanceChanged(callback: () => void): () => void;
62
-
63
- /** Message names. Shared with `GameWalletLoginBridge` on the website — keep both in step. */
64
- declare const PLATFORM_WALLET_MESSAGES: {
65
- readonly addressRequest: "IDOS_PLATFORM_WALLET_ADDRESS_REQUEST";
66
- readonly addressResponse: "IDOS_PLATFORM_WALLET_ADDRESS_RESPONSE";
67
- readonly signRequest: "IDOS_PLATFORM_WALLET_SIGN_REQUEST";
68
- readonly signResponse: "IDOS_PLATFORM_WALLET_SIGN_RESPONSE";
69
- /** Sent by the site the moment it receives a request — "I am here, the player is choosing". */
70
- readonly ack: "IDOS_PLATFORM_WALLET_ACK";
71
- };
72
- /** Which of the site's wallets signs: its EVM connection or its Solana adapter. */
73
- type PlatformWalletFamily = "evm" | "solana";
74
- /**
75
- * The page around the game did not answer at all — an old site build without the bridge, or a
76
- * parent that is not the platform. The button shows a plain "not available here" for it.
77
- */
78
- declare const PLATFORM_WALLET_UNAVAILABLE = "PLATFORM_WALLET_UNAVAILABLE";
79
- interface LoginWithWalletViaPlatformParams {
80
- /** The (not yet authenticated) shared client. */
81
- client: IDosGamesClient;
82
- /** NetworkID (key of cfg.Blockchain.Networks) the wallet proves ownership on. */
83
- networkID: string;
84
- /** Which of the site's wallets to use. */
85
- family: PlatformWalletFamily;
86
- }
87
- /**
88
- * Full wallet sign-in for a game embedded on idosgames.com, signed by the site's own wallet
89
- * connection. Same result shape and stages as `loginWithWalletEvm` / `loginWithWalletSolana`:
90
- * `challenge` covers getting the address and the engine's message, `sign` the site's signature,
91
- * `login` the exchange for a session.
92
- */
93
- declare function loginWithWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<ClientState>>;
94
- /**
95
- * Attach a wallet to the LOGGED-IN account inside the idosgames.com frame — the site's wallet signs
96
- * the engine's link challenge (same message template as login, so the site's check accepts it). Used
97
- * by the play-access screen of a gated title; `data.PlayAccess` is the pass checked against this
98
- * wallet.
99
- */
100
- declare function linkWalletViaPlatform(params: LoginWithWalletViaPlatformParams): Promise<WalletLoginResult<WalletLinkResponse>>;
5
+ import { E as EvmBridgeClients } from './withdraw-BPbJQVNt.js';
6
+ export { D as DepositNft721EvmParams, a as DepositNftEvmParams, b as DepositTokenEvmParams, c as DepositTokenOnChainParams, W as WithdrawNftEvmParams, d as WithdrawTokenEvmParams, e as depositNftEvm, f as depositNftEvm721, g as depositTokenEvm, h as depositTokenOnChainEvm, i as ensureErc20Allowance, s as submitEvmNftWithdrawal, j as submitEvmNftWithdrawal721, k as submitEvmTokenWithdrawal, w as withdrawNftEvm, l as withdrawTokenEvm, m as writeAndWait } from './withdraw-BPbJQVNt.js';
7
+ import { IDosGamesClient, WalletLinkResponse, ClientState, BlockchainNetworkDefinition, CryptoShortfall, OperationResult } from '@idosgames/core';
8
+ export { D as DepositTokenSolanaParams, S as SolanaProgramAdapter, W as WithdrawTokenSolanaParams, d as depositTokenSolana, w as withdrawTokenSolana } from './bridge-CcNWVuIE.js';
101
9
 
102
10
  declare const rewardPoolAbi: readonly [{
103
11
  readonly type: "function";
@@ -499,4 +407,4 @@ declare function loginWithWalletSolana(params: LoginWithWalletSolanaParams): Pro
499
407
  */
500
408
  declare function linkWalletSolana(params: LoginWithWalletSolanaParams): Promise<WalletLoginResult<WalletLinkResponse>>;
501
409
 
502
- export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type LoginWithWalletViaPlatformParams, PLATFORM_WALLET_MESSAGES, PLATFORM_WALLET_UNAVAILABLE, type PayWithWalletParams, type PlatformWalletFamily, type SolanaMessageSigner, WALLET_USE_SITE_PANEL, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, isAiCoderPreview, isEmbeddedInPlatform, isEmbeddedOnForeignSite, linkWalletEvm, linkWalletSolana, linkWalletViaPlatform, loginWithWalletEvm, loginWithWalletSolana, loginWithWalletViaPlatform, onWalletBalanceChanged, payWithWalletEvm, rewardPoolAbi };
410
+ export { BridgeResult, EvmBridgeClients, type LoginWithWalletEvmParams, type LoginWithWalletSolanaParams, type PayWithWalletParams, type SolanaMessageSigner, WalletLoginResult, encodeNftDepositData, erc1155Abi, erc20Abi, erc721Abi, linkWalletEvm, linkWalletSolana, loginWithWalletEvm, loginWithWalletSolana, payWithWalletEvm, rewardPoolAbi };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export{j as depositNftEvm,k as depositNftEvm721,h as depositTokenEvm,i as depositTokenOnChainEvm,e as encodeNftDepositData,g as ensureErc20Allowance,c as erc1155Abi,b as erc20Abi,d as erc721Abi,r as linkWalletEvm,q as loginWithWalletEvm,s as payWithWalletEvm,a as rewardPoolAbi,m as submitEvmNftWithdrawal,n as submitEvmNftWithdrawal721,l as submitEvmTokenWithdrawal,p as withdrawNftEvm,o as withdrawTokenEvm,f as writeAndWait}from'./chunk-YTTVLBAW.js';export{a as PLATFORM_WALLET_MESSAGES,b as PLATFORM_WALLET_UNAVAILABLE,d as linkWalletViaPlatform,c as loginWithWalletViaPlatform}from'./chunk-Q2E7DE4S.js';export{a as depositTokenSolana,d as linkWalletSolana,c as loginWithWalletSolana,b as withdrawTokenSolana}from'./chunk-MLIXKTS6.js';export{d as WALLET_USE_SITE_PANEL,o as arbitrum,n as base,b as bridgeFail,l as bsc,t as chainById,s as idosChains,e as isAiCoderPreview,f as isEmbeddedInPlatform,g as isEmbeddedOnForeignSite,k as mainnet,j as onWalletBalanceChanged,p as optimism,m as polygon,r as polygonAmoy,q as sepolia,w as solanaDevnet,v as solanaMainnet,u as toAppKitNetwork,a as toErrorMessage,c as walletLoginFail}from'./chunk-K3THMWU2.js';
1
+ export{j as depositNftEvm,k as depositNftEvm721,h as depositTokenEvm,i as depositTokenOnChainEvm,e as encodeNftDepositData,g as ensureErc20Allowance,c as erc1155Abi,b as erc20Abi,d as erc721Abi,r as linkWalletEvm,q as loginWithWalletEvm,s as payWithWalletEvm,a as rewardPoolAbi,m as submitEvmNftWithdrawal,n as submitEvmNftWithdrawal721,l as submitEvmTokenWithdrawal,p as withdrawNftEvm,o as withdrawTokenEvm,f as writeAndWait}from'./chunk-YTTVLBAW.js';export{a as PLATFORM_WALLET_MESSAGES,b as PLATFORM_WALLET_UNAVAILABLE,e as linkWalletViaPlatform,d as loginWithWalletViaPlatform,c as openPlatformWalletPanel}from'./chunk-D2ZPJ33L.js';export{a as depositTokenSolana,d as linkWalletSolana,c as loginWithWalletSolana,b as withdrawTokenSolana}from'./chunk-MLIXKTS6.js';export{d as WALLET_USE_SITE_PANEL,o as arbitrum,n as base,b as bridgeFail,l as bsc,t as chainById,s as idosChains,e as isAiCoderPreview,f as isEmbeddedInPlatform,g as isEmbeddedOnForeignSite,k as mainnet,j as onWalletBalanceChanged,p as optimism,m as polygon,r as polygonAmoy,q as sepolia,w as solanaDevnet,v as solanaMainnet,u as toAppKitNetwork,a as toErrorMessage,c as walletLoginFail}from'./chunk-K3THMWU2.js';