on master help sign in
Ensure wallet object always has an .address

This allows us to drastically reduce the amount of times we derive the address from the public key.

commitb42c62f82badd7d4f0100314322d036dc0b4005d authorFang <git@fang.io> dateFri 7 Jun 2019, 12:47 (7 years ago) parent201d3ec
13 files changed+27−15
src/bridge/Bridge.js+12−1 src/bridge/components/StatelessTransaction.js+2−2 src/bridge/lib/invite.js+1−1 src/bridge/lib/keys.js+1−1 src/bridge/lib/router.js+1−1 src/bridge/lib/wallet.js+3−1 src/bridge/views/AcceptTransfer.js+1−1 src/bridge/views/CreateGalaxy.js+1−1 src/bridge/views/InviteTicket.js+1−1 src/bridge/views/InvitesSend.js+1−1 src/bridge/views/Point/Actions.js+1−1 src/bridge/views/Points.js+1−2 src/bridge/views/SetKeys.js+1−1
src/bridge/Bridge.js+12−1
@@ -12,7 +12,12 @@ import { Container, Row, Col } from './components/Base'
1212
1313import { ROUTE_NAMES, router } from './lib/router'
1414import { NETWORK_NAMES } from './lib/network'
15−import { WALLET_NAMES, DEFAULT_HD_PATH, walletFromMnemonic } from './lib/wallet'
15+import {
16+ WALLET_NAMES,
17+ DEFAULT_HD_PATH,
18+ walletFromMnemonic,
19+ addressFromSecp256k1Public
20+} from './lib/wallet'
1621import { BRIDGE_ERROR } from './lib/error'
1722
1823const initWeb3 = (networkType) => {
@@ -212,6 +217,11 @@ class Bridge extends React.Component {
212217 }
213218
214219 setWallet(wallet) {
220+ if (Just.hasInstance(wallet) &&
221+ wallet.value.publicKey &&
222+ typeof wallet.value.address === 'undefined') {
223+ wallet.value.address = addressFromSecp256k1Public(wallet.value.publicKey);
224+ }
215225 this.setState({ wallet })
216226 }
217227
@@ -229,6 +239,7 @@ class Bridge extends React.Component {
229239 DEFAULT_HD_PATH,
230240 urbitWallet.value.meta.passphrase
231241 );
242+ wallet.value.address = urbitWallet.value.ownership.keys.address;
232243 }
233244 this.setState({ urbitWallet, wallet })
234245 }
src/bridge/components/StatelessTransaction.js+2−2
@@ -66,7 +66,7 @@ class StatelessTransaction extends React.Component {
6666 const { props } = this
6767
6868 const addr = props.wallet.matchWith({
69− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
69+ Just: wal => wal.value.address,
7070 Nothing: () => {
7171 throw BRIDGE_ERROR.MISSING_WALLET
7272 }
@@ -212,7 +212,7 @@ class StatelessTransaction extends React.Component {
212212
213213 //TODO need a lib function or something for address=, it's everywhere
214214 const address = props.wallet.matchWith({
215− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
215+ Just: wal => wal.value.address,
216216 Nothing: () => {
217217 throw BRIDGE_ERROR.MISSING_WALLET
218218 }
src/bridge/lib/invite.js+1−1
@@ -147,7 +147,7 @@ async function startTransactions(args) {
147147 }
148148 const point = realPointM.value;
149149
150− const inviteAddress = addressFromSecp256k1Public(inviteWallet.publicKey);
150+ const inviteAddress = inviteWallet.address;
151151 console.log('working as', inviteAddress);
152152
153153 // transfer from invite wallet to new wallet
src/bridge/lib/keys.js+1−1
@@ -105,7 +105,7 @@ const attemptSeedDerivation = async (next, args) => {
105105 } else if (walletType === WALLET_NAMES.MNEMONIC) {
106106
107107 const walProxy = wallet.matchWith({
108− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
108+ Just: wal => wal.value.address,
109109 Nothing: _ => {
110110 throw BRIDGE_ERROR.MISSING_WALLET
111111 }
src/bridge/lib/router.js+1−1
@@ -137,7 +137,7 @@ const renderRoute = (props, route) => {
137137 Just: (wal) =>
138138 wal.value instanceof EthereumWallet
139139 ? (<span className="text-mono">{wal.value.address}</span>)
140− : (<span className="text-mono">{addressFromSecp256k1Public(wal.value.publicKey)}</span>)
140+ : (<span className="text-mono">{wal.value.address}</span>)
141141 })
142142
143143 : route === ROUTE_NAMES.MNEMONIC
src/bridge/lib/wallet.js+3−1
@@ -122,7 +122,9 @@ const walletFromMnemonic = (mnemonic, hdpath, passphrase) => {
122122 let wal
123123 try {
124124 const hd = bip32.fromSeed(sd)
125− wal = Maybe.Just(hd.derivePath(path))
125+ wal = hd.derivePath(path);
126+ wal.address = addressFromSecp256k1Public(wal.publicKey);
127+ wal = Maybe.Just(wal);
126128 } catch (_) {
127129 wal = Maybe.Nothing()
128130 }
src/bridge/views/AcceptTransfer.js+1−1
@@ -15,7 +15,7 @@ class AcceptTransfer extends React.Component {
1515 super(props)
1616
1717 const receivingAddress = props.wallet.matchWith({
18− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
18+ Just: (wal) => wal.value.address,
1919 Nothing: () => {
2020 throw BRIDGE_ERROR.MISSING_WALLET
2121 }
src/bridge/views/CreateGalaxy.js+1−1
@@ -43,7 +43,7 @@ class CreateGalaxy extends React.Component {
4343 super(props)
4444
4545 const galaxyOwner = props.wallet.matchWith({
46− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
46+ Just: (wal) => wal.value.address,
4747 Nothing: () => {
4848 throw BRIDGE_ERROR.MISSING_WALLET
4949 }
src/bridge/views/InviteTicket.js+1−1
@@ -84,7 +84,7 @@ class InviteTicket extends React.Component {
8484 }
8585 });
8686
87− const addr = addressFromSecp256k1Public(inviteWallet.publicKey);
87+ const addr = inviteWallet.address;
8888
8989 const ctrcs = this.props.contracts.matchWith({
9090 Just: ctrcs => ctrcs.value,
src/bridge/views/InvitesSend.js+1−1
@@ -78,7 +78,7 @@ class InvitesSend extends React.Component {
7878 });
7979 //TODO why are we doing this locally, instead of made global on sign-in?
8080 this.address = this.props.wallet.matchWith({
81− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
81+ Just: (wal) => wal.value.address,
8282 Nothing: () => {
8383 throw BRIDGE_ERROR.MISSING_WALLET;
8484 }
src/bridge/views/Point/Actions.js+1−1
@@ -23,7 +23,7 @@ const Actions = (props) => {
2323 } = props
2424
2525 const addr = wallet.matchWith({
26− Just: (wal) => addressFromSecp256k1Public(wal.value.publicKey),
26+ Just: (wal) => wal.value.address,
2727 Nothing: () => {
2828 throw BRIDGE_ERROR.MISSING_WALLET
2929 }
src/bridge/views/Points.js+1−2
@@ -42,8 +42,7 @@ class Points extends React.Component {
4242 web3.chain(_ =>
4343 contracts.chain(ctrcs =>
4444 wallet.chain(async wal => {
45− const pub = wal.publicKey
46− const addr = addressFromSecp256k1Public(pub)
45+ const addr = wal.address
4746
4847 const points =
4948 await azimuth.azimuth.getOwnedPoints(ctrcs, addr)
src/bridge/views/SetKeys.js+1−1
@@ -52,7 +52,7 @@ class SetKeys extends React.Component {
5252 this.deriveSeed()
5353
5454 const addr = props.wallet.matchWith({
55− Just: wal => addressFromSecp256k1Public(wal.value.publicKey),
55+ Just: wal => wal.value.address,
5656 Nothing: () => {
5757 throw BRIDGE_ERROR.MISSING_WALLET
5858 }