diff --git a/src/serviceproviders/devto.js b/src/claimDefinitions/devto.js similarity index 93% rename from src/serviceproviders/devto.js rename to src/claimDefinitions/devto.js index 17a0499..d335666 100644 --- a/src/serviceproviders/devto.js +++ b/src/claimDefinitions/devto.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/dev\.to\/(.*)\/(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'devto', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: match[1], uri: `https://dev.to/${match[1]}`, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: ['body_markdown'], diff --git a/src/serviceproviders/discourse.js b/src/claimDefinitions/discourse.js similarity index 93% rename from src/serviceproviders/discourse.js rename to src/claimDefinitions/discourse.js index ab2f454..10d7be9 100644 --- a/src/serviceproviders/discourse.js +++ b/src/claimDefinitions/discourse.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/(.*)\/u\/(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'discourse', }, + match: { + regularExpression: reURI, + isAmbiguous: true, + }, profile: { display: `${match[2]}@${match[1]}`, uri: uri, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: ['user', 'bio_raw'], diff --git a/src/serviceproviders/dns.js b/src/claimDefinitions/dns.js similarity index 93% rename from src/serviceproviders/dns.js rename to src/claimDefinitions/dns.js index 167c55b..c6eb96b 100644 --- a/src/serviceproviders/dns.js +++ b/src/claimDefinitions/dns.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^dns:([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'dns', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: match[1], uri: `https://${match[1]}`, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.URI, relation: E.ClaimRelation.CONTAINS, path: ['records', 'txt'], diff --git a/src/serviceproviders/fediverse.js b/src/claimDefinitions/fediverse.js similarity index 93% rename from src/serviceproviders/fediverse.js rename to src/claimDefinitions/fediverse.js index 531973c..2c25f90 100644 --- a/src/serviceproviders/fediverse.js +++ b/src/claimDefinitions/fediverse.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/(.*)\/users\/(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'fediverse', }, + match: { + regularExpression: reURI, + isAmbiguous: true, + }, profile: { display: `@${match[2]}@${match[1]}`, uri: uri, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.FINGERPRINT, relation: E.ClaimRelation.CONTAINS, path: ['summary'], diff --git a/src/serviceproviders/gitea.js b/src/claimDefinitions/gitea.js similarity index 93% rename from src/serviceproviders/gitea.js rename to src/claimDefinitions/gitea.js index 7b37270..d1a635b 100644 --- a/src/serviceproviders/gitea.js +++ b/src/claimDefinitions/gitea.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/(.*)\/(.*)\/gitea_proof\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'gitea', }, + match: { + regularExpression: reURI, + isAmbiguous: true, + }, profile: { display: `${match[2]}@${match[1]}`, uri: `https://${match[1]}/${match[2]}`, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.EQUALS, path: ['description'], diff --git a/src/serviceproviders/github.js b/src/claimDefinitions/github.js similarity index 93% rename from src/serviceproviders/github.js rename to src/claimDefinitions/github.js index 87dd140..14fd006 100644 --- a/src/serviceproviders/github.js +++ b/src/claimDefinitions/github.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/gist\.github\.com\/(.*)\/(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'github', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: match[1], uri: `https://github.com/${match[1]}`, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: ['files', 'openpgp.md', 'content'], diff --git a/src/serviceproviders/gitlab.js b/src/claimDefinitions/gitlab.js similarity index 93% rename from src/serviceproviders/gitlab.js rename to src/claimDefinitions/gitlab.js index 7a24b46..e4e9007 100644 --- a/src/serviceproviders/gitlab.js +++ b/src/claimDefinitions/gitlab.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/(.*)\/(.*)\/gitlab_proof\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'gitlab', }, + match: { + regularExpression: reURI, + isAmbiguous: true, + }, profile: { display: `${match[2]}@${match[1]}`, uri: `https://${match[1]}/${match[2]}`, @@ -46,7 +47,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.EQUALS, path: ['description'], diff --git a/src/serviceproviders/hackernews.js b/src/claimDefinitions/hackernews.js similarity index 93% rename from src/serviceproviders/hackernews.js rename to src/claimDefinitions/hackernews.js index 34bfb72..ca65c72 100644 --- a/src/serviceproviders/hackernews.js +++ b/src/claimDefinitions/hackernews.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/news\.ycombinator\.com\/user\?id=(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'hackernews', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: match[1], uri: uri, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.URI, relation: E.ClaimRelation.CONTAINS, path: ['about'], diff --git a/src/claimDefinitions/index.js b/src/claimDefinitions/index.js new file mode 100644 index 0000000..c9557fa --- /dev/null +++ b/src/claimDefinitions/index.js @@ -0,0 +1,57 @@ +/* +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 list = [ + 'dns', + 'irc', + 'xmpp', + 'matrix', + 'twitter', + 'reddit', + 'liberapay', + 'hackernews', + 'lobsters', + 'devto', + 'gitea', + 'gitlab', + 'github', + 'mastodon', + 'fediverse', + 'discourse', + 'owncast', +] + +const data = { + dns: require('./dns'), + irc: require('./irc'), + xmpp: require('./xmpp'), + matrix: require('./matrix'), + twitter: require('./twitter'), + reddit: require('./reddit'), + liberapay: require('./liberapay'), + hackernews: require('./hackernews'), + lobsters: require('./lobsters'), + devto: require('./devto'), + gitea: require('./gitea'), + gitlab: require('./gitlab'), + github: require('./github'), + mastodon: require('./mastodon'), + fediverse: require('./fediverse'), + discourse: require('./discourse'), + owncast: require('./owncast'), +} + +exports.list = list +exports.data = data \ No newline at end of file diff --git a/src/serviceproviders/irc.js b/src/claimDefinitions/irc.js similarity index 93% rename from src/serviceproviders/irc.js rename to src/claimDefinitions/irc.js index 15a2e48..2308f8c 100644 --- a/src/serviceproviders/irc.js +++ b/src/claimDefinitions/irc.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^irc\:\/\/(.*)\/([a-zA-Z0-9]*)/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'communication', name: 'irc', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: `irc://${match[1]}/${match[2]}`, uri: uri, @@ -46,7 +47,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.URI, relation: E.ClaimRelation.CONTAINS, path: [], diff --git a/src/serviceproviders/liberapay.js b/src/claimDefinitions/liberapay.js similarity index 93% rename from src/serviceproviders/liberapay.js rename to src/claimDefinitions/liberapay.js index 4cddf27..760c2a7 100644 --- a/src/serviceproviders/liberapay.js +++ b/src/claimDefinitions/liberapay.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/liberapay\.com\/(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'liberapay', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: match[1], uri: uri, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: ['statements', 'content'], diff --git a/src/serviceproviders/lobsters.js b/src/claimDefinitions/lobsters.js similarity index 93% rename from src/serviceproviders/lobsters.js rename to src/claimDefinitions/lobsters.js index 17399ec..51e2ca9 100644 --- a/src/serviceproviders/lobsters.js +++ b/src/claimDefinitions/lobsters.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/lobste\.rs\/u\/(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'lobsters', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: match[1], uri: uri, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: ['about'], diff --git a/src/serviceproviders/mastodon.js b/src/claimDefinitions/mastodon.js similarity index 93% rename from src/serviceproviders/mastodon.js rename to src/claimDefinitions/mastodon.js index 340814e..7149ec0 100644 --- a/src/serviceproviders/mastodon.js +++ b/src/claimDefinitions/mastodon.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/(.*)\/@(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'mastodon', }, + match: { + regularExpression: reURI, + isAmbiguous: true, + }, profile: { display: `@${match[2]}@${match[1]}`, uri: uri, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.FINGERPRINT, relation: E.ClaimRelation.CONTAINS, path: ['attachment', 'value'], diff --git a/src/serviceproviders/matrix.js b/src/claimDefinitions/matrix.js similarity index 95% rename from src/serviceproviders/matrix.js rename to src/claimDefinitions/matrix.js index 319003c..fa8fdae 100644 --- a/src/serviceproviders/matrix.js +++ b/src/claimDefinitions/matrix.js @@ -18,10 +18,7 @@ const queryString = require('query-string') const reURI = /^matrix\:u\/(?:\@)?([^@:]*\:[^?]*)(\?.*)?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) if (!match[2]) { @@ -42,6 +39,10 @@ const processURI = (uri, opts) => { type: 'communication', name: 'matrix', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: `@${match[1]}`, uri: profileUrl, @@ -60,7 +61,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: ['data', 'content', 'body'], diff --git a/src/serviceproviders/owncast.js b/src/claimDefinitions/owncast.js similarity index 93% rename from src/serviceproviders/owncast.js rename to src/claimDefinitions/owncast.js index 8cdc378..dafd6b6 100644 --- a/src/serviceproviders/owncast.js +++ b/src/claimDefinitions/owncast.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/(.*)/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'owncast', }, + match: { + regularExpression: reURI, + isAmbiguous: true, + }, profile: { display: match[1], uri: uri, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.FINGERPRINT, relation: E.ClaimRelation.CONTAINS, path: ['socialHandles', 'url'], diff --git a/src/serviceproviders/reddit.js b/src/claimDefinitions/reddit.js similarity index 94% rename from src/serviceproviders/reddit.js rename to src/claimDefinitions/reddit.js index 4b212f9..21d6bdb 100644 --- a/src/serviceproviders/reddit.js +++ b/src/claimDefinitions/reddit.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^https:\/\/(?:www\.)?reddit\.com\/user\/(.*)\/comments\/(.*)\/(.*)\/?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'reddit', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: match[1], uri: `https://www.reddit.com/user/${match[1]}`, @@ -45,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: ['data', 'children', 'data', 'selftext'], diff --git a/src/serviceproviders/twitter.js b/src/claimDefinitions/twitter.js similarity index 51% rename from src/serviceproviders/twitter.js rename to src/claimDefinitions/twitter.js index 8294aae..6089c84 100644 --- a/src/serviceproviders/twitter.js +++ b/src/claimDefinitions/twitter.js @@ -14,60 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ const E = require('../enums') -const bent = require('bent') -const req = bent('GET') -const serviceproviders = require('../serviceproviders') -const utils = require('../utils') const reURI = /^https:\/\/twitter\.com\/(.*)\/status\/([0-9]*)(?:\?.*)?/ -const customRequestHandler = async (spData, opts) => { - const match = spData.proof.uri.match(reURI) - - // Attempt direct verification if policy allows it - if (opts.proxyPolicy !== 'always') { - if ('twitterBearerToken' in opts && opts.twitterBearerToken) { - const res = await req( - `https://api.twitter.com/1.1/statuses/show.json?id=${match[2]}`, - null, - { - Accept: 'application/json', - Authorization: `Bearer ${opts.twitterBearerToken}`, - } - ) - const json = await res.json() - return json.text - } else if ('nitterInstance' in opts && opts.nitterInstance) { - spData.proof.fetch = `https://${opts.nitterInstance}/${match[1]}/status/${match[2]}` - const res = await serviceproviders.proxyRequestHandler(spData, opts) - return res - } - } - - // Attempt proxy verification if policy allows it - if (opts.proxyPolicy !== 'never' && spData.proof.fetch) { - return req(utils.generateProxyURL('twitter', match[2], opts), null, { - Accept: 'application/json', - }) - .then(async (res) => { - return await res.json() - }) - .then((res) => { - return res.data.text - }) - .catch((e) => { - reject(e) - }) - } - - // No verification - return null -} - -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -75,6 +25,10 @@ const processURI = (uri, opts) => { type: 'web', name: 'twitter', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: `@${match[1]}`, uri: `https://twitter.com/${match[1]}`, @@ -92,7 +46,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: [], diff --git a/src/serviceproviders/xmpp.js b/src/claimDefinitions/xmpp.js similarity index 93% rename from src/serviceproviders/xmpp.js rename to src/claimDefinitions/xmpp.js index 1c57260..1eafc4a 100644 --- a/src/serviceproviders/xmpp.js +++ b/src/claimDefinitions/xmpp.js @@ -17,10 +17,7 @@ const E = require('../enums') const reURI = /^xmpp:([a-zA-Z0-9\.\-\_]*)@([a-zA-Z0-9\.\-\_]*)(?:\?(.*))?/ -const processURI = (uri, opts) => { - if (!opts) { - opts = {} - } +const processURI = (uri) => { const match = uri.match(reURI) return { @@ -28,6 +25,10 @@ const processURI = (uri, opts) => { type: 'communication', name: 'xmpp', }, + match: { + regularExpression: reURI, + isAmbiguous: false, + }, profile: { display: `${match[1]}@${match[2]}`, uri: uri, @@ -46,7 +47,6 @@ const processURI = (uri, opts) => { } }, claim: { - fingerprint: null, format: E.ClaimFormat.MESSAGE, relation: E.ClaimRelation.CONTAINS, path: [],