@fangorn-network/sdk 2026.7.12 → 2026.7.14
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/README.md +104 -69
- package/lib/cli/cli.js +26 -19
- package/lib/cli/index.d.ts +13 -13
- package/lib/config.d.ts +93 -92
- package/lib/contracts/data-registry/abi.d.ts +207 -35
- package/lib/contracts/data-registry/index.js +4 -4
- package/lib/contracts/index.d.ts +3 -1
- package/lib/contracts/index.js +3 -1
- package/lib/contracts/settlement-registry/abi.d.ts +47 -0
- package/lib/contracts/settlement-registry/abi.js +48 -0
- package/lib/contracts/settlement-registry/index.d.ts +25 -0
- package/lib/contracts/settlement-registry/index.js +40 -0
- package/lib/crypto/aes.d.ts +1 -8
- package/lib/crypto/aes.js +2 -34
- package/lib/crypto/encryption.d.ts +112 -26
- package/lib/crypto/encryption.js +105 -21
- package/lib/engine/car.d.ts +10 -0
- package/lib/engine/car.js +37 -0
- package/lib/engine/graph.d.ts +70 -0
- package/lib/engine/graph.js +73 -0
- package/lib/engine/index.d.ts +109 -70
- package/lib/engine/index.js +296 -226
- package/lib/engine/test-helpers.d.ts +43 -0
- package/lib/engine/test-helpers.js +69 -0
- package/lib/fangorn.d.ts +28 -25
- package/lib/fangorn.js +118 -83
- package/lib/harness/index.d.ts +4 -3
- package/lib/harness/index.js +9 -3
- package/lib/index.d.ts +3 -3
- package/lib/index.js +2 -2
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/_polyval.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/aes.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_ciphers@1.3.0/node_modules/@noble → @noble}/ciphers/esm/utils.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/curve.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/edwards.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/modular.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/abstract/montgomery.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/ed25519.js +1 -1
- package/lib/node_modules/{.pnpm/@noble_curves@1.9.7/node_modules/@noble → @noble}/curves/esm/utils.js +1 -1
- package/lib/providers/storage/car.js +2 -1
- package/lib/providers/storage/pinata.d.ts +16 -9
- package/lib/providers/storage/pinata.js +34 -25
- package/lib/providers/storage/types.d.ts +18 -8
- package/lib/{roles/repo → repo}/index.d.ts +1 -1
- package/lib/{roles/repo → repo}/index.js +1 -1
- package/lib/test/testbed.d.ts +9 -7
- package/lib/test/testbed.js +3 -2
- package/package.json +3 -9
- package/lib/ crypto/constants.d.ts +0 -4
- package/lib/ crypto/constants.js +0 -5
- package/lib/ crypto/merkle.d.ts +0 -10
- package/lib/ crypto/merkle.js +0 -34
- package/lib/ crypto/utils.d.ts +0 -1
- package/lib/ crypto/utils.js +0 -1
- package/lib/builders/a2aCardBuilder.d.ts +0 -28
- package/lib/builders/a2aCardBuilder.js +0 -105
- package/lib/engine/blockstore.d.ts +0 -24
- package/lib/engine/blockstore.js +0 -85
- package/lib/roles/index.d.ts +0 -1
- package/lib/roles/index.js +0 -1
- package/lib/test/car_smoke.d.ts +0 -1
- package/lib/test/car_smoke.js +0 -81
- package/lib/test/cleanup-embeddings-testdata.d.ts +0 -1
- package/lib/test/cleanup-embeddings-testdata.js +0 -75
- package/lib/test/index.d.ts +0 -10
- package/lib/test/index.js +0 -27
- package/lib/test/setup-embeddings-testdata.d.ts +0 -11
- package/lib/test/setup-embeddings-testdata.js +0 -155
- package/lib/utils/index.d.ts +0 -11
- package/lib/utils/index.js +0 -29
- package/lib/utils/manifest.d.ts +0 -23
- package/lib/utils/manifest.js +0 -77
package/lib/test/car_smoke.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { PinataBackend } from "../providers/storage/pinata.js";
|
|
2
|
-
import "dotenv/config";
|
|
3
|
-
|
|
4
|
-
//#region src/test/car_smoke.ts
|
|
5
|
-
async function main() {
|
|
6
|
-
const jwt = process.env.PINATA_JWT;
|
|
7
|
-
const gateway = process.env.PINATA_GATEWAY;
|
|
8
|
-
if (!jwt || !gateway) throw new Error("Set PINATA_JWT and PINATA_GATEWAY");
|
|
9
|
-
const backend = new PinataBackend(jwt, gateway);
|
|
10
|
-
const items = [
|
|
11
|
-
{
|
|
12
|
-
name: "chunk-small:0",
|
|
13
|
-
data: [{
|
|
14
|
-
id: "a",
|
|
15
|
-
v: 1
|
|
16
|
-
}, {
|
|
17
|
-
id: "b",
|
|
18
|
-
v: 2
|
|
19
|
-
}]
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
name: "chunk-big:1",
|
|
23
|
-
data: Array.from({ length: 4e4 }, (_, i) => ({
|
|
24
|
-
id: `r${i.toString()}`,
|
|
25
|
-
blob: "x".repeat(40)
|
|
26
|
-
}))
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: "chunk-bytes:2",
|
|
30
|
-
data: {
|
|
31
|
-
tag: "u8",
|
|
32
|
-
bytes: new Uint8Array([
|
|
33
|
-
1,
|
|
34
|
-
2,
|
|
35
|
-
3,
|
|
36
|
-
250,
|
|
37
|
-
255
|
|
38
|
-
])
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
];
|
|
42
|
-
console.log(`[smoke] packing + uploading ${items.length.toString()} chunks as one CAR...`);
|
|
43
|
-
const t0 = Date.now();
|
|
44
|
-
const cidByName = await backend.putMany(items);
|
|
45
|
-
console.log(`[smoke] uploaded in ${((Date.now() - t0) / 1e3).toFixed(1)}s`);
|
|
46
|
-
for (const { name } of items) console.log(` ${name} -> ${cidByName[name]}`);
|
|
47
|
-
console.log(`[smoke] retrieving each chunk by its standalone CID...`);
|
|
48
|
-
let ok = true;
|
|
49
|
-
for (const { name, data } of items) {
|
|
50
|
-
const cid = cidByName[name];
|
|
51
|
-
if (!cid) {
|
|
52
|
-
console.error(` ✘ ${name}: no CID returned`);
|
|
53
|
-
ok = false;
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
try {
|
|
57
|
-
const got = await backend.get(cid);
|
|
58
|
-
const match = JSON.stringify(got) === JSON.stringify(data);
|
|
59
|
-
console.log(` ${match ? "✓" : "✘"} ${name} (${cid})`);
|
|
60
|
-
if (!match) {
|
|
61
|
-
ok = false;
|
|
62
|
-
console.error(` expected ${JSON.stringify(data).slice(0, 80)}\n got ${JSON.stringify(got).slice(0, 80)}`);
|
|
63
|
-
}
|
|
64
|
-
} catch (err) {
|
|
65
|
-
ok = false;
|
|
66
|
-
console.error(` ✘ ${name} (${cid}): ${err.message}`);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (!ok) {
|
|
70
|
-
console.error("\n[smoke] FAILED — CAR sub-blocks are not independently retrievable");
|
|
71
|
-
process.exit(1);
|
|
72
|
-
}
|
|
73
|
-
console.log("\n[smoke] ✅ CAR path verified: every chunk CID resolves via the gateway.");
|
|
74
|
-
}
|
|
75
|
-
main().catch((err) => {
|
|
76
|
-
console.error("[smoke] failed:", err);
|
|
77
|
-
process.exit(1);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
//#endregion
|
|
81
|
-
export { };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { LEDGER_FILE } from "./setup-embeddings-testdata.js";
|
|
2
|
-
import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
|
|
4
|
-
//#region src/test/cleanup-embeddings-testdata.ts
|
|
5
|
-
/**
|
|
6
|
-
* Cleanup counterpart to setup-embeddings-testdata.ts.
|
|
7
|
-
*
|
|
8
|
-
* Reads the ledger written by the setup script and best-effort unpins, for
|
|
9
|
-
* every recorded run, the vertex CIDs it uploaded from Pinata. On-chain state
|
|
10
|
-
* (the namespace root) is not rewound — only `fangorn.reset()` (destructive,
|
|
11
|
-
* wipes ALL namespaces for that owner) can do that; this script only reclaims
|
|
12
|
-
* the IPFS pins for the vertex payloads themselves. Intermediate Pail shard
|
|
13
|
-
* blocks created alongside them are not individually tracked and are left
|
|
14
|
-
* pinned (they're small, content-addressed, and shared across commits).
|
|
15
|
-
*
|
|
16
|
-
* Run it:
|
|
17
|
-
*
|
|
18
|
-
* pnpm cleanup:embeddings
|
|
19
|
-
* # or: pnpm dotenvx run -f .env -- tsx src/test/cleanup-embeddings-testdata.ts
|
|
20
|
-
*
|
|
21
|
-
* The ledger is deleted only if every CID unpinned cleanly.
|
|
22
|
-
*/
|
|
23
|
-
const PINATA_JWT = process.env.PINATA_JWT ?? "";
|
|
24
|
-
async function unpinFromPinata(cid) {
|
|
25
|
-
try {
|
|
26
|
-
const response = await fetch(`https://api.pinata.cloud/pinning/unpin/${cid}`, {
|
|
27
|
-
method: "DELETE",
|
|
28
|
-
headers: { Authorization: `Bearer ${PINATA_JWT}` }
|
|
29
|
-
});
|
|
30
|
-
if (response.ok) {
|
|
31
|
-
console.log(` ✓ unpinned ${cid}`);
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
if (response.status === 404) {
|
|
35
|
-
console.log(` - ${cid} not pinned (already gone)`);
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
console.warn(` ✗ ${cid}: ${response.status.toString()} ${response.statusText}`);
|
|
39
|
-
return false;
|
|
40
|
-
} catch (err) {
|
|
41
|
-
console.warn(` ✗ ${cid}: request failed`, err);
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
async function main() {
|
|
46
|
-
if (!PINATA_JWT) throw new Error("PINATA_JWT is required to unpin.");
|
|
47
|
-
if (!existsSync(LEDGER_FILE)) {
|
|
48
|
-
console.log(`[cleanup] no ledger at ${LEDGER_FILE} — nothing to clean up.`);
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const entries = JSON.parse(readFileSync(LEDGER_FILE, "utf8"));
|
|
52
|
-
if (entries.length === 0) {
|
|
53
|
-
console.log("[cleanup] ledger is empty — nothing to clean up.");
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
let allOk = true;
|
|
57
|
-
for (const entry of entries) {
|
|
58
|
-
console.log(`\n[cleanup] ${entry.owner}/${entry.namespace} (commit ${entry.commitCid})`);
|
|
59
|
-
for (const cid of entry.vertexCids) {
|
|
60
|
-
const ok = await unpinFromPinata(cid);
|
|
61
|
-
allOk = allOk && ok;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (allOk) {
|
|
65
|
-
writeFileSync(LEDGER_FILE, "[]");
|
|
66
|
-
console.log(`\n✅ Cleanup complete. Cleared ${LEDGER_FILE}.`);
|
|
67
|
-
} else console.log(`\n⚠️ Cleanup finished with some failures — ledger left in place (${LEDGER_FILE}) so you can re-run.`);
|
|
68
|
-
}
|
|
69
|
-
main().catch((err) => {
|
|
70
|
-
console.error("\n[cleanup] failed:", err);
|
|
71
|
-
process.exit(1);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
//#endregion
|
|
75
|
-
export { };
|
package/lib/test/index.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { TestBed } from "./testbed.js";
|
|
2
|
-
|
|
3
|
-
//#region src/test/index.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Uploads any data to IPFS via Pinata
|
|
7
|
-
*/
|
|
8
|
-
declare function uploadToPinata(name: string, data: unknown, pinataJwt?: string): Promise<string>;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { TestBed, uploadToPinata };
|
package/lib/test/index.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { TestBed } from "./testbed.js";
|
|
2
|
-
|
|
3
|
-
//#region src/test/index.ts
|
|
4
|
-
/**
|
|
5
|
-
* Uploads any data to IPFS via Pinata
|
|
6
|
-
*/
|
|
7
|
-
async function uploadToPinata(name, data, pinataJwt) {
|
|
8
|
-
const jwt = pinataJwt ?? process.env.PINATA_JWT;
|
|
9
|
-
if (!jwt) throw new Error("PINATA_JWT is required");
|
|
10
|
-
const content = typeof data === "object" && !(data instanceof Blob) ? JSON.stringify(data) : data;
|
|
11
|
-
const contentType = typeof data === "object" ? "application/json" : "text/plain";
|
|
12
|
-
const form = new FormData();
|
|
13
|
-
form.append("file", new Blob([content], { type: contentType }), name);
|
|
14
|
-
const response = await fetch("https://api.pinata.cloud/pinning/pinFileToIPFS", {
|
|
15
|
-
method: "POST",
|
|
16
|
-
headers: { Authorization: `Bearer ${jwt}` },
|
|
17
|
-
body: form
|
|
18
|
-
});
|
|
19
|
-
if (!response.ok) {
|
|
20
|
-
const text = await response.text();
|
|
21
|
-
throw new Error(`Upload failed: ${String(response.status)} - ${text}`);
|
|
22
|
-
}
|
|
23
|
-
return (await response.json()).IpfsHash;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
export { TestBed, uploadToPinata };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//#region src/test/setup-embeddings-testdata.d.ts
|
|
2
|
-
declare const LEDGER_FILE: string;
|
|
3
|
-
interface LedgerEntry {
|
|
4
|
-
owner: string;
|
|
5
|
-
namespace: string;
|
|
6
|
-
commitCid: string;
|
|
7
|
-
vertexCids: string[];
|
|
8
|
-
createdAt: string;
|
|
9
|
-
}
|
|
10
|
-
//#endregion
|
|
11
|
-
export { LEDGER_FILE, LedgerEntry };
|
|
@@ -1,155 +0,0 @@
|
|
|
1
|
-
import { TestBed } from "./testbed.js";
|
|
2
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
-
import { dirname } from "node:path";
|
|
4
|
-
|
|
5
|
-
//#region src/test/setup-embeddings-testdata.ts
|
|
6
|
-
/**
|
|
7
|
-
* Test-data setup for the Python embeddings builder (quickbeam), owner+namespace model.
|
|
8
|
-
*
|
|
9
|
-
* Uploads a handful of joined Track/Artist vertices+edges into a namespace as a
|
|
10
|
-
* single batch commit. This is exactly the shape quickbeam's `fangorn read`
|
|
11
|
-
* consumer expects:
|
|
12
|
-
*
|
|
13
|
-
* fangorn read <namespace> --owner <address> --pretty
|
|
14
|
-
* python -m quickbeam build --source <address>:<namespace>
|
|
15
|
-
*
|
|
16
|
-
* Run it (loads .env the same way the e2e suite does):
|
|
17
|
-
*
|
|
18
|
-
* pnpm dotenvx run -f .env -- tsx src/test/setup-embeddings-testdata.ts
|
|
19
|
-
* # or: pnpm setup:embeddings
|
|
20
|
-
*
|
|
21
|
-
* On success it prints the --source argument to paste into the builder.
|
|
22
|
-
*/
|
|
23
|
-
const LEDGER_FILE = process.env.EMBEDDINGS_TESTDATA_LEDGER ?? "tmp/embeddings-testdata.json";
|
|
24
|
-
function appendLedger(entry) {
|
|
25
|
-
let entries = [];
|
|
26
|
-
if (existsSync(LEDGER_FILE)) try {
|
|
27
|
-
entries = JSON.parse(readFileSync(LEDGER_FILE, "utf8"));
|
|
28
|
-
} catch {
|
|
29
|
-
entries = [];
|
|
30
|
-
}
|
|
31
|
-
entries.push(entry);
|
|
32
|
-
mkdirSync(dirname(LEDGER_FILE), { recursive: true });
|
|
33
|
-
writeFileSync(LEDGER_FILE, JSON.stringify(entries, null, 2));
|
|
34
|
-
}
|
|
35
|
-
const SK = process.env.ETH_PRIVATE_KEY;
|
|
36
|
-
const VERTICES = [
|
|
37
|
-
{
|
|
38
|
-
id: "artist-aurora",
|
|
39
|
-
tag: "artist",
|
|
40
|
-
payload: {
|
|
41
|
-
name: "Aurora Skies",
|
|
42
|
-
country: "Norway"
|
|
43
|
-
}
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
id: "artist-monsoon",
|
|
47
|
-
tag: "artist",
|
|
48
|
-
payload: {
|
|
49
|
-
name: "Monsoon Collective",
|
|
50
|
-
country: "India"
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
id: "track-northern-lights",
|
|
55
|
-
tag: "track",
|
|
56
|
-
payload: {
|
|
57
|
-
title: "Northern Lights",
|
|
58
|
-
byArtist: "Aurora Skies",
|
|
59
|
-
genre: "ambient",
|
|
60
|
-
mood: "calm"
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
{
|
|
64
|
-
id: "track-glacier",
|
|
65
|
-
tag: "track",
|
|
66
|
-
payload: {
|
|
67
|
-
title: "Glacier Drift",
|
|
68
|
-
byArtist: "Aurora Skies",
|
|
69
|
-
genre: "ambient",
|
|
70
|
-
mood: "cold"
|
|
71
|
-
}
|
|
72
|
-
},
|
|
73
|
-
{
|
|
74
|
-
id: "track-monsoon-rain",
|
|
75
|
-
tag: "track",
|
|
76
|
-
payload: {
|
|
77
|
-
title: "Monsoon Rain",
|
|
78
|
-
byArtist: "Monsoon Collective",
|
|
79
|
-
genre: "world",
|
|
80
|
-
mood: "warm"
|
|
81
|
-
}
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
id: "track-tabla-pulse",
|
|
85
|
-
tag: "track",
|
|
86
|
-
payload: {
|
|
87
|
-
title: "Tabla Pulse",
|
|
88
|
-
byArtist: "Monsoon Collective",
|
|
89
|
-
genre: "world",
|
|
90
|
-
mood: "energetic"
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
];
|
|
94
|
-
const EDGES = [
|
|
95
|
-
{
|
|
96
|
-
rel: "performed_by",
|
|
97
|
-
from: "track-northern-lights",
|
|
98
|
-
to: "artist-aurora"
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
rel: "performed_by",
|
|
102
|
-
from: "track-glacier",
|
|
103
|
-
to: "artist-aurora"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
rel: "performed_by",
|
|
107
|
-
from: "track-monsoon-rain",
|
|
108
|
-
to: "artist-monsoon"
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
rel: "performed_by",
|
|
112
|
-
from: "track-tabla-pulse",
|
|
113
|
-
to: "artist-monsoon"
|
|
114
|
-
}
|
|
115
|
-
];
|
|
116
|
-
function requireEnv() {
|
|
117
|
-
const missing = [];
|
|
118
|
-
if (!SK) missing.push("ETH_PRIVATE_KEY");
|
|
119
|
-
if (!process.env.PINATA_JWT) missing.push("PINATA_JWT");
|
|
120
|
-
if (!process.env.PINATA_GATEWAY) missing.push("PINATA_GATEWAY");
|
|
121
|
-
if (missing.length) throw new Error(`Missing required env vars: ${missing.join(", ")}.\nRun via: pnpm dotenvx run -f .env -- tsx src/test/setup-embeddings-testdata.ts`);
|
|
122
|
-
}
|
|
123
|
-
async function main() {
|
|
124
|
-
requireEnv();
|
|
125
|
-
const testbed = TestBed.init([SK]);
|
|
126
|
-
const owner = testbed.getFangorn(0).getAddress();
|
|
127
|
-
console.log("[setup] ensuring publisher is registered...");
|
|
128
|
-
await testbed.register(0);
|
|
129
|
-
const namespace = `fangorn.music.${Date.now().toString()}`;
|
|
130
|
-
console.log(`[setup] initializing namespace "${namespace}"...`);
|
|
131
|
-
await testbed.initRepo(0, namespace);
|
|
132
|
-
console.log(`[setup] uploading ${VERTICES.length.toString()} vertices / ${EDGES.length.toString()} edges as one batch commit...`);
|
|
133
|
-
const result = await testbed.uploadBatch(0, namespace, VERTICES, EDGES);
|
|
134
|
-
appendLedger({
|
|
135
|
-
owner,
|
|
136
|
-
namespace,
|
|
137
|
-
commitCid: result.commitCid,
|
|
138
|
-
vertexCids: Object.values(result.vertexCids),
|
|
139
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
140
|
-
});
|
|
141
|
-
console.log("\n✅ Test data published.\n");
|
|
142
|
-
console.log(` owner : ${owner}`);
|
|
143
|
-
console.log(` namespace : ${namespace}`);
|
|
144
|
-
console.log(` commit cid : ${result.commitCid}`);
|
|
145
|
-
console.log("\nFeed the embeddings builder with:\n");
|
|
146
|
-
console.log(` quickbeam build --source ${owner}:${namespace}\n`);
|
|
147
|
-
console.log(`Recorded in ${LEDGER_FILE} — unpin later with: pnpm cleanup:embeddings\n`);
|
|
148
|
-
}
|
|
149
|
-
main().catch((err) => {
|
|
150
|
-
console.error("\n[setup] failed:", err);
|
|
151
|
-
process.exit(1);
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
//#endregion
|
|
155
|
-
export { LEDGER_FILE };
|
package/lib/utils/index.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { Address, Hex } from "viem";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/index.d.ts
|
|
4
|
-
declare function stringToBytes32Array(str: string): number[];
|
|
5
|
-
declare function hexToBytes32Array(hex: `0x${string}`): number[];
|
|
6
|
-
declare function addressToBytes32Array(address: Address): number[];
|
|
7
|
-
declare function fieldToHex(field: bigint): `0x${string}`;
|
|
8
|
-
declare function hexToField(hex: string): bigint;
|
|
9
|
-
declare function computeSchemaId(name: string): Hex;
|
|
10
|
-
//#endregion
|
|
11
|
-
export { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
|
package/lib/utils/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { encodeAbiParameters, keccak256, parseAbiParameters } from "viem";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/index.ts
|
|
4
|
-
function stringToBytes32Array(str) {
|
|
5
|
-
const padded = str.padEnd(32, "\0");
|
|
6
|
-
return Array.from(new TextEncoder().encode(padded)).slice(0, 32);
|
|
7
|
-
}
|
|
8
|
-
function hexToBytes32Array(hex) {
|
|
9
|
-
const padded = hex.slice(2).padStart(64, "0");
|
|
10
|
-
return Array.from(Buffer.from(padded, "hex"));
|
|
11
|
-
}
|
|
12
|
-
function addressToBytes32Array(address) {
|
|
13
|
-
const clean = address.slice(2).toLowerCase();
|
|
14
|
-
const bytes20 = Array.from(Buffer.from(clean, "hex"));
|
|
15
|
-
return [...new Array(12).fill(0), ...bytes20];
|
|
16
|
-
}
|
|
17
|
-
function fieldToHex(field) {
|
|
18
|
-
return `0x${field.toString(16).padStart(64, "0")}`;
|
|
19
|
-
}
|
|
20
|
-
function hexToField(hex) {
|
|
21
|
-
const cleanHex = hex.startsWith("0x") ? hex : `0x${hex}`;
|
|
22
|
-
return BigInt(cleanHex);
|
|
23
|
-
}
|
|
24
|
-
function computeSchemaId(name) {
|
|
25
|
-
return keccak256(encodeAbiParameters(parseAbiParameters("string"), [name]));
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
export { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
|
package/lib/utils/manifest.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { Address, Hex } from "viem";
|
|
2
|
-
|
|
3
|
-
//#region src/utils/manifest.d.ts
|
|
4
|
-
declare function poseidonHash(inputs: bigint[]): bigint;
|
|
5
|
-
declare function hashString(value: string): bigint;
|
|
6
|
-
interface ManifestLeaf {
|
|
7
|
-
index: bigint;
|
|
8
|
-
name: string;
|
|
9
|
-
}
|
|
10
|
-
declare class MerkleTree {
|
|
11
|
-
protected constructor();
|
|
12
|
-
static leafHash(leaf: ManifestLeaf): bigint;
|
|
13
|
-
static buildTree(leaves: ManifestLeaf[]): {
|
|
14
|
-
root: bigint;
|
|
15
|
-
layers: bigint[][];
|
|
16
|
-
};
|
|
17
|
-
static buildProof(layers: bigint[][], index: number): bigint[];
|
|
18
|
-
static rootToHex(root: bigint): Hex;
|
|
19
|
-
}
|
|
20
|
-
/** Off-chain datasource resourceId: keccak(owner ‖ schemaId ‖ keccak(name)). */
|
|
21
|
-
declare function resourceId(owner: Address, schemaId: Hex, name: string): Hex;
|
|
22
|
-
//#endregion
|
|
23
|
-
export { ManifestLeaf, MerkleTree, hashString, poseidonHash, resourceId };
|
package/lib/utils/manifest.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { encodePacked, keccak256 } from "viem";
|
|
2
|
-
import { poseidon2 } from "poseidon-lite";
|
|
3
|
-
|
|
4
|
-
//#region src/utils/manifest.ts
|
|
5
|
-
const MODULUS = 21888242871839275222246405745257275088548364400416034343698204186575808495617n;
|
|
6
|
-
function normalize(v) {
|
|
7
|
-
return (v % MODULUS + MODULUS) % MODULUS;
|
|
8
|
-
}
|
|
9
|
-
function poseidonHash(inputs) {
|
|
10
|
-
return poseidon2(inputs.map(normalize));
|
|
11
|
-
}
|
|
12
|
-
function bytesToField(chunk) {
|
|
13
|
-
let acc = 0n;
|
|
14
|
-
for (const b of chunk) acc = acc << 8n | BigInt(b);
|
|
15
|
-
return acc;
|
|
16
|
-
}
|
|
17
|
-
function hashString(value) {
|
|
18
|
-
const bytes = new TextEncoder().encode(value);
|
|
19
|
-
let h = 0n;
|
|
20
|
-
for (let i = 0; i < bytes.length; i += 31) h = poseidonHash([h, bytesToField(bytes.subarray(i, i + 31))]);
|
|
21
|
-
return h;
|
|
22
|
-
}
|
|
23
|
-
var MerkleTree = class MerkleTree {
|
|
24
|
-
constructor() {
|
|
25
|
-
throw new Error("MerkleTree is a static utility class and cannot be instantiated.");
|
|
26
|
-
}
|
|
27
|
-
static leafHash(leaf) {
|
|
28
|
-
return poseidonHash([leaf.index, hashString(leaf.name)]);
|
|
29
|
-
}
|
|
30
|
-
static buildTree(leaves) {
|
|
31
|
-
if (leaves.length === 0) throw new Error("Empty tree");
|
|
32
|
-
let current = [...leaves].sort((a, b) => Number(a.index - b.index)).map((leaf) => MerkleTree.leafHash(leaf));
|
|
33
|
-
const layers = [current];
|
|
34
|
-
while (current.length > 1) {
|
|
35
|
-
const next = [];
|
|
36
|
-
for (let i = 0; i < current.length; i += 2) {
|
|
37
|
-
const left = current[i];
|
|
38
|
-
const right = current[i + 1] ?? left;
|
|
39
|
-
next.push(poseidonHash([left, right]));
|
|
40
|
-
}
|
|
41
|
-
current = next;
|
|
42
|
-
layers.push(next);
|
|
43
|
-
}
|
|
44
|
-
return {
|
|
45
|
-
root: current[0],
|
|
46
|
-
layers
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
static buildProof(layers, index) {
|
|
50
|
-
const proof = [];
|
|
51
|
-
for (let d = 0; d < layers.length - 1; d++) {
|
|
52
|
-
const layer = layers[d];
|
|
53
|
-
const sibling = index % 2 === 0 ? layer[index + 1] ?? layer[index] : layer[index - 1];
|
|
54
|
-
proof.push(sibling);
|
|
55
|
-
index = Math.floor(index / 2);
|
|
56
|
-
}
|
|
57
|
-
return proof;
|
|
58
|
-
}
|
|
59
|
-
static rootToHex(root) {
|
|
60
|
-
return `0x${root.toString(16).padStart(64, "0")}`;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
/** Off-chain datasource resourceId: keccak(owner ‖ schemaId ‖ keccak(name)). */
|
|
64
|
-
function resourceId(owner, schemaId, name) {
|
|
65
|
-
return keccak256(encodePacked([
|
|
66
|
-
"address",
|
|
67
|
-
"bytes32",
|
|
68
|
-
"bytes32"
|
|
69
|
-
], [
|
|
70
|
-
owner,
|
|
71
|
-
schemaId,
|
|
72
|
-
keccak256(new TextEncoder().encode(name))
|
|
73
|
-
]));
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
//#endregion
|
|
77
|
-
export { MerkleTree, hashString, poseidonHash, resourceId };
|