@leofcoin/peernet 0.11.15 → 0.11.16
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/dist/browser/peernet.js +44135 -44500
- package/dist/commonjs/{http-f3ec9531.js → http-20a16cac.js} +1 -1
- package/dist/commonjs/peernet.js +47 -9
- package/dist/module/peernet.js +44 -6
- package/index.html +1 -1
- package/package.json +2 -2
- package/src/handlers/message.js +1 -1
- package/src/peernet.js +5 -5
- package/webpack.config.js +1 -1
- package/dist/browser/326.peernet.js +0 -29
|
@@ -10,7 +10,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
|
|
11
11
|
var Koa__default = /*#__PURE__*/_interopDefaultLegacy(Koa);
|
|
12
12
|
|
|
13
|
-
var version = "0.11.
|
|
13
|
+
var version = "0.11.15";
|
|
14
14
|
|
|
15
15
|
var api$1 = {
|
|
16
16
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -12,7 +12,7 @@ var response = require('./response.js');
|
|
|
12
12
|
var fetch = require('node-fetch');
|
|
13
13
|
var codec = require('./codec-45796010.js');
|
|
14
14
|
var hash = require('./hash.js');
|
|
15
|
-
var
|
|
15
|
+
var MultiWallet$1 = require('@leofcoin/multi-wallet');
|
|
16
16
|
var bs58check = require('bs58check');
|
|
17
17
|
var bip32 = require('bip32');
|
|
18
18
|
var createKeccakHash = require('keccak');
|
|
@@ -48,7 +48,7 @@ function _interopNamespace(e) {
|
|
|
48
48
|
var LeofcoinStorage__default = /*#__PURE__*/_interopDefaultLegacy(LeofcoinStorage);
|
|
49
49
|
var protons__default = /*#__PURE__*/_interopDefaultLegacy(protons);
|
|
50
50
|
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
51
|
-
var
|
|
51
|
+
var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet$1);
|
|
52
52
|
var bs58check__default = /*#__PURE__*/_interopDefaultLegacy(bs58check);
|
|
53
53
|
var bs58check__namespace = /*#__PURE__*/_interopNamespace(bs58check);
|
|
54
54
|
var bip32__namespace = /*#__PURE__*/_interopNamespace(bip32);
|
|
@@ -1049,6 +1049,43 @@ class DhtEarth {
|
|
|
1049
1049
|
}
|
|
1050
1050
|
}
|
|
1051
1051
|
|
|
1052
|
+
/**
|
|
1053
|
+
* @params {String} network
|
|
1054
|
+
* @return {object} { identity, accounts, config }
|
|
1055
|
+
*/
|
|
1056
|
+
var generateAccount = async network => {
|
|
1057
|
+
let wallet = new MultiWallet__default["default"](network);
|
|
1058
|
+
/**
|
|
1059
|
+
* @type {string}
|
|
1060
|
+
*/
|
|
1061
|
+
const mnemonic = await wallet.generate();
|
|
1062
|
+
|
|
1063
|
+
wallet = new MultiWallet__default["default"](network);
|
|
1064
|
+
await wallet.recover(mnemonic, network);
|
|
1065
|
+
/**
|
|
1066
|
+
* @type {object}
|
|
1067
|
+
*/
|
|
1068
|
+
const account = wallet.account(0);
|
|
1069
|
+
/**
|
|
1070
|
+
* @type {object}
|
|
1071
|
+
*/
|
|
1072
|
+
const external = account.external(0);
|
|
1073
|
+
const internal = account.internal(0);
|
|
1074
|
+
|
|
1075
|
+
return {
|
|
1076
|
+
identity: {
|
|
1077
|
+
mnemonic,
|
|
1078
|
+
// multiWIF: wallet.export(),
|
|
1079
|
+
publicKey: external.publicKey,
|
|
1080
|
+
privateKey: external.privateKey,
|
|
1081
|
+
walletId: external.id
|
|
1082
|
+
},
|
|
1083
|
+
accounts: [['main account', external.address, internal.address]]
|
|
1084
|
+
// config: {
|
|
1085
|
+
// }
|
|
1086
|
+
}
|
|
1087
|
+
};
|
|
1088
|
+
|
|
1052
1089
|
var testnets = {
|
|
1053
1090
|
'leofcoin:olivia': {
|
|
1054
1091
|
messagePrefix: '\u0019Leofcoin Signed Message:',
|
|
@@ -1552,7 +1589,8 @@ class MessageHandler {
|
|
|
1552
1589
|
let identity = await walletStore.get('identity');
|
|
1553
1590
|
identity = JSON.parse(new TextDecoder().decode(identity));
|
|
1554
1591
|
const wallet = new MultiWallet(this.network);
|
|
1555
|
-
|
|
1592
|
+
console.log(identity);
|
|
1593
|
+
wallet.recover(identity.mnemonic);
|
|
1556
1594
|
return wallet.sign(Buffer.from(hasher.hash).slice(0, 32))
|
|
1557
1595
|
}
|
|
1558
1596
|
|
|
@@ -1758,7 +1796,7 @@ class Peernet {
|
|
|
1758
1796
|
protocol: 'peernet-v0.1.0', host: '127.0.0.1', port: options.port
|
|
1759
1797
|
});
|
|
1760
1798
|
} else {
|
|
1761
|
-
const http = await Promise.resolve().then(function () { return require('./http-
|
|
1799
|
+
const http = await Promise.resolve().then(function () { return require('./http-20a16cac.js'); });
|
|
1762
1800
|
if (environment !== 'browser') http.default(options);
|
|
1763
1801
|
}
|
|
1764
1802
|
|
|
@@ -1771,7 +1809,7 @@ class Peernet {
|
|
|
1771
1809
|
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
1772
1810
|
} catch (e) {
|
|
1773
1811
|
if (e.code === 'ERR_NOT_FOUND') {
|
|
1774
|
-
const {identity, accounts, config} = await
|
|
1812
|
+
const {identity, accounts, config} = await generateAccount(this.network);
|
|
1775
1813
|
walletStore.put('version', new TextEncoder().encode(1));
|
|
1776
1814
|
walletStore.put('accounts', new TextEncoder().encode(accounts));
|
|
1777
1815
|
walletStore.put('identity', new TextEncoder().encode(JSON.stringify(identity)));
|
|
@@ -1860,7 +1898,7 @@ class Peernet {
|
|
|
1860
1898
|
const data = new dhtResponse({hash, has});
|
|
1861
1899
|
const node = await this.prepareMessage(from, data.encoded);
|
|
1862
1900
|
|
|
1863
|
-
sendMessage(peer, id, node.encoded);
|
|
1901
|
+
this.sendMessage(peer, id, node.encoded);
|
|
1864
1902
|
} else if (proto.name === 'peernet-data') {
|
|
1865
1903
|
let { hash, store } = proto.decoded;
|
|
1866
1904
|
let data;
|
|
@@ -1876,7 +1914,7 @@ class Peernet {
|
|
|
1876
1914
|
data = new DataMessageResponse({hash, data});
|
|
1877
1915
|
|
|
1878
1916
|
const node = await this.prepareMessage(from, data.encoded);
|
|
1879
|
-
sendMessage(peer, id, node.encoded);
|
|
1917
|
+
this.sendMessage(peer, id, node.encoded);
|
|
1880
1918
|
}
|
|
1881
1919
|
}
|
|
1882
1920
|
|
|
@@ -1885,7 +1923,7 @@ class Peernet {
|
|
|
1885
1923
|
if (method) {
|
|
1886
1924
|
const data = await method();
|
|
1887
1925
|
const node = await this.prepareMessage(from, data.encoded);
|
|
1888
|
-
sendMessage(peer, id, node.encoded);
|
|
1926
|
+
this.sendMessage(peer, id, node.encoded);
|
|
1889
1927
|
}
|
|
1890
1928
|
} else if (proto.name === 'peernet-ps' && peer.peerId !== this.id) {
|
|
1891
1929
|
globalSub.publish(new TextDecoder().decode(proto.decoded.topic), proto.decoded.data);
|
|
@@ -2157,7 +2195,7 @@ class Peernet {
|
|
|
2157
2195
|
for (const peer of this.connections) {
|
|
2158
2196
|
if (peer.peerId !== this.peerId) {
|
|
2159
2197
|
const node = await this.prepareMessage(peer.peerId, data.encoded);
|
|
2160
|
-
sendMessage(peer, id, node.encoded);
|
|
2198
|
+
this.sendMessage(peer, id, node.encoded);
|
|
2161
2199
|
}
|
|
2162
2200
|
// TODO: if peer subscribed
|
|
2163
2201
|
}
|
package/dist/module/peernet.js
CHANGED
|
@@ -6,7 +6,7 @@ import bs58 from '@vandeurenglenn/base58';
|
|
|
6
6
|
import isHex from '@vandeurenglenn/is-hex';
|
|
7
7
|
import varint from 'varint';
|
|
8
8
|
import createKeccakHash from 'keccak';
|
|
9
|
-
import
|
|
9
|
+
import MultiWallet$1 from '@leofcoin/multi-wallet';
|
|
10
10
|
import * as bs58check from 'bs58check';
|
|
11
11
|
import bs58check__default from 'bs58check';
|
|
12
12
|
import * as bip32 from 'bip32';
|
|
@@ -1645,6 +1645,43 @@ class DhtEarth {
|
|
|
1645
1645
|
}
|
|
1646
1646
|
}
|
|
1647
1647
|
|
|
1648
|
+
/**
|
|
1649
|
+
* @params {String} network
|
|
1650
|
+
* @return {object} { identity, accounts, config }
|
|
1651
|
+
*/
|
|
1652
|
+
var generateAccount = async network => {
|
|
1653
|
+
let wallet = new MultiWallet$1(network);
|
|
1654
|
+
/**
|
|
1655
|
+
* @type {string}
|
|
1656
|
+
*/
|
|
1657
|
+
const mnemonic = await wallet.generate();
|
|
1658
|
+
|
|
1659
|
+
wallet = new MultiWallet$1(network);
|
|
1660
|
+
await wallet.recover(mnemonic, network);
|
|
1661
|
+
/**
|
|
1662
|
+
* @type {object}
|
|
1663
|
+
*/
|
|
1664
|
+
const account = wallet.account(0);
|
|
1665
|
+
/**
|
|
1666
|
+
* @type {object}
|
|
1667
|
+
*/
|
|
1668
|
+
const external = account.external(0);
|
|
1669
|
+
const internal = account.internal(0);
|
|
1670
|
+
|
|
1671
|
+
return {
|
|
1672
|
+
identity: {
|
|
1673
|
+
mnemonic,
|
|
1674
|
+
// multiWIF: wallet.export(),
|
|
1675
|
+
publicKey: external.publicKey,
|
|
1676
|
+
privateKey: external.privateKey,
|
|
1677
|
+
walletId: external.id
|
|
1678
|
+
},
|
|
1679
|
+
accounts: [['main account', external.address, internal.address]]
|
|
1680
|
+
// config: {
|
|
1681
|
+
// }
|
|
1682
|
+
}
|
|
1683
|
+
};
|
|
1684
|
+
|
|
1648
1685
|
var testnets = {
|
|
1649
1686
|
'leofcoin:olivia': {
|
|
1650
1687
|
messagePrefix: '\u0019Leofcoin Signed Message:',
|
|
@@ -2148,7 +2185,8 @@ class MessageHandler {
|
|
|
2148
2185
|
let identity = await walletStore.get('identity');
|
|
2149
2186
|
identity = JSON.parse(new TextDecoder().decode(identity));
|
|
2150
2187
|
const wallet = new MultiWallet(this.network);
|
|
2151
|
-
|
|
2188
|
+
console.log(identity);
|
|
2189
|
+
wallet.recover(identity.mnemonic);
|
|
2152
2190
|
return wallet.sign(Buffer.from(hasher.hash).slice(0, 32))
|
|
2153
2191
|
}
|
|
2154
2192
|
|
|
@@ -2448,7 +2486,7 @@ class Peernet {
|
|
|
2448
2486
|
const data = new DHTMessageResponse({hash, has});
|
|
2449
2487
|
const node = await this.prepareMessage(from, data.encoded);
|
|
2450
2488
|
|
|
2451
|
-
sendMessage(peer, id, node.encoded);
|
|
2489
|
+
this.sendMessage(peer, id, node.encoded);
|
|
2452
2490
|
} else if (proto.name === 'peernet-data') {
|
|
2453
2491
|
let { hash, store } = proto.decoded;
|
|
2454
2492
|
let data;
|
|
@@ -2464,7 +2502,7 @@ class Peernet {
|
|
|
2464
2502
|
data = new DataMessageResponse({hash, data});
|
|
2465
2503
|
|
|
2466
2504
|
const node = await this.prepareMessage(from, data.encoded);
|
|
2467
|
-
sendMessage(peer, id, node.encoded);
|
|
2505
|
+
this.sendMessage(peer, id, node.encoded);
|
|
2468
2506
|
}
|
|
2469
2507
|
}
|
|
2470
2508
|
|
|
@@ -2473,7 +2511,7 @@ class Peernet {
|
|
|
2473
2511
|
if (method) {
|
|
2474
2512
|
const data = await method();
|
|
2475
2513
|
const node = await this.prepareMessage(from, data.encoded);
|
|
2476
|
-
sendMessage(peer, id, node.encoded);
|
|
2514
|
+
this.sendMessage(peer, id, node.encoded);
|
|
2477
2515
|
}
|
|
2478
2516
|
} else if (proto.name === 'peernet-ps' && peer.peerId !== this.id) {
|
|
2479
2517
|
globalSub.publish(new TextDecoder().decode(proto.decoded.topic), proto.decoded.data);
|
|
@@ -2745,7 +2783,7 @@ class Peernet {
|
|
|
2745
2783
|
for (const peer of this.connections) {
|
|
2746
2784
|
if (peer.peerId !== this.peerId) {
|
|
2747
2785
|
const node = await this.prepareMessage(peer.peerId, data.encoded);
|
|
2748
|
-
sendMessage(peer, id, node.encoded);
|
|
2786
|
+
this.sendMessage(peer, id, node.encoded);
|
|
2749
2787
|
}
|
|
2750
2788
|
// TODO: if peer subscribed
|
|
2751
2789
|
}
|
package/index.html
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
<script>
|
|
12
12
|
|
|
13
13
|
(async () => {
|
|
14
|
-
const peernet = await new Peernet
|
|
14
|
+
const peernet = await new Peernet()
|
|
15
15
|
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: new TextEncoder().encode(100)}))
|
|
16
16
|
})()
|
|
17
17
|
</script>
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.16",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/commonjs/peernet.js",
|
|
6
6
|
"module": "dist/module/peernet.js",
|
|
7
7
|
"browser": "dist/browser/peernet.js",
|
|
8
8
|
"scripts": {
|
|
9
|
-
"build": "webpack",
|
|
9
|
+
"build": "npm run c && webpack",
|
|
10
10
|
"test": "node test/index.js",
|
|
11
11
|
"server": "discovery-swarm-webrtc --port=4000",
|
|
12
12
|
"demo": "jsproject --serve ./ --port 6868",
|
package/src/handlers/message.js
CHANGED
|
@@ -21,7 +21,7 @@ export default class MessageHandler {
|
|
|
21
21
|
let identity = await walletStore.get('identity')
|
|
22
22
|
identity = JSON.parse(new TextDecoder().decode(identity))
|
|
23
23
|
const wallet = new MultiWallet(this.network)
|
|
24
|
-
wallet.
|
|
24
|
+
wallet.recover(identity.mnemonic)
|
|
25
25
|
return wallet.sign(Buffer.from(hasher.hash).slice(0, 32))
|
|
26
26
|
}
|
|
27
27
|
|
package/src/peernet.js
CHANGED
|
@@ -18,7 +18,7 @@ import DHT from './dht/dht.js'
|
|
|
18
18
|
import Hash from './hash/hash'
|
|
19
19
|
import codecs from './codec/codecs'
|
|
20
20
|
import { protoFor, target } from './utils/utils.js'
|
|
21
|
-
import generateAccount from '
|
|
21
|
+
import generateAccount from './../node_modules/@leofcoin/generate-account/dist/module/generate-account'
|
|
22
22
|
import MessageHandler from './handlers/message.js'
|
|
23
23
|
import { encapsulatedError, dhtError,
|
|
24
24
|
nothingFoundError } from './errors/errors.js'
|
|
@@ -283,7 +283,7 @@ export default class Peernet {
|
|
|
283
283
|
const data = new DHTMessageResponse({hash, has})
|
|
284
284
|
const node = await this.prepareMessage(from, data.encoded)
|
|
285
285
|
|
|
286
|
-
sendMessage(peer, id, node.encoded)
|
|
286
|
+
this.sendMessage(peer, id, node.encoded)
|
|
287
287
|
} else if (proto.name === 'peernet-data') {
|
|
288
288
|
let { hash, store } = proto.decoded
|
|
289
289
|
let data
|
|
@@ -299,7 +299,7 @@ export default class Peernet {
|
|
|
299
299
|
data = new DataMessageResponse({hash, data});
|
|
300
300
|
|
|
301
301
|
const node = await this.prepareMessage(from, data.encoded)
|
|
302
|
-
sendMessage(peer, id, node.encoded)
|
|
302
|
+
this.sendMessage(peer, id, node.encoded)
|
|
303
303
|
}
|
|
304
304
|
} else {
|
|
305
305
|
// ban (trying to access private st)
|
|
@@ -310,7 +310,7 @@ export default class Peernet {
|
|
|
310
310
|
if (method) {
|
|
311
311
|
const data = await method()
|
|
312
312
|
const node = await this.prepareMessage(from, data.encoded)
|
|
313
|
-
sendMessage(peer, id, node.encoded)
|
|
313
|
+
this.sendMessage(peer, id, node.encoded)
|
|
314
314
|
}
|
|
315
315
|
} else if (proto.name === 'peernet-ps' && peer.peerId !== this.id) {
|
|
316
316
|
globalSub.publish(new TextDecoder().decode(proto.decoded.topic), proto.decoded.data)
|
|
@@ -583,7 +583,7 @@ export default class Peernet {
|
|
|
583
583
|
for (const peer of this.connections) {
|
|
584
584
|
if (peer.peerId !== this.peerId) {
|
|
585
585
|
const node = await this.prepareMessage(peer.peerId, data.encoded)
|
|
586
|
-
sendMessage(peer, id, node.encoded)
|
|
586
|
+
this.sendMessage(peer, id, node.encoded)
|
|
587
587
|
}
|
|
588
588
|
// TODO: if peer subscribed
|
|
589
589
|
}
|
package/webpack.config.js
CHANGED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
(self["webpackChunkPeernet"] = self["webpackChunkPeernet"] || []).push([[326],{
|
|
3
|
-
|
|
4
|
-
/***/ 9326:
|
|
5
|
-
/***/ (function(__unused_webpack_module, exports) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.MediaStream = window.MediaStream;
|
|
10
|
-
exports.MediaStreamTrack = window.MediaStreamTrack;
|
|
11
|
-
exports.RTCDataChannel = window.RTCDataChannel;
|
|
12
|
-
exports.RTCDataChannelEvent = window.RTCDataChannelEvent;
|
|
13
|
-
exports.RTCDtlsTransport = window.RTCDtlsTransport;
|
|
14
|
-
exports.RTCIceCandidate = window.RTCIceCandidate;
|
|
15
|
-
exports.RTCIceTransport = window.RTCIceTransport;
|
|
16
|
-
exports.RTCPeerConnection = window.RTCPeerConnection;
|
|
17
|
-
exports.RTCPeerConnectionIceEvent = window.RTCPeerConnectionIceEvent;
|
|
18
|
-
exports.RTCRtpReceiver = window.RTCRtpReceiver;
|
|
19
|
-
exports.RTCRtpSender = window.RTCRtpSender;
|
|
20
|
-
exports.RTCRtpTransceiver = window.RTCRtpTransceiver;
|
|
21
|
-
exports.RTCSctpTransport = window.RTCSctpTransport;
|
|
22
|
-
exports.RTCSessionDescription = window.RTCSessionDescription;
|
|
23
|
-
exports.getUserMedia = window.getUserMedia;
|
|
24
|
-
exports.mediaDevices = navigator.mediaDevices;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/***/ })
|
|
28
|
-
|
|
29
|
-
}]);
|