@phantom/server-sdk 0.0.3 → 0.0.4
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 +43 -201
- package/dist/auth.js +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,228 +1,70 @@
|
|
|
1
1
|
# Phantom Server SDK
|
|
2
2
|
|
|
3
|
-
The Phantom Server SDK
|
|
3
|
+
The Phantom Server SDK provides a secure and straightforward way to create and manage wallets, sign transactions, and interact with multiple blockchains from your backend services.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @phantom/server-sdk
|
|
9
|
-
```
|
|
5
|
+
## 📖 Documentation
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
Visit **[docs.phantom.com/server-sdk](https://docs.phantom.com/server-sdk)** for comprehensive documentation including:
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
- Getting Started Guide
|
|
10
|
+
- Creating and Managing Wallets
|
|
11
|
+
- Signing Transactions
|
|
12
|
+
- Signing Messages
|
|
13
|
+
- Complete API Reference
|
|
14
|
+
- Integration Examples
|
|
15
|
+
- Best Practices
|
|
16
|
+
- Security Considerations
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
import { ServerSDK } from '@phantom/server-sdk';
|
|
18
|
+
## Installation
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
organizationId: 'your-org-id', // Your organization ID
|
|
21
|
-
apiBaseUrl: 'https://api.phantom.app/wallet'
|
|
22
|
-
});
|
|
20
|
+
```bash
|
|
21
|
+
npm install @phantom/server-sdk
|
|
23
22
|
```
|
|
24
23
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
The SDK provides user-friendly enums for CAIP-2 network identifiers:
|
|
28
|
-
|
|
29
|
-
```typescript
|
|
30
|
-
import { NetworkId } from '@phantom/server-sdk';
|
|
31
|
-
|
|
32
|
-
// Use the NetworkId enum for easy access to CAIP-2 identifiers
|
|
33
|
-
const solanaMainnet = NetworkId.SOLANA_MAINNET; // 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
|
|
34
|
-
const ethMainnet = NetworkId.ETHEREUM_MAINNET; // 'eip155:1'
|
|
35
|
-
const polygonMainnet = NetworkId.POLYGON_MAINNET; // 'eip155:137'
|
|
36
|
-
|
|
37
|
-
// Example usage with SDK methods
|
|
38
|
-
const result = await sdk.signAndSendTransaction(
|
|
39
|
-
walletId,
|
|
40
|
-
transaction,
|
|
41
|
-
NetworkId.SOLANA_MAINNET // Instead of hardcoding 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp'
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// Sign a message on Ethereum
|
|
45
|
-
const signature = await sdk.signMessage(
|
|
46
|
-
walletId,
|
|
47
|
-
'Hello World',
|
|
48
|
-
NetworkId.ETHEREUM_MAINNET
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
|
|
24
|
+
```bash
|
|
25
|
+
yarn add @phantom/server-sdk
|
|
52
26
|
```
|
|
53
27
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
| Network | Enum Value | CAIP-2 ID |
|
|
57
|
-
|---------|-----------|-----------|
|
|
58
|
-
| **Solana** | | |
|
|
59
|
-
| Mainnet | `NetworkId.SOLANA_MAINNET` | `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp` |
|
|
60
|
-
| Devnet | `NetworkId.SOLANA_DEVNET` | `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` |
|
|
61
|
-
| Testnet | `NetworkId.SOLANA_TESTNET` | `solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z` |
|
|
62
|
-
| **Ethereum** | | |
|
|
63
|
-
| Mainnet | `NetworkId.ETHEREUM_MAINNET` | `eip155:1` |
|
|
64
|
-
| Goerli | `NetworkId.ETHEREUM_GOERLI` | `eip155:5` |
|
|
65
|
-
| Sepolia | `NetworkId.ETHEREUM_SEPOLIA` | `eip155:11155111` |
|
|
66
|
-
| **Polygon** | | |
|
|
67
|
-
| Mainnet | `NetworkId.POLYGON_MAINNET` | `eip155:137` |
|
|
68
|
-
| Mumbai | `NetworkId.POLYGON_MUMBAI` | `eip155:80001` |
|
|
69
|
-
| **Arbitrum** | | |
|
|
70
|
-
| One | `NetworkId.ARBITRUM_ONE` | `eip155:42161` |
|
|
71
|
-
| Goerli | `NetworkId.ARBITRUM_GOERLI` | `eip155:421613` |
|
|
72
|
-
| **Base** | | |
|
|
73
|
-
| Mainnet | `NetworkId.BASE_MAINNET` | `eip155:8453` |
|
|
74
|
-
| Sepolia | `NetworkId.BASE_SEPOLIA` | `eip155:84532` |
|
|
75
|
-
|
|
76
|
-
## CAIP-2 Network Identifiers
|
|
77
|
-
|
|
78
|
-
This SDK uses the CAIP-2 (Chain Agnostic Improvement Proposal 2) standard for network identifiers. CAIP-2 provides a standardized way to identify blockchain networks across different ecosystems.
|
|
79
|
-
|
|
80
|
-
### Format
|
|
81
|
-
CAIP-2 identifiers follow the format: `namespace:reference`
|
|
82
|
-
|
|
83
|
-
### Common Network IDs
|
|
84
|
-
- **Solana Mainnet**: `solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp`
|
|
85
|
-
- **Solana Devnet**: `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1`
|
|
86
|
-
- **Ethereum Mainnet**: `eip155:1`
|
|
87
|
-
- **Polygon Mainnet**: `eip155:137`
|
|
88
|
-
- **Arbitrum One**: `eip155:42161`
|
|
89
|
-
- **Base Mainnet**: `eip155:8453`
|
|
90
|
-
|
|
91
|
-
## Methods
|
|
92
|
-
|
|
93
|
-
### createWallet(walletName?: string)
|
|
94
|
-
Creates a new wallet in your organization. Each wallet supports multiple chains.
|
|
95
|
-
|
|
96
|
-
```typescript
|
|
97
|
-
const wallet = await sdk.createWallet('My Main Wallet');
|
|
98
|
-
// Returns: {
|
|
99
|
-
// walletId: 'wallet-uuid',
|
|
100
|
-
// addresses: [
|
|
101
|
-
// { addressType: 'Solana', address: '...' },
|
|
102
|
-
// { addressType: 'Ethereum', address: '...' },
|
|
103
|
-
// { addressType: 'BitcoinSegwit', address: '...' },
|
|
104
|
-
// { addressType: 'Sui', address: '...' }
|
|
105
|
-
// ]
|
|
106
|
-
// }
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add @phantom/server-sdk
|
|
107
30
|
```
|
|
108
31
|
|
|
109
|
-
|
|
110
|
-
Signs a transaction and tries to submits it to the blockchain. The SDK automatically handles network-specific requirements.
|
|
111
|
-
If the networkId is not supported for sending, the transaction will only be signed.
|
|
32
|
+
## Quick Start
|
|
112
33
|
|
|
113
34
|
```typescript
|
|
114
|
-
import { NetworkId } from '@phantom/server-sdk';
|
|
35
|
+
import { ServerSDK, NetworkId } from '@phantom/server-sdk';
|
|
115
36
|
|
|
116
|
-
|
|
117
|
-
const
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
// Returns: {
|
|
124
|
-
// rawTransaction: 'base64-signed-transaction'
|
|
125
|
-
// txHash: 'tx-hash-string'
|
|
126
|
-
// }
|
|
127
|
-
|
|
128
|
-
// Extract the transaction signature (hash)
|
|
129
|
-
// Note: requires 'import bs58 from "bs58"'
|
|
130
|
-
const signedTx = Transaction.from(Buffer.from(result.rawTransaction, 'base64'));
|
|
131
|
-
const signature = signedTx.signature
|
|
132
|
-
? bs58.encode(signedTx.signature)
|
|
133
|
-
: bs58.encode(signedTx.signatures[0].signature);
|
|
134
|
-
```
|
|
37
|
+
// Initialize the SDK
|
|
38
|
+
const sdk = new ServerSDK({
|
|
39
|
+
organizationId: process.env.PHANTOM_ORGANIZATION_ID!,
|
|
40
|
+
apiPrivateKey: process.env.PHANTOM_PRIVATE_KEY!,
|
|
41
|
+
apiBaseUrl: process.env.PHANTOM_API_URL!
|
|
42
|
+
});
|
|
135
43
|
|
|
136
|
-
|
|
137
|
-
|
|
44
|
+
// Create a wallet
|
|
45
|
+
const wallet = await sdk.createWallet('My First Wallet');
|
|
46
|
+
console.log('Wallet ID:', wallet.walletId);
|
|
47
|
+
console.log('Addresses:', wallet.addresses);
|
|
138
48
|
|
|
139
|
-
|
|
49
|
+
// Sign a message
|
|
140
50
|
const signature = await sdk.signMessage(
|
|
141
|
-
|
|
142
|
-
'Hello
|
|
51
|
+
wallet.walletId,
|
|
52
|
+
'Hello, Phantom!',
|
|
143
53
|
NetworkId.SOLANA_MAINNET
|
|
144
54
|
);
|
|
145
|
-
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
### getWallets(limit?: number, offset?: number)
|
|
149
|
-
Retrieves all wallets for your organization with pagination support.
|
|
150
|
-
|
|
151
|
-
```typescript
|
|
152
|
-
// Get first 10 wallets
|
|
153
|
-
const result = await sdk.getWallets(10, 0);
|
|
154
|
-
// Returns: {
|
|
155
|
-
// wallets: [{ walletId: '...', walletName: '...' }, ...],
|
|
156
|
-
// totalCount: 25,
|
|
157
|
-
// limit: 10,
|
|
158
|
-
// offset: 0
|
|
159
|
-
// }
|
|
160
|
-
|
|
161
|
-
// Get all wallets (default limit: 20)
|
|
162
|
-
const allWallets = await sdk.getWallets();
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
### getWalletAddresses(walletId: string, derivationPaths?: string[])
|
|
166
|
-
Retrieves addresses for a specific wallet across different blockchains.
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
const addresses = await sdk.getWalletAddresses('wallet-id');
|
|
170
|
-
// Returns: [
|
|
171
|
-
// { addressType: 'Solana', address: '...' },
|
|
172
|
-
// { addressType: 'Ethereum', address: '...' },
|
|
173
|
-
// { addressType: 'Bitcoin', address: '...' },
|
|
174
|
-
// { addressType: 'Sui', address: '...' }
|
|
175
|
-
// ]
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
## CAIP-2 Utility Functions
|
|
179
|
-
|
|
180
|
-
The SDK exports several utility functions for working with CAIP-2 network identifiers:
|
|
181
|
-
|
|
182
|
-
```typescript
|
|
183
|
-
import {
|
|
184
|
-
deriveSubmissionConfig,
|
|
185
|
-
supportsTransactionSubmission,
|
|
186
|
-
getNetworkDescription,
|
|
187
|
-
getSupportedNetworkIds,
|
|
188
|
-
getNetworkIdsByChain
|
|
189
|
-
} from '@phantom/server-sdk';
|
|
190
|
-
|
|
191
|
-
// Check if a network supports transaction submission
|
|
192
|
-
if (supportsTransactionSubmission('solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')) {
|
|
193
|
-
// Network supports automatic transaction submission
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// Get human-readable network description
|
|
197
|
-
const description = getNetworkDescription('eip155:137'); // "Polygon Mainnet"
|
|
198
|
-
|
|
199
|
-
// List all supported networks
|
|
200
|
-
const allNetworks = getSupportedNetworkIds();
|
|
201
|
-
|
|
202
|
-
// Get networks for a specific chain
|
|
203
|
-
const solanaNetworks = getNetworkIdsByChain('solana');
|
|
204
|
-
// ['solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp', 'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1', ...]
|
|
55
|
+
console.log('Signature:', signature);
|
|
205
56
|
```
|
|
206
57
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
- **Never expose your private key** in client-side code or commit it to version control
|
|
210
|
-
- Store your credentials securely using environment variables or secret management systems
|
|
211
|
-
- Each wallet is isolated and can only be accessed by your organization
|
|
212
|
-
- All API requests are authenticated using cryptographic signatures
|
|
58
|
+
For complete documentation and examples, visit **[docs.phantom.com/server-sdk](https://docs.phantom.com/server-sdk)**.
|
|
213
59
|
|
|
214
|
-
##
|
|
60
|
+
## Resources
|
|
215
61
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
} catch (error) {
|
|
222
|
-
console.error('Failed to create wallet:', error.message);
|
|
223
|
-
}
|
|
224
|
-
```
|
|
62
|
+
- [Documentation](https://docs.phantom.com/server-sdk)
|
|
63
|
+
- [Example Code](https://github.com/phantom/wallet-sdk/tree/main/examples/server-sdk-examples)
|
|
64
|
+
- [Integration Guide](https://docs.phantom.com/server-sdk/integration-guide)
|
|
65
|
+
- [API Reference](https://docs.phantom.com/server-sdk/api-reference)
|
|
66
|
+
- [Changelog](./CHANGELOG.md)
|
|
225
67
|
|
|
226
|
-
##
|
|
68
|
+
## License
|
|
227
69
|
|
|
228
|
-
|
|
70
|
+
This SDK is distributed under the MIT License. See the [LICENSE](../../LICENSE) file for details.
|
package/dist/auth.js
CHANGED
|
@@ -16,7 +16,7 @@ function createAuthenticatedAxiosInstance(signingKeypair) {
|
|
|
16
16
|
const requestBody = typeof config.data === "string" ? config.data : JSON.stringify(config.data);
|
|
17
17
|
const dataUtf8 = Buffer.from(requestBody, "utf8");
|
|
18
18
|
const signature = tweetnacl_1.default.sign.detached(dataUtf8, signingKeypair.secretKey);
|
|
19
|
-
config.headers["X-Phantom-Sig"] = Buffer.from(signature).toString("
|
|
19
|
+
config.headers["X-Phantom-Sig"] = Buffer.from(signature).toString("base64url");
|
|
20
20
|
return config;
|
|
21
21
|
});
|
|
22
22
|
return instance;
|
package/dist/index.js
CHANGED
|
@@ -97,7 +97,7 @@ class ServerSDK {
|
|
|
97
97
|
async signAndSendTransaction(walletId, transaction, networkId) {
|
|
98
98
|
try {
|
|
99
99
|
// Encode the Uint8Array as a base64 string
|
|
100
|
-
const encodedTransaction = Buffer.from(transaction).toString('
|
|
100
|
+
const encodedTransaction = Buffer.from(transaction).toString('base64url');
|
|
101
101
|
const submissionConfig = (0, caip2_mappings_1.deriveSubmissionConfig)(networkId);
|
|
102
102
|
// If we don't have a submission config, the transaction will only be signed, not submitted
|
|
103
103
|
if (!submissionConfig) {
|
|
@@ -181,7 +181,7 @@ class ServerSDK {
|
|
|
181
181
|
curve: networkConfig.curve,
|
|
182
182
|
addressFormat: networkConfig.addressFormat,
|
|
183
183
|
};
|
|
184
|
-
const base64StringMessage = Buffer.from(message, "utf8").toString("
|
|
184
|
+
const base64StringMessage = Buffer.from(message, "utf8").toString("base64url");
|
|
185
185
|
const signRequest = {
|
|
186
186
|
organizationId: this.config.organizationId,
|
|
187
187
|
walletId: walletId,
|