@fangorn-network/sdk 2026.7.13 → 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 +23 -2
- package/lib/cli/cli.js +18 -11
- 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/index.js +5 -2
- package/lib/fangorn.d.ts +3 -3
- package/lib/fangorn.js +19 -13
- package/lib/harness/index.d.ts +4 -3
- package/lib/harness/index.js +9 -3
- package/lib/index.d.ts +2 -3
- package/lib/index.js +2 -3
- 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.js +5 -4
- 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 +2 -2
- package/lib/test/testbed.js +1 -1
- package/package.json +2 -2
- 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/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
|
@@ -148,7 +148,8 @@ var PinataBackend = class {
|
|
|
148
148
|
if (attempts === 0) break;
|
|
149
149
|
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
150
150
|
}
|
|
151
|
-
|
|
151
|
+
const internalMessage = lastError instanceof Error ? lastError.message : typeof lastError === "string" ? lastError : String(lastError ?? "");
|
|
152
|
+
throw new Error(`Pinata SDK failed to retrieve block ${uri} after multiple attempts. Internal Error: ${internalMessage}`);
|
|
152
153
|
}
|
|
153
154
|
static async getStatic(uri, gateway) {
|
|
154
155
|
return retrieveByCid(uri, gateway);
|
|
@@ -157,15 +158,15 @@ var PinataBackend = class {
|
|
|
157
158
|
const formattedRoot = stateRoot.toLowerCase();
|
|
158
159
|
for (let i = 0; i < retries; i++) {
|
|
159
160
|
const response = await this.pinata.files.public.list().keyvalues({ stateRoot: formattedRoot });
|
|
160
|
-
if (response
|
|
161
|
+
if (response.files.length > 0) return response.files[0].cid;
|
|
161
162
|
if (i < retries - 1) {
|
|
162
163
|
console.warn(`
|
|
163
|
-
[Pinata] Indexing lag detected for root ${formattedRoot}. Retrying in ${delay * (i + 1)}ms...
|
|
164
|
+
[Pinata] Indexing lag detected for root ${formattedRoot}. Retrying in ${(delay * (i + 1)).toString()}ms...
|
|
164
165
|
`);
|
|
165
166
|
await new Promise((resolve) => setTimeout(resolve, delay * (i + 1)));
|
|
166
167
|
}
|
|
167
168
|
}
|
|
168
|
-
throw new Error(`No matching IPFS CID found for state root: ${stateRoot} after ${retries} retrieval attempts.`);
|
|
169
|
+
throw new Error(`No matching IPFS CID found for state root: ${stateRoot} after ${retries.toString()} retrieval attempts.`);
|
|
169
170
|
}
|
|
170
171
|
async delete(uri) {
|
|
171
172
|
await this.pinata.files.public.delete([uri]);
|
package/lib/test/testbed.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ declare class TestBed {
|
|
|
21
21
|
txHash: `0x${string}`;
|
|
22
22
|
alreadyInitialized: false;
|
|
23
23
|
}>;
|
|
24
|
-
upload(index: number, namespace: string, payload:
|
|
24
|
+
upload(index: number, namespace: string, payload: unknown, name: string): Promise<{
|
|
25
25
|
payloadCid: string;
|
|
26
26
|
commitCid: string;
|
|
27
27
|
txHash: `0x${string}`;
|
|
@@ -29,7 +29,7 @@ declare class TestBed {
|
|
|
29
29
|
uploadBatch(index: number, namespace: string, vertices: {
|
|
30
30
|
id: string;
|
|
31
31
|
tag: string;
|
|
32
|
-
payload:
|
|
32
|
+
payload: unknown;
|
|
33
33
|
}[], edges?: {
|
|
34
34
|
rel: string;
|
|
35
35
|
from: string;
|
package/lib/test/testbed.js
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fangorn-network/sdk",
|
|
3
|
-
"version": "2026.07.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2026.07.14",
|
|
4
|
+
"description": "Git for knowledge graphs",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/fangorn-network/fangorn.git"
|
package/lib/ crypto/constants.js
DELETED
package/lib/ crypto/merkle.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
//#region src/ crypto/merkle.d.ts
|
|
2
|
-
declare function hashCidToField(cid: string): bigint;
|
|
3
|
-
declare function getProof(layers: bigint[][], index: number): {
|
|
4
|
-
path: bigint[];
|
|
5
|
-
indices: number[];
|
|
6
|
-
};
|
|
7
|
-
declare function fieldToHex(field: bigint): `0x${string}`;
|
|
8
|
-
declare function hexToField(hex: string): bigint;
|
|
9
|
-
//#endregion
|
|
10
|
-
export { fieldToHex, getProof, hashCidToField, hexToField };
|
package/lib/ crypto/merkle.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { TREE_DEPTH } from "./constants.js";
|
|
2
|
-
|
|
3
|
-
//#region src/ crypto/merkle.ts
|
|
4
|
-
function hashCidToField(cid) {
|
|
5
|
-
const bytes = new TextEncoder().encode(cid);
|
|
6
|
-
let value = 0n;
|
|
7
|
-
for (let i = 0; i < Math.min(bytes.length, 31); i++) value = value << 8n | BigInt(bytes[i]);
|
|
8
|
-
return value;
|
|
9
|
-
}
|
|
10
|
-
function getProof(layers, index) {
|
|
11
|
-
const path = [];
|
|
12
|
-
const indices = [];
|
|
13
|
-
for (let i = 0; i < TREE_DEPTH; i++) {
|
|
14
|
-
const isRight = index % 2 === 1;
|
|
15
|
-
const siblingIndex = isRight ? index - 1 : index + 1;
|
|
16
|
-
path.push(layers[i][siblingIndex] ?? 0n);
|
|
17
|
-
indices.push(isRight ? 1 : 0);
|
|
18
|
-
index = Math.floor(index / 2);
|
|
19
|
-
}
|
|
20
|
-
return {
|
|
21
|
-
path,
|
|
22
|
-
indices
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
function fieldToHex(field) {
|
|
26
|
-
return `0x${field.toString(16).padStart(64, "0")}`;
|
|
27
|
-
}
|
|
28
|
-
function hexToField(hex) {
|
|
29
|
-
const cleanHex = hex.startsWith("0x") ? hex : `0x${hex}`;
|
|
30
|
-
return BigInt(cleanHex);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
export { fieldToHex, getProof, hashCidToField, hexToField };
|
package/lib/ crypto/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/lib/ crypto/utils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { AgentCard } from "@a2a-js/sdk";
|
|
2
|
-
|
|
3
|
-
//#region src/builders/a2aCardBuilder.d.ts
|
|
4
|
-
declare class AgentCardBuilder {
|
|
5
|
-
private card;
|
|
6
|
-
name(name: string): this;
|
|
7
|
-
description(description: string): this;
|
|
8
|
-
version(version: string): this;
|
|
9
|
-
url(url: string): this;
|
|
10
|
-
protocolVersion(protocolVersion: string): this;
|
|
11
|
-
capabilities(opts: {
|
|
12
|
-
streaming?: boolean;
|
|
13
|
-
pushNotifications?: boolean;
|
|
14
|
-
stateTransitionHistory?: boolean;
|
|
15
|
-
}): this;
|
|
16
|
-
streaming(enabled?: boolean): this;
|
|
17
|
-
pushNotifications(enabled?: boolean): this;
|
|
18
|
-
stateTransitionHistory(enabled?: boolean): this;
|
|
19
|
-
inputModes(modes: string[]): this;
|
|
20
|
-
outputModes(modes: string[]): this;
|
|
21
|
-
addSkill(id: string, name: string, description: string, tags: string[], examples?: string[]): this;
|
|
22
|
-
provider(organization: string, url: string): this;
|
|
23
|
-
documentationUrl(url: string): this;
|
|
24
|
-
build(): AgentCard;
|
|
25
|
-
}
|
|
26
|
-
declare const agentCardBuilder: () => AgentCardBuilder;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { AgentCardBuilder, agentCardBuilder };
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
//#region src/builders/a2aCardBuilder.ts
|
|
2
|
-
var AgentCardBuilder = class {
|
|
3
|
-
card = {
|
|
4
|
-
capabilities: {
|
|
5
|
-
streaming: false,
|
|
6
|
-
pushNotifications: false,
|
|
7
|
-
stateTransitionHistory: false
|
|
8
|
-
},
|
|
9
|
-
defaultInputModes: ["text/plain", "application/json"],
|
|
10
|
-
defaultOutputModes: ["text/plain", "application/json"],
|
|
11
|
-
skills: []
|
|
12
|
-
};
|
|
13
|
-
name(name) {
|
|
14
|
-
this.card.name = name;
|
|
15
|
-
return this;
|
|
16
|
-
}
|
|
17
|
-
description(description) {
|
|
18
|
-
this.card.description = description;
|
|
19
|
-
return this;
|
|
20
|
-
}
|
|
21
|
-
version(version) {
|
|
22
|
-
this.card.version = version;
|
|
23
|
-
return this;
|
|
24
|
-
}
|
|
25
|
-
url(url) {
|
|
26
|
-
this.card.url = url;
|
|
27
|
-
return this;
|
|
28
|
-
}
|
|
29
|
-
protocolVersion(protocolVersion) {
|
|
30
|
-
this.card.protocolVersion = protocolVersion;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
capabilities(opts) {
|
|
34
|
-
this.card.capabilities = {
|
|
35
|
-
...this.card.capabilities,
|
|
36
|
-
...opts
|
|
37
|
-
};
|
|
38
|
-
return this;
|
|
39
|
-
}
|
|
40
|
-
streaming(enabled = true) {
|
|
41
|
-
this.card.capabilities = {
|
|
42
|
-
...this.card.capabilities,
|
|
43
|
-
streaming: enabled
|
|
44
|
-
};
|
|
45
|
-
return this;
|
|
46
|
-
}
|
|
47
|
-
pushNotifications(enabled = true) {
|
|
48
|
-
this.card.capabilities = {
|
|
49
|
-
...this.card.capabilities,
|
|
50
|
-
pushNotifications: enabled
|
|
51
|
-
};
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
stateTransitionHistory(enabled = true) {
|
|
55
|
-
this.card.capabilities = {
|
|
56
|
-
...this.card.capabilities,
|
|
57
|
-
stateTransitionHistory: enabled
|
|
58
|
-
};
|
|
59
|
-
return this;
|
|
60
|
-
}
|
|
61
|
-
inputModes(modes) {
|
|
62
|
-
this.card.defaultInputModes = modes;
|
|
63
|
-
return this;
|
|
64
|
-
}
|
|
65
|
-
outputModes(modes) {
|
|
66
|
-
this.card.defaultOutputModes = modes;
|
|
67
|
-
return this;
|
|
68
|
-
}
|
|
69
|
-
addSkill(id, name, description, tags, examples) {
|
|
70
|
-
const skill = {
|
|
71
|
-
id,
|
|
72
|
-
name,
|
|
73
|
-
description,
|
|
74
|
-
tags
|
|
75
|
-
};
|
|
76
|
-
if (examples) skill.examples = examples;
|
|
77
|
-
this.card.skills ??= [];
|
|
78
|
-
this.card.skills.push(skill);
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
provider(organization, url) {
|
|
82
|
-
this.card.provider = {
|
|
83
|
-
organization,
|
|
84
|
-
url
|
|
85
|
-
};
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
documentationUrl(url) {
|
|
89
|
-
this.card.documentationUrl = url;
|
|
90
|
-
return this;
|
|
91
|
-
}
|
|
92
|
-
build() {
|
|
93
|
-
for (const field of [
|
|
94
|
-
"name",
|
|
95
|
-
"description",
|
|
96
|
-
"version",
|
|
97
|
-
"url"
|
|
98
|
-
]) if (!this.card[field]) throw new Error(`AgentCard requires '${field}'`);
|
|
99
|
-
return this.card;
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
const agentCardBuilder = () => new AgentCardBuilder();
|
|
103
|
-
|
|
104
|
-
//#endregion
|
|
105
|
-
export { AgentCardBuilder, agentCardBuilder };
|
package/lib/roles/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/lib/roles/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
package/lib/test/car_smoke.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "dotenv/config";
|
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 };
|