@blocklet/sdk 1.16.54-beta-20251024-030947-6f2889bf → 1.16.54-beta-20251028-073105-3ed10cef

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 CHANGED
@@ -11,15 +11,18 @@ declare const Events: {
11
11
  };
12
12
  declare let logger: {
13
13
  info: {
14
+ (...data: any[]): void;
14
15
  (...data: any[]): void;
15
16
  (message?: any, ...optionalParams: any[]): void;
16
17
  };
17
18
  debug: (...args: any[]) => void;
18
19
  warn: {
20
+ (...data: any[]): void;
19
21
  (...data: any[]): void;
20
22
  (message?: any, ...optionalParams: any[]): void;
21
23
  };
22
24
  error: {
25
+ (...data: any[]): void;
23
26
  (...data: any[]): void;
24
27
  (message?: any, ...optionalParams: any[]): void;
25
28
  };
@@ -94,15 +97,18 @@ TComponent, events, Events, getBlockletJs, _handleComponentUpdateOld, _handleApp
94
97
  declare const _default: {
95
98
  logger: {
96
99
  info: {
100
+ (...data: any[]): void;
97
101
  (...data: any[]): void;
98
102
  (message?: any, ...optionalParams: any[]): void;
99
103
  };
100
104
  debug: (...args: any[]) => void;
101
105
  warn: {
106
+ (...data: any[]): void;
102
107
  (...data: any[]): void;
103
108
  (message?: any, ...optionalParams: any[]): void;
104
109
  };
105
110
  error: {
111
+ (...data: any[]): void;
106
112
  (...data: any[]): void;
107
113
  (message?: any, ...optionalParams: any[]): void;
108
114
  };
@@ -77,9 +77,10 @@ class BlockletClient extends server_js_1.default {
77
77
  }
78
78
  async _getAuthHeaders() {
79
79
  const headers = await super._getAuthHeaders();
80
- // BLOCKLET_DID is always same as BLOCKLET_APP_PID in structV2 application
81
- headers['x-access-blocklet'] = process.env.BLOCKLET_DID;
82
- headers['x-access-component'] = process.env.BLOCKLET_COMPONENT_DID;
80
+ // Use BLOCKLET_APP_PID to match the DID used for deriving BLOCKLET_APP_ASK
81
+ // BLOCKLET_APP_ASK is derived from root.appPid, so we must use BLOCKLET_APP_PID here
82
+ headers['x-access-blocklet'] = process.env.BLOCKLET_APP_PID;
83
+ headers['x-component-did'] = process.env.BLOCKLET_COMPONENT_DID;
83
84
  return headers;
84
85
  }
85
86
  }
@@ -0,0 +1 @@
1
+ export default function testSetup(): void;
@@ -3,8 +3,8 @@ 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.default = setupJest;
7
- // Setup blocklet environments for jest
6
+ exports.default = testSetup;
7
+ // Setup blocklet environments
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const fs_1 = __importDefault(require("fs"));
10
10
  const path_1 = __importDefault(require("path"));
@@ -12,7 +12,7 @@ const parse_1 = require("@blocklet/meta/lib/parse");
12
12
  const mcrypto_1 = require("@ocap/mcrypto");
13
13
  const wallet_1 = require("@ocap/wallet");
14
14
  const did_ext_1 = require("@arcblock/did-ext");
15
- function setupJest() {
15
+ function testSetup() {
16
16
  try {
17
17
  const dir = process.cwd();
18
18
  const wallet = (0, wallet_1.fromRandom)({ role: mcrypto_1.types.RoleType.ROLE_APPLICATION });
@@ -56,6 +56,6 @@ function setupJest() {
56
56
  ]);
57
57
  }
58
58
  catch (err) {
59
- console.error('Failed to setup blocklet environment for jest', err);
59
+ console.error('Failed to setup blocklet environment for test', err);
60
60
  }
61
61
  }
@@ -0,0 +1 @@
1
+ export default function testTeardown(): void;
@@ -3,13 +3,13 @@ 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.default = setupJest;
7
- // Setup blocklet environments for jest
6
+ exports.default = testTeardown;
7
+ // Setup blocklet environments for test
8
8
  const os_1 = __importDefault(require("os"));
9
9
  const fs_extra_1 = __importDefault(require("fs-extra"));
10
10
  const path_1 = __importDefault(require("path"));
11
11
  const parse_1 = require("@blocklet/meta/lib/parse");
12
- function setupJest() {
12
+ function testTeardown() {
13
13
  try {
14
14
  const dir = process.cwd();
15
15
  const meta = (0, parse_1.parse)(dir, { ensureComponentStore: false });
@@ -19,6 +19,6 @@ function setupJest() {
19
19
  }
20
20
  }
21
21
  catch (err) {
22
- console.error('Failed to tear blocklet environment for jest', err);
22
+ console.error('Failed to tear blocklet environment for test', err);
23
23
  }
24
24
  }
@@ -15,7 +15,7 @@ const semver_1 = __importDefault(require("semver"));
15
15
  const qs_1 = __importDefault(require("qs"));
16
16
  const wallet_1 = require("../wallet");
17
17
  const { getPkWallet } = wallet_1.getWallet;
18
- const verify = async (data, sig, { type, appSk, appPk, } = {}) => {
18
+ const verify = async (data, sig, { type, appSk = process.env.BLOCKLET_APP_ASK || process.env.BLOCKLET_APP_SK, appPk, } = {}) => {
19
19
  try {
20
20
  if (!sig) {
21
21
  throw new Error('empty sig');
@@ -35,8 +35,9 @@ const verify = async (data, sig, { type, appSk, appPk, } = {}) => {
35
35
  }
36
36
  };
37
37
  exports.verify = verify;
38
+ const sign = async (data, { type, appSk = process.env.BLOCKLET_APP_ASK || process.env.BLOCKLET_APP_SK } = {}
38
39
  // eslint-disable-next-line require-await
39
- const sign = async (data, { type, appSk } = {}) => {
40
+ ) => {
40
41
  const wallet = (0, wallet_1.getWallet)(type, appSk);
41
42
  return wallet.sign((0, json_stable_stringify_1.default)(data || {}));
42
43
  };
package/lib/wallet.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare const getWallet: {
26
26
  getPermanentWallet: () => WalletObject<string>;
27
27
  getEthereumWallet: (permanent?: boolean) => WalletObject<string>;
28
28
  getPkWallet: (type?: DIDTypeShortcut, appPk?: string) => WalletObject;
29
- deriveWallet: (sub: string, type?: DIDTypeArg, index?: number) => Promise<WalletObject>;
29
+ deriveWallet: (sub: string, type?: DIDTypeArg, index?: number, keyType?: "sk" | "psk") => Promise<WalletObject>;
30
30
  getAccessWallet: () => WalletObject<string>;
31
31
  };
32
32
  /**
@@ -34,9 +34,10 @@ export declare const getWallet: {
34
34
  * @param sub - Subject identifier (e.g., 'email|user@example.com')
35
35
  * @param type - DID type shortcut (e.g., 'ethereum')
36
36
  * @param index - Index for deriving wallet (default: 0)
37
+ * @param keyType - Key type to use ('sk' or 'psk', default: 'sk')
37
38
  * @returns Wallet object with sign and signJWT methods
38
39
  */
39
- export declare const deriveWallet: (sub: string, type?: DIDTypeArg, index?: number) => Promise<WalletObject>;
40
+ export declare const deriveWallet: (sub: string, type?: DIDTypeArg, index?: number, keyType?: "sk" | "psk") => Promise<WalletObject>;
40
41
  export declare const getPermanentWallet: () => WalletObject<string>;
41
42
  export declare const getEthereumWallet: (permanent?: boolean) => WalletObject<string>;
42
43
  export declare const getAccessWallet: () => WalletObject<string>;
package/lib/wallet.js CHANGED
@@ -47,7 +47,7 @@ const createRemoteWallet = (publicKey, type, keyType = 'sk') => {
47
47
  // Support full wallet.sign signature: sign(data, encoding?, hashBeforeSign?)
48
48
  remoteWallet.sign = async (payload, encoding, hashBeforeSign) => {
49
49
  try {
50
- const { signature } = await (0, signature_1.remoteSign)(payload, { keyType, encoding, hashBeforeSign });
50
+ const { signature } = await (0, signature_1.remoteSign)(payload, { keyType, encoding, hashBeforeSign, type });
51
51
  if (!signature) {
52
52
  throw new Error('Empty signature returned from blocklet-service');
53
53
  }
@@ -61,7 +61,7 @@ const createRemoteWallet = (publicKey, type, keyType = 'sk') => {
61
61
  // Match the signature: signJWT(payload?, doSign?, version?)
62
62
  remoteWallet.signJWT = async (payload, doSign, version) => {
63
63
  try {
64
- const { token } = await (0, signature_1.remoteSignJWT)(payload, { doSign, version, keyType });
64
+ const { token } = await (0, signature_1.remoteSignJWT)(payload, { doSign, version, keyType, type });
65
65
  if (!token) {
66
66
  throw new Error('Empty JWT token returned from blocklet-service');
67
67
  }
@@ -74,7 +74,7 @@ const createRemoteWallet = (publicKey, type, keyType = 'sk') => {
74
74
  // Add remote signETH method
75
75
  remoteWallet.signETH = async (data, hashBeforeSign) => {
76
76
  try {
77
- const { signature } = await (0, signature_1.remoteSignETH)(data, { hashBeforeSign, keyType });
77
+ const { signature } = await (0, signature_1.remoteSignETH)(data, { hashBeforeSign, keyType, type: 'ethereum' });
78
78
  if (!signature) {
79
79
  throw new Error('Empty signature returned from blocklet-service');
80
80
  }
@@ -105,8 +105,13 @@ const getWallet = (type, appSk = process.env.BLOCKLET_APP_SK, keyType = 'sk') =>
105
105
  ? (0, wallet_1.WalletType)(type)
106
106
  : (0, wallet_1.WalletType)({ role: mcrypto_1.types.RoleType.ROLE_APPLICATION, pk: mcrypto_1.types.KeyType.ED25519, hash: mcrypto_1.types.HashType.SHA3 });
107
107
  if (!appSk) {
108
- // Select public key based on keyType
109
- const appPk = keyType === 'psk' ? process.env.BLOCKLET_APP_PPK : process.env.BLOCKLET_APP_PK;
108
+ let appPk;
109
+ if ((0, did_1.isEthereumType)((0, did_1.DidType)(type))) {
110
+ appPk = keyType === 'psk' ? process.env.BLOCKLET_APP_PPK_ETH : process.env.BLOCKLET_APP_PK_ETH;
111
+ }
112
+ else {
113
+ appPk = keyType === 'psk' ? process.env.BLOCKLET_APP_PPK : process.env.BLOCKLET_APP_PK;
114
+ }
110
115
  if (!appPk) {
111
116
  throw new Error(`Missing public key for ${keyType.toUpperCase()} wallet: BLOCKLET_APP_P${keyType.toUpperCase()}`);
112
117
  }
@@ -125,16 +130,17 @@ exports.getWallet = getWallet;
125
130
  * @param sub - Subject identifier (e.g., 'email|user@example.com')
126
131
  * @param type - DID type shortcut (e.g., 'ethereum')
127
132
  * @param index - Index for deriving wallet (default: 0)
133
+ * @param keyType - Key type to use ('sk' or 'psk', default: 'sk')
128
134
  * @returns Wallet object with sign and signJWT methods
129
135
  */
130
- const deriveWallet = async (sub, type, index) => {
131
- const appSk = process.env.BLOCKLET_APP_SK;
136
+ const deriveWallet = async (sub, type, index, keyType = 'sk') => {
137
+ const appSk = keyType === 'psk' ? process.env.BLOCKLET_APP_PSK : process.env.BLOCKLET_APP_SK;
132
138
  // If we have a secret key, use local fromAppDid
133
139
  if (appSk) {
134
140
  return (0, did_ext_1.fromAppDid)(sub, appSk, type, index);
135
141
  }
136
142
  // No secret key available, use remote fromAppDid
137
- const walletJSON = await (0, signature_1.remoteDeriveWallet)(sub, type, index);
143
+ const walletJSON = await (0, signature_1.remoteDeriveWallet)(sub, type, index, { keyType });
138
144
  const wallet = (0, wallet_1.fromJSON)(walletJSON);
139
145
  if (!(0, wallet_1.isValid)(wallet, true)) {
140
146
  throw new Error('Invalid response from remote fromAppDid: wallet is invalid');
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.54-beta-20251024-030947-6f2889bf",
6
+ "version": "1.16.54-beta-20251028-073105-3ed10cef",
7
7
  "description": "graphql client to read/write data on abt node",
8
8
  "homepage": "https://www.arcblock.io/docs/blocklet-sdk-nodejs",
9
9
  "main": "lib/index.js",
@@ -16,8 +16,8 @@
16
16
  "verify": "npm run lint:fix && npm run test && npm run build",
17
17
  "lint": "eslint src tests service",
18
18
  "lint:fix": "npm run lint -- --fix",
19
- "test": "bun test",
20
- "coverage": "bun test --coverage",
19
+ "test": "bun test --bail --timeout 30000",
20
+ "coverage": "bun test --bail --timeout 30000 --coverage",
21
21
  "clean": "rm -fr lib",
22
22
  "prebuild": "npm run clean && npm run types",
23
23
  "types": "rm -rf ./src/types && node tools/version.js && ts-node tools/types.js && rm -f ./src/types/index.ts && prettier --write ./src/types/notification.ts",
@@ -28,19 +28,19 @@
28
28
  "author": "linchen1987 <linchen.1987@foxmail.com> (http://github.com/linchen1987)",
29
29
  "license": "Apache-2.0",
30
30
  "dependencies": {
31
- "@abtnode/constant": "1.16.54-beta-20251024-030947-6f2889bf",
32
- "@abtnode/db-cache": "1.16.54-beta-20251024-030947-6f2889bf",
33
- "@abtnode/util": "1.16.54-beta-20251024-030947-6f2889bf",
31
+ "@abtnode/constant": "1.16.54-beta-20251028-073105-3ed10cef",
32
+ "@abtnode/db-cache": "1.16.54-beta-20251028-073105-3ed10cef",
33
+ "@abtnode/util": "1.16.54-beta-20251028-073105-3ed10cef",
34
34
  "@arcblock/did": "^1.26.3",
35
35
  "@arcblock/did-connect-js": "^1.26.3",
36
36
  "@arcblock/did-ext": "^1.26.3",
37
37
  "@arcblock/jwt": "^1.26.3",
38
38
  "@arcblock/ws": "^1.26.3",
39
- "@blocklet/constant": "1.16.54-beta-20251024-030947-6f2889bf",
40
- "@blocklet/env": "1.16.54-beta-20251024-030947-6f2889bf",
39
+ "@blocklet/constant": "1.16.54-beta-20251028-073105-3ed10cef",
40
+ "@blocklet/env": "1.16.54-beta-20251028-073105-3ed10cef",
41
41
  "@blocklet/error": "^0.2.5",
42
- "@blocklet/meta": "1.16.54-beta-20251024-030947-6f2889bf",
43
- "@blocklet/server-js": "1.16.54-beta-20251024-030947-6f2889bf",
42
+ "@blocklet/meta": "1.16.54-beta-20251028-073105-3ed10cef",
43
+ "@blocklet/server-js": "1.16.54-beta-20251028-073105-3ed10cef",
44
44
  "@blocklet/theme": "^3.1.51",
45
45
  "@did-connect/authenticator": "^2.2.8",
46
46
  "@did-connect/handler": "^2.2.8",
@@ -70,7 +70,6 @@
70
70
  "devDependencies": {
71
71
  "@arcblock/eslint-config-ts": "^0.3.3",
72
72
  "@types/express": "^5.0.0",
73
- "@types/jest": "^29.5.13",
74
73
  "@types/json-stable-stringify": "^1.0.36",
75
74
  "@types/lodash": "^4.17.20",
76
75
  "@types/node": "^22.7.5",
@@ -79,13 +78,11 @@
79
78
  "axios-mock-adapter": "^2.1.0",
80
79
  "detect-port": "^1.5.1",
81
80
  "eslint": "^8.57.0",
82
- "jest": "^29.7.0",
83
81
  "joi-to-typescript": "^4.14.0",
84
82
  "json-stable-stringify": "^1.0.1",
85
83
  "prettier": "^3.3.2",
86
- "ts-jest": "^29.2.5",
87
84
  "ts-node": "^10.9.1",
88
85
  "typescript": "^5.6.3"
89
86
  },
90
- "gitHead": "73e5a3a80b82a2a7c62d42fdc08207b28e67633e"
87
+ "gitHead": "3002dd309759dd23c921b098b9edbef08838b734"
91
88
  }
@@ -1 +0,0 @@
1
- export default function setupJest(): void;
@@ -1 +0,0 @@
1
- export default function setupJest(): void;