├── keys ├── node └── wallet ├── .gitignore ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── lib └── constants.js ├── zmsg ├── zmsgread ├── README.md ├── zmsgpull └── zmsg-broadcast /keys/node: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /keys/wallet: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | 3 | -------------------------------------------------------------------------------- /1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/publiusfederalist/zmsg/HEAD/1.png -------------------------------------------------------------------------------- /2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/publiusfederalist/zmsg/HEAD/2.png -------------------------------------------------------------------------------- /3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/publiusfederalist/zmsg/HEAD/3.png -------------------------------------------------------------------------------- /4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/publiusfederalist/zmsg/HEAD/4.png -------------------------------------------------------------------------------- /lib/constants.js: -------------------------------------------------------------------------------- 1 | const MAX_TXT = 255; 2 | const MAGIC_ZMSG = "zmsg:"; 3 | const MAGIC_ZMSG_LENGTH = MAGIC_ZMSG.length; 4 | const MAGIC_ZOOKO = "zooko:"; 5 | const MAGIC_ZOOKO_LENGTH = MAGIC_ZOOKO.length; 6 | const POST_PAGE_LIMIT = 50; 7 | const ZMSG_START = 102262; 8 | 9 | module.exports = { 10 | MAX_TXT: MAX_TXT, 11 | MAGIC_ZMSG: MAGIC_ZMSG, 12 | MAGIC_ZMSG_LENGTH: MAGIC_ZMSG_LENGTH, 13 | MAGIC_ZOOKO: MAGIC_ZOOKO, 14 | MAGIC_ZOOKO_LENGTH: MAGIC_ZOOKO_LENGTH, 15 | POST_PAGE_LIMIT: POST_PAGE_LIMIT, 16 | ZMSG_START: ZMSG_START 17 | }; 18 | -------------------------------------------------------------------------------- /zmsg: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const {encrypt, decrypt} = require("hsencrypt"); 3 | const {WalletClient, NodeClient} = require('hs-client'); 4 | const {Network} = require('hsd'); 5 | const fs = require('fs'); 6 | const network = Network.get('main'); 7 | const ConsoleIO = new (require("consoleinout"))(console); 8 | 9 | const nodeOptions = { 10 | network: network.type, 11 | port: network.rpcPort, 12 | apiKey: fs.readFileSync("keys/node").toString().trim() 13 | } 14 | const walletOptions = { 15 | port: network.walletPort, 16 | apiKey: fs.readFileSync("keys/wallet").toString().trim() 17 | } 18 | const nodeClient = new NodeClient(nodeOptions); 19 | const _walletClient = new WalletClient(walletOptions); 20 | let walletClient; 21 | 22 | (async function() { 23 | const argv=process.argv; 24 | const argc=argv.length; 25 | 26 | if(argc!=6 && argc!=7) { 27 | console.log("Encrypt Usage: ",argv[1],"","","","\"\""); 28 | console.log(""); 29 | console.log("Decrypt Usage: ",argv[1],"","","","\"\"", "\"d\""); 30 | process.exit(); 31 | } 32 | walletClient = _walletClient.wallet(argv[2]); 33 | if(!walletClient) { 34 | console.log("Wallet ",argv[2],"not found"); 35 | process.exit(0); 36 | } 37 | 38 | console.output("Enter Password: "); 39 | const password = await console.input(true); 40 | 41 | if(argc==7) { 42 | let decrypted=await decrypt(walletClient, nodeClient, password, argv[4], argv[3], argv[5]); 43 | console.log("Decrypted: ",decrypted); 44 | process.exit(0); 45 | } 46 | else if(argc==6) { 47 | let encrypted=await encrypt(walletClient, nodeClient, password, argv[3], argv[4], argv[5]); 48 | console.log(encrypted); 49 | process.exit(0); 50 | } 51 | })() 52 | 53 | -------------------------------------------------------------------------------- /zmsgread: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const {encrypt, decrypt} = require("hsencrypt"); 3 | const {WalletClient, NodeClient} = require('hs-client'); 4 | const {Network} = require('hsd'); 5 | const fs = require('fs'); 6 | const network = Network.get('main'); 7 | const ConsoleIO = new (require("consoleinout"))(console); 8 | const constants = require('./lib/constants.js'); 9 | 10 | 11 | const argv = process.argv; 12 | const argc = process.argv.length; 13 | 14 | const nodeOptions = { 15 | network: network.type, 16 | port: network.rpcPort, 17 | apiKey: fs.readFileSync("keys/node").toString().trim() 18 | } 19 | const walletOptions = { 20 | port: network.walletPort, 21 | apiKey: fs.readFileSync("keys/wallet").toString().trim() 22 | } 23 | const nodeClient = new NodeClient(nodeOptions); 24 | const _walletClient = new WalletClient(walletOptions); 25 | let walletClient; 26 | 27 | if(argc != 4 && argc != 5) { 28 | console.log("Usage: ",argv[1],"",""); 29 | process.exit(0); 30 | } 31 | 32 | (async function() { 33 | 34 | walletClient = _walletClient.wallet(argv[2]); 35 | if(!walletClient) { 36 | console.log("Wallet ",argv[2],"not found"); 37 | process.exit(0); 38 | } 39 | 40 | console.output("Enter Password: "); 41 | const password = await console.input(true); 42 | 43 | let posts = fs.readFileSync(__dirname+"/.posts").toString().split("\n"); 44 | if(argc==4) { 45 | for(let x=0;x keys/node 45 | echo "somewalletkey" > keys/wallet 46 | ``` 47 | You can get these with hsd. Make sure hsd has all the index-tx, index-address and other options enabled. 48 | 49 | 4. Run commands! 50 | 51 | ## Commands 52 | 53 | #### Encryption 54 | ``` 55 | zmsg "" 56 | ``` 57 | 58 | #### Decryption 59 | ``` 60 | zmsg d 61 | ```` 62 | 63 | #### Blockchain 64 | 65 | You can also use `zmsg-broadcast` which will actually write this to the blockchain. 66 | 67 | ## Copyright 68 | 69 | Copyright (c) 2022 Publius Federalist 70 | 71 | All Rights Reserved 72 | 73 | MIT LICENSED. 74 | 75 | -------------------------------------------------------------------------------- /zmsgpull: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const {NodeClient} = require('hs-client'); 3 | const {Network} = require('hsd'); 4 | const {Resource} = require('hsd/lib/dns/resource'); 5 | const fs = require('fs'); 6 | const constants = require("./lib/constants.js"); 7 | const prepend = require('prepend'); 8 | 9 | const network = Network.get('main'); 10 | const nodeOptions = { 11 | network: network.type, 12 | port: network.rpcPort, 13 | apiKey: fs.readFileSync(__dirname+"/keys/node").toString().trim() 14 | }; 15 | const nodeClient = new NodeClient(nodeOptions); 16 | 17 | // Aliases 18 | async function getBlock(height) { return await nodeClient.getBlock(height) } 19 | async function getBlockTx(txh) { return await nodeClient.getTX(txh) } 20 | async function getNameByHash(hash) { return await nodeClient.execute('getnamebyhash', [ hash ]) } 21 | async function getHeight() { return await nodeClient.execute('getblockcount') } 22 | 23 | // Functions 24 | async function getUpdates(block) { 25 | let rupdates = []; 26 | for(let x=0;x { 56 | let x; 57 | if(fs.existsSync(__dirname+"/.lastBlock")) 58 | x = parseInt(fs.readFileSync(__dirname+"/.lastBlock")); 59 | else 60 | x = constants.ZMSG_START; 61 | if(!x) 62 | x = constants.ZMSG_START; 63 | 64 | const height = await getHeight(); 65 | 66 | for(;x<=height;x++) { 67 | console.log(x); 68 | let block = await getBlock(x); 69 | let updates = await getUpdates(block); 70 | if(updates.length>0) { 71 | for(let y=0;y {}); 75 | } 76 | } 77 | } 78 | } 79 | fs.writeFileSync(__dirname+"/.lastBlock",x.toString()); 80 | })(); 81 | -------------------------------------------------------------------------------- /zmsg-broadcast: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const {encrypt, decrypt} = require("hsencrypt"); 3 | const {WalletClient, NodeClient} = require('hs-client'); 4 | const {Network} = require('hsd'); 5 | const fs = require('fs'); 6 | const network = Network.get('main'); 7 | const ConsoleIO = new (require("consoleinout"))(console); 8 | const constants = require("./lib/constants.js"); 9 | 10 | const nodeOptions = { 11 | network: network.type, 12 | port: network.rpcPort, 13 | apiKey: fs.readFileSync("keys/node").toString().trim() 14 | } 15 | const walletOptions = { 16 | port: network.walletPort, 17 | apiKey: fs.readFileSync("keys/wallet").toString().trim() 18 | } 19 | const nodeClient = new NodeClient(nodeOptions); 20 | const _walletClient = new WalletClient(walletOptions); 21 | let walletClient; 22 | 23 | (async function() { 24 | const argv=process.argv; 25 | const argc=argv.length; 26 | 27 | if(argc!=6 && argc!=7) { 28 | console.log("Encrypt Usage: ",argv[1],"","","","\"\""); 29 | console.log(""); 30 | console.log("Decrypt Usage: ",argv[1],"","","","\"\"", "\"d\""); 31 | process.exit(); 32 | } 33 | walletClient = _walletClient.wallet(argv[2]); 34 | if(!walletClient) { 35 | console.log("Wallet ",argv[2],"not found"); 36 | process.exit(0); 37 | } 38 | 39 | console.output("Enter Password: "); 40 | const password = await console.input(true); 41 | 42 | let bName,bMessage; 43 | if(argc==7) { 44 | let decrypted=await decrypt(walletClient, nodeClient, password, argv[4], argv[3], argv[5]); 45 | console.log("Decrypted: ",decrypted); 46 | process.exit(0); 47 | } 48 | else if(argc==6) { 49 | let encrypted=await encrypt(walletClient, nodeClient, password, argv[3], argv[4], argv[5]); 50 | console.log(encrypted); 51 | bName = argv[3]; 52 | bMessage = encrypted; 53 | } 54 | const records = await writeZmsg(bName,bMessage); 55 | const options = {passphrase:password,name:bName,broadcast:true,sign:true,data:{records: records}}; 56 | if(!options.data.records) { 57 | console.log("zmsg broadcast failed"); 58 | process.exit(0); 59 | } 60 | let result; 61 | try { 62 | result = await walletClient.createUpdate(options); 63 | } catch(e) { 64 | console.log("zmsg failed (incorrect password or need to wait until next block?)"); 65 | process.exit(0); 66 | } 67 | console.log(result); 68 | process.exit(0); 69 | })() 70 | 71 | async function getNameResource(name) { 72 | let rr = await nodeClient.execute('getnameresource', [name]) 73 | if(rr) 74 | return rr.records; 75 | return null; 76 | } 77 | async function _writeZmsg(name,message) { 78 | if(message.length+constants.MAX_TXT>constants.MAGIC_ZMSG) 79 | return null; 80 | let records = await getNameResource(name); 81 | let returnRecord = []; 82 | if(records) { 83 | for(let x=0;x