Skip to content

Commit

Permalink
Update test case with actual recovery credential + add missing await
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Nov 20, 2023
1 parent ee35b22 commit 2247d36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions recovery/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -923,12 +923,12 @@ <h2>Message log</h2>
// This isn't perfect: there's a small chance that a base64url-encoded string doesn't have any of these characters by chance!
// But we accept this risk given this branching is only here to support our transition to base58check.
// I hear you'd like to quantify this risk? Let's do it.
// Assuming random bytes in our bundle and a bundle length of 33 (public key, compressed) + 80 (encrypted cred) = 113 bytes.
// Assuming random bytes in our bundle and a bundle length of 33 (public key, compressed) + 48 (encrypted cred) = 81 bytes.
// The odds of a byte being in the overlap set between base58 and base64url is 58/64=0.90625.
// Which means the odds of a 113 bytes string being in the overlap character set for its entire length is...
// ... 0.90625^113 = 0.00001475795604
// Which means the odds of a 81 bytes string being in the overlap character set for its entire length is...
// ... 0.90625^81 = 0.0003444209703
// Are you convinced that this is good enough? I am :)
var bundleBytes = TKHQ.base58checkDecode(bundle);
var bundleBytes = await TKHQ.base58checkDecode(bundle);
} else {
var bundleBytes = TKHQ.base64urlDecode(bundle);
}
Expand Down
6 changes: 3 additions & 3 deletions recovery/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ describe("TKHQ", () => {
// Same input as above, except last digit changed.
await expect(TKHQ.base58checkDecode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNb")).rejects.toThrow("checksums do not match: computed 194,155,125,147 but found 194,155,125,148");

// Realistic recovery code: concatenation of a 33 bytes P-256 public key + a 80-bytes long encrypted credential
// Realistic recovery code: concatenation of a 33 bytes P-256 public key + a 48-bytes long encrypted credential
// Test vector from our internal repo, which uses Rust to encode in base58check.
expect(Array.from(await TKHQ.base58checkDecode("Mobo835D8oQBX4BWPSrtYFcVHFNGgsp1X14t1MM18QpZD3aJdZJ4MioQk6ChU2mZ6b7gM3RxyiV5ArnwK2TH8bTU19zNG29q4w9WbBEp8HWuJLYqBTCh3KJPbnCxVcvDdhHZQ5nmghUB7noTXLTXeu3nnHbnuEz"))).toEqual(
Array.from(TKHQ.uint8arrayFromHexString("03d61d659ab8485f30cfe261ff965179519b2aeb16223ccc217e99b09d5aeb94f1ce9e701341d6ab5b330bf39a3488dfe37a7fc0d04b556de1f7c4beaf4f3c131c2fbb5e28e9c3056d621b66a9bb0dac7c11759767c3ff10ca0f686a06c4a30b6e57902fadc9a2a840cf1356592220fc80"))
expect(Array.from(await TKHQ.base58checkDecode("szrFBNGDkhXyVvRoqjjDT6xd7kRhDXHmtQH3NVkPuVVkeiPFjn6UkyjbiTzuxH9wKH4QdEJUaWxZLM1ZLzByUFN1TNjxVh5aoZENCnKYrSEdZBnRWcK"))).toEqual(
Array.from(TKHQ.uint8arrayFromHexString("02cb30f1f44d411383cc2a7bb7135d87e0fbf265d0e002b460c9d38d97b14cd0d26114254d213cd77887293644d942a62516a3f174f01ed1ccb57dea1f8ac88664759bb6febcd8b060e7a11d23c614dd66"))
);
})

Expand Down

0 comments on commit 2247d36

Please sign in to comment.