Skip to content

Commit

Permalink
Merge pull request #348 from dajiaji/fix-samples-in-readme-for-jsr
Browse files Browse the repository at this point in the history
Fix samples in readme for  JSR.
  • Loading branch information
dajiaji authored Aug 25, 2024
2 parents 622826e + e60cfe6 commit 17efd08
Show file tree
Hide file tree
Showing 6 changed files with 244 additions and 170 deletions.
203 changes: 122 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,29 @@ npm install hpke-js
Then, you can use it as follows:

```js
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js"; // or "hpke-js"
// import { AeadId, CipherSuite, KdfId, KemId } from "hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("@hpke/hpke-js");
// import {
// Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256,
// } from "@hpke/core";
import {
Aes128Gcm,
CipherSuite,
DhkemP256HkdfSha256,
HkdfSha256,
} from "@hpke/core";

async function doHpke() {
const suite = new CipherSuite({
kem: KemId.DhkemP256HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.Aes128Gcm,
});
// When using "@hpke/core", specify the cryptographic algorithm instances
// as follows, instead of identities above.
// When using "hpke-js", specify the cryptographic algorithm as follows:
// const suite = new CipherSuite({
// kem: new DhkemP256HkdfSha256(),
// kdf: new HkdfSha256(),
// aead: new Aes128Gcm(),
// kem: KemId.DhkemP256HkdfSha256,
// kdf: KdfId.HkdfSha256,
// aead: AeadId.Aes128Gcm,
// });
// When using "@hpke/core", specify the cryptographic algorithm instances
// as follows, instead of identities above:
const suite = new CipherSuite({
kem: new DhkemP256HkdfSha256(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});

// A recipient generates a key pair.
const rkp = await suite.kem.generateKeyPair();
Expand Down Expand Up @@ -296,17 +300,27 @@ This section shows some typical usage examples.
Node.js:

```js
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js"; // or "hpke-js"
// import { AeadId, CipherSuite, KdfId, KemId } from "hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("hpke-js");
// import {
// Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256,
// } from "@hpke/core";
import {
Aes128Gcm,
CipherSuite,
DhkemP256HkdfSha256,
HkdfSha256,
} from "@hpke/core";

async function doHpke() {
// When using "hpke-js":
// const suite = new CipherSuite({
// kem: KemId.DhkemP256HkdfSha256,
// kdf: KdfId.HkdfSha256,
// aead: AeadId.Aes128Gcm,
// });
// When using "@hpke/core":
const suite = new CipherSuite({
kem: KemId.DhkemP256HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.Aes128Gcm,
kem: new DhkemP256HkdfSha256(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});

// A recipient generates a key pair.
Expand Down Expand Up @@ -339,27 +353,23 @@ try {
Deno:

```ts
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js";
// import {
// Aes128Gcm, CipherSuite, HkdfSha256,
// } from "https://deno.land/x/[email protected]/core/mod.ts";
// import { DhkemX25519HkdfSha256 } from "@hpke/dhkem-x25519";
// import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js";
import { Aes128Gcm, CipherSuite, HkdfSha256 } from "@hpke/core";
import { DhkemX25519HkdfSha256 } from "@hpke/dhkem-x25519";

async function doHpke() {
// setup
// When using "@hpke/hpke-js", you can specify the identifier as follows:
// const suite = new CipherSuite({
// kem: KemId.DhkemX25519HkdfSha256,
// kdf: KdfId.HkdfSha256,
// aead: AeadId.Aes128Gcm,
// });
// When using "@hpke/core" and @hpke/dhkem-x25519, specify the instances as follows:
const suite = new CipherSuite({
// When using "https://deno.land/x/hpke/mod.ts" (not "/x/hpke/core/mod.ts"),
// you can specify the identifier as follows:
kem: KemId.DhkemX25519HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.Aes128Gcm,
kem: new DhkemX25519HkdfSha256(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});
//// When using hpke/core/mod.ts, specify the instances as follows:
//const suite = new CipherSuite({
// kem: new DhkemX25519HkdfSha256(),
// kdf: new HkdfSha256(),
// aead: new Aes128Gcm(),
//});

const rkp = await suite.kem.generateKeyPair();

Expand Down Expand Up @@ -429,7 +439,7 @@ Browsers:
import { AeadId, CipherSuite, KdfId, KemId } from "https://esm.sh/[email protected]";
// import {
// Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256,
// } from "@hpke/[email protected]";
// } from "https://esm.sh/@hpke/[email protected]";
globalThis.doHpke = async () => {
try {
Expand Down Expand Up @@ -475,18 +485,25 @@ Browsers:
Node.js:

```js
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js";
// import { AeadId, CipherSuite, KdfId, KemId } from "hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("hpke-js");
// import {
// Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256,
// } from "@hpke/core";
import {
Aes128Gcm,
CipherSuite,
DhkemP256HkdfSha256,
HkdfSha256,
} from "@hpke/core";

async function doHpke() {
// setup
// const suite = new CipherSuite({
// kem: KemId.DhkemP256HkdfSha256,
// kdf: KdfId.HkdfSha256,
// aead: AeadId.Aes128Gcm,
// });
const suite = new CipherSuite({
kem: KemId.DhkemP256HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.Aes128Gcm,
kem: new DhkemP256HkdfSha256(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});

const rkp = await suite.kem.generateKeyPair();
Expand Down Expand Up @@ -517,20 +534,23 @@ try {
Node.js:

```js
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("@hpke/hpke-js");
// import {
// CipherSuite, DhkemP256HkdfSha256, ExportOnly, HkdfSha256,
// } from "@hpke/core";
// import { AeadId, CipherSuite, KdfId, KemId } from "hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("hpke-js");
import {
CipherSuite,
DhkemP256HkdfSha256,
ExportOnly,
HkdfSha256,
} from "@hpke/core";

async function doHpke() {
// setup
// When using "hpke-js":
const suite = new CipherSuite({
kem: KemId.DhkemP256HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.ExportOnly,
});
// When using "@hpke/core",
// When using "@hpke/core":
const suite = new CipherSuite({
kem: new DhkemP256HkdfSha256(),
kdf: new HkdfSha256(),
Expand Down Expand Up @@ -568,18 +588,25 @@ try {
Node.js:

```js
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("@hpke/hpke-js");
// import {
// Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256,
// } from "@hpke/core";
// import { AeadId, CipherSuite, KdfId, KemId } from "@hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("@hpke-js");
import {
Aes128Gcm,
CipherSuite,
DhkemP256HkdfSha256,
HkdfSha256,
} from "@hpke/core";

async function doHpke() {
// setup
// const suite = new CipherSuite({
// kem: KemId.DhkemP256HkdfSha256,
// kdf: KdfId.HkdfSha256,
// aead: AeadId.Aes128Gcm,
// });
const suite = new CipherSuite({
kem: KemId.DhkemP256HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.Aes128Gcm,
kem: new DhkemP256HkdfSha256(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});

const rkp = await suite.kem.generateKeyPair();
Expand Down Expand Up @@ -625,18 +652,25 @@ try {
Node.js:

```js
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("@hpke/hpke-js");
// import {
// Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256,
// } from "@hpke/core";
// import { AeadId, CipherSuite, KdfId, KemId } from "hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("hpke-js");
import {
Aes128Gcm,
CipherSuite,
DhkemP256HkdfSha256,
HkdfSha256,
} from "@hpke/core";

async function doHpke() {
// setup
// const suite = new CipherSuite({
// kem: KemId.DhkemP256HkdfSha256,
// kdf: KdfId.HkdfSha256,
// aead: AeadId.Aes128Gcm,
// });
const suite = new CipherSuite({
kem: KemId.DhkemP256HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.Aes128Gcm,
kem: new DhkemP256HkdfSha256(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});

const rkp = await suite.kem.generateKeyPair();
Expand Down Expand Up @@ -675,18 +709,25 @@ try {
Node.js:

```js
import { AeadId, CipherSuite, KdfId, KemId } from "@hpke/hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("@hpke/hpke-js");
// import {
// Aes128Gcm, CipherSuite, DhkemP256HkdfSha256, HkdfSha256,
// } from "@hpke/core";
// import { AeadId, CipherSuite, KdfId, KemId } from "hpke-js";
// const { AeadId, CipherSuite, KdfId, KemId } = require("hpke-js");
import {
Aes128Gcm,
CipherSuite,
DhkemP256HkdfSha256,
HkdfSha256,
} from "@hpke/core";

async function doHpke() {
// setup
// const suite = new CipherSuite({
// kem: KemId.DhkemP256HkdfSha256,
// kdf: KdfId.HkdfSha256,
// aead: AeadId.Aes128Gcm,
// });
const suite = new CipherSuite({
kem: KemId.DhkemP256HkdfSha256,
kdf: KdfId.HkdfSha256,
aead: AeadId.Aes128Gcm,
kem: new DhkemP256HkdfSha256(),
kdf: new HkdfSha256(),
aead: new Aes128Gcm(),
});

const rkp = await suite.kem.generateKeyPair();
Expand Down
2 changes: 0 additions & 2 deletions x/dhkem-secp256k1/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<h1 align="center">@hpke/dhkem-secp256k1</h1>

<!--
<div align="center">
<a href="https://jsr.io/@hpke/dhkem-secp256k1"><img src="https://jsr.io/badges/@hpke/dhkem-secp256k1" alt="JSR"/></a>
</div>
-->

<div align="center">
A TypeScript <a href="https://datatracker.ietf.org/doc/html/rfc9180">Hybrid Public Key Encryption (HPKE)</a> module extension for DH-KEM with secp256k1 curve, which is implemented by using <a href="https://github.com/paulmillr/noble-curves">@noble/curves/secp256k1</a>. Note that the extension is EXPERIMENTAL and NOT STANDARDIZED.</div>
Expand Down
2 changes: 0 additions & 2 deletions x/dhkem-x25519/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<h1 align="center">@hpke/dhkem-x25519</h1>

<!--
<div align="center">
<a href="https://jsr.io/@hpke/dhkem-x25519"><img src="https://jsr.io/badges/@hpke/dhkem-x25519" alt="JSR"/></a>
</div>
-->

<div align="center">
A TypeScript <a href="https://datatracker.ietf.org/doc/html/rfc9180">Hybrid Public Key Encryption (HPKE)</a> module extension for DH-KEM with X25519, which is implemented by using <a href="https://github.com/paulmillr/noble-curves">@noble/curves</a></div>
Expand Down
2 changes: 0 additions & 2 deletions x/dhkem-x448/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
<h1 align="center">@hpke/dhkem-x448</h1>

<!--
<div align="center">
<a href="https://jsr.io/@hpke/dhkem-x448"><img src="https://jsr.io/badges/@hpke/dhkem-x448" alt="JSR"/></a>
</div>
-->

<div align="center">
A TypeScript <a href="https://datatracker.ietf.org/doc/html/rfc9180">Hybrid Public Key Encryption (HPKE)</a> module extension for DH-KEM with X448, which is implemented by using <a href="https://github.com/paulmillr/noble-curves">@noble/curves</a></div>
Expand Down
Loading

0 comments on commit 17efd08

Please sign in to comment.