@abtnode/auth 1.7.23 → 1.7.24
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 +21 -2
- package/lib/invitation.js +7 -3
- package/lib/lost-passport.js +23 -5
- package/lib/util/create-passport-svg.js +3 -1
- package/package.json +6 -6
package/lib/auth.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const path = require('path');
|
|
1
2
|
const jwt = require('jsonwebtoken');
|
|
2
3
|
const semver = require('semver');
|
|
3
4
|
const joinUrl = require('url-join');
|
|
@@ -8,8 +9,9 @@ const Mcrypto = require('@ocap/mcrypto');
|
|
|
8
9
|
const Client = require('@ocap/client');
|
|
9
10
|
const { fromSecretKey, WalletType } = require('@ocap/wallet');
|
|
10
11
|
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
11
|
-
const { PASSPORT_STATUS, VC_TYPE_NODE_PASSPORT, ROLES } = require('@abtnode/constant');
|
|
12
|
+
const { PASSPORT_STATUS, VC_TYPE_NODE_PASSPORT, ROLES, NODE_DATA_DIR_NAME } = require('@abtnode/constant');
|
|
12
13
|
const axios = require('@abtnode/util/lib/axios');
|
|
14
|
+
const { extractUserAvatar, parseUserAvatar } = require('@abtnode/util/lib/user-avatar');
|
|
13
15
|
|
|
14
16
|
const logger = require('./logger');
|
|
15
17
|
const verifySignature = require('./util/verify-signature');
|
|
@@ -253,6 +255,7 @@ const getTeamInfo = async ({ node, nodeInfo, teamDid }) => {
|
|
|
253
255
|
let description;
|
|
254
256
|
let passportColor;
|
|
255
257
|
let owner;
|
|
258
|
+
let dataDir;
|
|
256
259
|
|
|
257
260
|
if (teamDid === nodeInfo.did) {
|
|
258
261
|
name = nodeInfo.name;
|
|
@@ -261,6 +264,7 @@ const getTeamInfo = async ({ node, nodeInfo, teamDid }) => {
|
|
|
261
264
|
type = 'node';
|
|
262
265
|
passportColor = 'default';
|
|
263
266
|
owner = nodeInfo.nodeOwner;
|
|
267
|
+
dataDir = path.join(node.dataDirs.data, NODE_DATA_DIR_NAME);
|
|
264
268
|
} else {
|
|
265
269
|
const blocklet = await node.getBlocklet({ did: teamDid, attachRuntimeInfo: false });
|
|
266
270
|
const blockletInfo = getBlockletInfo(blocklet, nodeInfo.sk);
|
|
@@ -270,6 +274,7 @@ const getTeamInfo = async ({ node, nodeInfo, teamDid }) => {
|
|
|
270
274
|
passportColor = blockletInfo.passportColor;
|
|
271
275
|
type = 'blocklet';
|
|
272
276
|
owner = get(blocklet, 'settings.owner');
|
|
277
|
+
dataDir = blocklet.env.dataDir;
|
|
273
278
|
}
|
|
274
279
|
|
|
275
280
|
return {
|
|
@@ -280,6 +285,7 @@ const getTeamInfo = async ({ node, nodeInfo, teamDid }) => {
|
|
|
280
285
|
passportColor,
|
|
281
286
|
did: teamDid,
|
|
282
287
|
owner,
|
|
288
|
+
dataDir,
|
|
283
289
|
};
|
|
284
290
|
};
|
|
285
291
|
|
|
@@ -426,6 +432,7 @@ const handleInvitationResponse = async ({
|
|
|
426
432
|
wallet: issuerWallet,
|
|
427
433
|
type: issuerType,
|
|
428
434
|
passportColor,
|
|
435
|
+
dataDir,
|
|
429
436
|
} = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
430
437
|
|
|
431
438
|
const { remark } = inviteInfo;
|
|
@@ -483,11 +490,16 @@ const handleInvitationResponse = async ({
|
|
|
483
490
|
}
|
|
484
491
|
}
|
|
485
492
|
|
|
493
|
+
const avatar = await extractUserAvatar(get(profile, 'avatar'), {
|
|
494
|
+
dataDir,
|
|
495
|
+
});
|
|
496
|
+
|
|
486
497
|
if (user) {
|
|
487
498
|
const doc = await node.updateUser({
|
|
488
499
|
teamDid,
|
|
489
500
|
user: {
|
|
490
501
|
...profile,
|
|
502
|
+
avatar,
|
|
491
503
|
did: userDid,
|
|
492
504
|
pk: userPk,
|
|
493
505
|
locale,
|
|
@@ -510,6 +522,7 @@ const handleInvitationResponse = async ({
|
|
|
510
522
|
teamDid,
|
|
511
523
|
user: {
|
|
512
524
|
...profile,
|
|
525
|
+
avatar,
|
|
513
526
|
did: userDid,
|
|
514
527
|
pk: userPk,
|
|
515
528
|
approved: true,
|
|
@@ -572,6 +585,7 @@ const createIssuePassportRequest = async ({ node, nodeInfo, teamDid, id, locale
|
|
|
572
585
|
wallet: issuerWallet,
|
|
573
586
|
passportColor,
|
|
574
587
|
owner: teamOwner,
|
|
588
|
+
dataDir,
|
|
575
589
|
} = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
576
590
|
|
|
577
591
|
if (issuanceInfo.name === ROLES.OWNER && !!teamOwner) {
|
|
@@ -598,7 +612,7 @@ const createIssuePassportRequest = async ({ node, nodeInfo, teamDid, id, locale
|
|
|
598
612
|
title: passport.title,
|
|
599
613
|
issuerDid: issuerWallet.address,
|
|
600
614
|
ownerName: get(user, 'fullName', 'Your Name'),
|
|
601
|
-
ownerAvatarUrl: get(user, 'avatar', ''),
|
|
615
|
+
ownerAvatarUrl: await parseUserAvatar(get(user, 'avatar', ''), { dataDir }),
|
|
602
616
|
preferredColor: passportColor,
|
|
603
617
|
}),
|
|
604
618
|
}),
|
|
@@ -643,6 +657,7 @@ const handleIssuePassportResponse = async ({
|
|
|
643
657
|
type: issuerType,
|
|
644
658
|
passportColor,
|
|
645
659
|
owner: teamOwner,
|
|
660
|
+
dataDir,
|
|
646
661
|
} = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
647
662
|
|
|
648
663
|
// get issuanceInfo from session
|
|
@@ -658,6 +673,10 @@ const handleIssuePassportResponse = async ({
|
|
|
658
673
|
throw new Error(messages.notOwner[locale]);
|
|
659
674
|
}
|
|
660
675
|
|
|
676
|
+
if (user) {
|
|
677
|
+
user.avatar = await parseUserAvatar(user.avatar, { dataDir });
|
|
678
|
+
}
|
|
679
|
+
|
|
661
680
|
const vcParams = {
|
|
662
681
|
issuerName,
|
|
663
682
|
issuerWallet,
|
package/lib/invitation.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
const
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const joinUrl = require('url-join');
|
|
3
|
+
const { WELLKNOWN_SERVICE_PATH_PREFIX, NODE_DATA_DIR_NAME } = require('@abtnode/constant');
|
|
2
4
|
const { BLOCKLET_CONFIGURABLE_KEY } = require('@blocklet/meta/lib/constants');
|
|
3
5
|
const { getDisplayName } = require('@blocklet/meta/lib/util');
|
|
4
6
|
const logger = require('@abtnode/logger')(require('../package.json').name);
|
|
5
|
-
const
|
|
7
|
+
const { parseUserAvatar } = require('@abtnode/util/lib/user-avatar');
|
|
6
8
|
|
|
7
9
|
module.exports = {
|
|
8
10
|
init(server, node, { prefix, type } = {}) {
|
|
@@ -64,7 +66,9 @@ module.exports = {
|
|
|
64
66
|
email: invitation.inviter.email,
|
|
65
67
|
fullName: invitation.inviter.fullName,
|
|
66
68
|
role: invitation.inviter.role,
|
|
67
|
-
avatar:
|
|
69
|
+
avatar:
|
|
70
|
+
user &&
|
|
71
|
+
(await parseUserAvatar(user.avatar, { dataDir: path.join(node.dataDirs.data, NODE_DATA_DIR_NAME) })),
|
|
68
72
|
};
|
|
69
73
|
|
|
70
74
|
res.json({
|
package/lib/lost-passport.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const path = require('path');
|
|
1
2
|
const joinUrl = require('url-join');
|
|
2
3
|
const uniqBy = require('lodash/uniqBy');
|
|
3
4
|
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
@@ -5,8 +6,9 @@ const formatContext = require('@abtnode/util/lib/format-context');
|
|
|
5
6
|
const getRandomMessage = require('@abtnode/util/lib/get-random-message');
|
|
6
7
|
const getNodeWallet = require('@abtnode/util/lib/get-app-wallet');
|
|
7
8
|
const { getDisplayName } = require('@blocklet/meta/lib/util');
|
|
8
|
-
const { VC_TYPE_NODE_PASSPORT, PASSPORT_STATUS } = require('@abtnode/constant');
|
|
9
|
+
const { VC_TYPE_NODE_PASSPORT, PASSPORT_STATUS, NODE_DATA_DIR_NAME } = require('@abtnode/constant');
|
|
9
10
|
const get = require('lodash/get');
|
|
11
|
+
const { parseUserAvatar } = require('@abtnode/util/lib/user-avatar');
|
|
10
12
|
|
|
11
13
|
const logger = require('./logger');
|
|
12
14
|
const { messages, getUser, checkWalletVersion, getPassportStatusEndpoint } = require('./auth');
|
|
@@ -32,6 +34,7 @@ const getTeamInfo = async ({ type, node, req }) => {
|
|
|
32
34
|
let issuerName;
|
|
33
35
|
let issuerWallet;
|
|
34
36
|
let passportColor;
|
|
37
|
+
let dataDir;
|
|
35
38
|
|
|
36
39
|
const info = await node.getNodeInfo();
|
|
37
40
|
if (type === TEAM_TYPES.NODE) {
|
|
@@ -40,6 +43,7 @@ const getTeamInfo = async ({ type, node, req }) => {
|
|
|
40
43
|
issuerName = info.name;
|
|
41
44
|
issuerWallet = getNodeWallet(info.sk);
|
|
42
45
|
passportColor = 'default';
|
|
46
|
+
dataDir = path.join(node.dataDirs.data, NODE_DATA_DIR_NAME);
|
|
43
47
|
} else if (TEAM_TYPES.BLOCKLET) {
|
|
44
48
|
teamDid = req.headers['x-blocklet-did'];
|
|
45
49
|
const blocklet = await node.getBlocklet({ did: teamDid, attachRuntimeInfo: false });
|
|
@@ -48,6 +52,7 @@ const getTeamInfo = async ({ type, node, req }) => {
|
|
|
48
52
|
issuerName = getDisplayName(blocklet, true);
|
|
49
53
|
issuerWallet = blockletInfo.wallet;
|
|
50
54
|
passportColor = blockletInfo.passportColor;
|
|
55
|
+
dataDir = blocklet.env.dataDir;
|
|
51
56
|
} else {
|
|
52
57
|
throw new Error('createLostPassportListRoute: unknown type');
|
|
53
58
|
}
|
|
@@ -58,6 +63,7 @@ const getTeamInfo = async ({ type, node, req }) => {
|
|
|
58
63
|
issuerName,
|
|
59
64
|
issuerWallet,
|
|
60
65
|
passportColor,
|
|
66
|
+
dataDir,
|
|
61
67
|
};
|
|
62
68
|
};
|
|
63
69
|
|
|
@@ -89,7 +95,7 @@ const createLostPassportListRoute = ({ node, type }) => ({
|
|
|
89
95
|
onAuth: async ({ userDid, extraParams, updateSession, req }) => {
|
|
90
96
|
const { locale } = extraParams;
|
|
91
97
|
|
|
92
|
-
const { teamDid, issuerDid } = await getTeamInfo({ node, req, type });
|
|
98
|
+
const { teamDid, issuerDid, dataDir } = await getTeamInfo({ node, req, type });
|
|
93
99
|
|
|
94
100
|
// check user approved
|
|
95
101
|
const user = await getUser(node, teamDid, userDid);
|
|
@@ -122,6 +128,8 @@ const createLostPassportListRoute = ({ node, type }) => ({
|
|
|
122
128
|
|
|
123
129
|
logger.info('get passport type list', { userDid });
|
|
124
130
|
|
|
131
|
+
user.avatar = await parseUserAvatar(user.avatar, { did: teamDid, dataDir });
|
|
132
|
+
|
|
125
133
|
await updateSession({ user });
|
|
126
134
|
},
|
|
127
135
|
});
|
|
@@ -148,7 +156,11 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
148
156
|
const { locale, passportName, receiverDid } = extraParams;
|
|
149
157
|
checkWalletVersion({ didwallet, locale });
|
|
150
158
|
|
|
151
|
-
const { teamDid, issuerDid, issuerName, passportColor } = await getTeamInfo({
|
|
159
|
+
const { teamDid, issuerDid, issuerName, passportColor, dataDir } = await getTeamInfo({
|
|
160
|
+
node,
|
|
161
|
+
req: request,
|
|
162
|
+
type,
|
|
163
|
+
});
|
|
152
164
|
const user = await getUser(node, teamDid, receiverDid);
|
|
153
165
|
|
|
154
166
|
const passport = await createPassport({
|
|
@@ -169,7 +181,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
169
181
|
title: passport.title,
|
|
170
182
|
issuerDid,
|
|
171
183
|
ownerName: user.fullName || '',
|
|
172
|
-
ownerAvatarUrl: user.avatar || '',
|
|
184
|
+
ownerAvatarUrl: await parseUserAvatar(user.avatar || '', { dataDir }),
|
|
173
185
|
preferredColor: passportColor,
|
|
174
186
|
}),
|
|
175
187
|
}),
|
|
@@ -181,7 +193,11 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
181
193
|
onAuth: async ({ claims, userDid, userPk, extraParams, updateSession, baseUrl, req }) => {
|
|
182
194
|
const { locale = 'en', receiverDid, passportName } = extraParams;
|
|
183
195
|
|
|
184
|
-
const { teamDid, issuerDid, issuerName, issuerWallet, passportColor } = await getTeamInfo({
|
|
196
|
+
const { teamDid, issuerDid, issuerName, issuerWallet, passportColor, dataDir } = await getTeamInfo({
|
|
197
|
+
node,
|
|
198
|
+
req,
|
|
199
|
+
type,
|
|
200
|
+
});
|
|
185
201
|
const statusEndpointBaseUrl = getStatusEndpointBaseUrl(type, baseUrl, authServicePrefix);
|
|
186
202
|
|
|
187
203
|
// Verify signature
|
|
@@ -223,6 +239,8 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
223
239
|
);
|
|
224
240
|
}
|
|
225
241
|
|
|
242
|
+
user.avatar = await parseUserAvatar(user.avatar, { dataDir });
|
|
243
|
+
|
|
226
244
|
const vcParams = {
|
|
227
245
|
issuerName,
|
|
228
246
|
issuerWallet,
|
|
@@ -22,6 +22,8 @@ const createPassportSvg = ({
|
|
|
22
22
|
ownerAvatarUrl = '',
|
|
23
23
|
revoked,
|
|
24
24
|
isDataUrl,
|
|
25
|
+
width = '100%',
|
|
26
|
+
height = '100%',
|
|
25
27
|
} = {}) => {
|
|
26
28
|
let colors;
|
|
27
29
|
if (preferredColor === 'default') {
|
|
@@ -32,7 +34,7 @@ const createPassportSvg = ({
|
|
|
32
34
|
colors = getNftBGColor(preferredColor);
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
const svgXML = `<svg width="
|
|
37
|
+
const svgXML = `<svg width="${width}" height="${height}" viewBox="0 0 424 564" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
36
38
|
<rect x="1" y="1" width="422" height="562" rx="21" fill="url(#paint0_linear_6_342)"/>
|
|
37
39
|
<text x="360" y="65" fill="white" xml:space="preserve" font-family="Roboto,Helvetica" font-size="${(() => {
|
|
38
40
|
if (title.length >= 6) {
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.7.
|
|
6
|
+
"version": "1.7.24",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,12 +20,12 @@
|
|
|
20
20
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.7.
|
|
24
|
-
"@abtnode/logger": "1.7.
|
|
25
|
-
"@abtnode/util": "1.7.
|
|
23
|
+
"@abtnode/constant": "1.7.24",
|
|
24
|
+
"@abtnode/logger": "1.7.24",
|
|
25
|
+
"@abtnode/util": "1.7.24",
|
|
26
26
|
"@arcblock/did": "^1.16.15",
|
|
27
27
|
"@arcblock/vc": "^1.16.15",
|
|
28
|
-
"@blocklet/meta": "1.7.
|
|
28
|
+
"@blocklet/meta": "1.7.24",
|
|
29
29
|
"@ocap/client": "1.16.15",
|
|
30
30
|
"@ocap/mcrypto": "^1.16.15",
|
|
31
31
|
"@ocap/util": "^1.16.15",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"jest": "^27.4.5"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "904178e4dd0cd14c2a0a8b9131708c7ec68351e1"
|
|
44
44
|
}
|