mirror of
https://github.com/Blah-IM/typescript-core.git
synced 2025-04-30 16:21:10 +00:00
feat(identity): update profile
This commit is contained in:
parent
6546c2fe51
commit
5761b308a4
2 changed files with 28 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue