bm-create-enc-payload/index.js

69 lines
2.5 KiB
JavaScript
Raw Normal View History

2022-12-07 09:57:01 +01:00
var messages = require('bitmessage').messages;
var objects = require('bitmessage').objects;
var Address = require('bitmessage').Address;
var TcpTransport = require('bitmessage-transports').TcpTransport;
var eccrypto = require("eccrypto");
(async () => {
const from = Address.fromPassphrase('loremipsum1');
2022-12-23 03:55:26 +01:00
console.log('[from]', from.encode());
console.log('[from sign priv key]', from.signPrivateKey.toString('hex'));
console.log('[from version]', from.version);
console.log('[from stream]', from.stream);
console.log('[from behaviour]', from.behavior);
2022-12-07 09:57:01 +01:00
const toAddr = Address.fromPassphrase('gru');
2022-12-23 03:55:26 +01:00
console.log('[toAddr]', toAddr.encode());
console.log('[toAddr enc pub key]', toAddr.encPublicKey.toString('hex'));
console.log('[toAddr version]', toAddr.version);
console.log('[toAddr stream]', toAddr.stream);
console.log('[toAddr ripe]', toAddr.ripe);
const encodedMsg = await objects.msg.encodePayloadAsync({
2022-12-07 09:57:01 +01:00
ttl: 1800,
2022-12-23 03:55:26 +01:00
from: from,
2022-12-07 09:57:01 +01:00
to: toAddr,
message: 'hey there!',
2022-12-23 03:55:26 +01:00
subject: 'Lorem Ipsum',
encoding: 2,
friend: true,
skipPow: true,
});
const strippedMsg = encodedMsg.slice(8);
console.log('[check messages]', strippedMsg);
console.log('[check messages]', strippedMsg.toString('hex'));
var d = await objects.msg.decodePayloadAsync(encodedMsg, {
2022-12-07 09:57:01 +01:00
skipPow: true,
2022-12-23 03:55:26 +01:00
identities: toAddr,
2022-12-07 09:57:01 +01:00
});
2022-12-23 03:55:26 +01:00
console.log('[decoded]', d.message);
2022-12-07 09:57:01 +01:00
// const encPublicKey = '04a60f6cd97ecd16768215ef059ccfbb1840b736bcdb0763872ddfeef4c417d2ec8439383ce68de9a2b30ad44e9f0e56a13fc2895a6e41f7cf3757e46181d32dd0';
// const encPrivateKey = '2cb5ae4e8cf8c71d1221f5c6c46810b448207cacedd86cc52219c3f107048c10';
// const dec = await objects.msg.decPayloadTest(encPrivateKey, e);
// console.log('[dec]', dec);
// var encObj = encrypted.decode(buf);
// resolve(eccrypto.decrypt(privateKey, encObj));
})();
// var tcp = new TcpTransport({
// dnsSeeds: [['bootstrap8444.bitmessage.org', 8444]],
// });
// tcp.bootstrap().then(function (nodes) {
// var remoteHost = nodes[0][0];
// var remotePort = nodes[0][1];
// console.log('Connecting to', nodes[0]);
// tcp.connect(remotePort, remoteHost);
// });
// tcp.on('established', function (version) {
// console.log('Connection established to', version.userAgent);
// tcp.on('message', function (command, payload) {
// console.log('Got new', command, 'message');
// var decoded;
// if (command === 'addr') {
// decoded = messages.addr.decodePayload(payload);
// console.log('Got', decoded.addrs.length, 'node addresses');
// }
// });
// });