on master help sign in
Add randomPatq to lib
54003b2Fang
src/bridge/lib/lib.js+10
@@ -29,6 +29,15 @@ const isValidGalaxy = name => {
29 return point >= 0 && point < 256
29 return point >= 0 && point < 256
30}
30}
31
31
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+
32export {
41export {
33 compose,
42 compose,
34 allFalse,
43 allFalse,
@@ -40,4 +49,5 @@ export {
40 t,
49 t,
41 f,
50 f,
42 isValidGalaxy,
51 isValidGalaxy,
52+ randomPatq
43}
53}
src/bridge/views/InviteVerify.js+2−11
@@ -4,6 +4,7 @@ import { pour } from 'sigil-js'
4import * as ob from 'urbit-ob'
4import * as ob from 'urbit-ob'
5import * as azimuth from 'azimuth-js'
5import * as azimuth from 'azimuth-js'
6
6
7+import { randomPatq } from '../lib/lib'
7import { ROUTE_NAMES } from '../lib/router'
8import { ROUTE_NAMES } from '../lib/router'
8
9
9import { InnerLabel, TicketInput } from '../components/Base'
10import { InnerLabel, TicketInput } from '../components/Base'
@@ -13,16 +14,6 @@ import Actions from './Point/Actions'
13import { BRIDGE_ERROR } from '../lib/error'
14import { BRIDGE_ERROR } from '../lib/error'
14import { Row, Col, Warning, Button, H1, H3 } from '../components/Base'
15import { Row, Col, Warning, Button, H1, H3 } from '../components/Base'
15
16
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−
26class InviteVerify extends React.Component {
17class InviteVerify extends React.Component {
27
18
28 constructor(props) {
19 constructor(props) {
@@ -33,7 +24,7 @@ class InviteVerify extends React.Component {
33 realTicket: this.props.routeData.ticket
24 realTicket: this.props.routeData.ticket
34 }
25 }
35
26
36− this.ticketPlaceholder = placeholder(8);
27+ this.ticketPlaceholder = randomPatq(8);
37 this.handleTicketInput = this.handleTicketInput.bind(this);
28 this.handleTicketInput = this.handleTicketInput.bind(this);
38 this.proceed = this.proceed.bind(this);
29 this.proceed = this.proceed.bind(this);
39 }
30 }
src/bridge/views/Ticket.js+3−11
@@ -13,18 +13,10 @@ import { Row, Col, H1, P } from '../components/Base'
13import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
13import * as kg from '../../../node_modules/urbit-key-generation/dist/index'
14import * as ob from 'urbit-ob'
14import * as ob from 'urbit-ob'
15
15
16+import { randomPatq } from '../lib/lib'
16import { ROUTE_NAMES } from '../lib/router'
17import { ROUTE_NAMES } from '../lib/router'
17import { DEFAULT_HD_PATH, urbitWalletFromTicket } from '../lib/wallet'
18import { DEFAULT_HD_PATH, urbitWalletFromTicket } from '../lib/wallet'
18
19
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−
28class Ticket extends React.Component {
20class Ticket extends React.Component {
29
21
30 constructor(props) {
22 constructor(props) {
@@ -37,8 +29,8 @@ class Ticket extends React.Component {
37 isUnlocking: false
29 isUnlocking: false
38 }
30 }
39
31
40− this.pointPlaceholder = placeholder(4)
32+ this.pointPlaceholder = randomPatq(4)
41− this.ticketPlaceholder = placeholder(8)
33+ this.ticketPlaceholder = randomPatq(8)
42
34
43 this.handleTicketInput = this.handleTicketInput.bind(this)
35 this.handleTicketInput = this.handleTicketInput.bind(this)
44 this.handlePassphraseInput = this.handlePassphraseInput.bind(this)
36 this.handlePassphraseInput = this.handlePassphraseInput.bind(this)