@blocklet/meta 1.8.14 → 1.8.17

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/info.js CHANGED
@@ -12,17 +12,20 @@ module.exports = (state, nodeSk, { returnWallet = true } = {}) => {
12
12
 
13
13
  const customDescription = envs.find((x) => x.key === 'BLOCKLET_APP_DESCRIPTION');
14
14
  const customPassportColor = envs.find((x) => x.key === 'BLOCKLET_PASSPORT_COLOR');
15
+ const customAppUrl = envs.find((x) => x.key === 'BLOCKLET_APP_URL');
15
16
 
16
17
  const { did } = state.meta;
17
18
  const name = getDisplayName(state);
18
19
  const description = get(customDescription, 'value', state.meta.description);
19
20
  const passportColor = get(customPassportColor, 'value', 'auto');
21
+ const appUrl = get(customAppUrl, 'value', '');
20
22
 
21
23
  if (!returnWallet) {
22
24
  return {
23
25
  did,
24
26
  name,
25
27
  description,
28
+ appUrl,
26
29
  };
27
30
  }
28
31
 
@@ -54,6 +57,7 @@ module.exports = (state, nodeSk, { returnWallet = true } = {}) => {
54
57
  name,
55
58
  description,
56
59
  passportColor,
60
+ appUrl,
57
61
  wallet,
58
62
  };
59
63
  };
@@ -140,7 +140,7 @@ const doParseNavigation = (navigation, blocklet, prefix = '/', _level = 1) => {
140
140
  }
141
141
 
142
142
  if (childNav.role) {
143
- item.role = item.icon || childNav.role;
143
+ item.role = item.role || childNav.role;
144
144
  }
145
145
 
146
146
  if (childNav.section) {
package/lib/payment/v2.js CHANGED
@@ -140,7 +140,7 @@ const _getComponents = async (inputMeta, context = {}) => {
140
140
  * id: string
141
141
  * pk: string
142
142
  * url: string
143
- * componentDids: Array<string>
143
+ * components: Array<{did: string, version: string}>
144
144
  * }} Store
145
145
  * @param {Array<Component>} components
146
146
  * @param {Array<Store>} _stores
@@ -151,9 +151,14 @@ const _getStores = (components, _stores = []) => {
151
151
  if (storeInfo && (!isFreeBlocklet(meta) || !isFreeComponent(meta))) {
152
152
  const store = _stores.find((x) => x.id === storeInfo.id);
153
153
  if (!store) {
154
- _stores.push({ id: storeInfo.id, pk: storeInfo.pk, url: storeUrl, componentDids: new Set([meta.did]) });
155
- } else {
156
- store.componentDids.add(meta.did);
154
+ _stores.push({
155
+ id: storeInfo.id,
156
+ pk: storeInfo.pk,
157
+ url: storeUrl,
158
+ components: [{ did: meta.did, version: meta.version }],
159
+ });
160
+ } else if (!store.components.some((x) => x.did === meta.did && x.version === meta.version)) {
161
+ store.components.push({ did: meta.did, version: meta.version });
157
162
  }
158
163
  }
159
164
 
@@ -162,7 +167,7 @@ const _getStores = (components, _stores = []) => {
162
167
  }
163
168
  }
164
169
 
165
- return _stores.map((x) => ({ ...x, componentDids: [...x.componentDids] }));
170
+ return _stores;
166
171
  };
167
172
 
168
173
  const getComponents = async (inputMeta) => {
@@ -260,9 +265,10 @@ const getTokenTransfers = ({ priceToken, shares = [], components = [] }) => {
260
265
  }
261
266
  }
262
267
 
263
- shares.forEach(({ address: accountAddress, value: ratio }) => {
268
+ shares.forEach(({ name, address: accountAddress, value: ratio }) => {
264
269
  contracts.push({
265
270
  tokenAddress: priceToken.address,
271
+ accountName: name,
266
272
  accountAddress,
267
273
  amount: parentShareBN.mul(new BN(ratio * defaultDecimals)).div(defaultDecimalsBN),
268
274
  });
@@ -291,9 +297,19 @@ const getContract = async ({ meta, priceTokens, components }) => {
291
297
 
292
298
  const contracts = getTokenTransfers({ priceToken, shares, components });
293
299
 
294
- return contracts
300
+ const code = contracts
295
301
  .map((x) => `transferToken('${x.tokenAddress}','${x.accountAddress}','${x.amount.toString()}')`)
296
302
  .join(';\n');
303
+
304
+ const shareList = contracts.map((x) => ({
305
+ ...x,
306
+ amount: fromUnitToToken(x.amount, priceToken.decimal),
307
+ }));
308
+
309
+ return {
310
+ code,
311
+ shares: shareList,
312
+ };
297
313
  };
298
314
 
299
315
  /**
@@ -306,12 +322,15 @@ const getContract = async ({ meta, priceTokens, components }) => {
306
322
  * did: string
307
323
  * url: string
308
324
  * name: string
309
- * paymentVersion: string
325
+ * version: string
326
+ * payment: {
327
+ * version: string
328
+ * }
310
329
  * stores: Array<{
311
330
  * signer: string
312
331
  * pk: string
313
332
  * signature: string
314
- * componentDids: Array<string>
333
+ * components: Array<{did: string, version: string}>
315
334
  * paymentIntegrity: string
316
335
  * }>
317
336
  * }
@@ -342,8 +361,11 @@ const _createNftFactoryItx = ({ meta, issuers, serviceUrl, storeSignatures, fact
342
361
  did: meta.did,
343
362
  url: joinURL(serviceUrl, `/blocklet/${meta.did}`),
344
363
  name: meta.name,
345
- paymentVersion: VERSION,
346
- stores: storeSignatures.map((x) => pick(x, ['signer', 'pk', 'signature', 'componentDids', 'paymentIntegrity'])),
364
+ version: meta.version,
365
+ payment: {
366
+ version: VERSION,
367
+ },
368
+ stores: storeSignatures.map((x) => pick(x, ['signer', 'pk', 'signature', 'components', 'paymentIntegrity'])),
347
369
  },
348
370
  },
349
371
  hooks: [
@@ -377,24 +399,24 @@ const getFactoryInput = (inputTokens, { formatToken = true } = {}) => {
377
399
  };
378
400
  };
379
401
 
380
- const getPaymentIntegrity = async ({ contract, factoryInput, componentDids, meta, client, storeId }) => {
381
- if (!contract && !factoryInput && !componentDids) {
402
+ const getPaymentIntegrity = async ({ contract, factoryInput, storeComponents, meta, client, storeId }) => {
403
+ if (!contract && !factoryInput && !storeComponents) {
382
404
  const priceTokens = await getPriceTokens(meta, client);
383
405
  const { components, stores } = await getComponents(meta);
384
406
  const store = stores.find((x) => x.id === storeId);
385
407
 
386
408
  // eslint-disable-next-line no-param-reassign
387
- contract = await getContract({ meta, components, priceTokens });
409
+ contract = (await getContract({ meta, components, priceTokens })).code;
388
410
  // eslint-disable-next-line no-param-reassign
389
411
  factoryInput = await getFactoryInput(priceTokens);
390
412
  // eslint-disable-next-line no-param-reassign
391
- componentDids = store?.componentDids || [];
413
+ storeComponents = store?.components || [];
392
414
  }
393
415
 
394
416
  const paymentData = {
395
417
  factoryInput,
396
418
  contract,
397
- componentDids: componentDids || [],
419
+ components: storeComponents || [],
398
420
  };
399
421
 
400
422
  const integrity = md5(stableStringify(paymentData));
@@ -402,15 +424,12 @@ const getPaymentIntegrity = async ({ contract, factoryInput, componentDids, meta
402
424
  return integrity;
403
425
  };
404
426
 
405
- const getStoreSignatures = async ({ meta, client, priceTokens, components, stores }) => {
406
- const factoryInput = getFactoryInput(priceTokens);
407
- const contract = await getContract({ meta, client, priceTokens, components });
408
-
427
+ const getStoreSignatures = async ({ meta, stores, factoryInput, contract }) => {
409
428
  const storeSignatures = [];
410
429
  for (const store of stores) {
411
- const { id, url, pk, componentDids } = store;
430
+ const { id, url, pk, components: storeComponents } = store;
412
431
 
413
- const paymentIntegrity = await getPaymentIntegrity({ factoryInput, contract, componentDids });
432
+ const paymentIntegrity = await getPaymentIntegrity({ factoryInput, contract, storeComponents });
414
433
 
415
434
  /**
416
435
  * protocol: /api/payment/signature
@@ -448,7 +467,7 @@ const getStoreSignatures = async ({ meta, client, priceTokens, components, store
448
467
  signer: res.signer,
449
468
  pk: res.pk,
450
469
  signature: res.signature,
451
- componentDids,
470
+ components: storeComponents,
452
471
  paymentIntegrity,
453
472
  storeUrl: url,
454
473
  });
@@ -456,13 +475,12 @@ const getStoreSignatures = async ({ meta, client, priceTokens, components, store
456
475
 
457
476
  return {
458
477
  storeSignatures,
459
- factoryInput,
460
- contract,
461
478
  };
462
479
  };
463
480
 
464
481
  /**
465
482
  * Used by CLI and Store to independent compute factory itx
483
+ *
466
484
  * @param {{
467
485
  * blockletMeta: BlockletMeta,
468
486
  * ocapClient: OcapClient,
@@ -472,18 +490,34 @@ const getStoreSignatures = async ({ meta, client, priceTokens, components, store
472
490
  * @returns {{
473
491
  * itx: Itx
474
492
  * store: Array<{id, url}>
493
+ * shares: Array<{
494
+ * accountName: string
495
+ * accountAddress: DID
496
+ * tokenAddress: DID
497
+ * amount: string|number,
498
+ * }>
475
499
  * }}
476
500
  */
477
501
  const createNftFactoryItx = async ({ blockletMeta, ocapClient, issuers, storeUrl }) => {
478
502
  const priceTokens = await getPriceTokens(blockletMeta, ocapClient);
479
503
  const { components, stores } = await getComponents(blockletMeta);
480
504
 
481
- const { factoryInput, contract, storeSignatures } = await getStoreSignatures({
505
+ const factoryInput = getFactoryInput(priceTokens);
506
+ const { code: contract, shares } = await getContract({
507
+ meta: blockletMeta,
508
+ client: ocapClient,
509
+ priceTokens,
510
+ components,
511
+ });
512
+
513
+ const { storeSignatures } = await getStoreSignatures({
482
514
  meta: blockletMeta,
483
515
  client: ocapClient,
484
516
  priceTokens,
485
517
  components,
486
518
  stores,
519
+ factoryInput,
520
+ contract,
487
521
  });
488
522
 
489
523
  return {
@@ -499,6 +533,7 @@ const createNftFactoryItx = async ({ blockletMeta, ocapClient, issuers, storeUrl
499
533
  contract,
500
534
  }),
501
535
  stores: storeSignatures.map((x) => ({ id: x.signer, url: x.storeUrl })),
536
+ shares,
502
537
  };
503
538
  };
504
539
 
@@ -532,7 +567,7 @@ const verifyPaymentIntegrity = async ({ integrity: expected, blockletMeta, ocapC
532
567
  * }}
533
568
  *
534
569
  * @returns {{
535
- * componentDids: Array<string>
570
+ * components: Array<{did: string, version: string}>
536
571
  * }}
537
572
  */
538
573
  const verifyNftFactory = async ({ factoryState, signerWallet }) => {
@@ -547,7 +582,7 @@ const verifyNftFactory = async ({ factoryState, signerWallet }) => {
547
582
  }
548
583
 
549
584
  const c = factoryState.hooks.find((x) => x.type === 'contract');
550
- const { componentDids } = store;
585
+ const { components } = store;
551
586
 
552
587
  // Token 的字段和 factory 中的字段不一致
553
588
  const factoryInput = getFactoryInput(
@@ -558,15 +593,15 @@ const verifyNftFactory = async ({ factoryState, signerWallet }) => {
558
593
  const integrity = await getPaymentIntegrity({
559
594
  contract: c.hook,
560
595
  factoryInput,
561
- componentDids,
596
+ storeComponents: components,
562
597
  });
563
598
 
564
599
  if (signerWallet.sign(integrity) !== store.signature) {
565
- debug(store, factoryInput, integrity, componentDids, c.hook);
600
+ debug(store, factoryInput, integrity, components, c.hook);
566
601
  throw new Error(`verify nft factory failed: ${factoryState.address}`);
567
602
  }
568
603
 
569
- return { componentDids };
604
+ return { components };
570
605
  };
571
606
 
572
607
  module.exports = {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.8.14",
6
+ "version": "1.8.17",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,16 +18,16 @@
18
18
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@abtnode/constant": "1.8.14",
22
- "@abtnode/util": "1.8.14",
23
- "@arcblock/did": "1.17.17",
24
- "@arcblock/did-ext": "1.17.17",
25
- "@arcblock/did-util": "1.17.17",
26
- "@arcblock/jwt": "1.17.17",
27
- "@ocap/asset": "1.17.17",
28
- "@ocap/mcrypto": "1.17.17",
29
- "@ocap/util": "1.17.17",
30
- "@ocap/wallet": "1.17.17",
21
+ "@abtnode/constant": "1.8.17",
22
+ "@abtnode/util": "1.8.17",
23
+ "@arcblock/did": "1.17.19",
24
+ "@arcblock/did-ext": "1.17.19",
25
+ "@arcblock/did-util": "1.17.19",
26
+ "@arcblock/jwt": "1.17.19",
27
+ "@ocap/asset": "1.17.19",
28
+ "@ocap/mcrypto": "1.17.19",
29
+ "@ocap/util": "1.17.19",
30
+ "@ocap/wallet": "1.17.19",
31
31
  "ajv": "^8.11.0",
32
32
  "axios": "^0.27.2",
33
33
  "cjk-length": "^1.0.0",
@@ -53,5 +53,5 @@
53
53
  "express": "^4.18.1",
54
54
  "jest": "^27.5.1"
55
55
  },
56
- "gitHead": "4b0cee41fd03d09301e2c35af46dd9e513473ef8"
56
+ "gitHead": "aa1854b3b71a6250182bfcad794235099f38a514"
57
57
  }