simple-hpke 0.1.0 → 0.1.2
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 +14 -9
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -78,6 +78,8 @@ const aesKey = await crypto.subtle.generateKey(
|
|
|
78
78
|
// Wrap an existing key.
|
|
79
79
|
const { enc: sealedKey } = await seal(keypair, aesKey)
|
|
80
80
|
|
|
81
|
+
// or pass in just a public key
|
|
82
|
+
|
|
81
83
|
// Later, recover the same key with your private key.
|
|
82
84
|
const recoveredKey = await open(keypair, sealedKey)
|
|
83
85
|
|
|
@@ -115,19 +117,22 @@ const ciphertextBuffer = await crypto.subtle.encrypt(
|
|
|
115
117
|
new TextEncoder().encode('attack at dawn')
|
|
116
118
|
)
|
|
117
119
|
|
|
118
|
-
// Send `enc`, `iv`, and `ciphertext` together. `
|
|
119
|
-
//
|
|
120
|
-
//
|
|
120
|
+
// Send `enc`, `iv`, and `ciphertext` together. `create(...)` defaults to a
|
|
121
|
+
// 256-bit AES key, so `enc.length` is 80 bytes in this example.
|
|
122
|
+
//
|
|
123
|
+
// If your protocol allows different wrapped-key sizes, prefix `enc.length`
|
|
124
|
+
// (or otherwise transmit it) so the recipient can split the payload safely.
|
|
121
125
|
const ciphertext = new Uint8Array(ciphertextBuffer)
|
|
122
|
-
const
|
|
126
|
+
const encLength = enc.length
|
|
127
|
+
const message = new Uint8Array(encLength + iv.length + ciphertext.length)
|
|
123
128
|
message.set(enc, 0)
|
|
124
|
-
message.set(iv,
|
|
125
|
-
message.set(ciphertext,
|
|
129
|
+
message.set(iv, encLength)
|
|
130
|
+
message.set(ciphertext, encLength + iv.length)
|
|
126
131
|
|
|
127
132
|
// On the other side, split the payload back into its parts.
|
|
128
|
-
const enc2 = message.subarray(0,
|
|
129
|
-
const iv2 = message.subarray(
|
|
130
|
-
const ciphertext2 = message.subarray(
|
|
133
|
+
const enc2 = message.subarray(0, encLength)
|
|
134
|
+
const iv2 = message.subarray(encLength, encLength + 12)
|
|
135
|
+
const ciphertext2 = message.subarray(encLength + 12)
|
|
131
136
|
|
|
132
137
|
// Recover the key, then decrypt the message.
|
|
133
138
|
const recovered = await open(recipient, enc2)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simple-hpke",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Hybrid Public Key Encryption",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@substrate-system/debug": "^0.9.64",
|
|
46
|
-
"@substrate-system/keys": "^0.2.
|
|
47
|
-
"@substrate-system/tapout": "^0.0.
|
|
48
|
-
"@substrate-system/tapzero": "^0.10.
|
|
46
|
+
"@substrate-system/keys": "^0.2.43",
|
|
47
|
+
"@substrate-system/tapout": "^0.0.40",
|
|
48
|
+
"@substrate-system/tapzero": "^0.10.16",
|
|
49
49
|
"auto-changelog": "^2.4.0",
|
|
50
50
|
"esbuild": "^0.28.1",
|
|
51
51
|
"eslint": "^10.6.0",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"newneostandard": "^0.14.1",
|
|
54
54
|
"typedoc": "^0.28.9",
|
|
55
55
|
"typescript": "^6.0.3",
|
|
56
|
-
"typescript-eslint": "^8.
|
|
56
|
+
"typescript-eslint": "^8.63.0"
|
|
57
57
|
},
|
|
58
58
|
"main": "dist/index.js",
|
|
59
59
|
"types": "./dist/index.d.ts",
|