@@ -8,13 +8,12 @@ import * as ob from 'urbit-ob';
88import * as kg from 'urbit-key-generation/dist';
99import { isAddress } from 'web3-utils';
1010
11−const DEFAULT_HD_PATH = "m/44'/60'/0'/0/0";
12−
13−const ETH_ZERO_ADDR = '0x0000000000000000000000000000000000000000';
14−const CURVE_ZERO_ADDR =
11+export const DEFAULT_HD_PATH = "m/44'/60'/0'/0/0";
12+export const ETH_ZERO_ADDR = '0x0000000000000000000000000000000000000000';
13+export const CURVE_ZERO_ADDR =
1514 '0x0000000000000000000000000000000000000000000000000000000000000000';
1615
17−const WALLET_TYPES = {
16+export const WALLET_TYPES = {
1817 MNEMONIC: Symbol('MNEMONIC'),
1918 TICKET: Symbol('TICKET'),
2019 SHARDS: Symbol('SHARDS'),
@@ -24,31 +23,14 @@ const WALLET_TYPES = {
2423 KEYSTORE: Symbol('KEYSTORE'),
2524};
2625
27−function EthereumWallet(privateKey) {
26+export function EthereumWallet(privateKey) {
2827 this.privateKey = privateKey;
2928 this.publicKey = secp256k1.publicKeyCreate(this.privateKey);
3029 const pub = this.publicKey.toString('hex');
3130 this.address = addressFromSecp256k1Public(pub);
3231}
3332
34−const renderWalletType = wallet =>
35− wallet === WALLET_TYPES.MNEMONIC
36− ? 'Mnemonic'
37− : wallet === WALLET_TYPES.TICKET
38− ? 'Ticket'
39− : wallet === WALLET_TYPES.SHARDS
40− ? 'Ticket Shards'
41− : wallet === WALLET_TYPES.LEDGER
42− ? 'Ledger'
43− : wallet === WALLET_TYPES.TREZOR
44− ? 'Trezor'
45− : wallet === WALLET_TYPES.PRIVATE_KEY
46− ? 'Private Key'
47− : wallet === WALLET_TYPES.KEYSTORE
48− ? 'Keystore File'
49− : 'Wallet';
50−
51−const addressFromSecp256k1Public = pub => {
33+export const addressFromSecp256k1Public = pub => {
5234 const compressed = false;
5335 const uncompressed = secp256k1.publicKeyConvert(
5436 Buffer.from(pub, 'hex'),
@@ -60,18 +42,20 @@ const addressFromSecp256k1Public = pub => {
6042 return toChecksumAddress(addr);
6143};
6244
63−const addHexPrefix = hex => (hex.slice(0, 2) === '0x' ? hex : '0x' + hex);
45+export const addHexPrefix = hex =>
46+ hex.slice(0, 2) === '0x' ? hex : '0x' + hex;
6447
65−const stripHexPrefix = hex => (hex.slice(0, 2) === '0x' ? hex.slice(2) : hex);
48+export const stripHexPrefix = hex =>
49+ hex.slice(0, 2) === '0x' ? hex.slice(2) : hex;
6650
67−const keccak256 = str =>
51+export const keccak256 = str =>
6852 keccak('keccak256')
6953 .update(str)
7054 .digest();
7155
72−const isValidAddress = a => '0x0' === a || isAddress(a);
56+export const isValidAddress = a => '0x0' === a || isAddress(a);
7357
74−const toChecksumAddress = address => {
58+export const toChecksumAddress = address => {
7559 const addr = stripHexPrefix(address).toLowerCase();
7660 const hash = keccak256(addr).toString('hex');
7761
@@ -83,27 +67,28 @@ const toChecksumAddress = address => {
8367 );
8468};
8569
86−const eqAddr = (addr0, addr1) =>
70+export const eqAddr = (addr0, addr1) =>
8771 toChecksumAddress(addr0) === toChecksumAddress(addr1);
8872
89−const urbitWalletFromTicket = async (ticket, point, passphrase) => {
73+export const urbitWalletFromTicket = async (ticket, point, passphrase) => {
9074 if (typeof point === 'string') {
9175 //TODO why not in kg?
9276 point = ob.patp2dec(point);
9377 }
94− let uhdw = await kg.generateWallet({
78+
79+ return await kg.generateWallet({
9580 ticket: ticket,
9681 ship: point,
9782 passphrase: passphrase,
9883 });
99− return uhdw;
10084};
10185
102−const ownershipWalletFromTicket = async (ticket, point, passphrase) => {
86+export const ownershipWalletFromTicket = async (ticket, point, passphrase) => {
10387 if (typeof point === 'string') {
10488 //TODO why not in kg?
10589 point = ob.patp2dec(point);
10690 }
91+
10792 return await kg.generateOwnershipWallet({
10893 ticket,
10994 ship: point,
@@ -111,7 +96,7 @@ const ownershipWalletFromTicket = async (ticket, point, passphrase) => {
11196 });
11297};
11398
114−const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
99+export const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
115100 const seed = bip39.validateMnemonic(mnemonic)
116101 ? Maybe.Just(bip39.mnemonicToSeed(mnemonic, passphrase))
117102 : Maybe.Nothing();
@@ -132,20 +117,3 @@ const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
132117 const wallet = seed.chain(sd => toWallet(sd, hdpath));
133118 return wallet;
134119};
135−
136−export {
137− DEFAULT_HD_PATH,
138− WALLET_TYPES,
139− ETH_ZERO_ADDR,
140− CURVE_ZERO_ADDR,
141− renderWalletType,
142− isValidAddress,
143− toChecksumAddress,
144− addressFromSecp256k1Public,
145− eqAddr,
146− urbitWalletFromTicket,
147− ownershipWalletFromTicket,
148− walletFromMnemonic,
149− addHexPrefix,
150− EthereumWallet,
151−};