@synonymdev/pubky 0.1.0 → 0.1.1
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/LICENSE +21 -0
- package/README.md +76 -0
- package/browser.js +975 -0
- package/index.js +1 -0
- package/package.json +39 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# Pubky
|
|
2
|
+
|
|
3
|
+
JavaScript implementation of [Pubky](https://github.com/pubky/pubky).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @synonymdev/pubky
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Getting started
|
|
12
|
+
|
|
13
|
+
```js
|
|
14
|
+
import { PubkyClient, Keypair, PublicKey } from '../index.js'
|
|
15
|
+
|
|
16
|
+
// Initialize PubkyClient with Pkarr relay(s).
|
|
17
|
+
let client = new PubkyClient();
|
|
18
|
+
|
|
19
|
+
// Generate a keypair
|
|
20
|
+
let keypair = Keypair.random();
|
|
21
|
+
|
|
22
|
+
// Create a new account
|
|
23
|
+
let homeserver = PublicKey.from("8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo");
|
|
24
|
+
|
|
25
|
+
await client.signup(keypair, homeserver)
|
|
26
|
+
|
|
27
|
+
const publicKey = keypair.public_key();
|
|
28
|
+
|
|
29
|
+
// Verify that you are signed in.
|
|
30
|
+
const session = await client.session(publicKey)
|
|
31
|
+
|
|
32
|
+
const body = Buffer.from(JSON.stringify({ foo: 'bar' }))
|
|
33
|
+
|
|
34
|
+
// PUT public data, by authorized client
|
|
35
|
+
await client.put(publicKey, "/pub/example.com/arbitrary", body);
|
|
36
|
+
|
|
37
|
+
// GET public data without signup or signin
|
|
38
|
+
{
|
|
39
|
+
const client = new PubkyClient();
|
|
40
|
+
|
|
41
|
+
let response = await client.get(publicKey, "/pub/example.com/arbitrary");
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Test and Development
|
|
46
|
+
|
|
47
|
+
For test and development, you can run a local homeserver in a test network.
|
|
48
|
+
|
|
49
|
+
If you don't have Cargo Installed, start by installing it:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
curl https://sh.rustup.rs -sSf | sh
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Clone the Pubky repository:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
git clone https://github.com/pubky/pubky
|
|
59
|
+
cd pubky/pkg
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Run the local testnet server
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
npm run testnet
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Pass the logged addresses as inputs to `PubkyClient`
|
|
69
|
+
|
|
70
|
+
```js
|
|
71
|
+
import { PubkyClient, PublicKey } from '../index.js'
|
|
72
|
+
|
|
73
|
+
const client = new PubkyClient().setPkarrRelays(["http://localhost:15411/pkarr"]);
|
|
74
|
+
|
|
75
|
+
let homeserver = PublicKey.from("8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo");
|
|
76
|
+
```
|