Skip to content

Commit

Permalink
Merge pull request #50 from zippiehq/master
Browse files Browse the repository at this point in the history
Alpha 9 RC4
  • Loading branch information
Tom Swindell authored Mar 11, 2019
2 parents 2c6a352 + d9f1caa commit ec7cd62
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "index.js",
"scripts": {
"build": "webpack --config webpack.prod.config.js",
"dev": "webpack --config webpack.dev.config.js; webpack-dev-server --config webpack.dev.config.js"
"start": "webpack-dev-server --config webpack.dev.config.js"
},
"author": "Zippie Ltd.",
"license": "Commercial/AGPLv3",
Expand Down
33 changes: 31 additions & 2 deletions src/plugins/ipc_router.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* SOFTWARE.
*/

import * as utils from '../utils'

/**
* IPCRouter creates sub iframes and forwards messages
* for the purpose of enabling secure communication between dapps
Expand Down Expand Up @@ -73,6 +75,7 @@ export default class IPCRouter {
let req = event.data
var params = req.IPCRouterRequest

console.info('[IPCRouter]: Attempting to launch API:', params)
if(this._ipc_iframes[params.target] === undefined) {

let isPermitted = true // FIXME
Expand Down Expand Up @@ -104,8 +107,34 @@ export default class IPCRouter {
iframe.sandbox += ' allow-storage-access-by-user-activation'
iframe.sandbox += ' allow-same-origin'
iframe.sandbox += ' allow-scripts'

iframe.src = params.target;

// Decompose URI for parameter injection
let uri = params.target
let host = uri.split('#')[0]
let hash = uri.split('#')[1]
hash = (hash || '').split('?')[0]

// Collect hash parameters into params object.
let appParams = utils.hashToParams(uri)

// Inject ipc-mode flag
appParams['ipc-mode'] = true

// Recombine params into paramstr for URI building
let paramstr = ''
Object.keys(appParams).forEach(k => {
if (typeof(appParams[k]) === 'boolean' && appParams[k]) {
paramstr += (paramstr.length > 0 ? ';' : '') + k
} else {
paramstr += (paramstr.length > 0 ? ';' : '') + k + '=' + appParams[k]
}
})

// Reconstitute full application URI
hash = hash + (paramstr.length > 0 ? '?' + paramstr : '')
uri = host + (hash.length > 0 ? '#' + hash : '')

iframe.src = uri
document.body.appendChild(iframe)

this._ipc_iframes[params.target] = iframe
Expand Down
1 change: 0 additions & 1 deletion src/plugins/userdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ export default class {
const masterkey = await this.derive(keyhash)

const authkey = await masterkey.derive('m/0')
const authpub = secp256k1.publicKeyConvert(authkey.publicKey, false)

let cipher = await this.fms.fetch(authkey.privateKey)
if (!cipher) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function hashToParams (uri) {
let qparts = query.split(';')
for (let i = 0; i < qparts.length; i++) {
let kv = qparts[i].split('=')
params[kv[0]] = kv[1] ? (decodeURI(kv[1])) : true
params[kv[0]] = kv[1] ? (decodeURIComponent(kv[1])) : true
}
}

Expand Down
30 changes: 17 additions & 13 deletions src/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,22 +553,26 @@ export default class Vault {
console.info('VAULT: Creating enrollment registry')
await this.enroll('device', deviceName, localpub.toString('hex'), { userAgent: navigator.userAgent })

// XXX Refactor
console.info('VAULT: Processing user parameters:', params)
if (params['name']) {
this.store.setItem('user.name', params['name'])
await this.userdata.set.bind(this)({data: {userdata: { set: {key: 'user.name', value: params['name']}}}})
let passport = {}

if ('recover' in this.params) {
console.info('VAULT: Attempting to get identity passport userdata.')
try {
passport = await this.userdata.get.bind(this)({data: {userdata: { get: {key: 'passport'}}}})
} catch (e) {
console.warn('VAULT: Failed to get passport userdata.')
}
}

if (params['email']) {
this.store.setItem('user.email', params['email'])
await this.userdata.set.bind(this)({data: {userdata: { set: {key: 'user.email', value: params['email']}}}})
}
// XXX Still need a better, more robust way to do this.
console.info('VAULT: Processing user parameters:', params)
if (params['name']) passport.fullname = params['name']
if (params['email']) passport.email = params['email']
if (params['lang']) passport.language = params['lang']
if (params['phone']) passport.phone = params['phone']

if (params['lang']) {
this.store.setItem('user.lang', params['lang'])
await this.userdata.set.bind(this)({data: {userdata: { set: {key: 'user.lang', value: params['lang']}}}})
}
console.info('VAULT: Uploading user passport data.')
await this.userdata.set.bind(this)({data: {userdata: { set: {key: 'passport', value: passport}}}})

console.info('VAULT: New identity created successfully!')
this._isSetup = true
Expand Down
2 changes: 1 addition & 1 deletion webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = {
devServer: {
https: true,
host: '0.0.0.0',
port: 8443,
port: process.env.APP_PORT || '8443',
compress: true,
contentBase: './dist',
hot: true
Expand Down

0 comments on commit ec7cd62

Please sign in to comment.