@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/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,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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.
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
KeypairEncryptionAdapter
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
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-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
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
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
KDF_PRESETS,
|
|
3
3
|
PasswordEncryptionAdapter,
|
|
4
4
|
generatePqsPassword
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
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-
|
|
6
|
-
import "./chunk-
|
|
7
|
-
import "./chunk-
|
|
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,
|
package/dist/browser.d.mts
CHANGED
|
@@ -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
|
|
415
|
-
*
|
|
416
|
-
*
|
|
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
|
-
|
|
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;
|
|
@@ -1949,170 +2030,6 @@ declare const METADATA_ONLY_OWNER_SECRET_SALT: Uint8Array;
|
|
|
1949
2030
|
*/
|
|
1950
2031
|
declare const chunkAad: (index: number, total: number) => Uint8Array;
|
|
1951
2032
|
|
|
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
2033
|
/**
|
|
2117
2034
|
* @dstorage/core — dStorage.ts
|
|
2118
2035
|
*
|
|
@@ -2131,7 +2048,7 @@ declare class MetaTx {
|
|
|
2131
2048
|
* await ds.removeReference(chainRefId);
|
|
2132
2049
|
*/
|
|
2133
2050
|
|
|
2134
|
-
declare class DStorage
|
|
2051
|
+
declare class DStorage {
|
|
2135
2052
|
private config;
|
|
2136
2053
|
private wallet;
|
|
2137
2054
|
/** Encryption adapters — each wraps/unwraps per-upload DEKs using its own algorithm. */
|
|
@@ -2288,26 +2205,6 @@ declare class DStorage implements DStorageContext {
|
|
|
2288
2205
|
* Estimate the full cost (storage + chain) for a given payload size before committing.
|
|
2289
2206
|
*/
|
|
2290
2207
|
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
2208
|
/**
|
|
2312
2209
|
* Upload large content by splitting into CHUNK_SIZE pieces, encrypting each
|
|
2313
2210
|
* independently, and storing a manifest that ties them together.
|
|
@@ -2387,20 +2284,19 @@ declare const CoreErrorCode: {
|
|
|
2387
2284
|
readonly STORAGE_ADAPTER_MISMATCH: 10052;
|
|
2388
2285
|
readonly RETRIEVE_BY_REF_ID_ENVELOPE_EMPTY: 10053;
|
|
2389
2286
|
readonly CONTENT_HASH_MISMATCH: 10054;
|
|
2287
|
+
readonly METADATA_PARSE_FAILED: 10055;
|
|
2390
2288
|
readonly LIST_REFS_REQUIRES_CHAIN: 10060;
|
|
2391
2289
|
readonly LIST_REFS_NOT_SUPPORTED: 10061;
|
|
2392
2290
|
readonly REMOVE_REF_REQUIRES_CHAIN: 10070;
|
|
2393
2291
|
readonly REMOVE_REF_NOT_SUPPORTED: 10071;
|
|
2394
|
-
readonly META_TX_REQUIRES_ENCRYPTION: 10080;
|
|
2395
|
-
readonly PREPARE_UPLOAD_NO_PROVIDERS: 10081;
|
|
2396
2292
|
readonly MANIFEST_INVALID_STRUCTURE: 10090;
|
|
2397
2293
|
readonly MANIFEST_CHUNK_COUNT_MISMATCH: 10091;
|
|
2398
2294
|
readonly MANIFEST_NOT_CONTIGUOUS: 10092;
|
|
2399
2295
|
readonly DECRYPT_CHUNK_FAILED: 10093;
|
|
2400
2296
|
readonly CHUNK_OVERFLOWS_TOTAL_SIZE: 10094;
|
|
2401
2297
|
readonly REASSEMBLY_SIZE_MISMATCH: 10095;
|
|
2298
|
+
readonly MANIFEST_PARSE_FAILED: 10096;
|
|
2402
2299
|
readonly NOT_INITIALIZED: 10100;
|
|
2403
|
-
readonly META_TX_UNKNOWN_STEP: 10200;
|
|
2404
2300
|
readonly UNKNOWN_ERROR: 10999;
|
|
2405
2301
|
};
|
|
2406
2302
|
type CoreErrorCode = (typeof CoreErrorCode)[keyof typeof CoreErrorCode];
|
|
@@ -2415,4 +2311,4 @@ declare class StorePartialError extends DStorageError {
|
|
|
2415
2311
|
}
|
|
2416
2312
|
declare function isStorePartialError(err: unknown): err is StorePartialError;
|
|
2417
2313
|
|
|
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,
|
|
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 };
|