doipjs/src/claimDefinitions/activitypub.js

99 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-09-30 15:39:10 -06:00
/*
2022-10-24 13:33:12 -06:00
Copyright 2022 Yarmo Mackenbach
2022-09-30 15:39:10 -06:00
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 E = require('../enums')
2022-10-03 14:32:46 -06:00
const reURI = /^https:\/\/(.*)\/?/
2022-09-30 15:39:10 -06:00
const processURI = (uri) => {
return {
serviceprovider: {
type: 'web',
name: 'activitypub'
},
match: {
regularExpression: reURI,
2022-10-25 01:22:06 -06:00
isAmbiguous: true
2022-09-30 15:39:10 -06:00
},
profile: {
2022-10-03 14:32:46 -06:00
display: uri,
2022-09-30 15:39:10 -06:00
uri: uri,
qr: null
},
proof: {
uri: uri,
request: {
fetcher: E.Fetcher.ACTIVITYPUB,
access: E.ProofAccess.GENERIC,
format: E.ProofFormat.JSON,
data: {
2022-10-03 14:32:46 -06:00
url: uri
2022-09-30 15:39:10 -06:00
}
}
},
claim: [
{
format: E.ClaimFormat.FINGERPRINT,
relation: E.ClaimRelation.CONTAINS,
path: ['summary']
},
{
format: E.ClaimFormat.FINGERPRINT,
relation: E.ClaimRelation.CONTAINS,
path: ['attachment', 'value']
}
]
}
}
const functions = {
postprocess: (claimData, proofData) => {
claimData.profile.display = `${proofData.result.preferredUsername}@${new URL(proofData.result.url).hostname}`
return { claimData, proofData }
2022-09-30 15:39:10 -06:00
}
}
const tests = [
{
2022-10-03 14:32:46 -06:00
uri: 'https://domain.org',
2022-09-30 15:39:10 -06:00
shouldMatch: true
},
{
2022-10-03 14:32:46 -06:00
uri: 'https://domain.org/@/alice/',
shouldMatch: true
2022-09-30 15:39:10 -06:00
},
{
2022-10-03 14:32:46 -06:00
uri: 'https://domain.org/@alice',
shouldMatch: true
},
{
uri: 'https://domain.org/u/alice/',
shouldMatch: true
},
{
uri: 'https://domain.org/users/alice/',
shouldMatch: true
2022-09-30 15:39:10 -06:00
},
{
2022-10-03 14:32:46 -06:00
uri: 'http://domain.org/alice',
2022-09-30 15:39:10 -06:00
shouldMatch: false
}
]
exports.reURI = reURI
exports.processURI = processURI
exports.functions = functions
2022-09-30 15:39:10 -06:00
exports.tests = tests