2021-03-05 09:07:30 -07: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 07:59:03 -06:00
|
|
|
const E = require('../enums')
|
2021-03-05 09:07:30 -07:00
|
|
|
const queryString = require('query-string')
|
2021-04-12 06:31:34 -06:00
|
|
|
|
2021-07-09 15:44:52 -06:00
|
|
|
const reURI = /^matrix:u\/(?:@)?([^@:]*:[^?]*)(\?.*)?/
|
2021-03-05 09:07:30 -07:00
|
|
|
|
2021-04-15 02:19:24 -06:00
|
|
|
const processURI = (uri) => {
|
2021-03-05 09:07:30 -07:00
|
|
|
const match = uri.match(reURI)
|
2021-03-06 15:32:10 -07:00
|
|
|
|
2021-04-12 07:59:03 -06:00
|
|
|
if (!match[2]) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
const params = queryString.parse(match[2])
|
2023-03-08 05:46:41 -07:00
|
|
|
const paramRoomId = `${params['org.keyoxide.r'][0] !== '!' ? '!' : ''}${params['org.keyoxide.r']}`
|
|
|
|
const paramEventId = `${params['org.keyoxide.e'][0] !== '$' ? '$' : ''}${params['org.keyoxide.e']}`
|
2021-03-06 15:32:10 -07:00
|
|
|
|
2021-04-12 07:59:03 -06:00
|
|
|
if (!('org.keyoxide.e' in params && 'org.keyoxide.r' in params)) {
|
|
|
|
return null
|
2021-03-05 09:07:30 -07:00
|
|
|
}
|
|
|
|
|
2021-04-12 07:59:03 -06:00
|
|
|
const profileUrl = `https://matrix.to/#/@${match[1]}`
|
2023-03-08 05:46:41 -07:00
|
|
|
const eventUrl = `https://matrix.to/#/${paramRoomId}/${paramEventId}`
|
2021-04-12 07:59:03 -06:00
|
|
|
|
2021-03-05 09:07:30 -07:00
|
|
|
return {
|
|
|
|
serviceprovider: {
|
|
|
|
type: 'communication',
|
2021-07-09 15:44:52 -06:00
|
|
|
name: 'matrix'
|
2021-03-05 09:07:30 -07:00
|
|
|
},
|
2021-04-15 02:19:24 -06:00
|
|
|
match: {
|
|
|
|
regularExpression: reURI,
|
2021-07-09 15:44:52 -06:00
|
|
|
isAmbiguous: false
|
2021-04-15 02:19:24 -06:00
|
|
|
},
|
2021-03-05 09:07:30 -07:00
|
|
|
profile: {
|
2021-03-22 10:38:56 -06:00
|
|
|
display: `@${match[1]}`,
|
2021-03-06 15:32:10 -07:00
|
|
|
uri: profileUrl,
|
2021-07-09 15:44:52 -06:00
|
|
|
qr: null
|
2021-03-05 09:07:30 -07:00
|
|
|
},
|
|
|
|
proof: {
|
2021-03-06 15:32:10 -07:00
|
|
|
uri: eventUrl,
|
2021-04-12 07:59:03 -06:00
|
|
|
request: {
|
|
|
|
fetcher: E.Fetcher.MATRIX,
|
|
|
|
access: E.ProofAccess.GRANTED,
|
|
|
|
format: E.ProofFormat.JSON,
|
|
|
|
data: {
|
2023-03-08 05:46:41 -07:00
|
|
|
eventId: paramEventId,
|
|
|
|
roomId: paramRoomId
|
2021-07-09 15:44:52 -06:00
|
|
|
}
|
|
|
|
}
|
2021-03-05 09:07:30 -07:00
|
|
|
},
|
2022-11-16 14:25:32 -07:00
|
|
|
claim: [{
|
2022-08-16 13:46:54 -06:00
|
|
|
format: E.ClaimFormat.URI,
|
2021-04-12 07:59:03 -06:00
|
|
|
relation: E.ClaimRelation.CONTAINS,
|
2021-07-09 15:44:52 -06:00
|
|
|
path: ['content', 'body']
|
2022-11-16 14:25:32 -07:00
|
|
|
}]
|
2021-03-05 09:07:30 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const tests = [
|
|
|
|
{
|
2021-03-22 10:38:56 -06:00
|
|
|
uri:
|
2023-03-08 05:46:41 -07:00
|
|
|
'matrix:u/alice:matrix.domain.org?org.keyoxide.r=123:domain.org&org.keyoxide.e=123',
|
2021-07-09 15:44:52 -06:00
|
|
|
shouldMatch: true
|
2021-03-05 09:07:30 -07:00
|
|
|
},
|
|
|
|
{
|
2021-03-22 10:38:56 -06:00
|
|
|
uri: 'matrix:u/alice:matrix.domain.org',
|
2021-07-09 15:44:52 -06:00
|
|
|
shouldMatch: true
|
2021-03-05 09:07:30 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: 'xmpp:alice@domain.org',
|
2021-07-09 15:44:52 -06:00
|
|
|
shouldMatch: false
|
2021-03-05 09:07:30 -07:00
|
|
|
},
|
|
|
|
{
|
|
|
|
uri: 'https://domain.org/@alice',
|
2021-07-09 15:44:52 -06:00
|
|
|
shouldMatch: false
|
|
|
|
}
|
2021-03-05 09:07:30 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
exports.reURI = reURI
|
|
|
|
exports.processURI = processURI
|
|
|
|
exports.tests = tests
|