feat(identity): update profile

This commit is contained in:
Shibo Lyu 2024-09-30 16:16:58 +08:00
parent 6546c2fe51
commit 5761b308a4
2 changed files with 28 additions and 0 deletions

View file

@ -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);

View file

@ -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;
}
}