@blocklet/meta 1.15.17 → 1.16.0-beta-8ee536d7

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 (62) hide show
  1. package/lib/channel.d.ts +32 -0
  2. package/lib/channel.js +54 -0
  3. package/lib/constants.d.ts +2 -0
  4. package/lib/constants.js +5 -152
  5. package/lib/did.d.ts +3 -0
  6. package/lib/did.js +9 -9
  7. package/lib/engine.d.ts +7 -0
  8. package/lib/engine.js +21 -25
  9. package/lib/entry.d.ts +3 -0
  10. package/lib/entry.js +51 -64
  11. package/lib/extension.d.ts +14 -0
  12. package/lib/extension.js +82 -77
  13. package/lib/file.d.ts +23 -0
  14. package/lib/file.js +51 -36
  15. package/lib/fix.d.ts +36 -0
  16. package/lib/fix.js +231 -228
  17. package/lib/get-component-process-id.d.ts +5 -0
  18. package/lib/get-component-process-id.js +16 -0
  19. package/lib/has-reserved-key.d.ts +3 -0
  20. package/lib/has-reserved-key.js +15 -0
  21. package/lib/index.d.ts +86 -0
  22. package/lib/index.js +55 -34
  23. package/lib/info.d.ts +15 -0
  24. package/lib/info.js +70 -38
  25. package/lib/name.d.ts +15 -0
  26. package/lib/name.js +41 -8
  27. package/lib/nft-templates.d.ts +86 -0
  28. package/lib/nft-templates.js +52 -0
  29. package/lib/parse-navigation-from-blocklet.d.ts +92 -0
  30. package/lib/parse-navigation-from-blocklet.js +539 -0
  31. package/lib/parse-navigation.d.ts +3 -0
  32. package/lib/parse-navigation.js +197 -0
  33. package/lib/parse.d.ts +22 -0
  34. package/lib/parse.js +100 -89
  35. package/lib/payment/index.d.ts +254 -0
  36. package/lib/payment/index.js +14 -0
  37. package/lib/payment/v1.d.ts +185 -0
  38. package/lib/payment/v1.js +84 -0
  39. package/lib/payment/v2.d.ts +242 -0
  40. package/lib/payment/v2.js +576 -0
  41. package/lib/schema.d.ts +63 -0
  42. package/lib/schema.js +669 -283
  43. package/lib/service.d.ts +27 -0
  44. package/lib/service.js +71 -0
  45. package/lib/types/index.d.ts +1 -0
  46. package/lib/types/index.js +18 -0
  47. package/lib/types/schema.d.ts +284 -0
  48. package/lib/types/schema.js +3 -0
  49. package/lib/url-friendly.d.ts +6 -0
  50. package/lib/url-friendly.js +20 -0
  51. package/lib/util-meta.d.ts +42 -0
  52. package/lib/util-meta.js +146 -0
  53. package/lib/util.d.ts +201 -0
  54. package/lib/util.js +501 -82
  55. package/lib/validate.d.ts +13 -0
  56. package/lib/validate.js +37 -61
  57. package/lib/verify-multi-sig.d.ts +3 -0
  58. package/lib/verify-multi-sig.js +86 -59
  59. package/lib/wallet.d.ts +9 -0
  60. package/lib/wallet.js +19 -30
  61. package/package.json +59 -20
  62. package/lib/payment.js +0 -114
package/lib/validate.js CHANGED
@@ -1,64 +1,40 @@
1
- const Ajv = require('ajv').default;
2
- const cloneDeep = require('lodash/cloneDeep');
3
-
4
- const { createBlockletSchema } = require('./schema');
5
-
6
- const fixAndValidateService = (meta, serviceMetas) => {
7
- const ajv = new Ajv({
8
- useDefaults: true,
9
- removeAdditional: 'all',
10
- });
11
-
12
- if (!meta.interfaces) {
13
- return meta;
14
- }
15
- if (!meta.interfaces.length) {
16
- return meta;
17
- }
18
-
19
- meta.interfaces.forEach((d) => {
20
- if (d.services && d.services.length) {
21
- d.services.forEach((s) => {
22
- const config = cloneDeep(s.config) || {};
23
-
24
- // validate service.config if serviceMetaList is exist
25
- if (serviceMetas) {
26
- const serviceMeta = serviceMetas.find((x) => x.name === s.name);
27
- if (!serviceMeta) {
28
- throw new Error(`Invalid blocklet service: ${s.name} does not exist`);
29
- }
30
-
31
- const validate = ajv.compile(serviceMeta.schema.JSONSchema);
32
- // this method may have side effect thar will fill default value to config
33
- const valid = validate(config);
34
-
35
- if (!valid) {
36
- const message = validate.errors.map((x) => `${x.dataPath} ${x.message}`).join(', ');
37
- throw new Error(`Invalid blocklet service config: ${message}`);
38
- }
39
- }
40
-
41
- s.config = config;
42
- });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixAndValidateService = exports.validateMeta = void 0;
4
+ const schema_1 = require("./schema");
5
+ const service_1 = require("./service");
6
+ const fixAndValidateService = (meta) => {
7
+ if (!meta.interfaces) {
8
+ return meta;
9
+ }
10
+ if (!meta.interfaces.length) {
11
+ return meta;
43
12
  }
44
- });
45
-
46
- return meta;
13
+ meta.interfaces.forEach((d) => {
14
+ if (d.services && d.services.length) {
15
+ d.services.forEach((s) => {
16
+ s.config = (0, service_1.getServiceConfig)(s.name, s.config, { validate: true });
17
+ });
18
+ }
19
+ });
20
+ return meta;
47
21
  };
48
-
49
- const validateMeta = (
50
- meta,
51
- { ensureMain = false, ensureFiles = false, ensureDist = false, schemaOptions = {} } = {}
52
- ) => {
53
- const schema = createBlockletSchema(null, { ensureMain, ensureFiles, ensureDist, ...schemaOptions });
54
- const { value, error } = schema.validate(meta);
55
- if (error) {
56
- throw new Error(`Invalid blocklet meta: ${error.details.map((x) => x.message).join(', ')}`);
57
- }
58
-
59
- return value;
22
+ exports.fixAndValidateService = fixAndValidateService;
23
+ const validateMeta = (meta, { ensureMain = false, ensureFiles = false, ensureDist = false, ensureComponentStore = true, ensureName = false, skipValidateDidName = false, schemaOptions = {}, } = {}) => {
24
+ const schema = (0, schema_1.createBlockletSchema)(null, {
25
+ ensureMain,
26
+ ensureFiles,
27
+ ensureDist,
28
+ ensureComponentStore,
29
+ ensureName,
30
+ skipValidateDidName,
31
+ ...schemaOptions,
32
+ });
33
+ const { value, error } = schema.validate(meta);
34
+ if (error) {
35
+ throw new Error(`Invalid blocklet meta: ${error.details.map((x) => x.message).join(', ')}`);
36
+ }
37
+ return value;
60
38
  };
61
-
62
- module.exports = validateMeta;
63
- module.exports.validateMeta = validateMeta;
64
- module.exports.fixAndValidateService = fixAndValidateService;
39
+ exports.validateMeta = validateMeta;
40
+ exports.default = validateMeta;
@@ -0,0 +1,3 @@
1
+ import { TBlockletMeta } from './types';
2
+ declare const verifyMultiSig: (blockletMeta: TBlockletMeta) => boolean;
3
+ export = verifyMultiSig;
@@ -1,63 +1,90 @@
1
- const debug = require('debug')('@blocklet/meta:verifyMultiSig');
2
- const stableStringify = require('json-stable-stringify');
3
- const cloneDeep = require('lodash/cloneDeep');
4
- const omit = require('lodash/omit');
5
- const { toTypeInfo } = require('@arcblock/did');
6
- const { fromPublicKey } = require('@ocap/wallet');
7
-
8
- module.exports = (blockletMeta) => {
9
- const { signatures: tmpSignatures, ...meta } = blockletMeta;
10
- const signatures = cloneDeep(tmpSignatures);
11
-
12
- if (!Array.isArray(signatures)) {
13
- throw new Error('Invalid signatures, signatures should be an array');
14
- }
15
-
16
- if (signatures.length === 0) {
17
- throw new Error('Invalid signatures, found empty');
18
- }
19
-
20
- const { length } = signatures;
21
- let lastSignature = null;
22
-
23
- for (let i = 0; i < length; i++) {
24
- const signature = signatures.shift();
25
- const { sig, signer, pk } = signature;
26
- delete signature.sig;
27
- debug('verify', { signer });
28
-
29
- let toBeVerifiedMeta = { ...meta };
30
-
31
- if (lastSignature && lastSignature.appended) {
32
- debug('appended fields', { signer, appended: lastSignature.appended });
33
-
34
- lastSignature.appended.forEach((field) => {
35
- toBeVerifiedMeta = omit(toBeVerifiedMeta, field);
36
- });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ /* eslint-disable @typescript-eslint/indent */
6
+ const get_1 = __importDefault(require("lodash/get"));
7
+ const omit_1 = __importDefault(require("lodash/omit"));
8
+ const cloneDeep_1 = __importDefault(require("lodash/cloneDeep"));
9
+ const json_stable_stringify_1 = __importDefault(require("json-stable-stringify"));
10
+ const did_1 = require("@arcblock/did");
11
+ const wallet_1 = require("@ocap/wallet");
12
+ const jwt_1 = require("@arcblock/jwt");
13
+ const util_1 = require("@ocap/util");
14
+ const debug_1 = __importDefault(require("debug"));
15
+ const debug = (0, debug_1.default)('@blocklet/meta:verifyMultiSig');
16
+ function verifyDelegationToken(signature) {
17
+ if (signature.delegation) {
18
+ // @ts-ignore
19
+ const payload = JSON.parse((0, util_1.fromBase64)(signature.delegation.split('.')[1]));
20
+ if (payload.from !== signature.signer) {
21
+ debug('verify payload.from failed', { payload, signature });
22
+ return false;
23
+ }
24
+ if (payload.to !== signature.delegatee) {
25
+ debug('verify payload.to failed', { payload, signature });
26
+ return false;
27
+ }
28
+ if (!(0, get_1.default)(payload, 'permissions', []).includes('publish_blocklet')) {
29
+ debug('verify payload.permissions failed', payload);
30
+ return false;
31
+ }
32
+ // 验证一下delegation token
33
+ if (!(0, jwt_1.verify)(signature.delegation, signature.pk)) {
34
+ debug('verify delegation token failed', signature);
35
+ return false;
36
+ }
37
+ }
38
+ return true;
39
+ }
40
+ const verifyMultiSig = (blockletMeta) => {
41
+ const { signatures: tmpSignatures, ...meta } = blockletMeta;
42
+ const signatures = (0, cloneDeep_1.default)(tmpSignatures);
43
+ if (!Array.isArray(signatures)) {
44
+ throw new Error('Invalid signatures, signatures should be an array');
37
45
  }
38
-
39
- if (signature.excludes && signature.excludes.length > 0) {
40
- debug('excludes fields', { signer, excludes: signature.excludes });
41
-
42
- signature.excludes.forEach((field) => {
43
- toBeVerifiedMeta = omit(toBeVerifiedMeta, field);
44
- });
46
+ if (signatures.length === 0) {
47
+ throw new Error('Invalid signatures, found empty');
45
48
  }
46
-
47
- const type = toTypeInfo(signer);
48
- const wallet = fromPublicKey(pk, type);
49
- const verifyRes = wallet.verify(
50
- stableStringify({ ...toBeVerifiedMeta, signatures: [signature, ...signatures] }),
51
- sig
52
- );
53
- if (verifyRes !== true) {
54
- debug('verify failed', { signer });
55
-
56
- return verifyRes;
49
+ const { length } = signatures;
50
+ let lastSignature = null;
51
+ for (let i = 0; i < length; i++) {
52
+ const signature = signatures.shift();
53
+ // 验证delegation token
54
+ if (!verifyDelegationToken(signature)) {
55
+ return false;
56
+ }
57
+ const { sig, signer, pk } = signature.delegation
58
+ ? {
59
+ sig: signature.sig,
60
+ signer: signature.delegatee,
61
+ pk: signature.delegateePk,
62
+ }
63
+ : signature;
64
+ delete signature.sig;
65
+ debug('verify', { signer });
66
+ let toBeVerifiedMeta = { ...meta };
67
+ if (lastSignature && lastSignature.appended) {
68
+ debug('appended fields', { signer, appended: lastSignature.appended });
69
+ lastSignature.appended.forEach((field) => {
70
+ toBeVerifiedMeta = (0, omit_1.default)(toBeVerifiedMeta, field);
71
+ });
72
+ }
73
+ if (signature.excludes && signature.excludes.length > 0) {
74
+ debug('excludes fields', { signer, excludes: signature.excludes });
75
+ signature.excludes.forEach((field) => {
76
+ toBeVerifiedMeta = (0, omit_1.default)(toBeVerifiedMeta, field);
77
+ });
78
+ }
79
+ const type = (0, did_1.toTypeInfo)(signer);
80
+ const wallet = (0, wallet_1.fromPublicKey)(pk, type);
81
+ const verifyRes = wallet.verify((0, json_stable_stringify_1.default)({ ...toBeVerifiedMeta, signatures: [signature, ...signatures] }), sig);
82
+ if (verifyRes !== true) {
83
+ debug('verify failed', { signer });
84
+ return verifyRes;
85
+ }
86
+ lastSignature = signature;
57
87
  }
58
-
59
- lastSignature = signature;
60
- }
61
-
62
- return true;
88
+ return true;
63
89
  };
90
+ module.exports = verifyMultiSig;
@@ -0,0 +1,9 @@
1
+ import { WalletObject } from '@ocap/wallet';
2
+ import { DIDType } from '@arcblock/did';
3
+ /**
4
+ * Gen DID from blocklet did and nodeSk
5
+ *
6
+ * Spec: https://github.com/ArcBlock/ABT-DID-Protocol#request-did-authentication
7
+ */
8
+ declare const getApplicationWallet: (blockletDid: string, nodeSk?: string, type?: DIDType | string, index?: number) => WalletObject;
9
+ export = getApplicationWallet;
package/lib/wallet.js CHANGED
@@ -1,37 +1,26 @@
1
- const Mcrypto = require('@ocap/mcrypto');
2
- const { fromSecretKey } = require('@ocap/wallet');
3
- const { isValid } = require('@arcblock/did');
4
- const { fromAppDid } = require('@arcblock/did-ext');
5
-
6
- const { types } = Mcrypto;
7
-
1
+ "use strict";
2
+ const mcrypto_1 = require("@ocap/mcrypto");
3
+ const wallet_1 = require("@ocap/wallet");
4
+ const did_1 = require("@arcblock/did");
5
+ const did_ext_1 = require("@arcblock/did-ext");
8
6
  /**
9
7
  * Gen DID from blocklet did and nodeSk
10
8
  *
11
9
  * Spec: https://github.com/ArcBlock/ABT-DID-Protocol#request-did-authentication
12
- *
13
- * @public
14
- * @static
15
- * @param {string} blockletDid - blocklet did
16
- * @param {string} nodeSk - node sk used to derive blocklet sk
17
- * @param {object} [type={}]
18
- * @param {number} [index=0]
19
- * @returns {object} Wallet instance
20
10
  */
21
- const getBlockletWallet = (blockletDid, nodeSk, type = { role: types.RoleType.ROLE_APPLICATION }, index = 0) => {
22
- if (!isValid(blockletDid)) {
23
- try {
24
- return fromSecretKey(blockletDid, type);
25
- } catch (err) {
26
- throw new Error(`Cannot get blocklet wallet with invalid blocklet did or custom sk: ${err.message}`);
11
+ const getApplicationWallet = (blockletDid, nodeSk, type, index) => {
12
+ const t = type || { role: mcrypto_1.types.RoleType.ROLE_APPLICATION };
13
+ if (!(0, did_1.isValid)(blockletDid)) {
14
+ try {
15
+ return (0, wallet_1.fromSecretKey)(blockletDid, t);
16
+ }
17
+ catch (err) {
18
+ throw new Error(`Cannot get blocklet wallet with invalid blocklet did or custom sk: ${err.message}`);
19
+ }
20
+ }
21
+ if (!nodeSk) {
22
+ throw new Error('Cannot get blocklet wallet with empty node sk');
27
23
  }
28
- }
29
-
30
- if (!nodeSk) {
31
- throw new Error('Cannot get blocklet wallet with empty node sk');
32
- }
33
-
34
- return fromAppDid(blockletDid, nodeSk, type, index);
24
+ return (0, did_ext_1.fromAppDid)(blockletDid, nodeSk, t, index || 0);
35
25
  };
36
-
37
- module.exports = getBlockletWallet;
26
+ module.exports = getApplicationWallet;
package/package.json CHANGED
@@ -3,44 +3,83 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.15.17",
6
+ "version": "1.16.0-beta-8ee536d7",
7
7
  "description": "Library to parse/validate/fix blocklet meta",
8
- "main": "lib/index.js",
8
+ "main": "./lib/index.js",
9
+ "typings": "./lib/index.d.ts",
9
10
  "files": [
10
11
  "lib"
11
12
  ],
12
13
  "scripts": {
13
- "lint": "eslint tests lib",
14
- "lint:fix": "eslint --fix tests lib",
14
+ "verify": "npm run lint:fix && npm run coverage && npm run build",
15
+ "lint": "eslint src tests",
16
+ "lint:fix": "npm run lint -- --fix",
15
17
  "test": "node tools/jest.js",
16
- "coverage": "npm run test -- --coverage"
18
+ "coverage": "npm run test -- --coverage",
19
+ "clean": "rm -fr lib",
20
+ "types": "ts-node tools/types.js && sed -i.bak 's/unknown/string/g' ./src/types/schema.ts && rm ./src/types/schema.ts.bak && prettier --write ./src/types/*.ts",
21
+ "prebuild": "npm run clean && npm run types",
22
+ "build": "tsc"
17
23
  },
18
24
  "author": "wangshijun <wangshijun2020@gmail.com> (http://github.com/wangshijun)",
19
25
  "license": "MIT",
20
26
  "dependencies": {
21
- "@arcblock/did": "^1.13.61",
22
- "@arcblock/did-ext": "^1.13.61",
23
- "@arcblock/did-util": "^1.13.61",
24
- "@arcblock/nft": "^1.13.61",
25
- "@ocap/asset": "^1.13.61",
26
- "@ocap/mcrypto": "^1.13.61",
27
- "@ocap/util": "^1.13.61",
28
- "@ocap/wallet": "^1.13.61",
29
- "ajv": "^7.0.3",
30
- "debug": "^4.3.2",
31
- "fs-extra": "^10.0.0",
27
+ "@abtnode/client": "1.16.0-beta-8ee536d7",
28
+ "@abtnode/constant": "1.16.0-beta-8ee536d7",
29
+ "@abtnode/util": "1.16.0-beta-8ee536d7",
30
+ "@arcblock/did": "1.18.62",
31
+ "@arcblock/did-ext": "1.18.62",
32
+ "@arcblock/did-util": "1.18.62",
33
+ "@arcblock/jwt": "1.18.62",
34
+ "@blocklet/constant": "1.16.0-beta-8ee536d7",
35
+ "@ocap/asset": "1.18.62",
36
+ "@ocap/mcrypto": "1.18.62",
37
+ "@ocap/types": "1.18.62",
38
+ "@ocap/util": "1.18.62",
39
+ "@ocap/wallet": "1.18.62",
40
+ "ajv": "^8.11.0",
41
+ "axios": "^0.27.2",
42
+ "cjk-length": "^1.0.0",
43
+ "debug": "^4.3.4",
44
+ "fs-extra": "^10.1.0",
32
45
  "hosted-git-info": "3.0.8",
46
+ "is-absolute-url": "^3.0.3",
33
47
  "is-glob": "^4.0.3",
34
- "joi": "^17.4.0",
48
+ "is-var-name": "^2.0.0",
49
+ "joi": "17.7.0",
35
50
  "joi-extension-semver": "^5.0.0",
36
- "js-yaml": "^3.14.0",
51
+ "js-yaml": "^4.1.0",
37
52
  "json-stable-stringify": "^1.0.1",
38
53
  "lodash": "^4.17.21",
54
+ "p-limit": "^3.1.0",
55
+ "promise.any": "^2.0.4",
56
+ "slugify": "^1.6.5",
39
57
  "url-join": "^4.0.1",
58
+ "utility-types": "^3.10.0",
40
59
  "validate-npm-package-name": "^3.0.0"
41
60
  },
42
61
  "devDependencies": {
43
- "jest": "^27.3.1"
62
+ "@abtnode/client": "^1.8.68",
63
+ "@arcblock/eslint-config-ts": "^0.2.3",
64
+ "@types/express": "^4.17.14",
65
+ "@types/jest": "^29.2.2",
66
+ "@types/joi": "^17.2.3",
67
+ "@types/js-yaml": "^4.0.5",
68
+ "@types/validate-npm-package-name": "^4.0.0",
69
+ "@typescript-eslint/eslint-plugin": "^5.42.0",
70
+ "@typescript-eslint/parser": "^5.42.0",
71
+ "body-parser": "^1.20.1",
72
+ "compression": "^1.7.4",
73
+ "detect-port": "^1.5.1",
74
+ "eslint": "^8.27.0",
75
+ "expand-tilde": "^2.0.2",
76
+ "express": "^4.18.2",
77
+ "jest": "^29.3.0",
78
+ "joi-to-typescript": "^4.0.7",
79
+ "prettier": "^2.7.1",
80
+ "ts-jest": "^29.0.3",
81
+ "ts-node": "^10.9.1",
82
+ "typescript": "^4.8.4"
44
83
  },
45
- "gitHead": "22715c3ea74d0230f3413162a17f491614b6735a"
84
+ "gitHead": "57d0c45be311a5fbc1c0fffa2814b62c1a3ee34c"
46
85
  }
package/lib/payment.js DELETED
@@ -1,114 +0,0 @@
1
- /* eslint-disable no-await-in-loop */
2
- const joinURL = require('url-join');
3
- const { BN } = require('@ocap/util');
4
- const { isValidFactory } = require('@ocap/asset');
5
- const { toFactoryAddress } = require('@arcblock/did-util');
6
- const { getBlockletPurchaseTemplate } = require('@arcblock/nft/lib/templates');
7
-
8
- const isFreeBlocklet = (meta) => {
9
- if (!meta.charging) {
10
- return true;
11
- }
12
-
13
- const primaryPrice = meta.charging.price || 0;
14
- const secondaryPrice = (meta.charging.tokens || []).map((x) => x.price || 0);
15
- if (primaryPrice <= 0 && secondaryPrice.every((x) => x <= 0)) {
16
- return true;
17
- }
18
-
19
- return false;
20
- };
21
-
22
- const createShareContract = ({ price, shares, tokens = [] }) => {
23
- const zeroBN = new BN(0);
24
- const decimals = 1000000; // we only support 6 decimals on share ratio
25
- const decimalsBN = new BN(decimals);
26
-
27
- const contract = [];
28
- const shareSum = shares.reduce((sum, x) => sum + x.share, 0);
29
- if (shareSum > 1) {
30
- throw new Error('charging.shares invalid: share sum should not be greater than 1');
31
- }
32
-
33
- // split primary token
34
- const priceBN = new BN(price);
35
- if (priceBN.lt(zeroBN)) {
36
- throw new Error('price must be greater than or equal to zero');
37
- }
38
- if (priceBN.gt(zeroBN)) {
39
- shares.forEach(({ address, share }) => {
40
- const ratio = new BN(share * decimals);
41
- const amount = priceBN.mul(ratio).div(decimalsBN);
42
- contract.push(`transfer('${address}','${amount.toString()}')`);
43
- });
44
- }
45
-
46
- // split secondary token
47
- if (Array.isArray(tokens)) {
48
- tokens.forEach(({ address: tokenAddress, value }) => {
49
- const valueBN = new BN(value);
50
- if (valueBN.lt(zeroBN)) {
51
- throw new Error('token price must be greater than or equal to zero');
52
- }
53
- shares.forEach(({ address, share }) => {
54
- const ratio = new BN(share * decimals);
55
- const amount = valueBN.mul(ratio).div(decimalsBN);
56
- contract.push(`transferToken('${tokenAddress}','${address}','${amount.toString()}')`);
57
- });
58
- });
59
- }
60
-
61
- return contract.join(';\n');
62
- };
63
-
64
- // we need to ensure that blocklet purchase factory does not change across changes
65
- const createNftFactoryItx = ({ meta, price, tokens, shares, issuers, serviceUrl }) => {
66
- const factoryOutput = getBlockletPurchaseTemplate(serviceUrl);
67
- const itx = {
68
- name: meta.title || meta.name,
69
- description: `Purchase NFT factory for blocklet ${meta.name}`,
70
- settlement: 'instant',
71
- limit: 0,
72
- trustedIssuers: issuers,
73
- input: {
74
- value: price,
75
- tokens: [...tokens],
76
- assets: [],
77
- variables: [],
78
- },
79
- output: {
80
- issuer: '{{ctx.issuer.id}}',
81
- parent: '{{ctx.factory}}',
82
- moniker: 'BlockletPurchaseNFT',
83
- readonly: true,
84
- transferrable: false,
85
- data: factoryOutput,
86
- },
87
- data: {
88
- type: 'json',
89
- value: {
90
- did: meta.did,
91
- url: joinURL(serviceUrl, `/blocklet/${meta.did}`),
92
- name: meta.name,
93
- },
94
- },
95
- hooks: [
96
- {
97
- name: 'mint',
98
- type: 'contract',
99
- hook: createShareContract({ price, tokens, shares }),
100
- },
101
- ],
102
- };
103
-
104
- isValidFactory(itx, true);
105
-
106
- itx.address = toFactoryAddress(itx);
107
- return itx;
108
- };
109
-
110
- module.exports = {
111
- isFreeBlocklet,
112
- createShareContract,
113
- createNftFactoryItx,
114
- };