Browse Source

Start fixing the address verifying, using the lib core

master
meriadec 7 years ago
parent
commit
ced865a6fc
No known key found for this signature in database GPG Key ID: 1D2FC2305E2CB399
  1. 17
      src/components/DashboardPage/index.js
  2. 3
      src/components/DeviceCheckAddress.js
  3. 1
      src/components/DeviceMonit/index.js
  4. 1
      src/components/DeviceMonitNew/index.js
  5. 17
      src/internals/usb/wallet/accounts.js
  6. 17
      src/internals/usb/wallet/index.js
  7. 2
      src/internals/usb/wallet/scanAccountsOnDevice.js
  8. 467
      yarn.lock

17
src/components/DashboardPage/index.js

@ -144,6 +144,23 @@ class DashboardPage extends PureComponent<Props, State> {
<Box flow={7}>
{currentDevice && (
<Box p={8}>
<button
onClick={async () => {
const freshAddress = await runJob({
channel: 'usb',
job: 'wallet.getFreshReceiveAddress',
successResponse: 'wallet.getFreshReceiveAddress.success',
errorResponse: 'wallet.getFreshReceiveAddress.fail',
data: {
accountIndex: accounts[0].index,
currencyId: 'bitcoin_testnet',
},
})
console.log(freshAddress)
}}
>
{'get fresh address'}
</button>
{currentDevice.path}
<button
onClick={async () => {

3
src/components/DeviceCheckAddress.js

@ -55,7 +55,8 @@ class CheckAddress extends PureComponent<Props, State> {
verifyAddress = ({ device, account }: { device: Device, account: Account }) =>
sendEvent('usb', 'wallet.verifyAddress', {
pathDevice: device.path,
path: `${account.rootPath}${account.path}`,
path: account.path,
segwit: account.path.startsWith("49'"), // TODO: store segwit info in account
})
render() {

1
src/components/DeviceMonit/index.js

@ -84,6 +84,7 @@ class DeviceMonit extends PureComponent<Props, State> {
devicePath: currentDevice.path,
accountPath: account.path,
accountAddress: account.address,
segwit: account.path.startsWith("49'"), // TODO: store segwit info in account
})
}

1
src/components/DeviceMonitNew/index.js

@ -101,6 +101,7 @@ class DeviceMonit extends PureComponent<Props, State> {
options = {
accountPath: account.path,
accountAddress: account.address,
segwit: account.path.startsWith("49'"), // TODO: store segwit info in account
}
}

17
src/internals/usb/wallet/accounts.js

@ -24,6 +24,23 @@ export function getPath({
}`
}
export async function getFreshReceiveAddress({
currencyId,
accountIndex,
}: {
currencyId: string,
accountIndex: number,
}) {
const core = require('ledger-core')
const wallet = await core.getWallet(currencyId)
const account = await wallet.getAccount(accountIndex)
const addresses = await account.getFreshPublicAddresses()
if (!addresses.length) {
throw new Error('No fresh addresses')
}
return addresses[0]
}
export function verifyAddress({
transport,
path,

17
src/internals/usb/wallet/index.js

@ -3,7 +3,7 @@
import CommNodeHid from '@ledgerhq/hw-transport-node-hid'
import Btc from '@ledgerhq/hw-app-btc'
import { getPath, verifyAddress } from './accounts'
import { getPath, verifyAddress, getFreshReceiveAddress } from './accounts'
import scanAccountsOnDevice from './scanAccountsOnDevice'
export default (sendEvent: Function) => ({
@ -37,6 +37,21 @@ export default (sendEvent: Function) => ({
`NOT IMPLEMENTED: getting account for ${pathDevice} ${currencyId} ${currentAccounts.length}`,
)
},
getFreshReceiveAddress: async ({
currencyId,
accountIndex,
}: {
currencyId: string,
accountIndex: number,
}) => {
try {
console.log(accountIndex)
const freshAddress = await getFreshReceiveAddress({ currencyId, accountIndex })
sendEvent('wallet.getFreshReceiveAddress.success', freshAddress)
} catch (err) {
sendEvent('wallet.getFreshReceiveAddress.fail', err)
}
},
verifyAddress: async ({ pathDevice, path }: { pathDevice: string, path: string }) => {
const transport = await CommNodeHid.open(pathDevice)

2
src/internals/usb/wallet/scanAccountsOnDevice.js

@ -59,7 +59,7 @@ async function scanNextAccount({ wallet, hwApp, accountIndex = 0, accountsCount,
accounts.push(account)
// returns if the current index points on an account with no ops
if (!ops.length) {
if (utxosCount === 0) {
return accounts
}

467
yarn.lock

File diff suppressed because it is too large
Loading…
Cancel
Save