@artblocks/abx-sdk 0.1.0-alpha.4 → 0.1.0-alpha.40

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 (159) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +130 -0
  3. package/dist/abi/generated.d.ts +8502 -129
  4. package/dist/abi/generated.d.ts.map +1 -1
  5. package/dist/abi/generated.js +40 -22
  6. package/dist/abi/generated.js.map +1 -1
  7. package/dist/abi/index.d.ts +2645 -168
  8. package/dist/abi/index.d.ts.map +1 -1
  9. package/dist/abi/index.js +34 -7
  10. package/dist/abi/index.js.map +1 -1
  11. package/dist/anchors.d.ts +325 -0
  12. package/dist/anchors.d.ts.map +1 -0
  13. package/dist/anchors.js +740 -0
  14. package/dist/anchors.js.map +1 -0
  15. package/dist/chain-support.d.ts +28 -0
  16. package/dist/chain-support.d.ts.map +1 -0
  17. package/dist/chain-support.js +65 -0
  18. package/dist/chain-support.js.map +1 -0
  19. package/dist/chain-support.json +60 -0
  20. package/dist/chains.d.ts +24 -10
  21. package/dist/chains.d.ts.map +1 -1
  22. package/dist/chains.js +51 -17
  23. package/dist/chains.js.map +1 -1
  24. package/dist/chunks.d.ts +162 -31
  25. package/dist/chunks.d.ts.map +1 -1
  26. package/dist/chunks.js +179 -14
  27. package/dist/chunks.js.map +1 -1
  28. package/dist/clients.d.ts +23 -11
  29. package/dist/clients.d.ts.map +1 -1
  30. package/dist/clients.js +17 -18
  31. package/dist/clients.js.map +1 -1
  32. package/dist/contract-generations.d.ts +58 -0
  33. package/dist/contract-generations.d.ts.map +1 -0
  34. package/dist/contract-generations.js +109 -0
  35. package/dist/contract-generations.js.map +1 -0
  36. package/dist/contract-generations.json +48 -0
  37. package/dist/create2.d.ts +84 -1
  38. package/dist/create2.d.ts.map +1 -1
  39. package/dist/create2.js +158 -2
  40. package/dist/create2.js.map +1 -1
  41. package/dist/creator-token.d.ts +132 -0
  42. package/dist/creator-token.d.ts.map +1 -0
  43. package/dist/creator-token.js +183 -0
  44. package/dist/creator-token.js.map +1 -0
  45. package/dist/deploy.d.ts +234 -14
  46. package/dist/deploy.d.ts.map +1 -1
  47. package/dist/deploy.js +289 -111
  48. package/dist/deploy.js.map +1 -1
  49. package/dist/deployments.d.ts +38 -5
  50. package/dist/deployments.d.ts.map +1 -1
  51. package/dist/deployments.js +156 -30
  52. package/dist/deployments.js.map +1 -1
  53. package/dist/deps.d.ts +123 -6
  54. package/dist/deps.d.ts.map +1 -1
  55. package/dist/deps.js +249 -7
  56. package/dist/deps.js.map +1 -1
  57. package/dist/env.d.ts +5 -4
  58. package/dist/env.d.ts.map +1 -1
  59. package/dist/env.js +20 -5
  60. package/dist/env.js.map +1 -1
  61. package/dist/errors.d.ts +109 -0
  62. package/dist/errors.d.ts.map +1 -0
  63. package/dist/errors.js +148 -0
  64. package/dist/errors.js.map +1 -0
  65. package/dist/execute.d.ts +118 -0
  66. package/dist/execute.d.ts.map +1 -0
  67. package/dist/execute.js +159 -0
  68. package/dist/execute.js.map +1 -0
  69. package/dist/gateways.d.ts +79 -0
  70. package/dist/gateways.d.ts.map +1 -0
  71. package/dist/gateways.js +156 -0
  72. package/dist/gateways.js.map +1 -0
  73. package/dist/generator-document.d.ts +57 -0
  74. package/dist/generator-document.d.ts.map +1 -0
  75. package/dist/generator-document.js +123 -0
  76. package/dist/generator-document.js.map +1 -0
  77. package/dist/generator.d.ts +44 -2
  78. package/dist/generator.d.ts.map +1 -1
  79. package/dist/generator.js +29 -0
  80. package/dist/generator.js.map +1 -1
  81. package/dist/index.d.ts +19 -3
  82. package/dist/index.d.ts.map +1 -1
  83. package/dist/index.js +19 -3
  84. package/dist/index.js.map +1 -1
  85. package/dist/inspect.d.ts +48 -0
  86. package/dist/inspect.d.ts.map +1 -0
  87. package/dist/inspect.js +295 -0
  88. package/dist/inspect.js.map +1 -0
  89. package/dist/migrate.d.ts +41 -0
  90. package/dist/migrate.d.ts.map +1 -0
  91. package/dist/migrate.js +142 -0
  92. package/dist/migrate.js.map +1 -0
  93. package/dist/mime.d.ts +11 -0
  94. package/dist/mime.d.ts.map +1 -0
  95. package/dist/mime.js +40 -0
  96. package/dist/mime.js.map +1 -0
  97. package/dist/node.d.ts +69 -0
  98. package/dist/node.d.ts.map +1 -0
  99. package/dist/node.js +92 -0
  100. package/dist/node.js.map +1 -0
  101. package/dist/onchain-uri.d.ts +110 -0
  102. package/dist/onchain-uri.d.ts.map +1 -0
  103. package/dist/onchain-uri.js +276 -0
  104. package/dist/onchain-uri.js.map +1 -0
  105. package/dist/ops.d.ts +507 -14
  106. package/dist/ops.d.ts.map +1 -1
  107. package/dist/ops.js +850 -34
  108. package/dist/ops.js.map +1 -1
  109. package/dist/policy.d.ts +57 -0
  110. package/dist/policy.d.ts.map +1 -0
  111. package/dist/policy.js +35 -0
  112. package/dist/policy.js.map +1 -0
  113. package/dist/probe.d.ts +58 -0
  114. package/dist/probe.d.ts.map +1 -1
  115. package/dist/probe.js +190 -9
  116. package/dist/probe.js.map +1 -1
  117. package/dist/reconstruct.d.ts +141 -3
  118. package/dist/reconstruct.d.ts.map +1 -1
  119. package/dist/reconstruct.js +479 -100
  120. package/dist/reconstruct.js.map +1 -1
  121. package/dist/resume.d.ts +147 -0
  122. package/dist/resume.d.ts.map +1 -0
  123. package/dist/resume.js +146 -0
  124. package/dist/resume.js.map +1 -0
  125. package/dist/script-chunks.d.ts +105 -0
  126. package/dist/script-chunks.d.ts.map +1 -0
  127. package/dist/script-chunks.js +158 -0
  128. package/dist/script-chunks.js.map +1 -0
  129. package/dist/service.d.ts +155 -9
  130. package/dist/service.d.ts.map +1 -1
  131. package/dist/service.js +103 -11
  132. package/dist/service.js.map +1 -1
  133. package/dist/spine.d.ts +47 -4
  134. package/dist/spine.d.ts.map +1 -1
  135. package/dist/spine.js +0 -0
  136. package/dist/spine.js.map +1 -1
  137. package/dist/staging.d.ts +139 -0
  138. package/dist/staging.d.ts.map +1 -0
  139. package/dist/staging.js +139 -0
  140. package/dist/staging.js.map +1 -0
  141. package/dist/token.d.ts +11 -1
  142. package/dist/token.d.ts.map +1 -1
  143. package/dist/token.js +32 -1
  144. package/dist/token.js.map +1 -1
  145. package/dist/tokendata.d.ts +63 -3
  146. package/dist/tokendata.d.ts.map +1 -1
  147. package/dist/tokendata.js +81 -19
  148. package/dist/tokendata.js.map +1 -1
  149. package/dist/tokens.d.ts +119 -0
  150. package/dist/tokens.d.ts.map +1 -0
  151. package/dist/tokens.js +317 -0
  152. package/dist/tokens.js.map +1 -0
  153. package/dist/types.d.ts +107 -5
  154. package/dist/types.d.ts.map +1 -1
  155. package/dist/util.d.ts +74 -0
  156. package/dist/util.d.ts.map +1 -0
  157. package/dist/util.js +106 -0
  158. package/dist/util.js.map +1 -0
  159. package/package.json +15 -6
@@ -1,5 +1,24 @@
1
- import { type Hex, type PublicClient } from 'viem';
2
- import type { MetadataField, ProjectState, TokenState } from './types.js';
1
+ import { type Address, type Hex, type PublicClient } from 'viem';
2
+ import type { MetadataField, ParamSchema, ParamValue, ProjectState, TokenState } from './types.js';
3
+ /**
4
+ * The canonical `tokenData` assembly — the off-chain serializer the spec names as
5
+ * authoritative (`site/content/docs/protocol/code-projects.mdx`). One flat object: the reserved
6
+ * coordinates + every param (contract ∪ token scope, token wins) + the augment hook's
7
+ * entries (augment wins per key), every value its canonical string (`chainId` alone is
8
+ * a number). The serialization is canonical because it is *hashed*: an effect's
9
+ * `inputsHash` commits to it, so this exact byte shape is what makes render outputs
10
+ * addressable and self-invalidating.
11
+ *
12
+ * Decode rules: a schema'd param decodes per its type (`Select` → the option string,
13
+ * `DecimalRange` ÷ 1e10, …); a schema-less literal stays the raw `bytes32` hex (a
14
+ * schema is what buys a human decode — `seed` is the canonical example); a data-backed
15
+ * value reads its blob (`String` → UTF-8, `Bytes`/schema-less → base64).
16
+ */
17
+ /** The tokenData coordinates — never enumerable as params (the on-chain params store excludes
18
+ * `seed` from its key lists, and the generator/renderer skip the other three defensively).
19
+ * Exported because every off-chain surface that enumerates params must exclude exactly this
20
+ * set: two lists that have to agree are one list. */
21
+ export declare const RESERVED_TOKEN_DATA_KEYS: ReadonlySet<string>;
3
22
  export interface TokenDataResult {
4
23
  /** The flat object (values are canonical strings; `chainId` is a number). */
5
24
  data: Record<string, string | number>;
@@ -30,7 +49,7 @@ export declare function buildTokenData(client: PublicClient | null, state: Proje
30
49
  /** The canonical serialization: lexicographically sorted keys, compact JSON, UTF-8. */
31
50
  export declare function canonicalTokenDataJson(data: Record<string, string | number>): string;
32
51
  /**
33
- * The effect run identity (`specs/protocol/effects.md`):
52
+ * The effect run identity (`site/content/docs/protocol/effects.mdx`):
34
53
  * `keccak256(contentDigest ‖ canonical tokenData ‖ environmentId)`. Deterministic across
35
54
  * producers and consumers — the resolver computes the CURRENT hash and looks up exactly
36
55
  * that artifact, so a param change re-addresses output and stale renders are never served.
@@ -47,4 +66,45 @@ export declare function contentDigestOf(state: ProjectState): Hex | null;
47
66
  * resolver) agree on where a run's artifacts live, over any storage backend.
48
67
  */
49
68
  export declare function renderArtifactKey(chainId: number, address: string, tokenId: string, hash: Hex, outputKey?: string, effectKey?: string): Hex;
69
+ /**
70
+ * The **bound** effect outputs — `site/content/docs/protocol/effects.mdx → Bound vs referenced`. An output is
71
+ * bound iff a binding stitches its *content* into the metadata JSON, which is what decides who holds
72
+ * its bytes:
73
+ *
74
+ * - **bound** (`render/traits` → `attributes`): the serving node holds the content, capped at
75
+ * {@link BOUND_ARTIFACT_MAX_BYTES} and servable only at the current settled `inputsHash`. A
76
+ * locator here cannot work — the content is assembled into `tokenURI`, so a locator would put a
77
+ * third-party fetch on the hottest read the resolver serves.
78
+ * - **referenced** (everything else — `render/image` projects a *URL*, a `video`/`model` only
79
+ * appears in the manifest): the PRODUCER holds the bytes and the node stores a locator. Holding
80
+ * these bytes buys a node no capability (it redirects either way) and costs it an object store.
81
+ *
82
+ * This is the wire rule for `POST /v1/effect-artifacts` in both directions: bytes for a referenced
83
+ * output and a locator for a bound one are each a `400`. Growing this set is an interface change —
84
+ * every serving node must be able to stitch a bound output's content.
85
+ */
86
+ export declare const BOUND_EFFECT_OUTPUTS: ReadonlySet<string>;
87
+ /** The cap a serving node MUST accept per bound output and MUST refuse above (~100× a real traits
88
+ * payload — generous for JSON, far too small to become blob storage). */
89
+ export declare const BOUND_ARTIFACT_MAX_BYTES: number;
90
+ /** Is `{effectKey}/{outputKey}` a bound output — content the serving node must hold and stitch?
91
+ * Unknown effects answer `false`: an output a node can't stitch is referenced by definition, since
92
+ * bytes it can't stitch are bytes it could only redirect to. */
93
+ export declare function isBoundOutput(effectKey: string, outputKey: string): boolean;
94
+ /** One param's canonical decode, with the blob's SIZE alongside. */
95
+ export interface DecodedParam {
96
+ /** The canonical string — what tokenData carries for this key. */
97
+ value: string;
98
+ /** A data-backed param's full content length in bytes; `null` for a literal, and for a blob
99
+ * that didn't read (the value degraded to the hash). Callers that bound inline content —
100
+ * the off-chain resolver's params handling (spec v8 removed the `abx_params` projection from both lanes), mirroring the renderer's former inline ceiling (removed with the projection) —
101
+ * measure THIS, the same length the chain measures. */
102
+ contentBytes: number | null;
103
+ }
104
+ /**
105
+ * The canonical per-param decode — the one implementation every off-chain surface shares
106
+ * (tokenData assembly here, `abx_params` in the resolver), so a value reads the same
107
+ * everywhere and stays byte-parallel with the on-chain generator and renderer.
108
+ */
109
+ export declare function decodeParam(client: PublicClient | null, token: Address, tokenId: string, p: ParamValue, tokenScope: boolean, schema: ParamSchema | undefined): Promise<DecodedParam>;
50
110
  //# sourceMappingURL=tokendata.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokendata.d.ts","sourceRoot":"","sources":["../src/tokendata.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,GAAG,EACR,KAAK,YAAY,EAClB,MAAM,MAAM,CAAC;AAGd,OAAO,KAAK,EAAC,aAAa,EAA2B,YAAY,EAAE,UAAU,EAAC,MAAM,YAAY,CAAC;AAuBjG,MAAM,WAAW,eAAe;IAC9B,6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B,GAAG,CAQL;AAED;wFACwF;AACxF,wBAAgB,eAAe,CAAC,KAAK,EAAE,YAAY,GAAG,GAAG,GAAG,IAAI,CAI/D;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,GAAG,EACT,SAAS,GAAE,MAAgB,EAC3B,SAAS,SAAW,GACnB,GAAG,CAIL;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,MAAM,CAA8B,CAAC;AAEpF;0EAC0E;AAC1E,eAAO,MAAM,wBAAwB,QAAY,CAAC;AAElD;;iEAEiE;AACjE,wBAAgB,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAE3E;AAID,oEAAoE;AACpE,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd;;;4DAGwD;IACxD,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAsB,WAAW,CAC/B,MAAM,EAAE,YAAY,GAAG,IAAI,EAC3B,KAAK,EAAE,OAAO,EACd,OAAO,EAAE,MAAM,EACf,CAAC,EAAE,UAAU,EACb,UAAU,EAAE,OAAO,EACnB,MAAM,EAAE,WAAW,GAAG,SAAS,GAC9B,OAAO,CAAC,YAAY,CAAC,CAsCvB"}
package/dist/tokendata.js CHANGED
@@ -1,9 +1,10 @@
1
- import { concat, hexToBytes, keccak256, parseAbi, stringToBytes, } from 'viem';
1
+ import { bytesToHex, concat, hexToBytes, keccak256, parseAbi, stringToBytes, } from 'viem';
2
2
  import { seriesCodeAbi } from './abi/index.js';
3
3
  import { decodeScalarParam } from './spine.js';
4
+ import { bytesToBase64 } from './util.js';
4
5
  /**
5
6
  * The canonical `tokenData` assembly — the off-chain serializer the spec names as
6
- * authoritative (`specs/protocol/code-projects.md`). One flat object: the reserved
7
+ * authoritative (`site/content/docs/protocol/code-projects.mdx`). One flat object: the reserved
7
8
  * coordinates + every param (contract ∪ token scope, token wins) + the augment hook's
8
9
  * entries (augment wins per key), every value its canonical string (`chainId` alone is
9
10
  * a number). The serialization is canonical because it is *hashed*: an effect's
@@ -15,7 +16,16 @@ import { decodeScalarParam } from './spine.js';
15
16
  * schema is what buys a human decode — `seed` is the canonical example); a data-backed
16
17
  * value reads its blob (`String` → UTF-8, `Bytes`/schema-less → base64).
17
18
  */
18
- const RESERVED = new Set(['chainId', 'contractAddress', 'tokenId', 'seed']);
19
+ /** The tokenData coordinates — never enumerable as params (the on-chain params store excludes
20
+ * `seed` from its key lists, and the generator/renderer skip the other three defensively).
21
+ * Exported because every off-chain surface that enumerates params must exclude exactly this
22
+ * set: two lists that have to agree are one list. */
23
+ export const RESERVED_TOKEN_DATA_KEYS = new Set([
24
+ 'chainId',
25
+ 'contractAddress',
26
+ 'tokenId',
27
+ 'seed',
28
+ ]);
19
29
  const augmentHookAbi = parseAbi([
20
30
  'function augmentTokenParams(address token, uint256 tokenId) view returns ((bytes32 key, string value)[])',
21
31
  ]);
@@ -60,9 +70,16 @@ export async function buildTokenData(client, state, token, opts = {}) {
60
70
  for (const p of token.params ?? [])
61
71
  merged.set(p.key, { p, tokenScope: true });
62
72
  for (const [key, { p, tokenScope }] of merged) {
63
- if (RESERVED.has(key) && key !== 'seed')
64
- continue; // coordinates win
65
- data[key] = await decodeParam(client, state.address, token.tokenId, p, tokenScope, schemas.get(key));
73
+ // Coordinates win. `seed` is the one reserved key allowed through — but only from TOKEN
74
+ // scope, matching the on-chain document exactly: `TokenDataLib.begin` reads
75
+ // `tokenParam(tokenId, "seed")` and never falls back to contract scope. Letting a
76
+ // contract-scope `seed` through here (the merged map holds both scopes) meant an unseeded
77
+ // token carried a seed off-chain that the on-chain generator did not have — the two lanes
78
+ // disagreeing about what a token's seed is, which is the one value they must agree on.
79
+ // Contract-scope `seed` remains settable on-chain by design; it simply is not a token's seed.
80
+ if (RESERVED_TOKEN_DATA_KEYS.has(key) && !(key === 'seed' && tokenScope))
81
+ continue;
82
+ data[key] = (await decodeParam(client, state.address, token.tokenId, p, tokenScope, schemas.get(key))).value;
66
83
  }
67
84
  // augment hook — last, wins per key (except the reserved coordinates). Skipped for the
68
85
  // SETTLED form (opts.augment false): live data belongs in the live view, never in the
@@ -78,7 +95,7 @@ export async function buildTokenData(client, state, token, opts = {}) {
78
95
  }));
79
96
  for (const e of entries) {
80
97
  const key = decodeBytes32Key(e.key);
81
- if (RESERVED.has(key))
98
+ if (RESERVED_TOKEN_DATA_KEYS.has(key))
82
99
  continue;
83
100
  data[key] = e.value;
84
101
  }
@@ -97,7 +114,7 @@ export function canonicalTokenDataJson(data) {
97
114
  return JSON.stringify(sorted);
98
115
  }
99
116
  /**
100
- * The effect run identity (`specs/protocol/effects.md`):
117
+ * The effect run identity (`site/content/docs/protocol/effects.mdx`):
101
118
  * `keccak256(contentDigest ‖ canonical tokenData ‖ environmentId)`. Deterministic across
102
119
  * producers and consumers — the resolver computes the CURRENT hash and looks up exactly
103
120
  * that artifact, so a param change re-addresses output and stale renders are never served.
@@ -127,20 +144,63 @@ export function contentDigestOf(state) {
127
144
  export function renderArtifactKey(chainId, address, tokenId, hash, outputKey = 'image', effectKey = 'render') {
128
145
  return keccak256(stringToBytes(`${chainId}/${address.toLowerCase()}/${tokenId}/${effectKey}/${hash}/${outputKey}`));
129
146
  }
130
- // ── internals ──────────────────────────────────────────────────────────────────
131
- async function decodeParam(client, token, tokenId, p, tokenScope, schema) {
147
+ /**
148
+ * The **bound** effect outputs — `site/content/docs/protocol/effects.mdx → Bound vs referenced`. An output is
149
+ * bound iff a binding stitches its *content* into the metadata JSON, which is what decides who holds
150
+ * its bytes:
151
+ *
152
+ * - **bound** (`render/traits` → `attributes`): the serving node holds the content, capped at
153
+ * {@link BOUND_ARTIFACT_MAX_BYTES} and servable only at the current settled `inputsHash`. A
154
+ * locator here cannot work — the content is assembled into `tokenURI`, so a locator would put a
155
+ * third-party fetch on the hottest read the resolver serves.
156
+ * - **referenced** (everything else — `render/image` projects a *URL*, a `video`/`model` only
157
+ * appears in the manifest): the PRODUCER holds the bytes and the node stores a locator. Holding
158
+ * these bytes buys a node no capability (it redirects either way) and costs it an object store.
159
+ *
160
+ * This is the wire rule for `POST /v1/effect-artifacts` in both directions: bytes for a referenced
161
+ * output and a locator for a bound one are each a `400`. Growing this set is an interface change —
162
+ * every serving node must be able to stitch a bound output's content.
163
+ */
164
+ export const BOUND_EFFECT_OUTPUTS = new Set(['render/traits']);
165
+ /** The cap a serving node MUST accept per bound output and MUST refuse above (~100× a real traits
166
+ * payload — generous for JSON, far too small to become blob storage). */
167
+ export const BOUND_ARTIFACT_MAX_BYTES = 64 * 1024;
168
+ /** Is `{effectKey}/{outputKey}` a bound output — content the serving node must hold and stitch?
169
+ * Unknown effects answer `false`: an output a node can't stitch is referenced by definition, since
170
+ * bytes it can't stitch are bytes it could only redirect to. */
171
+ export function isBoundOutput(effectKey, outputKey) {
172
+ return BOUND_EFFECT_OUTPUTS.has(`${effectKey}/${outputKey}`);
173
+ }
174
+ /**
175
+ * The canonical per-param decode — the one implementation every off-chain surface shares
176
+ * (tokenData assembly here, `abx_params` in the resolver), so a value reads the same
177
+ * everywhere and stays byte-parallel with the on-chain generator and renderer.
178
+ */
179
+ export async function decodeParam(client, token, tokenId, p, tokenScope, schema) {
180
+ const literal = (value) => ({ value, contentBytes: null });
132
181
  if (!p.valueIsHash) {
182
+ // `seed`'s wire format is INVARIANT: always the raw 32-byte hex, schema or no schema. The
183
+ // on-chain side (`TokenDataLib.begin`) emits `toHexString(seed, 32)` unconditionally and never
184
+ // consults a schema, so consulting one here would fork the work. Concretely: a project that
185
+ // lets an authorized party choose the seed value declares a `seed` schema (typically
186
+ // `Uint256Range` — note this is "pick the value", not a re-roll: the caller supplies it), and this
187
+ // decode would then hand the work `"777"` where the on-chain generator hands it
188
+ // `"0x00…0309"` — the same token rendering differently depending on which surface served it.
189
+ // A `seed` schema governs WHO may write it and within what bounds; it does not change how it
190
+ // reads. Checked before the schema branch for exactly that reason.
191
+ if (p.key === 'seed')
192
+ return literal(p.value);
133
193
  if (!schema)
134
- return p.key === 'seed' ? p.value : decodeTagLoose(p.value);
194
+ return literal(decodeTagLoose(p.value));
135
195
  if (schema.paramType === 'Select') {
136
196
  const idx = Number(BigInt(p.value));
137
- return schema.selectOptions[idx] ?? String(idx);
197
+ return literal(schema.selectOptions[idx] ?? String(idx));
138
198
  }
139
- return decodeScalarParam(schema.paramType, p.value);
199
+ return literal(decodeScalarParam(schema.paramType, p.value));
140
200
  }
141
201
  // data-backed: read the blob (token scope falls back to contract scope by construction)
142
202
  if (!client)
143
- return p.value; // best-effort floor: the hash itself
203
+ return literal(p.value); // best-effort floor: the hash itself
144
204
  try {
145
205
  const blob = (await client.readContract({
146
206
  address: token,
@@ -149,14 +209,16 @@ async function decodeParam(client, token, tokenId, p, tokenScope, schema) {
149
209
  args: tokenScope ? [BigInt(tokenId), keyToBytes32(p.key)] : [keyToBytes32(p.key)],
150
210
  }));
151
211
  const bytes = hexToBytes(blob);
152
- if (schema?.paramType === 'String')
153
- return new TextDecoder().decode(bytes);
154
- return Buffer.from(bytes).toString('base64'); // Bytes + schema-less: base64 at read
212
+ const value = schema?.paramType === 'String'
213
+ ? new TextDecoder().decode(bytes)
214
+ : bytesToBase64(bytes); // Bytes + schema-less: base64 at read
215
+ return { value, contentBytes: bytes.length };
155
216
  }
156
217
  catch {
157
- return p.value;
218
+ return literal(p.value);
158
219
  }
159
220
  }
221
+ // ── internals ──────────────────────────────────────────────────────────────────
160
222
  /** A readable-ASCII `bytes32` literal as its string (e.g. a `display.animation` value). */
161
223
  function decodeTagLoose(value) {
162
224
  const bytes = hexToBytes(value);
@@ -173,6 +235,6 @@ function decodeBytes32Key(key) {
173
235
  function keyToBytes32(key) {
174
236
  const bytes = new Uint8Array(32);
175
237
  bytes.set(stringToBytes(key).slice(0, 32));
176
- return `0x${Buffer.from(bytes).toString('hex')}`;
238
+ return bytesToHex(bytes);
177
239
  }
178
240
  //# sourceMappingURL=tokendata.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tokendata.js","sourceRoot":"","sources":["../src/tokendata.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,UAAU,EACV,SAAS,EACT,QAAQ,EACR,aAAa,GAId,MAAM,MAAM,CAAC;AACd,OAAO,EAAC,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAC,iBAAiB,EAAqB,MAAM,YAAY,CAAC;AAGjE;;;;;;;;;;;;;GAaG;AAEH,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC;AAE5E,MAAM,cAAc,GAAG,QAAQ,CAAC;IAC9B,0GAA0G;CAC3G,CAAC,CAAC;AASH,6FAA6F;AAC7F,MAAM,UAAU,SAAS,CAAC,KAAmB;IAC3C,OAAO,KAAK,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC;AACxE,CAAC;AAED,+FAA+F;AAC/F,MAAM,UAAU,aAAa,CAAC,KAAmB;IAC/C,OAAO,SAAS,CAAC,KAAK,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5E,CAAC;AAED,0FAA0F;AAC1F,MAAM,UAAU,mBAAmB,CAAC,KAAmB,EAAE,GAAW;IAClE,MAAM,CAAC,GAAG,KAAK,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;IAC3D,IAAI,CAAC,CAAC,IA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AAC,CAAC;IACpC,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC;IAClF,OAAO,OAAO,CAAC,CAAC,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AAC7D,CAAC;AAED,SAAS,gBAAgB,CAAC,GAAQ;IAChC,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,SAAS,YAAY,CAAC,GAAW;IAC/B,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,KAAK,CAAC,GAAG,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3C,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,119 @@
1
+ import { type Address, type Hex, type PublicClient } from 'viem';
2
+ export interface TokenRow {
3
+ tokenId: string;
4
+ /** `null` when `ownerOf` reverts — see {@link lifecycle}, which says WHY it reverted whenever the
5
+ * chain gives enough evidence to tell. Always `null` on an ERC-1155 edition: an id can have many
6
+ * concurrent holders, and *which* holders is not chain-enumerable outside the event log (that's
7
+ * the indexer's job, not a head read). */
8
+ owner: Address | null;
9
+ /**
10
+ * Does a token exist at this id right now — from head reads alone, no event log. The same words the
11
+ * fold uses ({@link TokenState.lifecycle}), plus `'unknown'` for the one case where a head read
12
+ * genuinely cannot say and the log can:
13
+ *
14
+ * - `'live'` — `ownerOf` answered (721), or `totalSupply(id) > 0` (edition).
15
+ * - `'burned'` — 721 only, terminal, and *decidable at head*: `nextTokenId` is a mint frontier that
16
+ * only ever rises, so an id BELOW it whose `ownerOf` reverts was minted and destroyed. A listing
17
+ * enumerates `0 … nextTokenId - 1`, so inside that range a revert IS a burn.
18
+ * - `'unminted'` — 721: at or past the frontier, never issued.
19
+ * - `'no-live-copies'` — editions: `totalSupply(id) == 0`. **The same word the fold uses for the
20
+ * same id**, deliberately: the fold could distinguish never-minted from fully-burned and does not,
21
+ * because the distinction has no consumer (the id can mint again either way). One field name, one
22
+ * value per id, whichever lane produced it.
23
+ * - `'unknown'` — a 1/1 exposes no `nextTokenId`, so a reverting `ownerOf` there is evidence of
24
+ * nothing: it is equally consistent with never-minted and with burned. The log settles it; a head
25
+ * read must not guess. This is the *only* remaining case, and it is why the word exists.
26
+ *
27
+ * The first draft had this lane answer `'unknown'` for an edition at zero while the fold answered
28
+ * `'burned'` for the same id — two values under one field name, which is the sibling-drift class
29
+ * this repo treats as a bug (see {@link TokenState.maxSupply}'s note). Splitting `'burned'` from
30
+ * `'no-live-copies'` is what makes the claim true instead of aspirational.
31
+ */
32
+ lifecycle: 'live' | 'burned' | 'unminted' | 'no-live-copies' | 'unknown';
33
+ /**
34
+ * The mint-time seed as the raw `bytes32` — exactly what `tokenData` carries. A schema is what
35
+ * buys a human decode and `seed` deliberately has none, so raw hex IS its canonical form.
36
+ * `null` ⇒ no seed set for this token (no seed source, or not minted).
37
+ */
38
+ seed: Hex | null;
39
+ /**
40
+ * Token-scope params, decoded to their canonical strings. Contract-scope params are listed once
41
+ * on {@link TokenListing.contractParams} rather than repeated per row; the work sees
42
+ * contract ∪ token with **token winning** (see `buildTokenData`, the canonical assembly).
43
+ */
44
+ params: Record<string, string>;
45
+ /** ERC-1155 editions only — this id's live supply (`totalSupply(id)`), as a decimal string.
46
+ * Absent on a 721 token. */
47
+ supply?: string;
48
+ /** ERC-1155 editions only — this id's current supply cap (`maxSupply(id)`; `"0"` reads as
49
+ * open/uncapped exactly like the contract's own convention). Absent on a 721 token. */
50
+ maxSupply?: string;
51
+ }
52
+ /** What an edition id's cap actually means. `closed` is the state the on-chain getter cannot express
53
+ * (`maxSupply(id)` returns `0` for both "never capped" and "deliberately closed") — see
54
+ * {@link editionCapOf}. */
55
+ export type EditionCap = {
56
+ kind: 'open';
57
+ } | {
58
+ kind: 'capped';
59
+ cap: string;
60
+ } | {
61
+ kind: 'closed';
62
+ };
63
+ /**
64
+ * Read an edition id's cap without re-deriving the rule at each call site — the derivation this
65
+ * protocol got wrong twice, in opposite directions: the on-chain getter overloads `0`, and the
66
+ * event fold used to miss the collection default entirely.
67
+ *
68
+ * Pass a folded {@link TokenState} (from `reconstructProject`) to get all three states. Pass a
69
+ * head-read {@link TokenRow}, which has no `maxSupplyOverridden` because a state read cannot know
70
+ * it, and a `'0'` cap reads `open` — the documented on-chain convention, and the reason
71
+ * `IAbxEditionSupply` tells an integrator rendering a buy button to consult the log.
72
+ *
73
+ * `null` ⇒ no cap information at all (a 721 token, or a row from a projection written before
74
+ * `DefaultMaxSupplySet` was folded).
75
+ */
76
+ export declare function editionCapOf(token: {
77
+ maxSupply?: string;
78
+ maxSupplyOverridden?: boolean;
79
+ }): EditionCap | null;
80
+ export interface TokenListing {
81
+ chainId: number;
82
+ address: Address;
83
+ /** Ids `0 … nextTokenId - 1` have been minted at some point. `null` on a token type with no
84
+ * sequential mint frontier — a 1/1 (always just token 0), or an ERC-1155 edition (ids are
85
+ * caller-named, not a cursor; see each row's own `supply`/`maxSupply` instead). */
86
+ nextTokenId: number | null;
87
+ /** Live supply (mints − burns) — differs from `nextTokenId` only if tokens were burned. `null`
88
+ * on an edition: there's no unconditional whole-contract total, only a per-id one (each row's
89
+ * `supply`). */
90
+ totalSupply: number | null;
91
+ /** How many tokens have been destroyed: `nextTokenId − totalSupply`, both of which the contract
92
+ * keeps (the frontier counts mints and never falls; the total counts live tokens). `null` when
93
+ * either is absent — a 1/1, or an edition, where burns are per id (each row's `supply`). */
94
+ burnedCount: number | null;
95
+ maxInvocations: number | null;
96
+ /**
97
+ * Whether the contract exposes the params surface at all. `false` for the image token types
98
+ * (they have no Params extension), in which case every row's `seed` is `null` and `params` is
99
+ * empty — correct, not a failed read.
100
+ */
101
+ hasParams: boolean;
102
+ /** Whether the contract exposes on-chain param *enumeration*. `false` on a project deployed
103
+ * before enumeration shipped: seeds still read (by name), but params can't be listed. */
104
+ hasParamEnumeration: boolean;
105
+ contractParams: Record<string, string>;
106
+ tokens: TokenRow[];
107
+ }
108
+ export interface ListTokensOptions {
109
+ /** Read only this many ids from `from` (default: all). */
110
+ limit?: number;
111
+ /** First token id to read (default 0). */
112
+ from?: number;
113
+ concurrency?: number;
114
+ /** Called after each token resolves — for a progress line on a large collection. */
115
+ onProgress?: (done: number, total: number) => void;
116
+ }
117
+ /** Every token's owner, seed, and params, straight from the contract. */
118
+ export declare function listTokens(client: PublicClient, address: Address, opts?: ListTokensOptions): Promise<TokenListing>;
119
+ //# sourceMappingURL=tokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../src/tokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,YAAY,EAAC,MAAM,MAAM,CAAC;AA+B5E,MAAM,WAAW,QAAQ;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB;;;+CAG2C;IAC3C,KAAK,EAAE,OAAO,GAAG,IAAI,CAAC;IACrB;;;;;;;;;;;;;;;;;;;;;;MAsBE;IACH,SAAS,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,GAAG,gBAAgB,GAAG,SAAS,CAAC;IACzE;;;;OAIG;IACH,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;IACjB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B;iCAC6B;IAC7B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;4FACwF;IACxF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;4BAE4B;AAC5B,MAAM,MAAM,UAAU,GAAG;IAAC,IAAI,EAAE,MAAM,CAAA;CAAC,GAAG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