@artblocks/abx-cli 0.1.0-alpha.14 → 0.1.0-alpha.16

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.
@@ -10,6 +10,13 @@ pragma solidity ^0.8.20;
10
10
  /// The tokenData merge rule: a token-scope value overrides the contract-scope one. The
11
11
  /// common pattern is `tokenParam` first, then `contractParam` as a fallback (see the
12
12
  /// `_param` helper in MyRenderer.sol).
13
+ ///
14
+ /// TWO READERS, PICK BY TYPE. Scalar types (`Bool`, `Select`, the ranges, `HexColor`,
15
+ /// `Timestamp`) live entirely in the `bytes32` — read them with `tokenParam` /
16
+ /// `contractParam`. The two payload types, **`Bytes` and `String`**, do NOT: their
17
+ /// `bytes32` is a keccak COMMITMENT (`valueIsHash == true`) and the content is fetched with
18
+ /// `tokenParamData` / `contractParamData` below. Reading a `Bytes` param with `tokenParam`
19
+ /// hands you a hash, not the artwork — that is the tell you want the data reader.
13
20
  interface IAbxParams {
14
21
  /// Returns the token-scope param: its bytes32 `value`, `valueIsHash` (true if it commits to
15
22
  /// off-chain bytes — a literal scalar like a seed/HexColor is false), and `isSet` (does it exist).
@@ -23,4 +30,14 @@ interface IAbxParams {
23
30
  external
24
31
  view
25
32
  returns (bytes32 value, bool valueIsHash, bool isSet);
33
+
34
+ /// @notice A `Bytes`/`String` token param's FULL content — the payload types' real reader.
35
+ /// Returns empty bytes for a literal scalar or an unset key, so an empty return is your
36
+ /// "fall back to a default" signal. When non-empty, `keccak256(returned bytes)` equals
37
+ /// the `value` that `tokenParam` reports — verify it if you want the commitment proof.
38
+ /// Up to ~24KB per key: enough to carry an actual artwork payload on-chain.
39
+ function tokenParamData(uint256 tokenId, bytes32 key) external view returns (bytes memory);
40
+
41
+ /// @notice The contract-scope (collection-wide) blob — the fallback when a token has none.
42
+ function contractParamData(bytes32 key) external view returns (bytes memory);
26
43
  }
@@ -13,15 +13,38 @@ contract MockParams is IAbxParams {
13
13
  mapping(uint256 => mapping(bytes32 => bool)) private ts;
14
14
  mapping(bytes32 => bytes32) private cv;
15
15
  mapping(bytes32 => bool) private cs;
16
+ // `Bytes`/`String` params: the bytes32 holds keccak(content), the content lives here.
17
+ mapping(uint256 => mapping(bytes32 => bytes)) private td;
18
+ mapping(bytes32 => bytes) private cd;
16
19
 
17
20
  function setToken(uint256 id, bytes32 key, bytes32 val) external { tv[id][key] = val; ts[id][key] = true; }
18
21
  function setContract(bytes32 key, bytes32 val) external { cv[key] = val; cs[key] = true; }
19
22
 
23
+ /// Set a payload-typed (`Bytes`/`String`) param the way the real contract does: the scalar slot
24
+ /// carries the keccak COMMITMENT and `valueIsHash` is true, so a renderer that reads the bytes32
25
+ /// gets a hash — the data reader is the only way to the content.
26
+ function setTokenData(uint256 id, bytes32 key, bytes memory content) external {
27
+ td[id][key] = content;
28
+ tv[id][key] = keccak256(content);
29
+ ts[id][key] = true;
30
+ }
31
+ function setContractData(bytes32 key, bytes memory content) external {
32
+ cd[key] = content;
33
+ cv[key] = keccak256(content);
34
+ cs[key] = true;
35
+ }
36
+
20
37
  function tokenParam(uint256 id, bytes32 key) external view returns (bytes32, bool, bool) {
21
- return (tv[id][key], false, ts[id][key]);
38
+ return (tv[id][key], td[id][key].length > 0, ts[id][key]);
22
39
  }
23
40
  function contractParam(bytes32 key) external view returns (bytes32, bool, bool) {
24
- return (cv[key], false, cs[key]);
41
+ return (cv[key], cd[key].length > 0, cs[key]);
42
+ }
43
+ function tokenParamData(uint256 id, bytes32 key) external view returns (bytes memory) {
44
+ return td[id][key];
45
+ }
46
+ function contractParamData(bytes32 key) external view returns (bytes memory) {
47
+ return cd[key];
25
48
  }
26
49
  }
27
50
 
@@ -107,4 +130,30 @@ contract MyRendererTest is Test {
107
130
  (, bytes memory data) = img.render(address(params), tokenId, IMAGE);
108
131
  assertTrue(data.length > 0);
109
132
  }
133
+
134
+ /// READING A PAYLOAD PARAM (`Bytes`/`String`) — the pattern for carrying an actual artwork
135
+ /// payload on-chain. The scalar reader hands you a keccak COMMITMENT with `valueIsHash == true`;
136
+ /// the content only comes from `tokenParamData`. If your renderer reads a `Bytes` param through
137
+ /// `tokenParam` it will draw from a hash and produce garbage, silently — hence this test.
138
+ function test_bytesParam_readViaDataReader() public {
139
+ bytes memory grid = hex"00112233445566778899aabbccddeeff";
140
+ params.setTokenData(0, "grid", grid);
141
+
142
+ // The scalar surface: a commitment, explicitly flagged as one — NOT the content.
143
+ (bytes32 value, bool valueIsHash, bool isSet) = IAbxParams(address(params)).tokenParam(0, "grid");
144
+ assertTrue(isSet);
145
+ assertTrue(valueIsHash, "a Bytes param reports valueIsHash: read the data instead");
146
+ assertEq(value, keccak256(grid));
147
+
148
+ // The data surface: the real bytes, verifiable against that commitment.
149
+ bytes memory got = IAbxParams(address(params)).tokenParamData(0, "grid");
150
+ assertEq(got, grid);
151
+ assertEq(keccak256(got), value, "content must match the on-chain commitment");
152
+ }
153
+
154
+ /// An unset payload param returns empty bytes — your "use a default" signal, never a revert.
155
+ function test_bytesParam_unsetIsEmpty() public view {
156
+ assertEq(IAbxParams(address(params)).tokenParamData(0, "grid").length, 0);
157
+ assertEq(IAbxParams(address(params)).contractParamData("grid").length, 0);
158
+ }
110
159
  }
package/dist/flags.d.ts CHANGED
@@ -19,6 +19,13 @@ export declare const REPEATABLE_FLAGS: ReadonlySet<string>;
19
19
  */
20
20
  export declare const GLOBAL_FLAGS: ReadonlySet<string>;
21
21
  export declare function parseFlags(args: string[]): Flags;
22
+ /**
23
+ * The bare (non-flag) arguments, with flag VALUES removed — the mirror of {@link parseFlags}, and
24
+ * deliberately next to it: the two must consume argv by the same rule or a flag's value looks like a
25
+ * positional. (Hand-rolling `args.filter(a => !a.startsWith('-'))` reads `--token 0` as a stray
26
+ * positional `0`, which is exactly the bug a stray-positional check is meant to catch.)
27
+ */
28
+ export declare function positionalArgs(args: string[]): string[];
22
29
  /**
23
30
  * The flag keys in `flags` that are NOT in `allowed` — for a non-fatal "unrecognized flag"
24
31
  * notice at a command's entry. {@link parseFlags} keeps any `--k` it sees, so a typo'd or
@@ -1 +1 @@
1
- {"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAEvD,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAuC,CAAC;AAEzF;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,MAAM,CAAgC,CAAC;AAE9E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAchD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAG9E"}
1
+ {"version":3,"file":"flags.d.ts","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AAEvD,8EAA8E;AAC9E,eAAO,MAAM,gBAAgB,EAAE,WAAW,CAAC,MAAM,CAAuC,CAAC;AAEzF;;;;GAIG;AACH,eAAO,MAAM,YAAY,EAAE,WAAW,CAAC,MAAM,CAAgC,CAAC;AAE9E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,KAAK,CAchD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAWvD;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAG9E"}
package/dist/flags.js CHANGED
@@ -25,6 +25,25 @@ export function parseFlags(args) {
25
25
  }
26
26
  return out;
27
27
  }
28
+ /**
29
+ * The bare (non-flag) arguments, with flag VALUES removed — the mirror of {@link parseFlags}, and
30
+ * deliberately next to it: the two must consume argv by the same rule or a flag's value looks like a
31
+ * positional. (Hand-rolling `args.filter(a => !a.startsWith('-'))` reads `--token 0` as a stray
32
+ * positional `0`, which is exactly the bug a stray-positional check is meant to catch.)
33
+ */
34
+ export function positionalArgs(args) {
35
+ const out = [];
36
+ for (let i = 0; i < args.length; i++) {
37
+ const a = args[i];
38
+ if (a.startsWith('--')) {
39
+ if (a.indexOf('=') === -1 && args[i + 1] && !args[i + 1].startsWith('--'))
40
+ i++; // this flag consumes the next token
41
+ continue;
42
+ }
43
+ out.push(a);
44
+ }
45
+ return out;
46
+ }
28
47
  /**
29
48
  * The flag keys in `flags` that are NOT in `allowed` — for a non-fatal "unrecognized flag"
30
49
  * notice at a command's entry. {@link parseFlags} keeps any `--k` it sees, so a typo'd or
package/dist/flags.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"flags.js","sourceRoot":"","sources":["../src/flags.ts"],"names":[],"mappings":"AAaA,8EAA8E;AAC9E,MAAM,CAAC,MAAM,gBAAgB,GAAwB,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;AAEzF;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAwB,IAAI,GAAG,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC;AAE9E,MAAM,UAAU,UAAU,CAAC,IAAc;IACvC,MAAM,GAAG,GAAU,EAAE,CAAC;IACtB,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,CAAS,EAAE,EAAE;QACnC,GAAG,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC,CAA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