@synonymdev/pubky 0.6.0-rc.7 → 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 +28 -13
- package/index.cjs +70 -47
- package/index.js +73 -50
- package/package.json +3 -3
- package/pubky.d.ts +69 -56
- 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
|
@@ -53,33 +53,6 @@ type Level = "error" | "warn" | "info" | "debug" | "trace";
|
|
|
53
53
|
type ReadableStreamType = "bytes";
|
|
54
54
|
export type Path = `/pub/${string}`;
|
|
55
55
|
|
|
56
|
-
export type Address = `pubky${string}/pub/${string}` | `pubky://${string}/pub/${string}`;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Pkarr Config
|
|
60
|
-
*/
|
|
61
|
-
export interface PkarrConfig {
|
|
62
|
-
/**
|
|
63
|
-
* The list of relays to access the DHT with.
|
|
64
|
-
*/
|
|
65
|
-
relays?: string[];
|
|
66
|
-
/**
|
|
67
|
-
* The timeout for DHT requests in milliseconds.
|
|
68
|
-
* Default is 2000ms.
|
|
69
|
-
*/
|
|
70
|
-
requestTimeout?: number;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Pubky Client Config
|
|
75
|
-
*/
|
|
76
|
-
export interface PubkyClientConfig {
|
|
77
|
-
/**
|
|
78
|
-
* Configuration on how to access pkarr packets on the mainline DHT.
|
|
79
|
-
*/
|
|
80
|
-
pkarr?: PkarrConfig;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
56
|
export type CapabilityAction = "r" | "w" | "rw";
|
|
84
57
|
export type CapabilityScope = `/${string}`;
|
|
85
58
|
export type CapabilityEntry = `${CapabilityScope}:${CapabilityAction}`;
|
|
@@ -162,6 +135,33 @@ export interface PubkyError extends Error {
|
|
|
162
135
|
data?: unknown;
|
|
163
136
|
}
|
|
164
137
|
|
|
138
|
+
export type Address = `pubky${string}/pub/${string}` | `pubky://${string}/pub/${string}`;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Pkarr Config
|
|
142
|
+
*/
|
|
143
|
+
export interface PkarrConfig {
|
|
144
|
+
/**
|
|
145
|
+
* The list of relays to access the DHT with.
|
|
146
|
+
*/
|
|
147
|
+
relays?: string[];
|
|
148
|
+
/**
|
|
149
|
+
* The timeout for DHT requests in milliseconds.
|
|
150
|
+
* Default is 2000ms.
|
|
151
|
+
*/
|
|
152
|
+
requestTimeout?: number;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Pubky Client Config
|
|
157
|
+
*/
|
|
158
|
+
export interface PubkyClientConfig {
|
|
159
|
+
/**
|
|
160
|
+
* Configuration on how to access pkarr packets on the mainline DHT.
|
|
161
|
+
*/
|
|
162
|
+
pkarr?: PkarrConfig;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
165
|
/**
|
|
166
166
|
* Resource metadata returned by `SessionStorage.stats()` and `PublicStorage.stats()`.
|
|
167
167
|
*
|
|
@@ -327,7 +327,7 @@ export class AuthFlowKind {
|
|
|
327
327
|
* const token = await flow.awaitToken();
|
|
328
328
|
*
|
|
329
329
|
* // Identify the user
|
|
330
|
-
* console.log(token.publicKey().
|
|
330
|
+
* console.log(token.publicKey().toString());
|
|
331
331
|
*
|
|
332
332
|
* // Optionally forward to a server for verification:
|
|
333
333
|
* await fetch("/api/verify", { method: "POST", body: token.toBytes() });
|
|
@@ -355,7 +355,7 @@ export class AuthToken {
|
|
|
355
355
|
* export async function POST(req) {
|
|
356
356
|
* const bytes = new Uint8Array(await req.arrayBuffer());
|
|
357
357
|
* const token = AuthToken.verify(bytes); // throws on failure
|
|
358
|
-
* return new Response(token.publicKey().
|
|
358
|
+
* return new Response(token.publicKey().toString(), { status: 200 });
|
|
359
359
|
* }
|
|
360
360
|
* ```
|
|
361
361
|
*/
|
|
@@ -383,10 +383,11 @@ export class AuthToken {
|
|
|
383
383
|
/**
|
|
384
384
|
* Returns the **public key** that authenticated with this token.
|
|
385
385
|
*
|
|
386
|
-
* 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).
|
|
387
388
|
*
|
|
388
389
|
* @example
|
|
389
|
-
* const who =
|
|
390
|
+
* const who = token.publicKey.toString();
|
|
390
391
|
*/
|
|
391
392
|
readonly publicKey: PublicKey;
|
|
392
393
|
/**
|
|
@@ -410,6 +411,18 @@ export class AuthToken {
|
|
|
410
411
|
export class Client {
|
|
411
412
|
free(): void;
|
|
412
413
|
[Symbol.dispose](): void;
|
|
414
|
+
/**
|
|
415
|
+
* Perform a raw fetch. Works with `http(s)://` URLs.
|
|
416
|
+
*
|
|
417
|
+
* @param {string} url
|
|
418
|
+
* @param {RequestInit} init Standard fetch options; `credentials: "include"` recommended for session I/O.
|
|
419
|
+
* @returns {Promise<Response>}
|
|
420
|
+
*
|
|
421
|
+
* @example
|
|
422
|
+
* const client = pubky.client;
|
|
423
|
+
* const res = await client.fetch(`https://_pubky.${user}/pub/app/file.txt`, { method: "PUT", body: "hi", credentials: "include" });
|
|
424
|
+
*/
|
|
425
|
+
fetch(url: string, init?: RequestInit | null): Promise<Response>;
|
|
413
426
|
/**
|
|
414
427
|
* Create a Pubky HTTP client.
|
|
415
428
|
*
|
|
@@ -450,18 +463,6 @@ export class Client {
|
|
|
450
463
|
* const client = Client.testnet("docker0"); // custom host
|
|
451
464
|
*/
|
|
452
465
|
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>;
|
|
465
466
|
}
|
|
466
467
|
export class IntoUnderlyingByteSource {
|
|
467
468
|
private constructor();
|
|
@@ -497,13 +498,13 @@ export class Keypair {
|
|
|
497
498
|
*/
|
|
498
499
|
static random(): Keypair;
|
|
499
500
|
/**
|
|
500
|
-
* Generate a [Keypair] from a secret
|
|
501
|
+
* Generate a [Keypair] from a 32-byte secret.
|
|
501
502
|
*/
|
|
502
|
-
static
|
|
503
|
+
static fromSecret(secret: Uint8Array): Keypair;
|
|
503
504
|
/**
|
|
504
|
-
* Returns the secret
|
|
505
|
+
* Returns the secret of this keypair.
|
|
505
506
|
*/
|
|
506
|
-
|
|
507
|
+
secret(): Uint8Array;
|
|
507
508
|
/**
|
|
508
509
|
* Create a recovery file for this keypair (encrypted with the given passphrase).
|
|
509
510
|
*/
|
|
@@ -515,10 +516,12 @@ export class Keypair {
|
|
|
515
516
|
/**
|
|
516
517
|
* Returns the [PublicKey] of this keypair.
|
|
517
518
|
*
|
|
518
|
-
* 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()`.
|
|
519
522
|
*
|
|
520
523
|
* @example
|
|
521
|
-
* const who = keypair.publicKey.
|
|
524
|
+
* const who = keypair.publicKey.toString();
|
|
522
525
|
*/
|
|
523
526
|
readonly publicKey: PublicKey;
|
|
524
527
|
}
|
|
@@ -577,6 +580,10 @@ export class Pubky {
|
|
|
577
580
|
/**
|
|
578
581
|
* Create a Pubky facade wired for **mainnet** defaults (public relays).
|
|
579
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
|
+
*
|
|
580
587
|
* @returns {Pubky}
|
|
581
588
|
* A new facade instance. Use this to create signers, start auth flows, etc.
|
|
582
589
|
*
|
|
@@ -657,7 +664,7 @@ export class Pubky {
|
|
|
657
664
|
* Uses an internal read-only Pkdns actor.
|
|
658
665
|
*
|
|
659
666
|
* @param {PublicKey} user
|
|
660
|
-
* @returns {Promise<PublicKey|undefined>} Homeserver public key
|
|
667
|
+
* @returns {Promise<PublicKey|undefined>} Homeserver public key or `undefined` if not found.
|
|
661
668
|
*/
|
|
662
669
|
getHomeserverOf(user_public_key: PublicKey): Promise<PublicKey | undefined>;
|
|
663
670
|
/**
|
|
@@ -678,12 +685,12 @@ export class Pubky {
|
|
|
678
685
|
* Public, unauthenticated storage API.
|
|
679
686
|
*
|
|
680
687
|
* Use for **read-only** public access via addressed paths:
|
|
681
|
-
* `"<user
|
|
688
|
+
* `"pubky<user>/pub/…"`.
|
|
682
689
|
*
|
|
683
690
|
* @returns {PublicStorage}
|
|
684
691
|
*
|
|
685
692
|
* @example
|
|
686
|
-
* const text = await pubky.publicStorage.getText(`${userPk.
|
|
693
|
+
* const text = await pubky.publicStorage.getText(`${userPk.toString()}/pub/example.com/hello.txt`);
|
|
687
694
|
*/
|
|
688
695
|
readonly publicStorage: PublicStorage;
|
|
689
696
|
/**
|
|
@@ -693,7 +700,7 @@ export class Pubky {
|
|
|
693
700
|
* Use this for low-level `fetch()` calls or testing with raw URLs.
|
|
694
701
|
*
|
|
695
702
|
* @example
|
|
696
|
-
* const r = await pubky.client.fetch(`pubky://${
|
|
703
|
+
* const r = await pubky.client.fetch(`pubky://${userPk.z32()}/pub/app/file.txt`, { credentials: "include" });
|
|
697
704
|
*/
|
|
698
705
|
readonly client: Client;
|
|
699
706
|
}
|
|
@@ -709,13 +716,18 @@ export class PublicKey {
|
|
|
709
716
|
* Returns the z-base32 encoding of this public key
|
|
710
717
|
*/
|
|
711
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;
|
|
712
724
|
/**
|
|
713
725
|
* @throws
|
|
714
726
|
*/
|
|
715
727
|
static from(value: string): PublicKey;
|
|
716
728
|
}
|
|
717
729
|
/**
|
|
718
|
-
* Read-only public storage using addressed paths (`"<user
|
|
730
|
+
* Read-only public storage using addressed paths (`"pubky<user>/pub/..."`).
|
|
719
731
|
*/
|
|
720
732
|
export class PublicStorage {
|
|
721
733
|
free(): void;
|
|
@@ -849,12 +861,13 @@ export class SessionInfo {
|
|
|
849
861
|
/**
|
|
850
862
|
* The user’s public key for this session.
|
|
851
863
|
*
|
|
852
|
-
* 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).
|
|
853
866
|
*
|
|
854
867
|
* @returns {PublicKey}
|
|
855
868
|
*
|
|
856
869
|
* @example
|
|
857
|
-
* const who = sessionInfo.publicKey.
|
|
870
|
+
* const who = sessionInfo.publicKey.toString();
|
|
858
871
|
*/
|
|
859
872
|
readonly publicKey: PublicKey;
|
|
860
873
|
/**
|
package/pubky_bg.wasm
CHANGED
|
Binary file
|