@synonymdev/pubky 0.6.0-rc.6 → 0.6.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.
- package/README.md +84 -24
- package/index.cjs +935 -443
- package/index.js +1049 -555
- package/package.json +3 -3
- package/pubky.d.ts +201 -68
- package/pubky_bg.wasm +0 -0
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
|
|
5
|
+
"version": "0.6.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"build:test": "tsc --project tsconfig.json && mkdir -p dist && cp index.js dist/index.js",
|
|
14
14
|
"test": "npm run test-nodejs && npm run test-browser",
|
|
15
15
|
"test-nodejs": "npm run build:test && node --require ./node-header.cjs node_modules/tape/bin/tape dist/tests/*.js -cov",
|
|
16
|
-
"test-browser": "npm run build:test && browserify dist/tests/*.js -p esmify | npx tape-run",
|
|
17
|
-
"test-browser:ci": "npm run build:test && browserify dist/tests/*.js -p esmify | tape-run --browser electron --electron-arg=--no-sandbox --electron-arg=--disable-gpu",
|
|
16
|
+
"test-browser": "npm run build:test && browserify dist/tests/setup.js dist/tests/*.js -p esmify | npx tape-run",
|
|
17
|
+
"test-browser:ci": "npm run build:test && browserify dist/tests/setup.js dist/tests/*.js -p esmify | tape-run --browser electron --electron-arg=--no-sandbox --electron-arg=--disable-gpu",
|
|
18
18
|
"build": "cargo run --bin bundle_npm",
|
|
19
19
|
"prepublishOnly": "npm run build"
|
|
20
20
|
},
|
package/pubky.d.ts
CHANGED
|
@@ -51,47 +51,14 @@ 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
|
-
/**
|
|
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
54
|
export type Path = `/pub/${string}`;
|
|
94
55
|
|
|
56
|
+
export type CapabilityAction = "r" | "w" | "rw";
|
|
57
|
+
export type CapabilityScope = `/${string}`;
|
|
58
|
+
export type CapabilityEntry = `${CapabilityScope}:${CapabilityAction}`;
|
|
59
|
+
type CapabilitiesTail = `,${CapabilityEntry}${string}`;
|
|
60
|
+
export type Capabilities = "" | CapabilityEntry | `${CapabilityEntry}${CapabilitiesTail}`;
|
|
61
|
+
|
|
95
62
|
/**
|
|
96
63
|
* A union type of all possible machine-readable codes for the `name` property
|
|
97
64
|
* of a {@link PubkyError}.
|
|
@@ -195,11 +162,44 @@ export interface PubkyClientConfig {
|
|
|
195
162
|
pkarr?: PkarrConfig;
|
|
196
163
|
}
|
|
197
164
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
165
|
+
/**
|
|
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.
|
|
184
|
+
*/
|
|
185
|
+
export interface ResourceStats {
|
|
186
|
+
/**
|
|
187
|
+
* Size in bytes of the stored object.
|
|
188
|
+
*/
|
|
189
|
+
contentLength?: number;
|
|
190
|
+
/**
|
|
191
|
+
* Media type of the stored object (e.g., `\"application/json\"`).
|
|
192
|
+
*/
|
|
193
|
+
contentType?: string;
|
|
194
|
+
/**
|
|
195
|
+
* Unix epoch **milliseconds** for the last modification time.
|
|
196
|
+
*/
|
|
197
|
+
lastModifiedMs?: number;
|
|
198
|
+
/**
|
|
199
|
+
* Opaque entity tag identifying the current stored version.
|
|
200
|
+
*/
|
|
201
|
+
etag?: string;
|
|
202
|
+
}
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
205
|
* Start and control a pubkyauth authorization flow.
|
|
@@ -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.
|
|
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
|
|
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
|
*
|
|
@@ -292,7 +327,7 @@ export class AuthFlow {
|
|
|
292
327
|
* const token = await flow.awaitToken();
|
|
293
328
|
*
|
|
294
329
|
* // Identify the user
|
|
295
|
-
* console.log(token.publicKey().
|
|
330
|
+
* console.log(token.publicKey().toString());
|
|
296
331
|
*
|
|
297
332
|
* // Optionally forward to a server for verification:
|
|
298
333
|
* await fetch("/api/verify", { method: "POST", body: token.toBytes() });
|
|
@@ -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
|
*
|
|
@@ -319,7 +355,7 @@ export class AuthToken {
|
|
|
319
355
|
* export async function POST(req) {
|
|
320
356
|
* const bytes = new Uint8Array(await req.arrayBuffer());
|
|
321
357
|
* const token = AuthToken.verify(bytes); // throws on failure
|
|
322
|
-
* return new Response(token.publicKey().
|
|
358
|
+
* return new Response(token.publicKey().toString(), { status: 200 });
|
|
323
359
|
* }
|
|
324
360
|
* ```
|
|
325
361
|
*/
|
|
@@ -347,10 +383,11 @@ export class AuthToken {
|
|
|
347
383
|
/**
|
|
348
384
|
* Returns the **public key** that authenticated with this token.
|
|
349
385
|
*
|
|
350
|
-
* Use `.
|
|
386
|
+
* Use `.toString()` on the returned `PublicKey` to get the `pubky<z32>` identifier.
|
|
387
|
+
* Call `.z32()` when you specifically need the raw z-base32 value (e.g. hostnames).
|
|
351
388
|
*
|
|
352
389
|
* @example
|
|
353
|
-
* const who =
|
|
390
|
+
* const who = token.publicKey.toString();
|
|
354
391
|
*/
|
|
355
392
|
readonly publicKey: PublicKey;
|
|
356
393
|
/**
|
|
@@ -361,7 +398,7 @@ export class AuthToken {
|
|
|
361
398
|
*
|
|
362
399
|
* Returns: `string[]`, where each item is the canonical entry `"<scope>:<actions>"`.
|
|
363
400
|
*
|
|
364
|
-
* Example entry: `"/pub/my
|
|
401
|
+
* Example entry: `"/pub/my-cool-app/:rw"`
|
|
365
402
|
*/
|
|
366
403
|
readonly capabilities: string[];
|
|
367
404
|
}
|
|
@@ -373,6 +410,7 @@ export class AuthToken {
|
|
|
373
410
|
*/
|
|
374
411
|
export class Client {
|
|
375
412
|
free(): void;
|
|
413
|
+
[Symbol.dispose](): void;
|
|
376
414
|
/**
|
|
377
415
|
* Perform a raw fetch. Works with `http(s)://` URLs.
|
|
378
416
|
*
|
|
@@ -429,6 +467,7 @@ export class Client {
|
|
|
429
467
|
export class IntoUnderlyingByteSource {
|
|
430
468
|
private constructor();
|
|
431
469
|
free(): void;
|
|
470
|
+
[Symbol.dispose](): void;
|
|
432
471
|
start(controller: ReadableByteStreamController): void;
|
|
433
472
|
pull(controller: ReadableByteStreamController): Promise<any>;
|
|
434
473
|
cancel(): void;
|
|
@@ -438,6 +477,7 @@ export class IntoUnderlyingByteSource {
|
|
|
438
477
|
export class IntoUnderlyingSink {
|
|
439
478
|
private constructor();
|
|
440
479
|
free(): void;
|
|
480
|
+
[Symbol.dispose](): void;
|
|
441
481
|
write(chunk: any): Promise<any>;
|
|
442
482
|
close(): Promise<any>;
|
|
443
483
|
abort(reason: any): Promise<any>;
|
|
@@ -445,24 +485,26 @@ export class IntoUnderlyingSink {
|
|
|
445
485
|
export class IntoUnderlyingSource {
|
|
446
486
|
private constructor();
|
|
447
487
|
free(): void;
|
|
488
|
+
[Symbol.dispose](): void;
|
|
448
489
|
pull(controller: ReadableStreamDefaultController): Promise<any>;
|
|
449
490
|
cancel(): void;
|
|
450
491
|
}
|
|
451
492
|
export class Keypair {
|
|
452
493
|
private constructor();
|
|
453
494
|
free(): void;
|
|
495
|
+
[Symbol.dispose](): void;
|
|
454
496
|
/**
|
|
455
497
|
* Generate a random [Keypair]
|
|
456
498
|
*/
|
|
457
499
|
static random(): Keypair;
|
|
458
500
|
/**
|
|
459
|
-
* Generate a [Keypair] from a secret
|
|
501
|
+
* Generate a [Keypair] from a 32-byte secret.
|
|
460
502
|
*/
|
|
461
|
-
static
|
|
503
|
+
static fromSecret(secret: Uint8Array): Keypair;
|
|
462
504
|
/**
|
|
463
|
-
* Returns the secret
|
|
505
|
+
* Returns the secret of this keypair.
|
|
464
506
|
*/
|
|
465
|
-
|
|
507
|
+
secret(): Uint8Array;
|
|
466
508
|
/**
|
|
467
509
|
* Create a recovery file for this keypair (encrypted with the given passphrase).
|
|
468
510
|
*/
|
|
@@ -474,10 +516,12 @@ export class Keypair {
|
|
|
474
516
|
/**
|
|
475
517
|
* Returns the [PublicKey] of this keypair.
|
|
476
518
|
*
|
|
477
|
-
* Use `.
|
|
519
|
+
* Use `.toString()` on the returned `PublicKey` to get the string form
|
|
520
|
+
* or `.z32()` to get the z32 string form without prefix.
|
|
521
|
+
* Transport/storage (query params, headers, persistence) should use `.z32()`.
|
|
478
522
|
*
|
|
479
523
|
* @example
|
|
480
|
-
* const who = keypair.publicKey.
|
|
524
|
+
* const who = keypair.publicKey.toString();
|
|
481
525
|
*/
|
|
482
526
|
readonly publicKey: PublicKey;
|
|
483
527
|
}
|
|
@@ -486,6 +530,7 @@ export class Keypair {
|
|
|
486
530
|
*/
|
|
487
531
|
export class Pkdns {
|
|
488
532
|
free(): void;
|
|
533
|
+
[Symbol.dispose](): void;
|
|
489
534
|
/**
|
|
490
535
|
* Read-only PKDNS actor (no keypair; resolve only).
|
|
491
536
|
*/
|
|
@@ -531,9 +576,14 @@ export class Pkdns {
|
|
|
531
576
|
*/
|
|
532
577
|
export class Pubky {
|
|
533
578
|
free(): void;
|
|
579
|
+
[Symbol.dispose](): void;
|
|
534
580
|
/**
|
|
535
581
|
* Create a Pubky facade wired for **mainnet** defaults (public relays).
|
|
536
582
|
*
|
|
583
|
+
* Prefer to instantiate only once and use trough your application a single shared `Pubky`
|
|
584
|
+
* instead of constructing one per request. This avoids reinitializing transports and keeps
|
|
585
|
+
* the same client available for repeated usage.
|
|
586
|
+
*
|
|
537
587
|
* @returns {Pubky}
|
|
538
588
|
* A new facade instance. Use this to create signers, start auth flows, etc.
|
|
539
589
|
*
|
|
@@ -573,11 +623,15 @@ export class Pubky {
|
|
|
573
623
|
* Provide a **capabilities string** and (optionally) a relay base URL.
|
|
574
624
|
* The capabilities string is a comma-separated list of entries:
|
|
575
625
|
* `"<scope>:<actions>"`, where:
|
|
576
|
-
* - `scope` starts with `/` (e.g. `/pub/example.
|
|
626
|
+
* - `scope` starts with `/` (e.g. `/pub/example.com/`).
|
|
577
627
|
* - `actions` is any combo of `r` and/or `w` (order normalized; `wr` -> `rw`).
|
|
578
628
|
* Pass `""` for no scopes (read-only public session).
|
|
579
629
|
*
|
|
580
630
|
* @param {string} capabilities Comma-separated caps, e.g. `"/pub/app/:rw,/pub/foo/file:r"`.
|
|
631
|
+
* @param {AuthFlowKind} kind The kind of authentication flow to perform.
|
|
632
|
+
* Examples:
|
|
633
|
+
* - `AuthFlowKind.signin()` - Sign in to an existing account.
|
|
634
|
+
* - `AuthFlowKind.signup(homeserverPublicKey, signupToken)` - Sign up for a new account.
|
|
581
635
|
* @param {string=} relay Optional HTTP relay base (e.g. `"https://…/link/"`).
|
|
582
636
|
* @returns {AuthFlow}
|
|
583
637
|
* A running auth flow. Show `authorizationUrl` as QR/deeplink,
|
|
@@ -588,11 +642,11 @@ export class Pubky {
|
|
|
588
642
|
* - `{ name: "RequestError" }` if the flow cannot be started (network/relay)
|
|
589
643
|
*
|
|
590
644
|
* @example
|
|
591
|
-
* const flow = pubky.startAuthFlow("/pub/my
|
|
645
|
+
* const flow = pubky.startAuthFlow("/pub/my-cool-app/:rw");
|
|
592
646
|
* renderQr(flow.authorizationUrl);
|
|
593
647
|
* const session = await flow.awaitApproval();
|
|
594
648
|
*/
|
|
595
|
-
startAuthFlow(capabilities: Capabilities, relay?: string | null): AuthFlow;
|
|
649
|
+
startAuthFlow(capabilities: Capabilities, kind: AuthFlowKind, relay?: string | null): AuthFlow;
|
|
596
650
|
/**
|
|
597
651
|
* Create a `Signer` from an existing `Keypair`.
|
|
598
652
|
*
|
|
@@ -610,19 +664,33 @@ export class Pubky {
|
|
|
610
664
|
* Uses an internal read-only Pkdns actor.
|
|
611
665
|
*
|
|
612
666
|
* @param {PublicKey} user
|
|
613
|
-
* @returns {Promise<PublicKey|undefined>} Homeserver public key
|
|
667
|
+
* @returns {Promise<PublicKey|undefined>} Homeserver public key or `undefined` if not found.
|
|
614
668
|
*/
|
|
615
669
|
getHomeserverOf(user_public_key: PublicKey): Promise<PublicKey | undefined>;
|
|
670
|
+
/**
|
|
671
|
+
* Restore a session from a previously exported snapshot, using this instance's client.
|
|
672
|
+
*
|
|
673
|
+
* This does **not** read or write any secrets. It revalidates the session metadata with
|
|
674
|
+
* the server using the browser-managed HTTP-only cookie that must still be present.
|
|
675
|
+
*
|
|
676
|
+
* @param {string} exported A string produced by `session.export()`.
|
|
677
|
+
* @returns {Promise<Session>}
|
|
678
|
+
* A rehydrated session bound to this SDK's HTTP client.
|
|
679
|
+
*
|
|
680
|
+
* @example
|
|
681
|
+
* const restored = await pubky.restoreSession(localStorage.getItem("pubky-session")!);
|
|
682
|
+
*/
|
|
683
|
+
restoreSession(exported: string): Promise<Session>;
|
|
616
684
|
/**
|
|
617
685
|
* Public, unauthenticated storage API.
|
|
618
686
|
*
|
|
619
687
|
* Use for **read-only** public access via addressed paths:
|
|
620
|
-
* `"<user
|
|
688
|
+
* `"pubky<user>/pub/…"`.
|
|
621
689
|
*
|
|
622
690
|
* @returns {PublicStorage}
|
|
623
691
|
*
|
|
624
692
|
* @example
|
|
625
|
-
* const text = await pubky.publicStorage.getText(`${userPk.
|
|
693
|
+
* const text = await pubky.publicStorage.getText(`${userPk.toString()}/pub/example.com/hello.txt`);
|
|
626
694
|
*/
|
|
627
695
|
readonly publicStorage: PublicStorage;
|
|
628
696
|
/**
|
|
@@ -632,13 +700,14 @@ export class Pubky {
|
|
|
632
700
|
* Use this for low-level `fetch()` calls or testing with raw URLs.
|
|
633
701
|
*
|
|
634
702
|
* @example
|
|
635
|
-
* const r = await pubky.client.fetch(`pubky://${
|
|
703
|
+
* const r = await pubky.client.fetch(`pubky://${userPk.z32()}/pub/app/file.txt`, { credentials: "include" });
|
|
636
704
|
*/
|
|
637
705
|
readonly client: Client;
|
|
638
706
|
}
|
|
639
707
|
export class PublicKey {
|
|
640
708
|
private constructor();
|
|
641
709
|
free(): void;
|
|
710
|
+
[Symbol.dispose](): void;
|
|
642
711
|
/**
|
|
643
712
|
* Convert the PublicKey to Uint8Array
|
|
644
713
|
*/
|
|
@@ -647,16 +716,22 @@ export class PublicKey {
|
|
|
647
716
|
* Returns the z-base32 encoding of this public key
|
|
648
717
|
*/
|
|
649
718
|
z32(): string;
|
|
719
|
+
/**
|
|
720
|
+
* Returns the identifier form with the `pubky` prefix.
|
|
721
|
+
* Use for display only; transport/storage should use `.z32()`.
|
|
722
|
+
*/
|
|
723
|
+
toString(): string;
|
|
650
724
|
/**
|
|
651
725
|
* @throws
|
|
652
726
|
*/
|
|
653
727
|
static from(value: string): PublicKey;
|
|
654
728
|
}
|
|
655
729
|
/**
|
|
656
|
-
* Read-only public storage using addressed paths (`"<user
|
|
730
|
+
* Read-only public storage using addressed paths (`"pubky<user>/pub/..."`).
|
|
657
731
|
*/
|
|
658
732
|
export class PublicStorage {
|
|
659
733
|
free(): void;
|
|
734
|
+
[Symbol.dispose](): void;
|
|
660
735
|
/**
|
|
661
736
|
* Construct PublicStorage using global client (mainline relays).
|
|
662
737
|
*/
|
|
@@ -716,6 +791,14 @@ export class PublicStorage {
|
|
|
716
791
|
*/
|
|
717
792
|
stats(address: Address): Promise<ResourceStats | undefined>;
|
|
718
793
|
}
|
|
794
|
+
export class SeedExportDeepLink {
|
|
795
|
+
private constructor();
|
|
796
|
+
free(): void;
|
|
797
|
+
[Symbol.dispose](): void;
|
|
798
|
+
static parse(url: string): SeedExportDeepLink;
|
|
799
|
+
toString(): string;
|
|
800
|
+
readonly secret: Uint8Array;
|
|
801
|
+
}
|
|
719
802
|
/**
|
|
720
803
|
* An authenticated context “as the user”.
|
|
721
804
|
* - Use `storage` for reads/writes (absolute paths like `/pub/app/file.txt`)
|
|
@@ -724,6 +807,7 @@ export class PublicStorage {
|
|
|
724
807
|
export class Session {
|
|
725
808
|
private constructor();
|
|
726
809
|
free(): void;
|
|
810
|
+
[Symbol.dispose](): void;
|
|
727
811
|
/**
|
|
728
812
|
* Invalidate the session on the server (clears server cookie).
|
|
729
813
|
* Further calls to storage API will fail.
|
|
@@ -731,6 +815,29 @@ export class Session {
|
|
|
731
815
|
* @returns {Promise<void>}
|
|
732
816
|
*/
|
|
733
817
|
signout(): Promise<void>;
|
|
818
|
+
/**
|
|
819
|
+
* Export the session metadata so it can be restored after a tab refresh.
|
|
820
|
+
*
|
|
821
|
+
* The export string contains **no secrets**; it only serializes the public `SessionInfo`.
|
|
822
|
+
* Browsers remain responsible for persisting the HTTP-only session cookie.
|
|
823
|
+
*
|
|
824
|
+
* @returns {string}
|
|
825
|
+
* A base64 string to store (e.g. in `localStorage`).
|
|
826
|
+
*/
|
|
827
|
+
export(): string;
|
|
828
|
+
/**
|
|
829
|
+
* Restore a session from an `export()` string.
|
|
830
|
+
*
|
|
831
|
+
* The HTTP-only cookie must still be present in the browser; this function does not
|
|
832
|
+
* read or write any secrets.
|
|
833
|
+
*
|
|
834
|
+
* @param {string} exported
|
|
835
|
+
* A string produced by `session.export()`.
|
|
836
|
+
* @param {Client=} client
|
|
837
|
+
* Optional client to reuse transport configuration.
|
|
838
|
+
* @returns {Promise<Session>}
|
|
839
|
+
*/
|
|
840
|
+
static restore(exported: string, client?: Client | null): Promise<Session>;
|
|
734
841
|
/**
|
|
735
842
|
* Retrieve immutable info about this session (user & capabilities).
|
|
736
843
|
*
|
|
@@ -750,15 +857,17 @@ export class Session {
|
|
|
750
857
|
export class SessionInfo {
|
|
751
858
|
private constructor();
|
|
752
859
|
free(): void;
|
|
860
|
+
[Symbol.dispose](): void;
|
|
753
861
|
/**
|
|
754
862
|
* The user’s public key for this session.
|
|
755
863
|
*
|
|
756
|
-
* Use `.
|
|
864
|
+
* Use `.toString()` on the returned `PublicKey` to get the `pubky<z32>` identifier.
|
|
865
|
+
* Call `.z32()` when you specifically need the raw z-base32 value (e.g. hostnames).
|
|
757
866
|
*
|
|
758
867
|
* @returns {PublicKey}
|
|
759
868
|
*
|
|
760
869
|
* @example
|
|
761
|
-
* const who = sessionInfo.publicKey.
|
|
870
|
+
* const who = sessionInfo.publicKey.toString();
|
|
762
871
|
*/
|
|
763
872
|
readonly publicKey: PublicKey;
|
|
764
873
|
/**
|
|
@@ -774,6 +883,7 @@ export class SessionInfo {
|
|
|
774
883
|
export class SessionStorage {
|
|
775
884
|
private constructor();
|
|
776
885
|
free(): void;
|
|
886
|
+
[Symbol.dispose](): void;
|
|
777
887
|
/**
|
|
778
888
|
* List a directory (absolute session path). Returns `pubky://…` URLs.
|
|
779
889
|
*
|
|
@@ -870,6 +980,7 @@ export class SessionStorage {
|
|
|
870
980
|
export class Signer {
|
|
871
981
|
private constructor();
|
|
872
982
|
free(): void;
|
|
983
|
+
[Symbol.dispose](): void;
|
|
873
984
|
/**
|
|
874
985
|
* Create a signer from a `Keypair` (prefer `pubky.signer(kp)`).
|
|
875
986
|
*
|
|
@@ -929,3 +1040,25 @@ export class Signer {
|
|
|
929
1040
|
*/
|
|
930
1041
|
readonly pkdns: Pkdns;
|
|
931
1042
|
}
|
|
1043
|
+
export class SigninDeepLink {
|
|
1044
|
+
private constructor();
|
|
1045
|
+
free(): void;
|
|
1046
|
+
[Symbol.dispose](): void;
|
|
1047
|
+
static parse(url: string): SigninDeepLink;
|
|
1048
|
+
toString(): string;
|
|
1049
|
+
readonly capabilities: string;
|
|
1050
|
+
readonly baseRelayUrl: string;
|
|
1051
|
+
readonly secret: Uint8Array;
|
|
1052
|
+
}
|
|
1053
|
+
export class SignupDeepLink {
|
|
1054
|
+
private constructor();
|
|
1055
|
+
free(): void;
|
|
1056
|
+
[Symbol.dispose](): void;
|
|
1057
|
+
static parse(url: string): SignupDeepLink;
|
|
1058
|
+
toString(): string;
|
|
1059
|
+
readonly capabilities: string;
|
|
1060
|
+
readonly baseRelayUrl: string;
|
|
1061
|
+
readonly secret: Uint8Array;
|
|
1062
|
+
readonly homeserver: PublicKey;
|
|
1063
|
+
readonly signupToken: string | undefined;
|
|
1064
|
+
}
|
package/pubky_bg.wasm
CHANGED
|
Binary file
|