Check original encoded strings against the signature
matheus23 opened this issue · 0 comments
matheus23 commented
To verify the UCAN signature, at the moment we're decoding the base64 parts of the UCAN into JSON, then stringify that JSON back into base64 and then bytes, and then check those bytes against the signature.
This process is likely to be lossy in unexpected ways. JSON.stringify(JSON.parse(x)) === x
doesn't hold for all values of x
.
This results in some UCANs being rejected even though their signatures are correct.
Relevant code:
Lines 204 to 210 in 6a75d56
I think we should change the API somewhat to fix this issue:
async function checkSignature(string: encodedUcan): Promise<boolean>
function decode(string: encodedUcan): UCAN
async function validate(string: encodedUcan): Promise<UCAN> { // throws if invalid? Or just returns Result<>
// ...
... = await checkSignature(encodedUcan)
// ...
const ucan = decode(encodedUcan)
// ...
}