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

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/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@synonymdev/pubky",
3
3
  "type": "module",
4
4
  "description": "Pubky client",
5
- "version": "0.6.0-rc.6",
5
+ "version": "0.6.0-rc.7",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
package/pubky.d.ts CHANGED
@@ -51,46 +51,40 @@ type Level = "error" | "warn" | "info" | "debug" | "trace";
51
51
  * *This API requires the following crate features to be activated: `ReadableStreamType`*
52
52
  */
53
53
  type ReadableStreamType = "bytes";
54
+ export type Path = `/pub/${string}`;
55
+
56
+ export type Address = `pubky${string}/pub/${string}` | `pubky://${string}/pub/${string}`;
57
+
54
58
  /**
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.
59
+ * Pkarr Config
73
60
  */
74
- export interface ResourceStats {
75
- /**
76
- * Size in bytes of the stored object.
77
- */
78
- contentLength?: number;
61
+ export interface PkarrConfig {
79
62
  /**
80
- * Media type of the stored object (e.g., `\"application/json\"`).
63
+ * The list of relays to access the DHT with.
81
64
  */
82
- contentType?: string;
65
+ relays?: string[];
83
66
  /**
84
- * Unix epoch **milliseconds** for the last modification time.
67
+ * The timeout for DHT requests in milliseconds.
68
+ * Default is 2000ms.
85
69
  */
86
- lastModifiedMs?: number;
70
+ requestTimeout?: number;
71
+ }
72
+
73
+ /**
74
+ * Pubky Client Config
75
+ */
76
+ export interface PubkyClientConfig {
87
77
  /**
88
- * Opaque entity tag identifying the current stored version.
78
+ * Configuration on how to access pkarr packets on the mainline DHT.
89
79
  */
90
- etag?: string;
80
+ pkarr?: PkarrConfig;
91
81
  }
92
82
 
93
- export type Path = `/pub/${string}`;
83
+ export type CapabilityAction = "r" | "w" | "rw";
84
+ export type CapabilityScope = `/${string}`;
85
+ export type CapabilityEntry = `${CapabilityScope}:${CapabilityAction}`;
86
+ type CapabilitiesTail = `,${CapabilityEntry}${string}`;
87
+ export type Capabilities = "" | CapabilityEntry | `${CapabilityEntry}${CapabilitiesTail}`;
94
88
 
95
89
  /**
96
90
  * A union type of all possible machine-readable codes for the `name` property
@@ -168,39 +162,45 @@ export interface PubkyError extends Error {
168
162
  data?: unknown;
169
163
  }
170
164
 
171
- export type Address = `pubky${string}/pub/${string}` | `pubky://${string}/pub/${string}`;
172
-
173
165
  /**
174
- * Pkarr Config
166
+ * Resource metadata returned by `SessionStorage.stats()` and `PublicStorage.stats()`.
167
+ *
168
+ * @typedef {Object} ResourceStats
169
+ * @property {number=} contentLength Size in bytes.
170
+ * @property {string=} contentType Media type (e.g. \"application/json; charset=utf-8\").
171
+ * @property {number=} lastModifiedMs Unix epoch milliseconds.
172
+ * @property {string=} etag Opaque server ETag for the current version.
173
+ *
174
+ * @example
175
+ * const stats = await pubky.publicStorage.stats(`${user}/pub/app/file.json`);
176
+ * if (stats) {
177
+ * console.log(stats.contentLength, stats.contentType, stats.lastModifiedMs);
178
+ * }
179
+ *
180
+ * Notes:
181
+ * - `contentLength` equals `getBytes(...).length`.
182
+ * - `etag` may be absent and is opaque; compare values to detect updates.
183
+ * - `lastModifiedMs` increases when the resource is updated.
175
184
  */
176
- export interface PkarrConfig {
185
+ export interface ResourceStats {
177
186
  /**
178
- * The list of relays to access the DHT with.
187
+ * Size in bytes of the stored object.
179
188
  */
180
- relays?: string[];
189
+ contentLength?: number;
181
190
  /**
182
- * The timeout for DHT requests in milliseconds.
183
- * Default is 2000ms.
191
+ * Media type of the stored object (e.g., `\"application/json\"`).
184
192
  */
185
- requestTimeout?: number;
186
- }
187
-
188
- /**
189
- * Pubky Client Config
190
- */
191
- export interface PubkyClientConfig {
193
+ contentType?: string;
192
194
  /**
193
- * Configuration on how to access pkarr packets on the mainline DHT.
195
+ * Unix epoch **milliseconds** for the last modification time.
194
196
  */
195
- pkarr?: PkarrConfig;
197
+ lastModifiedMs?: number;
198
+ /**
199
+ * Opaque entity tag identifying the current stored version.
200
+ */
201
+ etag?: string;
196
202
  }
197
203
 
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}`;
203
-
204
204
  /**
205
205
  * Start and control a pubkyauth authorization flow.
206
206
  *
@@ -212,6 +212,7 @@ export type Capabilities = "" | CapabilityEntry | `${CapabilityEntry}${Capabilit
212
212
  export class AuthFlow {
213
213
  private constructor();
214
214
  free(): void;
215
+ [Symbol.dispose](): void;
215
216
  /**
216
217
  * Start a flow (standalone).
217
218
  * Prefer `pubky.startAuthFlow()` to reuse a facade client.
@@ -219,10 +220,17 @@ export class AuthFlow {
219
220
  * @param {string} capabilities
220
221
  * Comma-separated capabilities, e.g. `"/pub/app/:rw,/priv/foo.txt:r"`.
221
222
  * Each entry must be `"<scope>:<actions>"`, where:
222
- * - `scope` starts with `/` (e.g. `/pub/example.app/`)
223
+ * - `scope` starts with `/` (e.g. `/pub/example.com/`)
223
224
  * - `actions` is any combo of `r` and/or `w` (order is normalized; `wr` -> `rw`)
224
225
  * Empty string is allowed (no scopes).
225
226
  *
227
+ * @param {AuthFlowKind} kind
228
+ * The kind of authentication flow to perform.
229
+ * This can either be a sign in or a sign up flow.
230
+ * Examples:
231
+ * - `AuthFlowKind.signin()` - Sign in to an existing account.
232
+ * - `AuthFlowKind.signup(homeserverPublicKey, signupToken)` - Sign up for a new account.
233
+ *
226
234
  * @param {string} [relay]
227
235
  * Optional HTTP relay base, e.g. `"https://demo.httprelay.io/link/"`.
228
236
  * Defaults to the default Synonym-hosted relay when omitted.
@@ -234,11 +242,11 @@ export class AuthFlow {
234
242
  * - `{ name: "InvalidInput", message: string }` if any capability entry is invalid
235
243
  * or for an invalid relay URL.
236
244
  * @example
237
- * const flow = AuthFlow.start("/pub/my.app/:rw,/pub/pubky.app/:w");
245
+ * const flow = AuthFlow.start("/pub/my-cool-app/:rw,/pub/pubky.app/:w");
238
246
  * renderQRCode(flow.authorizationUrl());
239
247
  * const session = await flow.awaitApproval();
240
248
  */
241
- static start(capabilities: Capabilities, relay?: string | null): AuthFlow;
249
+ static start(capabilities: Capabilities, kind: AuthFlowKind, relay?: string | null): AuthFlow;
242
250
  /**
243
251
  * Block until the user approves on their signer device; returns a `Session`.
244
252
  *
@@ -276,6 +284,33 @@ export class AuthFlow {
276
284
  */
277
285
  readonly authorizationUrl: string;
278
286
  }
287
+ /**
288
+ * The kind of authentication flow to perform.
289
+ * This can either be a sign in or a sign up flow.
290
+ */
291
+ export class AuthFlowKind {
292
+ private constructor();
293
+ free(): void;
294
+ [Symbol.dispose](): void;
295
+ /**
296
+ * Create a sign in flow.
297
+ */
298
+ static signin(): AuthFlowKind;
299
+ /**
300
+ * Create a sign up flow.
301
+ * # Arguments
302
+ * * `homeserver_public_key` - The public key of the homeserver to sign up on.
303
+ * * `signup_token` - The signup token to use for the signup flow. This is optional.
304
+ */
305
+ static signup(homeserver_public_key: PublicKey, signup_token?: string | null): AuthFlowKind;
306
+ /**
307
+ * Get the intent of the authentication flow.
308
+ * # Returns
309
+ * * `"signin"` - If the authentication flow is a sign in flow.
310
+ * * `"signup"` - If the authentication flow is a sign up flow.
311
+ */
312
+ readonly intent: string;
313
+ }
279
314
  /**
280
315
  * AuthToken: signed, time-bound proof of key ownership.
281
316
  *
@@ -305,6 +340,7 @@ export class AuthFlow {
305
340
  export class AuthToken {
306
341
  private constructor();
307
342
  free(): void;
343
+ [Symbol.dispose](): void;
308
344
  /**
309
345
  * Parse and verify an `AuthToken` from its canonical bytes.
310
346
  *
@@ -361,7 +397,7 @@ export class AuthToken {
361
397
  *
362
398
  * Returns: `string[]`, where each item is the canonical entry `"<scope>:<actions>"`.
363
399
  *
364
- * Example entry: `"/pub/my.app/:rw"`
400
+ * Example entry: `"/pub/my-cool-app/:rw"`
365
401
  */
366
402
  readonly capabilities: string[];
367
403
  }
@@ -373,18 +409,7 @@ export class AuthToken {
373
409
  */
374
410
  export class Client {
375
411
  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>;
412
+ [Symbol.dispose](): void;
388
413
  /**
389
414
  * Create a Pubky HTTP client.
390
415
  *
@@ -425,10 +450,23 @@ export class Client {
425
450
  * const client = Client.testnet("docker0"); // custom host
426
451
  */
427
452
  static testnet(host?: string | null): Client;
453
+ /**
454
+ * Perform a raw fetch. Works with `http(s)://` URLs.
455
+ *
456
+ * @param {string} url
457
+ * @param {RequestInit} init Standard fetch options; `credentials: "include"` recommended for session I/O.
458
+ * @returns {Promise<Response>}
459
+ *
460
+ * @example
461
+ * const client = pubky.client;
462
+ * const res = await client.fetch(`https://_pubky.${user}/pub/app/file.txt`, { method: "PUT", body: "hi", credentials: "include" });
463
+ */
464
+ fetch(url: string, init?: RequestInit | null): Promise<Response>;
428
465
  }
429
466
  export class IntoUnderlyingByteSource {
430
467
  private constructor();
431
468
  free(): void;
469
+ [Symbol.dispose](): void;
432
470
  start(controller: ReadableByteStreamController): void;
433
471
  pull(controller: ReadableByteStreamController): Promise<any>;
434
472
  cancel(): void;
@@ -438,6 +476,7 @@ export class IntoUnderlyingByteSource {
438
476
  export class IntoUnderlyingSink {
439
477
  private constructor();
440
478
  free(): void;
479
+ [Symbol.dispose](): void;
441
480
  write(chunk: any): Promise<any>;
442
481
  close(): Promise<any>;
443
482
  abort(reason: any): Promise<any>;
@@ -445,12 +484,14 @@ export class IntoUnderlyingSink {
445
484
  export class IntoUnderlyingSource {
446
485
  private constructor();
447
486
  free(): void;
487
+ [Symbol.dispose](): void;
448
488
  pull(controller: ReadableStreamDefaultController): Promise<any>;
449
489
  cancel(): void;
450
490
  }
451
491
  export class Keypair {
452
492
  private constructor();
453
493
  free(): void;
494
+ [Symbol.dispose](): void;
454
495
  /**
455
496
  * Generate a random [Keypair]
456
497
  */
@@ -486,6 +527,7 @@ export class Keypair {
486
527
  */
487
528
  export class Pkdns {
488
529
  free(): void;
530
+ [Symbol.dispose](): void;
489
531
  /**
490
532
  * Read-only PKDNS actor (no keypair; resolve only).
491
533
  */
@@ -531,6 +573,7 @@ export class Pkdns {
531
573
  */
532
574
  export class Pubky {
533
575
  free(): void;
576
+ [Symbol.dispose](): void;
534
577
  /**
535
578
  * Create a Pubky facade wired for **mainnet** defaults (public relays).
536
579
  *
@@ -573,11 +616,15 @@ export class Pubky {
573
616
  * Provide a **capabilities string** and (optionally) a relay base URL.
574
617
  * The capabilities string is a comma-separated list of entries:
575
618
  * `"<scope>:<actions>"`, where:
576
- * - `scope` starts with `/` (e.g. `/pub/example.app/`).
619
+ * - `scope` starts with `/` (e.g. `/pub/example.com/`).
577
620
  * - `actions` is any combo of `r` and/or `w` (order normalized; `wr` -> `rw`).
578
621
  * Pass `""` for no scopes (read-only public session).
579
622
  *
580
623
  * @param {string} capabilities Comma-separated caps, e.g. `"/pub/app/:rw,/pub/foo/file:r"`.
624
+ * @param {AuthFlowKind} kind The kind of authentication flow to perform.
625
+ * Examples:
626
+ * - `AuthFlowKind.signin()` - Sign in to an existing account.
627
+ * - `AuthFlowKind.signup(homeserverPublicKey, signupToken)` - Sign up for a new account.
581
628
  * @param {string=} relay Optional HTTP relay base (e.g. `"https://…/link/"`).
582
629
  * @returns {AuthFlow}
583
630
  * A running auth flow. Show `authorizationUrl` as QR/deeplink,
@@ -588,11 +635,11 @@ export class Pubky {
588
635
  * - `{ name: "RequestError" }` if the flow cannot be started (network/relay)
589
636
  *
590
637
  * @example
591
- * const flow = pubky.startAuthFlow("/pub/my.app/:rw");
638
+ * const flow = pubky.startAuthFlow("/pub/my-cool-app/:rw");
592
639
  * renderQr(flow.authorizationUrl);
593
640
  * const session = await flow.awaitApproval();
594
641
  */
595
- startAuthFlow(capabilities: Capabilities, relay?: string | null): AuthFlow;
642
+ startAuthFlow(capabilities: Capabilities, kind: AuthFlowKind, relay?: string | null): AuthFlow;
596
643
  /**
597
644
  * Create a `Signer` from an existing `Keypair`.
598
645
  *
@@ -613,6 +660,20 @@ export class Pubky {
613
660
  * @returns {Promise<PublicKey|undefined>} Homeserver public key (z32) or `undefined` if not found.
614
661
  */
615
662
  getHomeserverOf(user_public_key: PublicKey): Promise<PublicKey | undefined>;
663
+ /**
664
+ * Restore a session from a previously exported snapshot, using this instance's client.
665
+ *
666
+ * This does **not** read or write any secrets. It revalidates the session metadata with
667
+ * the server using the browser-managed HTTP-only cookie that must still be present.
668
+ *
669
+ * @param {string} exported A string produced by `session.export()`.
670
+ * @returns {Promise<Session>}
671
+ * A rehydrated session bound to this SDK's HTTP client.
672
+ *
673
+ * @example
674
+ * const restored = await pubky.restoreSession(localStorage.getItem("pubky-session")!);
675
+ */
676
+ restoreSession(exported: string): Promise<Session>;
616
677
  /**
617
678
  * Public, unauthenticated storage API.
618
679
  *
@@ -639,6 +700,7 @@ export class Pubky {
639
700
  export class PublicKey {
640
701
  private constructor();
641
702
  free(): void;
703
+ [Symbol.dispose](): void;
642
704
  /**
643
705
  * Convert the PublicKey to Uint8Array
644
706
  */
@@ -657,6 +719,7 @@ export class PublicKey {
657
719
  */
658
720
  export class PublicStorage {
659
721
  free(): void;
722
+ [Symbol.dispose](): void;
660
723
  /**
661
724
  * Construct PublicStorage using global client (mainline relays).
662
725
  */
@@ -716,6 +779,14 @@ export class PublicStorage {
716
779
  */
717
780
  stats(address: Address): Promise<ResourceStats | undefined>;
718
781
  }
782
+ export class SeedExportDeepLink {
783
+ private constructor();
784
+ free(): void;
785
+ [Symbol.dispose](): void;
786
+ static parse(url: string): SeedExportDeepLink;
787
+ toString(): string;
788
+ readonly secret: Uint8Array;
789
+ }
719
790
  /**
720
791
  * An authenticated context “as the user”.
721
792
  * - Use `storage` for reads/writes (absolute paths like `/pub/app/file.txt`)
@@ -724,6 +795,7 @@ export class PublicStorage {
724
795
  export class Session {
725
796
  private constructor();
726
797
  free(): void;
798
+ [Symbol.dispose](): void;
727
799
  /**
728
800
  * Invalidate the session on the server (clears server cookie).
729
801
  * Further calls to storage API will fail.
@@ -731,6 +803,29 @@ export class Session {
731
803
  * @returns {Promise<void>}
732
804
  */
733
805
  signout(): Promise<void>;
806
+ /**
807
+ * Export the session metadata so it can be restored after a tab refresh.
808
+ *
809
+ * The export string contains **no secrets**; it only serializes the public `SessionInfo`.
810
+ * Browsers remain responsible for persisting the HTTP-only session cookie.
811
+ *
812
+ * @returns {string}
813
+ * A base64 string to store (e.g. in `localStorage`).
814
+ */
815
+ export(): string;
816
+ /**
817
+ * Restore a session from an `export()` string.
818
+ *
819
+ * The HTTP-only cookie must still be present in the browser; this function does not
820
+ * read or write any secrets.
821
+ *
822
+ * @param {string} exported
823
+ * A string produced by `session.export()`.
824
+ * @param {Client=} client
825
+ * Optional client to reuse transport configuration.
826
+ * @returns {Promise<Session>}
827
+ */
828
+ static restore(exported: string, client?: Client | null): Promise<Session>;
734
829
  /**
735
830
  * Retrieve immutable info about this session (user & capabilities).
736
831
  *
@@ -750,6 +845,7 @@ export class Session {
750
845
  export class SessionInfo {
751
846
  private constructor();
752
847
  free(): void;
848
+ [Symbol.dispose](): void;
753
849
  /**
754
850
  * The user’s public key for this session.
755
851
  *
@@ -774,6 +870,7 @@ export class SessionInfo {
774
870
  export class SessionStorage {
775
871
  private constructor();
776
872
  free(): void;
873
+ [Symbol.dispose](): void;
777
874
  /**
778
875
  * List a directory (absolute session path). Returns `pubky://…` URLs.
779
876
  *
@@ -870,6 +967,7 @@ export class SessionStorage {
870
967
  export class Signer {
871
968
  private constructor();
872
969
  free(): void;
970
+ [Symbol.dispose](): void;
873
971
  /**
874
972
  * Create a signer from a `Keypair` (prefer `pubky.signer(kp)`).
875
973
  *
@@ -929,3 +1027,25 @@ export class Signer {
929
1027
  */
930
1028
  readonly pkdns: Pkdns;
931
1029
  }
1030
+ export class SigninDeepLink {
1031
+ private constructor();
1032
+ free(): void;
1033
+ [Symbol.dispose](): void;
1034
+ static parse(url: string): SigninDeepLink;
1035
+ toString(): string;
1036
+ readonly capabilities: string;
1037
+ readonly baseRelayUrl: string;
1038
+ readonly secret: Uint8Array;
1039
+ }
1040
+ export class SignupDeepLink {
1041
+ private constructor();
1042
+ free(): void;
1043
+ [Symbol.dispose](): void;
1044
+ static parse(url: string): SignupDeepLink;
1045
+ toString(): string;
1046
+ readonly capabilities: string;
1047
+ readonly baseRelayUrl: string;
1048
+ readonly secret: Uint8Array;
1049
+ readonly homeserver: PublicKey;
1050
+ readonly signupToken: string | undefined;
1051
+ }
package/pubky_bg.wasm CHANGED
Binary file