Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add bip44Validators and more UI additions
- Loading branch information
1 parent
5a534f8
commit e0a19e7
Showing
8 changed files
with
180 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 25 additions & 5 deletions
30
src/components/WalletInit/RestoreWallet/styles/SaveReadOnlyWalletScreen.style.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,47 @@ | ||
// @flow | ||
import {StyleSheet} from 'react-native' | ||
|
||
import {COLORS} from '../../../../styles/config' | ||
import {THEME} from '../../../../styles/config' | ||
|
||
const SECTION_MARGIN = 22 | ||
const LABEL_MARGIN = 6 | ||
|
||
export default StyleSheet.create({ | ||
safeAreaView: { | ||
backgroundColor: COLORS.WHITE, | ||
backgroundColor: THEME.COLORS.BACKGROUND, | ||
paddingHorizontal: 16, | ||
paddingTop: 30, | ||
}, | ||
checkSumView: { | ||
scrollView: { | ||
paddingRight: 10, | ||
}, | ||
label: { | ||
marginBottom: LABEL_MARGIN, | ||
}, | ||
checksumContainer: { | ||
marginBottom: SECTION_MARGIN, | ||
}, | ||
checksumView: { | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
marginTop: 12, | ||
marginBottom: 32, | ||
borderColor: 'red', | ||
flexWrap: 'wrap', | ||
}, | ||
checksumText: { | ||
fontSize: 18, | ||
fontWeight: 'bold', | ||
paddingLeft: 12, | ||
}, | ||
addressesContainer: { | ||
marginBottom: 32, | ||
marginBottom: SECTION_MARGIN, | ||
}, | ||
keyAttributesContainer: { | ||
marginBottom: SECTION_MARGIN, | ||
}, | ||
keyView: { | ||
padding: 4, | ||
backgroundColor: THEME.COLORS.CODE_STYLE_BACKGROUND, | ||
marginBottom: 10, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// @flow | ||
import {Bip32PublicKey} from 'react-native-haskell-shelley' | ||
|
||
import {NUMBERS} from '../config/numbers' | ||
import assert from './assert' | ||
|
||
const isString = (s) => typeof s === 'string' || s instanceof String | ||
|
||
const isUInt32 = (i) => Number.isInteger(i) && i >= 0 && i < 4294967296 | ||
|
||
export const isValidPath = (path: any): boolean => { | ||
if (!(Array.isArray(path) && path.length > 0 && path.length <= 5)) { | ||
return false | ||
} | ||
for (const i of path) { | ||
if (!isUInt32(i)) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
export const isCIP1852AccountPath = (path: Array<number>): boolean => { | ||
assert.preconditionCheck(isValidPath(path), 'invalid bip44 path') | ||
// note: allows non-zero accounts | ||
return ( | ||
path.length === 3 && | ||
(path[0] === NUMBERS.WALLET_TYPE_PURPOSE.CIP1852 || path[0] === 1852) && | ||
(path[1] === NUMBERS.COIN_TYPES.CARDANO || path[1] === 1815) | ||
) | ||
} | ||
|
||
export const canParsePublicKey = async ( | ||
publicKeyHex: string, | ||
): Promise<boolean> => { | ||
try { | ||
await Bip32PublicKey.from_bytes(Buffer.from(publicKeyHex, 'hex')) | ||
return true | ||
} catch (_e) { | ||
return false | ||
} | ||
} | ||
|
||
export const isValidPublicKey = async (key: any): Promise<boolean> => | ||
key != null && isString(key) && (await canParsePublicKey(key)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// @flow | ||
import jestSetup from '../jestSetup' | ||
|
||
import {isCIP1852AccountPath, isValidPath} from './bip44Validators' | ||
|
||
jestSetup.setup() | ||
|
||
describe('Check BIP44/CIP1852 paths', () => { | ||
it('valid CIP1852 paths', () => { | ||
const account0 = [1852, 1815, 0] | ||
expect(isCIP1852AccountPath(account0)).toEqual(true) | ||
|
||
const account0Hardened = [2147485500, 2147485463, 2147483648] | ||
expect(isCIP1852AccountPath(account0Hardened)).toEqual(true) | ||
|
||
const lastAccount = [2147485500, 2147485463, 4294967295] | ||
expect(isCIP1852AccountPath(lastAccount)).toEqual(true) | ||
}) | ||
|
||
it('invalid CIP1852 paths', () => { | ||
const bip44Path = [2147483692, 2147485463, 2147483648] | ||
expect(isCIP1852AccountPath(bip44Path)).toEqual(false) | ||
|
||
const nonHardened = [2147483692, 2147485463, 0] | ||
expect(isCIP1852AccountPath(nonHardened)).toEqual(false) | ||
}) | ||
|
||
it('invalid BIP44 paths', () => { | ||
const paths = [ | ||
undefined, | ||
'', | ||
[], | ||
{}, | ||
[2147483692, 2147485463, 2147483648, 2147483692, 2147483692, 2147483692], | ||
] | ||
for (const path of paths) { | ||
expect(isValidPath(path)).toEqual(false) | ||
} | ||
}) | ||
}) |