@leofcoin/peernet 1.2.30 → 3.0.0

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.
Files changed (120) hide show
  1. package/README.md +13 -0
  2. package/docs/automatic-transport.md +37 -0
  3. package/exports/browser/{browser-DvU1xNFS.js → browser-CCfR9KOM.js} +1 -1
  4. package/exports/browser/{client-86Tnax66.js → client-C_pBoi1g.js} +254 -78
  5. package/exports/browser/{identity-CYVPDmkf.js → identity-Cf8KKnho.js} +511 -391
  6. package/exports/browser/identity.js +1 -1
  7. package/exports/browser/{index-BD0Anx7_.js → index-dTQVgkpf.js} +1 -1
  8. package/exports/browser/{messages-D7JxkkDW.js → messages-BGHaihSi.js} +2 -2
  9. package/exports/browser/{peernet-C4rOvyyU.js → peernet-Db43ag2D.js} +68 -45
  10. package/exports/browser/peernet.js +2 -2
  11. package/exports/store.js +0 -3
  12. package/package.json +10 -6
  13. package/.esdoc.json +0 -10
  14. package/.gitattributes +0 -2
  15. package/.github/workflows/release.yml +0 -34
  16. package/.prettierrc +0 -7
  17. package/.travis.yml +0 -27
  18. package/BREAKING_CHANGES.md +0 -35
  19. package/deploy.js +0 -8
  20. package/exports/browser/browser-D-r0O9Qn.js +0 -53
  21. package/exports/browser/browser-_hiyXwPp.js +0 -147
  22. package/exports/browser/client-BFxJts6j.js +0 -2224
  23. package/exports/browser/client-BVhUamQG.js +0 -2200
  24. package/exports/browser/client-BzvWzzLv.js +0 -2224
  25. package/exports/browser/client-C9GBz2Tf.js +0 -2224
  26. package/exports/browser/client-CQzuu6At.js +0 -2224
  27. package/exports/browser/client-CVkFejdx.js +0 -2224
  28. package/exports/browser/client-Cj_UUO8W.js +0 -2224
  29. package/exports/browser/client-CrGaeBjj.js +0 -2224
  30. package/exports/browser/client-DDC8C510.js +0 -2224
  31. package/exports/browser/client-ERocgKET.js +0 -2224
  32. package/exports/browser/client-a8rws3cu.js +0 -2224
  33. package/exports/browser/identity-ChyyZSve.js +0 -8397
  34. package/exports/browser/index-Bxr5Iztg.js +0 -37
  35. package/exports/browser/messages-BFCmg6Vb.js +0 -212
  36. package/exports/browser/messages-BHIC2mQu.js +0 -212
  37. package/exports/browser/messages-CimzJ4wr.js +0 -210
  38. package/exports/browser/messages-Cjoa_LGO.js +0 -210
  39. package/exports/browser/messages-DH0tgNM9.js +0 -207
  40. package/exports/browser/messages-DVHcNvs_.js +0 -212
  41. package/exports/browser/messages-DqL_g2qw.js +0 -210
  42. package/exports/browser/messages-UKnuelZ7.js +0 -207
  43. package/exports/browser/messages-XgZZUMma.js +0 -212
  44. package/exports/browser/messages-kfFyctPL.js +0 -210
  45. package/exports/browser/messages-psROnfRi.js +0 -212
  46. package/exports/browser/peernet-B9VL4Xwe.js +0 -9522
  47. package/exports/browser/peernet-C-HNdrcd.js +0 -9528
  48. package/exports/browser/peernet-Ca1iM2tN.js +0 -9336
  49. package/exports/browser/peernet-CbI0-jFn.js +0 -9651
  50. package/exports/browser/peernet-CtHScDyh.js +0 -9524
  51. package/exports/browser/peernet-DfuxUK3u.js +0 -9525
  52. package/exports/browser/peernet-DiEcNDLD.js +0 -9655
  53. package/exports/browser/peernet-DtuRXOzP.js +0 -9653
  54. package/exports/browser/peernet-r_9IyzTe.js +0 -9336
  55. package/exports/browser/peernet-rcD5XL1y.js +0 -9590
  56. package/exports/browser/peernet-rw8HJGOz.js +0 -9597
  57. package/exports/messages-CHKVVTVE.js +0 -204
  58. package/exports/messages-DaUtFfBh.js +0 -207
  59. package/index.html +0 -19
  60. package/rollup.config.js +0 -143
  61. package/src/dht/dht.ts +0 -142
  62. package/src/discovery/peer-discovery.js +0 -75
  63. package/src/errors/errors.js +0 -12
  64. package/src/file-transfer.ts +0 -194
  65. package/src/handlers/data.js +0 -15
  66. package/src/handlers/message.js +0 -34
  67. package/src/identity.ts +0 -172
  68. package/src/messages/chat.ts +0 -13
  69. package/src/messages/data-response.ts +0 -13
  70. package/src/messages/data.ts +0 -17
  71. package/src/messages/dht-response.ts +0 -13
  72. package/src/messages/dht.ts +0 -21
  73. package/src/messages/file-link.ts +0 -17
  74. package/src/messages/file.ts +0 -17
  75. package/src/messages/peer-response.ts +0 -13
  76. package/src/messages/peer.ts +0 -13
  77. package/src/messages/peernet.ts +0 -13
  78. package/src/messages/ps.ts +0 -13
  79. package/src/messages/request.ts +0 -13
  80. package/src/messages/response.ts +0 -13
  81. package/src/messages.js +0 -12
  82. package/src/peer-info.js +0 -9
  83. package/src/peernet.ts +0 -1113
  84. package/src/prompts/password/browser.js +0 -1
  85. package/src/prompts/password/node.js +0 -6
  86. package/src/prompts/password.js +0 -1
  87. package/src/proto/chat-message.proto.js +0 -6
  88. package/src/proto/data-response.proto.js +0 -4
  89. package/src/proto/data.proto.js +0 -4
  90. package/src/proto/dht-response.proto.js +0 -4
  91. package/src/proto/dht.proto.js +0 -4
  92. package/src/proto/file-link.proto.js +0 -5
  93. package/src/proto/file.proto.js +0 -10
  94. package/src/proto/peer-response.proto.js +0 -3
  95. package/src/proto/peer.proto.js +0 -3
  96. package/src/proto/peernet.proto.js +0 -7
  97. package/src/proto/ps.proto.js +0 -4
  98. package/src/proto/request.proto.js +0 -4
  99. package/src/proto/response.proto.js +0 -3
  100. package/src/types.ts +0 -25
  101. package/src/utils/utils.js +0 -77
  102. package/test/all.js +0 -5
  103. package/test/client.js +0 -15
  104. package/test/codec.js +0 -56
  105. package/test/file-transfer.test.js +0 -81
  106. package/test/fresh-empty-store.js +0 -15
  107. package/test/hash.js +0 -14
  108. package/test/index.js +0 -6
  109. package/test/lastBlock.js +0 -7
  110. package/test/messages.js +0 -26
  111. package/test/peer-data-exchange.test.js +0 -52
  112. package/test/peer-file-exchange.test.js +0 -78
  113. package/test/peernet.js +0 -17
  114. package/test/peernet.test.js +0 -440
  115. package/test-output.log +0 -84
  116. package/test.js +0 -63
  117. package/test2.js +0 -13
  118. package/test3.js +0 -16
  119. package/test4.js +0 -7
  120. package/tsconfig.json +0 -13
@@ -1,440 +0,0 @@
1
- import test from 'node:test'
2
- import assert from 'node:assert/strict'
3
- import { readFile } from 'node:fs/promises'
4
- import { execFile } from 'node:child_process'
5
- import { mkdtemp, rm } from 'node:fs/promises'
6
- import { tmpdir } from 'node:os'
7
- import { join } from 'node:path'
8
- import { promisify } from 'node:util'
9
-
10
- import Peernet from '../exports/peernet.js'
11
- import Identity, { resolveAccountWallets } from '../exports/identity.js'
12
- import MultiWallet from '@leofcoin/multi-wallet'
13
- import { fromBase58, toBase58 } from '@vandeurenglenn/typed-array-utils'
14
-
15
- const options = {
16
- network: 'leofcoin:peach',
17
- stars: [],
18
- root: `.testnet-${process.pid}`,
19
- version: '1.0.0',
20
- storePrefix: 'test',
21
- autoStart: false
22
- }
23
-
24
- const password = 'password'
25
- const peernet = await new Peernet(options, password)
26
- const execFileAsync = promisify(execFile)
27
-
28
- test('freshIdentity initializes against a completely empty store root', async () => {
29
- const root = await mkdtemp(join(tmpdir(), 'peernet-fresh-identity-'))
30
- try {
31
- const { stdout } = await execFileAsync(process.execPath, ['test/fresh-empty-store.js', root], {
32
- cwd: new URL('..', import.meta.url),
33
- timeout: 20_000
34
- })
35
- assert.match(stdout, /FRESH_IDENTITY_READY/)
36
- } finally {
37
- await rm(root, { recursive: true, force: true })
38
- }
39
- })
40
-
41
- test('node bundle uses a portable password prompt import', async () => {
42
- const identityBundle = await readFile(new URL('../exports/identity.js', import.meta.url), 'utf8')
43
- assert.match(identityBundle, /import\(['"]\.\/prompts\/password\.js['"]\)/)
44
- assert.doesNotMatch(identityBundle, /(?:\/home\/|\/Users\/|[A-Za-z]:\\)/)
45
- })
46
-
47
- test('initializes with provided options', () => {
48
- assert.equal(peernet.network, options.network)
49
- assert.equal(peernet.version, options.version)
50
- assert.equal(peernet.storePrefix, options.storePrefix)
51
- })
52
-
53
- test('exposes identity instance', () => {
54
- assert.ok(peernet.identity instanceof Identity)
55
- })
56
-
57
- test('freshIdentity replaces a persisted identity and signer', async () => {
58
- const originalId = peernet.id
59
- const originalAccount = peernet.selectedAccount
60
- const replacement = await new Peernet({ ...options, freshIdentity: true }, password)
61
-
62
- assert.notEqual(replacement.id, originalId)
63
- assert.notEqual(replacement.selectedAccount, originalAccount)
64
- assert.equal(new TextDecoder().decode(await globalThis.walletStore.get('selected-account')), replacement.selectedAccount)
65
- })
66
-
67
- test('has a DHT instance', () => {
68
- assert.ok(peernet.dht)
69
- })
70
-
71
- test('returns peers and connections safely', () => {
72
- assert.deepEqual(peernet.peers, [])
73
- assert.deepEqual(peernet.connections, {})
74
- assert.equal(peernet.getConnection('missing'), undefined)
75
- })
76
-
77
- test('provides callable helpers', () => {
78
- assert.equal(typeof peernet.addProto, 'function')
79
- assert.equal(typeof peernet.addCodec, 'function')
80
- assert.equal(typeof peernet.prepareMessage, 'function')
81
- assert.equal(typeof peernet.publish, 'function')
82
- assert.equal(typeof peernet.subscribe, 'function')
83
- })
84
-
85
- test('pubsub subscribe registers callback', async () => {
86
- const topic = 'test-topic'
87
- let callbackCalled = false
88
-
89
- const callback = () => {
90
- callbackCalled = true
91
- }
92
-
93
- // Subscribe to topic
94
- await peernet.subscribe(topic, callback)
95
-
96
- // Manually publish to globalSub to test subscription registration
97
- globalThis.globalSub.publish(topic, 'test-data')
98
-
99
- // Give async operation a moment to process
100
- await new Promise((resolve) => setTimeout(resolve, 10))
101
-
102
- assert.ok(callbackCalled)
103
- })
104
-
105
- test('addProto registers protocol', () => {
106
- const protoName = 'test-protocol'
107
- const protoObject = { test: 'data' }
108
-
109
- peernet.addProto(protoName, protoObject)
110
-
111
- assert.equal(globalThis.peernet.protos[protoName], protoObject)
112
- })
113
-
114
- test('addProto does not overwrite existing protocol', () => {
115
- const protoName = 'existing-proto'
116
- const originalProto = { original: true }
117
- const newProto = { new: true }
118
-
119
- peernet.addProto(protoName, originalProto)
120
- const firstRegistered = globalThis.peernet.protos[protoName]
121
-
122
- peernet.addProto(protoName, newProto)
123
- const afterSecondAdd = globalThis.peernet.protos[protoName]
124
-
125
- assert.equal(firstRegistered, originalProto)
126
- assert.equal(afterSecondAdd, originalProto)
127
- })
128
-
129
- test('addCodec is callable', () => {
130
- const mockCodec = { name: 'test-codec' }
131
- // addCodec may return undefined, just verify it doesn't throw
132
- assert.equal(typeof peernet.addCodec, 'function')
133
- peernet.addCodec(mockCodec)
134
- })
135
-
136
- test('selectAccount delegates to identity', () => {
137
- const accountName = 'test-account'
138
- // selectAccount may return undefined, just verify it doesn't throw
139
- assert.equal(typeof peernet.selectAccount, 'function')
140
- })
141
-
142
- test('identity has loaded account data', () => {
143
- assert.ok(peernet.identity.accounts !== undefined)
144
- assert.ok(peernet.identity.selectedAccount !== undefined)
145
- })
146
-
147
- test('peerId matches identity id', () => {
148
- assert.equal(peernet.peerId, peernet.identity.id)
149
- assert.equal(peernet.id, peernet.identity.id)
150
- })
151
-
152
- test('data store operations', () => {
153
- const hash = 'test-hash-123'
154
- const testData = new Uint8Array([1, 2, 3, 4, 5])
155
-
156
- // Test put operation - may hang, so just verify method exists
157
- assert.equal(typeof peernet.put, 'function')
158
-
159
- // Test has operation - verify method exists
160
- assert.equal(typeof peernet.has, 'function')
161
- })
162
-
163
- test('get attempts to retrieve from store', async () => {
164
- const hash = 'nonexistent-hash'
165
- // Just verify method exists
166
- assert.equal(typeof peernet.get, 'function')
167
- })
168
-
169
- test('message object provides get/put/has', () => {
170
- const messageObj = peernet.message
171
- assert.equal(typeof messageObj.get, 'function')
172
- assert.equal(typeof messageObj.put, 'function')
173
- assert.equal(typeof messageObj.has, 'function')
174
- })
175
-
176
- test('data object provides get/put/has', () => {
177
- const dataObj = peernet.data
178
- assert.equal(typeof dataObj.get, 'function')
179
- assert.equal(typeof dataObj.put, 'function')
180
- assert.equal(typeof dataObj.has, 'function')
181
- })
182
-
183
- test('block object provides get/put/has', () => {
184
- const blockObj = peernet.block
185
- assert.equal(typeof blockObj.get, 'function')
186
- assert.equal(typeof blockObj.put, 'function')
187
- assert.equal(typeof blockObj.has, 'function')
188
- })
189
-
190
- test('large blocks are chunked internally and reconstructed transparently', async () => {
191
- const previousThreshold = peernet.blockChunkThreshold
192
- const previousChunkSize = peernet.blockChunkSize
193
- peernet.blockChunkThreshold = 512
194
- peernet.blockChunkSize = 256
195
- try {
196
- const hash = `chunked-block-${Date.now()}`
197
- const block = new Uint8Array(1537)
198
- for (let index = 0; index < block.length; index++) block[index] = index % 251
199
-
200
- await peernet.block.put(hash, block)
201
- const stored = await globalThis.blockStore.get(hash)
202
- const manifest = new peernet.protos['peernet-file'](stored)
203
- await manifest.decode()
204
-
205
- assert.equal(manifest.decoded.kind, 'block')
206
- assert.equal(manifest.decoded.blockHash, hash)
207
- assert.equal(manifest.decoded.links.length, 7)
208
- assert.deepEqual(await peernet.block.get(hash), block)
209
- } finally {
210
- peernet.blockChunkThreshold = previousThreshold
211
- peernet.blockChunkSize = previousChunkSize
212
- }
213
- })
214
-
215
- test('transaction object provides get/put/has', () => {
216
- const txObj = peernet.transaction
217
- assert.equal(typeof txObj.get, 'function')
218
- assert.equal(typeof txObj.put, 'function')
219
- assert.equal(typeof txObj.has, 'function')
220
- })
221
-
222
- test('folder object provides get/put/has', () => {
223
- const folderObj = peernet.folder
224
- assert.equal(typeof folderObj.get, 'function')
225
- assert.equal(typeof folderObj.put, 'function')
226
- assert.equal(typeof folderObj.has, 'function')
227
- })
228
-
229
- test('Buffer property is available', () => {
230
- assert.ok(peernet.Buffer)
231
- assert.equal(peernet.Buffer, Buffer)
232
- })
233
-
234
- test('handleData is callable', () => {
235
- assert.equal(typeof peernet.handleData, 'function')
236
- })
237
-
238
- test('handleDHT is callable', () => {
239
- assert.equal(typeof peernet.handleDHT, 'function')
240
- })
241
-
242
- test('handleRequest is callable', () => {
243
- assert.equal(typeof peernet.handleRequest, 'function')
244
- })
245
-
246
- test('walk is callable', () => {
247
- assert.equal(typeof peernet.walk, 'function')
248
- })
249
-
250
- test('providersFor is callable', () => {
251
- assert.equal(typeof peernet.providersFor, 'function')
252
- })
253
-
254
- test('addRequestHandler is callable', () => {
255
- assert.equal(typeof peernet.addRequestHandler, 'function')
256
- })
257
-
258
- test('sendMessage is callable', () => {
259
- assert.equal(typeof peernet.sendMessage, 'function')
260
- })
261
-
262
- test('start method exists', () => {
263
- // Just verify method exists and is callable
264
- assert.equal(typeof peernet.start, 'function')
265
- })
266
-
267
- test('default stores are initialized', () => {
268
- const defaultStores = peernet.defaultStores
269
- assert.ok(Array.isArray(defaultStores))
270
- assert.ok(defaultStores.includes('account'))
271
- assert.ok(defaultStores.includes('wallet'))
272
- assert.ok(defaultStores.includes('block'))
273
- assert.ok(defaultStores.includes('transaction'))
274
- assert.ok(defaultStores.includes('chain'))
275
- assert.ok(defaultStores.includes('data'))
276
- assert.ok(defaultStores.includes('message'))
277
- assert.ok(defaultStores.includes('share'))
278
- })
279
-
280
- test('identity has all expected methods', () => {
281
- assert.equal(typeof peernet.identity.sign, 'function')
282
- assert.equal(typeof peernet.identity.export, 'function')
283
- assert.equal(typeof peernet.identity.import, 'function')
284
- assert.equal(typeof peernet.identity.lock, 'function')
285
- assert.equal(typeof peernet.identity.unlock, 'function')
286
- assert.equal(typeof peernet.identity.getAccounts, 'function')
287
- })
288
-
289
- test('identity wallet is loaded', () => {
290
- assert.ok(peernet.identity.id)
291
- assert.ok(typeof peernet.identity.id === 'string')
292
- assert.ok(peernet.identity.id.length > 0)
293
- })
294
-
295
- test('selected account is set', () => {
296
- assert.ok(peernet.identity.selectedAccount)
297
- assert.ok(typeof peernet.identity.selectedAccount === 'string')
298
- })
299
-
300
- test('identity signatures authenticate the selected account', async () => {
301
- const payload = new Uint8Array(32).fill(7)
302
- const signature = toBase58(await peernet.identity.sign(payload))
303
- const verifier = new MultiWallet(peernet.network)
304
- await verifier.fromAddress(peernet.selectedAccount, null, peernet.network)
305
- assert.equal(await verifier.verify(fromBase58(signature), payload), true)
306
- })
307
-
308
- test('legacy account(0)/address(0) identities keep their original signer', async () => {
309
- const wallet = new MultiWallet(peernet.network)
310
- await wallet.generate()
311
- const legacyAccount = wallet.account(0)
312
- const external = await legacyAccount.external(0)
313
- const internal = await legacyAccount.internal(0)
314
- const externalAddress = await external.address
315
- const wallets = await resolveAccountWallets(wallet, [
316
- ['legacy account', externalAddress, await internal.address]
317
- ])
318
- const payload = new Uint8Array(32).fill(9)
319
- const signature = toBase58(await wallets.get(externalAddress).sign(payload))
320
- const verifier = new MultiWallet(peernet.network)
321
- await verifier.fromAddress(externalAddress, null, peernet.network)
322
- assert.equal(await verifier.verify(fromBase58(signature), payload), true)
323
- })
324
-
325
- test('error handling methods exist', () => {
326
- assert.equal(typeof peernet.handleDHT, 'function')
327
- assert.equal(typeof peernet.handleData, 'function')
328
- assert.equal(typeof peernet.handleRequest, 'function')
329
- })
330
-
331
- test('in-memory broadcast and handleData returns correct data', async () => {
332
- // Broadcast a valid file object with path
333
- const testString = 'hello in-memory world'
334
- const path = '/test'
335
- const content = new TextEncoder().encode(testString)
336
-
337
- const hash = await peernet.broadcast(path, { content })
338
-
339
- // Prepare a mock peer and capture sendMessage output
340
- let sentNode = null
341
- const mockPeer = {
342
- connected: true,
343
- send: async (data, id) => {
344
- sentNode = { data, id }
345
- return Promise.resolve()
346
- }
347
- }
348
- const proto = {
349
- decoded: { hash }
350
- }
351
- await peernet.handleData(mockPeer, 'test-id', proto)
352
-
353
- assert.ok(sentNode)
354
- const DataResponseProto = globalThis.peernet.protos['peernet-data-response']
355
- const decodedProto = await new DataResponseProto(sentNode.data)
356
- await decodedProto.decode()
357
- const FileProto = globalThis.peernet.protos['peernet-file']
358
- const decodedFile = new FileProto(decodedProto.decoded.data)
359
- await decodedFile.decode()
360
- const decodedContent = new TextDecoder().decode(decodedFile.decoded.content)
361
- assert.equal(decodedProto.decoded.hash, hash)
362
- assert.equal(decodedContent, testString)
363
- })
364
-
365
- test('in-memory broadcast and handleData supports large binary data', async () => {
366
- // Create a large binary buffer (e.g., 1MB)
367
- const size = 1024 * 1024 // 1MB
368
- const largeBuffer = new Uint8Array(size)
369
- for (let i = 0; i < size; i++) largeBuffer[i] = i % 256
370
- const path = '/large-binary'
371
- const content = largeBuffer
372
- const hash = await peernet.broadcast(path, { content })
373
-
374
- // Prepare a mock peer and capture sendMessage output
375
- let sentNode = null
376
- const mockPeer = {
377
- connected: true,
378
- send: async (data, id) => {
379
- sentNode = { data, id }
380
- return Promise.resolve()
381
- }
382
- }
383
- const proto = {
384
- decoded: { hash }
385
- }
386
- await peernet.handleData(mockPeer, 'test-id', proto)
387
-
388
- assert.ok(sentNode)
389
- const DataResponseProto = globalThis.peernet.protos['peernet-data-response']
390
- const decodedProto = await new DataResponseProto(sentNode.data)
391
- await decodedProto.decode()
392
- assert.equal(decodedProto.decoded.hash, hash)
393
- const transfer = peernet.download(hash)
394
- const receivedBuffer = Buffer.from(await transfer.result)
395
- const originalBuffer = Buffer.from(largeBuffer)
396
- assert.equal(Buffer.compare(receivedBuffer, originalBuffer), 0)
397
- })
398
-
399
- test('share object provides get/put/has', () => {
400
- const shareObj = peernet.share
401
- assert.equal(typeof shareObj.get, 'function')
402
- assert.equal(typeof shareObj.put, 'function')
403
- assert.equal(typeof shareObj.has, 'function')
404
- })
405
-
406
- test('allSharedHashes method exists and is callable', () => {
407
- assert.equal(typeof peernet.allSharedHashes, 'function')
408
- })
409
-
410
- test('broadcast persists to share store', async () => {
411
- const testString = 'test broadcast content'
412
- const path = '/broadcast-test'
413
- const content = new TextEncoder().encode(testString)
414
-
415
- const hash = await peernet.broadcast(path, { content })
416
-
417
- // Verify it was stored in share store
418
- assert.ok(hash)
419
- const hasInShare = await peernet.share.has(hash)
420
- assert.equal(hasInShare, true)
421
- })
422
-
423
- test('share store can retrieve broadcasted content', async () => {
424
- const testString = 'retrievable broadcast content'
425
- const path = '/retrievable-test'
426
- const content = new TextEncoder().encode(testString)
427
-
428
- const hash = await peernet.broadcast(path, { content })
429
-
430
- // Verify we can retrieve it from share store
431
- const storedData = await peernet.share.get(hash)
432
- assert.ok(storedData)
433
- })
434
-
435
- test('allSharedHashes returns array of hashes', async () => {
436
- const hashes = await peernet.allSharedHashes()
437
- assert.ok(Array.isArray(hashes))
438
- // Should contain at least the hashes we broadcasted in previous tests
439
- assert.ok(hashes.length >= 0)
440
- })
package/test-output.log DELETED
@@ -1,84 +0,0 @@
1
- ✔ initializes with provided options (0.407125ms)
2
- ✔ exposes identity instance (0.051667ms)
3
- ✔ has a DHT instance (0.04425ms)
4
- ✔ returns peers and connections safely (0.267542ms)
5
- ✔ provides callable helpers (0.048958ms)
6
- ✔ pubsub subscribe registers callback (10.395584ms)
7
- ✔ addProto registers protocol (0.160417ms)
8
- ✔ addProto does not overwrite existing protocol (0.057709ms)
9
- ✔ addCodec is callable (0.063084ms)
10
- ✔ selectAccount delegates to identity (0.068584ms)
11
- ✔ identity has loaded account data (0.241875ms)
12
- ✔ peerId matches identity id (0.031375ms)
13
- ✔ data store operations (0.030125ms)
14
- ✔ get attempts to retrieve from store (0.035667ms)
15
- ✔ message object provides get/put/has (0.053917ms)
16
- ✔ data object provides get/put/has (0.045833ms)
17
- ✔ block object provides get/put/has (0.067375ms)
18
- ✔ transaction object provides get/put/has (0.042333ms)
19
- ✔ folder object provides get/put/has (0.034167ms)
20
- ✔ Buffer property is available (0.024417ms)
21
- ✔ handleData is callable (0.017709ms)
22
- ✔ handleDHT is callable (0.016167ms)
23
- ✔ handleRequest is callable (0.016417ms)
24
- ✔ walk is callable (0.015459ms)
25
- ✔ providersFor is callable (0.015583ms)
26
- ✔ addRequestHandler is callable (0.015375ms)
27
- ✔ sendMessage is callable (0.01625ms)
28
- ✔ start method exists (0.02675ms)
29
- ✔ default stores are initialized (0.0275ms)
30
- ✔ identity has all expected methods (0.020084ms)
31
- ✔ identity wallet is loaded (0.019333ms)
32
- ✔ selected account is set (0.016208ms)
33
- ✔ error handling methods exist (0.017083ms)
34
- DEBUG_HANDLE_DATA: entering in-memory branch { hash: 'BA43QACTNQLBH6SW7NO7ZQ63I3USRUBTD5DOWLEUFJGMY6JN2BSUAES54X' }
35
- DEBUG_HANDLE_DATA: got from _inMemoryBroadcasts {
36
- type: 'object',
37
- isUint8Array: true,
38
- length: 34,
39
- slice: [
40
- 230, 224, 1, 5, 47,
41
- 116, 101, 115, 116, 21,
42
- 104, 101, 108, 108, 111,
43
- 32
44
- ]
45
- }
46
- ✔ in-memory broadcast and handleData returns correct data (4.52275ms)
47
- DEBUG_HANDLE_DATA: entering in-memory branch { hash: 'BA43QACYLVOY2HRRGV4NOUDQ3GWPQ7YZVBBM5DOKGZIY4UOYMS3K3JSCVV' }
48
- DEBUG_HANDLE_DATA: got from _inMemoryBroadcasts {
49
- type: 'object',
50
- isUint8Array: true,
51
- length: 1048599,
52
- slice: [
53
- 230, 224, 1, 13, 47, 108,
54
- 97, 114, 103, 101, 45, 98,
55
- 105, 110, 97, 114
56
- ]
57
- }
58
- DEBUG_TEST receivedBuffer {
59
- type: 'object',
60
- isUint8Array: true,
61
- length: 1048576,
62
- slice: [
63
- 0, 1, 2, 3, 4, 5,
64
- 6, 7, 8, 9, 10, 11,
65
- 12, 13, 14, 15
66
- ]
67
- }
68
- DEBUG_TEST originalBuffer {
69
- length: 1048576,
70
- slice: [
71
- 0, 1, 2, 3, 4, 5,
72
- 6, 7, 8, 9, 10, 11,
73
- 12, 13, 14, 15
74
- ]
75
- }
76
- ✔ in-memory broadcast and handleData supports large binary data (163.195292ms)
77
- ℹ tests 35
78
- ℹ suites 0
79
- ℹ pass 35
80
- ℹ fail 0
81
- ℹ cancelled 0
82
- ℹ skipped 0
83
- ℹ todo 0
84
- ℹ duration_ms 366.132458
package/test.js DELETED
@@ -1,63 +0,0 @@
1
- import Client from './exports/peernet.js'
2
-
3
- const client = await new Client({
4
- network: 'leofcoin:peach',
5
- networkVersion: 'peach',
6
- stars: ['wss://star.leofcoin.org'],
7
- version: '0.1.0'
8
- })
9
- console.log(pubsub.subscribers)
10
- pubsub.subscribe('peer:discovered', (data) => {
11
- // console.log(data);
12
- console.log(`discovered: ${Object.keys(peernet.client.discovered).length}`)
13
- console.log(Object.keys(peernet.client.discovered))
14
- })
15
- pubsub.subscribe('peer:connected', (data) => {
16
- // console.log(data);
17
- console.log(`connections: ${peernet.connections.length}`)
18
- })
19
- pubsub.subscribe('peer:left', (data) => {
20
- console.log(`connections: ${peernet.connections.length}`)
21
- console.log(`discovered: ${Object.keys(peernet.client.discovered).length}`)
22
- // console.log(data);
23
- })
24
-
25
- // peernet.addFolder([{
26
- // path: 'assets/asset.png',
27
- // content: Buffer.from('png')
28
- // }, {
29
- // path: 'index.html',
30
- // content: Buffer.from('html')
31
- // }]).then(hash => peernet.ls(hash).then(paths => peernet.cat(paths[0].hash).then(content => console.log(content))))
32
-
33
- // pubsub.subscribe('peer:connected', async peer => {
34
- // chainStore.put('localBlock', '00000')
35
- // const request = await new globalThis.peernet.protos['peernet-request']({
36
- // request:'lastBlock'
37
- // })
38
- // const to = peer.id
39
- // await peernet.data.put('hello', 'hi')
40
- // console.log({request});
41
- // const node = await peernet.prepareMessage(request)
42
- // console.log({node});
43
- // let response = await peer.request(node.encoded)
44
- // console.log({response});
45
- // const keys = Object.keys(response)
46
- // const uint8Array = new Uint8Array(keys.length)
47
- // for (const key of keys) {
48
- // uint8Array[Number(key)] = response[key]
49
- // }
50
- // // const proto = await new globalThis.peernet.protos['peernet-message'](uint8Array)
51
- // // console.log(proto.decoded.data);
52
- // response = await new globalThis.peernet.protos['peernet-response'](uint8Array)
53
- // console.log({response});
54
-
55
- // const block = new TextDecoder().decode(response.decoded.response)
56
- // console.log(block);
57
- // const task = () => setTimeout(() => {
58
- // console.log(peernet.connections[0]?.connected);
59
- // console.log(pubsub.subscribers);
60
- // task()
61
- // }, 5000);
62
- // task()
63
- // })
package/test2.js DELETED
@@ -1,13 +0,0 @@
1
- import Client from './exports/peernet.js'
2
- ;(async () => {
3
- const client = await new Client({
4
- root: '.peernet/test2',
5
- network: 'peach',
6
- networkVersion: 'peach',
7
- stars: [['wss://star.leofcoin.org']]
8
- })
9
- const job = () => client.publish('socket-data', 'hello')
10
- setTimeout(async () => {
11
- job()
12
- }, 10000)
13
- })()
package/test3.js DELETED
@@ -1,16 +0,0 @@
1
- const Client = require('./dist/commonjs/peernet.js')
2
- const PeernetMessage = require('./dist/messages/peernet.js');
3
- const DHTMessage = require('./dist/messages/dht.js');
4
-
5
- globalThis.DEBUG = true;
6
- const client = new Client({root: '.peernet/test3'})
7
-
8
- pubsub.subscribe('peer:connected', async peer => setInterval(async () => {
9
- // const dhtMessage = new DHTMessage({hash: 'hello'})
10
- // console.log(dhtMessage.encoded);
11
- // const message = new PeernetMessage({ from: client.id, to: peer.id, data: dhtMessage.encoded, signature: Buffer.from('pnsig') })
12
- // console.log(message.encoded);
13
- // console.log(await peer.request(message.encoded));
14
- const data = await client.get('hello')
15
- console.log(data.toString())
16
- }, 5000))
package/test4.js DELETED
@@ -1,7 +0,0 @@
1
- const Client = require('./dist/commonjs/peernet.js')
2
-
3
- const client = new Client({root: '.peernet/test4'})
4
-
5
- pubsub.subscribe('peer:connected', async peer => {
6
- await peernet.get("ba5xcadcnub27naa7zrcvtmyruviahaiwvupatfgjkvdgcehuif7clissf")
7
- })
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "module": "NodeNext",
4
- "target": "ESNext",
5
- "declaration": true,
6
- "outDir": "./exports",
7
- "rootDir": "./src",
8
- "moduleResolution": "NodeNext",
9
- "allowJs": true,
10
- "skipLibCheck": true
11
- },
12
- "include": ["./src/**/*"]
13
- }