Skip to content

Commit

Permalink
Actor publicKeyはArrayでもいいように (#4991)
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Jul 21, 2024
1 parent 58492e2 commit b4aa3e0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
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

0 comments on commit b4aa3e0

Please sign in to comment.