@phantom/server-sdk 0.0.3 → 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 CHANGED
@@ -1,228 +1,240 @@
1
1
  # Phantom Server SDK
2
2
 
3
- The Phantom Server SDK enables secure wallet creation, message signing and transaction signing and submission for your applications.
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
+
5
+ ## 📖 Documentation
6
+
7
+ Visit **[docs.phantom.com/server-sdk](https://docs.phantom.com/server-sdk)** for comprehensive documentation including:
8
+
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
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
4
26
 
5
27
  ## Installation
6
28
 
29
+ Install the Server SDK using your preferred package manager:
30
+
7
31
  ```bash
8
32
  npm install @phantom/server-sdk
9
33
  ```
10
34
 
11
- ## Configuration
35
+ ```bash
36
+ yarn add @phantom/server-sdk
37
+ ```
12
38
 
13
- To get started, initialize the SDK with your credentials:
39
+ ```bash
40
+ pnpm add @phantom/server-sdk
41
+ ```
14
42
 
15
- ```typescript
16
- import { ServerSDK } from '@phantom/server-sdk';
43
+ ## Prerequisites
17
44
 
18
- const sdk = new ServerSDK({
19
- apiPrivateKey: 'your-private-key', // Base58 encoded private key
20
- organizationId: 'your-org-id', // Your organization ID
21
- apiBaseUrl: 'https://api.phantom.app/wallet'
22
- });
23
- ```
45
+ Before using the SDK, you need:
24
46
 
25
- ## Network Identifiers
47
+ 1. **Phantom Organization Credentials**
26
48
 
27
- The SDK provides user-friendly enums for CAIP-2 network identifiers:
49
+ - Organization ID
50
+ - Organization Private Key (base58 encoded)
51
+ - API Base URL
28
52
 
29
- ```typescript
30
- import { NetworkId } from '@phantom/server-sdk';
53
+ These credentials are provided when you create an organization with Phantom.
31
54
 
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'
55
+ 2. **Node.js** version 16 or higher
36
56
 
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
- );
57
+ ## Security First
43
58
 
44
- // Sign a message on Ethereum
45
- const signature = await sdk.signMessage(
46
- walletId,
47
- 'Hello World',
48
- NetworkId.ETHEREUM_MAINNET
49
- );
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
+
65
+ ## Quick Start
66
+
67
+ ### 1. Set up Environment Variables
50
68
 
69
+ Create a `.env` file in your project root:
51
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
52
75
  ```
53
76
 
54
- ### Available Networks
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.
77
+ ### 2. Initialize the SDK
95
78
 
96
79
  ```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
- // }
80
+ import { ServerSDK, NetworkId } from "@phantom/server-sdk";
81
+ import dotenv from "dotenv";
82
+
83
+ // Load environment variables
84
+ dotenv.config();
85
+
86
+ // Initialize the SDK
87
+ const sdk = new ServerSDK({
88
+ organizationId: process.env.ORGANIZATION_ID!,
89
+ apiPrivateKey: process.env.PRIVATE_KEY!,
90
+ apiBaseUrl: process.env.API_URL!,
91
+ });
92
+
93
+ // Create a wallet
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);
107
102
  ```
108
103
 
109
- ### signAndSendTransaction(walletId: string, transaction: Uint8Array, networkId: string)
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.
104
+ ## Usage Examples
105
+
106
+ ### Creating a Wallet
112
107
 
113
108
  ```typescript
114
- import { NetworkId } from '@phantom/server-sdk';
109
+ // Create a wallet with a custom name
110
+ const wallet = await sdk.createWallet("User Wallet 123");
115
111
 
116
- const transactionBuffer = new Uint8Array([...]); // Your serialized transaction
117
- const result = await sdk.signAndSendTransaction(
118
- 'wallet-id',
119
- transactionBuffer,
120
- NetworkId.SOLANA_MAINNET
121
- );
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;
122
116
 
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);
117
+ console.log("Solana address:", solanaAddress);
118
+ console.log("Ethereum address:", ethereumAddress);
134
119
  ```
135
120
 
136
- ### signMessage(walletId: string, message: string, networkId: string)
137
- Signs a message with the specified wallet.
121
+ ### Signing and Sending Transactions
138
122
 
139
123
  ```typescript
140
- const signature = await sdk.signMessage(
141
- 'wallet-id',
142
- 'Hello World',
143
- NetworkId.SOLANA_MAINNET
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
+ }),
144
133
  );
145
- // Returns: base64 encoded signature
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);
146
152
  ```
147
153
 
148
- ### getWallets(limit?: number, offset?: number)
149
- Retrieves all wallets for your organization with pagination support.
154
+ ### Signing Messages
150
155
 
151
156
  ```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();
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);
163
164
  ```
164
165
 
165
- ### getWalletAddresses(walletId: string, derivationPaths?: string[])
166
- Retrieves addresses for a specific wallet across different blockchains.
166
+ ### Managing Wallets
167
167
 
168
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
- ```
169
+ // Get all wallets for your organization with pagination
170
+ const result = await sdk.getWallets(20, 0); // limit: 20, offset: 0
177
171
 
178
- ## CAIP-2 Utility Functions
172
+ console.log(`Total wallets: ${result.totalCount}`);
173
+ console.log("Wallets:", result.wallets);
179
174
 
180
- The SDK exports several utility functions for working with CAIP-2 network identifiers:
175
+ // Get addresses for a specific wallet
176
+ const addresses = await sdk.getWalletAddresses(walletId);
181
177
 
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', ...]
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
182
+ );
205
183
  ```
206
184
 
207
- ## Security Best Practices
185
+ ## Network Support
208
186
 
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
187
+ The SDK supports multiple blockchain networks through the `NetworkId` enum:
213
188
 
214
- ## Error Handling
189
+ ### Solana Networks
215
190
 
216
- All SDK methods throw descriptive errors when operations fail:
191
+ - `NetworkId.SOLANA_MAINNET` - Solana Mainnet-Beta
192
+ - `NetworkId.SOLANA_DEVNET` - Solana Devnet
193
+ - `NetworkId.SOLANA_TESTNET` - Solana Testnet
217
194
 
218
- ```typescript
219
- try {
220
- const wallet = await sdk.createWallet();
221
- } catch (error) {
222
- console.error('Failed to create wallet:', error.message);
223
- }
224
- ```
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
225
+
226
+ ## Resources
227
+
228
+ - [Documentation](https://docs.phantom.com/server-sdk)
229
+ - [Example Code](https://github.com/phantom/wallet-sdk/tree/main/examples/server-sdk-examples)
230
+ - [Integration Guide](https://docs.phantom.com/server-sdk/integration-guide)
231
+ - [API Reference](https://docs.phantom.com/server-sdk/api-reference)
232
+ - [Changelog](./CHANGELOG.md)
233
+
234
+ ## License
235
+
236
+ This SDK is distributed under the MIT License. See the [LICENSE](../../LICENSE) file for details.
225
237
 
226
- ## Support
238
+ ## Contributing
227
239
 
228
- For detailed integration examples and best practices, see the [Integration Guide](./INTEGRATION.md).
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 { ServerSDKConfig, CreateWalletResult, Transaction, SignedTransaction, GetWalletsResult } from "./types";
2
- import { NetworkId } from "./caip2-mappings";
3
- export interface SubmissionConfig {
4
- chain: string;
5
- network: string;
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
- export { NetworkId, deriveSubmissionConfig, supportsTransactionSubmission, getNetworkDescription, getSupportedNetworkIds, getNetworkIdsByChain } from "./caip2-mappings";
8
- export declare class ServerSDK {
9
- private config;
10
- private kmsApi;
11
- private signingKeypair;
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
- export * from "./types";
19
+
20
+ export { ServerSDK, ServerSDKConfig, WalletAddress };
package/dist/index.js CHANGED
@@ -1,239 +1,71 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
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 __importDefault = (this && this.__importDefault) || function (mod) {
17
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
- Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.ServerSDK = exports.getNetworkIdsByChain = exports.getSupportedNetworkIds = exports.getNetworkDescription = exports.supportsTransactionSubmission = exports.deriveSubmissionConfig = exports.NetworkId = void 0;
21
- const auth_1 = require("./auth");
22
- const constants_1 = require("./constants");
23
- const caip2_mappings_1 = require("./caip2-mappings");
24
- const bs58_1 = __importDefault(require("bs58"));
25
- const openapi_wallet_service_1 = require("@phantom/openapi-wallet-service");
26
- const tweetnacl_1 = __importDefault(require("tweetnacl"));
27
- // Export CAIP-2 utilities and enums
28
- var caip2_mappings_2 = require("./caip2-mappings");
29
- Object.defineProperty(exports, "NetworkId", { enumerable: true, get: function () { return caip2_mappings_2.NetworkId; } });
30
- Object.defineProperty(exports, "deriveSubmissionConfig", { enumerable: true, get: function () { return caip2_mappings_2.deriveSubmissionConfig; } });
31
- Object.defineProperty(exports, "supportsTransactionSubmission", { enumerable: true, get: function () { return caip2_mappings_2.supportsTransactionSubmission; } });
32
- Object.defineProperty(exports, "getNetworkDescription", { enumerable: true, get: function () { return caip2_mappings_2.getNetworkDescription; } });
33
- Object.defineProperty(exports, "getSupportedNetworkIds", { enumerable: true, get: function () { return caip2_mappings_2.getSupportedNetworkIds; } });
34
- Object.defineProperty(exports, "getNetworkIdsByChain", { enumerable: true, get: function () { return caip2_mappings_2.getNetworkIdsByChain; } });
35
- class ServerSDK {
36
- constructor(config) {
37
- this.config = config;
38
- if (!config.organizationId || !config.apiBaseUrl) {
39
- throw new Error("organizationId and apiBaseUrl are required");
40
- }
41
- // Decode the private key from base58
42
- const privateKeyBytes = bs58_1.default.decode(config.apiPrivateKey);
43
- this.signingKeypair = tweetnacl_1.default.sign.keyPair.fromSecretKey(privateKeyBytes);
44
- // Create authenticated axios instance
45
- const authenticatedAxios = (0, auth_1.createAuthenticatedAxiosInstance)(this.signingKeypair);
46
- // Configure the KMS API client with authentication
47
- const configuration = new openapi_wallet_service_1.Configuration({
48
- basePath: config.apiBaseUrl,
49
- });
50
- // Pass the authenticated axios instance to the KMS API
51
- this.kmsApi = new openapi_wallet_service_1.KMSRPCApi(configuration, config.apiBaseUrl, authenticatedAxios);
52
- }
53
- async createWallet(walletName) {
54
- try {
55
- // Create wallet request
56
- const walletRequest = {
57
- organizationId: this.config.organizationId,
58
- walletName: walletName || `Wallet ${Date.now()}`,
59
- accounts: [constants_1.DerivationPath.Solana, constants_1.DerivationPath.Ethereum, constants_1.DerivationPath.Bitcoin, constants_1.DerivationPath.Sui],
60
- };
61
- console.log("Creating wallet with request:", walletRequest);
62
- const request = {
63
- method: openapi_wallet_service_1.CreateWalletMethodEnum.createWallet,
64
- params: walletRequest,
65
- timestampMs: Date.now(),
66
- };
67
- const response = await this.kmsApi.postKmsRpc(request);
68
- const walletResult = response.data.result;
69
- console.log("Wallet created successfully:", walletResult);
70
- // Fetch the accounts
71
- const requestAccounts = {
72
- method: openapi_wallet_service_1.GetAccountsMethodEnum.getAccounts,
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('base64');
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("base64");
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",
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": "tsc",
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/openapi-wallet-service": "^0.1.5",
24
- "axios": "^1.10.0",
25
- "bs58": "^6.0.0",
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
@@ -1,6 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import nacl from 'tweetnacl';
3
- /**
4
- * Creates an authenticated axios instance that signs requests with Ed25519
5
- */
6
- export declare function createAuthenticatedAxiosInstance(signingKeypair: nacl.SignKeyPair): AxiosInstance;
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("base64");
20
- return config;
21
- });
22
- return instance;
23
- }
@@ -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 {};
@@ -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
- }
@@ -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
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });