nostr-tools 0.12.1 → 0.12.2
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/.eslintrc.json +1 -0
- package/event.js +4 -4
- package/index.js +1 -0
- package/nip06.js +0 -1
- package/package.json +6 -3
- package/pool.js +27 -23
- package/relay.js +3 -1
package/.eslintrc.json
CHANGED
package/event.js
CHANGED
|
@@ -34,13 +34,13 @@ export function verifySignature(event) {
|
|
|
34
34
|
if (event.id !== getEventHash(event)) return false
|
|
35
35
|
return verifySchnorr(
|
|
36
36
|
Buffer.from(event.id, 'hex'),
|
|
37
|
-
Buffer.from(event.pubkey, 'hex')
|
|
38
|
-
Buffer.from(event.sig, 'hex')
|
|
37
|
+
Buffer.from(event.pubkey, 'hex'),
|
|
38
|
+
Buffer.from(event.sig, 'hex')
|
|
39
39
|
)
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export function signEvent(event, key) {
|
|
43
43
|
let eventHash = Buffer.from(getEventHash(event), 'hex')
|
|
44
|
-
let
|
|
45
|
-
return Buffer.from(signSchnorr(eventHash,
|
|
44
|
+
let keyB = Buffer.from(key, 'hex')
|
|
45
|
+
return Buffer.from(signSchnorr(eventHash, keyB)).toString('hex')
|
|
46
46
|
}
|
package/index.js
CHANGED
package/nip06.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nostr-tools",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"description": "Tools for making a Nostr client.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"browserify-cipher": ">=1",
|
|
13
13
|
"buffer": ">=5",
|
|
14
14
|
"create-hash": "^1.2.0",
|
|
15
|
-
"create-hmac": ">=1",
|
|
16
15
|
"dns-packet": "^5.2.4",
|
|
17
16
|
"micro-bip39": "^0.1.3",
|
|
18
17
|
"randombytes": ">=2",
|
|
@@ -30,5 +29,9 @@
|
|
|
30
29
|
"censorship",
|
|
31
30
|
"censorship-resistance",
|
|
32
31
|
"client"
|
|
33
|
-
]
|
|
32
|
+
],
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"eslint": "^8.5.0",
|
|
35
|
+
"eslint-plugin-babel": "^5.3.1"
|
|
36
|
+
}
|
|
34
37
|
}
|
package/pool.js
CHANGED
|
@@ -3,7 +3,6 @@ import {relayConnect, normalizeRelayURL} from './relay'
|
|
|
3
3
|
|
|
4
4
|
export function relayPool(globalPrivateKey) {
|
|
5
5
|
const relays = {}
|
|
6
|
-
const globalSub = []
|
|
7
6
|
const noticeCallbacks = []
|
|
8
7
|
|
|
9
8
|
function propagateNotice(notice, relayURL) {
|
|
@@ -28,29 +27,34 @@ export function relayPool(globalPrivateKey) {
|
|
|
28
27
|
const activeCallback = cb
|
|
29
28
|
const activeFilters = filter
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
unsub: () => {
|
|
51
|
-
Object.values(subControllers).forEach(sub => sub.unsub())
|
|
52
|
-
delete activeSubscriptions[id]
|
|
30
|
+
const unsub = () => {
|
|
31
|
+
Object.values(subControllers).forEach(sub => sub.unsub())
|
|
32
|
+
delete activeSubscriptions[id]
|
|
33
|
+
}
|
|
34
|
+
const sub = ({cb = activeCallback, filter = activeFilters}) => {
|
|
35
|
+
Object.entries(subControllers).map(([relayURL, sub]) => [
|
|
36
|
+
relayURL,
|
|
37
|
+
sub.sub({cb, filter}, id)
|
|
38
|
+
])
|
|
39
|
+
return activeSubscriptions[id]
|
|
40
|
+
}
|
|
41
|
+
const addRelay = relay => {
|
|
42
|
+
subControllers[relay.url] = relay.sub({cb, filter}, id)
|
|
43
|
+
return activeSubscriptions[id]
|
|
44
|
+
}
|
|
45
|
+
const removeRelay = relayURL => {
|
|
46
|
+
if (relayURL in subControllers) {
|
|
47
|
+
subControllers[relayURL].unsub()
|
|
48
|
+
if (Object.keys(subControllers).length === 0) unsub()
|
|
53
49
|
}
|
|
50
|
+
return activeSubscriptions[id]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
activeSubscriptions[id] = {
|
|
54
|
+
sub,
|
|
55
|
+
unsub,
|
|
56
|
+
addRelay,
|
|
57
|
+
removeRelay
|
|
54
58
|
}
|
|
55
59
|
|
|
56
60
|
return activeSubscriptions[id]
|
package/relay.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/* global WebSocket */
|
|
2
|
+
|
|
1
3
|
import 'websocket-polyfill'
|
|
2
4
|
|
|
3
5
|
import {verifySignature} from './event'
|
|
@@ -148,7 +150,7 @@ export function relayConnect(url, onNotice) {
|
|
|
148
150
|
try {
|
|
149
151
|
await trySend(['EVENT', event])
|
|
150
152
|
statusCallback(0)
|
|
151
|
-
let {unsub} =
|
|
153
|
+
let {unsub} = sub(
|
|
152
154
|
{
|
|
153
155
|
cb: () => {
|
|
154
156
|
statusCallback(1)
|