@abtnode/auth 1.16.6-beta-56be9f01 → 1.16.6-beta-e2082fec
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 +14 -4
- package/lib/server.js +20 -0
- package/package.json +12 -12
package/lib/auth.js
CHANGED
|
@@ -10,7 +10,7 @@ const { getChainClient } = require('@abtnode/util/lib/get-chain-client');
|
|
|
10
10
|
const { fromPublicKey } = require('@ocap/wallet');
|
|
11
11
|
const { fromBase58, toAddress } = require('@ocap/util');
|
|
12
12
|
const { toTypeInfo, isFromPublicKey } = require('@arcblock/did');
|
|
13
|
-
const
|
|
13
|
+
const { getRandomBytes, Hasher } = require('@ocap/mcrypto');
|
|
14
14
|
const getBlockletInfo = require('@blocklet/meta/lib/info');
|
|
15
15
|
const {
|
|
16
16
|
PASSPORT_STATUS,
|
|
@@ -95,6 +95,10 @@ const messages = {
|
|
|
95
95
|
en: 'You are not the owner of this application',
|
|
96
96
|
zh: '你不是该应用的所有者',
|
|
97
97
|
},
|
|
98
|
+
notSupported: {
|
|
99
|
+
en: 'This application is not supported on this server',
|
|
100
|
+
zh: '此应用不支持在当前节点安装',
|
|
101
|
+
},
|
|
98
102
|
missingCredentialClaim: {
|
|
99
103
|
en: 'Credential is not provided',
|
|
100
104
|
zh: '请提供凭证',
|
|
@@ -311,7 +315,7 @@ const getPassportStatusEndpoint = ({ baseUrl, userDid, teamDid }) => {
|
|
|
311
315
|
};
|
|
312
316
|
|
|
313
317
|
const getRandomMessage = (len = 16) => {
|
|
314
|
-
const hex =
|
|
318
|
+
const hex = getRandomBytes(len);
|
|
315
319
|
return hex.replace(/^0x/, '').toUpperCase();
|
|
316
320
|
};
|
|
317
321
|
|
|
@@ -324,6 +328,7 @@ const getApplicationInfo = async ({ node, nodeInfo = {}, teamDid }) => {
|
|
|
324
328
|
let passportColor;
|
|
325
329
|
let owner;
|
|
326
330
|
let dataDir;
|
|
331
|
+
let secret;
|
|
327
332
|
|
|
328
333
|
if (teamDid === nodeInfo.did) {
|
|
329
334
|
name = nodeInfo.name;
|
|
@@ -335,6 +340,7 @@ const getApplicationInfo = async ({ node, nodeInfo = {}, teamDid }) => {
|
|
|
335
340
|
passportColor = 'default';
|
|
336
341
|
owner = nodeInfo.nodeOwner;
|
|
337
342
|
dataDir = path.join(node.dataDirs.data, NODE_DATA_DIR_NAME);
|
|
343
|
+
secret = Hasher.SHA3.hash256(Buffer.concat([_wallet.secretKey, _wallet.address].map(Buffer.from)));
|
|
338
344
|
} else {
|
|
339
345
|
const blocklet = await node.getBlocklet({ did: teamDid, attachRuntimeInfo: false });
|
|
340
346
|
const blockletInfo = getBlockletInfo(blocklet, nodeInfo.sk);
|
|
@@ -346,6 +352,7 @@ const getApplicationInfo = async ({ node, nodeInfo = {}, teamDid }) => {
|
|
|
346
352
|
type = TEAM_TYPE.BLOCKLET;
|
|
347
353
|
owner = get(blocklet, 'settings.owner');
|
|
348
354
|
dataDir = blocklet.env.dataDir;
|
|
355
|
+
secret = blockletInfo.secret;
|
|
349
356
|
}
|
|
350
357
|
|
|
351
358
|
return {
|
|
@@ -357,6 +364,7 @@ const getApplicationInfo = async ({ node, nodeInfo = {}, teamDid }) => {
|
|
|
357
364
|
passportColor,
|
|
358
365
|
owner,
|
|
359
366
|
dataDir,
|
|
367
|
+
secret,
|
|
360
368
|
};
|
|
361
369
|
};
|
|
362
370
|
|
|
@@ -577,8 +585,10 @@ const handleInvitationReceive = async ({
|
|
|
577
585
|
dataDir,
|
|
578
586
|
});
|
|
579
587
|
|
|
588
|
+
let doc;
|
|
589
|
+
|
|
580
590
|
if (user) {
|
|
581
|
-
|
|
591
|
+
doc = await node.loginUser({
|
|
582
592
|
teamDid,
|
|
583
593
|
user: {
|
|
584
594
|
...profile,
|
|
@@ -606,7 +616,7 @@ const handleInvitationReceive = async ({
|
|
|
606
616
|
node
|
|
607
617
|
);
|
|
608
618
|
} else {
|
|
609
|
-
|
|
619
|
+
doc = await node.loginUser({
|
|
610
620
|
teamDid,
|
|
611
621
|
user: {
|
|
612
622
|
...profile,
|
package/lib/server.js
CHANGED
|
@@ -25,6 +25,7 @@ const {
|
|
|
25
25
|
NFT_TYPE_SERVERLESS,
|
|
26
26
|
MAIN_CHAIN_ENDPOINT,
|
|
27
27
|
APP_STRUCT_VERSION,
|
|
28
|
+
NODE_MODES,
|
|
28
29
|
} = require('@abtnode/constant');
|
|
29
30
|
const {
|
|
30
31
|
messages,
|
|
@@ -818,6 +819,24 @@ const createRestoreOnServerlessHandler =
|
|
|
818
819
|
};
|
|
819
820
|
};
|
|
820
821
|
|
|
822
|
+
const createServerlessInstallGuard = (node) => {
|
|
823
|
+
return async ({ extraParams }) => {
|
|
824
|
+
const { locale, blockletMetaUrl } = extraParams;
|
|
825
|
+
const [info, blocklet] = await Promise.all([
|
|
826
|
+
node.getNodeInfo(),
|
|
827
|
+
blockletMetaUrl ? node.getBlockletMetaFromUrl({ url: blockletMetaUrl, checkPrice: true }) : null,
|
|
828
|
+
]);
|
|
829
|
+
|
|
830
|
+
// check if serverless is supported
|
|
831
|
+
if (blocklet && info.mode === NODE_MODES.SERVERLESS) {
|
|
832
|
+
const isServerlessSupported = get(blocklet.meta, 'capabilities.serverless', true);
|
|
833
|
+
if (!isServerlessSupported) {
|
|
834
|
+
throw new Error(messages.notSupported[locale]);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
};
|
|
839
|
+
|
|
821
840
|
module.exports = {
|
|
822
841
|
getAuthVcClaim,
|
|
823
842
|
getKeyPairClaim,
|
|
@@ -839,4 +858,5 @@ module.exports = {
|
|
|
839
858
|
getLauncherAppIdList,
|
|
840
859
|
getAuthPrincipalForMigrateAppToV2,
|
|
841
860
|
getAuthPrincipalForTransferAppOwnerShip,
|
|
861
|
+
createServerlessInstallGuard,
|
|
842
862
|
};
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.6-beta-
|
|
6
|
+
"version": "1.16.6-beta-e2082fec",
|
|
7
7
|
"description": "Simple lib to manage auth in ABT Node",
|
|
8
8
|
"main": "lib/index.js",
|
|
9
9
|
"files": [
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"author": "linchen <linchen1987@foxmail.com> (http://github.com/linchen1987)",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.16.6-beta-
|
|
24
|
-
"@abtnode/logger": "1.16.6-beta-
|
|
25
|
-
"@abtnode/util": "1.16.6-beta-
|
|
26
|
-
"@arcblock/did": "1.18.
|
|
27
|
-
"@arcblock/vc": "1.18.
|
|
28
|
-
"@blocklet/constant": "1.16.6-beta-
|
|
29
|
-
"@blocklet/meta": "1.16.6-beta-
|
|
30
|
-
"@ocap/mcrypto": "1.18.
|
|
31
|
-
"@ocap/util": "1.18.
|
|
32
|
-
"@ocap/wallet": "1.18.
|
|
23
|
+
"@abtnode/constant": "1.16.6-beta-e2082fec",
|
|
24
|
+
"@abtnode/logger": "1.16.6-beta-e2082fec",
|
|
25
|
+
"@abtnode/util": "1.16.6-beta-e2082fec",
|
|
26
|
+
"@arcblock/did": "1.18.77",
|
|
27
|
+
"@arcblock/vc": "1.18.77",
|
|
28
|
+
"@blocklet/constant": "1.16.6-beta-e2082fec",
|
|
29
|
+
"@blocklet/meta": "1.16.6-beta-e2082fec",
|
|
30
|
+
"@ocap/mcrypto": "1.18.77",
|
|
31
|
+
"@ocap/util": "1.18.77",
|
|
32
|
+
"@ocap/wallet": "1.18.77",
|
|
33
33
|
"joi": "17.7.0",
|
|
34
34
|
"jsonwebtoken": "^9.0.0",
|
|
35
35
|
"lodash": "^4.17.21",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"jest": "^27.5.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "851e0ab17f1c6e160aedc47fcdbf7dd54dfa7237"
|
|
45
45
|
}
|