trac-msb 0.0.73 → 0.0.74
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/package.json +1 -1
- package/src/network.js +12 -7
- package/src/utils/check.js +1 -0
package/package.json
CHANGED
package/src/network.js
CHANGED
|
@@ -54,15 +54,13 @@ class Network {
|
|
|
54
54
|
|
|
55
55
|
static async dhtServer(dhtServer, base, wallet, writingKey, networkInstance){
|
|
56
56
|
try{
|
|
57
|
-
|
|
57
|
+
dhtServer.on('connection', function (connection) {
|
|
58
58
|
connection.on('message', async (msg) => {
|
|
59
|
-
|
|
60
|
-
if(
|
|
59
|
+
msg = b4a.toString(msg, 'utf-8');
|
|
60
|
+
if(msg === 'get_writer_key'){
|
|
61
61
|
await connection.send(b4a.from(JSON.stringify({op:'writer_key', key : writingKey})));
|
|
62
62
|
} else {
|
|
63
63
|
|
|
64
|
-
console.log(msg);
|
|
65
|
-
|
|
66
64
|
if (base.isIndexer || !base.writable) return;
|
|
67
65
|
|
|
68
66
|
// TODO: decide if a tx rejection should be responded with
|
|
@@ -77,6 +75,13 @@ class Network {
|
|
|
77
75
|
|
|
78
76
|
const parsedPreTx = JSON.parse(msg);
|
|
79
77
|
|
|
78
|
+
console.log(networkInstance.check.sanitizePreTx(parsedPreTx),
|
|
79
|
+
wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')),
|
|
80
|
+
parsedPreTx.w === writingKey,
|
|
81
|
+
parsedPreTx.wp === wallet.publicKey,
|
|
82
|
+
null === await base.view.get(parsedPreTx.tx)
|
|
83
|
+
);
|
|
84
|
+
|
|
80
85
|
if (networkInstance.check.sanitizePreTx(parsedPreTx) &&
|
|
81
86
|
wallet.verify(b4a.from(parsedPreTx.is, 'hex'), b4a.from(parsedPreTx.tx + parsedPreTx.in), b4a.from(parsedPreTx.ipk, 'hex')) &&
|
|
82
87
|
parsedPreTx.w === writingKey &&
|
|
@@ -106,7 +111,7 @@ class Network {
|
|
|
106
111
|
console.log(e)
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
|
-
await connection.destroy();
|
|
114
|
+
//await connection.destroy();
|
|
110
115
|
});
|
|
111
116
|
connection.on('close', () => { });
|
|
112
117
|
connection.on('error', (error) => { });
|
|
@@ -115,7 +120,7 @@ class Network {
|
|
|
115
120
|
publicKey: b4a.from(wallet.publicKey, 'hex'),
|
|
116
121
|
secretKey: b4a.from(wallet.secretKey, 'hex')
|
|
117
122
|
};
|
|
118
|
-
await
|
|
123
|
+
await dhtServer.listen(keyPair)
|
|
119
124
|
console.log('DHT node is listening on public key', wallet.publicKey);
|
|
120
125
|
} catch(e) { }
|
|
121
126
|
}
|
package/src/utils/check.js
CHANGED
|
@@ -108,6 +108,7 @@ class Check {
|
|
|
108
108
|
op: { type: 'string', enum: ['pre-tx'], required: true },
|
|
109
109
|
tx: { type: 'is_hex_string', required: true }, // TODO: if we will use only 256 bit hash then change to length: 64
|
|
110
110
|
is: { type: 'is_hex_string', length: 128, required: true },
|
|
111
|
+
wp: { type: 'is_hex_string', length: 64, required: true },
|
|
111
112
|
w: { type: 'is_hex_string', length: 64, required: true },
|
|
112
113
|
i: { type: 'is_hex_string', length: 64, required: true },
|
|
113
114
|
ipk: { type: 'is_hex_string', length: 64, required: true },
|