@ocap/asset 1.30.26 → 1.31.0

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.
@@ -16,13 +16,14 @@ import mustache from "mustache";
16
16
  * browser/Worker bundles that stick to CBOR never drag the protobuf runtime
17
17
  * in via the aggregate did-util entry.
18
18
  */
19
- const enforceProtectedAssetFields = (rendered, output, factoryAddress) => {
19
+ const enforceProtectedAssetFields = (rendered, output, factoryAddress, issuerId) => {
20
20
  if (!rendered || typeof rendered !== "object") return rendered;
21
21
  if (output && typeof output === "object") {
22
22
  if (output.readonly !== void 0 && rendered.readonly !== output.readonly) throw new Error("Failed to mint asset from factory: protected field \"readonly\" cannot be overridden");
23
23
  if (output.transferrable !== void 0 && rendered.transferrable !== output.transferrable) throw new Error("Failed to mint asset from factory: protected field \"transferrable\" cannot be overridden");
24
24
  if (!("owner" in output) && "owner" in rendered) throw new Error("Failed to mint asset from factory: protected field \"owner\" cannot be injected");
25
- if (output.parent === "{{ctx.factory}}" && factoryAddress && rendered.parent !== factoryAddress) throw new Error("Failed to mint asset from factory: protected field \"parent\" cannot be overridden");
25
+ if (factoryAddress && rendered.parent !== void 0 && rendered.parent !== factoryAddress) throw new Error("Failed to mint asset from factory: protected field \"parent\" cannot be overridden");
26
+ if (issuerId && rendered.issuer !== void 0 && rendered.issuer !== issuerId && !(output.issuer === "{{ctx.issuer}}" && rendered.issuer === "[object Object]")) throw new Error("Failed to mint asset from factory: protected field \"issuer\" cannot be overridden");
26
27
  }
27
28
  return rendered;
28
29
  };
@@ -83,7 +84,7 @@ const renderMintAsset = ({ factory, inputs, owner, issuer }) => {
83
84
  owner,
84
85
  issuer
85
86
  }
86
- })), output, factoryAddress);
87
+ })), output, factoryAddress, typeof issuer === "object" && issuer !== null ? issuer.id || issuer.wallet?.address : void 0);
87
88
  };
88
89
  /**
89
90
  * Build the rendered asset + resolved issuer + resolved variables for a
@@ -161,7 +162,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
161
162
  };
162
163
  extra.signature = signature;
163
164
  try {
164
- asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress);
165
+ asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress, issuerObject.id);
165
166
  vcObj = getPath(asset, vcRootPath);
166
167
  debug("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
167
168
  await verify({
@@ -176,7 +177,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
176
177
  }
177
178
  }
178
179
  } else {
179
- asset = enforceProtectedAssetFields(render(template), output, factoryAddress);
180
+ asset = enforceProtectedAssetFields(render(template), output, factoryAddress, issuerObject.id);
180
181
  debug("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
181
182
  }
182
183
  return {
package/esm/validate.mjs CHANGED
@@ -35,6 +35,8 @@ const isValidFactory = (props) => {
35
35
  if (["tokens", "assets"].every((x) => isEmpty(value.input[x])) && value.input.value <= 0) throw new Error("Factory input should contain at least one token or asset");
36
36
  if (uniqBy(value.input.tokens, "address").length !== value.input.tokens.length) throw new Error("Factory token input should not contains duplicate address");
37
37
  if (uniq(value.input.assets).length !== value.input.assets.length) throw new Error("Factory asset input should not contains duplicate address");
38
+ if (value.output.parent !== "{{ctx.factory}}") throw new Error("Factory output.parent must be {{ctx.factory}}");
39
+ if (value.output.issuer !== "{{ctx.issuer.id}}" && value.output.issuer !== "{{ctx.issuer}}") throw new Error("Factory output.issuer must be {{ctx.issuer.id}}");
38
40
  try {
39
41
  const template = JSON.stringify(value.output, null, 2);
40
42
  const result = mustache.parse(template);
@@ -19,13 +19,14 @@ mustache = require_rolldown_runtime.__toESM(mustache);
19
19
  * browser/Worker bundles that stick to CBOR never drag the protobuf runtime
20
20
  * in via the aggregate did-util entry.
21
21
  */
22
- const enforceProtectedAssetFields = (rendered, output, factoryAddress) => {
22
+ const enforceProtectedAssetFields = (rendered, output, factoryAddress, issuerId) => {
23
23
  if (!rendered || typeof rendered !== "object") return rendered;
24
24
  if (output && typeof output === "object") {
25
25
  if (output.readonly !== void 0 && rendered.readonly !== output.readonly) throw new Error("Failed to mint asset from factory: protected field \"readonly\" cannot be overridden");
26
26
  if (output.transferrable !== void 0 && rendered.transferrable !== output.transferrable) throw new Error("Failed to mint asset from factory: protected field \"transferrable\" cannot be overridden");
27
27
  if (!("owner" in output) && "owner" in rendered) throw new Error("Failed to mint asset from factory: protected field \"owner\" cannot be injected");
28
- if (output.parent === "{{ctx.factory}}" && factoryAddress && rendered.parent !== factoryAddress) throw new Error("Failed to mint asset from factory: protected field \"parent\" cannot be overridden");
28
+ if (factoryAddress && rendered.parent !== void 0 && rendered.parent !== factoryAddress) throw new Error("Failed to mint asset from factory: protected field \"parent\" cannot be overridden");
29
+ if (issuerId && rendered.issuer !== void 0 && rendered.issuer !== issuerId && !(output.issuer === "{{ctx.issuer}}" && rendered.issuer === "[object Object]")) throw new Error("Failed to mint asset from factory: protected field \"issuer\" cannot be overridden");
29
30
  }
30
31
  return rendered;
31
32
  };
@@ -86,7 +87,7 @@ const renderMintAsset = ({ factory, inputs, owner, issuer }) => {
86
87
  owner,
87
88
  issuer
88
89
  }
89
- })), output, factoryAddress);
90
+ })), output, factoryAddress, typeof issuer === "object" && issuer !== null ? issuer.id || issuer.wallet?.address : void 0);
90
91
  };
91
92
  /**
92
93
  * Build the rendered asset + resolved issuer + resolved variables for a
@@ -164,7 +165,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
164
165
  };
165
166
  extra.signature = signature;
166
167
  try {
167
- asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress);
168
+ asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress, issuerObject.id);
168
169
  vcObj = getPath(asset, vcRootPath);
169
170
  debug$1("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
170
171
  await (0, _arcblock_vc.verify)({
@@ -179,7 +180,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
179
180
  }
180
181
  }
181
182
  } else {
182
- asset = enforceProtectedAssetFields(render(template), output, factoryAddress);
183
+ asset = enforceProtectedAssetFields(render(template), output, factoryAddress, issuerObject.id);
183
184
  debug$1("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
184
185
  }
185
186
  return {
package/lib/validate.cjs CHANGED
@@ -41,6 +41,8 @@ const isValidFactory = (props) => {
41
41
  if (["tokens", "assets"].every((x) => (0, lodash_isEmpty.default)(value.input[x])) && value.input.value <= 0) throw new Error("Factory input should contain at least one token or asset");
42
42
  if ((0, lodash_uniqBy.default)(value.input.tokens, "address").length !== value.input.tokens.length) throw new Error("Factory token input should not contains duplicate address");
43
43
  if ((0, lodash_uniq.default)(value.input.assets).length !== value.input.assets.length) throw new Error("Factory asset input should not contains duplicate address");
44
+ if (value.output.parent !== "{{ctx.factory}}") throw new Error("Factory output.parent must be {{ctx.factory}}");
45
+ if (value.output.issuer !== "{{ctx.issuer.id}}" && value.output.issuer !== "{{ctx.issuer}}") throw new Error("Factory output.issuer must be {{ctx.issuer.id}}");
44
46
  try {
45
47
  const template = JSON.stringify(value.output, null, 2);
46
48
  const result = mustache.default.parse(template);
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@ocap/asset",
3
3
  "description": "Utility to work with asset and factory on ArcBlock blockchain",
4
4
  "type": "module",
5
- "version": "1.30.26",
5
+ "version": "1.31.0",
6
6
  "author": {
7
7
  "name": "wangshijun",
8
8
  "email": "shijun@arcblock.io",
@@ -19,15 +19,15 @@
19
19
  "wangshijun <shijun@arcblock.io> (https://github.com/wangshijun)"
20
20
  ],
21
21
  "dependencies": {
22
- "@arcblock/did": "1.30.26",
23
- "@arcblock/did-util": "1.30.26",
24
- "@arcblock/validator": "1.30.26",
25
- "@arcblock/vc": "1.30.26",
26
- "@ocap/contract": "1.30.26",
27
- "@ocap/mcrypto": "1.30.26",
28
- "@ocap/types": "1.30.26",
29
- "@ocap/util": "1.30.26",
30
- "@ocap/wallet": "1.30.26",
22
+ "@arcblock/did": "1.31.0",
23
+ "@arcblock/did-util": "1.31.0",
24
+ "@arcblock/validator": "1.31.0",
25
+ "@arcblock/vc": "1.31.0",
26
+ "@ocap/contract": "1.31.0",
27
+ "@ocap/mcrypto": "1.31.0",
28
+ "@ocap/types": "1.31.0",
29
+ "@ocap/util": "1.31.0",
30
+ "@ocap/wallet": "1.31.0",
31
31
  "debug": "^4.4.3",
32
32
  "flat": "^5.0.2",
33
33
  "is-absolute-url": "^3.0.3",