@synonymdev/pubky 0.5.2 → 0.5.4

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.5.2",
5
+ "version": "0.5.4",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
package/pubky.d.ts ADDED
@@ -0,0 +1,197 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /**
4
+ * Create a recovery file of the `keypair`, containing the secret key encrypted
5
+ * using the `passphrase`.
6
+ */
7
+ export function createRecoveryFile(keypair: Keypair, passphrase: string): Uint8Array;
8
+ /**
9
+ * Create a recovery file of the `keypair`, containing the secret key encrypted
10
+ * using the `passphrase`.
11
+ */
12
+ export function decryptRecoveryFile(recovery_file: Uint8Array, passphrase: string): Keypair;
13
+ export function setLogLevel(level: string): void;
14
+ /**
15
+ * Pkarr Config
16
+ */
17
+ export interface PkarrConfig {
18
+ /**
19
+ * The list of relays to access the DHT with.
20
+ */
21
+ relays?: string[];
22
+ /**
23
+ * The timeout for DHT requests in milliseconds.
24
+ * Default is 2000ms.
25
+ */
26
+ requestTimeout?: NonZeroU64;
27
+ }
28
+
29
+ /**
30
+ * Pubky Client Config
31
+ */
32
+ export interface PubkyClientConfig {
33
+ /**
34
+ * Configuration on how to access pkarr packets on the mainline DHT.
35
+ */
36
+ pkarr?: PkarrConfig;
37
+ /**
38
+ * The maximum age of a record in seconds.
39
+ * If the user pkarr record is older than this, it will be automatically refreshed.
40
+ */
41
+ userMaxRecordAge?: NonZeroU64;
42
+ }
43
+
44
+ export class AuthRequest {
45
+ private constructor();
46
+ free(): void;
47
+ /**
48
+ * Returns the Pubky Auth url, which you should show to the user
49
+ * to request an authentication or authorization token.
50
+ *
51
+ * Wait for this token using `this.response()`.
52
+ */
53
+ url(): string;
54
+ /**
55
+ * Wait for the user to send an authentication or authorization proof.
56
+ *
57
+ * If successful, you should expect an instance of [PublicKey]
58
+ *
59
+ * Otherwise it will throw an error.
60
+ */
61
+ response(): Promise<PublicKey>;
62
+ }
63
+ export class Client {
64
+ free(): void;
65
+ /**
66
+ * Signup to a homeserver and update Pkarr accordingly.
67
+ *
68
+ * The homeserver is a Pkarr domain name, where the TLD is a Pkarr public key
69
+ * for example "pubky.o4dksfbqk85ogzdb5osziw6befigbuxmuxkuxq8434q89uj56uyy"
70
+ */
71
+ signup(keypair: Keypair, homeserver: PublicKey, signup_token?: string | null): Promise<Session>;
72
+ /**
73
+ * Check the current session for a given Pubky in its homeserver.
74
+ *
75
+ * Returns [Session] or `None` (if received `404 NOT_FOUND`),
76
+ * or throws the received error if the response has any other `>=400` status code.
77
+ */
78
+ session(pubky: PublicKey): Promise<Session | undefined>;
79
+ /**
80
+ * Signout from a homeserver.
81
+ */
82
+ signout(pubky: PublicKey): Promise<void>;
83
+ /**
84
+ * Signin to a homeserver using the root Keypair.
85
+ */
86
+ signin(keypair: Keypair): Promise<void>;
87
+ /**
88
+ * Return `pubkyauth://` url and wait for the incoming [AuthToken]
89
+ * verifying that AuthToken, and if capabilities were requested, signing in to
90
+ * the Pubky's homeserver and returning the [Session] information.
91
+ *
92
+ * Returns a [AuthRequest]
93
+ */
94
+ authRequest(relay: string, capabilities: string): AuthRequest;
95
+ /**
96
+ * Sign an [pubky_common::auth::AuthToken], encrypt it and send it to the
97
+ * source of the pubkyauth request url.
98
+ */
99
+ sendAuthToken(keypair: Keypair, pubkyauth_url: string): Promise<void>;
100
+ /**
101
+ * Get the homeserver id for a given Pubky public key.
102
+ * Looks up the pkarr packet for the given public key and returns the content of the first `_pubky` SVCB record.
103
+ * Throws an error if no homeserver is found.
104
+ */
105
+ getHomeserver(public_key: PublicKey): Promise<PublicKey>;
106
+ /**
107
+ * Republish the user's PKarr record pointing to their homeserver.
108
+ *
109
+ * This method will republish the record if no record exists or if the existing record
110
+ * is older than 6 hours.
111
+ *
112
+ * The method is intended for clients and key managers (e.g., pubky-ring) to
113
+ * keep the records of active users fresh and available in the DHT and relays.
114
+ * It is intended to be used only after failed signin due to homeserver resolution
115
+ * failure. This method is lighter than performing a re-signup into the last known
116
+ * homeserver, but does not return a session token, so a signin must be done after
117
+ * republishing. On a failed signin due to homeserver resolution failure, a key
118
+ * manager should always attempt to republish the last known homeserver.
119
+ */
120
+ republishHomeserver(keypair: Keypair, host: PublicKey): Promise<void>;
121
+ /**
122
+ * Returns a list of Pubky urls (as strings).
123
+ *
124
+ * - `url`: The Pubky url (string) to the directory you want to list its content.
125
+ * - `cursor`: Either a full `pubky://` Url (from previous list response),
126
+ * or a path (to a file or directory) relative to the `url`
127
+ * - `reverse`: List in reverse order
128
+ * - `limit` Limit the number of urls in the response
129
+ * - `shallow`: List directories and files, instead of flat list of files.
130
+ */
131
+ list(url: string, cursor?: string | null, reverse?: boolean | null, limit?: number | null, shallow?: boolean | null): Promise<Array<any>>;
132
+ fetch(url: string, init?: any | null): Promise<Promise<any>>;
133
+ /**
134
+ * Create a new Pubky Client with an optional configuration.
135
+ */
136
+ constructor(config_opt?: PubkyClientConfig | null);
137
+ /**
138
+ * Create a client with with configurations appropriate for local testing:
139
+ * - set Pkarr relays to `http://<host>:15411` (defaults to `localhost`).
140
+ * - transform `pubky://<pkarr public key>` to `http://<host>` instead of `https:`
141
+ * and read the homeserver HTTP port from the PKarr record.
142
+ */
143
+ static testnet(host?: string | null): Client;
144
+ }
145
+ export class Keypair {
146
+ private constructor();
147
+ free(): void;
148
+ /**
149
+ * Generate a random [Keypair]
150
+ */
151
+ static random(): Keypair;
152
+ /**
153
+ * Generate a [Keypair] from a secret key.
154
+ */
155
+ static fromSecretKey(secret_key: Uint8Array): Keypair;
156
+ /**
157
+ * Returns the secret key of this keypair.
158
+ */
159
+ secretKey(): Uint8Array;
160
+ /**
161
+ * Returns the [PublicKey] of this keypair.
162
+ */
163
+ publicKey(): PublicKey;
164
+ }
165
+ export class PublicKey {
166
+ private constructor();
167
+ free(): void;
168
+ /**
169
+ * Convert the PublicKey to Uint8Array
170
+ * @deprecated Use `toUint8Array` instead
171
+ */
172
+ to_uint8array(): Uint8Array;
173
+ /**
174
+ * Convert the PublicKey to Uint8Array
175
+ */
176
+ toUint8Array(): Uint8Array;
177
+ /**
178
+ * Returns the z-base32 encoding of this public key
179
+ */
180
+ z32(): string;
181
+ /**
182
+ * @throws
183
+ */
184
+ static from(value: string): PublicKey;
185
+ }
186
+ export class Session {
187
+ private constructor();
188
+ free(): void;
189
+ /**
190
+ * Return the [PublicKey] of this session
191
+ */
192
+ pubky(): PublicKey;
193
+ /**
194
+ * Return the capabilities that this session has.
195
+ */
196
+ capabilities(): string[];
197
+ }
package/pubky_bg.wasm ADDED
Binary file