@leofcoin/peernet 0.11.2 → 0.11.3
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/326.peernet.js +1 -29
- package/dist/browser/peernet.js +2 -88552
- package/dist/browser/peernet.js.LICENSE.txt +40 -0
- package/dist/commonjs/{http-4bc6caeb.js → http-e088ccdb.js} +1 -1
- package/dist/commonjs/peernet.js +16 -18
- package/dist/commonjs/response.js +1 -1
- package/dist/module/peernet.js +16 -18
- package/index.html +1 -1
- package/package.json +5 -4
- package/src/handlers/message.js +2 -2
- package/src/peernet.js +8 -9
- package/src/proto/response.proto.js +1 -1
- package/test.js +1 -1
- package/webpack.config.js +3 -3
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Determine if an object is a Buffer
|
|
3
|
+
*
|
|
4
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5
|
+
* @license MIT
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/*!
|
|
9
|
+
* The buffer module from node.js, for the browser.
|
|
10
|
+
*
|
|
11
|
+
* @author Feross Aboukhadijeh <https://feross.org>
|
|
12
|
+
* @license MIT
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/*!
|
|
16
|
+
* assert.js - assertions for javascript
|
|
17
|
+
* Copyright (c) 2018, Christopher Jeffrey (MIT License).
|
|
18
|
+
* https://github.com/chjj/bsert
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/*!
|
|
22
|
+
* base32.js - base32 for bcrypto
|
|
23
|
+
* Copyright (c) 2014-2019, Christopher Jeffrey (MIT License).
|
|
24
|
+
* https://github.com/bcoin-org/bcrypto
|
|
25
|
+
*
|
|
26
|
+
* Parts of this software are based on bitcoin/bitcoin:
|
|
27
|
+
* Copyright (c) 2009-2019, The Bitcoin Core Developers (MIT License).
|
|
28
|
+
* Copyright (c) 2009-2019, The Bitcoin Developers (MIT License).
|
|
29
|
+
* https://github.com/bitcoin/bitcoin
|
|
30
|
+
*
|
|
31
|
+
* Resources:
|
|
32
|
+
* https://tools.ietf.org/html/rfc4648
|
|
33
|
+
* https://github.com/bitcoin/bitcoin/blob/11d486d/src/utilstrencodings.cpp#L230
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
/*! For license information please see browser.js.LICENSE.txt */
|
|
37
|
+
|
|
38
|
+
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
39
|
+
|
|
40
|
+
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
@@ -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.2";
|
|
14
14
|
|
|
15
15
|
var api$1 = {
|
|
16
16
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -1221,10 +1221,10 @@ class HDWallet {
|
|
|
1221
1221
|
return network;
|
|
1222
1222
|
}
|
|
1223
1223
|
|
|
1224
|
-
async generate(network) {
|
|
1224
|
+
async generate(password, network) {
|
|
1225
1225
|
network = this.validateNetwork(network);
|
|
1226
|
-
const mnemonic = bip39.generateMnemonic();
|
|
1227
|
-
const seed = await bip39.mnemonicToSeed(mnemonic);
|
|
1226
|
+
const mnemonic = bip39.generateMnemonic(256);
|
|
1227
|
+
const seed = await bip39.mnemonicToSeed(mnemonic, password);
|
|
1228
1228
|
this.defineHDNode(bip32__namespace.fromSeed(seed, network));
|
|
1229
1229
|
return mnemonic; // userpw
|
|
1230
1230
|
}
|
|
@@ -1232,8 +1232,8 @@ class HDWallet {
|
|
|
1232
1232
|
/**
|
|
1233
1233
|
* recover using mnemonic (recovery word list)
|
|
1234
1234
|
*/
|
|
1235
|
-
async recover(mnemonic, network) {
|
|
1236
|
-
network = this.validateNetwork(network);
|
|
1235
|
+
async recover(mnemonic, password, network) {
|
|
1236
|
+
network = this.validateNetwork(network, password);
|
|
1237
1237
|
const seed = await bip39.mnemonicToSeed(mnemonic);
|
|
1238
1238
|
this.defineHDNode(bip32__namespace.fromSeed(seed, network));
|
|
1239
1239
|
}
|
|
@@ -1433,8 +1433,8 @@ class MessageHandler {
|
|
|
1433
1433
|
*/
|
|
1434
1434
|
async hashAndSignMessage(message) {
|
|
1435
1435
|
const hasher = new hash(message, {name: 'peernet-message'});
|
|
1436
|
-
|
|
1437
|
-
|
|
1436
|
+
let identity = await walletStore.get('identity');
|
|
1437
|
+
identity = JSON.parse(new TextDecoder().decode(identity));
|
|
1438
1438
|
const wallet = new MultiWallet(this.network);
|
|
1439
1439
|
wallet.import(identity.multiWIF);
|
|
1440
1440
|
return wallet.sign(hasher.hash.slice(0, 32))
|
|
@@ -1628,7 +1628,7 @@ class Peernet {
|
|
|
1628
1628
|
protocol: 'peernet-v0.1.0', host: '127.0.0.1', port: options.port
|
|
1629
1629
|
});
|
|
1630
1630
|
} else {
|
|
1631
|
-
const http = await Promise.resolve().then(function () { return require('./http-
|
|
1631
|
+
const http = await Promise.resolve().then(function () { return require('./http-e088ccdb.js'); });
|
|
1632
1632
|
if (environment !== 'browser') http.default(options);
|
|
1633
1633
|
}
|
|
1634
1634
|
|
|
@@ -1638,19 +1638,17 @@ class Peernet {
|
|
|
1638
1638
|
|
|
1639
1639
|
try {
|
|
1640
1640
|
const pub = await accountStore.get('public');
|
|
1641
|
-
this.id = pub.walletId;
|
|
1641
|
+
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
1642
1642
|
} catch (e) {
|
|
1643
1643
|
if (e.code === 'ERR_NOT_FOUND') {
|
|
1644
|
-
const wallet = {};
|
|
1645
1644
|
const {identity, accounts, config} = await generateAccount__default["default"](this.network);
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
await accountStore.put('
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
this.id = wallet.identity.walletId;
|
|
1645
|
+
walletStore.put('version', new TextEncoder().encode(1));
|
|
1646
|
+
walletStore.put('accounts', new TextEncoder().encode(accounts));
|
|
1647
|
+
walletStore.put('identity', new TextEncoder().encode(JSON.stringify(identity)));
|
|
1648
|
+
await accountStore.put('config', new TextEncoder().encode(JSON.stringify(config)));
|
|
1649
|
+
await accountStore.put('public', new TextEncoder().encode(JSON.stringify({walletId: identity.walletId})));
|
|
1650
|
+
|
|
1651
|
+
this.id = identity.walletId;
|
|
1654
1652
|
} else {
|
|
1655
1653
|
throw e
|
|
1656
1654
|
}
|
package/dist/module/peernet.js
CHANGED
|
@@ -1281,7 +1281,7 @@ class RequestMessage extends FormatInterface {
|
|
|
1281
1281
|
var proto$3 = `
|
|
1282
1282
|
// PeernetResponseMessage
|
|
1283
1283
|
message PeernetResponseMessage {
|
|
1284
|
-
required
|
|
1284
|
+
required bytes response = 1;
|
|
1285
1285
|
}
|
|
1286
1286
|
`;
|
|
1287
1287
|
|
|
@@ -1799,10 +1799,10 @@ class HDWallet {
|
|
|
1799
1799
|
return network;
|
|
1800
1800
|
}
|
|
1801
1801
|
|
|
1802
|
-
async generate(network) {
|
|
1802
|
+
async generate(password, network) {
|
|
1803
1803
|
network = this.validateNetwork(network);
|
|
1804
|
-
const mnemonic = generateMnemonic();
|
|
1805
|
-
const seed = await mnemonicToSeed(mnemonic);
|
|
1804
|
+
const mnemonic = generateMnemonic(256);
|
|
1805
|
+
const seed = await mnemonicToSeed(mnemonic, password);
|
|
1806
1806
|
this.defineHDNode(bip32.fromSeed(seed, network));
|
|
1807
1807
|
return mnemonic; // userpw
|
|
1808
1808
|
}
|
|
@@ -1810,8 +1810,8 @@ class HDWallet {
|
|
|
1810
1810
|
/**
|
|
1811
1811
|
* recover using mnemonic (recovery word list)
|
|
1812
1812
|
*/
|
|
1813
|
-
async recover(mnemonic, network) {
|
|
1814
|
-
network = this.validateNetwork(network);
|
|
1813
|
+
async recover(mnemonic, password, network) {
|
|
1814
|
+
network = this.validateNetwork(network, password);
|
|
1815
1815
|
const seed = await mnemonicToSeed(mnemonic);
|
|
1816
1816
|
this.defineHDNode(bip32.fromSeed(seed, network));
|
|
1817
1817
|
}
|
|
@@ -2011,8 +2011,8 @@ class MessageHandler {
|
|
|
2011
2011
|
*/
|
|
2012
2012
|
async hashAndSignMessage(message) {
|
|
2013
2013
|
const hasher = new PeernetHash(message, {name: 'peernet-message'});
|
|
2014
|
-
|
|
2015
|
-
|
|
2014
|
+
let identity = await walletStore.get('identity');
|
|
2015
|
+
identity = JSON.parse(new TextDecoder().decode(identity));
|
|
2016
2016
|
const wallet = new MultiWallet(this.network);
|
|
2017
2017
|
wallet.import(identity.multiWIF);
|
|
2018
2018
|
return wallet.sign(hasher.hash.slice(0, 32))
|
|
@@ -2208,19 +2208,17 @@ class Peernet {
|
|
|
2208
2208
|
|
|
2209
2209
|
try {
|
|
2210
2210
|
const pub = await accountStore.get('public');
|
|
2211
|
-
this.id = pub.walletId;
|
|
2211
|
+
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId;
|
|
2212
2212
|
} catch (e) {
|
|
2213
2213
|
if (e.code === 'ERR_NOT_FOUND') {
|
|
2214
|
-
const wallet = {};
|
|
2215
2214
|
const {identity, accounts, config} = await generateAccount(this.network);
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
await accountStore.put('
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
this.id = wallet.identity.walletId;
|
|
2215
|
+
walletStore.put('version', new TextEncoder().encode(1));
|
|
2216
|
+
walletStore.put('accounts', new TextEncoder().encode(accounts));
|
|
2217
|
+
walletStore.put('identity', new TextEncoder().encode(JSON.stringify(identity)));
|
|
2218
|
+
await accountStore.put('config', new TextEncoder().encode(JSON.stringify(config)));
|
|
2219
|
+
await accountStore.put('public', new TextEncoder().encode(JSON.stringify({walletId: identity.walletId})));
|
|
2220
|
+
|
|
2221
|
+
this.id = identity.walletId;
|
|
2224
2222
|
} else {
|
|
2225
2223
|
throw e
|
|
2226
2224
|
}
|
package/index.html
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
(async () => {
|
|
14
14
|
const peernet = await new Peernet.default()
|
|
15
|
-
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: 100}))
|
|
15
|
+
peernet.addRequestHandler('lastBlock', () => new peernet.protos['peernet-response']({response: new TextEncoder().encode(100)}))
|
|
16
16
|
})()
|
|
17
17
|
</script>
|
|
18
18
|
</body>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/commonjs/peernet.js",
|
|
6
6
|
"module": "dist/module/peernet.js",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@leofcoin/generate-account": "^1.0.2",
|
|
27
|
-
"@leofcoin/multi-wallet": "^2.1.
|
|
27
|
+
"@leofcoin/multi-wallet": "^2.1.2",
|
|
28
28
|
"@leofcoin/peernet-swarm": "^0.1.9",
|
|
29
|
-
"@leofcoin/storage": "^2.
|
|
29
|
+
"@leofcoin/storage": "^2.3.0",
|
|
30
30
|
"@vandeurenglenn/base32": "^1.1.0",
|
|
31
31
|
"@vandeurenglenn/base58": "^1.1.0",
|
|
32
32
|
"@vandeurenglenn/is-hex": "^1.0.0",
|
|
@@ -62,6 +62,7 @@
|
|
|
62
62
|
"rollup-plugin-node-polyfills": "^0.2.1",
|
|
63
63
|
"tape": "^5.2.2",
|
|
64
64
|
"webpack": "^5.72.0",
|
|
65
|
-
"webpack-cli": "^4.9.2"
|
|
65
|
+
"webpack-cli": "^4.9.2",
|
|
66
|
+
"webpack-node-externals": "^3.0.0"
|
|
66
67
|
}
|
|
67
68
|
}
|
package/src/handlers/message.js
CHANGED
|
@@ -18,8 +18,8 @@ export default class MessageHandler {
|
|
|
18
18
|
*/
|
|
19
19
|
async hashAndSignMessage(message) {
|
|
20
20
|
const hasher = new Hash(message, {name: 'peernet-message'})
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
let identity = await walletStore.get('identity')
|
|
22
|
+
identity = JSON.parse(new TextDecoder().decode(identity))
|
|
23
23
|
const wallet = new MultiWallet(this.network)
|
|
24
24
|
wallet.import(identity.multiWIF)
|
|
25
25
|
return wallet.sign(hasher.hash.slice(0, 32))
|
package/src/peernet.js
CHANGED
|
@@ -175,19 +175,18 @@ export default class Peernet {
|
|
|
175
175
|
|
|
176
176
|
try {
|
|
177
177
|
const pub = await accountStore.get('public')
|
|
178
|
-
this.id = pub.walletId
|
|
178
|
+
this.id = JSON.parse(new TextDecoder().decode(pub)).walletId
|
|
179
179
|
} catch (e) {
|
|
180
180
|
if (e.code === 'ERR_NOT_FOUND') {
|
|
181
181
|
const wallet = {}
|
|
182
182
|
const {identity, accounts, config} = await generateAccount(this.network)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
await accountStore.put('
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.id = wallet.identity.walletId
|
|
183
|
+
walletStore.put('version', new TextEncoder().encode(1))
|
|
184
|
+
walletStore.put('accounts', new TextEncoder().encode(accounts))
|
|
185
|
+
walletStore.put('identity', new TextEncoder().encode(JSON.stringify(identity)))
|
|
186
|
+
await accountStore.put('config', new TextEncoder().encode(JSON.stringify(config)));
|
|
187
|
+
await accountStore.put('public', new TextEncoder().encode(JSON.stringify({walletId: identity.walletId})));
|
|
188
|
+
|
|
189
|
+
this.id = identity.walletId
|
|
191
190
|
} else {
|
|
192
191
|
throw e
|
|
193
192
|
}
|
package/test.js
CHANGED
|
@@ -23,6 +23,6 @@ pubsub.subscribe('peer:connected', async peer => {
|
|
|
23
23
|
response = new globalThis.peernet.protos['peernet-response'](proto.decoded.data)
|
|
24
24
|
console.log({response});
|
|
25
25
|
|
|
26
|
-
const block =
|
|
26
|
+
const block = new TextDecoder().decode(response.decoded.response)
|
|
27
27
|
console.log(block);
|
|
28
28
|
})
|
package/webpack.config.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const webpack = require('webpack');
|
|
3
|
-
module.exports = {
|
|
3
|
+
module.exports = [{
|
|
4
4
|
entry: './src/peernet.js',
|
|
5
5
|
plugins: [
|
|
6
6
|
// Work around for Buffer is undefined:
|
|
@@ -17,7 +17,7 @@ module.exports = {
|
|
|
17
17
|
})
|
|
18
18
|
],
|
|
19
19
|
optimization: {
|
|
20
|
-
minimize:
|
|
20
|
+
minimize: true
|
|
21
21
|
},
|
|
22
22
|
resolve: {
|
|
23
23
|
extensions: [ '.ts', '.js' ],
|
|
@@ -38,4 +38,4 @@ resolve: {
|
|
|
38
38
|
filename: 'peernet.js',
|
|
39
39
|
path: path.resolve(__dirname, 'dist', 'browser'),
|
|
40
40
|
},
|
|
41
|
-
};
|
|
41
|
+
}];
|