-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
device and hub actions separated from wallet logic, pairing code gene…
…ration added
- Loading branch information
1 parent
0ab9ba1
commit 1048f96
Showing
15 changed files
with
209 additions
and
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { actionTypes } from './../constants'; | ||
|
||
export const rotateDeviceTempKey = () => ({ | ||
type: actionTypes.DEVICE_TEMP_KEY_ROTATE, | ||
}); |
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
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 was deleted.
Oops, something went wrong.
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,38 @@ | ||
import { REHYDRATE } from 'redux-persist'; | ||
import Crypto from 'crypto'; | ||
import { actionTypes } from '../constants'; | ||
|
||
|
||
const initialState = { | ||
deviceTempKeys: { | ||
prevPrivKey: Crypto.randomBytes(32), | ||
privKey: Crypto.randomBytes(32), | ||
rotationTimestamp: Date.now(), | ||
} | ||
}; | ||
|
||
function reducer(state = initialState, action) { | ||
switch (action.type) { | ||
case REHYDRATE: | ||
return { | ||
...state, | ||
...action.payload.app, | ||
}; | ||
|
||
case actionTypes.DEVICE_TEMP_KEY_ROTATE: | ||
return { | ||
...state, | ||
deviceTempKeys: { | ||
privKey: Crypto.randomBytes(32), | ||
privKey: action.payload.privKey, | ||
prevPrivKey: state.deviceTempKeys.privKey, | ||
rotationTimestamp: Date.now(), | ||
} | ||
}; | ||
|
||
default: | ||
return state; | ||
} | ||
} | ||
|
||
export default reducer; |
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,70 @@ | ||
import { take, takeEvery, call, put, select } from '@redux-saga/core/effects'; | ||
import { channel } from '@redux-saga/core'; | ||
import { sign } from 'obyte/lib/internal'; | ||
import { oClient, getDeviceMessageHashToSign } from './../lib/OCustom'; | ||
import { actionTypes } from './../constants'; | ||
import { setExchangeRates } from './../actions/exchangeRates'; | ||
import { | ||
selectPermanentDeviceKeyObj, | ||
selectDeviceAddress, | ||
} from './../selectors/device'; | ||
|
||
|
||
export const oChannel = channel(); | ||
|
||
export function* subscribeToHub() { | ||
try { | ||
oClient.subscribe((err, result) => { | ||
if (err) { | ||
throw new Error('Hub socket error'); | ||
} else { | ||
const [messageType, message] = result; | ||
oChannel.put({ type: messageType, payload: message }); | ||
} | ||
}); | ||
yield call(setInterval, () => oClient.api.heartbeat(), 10 * 1000); | ||
} catch (error) { | ||
yield put(setToastMessage({ | ||
type: 'ERROR', | ||
message: 'Hub connection error', | ||
})); | ||
console.log(error); | ||
} | ||
} | ||
|
||
export function* watchHubMessages() { | ||
while (true) { | ||
const { type, payload } = yield take(oChannel) | ||
|
||
if (type === 'justsaying') { | ||
switch (payload.subject) { | ||
case 'hub/challenge': | ||
yield call(loginToHub, payload.body); | ||
return; | ||
default: | ||
console.log(payload.body); | ||
} | ||
} | ||
} | ||
} | ||
|
||
export function* loginToHub(challenge) { | ||
const permanentDeviceKey = yield select(selectPermanentDeviceKeyObj()); | ||
|
||
const objLogin = { challenge, pubkey: permanentDeviceKey.pub_b64 }; | ||
objLogin.signature = sign( | ||
getDeviceMessageHashToSign(objLogin), | ||
permanentDeviceKey.priv, | ||
); | ||
oClient.justsaying('hub/login', objLogin); | ||
|
||
} | ||
|
||
export function* rotateDeviceTempKey() { | ||
const ROTATION_PERIOD = 3600 * 1000; | ||
} | ||
|
||
export default function* watch() { | ||
yield takeEvery(actionTypes.DEVICE_TEMP_KEY_ROTATE, rotateDeviceTempKey); | ||
yield watchHubMessages(); | ||
} |
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,11 +1,13 @@ | ||
import { all } from '@redux-saga/core/effects'; | ||
import appSaga from './app'; | ||
import walletSaga from './wallet'; | ||
import deviceSaga from './device'; | ||
|
||
|
||
export default function* rootSaga() { | ||
yield all([ | ||
appSaga(), | ||
walletSaga(), | ||
deviceSaga(), | ||
]); | ||
} |
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.