up8-ticket

Securely generate UP8-compatible, @q-encoded master tickets.
Log | Files | Refs | README | LICENSE

commit 09b21967baf45b6d682d95d0e4ba2b255727fd0e
parent c0c5d77ce18c1ed8302c861726f838b60d85c92d
Author: Jared Tobin <jared@jtobin.io>
Date:   Wed, 16 Sep 2020 21:53:36 -0230

release: v0.1.1

Diffstat:
MREADME.md | 9+++++++++
Mpackage.json | 2+-
Msrc/index.js | 28++++++++++++++++++++++++++--
3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md @@ -15,4 +15,13 @@ $ node --experimental-repl-await '~wisbyl-tarfes-biltug-datmyr-rigsyp-ribryc-nocmyr-bilres-mipset-patsut-todbur-foptev-lorfer-famtux-loppes-mismug-tobdyl-hopnes-lophul-tapdus-habtuc-ragseg-dossev-ramneb' ``` +If you're paranoid, you can use the `gen_custom` function to supply an +additional custom buffer that will be XOR'd in with the generated entropy: + +``` +> let paranoia = await tg.gen(384, Buffer.from("a very random string")) +> paranoia +'~dolhes-parmes-tagnev-fablug-pagwyn-dopwel-ripnys-hardut-batnym-ridreb-finmec-mistes-figweg-labled-tocbet-bidryt-wolpub-filtev-tappeg-fassyt-tonred-savruc-lisred-tidlec' +``` + [wgen]: https://github.com/urbit/urbit-wallet-generator diff --git a/package.json b/package.json @@ -1,6 +1,6 @@ { "name": "master-ticket-generator", - "version": "0.1.0", + "version": "0.1.1", "description": "Generate master ticket-length @q values", "main": "index.js", "scripts": { diff --git a/src/index.js b/src/index.js @@ -4,9 +4,31 @@ const chunk = require('lodash.chunk') const flatMap = require('lodash.flatmap') const zipWith = require('lodash.zipwith') +// generate a @q of the desired bitlength const gen = bits => { const bytes = bits / 8 const some = crypto.rng(bytes) + const prng = new more.Generator() + + return new Promise((resolve, reject) => { + prng.generate(bits, result => { + const chunked = chunk(result, 2) + const desired = chunked.slice(0, bytes) // only take required entropy + const more = flatMap(desired, arr => arr[0] ^ arr[1]) + const entropy = zipWith(some, more, (x, y) => x ^ y) + const buf = Buffer.from(entropy) + const patq = ob.hex2patq(buf.toString('hex')) + resolve(patq) + reject("entropy generation failed") + }) + }) +} + +// generate a @q of the desired bitlength; the second argument should be a +// Buffer that will be XOR'd with the generated entropy +const gen_custom = (bits, addl) => { + const bytes = bits / 8 + const some = crypto.rng(bytes) const prng = new more.Generator() @@ -15,7 +37,8 @@ const gen = bits => { const chunked = chunk(result, 2) const desired = chunked.slice(0, bytes) // only take required entropy const more = flatMap(desired, arr => arr[0] ^ arr[1]) - const entropy = zipWith(some, more, (x, y) => x ^ y) + const moar = zipWith(some, more, (x, y) => x ^ y) + const entropy = zipWith(moar, addl, (x, y) => x ^ y) const buf = Buffer.from(entropy) const patq = ob.hex2patq(buf.toString('hex')) resolve(patq) @@ -25,5 +48,6 @@ const gen = bits => { } module.exports = { - gen: gen + gen, + gen_custom }