@abtnode/core 1.8.49 → 1.8.51

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.
@@ -14,6 +14,7 @@ const { Throttle } = require('stream-throttle');
14
14
  const LRU = require('lru-cache');
15
15
  const joi = require('joi');
16
16
  const { isNFTExpired } = require('@abtnode/util/lib/nft');
17
+ const { disableDNS } = require('@abtnode/util/lib/did-document');
17
18
  const { sign } = require('@arcblock/jwt');
18
19
  const { isValid: isValidDid } = require('@arcblock/did');
19
20
  const { verifyPresentation } = require('@arcblock/vc');
@@ -21,6 +22,7 @@ const { toBase58, isHex } = require('@ocap/util');
21
22
  const { fromSecretKey } = require('@ocap/wallet');
22
23
  const { toSvg: createDidLogo } =
23
24
  process.env.NODE_ENV !== 'test' ? require('@arcblock/did-motif') : require('@arcblock/did-motif/dist/did-motif.cjs');
25
+ const getBlockletInfo = require('@blocklet/meta/lib/info');
24
26
 
25
27
  const logger = require('@abtnode/logger')('@abtnode/core:blocklet:manager');
26
28
  const downloadFile = require('@abtnode/util/lib/download-file');
@@ -3603,6 +3605,16 @@ class BlockletManager extends BaseBlockletManager {
3603
3605
  }
3604
3606
  }
3605
3607
 
3608
+ const nodeInfo = await states.node.read();
3609
+ const { wallet } = getBlockletInfo(blocklet, nodeInfo.sk);
3610
+ disableDNS({ wallet, didRegistryUrl: nodeInfo.didRegistry })
3611
+ .then(() => {
3612
+ logger.info(`disabled blocklet ${blocklet.appDid} dns`);
3613
+ })
3614
+ .catch((err) => {
3615
+ logger.error(`disable blocklet ${blocklet.appDid} dns failed`, { error: err });
3616
+ });
3617
+
3606
3618
  const result = await states.blocklet.deleteBlocklet(did);
3607
3619
  logger.info('blocklet removed successfully', { did });
3608
3620
 
@@ -12,6 +12,9 @@ const { getProvider } = require('@abtnode/router-provider');
12
12
  const normalizePathPrefix = require('@abtnode/util/lib/normalize-path-prefix');
13
13
  const getTmpDir = require('@abtnode/util/lib/get-tmp-directory');
14
14
  const downloadFile = require('@abtnode/util/lib/download-file');
15
+ const { encode: encodeBase32 } = require('@abtnode/util/lib/base32');
16
+ const { updateBlockletDocument } = require('@abtnode/util/lib/did-document');
17
+ const getBlockletInfo = require('@blocklet/meta/lib/info');
15
18
  const {
16
19
  DOMAIN_FOR_DEFAULT_SITE,
17
20
  DOMAIN_FOR_IP_SITE_REGEXP,
@@ -564,35 +567,26 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
564
567
  }
565
568
  }
566
569
 
567
- const isExistsInAlias = (domainAlias) =>
568
- (dashboardSite.domainAliases || []).find((item) => {
569
- if (typeof item === 'object') {
570
- return domainAlias === item.value;
571
- }
572
-
573
- return domainAlias === item;
574
- });
575
-
576
570
  const ipWildcardDomain = get(info, 'routing.ipWildcardDomain', '');
577
- const didDomain = `${info.did.toLowerCase()}.${info.didDomain}`;
578
- let dashboardAliasDomains = [ipWildcardDomain, didDomain];
579
571
 
580
- dashboardAliasDomains = dashboardAliasDomains
581
- .filter((item) => item && !isExistsInAlias(item))
582
- .map((item) => ({ value: item, isProtected: true }));
572
+ const domainAliases = (dashboardSite.domainAliases || []).filter(
573
+ (item) => !item.value.endsWith(ipWildcardDomain) && !item.value.endsWith(info.didDomain)
574
+ );
583
575
 
584
- if (dashboardAliasDomains.length > 0) {
585
- try {
586
- const result = await siteState.update(
587
- { _id: dashboardSite.id },
588
- { $push: { domainAliases: { $each: dashboardAliasDomains } } }
589
- );
576
+ const didDomain = `${encodeBase32(info.did)}.${info.didDomain}`;
577
+ const dashboardAliasDomains = [
578
+ { value: ipWildcardDomain, isProtected: true },
579
+ { value: didDomain, isProtected: true },
580
+ ];
581
+ domainAliases.push(...dashboardAliasDomains);
590
582
 
591
- updatedResult.push(result);
592
- } catch (error) {
593
- logger.error('add dashboard domain rule failed', { error });
594
- console.error('Add dashboard domain rule failed:', error);
595
- }
583
+ try {
584
+ const result = await siteState.update({ _id: dashboardSite.id }, { $set: { domainAliases } });
585
+
586
+ updatedResult.push(result);
587
+ } catch (error) {
588
+ logger.error('add dashboard domain rule failed', { error });
589
+ console.error('Add dashboard domain rule failed:', error);
596
590
  }
597
591
 
598
592
  const defaultRule = sites.find((x) => x.domain === DOMAIN_FOR_DEFAULT_SITE);
@@ -666,11 +660,25 @@ module.exports = function getRouterHelpers({ dataDirs, routingSnapshot, routerMa
666
660
  const domainAliases = [];
667
661
 
668
662
  const didDomain = getDidDomainForBlocklet({
669
- name: blocklet.meta.name,
670
- daemonDid: nodeInfo.did,
663
+ blockletAppDid: blocklet.appDid,
671
664
  didDomain: nodeInfo.didDomain,
672
665
  });
673
666
 
667
+ const { wallet } = getBlockletInfo(blocklet, nodeInfo.sk);
668
+ updateBlockletDocument({
669
+ wallet,
670
+ blockletAppDid: blocklet.appDid,
671
+ daemonDidDomain: `${encodeBase32(nodeInfo.did)}.${nodeInfo.didDomain}`,
672
+ didRegistryUrl: nodeInfo.didRegistry,
673
+ domain: nodeInfo.didDomain,
674
+ })
675
+ .then(() => {
676
+ logger.info(`updated blocklet ${blocklet.appDid} dns`);
677
+ })
678
+ .catch((err) => {
679
+ logger.error(`update blocklet ${blocklet.appDid} dns failed`, { error: err });
680
+ });
681
+
674
682
  const ipEchoDnsDomain = getIpDnsDomainForBlocklet(blocklet, webInterface, nodeInfo.did);
675
683
 
676
684
  // let didDomain in front of ipEchoDnsDomain
@@ -266,7 +266,26 @@ const getAppSystemEnvironments = (blocklet, nodeInfo) => {
266
266
  const appName = title || name || result.name;
267
267
  const appDescription = description || result.description;
268
268
 
269
- const appUrl = `https://${getDidDomainForBlocklet({ name, daemonDid: nodeInfo.did, didDomain: nodeInfo.didDomain })}`;
269
+ /* 获取 did domain 方式:
270
+ * 1. 先从 site 里读
271
+ * 2. 如果没有,再拼接
272
+ */
273
+
274
+ let appUrl = '';
275
+
276
+ const domainAliases = get(blocklet, 'site.domainAliases') || [];
277
+ const didDomainAlias = domainAliases.find(
278
+ (item) => item.value.endsWith(nodeInfo.didDomain) || item.value.endsWith('did.staging.arcblock.io') // did.staging.arcblock.io 是旧 did domain, 但主要存在于比较旧的节点中, 需要做兼容
279
+ );
280
+
281
+ if (didDomainAlias) {
282
+ appUrl = didDomainAlias.value;
283
+ } else {
284
+ appUrl = `https://${getDidDomainForBlocklet({
285
+ blockletAppDid: appId,
286
+ didDomain: nodeInfo.didDomain,
287
+ })}`;
288
+ }
270
289
 
271
290
  return {
272
291
  BLOCKLET_DID: did,
@@ -1,6 +1,6 @@
1
1
  const slugify = require('slugify');
2
2
  const { DEFAULT_IP_DOMAIN_SUFFIX } = require('@abtnode/constant');
3
- const md5 = require('@abtnode/util/lib/md5');
3
+ const { encode: encodeBase32 } = require('@abtnode/util/lib/base32');
4
4
 
5
5
  const SLOT_FOR_IP_DNS_SITE = '888-888-888-888';
6
6
 
@@ -17,10 +17,8 @@ const getIpDnsDomainForBlocklet = (blocklet, blockletInterface) => {
17
17
  }${iName}-${SLOT_FOR_IP_DNS_SITE}.${DEFAULT_IP_DOMAIN_SUFFIX}`;
18
18
  };
19
19
 
20
- const getDidDomainForBlocklet = ({ name, daemonDid, didDomain }) => {
21
- const prefix = md5(name).substring(0, 8);
22
-
23
- return `${prefix}-${daemonDid.toLowerCase()}.${didDomain}`;
20
+ const getDidDomainForBlocklet = ({ blockletAppDid, didDomain }) => {
21
+ return `${encodeBase32(blockletAppDid)}.${didDomain}`;
24
22
  };
25
23
 
26
24
  module.exports = { getIpDnsDomainForBlocklet, getDidDomainForBlocklet, formatName };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.49",
6
+ "version": "1.8.51",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,18 +19,18 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@abtnode/auth": "1.8.49",
23
- "@abtnode/certificate-manager": "1.8.49",
24
- "@abtnode/constant": "1.8.49",
25
- "@abtnode/cron": "1.8.49",
26
- "@abtnode/db": "1.8.49",
27
- "@abtnode/logger": "1.8.49",
28
- "@abtnode/queue": "1.8.49",
29
- "@abtnode/rbac": "1.8.49",
30
- "@abtnode/router-provider": "1.8.49",
31
- "@abtnode/static-server": "1.8.49",
32
- "@abtnode/timemachine": "1.8.49",
33
- "@abtnode/util": "1.8.49",
22
+ "@abtnode/auth": "1.8.51",
23
+ "@abtnode/certificate-manager": "1.8.51",
24
+ "@abtnode/constant": "1.8.51",
25
+ "@abtnode/cron": "1.8.51",
26
+ "@abtnode/db": "1.8.51",
27
+ "@abtnode/logger": "1.8.51",
28
+ "@abtnode/queue": "1.8.51",
29
+ "@abtnode/rbac": "1.8.51",
30
+ "@abtnode/router-provider": "1.8.51",
31
+ "@abtnode/static-server": "1.8.51",
32
+ "@abtnode/timemachine": "1.8.51",
33
+ "@abtnode/util": "1.8.51",
34
34
  "@arcblock/did": "1.18.32",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
36
  "@arcblock/did-util": "1.18.32",
@@ -38,9 +38,9 @@
38
38
  "@arcblock/jwt": "^1.18.32",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
40
  "@arcblock/vc": "1.18.32",
41
- "@blocklet/constant": "1.8.49",
42
- "@blocklet/meta": "1.8.49",
43
- "@blocklet/sdk": "1.8.49",
41
+ "@blocklet/constant": "1.8.51",
42
+ "@blocklet/meta": "1.8.51",
43
+ "@blocklet/sdk": "1.8.51",
44
44
  "@fidm/x509": "^1.2.1",
45
45
  "@ocap/mcrypto": "1.18.32",
46
46
  "@ocap/util": "1.18.32",
@@ -82,5 +82,5 @@
82
82
  "express": "^4.18.2",
83
83
  "jest": "^27.5.1"
84
84
  },
85
- "gitHead": "627ac4fb21957fcbaf7c2c21e77de0f51ef9e30d"
85
+ "gitHead": "30e929da51edaa22104c4de4e3d1661d790c578c"
86
86
  }