@fgv/ts-web-extras 5.1.0-18 → 5.1.0-19
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/.rush/temp/{680645452ebdb4d7f294f08d3b45f143d69c3f5d.tar.log → 42a7a953924ae898114e7b6231a2408228d92433.tar.log} +8 -2
- package/.rush/temp/chunked-rush-logs/ts-web-extras.build.chunks.jsonl +19 -17
- package/.rush/temp/operation/build/all.log +19 -17
- package/.rush/temp/operation/build/log-chunks.jsonl +19 -17
- package/.rush/temp/operation/build/state.json +1 -1
- package/dist/packlets/crypto-utils/browserCryptoProvider.js +118 -1
- package/dist/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
- package/dist/test/unit/browserCryptoProvider.wrapBytes.test.js +221 -0
- package/dist/test/unit/browserCryptoProvider.wrapBytes.test.js.map +1 -0
- package/dist/ts-web-extras.d.ts +19 -0
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.md +28 -0
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.unwrapBytes.md +27 -0
- package/docs/CryptoUtils/classes/BrowserCryptoProvider.wrapBytes.md +28 -0
- package/docs/classes/BrowserCryptoProvider.md +28 -0
- package/docs/classes/BrowserCryptoProvider.unwrapBytes.md +27 -0
- package/docs/classes/BrowserCryptoProvider.wrapBytes.md +28 -0
- package/etc/ts-web-extras.api.md +5 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts +19 -0
- package/lib/packlets/crypto-utils/browserCryptoProvider.d.ts.map +1 -1
- package/lib/packlets/crypto-utils/browserCryptoProvider.js +118 -1
- package/lib/packlets/crypto-utils/browserCryptoProvider.js.map +1 -1
- package/lib/test/unit/browserCryptoProvider.wrapBytes.test.d.ts +2 -0
- package/lib/test/unit/browserCryptoProvider.wrapBytes.test.d.ts.map +1 -0
- package/lib/test/unit/browserCryptoProvider.wrapBytes.test.js +223 -0
- package/lib/test/unit/browserCryptoProvider.wrapBytes.test.js.map +1 -0
- package/package.json +14 -14
- package/rush-logs/ts-web-extras.build.cache.log +1 -1
- package/rush-logs/ts-web-extras.build.log +19 -17
- package/src/packlets/crypto-utils/browserCryptoProvider.ts +168 -1
- package/src/test/unit/browserCryptoProvider.wrapBytes.test.ts +325 -0
- package/temp/build/typescript/ts_8nwakTlr.json +1 -1
- package/temp/coverage/crypto-utils/browserCryptoProvider.ts.html +508 -7
- package/temp/coverage/crypto-utils/browserHashProvider.ts.html +1 -1
- package/temp/coverage/crypto-utils/index.html +9 -9
- package/temp/coverage/file-tree/directoryHandleStore.ts.html +1 -1
- package/temp/coverage/file-tree/fileApiTreeAccessors.ts.html +1 -1
- package/temp/coverage/file-tree/fileSystemAccessTreeAccessors.ts.html +1 -1
- package/temp/coverage/file-tree/httpTreeAccessors.ts.html +1 -1
- package/temp/coverage/file-tree/index.html +1 -1
- package/temp/coverage/file-tree/localStorageTreeAccessors.ts.html +1 -1
- package/temp/coverage/helpers/fileTreeHelpers.ts.html +1 -1
- package/temp/coverage/helpers/index.html +1 -1
- package/temp/coverage/index.html +10 -10
- package/temp/coverage/lcov-report/crypto-utils/browserCryptoProvider.ts.html +508 -7
- package/temp/coverage/lcov-report/crypto-utils/browserHashProvider.ts.html +1 -1
- package/temp/coverage/lcov-report/crypto-utils/index.html +9 -9
- package/temp/coverage/lcov-report/file-tree/directoryHandleStore.ts.html +1 -1
- package/temp/coverage/lcov-report/file-tree/fileApiTreeAccessors.ts.html +1 -1
- package/temp/coverage/lcov-report/file-tree/fileSystemAccessTreeAccessors.ts.html +1 -1
- package/temp/coverage/lcov-report/file-tree/httpTreeAccessors.ts.html +1 -1
- package/temp/coverage/lcov-report/file-tree/index.html +1 -1
- package/temp/coverage/lcov-report/file-tree/localStorageTreeAccessors.ts.html +1 -1
- package/temp/coverage/lcov-report/helpers/fileTreeHelpers.ts.html +1 -1
- package/temp/coverage/lcov-report/helpers/index.html +1 -1
- package/temp/coverage/lcov-report/index.html +10 -10
- package/temp/coverage/lcov-report/url-utils/index.html +1 -1
- package/temp/coverage/lcov-report/url-utils/urlParams.ts.html +1 -1
- package/temp/coverage/lcov.info +236 -25
- package/temp/coverage/url-utils/index.html +1 -1
- package/temp/coverage/url-utils/urlParams.ts.html +1 -1
- package/temp/test/jest/haste-map-7492f1b44480e0cdd1f220078fb3afd8-c8dd6c3430605adeb2f1cadf4f75e791-8c9336785555d572065b28c111982ba4 +0 -0
- package/temp/test/jest/perf-cache-7492f1b44480e0cdd1f220078fb3afd8-da39a3ee5e6b4b0d3255bfef95601890 +1 -1
- package/temp/ts-web-extras.api.json +212 -0
- package/temp/ts-web-extras.api.md +5 -0
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright (c) 2026 Erik Fortune
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
* furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
* copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
* SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
import '@fgv/ts-utils-jest';
|
|
23
|
+
import { BrowserCryptoProvider } from '../../packlets/crypto-utils';
|
|
24
|
+
const provider = new BrowserCryptoProvider();
|
|
25
|
+
const subtle = globalThis.crypto.subtle;
|
|
26
|
+
async function generateEcdhPair(curve = 'P-256') {
|
|
27
|
+
return (await subtle.generateKey({ name: 'ECDH', namedCurve: curve }, true, [
|
|
28
|
+
'deriveKey',
|
|
29
|
+
'deriveBits'
|
|
30
|
+
]));
|
|
31
|
+
}
|
|
32
|
+
async function generateEcdsaPair() {
|
|
33
|
+
return (await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, [
|
|
34
|
+
'sign',
|
|
35
|
+
'verify'
|
|
36
|
+
]));
|
|
37
|
+
}
|
|
38
|
+
describe('BrowserCryptoProvider — wrapBytes/unwrapBytes', () => {
|
|
39
|
+
const defaultOptions = {
|
|
40
|
+
salt: new TextEncoder().encode('test-salt'),
|
|
41
|
+
info: new TextEncoder().encode('test-info')
|
|
42
|
+
};
|
|
43
|
+
describe('round-trip', () => {
|
|
44
|
+
test.each([
|
|
45
|
+
['32-byte plaintext (AES-256 key shape)', globalThis.crypto.getRandomValues(new Uint8Array(32))],
|
|
46
|
+
['1-byte plaintext', new Uint8Array([0x42])],
|
|
47
|
+
['1KB plaintext', globalThis.crypto.getRandomValues(new Uint8Array(1024))],
|
|
48
|
+
['empty plaintext', new Uint8Array(0)],
|
|
49
|
+
['high-bit-set bytes', new Uint8Array(64).fill(0xff)]
|
|
50
|
+
])('round-trips %s', async (__label, plaintext) => {
|
|
51
|
+
const pair = await generateEcdhPair();
|
|
52
|
+
const wrapped = (await provider.wrapBytes(plaintext, pair.publicKey, defaultOptions)).orThrow();
|
|
53
|
+
expect(wrapped.ephemeralPublicKey.kty).toBe('EC');
|
|
54
|
+
expect(wrapped.ephemeralPublicKey.crv).toBe('P-256');
|
|
55
|
+
const recovered = (await provider.unwrapBytes(wrapped, pair.privateKey, defaultOptions)).orThrow();
|
|
56
|
+
expect(new Uint8Array(recovered)).toEqual(plaintext);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('determinism / freshness', () => {
|
|
60
|
+
test('two wraps of identical inputs produce different ephemeral keys and ciphertexts', async () => {
|
|
61
|
+
const pair = await generateEcdhPair();
|
|
62
|
+
const plaintext = new TextEncoder().encode('same payload');
|
|
63
|
+
const w1 = (await provider.wrapBytes(plaintext, pair.publicKey, defaultOptions)).orThrow();
|
|
64
|
+
const w2 = (await provider.wrapBytes(plaintext, pair.publicKey, defaultOptions)).orThrow();
|
|
65
|
+
expect(w1.ephemeralPublicKey).not.toEqual(w2.ephemeralPublicKey);
|
|
66
|
+
expect(w1.ciphertext).not.toEqual(w2.ciphertext);
|
|
67
|
+
expect(w1.nonce).not.toEqual(w2.nonce);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
describe('tampering', () => {
|
|
71
|
+
test('flipping a bit in the nonce fails GCM authentication', async () => {
|
|
72
|
+
const pair = await generateEcdhPair();
|
|
73
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
74
|
+
const nonce = provider.fromBase64(wrapped.nonce).orThrow();
|
|
75
|
+
nonce[0] ^= 0xff;
|
|
76
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { nonce: provider.toBase64(nonce) });
|
|
77
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed/i);
|
|
78
|
+
});
|
|
79
|
+
test('flipping a bit in the ciphertext fails GCM authentication', async () => {
|
|
80
|
+
const pair = await generateEcdhPair();
|
|
81
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
82
|
+
const ct = provider.fromBase64(wrapped.ciphertext).orThrow();
|
|
83
|
+
ct[0] ^= 0x01;
|
|
84
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { ciphertext: provider.toBase64(ct) });
|
|
85
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed/i);
|
|
86
|
+
});
|
|
87
|
+
test('truncating ciphertext by one byte fails GCM authentication (still ≥ 16 bytes)', async () => {
|
|
88
|
+
const pair = await generateEcdhPair();
|
|
89
|
+
// 16-byte plaintext → 32-byte ciphertext (16 ct + 16 tag); truncate by 1 → 31 bytes ≥ 16
|
|
90
|
+
const wrapped = (await provider.wrapBytes(new Uint8Array(16).fill(0xab), pair.publicKey, defaultOptions)).orThrow();
|
|
91
|
+
const ct = provider.fromBase64(wrapped.ciphertext).orThrow();
|
|
92
|
+
const truncated = ct.slice(0, ct.length - 1);
|
|
93
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { ciphertext: provider.toBase64(truncated) });
|
|
94
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed/i);
|
|
95
|
+
});
|
|
96
|
+
test('substituting a different ephemeral public key fails authentication', async () => {
|
|
97
|
+
const pair = await generateEcdhPair();
|
|
98
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
99
|
+
const other = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
100
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { ephemeralPublicKey: other.ephemeralPublicKey });
|
|
101
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed/i);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
describe('wrong-key / wrong-options', () => {
|
|
105
|
+
test('unwrap with a different recipient private key fails', async () => {
|
|
106
|
+
const pair = await generateEcdhPair();
|
|
107
|
+
const other = await generateEcdhPair();
|
|
108
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
109
|
+
expect(await provider.unwrapBytes(wrapped, other.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed/i);
|
|
110
|
+
});
|
|
111
|
+
test('unwrap with a different HKDF salt fails authentication', async () => {
|
|
112
|
+
const pair = await generateEcdhPair();
|
|
113
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
114
|
+
const wrongSalt = {
|
|
115
|
+
salt: new TextEncoder().encode('different-salt'),
|
|
116
|
+
info: defaultOptions.info
|
|
117
|
+
};
|
|
118
|
+
expect(await provider.unwrapBytes(wrapped, pair.privateKey, wrongSalt)).toFailWith(/unwrapBytes failed/i);
|
|
119
|
+
});
|
|
120
|
+
test('unwrap with a different HKDF info fails authentication', async () => {
|
|
121
|
+
const pair = await generateEcdhPair();
|
|
122
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
123
|
+
const wrongInfo = {
|
|
124
|
+
salt: defaultOptions.salt,
|
|
125
|
+
info: new TextEncoder().encode('different-info')
|
|
126
|
+
};
|
|
127
|
+
expect(await provider.unwrapBytes(wrapped, pair.privateKey, wrongInfo)).toFailWith(/unwrapBytes failed/i);
|
|
128
|
+
});
|
|
129
|
+
test('empty salt and info round-trip when both sides agree', async () => {
|
|
130
|
+
const pair = await generateEcdhPair();
|
|
131
|
+
const empty = { salt: new Uint8Array(0), info: new Uint8Array(0) };
|
|
132
|
+
const plaintext = globalThis.crypto.getRandomValues(new Uint8Array(16));
|
|
133
|
+
const wrapped = (await provider.wrapBytes(plaintext, pair.publicKey, empty)).orThrow();
|
|
134
|
+
const recovered = (await provider.unwrapBytes(wrapped, pair.privateKey, empty)).orThrow();
|
|
135
|
+
expect(new Uint8Array(recovered)).toEqual(plaintext);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
describe('malformed input', () => {
|
|
139
|
+
test('malformed ephemeralPublicKey JWK fails', async () => {
|
|
140
|
+
const pair = await generateEcdhPair();
|
|
141
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
142
|
+
const bogus = Object.assign(Object.assign({}, wrapped), { ephemeralPublicKey: { kty: 'EC', crv: 'P-256' } });
|
|
143
|
+
expect(await provider.unwrapBytes(bogus, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed/i);
|
|
144
|
+
});
|
|
145
|
+
test('ephemeralPublicKey on the wrong curve (P-384) fails', async () => {
|
|
146
|
+
const pair = await generateEcdhPair();
|
|
147
|
+
const wrongCurve = await generateEcdhPair('P-384');
|
|
148
|
+
const wrongJwk = await subtle.exportKey('jwk', wrongCurve.publicKey);
|
|
149
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
150
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { ephemeralPublicKey: wrongJwk });
|
|
151
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed/i);
|
|
152
|
+
});
|
|
153
|
+
test('non-base64 nonce fails with a clean error', async () => {
|
|
154
|
+
const pair = await generateEcdhPair();
|
|
155
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
156
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { nonce: 'not!base64!' });
|
|
157
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed: nonce/i);
|
|
158
|
+
});
|
|
159
|
+
test('non-base64 ciphertext fails with a clean error', async () => {
|
|
160
|
+
const pair = await generateEcdhPair();
|
|
161
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
162
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { ciphertext: 'not!base64!' });
|
|
163
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed: ciphertext/i);
|
|
164
|
+
});
|
|
165
|
+
test('wrong-length nonce (after base64 decode) fails before reaching AES-GCM', async () => {
|
|
166
|
+
const pair = await generateEcdhPair();
|
|
167
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
168
|
+
const shortNonce = new Uint8Array(8);
|
|
169
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { nonce: provider.toBase64(shortNonce) });
|
|
170
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed: nonce must be 12 bytes \(got 8\)/i);
|
|
171
|
+
});
|
|
172
|
+
test('ciphertext shorter than the GCM auth tag fails before reaching AES-GCM', async () => {
|
|
173
|
+
const pair = await generateEcdhPair();
|
|
174
|
+
const wrapped = (await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)).orThrow();
|
|
175
|
+
const shortCt = new Uint8Array(8);
|
|
176
|
+
const tampered = Object.assign(Object.assign({}, wrapped), { ciphertext: provider.toBase64(shortCt) });
|
|
177
|
+
expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(/unwrapBytes failed: ciphertext must be at least 16 bytes \(got 8\)/i);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
describe('algorithm / type mismatch on recipient key', () => {
|
|
181
|
+
test('wrap fails when recipient public key is RSA-OAEP, not ECDH', async () => {
|
|
182
|
+
const rsa = (await subtle.generateKey({
|
|
183
|
+
name: 'RSA-OAEP',
|
|
184
|
+
modulusLength: 2048,
|
|
185
|
+
publicExponent: new Uint8Array([0x01, 0x00, 0x01]),
|
|
186
|
+
hash: 'SHA-256'
|
|
187
|
+
}, true, ['encrypt', 'decrypt']));
|
|
188
|
+
const result = await provider.wrapBytes(new Uint8Array([1, 2, 3]), rsa.publicKey, defaultOptions);
|
|
189
|
+
expect(result).toFailWith(/wrapBytes failed: recipient public key must be ECDH P-256.*RSA-OAEP/i);
|
|
190
|
+
});
|
|
191
|
+
test('wrap fails when recipient public key is ECDSA P-256, not ECDH', async () => {
|
|
192
|
+
const ecdsa = await generateEcdsaPair();
|
|
193
|
+
const result = await provider.wrapBytes(new Uint8Array([1, 2, 3]), ecdsa.publicKey, defaultOptions);
|
|
194
|
+
expect(result).toFailWith(/wrapBytes failed: recipient public key must be ECDH P-256.*ECDSA/i);
|
|
195
|
+
});
|
|
196
|
+
test('wrap fails when recipient public key is ECDH P-384, not P-256', async () => {
|
|
197
|
+
const wrongCurve = await generateEcdhPair('P-384');
|
|
198
|
+
const result = await provider.wrapBytes(new Uint8Array([1, 2, 3]), wrongCurve.publicKey, defaultOptions);
|
|
199
|
+
expect(result).toFailWith(/wrapBytes failed: recipient public key must be ECDH P-256.*P-384/i);
|
|
200
|
+
});
|
|
201
|
+
test('unwrap fails when recipient private key is ECDH P-384, not P-256', async () => {
|
|
202
|
+
const pair = await generateEcdhPair();
|
|
203
|
+
const wrapped = (await provider.wrapBytes(new Uint8Array([1, 2, 3]), pair.publicKey, defaultOptions)).orThrow();
|
|
204
|
+
const wrongCurve = await generateEcdhPair('P-384');
|
|
205
|
+
const result = await provider.unwrapBytes(wrapped, wrongCurve.privateKey, defaultOptions);
|
|
206
|
+
expect(result).toFailWith(/unwrapBytes failed: recipient private key must be ECDH P-256.*P-384/i);
|
|
207
|
+
});
|
|
208
|
+
test('wrap fails when recipient is an ECDH private key (not public)', async () => {
|
|
209
|
+
const pair = await generateEcdhPair();
|
|
210
|
+
const result = await provider.wrapBytes(new Uint8Array([1, 2, 3]), pair.privateKey, defaultOptions);
|
|
211
|
+
expect(result).toFailWith(/wrapBytes failed: recipient public key must be a public CryptoKey \(got 'private'\)/i);
|
|
212
|
+
});
|
|
213
|
+
test('unwrap fails when recipient is an ECDH public key (not private)', async () => {
|
|
214
|
+
const pair = await generateEcdhPair();
|
|
215
|
+
const wrapped = (await provider.wrapBytes(new Uint8Array([1, 2, 3]), pair.publicKey, defaultOptions)).orThrow();
|
|
216
|
+
const result = await provider.unwrapBytes(wrapped, pair.publicKey, defaultOptions);
|
|
217
|
+
expect(result).toFailWith(/unwrapBytes failed: recipient private key must be a private CryptoKey \(got 'public'\)/i);
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
//# sourceMappingURL=browserCryptoProvider.wrapBytes.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserCryptoProvider.wrapBytes.test.js","sourceRoot":"","sources":["../../../src/test/unit/browserCryptoProvider.wrapBytes.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,oBAAoB,CAAC;AAG5B,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpE,MAAM,QAAQ,GAAG,IAAI,qBAAqB,EAAE,CAAC;AAC7C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC;AAExC,KAAK,UAAU,gBAAgB,CAAC,QAA2B,OAAO;IAChE,OAAO,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE;QAC1E,WAAW;QACX,YAAY;KACb,CAAC,CAAkB,CAAC;AACvB,CAAC;AAED,KAAK,UAAU,iBAAiB;IAC9B,OAAO,CAAC,MAAM,MAAM,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE;QAC7E,MAAM;QACN,QAAQ;KACT,CAAC,CAAkB,CAAC;AACvB,CAAC;AAED,QAAQ,CAAC,+CAA+C,EAAE,GAAG,EAAE;IAC7D,MAAM,cAAc,GAAkC;QACpD,IAAI,EAAE,IAAI,WAAW,EAAE,CA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ACJ,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,iEAAiE,EAAE,KAAK,IAAI,EAAE;YACjF,MAAM,IAAI,GAAG,MAAM,gBAAgB,EAAE,CAAC;YACtC,MAAM,OAAO,GAAG,CACd,MAAM,QAAQ,CAAC,SAAS,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CACpF,CAAC,OAAO,EAAE,CAAC;YACZ,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;YACnF,MAAM,CAAC,MAAM,CAAC,CAAC,UAAU,CACvB,yFAAyF,CAC1F,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n\nimport '@fgv/ts-utils-jest';\n\nimport { CryptoUtils } from '@fgv/ts-extras';\nimport { BrowserCryptoProvider } from '../../packlets/crypto-utils';\n\nconst provider = new BrowserCryptoProvider();\nconst subtle = globalThis.crypto.subtle;\n\nasync function generateEcdhPair(curve: 'P-256' | 'P-384' = 'P-256'): Promise<CryptoKeyPair> {\n return (await subtle.generateKey({ name: 'ECDH', namedCurve: curve }, true, [\n 'deriveKey',\n 'deriveBits'\n ])) as CryptoKeyPair;\n}\n\nasync function generateEcdsaPair(): Promise<CryptoKeyPair> {\n return (await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, [\n 'sign',\n 'verify'\n ])) as CryptoKeyPair;\n}\n\ndescribe('BrowserCryptoProvider — wrapBytes/unwrapBytes', () => {\n const defaultOptions: CryptoUtils.IWrapBytesOptions = {\n salt: new TextEncoder().encode('test-salt'),\n info: new TextEncoder().encode('test-info')\n };\n\n describe('round-trip', () => {\n test.each<[string, Uint8Array]>([\n ['32-byte plaintext (AES-256 key shape)', globalThis.crypto.getRandomValues(new Uint8Array(32))],\n ['1-byte plaintext', new Uint8Array([0x42])],\n ['1KB plaintext', globalThis.crypto.getRandomValues(new Uint8Array(1024))],\n ['empty plaintext', new Uint8Array(0)],\n ['high-bit-set bytes', new Uint8Array(64).fill(0xff)]\n ])('round-trips %s', async (__label, plaintext) => {\n const pair = await generateEcdhPair();\n const wrapped = (await provider.wrapBytes(plaintext, pair.publicKey, defaultOptions)).orThrow();\n expect(wrapped.ephemeralPublicKey.kty).toBe('EC');\n expect(wrapped.ephemeralPublicKey.crv).toBe('P-256');\n const recovered = (await provider.unwrapBytes(wrapped, pair.privateKey, defaultOptions)).orThrow();\n expect(new Uint8Array(recovered)).toEqual(plaintext);\n });\n });\n\n describe('determinism / freshness', () => {\n test('two wraps of identical inputs produce different ephemeral keys and ciphertexts', async () => {\n const pair = await generateEcdhPair();\n const plaintext = new TextEncoder().encode('same payload');\n const w1 = (await provider.wrapBytes(plaintext, pair.publicKey, defaultOptions)).orThrow();\n const w2 = (await provider.wrapBytes(plaintext, pair.publicKey, defaultOptions)).orThrow();\n expect(w1.ephemeralPublicKey).not.toEqual(w2.ephemeralPublicKey);\n expect(w1.ciphertext).not.toEqual(w2.ciphertext);\n expect(w1.nonce).not.toEqual(w2.nonce);\n });\n });\n\n describe('tampering', () => {\n test('flipping a bit in the nonce fails GCM authentication', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const nonce = provider.fromBase64(wrapped.nonce).orThrow();\n nonce[0] ^= 0xff;\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, nonce: provider.toBase64(nonce) };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('flipping a bit in the ciphertext fails GCM authentication', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const ct = provider.fromBase64(wrapped.ciphertext).orThrow();\n ct[0] ^= 0x01;\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, ciphertext: provider.toBase64(ct) };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('truncating ciphertext by one byte fails GCM authentication (still ≥ 16 bytes)', async () => {\n const pair = await generateEcdhPair();\n // 16-byte plaintext → 32-byte ciphertext (16 ct + 16 tag); truncate by 1 → 31 bytes ≥ 16\n const wrapped = (\n await provider.wrapBytes(new Uint8Array(16).fill(0xab), pair.publicKey, defaultOptions)\n ).orThrow();\n const ct = provider.fromBase64(wrapped.ciphertext).orThrow();\n const truncated = ct.slice(0, ct.length - 1);\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, ciphertext: provider.toBase64(truncated) };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('substituting a different ephemeral public key fails authentication', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const other = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const tampered: CryptoUtils.IWrappedBytes = {\n ...wrapped,\n ephemeralPublicKey: other.ephemeralPublicKey\n };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n });\n\n describe('wrong-key / wrong-options', () => {\n test('unwrap with a different recipient private key fails', async () => {\n const pair = await generateEcdhPair();\n const other = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n expect(await provider.unwrapBytes(wrapped, other.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('unwrap with a different HKDF salt fails authentication', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const wrongSalt: CryptoUtils.IWrapBytesOptions = {\n salt: new TextEncoder().encode('different-salt'),\n info: defaultOptions.info\n };\n expect(await provider.unwrapBytes(wrapped, pair.privateKey, wrongSalt)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('unwrap with a different HKDF info fails authentication', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const wrongInfo: CryptoUtils.IWrapBytesOptions = {\n salt: defaultOptions.salt,\n info: new TextEncoder().encode('different-info')\n };\n expect(await provider.unwrapBytes(wrapped, pair.privateKey, wrongInfo)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('empty salt and info round-trip when both sides agree', async () => {\n const pair = await generateEcdhPair();\n const empty: CryptoUtils.IWrapBytesOptions = { salt: new Uint8Array(0), info: new Uint8Array(0) };\n const plaintext = globalThis.crypto.getRandomValues(new Uint8Array(16));\n const wrapped = (await provider.wrapBytes(plaintext, pair.publicKey, empty)).orThrow();\n const recovered = (await provider.unwrapBytes(wrapped, pair.privateKey, empty)).orThrow();\n expect(new Uint8Array(recovered)).toEqual(plaintext);\n });\n });\n\n describe('malformed input', () => {\n test('malformed ephemeralPublicKey JWK fails', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const bogus: CryptoUtils.IWrappedBytes = {\n ...wrapped,\n ephemeralPublicKey: { kty: 'EC', crv: 'P-256' } as JsonWebKey\n };\n expect(await provider.unwrapBytes(bogus, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('ephemeralPublicKey on the wrong curve (P-384) fails', async () => {\n const pair = await generateEcdhPair();\n const wrongCurve = await generateEcdhPair('P-384');\n const wrongJwk = await subtle.exportKey('jwk', wrongCurve.publicKey);\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, ephemeralPublicKey: wrongJwk };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed/i\n );\n });\n\n test('non-base64 nonce fails with a clean error', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, nonce: 'not!base64!' };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed: nonce/i\n );\n });\n\n test('non-base64 ciphertext fails with a clean error', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, ciphertext: 'not!base64!' };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed: ciphertext/i\n );\n });\n\n test('wrong-length nonce (after base64 decode) fails before reaching AES-GCM', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const shortNonce = new Uint8Array(8);\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, nonce: provider.toBase64(shortNonce) };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed: nonce must be 12 bytes \\(got 8\\)/i\n );\n });\n\n test('ciphertext shorter than the GCM auth tag fails before reaching AES-GCM', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new TextEncoder().encode('payload'), pair.publicKey, defaultOptions)\n ).orThrow();\n const shortCt = new Uint8Array(8);\n const tampered: CryptoUtils.IWrappedBytes = { ...wrapped, ciphertext: provider.toBase64(shortCt) };\n expect(await provider.unwrapBytes(tampered, pair.privateKey, defaultOptions)).toFailWith(\n /unwrapBytes failed: ciphertext must be at least 16 bytes \\(got 8\\)/i\n );\n });\n });\n\n describe('algorithm / type mismatch on recipient key', () => {\n test('wrap fails when recipient public key is RSA-OAEP, not ECDH', async () => {\n const rsa = (await subtle.generateKey(\n {\n name: 'RSA-OAEP',\n modulusLength: 2048,\n publicExponent: new Uint8Array([0x01, 0x00, 0x01]),\n hash: 'SHA-256'\n },\n true,\n ['encrypt', 'decrypt']\n )) as CryptoKeyPair;\n const result = await provider.wrapBytes(new Uint8Array([1, 2, 3]), rsa.publicKey, defaultOptions);\n expect(result).toFailWith(/wrapBytes failed: recipient public key must be ECDH P-256.*RSA-OAEP/i);\n });\n\n test('wrap fails when recipient public key is ECDSA P-256, not ECDH', async () => {\n const ecdsa = await generateEcdsaPair();\n const result = await provider.wrapBytes(new Uint8Array([1, 2, 3]), ecdsa.publicKey, defaultOptions);\n expect(result).toFailWith(/wrapBytes failed: recipient public key must be ECDH P-256.*ECDSA/i);\n });\n\n test('wrap fails when recipient public key is ECDH P-384, not P-256', async () => {\n const wrongCurve = await generateEcdhPair('P-384');\n const result = await provider.wrapBytes(\n new Uint8Array([1, 2, 3]),\n wrongCurve.publicKey,\n defaultOptions\n );\n expect(result).toFailWith(/wrapBytes failed: recipient public key must be ECDH P-256.*P-384/i);\n });\n\n test('unwrap fails when recipient private key is ECDH P-384, not P-256', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new Uint8Array([1, 2, 3]), pair.publicKey, defaultOptions)\n ).orThrow();\n const wrongCurve = await generateEcdhPair('P-384');\n const result = await provider.unwrapBytes(wrapped, wrongCurve.privateKey, defaultOptions);\n expect(result).toFailWith(/unwrapBytes failed: recipient private key must be ECDH P-256.*P-384/i);\n });\n\n test('wrap fails when recipient is an ECDH private key (not public)', async () => {\n const pair = await generateEcdhPair();\n const result = await provider.wrapBytes(new Uint8Array([1, 2, 3]), pair.privateKey, defaultOptions);\n expect(result).toFailWith(\n /wrapBytes failed: recipient public key must be a public CryptoKey \\(got 'private'\\)/i\n );\n });\n\n test('unwrap fails when recipient is an ECDH public key (not private)', async () => {\n const pair = await generateEcdhPair();\n const wrapped = (\n await provider.wrapBytes(new Uint8Array([1, 2, 3]), pair.publicKey, defaultOptions)\n ).orThrow();\n const result = await provider.unwrapBytes(wrapped, pair.publicKey, defaultOptions);\n expect(result).toFailWith(\n /unwrapBytes failed: recipient private key must be a private CryptoKey \\(got 'public'\\)/i\n );\n });\n });\n});\n"]}
|
package/dist/ts-web-extras.d.ts
CHANGED
|
@@ -109,6 +109,25 @@ declare class BrowserCryptoProvider implements CryptoUtils_2.ICryptoProvider {
|
|
|
109
109
|
* @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
|
|
110
110
|
*/
|
|
111
111
|
importPublicKeyJwk(jwk: JsonWebKey, algorithm: CryptoUtils_2.KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
112
|
+
/**
|
|
113
|
+
* Wraps `plaintext` for the holder of `recipientPublicKey` using
|
|
114
|
+
* ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
|
|
115
|
+
* {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
|
|
116
|
+
* @param plaintext - The bytes to wrap.
|
|
117
|
+
* @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
|
|
118
|
+
* @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
|
|
119
|
+
* @returns `Success` with the wrapped payload, or `Failure` with an error.
|
|
120
|
+
*/
|
|
121
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: CryptoUtils_2.IWrapBytesOptions): Promise<Result<CryptoUtils_2.IWrappedBytes>>;
|
|
122
|
+
/**
|
|
123
|
+
* Unwraps a payload produced by `wrapBytes` using the recipient's private
|
|
124
|
+
* key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
|
|
125
|
+
* @param wrapped - The wrapped payload.
|
|
126
|
+
* @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
|
|
127
|
+
* @param options - HKDF salt and info matching the wrap call.
|
|
128
|
+
* @returns `Success` with the original `plaintext`, or `Failure` with an error.
|
|
129
|
+
*/
|
|
130
|
+
unwrapBytes(wrapped: CryptoUtils_2.IWrappedBytes, recipientPrivateKey: CryptoKey, options: CryptoUtils_2.IWrapBytesOptions): Promise<Result<Uint8Array>>;
|
|
112
131
|
}
|
|
113
132
|
|
|
114
133
|
/**
|
|
@@ -199,5 +199,33 @@ Exports a public `CryptoKey` as a JSON Web Key.
|
|
|
199
199
|
|
|
200
200
|
Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
|
|
201
201
|
|
|
202
|
+
</td></tr>
|
|
203
|
+
<tr><td>
|
|
204
|
+
|
|
205
|
+
[wrapBytes(plaintext, recipientPublicKey, options)](./BrowserCryptoProvider.wrapBytes.md)
|
|
206
|
+
|
|
207
|
+
</td><td>
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
</td><td>
|
|
212
|
+
|
|
213
|
+
Wraps `plaintext` for the holder of `recipientPublicKey` using
|
|
214
|
+
ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256).
|
|
215
|
+
|
|
216
|
+
</td></tr>
|
|
217
|
+
<tr><td>
|
|
218
|
+
|
|
219
|
+
[unwrapBytes(wrapped, recipientPrivateKey, options)](./BrowserCryptoProvider.unwrapBytes.md)
|
|
220
|
+
|
|
221
|
+
</td><td>
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
</td><td>
|
|
226
|
+
|
|
227
|
+
Unwraps a payload produced by `wrapBytes` using the recipient's private
|
|
228
|
+
key.
|
|
229
|
+
|
|
202
230
|
</td></tr>
|
|
203
231
|
</tbody></table>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[Home](../../README.md) > [CryptoUtils](../README.md) > [BrowserCryptoProvider](./BrowserCryptoProvider.md) > unwrapBytes
|
|
2
|
+
|
|
3
|
+
## BrowserCryptoProvider.unwrapBytes() method
|
|
4
|
+
|
|
5
|
+
Unwraps a payload produced by `wrapBytes` using the recipient's private
|
|
6
|
+
key. See CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes.
|
|
7
|
+
|
|
8
|
+
**Signature:**
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array<ArrayBufferLike>>>;
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**Parameters:**
|
|
15
|
+
|
|
16
|
+
<table><thead><tr><th>Parameter</th><th>Type</th><th>Description</th></tr></thead>
|
|
17
|
+
<tbody>
|
|
18
|
+
<tr><td>wrapped</td><td>IWrappedBytes</td><td>The wrapped payload.</td></tr>
|
|
19
|
+
<tr><td>recipientPrivateKey</td><td>CryptoKey</td><td>The recipient's ECDH P-256 private `CryptoKey`.</td></tr>
|
|
20
|
+
<tr><td>options</td><td>IWrapBytesOptions</td><td>HKDF salt and info matching the wrap call.</td></tr>
|
|
21
|
+
</tbody></table>
|
|
22
|
+
|
|
23
|
+
**Returns:**
|
|
24
|
+
|
|
25
|
+
Promise<Result<Uint8Array<ArrayBufferLike>>>
|
|
26
|
+
|
|
27
|
+
`Success` with the original `plaintext`, or `Failure` with an error.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[Home](../../README.md) > [CryptoUtils](../README.md) > [BrowserCryptoProvider](./BrowserCryptoProvider.md) > wrapBytes
|
|
2
|
+
|
|
3
|
+
## BrowserCryptoProvider.wrapBytes() method
|
|
4
|
+
|
|
5
|
+
Wraps `plaintext` for the holder of `recipientPublicKey` using
|
|
6
|
+
ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
|
|
7
|
+
CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Parameters:**
|
|
16
|
+
|
|
17
|
+
<table><thead><tr><th>Parameter</th><th>Type</th><th>Description</th></tr></thead>
|
|
18
|
+
<tbody>
|
|
19
|
+
<tr><td>plaintext</td><td>Uint8Array</td><td>The bytes to wrap.</td></tr>
|
|
20
|
+
<tr><td>recipientPublicKey</td><td>CryptoKey</td><td>The recipient's ECDH P-256 public `CryptoKey`.</td></tr>
|
|
21
|
+
<tr><td>options</td><td>IWrapBytesOptions</td><td>HKDF salt and info; see CryptoUtils.IWrapBytesOptions | IWrapBytesOptions.</td></tr>
|
|
22
|
+
</tbody></table>
|
|
23
|
+
|
|
24
|
+
**Returns:**
|
|
25
|
+
|
|
26
|
+
Promise<Result<IWrappedBytes>>
|
|
27
|
+
|
|
28
|
+
`Success` with the wrapped payload, or `Failure` with an error.
|
|
@@ -199,5 +199,33 @@ Exports a public `CryptoKey` as a JSON Web Key.
|
|
|
199
199
|
|
|
200
200
|
Imports a public-key JWK as a `CryptoKey` for the requested algorithm.
|
|
201
201
|
|
|
202
|
+
</td></tr>
|
|
203
|
+
<tr><td>
|
|
204
|
+
|
|
205
|
+
[wrapBytes(plaintext, recipientPublicKey, options)](./BrowserCryptoProvider.wrapBytes.md)
|
|
206
|
+
|
|
207
|
+
</td><td>
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
</td><td>
|
|
212
|
+
|
|
213
|
+
Wraps `plaintext` for the holder of `recipientPublicKey` using
|
|
214
|
+
ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256).
|
|
215
|
+
|
|
216
|
+
</td></tr>
|
|
217
|
+
<tr><td>
|
|
218
|
+
|
|
219
|
+
[unwrapBytes(wrapped, recipientPrivateKey, options)](./BrowserCryptoProvider.unwrapBytes.md)
|
|
220
|
+
|
|
221
|
+
</td><td>
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
</td><td>
|
|
226
|
+
|
|
227
|
+
Unwraps a payload produced by `wrapBytes` using the recipient's private
|
|
228
|
+
key.
|
|
229
|
+
|
|
202
230
|
</td></tr>
|
|
203
231
|
</tbody></table>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[Home](../README.md) > [BrowserCryptoProvider](./BrowserCryptoProvider.md) > unwrapBytes
|
|
2
|
+
|
|
3
|
+
## BrowserCryptoProvider.unwrapBytes() method
|
|
4
|
+
|
|
5
|
+
Unwraps a payload produced by `wrapBytes` using the recipient's private
|
|
6
|
+
key. See CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes.
|
|
7
|
+
|
|
8
|
+
**Signature:**
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
unwrapBytes(wrapped: IWrappedBytes, recipientPrivateKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<Uint8Array<ArrayBufferLike>>>;
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
**Parameters:**
|
|
15
|
+
|
|
16
|
+
<table><thead><tr><th>Parameter</th><th>Type</th><th>Description</th></tr></thead>
|
|
17
|
+
<tbody>
|
|
18
|
+
<tr><td>wrapped</td><td>IWrappedBytes</td><td>The wrapped payload.</td></tr>
|
|
19
|
+
<tr><td>recipientPrivateKey</td><td>CryptoKey</td><td>The recipient's ECDH P-256 private `CryptoKey`.</td></tr>
|
|
20
|
+
<tr><td>options</td><td>IWrapBytesOptions</td><td>HKDF salt and info matching the wrap call.</td></tr>
|
|
21
|
+
</tbody></table>
|
|
22
|
+
|
|
23
|
+
**Returns:**
|
|
24
|
+
|
|
25
|
+
Promise<Result<Uint8Array<ArrayBufferLike>>>
|
|
26
|
+
|
|
27
|
+
`Success` with the original `plaintext`, or `Failure` with an error.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
[Home](../README.md) > [BrowserCryptoProvider](./BrowserCryptoProvider.md) > wrapBytes
|
|
2
|
+
|
|
3
|
+
## BrowserCryptoProvider.wrapBytes() method
|
|
4
|
+
|
|
5
|
+
Wraps `plaintext` for the holder of `recipientPublicKey` using
|
|
6
|
+
ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
|
|
7
|
+
CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes.
|
|
8
|
+
|
|
9
|
+
**Signature:**
|
|
10
|
+
|
|
11
|
+
```typescript
|
|
12
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: IWrapBytesOptions): Promise<Result<IWrappedBytes>>;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Parameters:**
|
|
16
|
+
|
|
17
|
+
<table><thead><tr><th>Parameter</th><th>Type</th><th>Description</th></tr></thead>
|
|
18
|
+
<tbody>
|
|
19
|
+
<tr><td>plaintext</td><td>Uint8Array</td><td>The bytes to wrap.</td></tr>
|
|
20
|
+
<tr><td>recipientPublicKey</td><td>CryptoKey</td><td>The recipient's ECDH P-256 public `CryptoKey`.</td></tr>
|
|
21
|
+
<tr><td>options</td><td>IWrapBytesOptions</td><td>HKDF salt and info; see CryptoUtils.IWrapBytesOptions | IWrapBytesOptions.</td></tr>
|
|
22
|
+
</tbody></table>
|
|
23
|
+
|
|
24
|
+
**Returns:**
|
|
25
|
+
|
|
26
|
+
Promise<Result<IWrappedBytes>>
|
|
27
|
+
|
|
28
|
+
`Success` with the wrapped payload, or `Failure` with an error.
|
package/etc/ts-web-extras.api.md
CHANGED
|
@@ -25,6 +25,11 @@ class BrowserCryptoProvider implements CryptoUtils_2.ICryptoProvider {
|
|
|
25
25
|
importPublicKeyJwk(jwk: JsonWebKey, algorithm: CryptoUtils_2.KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
26
26
|
sha256(data: string): Promise<Result<string>>;
|
|
27
27
|
toBase64(data: Uint8Array): string;
|
|
28
|
+
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
|
|
29
|
+
unwrapBytes(wrapped: CryptoUtils_2.IWrappedBytes, recipientPrivateKey: CryptoKey, options: CryptoUtils_2.IWrapBytesOptions): Promise<Result<Uint8Array>>;
|
|
30
|
+
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
|
|
31
|
+
// Warning: (ae-unresolved-link) The @link reference could not be resolved: This type of declaration is not supported yet by the resolver
|
|
32
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: CryptoUtils_2.IWrapBytesOptions): Promise<Result<CryptoUtils_2.IWrappedBytes>>;
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
// @public
|
|
@@ -94,6 +94,25 @@ export declare class BrowserCryptoProvider implements CryptoUtils.ICryptoProvide
|
|
|
94
94
|
* @returns `Success` with the imported public `CryptoKey`, or `Failure` with an error.
|
|
95
95
|
*/
|
|
96
96
|
importPublicKeyJwk(jwk: JsonWebKey, algorithm: CryptoUtils.KeyPairAlgorithm): Promise<Result<CryptoKey>>;
|
|
97
|
+
/**
|
|
98
|
+
* Wraps `plaintext` for the holder of `recipientPublicKey` using
|
|
99
|
+
* ECIES (ECDH P-256 + HKDF-SHA256 + AES-GCM-256). See
|
|
100
|
+
* {@link CryptoUtils.ICryptoProvider.wrapBytes | ICryptoProvider.wrapBytes}.
|
|
101
|
+
* @param plaintext - The bytes to wrap.
|
|
102
|
+
* @param recipientPublicKey - The recipient's ECDH P-256 public `CryptoKey`.
|
|
103
|
+
* @param options - HKDF salt and info; see {@link CryptoUtils.IWrapBytesOptions | IWrapBytesOptions}.
|
|
104
|
+
* @returns `Success` with the wrapped payload, or `Failure` with an error.
|
|
105
|
+
*/
|
|
106
|
+
wrapBytes(plaintext: Uint8Array, recipientPublicKey: CryptoKey, options: CryptoUtils.IWrapBytesOptions): Promise<Result<CryptoUtils.IWrappedBytes>>;
|
|
107
|
+
/**
|
|
108
|
+
* Unwraps a payload produced by `wrapBytes` using the recipient's private
|
|
109
|
+
* key. See {@link CryptoUtils.ICryptoProvider.unwrapBytes | ICryptoProvider.unwrapBytes}.
|
|
110
|
+
* @param wrapped - The wrapped payload.
|
|
111
|
+
* @param recipientPrivateKey - The recipient's ECDH P-256 private `CryptoKey`.
|
|
112
|
+
* @param options - HKDF salt and info matching the wrap call.
|
|
113
|
+
* @returns `Success` with the original `plaintext`, or `Failure` with an error.
|
|
114
|
+
*/
|
|
115
|
+
unwrapBytes(wrapped: CryptoUtils.IWrappedBytes, recipientPrivateKey: CryptoKey, options: CryptoUtils.IWrapBytesOptions): Promise<Result<Uint8Array>>;
|
|
97
116
|
}
|
|
98
117
|
/**
|
|
99
118
|
* Creates a {@link CryptoUtils.BrowserCryptoProvider | BrowserCryptoProvider} if Web
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browserCryptoProvider.d.ts","sourceRoot":"","sources":["../../../src/packlets/crypto-utils/browserCryptoProvider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"browserCryptoProvider.d.ts","sourceRoot":"","sources":["../../../src/packlets/crypto-utils/browserCryptoProvider.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAoD,MAAM,EAAoB,MAAM,eAAe,CAAC;AAC3G,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAkC7C;;;;;;;;GAQG;AACH,qBAAa,qBAAsB,YAAW,WAAW,CAAC,eAAe;IACvE,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IAGjC;;;OAGG;gBACgB,SAAS,CAAC,EAAE,MAAM;IAYrC;;;;;OAKG;IACU,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAmDxG;;;;;;;OAOG;IACU,OAAO,CAClB,aAAa,EAAE,UAAU,EACzB,GAAG,EAAE,UAAU,EACf,EAAE,EAAE,UAAU,EACd,OAAO,EAAE,UAAU,GAClB,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAgD1B;;;OAGG;IACU,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAWvD;;;;;;OAMG;IACU,SAAS,CACpB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,EAChB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAqC9B;;;;OAIG;IACU,MAAM,CAAC,IAAI,E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