@fangorn-network/sdk 0.2.1 → 0.2.2

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.
@@ -20,6 +20,46 @@ function assertStoredBlock(returned, block) {
20
20
  const want = CID.createV1(RAW_CODE, block.cid.multihash);
21
21
  if (!cid?.equals(want)) throw new Error(`storage stored block ${block.cid.toString()} as ${JSON.stringify(returned)}, expected ${want.toString()}: readers could not fetch it`);
22
22
  }
23
+ /**
24
+ * The root CID of `content` imported as a UnixFS file in kubo's layout (CIDv1, raw leaves of 256 KiB, balanced,
25
+ * `fanout` links a node), which is how Pinata stores an upload. Built from the bytes alone, so a match proves the
26
+ * CID commits to them without fetching anything.
27
+ */
28
+ async function kuboFileRoot(content, fanout) {
29
+ const CHUNK = 262144;
30
+ let level = [];
31
+ for (let o = 0; o < content.length; o += CHUNK) {
32
+ const leaf = content.subarray(o, o + CHUNK);
33
+ level.push({
34
+ cid: CID.createV1(RAW_CODE, await sha256.digest(leaf)),
35
+ size: leaf.length,
36
+ tsize: leaf.length
37
+ });
38
+ }
39
+ while (level.length > 1) {
40
+ const next = [];
41
+ for (let i = 0; i < level.length; i += fanout) {
42
+ const kids = level.slice(i, i + fanout);
43
+ const file = new UnixFS({ type: "file" });
44
+ for (const k of kids) file.addBlockSize(BigInt(k.size));
45
+ const node = dagPb.encode(dagPb.prepare({
46
+ Data: file.marshal(),
47
+ Links: kids.map((k) => ({
48
+ Hash: k.cid,
49
+ Name: "",
50
+ Tsize: k.tsize
51
+ }))
52
+ }));
53
+ next.push({
54
+ cid: CID.createV1(dagPb.code, await sha256.digest(node)),
55
+ size: kids.reduce((s, k) => s + k.size, 0),
56
+ tsize: node.length + kids.reduce((s, k) => s + k.tsize, 0)
57
+ });
58
+ }
59
+ level = next;
60
+ }
61
+ return level[0]?.cid;
62
+ }
23
63
  /** Verify the file reference before including it in a commit or paid handle. */
24
64
  async function assertStoredFile(returned, bytes, storage) {
25
65
  const root = CID.parse(returned.replace(/^ipfs:\/\//, ""));
@@ -47,6 +87,9 @@ async function assertStoredFile(returned, bytes, storage) {
47
87
  offset = end;
48
88
  }
49
89
  }
90
+ if (root.code === dagPb.code) {
91
+ for (const fanout of [174, 1024]) if ((await kuboFileRoot(bytes, fanout))?.equals(root)) return;
92
+ }
50
93
  await verify(root, bytes, 0);
51
94
  }
52
95
 
@@ -3,12 +3,12 @@ import { CommitUpdate, LogFilter, Registry, RepoRef, UpdateEntry } from "../cont
3
3
  import { Mmr } from "../contracts/data-registry/mmr.js";
4
4
  import "../contracts/index.js";
5
5
  import "../index.js";
6
- import * as viem6075 from "viem";
6
+ import * as viem237 from "viem";
7
7
  import { Address, Hash, Hex, LocalAccount } from "viem";
8
8
 
9
9
  //#region src/test/mem-registry.d.ts
10
10
  /** The EIP-712 domain a MemRegistry signs under. */
11
- declare const MEM_DOMAIN: viem6075.TypedDataDomain;
11
+ declare const MEM_DOMAIN: viem237.TypedDataDomain;
12
12
  /** One ordering and the registry state over it, shared by every signer of a MemRegistry. */
13
13
  declare class MemLedger {
14
14
  /** H: position and head */