@abtnode/auth 1.5.5 → 1.5.9

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 (2) hide show
  1. package/lib/auth.js +45 -19
  2. package/package.json +11 -11
package/lib/auth.js CHANGED
@@ -172,27 +172,32 @@ const getRandomMessage = (len = 16) => {
172
172
  return hex.replace(/^0x/, '').toUpperCase();
173
173
  };
174
174
 
175
- const getIssuer = async ({ node, nodeInfo, teamDid }) => {
176
- let issuerName;
177
- let issuerWallet;
178
- let issuerType;
175
+ const getTeamInfo = async ({ node, nodeInfo, teamDid }) => {
176
+ let type;
177
+ let name;
178
+ let wallet;
179
+ let description;
179
180
 
180
181
  if (teamDid === nodeInfo.did) {
181
- issuerName = nodeInfo.name;
182
- issuerWallet = getNodeWallet(nodeInfo.sk);
183
- issuerType = 'node';
182
+ name = nodeInfo.name;
183
+ description = nodeInfo.description;
184
+ wallet = getNodeWallet(nodeInfo.sk);
185
+ type = 'node';
184
186
  } else {
185
187
  const blocklet = await node.getBlocklet({ did: teamDid, attachRuntimeInfo: false });
186
- const { name, wallet } = getBlockletInfo(blocklet, nodeInfo.sk);
187
- issuerName = name;
188
- issuerWallet = wallet;
189
- issuerType = 'blocklet';
188
+ const blockletInfo = getBlockletInfo(blocklet, nodeInfo.sk);
189
+ name = blockletInfo.name;
190
+ description = blockletInfo.description;
191
+ wallet = blockletInfo.wallet;
192
+ type = 'blocklet';
190
193
  }
191
194
 
192
195
  return {
193
- issuerName,
194
- issuerWallet,
195
- issuerType,
196
+ type,
197
+ name,
198
+ description,
199
+ wallet,
200
+ did: teamDid,
196
201
  };
197
202
  };
198
203
 
@@ -250,7 +255,7 @@ const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, loca
250
255
  throw new Error('The invitation does not exist or has been used');
251
256
  }
252
257
 
253
- const { issuerName, issuerWallet } = await getIssuer({ node, nodeInfo, teamDid });
258
+ const { name: issuerName, wallet: issuerWallet } = await getTeamInfo({ node, nodeInfo, teamDid });
254
259
 
255
260
  const passport = await createPassport({
256
261
  name: inviteInfo.role,
@@ -289,7 +294,7 @@ const handleInvitationResponse = async ({
289
294
  const claim = claims.find((x) => x.type === 'signature');
290
295
  verifySignature(claim, userDid, userPk, locale);
291
296
 
292
- const { issuerName, issuerWallet, issuerType } = await getIssuer({ node, nodeInfo, teamDid });
297
+ const { name: issuerName, wallet: issuerWallet, type: issuerType } = await getTeamInfo({ node, nodeInfo, teamDid });
293
298
 
294
299
  const inviteInfo = await node.processInvitation({ teamDid, inviteId });
295
300
 
@@ -390,7 +395,7 @@ const createIssuePassportRequest = async ({ node, nodeInfo, teamDid, id, locale
390
395
  throw new Error('The issuance does not exist or has been used');
391
396
  }
392
397
 
393
- const { issuerName, issuerWallet } = await getIssuer({ node, nodeInfo, teamDid });
398
+ const { name: issuerName, wallet: issuerWallet } = await getTeamInfo({ node, nodeInfo, teamDid });
394
399
 
395
400
  const passport = await createPassport({
396
401
  name: issuanceInfo.name,
@@ -440,7 +445,7 @@ const handleIssuePassportResponse = async ({
440
445
  );
441
446
  }
442
447
 
443
- const { issuerName, issuerWallet, issuerType } = await getIssuer({ node, nodeInfo, teamDid });
448
+ const { name: issuerName, wallet: issuerWallet, type: issuerType } = await getTeamInfo({ node, nodeInfo, teamDid });
444
449
 
445
450
  // get issuanceInfo from session
446
451
  const list = await node.getPassportIssuances({ teamDid });
@@ -561,7 +566,7 @@ const checkWalletVersion = ({ abtwallet, locale = 'en' }) => {
561
566
 
562
567
  const getPassportStatus = async ({ node, teamDid, userDid, vcId, locale = 'en' }) => {
563
568
  const nodeInfo = await node.getNodeInfo();
564
- const { issuerWallet, issuerName, issuerType } = await getIssuer({ node, nodeInfo, teamDid });
569
+ const { wallet: issuerWallet, name: issuerName, type: issuerType } = await getTeamInfo({ node, nodeInfo, teamDid });
565
570
 
566
571
  const actionLabel = {
567
572
  zh: `${issuerType === 'node' ? '管理节点' : '查看 Blocklet'}`,
@@ -656,8 +661,28 @@ const validatePassportStatus = async ({ vcId, endpoint, locale = 'en' }) => {
656
661
  }
657
662
  };
658
663
 
664
+ const setUserInfoHeaders = (req) => {
665
+ if (req.user) {
666
+ req.headers['x-user-did'] = req.user.did;
667
+ req.headers['x-user-fullname'] = encodeURIComponent(req.user.fullName);
668
+ req.headers['x-user-role'] = req.user.role;
669
+ req.headers['x-connected-did'] = req.user.did;
670
+ } else {
671
+ delete req.headers['x-user-did'];
672
+ delete req.headers['x-user-fullname'];
673
+ delete req.headers['x-user-role'];
674
+
675
+ if (req.cookies && req.cookies.connected_did) {
676
+ req.headers['x-connected-did'] = req.cookies.connected_did;
677
+ } else {
678
+ delete req.headers['x-connected-did'];
679
+ }
680
+ }
681
+ };
682
+
659
683
  module.exports = {
660
684
  getUser,
685
+ getTeamInfo,
661
686
  createAuthToken,
662
687
  createAuthTokenByOwnershipNFT,
663
688
  beforeInvitationRequest,
@@ -672,4 +697,5 @@ module.exports = {
672
697
  getPassportStatusEndpoint,
673
698
  getPassportStatus,
674
699
  validatePassportStatus,
700
+ setUserInfoHeaders,
675
701
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.5.5",
6
+ "version": "1.5.9",
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.5",
24
- "@abtnode/logger": "1.5.5",
25
- "@abtnode/util": "1.5.5",
26
- "@arcblock/did": "^1.13.28",
27
- "@arcblock/vc": "^1.13.28",
28
- "@blocklet/meta": "1.5.5",
29
- "@ocap/mcrypto": "^1.13.28",
30
- "@ocap/util": "^1.13.28",
31
- "@ocap/wallet": "^1.13.28",
23
+ "@abtnode/constant": "1.5.9",
24
+ "@abtnode/logger": "1.5.9",
25
+ "@abtnode/util": "1.5.9",
26
+ "@arcblock/did": "^1.13.49",
27
+ "@arcblock/vc": "^1.13.49",
28
+ "@blocklet/meta": "1.5.9",
29
+ "@ocap/mcrypto": "^1.13.49",
30
+ "@ocap/util": "^1.13.49",
31
+ "@ocap/wallet": "^1.13.49",
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": "1cdd5b1770ec9f9b8df59d4c43680d21b874eb1e"
42
+ "gitHead": "cd66ac83b32aaaee85bcd8a0a7cfe3501d1446c1"
43
43
  }