@abtnode/auth 1.16.25-beta-023ec101 → 1.16.25-beta-bc165d9b
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 +2 -1
- package/lib/launcher.js +18 -4
- package/lib/server.js +13 -9
- package/lib/util/get-auth-method.js +24 -7
- package/locales/ar.js +2 -0
- package/locales/de.js +2 -0
- package/locales/en.js +2 -1
- package/locales/es.js +2 -0
- package/locales/fr.js +2 -0
- package/locales/hi.js +2 -0
- package/locales/id.js +2 -0
- package/locales/ja.js +2 -0
- package/locales/ko.js +2 -0
- package/locales/pt.js +2 -0
- package/locales/ru.js +2 -0
- package/locales/th.js +2 -0
- package/locales/vi.js +2 -0
- package/locales/zh-tw.js +2 -0
- package/locales/zh.js +2 -0
- package/package.json +9 -9
package/lib/auth.js
CHANGED
|
@@ -100,7 +100,8 @@ const messages = {
|
|
|
100
100
|
nftAlreadyUsed: getLocaleMap('nftAlreadyUsed'),
|
|
101
101
|
missingNftClaim: getLocaleMap('missingNftClaim'),
|
|
102
102
|
noNft: getLocaleMap('noNft'),
|
|
103
|
-
|
|
103
|
+
noLauncherDid: getLocaleMap('noLauncherDid'),
|
|
104
|
+
noNftDid: getLocaleMap('noNftDid'),
|
|
104
105
|
noChainHost: getLocaleMap('noChainHost'),
|
|
105
106
|
alreadyTransferred: getLocaleMap('alreadyTransferred'),
|
|
106
107
|
delegateTransferOwnerNFT: getLocaleMap('delegateTransferOwnerNFT'),
|
package/lib/launcher.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const Joi = require('joi');
|
|
2
2
|
const axios = require('@abtnode/util/lib/axios');
|
|
3
|
-
const
|
|
3
|
+
const { joinURL } = require('ufo');
|
|
4
4
|
const pRetry = require('p-retry');
|
|
5
5
|
const { stableStringify } = require('@arcblock/vc');
|
|
6
6
|
const { toBase58 } = require('@ocap/util');
|
|
@@ -9,6 +9,8 @@ const formatError = require('@abtnode/util/lib/format-error');
|
|
|
9
9
|
|
|
10
10
|
const logger = require('@abtnode/logger')('@abtnode/auth:launcher');
|
|
11
11
|
|
|
12
|
+
const LAUNCHER_BLOCKLET_DID = 'z8iZkFBbrVQxZHvcWWB3Sa2TrfGmSeFz9MSU7';
|
|
13
|
+
|
|
12
14
|
const schema = Joi.object({
|
|
13
15
|
launcherSessionId: Joi.string().required(),
|
|
14
16
|
launcherUrl: Joi.string().uri().required(),
|
|
@@ -23,9 +25,20 @@ const doRequest = async (serverSk, { launcherUrl, pathname, payload, method = 'p
|
|
|
23
25
|
const wallet = getNodeWallet(serverSk);
|
|
24
26
|
|
|
25
27
|
const fn = async () => {
|
|
28
|
+
const baseURL = new URL(launcherUrl).origin;
|
|
29
|
+
const { data: launcherMeta } = await axios.get(joinURL(baseURL, '__blocklet__.js?type=json'));
|
|
30
|
+
const mountPoint = launcherMeta.componentMountPoints?.find((x) => x.did === LAUNCHER_BLOCKLET_DID);
|
|
31
|
+
if (!mountPoint) {
|
|
32
|
+
throw new Error('launcher blocklet mount point not found');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const url = joinURL(baseURL, mountPoint.mountPoint, pathname);
|
|
36
|
+
|
|
37
|
+
logger.info('do launcher request', { url, method, payload });
|
|
38
|
+
|
|
26
39
|
const { data } = await axios({
|
|
27
40
|
method,
|
|
28
|
-
url
|
|
41
|
+
url,
|
|
29
42
|
data: method !== 'get' ? payload : {},
|
|
30
43
|
params: method === 'get' ? payload : {},
|
|
31
44
|
headers: {
|
|
@@ -42,7 +55,7 @@ const doRequest = async (serverSk, { launcherUrl, pathname, payload, method = 'p
|
|
|
42
55
|
minTimeout: delay,
|
|
43
56
|
maxTimeout: delay,
|
|
44
57
|
onFailedAttempt: (error) => {
|
|
45
|
-
logger.error('failed to call launcher', { error, launcherUrl, pathname, payload });
|
|
58
|
+
logger.error('failed to call launcher', { error, method, launcherUrl, pathname, payload });
|
|
46
59
|
// Exclude retrying for 4XX response codes
|
|
47
60
|
if (error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
48
61
|
throw error;
|
|
@@ -60,7 +73,7 @@ const getLauncherSession = async (serverSk, params) => {
|
|
|
60
73
|
const { launcherSessionId, launcherUrl } = params;
|
|
61
74
|
try {
|
|
62
75
|
const result = await doRequest(serverSk, {
|
|
63
|
-
launcherUrl,
|
|
76
|
+
launcherUrl: launcherUrl || 'https://launcher.arcblock.io/',
|
|
64
77
|
pathname: `/api/launches/${launcherSessionId}`,
|
|
65
78
|
payload: {},
|
|
66
79
|
method: 'get',
|
|
@@ -87,4 +100,5 @@ module.exports = {
|
|
|
87
100
|
doRequest,
|
|
88
101
|
getLauncherSession,
|
|
89
102
|
getLauncherUser,
|
|
103
|
+
LAUNCHER_BLOCKLET_DID,
|
|
90
104
|
};
|
package/lib/server.js
CHANGED
|
@@ -223,7 +223,6 @@ const authenticateByNFT = async ({ node, claims, userDid, challenge, locale, isA
|
|
|
223
223
|
nftId: state.address,
|
|
224
224
|
nftOwner: state.owner,
|
|
225
225
|
chainHost,
|
|
226
|
-
appMaxCount: state.data.value.appMaxCount || 1,
|
|
227
226
|
},
|
|
228
227
|
},
|
|
229
228
|
user: {
|
|
@@ -270,7 +269,6 @@ const authenticateByLauncher = async ({ node, claims, launcherSessionId, launche
|
|
|
270
269
|
nftId: launcherSession.nftDid,
|
|
271
270
|
nftOwner: launcherSession.userDid,
|
|
272
271
|
chainHost,
|
|
273
|
-
appMaxCount: 1,
|
|
274
272
|
launcherUrl,
|
|
275
273
|
launcherSessionId,
|
|
276
274
|
ownerDid: claim.userDid,
|
|
@@ -522,19 +520,25 @@ const getOwnershipNFTClaim = async (node, locale) => {
|
|
|
522
520
|
throw new Error(messages.noNft[locale]);
|
|
523
521
|
}
|
|
524
522
|
|
|
525
|
-
const
|
|
523
|
+
const launcherDid = get(info, 'launcher.did', '');
|
|
524
|
+
const nftDid = get(info, 'launcher.nftDid', '');
|
|
526
525
|
const chainHost = get(info, 'launcher.chainHost', '');
|
|
527
|
-
if (!
|
|
528
|
-
throw new Error(messages.
|
|
526
|
+
if (!launcherDid) {
|
|
527
|
+
throw new Error(messages.noLauncherDid[locale]);
|
|
529
528
|
}
|
|
529
|
+
|
|
530
|
+
if (!nftDid) {
|
|
531
|
+
throw new Error(messages.noNftDid[locale]);
|
|
532
|
+
}
|
|
533
|
+
|
|
530
534
|
if (!chainHost) {
|
|
531
535
|
throw new Error(messages.noChainHost[locale]);
|
|
532
536
|
}
|
|
533
537
|
|
|
534
538
|
return {
|
|
535
539
|
description: messages.requestBlockletSpaceNFT[locale],
|
|
536
|
-
trustedIssuers: [
|
|
537
|
-
|
|
540
|
+
trustedIssuers: [launcherDid],
|
|
541
|
+
address: nftDid,
|
|
538
542
|
};
|
|
539
543
|
};
|
|
540
544
|
|
|
@@ -879,7 +883,6 @@ const handleRestoreByLauncherSession = async ({ node, userDid, updateSession, ex
|
|
|
879
883
|
nftId: launcherSession.nftDid,
|
|
880
884
|
nftOwner: launcherSession.userDid,
|
|
881
885
|
chainHost,
|
|
882
|
-
appMaxCount: 1,
|
|
883
886
|
launcherUrl,
|
|
884
887
|
launcherSessionId,
|
|
885
888
|
ownerDid: userDid, // FIXME: @wangshijun is this incorrect
|
|
@@ -963,7 +966,8 @@ const createServerlessInstallGuard = (node) => {
|
|
|
963
966
|
}
|
|
964
967
|
|
|
965
968
|
// check if launcher session consumed
|
|
966
|
-
|
|
969
|
+
// 只在 launch serverless 时校验 launch session 的合法性
|
|
970
|
+
if (launcherUrl && launcherSessionId && info.mode === NODE_MODES.SERVERLESS) {
|
|
967
971
|
if (await node.isLauncherSessionConsumed({ launcherUrl, launcherSessionId })) {
|
|
968
972
|
throw new Error(messages.sessionAlreadyConsumed[locale]);
|
|
969
973
|
}
|
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
const get = require('lodash/get');
|
|
2
2
|
|
|
3
|
+
const isServerLaunchedByLauncher = (info) =>
|
|
4
|
+
get(info, 'ownerNft.holder') &&
|
|
5
|
+
get(info, 'ownerNft.issuer') &&
|
|
6
|
+
get(info, 'launcher.tag') &&
|
|
7
|
+
get(info, 'launcher.chainHost') &&
|
|
8
|
+
get(info, 'launcher.did') === get(info, 'ownerNft.issuer');
|
|
9
|
+
|
|
3
10
|
const getServerAuthMethod = (info, type, launcherSessionId = '', authorized = false) => {
|
|
4
11
|
if (launcherSessionId) {
|
|
12
|
+
/*
|
|
13
|
+
* 需要用户提供 Ownership NFT 的情况:
|
|
14
|
+
* - 通过 Blocklet Launcher Launch
|
|
15
|
+
* - Server 是通过 Blocklet Launcher Launch 的
|
|
16
|
+
* - Server 没有初始化
|
|
17
|
+
*/
|
|
18
|
+
if (isServerLaunchedByLauncher(info) && !info.initialized && type !== 'serverless') {
|
|
19
|
+
return 'nft';
|
|
20
|
+
}
|
|
21
|
+
|
|
5
22
|
return 'launcher';
|
|
6
23
|
}
|
|
7
24
|
|
|
@@ -17,13 +34,13 @@ const getServerAuthMethod = (info, type, launcherSessionId = '', authorized = fa
|
|
|
17
34
|
return 'vc';
|
|
18
35
|
}
|
|
19
36
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
) {
|
|
37
|
+
/*
|
|
38
|
+
* 下面的情况也需要提供 NFT
|
|
39
|
+
* - 没有 launcherSessionId
|
|
40
|
+
* - Blocklet Server 没有初始化
|
|
41
|
+
* - Blocklet Server 是通过 Blocklet Launcher Launch
|
|
42
|
+
*/
|
|
43
|
+
if (isServerLaunchedByLauncher(info)) {
|
|
27
44
|
return 'nft';
|
|
28
45
|
}
|
|
29
46
|
|
package/locales/ar.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'التطبيق قيد التقدم، يرجى الانتظار حتى الانتهاء.',
|
|
67
67
|
requestDidSpace: 'يرجى تفويض مساحة DID للاستمرار',
|
|
68
68
|
cannotImportFromDidSpace: 'غير قادر على إيجاد بيانات من الفضاء({spaceName}) التي يمكن استيرادها',
|
|
69
|
+
noLauncherDid: 'لم يتم العثور على المشغّل من معلومات مشغّل الخادم',
|
|
70
|
+
noNftDid: 'لم يتم العثور على NFT من معلومات مشغل الخادم',
|
|
69
71
|
};
|
package/locales/de.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'Die Anwendung befindet sich in Bearbeitung. Bitte warten Sie, bis sie abgeschlossen ist.',
|
|
67
67
|
requestDidSpace: 'Bitte autorisieren Sie DID Space, um fortzufahren',
|
|
68
68
|
cannotImportFromDidSpace: 'Kann keine Daten aus dem Bereich({spaceName}) finden, die importiert werden können',
|
|
69
|
+
noLauncherDid: 'Launcher wurde nicht von der Server Launcher Info gefunden',
|
|
70
|
+
noNftDid: 'NFT wurde in den Server-Launcher-Informationen nicht gefunden',
|
|
69
71
|
};
|
package/locales/en.js
CHANGED
|
@@ -57,7 +57,8 @@ module.exports = {
|
|
|
57
57
|
nftAlreadyUsed: 'This NFT has already been connected to another user',
|
|
58
58
|
missingNftClaim: 'Ownership NFT not provided',
|
|
59
59
|
noNft: 'This server is not initialized to accept ownership NFT',
|
|
60
|
-
|
|
60
|
+
noLauncherDid: 'Launcher DID not found from server launcher info',
|
|
61
|
+
noNftDid: 'NFT DID not found from server launcher info',
|
|
61
62
|
noChainHost: 'chainHost not found from server launcher info',
|
|
62
63
|
alreadyTransferred: 'The Blocklet Server already belongs to {owner}',
|
|
63
64
|
delegateTransferOwnerNFT:
|
package/locales/es.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'La aplicación está en progreso, por favor espere a que termine',
|
|
67
67
|
requestDidSpace: 'Por favor, autoriza a DID Space para continuar',
|
|
68
68
|
cannotImportFromDidSpace: 'No se pueden encontrar datos para importar desde el espacio ({spaceName})',
|
|
69
|
+
noLauncherDid: 'El lanzador NO fue encontrado en la información del lanzador del servidor',
|
|
70
|
+
noNftDid: 'NFT DID no encontrada en el lanzador del servidor',
|
|
69
71
|
};
|
package/locales/fr.js
CHANGED
|
@@ -67,4 +67,6 @@ module.exports = {
|
|
|
67
67
|
appIsInProgress: "L'application est en cours, veuillez attendre qu'elle se termine.",
|
|
68
68
|
requestDidSpace: 'Veuillez autoriser DID Space à continuer',
|
|
69
69
|
cannotImportFromDidSpace: "Impossible de trouver des données de l'espace({spaceName}) pouvant être importées",
|
|
70
|
+
noLauncherDid: "Launcher n'a pas été trouvé depuis les informations du serveur Launcher",
|
|
71
|
+
noNftDid: 'Aucun NFT trouvé dans les informations du lanceur de serveur',
|
|
70
72
|
};
|
package/locales/hi.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'ऐप्लीकेशन प्रगति में है, कृपया पूरा होने तक प्रतीक्षा करें।',
|
|
67
67
|
requestDidSpace: 'कृपया DID स्थान की प्राधिकरणदिये जारी रखें',
|
|
68
68
|
cannotImportFromDidSpace: 'डेटास्पेस({spaceName}) से आयात किए जा सकने वाले डेटा को खोजने में असमर्थ',
|
|
69
|
+
noLauncherDid: 'Launcher सर्वर लॉन्चर जानकारी से नहीं मिला',
|
|
70
|
+
noNftDid: 'NFT सर्वर लॉन्चर जानकारी से नहीं मिला',
|
|
69
71
|
};
|
package/locales/id.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'Aplikasi ini sedang berjalan, mohon tunggu hingga selesai',
|
|
67
67
|
requestDidSpace: 'Silakan otorisasi DID Space untuk melanjutkan',
|
|
68
68
|
cannotImportFromDidSpace: 'Tidak dapat menemukan data dari ruang({spaceName}) yang dapat diimport',
|
|
69
|
+
noLauncherDid: 'Launcher TIDAK ditemukan dari info launcher server',
|
|
70
|
+
noNftDid: 'NFT DID tidak ditemukan dari info peluncur server',
|
|
69
71
|
};
|
package/locales/ja.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'アプリケーションは進行中です。完了するまでお待ちください',
|
|
67
67
|
requestDidSpace: '続行するためにDID Spaceへの承認をお願いします',
|
|
68
68
|
cannotImportFromDidSpace: 'スペース ({spaceName}) からインポートできるデータが見つかりません',
|
|
69
|
+
noLauncherDid: 'ランチャーがサーバーランチャー情報から見つかりませんでした',
|
|
70
|
+
noNftDid: 'NFT DID がサーバーランチャー情報から見つかりませんでした',
|
|
69
71
|
};
|
package/locales/ko.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: '애플리케이션 진행 중입니다. 완료될 때까지 기다려주세요',
|
|
67
67
|
requestDidSpace: '계속하려면 DID Space를 인증해주세요',
|
|
68
68
|
cannotImportFromDidSpace: '공간({spaceName})에서 가져올 수 있는 데이터를 찾을 수 없습니다.',
|
|
69
|
+
noLauncherDid: '서버 런처 정보에서 런처를 찾지 못했습니다',
|
|
70
|
+
noNftDid: '서버 런처 정보에서 NFT DID를 찾지 못했습니다',
|
|
69
71
|
};
|
package/locales/pt.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'O aplicativo está em progresso, por favor, aguarde até que ele termine',
|
|
67
67
|
requestDidSpace: 'Por favor, autorize o DID Space a continuar',
|
|
68
68
|
cannotImportFromDidSpace: 'Não é possível encontrar dados do espaço({spaceName}) que podem ser importados',
|
|
69
|
+
noLauncherDid: 'Launcher NÃO foi encontrado nas informações do Launcher do servidor',
|
|
70
|
+
noNftDid: 'NFT DID não encontrado nas informações do iniciador do servidor',
|
|
69
71
|
};
|
package/locales/ru.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'Приложение находится в процессе, пожалуйста, подождите, пока оно закончится.',
|
|
67
67
|
requestDidSpace: 'Пожалуйста, авторизуйте DID Space для продолжения',
|
|
68
68
|
cannotImportFromDidSpace: 'Не удалось найти данные в пространстве({spaceName}), которые можно импортировать',
|
|
69
|
+
noLauncherDid: 'Laucnher не был найден в информации о запуске сервера',
|
|
70
|
+
noNftDid: 'NFT не найден в информации о запускающем сервере',
|
|
69
71
|
};
|
package/locales/th.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'แอปพลิเคชันกำลังดำเนินการ โปรดรอให้เสร็จสิ้น',
|
|
67
67
|
requestDidSpace: 'โปรดอนุญาตให้ DID Space ดำเนินการต่อ',
|
|
68
68
|
cannotImportFromDidSpace: 'ไม่สามารถค้นหาข้อมูลจากพื้นที่({spaceName}) ที่สามารถนำเข้า',
|
|
69
|
+
noLauncherDid: 'Launcher หาไม่พบจากข้อมูล launcher ของ server',
|
|
70
|
+
noNftDid: 'ไม่พบ NFT DID จากข้อมูลตัวเปิดใช้เซิร์ฟเวอร์',
|
|
69
71
|
};
|
package/locales/vi.js
CHANGED
|
@@ -66,4 +66,6 @@ module.exports = {
|
|
|
66
66
|
appIsInProgress: 'Ứng dụng đang tiến hành, vui lòng đợi cho đến khi nó hoàn thành',
|
|
67
67
|
requestDidSpace: 'Vui lòng cho phép DID Space tiếp tục',
|
|
68
68
|
cannotImportFromDidSpace: 'Không tìm thấy dữ liệu từ khoảng không({spaceName}) có thể nhập',
|
|
69
|
+
noLauncherDid: 'Launcher KHÔNG tìm thấy từ thông tin launcher của máy chủ',
|
|
70
|
+
noNftDid: 'NFT DID không tìm thấy từ thông tin trình khởi chạy máy chủ',
|
|
69
71
|
};
|
package/locales/zh-tw.js
CHANGED
package/locales/zh.js
CHANGED
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.16.25-beta-
|
|
6
|
+
"version": "1.16.25-beta-bc165d9b",
|
|
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": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@abtnode/constant": "1.16.25-beta-
|
|
24
|
-
"@abtnode/logger": "1.16.25-beta-
|
|
25
|
-
"@abtnode/util": "1.16.25-beta-
|
|
23
|
+
"@abtnode/constant": "1.16.25-beta-bc165d9b",
|
|
24
|
+
"@abtnode/logger": "1.16.25-beta-bc165d9b",
|
|
25
|
+
"@abtnode/util": "1.16.25-beta-bc165d9b",
|
|
26
26
|
"@arcblock/did": "1.18.113",
|
|
27
27
|
"@arcblock/jwt": "^1.18.113",
|
|
28
|
-
"@arcblock/nft-display": "^2.9.
|
|
28
|
+
"@arcblock/nft-display": "^2.9.63",
|
|
29
29
|
"@arcblock/validator": "^1.18.113",
|
|
30
30
|
"@arcblock/vc": "1.18.113",
|
|
31
|
-
"@blocklet/constant": "1.16.25-beta-
|
|
32
|
-
"@blocklet/meta": "1.16.25-beta-
|
|
33
|
-
"@blocklet/sdk": "1.16.25-beta-
|
|
31
|
+
"@blocklet/constant": "1.16.25-beta-bc165d9b",
|
|
32
|
+
"@blocklet/meta": "1.16.25-beta-bc165d9b",
|
|
33
|
+
"@blocklet/sdk": "1.16.25-beta-bc165d9b",
|
|
34
34
|
"@ocap/client": "^1.18.113",
|
|
35
35
|
"@ocap/mcrypto": "1.18.113",
|
|
36
36
|
"@ocap/util": "1.18.113",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"jest": "^29.7.0"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "a7895ed39e47c8c6bd10d32317804cc1904714ef"
|
|
55
55
|
}
|