@6529-collections/stream-sdk 0.0.0-stage → 0.1.0-bootstrap.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.
Files changed (148) hide show
  1. package/CHANGELOG.md +46 -0
  2. package/LICENSE +201 -0
  3. package/NOTICE +4 -0
  4. package/README.md +413 -2
  5. package/dist/actions/accounts.d.ts +58 -0
  6. package/dist/actions/accounts.js +73 -0
  7. package/dist/actions/content.d.ts +22 -0
  8. package/dist/actions/content.js +45 -0
  9. package/dist/actions/curated.d.ts +177 -0
  10. package/dist/actions/curated.js +279 -0
  11. package/dist/actions/editions.d.ts +100 -0
  12. package/dist/actions/editions.js +161 -0
  13. package/dist/actions/independent.d.ts +149 -0
  14. package/dist/actions/independent.js +274 -0
  15. package/dist/actions/money.d.ts +117 -0
  16. package/dist/actions/money.js +148 -0
  17. package/dist/actions/record.d.ts +144 -0
  18. package/dist/actions/record.js +229 -0
  19. package/dist/actions/sale.d.ts +82 -0
  20. package/dist/actions/sale.js +113 -0
  21. package/dist/actions/shared.d.ts +40 -0
  22. package/dist/actions/shared.js +70 -0
  23. package/dist/actions/vault.d.ts +58 -0
  24. package/dist/actions/vault.js +94 -0
  25. package/dist/constants.d.ts +130 -0
  26. package/dist/constants.js +65 -0
  27. package/dist/display.d.ts +31 -0
  28. package/dist/display.js +28 -0
  29. package/dist/encoding.d.ts +110 -0
  30. package/dist/encoding.js +138 -0
  31. package/dist/errors.d.ts +76 -0
  32. package/dist/errors.js +66 -0
  33. package/dist/files/fetch.d.ts +85 -0
  34. package/dist/files/fetch.js +208 -0
  35. package/dist/files/verify.d.ts +36 -0
  36. package/dist/files/verify.js +125 -0
  37. package/dist/generated/abis/AccessManager.d.ts +1125 -0
  38. package/dist/generated/abis/AccessManager.js +1471 -0
  39. package/dist/generated/abis/Accounts.d.ts +1568 -0
  40. package/dist/generated/abis/Accounts.js +2049 -0
  41. package/dist/generated/abis/ClaimRouter.d.ts +343 -0
  42. package/dist/generated/abis/ClaimRouter.js +452 -0
  43. package/dist/generated/abis/ConsolidationAdapter.d.ts +97 -0
  44. package/dist/generated/abis/ConsolidationAdapter.js +133 -0
  45. package/dist/generated/abis/ContentStore.d.ts +812 -0
  46. package/dist/generated/abis/ContentStore.js +1073 -0
  47. package/dist/generated/abis/EconomicsResolver.d.ts +586 -0
  48. package/dist/generated/abis/EconomicsResolver.js +769 -0
  49. package/dist/generated/abis/Eip712CurationVerifier.d.ts +304 -0
  50. package/dist/generated/abis/Eip712CurationVerifier.js +406 -0
  51. package/dist/generated/abis/EnglishAuction.d.ts +1435 -0
  52. package/dist/generated/abis/EnglishAuction.js +1865 -0
  53. package/dist/generated/abis/GovernedVault.d.ts +468 -0
  54. package/dist/generated/abis/GovernedVault.js +617 -0
  55. package/dist/generated/abis/IndependentEditionAuction.d.ts +2373 -0
  56. package/dist/generated/abis/IndependentEditionAuction.js +3076 -0
  57. package/dist/generated/abis/IndependentStream6529.d.ts +1408 -0
  58. package/dist/generated/abis/IndependentStream6529.js +1834 -0
  59. package/dist/generated/abis/IndependentStreamDeployer.d.ts +141 -0
  60. package/dist/generated/abis/IndependentStreamDeployer.js +188 -0
  61. package/dist/generated/abis/IndependentStreamEditions6529.d.ts +963 -0
  62. package/dist/generated/abis/IndependentStreamEditions6529.js +1253 -0
  63. package/dist/generated/abis/IndependentStreamRegistry.d.ts +1351 -0
  64. package/dist/generated/abis/IndependentStreamRegistry.js +1755 -0
  65. package/dist/generated/abis/PackageRegistry.d.ts +1205 -0
  66. package/dist/generated/abis/PackageRegistry.js +1573 -0
  67. package/dist/generated/abis/RevenueEscrow.d.ts +626 -0
  68. package/dist/generated/abis/RevenueEscrow.js +820 -0
  69. package/dist/generated/abis/SaleStarter.d.ts +48 -0
  70. package/dist/generated/abis/SaleStarter.js +67 -0
  71. package/dist/generated/abis/SepoliaOpenGate.d.ts +317 -0
  72. package/dist/generated/abis/SepoliaOpenGate.js +419 -0
  73. package/dist/generated/abis/SplitLedger.d.ts +1097 -0
  74. package/dist/generated/abis/SplitLedger.js +1438 -0
  75. package/dist/generated/abis/StatementLog.d.ts +958 -0
  76. package/dist/generated/abis/StatementLog.js +1248 -0
  77. package/dist/generated/abis/Stream6529.d.ts +1490 -0
  78. package/dist/generated/abis/Stream6529.js +1941 -0
  79. package/dist/generated/abis/StreamDirectory6529.d.ts +355 -0
  80. package/dist/generated/abis/StreamDirectory6529.js +468 -0
  81. package/dist/generated/abis/StreamEditions6529.d.ts +1240 -0
  82. package/dist/generated/abis/StreamEditions6529.js +1614 -0
  83. package/dist/generated/abis/StreamTerms.d.ts +312 -0
  84. package/dist/generated/abis/StreamTerms.js +409 -0
  85. package/dist/generated/abis/StreamWorkFacts6529.d.ts +810 -0
  86. package/dist/generated/abis/StreamWorkFacts6529.js +1049 -0
  87. package/dist/generated/abis/UniformEditionAuction.d.ts +2372 -0
  88. package/dist/generated/abis/UniformEditionAuction.js +3074 -0
  89. package/dist/generated/abis/WorkDelivery.d.ts +605 -0
  90. package/dist/generated/abis/WorkDelivery.js +786 -0
  91. package/dist/generated/abis/WorkRules.d.ts +1154 -0
  92. package/dist/generated/abis/WorkRules.js +1501 -0
  93. package/dist/generated/abis/index.d.ts +28 -0
  94. package/dist/generated/abis/index.js +31 -0
  95. package/dist/generated/instances.d.ts +7 -0
  96. package/dist/generated/instances.js +9 -0
  97. package/dist/generated/sepoliaR10.d.ts +1391 -0
  98. package/dist/generated/sepoliaR10.js +1545 -0
  99. package/dist/hashing/content.d.ts +42 -0
  100. package/dist/hashing/content.js +54 -0
  101. package/dist/hashing/ids.d.ts +67 -0
  102. package/dist/hashing/ids.js +73 -0
  103. package/dist/hashing/items.d.ts +30 -0
  104. package/dist/hashing/items.js +44 -0
  105. package/dist/hashing/packages.d.ts +35 -0
  106. package/dist/hashing/packages.js +76 -0
  107. package/dist/hashing/vault.d.ts +17 -0
  108. package/dist/hashing/vault.js +37 -0
  109. package/dist/hashing/workState.d.ts +31 -0
  110. package/dist/hashing/workState.js +37 -0
  111. package/dist/index.d.ts +44 -0
  112. package/dist/index.js +47 -0
  113. package/dist/instance.d.ts +236 -0
  114. package/dist/instance.js +99 -0
  115. package/dist/items.d.ts +85 -0
  116. package/dist/items.js +144 -0
  117. package/dist/reads/accounts.d.ts +86 -0
  118. package/dist/reads/accounts.js +121 -0
  119. package/dist/reads/chain.d.ts +54 -0
  120. package/dist/reads/chain.js +133 -0
  121. package/dist/reads/creation.d.ts +139 -0
  122. package/dist/reads/creation.js +256 -0
  123. package/dist/reads/editionSale.d.ts +120 -0
  124. package/dist/reads/editionSale.js +182 -0
  125. package/dist/reads/metadata.d.ts +195 -0
  126. package/dist/reads/metadata.js +191 -0
  127. package/dist/reads/money.d.ts +51 -0
  128. package/dist/reads/money.js +68 -0
  129. package/dist/reads/network.d.ts +137 -0
  130. package/dist/reads/network.js +157 -0
  131. package/dist/reads/sale.d.ts +94 -0
  132. package/dist/reads/sale.js +133 -0
  133. package/dist/reads/vault.d.ts +47 -0
  134. package/dist/reads/vault.js +75 -0
  135. package/dist/reads/work.d.ts +293 -0
  136. package/dist/reads/work.js +338 -0
  137. package/dist/reads/workPage.d.ts +197 -0
  138. package/dist/reads/workPage.js +169 -0
  139. package/dist/signing/messages.d.ts +679 -0
  140. package/dist/signing/messages.js +397 -0
  141. package/dist/testing.d.ts +17 -0
  142. package/dist/testing.js +18 -0
  143. package/dist/types.d.ts +167 -0
  144. package/dist/types.js +14 -0
  145. package/docs/publishing.md +54 -0
  146. package/docs/reference.md +335 -0
  147. package/docs/using-from-a-site.md +175 -0
  148. package/package.json +93 -4
@@ -0,0 +1,31 @@
1
+ /** How a page may show a verified file without giving the file power over the page. */
2
+ export interface DisplayAdvice {
3
+ /**
4
+ * - `"image"`: a raster image. Show it with `<img>` from a blob or data URL.
5
+ * - `"svg"`: an SVG. Show it ONLY with `<img>` (scripts in it then do not run). Never inline
6
+ * it into the page and never open it as a document from your own origin.
7
+ * - `"document"`: HTML or a script: active content. Show it ONLY in an `<iframe>` with the
8
+ * `sandbox` attribute and WITHOUT `allow-same-origin`, from a blob or `srcdoc`.
9
+ * - `"media"`: audio or video, for `<audio>` / `<video>`.
10
+ * - `"text"`: plain text or JSON. Show it as text, never as HTML.
11
+ * - `"download"`: anything else. Offer it as a download; do not render it.
12
+ */
13
+ readonly kind: "image" | "svg" | "document" | "media" | "text" | "download";
14
+ /** True for content that can run code if it is given the page's origin. */
15
+ readonly active: boolean;
16
+ /** The `sandbox` attribute to use for `"document"`; null otherwise. */
17
+ readonly iframeSandbox: string | null;
18
+ }
19
+ /**
20
+ * How to show a file of a given MIME type safely. "Verified" means the bytes are the ones the
21
+ * work commits to; it does not mean they are safe to put in your page. The content store
22
+ * accepts any type, including `image/svg+xml`, `text/html` and `text/javascript`, and those
23
+ * can run code. A page that inlines a verified SVG, sets it as `innerHTML`, or serves a
24
+ * verified HTML file from its own origin gives the artist's file the page's cookies and
25
+ * wallet connection.
26
+ *
27
+ * Contract: the MIME type is the one declared in the file's manifest
28
+ * ([`ContentStore.registerManifest`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol)),
29
+ * limited by the store to lowercase letters, digits and `+-._/`.
30
+ */
31
+ export declare function displayAdvice(mimeType: string): DisplayAdvice;
@@ -0,0 +1,28 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /**
3
+ * How to show a file of a given MIME type safely. "Verified" means the bytes are the ones the
4
+ * work commits to; it does not mean they are safe to put in your page. The content store
5
+ * accepts any type, including `image/svg+xml`, `text/html` and `text/javascript`, and those
6
+ * can run code. A page that inlines a verified SVG, sets it as `innerHTML`, or serves a
7
+ * verified HTML file from its own origin gives the artist's file the page's cookies and
8
+ * wallet connection.
9
+ *
10
+ * Contract: the MIME type is the one declared in the file's manifest
11
+ * ([`ContentStore.registerManifest`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol)),
12
+ * limited by the store to lowercase letters, digits and `+-._/`.
13
+ */
14
+ export function displayAdvice(mimeType) {
15
+ const type = mimeType.toLowerCase().split(";")[0]?.trim() ?? "";
16
+ if (type === "image/svg+xml")
17
+ return { kind: "svg", active: true, iframeSandbox: null };
18
+ if (type.startsWith("image/"))
19
+ return { kind: "image", active: false, iframeSandbox: null };
20
+ if (type === "text/html" || type === "application/xhtml+xml" || type.endsWith("javascript") || type.endsWith("ecmascript") || type.endsWith("+xml") || type === "application/xml" || type === "text/xml") {
21
+ return { kind: "document", active: true, iframeSandbox: "allow-scripts" };
22
+ }
23
+ if (type.startsWith("audio/") || type.startsWith("video/"))
24
+ return { kind: "media", active: false, iframeSandbox: null };
25
+ if (type === "application/json" || type.startsWith("text/"))
26
+ return { kind: "text", active: false, iframeSandbox: null };
27
+ return { kind: "download", active: false, iframeSandbox: null };
28
+ }
@@ -0,0 +1,110 @@
1
+ import { type Address, type Hex } from "viem";
2
+ import { type MediaFile, type PackageItem } from "./types.js";
3
+ /** What starts the sale of a curated 6529 Stream work. */
4
+ export interface StreamMintRequest {
5
+ readonly packageRoot: Hex;
6
+ readonly item: PackageItem;
7
+ /** The item's Merkle proof in the package; empty for a package of one item. */
8
+ readonly proof: readonly Hex[];
9
+ readonly move: {
10
+ readonly nonce: bigint;
11
+ readonly deadline: bigint;
12
+ /** `walletProof(wallet, signature)` of the lead artist's `MoveToStream` signature. */
13
+ readonly signature: Hex;
14
+ };
15
+ }
16
+ /**
17
+ * `abi.encode(StreamMintRequest)`: the `request` of `EnglishAuction.start`, `startWithBid`
18
+ * and `SaleStarter.start` for a curated work.
19
+ *
20
+ * Contract: decoded by [`PackageRegistry.authorize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
21
+ */
22
+ export declare function encodeStreamMintRequest(request: StreamMintRequest): Hex;
23
+ /** What starts the sale of an Independent Stream work. */
24
+ export interface IndependentMint {
25
+ readonly item: PackageItem;
26
+ readonly media: readonly MediaFile[];
27
+ /** One `walletProof` per collaborator, in party order after the lead artist; empty with none. */
28
+ readonly consents: readonly Hex[];
29
+ }
30
+ /**
31
+ * `abi.encode(IIndependentStream.IndependentMint)`: the `request` of `EnglishAuction.start`
32
+ * and `startWithBid` for an Independent Stream work.
33
+ *
34
+ * Contract: decoded by [`IndependentStreamRegistry.authorize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
35
+ */
36
+ export declare function encodeIndependentMint(mint: IndependentMint): Hex;
37
+ /**
38
+ * The `data` of `UniformEditionAuction.open` for a curated edition master:
39
+ * `abi.encode(item, packageRoot, proof)`.
40
+ *
41
+ * Contract: [`UniformEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
42
+ */
43
+ export declare function encodeCuratedEditionOpen(item: PackageItem, packageRoot: Hex, proof: readonly Hex[]): Hex;
44
+ /**
45
+ * The `data` of `IndependentEditionAuction.open` for an Independent Stream edition master:
46
+ * `abi.encode(item)`.
47
+ *
48
+ * Contract: [`IndependentEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentEditionAuction.sol).
49
+ */
50
+ export declare function encodeIndependentEditionOpen(item: PackageItem): Hex;
51
+ /** The constructor values of an artist's own 1/1 contract. */
52
+ export interface Independent721Config {
53
+ /** The ERC-721 name, also the name of the contract's one collection. */
54
+ readonly name: string;
55
+ readonly symbol: string;
56
+ /** `StreamWorkFacts6529` of the instance. */
57
+ readonly workFacts: Address;
58
+ /** `StreamDirectory6529` of the instance. */
59
+ readonly streamDirectory: Address;
60
+ /** The artist's ID: every work minted there names this artist. */
61
+ readonly artistId: bigint;
62
+ /** The first marketplace owner (ERC-173 `owner`): it edits the collection page on marketplaces, nothing else. */
63
+ readonly owner: Address;
64
+ /** The first renderer module, or the zero address for none. */
65
+ readonly renderer: Address;
66
+ }
67
+ /**
68
+ * The `config` of `IndependentStreamDeployer.deploy` for a 1/1 contract:
69
+ * `abi.encode(name, symbol, workFacts, streamDirectory, artistId, owner, renderer)`.
70
+ *
71
+ * Contract: the constructor of [`IndependentStream6529`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStream6529.sol).
72
+ */
73
+ export declare function encodeIndependent721Config(config: Independent721Config): Hex;
74
+ /** The constructor values of the editions contract that partners an artist's 1/1 contract. */
75
+ export interface IndependentEditionsConfig {
76
+ readonly name: string;
77
+ readonly symbol: string;
78
+ /** The artist's 1/1 contract. */
79
+ readonly master: Address;
80
+ readonly streamDirectory: Address;
81
+ readonly artistId: bigint;
82
+ readonly owner: Address;
83
+ }
84
+ /**
85
+ * The `config` of `IndependentStreamDeployer.deploy` for an editions contract:
86
+ * `abi.encode(name, symbol, master, streamDirectory, artistId, owner)`.
87
+ *
88
+ * Contract: the constructor of [`IndependentStreamEditions6529`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamEditions6529.sol).
89
+ */
90
+ export declare function encodeIndependentEditionsConfig(config: IndependentEditionsConfig): Hex;
91
+ /** How a work was minted, as the transaction that started its first sale carried it. */
92
+ export interface StartRequest {
93
+ /** The token contract the sale was started for. */
94
+ readonly token: Address;
95
+ readonly item: PackageItem;
96
+ /** The media list, where the call carried one (`SaleStarter.start`, or any Independent start). */
97
+ readonly media: readonly MediaFile[] | null;
98
+ /** Curated only: the package root and the item's proof. */
99
+ readonly packageRoot: Hex | null;
100
+ readonly proof: readonly Hex[] | null;
101
+ }
102
+ /**
103
+ * Reads the item out of the calldata of a transaction that started a first sale:
104
+ * `EnglishAuction.start`, `EnglishAuction.startWithBid` or `SaleStarter.start`. Returns null
105
+ * for any other call.
106
+ *
107
+ * What comes back is whatever the caller sent. Check it before use:
108
+ * `itemHash(result.item)` must equal `Stream6529.itemHashOf(tokenId)` (`readWorkItem` does).
109
+ */
110
+ export declare function decodeStartCalldata(input: Hex): StartRequest | null;
@@ -0,0 +1,138 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ import { decodeAbiParameters, decodeFunctionData, encodeAbiParameters } from "viem";
3
+ import { englishAuctionAbi } from "./generated/abis/EnglishAuction.js";
4
+ import { saleStarterAbi } from "./generated/abis/SaleStarter.js";
5
+ import { MEDIA_FILES_ABI, PACKAGE_ITEM_ABI } from "./types.js";
6
+ /**
7
+ * The byte encodings the contracts take as opaque `bytes`: start requests, edition `open`
8
+ * data and deployment configurations. The tests compare each against bytes the Solidity code
9
+ * produced and the real contracts accepted.
10
+ */
11
+ const STREAM_MINT_REQUEST = [
12
+ {
13
+ type: "tuple",
14
+ components: [
15
+ { name: "packageRoot", type: "bytes32" },
16
+ { ...PACKAGE_ITEM_ABI, name: "item" },
17
+ { name: "proof", type: "bytes32[]" },
18
+ {
19
+ name: "move",
20
+ type: "tuple",
21
+ components: [
22
+ { name: "nonce", type: "uint256" },
23
+ { name: "deadline", type: "uint64" },
24
+ { name: "signature", type: "bytes" },
25
+ ],
26
+ },
27
+ ],
28
+ },
29
+ ];
30
+ const INDEPENDENT_MINT = [
31
+ {
32
+ type: "tuple",
33
+ components: [
34
+ { ...PACKAGE_ITEM_ABI, name: "item" },
35
+ { ...MEDIA_FILES_ABI, name: "media" },
36
+ { name: "consents", type: "bytes[]" },
37
+ ],
38
+ },
39
+ ];
40
+ /**
41
+ * `abi.encode(StreamMintRequest)`: the `request` of `EnglishAuction.start`, `startWithBid`
42
+ * and `SaleStarter.start` for a curated work.
43
+ *
44
+ * Contract: decoded by [`PackageRegistry.authorize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/curation/PackageRegistry.sol).
45
+ */
46
+ export function encodeStreamMintRequest(request) {
47
+ return encodeAbiParameters(STREAM_MINT_REQUEST, [
48
+ { packageRoot: request.packageRoot, item: request.item, proof: request.proof, move: request.move },
49
+ ]);
50
+ }
51
+ /**
52
+ * `abi.encode(IIndependentStream.IndependentMint)`: the `request` of `EnglishAuction.start`
53
+ * and `startWithBid` for an Independent Stream work.
54
+ *
55
+ * Contract: decoded by [`IndependentStreamRegistry.authorize`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
56
+ */
57
+ export function encodeIndependentMint(mint) {
58
+ return encodeAbiParameters(INDEPENDENT_MINT, [{ item: mint.item, media: mint.media, consents: mint.consents }]);
59
+ }
60
+ /**
61
+ * The `data` of `UniformEditionAuction.open` for a curated edition master:
62
+ * `abi.encode(item, packageRoot, proof)`.
63
+ *
64
+ * Contract: [`UniformEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuction.sol).
65
+ */
66
+ export function encodeCuratedEditionOpen(item, packageRoot, proof) {
67
+ return encodeAbiParameters([PACKAGE_ITEM_ABI, { type: "bytes32" }, { type: "bytes32[]" }], [item, packageRoot, proof]);
68
+ }
69
+ /**
70
+ * The `data` of `IndependentEditionAuction.open` for an Independent Stream edition master:
71
+ * `abi.encode(item)`.
72
+ *
73
+ * Contract: [`IndependentEditionAuction.open`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentEditionAuction.sol).
74
+ */
75
+ export function encodeIndependentEditionOpen(item) {
76
+ return encodeAbiParameters([PACKAGE_ITEM_ABI], [item]);
77
+ }
78
+ /**
79
+ * The `config` of `IndependentStreamDeployer.deploy` for a 1/1 contract:
80
+ * `abi.encode(name, symbol, workFacts, streamDirectory, artistId, owner, renderer)`.
81
+ *
82
+ * Contract: the constructor of [`IndependentStream6529`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStream6529.sol).
83
+ */
84
+ export function encodeIndependent721Config(config) {
85
+ return encodeAbiParameters([{ type: "string" }, { type: "string" }, { type: "address" }, { type: "address" }, { type: "uint256" }, { type: "address" }, { type: "address" }], [config.name, config.symbol, config.workFacts, config.streamDirectory, config.artistId, config.owner, config.renderer]);
86
+ }
87
+ /**
88
+ * The `config` of `IndependentStreamDeployer.deploy` for an editions contract:
89
+ * `abi.encode(name, symbol, master, streamDirectory, artistId, owner)`.
90
+ *
91
+ * Contract: the constructor of [`IndependentStreamEditions6529`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamEditions6529.sol).
92
+ */
93
+ export function encodeIndependentEditionsConfig(config) {
94
+ return encodeAbiParameters([{ type: "string" }, { type: "string" }, { type: "address" }, { type: "address" }, { type: "uint256" }, { type: "address" }], [config.name, config.symbol, config.master, config.streamDirectory, config.artistId, config.owner]);
95
+ }
96
+ function decodeRequest(token, request, media) {
97
+ try {
98
+ const [mint] = decodeAbiParameters(STREAM_MINT_REQUEST, request);
99
+ return { token, item: mint.item, media, packageRoot: mint.packageRoot, proof: mint.proof };
100
+ }
101
+ catch {
102
+ // Not a curated request.
103
+ }
104
+ try {
105
+ const [mint] = decodeAbiParameters(INDEPENDENT_MINT, request);
106
+ return { token, item: mint.item, media: mint.media, packageRoot: null, proof: null };
107
+ }
108
+ catch {
109
+ return null;
110
+ }
111
+ }
112
+ /**
113
+ * Reads the item out of the calldata of a transaction that started a first sale:
114
+ * `EnglishAuction.start`, `EnglishAuction.startWithBid` or `SaleStarter.start`. Returns null
115
+ * for any other call.
116
+ *
117
+ * What comes back is whatever the caller sent. Check it before use:
118
+ * `itemHash(result.item)` must equal `Stream6529.itemHashOf(tokenId)` (`readWorkItem` does).
119
+ */
120
+ export function decodeStartCalldata(input) {
121
+ try {
122
+ const call = decodeFunctionData({ abi: englishAuctionAbi, data: input });
123
+ if (call.functionName === "start" || call.functionName === "startWithBid") {
124
+ return decodeRequest(call.args[0], call.args[1], null);
125
+ }
126
+ return null;
127
+ }
128
+ catch {
129
+ // Not an EnglishAuction call.
130
+ }
131
+ try {
132
+ const call = decodeFunctionData({ abi: saleStarterAbi, data: input });
133
+ return decodeRequest(call.args[1], call.args[2], call.args[3]);
134
+ }
135
+ catch {
136
+ return null;
137
+ }
138
+ }
@@ -0,0 +1,76 @@
1
+ /** Base class of every error this library throws itself. `code` is stable; the message is for people. */
2
+ export declare class StreamSdkError extends Error {
3
+ readonly code: StreamErrorCode;
4
+ constructor(code: StreamErrorCode, message: string, options?: ErrorOptions);
5
+ }
6
+ /** The client is connected to another chain than the instance lives on. */
7
+ export declare class WrongChainError extends StreamSdkError {
8
+ constructor(expected: number, actual: number);
9
+ }
10
+ /** The instance is not on a test network. This release works on test networks only. */
11
+ export declare class UnsupportedChainError extends StreamSdkError {
12
+ constructor(chainId: number);
13
+ }
14
+ /** The wallet client has no account to send or sign with. */
15
+ export declare class NoAccountError extends StreamSdkError {
16
+ constructor();
17
+ }
18
+ /** A file's bytes did not match what the chain commits to, or no source could serve it. */
19
+ export declare class FileVerificationError extends StreamSdkError {
20
+ /** What was tried, in order, and why each failed. */
21
+ readonly attempts: readonly string[];
22
+ constructor(message: string, attempts?: readonly string[]);
23
+ }
24
+ /**
25
+ * The RPC provider does not keep the old blocks a read needs. Some providers prune history
26
+ * (EIP-4444) and answer a request for older logs with error 4444. Reads that scan events need
27
+ * logs back to the instance's start block: use a provider that serves them.
28
+ */
29
+ export declare class HistoryUnavailableError extends StreamSdkError {
30
+ /** The first block of the range the provider refused. */
31
+ readonly fromBlock: bigint;
32
+ /** The last block of the range the provider refused. */
33
+ readonly toBlock: bigint;
34
+ constructor(fromBlock: bigint, toBlock: bigint, options?: ErrorOptions);
35
+ }
36
+ /** A step cannot run in the state the chain is in. `code` says which. */
37
+ export declare class FlowError extends StreamSdkError {
38
+ constructor(code: FlowErrorCode, message: string);
39
+ }
40
+ /** Every `code` an error of this library can carry. */
41
+ export type StreamErrorCode = FlowErrorCode
42
+ /** The client is on another chain than the instance. */
43
+ | "WRONG_CHAIN"
44
+ /** The instance is not on a test network. */
45
+ | "UNSUPPORTED_CHAIN"
46
+ /** The wallet client has no account. */
47
+ | "NO_ACCOUNT"
48
+ /** The RPC provider has pruned the old logs a read needs. */
49
+ | "HISTORY_UNAVAILABLE"
50
+ /** A file's bytes did not match, or no source served it. */
51
+ | "FILE_NOT_VERIFIED"
52
+ /** The token was never minted, or the address is not a Stream token contract. */
53
+ | "NO_SUCH_WORK"
54
+ /** The chain's clock, as the RPC reports it, is far from this computer's: no deadline is set from it. */
55
+ | "CLOCK_MISMATCH"
56
+ /** A transaction was mined but reverted. */
57
+ | "TRANSACTION_REVERTED";
58
+ export type FlowErrorCode =
59
+ /** The instance has no open gate, or the gate no longer holds its roles. */
60
+ "GATE_CLOSED"
61
+ /** The primary file is already minted as another work on this token contract. */
62
+ | "CONTENT_ALREADY_MINTED"
63
+ /** The package was revoked, or its signer's approvals were stopped. */
64
+ | "PACKAGE_REVOKED"
65
+ /** The artist has no unused move nonce in the range searched. */
66
+ | "NO_MOVE_NONCE"
67
+ /** The item is not approved, or was used already. */
68
+ | "ITEM_NOT_APPROVED"
69
+ /** The work has not been minted yet. */
70
+ | "NOT_STARTED"
71
+ /** A transaction succeeded but did not emit the event the step reads its result from. */
72
+ | "MISSING_EVENT"
73
+ /** A value the chain answered does not match what this library computed. */
74
+ | "MISMATCH"
75
+ /** The input cannot be used as given. */
76
+ | "INVALID_INPUT";
package/dist/errors.js ADDED
@@ -0,0 +1,66 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ /** Base class of every error this library throws itself. `code` is stable; the message is for people. */
3
+ export class StreamSdkError extends Error {
4
+ code;
5
+ constructor(code, message, options) {
6
+ super(message, options);
7
+ this.name = "StreamSdkError";
8
+ this.code = code;
9
+ }
10
+ }
11
+ /** The client is connected to another chain than the instance lives on. */
12
+ export class WrongChainError extends StreamSdkError {
13
+ constructor(expected, actual) {
14
+ super("WRONG_CHAIN", `The client is on chain ${actual}, but this instance is on chain ${expected}.`);
15
+ this.name = "WrongChainError";
16
+ }
17
+ }
18
+ /** The instance is not on a test network. This release works on test networks only. */
19
+ export class UnsupportedChainError extends StreamSdkError {
20
+ constructor(chainId) {
21
+ super("UNSUPPORTED_CHAIN", `Chain ${chainId} is not a test network this release supports.`);
22
+ this.name = "UnsupportedChainError";
23
+ }
24
+ }
25
+ /** The wallet client has no account to send or sign with. */
26
+ export class NoAccountError extends StreamSdkError {
27
+ constructor() {
28
+ super("NO_ACCOUNT", "The wallet client has no account. Create the client with an account.");
29
+ this.name = "NoAccountError";
30
+ }
31
+ }
32
+ /** A file's bytes did not match what the chain commits to, or no source could serve it. */
33
+ export class FileVerificationError extends StreamSdkError {
34
+ /** What was tried, in order, and why each failed. */
35
+ attempts;
36
+ constructor(message, attempts = []) {
37
+ super("FILE_NOT_VERIFIED", attempts.length > 0 ? `${message} Tried: ${attempts.join("; ")}` : message);
38
+ this.name = "FileVerificationError";
39
+ this.attempts = attempts;
40
+ }
41
+ }
42
+ /**
43
+ * The RPC provider does not keep the old blocks a read needs. Some providers prune history
44
+ * (EIP-4444) and answer a request for older logs with error 4444. Reads that scan events need
45
+ * logs back to the instance's start block: use a provider that serves them.
46
+ */
47
+ export class HistoryUnavailableError extends StreamSdkError {
48
+ /** The first block of the range the provider refused. */
49
+ fromBlock;
50
+ /** The last block of the range the provider refused. */
51
+ toBlock;
52
+ constructor(fromBlock, toBlock, options) {
53
+ super("HISTORY_UNAVAILABLE", `The RPC provider does not serve logs for blocks ${fromBlock} to ${toBlock}: it has pruned that history. ` +
54
+ "This read scans events from the instance's start block. Use an RPC provider that keeps full log history.", options);
55
+ this.name = "HistoryUnavailableError";
56
+ this.fromBlock = fromBlock;
57
+ this.toBlock = toBlock;
58
+ }
59
+ }
60
+ /** A step cannot run in the state the chain is in. `code` says which. */
61
+ export class FlowError extends StreamSdkError {
62
+ constructor(code, message) {
63
+ super(code, message);
64
+ this.name = "FlowError";
65
+ }
66
+ }
@@ -0,0 +1,85 @@
1
+ import { type Client, type Hex } from "viem";
2
+ import { type StreamInstance } from "../instance.js";
3
+ import { type WorkRef } from "../reads/work.js";
4
+ import { type ChainManifest } from "./verify.js";
5
+ /** Where a verified file came from. */
6
+ export type FileSource = "onchain" | "arweave" | "ipfs";
7
+ /** A file whose bytes were checked against what the chain commits to. */
8
+ export interface VerifiedFile {
9
+ readonly fileId: Hex;
10
+ /** The decoded media. */
11
+ readonly bytes: Uint8Array;
12
+ readonly mimeType: string;
13
+ /** SHA-256 of `bytes`, equal to the manifest's. */
14
+ readonly sha256: Hex;
15
+ readonly source: FileSource;
16
+ /** The locator the bytes were fetched from, for an off-chain source. */
17
+ readonly locator: string | null;
18
+ }
19
+ /** A registered copy of a file: `ar://<txid>` (kind 1) or `ipfs://<CIDv1>` (kind 2). */
20
+ export interface FileLocator {
21
+ readonly kind: number;
22
+ readonly uri: string;
23
+ }
24
+ export interface FetchFileOptions {
25
+ /** Copies outside the chain, as `readWorkFiles` lists them. Without any, only the chain is tried. */
26
+ readonly locators?: readonly FileLocator[];
27
+ /** Which sources to try, in order. Default: the chain, then Arweave, then IPFS. */
28
+ readonly sources?: readonly FileSource[];
29
+ /** Gateways to fetch off-chain copies through, in order. Their answers are verified, so they need no trust. */
30
+ readonly gateways?: {
31
+ readonly arweave?: readonly string[];
32
+ readonly ipfs?: readonly string[];
33
+ };
34
+ /** The largest file accepted, stored or decoded, in bytes. Default: 64 MB. */
35
+ readonly maxBytes?: number;
36
+ /** How long one gateway request may take, in milliseconds. Default: 30 seconds. */
37
+ readonly timeoutMs?: number;
38
+ /** A `fetch` to use instead of the global one. */
39
+ readonly fetch?: typeof fetch;
40
+ }
41
+ /**
42
+ * A file's manifest, read from the content store and proven against the file ID: the chunk
43
+ * hashes, length, encoding, MIME type and SHA-256 must hash to `fileId`. No answer can pass
44
+ * for a manifest that is not this file ID's, so everything `fetchFile` checks rests on the
45
+ * file ID. Whether that file ID belongs to a given work is another question, answered by
46
+ * whoever supplied it (for a work: the token contract, through your RPC).
47
+ *
48
+ * Contract: [`ContentStore.fileInfo`, `chunkHash`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol).
49
+ */
50
+ export declare function readManifest(client: Client, instance: StreamInstance, fileId: Hex): Promise<ChainManifest>;
51
+ /**
52
+ * Fetches a file and returns it only after its bytes were verified against its file ID.
53
+ *
54
+ * 1. The manifest is read from the content store and proven against `fileId` (`readManifest`).
55
+ * 2. From the chain: every chunk must match its keccak256 in the manifest, and the decoded
56
+ * media its SHA-256.
57
+ * 3. From Arweave or IPFS: the bytes a gateway answers must have the manifest's SHA-256 (or
58
+ * be the stored form, checked as in 2). A gateway that answers anything else is skipped.
59
+ *
60
+ * Sources are tried in order until one passes. If none does, a `FileVerificationError` lists
61
+ * what was tried. Bytes that do not match the file ID are never returned. The default
62
+ * gateways are public services: they see the address of whoever fetches.
63
+ *
64
+ * Contract: [`ContentStore.readChunk`, `isComplete`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol);
65
+ * locators from [`WorkDelivery.locators`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/stream/WorkDelivery.sol).
66
+ */
67
+ export declare function fetchFile(client: Client, instance: StreamInstance, fileId: Hex, options?: FetchFileOptions): Promise<VerifiedFile>;
68
+ /**
69
+ * Fetches one file of a work, verified: the primary file by default, or the file with
70
+ * `fileId`, which must be one of the work's files. The work's registered Arweave and IPFS
71
+ * copies are used when the chain does not hold the file.
72
+ *
73
+ * Contract: as `readWorkFiles` and `fetchFile`.
74
+ */
75
+ export declare function fetchWorkFile(client: Client, instance: StreamInstance, ref: WorkRef, options?: FetchFileOptions & {
76
+ readonly fileId?: Hex;
77
+ }): Promise<VerifiedFile>;
78
+ /**
79
+ * A work's descriptive record (JSON: name, description, artists and more), fetched and
80
+ * verified like any file, then parsed. The fields are whatever the artist wrote: treat them
81
+ * as untrusted text.
82
+ *
83
+ * Contract: `factsOf(token, tokenId).recordFileId` in [`StreamWorkFacts6529`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/core/StreamWorkFacts6529.sol).
84
+ */
85
+ export declare function fetchRecord(client: Client, instance: StreamInstance, recordFileId: Hex, options?: FetchFileOptions): Promise<unknown>;