@phantom/server-sdk 1.0.0-beta.0 → 1.0.0-beta.10
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 +70 -2
- package/dist/index.d.ts +18 -3
- package/dist/index.js +109 -9
- package/dist/index.mjs +110 -7
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -69,6 +69,7 @@ Create a `.env` file in your project root:
|
|
|
69
69
|
|
|
70
70
|
```env
|
|
71
71
|
ORGANIZATION_ID=your-organization-id
|
|
72
|
+
APP_ID=your-app-id
|
|
72
73
|
PRIVATE_KEY=your-base58-encoded-private-key
|
|
73
74
|
API_URL=https://api.phantom.app/v1/wallets
|
|
74
75
|
```
|
|
@@ -85,8 +86,8 @@ dotenv.config();
|
|
|
85
86
|
// Initialize the SDK
|
|
86
87
|
const sdk = new ServerSDK({
|
|
87
88
|
organizationId: process.env.ORGANIZATION_ID!,
|
|
89
|
+
appId: process.env.APP_ID!,
|
|
88
90
|
apiPrivateKey: process.env.PRIVATE_KEY!,
|
|
89
|
-
apiBaseUrl: process.env.API_URL!,
|
|
90
91
|
});
|
|
91
92
|
|
|
92
93
|
// Create a wallet
|
|
@@ -120,6 +121,72 @@ console.log("Solana address:", solanaAddress);
|
|
|
120
121
|
console.log("Ethereum address:", ethereumAddress);
|
|
121
122
|
```
|
|
122
123
|
|
|
124
|
+
### Transaction Signing Methods
|
|
125
|
+
|
|
126
|
+
The Server SDK provides two methods for handling transactions:
|
|
127
|
+
|
|
128
|
+
1. **`signTransaction(params)`** - Signs a transaction without submitting it to the network
|
|
129
|
+
- Returns the signed transaction
|
|
130
|
+
- No network interaction
|
|
131
|
+
- Useful for offline signing or when you want to broadcast later
|
|
132
|
+
|
|
133
|
+
2. **`signAndSendTransaction(params)`** - Signs and submits the transaction to the network
|
|
134
|
+
- Returns both signed transaction and transaction hash
|
|
135
|
+
- Requires network connectivity
|
|
136
|
+
- Transaction is immediately broadcast to the blockchain
|
|
137
|
+
|
|
138
|
+
### Signing Only (No Network Submission)
|
|
139
|
+
|
|
140
|
+
#### Solana Transaction Signing
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import { Transaction, SystemProgram, PublicKey } from "@solana/web3.js";
|
|
144
|
+
|
|
145
|
+
// Create a Solana transaction
|
|
146
|
+
const transaction = new Transaction().add(
|
|
147
|
+
SystemProgram.transfer({
|
|
148
|
+
fromPubkey: new PublicKey(solanaAddress),
|
|
149
|
+
toPubkey: new PublicKey(recipientAddress),
|
|
150
|
+
lamports: 1000000, // 0.001 SOL
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// Set transaction parameters
|
|
155
|
+
transaction.recentBlockhash = blockhash;
|
|
156
|
+
transaction.feePayer = new PublicKey(solanaAddress);
|
|
157
|
+
|
|
158
|
+
// Sign the transaction (without sending)
|
|
159
|
+
const signed = await sdk.signTransaction({
|
|
160
|
+
walletId: wallet.walletId,
|
|
161
|
+
transaction,
|
|
162
|
+
networkId: NetworkId.SOLANA_MAINNET,
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
console.log("Signed transaction:", signed.rawTransaction);
|
|
166
|
+
// You can broadcast this transaction later using your own RPC client
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### Ethereum Transaction Signing
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Viem transaction object
|
|
173
|
+
const evmTransaction = {
|
|
174
|
+
to: "0x742d35Cc6634C0532925a3b8D4C8db86fB5C4A7E",
|
|
175
|
+
value: 1000000000000000000n, // 1 ETH in wei
|
|
176
|
+
data: "0x",
|
|
177
|
+
gasLimit: 21000n,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const signed = await sdk.signTransaction({
|
|
181
|
+
walletId: wallet.walletId,
|
|
182
|
+
transaction: evmTransaction,
|
|
183
|
+
networkId: NetworkId.ETHEREUM_MAINNET,
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
console.log("Signed transaction:", signed.rawTransaction);
|
|
187
|
+
// You can broadcast this signed transaction using your preferred method
|
|
188
|
+
```
|
|
189
|
+
|
|
123
190
|
### Signing and Sending Transactions
|
|
124
191
|
|
|
125
192
|
#### Solana - Native Web3.js Transaction Objects
|
|
@@ -278,7 +345,8 @@ For complete API documentation, visit **[docs.phantom.com/server-sdk](https://do
|
|
|
278
345
|
### Key Methods
|
|
279
346
|
|
|
280
347
|
- `createWallet(walletName?)` - Creates a new wallet
|
|
281
|
-
- `
|
|
348
|
+
- `signTransaction(params)` - Signs transactions without submitting to network
|
|
349
|
+
- `signAndSendTransaction(params)` - Signs and submits transactions to network
|
|
282
350
|
- `signMessage(params)` - Signs arbitrary messages
|
|
283
351
|
- `getWalletAddresses(walletId, derivationPaths?)` - Retrieves wallet addresses
|
|
284
352
|
- `getWallets(limit?, offset?)` - Lists all wallets with pagination
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AddressType, NetworkId, PhantomClient, Organization, GetWalletsResult, CreateWalletResult } from '@phantom/client';
|
|
2
|
-
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, PhantomClient, SignedTransaction, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
|
|
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
4
|
export { ParsedMessage, ParsedSignatureResult, ParsedTransaction, ParsedTransactionResult, parseMessage, parseSignMessageResponse, parseTransactionResponse, parseTransactionToBase64Url } from '@phantom/parsers';
|
|
5
5
|
export { NetworkId } from '@phantom/constants';
|
|
@@ -12,7 +12,8 @@ interface WalletAddress {
|
|
|
12
12
|
|
|
13
13
|
interface ServerSDKConfig {
|
|
14
14
|
organizationId: string;
|
|
15
|
-
|
|
15
|
+
appId: string;
|
|
16
|
+
apiBaseUrl?: string;
|
|
16
17
|
apiPrivateKey: string;
|
|
17
18
|
}
|
|
18
19
|
interface ServerSignMessageParams {
|
|
@@ -21,11 +22,19 @@ interface ServerSignMessageParams {
|
|
|
21
22
|
networkId: NetworkId;
|
|
22
23
|
derivationIndex?: number;
|
|
23
24
|
}
|
|
25
|
+
interface ServerSignTransactionParams {
|
|
26
|
+
walletId: string;
|
|
27
|
+
transaction: any;
|
|
28
|
+
networkId: NetworkId;
|
|
29
|
+
derivationIndex?: number;
|
|
30
|
+
account?: string;
|
|
31
|
+
}
|
|
24
32
|
interface ServerSignAndSendTransactionParams {
|
|
25
33
|
walletId: string;
|
|
26
34
|
transaction: any;
|
|
27
35
|
networkId: NetworkId;
|
|
28
36
|
derivationIndex?: number;
|
|
37
|
+
account?: string;
|
|
29
38
|
}
|
|
30
39
|
declare class ServerSDK {
|
|
31
40
|
private config;
|
|
@@ -37,6 +46,12 @@ declare class ServerSDK {
|
|
|
37
46
|
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
38
47
|
*/
|
|
39
48
|
signMessage(params: ServerSignMessageParams): Promise<ParsedSignatureResult>;
|
|
49
|
+
/**
|
|
50
|
+
* Sign a transaction - supports various transaction formats and automatically parses them
|
|
51
|
+
* @param params - Transaction parameters with flexible transaction format
|
|
52
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
53
|
+
*/
|
|
54
|
+
signTransaction(params: ServerSignTransactionParams): Promise<ParsedTransactionResult>;
|
|
40
55
|
/**
|
|
41
56
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
42
57
|
* @param params - Transaction parameters with flexible transaction format
|
|
@@ -55,4 +70,4 @@ declare class ServerSDK {
|
|
|
55
70
|
}[]>;
|
|
56
71
|
}
|
|
57
72
|
|
|
58
|
-
export { ServerSDK, ServerSDKConfig, ServerSignAndSendTransactionParams, ServerSignMessageParams, WalletAddress };
|
|
73
|
+
export { ServerSDK, ServerSDKConfig, ServerSignAndSendTransactionParams, ServerSignMessageParams, ServerSignTransactionParams, WalletAddress };
|
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,
|
|
@@ -50,24 +50,104 @@ __export(src_exports, {
|
|
|
50
50
|
});
|
|
51
51
|
module.exports = __toCommonJS(src_exports);
|
|
52
52
|
var import_client = require("@phantom/client");
|
|
53
|
+
var import_utils = require("@phantom/utils");
|
|
54
|
+
var import_constants = require("@phantom/constants");
|
|
53
55
|
var import_api_key_stamper = require("@phantom/api-key-stamper");
|
|
54
56
|
var import_base64url = require("@phantom/base64url");
|
|
55
57
|
var import_bs58 = __toESM(require("bs58"));
|
|
58
|
+
|
|
59
|
+
// package.json
|
|
60
|
+
var package_default = {
|
|
61
|
+
name: "@phantom/server-sdk",
|
|
62
|
+
version: "1.0.0-beta.10",
|
|
63
|
+
description: "Server SDK for Phantom Wallet",
|
|
64
|
+
main: "dist/index.js",
|
|
65
|
+
module: "dist/index.mjs",
|
|
66
|
+
types: "dist/index.d.ts",
|
|
67
|
+
exports: {
|
|
68
|
+
".": {
|
|
69
|
+
import: "./dist/index.mjs",
|
|
70
|
+
require: "./dist/index.js",
|
|
71
|
+
types: "./dist/index.d.ts"
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
scripts: {
|
|
75
|
+
"?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
|
|
76
|
+
"pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
|
|
77
|
+
build: "rimraf ./dist && tsup",
|
|
78
|
+
dev: "tsc --watch",
|
|
79
|
+
clean: "rm -rf dist",
|
|
80
|
+
test: "jest",
|
|
81
|
+
"test:watch": "jest --watch",
|
|
82
|
+
lint: "eslint src --ext .ts,.tsx",
|
|
83
|
+
"check-types": "yarn tsc --noEmit",
|
|
84
|
+
prettier: 'prettier --write "src/**/*.{ts,tsx}"'
|
|
85
|
+
},
|
|
86
|
+
devDependencies: {
|
|
87
|
+
"@types/jest": "^29.5.12",
|
|
88
|
+
"@types/node": "^20.11.0",
|
|
89
|
+
dotenv: "^16.4.1",
|
|
90
|
+
eslint: "8.53.0",
|
|
91
|
+
jest: "^29.7.0",
|
|
92
|
+
prettier: "^3.5.2",
|
|
93
|
+
rimraf: "^6.0.1",
|
|
94
|
+
"ts-jest": "^29.1.2",
|
|
95
|
+
tsup: "^6.7.0",
|
|
96
|
+
typescript: "^5.0.4"
|
|
97
|
+
},
|
|
98
|
+
dependencies: {
|
|
99
|
+
"@phantom/api-key-stamper": "workspace:^",
|
|
100
|
+
"@phantom/base64url": "workspace:^",
|
|
101
|
+
"@phantom/client": "workspace:^",
|
|
102
|
+
"@phantom/constants": "workspace:^",
|
|
103
|
+
"@phantom/parsers": "workspace:^",
|
|
104
|
+
"@phantom/utils": "workspace:^",
|
|
105
|
+
bs58: "^6.0.0"
|
|
106
|
+
},
|
|
107
|
+
files: [
|
|
108
|
+
"dist"
|
|
109
|
+
],
|
|
110
|
+
publishConfig: {
|
|
111
|
+
directory: "_release/package"
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// src/index.ts
|
|
56
116
|
var import_parsers = require("@phantom/parsers");
|
|
57
117
|
var import_client2 = require("@phantom/client");
|
|
58
|
-
var
|
|
118
|
+
var import_constants2 = require("@phantom/constants");
|
|
59
119
|
var import_api_key_stamper2 = require("@phantom/api-key-stamper");
|
|
60
120
|
var import_parsers2 = require("@phantom/parsers");
|
|
121
|
+
function getNodeVersion() {
|
|
122
|
+
if (typeof process !== "undefined" && process.version) {
|
|
123
|
+
return process.version;
|
|
124
|
+
}
|
|
125
|
+
return "unknown";
|
|
126
|
+
}
|
|
127
|
+
function getSdkVersion() {
|
|
128
|
+
return package_default.version || "unknown";
|
|
129
|
+
}
|
|
130
|
+
function createServerSdkHeaders(appId) {
|
|
131
|
+
return {
|
|
132
|
+
[import_constants.ANALYTICS_HEADERS.SDK_TYPE]: "server",
|
|
133
|
+
[import_constants.ANALYTICS_HEADERS.SDK_VERSION]: getSdkVersion(),
|
|
134
|
+
[import_constants.ANALYTICS_HEADERS.PLATFORM]: `node`,
|
|
135
|
+
[import_constants.ANALYTICS_HEADERS.PLATFORM_VERSION]: `${getNodeVersion()}`,
|
|
136
|
+
[import_constants.ANALYTICS_HEADERS.APP_ID]: appId
|
|
137
|
+
};
|
|
138
|
+
}
|
|
61
139
|
var ServerSDK = class {
|
|
62
140
|
constructor(config) {
|
|
63
141
|
this.config = config;
|
|
64
142
|
const stamper = new import_api_key_stamper.ApiKeyStamper({
|
|
65
143
|
apiSecretKey: config.apiPrivateKey
|
|
66
144
|
});
|
|
145
|
+
const headers = createServerSdkHeaders(config.appId);
|
|
67
146
|
this.client = new import_client.PhantomClient(
|
|
68
147
|
{
|
|
69
|
-
apiBaseUrl: config.apiBaseUrl,
|
|
70
|
-
organizationId: config.organizationId
|
|
148
|
+
apiBaseUrl: config.apiBaseUrl || import_constants.DEFAULT_WALLET_API_URL,
|
|
149
|
+
organizationId: config.organizationId,
|
|
150
|
+
headers
|
|
71
151
|
},
|
|
72
152
|
stamper
|
|
73
153
|
);
|
|
@@ -88,6 +168,23 @@ var ServerSDK = class {
|
|
|
88
168
|
const rawResponse = await this.client.signMessage(signMessageParams);
|
|
89
169
|
return (0, import_parsers.parseSignMessageResponse)(rawResponse, params.networkId);
|
|
90
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Sign a transaction - supports various transaction formats and automatically parses them
|
|
173
|
+
* @param params - Transaction parameters with flexible transaction format
|
|
174
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
175
|
+
*/
|
|
176
|
+
async signTransaction(params) {
|
|
177
|
+
const parsedTransaction = await (0, import_parsers.parseTransactionToBase64Url)(params.transaction, params.networkId);
|
|
178
|
+
const signTransactionParams = {
|
|
179
|
+
walletId: params.walletId,
|
|
180
|
+
transaction: parsedTransaction.base64url,
|
|
181
|
+
networkId: params.networkId,
|
|
182
|
+
derivationIndex: params.derivationIndex,
|
|
183
|
+
account: params.account
|
|
184
|
+
};
|
|
185
|
+
const rawResponse = await this.client.signTransaction(signTransactionParams);
|
|
186
|
+
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId);
|
|
187
|
+
}
|
|
91
188
|
/**
|
|
92
189
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
93
190
|
* @param params - Transaction parameters with flexible transaction format
|
|
@@ -99,16 +196,19 @@ var ServerSDK = class {
|
|
|
99
196
|
walletId: params.walletId,
|
|
100
197
|
transaction: parsedTransaction.base64url,
|
|
101
198
|
networkId: params.networkId,
|
|
102
|
-
derivationIndex: params.derivationIndex
|
|
199
|
+
derivationIndex: params.derivationIndex,
|
|
200
|
+
account: params.account
|
|
103
201
|
};
|
|
104
202
|
const rawResponse = await this.client.signAndSendTransaction(signAndSendParams);
|
|
105
203
|
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
106
204
|
}
|
|
107
205
|
createOrganization(name, keyPair) {
|
|
206
|
+
const headers = createServerSdkHeaders(this.config.appId);
|
|
108
207
|
const tempClient = new import_client.PhantomClient(
|
|
109
208
|
{
|
|
110
|
-
apiBaseUrl: this.config.apiBaseUrl,
|
|
111
|
-
organizationId: this.config.organizationId
|
|
209
|
+
apiBaseUrl: this.config.apiBaseUrl || import_constants.DEFAULT_WALLET_API_URL,
|
|
210
|
+
organizationId: this.config.organizationId,
|
|
211
|
+
headers
|
|
112
212
|
},
|
|
113
213
|
new import_api_key_stamper.ApiKeyStamper({
|
|
114
214
|
apiSecretKey: keyPair.secretKey
|
|
@@ -117,11 +217,11 @@ var ServerSDK = class {
|
|
|
117
217
|
const base64urlPublicKey = (0, import_base64url.base64urlEncode)(import_bs58.default.decode(keyPair.publicKey));
|
|
118
218
|
return tempClient.createOrganization(name, [
|
|
119
219
|
{
|
|
120
|
-
username: `user-${
|
|
220
|
+
username: `user-${(0, import_utils.randomUUID)()}`,
|
|
121
221
|
role: "ADMIN",
|
|
122
222
|
authenticators: [
|
|
123
223
|
{
|
|
124
|
-
authenticatorName: `auth-${
|
|
224
|
+
authenticatorName: `auth-${(0, import_utils.getSecureTimestampSync)()}`,
|
|
125
225
|
authenticatorKind: "keypair",
|
|
126
226
|
publicKey: base64urlPublicKey,
|
|
127
227
|
algorithm: "Ed25519"
|
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,72 @@
|
|
|
2
2
|
import {
|
|
3
3
|
PhantomClient
|
|
4
4
|
} from "@phantom/client";
|
|
5
|
+
import { randomUUID, getSecureTimestampSync } 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
11
|
import { base64urlEncode } 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.10",
|
|
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
72
|
parseMessage,
|
|
10
73
|
parseTransactionToBase64Url,
|
|
@@ -31,16 +94,36 @@ import {
|
|
|
31
94
|
parseSignMessageResponse as parseSignMessageResponse2,
|
|
32
95
|
parseTransactionResponse as parseTransactionResponse2
|
|
33
96
|
} from "@phantom/parsers";
|
|
97
|
+
function getNodeVersion() {
|
|
98
|
+
if (typeof process !== "undefined" && process.version) {
|
|
99
|
+
return process.version;
|
|
100
|
+
}
|
|
101
|
+
return "unknown";
|
|
102
|
+
}
|
|
103
|
+
function getSdkVersion() {
|
|
104
|
+
return package_default.version || "unknown";
|
|
105
|
+
}
|
|
106
|
+
function createServerSdkHeaders(appId) {
|
|
107
|
+
return {
|
|
108
|
+
[ANALYTICS_HEADERS.SDK_TYPE]: "server",
|
|
109
|
+
[ANALYTICS_HEADERS.SDK_VERSION]: getSdkVersion(),
|
|
110
|
+
[ANALYTICS_HEADERS.PLATFORM]: `node`,
|
|
111
|
+
[ANALYTICS_HEADERS.PLATFORM_VERSION]: `${getNodeVersion()}`,
|
|
112
|
+
[ANALYTICS_HEADERS.APP_ID]: appId
|
|
113
|
+
};
|
|
114
|
+
}
|
|
34
115
|
var ServerSDK = class {
|
|
35
116
|
constructor(config) {
|
|
36
117
|
this.config = config;
|
|
37
118
|
const stamper = new ApiKeyStamper({
|
|
38
119
|
apiSecretKey: config.apiPrivateKey
|
|
39
120
|
});
|
|
121
|
+
const headers = createServerSdkHeaders(config.appId);
|
|
40
122
|
this.client = new PhantomClient(
|
|
41
123
|
{
|
|
42
|
-
apiBaseUrl: config.apiBaseUrl,
|
|
43
|
-
organizationId: config.organizationId
|
|
124
|
+
apiBaseUrl: config.apiBaseUrl || DEFAULT_WALLET_API_URL,
|
|
125
|
+
organizationId: config.organizationId,
|
|
126
|
+
headers
|
|
44
127
|
},
|
|
45
128
|
stamper
|
|
46
129
|
);
|
|
@@ -61,6 +144,23 @@ var ServerSDK = class {
|
|
|
61
144
|
const rawResponse = await this.client.signMessage(signMessageParams);
|
|
62
145
|
return parseSignMessageResponse(rawResponse, params.networkId);
|
|
63
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Sign a transaction - supports various transaction formats and automatically parses them
|
|
149
|
+
* @param params - Transaction parameters with flexible transaction format
|
|
150
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result without hash
|
|
151
|
+
*/
|
|
152
|
+
async signTransaction(params) {
|
|
153
|
+
const parsedTransaction = await parseTransactionToBase64Url(params.transaction, params.networkId);
|
|
154
|
+
const signTransactionParams = {
|
|
155
|
+
walletId: params.walletId,
|
|
156
|
+
transaction: parsedTransaction.base64url,
|
|
157
|
+
networkId: params.networkId,
|
|
158
|
+
derivationIndex: params.derivationIndex,
|
|
159
|
+
account: params.account
|
|
160
|
+
};
|
|
161
|
+
const rawResponse = await this.client.signTransaction(signTransactionParams);
|
|
162
|
+
return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId);
|
|
163
|
+
}
|
|
64
164
|
/**
|
|
65
165
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
66
166
|
* @param params - Transaction parameters with flexible transaction format
|
|
@@ -72,16 +172,19 @@ var ServerSDK = class {
|
|
|
72
172
|
walletId: params.walletId,
|
|
73
173
|
transaction: parsedTransaction.base64url,
|
|
74
174
|
networkId: params.networkId,
|
|
75
|
-
derivationIndex: params.derivationIndex
|
|
175
|
+
derivationIndex: params.derivationIndex,
|
|
176
|
+
account: params.account
|
|
76
177
|
};
|
|
77
178
|
const rawResponse = await this.client.signAndSendTransaction(signAndSendParams);
|
|
78
179
|
return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
79
180
|
}
|
|
80
181
|
createOrganization(name, keyPair) {
|
|
182
|
+
const headers = createServerSdkHeaders(this.config.appId);
|
|
81
183
|
const tempClient = new PhantomClient(
|
|
82
184
|
{
|
|
83
|
-
apiBaseUrl: this.config.apiBaseUrl,
|
|
84
|
-
organizationId: this.config.organizationId
|
|
185
|
+
apiBaseUrl: this.config.apiBaseUrl || DEFAULT_WALLET_API_URL,
|
|
186
|
+
organizationId: this.config.organizationId,
|
|
187
|
+
headers
|
|
85
188
|
},
|
|
86
189
|
new ApiKeyStamper({
|
|
87
190
|
apiSecretKey: keyPair.secretKey
|
|
@@ -90,11 +193,11 @@ var ServerSDK = class {
|
|
|
90
193
|
const base64urlPublicKey = base64urlEncode(bs58.decode(keyPair.publicKey));
|
|
91
194
|
return tempClient.createOrganization(name, [
|
|
92
195
|
{
|
|
93
|
-
username: `user-${
|
|
196
|
+
username: `user-${randomUUID()}`,
|
|
94
197
|
role: "ADMIN",
|
|
95
198
|
authenticators: [
|
|
96
199
|
{
|
|
97
|
-
authenticatorName: `auth-${
|
|
200
|
+
authenticatorName: `auth-${getSecureTimestampSync()}`,
|
|
98
201
|
authenticatorKind: "keypair",
|
|
99
202
|
publicKey: base64urlPublicKey,
|
|
100
203
|
algorithm: "Ed25519"
|
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.10",
|
|
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.6",
|
|
41
|
+
"@phantom/base64url": "^1.0.0-beta.6",
|
|
42
|
+
"@phantom/client": "^1.0.0-beta.10",
|
|
43
|
+
"@phantom/constants": "^1.0.0-beta.6",
|
|
44
|
+
"@phantom/parsers": "^1.0.0-beta.6",
|
|
45
|
+
"@phantom/utils": "^1.0.0-beta.4",
|
|
45
46
|
"bs58": "^6.0.0"
|
|
46
47
|
},
|
|
47
48
|
"files": [
|