@@ -79,12 +79,13 @@ function validateActor(x: IObject, uri: string): IActor {
79
79
throw new Error ( 'invalid Actor: id has different host' ) ;
80
80
}
81
81
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' ) {
84
85
throw new Error ( 'invalid Actor: publicKey.id is not a string' ) ;
85
86
}
86
87
87
- const publicKeyIdHost = toUnicode ( new URL ( x . publicKey . id ) . hostname . toLowerCase ( ) ) ;
88
+ const publicKeyIdHost = toUnicode ( new URL ( publicKey . id ) . hostname . toLowerCase ( ) ) ;
88
89
if ( publicKeyIdHost !== expectHost ) {
89
90
throw new Error ( 'invalid Actor: publicKey.id has different host' ) ;
90
91
}
@@ -145,6 +146,8 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IR
145
146
146
147
const bday = person [ 'vcard:bday' ] ?. match ( / ^ [ 0 - 9 ] { 4 , 8 } - \d { 2 } - \d { 2 } / ) ;
147
148
149
+ const publicKey = toSingle ( person . publicKey ) ;
150
+
148
151
// Create user
149
152
let user : IRemoteUser | undefined ;
150
153
try {
@@ -164,9 +167,9 @@ export async function createPerson(uri: string, resolver?: Resolver): Promise<IR
164
167
username : person . preferredUsername ,
165
168
usernameLower : person . preferredUsername . toLowerCase ( ) ,
166
169
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
170
173
} : undefined ,
171
174
inbox : person . inbox ,
172
175
sharedInbox : person . sharedInbox || ( person . endpoints ? person . endpoints . sharedInbox : undefined ) ,
@@ -358,6 +361,8 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: IAct
358
361
359
362
const bday = person [ 'vcard:bday' ] ?. match ( / ^ [ 0 - 9 ] { 4 , 8 } - \d { 2 } - \d { 2 } / ) ;
360
363
364
+ const publicKey = toSingle ( person . publicKey ) ;
365
+
361
366
const updates = {
362
367
lastFetchedAt : new Date ( ) ,
363
368
inbox : person . inbox ,
@@ -387,9 +392,9 @@ export async function updatePerson(uri: string, resolver?: Resolver, hint?: IAct
387
392
isLocked : person . manuallyApprovesFollowers ,
388
393
isExplorable : ! ! person . discoverable ,
389
394
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
393
398
} : undefined ,
394
399
} as any ;
395
400
0 commit comments