@fangorn-network/sdk 2026.4.10 → 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 +118 -135
- package/lib/cli/cli.js +42 -96
- package/lib/cli/index.d.ts +159 -159
- package/lib/fangorn.d.ts +3 -17
- package/lib/fangorn.js +12 -37
- package/lib/index.d.ts +3 -7
- package/lib/index.js +3 -5
- 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 -49
- package/lib/providers/storage/pinata.d.ts +8 -5
- package/lib/providers/storage/pinata.js +16 -8
- 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/index.d.ts +2 -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 +14 -18
- package/lib/roles/consumer/index.js +73 -24
- package/lib/roles/consumer/types.d.ts +13 -32
- package/lib/roles/publisher/index.d.ts +17 -32
- package/lib/roles/publisher/index.js +37 -74
- package/lib/roles/publisher/types.d.ts +36 -41
- package/lib/roles/schema/index.d.ts +4 -25
- package/lib/roles/schema/index.js +5 -30
- package/lib/roles/schema/types.d.ts +16 -2
- package/lib/test/testbed.d.ts +6 -5
- package/lib/test/testbed.js +16 -26
- package/lib/types/index.d.ts +12 -45
- package/package.json +1 -6
- package/lib/modules/encryption/lit.d.ts +0 -20
- package/lib/modules/encryption/lit.js +0 -121
- 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 -24
- package/lib/modules/gadgets/settledGadget.js +0 -63
- package/lib/modules/gadgets/types.d.ts +0 -27
- /package/lib/{modules/gadgets → providers/storage}/types.js +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { SchemaRegistry } from "../../registries/schema-registry/index.js";
|
|
2
|
-
import {
|
|
3
|
-
import { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig } from "./types.js";
|
|
2
|
+
import { MetadataStorage } from "../../providers/storage/types.js";
|
|
3
|
+
import { EncryptedField, FieldDefinition, HandleField, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRoleConfig } from "./types.js";
|
|
4
4
|
import { WalletClient } from "viem";
|
|
5
5
|
|
|
6
6
|
//#region src/roles/schema/index.d.ts
|
|
@@ -8,32 +8,11 @@ declare class SchemaRole {
|
|
|
8
8
|
private readonly schemaRegistry;
|
|
9
9
|
private readonly storage;
|
|
10
10
|
private readonly walletClient;
|
|
11
|
-
|
|
12
|
-
constructor(schemaRegistry: SchemaRegistry, storage: PinningService, walletClient: WalletClient, ipfsGateway: string);
|
|
13
|
-
/**
|
|
14
|
-
* Register a schema on-chain, tied to an existing agent identity.
|
|
15
|
-
*
|
|
16
|
-
* Uploads a versioned schema blob to IPFS (definition + metadata), then
|
|
17
|
-
* calls SchemaRegistry.registerSchema(name, schemaCid, agentId).
|
|
18
|
-
*/
|
|
11
|
+
constructor(schemaRegistry: SchemaRegistry, storage: MetadataStorage, walletClient: WalletClient);
|
|
19
12
|
register(params: RegisterSchemaParams): Promise<RegisteredSchema>;
|
|
20
|
-
/**
|
|
21
|
-
* Fetch a registered schema. Accepts either a schema name or a bytes32 id.
|
|
22
|
-
* Returns undefined if not registered.
|
|
23
|
-
*/
|
|
24
13
|
get(nameOrId: string): Promise<RegisteredSchema | undefined>;
|
|
25
|
-
/**
|
|
26
|
-
* Validate that a data object structurally conforms to a schema definition.
|
|
27
|
-
*
|
|
28
|
-
* Shallow type-level check — catches missing fields and type mismatches
|
|
29
|
-
* before a publisher wastes gas on a bad commit. Encrypted fields require
|
|
30
|
-
* a `handle` object; ciphertext validity is enforced by the encryption
|
|
31
|
-
* service at upload time.
|
|
32
|
-
*
|
|
33
|
-
* Returns a list of validation errors, or an empty array if valid.
|
|
34
|
-
*/
|
|
35
14
|
validate(data: Record<string, unknown>, definition: SchemaDefinition): string[];
|
|
36
15
|
private requireAccount;
|
|
37
16
|
}
|
|
38
17
|
//#endregion
|
|
39
|
-
export { EncryptedField, FieldDefinition, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
|
|
18
|
+
export { EncryptedField, FieldDefinition, HandleField, PlainField, RegisterAgentParams, RegisterSchemaParams, RegisteredAgent, RegisteredSchema, SchemaBlobV1, SchemaDefinition, SchemaRole, SchemaRoleConfig };
|
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import { retrieveByCid } from "../../providers/storage/index.js";
|
|
2
|
-
|
|
3
1
|
//#region src/roles/schema/index.ts
|
|
4
2
|
var SchemaRole = class {
|
|
5
|
-
constructor(schemaRegistry, storage, walletClient
|
|
3
|
+
constructor(schemaRegistry, storage, walletClient) {
|
|
6
4
|
this.schemaRegistry = schemaRegistry;
|
|
7
5
|
this.storage = storage;
|
|
8
6
|
this.walletClient = walletClient;
|
|
9
|
-
this.ipfsGateway = ipfsGateway;
|
|
10
7
|
}
|
|
11
|
-
/**
|
|
12
|
-
* Register a schema on-chain, tied to an existing agent identity.
|
|
13
|
-
*
|
|
14
|
-
* Uploads a versioned schema blob to IPFS (definition + metadata), then
|
|
15
|
-
* calls SchemaRegistry.registerSchema(name, schemaCid, agentId).
|
|
16
|
-
*/
|
|
17
8
|
async register(params) {
|
|
18
9
|
const owner = this.requireAccount();
|
|
19
10
|
const blob = {
|
|
@@ -24,7 +15,7 @@ var SchemaRole = class {
|
|
|
24
15
|
definition: params.definition,
|
|
25
16
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
26
17
|
};
|
|
27
|
-
const schemaCid = await this.storage.
|
|
18
|
+
const schemaCid = await this.storage.put(blob, { name: `schema:${params.name}` });
|
|
28
19
|
const { schemaId } = await this.schemaRegistry.registerSchema(params.name, schemaCid, params.agentId);
|
|
29
20
|
return {
|
|
30
21
|
schemaId,
|
|
@@ -35,16 +26,12 @@ var SchemaRole = class {
|
|
|
35
26
|
owner
|
|
36
27
|
};
|
|
37
28
|
}
|
|
38
|
-
/**
|
|
39
|
-
* Fetch a registered schema. Accepts either a schema name or a bytes32 id.
|
|
40
|
-
* Returns undefined if not registered.
|
|
41
|
-
*/
|
|
42
29
|
async get(nameOrId) {
|
|
43
30
|
try {
|
|
44
31
|
const schemaId = await this.schemaRegistry.schemaId(typeof nameOrId === "string" && !/^0x[0-9a-fA-F]{64}$/.test(nameOrId) ? nameOrId : nameOrId);
|
|
45
32
|
const record = await this.schemaRegistry.getSchema(nameOrId);
|
|
46
33
|
if (!record.specCid) return void 0;
|
|
47
|
-
const blob = await
|
|
34
|
+
const blob = await this.storage.get(record.specCid);
|
|
48
35
|
return {
|
|
49
36
|
schemaId,
|
|
50
37
|
schemaCid: record.specCid,
|
|
@@ -58,16 +45,6 @@ var SchemaRole = class {
|
|
|
58
45
|
return;
|
|
59
46
|
}
|
|
60
47
|
}
|
|
61
|
-
/**
|
|
62
|
-
* Validate that a data object structurally conforms to a schema definition.
|
|
63
|
-
*
|
|
64
|
-
* Shallow type-level check — catches missing fields and type mismatches
|
|
65
|
-
* before a publisher wastes gas on a bad commit. Encrypted fields require
|
|
66
|
-
* a `handle` object; ciphertext validity is enforced by the encryption
|
|
67
|
-
* service at upload time.
|
|
68
|
-
*
|
|
69
|
-
* Returns a list of validation errors, or an empty array if valid.
|
|
70
|
-
*/
|
|
71
48
|
validate(data, definition) {
|
|
72
49
|
const errors = [];
|
|
73
50
|
for (const [field, fieldDef] of Object.entries(definition)) {
|
|
@@ -89,11 +66,9 @@ var SchemaRole = class {
|
|
|
89
66
|
case "bytes":
|
|
90
67
|
if (!(value instanceof Uint8Array) && !ArrayBuffer.isView(value)) errors.push(`Field "${field}" must be bytes (Uint8Array)`);
|
|
91
68
|
break;
|
|
92
|
-
case "
|
|
93
|
-
|
|
94
|
-
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 }`);
|
|
95
71
|
break;
|
|
96
|
-
}
|
|
97
72
|
}
|
|
98
73
|
}
|
|
99
74
|
return errors;
|
|
@@ -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
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,10 +15,11 @@ 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
|
-
static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number):
|
|
20
|
+
static init(delegatorWalletClient: WalletClient, dataSourceRegistryContractAddress: Hex, schemaRegistryContractAddress: Hex, settlementRegistryContractAddress: Hex, usdcContractAddress: Hex, usdcDomainName: string, rpcUrl: string, chain: string, caip2: number, workerUrl: string): TestBed;
|
|
20
21
|
registerSchema(name: string, definition: SchemaDefinition, agentId: string): Promise<Hex>;
|
|
21
|
-
fileUpload(records: PublishRecord[], schemaName: string,
|
|
22
|
+
fileUpload(records: PublishRecord[], schemaName: string, price: bigint): Promise<string>;
|
|
22
23
|
prepareRegister(burnerPrivateKey: Hex, paymentRecipient: Address, amount: bigint): Promise<TransferWithAuthPayload>;
|
|
23
24
|
register(owner: Address, schemaId: Hex, name: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
|
|
24
25
|
prepareSettle(owner: Address, schemaId: Hex, name: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
|
|
@@ -26,7 +27,7 @@ declare class TestBed {
|
|
|
26
27
|
txHash: Hex;
|
|
27
28
|
nullifier: bigint;
|
|
28
29
|
}>;
|
|
29
|
-
|
|
30
|
+
fetchContent(owner: Address, schemaId: Hex, name: string, field: string, nullifier: string, stealthPrivateKey: Hex): Promise<Uint8Array>;
|
|
30
31
|
checkManifestExists(who: Address, schemaId: Hex, name: string): Promise<boolean>;
|
|
31
32
|
checkEntryExists(who: Address, schemaId: Hex, name: string): Promise<boolean>;
|
|
32
33
|
getDelegatorAddress(): Address;
|
package/lib/test/testbed.js
CHANGED
|
@@ -6,14 +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
|
-
static
|
|
17
|
+
static init(delegatorWalletClient, dataSourceRegistryContractAddress, schemaRegistryContractAddress, settlementRegistryContractAddress, usdcContractAddress, usdcDomainName, rpcUrl, chain, caip2, workerUrl) {
|
|
17
18
|
let chainImpl = arbitrumSepolia;
|
|
18
19
|
if (chain === "baseSepolia") chainImpl = baseSepolia;
|
|
19
20
|
const config = {
|
|
@@ -24,26 +25,24 @@ var TestBed = class TestBed {
|
|
|
24
25
|
chain: chainImpl,
|
|
25
26
|
rpcUrl,
|
|
26
27
|
caip2,
|
|
27
|
-
ipfsGateway: "https://
|
|
28
|
+
ipfsGateway: "https://ipfs.io"
|
|
28
29
|
};
|
|
29
|
-
const delegatorFangorn =
|
|
30
|
+
const delegatorFangorn = Fangorn.create({
|
|
30
31
|
privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
|
|
31
32
|
storage: { pinata: {
|
|
32
33
|
jwt: process.env.PINATA_JWT ?? "",
|
|
33
34
|
gateway: process.env.PINATA_GATEWAY ?? ""
|
|
34
35
|
} },
|
|
35
|
-
encryption: { lit: true },
|
|
36
36
|
config,
|
|
37
37
|
domain: "localhost"
|
|
38
38
|
});
|
|
39
|
-
const delegateeFangorn =
|
|
39
|
+
const delegateeFangorn = Fangorn.create({
|
|
40
40
|
privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
|
|
41
|
-
encryption: { lit: true },
|
|
42
41
|
config,
|
|
43
42
|
domain: "localhost"
|
|
44
43
|
});
|
|
45
44
|
if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
|
|
46
|
-
return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
|
|
45
|
+
return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName, workerUrl);
|
|
47
46
|
}
|
|
48
47
|
async registerSchema(name, definition, agentId) {
|
|
49
48
|
const { schemaId } = await this.delegatorFangorn.schema.register({
|
|
@@ -53,13 +52,12 @@ var TestBed = class TestBed {
|
|
|
53
52
|
});
|
|
54
53
|
return schemaId;
|
|
55
54
|
}
|
|
56
|
-
async fileUpload(records, schemaName,
|
|
57
|
-
const {
|
|
55
|
+
async fileUpload(records, schemaName, price) {
|
|
56
|
+
const { manifestUri } = await this.delegatorFangorn.publisher.upload({
|
|
58
57
|
records,
|
|
59
|
-
schemaName
|
|
60
|
-
gateway
|
|
58
|
+
schemaName
|
|
61
59
|
}, price);
|
|
62
|
-
return
|
|
60
|
+
return manifestUri;
|
|
63
61
|
}
|
|
64
62
|
async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
|
|
65
63
|
const walletClient = createWalletClient({
|
|
@@ -107,22 +105,14 @@ var TestBed = class TestBed {
|
|
|
107
105
|
nullifier
|
|
108
106
|
};
|
|
109
107
|
}
|
|
110
|
-
async
|
|
108
|
+
async fetchContent(owner, schemaId, name, field, nullifier, stealthPrivateKey) {
|
|
111
109
|
const walletClient = createWalletClient({
|
|
112
|
-
account: privateKeyToAccount(
|
|
110
|
+
account: privateKeyToAccount(stealthPrivateKey),
|
|
113
111
|
chain: arbitrumSepolia,
|
|
114
|
-
transport: http(
|
|
115
|
-
});
|
|
116
|
-
return this.delegateeFangorn.consumer.decrypt({
|
|
117
|
-
owner,
|
|
118
|
-
walletClient,
|
|
119
|
-
schemaId,
|
|
120
|
-
nullifierHash,
|
|
121
|
-
name,
|
|
122
|
-
field,
|
|
123
|
-
identity,
|
|
124
|
-
skipSettlementCheck: !requireSettlement
|
|
112
|
+
transport: http(process.env.RPC_URL ?? "")
|
|
125
113
|
});
|
|
114
|
+
const { data } = await this.delegateeFangorn.consumer.fetchField(owner, schemaId, name, field, nullifier, walletClient);
|
|
115
|
+
return data;
|
|
126
116
|
}
|
|
127
117
|
async checkManifestExists(who, schemaId, name) {
|
|
128
118
|
return await this.delegatorFangorn.consumer.getManifest(who, schemaId, name) !== void 0;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,50 +1,17 @@
|
|
|
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
|
-
interface AgentConfig {
|
|
33
|
-
privateKey: Hex;
|
|
34
|
-
pinataJwt: string;
|
|
35
|
-
registryOverrides?: Record<number, {
|
|
36
|
-
IDENTITY: string;
|
|
37
|
-
REPUTATION: string;
|
|
38
|
-
}>;
|
|
39
|
-
subgraphOverrides?: Record<number, string>;
|
|
40
|
-
}
|
|
41
10
|
interface FangornContext {
|
|
42
11
|
config: AppConfig;
|
|
43
12
|
walletClient: WalletClient;
|
|
44
|
-
|
|
45
|
-
encryption: EncryptionService;
|
|
13
|
+
metadataStorage: MetadataStorage | undefined;
|
|
46
14
|
domain: string;
|
|
47
|
-
ipfsGateway: string;
|
|
48
15
|
schemaRegistry: SchemaRegistry;
|
|
49
16
|
dataSourceRegistry: DataSourceRegistry;
|
|
50
17
|
settlementRegistry: SettlementRegistry;
|
|
@@ -56,17 +23,17 @@ type StorageConfig = {
|
|
|
56
23
|
gateway: string;
|
|
57
24
|
};
|
|
58
25
|
};
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
35
|
interface FangornCreateOptions {
|
|
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
36
|
storage?: StorageConfig;
|
|
68
|
-
encryption: EncryptionConfig;
|
|
69
|
-
ipfsGateway?: string;
|
|
70
37
|
config?: AppConfig;
|
|
71
38
|
domain?: string;
|
|
72
39
|
agentConfig?: AgentConfig;
|
|
@@ -74,4 +41,4 @@ interface FangornCreateOptions {
|
|
|
74
41
|
walletClient?: WalletClient;
|
|
75
42
|
}
|
|
76
43
|
//#endregion
|
|
77
|
-
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,20 +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
|
-
}
|
|
19
|
-
//#endregion
|
|
20
|
-
export { LitEncryptionService };
|
|
@@ -1,121 +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 = walletClient.account;
|
|
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
|
-
};
|
|
119
|
-
|
|
120
|
-
//#endregion
|
|
121
|
-
export { LitEncryptionService };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Gadget, GadgetDescriptor } from "./types.js";
|
|
2
|
-
import { Address, Hex } from "viem";
|
|
3
|
-
import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
|
|
4
|
-
|
|
5
|
-
//#region src/modules/gadgets/settledGadget.d.ts
|
|
6
|
-
interface SettledGadgetParams {
|
|
7
|
-
/** keccak256(owner, schemaId, tag) — derived at upload time */
|
|
8
|
-
resourceId: Hex;
|
|
9
|
-
/** SettlementRegistry contract address */
|
|
10
|
-
settlementRegistryAddress: Address;
|
|
11
|
-
/** "arbitrumSepolia" | "baseSepolia" */
|
|
12
|
-
chainName: string;
|
|
13
|
-
}
|
|
14
|
-
declare class SettledGadget implements Gadget {
|
|
15
|
-
private readonly params;
|
|
16
|
-
readonly type = "settled";
|
|
17
|
-
constructor(params: SettledGadgetParams);
|
|
18
|
-
hookAddress(): Address;
|
|
19
|
-
hookParams(): Hex;
|
|
20
|
-
toAccessCondition(): UnifiedAccessControlCondition[];
|
|
21
|
-
toDescriptor(): GadgetDescriptor;
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
|
-
export { SettledGadget, SettledGadgetParams };
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { zeroAddress } from "viem";
|
|
2
|
-
import { createAccBuilder } from "@lit-protocol/access-control-conditions";
|
|
3
|
-
|
|
4
|
-
//#region src/modules/gadgets/settledGadget.ts
|
|
5
|
-
var SettledGadget = class {
|
|
6
|
-
type = "settled";
|
|
7
|
-
constructor(params) {
|
|
8
|
-
this.params = params;
|
|
9
|
-
}
|
|
10
|
-
hookAddress() {
|
|
11
|
-
return zeroAddress;
|
|
12
|
-
}
|
|
13
|
-
hookParams() {
|
|
14
|
-
return "0x";
|
|
15
|
-
}
|
|
16
|
-
toAccessCondition() {
|
|
17
|
-
return createAccBuilder().custom({
|
|
18
|
-
conditionType: "evmContract",
|
|
19
|
-
contractAddress: this.params.settlementRegistryAddress,
|
|
20
|
-
chain: "arbitrumSepolia",
|
|
21
|
-
functionName: "isSettled",
|
|
22
|
-
functionParams: [":userAddress", this.params.resourceId],
|
|
23
|
-
functionAbi: {
|
|
24
|
-
name: "isSettled",
|
|
25
|
-
type: "function",
|
|
26
|
-
stateMutability: "view",
|
|
27
|
-
inputs: [{
|
|
28
|
-
name: "stealth_address",
|
|
29
|
-
type: "address"
|
|
30
|
-
}, {
|
|
31
|
-
name: "resource_id",
|
|
32
|
-
type: "bytes32"
|
|
33
|
-
}],
|
|
34
|
-
outputs: [{
|
|
35
|
-
name: "",
|
|
36
|
-
type: "bool"
|
|
37
|
-
}]
|
|
38
|
-
},
|
|
39
|
-
returnValueTest: {
|
|
40
|
-
key: "",
|
|
41
|
-
comparator: "=",
|
|
42
|
-
value: "true"
|
|
43
|
-
}
|
|
44
|
-
}).build();
|
|
45
|
-
}
|
|
46
|
-
toDescriptor() {
|
|
47
|
-
const acc = this.toAccessCondition();
|
|
48
|
-
return {
|
|
49
|
-
type: this.type,
|
|
50
|
-
description: "Settlement-gated: SettlementRegistry.isSettled(resourceId, caller)",
|
|
51
|
-
hookAddress: this.hookAddress(),
|
|
52
|
-
acc,
|
|
53
|
-
params: {
|
|
54
|
-
resourceId: this.params.resourceId,
|
|
55
|
-
settlementRegistryAddress: this.params.settlementRegistryAddress,
|
|
56
|
-
chainName: this.params.chainName
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
//#endregion
|
|
63
|
-
export { SettledGadget };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Address, Hex } from "viem";
|
|
2
|
-
import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
|
|
3
|
-
|
|
4
|
-
//#region src/modules/gadgets/types.d.ts
|
|
5
|
-
interface Gadget {
|
|
6
|
-
readonly type: string;
|
|
7
|
-
/** Hook contract called by SettlementRegistry during settle(). Zero address = no hook. */
|
|
8
|
-
hookAddress(): Address;
|
|
9
|
-
/** ABI-encoded params forwarded to the hook. "0x" = no params. */
|
|
10
|
-
hookParams(): Hex;
|
|
11
|
-
/** The ACC baked into the ciphertext at encryption time. Must match what the hook produces. */
|
|
12
|
-
toAccessCondition(): UnifiedAccessControlCondition[];
|
|
13
|
-
/** Stored in the manifest so consumers/agents know what they're buying. */
|
|
14
|
-
toDescriptor(): GadgetDescriptor;
|
|
15
|
-
}
|
|
16
|
-
interface GadgetDescriptor {
|
|
17
|
-
type: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
/** Hook contract address — zero address for SettledGadget */
|
|
20
|
-
hookAddress: Address;
|
|
21
|
-
/** The ACC stored alongside the ciphertext */
|
|
22
|
-
acc?: UnifiedAccessControlCondition[];
|
|
23
|
-
/** Human-readable params for display and agent consumption */
|
|
24
|
-
params?: Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
//#endregion
|
|
27
|
-
export { Gadget, GadgetDescriptor };
|
|
File without changes
|