Skip to content

Commit bc77e38

Browse files
authored
Merge pull request #411 from wheval/ci/issue-387-web-crypto-budget
CI: web crypto build + tests + bundle-size budget
2 parents 12d87ce + 6799290 commit bc77e38

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

apps/web/src/lib/x3dh.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,20 @@ const ED25519_SPKI_HEADER = new Uint8Array([
2727
]);
2828

2929
export function toBase64(bytes: Uint8Array): string {
30-
return Buffer.from(bytes).toString('base64');
30+
let binary = '';
31+
for (let i = 0; i < bytes.length; i += 1) {
32+
binary += String.fromCharCode(bytes[i]!);
33+
}
34+
return btoa(binary);
3135
}
3236

3337
export function fromBase64(b64: string): Uint8Array {
34-
return new Uint8Array(Buffer.from(b64, 'base64'));
38+
const binary = atob(b64);
39+
const out = new Uint8Array(binary.length);
40+
for (let i = 0; i < binary.length; i += 1) {
41+
out[i] = binary.charCodeAt(i);
42+
}
43+
return out;
3544
}
3645

3746
export function rawEd25519PublicKeyToSpki(rawPublicKey: Uint8Array): Uint8Array {

0 commit comments

Comments
 (0)