diff --git a/src/pds.js b/src/pds.js index 53a1d42..4ff8fd7 100644 --- a/src/pds.js +++ b/src/pds.js @@ -483,9 +483,12 @@ export class PersonalDataServer { `) } - async initIdentity(did, privateKeyHex) { + async initIdentity(did, privateKeyHex, handle = null) { await this.state.storage.put('did', did) await this.state.storage.put('privateKey', privateKeyHex) + if (handle) { + await this.state.storage.put('handle', handle) + } } async getDid() { @@ -495,6 +498,10 @@ export class PersonalDataServer { return this._did } + async getHandle() { + return this.state.storage.get('handle') + } + async getSigningKey() { const hex = await this.state.storage.get('privateKey') if (!hex) return null @@ -638,8 +645,8 @@ export class PersonalDataServer { if (!body.did || !body.privateKey) { return Response.json({ error: 'missing did or privateKey' }, { status: 400 }) } - await this.initIdentity(body.did, body.privateKey) - return Response.json({ ok: true, did: body.did }) + await this.initIdentity(body.did, body.privateKey, body.handle || null) + return Response.json({ ok: true, did: body.did, handle: body.handle || null }) } if (url.pathname === '/status') { const did = await this.getDid()