phantomdisk 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ export declare const DEFAULT_API_URL = "https://api.phantomdisk.com";
2
+ /** What the server said, in words fit to show: `code` is the API's error code (`NOT_FOUND`, `KEY_READ_ONLY`, …). */
3
+ export declare class PhantomDiskError extends Error {
4
+ readonly code: string;
5
+ readonly status: number;
6
+ /** The API's `details` for this error, when it sends any. */
7
+ readonly details?: unknown | undefined;
8
+ constructor(code: string, message: string, status?: number,
9
+ /** The API's `details` for this error, when it sends any. */
10
+ details?: unknown | undefined);
11
+ }
12
+ export interface OpenOptions {
13
+ /** `pdk_…`, or `pdk_….<key>` for an encrypted account. Default: the `PHANTOMDISK_KEY` environment variable. */
14
+ key?: string;
15
+ /** A drive's id. Default: the account's main drive, or the key's first drive when it is limited to some. */
16
+ drive?: string;
17
+ /** Default: `PHANTOMDRIVE_API_URL`, else the PhantomDisk service. */
18
+ apiUrl?: string;
19
+ /** For tests and unusual runtimes. */
20
+ fetch?: typeof fetch;
21
+ }
22
+ export interface Entry {
23
+ /** From the drive's top folder, `/` between names, no leading slash: `notes/plan.md`. */
24
+ path: string;
25
+ name: string;
26
+ kind: "file" | "folder";
27
+ size: number;
28
+ modified: Date;
29
+ id: string;
30
+ /** A file's current version; null for a folder. */
31
+ versionId: string | null;
32
+ }
33
+ export interface Version {
34
+ id: string;
35
+ size: number;
36
+ createdAt: Date;
37
+ current: boolean;
38
+ /** When a replaced version is deleted for good; null for the current one. */
39
+ purgeAt: Date | null;
40
+ }
41
+ export declare class PhantomDisk {
42
+ private readonly token;
43
+ private readonly master;
44
+ private readonly nameKeyRaw;
45
+ private readonly apiUrl;
46
+ private readonly doFetch;
47
+ private readonly account;
48
+ /** The drive every call works in. */
49
+ readonly driveId: string;
50
+ private nodes;
51
+ private names;
52
+ private cursor;
53
+ private constructor();
54
+ /** Connects with an access key and loads the drive's file tree. */
55
+ static open(opts?: OpenOptions): Promise<PhantomDisk>;
56
+ /** False for a read-only key, and when the account's plan has ended. */
57
+ get writable(): boolean;
58
+ get encrypted(): boolean;
59
+ /** Everything in a folder (the top folder by default), folders first, then by name. */
60
+ list(path?: string): Promise<Entry[]>;
61
+ /** The file or folder at `path`, or null when there is none. */
62
+ stat(path: string): Promise<Entry | null>;
63
+ /**
64
+ * A file's bytes: all of them, or `length` bytes from `offset`, fetching only the blocks that hold them (a few
65
+ * hundred KB of a 50 GB file costs a few hundred KB). `version` reads an older version from `history`.
66
+ */
67
+ read(path: string, opts?: {
68
+ offset?: number;
69
+ length?: number;
70
+ version?: string;
71
+ }): Promise<Uint8Array>;
72
+ /** A text file's content (UTF-8). */
73
+ readText(path: string, opts?: {
74
+ version?: string;
75
+ }): Promise<string>;
76
+ /**
77
+ * Writes a file, making the folders above it. An existing file gets a new version: the old one stays in `history`
78
+ * for 30 days. The upload is verified piece by piece before it counts.
79
+ */
80
+ write(path: string, data: string | Uint8Array | Blob, opts?: {
81
+ mtime?: Date;
82
+ }): Promise<Entry>;
83
+ /** Makes a folder and any missing folders above it; an existing folder is returned as it is. */
84
+ mkdir(path: string): Promise<Entry>;
85
+ /** Renames or moves a file or folder; the folders above the new place are made when missing. */
86
+ move(from: string, to: string): Promise<Entry>;
87
+ /** Moves a file or folder to Recently Deleted, where it can be brought back for 30 days. A key cannot delete for good. */
88
+ remove(path: string): Promise<void>;
89
+ /**
90
+ * Copies a file, or a folder and everything in it, to `to`. Nothing is uploaded or downloaded: the copy shares the
91
+ * stored bytes, and from then on the two change apart. It counts against the plan like any other file.
92
+ */
93
+ copy(from: string, to: string): Promise<Entry>;
94
+ /**
95
+ * A fork: a new drive holding everything in this one as it is now, made without moving any file's bytes. Work in
96
+ * the fork changes nothing here, and the other way round; delete either and the other is whole. Needs a key for
97
+ * every drive (a key limited to some drives cannot make one). Returns the fork, open.
98
+ */
99
+ fork(name: string): Promise<PhantomDisk>;
100
+ /** Copies `root` (null: everything in this drive) into `target` under `parentId`; the id of the copy of `root`. */
101
+ private copyTree;
102
+ /** A file's versions, newest first. Replaced versions are kept for 30 days. */
103
+ history(path: string): Promise<Version[]>;
104
+ /** Makes an older version current again. Nothing is copied, and the version it replaces stays in `history`. */
105
+ restore(path: string, versionId: string): Promise<Entry>;
106
+ /** Catches up with changes made elsewhere (the Mac app, the web, another agent). Every call above does this first. */
107
+ refresh(): Promise<void>;
108
+ private get sealing();
109
+ private stored;
110
+ private nameOf;
111
+ private children;
112
+ private find;
113
+ private need;
114
+ private entry;
115
+ private apply;
116
+ private snapshot;
117
+ private ops;
118
+ private source;
119
+ private getRange;
120
+ /** One API call. A busy or rate-limited answer is tried again a few times, after the wait the server names. */
121
+ private api;
122
+ }
@@ -0,0 +1,16 @@
1
+ export type Bytes = Uint8Array<ArrayBuffer>;
2
+ export declare const utf8: (s: string) => Bytes;
3
+ export declare const hex: (b: Uint8Array) => string;
4
+ export declare function fromHex(s: string): Bytes;
5
+ export declare function b64(b: Uint8Array): string;
6
+ export declare function fromB64(s: string): Bytes;
7
+ export declare const b64url: (b: Uint8Array) => string;
8
+ export declare function fromB64url(s: string): Bytes;
9
+ export declare function concat(...parts: Uint8Array[]): Bytes;
10
+ export declare const sha256: (b: Bytes) => Promise<Bytes>;
11
+ export declare const sha256Hex: (b: Bytes) => Promise<string>;
12
+ export declare const randomBytes: (n: number) => Bytes;
13
+ /** Malformed, truncated, tampered or unsupported stored data. */
14
+ export declare class FormatError extends Error {
15
+ name: string;
16
+ }
@@ -0,0 +1,143 @@
1
+ import { type Bytes } from "./bytes";
2
+ import { type Layout } from "./format";
3
+ /** HKDF-SHA256 with an empty salt, 32 bytes out. */
4
+ export declare function hkdf(ikm: Bytes, info: Bytes): Promise<Bytes>;
5
+ export declare const blockNonce: (piece: number, block: number) => Bytes;
6
+ /** Seals and opens the blocks of one encrypted version. */
7
+ export declare class BlockCipher {
8
+ private readonly key;
9
+ private readonly versionId;
10
+ private constructor();
11
+ static create(fileKey: Bytes, versionId: string): Promise<BlockCipher>;
12
+ aad(piece: number, block: number, final: boolean): Bytes;
13
+ /** `ciphertext || tag`. */
14
+ sealBlock(plain: Bytes, piece: number, block: number, final: boolean): Promise<Bytes>;
15
+ /** Throws if the block was altered, moved, swapped or its final flag is wrong. */
16
+ openBlock(stored: Bytes, piece: number, block: number, final: boolean): Promise<Bytes>;
17
+ sealPiece(plain: Bytes, piece: number, layout: Layout): Promise<Bytes>;
18
+ /** Opens a whole stored piece; a wrong length counts as truncation. */
19
+ openPiece(stored: Bytes, piece: number, layout: Layout): Promise<Bytes>;
20
+ /** Opens blocks [first, end) of a piece from their stored bytes (a PieceRead's stored range). */
21
+ openBlocks(stored: Bytes, piece: number, first: number, end: number, layout: Layout): Promise<Bytes>;
22
+ }
23
+ export declare const generateKey: () => Bytes;
24
+ export declare function wrapKey(key: Bytes, wrappingKey: Bytes, nonce?: Bytes): Promise<Bytes>;
25
+ export declare function unwrapKey(wrapped: Bytes, wrappingKey: Bytes): Promise<Bytes>;
26
+ /** A file key wrapped by the master key, as the manifest's base64 `wrappedFileKey`. */
27
+ export declare const wrapFileKey: (fileKey: Bytes, masterKey: Bytes, nonce?: Bytes) => Promise<string>;
28
+ export declare const unwrapFileKey: (wrappedB64: string, masterKey: Bytes) => Promise<Bytes>;
29
+ /**
30
+ * Proof of holding the master key, sent with PUT /v1/account/keys: base64url (no padding) of
31
+ * HKDF-SHA256(masterKey, empty salt, info "phantomdrive/key-proof/v1"), 32 bytes. One-way, so it reveals nothing
32
+ * about the master key; the server keeps only its SHA-256.
33
+ */
34
+ export declare const keyProof: (masterKey: Bytes) => Promise<string>;
35
+ /**
36
+ * The account's key check, stored with the recovery copy and served by GET /v1/account/keys as
37
+ * `keyCheck: { version: 1, value }`: base64url (no padding) of HKDF-SHA256(masterKey, empty salt, info
38
+ * "phantomdrive/key-check/v1"), 32 bytes. A new device checks an approved master key against it before using it.
39
+ * Not the proof: the proof stays secret from other device tokens, the check is public to them.
40
+ */
41
+ export declare const KEY_CHECK_INFO = "phantomdrive/key-check/v1";
42
+ export declare const KEY_CHECK_VERSION = 1;
43
+ export declare const keyCheck: (masterKey: Bytes) => Promise<string>;
44
+ /** True only when `check` is a version-1 key check made from this master key. Constant-time compare. */
45
+ export declare function matchesKeyCheck(masterKey: Bytes, check: {
46
+ version: number;
47
+ value: string;
48
+ } | null | undefined): Promise<boolean>;
49
+ export declare const nameKey: (masterKey: Bytes) => Promise<Bytes>;
50
+ /**
51
+ * Name v2 (M5): `"2." + base64url(nonce || ciphertext || tag)`, AES-256-GCM under the name key with AAD
52
+ * `"phantomdrive/names/v2" || nodeId`, so a sealed name opens only as the name of the node it was sealed for.
53
+ * v1 (no prefix, no AAD) is still read while the account's `namesVersion` is below 2.
54
+ */
55
+ export declare const NAMES_V2_PREFIX = "2.";
56
+ /** Seals the NFC UTF-8 name of `nodeId` as v2. */
57
+ export declare function sealName(nameKeyRaw: Bytes, name: string, nodeId: string, nonce?: Bytes): Promise<string>;
58
+ /** v1 (no binding), for the shared vectors only: nothing new is sealed this way. */
59
+ export declare function sealNameV1(nameKeyRaw: Bytes, name: string, nonce?: Bytes): Promise<string>;
60
+ /**
61
+ * Opens the name of `nodeId` in the version its prefix names, never trying the other (no downgrade). `v1Allowed`
62
+ * false (the account's namesVersion is 2) refuses a v1 name.
63
+ */
64
+ export declare function openName(nameKeyRaw: Bytes, sealed: string, nodeId: string, v1Allowed?: boolean): Promise<string>;
65
+ /**
66
+ * What an encrypted folder link opens: each node's plaintext name and, for a file, the version shared and its file
67
+ * key (absent when that version's bytes are not encrypted). Taken when the link is made; nothing added later.
68
+ * Stored on the server sealed under the link's share key (`shareLinkKey`), which travels only in the link's `#s=`:
69
+ * base64url (no padding) of `nonce (12) || AES-256-GCM(shareKey, nonce, json, aad = UTF-8 SHARE_KEYRING_AAD) || tag`.
70
+ * `json` is sorted-key JSON `{"formatVersion":1,"nodes":{"<id>":{"fileKey"?:b64url,"name":string,"versionId"?:string}},"rootId"?:string}`
71
+ * with node ids sorted. `rootId` (optional, added 12 Nov) is the shared folder's node id: it ties the keyring to its
72
+ * link, so the owner can check a keyring the server hands back (`rebuildShareLinkKey`). Vectors:
73
+ * cloud/shared/test/vectors/share-keyring-v1.json (without rootId) and share-keyring-v1-root.json (with).
74
+ */
75
+ export interface ShareKeyring {
76
+ formatVersion: number;
77
+ nodes: Record<string, {
78
+ name: string;
79
+ versionId?: string;
80
+ fileKey?: Bytes;
81
+ }>;
82
+ rootId?: string;
83
+ }
84
+ export declare const SHARE_KEYRING_AAD = "phantomdrive/share-keyring/v1";
85
+ /**
86
+ * The share key of one folder link: HKDF-SHA256(masterKey, empty salt, info = UTF-8 "phantomdrive/share-link/v1" ||
87
+ * the keyring's 12-byte nonce), 32 bytes. One-way, so the link reveals nothing about the master key, and the owner can
88
+ * rebuild the link later from the stored keyring's nonce.
89
+ */
90
+ export declare const shareLinkKey: (masterKey: Bytes, nonce: Bytes) => Promise<Bytes>;
91
+ export declare const keyringNonce: (sealed: string) => Uint8Array<ArrayBuffer>;
92
+ export declare function shareKeyringJson(k: ShareKeyring): string;
93
+ export declare function sealShareKeyring(k: ShareKeyring, shareKey: Bytes, nonce?: Bytes): Promise<string>;
94
+ export declare function openShareKeyring(sealed: string, shareKey: Bytes): Promise<ShareKeyring>;
95
+ /**
96
+ * The share key of a link made earlier, for the owner's Copy: derived from the stored keyring's nonce, then checked.
97
+ * The server hands back the keyring, so it could hand back another link's (for example one to a parent folder) and
98
+ * have the owner send that link's key to this link's recipient. Throws unless the keyring opens with the rebuilt key
99
+ * and names `rootId` as its shared folder; a keyring made before rootId cannot be checked, so make a new link.
100
+ */
101
+ export declare function rebuildShareLinkKey(masterKey: Bytes, sealed: string, rootId: string): Promise<Bytes>;
102
+ export declare const recoveryChecksum: (key: Bytes) => Promise<number>;
103
+ /** Parses typed text, ignoring spaces, dashes, line breaks and case; O reads as 0, I and L as 1. */
104
+ export declare function parseRecoveryKey(text: string): Promise<Bytes>;
105
+ /** The 52 characters in 13 groups of four joined by dashes. */
106
+ export declare function formatRecoveryKey(key: Bytes): Promise<string>;
107
+ export declare const recoveryWrappingKey: (recoveryKey: Bytes) => Promise<Bytes>;
108
+ export declare const wrapMasterKey: (masterKey: Bytes, recoveryKey: Bytes, nonce?: Bytes) => Promise<Bytes>;
109
+ export declare const unwrapMasterKey: (wrapped: Bytes, recoveryKey: Bytes) => Promise<Bytes>;
110
+ /**
111
+ * @deprecated H3 (docs/SECURITY_REVIEW.md): a malicious server can grind this code in seconds. Use the
112
+ * commit-then-reveal `approvalCodeV2`. Kept only so the old testdata/keys.json vector still checks; never show it.
113
+ */
114
+ export declare function approvalCode(newDevicePub: Bytes, approverPub: Bytes): Promise<string>;
115
+ export declare const APPROVAL_V2_INFO = "phantomdrive/approval/v2";
116
+ /** C = SHA-256(N || rn), which the new device registers with N before it sees ra. */
117
+ export declare function approvalCommitment(newDevicePub: Bytes, rn: Bytes): Promise<Bytes>;
118
+ /** The approver's check of the revealed rn against the registered C. False means stop: the exchange was tampered with. */
119
+ export declare function checkApprovalCommitment(newDevicePub: Bytes, rn: Bytes, commitment: Bytes): Promise<boolean>;
120
+ /** The six digits both Macs show. Both must match before the master key is wrapped to N. */
121
+ export declare function approvalCodeV2(newDevicePub: Bytes, approverPub: Bytes, rn: Bytes, ra: Bytes): Promise<string>;
122
+ export declare const APPROVAL_KEY_INFO = "phantomdrive/approval-key/v2";
123
+ export declare const APPROVAL_KEY_FORMAT = 2;
124
+ /** The approver, once the user confirmed the digits: `approverPriv` is A's private key. */
125
+ export declare function wrapApprovedMasterKey(masterKey: Bytes, approverPriv: CryptoKey, A: Bytes, N: Bytes, rn: Bytes, ra: Bytes, nonce?: Bytes): Promise<Bytes>;
126
+ /** The new device, with the A and ra behind the digits it showed. Throws unless A's holder made the copy. */
127
+ export declare function unwrapApprovedMasterKey(wrapped: Bytes, newDevicePriv: CryptoKey, N: Bytes, A: Bytes, rn: Bytes, ra: Bytes): Promise<Bytes>;
128
+ /** Imports a P-256 private key from its 32-byte scalar and 65-byte uncompressed public key. */
129
+ export declare function importP256Private(d: Bytes, pub: Bytes): Promise<CryptoKey>;
130
+ /** `ephemeral public key (65) || nonce || ciphertext || tag`. The ephemeral key is made here unless given (tests). */
131
+ export declare function wrapMasterKeyToDevice(masterKey: Bytes, recipientPub: Bytes, ephemeral?: {
132
+ d: Bytes;
133
+ pub: Bytes;
134
+ }, nonce?: Bytes): Promise<Bytes>;
135
+ export declare function unwrapMasterKeyForDevice(wrapped: Bytes, devicePriv: CryptoKey, devicePub: Bytes): Promise<Bytes>;
136
+ export interface KeyBundle {
137
+ formatVersion: number;
138
+ recoveryWrappedMasterKey: Bytes;
139
+ deviceWrappedMasterKeys: Record<string, Bytes>;
140
+ }
141
+ /** Sorted-key JSON; binary fields are standard base64. */
142
+ export declare function encodeKeyBundle(k: KeyBundle): string;
143
+ export declare function decodeKeyBundle(json: string): KeyBundle;
@@ -0,0 +1,35 @@
1
+ export declare const FORMAT_VERSION = 1;
2
+ export declare const PIECE_SIZE: number;
3
+ export declare const BLOCK_SIZE: number;
4
+ export declare const TAG_SIZE = 16;
5
+ export declare const STORED_BLOCK_SIZE: number;
6
+ /** One Range request inside a piece object, block-aligned in both modes. Ends are exclusive. */
7
+ export interface PieceRead {
8
+ piece: number;
9
+ blockStart: number;
10
+ blockEnd: number;
11
+ storedStart: number;
12
+ storedEnd: number;
13
+ /** Where the requested bytes sit inside the concatenated plaintext of the blocks. */
14
+ sliceStart: number;
15
+ sliceEnd: number;
16
+ }
17
+ /** Where a version's bytes live across pieces and blocks. */
18
+ export declare class Layout {
19
+ readonly plaintextSize: number;
20
+ readonly encrypted: boolean;
21
+ constructor(plaintextSize: number, encrypted: boolean);
22
+ get pieceCount(): number;
23
+ plaintextLength(piece: number): number;
24
+ blockCount(piece: number): number;
25
+ blockLength(piece: number, block: number): number;
26
+ storedLength(piece: number): number;
27
+ isFinalBlock(piece: number, block: number): boolean;
28
+ /** The per-piece fetches for plaintext [start, end), clamped to the file. */
29
+ reads(start: number, end: number): PieceRead[];
30
+ }
31
+ export declare const versionPrefix: (accountId: string, versionId: string) => string;
32
+ export declare const pieceKey: (accountId: string, versionId: string, index: number) => string;
33
+ export declare const manifestKey: (accountId: string, versionId: string) => string;
34
+ /** A new lowercase UUIDv7 (client-made ids, plan 5.1). */
35
+ export declare function uuidv7(): string;
@@ -0,0 +1,6 @@
1
+ export * from "./bytes";
2
+ export * from "./crypto";
3
+ export * from "./format";
4
+ export * from "./manifest";
5
+ export * from "./md5";
6
+ export * from "./transfer";
@@ -0,0 +1,22 @@
1
+ import { type Bytes } from "./bytes";
2
+ export interface Manifest {
3
+ formatVersion: number;
4
+ versionId: string;
5
+ plaintextSize: number;
6
+ pieceSize: number;
7
+ blockSize: number;
8
+ encrypted: boolean;
9
+ /** Lowercase hex SHA-256 of each stored piece object. */
10
+ pieceHashes: string[];
11
+ /** Standard base64 of the file key wrapped by the master key; only when encrypted. */
12
+ wrappedFileKey?: string;
13
+ }
14
+ export declare const newManifest: (versionId: string, plaintextSize: number, pieceHashes: string[], wrappedFileKey?: string) => Manifest;
15
+ /** The exact bytes inside the gzip: keys sorted, no whitespace, `wrappedFileKey` omitted when absent. */
16
+ export declare function manifestJson(m: Manifest): string;
17
+ /** The stored manifest object. */
18
+ export declare const encodeManifest: (m: Manifest) => Promise<Bytes>;
19
+ /** Lowercase hex SHA-256 of the stored (gzipped) bytes, as kept in the file tree. */
20
+ export declare const manifestHash: (stored: Bytes) => Promise<string>;
21
+ /** Decodes and validates stored manifest bytes. */
22
+ export declare function decodeManifest(stored: Bytes): Promise<Manifest>;
@@ -0,0 +1 @@
1
+ export declare function md5Hex(data: Uint8Array): string;
@@ -0,0 +1,99 @@
1
+ import { type Bytes } from "./bytes";
2
+ import { BlockCipher } from "./crypto";
3
+ import { Layout } from "./format";
4
+ import { type Manifest } from "./manifest";
5
+ export interface UrlEntry {
6
+ index: number;
7
+ url: string;
8
+ }
9
+ export interface UrlBatch {
10
+ /** A read batch always has one; an upload's piece batch has null (see UploadTarget.manifestUrl). */
11
+ manifestUrl: string | null;
12
+ pieceUrls: UrlEntry[];
13
+ /** Seconds the URLs live (share-link reads: 300). The batch is refetched once 80% of it has passed. */
14
+ expiresIn?: number;
15
+ }
16
+ export interface UploadTarget {
17
+ /** Fresh presigned PUT URLs for pieces [from, from + count). */
18
+ urls(from: number, count: number): Promise<UrlBatch>;
19
+ /** A presigned PUT URL for the manifest, signed for exactly `size` bytes. */
20
+ manifestUrl(size: number): Promise<string>;
21
+ /**
22
+ * PUTs with `If-None-Match: *` and the exact length the URL was signed for. Resolves once the object exists:
23
+ * a 412 means it already did (a retry after a lost answer), which a resume has checked by ETag beforehand.
24
+ */
25
+ put(url: string, body: Bytes, signal?: AbortSignal): Promise<void>;
26
+ /** For resume: what the upload already holds, `key` "p/00000000" or "manifest", `etag` the lowercase hex MD5. */
27
+ objects?(): Promise<{
28
+ key: string;
29
+ etag: string;
30
+ }[]>;
31
+ /** Commits. Returns null when committed, else the piece indexes the server lacks or holds at the wrong size. */
32
+ complete(manifestHash: string): Promise<number[] | null>;
33
+ }
34
+ export interface UploadOptions {
35
+ versionId: string;
36
+ /** Present for encrypted accounts: the version's file key and its master-key wrap for the manifest. */
37
+ encryption?: {
38
+ fileKey: Bytes;
39
+ wrappedFileKey: string;
40
+ };
41
+ /** URLs already returned when the upload started. */
42
+ first?: UrlBatch;
43
+ /**
44
+ * Resuming: compare each piece with what the upload already holds (MD5 against the ETag) and send only what is
45
+ * missing. A stored piece or manifest with other bytes cannot be rewritten (create-only URLs), so that throws
46
+ * StaleUploadError: abandon the upload and start a new version.
47
+ */
48
+ resume?: boolean;
49
+ parallel?: number;
50
+ onProgress?: (doneBytes: number, totalBytes: number) => void;
51
+ signal?: AbortSignal;
52
+ }
53
+ /** A resumed upload's stored objects differ from this file: start a new version instead. */
54
+ export declare class StaleUploadError extends Error {
55
+ name: string;
56
+ }
57
+ /** Up to 5 attempts with backoff (plan 9.4). */
58
+ export declare function retry<T>(fn: () => Promise<T>, signal?: AbortSignal, attempts?: number, baseMs?: number): Promise<T>;
59
+ /** The stored bytes of one piece: plaintext as is, or sealed block by block. */
60
+ export declare function storedPiece(src: Blob, layout: Layout, piece: number, cipher?: BlockCipher): Promise<Bytes>;
61
+ /** Uploads one version of `src`. Returns the manifest and its hash once the server has committed it. */
62
+ export declare function uploadVersion(src: Blob, opts: UploadOptions, target: UploadTarget): Promise<{
63
+ manifest: Manifest;
64
+ manifestHash: string;
65
+ }>;
66
+ export interface ReadUrlBatch extends UrlBatch {
67
+ manifestUrl: string;
68
+ versionId: string;
69
+ size: number;
70
+ pieceCount: number;
71
+ manifestHash: string;
72
+ /** Whether the version is sealed, as its uploader declared (servers since 23 Nov 2026). */
73
+ encrypted?: boolean;
74
+ }
75
+ export interface DownloadSource {
76
+ /** The version the caller asked for; the manifest must name it (M5). Without it, the batch's versionId is used. */
77
+ versionId?: string;
78
+ /** Presigned GET URLs for pieces [from, from + count) plus the manifest. */
79
+ readUrls(from: number, count: number): Promise<ReadUrlBatch>;
80
+ get(url: string, signal?: AbortSignal): Promise<Bytes>;
81
+ }
82
+ /** The file key of an encrypted manifest, from the master key (owner) or given directly (a `#k=` share link). */
83
+ export declare function fileKeyOf(m: Manifest, keys: {
84
+ masterKey?: Bytes;
85
+ fileKey?: Bytes;
86
+ }): Promise<Bytes>;
87
+ /** Fetches and verifies a version's manifest, including that it is the version asked for. */
88
+ export declare function fetchManifest(src: DownloadSource, first: ReadUrlBatch, signal?: AbortSignal): Promise<Manifest>;
89
+ /**
90
+ * Downloads a whole version, verifying every piece, and hands plaintext to `sink` in order. Up to 3 pieces are
91
+ * fetched ahead of the one being written, so memory stays near 32 MiB whatever the file size.
92
+ */
93
+ export declare function downloadVersion(src: DownloadSource, keys: {
94
+ masterKey?: Bytes;
95
+ fileKey?: Bytes;
96
+ }, sink: (chunk: Bytes) => Promise<void> | void, opts?: {
97
+ onProgress?: (done: number, total: number) => void;
98
+ signal?: AbortSignal;
99
+ }): Promise<Manifest>;
package/package.json CHANGED
@@ -1,6 +1,17 @@
1
1
  {
2
2
  "name": "phantomdisk",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "PhantomDisk for programs and AI agents: read and write a drive with one access key. No mount, no helper program.",
5
+ "license": "MIT",
6
+ "homepage": "https://phantomdisk.com/docs/sdk",
7
+ "keywords": ["phantomdisk", "storage", "cloud drive", "files", "ai agents", "encryption"],
8
+ "type": "module",
9
+ "exports": { ".": { "types": "./dist/types/sdk/src/index.d.ts", "default": "./dist/index.js" } },
10
+ "files": ["dist", "!dist/types/sdk/test", "README.md"],
11
+ "engines": { "node": ">=20" },
12
+ "scripts": {
13
+ "typecheck": "../shared/node_modules/.bin/tsc --noEmit",
14
+ "test": "node --experimental-transform-types --disable-warning=ExperimentalWarning --import ./test/register.mjs --test test/*.test.ts",
15
+ "build": "../api/node_modules/.bin/esbuild src/index.ts --bundle --format=esm --platform=neutral --target=es2022 --outfile=dist/index.js && ../shared/node_modules/.bin/tsc --noEmit false --declaration --emitDeclarationOnly --outDir dist/types"
16
+ }
17
+ }