@fangorn-network/sdk 2026.4.7 → 2026.4.15
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 +137 -150
- package/lib/cli/cli.js +134 -226
- package/lib/cli/index.d.ts +170 -170
- package/lib/config.d.ts +260 -257
- package/lib/config.js +7 -5
- package/lib/fangorn.d.ts +3 -20
- package/lib/fangorn.js +15 -52
- package/lib/index.d.ts +3 -7
- package/lib/index.js +4 -7
- package/lib/modules/encryption/aes.d.ts +3 -3
- package/lib/modules/encryption/index.d.ts +1 -28
- package/lib/modules/encryption/index.js +1 -3
- package/lib/modules/encryption/types.d.ts +1 -48
- package/lib/providers/storage/index.d.ts +4 -21
- package/lib/providers/storage/index.js +3 -2
- package/lib/providers/storage/pinata.d.ts +14 -0
- package/lib/providers/storage/pinata.js +32 -0
- package/lib/providers/storage/types.d.ts +37 -0
- package/lib/providers/storage/utils.d.ts +12 -0
- package/lib/providers/storage/utils.js +50 -0
- package/lib/registries/datasource-registry/abi.d.ts +116 -43
- package/lib/registries/datasource-registry/abi.js +190 -12
- package/lib/registries/datasource-registry/index.d.ts +12 -6
- package/lib/registries/datasource-registry/index.js +96 -20
- package/lib/registries/index.js +1 -1
- package/lib/registries/schema-registry/abi.d.ts +157 -66
- package/lib/registries/schema-registry/abi.js +242 -15
- package/lib/registries/schema-registry/index.d.ts +8 -3
- package/lib/registries/schema-registry/index.js +82 -17
- package/lib/registries/settlement-registry/abi.d.ts +199 -145
- package/lib/registries/settlement-registry/abi.js +331 -25
- package/lib/registries/settlement-registry/index.d.ts +36 -39
- package/lib/registries/settlement-registry/index.js +125 -91
- package/lib/registries/settlement-registry/types.d.ts +6 -3
- package/lib/roles/consumer/index.d.ts +17 -42
- package/lib/roles/consumer/index.js +87 -58
- package/lib/roles/consumer/types.d.ts +15 -34
- package/lib/roles/publisher/index.d.ts +22 -40
- package/lib/roles/publisher/index.js +69 -113
- package/lib/roles/publisher/types.d.ts +40 -41
- package/lib/roles/schema/index.d.ts +4 -30
- package/lib/roles/schema/index.js +7 -60
- package/lib/roles/schema/types.d.ts +16 -2
- package/lib/test/testbed.d.ts +12 -36
- package/lib/test/testbed.js +35 -68
- package/lib/types/index.d.ts +14 -57
- package/package.json +1 -6
- package/lib/modules/encryption/lit.d.ts +0 -21
- package/lib/modules/encryption/lit.js +0 -127
- package/lib/modules/gadgets/index.d.ts +0 -2
- package/lib/modules/gadgets/index.js +0 -1
- package/lib/modules/gadgets/settledGadget.d.ts +0 -31
- package/lib/modules/gadgets/settledGadget.js +0 -75
- package/lib/modules/gadgets/types.d.ts +0 -27
- 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
- /package/lib/{modules/gadgets → providers/storage}/types.js +0 -0
|
@@ -1,43 +1,10 @@
|
|
|
1
|
-
import { SDK } from "agent0-sdk";
|
|
2
|
-
|
|
3
1
|
//#region src/roles/schema/index.ts
|
|
4
2
|
var SchemaRole = class {
|
|
5
|
-
|
|
6
|
-
constructor(schemaRegistry, storage, walletClient, config) {
|
|
3
|
+
constructor(schemaRegistry, storage, walletClient) {
|
|
7
4
|
this.schemaRegistry = schemaRegistry;
|
|
8
5
|
this.storage = storage;
|
|
9
6
|
this.walletClient = walletClient;
|
|
10
|
-
this.agent0 = config ? new SDK({
|
|
11
|
-
chainId: config.chainId,
|
|
12
|
-
rpcUrl: config.rpcUrl,
|
|
13
|
-
privateKey: config.privateKey,
|
|
14
|
-
ipfs: "pinata",
|
|
15
|
-
pinataJwt: config.pinataJwt,
|
|
16
|
-
...config.registryOverrides && { registryOverrides: config.registryOverrides },
|
|
17
|
-
...config.subgraphOverrides && { subgraphOverrides: config.subgraphOverrides }
|
|
18
|
-
}) : null;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Register an agent identity via the agent0-sdk / ERC-8004.
|
|
22
|
-
*/
|
|
23
|
-
async registerAgent(params) {
|
|
24
|
-
const agent = this.requireAgent0().createAgent(params.name, params.description);
|
|
25
|
-
if (params.a2aUrl) await agent.setA2A(params.a2aUrl);
|
|
26
|
-
if (params.mcpEndpoint) await agent.setMCP(params.mcpEndpoint);
|
|
27
|
-
if (params.ens) agent.setENS(params.ens);
|
|
28
|
-
agent.setActive(true);
|
|
29
|
-
agent.setX402Support(true);
|
|
30
|
-
const { result: registrationFile } = await (await agent.registerIPFS()).waitConfirmed();
|
|
31
|
-
const agentId = registrationFile.agentId;
|
|
32
|
-
if (!agentId) throw new Error("ERC-8004 registration did not return an agentId");
|
|
33
|
-
return { agentId };
|
|
34
7
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Register a schema on-chain, tied to an existing agent identity.
|
|
37
|
-
*
|
|
38
|
-
* Uploads a versioned schema blob to IPFS (definition + metadata), then
|
|
39
|
-
* calls SchemaRegistry.registerSchema(name, schemaCid, agentId).
|
|
40
|
-
*/
|
|
41
8
|
async register(params) {
|
|
42
9
|
const owner = this.requireAccount();
|
|
43
10
|
const blob = {
|
|
@@ -48,7 +15,7 @@ var SchemaRole = class {
|
|
|
48
15
|
definition: params.definition,
|
|
49
16
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
50
17
|
};
|
|
51
|
-
const schemaCid = await this.storage.
|
|
18
|
+
const schemaCid = await this.storage.put(blob, { name: `schema:${params.name}` });
|
|
52
19
|
const { schemaId } = await this.schemaRegistry.registerSchema(params.name, schemaCid, params.agentId);
|
|
53
20
|
return {
|
|
54
21
|
schemaId,
|
|
@@ -59,19 +26,15 @@ var SchemaRole = class {
|
|
|
59
26
|
owner
|
|
60
27
|
};
|
|
61
28
|
}
|
|
62
|
-
/**
|
|
63
|
-
* Fetch a registered schema. Accepts either a schema name or a bytes32 id.
|
|
64
|
-
* Returns undefined if not registered.
|
|
65
|
-
*/
|
|
66
29
|
async get(nameOrId) {
|
|
67
30
|
try {
|
|
68
31
|
const schemaId = await this.schemaRegistry.schemaId(typeof nameOrId === "string" && !/^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : nameOrId);
|
|
69
32
|
const record = await this.schemaRegistry.getSchema(nameOrId);
|
|
70
|
-
if (!record.
|
|
71
|
-
const blob = await this.storage.
|
|
33
|
+
if (!record.specCid) return void 0;
|
|
34
|
+
const blob = await this.storage.get(record.specCid);
|
|
72
35
|
return {
|
|
73
36
|
schemaId,
|
|
74
|
-
schemaCid: record.
|
|
37
|
+
schemaCid: record.specCid,
|
|
75
38
|
definition: blob.definition,
|
|
76
39
|
name: blob.name,
|
|
77
40
|
agentId: blob.agentId,
|
|
@@ -82,16 +45,6 @@ var SchemaRole = class {
|
|
|
82
45
|
return;
|
|
83
46
|
}
|
|
84
47
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Validate that a data object structurally conforms to a schema definition.
|
|
87
|
-
*
|
|
88
|
-
* Shallow type-level check — catches missing fields and type mismatches
|
|
89
|
-
* before a publisher wastes gas on a bad commit. Encrypted fields require
|
|
90
|
-
* a `handle` object; ciphertext validity is enforced by the encryption
|
|
91
|
-
* service at upload time.
|
|
92
|
-
*
|
|
93
|
-
* Returns a list of validation errors, or an empty array if valid.
|
|
94
|
-
*/
|
|
95
48
|
validate(data, definition) {
|
|
96
49
|
const errors = [];
|
|
97
50
|
for (const [field, fieldDef] of Object.entries(definition)) {
|
|
@@ -113,11 +66,9 @@ var SchemaRole = class {
|
|
|
113
66
|
case "bytes":
|
|
114
67
|
if (!(value instanceof Uint8Array) && !ArrayBuffer.isView(value)) errors.push(`Field "${field}" must be bytes (Uint8Array)`);
|
|
115
68
|
break;
|
|
116
|
-
case "
|
|
117
|
-
|
|
118
|
-
if (!asObj.handle || typeof asObj.handle !== "object") errors.push(`Field "${field}" is encrypted — expected a { handle: { cid, gateway } } shape`);
|
|
69
|
+
case "handle":
|
|
70
|
+
if (typeof value.uri !== "string") errors.push(`Field "${field}" is a handle — expected { uri: string }`);
|
|
119
71
|
break;
|
|
120
|
-
}
|
|
121
72
|
}
|
|
122
73
|
}
|
|
123
74
|
return errors;
|
|
@@ -127,10 +78,6 @@ var SchemaRole = class {
|
|
|
127
78
|
if (!address) throw new Error("No account connected to wallet client");
|
|
128
79
|
return address;
|
|
129
80
|
}
|
|
130
|
-
requireAgent0() {
|
|
131
|
-
if (!this.agent0) throw new Error("registerAgent() requires AgentConfig (privateKey + pinataJwt). Pass agentConfig to Fangorn.init() to enable ERC-8004 registration.");
|
|
132
|
-
return this.agent0;
|
|
133
|
-
}
|
|
134
81
|
};
|
|
135
82
|
|
|
136
83
|
//#endregion
|
|
@@ -14,7 +14,21 @@ interface EncryptedField {
|
|
|
14
14
|
gateway: string;
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
interface PlainField {
|
|
18
|
+
"@type": "string" | "number" | "boolean" | "bytes";
|
|
19
|
+
}
|
|
20
|
+
interface HandleField {
|
|
21
|
+
"@type": "handle";
|
|
22
|
+
}
|
|
23
|
+
interface EncryptedField {
|
|
24
|
+
"@type": "encrypted";
|
|
25
|
+
gadget: string;
|
|
26
|
+
handle?: {
|
|
27
|
+
cid: string;
|
|
28
|
+
gateway: string;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
type FieldDefinition = PlainField | HandleField | EncryptedField;
|
|
18
32
|
type SchemaDefinition = Record<string, FieldDefinition>;
|
|
19
33
|
interface RegisterAgentParams {
|
|
20
34
|
name: string;
|
|
@@ -64,4 +78,4 @@ interface SchemaRoleConfig {
|
|
|
64
78
|
subgraphOverrides?: Record<number, string>;
|
|
65
79
|
}
|
|
66
80
|
//#endregion
|
|
67
|
-
export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig };
|
|
81
|
+
export { EncryptedField, FieldDefinition, HandleField, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig };
|
package/lib/test/testbed.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SchemaDefinition } from "../roles/schema/types.js";
|
|
2
2
|
import "../roles/schema/index.js";
|
|
3
|
-
import { PrepareSettleResult, TransferWithAuthPayload } from "../registries/settlement-registry/types.js";
|
|
4
|
-
import { SettlementRegistry } from "../registries/settlement-registry/index.js";
|
|
5
3
|
import { PublishRecord } from "../roles/publisher/types.js";
|
|
6
4
|
import "../roles/publisher/index.js";
|
|
5
|
+
import { PrepareSettleResult, TransferWithAuthPayload } from "../registries/settlement-registry/types.js";
|
|
6
|
+
import { SettlementRegistry } from "../registries/settlement-registry/index.js";
|
|
7
7
|
import { Fangorn } from "../fangorn.js";
|
|
8
8
|
import { Address, Hex, WalletClient } from "viem";
|
|
9
9
|
import { Identity } from "@semaphore-protocol/identity";
|
|
@@ -15,45 +15,21 @@ declare class TestBed {
|
|
|
15
15
|
private readonly delegateeFangorn;
|
|
16
16
|
private readonly usdcContractAddress;
|
|
17
17
|
private readonly usdcDomainName;
|
|
18
|
+
private readonly workerUrl;
|
|
18
19
|
private constructor();
|
|
19
|
-
|
|
20
|
-
* Init the testbed client
|
|
21
|
-
* @param delegatorWalletClient
|
|
22
|
-
* @param delegateeWalletClient
|
|
23
|
-
* @param jwt
|
|
24
|
-
* @param gateway
|
|
25
|
-
* @param dataSourceRegistryContractAddress
|
|
26
|
-
* @param schemaRegistryContractAddress
|
|
27
|
-
* @param settlementRegistryContractAddress
|
|
28
|
-
* @param usdcContractAddress
|
|
29
|
-
* @param usdcDomainName
|
|
30
|
-
* @param rpcUrl
|
|
31
|
-
* @param chain
|
|
32
|
-
* @param caip2
|
|
33
|
-
* @param delegatorPrivateKey
|
|
34
|
-
* @returns The testbed client
|
|
35
|
-
*/
|
|
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>;
|
|
20
|
+
static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number, workerUrl: string): TestBed;
|
|
38
21
|
registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
|
|
39
|
-
|
|
40
|
-
* Upload files encrypted under SettledGadget.
|
|
41
|
-
*
|
|
42
|
-
* Each file gets its own resourceId derived from (owner, schemaId, file.tag),
|
|
43
|
-
* which is baked into the ACC at encryption time. A buyer must complete the
|
|
44
|
-
* full purchase → claim flow for each specific tag before decrypting.
|
|
45
|
-
*/
|
|
46
|
-
fileUpload(records: PublishRecord[], schemaName: string, gateway: string, price: bigint): Promise<string>;
|
|
22
|
+
fileUpload(records: PublishRecord[], schemaName: string, price: bigint): Promise<string>;
|
|
47
23
|
prepareRegister(burnerPrivateKey: Hex, paymentRecipient: Address, amount: bigint): Promise<TransferWithAuthPayload>;
|
|
48
|
-
register(owner: Address, schemaId: Hex,
|
|
49
|
-
prepareSettle(owner: Address, schemaId: Hex,
|
|
50
|
-
settle(owner: Address, schemaId: Hex,
|
|
24
|
+
register(owner: Address, schemaId: Hex, name: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
|
|
25
|
+
prepareSettle(owner: Address, schemaId: Hex, name: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
|
|
26
|
+
settle(owner: Address, schemaId: Hex, name: string, relayerPrivateKey: Hex, preparedSettle: PrepareSettleResult): Promise<{
|
|
51
27
|
txHash: Hex;
|
|
52
28
|
nullifier: bigint;
|
|
53
29
|
}>;
|
|
54
|
-
|
|
55
|
-
checkManifestExists(who: Address, schemaId: Hex): Promise<boolean>;
|
|
56
|
-
checkEntryExists(who: Address, schemaId: Hex,
|
|
30
|
+
fetchContent(owner: Address, schemaId: Hex, name: string, field: string, nullifier: string, stealthPrivateKey: Hex): Promise<Uint8Array>;
|
|
31
|
+
checkManifestExists(who: Address, schemaId: Hex, name: string): Promise<boolean>;
|
|
32
|
+
checkEntryExists(who: Address, schemaId: Hex, name: string): Promise<boolean>;
|
|
57
33
|
getDelegatorAddress(): Address;
|
|
58
34
|
getDelegatorFangorn(): Fangorn;
|
|
59
35
|
getDelegateeFangorn(): Fangorn;
|
package/lib/test/testbed.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
|
|
2
2
|
import { Fangorn } from "../fangorn.js";
|
|
3
3
|
import { arbitrumSepolia, baseSepolia } from "viem/chains";
|
|
4
4
|
import { createWalletClient, http } from "viem";
|
|
@@ -6,31 +6,15 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
6
6
|
|
|
7
7
|
//#region src/test/testbed.ts
|
|
8
8
|
var TestBed = class TestBed {
|
|
9
|
-
constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName) {
|
|
9
|
+
constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName, workerUrl) {
|
|
10
10
|
this.delegatorAddress = delegatorAddress;
|
|
11
11
|
this.delegatorFangorn = delegatorFangorn;
|
|
12
12
|
this.delegateeFangorn = delegateeFangorn;
|
|
13
13
|
this.usdcContractAddress = usdcContractAddress;
|
|
14
14
|
this.usdcDomainName = usdcDomainName;
|
|
15
|
+
this.workerUrl = workerUrl;
|
|
15
16
|
}
|
|
16
|
-
|
|
17
|
-
* Init the testbed client
|
|
18
|
-
* @param delegatorWalletClient
|
|
19
|
-
* @param delegateeWalletClient
|
|
20
|
-
* @param jwt
|
|
21
|
-
* @param gateway
|
|
22
|
-
* @param dataSourceRegistryContractAddress
|
|
23
|
-
* @param schemaRegistryContractAddress
|
|
24
|
-
* @param settlementRegistryContractAddress
|
|
25
|
-
* @param usdcContractAddress
|
|
26
|
-
* @param usdcDomainName
|
|
27
|
-
* @param rpcUrl
|
|
28
|
-
* @param chain
|
|
29
|
-
* @param caip2
|
|
30
|
-
* @param delegatorPrivateKey
|
|
31
|
-
* @returns The testbed client
|
|
32
|
-
*/
|
|
33
|
-
static async init(delegatorWalletClient, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2) {
|
|
17
|
+
static init(delegatorWalletClient, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2, workerUrl) {
|
|
34
18
|
let chainImpl = arbitrumSepolia;
|
|
35
19
|
if (chain === "baseSepolia") chainImpl = baseSepolia;
|
|
36
20
|
const config = {
|
|
@@ -40,31 +24,25 @@ var TestBed = class TestBed {
|
|
|
40
24
|
chainName: chain,
|
|
41
25
|
chain: chainImpl,
|
|
42
26
|
rpcUrl,
|
|
43
|
-
caip2
|
|
27
|
+
caip2,
|
|
28
|
+
ipfsGateway: "https://ipfs.io"
|
|
44
29
|
};
|
|
45
|
-
const delegatorFangorn =
|
|
30
|
+
const delegatorFangorn = Fangorn.create({
|
|
46
31
|
privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
|
|
47
32
|
storage: { pinata: {
|
|
48
33
|
jwt: process.env.PINATA_JWT ?? "",
|
|
49
34
|
gateway: process.env.PINATA_GATEWAY ?? ""
|
|
50
35
|
} },
|
|
51
|
-
encryption: { lit: true },
|
|
52
36
|
config,
|
|
53
|
-
domain: "localhost"
|
|
54
|
-
agentConfig: void 0
|
|
37
|
+
domain: "localhost"
|
|
55
38
|
});
|
|
56
|
-
const delegateeFangorn =
|
|
39
|
+
const delegateeFangorn = Fangorn.create({
|
|
57
40
|
privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
|
|
58
|
-
storage: { storacha: { "readOnly": true } },
|
|
59
|
-
encryption: { lit: true },
|
|
60
41
|
config,
|
|
61
42
|
domain: "localhost"
|
|
62
43
|
});
|
|
63
44
|
if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
|
|
64
|
-
return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
|
|
65
|
-
}
|
|
66
|
-
async registerAgent(params) {
|
|
67
|
-
return this.delegatorFangorn.schema.registerAgent(params);
|
|
45
|
+
return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName, workerUrl);
|
|
68
46
|
}
|
|
69
47
|
async registerSchema(name, definition, agentId) {
|
|
70
48
|
const { schemaId } = await this.delegatorFangorn.schema.register({
|
|
@@ -74,24 +52,21 @@ var TestBed = class TestBed {
|
|
|
74
52
|
});
|
|
75
53
|
return schemaId;
|
|
76
54
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
*
|
|
80
|
-
* Each file gets its own resourceId derived from (owner, schemaId, file.tag),
|
|
81
|
-
* which is baked into the ACC at encryption time. A buyer must complete the
|
|
82
|
-
* full purchase → claim flow for each specific tag before decrypting.
|
|
83
|
-
*/
|
|
84
|
-
async fileUpload(records, schemaName, gateway, price) {
|
|
85
|
-
const { manifestCid } = await this.delegatorFangorn.publisher.upload({
|
|
55
|
+
async fileUpload(records, schemaName, price) {
|
|
56
|
+
const { manifestUri } = await this.delegatorFangorn.publisher.upload({
|
|
86
57
|
records,
|
|
87
|
-
schemaName
|
|
88
|
-
gateway
|
|
58
|
+
schemaName
|
|
89
59
|
}, price);
|
|
90
|
-
return
|
|
60
|
+
return manifestUri;
|
|
91
61
|
}
|
|
92
62
|
async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
|
|
63
|
+
const walletClient = createWalletClient({
|
|
64
|
+
account: privateKeyToAccount(burnerPrivateKey),
|
|
65
|
+
chain: arbitrumSepolia,
|
|
66
|
+
transport: http(process.env.RPC_URL ?? "")
|
|
67
|
+
});
|
|
93
68
|
return this.delegateeFangorn.consumer.prepareRegister({
|
|
94
|
-
|
|
69
|
+
walletClient,
|
|
95
70
|
paymentRecipient,
|
|
96
71
|
amount,
|
|
97
72
|
usdcAddress: this.usdcContractAddress,
|
|
@@ -99,29 +74,29 @@ var TestBed = class TestBed {
|
|
|
99
74
|
usdcDomainVersion: "2"
|
|
100
75
|
});
|
|
101
76
|
}
|
|
102
|
-
async register(owner, schemaId,
|
|
77
|
+
async register(owner, schemaId, name, identityCommitment, relayerPrivateKey, preparedRegister) {
|
|
103
78
|
const { txHash } = await this.delegateeFangorn.consumer.register({
|
|
104
79
|
owner,
|
|
105
80
|
schemaId,
|
|
106
|
-
|
|
81
|
+
name,
|
|
107
82
|
identityCommitment,
|
|
108
83
|
relayerPrivateKey,
|
|
109
84
|
preparedRegister
|
|
110
85
|
});
|
|
111
86
|
return txHash;
|
|
112
87
|
}
|
|
113
|
-
async prepareSettle(owner, schemaId,
|
|
88
|
+
async prepareSettle(owner, schemaId, name, identity, stealthAddress) {
|
|
114
89
|
return this.delegateeFangorn.consumer.prepareSettle({
|
|
115
|
-
resourceId:
|
|
90
|
+
resourceId: DataSourceRegistry.resourceIdLocal(owner, schemaId, name),
|
|
116
91
|
identity,
|
|
117
92
|
stealthAddress
|
|
118
93
|
});
|
|
119
94
|
}
|
|
120
|
-
async settle(owner, schemaId,
|
|
95
|
+
async settle(owner, schemaId, name, relayerPrivateKey, preparedSettle) {
|
|
121
96
|
const { txHash, nullifier } = await this.delegateeFangorn.consumer.claim({
|
|
122
97
|
owner,
|
|
123
98
|
schemaId,
|
|
124
|
-
|
|
99
|
+
name,
|
|
125
100
|
relayerPrivateKey,
|
|
126
101
|
preparedSettle
|
|
127
102
|
});
|
|
@@ -130,29 +105,21 @@ var TestBed = class TestBed {
|
|
|
130
105
|
nullifier
|
|
131
106
|
};
|
|
132
107
|
}
|
|
133
|
-
async
|
|
108
|
+
async fetchContent(owner, schemaId, name, field, nullifier, stealthPrivateKey) {
|
|
134
109
|
const walletClient = createWalletClient({
|
|
135
|
-
account: privateKeyToAccount(
|
|
110
|
+
account: privateKeyToAccount(stealthPrivateKey),
|
|
136
111
|
chain: arbitrumSepolia,
|
|
137
|
-
transport: http(
|
|
138
|
-
});
|
|
139
|
-
return this.delegateeFangorn.consumer.decrypt({
|
|
140
|
-
owner,
|
|
141
|
-
walletClient,
|
|
142
|
-
schemaId,
|
|
143
|
-
nullifierHash,
|
|
144
|
-
tag,
|
|
145
|
-
field,
|
|
146
|
-
identity,
|
|
147
|
-
skipSettlementCheck: !requireSettlement
|
|
112
|
+
transport: http(process.env.RPC_URL ?? "")
|
|
148
113
|
});
|
|
114
|
+
const { data } = await this.delegateeFangorn.consumer.fetchField(owner, schemaId, name, field, nullifier, walletClient);
|
|
115
|
+
return data;
|
|
149
116
|
}
|
|
150
|
-
async checkManifestExists(who, schemaId) {
|
|
151
|
-
return await this.delegatorFangorn.consumer.getManifest(who, schemaId) !== void 0;
|
|
117
|
+
async checkManifestExists(who, schemaId, name) {
|
|
118
|
+
return await this.delegatorFangorn.consumer.getManifest(who, schemaId, name) !== void 0;
|
|
152
119
|
}
|
|
153
|
-
async checkEntryExists(who, schemaId,
|
|
120
|
+
async checkEntryExists(who, schemaId, name) {
|
|
154
121
|
try {
|
|
155
|
-
await this.delegatorFangorn.consumer.getEntry(who, schemaId,
|
|
122
|
+
await this.delegatorFangorn.consumer.getEntry(who, schemaId, name);
|
|
156
123
|
return true;
|
|
157
124
|
} catch {
|
|
158
125
|
return false;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,56 +1,16 @@
|
|
|
1
1
|
import { AppConfig } from "../config.js";
|
|
2
2
|
import { SchemaRegistry } from "../registries/schema-registry/index.js";
|
|
3
|
-
import {
|
|
3
|
+
import { MetadataStorage } from "../providers/storage/types.js";
|
|
4
4
|
import { SchemaRoleConfig } from "../roles/schema/types.js";
|
|
5
|
-
import "../roles/schema/index.js";
|
|
6
5
|
import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
|
|
7
|
-
import { GadgetDescriptor } from "../modules/gadgets/types.js";
|
|
8
6
|
import { SettlementRegistry } from "../registries/settlement-registry/index.js";
|
|
9
|
-
import { EncryptionService } from "../modules/encryption/index.js";
|
|
10
7
|
import { Hex, WalletClient } from "viem";
|
|
11
8
|
|
|
12
9
|
//#region src/types/index.d.ts
|
|
13
|
-
interface PendingEntry {
|
|
14
|
-
tag: string;
|
|
15
|
-
cid: string;
|
|
16
|
-
gadgetDescriptor: GadgetDescriptor;
|
|
17
|
-
extension: string;
|
|
18
|
-
fileType: string;
|
|
19
|
-
}
|
|
20
|
-
interface Filedata {
|
|
21
|
-
tag: string;
|
|
22
|
-
data: Uint8Array;
|
|
23
|
-
extension: string;
|
|
24
|
-
fileType: string;
|
|
25
|
-
}
|
|
26
|
-
interface EncryptedData {
|
|
27
|
-
ciphertext: Uint8Array<ArrayBuffer>;
|
|
28
|
-
iv: Uint8Array<ArrayBuffer>;
|
|
29
|
-
authTag: Uint8Array<ArrayBuffer>;
|
|
30
|
-
salt: Uint8Array<ArrayBuffer>;
|
|
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
|
-
interface AgentConfig {
|
|
39
|
-
privateKey: Hex;
|
|
40
|
-
pinataJwt: string;
|
|
41
|
-
/** Override ERC-8004 registry addresses per chainId (e.g. for Arbitrum Sepolia) */
|
|
42
|
-
registryOverrides?: Record<number, {
|
|
43
|
-
IDENTITY: string;
|
|
44
|
-
REPUTATION: string;
|
|
45
|
-
}>;
|
|
46
|
-
/** Override subgraph URLs per chainId */
|
|
47
|
-
subgraphOverrides?: Record<number, string>;
|
|
48
|
-
}
|
|
49
10
|
interface FangornContext {
|
|
50
11
|
config: AppConfig;
|
|
51
12
|
walletClient: WalletClient;
|
|
52
|
-
|
|
53
|
-
encryption: EncryptionService;
|
|
13
|
+
metadataStorage: MetadataStorage | undefined;
|
|
54
14
|
domain: string;
|
|
55
15
|
schemaRegistry: SchemaRegistry;
|
|
56
16
|
dataSourceRegistry: DataSourceRegistry;
|
|
@@ -62,21 +22,18 @@ type StorageConfig = {
|
|
|
62
22
|
jwt: string;
|
|
63
23
|
gateway: string;
|
|
64
24
|
};
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
lit: true;
|
|
76
|
-
} | EncryptionService;
|
|
25
|
+
};
|
|
26
|
+
interface AgentConfig {
|
|
27
|
+
privateKey: Hex;
|
|
28
|
+
pinataJwt: string;
|
|
29
|
+
registryOverrides?: Record<number, {
|
|
30
|
+
IDENTITY: string;
|
|
31
|
+
REPUTATION: string;
|
|
32
|
+
}>;
|
|
33
|
+
subgraphOverrides?: Record<number, string>;
|
|
34
|
+
}
|
|
77
35
|
interface FangornCreateOptions {
|
|
78
|
-
storage
|
|
79
|
-
encryption: EncryptionConfig;
|
|
36
|
+
storage?: StorageConfig;
|
|
80
37
|
config?: AppConfig;
|
|
81
38
|
domain?: string;
|
|
82
39
|
agentConfig?: AgentConfig;
|
|
@@ -84,4 +41,4 @@ interface FangornCreateOptions {
|
|
|
84
41
|
walletClient?: WalletClient;
|
|
85
42
|
}
|
|
86
43
|
//#endregion
|
|
87
|
-
export { AgentConfig,
|
|
44
|
+
export { AgentConfig, FangornContext, FangornCreateOptions, StorageConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fangorn-network/sdk",
|
|
3
|
-
"version": "2026.04.
|
|
3
|
+
"version": "2026.04.15",
|
|
4
4
|
"description": "A zero-knowledge conditional access control framework",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,11 +40,6 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@a2a-js/sdk": "^0.3.10",
|
|
42
42
|
"@clack/prompts": "^1.0.1",
|
|
43
|
-
"@lit-protocol/access-control-conditions": "^8.0.2",
|
|
44
|
-
"@lit-protocol/auth": "^8.2.2",
|
|
45
|
-
"@lit-protocol/auth-helpers": "^8.2.1",
|
|
46
|
-
"@lit-protocol/lit-client": "^8.3.1",
|
|
47
|
-
"@lit-protocol/networks": "^8.4.1",
|
|
48
43
|
"@semaphore-protocol/group": "^4.14.2",
|
|
49
44
|
"@semaphore-protocol/identity": "^4.14.2",
|
|
50
45
|
"@semaphore-protocol/proof": "^4.14.2",
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Gadget } from "../gadgets/types.js";
|
|
2
|
-
import { Filedata } from "../../types/index.js";
|
|
3
|
-
import { AuthContextWrapper, DecryptedPayload, EncryptedPayload } from "./types.js";
|
|
4
|
-
import { EncryptionService } from "./index.js";
|
|
5
|
-
import { WalletClient } from "viem";
|
|
6
|
-
import { LitClient } from "@lit-protocol/lit-client";
|
|
7
|
-
|
|
8
|
-
//#region src/modules/encryption/lit.d.ts
|
|
9
|
-
declare class LitEncryptionService implements EncryptionService {
|
|
10
|
-
private readonly litClient;
|
|
11
|
-
private readonly chainName;
|
|
12
|
-
constructor(litClient: LitClient, chainName: string);
|
|
13
|
-
static init(chain: string): Promise<LitEncryptionService>;
|
|
14
|
-
encrypt(file: Filedata, gadget: Gadget): Promise<EncryptedPayload>;
|
|
15
|
-
decrypt(payload: EncryptedPayload, authContext: AuthContextWrapper): Promise<DecryptedPayload>;
|
|
16
|
-
createAuthContext(walletClient: WalletClient, domain: string): Promise<AuthContextWrapper>;
|
|
17
|
-
private createAuthSig;
|
|
18
|
-
private parseKeyResponse;
|
|
19
|
-
}
|
|
20
|
-
//#endregion
|
|
21
|
-
export { LitEncryptionService };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { decryptData, encryptData } from "./aes.js";
|
|
2
|
-
import { LitAccessControlConditionResource, LitActionResource, LitPKPResource, createSiweMessage } from "@lit-protocol/auth-helpers";
|
|
3
|
-
import { createLitClient } from "@lit-protocol/lit-client";
|
|
4
|
-
import { createAuthManager, storagePlugins } from "@lit-protocol/auth";
|
|
5
|
-
import { nagaDev } from "@lit-protocol/networks";
|
|
6
|
-
|
|
7
|
-
//#region src/modules/encryption/lit.ts
|
|
8
|
-
var LitEncryptionService = class LitEncryptionService {
|
|
9
|
-
constructor(litClient, chainName) {
|
|
10
|
-
this.litClient = litClient;
|
|
11
|
-
this.chainName = chainName;
|
|
12
|
-
}
|
|
13
|
-
static async init(chain) {
|
|
14
|
-
return new LitEncryptionService(await createLitClient({ network: nagaDev }), chain);
|
|
15
|
-
}
|
|
16
|
-
async encrypt(file, gadget) {
|
|
17
|
-
const { encryptedData, keyMaterial } = await encryptData(file.data);
|
|
18
|
-
const rawAcc = gadget.toAccessCondition()[0];
|
|
19
|
-
const litEncryptedKey = await this.litClient.encrypt({
|
|
20
|
-
dataToEncrypt: keyMaterial.toString(),
|
|
21
|
-
evmContractConditions: [rawAcc],
|
|
22
|
-
chain: this.chainName
|
|
23
|
-
});
|
|
24
|
-
return {
|
|
25
|
-
data: encryptedData,
|
|
26
|
-
key: {
|
|
27
|
-
ciphertext: litEncryptedKey.ciphertext,
|
|
28
|
-
dataToEncryptHash: litEncryptedKey.dataToEncryptHash
|
|
29
|
-
},
|
|
30
|
-
acc: [rawAcc]
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
async decrypt(payload, authContext) {
|
|
34
|
-
console.log("authSig address:", authContext.authSig.address);
|
|
35
|
-
const result = await this.litClient.decrypt({
|
|
36
|
-
data: {
|
|
37
|
-
ciphertext: payload.key.ciphertext,
|
|
38
|
-
dataToEncryptHash: payload.key.dataToEncryptHash
|
|
39
|
-
},
|
|
40
|
-
unifiedAccessControlConditions: payload.acc,
|
|
41
|
-
authContext: authContext.sessionContext,
|
|
42
|
-
chain: this.chainName
|
|
43
|
-
});
|
|
44
|
-
const decryptedString = new TextDecoder().decode(result.decryptedData);
|
|
45
|
-
const key = new Uint8Array(decryptedString.split(",").map((n) => parseInt(n.trim(), 10)));
|
|
46
|
-
return { data: await decryptData(payload.data, key) };
|
|
47
|
-
}
|
|
48
|
-
async createAuthContext(walletClient, domain) {
|
|
49
|
-
const isNode = typeof window === "undefined";
|
|
50
|
-
const account = isNode ? walletClient.account : walletClient;
|
|
51
|
-
if (!account) throw new Error("No account found in wallet client");
|
|
52
|
-
if (!walletClient.chain) throw new Error("No chain found in wallet client");
|
|
53
|
-
const sessionContext = await (isNode ? createAuthManager({ storage: storagePlugins.localStorageNode({
|
|
54
|
-
appName: "fangorn",
|
|
55
|
-
networkName: "naga-dev",
|
|
56
|
-
storagePath: "./lit-auth-storage"
|
|
57
|
-
}) }) : createAuthManager({ storage: storagePlugins.localStorage({
|
|
58
|
-
appName: "fangorn",
|
|
59
|
-
networkName: "naga-dev"
|
|
60
|
-
}) })).createEoaAuthContext({
|
|
61
|
-
litClient: this.litClient,
|
|
62
|
-
config: { account },
|
|
63
|
-
authConfig: {
|
|
64
|
-
domain,
|
|
65
|
-
statement: "Recover key.",
|
|
66
|
-
expiration: new Date(Date.now() + 1e3 * 60 * 60 * 24).toISOString(),
|
|
67
|
-
resources: [
|
|
68
|
-
["access-control-condition-decryption", "*"],
|
|
69
|
-
["lit-action-execution", "*"],
|
|
70
|
-
["pkp-signing", "*"]
|
|
71
|
-
]
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
return {
|
|
75
|
-
authSig: await this.createAuthSig(walletClient, domain),
|
|
76
|
-
sessionContext,
|
|
77
|
-
chainName: walletClient.chain.name
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
async createAuthSig(walletClient, domain) {
|
|
81
|
-
const account = walletClient.account;
|
|
82
|
-
if (!account) throw new Error("No account found in wallet client");
|
|
83
|
-
const resources = [
|
|
84
|
-
{
|
|
85
|
-
resource: new LitAccessControlConditionResource("*"),
|
|
86
|
-
ability: "access-control-condition-decryption"
|
|
87
|
-
},
|
|
88
|
-
{
|
|
89
|
-
resource: new LitActionResource("*"),
|
|
90
|
-
ability: "lit-action-execution"
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
resource: new LitPKPResource("*"),
|
|
94
|
-
ability: "pkp-signing"
|
|
95
|
-
}
|
|
96
|
-
];
|
|
97
|
-
const siweMessage = await createSiweMessage({
|
|
98
|
-
walletAddress: account.address,
|
|
99
|
-
domain,
|
|
100
|
-
statement: "Decrypt data.",
|
|
101
|
-
uri: `https://${domain}`,
|
|
102
|
-
version: "1",
|
|
103
|
-
chainId: 1,
|
|
104
|
-
expiration: new Date(Date.now() + 1e3 * 60 * 60 * 24).toISOString(),
|
|
105
|
-
resources,
|
|
106
|
-
nonce: Date.now().toString()
|
|
107
|
-
});
|
|
108
|
-
return {
|
|
109
|
-
sig: await walletClient.signMessage({
|
|
110
|
-
message: siweMessage,
|
|
111
|
-
account
|
|
112
|
-
}),
|
|
113
|
-
derivedVia: "web3.eth.personal.sign",
|
|
114
|
-
signedMessage: siweMessage,
|
|
115
|
-
address: account.address
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
parseKeyResponse(response) {
|
|
119
|
-
return Uint8Array.from(response.replace(/^[^\d]+/, "").split(","), (entry) => {
|
|
120
|
-
const val = parseInt(entry.trim(), 10);
|
|
121
|
-
return isNaN(val) ? 0 : val;
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
//#endregion
|
|
127
|
-
export { LitEncryptionService };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|