@phantom/server-sdk 0.1.0 β†’ 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -95,9 +95,12 @@ const wallet = await sdk.createWallet("My First Wallet");
95
95
  console.log("Wallet ID:", wallet.walletId);
96
96
  console.log("Addresses:", wallet.addresses);
97
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);
98
+ // Sign a message
99
+ const signature = await sdk.signMessage({
100
+ walletId: wallet.walletId,
101
+ message: "Hello, Phantom!",
102
+ networkId: NetworkId.SOLANA_MAINNET,
103
+ });
101
104
  console.log("Signature:", signature);
102
105
  ```
103
106
 
@@ -120,6 +123,8 @@ console.log("Ethereum address:", ethereumAddress);
120
123
 
121
124
  ### Signing and Sending Transactions
122
125
 
126
+ #### Solana - Native Web3.js Transaction Objects
127
+
123
128
  ```typescript
124
129
  import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";
125
130
 
@@ -136,31 +141,88 @@ const transaction = new Transaction().add(
136
141
  transaction.recentBlockhash = blockhash;
137
142
  transaction.feePayer = new PublicKey(solanaAddress);
138
143
 
139
- // Serialize the transaction
140
- const serializedTx = transaction.serialize({
141
- requireAllSignatures: false,
142
- verifySignatures: false,
144
+ // Sign and send the transaction
145
+ const signedTx = await sdk.signAndSendTransaction({
146
+ walletId: wallet.walletId,
147
+ transaction,
148
+ networkId: NetworkId.SOLANA_MAINNET,
143
149
  });
144
150
 
145
- // Convert to base64url
146
- const transactionBase64 = Buffer.from(serializedTx).toString("base64url");
151
+ console.log("Signed transaction:", signedTx.rawTransaction);
152
+ ```
147
153
 
148
- // Sign and send the transaction
149
- const signedTx = await sdk.signAndSendTransaction(wallet.walletId, transactionBase64, NetworkId.SOLANA_MAINNET);
154
+ #### Ethereum/EVM - Transaction Objects
150
155
 
151
- console.log("Signed transaction:", signedTx.rawTransaction);
156
+ ```typescript
157
+ // Viem transaction object
158
+ const evmTransaction = {
159
+ to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
160
+ value: 1000000000000000000n, // 1 ETH in wei
161
+ data: "0x",
162
+ gasLimit: 21000n,
163
+ };
164
+
165
+ const signedEvmTx = await sdk.signAndSendTransaction({
166
+ walletId: wallet.walletId,
167
+ transaction: evmTransaction, // Native EVM transaction object
168
+ networkId: NetworkId.ETHEREUM_MAINNET,
169
+ });
170
+
171
+ // Ethers.js transactions also supported
172
+ const ethersTransaction = {
173
+ to: recipientAddress,
174
+ value: ethers.parseEther("0.01"),
175
+ serialize: () => "0x...", // Ethers serialization method
176
+ };
177
+
178
+ await sdk.signAndSendTransaction({
179
+ walletId: wallet.walletId,
180
+ transaction: ethersTransaction,
181
+ networkId: NetworkId.ETHEREUM_MAINNET,
182
+ });
183
+ ```
184
+
185
+ #### Raw Formats - Hex Strings and Bytes
186
+
187
+ ```typescript
188
+ // Hex string transaction
189
+ await sdk.signAndSendTransaction({
190
+ walletId: wallet.walletId,
191
+ transaction: "0x02f8710182013685012a05f2008301388094742d35cc...", // Raw hex
192
+ networkId: NetworkId.ETHEREUM_MAINNET,
193
+ });
194
+
195
+ // Raw bytes
196
+ const transactionBytes = new Uint8Array([1, 2, 3, 4, 5 /* ... */]);
197
+ await sdk.signAndSendTransaction({
198
+ walletId: wallet.walletId,
199
+ transaction: transactionBytes,
200
+ networkId: NetworkId.SOLANA_MAINNET,
201
+ });
152
202
  ```
153
203
 
154
204
  ### Signing Messages
155
205
 
156
206
  ```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);
207
+ const solanaSignature = await sdk.signMessage({
208
+ walletId: wallet.walletId,
209
+ message: "Please sign this message to authenticate",
210
+ networkId: NetworkId.SOLANA_MAINNET,
211
+ });
160
212
 
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);
213
+ // Unicode messages work too
214
+ const unicodeSignature = await sdk.signMessage({
215
+ walletId: wallet.walletId,
216
+ message: "πŸš€ Welcome to Web3! δ½ ε₯½δΈ–η•Œ", // Unicode text
217
+ networkId: NetworkId.SOLANA_MAINNET,
218
+ });
219
+
220
+ const ethMessage = Buffer.from().toString("base64url");
221
+ const ethSignature = await sdk.signMessage({
222
+ walletId: wallet.walletId,
223
+ message: "Sign in to our dApp",
224
+ networkId: NetworkId.ETHEREUM_MAINNET,
225
+ });
164
226
  ```
165
227
 
166
228
  ### Managing Wallets
@@ -218,8 +280,8 @@ For complete API documentation, visit **[docs.phantom.com/server-sdk](https://do
218
280
  ### Key Methods
219
281
 
220
282
  - `createWallet(walletName?)` - Creates a new wallet
221
- - `signAndSendTransaction(walletId, transaction, networkId)` - Signs and optionally submits transactions
222
- - `signMessage(walletId, message, networkId)` - Signs arbitrary messages
283
+ - `signAndSendTransaction(params)` - Signs and optionally submits transactions
284
+ - `signMessage(params)` - Signs arbitrary messages
223
285
  - `getWalletAddresses(walletId, derivationPaths?)` - Retrieves wallet addresses
224
286
  - `getWallets(limit?, offset?)` - Lists all wallets with pagination
225
287
 
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { PhantomClient } from '@phantom/client';
1
+ import { NetworkId, PhantomClient } from '@phantom/client';
2
2
  export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, NetworkId, PhantomClient, SignedTransaction, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
3
3
  export { ApiKeyStamper } from '@phantom/api-key-stamper';
4
+ export { ParsedMessage, ParsedTransaction, parseMessage, parseTransaction } from '@phantom/parsers';
4
5
  import { DerivationInfoAddressFormatEnum } from '@phantom/openapi-wallet-service';
5
6
 
6
7
  interface WalletAddress {
@@ -13,8 +14,30 @@ interface ServerSDKConfig {
13
14
  apiBaseUrl: string;
14
15
  apiPrivateKey: string;
15
16
  }
17
+ interface ServerSignMessageParams {
18
+ walletId: string;
19
+ message: string;
20
+ networkId: NetworkId;
21
+ }
22
+ interface ServerSignAndSendTransactionParams {
23
+ walletId: string;
24
+ transaction: any;
25
+ networkId: NetworkId;
26
+ }
16
27
  declare class ServerSDK extends PhantomClient {
17
28
  constructor(config: ServerSDKConfig);
29
+ /**
30
+ * Sign a message - supports plain text and automatically converts to base64url
31
+ * @param params - Message parameters with plain text message
32
+ * @returns Promise<string> - Base64 encoded signature
33
+ */
34
+ signMessage(params: ServerSignMessageParams): Promise<string>;
35
+ /**
36
+ * Sign and send a transaction - supports various transaction formats and automatically parses them
37
+ * @param params - Transaction parameters with flexible transaction format
38
+ * @returns Promise<SignedTransaction> - Signed transaction result
39
+ */
40
+ signAndSendTransaction(params: ServerSignAndSendTransactionParams): Promise<any>;
18
41
  }
19
42
 
20
- export { ServerSDK, ServerSDKConfig, WalletAddress };
43
+ export { ServerSDK, ServerSDKConfig, ServerSignAndSendTransactionParams, ServerSignMessageParams, WalletAddress };
package/dist/index.js CHANGED
@@ -32,13 +32,17 @@ __export(src_exports, {
32
32
  getNetworkDescription: () => import_client2.getNetworkDescription,
33
33
  getNetworkIdsByChain: () => import_client2.getNetworkIdsByChain,
34
34
  getSupportedNetworkIds: () => import_client2.getSupportedNetworkIds,
35
+ parseMessage: () => import_parsers2.parseMessage,
36
+ parseTransaction: () => import_parsers2.parseTransaction,
35
37
  supportsTransactionSubmission: () => import_client2.supportsTransactionSubmission
36
38
  });
37
39
  module.exports = __toCommonJS(src_exports);
38
40
  var import_client = require("@phantom/client");
39
41
  var import_api_key_stamper = require("@phantom/api-key-stamper");
42
+ var import_parsers = require("@phantom/parsers");
40
43
  var import_client2 = require("@phantom/client");
41
44
  var import_api_key_stamper2 = require("@phantom/api-key-stamper");
45
+ var import_parsers2 = require("@phantom/parsers");
42
46
  var ServerSDK = class extends import_client.PhantomClient {
43
47
  constructor(config) {
44
48
  const stamper = new import_api_key_stamper.ApiKeyStamper({
@@ -52,6 +56,34 @@ var ServerSDK = class extends import_client.PhantomClient {
52
56
  stamper
53
57
  );
54
58
  }
59
+ /**
60
+ * Sign a message - supports plain text and automatically converts to base64url
61
+ * @param params - Message parameters with plain text message
62
+ * @returns Promise<string> - Base64 encoded signature
63
+ */
64
+ signMessage(params) {
65
+ const parsedMessage = (0, import_parsers.parseMessage)(params.message);
66
+ const signMessageParams = {
67
+ walletId: params.walletId,
68
+ message: parsedMessage.base64url,
69
+ networkId: params.networkId
70
+ };
71
+ return super.signMessage(signMessageParams);
72
+ }
73
+ /**
74
+ * Sign and send a transaction - supports various transaction formats and automatically parses them
75
+ * @param params - Transaction parameters with flexible transaction format
76
+ * @returns Promise<SignedTransaction> - Signed transaction result
77
+ */
78
+ async signAndSendTransaction(params) {
79
+ const parsedTransaction = await (0, import_parsers.parseTransaction)(params.transaction, params.networkId);
80
+ const signAndSendParams = {
81
+ walletId: params.walletId,
82
+ transaction: parsedTransaction.base64url,
83
+ networkId: params.networkId
84
+ };
85
+ return super.signAndSendTransaction(signAndSendParams);
86
+ }
55
87
  };
56
88
  // Annotate the CommonJS export names for ESM import in node:
57
89
  0 && (module.exports = {
@@ -67,5 +99,7 @@ var ServerSDK = class extends import_client.PhantomClient {
67
99
  getNetworkDescription,
68
100
  getNetworkIdsByChain,
69
101
  getSupportedNetworkIds,
102
+ parseMessage,
103
+ parseTransaction,
70
104
  supportsTransactionSubmission
71
105
  });
package/dist/index.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  // src/index.ts
2
- import { PhantomClient } from "@phantom/client";
2
+ import {
3
+ PhantomClient
4
+ } from "@phantom/client";
3
5
  import { ApiKeyStamper } from "@phantom/api-key-stamper";
6
+ import { parseMessage, parseTransaction } from "@phantom/parsers";
4
7
  import {
5
8
  PhantomClient as PhantomClient2,
6
9
  NetworkId,
@@ -15,6 +18,7 @@ import {
15
18
  generateKeyPair
16
19
  } from "@phantom/client";
17
20
  import { ApiKeyStamper as ApiKeyStamper2 } from "@phantom/api-key-stamper";
21
+ import { parseMessage as parseMessage2, parseTransaction as parseTransaction2 } from "@phantom/parsers";
18
22
  var ServerSDK = class extends PhantomClient {
19
23
  constructor(config) {
20
24
  const stamper = new ApiKeyStamper({
@@ -28,6 +32,34 @@ var ServerSDK = class extends PhantomClient {
28
32
  stamper
29
33
  );
30
34
  }
35
+ /**
36
+ * Sign a message - supports plain text and automatically converts to base64url
37
+ * @param params - Message parameters with plain text message
38
+ * @returns Promise<string> - Base64 encoded signature
39
+ */
40
+ signMessage(params) {
41
+ const parsedMessage = parseMessage(params.message);
42
+ const signMessageParams = {
43
+ walletId: params.walletId,
44
+ message: parsedMessage.base64url,
45
+ networkId: params.networkId
46
+ };
47
+ return super.signMessage(signMessageParams);
48
+ }
49
+ /**
50
+ * Sign and send a transaction - supports various transaction formats and automatically parses them
51
+ * @param params - Transaction parameters with flexible transaction format
52
+ * @returns Promise<SignedTransaction> - Signed transaction result
53
+ */
54
+ async signAndSendTransaction(params) {
55
+ const parsedTransaction = await parseTransaction(params.transaction, params.networkId);
56
+ const signAndSendParams = {
57
+ walletId: params.walletId,
58
+ transaction: parsedTransaction.base64url,
59
+ networkId: params.networkId
60
+ };
61
+ return super.signAndSendTransaction(signAndSendParams);
62
+ }
31
63
  };
32
64
  export {
33
65
  ApiKeyStamper2 as ApiKeyStamper,
@@ -42,5 +74,7 @@ export {
42
74
  getNetworkDescription,
43
75
  getNetworkIdsByChain,
44
76
  getSupportedNetworkIds,
77
+ parseMessage2 as parseMessage,
78
+ parseTransaction2 as parseTransaction,
45
79
  supportsTransactionSubmission
46
80
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/server-sdk",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Server SDK for Phantom Wallet",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -13,6 +13,8 @@
13
13
  }
14
14
  },
15
15
  "scripts": {
16
+ "?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
17
+ "pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
16
18
  "build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts",
17
19
  "dev": "tsc --watch",
18
20
  "clean": "rm -rf dist",
@@ -34,11 +36,15 @@
34
36
  "typescript": "^5.0.4"
35
37
  },
36
38
  "dependencies": {
37
- "@phantom/api-key-stamper": "workspace:^",
38
- "@phantom/client": "workspace:^",
39
- "@phantom/openapi-wallet-service": "^0.1.7"
39
+ "@phantom/api-key-stamper": "^0.1.1",
40
+ "@phantom/client": "^0.1.1",
41
+ "@phantom/openapi-wallet-service": "^0.1.7",
42
+ "@phantom/parsers": "^0.0.2"
40
43
  },
41
44
  "files": [
42
45
  "dist"
43
- ]
44
- }
46
+ ],
47
+ "publishConfig": {
48
+ "directory": "_release/package"
49
+ }
50
+ }