@abtnode/core 1.16.6-beta-7cbab489 → 1.16.6-beta-61cf68d3

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/api/team.js CHANGED
@@ -27,6 +27,7 @@ const { getPassportStatusEndpoint } = require('@abtnode/auth/lib/auth');
27
27
  const getBlockletInfo = require('@blocklet/meta/lib/info');
28
28
  const { parseUserAvatar } = require('@abtnode/util/lib/user-avatar');
29
29
  const { getChainClient } = require('@abtnode/util/lib/get-chain-client');
30
+ const { getWalletDid } = require('@blocklet/meta/lib/did-utils');
30
31
 
31
32
  const { validateTrustedPassportIssuers } = require('../validators/trusted-passport');
32
33
  const { validateTrustedFactories } = require('../validators/trusted-factory');
@@ -290,6 +291,7 @@ class TeamAPI extends EventEmitter {
290
291
 
291
292
  const state = await this.getUserState(teamDid);
292
293
 
294
+ // NOTICE: 目前 owner 只能为 did-wallet,无需查询 connectedAccount
293
295
  const full = await state.getUser(owner.did);
294
296
  return full || owner;
295
297
  }
@@ -371,6 +373,7 @@ class TeamAPI extends EventEmitter {
371
373
  const { locale = 'en' } = context;
372
374
 
373
375
  const userState = await this.getUserState(teamDid);
376
+ // NOTICE: issuePassportToUser 必须传入 wallet did,无需查询 connectedAccount
374
377
  const user = await userState.getUser(userDid);
375
378
 
376
379
  if (!user) {
@@ -772,52 +775,61 @@ class TeamAPI extends EventEmitter {
772
775
 
773
776
  const state = await this.getSessionState(teamDid);
774
777
 
778
+ // 为指定用户颁发通行证,拿到的 did 是永久 did,无需查询 connectedAccount
775
779
  const currentUser = await this.getUser({ teamDid, user: { did: ownerDid } });
776
- const isRawWalletAccount =
777
- !currentUser?.extraConfigs?.sourceProvider || currentUser?.extraConfigs?.sourceProvider === 'wallet';
778
- if (!isRawWalletAccount) {
779
- const userDid = currentUser.did;
780
- const blocklet = await getBlocklet({ did: teamDid, states: this.states, dataDirs: this.dataDirs });
781
- const nodeInfo = await this.node.read();
782
- const blockletInfo = getBlockletInfo(blocklet, nodeInfo.sk);
783
- const { wallet, passportColor, appUrl, name: issuerName } = blockletInfo;
784
- const vc = createPassportVC({
785
- issuerName,
786
- issuerWallet: wallet,
787
- ownerDid: userDid,
788
- passport: await createPassport({
789
- role,
790
- }),
791
- endpoint: getPassportStatusEndpoint({
792
- baseUrl: joinUrl(appUrl, WELLKNOWN_SERVICE_PATH_PREFIX),
793
- userDid,
794
- teamDid,
795
- }),
796
- ownerProfile: {
797
- ...currentUser,
798
- },
799
- preferredColor: passportColor,
800
- });
780
+ const walletDid = getWalletDid(currentUser);
781
+ const userDid = walletDid || ownerDid;
782
+ // 这里可能是为一个不存在的用户创建一个 passport,所以需要额外判断一下
783
+ if (currentUser) {
784
+ // auth0 账户不需要手动领取
785
+ if (walletDid !== ownerDid) {
786
+ const blocklet = await getBlocklet({ did: teamDid, states: this.states, dataDirs: this.dataDirs });
787
+ const nodeInfo = await this.node.read();
788
+ const blockletInfo = getBlockletInfo(blocklet, nodeInfo.sk);
789
+ const { wallet, passportColor, appUrl, name: issuerName } = blockletInfo;
790
+ const vc = createPassportVC({
791
+ issuerName,
792
+ issuerWallet: wallet,
793
+ ownerDid: userDid,
794
+ passport: await createPassport({
795
+ role,
796
+ }),
797
+ endpoint: getPassportStatusEndpoint({
798
+ baseUrl: joinUrl(appUrl, WELLKNOWN_SERVICE_PATH_PREFIX),
799
+ userDid,
800
+ teamDid,
801
+ }),
802
+ ownerProfile: {
803
+ ...currentUser,
804
+ avatar: await parseUserAvatar(currentUser.avatar, { dataDir: blocklet.env.dataDir }),
805
+ },
806
+ preferredColor: passportColor,
807
+ });
801
808
 
802
- // write passport to db
803
- const passport = createUserPassport(vc, { role: role.name });
804
- const passports = upsertToPassports(currentUser.passports || [], passport);
805
- await this.updateUser({
806
- teamDid,
807
- user: {
808
- did: ownerDid,
809
- pk: currentUser.pk,
810
- passports,
811
- },
812
- });
813
- return undefined;
809
+ if (walletDid) {
810
+ sendPassportVcNotification({ userDid, appWallet: wallet, locale: 'en', vc });
811
+ }
812
+
813
+ // write passport to db
814
+ const passport = createUserPassport(vc, { role: role.name });
815
+ const passports = upsertToPassports(currentUser.passports || [], passport);
816
+ await this.updateUser({
817
+ teamDid,
818
+ user: {
819
+ did: currentUser.did,
820
+ pk: currentUser.pk,
821
+ passports,
822
+ },
823
+ });
824
+ return undefined;
825
+ }
814
826
  }
815
827
  const { id } = await state.start({
816
828
  type: 'passport-issuance',
817
829
  expireDate, // session expireDate
818
830
  name: role.name,
819
831
  title: role.title,
820
- ownerDid,
832
+ ownerDid: userDid,
821
833
  teamDid,
822
834
  });
823
835
 
@@ -828,7 +840,7 @@ class TeamAPI extends EventEmitter {
828
840
  name: role.name,
829
841
  title: role.title,
830
842
  expireDate: new Date(expireDate).toString(),
831
- ownerDid,
843
+ ownerDid: userDid,
832
844
  teamDid,
833
845
  };
834
846
  }
@@ -7,6 +7,7 @@ const get = require('lodash/get');
7
7
  const omit = require('lodash/omit');
8
8
  const merge = require('lodash/merge');
9
9
  const pick = require('lodash/pick');
10
+ const isEmpty = require('lodash/isEmpty');
10
11
  const cloneDeep = require('lodash/cloneDeep');
11
12
  const { isNFTExpired, getNftExpirationDate } = require('@abtnode/util/lib/nft');
12
13
  const didDocument = require('@abtnode/util/lib/did-document');
@@ -2453,38 +2454,47 @@ class BlockletManager extends BaseBlockletManager {
2453
2454
  { did: 1, meta: 1, controller: 1 }
2454
2455
  );
2455
2456
 
2457
+ logger.info('external blocklet count', { count: blockletExtras.length });
2458
+
2456
2459
  for (const data of blockletExtras) {
2457
2460
  try {
2461
+ if (isEmpty(data.controller)) {
2462
+ logger.info('skip the blocklet without controller', { blockletDid: data.did, controller: data.controller });
2463
+ // eslint-disable-next-line no-continue
2464
+ continue;
2465
+ }
2466
+
2467
+ const { did } = data;
2458
2468
  const assetState = await util.getNFTState(data.controller.chainHost, data.controller.nftId);
2459
2469
  const isExpired = isNFTExpired(assetState);
2460
2470
 
2461
2471
  if (isExpired) {
2462
2472
  logger.info('the blocklet already expired', {
2463
- blockletDid: data.meta.did,
2473
+ blockletDid: did,
2464
2474
  nftId: data.controller.nftId,
2465
2475
  });
2466
2476
 
2467
- const blocklet = await states.blocklet.getBlocklet(data.meta.did);
2477
+ const blocklet = await states.blocklet.getBlocklet(did);
2468
2478
  if (blocklet) {
2469
2479
  // 预防 Blocklet 已经删除,但是 blocklet extra data 没有清理的场景
2470
2480
  await this._backupToDisk({ blocklet });
2471
2481
  logger.info('backed up the expired blocklet', {
2472
- blockletDid: data.meta.did,
2482
+ blockletDid: did,
2473
2483
  nftId: data.controller.nftId,
2474
2484
  });
2475
2485
 
2476
- await this.delete({ did: data.meta.did, keepData: true, keepConfigs: true, keepLogsDir: true });
2486
+ await this.delete({ did, keepData: true, keepConfigs: true, keepLogsDir: true });
2477
2487
  logger.info('the expired blocklet already deleted', {
2478
- blockletDid: data.meta.did,
2488
+ blockletDid: did,
2479
2489
  nftId: data.controller.nftId,
2480
2490
  });
2481
2491
  }
2482
2492
 
2483
2493
  const expiredAt = getNftExpirationDate(assetState);
2484
- await states.blockletExtras.updateExpireInfo({ did: data.meta.did, expiredAt });
2494
+ await states.blockletExtras.updateExpireInfo({ did, expiredAt });
2485
2495
  logger.info('updated expired blocklet extra info', {
2486
2496
  nftId: data.controller.nftId,
2487
- blockletDid: data.meta.did,
2497
+ blockletDid: did,
2488
2498
  });
2489
2499
 
2490
2500
  // 删除 blocklet 后会 reload nginx, 所以这里每次删除一个
@@ -2494,8 +2504,8 @@ class BlockletManager extends BaseBlockletManager {
2494
2504
  }
2495
2505
  } catch (error) {
2496
2506
  logger.error('delete expired blocklet failed', {
2497
- blockletDid: data.meta.did,
2498
- nftId: data.controller.nftId,
2507
+ blockletDid: data.did,
2508
+ nftId: data.controller?.nftId,
2499
2509
  error,
2500
2510
  });
2501
2511
  }
@@ -2516,19 +2526,37 @@ class BlockletManager extends BaseBlockletManager {
2516
2526
  return;
2517
2527
  }
2518
2528
 
2519
- const tasks = blockletExtras.map(async ({ appDid, meta }) => {
2520
- await this._cleanBlockletData({ blocklet: { meta }, keepData: false, keepLogsDir: false, keepConfigs: false });
2521
- logger.info(`clean blocklet ${meta.did} extra data`);
2529
+ const tasks = blockletExtras.map(async ({ appDid, did, meta }) => {
2530
+ const blocklet = await this.getBlocklet(did);
2531
+ if (blocklet) {
2532
+ logger.error('skip cleaning the blocklet which is not deleted', { blockletDid: did });
2533
+ return;
2534
+ }
2535
+
2536
+ let blockletMeta = meta;
2537
+ if (isEmpty(blockletMeta)) {
2538
+ // 旧版本的 blocklet 没有 meta 信息,这里补充一下
2539
+ blockletMeta = { did, name: did };
2540
+ logger.error('the blocklet original meta is empty', { did, blockletMeta });
2541
+ }
2542
+
2543
+ await this._cleanBlockletData({
2544
+ blocklet: { meta: blockletMeta },
2545
+ keepData: false,
2546
+ keepLogsDir: false,
2547
+ keepConfigs: false,
2548
+ });
2549
+ logger.info(`clean blocklet ${blockletMeta.did} extra data`);
2522
2550
 
2523
2551
  await removeBackup(this.dataDirs.data, appDid);
2524
- logger.info(`removed blocklet ${meta.did} backup`);
2552
+ logger.info(`removed blocklet ${blockletMeta.did} backup`);
2525
2553
 
2526
2554
  this.emit(BlockletEvents.dataCleaned, {
2527
- blocklet: { meta },
2555
+ blocklet: { meta: blockletMeta },
2528
2556
  keepRouting: false,
2529
2557
  });
2530
2558
 
2531
- logger.info(`cleaned expired blocklet blocklet ${meta.did} data`);
2559
+ logger.info(`cleaned expired blocklet blocklet ${blockletMeta.did} data`);
2532
2560
  });
2533
2561
 
2534
2562
  await Promise.all(tasks);
@@ -89,7 +89,8 @@ const verifyBlockletServer = async (version) => {
89
89
 
90
90
  if (result.code === 0) {
91
91
  const actual = semver.coerce(result.stdout);
92
- if (actual && actual.version === version) {
92
+ const expected = semver.coerce(version);
93
+ if (actual && expected && actual.version === expected.version) {
93
94
  return result;
94
95
  }
95
96
 
@@ -57,7 +57,13 @@ const expandUser = async (teamDid, userDid, passportId, info, node) => {
57
57
  return ['', ''];
58
58
  }
59
59
 
60
- const user = await node.getUser({ teamDid, user: { did: userDid } });
60
+ const user = await node.getUser({
61
+ teamDid,
62
+ user: { did: userDid },
63
+ options: {
64
+ enableConnectedAccount: true,
65
+ },
66
+ });
61
67
  if (!user) {
62
68
  return ['', ''];
63
69
  }
@@ -12,7 +12,6 @@ const passportSchema = Joi.object({
12
12
  .unknown()
13
13
  .empty(null);
14
14
 
15
- // TODO: @zhanghan 这里目前仅包含必填的字段,后续需要增加其他字段
16
15
  const connectedAccountSchema = Joi.object({
17
16
  provider: Joi.string().required(),
18
17
  did: Joi.DID().trim().required(),
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.6-beta-7cbab489",
6
+ "version": "1.16.6-beta-61cf68d3",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,35 +19,35 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.16.6-beta-7cbab489",
23
- "@abtnode/certificate-manager": "1.16.6-beta-7cbab489",
24
- "@abtnode/constant": "1.16.6-beta-7cbab489",
25
- "@abtnode/cron": "1.16.6-beta-7cbab489",
26
- "@abtnode/db": "1.16.6-beta-7cbab489",
27
- "@abtnode/logger": "1.16.6-beta-7cbab489",
28
- "@abtnode/queue": "1.16.6-beta-7cbab489",
29
- "@abtnode/rbac": "1.16.6-beta-7cbab489",
30
- "@abtnode/router-provider": "1.16.6-beta-7cbab489",
31
- "@abtnode/static-server": "1.16.6-beta-7cbab489",
32
- "@abtnode/timemachine": "1.16.6-beta-7cbab489",
33
- "@abtnode/util": "1.16.6-beta-7cbab489",
34
- "@arcblock/did": "1.18.75",
35
- "@arcblock/did-auth": "1.18.75",
36
- "@arcblock/did-ext": "^1.18.75",
22
+ "@abtnode/auth": "1.16.6-beta-61cf68d3",
23
+ "@abtnode/certificate-manager": "1.16.6-beta-61cf68d3",
24
+ "@abtnode/constant": "1.16.6-beta-61cf68d3",
25
+ "@abtnode/cron": "1.16.6-beta-61cf68d3",
26
+ "@abtnode/db": "1.16.6-beta-61cf68d3",
27
+ "@abtnode/logger": "1.16.6-beta-61cf68d3",
28
+ "@abtnode/queue": "1.16.6-beta-61cf68d3",
29
+ "@abtnode/rbac": "1.16.6-beta-61cf68d3",
30
+ "@abtnode/router-provider": "1.16.6-beta-61cf68d3",
31
+ "@abtnode/static-server": "1.16.6-beta-61cf68d3",
32
+ "@abtnode/timemachine": "1.16.6-beta-61cf68d3",
33
+ "@abtnode/util": "1.16.6-beta-61cf68d3",
34
+ "@arcblock/did": "1.18.76",
35
+ "@arcblock/did-auth": "1.18.76",
36
+ "@arcblock/did-ext": "^1.18.76",
37
37
  "@arcblock/did-motif": "^1.1.10",
38
- "@arcblock/did-util": "1.18.75",
39
- "@arcblock/event-hub": "1.18.75",
40
- "@arcblock/jwt": "^1.18.75",
38
+ "@arcblock/did-util": "1.18.76",
39
+ "@arcblock/event-hub": "1.18.76",
40
+ "@arcblock/jwt": "^1.18.76",
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
- "@arcblock/vc": "1.18.75",
43
- "@blocklet/constant": "1.16.6-beta-7cbab489",
44
- "@blocklet/meta": "1.16.6-beta-7cbab489",
45
- "@blocklet/sdk": "1.16.6-beta-7cbab489",
46
- "@did-space/client": "^0.2.83",
42
+ "@arcblock/vc": "1.18.76",
43
+ "@blocklet/constant": "1.16.6-beta-61cf68d3",
44
+ "@blocklet/meta": "1.16.6-beta-61cf68d3",
45
+ "@blocklet/sdk": "1.16.6-beta-61cf68d3",
46
+ "@did-space/client": "^0.2.87",
47
47
  "@fidm/x509": "^1.2.1",
48
- "@ocap/mcrypto": "1.18.75",
49
- "@ocap/util": "1.18.75",
50
- "@ocap/wallet": "1.18.75",
48
+ "@ocap/mcrypto": "1.18.76",
49
+ "@ocap/util": "1.18.76",
50
+ "@ocap/wallet": "1.18.76",
51
51
  "@slack/webhook": "^5.0.4",
52
52
  "archiver": "^5.3.1",
53
53
  "axios": "^0.27.2",
@@ -94,5 +94,5 @@
94
94
  "express": "^4.18.2",
95
95
  "jest": "^27.5.1"
96
96
  },
97
- "gitHead": "36b58c0651762472ac34ad880965c47510eb9768"
97
+ "gitHead": "574a27436b429a97f443fc9ea1b44988807206bd"
98
98
  }