@phantom/server-sdk 0.0.4 → 0.1.0
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 +186 -16
- package/dist/index.d.ts +17 -19
- package/dist/index.js +68 -236
- package/dist/index.mjs +46 -0
- package/package.json +20 -7
- package/dist/auth.d.ts +0 -6
- package/dist/auth.js +0 -23
- package/dist/caip2-mappings.d.ts +0 -59
- package/dist/caip2-mappings.js +0 -192
- package/dist/constants.d.ts +0 -28
- package/dist/constants.js +0 -82
- package/dist/types.d.ts +0 -29
- package/dist/types.js +0 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Phantom Server SDK
|
|
2
2
|
|
|
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.
|
|
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. This SDK is designed for server-side applications that need programmatic access to Phantom's wallet infrastructure.
|
|
4
4
|
|
|
5
5
|
## 📖 Documentation
|
|
6
6
|
|
|
@@ -15,8 +15,19 @@ Visit **[docs.phantom.com/server-sdk](https://docs.phantom.com/server-sdk)** for
|
|
|
15
15
|
- Best Practices
|
|
16
16
|
- Security Considerations
|
|
17
17
|
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- 🔐 **Secure wallet creation and management** - Create wallets programmatically with enterprise-grade security
|
|
21
|
+
- ✍️ **Transaction signing** - Sign and optionally submit transactions across multiple blockchains
|
|
22
|
+
- 📝 **Message signing** - Sign arbitrary messages for authentication or verification
|
|
23
|
+
- 🌐 **Multi-chain support** - Works with Solana, Ethereum, Polygon, Sui, Bitcoin, Base and other major blockchains
|
|
24
|
+
- 🔑 **Ed25519 authentication** - Secure API authentication using cryptographic signatures
|
|
25
|
+
- 📊 **Wallet listing and pagination** - Efficiently manage large numbers of wallets
|
|
26
|
+
|
|
18
27
|
## Installation
|
|
19
28
|
|
|
29
|
+
Install the Server SDK using your preferred package manager:
|
|
30
|
+
|
|
20
31
|
```bash
|
|
21
32
|
npm install @phantom/server-sdk
|
|
22
33
|
```
|
|
@@ -29,33 +40,188 @@ yarn add @phantom/server-sdk
|
|
|
29
40
|
pnpm add @phantom/server-sdk
|
|
30
41
|
```
|
|
31
42
|
|
|
43
|
+
## Prerequisites
|
|
44
|
+
|
|
45
|
+
Before using the SDK, you need:
|
|
46
|
+
|
|
47
|
+
1. **Phantom Organization Credentials**
|
|
48
|
+
|
|
49
|
+
- Organization ID
|
|
50
|
+
- Organization Private Key (base58 encoded)
|
|
51
|
+
- API Base URL
|
|
52
|
+
|
|
53
|
+
These credentials are provided when you create an organization with Phantom.
|
|
54
|
+
|
|
55
|
+
2. **Node.js** version 16 or higher
|
|
56
|
+
|
|
57
|
+
## Security First
|
|
58
|
+
|
|
59
|
+
The private key for your organization is meant to be stored **ONLY on your server** in a secure environment.
|
|
60
|
+
|
|
61
|
+
- **NEVER expose this key in client-side code**
|
|
62
|
+
- **NEVER commit it to version control**
|
|
63
|
+
- **Always use environment variables or secret management systems**
|
|
64
|
+
|
|
32
65
|
## Quick Start
|
|
33
66
|
|
|
67
|
+
### 1. Set up Environment Variables
|
|
68
|
+
|
|
69
|
+
Create a `.env` file in your project root:
|
|
70
|
+
|
|
71
|
+
```env
|
|
72
|
+
ORGANIZATION_ID=your-organization-id
|
|
73
|
+
PRIVATE_KEY=your-base58-encoded-private-key
|
|
74
|
+
API_URL=https://api.phantom.app/wallet
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 2. Initialize the SDK
|
|
78
|
+
|
|
34
79
|
```typescript
|
|
35
|
-
import { ServerSDK, NetworkId } from
|
|
80
|
+
import { ServerSDK, NetworkId } from "@phantom/server-sdk";
|
|
81
|
+
import dotenv from "dotenv";
|
|
82
|
+
|
|
83
|
+
// Load environment variables
|
|
84
|
+
dotenv.config();
|
|
36
85
|
|
|
37
86
|
// Initialize the SDK
|
|
38
87
|
const sdk = new ServerSDK({
|
|
39
|
-
organizationId: process.env.
|
|
40
|
-
apiPrivateKey: process.env.
|
|
41
|
-
apiBaseUrl: process.env.
|
|
88
|
+
organizationId: process.env.ORGANIZATION_ID!,
|
|
89
|
+
apiPrivateKey: process.env.PRIVATE_KEY!,
|
|
90
|
+
apiBaseUrl: process.env.API_URL!,
|
|
42
91
|
});
|
|
43
92
|
|
|
44
93
|
// Create a wallet
|
|
45
|
-
const wallet = await sdk.createWallet(
|
|
46
|
-
console.log(
|
|
47
|
-
console.log(
|
|
48
|
-
|
|
49
|
-
// Sign a message
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
94
|
+
const wallet = await sdk.createWallet("My First Wallet");
|
|
95
|
+
console.log("Wallet ID:", wallet.walletId);
|
|
96
|
+
console.log("Addresses:", wallet.addresses);
|
|
97
|
+
|
|
98
|
+
// Sign a message (base64url encoded)
|
|
99
|
+
const message = Buffer.from("Hello, Phantom!").toString("base64url");
|
|
100
|
+
const signature = await sdk.signMessage(wallet.walletId, message, NetworkId.SOLANA_MAINNET);
|
|
101
|
+
console.log("Signature:", signature);
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Usage Examples
|
|
105
|
+
|
|
106
|
+
### Creating a Wallet
|
|
107
|
+
|
|
108
|
+
```typescript
|
|
109
|
+
// Create a wallet with a custom name
|
|
110
|
+
const wallet = await sdk.createWallet("User Wallet 123");
|
|
111
|
+
|
|
112
|
+
// Access addresses for different chains
|
|
113
|
+
const solanaAddress = wallet.addresses.find(addr => addr.addressType === "Solana")?.address;
|
|
114
|
+
|
|
115
|
+
const ethereumAddress = wallet.addresses.find(addr => addr.addressType === "Ethereum")?.address;
|
|
116
|
+
|
|
117
|
+
console.log("Solana address:", solanaAddress);
|
|
118
|
+
console.log("Ethereum address:", ethereumAddress);
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Signing and Sending Transactions
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";
|
|
125
|
+
|
|
126
|
+
// Create a Solana transaction
|
|
127
|
+
const transaction = new Transaction().add(
|
|
128
|
+
SystemProgram.transfer({
|
|
129
|
+
fromPubkey: new PublicKey(solanaAddress),
|
|
130
|
+
toPubkey: new PublicKey(recipientAddress),
|
|
131
|
+
lamports: 1000000, // 0.001 SOL
|
|
132
|
+
}),
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
// Set transaction parameters
|
|
136
|
+
transaction.recentBlockhash = blockhash;
|
|
137
|
+
transaction.feePayer = new PublicKey(solanaAddress);
|
|
138
|
+
|
|
139
|
+
// Serialize the transaction
|
|
140
|
+
const serializedTx = transaction.serialize({
|
|
141
|
+
requireAllSignatures: false,
|
|
142
|
+
verifySignatures: false,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// Convert to base64url
|
|
146
|
+
const transactionBase64 = Buffer.from(serializedTx).toString("base64url");
|
|
147
|
+
|
|
148
|
+
// Sign and send the transaction
|
|
149
|
+
const signedTx = await sdk.signAndSendTransaction(wallet.walletId, transactionBase64, NetworkId.SOLANA_MAINNET);
|
|
150
|
+
|
|
151
|
+
console.log("Signed transaction:", signedTx.rawTransaction);
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### Signing Messages
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
// Sign a message for Solana (base64url encoded)
|
|
158
|
+
const solanaMessage = Buffer.from("Please sign this message to authenticate").toString("base64url");
|
|
159
|
+
const solanaSignature = await sdk.signMessage(wallet.walletId, solanaMessage, NetworkId.SOLANA_MAINNET);
|
|
160
|
+
|
|
161
|
+
// Sign a message for Ethereum (base64url encoded)
|
|
162
|
+
const ethMessage = Buffer.from("Sign in to our dApp").toString("base64url");
|
|
163
|
+
const ethSignature = await sdk.signMessage(wallet.walletId, ethMessage, NetworkId.ETHEREUM_MAINNET);
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### Managing Wallets
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
// Get all wallets for your organization with pagination
|
|
170
|
+
const result = await sdk.getWallets(20, 0); // limit: 20, offset: 0
|
|
171
|
+
|
|
172
|
+
console.log(`Total wallets: ${result.totalCount}`);
|
|
173
|
+
console.log("Wallets:", result.wallets);
|
|
174
|
+
|
|
175
|
+
// Get addresses for a specific wallet
|
|
176
|
+
const addresses = await sdk.getWalletAddresses(walletId);
|
|
177
|
+
|
|
178
|
+
// Get specific addresses by derivation path
|
|
179
|
+
const customAddresses = await sdk.getWalletAddresses(
|
|
180
|
+
walletId,
|
|
181
|
+
["m/44'/501'/0'/0'", "m/44'/60'/0'/0/0"], // Solana and Ethereum
|
|
54
182
|
);
|
|
55
|
-
console.log('Signature:', signature);
|
|
56
183
|
```
|
|
57
184
|
|
|
58
|
-
|
|
185
|
+
## Network Support
|
|
186
|
+
|
|
187
|
+
The SDK supports multiple blockchain networks through the `NetworkId` enum:
|
|
188
|
+
|
|
189
|
+
### Solana Networks
|
|
190
|
+
|
|
191
|
+
- `NetworkId.SOLANA_MAINNET` - Solana Mainnet-Beta
|
|
192
|
+
- `NetworkId.SOLANA_DEVNET` - Solana Devnet
|
|
193
|
+
- `NetworkId.SOLANA_TESTNET` - Solana Testnet
|
|
194
|
+
|
|
195
|
+
### Ethereum Networks
|
|
196
|
+
|
|
197
|
+
- `NetworkId.ETHEREUM_MAINNET` - Ethereum Mainnet
|
|
198
|
+
- `NetworkId.ETHEREUM_GOERLI` - Goerli Testnet
|
|
199
|
+
- `NetworkId.ETHEREUM_SEPOLIA` - Sepolia Testnet
|
|
200
|
+
|
|
201
|
+
### Other EVM Networks
|
|
202
|
+
|
|
203
|
+
- `NetworkId.POLYGON_MAINNET` - Polygon Mainnet
|
|
204
|
+
- `NetworkId.POLYGON_MUMBAI` - Mumbai Testnet
|
|
205
|
+
- `NetworkId.OPTIMISM_MAINNET` - Optimism Mainnet
|
|
206
|
+
- `NetworkId.ARBITRUM_ONE` - Arbitrum One
|
|
207
|
+
- `NetworkId.BASE_MAINNET` - Base Mainnet
|
|
208
|
+
|
|
209
|
+
### Future Support
|
|
210
|
+
|
|
211
|
+
- `NetworkId.BITCOIN_MAINNET` - Bitcoin Mainnet
|
|
212
|
+
- `NetworkId.SUI_MAINNET` - Sui Mainnet
|
|
213
|
+
|
|
214
|
+
## API Reference
|
|
215
|
+
|
|
216
|
+
For complete API documentation, visit **[docs.phantom.com/server-sdk](https://docs.phantom.com/server-sdk)**.
|
|
217
|
+
|
|
218
|
+
### Key Methods
|
|
219
|
+
|
|
220
|
+
- `createWallet(walletName?)` - Creates a new wallet
|
|
221
|
+
- `signAndSendTransaction(walletId, transaction, networkId)` - Signs and optionally submits transactions
|
|
222
|
+
- `signMessage(walletId, message, networkId)` - Signs arbitrary messages
|
|
223
|
+
- `getWalletAddresses(walletId, derivationPaths?)` - Retrieves wallet addresses
|
|
224
|
+
- `getWallets(limit?, offset?)` - Lists all wallets with pagination
|
|
59
225
|
|
|
60
226
|
## Resources
|
|
61
227
|
|
|
@@ -68,3 +234,7 @@ For complete documentation and examples, visit **[docs.phantom.com/server-sdk](h
|
|
|
68
234
|
## License
|
|
69
235
|
|
|
70
236
|
This SDK is distributed under the MIT License. See the [LICENSE](../../LICENSE) file for details.
|
|
237
|
+
|
|
238
|
+
## Contributing
|
|
239
|
+
|
|
240
|
+
We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for details.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { PhantomClient } from '@phantom/client';
|
|
2
|
+
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, NetworkId, PhantomClient, SignedTransaction, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
|
|
3
|
+
export { ApiKeyStamper } from '@phantom/api-key-stamper';
|
|
4
|
+
import { DerivationInfoAddressFormatEnum } from '@phantom/openapi-wallet-service';
|
|
5
|
+
|
|
6
|
+
interface WalletAddress {
|
|
7
|
+
addressType: DerivationInfoAddressFormatEnum;
|
|
8
|
+
address: string;
|
|
6
9
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
|
|
11
|
+
interface ServerSDKConfig {
|
|
12
|
+
organizationId: string;
|
|
13
|
+
apiBaseUrl: string;
|
|
14
|
+
apiPrivateKey: string;
|
|
15
|
+
}
|
|
16
|
+
declare class ServerSDK extends PhantomClient {
|
|
12
17
|
constructor(config: ServerSDKConfig);
|
|
13
|
-
createWallet(walletName?: string): Promise<CreateWalletResult>;
|
|
14
|
-
signAndSendTransaction(walletId: string, transaction: Transaction, networkId: NetworkId): Promise<SignedTransaction>;
|
|
15
|
-
getWalletAddresses(walletId: string, derivationPaths?: string[]): Promise<{
|
|
16
|
-
addressType: string;
|
|
17
|
-
address: string;
|
|
18
|
-
}[]>;
|
|
19
|
-
signMessage(walletId: string, message: string, networkId: NetworkId): Promise<string>;
|
|
20
|
-
getWallets(limit?: number, offset?: number): Promise<GetWalletsResult>;
|
|
21
18
|
}
|
|
22
|
-
|
|
19
|
+
|
|
20
|
+
export { ServerSDK, ServerSDKConfig, WalletAddress };
|
package/dist/index.js
CHANGED
|
@@ -1,239 +1,71 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
9
|
};
|
|
16
|
-
var
|
|
17
|
-
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
params: {
|
|
74
|
-
accounts: [constants_1.DerivationPath.Solana, constants_1.DerivationPath.Ethereum, constants_1.DerivationPath.Bitcoin, constants_1.DerivationPath.Sui],
|
|
75
|
-
organizationId: this.config.organizationId,
|
|
76
|
-
walletId: walletResult.walletId,
|
|
77
|
-
},
|
|
78
|
-
timestampMs: Date.now(),
|
|
79
|
-
};
|
|
80
|
-
console.log("Fetching accounts for wallet:", walletResult.walletId);
|
|
81
|
-
const accountsResponse = await this.kmsApi.postKmsRpc(requestAccounts);
|
|
82
|
-
console.log("Accounts fetched successfully:", accountsResponse.data.result);
|
|
83
|
-
const accountsResult = accountsResponse.data.result;
|
|
84
|
-
return {
|
|
85
|
-
walletId: walletResult.walletId,
|
|
86
|
-
addresses: accountsResult.map(account => ({
|
|
87
|
-
addressType: account.addressFormat,
|
|
88
|
-
address: account.publicKey,
|
|
89
|
-
})),
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
catch (error) {
|
|
93
|
-
console.error("Failed to create wallet:", error.response?.data || error.message);
|
|
94
|
-
throw new Error(`Failed to create wallet: ${error.response?.data?.message || error.message}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
async signAndSendTransaction(walletId, transaction, networkId) {
|
|
98
|
-
try {
|
|
99
|
-
// Encode the Uint8Array as a base64 string
|
|
100
|
-
const encodedTransaction = Buffer.from(transaction).toString('base64url');
|
|
101
|
-
const submissionConfig = (0, caip2_mappings_1.deriveSubmissionConfig)(networkId);
|
|
102
|
-
// If we don't have a submission config, the transaction will only be signed, not submitted
|
|
103
|
-
if (!submissionConfig) {
|
|
104
|
-
console.warn(`No submission config available for network ${networkId}. Transaction will be signed but not submitted.`);
|
|
105
|
-
}
|
|
106
|
-
// Get network configuration
|
|
107
|
-
const networkConfig = (0, constants_1.getNetworkConfig)(networkId);
|
|
108
|
-
if (!networkConfig) {
|
|
109
|
-
throw new Error(`Unsupported network ID: ${networkId}`);
|
|
110
|
-
}
|
|
111
|
-
const derivationInfo = {
|
|
112
|
-
derivationPath: networkConfig.derivationPath,
|
|
113
|
-
curve: networkConfig.curve,
|
|
114
|
-
addressFormat: networkConfig.addressFormat,
|
|
115
|
-
};
|
|
116
|
-
// Sign transaction request - only include submissionConfig if available
|
|
117
|
-
const signRequest = {
|
|
118
|
-
organizationId: this.config.organizationId,
|
|
119
|
-
walletId: walletId,
|
|
120
|
-
transaction: encodedTransaction,
|
|
121
|
-
derivationInfo: derivationInfo,
|
|
122
|
-
};
|
|
123
|
-
// Add submission config if available
|
|
124
|
-
if (submissionConfig) {
|
|
125
|
-
signRequest.submissionConfig = submissionConfig;
|
|
126
|
-
}
|
|
127
|
-
const request = {
|
|
128
|
-
method: openapi_wallet_service_1.SignTransactionMethodEnum.signTransaction,
|
|
129
|
-
params: signRequest,
|
|
130
|
-
timestampMs: Date.now(),
|
|
131
|
-
};
|
|
132
|
-
const response = await this.kmsApi.postKmsRpc(request);
|
|
133
|
-
const result = response.data.result;
|
|
134
|
-
return {
|
|
135
|
-
rawTransaction: result.transaction, // Base64 encoded signed transaction
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
catch (error) {
|
|
139
|
-
console.error("Failed to sign and send transaction:", error.response?.data || error.message);
|
|
140
|
-
throw new Error(`Failed to sign and send transaction: ${error.response?.data?.message || error.message}`);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
async getWalletAddresses(walletId, derivationPaths) {
|
|
144
|
-
try {
|
|
145
|
-
const paths = derivationPaths || [
|
|
146
|
-
constants_1.DerivationPath.Solana,
|
|
147
|
-
constants_1.DerivationPath.Ethereum,
|
|
148
|
-
constants_1.DerivationPath.Bitcoin,
|
|
149
|
-
constants_1.DerivationPath.Sui,
|
|
150
|
-
];
|
|
151
|
-
const requestAccounts = {
|
|
152
|
-
method: openapi_wallet_service_1.GetAccountsMethodEnum.getAccounts,
|
|
153
|
-
params: {
|
|
154
|
-
accounts: paths,
|
|
155
|
-
organizationId: this.config.organizationId,
|
|
156
|
-
walletId: walletId,
|
|
157
|
-
},
|
|
158
|
-
timestampMs: Date.now(),
|
|
159
|
-
};
|
|
160
|
-
const accountsResponse = await this.kmsApi.postKmsRpc(requestAccounts);
|
|
161
|
-
const accountsResult = accountsResponse.data.result;
|
|
162
|
-
return accountsResult.map(account => ({
|
|
163
|
-
addressType: account.addressFormat,
|
|
164
|
-
address: account.publicKey,
|
|
165
|
-
}));
|
|
166
|
-
}
|
|
167
|
-
catch (error) {
|
|
168
|
-
console.error("Failed to get wallet addresses:", error.response?.data || error.message);
|
|
169
|
-
throw new Error(`Failed to get wallet addresses: ${error.response?.data?.message || error.message}`);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
async signMessage(walletId, message, networkId) {
|
|
173
|
-
try {
|
|
174
|
-
// Get network configuration
|
|
175
|
-
const networkConfig = (0, constants_1.getNetworkConfig)(networkId);
|
|
176
|
-
if (!networkConfig) {
|
|
177
|
-
throw new Error(`Unsupported network ID: ${networkId}`);
|
|
178
|
-
}
|
|
179
|
-
const derivationInfo = {
|
|
180
|
-
derivationPath: networkConfig.derivationPath,
|
|
181
|
-
curve: networkConfig.curve,
|
|
182
|
-
addressFormat: networkConfig.addressFormat,
|
|
183
|
-
};
|
|
184
|
-
const base64StringMessage = Buffer.from(message, "utf8").toString("base64url");
|
|
185
|
-
const signRequest = {
|
|
186
|
-
organizationId: this.config.organizationId,
|
|
187
|
-
walletId: walletId,
|
|
188
|
-
payload: base64StringMessage,
|
|
189
|
-
algorithm: networkConfig.algorithm,
|
|
190
|
-
derivationInfo: derivationInfo,
|
|
191
|
-
};
|
|
192
|
-
const request = {
|
|
193
|
-
method: openapi_wallet_service_1.SignRawPayloadMethodEnum.signRawPayload,
|
|
194
|
-
params: signRequest,
|
|
195
|
-
timestampMs: Date.now(),
|
|
196
|
-
};
|
|
197
|
-
const response = await this.kmsApi.postKmsRpc(request);
|
|
198
|
-
const result = response.data.result;
|
|
199
|
-
// Return the base64 encoded signature
|
|
200
|
-
return result.signature;
|
|
201
|
-
}
|
|
202
|
-
catch (error) {
|
|
203
|
-
console.error("Failed to sign message:", error.response?.data || error.message);
|
|
204
|
-
throw new Error(`Failed to sign message: ${error.response?.data?.message || error.message}`);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
async getWallets(limit, offset) {
|
|
208
|
-
try {
|
|
209
|
-
const request = {
|
|
210
|
-
method: "getOrganizationWallets",
|
|
211
|
-
params: {
|
|
212
|
-
organizationId: this.config.organizationId,
|
|
213
|
-
limit: limit || 20,
|
|
214
|
-
offset: offset || 0,
|
|
215
|
-
},
|
|
216
|
-
timestampMs: Date.now(),
|
|
217
|
-
};
|
|
218
|
-
console.log("Fetching wallets for organization:", this.config.organizationId);
|
|
219
|
-
const response = await this.kmsApi.postKmsRpc(request);
|
|
220
|
-
const result = response.data.result;
|
|
221
|
-
console.log(`Fetched ${result.wallets.length} wallets out of ${result.totalCount} total`);
|
|
222
|
-
return {
|
|
223
|
-
wallets: result.wallets.map((wallet) => ({
|
|
224
|
-
walletId: wallet.walletId,
|
|
225
|
-
walletName: wallet.walletName,
|
|
226
|
-
})),
|
|
227
|
-
totalCount: result.totalCount,
|
|
228
|
-
limit: result.limit,
|
|
229
|
-
offset: result.offset,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
catch (error) {
|
|
233
|
-
console.error("Failed to get wallets:", error.response?.data || error.message);
|
|
234
|
-
throw new Error(`Failed to get wallets: ${error.response?.data?.message || error.message}`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
exports.ServerSDK = ServerSDK;
|
|
239
|
-
__exportStar(require("./types"), exports);
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
ApiKeyStamper: () => import_api_key_stamper2.ApiKeyStamper,
|
|
24
|
+
DerivationPath: () => import_client2.DerivationPath,
|
|
25
|
+
NetworkId: () => import_client2.NetworkId,
|
|
26
|
+
PhantomClient: () => import_client2.PhantomClient,
|
|
27
|
+
ServerSDK: () => ServerSDK,
|
|
28
|
+
deriveSubmissionConfig: () => import_client2.deriveSubmissionConfig,
|
|
29
|
+
generateKeyPair: () => import_client2.generateKeyPair,
|
|
30
|
+
getDerivationPathForNetwork: () => import_client2.getDerivationPathForNetwork,
|
|
31
|
+
getNetworkConfig: () => import_client2.getNetworkConfig,
|
|
32
|
+
getNetworkDescription: () => import_client2.getNetworkDescription,
|
|
33
|
+
getNetworkIdsByChain: () => import_client2.getNetworkIdsByChain,
|
|
34
|
+
getSupportedNetworkIds: () => import_client2.getSupportedNetworkIds,
|
|
35
|
+
supportsTransactionSubmission: () => import_client2.supportsTransactionSubmission
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
var import_client = require("@phantom/client");
|
|
39
|
+
var import_api_key_stamper = require("@phantom/api-key-stamper");
|
|
40
|
+
var import_client2 = require("@phantom/client");
|
|
41
|
+
var import_api_key_stamper2 = require("@phantom/api-key-stamper");
|
|
42
|
+
var ServerSDK = class extends import_client.PhantomClient {
|
|
43
|
+
constructor(config) {
|
|
44
|
+
const stamper = new import_api_key_stamper.ApiKeyStamper({
|
|
45
|
+
apiSecretKey: config.apiPrivateKey
|
|
46
|
+
});
|
|
47
|
+
super(
|
|
48
|
+
{
|
|
49
|
+
apiBaseUrl: config.apiBaseUrl,
|
|
50
|
+
organizationId: config.organizationId
|
|
51
|
+
},
|
|
52
|
+
stamper
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
57
|
+
0 && (module.exports = {
|
|
58
|
+
ApiKeyStamper,
|
|
59
|
+
DerivationPath,
|
|
60
|
+
NetworkId,
|
|
61
|
+
PhantomClient,
|
|
62
|
+
ServerSDK,
|
|
63
|
+
deriveSubmissionConfig,
|
|
64
|
+
generateKeyPair,
|
|
65
|
+
getDerivationPathForNetwork,
|
|
66
|
+
getNetworkConfig,
|
|
67
|
+
getNetworkDescription,
|
|
68
|
+
getNetworkIdsByChain,
|
|
69
|
+
getSupportedNetworkIds,
|
|
70
|
+
supportsTransactionSubmission
|
|
71
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import { PhantomClient } from "@phantom/client";
|
|
3
|
+
import { ApiKeyStamper } from "@phantom/api-key-stamper";
|
|
4
|
+
import {
|
|
5
|
+
PhantomClient as PhantomClient2,
|
|
6
|
+
NetworkId,
|
|
7
|
+
deriveSubmissionConfig,
|
|
8
|
+
supportsTransactionSubmission,
|
|
9
|
+
getNetworkDescription,
|
|
10
|
+
getSupportedNetworkIds,
|
|
11
|
+
getNetworkIdsByChain,
|
|
12
|
+
DerivationPath,
|
|
13
|
+
getDerivationPathForNetwork,
|
|
14
|
+
getNetworkConfig,
|
|
15
|
+
generateKeyPair
|
|
16
|
+
} from "@phantom/client";
|
|
17
|
+
import { ApiKeyStamper as ApiKeyStamper2 } from "@phantom/api-key-stamper";
|
|
18
|
+
var ServerSDK = class extends PhantomClient {
|
|
19
|
+
constructor(config) {
|
|
20
|
+
const stamper = new ApiKeyStamper({
|
|
21
|
+
apiSecretKey: config.apiPrivateKey
|
|
22
|
+
});
|
|
23
|
+
super(
|
|
24
|
+
{
|
|
25
|
+
apiBaseUrl: config.apiBaseUrl,
|
|
26
|
+
organizationId: config.organizationId
|
|
27
|
+
},
|
|
28
|
+
stamper
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
ApiKeyStamper2 as ApiKeyStamper,
|
|
34
|
+
DerivationPath,
|
|
35
|
+
NetworkId,
|
|
36
|
+
PhantomClient2 as PhantomClient,
|
|
37
|
+
ServerSDK,
|
|
38
|
+
deriveSubmissionConfig,
|
|
39
|
+
generateKeyPair,
|
|
40
|
+
getDerivationPathForNetwork,
|
|
41
|
+
getNetworkConfig,
|
|
42
|
+
getNetworkDescription,
|
|
43
|
+
getNetworkIdsByChain,
|
|
44
|
+
getSupportedNetworkIds,
|
|
45
|
+
supportsTransactionSubmission
|
|
46
|
+
};
|
package/package.json
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/server-sdk",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "Server SDK for Phantom Wallet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.mjs",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
7
15
|
"scripts": {
|
|
8
|
-
"build": "
|
|
16
|
+
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts",
|
|
9
17
|
"dev": "tsc --watch",
|
|
10
18
|
"clean": "rm -rf dist",
|
|
11
19
|
"test": "jest",
|
|
12
|
-
"test:watch": "jest --watch"
|
|
20
|
+
"test:watch": "jest --watch",
|
|
21
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
22
|
+
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
13
23
|
},
|
|
14
24
|
"devDependencies": {
|
|
15
25
|
"@types/jest": "^29.5.12",
|
|
16
26
|
"@types/node": "^20.11.0",
|
|
17
27
|
"dotenv": "^16.4.1",
|
|
28
|
+
"eslint": "8.53.0",
|
|
18
29
|
"jest": "^29.7.0",
|
|
30
|
+
"prettier": "^3.5.2",
|
|
31
|
+
"rimraf": "^6.0.1",
|
|
19
32
|
"ts-jest": "^29.1.2",
|
|
33
|
+
"tsup": "^6.7.0",
|
|
20
34
|
"typescript": "^5.0.4"
|
|
21
35
|
},
|
|
22
36
|
"dependencies": {
|
|
23
|
-
"@phantom/
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"tweetnacl": "^1.0.3"
|
|
37
|
+
"@phantom/api-key-stamper": "workspace:^",
|
|
38
|
+
"@phantom/client": "workspace:^",
|
|
39
|
+
"@phantom/openapi-wallet-service": "^0.1.7"
|
|
27
40
|
},
|
|
28
41
|
"files": [
|
|
29
42
|
"dist"
|
package/dist/auth.d.ts
DELETED
package/dist/auth.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createAuthenticatedAxiosInstance = createAuthenticatedAxiosInstance;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
|
-
const tweetnacl_1 = __importDefault(require("tweetnacl"));
|
|
9
|
-
/**
|
|
10
|
-
* Creates an authenticated axios instance that signs requests with Ed25519
|
|
11
|
-
*/
|
|
12
|
-
function createAuthenticatedAxiosInstance(signingKeypair) {
|
|
13
|
-
const instance = axios_1.default.create();
|
|
14
|
-
instance.interceptors.request.use((config) => {
|
|
15
|
-
// Sign the message
|
|
16
|
-
const requestBody = typeof config.data === "string" ? config.data : JSON.stringify(config.data);
|
|
17
|
-
const dataUtf8 = Buffer.from(requestBody, "utf8");
|
|
18
|
-
const signature = tweetnacl_1.default.sign.detached(dataUtf8, signingKeypair.secretKey);
|
|
19
|
-
config.headers["X-Phantom-Sig"] = Buffer.from(signature).toString("base64url");
|
|
20
|
-
return config;
|
|
21
|
-
});
|
|
22
|
-
return instance;
|
|
23
|
-
}
|
package/dist/caip2-mappings.d.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
interface SubmissionConfig {
|
|
2
|
-
chain: string;
|
|
3
|
-
network: string;
|
|
4
|
-
}
|
|
5
|
-
/**
|
|
6
|
-
* User-friendly enum for CAIP-2 network identifiers
|
|
7
|
-
* Use these constants instead of hardcoding network IDs
|
|
8
|
-
*/
|
|
9
|
-
export declare enum NetworkId {
|
|
10
|
-
SOLANA_MAINNET = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
|
|
11
|
-
SOLANA_DEVNET = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
12
|
-
SOLANA_TESTNET = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z",
|
|
13
|
-
ETHEREUM_MAINNET = "eip155:1",
|
|
14
|
-
ETHEREUM_GOERLI = "eip155:5",
|
|
15
|
-
ETHEREUM_SEPOLIA = "eip155:11155111",
|
|
16
|
-
POLYGON_MAINNET = "eip155:137",
|
|
17
|
-
POLYGON_MUMBAI = "eip155:80001",
|
|
18
|
-
OPTIMISM_MAINNET = "eip155:10",
|
|
19
|
-
OPTIMISM_GOERLI = "eip155:420",
|
|
20
|
-
ARBITRUM_ONE = "eip155:42161",
|
|
21
|
-
ARBITRUM_GOERLI = "eip155:421613",
|
|
22
|
-
BASE_MAINNET = "eip155:8453",
|
|
23
|
-
BASE_GOERLI = "eip155:84531",
|
|
24
|
-
BASE_SEPOLIA = "eip155:84532",
|
|
25
|
-
BITCOIN_MAINNET = "bip122:000000000019d6689c085ae165831e93",
|
|
26
|
-
BITCOIN_TESTNET = "bip122:000000000933ea01ad0ee984209779ba",
|
|
27
|
-
SUI_MAINNET = "sui:35834a8a",
|
|
28
|
-
SUI_TESTNET = "sui:4c78adac"
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Derive SubmissionConfig from a CAIP-2 network ID
|
|
32
|
-
* @param networkId - CAIP-2 compliant network ID (e.g., 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')
|
|
33
|
-
* @returns SubmissionConfig if network supports transaction submission, undefined otherwise
|
|
34
|
-
*/
|
|
35
|
-
export declare function deriveSubmissionConfig(networkId: string): SubmissionConfig | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Check if a network ID supports transaction submission
|
|
38
|
-
* @param networkId - CAIP-2 compliant network ID
|
|
39
|
-
* @returns true if the network supports transaction submission
|
|
40
|
-
*/
|
|
41
|
-
export declare function supportsTransactionSubmission(networkId: string): boolean;
|
|
42
|
-
/**
|
|
43
|
-
* Get network description for a CAIP-2 network ID
|
|
44
|
-
* @param networkId - CAIP-2 compliant network ID
|
|
45
|
-
* @returns Network description or undefined if not found
|
|
46
|
-
*/
|
|
47
|
-
export declare function getNetworkDescription(networkId: string): string | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* List all supported CAIP-2 network IDs
|
|
50
|
-
* @returns Array of supported network IDs
|
|
51
|
-
*/
|
|
52
|
-
export declare function getSupportedNetworkIds(): string[];
|
|
53
|
-
/**
|
|
54
|
-
* Get all networks for a specific chain
|
|
55
|
-
* @param chain - Chain name (e.g., 'solana', 'ethereum')
|
|
56
|
-
* @returns Array of network IDs for the specified chain
|
|
57
|
-
*/
|
|
58
|
-
export declare function getNetworkIdsByChain(chain: string): string[];
|
|
59
|
-
export {};
|
package/dist/caip2-mappings.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.NetworkId = void 0;
|
|
4
|
-
exports.deriveSubmissionConfig = deriveSubmissionConfig;
|
|
5
|
-
exports.supportsTransactionSubmission = supportsTransactionSubmission;
|
|
6
|
-
exports.getNetworkDescription = getNetworkDescription;
|
|
7
|
-
exports.getSupportedNetworkIds = getSupportedNetworkIds;
|
|
8
|
-
exports.getNetworkIdsByChain = getNetworkIdsByChain;
|
|
9
|
-
/**
|
|
10
|
-
* User-friendly enum for CAIP-2 network identifiers
|
|
11
|
-
* Use these constants instead of hardcoding network IDs
|
|
12
|
-
*/
|
|
13
|
-
var NetworkId;
|
|
14
|
-
(function (NetworkId) {
|
|
15
|
-
// Solana Networks
|
|
16
|
-
NetworkId["SOLANA_MAINNET"] = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
|
|
17
|
-
NetworkId["SOLANA_DEVNET"] = "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1";
|
|
18
|
-
NetworkId["SOLANA_TESTNET"] = "solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z";
|
|
19
|
-
// Ethereum Networks
|
|
20
|
-
NetworkId["ETHEREUM_MAINNET"] = "eip155:1";
|
|
21
|
-
NetworkId["ETHEREUM_GOERLI"] = "eip155:5";
|
|
22
|
-
NetworkId["ETHEREUM_SEPOLIA"] = "eip155:11155111";
|
|
23
|
-
// Polygon Networks
|
|
24
|
-
NetworkId["POLYGON_MAINNET"] = "eip155:137";
|
|
25
|
-
NetworkId["POLYGON_MUMBAI"] = "eip155:80001";
|
|
26
|
-
// Optimism Networks
|
|
27
|
-
NetworkId["OPTIMISM_MAINNET"] = "eip155:10";
|
|
28
|
-
NetworkId["OPTIMISM_GOERLI"] = "eip155:420";
|
|
29
|
-
// Arbitrum Networks
|
|
30
|
-
NetworkId["ARBITRUM_ONE"] = "eip155:42161";
|
|
31
|
-
NetworkId["ARBITRUM_GOERLI"] = "eip155:421613";
|
|
32
|
-
// Base Networks
|
|
33
|
-
NetworkId["BASE_MAINNET"] = "eip155:8453";
|
|
34
|
-
NetworkId["BASE_GOERLI"] = "eip155:84531";
|
|
35
|
-
NetworkId["BASE_SEPOLIA"] = "eip155:84532";
|
|
36
|
-
// Bitcoin Networks (for future support)
|
|
37
|
-
NetworkId["BITCOIN_MAINNET"] = "bip122:000000000019d6689c085ae165831e93";
|
|
38
|
-
NetworkId["BITCOIN_TESTNET"] = "bip122:000000000933ea01ad0ee984209779ba";
|
|
39
|
-
// Sui Networks (for future support)
|
|
40
|
-
NetworkId["SUI_MAINNET"] = "sui:35834a8a";
|
|
41
|
-
NetworkId["SUI_TESTNET"] = "sui:4c78adac";
|
|
42
|
-
})(NetworkId || (exports.NetworkId = NetworkId = {}));
|
|
43
|
-
const CAIP2_NETWORK_MAPPINGS = {
|
|
44
|
-
// Solana networks
|
|
45
|
-
'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': {
|
|
46
|
-
chain: 'solana',
|
|
47
|
-
network: 'mainnet',
|
|
48
|
-
description: 'Solana Mainnet-Beta'
|
|
49
|
-
},
|
|
50
|
-
'solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1': {
|
|
51
|
-
chain: 'solana',
|
|
52
|
-
network: 'devnet',
|
|
53
|
-
description: 'Solana Devnet'
|
|
54
|
-
},
|
|
55
|
-
'solana:4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z': {
|
|
56
|
-
chain: 'solana',
|
|
57
|
-
network: 'testnet',
|
|
58
|
-
description: 'Solana Testnet'
|
|
59
|
-
},
|
|
60
|
-
// Ethereum/EVM networks
|
|
61
|
-
'eip155:1': {
|
|
62
|
-
chain: 'ethereum',
|
|
63
|
-
network: 'mainnet',
|
|
64
|
-
description: 'Ethereum Mainnet'
|
|
65
|
-
},
|
|
66
|
-
'eip155:5': {
|
|
67
|
-
chain: 'ethereum',
|
|
68
|
-
network: 'goerli',
|
|
69
|
-
description: 'Goerli Testnet'
|
|
70
|
-
},
|
|
71
|
-
'eip155:11155111': {
|
|
72
|
-
chain: 'ethereum',
|
|
73
|
-
network: 'sepolia',
|
|
74
|
-
description: 'Sepolia Testnet'
|
|
75
|
-
},
|
|
76
|
-
'eip155:137': {
|
|
77
|
-
chain: 'polygon',
|
|
78
|
-
network: 'mainnet',
|
|
79
|
-
description: 'Polygon Mainnet'
|
|
80
|
-
},
|
|
81
|
-
'eip155:80001': {
|
|
82
|
-
chain: 'polygon',
|
|
83
|
-
network: 'mumbai',
|
|
84
|
-
description: 'Polygon Mumbai Testnet'
|
|
85
|
-
},
|
|
86
|
-
'eip155:10': {
|
|
87
|
-
chain: 'optimism',
|
|
88
|
-
network: 'mainnet',
|
|
89
|
-
description: 'Optimism Mainnet'
|
|
90
|
-
},
|
|
91
|
-
'eip155:420': {
|
|
92
|
-
chain: 'optimism',
|
|
93
|
-
network: 'goerli',
|
|
94
|
-
description: 'Optimism Goerli Testnet'
|
|
95
|
-
},
|
|
96
|
-
'eip155:42161': {
|
|
97
|
-
chain: 'arbitrum',
|
|
98
|
-
network: 'mainnet',
|
|
99
|
-
description: 'Arbitrum One'
|
|
100
|
-
},
|
|
101
|
-
'eip155:421613': {
|
|
102
|
-
chain: 'arbitrum',
|
|
103
|
-
network: 'goerli',
|
|
104
|
-
description: 'Arbitrum Goerli'
|
|
105
|
-
},
|
|
106
|
-
'eip155:8453': {
|
|
107
|
-
chain: 'base',
|
|
108
|
-
network: 'mainnet',
|
|
109
|
-
description: 'Base Mainnet'
|
|
110
|
-
},
|
|
111
|
-
'eip155:84531': {
|
|
112
|
-
chain: 'base',
|
|
113
|
-
network: 'goerli',
|
|
114
|
-
description: 'Base Goerli Testnet'
|
|
115
|
-
},
|
|
116
|
-
'eip155:84532': {
|
|
117
|
-
chain: 'base',
|
|
118
|
-
network: 'sepolia',
|
|
119
|
-
description: 'Base Sepolia Testnet'
|
|
120
|
-
},
|
|
121
|
-
// Bitcoin networks (for future support)
|
|
122
|
-
'bip122:000000000019d6689c085ae165831e93': {
|
|
123
|
-
chain: 'bitcoin',
|
|
124
|
-
network: 'mainnet',
|
|
125
|
-
description: 'Bitcoin Mainnet'
|
|
126
|
-
},
|
|
127
|
-
'bip122:000000000933ea01ad0ee984209779ba': {
|
|
128
|
-
chain: 'bitcoin',
|
|
129
|
-
network: 'testnet',
|
|
130
|
-
description: 'Bitcoin Testnet'
|
|
131
|
-
},
|
|
132
|
-
// Sui networks (for future support)
|
|
133
|
-
'sui:35834a8a': {
|
|
134
|
-
chain: 'sui',
|
|
135
|
-
network: 'mainnet',
|
|
136
|
-
description: 'Sui Mainnet'
|
|
137
|
-
},
|
|
138
|
-
'sui:4c78adac': {
|
|
139
|
-
chain: 'sui',
|
|
140
|
-
network: 'testnet',
|
|
141
|
-
description: 'Sui Testnet'
|
|
142
|
-
},
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Derive SubmissionConfig from a CAIP-2 network ID
|
|
146
|
-
* @param networkId - CAIP-2 compliant network ID (e.g., 'solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp')
|
|
147
|
-
* @returns SubmissionConfig if network supports transaction submission, undefined otherwise
|
|
148
|
-
*/
|
|
149
|
-
function deriveSubmissionConfig(networkId) {
|
|
150
|
-
const mapping = CAIP2_NETWORK_MAPPINGS[networkId];
|
|
151
|
-
if (!mapping) {
|
|
152
|
-
// Network not found in mappings - cannot derive submission config
|
|
153
|
-
return undefined;
|
|
154
|
-
}
|
|
155
|
-
return {
|
|
156
|
-
chain: mapping.chain,
|
|
157
|
-
network: mapping.network
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Check if a network ID supports transaction submission
|
|
162
|
-
* @param networkId - CAIP-2 compliant network ID
|
|
163
|
-
* @returns true if the network supports transaction submission
|
|
164
|
-
*/
|
|
165
|
-
function supportsTransactionSubmission(networkId) {
|
|
166
|
-
return networkId in CAIP2_NETWORK_MAPPINGS;
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Get network description for a CAIP-2 network ID
|
|
170
|
-
* @param networkId - CAIP-2 compliant network ID
|
|
171
|
-
* @returns Network description or undefined if not found
|
|
172
|
-
*/
|
|
173
|
-
function getNetworkDescription(networkId) {
|
|
174
|
-
return CAIP2_NETWORK_MAPPINGS[networkId]?.description;
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* List all supported CAIP-2 network IDs
|
|
178
|
-
* @returns Array of supported network IDs
|
|
179
|
-
*/
|
|
180
|
-
function getSupportedNetworkIds() {
|
|
181
|
-
return Object.keys(CAIP2_NETWORK_MAPPINGS);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
184
|
-
* Get all networks for a specific chain
|
|
185
|
-
* @param chain - Chain name (e.g., 'solana', 'ethereum')
|
|
186
|
-
* @returns Array of network IDs for the specified chain
|
|
187
|
-
*/
|
|
188
|
-
function getNetworkIdsByChain(chain) {
|
|
189
|
-
return Object.entries(CAIP2_NETWORK_MAPPINGS)
|
|
190
|
-
.filter(([_, mapping]) => mapping.chain.toLowerCase() === chain.toLowerCase())
|
|
191
|
-
.map(([networkId]) => networkId);
|
|
192
|
-
}
|
package/dist/constants.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { DerivationInfoCurveEnum, DerivationInfoAddressFormatEnum, Algorithm } from '@phantom/openapi-wallet-service';
|
|
2
|
-
import { NetworkId } from './caip2-mappings';
|
|
3
|
-
/**
|
|
4
|
-
* Default derivation paths for different blockchain networks
|
|
5
|
-
*/
|
|
6
|
-
export declare enum DerivationPath {
|
|
7
|
-
Solana = "m/44'/501'/0'/0'",
|
|
8
|
-
Ethereum = "m/44'/60'/0'/0/0",
|
|
9
|
-
Bitcoin = "m/84'/0'/0'/0",
|
|
10
|
-
Sui = "m/44'/784'/0'/0'/0'"
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Helper function to get derivation path based on network ID
|
|
14
|
-
*/
|
|
15
|
-
export declare function getDerivationPathForNetwork(networkId: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* Network configuration
|
|
18
|
-
*/
|
|
19
|
-
export interface NetworkConfig {
|
|
20
|
-
derivationPath: string;
|
|
21
|
-
curve: DerivationInfoCurveEnum;
|
|
22
|
-
algorithm: Algorithm;
|
|
23
|
-
addressFormat: DerivationInfoAddressFormatEnum;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Get complete network configuration
|
|
27
|
-
*/
|
|
28
|
-
export declare function getNetworkConfig(networkId: NetworkId): NetworkConfig | null;
|
package/dist/constants.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DerivationPath = void 0;
|
|
4
|
-
exports.getDerivationPathForNetwork = getDerivationPathForNetwork;
|
|
5
|
-
exports.getNetworkConfig = getNetworkConfig;
|
|
6
|
-
const openapi_wallet_service_1 = require("@phantom/openapi-wallet-service");
|
|
7
|
-
/**
|
|
8
|
-
* Default derivation paths for different blockchain networks
|
|
9
|
-
*/
|
|
10
|
-
var DerivationPath;
|
|
11
|
-
(function (DerivationPath) {
|
|
12
|
-
// Solana - BIP44 standard for Solana (coin type 501)
|
|
13
|
-
DerivationPath["Solana"] = "m/44'/501'/0'/0'";
|
|
14
|
-
// Ethereum - BIP44 standard for Ethereum and all EVM-compatible chains (coin type 60)
|
|
15
|
-
DerivationPath["Ethereum"] = "m/44'/60'/0'/0/0";
|
|
16
|
-
// Bitcoin - BIP44 standard for Bitcoin (coin type 0)
|
|
17
|
-
DerivationPath["Bitcoin"] = "m/84'/0'/0'/0";
|
|
18
|
-
// Sui - BIP44 standard for Sui (coin type 784)
|
|
19
|
-
DerivationPath["Sui"] = "m/44'/784'/0'/0'/0'";
|
|
20
|
-
})(DerivationPath || (exports.DerivationPath = DerivationPath = {}));
|
|
21
|
-
/**
|
|
22
|
-
* Helper function to get derivation path based on network ID
|
|
23
|
-
*/
|
|
24
|
-
function getDerivationPathForNetwork(networkId) {
|
|
25
|
-
// Extract the chain name from network ID format (e.g., "solana:mainnet" -> "solana")
|
|
26
|
-
const network = networkId.split(':')[0].toLowerCase();
|
|
27
|
-
switch (network) {
|
|
28
|
-
case 'solana':
|
|
29
|
-
return DerivationPath.Solana;
|
|
30
|
-
case 'sui':
|
|
31
|
-
return DerivationPath.Sui;
|
|
32
|
-
case 'bitcoin':
|
|
33
|
-
case 'btc':
|
|
34
|
-
return DerivationPath.Bitcoin;
|
|
35
|
-
case 'eip155': // EVM chains use eip155 prefix
|
|
36
|
-
case 'ethereum':
|
|
37
|
-
case 'eth':
|
|
38
|
-
default:
|
|
39
|
-
// Default to Ethereum path for all EVM-compatible chains
|
|
40
|
-
return DerivationPath.Ethereum;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Get complete network configuration
|
|
45
|
-
*/
|
|
46
|
-
function getNetworkConfig(networkId) {
|
|
47
|
-
const network = networkId.split(':')[0].toLowerCase();
|
|
48
|
-
switch (network) {
|
|
49
|
-
case 'solana':
|
|
50
|
-
return {
|
|
51
|
-
derivationPath: DerivationPath.Solana,
|
|
52
|
-
curve: openapi_wallet_service_1.DerivationInfoCurveEnum.ed25519,
|
|
53
|
-
algorithm: openapi_wallet_service_1.Algorithm.ed25519,
|
|
54
|
-
addressFormat: openapi_wallet_service_1.DerivationInfoAddressFormatEnum.solana
|
|
55
|
-
};
|
|
56
|
-
case 'sui':
|
|
57
|
-
return {
|
|
58
|
-
derivationPath: DerivationPath.Sui,
|
|
59
|
-
curve: openapi_wallet_service_1.DerivationInfoCurveEnum.ed25519,
|
|
60
|
-
algorithm: openapi_wallet_service_1.Algorithm.ed25519,
|
|
61
|
-
addressFormat: openapi_wallet_service_1.DerivationInfoAddressFormatEnum.sui,
|
|
62
|
-
};
|
|
63
|
-
case 'bitcoin':
|
|
64
|
-
case 'btc':
|
|
65
|
-
return {
|
|
66
|
-
derivationPath: DerivationPath.Bitcoin,
|
|
67
|
-
curve: openapi_wallet_service_1.DerivationInfoCurveEnum.secp256k1,
|
|
68
|
-
algorithm: openapi_wallet_service_1.Algorithm.secp256k1,
|
|
69
|
-
addressFormat: openapi_wallet_service_1.DerivationInfoAddressFormatEnum.bitcoinSegwit // Bitcoin uses a different format, but for SDK consistency we use Ethereum format
|
|
70
|
-
};
|
|
71
|
-
case 'eip155': // EVM chains use eip155 prefix
|
|
72
|
-
// All EVM-compatible chains (Ethereum, Polygon, BSC, Arbitrum, etc.)
|
|
73
|
-
return {
|
|
74
|
-
derivationPath: DerivationPath.Ethereum,
|
|
75
|
-
curve: openapi_wallet_service_1.DerivationInfoCurveEnum.secp256k1,
|
|
76
|
-
algorithm: openapi_wallet_service_1.Algorithm.secp256k1,
|
|
77
|
-
addressFormat: openapi_wallet_service_1.DerivationInfoAddressFormatEnum.ethereum // EVM chains use Ethereum address format
|
|
78
|
-
};
|
|
79
|
-
default:
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
}
|
package/dist/types.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { DerivationInfoAddressFormatEnum } from "@phantom/openapi-wallet-service";
|
|
2
|
-
export interface ServerSDKConfig {
|
|
3
|
-
apiPrivateKey: string;
|
|
4
|
-
organizationId: string;
|
|
5
|
-
apiBaseUrl: string;
|
|
6
|
-
solanaRpcUrl?: string;
|
|
7
|
-
}
|
|
8
|
-
export interface WalletAddress {
|
|
9
|
-
addressType: DerivationInfoAddressFormatEnum;
|
|
10
|
-
address: string;
|
|
11
|
-
}
|
|
12
|
-
export interface CreateWalletResult {
|
|
13
|
-
walletId: string;
|
|
14
|
-
addresses: WalletAddress[];
|
|
15
|
-
}
|
|
16
|
-
export type Transaction = Uint8Array;
|
|
17
|
-
export interface SignedTransaction {
|
|
18
|
-
rawTransaction: string;
|
|
19
|
-
}
|
|
20
|
-
export interface Wallet {
|
|
21
|
-
walletId: string;
|
|
22
|
-
walletName: string;
|
|
23
|
-
}
|
|
24
|
-
export interface GetWalletsResult {
|
|
25
|
-
wallets: Wallet[];
|
|
26
|
-
totalCount: number;
|
|
27
|
-
limit: number;
|
|
28
|
-
offset: number;
|
|
29
|
-
}
|
package/dist/types.js
DELETED