@blocklet/sdk 1.16.34 → 1.16.35-beta-20241220-110602-f7ee8cba
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/lib/config.d.ts +2 -0
- package/lib/config.js +2 -0
- package/lib/util/verify-session.d.ts +1 -0
- package/lib/util/verify-session.js +12 -7
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/wallet.d.ts +2 -2
- package/lib/wallet.js +2 -4
- package/package.json +8 -8
package/lib/config.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ declare const env: {
|
|
|
39
39
|
tenantMode: string;
|
|
40
40
|
appStorageEndpoint: string;
|
|
41
41
|
serverVersion: string;
|
|
42
|
+
sessionSalt: string;
|
|
42
43
|
languages: {
|
|
43
44
|
code: string;
|
|
44
45
|
name: string;
|
|
@@ -109,6 +110,7 @@ declare const _default: {
|
|
|
109
110
|
tenantMode: string;
|
|
110
111
|
appStorageEndpoint: string;
|
|
111
112
|
serverVersion: string;
|
|
113
|
+
sessionSalt: string;
|
|
112
114
|
languages: {
|
|
113
115
|
code: string;
|
|
114
116
|
name: string;
|
package/lib/config.js
CHANGED
|
@@ -44,6 +44,7 @@ const AppConfigKeyMap = {
|
|
|
44
44
|
BLOCKLET_APP_SPACE_ENDPOINT: 'appStorageEndpoint',
|
|
45
45
|
BLOCKLET_APP_LANGUAGES: ['languages', util_1.getBlockletLanguages],
|
|
46
46
|
BLOCKLET_APP_TENANT_MODE: 'tenantMode',
|
|
47
|
+
BLOCKLET_APP_SALT: 'sessionSalt',
|
|
47
48
|
ABT_NODE_VERSION: 'serverVersion',
|
|
48
49
|
ABT_NODE: 'serverVersion', // for backup compatibility
|
|
49
50
|
};
|
|
@@ -98,6 +99,7 @@ const env = {
|
|
|
98
99
|
cacheDir: process.env.BLOCKLET_CACHE_DIR,
|
|
99
100
|
mode: process.env.BLOCKLET_MODE,
|
|
100
101
|
tenantMode: process.env.BLOCKLET_APP_TENANT_MODE,
|
|
102
|
+
sessionSalt: process.env.BLOCKLET_APP_SALT || '',
|
|
101
103
|
preferences: {
|
|
102
104
|
...env_1.default.preferences,
|
|
103
105
|
...appEnvFromDisk.preferences,
|
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSessionSecret = void 0;
|
|
6
7
|
exports.verifyLoginToken = verifyLoginToken;
|
|
7
8
|
exports.verifyComponentCall = verifyComponentCall;
|
|
8
9
|
exports.verifySignedToken = verifySignedToken;
|
|
@@ -10,16 +11,21 @@ const constant_1 = require("@blocklet/constant");
|
|
|
10
11
|
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
11
12
|
const mcrypto_1 = require("@ocap/mcrypto");
|
|
12
13
|
const jwt_1 = require("@arcblock/jwt");
|
|
13
|
-
const login_1 = require("./login");
|
|
14
14
|
const wallet_1 = __importDefault(require("../wallet"));
|
|
15
|
+
const login_1 = require("./login");
|
|
16
|
+
const config_1 = require("../config");
|
|
15
17
|
const verify_sign_1 = require("./verify-sign");
|
|
18
|
+
const getSessionSecret = () => {
|
|
19
|
+
const wallet = (0, wallet_1.default)();
|
|
20
|
+
const secret = mcrypto_1.Hasher.SHA3.hash256(Buffer.concat([wallet.secretKey, wallet.address, config_1.env.sessionSalt].filter(Boolean).map((v) => Buffer.from(v))));
|
|
21
|
+
return secret;
|
|
22
|
+
};
|
|
23
|
+
exports.getSessionSecret = getSessionSecret;
|
|
16
24
|
function verifyLoginToken({ token, strictMode }) {
|
|
17
25
|
if (!token)
|
|
18
26
|
return null;
|
|
19
|
-
const wallet = (0, wallet_1.default)();
|
|
20
|
-
const secret = mcrypto_1.Hasher.SHA3.hash256(Buffer.concat([wallet.secretKey, wallet.address].map((v) => Buffer.from(v))));
|
|
21
27
|
return new Promise((resolve, reject) => {
|
|
22
|
-
jsonwebtoken_1.default.verify(token,
|
|
28
|
+
jsonwebtoken_1.default.verify(token, (0, exports.getSessionSecret)(), (err, decoded) => {
|
|
23
29
|
if (err) {
|
|
24
30
|
if (strictMode) {
|
|
25
31
|
reject(new Error('Unauthorized: Invalid login token'));
|
|
@@ -64,14 +70,13 @@ function verifyComponentCall({ req, strictMode }) {
|
|
|
64
70
|
function verifySignedToken({ token, strictMode }) {
|
|
65
71
|
if (!token)
|
|
66
72
|
return null;
|
|
67
|
-
|
|
68
|
-
const secret = mcrypto_1.Hasher.SHA3.hash256(Buffer.concat([wallet.secretKey, wallet.address].map((v) => Buffer.from(v))));
|
|
69
|
-
if ((0, jwt_1.verify)(token, secret) === false) {
|
|
73
|
+
if ((0, jwt_1.verify)(token, (0, exports.getSessionSecret)()) === false) {
|
|
70
74
|
if (strictMode) {
|
|
71
75
|
throw new Error('Unauthorized: Invalid signed token');
|
|
72
76
|
}
|
|
73
77
|
return null;
|
|
74
78
|
}
|
|
79
|
+
const wallet = (0, wallet_1.default)();
|
|
75
80
|
return {
|
|
76
81
|
did: wallet.address,
|
|
77
82
|
role: 'component',
|
package/lib/version.d.ts
CHANGED
package/lib/version.js
CHANGED
package/lib/wallet.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ import { DIDTypeShortcut } from '@arcblock/did';
|
|
|
7
7
|
*/
|
|
8
8
|
declare const getWallet: {
|
|
9
9
|
(type?: DIDTypeShortcut, appSk?: string): WalletObject;
|
|
10
|
-
getPermanentWallet
|
|
11
|
-
getEthereumWallet
|
|
10
|
+
getPermanentWallet(): WalletObject<string>;
|
|
11
|
+
getEthereumWallet(permanent?: boolean): WalletObject<string>;
|
|
12
12
|
getPkWallet(type?: DIDTypeShortcut, appPk?: string): WalletObject<string>;
|
|
13
13
|
};
|
|
14
14
|
export = getWallet;
|
package/lib/wallet.js
CHANGED
|
@@ -34,10 +34,8 @@ const getWallet = (type, appSk = process.env.BLOCKLET_APP_SK) => {
|
|
|
34
34
|
return currentWallet;
|
|
35
35
|
};
|
|
36
36
|
// BLOCKLET_WALLET_TYPE is for backward compatibility
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
getWallet.getPermanentWallet = getPermanentWallet;
|
|
40
|
-
getWallet.getEthereumWallet = getEthereumWallet;
|
|
37
|
+
getWallet.getPermanentWallet = () => getWallet(process.env.CHAIN_TYPE || process.env.BLOCKLET_WALLET_TYPE, process.env.BLOCKLET_APP_PSK);
|
|
38
|
+
getWallet.getEthereumWallet = (permanent = false) => getWallet('ethereum', permanent ? process.env.BLOCKLET_APP_PSK : process.env.BLOCKLET_APP_SK);
|
|
41
39
|
getWallet.getPkWallet = (type, appPk = process.env.BLOCKLET_APP_PK) => {
|
|
42
40
|
let t;
|
|
43
41
|
let sk;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.
|
|
6
|
+
"version": "1.16.35-beta-20241220-110602-f7ee8cba",
|
|
7
7
|
"description": "graphql client to read/write data on abt node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"typings": "lib/index.d.ts",
|
|
@@ -27,16 +27,16 @@
|
|
|
27
27
|
"author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
|
|
28
28
|
"license": "Apache-2.0",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@abtnode/client": "1.16.
|
|
31
|
-
"@abtnode/constant": "1.16.
|
|
32
|
-
"@abtnode/util": "1.16.
|
|
30
|
+
"@abtnode/client": "1.16.35-beta-20241220-110602-f7ee8cba",
|
|
31
|
+
"@abtnode/constant": "1.16.35-beta-20241220-110602-f7ee8cba",
|
|
32
|
+
"@abtnode/util": "1.16.35-beta-20241220-110602-f7ee8cba",
|
|
33
33
|
"@arcblock/did": "1.18.162",
|
|
34
34
|
"@arcblock/did-auth": "1.18.162",
|
|
35
35
|
"@arcblock/jwt": "1.18.162",
|
|
36
36
|
"@arcblock/ws": "1.18.162",
|
|
37
|
-
"@blocklet/constant": "1.16.
|
|
38
|
-
"@blocklet/env": "1.16.
|
|
39
|
-
"@blocklet/meta": "1.16.
|
|
37
|
+
"@blocklet/constant": "1.16.35-beta-20241220-110602-f7ee8cba",
|
|
38
|
+
"@blocklet/env": "1.16.35-beta-20241220-110602-f7ee8cba",
|
|
39
|
+
"@blocklet/meta": "1.16.35-beta-20241220-110602-f7ee8cba",
|
|
40
40
|
"@did-connect/authenticator": "^2.2.4",
|
|
41
41
|
"@did-connect/handler": "^2.2.4",
|
|
42
42
|
"@nedb/core": "^2.1.5",
|
|
@@ -81,5 +81,5 @@
|
|
|
81
81
|
"ts-node": "^10.9.1",
|
|
82
82
|
"typescript": "^5.6.3"
|
|
83
83
|
},
|
|
84
|
-
"gitHead": "
|
|
84
|
+
"gitHead": "c2b7351da906ccb19cad15a5229196803df5c2ce"
|
|
85
85
|
}
|