namirasoft-core 1.2.10 → 1.2.11
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/BaseServer.js +1 -1
- package/dist/HashOperation.d.ts +4 -4
- package/dist/HashOperation.js +6 -6
- package/dist/HashOperation.js.map +1 -1
- package/package.json +1 -1
- package/src/BaseServer.ts +1 -1
- package/src/HashOperation.ts +6 -6
package/dist/BaseServer.js
CHANGED
|
@@ -32,7 +32,7 @@ class BaseServer {
|
|
|
32
32
|
if (sign_key)
|
|
33
33
|
if (data)
|
|
34
34
|
if (config === null || config === void 0 ? void 0 : config.headers)
|
|
35
|
-
config.headers[sign_header] = HashOperation_1.HashOperation.
|
|
35
|
+
config.headers[sign_header] = HashOperation_1.HashOperation.SHA256Secret(sign_key, data);
|
|
36
36
|
try {
|
|
37
37
|
this.onBeforeRequest(url, config);
|
|
38
38
|
let response = yield onRequest(url, data, config);
|
package/dist/HashOperation.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare class HashOperation {
|
|
2
|
-
static
|
|
3
|
-
static
|
|
4
|
-
static
|
|
5
|
-
static
|
|
2
|
+
static SHA256<T>(message: T): string;
|
|
3
|
+
static SHA256Secret<T>(secret: string, message: T): string;
|
|
4
|
+
static isValidSHA256(values: any, signature: string): boolean;
|
|
5
|
+
static isValidSHA256Secret(secret: string, values: any, signature: string): boolean;
|
|
6
6
|
}
|
package/dist/HashOperation.js
CHANGED
|
@@ -26,21 +26,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.HashOperation = void 0;
|
|
27
27
|
const crypto = __importStar(require("node:crypto"));
|
|
28
28
|
class HashOperation {
|
|
29
|
-
static
|
|
29
|
+
static SHA256(message) {
|
|
30
30
|
const hash = crypto.createHash('sha256');
|
|
31
31
|
hash.update(JSON.stringify(message));
|
|
32
32
|
return hash.digest('hex');
|
|
33
33
|
}
|
|
34
|
-
static
|
|
34
|
+
static SHA256Secret(secret, message) {
|
|
35
35
|
const hash = crypto.createHmac('sha256', secret);
|
|
36
36
|
hash.update(JSON.stringify(message));
|
|
37
37
|
return hash.digest('hex');
|
|
38
38
|
}
|
|
39
|
-
static
|
|
40
|
-
return this.
|
|
39
|
+
static isValidSHA256(values, signature) {
|
|
40
|
+
return this.SHA256(values).toLowerCase() === signature.toLowerCase();
|
|
41
41
|
}
|
|
42
|
-
static
|
|
43
|
-
return this.
|
|
42
|
+
static isValidSHA256Secret(secret, values, signature) {
|
|
43
|
+
return this.SHA256Secret(secret, values).toLowerCase() === signature.toLowerCase();
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
exports.HashOperation = HashOperation;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HashOperation.js","sourceRoot":"","sources":["../src/HashOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,MAAa,aAAa;IAEtB,MAAM,CAAC,MAAM,CAAI,OAAU;QAEvB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,MAAM,CAAC,YAAY,CAAI,MAAc,EAAE,OAAU;QAE7C,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,MAAM,CAAC,
|
|
1
|
+
{"version":3,"file":"HashOperation.js","sourceRoot":"","sources":["../src/HashOperation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oDAAsC;AAEtC,MAAa,aAAa;IAEtB,MAAM,CAAC,MAAM,CAAI,OAAU;QAEvB,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;QACzC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,MAAM,CAAC,YAAY,CAAI,MAAc,EAAE,OAAU;QAE7C,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QACjD,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IACD,MAAM,CAAC,aAAa,CAAC,MAAW,EAAE,SAAiB;QAE/C,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,WAAW,EAAE,CAAC;IACzE,CAAC;IACD,MAAM,CAAC,mBAAmB,CAAC,MAAc,EAAE,MAAW,EAAE,SAAiB;QAErE,OAAO,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,WAAW,EAAE,CAAC;IACvF,CAAC;CACJ;AAtBD,sCAsBC"}
|
package/package.json
CHANGED
package/src/BaseServer.ts
CHANGED
|
@@ -23,7 +23,7 @@ export abstract class BaseServer
|
|
|
23
23
|
if (sign_key)
|
|
24
24
|
if (data)
|
|
25
25
|
if (config?.headers)
|
|
26
|
-
config.headers[sign_header] = HashOperation.
|
|
26
|
+
config.headers[sign_header] = HashOperation.SHA256Secret(sign_key, data);
|
|
27
27
|
try
|
|
28
28
|
{
|
|
29
29
|
this.onBeforeRequest(url, config);
|
package/src/HashOperation.ts
CHANGED
|
@@ -2,24 +2,24 @@ import * as crypto from 'node:crypto';
|
|
|
2
2
|
|
|
3
3
|
export class HashOperation
|
|
4
4
|
{
|
|
5
|
-
static
|
|
5
|
+
static SHA256<T>(message: T): string
|
|
6
6
|
{
|
|
7
7
|
const hash = crypto.createHash('sha256');
|
|
8
8
|
hash.update(JSON.stringify(message));
|
|
9
9
|
return hash.digest('hex');
|
|
10
10
|
}
|
|
11
|
-
static
|
|
11
|
+
static SHA256Secret<T>(secret: string, message: T): string
|
|
12
12
|
{
|
|
13
13
|
const hash = crypto.createHmac('sha256', secret);
|
|
14
14
|
hash.update(JSON.stringify(message));
|
|
15
15
|
return hash.digest('hex');
|
|
16
16
|
}
|
|
17
|
-
static
|
|
17
|
+
static isValidSHA256(values: any, signature: string)
|
|
18
18
|
{
|
|
19
|
-
return this.
|
|
19
|
+
return this.SHA256(values).toLowerCase() === signature.toLowerCase();
|
|
20
20
|
}
|
|
21
|
-
static
|
|
21
|
+
static isValidSHA256Secret(secret: string, values: any, signature: string)
|
|
22
22
|
{
|
|
23
|
-
return this.
|
|
23
|
+
return this.SHA256Secret(secret, values).toLowerCase() === signature.toLowerCase();
|
|
24
24
|
}
|
|
25
25
|
}
|