forked from Mirrors/doipjs
Release 0.11.0
This commit is contained in:
parent
ef48a9535c
commit
75c8ce3626
7 changed files with 766 additions and 35 deletions
|
@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [0.11.0] - 2021-03-05
|
||||
## Added
|
||||
- IRC service provider
|
||||
- Matrix service provider
|
||||
|
|
781
dist/doip.js
vendored
781
dist/doip.js
vendored
|
@ -133,6 +133,121 @@ module.exports = mkrequest => (...args) => {
|
|||
|
||||
},{}],4:[function(require,module,exports){
|
||||
'use strict';
|
||||
var token = '%[a-f0-9]{2}';
|
||||
var singleMatcher = new RegExp(token, 'gi');
|
||||
var multiMatcher = new RegExp('(' + token + ')+', 'gi');
|
||||
|
||||
function decodeComponents(components, split) {
|
||||
try {
|
||||
// Try to decode the entire string first
|
||||
return decodeURIComponent(components.join(''));
|
||||
} catch (err) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
if (components.length === 1) {
|
||||
return components;
|
||||
}
|
||||
|
||||
split = split || 1;
|
||||
|
||||
// Split the array in 2 parts
|
||||
var left = components.slice(0, split);
|
||||
var right = components.slice(split);
|
||||
|
||||
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right));
|
||||
}
|
||||
|
||||
function decode(input) {
|
||||
try {
|
||||
return decodeURIComponent(input);
|
||||
} catch (err) {
|
||||
var tokens = input.match(singleMatcher);
|
||||
|
||||
for (var i = 1; i < tokens.length; i++) {
|
||||
input = decodeComponents(tokens, i).join('');
|
||||
|
||||
tokens = input.match(singleMatcher);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
function customDecodeURIComponent(input) {
|
||||
// Keep track of all the replacements and prefill the map with the `BOM`
|
||||
var replaceMap = {
|
||||
'%FE%FF': '\uFFFD\uFFFD',
|
||||
'%FF%FE': '\uFFFD\uFFFD'
|
||||
};
|
||||
|
||||
var match = multiMatcher.exec(input);
|
||||
while (match) {
|
||||
try {
|
||||
// Decode as big chunks as possible
|
||||
replaceMap[match[0]] = decodeURIComponent(match[0]);
|
||||
} catch (err) {
|
||||
var result = decode(match[0]);
|
||||
|
||||
if (result !== match[0]) {
|
||||
replaceMap[match[0]] = result;
|
||||
}
|
||||
}
|
||||
|
||||
match = multiMatcher.exec(input);
|
||||
}
|
||||
|
||||
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else
|
||||
replaceMap['%C2'] = '\uFFFD';
|
||||
|
||||
var entries = Object.keys(replaceMap);
|
||||
|
||||
for (var i = 0; i < entries.length; i++) {
|
||||
// Replace all decoded components
|
||||
var key = entries[i];
|
||||
input = input.replace(new RegExp(key, 'g'), replaceMap[key]);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
module.exports = function (encodedURI) {
|
||||
if (typeof encodedURI !== 'string') {
|
||||
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`');
|
||||
}
|
||||
|
||||
try {
|
||||
encodedURI = encodedURI.replace(/\+/g, ' ');
|
||||
|
||||
// Try the built in decoder first
|
||||
return decodeURIComponent(encodedURI);
|
||||
} catch (err) {
|
||||
// Fallback to a more advanced decoder
|
||||
return customDecodeURIComponent(encodedURI);
|
||||
}
|
||||
};
|
||||
|
||||
},{}],5:[function(require,module,exports){
|
||||
'use strict';
|
||||
module.exports = function (obj, predicate) {
|
||||
var ret = {};
|
||||
var keys = Object.keys(obj);
|
||||
var isArr = Array.isArray(predicate);
|
||||
|
||||
for (var i = 0; i < keys.length; i++) {
|
||||
var key = keys[i];
|
||||
var val = obj[key];
|
||||
|
||||
if (isArr ? predicate.indexOf(key) !== -1 : predicate(key, val, obj)) {
|
||||
ret[key] = val;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
},{}],6:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
module.exports = value => {
|
||||
if (Object.prototype.toString.call(value) !== '[object Object]') {
|
||||
|
@ -143,7 +258,7 @@ module.exports = value => {
|
|||
return prototype === null || prototype === Object.prototype;
|
||||
};
|
||||
|
||||
},{}],5:[function(require,module,exports){
|
||||
},{}],7:[function(require,module,exports){
|
||||
'use strict';
|
||||
const isOptionObject = require('is-plain-obj');
|
||||
|
||||
|
@ -316,7 +431,7 @@ module.exports = function (...options) {
|
|||
return merged._;
|
||||
};
|
||||
|
||||
},{"is-plain-obj":4}],6:[function(require,module,exports){
|
||||
},{"is-plain-obj":6}],8:[function(require,module,exports){
|
||||
(function (process){(function (){
|
||||
// 'path' module extracted from Node.js v8.11.1 (only the posix part)
|
||||
// transplited with Babel
|
||||
|
@ -849,7 +964,7 @@ posix.posix = posix;
|
|||
module.exports = posix;
|
||||
|
||||
}).call(this)}).call(this,require('_process'))
|
||||
},{"_process":7}],7:[function(require,module,exports){
|
||||
},{"_process":9}],9:[function(require,module,exports){
|
||||
// shim for using process in browser
|
||||
var process = module.exports = {};
|
||||
|
||||
|
@ -1035,7 +1150,441 @@ process.chdir = function (dir) {
|
|||
};
|
||||
process.umask = function() { return 0; };
|
||||
|
||||
},{}],8:[function(require,module,exports){
|
||||
},{}],10:[function(require,module,exports){
|
||||
'use strict';
|
||||
const strictUriEncode = require('strict-uri-encode');
|
||||
const decodeComponent = require('decode-uri-component');
|
||||
const splitOnFirst = require('split-on-first');
|
||||
const filterObject = require('filter-obj');
|
||||
|
||||
const isNullOrUndefined = value => value === null || value === undefined;
|
||||
|
||||
function encoderForArrayFormat(options) {
|
||||
switch (options.arrayFormat) {
|
||||
case 'index':
|
||||
return key => (result, value) => {
|
||||
const index = result.length;
|
||||
|
||||
if (
|
||||
value === undefined ||
|
||||
(options.skipNull && value === null) ||
|
||||
(options.skipEmptyString && value === '')
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
return [...result, [encode(key, options), '[', index, ']'].join('')];
|
||||
}
|
||||
|
||||
return [
|
||||
...result,
|
||||
[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('')
|
||||
];
|
||||
};
|
||||
|
||||
case 'bracket':
|
||||
return key => (result, value) => {
|
||||
if (
|
||||
value === undefined ||
|
||||
(options.skipNull && value === null) ||
|
||||
(options.skipEmptyString && value === '')
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
return [...result, [encode(key, options), '[]'].join('')];
|
||||
}
|
||||
|
||||
return [...result, [encode(key, options), '[]=', encode(value, options)].join('')];
|
||||
};
|
||||
|
||||
case 'comma':
|
||||
case 'separator':
|
||||
return key => (result, value) => {
|
||||
if (value === null || value === undefined || value.length === 0) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (result.length === 0) {
|
||||
return [[encode(key, options), '=', encode(value, options)].join('')];
|
||||
}
|
||||
|
||||
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
|
||||
};
|
||||
|
||||
default:
|
||||
return key => (result, value) => {
|
||||
if (
|
||||
value === undefined ||
|
||||
(options.skipNull && value === null) ||
|
||||
(options.skipEmptyString && value === '')
|
||||
) {
|
||||
return result;
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
return [...result, encode(key, options)];
|
||||
}
|
||||
|
||||
return [...result, [encode(key, options), '=', encode(value, options)].join('')];
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function parserForArrayFormat(options) {
|
||||
let result;
|
||||
|
||||
switch (options.arrayFormat) {
|
||||
case 'index':
|
||||
return (key, value, accumulator) => {
|
||||
result = /\[(\d*)\]$/.exec(key);
|
||||
|
||||
key = key.replace(/\[\d*\]$/, '');
|
||||
|
||||
if (!result) {
|
||||
accumulator[key] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (accumulator[key] === undefined) {
|
||||
accumulator[key] = {};
|
||||
}
|
||||
|
||||
accumulator[key][result[1]] = value;
|
||||
};
|
||||
|
||||
case 'bracket':
|
||||
return (key, value, accumulator) => {
|
||||
result = /(\[\])$/.exec(key);
|
||||
key = key.replace(/\[\]$/, '');
|
||||
|
||||
if (!result) {
|
||||
accumulator[key] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
if (accumulator[key] === undefined) {
|
||||
accumulator[key] = [value];
|
||||
return;
|
||||
}
|
||||
|
||||
accumulator[key] = [].concat(accumulator[key], value);
|
||||
};
|
||||
|
||||
case 'comma':
|
||||
case 'separator':
|
||||
return (key, value, accumulator) => {
|
||||
const isArray = typeof value === 'string' && value.includes(options.arrayFormatSeparator);
|
||||
const isEncodedArray = (typeof value === 'string' && !isArray && decode(value, options).includes(options.arrayFormatSeparator));
|
||||
value = isEncodedArray ? decode(value, options) : value;
|
||||
const newValue = isArray || isEncodedArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options);
|
||||
accumulator[key] = newValue;
|
||||
};
|
||||
|
||||
default:
|
||||
return (key, value, accumulator) => {
|
||||
if (accumulator[key] === undefined) {
|
||||
accumulator[key] = value;
|
||||
return;
|
||||
}
|
||||
|
||||
accumulator[key] = [].concat(accumulator[key], value);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
function validateArrayFormatSeparator(value) {
|
||||
if (typeof value !== 'string' || value.length !== 1) {
|
||||
throw new TypeError('arrayFormatSeparator must be single character string');
|
||||
}
|
||||
}
|
||||
|
||||
function encode(value, options) {
|
||||
if (options.encode) {
|
||||
return options.strict ? strictUriEncode(value) : encodeURIComponent(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function decode(value, options) {
|
||||
if (options.decode) {
|
||||
return decodeComponent(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function keysSorter(input) {
|
||||
if (Array.isArray(input)) {
|
||||
return input.sort();
|
||||
}
|
||||
|
||||
if (typeof input === 'object') {
|
||||
return keysSorter(Object.keys(input))
|
||||
.sort((a, b) => Number(a) - Number(b))
|
||||
.map(key => input[key]);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
function removeHash(input) {
|
||||
const hashStart = input.indexOf('#');
|
||||
if (hashStart !== -1) {
|
||||
input = input.slice(0, hashStart);
|
||||
}
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
function getHash(url) {
|
||||
let hash = '';
|
||||
const hashStart = url.indexOf('#');
|
||||
if (hashStart !== -1) {
|
||||
hash = url.slice(hashStart);
|
||||
}
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
function extract(input) {
|
||||
input = removeHash(input);
|
||||
const queryStart = input.indexOf('?');
|
||||
if (queryStart === -1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return input.slice(queryStart + 1);
|
||||
}
|
||||
|
||||
function parseValue(value, options) {
|
||||
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) {
|
||||
value = Number(value);
|
||||
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) {
|
||||
value = value.toLowerCase() === 'true';
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function parse(query, options) {
|
||||
options = Object.assign({
|
||||
decode: true,
|
||||
sort: true,
|
||||
arrayFormat: 'none',
|
||||
arrayFormatSeparator: ',',
|
||||
parseNumbers: false,
|
||||
parseBooleans: false
|
||||
}, options);
|
||||
|
||||
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
||||
|
||||
const formatter = parserForArrayFormat(options);
|
||||
|
||||
// Create an object with no prototype
|
||||
const ret = Object.create(null);
|
||||
|
||||
if (typeof query !== 'string') {
|
||||
return ret;
|
||||
}
|
||||
|
||||
query = query.trim().replace(/^[?#&]/, '');
|
||||
|
||||
if (!query) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (const param of query.split('&')) {
|
||||
if (param === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '=');
|
||||
|
||||
// Missing `=` should be `null`:
|
||||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
||||
value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options);
|
||||
formatter(decode(key, options), value, ret);
|
||||
}
|
||||
|
||||
for (const key of Object.keys(ret)) {
|
||||
const value = ret[key];
|
||||
if (typeof value === 'object' && value !== null) {
|
||||
for (const k of Object.keys(value)) {
|
||||
value[k] = parseValue(value[k], options);
|
||||
}
|
||||
} else {
|
||||
ret[key] = parseValue(value, options);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.sort === false) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => {
|
||||
const value = ret[key];
|
||||
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) {
|
||||
// Sort object keys, not values
|
||||
result[key] = keysSorter(value);
|
||||
} else {
|
||||
result[key] = value;
|
||||
}
|
||||
|
||||
return result;
|
||||
}, Object.create(null));
|
||||
}
|
||||
|
||||
exports.extract = extract;
|
||||
exports.parse = parse;
|
||||
|
||||
exports.stringify = (object, options) => {
|
||||
if (!object) {
|
||||
return '';
|
||||
}
|
||||
|
||||
options = Object.assign({
|
||||
encode: true,
|
||||
strict: true,
|
||||
arrayFormat: 'none',
|
||||
arrayFormatSeparator: ','
|
||||
}, options);
|
||||
|
||||
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
||||
|
||||
const shouldFilter = key => (
|
||||
(options.skipNull && isNullOrUndefined(object[key])) ||
|
||||
(options.skipEmptyString && object[key] === '')
|
||||
);
|
||||
|
||||
const formatter = encoderForArrayFormat(options);
|
||||
|
||||
const objectCopy = {};
|
||||
|
||||
for (const key of Object.keys(object)) {
|
||||
if (!shouldFilter(key)) {
|
||||
objectCopy[key] = object[key];
|
||||
}
|
||||
}
|
||||
|
||||
const keys = Object.keys(objectCopy);
|
||||
|
||||
if (options.sort !== false) {
|
||||
keys.sort(options.sort);
|
||||
}
|
||||
|
||||
return keys.map(key => {
|
||||
const value = object[key];
|
||||
|
||||
if (value === undefined) {
|
||||
return '';
|
||||
}
|
||||
|
||||
if (value === null) {
|
||||
return encode(key, options);
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value
|
||||
.reduce(formatter(key), [])
|
||||
.join('&');
|
||||
}
|
||||
|
||||
return encode(key, options) + '=' + encode(value, options);
|
||||
}).filter(x => x.length > 0).join('&');
|
||||
};
|
||||
|
||||
exports.parseUrl = (url, options) => {
|
||||
options = Object.assign({
|
||||
decode: true
|
||||
}, options);
|
||||
|
||||
const [url_, hash] = splitOnFirst(url, '#');
|
||||
|
||||
return Object.assign(
|
||||
{
|
||||
url: url_.split('?')[0] || '',
|
||||
query: parse(extract(url), options)
|
||||
},
|
||||
options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
|
||||
);
|
||||
};
|
||||
|
||||
exports.stringifyUrl = (object, options) => {
|
||||
options = Object.assign({
|
||||
encode: true,
|
||||
strict: true
|
||||
}, options);
|
||||
|
||||
const url = removeHash(object.url).split('?')[0] || '';
|
||||
const queryFromUrl = exports.extract(object.url);
|
||||
const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false});
|
||||
|
||||
const query = Object.assign(parsedQueryFromUrl, object.query);
|
||||
let queryString = exports.stringify(query, options);
|
||||
if (queryString) {
|
||||
queryString = `?${queryString}`;
|
||||
}
|
||||
|
||||
let hash = getHash(object.url);
|
||||
if (object.fragmentIdentifier) {
|
||||
hash = `#${encode(object.fragmentIdentifier, options)}`;
|
||||
}
|
||||
|
||||
return `${url}${queryString}${hash}`;
|
||||
};
|
||||
|
||||
exports.pick = (input, filter, options) => {
|
||||
options = Object.assign({
|
||||
parseFragmentIdentifier: true
|
||||
}, options);
|
||||
|
||||
const {url, query, fragmentIdentifier} = exports.parseUrl(input, options);
|
||||
return exports.stringifyUrl({
|
||||
url,
|
||||
query: filterObject(query, filter),
|
||||
fragmentIdentifier
|
||||
}, options);
|
||||
};
|
||||
|
||||
exports.exclude = (input, filter, options) => {
|
||||
const exclusionFilter = Array.isArray(filter) ? key => !filter.includes(key) : (key, value) => !filter(key, value);
|
||||
|
||||
return exports.pick(input, exclusionFilter, options);
|
||||
};
|
||||
|
||||
},{"decode-uri-component":4,"filter-obj":5,"split-on-first":11,"strict-uri-encode":12}],11:[function(require,module,exports){
|
||||
'use strict';
|
||||
|
||||
module.exports = (string, separator) => {
|
||||
if (!(typeof string === 'string' && typeof separator === 'string')) {
|
||||
throw new TypeError('Expected the arguments to be of type `string`');
|
||||
}
|
||||
|
||||
if (separator === '') {
|
||||
return [string];
|
||||
}
|
||||
|
||||
const separatorIndex = string.indexOf(separator);
|
||||
|
||||
if (separatorIndex === -1) {
|
||||
return [string];
|
||||
}
|
||||
|
||||
return [
|
||||
string.slice(0, separatorIndex),
|
||||
string.slice(separatorIndex + separator.length)
|
||||
];
|
||||
};
|
||||
|
||||
},{}],12:[function(require,module,exports){
|
||||
'use strict';
|
||||
module.exports = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
|
||||
|
||||
},{}],13:[function(require,module,exports){
|
||||
(function(module) {
|
||||
'use strict';
|
||||
|
||||
|
@ -1190,10 +1739,10 @@ process.umask = function() { return 0; };
|
|||
|
||||
})(module);
|
||||
|
||||
},{}],9:[function(require,module,exports){
|
||||
},{}],14:[function(require,module,exports){
|
||||
module.exports={
|
||||
"name": "doipjs",
|
||||
"version": "0.10.5",
|
||||
"version": "0.11.0",
|
||||
"description": "Decentralized OpenPGP Identity Proofs library in Node.js",
|
||||
"main": "src/index.js",
|
||||
"dependencies": {
|
||||
|
@ -1202,6 +1751,7 @@ module.exports={
|
|||
"merge-options": "^3.0.3",
|
||||
"openpgp": "^4.10.9",
|
||||
"prettier": "^2.1.2",
|
||||
"query-string": "^6.14.1",
|
||||
"valid-url": "^1.0.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -1249,7 +1799,7 @@ module.exports={
|
|||
}
|
||||
}
|
||||
|
||||
},{}],10:[function(require,module,exports){
|
||||
},{}],15:[function(require,module,exports){
|
||||
(function (global){(function (){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
@ -1579,7 +2129,7 @@ const verify = async (input, fingerprint, opts) => {
|
|||
setTimeout(() => {
|
||||
resolve(objResult)
|
||||
return
|
||||
}, 3000)
|
||||
}, 10000)
|
||||
})
|
||||
|
||||
return await Promise.race([promiseClaim, promiseTimeout])
|
||||
|
@ -1588,7 +2138,7 @@ const verify = async (input, fingerprint, opts) => {
|
|||
exports.verify = verify
|
||||
|
||||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"./keys":12,"./serviceproviders":13,"./utils":30,"merge-options":5,"path":6,"valid-url":8}],11:[function(require,module,exports){
|
||||
},{"./keys":17,"./serviceproviders":18,"./utils":37,"merge-options":7,"path":8,"valid-url":13}],16:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -1616,7 +2166,7 @@ exports.signatures = signatures
|
|||
exports.serviceproviders = serviceproviders
|
||||
exports.utils = utils
|
||||
|
||||
},{"./claims":10,"./keys":12,"./serviceproviders":13,"./signatures":29,"./utils":30}],12:[function(require,module,exports){
|
||||
},{"./claims":15,"./keys":17,"./serviceproviders":18,"./signatures":36,"./utils":37}],17:[function(require,module,exports){
|
||||
(function (global){(function (){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
@ -1857,7 +2407,7 @@ exports.getUserData = getUserData
|
|||
exports.getFingerprint = getFingerprint
|
||||
|
||||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"bent":1,"merge-options":5,"path":6,"valid-url":8}],13:[function(require,module,exports){
|
||||
},{"bent":1,"merge-options":7,"path":8,"valid-url":13}],18:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -1879,7 +2429,9 @@ const utils = require('./utils')
|
|||
|
||||
const list = [
|
||||
'dns',
|
||||
'irc',
|
||||
'xmpp',
|
||||
'matrix',
|
||||
'twitter',
|
||||
'reddit',
|
||||
'liberapay',
|
||||
|
@ -1897,7 +2449,9 @@ const list = [
|
|||
|
||||
const data = {
|
||||
dns: require('./serviceproviders/dns'),
|
||||
irc: require('./serviceproviders/irc'),
|
||||
xmpp: require('./serviceproviders/xmpp'),
|
||||
matrix: require('./serviceproviders/matrix'),
|
||||
twitter: require('./serviceproviders/twitter'),
|
||||
reddit: require('./serviceproviders/reddit'),
|
||||
liberapay: require('./serviceproviders/liberapay'),
|
||||
|
@ -1930,6 +2484,10 @@ const match = (uri, opts) => {
|
|||
const directRequestHandler = (spData, opts) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri
|
||||
if (!url) {
|
||||
reject('No valid URI provided')
|
||||
return
|
||||
}
|
||||
let res
|
||||
|
||||
switch (spData.proof.format) {
|
||||
|
@ -1991,7 +2549,7 @@ exports.match = match
|
|||
exports.directRequestHandler = directRequestHandler
|
||||
exports.proxyRequestHandler = proxyRequestHandler
|
||||
|
||||
},{"../package.json":9,"./serviceproviders/devto":14,"./serviceproviders/discourse":15,"./serviceproviders/dns":16,"./serviceproviders/fediverse":17,"./serviceproviders/gitea":18,"./serviceproviders/github":19,"./serviceproviders/gitlab":20,"./serviceproviders/hackernews":21,"./serviceproviders/liberapay":22,"./serviceproviders/lobsters":23,"./serviceproviders/mastodon":24,"./serviceproviders/owncast":25,"./serviceproviders/reddit":26,"./serviceproviders/twitter":27,"./serviceproviders/xmpp":28,"./utils":30,"bent":1}],14:[function(require,module,exports){
|
||||
},{"../package.json":14,"./serviceproviders/devto":19,"./serviceproviders/discourse":20,"./serviceproviders/dns":21,"./serviceproviders/fediverse":22,"./serviceproviders/gitea":23,"./serviceproviders/github":24,"./serviceproviders/gitlab":25,"./serviceproviders/hackernews":26,"./serviceproviders/irc":27,"./serviceproviders/liberapay":28,"./serviceproviders/lobsters":29,"./serviceproviders/mastodon":30,"./serviceproviders/matrix":31,"./serviceproviders/owncast":32,"./serviceproviders/reddit":33,"./serviceproviders/twitter":34,"./serviceproviders/xmpp":35,"./utils":37,"bent":1}],19:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2060,7 +2618,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],15:[function(require,module,exports){
|
||||
},{}],20:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2129,7 +2687,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],16:[function(require,module,exports){
|
||||
},{}],21:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2227,7 +2785,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{"../utils":30,"bent":1,"dns":3}],17:[function(require,module,exports){
|
||||
},{"../utils":37,"bent":1,"dns":3}],22:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2296,7 +2854,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],18:[function(require,module,exports){
|
||||
},{}],23:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2365,7 +2923,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],19:[function(require,module,exports){
|
||||
},{}],24:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2434,7 +2992,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],20:[function(require,module,exports){
|
||||
},{}],25:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2546,7 +3104,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{"bent":1}],21:[function(require,module,exports){
|
||||
},{"bent":1}],26:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2615,7 +3173,77 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],22:[function(require,module,exports){
|
||||
},{}],27:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const utils = require('../utils')
|
||||
const reURI = /^irc\:\/\/(.*)\/([a-zA-Z0-9]*)/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const match = uri.match(reURI)
|
||||
|
||||
return {
|
||||
serviceprovider: {
|
||||
type: 'communication',
|
||||
name: 'irc',
|
||||
},
|
||||
profile: {
|
||||
display: `irc://${match[1]}/${match[2]}`,
|
||||
uri: uri,
|
||||
qr: null,
|
||||
},
|
||||
proof: {
|
||||
uri: utils.generateProxyURL('irc', [match[1], match[2]], opts),
|
||||
fetch: null,
|
||||
useProxy: false,
|
||||
format: 'json',
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: 'uri',
|
||||
path: ['data'],
|
||||
relation: 'contains',
|
||||
},
|
||||
customRequestHandler: null,
|
||||
}
|
||||
}
|
||||
|
||||
const tests = [
|
||||
{
|
||||
uri: 'irc://chat.ircserver.org/Alice1',
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: 'irc://chat.ircserver.org/alice?param=123',
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: 'https://chat.ircserver.org/alice',
|
||||
shouldMatch: false,
|
||||
},
|
||||
]
|
||||
|
||||
exports.reURI = reURI
|
||||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{"../utils":37}],28:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2684,7 +3312,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],23:[function(require,module,exports){
|
||||
},{}],29:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2753,7 +3381,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],24:[function(require,module,exports){
|
||||
},{}],30:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2822,7 +3450,91 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],25:[function(require,module,exports){
|
||||
},{}],31:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const bent = require('bent')
|
||||
const req = bent('GET')
|
||||
const queryString = require('query-string')
|
||||
const utils = require('../utils')
|
||||
const reURI = /^matrix\:u\/(\@[^:]*\:[^?]*)(\?.*)?/
|
||||
|
||||
const processURI = (uri, opts) => {
|
||||
if (!opts) {
|
||||
opts = {}
|
||||
}
|
||||
const match = uri.match(reURI)
|
||||
let proofUrl = null
|
||||
if (match[2]) {
|
||||
const params = queryString.parse(match[2])
|
||||
if ('org.keyoxide.e' in params && 'org.keyoxide.r' in params) {
|
||||
proofUrl = utils.generateProxyURL('matrix', [params['org.keyoxide.r'], params['org.keyoxide.e']], opts)
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
serviceprovider: {
|
||||
type: 'communication',
|
||||
name: 'matrix',
|
||||
},
|
||||
profile: {
|
||||
display: match[1],
|
||||
uri: uri,
|
||||
qr: null,
|
||||
},
|
||||
proof: {
|
||||
uri: proofUrl,
|
||||
fetch: null,
|
||||
useProxy: false,
|
||||
format: 'json',
|
||||
},
|
||||
claim: {
|
||||
fingerprint: null,
|
||||
format: 'message',
|
||||
path: ['data', 'content', 'body'],
|
||||
relation: 'contains',
|
||||
},
|
||||
customRequestHandler: null,
|
||||
}
|
||||
}
|
||||
|
||||
const tests = [
|
||||
{
|
||||
uri: 'matrix:u/@alice:matrix.domain.org',
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: 'matrix:u/@alice:matrix.domain.org?org.keyoxide.r=!123:domain.org&org.keyoxide.e=$123',
|
||||
shouldMatch: true,
|
||||
},
|
||||
{
|
||||
uri: 'xmpp:alice@domain.org',
|
||||
shouldMatch: false,
|
||||
},
|
||||
{
|
||||
uri: 'https://domain.org/@alice',
|
||||
shouldMatch: false,
|
||||
},
|
||||
]
|
||||
|
||||
exports.reURI = reURI
|
||||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{"../utils":37,"bent":1,"query-string":10}],32:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2898,7 +3610,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{"bent":1}],26:[function(require,module,exports){
|
||||
},{"bent":1}],33:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -2975,7 +3687,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{}],27:[function(require,module,exports){
|
||||
},{}],34:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -3087,7 +3799,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{"../serviceproviders":13,"../utils":30,"bent":1}],28:[function(require,module,exports){
|
||||
},{"../serviceproviders":18,"../utils":37,"bent":1}],35:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -3157,7 +3869,7 @@ exports.reURI = reURI
|
|||
exports.processURI = processURI
|
||||
exports.tests = tests
|
||||
|
||||
},{"../utils":30}],29:[function(require,module,exports){
|
||||
},{"../utils":37}],36:[function(require,module,exports){
|
||||
(function (global){(function (){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
@ -3284,7 +3996,7 @@ const verify = (signature, opts) => {
|
|||
exports.verify = verify
|
||||
|
||||
}).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
|
||||
},{"./claims":10,"./keys":12,"merge-options":5}],30:[function(require,module,exports){
|
||||
},{"./claims":15,"./keys":17,"merge-options":7}],37:[function(require,module,exports){
|
||||
/*
|
||||
Copyright 2021 Yarmo Mackenbach
|
||||
|
||||
|
@ -3300,7 +4012,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
const generateProxyURL = (type, url, opts) => {
|
||||
const generateProxyURL = (type, urlElements, opts) => {
|
||||
if (!opts || !opts.doipProxyHostname) {
|
||||
return null
|
||||
}
|
||||
|
@ -3308,9 +4020,16 @@ const generateProxyURL = (type, url, opts) => {
|
|||
if (type == 'xmpp') {
|
||||
addParam += '/DESC'
|
||||
}
|
||||
|
||||
if (!Array.isArray(urlElements)) {
|
||||
urlElements = [urlElements]
|
||||
}
|
||||
|
||||
urlElements.map((x) => { encodeURIComponent(x) })
|
||||
|
||||
return `https://${
|
||||
opts.doipProxyHostname
|
||||
}/api/1/get/${type}/${encodeURIComponent(url)}${addParam}`
|
||||
}/api/1/get/${type}/${urlElements.join('/')}${addParam}`
|
||||
}
|
||||
|
||||
const generateClaim = (fingerprint, format) => {
|
||||
|
@ -3332,5 +4051,5 @@ const generateClaim = (fingerprint, format) => {
|
|||
exports.generateProxyURL = generateProxyURL
|
||||
exports.generateClaim = generateClaim
|
||||
|
||||
},{}]},{},[11])(11)
|
||||
},{}]},{},[16])(16)
|
||||
});
|
||||
|
|
2
dist/doip.min.js
vendored
2
dist/doip.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
|||
# doip.js <small>0.10.5</small>
|
||||
# doip.js <small>0.11.0</small>
|
||||
|
||||
<img src="doip.png" width="120">
|
||||
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
# Changelog
|
||||
|
||||
## [0.11.0]
|
||||
|
||||
[2021-03-05](https://codeberg.org/keyoxide/doipjs/releases/tag/0.11.0)
|
||||
|
||||
## Added
|
||||
- IRC service provider
|
||||
- Matrix service provider
|
||||
## Fixed
|
||||
- Handling of requests without URI
|
||||
|
||||
## [0.10.5]
|
||||
|
||||
[2021-03-02](https://codeberg.org/keyoxide/doipjs/releases/tag/0.10.5)
|
||||
|
|
|
@ -15,7 +15,7 @@ npm install --save doipjs
|
|||
Install on website by including the following HTML snippet:
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/doipjs@0.10.5/dist/doip.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/doipjs@0.11.0/dist/doip.min.js"></script>
|
||||
```
|
||||
|
||||
Next step: [quick start (Node.js)](quickstart-nodejs.md) and [quick start (browser)](quickstart-browser.md)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "doipjs",
|
||||
"version": "0.10.5",
|
||||
"version": "0.11.0",
|
||||
"description": "Decentralized OpenPGP Identity Proofs library in Node.js",
|
||||
"main": "src/index.js",
|
||||
"dependencies": {
|
||||
|
|
Loading…
Reference in a new issue