Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actor publicKeyはArrayでもいいように #4991

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/remote/activitypub/models/person.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ function validateActor(x: IObject, uri: string): IActor {
throw new Error('invalid Actor: id has different host');
}

if (x.publicKey) {
if (typeof x.publicKey.id !== 'string') {
const publicKey = toSingle(x.publicKey);
if (publicKey) {
if (typeof publicKey.id !== 'string') {
throw new Error('invalid Actor: publicKey.id is not a string');
}

const publicKeyIdHost = toUnicode(new URL(x.publicKey.id).hostname.toLowerCase());
const publicKeyIdHost = toUnicode(new URL(publicKey.id).hostname.toLowerCase());
if (publicKeyIdHost !== expectHost) {
throw new Error('invalid Actor: publicKey.id has different host');
}
Expand Down Expand Up @@ -145,6 +146,8 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IR

const bday = person['vcard:bday']?.match(/^[0-9]{4,8}-\d{2}-\d{2}/);

const publicKey = toSingle(person.publicKey);

// Create user
let user: IRemoteUser | undefined;
try {
Expand All @@ -164,9 +167,9 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IR
username: person.preferredUsername,
usernameLower: person.preferredUsername.toLowerCase(),
host,
publicKey: person.publicKey ? {
id: person.publicKey.id,
publicKeyPem: person.publicKey.publicKeyPem
publicKey: publicKey ? {
id: publicKey.id,
publicKeyPem: publicKey.publicKeyPem
} : undefined,
inbox: person.inbox,
sharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined),
Expand Down Expand Up @@ -358,6 +361,8 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: IAct

const bday = person['vcard:bday']?.match(/^[0-9]{4,8}-\d{2}-\d{2}/);

const publicKey = toSingle(person.publicKey);

const updates = {
lastFetchedAt: new Date(),
inbox: person.inbox,
Expand Down Expand Up @@ -387,9 +392,9 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: IAct
isLocked: person.manuallyApprovesFollowers,
isExplorable: !!person.discoverable,
searchableBy: parseSearchableBy(person),
publicKey: person.publicKey ? {
id: person.publicKey.id,
publicKeyPem: person.publicKey.publicKeyPem
publicKey: publicKey ? {
id: publicKey.id,
publicKeyPem: publicKey.publicKeyPem
} : undefined,
} as any;

Expand Down
5 changes: 4 additions & 1 deletion src/remote/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,10 @@ export interface IActor extends IObject {
publicKey?: {
id: string;
publicKeyPem: string;
};
} | {
id: string;
publicKeyPem: string;
}[];
followers?: string | ICollection | IOrderedCollection;
following?: string | ICollection | IOrderedCollection;
featured?: string | IOrderedCollection;
Expand Down