2import Maybe from 'folktale/maybe';
3import * as need from './need';
5import * as noun from '../nockjs/noun';
6import * as serial from '../nockjs/serial';
7import * as kg from 'urbit-key-generation/dist';
9import { BRIDGE_ERROR } from './error';
10import { WALLET_TYPES, eqAddr } from './wallet';
14 let hex = buf.reverse().toString('hex');
15 let n = new BN(hex, 'hex');
17 while (1 === n.cmpn(0)) {
18 c.push(n.andln(0x3f));
38 String.fromCharCode(trans(b)) + (i && 0 === i % 5 ? '.' : '') + a,
49 const pad = hex.length % 2 === 0 ? hex : '0' + hex;
50 return Buffer.from(pad, 'hex').reverse();
53const genKey = (networkSeed, point, revision) => {
54 const pair = kg.deriveNetworkKeys(networkSeed);
55 const bnsec = new BN(pair.crypt.private + pair.auth.private + '42', 'hex'); // '42' is curve parameter
57 const sed = noun.dwim(
58 noun.Atom.fromInt(point),
59 noun.Atom.fromInt(revision),
60 noun.Atom.fromString(bnsec.toString()),
67// 'next' refers to setting the next set of keys
68// if false, we use revision - 1
69const attemptNetworkSeedDerivation = async (next, args) => {
70 const { walletType, urbitWallet, authMnemonic } = args;
74 // following code is intentionally verbose for sake of clarity
76 const point = need.point(args.pointCursor);
77 const pointDetails = need.fromPointCache(args.pointCache, point);
81 ? parseInt(pointDetails.keyRevisionNumber)
82 : parseInt(pointDetails.keyRevisionNumber) - 1;
84 let managementSeed = '';
86 const ticketLike = [WALLET_TYPES.TICKET, WALLET_TYPES.SHARDS];
88 if (ticketLike.includes(walletType)) {
89 const uwal = urbitWallet.matchWith({
92 throw BRIDGE_ERROR.MISSING_URBIT_WALLET;
96 managementSeed = uwal.management.seed;
97 } else if (walletType === WALLET_TYPES.MNEMONIC) {
98 const walProxy = need.addressFromWallet(args.wallet);
100 const mnemonic = authMnemonic.matchWith({
101 Just: mnem => mnem.value,
103 throw BRIDGE_ERROR.MISSING_MNEMONIC;
107 const chainProxy = pointDetails.managementProxy;
109 // the network seed is only derivable from mnemonic if the derived
110 // management seed equals the record we have on chain
111 const networkSeedDerivable = eqAddr(walProxy, chainProxy);
113 if (networkSeedDerivable === true) {
114 managementSeed = mnemonic;
118 if (managementSeed !== '') {
119 const seed = await kg.deriveNetworkSeed(managementSeed, '', revision);
122 return Maybe.Nothing();
125 return Maybe.Just(seed);
128 return Maybe.Nothing();
131export { genKey, attemptNetworkSeedDerivation };
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