@phantom/server-sdk 0.1.3 → 0.2.1
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 +0 -2
- package/dist/index.d.ts +22 -8
- package/dist/index.js +37 -8
- package/dist/index.mjs +46 -10
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -45,7 +45,6 @@ pnpm add @phantom/server-sdk
|
|
|
45
45
|
Before using the SDK, you need:
|
|
46
46
|
|
|
47
47
|
1. **Phantom Organization Credentials**
|
|
48
|
-
|
|
49
48
|
- Organization ID
|
|
50
49
|
- Organization Private Key (base58 encoded)
|
|
51
50
|
- API Base URL
|
|
@@ -217,7 +216,6 @@ const unicodeSignature = await sdk.signMessage({
|
|
|
217
216
|
networkId: NetworkId.SOLANA_MAINNET,
|
|
218
217
|
});
|
|
219
218
|
|
|
220
|
-
const ethMessage = Buffer.from().toString("base64url");
|
|
221
219
|
const ethSignature = await sdk.signMessage({
|
|
222
220
|
walletId: wallet.walletId,
|
|
223
221
|
message: "Sign in to our dApp",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { NetworkId, PhantomClient } from '@phantom/client';
|
|
2
|
-
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig,
|
|
1
|
+
import { NetworkId, PhantomClient, Organization, GetWalletsResult, CreateWalletResult, AddressType } from '@phantom/client';
|
|
2
|
+
export { CreateWalletResult, DerivationPath, GetWalletsResult, NetworkConfig, PhantomClient, SignedTransaction, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
|
|
3
|
+
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
4
|
+
export { ParsedMessage, ParsedSignatureResult, ParsedTransaction, ParsedTransactionResult, parseMessage, parseSignMessageResponse, parseTransaction, parseTransactionResponse } from '@phantom/parsers';
|
|
5
|
+
export { NetworkId } from '@phantom/constants';
|
|
3
6
|
export { ApiKeyStamper } from '@phantom/api-key-stamper';
|
|
4
|
-
export { ParsedMessage, ParsedTransaction, parseMessage, parseTransaction } from '@phantom/parsers';
|
|
5
7
|
import { DerivationInfoAddressFormatEnum } from '@phantom/openapi-wallet-service';
|
|
6
8
|
|
|
7
9
|
interface WalletAddress {
|
|
@@ -24,20 +26,32 @@ interface ServerSignAndSendTransactionParams {
|
|
|
24
26
|
transaction: any;
|
|
25
27
|
networkId: NetworkId;
|
|
26
28
|
}
|
|
27
|
-
declare class ServerSDK
|
|
29
|
+
declare class ServerSDK {
|
|
30
|
+
private config;
|
|
31
|
+
client: PhantomClient;
|
|
28
32
|
constructor(config: ServerSDKConfig);
|
|
29
33
|
/**
|
|
30
34
|
* Sign a message - supports plain text and automatically converts to base64url
|
|
31
35
|
* @param params - Message parameters with plain text message
|
|
32
|
-
* @returns Promise<
|
|
36
|
+
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
33
37
|
*/
|
|
34
|
-
signMessage(params: ServerSignMessageParams): Promise<
|
|
38
|
+
signMessage(params: ServerSignMessageParams): Promise<ParsedSignatureResult>;
|
|
35
39
|
/**
|
|
36
40
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
37
41
|
* @param params - Transaction parameters with flexible transaction format
|
|
38
|
-
* @returns Promise<
|
|
42
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
|
|
39
43
|
*/
|
|
40
|
-
signAndSendTransaction(params: ServerSignAndSendTransactionParams): Promise<
|
|
44
|
+
signAndSendTransaction(params: ServerSignAndSendTransactionParams): Promise<ParsedTransactionResult>;
|
|
45
|
+
createOrganization(name: string, keyPair: {
|
|
46
|
+
publicKey: string;
|
|
47
|
+
secretKey: string;
|
|
48
|
+
}, authenticatorName?: string): Promise<Organization>;
|
|
49
|
+
getWallets(limit?: number, offset?: number): Promise<GetWalletsResult>;
|
|
50
|
+
createWallet(name: string): Promise<CreateWalletResult>;
|
|
51
|
+
getWalletAddresses(walletId: string, derivationPaths?: string[]): Promise<{
|
|
52
|
+
addressType: AddressType;
|
|
53
|
+
address: string;
|
|
54
|
+
}[]>;
|
|
41
55
|
}
|
|
42
56
|
|
|
43
57
|
export { ServerSDK, ServerSDKConfig, ServerSignAndSendTransactionParams, ServerSignMessageParams, WalletAddress };
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
ApiKeyStamper: () => import_api_key_stamper2.ApiKeyStamper,
|
|
24
24
|
DerivationPath: () => import_client2.DerivationPath,
|
|
25
|
-
NetworkId: () =>
|
|
25
|
+
NetworkId: () => import_constants.NetworkId,
|
|
26
26
|
PhantomClient: () => import_client2.PhantomClient,
|
|
27
27
|
ServerSDK: () => ServerSDK,
|
|
28
28
|
deriveSubmissionConfig: () => import_client2.deriveSubmissionConfig,
|
|
@@ -33,7 +33,9 @@ __export(src_exports, {
|
|
|
33
33
|
getNetworkIdsByChain: () => import_client2.getNetworkIdsByChain,
|
|
34
34
|
getSupportedNetworkIds: () => import_client2.getSupportedNetworkIds,
|
|
35
35
|
parseMessage: () => import_parsers2.parseMessage,
|
|
36
|
+
parseSignMessageResponse: () => import_parsers2.parseSignMessageResponse,
|
|
36
37
|
parseTransaction: () => import_parsers2.parseTransaction,
|
|
38
|
+
parseTransactionResponse: () => import_parsers2.parseTransactionResponse,
|
|
37
39
|
supportsTransactionSubmission: () => import_client2.supportsTransactionSubmission
|
|
38
40
|
});
|
|
39
41
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -41,14 +43,16 @@ var import_client = require("@phantom/client");
|
|
|
41
43
|
var import_api_key_stamper = require("@phantom/api-key-stamper");
|
|
42
44
|
var import_parsers = require("@phantom/parsers");
|
|
43
45
|
var import_client2 = require("@phantom/client");
|
|
46
|
+
var import_constants = require("@phantom/constants");
|
|
44
47
|
var import_api_key_stamper2 = require("@phantom/api-key-stamper");
|
|
45
48
|
var import_parsers2 = require("@phantom/parsers");
|
|
46
|
-
var ServerSDK = class
|
|
49
|
+
var ServerSDK = class {
|
|
47
50
|
constructor(config) {
|
|
51
|
+
this.config = config;
|
|
48
52
|
const stamper = new import_api_key_stamper.ApiKeyStamper({
|
|
49
53
|
apiSecretKey: config.apiPrivateKey
|
|
50
54
|
});
|
|
51
|
-
|
|
55
|
+
this.client = new import_client.PhantomClient(
|
|
52
56
|
{
|
|
53
57
|
apiBaseUrl: config.apiBaseUrl,
|
|
54
58
|
organizationId: config.organizationId
|
|
@@ -59,21 +63,22 @@ var ServerSDK = class extends import_client.PhantomClient {
|
|
|
59
63
|
/**
|
|
60
64
|
* Sign a message - supports plain text and automatically converts to base64url
|
|
61
65
|
* @param params - Message parameters with plain text message
|
|
62
|
-
* @returns Promise<
|
|
66
|
+
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
63
67
|
*/
|
|
64
|
-
signMessage(params) {
|
|
68
|
+
async signMessage(params) {
|
|
65
69
|
const parsedMessage = (0, import_parsers.parseMessage)(params.message);
|
|
66
70
|
const signMessageParams = {
|
|
67
71
|
walletId: params.walletId,
|
|
68
72
|
message: parsedMessage.base64url,
|
|
69
73
|
networkId: params.networkId
|
|
70
74
|
};
|
|
71
|
-
|
|
75
|
+
const rawResponse = await this.client.signMessage(signMessageParams);
|
|
76
|
+
return (0, import_parsers.parseSignMessageResponse)(rawResponse, params.networkId);
|
|
72
77
|
}
|
|
73
78
|
/**
|
|
74
79
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
75
80
|
* @param params - Transaction parameters with flexible transaction format
|
|
76
|
-
* @returns Promise<
|
|
81
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
|
|
77
82
|
*/
|
|
78
83
|
async signAndSendTransaction(params) {
|
|
79
84
|
const parsedTransaction = await (0, import_parsers.parseTransaction)(params.transaction, params.networkId);
|
|
@@ -82,7 +87,29 @@ var ServerSDK = class extends import_client.PhantomClient {
|
|
|
82
87
|
transaction: parsedTransaction.base64url,
|
|
83
88
|
networkId: params.networkId
|
|
84
89
|
};
|
|
85
|
-
|
|
90
|
+
const rawResponse = await this.client.signAndSendTransaction(signAndSendParams);
|
|
91
|
+
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
92
|
+
}
|
|
93
|
+
createOrganization(name, keyPair, authenticatorName) {
|
|
94
|
+
const tempClient = new import_client.PhantomClient(
|
|
95
|
+
{
|
|
96
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
97
|
+
organizationId: this.config.organizationId
|
|
98
|
+
},
|
|
99
|
+
new import_api_key_stamper.ApiKeyStamper({
|
|
100
|
+
apiSecretKey: keyPair.secretKey
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
return tempClient.createOrganization(name, keyPair.publicKey, authenticatorName);
|
|
104
|
+
}
|
|
105
|
+
getWallets(limit, offset) {
|
|
106
|
+
return this.client.getWallets(limit, offset);
|
|
107
|
+
}
|
|
108
|
+
createWallet(name) {
|
|
109
|
+
return this.client.createWallet(name);
|
|
110
|
+
}
|
|
111
|
+
getWalletAddresses(walletId, derivationPaths) {
|
|
112
|
+
return this.client.getWalletAddresses(walletId, derivationPaths);
|
|
86
113
|
}
|
|
87
114
|
};
|
|
88
115
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -100,6 +127,8 @@ var ServerSDK = class extends import_client.PhantomClient {
|
|
|
100
127
|
getNetworkIdsByChain,
|
|
101
128
|
getSupportedNetworkIds,
|
|
102
129
|
parseMessage,
|
|
130
|
+
parseSignMessageResponse,
|
|
103
131
|
parseTransaction,
|
|
132
|
+
parseTransactionResponse,
|
|
104
133
|
supportsTransactionSubmission
|
|
105
134
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -3,10 +3,14 @@ import {
|
|
|
3
3
|
PhantomClient
|
|
4
4
|
} from "@phantom/client";
|
|
5
5
|
import { ApiKeyStamper } from "@phantom/api-key-stamper";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
parseMessage,
|
|
8
|
+
parseTransaction,
|
|
9
|
+
parseSignMessageResponse,
|
|
10
|
+
parseTransactionResponse
|
|
11
|
+
} from "@phantom/parsers";
|
|
7
12
|
import {
|
|
8
13
|
PhantomClient as PhantomClient2,
|
|
9
|
-
NetworkId,
|
|
10
14
|
deriveSubmissionConfig,
|
|
11
15
|
supportsTransactionSubmission,
|
|
12
16
|
getNetworkDescription,
|
|
@@ -17,14 +21,21 @@ import {
|
|
|
17
21
|
getNetworkConfig,
|
|
18
22
|
generateKeyPair
|
|
19
23
|
} from "@phantom/client";
|
|
24
|
+
import { NetworkId } from "@phantom/constants";
|
|
20
25
|
import { ApiKeyStamper as ApiKeyStamper2 } from "@phantom/api-key-stamper";
|
|
21
|
-
import {
|
|
22
|
-
|
|
26
|
+
import {
|
|
27
|
+
parseMessage as parseMessage2,
|
|
28
|
+
parseTransaction as parseTransaction2,
|
|
29
|
+
parseSignMessageResponse as parseSignMessageResponse2,
|
|
30
|
+
parseTransactionResponse as parseTransactionResponse2
|
|
31
|
+
} from "@phantom/parsers";
|
|
32
|
+
var ServerSDK = class {
|
|
23
33
|
constructor(config) {
|
|
34
|
+
this.config = config;
|
|
24
35
|
const stamper = new ApiKeyStamper({
|
|
25
36
|
apiSecretKey: config.apiPrivateKey
|
|
26
37
|
});
|
|
27
|
-
|
|
38
|
+
this.client = new PhantomClient(
|
|
28
39
|
{
|
|
29
40
|
apiBaseUrl: config.apiBaseUrl,
|
|
30
41
|
organizationId: config.organizationId
|
|
@@ -35,21 +46,22 @@ var ServerSDK = class extends PhantomClient {
|
|
|
35
46
|
/**
|
|
36
47
|
* Sign a message - supports plain text and automatically converts to base64url
|
|
37
48
|
* @param params - Message parameters with plain text message
|
|
38
|
-
* @returns Promise<
|
|
49
|
+
* @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
|
|
39
50
|
*/
|
|
40
|
-
signMessage(params) {
|
|
51
|
+
async signMessage(params) {
|
|
41
52
|
const parsedMessage = parseMessage(params.message);
|
|
42
53
|
const signMessageParams = {
|
|
43
54
|
walletId: params.walletId,
|
|
44
55
|
message: parsedMessage.base64url,
|
|
45
56
|
networkId: params.networkId
|
|
46
57
|
};
|
|
47
|
-
|
|
58
|
+
const rawResponse = await this.client.signMessage(signMessageParams);
|
|
59
|
+
return parseSignMessageResponse(rawResponse, params.networkId);
|
|
48
60
|
}
|
|
49
61
|
/**
|
|
50
62
|
* Sign and send a transaction - supports various transaction formats and automatically parses them
|
|
51
63
|
* @param params - Transaction parameters with flexible transaction format
|
|
52
|
-
* @returns Promise<
|
|
64
|
+
* @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
|
|
53
65
|
*/
|
|
54
66
|
async signAndSendTransaction(params) {
|
|
55
67
|
const parsedTransaction = await parseTransaction(params.transaction, params.networkId);
|
|
@@ -58,7 +70,29 @@ var ServerSDK = class extends PhantomClient {
|
|
|
58
70
|
transaction: parsedTransaction.base64url,
|
|
59
71
|
networkId: params.networkId
|
|
60
72
|
};
|
|
61
|
-
|
|
73
|
+
const rawResponse = await this.client.signAndSendTransaction(signAndSendParams);
|
|
74
|
+
return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
75
|
+
}
|
|
76
|
+
createOrganization(name, keyPair, authenticatorName) {
|
|
77
|
+
const tempClient = new PhantomClient(
|
|
78
|
+
{
|
|
79
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
80
|
+
organizationId: this.config.organizationId
|
|
81
|
+
},
|
|
82
|
+
new ApiKeyStamper({
|
|
83
|
+
apiSecretKey: keyPair.secretKey
|
|
84
|
+
})
|
|
85
|
+
);
|
|
86
|
+
return tempClient.createOrganization(name, keyPair.publicKey, authenticatorName);
|
|
87
|
+
}
|
|
88
|
+
getWallets(limit, offset) {
|
|
89
|
+
return this.client.getWallets(limit, offset);
|
|
90
|
+
}
|
|
91
|
+
createWallet(name) {
|
|
92
|
+
return this.client.createWallet(name);
|
|
93
|
+
}
|
|
94
|
+
getWalletAddresses(walletId, derivationPaths) {
|
|
95
|
+
return this.client.getWalletAddresses(walletId, derivationPaths);
|
|
62
96
|
}
|
|
63
97
|
};
|
|
64
98
|
export {
|
|
@@ -75,6 +109,8 @@ export {
|
|
|
75
109
|
getNetworkIdsByChain,
|
|
76
110
|
getSupportedNetworkIds,
|
|
77
111
|
parseMessage2 as parseMessage,
|
|
112
|
+
parseSignMessageResponse2 as parseSignMessageResponse,
|
|
78
113
|
parseTransaction2 as parseTransaction,
|
|
114
|
+
parseTransactionResponse2 as parseTransactionResponse,
|
|
79
115
|
supportsTransactionSubmission
|
|
80
116
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/server-sdk",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Server SDK for Phantom Wallet",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"test": "jest",
|
|
22
22
|
"test:watch": "jest --watch",
|
|
23
23
|
"lint": "eslint src --ext .ts,.tsx",
|
|
24
|
+
"check-types": "yarn tsc --noEmit",
|
|
24
25
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
@@ -36,10 +37,11 @@
|
|
|
36
37
|
"typescript": "^5.0.4"
|
|
37
38
|
},
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"@phantom/api-key-stamper": "^0.1.
|
|
40
|
-
"@phantom/client": "^0.1.
|
|
40
|
+
"@phantom/api-key-stamper": "^0.1.2",
|
|
41
|
+
"@phantom/client": "^0.1.5",
|
|
42
|
+
"@phantom/constants": "^0.0.2",
|
|
41
43
|
"@phantom/openapi-wallet-service": "^0.1.7",
|
|
42
|
-
"@phantom/parsers": "^0.0.
|
|
44
|
+
"@phantom/parsers": "^0.0.5"
|
|
43
45
|
},
|
|
44
46
|
"files": [
|
|
45
47
|
"dist"
|