Created
November 25, 2020 00:34
-
-
Save kennyrowe/78fa18951c55dc7258fd71bca8255d31 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Get managment seed and login code given a patp and master tikets | |
// -s ship_name -t ticket | |
// To-Do: Make installable by NPM add help | |
kg = require('urbit-key-generation'); | |
ob = require('urbit-ob'); | |
jssha256 = require('js-sha256'); | |
var fs = require('fs') | |
NETWORK_KEY_CURVE_PARAMETER = '42'; | |
var args = process.argv.slice(2); | |
shipIndex = args.indexOf('-s'); | |
ticketIndex = args.indexOf('-t') | |
nameIndex = args.indexOf('-n') | |
name = args[nameIndex + 1]; | |
config = {shipName: args[shipIndex + 1], ship: ob.patp2dec(args[shipIndex + 1]), ticket: args[ticketIndex + 1], boot: true} | |
function hex2buf(hex) { | |
return Buffer.from(hex, 'hex').reverse(); | |
} | |
function shax(buf) { | |
const hashed = jssha256.sha256.array(buf); | |
return Buffer.from(hashed); | |
} | |
function shas(buf, salt) { | |
return shax(xor(salt, shax(buf))); | |
} | |
function shaf(buf, salt) { | |
const result = shas(buf, salt); | |
const halfway = result.length / 2; | |
const front = result.slice(0, halfway); | |
const back = result.slice(halfway, result.length); | |
return xor(front, back); | |
} | |
function xor(a, b) { | |
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { | |
console.log('a', a); | |
console.log('b', b); | |
throw new Error('only xor buffers!'); | |
} | |
const length = Math.max(a.byteLength, b.byteLength); | |
const result = new Uint8Array(length); | |
for (let i = 0; i < length; i++) { | |
result[i] = a[i] ^ b[i]; | |
} | |
return result; | |
} | |
function buf2hex(buf) { | |
return Buffer.from(buf) | |
.reverse() | |
.toString('hex'); | |
} | |
function getSeed(ticket, ship){ | |
wallet = kg.generateWallet({ticket: ticket, ship: ob.patp2dec(ship), boot: true}); | |
wallet.then(function(data){seed = data.management.seed}) | |
} | |
function createRing(pair){ | |
return pair.crypt.private + pair.auth.private + NETWORK_KEY_CURVE_PARAMETER; | |
} | |
function generateCode(pair) { | |
const ring = hex2buf(createRing(pair)); | |
const salt = hex2buf('73736170'); // salt is the noun %pass | |
const hash = shax(ring); | |
const result = shaf(hash, salt); | |
const half = result.slice(0, result.length / 2); | |
return ob.hex2patp(buf2hex(half)).slice(1); | |
}; | |
function setWallet(config){ | |
wallet = kg.generateWallet(config); | |
wallet.then(function(data){ | |
//config.pair = data.network.keys; | |
config.managementSeed = data.management.seed; | |
config.login = generateCode(data.network.keys); | |
process.stdout.write( | |
"Ship: " + config.shipName + "\n" + | |
"Login: " + config.login + "\n" + | |
"Link: " + "https://" + config.shipName.substring(1,14) + ".tlon.network" + "\n" + | |
"Management Seed: " + config.managementSeed + "\n" | |
); | |
html = makeHTML(); | |
fs.writeFile('yourUrbitIsReady.html', html, function (err) { | |
if (err) return console.log(err); | |
console.log('Email text > file:///home/kenny/yourUrbitIsReady.html'); | |
}); | |
}) | |
} | |
function setShip(ship){ | |
config.ticket = ship.ticket; | |
config.ship = ob.patp2dec(ship.shipName); | |
config.shipName = ship.shipName; | |
} | |
setWallet(config); | |
function makeHTML(){ | |
p1 = '<p ><span>Hey ' | |
p2 = name | |
p3 = ', your urbit is ready!<br /><br /></span><span>Go to the following address to access it: <br /></span><span><a href="' | |
p4 = "https://" + config.shipName.substring(1,14) + ".tlon.network" | |
p5 ='" target="_blank">' | |
p6 = "https://" + config.shipName.substring(1,14) + ".tlon.network" | |
p7 = '</a></span></p><p ><span>Use the following code to log in:<br /></span><span><b><span>' | |
p8 = config.login | |
p9 = '</span></b></span></p><p ><span>If you’re having a hard day, or need help in any way, email </span><a href="mailto:support@tlon.io" target="_blank"><span>support@tlon.io</span></a><span>. We’re here for you. If you want to learn more about Urbit, check out </span><a href="https://urbit.org/" target="_blank"><span>http://urbit.org</span></a><span>!<br /><br /></span><span><span>You can use the documents attached to this email to manager your Urbit-ID at <a href="https://bridge.urbit.org/" target="_blank">https://bridge.urbit.org</a><br /><br /></span></span><span style="color: #888888;">-Kenny<br /></span><span style="color: #888888;">~sicdev-pilnup</span></p>' | |
text = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 | |
return text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment