@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.
Files changed (89) hide show
  1. package/README.md +311 -198
  2. package/lib/builders/a2aCardBuilder.js +1 -0
  3. package/lib/cli/cli.d.ts +0 -0
  4. package/lib/cli/cli.js +399 -380
  5. package/lib/cli/index.d.ts +170 -170
  6. package/lib/cli/index.js +1 -4
  7. package/lib/config.d.ts +543 -163
  8. package/lib/config.js +11 -8
  9. package/lib/fangorn.d.ts +31 -43
  10. package/lib/fangorn.js +101 -117
  11. package/lib/index.d.ts +8 -5
  12. package/lib/index.js +8 -7
  13. package/lib/modules/encryption/index.d.ts +4 -3
  14. package/lib/modules/encryption/lit.d.ts +3 -18
  15. package/lib/modules/encryption/lit.js +20 -49
  16. package/lib/modules/encryption/rand.js +2 -2
  17. package/lib/modules/encryption/types.d.ts +23 -8
  18. package/lib/modules/gadgets/settledGadget.d.ts +31 -0
  19. package/lib/modules/gadgets/settledGadget.js +75 -0
  20. package/lib/modules/gadgets/types.d.ts +16 -4
  21. package/lib/providers/storage/index.d.ts +15 -4
  22. package/lib/providers/storage/pinata/index.d.ts +5 -4
  23. package/lib/providers/storage/pinata/index.js +17 -2
  24. package/lib/providers/storage/storacha/index.d.ts +13 -0
  25. package/lib/providers/storage/storacha/index.js +49 -0
  26. package/lib/providers/storage/storacha/readOnly.d.ts +8 -0
  27. package/lib/providers/storage/storacha/readOnly.js +16 -0
  28. package/lib/{interface → registries}/datasource-registry/abi.d.ts +29 -43
  29. package/lib/registries/datasource-registry/abi.js +16 -0
  30. package/lib/registries/datasource-registry/index.d.ts +24 -0
  31. package/lib/{interface/datasource-registry/dataSourceRegistry.js → registries/datasource-registry/index.js} +35 -34
  32. package/lib/registries/index.d.ts +3 -0
  33. package/lib/registries/index.js +4 -0
  34. package/lib/registries/schema-registry/abi.d.ts +127 -0
  35. package/lib/registries/schema-registry/abi.js +19 -0
  36. package/lib/registries/schema-registry/index.d.ts +29 -0
  37. package/lib/registries/schema-registry/index.js +114 -0
  38. package/lib/registries/settlement-registry/abi.d.ts +228 -0
  39. package/lib/registries/settlement-registry/abi.js +29 -0
  40. package/lib/registries/settlement-registry/index.d.ts +72 -0
  41. package/lib/registries/settlement-registry/index.js +316 -0
  42. package/lib/registries/settlement-registry/types.d.ts +51 -0
  43. package/lib/roles/consumer/index.d.ts +64 -0
  44. package/lib/roles/consumer/index.js +114 -0
  45. package/lib/roles/consumer/types.d.ts +66 -0
  46. package/lib/roles/index.js +1 -0
  47. package/lib/roles/publisher/index.d.ts +68 -0
  48. package/lib/roles/publisher/index.js +205 -0
  49. package/lib/roles/publisher/types.d.ts +93 -0
  50. package/lib/roles/publisher/types.js +1 -0
  51. package/lib/roles/schema/index.d.ts +44 -0
  52. package/lib/roles/schema/index.js +137 -0
  53. package/lib/roles/schema/types.d.ts +67 -0
  54. package/lib/roles/schema/types.js +1 -0
  55. package/lib/test/index.d.ts +5 -2
  56. package/lib/test/index.js +5 -3
  57. package/lib/test/testbed.d.ts +52 -32
  58. package/lib/test/testbed.js +138 -137
  59. package/lib/types/index.d.ts +65 -21
  60. package/lib/types/index.js +1 -12
  61. package/lib/utils/index.d.ts +2 -3
  62. package/lib/utils/index.js +4 -18
  63. package/package.json +85 -81
  64. package/lib/cli/registry.d.ts +0 -29
  65. package/lib/cli/registry.js +0 -53
  66. package/lib/deployContract.d.ts +0 -23
  67. package/lib/deployContract.js +0 -78
  68. package/lib/interface/datasource-registry/abi.js +0 -110
  69. package/lib/interface/datasource-registry/dataSourceRegistry.d.ts +0 -24
  70. package/lib/interface/index.d.ts +0 -3
  71. package/lib/interface/index.js +0 -4
  72. package/lib/interface/manifest.d.ts +0 -7
  73. package/lib/interface/manifest.js +0 -10
  74. package/lib/interface/settlement-tracker/abi.d.ts +0 -26
  75. package/lib/interface/settlement-tracker/abi.js +0 -88
  76. package/lib/interface/settlement-tracker/settlementTracker.d.ts +0 -32
  77. package/lib/interface/settlement-tracker/settlementTracker.js +0 -64
  78. package/lib/modules/gadgets/acc/gadgets.d.ts +0 -7
  79. package/lib/modules/gadgets/acc/gadgets.js +0 -10
  80. package/lib/modules/gadgets/acc.d.ts +0 -15
  81. package/lib/modules/gadgets/acc.js +0 -24
  82. package/lib/modules/gadgets/builder.d.ts +0 -1
  83. package/lib/modules/gadgets/payment.d.ts +0 -23
  84. package/lib/modules/gadgets/payment.js +0 -88
  85. package/lib/test/test-gadget.d.ts +0 -7
  86. package/lib/test/test-gadget.js +0 -10
  87. /package/lib/{modules/gadgets/builder.js → registries/settlement-registry/types.js} +0 -0
  88. /package/lib/{providers/storage/s3/index.js → roles/consumer/types.js} +0 -0
  89. /package/lib/{providers/storage/s3 → roles}/index.d.ts +0 -0
@@ -1,4 +1,8 @@
1
+ import { createAuthManager } from "@lit-protocol/auth";
2
+ import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
3
+
1
4
  //#region src/modules/encryption/types.d.ts
5
+ type EoaAuthContext = Awaited<ReturnType<ReturnType<typeof createAuthManager>["createEoaAuthContext"]>>;
2
6
  interface AesEncryptedData {
3
7
  ciphertext: Uint8Array<ArrayBuffer>;
4
8
  iv: Uint8Array<ArrayBuffer>;
@@ -9,14 +13,24 @@ interface LitEncryptedData {
9
13
  ciphertext: string;
10
14
  dataToEncryptHash: string;
11
15
  }
12
- /**
13
- * Complete encrypted payload - stored to IPFS
14
- */
15
16
  interface EncryptedPayload {
17
+ /** Locally AES-encrypted file bytes */
16
18
  data: AesEncryptedData;
17
- key: LitEncryptedData;
18
- acc: AccessControlCondition;
19
- litAction: string;
19
+ /** Lit-threshold-encrypted AES key */
20
+ key: {
21
+ ciphertext: string;
22
+ dataToEncryptHash: string;
23
+ };
24
+ /**
25
+ * The ACC used to encrypt the key — stored here so decrypt() can
26
+ * reconstruct the exact conditions without re-deriving them from
27
+ * the gadget. The gadget is a publisher-time concept; the consumer
28
+ * only has the payload.
29
+ */
30
+ acc: UnifiedAccessControlCondition[];
31
+ }
32
+ interface DecryptedPayload {
33
+ data: Uint8Array;
20
34
  }
21
35
  /**
22
36
  * Lit's access control condition structure
@@ -37,8 +51,9 @@ interface AuthSig {
37
51
  */
38
52
  interface AuthContextWrapper {
39
53
  authSig: AuthSig;
40
- sessionContext: any;
54
+ sessionContext: EoaAuthContext;
41
55
  chainName: string;
56
+ nullifierHash?: string;
42
57
  }
43
58
  /**
44
59
  * Result of successful decryption
@@ -52,4 +67,4 @@ interface DecryptedPayload {
52
67
  };
53
68
  }
54
69
  //#endregion
55
- export { AccessControlCondition, AesEncryptedData, AuthContextWrapper, AuthSig, DecryptedPayload, EncryptedPayload, LitEncryptedData };
70
+ export { AccessControlCondition, AesEncryptedData, AuthContextWrapper, AuthSig, DecryptedPayload, EncryptedPayload, EoaAuthContext, LitEncryptedData };
@@ -0,0 +1,31 @@
1
+ import { AppConfig } from "../../config.js";
2
+ import { Gadget, GadgetDescriptor } from "./types.js";
3
+ import { Address, Hex } from "viem";
4
+ import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
5
+
6
+ //#region src/modules/gadgets/settledGadget.d.ts
7
+ interface SettledGadgetParams {
8
+ /** keccak256(owner, schemaId, tag) — derived at upload time */
9
+ resourceId: Hex;
10
+ /** SettlementRegistry contract address */
11
+ settlementRegistryAddress: Address;
12
+ /** "arbitrumSepolia" | "baseSepolia" */
13
+ chainName: string;
14
+ }
15
+ /**
16
+ * Build a new default gadget from the given config
17
+ * @param config : AppConfig
18
+ * @returns the configured gadget
19
+ */
20
+ declare function makeSettledGadgetFactory(config: AppConfig): (resourceId: Hex) => SettledGadget;
21
+ declare class SettledGadget implements Gadget {
22
+ private readonly params;
23
+ readonly type = "settled";
24
+ constructor(params: SettledGadgetParams);
25
+ hookAddress(): Address;
26
+ hookParams(): Hex;
27
+ toAccessCondition(): UnifiedAccessControlCondition[];
28
+ toDescriptor(): GadgetDescriptor;
29
+ }
30
+ //#endregion
31
+ export { SettledGadget, SettledGadgetParams, makeSettledGadgetFactory };
@@ -0,0 +1,75 @@
1
+ import { zeroAddress } from "viem";
2
+ import { createAccBuilder } from "@lit-protocol/access-control-conditions";
3
+
4
+ //#region src/modules/gadgets/settledGadget.ts
5
+ /**
6
+ * Build a new default gadget from the given config
7
+ * @param config : AppConfig
8
+ * @returns the configured gadget
9
+ */
10
+ function makeSettledGadgetFactory(config) {
11
+ return (resourceId) => new SettledGadget({
12
+ resourceId,
13
+ settlementRegistryAddress: config.settlementRegistryContractAddress,
14
+ chainName: config.chainName
15
+ });
16
+ }
17
+ var SettledGadget = class {
18
+ type = "settled";
19
+ constructor(params) {
20
+ this.params = params;
21
+ }
22
+ hookAddress() {
23
+ return zeroAddress;
24
+ }
25
+ hookParams() {
26
+ return "0x";
27
+ }
28
+ toAccessCondition() {
29
+ return createAccBuilder().custom({
30
+ conditionType: "evmContract",
31
+ contractAddress: this.params.settlementRegistryAddress,
32
+ chain: "arbitrumSepolia",
33
+ functionName: "isSettled",
34
+ functionParams: [":userAddress", this.params.resourceId],
35
+ functionAbi: {
36
+ name: "isSettled",
37
+ type: "function",
38
+ stateMutability: "view",
39
+ inputs: [{
40
+ name: "stealth_address",
41
+ type: "address"
42
+ }, {
43
+ name: "resource_id",
44
+ type: "bytes32"
45
+ }],
46
+ outputs: [{
47
+ name: "",
48
+ type: "bool"
49
+ }]
50
+ },
51
+ returnValueTest: {
52
+ key: "",
53
+ comparator: "=",
54
+ value: "true"
55
+ }
56
+ }).build();
57
+ }
58
+ toDescriptor() {
59
+ const acc = this.toAccessCondition();
60
+ return {
61
+ type: this.type,
62
+ description: "Settlement-gated: SettlementRegistry.isSettled(resourceId, caller)",
63
+ hookAddress: this.hookAddress(),
64
+ acc,
65
+ params: {
66
+ resourceId: this.params.resourceId,
67
+ settlementRegistryAddress: this.params.settlementRegistryAddress,
68
+ chainName: this.params.chainName
69
+ }
70
+ };
71
+ }
72
+ };
73
+
74
+ //#endregion
75
+ export { SettledGadget, makeSettledGadgetFactory };
@@ -1,14 +1,26 @@
1
+ import { Address, Hex } from "viem";
2
+ import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
3
+
1
4
  //#region src/modules/gadgets/types.d.ts
2
5
  interface Gadget {
3
- type: string;
4
- toLitAction(): string;
5
- toAccessCondition(): any;
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. */
6
14
  toDescriptor(): GadgetDescriptor;
7
15
  }
8
16
  interface GadgetDescriptor {
9
17
  type: string;
10
18
  description?: string;
11
- acc?: any;
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 */
12
24
  params?: Record<string, unknown>;
13
25
  }
14
26
  //#endregion
@@ -1,10 +1,21 @@
1
1
  import { PinataStorage } from "./pinata/index.js";
2
2
 
3
3
  //#region src/providers/storage/index.d.ts
4
- interface StorageProvider<T> {
5
- store(data: T, metadata?: Record<string, unknown>): Promise<string>;
4
+
5
+ /**
6
+ * Read-only storage (e.g. for a consuming party)
7
+ * Does not require any authentication
8
+ */
9
+ interface ReadableStorage<T> {
6
10
  retrieve(cid: string): Promise<T>;
7
- delete?(cid: string): Promise<void>;
11
+ }
12
+ /**
13
+ * Read/Write storage
14
+ * (Likely) Requires authentication.
15
+ */
16
+ interface WritableStorage<T> extends ReadableStorage<T> {
17
+ store(data: T, metadata?: Record<string, unknown>): Promise<string>;
18
+ delete(cid: string): Promise<void>;
8
19
  }
9
20
  //#endregion
10
- export { PinataStorage, StorageProvider as default };
21
+ export { PinataStorage, ReadableStorage, WritableStorage };
@@ -1,11 +1,12 @@
1
- import StorageProvider from "../index.js";
1
+ import { WritableStorage } from "../index.js";
2
2
 
3
3
  //#region src/providers/storage/pinata/index.d.ts
4
- declare class PinataStorage implements StorageProvider<any> {
4
+ declare class PinataStorage implements WritableStorage<unknown> {
5
5
  private pinata;
6
+ private gateway;
6
7
  constructor(pinataJwt: string, pinataGateway: string);
7
- store(data: any, metadata?: Record<string, unknown>): Promise<string>;
8
- retrieve(cid: string): Promise<string | JSON | Blob>;
8
+ store(data: unknown, metadata?: Record<string, string>): Promise<string>;
9
+ retrieve(cid: string): Promise<unknown>;
9
10
  delete(cid: string): Promise<void>;
10
11
  }
11
12
  //#endregion
@@ -3,19 +3,34 @@ import { PinataSDK } from "pinata";
3
3
  //#region src/providers/storage/pinata/index.ts
4
4
  var PinataStorage = class {
5
5
  pinata;
6
+ gateway;
6
7
  constructor(pinataJwt, pinataGateway) {
7
8
  this.pinata = new PinataSDK({
8
9
  pinataJwt,
9
10
  pinataGateway
10
11
  });
12
+ this.gateway = pinataGateway.replace(/\/$/, "");
11
13
  }
12
14
  async store(data, metadata) {
13
- const content = typeof data === "string" ? data : JSON.stringify(data);
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
+ });
14
22
  const file = new File([content], metadata?.name ?? "file", { type: "text/plain" });
15
23
  return (await this.pinata.upload.public.file(file, { metadata })).cid;
16
24
  }
17
25
  async retrieve(cid) {
18
- return (await this.pinata.gateways.public.get(cid)).data;
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
+ });
19
34
  }
20
35
  async delete(cid) {
21
36
  await this.pinata.files.public.delete([cid]);
@@ -0,0 +1,13 @@
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 };
@@ -0,0 +1,49 @@
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 };
@@ -0,0 +1,8 @@
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 };
@@ -0,0 +1,16 @@
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 };
@@ -1,95 +1,81 @@
1
- //#region src/interface/datasource-registry/abi.d.ts
1
+ //#region src/registries/datasource-registry/abi.d.ts
2
2
  declare const DS_REGISTRY_ABI: readonly [{
3
- readonly name: "registerDataSource";
3
+ readonly name: "initialize";
4
4
  readonly type: "function";
5
5
  readonly stateMutability: "nonpayable";
6
6
  readonly inputs: readonly [{
7
- readonly name: "name";
8
- readonly type: "string";
9
- }, {
10
- readonly name: "agentId";
11
- readonly type: "string";
12
- }];
13
- readonly outputs: readonly [{
14
- readonly name: "id";
15
- readonly type: "bytes32";
7
+ readonly type: "address";
8
+ readonly name: "schema_registry";
16
9
  }];
10
+ readonly outputs: readonly [];
17
11
  }, {
18
- readonly name: "updateDataSource";
12
+ readonly name: "publishManifest";
19
13
  readonly type: "function";
20
14
  readonly stateMutability: "nonpayable";
21
15
  readonly inputs: readonly [{
22
- readonly name: "name";
23
16
  readonly type: "string";
17
+ readonly name: "manifest_cid";
24
18
  }, {
25
- readonly name: "newManifestCid";
26
- readonly type: "string";
19
+ readonly type: "bytes32";
20
+ readonly name: "schema_id";
27
21
  }];
28
22
  readonly outputs: readonly [];
29
23
  }, {
30
- readonly name: "getDataSource";
24
+ readonly name: "getManifest";
31
25
  readonly type: "function";
32
26
  readonly stateMutability: "view";
33
27
  readonly inputs: readonly [{
34
- readonly name: "owner";
35
28
  readonly type: "address";
29
+ readonly name: "owner";
36
30
  }, {
37
- readonly name: "name";
38
- readonly type: "string";
31
+ readonly type: "bytes32";
32
+ readonly name: "schema_id";
39
33
  }];
40
34
  readonly outputs: readonly [{
41
- readonly name: "manifestCid";
42
35
  readonly type: "string";
43
36
  }];
44
37
  }, {
45
- readonly name: "getOwnedDataSources";
38
+ readonly name: "getVersion";
46
39
  readonly type: "function";
47
40
  readonly stateMutability: "view";
48
41
  readonly inputs: readonly [{
49
- readonly name: "owner";
50
42
  readonly type: "address";
43
+ readonly name: "owner";
44
+ }, {
45
+ readonly type: "bytes32";
46
+ readonly name: "schema_id";
51
47
  }];
52
48
  readonly outputs: readonly [{
53
- readonly type: "bytes32[]";
49
+ readonly type: "uint64";
54
50
  }];
55
51
  }, {
56
- readonly name: "DataSourceCreated";
52
+ readonly name: "ManifestPublished";
57
53
  readonly type: "event";
58
54
  readonly inputs: readonly [{
59
- readonly name: "id";
60
- readonly type: "bytes32";
61
- readonly indexed: true;
62
- }, {
63
- readonly name: "owner";
64
55
  readonly type: "address";
56
+ readonly name: "owner";
65
57
  readonly indexed: true;
66
58
  }, {
67
- readonly name: "name";
68
- readonly type: "string";
69
- readonly indexed: false;
70
- }];
71
- }, {
72
- readonly name: "DataSourceUpdated";
73
- readonly type: "event";
74
- readonly inputs: readonly [{
75
- readonly name: "id";
76
59
  readonly type: "bytes32";
60
+ readonly name: "schema_id";
77
61
  readonly indexed: true;
78
62
  }, {
79
- readonly name: "newManifestCid";
80
63
  readonly type: "string";
81
- readonly indexed: false;
64
+ readonly name: "manifest_cid";
65
+ }, {
66
+ readonly type: "uint64";
67
+ readonly name: "version";
82
68
  }];
83
69
  }, {
84
- readonly name: "NotOwner";
70
+ readonly name: "DataSourceNotFound";
85
71
  readonly type: "error";
86
72
  readonly inputs: readonly [];
87
73
  }, {
88
- readonly name: "DataSourceNotFound";
74
+ readonly name: "SchemaNotFound";
89
75
  readonly type: "error";
90
76
  readonly inputs: readonly [];
91
77
  }, {
92
- readonly name: "DataSourceAlreadyExists";
78
+ readonly name: "SchemaRequired";
93
79
  readonly type: "error";
94
80
  readonly inputs: readonly [];
95
81
  }];
@@ -0,0 +1,16 @@
1
+ import { parseAbi } from "viem";
2
+
3
+ //#region src/registries/datasource-registry/abi.ts
4
+ const DS_REGISTRY_ABI = parseAbi([
5
+ "function initialize(address schema_registry) external",
6
+ "function publishManifest(string calldata manifest_cid, bytes32 schema_id) external",
7
+ "function getManifest(address owner, bytes32 schema_id) external view returns (string memory)",
8
+ "function getVersion(address owner, bytes32 schema_id) external view returns (uint64)",
9
+ "event ManifestPublished(address indexed owner, bytes32 indexed schema_id, string manifest_cid, uint64 version)",
10
+ "error DataSourceNotFound()",
11
+ "error SchemaNotFound()",
12
+ "error SchemaRequired()"
13
+ ]);
14
+
15
+ //#endregion
16
+ export { DS_REGISTRY_ABI };
@@ -0,0 +1,24 @@
1
+ import * as viem431 from "viem";
2
+ import { Address, Hash, Hex, PublicClient, WalletClient } from "viem";
3
+
4
+ //#region src/registries/datasource-registry/index.d.ts
5
+ interface DataSource {
6
+ manifestCid: string;
7
+ schemaId: Hex;
8
+ version: bigint;
9
+ }
10
+ declare class DataSourceRegistry {
11
+ private publicClient;
12
+ private walletClient;
13
+ private contractAddress;
14
+ constructor(contractAddress: Address, publicClient: PublicClient, walletClient: WalletClient);
15
+ private getWriteConfig;
16
+ getContractAddress(): `0x${string}`;
17
+ initialize(schemaRegistryAddress: Address): Promise<Hash>;
18
+ publishManifest(manifestCid: string, schemaId: Hex): Promise<Hash>;
19
+ getManifest(owner: Address, schemaId: Hex): Promise<DataSource>;
20
+ getVersion(owner: Address, schemaId: Hex): Promise<bigint>;
21
+ waitForTransaction(hash: Hash): Promise<viem431.TransactionReceipt>;
22
+ }
23
+ //#endregion
24
+ export { DataSource, DataSourceRegistry };
@@ -1,7 +1,6 @@
1
1
  import { DS_REGISTRY_ABI } from "./abi.js";
2
- import { parseEventLogs } from "viem";
3
2
 
4
- //#region src/interface/datasource-registry/dataSourceRegistry.ts
3
+ //#region src/registries/datasource-registry/index.ts
5
4
  var DataSourceRegistry = class {
6
5
  publicClient;
7
6
  walletClient;
@@ -22,56 +21,58 @@ var DataSourceRegistry = class {
22
21
  getContractAddress() {
23
22
  return this.contractAddress;
24
23
  }
25
- async getDataSource(owner, name) {
26
- return {
27
- manifestCid: await this.publicClient.readContract({
28
- address: this.contractAddress,
29
- abi: DS_REGISTRY_ABI,
30
- functionName: "getDataSource",
31
- args: [owner, name]
32
- }),
33
- owner,
34
- name
35
- };
36
- }
37
- async getOwnedDataSources(address) {
38
- return await this.publicClient.readContract({
39
- address: this.contractAddress,
40
- abi: DS_REGISTRY_ABI,
41
- functionName: "getOwnedDataSources",
42
- args: [address]
43
- });
44
- }
45
- async registerDataSource(name, agentId) {
24
+ async initialize(schemaRegistryAddress) {
46
25
  const { chain, account } = this.getWriteConfig();
47
26
  const hash = await this.walletClient.writeContract({
48
27
  address: this.contractAddress,
49
28
  abi: DS_REGISTRY_ABI,
50
- functionName: "registerDataSource",
51
- args: [name, agentId],
29
+ functionName: "initialize",
30
+ args: [schemaRegistryAddress],
52
31
  chain,
53
32
  account
54
33
  });
55
- const logs = parseEventLogs({
56
- abi: DS_REGISTRY_ABI,
57
- logs: (await this.waitForTransaction(hash)).logs
58
- });
59
- for (const log of logs) if (log.eventName == "DataSourceCreated") return log.args.id;
60
- console.error("Something went wrong: no id created!");
34
+ await this.waitForTransaction(hash);
35
+ return hash;
61
36
  }
62
- async updateDataSource(name, newManifestCid) {
37
+ async publishManifest(manifestCid, schemaId) {
63
38
  const { chain, account } = this.getWriteConfig();
64
39
  const hash = await this.walletClient.writeContract({
65
40
  address: this.contractAddress,
66
41
  abi: DS_REGISTRY_ABI,
67
- functionName: "updateDataSource",
68
- args: [name, newManifestCid],
42
+ functionName: "publishManifest",
43
+ args: [manifestCid, schemaId],
69
44
  chain,
70
45
  account
71
46
  });
72
47
  await this.waitForTransaction(hash);
73
48
  return hash;
74
49
  }
50
+ async getManifest(owner, schemaId) {
51
+ const [manifestCid, version] = await Promise.all([this.publicClient.readContract({
52
+ address: this.contractAddress,
53
+ abi: DS_REGISTRY_ABI,
54
+ functionName: "getManifest",
55
+ args: [owner, schemaId]
56
+ }), this.publicClient.readContract({
57
+ address: this.contractAddress,
58
+ abi: DS_REGISTRY_ABI,
59
+ functionName: "getVersion",
60
+ args: [owner, schemaId]
61
+ })]);
62
+ return {
63
+ manifestCid,
64
+ schemaId,
65
+ version
66
+ };
67
+ }
68
+ async getVersion(owner, schemaId) {
69
+ return this.publicClient.readContract({
70
+ address: this.contractAddress,
71
+ abi: DS_REGISTRY_ABI,
72
+ functionName: "getVersion",
73
+ args: [owner, schemaId]
74
+ });
75
+ }
75
76
  async waitForTransaction(hash) {
76
77
  return this.publicClient.waitForTransactionReceipt({ hash });
77
78
  }
@@ -0,0 +1,3 @@
1
+ import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
2
+ import { DS_REGISTRY_ABI } from "./datasource-registry/abi.js";
3
+ export { DS_REGISTRY_ABI, SETTLEMENT_REGISTRY_ABI };
@@ -0,0 +1,4 @@
1
+ import { SETTLEMENT_REGISTRY_ABI } from "./settlement-registry/abi.js";
2
+ import { DS_REGISTRY_ABI } from "./datasource-registry/abi.js";
3
+
4
+ export { DS_REGISTRY_ABI, SETTLEMENT_REGISTRY_ABI };