@phantom/server-sdk 1.0.0-beta.0 → 1.0.0-beta.2
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 +69 -1
- package/dist/index.d.ts +15 -2
- package/dist/index.js +16 -0
- package/dist/index.mjs +16 -0
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ Create a `.env` file in your project root:
|
|
|
69
69
|
|
|
70
70
|
```env
|
|
71
71
|
ORGANIZATION_ID=your-organization-id
|
|
72
|
+
APP_ID=your-app-id
|
|
72
73
|
PRIVATE_KEY=your-base58-encoded-private-key
|
|
73
74
|
API_URL=https://api.phantom.app/v1/wallets
|
|
74
75
|
```
|
|
@@ -120,6 +121,72 @@ console.log("Solana address:", solanaAddress);
|
|
|
120
121
|
console.log("Ethereum address:", ethereumAddress);
|
|
121
122
|
```
|
|
122
123
|
|
|
124
|
+
### Transaction Signing Methods
|
|
125
|
+
|
|
126
|
+
The Server SDK provides two methods for handling transactions:
|
|
127
|
+
|
|
128
|
+
1. **`signTransaction(params)`** - Signs a transaction without submitting it to the network
|
|
129
|
+
- Returns the signed transaction
|
|
130
|
+
- No network interaction
|
|
131
|
+
- Useful for offline signing or when you want to broadcast later
|
|
132
|
+
|
|
133
|
+
2. **`signAndSendTransaction(params)`** - Signs and submits the transaction to the network
|
|
134
|
+
- Returns both signed transaction and transaction hash
|
|
135
|
+
- Requires network connectivity
|
|
136
|
+
- Transaction is immediately broadcast to the blockchain
|
|
137
|
+
|
|
138
|
+
### Signing Only (No Network Submission)
|
|
139
|
+
|
|
140
|
+
#### Solana Transaction Signing
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";
|
|
144
|
+
|
|
145
|
+
// Create a Solana transaction
|
|
146
|
+
const transaction = new Transaction().add(
|
|
147
|
+
SystemProgram.transfer({
|
|
148
|
+
fromPubkey: new PublicKey(solanaAddress),
|
|
149
|
+
toPubkey: new PublicKey(recipientAddress),
|
|
150
|
+
lamports: 1000000, // 0.001 SOL
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// Set transaction parameters
|
|
155
|
+
transaction.recentBlockhash = blockhash;
|
|
156
|
+
transaction.feePayer = new PublicKey(solanaAddress);
|
|
157
|
+
|
|
158
|
+
// Sign the transaction (without sending)
|
|
159
|
+
const signed = await sdk.signTransaction({
|
|
160
|
+
walletId: wallet.walletId,
|
|
161
|
+
transaction,
|
|
162
|
+
networkId: NetworkId.SOLANA_MAINNET,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
console.log("Signed transaction:", signed.rawTransaction);
|
|
166
|
+
// You can broadcast this transaction later using your own RPC client
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Ethereum Transaction Signing
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Viem transaction object
|
|
173
|
+
const evmTransaction = {
|
|
174
|
+
to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
|
|
175
|
+
value: 1000000000000000000n, // 1 ETH in wei
|
|
176
|
+
data: "0x",
|
|
177
|
+
gasLimit: 21000n,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const signed = await sdk.signTransaction({
|
|
181
|
+
walletId: wallet.walletId,
|
|
182
|
+
transaction: evmTransaction,
|
|
183
|
+
networkId: NetworkId.ETHEREUM_MAINNET,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
console.log("Signed transaction:", signed.rawTransaction);
|
|
187
|
+
// You can broadcast this signed transaction using your preferred method
|
|
188
|
+
```
|
|
189
|
+
|
|
123
190
|
### Signing and Sending Transactions
|
|
124
191
|
|
|
125
192
|
#### Solana - Native Web3.js Transaction Objects
|
|
@@ -278,7 +345,8 @@ For complete API documentation, visit **[docs.phantom.com/server-sdk](https://do
|
|
|
278
345
|
### Key Methods
|
|
279
346
|
|
|
280
347
|
- `createWallet(walletName?)` - Creates a new wallet
|
|
281
|
-
- `
|
|
348
|
+
- `signTransaction(params)` - Signs transactions without submitting to network
|
|
349
|
+
- `signAndSendTransaction(params)` - Signs and submits transactions to network
|
|
282
350
|
- `signMessage(params)` - Signs arbitrary messages
|
|
283
351
|
- `getWalletAddresses(walletId, derivationPaths?)` - Retrieves wallet addresses
|
|
284
352
|
- `getWallets(limit?, offset?)` - Lists all wallets with pagination
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AddressType, NetworkId, PhantomClient, Organization, GetWalletsResult, CreateWalletResult } from '@phantom/client';
|
|
2
|
-
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, PhantomClient, SignedTransaction, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
|
|
2
|
+
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, PhantomClient, SignedTransaction, SignedTransactionResult, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
|
|
3
3
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
4
4
|
export { ParsedMessage, ParsedSignatureResult, ParsedTransaction, ParsedTransactionResult, parseMessage, parseSignMessageResponse, parseTransactionResponse, parseTransactionToBase64Url } from '@phantom/parsers';
|
|
5
5
|
export { NetworkId } from '@phantom/constants';
|
|
@@ -12,6 +12,7 @@ interface WalletAddress {
|
|
|
12
12
|
|
|
13
13
|
interface ServerSDKConfig {
|
|
14
14
|
organizationId: string;
|
|
15
|
+
appId: string;
|
|
15
16
|
apiBaseUrl: string;
|
|
16
17
|
apiPrivateKey: string;
|
|
17
18
|
}
|
|
@@ -21,6 +22,12 @@ interface ServerSignMessageParams {
|
|
|
21
22
|
networkId: NetworkId;
|
|
22
23
|
derivationIndex?: number;
|
|
23
24
|
}
|
|
25
|
+
interface ServerSignTransactionParams {
|
|
26
|
+
walletId: string;
|
|
27
|
+
transaction: any;
|
|
28
|
+
networkId: NetworkId;
|
|
29
|
+
derivationIndex?: number;
|
|
30
|
+
}
|
|
24
31
|
interface ServerSignAndSendTransactionParams {
|
|
25
32
|
walletId: string;
|
|
26
33
|
transaction: any;
|
|
@@ -37,6 +44,12 @@ declare class ServerSDK {
|
|
|
37
44
|
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
38
45
|
*/
|
|
39
46
|
signMessage(params: ServerSignMessageParams): Promise<ParsedSignatureResult>;
|
|
47
|
+
/**
|
|
48
|
+
* Sign a transaction - supports various transaction formats and automatically parses them
|
|
49
|
+
* @param params - Transaction parameters with flexible transaction format
|
|
50
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
51
|
+
*/
|
|
52
|
+
signTransaction(params: ServerSignTransactionParams): Promise<ParsedTransactionResult>;
|
|
40
53
|
/**
|
|
41
54
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
42
55
|
* @param params - Transaction parameters with flexible transaction format
|
|
@@ -55,4 +68,4 @@ declare class ServerSDK {
|
|
|
55
68
|
}[]>;
|
|
56
69
|
}
|
|
57
70
|
|
|
58
|
-
export { ServerSDK, ServerSDKConfig, ServerSignAndSendTransactionParams, ServerSignMessageParams, WalletAddress };
|
|
71
|
+
export { ServerSDK, ServerSDKConfig, ServerSignAndSendTransactionParams, ServerSignMessageParams, ServerSignTransactionParams, WalletAddress };
|
package/dist/index.js
CHANGED
|
@@ -88,6 +88,22 @@ var ServerSDK = class {
|
|
|
88
88
|
const rawResponse = await this.client.signMessage(signMessageParams);
|
|
89
89
|
return (0, import_parsers.parseSignMessageResponse)(rawResponse, params.networkId);
|
|
90
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Sign a transaction - supports various transaction formats and automatically parses them
|
|
93
|
+
* @param params - Transaction parameters with flexible transaction format
|
|
94
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
95
|
+
*/
|
|
96
|
+
async signTransaction(params) {
|
|
97
|
+
const parsedTransaction = await (0, import_parsers.parseTransactionToBase64Url)(params.transaction, params.networkId);
|
|
98
|
+
const signTransactionParams = {
|
|
99
|
+
walletId: params.walletId,
|
|
100
|
+
transaction: parsedTransaction.base64url,
|
|
101
|
+
networkId: params.networkId,
|
|
102
|
+
derivationIndex: params.derivationIndex
|
|
103
|
+
};
|
|
104
|
+
const rawResponse = await this.client.signTransaction(signTransactionParams);
|
|
105
|
+
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId);
|
|
106
|
+
}
|
|
91
107
|
/**
|
|
92
108
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
93
109
|
* @param params - Transaction parameters with flexible transaction format
|
package/dist/index.mjs
CHANGED
|
@@ -61,6 +61,22 @@ var ServerSDK = class {
|
|
|
61
61
|
const rawResponse = await this.client.signMessage(signMessageParams);
|
|
62
62
|
return parseSignMessageResponse(rawResponse, params.networkId);
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Sign a transaction - supports various transaction formats and automatically parses them
|
|
66
|
+
* @param params - Transaction parameters with flexible transaction format
|
|
67
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
68
|
+
*/
|
|
69
|
+
async signTransaction(params) {
|
|
70
|
+
const parsedTransaction = await parseTransactionToBase64Url(params.transaction, params.networkId);
|
|
71
|
+
const signTransactionParams = {
|
|
72
|
+
walletId: params.walletId,
|
|
73
|
+
transaction: parsedTransaction.base64url,
|
|
74
|
+
networkId: params.networkId,
|
|
75
|
+
derivationIndex: params.derivationIndex
|
|
76
|
+
};
|
|
77
|
+
const rawResponse = await this.client.signTransaction(signTransactionParams);
|
|
78
|
+
return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId);
|
|
79
|
+
}
|
|
64
80
|
/**
|
|
65
81
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
66
82
|
* @param params - Transaction parameters with flexible transaction format
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/server-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.2",
|
|
4
4
|
"description": "Server SDK for Phantom Wallet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"typescript": "^5.0.4"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@phantom/api-key-stamper": "^1.0.0-beta.
|
|
41
|
-
"@phantom/base64url": "^1.0.0-beta.
|
|
42
|
-
"@phantom/client": "^1.0.0-beta.
|
|
43
|
-
"@phantom/constants": "^1.0.0-beta.
|
|
44
|
-
"@phantom/parsers": "^1.0.0-beta.
|
|
40
|
+
"@phantom/api-key-stamper": "^1.0.0-beta.2",
|
|
41
|
+
"@phantom/base64url": "^1.0.0-beta.2",
|
|
42
|
+
"@phantom/client": "^1.0.0-beta.2",
|
|
43
|
+
"@phantom/constants": "^1.0.0-beta.2",
|
|
44
|
+
"@phantom/parsers": "^1.0.0-beta.2",
|
|
45
45
|
"bs58": "^6.0.0"
|
|
46
46
|
},
|
|
47
47
|
"files": [
|