@synonymdev/pubky 0.6.0-rc.2 → 0.6.0-rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. package/README.md +117 -40
  2. package/index.cjs +499 -147
  3. package/index.js +534 -152
  4. package/package.json +9 -5
  5. package/pubky.d.ts +296 -186
  6. package/pubky_bg.wasm +0 -0
package/pubky.d.ts CHANGED
@@ -3,13 +3,13 @@
3
3
  /**
4
4
  * Set the global logging verbosity for the WASM Pubky SDK. Routes Rust `log` output to the browser console.
5
5
  *
6
- * Accepted values (case-insensitive): "error" | "warn" | "info" | "debug" | "trace".
6
+ * Accepted values (case-sensitive): "error" | "warn" | "info" | "debug" | "trace".
7
7
  * Effects:
8
8
  * - Initializes the logger once; subsequent calls may throw if the logger is already set.
9
9
  * - Emits a single info log: `Log level set to: <level>`.
10
10
  * - Messages at or above `level` are forwarded to the appropriate `console.*` method.
11
11
  *
12
- * @param {string} level
12
+ * @param {Level} level
13
13
  * Minimum log level to enable. One of: "error" | "warn" | "info" | "debug" | "trace".
14
14
  *
15
15
  * @returns {void}
@@ -21,7 +21,14 @@
21
21
  * Usage:
22
22
  * Call once at application startup, before invoking other SDK APIs.
23
23
  */
24
- export function setLogLevel(level: string): void;
24
+ export function setLogLevel(level: Level): void;
25
+ /**
26
+ * Resolve a `pubky://` or `pubky<pk>/…` identifier into the homeserver transport URL.
27
+ *
28
+ * @param {string} identifier Either `pubky<pk>/...` (preferred) or `pubky://<pk>/...`.
29
+ * @returns {string} HTTPS URL in the form `https://_pubky.<pk>/...`.
30
+ */
31
+ export function resolvePubky(identifier: string): string;
25
32
  /**
26
33
  * Validate and normalize a capabilities string.
27
34
  *
@@ -30,12 +37,64 @@ export function setLogLevel(level: string): void;
30
37
  *
31
38
  * @param {string} input
32
39
  * @returns {string} Normalized string (same shape as input).
33
- * @throws {PubkyJsError} `{ name: "InvalidInput" }` with a helpful message.
40
+ * @throws {PubkyError} `{ name: "InvalidInput" }` with a helpful message.
41
+ * The error's `data` field is `{ invalidEntries: string[] }` listing malformed tokens.
34
42
  */
35
43
  export function validateCapabilities(input: string): string;
44
+ /**
45
+ * An enum representing the available verbosity levels of the logger.
46
+ */
47
+ type Level = "error" | "warn" | "info" | "debug" | "trace";
48
+ /**
49
+ * The `ReadableStreamType` enum.
50
+ *
51
+ * *This API requires the following crate features to be activated: `ReadableStreamType`*
52
+ */
53
+ type ReadableStreamType = "bytes";
54
+ /**
55
+ * Resource metadata returned by `SessionStorage.stats()` and `PublicStorage.stats()`.
56
+ *
57
+ * @typedef {Object} ResourceStats
58
+ * @property {number=} contentLength Size in bytes.
59
+ * @property {string=} contentType Media type (e.g. \"application/json; charset=utf-8\").
60
+ * @property {number=} lastModifiedMs Unix epoch milliseconds.
61
+ * @property {string=} etag Opaque server ETag for the current version.
62
+ *
63
+ * @example
64
+ * const stats = await pubky.publicStorage.stats(`${user}/pub/app/file.json`);
65
+ * if (stats) {
66
+ * console.log(stats.contentLength, stats.contentType, stats.lastModifiedMs);
67
+ * }
68
+ *
69
+ * Notes:
70
+ * - `contentLength` equals `getBytes(...).length`.
71
+ * - `etag` may be absent and is opaque; compare values to detect updates.
72
+ * - `lastModifiedMs` increases when the resource is updated.
73
+ */
74
+ export interface ResourceStats {
75
+ /**
76
+ * Size in bytes of the stored object.
77
+ */
78
+ contentLength?: number;
79
+ /**
80
+ * Media type of the stored object (e.g., `\"application/json\"`).
81
+ */
82
+ contentType?: string;
83
+ /**
84
+ * Unix epoch **milliseconds** for the last modification time.
85
+ */
86
+ lastModifiedMs?: number;
87
+ /**
88
+ * Opaque entity tag identifying the current stored version.
89
+ */
90
+ etag?: string;
91
+ }
92
+
93
+ export type Path = `/pub/${string}`;
94
+
36
95
  /**
37
96
  * A union type of all possible machine-readable codes for the `name` property
38
- * of a {@link PubkyJsError}.
97
+ * of a {@link PubkyError}.
39
98
  *
40
99
  * Provides a simplified, actionable set of error categories for developers
41
100
  * to handle in their code.
@@ -55,23 +114,62 @@ export type PubkyErrorName = "RequestError" | "InvalidInput" | "AuthenticationEr
55
114
  * try {
56
115
  * await client.signup(...);
57
116
  * } catch (e) {
58
- * const error = e as PubkyJsError;
59
- * if (error.name === \'RequestError\' && error.statusCode === 404) {
117
+ * const error = e as PubkyError;
118
+ * if (
119
+ * error.name === \'RequestError\' &&
120
+ * typeof error.data === \'object\' &&
121
+ * error.data !== null &&
122
+ * \'statusCode\' in error.data &&
123
+ * (error.data as { statusCode?: number }).statusCode === 404
124
+ * ) {
60
125
  * // Handle not found...
61
126
  * }
62
127
  * }
63
128
  * ```
64
129
  */
65
- export interface PubkyJsError {
130
+ export interface PubkyError {
66
131
  name: PubkyErrorName;
67
132
  message: string;
68
133
  /**
69
- * For `RequestError::Server`, this carries the numeric HTTP status code (e.g. 404).
70
- * Otherwise `undefined` on the JS side.
134
+ * Optional structured context associated with the error.
71
135
  */
72
- statusCode?: number;
136
+ data?: unknown;
137
+ }
138
+
139
+ /**
140
+ * Represents the standard error structure for all exceptions thrown by the Pubky
141
+ * WASM client.
142
+ *
143
+ * @property name - A machine-readable error code from {@link PubkyErrorName}. Use this for programmatic error handling.
144
+ * @property message - A human-readable, descriptive error message suitable for logging.
145
+ * @property data - An optional payload containing structured context for an error. For a `RequestError`, this may contain an object with the HTTP status code, e.g., `{ statusCode: 404 }`.
146
+ *
147
+ * @example
148
+ * ```typescript
149
+ * try {
150
+ * await client.signup(...);
151
+ * } catch (e) {
152
+ * const error = e as PubkyError;
153
+ * if (
154
+ * error.name === "RequestError" &&
155
+ * typeof error.data === "object" &&
156
+ * error.data !== null &&
157
+ * "statusCode" in error.data &&
158
+ * (error.data as { statusCode?: number }).statusCode === 404
159
+ * ) {
160
+ * // Handle not found...
161
+ * }
162
+ * }
163
+ * ```
164
+ */
165
+ export interface PubkyError extends Error {
166
+ name: PubkyErrorName;
167
+ message: string;
168
+ data?: unknown;
73
169
  }
74
170
 
171
+ export type Address = `pubky${string}/pub/${string}` | `pubky://${string}/pub/${string}`;
172
+
75
173
  /**
76
174
  * Pkarr Config
77
175
  */
@@ -97,44 +195,11 @@ export interface PubkyClientConfig {
97
195
  pkarr?: PkarrConfig;
98
196
  }
99
197
 
100
- /**
101
- * Resource metadata returned by `SessionStorage.stats()` and `PublicStorage.stats()`.
102
- *
103
- * @typedef {Object} ResourceStats
104
- * @property {number=} contentLength Size in bytes.
105
- * @property {string=} contentType Media type (e.g. \"application/json; charset=utf-8\").
106
- * @property {number=} lastModifiedMs Unix epoch milliseconds.
107
- * @property {string=} etag Opaque server ETag for the current version.
108
- *
109
- * @example
110
- * const stats = await pubky.publicStorage().stats(`${user}/pub/app/file.json`);
111
- * if (stats) {
112
- * console.log(stats.contentLength, stats.contentType, stats.lastModifiedMs);
113
- * }
114
- *
115
- * Notes:
116
- * - `contentLength` equals `getBytes(...).length`.
117
- * - `etag` may be absent and is opaque; compare values to detect updates.
118
- * - `lastModifiedMs` increases when the resource is updated.
119
- */
120
- export interface ResourceStats {
121
- /**
122
- * Size in bytes of the stored object.
123
- */
124
- contentLength?: number;
125
- /**
126
- * Media type of the stored object (e.g., `\"application/json\"`).
127
- */
128
- contentType?: string;
129
- /**
130
- * Unix epoch **milliseconds** for the last modification time.
131
- */
132
- lastModifiedMs?: number;
133
- /**
134
- * Opaque entity tag identifying the current stored version.
135
- */
136
- etag?: string;
137
- }
198
+ export type CapabilityAction = "r" | "w" | "rw";
199
+ export type CapabilityScope = `/${string}`;
200
+ export type CapabilityEntry = `${CapabilityScope}:${CapabilityAction}`;
201
+ type CapabilitiesTail = `,${CapabilityEntry}${string}`;
202
+ export type Capabilities = "" | CapabilityEntry | `${CapabilityEntry}${CapabilitiesTail}`;
138
203
 
139
204
  /**
140
205
  * Start and control a pubkyauth authorization flow.
@@ -149,7 +214,7 @@ export class AuthFlow {
149
214
  free(): void;
150
215
  /**
151
216
  * Start a flow (standalone).
152
- * Prefer `pubky.startAuthFlow()` to reuse a façade client.
217
+ * Prefer `pubky.startAuthFlow()` to reuse a facade client.
153
218
  *
154
219
  * @param {string} capabilities
155
220
  * Comma-separated capabilities, e.g. `"/pub/app/:rw,/priv/foo.txt:r"`.
@@ -165,7 +230,7 @@ export class AuthFlow {
165
230
  * @returns {AuthFlow}
166
231
  * A running auth flow. Call `authorizationUrl()` to show the deep link,
167
232
  * then `awaitApproval()` to receive a `Session`.
168
- * @throws {PubkyJsError}
233
+ * @throws {PubkyError}
169
234
  * - `{ name: "InvalidInput", message: string }` if any capability entry is invalid
170
235
  * or for an invalid relay URL.
171
236
  * @example
@@ -173,23 +238,14 @@ export class AuthFlow {
173
238
  * renderQRCode(flow.authorizationUrl());
174
239
  * const session = await flow.awaitApproval();
175
240
  */
176
- static start(capabilities: string, relay?: string | null): AuthFlow;
177
- /**
178
- * Return the authorization deep link (URL) to show as QR or open on the signer device.
179
- *
180
- * @returns {string} A `pubkyauth://…` or `https://…` URL with channel info.
181
- *
182
- * @example
183
- * renderQr(flow.authorizationUrl());
184
- */
185
- authorizationUrl(): string;
241
+ static start(capabilities: Capabilities, relay?: string | null): AuthFlow;
186
242
  /**
187
243
  * Block until the user approves on their signer device; returns a `Session`.
188
244
  *
189
245
  * @returns {Promise<Session>}
190
246
  * Resolves when approved; rejects on timeout/cancel/network errors.
191
247
  *
192
- * @throws {PubkyJsError}
248
+ * @throws {PubkyError}
193
249
  * - `RequestError` if relay/network fails
194
250
  * - `AuthenticationError` if approval is denied/invalid
195
251
  */
@@ -200,16 +256,25 @@ export class AuthFlow {
200
256
  * @returns {Promise<AuthToken>}
201
257
  * Resolves when approved; rejects on timeout/cancel/network errors.
202
258
  *
203
- * @throws {PubkyJsError}
259
+ * @throws {PubkyError}
204
260
  * - `RequestError` if relay/network fails
205
261
  */
206
262
  awaitToken(): Promise<AuthToken>;
207
263
  /**
208
264
  * Non-blocking single poll step (advanced UIs).
209
265
  *
210
- * @returns {Promise<Session|null>} A session if the approval arrived, otherwise `null`.
266
+ * @returns {Promise<Session|undefined>} A session if the approval arrived, otherwise `undefined`.
211
267
  */
212
268
  tryPollOnce(): Promise<Session | undefined>;
269
+ /**
270
+ * Return the authorization deep link (URL) to show as QR or open on the signer device.
271
+ *
272
+ * @returns {string} A `pubkyauth://…` or `https://…` URL with channel info.
273
+ *
274
+ * @example
275
+ * renderQr(flow.authorizationUrl());
276
+ */
277
+ readonly authorizationUrl: string;
213
278
  }
214
279
  /**
215
280
  * AuthToken: signed, time-bound proof of key ownership.
@@ -269,15 +334,25 @@ export class AuthToken {
269
334
  */
270
335
  static fromBytes(bytes: Uint8Array): AuthToken;
271
336
  /**
272
- * Returns the **public key** that authenticated with this token.
337
+ * Serialize the token to a `Uint8Array` in its **canonical** (postcard) binary format.
273
338
  *
274
- * Use `.z32()` on the returned `PublicKey` to get the string form.
339
+ * Use this to send the token to a backend for verification.
275
340
  *
276
341
  * ```js
277
- * const who = token.publicKey().z32();
342
+ * const bytes = token.toBytes();
343
+ * await fetch("/api/verify", { method: "POST", body: bytes });
278
344
  * ```
279
345
  */
280
- publicKey(): PublicKey;
346
+ toBytes(): Uint8Array;
347
+ /**
348
+ * Returns the **public key** that authenticated with this token.
349
+ *
350
+ * Use `.z32()` on the returned `PublicKey` to get the string form.
351
+ *
352
+ * @example
353
+ * const who = sessionInfo.publicKey.z32();
354
+ */
355
+ readonly publicKey: PublicKey;
281
356
  /**
282
357
  * Returns the **capabilities** requested by the flow at the time this token was signed.
283
358
  *
@@ -288,27 +363,28 @@ export class AuthToken {
288
363
  *
289
364
  * Example entry: `"/pub/my.app/:rw"`
290
365
  */
291
- capabilities(): Array<any>;
292
- /**
293
- * Serialize the token to a `Uint8Array` in its **canonical** (postcard) binary format.
294
- *
295
- * Use this to send the token to a backend for verification.
296
- *
297
- * ```js
298
- * const bytes = token.toBytes();
299
- * await fetch("/api/verify", { method: "POST", body: bytes });
300
- * ```
301
- */
302
- toBytes(): Uint8Array;
366
+ readonly capabilities: string[];
303
367
  }
304
368
  /**
305
- * Low-level HTTP bridge used by the Pubky façade and actors.
369
+ * Low-level HTTP bridge used by the Pubky facade and actors.
306
370
  *
307
- * - Supports `pubky://<user-z32>/<abs-path>` and `http(s)://` URLs.
371
+ * - Supports `http(s)://` URLs targeting Pubky or ICANN hosts.
308
372
  * - In browsers/undici, passes `credentials: "include"` to send cookies.
309
373
  */
310
374
  export class Client {
311
375
  free(): void;
376
+ /**
377
+ * Perform a raw fetch. Works with `http(s)://` URLs.
378
+ *
379
+ * @param {string} url
380
+ * @param {RequestInit} init Standard fetch options; `credentials: "include"` recommended for session I/O.
381
+ * @returns {Promise<Response>}
382
+ *
383
+ * @example
384
+ * const client = pubky.client;
385
+ * const res = await client.fetch(`https://_pubky.${user}/pub/app/file.txt`, { method: "PUT", body: "hi", credentials: "include" });
386
+ */
387
+ fetch(url: string, init?: RequestInit | null): Promise<Response>;
312
388
  /**
313
389
  * Create a Pubky HTTP client.
314
390
  *
@@ -317,7 +393,7 @@ export class Client {
317
393
  * `{ pkarr?: { relays?: string[], request_timeout?: number } }`.
318
394
  *
319
395
  * @returns {Client}
320
- * A configured low-level client. Prefer `new Pubky().client()` unless you
396
+ * A configured low-level client. Prefer `new Pubky().client` unless you
321
397
  * need custom relays/timeouts.
322
398
  *
323
399
  * @throws {InvalidInput}
@@ -333,8 +409,7 @@ export class Client {
333
409
  /**
334
410
  * Create a client wired for **local testnet**.
335
411
  *
336
- * Sets PKARR relays to `http://<host>:15411/` and enables WASM `pubky://`
337
- * mapping for that host.
412
+ * Configures PKARR relays for the testnet and remembers the hostname for WASM `_pubky` mapping.
338
413
  *
339
414
  * @param {string} [host="localhost"]
340
415
  * Testnet hostname or IP.
@@ -350,18 +425,28 @@ export class Client {
350
425
  * const client = Client.testnet("docker0"); // custom host
351
426
  */
352
427
  static testnet(host?: string | null): Client;
353
- /**
354
- * Perform a raw fetch. Works with `pubky://` or `http(s)://` URLs.
355
- *
356
- * @param {string} url
357
- * @param {RequestInit=} init Standard fetch options; `credentials: "include"` recommended for session I/O.
358
- * @returns {Promise<Response>}
359
- *
360
- * @example
361
- * const client = pubky.client();
362
- * const res = await client.fetch(`pubky://${user}/pub/app/file.txt`, { method: "PUT", body: "hi", credentials: "include" });
363
- */
364
- fetch(url: string, init?: any | null): Promise<Promise<any>>;
428
+ }
429
+ export class IntoUnderlyingByteSource {
430
+ private constructor();
431
+ free(): void;
432
+ start(controller: ReadableByteStreamController): void;
433
+ pull(controller: ReadableByteStreamController): Promise<any>;
434
+ cancel(): void;
435
+ readonly type: ReadableStreamType;
436
+ readonly autoAllocateChunkSize: number;
437
+ }
438
+ export class IntoUnderlyingSink {
439
+ private constructor();
440
+ free(): void;
441
+ write(chunk: any): Promise<any>;
442
+ close(): Promise<any>;
443
+ abort(reason: any): Promise<any>;
444
+ }
445
+ export class IntoUnderlyingSource {
446
+ private constructor();
447
+ free(): void;
448
+ pull(controller: ReadableStreamDefaultController): Promise<any>;
449
+ cancel(): void;
365
450
  }
366
451
  export class Keypair {
367
452
  private constructor();
@@ -378,10 +463,6 @@ export class Keypair {
378
463
  * Returns the secret key of this keypair.
379
464
  */
380
465
  secretKey(): Uint8Array;
381
- /**
382
- * Returns the [PublicKey] of this keypair.
383
- */
384
- publicKey(): PublicKey;
385
466
  /**
386
467
  * Create a recovery file for this keypair (encrypted with the given passphrase).
387
468
  */
@@ -390,6 +471,15 @@ export class Keypair {
390
471
  * Decrypt a recovery file and return a Keypair (decrypted with the given passphrase).
391
472
  */
392
473
  static fromRecoveryFile(recovery_file: Uint8Array, passphrase: string): Keypair;
474
+ /**
475
+ * Returns the [PublicKey] of this keypair.
476
+ *
477
+ * Use `.z32()` on the returned `PublicKey` to get the string form.
478
+ *
479
+ * @example
480
+ * const who = keypair.publicKey.z32();
481
+ */
482
+ readonly publicKey: PublicKey;
393
483
  }
394
484
  /**
395
485
  * Resolve/publish `_pubky` PKDNS records (homeserver pointers).
@@ -408,17 +498,17 @@ export class Pkdns {
408
498
  * Resolve the homeserver for a given public key (read-only).
409
499
  *
410
500
  * @param {PublicKey} user
411
- * @returns {Promise<string|undefined>} Homeserver public key (z32) or `undefined` if not found.
501
+ * @returns {Promise<PublicKey|undefined>} Homeserver public key or `undefined` if not found.
412
502
  */
413
- getHomeserverOf(pubky: PublicKey): Promise<string | undefined>;
503
+ getHomeserverOf(pubky: PublicKey): Promise<PublicKey | undefined>;
414
504
  /**
415
505
  * Resolve the homeserver for **this** user (requires keypair).
416
506
  *
417
- * @returns {Promise<string|undefined>} Homeserver public key (z32) or `undefined` if not found.
507
+ * @returns {Promise<PublicKey|undefined>} Homeserver public key or `undefined` if not found.
418
508
  */
419
- getHomeserver(): Promise<string | undefined>;
509
+ getHomeserver(): Promise<PublicKey | undefined>;
420
510
  /**
421
- * Republish homeserver if record is missing/stale.
511
+ * Force publish homeserver immediately (even if fresh).
422
512
  *
423
513
  * Requires keypair or to be signer bound.
424
514
  *
@@ -427,7 +517,7 @@ export class Pkdns {
427
517
  */
428
518
  publishHomeserverForce(host_override?: PublicKey | null): Promise<void>;
429
519
  /**
430
- * Force publish homeserver immediately (even if fresh).
520
+ * Republish homeserver if record is missing/stale.
431
521
  *
432
522
  * Requires keypair or to be signer bound.
433
523
  *
@@ -442,10 +532,10 @@ export class Pkdns {
442
532
  export class Pubky {
443
533
  free(): void;
444
534
  /**
445
- * Create a Pubky façade wired for **mainnet** defaults (public relays).
535
+ * Create a Pubky facade wired for **mainnet** defaults (public relays).
446
536
  *
447
537
  * @returns {Pubky}
448
- * A new façade instance. Use this to create signers, start auth flows, etc.
538
+ * A new facade instance. Use this to create signers, start auth flows, etc.
449
539
  *
450
540
  * @example
451
541
  * const pubky = new Pubky();
@@ -453,7 +543,7 @@ export class Pubky {
453
543
  */
454
544
  constructor();
455
545
  /**
456
- * Create a Pubky façade preconfigured for a **local testnet**.
546
+ * Create a Pubky facade preconfigured for a **local testnet**.
457
547
  *
458
548
  * If `host` is provided, PKARR and HTTP endpoints are derived as `http://<host>:ports/...`.
459
549
  * If omitted, `"localhost"` is assumed (handy for `cargo install pubky-testnet`).
@@ -467,7 +557,7 @@ export class Pubky {
467
557
  */
468
558
  static testnet(host?: string | null): Pubky;
469
559
  /**
470
- * Wrap an existing configured HTTP client into a Pubky façade.
560
+ * Wrap an existing configured HTTP client into a Pubky facade.
471
561
  *
472
562
  * @param {Client} client A previously constructed client.
473
563
  * @returns {Pubky}
@@ -490,19 +580,19 @@ export class Pubky {
490
580
  * @param {string} capabilities Comma-separated caps, e.g. `"/pub/app/:rw,/pub/foo/file:r"`.
491
581
  * @param {string=} relay Optional HTTP relay base (e.g. `"https://…/link/"`).
492
582
  * @returns {AuthFlow}
493
- * A running auth flow. Call `authorizationUrl()` to show a QR/deeplink,
583
+ * A running auth flow. Show `authorizationUrl` as QR/deeplink,
494
584
  * then `awaitApproval()` to obtain a `Session`.
495
585
  *
496
- * @throws {PubkyJsError}
586
+ * @throws {PubkyError}
497
587
  * - `{ name: "InvalidInput" }` for malformed capabilities or bad relay URL
498
588
  * - `{ name: "RequestError" }` if the flow cannot be started (network/relay)
499
589
  *
500
590
  * @example
501
591
  * const flow = pubky.startAuthFlow("/pub/my.app/:rw");
502
- * renderQr(flow.authorizationUrl());
592
+ * renderQr(flow.authorizationUrl);
503
593
  * const session = await flow.awaitApproval();
504
594
  */
505
- startAuthFlow(capabilities: string, relay?: string | null): AuthFlow;
595
+ startAuthFlow(capabilities: Capabilities, relay?: string | null): AuthFlow;
506
596
  /**
507
597
  * Create a `Signer` from an existing `Keypair`.
508
598
  *
@@ -514,6 +604,15 @@ export class Pubky {
514
604
  * const session = await signer.signup(homeserverPk, null);
515
605
  */
516
606
  signer(keypair: Keypair): Signer;
607
+ /**
608
+ * Resolve the homeserver for a given public key (read-only).
609
+ *
610
+ * Uses an internal read-only Pkdns actor.
611
+ *
612
+ * @param {PublicKey} user
613
+ * @returns {Promise<PublicKey|undefined>} Homeserver public key (z32) or `undefined` if not found.
614
+ */
615
+ getHomeserverOf(user_public_key: PublicKey): Promise<PublicKey | undefined>;
517
616
  /**
518
617
  * Public, unauthenticated storage API.
519
618
  *
@@ -523,20 +622,9 @@ export class Pubky {
523
622
  * @returns {PublicStorage}
524
623
  *
525
624
  * @example
526
- * const pub = pubky.publicStorage();
527
- * const text = await pub.getText(`${userPk.z32()}/pub/example.com/hello.txt`);
528
- */
529
- publicStorage(): PublicStorage;
530
- /**
531
- * Read-only PKDNS (Pkarr) resolver.
532
- *
533
- * @returns {Pkdns}
534
- *
535
- * @example
536
- * const dns = pubky.pkdns();
537
- * const homeserver = await dns.getHomeserverOf(userPk);
625
+ * const text = await pubky.publicStorage.getText(`${userPk.z32()}/pub/example.com/hello.txt`);
538
626
  */
539
- pkdns(): Pkdns;
627
+ readonly publicStorage: PublicStorage;
540
628
  /**
541
629
  * Access the underlying HTTP client (advanced).
542
630
  *
@@ -544,9 +632,9 @@ export class Pubky {
544
632
  * Use this for low-level `fetch()` calls or testing with raw URLs.
545
633
  *
546
634
  * @example
547
- * const r = await pubky.client().fetch(`pubky://${user}/pub/app/file.txt`, { credentials: "include" });
635
+ * const r = await pubky.client.fetch(`pubky://${user}/pub/app/file.txt`, { credentials: "include" });
548
636
  */
549
- client(): Client;
637
+ readonly client: Client;
550
638
  }
551
639
  export class PublicKey {
552
640
  private constructor();
@@ -574,80 +662,87 @@ export class PublicStorage {
574
662
  */
575
663
  constructor();
576
664
  /**
577
- * List a directory. Results are `pubky://…` absolute URLs.
665
+ * List a directory. Results are `pubky://…` identifier URLs.
578
666
  *
579
- * @param {string} address Addressed directory (must end with `/`).
667
+ * @param {Address} address Addressed directory (must end with `/`).
580
668
  * @param {string|null=} cursor Optional suffix or full URL to start **after**.
581
669
  * @param {boolean=} reverse Default `false`. When `true`, newest/lexicographically-last first.
582
670
  * @param {number=} limit Optional result limit.
583
671
  * @param {boolean=} shallow Default `false`. When `true`, lists only first-level entries.
584
672
  * @returns {Promise<string[]>}
585
673
  */
586
- list(address: string, cursor?: string | null, reverse?: boolean | null, limit?: number | null, shallow?: boolean | null): Promise<string[]>;
674
+ list(address: Address, cursor?: string | null, reverse?: boolean | null, limit?: number | null, shallow?: boolean | null): Promise<string[]>;
675
+ /**
676
+ * Perform a streaming `GET` and expose the raw `Response` object.
677
+ *
678
+ * @param {Address} address
679
+ * @returns {Promise<Response>}
680
+ */
681
+ get(address: Address): Promise<Response>;
587
682
  /**
588
683
  * Fetch bytes from an addressed path.
589
684
  *
590
- * @param {string} address
685
+ * @param {Address} address
591
686
  * @returns {Promise<Uint8Array>}
592
687
  */
593
- getBytes(address: string): Promise<Uint8Array>;
688
+ getBytes(address: Address): Promise<Uint8Array>;
594
689
  /**
595
690
  * Fetch text from an addressed path as UTF-8 text.
596
691
  *
597
- * @param {string} address
692
+ * @param {Address} address
598
693
  * @returns {Promise<string>}
599
694
  */
600
- getText(address: string): Promise<string>;
695
+ getText(address: Address): Promise<string>;
601
696
  /**
602
697
  * Fetch JSON from an addressed path.
603
698
  *
604
- * @param {string} address `"<user-z32>/pub/.../file.json"` or `pubky://<user>/pub/...`.
699
+ * @param {Address} address `"pubky<user>/pub/.../file.json"` (preferred) or `pubky://<user>/pub/...`.
605
700
  * @returns {Promise<any>}
606
701
  */
607
- getJson(address: string): Promise<any>;
702
+ getJson(address: Address): Promise<any>;
608
703
  /**
609
704
  * Check if a path exists.
610
705
  *
611
- * @param {string} address
706
+ * @param {Address} address
612
707
  * @returns {Promise<boolean>}
613
708
  */
614
- exists(address: string): Promise<boolean>;
709
+ exists(address: Address): Promise<boolean>;
615
710
  /**
616
711
  * Get metadata for an address
617
712
  *
618
- * @param {string} address `"<user-z32>/pub/.../file.json"` or `pubky://<user>/pub/...`.
713
+ * @param {Address} address `"pubky<user>/pub/.../file.json"` (preferred) or `pubky://<user>/pub/...`.
619
714
  * @returns {Promise<ResourceStats|undefined>} `undefined` if the resource does not exist.
620
- * @throws {PubkyJsError} On invalid input or transport/server errors.
715
+ * @throws {PubkyError} On invalid input or transport/server errors.
621
716
  */
622
- stats(address: string): Promise<ResourceStats | undefined>;
717
+ stats(address: Address): Promise<ResourceStats | undefined>;
623
718
  }
624
719
  /**
625
720
  * An authenticated context “as the user”.
626
- * - Use `storage()` for reads/writes (absolute paths like `/pub/app/file.txt`)
721
+ * - Use `storage` for reads/writes (absolute paths like `/pub/app/file.txt`)
627
722
  * - Cookie is managed automatically by the underlying fetch client
628
723
  */
629
724
  export class Session {
630
725
  private constructor();
631
726
  free(): void;
727
+ /**
728
+ * Invalidate the session on the server (clears server cookie).
729
+ * Further calls to storage API will fail.
730
+ *
731
+ * @returns {Promise<void>}
732
+ */
733
+ signout(): Promise<void>;
632
734
  /**
633
735
  * Retrieve immutable info about this session (user & capabilities).
634
736
  *
635
737
  * @returns {SessionInfo}
636
738
  */
637
- info(): SessionInfo;
739
+ readonly info: SessionInfo;
638
740
  /**
639
741
  * Access the session-scoped storage API (read/write).
640
742
  *
641
743
  * @returns {SessionStorage}
642
744
  */
643
- storage(): SessionStorage;
644
- /**
645
- * Invalidate the session on the server (clears server cookie).
646
- * It also consumes this JS/Wasm Session. Further calls will fail.
647
- *
648
- * @returns {Promise<void>}
649
- */
650
- signout(): Promise<void>;
745
+ readonly storage: SessionStorage;
651
746
  }
652
747
  /**
653
748
  * Static snapshot of session metadata.
@@ -658,15 +753,20 @@ export class SessionInfo {
658
753
  /**
659
754
  * The user’s public key for this session.
660
755
  *
756
+ * Use `.z32()` on the returned `PublicKey` to get the string form.
757
+ *
661
758
  * @returns {PublicKey}
759
+ *
760
+ * @example
761
+ * const who = sessionInfo.publicKey.z32();
662
762
  */
663
- publicKey(): PublicKey;
763
+ readonly publicKey: PublicKey;
664
764
  /**
665
765
  * Effective capabilities granted to this session.
666
766
  *
667
767
  * @returns {string[]} Normalized capability entries (e.g. `"/pub/app/:rw"`).
668
768
  */
669
- capabilities(): string[];
769
+ readonly capabilities: string[];
670
770
  }
671
771
  /**
672
772
  * Read/write storage scoped to **your** session (absolute paths: `/pub/...`).
@@ -677,81 +777,88 @@ export class SessionStorage {
677
777
  /**
678
778
  * List a directory (absolute session path). Returns `pubky://…` URLs.
679
779
  *
680
- * @param {string} path Must end with `/`.
780
+ * @param {Path} path Must end with `/`.
681
781
  * @param {string|null=} cursor Optional suffix or full URL to start **after**.
682
782
  * @param {boolean=} reverse Default `false`.
683
783
  * @param {number=} limit Optional result limit.
684
784
  * @param {boolean=} shallow Default `false`.
685
785
  * @returns {Promise<string[]>}
686
786
  */
687
- list(path: string, cursor?: string | null, reverse?: boolean | null, limit?: number | null, shallow?: boolean | null): Promise<string[]>;
787
+ list(path: Path, cursor?: string | null, reverse?: boolean | null, limit?: number | null, shallow?: boolean | null): Promise<string[]>;
788
+ /**
789
+ * GET a streaming response for an absolute session path.
790
+ *
791
+ * @param {Path} path
792
+ * @returns {Promise<Response>}
793
+ */
794
+ get(path: Path): Promise<Response>;
688
795
  /**
689
796
  * GET bytes from an absolute session path.
690
797
  *
691
- * @param {string} path
798
+ * @param {Path} path
692
799
  * @returns {Promise<Uint8Array>}
693
800
  */
694
- getBytes(path: string): Promise<Uint8Array>;
801
+ getBytes(path: Path): Promise<Uint8Array>;
695
802
  /**
696
803
  * GET text from an absolute session path.
697
804
  *
698
- * @param {string} path
805
+ * @param {Path} path
699
806
  * @returns {Promise<string>}
700
807
  */
701
- getText(path: string): Promise<string>;
808
+ getText(path: Path): Promise<string>;
702
809
  /**
703
810
  * GET JSON from an absolute session path.
704
811
  *
705
- * @param {string} path
812
+ * @param {Path} path
706
813
  * @returns {Promise<any>}
707
814
  */
708
- getJson(addr: string): Promise<any>;
815
+ getJson(path: Path): Promise<any>;
709
816
  /**
710
817
  * Check existence.
711
818
  *
712
- * @param {string} path
819
+ * @param {Path} path
713
820
  * @returns {Promise<boolean>}
714
821
  */
715
- exists(path: string): Promise<boolean>;
822
+ exists(path: Path): Promise<boolean>;
716
823
  /**
717
824
  * Get metadata for an absolute, session-scoped path (e.g. `"/pub/app/file.json"`).
718
825
  *
719
- * @param {string} path Absolute path under your user (starts with `/`).
826
+ * @param {Path} path Absolute path under your user (starts with `/`).
720
827
  * @returns {Promise<ResourceStats|undefined>} `undefined` if the resource does not exist.
721
- * @throws {PubkyJsError} On invalid input or transport/server errors.
828
+ * @throws {PubkyError} On invalid input or transport/server errors.
722
829
  */
723
- stats(path: string): Promise<ResourceStats | undefined>;
830
+ stats(path: Path): Promise<ResourceStats | undefined>;
724
831
  /**
725
832
  * PUT binary at an absolute session path.
726
833
  *
727
- * @param {string} path
834
+ * @param {Path} path
728
835
  * @param {Uint8Array} bytes
729
836
  * @returns {Promise<void>}
730
837
  */
731
- putBytes(path: string, body: Uint8Array): Promise<void>;
838
+ putBytes(path: Path, body: Uint8Array): Promise<void>;
732
839
  /**
733
840
  * PUT text at an absolute session path.
734
841
  *
735
- * @param {string} path
842
+ * @param {Path} path
736
843
  * @param {string} text
737
844
  * @returns {Promise<void>}
738
845
  */
739
- putText(path: string, body: string): Promise<void>;
846
+ putText(path: Path, body: string): Promise<void>;
740
847
  /**
741
848
  * PUT JSON at an absolute session path.
742
849
  *
743
- * @param {string} path Absolute path (e.g. `"/pub/app/data.json"`).
850
+ * @param {Path} path Absolute path (e.g. `"/pub/app/data.json"`).
744
851
  * @param {any} value JSON-serializable value.
745
852
  * @returns {Promise<void>}
746
853
  */
747
- putJson(path: string, body: any): Promise<void>;
854
+ putJson(path: Path, body: any): Promise<void>;
748
855
  /**
749
856
  * Delete a path (file or empty directory).
750
857
  *
751
- * @param {string} path
858
+ * @param {Path} path
752
859
  * @returns {Promise<void>}
753
860
  */
754
- delete(path: string): Promise<void>;
861
+ delete(path: Path): Promise<void>;
755
862
  }
756
863
  /**
757
864
  * Holds a user’s `Keypair` and performs identity operations:
@@ -770,12 +877,6 @@ export class Signer {
770
877
  * @returns {Signer}
771
878
  */
772
879
  static fromKeypair(keypair: Keypair): Signer;
773
- /**
774
- * Get the public key of this signer.
775
- *
776
- * @returns {PublicKey}
777
- */
778
- publicKey(): PublicKey;
779
880
  /**
780
881
  * Sign up at a homeserver. Returns a ready `Session`.
781
882
  *
@@ -785,7 +886,7 @@ export class Signer {
785
886
  * @param {string|null} signupToken Invite/registration token or `null`.
786
887
  * @returns {Promise<Session>}
787
888
  *
788
- * @throws {PubkyJsError}
889
+ * @throws {PubkyError}
789
890
  * - `AuthenticationError` (bad/expired token)
790
891
  * - `RequestError` (network/server)
791
892
  */
@@ -797,7 +898,7 @@ export class Signer {
797
898
  *
798
899
  * @returns {Promise<Session>}
799
900
  *
800
- * @throws {PubkyJsError}
901
+ * @throws {PubkyError}
801
902
  */
802
903
  signin(): Promise<Session>;
803
904
  /**
@@ -812,10 +913,19 @@ export class Signer {
812
913
  * Approve a `pubkyauth://` request URL (encrypts & POSTs the signed AuthToken).
813
914
  */
814
915
  approveAuthRequest(pubkyauth_url: string): Promise<void>;
916
+ /**
917
+ * Get the public key of this signer.
918
+ *
919
+ * @returns {PublicKey}
920
+ */
921
+ readonly publicKey: PublicKey;
815
922
  /**
816
923
  * Get a PKDNS actor bound to this signer's client & keypair (publishing enabled).
817
924
  *
818
925
  * @returns {Pkdns}
926
+ *
927
+ * @example
928
+ * await signer.pkdns.publishHomeserverIfStale(homeserverPk);
819
929
  */
820
- pkdns(): Pkdns;
930
+ readonly pkdns: Pkdns;
821
931
  }