@abtnode/core 1.16.8-beta-186fd5aa → 1.16.8-next-d1e52353

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 (38) hide show
  1. package/lib/api/team.js +24 -64
  2. package/lib/blocklet/manager/disk.js +2 -8
  3. package/lib/blocklet/manager/helper/migrate-application-to-struct-v2.js +5 -5
  4. package/lib/blocklet/storage/backup/blocklet-extras.js +2 -2
  5. package/lib/blocklet/storage/backup/blocklet.js +2 -2
  6. package/lib/index.js +14 -16
  7. package/lib/migrations/1.16.8-component-title.js +1 -1
  8. package/lib/migrations/1.6.9-update-node-info-and-certificate.js +1 -1
  9. package/lib/migrations/index.js +190 -40
  10. package/lib/monitor/node-runtime-monitor.js +2 -29
  11. package/lib/router/helper.js +6 -6
  12. package/lib/router/manager.js +35 -36
  13. package/lib/states/access-key.js +3 -20
  14. package/lib/states/audit-log.js +7 -8
  15. package/lib/states/backup.js +11 -59
  16. package/lib/states/base.js +13 -5
  17. package/lib/states/blocklet-extras.js +11 -8
  18. package/lib/states/blocklet.js +136 -225
  19. package/lib/states/cache.js +3 -21
  20. package/lib/states/connect-account.js +8 -0
  21. package/lib/states/index.js +28 -18
  22. package/lib/states/job.js +8 -0
  23. package/lib/states/migration.js +3 -4
  24. package/lib/states/node.js +104 -145
  25. package/lib/states/notification.js +18 -40
  26. package/lib/states/passport.js +8 -0
  27. package/lib/states/session.js +28 -44
  28. package/lib/states/site.js +32 -39
  29. package/lib/states/user.js +187 -374
  30. package/lib/states/webhook.js +5 -7
  31. package/lib/team/manager.js +108 -116
  32. package/lib/util/blocklet.js +0 -1
  33. package/lib/util/index.js +3 -0
  34. package/lib/util/queue.js +14 -20
  35. package/lib/util/ready.js +1 -1
  36. package/lib/webhook/index.js +6 -4
  37. package/package.json +19 -18
  38. package/lib/states/challenge.js +0 -58
@@ -3,11 +3,10 @@ const logger = require('@abtnode/logger')('@abtnode/core:states:webhook');
3
3
  const BaseState = require('./base');
4
4
  const { validateWebhook } = require('../validators/webhook');
5
5
 
6
+ /**
7
+ * @extends BaseState<import('@abtnode/models').WebHookState>
8
+ */
6
9
  class WebhookState extends BaseState {
7
- constructor(baseDir, config = {}) {
8
- super(baseDir, { filename: 'webhook.db', ...config });
9
- }
10
-
11
10
  async create(info, { mock } = {}) {
12
11
  const { type, params } = info;
13
12
  const filterParams = params.map((item) => {
@@ -46,7 +45,7 @@ class WebhookState extends BaseState {
46
45
  throw new Error('webhookId should not be empty');
47
46
  }
48
47
  const webhook = await this.findOne(id);
49
- const num = await this.remove({ _id: id });
48
+ const num = await this.remove({ id });
50
49
  if (num <= 0) {
51
50
  throw new Error(`${id} does not exist`);
52
51
  }
@@ -56,8 +55,7 @@ class WebhookState extends BaseState {
56
55
 
57
56
  async findOne(id) {
58
57
  try {
59
- const webhook = await super.findOne({ _id: id });
60
-
58
+ const webhook = await super.findOne({ id });
61
59
  return webhook;
62
60
  } catch (error) {
63
61
  throw new Error(`webhook with id ${id} not exist`);
@@ -1,3 +1,4 @@
1
+ /* eslint-disable global-require */
1
2
  /**
2
3
  * Access Control Manager is the business logic layer of access control related
3
4
  */
@@ -7,22 +8,36 @@ const upperFirst = require('lodash/upperFirst');
7
8
  const get = require('lodash/get');
8
9
  const pick = require('lodash/pick');
9
10
 
10
- const { createRBAC, MemoryStorage, NedbStorage } = require('@abtnode/rbac');
11
+ const { createRBAC, MemoryStorage, SequelizeStorage } = require('@abtnode/rbac');
11
12
  const logger = require('@abtnode/logger')('@abtnode/core:team:manager');
12
13
  const { ROLES, RBAC_CONFIG } = require('@abtnode/constant');
13
14
  const { BlockletEvents } = require('@blocklet/constant');
14
15
  const Lock = require('@abtnode/util/lib/lock');
15
16
  const sleep = require('@abtnode/util/lib/sleep');
16
- const UserState = require('../states/user');
17
- const SessionState = require('../states/session');
17
+ const { BaseState, doSchemaMigration, createSequelize, getBlockletModels, setupModels } = require('@abtnode/models');
18
18
 
19
- const { isCLI } = require('../util');
19
+ const { isCLI, getDbFilePath } = require('../util');
20
20
 
21
21
  const rbacCreationLock = new Lock('rbac-creation-lock');
22
22
 
23
+ const States = {
24
+ User: require('../states/user'),
25
+ Passport: require('../states/passport'),
26
+ ConnectedAccount: require('../states/connect-account'),
27
+ Session: require('../states/session'),
28
+ };
29
+
30
+ const getDefaultTeamState = () => ({
31
+ rbac: null,
32
+ user: null,
33
+ passport: null,
34
+ connectedAccount: null,
35
+ session: null,
36
+ });
37
+
23
38
  const closeDatabase = async (db) =>
24
39
  new Promise((resolve, reject) => {
25
- if (!db) {
40
+ if (!db || process.env.NODE_ENV === 'test') {
26
41
  resolve(true);
27
42
  return;
28
43
  }
@@ -53,6 +68,8 @@ class TeamManager extends EventEmitter {
53
68
  // cache: { [did]: { rbac, user, session } }
54
69
  this.cache = {};
55
70
 
71
+ this.models = new Map();
72
+
56
73
  this.init();
57
74
  }
58
75
 
@@ -60,11 +77,7 @@ class TeamManager extends EventEmitter {
60
77
  // listen blocklet state
61
78
  ['add', 'upgrade'].forEach((event) => {
62
79
  this.states.blocklet.on(event, ({ meta: { did } }) => {
63
- this.cache[did] = {
64
- rbac: null,
65
- user: null,
66
- session: null,
67
- };
80
+ this.cache[did] = getDefaultTeamState();
68
81
  });
69
82
  });
70
83
 
@@ -73,119 +86,69 @@ class TeamManager extends EventEmitter {
73
86
  .getBlocklets()
74
87
  .then((blocklets) => {
75
88
  blocklets.forEach(({ meta: { did } }) => {
76
- this.cache[did] = {
77
- rbac: null,
78
- user: null,
79
- session: null,
80
- };
89
+ this.cache[did] = getDefaultTeamState();
81
90
  });
82
91
  })
83
92
  .catch((error) => {
84
93
  logger.error('get blocklets failed', error);
85
94
  });
86
95
 
87
- // init abtnode
88
- this.cache[this.nodeDid] = {
89
- rbac: null,
90
- user: null,
91
- session: null,
92
- };
93
-
94
- logger.info('init node rbac', { nodeDid: this.nodeDid });
95
-
96
- const rbac = await createRBAC({ storage: new MemoryStorage(), data: RBAC_CONFIG });
97
-
98
- logger.info('init node user', { nodeDid: this.nodeDid });
99
- const user = await this.createUserState(this.nodeDid);
100
-
101
- logger.info('init node session', { nodeDid: this.nodeDid });
102
- const session = await this.createSessionState(this.nodeDid);
96
+ // init server
97
+ this.cache[this.nodeDid] = getDefaultTeamState();
98
+ logger.info('init node team manager', { nodeDid: this.nodeDid });
103
99
 
104
100
  this.cache[this.nodeDid] = {
105
- rbac,
106
- user,
107
- session,
101
+ rbac: await createRBAC({ storage: new MemoryStorage(), data: RBAC_CONFIG }),
102
+ user: await this.createState(this.nodeDid, 'User'),
103
+ passport: await this.createState(this.nodeDid, 'Passport'),
104
+ connectedAccount: await this.createState(this.nodeDid, 'ConnectedAccount'),
105
+ session: await this.createState(this.nodeDid, 'Session'),
108
106
  };
109
107
  }
110
108
 
111
- // user state
112
-
113
- async getUserState(did) {
114
- const pid = await this.getPid(did);
115
-
116
- // validate exist
117
- if (!pid) {
118
- logger.error('Did does not exist', { action: 'getUserState', did });
119
- throw new Error(`Did does not exist: ${did}`);
120
- }
121
-
122
- if (!this.cache[pid]) {
123
- this.cache[pid] = {
124
- rbac: null,
125
- user: null,
126
- session: null,
127
- };
128
- }
129
-
130
- // first get userState after blocklet added
131
- if (!this.cache[pid].user) {
132
- const user = await this.createUserState(did);
133
- logger.info('Team state created', { teamDid: did });
134
- this.cache[pid].user = user;
135
- return user;
136
- }
137
-
138
- // use cache
139
- return this.cache[pid].user;
109
+ async getUserState(teamDid) {
110
+ return this.getState(teamDid, 'user');
140
111
  }
141
112
 
142
- async createUserState(did) {
143
- const dir = await this.getDataDirByDid(did);
144
- const userState = new UserState(dir);
145
- return new Promise((resolve) => {
146
- userState.onReady(() => {
147
- resolve(userState);
148
- });
149
- });
113
+ async getPassportState(teamDid) {
114
+ return this.getState(teamDid, 'passport');
150
115
  }
151
116
 
152
- // session state
117
+ async getConnectedAccount(teamDid) {
118
+ return this.getState(teamDid, 'connectedAccount');
119
+ }
153
120
 
154
- async getSessionState(did) {
155
- const pid = await this.getPid(did);
121
+ async getSessionState(teamDid) {
122
+ return this.getState(teamDid, 'session');
123
+ }
156
124
 
157
- // validate exist
125
+ async getState(teamDid, key) {
126
+ const pid = await this.getPid(teamDid);
158
127
  if (!pid) {
159
- logger.error('Did does not exist', { action: 'getSessionState', did });
160
- throw new Error(`Did does not exist: ${did}`);
128
+ logger.error('teamDid does not exist', { action: 'getState', key, teamDid });
129
+ throw new Error(`teamDid does not exist: ${teamDid}`);
161
130
  }
162
131
 
163
132
  if (!this.cache[pid]) {
164
- this.cache[pid] = {
165
- rbac: null,
166
- user: null,
167
- session: null,
168
- };
133
+ this.cache[pid] = getDefaultTeamState();
169
134
  }
170
135
 
171
- // first get userState after blocklet added
172
- if (!this.cache[pid].session) {
173
- const session = await this.createSessionState(pid);
174
- logger.info('session state created', { did, pid });
175
- this.cache[pid].session = session;
176
- return session;
136
+ if (this.cache[pid][key]) {
137
+ return this.cache[pid][key];
177
138
  }
178
139
 
179
- // use cache
180
- return this.cache[pid].session;
140
+ const state = await this.createState(teamDid, upperFirst(key));
141
+ logger.info(`${key} state created`, { teamDid });
142
+ this.cache[pid][key] = state;
143
+ return state;
181
144
  }
182
145
 
183
- async createSessionState(did) {
184
- const dir = await this.getDataDirByDid(did);
185
- const sessionState = new SessionState(dir);
146
+ async createState(did, key) {
147
+ const models = await this.getModels(did);
148
+ const state = new States[key](models[key], {}, models);
186
149
  return new Promise((resolve) => {
187
- sessionState.onReady(() => {
188
- resolve(sessionState);
150
+ state.onReady(() => {
151
+ resolve(state);
189
152
  });
190
153
  });
191
154
  }
@@ -202,11 +165,7 @@ class TeamManager extends EventEmitter {
202
165
  }
203
166
 
204
167
  if (!this.cache[pid]) {
205
- this.cache[pid] = {
206
- rbac: null,
207
- user: null,
208
- session: null,
209
- };
168
+ this.cache[pid] = getDefaultTeamState();
210
169
  }
211
170
 
212
171
  // first getRBAC after blocklet added
@@ -219,8 +178,9 @@ class TeamManager extends EventEmitter {
219
178
  await rbacCreationLock.acquire();
220
179
  try {
221
180
  logger.info('create rbac', { did });
222
- const file = await this.getRbacFileByDid(pid);
223
- const rbac = await createRBAC({ storage: new NedbStorage({ file }) });
181
+ const models = await this.getModels(did);
182
+ const db = new BaseState(models.Rbac);
183
+ const rbac = await createRBAC({ storage: new SequelizeStorage(db) });
224
184
  this.cache[pid].rbac = rbac;
225
185
 
226
186
  const roles = await rbac.getRoles();
@@ -351,9 +311,7 @@ class TeamManager extends EventEmitter {
351
311
 
352
312
  async getRoles(did) {
353
313
  const rbac = await this.getRBAC(did);
354
-
355
314
  const roles = await rbac.getRoles();
356
-
357
315
  return roles.map((d) => pick(d, ['name', 'grants', 'title', 'description']));
358
316
  }
359
317
 
@@ -365,18 +323,25 @@ class TeamManager extends EventEmitter {
365
323
 
366
324
  logger.info('initTeam', { did });
367
325
 
326
+ await this.getModels(did);
327
+
368
328
  const rbac = await this.getRBAC(did);
369
- const user = await this.getUserState(did);
370
- const session = await this.getSessionState(did);
329
+ const user = await this.createState(did, 'User');
330
+ const passport = await this.createState(did, 'Passport');
331
+ const connectedAccount = await this.createState(did, 'ConnectedAccount');
332
+ const session = await this.createState(did, 'Session');
371
333
 
372
334
  this.cache[did] = {
373
335
  rbac,
374
336
  user,
375
337
  session,
338
+ passport,
339
+ connectedAccount,
376
340
  };
377
341
  }
378
342
 
379
- async deleteTeam(did, { closeDatabase: closeDB = true } = {}) {
343
+ // FIXME: @wangshijun should we clear models cache here
344
+ async deleteTeam(did, { closeDatabase: closeDB = false } = {}) {
380
345
  if (!did) {
381
346
  logger.error('deleteTeam: did does not exist');
382
347
  return;
@@ -385,17 +350,21 @@ class TeamManager extends EventEmitter {
385
350
  logger.info('deleteTeam', { did, closeDB });
386
351
 
387
352
  const pid = await this.getPid(did);
388
-
389
353
  if (closeDB && this.cache[pid]) {
354
+ logger.info('deleteTeam.closeDatabase', { did });
390
355
  try {
391
356
  if (this.cache[pid].rbac) {
392
357
  await closeDatabase(this.cache[pid].rbac.storage.db);
393
358
  }
394
-
395
359
  if (this.cache[pid].user) {
396
360
  await closeDatabase(this.cache[pid].user.db);
397
361
  }
398
-
362
+ if (this.cache[pid].passport) {
363
+ await closeDatabase(this.cache[pid].passport.db);
364
+ }
365
+ if (this.cache[pid].connectedAccount) {
366
+ await closeDatabase(this.cache[pid].connectedAccount.db);
367
+ }
399
368
  if (this.cache[pid].session) {
400
369
  await closeDatabase(this.cache[pid].session.db);
401
370
  }
@@ -415,10 +384,9 @@ class TeamManager extends EventEmitter {
415
384
  // =======
416
385
  // Private
417
386
  // =======
418
-
419
- async getRbacFileByDid(did) {
387
+ async getDataFileByDid(did) {
420
388
  const dir = await this.getDataDirByDid(did);
421
- return path.join(dir, 'rbac.db');
389
+ return getDbFilePath(path.join(dir, 'blocklet.db'));
422
390
  }
423
391
 
424
392
  async getDataDirByDid(did) {
@@ -430,12 +398,36 @@ class TeamManager extends EventEmitter {
430
398
  return path.join(this.dataDirs.data, blocklet.meta.name);
431
399
  }
432
400
 
433
- async getPid(did) {
401
+ async getModels(did) {
402
+ if (this.isNodeTeam(did)) {
403
+ return this.states.models;
404
+ }
405
+
406
+ if (this.models.has(did) === false) {
407
+ const file = await this.getDataFileByDid(did);
408
+ const sequelize = createSequelize(file);
409
+ const models = getBlockletModels();
410
+ logger.info('initModels', { did, models: Object.keys(models) });
411
+ setupModels(models, sequelize);
412
+ await this.initDatabase(did);
413
+ this.models.set(did, models);
414
+ }
415
+
416
+ return this.models.get(did);
417
+ }
418
+
419
+ async initDatabase(did) {
434
420
  if (this.isNodeTeam(did)) {
435
- return did;
421
+ return;
436
422
  }
437
423
 
438
- return this.states.blocklet.getBlockletMetaDid(did);
424
+ const dbPath = await this.getDataFileByDid(did);
425
+ logger.info('initDatabase', { did, dbPath });
426
+ await doSchemaMigration(dbPath, 'blocklet');
427
+ }
428
+
429
+ async getPid(did) {
430
+ return this.isNodeTeam(did) ? did : this.states.blocklet.getBlockletMetaDid(did);
439
431
  }
440
432
  }
441
433
 
@@ -125,7 +125,6 @@ const statusMap = {
125
125
  };
126
126
 
127
127
  const PRIVATE_NODE_ENVS = [
128
- 'NEDB_MULTI_PORT',
129
128
  'ABT_NODE_UPDATER_PORT',
130
129
  'ABT_NODE_SESSION_TTL',
131
130
  'ABT_NODE_ROUTER_PROVIDER',
package/lib/util/index.js CHANGED
@@ -467,6 +467,8 @@ const isBlockletSite = (domain) => domain.endsWith(BLOCKLET_SITE_GROUP_SUFFIX);
467
467
  const isServerSite = (domain) =>
468
468
  [DOMAIN_FOR_DEFAULT_SITE, DOMAIN_FOR_IP_SITE, DOMAIN_FOR_IP_SITE_REGEXP].includes(domain);
469
469
 
470
+ const getDbFilePath = (filePath) => (process.env.NODE_ENV === 'test' ? `${filePath}:memory:` : filePath);
471
+
470
472
  const lib = {
471
473
  validateOwner,
472
474
  getProviderFromNodeInfo,
@@ -502,6 +504,7 @@ const lib = {
502
504
  isGatewayCacheEnabled,
503
505
  isBlockletSite,
504
506
  isServerSite,
507
+ getDbFilePath,
505
508
  };
506
509
 
507
510
  module.exports = lib;
package/lib/util/queue.js CHANGED
@@ -1,8 +1,18 @@
1
- const path = require('path');
2
1
  const createQueue = require('@abtnode/queue');
2
+ const QueueStore = require('@abtnode/queue/lib/store/sequelize');
3
3
 
4
4
  /**
5
- *
5
+ * @param {object} params
6
+ * @param {string} params.name name of the queue
7
+ * @param {object} params.model model
8
+ * @param {function} params.onJob called on receives job
9
+ * @param {boolean} params.daemon [param=false] is the running in a daemon environment, default false
10
+ * @param {object} params.options options
11
+ * @param {any} [params.options.id] id of the job
12
+ * @param {number} [params.options.concurrency] [param=1] number of concurrent jobs
13
+ * @param {number} [params.options.maxRetries] [param=1] number of max retries, default 1
14
+ * @param {number} [params.options.maxTimeout] [param=86400000] max timeout, in ms, default 86400000ms(1d)
15
+ * @param {number} [params.options.retryDelay] [param=0] retry delay, in ms, default 0ms
6
16
  * @typedef {
7
17
  * EventEmitter & {
8
18
  * store: JobStore;
@@ -18,26 +28,10 @@ const createQueue = require('@abtnode/queue');
18
28
  * }
19
29
  * } Queue
20
30
  */
21
-
22
- /**
23
- *
24
- * @param {Object} Options
25
- * @param {string} Options.name name of the queue
26
- * @param {string} Options.dataDir directory path of the queue data
27
- * @param {function} Options.onJob called on receives job
28
- * @param {boolean} Options.daemon [param=false] is the running in a daemon environment, default false
29
- * @param {Object} Options.options options
30
- * @param {string} Options.options.id id of the job
31
- * @param {number} Options.options.concurrency [param=1] number of concurrent jobs
32
- * @param {number} Options.options.maxRetries [param=1] number of max retries, default 1
33
- * @param {number} Options.options.maxTimeout [param=86400000] max timeout, in ms, default 86400000ms(1d)
34
- * @param {number} Options.options.retryDelay [param=0] retry delay, in ms, default 0ms
35
- * @returns {Queue}
36
- */
37
- module.exports = ({ name, dataDir, onJob, daemon = false, options = {} }) => {
31
+ module.exports = ({ name, model, onJob, daemon = false, options = {} }) => {
38
32
  if (daemon) {
39
33
  const queue = createQueue({
40
- file: path.join(dataDir, `${name}.db`),
34
+ store: new QueueStore(model, name),
41
35
  onJob,
42
36
  options,
43
37
  });
package/lib/util/ready.js CHANGED
@@ -27,7 +27,7 @@ const createStateReadyHandler =
27
27
  const count = await states.node.count();
28
28
  if (count > 1) {
29
29
  // eslint-disable-next-line no-underscore-dangle
30
- await states.node.remove({ _id: state._id });
30
+ await states.node.remove({ did: state.did });
31
31
  console.error('\n\x1b[31m======================================================');
32
32
  console.error(`Data dir: ${options.dataDir} is used by another Blocklet Server instance, abort!`);
33
33
  console.error('Sharing data dir between Blocklet Server instances may break things!');
@@ -31,11 +31,11 @@ const getSlackUrlInfo = async (actionPath = '/notifications', urls) => {
31
31
  });
32
32
  }
33
33
 
34
- const prioritys = await evaluateURLs(
34
+ const priorities = await evaluateURLs(
35
35
  urls.map((item) => item.url),
36
- { checkAccessble: checkURLAccessible }
36
+ { checkAccessible: checkURLAccessible }
37
37
  );
38
- const priorityUrl = prioritys[0].url;
38
+ const priorityUrl = priorities[0].url;
39
39
 
40
40
  const { protocol } = new URL(priorityUrl);
41
41
  const normalized = `${priorityUrl}${actionPath}`.replace(`${protocol}//`, '').replace(/\/+/g, '/');
@@ -60,6 +60,7 @@ const getSlackUrlInfo = async (actionPath = '/notifications', urls) => {
60
60
  return info;
61
61
  };
62
62
 
63
+ // eslint-disable-next-line no-unused-vars
63
64
  module.exports = ({ events, dataDirs, instance }) => {
64
65
  const nodeState = states.node;
65
66
  const webhookState = states.webhook;
@@ -105,8 +106,9 @@ module.exports = ({ events, dataDirs, instance }) => {
105
106
 
106
107
  const queue = createQueue({
107
108
  name: 'webhook-messages',
108
- dataDir: dataDirs.core,
109
+ model: states.job,
109
110
  daemon: true,
111
+ options: {},
110
112
  onJob: async (job) => {
111
113
  if (job.entityType === 'webhook') {
112
114
  return;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.16.8-beta-186fd5aa",
6
+ "version": "1.16.8-next-d1e52353",
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.16.8-beta-186fd5aa",
23
- "@abtnode/certificate-manager": "1.16.8-beta-186fd5aa",
24
- "@abtnode/constant": "1.16.8-beta-186fd5aa",
25
- "@abtnode/cron": "1.16.8-beta-186fd5aa",
26
- "@abtnode/db": "1.16.8-beta-186fd5aa",
27
- "@abtnode/logger": "1.16.8-beta-186fd5aa",
28
- "@abtnode/queue": "1.16.8-beta-186fd5aa",
29
- "@abtnode/rbac": "1.16.8-beta-186fd5aa",
30
- "@abtnode/router-provider": "1.16.8-beta-186fd5aa",
31
- "@abtnode/static-server": "1.16.8-beta-186fd5aa",
32
- "@abtnode/timemachine": "1.16.8-beta-186fd5aa",
33
- "@abtnode/util": "1.16.8-beta-186fd5aa",
22
+ "@abtnode/auth": "1.16.8-next-d1e52353",
23
+ "@abtnode/certificate-manager": "1.16.8-next-d1e52353",
24
+ "@abtnode/constant": "1.16.8-next-d1e52353",
25
+ "@abtnode/cron": "1.16.8-next-d1e52353",
26
+ "@abtnode/logger": "1.16.8-next-d1e52353",
27
+ "@abtnode/models": "1.16.8-next-d1e52353",
28
+ "@abtnode/queue": "1.16.8-next-d1e52353",
29
+ "@abtnode/rbac": "1.16.8-next-d1e52353",
30
+ "@abtnode/router-provider": "1.16.8-next-d1e52353",
31
+ "@abtnode/static-server": "1.16.8-next-d1e52353",
32
+ "@abtnode/timemachine": "1.16.8-next-d1e52353",
33
+ "@abtnode/util": "1.16.8-next-d1e52353",
34
34
  "@arcblock/did": "1.18.78",
35
35
  "@arcblock/did-auth": "1.18.78",
36
36
  "@arcblock/did-ext": "^1.18.78",
@@ -41,9 +41,9 @@
41
41
  "@arcblock/pm2-events": "^0.0.5",
42
42
  "@arcblock/validator": "^1.18.78",
43
43
  "@arcblock/vc": "1.18.78",
44
- "@blocklet/constant": "1.16.8-beta-186fd5aa",
45
- "@blocklet/meta": "1.16.8-beta-186fd5aa",
46
- "@blocklet/sdk": "1.16.8-beta-186fd5aa",
44
+ "@blocklet/constant": "1.16.8-next-d1e52353",
45
+ "@blocklet/meta": "1.16.8-next-d1e52353",
46
+ "@blocklet/sdk": "1.16.8-next-d1e52353",
47
47
  "@did-space/client": "^0.2.91",
48
48
  "@fidm/x509": "^1.2.1",
49
49
  "@ocap/mcrypto": "1.18.78",
@@ -77,6 +77,7 @@
77
77
  "p-limit": "^3.1.0",
78
78
  "p-retry": "4.6.1",
79
79
  "semver": "^7.3.8",
80
+ "sequelize": "^6.31.0",
80
81
  "shelljs": "^0.8.5",
81
82
  "ssri": "^8.0.1",
82
83
  "stream-throttle": "^0.1.3",
@@ -86,7 +87,7 @@
86
87
  "transliteration": "^2.3.5",
87
88
  "ua-parser-js": "^1.0.2",
88
89
  "url-join": "^4.0.1",
89
- "uuid": "7.0.3",
90
+ "uuid": "^8.3.2",
90
91
  "valid-url": "^1.0.9"
91
92
  },
92
93
  "devDependencies": {
@@ -95,5 +96,5 @@
95
96
  "express": "^4.18.2",
96
97
  "jest": "^27.5.1"
97
98
  },
98
- "gitHead": "3150c3a5c3e041fe7f5a3902418d9d62adee3173"
99
+ "gitHead": "d357376aa3df9ef789befc7f548629deecb04d96"
99
100
  }
@@ -1,58 +0,0 @@
1
- const Mcrypto = require('@ocap/mcrypto');
2
- const { fromPublicKey } = require('@ocap/wallet');
3
- const { stripHexPrefix } = require('@ocap/util');
4
- const logger = require('@abtnode/logger')('@abtnode/core:states:challenge');
5
-
6
- const BaseState = require('./base');
7
-
8
- class ChallengeState extends BaseState {
9
- /**
10
- * Creates an instance of ChallengeState
11
- * @param {string} baseDir
12
- * @param {object} config
13
- * @memberof ChallengeState
14
- */
15
- constructor(baseDir, config = {}) {
16
- super(baseDir, { filename: 'challenge.db', ...config });
17
- }
18
-
19
- generate() {
20
- return new Promise((resolve, reject) => {
21
- const challenge = stripHexPrefix(Mcrypto.getRandomBytes(16)).toUpperCase();
22
- this.insert({ challenge }, (err, data) => {
23
- if (err) {
24
- logger.error('generating error', { error: err });
25
- return reject(err);
26
- }
27
-
28
- logger.info('generated', { data });
29
- return resolve(challenge);
30
- });
31
- });
32
- }
33
-
34
- verify(challenge, publicKey, signature) {
35
- return new Promise((resolve, reject) => {
36
- if (!signature) {
37
- reject(new Error('Cannot verify challenge without signature.'));
38
- return;
39
- }
40
-
41
- this.findOne({ challenge }, (err, data) => {
42
- if (err) {
43
- logger.error('error find challenge', { error: err });
44
- }
45
-
46
- if (data) {
47
- // TODO: we may need wallet type info here from wallet did
48
- const wallet = fromPublicKey(publicKey);
49
- return resolve(wallet.verify(challenge, signature));
50
- }
51
-
52
- return resolve(false);
53
- });
54
- });
55
- }
56
- }
57
-
58
- module.exports = ChallengeState;