trac-peer 0.0.54 → 0.0.56
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/functions.js +19 -18
- package/src/index.js +50 -38
package/package.json
CHANGED
package/src/functions.js
CHANGED
|
@@ -75,7 +75,7 @@ export function restoreManifest(parsedManifest) {
|
|
|
75
75
|
|
|
76
76
|
if (Array.isArray(parsedManifest.signers)) {
|
|
77
77
|
parsedManifest.signers = parsedManifest.signers.map(signer => {
|
|
78
|
-
if(signer.namespace && signer.namespace.data &&signer.publicKey && signer.publicKey.data){
|
|
78
|
+
if(signer.namespace && signer.namespace.data &&signer.publicKey && signer.publicKey.data){
|
|
79
79
|
return {
|
|
80
80
|
...signer,
|
|
81
81
|
namespace: Buffer.from(signer.namespace.data),
|
|
@@ -120,7 +120,7 @@ export async function setWhitelistStatus(input, peer){
|
|
|
120
120
|
|
|
121
121
|
export async function enableWhitelist(input, peer){
|
|
122
122
|
const splitted = yargs(input).parse();
|
|
123
|
-
const value = splitted.enabled;
|
|
123
|
+
const value = splitted.enabled === 1;
|
|
124
124
|
const nonce = Math.random() + '-' + Date.now();
|
|
125
125
|
const signature = { dispatch : {
|
|
126
126
|
type : 'enableWhitelist',
|
|
@@ -197,19 +197,19 @@ export async function postMessage(input, peer){
|
|
|
197
197
|
const value = splitted.message;
|
|
198
198
|
const nonce = Math.random() + '-' + Date.now();
|
|
199
199
|
const signature = { dispatch : {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
200
|
+
type : 'msg',
|
|
201
|
+
msg: value,
|
|
202
|
+
address : peer.wallet.publicKey,
|
|
203
|
+
attachments : [],
|
|
204
|
+
deleted_by : null
|
|
205
|
+
}};
|
|
206
206
|
const hash = peer.wallet.sign(JSON.stringify(signature) + nonce);
|
|
207
207
|
await peer.base.append({type: 'msg', value: signature, hash : hash, nonce: nonce });
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
export async function setChatStatus(input, peer){
|
|
211
|
-
const splitted = input.
|
|
212
|
-
const value = splitted
|
|
211
|
+
const splitted = yargs(input).parse();
|
|
212
|
+
const value = splitted.enabled === 1 ? 'on' : 'off';
|
|
213
213
|
const nonce = Math.random() + '-' + Date.now();
|
|
214
214
|
if(value !== 'on' && value !== 'off') throw new Error('setChatStatus: use on and off values.');
|
|
215
215
|
const msg = { type: 'setChatStatus', key: value }
|
|
@@ -221,8 +221,8 @@ export async function setChatStatus(input, peer){
|
|
|
221
221
|
}
|
|
222
222
|
|
|
223
223
|
export async function setAutoAddWriters(input, peer){
|
|
224
|
-
const splitted = input.
|
|
225
|
-
const value = splitted
|
|
224
|
+
const splitted = yargs(input).parse();
|
|
225
|
+
const value = splitted.enabled === 1 ? 'on' : 'off';
|
|
226
226
|
const nonce = Math.random() + '-' + Date.now();
|
|
227
227
|
if(value !== 'on' && value !== 'off') throw new Error('setAutoAddWriters: use on and off values.');
|
|
228
228
|
const msg = { type: 'setAutoAddWriters', key: value }
|
|
@@ -234,27 +234,28 @@ export async function setAutoAddWriters(input, peer){
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
export async function addAdmin(input, peer){
|
|
237
|
-
const splitted = input.
|
|
238
|
-
const publicKey = splitted
|
|
237
|
+
const splitted = yargs(input).parse();
|
|
238
|
+
const publicKey = splitted.address;
|
|
239
239
|
await peer.base.append({ type: 'addAdmin', key: publicKey });
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
export async function addWriter(input, peer){
|
|
243
243
|
const splitted = input.split(' ');
|
|
244
|
+
const parsed = yargs(input).parse();
|
|
244
245
|
const nonce = Math.random() + '-' + Date.now();
|
|
245
246
|
if(splitted[0] === '/add_indexer'){
|
|
246
|
-
const msg = { type: 'addIndexer', key:
|
|
247
|
+
const msg = { type: 'addIndexer', key: parsed.key }
|
|
247
248
|
const signature = {
|
|
248
249
|
msg: msg
|
|
249
250
|
};
|
|
250
251
|
const hash = peer.wallet.sign(JSON.stringify(msg) + nonce);
|
|
251
|
-
peer.emit('announce', { op : 'append_writer', type: 'addIndexer', key:
|
|
252
|
+
peer.emit('announce', { op : 'append_writer', type: 'addIndexer', key: parsed.key, value: signature, hash: hash, nonce: nonce });
|
|
252
253
|
} else if(splitted[0] === '/add_writer') {
|
|
253
|
-
const msg = { type: 'addWriter', key:
|
|
254
|
+
const msg = { type: 'addWriter', key: parsed.key }
|
|
254
255
|
const signature = {
|
|
255
256
|
msg: msg
|
|
256
257
|
};
|
|
257
258
|
const hash = peer.wallet.sign(JSON.stringify(msg) + nonce);
|
|
258
|
-
peer.emit('announce', { op : 'append_writer', type: 'addWriter', key:
|
|
259
|
+
peer.emit('announce', { op : 'append_writer', type: 'addWriter', key: parsed.key, value: signature, hash: hash, nonce : nonce });
|
|
259
260
|
}
|
|
260
261
|
}
|
package/src/index.js
CHANGED
|
@@ -611,20 +611,28 @@ export class Peer extends ReadyResource {
|
|
|
611
611
|
});
|
|
612
612
|
|
|
613
613
|
console.log('Node started. Available commands:');
|
|
614
|
-
console.log('
|
|
615
|
-
console.log('-
|
|
616
|
-
console.log('- /
|
|
617
|
-
console.log('- /
|
|
618
|
-
console.log('- /
|
|
619
|
-
console.log('- /
|
|
620
|
-
console.log('
|
|
621
|
-
console.log('-
|
|
622
|
-
console.log('- /
|
|
623
|
-
console.log('- /
|
|
624
|
-
console.log('- /
|
|
625
|
-
console.log('- /
|
|
626
|
-
console.log('- /
|
|
627
|
-
console.log('- /
|
|
614
|
+
console.log(' ');
|
|
615
|
+
console.log('- Setup Commands:');
|
|
616
|
+
console.log('- /add_admin | Works only once and only on bootstrap node! Enter a wallet address to assign admin rights: \'/add_admin --address "<address>"\'.');
|
|
617
|
+
console.log('- /add_indexer | Only admin. Enter a peer writer key to get included as indexer for this network: \'/add_indexer --key "<key>"\'.');
|
|
618
|
+
console.log('- /add_writer | Only admin. Enter a peer writer key to get included as writer for this network: \'/add_writer --key "<key>"\'.');
|
|
619
|
+
console.log('- /set_auto_add_writers | Only admin. Allow any peer to join as writer automatically: \'/set_auto_add_writers --enabled 1\'');
|
|
620
|
+
console.log(' ');
|
|
621
|
+
console.log('- Chat Commands:');
|
|
622
|
+
console.log('- /set_chat_status | Only admin. Enable/disable the built-in chat system: \'/set_chat_status --enabled 1\'. The chat system is disabled by default.');
|
|
623
|
+
console.log('- /post | Post a message: \'/post --message "Hello"\'. Chat must be enabled.');
|
|
624
|
+
console.log('- /set_nick | Change your nickname like this \'/set_nick --nick "Peter"\'. Chat must be enabled. Can be edited by admin and mods using the optional --user <address> flag.');
|
|
625
|
+
console.log('- /mute_status | Only admin and mods. Mute or unmute a user by their address: \'/mute_status --user "<address>" --muted 1\'.');
|
|
626
|
+
console.log('- /set_mod | Only admin. Set a user as mod: \'/set_mod --user "<address>" --mod 1\'.');
|
|
627
|
+
console.log('- /delete_message | Delete a messages: \'/delete_message --id 1\'. Chat must be enabled.');
|
|
628
|
+
console.log('- /enable_whitelist | Only admin. Enable/disable chat whitelists: \'/enable_whitelist --enabled 1\'.');
|
|
629
|
+
console.log('- /set_whitelist_status | Only admin. Add/remove users to/from the chat whitelist: \'/set_whitelist_status --user "<address>" --status 1\'.');
|
|
630
|
+
console.log(' ');
|
|
631
|
+
console.log('- System Commands:');
|
|
632
|
+
console.log('- /dag | check system properties such as writer key, DAG, etc.');
|
|
633
|
+
console.log('- /get_keys | prints your public and private keys. Be careful and never share your private key!');
|
|
634
|
+
console.log('- /exit | Exit the program');
|
|
635
|
+
|
|
628
636
|
this.protocol_instance.printOptions();
|
|
629
637
|
|
|
630
638
|
rl.on('line', async (input) => {
|
|
@@ -642,30 +650,34 @@ export class Peer extends ReadyResource {
|
|
|
642
650
|
console.log("Secret Key: ", this.wallet.secretKey);
|
|
643
651
|
break;
|
|
644
652
|
default:
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
653
|
+
try {
|
|
654
|
+
if (input.startsWith('/add_indexer') || input.startsWith('/add_writer')) {
|
|
655
|
+
await addWriter(input, this);
|
|
656
|
+
} else if (input.startsWith('/add_admin')) {
|
|
657
|
+
await addAdmin(input, this);
|
|
658
|
+
} else if (input.startsWith('/set_auto_add_writers')) {
|
|
659
|
+
await setAutoAddWriters(input, this);
|
|
660
|
+
} else if (input.startsWith('/set_chat_status')) {
|
|
661
|
+
await setChatStatus(input, this);
|
|
662
|
+
} else if (input.startsWith('/post')) {
|
|
663
|
+
await postMessage(input, this);
|
|
664
|
+
} else if (input.startsWith('/set_nick')) {
|
|
665
|
+
await setNick(input, this);
|
|
666
|
+
} else if (input.startsWith('/mute_status')) {
|
|
667
|
+
await muteStatus(input, this);
|
|
668
|
+
} else if (input.startsWith('/set_mod')) {
|
|
669
|
+
await setMod(input, this);
|
|
670
|
+
} else if (input.startsWith('/delete_message')) {
|
|
671
|
+
await deleteMessage(input, this);
|
|
672
|
+
} else if (input.startsWith('/enable_whitelist')) {
|
|
673
|
+
await enableWhitelist(input, this);
|
|
674
|
+
} else if (input.startsWith('/set_whitelist_status')) {
|
|
675
|
+
await setWhitelistStatus(input, this);
|
|
676
|
+
} else {
|
|
677
|
+
this.protocol_instance.execute(input);
|
|
678
|
+
}
|
|
679
|
+
} catch(e) {
|
|
680
|
+
console.log('Command failed:', e.message);
|
|
669
681
|
}
|
|
670
682
|
}
|
|
671
683
|
rl.prompt();
|