@abtnode/core 1.8.69-beta-650a290b → 1.16.0-beta-b16cb035

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.
@@ -16,7 +16,13 @@ const getBlockletInfo = require('@blocklet/meta/lib/info');
16
16
  const sleep = require('@abtnode/util/lib/sleep');
17
17
 
18
18
  const logger = require('@abtnode/logger')('@abtnode/core:blocklet:manager');
19
- const { WHO_CAN_ACCESS, WHO_CAN_ACCESS_PREFIX_ROLES, BLOCKLET_INSTALL_TYPE, NODE_MODES } = require('@abtnode/constant');
19
+ const {
20
+ WHO_CAN_ACCESS,
21
+ WHO_CAN_ACCESS_PREFIX_ROLES,
22
+ BLOCKLET_INSTALL_TYPE,
23
+ NODE_MODES,
24
+ APP_STRUCT_VERSION,
25
+ } = require('@abtnode/constant');
20
26
 
21
27
  const getBlockletEngine = require('@blocklet/meta/lib/engine');
22
28
  const {
@@ -564,34 +570,19 @@ class BlockletManager extends BaseBlockletManager {
564
570
  * @memberof BlockletManager
565
571
  */
566
572
  // eslint-disable-next-line no-unused-vars
567
- async backupToSpaces({ appPid }, context) {
568
- // add to queue
569
- // const ticket = this.backupQueue.push({
570
- // entity: 'blocklet',
571
- // action: 'backup-to-space',
572
- // appPid,
573
- // context,
574
- // });
575
-
576
- // ticket.on('failed', async (err) => {
577
- // logger.error('backup failed', { entity: 'blocklet', appPid, error: err });
578
- // this.emit('blocklet.backup.failed', { appPid, err });
579
- // this._createNotification(appPid, {
580
- // title: 'Blocklet Backup Failed',
581
- // description: `Blocklet backup failed with error: ${err.message || 'queue exception'}`,
582
- // entityType: 'blocklet',
583
- // entityId: appPid,
584
- // severity: 'error',
585
- // });
586
- // });
573
+ async backupToSpaces({ appDid }, context) {
574
+ const blocklet = await states.blocklet.getBlocklet(appDid);
575
+ if (blocklet.structVersion !== APP_STRUCT_VERSION) {
576
+ throw new Error('Only new version app can be backup to spaces, please migrate this app first');
577
+ }
587
578
 
588
579
  const userDid = context.user.did;
589
580
  const { referrer } = context;
590
581
 
591
- const spacesBackup = new SpacesBackup({ appPid, event: this, userDid, referrer });
592
- this.emit(BlockletEvents.backupProgress, { appPid, message: 'Start backup...', progress: 10, completed: false });
582
+ const spacesBackup = new SpacesBackup({ appDid, event: this, userDid, referrer });
583
+ this.emit(BlockletEvents.backupProgress, { appDid, message: 'Start backup...', progress: 10, completed: false });
593
584
  await spacesBackup.backup();
594
- this.emit(BlockletEvents.backupProgress, { appPid, completed: true, progress: 100 });
585
+ this.emit(BlockletEvents.backupProgress, { appDid, completed: true, progress: 100 });
595
586
  }
596
587
 
597
588
  /**
@@ -605,9 +596,8 @@ class BlockletManager extends BaseBlockletManager {
605
596
  this.emit(BlockletEvents.restoreProgress, { appDid: input.appDid, message: 'Start restore...', completed: false });
606
597
 
607
598
  const userDid = context.user.did;
608
- const { referrer } = context;
609
599
 
610
- const spacesRestore = new SpacesRestore({ ...input, event: this, userDid, referrer });
600
+ const spacesRestore = new SpacesRestore({ ...input, event: this, userDid, referrer: context.referrer });
611
601
  const params = await spacesRestore.restore();
612
602
 
613
603
  this.emit(BlockletEvents.restoreProgress, { appDid: input.appDid, message: 'Installing blocklet...' });
@@ -441,6 +441,10 @@ const migrateApplicationToStructV2 = async ({ did, appSk: newAppSk, context = {}
441
441
 
442
442
  // 通过 event 触发 ensureBlockletRouting
443
443
  manager.emit(BlockletEvents.installed, { blocklet: newBlocklet, context });
444
+ manager.emit(BlockletEvents.removed, {
445
+ blocklet: { meta: { did: oldBlocklet.meta.did } },
446
+ context: { skipAll: true },
447
+ });
444
448
  };
445
449
 
446
450
  module.exports = { migrateApplicationToStructV2, sortMoveListBySrc };
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @typedef {{
3
- * appPid: string
3
+ * appDid: string
4
4
  * event: import('events').EventEmitter,
5
5
  * userDid: string,
6
6
  * referrer: string,
@@ -20,7 +20,6 @@ const { SpaceClient, BackupBlockletCommand } = require('@did-space/client');
20
20
  const { ensureDirSync } = require('fs-extra');
21
21
  const { isEmpty } = require('lodash');
22
22
  const { join, basename } = require('path');
23
- const { signV2 } = require('@arcblock/jwt');
24
23
  const { Hasher } = require('@ocap/mcrypto');
25
24
  const { toBuffer } = require('@ocap/util');
26
25
  const { getAppName, getAppDescription } = require('@blocklet/meta/lib/util');
@@ -109,8 +108,8 @@ class SpacesBackup {
109
108
  * @memberof SpacesBackup
110
109
  */
111
110
  verify(input) {
112
- if (isEmpty(input?.appPid) || !isValid(input?.appPid)) {
113
- throw new Error(`input.appPid(${input?.appPid}) is not a valid did`);
111
+ if (isEmpty(input?.appDid) || !isValid(input?.appDid)) {
112
+ throw new Error(`input.appDid(${input?.appDid}) is not a valid did`);
114
113
  }
115
114
  }
116
115
 
@@ -126,13 +125,13 @@ class SpacesBackup {
126
125
  }
127
126
 
128
127
  async initialize() {
129
- this.blocklet = await states.blocklet.getBlocklet(this.input.appPid);
128
+ this.blocklet = await states.blocklet.getBlocklet(this.input.appDid);
130
129
  if (isEmpty(this.blocklet)) {
131
130
  throw new Error('blocklet cannot be empty');
132
131
  }
133
132
 
134
133
  this.serverDir = process.env.ABT_NODE_DATA_DIR;
135
- this.backupDir = join(this.serverDir, 'tmp/backup', this.blocklet.appPid);
134
+ this.backupDir = join(this.serverDir, 'tmp/backup', this.blocklet.appDid);
136
135
  ensureDirSync(this.backupDir);
137
136
 
138
137
  this.spaceEndpoint = this.blocklet.environments.find(
@@ -147,7 +146,7 @@ class SpacesBackup {
147
146
 
148
147
  async export() {
149
148
  this.input.event.emit(BlockletEvents.backupProgress, {
150
- appPid: this.input.appPid,
149
+ appDid: this.input.appDid,
151
150
  message: 'Preparing data for backup...',
152
151
  progress: 15,
153
152
  completed: false,
@@ -159,7 +158,7 @@ class SpacesBackup {
159
158
  })
160
159
  );
161
160
  this.input.event.emit(BlockletEvents.backupProgress, {
162
- appPid: this.input.appPid,
161
+ appDid: this.input.appDid,
163
162
  message: 'Data ready, start backup...',
164
163
  progress: 20,
165
164
  completed: false,
@@ -181,7 +180,7 @@ class SpacesBackup {
181
180
 
182
181
  const { errorCount, message } = await spaceClient.send(
183
182
  new BackupBlockletCommand({
184
- appDid: this.blocklet.appPid,
183
+ appDid: this.blocklet.appDid,
185
184
  appName: getAppName(this.blocklet),
186
185
  appDescription: getAppDescription(this.blocklet),
187
186
  userDid: this.input.userDid,
@@ -198,10 +197,10 @@ class SpacesBackup {
198
197
  return object.name !== '.DS_Store';
199
198
  },
200
199
  onProgress: (data) => {
201
- logger.info('backup progress', { appDid: this.input.appPid, data });
200
+ logger.info('backup progress', { appDid: this.input.appDid, data });
202
201
  const percent = (data.completed * 100) / data.total;
203
202
  this.input.event.emit(BlockletEvents.backupProgress, {
204
- appPid: this.input.appPid,
203
+ appDid: this.input.appDid,
205
204
  message: `Uploaded file ${basename(data.key)} (${data.completed}/${data.total})`,
206
205
  // 0.8 是因为上传文件到 spaces 占进度的 80%,+ 20 是因为需要累加之前的进度
207
206
  progress: +Math.ceil(percent * 0.8).toFixed(2) + 20,
@@ -217,30 +216,19 @@ class SpacesBackup {
217
216
  }
218
217
 
219
218
  async getSecurityContext() {
220
- const blocklet = await states.blocklet.getBlocklet(this.input.appPid);
219
+ const blocklet = await states.blocklet.getBlocklet(this.input.appDid);
221
220
  const nodeInfo = await states.node.read();
222
221
 
223
- const { wallet, permanentWallet } = getBlockletInfo(blocklet, nodeInfo.sk);
222
+ const { wallet } = getBlockletInfo(blocklet, nodeInfo.sk);
224
223
 
225
224
  const { secretKey, address } = wallet; // we encrypt using latest wallet, not the permanent wallet
226
225
  const password = toBuffer(Hasher.SHA3.hash256(Buffer.concat([secretKey, address].map(toBuffer))));
227
226
  const encrypt = (v) => security.encrypt(v, address, password);
228
227
  const decrypt = (v) => security.decrypt(v, address, password);
229
- const isRotated = permanentWallet.address !== wallet.address;
230
-
231
- const delegation = isRotated
232
- ? signV2(permanentWallet.address, permanentWallet.secretKey, {
233
- from: permanentWallet.address,
234
- to: wallet.address,
235
- userPk: permanentWallet.publicKey,
236
- permissions: [{ role: 'DIDSpaceAgent', spaces: ['*'] }],
237
- exp: Math.floor(new Date().getTime() / 1000) + 60 * 60,
238
- })
239
- : '';
240
228
 
241
229
  return {
242
230
  signer: wallet,
243
- delegation,
231
+ delegation: '',
244
232
  encrypt,
245
233
  decrypt,
246
234
  };
@@ -1,6 +1,8 @@
1
1
  const { removeSync, outputJsonSync, readJSONSync } = require('fs-extra');
2
2
  const { join } = require('path');
3
+ const { APP_STRUCT_VERSION } = require('@abtnode/constant');
3
4
  const security = require('@abtnode/util/lib/security');
5
+
4
6
  const { BaseRestore } = require('./base');
5
7
 
6
8
  class BlockletRestore extends BaseRestore {
@@ -42,7 +44,12 @@ class BlockletRestore extends BaseRestore {
42
44
  }
43
45
 
44
46
  getImportParams() {
45
- return { salt: this.getBlocklet().appDid };
47
+ const blocklet = this.getBlocklet();
48
+ if (blocklet.structVersion !== APP_STRUCT_VERSION) {
49
+ throw new Error('Only new version backup can be restored to this server');
50
+ }
51
+
52
+ return { salt: blocklet.appDid };
46
53
  }
47
54
  }
48
55
 
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * @typedef {{
3
- * appDid: string; // --> appPid
3
+ * appDid: string; // --> appDid
4
4
  * endpoint: string;
5
5
  * password: Buffer; // derived from (appSk, appDid)
6
- * delegation: string; // from appPid --> serverDid for downloading
6
+ * delegation: string; // from appDid --> serverDid for downloading
7
7
  * wallet: import('@ocap/wallet').WalletObject; // server wallet
8
8
  * event: import('events').EventEmitter,
9
9
  * userDid: string,
package/lib/event.js CHANGED
@@ -107,6 +107,10 @@ module.exports = ({
107
107
  };
108
108
 
109
109
  const handleBlockletRemove = async (name, { blocklet, context }) => {
110
+ if (context?.skipAll) {
111
+ return;
112
+ }
113
+
110
114
  try {
111
115
  const changed = await removeBlockletRouting(blocklet, context);
112
116
 
@@ -309,7 +309,7 @@ const getAppSystemEnvironments = (blocklet, nodeInfo) => {
309
309
  }
310
310
 
311
311
  return {
312
- BLOCKLET_DID: did,
312
+ BLOCKLET_DID: did, // BLOCKLET_DID is always same as BLOCKLET_APP_PID in structV2 application
313
313
  BLOCKLET_APP_SK: appSk,
314
314
  BLOCKLET_APP_ID: appId,
315
315
  BLOCKLET_APP_PSK: appPsk, // permanent sk even the blocklet has been migrated
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.69-beta-650a290b",
6
+ "version": "1.16.0-beta-b16cb035",
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.69-beta-650a290b",
23
- "@abtnode/certificate-manager": "1.8.69-beta-650a290b",
24
- "@abtnode/constant": "1.8.69-beta-650a290b",
25
- "@abtnode/cron": "1.8.69-beta-650a290b",
26
- "@abtnode/db": "1.8.69-beta-650a290b",
27
- "@abtnode/logger": "1.8.69-beta-650a290b",
28
- "@abtnode/queue": "1.8.69-beta-650a290b",
29
- "@abtnode/rbac": "1.8.69-beta-650a290b",
30
- "@abtnode/router-provider": "1.8.69-beta-650a290b",
31
- "@abtnode/static-server": "1.8.69-beta-650a290b",
32
- "@abtnode/timemachine": "1.8.69-beta-650a290b",
33
- "@abtnode/util": "1.8.69-beta-650a290b",
22
+ "@abtnode/auth": "1.16.0-beta-b16cb035",
23
+ "@abtnode/certificate-manager": "1.16.0-beta-b16cb035",
24
+ "@abtnode/constant": "1.16.0-beta-b16cb035",
25
+ "@abtnode/cron": "1.16.0-beta-b16cb035",
26
+ "@abtnode/db": "1.16.0-beta-b16cb035",
27
+ "@abtnode/logger": "1.16.0-beta-b16cb035",
28
+ "@abtnode/queue": "1.16.0-beta-b16cb035",
29
+ "@abtnode/rbac": "1.16.0-beta-b16cb035",
30
+ "@abtnode/router-provider": "1.16.0-beta-b16cb035",
31
+ "@abtnode/static-server": "1.16.0-beta-b16cb035",
32
+ "@abtnode/timemachine": "1.16.0-beta-b16cb035",
33
+ "@abtnode/util": "1.16.0-beta-b16cb035",
34
34
  "@arcblock/did": "1.18.59",
35
35
  "@arcblock/did-motif": "^1.1.10",
36
36
  "@arcblock/did-util": "1.18.59",
@@ -38,9 +38,9 @@
38
38
  "@arcblock/jwt": "^1.18.59",
39
39
  "@arcblock/pm2-events": "^0.0.5",
40
40
  "@arcblock/vc": "1.18.59",
41
- "@blocklet/constant": "1.8.69-beta-650a290b",
42
- "@blocklet/meta": "1.8.69-beta-650a290b",
43
- "@blocklet/sdk": "1.8.69-beta-650a290b",
41
+ "@blocklet/constant": "1.16.0-beta-b16cb035",
42
+ "@blocklet/meta": "1.16.0-beta-b16cb035",
43
+ "@blocklet/sdk": "1.16.0-beta-b16cb035",
44
44
  "@did-space/client": "^0.2.33",
45
45
  "@fidm/x509": "^1.2.1",
46
46
  "@ocap/client": "1.18.59",
@@ -91,5 +91,5 @@
91
91
  "express": "^4.18.2",
92
92
  "jest": "^27.5.1"
93
93
  },
94
- "gitHead": "a33c9ce6a52b8d522d13860e85809dcbba236712"
94
+ "gitHead": "138bd91aee5a35b28c2de4e1e924c44932efaf3a"
95
95
  }