@abtnode/auth 1.17.2 → 1.17.3-beta-20251117-130331-b2ce7065

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.
Files changed (2) hide show
  1. package/lib/util/federated.js +24 -38
  2. package/package.json +21 -21
@@ -8,12 +8,10 @@ const {
8
8
  } = require('@abtnode/constant');
9
9
  const { Joi } = require('@arcblock/validator');
10
10
  const pRetry = require('p-retry');
11
- const { signV2 } = require('@arcblock/jwt');
12
11
  const { joinURL } = require('ufo');
13
12
  const { normalizePathPrefix } = require('@blocklet/meta/lib/normalize-path-prefix');
14
13
  const { getBlockletInfo } = require('@blocklet/meta/lib/info');
15
14
  const { getSignData } = require('@blocklet/sdk/lib/util/verify-sign');
16
- const { SIG_VERSION } = require('@blocklet/constant');
17
15
  const cloneDeep = require('@abtnode/util/lib/deep-clone');
18
16
  const defaults = require('lodash/defaults');
19
17
  const pick = require('lodash/pick');
@@ -25,6 +23,7 @@ const logger = require('../logger');
25
23
 
26
24
  const federatedEnvSchema = Joi.object({
27
25
  sigVersion: Joi.string().optional().allow('').default(''),
26
+ masterAppUrl: Joi.string().optional().allow('').default(''),
28
27
  }).unknown(true);
29
28
 
30
29
  function isMaster(site) {
@@ -87,10 +86,13 @@ function findFederatedSite(blocklet, targetAppPid) {
87
86
  return targetSite || null;
88
87
  }
89
88
 
89
+ /**
90
+ * 获取统一登录站点的环境信息
91
+ * @param {object} options.site
92
+ * @returns {Promise<{sigVersion: string; masterAppUrl: string} | null>}
93
+ */
90
94
  async function getFederatedSiteEnv({ site }) {
91
- const defaultEnv = {
92
- sigVersion: SIG_VERSION.V0,
93
- };
95
+ const defaultEnv = null;
94
96
  try {
95
97
  const url = joinURL(WELLKNOWN_SERVICE_PATH_PREFIX, '/api/federated/env');
96
98
  const { data: result } = await request.get(url, { baseURL: site.appUrl });
@@ -142,41 +144,25 @@ function safeGetFederated(blocklet, { isMaster: _isMaster = false } = {}) {
142
144
  * @throws {Error} - Throws an error if the request fails after the specified number of retries.
143
145
  */
144
146
  async function callFederated({ site, permanentWallet, action, data = {}, customUrl, requestOptions = {} } = {}) {
145
- const siteEnv = await getFederatedSiteEnv({ site });
146
147
  const url = customUrl || joinURL(WELLKNOWN_SERVICE_PATH_PREFIX, `/api/federated/${action}`);
147
148
  let requestFn = () => {};
148
- // default 永远会指向最新版
149
- if (siteEnv.sigVersion === SIG_VERSION.DEFAULT) {
150
- const { exp, iat, sig, version } = await getSignData(
151
- { data, method: 'post', url },
152
- {
153
- appSk: permanentWallet.secretKey,
154
- }
155
- );
156
- requestFn = request.post(url, data, {
157
- ...requestOptions,
158
- baseURL: site.appUrl,
159
- headers: {
160
- 'x-blocklet-sig': sig,
161
- 'x-blocklet-sig-pk': permanentWallet.publicKey,
162
- 'x-blocklet-sig-iat': iat,
163
- 'x-blocklet-sig-exp': exp,
164
- 'x-blocklet-sig-version': version,
165
- },
166
- });
167
- } else if (siteEnv.sigVersion === SIG_VERSION.V0) {
168
- // DEPRECATED: @zhanghan 在 1.16.35 发布时移除旧版本的兼容
169
- requestFn = request.post(
170
- url,
171
- {
172
- signer: permanentWallet.address,
173
- data: await signV2(permanentWallet.address, permanentWallet.secretKey, data),
174
- },
175
- {
176
- baseURL: site.appUrl,
177
- }
178
- );
179
- }
149
+ const { exp, iat, sig, version } = await getSignData(
150
+ { data, method: 'post', url },
151
+ {
152
+ appSk: permanentWallet.secretKey,
153
+ }
154
+ );
155
+ requestFn = request.post(url, data, {
156
+ ...requestOptions,
157
+ baseURL: site.appUrl,
158
+ headers: {
159
+ 'x-blocklet-sig': sig,
160
+ 'x-blocklet-sig-pk': permanentWallet.publicKey,
161
+ 'x-blocklet-sig-iat': iat,
162
+ 'x-blocklet-sig-exp': exp,
163
+ 'x-blocklet-sig-version': version,
164
+ },
165
+ });
180
166
  const result = await pRetry(() => requestFn, { retries: 3 });
181
167
  return result.data;
182
168
  }
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.17.2",
6
+ "version": "1.17.3-beta-20251117-130331-b2ce7065",
7
7
  "description": "Simple lib to manage auth in ABT Node",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,25 +18,25 @@
18
18
  "author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
19
19
  "license": "Apache-2.0",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.17.2",
22
- "@abtnode/logger": "1.17.2",
23
- "@abtnode/util": "1.17.2",
24
- "@arcblock/did": "^1.27.6",
25
- "@arcblock/did-connect-js": "^1.27.6",
26
- "@arcblock/did-ext": "^1.27.6",
27
- "@arcblock/did-util": "^1.27.6",
28
- "@arcblock/jwt": "^1.27.6",
29
- "@arcblock/nft-display": "^3.2.5",
30
- "@arcblock/validator": "^1.27.6",
31
- "@arcblock/vc": "^1.27.6",
32
- "@blocklet/constant": "1.17.2",
33
- "@blocklet/error": "^0.3.2",
34
- "@blocklet/meta": "1.17.2",
35
- "@blocklet/sdk": "1.17.2",
36
- "@ocap/client": "^1.27.6",
37
- "@ocap/mcrypto": "^1.27.6",
38
- "@ocap/util": "^1.27.6",
39
- "@ocap/wallet": "^1.27.6",
21
+ "@abtnode/constant": "1.17.3-beta-20251117-130331-b2ce7065",
22
+ "@abtnode/logger": "1.17.3-beta-20251117-130331-b2ce7065",
23
+ "@abtnode/util": "1.17.3-beta-20251117-130331-b2ce7065",
24
+ "@arcblock/did": "^1.27.7",
25
+ "@arcblock/did-connect-js": "^1.27.7",
26
+ "@arcblock/did-ext": "^1.27.7",
27
+ "@arcblock/did-util": "^1.27.7",
28
+ "@arcblock/jwt": "^1.27.7",
29
+ "@arcblock/nft-display": "^3.2.6",
30
+ "@arcblock/validator": "^1.27.7",
31
+ "@arcblock/vc": "^1.27.7",
32
+ "@blocklet/constant": "1.17.3-beta-20251117-130331-b2ce7065",
33
+ "@blocklet/error": "^0.3.3",
34
+ "@blocklet/meta": "1.17.3-beta-20251117-130331-b2ce7065",
35
+ "@blocklet/sdk": "1.17.3-beta-20251117-130331-b2ce7065",
36
+ "@ocap/client": "^1.27.7",
37
+ "@ocap/mcrypto": "^1.27.7",
38
+ "@ocap/util": "^1.27.7",
39
+ "@ocap/wallet": "^1.27.7",
40
40
  "@simplewebauthn/server": "^13.1.1",
41
41
  "axios": "^1.7.9",
42
42
  "flat": "^5.0.2",
@@ -55,5 +55,5 @@
55
55
  "devDependencies": {
56
56
  "axios-mock-adapter": "^2.1.0"
57
57
  },
58
- "gitHead": "d11c73575f9211d0794ccb72ea8981c50700ad10"
58
+ "gitHead": "4d719e72f7845c5f607d854300a0576dddfaaeff"
59
59
  }