2021-03-05 15:39:17 +01:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
2021-04-12 15:59:03 +02:00
|
|
|
const E = require('../enums')
|
2021-04-12 14:31:34 +02:00
|
|
|
|
2021-07-09 23:44:52 +02:00
|
|
|
const reURI = /^irc:\/\/(.*)\/([a-zA-Z0-9\-[\]\\`_^{|}]*)/
|
2021-03-05 15:39:17 +01:00
|
|
|
|
2021-04-15 10:19:24 +02:00
|
|
|
const processURI = (uri) => {
|
2021-03-05 15:39:17 +01:00
|
|
|
const match = uri.match(reURI)
|
|
|
|
|
|
|
|
return {
|
|
|
|
serviceprovider: {
|
|
|
|
type: 'communication',
|
2021-07-09 23:44:52 +02:00
|
|
|
name: 'irc'
|
2021-03-05 15:39:17 +01:00
|
|
|
},
|
2021-04-15 10:19:24 +02:00
|
|
|
match: {
|
|
|
|
regularExpression: reURI,
|
2021-07-09 23:44:52 +02:00
|
|
|
isAmbiguous: false
|
2021-04-15 10:19:24 +02:00
|
|
|
},
|
2021-03-05 15:39:17 +01:00
|
|
|
profile: {
|
|
|
|
display: `irc://${match[1]}/${match[2]}`,
|
2023-06-16 15:38:47 +02:00
|
|
|
uri,
|
2021-07-09 23:44:52 +02:00
|
|
|
qr: null
|
2021-03-05 15:39:17 +01:00
|
|
|
},
|
|
|
|
proof: {
|
2021-04-12 15:59:03 +02:00
|
|
|
uri: null,
|
|
|
|
request: {
|
|
|
|
fetcher: E.Fetcher.IRC,
|
|
|
|
access: E.ProofAccess.SERVER,
|
|
|
|
format: E.ProofFormat.JSON,
|
|
|
|
data: {
|
|
|
|
domain: match[1],
|
2021-07-09 23:44:52 +02:00
|
|
|
nick: match[2]
|
|
|
|
}
|
|
|
|
}
|
2021-03-05 15:39:17 +01:00
|
|
|
},
|
2022-11-16 22:25:32 +01:00
|
|
|
claim: [{
|
2021-04-12 15:59:03 +02:00
|
|
|
format: E.ClaimFormat.URI,
|
2023-03-12 21:44:32 +01:00
|
|
|
encoding: E.EntityEncodingFormat.PLAIN,
|
2021-04-12 15:59:03 +02:00
|
|
|
relation: E.ClaimRelation.CONTAINS,
|
2021-07-09 23:44:52 +02:00
|
|
|
path: []
|
2022-11-16 22:25:32 +01:00
|
|
|
}]
|
2021-03-05 15:39:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const tests = [
|
|
|
|
{
|
|
|
|
uri: 'irc://chat.ircserver.org/Alice1',
|
2021-07-09 23:44:52 +02:00
|
|
|
shouldMatch: true
|
2021-03-05 15:39:17 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: 'irc://chat.ircserver.org/alice?param=123',
|
2021-07-09 23:44:52 +02:00
|
|
|
shouldMatch: true
|
2021-03-05 15:39:17 +01:00
|
|
|
},
|
2021-06-03 09:58:39 +02:00
|
|
|
{
|
|
|
|
uri: 'irc://chat.ircserver.org/alice_bob',
|
2021-07-09 23:44:52 +02:00
|
|
|
shouldMatch: true
|
2021-06-03 09:58:39 +02:00
|
|
|
},
|
2021-03-05 15:39:17 +01:00
|
|
|
{
|
|
|
|
uri: 'https://chat.ircserver.org/alice',
|
2021-07-09 23:44:52 +02:00
|
|
|
shouldMatch: false
|
|
|
|
}
|
2021-03-05 15:39:17 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
exports.reURI = reURI
|
|
|
|
exports.processURI = processURI
|
|
|
|
exports.tests = tests
|