@phantom/server-sdk 1.0.0-beta.2 → 1.0.0-beta.21
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 +63 -9
- package/dist/index.d.ts +5 -2
- package/dist/index.js +116 -27
- package/dist/index.mjs +119 -28
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -86,8 +86,8 @@ dotenv.config();
|
|
|
86
86
|
// Initialize the SDK
|
|
87
87
|
const sdk = new ServerSDK({
|
|
88
88
|
organizationId: process.env.ORGANIZATION_ID!,
|
|
89
|
+
appId: process.env.APP_ID!,
|
|
89
90
|
apiPrivateKey: process.env.PRIVATE_KEY!,
|
|
90
|
-
apiBaseUrl: process.env.API_URL!,
|
|
91
91
|
});
|
|
92
92
|
|
|
93
93
|
// Create a wallet
|
|
@@ -311,7 +311,7 @@ const customAddresses = await sdk.getWalletAddresses(
|
|
|
311
311
|
|
|
312
312
|
## Network Support
|
|
313
313
|
|
|
314
|
-
The SDK
|
|
314
|
+
The Server SDK uses the `NetworkId` enum to identify blockchain networks for signing transactions and messages.
|
|
315
315
|
|
|
316
316
|
### Solana Networks
|
|
317
317
|
|
|
@@ -322,21 +322,75 @@ The SDK supports multiple blockchain networks through the `NetworkId` enum:
|
|
|
322
322
|
### Ethereum Networks
|
|
323
323
|
|
|
324
324
|
- `NetworkId.ETHEREUM_MAINNET` - Ethereum Mainnet
|
|
325
|
-
- `NetworkId.ETHEREUM_GOERLI` - Goerli Testnet
|
|
326
325
|
- `NetworkId.ETHEREUM_SEPOLIA` - Sepolia Testnet
|
|
327
326
|
|
|
328
|
-
###
|
|
327
|
+
### Polygon Networks
|
|
329
328
|
|
|
330
|
-
- `NetworkId.POLYGON_MAINNET` - Polygon Mainnet
|
|
331
|
-
- `NetworkId.
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
329
|
+
- `NetworkId.POLYGON_MAINNET` - Polygon Mainnet (Chain ID: 137)
|
|
330
|
+
- `NetworkId.POLYGON_AMOY` - Polygon Amoy Testnet (Chain ID: 80002)
|
|
331
|
+
|
|
332
|
+
### Base Networks
|
|
333
|
+
|
|
334
|
+
- `NetworkId.BASE_MAINNET` - Base Mainnet (Chain ID: 8453)
|
|
335
|
+
- `NetworkId.BASE_SEPOLIA` - Base Sepolia Testnet (Chain ID: 84532)
|
|
336
|
+
|
|
337
|
+
### Arbitrum Networks
|
|
338
|
+
|
|
339
|
+
- `NetworkId.ARBITRUM_ONE` - Arbitrum One (Chain ID: 42161)
|
|
340
|
+
- `NetworkId.ARBITRUM_SEPOLIA` - Arbitrum Sepolia Testnet (Chain ID: 421614)
|
|
341
|
+
|
|
342
|
+
### Monad Networks
|
|
343
|
+
|
|
344
|
+
- `NetworkId.MONAD_MAINNET` - Monad Mainnet (Chain ID: 143)
|
|
345
|
+
- `NetworkId.MONAD_TESTNET` - Monad Testnet (Chain ID: 10143)
|
|
335
346
|
|
|
336
347
|
### Future Support
|
|
337
348
|
|
|
338
349
|
- `NetworkId.BITCOIN_MAINNET` - Bitcoin Mainnet
|
|
350
|
+
- `NetworkId.BITCOIN_TESTNET` - Bitcoin Testnet
|
|
339
351
|
- `NetworkId.SUI_MAINNET` - Sui Mainnet
|
|
352
|
+
- `NetworkId.SUI_TESTNET` - Sui Testnet
|
|
353
|
+
- `NetworkId.SUI_DEVNET` - Sui Devnet
|
|
354
|
+
|
|
355
|
+
### Usage Examples
|
|
356
|
+
|
|
357
|
+
```typescript
|
|
358
|
+
import { ServerSDK, NetworkId } from "@phantom/server-sdk";
|
|
359
|
+
|
|
360
|
+
const sdk = new ServerSDK({
|
|
361
|
+
organizationId: process.env.ORGANIZATION_ID!,
|
|
362
|
+
appId: process.env.APP_ID!,
|
|
363
|
+
apiPrivateKey: process.env.PRIVATE_KEY!,
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// Sign a message on Solana
|
|
367
|
+
await sdk.signMessage({
|
|
368
|
+
walletId: wallet.walletId,
|
|
369
|
+
message: "Hello from Phantom!",
|
|
370
|
+
networkId: NetworkId.SOLANA_MAINNET,
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
// Sign a transaction on Ethereum
|
|
374
|
+
await sdk.signAndSendTransaction({
|
|
375
|
+
walletId: wallet.walletId,
|
|
376
|
+
transaction: ethTransaction,
|
|
377
|
+
networkId: NetworkId.ETHEREUM_MAINNET,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
// Sign on Polygon
|
|
381
|
+
await sdk.signAndSendTransaction({
|
|
382
|
+
walletId: wallet.walletId,
|
|
383
|
+
transaction: polygonTransaction,
|
|
384
|
+
networkId: NetworkId.POLYGON_MAINNET,
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// Sign on Base
|
|
388
|
+
await sdk.signAndSendTransaction({
|
|
389
|
+
walletId: wallet.walletId,
|
|
390
|
+
transaction: baseTransaction,
|
|
391
|
+
networkId: NetworkId.BASE_MAINNET,
|
|
392
|
+
});
|
|
393
|
+
```
|
|
340
394
|
|
|
341
395
|
## API Reference
|
|
342
396
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddressType, NetworkId, PhantomClient, Organization, GetWalletsResult, CreateWalletResult } from '@phantom/client';
|
|
2
2
|
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, PhantomClient, SignedTransaction, SignedTransactionResult, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
|
|
3
3
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
4
|
-
export {
|
|
4
|
+
export { ParsedSignatureResult, ParsedTransaction, ParsedTransactionResult, parseSignMessageResponse, parseToKmsTransaction, parseTransactionResponse } from '@phantom/parsers';
|
|
5
5
|
export { NetworkId } from '@phantom/constants';
|
|
6
6
|
export { ApiKeyStamper } from '@phantom/api-key-stamper';
|
|
7
7
|
|
|
@@ -13,7 +13,7 @@ interface WalletAddress {
|
|
|
13
13
|
interface ServerSDKConfig {
|
|
14
14
|
organizationId: string;
|
|
15
15
|
appId: string;
|
|
16
|
-
apiBaseUrl
|
|
16
|
+
apiBaseUrl?: string;
|
|
17
17
|
apiPrivateKey: string;
|
|
18
18
|
}
|
|
19
19
|
interface ServerSignMessageParams {
|
|
@@ -27,12 +27,14 @@ interface ServerSignTransactionParams {
|
|
|
27
27
|
transaction: any;
|
|
28
28
|
networkId: NetworkId;
|
|
29
29
|
derivationIndex?: number;
|
|
30
|
+
account?: string;
|
|
30
31
|
}
|
|
31
32
|
interface ServerSignAndSendTransactionParams {
|
|
32
33
|
walletId: string;
|
|
33
34
|
transaction: any;
|
|
34
35
|
networkId: NetworkId;
|
|
35
36
|
derivationIndex?: number;
|
|
37
|
+
account?: string;
|
|
36
38
|
}
|
|
37
39
|
declare class ServerSDK {
|
|
38
40
|
private config;
|
|
@@ -40,6 +42,7 @@ declare class ServerSDK {
|
|
|
40
42
|
constructor(config: ServerSDKConfig);
|
|
41
43
|
/**
|
|
42
44
|
* Sign a message - supports plain text and automatically converts to base64url
|
|
45
|
+
* Routes to appropriate signing method based on network type
|
|
43
46
|
* @param params - Message parameters with plain text message
|
|
44
47
|
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
45
48
|
*/
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
ApiKeyStamper: () => import_api_key_stamper2.ApiKeyStamper,
|
|
34
34
|
DerivationPath: () => import_client2.DerivationPath,
|
|
35
|
-
NetworkId: () =>
|
|
35
|
+
NetworkId: () => import_constants2.NetworkId,
|
|
36
36
|
PhantomClient: () => import_client2.PhantomClient,
|
|
37
37
|
ServerSDK: () => ServerSDK,
|
|
38
38
|
deriveSubmissionConfig: () => import_client2.deriveSubmissionConfig,
|
|
@@ -42,50 +42,130 @@ __export(src_exports, {
|
|
|
42
42
|
getNetworkDescription: () => import_client2.getNetworkDescription,
|
|
43
43
|
getNetworkIdsByChain: () => import_client2.getNetworkIdsByChain,
|
|
44
44
|
getSupportedNetworkIds: () => import_client2.getSupportedNetworkIds,
|
|
45
|
-
parseMessage: () => import_parsers2.parseMessage,
|
|
46
45
|
parseSignMessageResponse: () => import_parsers2.parseSignMessageResponse,
|
|
46
|
+
parseToKmsTransaction: () => import_parsers2.parseToKmsTransaction,
|
|
47
47
|
parseTransactionResponse: () => import_parsers2.parseTransactionResponse,
|
|
48
|
-
parseTransactionToBase64Url: () => import_parsers2.parseTransactionToBase64Url,
|
|
49
48
|
supportsTransactionSubmission: () => import_client2.supportsTransactionSubmission
|
|
50
49
|
});
|
|
51
50
|
module.exports = __toCommonJS(src_exports);
|
|
52
51
|
var import_client = require("@phantom/client");
|
|
52
|
+
var import_utils = require("@phantom/utils");
|
|
53
|
+
var import_constants = require("@phantom/constants");
|
|
53
54
|
var import_api_key_stamper = require("@phantom/api-key-stamper");
|
|
54
55
|
var import_base64url = require("@phantom/base64url");
|
|
55
56
|
var import_bs58 = __toESM(require("bs58"));
|
|
57
|
+
|
|
58
|
+
// package.json
|
|
59
|
+
var package_default = {
|
|
60
|
+
name: "@phantom/server-sdk",
|
|
61
|
+
version: "1.0.0-beta.21",
|
|
62
|
+
description: "Server SDK for Phantom Wallet",
|
|
63
|
+
main: "dist/index.js",
|
|
64
|
+
module: "dist/index.mjs",
|
|
65
|
+
types: "dist/index.d.ts",
|
|
66
|
+
exports: {
|
|
67
|
+
".": {
|
|
68
|
+
import: "./dist/index.mjs",
|
|
69
|
+
require: "./dist/index.js",
|
|
70
|
+
types: "./dist/index.d.ts"
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
scripts: {
|
|
74
|
+
"?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
|
|
75
|
+
"pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
|
|
76
|
+
build: "rimraf ./dist && tsup",
|
|
77
|
+
dev: "tsc --watch",
|
|
78
|
+
clean: "rm -rf dist",
|
|
79
|
+
test: "jest",
|
|
80
|
+
"test:watch": "jest --watch",
|
|
81
|
+
lint: "eslint src --ext .ts,.tsx",
|
|
82
|
+
"check-types": "yarn tsc --noEmit",
|
|
83
|
+
prettier: 'prettier --write "src/**/*.{ts,tsx}"'
|
|
84
|
+
},
|
|
85
|
+
devDependencies: {
|
|
86
|
+
"@types/jest": "^29.5.12",
|
|
87
|
+
"@types/node": "^20.11.0",
|
|
88
|
+
dotenv: "^16.4.1",
|
|
89
|
+
eslint: "8.53.0",
|
|
90
|
+
jest: "^29.7.0",
|
|
91
|
+
prettier: "^3.5.2",
|
|
92
|
+
rimraf: "^6.0.1",
|
|
93
|
+
"ts-jest": "^29.1.2",
|
|
94
|
+
tsup: "^6.7.0",
|
|
95
|
+
typescript: "^5.0.4"
|
|
96
|
+
},
|
|
97
|
+
dependencies: {
|
|
98
|
+
"@phantom/api-key-stamper": "workspace:^",
|
|
99
|
+
"@phantom/base64url": "workspace:^",
|
|
100
|
+
"@phantom/client": "workspace:^",
|
|
101
|
+
"@phantom/constants": "workspace:^",
|
|
102
|
+
"@phantom/parsers": "workspace:^",
|
|
103
|
+
"@phantom/utils": "workspace:^",
|
|
104
|
+
bs58: "^6.0.0"
|
|
105
|
+
},
|
|
106
|
+
files: [
|
|
107
|
+
"dist"
|
|
108
|
+
],
|
|
109
|
+
publishConfig: {
|
|
110
|
+
directory: "_release/package"
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
// src/index.ts
|
|
56
115
|
var import_parsers = require("@phantom/parsers");
|
|
57
116
|
var import_client2 = require("@phantom/client");
|
|
58
|
-
var
|
|
117
|
+
var import_constants2 = require("@phantom/constants");
|
|
59
118
|
var import_api_key_stamper2 = require("@phantom/api-key-stamper");
|
|
60
119
|
var import_parsers2 = require("@phantom/parsers");
|
|
120
|
+
function getNodeVersion() {
|
|
121
|
+
if (typeof process !== "undefined" && process.version) {
|
|
122
|
+
return process.version;
|
|
123
|
+
}
|
|
124
|
+
return "unknown";
|
|
125
|
+
}
|
|
126
|
+
function getSdkVersion() {
|
|
127
|
+
return package_default.version || "unknown";
|
|
128
|
+
}
|
|
129
|
+
function createServerSdkHeaders(appId) {
|
|
130
|
+
return {
|
|
131
|
+
[import_constants.ANALYTICS_HEADERS.SDK_TYPE]: "server",
|
|
132
|
+
[import_constants.ANALYTICS_HEADERS.SDK_VERSION]: getSdkVersion(),
|
|
133
|
+
[import_constants.ANALYTICS_HEADERS.PLATFORM]: `node`,
|
|
134
|
+
[import_constants.ANALYTICS_HEADERS.PLATFORM_VERSION]: `${getNodeVersion()}`,
|
|
135
|
+
[import_constants.ANALYTICS_HEADERS.APP_ID]: appId
|
|
136
|
+
};
|
|
137
|
+
}
|
|
61
138
|
var ServerSDK = class {
|
|
62
139
|
constructor(config) {
|
|
63
140
|
this.config = config;
|
|
64
141
|
const stamper = new import_api_key_stamper.ApiKeyStamper({
|
|
65
142
|
apiSecretKey: config.apiPrivateKey
|
|
66
143
|
});
|
|
144
|
+
const headers = createServerSdkHeaders(config.appId);
|
|
67
145
|
this.client = new import_client.PhantomClient(
|
|
68
146
|
{
|
|
69
|
-
apiBaseUrl: config.apiBaseUrl,
|
|
70
|
-
organizationId: config.organizationId
|
|
147
|
+
apiBaseUrl: config.apiBaseUrl || import_constants.DEFAULT_WALLET_API_URL,
|
|
148
|
+
organizationId: config.organizationId,
|
|
149
|
+
headers
|
|
71
150
|
},
|
|
72
151
|
stamper
|
|
73
152
|
);
|
|
74
153
|
}
|
|
75
154
|
/**
|
|
76
155
|
* Sign a message - supports plain text and automatically converts to base64url
|
|
156
|
+
* Routes to appropriate signing method based on network type
|
|
77
157
|
* @param params - Message parameters with plain text message
|
|
78
158
|
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
79
159
|
*/
|
|
80
160
|
async signMessage(params) {
|
|
81
|
-
const
|
|
161
|
+
const base64UrlMessage = (0, import_base64url.stringToBase64url)(params.message);
|
|
82
162
|
const signMessageParams = {
|
|
83
163
|
walletId: params.walletId,
|
|
84
|
-
message:
|
|
164
|
+
message: base64UrlMessage,
|
|
85
165
|
networkId: params.networkId,
|
|
86
166
|
derivationIndex: params.derivationIndex
|
|
87
167
|
};
|
|
88
|
-
const rawResponse = await this.client.
|
|
168
|
+
const rawResponse = (0, import_utils.isEthereumChain)(params.networkId) ? await this.client.ethereumSignMessage(signMessageParams) : await this.client.signRawPayload(signMessageParams);
|
|
89
169
|
return (0, import_parsers.parseSignMessageResponse)(rawResponse, params.networkId);
|
|
90
170
|
}
|
|
91
171
|
/**
|
|
@@ -94,14 +174,18 @@ var ServerSDK = class {
|
|
|
94
174
|
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
95
175
|
*/
|
|
96
176
|
async signTransaction(params) {
|
|
97
|
-
const parsedTransaction = await (0, import_parsers.
|
|
98
|
-
const
|
|
177
|
+
const parsedTransaction = await (0, import_parsers.parseToKmsTransaction)(params.transaction, params.networkId);
|
|
178
|
+
const transactionPayload = parsedTransaction.parsed;
|
|
179
|
+
if (!transactionPayload) {
|
|
180
|
+
throw new Error("Failed to parse transaction: no valid encoding found");
|
|
181
|
+
}
|
|
182
|
+
const rawResponse = await this.client.signTransaction({
|
|
99
183
|
walletId: params.walletId,
|
|
100
|
-
transaction:
|
|
184
|
+
transaction: transactionPayload,
|
|
101
185
|
networkId: params.networkId,
|
|
102
|
-
derivationIndex: params.derivationIndex
|
|
103
|
-
|
|
104
|
-
|
|
186
|
+
derivationIndex: params.derivationIndex,
|
|
187
|
+
account: params.account
|
|
188
|
+
});
|
|
105
189
|
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId);
|
|
106
190
|
}
|
|
107
191
|
/**
|
|
@@ -110,21 +194,27 @@ var ServerSDK = class {
|
|
|
110
194
|
* @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
|
|
111
195
|
*/
|
|
112
196
|
async signAndSendTransaction(params) {
|
|
113
|
-
const parsedTransaction = await (0, import_parsers.
|
|
114
|
-
const
|
|
197
|
+
const parsedTransaction = await (0, import_parsers.parseToKmsTransaction)(params.transaction, params.networkId);
|
|
198
|
+
const transactionPayload = parsedTransaction.parsed;
|
|
199
|
+
if (!transactionPayload) {
|
|
200
|
+
throw new Error("Failed to parse transaction: no valid encoding found");
|
|
201
|
+
}
|
|
202
|
+
const rawResponse = await this.client.signAndSendTransaction({
|
|
115
203
|
walletId: params.walletId,
|
|
116
|
-
transaction:
|
|
204
|
+
transaction: transactionPayload,
|
|
117
205
|
networkId: params.networkId,
|
|
118
|
-
derivationIndex: params.derivationIndex
|
|
119
|
-
|
|
120
|
-
|
|
206
|
+
derivationIndex: params.derivationIndex,
|
|
207
|
+
account: params.account
|
|
208
|
+
});
|
|
121
209
|
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
122
210
|
}
|
|
123
211
|
createOrganization(name, keyPair) {
|
|
212
|
+
const headers = createServerSdkHeaders(this.config.appId);
|
|
124
213
|
const tempClient = new import_client.PhantomClient(
|
|
125
214
|
{
|
|
126
|
-
apiBaseUrl: this.config.apiBaseUrl,
|
|
127
|
-
organizationId: this.config.organizationId
|
|
215
|
+
apiBaseUrl: this.config.apiBaseUrl || import_constants.DEFAULT_WALLET_API_URL,
|
|
216
|
+
organizationId: this.config.organizationId,
|
|
217
|
+
headers
|
|
128
218
|
},
|
|
129
219
|
new import_api_key_stamper.ApiKeyStamper({
|
|
130
220
|
apiSecretKey: keyPair.secretKey
|
|
@@ -133,11 +223,11 @@ var ServerSDK = class {
|
|
|
133
223
|
const base64urlPublicKey = (0, import_base64url.base64urlEncode)(import_bs58.default.decode(keyPair.publicKey));
|
|
134
224
|
return tempClient.createOrganization(name, [
|
|
135
225
|
{
|
|
136
|
-
username: `user-${
|
|
226
|
+
username: `user-${(0, import_utils.randomUUID)()}`,
|
|
137
227
|
role: "ADMIN",
|
|
138
228
|
authenticators: [
|
|
139
229
|
{
|
|
140
|
-
authenticatorName: `auth-${
|
|
230
|
+
authenticatorName: `auth-${(0, import_utils.getSecureTimestampSync)()}`,
|
|
141
231
|
authenticatorKind: "keypair",
|
|
142
232
|
publicKey: base64urlPublicKey,
|
|
143
233
|
algorithm: "Ed25519"
|
|
@@ -170,9 +260,8 @@ var ServerSDK = class {
|
|
|
170
260
|
getNetworkDescription,
|
|
171
261
|
getNetworkIdsByChain,
|
|
172
262
|
getSupportedNetworkIds,
|
|
173
|
-
parseMessage,
|
|
174
263
|
parseSignMessageResponse,
|
|
264
|
+
parseToKmsTransaction,
|
|
175
265
|
parseTransactionResponse,
|
|
176
|
-
parseTransactionToBase64Url,
|
|
177
266
|
supportsTransactionSubmission
|
|
178
267
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -2,12 +2,74 @@
|
|
|
2
2
|
import {
|
|
3
3
|
PhantomClient
|
|
4
4
|
} from "@phantom/client";
|
|
5
|
+
import { randomUUID, getSecureTimestampSync, isEthereumChain } from "@phantom/utils";
|
|
6
|
+
import {
|
|
7
|
+
ANALYTICS_HEADERS,
|
|
8
|
+
DEFAULT_WALLET_API_URL
|
|
9
|
+
} from "@phantom/constants";
|
|
5
10
|
import { ApiKeyStamper } from "@phantom/api-key-stamper";
|
|
6
|
-
import { base64urlEncode } from "@phantom/base64url";
|
|
11
|
+
import { base64urlEncode, stringToBase64url } from "@phantom/base64url";
|
|
7
12
|
import bs58 from "bs58";
|
|
13
|
+
|
|
14
|
+
// package.json
|
|
15
|
+
var package_default = {
|
|
16
|
+
name: "@phantom/server-sdk",
|
|
17
|
+
version: "1.0.0-beta.21",
|
|
18
|
+
description: "Server SDK for Phantom Wallet",
|
|
19
|
+
main: "dist/index.js",
|
|
20
|
+
module: "dist/index.mjs",
|
|
21
|
+
types: "dist/index.d.ts",
|
|
22
|
+
exports: {
|
|
23
|
+
".": {
|
|
24
|
+
import: "./dist/index.mjs",
|
|
25
|
+
require: "./dist/index.js",
|
|
26
|
+
types: "./dist/index.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
scripts: {
|
|
30
|
+
"?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
|
|
31
|
+
"pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
|
|
32
|
+
build: "rimraf ./dist && tsup",
|
|
33
|
+
dev: "tsc --watch",
|
|
34
|
+
clean: "rm -rf dist",
|
|
35
|
+
test: "jest",
|
|
36
|
+
"test:watch": "jest --watch",
|
|
37
|
+
lint: "eslint src --ext .ts,.tsx",
|
|
38
|
+
"check-types": "yarn tsc --noEmit",
|
|
39
|
+
prettier: 'prettier --write "src/**/*.{ts,tsx}"'
|
|
40
|
+
},
|
|
41
|
+
devDependencies: {
|
|
42
|
+
"@types/jest": "^29.5.12",
|
|
43
|
+
"@types/node": "^20.11.0",
|
|
44
|
+
dotenv: "^16.4.1",
|
|
45
|
+
eslint: "8.53.0",
|
|
46
|
+
jest: "^29.7.0",
|
|
47
|
+
prettier: "^3.5.2",
|
|
48
|
+
rimraf: "^6.0.1",
|
|
49
|
+
"ts-jest": "^29.1.2",
|
|
50
|
+
tsup: "^6.7.0",
|
|
51
|
+
typescript: "^5.0.4"
|
|
52
|
+
},
|
|
53
|
+
dependencies: {
|
|
54
|
+
"@phantom/api-key-stamper": "workspace:^",
|
|
55
|
+
"@phantom/base64url": "workspace:^",
|
|
56
|
+
"@phantom/client": "workspace:^",
|
|
57
|
+
"@phantom/constants": "workspace:^",
|
|
58
|
+
"@phantom/parsers": "workspace:^",
|
|
59
|
+
"@phantom/utils": "workspace:^",
|
|
60
|
+
bs58: "^6.0.0"
|
|
61
|
+
},
|
|
62
|
+
files: [
|
|
63
|
+
"dist"
|
|
64
|
+
],
|
|
65
|
+
publishConfig: {
|
|
66
|
+
directory: "_release/package"
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// src/index.ts
|
|
8
71
|
import {
|
|
9
|
-
|
|
10
|
-
parseTransactionToBase64Url,
|
|
72
|
+
parseToKmsTransaction,
|
|
11
73
|
parseSignMessageResponse,
|
|
12
74
|
parseTransactionResponse
|
|
13
75
|
} from "@phantom/parsers";
|
|
@@ -26,39 +88,59 @@ import {
|
|
|
26
88
|
import { NetworkId } from "@phantom/constants";
|
|
27
89
|
import { ApiKeyStamper as ApiKeyStamper2 } from "@phantom/api-key-stamper";
|
|
28
90
|
import {
|
|
29
|
-
|
|
30
|
-
parseTransactionToBase64Url as parseTransactionToBase64Url2,
|
|
91
|
+
parseToKmsTransaction as parseToKmsTransaction2,
|
|
31
92
|
parseSignMessageResponse as parseSignMessageResponse2,
|
|
32
93
|
parseTransactionResponse as parseTransactionResponse2
|
|
33
94
|
} from "@phantom/parsers";
|
|
95
|
+
function getNodeVersion() {
|
|
96
|
+
if (typeof process !== "undefined" && process.version) {
|
|
97
|
+
return process.version;
|
|
98
|
+
}
|
|
99
|
+
return "unknown";
|
|
100
|
+
}
|
|
101
|
+
function getSdkVersion() {
|
|
102
|
+
return package_default.version || "unknown";
|
|
103
|
+
}
|
|
104
|
+
function createServerSdkHeaders(appId) {
|
|
105
|
+
return {
|
|
106
|
+
[ANALYTICS_HEADERS.SDK_TYPE]: "server",
|
|
107
|
+
[ANALYTICS_HEADERS.SDK_VERSION]: getSdkVersion(),
|
|
108
|
+
[ANALYTICS_HEADERS.PLATFORM]: `node`,
|
|
109
|
+
[ANALYTICS_HEADERS.PLATFORM_VERSION]: `${getNodeVersion()}`,
|
|
110
|
+
[ANALYTICS_HEADERS.APP_ID]: appId
|
|
111
|
+
};
|
|
112
|
+
}
|
|
34
113
|
var ServerSDK = class {
|
|
35
114
|
constructor(config) {
|
|
36
115
|
this.config = config;
|
|
37
116
|
const stamper = new ApiKeyStamper({
|
|
38
117
|
apiSecretKey: config.apiPrivateKey
|
|
39
118
|
});
|
|
119
|
+
const headers = createServerSdkHeaders(config.appId);
|
|
40
120
|
this.client = new PhantomClient(
|
|
41
121
|
{
|
|
42
|
-
apiBaseUrl: config.apiBaseUrl,
|
|
43
|
-
organizationId: config.organizationId
|
|
122
|
+
apiBaseUrl: config.apiBaseUrl || DEFAULT_WALLET_API_URL,
|
|
123
|
+
organizationId: config.organizationId,
|
|
124
|
+
headers
|
|
44
125
|
},
|
|
45
126
|
stamper
|
|
46
127
|
);
|
|
47
128
|
}
|
|
48
129
|
/**
|
|
49
130
|
* Sign a message - supports plain text and automatically converts to base64url
|
|
131
|
+
* Routes to appropriate signing method based on network type
|
|
50
132
|
* @param params - Message parameters with plain text message
|
|
51
133
|
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
52
134
|
*/
|
|
53
135
|
async signMessage(params) {
|
|
54
|
-
const
|
|
136
|
+
const base64UrlMessage = stringToBase64url(params.message);
|
|
55
137
|
const signMessageParams = {
|
|
56
138
|
walletId: params.walletId,
|
|
57
|
-
message:
|
|
139
|
+
message: base64UrlMessage,
|
|
58
140
|
networkId: params.networkId,
|
|
59
141
|
derivationIndex: params.derivationIndex
|
|
60
142
|
};
|
|
61
|
-
const rawResponse = await this.client.
|
|
143
|
+
const rawResponse = isEthereumChain(params.networkId) ? await this.client.ethereumSignMessage(signMessageParams) : await this.client.signRawPayload(signMessageParams);
|
|
62
144
|
return parseSignMessageResponse(rawResponse, params.networkId);
|
|
63
145
|
}
|
|
64
146
|
/**
|
|
@@ -67,14 +149,18 @@ var ServerSDK = class {
|
|
|
67
149
|
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
68
150
|
*/
|
|
69
151
|
async signTransaction(params) {
|
|
70
|
-
const parsedTransaction = await
|
|
71
|
-
const
|
|
152
|
+
const parsedTransaction = await parseToKmsTransaction(params.transaction, params.networkId);
|
|
153
|
+
const transactionPayload = parsedTransaction.parsed;
|
|
154
|
+
if (!transactionPayload) {
|
|
155
|
+
throw new Error("Failed to parse transaction: no valid encoding found");
|
|
156
|
+
}
|
|
157
|
+
const rawResponse = await this.client.signTransaction({
|
|
72
158
|
walletId: params.walletId,
|
|
73
|
-
transaction:
|
|
159
|
+
transaction: transactionPayload,
|
|
74
160
|
networkId: params.networkId,
|
|
75
|
-
derivationIndex: params.derivationIndex
|
|
76
|
-
|
|
77
|
-
|
|
161
|
+
derivationIndex: params.derivationIndex,
|
|
162
|
+
account: params.account
|
|
163
|
+
});
|
|
78
164
|
return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId);
|
|
79
165
|
}
|
|
80
166
|
/**
|
|
@@ -83,21 +169,27 @@ var ServerSDK = class {
|
|
|
83
169
|
* @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
|
|
84
170
|
*/
|
|
85
171
|
async signAndSendTransaction(params) {
|
|
86
|
-
const parsedTransaction = await
|
|
87
|
-
const
|
|
172
|
+
const parsedTransaction = await parseToKmsTransaction(params.transaction, params.networkId);
|
|
173
|
+
const transactionPayload = parsedTransaction.parsed;
|
|
174
|
+
if (!transactionPayload) {
|
|
175
|
+
throw new Error("Failed to parse transaction: no valid encoding found");
|
|
176
|
+
}
|
|
177
|
+
const rawResponse = await this.client.signAndSendTransaction({
|
|
88
178
|
walletId: params.walletId,
|
|
89
|
-
transaction:
|
|
179
|
+
transaction: transactionPayload,
|
|
90
180
|
networkId: params.networkId,
|
|
91
|
-
derivationIndex: params.derivationIndex
|
|
92
|
-
|
|
93
|
-
|
|
181
|
+
derivationIndex: params.derivationIndex,
|
|
182
|
+
account: params.account
|
|
183
|
+
});
|
|
94
184
|
return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
95
185
|
}
|
|
96
186
|
createOrganization(name, keyPair) {
|
|
187
|
+
const headers = createServerSdkHeaders(this.config.appId);
|
|
97
188
|
const tempClient = new PhantomClient(
|
|
98
189
|
{
|
|
99
|
-
apiBaseUrl: this.config.apiBaseUrl,
|
|
100
|
-
organizationId: this.config.organizationId
|
|
190
|
+
apiBaseUrl: this.config.apiBaseUrl || DEFAULT_WALLET_API_URL,
|
|
191
|
+
organizationId: this.config.organizationId,
|
|
192
|
+
headers
|
|
101
193
|
},
|
|
102
194
|
new ApiKeyStamper({
|
|
103
195
|
apiSecretKey: keyPair.secretKey
|
|
@@ -106,11 +198,11 @@ var ServerSDK = class {
|
|
|
106
198
|
const base64urlPublicKey = base64urlEncode(bs58.decode(keyPair.publicKey));
|
|
107
199
|
return tempClient.createOrganization(name, [
|
|
108
200
|
{
|
|
109
|
-
username: `user-${
|
|
201
|
+
username: `user-${randomUUID()}`,
|
|
110
202
|
role: "ADMIN",
|
|
111
203
|
authenticators: [
|
|
112
204
|
{
|
|
113
|
-
authenticatorName: `auth-${
|
|
205
|
+
authenticatorName: `auth-${getSecureTimestampSync()}`,
|
|
114
206
|
authenticatorKind: "keypair",
|
|
115
207
|
publicKey: base64urlPublicKey,
|
|
116
208
|
algorithm: "Ed25519"
|
|
@@ -142,9 +234,8 @@ export {
|
|
|
142
234
|
getNetworkDescription,
|
|
143
235
|
getNetworkIdsByChain,
|
|
144
236
|
getSupportedNetworkIds,
|
|
145
|
-
parseMessage2 as parseMessage,
|
|
146
237
|
parseSignMessageResponse2 as parseSignMessageResponse,
|
|
238
|
+
parseToKmsTransaction2 as parseToKmsTransaction,
|
|
147
239
|
parseTransactionResponse2 as parseTransactionResponse,
|
|
148
|
-
parseTransactionToBase64Url2 as parseTransactionToBase64Url,
|
|
149
240
|
supportsTransactionSubmission
|
|
150
241
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/server-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.21",
|
|
4
4
|
"description": "Server SDK for Phantom Wallet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
|
|
17
17
|
"pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
|
|
18
|
-
"build": "rimraf ./dist && tsup
|
|
18
|
+
"build": "rimraf ./dist && tsup",
|
|
19
19
|
"dev": "tsc --watch",
|
|
20
20
|
"clean": "rm -rf dist",
|
|
21
21
|
"test": "jest",
|
|
@@ -37,11 +37,12 @@
|
|
|
37
37
|
"typescript": "^5.0.4"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@phantom/api-key-stamper": "^1.0.0-beta.
|
|
41
|
-
"@phantom/base64url": "^1.0.0-beta.
|
|
42
|
-
"@phantom/client": "^1.0.0-beta.
|
|
43
|
-
"@phantom/constants": "^1.0.0-beta.
|
|
44
|
-
"@phantom/parsers": "^1.0.0-beta.
|
|
40
|
+
"@phantom/api-key-stamper": "^1.0.0-beta.9",
|
|
41
|
+
"@phantom/base64url": "^1.0.0-beta.9",
|
|
42
|
+
"@phantom/client": "^1.0.0-beta.21",
|
|
43
|
+
"@phantom/constants": "^1.0.0-beta.9",
|
|
44
|
+
"@phantom/parsers": "^1.0.0-beta.9",
|
|
45
|
+
"@phantom/utils": "^1.0.0-beta.21",
|
|
45
46
|
"bs58": "^6.0.0"
|
|
46
47
|
},
|
|
47
48
|
"files": [
|