@synonymdev/pubky 0.2.1 → 0.4.0-rc.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/README.md +24 -36
- package/index.cjs +543 -525
- package/index.js +630 -604
- package/package.json +3 -3
- package/pubky.d.ts +99 -161
- package/pubky_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Pubky
|
|
2
2
|
|
|
3
|
-
JavaScript implementation of [Pubky](https://github.com/pubky/pubky).
|
|
3
|
+
JavaScript implementation of [Pubky](https://github.com/pubky/pubky-core) client.
|
|
4
4
|
|
|
5
5
|
## Table of Contents
|
|
6
6
|
- [Install](#install)
|
|
@@ -21,10 +21,10 @@ For Nodejs, you need Node v20 or later.
|
|
|
21
21
|
## Getting started
|
|
22
22
|
|
|
23
23
|
```js
|
|
24
|
-
import {
|
|
24
|
+
import { Client, Keypair, PublicKey } from '../index.js'
|
|
25
25
|
|
|
26
|
-
// Initialize
|
|
27
|
-
let client = new
|
|
26
|
+
// Initialize Client with Pkarr relay(s).
|
|
27
|
+
let client = new Client();
|
|
28
28
|
|
|
29
29
|
// Generate a keypair
|
|
30
30
|
let keypair = Keypair.random();
|
|
@@ -42,31 +42,40 @@ let url = `pubky://${publicKey.z32()}/pub/example.com/arbitrary`;
|
|
|
42
42
|
// Verify that you are signed in.
|
|
43
43
|
const session = await client.session(publicKey)
|
|
44
44
|
|
|
45
|
-
const body = Buffer.from(JSON.stringify({ foo: 'bar' }))
|
|
46
|
-
|
|
47
45
|
// PUT public data, by authorized client
|
|
48
|
-
await client.
|
|
46
|
+
await client.fetch(url, {
|
|
47
|
+
method: "PUT",
|
|
48
|
+
body: JSON.stringify({foo: "bar"}),
|
|
49
|
+
credentials: "include"
|
|
50
|
+
});
|
|
49
51
|
|
|
50
52
|
// GET public data without signup or signin
|
|
51
53
|
{
|
|
52
|
-
const client = new
|
|
54
|
+
const client = new Client();
|
|
53
55
|
|
|
54
|
-
let response = await client.
|
|
56
|
+
let response = await client.fetch(url);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// Delete public data, by authorized client
|
|
58
|
-
await client.
|
|
60
|
+
await client.fetch(url, { method: "DELETE", credentials: "include "});
|
|
59
61
|
```
|
|
60
62
|
|
|
61
63
|
## API
|
|
62
64
|
|
|
63
|
-
###
|
|
65
|
+
### Client
|
|
64
66
|
|
|
65
67
|
#### constructor
|
|
66
68
|
```js
|
|
67
|
-
let client = new
|
|
69
|
+
let client = new Client()
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### fetch
|
|
73
|
+
```js
|
|
74
|
+
let response = await client.fetch(url, opts);
|
|
68
75
|
```
|
|
69
76
|
|
|
77
|
+
Just like normal Fetch API, but it can handle `pubky://` urls and `http(s)://` urls with Pkarr domains.
|
|
78
|
+
|
|
70
79
|
#### signup
|
|
71
80
|
```js
|
|
72
81
|
await client.signup(keypair, homeserver)
|
|
@@ -127,27 +136,6 @@ let session = await client.session(publicKey)
|
|
|
127
136
|
- publicKey: An instance of [PublicKey](#publickey).
|
|
128
137
|
- Returns: A [Session](#session) object if signed in, or undefined if not.
|
|
129
138
|
|
|
130
|
-
#### put
|
|
131
|
-
```js
|
|
132
|
-
let response = await client.put(url, body);
|
|
133
|
-
```
|
|
134
|
-
- url: A string representing the Pubky URL.
|
|
135
|
-
- body: A Buffer containing the data to be stored.
|
|
136
|
-
|
|
137
|
-
### get
|
|
138
|
-
```js
|
|
139
|
-
let response = await client.get(url)
|
|
140
|
-
```
|
|
141
|
-
- url: A string representing the Pubky URL.
|
|
142
|
-
- Returns: A Uint8Array object containing the requested data, or `undefined` if `NOT_FOUND`.
|
|
143
|
-
|
|
144
|
-
### delete
|
|
145
|
-
|
|
146
|
-
```js
|
|
147
|
-
let response = await client.delete(url);
|
|
148
|
-
```
|
|
149
|
-
- url: A string representing the Pubky URL.
|
|
150
|
-
|
|
151
139
|
### list
|
|
152
140
|
```js
|
|
153
141
|
let response = await client.list(url, cursor, reverse, limit)
|
|
@@ -257,10 +245,10 @@ Run the local testnet server
|
|
|
257
245
|
npm run testnet
|
|
258
246
|
```
|
|
259
247
|
|
|
260
|
-
Use the logged addresses as inputs to `
|
|
248
|
+
Use the logged addresses as inputs to `Client`
|
|
261
249
|
|
|
262
250
|
```js
|
|
263
|
-
import {
|
|
251
|
+
import { Client } from '../index.js'
|
|
264
252
|
|
|
265
|
-
const client =
|
|
253
|
+
const client = Client().testnet();
|
|
266
254
|
```
|