unoffical wafrn mirror
wafrn.net
atproto
social-network
activitypub
1/*
2 THIS FILE IS STOLEN FROM SHARKEY WICH ALSO 'STOLE' IT FROM MISSKEY.
3 Its publicly avaialable information
4 * SPDX-FileCopyrightText: syuilo and misskey-project
5 * SPDX-License-Identifier: AGPL-3.0-only
6 */
7
8import type { Context, JsonLd } from 'jsonld/jsonld-spec.js'
9import { completeEnvironment } from '../backendOptions.js'
10
11/* eslint:disable:quotemark indent */
12const id_v1 = {
13 '@context': {
14 id: '@id',
15 type: '@type',
16
17 cred: 'https://w3id.org/credentials#',
18 dc: 'http://purl.org/dc/terms/',
19 identity: 'https://w3id.org/identity#',
20 perm: 'https://w3id.org/permissions#',
21 ps: 'https://w3id.org/payswarm#',
22 rdf: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
23 rdfs: 'http://www.w3.org/2000/01/rdf-schema#',
24 sec: 'https://w3id.org/security#',
25 schema: 'http://schema.org/',
26 xsd: 'http://www.w3.org/2001/XMLSchema#',
27
28 Group: 'https://www.w3.org/ns/activitystreams#Group',
29
30 claim: { '@id': 'cred:claim', '@type': '@id' },
31 credential: { '@id': 'cred:credential', '@type': '@id' },
32 issued: { '@id': 'cred:issued', '@type': 'xsd:dateTime' },
33 issuer: { '@id': 'cred:issuer', '@type': '@id' },
34 recipient: { '@id': 'cred:recipient', '@type': '@id' },
35 Credential: 'cred:Credential',
36 CryptographicKeyCredential: 'cred:CryptographicKeyCredential',
37
38 about: { '@id': 'schema:about', '@type': '@id' },
39 address: { '@id': 'schema:address', '@type': '@id' },
40 addressCountry: 'schema:addressCountry',
41 addressLocality: 'schema:addressLocality',
42 addressRegion: 'schema:addressRegion',
43 comment: 'rdfs:comment',
44 created: { '@id': 'dc:created', '@type': 'xsd:dateTime' },
45 creator: { '@id': 'dc:creator', '@type': '@id' },
46 description: 'schema:description',
47 email: 'schema:email',
48 familyName: 'schema:familyName',
49 givenName: 'schema:givenName',
50 image: { '@id': 'schema:image', '@type': '@id' },
51 label: 'rdfs:label',
52 name: 'schema:name',
53 postalCode: 'schema:postalCode',
54 streetAddress: 'schema:streetAddress',
55 title: 'dc:title',
56 url: { '@id': 'schema:url', '@type': '@id' },
57 Person: 'schema:Person',
58 PostalAddress: 'schema:PostalAddress',
59 Organization: 'schema:Organization',
60
61 identityService: { '@id': 'identity:identityService', '@type': '@id' },
62 idp: { '@id': 'identity:idp', '@type': '@id' },
63 Identity: 'identity:Identity',
64
65 paymentProcessor: 'ps:processor',
66 preferences: { '@id': 'ps:preferences', '@type': '@vocab' },
67
68 cipherAlgorithm: 'sec:cipherAlgorithm',
69 cipherData: 'sec:cipherData',
70 cipherKey: 'sec:cipherKey',
71 digestAlgorithm: 'sec:digestAlgorithm',
72 digestValue: 'sec:digestValue',
73 domain: 'sec:domain',
74 expires: { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
75 initializationVector: 'sec:initializationVector',
76 member: { '@id': 'schema:member', '@type': '@id' },
77 memberOf: { '@id': 'schema:memberOf', '@type': '@id' },
78 nonce: 'sec:nonce',
79 normalizationAlgorithm: 'sec:normalizationAlgorithm',
80 owner: { '@id': 'sec:owner', '@type': '@id' },
81 password: 'sec:password',
82 privateKey: { '@id': 'sec:privateKey', '@type': '@id' },
83 privateKeyPem: 'sec:privateKeyPem',
84 publicKey: { '@id': 'sec:publicKey', '@type': '@id' },
85 publicKeyPem: 'sec:publicKeyPem',
86 publicKeyService: { '@id': 'sec:publicKeyService', '@type': '@id' },
87 revoked: { '@id': 'sec:revoked', '@type': 'xsd:dateTime' },
88 signature: 'sec:signature',
89 signatureAlgorithm: 'sec:signatureAlgorithm',
90 signatureValue: 'sec:signatureValue',
91 CryptographicKey: 'sec:Key',
92 EncryptedMessage: 'sec:EncryptedMessage',
93 GraphSignature2012: 'sec:GraphSignature2012',
94 LinkedDataSignature2015: 'sec:LinkedDataSignature2015',
95
96 accessControl: { '@id': 'perm:accessControl', '@type': '@id' },
97 writePermission: { '@id': 'perm:writePermission', '@type': '@id' }
98 }
99} satisfies JsonLd
100
101const security_v1 = {
102 '@context': {
103 id: '@id',
104 type: '@type',
105
106 dc: 'http://purl.org/dc/terms/',
107 sec: 'https://w3id.org/security#',
108 xsd: 'http://www.w3.org/2001/XMLSchema#',
109
110 EcdsaKoblitzSignature2016: 'sec:EcdsaKoblitzSignature2016',
111 Ed25519Signature2018: 'sec:Ed25519Signature2018',
112 EncryptedMessage: 'sec:EncryptedMessage',
113 GraphSignature2012: 'sec:GraphSignature2012',
114 LinkedDataSignature2015: 'sec:LinkedDataSignature2015',
115 LinkedDataSignature2016: 'sec:LinkedDataSignature2016',
116 CryptographicKey: 'sec:Key',
117
118 authenticationTag: 'sec:authenticationTag',
119 canonicalizationAlgorithm: 'sec:canonicalizationAlgorithm',
120 cipherAlgorithm: 'sec:cipherAlgorithm',
121 cipherData: 'sec:cipherData',
122 cipherKey: 'sec:cipherKey',
123 created: { '@id': 'dc:created', '@type': 'xsd:dateTime' },
124 creator: { '@id': 'dc:creator', '@type': '@id' },
125 digestAlgorithm: 'sec:digestAlgorithm',
126 digestValue: 'sec:digestValue',
127 domain: 'sec:domain',
128 encryptionKey: 'sec:encryptionKey',
129 expiration: { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
130 expires: { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
131 initializationVector: 'sec:initializationVector',
132 iterationCount: 'sec:iterationCount',
133 nonce: 'sec:nonce',
134 normalizationAlgorithm: 'sec:normalizationAlgorithm',
135 owner: { '@id': 'sec:owner', '@type': '@id' },
136 password: 'sec:password',
137 privateKey: { '@id': 'sec:privateKey', '@type': '@id' },
138 privateKeyPem: 'sec:privateKeyPem',
139 publicKey: { '@id': 'sec:publicKey', '@type': '@id' },
140 publicKeyBase58: 'sec:publicKeyBase58',
141 publicKeyPem: 'sec:publicKeyPem',
142 publicKeyWif: 'sec:publicKeyWif',
143 publicKeyService: { '@id': 'sec:publicKeyService', '@type': '@id' },
144 revoked: { '@id': 'sec:revoked', '@type': 'xsd:dateTime' },
145 salt: 'sec:salt',
146 signature: 'sec:signature',
147 signatureAlgorithm: 'sec:signingAlgorithm',
148 signatureValue: 'sec:signatureValue'
149 }
150} satisfies JsonLd
151
152const activitystreams = {
153 '@context': {
154 '@vocab': '_:',
155 xsd: 'http://www.w3.org/2001/XMLSchema#',
156 as: 'https://www.w3.org/ns/activitystreams#',
157 ldp: 'http://www.w3.org/ns/ldp#',
158 vcard: 'http://www.w3.org/2006/vcard/ns#',
159 id: '@id',
160 type: '@type',
161 Accept: 'as:Accept',
162 Activity: 'as:Activity',
163 IntransitiveActivity: 'as:IntransitiveActivity',
164 Add: 'as:Add',
165 Announce: 'as:Announce',
166 Application: 'as:Application',
167 Arrive: 'as:Arrive',
168 Article: 'as:Article',
169 Audio: 'as:Audio',
170 Block: 'as:Block',
171 Collection: 'as:Collection',
172 CollectionPage: 'as:CollectionPage',
173 Relationship: 'as:Relationship',
174 Create: 'as:Create',
175 Delete: 'as:Delete',
176 Dislike: 'as:Dislike',
177 Document: 'as:Document',
178 Event: 'as:Event',
179 Follow: 'as:Follow',
180 Flag: 'as:Flag',
181 Group: 'as:Group',
182 Ignore: 'as:Ignore',
183 Image: 'as:Image',
184 Invite: 'as:Invite',
185 Join: 'as:Join',
186 Leave: 'as:Leave',
187 Like: 'as:Like',
188 Link: 'as:Link',
189 Mention: 'as:Mention',
190 Note: 'as:Note',
191 Object: 'as:Object',
192 Offer: 'as:Offer',
193 OrderedCollection: 'as:OrderedCollection',
194 OrderedCollectionPage: 'as:OrderedCollectionPage',
195 Organization: 'as:Organization',
196 Page: 'as:Page',
197 Person: 'as:Person',
198 Place: 'as:Place',
199 Profile: 'as:Profile',
200 Question: 'as:Question',
201 Reject: 'as:Reject',
202 Remove: 'as:Remove',
203 Service: 'as:Service',
204 TentativeAccept: 'as:TentativeAccept',
205 TentativeReject: 'as:TentativeReject',
206 Tombstone: 'as:Tombstone',
207 Undo: 'as:Undo',
208 Update: 'as:Update',
209 Video: 'as:Video',
210 View: 'as:View',
211 Listen: 'as:Listen',
212 Read: 'as:Read',
213 Move: 'as:Move',
214 Travel: 'as:Travel',
215 IsFollowing: 'as:IsFollowing',
216 IsFollowedBy: 'as:IsFollowedBy',
217 IsContact: 'as:IsContact',
218 IsMember: 'as:IsMember',
219 subject: {
220 '@id': 'as:subject',
221 '@type': '@id'
222 },
223 relationship: {
224 '@id': 'as:relationship',
225 '@type': '@id'
226 },
227 actor: {
228 '@id': 'as:actor',
229 '@type': '@id'
230 },
231 attributedTo: {
232 '@id': 'as:attributedTo',
233 '@type': '@id'
234 },
235 attachment: {
236 '@id': 'as:attachment',
237 '@type': '@id'
238 },
239 bcc: {
240 '@id': 'as:bcc',
241 '@type': '@id'
242 },
243 bto: {
244 '@id': 'as:bto',
245 '@type': '@id'
246 },
247 cc: {
248 '@id': 'as:cc',
249 '@type': '@id'
250 },
251 context: {
252 '@id': 'as:context',
253 '@type': '@id'
254 },
255 current: {
256 '@id': 'as:current',
257 '@type': '@id'
258 },
259 first: {
260 '@id': 'as:first',
261 '@type': '@id'
262 },
263 generator: {
264 '@id': 'as:generator',
265 '@type': '@id'
266 },
267 icon: {
268 '@id': 'as:icon',
269 '@type': '@id'
270 },
271 image: {
272 '@id': 'as:image',
273 '@type': '@id'
274 },
275 inReplyTo: {
276 '@id': 'as:inReplyTo',
277 '@type': '@id'
278 },
279 items: {
280 '@id': 'as:items',
281 '@type': '@id'
282 },
283 instrument: {
284 '@id': 'as:instrument',
285 '@type': '@id'
286 },
287 orderedItems: {
288 '@id': 'as:items',
289 '@type': '@id',
290 '@container': '@list'
291 },
292 last: {
293 '@id': 'as:last',
294 '@type': '@id'
295 },
296 location: {
297 '@id': 'as:location',
298 '@type': '@id'
299 },
300 next: {
301 '@id': 'as:next',
302 '@type': '@id'
303 },
304 object: {
305 '@id': 'as:object',
306 '@type': '@id'
307 },
308 oneOf: {
309 '@id': 'as:oneOf',
310 '@type': '@id'
311 },
312 anyOf: {
313 '@id': 'as:anyOf',
314 '@type': '@id'
315 },
316 closed: {
317 '@id': 'as:closed',
318 '@type': 'xsd:dateTime'
319 },
320 origin: {
321 '@id': 'as:origin',
322 '@type': '@id'
323 },
324 accuracy: {
325 '@id': 'as:accuracy',
326 '@type': 'xsd:float'
327 },
328 prev: {
329 '@id': 'as:prev',
330 '@type': '@id'
331 },
332 preview: {
333 '@id': 'as:preview',
334 '@type': '@id'
335 },
336 replies: {
337 '@id': 'as:replies',
338 '@type': '@id'
339 },
340 result: {
341 '@id': 'as:result',
342 '@type': '@id'
343 },
344 audience: {
345 '@id': 'as:audience',
346 '@type': '@id'
347 },
348 partOf: {
349 '@id': 'as:partOf',
350 '@type': '@id'
351 },
352 tag: {
353 '@id': 'as:tag',
354 '@type': '@id'
355 },
356 target: {
357 '@id': 'as:target',
358 '@type': '@id'
359 },
360 to: {
361 '@id': 'as:to',
362 '@type': '@id'
363 },
364 url: {
365 '@id': 'as:url',
366 '@type': '@id'
367 },
368 altitude: {
369 '@id': 'as:altitude',
370 '@type': 'xsd:float'
371 },
372 content: 'as:content',
373 contentMap: {
374 '@id': 'as:content',
375 '@container': '@language'
376 },
377 name: 'as:name',
378 nameMap: {
379 '@id': 'as:name',
380 '@container': '@language'
381 },
382 duration: {
383 '@id': 'as:duration',
384 '@type': 'xsd:duration'
385 },
386 endTime: {
387 '@id': 'as:endTime',
388 '@type': 'xsd:dateTime'
389 },
390 height: {
391 '@id': 'as:height',
392 '@type': 'xsd:nonNegativeInteger'
393 },
394 href: {
395 '@id': 'as:href',
396 '@type': '@id'
397 },
398 hreflang: 'as:hreflang',
399 latitude: {
400 '@id': 'as:latitude',
401 '@type': 'xsd:float'
402 },
403 longitude: {
404 '@id': 'as:longitude',
405 '@type': 'xsd:float'
406 },
407 mediaType: 'as:mediaType',
408 published: {
409 '@id': 'as:published',
410 '@type': 'xsd:dateTime'
411 },
412 radius: {
413 '@id': 'as:radius',
414 '@type': 'xsd:float'
415 },
416 rel: 'as:rel',
417 startIndex: {
418 '@id': 'as:startIndex',
419 '@type': 'xsd:nonNegativeInteger'
420 },
421 startTime: {
422 '@id': 'as:startTime',
423 '@type': 'xsd:dateTime'
424 },
425 summary: 'as:summary',
426 summaryMap: {
427 '@id': 'as:summary',
428 '@container': '@language'
429 },
430 totalItems: {
431 '@id': 'as:totalItems',
432 '@type': 'xsd:nonNegativeInteger'
433 },
434 units: 'as:units',
435 updated: {
436 '@id': 'as:updated',
437 '@type': 'xsd:dateTime'
438 },
439 width: {
440 '@id': 'as:width',
441 '@type': 'xsd:nonNegativeInteger'
442 },
443 describes: {
444 '@id': 'as:describes',
445 '@type': '@id'
446 },
447 formerType: {
448 '@id': 'as:formerType',
449 '@type': '@id'
450 },
451 deleted: {
452 '@id': 'as:deleted',
453 '@type': 'xsd:dateTime'
454 },
455 inbox: {
456 '@id': 'ldp:inbox',
457 '@type': '@id'
458 },
459 outbox: {
460 '@id': 'as:outbox',
461 '@type': '@id'
462 },
463 following: {
464 '@id': 'as:following',
465 '@type': '@id'
466 },
467 followers: {
468 '@id': 'as:followers',
469 '@type': '@id'
470 },
471 streams: {
472 '@id': 'as:streams',
473 '@type': '@id'
474 },
475 preferredUsername: 'as:preferredUsername',
476 endpoints: {
477 '@id': 'as:endpoints',
478 '@type': '@id'
479 },
480 uploadMedia: {
481 '@id': 'as:uploadMedia',
482 '@type': '@id'
483 },
484 proxyUrl: {
485 '@id': 'as:proxyUrl',
486 '@type': '@id'
487 },
488 liked: {
489 '@id': 'as:liked',
490 '@type': '@id'
491 },
492 oauthAuthorizationEndpoint: {
493 '@id': 'as:oauthAuthorizationEndpoint',
494 '@type': '@id'
495 },
496 oauthTokenEndpoint: {
497 '@id': 'as:oauthTokenEndpoint',
498 '@type': '@id'
499 },
500 provideClientKey: {
501 '@id': 'as:provideClientKey',
502 '@type': '@id'
503 },
504 signClientKey: {
505 '@id': 'as:signClientKey',
506 '@type': '@id'
507 },
508 sharedInbox: {
509 '@id': 'as:sharedInbox',
510 '@type': '@id'
511 },
512 Public: {
513 '@id': 'as:Public',
514 '@type': '@id'
515 },
516 source: 'as:source',
517 likes: {
518 '@id': 'as:likes',
519 '@type': '@id'
520 },
521 shares: {
522 '@id': 'as:shares',
523 '@type': '@id'
524 },
525 alsoKnownAs: {
526 '@id': 'as:alsoKnownAs',
527 '@type': '@id'
528 }
529 }
530} satisfies JsonLd
531
532export const wafrnContext = {
533 '@context': [
534 'https://www.w3.org/ns/activitystreams',
535 'https://w3id.org/security/v1',
536 {
537 Emoji: 'toot:Emoji',
538 Hashtag: 'as:Hashtag',
539 WafrnHashtag: 'as:WafrnHashtag',
540 PropertyValue: 'schema:PropertyValue',
541 atomUri: 'ostatus:atomUri',
542 conversation: {
543 '@id': 'ostatus:conversation',
544 '@type': '@id'
545 },
546 discoverable: 'toot:discoverable',
547 manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
548 capabilities: 'litepub:capabilities',
549 ostatus: 'http://ostatus.org#',
550 schema: 'http://schema.org#',
551 toot: 'http://joinmastodon.org/ns#',
552 misskey: 'https://misskey-hub.net/ns#',
553 fedibird: 'http://fedibird.com/ns#',
554 value: 'schema:value',
555 sensitive: 'as:sensitive',
556 litepub: 'http://litepub.social/ns#',
557 invisible: 'litepub:invisible',
558 directMessage: 'litepub:directMessage',
559 listMessage: {
560 '@id': 'litepub:listMessage',
561 '@type': '@id'
562 },
563 quoteUrl: 'as:quoteUrl',
564 quoteUri: 'fedibird:quoteUri',
565 oauthRegistrationEndpoint: {
566 '@id': 'litepub:oauthRegistrationEndpoint',
567 '@type': '@id'
568 },
569 EmojiReact: 'litepub:EmojiReact',
570 ChatMessage: 'litepub:ChatMessage',
571 alsoKnownAs: {
572 '@id': 'as:alsoKnownAs',
573 '@type': '@id'
574 },
575 vcard: 'http://www.w3.org/2006/vcard/ns#',
576 formerRepresentations: 'litepub:formerRepresentations',
577 contentMap: {
578 '@id': 'as:content',
579 '@container': '@language'
580 }
581 }
582 ]
583} satisfies JsonLd
584
585const context_iris = ['https://www.w3.org/ns/activitystreams', 'https://w3id.org/security/v1']
586
587const extension_context_definition = {
588 Key: 'sec:Key',
589 // as non-standards
590 manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
591 sensitive: 'as:sensitive',
592 Hashtag: 'as:Hashtag',
593 quoteUrl: 'as:quoteUrl',
594 fedibird: 'http://fedibird.com/ns#',
595 quoteUri: 'fedibird:quoteUri',
596 // Mastodon
597 toot: 'http://joinmastodon.org/ns#',
598 Emoji: 'toot:Emoji',
599 featured: 'toot:featured',
600 discoverable: 'toot:discoverable',
601 indexable: 'toot:indexable',
602 // schema
603 schema: 'http://schema.org#',
604 PropertyValue: 'schema:PropertyValue',
605 value: 'schema:value',
606 // Misskey
607 misskey: 'https://misskey-hub.net/ns#',
608 _misskey_content: 'misskey:_misskey_content',
609 _misskey_quote: 'misskey:_misskey_quote',
610 _misskey_reaction: 'misskey:_misskey_reaction',
611 _misskey_votes: 'misskey:_misskey_votes',
612 _misskey_summary: 'misskey:_misskey_summary',
613 _misskey_followedMessage: 'misskey:_misskey_followedMessage',
614 _misskey_requireSigninToViewContents: 'misskey:_misskey_requireSigninToViewContents',
615 _misskey_makeNotesFollowersOnlyBefore: 'misskey:_misskey_makeNotesFollowersOnlyBefore',
616 _misskey_makeNotesHiddenBefore: 'misskey:_misskey_makeNotesHiddenBefore',
617 _misskey_license: 'misskey:_misskey_license',
618 freeText: {
619 '@id': 'misskey:freeText',
620 '@type': 'schema:text'
621 },
622 isCat: 'misskey:isCat',
623 // Firefish
624 firefish: 'https://joinfirefish.org/ns#',
625 speakAsCat: 'firefish:speakAsCat',
626 // Sharkey
627 sharkey: 'https://joinsharkey.org/ns#',
628 hideOnlineStatus: 'sharkey:hideOnlineStatus',
629 backgroundUrl: 'sharkey:backgroundUrl',
630 listenbrainz: 'sharkey:listenbrainz',
631 enableRss: 'sharkey:enableRss',
632 // vcard
633 vcard: 'http://www.w3.org/2006/vcard/ns#'
634} satisfies Context
635
636export const CONTEXT: (string | Context)[] = [...context_iris, extension_context_definition]
637
638export const PRELOADED_CONTEXTS: Record<string, JsonLd> = {
639 'https://w3id.org/identity/v1': id_v1,
640 'https://w3id.org/security/v1': security_v1,
641 'https://www.w3.org/ns/activitystreams': activitystreams
642}
643
644export function getPreloadedContexts(): Record<string, JsonLd> {
645 const res = PRELOADED_CONTEXTS
646 const wafrnContextUrl = `${completeEnvironment.frontendUrl}/contexts/litepub-0.1.jsonld`
647 res[wafrnContextUrl] = wafrnContext
648 return res
649}