trac-msb 0.0.14 → 0.0.16
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/index.js +2 -39
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -20,7 +20,6 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
20
20
|
super();
|
|
21
21
|
this.STORES_DIRECTORY = options.stores_directory;
|
|
22
22
|
this.KEY_PAIR_PATH = `${this.STORES_DIRECTORY}${options.store_name}/db/keypair.json`
|
|
23
|
-
this.signingKeyPair = null;
|
|
24
23
|
this.store = new Corestore(this.STORES_DIRECTORY + options.store_name);
|
|
25
24
|
this.swarm = null;
|
|
26
25
|
this.tx = options.tx || null;
|
|
@@ -150,7 +149,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
150
149
|
parsedPreTx.w === _this.writerLocalKey &&
|
|
151
150
|
null === await _this.base.view.get(parsedPreTx.tx)
|
|
152
151
|
) {
|
|
153
|
-
const signature = crypto.sign(Buffer.from(parsedPreTx.tx, 'utf-8'), this.
|
|
152
|
+
const signature = crypto.sign(Buffer.from(parsedPreTx.tx, 'utf-8'), Buffer.from(this.wallet.secretKey, 'hex'));
|
|
154
153
|
const append_tx = {
|
|
155
154
|
op: 'post-tx',
|
|
156
155
|
tx: parsedPreTx.tx,
|
|
@@ -161,7 +160,7 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
161
160
|
ch: parsedPreTx.ch,
|
|
162
161
|
in: parsedPreTx.in,
|
|
163
162
|
ws: signature.toString('hex'),
|
|
164
|
-
wp: this.
|
|
163
|
+
wp: this.wallet.publicKey,
|
|
165
164
|
};
|
|
166
165
|
_this.tx_pool.push({ tx: parsedPreTx.tx, append_tx : append_tx });
|
|
167
166
|
}
|
|
@@ -328,42 +327,6 @@ export class MainSettlementBus extends ReadyResource {
|
|
|
328
327
|
rl.close();
|
|
329
328
|
return mnemonic;
|
|
330
329
|
}
|
|
331
|
-
|
|
332
|
-
async #initKeyPair() {
|
|
333
|
-
// TODO: User shouldn't be allowed to store it in unencrypted form. ASK for a password to encrypt it. ENCRYPT(HASH(PASSWORD,SALT),FILE)/DECRYPT(HASH(PASSWORD,SALT),ENCRYPTED_FILE)?
|
|
334
|
-
try {
|
|
335
|
-
// Check if the key file exists
|
|
336
|
-
if (fs.existsSync(this.KEY_PAIR_PATH)) {
|
|
337
|
-
const keyPair = JSON.parse(fs.readFileSync(this.KEY_PAIR_PATH));
|
|
338
|
-
this.signingKeyPair = {
|
|
339
|
-
publicKey: Buffer.from(keyPair.publicKey, 'hex'),
|
|
340
|
-
secretKey: Buffer.from(keyPair.secretKey, 'hex')
|
|
341
|
-
}
|
|
342
|
-
} else {
|
|
343
|
-
console.log("Key file was not found. How do you wish to proceed?");
|
|
344
|
-
const mnemonic = await this.#getMnemonicInteractiveMode();
|
|
345
|
-
|
|
346
|
-
const generatedSecrets = this.wallet.generateKeyPair(mnemonic);
|
|
347
|
-
const keyPair = {
|
|
348
|
-
publicKey: Buffer.from(generatedSecrets.publicKey).toString('hex'),
|
|
349
|
-
secretKey: Buffer.from(generatedSecrets.secretKey).toString('hex')
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
//TODO: ASK USER TO WRITE FIRST SECOND AND LAST WORD OR SOMETHING SIMILAR TO CONFIRM THEY HAVE WRITTEN IT DOWN
|
|
353
|
-
if (!mnemonic) console.log("This is your mnemonic:\n", generatedSecrets.mnemonic, "\nPlease back it up in a safe location")
|
|
354
|
-
|
|
355
|
-
fs.writeFileSync(this.KEY_PAIR_PATH, JSON.stringify(keyPair));
|
|
356
|
-
this.signingKeyPair = {
|
|
357
|
-
publicKey: generatedSecrets.publicKey,
|
|
358
|
-
secretKey: generatedSecrets.secretKey,
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
console.log("DEBUG: Key pair generated and stored in", this.KEY_PAIR_PATH);
|
|
362
|
-
}
|
|
363
|
-
} catch (err) {
|
|
364
|
-
console.error(err);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
330
|
}
|
|
368
331
|
|
|
369
332
|
function noop() { }
|