uport-core
Advanced tools
Comparing version 0.0.18 to 0.0.19
{ | ||
"name": "uport-core", | ||
"version": "0.0.18", | ||
"version": "0.0.19", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -1,2 +0,1 @@ | ||
// TODO make so the following funcs don't necessarily need to be used and order, and they are redundant. | ||
/** | ||
@@ -34,3 +33,16 @@ * Add params as url fragment (hash params) | ||
/** | ||
* Returns params object of query params in given url | ||
* | ||
* @param {String} url a url | ||
* @return {Object} object of param key and values | ||
*/ | ||
const getUrlQueryParams = (url) => ( | ||
url.match(/[^&?]*?=[^&?]*/g) | ||
.map((param) => param.split('=')) | ||
.reduce((params, param) => { | ||
params[param[0]] = param[1] | ||
return params | ||
}, {})) | ||
export { paramsToUrlFragment, paramsToQueryString } | ||
export { paramsToUrlFragment, paramsToQueryString, getUrlQueryParams } |
@@ -1,4 +0,5 @@ | ||
import { paramsToQueryString } from './../message/util.js' | ||
import { paramsToQueryString, getUrlQueryParams } from './../message/util.js' | ||
import { randomString } from './../crypto/index.js' | ||
import generalPoll from './poll.js' | ||
import { decodeJWT } from 'did-jwt' | ||
import nets from 'nets' | ||
@@ -27,8 +28,8 @@ const CHASQUI_URL = 'https://chasqui.uport.me/api/v1/topic/' | ||
return (uri) => { | ||
const callback = getCallback(uri) | ||
let isCancelled = false | ||
const cancel = () => { isCancelled = true } | ||
const cb = chasquiUrl + randomString(16) | ||
uri = paramsToQueryString(uri, {'callback_url': cb, 'type': 'post'}) | ||
uri = paramsToQueryString(uri, {'type': 'post'}) | ||
uriHandler(uri, { cancel }) | ||
const returnVal = poll(cb, pollingInterval, () => isCancelled) | ||
const returnVal = poll(callback, pollingInterval, () => isCancelled) | ||
returnVal.cancel = cancel | ||
@@ -66,4 +67,10 @@ return returnVal | ||
const genCallback = () => `https://chasqui.uport.me/api/v1/topic/${crypto.randomString(16)}` | ||
const isChasquiCallback = (uri) => new RegExp(CHASQUI_URL).test(getCallback(uri)) | ||
const getCallback = (uri) => decodeJWT(getUrlQueryParams(uri)['requestToken']).payload.callback | ||
export { URIHandlerSend, | ||
poll, | ||
clearResponse } | ||
clearResponse, | ||
genCallback, | ||
isChasquiCallback } |
@@ -34,4 +34,4 @@ import qrImage from 'qr-image' | ||
*/ | ||
const chasquiSend = ({chasquiUrl = CHASQUI_URL, pollingInterval = POLLING_INTERVAL} = {}) => { | ||
const transport = URIHandlerSend(send(), {chasquiUrl, pollingInterval}) | ||
const chasquiSend = ({chasquiUrl = CHASQUI_URL, pollingInterval = POLLING_INTERVAL, appName } = {}) => { | ||
const transport = URIHandlerSend(send(appName), {chasquiUrl, pollingInterval}) | ||
return (uri) => transport(uri).then(res => { | ||
@@ -38,0 +38,0 @@ close() |
3
103594
31
1635