@idosgames/wallet 0.1.6 → 0.1.8

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.
@@ -0,0 +1,99 @@
1
+ import { SolanaAdapter } from '@reown/appkit-adapter-solana';
2
+ import { BaseWalletAdapter } from '@solana/wallet-adapter-base';
3
+ import { a as AppKitSolanaNetwork } from '../chains-B_P3u8_S.js';
4
+ export { g as solanaDevnet, h as solanaMainnet } from '../chains-B_P3u8_S.js';
5
+ import { ClientState, DepositTokenResponse, TokenWithdrawalResponse, IDosGamesClient } from '@idosgames/core';
6
+ import { D as DepositTokenSolanaParams, W as WithdrawTokenSolanaParams, S as SolanaProgramAdapter } from '../bridge-BJnRn3NX.js';
7
+ import { W as WalletLoginResult, a as BridgeResult } from '../types-C11zAA05.js';
8
+ import { CSSProperties, ReactNode } from 'react';
9
+ import 'viem';
10
+
11
+ interface SolanaWalletConfigOptions {
12
+ /**
13
+ * WalletConnect Cloud / Reown project id. Required: it is what gives phones a working wallet at
14
+ * all. Solana's own Mobile Wallet Adapter is Android-only — on iOS a plain web page cannot reach
15
+ * a wallet app except through WalletConnect deep-links (or the wallet's in-app browser).
16
+ */
17
+ walletConnectProjectId: string;
18
+ /** Networks the title supports. Defaults to Solana mainnet. */
19
+ networks?: [AppKitSolanaNetwork, ...AppKitSolanaNetwork[]];
20
+ /** App name/metadata shown in the wallet's connect prompt. */
21
+ appName?: string;
22
+ appUrl?: string;
23
+ appIcon?: string;
24
+ /**
25
+ * Extra standard Solana wallet adapters (Phantom, Solflare, Mobile Wallet Adapter…).
26
+ *
27
+ * These do NOT replace the WalletConnect path — AppKit runs both: adapters cover browser
28
+ * extensions, wallet in-app browsers and Android's MWA, while WalletConnect covers iOS and any
29
+ * wallet the player has not installed as an extension. Wallet Standard already auto-detects most
30
+ * installed wallets, so this is only needed for ones that do not announce themselves.
31
+ */
32
+ wallets?: BaseWalletAdapter[];
33
+ }
34
+ /**
35
+ * Builds the Solana wallet stack for a title, on **Reown AppKit** — the same modal, session and
36
+ * deep-link machinery the EVM side uses, so both chains behave identically on a phone.
37
+ *
38
+ * A title is EVM or Solana, so exactly one of {@link createEvmWalletConfig} /
39
+ * `createSolanaWalletConfig` runs per game; both register the shared AppKit instance the sign-in
40
+ * button opens.
41
+ */
42
+ declare function createSolanaWalletConfig(options: SolanaWalletConfigOptions): SolanaAdapter;
43
+
44
+ type DepositTokenArgs = Omit<DepositTokenSolanaParams, "client" | "adapter" | "titleID">;
45
+ /** `walletAddress` defaults to the connected wallet if omitted. */
46
+ type WithdrawTokenArgs = Omit<WithdrawTokenSolanaParams, "client" | "adapter" | "walletAddress"> & {
47
+ walletAddress?: string;
48
+ };
49
+ interface SolanaBridge {
50
+ connected: boolean;
51
+ account: string | null;
52
+ /**
53
+ * Logs into the game with the connected Solana wallet by signing a server challenge (no tx, no
54
+ * fee). `networkID` is the cfg.Blockchain.Networks key; `walletAddress` defaults to the connected
55
+ * account. Requires a wallet that supports `signMessage`. Returns the fresh ClientState.
56
+ */
57
+ loginWithWallet(networkID: string, walletAddress?: string): Promise<WalletLoginResult<ClientState>>;
58
+ depositToken(args: DepositTokenArgs): Promise<BridgeResult<DepositTokenResponse>>;
59
+ withdrawToken(args: WithdrawTokenArgs): Promise<BridgeResult<TokenWithdrawalResponse>>;
60
+ }
61
+ /**
62
+ * The ergonomic Solana bridge hook: binds the connected wallet-adapter wallet + your
63
+ * {@link SolanaProgramAdapter} to the deposit/withdraw flows against a core client + title.
64
+ * The on-chain instruction building lives in the adapter (it owns the program IDL); this hook
65
+ * just wires the connected address and threads the request → submit → confirm lifecycle.
66
+ */
67
+ declare function useSolanaBridge(client: IDosGamesClient, titleID: string, adapter: SolanaProgramAdapter): SolanaBridge;
68
+
69
+ interface SolanaWalletLoginProps {
70
+ /** The (not yet authenticated) shared client. */
71
+ client: IDosGamesClient;
72
+ /** NetworkID the challenge is issued for — one of the title's configured networks. */
73
+ networkID: string;
74
+ /** Called once the wallet signature has been exchanged for a session. */
75
+ onAuthenticated: () => void;
76
+ disabled?: boolean;
77
+ label?: string;
78
+ style?: CSSProperties;
79
+ /**
80
+ * Fire the sign-in immediately on mount instead of waiting for a click. Used by the lazy wrapper,
81
+ * which already consumed the player's click to load this module — a second tap would be a bug.
82
+ */
83
+ autoStart?: boolean;
84
+ }
85
+ /**
86
+ * Ready-made "sign in with wallet" button for **Solana** titles: connect → sign the challenge →
87
+ * session. The EVM twin is {@link WalletLogin}; a title is one or the other.
88
+ *
89
+ * Unlike the EVM button this needs no provider wrapper — AppKit is a global instance created by
90
+ * `createSolanaWalletConfig`, and the wallet is read through its hooks.
91
+ *
92
+ * Connecting and signing are one action for the player, but on a phone they are separated by an app
93
+ * switch: `appKit.open()` returns as soon as the modal is on screen, long before a wallet is picked
94
+ * and the deep-link round trip completes. So the click only *arms* the flow, and an effect fires the
95
+ * signature once the account actually appears — no polling, no second tap.
96
+ */
97
+ declare function SolanaWalletLogin(props: SolanaWalletLoginProps): ReactNode;
98
+
99
+ export { AppKitSolanaNetwork, type SolanaBridge, type SolanaWalletConfigOptions, SolanaWalletLogin, type SolanaWalletLoginProps, createSolanaWalletConfig, useSolanaBridge };
@@ -0,0 +1 @@
1
+ import {b,a as a$1,c}from'../chunk-44AGTUFV.js';import {a,b as b$2}from'../chunk-ZL42KPPC.js';import {b as b$1,c as c$1}from'../chunk-K62NMX3A.js';import {l}from'../chunk-HQNS6ZWL.js';export{m as solanaDevnet,l as solanaMainnet}from'../chunk-HQNS6ZWL.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 J(e){let{walletConnectProjectId:r,appName:n,appUrl:a$1,appIcon:i,wallets:t}=e,c=e.networks??[l],s=a$1??(typeof window<"u"?window.location.origin:""),o={name:n??"iDosGames",description:n??"iDosGames game",url:s,icons:i?[i]:[]},l$1=new SolanaAdapter(t?{wallets:t}:{});return a(createAppKit({adapters:[l$1],networks:c,projectId:r,metadata:o,features:{analytics:false,email:false,socials:false}})),l$1}var _="Wallet not connected.";function X(e,r,n){let{address:a}=useAppKitAccount(),{walletProvider:i}=useAppKitProvider("solana"),t=a??null,c$2=i?.signMessage?.bind(i);return {connected:!!t,account:t,loginWithWallet:(s,o)=>{let l=o??t;return l?c$2?c({client:e,networkID:s,walletAddress:l,signMessage:c$2}):Promise.resolve(c$1("sign","The connected wallet does not support message signing.")):Promise.resolve(c$1("challenge",_))},depositToken:s=>a$1({client:e,adapter:n,titleID:r,...s}),withdrawToken:s=>{let o=s.walletAddress??t;return o?b({client:e,adapter:n,...s,walletAddress:o}):Promise.resolve(b$1("request",_))}}}var $=18e4,ee=9e4;function te(e){try{let n=e?.session?.peer?.metadata?.redirect,a=n?.native||n?.universal;return !a||typeof window>"u"?!1:(window.location.href=a,!0)}catch{return false}}function ne(e,r){return new Promise((n,a)=>{let i=setTimeout(()=>a(new Error("The wallet request timed out.")),r);e.then(t=>{clearTimeout(i),n(t);},t=>{clearTimeout(i),a(t instanceof Error?t:new Error(String(t)));});})}function oe(e){let r="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.":r:r}function re(e){let{client:r,networkID:n,onAuthenticated:a,disabled:i,label:t,style:c$1,autoStart:s}=e,{address:o,isConnected:l}=useAppKitAccount(),{walletProvider:p}=useAppKitProvider("solana"),[q,f]=useState(false),[D,d]=useState(null),[I,y]=useState(false),[K,x]=useState(false),m=useRef(null),N=useRef(0),g=useCallback(()=>{m.current&&clearTimeout(m.current),m.current=null;},[]);useEffect(()=>g,[g]);let k=useRef(false),A=useCallback(async()=>{let w=++N.current,W=()=>N.current===w,B=p?.signMessage?.bind(p);if(!o||!B){d("The connected wallet cannot sign messages."),f(false);return}f(true),d(null);try{x(!0);let u=await ne(c({client:r,networkID:n,walletAddress:o,signMessage:B}),ee);if(!W())return;if(u.ok){a();return}d(u.stage==="sign"?"Signature declined.":u.error??"Wallet sign-in failed.");}catch(u){if(!W())return;console.error("[idosgames/wallet] solana sign-in failed:",u),d(oe(u));}finally{W()&&(f(false),x(false));}},[o,p,r,n,a]),j=useCallback(()=>{te(p)||b$2()?.open();},[p]);useEffect(()=>{!I||!l||!o||!p||(y(false),g(),A());},[I,l,o,p,A,g]);let E=()=>{if(K){j();return}if(d(null),k.current=true,l&&o&&p){A();return}let w=b$2();if(!w){d("Wallet sign-in is not configured for this title.");return}f(true),y(true),g(),m.current=setTimeout(()=>{y(false),f(false),d("No wallet was connected.");},$),w.open();};return useEffect(()=>{!s||k.current||(k.current=true,E());},[s]),jsxs(Fragment,{children:[jsx("button",{type:"button",onClick:E,disabled:i,style:{...ae,...i?{opacity:.6,cursor:"default"}:null,...c$1},children:K?"Waiting for signature \u2014 tap to open wallet":q?"Check your wallet\u2026":l?t??"Sign in with wallet":"Connect wallet"}),D&&jsx("span",{role:"alert",style:ie,children:D})]})}var ae={padding:"11px 16px",borderRadius:"8px",border:"none",background:"#4c3fa8",color:"#fff",font:"inherit",fontWeight:600,cursor:"pointer"},ie={display:"block",marginTop:"6px",color:"#ff9b9b",fontSize:"13px",textAlign:"center"};export{re as SolanaWalletLogin,J as createSolanaWalletConfig,X as useSolanaBridge};
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Where a multi-step bridge flow stopped. Deposits run approve → deposit-onchain → report;
3
+ * withdrawals run request → withdraw-onchain → confirm. Knowing the stage lets a UI recover
4
+ * correctly (e.g. a failed `withdraw-onchain` after a successful `request` means the asset is
5
+ * already debited — offer `retryWithdrawal`, never a fresh request that would debit twice).
6
+ */
7
+ type BridgeStage = "approve" | "deposit-onchain" | "report" | "request" | "withdraw-onchain" | "confirm";
8
+ interface BridgeSuccess<T> {
9
+ ok: true;
10
+ /** Hash/signature of the on-chain transaction that moved the asset (EVM hex or Solana base58). */
11
+ onChainTxHash: string;
12
+ /** The core SDK response that finalized the operation server-side. */
13
+ data: T;
14
+ }
15
+ interface BridgeFailure {
16
+ ok: false;
17
+ stage: BridgeStage;
18
+ error: string;
19
+ /**
20
+ * Set when the asset-moving on-chain tx already landed but a later step failed — the caller can
21
+ * finish the flow with this hash (e.g. re-call `confirmWithdrawal`) instead of restarting.
22
+ */
23
+ onChainTxHash?: string;
24
+ /**
25
+ * Set for a withdrawal whose server-side `request` already succeeded (and already debited the
26
+ * player) but whose on-chain/confirm leg failed. Recover with `client.blockchain.retryWithdrawal`
27
+ * (before ExpiresAt) or `confirmWithdrawal` (if the tx actually landed) — NOT a fresh request.
28
+ */
29
+ titleTransactionID?: string;
30
+ }
31
+ type BridgeResult<T> = BridgeSuccess<T> | BridgeFailure;
32
+ /** Normalizes a thrown value (viem error, plain Error, or unknown) into a short human string. */
33
+ declare function toErrorMessage(e: unknown): string;
34
+ declare function bridgeFail(stage: BridgeStage, error: string, extra?: {
35
+ onChainTxHash?: string;
36
+ titleTransactionID?: string;
37
+ }): BridgeFailure;
38
+ /**
39
+ * Where a wallet-login flow stopped. `challenge` = fetching the message to sign; `sign` = the
40
+ * wallet signing it (user may reject); `login` = exchanging the signature for a session. Unlike
41
+ * a bridge flow there is no on-chain transaction — this is an off-chain proof of ownership.
42
+ */
43
+ type WalletLoginStage = "challenge" | "sign" | "login";
44
+ interface WalletLoginSuccess<T> {
45
+ ok: true;
46
+ /** The core SDK result of the successful login (the fresh ClientState). */
47
+ data: T;
48
+ }
49
+ interface WalletLoginFailure {
50
+ ok: false;
51
+ stage: WalletLoginStage;
52
+ error: string;
53
+ }
54
+ type WalletLoginResult<T> = WalletLoginSuccess<T> | WalletLoginFailure;
55
+ declare function walletLoginFail(stage: WalletLoginStage, error: string): WalletLoginFailure;
56
+
57
+ export { type BridgeFailure as B, type WalletLoginResult as W, type BridgeResult 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 };
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Where a multi-step bridge flow stopped. Deposits run approve → deposit-onchain → report;
3
+ * withdrawals run request → withdraw-onchain → confirm. Knowing the stage lets a UI recover
4
+ * correctly (e.g. a failed `withdraw-onchain` after a successful `request` means the asset is
5
+ * already debited — offer `retryWithdrawal`, never a fresh request that would debit twice).
6
+ */
7
+ type BridgeStage = "approve" | "deposit-onchain" | "report" | "request" | "withdraw-onchain" | "confirm";
8
+ interface BridgeSuccess<T> {
9
+ ok: true;
10
+ /** Hash/signature of the on-chain transaction that moved the asset (EVM hex or Solana base58). */
11
+ onChainTxHash: string;
12
+ /** The core SDK response that finalized the operation server-side. */
13
+ data: T;
14
+ }
15
+ interface BridgeFailure {
16
+ ok: false;
17
+ stage: BridgeStage;
18
+ error: string;
19
+ /**
20
+ * Set when the asset-moving on-chain tx already landed but a later step failed — the caller can
21
+ * finish the flow with this hash (e.g. re-call `confirmWithdrawal`) instead of restarting.
22
+ */
23
+ onChainTxHash?: string;
24
+ /**
25
+ * Set for a withdrawal whose server-side `request` already succeeded (and already debited the
26
+ * player) but whose on-chain/confirm leg failed. Recover with `client.blockchain.retryWithdrawal`
27
+ * (before ExpiresAt) or `confirmWithdrawal` (if the tx actually landed) — NOT a fresh request.
28
+ */
29
+ titleTransactionID?: string;
30
+ }
31
+ type BridgeResult<T> = BridgeSuccess<T> | BridgeFailure;
32
+ /** Normalizes a thrown value (viem error, plain Error, or unknown) into a short human string. */
33
+ declare function toErrorMessage(e: unknown): string;
34
+ declare function bridgeFail(stage: BridgeStage, error: string, extra?: {
35
+ onChainTxHash?: string;
36
+ titleTransactionID?: string;
37
+ }): BridgeFailure;
38
+ /**
39
+ * Where a wallet-login flow stopped. `challenge` = fetching the message to sign; `sign` = the
40
+ * wallet signing it (user may reject); `login` = exchanging the signature for a session. Unlike
41
+ * a bridge flow there is no on-chain transaction — this is an off-chain proof of ownership.
42
+ */
43
+ type WalletLoginStage = "challenge" | "sign" | "login";
44
+ interface WalletLoginSuccess<T> {
45
+ ok: true;
46
+ /** The core SDK result of the successful login (the fresh ClientState). */
47
+ data: T;
48
+ }
49
+ interface WalletLoginFailure {
50
+ ok: false;
51
+ stage: WalletLoginStage;
52
+ error: string;
53
+ }
54
+ type WalletLoginResult<T> = WalletLoginSuccess<T> | WalletLoginFailure;
55
+ declare function walletLoginFail(stage: WalletLoginStage, error: string): WalletLoginFailure;
56
+
57
+ export { type BridgeFailure as B, type WalletLoginResult as W, type BridgeResult 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 };
@@ -0,0 +1,148 @@
1
+ import { PublicClient, WalletClient, Address, Abi, ContractFunctionName, ContractFunctionArgs, Hex } from 'viem';
2
+ import { IDosGamesClient, BlockchainNetworkDefinition, DepositNFTResponse, DepositTokenResponse, WithdrawalSignatureResponse, NFTWithdrawalResponse, TokenWithdrawalResponse } from '@idosgames/core';
3
+ import { a as BridgeResult } from './types-C11zAA05.js';
4
+
5
+ /**
6
+ * The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
7
+ * `usePublicClient()`, `useWalletClient().data`, and `useAccount().address`. Kept as plain viem
8
+ * types so the framework-agnostic core never imports wagmi/React.
9
+ */
10
+ interface EvmBridgeClients {
11
+ publicClient: PublicClient;
12
+ walletClient: WalletClient;
13
+ /** The connected wallet address that signs and pays for the transactions. */
14
+ account: Address;
15
+ }
16
+ /**
17
+ * Sends a contract write and waits for its receipt, returning the tx hash. Throws if the
18
+ * transaction reverts on-chain (so callers can attribute the failure to the on-chain stage).
19
+ */
20
+ declare function writeAndWait<const TAbi extends Abi, TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable">>(clients: EvmBridgeClients, request: {
21
+ address: Address;
22
+ abi: TAbi;
23
+ functionName: TFunctionName;
24
+ args: ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>;
25
+ value?: bigint;
26
+ }): Promise<Hex>;
27
+
28
+ /**
29
+ * Ensures the RewardPool is allowed to pull at least `amount` of an ERC-20 from `account`.
30
+ * Reads the current allowance and only sends an `approve` when it's short. Returns the approve
31
+ * tx hash if one was sent, or null when the existing allowance already covered the amount.
32
+ */
33
+ declare function ensureErc20Allowance(clients: EvmBridgeClients, tokenAddress: Address, spender: Address, amount: bigint): Promise<Hex | null>;
34
+ interface DepositTokenEvmParams {
35
+ client: IDosGamesClient;
36
+ clients: EvmBridgeClients;
37
+ network: BlockchainNetworkDefinition;
38
+ /** ERC-20 contract of the token being deposited (the RewardPool splits/credits it in-game). */
39
+ tokenAddress: Address;
40
+ /** Raw on-chain amount, already scaled by the token's decimals (use viem `parseUnits`). */
41
+ amount: bigint;
42
+ /** The title the client was created for (not exposed on the client — pass it through). */
43
+ titleID: string;
44
+ /** Operation kind; defaults to "game_topup" server-side. Deposits echo it into the tx. */
45
+ category?: string;
46
+ }
47
+ /**
48
+ * Full EVM token-deposit flow: approve (if needed) → `depositERC20(token, amount, userID,
49
+ * titleID, category)` on the RewardPool → report the tx hash to the backend so it verifies the
50
+ * transfer and credits the in-game crypto balance. On success the core cache balance is already
51
+ * updated by `client.blockchain.depositToken`.
52
+ */
53
+ declare function depositTokenEvm(params: DepositTokenEvmParams): Promise<BridgeResult<DepositTokenResponse>>;
54
+ interface DepositNftEvmParams {
55
+ client: IDosGamesClient;
56
+ clients: EvmBridgeClients;
57
+ network: BlockchainNetworkDefinition;
58
+ /** ERC-1155 collection contract holding the NFT. */
59
+ nftContractAddress: Address;
60
+ /** On-chain token id of the NFT being deposited. */
61
+ tokenId: bigint;
62
+ /** Copies to transfer (1 for a unique NFT; ERC-1155 collections can hold fungible editions). */
63
+ amount: bigint;
64
+ titleID: string;
65
+ category?: string;
66
+ }
67
+ /**
68
+ * Full EVM NFT-deposit flow: `safeTransferFrom(account, pool, id, amount, data)` on the ERC-1155
69
+ * collection — where `data = abi.encode(userID, titleID, category)` — then report the tx hash so
70
+ * the backend verifies the transfer and grants the matching in-game item. No operator approval is
71
+ * needed: the player transfers their own token, so msg.sender == from.
72
+ */
73
+ declare function depositNftEvm(params: DepositNftEvmParams): Promise<BridgeResult<DepositNFTResponse>>;
74
+ interface DepositNft721EvmParams {
75
+ client: IDosGamesClient;
76
+ clients: EvmBridgeClients;
77
+ network: BlockchainNetworkDefinition;
78
+ /** ERC-721 collection contract holding the NFT. */
79
+ nftContractAddress: Address;
80
+ /** On-chain token id of the unique NFT being deposited. */
81
+ tokenId: bigint;
82
+ titleID: string;
83
+ category?: string;
84
+ }
85
+ /**
86
+ * Full EVM ERC-721 NFT-deposit flow: `safeTransferFrom(account, pool, tokenId, data)` on the
87
+ * ERC-721 collection — where `data = abi.encode(userID, titleID, category)` — then report the tx
88
+ * hash so the backend verifies the transfer and grants the matching in-game unique item. No
89
+ * operator approval is needed: the player transfers their own token, so msg.sender == from.
90
+ */
91
+ declare function depositNftEvm721(params: DepositNft721EvmParams): Promise<BridgeResult<DepositNFTResponse>>;
92
+
93
+ /**
94
+ * Submits a server-signed ERC-20 withdrawal on-chain by calling `withdrawERC20` on the RewardPool.
95
+ * Every field comes straight from the server's {@link WithdrawalSignatureResponse}; the client
96
+ * only echoes them (Amount and Nonce are decimal strings the server already scaled to raw units,
97
+ * and userID/titleID/category are part of the signed hash — passing anything else reverts). Use
98
+ * this directly to submit a fresh signature from `retryWithdrawal`.
99
+ */
100
+ declare function submitEvmTokenWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
101
+ /**
102
+ * Submits a server-signed ERC-1155 game-NFT withdrawal on-chain. The v2 backend signs a MINT voucher
103
+ * (tag "ERC1155_MINT") against the ItemBridge — `sig.ContractAddress` is the bridge and
104
+ * `sig.TokenAddress` is the collection — so this calls `withdrawERC1155Mint`, NOT RewardPool's
105
+ * `withdrawERC1155` (which would fail the selector/hash-tag check).
106
+ */
107
+ declare function submitEvmNftWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
108
+ /**
109
+ * Submits a server-signed ERC-721 unique game-NFT withdrawal on-chain via the ItemBridge's
110
+ * `withdrawERC721Mint` (MINT voucher, tag "ERC721_MINT"; `sig.ContractAddress` = bridge,
111
+ * `sig.TokenAddress` = collection) — not RewardPool's custody `withdrawERC721`.
112
+ */
113
+ declare function submitEvmNftWithdrawal721(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
114
+ interface WithdrawTokenEvmParams {
115
+ client: IDosGamesClient;
116
+ clients: EvmBridgeClients;
117
+ currencyID: string;
118
+ networkID: string;
119
+ /** Destination wallet — usually the connected `clients.account`. */
120
+ walletAddress: string;
121
+ /** Human decimal amount to withdraw (the server converts and signs raw units). */
122
+ amount: string;
123
+ category?: string;
124
+ }
125
+ /**
126
+ * Full EVM token-withdrawal flow: `requestTokenWithdrawal` (debits in-game immediately and returns
127
+ * a signed payload) → `withdrawERC20` on-chain → `confirmWithdrawal` with the resulting hash.
128
+ *
129
+ * On a failure AFTER the request succeeded, the returned {@link BridgeFailure} carries
130
+ * `titleTransactionID` (the asset is already debited — recover with `retryWithdrawal` while
131
+ * Pending, or `confirmWithdrawal` if the tx actually landed) and, when the on-chain leg landed,
132
+ * `onChainTxHash`. Never restart with a fresh `requestTokenWithdrawal` — that debits twice.
133
+ */
134
+ declare function withdrawTokenEvm(params: WithdrawTokenEvmParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
135
+ interface WithdrawNftEvmParams {
136
+ client: IDosGamesClient;
137
+ clients: EvmBridgeClients;
138
+ itemID: string;
139
+ networkID: string;
140
+ walletAddress: string;
141
+ /** Copies to withdraw, as an integer string (usually "1"). */
142
+ amount: string;
143
+ category?: string;
144
+ }
145
+ /** Full EVM NFT-withdrawal flow: `requestNFTWithdrawal` → `withdrawERC1155` → `confirmWithdrawal`. */
146
+ declare function withdrawNftEvm(params: WithdrawNftEvmParams): Promise<BridgeResult<NFTWithdrawalResponse>>;
147
+
148
+ export { type DepositNft721EvmParams as D, type EvmBridgeClients as E, type WithdrawNftEvmParams as W, type DepositNftEvmParams as a, type DepositTokenEvmParams as b, type WithdrawTokenEvmParams as c, depositNftEvm as d, depositNftEvm721 as e, depositTokenEvm as f, ensureErc20Allowance as g, submitEvmNftWithdrawal721 as h, submitEvmTokenWithdrawal as i, withdrawTokenEvm as j, writeAndWait as k, submitEvmNftWithdrawal as s, withdrawNftEvm as w };
@@ -0,0 +1,148 @@
1
+ import { PublicClient, WalletClient, Address, Abi, ContractFunctionName, ContractFunctionArgs, Hex } from 'viem';
2
+ import { IDosGamesClient, BlockchainNetworkDefinition, DepositNFTResponse, DepositTokenResponse, WithdrawalSignatureResponse, NFTWithdrawalResponse, TokenWithdrawalResponse } from '@idosgames/core';
3
+ import { a as BridgeResult } from './types-C11zAA05.cjs';
4
+
5
+ /**
6
+ * The viem clients + signing account the EVM bridge needs. wagmi supplies all three:
7
+ * `usePublicClient()`, `useWalletClient().data`, and `useAccount().address`. Kept as plain viem
8
+ * types so the framework-agnostic core never imports wagmi/React.
9
+ */
10
+ interface EvmBridgeClients {
11
+ publicClient: PublicClient;
12
+ walletClient: WalletClient;
13
+ /** The connected wallet address that signs and pays for the transactions. */
14
+ account: Address;
15
+ }
16
+ /**
17
+ * Sends a contract write and waits for its receipt, returning the tx hash. Throws if the
18
+ * transaction reverts on-chain (so callers can attribute the failure to the on-chain stage).
19
+ */
20
+ declare function writeAndWait<const TAbi extends Abi, TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable">>(clients: EvmBridgeClients, request: {
21
+ address: Address;
22
+ abi: TAbi;
23
+ functionName: TFunctionName;
24
+ args: ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>;
25
+ value?: bigint;
26
+ }): Promise<Hex>;
27
+
28
+ /**
29
+ * Ensures the RewardPool is allowed to pull at least `amount` of an ERC-20 from `account`.
30
+ * Reads the current allowance and only sends an `approve` when it's short. Returns the approve
31
+ * tx hash if one was sent, or null when the existing allowance already covered the amount.
32
+ */
33
+ declare function ensureErc20Allowance(clients: EvmBridgeClients, tokenAddress: Address, spender: Address, amount: bigint): Promise<Hex | null>;
34
+ interface DepositTokenEvmParams {
35
+ client: IDosGamesClient;
36
+ clients: EvmBridgeClients;
37
+ network: BlockchainNetworkDefinition;
38
+ /** ERC-20 contract of the token being deposited (the RewardPool splits/credits it in-game). */
39
+ tokenAddress: Address;
40
+ /** Raw on-chain amount, already scaled by the token's decimals (use viem `parseUnits`). */
41
+ amount: bigint;
42
+ /** The title the client was created for (not exposed on the client — pass it through). */
43
+ titleID: string;
44
+ /** Operation kind; defaults to "game_topup" server-side. Deposits echo it into the tx. */
45
+ category?: string;
46
+ }
47
+ /**
48
+ * Full EVM token-deposit flow: approve (if needed) → `depositERC20(token, amount, userID,
49
+ * titleID, category)` on the RewardPool → report the tx hash to the backend so it verifies the
50
+ * transfer and credits the in-game crypto balance. On success the core cache balance is already
51
+ * updated by `client.blockchain.depositToken`.
52
+ */
53
+ declare function depositTokenEvm(params: DepositTokenEvmParams): Promise<BridgeResult<DepositTokenResponse>>;
54
+ interface DepositNftEvmParams {
55
+ client: IDosGamesClient;
56
+ clients: EvmBridgeClients;
57
+ network: BlockchainNetworkDefinition;
58
+ /** ERC-1155 collection contract holding the NFT. */
59
+ nftContractAddress: Address;
60
+ /** On-chain token id of the NFT being deposited. */
61
+ tokenId: bigint;
62
+ /** Copies to transfer (1 for a unique NFT; ERC-1155 collections can hold fungible editions). */
63
+ amount: bigint;
64
+ titleID: string;
65
+ category?: string;
66
+ }
67
+ /**
68
+ * Full EVM NFT-deposit flow: `safeTransferFrom(account, pool, id, amount, data)` on the ERC-1155
69
+ * collection — where `data = abi.encode(userID, titleID, category)` — then report the tx hash so
70
+ * the backend verifies the transfer and grants the matching in-game item. No operator approval is
71
+ * needed: the player transfers their own token, so msg.sender == from.
72
+ */
73
+ declare function depositNftEvm(params: DepositNftEvmParams): Promise<BridgeResult<DepositNFTResponse>>;
74
+ interface DepositNft721EvmParams {
75
+ client: IDosGamesClient;
76
+ clients: EvmBridgeClients;
77
+ network: BlockchainNetworkDefinition;
78
+ /** ERC-721 collection contract holding the NFT. */
79
+ nftContractAddress: Address;
80
+ /** On-chain token id of the unique NFT being deposited. */
81
+ tokenId: bigint;
82
+ titleID: string;
83
+ category?: string;
84
+ }
85
+ /**
86
+ * Full EVM ERC-721 NFT-deposit flow: `safeTransferFrom(account, pool, tokenId, data)` on the
87
+ * ERC-721 collection — where `data = abi.encode(userID, titleID, category)` — then report the tx
88
+ * hash so the backend verifies the transfer and grants the matching in-game unique item. No
89
+ * operator approval is needed: the player transfers their own token, so msg.sender == from.
90
+ */
91
+ declare function depositNftEvm721(params: DepositNft721EvmParams): Promise<BridgeResult<DepositNFTResponse>>;
92
+
93
+ /**
94
+ * Submits a server-signed ERC-20 withdrawal on-chain by calling `withdrawERC20` on the RewardPool.
95
+ * Every field comes straight from the server's {@link WithdrawalSignatureResponse}; the client
96
+ * only echoes them (Amount and Nonce are decimal strings the server already scaled to raw units,
97
+ * and userID/titleID/category are part of the signed hash — passing anything else reverts). Use
98
+ * this directly to submit a fresh signature from `retryWithdrawal`.
99
+ */
100
+ declare function submitEvmTokenWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
101
+ /**
102
+ * Submits a server-signed ERC-1155 game-NFT withdrawal on-chain. The v2 backend signs a MINT voucher
103
+ * (tag "ERC1155_MINT") against the ItemBridge — `sig.ContractAddress` is the bridge and
104
+ * `sig.TokenAddress` is the collection — so this calls `withdrawERC1155Mint`, NOT RewardPool's
105
+ * `withdrawERC1155` (which would fail the selector/hash-tag check).
106
+ */
107
+ declare function submitEvmNftWithdrawal(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
108
+ /**
109
+ * Submits a server-signed ERC-721 unique game-NFT withdrawal on-chain via the ItemBridge's
110
+ * `withdrawERC721Mint` (MINT voucher, tag "ERC721_MINT"; `sig.ContractAddress` = bridge,
111
+ * `sig.TokenAddress` = collection) — not RewardPool's custody `withdrawERC721`.
112
+ */
113
+ declare function submitEvmNftWithdrawal721(clients: EvmBridgeClients, sig: WithdrawalSignatureResponse): Promise<Hex>;
114
+ interface WithdrawTokenEvmParams {
115
+ client: IDosGamesClient;
116
+ clients: EvmBridgeClients;
117
+ currencyID: string;
118
+ networkID: string;
119
+ /** Destination wallet — usually the connected `clients.account`. */
120
+ walletAddress: string;
121
+ /** Human decimal amount to withdraw (the server converts and signs raw units). */
122
+ amount: string;
123
+ category?: string;
124
+ }
125
+ /**
126
+ * Full EVM token-withdrawal flow: `requestTokenWithdrawal` (debits in-game immediately and returns
127
+ * a signed payload) → `withdrawERC20` on-chain → `confirmWithdrawal` with the resulting hash.
128
+ *
129
+ * On a failure AFTER the request succeeded, the returned {@link BridgeFailure} carries
130
+ * `titleTransactionID` (the asset is already debited — recover with `retryWithdrawal` while
131
+ * Pending, or `confirmWithdrawal` if the tx actually landed) and, when the on-chain leg landed,
132
+ * `onChainTxHash`. Never restart with a fresh `requestTokenWithdrawal` — that debits twice.
133
+ */
134
+ declare function withdrawTokenEvm(params: WithdrawTokenEvmParams): Promise<BridgeResult<TokenWithdrawalResponse>>;
135
+ interface WithdrawNftEvmParams {
136
+ client: IDosGamesClient;
137
+ clients: EvmBridgeClients;
138
+ itemID: string;
139
+ networkID: string;
140
+ walletAddress: string;
141
+ /** Copies to withdraw, as an integer string (usually "1"). */
142
+ amount: string;
143
+ category?: string;
144
+ }
145
+ /** Full EVM NFT-withdrawal flow: `requestNFTWithdrawal` → `withdrawERC1155` → `confirmWithdrawal`. */
146
+ declare function withdrawNftEvm(params: WithdrawNftEvmParams): Promise<BridgeResult<NFTWithdrawalResponse>>;
147
+
148
+ export { type DepositNft721EvmParams as D, type EvmBridgeClients as E, type WithdrawNftEvmParams as W, type DepositNftEvmParams as a, type DepositTokenEvmParams as b, type WithdrawTokenEvmParams as c, depositNftEvm as d, depositNftEvm721 as e, depositTokenEvm as f, ensureErc20Allowance as g, submitEvmNftWithdrawal721 as h, submitEvmTokenWithdrawal as i, withdrawTokenEvm as j, writeAndWait as k, submitEvmNftWithdrawal as s, withdrawNftEvm as w };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idosgames/wallet",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
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",
@@ -42,6 +42,16 @@
42
42
  "types": "./dist/react/index.d.ts",
43
43
  "import": "./dist/react/index.js",
44
44
  "require": "./dist/react/index.cjs"
45
+ },
46
+ "./react/solana": {
47
+ "types": "./dist/react/solanaIndex.d.ts",
48
+ "import": "./dist/react/solanaIndex.js",
49
+ "require": "./dist/react/solanaIndex.cjs"
50
+ },
51
+ "./react/lazy": {
52
+ "types": "./dist/react/lazyIndex.d.ts",
53
+ "import": "./dist/react/lazyIndex.js",
54
+ "require": "./dist/react/lazyIndex.cjs"
45
55
  }
46
56
  },
47
57
  "files": [
@@ -57,14 +67,12 @@
57
67
  "dependencies": {
58
68
  "@idosgames/core": "^0.1.1",
59
69
  "@reown/appkit": "^1.8.23",
70
+ "@reown/appkit-adapter-solana": "^1.8.23",
60
71
  "@reown/appkit-adapter-wagmi": "^1.8.23",
61
- "@solana/web3.js": "^1.98.4",
62
- "@walletconnect/ethereum-provider": "^2.21.1",
63
72
  "viem": "^2.55.2"
64
73
  },
65
74
  "peerDependencies": {
66
75
  "@solana/wallet-adapter-base": "^0.9.27",
67
- "@solana/wallet-adapter-react": "^0.15.39",
68
76
  "@tanstack/react-query": "^5.101.2",
69
77
  "react": "^18.3.1 || ^19.0.0",
70
78
  "wagmi": "^3.0.0"
@@ -81,9 +89,6 @@
81
89
  },
82
90
  "@solana/wallet-adapter-base": {
83
91
  "optional": true
84
- },
85
- "@solana/wallet-adapter-react": {
86
- "optional": true
87
92
  }
88
93
  },
89
94
  "devDependencies": {