@dstorage-tech/dstorage-sdk 0.0.6 → 0.0.8

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 (33) hide show
  1. package/dist/KeypairEncryptionAdapter-EOBRCIGP-5PFPNLLA.mjs +8 -0
  2. package/dist/{KeypairEncryptionAdapter-XUKCLRFU-AYDAZ2TZ.mjs → KeypairEncryptionAdapter-EOBRCIGP-FLPJIL26.mjs} +3 -3
  3. package/dist/{MnemonicEncryptionAdapter-RCHUETBP-M7NHGSHO.mjs → MnemonicEncryptionAdapter-S56YG63Q-B3F3TO3T.mjs} +3 -3
  4. package/dist/MnemonicEncryptionAdapter-S56YG63Q-POTD74UN.mjs +8 -0
  5. package/dist/{PasswordEncryptionAdapter-ECHND672-MUTHAMZY.mjs → PasswordEncryptionAdapter-B2UG7MWB-M4C3KJ4S.mjs} +3 -3
  6. package/dist/{PasswordEncryptionAdapter-ECHND672-3DEFO6FP.mjs → PasswordEncryptionAdapter-B2UG7MWB-QCSOIQJA.mjs} +3 -3
  7. package/dist/browser.d.mts +91 -8
  8. package/dist/browser.mjs +171 -67
  9. package/dist/{chunk-HDD6SUU4.mjs → chunk-42O7KEL4.mjs} +30 -11
  10. package/dist/{chunk-X4LEBNK6.mjs → chunk-5F3HZ2RJ.mjs} +30 -11
  11. package/dist/{chunk-6IAQVMSM.mjs → chunk-E73HFT6J.mjs} +5 -5
  12. package/dist/{chunk-UDYXMII2.mjs → chunk-EOPUNIUH.mjs} +5 -5
  13. package/dist/{chunk-O37NHERH.mjs → chunk-L6WCT64V.mjs} +4 -2
  14. package/dist/{chunk-4X5K43JF.mjs → chunk-M3F2LR3B.mjs} +3 -1
  15. package/dist/{chunk-JMPRZK5D.mjs → chunk-O6COTUD4.mjs} +3 -1
  16. package/dist/{chunk-BWLEAAFW.mjs → chunk-PCXBQRCO.mjs} +55 -2056
  17. package/dist/{chunk-OLGVVM5Y.mjs → chunk-QFJ2Y4XE.mjs} +5 -5
  18. package/dist/{chunk-Z6DUAI5B.mjs → chunk-XW4RZG2X.mjs} +5 -5
  19. package/dist/{contract-api-TJ7JPHZA-6FUBJ6DS.mjs → contract-api-NUY4UEKE-ZANT3ICG.mjs} +3 -3
  20. package/dist/{contract-api-AO4RGPLT-ENC72WCG.mjs → contract-api-P6YEDYQ6-2X6BMD64.mjs} +3 -3
  21. package/dist/{dist-INTAFXQ7.mjs → dist-AGNOIJI4.mjs} +3 -1
  22. package/dist/{dist-MOLWJ4Y7.mjs → dist-J4JUJ2J5.mjs} +3 -1
  23. package/dist/errors.d.mts +2 -0
  24. package/dist/errors.d.ts +2 -0
  25. package/dist/errors.js +10 -2054
  26. package/dist/errors.mjs +10 -2054
  27. package/dist/index.d.mts +108 -8
  28. package/dist/index.d.ts +108 -8
  29. package/dist/index.js +306 -2187
  30. package/dist/index.mjs +174 -70
  31. package/package.json +3 -2
  32. package/dist/KeypairEncryptionAdapter-XUKCLRFU-ERPYK5S4.mjs +0 -8
  33. package/dist/MnemonicEncryptionAdapter-RCHUETBP-DZPBGQG6.mjs +0 -8
@@ -0,0 +1,8 @@
1
+ import {
2
+ KeypairEncryptionAdapter
3
+ } from "./chunk-XW4RZG2X.mjs";
4
+ import "./chunk-L6WCT64V.mjs";
5
+ import "./chunk-PCXBQRCO.mjs";
6
+ export {
7
+ KeypairEncryptionAdapter
8
+ };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  KeypairEncryptionAdapter
3
- } from "./chunk-UDYXMII2.mjs";
4
- import "./chunk-O37NHERH.mjs";
5
- import "./chunk-BWLEAAFW.mjs";
3
+ } from "./chunk-EOPUNIUH.mjs";
4
+ import "./chunk-L6WCT64V.mjs";
5
+ import "./chunk-PCXBQRCO.mjs";
6
6
  import "./chunk-UJCSKKID.mjs";
7
7
  export {
8
8
  KeypairEncryptionAdapter
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  MnemonicEncryptionAdapter
3
- } from "./chunk-6IAQVMSM.mjs";
4
- import "./chunk-O37NHERH.mjs";
5
- import "./chunk-BWLEAAFW.mjs";
3
+ } from "./chunk-QFJ2Y4XE.mjs";
4
+ import "./chunk-L6WCT64V.mjs";
5
+ import "./chunk-PCXBQRCO.mjs";
6
6
  import "./chunk-UJCSKKID.mjs";
7
7
  export {
8
8
  MnemonicEncryptionAdapter
@@ -0,0 +1,8 @@
1
+ import {
2
+ MnemonicEncryptionAdapter
3
+ } from "./chunk-E73HFT6J.mjs";
4
+ import "./chunk-L6WCT64V.mjs";
5
+ import "./chunk-PCXBQRCO.mjs";
6
+ export {
7
+ MnemonicEncryptionAdapter
8
+ };
@@ -2,9 +2,9 @@ import {
2
2
  KDF_PRESETS,
3
3
  PasswordEncryptionAdapter,
4
4
  generatePqsPassword
5
- } from "./chunk-HDD6SUU4.mjs";
6
- import "./chunk-O37NHERH.mjs";
7
- import "./chunk-BWLEAAFW.mjs";
5
+ } from "./chunk-42O7KEL4.mjs";
6
+ import "./chunk-L6WCT64V.mjs";
7
+ import "./chunk-PCXBQRCO.mjs";
8
8
  export {
9
9
  KDF_PRESETS,
10
10
  PasswordEncryptionAdapter,
@@ -2,9 +2,9 @@ import {
2
2
  KDF_PRESETS,
3
3
  PasswordEncryptionAdapter,
4
4
  generatePqsPassword
5
- } from "./chunk-X4LEBNK6.mjs";
6
- import "./chunk-O37NHERH.mjs";
7
- import "./chunk-BWLEAAFW.mjs";
5
+ } from "./chunk-5F3HZ2RJ.mjs";
6
+ import "./chunk-L6WCT64V.mjs";
7
+ import "./chunk-PCXBQRCO.mjs";
8
8
  import "./chunk-UJCSKKID.mjs";
9
9
  export {
10
10
  KDF_PRESETS,
@@ -1,4 +1,4 @@
1
- import { PaymentAdapter, PaymentNetworkName, TokenSymbol, NetworkType, PaymentAdapterLogger, PaymentQuote, PaymentInstruction, PaymentReceipt, MidnightWalletProvider, StorageAdapterLogger, StorageAdapter, StorageProviderName, StorageUploadResult, StorageQuote, ChainAdapter, ChainProviderName, DataReferenceSummary } from './types.js';
1
+ import { PaymentAdapter, PaymentNetworkName, TokenSymbol, NetworkType, PaymentAdapterLogger, PaymentQuote, PaymentInstruction, PaymentReceipt, MidnightWalletProvider, StorageAdapterLogger, StorageAdapter, StorageProviderName, StorageUploadResult, RetrieveOptions, StorageQuote, ChainAdapter, ChainProviderName, DataReferenceSummary } from './types.js';
2
2
  export { MidnightWalletProvider, NetworkType, PaymentAdapter, PaymentAdapterLogger, PaymentNetworkName, PaymentQuote, PaymentReceipt, StorageAdapter, StorageAdapterLogger, StorageProviderName, StorageQuote, StorageUploadResult, TOKENS, Token, TokenSymbol } from './types.js';
3
3
  import Arweave from 'arweave';
4
4
  import Transaction from 'arweave/node/lib/transaction';
@@ -344,6 +344,12 @@ declare class ManagedPaymentAdapter extends ArweavePaymentAdapter {
344
344
  *
345
345
  * • storageId (txId) is PUBLIC on Arweave. Data security relies entirely on
346
346
  * the XChaCha20-Poly1305 encryption applied by @dstorage/crypto before reaching here.
347
+ *
348
+ * • retrieve()'s content-hash check only defends against a malicious gateway when
349
+ * called with an `expectedContentHash` anchor sourced independently of this
350
+ * gateway (see skipIntegrityCheck below) — @dstorage/core supplies this
351
+ * automatically from the on-chain reference. Without an anchor, the check falls
352
+ * back to a gateway-supplied tag and only catches non-adversarial corruption.
347
353
  */
348
354
 
349
355
  interface ArweaveGatewayConfig {
@@ -411,9 +417,17 @@ interface ArweaveAdapterConfig {
411
417
  confirmationTimeoutMs?: number;
412
418
  /**
413
419
  * When true, skip the BLAKE3 content-hash check on retrieve.
414
- * By default (false) the adapter fetches the transaction metadata and verifies
415
- * that the `X-Content-Hash` tag recorded at upload time matches the retrieved
416
- * bytes. Set to true only if you trust the gateway entirely or are using an
420
+ * By default (false) the adapter verifies retrieved bytes against a content hash.
421
+ * The strength of that guarantee depends on the hash's source:
422
+ * - When retrieve() is called with `options.expectedContentHash` (as
423
+ * `@dstorage/core` does automatically, from the on-chain ChainReference),
424
+ * verification is anchored to that chain-committed value and holds even
425
+ * against a fully malicious/colluding gateway.
426
+ * - Without an anchor, the adapter falls back to the `X-Content-Hash` tag
427
+ * fetched from this same gateway — that only catches non-adversarial
428
+ * corruption in transit, since a malicious gateway controls both the tag
429
+ * and the bytes and can make them consistent with each other.
430
+ * Set to true only if you trust the gateway entirely or are using an
417
431
  * Arweave node that does not expose the transaction metadata endpoint.
418
432
  */
419
433
  skipIntegrityCheck?: boolean;
@@ -448,7 +462,7 @@ declare class ArweaveStorageAdapter implements StorageAdapter {
448
462
  constructor(config?: ArweaveAdapterConfig);
449
463
  private getClient;
450
464
  store(data: Uint8Array, metadata?: Record<string, string>): Promise<StorageUploadResult>;
451
- retrieve(id: string): Promise<{
465
+ retrieve(id: string, options?: RetrieveOptions): Promise<{
452
466
  bytes: Uint8Array;
453
467
  tags: Record<string, string>;
454
468
  }>;
@@ -487,6 +501,11 @@ declare class ArweaveStorageAdapter implements StorageAdapter {
487
501
  *
488
502
  * ── Retrieve flow ─────────────────────────────────────────────────────────────
489
503
  * Standard Arweave gateway fetch (identical to ArweaveStorageAdapter.retrieve).
504
+ * Its content-hash check only defends against a malicious gateway when called
505
+ * with an `expectedContentHash` anchor sourced independently of this gateway
506
+ * (see skipIntegrityCheck below) — @dstorage/core supplies this automatically
507
+ * from the on-chain reference. Without an anchor, the check falls back to a
508
+ * gateway-supplied tag and only catches non-adversarial corruption.
490
509
  *
491
510
  * ── Peer dependency ───────────────────────────────────────────────────────────
492
511
  * No extra install needed — @dha-team/arbundles ships as a dependency of @ardrive/turbo-sdk.
@@ -539,10 +558,32 @@ interface ArweaveBundlerAdapterConfig {
539
558
  maxRetrieveSizeBytes?: number;
540
559
  /**
541
560
  * Skip BLAKE3 content-hash verification on retrieve.
561
+ * By default (false) the adapter verifies retrieved bytes against a content hash.
562
+ * The strength of that guarantee depends on the hash's source:
563
+ * - When retrieve() is called with `options.expectedContentHash` (as
564
+ * `@dstorage/core` does automatically, from the on-chain ChainReference),
565
+ * verification is anchored to that chain-committed value and holds even
566
+ * against a fully malicious/colluding gateway.
567
+ * - Without an anchor, the adapter falls back to the `X-Content-Hash` tag
568
+ * fetched from this same gateway — that only catches non-adversarial
569
+ * corruption in transit, since a malicious gateway controls both the tag
570
+ * and the bytes and can make them consistent with each other.
542
571
  * Only set to true when connecting to a fully trusted gateway.
543
- * Defaults to false.
544
572
  */
545
573
  skipIntegrityCheck?: boolean;
574
+ /**
575
+ * Maximum time in milliseconds to wait for any single retrieve() request
576
+ * (metadata or data fetch) before aborting. Defaults to 30_000 ms (30 s).
577
+ * Pass `0` to disable the timeout entirely (not recommended for production).
578
+ */
579
+ requestTimeoutMs?: number;
580
+ /**
581
+ * Maximum number of bytes allowed in the transaction metadata/tags JSON
582
+ * response fetched during retrieve(). Guards against a hostile or
583
+ * misbehaving gateway returning an oversized body to exhaust memory.
584
+ * Defaults to 1_048_576 (1 MiB) — metadata/tags are always tiny in practice.
585
+ */
586
+ maxMetadataResponseBytes?: number;
546
587
  /**
547
588
  * Optional logger for SDK operational output.
548
589
  */
@@ -571,12 +612,16 @@ declare class ArweaveBundlerStorageAdapter implements StorageAdapter {
571
612
  private readonly gateway;
572
613
  private readonly maxRetrieveSizeBytes;
573
614
  private readonly skipIntegrityCheck;
615
+ private readonly requestTimeoutMs;
616
+ private readonly maxMetadataResponseBytes;
574
617
  protected readonly logger: StorageAdapterLogger | undefined;
575
618
  /** RSA-4096 public key modulus (512 bytes) parsed from the auth token at construction time. */
576
619
  private readonly ownerPublicKey;
577
620
  constructor(config?: ArweaveBundlerAdapterConfig);
578
621
  store(data: Uint8Array, metadata?: Record<string, string>): Promise<StorageUploadResult>;
579
- retrieve(id: string): Promise<{
622
+ /** Adds an AbortSignal.timeout() to a fetch init object (when requestTimeoutMs > 0). */
623
+ private _withTimeout;
624
+ retrieve(id: string, options?: RetrieveOptions): Promise<{
580
625
  bytes: Uint8Array;
581
626
  tags: Record<string, string>;
582
627
  }>;
@@ -1333,6 +1378,34 @@ declare function computeBlake3(bytes: Uint8Array): Promise<Uint8Array>;
1333
1378
  /** BLAKE3 hash of `bytes`, returned as a 64-character lowercase hex string. */
1334
1379
  declare function computeBlake3Hex(bytes: Uint8Array): Promise<string>;
1335
1380
 
1381
+ /**
1382
+ * @dstorage/crypto — boundedFetch.ts
1383
+ * Shared helper for reading a fetch Response body with a hard size cap —
1384
+ * used by chain/storage HTTP adapters to avoid a hostile or misbehaving
1385
+ * gateway exhausting memory with an oversized response.
1386
+ */
1387
+ interface BoundedTextReadOptions {
1388
+ /** Maximum number of bytes/characters allowed in the response body. */
1389
+ maxBytes: number;
1390
+ /** Error code to throw (caller-owned, package-specific) when the cap is exceeded. */
1391
+ code: number;
1392
+ /** Prefix identifying the caller/operation in the thrown error message. */
1393
+ component: string;
1394
+ }
1395
+ /**
1396
+ * Reads a fetch Response body as text, aborting once the accumulated size
1397
+ * exceeds `maxBytes`.
1398
+ *
1399
+ * Uses a streaming reader when the Response exposes `.body` (always true for
1400
+ * real `fetch()` responses), so a gateway that omits or lies about
1401
+ * `Content-Length` (e.g. chunked transfer encoding) can't force an unbounded
1402
+ * read — the read is aborted as soon as the limit is crossed, before the
1403
+ * full body is buffered. Falls back to a single `.text()` read + post-hoc
1404
+ * length check only when `.body` is unavailable (e.g. non-streaming
1405
+ * environments or simple test doubles).
1406
+ */
1407
+ declare function readResponseTextWithLimit(res: Response, opts: BoundedTextReadOptions): Promise<string>;
1408
+
1336
1409
  declare const EncryptionErrorCode: {
1337
1410
  readonly KEYPAIR_MISSING_SECRET_KEY: 13001;
1338
1411
  readonly MNEMONIC_TOO_SHORT: 13002;
@@ -1344,6 +1417,8 @@ declare const EncryptionErrorCode: {
1344
1417
  readonly PASSWORD_SEQUENTIAL_RUN: 13008;
1345
1418
  readonly PASSWORD_KEYBOARD_WALK: 13009;
1346
1419
  readonly PASSWORD_ENTROPY_TOO_LOW: 13010;
1420
+ readonly PASSWORD_SCRYPT_N_TOO_LOW: 13011;
1421
+ readonly PASSWORD_SCRYPT_N_NOT_POWER_OF_TWO: 13012;
1347
1422
  };
1348
1423
  type EncryptionErrorCode = (typeof EncryptionErrorCode)[keyof typeof EncryptionErrorCode];
1349
1424
 
@@ -1572,6 +1647,12 @@ interface PasswordEncryptionAdapterConfig {
1572
1647
  /**
1573
1648
  * Custom scrypt parameters. Only used when `preset` is not provided.
1574
1649
  * Prefer `preset` for well-known configurations.
1650
+ *
1651
+ * `N` is rejected if it is below 32768 (OWASP 2024 minimum, 32 MB
1652
+ * memory-hard) or is not a power of two — this floor also applies when
1653
+ * reconstructing via `fromKdfParams()`, since a downgraded or corrupted
1654
+ * stored value could otherwise collapse the KDF to something trivially
1655
+ * brute-forceable.
1575
1656
  */
1576
1657
  params?: {
1577
1658
  N?: number;
@@ -2203,6 +2284,7 @@ declare const CoreErrorCode: {
2203
2284
  readonly STORAGE_ADAPTER_MISMATCH: 10052;
2204
2285
  readonly RETRIEVE_BY_REF_ID_ENVELOPE_EMPTY: 10053;
2205
2286
  readonly CONTENT_HASH_MISMATCH: 10054;
2287
+ readonly METADATA_PARSE_FAILED: 10055;
2206
2288
  readonly LIST_REFS_REQUIRES_CHAIN: 10060;
2207
2289
  readonly LIST_REFS_NOT_SUPPORTED: 10061;
2208
2290
  readonly REMOVE_REF_REQUIRES_CHAIN: 10070;
@@ -2213,6 +2295,7 @@ declare const CoreErrorCode: {
2213
2295
  readonly DECRYPT_CHUNK_FAILED: 10093;
2214
2296
  readonly CHUNK_OVERFLOWS_TOTAL_SIZE: 10094;
2215
2297
  readonly REASSEMBLY_SIZE_MISMATCH: 10095;
2298
+ readonly MANIFEST_PARSE_FAILED: 10096;
2216
2299
  readonly NOT_INITIALIZED: 10100;
2217
2300
  readonly UNKNOWN_ERROR: 10999;
2218
2301
  };
@@ -2228,4 +2311,4 @@ declare class StorePartialError extends DStorageError {
2228
2311
  }
2229
2312
  declare function isStorePartialError(err: unknown): err is StorePartialError;
2230
2313
 
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 };
2314
+ export { ARWEAVE_LOCAL, type ArweaveBundlerAdapterConfig, ArweaveBundlerStorageAdapter, type ArweaveLocalAdapterConfig, type ArweaveLocalBalance, ArweaveLocalError, ArweaveLocalHelper, type ArweaveLocalHelperConfig, type ArweaveLocalInfo, ArweaveLocalStorageAdapter, ArweavePaymentAdapter, ArweaveStorageAdapter, type BoundedTextReadOptions, 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, readResponseTextWithLimit, serializeKeyEnvelope, serializeXChaChaPayload, unwrapKey, wrapKey };