mirror of
https://github.com/Blah-IM/blahrs.git
synced 2025-07-08 15:15:33 +00:00
Use serde_jcs for RFC 8785 compliancy
This fixes serialization and reduces maintainance cost, but does more data copying on serialization.
This commit is contained in:
parent
6e7229e4ac
commit
a63d0df443
5 changed files with 60 additions and 57 deletions
|
@ -96,7 +96,12 @@ async function showChatMsg(chat) {
|
|||
let verifyRet = null;
|
||||
crypto.subtle.exportKey('raw', keypair.publicKey)
|
||||
try {
|
||||
const signeeBytes = (new TextEncoder()).encode(JSON.stringify(chat.signee));
|
||||
const sortKeys = (obj) =>
|
||||
Object.fromEntries(Object.entries(obj).sort((lhs, rhs) => lhs[0] > rhs[0]));
|
||||
const canonicalJson = chat.signee
|
||||
// Just for simplicity. Only this struct is unsorted due to serde implementation.
|
||||
canonicalJson.payload = sortKeys(canonicalJson.payload)
|
||||
const signeeBytes = (new TextEncoder()).encode(JSON.stringify(canonicalJson));
|
||||
const rawkey = hexToBuf(chat.signee.user);
|
||||
const senderKey = await crypto.subtle.importKey('raw', rawkey, { name: 'Ed25519' }, true, ['verify']);
|
||||
const success = await crypto.subtle.verify('Ed25519', senderKey, hexToBuf(chat.sig), signeeBytes);
|
||||
|
@ -244,9 +249,10 @@ async function postChat(text) {
|
|||
richText = [text];
|
||||
}
|
||||
const signedPayload = await signData({
|
||||
typ: 'chat',
|
||||
// sorted fields.
|
||||
rich_text: richText,
|
||||
room: roomUuid,
|
||||
typ: 'chat',
|
||||
});
|
||||
const resp = await fetch(`${roomUrl}/item`, {
|
||||
method: 'POST',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue