simple-hpke 0.0.8 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,11 +1,11 @@
1
1
  # Simple HPKE
2
2
  [![tests](https://img.shields.io/github/actions/workflow/status/nichoth/simple-hpke/nodejs.yml?style=flat-square)](https://github.com/nichoth/simple-hpke/actions/workflows/nodejs.yml)
3
- [![types](https://img.shields.io/npm/types/@substrate-system/simple-hpke?style=flat-square)](README.md)
3
+ [![types](https://img.shields.io/npm/types/simple-hpke?style=flat-square)](README.md)
4
4
  [![module](https://img.shields.io/badge/module-ESM%2FCJS-blue?style=flat-square)](README.md)
5
5
  [![semantic versioning](https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&style=flat-square)](https://semver.org/)
6
6
  [![Common Changelog](https://nichoth.github.io/badge/common-changelog.svg)](./CHANGELOG.md)
7
- [![install size](https://flat.badgen.net/packagephobia/install/@substrate-system/simple-hpke)](https://packagephobia.com/result?p=@substrate-system/simple-hpke)
8
- [![gzip size](https://flat.badgen.net/bundlephobia/minzip/@substrate-system/simple-hpke)](https://bundlephobia.com/package/@substrate-system/simple-hpke)
7
+ [![install size](https://flat.badgen.net/packagephobia/install/simple-hpke)](https://packagephobia.com/result?p=simple-hpke)
8
+ [![gzip size](https://flat.badgen.net/bundlephobia/minzip/simple-hpke)](https://bundlephobia.com/package/simple-hpke)
9
9
  [![license](https://img.shields.io/badge/license-Big_Time-blue?style=flat-square)](LICENSE)
10
10
 
11
11
 
@@ -24,7 +24,7 @@ Hybrid Public Key Encryption
24
24
  * [Hybrid Encryption](#hybrid-encryption)
25
25
  + [Encrypt / Decrypt](#encrypt--decrypt)
26
26
  - [`encrypt`](#encrypt)
27
- - [Encrypt to a string](#encrypt-to-a-string)
27
+ - [`encrypt.asString`](#encryptasstring)
28
28
  - [`decrypt`](#decrypt)
29
29
  - [`decrypt.asString`](#decryptasstring)
30
30
  - [`decrypt.fromString`](#decryptfromstring)
@@ -42,7 +42,7 @@ Hybrid Public Key Encryption
42
42
  ## Install
43
43
 
44
44
  ```sh
45
- npm i -S @substrate-system/simple-hpke
45
+ npm i -S simple-hpke
46
46
  ```
47
47
 
48
48
  ## Example
@@ -54,10 +54,11 @@ Wrap an AES key, or encrypt a message.
54
54
  Encrypt an AES key to yourself, then recover it later.
55
55
 
56
56
  ```ts
57
- import { seal, open } from '@substrate-system/simple-hpke'
57
+ import { seal, open } from 'simple-hpke'
58
58
 
59
- // An X25519 keypair. The private key can be non-extractable.
60
- // HPKE needs only `deriveBits`.
59
+ // An X25519 keypair. (asymmetric keypair).
60
+ // The private key can be non-extractable.
61
+ // HPKE only needs `deriveBits`.
61
62
  const keypair = await crypto.subtle.generateKey(
62
63
  { name: 'X25519' },
63
64
  false, // extractable
@@ -67,31 +68,37 @@ const keypair = await crypto.subtle.generateKey(
67
68
  // create a new AES key, and encrypt it to your public key.
68
69
  const { wrapped, key } = await seal(keypair)
69
70
 
70
- // Or wrap an existing AES key. The supplied key must be extractable.
71
+ // Or wrap an existing AES key. The supplied AES key must be extractable.
71
72
  const aesKey = await crypto.subtle.generateKey(
72
73
  { name: 'AES-GCM', length: 256 },
73
74
  true, // extractable
74
75
  ['encrypt', 'decrypt']
75
76
  )
76
77
 
77
- // pass in a key. The return value is just the wrapped key
78
+ // pass in an existing key. The return value has the wrapped key.
78
79
  const { wrapped } = await seal(keypair, aesKey)
79
80
 
80
81
  // Later, recover the same key with your private key.
81
82
  const recoveredKey = await open(keypair, wrapped)
83
+
84
+ // `recoveredKey` is equal to `aesKey`
82
85
  ```
83
86
 
84
87
  See [docs/README.md](./docs/README.md) for the full API and rationale.
85
88
 
89
+
90
+ ------------------------------------------------------
91
+
92
+
86
93
  ### Hybrid Encryption
87
94
 
88
- Seal a key, then use it to encrypt a message with AES-GCM.
89
- The wrapped key is concattenated with the cipher text, along with the
90
- IV. The recipient uses their private key to open the AES key and decrypt
91
- the message.
95
+ Encrypt a message with AES-GCM, then encrypt the AES key to a given
96
+ public key. The wrapped key is concattenated with the cipher text,
97
+ along with the IV. The recipient uses their private key to open the AES key and
98
+ decrypt the message.
92
99
 
93
100
  ```ts
94
- import { seal, open } from '@substrate-system/simple-hpke'
101
+ import { seal, open } from 'simple-hpke'
95
102
 
96
103
  const recipient = await crypto.subtle.generateKey(
97
104
  { name: 'X25519' },
@@ -155,10 +162,7 @@ cipher text). `decrypt` reverses it, returning the plaintext bytes.
155
162
 
156
163
 
157
164
  ```ts
158
- import {
159
- encrypt,
160
- decrypt
161
- } from '@substrate-system/simple-hpke'
165
+ import { encrypt, decrypt } from 'simple-hpke'
162
166
 
163
167
  // need a public key for the recipient
164
168
  const recipient = await crypto.subtle.generateKey(
@@ -214,14 +218,14 @@ async function encrypt (
214
218
  ):Promise<Uint8Array>
215
219
  ```
216
220
 
217
- ##### Encrypt to a string
221
+ ##### `encrypt.asString`
218
222
 
219
- `encrypt.asString` is `encrypt` with the envelope encoded to a string, handy
223
+ `encrypt.asString` is `encrypt` with the envelope encoded to a string, useful
220
224
  for transports that carry text (JSON, URLs, headers). `opts.encoding` sets the
221
225
  string encoding. Default encoding is `base64url`.
222
226
 
223
227
  ```ts
224
- import { encrypt, decrypt } from '@substrate-system/ecies'
228
+ import { encrypt, decrypt } from 'simple-hpke'
225
229
  import { fromString } from 'uint8arrays'
226
230
 
227
231
  // recipient is any RecipientKey; keypair holds the matching private key
@@ -289,12 +293,12 @@ This exposes ESM and common JS via
289
293
 
290
294
  ### ESM
291
295
  ```js
292
- import { seal, open, encrypt, decrypt } from '@substrate-system/simple-hpke'
296
+ import { seal, open, encrypt, decrypt } from 'simple-hpke'
293
297
  ```
294
298
 
295
299
  ### Common JS
296
300
  ```js
297
- require('@substrate-system/simple-hpke')
301
+ require('simple-hpke')
298
302
  ```
299
303
 
300
304
  ### pre-built JS
@@ -303,7 +307,7 @@ accessible to your web server, then link to them in HTML.
303
307
 
304
308
  #### copy
305
309
  ```sh
306
- cp ./node_modules/@substrate-system/simple-hpke/dist/index.min.js ./public/hpke.min.js
310
+ cp ./node_modules/simple-hpke/dist/index.min.js ./public/hpke.min.js
307
311
  ```
308
312
 
309
313
  #### HTML