simple-hpke 0.0.9 → 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
@@ -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)
@@ -56,8 +56,9 @@ Encrypt an AES key to yourself, then recover it later.
56
56
  ```ts
57
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,28 +68,34 @@ 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
101
  import { seal, open } from 'simple-hpke'
@@ -211,9 +218,9 @@ async function encrypt (
211
218
  ):Promise<Uint8Array>
212
219
  ```
213
220
 
214
- ##### Encrypt to a string
221
+ ##### `encrypt.asString`
215
222
 
216
- `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
217
224
  for transports that carry text (JSON, URLs, headers). `opts.encoding` sets the
218
225
  string encoding. Default encoding is `base64url`.
219
226