@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.
- package/CHANGELOG.md +46 -0
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +413 -2
- package/dist/actions/accounts.d.ts +58 -0
- package/dist/actions/accounts.js +73 -0
- package/dist/actions/content.d.ts +22 -0
- package/dist/actions/content.js +45 -0
- package/dist/actions/curated.d.ts +177 -0
- package/dist/actions/curated.js +279 -0
- package/dist/actions/editions.d.ts +100 -0
- package/dist/actions/editions.js +161 -0
- package/dist/actions/independent.d.ts +149 -0
- package/dist/actions/independent.js +274 -0
- package/dist/actions/money.d.ts +117 -0
- package/dist/actions/money.js +148 -0
- package/dist/actions/record.d.ts +144 -0
- package/dist/actions/record.js +229 -0
- package/dist/actions/sale.d.ts +82 -0
- package/dist/actions/sale.js +113 -0
- package/dist/actions/shared.d.ts +40 -0
- package/dist/actions/shared.js +70 -0
- package/dist/actions/vault.d.ts +58 -0
- package/dist/actions/vault.js +94 -0
- package/dist/constants.d.ts +130 -0
- package/dist/constants.js +65 -0
- package/dist/display.d.ts +31 -0
- package/dist/display.js +28 -0
- package/dist/encoding.d.ts +110 -0
- package/dist/encoding.js +138 -0
- package/dist/errors.d.ts +76 -0
- package/dist/errors.js +66 -0
- package/dist/files/fetch.d.ts +85 -0
- package/dist/files/fetch.js +208 -0
- package/dist/files/verify.d.ts +36 -0
- package/dist/files/verify.js +125 -0
- package/dist/generated/abis/AccessManager.d.ts +1125 -0
- package/dist/generated/abis/AccessManager.js +1471 -0
- package/dist/generated/abis/Accounts.d.ts +1568 -0
- package/dist/generated/abis/Accounts.js +2049 -0
- package/dist/generated/abis/ClaimRouter.d.ts +343 -0
- package/dist/generated/abis/ClaimRouter.js +452 -0
- package/dist/generated/abis/ConsolidationAdapter.d.ts +97 -0
- package/dist/generated/abis/ConsolidationAdapter.js +133 -0
- package/dist/generated/abis/ContentStore.d.ts +812 -0
- package/dist/generated/abis/ContentStore.js +1073 -0
- package/dist/generated/abis/EconomicsResolver.d.ts +586 -0
- package/dist/generated/abis/EconomicsResolver.js +769 -0
- package/dist/generated/abis/Eip712CurationVerifier.d.ts +304 -0
- package/dist/generated/abis/Eip712CurationVerifier.js +406 -0
- package/dist/generated/abis/EnglishAuction.d.ts +1435 -0
- package/dist/generated/abis/EnglishAuction.js +1865 -0
- package/dist/generated/abis/GovernedVault.d.ts +468 -0
- package/dist/generated/abis/GovernedVault.js +617 -0
- package/dist/generated/abis/IndependentEditionAuction.d.ts +2373 -0
- package/dist/generated/abis/IndependentEditionAuction.js +3076 -0
- package/dist/generated/abis/IndependentStream6529.d.ts +1408 -0
- package/dist/generated/abis/IndependentStream6529.js +1834 -0
- package/dist/generated/abis/IndependentStreamDeployer.d.ts +141 -0
- package/dist/generated/abis/IndependentStreamDeployer.js +188 -0
- package/dist/generated/abis/IndependentStreamEditions6529.d.ts +963 -0
- package/dist/generated/abis/IndependentStreamEditions6529.js +1253 -0
- package/dist/generated/abis/IndependentStreamRegistry.d.ts +1351 -0
- package/dist/generated/abis/IndependentStreamRegistry.js +1755 -0
- package/dist/generated/abis/PackageRegistry.d.ts +1205 -0
- package/dist/generated/abis/PackageRegistry.js +1573 -0
- package/dist/generated/abis/RevenueEscrow.d.ts +626 -0
- package/dist/generated/abis/RevenueEscrow.js +820 -0
- package/dist/generated/abis/SaleStarter.d.ts +48 -0
- package/dist/generated/abis/SaleStarter.js +67 -0
- package/dist/generated/abis/SepoliaOpenGate.d.ts +317 -0
- package/dist/generated/abis/SepoliaOpenGate.js +419 -0
- package/dist/generated/abis/SplitLedger.d.ts +1097 -0
- package/dist/generated/abis/SplitLedger.js +1438 -0
- package/dist/generated/abis/StatementLog.d.ts +958 -0
- package/dist/generated/abis/StatementLog.js +1248 -0
- package/dist/generated/abis/Stream6529.d.ts +1490 -0
- package/dist/generated/abis/Stream6529.js +1941 -0
- package/dist/generated/abis/StreamDirectory6529.d.ts +355 -0
- package/dist/generated/abis/StreamDirectory6529.js +468 -0
- package/dist/generated/abis/StreamEditions6529.d.ts +1240 -0
- package/dist/generated/abis/StreamEditions6529.js +1614 -0
- package/dist/generated/abis/StreamTerms.d.ts +312 -0
- package/dist/generated/abis/StreamTerms.js +409 -0
- package/dist/generated/abis/StreamWorkFacts6529.d.ts +810 -0
- package/dist/generated/abis/StreamWorkFacts6529.js +1049 -0
- package/dist/generated/abis/UniformEditionAuction.d.ts +2372 -0
- package/dist/generated/abis/UniformEditionAuction.js +3074 -0
- package/dist/generated/abis/WorkDelivery.d.ts +605 -0
- package/dist/generated/abis/WorkDelivery.js +786 -0
- package/dist/generated/abis/WorkRules.d.ts +1154 -0
- package/dist/generated/abis/WorkRules.js +1501 -0
- package/dist/generated/abis/index.d.ts +28 -0
- package/dist/generated/abis/index.js +31 -0
- package/dist/generated/instances.d.ts +7 -0
- package/dist/generated/instances.js +9 -0
- package/dist/generated/sepoliaR10.d.ts +1391 -0
- package/dist/generated/sepoliaR10.js +1545 -0
- package/dist/hashing/content.d.ts +42 -0
- package/dist/hashing/content.js +54 -0
- package/dist/hashing/ids.d.ts +67 -0
- package/dist/hashing/ids.js +73 -0
- package/dist/hashing/items.d.ts +30 -0
- package/dist/hashing/items.js +44 -0
- package/dist/hashing/packages.d.ts +35 -0
- package/dist/hashing/packages.js +76 -0
- package/dist/hashing/vault.d.ts +17 -0
- package/dist/hashing/vault.js +37 -0
- package/dist/hashing/workState.d.ts +31 -0
- package/dist/hashing/workState.js +37 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +47 -0
- package/dist/instance.d.ts +236 -0
- package/dist/instance.js +99 -0
- package/dist/items.d.ts +85 -0
- package/dist/items.js +144 -0
- package/dist/reads/accounts.d.ts +86 -0
- package/dist/reads/accounts.js +121 -0
- package/dist/reads/chain.d.ts +54 -0
- package/dist/reads/chain.js +133 -0
- package/dist/reads/creation.d.ts +139 -0
- package/dist/reads/creation.js +256 -0
- package/dist/reads/editionSale.d.ts +120 -0
- package/dist/reads/editionSale.js +182 -0
- package/dist/reads/metadata.d.ts +195 -0
- package/dist/reads/metadata.js +191 -0
- package/dist/reads/money.d.ts +51 -0
- package/dist/reads/money.js +68 -0
- package/dist/reads/network.d.ts +137 -0
- package/dist/reads/network.js +157 -0
- package/dist/reads/sale.d.ts +94 -0
- package/dist/reads/sale.js +133 -0
- package/dist/reads/vault.d.ts +47 -0
- package/dist/reads/vault.js +75 -0
- package/dist/reads/work.d.ts +293 -0
- package/dist/reads/work.js +338 -0
- package/dist/reads/workPage.d.ts +197 -0
- package/dist/reads/workPage.js +169 -0
- package/dist/signing/messages.d.ts +679 -0
- package/dist/signing/messages.js +397 -0
- package/dist/testing.d.ts +17 -0
- package/dist/testing.js +18 -0
- package/dist/types.d.ts +167 -0
- package/dist/types.js +14 -0
- package/docs/publishing.md +54 -0
- package/docs/reference.md +335 -0
- package/docs/using-from-a-site.md +175 -0
- package/package.json +93 -4
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import type { Address, Client, Hex } from "viem";
|
|
2
|
+
import { type DisplayAdvice } from "../display.js";
|
|
3
|
+
import { type FetchFileOptions, type FileSource } from "../files/fetch.js";
|
|
4
|
+
import { type StreamInstance } from "../instance.js";
|
|
5
|
+
import type { PackageItem } from "../types.js";
|
|
6
|
+
import type { LogScanOptions } from "./chain.js";
|
|
7
|
+
import { type EditionSale } from "./editionSale.js";
|
|
8
|
+
import { type Edition, type TokenMetadata, type WorkRecord } from "./metadata.js";
|
|
9
|
+
import { type Sale, type SaleHistory } from "./sale.js";
|
|
10
|
+
import { type RoyaltyVault } from "./vault.js";
|
|
11
|
+
import { type Split, type Work, type WorkFile, type WorkMint } from "./work.js";
|
|
12
|
+
/** Whether a file's bytes were fetched and checked. */
|
|
13
|
+
export type FileCheck =
|
|
14
|
+
/** Fetched, and every byte checked against the file ID and its SHA-256. */
|
|
15
|
+
{
|
|
16
|
+
readonly status: "verified";
|
|
17
|
+
readonly source: FileSource;
|
|
18
|
+
readonly locator: string | null;
|
|
19
|
+
}
|
|
20
|
+
/** No source served bytes that match. `attempts` says what was tried. */
|
|
21
|
+
| {
|
|
22
|
+
readonly status: "unavailable";
|
|
23
|
+
readonly attempts: readonly string[];
|
|
24
|
+
}
|
|
25
|
+
/** Not fetched, by the options given. */
|
|
26
|
+
| {
|
|
27
|
+
readonly status: "notFetched";
|
|
28
|
+
};
|
|
29
|
+
/** One file of a work, with its bytes when they were fetched and verified. */
|
|
30
|
+
export interface WorkPageFile extends WorkFile {
|
|
31
|
+
readonly check: FileCheck;
|
|
32
|
+
/** The decoded media, present only with `check.status === "verified"`. */
|
|
33
|
+
readonly bytes: Uint8Array | null;
|
|
34
|
+
/** How to show a file of this type without giving it power over the page (`displayAdvice`). */
|
|
35
|
+
readonly display: DisplayAdvice;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Where a fact on the page comes from.
|
|
39
|
+
*
|
|
40
|
+
* - `"contract"`: read from a contract of the instance: its name, its address, and the
|
|
41
|
+
* functions or events read.
|
|
42
|
+
* - `"transaction"`: decoded from the input of one transaction (the item, from the
|
|
43
|
+
* transaction that started the first sale). `transactionHash` is that transaction;
|
|
44
|
+
* `contract` and `address` are the contract it called.
|
|
45
|
+
*
|
|
46
|
+
* Every kind has `contract`, `address` and `reads`, so code that shows only those keeps working.
|
|
47
|
+
*/
|
|
48
|
+
export type FactSource = {
|
|
49
|
+
readonly kind: "contract";
|
|
50
|
+
readonly contract: string;
|
|
51
|
+
readonly address: Address;
|
|
52
|
+
readonly reads: string;
|
|
53
|
+
} | {
|
|
54
|
+
readonly kind: "transaction";
|
|
55
|
+
readonly transactionHash: Hex;
|
|
56
|
+
readonly contract: string;
|
|
57
|
+
readonly address: Address;
|
|
58
|
+
readonly reads: string;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* What a page about one work shows, each part read from the chain and checked against the
|
|
62
|
+
* hashes the token contract stores. See "What verified means" in the README: the checks are
|
|
63
|
+
* relative to what your RPC reports the chain to hold.
|
|
64
|
+
*/
|
|
65
|
+
export interface WorkPage {
|
|
66
|
+
/** The work's permanent facts and its record. */
|
|
67
|
+
readonly work: Work;
|
|
68
|
+
/**
|
|
69
|
+
* The item the work was minted from: parties, payees, the license it was approved with, sale
|
|
70
|
+
* and edition terms. Null when it could not be found; when present, it hashes to
|
|
71
|
+
* `work.itemHash`.
|
|
72
|
+
*/
|
|
73
|
+
readonly item: PackageItem | null;
|
|
74
|
+
/** The mint: content hash, package root, seller vault, the transaction that started the first sale. */
|
|
75
|
+
readonly mint: WorkMint | null;
|
|
76
|
+
/** The work's files, primary first, each with its verification result and display advice. */
|
|
77
|
+
readonly files: readonly WorkPageFile[];
|
|
78
|
+
/**
|
|
79
|
+
* The descriptive record: its file ID, the JSON once fetched and verified, its known keys
|
|
80
|
+
* (`parsed`), and whether the artist can still replace it. The text is the artist's own:
|
|
81
|
+
* escape it for display.
|
|
82
|
+
*/
|
|
83
|
+
readonly record: {
|
|
84
|
+
readonly fileId: Hex | null;
|
|
85
|
+
readonly json: unknown;
|
|
86
|
+
readonly parsed: WorkRecord | null;
|
|
87
|
+
readonly check: FileCheck;
|
|
88
|
+
readonly finalized: boolean;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* The metadata the token contract serves to marketplaces and wallets (`tokenURI`), for
|
|
92
|
+
* comparing with what this page shows. It is the renderer's output and is not verified here.
|
|
93
|
+
*/
|
|
94
|
+
readonly metadata: TokenMetadata | null;
|
|
95
|
+
/** The license now, whether it can still change, and the license the item was approved with. */
|
|
96
|
+
readonly license: {
|
|
97
|
+
readonly spdxId: string;
|
|
98
|
+
readonly textFileId: Hex;
|
|
99
|
+
readonly key: Hex;
|
|
100
|
+
/** The contract's own lock flag: set when the artist gave up relicensing. */
|
|
101
|
+
readonly locked: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Whether the license can ever change again. False for CC0 (the contract never lets a work
|
|
104
|
+
* leave CC0, although it does not set the lock flag for it) and for a locked license.
|
|
105
|
+
*/
|
|
106
|
+
readonly canChange: boolean;
|
|
107
|
+
readonly atMint: {
|
|
108
|
+
readonly spdxId: string;
|
|
109
|
+
readonly textFileId: Hex;
|
|
110
|
+
} | null;
|
|
111
|
+
} | null;
|
|
112
|
+
/** The royalty on later sales, and the vault it is paid to. */
|
|
113
|
+
readonly royalty: {
|
|
114
|
+
readonly receiver: Address;
|
|
115
|
+
readonly rate: number;
|
|
116
|
+
readonly percent: number;
|
|
117
|
+
readonly locked: boolean;
|
|
118
|
+
};
|
|
119
|
+
/** The royalty vault: royalties are split there between the network and the seller vault. */
|
|
120
|
+
readonly royaltyVault: RoyaltyVault | null;
|
|
121
|
+
/** The seller vault and each payee's share and balance; null without the item. */
|
|
122
|
+
readonly split: Split | null;
|
|
123
|
+
/** Who is credited: the item's parties, in order, the lead artist first. */
|
|
124
|
+
readonly parties: readonly {
|
|
125
|
+
readonly account: Address;
|
|
126
|
+
readonly role: number;
|
|
127
|
+
readonly lead: boolean;
|
|
128
|
+
}[];
|
|
129
|
+
/** The 1/1's first sale: its state now, its bids and settlement. */
|
|
130
|
+
readonly sale: Sale;
|
|
131
|
+
readonly saleHistory: SaleHistory;
|
|
132
|
+
/** An edition master's edition sale and the edition itself (copies minted, sealed maximum, original cap: three separate numbers); null for an original. */
|
|
133
|
+
readonly editionSale: EditionSale | null;
|
|
134
|
+
readonly edition: Edition | null;
|
|
135
|
+
/**
|
|
136
|
+
* What was checked. `true`: checked and it held. `false`: checked and it FAILED: do not
|
|
137
|
+
* present that part as fact. `null`: not checked (the data was not available or not fetched).
|
|
138
|
+
*/
|
|
139
|
+
readonly checks: {
|
|
140
|
+
/** The item found hashes to the item hash the token stores. Null when no item was found. */
|
|
141
|
+
readonly itemMatchesToken: boolean | null;
|
|
142
|
+
/** The item's content hash is the primary file's SHA-256. */
|
|
143
|
+
readonly contentMatchesPrimaryFile: boolean | null;
|
|
144
|
+
/** The files the record lists, with their hashes, are the media list the item commits to. */
|
|
145
|
+
readonly filesMatchItem: boolean | null;
|
|
146
|
+
/** The seller vault derived from the item's payees is the one the mint recorded. */
|
|
147
|
+
readonly splitMatchesMint: boolean | null;
|
|
148
|
+
/**
|
|
149
|
+
* Every listed file and the record were fetched and verified. `false` if any failed;
|
|
150
|
+
* `null` if some were not fetched (see `fetchFiles`) or the record is not open.
|
|
151
|
+
*/
|
|
152
|
+
readonly filesVerified: boolean | null;
|
|
153
|
+
};
|
|
154
|
+
/** How many files (the record included) were fetched and verified, and how many there are. */
|
|
155
|
+
readonly filesFetched: {
|
|
156
|
+
readonly verified: number;
|
|
157
|
+
readonly total: number;
|
|
158
|
+
};
|
|
159
|
+
/** For each part of the page, the contract and the function or event it was read from. */
|
|
160
|
+
readonly sources: Readonly<Record<"work" | "record" | "artist" | "item" | "mint" | "files" | "locators" | "metadata" | "split" | "royaltyVault" | "sale" | "saleHistory" | "editionSale" | "edition", FactSource>>;
|
|
161
|
+
}
|
|
162
|
+
export interface WorkPageOptions extends FetchFileOptions, LogScanOptions {
|
|
163
|
+
/** Which files to fetch and verify: the primary one (default), all of them, or none. */
|
|
164
|
+
readonly fetchFiles?: "primary" | "all" | "none";
|
|
165
|
+
/** Whether to fetch and parse the descriptive record. Default: true. */
|
|
166
|
+
readonly fetchRecord?: boolean;
|
|
167
|
+
/** A holder whose edition balance to include. */
|
|
168
|
+
readonly holder?: Address;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* What a page about one work shows, in one call:
|
|
172
|
+
*
|
|
173
|
+
* - the work's facts, record, license and royalty (`readWork`);
|
|
174
|
+
* - the item it was minted from, proven against the item hash the token stores (`readWorkItem`);
|
|
175
|
+
* - its files, fetched and checked byte for byte (`fetchFile`), with the result and display
|
|
176
|
+
* advice per file, and the file list itself checked against the item's `mediaHash`;
|
|
177
|
+
* - its descriptive record, fetched, verified and parsed;
|
|
178
|
+
* - the metadata marketplaces see (`readTokenMetadata`), for comparison;
|
|
179
|
+
* - the seller vault and its payees (`readSplit`), checked against the vault the mint
|
|
180
|
+
* recorded, and the royalty vault (`readRoyaltyVault`);
|
|
181
|
+
* - the 1/1 sale and its history, the edition sale and the edition.
|
|
182
|
+
*
|
|
183
|
+
* A file that cannot be fetched or does not verify does not fail the call: it comes back with
|
|
184
|
+
* `check.status === "unavailable"` and no bytes, so the page can say so. `checks` says what
|
|
185
|
+
* was verified, what failed and what was not checked; `sources` names the contract and
|
|
186
|
+
* function behind each part. Not included: the works of the same artist or collection
|
|
187
|
+
* (`readWorks`), statements about the work (`readStatements`), and artist names (the chain
|
|
188
|
+
* holds profile IDs, not names).
|
|
189
|
+
*
|
|
190
|
+
* Contract: see `sources` in the result, and each read function named above.
|
|
191
|
+
*
|
|
192
|
+
* @throws StreamSdkError `NO_SUCH_WORK` if the token was never minted.
|
|
193
|
+
*/
|
|
194
|
+
export declare function readWorkPage(client: Client, instance: StreamInstance, ref: {
|
|
195
|
+
readonly token?: Address;
|
|
196
|
+
readonly tokenId: bigint;
|
|
197
|
+
}, options?: WorkPageOptions): Promise<WorkPage>;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { CC0_LICENSE_KEY, FILE_ROLE, ITEM_KIND } from "../constants.js";
|
|
2
|
+
import { displayAdvice } from "../display.js";
|
|
3
|
+
import { fetchFile } from "../files/fetch.js";
|
|
4
|
+
import { mediaHash } from "../hashing/items.js";
|
|
5
|
+
import { assertInstanceChain, contractAt } from "../instance.js";
|
|
6
|
+
import { readEditionSale } from "./editionSale.js";
|
|
7
|
+
import { parseRecord, readEdition, readTokenMetadata } from "./metadata.js";
|
|
8
|
+
import { readSale, readSaleHistory } from "./sale.js";
|
|
9
|
+
import { readRoyaltyVault } from "./vault.js";
|
|
10
|
+
import { readSplit, readWork, readWorkFiles, readWorkItem, readWorkMint } from "./work.js";
|
|
11
|
+
/** A record is at most this large: the contracts' own limit (`Limits.MAX_RECORD_BYTES`). */
|
|
12
|
+
const MAX_RECORD_BYTES = 12_288;
|
|
13
|
+
function reasonOf(error) {
|
|
14
|
+
const attempts = error.attempts;
|
|
15
|
+
if (Array.isArray(attempts) && attempts.length > 0)
|
|
16
|
+
return attempts.map(String);
|
|
17
|
+
return [error instanceof Error ? error.message : String(error)];
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* What a page about one work shows, in one call:
|
|
21
|
+
*
|
|
22
|
+
* - the work's facts, record, license and royalty (`readWork`);
|
|
23
|
+
* - the item it was minted from, proven against the item hash the token stores (`readWorkItem`);
|
|
24
|
+
* - its files, fetched and checked byte for byte (`fetchFile`), with the result and display
|
|
25
|
+
* advice per file, and the file list itself checked against the item's `mediaHash`;
|
|
26
|
+
* - its descriptive record, fetched, verified and parsed;
|
|
27
|
+
* - the metadata marketplaces see (`readTokenMetadata`), for comparison;
|
|
28
|
+
* - the seller vault and its payees (`readSplit`), checked against the vault the mint
|
|
29
|
+
* recorded, and the royalty vault (`readRoyaltyVault`);
|
|
30
|
+
* - the 1/1 sale and its history, the edition sale and the edition.
|
|
31
|
+
*
|
|
32
|
+
* A file that cannot be fetched or does not verify does not fail the call: it comes back with
|
|
33
|
+
* `check.status === "unavailable"` and no bytes, so the page can say so. `checks` says what
|
|
34
|
+
* was verified, what failed and what was not checked; `sources` names the contract and
|
|
35
|
+
* function behind each part. Not included: the works of the same artist or collection
|
|
36
|
+
* (`readWorks`), statements about the work (`readStatements`), and artist names (the chain
|
|
37
|
+
* holds profile IDs, not names).
|
|
38
|
+
*
|
|
39
|
+
* Contract: see `sources` in the result, and each read function named above.
|
|
40
|
+
*
|
|
41
|
+
* @throws StreamSdkError `NO_SUCH_WORK` if the token was never minted.
|
|
42
|
+
*/
|
|
43
|
+
export async function readWorkPage(client, instance, ref, options = {}) {
|
|
44
|
+
await assertInstanceChain(client, instance);
|
|
45
|
+
const token = ref.token ?? instance.addresses.stream;
|
|
46
|
+
const at = { token, tokenId: ref.tokenId };
|
|
47
|
+
const [work, found, mint, listed, sale, saleHistory, metadata] = await Promise.all([
|
|
48
|
+
readWork(client, instance, at),
|
|
49
|
+
readWorkItem(client, instance, at, options),
|
|
50
|
+
readWorkMint(client, instance, at, options),
|
|
51
|
+
readWorkFiles(client, instance, at),
|
|
52
|
+
readSale(client, instance, at),
|
|
53
|
+
readSaleHistory(client, instance, at, options),
|
|
54
|
+
readTokenMetadata(client, instance, at),
|
|
55
|
+
]);
|
|
56
|
+
const item = found?.item ?? null;
|
|
57
|
+
const want = options.fetchFiles ?? "primary";
|
|
58
|
+
const files = await Promise.all(listed.map(async (file) => {
|
|
59
|
+
const display = displayAdvice(file.mimeType);
|
|
60
|
+
if (want === "none" || (want === "primary" && file.role !== FILE_ROLE.PRIMARY)) {
|
|
61
|
+
return { ...file, check: { status: "notFetched" }, bytes: null, display };
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
const fetched = await fetchFile(client, instance, file.fileId, { ...options, locators: options.locators ?? file.locators });
|
|
65
|
+
return { ...file, check: { status: "verified", source: fetched.source, locator: fetched.locator }, bytes: fetched.bytes, display };
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return { ...file, check: { status: "unavailable", attempts: reasonOf(error) }, bytes: null, display };
|
|
69
|
+
}
|
|
70
|
+
}));
|
|
71
|
+
let recordJson = null;
|
|
72
|
+
let recordCheck = { status: "notFetched" };
|
|
73
|
+
if (work.record.opened && options.fetchRecord !== false) {
|
|
74
|
+
try {
|
|
75
|
+
// The record is read from the chain: a work's off-chain copies are copies of its media files.
|
|
76
|
+
const fetched = await fetchFile(client, instance, work.record.recordFileId, { ...options, locators: [], maxBytes: Math.min(options.maxBytes ?? MAX_RECORD_BYTES, MAX_RECORD_BYTES) });
|
|
77
|
+
recordJson = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(fetched.bytes));
|
|
78
|
+
recordCheck = { status: "verified", source: fetched.source, locator: fetched.locator };
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
recordCheck = { status: "unavailable", attempts: reasonOf(error) };
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const master = work.kind === ITEM_KIND.EDITION_MASTER;
|
|
85
|
+
const [split, editionSale, royaltyVault] = await Promise.all([
|
|
86
|
+
item ? readSplit(client, instance, item.payees) : null,
|
|
87
|
+
master ? readEditionSale(client, instance, at) : null,
|
|
88
|
+
readRoyaltyVault(client, instance, at, options).catch(() => null),
|
|
89
|
+
]);
|
|
90
|
+
const edition = editionSale ? await readEdition(client, instance, { editions: editionSale.editions, editionId: ref.tokenId, ...(options.holder ? { holder: options.holder } : {}) }) : null;
|
|
91
|
+
const primary = listed.find((file) => file.role === FILE_ROLE.PRIMARY);
|
|
92
|
+
const checksOfFiles = [...files.map((file) => file.check.status), ...(work.record.opened ? [recordCheck.status] : [])];
|
|
93
|
+
const filesVerified = checksOfFiles.includes("unavailable") ? false : checksOfFiles.length > 0 && checksOfFiles.every((status) => status === "verified") ? true : null;
|
|
94
|
+
const a = instance.addresses;
|
|
95
|
+
const tokenContract = work.curated ? "Stream6529" : "IndependentStream6529";
|
|
96
|
+
return {
|
|
97
|
+
work,
|
|
98
|
+
item,
|
|
99
|
+
mint,
|
|
100
|
+
files,
|
|
101
|
+
record: {
|
|
102
|
+
fileId: work.record.opened ? work.record.recordFileId : null,
|
|
103
|
+
json: recordJson,
|
|
104
|
+
parsed: recordCheck.status === "verified" ? parseRecord(recordJson) : null,
|
|
105
|
+
check: recordCheck,
|
|
106
|
+
finalized: work.record.finalized,
|
|
107
|
+
},
|
|
108
|
+
metadata,
|
|
109
|
+
license: work.license
|
|
110
|
+
? {
|
|
111
|
+
...work.license,
|
|
112
|
+
locked: work.record.licenseLocked,
|
|
113
|
+
canChange: !work.record.licenseLocked && work.license.key !== CC0_LICENSE_KEY,
|
|
114
|
+
atMint: item ? { spdxId: item.license.spdxId, textFileId: item.license.textFileId } : null,
|
|
115
|
+
}
|
|
116
|
+
: null,
|
|
117
|
+
royalty: { ...work.royalty, percent: work.royalty.rate / 1_000 },
|
|
118
|
+
royaltyVault,
|
|
119
|
+
split,
|
|
120
|
+
parties: (item?.parties ?? []).map((party, index) => ({ account: party.account, role: party.role, lead: index === 0 })),
|
|
121
|
+
sale,
|
|
122
|
+
saleHistory,
|
|
123
|
+
editionSale,
|
|
124
|
+
edition,
|
|
125
|
+
checks: {
|
|
126
|
+
// readWorkItem returns an item only when it hashes to the stored item hash.
|
|
127
|
+
itemMatchesToken: item ? true : null,
|
|
128
|
+
contentMatchesPrimaryFile: item && primary ? item.contentHash.toLowerCase() === primary.sha256.toLowerCase() : null,
|
|
129
|
+
filesMatchItem: item && listed.length > 0
|
|
130
|
+
? mediaHash(instance.protocol, listed.map((file) => ({ fileId: file.fileId, sha256Hash: file.sha256, role: file.role }))) === item.mediaHash
|
|
131
|
+
: null,
|
|
132
|
+
splitMatchesMint: split && mint ? split.wallet.toLowerCase() === mint.seller.toLowerCase() : null,
|
|
133
|
+
filesVerified,
|
|
134
|
+
},
|
|
135
|
+
filesFetched: { verified: checksOfFiles.filter((status) => status === "verified").length, total: files.length + (work.record.opened ? 1 : 0) },
|
|
136
|
+
sources: {
|
|
137
|
+
work: { kind: "contract", contract: tokenContract, address: token, reads: "workOf, ownerOf, collectionOf" },
|
|
138
|
+
record: { kind: "contract", contract: "StreamWorkFacts6529", address: a.workFacts, reads: "factsOf" },
|
|
139
|
+
artist: { kind: "contract", contract: "Accounts", address: a.accounts, reads: "artist" },
|
|
140
|
+
item: found?.source === "startTransaction"
|
|
141
|
+
? {
|
|
142
|
+
kind: "transaction",
|
|
143
|
+
transactionHash: found.transactionHash,
|
|
144
|
+
contract: (found.calledContract && contractAt(instance, found.calledContract)?.name) ?? "a contract outside the instance",
|
|
145
|
+
address: found.calledContract ?? a.englishAuction,
|
|
146
|
+
reads: "calldata of the start transaction, checked against workOf().itemHash",
|
|
147
|
+
}
|
|
148
|
+
: { kind: "contract", contract: "StreamWorkFacts6529", address: a.workFacts, reads: "event RecordOpened, checked against workOf().itemHash" },
|
|
149
|
+
mint: { kind: "contract", contract: tokenContract, address: token, reads: "event WorkMinted, tokenOfContent" },
|
|
150
|
+
files: { kind: "contract", contract: "ContentStore", address: a.contentStore, reads: "fileInfo, chunkHash, isComplete, readChunk" },
|
|
151
|
+
locators: { kind: "contract", contract: "WorkDelivery", address: a.workDelivery, reads: "locators" },
|
|
152
|
+
metadata: { kind: "contract", contract: tokenContract, address: token, reads: "tokenURI (answered by the Renderer)" },
|
|
153
|
+
split: { kind: "contract", contract: "SplitLedger", address: a.splitLedger, reads: "walletFor, releasable, released" },
|
|
154
|
+
royaltyVault: { kind: "contract", contract: "SplitLedger", address: a.splitLedger, reads: "event WalletCreated, walletFor, releasable, released, isWallet" },
|
|
155
|
+
sale: { kind: "contract", contract: "EnglishAuction", address: a.englishAuction, reads: "auction, auctionClock, minimumBid, pendingDelivery, refusableAt, config, paused" },
|
|
156
|
+
saleHistory: { kind: "contract", contract: "EnglishAuction", address: a.englishAuction, reads: "events SaleStarted, BidPlaced, SaleSettled" },
|
|
157
|
+
editionSale: { kind: "contract",
|
|
158
|
+
contract: work.curated ? "UniformEditionAuction" : "IndependentEditionAuction",
|
|
159
|
+
address: editionSale?.auction ?? (work.curated ? a.editionAuction : a.independentEditionAuction),
|
|
160
|
+
reads: "auction, endTimes, clearing, ladder, stepTotals, abandonable, paused",
|
|
161
|
+
},
|
|
162
|
+
edition: { kind: "contract",
|
|
163
|
+
contract: work.curated ? "StreamEditions6529" : "IndependentStreamEditions6529",
|
|
164
|
+
address: editionSale?.editions ?? a.streamEditions,
|
|
165
|
+
reads: "editionOf, uri, balanceOf",
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|