-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #301 from OR13/debug-webpack-of-ts-of-hpke
Add webpack sample
- Loading branch information
Showing
8 changed files
with
3,312 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist | ||
app.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256 } from "@hpke/core"; | ||
|
||
export const test = async () => { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemP256HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Aes128Gcm(), | ||
}); | ||
|
||
// I expected to be able to do: | ||
// const rkp = await suite.kem.generateKeyPair(); | ||
// instead I needed to do: | ||
const extractable = true | ||
const rkp = await window.crypto.subtle.generateKey({ | ||
name: "ECDH", | ||
namedCurve: "P-256", | ||
}, extractable, ['deriveBits']) | ||
|
||
// A sender encrypts a message. | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey | ||
}); | ||
const ct = await sender.seal(new TextEncoder().encode("✨ hello world! ✨")); | ||
// A recipient decripts it. | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, | ||
enc: sender.enc, | ||
}); | ||
try { | ||
const pt = await recipient.open(ct); | ||
// hello world! | ||
alert(new TextDecoder().decode(pt)); | ||
} catch (err) { | ||
alert("failed to decrypt."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<title>Test</title> | ||
<script src="./dist/main.js" class="remove"></script> | ||
<script> | ||
window.test.test(); | ||
</script> | ||
</head> | ||
<body> | ||
<pre>See developer console.</pre> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
|
||
import * as app from './app.js' | ||
|
||
const test = async () => { | ||
app.test() | ||
} | ||
// setup exports on window | ||
window.test = { | ||
test | ||
} |
Oops, something went wrong.