@gnufoo/envlp 0.1.1
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/envlp_wasm.d.ts +323 -0
- package/envlp_wasm.js +751 -0
- package/envlp_wasm_bg.wasm +0 -0
- package/envlp_wasm_bg.wasm.d.ts +24 -0
- package/init.d.ts +11 -0
- package/init.js +24 -0
- package/meta.d.ts +85 -0
- package/meta.js +129 -0
- package/package.json +45 -0
- package/tool.d.ts +8 -0
- package/tool.js +169 -0
package/envlp_wasm.d.ts
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Returns the key size in bytes (32 = 256 bits).
|
|
6
|
+
*/
|
|
7
|
+
export function KEY_SIZE(): number;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Returns the nonce size in bytes (24 = 192 bits).
|
|
11
|
+
*/
|
|
12
|
+
export function NONCE_SIZE(): number;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Returns the current envelope format version.
|
|
16
|
+
*
|
|
17
|
+
* Per AAED spec, current version is 1.
|
|
18
|
+
*/
|
|
19
|
+
export function SPEC_VERSION(): number;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Returns the authentication tag size in bytes (16 = 128 bits).
|
|
23
|
+
*/
|
|
24
|
+
export function TAG_SIZE(): number;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Checks if bytes start with the envelope magic prefix.
|
|
28
|
+
*
|
|
29
|
+
* Magic bytes are `0x454E5601` ("ENV" + version byte).
|
|
30
|
+
* This can be used for quick format detection without full CBOR parsing.
|
|
31
|
+
*
|
|
32
|
+
* # Arguments
|
|
33
|
+
*
|
|
34
|
+
* * `bytes` - Bytes to check (Uint8Array)
|
|
35
|
+
*
|
|
36
|
+
* # Returns
|
|
37
|
+
*
|
|
38
|
+
* `true` if bytes start with magic prefix, `false` otherwise.
|
|
39
|
+
*
|
|
40
|
+
* # Example (JavaScript)
|
|
41
|
+
*
|
|
42
|
+
* ```javascript
|
|
43
|
+
* const envelope = seal(key, plaintext, aad, "my-key");
|
|
44
|
+
* console.log(hasMagicPrefix(envelope)); // true
|
|
45
|
+
*
|
|
46
|
+
* const noMagic = seal(key, plaintext, aad, "my-key", true, false);
|
|
47
|
+
* console.log(hasMagicPrefix(noMagic)); // false
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export function hasMagicPrefix(bytes: Uint8Array): boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Inspects envelope metadata without decryption.
|
|
54
|
+
*
|
|
55
|
+
* Returns information about the envelope that can be extracted without
|
|
56
|
+
* decryption. Useful for logging, debugging, and routing decisions
|
|
57
|
+
* (e.g., selecting the correct key based on key_id).
|
|
58
|
+
*
|
|
59
|
+
* # Arguments
|
|
60
|
+
*
|
|
61
|
+
* * `envelope_bytes` - CBOR-encoded envelope (Uint8Array)
|
|
62
|
+
*
|
|
63
|
+
* # Returns
|
|
64
|
+
*
|
|
65
|
+
* JavaScript object with envelope metadata:
|
|
66
|
+
* - `version`: Envelope format version (number)
|
|
67
|
+
* - `algorithm`: Algorithm name (string, e.g., "XChaCha20Poly1305")
|
|
68
|
+
* - `algorithmId`: Algorithm ID (number, 1=XChaCha20, 2=GCM-SIV, 3=GCM)
|
|
69
|
+
* - `keyId`: Key identifier from header (string)
|
|
70
|
+
* - `nonceHex`: Nonce as hexadecimal string
|
|
71
|
+
* - `ciphertextLen`: Ciphertext length in bytes (number)
|
|
72
|
+
* - `hasAad`: Whether AAD is included in envelope (boolean)
|
|
73
|
+
* - `aadLen`: AAD length in bytes (number or null)
|
|
74
|
+
* - `isWrappedMode`: Whether envelope uses wrapped mode (boolean)
|
|
75
|
+
*
|
|
76
|
+
* # Errors
|
|
77
|
+
*
|
|
78
|
+
* Throws a JavaScript error if envelope parsing fails.
|
|
79
|
+
*
|
|
80
|
+
* # Example (JavaScript)
|
|
81
|
+
*
|
|
82
|
+
* ```javascript
|
|
83
|
+
* const meta = inspect(envelope);
|
|
84
|
+
* console.log(`Key: ${meta.keyId}, Algorithm: ${meta.algorithm}`);
|
|
85
|
+
* if (meta.hasAad) {
|
|
86
|
+
* console.log(`AAD size: ${meta.aadLen} bytes`);
|
|
87
|
+
* }
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export function inspect(envelope_bytes: Uint8Array): any;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Generates a new 256-bit encryption key.
|
|
94
|
+
*
|
|
95
|
+
* Uses a cryptographically secure random number generator.
|
|
96
|
+
*
|
|
97
|
+
* # Returns
|
|
98
|
+
*
|
|
99
|
+
* A 32-byte `Uint8Array` containing the random key.
|
|
100
|
+
*
|
|
101
|
+
* # Example (JavaScript)
|
|
102
|
+
*
|
|
103
|
+
* ```javascript
|
|
104
|
+
* const key = keygen();
|
|
105
|
+
* console.log(key.length); // 32
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function keygen(): Uint8Array;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Returns the magic bytes as Uint8Array.
|
|
112
|
+
*
|
|
113
|
+
* Magic bytes are `0x454E5601` ("ENV" + version byte) for format detection.
|
|
114
|
+
*/
|
|
115
|
+
export function magicBytes(): Uint8Array;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Decrypts an envelope using reconstructed AAD.
|
|
119
|
+
*
|
|
120
|
+
* Use this when AAD was not included in the envelope (reconstructed mode).
|
|
121
|
+
* The provided AAD JSON will be canonicalized before verification.
|
|
122
|
+
*
|
|
123
|
+
* # Arguments
|
|
124
|
+
*
|
|
125
|
+
* * `key` - 256-bit decryption key (Uint8Array, 32 bytes)
|
|
126
|
+
* * `envelope_bytes` - CBOR-encoded envelope (Uint8Array)
|
|
127
|
+
* * `aad_json` - AAD as JSON string (must match AAD used during encryption)
|
|
128
|
+
*
|
|
129
|
+
* # Returns
|
|
130
|
+
*
|
|
131
|
+
* Decrypted plaintext as `Uint8Array`.
|
|
132
|
+
*
|
|
133
|
+
* # Errors
|
|
134
|
+
*
|
|
135
|
+
* Throws a JavaScript error with message "DECRYPTION_FAILED" for ANY failure.
|
|
136
|
+
*
|
|
137
|
+
* # Warning
|
|
138
|
+
*
|
|
139
|
+
* Reconstructed AAD requires bit-perfect reproduction of all context values.
|
|
140
|
+
* Unicode normalization differences between systems can cause decryption to fail.
|
|
141
|
+
* Use transmitted AAD for cross-platform deployments.
|
|
142
|
+
*
|
|
143
|
+
* # Example (JavaScript)
|
|
144
|
+
*
|
|
145
|
+
* ```javascript
|
|
146
|
+
* const key = keygen();
|
|
147
|
+
* const aad = '{"v":1,"tenant":"org","resource":"res","purpose":"enc"}';
|
|
148
|
+
*
|
|
149
|
+
* // Seal without AAD in envelope
|
|
150
|
+
* const envelope = seal(key, plaintext, aad, "my-key", false, true);
|
|
151
|
+
*
|
|
152
|
+
* // Reconstruct AAD at decryption time
|
|
153
|
+
* const decrypted = openReconstructed(key, envelope, aad);
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
export function openReconstructed(key: Uint8Array, envelope_bytes: Uint8Array, aad_json: string): Uint8Array;
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Decrypts an envelope using transmitted AAD.
|
|
160
|
+
*
|
|
161
|
+
* This is the common case where AAD is stored in the envelope.
|
|
162
|
+
*
|
|
163
|
+
* # Arguments
|
|
164
|
+
*
|
|
165
|
+
* * `key` - 256-bit decryption key (Uint8Array, 32 bytes)
|
|
166
|
+
* * `envelope_bytes` - CBOR-encoded envelope (Uint8Array)
|
|
167
|
+
*
|
|
168
|
+
* # Returns
|
|
169
|
+
*
|
|
170
|
+
* Decrypted plaintext as `Uint8Array`.
|
|
171
|
+
*
|
|
172
|
+
* # Errors
|
|
173
|
+
*
|
|
174
|
+
* Throws a JavaScript error with message "DECRYPTION_FAILED" for ANY failure:
|
|
175
|
+
* - Invalid envelope format
|
|
176
|
+
* - No transmitted AAD in envelope
|
|
177
|
+
* - Wrong key
|
|
178
|
+
* - Corrupted ciphertext
|
|
179
|
+
* - Mismatched AAD
|
|
180
|
+
*
|
|
181
|
+
* Per AAED spec Section 10, errors are intentionally generic to prevent
|
|
182
|
+
* information leakage.
|
|
183
|
+
*
|
|
184
|
+
* # Example (JavaScript)
|
|
185
|
+
*
|
|
186
|
+
* ```javascript
|
|
187
|
+
* const key = keygen();
|
|
188
|
+
* const envelope = seal(key, plaintext, aad, "my-key");
|
|
189
|
+
*
|
|
190
|
+
* const decrypted = openTransmitted(key, envelope);
|
|
191
|
+
* console.log(new TextDecoder().decode(decrypted));
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
export function openTransmitted(key: Uint8Array, envelope_bytes: Uint8Array): Uint8Array;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Encrypts plaintext into an envelope.
|
|
198
|
+
*
|
|
199
|
+
* # Arguments
|
|
200
|
+
*
|
|
201
|
+
* * `key` - 256-bit encryption key (Uint8Array, 32 bytes)
|
|
202
|
+
* * `plaintext` - Data to encrypt (Uint8Array)
|
|
203
|
+
* * `aad_json` - AAD as JSON string (will be canonicalized via canaad)
|
|
204
|
+
* * `key_id` - Key identifier string for the envelope header
|
|
205
|
+
* * `include_aad` - Whether to include AAD in envelope (default: true)
|
|
206
|
+
* * `emit_magic` - Whether to emit magic bytes prefix (default: true)
|
|
207
|
+
*
|
|
208
|
+
* # Returns
|
|
209
|
+
*
|
|
210
|
+
* Envelope as `Uint8Array` (CBOR-encoded, optionally with magic prefix).
|
|
211
|
+
*
|
|
212
|
+
* # Errors
|
|
213
|
+
*
|
|
214
|
+
* Throws a JavaScript error if:
|
|
215
|
+
* - Key size is invalid (must be 32 bytes)
|
|
216
|
+
* - AAD JSON canonicalization fails
|
|
217
|
+
* - Key ID exceeds 256 bytes
|
|
218
|
+
*
|
|
219
|
+
* # Example (JavaScript)
|
|
220
|
+
*
|
|
221
|
+
* ```javascript
|
|
222
|
+
* const key = keygen();
|
|
223
|
+
* const plaintext = new TextEncoder().encode("Hello, World!");
|
|
224
|
+
* const aad = '{"v":1,"tenant":"org","resource":"res","purpose":"enc"}';
|
|
225
|
+
*
|
|
226
|
+
* // Default options (include AAD, emit magic)
|
|
227
|
+
* const envelope = seal(key, plaintext, aad, "my-key");
|
|
228
|
+
*
|
|
229
|
+
* // Without AAD in envelope (reconstructed mode)
|
|
230
|
+
* const envelope2 = seal(key, plaintext, aad, "my-key", false, true);
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
export function seal(key: Uint8Array, plaintext: Uint8Array, aad_json: string, key_id: string, include_aad?: boolean | null, emit_magic?: boolean | null): Uint8Array;
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Validates envelope structure without decryption.
|
|
237
|
+
*
|
|
238
|
+
* Checks structural integrity, not cryptographic validity. This is useful
|
|
239
|
+
* for fail-fast validation before attempting expensive operations.
|
|
240
|
+
*
|
|
241
|
+
* # Checks Performed
|
|
242
|
+
*
|
|
243
|
+
* - Envelope version is supported
|
|
244
|
+
* - Algorithm is known
|
|
245
|
+
* - AES-256-GCM has wrapped mode requirement
|
|
246
|
+
* - Ciphertext is at least tag size
|
|
247
|
+
*
|
|
248
|
+
* # Arguments
|
|
249
|
+
*
|
|
250
|
+
* * `envelope_bytes` - CBOR-encoded envelope (Uint8Array)
|
|
251
|
+
*
|
|
252
|
+
* # Returns
|
|
253
|
+
*
|
|
254
|
+
* JavaScript object with validation result:
|
|
255
|
+
* - `valid`: Whether the envelope passed all checks (boolean)
|
|
256
|
+
* - `errors`: Array of error messages (string[])
|
|
257
|
+
*
|
|
258
|
+
* # Example (JavaScript)
|
|
259
|
+
*
|
|
260
|
+
* ```javascript
|
|
261
|
+
* const result = validate(envelope);
|
|
262
|
+
* if (result.valid) {
|
|
263
|
+
* console.log("Envelope is valid");
|
|
264
|
+
* } else {
|
|
265
|
+
* console.error("Validation errors:", result.errors);
|
|
266
|
+
* }
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
export function validate(envelope_bytes: Uint8Array): any;
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Returns the library version.
|
|
273
|
+
*/
|
|
274
|
+
export function version(): string;
|
|
275
|
+
|
|
276
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
277
|
+
|
|
278
|
+
export interface InitOutput {
|
|
279
|
+
readonly memory: WebAssembly.Memory;
|
|
280
|
+
readonly KEY_SIZE: () => number;
|
|
281
|
+
readonly NONCE_SIZE: () => number;
|
|
282
|
+
readonly SPEC_VERSION: () => number;
|
|
283
|
+
readonly TAG_SIZE: () => number;
|
|
284
|
+
readonly hasMagicPrefix: (a: number, b: number) => number;
|
|
285
|
+
readonly inspect: (a: number, b: number) => [number, number, number];
|
|
286
|
+
readonly keygen: () => [number, number];
|
|
287
|
+
readonly magicBytes: () => [number, number];
|
|
288
|
+
readonly openReconstructed: (a: number, b: number, c: number, d: number, e: number, f: number) => [number, number, number, number];
|
|
289
|
+
readonly openTransmitted: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
290
|
+
readonly seal: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => [number, number, number, number];
|
|
291
|
+
readonly validate: (a: number, b: number) => [number, number, number];
|
|
292
|
+
readonly version: () => [number, number];
|
|
293
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
294
|
+
readonly __externref_table_alloc: () => number;
|
|
295
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
296
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
297
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
298
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
299
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
300
|
+
readonly __wbindgen_start: () => void;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
307
|
+
* a precompiled `WebAssembly.Module`.
|
|
308
|
+
*
|
|
309
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
310
|
+
*
|
|
311
|
+
* @returns {InitOutput}
|
|
312
|
+
*/
|
|
313
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
317
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
318
|
+
*
|
|
319
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
320
|
+
*
|
|
321
|
+
* @returns {Promise<InitOutput>}
|
|
322
|
+
*/
|
|
323
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|