@fangorn-network/sdk 2026.7.13 → 2026.7.24
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 +106 -22
- package/lib/engine/index.js +6 -3
- package/lib/fangorn.d.ts +4 -4
- package/lib/fangorn.js +20 -18
- 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 +3 -3
- package/lib/providers/storage/car.js +3 -2
- package/lib/providers/storage/pinata.js +27 -7
- 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 +4 -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/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/_polyval.js +0 -218
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/aes.js +0 -261
- package/lib/node_modules/.pnpm/@noble_ciphers@1.3.0/node_modules/@noble/ciphers/esm/utils.js +0 -156
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/curve.js +0 -299
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/edwards.js +0 -532
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/modular.js +0 -344
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/abstract/montgomery.js +0 -137
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/ed25519.js +0 -262
- package/lib/node_modules/.pnpm/@noble_curves@1.9.7/node_modules/@noble/curves/esm/utils.js +0 -150
- 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
|
@@ -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 };
|