uport-transports
Advanced tools
Comparing version 0.0.46 to 0.0.47
@@ -90,7 +90,7 @@ 'use strict'; | ||
* | ||
* @param {String} jwt A JWT string | ||
* @param {String} message A request message (JWT), or if given URI will just return | ||
* @return {Staring} A valid request URI, including the given request token | ||
*/ | ||
var tokenRequest = function tokenRequest(jwt) { | ||
return 'https://id.uport.me/req/' + jwt; | ||
var messageToURI = function messageToURI(message) { | ||
return message.match('id.uport.me') ? message : 'https://id.uport.me/req/' + message; | ||
}; | ||
@@ -103,2 +103,2 @@ | ||
exports.isJWT = isJWT; | ||
exports.tokenRequest = tokenRequest; | ||
exports.messageToURI = messageToURI; |
@@ -40,3 +40,3 @@ 'use strict'; | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} uri a uport client request URI | ||
* @param {String} message a uport client request message | ||
* @return {Promise<Object, Error>} a function to close the QR modal | ||
@@ -52,5 +52,6 @@ */ | ||
if (!uriHandler) throw new Error('uriHandler function required'); | ||
return function (uri) { | ||
return function (message) { | ||
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var uri = (0, _util.messageToURI)(message); | ||
var callback = getCallback(uri); | ||
@@ -57,0 +58,0 @@ if (!isMessageServerCallback(uri, messageServerUrl)) throw new Error('Not a request that can be handled by this configured messaging server transport'); |
@@ -28,5 +28,4 @@ 'use strict'; | ||
* @return {Function} a configured Push transport function | ||
* @param {String} url a uport client request url | ||
* @param {String} message a uport client request message | ||
* @param {Object} [opts={}] an optional config object | ||
* @param {String} opts.message a message to display to the user | ||
* @param {String} opts.type specifies callback type 'post' or 'redirect' for response | ||
@@ -42,5 +41,4 @@ * @param {String} opts.callback specifies url which a uport client will return to control once the request is handled, depending on request type it may or may not be returned with the response as well. | ||
return function (url) { | ||
return function (message) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
message = _ref.message, | ||
type = _ref.type, | ||
@@ -50,8 +48,8 @@ redirectUrl = _ref.redirectUrl; | ||
return new Promise(function (resolve, reject) { | ||
if (!url) return reject(new Error('Requires url request for sending to users device')); | ||
if (type) url = (0, _util.paramsToQueryString)(url, { callback_type: type }); | ||
if (redirectUrl) url = (0, _util.paramsToQueryString)(url, { 'redirect_url': redirectUrl }); | ||
var reqObj = { url: url }; | ||
if (message) reqObj.message = message; | ||
var plaintext = padMessage(JSON.stringify(reqObj)); | ||
if (!message) return reject(new Error('Requires message request to send')); | ||
// TODO will need following comments if mobile consumes these url params instead of just request message/token | ||
// let url = messageToURI(reqMessage) | ||
// if (type) url = paramsToQueryString(url, {callback_type: type}) | ||
// if (redirectUrl) url = paramsToQueryString(url, {'redirect_url': redirectUrl}) | ||
var plaintext = padMessage(message); | ||
var enc = (0, _crypto.encryptMessage)(plaintext, pubEncKey); | ||
@@ -58,0 +56,0 @@ var payload = { message: JSON.stringify(enc) }; |
@@ -27,8 +27,9 @@ 'use strict'; | ||
* | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} uri a uport client request URI | ||
* @return {Function} a function to close the QR modal | ||
* @param {String} appName app name used in qr modal display | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} message a uport client request message | ||
* @return {Function} a function to close the QR modal | ||
*/ | ||
var send = function send(appName) { | ||
return function (uri) { | ||
return function (message) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
@@ -38,2 +39,3 @@ cancel = _ref.cancel, | ||
var uri = (0, _util.messageToURI)(message); | ||
uri = /callback_type=/.test(uri) ? uri : (0, _util.paramsToQueryString)(uri, { callback_type: 'post' }); | ||
@@ -53,3 +55,3 @@ open(uri, cancel, appName, introModal); | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} uri a uport client request URI | ||
* @param {String} message a uport client request message | ||
* @return {Promise<Object, Error>} a function to close the QR modal | ||
@@ -66,4 +68,4 @@ */ | ||
var transport = (0, _messageServer.URIHandlerSend)(send(appName), { chasquiUrl: chasquiUrl, pollingInterval: pollingInterval }); | ||
return function (uri, params) { | ||
return transport(uri, params).then(function (res) { | ||
return function (message, params) { | ||
return transport(message, params).then(function (res) { | ||
close(); | ||
@@ -70,0 +72,0 @@ return res; |
@@ -23,3 +23,3 @@ 'use strict'; | ||
* @return {Function} a configured MobileTransport Function | ||
* @param {String} uri a uport client request message | ||
* @param {String} message a uport client request message | ||
* @param {Object} [opts={}] an optional config object | ||
@@ -35,3 +35,3 @@ * @param {String} opts.id an id string for a request, used to identify response once returned | ||
return function (uri) { | ||
return function (message) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
@@ -43,8 +43,3 @@ id = _ref2.id, | ||
// what if has no protocol in passed in string, can probably go here | ||
// if( md.userAgent() === 'Chrome' && md.os() === 'iOS' ) { | ||
// url = 'googlechrome:' + window.location.href.substring(window.location.protocol.length) | ||
// } else { | ||
// url = window.location.href | ||
// } | ||
var uri = (0, _util.messageToURI)(message); | ||
if (type) uri = (0, _util.paramsToQueryString)(uri, { callback_type: type }); | ||
@@ -103,3 +98,3 @@ if (redirectUrl) { | ||
var parseResponse = function parseResponse(url) { | ||
var params = _qs2.default.parse(url.split('#')[0]); | ||
var params = _qs2.default.parse(url.split('#').pop()); | ||
if (params.id) { | ||
@@ -106,0 +101,0 @@ var payload = { data: params.data || null, id: params.id }; |
{ | ||
"name": "uport-transports", | ||
"version": "0.0.46", | ||
"version": "0.0.47", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -68,9 +68,9 @@ /** | ||
* | ||
* @param {String} jwt A JWT string | ||
* @param {String} message A request message (JWT), or if given URI will just return | ||
* @return {Staring} A valid request URI, including the given request token | ||
*/ | ||
const tokenRequest = (jwt) => `https://id.uport.me/req/${jwt}` | ||
const messageToURI = (message) => message.match('id.uport.me') ? message : `https://id.uport.me/req/${message}` | ||
export { paramsToUrlFragment, paramsToQueryString, getUrlQueryParams, getURLJWT, isJWT, tokenRequest } | ||
export { paramsToUrlFragment, paramsToQueryString, getUrlQueryParams, getURLJWT, isJWT, messageToURI } |
@@ -1,2 +0,2 @@ | ||
import { paramsToQueryString, getUrlQueryParams, getURLJWT } from './../message/util.js' | ||
import { paramsToQueryString, getUrlQueryParams, getURLJWT, messageToURI } from './../message/util.js' | ||
import { randomString } from './../crypto.js' | ||
@@ -22,3 +22,3 @@ import generalPoll from './poll.js' | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} uri a uport client request URI | ||
* @param {String} message a uport client request message | ||
* @return {Promise<Object, Error>} a function to close the QR modal | ||
@@ -28,3 +28,4 @@ */ | ||
if (!uriHandler) throw new Error('uriHandler function required') | ||
return (uri, params = {}) => { | ||
return (message, params = {}) => { | ||
let uri = messageToURI(message) | ||
const callback = getCallback(uri) | ||
@@ -31,0 +32,0 @@ if (!isMessageServerCallback(uri, messageServerUrl)) throw new Error('Not a request that can be handled by this configured messaging server transport') |
import { encryptMessage } from '../crypto.js' | ||
import { paramsToQueryString } from './../message/util.js' | ||
import { paramsToQueryString, messageToURI } from './../message/util.js' | ||
import nets from 'nets' | ||
@@ -14,5 +14,4 @@ const PUTUTU_URL = 'https://api.uport.me/pututu/sns' | ||
* @return {Function} a configured Push transport function | ||
* @param {String} url a uport client request url | ||
* @param {String} message a uport client request message | ||
* @param {Object} [opts={}] an optional config object | ||
* @param {String} opts.message a message to display to the user | ||
* @param {String} opts.type specifies callback type 'post' or 'redirect' for response | ||
@@ -26,9 +25,9 @@ * @param {String} opts.callback specifies url which a uport client will return to control once the request is handled, depending on request type it may or may not be returned with the response as well. | ||
return (url, {message, type, redirectUrl}={}) => new Promise((resolve, reject) => { | ||
if (!url) return reject(new Error('Requires url request for sending to users device')) | ||
if (type) url = paramsToQueryString(url, {callback_type: type}) | ||
if (redirectUrl) url = paramsToQueryString(url, {'redirect_url': redirectUrl}) | ||
const reqObj = {url} | ||
if (message) reqObj.message = message | ||
const plaintext = padMessage(JSON.stringify(reqObj)) | ||
return (message, { type, redirectUrl}={}) => new Promise((resolve, reject) => { | ||
if (!message) return reject(new Error('Requires message request to send')) | ||
// TODO will need following comments if mobile consumes these url params instead of just request message/token | ||
// let url = messageToURI(reqMessage) | ||
// if (type) url = paramsToQueryString(url, {callback_type: type}) | ||
// if (redirectUrl) url = paramsToQueryString(url, {'redirect_url': redirectUrl}) | ||
const plaintext = padMessage(message) | ||
const enc = encryptMessage(plaintext, pubEncKey) | ||
@@ -35,0 +34,0 @@ const payload = { message: JSON.stringify(enc) } |
import qrImage from 'qr-image' | ||
import SVG from './assets.js' | ||
import { paramsToQueryString, paramsToUrlFragment } from './../../message/util.js' | ||
import { paramsToQueryString, paramsToUrlFragment, messageToURI } from './../../message/util.js' | ||
import { URIHandlerSend, CHASQUI_URL } from './../messageServer.js' | ||
@@ -10,7 +10,9 @@ const POLLING_INTERVAL = 2000 | ||
* | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} uri a uport client request URI | ||
* @return {Function} a function to close the QR modal | ||
* @param {String} appName app name used in qr modal display | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} message a uport client request message | ||
* @return {Function} a function to close the QR modal | ||
*/ | ||
const send = (appName) => (uri, {cancel, introModal} = {}) => { | ||
const send = (appName) => (message, {cancel, introModal} = {}) => { | ||
let uri = messageToURI(message) | ||
uri = /callback_type=/.test(uri) ? uri : paramsToQueryString(uri, {callback_type: 'post'}) | ||
@@ -29,3 +31,3 @@ open(uri, cancel, appName, introModal) | ||
* @return {Function} a configured QRTransport Function | ||
* @param {String} uri a uport client request URI | ||
* @param {String} message a uport client request message | ||
* @return {Promise<Object, Error>} a function to close the QR modal | ||
@@ -35,3 +37,3 @@ */ | ||
const transport = URIHandlerSend(send(appName), {chasquiUrl, pollingInterval}) | ||
return (uri, params) => transport(uri, params).then(res => { | ||
return (message, params) => transport(message, params).then(res => { | ||
close() | ||
@@ -38,0 +40,0 @@ return res |
@@ -1,2 +0,2 @@ | ||
import { paramsToQueryString, paramsToUrlFragment } from './../message/util.js' | ||
import { paramsToQueryString, paramsToUrlFragment, messageToURI } from './../message/util.js' | ||
import qs from 'qs' | ||
@@ -11,3 +11,3 @@ | ||
* @return {Function} a configured MobileTransport Function | ||
* @param {String} uri a uport client request message | ||
* @param {String} message a uport client request message | ||
* @param {Object} [opts={}] an optional config object | ||
@@ -20,9 +20,4 @@ * @param {String} opts.id an id string for a request, used to identify response once returned | ||
const send = ({uriHandler}={}) => { | ||
return (uri, {id, data, type, redirectUrl} = {}) => { | ||
// what if has no protocol in passed in string, can probably go here | ||
// if( md.userAgent() === 'Chrome' && md.os() === 'iOS' ) { | ||
// url = 'googlechrome:' + window.location.href.substring(window.location.protocol.length) | ||
// } else { | ||
// url = window.location.href | ||
// } | ||
return (message, {id, data, type, redirectUrl} = {}) => { | ||
let uri = messageToURI(message) | ||
if (type) uri = paramsToQueryString(uri, {callback_type: type}) | ||
@@ -77,3 +72,3 @@ if (redirectUrl) { | ||
const parseResponse = (url) => { | ||
const params = qs.parse(url.split('#')[0]) | ||
const params = qs.parse(url.split('#').pop()) | ||
if (params.id) { | ||
@@ -80,0 +75,0 @@ const payload = { data: params.data || null, id: params.id} |
@@ -7,7 +7,4 @@ import * as util from './../../src/message/util.js' | ||
// TODO removed unsigned reqs and use new urls | ||
const request = 'https://id.uport.me/req/eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vY2hhc3F1aS51cG9ydC5tZS9hcGkvdjEvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDp1cG9ydDoyb2VYdWZIR0RwVTUxYmZLQnNaRGR1N0plOXdlSjNyN3NWRyJ9.ISlUPHoqmGru_MfwjGzq1xxuTKeYIVr4V7g40HeUVsZ-j_gxOkJSzYsTd7AGpth-CwjaPmFLGXnyDG2aiE7NXA' | ||
// const unsignedRequest = `https://id.uport.me/me` | ||
const request = 'https://id.uport.me/req/eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vY2hhc3F1aS51cG9ydC5tZS9hcGkvdjEvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDp1cG9ydDoyb2VYdWZIR0RwVTUxYmZLQnNaRGR1N0plOXdlSjNyN3NWRyJ9.ISlUPHoqmGru_MfwjGzq1xxuTKeYIVr4V7g40HeUVsZ-j_gxOkJSzYsTd7AGpth-CwjaPmFLGXnyDG2aiE7NXA' | ||
// const signedRequest = `https://id.uport.me/me?requestToken=eyJ0eXAiOiJK` | ||
const data = 'dataString' | ||
@@ -14,0 +11,0 @@ const id = 'idString' |
@@ -28,2 +28,3 @@ // import { expect } from 'chai' | ||
const randomString = sinon.stub().returns(ranStr) | ||
const requestMessage = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vY2hhc3F1aS51cG9ydC5tZS9hcGkvdjEvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDp1cG9ydDoyb2VYdWZIR0RwVTUxYmZLQnNaRGR1N0plOXdlSjNyN3NWRyJ9.ISlUPHoqmGru_MfwjGzq1xxuTKeYIVr4V7g40HeUVsZ-j_gxOkJSzYsTd7AGpth-CwjaPmFLGXnyDG2aiE7NXA' | ||
const uri = 'https://id.uport.me/req/eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vY2hhc3F1aS51cG9ydC5tZS9hcGkvdjEvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDp1cG9ydDoyb2VYdWZIR0RwVTUxYmZLQnNaRGR1N0plOXdlSjNyN3NWRyJ9.ISlUPHoqmGru_MfwjGzq1xxuTKeYIVr4V7g40HeUVsZ-j_gxOkJSzYsTd7AGpth-CwjaPmFLGXnyDG2aiE7NXA' | ||
@@ -41,3 +42,3 @@ let URIHandlerSend | ||
it('Uses uPort chasqui as default messaging server', () => { | ||
return URIHandlerSend(uri).then(res => { | ||
return URIHandlerSend(requestMessage).then(res => { | ||
expect(uriHandler).to.have.been.calledWithMatch(uri) | ||
@@ -48,3 +49,3 @@ }) | ||
it('Adds "post" as type url param', () => { | ||
return URIHandlerSend(uri).then(res => { | ||
return URIHandlerSend(requestMessage).then(res => { | ||
expect(uriHandler).to.have.been.calledWithMatch(`type=post`) | ||
@@ -55,3 +56,3 @@ }) | ||
it('Polls messaging server at cb for a response', () => { | ||
return URIHandlerSend(uri).then(res => { | ||
return URIHandlerSend(requestMessage).then(res => { | ||
expect(pollGeneral).to.have.been.calledWith(CHASQUI_URL + ranStr) | ||
@@ -58,0 +59,0 @@ }) |
@@ -7,4 +7,4 @@ import * as url from './../../src/transport/url.js' | ||
const unsignedRequest = `https://id.uport.me/me` | ||
const signedRequest = `https://id.uport.me/me?requestToken=eyJ0eXAiOiJK` | ||
const requestMessage = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1Mjk5NTQxMjcsImV4cCI6MTUyOTk1NDcyNywicmVxdWVzdGVkIjpbIm5hbWUiLCJwaG9uZSIsImNvdW50cnkiXSwicGVybWlzc2lvbnMiOlsibm90aWZpY2F0aW9ucyJdLCJjYWxsYmFjayI6Imh0dHBzOi8vY2hhc3F1aS51cG9ydC5tZS9hcGkvdjEvdG9waWMvYVZLY0VkNWp6bm1Xc2xqMyIsInR5cGUiOiJzaGFyZVJlcSIsImlzcyI6ImRpZDp1cG9ydDoyb2VYdWZIR0RwVTUxYmZLQnNaRGR1N0plOXdlSjNyN3NWRyJ9.ISlUPHoqmGru_MfwjGzq1xxuTKeYIVr4V7g40HeUVsZ-j_gxOkJSzYsTd7AGpth-CwjaPmFLGXnyDG2aiE7NXA' | ||
const windowUrl = 'thiswindow.url' | ||
@@ -30,3 +30,3 @@ const res = 'eyJ0eXAiOiJK' | ||
global.window = {location : {href: windowUrl, assign}} | ||
send(signedRequest, {type: 'post'}) | ||
send(requestMessage, {type: 'post'}) | ||
expect(assign).to.be.calledWithMatch('type=post') | ||
@@ -39,3 +39,3 @@ }) | ||
const redirectUrl = 'https://myserver.web' | ||
send(signedRequest, {redirectUrl}) | ||
send(requestMessage, {redirectUrl}) | ||
expect(assign).to.be.calledWithMatch(`redirect_url=${encodeURIComponent(redirectUrl)}`) | ||
@@ -48,3 +48,3 @@ }) | ||
const redirectUrl = 'https://myserver.web' | ||
send(unsignedRequest, {id: 'idString', redirectUrl}) | ||
send(requestMessage, {id: 'idString', redirectUrl}) | ||
expect(assign).to.be.calledWithMatch(encodeURIComponent('id=idString')) | ||
@@ -57,3 +57,3 @@ }) | ||
const redirectUrl = 'https://myserver.web' | ||
send(unsignedRequest, {data: 'dataString', redirectUrl}) | ||
send(requestMessage, {data: 'dataString', redirectUrl}) | ||
expect(assign).to.be.calledWithMatch(encodeURIComponent('data=dataString')) | ||
@@ -60,0 +60,0 @@ }) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
345458
6
2951