@gnufoo/canaad 0.3.0 → 0.4.0

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
@@ -1,104 +1,84 @@
1
- # canaad-wasm
1
+ # @gnufoo/canaad
2
2
 
3
- WASM bindings for AAD (Additional Authenticated Data) canonicalization per RFC 8785.
4
-
5
- This crate provides WebAssembly bindings for the `canaad-core` library, enabling
6
- AAD canonicalization in browsers, Node.js, and other WASM runtimes like
7
- Cloudflare Workers.
8
-
9
- ## Installation
3
+ AAD canonicalization in your browser or Worker. Same spec, same bytes.
10
4
 
11
5
  ```bash
12
6
  npm install @gnufoo/canaad
13
7
  ```
14
8
 
15
- ## Usage
16
-
17
- ### Canonicalize JSON
9
+ ## canonicalize
18
10
 
19
11
  ```typescript
20
12
  import { canonicalize, canonicalizeString, validate, hash } from '@gnufoo/canaad';
21
13
 
22
- // Canonicalize JSON to bytes
23
- const json = '{"v":1,"tenant":"org_abc","resource":"secrets/db","purpose":"encryption"}';
24
- const bytes: Uint8Array = canonicalize(json);
25
-
26
- // Canonicalize JSON to string
27
- const canonical: string = canonicalizeString(json);
28
- // => '{"purpose":"encryption","resource":"secrets/db","tenant":"org_abc","v":1}'
29
-
30
- // Validate JSON
31
- const isValid: boolean = validate(json);
32
-
33
- // Get SHA-256 hash of canonical form
34
- const hashBytes: Uint8Array = hash(json);
14
+ const bytes = canonicalize('{"v":1,"tenant":"org_abc","resource":"secrets/db","purpose":"encryption"}');
15
+ const str = canonicalizeString('{"v":1,"tenant":"org_abc","resource":"secrets/db","purpose":"encryption"}');
16
+ const ok = validate(json);
17
+ const sha = hash(json); // 32-byte SHA-256
35
18
  ```
36
19
 
37
- ### Builder API
20
+ ## build
38
21
 
39
22
  ```typescript
40
23
  import { AadBuilder } from '@gnufoo/canaad';
41
24
 
42
- const builder = new AadBuilder()
25
+ const aad = new AadBuilder()
43
26
  .tenant("org_abc")
44
27
  .resource("secrets/db")
45
28
  .purpose("encryption")
46
29
  .timestamp(1706400000)
47
30
  .extensionString("x_vault_cluster", "us-east-1")
48
- .extensionInt("x_app_priority", 5);
31
+ .extensionInt("x_app_priority", 5)
32
+ .build(); // Uint8Array
33
+ ```
49
34
 
50
- // Build to bytes
51
- const bytes: Uint8Array = builder.build();
35
+ Numbers only no BigInt. `build()` and `buildString()` validate all inputs:
52
36
 
53
- // Build to string
54
- const canonical: string = builder.buildString();
55
- ```
37
+ - NaN, Infinity, negative, fractional → rejected
38
+ - `-0.0` allowed (equals 0 in IEEE 754)
39
+ - integers > 2^53-1 → rejected (JS safe integer limit)
56
40
 
57
- ### Constants
41
+ ## exports
58
42
 
59
- ```typescript
60
- import { SPEC_VERSION, MAX_SAFE_INTEGER, MAX_SERIALIZED_BYTES } from '@gnufoo/canaad';
43
+ This package follows the gnufoo tool package format with four entry points:
61
44
 
62
- console.log(SPEC_VERSION); // 1
63
- console.log(MAX_SAFE_INTEGER); // 9007199254740991 (2^53 - 1)
64
- console.log(MAX_SERIALIZED_BYTES); // 16384 (16 KiB)
65
- ```
45
+ | Import | What you get |
46
+ |--------|-------------|
47
+ | `@gnufoo/canaad` | Direct WASM functions (after init) |
48
+ | `@gnufoo/canaad/init` | `initWasm()` + `isInitialized()` |
49
+ | `@gnufoo/canaad/meta` | Zod schemas + metadata (no WASM, SSG-safe) |
50
+ | `@gnufoo/canaad/tool` | `toolDefinition` with `execute()` |
66
51
 
67
- ## Error Handling
52
+ The `/meta` import is safe for static site generation — no WASM loaded.
68
53
 
69
- All functions that can fail will throw JavaScript errors with descriptive messages:
54
+ The `/tool` path validates inputs via Zod (`z.number().int().nonnegative()` for timestamps and extension integers). Direct WASM imports bypass Zod — the Rust layer validates as defense-in-depth.
70
55
 
71
- ```typescript
72
- try {
73
- canonicalize('{"v":1}'); // Missing required fields
74
- } catch (e) {
75
- console.error(e.message); // "missing required field: tenant"
76
- }
77
- ```
56
+ ## cloudflare workers
78
57
 
79
- ## Supported Environments
58
+ ```typescript
59
+ import wasmModule from '@gnufoo/canaad/canaad_wasm_bg.wasm';
60
+ import { toolDefinition } from '@gnufoo/canaad/tool';
80
61
 
81
- - **Browsers**: Modern browsers with WASM support
82
- - **Node.js**: v14+ with WASM support
83
- - **Cloudflare Workers**: Full support
84
- - **Deno**: With WASM import
62
+ await toolDefinition.initWasm(wasmModule);
85
63
 
86
- ## Building from Source
64
+ const result = await toolDefinition.execute({
65
+ action: 'build',
66
+ tenant: 'org_abc',
67
+ resource: 'secrets/db',
68
+ purpose: 'encryption',
69
+ });
70
+ ```
87
71
 
88
- ```bash
89
- # Install wasm-pack
90
- cargo install wasm-pack
72
+ ## browser (vite)
91
73
 
92
- # Build for bundlers (webpack, vite, etc.)
93
- wasm-pack build --target bundler
74
+ With `vite-plugin-wasm` and `vite-plugin-top-level-await`:
94
75
 
95
- # Build for Node.js
96
- wasm-pack build --target nodejs
76
+ ```typescript
77
+ import { toolDefinition } from '@gnufoo/canaad/tool';
97
78
 
98
- # Build for web (no bundler)
99
- wasm-pack build --target web
79
+ await toolDefinition.initWasm();
100
80
  ```
101
81
 
102
- ## License
82
+ ## license
103
83
 
104
84
  MIT OR Apache-2.0
package/canaad_wasm.d.ts CHANGED
@@ -2,92 +2,25 @@
2
2
  /* eslint-disable */
3
3
 
4
4
  /**
5
- * Builder for constructing AAD objects programmatically.
6
- *
7
- * Provides a fluent API for building AAD with method chaining.
8
- * All setter methods return a new builder to enable chaining.
9
- *
10
- * # Example (JavaScript)
11
- *
12
- * ```javascript
13
- * const builder = new AadBuilder()
14
- * .tenant("org_abc")
15
- * .resource("secrets/db")
16
- * .purpose("encryption")
17
- * .timestamp(1706400000)
18
- * .extensionString("x_vault_cluster", "us-east-1");
19
- *
20
- * const bytes = builder.build();
21
- * const canonical = builder.buildString();
22
- * ```
5
+ * Fluent builder for AAD objects. Chain setters, call `build()` or `buildString()`.
23
6
  */
24
7
  export class AadBuilder {
25
8
  free(): void;
26
9
  [Symbol.dispose](): void;
27
10
  /**
28
- * Builds the AAD and returns the canonical bytes.
29
- *
30
- * # Returns
31
- *
32
- * A `Uint8Array` containing the UTF-8 encoded canonical JSON.
33
- *
34
- * # Errors
35
- *
36
- * Throws a JavaScript error if:
37
- * - Required fields (tenant, resource, purpose) are missing
38
- * - Any field value is invalid
39
- * - Extension keys don't match the required pattern
40
- * - The serialized output exceeds 16 KiB
11
+ * Builds AAD and returns canonical bytes.
41
12
  */
42
13
  build(): Uint8Array;
43
14
  /**
44
- * Builds the AAD and returns the canonical string.
45
- *
46
- * # Returns
47
- *
48
- * The canonical (JCS) representation as a string.
49
- *
50
- * # Errors
51
- *
52
- * Throws a JavaScript error if:
53
- * - Required fields (tenant, resource, purpose) are missing
54
- * - Any field value is invalid
55
- * - Extension keys don't match the required pattern
56
- * - The serialized output exceeds 16 KiB
15
+ * Builds AAD and returns canonical UTF-8 string.
57
16
  */
58
17
  buildString(): string;
59
18
  /**
60
- * Adds an integer extension field.
61
- *
62
- * Extension keys must match pattern `x_<app>_<field>` where:
63
- * - `<app>` is one or more lowercase letters
64
- * - `<field>` is one or more lowercase letters or underscores
65
- *
66
- * # Arguments
67
- *
68
- * * `key` - Extension key (e.g., `x_app_priority`)
69
- * * `value` - Integer value (0 to 2^53-1)
70
- *
71
- * # Returns
72
- *
73
- * A new builder with the extension added.
19
+ * Adds an integer extension. Validated at `build()`.
74
20
  */
75
21
  extensionInt(key: string, value: number): AadBuilder;
76
22
  /**
77
- * Adds a string extension field.
78
- *
79
- * Extension keys must match pattern `x_<app>_<field>` where:
80
- * - `<app>` is one or more lowercase letters
81
- * - `<field>` is one or more lowercase letters or underscores
82
- *
83
- * # Arguments
84
- *
85
- * * `key` - Extension key (e.g., `x_vault_cluster`)
86
- * * `value` - String value (no NUL bytes)
87
- *
88
- * # Returns
89
- *
90
- * A new builder with the extension added.
23
+ * Adds a string extension. Key format: `x_<app>_<field>`.
91
24
  */
92
25
  extensionString(key: string, value: string): AadBuilder;
93
26
  /**
@@ -95,160 +28,55 @@ export class AadBuilder {
95
28
  */
96
29
  constructor();
97
30
  /**
98
- * Sets the purpose or usage context.
99
- *
100
- * # Arguments
101
- *
102
- * * `value` - Purpose description (1+ bytes, no NUL bytes)
103
- *
104
- * # Returns
105
- *
106
- * A new builder with the purpose set.
31
+ * Sets the purpose. 1+ bytes, no NUL.
107
32
  */
108
33
  purpose(value: string): AadBuilder;
109
34
  /**
110
- * Sets the resource path or identifier.
111
- *
112
- * # Arguments
113
- *
114
- * * `value` - Resource path (1-1024 bytes, no NUL bytes)
115
- *
116
- * # Returns
117
- *
118
- * A new builder with the resource set.
35
+ * Sets the resource. 1-1024 bytes, no NUL.
119
36
  */
120
37
  resource(value: string): AadBuilder;
121
38
  /**
122
- * Sets the tenant identifier.
123
- *
124
- * # Arguments
125
- *
126
- * * `value` - Tenant identifier (1-256 bytes, no NUL bytes)
127
- *
128
- * # Returns
129
- *
130
- * A new builder with the tenant set.
39
+ * Sets the tenant. 1-256 bytes, no NUL.
131
40
  */
132
41
  tenant(value: string): AadBuilder;
133
42
  /**
134
- * Sets the timestamp.
135
- *
136
- * # Arguments
137
- *
138
- * * `ts` - Unix timestamp (0 to 2^53-1)
139
- *
140
- * # Returns
141
- *
142
- * A new builder with the timestamp set.
43
+ * Sets the timestamp. Validated at `build()`.
143
44
  */
144
45
  timestamp(ts: number): AadBuilder;
145
46
  }
146
47
 
147
48
  /**
148
- * Returns the maximum safe integer value (2^53 - 1).
149
- *
150
- * This is the maximum integer value that can be exactly represented in
151
- * JavaScript's Number type.
49
+ * Maximum safe integer (2^53 - 1).
152
50
  */
153
51
  export function MAX_SAFE_INTEGER(): number;
154
52
 
155
53
  /**
156
- * Returns the maximum serialized AAD size in bytes (16 KiB).
54
+ * Maximum serialized AAD size in bytes (16 KiB).
157
55
  */
158
56
  export function MAX_SERIALIZED_BYTES(): number;
159
57
 
160
58
  /**
161
- * Returns the current AAD specification version.
162
- *
163
- * Currently always returns 1.
59
+ * Current AAD specification version (always 1).
164
60
  */
165
61
  export function SPEC_VERSION(): number;
166
62
 
167
63
  /**
168
- * Parses and canonicalizes a JSON string to bytes.
169
- *
170
- * This function:
171
- * 1. Parses the JSON with duplicate key detection
172
- * 2. Validates all fields according to the AAD specification
173
- * 3. Returns the canonical (JCS) representation as bytes
174
- *
175
- * # Arguments
176
- *
177
- * * `json` - A JSON string containing an AAD object
178
- *
179
- * # Returns
180
- *
181
- * A `Uint8Array` containing the UTF-8 encoded canonical JSON.
182
- *
183
- * # Errors
184
- *
185
- * Throws a JavaScript error if:
186
- * - The JSON is invalid or contains duplicate keys
187
- * - Any field violates AAD constraints
188
- * - The serialized output exceeds 16 KiB
64
+ * Parses and canonicalizes a JSON string to bytes (RFC 8785).
189
65
  */
190
66
  export function canonicalize(json: string): Uint8Array;
191
67
 
192
68
  /**
193
69
  * Parses and canonicalizes a JSON string to a UTF-8 string.
194
- *
195
- * This is equivalent to `canonicalize` but returns a string instead of bytes.
196
- *
197
- * # Arguments
198
- *
199
- * * `json` - A JSON string containing an AAD object
200
- *
201
- * # Returns
202
- *
203
- * The canonical (JCS) representation as a string.
204
- *
205
- * # Errors
206
- *
207
- * Throws a JavaScript error if:
208
- * - The JSON is invalid or contains duplicate keys
209
- * - Any field violates AAD constraints
210
- * - The serialized output exceeds 16 KiB
211
70
  */
212
71
  export function canonicalizeString(json: string): string;
213
72
 
214
73
  /**
215
- * Computes the SHA-256 hash of the canonical JSON form.
216
- *
217
- * This function:
218
- * 1. Parses and validates the JSON
219
- * 2. Canonicalizes according to RFC 8785
220
- * 3. Returns the SHA-256 hash of the canonical bytes
221
- *
222
- * # Arguments
223
- *
224
- * * `json` - A JSON string containing an AAD object
225
- *
226
- * # Returns
227
- *
228
- * A 32-byte `Uint8Array` containing the SHA-256 hash.
229
- *
230
- * # Errors
231
- *
232
- * Throws a JavaScript error if:
233
- * - The JSON is invalid or contains duplicate keys
234
- * - Any field violates AAD constraints
235
- * - The serialized output exceeds 16 KiB
74
+ * SHA-256 hash of the canonical JSON form.
236
75
  */
237
76
  export function hash(json: string): Uint8Array;
238
77
 
239
78
  /**
240
79
  * Validates a JSON string against the AAD specification.
241
- *
242
- * This function performs full validation without returning the context.
243
- * Use this for quick validation checks.
244
- *
245
- * # Arguments
246
- *
247
- * * `json` - A JSON string to validate
248
- *
249
- * # Returns
250
- *
251
- * `true` if the JSON is valid AAD, `false` otherwise.
252
80
  */
253
81
  export function validate(json: string): boolean;
254
82
 
package/canaad_wasm.js CHANGED
@@ -1,24 +1,7 @@
1
1
  /* @ts-self-types="./canaad_wasm.d.ts" */
2
2
 
3
3
  /**
4
- * Builder for constructing AAD objects programmatically.
5
- *
6
- * Provides a fluent API for building AAD with method chaining.
7
- * All setter methods return a new builder to enable chaining.
8
- *
9
- * # Example (JavaScript)
10
- *
11
- * ```javascript
12
- * const builder = new AadBuilder()
13
- * .tenant("org_abc")
14
- * .resource("secrets/db")
15
- * .purpose("encryption")
16
- * .timestamp(1706400000)
17
- * .extensionString("x_vault_cluster", "us-east-1");
18
- *
19
- * const bytes = builder.build();
20
- * const canonical = builder.buildString();
21
- * ```
4
+ * Fluent builder for AAD objects. Chain setters, call `build()` or `buildString()`.
22
5
  */
23
6
  export class AadBuilder {
24
7
  static __wrap(ptr) {
@@ -39,19 +22,7 @@ export class AadBuilder {
39
22
  wasm.__wbg_aadbuilder_free(ptr, 0);
40
23
  }
41
24
  /**
42
- * Builds the AAD and returns the canonical bytes.
43
- *
44
- * # Returns
45
- *
46
- * A `Uint8Array` containing the UTF-8 encoded canonical JSON.
47
- *
48
- * # Errors
49
- *
50
- * Throws a JavaScript error if:
51
- * - Required fields (tenant, resource, purpose) are missing
52
- * - Any field value is invalid
53
- * - Extension keys don't match the required pattern
54
- * - The serialized output exceeds 16 KiB
25
+ * Builds AAD and returns canonical bytes.
55
26
  * @returns {Uint8Array}
56
27
  */
57
28
  build() {
@@ -64,19 +35,7 @@ export class AadBuilder {
64
35
  return v1;
65
36
  }
66
37
  /**
67
- * Builds the AAD and returns the canonical string.
68
- *
69
- * # Returns
70
- *
71
- * The canonical (JCS) representation as a string.
72
- *
73
- * # Errors
74
- *
75
- * Throws a JavaScript error if:
76
- * - Required fields (tenant, resource, purpose) are missing
77
- * - Any field value is invalid
78
- * - Extension keys don't match the required pattern
79
- * - The serialized output exceeds 16 KiB
38
+ * Builds AAD and returns canonical UTF-8 string.
80
39
  * @returns {string}
81
40
  */
82
41
  buildString() {
@@ -98,20 +57,7 @@ export class AadBuilder {
98
57
  }
99
58
  }
100
59
  /**
101
- * Adds an integer extension field.
102
- *
103
- * Extension keys must match pattern `x_<app>_<field>` where:
104
- * - `<app>` is one or more lowercase letters
105
- * - `<field>` is one or more lowercase letters or underscores
106
- *
107
- * # Arguments
108
- *
109
- * * `key` - Extension key (e.g., `x_app_priority`)
110
- * * `value` - Integer value (0 to 2^53-1)
111
- *
112
- * # Returns
113
- *
114
- * A new builder with the extension added.
60
+ * Adds an integer extension. Validated at `build()`.
115
61
  * @param {string} key
116
62
  * @param {number} value
117
63
  * @returns {AadBuilder}
@@ -124,20 +70,7 @@ export class AadBuilder {
124
70
  return AadBuilder.__wrap(ret);
125
71
  }
126
72
  /**
127
- * Adds a string extension field.
128
- *
129
- * Extension keys must match pattern `x_<app>_<field>` where:
130
- * - `<app>` is one or more lowercase letters
131
- * - `<field>` is one or more lowercase letters or underscores
132
- *
133
- * # Arguments
134
- *
135
- * * `key` - Extension key (e.g., `x_vault_cluster`)
136
- * * `value` - String value (no NUL bytes)
137
- *
138
- * # Returns
139
- *
140
- * A new builder with the extension added.
73
+ * Adds a string extension. Key format: `x_<app>_<field>`.
141
74
  * @param {string} key
142
75
  * @param {string} value
143
76
  * @returns {AadBuilder}
@@ -161,15 +94,7 @@ export class AadBuilder {
161
94
  return this;
162
95
  }
163
96
  /**
164
- * Sets the purpose or usage context.
165
- *
166
- * # Arguments
167
- *
168
- * * `value` - Purpose description (1+ bytes, no NUL bytes)
169
- *
170
- * # Returns
171
- *
172
- * A new builder with the purpose set.
97
+ * Sets the purpose. 1+ bytes, no NUL.
173
98
  * @param {string} value
174
99
  * @returns {AadBuilder}
175
100
  */
@@ -181,15 +106,7 @@ export class AadBuilder {
181
106
  return AadBuilder.__wrap(ret);
182
107
  }
183
108
  /**
184
- * Sets the resource path or identifier.
185
- *
186
- * # Arguments
187
- *
188
- * * `value` - Resource path (1-1024 bytes, no NUL bytes)
189
- *
190
- * # Returns
191
- *
192
- * A new builder with the resource set.
109
+ * Sets the resource. 1-1024 bytes, no NUL.
193
110
  * @param {string} value
194
111
  * @returns {AadBuilder}
195
112
  */
@@ -201,15 +118,7 @@ export class AadBuilder {
201
118
  return AadBuilder.__wrap(ret);
202
119
  }
203
120
  /**
204
- * Sets the tenant identifier.
205
- *
206
- * # Arguments
207
- *
208
- * * `value` - Tenant identifier (1-256 bytes, no NUL bytes)
209
- *
210
- * # Returns
211
- *
212
- * A new builder with the tenant set.
121
+ * Sets the tenant. 1-256 bytes, no NUL.
213
122
  * @param {string} value
214
123
  * @returns {AadBuilder}
215
124
  */
@@ -221,15 +130,7 @@ export class AadBuilder {
221
130
  return AadBuilder.__wrap(ret);
222
131
  }
223
132
  /**
224
- * Sets the timestamp.
225
- *
226
- * # Arguments
227
- *
228
- * * `ts` - Unix timestamp (0 to 2^53-1)
229
- *
230
- * # Returns
231
- *
232
- * A new builder with the timestamp set.
133
+ * Sets the timestamp. Validated at `build()`.
233
134
  * @param {number} ts
234
135
  * @returns {AadBuilder}
235
136
  */
@@ -242,10 +143,7 @@ export class AadBuilder {
242
143
  if (Symbol.dispose) AadBuilder.prototype[Symbol.dispose] = AadBuilder.prototype.free;
243
144
 
244
145
  /**
245
- * Returns the maximum safe integer value (2^53 - 1).
246
- *
247
- * This is the maximum integer value that can be exactly represented in
248
- * JavaScript's Number type.
146
+ * Maximum safe integer (2^53 - 1).
249
147
  * @returns {number}
250
148
  */
251
149
  export function MAX_SAFE_INTEGER() {
@@ -254,7 +152,7 @@ export function MAX_SAFE_INTEGER() {
254
152
  }
255
153
 
256
154
  /**
257
- * Returns the maximum serialized AAD size in bytes (16 KiB).
155
+ * Maximum serialized AAD size in bytes (16 KiB).
258
156
  * @returns {number}
259
157
  */
260
158
  export function MAX_SERIALIZED_BYTES() {
@@ -263,9 +161,7 @@ export function MAX_SERIALIZED_BYTES() {
263
161
  }
264
162
 
265
163
  /**
266
- * Returns the current AAD specification version.
267
- *
268
- * Currently always returns 1.
164
+ * Current AAD specification version (always 1).
269
165
  * @returns {number}
270
166
  */
271
167
  export function SPEC_VERSION() {
@@ -274,27 +170,7 @@ export function SPEC_VERSION() {
274
170
  }
275
171
 
276
172
  /**
277
- * Parses and canonicalizes a JSON string to bytes.
278
- *
279
- * This function:
280
- * 1. Parses the JSON with duplicate key detection
281
- * 2. Validates all fields according to the AAD specification
282
- * 3. Returns the canonical (JCS) representation as bytes
283
- *
284
- * # Arguments
285
- *
286
- * * `json` - A JSON string containing an AAD object
287
- *
288
- * # Returns
289
- *
290
- * A `Uint8Array` containing the UTF-8 encoded canonical JSON.
291
- *
292
- * # Errors
293
- *
294
- * Throws a JavaScript error if:
295
- * - The JSON is invalid or contains duplicate keys
296
- * - Any field violates AAD constraints
297
- * - The serialized output exceeds 16 KiB
173
+ * Parses and canonicalizes a JSON string to bytes (RFC 8785).
298
174
  * @param {string} json
299
175
  * @returns {Uint8Array}
300
176
  */
@@ -312,23 +188,6 @@ export function canonicalize(json) {
312
188
 
313
189
  /**
314
190
  * Parses and canonicalizes a JSON string to a UTF-8 string.
315
- *
316
- * This is equivalent to `canonicalize` but returns a string instead of bytes.
317
- *
318
- * # Arguments
319
- *
320
- * * `json` - A JSON string containing an AAD object
321
- *
322
- * # Returns
323
- *
324
- * The canonical (JCS) representation as a string.
325
- *
326
- * # Errors
327
- *
328
- * Throws a JavaScript error if:
329
- * - The JSON is invalid or contains duplicate keys
330
- * - Any field violates AAD constraints
331
- * - The serialized output exceeds 16 KiB
332
191
  * @param {string} json
333
192
  * @returns {string}
334
193
  */
@@ -354,27 +213,7 @@ export function canonicalizeString(json) {
354
213
  }
355
214
 
356
215
  /**
357
- * Computes the SHA-256 hash of the canonical JSON form.
358
- *
359
- * This function:
360
- * 1. Parses and validates the JSON
361
- * 2. Canonicalizes according to RFC 8785
362
- * 3. Returns the SHA-256 hash of the canonical bytes
363
- *
364
- * # Arguments
365
- *
366
- * * `json` - A JSON string containing an AAD object
367
- *
368
- * # Returns
369
- *
370
- * A 32-byte `Uint8Array` containing the SHA-256 hash.
371
- *
372
- * # Errors
373
- *
374
- * Throws a JavaScript error if:
375
- * - The JSON is invalid or contains duplicate keys
376
- * - Any field violates AAD constraints
377
- * - The serialized output exceeds 16 KiB
216
+ * SHA-256 hash of the canonical JSON form.
378
217
  * @param {string} json
379
218
  * @returns {Uint8Array}
380
219
  */
@@ -392,17 +231,6 @@ export function hash(json) {
392
231
 
393
232
  /**
394
233
  * Validates a JSON string against the AAD specification.
395
- *
396
- * This function performs full validation without returning the context.
397
- * Use this for quick validation checks.
398
- *
399
- * # Arguments
400
- *
401
- * * `json` - A JSON string to validate
402
- *
403
- * # Returns
404
- *
405
- * `true` if the JSON is valid AAD, `false` otherwise.
406
234
  * @param {string} json
407
235
  * @returns {boolean}
408
236
  */
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gnufoo/canaad",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "main": "canaad_wasm.js",
6
6
  "types": "canaad_wasm.d.ts",