-
-
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.
Merge branch 'feature/my-device-qr-screen'
- Loading branch information
Showing
22 changed files
with
395 additions
and
147 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
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 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,80 @@ | ||
import _ from 'lodash'; | ||
import Crypto from 'crypto'; | ||
import obyte from 'obyte'; | ||
import { common } from './../constants'; | ||
|
||
|
||
export const testnet = common.network === 'testnet'; | ||
|
||
export const hubAddress = common.network === 'testnet' | ||
? 'obyte.org/bb-test' | ||
: 'obyte.org/bb'; | ||
|
||
export const oClient = common.network === 'testnet' | ||
? new obyte.Client('wss://obyte.org/bb-test', { testnet }) | ||
: new obyte.Client('wss://obyte.org/bb'); | ||
|
||
export const urlHost = common.network === 'testnet' | ||
? 'obyte-tn:' | ||
: 'obyte:'; | ||
|
||
export const getDeviceMessageHashToSign = (objDeviceMessage) => { | ||
var objNakedDeviceMessage = _.clone(objDeviceMessage); | ||
delete objNakedDeviceMessage.signature; | ||
cleanNullsDeep(objNakedDeviceMessage); // device messages have free format and we can't guarantee absence of malicious fields | ||
return Crypto.createHash('sha256').update(getSourceString(objNakedDeviceMessage), 'utf8').digest(); | ||
} | ||
|
||
function getSourceString(obj) { | ||
var arrComponents = []; | ||
function extractComponents(variable) { | ||
if (variable === null) | ||
throw Error("null value in " + JSON.stringify(obj)); | ||
switch (typeof variable) { | ||
case "string": | ||
arrComponents.push("s", variable); | ||
break; | ||
case "number": | ||
arrComponents.push("n", variable.toString()); | ||
break; | ||
case "boolean": | ||
arrComponents.push("b", variable.toString()); | ||
break; | ||
case "object": | ||
if (Array.isArray(variable)) { | ||
if (variable.length === 0) | ||
throw Error("empty array in " + JSON.stringify(obj)); | ||
arrComponents.push('['); | ||
for (var i = 0; i < variable.length; i++) | ||
extractComponents(variable[i]); | ||
arrComponents.push(']'); | ||
} | ||
else { | ||
var keys = Object.keys(variable).sort(); | ||
if (keys.length === 0) | ||
throw Error("empty object in " + JSON.stringify(obj)); | ||
keys.forEach(function (key) { | ||
if (typeof variable[key] === "undefined") | ||
throw Error("undefined at " + key + " of " + JSON.stringify(obj)); | ||
arrComponents.push(key); | ||
extractComponents(variable[key]); | ||
}); | ||
} | ||
break; | ||
default: | ||
throw Error("getSourceString: unknown type=" + (typeof variable) + " of " + variable + ", object: " + JSON.stringify(obj)); | ||
} | ||
} | ||
|
||
extractComponents(obj); | ||
return arrComponents.join("\x00"); | ||
} | ||
|
||
export const cleanNullsDeep = (obj) => { | ||
Object.keys(obj).forEach(function (key) { | ||
if (obj[key] === null) | ||
delete obj[key]; | ||
else if (typeof obj[key] === 'object') | ||
cleanNullsDeep(obj[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
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
Oops, something went wrong.