trac-peer 0.0.82 → 0.0.84
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 +2 -2
- package/src/functions.js +0 -2
- package/src/index.js +25 -3
- package/src/protocol.js +4 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trac-peer",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.84",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"autobase": "7.0.45",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"ready-resource": "^1.0.0",
|
|
24
24
|
"safety-catch": "1.0.2",
|
|
25
25
|
"sodium-native": "^4.3.3",
|
|
26
|
-
"trac-wallet": "^0.0.
|
|
26
|
+
"trac-wallet": "^0.0.31",
|
|
27
27
|
"xache": "1.2.0",
|
|
28
28
|
"bare-assert": "^1.0.2",
|
|
29
29
|
"bare-buffer": "^3.1.2",
|
package/src/functions.js
CHANGED
package/src/index.js
CHANGED
|
@@ -3,12 +3,10 @@ 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 {Buffer} from "buffer"
|
|
7
6
|
import Hyperbee from 'hyperbee';
|
|
8
7
|
import readline from 'readline';
|
|
9
8
|
import tty from 'tty'
|
|
10
9
|
import Corestore from 'corestore';
|
|
11
|
-
import {createHash} from "crypto";
|
|
12
10
|
import w from 'protomux-wakeup';
|
|
13
11
|
const wakeup = new w();
|
|
14
12
|
import {addWriter, addAdmin, setAutoAddWriters, setChatStatus, setMod, deleteMessage,
|
|
@@ -90,7 +88,7 @@ export class Peer extends ReadyResource {
|
|
|
90
88
|
if (null !== str_dispatch &&
|
|
91
89
|
null === await batch.get('tx/'+op.key) &&
|
|
92
90
|
post_tx.value.tx === op.key &&
|
|
93
|
-
post_tx.value.ch === createHash('sha256'
|
|
91
|
+
post_tx.value.ch === await _this.createHash('sha256', str_dispatch) &&
|
|
94
92
|
false !== await _this.contract_instance.execute(op, node, batch)) {
|
|
95
93
|
let len = await batch.get('txl');
|
|
96
94
|
if(null === len) {
|
|
@@ -509,6 +507,30 @@ export class Peer extends ReadyResource {
|
|
|
509
507
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
510
508
|
}
|
|
511
509
|
|
|
510
|
+
async createHash(type, message){
|
|
511
|
+
let createHash = null;
|
|
512
|
+
console.log(message.toLowerCase());
|
|
513
|
+
if(typeof crypto.subtle !== 'undefined'){
|
|
514
|
+
let _type = '';
|
|
515
|
+
switch(type.toLowerCase()){
|
|
516
|
+
case 'sha1': _type = 'SHA-1'; break;
|
|
517
|
+
case 'sha256': _type = 'SHA-256'; break;
|
|
518
|
+
case 'sha384': _type = 'SHA-384'; break;
|
|
519
|
+
case 'sha512': _type = 'SHA-512'; break;
|
|
520
|
+
default: throw new Error('Unsupported algorithm.');
|
|
521
|
+
}
|
|
522
|
+
const encoder = new TextEncoder();
|
|
523
|
+
const data = encoder.encode(message);
|
|
524
|
+
const hash = await crypto.subtle.digest(_type, data);
|
|
525
|
+
const hashArray = Array.from(new Uint8Array(hash));
|
|
526
|
+
return hashArray
|
|
527
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
528
|
+
.join("");
|
|
529
|
+
} else {
|
|
530
|
+
return createHash(type).update(message).digest('hex')
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
512
534
|
async _replicate() {
|
|
513
535
|
if (!this.swarm) {
|
|
514
536
|
const keyPair = await this.store.createKeyPair('hyperswarm');
|
package/src/protocol.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { formatNumberString, resolveNumberString } from "./functions.js";
|
|
2
|
-
import {createHash} from "crypto";
|
|
3
2
|
|
|
4
3
|
class Protocol{
|
|
5
4
|
constructor(options = {}) {
|
|
@@ -70,14 +69,14 @@ class Protocol{
|
|
|
70
69
|
{
|
|
71
70
|
this.nonce = Math.random() + '-' + Date.now();
|
|
72
71
|
const MSBwriter = writer;
|
|
73
|
-
const content_hash = createHash('sha256'
|
|
74
|
-
let tx = createHash('sha256'
|
|
72
|
+
const content_hash = await this.peer.createHash('sha256', JSON.stringify(obj));
|
|
73
|
+
let tx = await this.peer.createHash('sha256',
|
|
75
74
|
MSBwriter + '-' +
|
|
76
75
|
this.peer.writerLocalKey + '-' +
|
|
77
76
|
this.peer.wallet.publicKey + '-' +
|
|
78
77
|
content_hash + '-' +
|
|
79
|
-
this.nonce)
|
|
80
|
-
tx = createHash('sha256'
|
|
78
|
+
this.nonce);
|
|
79
|
+
tx = await this.peer.createHash('sha256', tx);
|
|
81
80
|
const signature = this.peer.wallet.sign(tx + this.nonce);
|
|
82
81
|
this.peer.emit('tx', {
|
|
83
82
|
op: 'pre-tx',
|