mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 06:23:45 +00:00
code cleanup, support keypairs, init support for X25519
This commit is contained in:
@@ -47,6 +47,54 @@
|
||||
// }
|
||||
</script>
|
||||
|
||||
<script id=SubtleCrypto>
|
||||
testing.async(async () => {
|
||||
let key = await crypto.subtle.generateKey(
|
||||
{
|
||||
name: "HMAC",
|
||||
hash: { name: "SHA-512" },
|
||||
},
|
||||
true,
|
||||
["sign", "verify"],
|
||||
);
|
||||
|
||||
//const raw = crypto.subtle.exportKey("adv", key).catch(err => console.warn(err));
|
||||
//testing.expectEqual(128, raw.byteLength);
|
||||
|
||||
const encoder = new TextEncoder();
|
||||
|
||||
const signature = await crypto.subtle.sign(
|
||||
"HMAC",
|
||||
key,
|
||||
encoder.encode("Hello, world!")
|
||||
);
|
||||
|
||||
const result = await window.crypto.subtle.verify(
|
||||
{ name: "HMAC" },
|
||||
key,
|
||||
signature,
|
||||
encoder.encode("Hello, world!")
|
||||
);
|
||||
|
||||
testing.expectEqual(true, true);
|
||||
});
|
||||
</script>
|
||||
|
||||
<script id=X25519>
|
||||
testing.async(async () => {
|
||||
const { privateKey, publicKey } = await crypto.subtle.generateKey(
|
||||
{ name: "X25519" },
|
||||
true,
|
||||
["deriveKey", "deriveBits"],
|
||||
);
|
||||
|
||||
console.warn(privateKey);
|
||||
console.warn(publicKey);
|
||||
|
||||
testing.expectEqual(true, true);
|
||||
});
|
||||
</script>
|
||||
|
||||
<!-- <script id="randomUUID">
|
||||
const uuid = crypto.randomUUID();
|
||||
testing.expectEqual('string', typeof uuid);
|
||||
|
||||
@@ -26,3 +26,9 @@ pub extern fn HMAC(
|
||||
out: [*]u8,
|
||||
out_len: *c_uint,
|
||||
) ?[*]u8;
|
||||
|
||||
pub const X25519_PRIVATE_KEY_LEN = 32;
|
||||
pub const X25519_PUBLIC_VALUE_LEN = 32;
|
||||
pub const X25519_SHARED_KEY_LEN = 32;
|
||||
|
||||
pub extern fn X25519_keypair(out_public_value: *[32]u8, out_private_key: *[32]u8) void;
|
||||
|
||||
Reference in New Issue
Block a user