@synonymdev/pubky 0.4.0 → 0.4.2-rc2

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 CHANGED
@@ -3,6 +3,7 @@
3
3
  JavaScript implementation of [Pubky](https://github.com/pubky/pubky-core) client.
4
4
 
5
5
  ## Table of Contents
6
+
6
7
  - [Install](#install)
7
8
  - [Getting Started](#getting-started)
8
9
  - [API](#api)
@@ -21,7 +22,7 @@ For Nodejs, you need Node v20 or later.
21
22
  ## Getting started
22
23
 
23
24
  ```js
24
- import { Client, Keypair, PublicKey } from '../index.js'
25
+ import { Client, Keypair, PublicKey } from "../index.js";
25
26
 
26
27
  // Initialize Client with Pkarr relay(s).
27
28
  let client = new Client();
@@ -30,9 +31,11 @@ let client = new Client();
30
31
  let keypair = Keypair.random();
31
32
 
32
33
  // Create a new account
33
- let homeserver = PublicKey.from("8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo");
34
+ let homeserver = PublicKey.from(
35
+ "8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo"
36
+ );
34
37
 
35
- await client.signup(keypair, homeserver)
38
+ await client.signup(keypair, homeserver, signup_token);
36
39
 
37
40
  const publicKey = keypair.publicKey();
38
41
 
@@ -40,24 +43,24 @@ const publicKey = keypair.publicKey();
40
43
  let url = `pubky://${publicKey.z32()}/pub/example.com/arbitrary`;
41
44
 
42
45
  // Verify that you are signed in.
43
- const session = await client.session(publicKey)
46
+ const session = await client.session(publicKey);
44
47
 
45
48
  // PUT public data, by authorized client
46
- await client.fetch(url, {
47
- method: "PUT",
48
- body: JSON.stringify({foo: "bar"}),
49
- credentials: "include"
49
+ await client.fetch(url, {
50
+ method: "PUT",
51
+ body: JSON.stringify({ foo: "bar" }),
52
+ credentials: "include",
50
53
  });
51
54
 
52
55
  // GET public data without signup or signin
53
56
  {
54
- const client = new Client();
57
+ const client = new Client();
55
58
 
56
- let response = await client.fetch(url);
59
+ let response = await client.fetch(url);
57
60
  }
58
61
 
59
62
  // Delete public data, by authorized client
60
- await client.fetch(url, { method: "DELETE", credentials: "include "});
63
+ await client.fetch(url, { method: "DELETE", credentials: "include " });
61
64
  ```
62
65
 
63
66
  ## API
@@ -65,11 +68,13 @@ await client.fetch(url, { method: "DELETE", credentials: "include "});
65
68
  ### Client
66
69
 
67
70
  #### constructor
71
+
68
72
  ```js
69
- let client = new Client()
73
+ let client = new Client();
70
74
  ```
71
75
 
72
76
  #### fetch
77
+
73
78
  ```js
74
79
  let response = await client.fetch(url, opts);
75
80
  ```
@@ -77,35 +82,45 @@ let response = await client.fetch(url, opts);
77
82
  Just like normal Fetch API, but it can handle `pubky://` urls and `http(s)://` urls with Pkarr domains.
78
83
 
79
84
  #### signup
85
+
80
86
  ```js
81
- await client.signup(keypair, homeserver)
87
+ await client.signup(keypair, homeserver, signup_token);
82
88
  ```
89
+
83
90
  - keypair: An instance of [Keypair](#keypair).
84
91
  - homeserver: An instance of [PublicKey](#publickey) representing the homeserver.
92
+ - signup_token: A homeserver could optionally ask for a valid signup token (aka, invitation code).
85
93
 
86
94
  Returns:
95
+
87
96
  - session: An instance of [Session](#session).
88
97
 
89
98
  #### signin
99
+
90
100
  ```js
91
- let session = await client.signin(keypair)
101
+ let session = await client.signin(keypair);
92
102
  ```
103
+
93
104
  - keypair: An instance of [Keypair](#keypair).
94
105
 
95
106
  Returns:
107
+
96
108
  - An instance of [Session](#session).
97
109
 
98
110
  #### signout
111
+
99
112
  ```js
100
- await client.signout(publicKey)
113
+ await client.signout(publicKey);
101
114
  ```
115
+
102
116
  - publicKey: An instance of [PublicKey](#publicKey).
103
117
 
104
118
  #### authRequest
119
+
105
120
  ```js
106
121
  let pubkyAuthRequest = client.authRequest(relay, capabilities);
107
122
 
108
- let pubkyauthUrl= pubkyAuthRequest.url();
123
+ let pubkyauthUrl = pubkyAuthRequest.url();
109
124
 
110
125
  showQr(pubkyauthUrl);
111
126
 
@@ -119,25 +134,31 @@ instead request permissions (showing the user pubkyauthUrl), and await a Session
119
134
  - capabilities: A list of capabilities required for the app for example `/pub/pubky.app/:rw,/pub/example.com/:r`.
120
135
 
121
136
  #### sendAuthToken
137
+
122
138
  ```js
123
139
  await client.sendAuthToken(keypair, pubkyauthUrl);
124
140
  ```
141
+
125
142
  Consenting to authentication or authorization according to the required capabilities in the `pubkyauthUrl` , and sign and send an auth token to the requester.
126
143
 
127
144
  - keypair: An instance of [KeyPair](#keypair)
128
145
  - pubkyauthUrl: A string `pubkyauth://` url
129
146
 
130
147
  #### session {#session-method}
148
+
131
149
  ```js
132
- let session = await client.session(publicKey)
150
+ let session = await client.session(publicKey);
133
151
  ```
152
+
134
153
  - publicKey: An instance of [PublicKey](#publickey).
135
154
  - Returns: A [Session](#session) object if signed in, or undefined if not.
136
155
 
137
156
  ### list
157
+
138
158
  ```js
139
- let response = await client.list(url, cursor, reverse, limit)
159
+ let response = await client.list(url, cursor, reverse, limit);
140
160
  ```
161
+
141
162
  - url: A string representing the Pubky URL. The path in that url is the prefix that you want to list files within.
142
163
  - cursor: Usually the last URL from previous calls. List urls after/before (depending on `reverse`) the cursor.
143
164
  - reverse: Whether or not return urls in reverse order.
@@ -147,29 +168,36 @@ let response = await client.list(url, cursor, reverse, limit)
147
168
  ### Keypair
148
169
 
149
170
  #### random
171
+
150
172
  ```js
151
- let keypair = Keypair.random()
173
+ let keypair = Keypair.random();
152
174
  ```
175
+
153
176
  - Returns: A new random Keypair.
154
177
 
155
178
  #### fromSecretKey
179
+
156
180
  ```js
157
- let keypair = Keypair.fromSecretKey(secretKey)
181
+ let keypair = Keypair.fromSecretKey(secretKey);
158
182
  ```
183
+
159
184
  - secretKey: A 32 bytes Uint8array.
160
185
  - Returns: A new Keypair.
161
186
 
162
-
163
187
  #### publicKey {#publickey-method}
188
+
164
189
  ```js
165
- let publicKey = keypair.publicKey()
190
+ let publicKey = keypair.publicKey();
166
191
  ```
192
+
167
193
  - Returns: The [PublicKey](#publickey) associated with the Keypair.
168
194
 
169
195
  #### secretKey
196
+
170
197
  ```js
171
- let secretKey = keypair.secretKey()
198
+ let secretKey = keypair.secretKey();
172
199
  ```
200
+
173
201
  - Returns: The Uint8array secret key associated with the Keypair.
174
202
 
175
203
  ### PublicKey
@@ -179,43 +207,54 @@ let secretKey = keypair.secretKey()
179
207
  ```js
180
208
  let publicKey = PublicKey.from(string);
181
209
  ```
210
+
182
211
  - string: A string representing the public key.
183
212
  - Returns: A new PublicKey instance.
184
213
 
185
214
  #### z32
215
+
186
216
  ```js
187
217
  let pubky = publicKey.z32();
188
218
  ```
219
+
189
220
  Returns: The z-base-32 encoded string representation of the PublicKey.
190
221
 
191
- ### Session
222
+ ### Session
192
223
 
193
224
  #### pubky
225
+
194
226
  ```js
195
227
  let pubky = session.pubky();
196
228
  ```
229
+
197
230
  Returns an instance of [PublicKey](#publickey)
198
231
 
199
232
  #### capabilities
233
+
200
234
  ```js
201
235
  let capabilities = session.capabilities();
202
236
  ```
237
+
203
238
  Returns an array of capabilities, for example `["/pub/pubky.app/:rw"]`
204
239
 
205
240
  ### Helper functions
206
241
 
207
242
  #### createRecoveryFile
243
+
208
244
  ```js
209
- let recoveryFile = createRecoveryFile(keypair, passphrase)
245
+ let recoveryFile = createRecoveryFile(keypair, passphrase);
210
246
  ```
247
+
211
248
  - keypair: An instance of [Keypair](#keypair).
212
249
  - passphrase: A utf-8 string [passphrase](https://www.useapassphrase.com/).
213
250
  - Returns: A recovery file with a spec line and an encrypted secret key.
214
251
 
215
252
  #### createRecoveryFile
253
+
216
254
  ```js
217
- let keypair = decryptRecoveryfile(recoveryFile, passphrase)
255
+ let keypair = decryptRecoveryfile(recoveryFile, passphrase);
218
256
  ```
257
+
219
258
  - recoveryFile: An instance of Uint8Array containing the recovery file blob.
220
259
  - passphrase: A utf-8 string [passphrase](https://www.useapassphrase.com/).
221
260
  - Returns: An instance of [Keypair](#keypair).
@@ -246,7 +285,7 @@ npm run testnet
246
285
  Use the logged addresses as inputs to `Client`
247
286
 
248
287
  ```js
249
- import { Client } from '../index.js'
288
+ import { Client } from "../index.js";
250
289
 
251
290
  const client = Client().testnet();
252
291
  ```