@hpke/chacha20poly1305
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -27,2 +27,3 @@ /** | ||
readonly DhkemX448HkdfSha512: 33; | ||
readonly HybridkemX25519Kyber768: 48; | ||
}; | ||
@@ -46,2 +47,3 @@ /** | ||
readonly DhkemX448HkdfSha512: 33; | ||
readonly HybridkemX25519Kyber768: 48; | ||
}; | ||
@@ -48,0 +50,0 @@ /** |
@@ -23,2 +23,3 @@ /** | ||
DhkemX448HkdfSha512: 0x0021, | ||
HybridkemX25519Kyber768: 0x0030, | ||
}; | ||
@@ -25,0 +26,0 @@ /** |
@@ -6,3 +6,3 @@ { | ||
"name": "@hpke/chacha20poly1305", | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"description": "A Hybrid Public Key Encryption (HPKE) module extension for ChaCha20/Poly1305", | ||
@@ -9,0 +9,0 @@ "repository": { |
223
README.md
@@ -12,3 +12,3 @@ <h1 align="center">@hpke/chacha20poly1305</h1> | ||
| | ||
[pages(only for the latest ver.)](https://dajiaji.github.io/hpke-js/chacha20poly1305/docs/) | ||
[pages (only for the latest ver.)](https://dajiaji.github.io/hpke-js/chacha20poly1305/docs/) | ||
@@ -20,5 +20,5 @@ </div> | ||
- [Installation](#installation) | ||
- [Web Browser](#web-browser) | ||
- [Node.js](#nodejs) | ||
- [Deno](#deno) | ||
- [Web Browsers](#web-browsers) | ||
- [Cloudflare Workers](#cloudflare-workers) | ||
@@ -30,6 +30,35 @@ - [Usage](#usage) | ||
### Web Browser | ||
### Node.js | ||
Followings are how to use with typical CDNs. Other CDNs can be used as well. | ||
Using npm: | ||
```sh | ||
npm install @hpke/chacha20poly1305 | ||
``` | ||
Using yarn: | ||
```sh | ||
yarn add @hpke/chacha20poly1305 | ||
``` | ||
### Deno | ||
Using deno.land: | ||
```js | ||
// use a specific version | ||
import * as hpke from "https://deno.land/x/hpke@1.2.1/core/mod.ts"; | ||
import * as chacha20 from "https://deno.land/x/hpke@1.2.1/x/chacha20poly1305/mod.ts"; | ||
// use the latest stable version | ||
import * as hpke from "https://deno.land/x/hpke/core/mod.ts"; | ||
import * as chacha20 from "https://deno.land/x/hpke/x/chacha20poly1305/mod.ts"; | ||
``` | ||
### Web Browsers | ||
Followings are how to use this module with typical CDNs. Other CDNs can be used | ||
as well. | ||
Using esm.sh: | ||
@@ -40,4 +69,4 @@ | ||
<script type="module"> | ||
import * as hpke from "https://esm.sh/@hpke/core@1.2.0"; | ||
import * as chacha20 from "https://esm.sh/@hpke/chacha20poly1305@1.2.0"; | ||
import * as hpke from "https://esm.sh/@hpke/core@1.2.1"; | ||
import * as chacha20 from "https://esm.sh/@hpke/chacha20poly1305@1.2.1"; | ||
// ... | ||
@@ -59,4 +88,4 @@ </script> | ||
<script type="module"> | ||
import * as hpke from "https://unpkg.com/@hpke/core@1.2.0/esm/mod.js"; | ||
import * as chacha20 from "https://unpkg.com/@hpke/chacha20poly1305@1.2.0/esm/mod.js"; | ||
import * as hpke from "https://unpkg.com/@hpke/core@1.2.1/esm/mod.js"; | ||
import * as chacha20 from "https://unpkg.com/@hpke/chacha20poly1305@1.2.1/esm/mod.js"; | ||
// ... | ||
@@ -66,30 +95,2 @@ </script> | ||
### Node.js | ||
Using npm: | ||
```sh | ||
npm install @hpke/chacha20poly1305 | ||
``` | ||
Using yarn: | ||
```sh | ||
yarn add @hpke/chacha20poly1305 | ||
``` | ||
### Deno | ||
Using deno.land: | ||
```js | ||
// use a specific version | ||
import * as hpke from "https://deno.land/x/hpke@1.2.0/core/mod.ts"; | ||
import * as chacha20 from "https://deno.land/x/hpke@1.2.0/x/chacha20poly1305/mod.ts"; | ||
// use the latest stable version | ||
import * as hpke from "https://deno.land/x/hpke/core/mod.ts"; | ||
import * as chacha20 from "https://deno.land/x/hpke/x/chacha20poly1305/mod.ts"; | ||
``` | ||
### Cloudflare Workers | ||
@@ -109,54 +110,2 @@ | ||
### Browsers | ||
```html | ||
<html> | ||
<head></head> | ||
<body> | ||
<script type="module"> | ||
// import * as hpke from "https://esm.sh/hpke-js@1.2.0"; | ||
import { | ||
CipherSuite, DhkemP256HkdfSha256, HkdfSha256, | ||
} from "https://esm.sh/@hpke/core@1.2.0"; | ||
import { Chacha20Poly1305 } from "https://esm.sh/@hpke/chacha20poly1305@1.2.0"; | ||
globalThis.doHpke = async () => { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemP256HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Chacha20Poly1305() | ||
}); | ||
const rkp = await suite.kem.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey | ||
}); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable. | ||
enc: sender.enc, | ||
}); | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("hello world!")); | ||
// decrypt | ||
try { | ||
const pt = await recipient.open(ct); | ||
// hello world! | ||
alert(new TextDecoder().decode(pt)); | ||
} catch (err) { | ||
alert("failed to decrypt."); | ||
} | ||
} | ||
</script> | ||
<button type="button" onclick="doHpke()">do HPKE</button> | ||
</body> | ||
</html> | ||
``` | ||
### Node.js | ||
@@ -183,2 +132,5 @@ | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
const recipient = await suite.createRecipientContext({ | ||
@@ -189,17 +141,14 @@ recipientKey: rkp.privateKey, | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("my-secret-message")); | ||
// decrypt | ||
try { | ||
const pt = await recipient.open(ct); | ||
const pt = await recipient.open(ct); | ||
console.log("decrypted: ", new TextDecoder().decode(pt)); | ||
// decrypted: my-secret-message | ||
} catch (err) { | ||
console.log("failed to decrypt."); | ||
} | ||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
doHpke(); | ||
try { | ||
doHpke(); | ||
} catch (err) { | ||
console.log("failed:", err.message); | ||
} | ||
``` | ||
@@ -212,4 +161,4 @@ | ||
CipherSuite, DhkemP256HkdfSha256, HkdfSha256, | ||
} from "https://deno.land/x/hpke@1.2.0/core/mod.ts"; | ||
import { Chacha20Poly1305 } from "https://deno.land/x/hpke@1.2.0/x/chacha20poly1305/mod.ts"; | ||
} from "https://deno.land/x/hpke@1.2.1/core/mod.ts"; | ||
import { Chacha20Poly1305 } from "https://deno.land/x/hpke@1.2.1/x/chacha20poly1305/mod.ts"; | ||
@@ -230,2 +179,5 @@ async function doHpke() { | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
const recipient = await suite.createRecipientContext({ | ||
@@ -236,17 +188,64 @@ recipientKey: rkp.privateKey, | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("my-secret-message")); | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
try { | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
// Hello world! | ||
console.log(new TextDecoder().decode(pt)); | ||
} | ||
console.log("decrypted: ", new TextDecoder().decode(pt)); | ||
// decrypted: my-secret-message | ||
} catch (_err: unknown) { | ||
console.log("failed to decrypt."); | ||
} | ||
try { | ||
doHpke(); | ||
} catch (_err: unknown) { | ||
console.log("failed."); | ||
} | ||
``` | ||
doHpke(); | ||
### Browsers | ||
```html | ||
<html> | ||
<head></head> | ||
<body> | ||
<script type="module"> | ||
// import * as hpke from "https://esm.sh/hpke-js@1.2.1"; | ||
import { | ||
CipherSuite, DhkemP256HkdfSha256, HkdfSha256, | ||
} from "https://esm.sh/@hpke/core@1.2.1"; | ||
import { Chacha20Poly1305 } from "https://esm.sh/@hpke/chacha20poly1305@1.2.1"; | ||
globalThis.doHpke = async () => { | ||
try { | ||
const suite = new CipherSuite({ | ||
kem: new DhkemP256HkdfSha256(), | ||
kdf: new HkdfSha256(), | ||
aead: new Chacha20Poly1305() | ||
}); | ||
const rkp = await suite.kem.generateKeyPair(); | ||
const sender = await suite.createSenderContext({ | ||
recipientPublicKey: rkp.publicKey | ||
}); | ||
// encrypt | ||
const ct = await sender.seal(new TextEncoder().encode("Hello world!")); | ||
const recipient = await suite.createRecipientContext({ | ||
recipientKey: rkp.privateKey, // rkp (CryptoKeyPair) is also acceptable. | ||
enc: sender.enc, | ||
}); | ||
// decrypt | ||
const pt = await recipient.open(ct); | ||
// Hello world! | ||
alert(new TextDecoder().decode(pt)); | ||
} catch (err) { | ||
alert("failed:", err.message); | ||
} | ||
} | ||
</script> | ||
<button type="button" onclick="doHpke()">do HPKE</button> | ||
</body> | ||
</html> | ||
``` | ||
@@ -253,0 +252,0 @@ |
@@ -27,2 +27,3 @@ /** | ||
readonly DhkemX448HkdfSha512: 33; | ||
readonly HybridkemX25519Kyber768: 48; | ||
}; | ||
@@ -46,2 +47,3 @@ /** | ||
readonly DhkemX448HkdfSha512: 33; | ||
readonly HybridkemX25519Kyber768: 48; | ||
}; | ||
@@ -48,0 +50,0 @@ /** |
@@ -35,2 +35,3 @@ (function (factory) { | ||
DhkemX448HkdfSha512: 0x0021, | ||
HybridkemX25519Kyber768: 0x0030, | ||
}; | ||
@@ -37,0 +38,0 @@ /** |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32031
746
245