trac-peer 0.0.85 → 0.0.86
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 +7 -7
- package/src/check.js +13 -9
- package/src/functions.js +4 -2
- package/src/index.js +16 -8
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trac-peer",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.86",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
|
+
"trac-wallet": "^0.0.33",
|
|
7
8
|
"autobase": "7.0.45",
|
|
8
9
|
"b4a": "1.6.7",
|
|
9
10
|
"bip39": "^3.1.0",
|
|
@@ -23,12 +24,11 @@
|
|
|
23
24
|
"ready-resource": "^1.0.0",
|
|
24
25
|
"safety-catch": "1.0.2",
|
|
25
26
|
"sodium-native": "^4.3.3",
|
|
26
|
-
"trac-wallet": "^0.0.32",
|
|
27
27
|
"xache": "1.2.0",
|
|
28
28
|
"bare-assert": "^1.0.2",
|
|
29
29
|
"bare-buffer": "^3.1.2",
|
|
30
30
|
"bare-console": "^6.0.1",
|
|
31
|
-
"bare-crypto": "^1.4.
|
|
31
|
+
"bare-crypto": "^1.4.2",
|
|
32
32
|
"bare-events": "^2.5.4",
|
|
33
33
|
"bare-fs": "^4.0.2",
|
|
34
34
|
"bare-http1": "^4.0.2",
|
|
@@ -44,22 +44,23 @@
|
|
|
44
44
|
"bare-subprocess": "^5.0.3",
|
|
45
45
|
"bare-timers": "^3.0.1",
|
|
46
46
|
"bare-tls": "^2.0.2",
|
|
47
|
-
"bare-tty": "^
|
|
47
|
+
"bare-tty": "^3.2.0",
|
|
48
48
|
"bare-url": "^2.1.4",
|
|
49
49
|
"bare-utils": "^1.2.0",
|
|
50
50
|
"bare-worker": "^3.0.0",
|
|
51
51
|
"bare-zlib": "^1.2.5",
|
|
52
|
+
"worker_threads": "npm:bare-node-worker-threads",
|
|
53
|
+
"crypto": "npm:bare-node-crypto",
|
|
52
54
|
"assert": "npm:bare-node-assert",
|
|
53
55
|
"buffer": "npm:bare-node-buffer",
|
|
54
56
|
"child_process": "npm:bare-node-child-process",
|
|
55
57
|
"console": "npm:bare-node-console",
|
|
56
|
-
"crypto": "npm:bare-node-crypto",
|
|
57
58
|
"events": "npm:bare-node-events",
|
|
58
59
|
"fs": "npm:bare-node-fs",
|
|
59
60
|
"http": "npm:bare-node-http",
|
|
60
61
|
"https": "npm:bare-node-https",
|
|
61
|
-
"inspector": "npm:bare-node-inspector",
|
|
62
62
|
"module": "npm:bare-node-module",
|
|
63
|
+
"inspector": "npm:bare-node-inspector",
|
|
63
64
|
"os": "npm:bare-node-os",
|
|
64
65
|
"path": "npm:bare-node-path",
|
|
65
66
|
"process": "npm:bare-node-process",
|
|
@@ -71,7 +72,6 @@
|
|
|
71
72
|
"tty": "npm:bare-node-tty",
|
|
72
73
|
"url": "npm:bare-node-url",
|
|
73
74
|
"util": "npm:bare-node-util",
|
|
74
|
-
"worker_threads": "npm:bare-node-worker-threads",
|
|
75
75
|
"zlib": "npm:bare-node-zlib"
|
|
76
76
|
},
|
|
77
77
|
"publishConfig": {
|
package/src/check.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Validator from 'fastest-validator';
|
|
2
2
|
import WAValidator from 'multicoin-address-validator';
|
|
3
|
+
import b4a from "b4a";
|
|
3
4
|
|
|
4
5
|
class Check {
|
|
5
6
|
|
|
@@ -20,6 +21,15 @@ class Check {
|
|
|
20
21
|
if (false === result)
|
|
21
22
|
return false;
|
|
22
23
|
return true;
|
|
24
|
+
},
|
|
25
|
+
hexCheck : (value, errors) => {
|
|
26
|
+
let buf = null
|
|
27
|
+
let result = false
|
|
28
|
+
try{
|
|
29
|
+
buf = b4a.from(value, 'hex')
|
|
30
|
+
result = value === b4a.toString(buf, 'hex')
|
|
31
|
+
} catch (e) {}
|
|
32
|
+
return result;
|
|
23
33
|
}
|
|
24
34
|
}
|
|
25
35
|
});
|
|
@@ -41,15 +51,9 @@ class Check {
|
|
|
41
51
|
this.validator.add("is_hex", function({ schema, messages }, path, context) {
|
|
42
52
|
return {
|
|
43
53
|
source: `
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
buf = Buffer.from(value, 'hex')
|
|
48
|
-
result = value === buf.toString('hex')
|
|
49
|
-
} catch (e) {}
|
|
50
|
-
if (false === result)
|
|
51
|
-
${this.makeError({ type: "bufferedHex", actual: "value", messages })}
|
|
52
|
-
return value
|
|
54
|
+
const result = context.customFunctions.hexCheck(value, errors);
|
|
55
|
+
if(false === result) ${this.makeError({ type: "bufferedHex", actual: "value", messages })}
|
|
56
|
+
return value;
|
|
53
57
|
`
|
|
54
58
|
};
|
|
55
59
|
});
|
package/src/functions.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import b4a from "b4a";
|
|
2
|
+
|
|
1
3
|
export function resolveNumberString(number, decimals){
|
|
2
4
|
number = number + '';
|
|
3
5
|
decimals = isNaN(decimals) ? 18 : parseInt(decimals);
|
|
@@ -76,8 +78,8 @@ export function restoreManifest(parsedManifest) {
|
|
|
76
78
|
if(signer.namespace && signer.namespace.data &&signer.publicKey && signer.publicKey.data){
|
|
77
79
|
return {
|
|
78
80
|
...signer,
|
|
79
|
-
namespace:
|
|
80
|
-
publicKey:
|
|
81
|
+
namespace: b4a.from(signer.namespace.data),
|
|
82
|
+
publicKey: b4a.from(signer.publicKey.data),
|
|
81
83
|
}
|
|
82
84
|
} else {
|
|
83
85
|
return signer;
|
package/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import Autobase from 'autobase';
|
|
|
3
3
|
import Hyperswarm from 'hyperswarm';
|
|
4
4
|
import ReadyResource from 'ready-resource';
|
|
5
5
|
import b4a from 'b4a';
|
|
6
|
+
import sodium from 'sodium-native'
|
|
6
7
|
import Hyperbee from 'hyperbee';
|
|
7
8
|
import readline from 'readline';
|
|
8
9
|
import tty from 'tty'
|
|
@@ -18,6 +19,9 @@ export {default as Contract} from "./contract.js";
|
|
|
18
19
|
export {default as Feature} from "./feature.js";
|
|
19
20
|
export {default as Wallet} from "./wallet.js";
|
|
20
21
|
|
|
22
|
+
// removed until PEAR desktop bare-crypto package is fixed
|
|
23
|
+
//import crypto from 'crypto'
|
|
24
|
+
|
|
21
25
|
export class Peer extends ReadyResource {
|
|
22
26
|
|
|
23
27
|
constructor(options = {}) {
|
|
@@ -41,8 +45,8 @@ export class Peer extends ReadyResource {
|
|
|
41
45
|
this.features = options.features || [];
|
|
42
46
|
this.protocol_instance = null;
|
|
43
47
|
this.contract_instance = null;
|
|
44
|
-
this.channel =
|
|
45
|
-
this.tx_channel =
|
|
48
|
+
this.channel = b4a.alloc(32).fill(options.channel) || null;
|
|
49
|
+
this.tx_channel = b4a.alloc(32).fill(options.tx_channel) || null;
|
|
46
50
|
this.bee = null;
|
|
47
51
|
this.replicate = options.replicate !== false;
|
|
48
52
|
this.connectedNodes = 1;
|
|
@@ -130,7 +134,7 @@ export class Peer extends ReadyResource {
|
|
|
130
134
|
null !== str_value &&
|
|
131
135
|
null !== chat_status &&
|
|
132
136
|
null === await batch.get('sh/'+op.hash) &&
|
|
133
|
-
|
|
137
|
+
b4a.byteLength(str_value) <= 10_2400 &&
|
|
134
138
|
chat_status.value === 'on' &&
|
|
135
139
|
false !== await _this.contract_instance.execute(op, node, batch)){
|
|
136
140
|
let len = await batch.get('msgl');
|
|
@@ -238,7 +242,7 @@ export class Peer extends ReadyResource {
|
|
|
238
242
|
console.log(`Writer auto added: ${op.key}`);
|
|
239
243
|
} else if (op.type === 'addAdmin') {
|
|
240
244
|
if(false === this.check.key(op)) continue;
|
|
241
|
-
const bootstrap =
|
|
245
|
+
const bootstrap = b4a.toString(node.from.key, 'hex')
|
|
242
246
|
if(null === await batch.get('admin') && bootstrap === _this.bootstrap){
|
|
243
247
|
await batch.put('admin', op.key);
|
|
244
248
|
console.log(`Admin added: ${op.key}`);
|
|
@@ -281,7 +285,7 @@ export class Peer extends ReadyResource {
|
|
|
281
285
|
null !== chat_status &&
|
|
282
286
|
chat_status.value === 'on' &&
|
|
283
287
|
null === await batch.get('sh/'+op.hash) &&
|
|
284
|
-
|
|
288
|
+
b4a.byteLength(str_value) <= 256 &&
|
|
285
289
|
visibleLength(op.value.dispatch.nick) <= 32){
|
|
286
290
|
const old = await batch.get('nick/'+op.value.dispatch.address);
|
|
287
291
|
if(old !== null){
|
|
@@ -508,12 +512,16 @@ export class Peer extends ReadyResource {
|
|
|
508
512
|
}
|
|
509
513
|
|
|
510
514
|
async createHash(type, message){
|
|
515
|
+
if(type === 'sha256'){
|
|
516
|
+
const out = b4a.alloc(sodium.crypto_hash_sha256_BYTES);
|
|
517
|
+
sodium.crypto_hash_sha256(out, b4a.from(message));
|
|
518
|
+
return b4a.toString(out, 'hex');
|
|
519
|
+
}
|
|
511
520
|
let createHash = null;
|
|
512
|
-
if(
|
|
521
|
+
if(global.Pear !== undefined){
|
|
513
522
|
let _type = '';
|
|
514
523
|
switch(type.toLowerCase()){
|
|
515
524
|
case 'sha1': _type = 'SHA-1'; break;
|
|
516
|
-
case 'sha256': _type = 'SHA-256'; break;
|
|
517
525
|
case 'sha384': _type = 'SHA-384'; break;
|
|
518
526
|
case 'sha512': _type = 'SHA-512'; break;
|
|
519
527
|
default: throw new Error('Unsupported algorithm.');
|
|
@@ -526,7 +534,7 @@ export class Peer extends ReadyResource {
|
|
|
526
534
|
.map((b) => b.toString(16).padStart(2, "0"))
|
|
527
535
|
.join("");
|
|
528
536
|
} else {
|
|
529
|
-
return createHash(type).update(message).digest('hex')
|
|
537
|
+
return crypto.createHash(type).update(message).digest('hex')
|
|
530
538
|
}
|
|
531
539
|
}
|
|
532
540
|
|