@seayoo-io/combo-sdk-node 0.1.2 → 0.1.3
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/dist/const.d.ts +1 -1
- package/dist/index.cjs +10 -9
- package/dist/index.js +10 -9
- package/dist/utils/signer.d.ts +1 -1
- package/package.json +12 -7
- package/vitest.config.ts +9 -0
package/dist/const.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ var https__namespace = /*#__PURE__*/_interopNamespace(https);
|
|
|
28
28
|
/** SDK 名称 */
|
|
29
29
|
const SDKName = "combo-sdk-node";
|
|
30
30
|
/** SDK 版本,在编译前会被动态替换 */
|
|
31
|
-
const SDKVersion = "0.1.
|
|
31
|
+
const SDKVersion = "0.1.3";
|
|
32
32
|
/**
|
|
33
33
|
* 世游支持的服务端点列表
|
|
34
34
|
*/
|
|
@@ -187,7 +187,6 @@ function verifyConfig(config) {
|
|
|
187
187
|
|
|
188
188
|
const AuthorizationField = "Authorization";
|
|
189
189
|
const MaxTimeDiff = 5 * 60 * 1000;
|
|
190
|
-
const EmptyStringSha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
191
190
|
const timestampReg = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/;
|
|
192
191
|
// 签名方法定义,给未来扩展新签名方法留出空间
|
|
193
192
|
const SigningDefinitions = {
|
|
@@ -196,15 +195,17 @@ const SigningDefinitions = {
|
|
|
196
195
|
sign({
|
|
197
196
|
game,
|
|
198
197
|
secret,
|
|
199
|
-
endpoint,
|
|
200
198
|
method,
|
|
201
199
|
url,
|
|
202
200
|
data,
|
|
203
201
|
timestamp
|
|
204
202
|
}, onlySignature = false) {
|
|
205
|
-
|
|
203
|
+
if (timestamp && !timestampReg.test(timestamp)) {
|
|
204
|
+
return "ErrorTimestamp";
|
|
205
|
+
}
|
|
206
|
+
const payloadHash = sha256(convertBodyData(data || ""));
|
|
206
207
|
const ts = timestamp || getTimestamp();
|
|
207
|
-
const fullURL = url
|
|
208
|
+
const fullURL = isFullURL(url) ? new URL(url) : new URL(url, "http://x.com");
|
|
208
209
|
const uri = fullURL.pathname + fullURL.search;
|
|
209
210
|
const signature = hS256(secret, [this.prefix, method.toUpperCase(), uri, ts, payloadHash].join("\n"));
|
|
210
211
|
return onlySignature ? signature : `${this.prefix} Game=${game},Timestamp=${ts},Signature=${signature}`;
|
|
@@ -221,7 +222,8 @@ const SigningDefinitions = {
|
|
|
221
222
|
return false;
|
|
222
223
|
}
|
|
223
224
|
const ts = parseTimestamp(timestamp);
|
|
224
|
-
|
|
225
|
+
// 时间戳精度只到秒,需要忽略毫秒值
|
|
226
|
+
const now = Math.floor(Date.now() / 1000) * 1000;
|
|
225
227
|
if (!ts || ts < now - MaxTimeDiff || ts > now + MaxTimeDiff) {
|
|
226
228
|
return false;
|
|
227
229
|
}
|
|
@@ -295,8 +297,7 @@ function convertBodyData(body) {
|
|
|
295
297
|
if (typeof body === "string") {
|
|
296
298
|
return body;
|
|
297
299
|
}
|
|
298
|
-
|
|
299
|
-
return body.toString();
|
|
300
|
+
return JSON.stringify(body);
|
|
300
301
|
}
|
|
301
302
|
function parseRawAuthHeader(authString, prefix) {
|
|
302
303
|
if (!authString || !authString.startsWith(prefix + " ")) {
|
|
@@ -317,7 +318,7 @@ function parseRawAuthHeader(authString, prefix) {
|
|
|
317
318
|
}
|
|
318
319
|
function getValue(value) {
|
|
319
320
|
const v = value.trim();
|
|
320
|
-
return /^".+"$/.test(v) ?
|
|
321
|
+
return /^".+"$/.test(v) ? v.replace(/^"|"$/g, "") : v;
|
|
321
322
|
}
|
|
322
323
|
|
|
323
324
|
async function readBody(req, backup) {
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { verify } from 'jsonwebtoken';
|
|
|
7
7
|
/** SDK 名称 */
|
|
8
8
|
const SDKName = "combo-sdk-node";
|
|
9
9
|
/** SDK 版本,在编译前会被动态替换 */
|
|
10
|
-
const SDKVersion = "0.1.
|
|
10
|
+
const SDKVersion = "0.1.3";
|
|
11
11
|
/**
|
|
12
12
|
* 世游支持的服务端点列表
|
|
13
13
|
*/
|
|
@@ -166,7 +166,6 @@ function verifyConfig(config) {
|
|
|
166
166
|
|
|
167
167
|
const AuthorizationField = "Authorization";
|
|
168
168
|
const MaxTimeDiff = 5 * 60 * 1000;
|
|
169
|
-
const EmptyStringSha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
170
169
|
const timestampReg = /^(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})Z$/;
|
|
171
170
|
// 签名方法定义,给未来扩展新签名方法留出空间
|
|
172
171
|
const SigningDefinitions = {
|
|
@@ -175,15 +174,17 @@ const SigningDefinitions = {
|
|
|
175
174
|
sign({
|
|
176
175
|
game,
|
|
177
176
|
secret,
|
|
178
|
-
endpoint,
|
|
179
177
|
method,
|
|
180
178
|
url,
|
|
181
179
|
data,
|
|
182
180
|
timestamp
|
|
183
181
|
}, onlySignature = false) {
|
|
184
|
-
|
|
182
|
+
if (timestamp && !timestampReg.test(timestamp)) {
|
|
183
|
+
return "ErrorTimestamp";
|
|
184
|
+
}
|
|
185
|
+
const payloadHash = sha256(convertBodyData(data || ""));
|
|
185
186
|
const ts = timestamp || getTimestamp();
|
|
186
|
-
const fullURL = url
|
|
187
|
+
const fullURL = isFullURL(url) ? new URL(url) : new URL(url, "http://x.com");
|
|
187
188
|
const uri = fullURL.pathname + fullURL.search;
|
|
188
189
|
const signature = hS256(secret, [this.prefix, method.toUpperCase(), uri, ts, payloadHash].join("\n"));
|
|
189
190
|
return onlySignature ? signature : `${this.prefix} Game=${game},Timestamp=${ts},Signature=${signature}`;
|
|
@@ -200,7 +201,8 @@ const SigningDefinitions = {
|
|
|
200
201
|
return false;
|
|
201
202
|
}
|
|
202
203
|
const ts = parseTimestamp(timestamp);
|
|
203
|
-
|
|
204
|
+
// 时间戳精度只到秒,需要忽略毫秒值
|
|
205
|
+
const now = Math.floor(Date.now() / 1000) * 1000;
|
|
204
206
|
if (!ts || ts < now - MaxTimeDiff || ts > now + MaxTimeDiff) {
|
|
205
207
|
return false;
|
|
206
208
|
}
|
|
@@ -274,8 +276,7 @@ function convertBodyData(body) {
|
|
|
274
276
|
if (typeof body === "string") {
|
|
275
277
|
return body;
|
|
276
278
|
}
|
|
277
|
-
|
|
278
|
-
return body.toString();
|
|
279
|
+
return JSON.stringify(body);
|
|
279
280
|
}
|
|
280
281
|
function parseRawAuthHeader(authString, prefix) {
|
|
281
282
|
if (!authString || !authString.startsWith(prefix + " ")) {
|
|
@@ -296,7 +297,7 @@ function parseRawAuthHeader(authString, prefix) {
|
|
|
296
297
|
}
|
|
297
298
|
function getValue(value) {
|
|
298
299
|
const v = value.trim();
|
|
299
|
-
return /^".+"$/.test(v) ?
|
|
300
|
+
return /^".+"$/.test(v) ? v.replace(/^"|"$/g, "") : v;
|
|
300
301
|
}
|
|
301
302
|
|
|
302
303
|
async function readBody(req, backup) {
|
package/dist/utils/signer.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ type SignDataOptionForVerify = Omit<SignDataOption, "game" | "timestamp"> & {
|
|
|
15
15
|
declare const SigningDefinitions: {
|
|
16
16
|
readonly HS256: {
|
|
17
17
|
readonly prefix: "SEAYOO-HMAC-SHA256";
|
|
18
|
-
readonly sign: ({ game, secret,
|
|
18
|
+
readonly sign: ({ game, secret, method, url, data, timestamp }: SignDataOption, onlySignature?: boolean) => string;
|
|
19
19
|
readonly verify: (authString: string, option: SignDataOptionForVerify) => boolean;
|
|
20
20
|
};
|
|
21
21
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@seayoo-io/combo-sdk-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"description": "Combo SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"source": "./src/index.ts",
|
|
@@ -23,7 +23,11 @@
|
|
|
23
23
|
"type-check": "tsc --noEmit",
|
|
24
24
|
"lint": "eslint ./src/**/*.ts",
|
|
25
25
|
"lint:fix": "eslint ./src/**/*.{ts,js} --fix",
|
|
26
|
-
"
|
|
26
|
+
"test": "vitest",
|
|
27
|
+
"pub": "pnpm type-check && pnpm lint:fix && vitest run && pnpm build && npm publish"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=14.0.0"
|
|
27
31
|
},
|
|
28
32
|
"simple-git-hooks": {
|
|
29
33
|
"pre-commit": "pnpm lint && pnpm type-check"
|
|
@@ -40,9 +44,9 @@
|
|
|
40
44
|
"@types/express": "^4.17.21",
|
|
41
45
|
"@types/jsonwebtoken": "^9.0.5",
|
|
42
46
|
"@types/koa": "^2.13.12",
|
|
43
|
-
"@types/node": "^20.10.
|
|
44
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
45
|
-
"@typescript-eslint/parser": "^6.
|
|
47
|
+
"@types/node": "^20.10.6",
|
|
48
|
+
"@typescript-eslint/eslint-plugin": "^6.17.0",
|
|
49
|
+
"@typescript-eslint/parser": "^6.17.0",
|
|
46
50
|
"eslint": "^8.56.0",
|
|
47
51
|
"eslint-config-prettier": "^9.1.0",
|
|
48
52
|
"eslint-plugin-prettier": "^5.1.2",
|
|
@@ -50,8 +54,9 @@
|
|
|
50
54
|
"microbundle": "^0.15.1",
|
|
51
55
|
"rimraf": "^5.0.5",
|
|
52
56
|
"simple-git-hooks": "^2.9.0",
|
|
53
|
-
"
|
|
54
|
-
"
|
|
57
|
+
"typescript": "^5.3.3",
|
|
58
|
+
"vite": "^5.0.10",
|
|
59
|
+
"vitest": "^1.1.1"
|
|
55
60
|
},
|
|
56
61
|
"dependencies": {
|
|
57
62
|
"jsonwebtoken": "^9.0.2"
|