@abtnode/auth 1.6.15 → 1.6.19
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 +22 -4
- package/lib/lost-passport.js +11 -5
- package/lib/passport.js +2 -0
- package/lib/util/create-passport-svg.js +32 -9
- package/lib/util/passport-color.js +134 -0
- package/package.json +13 -13
package/lib/auth.js
CHANGED
|
@@ -178,18 +178,21 @@ const getTeamInfo = async ({ node, nodeInfo, teamDid }) => {
|
|
|
178
178
|
let name;
|
|
179
179
|
let wallet;
|
|
180
180
|
let description;
|
|
181
|
+
let passportColor;
|
|
181
182
|
|
|
182
183
|
if (teamDid === nodeInfo.did) {
|
|
183
184
|
name = nodeInfo.name;
|
|
184
185
|
description = nodeInfo.description;
|
|
185
186
|
wallet = getNodeWallet(nodeInfo.sk);
|
|
186
187
|
type = 'node';
|
|
188
|
+
passportColor = 'default';
|
|
187
189
|
} else {
|
|
188
190
|
const blocklet = await node.getBlocklet({ did: teamDid, attachRuntimeInfo: false });
|
|
189
191
|
const blockletInfo = getBlockletInfo(blocklet, nodeInfo.sk);
|
|
190
192
|
name = blockletInfo.name;
|
|
191
193
|
description = blockletInfo.description;
|
|
192
194
|
wallet = blockletInfo.wallet;
|
|
195
|
+
passportColor = blockletInfo.passportColor;
|
|
193
196
|
type = 'blocklet';
|
|
194
197
|
}
|
|
195
198
|
|
|
@@ -198,6 +201,7 @@ const getTeamInfo = async ({ node, nodeInfo, teamDid }) => {
|
|
|
198
201
|
name,
|
|
199
202
|
description,
|
|
200
203
|
wallet,
|
|
204
|
+
passportColor,
|
|
201
205
|
did: teamDid,
|
|
202
206
|
};
|
|
203
207
|
};
|
|
@@ -256,7 +260,7 @@ const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, loca
|
|
|
256
260
|
throw new Error('The invitation does not exist or has been used');
|
|
257
261
|
}
|
|
258
262
|
|
|
259
|
-
const { name: issuerName, wallet: issuerWallet } = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
263
|
+
const { name: issuerName, wallet: issuerWallet, passportColor } = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
260
264
|
|
|
261
265
|
const passport = await createPassport({
|
|
262
266
|
name: inviteInfo.role,
|
|
@@ -276,6 +280,7 @@ const createInvitationRequest = async ({ node, nodeInfo, teamDid, inviteId, loca
|
|
|
276
280
|
title: passport.title,
|
|
277
281
|
issuerDid: issuerWallet.address,
|
|
278
282
|
ownerName: 'Your Name',
|
|
283
|
+
preferredColor: passportColor,
|
|
279
284
|
}),
|
|
280
285
|
}),
|
|
281
286
|
};
|
|
@@ -300,7 +305,12 @@ const handleInvitationResponse = async ({
|
|
|
300
305
|
const claim = claims.find((x) => x.type === 'signature');
|
|
301
306
|
verifySignature(claim, userDid, userPk, locale);
|
|
302
307
|
|
|
303
|
-
const {
|
|
308
|
+
const {
|
|
309
|
+
name: issuerName,
|
|
310
|
+
wallet: issuerWallet,
|
|
311
|
+
type: issuerType,
|
|
312
|
+
passportColor,
|
|
313
|
+
} = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
304
314
|
|
|
305
315
|
const inviteInfo = await node.processInvitation({ teamDid, inviteId });
|
|
306
316
|
const { remark } = inviteInfo;
|
|
@@ -325,6 +335,7 @@ const handleInvitationResponse = async ({
|
|
|
325
335
|
}),
|
|
326
336
|
types: teamDid === nodeInfo.did ? [NFT_TYPE_NODE_PASSPORT] : [],
|
|
327
337
|
ownerProfile: profile,
|
|
338
|
+
preferredColor: passportColor,
|
|
328
339
|
};
|
|
329
340
|
|
|
330
341
|
if (issuerType === 'node') {
|
|
@@ -404,7 +415,7 @@ const createIssuePassportRequest = async ({ node, nodeInfo, teamDid, id, locale
|
|
|
404
415
|
throw new Error('The issuance does not exist or has been used');
|
|
405
416
|
}
|
|
406
417
|
|
|
407
|
-
const { name: issuerName, wallet: issuerWallet } = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
418
|
+
const { name: issuerName, wallet: issuerWallet, passportColor } = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
408
419
|
const user = await getUser(node, teamDid, issuanceInfo.ownerDid);
|
|
409
420
|
|
|
410
421
|
const passport = await createPassport({
|
|
@@ -426,6 +437,7 @@ const createIssuePassportRequest = async ({ node, nodeInfo, teamDid, id, locale
|
|
|
426
437
|
issuerDid: issuerWallet.address,
|
|
427
438
|
ownerName: get(user, 'fullName', 'Your Name'),
|
|
428
439
|
ownerAvatarUrl: get(user, 'avatar', ''),
|
|
440
|
+
preferredColor: passportColor,
|
|
429
441
|
}),
|
|
430
442
|
}),
|
|
431
443
|
};
|
|
@@ -461,7 +473,12 @@ const handleIssuePassportResponse = async ({
|
|
|
461
473
|
);
|
|
462
474
|
}
|
|
463
475
|
|
|
464
|
-
const {
|
|
476
|
+
const {
|
|
477
|
+
name: issuerName,
|
|
478
|
+
wallet: issuerWallet,
|
|
479
|
+
type: issuerType,
|
|
480
|
+
passportColor,
|
|
481
|
+
} = await getTeamInfo({ node, nodeInfo, teamDid });
|
|
465
482
|
|
|
466
483
|
// get issuanceInfo from session
|
|
467
484
|
const list = await node.getPassportIssuances({ teamDid });
|
|
@@ -490,6 +507,7 @@ const handleIssuePassportResponse = async ({
|
|
|
490
507
|
}),
|
|
491
508
|
types: teamDid === nodeInfo.did ? [NFT_TYPE_NODE_PASSPORT] : [],
|
|
492
509
|
ownerProfile: user,
|
|
510
|
+
preferredColor: passportColor,
|
|
493
511
|
};
|
|
494
512
|
|
|
495
513
|
if (issuerType === 'node') {
|
package/lib/lost-passport.js
CHANGED
|
@@ -29,6 +29,7 @@ const getTeamInfo = async ({ type, node, req }) => {
|
|
|
29
29
|
let issuerDid;
|
|
30
30
|
let issuerName;
|
|
31
31
|
let issuerWallet;
|
|
32
|
+
let passportColor;
|
|
32
33
|
|
|
33
34
|
const info = await node.getNodeInfo();
|
|
34
35
|
if (type === TEAM_TYPES.NODE) {
|
|
@@ -36,13 +37,15 @@ const getTeamInfo = async ({ type, node, req }) => {
|
|
|
36
37
|
issuerDid = info.did;
|
|
37
38
|
issuerName = info.name;
|
|
38
39
|
issuerWallet = getNodeWallet(info.sk);
|
|
40
|
+
passportColor = 'default';
|
|
39
41
|
} else if (TEAM_TYPES.BLOCKLET) {
|
|
40
42
|
teamDid = req.headers['x-blocklet-did'];
|
|
41
43
|
const blocklet = await node.getBlocklet({ did: teamDid, attachRuntimeInfo: false });
|
|
42
|
-
const
|
|
43
|
-
issuerDid = wallet.address;
|
|
44
|
+
const blockletInfo = getBlockletInfo(blocklet, info.sk);
|
|
45
|
+
issuerDid = blockletInfo.wallet.address;
|
|
44
46
|
issuerName = blocklet.meta.title || blocklet.meta.name;
|
|
45
|
-
issuerWallet = wallet;
|
|
47
|
+
issuerWallet = blockletInfo.wallet;
|
|
48
|
+
passportColor = blockletInfo.passportColor;
|
|
46
49
|
} else {
|
|
47
50
|
throw new Error('createLostPassportListRoute: unknown type');
|
|
48
51
|
}
|
|
@@ -52,6 +55,7 @@ const getTeamInfo = async ({ type, node, req }) => {
|
|
|
52
55
|
issuerDid,
|
|
53
56
|
issuerName,
|
|
54
57
|
issuerWallet,
|
|
58
|
+
passportColor,
|
|
55
59
|
};
|
|
56
60
|
};
|
|
57
61
|
|
|
@@ -148,7 +152,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
148
152
|
const { locale, passportName, receiverDid } = extraParams;
|
|
149
153
|
checkWalletVersion({ abtwallet, locale });
|
|
150
154
|
|
|
151
|
-
const { teamDid, issuerDid, issuerName } = await getTeamInfo({ node, req: request, type });
|
|
155
|
+
const { teamDid, issuerDid, issuerName, passportColor } = await getTeamInfo({ node, req: request, type });
|
|
152
156
|
const user = await getUser(node, teamDid, receiverDid);
|
|
153
157
|
|
|
154
158
|
const passport = await createPassport({
|
|
@@ -170,6 +174,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
170
174
|
issuerDid,
|
|
171
175
|
ownerName: user.fullName || '',
|
|
172
176
|
ownerAvatarUrl: user.avatar || '',
|
|
177
|
+
preferredColor: passportColor,
|
|
173
178
|
}),
|
|
174
179
|
}),
|
|
175
180
|
};
|
|
@@ -180,7 +185,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
180
185
|
onAuth: async ({ claims, userDid, userPk, extraParams, baseUrl, req }) => {
|
|
181
186
|
const { locale = 'en', receiverDid, passportName } = extraParams;
|
|
182
187
|
|
|
183
|
-
const { teamDid, issuerDid, issuerName, issuerWallet } = await getTeamInfo({ node, req, type });
|
|
188
|
+
const { teamDid, issuerDid, issuerName, issuerWallet, passportColor } = await getTeamInfo({ node, req, type });
|
|
184
189
|
const statusEndpointBaseUrl = getStatusEndpointBaseUrl(type, baseUrl, authServicePrefix);
|
|
185
190
|
|
|
186
191
|
// Verify signature
|
|
@@ -240,6 +245,7 @@ const createLostPassportIssueRoute = ({ node, type, authServicePrefix }) => ({
|
|
|
240
245
|
}),
|
|
241
246
|
types: [],
|
|
242
247
|
ownerProfile: user,
|
|
248
|
+
preferredColor: passportColor,
|
|
243
249
|
};
|
|
244
250
|
|
|
245
251
|
if (type === TEAM_TYPES.NODE) {
|
package/lib/passport.js
CHANGED
|
@@ -58,6 +58,7 @@ const createPassportVC = ({
|
|
|
58
58
|
types = [],
|
|
59
59
|
tag,
|
|
60
60
|
ownerProfile,
|
|
61
|
+
preferredColor,
|
|
61
62
|
} = {}) => {
|
|
62
63
|
validatePassport(passport);
|
|
63
64
|
|
|
@@ -78,6 +79,7 @@ const createPassportVC = ({
|
|
|
78
79
|
title: passport.title,
|
|
79
80
|
ownerName: ownerProfile ? ownerProfile.fullName : '',
|
|
80
81
|
ownerAvatarUrl: ownerProfile ? ownerProfile.avatar : '',
|
|
82
|
+
preferredColor,
|
|
81
83
|
}),
|
|
82
84
|
},
|
|
83
85
|
},
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
const { toHex } = require('@ocap/util');
|
|
2
|
+
const { Hasher } = require('@ocap/mcrypto');
|
|
3
|
+
const { getNftBGColor, DEFAULT_COLOR } = require('./passport-color');
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* Generate Passport SVG
|
|
3
7
|
*
|
|
@@ -5,15 +9,34 @@
|
|
|
5
9
|
* @param {string} issuer issuer name
|
|
6
10
|
* @param {string} issuerDid
|
|
7
11
|
* @param {boolean} ownerName
|
|
12
|
+
* @param {string} preferredColor
|
|
8
13
|
* @param {boolean} ownerAvatarUrl
|
|
9
14
|
* @param {boolean} revoked 是否撤销
|
|
10
15
|
* @param {boolean} isDataUrl 返回生成 data url
|
|
11
16
|
* @returns {string} svg xml or image data url
|
|
12
17
|
*/
|
|
13
|
-
const createPassportSvg = ({
|
|
18
|
+
const createPassportSvg = ({
|
|
19
|
+
issuer = '',
|
|
20
|
+
title = '',
|
|
21
|
+
issuerDid = '',
|
|
22
|
+
ownerName = '',
|
|
23
|
+
preferredColor = 'default',
|
|
24
|
+
ownerAvatarUrl = '',
|
|
25
|
+
revoked,
|
|
26
|
+
isDataUrl,
|
|
27
|
+
} = {}) => {
|
|
28
|
+
let colors;
|
|
29
|
+
if (preferredColor === 'default') {
|
|
30
|
+
colors = DEFAULT_COLOR;
|
|
31
|
+
} else if (preferredColor === 'auto') {
|
|
32
|
+
colors = getNftBGColor(`#${toHex(Hasher.SHA3.hash224(issuerDid)).slice(-6)}`);
|
|
33
|
+
} else {
|
|
34
|
+
colors = getNftBGColor(preferredColor);
|
|
35
|
+
}
|
|
36
|
+
|
|
14
37
|
const svgXML = `<svg width="100%" height="100%" viewBox="0 0 424 564" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
15
38
|
<rect x="1" y="1" width="422" height="562" rx="21" fill="url(#paint0_linear_6_342)"/>
|
|
16
|
-
<text x="360" y="65" fill="white" xml:space="preserve" font-family="Roboto" font-size="${(() => {
|
|
39
|
+
<text x="360" y="65" fill="white" xml:space="preserve" font-family="Roboto,Helvetica" font-size="${(() => {
|
|
17
40
|
if (title.length >= 6) {
|
|
18
41
|
return 24;
|
|
19
42
|
}
|
|
@@ -24,8 +47,8 @@ const createPassportSvg = ({ issuer, title, issuerDid, ownerName = '', ownerAvat
|
|
|
24
47
|
|
|
25
48
|
return 28;
|
|
26
49
|
})()}" letter-spacing="0px" style="dominant-baseline:middle;text-anchor:middle;">${title.toUpperCase()}</text>
|
|
27
|
-
<text opacity="0.4" fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto" font-size="16" font-weight="500" letter-spacing="0px"><tspan x="319" y="40.9688">PASSPORT</tspan></text>
|
|
28
|
-
<text fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto" font-size="${(() => {
|
|
50
|
+
<text opacity="0.4" fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto,Helvetica" font-size="16" font-weight="500" letter-spacing="0px"><tspan x="319" y="40.9688">PASSPORT</tspan></text>
|
|
51
|
+
<text fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto,Helvetica" font-size="${(() => {
|
|
29
52
|
if (issuer.length > 15) {
|
|
30
53
|
return 20;
|
|
31
54
|
}
|
|
@@ -42,15 +65,15 @@ const createPassportSvg = ({ issuer, title, issuerDid, ownerName = '', ownerAvat
|
|
|
42
65
|
<image x="152" y="190" href="${ownerAvatarUrl}" width="120" height="120" />
|
|
43
66
|
</pattern>
|
|
44
67
|
</defs>
|
|
45
|
-
<text x="215" y="350" fill="white" xml:space="preserve" style="dominant-baseline:middle;text-anchor:middle;" font-family="Roboto" font-size="28" font-weight="500" letter-spacing="0px">${ownerName}</text>
|
|
46
|
-
<text opacity="0.4" fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto" font-size="18" font-weight="500" letter-spacing="0px"><tspan x="26" y="407.652">ISSUER DID</tspan></text>
|
|
68
|
+
<text x="215" y="350" fill="white" xml:space="preserve" style="dominant-baseline:middle;text-anchor:middle;" font-family="Roboto,Helvetica" font-size="28" font-weight="500" letter-spacing="0px">${ownerName}</text>
|
|
69
|
+
<text opacity="0.4" fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto,Helvetica" font-size="18" font-weight="500" letter-spacing="0px"><tspan x="26" y="407.652">ISSUER DID</tspan></text>
|
|
47
70
|
<path fill-rule="evenodd" clip-rule="evenodd" d="M28.6722 423.313H45.3819C46.4294 423.313 47.2787 424.162 47.2787 425.21V433.79C47.2787 434.838 46.4294 435.687 45.3819 435.687H28.6722C27.9517 435.687 27.3249 435.285 27.0039 434.694H26.1167C26.4887 435.746 27.4924 436.5 28.6722 436.5H45.3819C46.8784 436.5 48.0916 435.287 48.0916 433.79V425.21C48.0916 423.713 46.8784 422.5 45.3819 422.5H28.6722C27.3296 422.5 26.215 423.477 26 424.758H26.8295C27.0321 423.929 27.7803 423.313 28.6722 423.313ZM27.8801 432.096C27.7831 432.089 27.6966 432.082 27.6204 432.075V427.526C27.7243 427.512 27.8351 427.505 27.9528 427.505C28.0705 427.498 28.1848 427.494 28.2955 427.494C29.1057 427.494 29.6978 427.688 30.0717 428.076C30.4457 428.464 30.6326 429.035 30.6326 429.79C30.6326 430.51 30.4353 431.074 30.0406 431.483C29.6528 431.892 29.0538 432.096 28.2436 432.096H27.8801ZM32.0141 431.421C32.208 430.957 32.305 430.413 32.305 429.79C32.305 429.139 32.208 428.582 32.0141 428.118C31.8202 427.654 31.5432 427.273 31.1832 426.975C30.8231 426.677 30.3903 426.459 29.8848 426.321C29.3862 426.182 28.8288 426.113 28.2125 426.113C27.9216 426.113 27.5719 426.127 27.1634 426.154C26.7617 426.175 26.3739 426.22 26 426.29V433.301C26.3739 433.377 26.7548 433.425 27.1426 433.446C27.5304 433.474 27.8697 433.488 28.1605 433.488C28.7976 433.488 29.3723 433.412 29.8848 433.259C30.3972 433.107 30.83 432.878 31.1832 432.574C31.5432 432.269 31.8202 431.885 32.0141 431.421ZM35.2788 426.196H33.6585V433.394H35.2788V426.196ZM38.5654 432.075C38.6416 432.082 38.7281 432.089 38.8251 432.096H39.1886C39.9988 432.096 40.5978 431.892 40.9856 431.483C41.3803 431.074 41.5776 430.51 41.5776 429.79C41.5776 429.035 41.3907 428.464 41.0167 428.076C40.6428 427.688 40.0507 427.494 39.2405 427.494C39.1298 427.494 39.0155 427.498 38.8978 427.505C38.7801 427.505 38.6693 427.512 38.5654 427.526V432.075ZM43.25 429.79C43.25 430.413 43.153 430.957 42.9591 431.421C42.7652 431.885 42.4882 432.269 42.1282 432.574C41.775 432.878 41.3422 433.107 40.8298 433.259C40.3173 433.412 39.7426 433.488 39.1055 433.488C38.8147 433.488 38.4754 433.474 38.0876 433.446C37.6998 433.425 37.3189 433.377 36.945 433.301V426.29C37.3189 426.22 37.7067 426.175 38.1084 426.154C38.5169 426.127 38.8666 426.113 39.1574 426.113C39.7738 426.113 40.3312 426.182 40.8298 426.321C41.3353 426.459 41.7681 426.677 42.1282 426.975C42.4882 427.273 42.7652 427.654 42.9591 428.118C43.153 428.582 43.25 429.139 43.25 429.79ZM45.1907 428.355C44.8209 428.355 44.5161 428.055 44.5161 427.686C44.5161 427.316 44.8209 427.016 45.1907 427.016C45.5604 427.016 45.8652 427.316 45.8652 427.686C45.8652 428.055 45.5604 428.355 45.1907 428.355ZM45.1907 431.855C44.8209 431.855 44.5161 431.555 44.5161 431.185C44.5161 430.815 44.8209 430.516 45.1907 430.516C45.5604 430.516 45.8652 430.815 45.8652 431.185C45.8652 431.555 45.5604 431.855 45.1907 431.855Z" fill="white"/>
|
|
48
|
-
<text fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto" font-size="15" font-weight="500" letter-spacing="0px"><tspan x="54.0916" y="434.969">${issuerDid}</tspan></text>
|
|
71
|
+
<text fill="white" xml:space="preserve" style="white-space: pre" font-family="Roboto,Helvetica" font-size="15" font-weight="500" letter-spacing="0px"><tspan x="54.0916" y="434.969">${issuerDid}</tspan></text>
|
|
49
72
|
<rect x="1" y="1" width="422" height="562" rx="21" stroke="#F0F0F0" stroke-width="2"/>
|
|
50
73
|
<defs>
|
|
51
74
|
<linearGradient id="paint0_linear_6_342" x1="414.5" y1="562" x2="-116.166" y2="156.726" gradientUnits="userSpaceOnUse">
|
|
52
|
-
<stop stop-color="
|
|
53
|
-
<stop offset="1" stop-color="
|
|
75
|
+
<stop stop-color="${colors.startColor}"/>
|
|
76
|
+
<stop offset="1" stop-color="${colors.endColor}"/>
|
|
54
77
|
</linearGradient>
|
|
55
78
|
</defs>
|
|
56
79
|
${
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
const DEFAULT_COLOR = {
|
|
2
|
+
startColor: '#2B3845',
|
|
3
|
+
endColor: '#5A7A8A',
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 将单个颜色转换为可用 nft 两个渐变背景色
|
|
8
|
+
* @param {String} rgbString 背景色
|
|
9
|
+
* @returns {Object}
|
|
10
|
+
*/
|
|
11
|
+
const getNftBGColor = (rgbString) => {
|
|
12
|
+
if (rgbString) {
|
|
13
|
+
const hsldata = rgbToHsl(rgbString);
|
|
14
|
+
|
|
15
|
+
// 色相 h 随意
|
|
16
|
+
// 饱和度 s 不可超过 0.8
|
|
17
|
+
// 亮度 l 不可超过 0.6,0.3 以上
|
|
18
|
+
const newHsl = [hsldata[0]];
|
|
19
|
+
if (hsldata[1] > 0.7) {
|
|
20
|
+
newHsl.push(0.7);
|
|
21
|
+
} else {
|
|
22
|
+
newHsl.push(hsldata[1]);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (hsldata[2] > 0.6) {
|
|
26
|
+
newHsl.push(0.6);
|
|
27
|
+
} else if (hsldata[2] < 0.3) {
|
|
28
|
+
newHsl.push(0.3);
|
|
29
|
+
} else {
|
|
30
|
+
newHsl.push(hsldata[2]);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const newRepeatHsl = [newHsl[0], newHsl[1], newHsl[2] - 0.1];
|
|
34
|
+
|
|
35
|
+
const newColor = hslToRgb(...newHsl);
|
|
36
|
+
const newRepeatColor = hslToRgb(...newRepeatHsl);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
startColor: newRepeatColor,
|
|
40
|
+
endColor: newColor,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
startColor: '#2B3845',
|
|
46
|
+
endColor: '#5A7A8A',
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* RGB 转换为 HSL 颜色
|
|
52
|
+
*
|
|
53
|
+
* @param {String} rgbString rgb色值
|
|
54
|
+
* @return {Array} HSL色值
|
|
55
|
+
*/
|
|
56
|
+
function rgbToHsl(rgbString) {
|
|
57
|
+
const color = rgbString.replace('#', '');
|
|
58
|
+
const r = parseInt(color.slice(0, 2), 16) / 255;
|
|
59
|
+
const g = parseInt(color.slice(2, 4), 16) / 255;
|
|
60
|
+
const b = parseInt(color.slice(4, 6), 16) / 255;
|
|
61
|
+
const max = Math.max(r, g, b);
|
|
62
|
+
const min = Math.min(r, g, b);
|
|
63
|
+
let h;
|
|
64
|
+
let s;
|
|
65
|
+
const l = (max + min) / 2;
|
|
66
|
+
|
|
67
|
+
if (max === min) {
|
|
68
|
+
h = 0;
|
|
69
|
+
s = 0;
|
|
70
|
+
} else {
|
|
71
|
+
const d = max - min;
|
|
72
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
73
|
+
switch (max) {
|
|
74
|
+
case r:
|
|
75
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
76
|
+
break;
|
|
77
|
+
case g:
|
|
78
|
+
h = (b - r) / d + 2;
|
|
79
|
+
break;
|
|
80
|
+
case b:
|
|
81
|
+
h = (r - g) / d + 4;
|
|
82
|
+
break;
|
|
83
|
+
default:
|
|
84
|
+
}
|
|
85
|
+
h /= 6;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return [h, s, l];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* HSL颜色值转换为RGB.
|
|
93
|
+
* h, s, 和 l 设定在 [0, 1] 之间
|
|
94
|
+
* @param {Number} h 色相
|
|
95
|
+
* @param {Number} s 饱和度
|
|
96
|
+
* @param {Number} l 亮度
|
|
97
|
+
* @returns rgb string
|
|
98
|
+
*/
|
|
99
|
+
function hslToRgb(h, s, l) {
|
|
100
|
+
let r;
|
|
101
|
+
let g;
|
|
102
|
+
let b;
|
|
103
|
+
|
|
104
|
+
if (s === 0) {
|
|
105
|
+
r = l;
|
|
106
|
+
g = l;
|
|
107
|
+
b = l;
|
|
108
|
+
} else {
|
|
109
|
+
const hue2rgb = (p, q, t2) => {
|
|
110
|
+
let t = t2;
|
|
111
|
+
if (t < 0) t += 1;
|
|
112
|
+
if (t > 1) t -= 1;
|
|
113
|
+
if (t < 1 / 6) return p + (q - p) * 6 * t;
|
|
114
|
+
if (t < 1 / 2) return q;
|
|
115
|
+
if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
|
116
|
+
return p;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
|
120
|
+
const p = 2 * l - q;
|
|
121
|
+
r = hue2rgb(p, q, h + 1 / 3);
|
|
122
|
+
g = hue2rgb(p, q, h);
|
|
123
|
+
b = hue2rgb(p, q, h - 1 / 3);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return `#${[Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)]
|
|
127
|
+
.map((e) => e.toString(16).padStart(2, 0))
|
|
128
|
+
.join('')}`;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
module.exports = {
|
|
132
|
+
getNftBGColor,
|
|
133
|
+
DEFAULT_COLOR,
|
|
134
|
+
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.6.
|
|
6
|
+
"version": "1.6.19",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,17 +20,17 @@
|
|
|
20
20
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.6.
|
|
24
|
-
"@abtnode/logger": "1.6.
|
|
25
|
-
"@abtnode/util": "1.6.
|
|
26
|
-
"@arcblock/did": "^1.
|
|
27
|
-
"@arcblock/vc": "^1.
|
|
28
|
-
"@blocklet/meta": "1.6.
|
|
29
|
-
"@ocap/mcrypto": "^1.
|
|
30
|
-
"@ocap/util": "^1.
|
|
31
|
-
"@ocap/wallet": "^1.
|
|
32
|
-
"axios": "^0.
|
|
33
|
-
"joi": "^17.
|
|
23
|
+
"@abtnode/constant": "1.6.19",
|
|
24
|
+
"@abtnode/logger": "1.6.19",
|
|
25
|
+
"@abtnode/util": "1.6.19",
|
|
26
|
+
"@arcblock/did": "^1.14.11",
|
|
27
|
+
"@arcblock/vc": "^1.14.11",
|
|
28
|
+
"@blocklet/meta": "1.6.19",
|
|
29
|
+
"@ocap/mcrypto": "^1.14.11",
|
|
30
|
+
"@ocap/util": "^1.14.11",
|
|
31
|
+
"@ocap/wallet": "^1.14.11",
|
|
32
|
+
"axios": "^0.25.0",
|
|
33
|
+
"joi": "^17.6.0",
|
|
34
34
|
"jsonwebtoken": "^8.5.1",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
36
36
|
"semver": "^7.3.2",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"jest": "^27.4.5"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "42a1290f14fca261eccafb05561eecf8683ed66a"
|
|
43
43
|
}
|