@phantom/server-sdk 1.0.0-beta.2 → 1.0.0-beta.4
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +89 -7
- package/dist/index.mjs +90 -5
- 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
|
package/dist/index.d.ts
CHANGED
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.4",
|
|
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
|
);
|
|
@@ -121,10 +201,12 @@ var ServerSDK = class {
|
|
|
121
201
|
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
122
202
|
}
|
|
123
203
|
createOrganization(name, keyPair) {
|
|
204
|
+
const headers = createServerSdkHeaders(this.config.appId);
|
|
124
205
|
const tempClient = new import_client.PhantomClient(
|
|
125
206
|
{
|
|
126
|
-
apiBaseUrl: this.config.apiBaseUrl,
|
|
127
|
-
organizationId: this.config.organizationId
|
|
207
|
+
apiBaseUrl: this.config.apiBaseUrl || import_constants.DEFAULT_WALLET_API_URL,
|
|
208
|
+
organizationId: this.config.organizationId,
|
|
209
|
+
headers
|
|
128
210
|
},
|
|
129
211
|
new import_api_key_stamper.ApiKeyStamper({
|
|
130
212
|
apiSecretKey: keyPair.secretKey
|
|
@@ -133,7 +215,7 @@ var ServerSDK = class {
|
|
|
133
215
|
const base64urlPublicKey = (0, import_base64url.base64urlEncode)(import_bs58.default.decode(keyPair.publicKey));
|
|
134
216
|
return tempClient.createOrganization(name, [
|
|
135
217
|
{
|
|
136
|
-
username: `user-${
|
|
218
|
+
username: `user-${(0, import_utils.randomUUID)()}`,
|
|
137
219
|
role: "ADMIN",
|
|
138
220
|
authenticators: [
|
|
139
221
|
{
|
package/dist/index.mjs
CHANGED
|
@@ -2,9 +2,72 @@
|
|
|
2
2
|
import {
|
|
3
3
|
PhantomClient
|
|
4
4
|
} from "@phantom/client";
|
|
5
|
+
import { randomUUID } 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.4",
|
|
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
|
);
|
|
@@ -94,10 +177,12 @@ var ServerSDK = class {
|
|
|
94
177
|
return await parseTransactionResponse(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
95
178
|
}
|
|
96
179
|
createOrganization(name, keyPair) {
|
|
180
|
+
const headers = createServerSdkHeaders(this.config.appId);
|
|
97
181
|
const tempClient = new PhantomClient(
|
|
98
182
|
{
|
|
99
|
-
apiBaseUrl: this.config.apiBaseUrl,
|
|
100
|
-
organizationId: this.config.organizationId
|
|
183
|
+
apiBaseUrl: this.config.apiBaseUrl || DEFAULT_WALLET_API_URL,
|
|
184
|
+
organizationId: this.config.organizationId,
|
|
185
|
+
headers
|
|
101
186
|
},
|
|
102
187
|
new ApiKeyStamper({
|
|
103
188
|
apiSecretKey: keyPair.secretKey
|
|
@@ -106,7 +191,7 @@ var ServerSDK = class {
|
|
|
106
191
|
const base64urlPublicKey = base64urlEncode(bs58.decode(keyPair.publicKey));
|
|
107
192
|
return tempClient.createOrganization(name, [
|
|
108
193
|
{
|
|
109
|
-
username: `user-${
|
|
194
|
+
username: `user-${randomUUID()}`,
|
|
110
195
|
role: "ADMIN",
|
|
111
196
|
authenticators: [
|
|
112
197
|
{
|
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.4",
|
|
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.4",
|
|
41
|
+
"@phantom/base64url": "^1.0.0-beta.4",
|
|
42
|
+
"@phantom/client": "^1.0.0-beta.4",
|
|
43
|
+
"@phantom/constants": "^1.0.0-beta.4",
|
|
44
|
+
"@phantom/parsers": "^1.0.0-beta.4",
|
|
45
|
+
"@phantom/utils": "^1.0.0-beta.3",
|
|
45
46
|
"bs58": "^6.0.0"
|
|
46
47
|
},
|
|
47
48
|
"files": [
|