diff --git a/identity/identity.test.ts b/identity/identity.test.ts index d556ae1..318b403 100644 --- a/identity/identity.test.ts +++ b/identity/identity.test.ts @@ -74,6 +74,20 @@ Deno.test("update first act key", async () => { expect(record.comment).toBe("test2"); }); +Deno.test("update profile", async () => { + const newProfile: BlahProfile = { + typ: "profile", + name: "Shibo Lyu", + preferred_chat_server_urls: ["https://example.com"], + id_urls: ["https://localhost:8080"], + }; + + await identity.updateProfile(newProfile); + identityFile = identity.generateIdentityFile(); + + expect(identityFile.profile.signee.payload).toEqual(newProfile); +}); + Deno.test("throw when try writing to identity without id key pair", () => { expect(identityFromFile.updateActKey(actKeyPair.id, { comment: "test2" })) .rejects.toMatch(/key pair/i); diff --git a/identity/identity.ts b/identity/identity.ts index b56580f..86c6965 100644 --- a/identity/identity.ts +++ b/identity/identity.ts @@ -228,4 +228,18 @@ export class BlahIdentity { config, ); } + + async updateProfile(profile: BlahProfile) { + const signingActKey = this.internalActKeys.find((k) => + k.key instanceof BlahKeyPair + ); + if (!signingActKey) { + throw new Error("No act key to sign profile with."); + } + + this.rawProfile = await (signingActKey.key as BlahKeyPair).signPayload( + profile, + ); + this.internalProfileSigValid = true; + } }