@dimcool/sdk 0.1.22 → 0.1.26
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 +63 -31
- package/dist/index.cjs +582 -21899
- package/dist/index.d.cts +119 -6
- package/dist/index.d.ts +119 -6
- package/dist/index.js +538 -21866
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -935,16 +935,23 @@ The wallet module provides functionality for managing Solana wallets, checking b
|
|
|
935
935
|
|
|
936
936
|
### WalletSigner Interface
|
|
937
937
|
|
|
938
|
-
The SDK exposes a `WalletSigner` interface for transaction and message signing
|
|
938
|
+
The SDK exposes a `WalletSigner` interface for transaction and message signing. A signer provides exactly one of `signTransaction` or `signAndSendTransaction`:
|
|
939
939
|
|
|
940
940
|
```typescript
|
|
941
941
|
interface WalletSigner {
|
|
942
|
+
address?: string;
|
|
942
943
|
signMessage: (message: string) => Promise<Uint8Array | string>;
|
|
943
|
-
signTransaction
|
|
944
|
+
signTransaction?: (transaction: Transaction) => Promise<Transaction>;
|
|
945
|
+
signAndSendTransaction?: (transaction: Transaction) => Promise<string>;
|
|
944
946
|
}
|
|
945
947
|
```
|
|
946
948
|
|
|
947
|
-
|
|
949
|
+
**Two signing modes:**
|
|
950
|
+
|
|
951
|
+
- **`signTransaction`** (server-sent) — the signer returns signed bytes; the server submits the transaction to the network. Used by `@dimcool/wallet` (keypair agents) and Phantom browser extensions.
|
|
952
|
+
- **`signAndSendTransaction`** (client-sent) — the signer signs AND submits the transaction, returning the signature. The SDK then calls a `confirm-signature` endpoint so the backend can track and confirm it via the queue. Used by Phantom embedded wallets (Google/Apple login).
|
|
953
|
+
|
|
954
|
+
The SDK detects the mode via `sdk.wallet.isSignAndSendMode()` and automatically routes `send()` and `depositForLobby()` through the correct path.
|
|
948
955
|
|
|
949
956
|
If you're building agents, you can use `@dimcool/wallet` and pass `wallet.getSigner()` directly:
|
|
950
957
|
|
|
@@ -964,12 +971,9 @@ sdk.wallet.setSigner(wallet.getSigner());
|
|
|
964
971
|
Configure the wallet signer. This must be called before any signing operations.
|
|
965
972
|
|
|
966
973
|
```typescript
|
|
967
|
-
// Example:
|
|
968
|
-
import { useSolana } from '@phantom/react-sdk';
|
|
969
|
-
|
|
970
|
-
const { solana } = useSolana();
|
|
971
|
-
|
|
974
|
+
// Example: Phantom extension (signTransaction — server submits)
|
|
972
975
|
sdk.wallet.setSigner({
|
|
976
|
+
address: connectedAddress,
|
|
973
977
|
signMessage: async (message: string) => {
|
|
974
978
|
return solana.signMessage(new TextEncoder().encode(message));
|
|
975
979
|
},
|
|
@@ -980,13 +984,28 @@ sdk.wallet.setSigner({
|
|
|
980
984
|
```
|
|
981
985
|
|
|
982
986
|
```typescript
|
|
983
|
-
// Example:
|
|
987
|
+
// Example: Phantom embedded / Google/Apple (signAndSendTransaction — client submits)
|
|
988
|
+
sdk.wallet.setSigner({
|
|
989
|
+
address: connectedAddress,
|
|
990
|
+
signMessage: async (message: string) => {
|
|
991
|
+
return solana.signMessage(new TextEncoder().encode(message));
|
|
992
|
+
},
|
|
993
|
+
signAndSendTransaction: async (transaction: Transaction) => {
|
|
994
|
+
const result = await solana.signAndSendTransaction(transaction);
|
|
995
|
+
return typeof result === 'string' ? result : result.signature;
|
|
996
|
+
},
|
|
997
|
+
});
|
|
998
|
+
```
|
|
999
|
+
|
|
1000
|
+
```typescript
|
|
1001
|
+
// Example: Using a Keypair (for bots/Node.js — signTransaction)
|
|
984
1002
|
import { Keypair } from '@solana/web3.js';
|
|
985
1003
|
import * as nacl from 'tweetnacl';
|
|
986
1004
|
|
|
987
1005
|
const keypair = Keypair.fromSecretKey(/* ... */);
|
|
988
1006
|
|
|
989
1007
|
sdk.wallet.setSigner({
|
|
1008
|
+
address: keypair.publicKey.toBase58(),
|
|
990
1009
|
signMessage: async (message: string) => {
|
|
991
1010
|
const messageBytes = new TextEncoder().encode(message);
|
|
992
1011
|
return nacl.sign.detached(messageBytes, keypair.secretKey);
|
|
@@ -1080,40 +1099,37 @@ const signature = await sdk.wallet.signMessage('Hello, world!');
|
|
|
1080
1099
|
|
|
1081
1100
|
### `signTransaction(transaction: Transaction): Promise<Transaction>`
|
|
1082
1101
|
|
|
1083
|
-
Sign a Solana transaction using the configured signer.
|
|
1102
|
+
Sign a Solana transaction using the configured signer. Only available when the signer provides `signTransaction`.
|
|
1084
1103
|
|
|
1085
1104
|
```typescript
|
|
1086
|
-
import { Transaction } from '@solana/web3.js';
|
|
1087
|
-
|
|
1088
|
-
const unsignedTransaction = Transaction.from(/* ... */);
|
|
1089
1105
|
const signedTransaction = await sdk.wallet.signTransaction(unsignedTransaction);
|
|
1090
1106
|
```
|
|
1091
1107
|
|
|
1092
|
-
**
|
|
1108
|
+
**Throws** if the signer does not support `signTransaction` (i.e., it only has `signAndSendTransaction`).
|
|
1093
1109
|
|
|
1094
|
-
|
|
1110
|
+
### `signAndSendTransaction(transaction: Transaction): Promise<string>`
|
|
1095
1111
|
|
|
1096
|
-
|
|
1112
|
+
Sign and send a Solana transaction in one step. Only available when the signer provides `signAndSendTransaction`. Returns the transaction signature.
|
|
1113
|
+
|
|
1114
|
+
```typescript
|
|
1115
|
+
const signature = await sdk.wallet.signAndSendTransaction(unsignedTransaction);
|
|
1116
|
+
```
|
|
1097
1117
|
|
|
1098
|
-
|
|
1118
|
+
**Throws** if the signer does not support `signAndSendTransaction`.
|
|
1099
1119
|
|
|
1100
|
-
|
|
1120
|
+
### `isSignAndSendMode(): boolean`
|
|
1101
1121
|
|
|
1102
|
-
|
|
1103
|
-
// Transaction should be prepared by the backend first
|
|
1104
|
-
const { unsignedTransaction } = await sdk.http.post(
|
|
1105
|
-
'/transactions/prepare-deposit',
|
|
1106
|
-
{
|
|
1107
|
-
lobbyId: 'lobby-id',
|
|
1108
|
-
amount: 100,
|
|
1109
|
-
},
|
|
1110
|
-
);
|
|
1122
|
+
Check which signing mode the current signer uses.
|
|
1111
1123
|
|
|
1112
|
-
|
|
1113
|
-
|
|
1124
|
+
```typescript
|
|
1125
|
+
if (sdk.wallet.isSignAndSendMode()) {
|
|
1126
|
+
// Client-sent path: signer signs AND sends
|
|
1127
|
+
} else {
|
|
1128
|
+
// Server-sent path: signer returns signed bytes
|
|
1129
|
+
}
|
|
1114
1130
|
```
|
|
1115
1131
|
|
|
1116
|
-
**Note:**
|
|
1132
|
+
**Note:** `send()` and `depositForLobby()` use this internally to route automatically.
|
|
1117
1133
|
|
|
1118
1134
|
### `send(recipient, amount, token?)`
|
|
1119
1135
|
|
|
@@ -1187,7 +1203,23 @@ Use these only when you explicitly need manual control of signing/submission.
|
|
|
1187
1203
|
|
|
1188
1204
|
## Escrow Module (`sdk.escrow`)
|
|
1189
1205
|
|
|
1190
|
-
The escrow module provides functionality for managing deposits, checking deposit status, and handling the escrow flow for game lobbies.
|
|
1206
|
+
The escrow module provides functionality for managing deposits, checking deposit status, and handling the escrow flow for game lobbies. It is constructed with `http` and `wallet` (the wallet is used for signing in `depositForLobby`). Use the wallet module to set a signer via `sdk.wallet.setSigner(...)` before calling `depositForLobby`.
|
|
1207
|
+
|
|
1208
|
+
### One-call lobby deposit
|
|
1209
|
+
|
|
1210
|
+
For the common case of depositing into a paid lobby in one step, use **`depositForLobby(lobbyId: string): Promise<DepositForLobbyResponse>`**. It starts deposits, prepares the transaction, signs with the configured wallet, submits, and polls until the current user's deposit is confirmed (or all deposits are confirmed for multi-player). Requires a signer to be set (`sdk.wallet.setSigner(...)`).
|
|
1211
|
+
|
|
1212
|
+
```typescript
|
|
1213
|
+
const result = await sdk.escrow.depositForLobby(lobbyId);
|
|
1214
|
+
// result: { signature: string; status: string; canProceedToQueue: boolean }
|
|
1215
|
+
if (result.canProceedToQueue) {
|
|
1216
|
+
await sdk.lobbies.joinQueue(lobbyId);
|
|
1217
|
+
}
|
|
1218
|
+
```
|
|
1219
|
+
|
|
1220
|
+
**Response:** `{ signature, status, canProceedToQueue }`. When `canProceedToQueue` is true, call `sdk.lobbies.joinQueue(lobbyId)` to enter matchmaking.
|
|
1221
|
+
|
|
1222
|
+
**Throws:** If no signer is configured: "No signer configured. Use sdk.wallet.setSigner(...) first."
|
|
1191
1223
|
|
|
1192
1224
|
### `startDeposits(lobbyId: string): Promise<void>`
|
|
1193
1225
|
|