libp2r2p 0.0.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/AGENTS.md +20 -0
- package/README.md +129 -0
- package/base16/index.js +14 -0
- package/base64/index.js +29 -0
- package/content-key/event/index.js +85 -0
- package/content-key/index.js +1 -0
- package/content-key/services/iykc-proof.js +129 -0
- package/double-dh/index.js +166 -0
- package/ecdh/index.js +8 -0
- package/idb/index.js +64 -0
- package/idb-queue/index.js +793 -0
- package/index.js +21 -0
- package/key/index.js +139 -0
- package/network/index.js +68 -0
- package/nip44-v3/index.js +175 -0
- package/nip46/constants/index.js +5 -0
- package/nip46/helpers/frame.js +51 -0
- package/nip46/helpers/url.js +96 -0
- package/nip46/index.js +5 -0
- package/nip46/services/bunker-signer.js +49 -0
- package/nip46/services/client.js +252 -0
- package/nip46/services/server-session.js +225 -0
- package/nip46/services/transport.js +265 -0
- package/package.json +49 -0
- package/private-channel/constants/index.js +5 -0
- package/private-channel/helpers/chunk-size.js +61 -0
- package/private-channel/helpers/chunks.js +282 -0
- package/private-channel/helpers/event.js +68 -0
- package/private-channel/index.js +942 -0
- package/private-channel/services/received-chunks.js +398 -0
- package/private-message/index.js +672 -0
- package/private-messenger/constants/index.js +1 -0
- package/private-messenger/index.js +1431 -0
- package/private-messenger/recovery/index.js +316 -0
- package/relay/constants/index.js +18 -0
- package/relay/helpers/hll.js +62 -0
- package/relay/helpers/publish.js +100 -0
- package/relay/helpers/routing.js +36 -0
- package/relay/helpers/timer.js +4 -0
- package/relay/index.js +4 -0
- package/relay/services/query.js +224 -0
- package/relay/services/relay-connection.js +156 -0
- package/relay/services/relay-pool.js +908 -0
- package/temporary-storage/index.js +85 -0
- package/tests/base16.test.js +19 -0
- package/tests/base64.test.js +18 -0
- package/tests/content-key-event.test.js +48 -0
- package/tests/fixtures/nip44v3-vectors.json +1 -0
- package/tests/helpers/test-signer.js +185 -0
- package/tests/idb-queue.test.js +153 -0
- package/tests/idb.test.js +91 -0
- package/tests/nip44-v3.test.js +73 -0
- package/tests/nip46.test.js +668 -0
- package/tests/private-channel.test.js +1899 -0
- package/tests/private-message.test.js +460 -0
- package/tests/private-messenger.test.js +1715 -0
- package/tests/queries.test.js +101 -0
- package/tests/queue-parity.test.js +105 -0
- package/tests/relay-hll.test.js +32 -0
- package/tests/relay-pool.test.js +2067 -0
- package/tests/temporary-storage.test.js +89 -0
- package/tests/web-storage-queue.test.js +480 -0
- package/web-storage-queue/index.js +652 -0
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { NYM_CARRIER_KIND, ROUTER_KIND } from '../constants/index.js'
|
|
2
|
+
|
|
3
|
+
const encoder = new TextEncoder()
|
|
4
|
+
|
|
5
|
+
export function nowSeconds () {
|
|
6
|
+
return Math.floor(Date.now() / 1000)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function eventByteLength (event) {
|
|
10
|
+
return encoder.encode(JSON.stringify(event)).length
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function readReceiverTag (event) {
|
|
14
|
+
return event.tags?.find(t => t[0] === 'r')?.[1] || ''
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function readSenderTag (event) {
|
|
18
|
+
const senderPubkey = event.tags?.find(t => t[0] === 'f')?.[1]
|
|
19
|
+
if (!senderPubkey) throw new Error('MISSING_SENDER_TAG')
|
|
20
|
+
return senderPubkey
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function readImkcTag (event) {
|
|
24
|
+
return event.tags?.find(t => t[0] === 'imkc')?.[1] || ''
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function hasImkcTag (event) {
|
|
28
|
+
return event.tags?.some(t => t[0] === 'imkc') || false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function readImkcProof (event) {
|
|
32
|
+
return event.tags?.find(t => t[0] === 'imkc')?.[2] || ''
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function readIdTag (event) {
|
|
36
|
+
return event.tags?.find(t => t[0] === 'id')?.[1] || ''
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function readChunkTag (event) {
|
|
40
|
+
const tag = event.tags?.find(t => t[0] === 'c')
|
|
41
|
+
const index = Number(tag?.[1])
|
|
42
|
+
const total = Number(tag?.[2])
|
|
43
|
+
if (!Number.isInteger(index) || !Number.isInteger(total) || index < 0 || total < 1) {
|
|
44
|
+
throw new Error('INVALID_CHUNK_TAG')
|
|
45
|
+
}
|
|
46
|
+
return { index, total }
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function makeRouterEvent ({ pubkey, senderPubkey, imkcPubkey, imkcProof, receiverPubkey, chunkIndex, chunkTotal, content }) {
|
|
50
|
+
const tags = [['f', senderPubkey]]
|
|
51
|
+
if (imkcPubkey) {
|
|
52
|
+
if (!imkcProof) throw new Error('INVALID_IMKC_PROOF')
|
|
53
|
+
tags.push(['imkc', imkcPubkey, imkcProof])
|
|
54
|
+
}
|
|
55
|
+
tags.push(['c', String(chunkIndex), String(chunkTotal)])
|
|
56
|
+
if (receiverPubkey) tags.push(['r', receiverPubkey])
|
|
57
|
+
return { kind: ROUTER_KIND, pubkey, created_at: nowSeconds(), tags, content }
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function makeNymCarrierEvent ({ innerId, chunkIndex, chunkTotal, content, createdAt = nowSeconds() }) {
|
|
61
|
+
if (!innerId) throw new Error('INNER_EVENT_ID_REQUIRED')
|
|
62
|
+
return {
|
|
63
|
+
kind: NYM_CARRIER_KIND,
|
|
64
|
+
created_at: createdAt,
|
|
65
|
+
tags: [['id', innerId], ['c', String(chunkIndex), String(chunkTotal)]],
|
|
66
|
+
content
|
|
67
|
+
}
|
|
68
|
+
}
|