Skip to content

Commit

Permalink
publicKeyに配列が入ってもいいようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
tamaina committed Jun 11, 2024
1 parent 3717ff3 commit 64004fd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions packages/backend/src/core/activitypub/models/ApPersonService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,24 @@ export class ApPersonService implements OnModuleInit {
throw new Error('invalid Actor: id has different host');
}

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

if (x.publicKey && typeof x.publicKey.id !== 'string') {
const publicKeyIdHost = this.punyHost(x.publicKey.id);
if (publicKeyIdHost !== expectHost) {
throw new Error('invalid Actor: publicKey.id has different host');
}
} else if (x.publicKey && Array.isArray(x.publicKey)) {
for (const publicKey of x.publicKey) {
if (typeof publicKey.id !== 'string') {
throw new Error('invalid Actor: publicKey.id is not a string');
}

const publicKeyIdHost = this.punyHost(publicKey.id);
if (publicKeyIdHost !== expectHost) {
throw new Error('invalid Actor: publicKey.id has different host');
}
}
} else if (x.publicKey) {
throw new Error('invalid Actor: publicKey is not an object or an array');
}

if (x.additionalPublicKeys) {
Expand Down Expand Up @@ -408,7 +417,7 @@ export class ApPersonService implements OnModuleInit {
if (person.publicKey) {
const publicKeys = new Map<string, IKey>([
...(person.additionalPublicKeys ? person.additionalPublicKeys.map(key => [key.id, key] as const) : []),
[person.publicKey.id, person.publicKey],
...(Array.isArray(person.publicKey) ? person.publicKey.map(key => [key.id, key] as const) : [[person.publicKey.id, person.publicKey]] as const),
]);

await transactionalEntityManager.save(Array.from(publicKeys.values(), key => new MiUserPublickey({
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/activitypub/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export interface IActor extends IObject {
discoverable?: boolean;
inbox: string;
sharedInbox?: string; // 後方互換性のため
publicKey?: IKey;
publicKey?: IKey | IKey[];
additionalPublicKeys?: IKey[];
followers?: string | ICollection | IOrderedCollection;
following?: string | ICollection | IOrderedCollection;
Expand Down

0 comments on commit 64004fd

Please sign in to comment.