@blocklet/meta 1.8.14 → 1.8.15

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.
Files changed (2) hide show
  1. package/lib/payment/v2.js +32 -21
  2. package/package.json +4 -4
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) => {
@@ -306,12 +311,15 @@ const getContract = async ({ meta, priceTokens, components }) => {
306
311
  * did: string
307
312
  * url: string
308
313
  * name: string
309
- * paymentVersion: string
314
+ * version: string
315
+ * payment: {
316
+ * version: string
317
+ * }
310
318
  * stores: Array<{
311
319
  * signer: string
312
320
  * pk: string
313
321
  * signature: string
314
- * componentDids: Array<string>
322
+ * components: Array<{did: string, version: string}>
315
323
  * paymentIntegrity: string
316
324
  * }>
317
325
  * }
@@ -342,8 +350,11 @@ const _createNftFactoryItx = ({ meta, issuers, serviceUrl, storeSignatures, fact
342
350
  did: meta.did,
343
351
  url: joinURL(serviceUrl, `/blocklet/${meta.did}`),
344
352
  name: meta.name,
345
- paymentVersion: VERSION,
346
- stores: storeSignatures.map((x) => pick(x, ['signer', 'pk', 'signature', 'componentDids', 'paymentIntegrity'])),
353
+ version: meta.version,
354
+ payment: {
355
+ version: VERSION,
356
+ },
357
+ stores: storeSignatures.map((x) => pick(x, ['signer', 'pk', 'signature', 'components', 'paymentIntegrity'])),
347
358
  },
348
359
  },
349
360
  hooks: [
@@ -377,8 +388,8 @@ const getFactoryInput = (inputTokens, { formatToken = true } = {}) => {
377
388
  };
378
389
  };
379
390
 
380
- const getPaymentIntegrity = async ({ contract, factoryInput, componentDids, meta, client, storeId }) => {
381
- if (!contract && !factoryInput && !componentDids) {
391
+ const getPaymentIntegrity = async ({ contract, factoryInput, storeComponents, meta, client, storeId }) => {
392
+ if (!contract && !factoryInput && !storeComponents) {
382
393
  const priceTokens = await getPriceTokens(meta, client);
383
394
  const { components, stores } = await getComponents(meta);
384
395
  const store = stores.find((x) => x.id === storeId);
@@ -388,13 +399,13 @@ const getPaymentIntegrity = async ({ contract, factoryInput, componentDids, meta
388
399
  // eslint-disable-next-line no-param-reassign
389
400
  factoryInput = await getFactoryInput(priceTokens);
390
401
  // eslint-disable-next-line no-param-reassign
391
- componentDids = store?.componentDids || [];
402
+ storeComponents = store?.components || [];
392
403
  }
393
404
 
394
405
  const paymentData = {
395
406
  factoryInput,
396
407
  contract,
397
- componentDids: componentDids || [],
408
+ components: storeComponents || [],
398
409
  };
399
410
 
400
411
  const integrity = md5(stableStringify(paymentData));
@@ -408,9 +419,9 @@ const getStoreSignatures = async ({ meta, client, priceTokens, components, store
408
419
 
409
420
  const storeSignatures = [];
410
421
  for (const store of stores) {
411
- const { id, url, pk, componentDids } = store;
422
+ const { id, url, pk, components: storeComponents } = store;
412
423
 
413
- const paymentIntegrity = await getPaymentIntegrity({ factoryInput, contract, componentDids });
424
+ const paymentIntegrity = await getPaymentIntegrity({ factoryInput, contract, storeComponents });
414
425
 
415
426
  /**
416
427
  * protocol: /api/payment/signature
@@ -448,7 +459,7 @@ const getStoreSignatures = async ({ meta, client, priceTokens, components, store
448
459
  signer: res.signer,
449
460
  pk: res.pk,
450
461
  signature: res.signature,
451
- componentDids,
462
+ components: storeComponents,
452
463
  paymentIntegrity,
453
464
  storeUrl: url,
454
465
  });
@@ -532,7 +543,7 @@ const verifyPaymentIntegrity = async ({ integrity: expected, blockletMeta, ocapC
532
543
  * }}
533
544
  *
534
545
  * @returns {{
535
- * componentDids: Array<string>
546
+ * components: Array<{did: string, version: string}>
536
547
  * }}
537
548
  */
538
549
  const verifyNftFactory = async ({ factoryState, signerWallet }) => {
@@ -547,7 +558,7 @@ const verifyNftFactory = async ({ factoryState, signerWallet }) => {
547
558
  }
548
559
 
549
560
  const c = factoryState.hooks.find((x) => x.type === 'contract');
550
- const { componentDids } = store;
561
+ const { components } = store;
551
562
 
552
563
  // Token 的字段和 factory 中的字段不一致
553
564
  const factoryInput = getFactoryInput(
@@ -558,15 +569,15 @@ const verifyNftFactory = async ({ factoryState, signerWallet }) => {
558
569
  const integrity = await getPaymentIntegrity({
559
570
  contract: c.hook,
560
571
  factoryInput,
561
- componentDids,
572
+ storeComponents: components,
562
573
  });
563
574
 
564
575
  if (signerWallet.sign(integrity) !== store.signature) {
565
- debug(store, factoryInput, integrity, componentDids, c.hook);
576
+ debug(store, factoryInput, integrity, components, c.hook);
566
577
  throw new Error(`verify nft factory failed: ${factoryState.address}`);
567
578
  }
568
579
 
569
- return { componentDids };
580
+ return { components };
570
581
  };
571
582
 
572
583
  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.15",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -18,8 +18,8 @@
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",
21
+ "@abtnode/constant": "1.8.15",
22
+ "@abtnode/util": "1.8.15",
23
23
  "@arcblock/did": "1.17.17",
24
24
  "@arcblock/did-ext": "1.17.17",
25
25
  "@arcblock/did-util": "1.17.17",
@@ -53,5 +53,5 @@
53
53
  "express": "^4.18.1",
54
54
  "jest": "^27.5.1"
55
55
  },
56
- "gitHead": "4b0cee41fd03d09301e2c35af46dd9e513473ef8"
56
+ "gitHead": "57106db1b559b906734df5b8eac7ce87cae72980"
57
57
  }