@phantom/server-sdk 0.1.1 β 0.1.3
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 +65 -19
- package/dist/index.d.ts +26 -3
- package/dist/index.js +34 -0
- package/dist/index.mjs +35 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -95,11 +95,10 @@ 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
|
|
99
|
-
const message = Buffer.from("Hello, Phantom!").toString("base64url");
|
|
98
|
+
// Sign a message
|
|
100
99
|
const signature = await sdk.signMessage({
|
|
101
100
|
walletId: wallet.walletId,
|
|
102
|
-
message,
|
|
101
|
+
message: "Hello, Phantom!",
|
|
103
102
|
networkId: NetworkId.SOLANA_MAINNET,
|
|
104
103
|
});
|
|
105
104
|
console.log("Signature:", signature);
|
|
@@ -124,6 +123,8 @@ console.log("Ethereum address:", ethereumAddress);
|
|
|
124
123
|
|
|
125
124
|
### Signing and Sending Transactions
|
|
126
125
|
|
|
126
|
+
#### Solana - Native Web3.js Transaction Objects
|
|
127
|
+
|
|
127
128
|
```typescript
|
|
128
129
|
import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";
|
|
129
130
|
|
|
@@ -140,41 +141,86 @@ const transaction = new Transaction().add(
|
|
|
140
141
|
transaction.recentBlockhash = blockhash;
|
|
141
142
|
transaction.feePayer = new PublicKey(solanaAddress);
|
|
142
143
|
|
|
143
|
-
// Serialize the transaction
|
|
144
|
-
const serializedTx = transaction.serialize({
|
|
145
|
-
requireAllSignatures: false,
|
|
146
|
-
verifySignatures: false,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
// Convert to base64url
|
|
150
|
-
const transactionBase64 = Buffer.from(serializedTx).toString("base64url");
|
|
151
|
-
|
|
152
144
|
// Sign and send the transaction
|
|
153
145
|
const signedTx = await sdk.signAndSendTransaction({
|
|
154
146
|
walletId: wallet.walletId,
|
|
155
|
-
transaction
|
|
147
|
+
transaction,
|
|
156
148
|
networkId: NetworkId.SOLANA_MAINNET,
|
|
157
149
|
});
|
|
158
150
|
|
|
159
151
|
console.log("Signed transaction:", signedTx.rawTransaction);
|
|
160
152
|
```
|
|
161
153
|
|
|
154
|
+
#### Ethereum/EVM - Transaction Objects
|
|
155
|
+
|
|
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
|
+
});
|
|
202
|
+
```
|
|
203
|
+
|
|
162
204
|
### Signing Messages
|
|
163
205
|
|
|
164
206
|
```typescript
|
|
165
|
-
// Sign a message for Solana (base64url encoded)
|
|
166
|
-
const solanaMessage = Buffer.from("Please sign this message to authenticate").toString("base64url");
|
|
167
207
|
const solanaSignature = await sdk.signMessage({
|
|
168
208
|
walletId: wallet.walletId,
|
|
169
|
-
message:
|
|
209
|
+
message: "Please sign this message to authenticate",
|
|
210
|
+
networkId: NetworkId.SOLANA_MAINNET,
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
// Unicode messages work too
|
|
214
|
+
const unicodeSignature = await sdk.signMessage({
|
|
215
|
+
walletId: wallet.walletId,
|
|
216
|
+
message: "π Welcome to Web3! δ½ ε₯½δΈη", // Unicode text
|
|
170
217
|
networkId: NetworkId.SOLANA_MAINNET,
|
|
171
218
|
});
|
|
172
219
|
|
|
173
|
-
|
|
174
|
-
const ethMessage = Buffer.from("Sign in to our dApp").toString("base64url");
|
|
220
|
+
const ethMessage = Buffer.from().toString("base64url");
|
|
175
221
|
const ethSignature = await sdk.signMessage({
|
|
176
222
|
walletId: wallet.walletId,
|
|
177
|
-
message:
|
|
223
|
+
message: "Sign in to our dApp",
|
|
178
224
|
networkId: NetworkId.ETHEREUM_MAINNET,
|
|
179
225
|
});
|
|
180
226
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { PhantomClient } from '@phantom/client';
|
|
2
|
-
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, NetworkId, PhantomClient,
|
|
1
|
+
import { NetworkId, 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
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 {
|
|
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.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Server SDK for Phantom Wallet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -36,9 +36,10 @@
|
|
|
36
36
|
"typescript": "^5.0.4"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@phantom/api-key-stamper": "^0.1.
|
|
40
|
-
"@phantom/client": "^0.1.
|
|
41
|
-
"@phantom/openapi-wallet-service": "^0.1.7"
|
|
39
|
+
"@phantom/api-key-stamper": "^0.1.1",
|
|
40
|
+
"@phantom/client": "^0.1.2",
|
|
41
|
+
"@phantom/openapi-wallet-service": "^0.1.7",
|
|
42
|
+
"@phantom/parsers": "^0.0.3"
|
|
42
43
|
},
|
|
43
44
|
"files": [
|
|
44
45
|
"dist"
|