@fangorn-network/sdk 2026.4.7 → 2026.4.10
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 +30 -26
- package/lib/cli/cli.js +115 -153
- 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 +0 -3
- package/lib/fangorn.js +16 -28
- package/lib/index.d.ts +3 -3
- package/lib/index.js +4 -5
- package/lib/modules/encryption/lit.d.ts +0 -1
- package/lib/modules/encryption/lit.js +1 -7
- package/lib/modules/gadgets/settledGadget.d.ts +1 -8
- package/lib/modules/gadgets/settledGadget.js +1 -13
- package/lib/providers/storage/index.d.ts +12 -12
- package/lib/providers/storage/index.js +49 -2
- package/lib/providers/storage/pinata.d.ts +11 -0
- package/lib/providers/storage/pinata.js +24 -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 +8 -29
- package/lib/roles/consumer/index.js +25 -45
- package/lib/roles/consumer/types.d.ts +4 -4
- package/lib/roles/publisher/index.d.ts +26 -29
- package/lib/roles/publisher/index.js +70 -77
- package/lib/roles/publisher/types.d.ts +7 -3
- package/lib/roles/schema/index.d.ts +3 -8
- package/lib/roles/schema/index.js +6 -34
- package/lib/test/testbed.d.ts +7 -32
- package/lib/test/testbed.js +22 -45
- package/lib/types/index.d.ts +10 -20
- package/package.json +1 -1
- package/lib/providers/storage/pinata/index.d.ts +0 -13
- package/lib/providers/storage/pinata/index.js +0 -41
- package/lib/providers/storage/storacha/index.d.ts +0 -13
- package/lib/providers/storage/storacha/index.js +0 -49
- package/lib/providers/storage/storacha/readOnly.d.ts +0 -8
- package/lib/providers/storage/storacha/readOnly.js +0 -16
package/lib/config.js
CHANGED
|
@@ -26,13 +26,14 @@ function getNetwork(name) {
|
|
|
26
26
|
}
|
|
27
27
|
const FangornConfig = {
|
|
28
28
|
ArbitrumSepolia: {
|
|
29
|
-
dataSourceRegistryContractAddress: "
|
|
30
|
-
schemaRegistryContractAddress: "
|
|
31
|
-
settlementRegistryContractAddress: "
|
|
29
|
+
dataSourceRegistryContractAddress: "0xdb82c131a9d51f6e7695e744bb2bd7774cbb224c",
|
|
30
|
+
schemaRegistryContractAddress: "0x35b67934f9c75bfef6ff3f4d61ff406d81420066",
|
|
31
|
+
settlementRegistryContractAddress: "0x6aff8212e126ed3232958fd228bc58a202b8f590",
|
|
32
32
|
chainName: "arbitrumSepolia",
|
|
33
33
|
chain: arbitrumSepolia,
|
|
34
34
|
rpcUrl: "https://sepolia-rollup.arbitrum.io/rpc",
|
|
35
|
-
caip2: 421614
|
|
35
|
+
caip2: 421614,
|
|
36
|
+
ipfsGateway: "https://ipfs.io"
|
|
36
37
|
},
|
|
37
38
|
BaseSepolia: {
|
|
38
39
|
dataSourceRegistryContractAddress: "0x6fd0e50073dbd8169bcaf066bb4a4991bfa48eeb",
|
|
@@ -41,7 +42,8 @@ const FangornConfig = {
|
|
|
41
42
|
chainName: "baseSepolia",
|
|
42
43
|
chain: baseSepolia,
|
|
43
44
|
rpcUrl: "https://sepolia.base.org",
|
|
44
|
-
caip2: 84532
|
|
45
|
+
caip2: 84532,
|
|
46
|
+
ipfsGateway: "https://ipfs.io"
|
|
45
47
|
}
|
|
46
48
|
};
|
|
47
49
|
|
package/lib/fangorn.d.ts
CHANGED
|
@@ -17,17 +17,14 @@ declare class Fangorn {
|
|
|
17
17
|
private constructor();
|
|
18
18
|
/**
|
|
19
19
|
* Schema owner: register agents, register schemas, validate definitions.
|
|
20
|
-
* Requires writable storage.
|
|
21
20
|
*/
|
|
22
21
|
get schema(): SchemaRole;
|
|
23
22
|
/**
|
|
24
23
|
* Publisher: encrypt, stage, and commit data under a schema.
|
|
25
|
-
* Requires writable storage.
|
|
26
24
|
*/
|
|
27
25
|
get publisher(): PublisherRole;
|
|
28
26
|
/**
|
|
29
27
|
* Consumer: purchase, claim, and decrypt data.
|
|
30
|
-
* Works with both readable and writable storage.
|
|
31
28
|
*/
|
|
32
29
|
get consumer(): ConsumerRole;
|
|
33
30
|
/**
|
package/lib/fangorn.js
CHANGED
|
@@ -1,40 +1,29 @@
|
|
|
1
1
|
import { FangornConfig } from "./config.js";
|
|
2
2
|
import { LitEncryptionService } from "./modules/encryption/lit.js";
|
|
3
3
|
import "./modules/encryption/index.js";
|
|
4
|
+
import { PinataStorage } from "./providers/storage/pinata.js";
|
|
5
|
+
import "./providers/storage/index.js";
|
|
4
6
|
import { SchemaRole } from "./roles/schema/index.js";
|
|
5
|
-
import {
|
|
7
|
+
import { DataSourceRegistry } from "./registries/datasource-registry/index.js";
|
|
6
8
|
import { PublisherRole } from "./roles/publisher/index.js";
|
|
7
9
|
import { ConsumerRole } from "./roles/consumer/index.js";
|
|
8
10
|
import { SchemaRegistry } from "./registries/schema-registry/index.js";
|
|
9
|
-
import {
|
|
10
|
-
import { PinataStorage } from "./providers/storage/pinata/index.js";
|
|
11
|
-
import "./providers/storage/index.js";
|
|
12
|
-
import { StorachaStorage } from "./providers/storage/storacha/index.js";
|
|
13
|
-
import { ReadOnlyStorachaStorage } from "./providers/storage/storacha/readOnly.js";
|
|
11
|
+
import { SettlementRegistry } from "./registries/settlement-registry/index.js";
|
|
14
12
|
import { createPublicClient, createWalletClient, http } from "viem";
|
|
15
13
|
import { privateKeyToAccount } from "viem/accounts";
|
|
16
14
|
|
|
17
15
|
//#region src/fangorn.ts
|
|
16
|
+
const DEFAULT_IPFS_GATEWAY = "https://ipfs.io";
|
|
18
17
|
function isEncryptionService(e) {
|
|
19
18
|
return typeof e.encrypt === "function";
|
|
20
19
|
}
|
|
21
20
|
function isPinataConfig(s) {
|
|
22
21
|
return "pinata" in s;
|
|
23
22
|
}
|
|
24
|
-
function
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
function isStorachaConfig(s) {
|
|
28
|
-
return "storacha" in s && "email" in s.storacha;
|
|
29
|
-
}
|
|
30
|
-
function isWritable(s) {
|
|
31
|
-
return "store" in s && "delete" in s;
|
|
32
|
-
}
|
|
33
|
-
async function resolveStorage(storage) {
|
|
23
|
+
function resolveStorage(storage) {
|
|
24
|
+
if (!storage) return void 0;
|
|
34
25
|
if (isPinataConfig(storage)) return new PinataStorage(storage.pinata.jwt, storage.pinata.gateway);
|
|
35
|
-
|
|
36
|
-
if (isStorachaConfig(storage)) return StorachaStorage.create(storage.storacha.email);
|
|
37
|
-
throw new Error("Invalid storage config: must be a StorageProvider instance, a { pinata } object, or a { storacha } object.");
|
|
26
|
+
throw new Error(`Invalid storage config: must be { pinata: { jwt, gateway } }, but was ${JSON.stringify(storage)}`);
|
|
38
27
|
}
|
|
39
28
|
var Fangorn = class Fangorn {
|
|
40
29
|
ctx;
|
|
@@ -46,26 +35,23 @@ var Fangorn = class Fangorn {
|
|
|
46
35
|
}
|
|
47
36
|
/**
|
|
48
37
|
* Schema owner: register agents, register schemas, validate definitions.
|
|
49
|
-
* Requires writable storage.
|
|
50
38
|
*/
|
|
51
39
|
get schema() {
|
|
52
|
-
if (!
|
|
53
|
-
return this._schema ??= new SchemaRole(this.ctx.schemaRegistry, this.ctx.storage, this.ctx.walletClient, this.ctx.
|
|
40
|
+
if (!this.ctx.storage) throw new Error("fangorn.schema requires storage. Pass { pinata: { ... } } to Fangorn.create()");
|
|
41
|
+
return this._schema ??= new SchemaRole(this.ctx.schemaRegistry, this.ctx.storage, this.ctx.walletClient, this.ctx.ipfsGateway);
|
|
54
42
|
}
|
|
55
43
|
/**
|
|
56
44
|
* Publisher: encrypt, stage, and commit data under a schema.
|
|
57
|
-
* Requires writable storage.
|
|
58
45
|
*/
|
|
59
46
|
get publisher() {
|
|
60
|
-
if (!
|
|
61
|
-
return this._publisher ??= new PublisherRole(this.ctx.dataSourceRegistry, this.ctx.
|
|
47
|
+
if (!this.ctx.storage) throw new Error("fangorn.publisher requires storage. Pass { pinata: { ... } } to Fangorn.create()");
|
|
48
|
+
return this._publisher ??= new PublisherRole(this.ctx.dataSourceRegistry, this.ctx.schemaRegistry, this.ctx.storage, this.ctx.encryption, this.ctx.walletClient, this.ctx.config);
|
|
62
49
|
}
|
|
63
50
|
/**
|
|
64
51
|
* Consumer: purchase, claim, and decrypt data.
|
|
65
|
-
* Works with both readable and writable storage.
|
|
66
52
|
*/
|
|
67
53
|
get consumer() {
|
|
68
|
-
return this._consumer ??= new ConsumerRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.
|
|
54
|
+
return this._consumer ??= new ConsumerRole(this.ctx.dataSourceRegistry, this.ctx.settlementRegistry, this.ctx.encryption, this.ctx.domain, this.ctx.ipfsGateway);
|
|
69
55
|
}
|
|
70
56
|
/**
|
|
71
57
|
* Create a new Fangorn instance
|
|
@@ -80,15 +66,17 @@ var Fangorn = class Fangorn {
|
|
|
80
66
|
chain: resolvedConfig.chain,
|
|
81
67
|
transport: http(resolvedConfig.rpcUrl)
|
|
82
68
|
});
|
|
83
|
-
const storage =
|
|
69
|
+
const storage = resolveStorage(options.storage);
|
|
84
70
|
const encryption = isEncryptionService(options.encryption) ? options.encryption : await LitEncryptionService.init(resolvedConfig.chainName);
|
|
85
71
|
const domain = options.domain ?? new URL(resolvedConfig.rpcUrl).hostname;
|
|
72
|
+
const ipfsGateway = options.ipfsGateway ?? DEFAULT_IPFS_GATEWAY;
|
|
86
73
|
const publicClient = createPublicClient({ transport: http(resolvedConfig.rpcUrl) });
|
|
87
74
|
return new Fangorn({
|
|
88
75
|
walletClient,
|
|
89
76
|
storage,
|
|
90
77
|
encryption,
|
|
91
78
|
domain,
|
|
79
|
+
ipfsGateway,
|
|
92
80
|
schemaRegistry: new SchemaRegistry(resolvedConfig.schemaRegistryContractAddress, publicClient, walletClient),
|
|
93
81
|
dataSourceRegistry: new DataSourceRegistry(resolvedConfig.dataSourceRegistryContractAddress, publicClient, walletClient),
|
|
94
82
|
settlementRegistry: new SettlementRegistry(resolvedConfig.settlementRegistryContractAddress, publicClient, walletClient),
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AppConfig, FangornConfig, SupportedNetworks } from "./config.js";
|
|
2
|
-
import { PinataStorage } from "./providers/storage/pinata
|
|
3
|
-
import {
|
|
2
|
+
import { PinataStorage } from "./providers/storage/pinata.js";
|
|
3
|
+
import { PinningService, deserialize, retrieveByCid, serialize } from "./providers/storage/index.js";
|
|
4
4
|
import { Gadget } from "./modules/gadgets/types.js";
|
|
5
5
|
import "./modules/gadgets/index.js";
|
|
6
6
|
import { LitEncryptionService } from "./modules/encryption/lit.js";
|
|
@@ -9,4 +9,4 @@ import { Fangorn } from "./fangorn.js";
|
|
|
9
9
|
import { SETTLEMENT_REGISTRY_ABI } from "./registries/settlement-registry/abi.js";
|
|
10
10
|
import { DS_REGISTRY_ABI } from "./registries/datasource-registry/abi.js";
|
|
11
11
|
import { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
|
|
12
|
-
export { AppConfig, AuthContext, AuthSig, DS_REGISTRY_ABI, EncryptionService, Fangorn, FangornConfig, Gadget, LitEncryptionService, PinataStorage,
|
|
12
|
+
export { AppConfig, AuthContext, AuthSig, DS_REGISTRY_ABI, EncryptionService, Fangorn, FangornConfig, Gadget, LitEncryptionService, PinataStorage, PinningService, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
|
package/lib/index.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { FangornConfig, SupportedNetworks } from "./config.js";
|
|
2
2
|
import { LitEncryptionService } from "./modules/encryption/lit.js";
|
|
3
3
|
import "./modules/encryption/index.js";
|
|
4
|
-
import {
|
|
4
|
+
import { PinataStorage } from "./providers/storage/pinata.js";
|
|
5
|
+
import { deserialize, retrieveByCid, serialize } from "./providers/storage/index.js";
|
|
5
6
|
import { DS_REGISTRY_ABI } from "./registries/datasource-registry/abi.js";
|
|
6
|
-
import {
|
|
7
|
-
import "./providers/storage/index.js";
|
|
7
|
+
import { SETTLEMENT_REGISTRY_ABI } from "./registries/settlement-registry/abi.js";
|
|
8
8
|
import { Fangorn } from "./fangorn.js";
|
|
9
|
-
import "./registries/index.js";
|
|
10
9
|
import { addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array } from "./utils/index.js";
|
|
11
10
|
|
|
12
|
-
export { DS_REGISTRY_ABI, Fangorn, FangornConfig, LitEncryptionService, PinataStorage, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, fieldToHex, hexToBytes32Array, hexToField, stringToBytes32Array };
|
|
11
|
+
export { DS_REGISTRY_ABI, Fangorn, FangornConfig, LitEncryptionService, PinataStorage, SETTLEMENT_REGISTRY_ABI, SupportedNetworks, addressToBytes32Array, computeSchemaId, deserialize, fieldToHex, hexToBytes32Array, hexToField, retrieveByCid, serialize, stringToBytes32Array };
|
|
@@ -15,7 +15,6 @@ declare class LitEncryptionService implements EncryptionService {
|
|
|
15
15
|
decrypt(payload: EncryptedPayload, authContext: AuthContextWrapper): Promise<DecryptedPayload>;
|
|
16
16
|
createAuthContext(walletClient: WalletClient, domain: string): Promise<AuthContextWrapper>;
|
|
17
17
|
private createAuthSig;
|
|
18
|
-
private parseKeyResponse;
|
|
19
18
|
}
|
|
20
19
|
//#endregion
|
|
21
20
|
export { LitEncryptionService };
|
|
@@ -47,7 +47,7 @@ var LitEncryptionService = class LitEncryptionService {
|
|
|
47
47
|
}
|
|
48
48
|
async createAuthContext(walletClient, domain) {
|
|
49
49
|
const isNode = typeof window === "undefined";
|
|
50
|
-
const account =
|
|
50
|
+
const account = walletClient.account;
|
|
51
51
|
if (!account) throw new Error("No account found in wallet client");
|
|
52
52
|
if (!walletClient.chain) throw new Error("No chain found in wallet client");
|
|
53
53
|
const sessionContext = await (isNode ? createAuthManager({ storage: storagePlugins.localStorageNode({
|
|
@@ -115,12 +115,6 @@ var LitEncryptionService = class LitEncryptionService {
|
|
|
115
115
|
address: account.address
|
|
116
116
|
};
|
|
117
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
118
|
};
|
|
125
119
|
|
|
126
120
|
//#endregion
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { AppConfig } from "../../config.js";
|
|
2
1
|
import { Gadget, GadgetDescriptor } from "./types.js";
|
|
3
2
|
import { Address, Hex } from "viem";
|
|
4
3
|
import { UnifiedAccessControlCondition } from "@lit-protocol/access-control-conditions";
|
|
@@ -12,12 +11,6 @@ interface SettledGadgetParams {
|
|
|
12
11
|
/** "arbitrumSepolia" | "baseSepolia" */
|
|
13
12
|
chainName: string;
|
|
14
13
|
}
|
|
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
14
|
declare class SettledGadget implements Gadget {
|
|
22
15
|
private readonly params;
|
|
23
16
|
readonly type = "settled";
|
|
@@ -28,4 +21,4 @@ declare class SettledGadget implements Gadget {
|
|
|
28
21
|
toDescriptor(): GadgetDescriptor;
|
|
29
22
|
}
|
|
30
23
|
//#endregion
|
|
31
|
-
export { SettledGadget, SettledGadgetParams
|
|
24
|
+
export { SettledGadget, SettledGadgetParams };
|
|
@@ -2,18 +2,6 @@ import { zeroAddress } from "viem";
|
|
|
2
2
|
import { createAccBuilder } from "@lit-protocol/access-control-conditions";
|
|
3
3
|
|
|
4
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
5
|
var SettledGadget = class {
|
|
18
6
|
type = "settled";
|
|
19
7
|
constructor(params) {
|
|
@@ -72,4 +60,4 @@ var SettledGadget = class {
|
|
|
72
60
|
};
|
|
73
61
|
|
|
74
62
|
//#endregion
|
|
75
|
-
export { SettledGadget
|
|
63
|
+
export { SettledGadget };
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { PinataStorage } from "./pinata
|
|
1
|
+
import { PinataStorage } from "./pinata.js";
|
|
2
2
|
|
|
3
3
|
//#region src/providers/storage/index.d.ts
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
6
|
+
* A pinning service that stores content on IPFS and returns a CID.
|
|
7
|
+
* Retrieval is always done via a public gateway — see retrieveByCid.
|
|
8
8
|
*/
|
|
9
|
-
interface
|
|
10
|
-
|
|
9
|
+
interface PinningService {
|
|
10
|
+
store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
|
|
11
|
+
delete(cid: string): Promise<void>;
|
|
11
12
|
}
|
|
13
|
+
declare function serialize(data: unknown): string;
|
|
14
|
+
declare function deserialize(text: string): unknown;
|
|
12
15
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
16
|
+
* Fetch any content by CID from a public IPFS gateway.
|
|
17
|
+
* No auth required — all Fangorn content is public; privacy is cryptographic.
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
store(data: T, metadata?: Record<string, unknown>): Promise<string>;
|
|
18
|
-
delete(cid: string): Promise<void>;
|
|
19
|
-
}
|
|
19
|
+
declare function retrieveByCid<T>(cid: string, gateway?: string): Promise<T>;
|
|
20
20
|
//#endregion
|
|
21
|
-
export { PinataStorage,
|
|
21
|
+
export { PinataStorage, PinningService, deserialize, retrieveByCid, serialize };
|
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
import { PinataStorage } from "./pinata
|
|
1
|
+
import { PinataStorage } from "./pinata.js";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
//#region src/providers/storage/index.ts
|
|
4
|
+
const REVIVERS = [(_key, value) => {
|
|
5
|
+
if (value !== null && typeof value === "object" && "__type" in value && "data" in value && value.__type === "Uint8Array") return new Uint8Array(Buffer.from(value.data, "base64"));
|
|
6
|
+
return value;
|
|
7
|
+
}];
|
|
8
|
+
function serialize(data) {
|
|
9
|
+
if (typeof data === "string") return data;
|
|
10
|
+
return JSON.stringify(data, (_key, value) => {
|
|
11
|
+
if (value instanceof Uint8Array) return {
|
|
12
|
+
__type: "Uint8Array",
|
|
13
|
+
data: Buffer.from(value).toString("base64")
|
|
14
|
+
};
|
|
15
|
+
return value;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function deserialize(text) {
|
|
19
|
+
return JSON.parse(text, (key, value) => {
|
|
20
|
+
for (const reviver of REVIVERS) {
|
|
21
|
+
const result = reviver(key, value);
|
|
22
|
+
if (result !== value) return result;
|
|
23
|
+
}
|
|
24
|
+
return value;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Fetch any content by CID from a public IPFS gateway.
|
|
29
|
+
* No auth required — all Fangorn content is public; privacy is cryptographic.
|
|
30
|
+
*/
|
|
31
|
+
async function retrieveByCid(cid, gateway = "https://ipfs.io") {
|
|
32
|
+
const url = `${gateway.replace(/\/$/, "")}/ipfs/${cid}`;
|
|
33
|
+
const controller = new AbortController();
|
|
34
|
+
const timeout = setTimeout(() => {
|
|
35
|
+
controller.abort();
|
|
36
|
+
}, 1e4);
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(url, { signal: controller.signal });
|
|
39
|
+
if (!res.ok) throw new Error(`Failed to retrieve ${cid}: ${res.statusText}`);
|
|
40
|
+
return deserialize(await res.text());
|
|
41
|
+
} catch (err) {
|
|
42
|
+
if (err.name === "AbortError") throw new Error(`Timed out retrieving ${cid} from ${url}`);
|
|
43
|
+
throw err;
|
|
44
|
+
} finally {
|
|
45
|
+
clearTimeout(timeout);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
export { PinataStorage, deserialize, retrieveByCid, serialize };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PinningService } from "./index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/providers/storage/pinata.d.ts
|
|
4
|
+
declare class PinataStorage implements PinningService {
|
|
5
|
+
private pinata;
|
|
6
|
+
constructor(pinataJwt: string, pinataGateway: string);
|
|
7
|
+
store(data: unknown, metadata?: Record<string, unknown>): Promise<string>;
|
|
8
|
+
delete(cid: string): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PinataStorage };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { serialize } from "./index.js";
|
|
2
|
+
import { PinataSDK } from "pinata";
|
|
3
|
+
|
|
4
|
+
//#region src/providers/storage/pinata.ts
|
|
5
|
+
var PinataStorage = class {
|
|
6
|
+
pinata;
|
|
7
|
+
constructor(pinataJwt, pinataGateway) {
|
|
8
|
+
this.pinata = new PinataSDK({
|
|
9
|
+
pinataJwt,
|
|
10
|
+
pinataGateway
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async store(data, metadata) {
|
|
14
|
+
const content = serialize(data);
|
|
15
|
+
const file = new File([content], (metadata ?? { name: "file" }).name, { type: "text/plain" });
|
|
16
|
+
return (await this.pinata.upload.public.file(file, { metadata })).cid;
|
|
17
|
+
}
|
|
18
|
+
async delete(cid) {
|
|
19
|
+
await this.pinata.files.public.delete([cid]);
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
//#endregion
|
|
24
|
+
export { PinataStorage };
|
|
@@ -1,83 +1,156 @@
|
|
|
1
1
|
//#region src/registries/datasource-registry/abi.d.ts
|
|
2
2
|
declare const DS_REGISTRY_ABI: readonly [{
|
|
3
|
-
readonly
|
|
4
|
-
readonly
|
|
5
|
-
readonly
|
|
3
|
+
readonly inputs: readonly [];
|
|
4
|
+
readonly name: "DataSourceNotFound";
|
|
5
|
+
readonly type: "error";
|
|
6
|
+
}, {
|
|
7
|
+
readonly inputs: readonly [];
|
|
8
|
+
readonly name: "NameRequired";
|
|
9
|
+
readonly type: "error";
|
|
10
|
+
}, {
|
|
11
|
+
readonly inputs: readonly [];
|
|
12
|
+
readonly name: "ResourceSetupFailed";
|
|
13
|
+
readonly type: "error";
|
|
14
|
+
}, {
|
|
15
|
+
readonly inputs: readonly [];
|
|
16
|
+
readonly name: "SchemaNotFound";
|
|
17
|
+
readonly type: "error";
|
|
18
|
+
}, {
|
|
19
|
+
readonly inputs: readonly [];
|
|
20
|
+
readonly name: "SchemaRequired";
|
|
21
|
+
readonly type: "error";
|
|
22
|
+
}, {
|
|
6
23
|
readonly inputs: readonly [{
|
|
24
|
+
readonly internalType: "address";
|
|
25
|
+
readonly name: "owner";
|
|
7
26
|
readonly type: "address";
|
|
8
|
-
|
|
27
|
+
}, {
|
|
28
|
+
readonly internalType: "bytes32";
|
|
29
|
+
readonly name: "schema_id";
|
|
30
|
+
readonly type: "bytes32";
|
|
31
|
+
}, {
|
|
32
|
+
readonly internalType: "string";
|
|
33
|
+
readonly name: "name";
|
|
34
|
+
readonly type: "string";
|
|
9
35
|
}];
|
|
10
|
-
readonly
|
|
11
|
-
|
|
12
|
-
|
|
36
|
+
readonly name: "get";
|
|
37
|
+
readonly outputs: readonly [{
|
|
38
|
+
readonly internalType: "string";
|
|
39
|
+
readonly name: "";
|
|
40
|
+
readonly type: "string";
|
|
41
|
+
}];
|
|
42
|
+
readonly stateMutability: "view";
|
|
13
43
|
readonly type: "function";
|
|
14
|
-
|
|
44
|
+
}, {
|
|
15
45
|
readonly inputs: readonly [{
|
|
16
|
-
readonly
|
|
17
|
-
readonly name: "
|
|
46
|
+
readonly internalType: "address";
|
|
47
|
+
readonly name: "owner";
|
|
48
|
+
readonly type: "address";
|
|
18
49
|
}, {
|
|
19
|
-
readonly
|
|
50
|
+
readonly internalType: "bytes32";
|
|
20
51
|
readonly name: "schema_id";
|
|
52
|
+
readonly type: "bytes32";
|
|
53
|
+
}, {
|
|
54
|
+
readonly internalType: "bytes32";
|
|
55
|
+
readonly name: "name_hash";
|
|
56
|
+
readonly type: "bytes32";
|
|
57
|
+
}];
|
|
58
|
+
readonly name: "getByHash";
|
|
59
|
+
readonly outputs: readonly [{
|
|
60
|
+
readonly internalType: "string";
|
|
61
|
+
readonly name: "";
|
|
62
|
+
readonly type: "string";
|
|
21
63
|
}];
|
|
22
|
-
readonly outputs: readonly [];
|
|
23
|
-
}, {
|
|
24
|
-
readonly name: "getManifest";
|
|
25
|
-
readonly type: "function";
|
|
26
64
|
readonly stateMutability: "view";
|
|
65
|
+
readonly type: "function";
|
|
66
|
+
}, {
|
|
27
67
|
readonly inputs: readonly [{
|
|
28
|
-
readonly
|
|
68
|
+
readonly internalType: "address";
|
|
29
69
|
readonly name: "owner";
|
|
70
|
+
readonly type: "address";
|
|
30
71
|
}, {
|
|
31
|
-
readonly
|
|
72
|
+
readonly internalType: "bytes32";
|
|
32
73
|
readonly name: "schema_id";
|
|
74
|
+
readonly type: "bytes32";
|
|
75
|
+
}, {
|
|
76
|
+
readonly internalType: "bytes32";
|
|
77
|
+
readonly name: "name_hash";
|
|
78
|
+
readonly type: "bytes32";
|
|
33
79
|
}];
|
|
80
|
+
readonly name: "getName";
|
|
34
81
|
readonly outputs: readonly [{
|
|
82
|
+
readonly internalType: "string";
|
|
83
|
+
readonly name: "";
|
|
35
84
|
readonly type: "string";
|
|
36
85
|
}];
|
|
37
|
-
}, {
|
|
38
|
-
readonly name: "getVersion";
|
|
39
|
-
readonly type: "function";
|
|
40
86
|
readonly stateMutability: "view";
|
|
87
|
+
readonly type: "function";
|
|
88
|
+
}, {
|
|
41
89
|
readonly inputs: readonly [{
|
|
42
|
-
readonly
|
|
90
|
+
readonly internalType: "address";
|
|
43
91
|
readonly name: "owner";
|
|
92
|
+
readonly type: "address";
|
|
44
93
|
}, {
|
|
45
|
-
readonly
|
|
94
|
+
readonly internalType: "bytes32";
|
|
46
95
|
readonly name: "schema_id";
|
|
96
|
+
readonly type: "bytes32";
|
|
97
|
+
}, {
|
|
98
|
+
readonly internalType: "string";
|
|
99
|
+
readonly name: "name";
|
|
100
|
+
readonly type: "string";
|
|
47
101
|
}];
|
|
102
|
+
readonly name: "getVersion";
|
|
48
103
|
readonly outputs: readonly [{
|
|
104
|
+
readonly internalType: "uint64";
|
|
105
|
+
readonly name: "";
|
|
49
106
|
readonly type: "uint64";
|
|
50
107
|
}];
|
|
108
|
+
readonly stateMutability: "view";
|
|
109
|
+
readonly type: "function";
|
|
51
110
|
}, {
|
|
52
|
-
readonly name: "ManifestPublished";
|
|
53
|
-
readonly type: "event";
|
|
54
111
|
readonly inputs: readonly [{
|
|
55
|
-
readonly
|
|
56
|
-
readonly name: "
|
|
57
|
-
readonly
|
|
112
|
+
readonly internalType: "string";
|
|
113
|
+
readonly name: "manifest_cid";
|
|
114
|
+
readonly type: "string";
|
|
58
115
|
}, {
|
|
59
|
-
readonly
|
|
116
|
+
readonly internalType: "bytes32";
|
|
60
117
|
readonly name: "schema_id";
|
|
61
|
-
readonly
|
|
118
|
+
readonly type: "bytes32";
|
|
62
119
|
}, {
|
|
120
|
+
readonly internalType: "string";
|
|
121
|
+
readonly name: "name";
|
|
63
122
|
readonly type: "string";
|
|
64
|
-
readonly name: "manifest_cid";
|
|
65
123
|
}, {
|
|
66
|
-
readonly
|
|
67
|
-
readonly name: "
|
|
124
|
+
readonly internalType: "uint256";
|
|
125
|
+
readonly name: "price";
|
|
126
|
+
readonly type: "uint256";
|
|
68
127
|
}];
|
|
128
|
+
readonly name: "publish";
|
|
129
|
+
readonly outputs: readonly [];
|
|
130
|
+
readonly stateMutability: "nonpayable";
|
|
131
|
+
readonly type: "function";
|
|
69
132
|
}, {
|
|
70
|
-
readonly
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
133
|
+
readonly inputs: readonly [{
|
|
134
|
+
readonly internalType: "address";
|
|
135
|
+
readonly name: "owner";
|
|
136
|
+
readonly type: "address";
|
|
137
|
+
}, {
|
|
138
|
+
readonly internalType: "bytes32";
|
|
139
|
+
readonly name: "schema_id";
|
|
140
|
+
readonly type: "bytes32";
|
|
141
|
+
}, {
|
|
142
|
+
readonly internalType: "string";
|
|
143
|
+
readonly name: "name";
|
|
144
|
+
readonly type: "string";
|
|
145
|
+
}];
|
|
146
|
+
readonly name: "resourceId";
|
|
147
|
+
readonly outputs: readonly [{
|
|
148
|
+
readonly internalType: "bytes32";
|
|
149
|
+
readonly name: "";
|
|
150
|
+
readonly type: "bytes32";
|
|
151
|
+
}];
|
|
152
|
+
readonly stateMutability: "view";
|
|
153
|
+
readonly type: "function";
|
|
81
154
|
}];
|
|
82
155
|
//#endregion
|
|
83
156
|
export { DS_REGISTRY_ABI };
|