Skip to content

Commit

Permalink
Feat/bump wallet provider (#500)
Browse files Browse the repository at this point in the history
* Bump wallet provider version

* Add tests to check paths, use createPath in ledgerProvider
  • Loading branch information
Schwartz10 authored Sep 4, 2020
1 parent d311f20 commit b4752d7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 15 deletions.
24 changes: 24 additions & 0 deletions WalletProvider/prepareSubproviders/createHDWalletProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ describe('createHDWalletProvider', () => {
const hdWalletProvider = HDWalletProvider(mnemonic)
const accounts = await hdWalletProvider.getAccounts(TESTNET, 0, 5)
expect(accounts.length).toBe(5)
})

test('it calls the wasm keyDerive method', async () => {
const HDWalletProvider = createHDWalletProvider(mockRustModule)
const hdWalletProvider = HDWalletProvider(mnemonic)
await hdWalletProvider.getAccounts(TESTNET, 0, 5)
expect(mockRustModule.keyDerive).toHaveBeenCalledTimes(5)
})

test('it passes the right, hardened paths', async () => {
const HDWalletProvider = createHDWalletProvider(mockRustModule)
const hdWalletProvider = HDWalletProvider(mnemonic)
await hdWalletProvider.getAccounts(TESTNET, 0, 5)
mockRustModule.keyDerive.mock.calls.forEach(([_, path], walletIdx) => {
// check to make sure the path fits m/44'/1'/0'/0/0
path.split('/').forEach((v, i) => {
// expect apostrophe at the end if its in the first 3 vals after "m"
if (i === 0) expect(v).toBe('m')
else if (i < 4) expect(v[v.length - 1]).toBe("'")
else expect(v[v.length - 1]).not.toBe("'")

if (i === 5) expect(v).toBe(walletIdx.toString())
})
})
expect(mockRustModule.keyDerive).toHaveBeenCalledTimes(5)
})
})
Expand Down
3 changes: 2 additions & 1 deletion WalletProvider/prepareSubproviders/createLedgerProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
MAINNET_PATH_CODE,
TESTNET_PATH_CODE
} from '../../constants'
import createPath from '../../utils/createPath'

const handleErrors = response => {
if (
Expand Down Expand Up @@ -76,7 +77,7 @@ export default rustModule => {
network === MAINNET ? MAINNET_PATH_CODE : TESTNET_PATH_CODE
const paths = []
for (let i = nStart; i < nEnd; i += 1) {
paths.push(`m/44'/${networkCode}'/0/0/${i}`)
paths.push(createPath(networkCode, i))
}
const addresses = await mapSeries(paths, async path => {
const { addrString } = handleErrors(
Expand Down
17 changes: 17 additions & 0 deletions WalletProvider/prepareSubproviders/createLedgerProvider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ describe('createLedgerProvider', () => {
expect(accounts.length).toBe(5)
expect(mockGetAddressAndPubKey).toHaveBeenCalledTimes(5)
})

test('it generates accounts with the right, hardened paths', async () => {
const LedgerProvider = createLedgerProvider(mockRustModule)
const ledgerProvider = LedgerProvider({})
await ledgerProvider.getAccounts(TESTNET, 0, 5)
mockGetAddressAndPubKey.mock.calls.forEach(([path], walletIdx) => {
// check to make sure the path fits m/44'/1'/0'/0/0
path.split('/').forEach((v, i) => {
// expect apostrophe at the end if its in the first 3 vals after "m"
if (i === 0) expect(v).toBe('m')
else if (i < 4) expect(v[v.length - 1]).toBe("'")
else expect(v[v.length - 1]).not.toBe("'")

if (i === 5) expect(v).toBe(walletIdx.toString())
})
})
})
})
})
})
17 changes: 4 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@openworklabs/filecoin-address": "0.0.10",
"@openworklabs/filecoin-message": "^1.0.0-beta.1",
"@openworklabs/filecoin-number": "0.0.9",
"@openworklabs/filecoin-wallet-provider": "^1.0.0-beta.1",
"@openworklabs/filecoin-wallet-provider": "^1.0.0-beta.2",
"@openworklabs/lotus-jsonrpc-engine": "0.1.3",
"@zondax/filecoin-signing-tools": "0.7.1",
"@zondax/ledger-filecoin": "0.11.0",
Expand Down

0 comments on commit b4752d7

Please sign in to comment.