2import Maybe from 'folktale/maybe'
4import * as noun from '../nockjs/noun'
5import * as serial from '../nockjs/serial'
6import * as kg from '../../node_modules/urbit-key-generation/dist/index'
8import { BRIDGE_ERROR } from './error'
10 addressFromSecp256k1Public,
17 let hex = buf.reverse().toString('hex')
18 let n = new BN(hex, 'hex')
20 while (1 === n.cmpn(0)) {
38 String.fromCharCode(trans(b)) +
39 (( i && 0 === i % 5 ) ? '.' : '') + a,
44 const hex = serial.jam(seed).toString().slice(2)
45 const pad = hex.length % 2 === 0 ? hex : '0' + hex
46 return Buffer.from(pad, 'hex').reverse()
49const genKey = (networkSeed, point, revision) => {
50 const pair = kg.deriveNetworkKeys(networkSeed)
51 const bnsec = new BN(pair.crypt.private + pair.auth.private + '42', 'hex') // '42' is curve parameter
53 const sed = noun.dwim(
54 noun.Atom.fromString(point),
55 noun.Atom.fromInt(revision),
56 noun.Atom.fromString(bnsec.toString()),
63// 'next' refers to setting the next set of keys
64// if false, we use revision - 1
65const attemptSeedDerivation = async (next, args) => {
66 const { walletType, wallet, pointCursor, pointCache } = args
67 const { urbitWallet, authMnemonic } = args
71 // following code is intentionally verbose for sake of clarity
73 const walProxy = wallet.matchWith({
74 Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
76 throw BRIDGE_ERROR.MISSING_WALLET
80 const point = pointCursor.matchWith({
83 throw BRIDGE_ERROR.MISSING_POINT
90 : (() => { throw BRIDGE_ERROR.MISSING_POINT })()
94 ? parseInt(pointDetails.keyRevisionNumber)
95 : parseInt(pointDetails.keyRevisionNumber) - 1
97 let managementSeed = ''
99 const ticketLike = [ WALLET_NAMES.TICKET, WALLET_NAMES.SHARDS ]
101 if (ticketLike.includes(walletType)) {
103 const uwal = urbitWallet.matchWith({
104 Just: uw => uw.value,
106 throw BRIDGE_ERROR.MISSING_URBIT_WALLET
110 managementSeed = uwal.management.seed
112 } else if (walletType === WALLET_NAMES.MNEMONIC) {
114 const mnemonic = authMnemonic.matchWith({
115 Just: mnem => mnem.value,
117 throw BRIDGE_ERROR.MISSING_MNEMONIC
121 const chainProxy = pointDetails.managementProxy
123 // the network seed is only derivable from mnemonic if the derived
124 // management seed equals the record we have on chain
125 const networkSeedDerivable = eqAddr(walProxy, chainProxy)
127 if (networkSeedDerivable === true) {
128 managementSeed = mnemonic
132 let networkSeed = Maybe.Nothing()
134 if (managementSeed !== '') {
136 await kg.deriveNetworkSeed(managementSeed, '', revision)
138 networkSeed = Maybe.Just(seed)
149 attemptSeedDerivation
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list