@blocklet/sdk 1.16.54-beta-20251017-133309-7d40faa6 → 1.16.54-beta-20251021-070951-25e3083c
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.js +5 -5
- package/lib/connect/authenticator.d.ts +1 -1
- package/lib/connect/authenticator.js +9 -11
- package/lib/connect/handler.d.ts +1 -1
- package/lib/connect/handler.js +3 -1
- package/lib/connect/shared.d.ts +1 -1
- package/lib/connect/shared.js +17 -6
- package/lib/database/index.d.ts +2 -2
- package/lib/database/index.js +4 -2
- package/lib/did.d.ts +2 -2
- package/lib/did.js +4 -7
- package/lib/env.d.ts +2 -2
- package/lib/env.js +4 -5
- package/lib/index.d.ts +9 -9
- package/lib/index.js +18 -18
- package/lib/middlewares/auth.d.ts +3 -3
- package/lib/middlewares/auth.js +7 -8
- package/lib/middlewares/blocklet.d.ts +2 -2
- package/lib/middlewares/blocklet.js +2 -2
- package/lib/middlewares/csrf.js +2 -4
- package/lib/middlewares/fallback.d.ts +1 -1
- package/lib/middlewares/fallback.js +3 -1
- package/lib/middlewares/index.d.ts +5 -5
- package/lib/middlewares/index.js +15 -15
- package/lib/middlewares/session.d.ts +1 -1
- package/lib/middlewares/session.js +3 -1
- package/lib/middlewares/sitemap.d.ts +1 -1
- package/lib/middlewares/sitemap.js +3 -1
- package/lib/middlewares/user.d.ts +1 -1
- package/lib/middlewares/user.js +3 -1
- package/lib/security/index.d.ts +2 -2
- package/lib/security/index.js +3 -3
- package/lib/service/blocklet.d.ts +1 -1
- package/lib/service/blocklet.js +10 -9
- package/lib/service/eventbus.d.ts +2 -2
- package/lib/service/eventbus.js +5 -8
- package/lib/service/notification.d.ts +7 -6
- package/lib/service/notification.js +33 -29
- package/lib/service/signature.d.ts +21 -0
- package/lib/service/signature.js +78 -0
- package/lib/util/app-info.js +2 -2
- package/lib/util/check-blocklet-env.d.ts +1 -1
- package/lib/util/check-blocklet-env.js +4 -2
- package/lib/util/component-api.js +8 -4
- package/lib/util/csrf.d.ts +5 -0
- package/lib/util/csrf.js +9 -0
- package/lib/util/jest-setup.js +2 -2
- package/lib/util/jest-teardown.js +2 -2
- package/lib/util/send-notification.d.ts +13 -10
- package/lib/util/send-notification.js +42 -47
- package/lib/util/service-api.js +8 -4
- package/lib/util/verify-session.js +10 -7
- package/lib/util/verify-sign.d.ts +8 -7
- package/lib/util/verify-sign.js +11 -42
- package/lib/wallet-authenticator.d.ts +1 -1
- package/lib/wallet-authenticator.js +9 -10
- package/lib/wallet-handler.d.ts +1 -1
- package/lib/wallet-handler.js +3 -1
- package/lib/wallet.d.ts +31 -5
- package/lib/wallet.js +129 -29
- package/package.json +19 -18
package/lib/config.js
CHANGED
|
@@ -15,7 +15,7 @@ const debug_1 = __importDefault(require("debug"));
|
|
|
15
15
|
const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
|
|
16
16
|
const throttle_1 = __importDefault(require("lodash/throttle"));
|
|
17
17
|
const theme_1 = require("@blocklet/theme");
|
|
18
|
-
const env_1 =
|
|
18
|
+
const env_1 = require("@blocklet/env");
|
|
19
19
|
const constant_1 = require("@blocklet/constant");
|
|
20
20
|
const util_1 = require("@blocklet/env/lib/util");
|
|
21
21
|
const util_2 = require("@blocklet/meta/lib/util");
|
|
@@ -25,7 +25,7 @@ const notification_1 = __importDefault(require("./service/notification"));
|
|
|
25
25
|
const server_version_1 = __importDefault(require("./util/server-version"));
|
|
26
26
|
const parse_env_file_1 = require("./util/parse-env-file");
|
|
27
27
|
const parse_docker_endpoint_1 = require("./util/parse-docker-endpoint");
|
|
28
|
-
const blocklet_1 =
|
|
28
|
+
const blocklet_1 = require("./service/blocklet");
|
|
29
29
|
const debug = (0, debug_1.default)('@blocklet/sdk:config');
|
|
30
30
|
const events = new events_1.EventEmitter();
|
|
31
31
|
exports.events = events;
|
|
@@ -101,7 +101,7 @@ if (appDataDir) {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
const env = {
|
|
104
|
-
...env_1.
|
|
104
|
+
...env_1.blockletEnv,
|
|
105
105
|
...appEnvFromDisk,
|
|
106
106
|
...envFromDisk,
|
|
107
107
|
componentDid: process.env.BLOCKLET_COMPONENT_DID,
|
|
@@ -112,7 +112,7 @@ const env = {
|
|
|
112
112
|
sessionSalt: process.env.BLOCKLET_APP_SALT || '',
|
|
113
113
|
assetCdnHost: process.env.ASSET_CDN_HOST,
|
|
114
114
|
preferences: {
|
|
115
|
-
...env_1.
|
|
115
|
+
...env_1.blockletEnv.preferences,
|
|
116
116
|
...appEnvFromDisk.preferences,
|
|
117
117
|
...envFromDisk.preferences,
|
|
118
118
|
},
|
|
@@ -334,7 +334,7 @@ const fetchBlockletJs = async (type = 'js') => {
|
|
|
334
334
|
const fetchBlockletData = async () => {
|
|
335
335
|
try {
|
|
336
336
|
if (!blockletClient) {
|
|
337
|
-
blockletClient = new blocklet_1.
|
|
337
|
+
blockletClient = new blocklet_1.BlockletService();
|
|
338
338
|
}
|
|
339
339
|
const { blocklet } = await blockletClient.getBlocklet();
|
|
340
340
|
blockletSettings.federated = blocklet.settings?.federated;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BlockletAuthenticator = void 0;
|
|
5
4
|
const authenticator_1 = require("@did-connect/authenticator");
|
|
6
|
-
const wallet_1 =
|
|
7
|
-
const check_blocklet_env_1 =
|
|
5
|
+
const wallet_1 = require("../wallet");
|
|
6
|
+
const check_blocklet_env_1 = require("../util/check-blocklet-env");
|
|
8
7
|
const shared_1 = require("./shared");
|
|
9
|
-
const blocklet_1 =
|
|
8
|
+
const blocklet_1 = require("../service/blocklet");
|
|
10
9
|
class BlockletAuthenticator extends authenticator_1.Authenticator {
|
|
11
10
|
constructor(options = {}) {
|
|
12
|
-
(0, check_blocklet_env_1.
|
|
11
|
+
(0, check_blocklet_env_1.checkBlockletEnvironment)();
|
|
13
12
|
super({
|
|
14
|
-
|
|
15
|
-
wallet: (0, wallet_1.default)(),
|
|
13
|
+
wallet: (0, wallet_1.getWallet)(),
|
|
16
14
|
...(0, shared_1.getAuthenticatorProps)(options),
|
|
17
15
|
});
|
|
18
|
-
this.blockletClient = new blocklet_1.
|
|
16
|
+
this.blockletClient = new blocklet_1.BlockletService();
|
|
19
17
|
this.authClient = this.blockletClient;
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
|
-
|
|
20
|
+
exports.BlockletAuthenticator = BlockletAuthenticator;
|
package/lib/connect/handler.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
declare const createConnectHandlers: ({ authenticator, storage, logger, socketPathname, sendNotificationFn, }: $TSFixMe) => import("@did-connect/handler").THandlers;
|
|
2
|
-
export
|
|
2
|
+
export { createConnectHandlers };
|
package/lib/connect/handler.js
CHANGED
|
@@ -35,6 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
37
|
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.createConnectHandlers = void 0;
|
|
38
40
|
const get_1 = __importDefault(require("lodash/get"));
|
|
39
41
|
const handler_1 = require("@did-connect/handler");
|
|
40
42
|
const notification_1 = __importStar(require("../service/notification"));
|
|
@@ -96,4 +98,4 @@ const createConnectHandlers = ({ authenticator, storage, logger = config_1.defau
|
|
|
96
98
|
};
|
|
97
99
|
return handlers;
|
|
98
100
|
};
|
|
99
|
-
|
|
101
|
+
exports.createConnectHandlers = createConnectHandlers;
|
package/lib/connect/shared.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { WalletObject } from '@ocap/wallet';
|
|
2
2
|
declare const getDelegator: () => WalletObject<string>;
|
|
3
3
|
declare const getDelegatee: () => WalletObject<string>;
|
|
4
|
-
declare const getDelegation: (delegator: WalletObject, delegatee: WalletObject) => string
|
|
4
|
+
declare const getDelegation: (delegator: WalletObject, delegatee: WalletObject) => Promise<string>;
|
|
5
5
|
declare const getAuthenticatorProps: (options?: {}) => {
|
|
6
6
|
appInfo(...args: any[]): Promise<any>;
|
|
7
7
|
memberAppInfo({ request, baseUrl }: {
|
package/lib/connect/shared.js
CHANGED
|
@@ -9,7 +9,7 @@ const util_1 = require("@blocklet/meta/lib/util");
|
|
|
9
9
|
const wallet_1 = require("@ocap/wallet");
|
|
10
10
|
const mcrypto_1 = require("@ocap/mcrypto");
|
|
11
11
|
const get_1 = __importDefault(require("lodash/get"));
|
|
12
|
-
const wallet_2 =
|
|
12
|
+
const wallet_2 = require("../wallet");
|
|
13
13
|
const login_1 = require("../util/login");
|
|
14
14
|
const app_info_1 = require("../util/app-info");
|
|
15
15
|
// 为了避免循环依赖,暂时将 @abtnode/auth 中必要的方法复制过来
|
|
@@ -28,7 +28,7 @@ const getDelegator = () => {
|
|
|
28
28
|
// BLOCKLET_WALLET_TYPE is for backward compatibility
|
|
29
29
|
const { BLOCKLET_APP_SK, BLOCKLET_APP_PSK, BLOCKLET_WALLET_TYPE, CHAIN_TYPE } = process.env;
|
|
30
30
|
if (BLOCKLET_APP_SK && BLOCKLET_APP_PSK && BLOCKLET_APP_SK !== BLOCKLET_APP_PSK) {
|
|
31
|
-
return (0, wallet_2.
|
|
31
|
+
return (0, wallet_2.getWallet)(CHAIN_TYPE || BLOCKLET_WALLET_TYPE, BLOCKLET_APP_PSK);
|
|
32
32
|
}
|
|
33
33
|
return null;
|
|
34
34
|
};
|
|
@@ -36,11 +36,11 @@ exports.getDelegator = getDelegator;
|
|
|
36
36
|
const getDelegatee = () => {
|
|
37
37
|
// BLOCKLET_WALLET_TYPE is for backward compatibility
|
|
38
38
|
const { BLOCKLET_APP_SK, BLOCKLET_WALLET_TYPE, CHAIN_TYPE } = process.env;
|
|
39
|
-
return (0, wallet_2.
|
|
39
|
+
return (0, wallet_2.getWallet)(CHAIN_TYPE || BLOCKLET_WALLET_TYPE, BLOCKLET_APP_SK);
|
|
40
40
|
};
|
|
41
41
|
exports.getDelegatee = getDelegatee;
|
|
42
|
-
const getDelegation = (delegator, delegatee) => {
|
|
43
|
-
|
|
42
|
+
const getDelegation = async (delegator, delegatee) => {
|
|
43
|
+
const payload = {
|
|
44
44
|
agentDid: `did:abt:${delegatee.address}`,
|
|
45
45
|
permissions: [
|
|
46
46
|
{
|
|
@@ -60,7 +60,18 @@ const getDelegation = (delegator, delegatee) => {
|
|
|
60
60
|
},
|
|
61
61
|
],
|
|
62
62
|
exp: Math.floor(new Date().getTime() / 1000) + 60 * 60, // valid for 1 hour
|
|
63
|
-
}
|
|
63
|
+
};
|
|
64
|
+
if (delegator.secretKey) {
|
|
65
|
+
const token = await (0, jwt_1.signV2)(delegator.address, delegator.secretKey, payload);
|
|
66
|
+
return token;
|
|
67
|
+
}
|
|
68
|
+
// Remote signing mode
|
|
69
|
+
if (typeof delegator.signJWT === 'function') {
|
|
70
|
+
// Match signV2 behavior: doSign=true, version='1.1.0'
|
|
71
|
+
const token = await delegator.signJWT(payload, true, '1.1.0');
|
|
72
|
+
return token;
|
|
73
|
+
}
|
|
74
|
+
throw new Error('Delegator wallet does not support signing (no secretKey or signJWT method available)');
|
|
64
75
|
};
|
|
65
76
|
exports.getDelegation = getDelegation;
|
|
66
77
|
const getAuthenticatorProps = (options = {}) => ({
|
package/lib/database/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AnyObject, DataStore as BaseStore, DataStoreOptions, FilterQuery, ProjectionQuery, SortQuery } from '@nedb/core';
|
|
2
|
-
declare class
|
|
2
|
+
declare class Database<T = AnyObject> extends BaseStore<T> {
|
|
3
3
|
constructor(name: string, options?: DataStoreOptions);
|
|
4
4
|
exists(query: FilterQuery<T>): Promise<boolean>;
|
|
5
5
|
paginate({ condition, sort, page, size, projection, }: {
|
|
@@ -10,4 +10,4 @@ declare class DataBase<T = AnyObject> extends BaseStore<T> {
|
|
|
10
10
|
projection?: ProjectionQuery<T>;
|
|
11
11
|
}): PromiseLike<import("@nedb/core").Row<T>[]>;
|
|
12
12
|
}
|
|
13
|
-
export
|
|
13
|
+
export { Database };
|
package/lib/database/index.js
CHANGED
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Database = void 0;
|
|
5
7
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
6
8
|
const path_1 = __importDefault(require("path"));
|
|
7
9
|
const core_1 = require("@nedb/core");
|
|
8
|
-
class
|
|
10
|
+
class Database extends core_1.DataStore {
|
|
9
11
|
constructor(name, options = {}) {
|
|
10
12
|
if (!process.env.BLOCKLET_DATA_DIR) {
|
|
11
13
|
throw new Error('Blocklet SDK must be used in blocklet runtime');
|
|
@@ -43,4 +45,4 @@ class DataBase extends core_1.DataStore {
|
|
|
43
45
|
.exec();
|
|
44
46
|
}
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
exports.Database = Database;
|
package/lib/did.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import toBlockletDid from '@blocklet/meta/lib/did';
|
|
1
|
+
import { toBlockletDid } from '@blocklet/meta/lib/did';
|
|
2
2
|
import { getConnectedAccounts, getConnectedDids, getPermanentDid, getWallet, getWalletDid } from '@blocklet/meta/lib/did-utils';
|
|
3
|
-
import BlockletService from './service/blocklet';
|
|
3
|
+
import { BlockletService } from './service/blocklet';
|
|
4
4
|
declare function getUserInfo(userDid: string, { blockletClient, authClient, }?: {
|
|
5
5
|
blockletClient?: BlockletService;
|
|
6
6
|
/** @deprecated Use blockletClient instead */
|
package/lib/did.js
CHANGED
|
@@ -1,21 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getWalletDid = exports.getWallet = exports.getPermanentDid = exports.getConnectedDids = exports.getConnectedAccounts = exports.toBlockletDid = void 0;
|
|
7
4
|
exports.getUserInfo = getUserInfo;
|
|
8
|
-
const did_1 =
|
|
9
|
-
exports
|
|
5
|
+
const did_1 = require("@blocklet/meta/lib/did");
|
|
6
|
+
Object.defineProperty(exports, "toBlockletDid", { enumerable: true, get: function () { return did_1.toBlockletDid; } });
|
|
10
7
|
const did_utils_1 = require("@blocklet/meta/lib/did-utils");
|
|
11
8
|
Object.defineProperty(exports, "getConnectedAccounts", { enumerable: true, get: function () { return did_utils_1.getConnectedAccounts; } });
|
|
12
9
|
Object.defineProperty(exports, "getConnectedDids", { enumerable: true, get: function () { return did_utils_1.getConnectedDids; } });
|
|
13
10
|
Object.defineProperty(exports, "getPermanentDid", { enumerable: true, get: function () { return did_utils_1.getPermanentDid; } });
|
|
14
11
|
Object.defineProperty(exports, "getWallet", { enumerable: true, get: function () { return did_utils_1.getWallet; } });
|
|
15
12
|
Object.defineProperty(exports, "getWalletDid", { enumerable: true, get: function () { return did_utils_1.getWalletDid; } });
|
|
16
|
-
const blocklet_1 =
|
|
13
|
+
const blocklet_1 = require("./service/blocklet");
|
|
17
14
|
async function getUserInfo(userDid, { blockletClient = undefined, authClient = undefined, } = {}) {
|
|
18
|
-
const client = blockletClient || authClient || new blocklet_1.
|
|
15
|
+
const client = blockletClient || authClient || new blocklet_1.BlockletService();
|
|
19
16
|
const { user } = await client.getUser(userDid, {
|
|
20
17
|
enableConnectedAccount: true,
|
|
21
18
|
});
|
package/lib/env.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import env from '@blocklet/env';
|
|
2
|
-
export
|
|
1
|
+
import { blockletEnv as env } from '@blocklet/env';
|
|
2
|
+
export { env };
|
package/lib/env.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
module.exports = env_1.default;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.env = void 0;
|
|
4
|
+
const env_1 = require("@blocklet/env");
|
|
5
|
+
Object.defineProperty(exports, "env", { enumerable: true, get: function () { return env_1.blockletEnv; } });
|
package/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { TTheme, type TNavigationItem } from '@blocklet/meta/lib/types';
|
|
2
|
-
import
|
|
3
|
-
import BlockletService from './service/blocklet';
|
|
2
|
+
import { blockletEnv } from '@blocklet/env';
|
|
3
|
+
import { BlockletService } from './service/blocklet';
|
|
4
4
|
import Notification from './service/notification';
|
|
5
|
-
import WalletAuthenticator from './wallet-authenticator';
|
|
6
|
-
import WalletHandlers from './wallet-handler';
|
|
7
|
-
import BlockletAuthenticator from './connect/authenticator';
|
|
8
|
-
import createConnectHandlers from './connect/handler';
|
|
9
|
-
import Database from './database/index';
|
|
5
|
+
import { WalletAuthenticator } from './wallet-authenticator';
|
|
6
|
+
import { WalletHandlers } from './wallet-handler';
|
|
7
|
+
import { BlockletAuthenticator } from './connect/authenticator';
|
|
8
|
+
import { createConnectHandlers } from './connect/handler';
|
|
9
|
+
import { Database } from './database/index';
|
|
10
10
|
import middlewares from './middlewares/index';
|
|
11
|
-
import getWallet from './wallet';
|
|
11
|
+
import { getWallet } from './wallet';
|
|
12
12
|
import Component from './component/index';
|
|
13
13
|
import Security from './security/index';
|
|
14
14
|
import config, { TComponent } from './config';
|
|
@@ -25,7 +25,7 @@ export { BlockletAuthenticator };
|
|
|
25
25
|
export { createConnectHandlers };
|
|
26
26
|
export { Database };
|
|
27
27
|
export { getWallet };
|
|
28
|
-
export { env };
|
|
28
|
+
export { blockletEnv as env };
|
|
29
29
|
export { middlewares };
|
|
30
30
|
export { Component as component };
|
|
31
31
|
export { Component };
|
package/lib/index.js
CHANGED
|
@@ -18,29 +18,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.config = exports.Security = exports.Component = exports.component = exports.middlewares = exports.env = exports.getWallet = exports.Database = exports.createConnectHandlers = exports.BlockletAuthenticator = exports.WalletAuthenticator = exports.WalletHandlers = exports.Notification = exports.NotificationService = exports.BlockletService = exports.Auth = exports.AuthService = void 0;
|
|
21
|
-
const env_1 =
|
|
22
|
-
exports
|
|
23
|
-
const blocklet_1 =
|
|
24
|
-
exports
|
|
25
|
-
exports
|
|
26
|
-
exports
|
|
21
|
+
const env_1 = require("@blocklet/env");
|
|
22
|
+
Object.defineProperty(exports, "env", { enumerable: true, get: function () { return env_1.blockletEnv; } });
|
|
23
|
+
const blocklet_1 = require("./service/blocklet");
|
|
24
|
+
Object.defineProperty(exports, "AuthService", { enumerable: true, get: function () { return blocklet_1.BlockletService; } });
|
|
25
|
+
Object.defineProperty(exports, "Auth", { enumerable: true, get: function () { return blocklet_1.BlockletService; } });
|
|
26
|
+
Object.defineProperty(exports, "BlockletService", { enumerable: true, get: function () { return blocklet_1.BlockletService; } });
|
|
27
27
|
const notification_1 = __importDefault(require("./service/notification"));
|
|
28
28
|
exports.NotificationService = notification_1.default;
|
|
29
29
|
exports.Notification = notification_1.default;
|
|
30
|
-
const wallet_authenticator_1 =
|
|
31
|
-
exports
|
|
32
|
-
const wallet_handler_1 =
|
|
33
|
-
exports
|
|
34
|
-
const authenticator_1 =
|
|
35
|
-
exports
|
|
36
|
-
const handler_1 =
|
|
37
|
-
exports
|
|
38
|
-
const index_1 =
|
|
39
|
-
exports
|
|
30
|
+
const wallet_authenticator_1 = require("./wallet-authenticator");
|
|
31
|
+
Object.defineProperty(exports, "WalletAuthenticator", { enumerable: true, get: function () { return wallet_authenticator_1.WalletAuthenticator; } });
|
|
32
|
+
const wallet_handler_1 = require("./wallet-handler");
|
|
33
|
+
Object.defineProperty(exports, "WalletHandlers", { enumerable: true, get: function () { return wallet_handler_1.WalletHandlers; } });
|
|
34
|
+
const authenticator_1 = require("./connect/authenticator");
|
|
35
|
+
Object.defineProperty(exports, "BlockletAuthenticator", { enumerable: true, get: function () { return authenticator_1.BlockletAuthenticator; } });
|
|
36
|
+
const handler_1 = require("./connect/handler");
|
|
37
|
+
Object.defineProperty(exports, "createConnectHandlers", { enumerable: true, get: function () { return handler_1.createConnectHandlers; } });
|
|
38
|
+
const index_1 = require("./database/index");
|
|
39
|
+
Object.defineProperty(exports, "Database", { enumerable: true, get: function () { return index_1.Database; } });
|
|
40
40
|
const index_2 = __importDefault(require("./middlewares/index"));
|
|
41
41
|
exports.middlewares = index_2.default;
|
|
42
|
-
const wallet_1 =
|
|
43
|
-
exports
|
|
42
|
+
const wallet_1 = require("./wallet");
|
|
43
|
+
Object.defineProperty(exports, "getWallet", { enumerable: true, get: function () { return wallet_1.getWallet; } });
|
|
44
44
|
const index_3 = __importDefault(require("./component/index"));
|
|
45
45
|
exports.component = index_3.default;
|
|
46
46
|
exports.Component = index_3.default;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import BlockletService from '../service/blocklet';
|
|
2
|
+
import { BlockletService } from '../service/blocklet';
|
|
3
3
|
import { SessionUser, AuthMethod, KycMethod } from '../util/login';
|
|
4
4
|
type AuthOptions = {
|
|
5
5
|
roles?: string[];
|
|
@@ -8,10 +8,10 @@ type AuthOptions = {
|
|
|
8
8
|
methods?: AuthMethod[];
|
|
9
9
|
getClient?: Function;
|
|
10
10
|
};
|
|
11
|
-
declare const
|
|
11
|
+
declare const authMiddleware: {
|
|
12
12
|
({ roles, permissions, kyc, methods, getClient }?: AuthOptions): (req: Request & {
|
|
13
13
|
user?: SessionUser;
|
|
14
14
|
}, res: Response, next: NextFunction) => Promise<void>;
|
|
15
15
|
getServiceClient: () => BlockletService;
|
|
16
16
|
};
|
|
17
|
-
export
|
|
17
|
+
export { authMiddleware };
|
package/lib/middlewares/auth.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.authMiddleware = void 0;
|
|
5
4
|
const lru_cache_1 = require("lru-cache");
|
|
6
|
-
const blocklet_1 =
|
|
5
|
+
const blocklet_1 = require("../service/blocklet");
|
|
7
6
|
const login_1 = require("../util/login");
|
|
8
7
|
const clients = {};
|
|
9
8
|
const getServiceClient = () => {
|
|
10
9
|
const appId = process.env.BLOCKLET_APP_ID;
|
|
11
10
|
if (!clients[appId]) {
|
|
12
|
-
clients[appId] = new blocklet_1.
|
|
11
|
+
clients[appId] = new blocklet_1.BlockletService();
|
|
13
12
|
}
|
|
14
13
|
return clients[appId];
|
|
15
14
|
};
|
|
@@ -26,7 +25,7 @@ const getPermissionsByRole = async (getClient, role) => {
|
|
|
26
25
|
cache.set(role, res);
|
|
27
26
|
return res;
|
|
28
27
|
};
|
|
29
|
-
const
|
|
28
|
+
const authMiddleware = ({ roles, permissions, kyc, methods, getClient = getServiceClient } = {}) => {
|
|
30
29
|
if (roles && !Array.isArray(roles)) {
|
|
31
30
|
throw new Error('roles must be array');
|
|
32
31
|
}
|
|
@@ -75,5 +74,5 @@ const AuthMiddleware = ({ roles, permissions, kyc, methods, getClient = getServi
|
|
|
75
74
|
next();
|
|
76
75
|
};
|
|
77
76
|
};
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
exports.authMiddleware = authMiddleware;
|
|
78
|
+
authMiddleware.getServiceClient = getServiceClient;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { NextFunction, Request, Response } from 'express';
|
|
2
|
-
declare const verifyBlockletSig: (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any
|
|
2
|
+
declare const verifyBlockletSig: (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
3
3
|
export { verifyBlockletSig };
|
|
4
4
|
declare const _default: {
|
|
5
|
-
verifyBlockletSig: (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any
|
|
5
|
+
verifyBlockletSig: (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
|
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.verifyBlockletSig = void 0;
|
|
7
7
|
const config_1 = __importDefault(require("../config"));
|
|
8
8
|
const verify_sign_1 = require("../util/verify-sign");
|
|
9
|
-
const verifyBlockletSig = (req, res, next) => {
|
|
9
|
+
const verifyBlockletSig = async (req, res, next) => {
|
|
10
10
|
try {
|
|
11
11
|
const { data, sig } = (0, verify_sign_1.getVerifyData)(req, 'blocklet');
|
|
12
12
|
if (!sig) {
|
|
13
13
|
return res.status(400).json({ error: 'Bad Request' });
|
|
14
14
|
}
|
|
15
|
-
const verified = (0, verify_sign_1.verify)(data, sig);
|
|
15
|
+
const verified = await (0, verify_sign_1.verify)(data, sig);
|
|
16
16
|
if (!verified) {
|
|
17
17
|
config_1.default.logger.error('verify blocklet sig failed', { data, sig });
|
|
18
18
|
return res.status(401).json({ error: 'verify sig failed' });
|
package/lib/middlewares/csrf.js
CHANGED
|
@@ -9,8 +9,6 @@ const joi_1 = __importDefault(require("joi"));
|
|
|
9
9
|
const csrf_1 = require("../util/csrf");
|
|
10
10
|
const wallet_1 = require("../util/wallet");
|
|
11
11
|
const config_1 = __importDefault(require("../config"));
|
|
12
|
-
const wallet_2 = __importDefault(require("../wallet"));
|
|
13
|
-
const wallet = (0, wallet_2.default)();
|
|
14
12
|
function printCookieParserNotInstalledWarning() {
|
|
15
13
|
config_1.default.logger.warn('cookie-parser middleware is required for the csrf middleware to work properly.');
|
|
16
14
|
}
|
|
@@ -28,7 +26,7 @@ function defaultGenerateToken(req, res) {
|
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
30
28
|
if (req.cookies.login_token) {
|
|
31
|
-
const newCsrfToken = (0, csrf_1.sign)(
|
|
29
|
+
const newCsrfToken = (0, csrf_1.sign)((0, csrf_1.getCsrfSecret)(), req.cookies.login_token);
|
|
32
30
|
const oldCsrfToken = req.cookies['x-csrf-token'];
|
|
33
31
|
if (newCsrfToken !== oldCsrfToken) {
|
|
34
32
|
res.cookie('x-csrf-token', newCsrfToken, {
|
|
@@ -48,7 +46,7 @@ function defaultVerifyToken(req) {
|
|
|
48
46
|
}
|
|
49
47
|
if (!(0, isEmpty_1.default)(req.cookies['x-csrf-token']) && req.cookies['x-csrf-token'] === req.headers['x-csrf-token']) {
|
|
50
48
|
const csrfTokenFromRequest = req.cookies['x-csrf-token'];
|
|
51
|
-
if ((0, csrf_1.verify)(
|
|
49
|
+
if ((0, csrf_1.verify)((0, csrf_1.getCsrfSecret)(), csrfTokenFromRequest, req.cookies.login_token)) {
|
|
52
50
|
return;
|
|
53
51
|
}
|
|
54
52
|
config_1.default.logger.warn('Invalid request: csrf token mismatch', {
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fallback = void 0;
|
|
5
7
|
const fs_1 = __importDefault(require("fs"));
|
|
6
8
|
const path_1 = require("path");
|
|
7
9
|
const ufo_1 = require("ufo");
|
|
@@ -178,4 +180,4 @@ const fallback = (file, options = {}) => {
|
|
|
178
180
|
}
|
|
179
181
|
};
|
|
180
182
|
};
|
|
181
|
-
|
|
183
|
+
exports.fallback = fallback;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import user from './user';
|
|
2
|
-
import auth from './auth';
|
|
1
|
+
import { userMiddleware as user } from './user';
|
|
2
|
+
import { authMiddleware as auth } from './auth';
|
|
3
3
|
import component from './component';
|
|
4
|
-
import fallback from './fallback';
|
|
5
|
-
import sitemap from './sitemap';
|
|
6
|
-
import session from './session';
|
|
4
|
+
import { fallback } from './fallback';
|
|
5
|
+
import { sitemap } from './sitemap';
|
|
6
|
+
import { sessionMiddleware as session } from './session';
|
|
7
7
|
import { csrf } from './csrf';
|
|
8
8
|
export { user, auth, component, fallback, sitemap, csrf, session };
|
|
9
9
|
declare const _default: {
|
package/lib/middlewares/index.js
CHANGED
|
@@ -4,28 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.session = exports.csrf = exports.sitemap = exports.fallback = exports.component = exports.auth = exports.user = void 0;
|
|
7
|
-
const user_1 =
|
|
8
|
-
exports
|
|
9
|
-
const auth_1 =
|
|
10
|
-
exports
|
|
7
|
+
const user_1 = require("./user");
|
|
8
|
+
Object.defineProperty(exports, "user", { enumerable: true, get: function () { return user_1.userMiddleware; } });
|
|
9
|
+
const auth_1 = require("./auth");
|
|
10
|
+
Object.defineProperty(exports, "auth", { enumerable: true, get: function () { return auth_1.authMiddleware; } });
|
|
11
11
|
const component_1 = __importDefault(require("./component"));
|
|
12
12
|
exports.component = component_1.default;
|
|
13
|
-
const fallback_1 =
|
|
14
|
-
exports
|
|
15
|
-
const sitemap_1 =
|
|
16
|
-
exports
|
|
17
|
-
const session_1 =
|
|
18
|
-
exports
|
|
13
|
+
const fallback_1 = require("./fallback");
|
|
14
|
+
Object.defineProperty(exports, "fallback", { enumerable: true, get: function () { return fallback_1.fallback; } });
|
|
15
|
+
const sitemap_1 = require("./sitemap");
|
|
16
|
+
Object.defineProperty(exports, "sitemap", { enumerable: true, get: function () { return sitemap_1.sitemap; } });
|
|
17
|
+
const session_1 = require("./session");
|
|
18
|
+
Object.defineProperty(exports, "session", { enumerable: true, get: function () { return session_1.sessionMiddleware; } });
|
|
19
19
|
const csrf_1 = require("./csrf");
|
|
20
20
|
Object.defineProperty(exports, "csrf", { enumerable: true, get: function () { return csrf_1.csrf; } });
|
|
21
21
|
const cdn_1 = require("./cdn");
|
|
22
22
|
exports.default = {
|
|
23
|
-
user: user_1.
|
|
24
|
-
auth: auth_1.
|
|
23
|
+
user: user_1.userMiddleware,
|
|
24
|
+
auth: auth_1.authMiddleware,
|
|
25
25
|
component: component_1.default,
|
|
26
|
-
fallback: fallback_1.
|
|
27
|
-
sitemap: sitemap_1.
|
|
26
|
+
fallback: fallback_1.fallback,
|
|
27
|
+
sitemap: sitemap_1.sitemap,
|
|
28
28
|
csrf: csrf_1.csrf,
|
|
29
|
-
session: session_1.
|
|
29
|
+
session: session_1.sessionMiddleware,
|
|
30
30
|
cdn: cdn_1.cdn,
|
|
31
31
|
};
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.sessionMiddleware = void 0;
|
|
5
7
|
const get_token_from_req_1 = require("@abtnode/util/lib/get-token-from-req");
|
|
6
8
|
const service_api_1 = __importDefault(require("../util/service-api"));
|
|
7
9
|
const login_1 = require("../util/login");
|
|
@@ -70,4 +72,4 @@ const sessionMiddleware = (options = {}) => {
|
|
|
70
72
|
next();
|
|
71
73
|
};
|
|
72
74
|
};
|
|
73
|
-
|
|
75
|
+
exports.sessionMiddleware = sessionMiddleware;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sitemap = void 0;
|
|
2
4
|
const sitemap_1 = require("sitemap");
|
|
3
5
|
const error_1 = require("@blocklet/error");
|
|
4
6
|
const config_1 = require("../config");
|
|
@@ -18,4 +20,4 @@ const sitemap = (generatorFn) => {
|
|
|
18
20
|
}
|
|
19
21
|
};
|
|
20
22
|
};
|
|
21
|
-
|
|
23
|
+
exports.sitemap = sitemap;
|
package/lib/middlewares/user.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.userMiddleware = void 0;
|
|
2
4
|
const util_1 = require("util");
|
|
3
5
|
const login_1 = require("../util/login");
|
|
4
6
|
const userMiddleware = (0, util_1.deprecate)(() => (req, res, next) => {
|
|
@@ -14,4 +16,4 @@ const userMiddleware = (0, util_1.deprecate)(() => (req, res, next) => {
|
|
|
14
16
|
}
|
|
15
17
|
next();
|
|
16
18
|
}, 'user middleware is deprecated, please use session middleware for better security');
|
|
17
|
-
|
|
19
|
+
exports.userMiddleware = userMiddleware;
|
package/lib/security/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
declare const encrypt: (message: string, password?: string, salt?: string) => string;
|
|
2
2
|
declare const decrypt: (message: string, password?: string, salt?: string) => string;
|
|
3
|
-
declare const signResponse: (data: any) => any
|
|
3
|
+
declare const signResponse: (data: any) => Promise<any>;
|
|
4
4
|
declare const verifyResponse: (data: any) => Promise<boolean>;
|
|
5
5
|
export { encrypt };
|
|
6
6
|
export { decrypt };
|
|
@@ -8,7 +8,7 @@ export { signResponse, verifyResponse };
|
|
|
8
8
|
declare const _default: {
|
|
9
9
|
encrypt: (message: string, password?: string, salt?: string) => string;
|
|
10
10
|
decrypt: (message: string, password?: string, salt?: string) => string;
|
|
11
|
-
signResponse: (data: any) => any
|
|
11
|
+
signResponse: (data: any) => Promise<any>;
|
|
12
12
|
verifyResponse: (data: any) => Promise<boolean>;
|
|
13
13
|
};
|
|
14
14
|
export default _default;
|