@fangorn-network/sdk 2026.3.29 → 2026.4.7-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/README.md +24 -31
- package/lib/cli/cli.js +18 -2
- package/lib/cli/index.d.ts +159 -159
- package/lib/config.d.ts +241 -238
- package/lib/config.js +4 -2
- package/lib/fangorn.d.ts +0 -8
- package/lib/fangorn.js +12 -29
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -3
- package/lib/modules/gadgets/settledGadget.d.ts +8 -1
- package/lib/modules/gadgets/settledGadget.js +13 -1
- package/lib/providers/storage/index.d.ts +12 -12
- package/lib/providers/storage/index.js +47 -2
- package/lib/providers/storage/pinata.d.ts +11 -0
- package/lib/providers/storage/pinata.js +24 -0
- package/lib/registries/datasource-registry/index.d.ts +4 -3
- package/lib/registries/datasource-registry/index.js +14 -2
- package/lib/registries/schema-registry/index.d.ts +2 -2
- package/lib/registries/settlement-registry/index.d.ts +2 -2
- package/lib/roles/consumer/index.d.ts +2 -24
- package/lib/roles/consumer/index.js +5 -26
- package/lib/roles/publisher/index.d.ts +17 -15
- package/lib/roles/publisher/index.js +43 -36
- package/lib/roles/publisher/types.d.ts +5 -7
- package/lib/roles/schema/index.d.ts +9 -2
- package/lib/roles/schema/index.js +35 -2
- package/lib/test/testbed.d.ts +3 -2
- package/lib/test/testbed.js +12 -8
- package/lib/types/index.d.ts +10 -20
- package/package.json +1 -1
- package/lib/providers/storage/pinata/index.d.ts +0 -13
- package/lib/providers/storage/pinata/index.js +0 -41
- package/lib/providers/storage/storacha/index.d.ts +0 -13
- package/lib/providers/storage/storacha/index.js +0 -49
- package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
- package/lib/providers/storage/storacha/readOnly.js +0 -16
|
@@ -1,42 +1,40 @@
|
|
|
1
|
+
import { retrieveByCid } from "../../providers/storage/index.js";
|
|
1
2
|
import { SettlementRegistry } from "../../registries/settlement-registry/index.js";
|
|
2
|
-
import {
|
|
3
|
+
import { makeSettledGadgetFactory } from "../../modules/gadgets/settledGadget.js";
|
|
3
4
|
|
|
4
5
|
//#region src/roles/publisher/index.ts
|
|
5
6
|
var PublisherRole = class {
|
|
6
7
|
pendingEntries = /* @__PURE__ */ new Map();
|
|
7
|
-
|
|
8
|
+
schemaCache = /* @__PURE__ */ new Map();
|
|
9
|
+
constructor(dataSourceRegistry, settlementRegistry, schemaRegistry, storage, encryptionService, walletClient, config) {
|
|
8
10
|
this.dataSourceRegistry = dataSourceRegistry;
|
|
9
11
|
this.settlementRegistry = settlementRegistry;
|
|
12
|
+
this.schemaRegistry = schemaRegistry;
|
|
10
13
|
this.storage = storage;
|
|
11
14
|
this.encryptionService = encryptionService;
|
|
12
15
|
this.walletClient = walletClient;
|
|
13
16
|
this.config = config;
|
|
14
17
|
}
|
|
15
18
|
/**
|
|
16
|
-
* Encrypt and
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
+
* Encrypt and upload data with Fangorn.
|
|
20
|
+
* Validates records against the schema, encrypts encrypted fields,
|
|
21
|
+
* stages all resolved entries, then commits to IPFS + on-chain.
|
|
19
22
|
*
|
|
20
23
|
* Each encrypted field within a record is stored as a separate IPFS object
|
|
21
24
|
* (the ciphertext). The manifest entry stores the handle (CID + gateway)
|
|
22
|
-
* alongside
|
|
25
|
+
* alongside plain fields. Consumers can read plain fields freely and
|
|
23
26
|
* only need to purchase + decrypt for encrypted fields.
|
|
24
27
|
*/
|
|
25
28
|
async upload(params, price) {
|
|
26
|
-
const { records,
|
|
29
|
+
const { records, schemaName, gateway, options } = params;
|
|
27
30
|
const address = this.requireAccount();
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
chainName: this.config.chainName
|
|
33
|
-
});
|
|
34
|
-
};
|
|
31
|
+
const { schema, schemaId } = await this.resolveSchema(schemaName);
|
|
32
|
+
const gadgetFactory = params.gadgetFactory ?? ((resourceId) => {
|
|
33
|
+
return makeSettledGadgetFactory(this.config)(resourceId);
|
|
34
|
+
});
|
|
35
35
|
for (const record of records) {
|
|
36
36
|
this.validateRecord(record, schema);
|
|
37
|
-
const
|
|
38
|
-
console.log("using resource Id" + resourceId);
|
|
39
|
-
const gadget = gadgetFactory(record.tag);
|
|
37
|
+
const gadget = await gadgetFactory(SettlementRegistry.deriveResourceId(address, schemaId, record.tag));
|
|
40
38
|
const entry = await this.resolveRecord(record, schema, gadget, gateway);
|
|
41
39
|
this.pendingEntries.set(record.tag, entry);
|
|
42
40
|
}
|
|
@@ -57,11 +55,6 @@ var PublisherRole = class {
|
|
|
57
55
|
/**
|
|
58
56
|
* Serialize all staged entries into a manifest, create SettlementRegistry
|
|
59
57
|
* resources for each entry, pin the manifest to IPFS, and publish on-chain.
|
|
60
|
-
*
|
|
61
|
-
* @param schemaId: The unique id of the schema
|
|
62
|
-
* @param price: The USDC price required to register with the sempaphore group
|
|
63
|
-
* @param overwrite: If true, overwrite manifest data, else append (default: false)
|
|
64
|
-
*
|
|
65
58
|
*/
|
|
66
59
|
async commit(schemaId, price, overwrite) {
|
|
67
60
|
const owner = this.requireAccount();
|
|
@@ -77,8 +70,8 @@ var PublisherRole = class {
|
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
72
|
if (!overwrite) {
|
|
80
|
-
const
|
|
81
|
-
entries = [...Array.from(
|
|
73
|
+
const existingEntriesMap = await this.loadExistingManifest(owner, schemaId);
|
|
74
|
+
entries = [...Array.from(existingEntriesMap.values()), ...entries];
|
|
82
75
|
}
|
|
83
76
|
const manifest = {
|
|
84
77
|
version: 1,
|
|
@@ -100,7 +93,7 @@ var PublisherRole = class {
|
|
|
100
93
|
try {
|
|
101
94
|
const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
|
|
102
95
|
if (!ds.manifestCid || ds.manifestCid === "") return void 0;
|
|
103
|
-
return
|
|
96
|
+
return retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
|
|
104
97
|
} catch {
|
|
105
98
|
return;
|
|
106
99
|
}
|
|
@@ -118,10 +111,30 @@ var PublisherRole = class {
|
|
|
118
111
|
return address;
|
|
119
112
|
}
|
|
120
113
|
/**
|
|
114
|
+
* Resolve the schema definition and id by name, with in-memory caching.
|
|
115
|
+
* Schema resolution is concurrent-safe — parallel calls for the same name
|
|
116
|
+
* share a single in-flight promise.
|
|
117
|
+
*/
|
|
118
|
+
resolveSchema(name) {
|
|
119
|
+
if (!this.schemaCache.has(name)) {
|
|
120
|
+
const p = Promise.all([this.schemaRegistry.getSchema(name), this.schemaRegistry.schemaId(name)]).then(async ([{ cid }, schemaId]) => {
|
|
121
|
+
return {
|
|
122
|
+
schema: (await retrieveByCid(cid, this.config.ipfsGateway)).definition,
|
|
123
|
+
schemaId
|
|
124
|
+
};
|
|
125
|
+
}).catch((err) => {
|
|
126
|
+
this.schemaCache.delete(name);
|
|
127
|
+
throw err;
|
|
128
|
+
});
|
|
129
|
+
this.schemaCache.set(name, p);
|
|
130
|
+
}
|
|
131
|
+
return this.schemaCache.get(name);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
121
134
|
* Resolve a PublishRecord into a ManifestEntry by processing each field
|
|
122
135
|
* according to the schema definition:
|
|
123
136
|
* - plain fields are stored as-is
|
|
124
|
-
* - encrypted fields are
|
|
137
|
+
* - encrypted fields are encrypted, pinned to IPFS, and replaced
|
|
125
138
|
* with a handle + gadgetDescriptor
|
|
126
139
|
*/
|
|
127
140
|
async resolveRecord(record, schema, gadget, gateway) {
|
|
@@ -137,14 +150,13 @@ var PublisherRole = class {
|
|
|
137
150
|
fileType: input.fileType ?? "application/octet-stream"
|
|
138
151
|
}, gadget);
|
|
139
152
|
const cid = await this.storage.store(encrypted, { metadata: { name: `${record.tag}:${fieldName}` } });
|
|
140
|
-
const gadgetDescriptor = gadget.toDescriptor();
|
|
141
153
|
resolvedFields[fieldName] = {
|
|
142
154
|
"@type": "encrypted",
|
|
143
155
|
handle: {
|
|
144
156
|
cid,
|
|
145
157
|
gateway
|
|
146
158
|
},
|
|
147
|
-
gadgetDescriptor
|
|
159
|
+
gadgetDescriptor: gadget.toDescriptor()
|
|
148
160
|
};
|
|
149
161
|
} else resolvedFields[fieldName] = value;
|
|
150
162
|
}
|
|
@@ -155,14 +167,10 @@ var PublisherRole = class {
|
|
|
155
167
|
}
|
|
156
168
|
/**
|
|
157
169
|
* Validate that a record's fields match the schema before touching IPFS.
|
|
158
|
-
* Catches type mismatches and missing required fields early.
|
|
159
170
|
*/
|
|
160
171
|
validateRecord(record, schema) {
|
|
161
172
|
const errors = [];
|
|
162
|
-
for (const [fieldName, fieldDef] of Object.entries(schema))
|
|
163
|
-
const value = record.fields[fieldName];
|
|
164
|
-
this.validateField(record.tag, fieldName, fieldDef, value, errors);
|
|
165
|
-
}
|
|
173
|
+
for (const [fieldName, fieldDef] of Object.entries(schema)) this.validateField(record.tag, fieldName, fieldDef, record.fields[fieldName], errors);
|
|
166
174
|
for (const fieldName of Object.keys(record.fields)) if (!(fieldName in schema)) console.warn(`Record "${record.tag}": field "${fieldName}" is not in the schema and will be ignored`);
|
|
167
175
|
if (errors.length > 0) throw new Error(`Validation failed for record "${record.tag}":\n` + errors.map((e) => ` • ${e}`).join("\n"));
|
|
168
176
|
}
|
|
@@ -186,15 +194,14 @@ var PublisherRole = class {
|
|
|
186
194
|
}
|
|
187
195
|
}
|
|
188
196
|
/**
|
|
189
|
-
* Load the existing manifest
|
|
190
|
-
* Unpins the old manifest CID
|
|
197
|
+
* Load the existing manifest for merge behaviour and unpin the old CID.
|
|
191
198
|
*/
|
|
192
199
|
async loadExistingManifest(owner, schemaId) {
|
|
193
200
|
const entries = /* @__PURE__ */ new Map();
|
|
194
201
|
try {
|
|
195
202
|
const ds = await this.dataSourceRegistry.getManifest(owner, schemaId);
|
|
196
203
|
if (!ds.manifestCid) return entries;
|
|
197
|
-
const manifest = await
|
|
204
|
+
const manifest = await retrieveByCid(ds.manifestCid, this.config.ipfsGateway);
|
|
198
205
|
for (const entry of manifest.entries) entries.set(entry.tag, entry);
|
|
199
206
|
try {
|
|
200
207
|
await this.storage.delete(ds.manifestCid);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { SchemaDefinition } from "../schema/types.js";
|
|
2
1
|
import { Gadget, GadgetDescriptor } from "../../modules/gadgets/types.js";
|
|
3
2
|
import "../../modules/gadgets/index.js";
|
|
4
3
|
import { Address, Hex } from "viem";
|
|
@@ -57,18 +56,17 @@ interface Manifest {
|
|
|
57
56
|
}
|
|
58
57
|
interface UploadParams {
|
|
59
58
|
records: PublishRecord[];
|
|
60
|
-
|
|
61
|
-
* The schema the records must conform to. Required — field-level encryption
|
|
62
|
-
* decisions are driven by the schema definition.
|
|
63
|
-
*/
|
|
64
|
-
schema: SchemaDefinition;
|
|
65
|
-
schemaId: Hex;
|
|
59
|
+
schemaName: string;
|
|
66
60
|
/**
|
|
67
61
|
* Called once per record to produce the gadget for that record's encrypted
|
|
68
62
|
* fields. All encrypted fields within a record share the same gadget —
|
|
69
63
|
* and therefore the same resourceId and access condition.
|
|
70
64
|
*/
|
|
71
65
|
gadgetFactory?: (tag: string) => Gadget | Promise<Gadget>;
|
|
66
|
+
/**
|
|
67
|
+
* Configurable gas for sending the call
|
|
68
|
+
*/
|
|
69
|
+
gas?: bigint;
|
|
72
70
|
/**
|
|
73
71
|
* IPFS gateway URL written into each encrypted field handle so consumers
|
|
74
72
|
* can retrieve ciphertexts without knowing the storage provider.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SchemaRegistry } from "../../registries/schema-registry/index.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PinningService } from "../../providers/storage/index.js";
|
|
3
3
|
import { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig } from "./types.js";
|
|
4
4
|
import { WalletClient } from "viem";
|
|
5
5
|
|
|
@@ -8,7 +8,13 @@ declare class SchemaRole {
|
|
|
8
8
|
private readonly schemaRegistry;
|
|
9
9
|
private readonly storage;
|
|
10
10
|
private readonly walletClient;
|
|
11
|
-
|
|
11
|
+
private readonly ipfsGateway;
|
|
12
|
+
private readonly agent0;
|
|
13
|
+
constructor(schemaRegistry: SchemaRegistry, storage: PinningService, walletClient: WalletClient, ipfsGateway: string, config?: SchemaRoleConfig);
|
|
14
|
+
/**
|
|
15
|
+
* Register an agent identity via the agent0-sdk / ERC-8004.
|
|
16
|
+
*/
|
|
17
|
+
registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
|
|
12
18
|
/**
|
|
13
19
|
* Register a schema on-chain, tied to an existing agent identity.
|
|
14
20
|
*
|
|
@@ -33,6 +39,7 @@ declare class SchemaRole {
|
|
|
33
39
|
*/
|
|
34
40
|
validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
|
|
35
41
|
private requireAccount;
|
|
42
|
+
private requireAgent0;
|
|
36
43
|
}
|
|
37
44
|
//#endregion
|
|
38
45
|
export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
|
|
@@ -1,9 +1,38 @@
|
|
|
1
|
+
import { retrieveByCid } from "../../providers/storage/index.js";
|
|
2
|
+
import { SDK } from "agent0-sdk";
|
|
3
|
+
|
|
1
4
|
//#region src/roles/schema/index.ts
|
|
2
5
|
var SchemaRole = class {
|
|
3
|
-
|
|
6
|
+
agent0;
|
|
7
|
+
constructor(schemaRegistry, storage, walletClient, ipfsGateway, config) {
|
|
4
8
|
this.schemaRegistry = schemaRegistry;
|
|
5
9
|
this.storage = storage;
|
|
6
10
|
this.walletClient = walletClient;
|
|
11
|
+
this.ipfsGateway = ipfsGateway;
|
|
12
|
+
this.agent0 = config ? new SDK({
|
|
13
|
+
chainId: config.chainId,
|
|
14
|
+
rpcUrl: config.rpcUrl,
|
|
15
|
+
privateKey: config.privateKey,
|
|
16
|
+
ipfs: "pinata",
|
|
17
|
+
pinataJwt: config.pinataJwt,
|
|
18
|
+
...config.registryOverrides && { registryOverrides: config.registryOverrides },
|
|
19
|
+
...config.subgraphOverrides && { subgraphOverrides: config.subgraphOverrides }
|
|
20
|
+
}) : null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Register an agent identity via the agent0-sdk / ERC-8004.
|
|
24
|
+
*/
|
|
25
|
+
async registerAgent(params) {
|
|
26
|
+
const agent = this.requireAgent0().createAgent(params.name, params.description);
|
|
27
|
+
if (params.a2aUrl) await agent.setA2A(params.a2aUrl);
|
|
28
|
+
if (params.mcpEndpoint) await agent.setMCP(params.mcpEndpoint);
|
|
29
|
+
if (params.ens) agent.setENS(params.ens);
|
|
30
|
+
agent.setActive(true);
|
|
31
|
+
agent.setX402Support(true);
|
|
32
|
+
const { result: registrationFile } = await (await agent.registerIPFS()).waitConfirmed();
|
|
33
|
+
const agentId = registrationFile.agentId;
|
|
34
|
+
if (!agentId) throw new Error("ERC-8004 registration did not return an agentId");
|
|
35
|
+
return { agentId };
|
|
7
36
|
}
|
|
8
37
|
/**
|
|
9
38
|
* Register a schema on-chain, tied to an existing agent identity.
|
|
@@ -41,7 +70,7 @@ var SchemaRole = class {
|
|
|
41
70
|
const schemaId = await this.schemaRegistry.schemaId(typeof nameOrId === "string" && !/^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : nameOrId);
|
|
42
71
|
const record = await this.schemaRegistry.getSchema(nameOrId);
|
|
43
72
|
if (!record.cid) return void 0;
|
|
44
|
-
const blob = await
|
|
73
|
+
const blob = await retrieveByCid(record.cid, this.ipfsGateway);
|
|
45
74
|
return {
|
|
46
75
|
schemaId,
|
|
47
76
|
schemaCid: record.cid,
|
|
@@ -100,6 +129,10 @@ var SchemaRole = class {
|
|
|
100
129
|
if (!address) throw new Error("No account connected to wallet client");
|
|
101
130
|
return address;
|
|
102
131
|
}
|
|
132
|
+
requireAgent0() {
|
|
133
|
+
if (!this.agent0) throw new Error("registerAgent() requires AgentConfig (privateKey + pinataJwt). Pass agentConfig to Fangorn.init() to enable ERC-8004 registration.");
|
|
134
|
+
return this.agent0;
|
|
135
|
+
}
|
|
103
136
|
};
|
|
104
137
|
|
|
105
138
|
//#endregion
|
package/lib/test/testbed.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SchemaDefinition } from "../roles/schema/types.js";
|
|
1
|
+
import { RegisterAgentParams, RegisteredAgent, SchemaDefinition } from "../roles/schema/types.js";
|
|
2
2
|
import "../roles/schema/index.js";
|
|
3
3
|
import { PrepareSettleResult, TransferWithAuthPayload } from "../registries/settlement-registry/types.js";
|
|
4
4
|
import { SettlementRegistry } from "../registries/settlement-registry/index.js";
|
|
@@ -34,6 +34,7 @@ declare class TestBed {
|
|
|
34
34
|
* @returns The testbed client
|
|
35
35
|
*/
|
|
36
36
|
static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number): Promise<TestBed>;
|
|
37
|
+
registerAgent(params: RegisterAgentParams): Promise<RegisteredAgent>;
|
|
37
38
|
registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
|
|
38
39
|
/**
|
|
39
40
|
* Upload files encrypted under SettledGadget.
|
|
@@ -42,7 +43,7 @@ declare class TestBed {
|
|
|
42
43
|
* which is baked into the ACC at encryption time. A buyer must complete the
|
|
43
44
|
* full purchase → claim flow for each specific tag before decrypting.
|
|
44
45
|
*/
|
|
45
|
-
fileUpload(records: PublishRecord[],
|
|
46
|
+
fileUpload(records: PublishRecord[], schemaName: string, gateway: string, price: bigint): Promise<string>;
|
|
46
47
|
prepareRegister(burnerPrivateKey: Hex, paymentRecipient: Address, amount: bigint): Promise<TransferWithAuthPayload>;
|
|
47
48
|
register(owner: Address, schemaId: Hex, tag: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
|
|
48
49
|
prepareSettle(owner: Address, schemaId: Hex, tag: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
|
package/lib/test/testbed.js
CHANGED
|
@@ -40,20 +40,22 @@ var TestBed = class TestBed {
|
|
|
40
40
|
chainName: chain,
|
|
41
41
|
chain: chainImpl,
|
|
42
42
|
rpcUrl,
|
|
43
|
-
caip2
|
|
43
|
+
caip2,
|
|
44
|
+
ipfsGateway: "https://gateway.pinata.cloud"
|
|
44
45
|
};
|
|
45
|
-
const agentConfig = void 0;
|
|
46
46
|
const delegatorFangorn = await Fangorn.create({
|
|
47
47
|
privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
|
|
48
|
-
storage: {
|
|
48
|
+
storage: { pinata: {
|
|
49
|
+
jwt: process.env.PINATA_JWT ?? "",
|
|
50
|
+
gateway: process.env.PINATA_GATEWAY ?? ""
|
|
51
|
+
} },
|
|
49
52
|
encryption: { lit: true },
|
|
50
53
|
config,
|
|
51
54
|
domain: "localhost",
|
|
52
|
-
agentConfig
|
|
55
|
+
agentConfig: void 0
|
|
53
56
|
});
|
|
54
57
|
const delegateeFangorn = await Fangorn.create({
|
|
55
58
|
privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
|
|
56
|
-
storage: { storacha: { "readOnly": true } },
|
|
57
59
|
encryption: { lit: true },
|
|
58
60
|
config,
|
|
59
61
|
domain: "localhost"
|
|
@@ -61,6 +63,9 @@ var TestBed = class TestBed {
|
|
|
61
63
|
if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
|
|
62
64
|
return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
|
|
63
65
|
}
|
|
66
|
+
async registerAgent(params) {
|
|
67
|
+
return this.delegatorFangorn.schema.registerAgent(params);
|
|
68
|
+
}
|
|
64
69
|
async registerSchema(name, definition, agentId) {
|
|
65
70
|
const { schemaId } = await this.delegatorFangorn.schema.register({
|
|
66
71
|
name,
|
|
@@ -76,11 +81,10 @@ var TestBed = class TestBed {
|
|
|
76
81
|
* which is baked into the ACC at encryption time. A buyer must complete the
|
|
77
82
|
* full purchase → claim flow for each specific tag before decrypting.
|
|
78
83
|
*/
|
|
79
|
-
async fileUpload(records,
|
|
84
|
+
async fileUpload(records, schemaName, gateway, price) {
|
|
80
85
|
const { manifestCid } = await this.delegatorFangorn.publisher.upload({
|
|
81
86
|
records,
|
|
82
|
-
|
|
83
|
-
schemaId,
|
|
87
|
+
schemaName,
|
|
84
88
|
gateway
|
|
85
89
|
}, price);
|
|
86
90
|
return manifestCid;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AppConfig } from "../config.js";
|
|
2
2
|
import { SchemaRegistry } from "../registries/schema-registry/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { PinningService } from "../providers/storage/index.js";
|
|
4
4
|
import { SchemaRoleConfig } from "../roles/schema/types.js";
|
|
5
5
|
import "../roles/schema/index.js";
|
|
6
6
|
import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
|
|
@@ -29,29 +29,22 @@ interface EncryptedData {
|
|
|
29
29
|
authTag: Uint8Array<ArrayBuffer>;
|
|
30
30
|
salt: Uint8Array<ArrayBuffer>;
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
33
|
-
* Credentials required to enable ERC-8004 agent registration via agent0-sdk.
|
|
34
|
-
* Optional: omit if thewill throw. caller only needs publisher or consumer functionality.
|
|
35
|
-
* When omitted, fangorn.schema.register() and fangorn.schema.get() still work;
|
|
36
|
-
* only fangorn.schema.registerAgent()
|
|
37
|
-
*/
|
|
38
32
|
interface AgentConfig {
|
|
39
33
|
privateKey: Hex;
|
|
40
34
|
pinataJwt: string;
|
|
41
|
-
/** Override ERC-8004 registry addresses per chainId (e.g. for Arbitrum Sepolia) */
|
|
42
35
|
registryOverrides?: Record<number, {
|
|
43
36
|
IDENTITY: string;
|
|
44
37
|
REPUTATION: string;
|
|
45
38
|
}>;
|
|
46
|
-
/** Override subgraph URLs per chainId */
|
|
47
39
|
subgraphOverrides?: Record<number, string>;
|
|
48
40
|
}
|
|
49
41
|
interface FangornContext {
|
|
50
42
|
config: AppConfig;
|
|
51
43
|
walletClient: WalletClient;
|
|
52
|
-
storage:
|
|
44
|
+
storage: PinningService | undefined;
|
|
53
45
|
encryption: EncryptionService;
|
|
54
46
|
domain: string;
|
|
47
|
+
ipfsGateway: string;
|
|
55
48
|
schemaRegistry: SchemaRegistry;
|
|
56
49
|
dataSourceRegistry: DataSourceRegistry;
|
|
57
50
|
settlementRegistry: SettlementRegistry;
|
|
@@ -62,21 +55,18 @@ type StorageConfig = {
|
|
|
62
55
|
jwt: string;
|
|
63
56
|
gateway: string;
|
|
64
57
|
};
|
|
65
|
-
}
|
|
66
|
-
storacha: {
|
|
67
|
-
email: string;
|
|
68
|
-
};
|
|
69
|
-
} | {
|
|
70
|
-
storacha: {
|
|
71
|
-
readOnly: true;
|
|
72
|
-
};
|
|
73
|
-
} | ReadableStorage<unknown>;
|
|
58
|
+
};
|
|
74
59
|
type EncryptionConfig = {
|
|
75
60
|
lit: true;
|
|
76
61
|
} | EncryptionService;
|
|
77
62
|
interface FangornCreateOptions {
|
|
78
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Pinning service config. Required for publisher and schema roles.
|
|
65
|
+
* Omit for consumer-only usage — reads always go through the public IPFS gateway.
|
|
66
|
+
*/
|
|
67
|
+
storage?: StorageConfig;
|
|
79
68
|
encryption: EncryptionConfig;
|
|
69
|
+
ipfsGateway?: string;
|
|
80
70
|
config?: AppConfig;
|
|
81
71
|
domain?: string;
|
|
82
72
|
agentConfig?: AgentConfig;
|
package/package.json
CHANGED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { WritableStorage } from "../index.js";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/storage/pinata/index.d.ts
|
|
4
|
-
declare class PinataStorage implements WritableStorage<unknown> {
|
|
5
|
-
private pinata;
|
|
6
|
-
private gateway;
|
|
7
|
-
constructor(pinataJwt: string, pinataGateway: string);
|
|
8
|
-
store(data: unknown, metadata?: Record<string, string>): Promise<string>;
|
|
9
|
-
retrieve(cid: string): Promise<unknown>;
|
|
10
|
-
delete(cid: string): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { PinataStorage };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { PinataSDK } from "pinata";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/storage/pinata/index.ts
|
|
4
|
-
var PinataStorage = class {
|
|
5
|
-
pinata;
|
|
6
|
-
gateway;
|
|
7
|
-
constructor(pinataJwt, pinataGateway) {
|
|
8
|
-
this.pinata = new PinataSDK({
|
|
9
|
-
pinataJwt,
|
|
10
|
-
pinataGateway
|
|
11
|
-
});
|
|
12
|
-
this.gateway = pinataGateway.replace(/\/$/, "");
|
|
13
|
-
}
|
|
14
|
-
async store(data, metadata) {
|
|
15
|
-
const content = typeof data === "string" ? data : JSON.stringify(data, (_key, value) => {
|
|
16
|
-
if (value instanceof Uint8Array) return {
|
|
17
|
-
__type: "Uint8Array",
|
|
18
|
-
data: Buffer.from(value).toString("base64")
|
|
19
|
-
};
|
|
20
|
-
return value;
|
|
21
|
-
});
|
|
22
|
-
const file = new File([content], metadata?.name ?? "file", { type: "text/plain" });
|
|
23
|
-
return (await this.pinata.upload.public.file(file, { metadata })).cid;
|
|
24
|
-
}
|
|
25
|
-
async retrieve(cid) {
|
|
26
|
-
const url = `https://${this.gateway}/ipfs/${cid}`;
|
|
27
|
-
const response = await fetch(url);
|
|
28
|
-
const text = await response.text();
|
|
29
|
-
if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
|
|
30
|
-
return JSON.parse(text, (_key, value) => {
|
|
31
|
-
if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
|
|
32
|
-
return value;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
async delete(cid) {
|
|
36
|
-
await this.pinata.files.public.delete([cid]);
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
export { PinataStorage };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { WritableStorage } from "../index.js";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/storage/storacha/index.d.ts
|
|
4
|
-
declare class StorachaStorage implements WritableStorage<unknown> {
|
|
5
|
-
private client;
|
|
6
|
-
private constructor();
|
|
7
|
-
static create(email: string): Promise<StorachaStorage>;
|
|
8
|
-
store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
|
|
9
|
-
retrieve(cid: string): Promise<unknown>;
|
|
10
|
-
delete(cid: string): Promise<void>;
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { StorachaStorage };
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { create } from "@storacha/client";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/storage/storacha/index.ts
|
|
4
|
-
var StorachaStorage = class StorachaStorage {
|
|
5
|
-
client;
|
|
6
|
-
constructor(client) {
|
|
7
|
-
this.client = client;
|
|
8
|
-
}
|
|
9
|
-
static async create(email) {
|
|
10
|
-
const client = await create();
|
|
11
|
-
const account = await client.login(email);
|
|
12
|
-
if (!(await account.plan.get()).ok) await account.plan.wait();
|
|
13
|
-
const spaces = client.spaces();
|
|
14
|
-
if (spaces.length > 0) await client.setCurrentSpace(spaces[0].did());
|
|
15
|
-
else {
|
|
16
|
-
const space = await client.createSpace("fangorn", { account });
|
|
17
|
-
await client.setCurrentSpace(space.did());
|
|
18
|
-
}
|
|
19
|
-
return new StorachaStorage(client);
|
|
20
|
-
}
|
|
21
|
-
async store(data, metadata) {
|
|
22
|
-
const content = typeof data === "string" ? data : JSON.stringify(data, (_key, value) => {
|
|
23
|
-
if (value instanceof Uint8Array) return {
|
|
24
|
-
__type: "Uint8Array",
|
|
25
|
-
data: Buffer.from(value).toString("base64")
|
|
26
|
-
};
|
|
27
|
-
return value;
|
|
28
|
-
});
|
|
29
|
-
const name = typeof metadata?.name === "string" ? metadata.name : "file";
|
|
30
|
-
const file = new File([content], name, { type: "text/plain" });
|
|
31
|
-
return (await this.client.uploadFile(file)).toString();
|
|
32
|
-
}
|
|
33
|
-
async retrieve(cid) {
|
|
34
|
-
const url = `https://${cid}.ipfs.w3s.link`;
|
|
35
|
-
const response = await fetch(url);
|
|
36
|
-
if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
|
|
37
|
-
const text = await response.text();
|
|
38
|
-
return JSON.parse(text, (_key, value) => {
|
|
39
|
-
if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
|
|
40
|
-
return value;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
async delete(cid) {
|
|
44
|
-
await this.client.remove(cid);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
//#endregion
|
|
49
|
-
export { StorachaStorage };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ReadableStorage } from "../index.js";
|
|
2
|
-
|
|
3
|
-
//#region src/providers/storage/storacha/readOnly.d.ts
|
|
4
|
-
declare class ReadOnlyStorachaStorage implements ReadableStorage<unknown> {
|
|
5
|
-
retrieve(cid: string): Promise<unknown>;
|
|
6
|
-
}
|
|
7
|
-
//#endregion
|
|
8
|
-
export { ReadOnlyStorachaStorage };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/providers/storage/storacha/readOnly.ts
|
|
2
|
-
var ReadOnlyStorachaStorage = class {
|
|
3
|
-
async retrieve(cid) {
|
|
4
|
-
const url = `https://${cid}.ipfs.w3s.link`;
|
|
5
|
-
const response = await fetch(url);
|
|
6
|
-
if (!response.ok) throw new Error(`Failed to retrieve ${cid}: ${response.statusText}`);
|
|
7
|
-
const text = await response.text();
|
|
8
|
-
return JSON.parse(text, (_key, value) => {
|
|
9
|
-
if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
|
|
10
|
-
return value;
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { ReadOnlyStorachaStorage };
|