@fangorn-network/sdk 2026.3.11 → 2026.3.28
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 +311 -198
- package/lib/builders/a2aCardBuilder.js +1 -0
- package/lib/cli/cli.d.ts +0 -0
- package/lib/cli/cli.js +399 -380
- package/lib/cli/index.d.ts +170 -170
- package/lib/cli/index.js +1 -4
- package/lib/config.d.ts +543 -163
- package/lib/config.js +11 -8
- package/lib/fangorn.d.ts +31 -43
- package/lib/fangorn.js +101 -117
- package/lib/index.d.ts +8 -5
- package/lib/index.js +8 -7
- package/lib/modules/encryption/index.d.ts +4 -3
- package/lib/modules/encryption/lit.d.ts +3 -18
- package/lib/modules/encryption/lit.js +20 -49
- package/lib/modules/encryption/rand.js +2 -2
- package/lib/modules/encryption/types.d.ts +23 -8
- package/lib/modules/gadgets/settledGadget.d.ts +31 -0
- package/lib/modules/gadgets/settledGadget.js +75 -0
- package/lib/modules/gadgets/types.d.ts +16 -4
- package/lib/providers/storage/index.d.ts +15 -4
- package/lib/providers/storage/pinata/index.d.ts +5 -4
- package/lib/providers/storage/pinata/index.js +17 -2
- package/lib/providers/storage/storacha/index.d.ts +13 -0
- package/lib/providers/storage/storacha/index.js +49 -0
- package/lib/providers/storage/storacha/readOnly.d.ts +8 -0
- package/lib/providers/storage/storacha/readOnly.js +16 -0
- package/lib/{interface → registries}/datasource-registry/abi.d.ts +29 -43
- package/lib/registries/datasource-registry/abi.js +16 -0
- package/lib/registries/datasource-registry/index.d.ts +24 -0
- package/lib/{interface/datasource-registry/dataSourceRegistry.js → registries/datasource-registry/index.js} +35 -34
- package/lib/registries/index.d.ts +3 -0
- package/lib/registries/index.js +4 -0
- package/lib/registries/schema-registry/abi.d.ts +127 -0
- package/lib/registries/schema-registry/abi.js +19 -0
- package/lib/registries/schema-registry/index.d.ts +29 -0
- package/lib/registries/schema-registry/index.js +114 -0
- package/lib/registries/settlement-registry/abi.d.ts +228 -0
- package/lib/registries/settlement-registry/abi.js +29 -0
- package/lib/registries/settlement-registry/index.d.ts +72 -0
- package/lib/registries/settlement-registry/index.js +316 -0
- package/lib/registries/settlement-registry/types.d.ts +51 -0
- package/lib/roles/consumer/index.d.ts +64 -0
- package/lib/roles/consumer/index.js +114 -0
- package/lib/roles/consumer/types.d.ts +66 -0
- package/lib/roles/index.js +1 -0
- package/lib/roles/publisher/index.d.ts +68 -0
- package/lib/roles/publisher/index.js +205 -0
- package/lib/roles/publisher/types.d.ts +93 -0
- package/lib/roles/publisher/types.js +1 -0
- package/lib/roles/schema/index.d.ts +44 -0
- package/lib/roles/schema/index.js +137 -0
- package/lib/roles/schema/types.d.ts +67 -0
- package/lib/roles/schema/types.js +1 -0
- package/lib/test/index.d.ts +5 -2
- package/lib/test/index.js +5 -3
- package/lib/test/testbed.d.ts +52 -32
- package/lib/test/testbed.js +138 -137
- package/lib/types/index.d.ts +65 -21
- package/lib/types/index.js +1 -12
- package/lib/utils/index.d.ts +2 -3
- package/lib/utils/index.js +4 -18
- package/package.json +85 -81
- package/lib/cli/registry.d.ts +0 -29
- package/lib/cli/registry.js +0 -53
- package/lib/deployContract.d.ts +0 -23
- package/lib/deployContract.js +0 -78
- package/lib/interface/datasource-registry/abi.js +0 -110
- package/lib/interface/datasource-registry/dataSourceRegistry.d.ts +0 -24
- package/lib/interface/index.d.ts +0 -3
- package/lib/interface/index.js +0 -4
- package/lib/interface/manifest.d.ts +0 -7
- package/lib/interface/manifest.js +0 -10
- package/lib/interface/settlement-tracker/abi.d.ts +0 -26
- package/lib/interface/settlement-tracker/abi.js +0 -88
- package/lib/interface/settlement-tracker/settlementTracker.d.ts +0 -32
- package/lib/interface/settlement-tracker/settlementTracker.js +0 -64
- package/lib/modules/gadgets/acc/gadgets.d.ts +0 -7
- package/lib/modules/gadgets/acc/gadgets.js +0 -10
- package/lib/modules/gadgets/acc.d.ts +0 -15
- package/lib/modules/gadgets/acc.js +0 -24
- package/lib/modules/gadgets/builder.d.ts +0 -1
- package/lib/modules/gadgets/payment.d.ts +0 -23
- package/lib/modules/gadgets/payment.js +0 -88
- package/lib/test/test-gadget.d.ts +0 -7
- package/lib/test/test-gadget.js +0 -10
- /package/lib/{modules/gadgets/builder.js → registries/settlement-registry/types.js} +0 -0
- /package/lib/{providers/storage/s3/index.js → roles/consumer/types.js} +0 -0
- /package/lib/{providers/storage/s3 → roles}/index.d.ts +0 -0
package/lib/test/testbed.d.ts
CHANGED
|
@@ -1,43 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import { RegisterAgentParams, RegisteredAgent, SchemaDefinition } from "../roles/schema/types.js";
|
|
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
|
+
import { PublishRecord } from "../roles/publisher/types.js";
|
|
6
|
+
import "../roles/publisher/index.js";
|
|
4
7
|
import { Fangorn } from "../fangorn.js";
|
|
5
8
|
import { Address, Hex, WalletClient } from "viem";
|
|
6
|
-
import {
|
|
9
|
+
import { Identity } from "@semaphore-protocol/identity";
|
|
7
10
|
|
|
8
11
|
//#region src/test/testbed.d.ts
|
|
9
12
|
declare class TestBed {
|
|
10
|
-
private
|
|
11
|
-
private
|
|
12
|
-
private
|
|
13
|
-
private
|
|
14
|
-
private
|
|
15
|
-
private
|
|
16
|
-
private config;
|
|
17
|
-
private litChain;
|
|
18
|
-
constructor(delegatorAddress: Address, delegatorFangorn: Fangorn, delegateeFangorn: Fangorn, storage: PinataStorage, config: AppConfig, litChain: EvmChain, usdcContractAddress: Address);
|
|
19
|
-
static init(delegatorWalletClient: WalletClient, delegateeWalletClient: WalletClient, jwt: string, gateway: string, dataSourceRegistryContractAddress: Hex, usdcContractAddress: Hex, rpcUrl: string, chain: string, litChain: EvmChain, caip2: number): Promise<TestBed>;
|
|
20
|
-
registerDatasource(name: string): Promise<Hex>;
|
|
13
|
+
private readonly delegatorAddress;
|
|
14
|
+
private readonly delegatorFangorn;
|
|
15
|
+
private readonly delegateeFangorn;
|
|
16
|
+
private readonly usdcContractAddress;
|
|
17
|
+
private readonly usdcDomainName;
|
|
18
|
+
private constructor();
|
|
21
19
|
/**
|
|
22
|
-
*
|
|
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
|
|
23
35
|
*/
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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>;
|
|
38
|
+
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[], schema: SchemaDefinition, schemaId: Hex, gateway: string, price: bigint): Promise<string>;
|
|
47
|
+
prepareRegister(burnerPrivateKey: Hex, paymentRecipient: Address, amount: bigint): Promise<TransferWithAuthPayload>;
|
|
48
|
+
register(owner: Address, schemaId: Hex, tag: string, identityCommitment: bigint, relayerPrivateKey: Hex, preparedRegister: TransferWithAuthPayload): Promise<Hex>;
|
|
49
|
+
prepareSettle(owner: Address, schemaId: Hex, tag: string, identity: Identity, stealthAddress: Address): Promise<PrepareSettleResult>;
|
|
50
|
+
settle(owner: Address, schemaId: Hex, tag: string, relayerPrivateKey: Hex, preparedSettle: PrepareSettleResult): Promise<{
|
|
51
|
+
txHash: Hex;
|
|
52
|
+
nullifier: bigint;
|
|
38
53
|
}>;
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
tryDecrypt(owner: Address, nullifierHash: bigint, stealthSecretKey: Hex, schemaId: Hex, tag: string, field: string, rpcUrl: string, identity?: Identity, requireSettlement?: boolean): Promise<Uint8Array>;
|
|
55
|
+
checkManifestExists(who: Address, schemaId: Hex): Promise<boolean>;
|
|
56
|
+
checkEntryExists(who: Address, schemaId: Hex, tag: string): Promise<boolean>;
|
|
57
|
+
getDelegatorAddress(): Address;
|
|
58
|
+
getDelegatorFangorn(): Fangorn;
|
|
59
|
+
getDelegateeFangorn(): Fangorn;
|
|
60
|
+
getSettlementRegistry(): SettlementRegistry;
|
|
41
61
|
}
|
|
42
62
|
//#endregion
|
|
43
63
|
export { TestBed };
|
package/lib/test/testbed.js
CHANGED
|
@@ -1,172 +1,173 @@
|
|
|
1
|
+
import { SettlementRegistry } from "../registries/settlement-registry/index.js";
|
|
1
2
|
import { Fangorn } from "../fangorn.js";
|
|
2
|
-
import { PinataStorage } from "../providers/storage/pinata/index.js";
|
|
3
|
-
import { computeTagCommitment, fieldToHex } from "../utils/index.js";
|
|
4
|
-
import { LitEncryptionService } from "../modules/encryption/lit.js";
|
|
5
|
-
import { PaymentGadget } from "../modules/gadgets/payment.js";
|
|
6
|
-
import { emptyWallet } from "./test-gadget.js";
|
|
7
|
-
import { SettlementTracker } from "../interface/settlement-tracker/settlementTracker.js";
|
|
8
3
|
import { arbitrumSepolia, baseSepolia } from "viem/chains";
|
|
9
|
-
import {
|
|
4
|
+
import { createWalletClient, http } from "viem";
|
|
5
|
+
import { privateKeyToAccount } from "viem/accounts";
|
|
10
6
|
|
|
11
7
|
//#region src/test/testbed.ts
|
|
12
8
|
var TestBed = class TestBed {
|
|
13
|
-
delegatorFangorn
|
|
14
|
-
delegateeFangorn;
|
|
15
|
-
delegatorAddress;
|
|
16
|
-
storage;
|
|
17
|
-
usdcContractAddress;
|
|
18
|
-
vaultIds;
|
|
19
|
-
config;
|
|
20
|
-
litChain;
|
|
21
|
-
constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, storage, config, litChain, usdcContractAddress) {
|
|
9
|
+
constructor(delegatorAddress, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName) {
|
|
22
10
|
this.delegatorAddress = delegatorAddress;
|
|
23
11
|
this.delegatorFangorn = delegatorFangorn;
|
|
24
12
|
this.delegateeFangorn = delegateeFangorn;
|
|
25
|
-
this.vaultIds = /* @__PURE__ */ new Map();
|
|
26
|
-
this.config = config;
|
|
27
|
-
this.litChain = litChain;
|
|
28
|
-
this.storage = storage;
|
|
29
13
|
this.usdcContractAddress = usdcContractAddress;
|
|
14
|
+
this.usdcDomainName = usdcDomainName;
|
|
30
15
|
}
|
|
31
|
-
|
|
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) {
|
|
32
34
|
let chainImpl = arbitrumSepolia;
|
|
33
35
|
if (chain === "baseSepolia") chainImpl = baseSepolia;
|
|
34
36
|
const config = {
|
|
35
37
|
dataSourceRegistryContractAddress,
|
|
38
|
+
schemaRegistryContractAddress,
|
|
39
|
+
settlementRegistryContractAddress,
|
|
36
40
|
chainName: chain,
|
|
37
41
|
chain: chainImpl,
|
|
38
42
|
rpcUrl,
|
|
39
43
|
caip2
|
|
40
44
|
};
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
45
|
+
const agentConfig = void 0;
|
|
46
|
+
const delegatorFangorn = await Fangorn.create({
|
|
47
|
+
privateKey: process.env.DELEGATOR_ETH_PRIVATE_KEY ?? "0x0",
|
|
48
|
+
storage: { storacha: { "email": process.env.TEST_EMAIL_ADDR ?? "" } },
|
|
49
|
+
encryption: { lit: true },
|
|
50
|
+
config,
|
|
51
|
+
domain: "localhost",
|
|
52
|
+
agentConfig
|
|
53
|
+
});
|
|
54
|
+
const delegateeFangorn = await Fangorn.create({
|
|
55
|
+
privateKey: process.env.DELEGATEE_ETH_PRIVATE_KEY ?? "0x0",
|
|
56
|
+
storage: { storacha: { "readOnly": true } },
|
|
57
|
+
encryption: { lit: true },
|
|
58
|
+
config,
|
|
59
|
+
domain: "localhost"
|
|
60
|
+
});
|
|
61
|
+
if (!delegatorWalletClient.account) throw new Error("Delegator account not found");
|
|
62
|
+
return new TestBed(delegatorWalletClient.account.address, delegatorFangorn, delegateeFangorn, usdcContractAddress, usdcDomainName);
|
|
56
63
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
async
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return new PaymentGadget({
|
|
66
|
-
commitment: fieldToHex(await computeTagCommitment(this.delegatorAddress, datasourceName, file.tag, usdcPrice)),
|
|
67
|
-
chainName: this.config.chainName,
|
|
68
|
-
settlementTrackerContractAddress,
|
|
69
|
-
usdcPrice,
|
|
70
|
-
pinataJwt: jwt
|
|
71
|
-
});
|
|
64
|
+
async registerAgent(params) {
|
|
65
|
+
return this.delegatorFangorn.schema.registerAgent(params);
|
|
66
|
+
}
|
|
67
|
+
async registerSchema(name, definition, agentId) {
|
|
68
|
+
const { schemaId } = await this.delegatorFangorn.schema.register({
|
|
69
|
+
name,
|
|
70
|
+
definition,
|
|
71
|
+
agentId
|
|
72
72
|
});
|
|
73
|
+
return schemaId;
|
|
73
74
|
}
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
/**
|
|
76
|
+
* Upload files encrypted under SettledGadget.
|
|
77
|
+
*
|
|
78
|
+
* Each file gets its own resourceId derived from (owner, schemaId, file.tag),
|
|
79
|
+
* which is baked into the ACC at encryption time. A buyer must complete the
|
|
80
|
+
* full purchase → claim flow for each specific tag before decrypting.
|
|
81
|
+
*/
|
|
82
|
+
async fileUpload(records, schema, schemaId, gateway, price) {
|
|
83
|
+
const { manifestCid } = await this.delegatorFangorn.publisher.upload({
|
|
84
|
+
records,
|
|
85
|
+
schema,
|
|
86
|
+
schemaId,
|
|
87
|
+
gateway
|
|
88
|
+
}, price);
|
|
89
|
+
return manifestCid;
|
|
76
90
|
}
|
|
77
|
-
async
|
|
78
|
-
return
|
|
91
|
+
async prepareRegister(burnerPrivateKey, paymentRecipient, amount) {
|
|
92
|
+
return this.delegateeFangorn.consumer.prepareRegister({
|
|
93
|
+
burnerPrivateKey,
|
|
94
|
+
paymentRecipient,
|
|
95
|
+
amount,
|
|
96
|
+
usdcAddress: this.usdcContractAddress,
|
|
97
|
+
usdcDomainName: this.usdcDomainName,
|
|
98
|
+
usdcDomainVersion: "2"
|
|
99
|
+
});
|
|
79
100
|
}
|
|
80
|
-
async
|
|
81
|
-
const
|
|
82
|
-
|
|
101
|
+
async register(owner, schemaId, tag, identityCommitment, relayerPrivateKey, preparedRegister) {
|
|
102
|
+
const { txHash } = await this.delegateeFangorn.consumer.register({
|
|
103
|
+
owner,
|
|
104
|
+
schemaId,
|
|
105
|
+
tag,
|
|
106
|
+
identityCommitment,
|
|
107
|
+
relayerPrivateKey,
|
|
108
|
+
preparedRegister
|
|
109
|
+
});
|
|
110
|
+
return txHash;
|
|
83
111
|
}
|
|
84
|
-
async
|
|
85
|
-
|
|
112
|
+
async prepareSettle(owner, schemaId, tag, identity, stealthAddress) {
|
|
113
|
+
return this.delegateeFangorn.consumer.prepareSettle({
|
|
114
|
+
resourceId: SettlementRegistry.deriveResourceId(owner, schemaId, tag),
|
|
115
|
+
identity,
|
|
116
|
+
stealthAddress
|
|
117
|
+
});
|
|
86
118
|
}
|
|
87
|
-
async
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
verifyingContract: usdcAddress
|
|
95
|
-
};
|
|
96
|
-
const types = { TransferWithAuthorization: [
|
|
97
|
-
{
|
|
98
|
-
name: "from",
|
|
99
|
-
type: "address"
|
|
100
|
-
},
|
|
101
|
-
{
|
|
102
|
-
name: "to",
|
|
103
|
-
type: "address"
|
|
104
|
-
},
|
|
105
|
-
{
|
|
106
|
-
name: "value",
|
|
107
|
-
type: "uint256"
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "validAfter",
|
|
111
|
-
type: "uint256"
|
|
112
|
-
},
|
|
113
|
-
{
|
|
114
|
-
name: "validBefore",
|
|
115
|
-
type: "uint256"
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: "nonce",
|
|
119
|
-
type: "bytes32"
|
|
120
|
-
}
|
|
121
|
-
] };
|
|
122
|
-
const value = parseUnits(amount, 6);
|
|
123
|
-
const nonce = keccak256(toHex(crypto.getRandomValues(new Uint8Array(32))));
|
|
124
|
-
const signature = await walletClient.signTypedData({
|
|
125
|
-
account,
|
|
126
|
-
domain,
|
|
127
|
-
types,
|
|
128
|
-
primaryType: "TransferWithAuthorization",
|
|
129
|
-
message: {
|
|
130
|
-
from: account.address,
|
|
131
|
-
to: recipient,
|
|
132
|
-
value,
|
|
133
|
-
validAfter: 0n,
|
|
134
|
-
validBefore: 281474976710655n,
|
|
135
|
-
nonce
|
|
136
|
-
}
|
|
119
|
+
async settle(owner, schemaId, tag, relayerPrivateKey, preparedSettle) {
|
|
120
|
+
const { txHash, nullifier } = await this.delegateeFangorn.consumer.claim({
|
|
121
|
+
owner,
|
|
122
|
+
schemaId,
|
|
123
|
+
tag,
|
|
124
|
+
relayerPrivateKey,
|
|
125
|
+
preparedSettle
|
|
137
126
|
});
|
|
138
127
|
return {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
amount: value,
|
|
142
|
-
validAfter: 0n,
|
|
143
|
-
validBefore: 281474976710655n,
|
|
144
|
-
nonce,
|
|
145
|
-
signature
|
|
128
|
+
txHash,
|
|
129
|
+
nullifier
|
|
146
130
|
};
|
|
147
131
|
}
|
|
148
|
-
async
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
132
|
+
async tryDecrypt(owner, nullifierHash, stealthSecretKey, schemaId, tag, field, rpcUrl, identity, requireSettlement = true) {
|
|
133
|
+
const walletClient = createWalletClient({
|
|
134
|
+
account: privateKeyToAccount(stealthSecretKey),
|
|
135
|
+
chain: arbitrumSepolia,
|
|
136
|
+
transport: http(rpcUrl)
|
|
137
|
+
});
|
|
138
|
+
return this.delegateeFangorn.consumer.decrypt({
|
|
139
|
+
owner,
|
|
140
|
+
walletClient,
|
|
141
|
+
schemaId,
|
|
142
|
+
nullifierHash,
|
|
143
|
+
tag,
|
|
144
|
+
field,
|
|
145
|
+
identity,
|
|
146
|
+
skipSettlementCheck: !requireSettlement
|
|
160
147
|
});
|
|
161
148
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
149
|
+
async checkManifestExists(who, schemaId) {
|
|
150
|
+
return await this.delegatorFangorn.consumer.getManifest(who, schemaId) !== void 0;
|
|
151
|
+
}
|
|
152
|
+
async checkEntryExists(who, schemaId, tag) {
|
|
153
|
+
try {
|
|
154
|
+
await this.delegatorFangorn.consumer.getEntry(who, schemaId, tag);
|
|
155
|
+
return true;
|
|
156
|
+
} catch {
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
getDelegatorAddress() {
|
|
161
|
+
return this.delegatorAddress;
|
|
162
|
+
}
|
|
163
|
+
getDelegatorFangorn() {
|
|
164
|
+
return this.delegatorFangorn;
|
|
165
|
+
}
|
|
166
|
+
getDelegateeFangorn() {
|
|
167
|
+
return this.delegateeFangorn;
|
|
168
|
+
}
|
|
169
|
+
getSettlementRegistry() {
|
|
170
|
+
return this.delegatorFangorn.getSettlementRegistry();
|
|
170
171
|
}
|
|
171
172
|
};
|
|
172
173
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,25 +1,15 @@
|
|
|
1
|
+
import { AppConfig } from "../config.js";
|
|
2
|
+
import { SchemaRegistry } from "../registries/schema-registry/index.js";
|
|
3
|
+
import { ReadableStorage, WritableStorage } from "../providers/storage/index.js";
|
|
4
|
+
import { SchemaRoleConfig } from "../roles/schema/types.js";
|
|
5
|
+
import "../roles/schema/index.js";
|
|
6
|
+
import { DataSourceRegistry } from "../registries/datasource-registry/index.js";
|
|
1
7
|
import { GadgetDescriptor } from "../modules/gadgets/types.js";
|
|
8
|
+
import { SettlementRegistry } from "../registries/settlement-registry/index.js";
|
|
9
|
+
import { EncryptionService } from "../modules/encryption/index.js";
|
|
10
|
+
import { Hex, WalletClient } from "viem";
|
|
2
11
|
|
|
3
12
|
//#region src/types/index.d.ts
|
|
4
|
-
interface VaultEntry {
|
|
5
|
-
tag: string;
|
|
6
|
-
cid: string;
|
|
7
|
-
index: number;
|
|
8
|
-
gadgetDescriptor: GadgetDescriptor;
|
|
9
|
-
extension: string;
|
|
10
|
-
fileType: string;
|
|
11
|
-
}
|
|
12
|
-
interface VaultManifest {
|
|
13
|
-
version: number;
|
|
14
|
-
entries: VaultEntry[];
|
|
15
|
-
tree?: string[][];
|
|
16
|
-
}
|
|
17
|
-
interface BuildManifestOptions {
|
|
18
|
-
root: string;
|
|
19
|
-
entries: VaultEntry[];
|
|
20
|
-
tree?: string[][];
|
|
21
|
-
}
|
|
22
|
-
declare const buildManifest: (options: BuildManifestOptions) => VaultManifest;
|
|
23
13
|
interface PendingEntry {
|
|
24
14
|
tag: string;
|
|
25
15
|
cid: string;
|
|
@@ -29,7 +19,7 @@ interface PendingEntry {
|
|
|
29
19
|
}
|
|
30
20
|
interface Filedata {
|
|
31
21
|
tag: string;
|
|
32
|
-
data:
|
|
22
|
+
data: Uint8Array;
|
|
33
23
|
extension: string;
|
|
34
24
|
fileType: string;
|
|
35
25
|
}
|
|
@@ -39,5 +29,59 @@ interface EncryptedData {
|
|
|
39
29
|
authTag: Uint8Array<ArrayBuffer>;
|
|
40
30
|
salt: Uint8Array<ArrayBuffer>;
|
|
41
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
|
+
interface FangornContext {
|
|
50
|
+
config: AppConfig;
|
|
51
|
+
walletClient: WalletClient;
|
|
52
|
+
storage: ReadableStorage<unknown> | WritableStorage<unknown>;
|
|
53
|
+
encryption: EncryptionService;
|
|
54
|
+
domain: string;
|
|
55
|
+
schemaRegistry: SchemaRegistry;
|
|
56
|
+
dataSourceRegistry: DataSourceRegistry;
|
|
57
|
+
settlementRegistry: SettlementRegistry;
|
|
58
|
+
schemaRoleConfig: SchemaRoleConfig | undefined;
|
|
59
|
+
}
|
|
60
|
+
type StorageConfig = {
|
|
61
|
+
pinata: {
|
|
62
|
+
jwt: string;
|
|
63
|
+
gateway: string;
|
|
64
|
+
};
|
|
65
|
+
} | {
|
|
66
|
+
storacha: {
|
|
67
|
+
email: string;
|
|
68
|
+
};
|
|
69
|
+
} | {
|
|
70
|
+
storacha: {
|
|
71
|
+
readOnly: true;
|
|
72
|
+
};
|
|
73
|
+
} | ReadableStorage<unknown>;
|
|
74
|
+
type EncryptionConfig = {
|
|
75
|
+
lit: true;
|
|
76
|
+
} | EncryptionService;
|
|
77
|
+
interface FangornCreateOptions {
|
|
78
|
+
storage: StorageConfig;
|
|
79
|
+
encryption: EncryptionConfig;
|
|
80
|
+
config?: AppConfig;
|
|
81
|
+
domain?: string;
|
|
82
|
+
agentConfig?: AgentConfig;
|
|
83
|
+
privateKey?: Hex;
|
|
84
|
+
walletClient?: WalletClient;
|
|
85
|
+
}
|
|
42
86
|
//#endregion
|
|
43
|
-
export { EncryptedData,
|
|
87
|
+
export { AgentConfig, EncryptedData, EncryptionConfig, FangornContext, FangornCreateOptions, Filedata, PendingEntry, StorageConfig };
|
package/lib/types/index.js
CHANGED
package/lib/utils/index.d.ts
CHANGED
|
@@ -6,7 +6,6 @@ declare function hexToBytes32Array(hex: `0x${string}`): number[];
|
|
|
6
6
|
declare function addressToBytes32Array(address: Address): number[];
|
|
7
7
|
declare function fieldToHex(field: bigint): `0x${string}`;
|
|
8
8
|
declare function hexToField(hex: string): bigint;
|
|
9
|
-
declare function
|
|
10
|
-
declare function computeTagCommitment(owner: Address, name: string, tag: string, price: string): bigint;
|
|
9
|
+
declare function computeSchemaId(name: string): Hex;
|
|
11
10
|
//#endregion
|
|
12
|
-
export { addressToBytes32Array,
|
|
11
|
+
export { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
|
package/lib/utils/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { encodeAbiParameters,
|
|
1
|
+
import { encodeAbiParameters, keccak256, parseAbiParameters } from "viem";
|
|
2
2
|
|
|
3
3
|
//#region src/utils/index.ts
|
|
4
4
|
function stringToBytes32Array(str) {
|
|
@@ -21,23 +21,9 @@ function hexToField(hex) {
|
|
|
21
21
|
const cleanHex = hex.startsWith("0x") ? hex : `0x${hex}`;
|
|
22
22
|
return BigInt(cleanHex);
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
return keccak256(encodeAbiParameters(parseAbiParameters("string
|
|
26
|
-
}
|
|
27
|
-
function computeTagCommitment(owner, name, tag, price) {
|
|
28
|
-
const hash = keccak256(encodePacked([
|
|
29
|
-
"bytes32",
|
|
30
|
-
"string",
|
|
31
|
-
"string",
|
|
32
|
-
"string"
|
|
33
|
-
], [
|
|
34
|
-
deriveDatasourceId(name, owner),
|
|
35
|
-
name,
|
|
36
|
-
tag,
|
|
37
|
-
price
|
|
38
|
-
]));
|
|
39
|
-
return BigInt(hash);
|
|
24
|
+
function computeSchemaId(name) {
|
|
25
|
+
return keccak256(encodeAbiParameters(parseAbiParameters("string"), [name]));
|
|
40
26
|
}
|
|
41
27
|
|
|
42
28
|
//#endregion
|
|
43
|
-
export { addressToBytes32Array,
|
|
29
|
+
export { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
|