@ocap/asset 1.31.1 → 1.31.2

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,12 +16,18 @@ 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, issuerId) => {
19
+ const FORBIDDEN_PATH_SEGMENTS = new Set([
20
+ "__proto__",
21
+ "constructor",
22
+ "prototype"
23
+ ]);
24
+ const enforceProtectedAssetFields = (rendered, output, factoryAddress, issuerId, owner) => {
20
25
  if (!rendered || typeof rendered !== "object") return rendered;
21
26
  if (output && typeof output === "object") {
22
27
  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
28
  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
29
  if (!("owner" in output) && "owner" in rendered) throw new Error("Failed to mint asset from factory: protected field \"owner\" cannot be injected");
30
+ if (owner !== void 0 && rendered.owner !== void 0 && rendered.owner !== owner) throw new Error("Failed to mint asset from factory: protected field \"owner\" cannot be overridden");
25
31
  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
32
  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");
27
33
  }
@@ -29,11 +35,14 @@ const enforceProtectedAssetFields = (rendered, output, factoryAddress, issuerId)
29
35
  };
30
36
  const getPath = (obj, path) => {
31
37
  if (obj == null) return void 0;
32
- return path.split(".").reduce((acc, k) => acc == null ? acc : acc[k], obj);
38
+ const parts = path.split(".");
39
+ for (const part of parts) if (FORBIDDEN_PATH_SEGMENTS.has(part)) throw new Error(`Invalid path segment "${part}" in asset template`);
40
+ return parts.reduce((acc, k) => acc == null ? acc : acc[k], obj);
33
41
  };
34
42
  const setPath = (obj, path, value) => {
35
43
  if (obj == null) return obj;
36
44
  const parts = path.split(".");
45
+ for (const part of parts) if (FORBIDDEN_PATH_SEGMENTS.has(part)) throw new Error(`Invalid path segment "${part}" in asset template`);
37
46
  let current = obj;
38
47
  for (let i = 0; i < parts.length - 1; i++) {
39
48
  const part = parts[i];
@@ -84,7 +93,7 @@ const renderMintAsset = ({ factory, inputs, owner, issuer }) => {
84
93
  owner,
85
94
  issuer
86
95
  }
87
- })), output, factoryAddress, typeof issuer === "object" && issuer !== null ? issuer.id || issuer.wallet?.address : void 0);
96
+ })), output, factoryAddress, typeof issuer === "object" && issuer !== null ? issuer.id || issuer.wallet?.address : void 0, owner);
88
97
  };
89
98
  /**
90
99
  * Build the rendered asset + resolved issuer + resolved variables for a
@@ -162,7 +171,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
162
171
  };
163
172
  extra.signature = signature;
164
173
  try {
165
- asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress, issuerObject.id);
174
+ asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress, issuerObject.id, owner);
166
175
  vcObj = getPath(asset, vcRootPath);
167
176
  debug("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
168
177
  await verify({
@@ -177,7 +186,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
177
186
  }
178
187
  }
179
188
  } else {
180
- asset = enforceProtectedAssetFields(render(template), output, factoryAddress, issuerObject.id);
189
+ asset = enforceProtectedAssetFields(render(template), output, factoryAddress, issuerObject.id, owner);
181
190
  debug("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
182
191
  }
183
192
  return {
@@ -19,12 +19,18 @@ 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, issuerId) => {
22
+ const FORBIDDEN_PATH_SEGMENTS = new Set([
23
+ "__proto__",
24
+ "constructor",
25
+ "prototype"
26
+ ]);
27
+ const enforceProtectedAssetFields = (rendered, output, factoryAddress, issuerId, owner) => {
23
28
  if (!rendered || typeof rendered !== "object") return rendered;
24
29
  if (output && typeof output === "object") {
25
30
  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
31
  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
32
  if (!("owner" in output) && "owner" in rendered) throw new Error("Failed to mint asset from factory: protected field \"owner\" cannot be injected");
33
+ if (owner !== void 0 && rendered.owner !== void 0 && rendered.owner !== owner) throw new Error("Failed to mint asset from factory: protected field \"owner\" cannot be overridden");
28
34
  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
35
  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");
30
36
  }
@@ -32,11 +38,14 @@ const enforceProtectedAssetFields = (rendered, output, factoryAddress, issuerId)
32
38
  };
33
39
  const getPath = (obj, path) => {
34
40
  if (obj == null) return void 0;
35
- return path.split(".").reduce((acc, k) => acc == null ? acc : acc[k], obj);
41
+ const parts = path.split(".");
42
+ for (const part of parts) if (FORBIDDEN_PATH_SEGMENTS.has(part)) throw new Error(`Invalid path segment "${part}" in asset template`);
43
+ return parts.reduce((acc, k) => acc == null ? acc : acc[k], obj);
36
44
  };
37
45
  const setPath = (obj, path, value) => {
38
46
  if (obj == null) return obj;
39
47
  const parts = path.split(".");
48
+ for (const part of parts) if (FORBIDDEN_PATH_SEGMENTS.has(part)) throw new Error(`Invalid path segment "${part}" in asset template`);
40
49
  let current = obj;
41
50
  for (let i = 0; i < parts.length - 1; i++) {
42
51
  const part = parts[i];
@@ -87,7 +96,7 @@ const renderMintAsset = ({ factory, inputs, owner, issuer }) => {
87
96
  owner,
88
97
  issuer
89
98
  }
90
- })), output, factoryAddress, typeof issuer === "object" && issuer !== null ? issuer.id || issuer.wallet?.address : void 0);
99
+ })), output, factoryAddress, typeof issuer === "object" && issuer !== null ? issuer.id || issuer.wallet?.address : void 0, owner);
91
100
  };
92
101
  /**
93
102
  * Build the rendered asset + resolved issuer + resolved variables for a
@@ -165,7 +174,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
165
174
  };
166
175
  extra.signature = signature;
167
176
  try {
168
- asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress, issuerObject.id);
177
+ asset = enforceProtectedAssetFields(render(structuredClone(output)), output, factoryAddress, issuerObject.id, owner);
169
178
  vcObj = getPath(asset, vcRootPath);
170
179
  debug$1("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
171
180
  await (0, _arcblock_vc.verify)({
@@ -180,7 +189,7 @@ const preparePreMintAsset = async ({ factory, inputs, owner, issuer }) => {
180
189
  }
181
190
  }
182
191
  } else {
183
- asset = enforceProtectedAssetFields(render(template), output, factoryAddress, issuerObject.id);
192
+ asset = enforceProtectedAssetFields(render(template), output, factoryAddress, issuerObject.id, owner);
184
193
  debug$1("preparePreMintAsset.result", JSON.stringify(asset, null, 2));
185
194
  }
186
195
  return {
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.31.1",
5
+ "version": "1.31.2",
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.31.1",
23
- "@arcblock/did-util": "1.31.1",
24
- "@arcblock/validator": "1.31.1",
25
- "@arcblock/vc": "1.31.1",
26
- "@ocap/contract": "1.31.1",
27
- "@ocap/mcrypto": "1.31.1",
28
- "@ocap/types": "1.31.1",
29
- "@ocap/util": "1.31.1",
30
- "@ocap/wallet": "1.31.1",
22
+ "@arcblock/did": "1.31.2",
23
+ "@arcblock/did-util": "1.31.2",
24
+ "@arcblock/validator": "1.31.2",
25
+ "@arcblock/vc": "1.31.2",
26
+ "@ocap/contract": "1.31.2",
27
+ "@ocap/mcrypto": "1.31.2",
28
+ "@ocap/types": "1.31.2",
29
+ "@ocap/util": "1.31.2",
30
+ "@ocap/wallet": "1.31.2",
31
31
  "debug": "^4.4.3",
32
32
  "flat": "^5.0.2",
33
33
  "is-absolute-url": "^3.0.3",