urbit / urbit-key-generation

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

shard() #8

Closed g-a-v-i-n closed 5 years ago

g-a-v-i-n commented 5 years ago

We need a helper function that converts a wallet to a sharded wallet. I propose we add this to keygen-js. The output has downstream dependancies like paper-wallet-js.

Input

1. reconstructNum Number of shards needed to reconstruct a working key or seed. int

2. shardNum Number of shards to make. int

3. wallet An Urbit hd wallet. object

4. path ie: 'owner.seed', a path to the target property we want to shard. string

Output

A full wallet, where the the target is transformed from a string to and array of strings

Usage

import { shard, fullWalletFromSeed } from 'urbit-keygen'

const wallet = fullWalletFromSeed(config)
const shardedWallet = shard(2, 3, wallet, 'owner.seed')

To make this easy we can use lodash's get and set which accept string object property paths. This means adding lodash as a dep.

Other ideas:

shard() could accept a full wallet with the owner.seed path built in. IMO not ideal because it is overly specific.

import { shard, fullWalletFromSeed } from 'urbit-keygen'

const wallet = fullWalletFromSeed(config)
const shardedWallet = shard(2, 3, wallet)

or only a value to shard.

const wallet = fullWalletFromSeed(config)

const shardedSeed = shard(2, 3, wallet.owner.seed)

const shardedWallet = {
   ...wallet,
   owner: {
      ...wallet.owner,
      seed: ['aDIzbzQ4d2dkZmlsdTJnM29yNzg', 'cTNzZnNkZ3NmZ2RmaGRmaA', ...],
   },
}

This isn't exactly ideal because it means the wallet has to be manually reconstructed.

g-a-v-i-n commented 5 years ago

https://github.com/urbit/keygen-js/pull/10

g-a-v-i-n commented 5 years ago

@jtobin Update: I was under the impression that wallet.owner.seed was in fact the entropy ticket, but it is not. Sorry about that!

g-a-v-i-n commented 5 years ago

@jtobin Ok, finally figured this out once and for all (fingers crossed).

Since master tickets will now be included in the keygen-js output, shard() should be a function that can be called by setting a config prop in the argument to the shard function should be an internal option set by an argument in the config passed tofullWalletFromTicket()` and fullWalletFromSeed().

jtobin commented 5 years ago

:+1: :+1:

jtobin commented 5 years ago

@gavinpatkinson Is there any reason to keep fullWalletFromSeed around?

I'm inclined to just axe it entirely, since we always want to generate wallets from tickets.

jtobin commented 5 years ago

(I reckoned the easiest thing to do here was just remove it -- we can put it back in afterwards if it's needed, e.g. for internal wallet gen.)