trac-peer 0.1.39 → 0.1.41
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 +3 -3
- package/src/feature.js +1 -1
- package/src/functions.js +12 -12
- package/src/index.js +2 -2
- package/src/protocol.js +7 -2
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "trac-peer",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.41",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"dependencies": {
|
|
7
7
|
"assert": "npm:bare-node-assert",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"bare-stream": "^2.6.5",
|
|
27
27
|
"bare-subprocess": "^5.0.3",
|
|
28
28
|
"bare-timers": "^3.0.1",
|
|
29
|
-
"bare-tls": "^2.0.
|
|
29
|
+
"bare-tls": "^2.0.4",
|
|
30
30
|
"bare-tty": "^5.0.2",
|
|
31
31
|
"bare-url": "^2.1.4",
|
|
32
32
|
"bare-utils": "^1.2.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"stream": "npm:bare-node-stream",
|
|
69
69
|
"timers": "npm:bare-node-timers",
|
|
70
70
|
"tls": "npm:bare-node-tls",
|
|
71
|
-
"trac-wallet": "^0.0.
|
|
71
|
+
"trac-wallet": "^0.0.42",
|
|
72
72
|
"tty": "npm:bare-node-tty",
|
|
73
73
|
"url": "npm:bare-node-url",
|
|
74
74
|
"util": "npm:bare-node-util",
|
package/src/feature.js
CHANGED
|
@@ -20,7 +20,7 @@ class Feature {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
async append(key, value){
|
|
23
|
-
const nonce =
|
|
23
|
+
const nonce = this.peer.protocol_instance.generateNonce();
|
|
24
24
|
const hash = this.peer.wallet.sign(JSON.stringify(value) + nonce);
|
|
25
25
|
await this.peer.base.append({ type: 'feature', key: this.key + '_' + key, value : {
|
|
26
26
|
dispatch : {
|
package/src/functions.js
CHANGED
|
@@ -125,7 +125,7 @@ export async function setWhitelistStatus(input, peer){
|
|
|
125
125
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
126
126
|
const value = ''+splitted.user;
|
|
127
127
|
const status = parseInt(splitted.status) === 1;
|
|
128
|
-
const nonce =
|
|
128
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
129
129
|
const signature = { dispatch : {
|
|
130
130
|
type : 'setWhitelistStatus',
|
|
131
131
|
user: value,
|
|
@@ -139,7 +139,7 @@ export async function setWhitelistStatus(input, peer){
|
|
|
139
139
|
export async function enableWhitelist(input, peer){
|
|
140
140
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
141
141
|
const value = splitted.enabled === 1;
|
|
142
|
-
const nonce =
|
|
142
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
143
143
|
const signature = { dispatch : {
|
|
144
144
|
type : 'enableWhitelist',
|
|
145
145
|
enabled: value,
|
|
@@ -154,7 +154,7 @@ export async function pinMessage(input, peer){
|
|
|
154
154
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
155
155
|
const value = parseInt(splitted.id);
|
|
156
156
|
const pinned = parseInt(splitted.pin) === 1;
|
|
157
|
-
const nonce =
|
|
157
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
158
158
|
const signature = { dispatch : {
|
|
159
159
|
type : 'pinMessage',
|
|
160
160
|
id: value,
|
|
@@ -169,7 +169,7 @@ export async function deleteMessage(input, peer){
|
|
|
169
169
|
let address = null;
|
|
170
170
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
171
171
|
const value = parseInt(splitted.id);
|
|
172
|
-
const nonce =
|
|
172
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
173
173
|
const signature = { dispatch : {
|
|
174
174
|
type : 'deleteMessage',
|
|
175
175
|
id: value,
|
|
@@ -182,7 +182,7 @@ export async function deleteMessage(input, peer){
|
|
|
182
182
|
export async function updateAdmin(input, peer){
|
|
183
183
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
184
184
|
const value = ''+splitted.address === 'null' ? null : ''+splitted.address;
|
|
185
|
-
const nonce =
|
|
185
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
186
186
|
const signature = { dispatch : {
|
|
187
187
|
type : 'updateAdmin',
|
|
188
188
|
admin: value,
|
|
@@ -196,7 +196,7 @@ export async function setMod(input, peer){
|
|
|
196
196
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
197
197
|
const value = ''+splitted.user;
|
|
198
198
|
const mod = parseInt(splitted.mod) === 1;
|
|
199
|
-
const nonce =
|
|
199
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
200
200
|
const signature = { dispatch : {
|
|
201
201
|
type : 'setMod',
|
|
202
202
|
user: value,
|
|
@@ -211,7 +211,7 @@ export async function muteStatus(input, peer){
|
|
|
211
211
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
212
212
|
const value = ''+splitted.user;
|
|
213
213
|
const muted = parseInt(splitted.muted) === 1;
|
|
214
|
-
const nonce =
|
|
214
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
215
215
|
const signature = { dispatch : {
|
|
216
216
|
type : 'muteStatus',
|
|
217
217
|
user: value,
|
|
@@ -229,7 +229,7 @@ export async function setNick(input, peer){
|
|
|
229
229
|
if(splitted.user !== undefined){
|
|
230
230
|
user = ''+splitted.user;
|
|
231
231
|
}
|
|
232
|
-
const nonce =
|
|
232
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
233
233
|
const signature = { dispatch : {
|
|
234
234
|
type : 'setNick',
|
|
235
235
|
nick: value,
|
|
@@ -245,7 +245,7 @@ export async function postMessage(input, peer){
|
|
|
245
245
|
if(typeof splitted.message === "boolean" || splitted.message === undefined) throw new Error('Empty message not allowed');
|
|
246
246
|
const reply_to = splitted.reply_to !== undefined ? parseInt(splitted.reply_to) : null;
|
|
247
247
|
const value = '' + splitted.message;
|
|
248
|
-
const nonce =
|
|
248
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
249
249
|
const signature = { dispatch : {
|
|
250
250
|
type : 'msg',
|
|
251
251
|
msg: value,
|
|
@@ -263,7 +263,7 @@ export async function postMessage(input, peer){
|
|
|
263
263
|
export async function setChatStatus(input, peer){
|
|
264
264
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
265
265
|
const value = parseInt(splitted.enabled) === 1 ? 'on' : 'off';
|
|
266
|
-
const nonce =
|
|
266
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
267
267
|
if(value !== 'on' && value !== 'off') throw new Error('setChatStatus: use on and off values.');
|
|
268
268
|
const msg = { type: 'setChatStatus', key: value }
|
|
269
269
|
const signature = {
|
|
@@ -276,7 +276,7 @@ export async function setChatStatus(input, peer){
|
|
|
276
276
|
export async function setAutoAddWriters(input, peer){
|
|
277
277
|
const splitted = peer.protocol_instance.parseArgs(input)
|
|
278
278
|
const value = parseInt(splitted.enabled) === 1 ? 'on' : 'off';
|
|
279
|
-
const nonce =
|
|
279
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
280
280
|
if(value !== 'on' && value !== 'off') throw new Error('setAutoAddWriters: use on and off values.');
|
|
281
281
|
const msg = { type: 'setAutoAddWriters', key: value }
|
|
282
282
|
const signature = {
|
|
@@ -295,7 +295,7 @@ export async function addAdmin(input, peer){
|
|
|
295
295
|
export async function addWriter(input, peer){
|
|
296
296
|
const splitted = input.split(' ');
|
|
297
297
|
const parsed = peer.protocol_instance.parseArgs(input)
|
|
298
|
-
const nonce =
|
|
298
|
+
const nonce = peer.protocol_instance.generateNonce();
|
|
299
299
|
if(splitted[0] === '/add_indexer'){
|
|
300
300
|
const msg = { type: 'addIndexer', key: ''+parsed.key }
|
|
301
301
|
const signature = {
|
package/src/index.js
CHANGED
|
@@ -217,7 +217,7 @@ export class Peer extends ReadyResource {
|
|
|
217
217
|
if(true === verified) {
|
|
218
218
|
await _this.contract_instance.execute(op, batch);
|
|
219
219
|
await batch.put('sh/'+op.value.dispatch.hash, '');
|
|
220
|
-
console.log(`Feature ${op.key} appended`);
|
|
220
|
+
//console.log(`Feature ${op.key} appended`);
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
} else if (op.type === 'addIndexer') {
|
|
@@ -655,7 +655,7 @@ export class Peer extends ReadyResource {
|
|
|
655
655
|
msb_tx['msbsl'] = msbsl;
|
|
656
656
|
msb_tx['ipk'] = this.wallet.publicKey;
|
|
657
657
|
msb_tx['wp'] = this.validator;
|
|
658
|
-
msb_tx['nonce'] =
|
|
658
|
+
msb_tx['nonce'] = this.protocol_instance.generateNonce();
|
|
659
659
|
msb_tx['hash'] = this.wallet.sign(tx + await this.createHash('sha256', jsonStringify(msb_tx['dispatch'])) + msb_tx['nonce']);
|
|
660
660
|
delete this.tx_pool[tx];
|
|
661
661
|
delete this.protocol_instance.prepared_transactions_content[tx];
|
package/src/protocol.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { formatNumberString, resolveNumberString, jsonStringify, jsonParse, safeClone } from "./functions.js";
|
|
2
2
|
import {ProtocolApi} from './api.js';
|
|
3
|
+
import Wallet from 'trac-wallet';
|
|
3
4
|
|
|
4
5
|
class Protocol{
|
|
5
6
|
constructor(options = {}) {
|
|
@@ -32,6 +33,10 @@ class Protocol{
|
|
|
32
33
|
return 8_192;
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
generateNonce(){
|
|
37
|
+
return Wallet.generateNonce().toString('hex');
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
safeBigInt(value) {
|
|
36
41
|
try{
|
|
37
42
|
return BigInt(value);
|
|
@@ -100,7 +105,7 @@ class Protocol{
|
|
|
100
105
|
async simulateTransaction(obj){
|
|
101
106
|
const storage = new SimStorage(this.peer);
|
|
102
107
|
const null_hex = '0000000000000000000000000000000000000000000000000000000000000000';
|
|
103
|
-
let nonce =
|
|
108
|
+
let nonce = this.generateNonce();
|
|
104
109
|
const content_hash = await this.peer.createHash('sha256', JSON.stringify(obj));
|
|
105
110
|
let tx = await this.generateTx(this.peer.bootstrap, this.peer.msb.bootstrap, null_hex,
|
|
106
111
|
this.peer.writerLocalKey, this.peer.wallet.publicKey, content_hash, nonce);
|
|
@@ -129,7 +134,7 @@ class Protocol{
|
|
|
129
134
|
obj.type !== undefined &&
|
|
130
135
|
obj.value !== undefined)
|
|
131
136
|
{
|
|
132
|
-
this.nonce =
|
|
137
|
+
this.nonce = this.generateNonce();
|
|
133
138
|
const content_hash = await this.peer.createHash('sha256', JSON.stringify(obj));
|
|
134
139
|
let tx = await this.generateTx(this.peer.bootstrap, this.peer.msb.bootstrap, validator_pub_key,
|
|
135
140
|
this.peer.writerLocalKey, this.peer.wallet.publicKey, content_hash, this.nonce);
|