@leofcoin/peernet 1.2.12 → 1.2.14

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.
@@ -1,4 +1,4 @@
1
- import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-BpKdfmda.js';
1
+ import { L as LittlePubSub, d as deflate_1, i as inflate_1, c as createDebugger } from './peernet-Bl3tF9yA.js';
2
2
  import './identity-CqSnKXWH.js';
3
3
  import './value-C3vAp-wb.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { F as FormatInterface } from './peernet-BpKdfmda.js';
1
+ import { F as FormatInterface } from './peernet-Bl3tF9yA.js';
2
2
  import './identity-CqSnKXWH.js';
3
3
  import './value-C3vAp-wb.js';
4
4
 
@@ -123,7 +123,7 @@ class RequestMessage extends FormatInterface {
123
123
  }
124
124
 
125
125
  var proto$4 = {
126
- response: {}
126
+ response: new Uint8Array()
127
127
  };
128
128
 
129
129
  class ResponseMessage extends FormatInterface {
@@ -166,10 +166,10 @@ class DataMessageResponse extends FormatInterface {
166
166
  }
167
167
 
168
168
  var proto$1 = {
169
- value: String(),
170
- author: String(),
169
+ value: new Uint8Array(),
170
+ author: new Uint8Array(),
171
171
  timestamp: Number(),
172
- files: [String()]
172
+ files: [new Uint8Array()]
173
173
  };
174
174
 
175
175
  class ChatMessage extends FormatInterface {
@@ -8473,7 +8473,7 @@ class Peernet {
8473
8473
  await getAddress();
8474
8474
  this.storePrefix = options.storePrefix;
8475
8475
  this.root = options.root;
8476
- const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-C-BwUsHC.js');
8476
+ const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-oCxYLnpB.js');
8477
8477
  /**
8478
8478
  * proto Object containing protos
8479
8479
  * @type {Object}
@@ -8520,7 +8520,7 @@ class Peernet {
8520
8520
  if (this.#starting || this.#started)
8521
8521
  return;
8522
8522
  this.#starting = true;
8523
- const importee = await import('./client-DN_Y7L6h.js');
8523
+ const importee = await import('./client-CXjaAk7-.js');
8524
8524
  /**
8525
8525
  * @access public
8526
8526
  * @type {PeernetClient}
@@ -8990,7 +8990,7 @@ class Peernet {
8990
8990
  const links = [];
8991
8991
  for (const file of files) {
8992
8992
  const fileNode = await new globalThis.peernet.protos['peernet-file'](file);
8993
- const hash = await fileNode.hash;
8993
+ const hash = await fileNode.hash();
8994
8994
  await dataStore.put(hash, fileNode.encoded);
8995
8995
  links.push({ hash, path: file.path });
8996
8996
  }
@@ -8998,7 +8998,7 @@ class Peernet {
8998
8998
  path: '/',
8999
8999
  links
9000
9000
  });
9001
- const hash = await node.hash;
9001
+ const hash = await node.hash();
9002
9002
  await dataStore.put(hash, node.encoded);
9003
9003
  return hash;
9004
9004
  }
@@ -9016,7 +9016,7 @@ class Peernet {
9016
9016
  const links = [];
9017
9017
  for (const file of files) {
9018
9018
  const fileNode = await new globalThis.peernet.protos['peernet-file'](file);
9019
- const hash = await fileNode.hash;
9019
+ const hash = await fileNode.hash();
9020
9020
  await dataStore.put(hash, fileNode.encoded);
9021
9021
  links.push({ hash, path: file.path });
9022
9022
  }
@@ -9024,7 +9024,7 @@ class Peernet {
9024
9024
  path: '/',
9025
9025
  links
9026
9026
  });
9027
- const hash = await node.hash;
9027
+ const hash = await node.hash();
9028
9028
  await dataStore.put(hash, node.encoded);
9029
9029
  return hash;
9030
9030
  }
@@ -1,3 +1,3 @@
1
- export { P as default } from './peernet-BpKdfmda.js';
1
+ export { P as default } from './peernet-Bl3tF9yA.js';
2
2
  import './identity-CqSnKXWH.js';
3
3
  import './value-C3vAp-wb.js';
@@ -121,7 +121,7 @@ class RequestMessage extends FormatInterface {
121
121
  }
122
122
 
123
123
  var proto$4 = {
124
- response: {}
124
+ response: new Uint8Array()
125
125
  };
126
126
 
127
127
  class ResponseMessage extends FormatInterface {
@@ -164,10 +164,10 @@ class DataMessageResponse extends FormatInterface {
164
164
  }
165
165
 
166
166
  var proto$1 = {
167
- value: String(),
168
- author: String(),
167
+ value: new Uint8Array(),
168
+ author: new Uint8Array(),
169
169
  timestamp: Number(),
170
- files: [String()]
170
+ files: [new Uint8Array()]
171
171
  };
172
172
 
173
173
  class ChatMessage extends FormatInterface {
@@ -451,7 +451,7 @@ class Peernet {
451
451
  await getAddress();
452
452
  this.storePrefix = options.storePrefix;
453
453
  this.root = options.root;
454
- const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-C9lYBAhD.js');
454
+ const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-CHKVVTVE.js');
455
455
  /**
456
456
  * proto Object containing protos
457
457
  * @type {Object}
@@ -968,7 +968,7 @@ class Peernet {
968
968
  const links = [];
969
969
  for (const file of files) {
970
970
  const fileNode = await new globalThis.peernet.protos['peernet-file'](file);
971
- const hash = await fileNode.hash;
971
+ const hash = await fileNode.hash();
972
972
  await dataStore.put(hash, fileNode.encoded);
973
973
  links.push({ hash, path: file.path });
974
974
  }
@@ -976,7 +976,7 @@ class Peernet {
976
976
  path: '/',
977
977
  links
978
978
  });
979
- const hash = await node.hash;
979
+ const hash = await node.hash();
980
980
  await dataStore.put(hash, node.encoded);
981
981
  return hash;
982
982
  }
@@ -994,7 +994,7 @@ class Peernet {
994
994
  const links = [];
995
995
  for (const file of files) {
996
996
  const fileNode = await new globalThis.peernet.protos['peernet-file'](file);
997
- const hash = await fileNode.hash;
997
+ const hash = await fileNode.hash();
998
998
  await dataStore.put(hash, fileNode.encoded);
999
999
  links.push({ hash, path: file.path });
1000
1000
  }
@@ -1002,7 +1002,7 @@ class Peernet {
1002
1002
  path: '/',
1003
1003
  links
1004
1004
  });
1005
- const hash = await node.hash;
1005
+ const hash = await node.hash();
1006
1006
  await dataStore.put(hash, node.encoded);
1007
1007
  return hash;
1008
1008
  }
@@ -1,7 +1,7 @@
1
1
  declare namespace _default {
2
- let value: string;
3
- let author: string;
2
+ let value: Uint8Array<ArrayBuffer>;
3
+ let author: Uint8Array<ArrayBuffer>;
4
4
  let timestamp: number;
5
- let files: string[];
5
+ let files: Uint8Array<ArrayBuffer>[];
6
6
  }
7
7
  export default _default;
@@ -1,4 +1,4 @@
1
1
  declare namespace _default {
2
- let response: {};
2
+ let response: Uint8Array<ArrayBuffer>;
3
3
  }
4
4
  export default _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "1.2.12",
3
+ "version": "1.2.14",
4
4
  "description": "",
5
5
  "browser": "./exports/browser/peernet.js",
6
6
  "exports": {
package/src/peernet.ts CHANGED
@@ -754,7 +754,7 @@ export default class Peernet {
754
754
  const links = []
755
755
  for (const file of files) {
756
756
  const fileNode = await new globalThis.peernet.protos['peernet-file'](file)
757
- const hash = await fileNode.hash
757
+ const hash = await fileNode.hash()
758
758
  await dataStore.put(hash, fileNode.encoded)
759
759
  links.push({ hash, path: file.path })
760
760
  }
@@ -762,7 +762,7 @@ export default class Peernet {
762
762
  path: '/',
763
763
  links
764
764
  })
765
- const hash = await node.hash
765
+ const hash = await node.hash()
766
766
  await dataStore.put(hash, node.encoded)
767
767
 
768
768
  return hash
@@ -783,7 +783,7 @@ export default class Peernet {
783
783
  const links = []
784
784
  for (const file of files) {
785
785
  const fileNode = await new globalThis.peernet.protos['peernet-file'](file)
786
- const hash = await fileNode.hash
786
+ const hash = await fileNode.hash()
787
787
  await dataStore.put(hash, fileNode.encoded)
788
788
  links.push({ hash, path: file.path })
789
789
  }
@@ -791,7 +791,7 @@ export default class Peernet {
791
791
  path: '/',
792
792
  links
793
793
  })
794
- const hash = await node.hash
794
+ const hash = await node.hash()
795
795
  await dataStore.put(hash, node.encoded)
796
796
 
797
797
  return hash
@@ -1,6 +1,6 @@
1
1
  export default {
2
- value: String(),
3
- author: String(),
2
+ value: new Uint8Array(),
3
+ author: new Uint8Array(),
4
4
  timestamp: Number(),
5
- files: [String()]
5
+ files: [new Uint8Array()]
6
6
  }
@@ -1,3 +1,3 @@
1
1
  export default {
2
- response: {}
2
+ response: new Uint8Array()
3
3
  }
package/test/all.js ADDED
@@ -0,0 +1,5 @@
1
+ import './codec.js'
2
+ import './messages.js'
3
+ import './peernet.test.js'
4
+ import './peer-data-exchange.test.js'
5
+ import './peer-file-exchange.test.js'
package/test/index.js CHANGED
@@ -1,3 +1,6 @@
1
- import './messages.js'
1
+ import './peernet.test.js'
2
+ import './peer-data-exchange.test.js'
3
+ import './peer-file-exchange.test.js'
4
+ // import './messages.js'
2
5
  // require('./peernet')
3
6
  // require('./hash')
@@ -0,0 +1,52 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import Peernet from '../exports/peernet.js'
4
+ import { createHash } from 'crypto'
5
+
6
+ // This test simulates two peers: one saves data, the other retrieves it
7
+
8
+ test('peer can save data and other peer can get it', async (t) => {
9
+ const password = 'password'
10
+ // Peer 1
11
+ const peer1 = await new Peernet(
12
+ {
13
+ network: 'leofcoin:peach',
14
+ stars: [],
15
+ root: '.testnet-peer1',
16
+ version: '1.0.0',
17
+ storePrefix: 'test-peer1',
18
+ autoStart: true
19
+ },
20
+ password
21
+ )
22
+
23
+ // Peer 2
24
+ const peer2 = await new Peernet(
25
+ {
26
+ network: 'leofcoin:peach',
27
+ stars: [],
28
+ root: '.testnet-peer2',
29
+ version: '1.0.0',
30
+ storePrefix: 'test-peer2',
31
+ autoStart: true
32
+ },
33
+ password
34
+ )
35
+
36
+ // Wait for both peers to be ready and connected
37
+ await new Promise((resolve) => setTimeout(resolve, 2000))
38
+
39
+ // Peer 1 saves data
40
+ const testData = new TextEncoder().encode('shared-data')
41
+ // Generate SHA-256 hash for the data
42
+ const hash = createHash('sha256').update(testData).digest('hex')
43
+ await peer1.put(hash, testData)
44
+
45
+ // Wait for DHT propagation
46
+ await new Promise((resolve) => setTimeout(resolve, 2000))
47
+
48
+ // Peer 2 tries to get the data
49
+ const received = await peer2.get(hash)
50
+ assert.ok(received, 'Peer 2 should retrieve the data by hash')
51
+ assert.equal(new TextDecoder().decode(received), 'shared-data')
52
+ })
@@ -0,0 +1,78 @@
1
+ import test from 'node:test'
2
+ import assert from 'node:assert/strict'
3
+ import Peernet from '../exports/peernet.js'
4
+
5
+ test('peer can save (put) and retrieve (get) PeernetFile messages', async (t) => {
6
+ const password = 'password'
7
+
8
+ // Peer 1
9
+ const peer1 = await new Peernet(
10
+ {
11
+ network: 'leofcoin:peach',
12
+ stars: [],
13
+ root: '.testnet-file-peer1',
14
+ version: '1.0.0',
15
+ storePrefix: 'test-file-peer1',
16
+ autoStart: true
17
+ },
18
+ password
19
+ )
20
+
21
+ // Peer 2
22
+ const peer2 = await new Peernet(
23
+ {
24
+ network: 'leofcoin:peach',
25
+ stars: [],
26
+ root: '.testnet-file-peer2',
27
+ version: '1.0.0',
28
+ storePrefix: 'test-file-peer2',
29
+ autoStart: true
30
+ },
31
+ password
32
+ )
33
+
34
+ // Wait for peers to connect
35
+ await new Promise((resolve) => setTimeout(resolve, 2000))
36
+
37
+ // Access the proto class from the global object (populated by Peernet)
38
+ const PeernetFile = globalThis.peernet.protos['peernet-file']
39
+ assert.ok(PeernetFile, 'PeernetFile proto should be available')
40
+
41
+ // Create a file message
42
+ const fileContent = `${Date.now()} - Hello, this is a test file content!`
43
+ const fileData = {
44
+ path: '/hello.txt',
45
+ content: new TextEncoder().encode(fileContent)
46
+ }
47
+
48
+ const fileMsg = new PeernetFile(fileData)
49
+
50
+ // Get hash and encoded data
51
+ // Note: hash might be a function
52
+ const hash = await fileMsg.hash()
53
+ const encoded = fileMsg.encoded
54
+
55
+ assert.ok(hash, 'File message should have a hash')
56
+ assert.ok(encoded, 'File message should have encoded data')
57
+
58
+ // Peer 1 puts the file message
59
+ await peer1.put(hash, encoded)
60
+
61
+ // Wait for propagation
62
+ await new Promise((resolve) => setTimeout(resolve, 2000))
63
+
64
+ // Peer 2 gets the file message
65
+ const retrievedEncoded = await peer2.get(hash)
66
+
67
+ assert.ok(retrievedEncoded, 'Peer 2 should be able to retrieve the file message')
68
+
69
+ // Decode and verify
70
+ const retrievedMsg = new PeernetFile(retrievedEncoded)
71
+ const decodedContent = new TextDecoder().decode(retrievedMsg.decoded.content)
72
+
73
+ assert.equal(decodedContent, fileContent, 'Retrieved content should match original')
74
+ assert.equal(retrievedMsg.decoded.path, fileData.path, 'Retrieved path should match original')
75
+
76
+ // Cleanup (if stop methods existed, checking if specific teardown is needed)
77
+ // peer1.close() // or similar if available
78
+ })