on master help sign in
Add randomPatq to lib
commit54003b2c65f58a16f4feecc943bc251f59e776ce authorFang <git@fang.io> dateTue 30 Apr 2019, 16:23 (8 years ago) parent5f17519
3 files changed+15−22
src/bridge/lib/lib.js+10 src/bridge/views/InviteVerify.js+2−11 src/bridge/views/Ticket.js+3−11
src/bridge/lib/lib.js+10
@@ -29,6 +29,15 @@ const isValidGalaxy = name => {
2929 return point >= 0 && point < 256
3030}
3131
32+const randomPatq = (len) => {
33+ let bytes = window.crypto.getRandomValues(new Uint8Array(len))
34+ let hex = bytes.reduce((acc, byt) =>
35+ acc + byt.toString(16).padStart(2, '0'),
36+ ''
37+ )
38+ return ob.hex2patq(hex)
39+}
40+
3241export {
3342 compose,
3443 allFalse,
@@ -40,4 +49,5 @@ export {
4049 t,
4150 f,
4251 isValidGalaxy,
52+ randomPatq
4353}
src/bridge/views/InviteVerify.js+2−11
@@ -4,6 +4,7 @@ import { pour } from 'sigil-js'
44import * as ob from 'urbit-ob'
55import * as azimuth from 'azimuth-js'
66
7+import { randomPatq } from '../lib/lib'
78import { ROUTE_NAMES } from '../lib/router'
89
910import { InnerLabel, TicketInput } from '../components/Base'
@@ -13,16 +14,6 @@ import Actions from './Point/Actions'
1314import { BRIDGE_ERROR } from '../lib/error'
1415import { Row, Col, Warning, Button, H1, H3 } from '../components/Base'
1516
16−//TODO from Ticket.js, move to lib
17−const placeholder = (len) => {
18− let bytes = window.crypto.getRandomValues(new Uint8Array(len))
19− let hex = bytes.reduce((acc, byt) =>
20− acc + byt.toString(16).padStart(2, '0'),
21− ''
22− )
23− return ob.hex2patq(hex)
24−}
25−
2617class InviteVerify extends React.Component {
2718
2819 constructor(props) {
@@ -33,7 +24,7 @@ class InviteVerify extends React.Component {
3324 realTicket: this.props.routeData.ticket
3425 }
3526
36− this.ticketPlaceholder = placeholder(8);
27+ this.ticketPlaceholder = randomPatq(8);
3728 this.handleTicketInput = this.handleTicketInput.bind(this);
3829 this.proceed = this.proceed.bind(this);
3930 }
src/bridge/views/Ticket.js+3−11
@@ -13,18 +13,10 @@ import { Row, Col, H1, P } from '../components/Base'
1313import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
1414import * as ob from 'urbit-ob'
1515
16+import { randomPatq } from '../lib/lib'
1617import { ROUTE_NAMES } from '../lib/router'
1718import { DEFAULT_HD_PATH, urbitWalletFromTicket } from '../lib/wallet'
1819
19−const placeholder = (len) => {
20− let bytes = window.crypto.getRandomValues(new Uint8Array(len))
21− let hex = bytes.reduce((acc, byt) =>
22− acc + byt.toString(16).padStart(2, '0'),
23− ''
24− )
25− return ob.hex2patq(hex)
26−}
27−
2820class Ticket extends React.Component {
2921
3022 constructor(props) {
@@ -37,8 +29,8 @@ class Ticket extends React.Component {
3729 isUnlocking: false
3830 }
3931
40− this.pointPlaceholder = placeholder(4)
41− this.ticketPlaceholder = placeholder(8)
32+ this.pointPlaceholder = randomPatq(4)
33+ this.ticketPlaceholder = randomPatq(8)
4234
4335 this.handleTicketInput = this.handleTicketInput.bind(this)
4436 this.handlePassphraseInput = this.handlePassphraseInput.bind(this)