@blocklet/sdk 1.16.37-beta-20250104-120451-e4049aeb → 1.16.37-beta-20250107-235521-f1778ec0

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/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2018-2020 ArcBlock
1
+ Copyright 2018-2025 ArcBlock
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
@@ -11,6 +11,7 @@ class BlockletAuthenticator extends authenticator_1.Authenticator {
11
11
  constructor(options = {}) {
12
12
  (0, check_blocklet_env_1.default)();
13
13
  super({
14
+ // @ts-ignore
14
15
  wallet: (0, wallet_1.default)(),
15
16
  ...(0, shared_1.getAuthenticatorProps)(options),
16
17
  });
@@ -1,7 +1,7 @@
1
1
  import type { NextFunction, Request, Response } from 'express';
2
- declare const verifySig: (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
2
+ declare const verifySig: (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
3
3
  export { verifySig };
4
4
  declare const _default: {
5
- verifySig: (req: Request, res: Response, next: NextFunction) => void | Response<any, Record<string, any>>;
5
+ verifySig: (req: Request, res: Response, next: NextFunction) => Promise<void | Response<any, Record<string, any>>>;
6
6
  };
7
7
  export default _default;
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.verifySig = void 0;
4
4
  const config_1 = require("../config");
5
5
  const verify_sign_1 = require("../util/verify-sign");
6
- const verifySig = (req, res, next) => {
6
+ const verifySig = async (req, res, next) => {
7
7
  try {
8
8
  const { data, sig } = (0, verify_sign_1.getVerifyData)(req, 'component');
9
9
  if (!sig) {
10
10
  return res.status(400).json({ error: 'Bad Request' });
11
11
  }
12
- const verified = (0, verify_sign_1.verify)(data, sig);
12
+ const verified = await (0, verify_sign_1.verify)(data, sig);
13
13
  if (!verified) {
14
14
  config_1.logger.error('verify component sig failed', { data, sig });
15
15
  return res.status(401).json({ error: 'verify sig failed' });
@@ -20,7 +20,7 @@ declare const _default: {
20
20
  user?: import("../util/login").SessionUser;
21
21
  }, res: import("express").Response, next: import("express").NextFunction) => Promise<void>;
22
22
  component: {
23
- verifySig: (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction) => void | import("express").Response<any, Record<string, any>>;
23
+ verifySig: (req: import("express").Request, res: import("express").Response, next: import("express").NextFunction) => Promise<void | import("express").Response<any, Record<string, any>>>;
24
24
  };
25
25
  fallback: (file: string, options?: {
26
26
  root?: string | undefined;
@@ -21,12 +21,12 @@ const sessionMiddleware = (options = {}) => {
21
21
  }
22
22
  // authenticate by component call
23
23
  if (!result && componentCall) {
24
- result = (0, verify_session_1.verifyComponentCall)({ req, strictMode });
24
+ result = await (0, verify_session_1.verifyComponentCall)({ req, strictMode });
25
25
  }
26
26
  // authenticate by signed tmp token: which expires in 5 minutes
27
27
  if (!result && signedToken) {
28
28
  const token = req.query.__jwt || '';
29
- result = (0, verify_session_1.verifySignedToken)({ token, strictMode });
29
+ result = await (0, verify_session_1.verifySignedToken)({ token, strictMode });
30
30
  }
31
31
  }
32
32
  catch (err) {
@@ -1,7 +1,7 @@
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
3
  declare const signResponse: (data: any) => any;
4
- declare const verifyResponse: (data: any) => boolean;
4
+ declare const verifyResponse: (data: any) => Promise<boolean>;
5
5
  export { encrypt };
6
6
  export { decrypt };
7
7
  export { signResponse, verifyResponse };
@@ -9,6 +9,6 @@ declare const _default: {
9
9
  encrypt: (message: string, password?: string, salt?: string) => string;
10
10
  decrypt: (message: string, password?: string, salt?: string) => string;
11
11
  signResponse: (data: any) => any;
12
- verifyResponse: (data: any) => boolean;
12
+ verifyResponse: (data: any) => Promise<boolean>;
13
13
  };
14
14
  export default _default;
@@ -8,26 +8,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
8
8
  const pickBy_1 = __importDefault(require("lodash/pickBy"));
9
9
  const ufo_1 = require("ufo");
10
10
  const client_1 = __importDefault(require("@abtnode/client"));
11
- const semver_1 = __importDefault(require("semver"));
12
- const mcrypto_1 = require("@ocap/mcrypto");
13
- const wallet_1 = require("@ocap/wallet");
14
- const env_1 = require("@blocklet/env");
15
11
  const constant_1 = __importDefault(require("@abtnode/constant"));
12
+ const util_1 = require("@ocap/util");
16
13
  const constant_2 = require("@blocklet/constant");
17
- const util_1 = require("@blocklet/meta/lib/util");
14
+ const util_2 = require("@blocklet/meta/lib/util");
18
15
  const check_blocklet_env_1 = __importDefault(require("../util/check-blocklet-env"));
19
16
  const version_1 = require("../version");
20
- const wallet_2 = __importDefault(require("../wallet"));
17
+ const wallet_1 = __importDefault(require("../wallet"));
21
18
  const service_api_1 = __importDefault(require("../util/service-api"));
22
19
  const parse_docker_endpoint_1 = require("../util/parse-docker-endpoint");
23
20
  const { WELLKNOWN_SERVICE_PATH_PREFIX, USER_AVATAR_URL_PREFIX, USER_AVATAR_PATH_PREFIX } = constant_1.default;
24
21
  const VERSION = version_1.version; // version of notification sdk
25
22
  const isNotNullOrUndefined = (x) => ![null, undefined].includes(x);
26
- // BLOCKLET_WALLET_TYPE is for backward compatibility
27
- const chainType = process.env.CHAIN_TYPE || process.env.BLOCKLET_WALLET_TYPE;
28
- const type = chainType !== 'ethereum' && chainType !== 'eth'
29
- ? (0, wallet_1.WalletType)({ role: mcrypto_1.types.RoleType.ROLE_APPLICATION, pk: mcrypto_1.types.KeyType.ED25519, hash: mcrypto_1.types.HashType.SHA3 })
30
- : 'eth';
31
23
  const fixAvatar = (user) => {
32
24
  const avatar = user?.avatar;
33
25
  if (avatar && avatar.startsWith(USER_AVATAR_URL_PREFIX)) {
@@ -35,18 +27,16 @@ const fixAvatar = (user) => {
35
27
  }
36
28
  return user;
37
29
  };
38
- const toBuffer = (str) => (str.startsWith('0x') ? Buffer.from(str.slice(2), 'hex') : str);
39
30
  class AuthClient extends client_1.default {
40
31
  constructor(httpEndpoint) {
41
32
  (0, check_blocklet_env_1.default)();
42
33
  super(httpEndpoint || `http://${(0, parse_docker_endpoint_1.getServerHost)()}:${process.env.ABT_NODE_PORT}/api/gql`.trim(), `BlockletSDK/${VERSION}`);
43
- const wallet = (0, wallet_2.default)();
44
- const useNewSigner = !env_1.serverVersion || semver_1.default.gte(env_1.serverVersion, '1.16.7');
34
+ const wallet = (0, wallet_1.default)();
45
35
  this.setAuthAccessKey({
46
36
  accessKeyId: wallet.address,
47
37
  // for backward compatibility
48
- accessKeySecret: useNewSigner ? toBuffer(wallet.secretKey) : wallet.secretKey,
49
- type: useNewSigner ? 'sha256' : type,
38
+ accessKeySecret: (0, util_1.toBuffer)(wallet.secretKey),
39
+ type: 'sha256',
50
40
  });
51
41
  }
52
42
  _getAuthHeaders() {
@@ -200,7 +190,7 @@ class AuthService {
200
190
  };
201
191
  this.getComponent = async (did) => {
202
192
  const { blocklet } = await this.getBlocklet();
203
- return (0, util_1.findComponentByIdV2)(blocklet, did);
193
+ return (0, util_2.findComponentByIdV2)(blocklet, did);
204
194
  };
205
195
  // eslint-disable-next-line no-constructor-return
206
196
  return new Proxy(this, {
@@ -174,7 +174,7 @@ const initClient = () => {
174
174
  });
175
175
  [...Object.keys(constant_1.BlockletInternalEvents), ...Object.keys(constant_1.TeamEvents)].forEach((key) => {
176
176
  const event = constant_1.BlockletInternalEvents[key] || constant_1.TeamEvents[key];
177
- componentChannel.on(event, ({ status, response } = {}) => {
177
+ componentChannel.on(event, async ({ status, response } = {}) => {
178
178
  debug('componentChannel.on', { event, status, response });
179
179
  if (status === 'ok') {
180
180
  const { data, sender, time } = response;
@@ -183,7 +183,7 @@ const initClient = () => {
183
183
  }
184
184
  // verify sender is server
185
185
  const tolerance = 600;
186
- if (!Jwt.verify(sender.token, process.env.ABT_NODE_PK, { tolerance })) {
186
+ if (!(await Jwt.verify(sender.token, process.env.ABT_NODE_PK, { tolerance }))) {
187
187
  const message = `verify sender failed in internal events. event: ${event}, sender: ${JSON.stringify(sender)}`;
188
188
  emitError({ message });
189
189
  console.error(message);
@@ -7,8 +7,8 @@ export declare function verifyLoginToken({ token, strictMode }: {
7
7
  export declare function verifyComponentCall({ req, strictMode }: {
8
8
  req: any;
9
9
  strictMode: any;
10
- }): SessionUser | null;
10
+ }): Promise<SessionUser | null>;
11
11
  export declare function verifySignedToken({ token, strictMode }: {
12
12
  token: any;
13
13
  strictMode: any;
14
- }): SessionUser | null;
14
+ }): Promise<SessionUser | null>;
@@ -46,11 +46,11 @@ function verifyLoginToken({ token, strictMode }) {
46
46
  });
47
47
  });
48
48
  }
49
- function verifyComponentCall({ req, strictMode }) {
49
+ async function verifyComponentCall({ req, strictMode }) {
50
50
  const { sig, data } = (0, verify_sign_1.getVerifyData)(req);
51
51
  if (!sig)
52
52
  return null;
53
- if ((0, verify_sign_1.verify)(data, sig) === false) {
53
+ if ((await (0, verify_sign_1.verify)(data, sig)) === false) {
54
54
  if (strictMode) {
55
55
  throw new Error('Unauthorized: Invalid signature');
56
56
  }
@@ -67,10 +67,10 @@ function verifyComponentCall({ req, strictMode }) {
67
67
  method: 'componentCall',
68
68
  };
69
69
  }
70
- function verifySignedToken({ token, strictMode }) {
70
+ async function verifySignedToken({ token, strictMode }) {
71
71
  if (!token)
72
72
  return null;
73
- if ((0, jwt_1.verify)(token, (0, exports.getSessionSecret)()) === false) {
73
+ if (!(await (0, jwt_1.verify)(token, (0, exports.getSessionSecret)()))) {
74
74
  if (strictMode) {
75
75
  throw new Error('Unauthorized: Invalid signed token');
76
76
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.37-beta-20250104-120451-e4049aeb",
6
+ "version": "1.16.37-beta-20250107-235521-f1778ec0",
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,21 +27,22 @@
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.37-beta-20250104-120451-e4049aeb",
31
- "@abtnode/constant": "1.16.37-beta-20250104-120451-e4049aeb",
32
- "@abtnode/util": "1.16.37-beta-20250104-120451-e4049aeb",
33
- "@arcblock/did": "1.18.166",
34
- "@arcblock/did-auth": "1.18.166",
35
- "@arcblock/jwt": "1.18.166",
36
- "@arcblock/ws": "1.18.166",
37
- "@blocklet/constant": "1.16.37-beta-20250104-120451-e4049aeb",
38
- "@blocklet/env": "1.16.37-beta-20250104-120451-e4049aeb",
39
- "@blocklet/meta": "1.16.37-beta-20250104-120451-e4049aeb",
30
+ "@abtnode/client": "1.16.37-beta-20250107-235521-f1778ec0",
31
+ "@abtnode/constant": "1.16.37-beta-20250107-235521-f1778ec0",
32
+ "@abtnode/util": "1.16.37-beta-20250107-235521-f1778ec0",
33
+ "@arcblock/did": "1.19.1",
34
+ "@arcblock/did-auth": "1.19.1",
35
+ "@arcblock/jwt": "1.19.1",
36
+ "@arcblock/ws": "1.19.1",
37
+ "@blocklet/constant": "1.16.37-beta-20250107-235521-f1778ec0",
38
+ "@blocklet/env": "1.16.37-beta-20250107-235521-f1778ec0",
39
+ "@blocklet/meta": "1.16.37-beta-20250107-235521-f1778ec0",
40
40
  "@did-connect/authenticator": "^2.2.4",
41
41
  "@did-connect/handler": "^2.2.4",
42
42
  "@nedb/core": "^2.1.5",
43
- "@ocap/mcrypto": "1.18.166",
44
- "@ocap/wallet": "1.18.166",
43
+ "@ocap/mcrypto": "1.19.1",
44
+ "@ocap/util": "1.19.1",
45
+ "@ocap/wallet": "1.19.1",
45
46
  "axios": "^1.7.9",
46
47
  "cheerio": "1.0.0-rc.12",
47
48
  "debug": "^4.3.7",
@@ -81,5 +82,5 @@
81
82
  "ts-node": "^10.9.1",
82
83
  "typescript": "^5.6.3"
83
84
  },
84
- "gitHead": "b7b25187705d6a0ac07d3ff4ed3333bf7808120b"
85
+ "gitHead": "3a46e922782029700f45d7da9fd9535302d0594c"
85
86
  }