@abtnode/auth 1.5.3 → 1.5.4

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/auth.js CHANGED
@@ -198,6 +198,7 @@ const getIssuer = async ({ node, nodeInfo, teamDid }) => {
198
198
 
199
199
  const createAuthToken = ({ did, passport, role, secret, expiresIn } = {}) => {
200
200
  const payload = {
201
+ type: 'user',
201
202
  did,
202
203
  role,
203
204
  };
@@ -213,6 +214,15 @@ const createAuthToken = ({ did, passport, role, secret, expiresIn } = {}) => {
213
214
  return token;
214
215
  };
215
216
 
217
+ const createAuthTokenByOwnershipNFT = ({ role, secret, expiresIn } = {}) => {
218
+ const payload = {
219
+ type: 'ownership_nft',
220
+ role,
221
+ };
222
+
223
+ return jwt.sign(payload, secret, { expiresIn });
224
+ };
225
+
216
226
  const getUser = async (node, teamDid, userDid) => {
217
227
  const user = await node.getUser({ teamDid, user: { did: userDid } });
218
228
  return user;
@@ -255,7 +265,7 @@ const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, loca
255
265
  type: 'mime:text/plain',
256
266
  display: JSON.stringify({
257
267
  type: 'svg',
258
- content: createPassportSvg({ issuer: issuerName, title: passport.title, issuerDid: issuerWallet.toAddress() }),
268
+ content: createPassportSvg({ issuer: issuerName, title: passport.title, issuerDid: issuerWallet.address }),
259
269
  }),
260
270
  };
261
271
  };
@@ -279,11 +289,11 @@ const handleInvitationResponse = async ({
279
289
  const claim = claims.find((x) => x.type === 'signature');
280
290
  verifySignature(claim, userDid, userPk, locale);
281
291
 
282
- const { issuerName, issuerWallet } = await getIssuer({ node, nodeInfo, teamDid });
292
+ const { issuerName, issuerWallet, issuerType } = await getIssuer({ node, nodeInfo, teamDid });
283
293
 
284
294
  const inviteInfo = await node.processInvitation({ teamDid, inviteId });
285
295
 
286
- const vc = createPassportVC({
296
+ const vcParams = {
287
297
  issuerName,
288
298
  issuerWallet,
289
299
  ownerDid: userDid,
@@ -300,7 +310,13 @@ const handleInvitationResponse = async ({
300
310
  teamDid,
301
311
  }),
302
312
  types: teamDid === nodeInfo.did ? [NFT_TYPE_NODE_PASSPORT] : [],
303
- });
313
+ };
314
+
315
+ if (issuerType === 'node') {
316
+ vcParams.tag = nodeInfo.did;
317
+ }
318
+
319
+ const vc = createPassportVC(vcParams);
304
320
 
305
321
  const role = getRoleFromLocalPassport(get(vc, 'credentialSubject.passport'));
306
322
  const passport = createUserPassport(vc, { role });
@@ -389,7 +405,7 @@ const createIssuePassportRequest = async ({ node, nodeInfo, teamDid, id, locale
389
405
  type: 'mime:text/plain',
390
406
  display: JSON.stringify({
391
407
  type: 'svg',
392
- content: createPassportSvg({ issuer: issuerName, title: passport.title, issuerDid: issuerWallet.toAddress() }),
408
+ content: createPassportSvg({ issuer: issuerName, title: passport.title, issuerDid: issuerWallet.address }),
393
409
  }),
394
410
  };
395
411
  };
@@ -424,7 +440,7 @@ const handleIssuePassportResponse = async ({
424
440
  );
425
441
  }
426
442
 
427
- const { issuerName, issuerWallet } = await getIssuer({ node, nodeInfo, teamDid });
443
+ const { issuerName, issuerWallet, issuerType } = await getIssuer({ node, nodeInfo, teamDid });
428
444
 
429
445
  // get issuanceInfo from session
430
446
  const list = await node.getPassportIssuances({ teamDid });
@@ -435,7 +451,7 @@ const handleIssuePassportResponse = async ({
435
451
  throw new Error(messages.notOwner[locale]);
436
452
  }
437
453
 
438
- const vc = createPassportVC({
454
+ const vcParams = {
439
455
  issuerName,
440
456
  issuerWallet,
441
457
  ownerDid: userDid,
@@ -452,7 +468,13 @@ const handleIssuePassportResponse = async ({
452
468
  teamDid,
453
469
  }),
454
470
  types: teamDid === nodeInfo.did ? [NFT_TYPE_NODE_PASSPORT] : [],
455
- });
471
+ };
472
+
473
+ if (issuerType === 'node') {
474
+ vcParams.tag = nodeInfo.did;
475
+ }
476
+
477
+ const vc = createPassportVC(vcParams);
456
478
 
457
479
  const role = getRoleFromLocalPassport(get(vc, 'credentialSubject.passport'));
458
480
  const passport = createUserPassport(vc, { role });
@@ -637,6 +659,7 @@ const validatePassportStatus = async ({ vcId, endpoint, locale = 'en' }) => {
637
659
  module.exports = {
638
660
  getUser,
639
661
  createAuthToken,
662
+ createAuthTokenByOwnershipNFT,
640
663
  beforeInvitationRequest,
641
664
  createInvitationRequest,
642
665
  handleInvitationResponse,
@@ -39,7 +39,7 @@ const getTeamInfo = async ({ type, node, req }) => {
39
39
  teamDid = req.headers['x-blocklet-did'];
40
40
  const blocklet = await node.getBlocklet({ did: teamDid, attachRuntimeInfo: false });
41
41
  const { wallet } = getBlockletInfo(blocklet, info.sk);
42
- issuerDid = wallet.toAddress();
42
+ issuerDid = wallet.address;
43
43
  issuerName = blocklet.meta.title || blocklet.meta.name;
44
44
  issuerWallet = wallet;
45
45
  } else {
@@ -215,7 +215,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
215
215
  );
216
216
  }
217
217
 
218
- const vc = createPassportVC({
218
+ const vcParams = {
219
219
  issuerName,
220
220
  issuerWallet,
221
221
  ownerDid: userDid,
@@ -231,8 +231,15 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
231
231
  userDid,
232
232
  teamDid,
233
233
  }),
234
- types: type === TEAM_TYPES.NODE ? [NFT_TYPE_NODE_PASSPORT] : [],
235
- });
234
+ types: [],
235
+ };
236
+
237
+ if (type === TEAM_TYPES.NODE) {
238
+ vcParams.types = [NFT_TYPE_NODE_PASSPORT];
239
+ vcParams.tag = teamDid;
240
+ }
241
+
242
+ const vc = createPassportVC(vcParams);
236
243
 
237
244
  const role = getRoleFromLocalPassport(get(vc, 'credentialSubject.passport'));
238
245
 
package/lib/passport.js CHANGED
@@ -72,7 +72,7 @@ const createPassportSvg = ({
72
72
  </svg>
73
73
  `;
74
74
 
75
- const createPassportVC = ({ issuerWallet, issuerName, ownerDid, passport, endpoint, types = [] } = {}) => {
75
+ const createPassportVC = ({ issuerWallet, issuerName, ownerDid, passport, endpoint, types = [], tag } = {}) => {
76
76
  validatePassport(passport);
77
77
 
78
78
  return createVC({
@@ -86,10 +86,11 @@ const createPassportVC = ({ issuerWallet, issuerName, ownerDid, passport, endpoi
86
86
  passport,
87
87
  display: {
88
88
  type: 'svg',
89
- content: createPassportSvg({ issuer: issuerName, issuerDid: issuerWallet.toAddress(), title: passport.title }),
89
+ content: createPassportSvg({ issuer: issuerName, issuerDid: issuerWallet.address, title: passport.title }),
90
90
  },
91
91
  },
92
92
  endpoint,
93
+ tag,
93
94
  });
94
95
  };
95
96
 
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.5.3",
6
+ "version": "1.5.4",
7
7
  "description": "Simple lib to manage auth in ABT Node",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -20,15 +20,15 @@
20
20
  "author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
21
21
  "license": "MIT",
22
22
  "dependencies": {
23
- "@abtnode/constant": "1.5.3",
24
- "@abtnode/logger": "1.5.3",
25
- "@abtnode/util": "1.5.3",
26
- "@arcblock/did": "^1.13.27",
27
- "@arcblock/vc": "^1.13.27",
28
- "@blocklet/meta": "1.5.3",
29
- "@ocap/mcrypto": "^1.13.27",
30
- "@ocap/util": "^1.13.27",
31
- "@ocap/wallet": "^1.13.27",
23
+ "@abtnode/constant": "1.5.4",
24
+ "@abtnode/logger": "1.5.4",
25
+ "@abtnode/util": "1.5.4",
26
+ "@arcblock/did": "^1.13.28",
27
+ "@arcblock/vc": "^1.13.28",
28
+ "@blocklet/meta": "1.5.4",
29
+ "@ocap/mcrypto": "^1.13.28",
30
+ "@ocap/util": "^1.13.28",
31
+ "@ocap/wallet": "^1.13.28",
32
32
  "axios": "^0.21.4",
33
33
  "joi": "^17.4.0",
34
34
  "jsonwebtoken": "^8.5.1",
@@ -39,5 +39,5 @@
39
39
  "devDependencies": {
40
40
  "jest": "^26.4.2"
41
41
  },
42
- "gitHead": "31e38c299c61c2a33caa93ed6a74d6e901409295"
42
+ "gitHead": "8856a7eae8ebd3e09ca11214892f57fb522f9b45"
43
43
  }