uport-connect
Version:
Library for integrating uPort into your app frontend
572 lines (553 loc) • 10.7 kB
JavaScript
'use strict';
var cov_2oxemx8fnf = function () {
var path = '/Users/mxu/code/uport-connect/src/util.js',
hash = '793506c2ca48ba4665a20e33a1e8ed19d4cbc232',
Function = function () {}.constructor,
global = new Function('return this')(),
gcv = '__coverage__',
coverageData = {
path: '/Users/mxu/code/uport-connect/src/util.js',
statementMap: {
'0': {
start: {
line: 9,
column: 24
},
end: {
line: 13,
column: 1
}
},
'1': {
start: {
line: 10,
column: 2
},
end: {
line: 12,
column: 21
}
},
'2': {
start: {
line: 11,
column: 4
},
end: {
line: 11,
column: 61
}
},
'3': {
start: {
line: 12,
column: 9
},
end: {
line: 12,
column: 21
}
},
'4': {
start: {
line: 20,
column: 2
},
end: {
line: 20,
column: 38
}
},
'5': {
start: {
line: 28,
column: 2
},
end: {
line: 44,
column: 4
}
},
'6': {
start: {
line: 30,
column: 20
},
end: {
line: 30,
column: 34
}
},
'7': {
start: {
line: 31,
column: 4
},
end: {
line: 31,
column: 43
}
},
'8': {
start: {
line: 32,
column: 16
},
end: {
line: 32,
column: 36
}
},
'9': {
start: {
line: 34,
column: 4
},
end: {
line: 38,
column: 5
}
},
'10': {
start: {
line: 35,
column: 6
},
end: {
line: 35,
column: 38
}
},
'11': {
start: {
line: 35,
column: 32
},
end: {
line: 35,
column: 38
}
},
'12': {
start: {
line: 36,
column: 6
},
end: {
line: 37,
column: 53
}
},
'13': {
start: {
line: 36,
column: 29
},
end: {
line: 36,
column: 79
}
},
'14': {
start: {
line: 37,
column: 11
},
end: {
line: 37,
column: 53
}
},
'15': {
start: {
line: 40,
column: 4
},
end: {
line: 40,
column: 62
}
},
'16': {
start: {
line: 41,
column: 4
},
end: {
line: 41,
column: 53
}
},
'17': {
start: {
line: 42,
column: 4
},
end: {
line: 42,
column: 39
}
},
'18': {
start: {
line: 43,
column: 4
},
end: {
line: 43,
column: 21
}
}
},
fnMap: {
'0': {
name: '(anonymous_0)',
decl: {
start: {
line: 9,
column: 24
},
end: {
line: 9,
column: 25
}
},
loc: {
start: {
line: 9,
column: 30
},
end: {
line: 13,
column: 1
}
},
line: 9
},
'1': {
name: 'hasWeb3',
decl: {
start: {
line: 19,
column: 16
},
end: {
line: 19,
column: 23
}
},
loc: {
start: {
line: 19,
column: 26
},
end: {
line: 21,
column: 1
}
},
line: 19
},
'2': {
name: 'ipfsAdd',
decl: {
start: {
line: 27,
column: 16
},
end: {
line: 27,
column: 23
}
},
loc: {
start: {
line: 27,
column: 29
},
end: {
line: 45,
column: 1
}
},
line: 27
},
'3': {
name: '(anonymous_3)',
decl: {
start: {
line: 28,
column: 21
},
end: {
line: 28,
column: 22
}
},
loc: {
start: {
line: 28,
column: 42
},
end: {
line: 44,
column: 3
}
},
line: 28
},
'4': {
name: '(anonymous_4)',
decl: {
start: {
line: 34,
column: 29
},
end: {
line: 34,
column: 30
}
},
loc: {
start: {
line: 34,
column: 35
},
end: {
line: 38,
column: 5
}
},
line: 34
}
},
branchMap: {
'0': {
loc: {
start: {
line: 10,
column: 2
},
end: {
line: 12,
column: 21
}
},
type: 'if',
locations: [{
start: {
line: 10,
column: 2
},
end: {
line: 12,
column: 21
}
}, {
start: {
line: 10,
column: 2
},
end: {
line: 12,
column: 21
}
}],
line: 10
},
'1': {
loc: {
start: {
line: 35,
column: 6
},
end: {
line: 35,
column: 38
}
},
type: 'if',
locations: [{
start: {
line: 35,
column: 6
},
end: {
line: 35,
column: 38
}
}, {
start: {
line: 35,
column: 6
},
end: {
line: 35,
column: 38
}
}],
line: 35
},
'2': {
loc: {
start: {
line: 36,
column: 6
},
end: {
line: 37,
column: 53
}
},
type: 'if',
locations: [{
start: {
line: 36,
column: 6
},
end: {
line: 37,
column: 53
}
}, {
start: {
line: 36,
column: 6
},
end: {
line: 37,
column: 53
}
}],
line: 36
}
},
s: {
'0': 0,
'1': 0,
'2': 0,
'3': 0,
'4': 0,
'5': 0,
'6': 0,
'7': 0,
'8': 0,
'9': 0,
'10': 0,
'11': 0,
'12': 0,
'13': 0,
'14': 0,
'15': 0,
'16': 0,
'17': 0,
'18': 0
},
f: {
'0': 0,
'1': 0,
'2': 0,
'3': 0,
'4': 0
},
b: {
'0': [0, 0],
'1': [0, 0],
'2': [0, 0]
},
_coverageSchema: '332fd63041d2c1bcb487cc26dd0d5f7d97098a6c'
},
coverage = global[gcv] || (global[gcv] = {});
if (coverage[path] && coverage[path].hash === hash) {
return coverage[path];
}
coverageData.hash = hash;
return coverage[path] = coverageData;
}();
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isMobile = undefined;
var _promise = require('babel-runtime/core-js/promise');
var _promise2 = _interopRequireDefault(_promise);
exports.hasWeb3 = hasWeb3;
exports.ipfsAdd = ipfsAdd;
var _mobileDetect = require('mobile-detect');
var _mobileDetect2 = _interopRequireDefault(_mobileDetect);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* Detects if this library is called on a mobile device or tablet.
*
* @return {Boolean} Returns true if on mobile or tablet, false otherwise.
* @private
*/
cov_2oxemx8fnf.s[0]++;
var isMobile = exports.isMobile = function isMobile() {
cov_2oxemx8fnf.f[0]++;
cov_2oxemx8fnf.s[1]++;
if (typeof navigator !== 'undefined') {
cov_2oxemx8fnf.b[0][0]++;
cov_2oxemx8fnf.s[2]++;
return !!new _mobileDetect2.default(navigator.userAgent).mobile();
} else {
cov_2oxemx8fnf.b[0][1]++;
cov_2oxemx8fnf.s[3]++;
return false;
}
};
/**
* Detect whether the current window has an injected web3 instance
* @private
*/
function hasWeb3() {
cov_2oxemx8fnf.f[1]++;
cov_2oxemx8fnf.s[4]++;
return typeof web3 !== 'undefined';
}
/**
* Post a json document to ipfs
* @private
*/
function ipfsAdd(jwt) {
cov_2oxemx8fnf.f[2]++;
cov_2oxemx8fnf.s[5]++;
return new _promise2.default(function (resolve, reject) {
cov_2oxemx8fnf.f[3]++;
// Create new FormData to hold stringified JSON
var payload = (cov_2oxemx8fnf.s[6]++, new FormData());
cov_2oxemx8fnf.s[7]++;
payload.append("file", new Blob([jwt]));
var req = (cov_2oxemx8fnf.s[8]++, new XMLHttpRequest());
// Resolve to hash on success
cov_2oxemx8fnf.s[9]++;
req.onreadystatechange = function () {
cov_2oxemx8fnf.f[4]++;
cov_2oxemx8fnf.s[10]++;
if (req.readyState !== 4) {
cov_2oxemx8fnf.b[1][0]++;
cov_2oxemx8fnf.s[11]++;
return;
} else {
cov_2oxemx8fnf.b[1][1]++;
}cov_2oxemx8fnf.s[12]++;
if (req.status != 200) {
cov_2oxemx8fnf.b[2][0]++;
cov_2oxemx8fnf.s[13]++;
reject('Error ' + req.status + ': ' + req.responseText);
} else {
cov_2oxemx8fnf.b[2][1]++;
cov_2oxemx8fnf.s[14]++;
resolve(JSON.parse(req.responseText).Hash);
}
};
// Send request
cov_2oxemx8fnf.s[15]++;
req.open('POST', 'https://ipfs.infura.io:5001/api/v0/add');
cov_2oxemx8fnf.s[16]++;
req.setRequestHeader('accept', 'application/json');
cov_2oxemx8fnf.s[17]++;
req.enctype = 'multipart/form-data';
cov_2oxemx8fnf.s[18]++;
req.send(payload);
});
}