2import { Just, Nothing } from 'folktale/maybe';
4import * as noun from '../nockjs/noun';
5import * as serial from '../nockjs/serial';
6import * as kg from 'urbit-key-generation/dist';
8import { eqAddr, addHexPrefix } from './wallet';
10// the curve param for the network keys
11export const NETWORK_KEY_CURVE_PARAMETER = '42';
12// the current crypto suite version
13export const CRYPTO_SUITE_VERSION = 1;
15export const CURVE_ZERO_ADDR =
16 '0x0000000000000000000000000000000000000000000000000000000000000000';
20 let hex = buf.reverse().toString('hex');
21 let n = new BN(hex, 'hex');
23 while (1 === n.cmpn(0)) {
24 c.push(n.andln(0x3f));
44 String.fromCharCode(trans(b)) + (i && 0 === i % 5 ? '.' : '') + a,
55 const pad = hex.length % 2 === 0 ? hex : '0' + hex;
56 return Buffer.from(pad, 'hex').reverse();
59// simple alias to avoid importing kg into component scope
60export const deriveNetworkKeys = seed => kg.deriveNetworkKeys(seed);
63 * @param {object} pair
64 * @param {number} point
65 * @param {number} revision
68export const compileNetworkingKey = (pair, point, revision) => {
70 pair.crypt.private + pair.auth.private + NETWORK_KEY_CURVE_PARAMETER,
74 const sed = noun.dwim(
75 noun.Atom.fromInt(point),
76 noun.Atom.fromInt(revision),
77 noun.Atom.fromString(bnsec.toString()),
85 * @param {object} urbitWallet
86 * @param {number} revision
87 * @return {Promise<Maybe<string>>}
89export const deriveNetworkSeedFromUrbitWallet = async (
93 return await deriveNetworkSeedFromMnemonic(
94 urbitWallet.management.seed,
95 urbitWallet.meta.passphrase,
101 * @param {Maybe<any>} wallet
102 * @param {string} authMnemonic
103 * @param {object} details
104 * @param {number} revision
105 * @return {Promise<Maybe<string>>}
107export const deriveNetworkSeedFromManagementMnemonic = async (
113 const isManagementProxy = eqAddr(wallet.address, details.managementProxy);
115 // the network seed is derivable iff this mnemonic is the management proxy
116 if (isManagementProxy) {
117 return await deriveNetworkSeedFromMnemonic(
128 * @param {string} mnemonic
129 * @param {string} passphrase
130 * @param {number} revision
131 * @return {Promise<Maybe<string>>}
133const deriveNetworkSeedFromMnemonic = async (
138 //NOTE revision is the point's on-chain revision number. since common uhdw
139 // usage derives the first key at revision/index 0, we need to decrement
140 // the on-chain revision number by one to get the number to derive with.
141 return Just(await kg.deriveNetworkSeed(mnemonic, passphrase, revision - 1));
145 * @return {Promise<Maybe<string>>}
147export const attemptNetworkSeedDerivation = async ({
154 if (Just.hasInstance(urbitWallet)) {
155 return await deriveNetworkSeedFromUrbitWallet(urbitWallet.value, revision);
158 if (Just.hasInstance(wallet) && Just.hasInstance(authMnemonic)) {
159 return await deriveNetworkSeedFromManagementMnemonic(
172 * @param {object} pair
173 * @param {object} details
176export const keysMatchChain = (pair, details) => {
177 const { crypt, auth } = pair;
178 const { encryptionKey, authenticationKey } = details;
181 encryptionKey === addHexPrefix(crypt.public) &&
182 authenticationKey === addHexPrefix(auth.public)
186export const segmentNetworkKey = hex => {
187 if (hex === CURVE_ZERO_ADDR) {
191 const sl = i => hex.slice(i, i + 4);
192 const rowFrom = i => `${sl(i)}.${sl(i + 4)}.${sl(i + 8)}.${sl(i + 12)}`;
194 return [rowFrom(2), rowFrom(18), rowFrom(34), rowFrom(50)];
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