Skip to content

Commit

Permalink
FIXED_CONTEXT
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Apr 29, 2024
1 parent aa6ebf7 commit 1c2b962
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/queue/processors/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import resolveUser from '../../remote/resolve-user';
import config from '../../config';
import { publishInstanceModUpdated } from '../../services/server-event';
import { StatusError } from '../../misc/fetch';
import { FIXED_CONTEXT } from '../../remote/activitypub/misc/contexts';

const logger = new Logger('inbox');

Expand Down Expand Up @@ -124,7 +125,7 @@ export const tryProcessInbox = async (data: InboxJobData, ctx?: ApContext): Prom

const activity2 = JSON.parse(JSON.stringify(activity));
delete activity2.signature;
const compacted = await ldSignature.compact(activity2);
const compacted = await ldSignature.compact(activity2, FIXED_CONTEXT);
activity = compacted as any;
} else {
return `skip: http-signature verification failed and ${config.ignoreApForwarded ? 'ignoreApForwarded' : 'no LD-Signature'}. keyId=${signature.keyId}`;
Expand Down
35 changes: 35 additions & 0 deletions src/remote/activitypub/misc/contexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,38 @@ export const CONTEXTS: Record<string, any> = {
"https://w3id.org/security/v1": security_v1,
"https://www.w3.org/ns/activitystreams": activitystreams,
};

export const FIXED_CONTEXT = [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
{
Key: 'sec:Key',
// as non-standards
manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
sensitive: 'as:sensitive',
Hashtag: 'as:Hashtag',
// Mastodon
toot: 'http://joinmastodon.org/ns#',
Emoji: 'toot:Emoji',
featured: 'toot:featured',
discoverable: 'toot:discoverable',
indexable: 'toot:indexable',
// schema
schema: 'http://schema.org#',
PropertyValue: 'schema:PropertyValue',
value: 'schema:value',
// Misskey
misskey: 'https://misskey-hub.net/ns#',
'_misskey_content': 'misskey:_misskey_content',
'_misskey_quote': 'misskey:_misskey_quote',
'_misskey_reaction': 'misskey:_misskey_reaction',
'_misskey_votes': 'misskey:_misskey_votes',
'isCat': 'misskey:isCat',
// vcard
vcard: 'http://www.w3.org/2006/vcard/ns#',
// Fedibird
fedibird: 'http://fedibird.com/ns#',
quoteUri: 'fedibird:quoteUri',
searchableBy: { '@id': 'fedibird:searchableBy', '@type': '@id' },
}
];
4 changes: 2 additions & 2 deletions src/remote/activitypub/misc/ld-signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ export class LdSignature {
});
}

public async compact(data: any) {
public async compact(data: any, context: any) {
const customLoader = this.getLoader();
return await jsonld.compact(data, data['@context'], {
return await jsonld.compact(data, context, {
documentLoader: customLoader
});
}
Expand Down
36 changes: 2 additions & 34 deletions src/remote/activitypub/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { v4 as uuid } from 'uuid';
import { IActivity } from '../type';
import { LdSignature } from '../misc/ld-signature';
import { ILocalUser } from '../../../models/user';
import { FIXED_CONTEXT } from '../misc/contexts';

export const renderActivity = (x: any): IActivity | null => {
if (x == null) return null;
Expand All @@ -12,40 +13,7 @@ export const renderActivity = (x: any): IActivity | null => {
}

return Object.assign({
'@context': [
'https://www.w3.org/ns/activitystreams',
'https://w3id.org/security/v1',
{
Key: 'sec:Key',
// as non-standards
manuallyApprovesFollowers: 'as:manuallyApprovesFollowers',
sensitive: 'as:sensitive',
Hashtag: 'as:Hashtag',
// Mastodon
toot: 'http://joinmastodon.org/ns#',
Emoji: 'toot:Emoji',
featured: 'toot:featured',
discoverable: 'toot:discoverable',
indexable: 'toot:indexable',
// schema
schema: 'http://schema.org#',
PropertyValue: 'schema:PropertyValue',
value: 'schema:value',
// Misskey
misskey: 'https://misskey-hub.net/ns#',
'_misskey_content': 'misskey:_misskey_content',
'_misskey_quote': 'misskey:_misskey_quote',
'_misskey_reaction': 'misskey:_misskey_reaction',
'_misskey_votes': 'misskey:_misskey_votes',
'isCat': 'misskey:isCat',
// vcard
vcard: 'http://www.w3.org/2006/vcard/ns#',
// Fedibird
fedibird: 'http://fedibird.com/ns#',
quoteUri: 'fedibird:quoteUri',
searchableBy: { '@id': 'fedibird:searchableBy', '@type': '@id' },
}
]
'@context': FIXED_CONTEXT
}, x);
};

Expand Down

0 comments on commit 1c2b962

Please sign in to comment.