@abtnode/auth 1.7.26 → 1.8.1
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 +4 -0
- package/lib/server.js +23 -65
- package/package.json +7 -6
package/lib/auth.js
CHANGED
|
@@ -402,10 +402,14 @@ const handleInvitationResponse = async ({
|
|
|
402
402
|
verifySignature(claim, userDid, userPk, locale);
|
|
403
403
|
|
|
404
404
|
const tmpInvitation = await node.getInvitation({ teamDid, inviteId });
|
|
405
|
+
if (!tmpInvitation) {
|
|
406
|
+
throw new Error(`The invitation does not exist: ${inviteId}`);
|
|
407
|
+
}
|
|
405
408
|
|
|
406
409
|
if (tmpInvitation.role === 'owner' && userDid === nodeInfo.nodeOwner.did) {
|
|
407
410
|
throw new Error(messages.notAllowedTransferToSelf[locale]);
|
|
408
411
|
}
|
|
412
|
+
|
|
409
413
|
const inviteInfo = await node.processInvitation({ teamDid, inviteId });
|
|
410
414
|
if (inviteInfo.role === 'owner' && get(nodeInfo, 'ownerNft.holder')) {
|
|
411
415
|
// 这种情况下是 Transfer 有 Owner NFT 的 Blocklet Server
|
package/lib/server.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const get = require('lodash/get');
|
|
2
|
+
const isEmpty = require('lodash/isEmpty');
|
|
2
3
|
const last = require('lodash/last');
|
|
3
4
|
const Client = require('@ocap/client');
|
|
4
5
|
const { fromPublicKey } = require('@ocap/wallet');
|
|
@@ -10,7 +11,6 @@ const {
|
|
|
10
11
|
ROLES,
|
|
11
12
|
VC_TYPE_GENERAL_PASSPORT,
|
|
12
13
|
VC_TYPE_NODE_PASSPORT,
|
|
13
|
-
VC_TYPE_BLOCKLET_PURCHASE,
|
|
14
14
|
NFT_TYPE_SERVER_OWNERSHIP,
|
|
15
15
|
} = require('@abtnode/constant');
|
|
16
16
|
const {
|
|
@@ -29,13 +29,11 @@ const {
|
|
|
29
29
|
getRoleFromExternalPassport,
|
|
30
30
|
createUserPassport,
|
|
31
31
|
} = require('./passport');
|
|
32
|
-
|
|
33
32
|
const logger = require('./logger');
|
|
34
33
|
|
|
35
34
|
const secret = process.env.ABT_NODE_SESSION_SECRET;
|
|
36
35
|
const LAUNCH_BLOCKLET_TOKEN_EXPIRE = '1d';
|
|
37
36
|
const abtnodeVcTypes = [VC_TYPE_GENERAL_PASSPORT, VC_TYPE_NODE_PASSPORT];
|
|
38
|
-
const blockletVcTypes = [VC_TYPE_BLOCKLET_PURCHASE];
|
|
39
37
|
|
|
40
38
|
const authenticateByVc = async ({ node, locale, userDid, claims, challenge, requireNodeInitialized = true }) => {
|
|
41
39
|
if (requireNodeInitialized) {
|
|
@@ -184,7 +182,7 @@ const getAuthVcClaim =
|
|
|
184
182
|
return claim;
|
|
185
183
|
};
|
|
186
184
|
|
|
187
|
-
const
|
|
185
|
+
const getLaunchBlockletClaims = (node, authMethod) => {
|
|
188
186
|
if (authMethod === 'vc') {
|
|
189
187
|
return {
|
|
190
188
|
serverPassport: ['verifiableCredential', getAuthVcClaim(node)],
|
|
@@ -202,31 +200,6 @@ const getLaunchFreeBlockletClaims = (node, authMethod) => {
|
|
|
202
200
|
};
|
|
203
201
|
};
|
|
204
202
|
|
|
205
|
-
const getLaunchPaidBlockletClaims = (node, authMethod) => {
|
|
206
|
-
const claims = getLaunchFreeBlockletClaims(node, authMethod);
|
|
207
|
-
|
|
208
|
-
claims.blockletPurchaseNft = [
|
|
209
|
-
'verifiableCredential',
|
|
210
|
-
async ({ extraParams: { locale, blockletMetaUrl }, context: { didwallet } }) => {
|
|
211
|
-
checkWalletVersion({ didwallet, locale });
|
|
212
|
-
const registryUrl = new URL(blockletMetaUrl).origin;
|
|
213
|
-
const [registry, { meta }] = await Promise.all([
|
|
214
|
-
node.getRegistryMeta(registryUrl),
|
|
215
|
-
node.getBlockletMetaFromUrl({ url: blockletMetaUrl }),
|
|
216
|
-
]);
|
|
217
|
-
|
|
218
|
-
return {
|
|
219
|
-
description: messages.requestBlockletNft[locale],
|
|
220
|
-
item: blockletVcTypes,
|
|
221
|
-
trustedIssuers: [registry.id],
|
|
222
|
-
tag: meta.did,
|
|
223
|
-
};
|
|
224
|
-
},
|
|
225
|
-
];
|
|
226
|
-
|
|
227
|
-
return claims;
|
|
228
|
-
};
|
|
229
|
-
|
|
230
203
|
const getOwnershipNFTClaim = async (node, locale) => {
|
|
231
204
|
const info = await node.getNodeInfo();
|
|
232
205
|
if (!info.ownerNft && !info.ownerNft.issuer) {
|
|
@@ -281,8 +254,12 @@ const ensureBlockletPermission = async ({ authMethod, node, userDid, claims, cha
|
|
|
281
254
|
|
|
282
255
|
const createLaunchBlockletHandler =
|
|
283
256
|
(node, authMethod) =>
|
|
284
|
-
async ({ claims, challenge, userDid, updateSession, req, extraParams
|
|
257
|
+
async ({ claims, challenge, userDid, updateSession, req, extraParams }) => {
|
|
258
|
+
const { locale, blockletMetaUrl } = extraParams;
|
|
259
|
+
logger.info('createLaunchBlockletHandler', extraParams);
|
|
260
|
+
|
|
285
261
|
if (!blockletMetaUrl) {
|
|
262
|
+
logger.error('blockletMetaUrl must be provided');
|
|
286
263
|
throw new Error(messages.invalidParams[locale]);
|
|
287
264
|
}
|
|
288
265
|
|
|
@@ -295,37 +272,20 @@ const createLaunchBlockletHandler =
|
|
|
295
272
|
locale,
|
|
296
273
|
});
|
|
297
274
|
|
|
298
|
-
const
|
|
299
|
-
if (!
|
|
275
|
+
const blocklet = await node.getBlockletMetaFromUrl({ url: blockletMetaUrl, checkPrice: true });
|
|
276
|
+
if (!blocklet.meta) {
|
|
300
277
|
throw new Error(messages.invalidBlocklet[locale]);
|
|
301
278
|
}
|
|
302
279
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
const registryUrl = new URL(blockletMetaUrl).origin;
|
|
308
|
-
const registryMeta = await node.getRegistryMeta(registryUrl);
|
|
309
|
-
|
|
310
|
-
const { vc: blockletVc } = await getVCFromClaims({
|
|
311
|
-
claims,
|
|
312
|
-
challenge,
|
|
313
|
-
trustedIssuers: [registryMeta.id],
|
|
314
|
-
vcTypes: blockletVcTypes,
|
|
315
|
-
locale,
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
if (!blockletVc) {
|
|
319
|
-
throw new Error(messages.missingBlockletCredentialClaim[locale]);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
if (get(blockletVc, 'credentialSubject.purchased.blocklet.id') !== did) {
|
|
323
|
-
throw new Error(messages.invalidBlockletVc[locale]);
|
|
280
|
+
if (!blocklet.isFree) {
|
|
281
|
+
if (isEmpty(extraParams?.previousWorkflowData?.downloadToken)) {
|
|
282
|
+
logger.error('downloadToken must be provided');
|
|
283
|
+
throw new Error(messages.invalidParams[locale]);
|
|
324
284
|
}
|
|
325
|
-
|
|
326
|
-
blockletPurchaseVerified = true;
|
|
327
285
|
}
|
|
328
286
|
|
|
287
|
+
const { did } = blocklet.meta;
|
|
288
|
+
|
|
329
289
|
let sessionToken = '';
|
|
330
290
|
if (authMethod === 'vc') {
|
|
331
291
|
sessionToken = createAuthToken({
|
|
@@ -345,19 +305,19 @@ const createLaunchBlockletHandler =
|
|
|
345
305
|
}
|
|
346
306
|
|
|
347
307
|
// 检查是否已安装,这里不做升级的处理
|
|
348
|
-
const existedBlocklet = await node.getBlocklet({ did });
|
|
308
|
+
const existedBlocklet = await node.getBlocklet({ did, attachRuntimeInfo: false });
|
|
349
309
|
await updateSession({ sessionToken }, true);
|
|
350
310
|
|
|
351
311
|
if (existedBlocklet) {
|
|
352
312
|
const storageData = { did: userDid };
|
|
353
313
|
|
|
354
|
-
if (semver.gt(
|
|
314
|
+
if (semver.gt(blocklet.meta.version, existedBlocklet.meta.version)) {
|
|
355
315
|
const appDidEnv = existedBlocklet.environments.find((e) => e.key === 'BLOCKLET_APP_ID');
|
|
356
316
|
storageData.upgradeAvailable = {
|
|
357
317
|
appDid: appDidEnv ? appDidEnv.value : '',
|
|
358
318
|
did: existedBlocklet.meta.did,
|
|
359
319
|
currentVersion: existedBlocklet.meta.version,
|
|
360
|
-
version:
|
|
320
|
+
version: blocklet.meta.version,
|
|
361
321
|
};
|
|
362
322
|
}
|
|
363
323
|
|
|
@@ -366,12 +326,11 @@ const createLaunchBlockletHandler =
|
|
|
366
326
|
return;
|
|
367
327
|
}
|
|
368
328
|
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
}
|
|
329
|
+
const tmp = await node.installBlocklet({
|
|
330
|
+
url: blockletMetaUrl,
|
|
331
|
+
downloadToken: extraParams?.previousWorkflowData?.downloadToken,
|
|
332
|
+
});
|
|
373
333
|
|
|
374
|
-
const tmp = await node.installBlocklet({ url: blockletMetaUrl }, context);
|
|
375
334
|
await node.createAuditLog(
|
|
376
335
|
{
|
|
377
336
|
action: 'installBlocklet',
|
|
@@ -389,8 +348,7 @@ module.exports = {
|
|
|
389
348
|
authenticateByVc,
|
|
390
349
|
authenticateByNFT,
|
|
391
350
|
getOwnershipNFTClaim,
|
|
392
|
-
|
|
393
|
-
getLaunchPaidBlockletClaims,
|
|
351
|
+
getLaunchBlockletClaims,
|
|
394
352
|
createLaunchBlockletHandler,
|
|
395
353
|
ensureBlockletPermission,
|
|
396
354
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.
|
|
6
|
+
"version": "1.8.1",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,12 +20,13 @@
|
|
|
20
20
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.
|
|
24
|
-
"@abtnode/logger": "1.
|
|
25
|
-
"@abtnode/util": "1.
|
|
23
|
+
"@abtnode/constant": "1.8.1",
|
|
24
|
+
"@abtnode/logger": "1.8.1",
|
|
25
|
+
"@abtnode/util": "1.8.1",
|
|
26
26
|
"@arcblock/did": "1.17.0",
|
|
27
|
+
"@arcblock/jwt": "^1.17.0",
|
|
27
28
|
"@arcblock/vc": "1.17.0",
|
|
28
|
-
"@blocklet/meta": "1.
|
|
29
|
+
"@blocklet/meta": "1.8.1",
|
|
29
30
|
"@ocap/client": "1.17.0",
|
|
30
31
|
"@ocap/mcrypto": "1.17.0",
|
|
31
32
|
"@ocap/util": "1.17.0",
|
|
@@ -40,5 +41,5 @@
|
|
|
40
41
|
"devDependencies": {
|
|
41
42
|
"jest": "^27.4.5"
|
|
42
43
|
},
|
|
43
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "c970b8a386bebd7fe6dbc8b8eedf8bd8328b4bb5"
|
|
44
45
|
}
|