on master help sign in
- Add proper validation for ticket verification
commitf2e52b485e1e9b9f14d439662712b97b9b61ec8a authorChris Johnson <chris@cjohnson.io> dateMon 29 Apr 2019, 14:06 (8 years ago) parent967e37b
4 files changed+34−36
src/bridge/components/Base.js+21 src/bridge/components/advancedInput.js+1 src/bridge/lib/validators.js+1−24 src/bridge/views/InviteTicket.js+11−12
src/bridge/components/Base.js+21
@@ -1,5 +1,6 @@
11// Helpers
22import {
3+ simpleValidatorWrapper,
34 validateMnemonic,
45 validateNotEmpty,
56 validateEthereumAddress,
@@ -143,6 +144,25 @@ const TicketInput = advancedInput({
143144 ]
144145});
145146
147+const VerifyTicketInput = matchingTicket => advancedInput({
148+ WrappedComponent: Input,
149+ validators: [
150+ validateTicket,
151+ validateNotEmpty,
152+
153+ // TODO: This should be in /lib/validators, but we'd need a way for
154+ // validators to compare against dynamic values
155+ m => simpleValidatorWrapper({
156+ prevMessage: m,
157+ validator: d => d === matchingTicket,
158+ errorMessage: 'This does not match the provided master ticket'
159+ })
160+ ],
161+ transformers: [
162+ prependSig,
163+ ]
164+});
165+
146166const ShardInput = advancedInput({
147167 WrappedComponent: Input,
148168 validators: [
@@ -169,6 +189,7 @@ export {
169189 GalaxyInput,
170190 PointInput,
171191 TicketInput,
192+ VerifyTicketInput,
172193 ShardInput,
173194 RequiredInput,
174195 NetworkKeyInput,
src/bridge/components/advancedInput.js+1
@@ -75,6 +75,7 @@ const advancedInput = ({
7575
7676 // Run validation chain on the transformed value. Validators are executed
7777 // from right to left and exit on the first validation failure.
78+
7879 const report = compose(...validators, initMessage)(props.value)
7980
8081 // Makes a uniform data structure to pass to display triggers. This
src/bridge/lib/validators.js+1−24
@@ -5,7 +5,6 @@ import { isValidAddress } from './wallet'
55
66const hexRegExp = /[0-9A-Fa-f]{64}/g
77
8−
98// // Note that this validator also transforms data
109// const validateBase64 = ({ data, pass, error }) => {
1110// if (pass !== true) return { data, pass, error }
@@ -30,10 +29,6 @@ const hexRegExp = /[0-9A-Fa-f]{64}/g
3029// }
3130// };
3231
33−
34−
35−
36−
3732// Validates a bip39 mnemonic
3833const validateMnemonic = m => simpleValidatorWrapper({
3934 prevMessage: m,
@@ -41,7 +36,6 @@ const validateMnemonic = m => simpleValidatorWrapper({
4136 errorMessage: 'This is not a valid mnemonic.'
4237});
4338
44−
4539// Checks an empty field
4640const validateNotEmpty = m => simpleValidatorWrapper({
4741 prevMessage: m,
@@ -49,8 +43,6 @@ const validateNotEmpty = m => simpleValidatorWrapper({
4943 errorMessage: 'This field is required.'
5044});
5145
52−
53−
5446// Checks if a patp is a valid galaxy
5547const validateGalaxy = m => simpleValidatorWrapper({
5648 prevMessage: m,
@@ -66,8 +58,6 @@ const validateGalaxy = m => simpleValidatorWrapper({
6658 errorMessage: 'This is not a valid galaxy'
6759});
6860
69−
70−
7161const validatePoint = m => simpleValidatorWrapper({
7262 prevMessage: m,
7363 validator: d => {
@@ -80,8 +70,6 @@ const validatePoint = m => simpleValidatorWrapper({
8070 errorMessage: 'This is not a valid point'
8171});
8272
83−
84−
8573const validateTicket = m => simpleValidatorWrapper({
8674 prevMessage: m,
8775 validator: d => {
@@ -94,7 +82,6 @@ const validateTicket = m => simpleValidatorWrapper({
9482 errorMessage: 'This is not a valid ticket'
9583});
9684
97−
9885const validateShard = m => simpleValidatorWrapper({
9986 prevMessage: m,
10087 validator: d => {
@@ -107,29 +94,24 @@ const validateShard = m => simpleValidatorWrapper({
10794 errorMessage: 'This is not a valid shard'
10895});
10996
110−
11197const validateLength = (m, l) => simpleValidatorWrapper({
11298 prevMessage: m,
11399 validator: d => d.length === l,
114100 errorMessage: 'This is of an invalid length'
115101});
116102
117−
118103const validateNetworkKey = m => simpleValidatorWrapper({
119104 prevMessage: m,
120105 validator: d => hexRegExp.test(d),
121106 errorMessage: 'This is not a valid network key'
122107});
123108
124−
125109const validateNetworkSeed = m => simpleValidatorWrapper({
126110 prevMessage: m,
127111 validator: d => hexRegExp.test(d),
128112 errorMessage: 'This is not a valid network seed'
129113});
130114
131−
132−
133115// Checks if a string is a valid ethereum address
134116const validateEthereumAddress = m => simpleValidatorWrapper({
135117 prevMessage: m,
@@ -137,10 +119,6 @@ const validateEthereumAddress = m => simpleValidatorWrapper({
137119 errorMessage: 'This is not a valid Ethereum address'
138120});
139121
140−
141−
142−
143−
144122// Wraps single validation functions in a controlled and predictable way.
145123const simpleValidatorWrapper = config => {
146124
@@ -172,11 +150,10 @@ const newMessage = (data, pass, error) => ({
172150 error,
173151})
174152
175−
176−
177153export {
178154 // validateBase64,
179155 // validateJSON,
156+ simpleValidatorWrapper,
180157 validateMnemonic,
181158 validateNotEmpty,
182159 validateGalaxy,
src/bridge/views/InviteTicket.js+11−12
@@ -1,11 +1,12 @@
11import { Just, Nothing } from 'folktale/maybe'
22import React from 'react'
3−import { InnerLabel, ValidatedSigil, PointInput, Warning,
4− TicketInput, Button, Row, Col, H1, P, Passport } from '../components/Base'
3+import { InnerLabel, ValidatedSigil, PointInput, Warning, Input, TicketInput,
4+ VerifyTicketInput, Button, Row, Col, H1, P, Passport } from '../components/Base'
55import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
66import * as ob from 'urbit-ob'
77import * as azimuth from 'azimuth-js'
88
9+import { simpleValidatorWrapper } from '../lib/validators'
910import { ROUTE_NAMES } from '../lib/router'
1011import { DEFAULT_HD_PATH, urbitWalletFromTicket,
1112 walletFromMnemonic, addressFromSecp256k1Public } from '../lib/wallet'
@@ -127,6 +128,7 @@ class InviteTicket extends React.Component {
127128 realPoint,
128129 realWallet,
129130 inviteWallet: Just(inviteWallet),
131+ // verifyTicket: realWallet.value.ticket,
130132 walletStates: this.state.walletStates.concat(WALLET_STATES.RENDERING),
131133 errors
132134 })
@@ -144,8 +146,13 @@ class InviteTicket extends React.Component {
144146 let handler = isLogin ? this.handleInviteTicketInput : this.handleVerifyTicketInput
145147 let label = isLogin ? 'Activation code' : 'ticket'
146148
149+ const TicketElem =
150+ isVerify && !Nothing.hasInstance(this.state.realWallet)
151+ ? VerifyTicketInput(this.state.realWallet.value.ticket)
152+ : TicketInput
153+
147154 return (
148− <TicketInput
155+ <TicketElem
149156 className='mono mt-8'
150157 prop-size='md'
151158 prop-format='innerLabel'
@@ -156,7 +163,7 @@ class InviteTicket extends React.Component {
156163 value={ value }
157164 onChange={ handler }>
158165 <InnerLabel>{ label }</InnerLabel>
159− </TicketInput>
166+ </TicketElem>
160167 )
161168 } else {
162169 return null
@@ -258,13 +265,6 @@ class InviteTicket extends React.Component {
258265 Nothing: null
259266 })
260267
261− // if (realTicket !== verifyTicket) {
262− // const verifyError = "Incorrect ticket. Please double-check the Master Ticket field from your generated wallet and try again."
263− //
264− // this.setState({
265− // errors: [verifyError]
266− // })
267− // } else {
268268 this.setState({
269269 stage: INVITE_STAGES.INVITE_TRANSACTIONS,
270270 walletStates: this.state.walletStates.concat(WALLET_STATES.TRANSACTIONS)
@@ -285,7 +285,6 @@ class InviteTicket extends React.Component {
285285 this.props.popRoute()
286286 }, 5000)
287287 })
288− // }
289288 }
290289 continueReady = true
291290 break