@leofcoin/peernet 1.1.57 → 1.1.58
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/.esdoc.json +10 -10
- package/.eslintrc.json +24 -24
- package/.gitattributes +2 -2
- package/.travis.yml +27 -27
- package/BREAKING_CHANGES.md +34 -34
- package/LICENSE +21 -21
- package/README.md +72 -72
- package/deploy.js +8 -8
- package/exports/browser/{index-329e0324.js → index-8868bdd8.js} +1 -1
- package/exports/browser/{messages-000b7f84.js → messages-eb6e5c71.js} +174 -174
- package/exports/browser/{peernet-bfbe6fff.js → peernet-87ea02a4.js} +2005 -1915
- package/exports/browser/peernet.d.ts +13 -11
- package/exports/browser/peernet.js +1 -1
- package/exports/{messages-dc960cb3.js → messages-b9a32987.js} +173 -173
- package/exports/peernet.js +288 -246
- package/exports/src/prompts/password.js +3 -3
- package/exports/store.js +7 -8
- package/exports/types/peernet.d.ts +13 -11
- package/index.html +19 -19
- package/package.json +70 -70
- package/rollup.config.js +76 -69
- package/src/dht/dht.ts +141 -141
- package/src/discovery/peer-discovery.js +75 -75
- package/src/errors/errors.js +12 -12
- package/src/handlers/data.js +11 -11
- package/src/handlers/message.js +34 -34
- package/src/identity.ts +101 -101
- package/src/messages/chat.js +14 -14
- package/src/messages/data-response.js +14 -14
- package/src/messages/data.js +18 -18
- package/src/messages/dht-response.js +14 -14
- package/src/messages/dht.js +22 -22
- package/src/messages/file-link.js +18 -18
- package/src/messages/file.js +18 -18
- package/src/messages/peer-response.js +14 -14
- package/src/messages/peer.js +13 -13
- package/src/messages/peernet.js +14 -14
- package/src/messages/ps.js +13 -13
- package/src/messages/request.js +14 -14
- package/src/messages/response.js +14 -14
- package/src/messages.js +13 -13
- package/src/peer-info.js +9 -9
- package/src/peernet.ts +848 -776
- package/src/prompts/password/node.js +5 -5
- package/src/proto/chat-message.proto.js +6 -6
- package/src/proto/data-response.proto.js +4 -4
- package/src/proto/data.proto.js +4 -4
- package/src/proto/dht-response.proto.js +4 -4
- package/src/proto/dht.proto.js +4 -4
- package/src/proto/file-link.proto.js +5 -5
- package/src/proto/file.proto.js +5 -5
- package/src/proto/peer-response.proto.js +3 -3
- package/src/proto/peer.proto.js +3 -3
- package/src/proto/peernet.proto.js +7 -7
- package/src/proto/ps.proto.js +4 -4
- package/src/proto/request.proto.js +4 -4
- package/src/proto/response.proto.js +3 -3
- package/src/types.ts +27 -27
- package/src/utils/utils.js +78 -78
- package/test/client.js +14 -14
- package/test/codec.js +56 -56
- package/test/hash.js +13 -13
- package/test/index.js +3 -3
- package/test/lastBlock.js +7 -7
- package/test/messages.js +26 -26
- package/test/peernet.js +17 -17
- package/test.js +64 -64
- package/test2.js +9 -9
- package/test3.js +15 -15
- package/test4.js +7 -7
- package/tsconfig.json +12 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import inquirer from 'inquirer'
|
|
2
|
-
|
|
3
|
-
export default async () => {
|
|
4
|
-
const answers = await inquirer.prompt({type: 'password', name: 'password', message: 'Enter password'})
|
|
5
|
-
return answers.password
|
|
1
|
+
import inquirer from 'inquirer'
|
|
2
|
+
|
|
3
|
+
export default async () => {
|
|
4
|
+
const answers = await inquirer.prompt({type: 'password', name: 'password', message: 'Enter password'})
|
|
5
|
+
return answers.password
|
|
6
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
value: String(),
|
|
3
|
-
author: String(),
|
|
4
|
-
timestamp: Number(),
|
|
5
|
-
files: [String()],
|
|
6
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
value: String(),
|
|
3
|
+
author: String(),
|
|
4
|
+
timestamp: Number(),
|
|
5
|
+
files: [String()],
|
|
6
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
hash: String(),
|
|
3
|
-
data: new Uint8Array(),
|
|
4
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
hash: String(),
|
|
3
|
+
data: new Uint8Array(),
|
|
4
|
+
}
|
package/src/proto/data.proto.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
hash: String(),
|
|
3
|
-
'store?': String()
|
|
4
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
hash: String(),
|
|
3
|
+
'store?': String()
|
|
4
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
hash: String(),
|
|
3
|
-
has: Boolean()
|
|
4
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
hash: String(),
|
|
3
|
+
has: Boolean()
|
|
4
|
+
}
|
package/src/proto/dht.proto.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
hash: String(),
|
|
3
|
-
'store?': String()
|
|
4
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
hash: String(),
|
|
3
|
+
'store?': String()
|
|
4
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
hash: String(),
|
|
3
|
-
path: String(),
|
|
4
|
-
'size?': Number()
|
|
5
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
hash: String(),
|
|
3
|
+
path: String(),
|
|
4
|
+
'size?': Number()
|
|
5
|
+
}
|
package/src/proto/file.proto.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
path: String(),
|
|
3
|
-
'content?': '',
|
|
4
|
-
'links?': []
|
|
5
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
path: String(),
|
|
3
|
+
'content?': '',
|
|
4
|
+
'links?': []
|
|
5
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
id: String()
|
|
3
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
id: String()
|
|
3
|
+
}
|
package/src/proto/peer.proto.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
id: String()
|
|
3
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
id: String()
|
|
3
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
data: new Uint8Array(),
|
|
3
|
-
signature: new Uint8Array(),
|
|
4
|
-
'from?': String(),
|
|
5
|
-
'to?': String(),
|
|
6
|
-
'id?': String()
|
|
7
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
data: new Uint8Array(),
|
|
3
|
+
signature: new Uint8Array(),
|
|
4
|
+
'from?': String(),
|
|
5
|
+
'to?': String(),
|
|
6
|
+
'id?': String()
|
|
7
|
+
}
|
package/src/proto/ps.proto.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
data: new Uint8Array(),
|
|
3
|
-
topic: new Uint8Array()
|
|
4
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
data: new Uint8Array(),
|
|
3
|
+
topic: new Uint8Array()
|
|
4
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
request: String(),
|
|
3
|
-
'requested?': new Uint8Array()
|
|
4
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
request: String(),
|
|
3
|
+
'requested?': new Uint8Array()
|
|
4
|
+
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
response: {}
|
|
3
|
-
}
|
|
1
|
+
export default {
|
|
2
|
+
response: {}
|
|
3
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import '@vandeurenglenn/debug'
|
|
2
|
-
import PubSub from '@vandeurenglenn/little-pubsub'
|
|
3
|
-
import Peernet from './peernet.js'
|
|
4
|
-
import PeerDiscovery from './discovery/peer-discovery.js'
|
|
5
|
-
import DHT from './dht/dht.js'
|
|
6
|
-
import { BufferToUint8Array, protoFor, target } from './utils/utils.js'
|
|
7
|
-
import MessageHandler from './handlers/message.js'
|
|
8
|
-
import dataHandler from './handlers/data.js'
|
|
9
|
-
import { encapsulatedError, dhtError,
|
|
10
|
-
nothingFoundError } from './errors/errors.js'
|
|
11
|
-
|
|
12
|
-
import {LeofcoinStorage as LeofcoinStorageClass } from '@leofcoin/storage'
|
|
13
|
-
import { utils as codecUtils } from '@leofcoin/codecs'
|
|
14
|
-
import Identity from './identity.js'
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
declare global {
|
|
18
|
-
var debug: (message) => string
|
|
19
|
-
var globalSub: PubSub
|
|
20
|
-
var pubsub: PubSub
|
|
21
|
-
var peernet: Peernet
|
|
22
|
-
var LeofcoinStorage: typeof LeofcoinStorageClass
|
|
23
|
-
var LeofcoinStorageClient
|
|
24
|
-
var messageStore: typeof LeofcoinStorage
|
|
25
|
-
var dataStore: typeof LeofcoinStorage
|
|
26
|
-
var transactionStore: typeof LeofcoinStorage
|
|
27
|
-
var blockStore: typeof LeofcoinStorage
|
|
1
|
+
import '@vandeurenglenn/debug'
|
|
2
|
+
import PubSub from '@vandeurenglenn/little-pubsub'
|
|
3
|
+
import Peernet from './peernet.js'
|
|
4
|
+
import PeerDiscovery from './discovery/peer-discovery.js'
|
|
5
|
+
import DHT from './dht/dht.js'
|
|
6
|
+
import { BufferToUint8Array, protoFor, target } from './utils/utils.js'
|
|
7
|
+
import MessageHandler from './handlers/message.js'
|
|
8
|
+
import dataHandler from './handlers/data.js'
|
|
9
|
+
import { encapsulatedError, dhtError,
|
|
10
|
+
nothingFoundError } from './errors/errors.js'
|
|
11
|
+
|
|
12
|
+
import {LeofcoinStorage as LeofcoinStorageClass } from '@leofcoin/storage'
|
|
13
|
+
import { utils as codecUtils } from '@leofcoin/codecs'
|
|
14
|
+
import Identity from './identity.js'
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
declare global {
|
|
18
|
+
var debug: (message) => string
|
|
19
|
+
var globalSub: PubSub
|
|
20
|
+
var pubsub: PubSub
|
|
21
|
+
var peernet: Peernet
|
|
22
|
+
var LeofcoinStorage: typeof LeofcoinStorageClass
|
|
23
|
+
var LeofcoinStorageClient
|
|
24
|
+
var messageStore: typeof LeofcoinStorage
|
|
25
|
+
var dataStore: typeof LeofcoinStorage
|
|
26
|
+
var transactionStore: typeof LeofcoinStorage
|
|
27
|
+
var blockStore: typeof LeofcoinStorage
|
|
28
28
|
}
|
package/src/utils/utils.js
CHANGED
|
@@ -1,78 +1,78 @@
|
|
|
1
|
-
import { Codec } from '@leofcoin/codec-format-interface'
|
|
2
|
-
|
|
3
|
-
export const BufferToUint8Array = data => {
|
|
4
|
-
if (data.type === 'Buffer') {
|
|
5
|
-
data = new Uint8Array(data.data)
|
|
6
|
-
}
|
|
7
|
-
return data
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export const expected = (expected, actual) => {
|
|
11
|
-
const rule = (entry) => {
|
|
12
|
-
return !entry ? `: undefined - ${entry} ` :`: ${typeof entry} - `
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const entries = Object.entries(actual)
|
|
16
|
-
.map((entry) => entry.join(rule(entry[1])));
|
|
17
|
-
|
|
18
|
-
return `\nExpected:
|
|
19
|
-
${expected.join('\n\t')}
|
|
20
|
-
|
|
21
|
-
actual:
|
|
22
|
-
${entries.join('\n\t')}`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const protoFor = (message) => {
|
|
26
|
-
const codec = new Codec(message)
|
|
27
|
-
if (!codec.name) throw new Error('proto not found')
|
|
28
|
-
const Proto = globalThis.peernet.protos[codec.name]
|
|
29
|
-
if (!Proto) throw (new Error(`No proto defined for ${codec.name}`))
|
|
30
|
-
return new Proto(message)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* wether or not a peernet daemon is active
|
|
35
|
-
* @return {Boolean}
|
|
36
|
-
*/
|
|
37
|
-
export const hasDaemon = async () => {
|
|
38
|
-
try {
|
|
39
|
-
let response = await fetch('http://127.0.0.1:1000/api/version')
|
|
40
|
-
response = await response.json()
|
|
41
|
-
return Boolean(response.client === '@peernet/api/http')
|
|
42
|
-
} catch (e) {
|
|
43
|
-
return false
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export const https = () => {
|
|
48
|
-
if (!globalThis.location) return false;
|
|
49
|
-
return Boolean(globalThis.location.protocol === 'https:')
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Get current environment
|
|
54
|
-
* @return {String} current environment [node, electron, browser]
|
|
55
|
-
*/
|
|
56
|
-
export const environment = () => {
|
|
57
|
-
const _navigator = globalThis.navigator
|
|
58
|
-
if (!_navigator) {
|
|
59
|
-
return 'node'
|
|
60
|
-
} else if (_navigator && /electron/i.test(_navigator.userAgent)) {
|
|
61
|
-
return 'electron'
|
|
62
|
-
} else {
|
|
63
|
-
return 'browser'
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* * Get current environment
|
|
69
|
-
* @return {Object} result
|
|
70
|
-
* @property {Boolean} reult.daemon whether or not daemon is running
|
|
71
|
-
* @property {Boolean} reult.environment Current environment
|
|
72
|
-
*/
|
|
73
|
-
export const target = async () => {
|
|
74
|
-
let daemon = false
|
|
75
|
-
if (!https()) daemon = await hasDaemon()
|
|
76
|
-
|
|
77
|
-
return {daemon, environment: environment()}
|
|
78
|
-
}
|
|
1
|
+
import { Codec } from '@leofcoin/codec-format-interface'
|
|
2
|
+
|
|
3
|
+
export const BufferToUint8Array = data => {
|
|
4
|
+
if (data.type === 'Buffer') {
|
|
5
|
+
data = new Uint8Array(data.data)
|
|
6
|
+
}
|
|
7
|
+
return data
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const expected = (expected, actual) => {
|
|
11
|
+
const rule = (entry) => {
|
|
12
|
+
return !entry ? `: undefined - ${entry} ` :`: ${typeof entry} - `
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const entries = Object.entries(actual)
|
|
16
|
+
.map((entry) => entry.join(rule(entry[1])));
|
|
17
|
+
|
|
18
|
+
return `\nExpected:
|
|
19
|
+
${expected.join('\n\t')}
|
|
20
|
+
|
|
21
|
+
actual:
|
|
22
|
+
${entries.join('\n\t')}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const protoFor = (message) => {
|
|
26
|
+
const codec = new Codec(message)
|
|
27
|
+
if (!codec.name) throw new Error('proto not found')
|
|
28
|
+
const Proto = globalThis.peernet.protos[codec.name]
|
|
29
|
+
if (!Proto) throw (new Error(`No proto defined for ${codec.name}`))
|
|
30
|
+
return new Proto(message)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* wether or not a peernet daemon is active
|
|
35
|
+
* @return {Boolean}
|
|
36
|
+
*/
|
|
37
|
+
export const hasDaemon = async () => {
|
|
38
|
+
try {
|
|
39
|
+
let response = await fetch('http://127.0.0.1:1000/api/version')
|
|
40
|
+
response = await response.json()
|
|
41
|
+
return Boolean(response.client === '@peernet/api/http')
|
|
42
|
+
} catch (e) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const https = () => {
|
|
48
|
+
if (!globalThis.location) return false;
|
|
49
|
+
return Boolean(globalThis.location.protocol === 'https:')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Get current environment
|
|
54
|
+
* @return {String} current environment [node, electron, browser]
|
|
55
|
+
*/
|
|
56
|
+
export const environment = () => {
|
|
57
|
+
const _navigator = globalThis.navigator
|
|
58
|
+
if (!_navigator) {
|
|
59
|
+
return 'node'
|
|
60
|
+
} else if (_navigator && /electron/i.test(_navigator.userAgent)) {
|
|
61
|
+
return 'electron'
|
|
62
|
+
} else {
|
|
63
|
+
return 'browser'
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* * Get current environment
|
|
69
|
+
* @return {Object} result
|
|
70
|
+
* @property {Boolean} reult.daemon whether or not daemon is running
|
|
71
|
+
* @property {Boolean} reult.environment Current environment
|
|
72
|
+
*/
|
|
73
|
+
export const target = async () => {
|
|
74
|
+
let daemon = false
|
|
75
|
+
if (!https()) daemon = await hasDaemon()
|
|
76
|
+
|
|
77
|
+
return {daemon, environment: environment()}
|
|
78
|
+
}
|
package/test/client.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
const Client = require('./../client.js')
|
|
2
|
-
|
|
3
|
-
const client = new Client()
|
|
4
|
-
|
|
5
|
-
console.log(pubsub.subscribers);
|
|
6
|
-
pubsub.subscribe('peer:connected', (data) => {
|
|
7
|
-
console.log(data);
|
|
8
|
-
})
|
|
9
|
-
pubsub.subscribe('peer:data', (data) => {
|
|
10
|
-
console.log(data);
|
|
11
|
-
})
|
|
12
|
-
|
|
13
|
-
// pubsub.subscribe('peer:connected', async peer => setInterval(async () => {
|
|
14
|
-
// // console.log(await peer.request({type: 'block', index: 0}));
|
|
1
|
+
const Client = require('./../client.js')
|
|
2
|
+
|
|
3
|
+
const client = new Client()
|
|
4
|
+
|
|
5
|
+
console.log(pubsub.subscribers);
|
|
6
|
+
pubsub.subscribe('peer:connected', (data) => {
|
|
7
|
+
console.log(data);
|
|
8
|
+
})
|
|
9
|
+
pubsub.subscribe('peer:data', (data) => {
|
|
10
|
+
console.log(data);
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
// pubsub.subscribe('peer:connected', async peer => setInterval(async () => {
|
|
14
|
+
// // console.log(await peer.request({type: 'block', index: 0}));
|
|
15
15
|
// }, 5000))
|
package/test/codec.js
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
import test from 'tape'
|
|
2
|
-
import Codec from './../src/commonjs/codec.js'
|
|
3
|
-
|
|
4
|
-
const block = '4lmacqas6kpnmvehxpmlvsndgydw5i46mf2pgnaub72eug63dozkw4oqxhk3fazbhkguvlhslcaeqm5jtwghxdk5nvmuakrs7yi2gl6xqmmmw';
|
|
5
|
-
const itx = '5hmacqb6ao252jmbhkhu5isr4yua3jnkhgb5ejjbiomrlzglwarlb777wq7aw5nfz5m4pubx5uffaxp2cqc4ckrh4xirss4nkujvcjbnmomtm';
|
|
6
|
-
const dht = 'b4wiyebqbigjfvm5mizik7ke3v6lyhoahecqiwergnl3cytarf5bd2qvqase'
|
|
7
|
-
const message = '4xnmcay'
|
|
8
|
-
const data = '4hemcay'
|
|
9
|
-
globalThis.peernet = {};
|
|
10
|
-
console.log(parseInt('706468', 16));
|
|
11
|
-
|
|
12
|
-
test('peernet dht codec', tape => {
|
|
13
|
-
tape.plan(2)
|
|
14
|
-
|
|
15
|
-
const codec = new Codec(dht)
|
|
16
|
-
const codec2 = new Codec(codec.encoded)
|
|
17
|
-
tape.equal(codec.name, 'peernet-dht-response', `name from encoded is valid ${codec.name}`)
|
|
18
|
-
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
test('peernet message codec', tape => {
|
|
22
|
-
tape.plan(2)
|
|
23
|
-
|
|
24
|
-
const codec = new Codec(message)
|
|
25
|
-
const codec2 = new Codec(codec.encoded)
|
|
26
|
-
tape.equal(codec.name, 'peernet-message', `name from encoded is valid ${codec.name}`)
|
|
27
|
-
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
test('peernet data codec', tape => {
|
|
31
|
-
tape.plan(2)
|
|
32
|
-
|
|
33
|
-
const codec = new Codec(data)
|
|
34
|
-
const codec2 = new Codec(codec.encoded)
|
|
35
|
-
tape.equal(codec.name, 'peernet-data', `name from encoded is valid ${codec.name}`)
|
|
36
|
-
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
test('leofcoin block codec', tape => {
|
|
40
|
-
tape.plan(2)
|
|
41
|
-
|
|
42
|
-
const codec = new Codec(block)
|
|
43
|
-
const codec2 = new Codec(codec.encoded)
|
|
44
|
-
tape.equal(codec.name, 'leofcoin-block', `name from encoded is valid ${codec.name}`)
|
|
45
|
-
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
test('leofcoin itx codec', tape => {
|
|
49
|
-
tape.plan(2)
|
|
50
|
-
|
|
51
|
-
const codec = new Codec(itx)
|
|
52
|
-
|
|
53
|
-
const codec2 = new Codec(codec.encoded)
|
|
54
|
-
tape.equal(codec.name, 'leofcoin-itx', `name from encoded is valid ${codec.name}`)
|
|
55
|
-
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
56
|
-
})
|
|
1
|
+
import test from 'tape'
|
|
2
|
+
import Codec from './../src/commonjs/codec.js'
|
|
3
|
+
|
|
4
|
+
const block = '4lmacqas6kpnmvehxpmlvsndgydw5i46mf2pgnaub72eug63dozkw4oqxhk3fazbhkguvlhslcaeqm5jtwghxdk5nvmuakrs7yi2gl6xqmmmw';
|
|
5
|
+
const itx = '5hmacqb6ao252jmbhkhu5isr4yua3jnkhgb5ejjbiomrlzglwarlb777wq7aw5nfz5m4pubx5uffaxp2cqc4ckrh4xirss4nkujvcjbnmomtm';
|
|
6
|
+
const dht = 'b4wiyebqbigjfvm5mizik7ke3v6lyhoahecqiwergnl3cytarf5bd2qvqase'
|
|
7
|
+
const message = '4xnmcay'
|
|
8
|
+
const data = '4hemcay'
|
|
9
|
+
globalThis.peernet = {};
|
|
10
|
+
console.log(parseInt('706468', 16));
|
|
11
|
+
|
|
12
|
+
test('peernet dht codec', tape => {
|
|
13
|
+
tape.plan(2)
|
|
14
|
+
|
|
15
|
+
const codec = new Codec(dht)
|
|
16
|
+
const codec2 = new Codec(codec.encoded)
|
|
17
|
+
tape.equal(codec.name, 'peernet-dht-response', `name from encoded is valid ${codec.name}`)
|
|
18
|
+
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
test('peernet message codec', tape => {
|
|
22
|
+
tape.plan(2)
|
|
23
|
+
|
|
24
|
+
const codec = new Codec(message)
|
|
25
|
+
const codec2 = new Codec(codec.encoded)
|
|
26
|
+
tape.equal(codec.name, 'peernet-message', `name from encoded is valid ${codec.name}`)
|
|
27
|
+
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('peernet data codec', tape => {
|
|
31
|
+
tape.plan(2)
|
|
32
|
+
|
|
33
|
+
const codec = new Codec(data)
|
|
34
|
+
const codec2 = new Codec(codec.encoded)
|
|
35
|
+
tape.equal(codec.name, 'peernet-data', `name from encoded is valid ${codec.name}`)
|
|
36
|
+
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('leofcoin block codec', tape => {
|
|
40
|
+
tape.plan(2)
|
|
41
|
+
|
|
42
|
+
const codec = new Codec(block)
|
|
43
|
+
const codec2 = new Codec(codec.encoded)
|
|
44
|
+
tape.equal(codec.name, 'leofcoin-block', `name from encoded is valid ${codec.name}`)
|
|
45
|
+
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('leofcoin itx codec', tape => {
|
|
49
|
+
tape.plan(2)
|
|
50
|
+
|
|
51
|
+
const codec = new Codec(itx)
|
|
52
|
+
|
|
53
|
+
const codec2 = new Codec(codec.encoded)
|
|
54
|
+
tape.equal(codec.name, 'leofcoin-itx', `name from encoded is valid ${codec.name}`)
|
|
55
|
+
tape.equal(codec.name, codec2.name, `decoded name is valid ${codec.name}`)
|
|
56
|
+
})
|
package/test/hash.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
const test = require('tape')
|
|
2
|
-
const Node = require('./../dist/hash/hash.js')
|
|
3
|
-
|
|
4
|
-
const message = '4xnmcay'
|
|
5
|
-
|
|
6
|
-
test('peernet message dht-response', tape => {
|
|
7
|
-
tape.plan(2)
|
|
8
|
-
|
|
9
|
-
const node = new Node(response)
|
|
10
|
-
const node2 = new Node(node.encoded)
|
|
11
|
-
console.log(node2.decoded.has);
|
|
12
|
-
tape.equal(node.name, 'peernet-dht-response', `name from encoded is valid ${node.name}`)
|
|
13
|
-
tape.equal(node.name, node2.name, `decoded name is valid ${node.name}`)
|
|
1
|
+
const test = require('tape')
|
|
2
|
+
const Node = require('./../dist/hash/hash.js')
|
|
3
|
+
|
|
4
|
+
const message = '4xnmcay'
|
|
5
|
+
|
|
6
|
+
test('peernet message dht-response', tape => {
|
|
7
|
+
tape.plan(2)
|
|
8
|
+
|
|
9
|
+
const node = new Node(response)
|
|
10
|
+
const node2 = new Node(node.encoded)
|
|
11
|
+
console.log(node2.decoded.has);
|
|
12
|
+
tape.equal(node.name, 'peernet-dht-response', `name from encoded is valid ${node.name}`)
|
|
13
|
+
tape.equal(node.name, node2.name, `decoded name is valid ${node.name}`)
|
|
14
14
|
})
|
package/test/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './messages.js'
|
|
2
|
-
// require('./peernet')
|
|
3
|
-
// require('./hash')
|
|
1
|
+
import './messages.js'
|
|
2
|
+
// require('./peernet')
|
|
3
|
+
// require('./hash')
|
package/test/lastBlock.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
peernet.addRequestHandler('lastBlock', () => {
|
|
2
|
-
let response;
|
|
3
|
-
const height = await chainStore.get('localIndex')
|
|
4
|
-
const hash = await chainStore.get('localBlock')
|
|
5
|
-
response = JSON.stringify({ height: height.toString(), hash: hash.toString() })
|
|
6
|
-
return new peernet.protos['peernet-response']({ response })
|
|
7
|
-
})
|
|
1
|
+
peernet.addRequestHandler('lastBlock', () => {
|
|
2
|
+
let response;
|
|
3
|
+
const height = await chainStore.get('localIndex')
|
|
4
|
+
const hash = await chainStore.get('localBlock')
|
|
5
|
+
response = JSON.stringify({ height: height.toString(), hash: hash.toString() })
|
|
6
|
+
return new peernet.protos['peernet-response']({ response })
|
|
7
|
+
})
|
package/test/messages.js
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
import test from 'tape'
|
|
2
|
-
import Node from './../dist/commonjs/dht-response.js'
|
|
3
|
-
|
|
4
|
-
const responseHash = 'cqbigjfvm5mizik7ke3v6lyhoahecqiwergnl3cytarf5bd2qvqase'
|
|
5
|
-
|
|
6
|
-
const block = '4lmacqas6kpnmvehxpmlvsndgydw5i46mf2pgnaub72eug63dozkw4oqxhk3fazbhkguvlhslcaeqm5jtwghxdk5nvmuakrs7yi2gl6xqmmmw';
|
|
7
|
-
const itx = '5hmacqb6ao252jmbhkhu5isr4yua3jnkhgb5ejjbiomrlzglwarlb777wq7aw5nfz5m4pubx5uffaxp2cqc4ckrh4xirss4nkujvcjbnmomtm';
|
|
8
|
-
const dht = '5demcay'
|
|
9
|
-
|
|
10
|
-
const message = '4xnmcay'
|
|
11
|
-
const data = '4hemcay'
|
|
12
|
-
globalThis.peernet = {
|
|
13
|
-
codecs: {}
|
|
14
|
-
}
|
|
15
|
-
test('peernet message dht-response', tape => {
|
|
16
|
-
tape.plan(4)
|
|
17
|
-
const n = new Node({ hash: 'hello', has: true })
|
|
18
|
-
console.log(n.hash);
|
|
19
|
-
const node = new Node(n.encoded)
|
|
20
|
-
const node2 = new Node(node.encoded)
|
|
21
|
-
|
|
22
|
-
tape.equal(node.name, 'peernet-dht-response', `name from encoded is valid ${node.name}`)
|
|
23
|
-
tape.equal(node.name, node2.name, `decoded name is valid ${node.name}`)
|
|
24
|
-
tape.equal(node.hash, responseHash, `hash from encoded is valid ${node.hash}`)
|
|
25
|
-
tape.equal(node.hash, node2.hash, `decoded hash is valid ${node.hash}`)
|
|
26
|
-
})
|
|
1
|
+
import test from 'tape'
|
|
2
|
+
import Node from './../dist/commonjs/dht-response.js'
|
|
3
|
+
|
|
4
|
+
const responseHash = 'cqbigjfvm5mizik7ke3v6lyhoahecqiwergnl3cytarf5bd2qvqase'
|
|
5
|
+
|
|
6
|
+
const block = '4lmacqas6kpnmvehxpmlvsndgydw5i46mf2pgnaub72eug63dozkw4oqxhk3fazbhkguvlhslcaeqm5jtwghxdk5nvmuakrs7yi2gl6xqmmmw';
|
|
7
|
+
const itx = '5hmacqb6ao252jmbhkhu5isr4yua3jnkhgb5ejjbiomrlzglwarlb777wq7aw5nfz5m4pubx5uffaxp2cqc4ckrh4xirss4nkujvcjbnmomtm';
|
|
8
|
+
const dht = '5demcay'
|
|
9
|
+
|
|
10
|
+
const message = '4xnmcay'
|
|
11
|
+
const data = '4hemcay'
|
|
12
|
+
globalThis.peernet = {
|
|
13
|
+
codecs: {}
|
|
14
|
+
}
|
|
15
|
+
test('peernet message dht-response', tape => {
|
|
16
|
+
tape.plan(4)
|
|
17
|
+
const n = new Node({ hash: 'hello', has: true })
|
|
18
|
+
console.log(n.hash);
|
|
19
|
+
const node = new Node(n.encoded)
|
|
20
|
+
const node2 = new Node(node.encoded)
|
|
21
|
+
|
|
22
|
+
tape.equal(node.name, 'peernet-dht-response', `name from encoded is valid ${node.name}`)
|
|
23
|
+
tape.equal(node.name, node2.name, `decoded name is valid ${node.name}`)
|
|
24
|
+
tape.equal(node.hash, responseHash, `hash from encoded is valid ${node.hash}`)
|
|
25
|
+
tape.equal(node.hash, node2.hash, `decoded hash is valid ${node.hash}`)
|
|
26
|
+
})
|
package/test/peernet.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
const Client = require('./../dist/commonjs/peernet.js')
|
|
2
|
-
|
|
3
|
-
globalThis.DEBUG = true;
|
|
4
|
-
(async () => {
|
|
5
|
-
const peernet = await new Client({root: '.peernet/test3'})
|
|
6
|
-
|
|
7
|
-
pubsub.subscribe('peer:connected', async peer => setInterval(async () => {
|
|
8
|
-
// const dhtMessage = new DHTMessage({hash: 'hello'})
|
|
9
|
-
// console.log(dhtMessage.encoded);
|
|
10
|
-
// const message = new PeernetMessage({ from: client.id, to: peer.id, data: dhtMessage.encoded, signature: Buffer.from('pnsig') })
|
|
11
|
-
// console.log(message.encoded);
|
|
12
|
-
// console.log(await peer.request(message.encoded));
|
|
13
|
-
const hello = await peernet.get('hello')
|
|
14
|
-
console.log({hello: hello.toString()});
|
|
15
|
-
process.exit()
|
|
16
|
-
}, 5000))
|
|
17
|
-
})()
|
|
1
|
+
const Client = require('./../dist/commonjs/peernet.js')
|
|
2
|
+
|
|
3
|
+
globalThis.DEBUG = true;
|
|
4
|
+
(async () => {
|
|
5
|
+
const peernet = await new Client({root: '.peernet/test3'})
|
|
6
|
+
|
|
7
|
+
pubsub.subscribe('peer:connected', async peer => setInterval(async () => {
|
|
8
|
+
// const dhtMessage = new DHTMessage({hash: 'hello'})
|
|
9
|
+
// console.log(dhtMessage.encoded);
|
|
10
|
+
// const message = new PeernetMessage({ from: client.id, to: peer.id, data: dhtMessage.encoded, signature: Buffer.from('pnsig') })
|
|
11
|
+
// console.log(message.encoded);
|
|
12
|
+
// console.log(await peer.request(message.encoded));
|
|
13
|
+
const hello = await peernet.get('hello')
|
|
14
|
+
console.log({hello: hello.toString()});
|
|
15
|
+
process.exit()
|
|
16
|
+
}, 5000))
|
|
17
|
+
})()
|