Skip to content

Commit b4aa3e0

Browse files
authored
Actor publicKeyはArrayでもいいように (#4991)
1 parent 58492e2 commit b4aa3e0

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

src/remote/activitypub/models/person.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ function validateActor(x: IObject, uri: string): IActor {
7979
throw new Error('invalid Actor: id has different host');
8080
}
8181

82-
if (x.publicKey) {
83-
if (typeof x.publicKey.id !== 'string') {
82+
const publicKey = toSingle(x.publicKey);
83+
if (publicKey) {
84+
if (typeof publicKey.id !== 'string') {
8485
throw new Error('invalid Actor: publicKey.id is not a string');
8586
}
8687

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

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

149+
const publicKey = toSingle(person.publicKey);
150+
148151
// Create user
149152
let user: IRemoteUser | undefined;
150153
try {
@@ -164,9 +167,9 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IR
164167
username: person.preferredUsername,
165168
usernameLower: person.preferredUsername.toLowerCase(),
166169
host,
167-
publicKey: person.publicKey ? {
168-
id: person.publicKey.id,
169-
publicKeyPem: person.publicKey.publicKeyPem
170+
publicKey: publicKey ? {
171+
id: publicKey.id,
172+
publicKeyPem: publicKey.publicKeyPem
170173
} : undefined,
171174
inbox: person.inbox,
172175
sharedInbox: person.sharedInbox || (person.endpoints ? person.endpoints.sharedInbox : undefined),
@@ -358,6 +361,8 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: IAct
358361

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

364+
const publicKey = toSingle(person.publicKey);
365+
361366
const updates = {
362367
lastFetchedAt: new Date(),
363368
inbox: person.inbox,
@@ -387,9 +392,9 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: IAct
387392
isLocked: person.manuallyApprovesFollowers,
388393
isExplorable: !!person.discoverable,
389394
searchableBy: parseSearchableBy(person),
390-
publicKey: person.publicKey ? {
391-
id: person.publicKey.id,
392-
publicKeyPem: person.publicKey.publicKeyPem
395+
publicKey: publicKey ? {
396+
id: publicKey.id,
397+
publicKeyPem: publicKey.publicKeyPem
393398
} : undefined,
394399
} as any;
395400

src/remote/activitypub/type.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,10 @@ export interface IActor extends IObject {
243243
publicKey?: {
244244
id: string;
245245
publicKeyPem: string;
246-
};
246+
} | {
247+
id: string;
248+
publicKeyPem: string;
249+
}[];
247250
followers?: string | ICollection | IOrderedCollection;
248251
following?: string | ICollection | IOrderedCollection;
249252
featured?: string | IOrderedCollection;

0 commit comments

Comments
 (0)