bm-create-enc-payload/index.js

43 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2024-03-20 16:18:12 +00:00
// Send newly generated message via a MiNode process running in background
2023-11-02 21:16:01 +00:00
const objects = require('bitmessage').objects,
Address = require('bitmessage').Address;
const { spawn } = require('child_process');
const zmq = require('zeromq');
2022-12-07 08:57:01 +00:00
(async () => {
2023-11-02 21:16:01 +00:00
const sock = zmq.socket('pub');
sock.bindSync('tcp://127.0.0.1:5566');
console.log('Publisher bound to port 5566');
spawn(
'minode', ['--request-queue', 'tcp://127.0.0.1:5566'],
{timeout: 100000, killSignal: 'SIGTERM', detached: true, stdio: 'inherit'}
).on('exit', (c, s) => {
sock.close();
2022-12-07 08:57:01 +00:00
});
2023-11-02 21:16:01 +00:00
const sender = Address.fromRandom(),
recipient = Address.fromPassphrase('test');
console.log('sender:', sender.encode());
console.log('recipient:', recipient.encode());
2022-12-07 08:57:01 +00:00
2024-03-20 16:18:12 +00:00
objects.msg.encodePayloadAsync({
2023-11-02 21:16:01 +00:00
ttl: 1800,
from: sender,
to: recipient,
message: 'The quick brown fox jumps over the lazy dog.',
subject: 'hello',
2024-03-20 16:18:12 +00:00
encoding: 2
}).then(function (msg) {
console.log('msg:', msg.toString('hex'));
console.log('Sending the msg...');
sock.send(Buffer.concat([
Buffer.from('msg', 'ascii'), Buffer.from('00', 'hex'), msg
]));
2023-11-02 21:16:01 +00:00
});
2022-12-07 08:57:01 +00:00
2023-11-02 21:16:01 +00:00
})();