@blocklet/meta 1.8.66-beta-7f4224af → 1.8.66-beta-b56e3b54
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/fix.js +1 -1
- package/lib/parse-navigation-from-blocklet.js +29 -25
- package/lib/parse-navigation.js +13 -6
- package/lib/parse.js +7 -5
- package/lib/payment/v2.js +52 -60
- package/lib/schema.js +15 -18
- package/lib/service.js +7 -1
- package/lib/util-meta.js +14 -23
- package/lib/util.js +5 -14
- package/lib/validate.js +5 -2
- package/lib/verify-multi-sig.js +3 -14
- package/package.json +15 -15
package/lib/fix.js
CHANGED
|
@@ -74,13 +74,13 @@ function tryParseItem(item) {
|
|
|
74
74
|
try {
|
|
75
75
|
return JSON.parse(item);
|
|
76
76
|
}
|
|
77
|
-
catch
|
|
77
|
+
catch {
|
|
78
78
|
return item;
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
function normalizeNavigationList(navigationList) {
|
|
82
82
|
return navigationList.map((item) => {
|
|
83
|
-
const tempData =
|
|
83
|
+
const tempData = { ...item };
|
|
84
84
|
if (tempData.role) {
|
|
85
85
|
tempData.role = tryParseItem(tempData.role);
|
|
86
86
|
}
|
|
@@ -209,11 +209,10 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
209
209
|
* @returns
|
|
210
210
|
*/
|
|
211
211
|
function genNavigationListByBlocklet(current, parent = {}) {
|
|
212
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
213
212
|
const targetList = [];
|
|
214
213
|
const { children = [], meta = {} } = current;
|
|
215
|
-
const navigation = (0, cloneDeep_1.default)(
|
|
216
|
-
if (
|
|
214
|
+
const navigation = (0, cloneDeep_1.default)(meta?.navigation || []);
|
|
215
|
+
if (current.meta?.capabilities?.navigation !== false) {
|
|
217
216
|
targetList.push(...navigation);
|
|
218
217
|
}
|
|
219
218
|
const parentName = parent.name || '';
|
|
@@ -226,15 +225,17 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
226
225
|
const mergeName = [parentName, currentName, childName].filter(Boolean).join('.');
|
|
227
226
|
const childNavigation = child.meta.navigation || [];
|
|
228
227
|
const mergeBase = (0, url_join_1.default)(parentBase, currentBase, childBase);
|
|
229
|
-
if (
|
|
228
|
+
if (child.meta?.capabilities?.navigation !== false) {
|
|
230
229
|
components.push({
|
|
231
230
|
did: child.meta.did,
|
|
232
231
|
name: mergeName,
|
|
233
232
|
link: mergeBase,
|
|
234
233
|
title: child.meta.title || '',
|
|
235
|
-
navigation: childNavigation.map((item) => (
|
|
234
|
+
navigation: childNavigation.map((item) => ({
|
|
236
235
|
// 给每个 navigation 赋予一个 setion,用于在 autocomplete 提供依据 section 筛选的基础
|
|
237
|
-
section: DEFAULT_SECTION
|
|
236
|
+
section: DEFAULT_SECTION,
|
|
237
|
+
...item,
|
|
238
|
+
})),
|
|
238
239
|
});
|
|
239
240
|
}
|
|
240
241
|
// 在现有的 navigation 中判断是否存在 children
|
|
@@ -250,7 +251,7 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
250
251
|
if (child.meta.navigation && child.meta.navigation.length > 0) {
|
|
251
252
|
const items = genNavigationListByBlocklet(child, { mountPoint: currentBase, name: currentName });
|
|
252
253
|
if (items.length > 0) {
|
|
253
|
-
matchNavigation.items =
|
|
254
|
+
matchNavigation.items = matchNavigation.items ?? [];
|
|
254
255
|
matchNavigation.items.push(...items);
|
|
255
256
|
}
|
|
256
257
|
}
|
|
@@ -259,7 +260,7 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
259
260
|
}
|
|
260
261
|
}
|
|
261
262
|
}
|
|
262
|
-
else if (
|
|
263
|
+
else if (child.meta?.capabilities?.navigation !== false) {
|
|
263
264
|
const childItems = genNavigationListByBlocklet(child, { mountPoint: currentBase, name: currentName });
|
|
264
265
|
// 否则动态注入一个 navigation
|
|
265
266
|
const tmpData = {
|
|
@@ -289,7 +290,6 @@ function parseBlockletNavigationList(blocklet = {}) {
|
|
|
289
290
|
function patchBuiltinNavigation(navigation) {
|
|
290
291
|
const copyNavigation = (0, cloneDeep_1.default)(navigation).filter((item) => item.id);
|
|
291
292
|
deepWalk(copyNavigation, (item, parent) => {
|
|
292
|
-
var _a;
|
|
293
293
|
if (item.items && item.items.length) {
|
|
294
294
|
for (let i = item.items.length - 1; i >= 0; i--) {
|
|
295
295
|
if (!item.items[i].id) {
|
|
@@ -309,7 +309,7 @@ function patchBuiltinNavigation(navigation) {
|
|
|
309
309
|
item.id = [parent.id, item.id].join(ID_SEPARATE);
|
|
310
310
|
}
|
|
311
311
|
item.from = item.from || 'yaml';
|
|
312
|
-
item.visible =
|
|
312
|
+
item.visible = item.visible ?? true;
|
|
313
313
|
}, { key: 'items' });
|
|
314
314
|
return copyNavigation;
|
|
315
315
|
}
|
|
@@ -324,7 +324,6 @@ function compactNavigation(navigation, depth = 2) {
|
|
|
324
324
|
const resData = flatternNavigation(copyNavigation, {
|
|
325
325
|
depth,
|
|
326
326
|
transform: (item, parent) => {
|
|
327
|
-
var _a;
|
|
328
327
|
if (parent) {
|
|
329
328
|
if (!item._parent) {
|
|
330
329
|
item._parent = parent.id;
|
|
@@ -333,7 +332,7 @@ function compactNavigation(navigation, depth = 2) {
|
|
|
333
332
|
}
|
|
334
333
|
}
|
|
335
334
|
item.section = item.section || parent.section || [DEFAULT_SECTION];
|
|
336
|
-
item.visible =
|
|
335
|
+
item.visible = item.visible ?? parent.visible;
|
|
337
336
|
}
|
|
338
337
|
item.component = [parent.component, item.component].filter(Boolean).join('.');
|
|
339
338
|
return item;
|
|
@@ -374,7 +373,7 @@ function getNavigationListBySection(navigationItem, section) {
|
|
|
374
373
|
}
|
|
375
374
|
return false;
|
|
376
375
|
})
|
|
377
|
-
.map((item) => (
|
|
376
|
+
.map((item) => ({ ...item, section }));
|
|
378
377
|
}
|
|
379
378
|
return [];
|
|
380
379
|
}
|
|
@@ -392,7 +391,11 @@ function splitNavigationBySection(navigation) {
|
|
|
392
391
|
// eslint-disable-next-line no-inner-declarations
|
|
393
392
|
function patchNavigationItem(item, section) {
|
|
394
393
|
const sectionNavigationList = getNavigationListBySection(item, section);
|
|
395
|
-
itemNavigationList.push(
|
|
394
|
+
itemNavigationList.push({
|
|
395
|
+
...baseNavigation,
|
|
396
|
+
section,
|
|
397
|
+
items: sectionNavigationList,
|
|
398
|
+
});
|
|
396
399
|
}
|
|
397
400
|
if (Array.isArray(navigationItem.section)) {
|
|
398
401
|
for (const section of navigationItem.section) {
|
|
@@ -415,7 +418,10 @@ function splitNavigationBySection(navigation) {
|
|
|
415
418
|
}
|
|
416
419
|
}
|
|
417
420
|
else {
|
|
418
|
-
itemNavigationList.push(
|
|
421
|
+
itemNavigationList.push({
|
|
422
|
+
...navigationItem,
|
|
423
|
+
section: DEFAULT_SECTION,
|
|
424
|
+
});
|
|
419
425
|
}
|
|
420
426
|
allNavigationList.push(...itemNavigationList);
|
|
421
427
|
}
|
|
@@ -453,7 +459,7 @@ exports.nestNavigationList = nestNavigationList;
|
|
|
453
459
|
function filterNavigation(navigationList, components = []) {
|
|
454
460
|
const nestedNavigation = nestNavigationList(navigationList);
|
|
455
461
|
deepWalk(nestedNavigation, (item) => {
|
|
456
|
-
if (item
|
|
462
|
+
if (item?.component) {
|
|
457
463
|
if (!components.some((x) => x.name === item.component)) {
|
|
458
464
|
item.visible = false;
|
|
459
465
|
}
|
|
@@ -467,14 +473,13 @@ function filterNavigation(navigationList, components = []) {
|
|
|
467
473
|
}
|
|
468
474
|
}, { key: 'items' });
|
|
469
475
|
const filteredNavigation = nestedNavigation.filter((item) => {
|
|
470
|
-
var _a;
|
|
471
476
|
if (item.visible === false)
|
|
472
477
|
return false;
|
|
473
478
|
// 如果某一菜单的 子菜单 均为隐藏状态,则一级菜单本身也不显示出来
|
|
474
479
|
if (item.items &&
|
|
475
480
|
Array.isArray(item.items) &&
|
|
476
481
|
item.items.length > 0 &&
|
|
477
|
-
|
|
482
|
+
item.items?.every((v) => v.visible === false))
|
|
478
483
|
return false;
|
|
479
484
|
return true;
|
|
480
485
|
});
|
|
@@ -494,10 +499,9 @@ function cleanOrphanNavigation(list) {
|
|
|
494
499
|
}
|
|
495
500
|
exports.cleanOrphanNavigation = cleanOrphanNavigation;
|
|
496
501
|
function parseNavigation(blocklet = {}, options = {}) {
|
|
497
|
-
var _a;
|
|
498
502
|
const { beforeProcess = (v) => v } = options;
|
|
499
503
|
const { navigationList: builtinNavigation, components } = parseBlockletNavigationList(blocklet);
|
|
500
|
-
const customNavigationList =
|
|
504
|
+
const customNavigationList = blocklet?.settings?.navigations || [];
|
|
501
505
|
const compactedNavigation = compactNavigation(beforeProcess(builtinNavigation));
|
|
502
506
|
const patchedNavigation = patchBuiltinNavigation(compactedNavigation);
|
|
503
507
|
const splitNavigation = splitNavigationBySection(patchedNavigation);
|
|
@@ -509,7 +513,7 @@ function parseNavigation(blocklet = {}, options = {}) {
|
|
|
509
513
|
const { section } = cur;
|
|
510
514
|
const link = smartJoinLink(cur.link, x.link);
|
|
511
515
|
const component = [cur.component, x.component].filter(Boolean).join('.');
|
|
512
|
-
return
|
|
516
|
+
return { ...x, section, link, component, parent: '' };
|
|
513
517
|
}));
|
|
514
518
|
return all;
|
|
515
519
|
}
|
|
@@ -520,10 +524,10 @@ function parseNavigation(blocklet = {}, options = {}) {
|
|
|
520
524
|
const flatNavigation = flatternNavigation(levelUpNavigation, {
|
|
521
525
|
transform(item, parent) {
|
|
522
526
|
let { component } = item;
|
|
523
|
-
if (parent
|
|
527
|
+
if (parent?.component) {
|
|
524
528
|
component = [parent.component, item.component].filter(Boolean).join('.');
|
|
525
529
|
}
|
|
526
|
-
return
|
|
530
|
+
return { ...item, component };
|
|
527
531
|
},
|
|
528
532
|
});
|
|
529
533
|
const rawNavigation = (0, unionWith_1.default)(normalizeNavigationList(customNavigationList), flatNavigation, (prev, next) => {
|
package/lib/parse-navigation.js
CHANGED
|
@@ -24,7 +24,9 @@ const getGroups = (navigation) => {
|
|
|
24
24
|
if (!groups[sec]) {
|
|
25
25
|
groups[sec] = [];
|
|
26
26
|
}
|
|
27
|
-
const item =
|
|
27
|
+
const item = {
|
|
28
|
+
...nav,
|
|
29
|
+
};
|
|
28
30
|
if (nav.section) {
|
|
29
31
|
item.section = sec === '__undefined__' ? [] : [sec];
|
|
30
32
|
}
|
|
@@ -37,9 +39,8 @@ const getChildName = (nav) => nav.component || nav.child;
|
|
|
37
39
|
const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
38
40
|
const result = [];
|
|
39
41
|
(navigation || []).forEach((nav) => {
|
|
40
|
-
var _a, _b;
|
|
41
42
|
if (!getChildName(nav)) {
|
|
42
|
-
if (_level > 1 &&
|
|
43
|
+
if (_level > 1 && nav.items?.length) {
|
|
43
44
|
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
44
45
|
result.push(...list);
|
|
45
46
|
return;
|
|
@@ -63,7 +64,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
63
64
|
if (nav.role) {
|
|
64
65
|
item.role = nav.role;
|
|
65
66
|
}
|
|
66
|
-
if (
|
|
67
|
+
if (nav.items?.length) {
|
|
67
68
|
const list = doParseNavigation(nav.items, blocklet, prefix, _level + 1);
|
|
68
69
|
if (list.length) {
|
|
69
70
|
item.items = list;
|
|
@@ -124,7 +125,10 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
124
125
|
if (list.length > 1) {
|
|
125
126
|
// more than 1 child nav
|
|
126
127
|
delete item.link;
|
|
127
|
-
result.push(
|
|
128
|
+
result.push({
|
|
129
|
+
...item,
|
|
130
|
+
items: list,
|
|
131
|
+
});
|
|
128
132
|
}
|
|
129
133
|
else {
|
|
130
134
|
// only 1 child nav
|
|
@@ -143,7 +147,10 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
|
|
|
143
147
|
item.section = item.section || groupSection;
|
|
144
148
|
}
|
|
145
149
|
item.items = list;
|
|
146
|
-
result.push(
|
|
150
|
+
result.push({
|
|
151
|
+
...item,
|
|
152
|
+
items: list,
|
|
153
|
+
});
|
|
147
154
|
}
|
|
148
155
|
else {
|
|
149
156
|
// secondary menu
|
package/lib/parse.js
CHANGED
|
@@ -22,7 +22,6 @@ const { BLOCKLET_META_FILE, BLOCKLET_META_FILE_ALT } = constants_1.default;
|
|
|
22
22
|
* @param {boolean} options.ensureFiles should we verify that logo and files exists
|
|
23
23
|
*/
|
|
24
24
|
const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, extraRawAttrs = {}, schemaOptions = {}, defaultStoreUrl, fix = true, } = {}) => {
|
|
25
|
-
var _a;
|
|
26
25
|
let result;
|
|
27
26
|
const blockletMetaFile = path_1.default.join(dir, BLOCKLET_META_FILE);
|
|
28
27
|
const blockletMetaFileAlt = path_1.default.join(dir, BLOCKLET_META_FILE_ALT);
|
|
@@ -64,7 +63,7 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
64
63
|
(0, fix_1.fixName)(result);
|
|
65
64
|
(0, fix_1.fixPerson)(result);
|
|
66
65
|
(0, fix_1.fixService)(result);
|
|
67
|
-
if (defaultStoreUrl &&
|
|
66
|
+
if (defaultStoreUrl && result.components?.length) {
|
|
68
67
|
result.components.forEach((x) => {
|
|
69
68
|
if ('name' in x.source) {
|
|
70
69
|
if (!x.source.store) {
|
|
@@ -82,10 +81,13 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
82
81
|
}, {});
|
|
83
82
|
debug('fix', result);
|
|
84
83
|
// Validate and cleanup
|
|
85
|
-
const schema = (0, schema_1.createBlockletSchema)(dir,
|
|
84
|
+
const schema = (0, schema_1.createBlockletSchema)(dir, {
|
|
85
|
+
ensureMain,
|
|
86
86
|
ensureFiles,
|
|
87
87
|
ensureDist,
|
|
88
|
-
ensureComponentStore
|
|
88
|
+
ensureComponentStore,
|
|
89
|
+
...schemaOptions,
|
|
90
|
+
});
|
|
89
91
|
const { value, error } = schema.validate(result);
|
|
90
92
|
if (error) {
|
|
91
93
|
throw new Error(`Invalid blocklet.yml: ${error.details
|
|
@@ -96,7 +98,7 @@ const parse = (dir, { ensureMain = false, ensureFiles = false, ensureDist = fals
|
|
|
96
98
|
return `${x.message}: ${x.context.value.id}`;
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
|
-
catch
|
|
101
|
+
catch {
|
|
100
102
|
//
|
|
101
103
|
}
|
|
102
104
|
return x.message;
|
package/lib/payment/v2.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
27
|
};
|
|
@@ -68,11 +59,11 @@ const safeMul = (a, b) => Number((0, util_1.fromUnitToToken)((0, util_1.fromToke
|
|
|
68
59
|
.mul(new util_1.BN(b * defaultDecimals))
|
|
69
60
|
.div(defaultDecimalsBN)));
|
|
70
61
|
const md5 = (str) => crypto_1.default.createHash('md5').update(str).digest('hex');
|
|
71
|
-
const getStoreInfo = (url) =>
|
|
62
|
+
const getStoreInfo = async (url) => {
|
|
72
63
|
const storeMetaUrl = (0, url_join_1.default)(new URL(url).origin, BLOCKLET_STORE_META_PATH);
|
|
73
|
-
const { data: info } =
|
|
64
|
+
const { data: info } = await axios_1.default.get(storeMetaUrl, { timeout: 8000 });
|
|
74
65
|
return info;
|
|
75
|
-
}
|
|
66
|
+
};
|
|
76
67
|
/**
|
|
77
68
|
* @typedef {{
|
|
78
69
|
* meta: Object
|
|
@@ -91,7 +82,7 @@ const getStoreInfo = (url) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
91
82
|
*
|
|
92
83
|
* @returns {Array<Component>}
|
|
93
84
|
*/
|
|
94
|
-
const innerGetComponents = (inputMeta, context = {}) =>
|
|
85
|
+
const innerGetComponents = async (inputMeta, context = {}) => {
|
|
95
86
|
// FIXME 是否需要验证: 在同一个链上; 重复的 component
|
|
96
87
|
const { ancestors = [], bundles = {} } = context;
|
|
97
88
|
// check ancestor length
|
|
@@ -109,7 +100,7 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
109
100
|
let meta;
|
|
110
101
|
let url;
|
|
111
102
|
try {
|
|
112
|
-
const res =
|
|
103
|
+
const res = await (0, util_meta_1.getBlockletMetaFromUrls)(urls, {
|
|
113
104
|
returnUrl: true,
|
|
114
105
|
validateFn: (m) => (0, validate_1.validateMeta)(m),
|
|
115
106
|
ensureTarball: false,
|
|
@@ -125,7 +116,7 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
125
116
|
throw new Error(`The blocklet cannot be a component: ${meta.title}`);
|
|
126
117
|
}
|
|
127
118
|
// check circular dependencies
|
|
128
|
-
if (ancestors.map((x) =>
|
|
119
|
+
if (ancestors.map((x) => x.meta?.did).indexOf(meta.did) > -1) {
|
|
129
120
|
throw new Error('Blocklet components have circular dependencies');
|
|
130
121
|
}
|
|
131
122
|
// generate child
|
|
@@ -134,7 +125,7 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
134
125
|
};
|
|
135
126
|
// child store info
|
|
136
127
|
if (config.source.store) {
|
|
137
|
-
const storeInfo =
|
|
128
|
+
const storeInfo = await getStoreInfo(url);
|
|
138
129
|
// check uniq bundle did in different stores
|
|
139
130
|
if (!bundles[child.meta.did]) {
|
|
140
131
|
bundles[child.meta.did] = storeInfo.id;
|
|
@@ -146,14 +137,14 @@ const innerGetComponents = (inputMeta, context = {}) => __awaiter(void 0, void 0
|
|
|
146
137
|
child.storeUrl = new URL(url).origin;
|
|
147
138
|
}
|
|
148
139
|
// child children
|
|
149
|
-
child.children =
|
|
140
|
+
child.children = await innerGetComponents(meta, {
|
|
150
141
|
ancestors: [...ancestors, { meta }],
|
|
151
142
|
bundles,
|
|
152
143
|
});
|
|
153
144
|
children.push(child);
|
|
154
145
|
}
|
|
155
146
|
return children;
|
|
156
|
-
}
|
|
147
|
+
};
|
|
157
148
|
/**
|
|
158
149
|
* @param {Array<Component>} components
|
|
159
150
|
* @param {Array<Store>} _stores
|
|
@@ -181,26 +172,25 @@ const getStores = (components, _stores = []) => {
|
|
|
181
172
|
}
|
|
182
173
|
return _stores;
|
|
183
174
|
};
|
|
184
|
-
const getComponents = (inputMeta) =>
|
|
185
|
-
const components =
|
|
186
|
-
const stores =
|
|
175
|
+
const getComponents = async (inputMeta) => {
|
|
176
|
+
const components = await innerGetComponents(inputMeta);
|
|
177
|
+
const stores = await getStores(components);
|
|
187
178
|
return { components, stores };
|
|
188
|
-
}
|
|
189
|
-
const getPriceTokens = (meta, ocapClient) =>
|
|
179
|
+
};
|
|
180
|
+
const getPriceTokens = async (meta, ocapClient) => {
|
|
190
181
|
const priceTokens = (0, cloneDeep_1.default)((0, get_1.default)(meta, 'payment.price', []));
|
|
191
182
|
for (const token of priceTokens) {
|
|
192
183
|
// eslint-disable-next-line no-await-in-loop
|
|
193
|
-
const { state } =
|
|
184
|
+
const { state } = await ocapClient.getTokenState({ address: token.address });
|
|
194
185
|
if (!state) {
|
|
195
186
|
throw new Error(`Token specified in blocklet meta was not found on chain: ${token.address}`);
|
|
196
187
|
}
|
|
197
188
|
token.decimal = state.decimal;
|
|
198
189
|
}
|
|
199
190
|
return priceTokens;
|
|
200
|
-
}
|
|
191
|
+
};
|
|
201
192
|
const getChildShare = (childMeta, parentPrice) => {
|
|
202
|
-
|
|
203
|
-
if (!((_a = childMeta === null || childMeta === void 0 ? void 0 : childMeta.payment) === null || _a === void 0 ? void 0 : _a.componentPrice)) {
|
|
193
|
+
if (!childMeta?.payment?.componentPrice) {
|
|
204
194
|
return 0;
|
|
205
195
|
}
|
|
206
196
|
const priceList = childMeta.payment.componentPrice;
|
|
@@ -246,7 +236,7 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [], }) => {
|
|
|
246
236
|
const childShare = getChildShare(child.meta, price);
|
|
247
237
|
parentShareBN = parentShareBN.sub((0, util_1.fromTokenToUnit)(childShare, priceToken.decimal));
|
|
248
238
|
const componentContracts = getTokenTransfers({
|
|
249
|
-
priceToken:
|
|
239
|
+
priceToken: { ...priceToken, value: childShare },
|
|
250
240
|
shares: child.meta.payment.share,
|
|
251
241
|
components: child.children || [],
|
|
252
242
|
});
|
|
@@ -277,19 +267,22 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [], }) => {
|
|
|
277
267
|
});
|
|
278
268
|
return mergedContracts;
|
|
279
269
|
};
|
|
280
|
-
const getContract = ({ meta, priceTokens, components, }) =>
|
|
270
|
+
const getContract = async ({ meta, priceTokens, components, }) => {
|
|
281
271
|
const shares = meta.payment.share || [];
|
|
282
272
|
const [priceToken] = priceTokens;
|
|
283
273
|
const contracts = getTokenTransfers({ priceToken, shares, components });
|
|
284
274
|
const code = contracts
|
|
285
275
|
.map((x) => `transferToken('${x.tokenAddress}','${x.accountAddress}','${x.amount.toString()}')`)
|
|
286
276
|
.join(';\n');
|
|
287
|
-
const shareList = contracts.map((x) => (
|
|
277
|
+
const shareList = contracts.map((x) => ({
|
|
278
|
+
...x,
|
|
279
|
+
amount: (0, util_1.fromUnitToToken)(x.amount, priceToken.decimal),
|
|
280
|
+
}));
|
|
288
281
|
return {
|
|
289
282
|
code,
|
|
290
283
|
shares: shareList,
|
|
291
284
|
};
|
|
292
|
-
}
|
|
285
|
+
};
|
|
293
286
|
/**
|
|
294
287
|
* we need to ensure that blocklet purchase factory does not change across changes
|
|
295
288
|
*
|
|
@@ -373,17 +366,17 @@ const getFactoryInput = (inputTokens, { formatToken = true } = {}) => {
|
|
|
373
366
|
variables: [],
|
|
374
367
|
};
|
|
375
368
|
};
|
|
376
|
-
const getPaymentIntegrity = ({ contract, factoryInput, storeComponents, meta, client, storeId, }) =>
|
|
369
|
+
const getPaymentIntegrity = async ({ contract, factoryInput, storeComponents, meta, client, storeId, }) => {
|
|
377
370
|
if (!contract && !factoryInput && !storeComponents) {
|
|
378
|
-
const priceTokens =
|
|
379
|
-
const { components, stores } =
|
|
371
|
+
const priceTokens = await getPriceTokens(meta, client);
|
|
372
|
+
const { components, stores } = await getComponents(meta);
|
|
380
373
|
const store = stores.find((x) => x.id === storeId);
|
|
381
374
|
// eslint-disable-next-line no-param-reassign
|
|
382
|
-
contract = (
|
|
375
|
+
contract = (await getContract({ meta, components, priceTokens })).code;
|
|
383
376
|
// eslint-disable-next-line no-param-reassign
|
|
384
|
-
factoryInput =
|
|
377
|
+
factoryInput = await getFactoryInput(priceTokens);
|
|
385
378
|
// eslint-disable-next-line no-param-reassign
|
|
386
|
-
storeComponents =
|
|
379
|
+
storeComponents = store?.components || [];
|
|
387
380
|
}
|
|
388
381
|
const paymentData = {
|
|
389
382
|
factoryInput,
|
|
@@ -392,19 +385,19 @@ const getPaymentIntegrity = ({ contract, factoryInput, storeComponents, meta, cl
|
|
|
392
385
|
};
|
|
393
386
|
const integrity = md5((0, json_stable_stringify_1.default)(paymentData));
|
|
394
387
|
return integrity;
|
|
395
|
-
}
|
|
396
|
-
const getStoreSignatures = ({ meta, stores, factoryInput, contract, }) =>
|
|
388
|
+
};
|
|
389
|
+
const getStoreSignatures = async ({ meta, stores, factoryInput, contract, }) => {
|
|
397
390
|
const storeSignatures = [];
|
|
398
391
|
for (const store of stores) {
|
|
399
392
|
const { id, url, pk, components: storeComponents } = store;
|
|
400
|
-
const paymentIntegrity =
|
|
393
|
+
const paymentIntegrity = await getPaymentIntegrity({ factoryInput, contract, storeComponents });
|
|
401
394
|
/**
|
|
402
395
|
* protocol: /api/payment/signature
|
|
403
396
|
* method: POST
|
|
404
397
|
* body: { blockletMeta, paymentIntegrity, paymentVersion }
|
|
405
398
|
* return: { signer, pk, signature}
|
|
406
399
|
*/
|
|
407
|
-
const { data: res } =
|
|
400
|
+
const { data: res } = await axios_1.default.post(`${url}/api/payment/signature`, {
|
|
408
401
|
blockletMeta: meta,
|
|
409
402
|
paymentIntegrity,
|
|
410
403
|
paymentVersion: VERSION,
|
|
@@ -434,7 +427,7 @@ const getStoreSignatures = ({ meta, stores, factoryInput, contract, }) => __awai
|
|
|
434
427
|
return {
|
|
435
428
|
storeSignatures,
|
|
436
429
|
};
|
|
437
|
-
}
|
|
430
|
+
};
|
|
438
431
|
/**
|
|
439
432
|
* Used by CLI and Store to independent compute factory itx
|
|
440
433
|
*
|
|
@@ -455,16 +448,16 @@ const getStoreSignatures = ({ meta, stores, factoryInput, contract, }) => __awai
|
|
|
455
448
|
* }>
|
|
456
449
|
* }}
|
|
457
450
|
*/
|
|
458
|
-
const createNftFactoryItx = ({ blockletMeta, ocapClient, issuers, storeUrl, }) =>
|
|
459
|
-
const priceTokens =
|
|
460
|
-
const { components, stores } =
|
|
451
|
+
const createNftFactoryItx = async ({ blockletMeta, ocapClient, issuers, storeUrl, }) => {
|
|
452
|
+
const priceTokens = await getPriceTokens(blockletMeta, ocapClient);
|
|
453
|
+
const { components, stores } = await getComponents(blockletMeta);
|
|
461
454
|
const factoryInput = getFactoryInput(priceTokens);
|
|
462
|
-
const { code: contract, shares } =
|
|
455
|
+
const { code: contract, shares } = await getContract({
|
|
463
456
|
meta: blockletMeta,
|
|
464
457
|
priceTokens,
|
|
465
458
|
components,
|
|
466
459
|
});
|
|
467
|
-
const { storeSignatures } =
|
|
460
|
+
const { storeSignatures } = await getStoreSignatures({
|
|
468
461
|
meta: blockletMeta,
|
|
469
462
|
stores,
|
|
470
463
|
factoryInput,
|
|
@@ -482,7 +475,7 @@ const createNftFactoryItx = ({ blockletMeta, ocapClient, issuers, storeUrl, }) =
|
|
|
482
475
|
stores: storeSignatures.map((x) => ({ id: x.signer, url: x.storeUrl })),
|
|
483
476
|
shares,
|
|
484
477
|
};
|
|
485
|
-
}
|
|
478
|
+
};
|
|
486
479
|
exports.createNftFactoryItx = createNftFactoryItx;
|
|
487
480
|
/**
|
|
488
481
|
* Used by Store before generating payment signature
|
|
@@ -495,13 +488,13 @@ exports.createNftFactoryItx = createNftFactoryItx;
|
|
|
495
488
|
* }}
|
|
496
489
|
* @returns {string} integrity
|
|
497
490
|
*/
|
|
498
|
-
const verifyPaymentIntegrity = ({ integrity: expected, blockletMeta, ocapClient, storeId, }) =>
|
|
499
|
-
const actual =
|
|
491
|
+
const verifyPaymentIntegrity = async ({ integrity: expected, blockletMeta, ocapClient, storeId, }) => {
|
|
492
|
+
const actual = await getPaymentIntegrity({ meta: blockletMeta, client: ocapClient, storeId });
|
|
500
493
|
if (actual !== expected) {
|
|
501
494
|
throw new Error('verify payment integrity failed');
|
|
502
495
|
}
|
|
503
496
|
return expected;
|
|
504
|
-
}
|
|
497
|
+
};
|
|
505
498
|
exports.verifyPaymentIntegrity = verifyPaymentIntegrity;
|
|
506
499
|
/**
|
|
507
500
|
* Used by Store before generating downloadToken
|
|
@@ -515,10 +508,9 @@ exports.verifyPaymentIntegrity = verifyPaymentIntegrity;
|
|
|
515
508
|
* components: Array<{did: string, version: string}>
|
|
516
509
|
* }}
|
|
517
510
|
*/
|
|
518
|
-
const verifyNftFactory = ({ factoryState, signerWallet, }) =>
|
|
519
|
-
|
|
520
|
-
const
|
|
521
|
-
const stores = (data === null || data === void 0 ? void 0 : data.stores) || [];
|
|
511
|
+
const verifyNftFactory = async ({ factoryState, signerWallet, }) => {
|
|
512
|
+
const data = JSON.parse(factoryState?.data?.value);
|
|
513
|
+
const stores = data?.stores || [];
|
|
522
514
|
const store = stores.find((x) => x.signer === signerWallet.address);
|
|
523
515
|
if (!store) {
|
|
524
516
|
throw new Error(`Signer does not found in factory. factory: ${factoryState.address}, signer: ${signerWallet.address}`);
|
|
@@ -527,7 +519,7 @@ const verifyNftFactory = ({ factoryState, signerWallet, }) => __awaiter(void 0,
|
|
|
527
519
|
const { components } = store;
|
|
528
520
|
// Token 的字段和 factory 中的字段不一致
|
|
529
521
|
const factoryInput = getFactoryInput(factoryState.input.tokens.map((x) => (0, pick_1.default)(x, ['address', 'value'])), { formatToken: false });
|
|
530
|
-
const integrity =
|
|
522
|
+
const integrity = await getPaymentIntegrity({
|
|
531
523
|
contract: c.hook,
|
|
532
524
|
factoryInput,
|
|
533
525
|
storeComponents: components,
|
|
@@ -537,7 +529,7 @@ const verifyNftFactory = ({ factoryState, signerWallet, }) => __awaiter(void 0,
|
|
|
537
529
|
throw new Error(`verify nft factory failed: ${factoryState.address}`);
|
|
538
530
|
}
|
|
539
531
|
return { components };
|
|
540
|
-
}
|
|
532
|
+
};
|
|
541
533
|
exports.verifyNftFactory = verifyNftFactory;
|
|
542
534
|
/**
|
|
543
535
|
* Check blocklet and all of components are free
|
|
@@ -545,11 +537,11 @@ exports.verifyNftFactory = verifyNftFactory;
|
|
|
545
537
|
*
|
|
546
538
|
* @param {TBlockletMeta} meta
|
|
547
539
|
*/
|
|
548
|
-
const checkFreeBlocklet = (blockletMeta) =>
|
|
540
|
+
const checkFreeBlocklet = async (blockletMeta) => {
|
|
549
541
|
if (!(0, util_2.isFreeBlocklet)(blockletMeta)) {
|
|
550
542
|
return Promise.reject(new Error('blocklet is not free'));
|
|
551
543
|
}
|
|
552
|
-
const { components } =
|
|
544
|
+
const { components } = await getComponents(blockletMeta);
|
|
553
545
|
const shouldAllComponentFree = (arr) => {
|
|
554
546
|
arr.forEach(({ meta, children }) => {
|
|
555
547
|
if (!(0, util_2.isFreeBlocklet)(meta) || !(0, util_2.isFreeComponent)(meta)) {
|
|
@@ -561,7 +553,7 @@ const checkFreeBlocklet = (blockletMeta) => __awaiter(void 0, void 0, void 0, fu
|
|
|
561
553
|
};
|
|
562
554
|
shouldAllComponentFree(components);
|
|
563
555
|
return true;
|
|
564
|
-
}
|
|
556
|
+
};
|
|
565
557
|
exports.checkFreeBlocklet = checkFreeBlocklet;
|
|
566
558
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
567
559
|
exports._test = {
|
package/lib/schema.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -375,7 +364,10 @@ const navigationItemProps = {
|
|
|
375
364
|
icon: Joi.string().min(1),
|
|
376
365
|
visible: Joi.boolean(),
|
|
377
366
|
};
|
|
378
|
-
const navigationItemSchema = Joi.object(
|
|
367
|
+
const navigationItemSchema = Joi.object({
|
|
368
|
+
...navigationItemProps,
|
|
369
|
+
items: Joi.array().items(Joi.object({ ...navigationItemProps }).rename('child', 'component')),
|
|
370
|
+
})
|
|
379
371
|
.rename('child', 'component')
|
|
380
372
|
.meta({
|
|
381
373
|
className: 'TNavigationItem',
|
|
@@ -623,25 +615,30 @@ const blockletMetaSchema = Joi.object(blockletMetaProps).options({ stripUnknown:
|
|
|
623
615
|
unknownType: 'any',
|
|
624
616
|
});
|
|
625
617
|
exports.blockletMetaSchema = blockletMetaSchema;
|
|
626
|
-
const createBlockletSchema = (baseDir,
|
|
627
|
-
var { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true } = _a, schemaOptions = __rest(_a, ["ensureMain", "ensureFiles", "ensureDist", "ensureComponentStore"]);
|
|
618
|
+
const createBlockletSchema = (baseDir, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, ...schemaOptions } = {}) => {
|
|
628
619
|
if (!baseDir || !fs_1.default.existsSync(baseDir)) {
|
|
629
620
|
// eslint-disable-next-line no-param-reassign
|
|
630
621
|
ensureFiles = false;
|
|
631
622
|
}
|
|
632
|
-
return Joi.object(
|
|
623
|
+
return Joi.object({
|
|
624
|
+
...blockletMetaProps,
|
|
625
|
+
main: Joi.when('group', {
|
|
633
626
|
is: Joi.valid(BlockletGroup.gateway),
|
|
634
627
|
then: Joi.forbidden(),
|
|
635
628
|
otherwise: ensureMain ? Joi.file().exists({ baseDir }).required() : Joi.string().trim().required(),
|
|
636
|
-
}),
|
|
629
|
+
}),
|
|
630
|
+
logo: ensureFiles ? Joi.file().trim().exists({ baseDir }).optional() : Joi.string().trim().optional(),
|
|
637
631
|
// Other contents to be included in the bundle
|
|
638
632
|
files: Joi.array()
|
|
639
633
|
.items(ensureFiles
|
|
640
634
|
? // eslint-disable-next-line
|
|
641
635
|
Joi.file().exists({ baseDir, canSkip: (dir, name) => [BLOCKLET_ENTRY_FILE, BLOCKLET_BUNDLE_FILE].includes(name) || (0, is_glob_1.default)(name) }) // prettier-ignore
|
|
642
636
|
: Joi.string().trim())
|
|
643
|
-
.optional(),
|
|
644
|
-
|
|
637
|
+
.optional(),
|
|
638
|
+
dist: ensureDist ? distSchema.required() : distSchema.optional(),
|
|
639
|
+
components: componentsSchema(ensureComponentStore),
|
|
640
|
+
})
|
|
641
|
+
.options({ stripUnknown: true, noDefaults: false, ...schemaOptions })
|
|
645
642
|
.rename('children', 'components')
|
|
646
643
|
.custom((data, helper) => {
|
|
647
644
|
const { did, name } = data;
|
package/lib/service.js
CHANGED
|
@@ -22,7 +22,13 @@ setService({
|
|
|
22
22
|
default: {},
|
|
23
23
|
});
|
|
24
24
|
// backward compatible
|
|
25
|
-
SERVICES[NODE_SERVICES.AUTH_SERVICE] =
|
|
25
|
+
SERVICES[NODE_SERVICES.AUTH_SERVICE] = {
|
|
26
|
+
...SERVICES[NODE_SERVICES.AUTH],
|
|
27
|
+
meta: {
|
|
28
|
+
...SERVICES[NODE_SERVICES.AUTH].meta,
|
|
29
|
+
name: NODE_SERVICES.AUTH_SERVICE,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
26
32
|
const getService = (serviceName) => {
|
|
27
33
|
if (!serviceName) {
|
|
28
34
|
throw new Error('service name should not be empty');
|
package/lib/util-meta.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -22,7 +13,7 @@ const constant_1 = __importDefault(require("@abtnode/constant"));
|
|
|
22
13
|
const did_1 = __importDefault(require("./did"));
|
|
23
14
|
const validate_1 = require("./validate");
|
|
24
15
|
const { BLOCKLET_STORE_API_BLOCKLET_PREFIX } = constant_1.default;
|
|
25
|
-
const validateUrl = (url, expectedHttpResTypes = ['application/json', 'text/plain']) =>
|
|
16
|
+
const validateUrl = async (url, expectedHttpResTypes = ['application/json', 'text/plain']) => {
|
|
26
17
|
const parsed = new URL(url);
|
|
27
18
|
const { protocol } = parsed;
|
|
28
19
|
// file
|
|
@@ -37,7 +28,7 @@ const validateUrl = (url, expectedHttpResTypes = ['application/json', 'text/plai
|
|
|
37
28
|
if (protocol.startsWith('http')) {
|
|
38
29
|
let res;
|
|
39
30
|
try {
|
|
40
|
-
res =
|
|
31
|
+
res = await (0, axios_1.default)({ url, method: 'HEAD', timeout: 1000 * 10 });
|
|
41
32
|
}
|
|
42
33
|
catch (err) {
|
|
43
34
|
throw new Error(`Cannot get content-type from ${url}: ${err.message}`);
|
|
@@ -49,36 +40,36 @@ const validateUrl = (url, expectedHttpResTypes = ['application/json', 'text/plai
|
|
|
49
40
|
return true;
|
|
50
41
|
}
|
|
51
42
|
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
52
|
-
}
|
|
43
|
+
};
|
|
53
44
|
exports.validateUrl = validateUrl;
|
|
54
45
|
const validateBlockletMeta = (meta, opts = {}) => {
|
|
55
46
|
(0, validate_1.fixAndValidateService)(meta);
|
|
56
47
|
return (0, validate_1.validateMeta)(meta, opts);
|
|
57
48
|
};
|
|
58
|
-
const getBlockletMetaByUrl = (url) =>
|
|
49
|
+
const getBlockletMetaByUrl = async (url) => {
|
|
59
50
|
const { protocol } = new URL(url);
|
|
60
51
|
if (protocol.startsWith('file')) {
|
|
61
52
|
const decoded = decodeURIComponent((0, url_1.fileURLToPath)(url));
|
|
62
53
|
if (!fs_1.default.existsSync(decoded)) {
|
|
63
54
|
throw new Error(`File does not exist: ${decoded}`);
|
|
64
55
|
}
|
|
65
|
-
const d =
|
|
56
|
+
const d = await fs_1.default.promises.readFile(decoded);
|
|
66
57
|
// @ts-expect-error TS(2345) FIXME: Argument of type 'Buffer' is not assignable to par... Remove this comment to see the full error message
|
|
67
58
|
const meta = JSON.parse(d);
|
|
68
59
|
return meta;
|
|
69
60
|
}
|
|
70
61
|
if (protocol.startsWith('http')) {
|
|
71
|
-
const { data: meta } =
|
|
62
|
+
const { data: meta } = await (0, axios_1.default)({ url, method: 'GET', timeout: 1000 * 20 });
|
|
72
63
|
if (Object.prototype.toString.call(meta) !== '[object Object]') {
|
|
73
64
|
throw new Error('Url is not valid');
|
|
74
65
|
}
|
|
75
66
|
return meta;
|
|
76
67
|
}
|
|
77
68
|
throw new Error(`Invalid url protocol: ${protocol.replace(/:$/, '')}`);
|
|
78
|
-
}
|
|
69
|
+
};
|
|
79
70
|
exports.getBlockletMetaByUrl = getBlockletMetaByUrl;
|
|
80
|
-
const getBlockletMetaFromUrl = (url, { validateFn = validateBlockletMeta, returnUrl = false, ensureTarball = true, logger, } = {}) =>
|
|
81
|
-
const meta =
|
|
71
|
+
const getBlockletMetaFromUrl = async (url, { validateFn = validateBlockletMeta, returnUrl = false, ensureTarball = true, logger, } = {}) => {
|
|
72
|
+
const meta = await getBlockletMetaByUrl(url);
|
|
82
73
|
delete meta.htmlAst;
|
|
83
74
|
const newMeta = validateFn(meta, { ensureDist: true });
|
|
84
75
|
if (ensureTarball) {
|
|
@@ -86,7 +77,7 @@ const getBlockletMetaFromUrl = (url, { validateFn = validateBlockletMeta, return
|
|
|
86
77
|
const { href } = new URL(newMeta.dist.tarball, url);
|
|
87
78
|
const tarball = decodeURIComponent(href);
|
|
88
79
|
try {
|
|
89
|
-
|
|
80
|
+
await validateUrl(tarball, ['application/octet-stream', 'application/x-gzip']);
|
|
90
81
|
}
|
|
91
82
|
catch (error) {
|
|
92
83
|
if (!error.message.startsWith('Cannot get content-type')) {
|
|
@@ -107,11 +98,11 @@ const getBlockletMetaFromUrl = (url, { validateFn = validateBlockletMeta, return
|
|
|
107
98
|
return { meta: newMeta, url };
|
|
108
99
|
}
|
|
109
100
|
return newMeta;
|
|
110
|
-
}
|
|
101
|
+
};
|
|
111
102
|
exports.getBlockletMetaFromUrl = getBlockletMetaFromUrl;
|
|
112
|
-
const getBlockletMetaFromUrls = (urls, { validateFn, returnUrl = false, ensureTarball = true, logger, } = {}) =>
|
|
103
|
+
const getBlockletMetaFromUrls = async (urls, { validateFn, returnUrl = false, ensureTarball = true, logger, } = {}) => {
|
|
113
104
|
try {
|
|
114
|
-
const res =
|
|
105
|
+
const res = await (0, promise_any_1.default)(urls.map((url) => getBlockletMetaFromUrl(url, { validateFn, returnUrl, ensureTarball, logger })));
|
|
115
106
|
return res;
|
|
116
107
|
}
|
|
117
108
|
catch (err) {
|
|
@@ -124,7 +115,7 @@ const getBlockletMetaFromUrls = (urls, { validateFn, returnUrl = false, ensureTa
|
|
|
124
115
|
}
|
|
125
116
|
throw new Error(message);
|
|
126
117
|
}
|
|
127
|
-
}
|
|
118
|
+
};
|
|
128
119
|
exports.getBlockletMetaFromUrls = getBlockletMetaFromUrls;
|
|
129
120
|
/**
|
|
130
121
|
* @param {*} config defined in componentSchema in blocklet meta schema
|
package/lib/util.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -88,9 +79,9 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5,
|
|
|
88
79
|
// serial
|
|
89
80
|
if (!parallel) {
|
|
90
81
|
// eslint-disable-next-line no-async-promise-executor
|
|
91
|
-
return new Promise((resolve, reject) =>
|
|
82
|
+
return new Promise(async (resolve, reject) => {
|
|
92
83
|
try {
|
|
93
|
-
const params =
|
|
84
|
+
const params = await cb(blocklet, {
|
|
94
85
|
parent: _parent,
|
|
95
86
|
root,
|
|
96
87
|
level: _level,
|
|
@@ -100,7 +91,7 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5,
|
|
|
100
91
|
});
|
|
101
92
|
if (blocklet.children) {
|
|
102
93
|
for (const child of blocklet.children) {
|
|
103
|
-
|
|
94
|
+
await forEachBlocklet(child, cb, {
|
|
104
95
|
params,
|
|
105
96
|
_parent: blocklet,
|
|
106
97
|
_root: root,
|
|
@@ -114,7 +105,7 @@ const forEachBlocklet = (blocklet, cb, { parallel = false, concurrencyLimit = 5,
|
|
|
114
105
|
catch (err) {
|
|
115
106
|
reject(err);
|
|
116
107
|
}
|
|
117
|
-
})
|
|
108
|
+
});
|
|
118
109
|
}
|
|
119
110
|
// parallel
|
|
120
111
|
const limit = _limit || (0, p_limit_1.default)(concurrencyLimit);
|
|
@@ -439,7 +430,7 @@ const getChainInfo = (env) => Object.entries(CHAIN_INFO_CONFIG).reduce((info, x)
|
|
|
439
430
|
return info;
|
|
440
431
|
}, {});
|
|
441
432
|
exports.getChainInfo = getChainInfo;
|
|
442
|
-
const isExternalBlocklet = (blocklet) => !!
|
|
433
|
+
const isExternalBlocklet = (blocklet) => !!blocklet?.controller;
|
|
443
434
|
exports.isExternalBlocklet = isExternalBlocklet;
|
|
444
435
|
const getRolesFromAuthConfig = (config) => {
|
|
445
436
|
if (!config.whoCanAccess.startsWith(WHO_CAN_ACCESS_PREFIX_ROLES)) {
|
package/lib/validate.js
CHANGED
|
@@ -21,10 +21,13 @@ const fixAndValidateService = (meta) => {
|
|
|
21
21
|
};
|
|
22
22
|
exports.fixAndValidateService = fixAndValidateService;
|
|
23
23
|
const validateMeta = (meta, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, schemaOptions = {}, } = {}) => {
|
|
24
|
-
const schema = (0, schema_1.createBlockletSchema)(null,
|
|
24
|
+
const schema = (0, schema_1.createBlockletSchema)(null, {
|
|
25
|
+
ensureMain,
|
|
25
26
|
ensureFiles,
|
|
26
27
|
ensureDist,
|
|
27
|
-
ensureComponentStore
|
|
28
|
+
ensureComponentStore,
|
|
29
|
+
...schemaOptions,
|
|
30
|
+
});
|
|
28
31
|
const { value, error } = schema.validate(meta);
|
|
29
32
|
if (error) {
|
|
30
33
|
throw new Error(`Invalid blocklet meta: ${error.details.map((x) => x.message).join(', ')}`);
|
package/lib/verify-multi-sig.js
CHANGED
|
@@ -1,15 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
-
var t = {};
|
|
4
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
-
t[p] = s[p];
|
|
6
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
-
t[p[i]] = s[p[i]];
|
|
10
|
-
}
|
|
11
|
-
return t;
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
@@ -49,7 +38,7 @@ function verifyDelegationToken(signature) {
|
|
|
49
38
|
return true;
|
|
50
39
|
}
|
|
51
40
|
const verifyMultiSig = (blockletMeta) => {
|
|
52
|
-
const { signatures: tmpSignatures
|
|
41
|
+
const { signatures: tmpSignatures, ...meta } = blockletMeta;
|
|
53
42
|
const signatures = (0, cloneDeep_1.default)(tmpSignatures);
|
|
54
43
|
if (!Array.isArray(signatures)) {
|
|
55
44
|
throw new Error('Invalid signatures, signatures should be an array');
|
|
@@ -74,7 +63,7 @@ const verifyMultiSig = (blockletMeta) => {
|
|
|
74
63
|
: signature;
|
|
75
64
|
delete signature.sig;
|
|
76
65
|
debug('verify', { signer });
|
|
77
|
-
let toBeVerifiedMeta =
|
|
66
|
+
let toBeVerifiedMeta = { ...meta };
|
|
78
67
|
if (lastSignature && lastSignature.appended) {
|
|
79
68
|
debug('appended fields', { signer, appended: lastSignature.appended });
|
|
80
69
|
lastSignature.appended.forEach((field) => {
|
|
@@ -89,7 +78,7 @@ const verifyMultiSig = (blockletMeta) => {
|
|
|
89
78
|
}
|
|
90
79
|
const type = (0, did_1.toTypeInfo)(signer);
|
|
91
80
|
const wallet = (0, wallet_1.fromPublicKey)(pk, type);
|
|
92
|
-
const verifyRes = wallet.verify((0, json_stable_stringify_1.default)(
|
|
81
|
+
const verifyRes = wallet.verify((0, json_stable_stringify_1.default)({ ...toBeVerifiedMeta, signatures: [signature, ...signatures] }), sig);
|
|
93
82
|
if (verifyRes !== true) {
|
|
94
83
|
debug('verify failed', { signer });
|
|
95
84
|
return verifyRes;
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.8.66-beta-
|
|
6
|
+
"version": "1.8.66-beta-b56e3b54",
|
|
7
7
|
"description": "Library to parse/validate/fix blocklet meta",
|
|
8
8
|
"main": "./lib/index.js",
|
|
9
9
|
"typings": "./lib/index.d.ts",
|
|
@@ -24,19 +24,19 @@
|
|
|
24
24
|
"author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@abtnode/client": "1.8.66-beta-
|
|
28
|
-
"@abtnode/constant": "1.8.66-beta-
|
|
29
|
-
"@abtnode/util": "1.8.66-beta-
|
|
30
|
-
"@arcblock/did": "1.18.
|
|
31
|
-
"@arcblock/did-ext": "1.18.
|
|
32
|
-
"@arcblock/did-util": "1.18.
|
|
33
|
-
"@arcblock/jwt": "1.18.
|
|
34
|
-
"@blocklet/constant": "1.8.66-beta-
|
|
35
|
-
"@ocap/asset": "1.18.
|
|
36
|
-
"@ocap/mcrypto": "1.18.
|
|
37
|
-
"@ocap/types": "1.18.
|
|
38
|
-
"@ocap/util": "1.18.
|
|
39
|
-
"@ocap/wallet": "1.18.
|
|
27
|
+
"@abtnode/client": "1.8.66-beta-b56e3b54",
|
|
28
|
+
"@abtnode/constant": "1.8.66-beta-b56e3b54",
|
|
29
|
+
"@abtnode/util": "1.8.66-beta-b56e3b54",
|
|
30
|
+
"@arcblock/did": "1.18.52",
|
|
31
|
+
"@arcblock/did-ext": "1.18.52",
|
|
32
|
+
"@arcblock/did-util": "1.18.52",
|
|
33
|
+
"@arcblock/jwt": "1.18.52",
|
|
34
|
+
"@blocklet/constant": "1.8.66-beta-b56e3b54",
|
|
35
|
+
"@ocap/asset": "1.18.52",
|
|
36
|
+
"@ocap/mcrypto": "1.18.52",
|
|
37
|
+
"@ocap/types": "1.18.52",
|
|
38
|
+
"@ocap/util": "1.18.52",
|
|
39
|
+
"@ocap/wallet": "1.18.52",
|
|
40
40
|
"ajv": "^8.11.0",
|
|
41
41
|
"axios": "^0.27.2",
|
|
42
42
|
"cjk-length": "^1.0.0",
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"ts-node": "^10.9.1",
|
|
81
81
|
"typescript": "^4.8.4"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "4d95b431526128c14cd04c0741cac423afce8f48"
|
|
84
84
|
}
|