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 +18 -11
- package/dist/constants.cjs +1768 -0
- package/dist/constants.cjs.map +7 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +1751 -0
- package/dist/constants.js.map +7 -0
- package/dist/constants.min.cjs +2 -0
- package/dist/constants.min.cjs.map +7 -0
- package/dist/constants.min.js +2 -0
- package/dist/constants.min.js.map +7 -0
- package/dist/index.cjs +212 -207
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +8 -81
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +212 -207
- package/dist/index.js.map +4 -4
- package/dist/index.min.cjs +1 -1
- package/dist/index.min.cjs.map +4 -4
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/meta.json +298 -4
- package/dist/util.cjs +1767 -0
- package/dist/util.cjs.map +7 -0
- package/dist/util.d.ts +90 -0
- package/dist/util.d.ts.map +1 -0
- package/dist/util.js +1750 -0
- package/dist/util.js.map +7 -0
- package/dist/util.min.cjs +2 -0
- package/dist/util.min.cjs.map +7 -0
- package/dist/util.min.js +2 -0
- package/dist/util.min.js.map +7 -0
- package/package.json +1 -1
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
|
-
- [
|
|
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.
|
|
60
|
-
//
|
|
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
|
|
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
|
-
|
|
89
|
-
The wrapped key is concattenated with the cipher text,
|
|
90
|
-
IV. The recipient uses their private key to open the AES key and
|
|
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
|
-
#####
|
|
221
|
+
##### `encrypt.asString`
|
|
215
222
|
|
|
216
|
-
`encrypt.asString` is `encrypt` with the envelope encoded to a string,
|
|
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
|
|