@phantom/server-sdk 0.1.4 → 0.2.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
@@ -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, NetworkId, PhantomClient, SignedTransaction, Transaction, Wallet, deriveSubmissionConfig, generateKeyPair, getDerivationPathForNetwork, getNetworkConfig, getNetworkDescription, getNetworkIdsByChain, getSupportedNetworkIds, supportsTransactionSubmission } from '@phantom/client';
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 extends PhantomClient {
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<string> - Base64 encoded signature
36
+ * @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
33
37
  */
34
- signMessage(params: ServerSignMessageParams): Promise<string>;
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<SignedTransaction> - Signed transaction result
42
+ * @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
39
43
  */
40
- signAndSendTransaction(params: ServerSignAndSendTransactionParams): Promise<any>;
44
+ signAndSendTransaction(params: ServerSignAndSendTransactionParams): Promise<ParsedTransactionResult>;
45
+ createOrganization(name: string, keyPair: {
46
+ publicKey: string;
47
+ secretKey: string;
48
+ }): 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
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -22,7 +32,7 @@ var src_exports = {};
22
32
  __export(src_exports, {
23
33
  ApiKeyStamper: () => import_api_key_stamper2.ApiKeyStamper,
24
34
  DerivationPath: () => import_client2.DerivationPath,
25
- NetworkId: () => import_client2.NetworkId,
35
+ NetworkId: () => import_constants.NetworkId,
26
36
  PhantomClient: () => import_client2.PhantomClient,
27
37
  ServerSDK: () => ServerSDK,
28
38
  deriveSubmissionConfig: () => import_client2.deriveSubmissionConfig,
@@ -33,22 +43,28 @@ __export(src_exports, {
33
43
  getNetworkIdsByChain: () => import_client2.getNetworkIdsByChain,
34
44
  getSupportedNetworkIds: () => import_client2.getSupportedNetworkIds,
35
45
  parseMessage: () => import_parsers2.parseMessage,
46
+ parseSignMessageResponse: () => import_parsers2.parseSignMessageResponse,
36
47
  parseTransaction: () => import_parsers2.parseTransaction,
48
+ parseTransactionResponse: () => import_parsers2.parseTransactionResponse,
37
49
  supportsTransactionSubmission: () => import_client2.supportsTransactionSubmission
38
50
  });
39
51
  module.exports = __toCommonJS(src_exports);
40
52
  var import_client = require("@phantom/client");
41
53
  var import_api_key_stamper = require("@phantom/api-key-stamper");
54
+ var import_base64url = require("@phantom/base64url");
55
+ var import_bs58 = __toESM(require("bs58"));
42
56
  var import_parsers = require("@phantom/parsers");
43
57
  var import_client2 = require("@phantom/client");
58
+ var import_constants = require("@phantom/constants");
44
59
  var import_api_key_stamper2 = require("@phantom/api-key-stamper");
45
60
  var import_parsers2 = require("@phantom/parsers");
46
- var ServerSDK = class extends import_client.PhantomClient {
61
+ var ServerSDK = class {
47
62
  constructor(config) {
63
+ this.config = config;
48
64
  const stamper = new import_api_key_stamper.ApiKeyStamper({
49
65
  apiSecretKey: config.apiPrivateKey
50
66
  });
51
- super(
67
+ this.client = new import_client.PhantomClient(
52
68
  {
53
69
  apiBaseUrl: config.apiBaseUrl,
54
70
  organizationId: config.organizationId
@@ -59,21 +75,22 @@ var ServerSDK = class extends import_client.PhantomClient {
59
75
  /**
60
76
  * Sign a message - supports plain text and automatically converts to base64url
61
77
  * @param params - Message parameters with plain text message
62
- * @returns Promise<string> - Base64 encoded signature
78
+ * @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
63
79
  */
64
- signMessage(params) {
80
+ async signMessage(params) {
65
81
  const parsedMessage = (0, import_parsers.parseMessage)(params.message);
66
82
  const signMessageParams = {
67
83
  walletId: params.walletId,
68
84
  message: parsedMessage.base64url,
69
85
  networkId: params.networkId
70
86
  };
71
- return super.signMessage(signMessageParams);
87
+ const rawResponse = await this.client.signMessage(signMessageParams);
88
+ return (0, import_parsers.parseSignMessageResponse)(rawResponse, params.networkId);
72
89
  }
73
90
  /**
74
91
  * Sign and send a transaction - supports various transaction formats and automatically parses them
75
92
  * @param params - Transaction parameters with flexible transaction format
76
- * @returns Promise<SignedTransaction> - Signed transaction result
93
+ * @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
77
94
  */
78
95
  async signAndSendTransaction(params) {
79
96
  const parsedTransaction = await (0, import_parsers.parseTransaction)(params.transaction, params.networkId);
@@ -82,7 +99,39 @@ var ServerSDK = class extends import_client.PhantomClient {
82
99
  transaction: parsedTransaction.base64url,
83
100
  networkId: params.networkId
84
101
  };
85
- return super.signAndSendTransaction(signAndSendParams);
102
+ const rawResponse = await this.client.signAndSendTransaction(signAndSendParams);
103
+ return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
104
+ }
105
+ createOrganization(name, keyPair) {
106
+ const tempClient = new import_client.PhantomClient(
107
+ {
108
+ apiBaseUrl: this.config.apiBaseUrl,
109
+ organizationId: this.config.organizationId
110
+ },
111
+ new import_api_key_stamper.ApiKeyStamper({
112
+ apiSecretKey: keyPair.secretKey
113
+ })
114
+ );
115
+ const base64urlPublicKey = (0, import_base64url.base64urlEncode)(import_bs58.default.decode(keyPair.publicKey));
116
+ return tempClient.createOrganization(name, [{
117
+ username: `user-${Date.now()}`,
118
+ role: "admin",
119
+ authenticators: [{
120
+ authenticatorName: `auth-${Date.now()}`,
121
+ authenticatorKind: "keypair",
122
+ publicKey: base64urlPublicKey,
123
+ algorithm: "Ed25519"
124
+ }]
125
+ }]);
126
+ }
127
+ getWallets(limit, offset) {
128
+ return this.client.getWallets(limit, offset);
129
+ }
130
+ createWallet(name) {
131
+ return this.client.createWallet(name);
132
+ }
133
+ getWalletAddresses(walletId, derivationPaths) {
134
+ return this.client.getWalletAddresses(walletId, derivationPaths);
86
135
  }
87
136
  };
88
137
  // Annotate the CommonJS export names for ESM import in node:
@@ -100,6 +149,8 @@ var ServerSDK = class extends import_client.PhantomClient {
100
149
  getNetworkIdsByChain,
101
150
  getSupportedNetworkIds,
102
151
  parseMessage,
152
+ parseSignMessageResponse,
103
153
  parseTransaction,
154
+ parseTransactionResponse,
104
155
  supportsTransactionSubmission
105
156
  });
package/dist/index.mjs CHANGED
@@ -3,10 +3,16 @@ import {
3
3
  PhantomClient
4
4
  } from "@phantom/client";
5
5
  import { ApiKeyStamper } from "@phantom/api-key-stamper";
6
- import { parseMessage, parseTransaction } from "@phantom/parsers";
6
+ import { base64urlEncode } from "@phantom/base64url";
7
+ import bs58 from "bs58";
8
+ import {
9
+ parseMessage,
10
+ parseTransaction,
11
+ parseSignMessageResponse,
12
+ parseTransactionResponse
13
+ } from "@phantom/parsers";
7
14
  import {
8
15
  PhantomClient as PhantomClient2,
9
- NetworkId,
10
16
  deriveSubmissionConfig,
11
17
  supportsTransactionSubmission,
12
18
  getNetworkDescription,
@@ -17,14 +23,21 @@ import {
17
23
  getNetworkConfig,
18
24
  generateKeyPair
19
25
  } from "@phantom/client";
26
+ import { NetworkId } from "@phantom/constants";
20
27
  import { ApiKeyStamper as ApiKeyStamper2 } from "@phantom/api-key-stamper";
21
- import { parseMessage as parseMessage2, parseTransaction as parseTransaction2 } from "@phantom/parsers";
22
- var ServerSDK = class extends PhantomClient {
28
+ import {
29
+ parseMessage as parseMessage2,
30
+ parseTransaction as parseTransaction2,
31
+ parseSignMessageResponse as parseSignMessageResponse2,
32
+ parseTransactionResponse as parseTransactionResponse2
33
+ } from "@phantom/parsers";
34
+ var ServerSDK = class {
23
35
  constructor(config) {
36
+ this.config = config;
24
37
  const stamper = new ApiKeyStamper({
25
38
  apiSecretKey: config.apiPrivateKey
26
39
  });
27
- super(
40
+ this.client = new PhantomClient(
28
41
  {
29
42
  apiBaseUrl: config.apiBaseUrl,
30
43
  organizationId: config.organizationId
@@ -35,21 +48,22 @@ var ServerSDK = class extends PhantomClient {
35
48
  /**
36
49
  * Sign a message - supports plain text and automatically converts to base64url
37
50
  * @param params - Message parameters with plain text message
38
- * @returns Promise<string> - Base64 encoded signature
51
+ * @returns Promise<ParsedSignatureResult> - Parsed signature with explorer URL
39
52
  */
40
- signMessage(params) {
53
+ async signMessage(params) {
41
54
  const parsedMessage = parseMessage(params.message);
42
55
  const signMessageParams = {
43
56
  walletId: params.walletId,
44
57
  message: parsedMessage.base64url,
45
58
  networkId: params.networkId
46
59
  };
47
- return super.signMessage(signMessageParams);
60
+ const rawResponse = await this.client.signMessage(signMessageParams);
61
+ return parseSignMessageResponse(rawResponse, params.networkId);
48
62
  }
49
63
  /**
50
64
  * Sign and send a transaction - supports various transaction formats and automatically parses them
51
65
  * @param params - Transaction parameters with flexible transaction format
52
- * @returns Promise<SignedTransaction> - Signed transaction result
66
+ * @returns Promise<ParsedTransactionResult> - Parsed transaction result with hash and explorer URL
53
67
  */
54
68
  async signAndSendTransaction(params) {
55
69
  const parsedTransaction = await parseTransaction(params.transaction, params.networkId);
@@ -58,7 +72,39 @@ var ServerSDK = class extends PhantomClient {
58
72
  transaction: parsedTransaction.base64url,
59
73
  networkId: params.networkId
60
74
  };
61
- return super.signAndSendTransaction(signAndSendParams);
75
+ const rawResponse = await this.client.signAndSendTransaction(signAndSendParams);
76
+ return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
77
+ }
78
+ createOrganization(name, keyPair) {
79
+ const tempClient = new PhantomClient(
80
+ {
81
+ apiBaseUrl: this.config.apiBaseUrl,
82
+ organizationId: this.config.organizationId
83
+ },
84
+ new ApiKeyStamper({
85
+ apiSecretKey: keyPair.secretKey
86
+ })
87
+ );
88
+ const base64urlPublicKey = base64urlEncode(bs58.decode(keyPair.publicKey));
89
+ return tempClient.createOrganization(name, [{
90
+ username: `user-${Date.now()}`,
91
+ role: "admin",
92
+ authenticators: [{
93
+ authenticatorName: `auth-${Date.now()}`,
94
+ authenticatorKind: "keypair",
95
+ publicKey: base64urlPublicKey,
96
+ algorithm: "Ed25519"
97
+ }]
98
+ }]);
99
+ }
100
+ getWallets(limit, offset) {
101
+ return this.client.getWallets(limit, offset);
102
+ }
103
+ createWallet(name) {
104
+ return this.client.createWallet(name);
105
+ }
106
+ getWalletAddresses(walletId, derivationPaths) {
107
+ return this.client.getWalletAddresses(walletId, derivationPaths);
62
108
  }
63
109
  };
64
110
  export {
@@ -75,6 +121,8 @@ export {
75
121
  getNetworkIdsByChain,
76
122
  getSupportedNetworkIds,
77
123
  parseMessage2 as parseMessage,
124
+ parseSignMessageResponse2 as parseSignMessageResponse,
78
125
  parseTransaction2 as parseTransaction,
126
+ parseTransactionResponse2 as parseTransactionResponse,
79
127
  supportsTransactionSubmission
80
128
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/server-sdk",
3
- "version": "0.1.4",
3
+ "version": "0.2.2",
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,13 @@
36
37
  "typescript": "^5.0.4"
37
38
  },
38
39
  "dependencies": {
39
- "@phantom/api-key-stamper": "^0.1.1",
40
- "@phantom/client": "^0.1.3",
40
+ "@phantom/api-key-stamper": "^0.1.3",
41
+ "@phantom/base64url": "^0.1.0",
42
+ "@phantom/client": "^0.1.6",
43
+ "@phantom/constants": "^0.0.2",
41
44
  "@phantom/openapi-wallet-service": "^0.1.7",
42
- "@phantom/parsers": "^0.0.4"
45
+ "@phantom/parsers": "^0.0.6",
46
+ "bs58": "^6.0.0"
43
47
  },
44
48
  "files": [
45
49
  "dist"