@dstorage-tech/dstorage-sdk 0.0.5 → 0.0.6

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 CHANGED
@@ -133,10 +133,14 @@ import { DStorage, ArweaveStorageAdapter } from "@dstorage-tech/dstorage-sdk";
133
133
  ```
134
134
 
135
135
  Bundlers configured for a browser target (Vite, webpack 5+, Rollup, esbuild) resolve the
136
- plain import to a pre-built, minified, browser-safe bundle automatically via the
137
- `"browser"` condition in `package.json`'s `exports` map it excludes all Node.js-only
138
- code (`node:fs`, LevelDB, etc.). For tooling that doesn't resolve conditional exports, or
139
- for explicit clarity, the same bundle is also available at the `/browser` subpath:
136
+ plain import to a pre-built, browser-safe bundle automatically via the `"browser"`
137
+ condition in `package.json`'s `exports` map. It is not minified — minification strips
138
+ the `/* @vite-ignore */` comments that tell a bundler to skip static analysis of
139
+ Node-only code paths (e.g. `MidnightChainAdapter`'s facade/provider mode, which
140
+ dynamically imports `fs` and LevelDB). Those Node-only paths are present in the bundle
141
+ but statically unreachable in connector mode. For tooling that doesn't resolve
142
+ conditional exports, or for explicit clarity, the same bundle is also available at the
143
+ `/browser` subpath:
140
144
 
141
145
  ```typescript
142
146
  import {
@@ -513,6 +517,20 @@ const adapter = await KeypairEncryptionAdapter.fromPassword(
513
517
 
514
518
  **Authenticated Encryption with Associated Data (AEAD)**. The Poly1305 tag covers the ciphertext. Any bit-flip in the on-chain encrypted pointer causes decryption to throw before the SDK ever attempts to fetch from storage.
515
519
 
520
+ **AAD context binding**. Beyond integrity, each ciphertext is bound to its _role and position_ via Additional Authenticated Data (AAD). The AAD is not encrypted — it is a plain label passed alongside the ciphertext — but the Poly1305 MAC covers it, so any mismatch causes decryption to fail. The SDK uses four distinct labels:
521
+
522
+ | Label | Value | Purpose |
523
+ | ---------- | ----------------------------- | ------------------------------------------------------------ |
524
+ | Payload | `"dstorage:payload:v1"` | Single-shot file uploads (non-chunked user content) |
525
+ | Manifest | `"dstorage:manifest:v1"` | The chunked upload manifest (distinct from user content) |
526
+ | Chunk | `"dstorage:chunk:v1:<i>/<n>"` | Each chunk in a chunked upload, bound to its index and total |
527
+ | Storage ID | `"dstorage:storageId:v1"` | The storage pointer encrypted on-chain |
528
+
529
+ This means a ciphertext produced for one role cannot be silently substituted into another. In particular:
530
+
531
+ - A storage gateway that reorders or swaps chunk blobs causes decryption to throw — the MAC was computed with a different index label.
532
+ - A user file whose plaintext happens to look like a manifest JSON cannot be misinterpreted as one — a payload ciphertext (encrypted with `"dstorage:payload:v1"`) will fail MAC verification when the SDK attempts to decrypt it as a manifest (with `"dstorage:manifest:v1"`). Manifest detection is cryptographic, not JSON-shape-based.
533
+
516
534
  ### Storage ID format
517
535
 
518
536
  The SDK treats `storageId` as an opaque string — the crypto layer encrypts its UTF-8 bytes (see [Wire formats](#wire-formats) above), so there is no length or format requirement at the SDK level. Today's Arweave-family adapters (`ArweaveStorageAdapter`, `ArweaveLocalStorageAdapter`, `ArweaveBundlerStorageAdapter`) all return 43-character base64url strings — 32 random bytes encoded without padding, matching the Arweave transaction ID format — but a storage adapter for a different network (e.g. an IPFS CID or another content-addressed ID) can return any string shape without requiring changes to the encryption layer.
@@ -1949,170 +1949,6 @@ declare const METADATA_ONLY_OWNER_SECRET_SALT: Uint8Array;
1949
1949
  */
1950
1950
  declare const chunkAad: (index: number, total: number) => Uint8Array;
1951
1951
 
1952
- /**
1953
- * @dstorage/core — metaTx/types.ts
1954
- *
1955
- * All public interfaces and type aliases for the MetaTx orchestrator.
1956
- */
1957
-
1958
- type MetaTxStepId = "estimate" | "encrypt" | "payment_storage" | "upload" | "chain_reference" | "complete";
1959
- type MetaTxStepStatus = "pending" | "running" | "done" | "error";
1960
- interface MetaTxStepState {
1961
- id: MetaTxStepId;
1962
- label: string;
1963
- description: string;
1964
- status: MetaTxStepStatus;
1965
- /** Live detail message updated during the step */
1966
- detail?: string;
1967
- /** Duration in ms (set when done) */
1968
- durationMs?: number;
1969
- startedAt?: number;
1970
- }
1971
- interface MetaTxProgress {
1972
- steps: MetaTxStepState[];
1973
- currentStepId: MetaTxStepId | null;
1974
- overallStatus: "idle" | "awaiting_confirmation" | "running" | "complete" | "error";
1975
- /** Cost estimate — set after 'estimate' step completes */
1976
- estimate?: CostEstimate;
1977
- /** Final receipt — set when complete */
1978
- receipt?: MetaTxReceipt;
1979
- /** Error message if overallStatus is 'error' */
1980
- error?: string;
1981
- }
1982
- interface MetaTxReceipt {
1983
- dataId: string;
1984
- storageId: string;
1985
- /** Undefined when no chain adapter is configured (storage-only mode). */
1986
- chainRefId?: string;
1987
- /** Original file info */
1988
- file: {
1989
- name: string;
1990
- type: string;
1991
- sizeBytes: number;
1992
- };
1993
- /** Payment receipts */
1994
- storagePayment: PaymentReceipt;
1995
- /** Undefined when no chain adapter is configured. */
1996
- chainPayment?: PaymentReceipt;
1997
- /** Tokens used */
1998
- storageToken: TokenSymbol;
1999
- /** Undefined when no chain adapter is configured. */
2000
- chainToken?: TokenSymbol;
2001
- /** Contract invoked (if selected) */
2002
- contract?: {
2003
- address: string;
2004
- name: string;
2005
- };
2006
- completedAt: number;
2007
- /** Duration of the full meta-transaction in ms */
2008
- totalDurationMs: number;
2009
- }
2010
- interface MetaTxConfig {
2011
- /** Optional metadata to attach to the on-chain reference */
2012
- metadata?: Record<string, string>;
2013
- /** Selected contract address (from the contract registry) */
2014
- contractAddress?: string;
2015
- /** Selected contract name (for display / receipt) */
2016
- contractName?: string;
2017
- }
2018
- /**
2019
- * Crypto materials for a single upload: a fresh random DEK wrapped in a
2020
- * key envelope, ready to encrypt payload and storageId.
2021
- *
2022
- * For private uploads: uploadScheme encrypts content; dek is the per-upload
2023
- * Data Encryption Key used both to encrypt content AND to derive
2024
- * ownerSecret = HKDF(dek, rawStorageId). Any KEK holder can re-derive the
2025
- * ownerSecret by unwrapping the envelope DEK.
2026
- * For public uploads: uploadScheme is null; ownerSeed is a random secret wrapped
2027
- * under every KEK in keyEnvelope, and ownerSecret = HKDF(ownerSeed, rawStorageId).
2028
- * Any single KEK holder can re-derive the ownerSecret by unwrapping the envelope.
2029
- */
2030
- interface UploadCrypto {
2031
- /** XChaChaScheme built from a fresh random DEK. null for public uploads. */
2032
- uploadScheme: CryptoScheme | null;
2033
- /** JSON-encoded KeyEnvelope wrapping the DEK (private) or ownerSeed (public) under every KEK. */
2034
- keyEnvelope: string;
2035
- /** Encryption scheme identifier to record on-chain. "" for public uploads. */
2036
- encryptionScheme: EncryptionScheme;
2037
- /**
2038
- * The raw per-upload DEK for private uploads; undefined for public uploads.
2039
- * Used by MetaTx to derive ownerSecret = HKDF(dek, rawStorageId) after upload.
2040
- * Not stored anywhere — must not be persisted.
2041
- */
2042
- dek?: Uint8Array;
2043
- /**
2044
- * The raw ownerSeed for public uploads; undefined for private uploads.
2045
- * Used by MetaTx to derive ownerSecret = HKDF(ownerSeed, rawStorageId) after upload.
2046
- * Not stored anywhere — must not be persisted.
2047
- */
2048
- ownerSeed?: Uint8Array;
2049
- }
2050
- /**
2051
- * Minimal SDK surface required by MetaTx.
2052
- * Implemented by DStorage — MetaTx receives the SDK instance directly
2053
- * rather than individual adapters/keys/address to avoid redundant constructor args.
2054
- */
2055
- interface DStorageContext {
2056
- readonly storageAdapter: StorageAdapter;
2057
- readonly chainAdapter: ChainAdapter | undefined;
2058
- /** Wallet address of the connected user, or null if using init() / facade mode. */
2059
- readonly connectedAddress: string | null;
2060
- /**
2061
- * Generate a fresh random DEK, wrap it under the KEK, and return the
2062
- * upload crypto materials needed to encrypt payload and storageId.
2063
- * @param isPublic Pass true to skip encryption (returns null scheme + no envelope).
2064
- */
2065
- prepareUploadCrypto(isPublic?: boolean): Promise<UploadCrypto>;
2066
- /** Estimate the full cost (storage + chain) for a given payload size. */
2067
- estimateCost(sizeBytes: number): Promise<CostEstimate>;
2068
- }
2069
-
2070
- /**
2071
- * @dstorage/core — metaTx/utils.ts
2072
- *
2073
- * Helpers used internally by MetaTx and one exported utility.
2074
- */
2075
-
2076
- /**
2077
- * Return the default chain payment token for a given chain provider name.
2078
- */
2079
- declare function defaultChainToken(chainProvider: string): TokenSymbol;
2080
-
2081
- /**
2082
- * @dstorage/core — metaTx/MetaTx.ts
2083
- *
2084
- * The MetaTx orchestrator.
2085
- *
2086
- * Presents a single conceptual action to the user while internally executing:
2087
- * [0] Estimate → compute storage + chain costs
2088
- * [1] Encrypt → XChaCha20-Poly1305 encrypt the file client-side
2089
- * [2] PayStorage → simulate storage payment (AR / MOCK)
2090
- * [3] Upload → upload encrypted blob to decentralised storage
2091
- * [4] Reference → pay chain fee + write CID + metadata reference on-chain
2092
- * [✓] Complete → return full receipt
2093
- *
2094
- * Usage:
2095
- * const metaTx = new MetaTx(dStorage);
2096
- * metaTx.onProgress((progress) => updateUI(progress));
2097
- * const receipt = await metaTx.execute(file);
2098
- */
2099
-
2100
- declare class MetaTx {
2101
- private sdk;
2102
- private progressCallback;
2103
- private steps;
2104
- private startedAt;
2105
- constructor(sdk: DStorageContext);
2106
- /** Register a progress listener. Called after every step state change. */
2107
- onProgress(cb: (progress: MetaTxProgress) => void): this;
2108
- execute(file: File, config?: MetaTxConfig): Promise<MetaTxReceipt>;
2109
- private startStep;
2110
- private updateStepDetail;
2111
- private completeStep;
2112
- private getStep;
2113
- private emit;
2114
- }
2115
-
2116
1952
  /**
2117
1953
  * @dstorage/core — dStorage.ts
2118
1954
  *
@@ -2131,7 +1967,7 @@ declare class MetaTx {
2131
1967
  * await ds.removeReference(chainRefId);
2132
1968
  */
2133
1969
 
2134
- declare class DStorage implements DStorageContext {
1970
+ declare class DStorage {
2135
1971
  private config;
2136
1972
  private wallet;
2137
1973
  /** Encryption adapters — each wraps/unwraps per-upload DEKs using its own algorithm. */
@@ -2288,26 +2124,6 @@ declare class DStorage implements DStorageContext {
2288
2124
  * Estimate the full cost (storage + chain) for a given payload size before committing.
2289
2125
  */
2290
2126
  estimateCost(sizeBytes: number): Promise<CostEstimate>;
2291
- /**
2292
- * Execute a full meta-transaction for a file:
2293
- * estimate → encrypt → pay storage → upload → pay chain → write reference
2294
- *
2295
- * Presents the entire flow as a single action with step-by-step progress.
2296
- *
2297
- * @param file The File to encrypt and store
2298
- * @param onProgress Callback fired on every step state change
2299
- * @param config Optional token overrides and metadata
2300
- */
2301
- executeMetaTransaction(file: File, onProgress: (progress: MetaTxProgress) => void, config?: MetaTxConfig): Promise<MetaTxReceipt>;
2302
- /**
2303
- * Generate a fresh random DEK, wrap it under the KEK(s), and return the crypto
2304
- * materials needed by MetaTx to encrypt payload and storageId.
2305
- *
2306
- * For private stores: the DEK is wrapped under every available KEK. The ownerSecret
2307
- * can later be re-derived as HKDF(dek, rawStorageId) by any KEK holder.
2308
- * For public stores: a random ownerSeed is generated and wrapped under all KEKs (same pattern).
2309
- */
2310
- prepareUploadCrypto(isPublic?: boolean): Promise<UploadCrypto>;
2311
2127
  /**
2312
2128
  * Upload large content by splitting into CHUNK_SIZE pieces, encrypting each
2313
2129
  * independently, and storing a manifest that ties them together.
@@ -2391,8 +2207,6 @@ declare const CoreErrorCode: {
2391
2207
  readonly LIST_REFS_NOT_SUPPORTED: 10061;
2392
2208
  readonly REMOVE_REF_REQUIRES_CHAIN: 10070;
2393
2209
  readonly REMOVE_REF_NOT_SUPPORTED: 10071;
2394
- readonly META_TX_REQUIRES_ENCRYPTION: 10080;
2395
- readonly PREPARE_UPLOAD_NO_PROVIDERS: 10081;
2396
2210
  readonly MANIFEST_INVALID_STRUCTURE: 10090;
2397
2211
  readonly MANIFEST_CHUNK_COUNT_MISMATCH: 10091;
2398
2212
  readonly MANIFEST_NOT_CONTIGUOUS: 10092;
@@ -2400,7 +2214,6 @@ declare const CoreErrorCode: {
2400
2214
  readonly CHUNK_OVERFLOWS_TOTAL_SIZE: 10094;
2401
2215
  readonly REASSEMBLY_SIZE_MISMATCH: 10095;
2402
2216
  readonly NOT_INITIALIZED: 10100;
2403
- readonly META_TX_UNKNOWN_STEP: 10200;
2404
2217
  readonly UNKNOWN_ERROR: 10999;
2405
2218
  };
2406
2219
  type CoreErrorCode = (typeof CoreErrorCode)[keyof typeof CoreErrorCode];
@@ -2415,4 +2228,4 @@ declare class StorePartialError extends DStorageError {
2415
2228
  }
2416
2229
  declare function isStorePartialError(err: unknown): err is StorePartialError;
2417
2230
 
2418
- export { ARWEAVE_LOCAL, type ArweaveBundlerAdapterConfig, ArweaveBundlerStorageAdapter, type ArweaveLocalAdapterConfig, type ArweaveLocalBalance, ArweaveLocalError, ArweaveLocalHelper, type ArweaveLocalHelperConfig, type ArweaveLocalInfo, ArweaveLocalStorageAdapter, ArweavePaymentAdapter, ArweaveStorageAdapter, CHUNK_SIZE, type ChunkEntry, type ChunkManifest, CoreErrorCode, type CostEstimate, CryptoErrorCode, type CryptoScheme, DStorage, type DStorageConfig, type DStorageContext, DStorageError, type EncryptionAdapter, EncryptionErrorCode, type EncryptionScheme, type FromKdfParamsConfig, KDF_PRESETS, type KdfPreset, KeyDeriver, type KeyEnvelope, type KeyWrapper, KeypairEncryptionAdapter, type ListReferencesOptions, type Logger, MANIFEST_AAD, METADATA_AAD, METADATA_ONLY_OWNER_SECRET_SALT, type MLKemVariant, ManagedPaymentAdapter, MetaTx, type MetaTxConfig, type MetaTxProgress, type MetaTxReceipt, type MetaTxStepId, type MetaTxStepState, type MetaTxStepStatus, MnemonicEncryptionAdapter, PAYLOAD_AAD, PasswordEncryptionAdapter, type PasswordEncryptionAdapterConfig, type RegisterReferenceOptions, type RegisterReferenceResult, type RetrieveResult, type StoreOptions, StorePartialError, type StoreProgress, type StoreRecovery, type StoreResult, type StoredKdfParams, type UpdateResult, type UploadCrypto, type WalletInfo, type WrappedDekResult, type XChaChaPayload, XChaChaScheme, arlocalGateway, base64urlToBytes, buildKeyEnvelope, bytesToBase64url, chunkAad, computeBlake3, computeBlake3Hex, decryptStorageIdXChaCha, decryptXChaCha, defaultChainToken, deriveKek, deriveOwnerSecret, deriveSymmetricKeyFromSeed, deserializeXChaChaPayload, encryptStorageIdXChaCha, encryptXChaCha, findWrapper, generateDek, generatePqsPassword, hexToBytes, isDStorageError, isManifest, isStorePartialError, mlkemGenerateKeypair, mlkemGenerateKeypairFromSeed, mlkemUnwrapDek, mlkemWrapDek, parseKeyEnvelope, serializeKeyEnvelope, serializeXChaChaPayload, unwrapKey, wrapKey };
2231
+ export { ARWEAVE_LOCAL, type ArweaveBundlerAdapterConfig, ArweaveBundlerStorageAdapter, type ArweaveLocalAdapterConfig, type ArweaveLocalBalance, ArweaveLocalError, ArweaveLocalHelper, type ArweaveLocalHelperConfig, type ArweaveLocalInfo, ArweaveLocalStorageAdapter, ArweavePaymentAdapter, ArweaveStorageAdapter, CHUNK_SIZE, type ChunkEntry, type ChunkManifest, CoreErrorCode, type CostEstimate, CryptoErrorCode, type CryptoScheme, DStorage, type DStorageConfig, DStorageError, type EncryptionAdapter, EncryptionErrorCode, type EncryptionScheme, type FromKdfParamsConfig, KDF_PRESETS, type KdfPreset, KeyDeriver, type KeyEnvelope, type KeyWrapper, KeypairEncryptionAdapter, type ListReferencesOptions, type Logger, MANIFEST_AAD, METADATA_AAD, METADATA_ONLY_OWNER_SECRET_SALT, type MLKemVariant, ManagedPaymentAdapter, MnemonicEncryptionAdapter, PAYLOAD_AAD, PasswordEncryptionAdapter, type PasswordEncryptionAdapterConfig, type RegisterReferenceOptions, type RegisterReferenceResult, type RetrieveResult, type StoreOptions, StorePartialError, type StoreProgress, type StoreRecovery, type StoreResult, type StoredKdfParams, type UpdateResult, type WalletInfo, type WrappedDekResult, type XChaChaPayload, XChaChaScheme, arlocalGateway, base64urlToBytes, buildKeyEnvelope, bytesToBase64url, chunkAad, computeBlake3, computeBlake3Hex, decryptStorageIdXChaCha, decryptXChaCha, deriveKek, deriveOwnerSecret, deriveSymmetricKeyFromSeed, deserializeXChaChaPayload, encryptStorageIdXChaCha, encryptXChaCha, findWrapper, generateDek, generatePqsPassword, hexToBytes, isDStorageError, isManifest, isStorePartialError, mlkemGenerateKeypair, mlkemGenerateKeypairFromSeed, mlkemUnwrapDek, mlkemWrapDek, parseKeyEnvelope, serializeKeyEnvelope, serializeXChaChaPayload, unwrapKey, wrapKey };