@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,42 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
/** What a content-store manifest states about a file. */
|
|
3
|
+
export interface Manifest {
|
|
4
|
+
/** keccak256 of each stored chunk, in order. */
|
|
5
|
+
readonly chunkHashes: readonly Hex[];
|
|
6
|
+
/** The stored length in bytes. */
|
|
7
|
+
readonly length: bigint;
|
|
8
|
+
/** `ENCODING`: how the stored bytes relate to the media. */
|
|
9
|
+
readonly encoding: number;
|
|
10
|
+
readonly mimeType: string;
|
|
11
|
+
/** SHA-256 of the decoded media. */
|
|
12
|
+
readonly sha256: Hex;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A file's ID in the content store. The ID commits to the chunk hashes, the stored length,
|
|
16
|
+
* the encoding, the MIME type and the SHA-256 of the decoded media, so a file fetched from
|
|
17
|
+
* anywhere can be checked against its ID alone.
|
|
18
|
+
*
|
|
19
|
+
* Rule: `keccak256(abi.encode(chunkHashes, length, encoding, mimeType, sha256Hash))`.
|
|
20
|
+
*
|
|
21
|
+
* Contract: [`ContentStore.manifestId`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol).
|
|
22
|
+
*/
|
|
23
|
+
export declare function manifestId(manifest: Manifest): Hex;
|
|
24
|
+
/** Splits stored bytes into the chunks the content store takes: `CHUNK_SIZE` bytes each, the last one shorter. */
|
|
25
|
+
export declare function splitChunks(bytes: Uint8Array): Uint8Array[];
|
|
26
|
+
/** A file ready to store: its chunks, its manifest and the file ID it will get. */
|
|
27
|
+
export interface PreparedFile extends Manifest {
|
|
28
|
+
/** The bytes as they are stored. */
|
|
29
|
+
readonly bytes: Uint8Array;
|
|
30
|
+
readonly chunks: readonly Uint8Array[];
|
|
31
|
+
/** `manifestId` of this manifest: the file's ID before anything is sent. */
|
|
32
|
+
readonly fileId: Hex;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Prepares a file for the content store, stored as it is (identity encoding): chunks, chunk
|
|
36
|
+
* hashes, SHA-256 and the file ID, all computed here.
|
|
37
|
+
*
|
|
38
|
+
* Contract: the arguments of [`ContentStore.registerManifest`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol).
|
|
39
|
+
*/
|
|
40
|
+
export declare function prepareFile(bytes: Uint8Array, mimeType: string): PreparedFile;
|
|
41
|
+
/** Hex of bytes, for `ContentStore.writeChunk`. */
|
|
42
|
+
export declare function chunkData(chunk: Uint8Array): Hex;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { bytesToHex, encodeAbiParameters, keccak256, sha256 } from "viem";
|
|
3
|
+
import { CHUNK_SIZE, ENCODING } from "../constants.js";
|
|
4
|
+
import { FlowError } from "../errors.js";
|
|
5
|
+
/**
|
|
6
|
+
* A file's ID in the content store. The ID commits to the chunk hashes, the stored length,
|
|
7
|
+
* the encoding, the MIME type and the SHA-256 of the decoded media, so a file fetched from
|
|
8
|
+
* anywhere can be checked against its ID alone.
|
|
9
|
+
*
|
|
10
|
+
* Rule: `keccak256(abi.encode(chunkHashes, length, encoding, mimeType, sha256Hash))`.
|
|
11
|
+
*
|
|
12
|
+
* Contract: [`ContentStore.manifestId`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol).
|
|
13
|
+
*/
|
|
14
|
+
export function manifestId(manifest) {
|
|
15
|
+
return keccak256(encodeAbiParameters([{ type: "bytes32[]" }, { type: "uint256" }, { type: "uint8" }, { type: "string" }, { type: "bytes32" }], [manifest.chunkHashes, manifest.length, manifest.encoding, manifest.mimeType, manifest.sha256]));
|
|
16
|
+
}
|
|
17
|
+
/** Splits stored bytes into the chunks the content store takes: `CHUNK_SIZE` bytes each, the last one shorter. */
|
|
18
|
+
export function splitChunks(bytes) {
|
|
19
|
+
const chunks = [];
|
|
20
|
+
for (let offset = 0; offset < bytes.length; offset += CHUNK_SIZE) {
|
|
21
|
+
chunks.push(bytes.subarray(offset, offset + CHUNK_SIZE));
|
|
22
|
+
}
|
|
23
|
+
return chunks;
|
|
24
|
+
}
|
|
25
|
+
/** `ContentStore.MAX_MIME_LENGTH`. */
|
|
26
|
+
const MAX_MIME_LENGTH = 64;
|
|
27
|
+
/**
|
|
28
|
+
* Prepares a file for the content store, stored as it is (identity encoding): chunks, chunk
|
|
29
|
+
* hashes, SHA-256 and the file ID, all computed here.
|
|
30
|
+
*
|
|
31
|
+
* Contract: the arguments of [`ContentStore.registerManifest`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/content/ContentStore.sol).
|
|
32
|
+
*/
|
|
33
|
+
export function prepareFile(bytes, mimeType) {
|
|
34
|
+
if (bytes.length === 0)
|
|
35
|
+
throw new FlowError("INVALID_INPUT", "A stored file cannot be empty.");
|
|
36
|
+
// The store refuses any other MIME type, but only when the manifest is registered, after
|
|
37
|
+
// every chunk has been paid for: check it first.
|
|
38
|
+
if (mimeType.length > MAX_MIME_LENGTH || !/^[a-z0-9+._-]+\/[a-z0-9+._-]+$/.test(mimeType)) {
|
|
39
|
+
throw new FlowError("INVALID_INPUT", `"${mimeType}" is not a MIME type the content store takes: lower case type/subtype from a-z, 0-9 and "+", "-", ".", "_", at most ${MAX_MIME_LENGTH} characters.`);
|
|
40
|
+
}
|
|
41
|
+
const chunks = splitChunks(bytes);
|
|
42
|
+
const manifest = {
|
|
43
|
+
chunkHashes: chunks.map((chunk) => keccak256(chunk)),
|
|
44
|
+
length: BigInt(bytes.length),
|
|
45
|
+
encoding: ENCODING.IDENTITY,
|
|
46
|
+
mimeType,
|
|
47
|
+
sha256: sha256(bytes),
|
|
48
|
+
};
|
|
49
|
+
return { ...manifest, bytes, chunks, fileId: manifestId(manifest) };
|
|
50
|
+
}
|
|
51
|
+
/** Hex of bytes, for `ContentStore.writeChunk`. */
|
|
52
|
+
export function chunkData(chunk) {
|
|
53
|
+
return bytesToHex(chunk);
|
|
54
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import type { StreamProtocol } from "../instance.js";
|
|
3
|
+
/**
|
|
4
|
+
* The ID of a token's sale: the same rule on the English auction (`token` is the 1/1
|
|
5
|
+
* contract) and on both edition auctions (`token` is the editions contract, `tokenId` the
|
|
6
|
+
* edition ID, which equals its master's token ID).
|
|
7
|
+
*
|
|
8
|
+
* Rule: `uint256(keccak256(abi.encode(token, tokenId)))`.
|
|
9
|
+
*
|
|
10
|
+
* Contract: [`EnglishAuction.saleIdOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol),
|
|
11
|
+
* [`UniformEditionAuctionLens.saleIdOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuctionLens.sol).
|
|
12
|
+
*/
|
|
13
|
+
export declare function saleId(token: Address, tokenId: bigint): bigint;
|
|
14
|
+
/**
|
|
15
|
+
* The key of a statement subject: a token (`token`, `id`), or a work ID when `token` is zero.
|
|
16
|
+
*
|
|
17
|
+
* Rule: `keccak256(abi.encode(token, id))`.
|
|
18
|
+
*
|
|
19
|
+
* Contract: [`StatementLog.subjectKey`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/StatementLog.sol).
|
|
20
|
+
*/
|
|
21
|
+
export declare function statementSubjectKey(token: Address, id: bigint): Hex;
|
|
22
|
+
/** What an artist consents to when listing an Independent Stream contract. */
|
|
23
|
+
export interface ListingTerms {
|
|
24
|
+
/** The contract being listed. */
|
|
25
|
+
readonly token: Address;
|
|
26
|
+
/** `INDEPENDENT_FORM`: 0 for the 1/1 contract, 1 for its editions contract. */
|
|
27
|
+
readonly form: number;
|
|
28
|
+
/** For an editions contract, its 1/1 contract; otherwise the zero address. */
|
|
29
|
+
readonly partner: Address;
|
|
30
|
+
/** The network's share of sales and royalties, out of 100,000, as the contract reads it now. */
|
|
31
|
+
readonly feeShare: number;
|
|
32
|
+
/** Unix seconds, on the chain's clock. */
|
|
33
|
+
readonly deadline: bigint;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The subject of a listing consent: the `what` of the `Consent` message an artist signs to
|
|
37
|
+
* list a contract. Compute it here and show its inputs to the artist; do not sign a value an
|
|
38
|
+
* RPC supplied.
|
|
39
|
+
*
|
|
40
|
+
* Rule: `keccak256(abi.encode(LISTING_DOMAIN, token, form, partner, feeShare, deadline))`.
|
|
41
|
+
*
|
|
42
|
+
* Contract: [`IndependentStreamRegistry.listingSubject`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
|
|
43
|
+
*/
|
|
44
|
+
export declare function listingSubject(protocol: StreamProtocol, terms: ListingTerms): Hex;
|
|
45
|
+
/**
|
|
46
|
+
* What a collaborator of an Independent Stream work consents to: the item and its royalty
|
|
47
|
+
* rate. It is the `what` of the `Consent` message, whose `subject` is the token contract.
|
|
48
|
+
*
|
|
49
|
+
* Rule: `keccak256(abi.encode(tag, itemHash, royaltyRate))`. The tag is the instance's consent
|
|
50
|
+
* label: on r9 the label itself, encoded as a string; on later code its keccak256
|
|
51
|
+
* (`INDEPENDENT_CONSENT_DOMAIN`), one word like the other labels. `protocol` says which.
|
|
52
|
+
*
|
|
53
|
+
* Contract: [`Core.independentConsent`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/core/CoreTypes.sol).
|
|
54
|
+
*/
|
|
55
|
+
export declare function independentConsent(protocol: StreamProtocol, itemHash: Hex, royaltyRate: number): Hex;
|
|
56
|
+
/**
|
|
57
|
+
* The artist ID a wallet gets when its account is created: the address as a number.
|
|
58
|
+
*
|
|
59
|
+
* This is only the ID of a NEW account. A wallet that already belongs to an account has that
|
|
60
|
+
* account's ID, which can be another wallet's number (a consolidated wallet, or a root that
|
|
61
|
+
* was replaced). Read `Accounts.artistIdOf(wallet)` first; `readArtistId` does both.
|
|
62
|
+
*
|
|
63
|
+
* Contract: [`PackageTypes.sol`, `Party`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/PackageTypes.sol).
|
|
64
|
+
*/
|
|
65
|
+
export declare function newArtistId(wallet: Address): bigint;
|
|
66
|
+
/** The address whose number an artist ID is. It is the account's first root, not always its current one. */
|
|
67
|
+
export declare function artistIdAddress(artistId: bigint): Address;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { encodeAbiParameters, getAddress, keccak256, toBytes } from "viem";
|
|
3
|
+
import { FlowError } from "../errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* The ID of a token's sale: the same rule on the English auction (`token` is the 1/1
|
|
6
|
+
* contract) and on both edition auctions (`token` is the editions contract, `tokenId` the
|
|
7
|
+
* edition ID, which equals its master's token ID).
|
|
8
|
+
*
|
|
9
|
+
* Rule: `uint256(keccak256(abi.encode(token, tokenId)))`.
|
|
10
|
+
*
|
|
11
|
+
* Contract: [`EnglishAuction.saleIdOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/EnglishAuction.sol),
|
|
12
|
+
* [`UniformEditionAuctionLens.saleIdOf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/sales/UniformEditionAuctionLens.sol).
|
|
13
|
+
*/
|
|
14
|
+
export function saleId(token, tokenId) {
|
|
15
|
+
return BigInt(keccak256(encodeAbiParameters([{ type: "address" }, { type: "uint256" }], [token, tokenId])));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The key of a statement subject: a token (`token`, `id`), or a work ID when `token` is zero.
|
|
19
|
+
*
|
|
20
|
+
* Rule: `keccak256(abi.encode(token, id))`.
|
|
21
|
+
*
|
|
22
|
+
* Contract: [`StatementLog.subjectKey`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/StatementLog.sol).
|
|
23
|
+
*/
|
|
24
|
+
export function statementSubjectKey(token, id) {
|
|
25
|
+
return keccak256(encodeAbiParameters([{ type: "address" }, { type: "uint256" }], [token, id]));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The subject of a listing consent: the `what` of the `Consent` message an artist signs to
|
|
29
|
+
* list a contract. Compute it here and show its inputs to the artist; do not sign a value an
|
|
30
|
+
* RPC supplied.
|
|
31
|
+
*
|
|
32
|
+
* Rule: `keccak256(abi.encode(LISTING_DOMAIN, token, form, partner, feeShare, deadline))`.
|
|
33
|
+
*
|
|
34
|
+
* Contract: [`IndependentStreamRegistry.listingSubject`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/independent/IndependentStreamRegistry.sol).
|
|
35
|
+
*/
|
|
36
|
+
export function listingSubject(protocol, terms) {
|
|
37
|
+
return keccak256(encodeAbiParameters([{ type: "bytes32" }, { type: "address" }, { type: "uint8" }, { type: "address" }, { type: "uint32" }, { type: "uint64" }], [keccak256(toBytes(protocol.labels.independentListing)), terms.token, terms.form, terms.partner, terms.feeShare, terms.deadline]));
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What a collaborator of an Independent Stream work consents to: the item and its royalty
|
|
41
|
+
* rate. It is the `what` of the `Consent` message, whose `subject` is the token contract.
|
|
42
|
+
*
|
|
43
|
+
* Rule: `keccak256(abi.encode(tag, itemHash, royaltyRate))`. The tag is the instance's consent
|
|
44
|
+
* label: on r9 the label itself, encoded as a string; on later code its keccak256
|
|
45
|
+
* (`INDEPENDENT_CONSENT_DOMAIN`), one word like the other labels. `protocol` says which.
|
|
46
|
+
*
|
|
47
|
+
* Contract: [`Core.independentConsent`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/core/CoreTypes.sol).
|
|
48
|
+
*/
|
|
49
|
+
export function independentConsent(protocol, itemHash, royaltyRate) {
|
|
50
|
+
const label = protocol.labels.independentConsent;
|
|
51
|
+
return protocol.independentConsentTag === "bytes32"
|
|
52
|
+
? keccak256(encodeAbiParameters([{ type: "bytes32" }, { type: "bytes32" }, { type: "uint24" }], [keccak256(toBytes(label)), itemHash, royaltyRate]))
|
|
53
|
+
: keccak256(encodeAbiParameters([{ type: "string" }, { type: "bytes32" }, { type: "uint24" }], [label, itemHash, royaltyRate]));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The artist ID a wallet gets when its account is created: the address as a number.
|
|
57
|
+
*
|
|
58
|
+
* This is only the ID of a NEW account. A wallet that already belongs to an account has that
|
|
59
|
+
* account's ID, which can be another wallet's number (a consolidated wallet, or a root that
|
|
60
|
+
* was replaced). Read `Accounts.artistIdOf(wallet)` first; `readArtistId` does both.
|
|
61
|
+
*
|
|
62
|
+
* Contract: [`PackageTypes.sol`, `Party`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/PackageTypes.sol).
|
|
63
|
+
*/
|
|
64
|
+
export function newArtistId(wallet) {
|
|
65
|
+
return BigInt(wallet);
|
|
66
|
+
}
|
|
67
|
+
/** The address whose number an artist ID is. It is the account's first root, not always its current one. */
|
|
68
|
+
export function artistIdAddress(artistId) {
|
|
69
|
+
if (artistId <= 0n || artistId >= 1n << 160n) {
|
|
70
|
+
throw new FlowError("INVALID_INPUT", "An artist ID is a nonzero number of at most 160 bits.");
|
|
71
|
+
}
|
|
72
|
+
return getAddress(`0x${artistId.toString(16).padStart(40, "0")}`);
|
|
73
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
import type { StreamProtocol } from "../instance.js";
|
|
3
|
+
import { type MediaFile, type PackageItem } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* An item's hash: its identity, consumed at most once.
|
|
6
|
+
*
|
|
7
|
+
* Rule: `keccak256(abi.encode(PACKAGE_ITEM_DOMAIN, item))`. No chain ID and no contract
|
|
8
|
+
* address enter it, so an item has the same hash on every chain.
|
|
9
|
+
*
|
|
10
|
+
* Contract: [`StreamHashing.itemHash`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol),
|
|
11
|
+
* read back from a minted work with `Stream6529.itemHashOf(tokenId)`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function itemHash(protocol: StreamProtocol, item: PackageItem): Hex;
|
|
14
|
+
/**
|
|
15
|
+
* The hash of an ordered media list, which `PackageItem.mediaHash` commits to. The primary
|
|
16
|
+
* file comes first and carries the item's `contentHash`.
|
|
17
|
+
*
|
|
18
|
+
* Rule: `keccak256(abi.encode(MEDIA_DOMAIN, media))`.
|
|
19
|
+
*
|
|
20
|
+
* Contract: [`StreamHashing.mediaHash`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
21
|
+
*/
|
|
22
|
+
export declare function mediaHash(protocol: StreamProtocol, media: readonly MediaFile[]): Hex;
|
|
23
|
+
/**
|
|
24
|
+
* A license's canonical key: keccak256 of its SPDX identifier with the ASCII letters A to Z
|
|
25
|
+
* lowercased. Only those 26 bytes change, exactly as the contract does it, so this is not
|
|
26
|
+
* `toLowerCase()`.
|
|
27
|
+
*
|
|
28
|
+
* Contract: [`StreamHashing.licenseKey`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
29
|
+
*/
|
|
30
|
+
export declare function licenseKey(spdxId: string): Hex;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { encodeAbiParameters, keccak256, toBytes } from "viem";
|
|
3
|
+
import { MEDIA_FILES_ABI, PACKAGE_ITEM_ABI } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* An item's hash: its identity, consumed at most once.
|
|
6
|
+
*
|
|
7
|
+
* Rule: `keccak256(abi.encode(PACKAGE_ITEM_DOMAIN, item))`. No chain ID and no contract
|
|
8
|
+
* address enter it, so an item has the same hash on every chain.
|
|
9
|
+
*
|
|
10
|
+
* Contract: [`StreamHashing.itemHash`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol),
|
|
11
|
+
* read back from a minted work with `Stream6529.itemHashOf(tokenId)`.
|
|
12
|
+
*/
|
|
13
|
+
export function itemHash(protocol, item) {
|
|
14
|
+
const domain = keccak256(toBytes(protocol.labels.packageItem));
|
|
15
|
+
return keccak256(encodeAbiParameters([{ type: "bytes32" }, PACKAGE_ITEM_ABI], [domain, item]));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The hash of an ordered media list, which `PackageItem.mediaHash` commits to. The primary
|
|
19
|
+
* file comes first and carries the item's `contentHash`.
|
|
20
|
+
*
|
|
21
|
+
* Rule: `keccak256(abi.encode(MEDIA_DOMAIN, media))`.
|
|
22
|
+
*
|
|
23
|
+
* Contract: [`StreamHashing.mediaHash`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
24
|
+
*/
|
|
25
|
+
export function mediaHash(protocol, media) {
|
|
26
|
+
const domain = keccak256(toBytes(protocol.labels.media));
|
|
27
|
+
return keccak256(encodeAbiParameters([{ type: "bytes32" }, MEDIA_FILES_ABI], [domain, media]));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A license's canonical key: keccak256 of its SPDX identifier with the ASCII letters A to Z
|
|
31
|
+
* lowercased. Only those 26 bytes change, exactly as the contract does it, so this is not
|
|
32
|
+
* `toLowerCase()`.
|
|
33
|
+
*
|
|
34
|
+
* Contract: [`StreamHashing.licenseKey`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
35
|
+
*/
|
|
36
|
+
export function licenseKey(spdxId) {
|
|
37
|
+
const bytes = toBytes(spdxId);
|
|
38
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
39
|
+
const byte = bytes[i] ?? 0;
|
|
40
|
+
if (byte >= 0x41 && byte <= 0x5a)
|
|
41
|
+
bytes[i] = byte + 32;
|
|
42
|
+
}
|
|
43
|
+
return keccak256(bytes);
|
|
44
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type Hex } from "viem";
|
|
2
|
+
/**
|
|
3
|
+
* The Merkle leaf of an item hash: `keccak256(itemHash)`. Hashing twice makes a leaf's
|
|
4
|
+
* preimage 32 bytes, so an inner node (64 bytes) can never pass as a leaf.
|
|
5
|
+
*
|
|
6
|
+
* Contract: [`StreamHashing.leaf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
7
|
+
*/
|
|
8
|
+
export declare function itemLeaf(itemHash: Hex): Hex;
|
|
9
|
+
/** A package: the root that is approved and signed, and each item's proof. */
|
|
10
|
+
export interface PackageTree {
|
|
11
|
+
/** The package root. For one item it is that item's leaf. */
|
|
12
|
+
readonly root: Hex;
|
|
13
|
+
/** The item hashes, in the order given. */
|
|
14
|
+
readonly itemHashes: readonly Hex[];
|
|
15
|
+
/** The proof that `itemHash` is in the package. Throws if it is not. */
|
|
16
|
+
proofOf(itemHash: Hex): Hex[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Builds the package tree over item hashes: the root every party signs, and the proof each
|
|
20
|
+
* item is minted with.
|
|
21
|
+
*
|
|
22
|
+
* The layout is OpenZeppelin's `StandardMerkleTree`, the one `StreamHashing` names: the leaves
|
|
23
|
+
* `keccak256(itemHash)` sorted ascending, and each parent the sorted-pair hash of its two
|
|
24
|
+
* children. The order of the item hashes given does not change the root.
|
|
25
|
+
*
|
|
26
|
+
* Contract: verified by [`StreamHashing.isItem`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol)
|
|
27
|
+
* (OpenZeppelin `MerkleProof.verify`), which `PackageRegistry.isApprovedItem` calls.
|
|
28
|
+
*/
|
|
29
|
+
export declare function packageTree(itemHashes: readonly Hex[]): PackageTree;
|
|
30
|
+
/**
|
|
31
|
+
* Whether `itemHash` is an item of the package with root `packageRoot`.
|
|
32
|
+
*
|
|
33
|
+
* Contract: [`StreamHashing.isItem`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
34
|
+
*/
|
|
35
|
+
export declare function isPackageItem(proof: readonly Hex[], packageRoot: Hex, itemHash: Hex): boolean;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { concat, keccak256 } from "viem";
|
|
3
|
+
import { FlowError } from "../errors.js";
|
|
4
|
+
/**
|
|
5
|
+
* The Merkle leaf of an item hash: `keccak256(itemHash)`. Hashing twice makes a leaf's
|
|
6
|
+
* preimage 32 bytes, so an inner node (64 bytes) can never pass as a leaf.
|
|
7
|
+
*
|
|
8
|
+
* Contract: [`StreamHashing.leaf`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
9
|
+
*/
|
|
10
|
+
export function itemLeaf(itemHash) {
|
|
11
|
+
return keccak256(itemHash);
|
|
12
|
+
}
|
|
13
|
+
/** The parent of two nodes: keccak256 of the pair, smaller first (OpenZeppelin's sorted-pair hash). */
|
|
14
|
+
function hashPair(a, b) {
|
|
15
|
+
return keccak256(a.toLowerCase() < b.toLowerCase() ? concat([a, b]) : concat([b, a]));
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Builds the package tree over item hashes: the root every party signs, and the proof each
|
|
19
|
+
* item is minted with.
|
|
20
|
+
*
|
|
21
|
+
* The layout is OpenZeppelin's `StandardMerkleTree`, the one `StreamHashing` names: the leaves
|
|
22
|
+
* `keccak256(itemHash)` sorted ascending, and each parent the sorted-pair hash of its two
|
|
23
|
+
* children. The order of the item hashes given does not change the root.
|
|
24
|
+
*
|
|
25
|
+
* Contract: verified by [`StreamHashing.isItem`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol)
|
|
26
|
+
* (OpenZeppelin `MerkleProof.verify`), which `PackageRegistry.isApprovedItem` calls.
|
|
27
|
+
*/
|
|
28
|
+
export function packageTree(itemHashes) {
|
|
29
|
+
if (itemHashes.length === 0)
|
|
30
|
+
throw new FlowError("INVALID_INPUT", "A package needs at least one item.");
|
|
31
|
+
const leaves = itemHashes.map((hash) => itemLeaf(hash).toLowerCase());
|
|
32
|
+
if (new Set(leaves).size !== leaves.length) {
|
|
33
|
+
throw new FlowError("INVALID_INPUT", "A package cannot hold the same item twice.");
|
|
34
|
+
}
|
|
35
|
+
const sorted = [...leaves].sort((a, b) => (a < b ? -1 : 1));
|
|
36
|
+
const count = sorted.length;
|
|
37
|
+
const tree = new Array(2 * count - 1);
|
|
38
|
+
sorted.forEach((leaf, index) => {
|
|
39
|
+
tree[tree.length - 1 - index] = leaf;
|
|
40
|
+
});
|
|
41
|
+
for (let index = tree.length - 1 - count; index >= 0; index--) {
|
|
42
|
+
tree[index] = hashPair(nodeAt(tree, 2 * index + 1), nodeAt(tree, 2 * index + 2));
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
root: nodeAt(tree, 0),
|
|
46
|
+
itemHashes: [...itemHashes],
|
|
47
|
+
proofOf(hash) {
|
|
48
|
+
let index = tree.indexOf(itemLeaf(hash).toLowerCase(), tree.length - count);
|
|
49
|
+
if (index === -1)
|
|
50
|
+
throw new FlowError("INVALID_INPUT", `Item ${hash} is not in this package.`);
|
|
51
|
+
const proof = [];
|
|
52
|
+
while (index > 0) {
|
|
53
|
+
proof.push(nodeAt(tree, index % 2 === 0 ? index - 1 : index + 1));
|
|
54
|
+
index = Math.floor((index - 1) / 2);
|
|
55
|
+
}
|
|
56
|
+
return proof;
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function nodeAt(tree, index) {
|
|
61
|
+
const node = tree[index];
|
|
62
|
+
if (node === undefined)
|
|
63
|
+
throw new Error("package tree index out of range");
|
|
64
|
+
return node;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether `itemHash` is an item of the package with root `packageRoot`.
|
|
68
|
+
*
|
|
69
|
+
* Contract: [`StreamHashing.isItem`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/interfaces/types/StreamHashing.sol).
|
|
70
|
+
*/
|
|
71
|
+
export function isPackageItem(proof, packageRoot, itemHash) {
|
|
72
|
+
let node = itemLeaf(itemHash);
|
|
73
|
+
for (const sibling of proof)
|
|
74
|
+
node = hashPair(node, sibling);
|
|
75
|
+
return node.toLowerCase() === packageRoot.toLowerCase();
|
|
76
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import type { StreamInstance } from "../instance.js";
|
|
3
|
+
import type { Payee } from "../types.js";
|
|
4
|
+
/**
|
|
5
|
+
* The address of the vault (split wallet) of a payee list, computed here. A vault's address
|
|
6
|
+
* is fixed by its payees: the ledger creates it with CREATE2 from one init code, with the salt
|
|
7
|
+
* `keccak256(abi.encode(keccak256(abi.encode(payees)), salt))`. ETH sent to the address is
|
|
8
|
+
* held for the payees even before the vault is created.
|
|
9
|
+
*
|
|
10
|
+
* Use this, not an RPC's answer, for any vault address that goes into a signature.
|
|
11
|
+
*
|
|
12
|
+
* Contract: [`SplitLedger.walletFor`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol)
|
|
13
|
+
* (`_walletSalt`, `walletInitCodeHash`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function vaultAddress(instance: Pick<StreamInstance, "addresses" | "protocol">, payees: readonly Payee[], salt?: Hex): Address;
|
|
16
|
+
/** `vaultAddress` for a ledger and init code hash given directly. */
|
|
17
|
+
export declare function vaultAddressOf(ledger: Address, initCodeHash: Hex, payees: readonly Payee[], salt?: Hex): Address;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { encodeAbiParameters, getContractAddress, keccak256 } from "viem";
|
|
3
|
+
import { ZERO_HASH } from "../constants.js";
|
|
4
|
+
const PAYEES = [
|
|
5
|
+
{
|
|
6
|
+
type: "tuple[]",
|
|
7
|
+
components: [
|
|
8
|
+
{ name: "artistId", type: "uint256" },
|
|
9
|
+
{ name: "account", type: "address" },
|
|
10
|
+
{ name: "share", type: "uint32" },
|
|
11
|
+
],
|
|
12
|
+
},
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* The address of the vault (split wallet) of a payee list, computed here. A vault's address
|
|
16
|
+
* is fixed by its payees: the ledger creates it with CREATE2 from one init code, with the salt
|
|
17
|
+
* `keccak256(abi.encode(keccak256(abi.encode(payees)), salt))`. ETH sent to the address is
|
|
18
|
+
* held for the payees even before the vault is created.
|
|
19
|
+
*
|
|
20
|
+
* Use this, not an RPC's answer, for any vault address that goes into a signature.
|
|
21
|
+
*
|
|
22
|
+
* Contract: [`SplitLedger.walletFor`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/economics/SplitLedger.sol)
|
|
23
|
+
* (`_walletSalt`, `walletInitCodeHash`).
|
|
24
|
+
*/
|
|
25
|
+
export function vaultAddress(instance, payees, salt = ZERO_HASH) {
|
|
26
|
+
return vaultAddressOf(instance.addresses.splitLedger, instance.protocol.vaultInitCodeHash, payees, salt);
|
|
27
|
+
}
|
|
28
|
+
/** `vaultAddress` for a ledger and init code hash given directly. */
|
|
29
|
+
export function vaultAddressOf(ledger, initCodeHash, payees, salt = ZERO_HASH) {
|
|
30
|
+
const configHash = keccak256(encodeAbiParameters(PAYEES, [payees]));
|
|
31
|
+
return getContractAddress({
|
|
32
|
+
opcode: "CREATE2",
|
|
33
|
+
from: ledger,
|
|
34
|
+
salt: keccak256(encodeAbiParameters([{ type: "bytes32" }, { type: "bytes32" }], [configHash, salt])),
|
|
35
|
+
bytecodeHash: initCodeHash,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Address, type Hex } from "viem";
|
|
2
|
+
import type { StreamProtocol } from "../instance.js";
|
|
3
|
+
/** The changeable state of a work that a relicense, royalty or renounce signature binds. */
|
|
4
|
+
export interface WorkState {
|
|
5
|
+
/** The `WorkRules` contract. */
|
|
6
|
+
readonly rules: Address;
|
|
7
|
+
readonly token: Address;
|
|
8
|
+
readonly tokenId: bigint;
|
|
9
|
+
/** `WorkRules.versionOf(token, tokenId)`: counts the changes made so far. */
|
|
10
|
+
readonly version: number;
|
|
11
|
+
/** `factsOf(token, tokenId).recordFileId`. */
|
|
12
|
+
readonly recordFileId: Hex;
|
|
13
|
+
/** `factsOf(token, tokenId).licenseId`: the SPDX identifier as stored. */
|
|
14
|
+
readonly licenseId: string;
|
|
15
|
+
/** `factsOf(token, tokenId).licenseTextFileId`. */
|
|
16
|
+
readonly licenseTextFileId: Hex;
|
|
17
|
+
/** `workOf(tokenId).royaltyRate`, out of 100,000. */
|
|
18
|
+
readonly royaltyRate: number;
|
|
19
|
+
/** The token's RENDERER module before the work is finalized, the pinned renderer after. */
|
|
20
|
+
readonly renderer: Address;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A work's state hash. A signature over a change names the state it was made for, so it
|
|
24
|
+
* cannot be used after anything about the work changed.
|
|
25
|
+
*
|
|
26
|
+
* Rule: `keccak256(abi.encode(STATE_DOMAIN, rules, token, tokenId, version, recordFileId,
|
|
27
|
+
* licenseKey(licenseId), licenseTextFileId, royaltyRate, renderer))`.
|
|
28
|
+
*
|
|
29
|
+
* Contract: [`WorkRules.workStateHash`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
|
|
30
|
+
*/
|
|
31
|
+
export declare function workStateHash(protocol: StreamProtocol, state: WorkState): Hex;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { encodeAbiParameters, keccak256, toBytes } from "viem";
|
|
3
|
+
import { licenseKey } from "./items.js";
|
|
4
|
+
/**
|
|
5
|
+
* A work's state hash. A signature over a change names the state it was made for, so it
|
|
6
|
+
* cannot be used after anything about the work changed.
|
|
7
|
+
*
|
|
8
|
+
* Rule: `keccak256(abi.encode(STATE_DOMAIN, rules, token, tokenId, version, recordFileId,
|
|
9
|
+
* licenseKey(licenseId), licenseTextFileId, royaltyRate, renderer))`.
|
|
10
|
+
*
|
|
11
|
+
* Contract: [`WorkRules.workStateHash`](https://github.com/6529-Collections/6529-stream/blob/c6d4965861907841519cf3878c9db7052424a9a0/src/records/WorkRules.sol).
|
|
12
|
+
*/
|
|
13
|
+
export function workStateHash(protocol, state) {
|
|
14
|
+
return keccak256(encodeAbiParameters([
|
|
15
|
+
{ type: "bytes32" },
|
|
16
|
+
{ type: "address" },
|
|
17
|
+
{ type: "address" },
|
|
18
|
+
{ type: "uint256" },
|
|
19
|
+
{ type: "uint32" },
|
|
20
|
+
{ type: "bytes32" },
|
|
21
|
+
{ type: "bytes32" },
|
|
22
|
+
{ type: "bytes32" },
|
|
23
|
+
{ type: "uint24" },
|
|
24
|
+
{ type: "address" },
|
|
25
|
+
], [
|
|
26
|
+
keccak256(toBytes(protocol.labels.workState)),
|
|
27
|
+
state.rules,
|
|
28
|
+
state.token,
|
|
29
|
+
state.tokenId,
|
|
30
|
+
state.version,
|
|
31
|
+
state.recordFileId,
|
|
32
|
+
licenseKey(state.licenseId),
|
|
33
|
+
state.licenseTextFileId,
|
|
34
|
+
state.royaltyRate,
|
|
35
|
+
state.renderer,
|
|
36
|
+
]));
|
|
37
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 6529 Stream SDK: read a work, verify it, and use the contracts.
|
|
3
|
+
*
|
|
4
|
+
* Pre-audit. Test networks only. See README.md for what each part covers, and
|
|
5
|
+
* docs/reference.md for every function with the contract function behind it.
|
|
6
|
+
*/
|
|
7
|
+
export * from "./constants.js";
|
|
8
|
+
export * from "./errors.js";
|
|
9
|
+
export * from "./instance.js";
|
|
10
|
+
export * from "./generated/instances.js";
|
|
11
|
+
export * from "./types.js";
|
|
12
|
+
export * from "./display.js";
|
|
13
|
+
export * from "./hashing/items.js";
|
|
14
|
+
export * from "./hashing/packages.js";
|
|
15
|
+
export { manifestId, prepareFile, splitChunks, type Manifest, type PreparedFile } from "./hashing/content.js";
|
|
16
|
+
export * from "./hashing/ids.js";
|
|
17
|
+
export * from "./hashing/workState.js";
|
|
18
|
+
export * from "./hashing/vault.js";
|
|
19
|
+
export * from "./signing/messages.js";
|
|
20
|
+
export * from "./encoding.js";
|
|
21
|
+
export * from "./items.js";
|
|
22
|
+
export { chainDeadline, chainTime, isContractRevert, scanEvents, type LogScanOptions } from "./reads/chain.js";
|
|
23
|
+
export * from "./reads/workPage.js";
|
|
24
|
+
export * from "./reads/creation.js";
|
|
25
|
+
export * from "./reads/work.js";
|
|
26
|
+
export * from "./reads/metadata.js";
|
|
27
|
+
export * from "./reads/vault.js";
|
|
28
|
+
export * from "./reads/money.js";
|
|
29
|
+
export * from "./reads/sale.js";
|
|
30
|
+
export * from "./reads/editionSale.js";
|
|
31
|
+
export * from "./reads/accounts.js";
|
|
32
|
+
export * from "./reads/network.js";
|
|
33
|
+
export { chainManifestId, decodeStored, verifyFetched, verifyStored, type ChainManifest } from "./files/verify.js";
|
|
34
|
+
export * from "./files/fetch.js";
|
|
35
|
+
export type { Sent, StreamClients } from "./actions/shared.js";
|
|
36
|
+
export * from "./actions/content.js";
|
|
37
|
+
export * from "./actions/curated.js";
|
|
38
|
+
export * from "./actions/independent.js";
|
|
39
|
+
export * from "./actions/sale.js";
|
|
40
|
+
export * from "./actions/editions.js";
|
|
41
|
+
export * from "./actions/vault.js";
|
|
42
|
+
export * from "./actions/money.js";
|
|
43
|
+
export * from "./actions/record.js";
|
|
44
|
+
export * from "./actions/accounts.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
/**
|
|
3
|
+
* 6529 Stream SDK: read a work, verify it, and use the contracts.
|
|
4
|
+
*
|
|
5
|
+
* Pre-audit. Test networks only. See README.md for what each part covers, and
|
|
6
|
+
* docs/reference.md for every function with the contract function behind it.
|
|
7
|
+
*/
|
|
8
|
+
export * from "./constants.js";
|
|
9
|
+
export * from "./errors.js";
|
|
10
|
+
export * from "./instance.js";
|
|
11
|
+
export * from "./generated/instances.js";
|
|
12
|
+
export * from "./types.js";
|
|
13
|
+
export * from "./display.js";
|
|
14
|
+
// Hashing, signed messages, encodings
|
|
15
|
+
export * from "./hashing/items.js";
|
|
16
|
+
export * from "./hashing/packages.js";
|
|
17
|
+
export { manifestId, prepareFile, splitChunks } from "./hashing/content.js";
|
|
18
|
+
export * from "./hashing/ids.js";
|
|
19
|
+
export * from "./hashing/workState.js";
|
|
20
|
+
export * from "./hashing/vault.js";
|
|
21
|
+
export * from "./signing/messages.js";
|
|
22
|
+
export * from "./encoding.js";
|
|
23
|
+
export * from "./items.js";
|
|
24
|
+
// Reads
|
|
25
|
+
export { chainDeadline, chainTime, isContractRevert, scanEvents } from "./reads/chain.js";
|
|
26
|
+
export * from "./reads/workPage.js";
|
|
27
|
+
export * from "./reads/creation.js";
|
|
28
|
+
export * from "./reads/work.js";
|
|
29
|
+
export * from "./reads/metadata.js";
|
|
30
|
+
export * from "./reads/vault.js";
|
|
31
|
+
export * from "./reads/money.js";
|
|
32
|
+
export * from "./reads/sale.js";
|
|
33
|
+
export * from "./reads/editionSale.js";
|
|
34
|
+
export * from "./reads/accounts.js";
|
|
35
|
+
export * from "./reads/network.js";
|
|
36
|
+
// Files
|
|
37
|
+
export { chainManifestId, decodeStored, verifyFetched, verifyStored } from "./files/verify.js";
|
|
38
|
+
export * from "./files/fetch.js";
|
|
39
|
+
export * from "./actions/content.js";
|
|
40
|
+
export * from "./actions/curated.js";
|
|
41
|
+
export * from "./actions/independent.js";
|
|
42
|
+
export * from "./actions/sale.js";
|
|
43
|
+
export * from "./actions/editions.js";
|
|
44
|
+
export * from "./actions/vault.js";
|
|
45
|
+
export * from "./actions/money.js";
|
|
46
|
+
export * from "./actions/record.js";
|
|
47
|
+
export * from "./actions/accounts.js";
|