@dstorage-tech/dstorage-sdk 0.0.5 → 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.
- package/README.md +22 -4
- package/dist/KeypairEncryptionAdapter-EOBRCIGP-5PFPNLLA.mjs +8 -0
- package/dist/{KeypairEncryptionAdapter-XUKCLRFU-AYDAZ2TZ.mjs → KeypairEncryptionAdapter-EOBRCIGP-FLPJIL26.mjs} +3 -3
- package/dist/{MnemonicEncryptionAdapter-RCHUETBP-M7NHGSHO.mjs → MnemonicEncryptionAdapter-S56YG63Q-B3F3TO3T.mjs} +3 -3
- package/dist/MnemonicEncryptionAdapter-S56YG63Q-POTD74UN.mjs +8 -0
- package/dist/{PasswordEncryptionAdapter-ECHND672-MUTHAMZY.mjs → PasswordEncryptionAdapter-B2UG7MWB-M4C3KJ4S.mjs} +3 -3
- package/dist/{PasswordEncryptionAdapter-ECHND672-3DEFO6FP.mjs → PasswordEncryptionAdapter-B2UG7MWB-QCSOIQJA.mjs} +3 -3
- package/dist/browser.d.mts +92 -196
- package/dist/browser.mjs +1886 -2139
- package/dist/{chunk-HDD6SUU4.mjs → chunk-42O7KEL4.mjs} +30 -11
- package/dist/{chunk-X4LEBNK6.mjs → chunk-5F3HZ2RJ.mjs} +30 -11
- package/dist/{chunk-6IAQVMSM.mjs → chunk-E73HFT6J.mjs} +5 -5
- package/dist/{chunk-UDYXMII2.mjs → chunk-EOPUNIUH.mjs} +5 -5
- package/dist/{chunk-O37NHERH.mjs → chunk-L6WCT64V.mjs} +4 -2
- package/dist/{chunk-4X5K43JF.mjs → chunk-M3F2LR3B.mjs} +3 -1
- package/dist/{chunk-JMPRZK5D.mjs → chunk-O6COTUD4.mjs} +3 -1
- package/dist/{chunk-BWLEAAFW.mjs → chunk-PCXBQRCO.mjs} +55 -2056
- package/dist/{chunk-OLGVVM5Y.mjs → chunk-QFJ2Y4XE.mjs} +5 -5
- package/dist/{chunk-Z6DUAI5B.mjs → chunk-XW4RZG2X.mjs} +5 -5
- package/dist/{contract-api-TJ7JPHZA-6FUBJ6DS.mjs → contract-api-NUY4UEKE-ZANT3ICG.mjs} +3 -3
- package/dist/{contract-api-AO4RGPLT-ENC72WCG.mjs → contract-api-P6YEDYQ6-2X6BMD64.mjs} +3 -3
- package/dist/{dist-INTAFXQ7.mjs → dist-AGNOIJI4.mjs} +3 -1
- package/dist/{dist-MOLWJ4Y7.mjs → dist-J4JUJ2J5.mjs} +3 -1
- package/dist/errors.d.mts +2 -3
- package/dist/errors.d.ts +2 -3
- package/dist/errors.js +10 -2059
- package/dist/errors.mjs +10 -2059
- package/dist/index.d.mts +109 -196
- package/dist/index.d.ts +109 -196
- package/dist/index.js +2106 -4347
- package/dist/index.mjs +1941 -2194
- package/package.json +3 -2
- package/dist/KeypairEncryptionAdapter-XUKCLRFU-ERPYK5S4.mjs +0 -8
- package/dist/MnemonicEncryptionAdapter-RCHUETBP-DZPBGQG6.mjs +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PaymentAdapter, PaymentNetworkName, TokenSymbol, NetworkType, PaymentAdapterLogger, PaymentQuote, PaymentInstruction, PaymentReceipt, MidnightWalletProvider, StorageAdapterLogger, StorageAdapter, StorageProviderName, StorageUploadResult, StorageQuote, ChainAdapter, ChainProviderName, ChainAdapterLogger, ChainReference, ChainWriteResult, ChainReferenceUpdate, DataReferenceSummary, ChainQuote, WalletBalances } from './types.js';
|
|
1
|
+
import { PaymentAdapter, PaymentNetworkName, TokenSymbol, NetworkType, PaymentAdapterLogger, PaymentQuote, PaymentInstruction, PaymentReceipt, MidnightWalletProvider, StorageAdapterLogger, StorageAdapter, StorageProviderName, StorageUploadResult, RetrieveOptions, StorageQuote, ChainAdapter, ChainProviderName, ChainAdapterLogger, ChainReference, ChainWriteResult, ChainReferenceUpdate, DataReferenceSummary, ChainQuote, WalletBalances } from './types.js';
|
|
2
2
|
export { ChainAdapter, ChainAdapterLogger, ChainProviderName, ChainQuote, ChainReference, ChainReferenceUpdate, ChainWriteResult, DataReferenceSummary, MidnightWalletProvider, NetworkType, PaymentAdapter, PaymentAdapterLogger, PaymentNetworkName, PaymentQuote, PaymentReceipt, StorageAdapter, StorageAdapterLogger, StorageProviderName, StorageQuote, StorageUploadResult, TOKENS, Token, TokenSymbol, WalletBalances } from './types.js';
|
|
3
3
|
import Arweave from 'arweave';
|
|
4
4
|
import Transaction from 'arweave/node/lib/transaction';
|
|
@@ -346,6 +346,12 @@ declare class ManagedPaymentAdapter extends ArweavePaymentAdapter {
|
|
|
346
346
|
*
|
|
347
347
|
* • storageId (txId) is PUBLIC on Arweave. Data security relies entirely on
|
|
348
348
|
* the XChaCha20-Poly1305 encryption applied by @dstorage/crypto before reaching here.
|
|
349
|
+
*
|
|
350
|
+
* • retrieve()'s content-hash check only defends against a malicious gateway when
|
|
351
|
+
* called with an `expectedContentHash` anchor sourced independently of this
|
|
352
|
+
* gateway (see skipIntegrityCheck below) — @dstorage/core supplies this
|
|
353
|
+
* automatically from the on-chain reference. Without an anchor, the check falls
|
|
354
|
+
* back to a gateway-supplied tag and only catches non-adversarial corruption.
|
|
349
355
|
*/
|
|
350
356
|
|
|
351
357
|
interface ArweaveGatewayConfig {
|
|
@@ -413,9 +419,17 @@ interface ArweaveAdapterConfig {
|
|
|
413
419
|
confirmationTimeoutMs?: number;
|
|
414
420
|
/**
|
|
415
421
|
* When true, skip the BLAKE3 content-hash check on retrieve.
|
|
416
|
-
* By default (false) the adapter
|
|
417
|
-
*
|
|
418
|
-
*
|
|
422
|
+
* By default (false) the adapter verifies retrieved bytes against a content hash.
|
|
423
|
+
* The strength of that guarantee depends on the hash's source:
|
|
424
|
+
* - When retrieve() is called with `options.expectedContentHash` (as
|
|
425
|
+
* `@dstorage/core` does automatically, from the on-chain ChainReference),
|
|
426
|
+
* verification is anchored to that chain-committed value and holds even
|
|
427
|
+
* against a fully malicious/colluding gateway.
|
|
428
|
+
* - Without an anchor, the adapter falls back to the `X-Content-Hash` tag
|
|
429
|
+
* fetched from this same gateway — that only catches non-adversarial
|
|
430
|
+
* corruption in transit, since a malicious gateway controls both the tag
|
|
431
|
+
* and the bytes and can make them consistent with each other.
|
|
432
|
+
* Set to true only if you trust the gateway entirely or are using an
|
|
419
433
|
* Arweave node that does not expose the transaction metadata endpoint.
|
|
420
434
|
*/
|
|
421
435
|
skipIntegrityCheck?: boolean;
|
|
@@ -450,7 +464,7 @@ declare class ArweaveStorageAdapter implements StorageAdapter {
|
|
|
450
464
|
constructor(config?: ArweaveAdapterConfig);
|
|
451
465
|
private getClient;
|
|
452
466
|
store(data: Uint8Array, metadata?: Record<string, string>): Promise<StorageUploadResult>;
|
|
453
|
-
retrieve(id: string): Promise<{
|
|
467
|
+
retrieve(id: string, options?: RetrieveOptions): Promise<{
|
|
454
468
|
bytes: Uint8Array;
|
|
455
469
|
tags: Record<string, string>;
|
|
456
470
|
}>;
|
|
@@ -489,6 +503,11 @@ declare class ArweaveStorageAdapter implements StorageAdapter {
|
|
|
489
503
|
*
|
|
490
504
|
* ── Retrieve flow ─────────────────────────────────────────────────────────────
|
|
491
505
|
* Standard Arweave gateway fetch (identical to ArweaveStorageAdapter.retrieve).
|
|
506
|
+
* Its content-hash check only defends against a malicious gateway when called
|
|
507
|
+
* with an `expectedContentHash` anchor sourced independently of this gateway
|
|
508
|
+
* (see skipIntegrityCheck below) — @dstorage/core supplies this automatically
|
|
509
|
+
* from the on-chain reference. Without an anchor, the check falls back to a
|
|
510
|
+
* gateway-supplied tag and only catches non-adversarial corruption.
|
|
492
511
|
*
|
|
493
512
|
* ── Peer dependency ───────────────────────────────────────────────────────────
|
|
494
513
|
* No extra install needed — @dha-team/arbundles ships as a dependency of @ardrive/turbo-sdk.
|
|
@@ -541,10 +560,32 @@ interface ArweaveBundlerAdapterConfig {
|
|
|
541
560
|
maxRetrieveSizeBytes?: number;
|
|
542
561
|
/**
|
|
543
562
|
* Skip BLAKE3 content-hash verification on retrieve.
|
|
563
|
+
* By default (false) the adapter verifies retrieved bytes against a content hash.
|
|
564
|
+
* The strength of that guarantee depends on the hash's source:
|
|
565
|
+
* - When retrieve() is called with `options.expectedContentHash` (as
|
|
566
|
+
* `@dstorage/core` does automatically, from the on-chain ChainReference),
|
|
567
|
+
* verification is anchored to that chain-committed value and holds even
|
|
568
|
+
* against a fully malicious/colluding gateway.
|
|
569
|
+
* - Without an anchor, the adapter falls back to the `X-Content-Hash` tag
|
|
570
|
+
* fetched from this same gateway — that only catches non-adversarial
|
|
571
|
+
* corruption in transit, since a malicious gateway controls both the tag
|
|
572
|
+
* and the bytes and can make them consistent with each other.
|
|
544
573
|
* Only set to true when connecting to a fully trusted gateway.
|
|
545
|
-
* Defaults to false.
|
|
546
574
|
*/
|
|
547
575
|
skipIntegrityCheck?: boolean;
|
|
576
|
+
/**
|
|
577
|
+
* Maximum time in milliseconds to wait for any single retrieve() request
|
|
578
|
+
* (metadata or data fetch) before aborting. Defaults to 30_000 ms (30 s).
|
|
579
|
+
* Pass `0` to disable the timeout entirely (not recommended for production).
|
|
580
|
+
*/
|
|
581
|
+
requestTimeoutMs?: number;
|
|
582
|
+
/**
|
|
583
|
+
* Maximum number of bytes allowed in the transaction metadata/tags JSON
|
|
584
|
+
* response fetched during retrieve(). Guards against a hostile or
|
|
585
|
+
* misbehaving gateway returning an oversized body to exhaust memory.
|
|
586
|
+
* Defaults to 1_048_576 (1 MiB) — metadata/tags are always tiny in practice.
|
|
587
|
+
*/
|
|
588
|
+
maxMetadataResponseBytes?: number;
|
|
548
589
|
/**
|
|
549
590
|
* Optional logger for SDK operational output.
|
|
550
591
|
*/
|
|
@@ -573,12 +614,16 @@ declare class ArweaveBundlerStorageAdapter implements StorageAdapter {
|
|
|
573
614
|
private readonly gateway;
|
|
574
615
|
private readonly maxRetrieveSizeBytes;
|
|
575
616
|
private readonly skipIntegrityCheck;
|
|
617
|
+
private readonly requestTimeoutMs;
|
|
618
|
+
private readonly maxMetadataResponseBytes;
|
|
576
619
|
protected readonly logger: StorageAdapterLogger | undefined;
|
|
577
620
|
/** RSA-4096 public key modulus (512 bytes) parsed from the auth token at construction time. */
|
|
578
621
|
private readonly ownerPublicKey;
|
|
579
622
|
constructor(config?: ArweaveBundlerAdapterConfig);
|
|
580
623
|
store(data: Uint8Array, metadata?: Record<string, string>): Promise<StorageUploadResult>;
|
|
581
|
-
|
|
624
|
+
/** Adds an AbortSignal.timeout() to a fetch init object (when requestTimeoutMs > 0). */
|
|
625
|
+
private _withTimeout;
|
|
626
|
+
retrieve(id: string, options?: RetrieveOptions): Promise<{
|
|
582
627
|
bytes: Uint8Array;
|
|
583
628
|
tags: Record<string, string>;
|
|
584
629
|
}>;
|
|
@@ -1335,6 +1380,34 @@ declare function computeBlake3(bytes: Uint8Array): Promise<Uint8Array>;
|
|
|
1335
1380
|
/** BLAKE3 hash of `bytes`, returned as a 64-character lowercase hex string. */
|
|
1336
1381
|
declare function computeBlake3Hex(bytes: Uint8Array): Promise<string>;
|
|
1337
1382
|
|
|
1383
|
+
/**
|
|
1384
|
+
* @dstorage/crypto — boundedFetch.ts
|
|
1385
|
+
* Shared helper for reading a fetch Response body with a hard size cap —
|
|
1386
|
+
* used by chain/storage HTTP adapters to avoid a hostile or misbehaving
|
|
1387
|
+
* gateway exhausting memory with an oversized response.
|
|
1388
|
+
*/
|
|
1389
|
+
interface BoundedTextReadOptions {
|
|
1390
|
+
/** Maximum number of bytes/characters allowed in the response body. */
|
|
1391
|
+
maxBytes: number;
|
|
1392
|
+
/** Error code to throw (caller-owned, package-specific) when the cap is exceeded. */
|
|
1393
|
+
code: number;
|
|
1394
|
+
/** Prefix identifying the caller/operation in the thrown error message. */
|
|
1395
|
+
component: string;
|
|
1396
|
+
}
|
|
1397
|
+
/**
|
|
1398
|
+
* Reads a fetch Response body as text, aborting once the accumulated size
|
|
1399
|
+
* exceeds `maxBytes`.
|
|
1400
|
+
*
|
|
1401
|
+
* Uses a streaming reader when the Response exposes `.body` (always true for
|
|
1402
|
+
* real `fetch()` responses), so a gateway that omits or lies about
|
|
1403
|
+
* `Content-Length` (e.g. chunked transfer encoding) can't force an unbounded
|
|
1404
|
+
* read — the read is aborted as soon as the limit is crossed, before the
|
|
1405
|
+
* full body is buffered. Falls back to a single `.text()` read + post-hoc
|
|
1406
|
+
* length check only when `.body` is unavailable (e.g. non-streaming
|
|
1407
|
+
* environments or simple test doubles).
|
|
1408
|
+
*/
|
|
1409
|
+
declare function readResponseTextWithLimit(res: Response, opts: BoundedTextReadOptions): Promise<string>;
|
|
1410
|
+
|
|
1338
1411
|
/**
|
|
1339
1412
|
* @dstorage/chain — adapters/midnightSimulator.ts
|
|
1340
1413
|
*
|
|
@@ -1418,6 +1491,19 @@ interface HttpGatewayChainAdapterConfig {
|
|
|
1418
1491
|
*/
|
|
1419
1492
|
customFetch?: typeof fetch;
|
|
1420
1493
|
logger?: ChainAdapterLogger;
|
|
1494
|
+
/**
|
|
1495
|
+
* Maximum time in milliseconds to wait for any single request before aborting.
|
|
1496
|
+
* Defaults to 30_000 ms (30 s). Pass `0` to disable the timeout entirely
|
|
1497
|
+
* (not recommended for production).
|
|
1498
|
+
*/
|
|
1499
|
+
requestTimeoutMs?: number;
|
|
1500
|
+
/**
|
|
1501
|
+
* Maximum number of bytes allowed in a `readReference`/`listReferences`
|
|
1502
|
+
* JSON response body. Guards against a hostile or misbehaving gateway
|
|
1503
|
+
* returning an oversized body to exhaust memory. Defaults to 10_485_760
|
|
1504
|
+
* (10 MiB) — generous for reference/list JSON payloads.
|
|
1505
|
+
*/
|
|
1506
|
+
maxResponseBytes?: number;
|
|
1421
1507
|
}
|
|
1422
1508
|
declare class HttpGatewayChainAdapter implements ChainAdapter {
|
|
1423
1509
|
readonly name: ChainProviderName;
|
|
@@ -1429,7 +1515,11 @@ declare class HttpGatewayChainAdapter implements ChainAdapter {
|
|
|
1429
1515
|
private readonly readUrl;
|
|
1430
1516
|
private readonly listUrl;
|
|
1431
1517
|
private readonly deleteUrl;
|
|
1518
|
+
private readonly requestTimeoutMs;
|
|
1519
|
+
private readonly maxResponseBytes;
|
|
1432
1520
|
constructor(config: HttpGatewayChainAdapterConfig);
|
|
1521
|
+
/** Adds an AbortSignal.timeout() to a fetch init object (when requestTimeoutMs > 0). */
|
|
1522
|
+
private _withTimeout;
|
|
1433
1523
|
writeReference(ref: ChainReference): Promise<ChainWriteResult>;
|
|
1434
1524
|
updateReference(refId: string, update: ChainReferenceUpdate, _ownerSecret?: Uint8Array, _newOwnerSecret?: Uint8Array): Promise<void>;
|
|
1435
1525
|
readReference(refId: string): Promise<ChainReference>;
|
|
@@ -1769,6 +1859,8 @@ declare const EncryptionErrorCode: {
|
|
|
1769
1859
|
readonly PASSWORD_SEQUENTIAL_RUN: 13008;
|
|
1770
1860
|
readonly PASSWORD_KEYBOARD_WALK: 13009;
|
|
1771
1861
|
readonly PASSWORD_ENTROPY_TOO_LOW: 13010;
|
|
1862
|
+
readonly PASSWORD_SCRYPT_N_TOO_LOW: 13011;
|
|
1863
|
+
readonly PASSWORD_SCRYPT_N_NOT_POWER_OF_TWO: 13012;
|
|
1772
1864
|
};
|
|
1773
1865
|
type EncryptionErrorCode = (typeof EncryptionErrorCode)[keyof typeof EncryptionErrorCode];
|
|
1774
1866
|
|
|
@@ -1997,6 +2089,12 @@ interface PasswordEncryptionAdapterConfig {
|
|
|
1997
2089
|
/**
|
|
1998
2090
|
* Custom scrypt parameters. Only used when `preset` is not provided.
|
|
1999
2091
|
* Prefer `preset` for well-known configurations.
|
|
2092
|
+
*
|
|
2093
|
+
* `N` is rejected if it is below 32768 (OWASP 2024 minimum, 32 MB
|
|
2094
|
+
* memory-hard) or is not a power of two — this floor also applies when
|
|
2095
|
+
* reconstructing via `fromKdfParams()`, since a downgraded or corrupted
|
|
2096
|
+
* stored value could otherwise collapse the KDF to something trivially
|
|
2097
|
+
* brute-forceable.
|
|
2000
2098
|
*/
|
|
2001
2099
|
params?: {
|
|
2002
2100
|
N?: number;
|
|
@@ -2374,170 +2472,6 @@ declare const METADATA_ONLY_OWNER_SECRET_SALT: Uint8Array;
|
|
|
2374
2472
|
*/
|
|
2375
2473
|
declare const chunkAad: (index: number, total: number) => Uint8Array;
|
|
2376
2474
|
|
|
2377
|
-
/**
|
|
2378
|
-
* @dstorage/core — metaTx/types.ts
|
|
2379
|
-
*
|
|
2380
|
-
* All public interfaces and type aliases for the MetaTx orchestrator.
|
|
2381
|
-
*/
|
|
2382
|
-
|
|
2383
|
-
type MetaTxStepId = "estimate" | "encrypt" | "payment_storage" | "upload" | "chain_reference" | "complete";
|
|
2384
|
-
type MetaTxStepStatus = "pending" | "running" | "done" | "error";
|
|
2385
|
-
interface MetaTxStepState {
|
|
2386
|
-
id: MetaTxStepId;
|
|
2387
|
-
label: string;
|
|
2388
|
-
description: string;
|
|
2389
|
-
status: MetaTxStepStatus;
|
|
2390
|
-
/** Live detail message updated during the step */
|
|
2391
|
-
detail?: string;
|
|
2392
|
-
/** Duration in ms (set when done) */
|
|
2393
|
-
durationMs?: number;
|
|
2394
|
-
startedAt?: number;
|
|
2395
|
-
}
|
|
2396
|
-
interface MetaTxProgress {
|
|
2397
|
-
steps: MetaTxStepState[];
|
|
2398
|
-
currentStepId: MetaTxStepId | null;
|
|
2399
|
-
overallStatus: "idle" | "awaiting_confirmation" | "running" | "complete" | "error";
|
|
2400
|
-
/** Cost estimate — set after 'estimate' step completes */
|
|
2401
|
-
estimate?: CostEstimate;
|
|
2402
|
-
/** Final receipt — set when complete */
|
|
2403
|
-
receipt?: MetaTxReceipt;
|
|
2404
|
-
/** Error message if overallStatus is 'error' */
|
|
2405
|
-
error?: string;
|
|
2406
|
-
}
|
|
2407
|
-
interface MetaTxReceipt {
|
|
2408
|
-
dataId: string;
|
|
2409
|
-
storageId: string;
|
|
2410
|
-
/** Undefined when no chain adapter is configured (storage-only mode). */
|
|
2411
|
-
chainRefId?: string;
|
|
2412
|
-
/** Original file info */
|
|
2413
|
-
file: {
|
|
2414
|
-
name: string;
|
|
2415
|
-
type: string;
|
|
2416
|
-
sizeBytes: number;
|
|
2417
|
-
};
|
|
2418
|
-
/** Payment receipts */
|
|
2419
|
-
storagePayment: PaymentReceipt;
|
|
2420
|
-
/** Undefined when no chain adapter is configured. */
|
|
2421
|
-
chainPayment?: PaymentReceipt;
|
|
2422
|
-
/** Tokens used */
|
|
2423
|
-
storageToken: TokenSymbol;
|
|
2424
|
-
/** Undefined when no chain adapter is configured. */
|
|
2425
|
-
chainToken?: TokenSymbol;
|
|
2426
|
-
/** Contract invoked (if selected) */
|
|
2427
|
-
contract?: {
|
|
2428
|
-
address: string;
|
|
2429
|
-
name: string;
|
|
2430
|
-
};
|
|
2431
|
-
completedAt: number;
|
|
2432
|
-
/** Duration of the full meta-transaction in ms */
|
|
2433
|
-
totalDurationMs: number;
|
|
2434
|
-
}
|
|
2435
|
-
interface MetaTxConfig {
|
|
2436
|
-
/** Optional metadata to attach to the on-chain reference */
|
|
2437
|
-
metadata?: Record<string, string>;
|
|
2438
|
-
/** Selected contract address (from the contract registry) */
|
|
2439
|
-
contractAddress?: string;
|
|
2440
|
-
/** Selected contract name (for display / receipt) */
|
|
2441
|
-
contractName?: string;
|
|
2442
|
-
}
|
|
2443
|
-
/**
|
|
2444
|
-
* Crypto materials for a single upload: a fresh random DEK wrapped in a
|
|
2445
|
-
* key envelope, ready to encrypt payload and storageId.
|
|
2446
|
-
*
|
|
2447
|
-
* For private uploads: uploadScheme encrypts content; dek is the per-upload
|
|
2448
|
-
* Data Encryption Key used both to encrypt content AND to derive
|
|
2449
|
-
* ownerSecret = HKDF(dek, rawStorageId). Any KEK holder can re-derive the
|
|
2450
|
-
* ownerSecret by unwrapping the envelope DEK.
|
|
2451
|
-
* For public uploads: uploadScheme is null; ownerSeed is a random secret wrapped
|
|
2452
|
-
* under every KEK in keyEnvelope, and ownerSecret = HKDF(ownerSeed, rawStorageId).
|
|
2453
|
-
* Any single KEK holder can re-derive the ownerSecret by unwrapping the envelope.
|
|
2454
|
-
*/
|
|
2455
|
-
interface UploadCrypto {
|
|
2456
|
-
/** XChaChaScheme built from a fresh random DEK. null for public uploads. */
|
|
2457
|
-
uploadScheme: CryptoScheme | null;
|
|
2458
|
-
/** JSON-encoded KeyEnvelope wrapping the DEK (private) or ownerSeed (public) under every KEK. */
|
|
2459
|
-
keyEnvelope: string;
|
|
2460
|
-
/** Encryption scheme identifier to record on-chain. "" for public uploads. */
|
|
2461
|
-
encryptionScheme: EncryptionScheme;
|
|
2462
|
-
/**
|
|
2463
|
-
* The raw per-upload DEK for private uploads; undefined for public uploads.
|
|
2464
|
-
* Used by MetaTx to derive ownerSecret = HKDF(dek, rawStorageId) after upload.
|
|
2465
|
-
* Not stored anywhere — must not be persisted.
|
|
2466
|
-
*/
|
|
2467
|
-
dek?: Uint8Array;
|
|
2468
|
-
/**
|
|
2469
|
-
* The raw ownerSeed for public uploads; undefined for private uploads.
|
|
2470
|
-
* Used by MetaTx to derive ownerSecret = HKDF(ownerSeed, rawStorageId) after upload.
|
|
2471
|
-
* Not stored anywhere — must not be persisted.
|
|
2472
|
-
*/
|
|
2473
|
-
ownerSeed?: Uint8Array;
|
|
2474
|
-
}
|
|
2475
|
-
/**
|
|
2476
|
-
* Minimal SDK surface required by MetaTx.
|
|
2477
|
-
* Implemented by DStorage — MetaTx receives the SDK instance directly
|
|
2478
|
-
* rather than individual adapters/keys/address to avoid redundant constructor args.
|
|
2479
|
-
*/
|
|
2480
|
-
interface DStorageContext {
|
|
2481
|
-
readonly storageAdapter: StorageAdapter;
|
|
2482
|
-
readonly chainAdapter: ChainAdapter | undefined;
|
|
2483
|
-
/** Wallet address of the connected user, or null if using init() / facade mode. */
|
|
2484
|
-
readonly connectedAddress: string | null;
|
|
2485
|
-
/**
|
|
2486
|
-
* Generate a fresh random DEK, wrap it under the KEK, and return the
|
|
2487
|
-
* upload crypto materials needed to encrypt payload and storageId.
|
|
2488
|
-
* @param isPublic Pass true to skip encryption (returns null scheme + no envelope).
|
|
2489
|
-
*/
|
|
2490
|
-
prepareUploadCrypto(isPublic?: boolean): Promise<UploadCrypto>;
|
|
2491
|
-
/** Estimate the full cost (storage + chain) for a given payload size. */
|
|
2492
|
-
estimateCost(sizeBytes: number): Promise<CostEstimate>;
|
|
2493
|
-
}
|
|
2494
|
-
|
|
2495
|
-
/**
|
|
2496
|
-
* @dstorage/core — metaTx/utils.ts
|
|
2497
|
-
*
|
|
2498
|
-
* Helpers used internally by MetaTx and one exported utility.
|
|
2499
|
-
*/
|
|
2500
|
-
|
|
2501
|
-
/**
|
|
2502
|
-
* Return the default chain payment token for a given chain provider name.
|
|
2503
|
-
*/
|
|
2504
|
-
declare function defaultChainToken(chainProvider: string): TokenSymbol;
|
|
2505
|
-
|
|
2506
|
-
/**
|
|
2507
|
-
* @dstorage/core — metaTx/MetaTx.ts
|
|
2508
|
-
*
|
|
2509
|
-
* The MetaTx orchestrator.
|
|
2510
|
-
*
|
|
2511
|
-
* Presents a single conceptual action to the user while internally executing:
|
|
2512
|
-
* [0] Estimate → compute storage + chain costs
|
|
2513
|
-
* [1] Encrypt → XChaCha20-Poly1305 encrypt the file client-side
|
|
2514
|
-
* [2] PayStorage → simulate storage payment (AR / MOCK)
|
|
2515
|
-
* [3] Upload → upload encrypted blob to decentralised storage
|
|
2516
|
-
* [4] Reference → pay chain fee + write CID + metadata reference on-chain
|
|
2517
|
-
* [✓] Complete → return full receipt
|
|
2518
|
-
*
|
|
2519
|
-
* Usage:
|
|
2520
|
-
* const metaTx = new MetaTx(dStorage);
|
|
2521
|
-
* metaTx.onProgress((progress) => updateUI(progress));
|
|
2522
|
-
* const receipt = await metaTx.execute(file);
|
|
2523
|
-
*/
|
|
2524
|
-
|
|
2525
|
-
declare class MetaTx {
|
|
2526
|
-
private sdk;
|
|
2527
|
-
private progressCallback;
|
|
2528
|
-
private steps;
|
|
2529
|
-
private startedAt;
|
|
2530
|
-
constructor(sdk: DStorageContext);
|
|
2531
|
-
/** Register a progress listener. Called after every step state change. */
|
|
2532
|
-
onProgress(cb: (progress: MetaTxProgress) => void): this;
|
|
2533
|
-
execute(file: File, config?: MetaTxConfig): Promise<MetaTxReceipt>;
|
|
2534
|
-
private startStep;
|
|
2535
|
-
private updateStepDetail;
|
|
2536
|
-
private completeStep;
|
|
2537
|
-
private getStep;
|
|
2538
|
-
private emit;
|
|
2539
|
-
}
|
|
2540
|
-
|
|
2541
2475
|
/**
|
|
2542
2476
|
* @dstorage/core — dStorage.ts
|
|
2543
2477
|
*
|
|
@@ -2556,7 +2490,7 @@ declare class MetaTx {
|
|
|
2556
2490
|
* await ds.removeReference(chainRefId);
|
|
2557
2491
|
*/
|
|
2558
2492
|
|
|
2559
|
-
declare class DStorage
|
|
2493
|
+
declare class DStorage {
|
|
2560
2494
|
private config;
|
|
2561
2495
|
private wallet;
|
|
2562
2496
|
/** Encryption adapters — each wraps/unwraps per-upload DEKs using its own algorithm. */
|
|
@@ -2713,26 +2647,6 @@ declare class DStorage implements DStorageContext {
|
|
|
2713
2647
|
* Estimate the full cost (storage + chain) for a given payload size before committing.
|
|
2714
2648
|
*/
|
|
2715
2649
|
estimateCost(sizeBytes: number): Promise<CostEstimate>;
|
|
2716
|
-
/**
|
|
2717
|
-
* Execute a full meta-transaction for a file:
|
|
2718
|
-
* estimate → encrypt → pay storage → upload → pay chain → write reference
|
|
2719
|
-
*
|
|
2720
|
-
* Presents the entire flow as a single action with step-by-step progress.
|
|
2721
|
-
*
|
|
2722
|
-
* @param file The File to encrypt and store
|
|
2723
|
-
* @param onProgress Callback fired on every step state change
|
|
2724
|
-
* @param config Optional token overrides and metadata
|
|
2725
|
-
*/
|
|
2726
|
-
executeMetaTransaction(file: File, onProgress: (progress: MetaTxProgress) => void, config?: MetaTxConfig): Promise<MetaTxReceipt>;
|
|
2727
|
-
/**
|
|
2728
|
-
* Generate a fresh random DEK, wrap it under the KEK(s), and return the crypto
|
|
2729
|
-
* materials needed by MetaTx to encrypt payload and storageId.
|
|
2730
|
-
*
|
|
2731
|
-
* For private stores: the DEK is wrapped under every available KEK. The ownerSecret
|
|
2732
|
-
* can later be re-derived as HKDF(dek, rawStorageId) by any KEK holder.
|
|
2733
|
-
* For public stores: a random ownerSeed is generated and wrapped under all KEKs (same pattern).
|
|
2734
|
-
*/
|
|
2735
|
-
prepareUploadCrypto(isPublic?: boolean): Promise<UploadCrypto>;
|
|
2736
2650
|
/**
|
|
2737
2651
|
* Upload large content by splitting into CHUNK_SIZE pieces, encrypting each
|
|
2738
2652
|
* independently, and storing a manifest that ties them together.
|
|
@@ -2812,20 +2726,19 @@ declare const CoreErrorCode: {
|
|
|
2812
2726
|
readonly STORAGE_ADAPTER_MISMATCH: 10052;
|
|
2813
2727
|
readonly RETRIEVE_BY_REF_ID_ENVELOPE_EMPTY: 10053;
|
|
2814
2728
|
readonly CONTENT_HASH_MISMATCH: 10054;
|
|
2729
|
+
readonly METADATA_PARSE_FAILED: 10055;
|
|
2815
2730
|
readonly LIST_REFS_REQUIRES_CHAIN: 10060;
|
|
2816
2731
|
readonly LIST_REFS_NOT_SUPPORTED: 10061;
|
|
2817
2732
|
readonly REMOVE_REF_REQUIRES_CHAIN: 10070;
|
|
2818
2733
|
readonly REMOVE_REF_NOT_SUPPORTED: 10071;
|
|
2819
|
-
readonly META_TX_REQUIRES_ENCRYPTION: 10080;
|
|
2820
|
-
readonly PREPARE_UPLOAD_NO_PROVIDERS: 10081;
|
|
2821
2734
|
readonly MANIFEST_INVALID_STRUCTURE: 10090;
|
|
2822
2735
|
readonly MANIFEST_CHUNK_COUNT_MISMATCH: 10091;
|
|
2823
2736
|
readonly MANIFEST_NOT_CONTIGUOUS: 10092;
|
|
2824
2737
|
readonly DECRYPT_CHUNK_FAILED: 10093;
|
|
2825
2738
|
readonly CHUNK_OVERFLOWS_TOTAL_SIZE: 10094;
|
|
2826
2739
|
readonly REASSEMBLY_SIZE_MISMATCH: 10095;
|
|
2740
|
+
readonly MANIFEST_PARSE_FAILED: 10096;
|
|
2827
2741
|
readonly NOT_INITIALIZED: 10100;
|
|
2828
|
-
readonly META_TX_UNKNOWN_STEP: 10200;
|
|
2829
2742
|
readonly UNKNOWN_ERROR: 10999;
|
|
2830
2743
|
};
|
|
2831
2744
|
type CoreErrorCode = (typeof CoreErrorCode)[keyof typeof CoreErrorCode];
|
|
@@ -2840,4 +2753,4 @@ declare class StorePartialError extends DStorageError {
|
|
|
2840
2753
|
}
|
|
2841
2754
|
declare function isStorePartialError(err: unknown): err is StorePartialError;
|
|
2842
2755
|
|
|
2843
|
-
export { ARWEAVE_LOCAL, type AdapterWalletProvider, 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,
|
|
2756
|
+
export { ARWEAVE_LOCAL, type AdapterWalletProvider, 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, HttpGatewayChainAdapter, type HttpGatewayChainAdapterConfig, 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, MidnightChainAdapter, type MidnightChainAdapterConfig, MidnightSimulatorChainAdapter, MnemonicEncryptionAdapter, NETWORKS, 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 WalletAddresses, 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, waitForFacadeSync, wrapKey };
|