bm-create-enc-payload/index.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-11-02 22:16:01 +01:00
const objects = require('bitmessage').objects,
Address = require('bitmessage').Address;
const { spawn } = require('child_process');
const zmq = require('zeromq');
2022-12-07 09:57:01 +01:00
(async () => {
2023-11-02 22:16:01 +01: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: 300000, killSignal: 'SIGQUIT'}
).stderr.on('data', (data) => {
console.log(`${data}`);
2022-12-07 09:57:01 +01:00
});
2023-11-02 22:16:01 +01:00
const sender = Address.fromRandom(),
recipient = Address.fromPassphrase('test');
console.log('sender:', sender.encode());
console.log('recipient:', recipient.encode());
2022-12-07 09:57:01 +01:00
2023-11-02 22:16:01 +01:00
var msg = await objects.msg.encodePayloadAsync({
ttl: 1800,
from: sender,
to: recipient,
message: 'The quick brown fox jumps over the lazy dog.',
subject: 'hello',
encoding: 2,
friend: true
});
console.log('msg:', msg.toString('hex'));
2022-12-07 09:57:01 +01:00
2023-11-02 22:16:01 +01:00
console.log('Sending the msg');
sock.send(Buffer.concat([
Buffer.from('msg', 'ascii'), Buffer.from('00', 'hex'), msg
]));
2022-12-07 09:57:01 +01:00
2023-11-02 22:16:01 +01:00
})();