@fluxpointstudios/orynq-sdk-storage-adapters 0.1.0

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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/dist/adapters/arweave/arweave-adapter.d.ts +52 -0
  3. package/dist/adapters/arweave/arweave-adapter.d.ts.map +1 -0
  4. package/dist/adapters/arweave/arweave-adapter.js +200 -0
  5. package/dist/adapters/arweave/arweave-adapter.js.map +1 -0
  6. package/dist/adapters/arweave/index.d.ts +2 -0
  7. package/dist/adapters/arweave/index.d.ts.map +1 -0
  8. package/dist/adapters/arweave/index.js +2 -0
  9. package/dist/adapters/arweave/index.js.map +1 -0
  10. package/dist/adapters/ipfs/index.d.ts +3 -0
  11. package/dist/adapters/ipfs/index.d.ts.map +1 -0
  12. package/dist/adapters/ipfs/index.js +3 -0
  13. package/dist/adapters/ipfs/index.js.map +1 -0
  14. package/dist/adapters/ipfs/ipfs-adapter.d.ts +51 -0
  15. package/dist/adapters/ipfs/ipfs-adapter.d.ts.map +1 -0
  16. package/dist/adapters/ipfs/ipfs-adapter.js +186 -0
  17. package/dist/adapters/ipfs/ipfs-adapter.js.map +1 -0
  18. package/dist/adapters/ipfs/pinning-service.d.ts +68 -0
  19. package/dist/adapters/ipfs/pinning-service.d.ts.map +1 -0
  20. package/dist/adapters/ipfs/pinning-service.js +249 -0
  21. package/dist/adapters/ipfs/pinning-service.js.map +1 -0
  22. package/dist/adapters/s3/index.d.ts +2 -0
  23. package/dist/adapters/s3/index.d.ts.map +1 -0
  24. package/dist/adapters/s3/index.js +2 -0
  25. package/dist/adapters/s3/index.js.map +1 -0
  26. package/dist/adapters/s3/s3-adapter.d.ts +79 -0
  27. package/dist/adapters/s3/s3-adapter.d.ts.map +1 -0
  28. package/dist/adapters/s3/s3-adapter.js +275 -0
  29. package/dist/adapters/s3/s3-adapter.js.map +1 -0
  30. package/dist/index.d.ts +40 -0
  31. package/dist/index.d.ts.map +1 -0
  32. package/dist/index.js +43 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/types.d.ts +182 -0
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +27 -0
  37. package/dist/types.js.map +1 -0
  38. package/dist/utils/content-addressing.d.ts +50 -0
  39. package/dist/utils/content-addressing.d.ts.map +1 -0
  40. package/dist/utils/content-addressing.js +101 -0
  41. package/dist/utils/content-addressing.js.map +1 -0
  42. package/dist/utils/index.d.ts +3 -0
  43. package/dist/utils/index.d.ts.map +1 -0
  44. package/dist/utils/index.js +3 -0
  45. package/dist/utils/index.js.map +1 -0
  46. package/dist/utils/replication.d.ts +64 -0
  47. package/dist/utils/replication.d.ts.map +1 -0
  48. package/dist/utils/replication.js +217 -0
  49. package/dist/utils/replication.js.map +1 -0
  50. package/package.json +68 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * PoI Storage Adapters
3
+ *
4
+ * Content-addressed storage backends for PoI SDK.
5
+ * Supports IPFS, S3, and Arweave.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { IpfsAdapter, S3Adapter, ReplicatedStorageAdapter } from '@fluxpointstudios/orynq-sdk-storage-adapters';
10
+ *
11
+ * // Single adapter usage
12
+ * const ipfs = new IpfsAdapter({
13
+ * gateway: 'https://ipfs.io',
14
+ * pinningService: {
15
+ * name: 'pinata',
16
+ * apiKey: process.env.PINATA_API_KEY!,
17
+ * },
18
+ * });
19
+ *
20
+ * const ref = await ipfs.store(data);
21
+ * console.log('Stored at:', ref.uri);
22
+ *
23
+ * // Replication across multiple backends
24
+ * const replicated = new ReplicatedStorageAdapter({
25
+ * adapters: [ipfsAdapter, s3Adapter],
26
+ * strategy: 'all',
27
+ * });
28
+ *
29
+ * const ref = await replicated.store(data);
30
+ * ```
31
+ *
32
+ * @packageDocumentation
33
+ */
34
+ export type { StorageType, StorageRef, StorableManifest, StorageAdapter, IpfsAdapterConfig, PinningServiceConfig, S3AdapterConfig, ArweaveAdapterConfig, ArweaveWallet, BundlrConfig, ReplicationConfig, } from "./types.js";
35
+ export { StorageError, StorageException } from "./types.js";
36
+ export { IpfsAdapter, createIpfsAdapter, type PinningService, PinataPinningService, InfuraPinningService, Web3StoragePinningService, createPinningService, } from "./adapters/ipfs/index.js";
37
+ export { S3Adapter, createS3Adapter, type S3Client, } from "./adapters/s3/index.js";
38
+ export { ArweaveAdapter, createArweaveAdapter, } from "./adapters/arweave/index.js";
39
+ export { sha256, sha256Raw, contentId, validateContentHash, parseIpfsCid, parseArweaveId, parseS3Key, buildStorageUri, HASH_DOMAIN_PREFIXES, type HashDomain, ReplicatedStorageAdapter, } from "./utils/index.js";
40
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAGH,YAAY,EACV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAG5D,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,KAAK,cAAc,EACnB,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,SAAS,EACT,eAAe,EACf,KAAK,QAAQ,GACd,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,cAAc,EACd,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,KAAK,UAAU,EACf,wBAAwB,GACzB,MAAM,kBAAkB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,43 @@
1
+ /**
2
+ * PoI Storage Adapters
3
+ *
4
+ * Content-addressed storage backends for PoI SDK.
5
+ * Supports IPFS, S3, and Arweave.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { IpfsAdapter, S3Adapter, ReplicatedStorageAdapter } from '@fluxpointstudios/orynq-sdk-storage-adapters';
10
+ *
11
+ * // Single adapter usage
12
+ * const ipfs = new IpfsAdapter({
13
+ * gateway: 'https://ipfs.io',
14
+ * pinningService: {
15
+ * name: 'pinata',
16
+ * apiKey: process.env.PINATA_API_KEY!,
17
+ * },
18
+ * });
19
+ *
20
+ * const ref = await ipfs.store(data);
21
+ * console.log('Stored at:', ref.uri);
22
+ *
23
+ * // Replication across multiple backends
24
+ * const replicated = new ReplicatedStorageAdapter({
25
+ * adapters: [ipfsAdapter, s3Adapter],
26
+ * strategy: 'all',
27
+ * });
28
+ *
29
+ * const ref = await replicated.store(data);
30
+ * ```
31
+ *
32
+ * @packageDocumentation
33
+ */
34
+ export { StorageError, StorageException } from "./types.js";
35
+ // === IPFS Adapter ===
36
+ export { IpfsAdapter, createIpfsAdapter, PinataPinningService, InfuraPinningService, Web3StoragePinningService, createPinningService, } from "./adapters/ipfs/index.js";
37
+ // === S3 Adapter ===
38
+ export { S3Adapter, createS3Adapter, } from "./adapters/s3/index.js";
39
+ // === Arweave Adapter ===
40
+ export { ArweaveAdapter, createArweaveAdapter, } from "./adapters/arweave/index.js";
41
+ // === Utilities ===
42
+ export { sha256, sha256Raw, contentId, validateContentHash, parseIpfsCid, parseArweaveId, parseS3Key, buildStorageUri, HASH_DOMAIN_PREFIXES, ReplicatedStorageAdapter, } from "./utils/index.js";
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAiBH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE5D,uBAAuB;AACvB,OAAO,EACL,WAAW,EACX,iBAAiB,EAEjB,oBAAoB,EACpB,oBAAoB,EACpB,yBAAyB,EACzB,oBAAoB,GACrB,MAAM,0BAA0B,CAAC;AAElC,qBAAqB;AACrB,OAAO,EACL,SAAS,EACT,eAAe,GAEhB,MAAM,wBAAwB,CAAC;AAEhC,0BAA0B;AAC1B,OAAO,EACL,cAAc,EACd,oBAAoB,GACrB,MAAM,6BAA6B,CAAC;AAErC,oBAAoB;AACpB,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,UAAU,EACV,eAAe,EACf,oBAAoB,EAEpB,wBAAwB,GACzB,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Types for storage adapters.
3
+ */
4
+ export type StorageType = "local" | "ipfs" | "s3" | "arweave";
5
+ export interface StorageRef {
6
+ type: StorageType;
7
+ uri: string;
8
+ hash: string;
9
+ size: number;
10
+ }
11
+ /**
12
+ * Minimal manifest interface for storage operations.
13
+ * Compatible with ManifestV2 from flight-recorder.
14
+ */
15
+ export interface StorableManifest {
16
+ formatVersion: string;
17
+ sessionId: string;
18
+ manifestHash?: string;
19
+ [key: string]: unknown;
20
+ }
21
+ export interface StorageAdapter {
22
+ readonly type: StorageType;
23
+ /**
24
+ * Store raw data.
25
+ */
26
+ store(data: Uint8Array): Promise<StorageRef>;
27
+ /**
28
+ * Store a manifest.
29
+ */
30
+ storeManifest(manifest: StorableManifest): Promise<StorageRef>;
31
+ /**
32
+ * Fetch data by reference.
33
+ */
34
+ fetch(ref: StorageRef): Promise<Uint8Array>;
35
+ /**
36
+ * Fetch a manifest by reference.
37
+ */
38
+ fetchManifest(ref: StorageRef): Promise<StorableManifest>;
39
+ /**
40
+ * Verify data integrity.
41
+ */
42
+ verify(ref: StorageRef): Promise<boolean>;
43
+ /**
44
+ * Delete data (optional).
45
+ */
46
+ delete?(ref: StorageRef): Promise<void>;
47
+ /**
48
+ * Pin data for persistence (optional).
49
+ */
50
+ pin?(ref: StorageRef): Promise<void>;
51
+ }
52
+ export interface IpfsAdapterConfig {
53
+ /**
54
+ * IPFS gateway URL for reading (e.g., "https://ipfs.io").
55
+ */
56
+ gateway: string;
57
+ /**
58
+ * IPFS API endpoint for writing (e.g., "http://localhost:5001").
59
+ * Required for storing data.
60
+ */
61
+ apiEndpoint?: string;
62
+ /**
63
+ * Pinning service configuration.
64
+ */
65
+ pinningService?: PinningServiceConfig;
66
+ /**
67
+ * Request timeout in milliseconds.
68
+ */
69
+ timeoutMs?: number;
70
+ }
71
+ export interface PinningServiceConfig {
72
+ name: "pinata" | "infura" | "web3.storage" | "custom";
73
+ apiKey: string;
74
+ apiSecret?: string;
75
+ endpoint?: string;
76
+ }
77
+ export interface S3AdapterConfig {
78
+ /**
79
+ * S3 bucket name.
80
+ */
81
+ bucket: string;
82
+ /**
83
+ * AWS region.
84
+ */
85
+ region: string;
86
+ /**
87
+ * Optional prefix for all keys.
88
+ */
89
+ prefix?: string;
90
+ /**
91
+ * AWS credentials.
92
+ */
93
+ credentials?: {
94
+ accessKeyId: string;
95
+ secretAccessKey: string;
96
+ };
97
+ /**
98
+ * Custom endpoint (for S3-compatible services).
99
+ */
100
+ endpoint?: string;
101
+ /**
102
+ * Enable server-side encryption.
103
+ */
104
+ serverSideEncryption?: boolean;
105
+ /**
106
+ * Presigned URL expiry in seconds (default: 3600).
107
+ */
108
+ presignedUrlExpiry?: number;
109
+ }
110
+ export interface ArweaveAdapterConfig {
111
+ /**
112
+ * Arweave gateway URL (default: "https://arweave.net").
113
+ */
114
+ gateway?: string;
115
+ /**
116
+ * JWK wallet for signing transactions.
117
+ */
118
+ wallet?: ArweaveWallet;
119
+ /**
120
+ * Bundlr/Irys configuration for bundled uploads.
121
+ */
122
+ bundlr?: BundlrConfig;
123
+ /**
124
+ * Request timeout in milliseconds.
125
+ */
126
+ timeoutMs?: number;
127
+ }
128
+ export interface ArweaveWallet {
129
+ kty: string;
130
+ n: string;
131
+ e: string;
132
+ d?: string;
133
+ p?: string;
134
+ q?: string;
135
+ dp?: string;
136
+ dq?: string;
137
+ qi?: string;
138
+ }
139
+ export interface BundlrConfig {
140
+ url: string;
141
+ currency: "arweave" | "matic" | "ethereum";
142
+ providerUrl?: string;
143
+ }
144
+ export interface ReplicationConfig {
145
+ /**
146
+ * Storage adapters to replicate to.
147
+ */
148
+ adapters: StorageAdapter[];
149
+ /**
150
+ * Strategy for handling failures.
151
+ */
152
+ strategy: "all" | "any" | "quorum";
153
+ /**
154
+ * Minimum number of successful stores for quorum strategy.
155
+ */
156
+ quorum?: number;
157
+ /**
158
+ * Retry configuration.
159
+ */
160
+ retry?: {
161
+ maxAttempts: number;
162
+ delayMs: number;
163
+ backoffMultiplier: number;
164
+ };
165
+ }
166
+ export declare enum StorageError {
167
+ STORE_FAILED = 2001,
168
+ FETCH_FAILED = 2002,
169
+ NOT_FOUND = 2003,
170
+ VERIFICATION_FAILED = 2004,
171
+ DELETE_FAILED = 2005,
172
+ PIN_FAILED = 2006,
173
+ TIMEOUT = 2007,
174
+ INVALID_CONFIG = 2008,
175
+ REPLICATION_FAILED = 2009
176
+ }
177
+ export declare class StorageException extends Error {
178
+ readonly code: StorageError;
179
+ readonly cause?: Error | undefined;
180
+ constructor(code: StorageError, message: string, cause?: Error | undefined);
181
+ }
182
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC;AAE9D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,WAAW,CAAC;IAClB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,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AM,CAAC;CACtB;AAID,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,EAAE,cAAc,EAAE,CAAC;IAE3B;;OAEG;IACH,QAAQ,EAAE,KAAK,GAAG,KAAK,GAAG,QAAQ,CAAC;IAEnC;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,KAAK,CAAC,EAAE;QACN,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;QAChB,iBAAiB,EAAE,MAAM,CAAC;KAC3B,CAAC;CACH;AAID,oBAAY,YAAY;IACtB,YAAY,OAAO;IACnB,YAAY,OAAO;IACnB,SAAS,OAAO;IAChB,mBAAmB,OAAO;IAC1B,aAAa,OAAO;IACpB,UAAU,OAAO;IACjB,OAAO,OAAO;IACd,cAAc,OAAO;IACrB,kBAAkB,OAAO;CAC1B;AAED,qBAAa,gBAAiB,SAAQ,KAAK;aAEvB,IAAI,EAAE,YAAY;aAElB,KAAK,CAAC,EAAE,KAAK;gBAFb,IAAI,EAAE,YAAY,EAClC,OAAO,EAAE,MAAM,EACC,KAAK,CAAC,EAAE,KAAK,YAAA;CAKhC"}
package/dist/types.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Types for storage adapters.
3
+ */
4
+ // === Error Codes ===
5
+ export var StorageError;
6
+ (function (StorageError) {
7
+ StorageError[StorageError["STORE_FAILED"] = 2001] = "STORE_FAILED";
8
+ StorageError[StorageError["FETCH_FAILED"] = 2002] = "FETCH_FAILED";
9
+ StorageError[StorageError["NOT_FOUND"] = 2003] = "NOT_FOUND";
10
+ StorageError[StorageError["VERIFICATION_FAILED"] = 2004] = "VERIFICATION_FAILED";
11
+ StorageError[StorageError["DELETE_FAILED"] = 2005] = "DELETE_FAILED";
12
+ StorageError[StorageError["PIN_FAILED"] = 2006] = "PIN_FAILED";
13
+ StorageError[StorageError["TIMEOUT"] = 2007] = "TIMEOUT";
14
+ StorageError[StorageError["INVALID_CONFIG"] = 2008] = "INVALID_CONFIG";
15
+ StorageError[StorageError["REPLICATION_FAILED"] = 2009] = "REPLICATION_FAILED";
16
+ })(StorageError || (StorageError = {}));
17
+ export class StorageException extends Error {
18
+ code;
19
+ cause;
20
+ constructor(code, message, cause) {
21
+ super(message);
22
+ this.code = code;
23
+ this.cause = cause;
24
+ this.name = "StorageException";
25
+ }
26
+ }
27
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAmNH,sBAAsB;AAEtB,MAAM,CAAN,IAAY,YAUX;AAVD,WAAY,YAAY;IACtB,kEAAmB,CAAA;IACnB,kEAAmB,CAAA;IACnB,4DAAgB,CAAA;IAChB,gFAA0B,CAAA;IAC1B,oEAAoB,CAAA;IACpB,8DAAiB,CAAA;IACjB,wDAAc,CAAA;IACd,sEAAqB,CAAA;IACrB,8EAAyB,CAAA;AAC3B,CAAC,EAVW,YAAY,KAAZ,YAAY,QAUvB;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IAEvB;IAEA;IAHlB,YACkB,IAAkB,EAClC,OAAe,EACC,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJC,SAAI,GAAJ,IAAI,CAAc;QAElB,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Content-addressing utilities for storage.
3
+ */
4
+ /**
5
+ * Hash domain prefixes for content-addressed storage.
6
+ */
7
+ export declare const HASH_DOMAIN_PREFIXES: {
8
+ readonly chunk: "poi-storage:chunk:v1|";
9
+ readonly manifest: "poi-storage:manifest:v1|";
10
+ readonly data: "poi-storage:data:v1|";
11
+ };
12
+ export type HashDomain = keyof typeof HASH_DOMAIN_PREFIXES;
13
+ /**
14
+ * Compute SHA-256 hash with domain separation.
15
+ */
16
+ export declare function sha256(data: Uint8Array, domain?: HashDomain): string;
17
+ /**
18
+ * Compute SHA-256 hash without domain separation.
19
+ */
20
+ export declare function sha256Raw(data: Uint8Array): string;
21
+ /**
22
+ * Generate a content-addressed ID from data.
23
+ */
24
+ export declare function contentId(data: Uint8Array): string;
25
+ /**
26
+ * Validate that data matches a content hash.
27
+ */
28
+ export declare function validateContentHash(data: Uint8Array, expectedHash: string, domain?: HashDomain): boolean;
29
+ /**
30
+ * Parse an IPFS CID from a URI.
31
+ */
32
+ export declare function parseIpfsCid(uri: string): string | undefined;
33
+ /**
34
+ * Parse an Arweave transaction ID from a URI.
35
+ */
36
+ export declare function parseArweaveId(uri: string): string | undefined;
37
+ /**
38
+ * Parse an S3 key from a URI.
39
+ */
40
+ export declare function parseS3Key(uri: string): {
41
+ bucket: string;
42
+ key: string;
43
+ } | undefined;
44
+ /**
45
+ * Build a storage URI from components.
46
+ */
47
+ export declare function buildStorageUri(type: "ipfs" | "s3" | "arweave" | "local", id: string, options?: {
48
+ bucket?: string;
49
+ }): string;
50
+ //# sourceMappingURL=content-addressing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-addressing.d.ts","sourceRoot":"","sources":["../../src/utils/content-addressing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;CAIvB,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,oBAAoB,CAAC;AAE3D;;GAEG;AACH,wBAAgB,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,GAAE,UAAmB,GAAG,MAAM,CAS5E;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAElD;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,UAAU,EAChB,YAAY,EAAE,MAAM,EACpB,MAAM,GAAE,UAAmB,GAC1B,OAAO,CAGT;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG5D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG9D;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAsBnF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,EACzC,EAAE,EAAE,MAAM,EACV,OAAO,CAAC,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,GAC5B,MAAM,CAgBR"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Content-addressing utilities for storage.
3
+ */
4
+ import { createHash } from "node:crypto";
5
+ /**
6
+ * Hash domain prefixes for content-addressed storage.
7
+ */
8
+ export const HASH_DOMAIN_PREFIXES = {
9
+ chunk: "poi-storage:chunk:v1|",
10
+ manifest: "poi-storage:manifest:v1|",
11
+ data: "poi-storage:data:v1|",
12
+ };
13
+ /**
14
+ * Compute SHA-256 hash with domain separation.
15
+ */
16
+ export function sha256(data, domain = "data") {
17
+ const prefix = HASH_DOMAIN_PREFIXES[domain];
18
+ const prefixBytes = new TextEncoder().encode(prefix);
19
+ const combined = new Uint8Array(prefixBytes.length + data.length);
20
+ combined.set(prefixBytes, 0);
21
+ combined.set(data, prefixBytes.length);
22
+ return createHash("sha256").update(combined).digest("hex");
23
+ }
24
+ /**
25
+ * Compute SHA-256 hash without domain separation.
26
+ */
27
+ export function sha256Raw(data) {
28
+ return createHash("sha256").update(data).digest("hex");
29
+ }
30
+ /**
31
+ * Generate a content-addressed ID from data.
32
+ */
33
+ export function contentId(data) {
34
+ return sha256(data, "data");
35
+ }
36
+ /**
37
+ * Validate that data matches a content hash.
38
+ */
39
+ export function validateContentHash(data, expectedHash, domain = "data") {
40
+ const actualHash = sha256(data, domain);
41
+ return actualHash === expectedHash;
42
+ }
43
+ /**
44
+ * Parse an IPFS CID from a URI.
45
+ */
46
+ export function parseIpfsCid(uri) {
47
+ const match = uri.match(/ipfs:\/\/(\w+)/) ?? uri.match(/\/ipfs\/(\w+)/);
48
+ return match?.[1];
49
+ }
50
+ /**
51
+ * Parse an Arweave transaction ID from a URI.
52
+ */
53
+ export function parseArweaveId(uri) {
54
+ const match = uri.match(/ar:\/\/(\w+)/) ?? uri.match(/arweave\.net\/(\w+)/);
55
+ return match?.[1];
56
+ }
57
+ /**
58
+ * Parse an S3 key from a URI.
59
+ */
60
+ export function parseS3Key(uri) {
61
+ // s3://bucket/key/path
62
+ const s3Match = uri.match(/s3:\/\/([^\/]+)\/(.+)/);
63
+ if (s3Match) {
64
+ const bucket = s3Match[1];
65
+ const key = s3Match[2];
66
+ if (bucket !== undefined && key !== undefined) {
67
+ return { bucket, key };
68
+ }
69
+ }
70
+ // https://bucket.s3.region.amazonaws.com/key
71
+ const httpsMatch = uri.match(/https?:\/\/([^\.]+)\.s3\.[^\/]+\/(.+)/);
72
+ if (httpsMatch) {
73
+ const bucket = httpsMatch[1];
74
+ const key = httpsMatch[2];
75
+ if (bucket !== undefined && key !== undefined) {
76
+ return { bucket, key };
77
+ }
78
+ }
79
+ return undefined;
80
+ }
81
+ /**
82
+ * Build a storage URI from components.
83
+ */
84
+ export function buildStorageUri(type, id, options) {
85
+ switch (type) {
86
+ case "ipfs":
87
+ return `ipfs://${id}`;
88
+ case "arweave":
89
+ return `ar://${id}`;
90
+ case "s3":
91
+ if (options?.bucket) {
92
+ return `s3://${options.bucket}/${id}`;
93
+ }
94
+ return `s3://${id}`;
95
+ case "local":
96
+ return `file://${id}`;
97
+ default:
98
+ return id;
99
+ }
100
+ }
101
+ //# sourceMappingURL=content-addressing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-addressing.js","sourceRoot":"","sources":["../../src/utils/content-addressing.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,KAAK,EAAE,uBAAuB;IAC9B,QAAQ,EAAE,0BAA0B;IACpC,IAAI,EAAE,sBAAsB;CACpB,CAAC;AAIX;;GAEG;AACH,MAAM,UAAU,MAAM,CAAC,IAAgB,EAAE,SAAqB,MAAM;IAClE,MAAM,MAAM,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC5C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAErD,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;IAClE,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAC7B,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAEvC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC7D,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,SAAS,CAAC,IAAgB;IACxC,OAAO,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB,CACjC,IAAgB,EAChB,YAAoB,EACpB,SAAqB,M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AK,SAAS,EAAE,CAAC;YAC9C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC;QACzB,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAC7B,IAAyC,EACzC,EAAU,EACV,OAA6B;IAE7B,QAAQ,IAAI,EAAE,CAAC;QACb,KAAK,MAAM;YACT,OAAO,UAAU,EAAE,EAAE,CAAC;QACxB,KAAK,SAAS;YACZ,OAAO,QAAQ,EAAE,EAAE,CAAC;QACtB,KAAK,IAAI;YACP,IAAI,OAAO,EAAE,MAAM,EAAE,CAAC;gBACpB,OAAO,QAAQ,OAAO,CAAC,MAAM,IAAI,EAAE,EAAE,CAAC;YACxC,CAAC;YACD,OAAO,QAAQ,EAAE,EAAE,CAAC;QACtB,KAAK,OAAO;YACV,OAAO,UAAU,EAAE,EAAE,CAAC;QACxB;YACE,OAAO,EAAE,CAAC;IACd,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { sha256, sha256Raw, contentId, validateContentHash, parseIpfsCid, parseArweaveId, parseS3Key, buildStorageUri, HASH_DOMAIN_PREFIXES, type HashDomain, } from "./content-addressing.js";
2
+ export { ReplicatedStorageAdapter } from "./replication.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,UAAU,EACV,eAAe,EACf,oBAAoB,EACpB,KAAK,UAAU,GAChB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { sha256, sha256Raw, contentId, validateContentHash, parseIpfsCid, parseArweaveId, parseS3Key, buildStorageUri, HASH_DOMAIN_PREFIXES, } from "./content-addressing.js";
2
+ export { ReplicatedStorageAdapter } from "./replication.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,UAAU,EACV,eAAe,EACf,oBAAoB,GAErB,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Replication utility for storing data across multiple storage backends.
3
+ */
4
+ import type { StorageAdapter, StorageRef, StorableManifest, ReplicationConfig } from "../types.js";
5
+ export interface ReplicationResult {
6
+ success: boolean;
7
+ refs: StorageRef[];
8
+ errors: Array<{
9
+ adapter: string;
10
+ error: Error;
11
+ }>;
12
+ }
13
+ /**
14
+ * Storage adapter that replicates data across multiple backends.
15
+ */
16
+ export declare class ReplicatedStorageAdapter implements StorageAdapter {
17
+ readonly type: "local";
18
+ private readonly adapters;
19
+ private readonly strategy;
20
+ private readonly quorum;
21
+ private readonly retry;
22
+ constructor(config: ReplicationConfig);
23
+ /**
24
+ * Store data across all configured adapters.
25
+ */
26
+ store(data: Uint8Array): Promise<StorageRef>;
27
+ /**
28
+ * Store a manifest across all configured adapters.
29
+ */
30
+ storeManifest(manifest: StorableManifest): Promise<StorageRef>;
31
+ /**
32
+ * Fetch data from any adapter that has it.
33
+ */
34
+ fetch(ref: StorageRef): Promise<Uint8Array>;
35
+ /**
36
+ * Fetch a manifest from any adapter that has it.
37
+ */
38
+ fetchManifest(ref: StorageRef): Promise<StorableManifest>;
39
+ /**
40
+ * Verify data exists and is valid in at least one adapter.
41
+ */
42
+ verify(ref: StorageRef): Promise<boolean>;
43
+ /**
44
+ * Delete data from all adapters.
45
+ */
46
+ delete(ref: StorageRef): Promise<void>;
47
+ /**
48
+ * Pin data in all adapters that support pinning.
49
+ */
50
+ pin(ref: StorageRef): Promise<void>;
51
+ /**
52
+ * Get all storage references from a replication operation.
53
+ */
54
+ storeAll(data: Uint8Array): Promise<ReplicationResult>;
55
+ /**
56
+ * Store manifest to all adapters and return all references.
57
+ */
58
+ storeManifestAll(manifest: StorableManifest): Promise<ReplicationResult>;
59
+ private storeWithReplication;
60
+ private checkSuccess;
61
+ private retryOperation;
62
+ private sleep;
63
+ }
64
+ //# sourceMappingURL=replication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"replication.d.ts","sourceRoot":"","sources":["../../src/utils/replication.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,aAAa,CAAC;AAGrB,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,EAAE,UAAU,EAAE,CAAC;IACnB,MAAM,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,KAAK,CAAA;KAAE,CAAC,CAAC;CAClD;AAED;;GAEG;AACH,qBAAa,wBAAyB,YAAW,cAAc;IAC7D,QAAQ,CAAC,IAAI,EAAG,OAAO,CAAU;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAmB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA2B;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAIpB;gBAEU,MAAM,EAAE,iBAAiB;IAkBrC;;OAEG;IACG,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IAuBlD;;OAEG;IACG,aAAa,CAAC,QAAQ,EAAE,gBAAgB,GAAG,OAAO,CAAC,UAAU,CAAC;IAsBpE;;OAEG;IACG,KAAK,CAAC,GAAG,EAAE,UAAU,GAA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