urbit / urbit-key-generation

Key derivation and HD wallet generation functions for Urbit
MIT License
15 stars 8 forks source link

Derive +code from master ticket #64

Closed vvisigoth closed 2 years ago

vvisigoth commented 5 years ago

Should implement a function that emulates

https://github.com/urbit/arvo/blob/master/sys/vane/jael.hoon#L2292-L2304

And derives a ship's code from the master ticket. This will allow sign in w/ Bridge (via JSON webtoken or similar)

joemfb commented 5 years ago

Note the XX there, we should review and standardize how that code is derived. We might also want additional features, like the ability to rotate +code without rekeying.

jtobin commented 2 years ago

I'm going to handle this together with #101.

Faolain commented 2 years ago

Hey @jtobin I tried using generateCode() for a ship of mine that's in a strange state (I can't access dojo because on Port it says the ship is not on, but I can |hi it from other ships). I have the master ticket & ownership seed but I can't seem to quite get the +code correct in order to access landscape via my browser (which unrelated is still somehow present despite Port not loading). I tried sanity checking with another ship that I booted and using that master key as well the code output below is different the the Port provided access key/+code. I was wondering what parameters I'm using incorrectly in this script or how I'm using generateCode() incorrectly, really appreciate it!

const VALID_PATH = "m/44'/60'/0'/0/0";

let node = deriveNodeKeys(mnemonic, VALID_PATH);
// Checking here to make sure the address in the node matches what I have on my master ticket paper to confirm that the mnemonic is in fact correct
console.log("node", node);

// Steps start here
let seed = deriveNetworkSeed(mnemonic);
let keys = deriveNetworkKeys(seed);
let code = generateCode(keys);

// Provided code below different than what is given by Port or dojo +code
console.log("code", code);

Probably just using this wrong as the access key from the bridge works unsure if documentation is needed for use or if it's self explanatory for others.

jtobin commented 2 years ago

Linking #103.

jtobin commented 2 years ago

I have the master ticket & ownership seed but I can't seem to quite get the +code correct

@Faolain sorry for my slow response here, was traveling and socializing and such.

If you have the master ticket then you should be able to derive the code. It looks like you might be missing a required revision parameter when calling deriveNetworkSeed; this will correspond to the life of the ship on chain, which can be checked via etherscan here using getKeyRevisionNumber.

Try calling deriveNetworkSeed(mnemonic, null, revision) with revision being the appropriate life and let me know if it works / you get the expected result. You can also DM me on Urbit for help.