@gnufoo/canaad 0.1.0 → 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/canaad_wasm.js +6 -537
- package/canaad_wasm_bg.js +527 -0
- package/package.json +7 -1
package/canaad_wasm.js
CHANGED
|
@@ -1,540 +1,9 @@
|
|
|
1
1
|
/* @ts-self-types="./canaad_wasm.d.ts" */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
class AadBuilder {
|
|
24
|
-
static __wrap(ptr) {
|
|
25
|
-
ptr = ptr >>> 0;
|
|
26
|
-
const obj = Object.create(AadBuilder.prototype);
|
|
27
|
-
obj.__wbg_ptr = ptr;
|
|
28
|
-
AadBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
29
|
-
return obj;
|
|
30
|
-
}
|
|
31
|
-
__destroy_into_raw() {
|
|
32
|
-
const ptr = this.__wbg_ptr;
|
|
33
|
-
this.__wbg_ptr = 0;
|
|
34
|
-
AadBuilderFinalization.unregister(this);
|
|
35
|
-
return ptr;
|
|
36
|
-
}
|
|
37
|
-
free() {
|
|
38
|
-
const ptr = this.__destroy_into_raw();
|
|
39
|
-
wasm.__wbg_aadbuilder_free(ptr, 0);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
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
|
|
55
|
-
* @returns {Uint8Array}
|
|
56
|
-
*/
|
|
57
|
-
build() {
|
|
58
|
-
const ret = wasm.aadbuilder_build(this.__wbg_ptr);
|
|
59
|
-
if (ret[3]) {
|
|
60
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
61
|
-
}
|
|
62
|
-
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
63
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
64
|
-
return v1;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
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
|
|
80
|
-
* @returns {string}
|
|
81
|
-
*/
|
|
82
|
-
buildString() {
|
|
83
|
-
let deferred2_0;
|
|
84
|
-
let deferred2_1;
|
|
85
|
-
try {
|
|
86
|
-
const ret = wasm.aadbuilder_buildString(this.__wbg_ptr);
|
|
87
|
-
var ptr1 = ret[0];
|
|
88
|
-
var len1 = ret[1];
|
|
89
|
-
if (ret[3]) {
|
|
90
|
-
ptr1 = 0; len1 = 0;
|
|
91
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
92
|
-
}
|
|
93
|
-
deferred2_0 = ptr1;
|
|
94
|
-
deferred2_1 = len1;
|
|
95
|
-
return getStringFromWasm0(ptr1, len1);
|
|
96
|
-
} finally {
|
|
97
|
-
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
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.
|
|
115
|
-
* @param {string} key
|
|
116
|
-
* @param {number} value
|
|
117
|
-
* @returns {AadBuilder}
|
|
118
|
-
*/
|
|
119
|
-
extensionInt(key, value) {
|
|
120
|
-
const ptr = this.__destroy_into_raw();
|
|
121
|
-
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
122
|
-
const len0 = WASM_VECTOR_LEN;
|
|
123
|
-
const ret = wasm.aadbuilder_extensionInt(ptr, ptr0, len0, value);
|
|
124
|
-
return AadBuilder.__wrap(ret);
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
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.
|
|
141
|
-
* @param {string} key
|
|
142
|
-
* @param {string} value
|
|
143
|
-
* @returns {AadBuilder}
|
|
144
|
-
*/
|
|
145
|
-
extensionString(key, value) {
|
|
146
|
-
const ptr = this.__destroy_into_raw();
|
|
147
|
-
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
148
|
-
const len0 = WASM_VECTOR_LEN;
|
|
149
|
-
const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
150
|
-
const len1 = WASM_VECTOR_LEN;
|
|
151
|
-
const ret = wasm.aadbuilder_extensionString(ptr, ptr0, len0, ptr1, len1);
|
|
152
|
-
return AadBuilder.__wrap(ret);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Creates a new AAD builder.
|
|
156
|
-
*/
|
|
157
|
-
constructor() {
|
|
158
|
-
const ret = wasm.aadbuilder_new();
|
|
159
|
-
this.__wbg_ptr = ret >>> 0;
|
|
160
|
-
AadBuilderFinalization.register(this, this.__wbg_ptr, this);
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
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.
|
|
173
|
-
* @param {string} value
|
|
174
|
-
* @returns {AadBuilder}
|
|
175
|
-
*/
|
|
176
|
-
purpose(value) {
|
|
177
|
-
const ptr = this.__destroy_into_raw();
|
|
178
|
-
const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
179
|
-
const len0 = WASM_VECTOR_LEN;
|
|
180
|
-
const ret = wasm.aadbuilder_purpose(ptr, ptr0, len0);
|
|
181
|
-
return AadBuilder.__wrap(ret);
|
|
182
|
-
}
|
|
183
|
-
/**
|
|
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.
|
|
193
|
-
* @param {string} value
|
|
194
|
-
* @returns {AadBuilder}
|
|
195
|
-
*/
|
|
196
|
-
resource(value) {
|
|
197
|
-
const ptr = this.__destroy_into_raw();
|
|
198
|
-
const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
199
|
-
const len0 = WASM_VECTOR_LEN;
|
|
200
|
-
const ret = wasm.aadbuilder_resource(ptr, ptr0, len0);
|
|
201
|
-
return AadBuilder.__wrap(ret);
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
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.
|
|
213
|
-
* @param {string} value
|
|
214
|
-
* @returns {AadBuilder}
|
|
215
|
-
*/
|
|
216
|
-
tenant(value) {
|
|
217
|
-
const ptr = this.__destroy_into_raw();
|
|
218
|
-
const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
219
|
-
const len0 = WASM_VECTOR_LEN;
|
|
220
|
-
const ret = wasm.aadbuilder_tenant(ptr, ptr0, len0);
|
|
221
|
-
return AadBuilder.__wrap(ret);
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
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.
|
|
233
|
-
* @param {number} ts
|
|
234
|
-
* @returns {AadBuilder}
|
|
235
|
-
*/
|
|
236
|
-
timestamp(ts) {
|
|
237
|
-
const ptr = this.__destroy_into_raw();
|
|
238
|
-
const ret = wasm.aadbuilder_timestamp(ptr, ts);
|
|
239
|
-
return AadBuilder.__wrap(ret);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (Symbol.dispose) AadBuilder.prototype[Symbol.dispose] = AadBuilder.prototype.free;
|
|
243
|
-
exports.AadBuilder = AadBuilder;
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Returns the maximum safe integer value (2^53 - 1).
|
|
247
|
-
*
|
|
248
|
-
* This is the maximum integer value that can be exactly represented in
|
|
249
|
-
* JavaScript's Number type.
|
|
250
|
-
* @returns {number}
|
|
251
|
-
*/
|
|
252
|
-
function MAX_SAFE_INTEGER() {
|
|
253
|
-
const ret = wasm.MAX_SAFE_INTEGER();
|
|
254
|
-
return ret;
|
|
255
|
-
}
|
|
256
|
-
exports.MAX_SAFE_INTEGER = MAX_SAFE_INTEGER;
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Returns the maximum serialized AAD size in bytes (16 KiB).
|
|
260
|
-
* @returns {number}
|
|
261
|
-
*/
|
|
262
|
-
function MAX_SERIALIZED_BYTES() {
|
|
263
|
-
const ret = wasm.MAX_SERIALIZED_BYTES();
|
|
264
|
-
return ret >>> 0;
|
|
265
|
-
}
|
|
266
|
-
exports.MAX_SERIALIZED_BYTES = MAX_SERIALIZED_BYTES;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* Returns the current AAD specification version.
|
|
270
|
-
*
|
|
271
|
-
* Currently always returns 1.
|
|
272
|
-
* @returns {number}
|
|
273
|
-
*/
|
|
274
|
-
function SPEC_VERSION() {
|
|
275
|
-
const ret = wasm.SPEC_VERSION();
|
|
276
|
-
return ret >>> 0;
|
|
277
|
-
}
|
|
278
|
-
exports.SPEC_VERSION = SPEC_VERSION;
|
|
279
|
-
|
|
280
|
-
/**
|
|
281
|
-
* Parses and canonicalizes a JSON string to bytes.
|
|
282
|
-
*
|
|
283
|
-
* This function:
|
|
284
|
-
* 1. Parses the JSON with duplicate key detection
|
|
285
|
-
* 2. Validates all fields according to the AAD specification
|
|
286
|
-
* 3. Returns the canonical (JCS) representation as bytes
|
|
287
|
-
*
|
|
288
|
-
* # Arguments
|
|
289
|
-
*
|
|
290
|
-
* * `json` - A JSON string containing an AAD object
|
|
291
|
-
*
|
|
292
|
-
* # Returns
|
|
293
|
-
*
|
|
294
|
-
* A `Uint8Array` containing the UTF-8 encoded canonical JSON.
|
|
295
|
-
*
|
|
296
|
-
* # Errors
|
|
297
|
-
*
|
|
298
|
-
* Throws a JavaScript error if:
|
|
299
|
-
* - The JSON is invalid or contains duplicate keys
|
|
300
|
-
* - Any field violates AAD constraints
|
|
301
|
-
* - The serialized output exceeds 16 KiB
|
|
302
|
-
* @param {string} json
|
|
303
|
-
* @returns {Uint8Array}
|
|
304
|
-
*/
|
|
305
|
-
function canonicalize(json) {
|
|
306
|
-
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
307
|
-
const len0 = WASM_VECTOR_LEN;
|
|
308
|
-
const ret = wasm.canonicalize(ptr0, len0);
|
|
309
|
-
if (ret[3]) {
|
|
310
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
311
|
-
}
|
|
312
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
313
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
314
|
-
return v2;
|
|
315
|
-
}
|
|
316
|
-
exports.canonicalize = canonicalize;
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Parses and canonicalizes a JSON string to a UTF-8 string.
|
|
320
|
-
*
|
|
321
|
-
* This is equivalent to `canonicalize` but returns a string instead of bytes.
|
|
322
|
-
*
|
|
323
|
-
* # Arguments
|
|
324
|
-
*
|
|
325
|
-
* * `json` - A JSON string containing an AAD object
|
|
326
|
-
*
|
|
327
|
-
* # Returns
|
|
328
|
-
*
|
|
329
|
-
* The canonical (JCS) representation as a string.
|
|
330
|
-
*
|
|
331
|
-
* # Errors
|
|
332
|
-
*
|
|
333
|
-
* Throws a JavaScript error if:
|
|
334
|
-
* - The JSON is invalid or contains duplicate keys
|
|
335
|
-
* - Any field violates AAD constraints
|
|
336
|
-
* - The serialized output exceeds 16 KiB
|
|
337
|
-
* @param {string} json
|
|
338
|
-
* @returns {string}
|
|
339
|
-
*/
|
|
340
|
-
function canonicalizeString(json) {
|
|
341
|
-
let deferred3_0;
|
|
342
|
-
let deferred3_1;
|
|
343
|
-
try {
|
|
344
|
-
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
345
|
-
const len0 = WASM_VECTOR_LEN;
|
|
346
|
-
const ret = wasm.canonicalizeString(ptr0, len0);
|
|
347
|
-
var ptr2 = ret[0];
|
|
348
|
-
var len2 = ret[1];
|
|
349
|
-
if (ret[3]) {
|
|
350
|
-
ptr2 = 0; len2 = 0;
|
|
351
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
352
|
-
}
|
|
353
|
-
deferred3_0 = ptr2;
|
|
354
|
-
deferred3_1 = len2;
|
|
355
|
-
return getStringFromWasm0(ptr2, len2);
|
|
356
|
-
} finally {
|
|
357
|
-
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
exports.canonicalizeString = canonicalizeString;
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
* Computes the SHA-256 hash of the canonical JSON form.
|
|
364
|
-
*
|
|
365
|
-
* This function:
|
|
366
|
-
* 1. Parses and validates the JSON
|
|
367
|
-
* 2. Canonicalizes according to RFC 8785
|
|
368
|
-
* 3. Returns the SHA-256 hash of the canonical bytes
|
|
369
|
-
*
|
|
370
|
-
* # Arguments
|
|
371
|
-
*
|
|
372
|
-
* * `json` - A JSON string containing an AAD object
|
|
373
|
-
*
|
|
374
|
-
* # Returns
|
|
375
|
-
*
|
|
376
|
-
* A 32-byte `Uint8Array` containing the SHA-256 hash.
|
|
377
|
-
*
|
|
378
|
-
* # Errors
|
|
379
|
-
*
|
|
380
|
-
* Throws a JavaScript error if:
|
|
381
|
-
* - The JSON is invalid or contains duplicate keys
|
|
382
|
-
* - Any field violates AAD constraints
|
|
383
|
-
* - The serialized output exceeds 16 KiB
|
|
384
|
-
* @param {string} json
|
|
385
|
-
* @returns {Uint8Array}
|
|
386
|
-
*/
|
|
387
|
-
function hash(json) {
|
|
388
|
-
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
389
|
-
const len0 = WASM_VECTOR_LEN;
|
|
390
|
-
const ret = wasm.hash(ptr0, len0);
|
|
391
|
-
if (ret[3]) {
|
|
392
|
-
throw takeFromExternrefTable0(ret[2]);
|
|
393
|
-
}
|
|
394
|
-
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
395
|
-
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
396
|
-
return v2;
|
|
397
|
-
}
|
|
398
|
-
exports.hash = hash;
|
|
399
|
-
|
|
400
|
-
/**
|
|
401
|
-
* Validates a JSON string against the AAD specification.
|
|
402
|
-
*
|
|
403
|
-
* This function performs full validation without returning the context.
|
|
404
|
-
* Use this for quick validation checks.
|
|
405
|
-
*
|
|
406
|
-
* # Arguments
|
|
407
|
-
*
|
|
408
|
-
* * `json` - A JSON string to validate
|
|
409
|
-
*
|
|
410
|
-
* # Returns
|
|
411
|
-
*
|
|
412
|
-
* `true` if the JSON is valid AAD, `false` otherwise.
|
|
413
|
-
* @param {string} json
|
|
414
|
-
* @returns {boolean}
|
|
415
|
-
*/
|
|
416
|
-
function validate(json) {
|
|
417
|
-
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
418
|
-
const len0 = WASM_VECTOR_LEN;
|
|
419
|
-
const ret = wasm.validate(ptr0, len0);
|
|
420
|
-
return ret !== 0;
|
|
421
|
-
}
|
|
422
|
-
exports.validate = validate;
|
|
423
|
-
|
|
424
|
-
function __wbg_get_imports() {
|
|
425
|
-
const import0 = {
|
|
426
|
-
__proto__: null,
|
|
427
|
-
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
428
|
-
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
429
|
-
return ret;
|
|
430
|
-
},
|
|
431
|
-
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
432
|
-
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
433
|
-
},
|
|
434
|
-
__wbindgen_init_externref_table: function() {
|
|
435
|
-
const table = wasm.__wbindgen_externrefs;
|
|
436
|
-
const offset = table.grow(4);
|
|
437
|
-
table.set(0, undefined);
|
|
438
|
-
table.set(offset + 0, undefined);
|
|
439
|
-
table.set(offset + 1, null);
|
|
440
|
-
table.set(offset + 2, true);
|
|
441
|
-
table.set(offset + 3, false);
|
|
442
|
-
},
|
|
443
|
-
};
|
|
444
|
-
return {
|
|
445
|
-
__proto__: null,
|
|
446
|
-
"./canaad_wasm_bg.js": import0,
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
const AadBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
451
|
-
? { register: () => {}, unregister: () => {} }
|
|
452
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_aadbuilder_free(ptr >>> 0, 1));
|
|
453
|
-
|
|
454
|
-
function getArrayU8FromWasm0(ptr, len) {
|
|
455
|
-
ptr = ptr >>> 0;
|
|
456
|
-
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
function getStringFromWasm0(ptr, len) {
|
|
460
|
-
ptr = ptr >>> 0;
|
|
461
|
-
return decodeText(ptr, len);
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
let cachedUint8ArrayMemory0 = null;
|
|
465
|
-
function getUint8ArrayMemory0() {
|
|
466
|
-
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
467
|
-
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
468
|
-
}
|
|
469
|
-
return cachedUint8ArrayMemory0;
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
function passStringToWasm0(arg, malloc, realloc) {
|
|
473
|
-
if (realloc === undefined) {
|
|
474
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
475
|
-
const ptr = malloc(buf.length, 1) >>> 0;
|
|
476
|
-
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
477
|
-
WASM_VECTOR_LEN = buf.length;
|
|
478
|
-
return ptr;
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
let len = arg.length;
|
|
482
|
-
let ptr = malloc(len, 1) >>> 0;
|
|
483
|
-
|
|
484
|
-
const mem = getUint8ArrayMemory0();
|
|
485
|
-
|
|
486
|
-
let offset = 0;
|
|
487
|
-
|
|
488
|
-
for (; offset < len; offset++) {
|
|
489
|
-
const code = arg.charCodeAt(offset);
|
|
490
|
-
if (code > 0x7F) break;
|
|
491
|
-
mem[ptr + offset] = code;
|
|
492
|
-
}
|
|
493
|
-
if (offset !== len) {
|
|
494
|
-
if (offset !== 0) {
|
|
495
|
-
arg = arg.slice(offset);
|
|
496
|
-
}
|
|
497
|
-
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
498
|
-
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
499
|
-
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
500
|
-
|
|
501
|
-
offset += ret.written;
|
|
502
|
-
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
WASM_VECTOR_LEN = offset;
|
|
506
|
-
return ptr;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
function takeFromExternrefTable0(idx) {
|
|
510
|
-
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
511
|
-
wasm.__externref_table_dealloc(idx);
|
|
512
|
-
return value;
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
516
|
-
cachedTextDecoder.decode();
|
|
517
|
-
function decodeText(ptr, len) {
|
|
518
|
-
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const cachedTextEncoder = new TextEncoder();
|
|
522
|
-
|
|
523
|
-
if (!('encodeInto' in cachedTextEncoder)) {
|
|
524
|
-
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
525
|
-
const buf = cachedTextEncoder.encode(arg);
|
|
526
|
-
view.set(buf);
|
|
527
|
-
return {
|
|
528
|
-
read: arg.length,
|
|
529
|
-
written: buf.length
|
|
530
|
-
};
|
|
531
|
-
};
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
let WASM_VECTOR_LEN = 0;
|
|
535
|
-
|
|
536
|
-
const wasmPath = `${__dirname}/canaad_wasm_bg.wasm`;
|
|
537
|
-
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
538
|
-
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
539
|
-
const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
3
|
+
import * as wasm from "./canaad_wasm_bg.wasm";
|
|
4
|
+
import { __wbg_set_wasm } from "./canaad_wasm_bg.js";
|
|
5
|
+
__wbg_set_wasm(wasm);
|
|
540
6
|
wasm.__wbindgen_start();
|
|
7
|
+
export {
|
|
8
|
+
AadBuilder, MAX_SAFE_INTEGER, MAX_SERIALIZED_BYTES, SPEC_VERSION, canonicalize, canonicalizeString, hash, validate
|
|
9
|
+
} from "./canaad_wasm_bg.js";
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Builder for constructing AAD objects programmatically.
|
|
3
|
+
*
|
|
4
|
+
* Provides a fluent API for building AAD with method chaining.
|
|
5
|
+
* All setter methods return a new builder to enable chaining.
|
|
6
|
+
*
|
|
7
|
+
* # Example (JavaScript)
|
|
8
|
+
*
|
|
9
|
+
* ```javascript
|
|
10
|
+
* const builder = new AadBuilder()
|
|
11
|
+
* .tenant("org_abc")
|
|
12
|
+
* .resource("secrets/db")
|
|
13
|
+
* .purpose("encryption")
|
|
14
|
+
* .timestamp(1706400000)
|
|
15
|
+
* .extensionString("x_vault_cluster", "us-east-1");
|
|
16
|
+
*
|
|
17
|
+
* const bytes = builder.build();
|
|
18
|
+
* const canonical = builder.buildString();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class AadBuilder {
|
|
22
|
+
static __wrap(ptr) {
|
|
23
|
+
ptr = ptr >>> 0;
|
|
24
|
+
const obj = Object.create(AadBuilder.prototype);
|
|
25
|
+
obj.__wbg_ptr = ptr;
|
|
26
|
+
AadBuilderFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
29
|
+
__destroy_into_raw() {
|
|
30
|
+
const ptr = this.__wbg_ptr;
|
|
31
|
+
this.__wbg_ptr = 0;
|
|
32
|
+
AadBuilderFinalization.unregister(this);
|
|
33
|
+
return ptr;
|
|
34
|
+
}
|
|
35
|
+
free() {
|
|
36
|
+
const ptr = this.__destroy_into_raw();
|
|
37
|
+
wasm.__wbg_aadbuilder_free(ptr, 0);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Builds the AAD and returns the canonical bytes.
|
|
41
|
+
*
|
|
42
|
+
* # Returns
|
|
43
|
+
*
|
|
44
|
+
* A `Uint8Array` containing the UTF-8 encoded canonical JSON.
|
|
45
|
+
*
|
|
46
|
+
* # Errors
|
|
47
|
+
*
|
|
48
|
+
* Throws a JavaScript error if:
|
|
49
|
+
* - Required fields (tenant, resource, purpose) are missing
|
|
50
|
+
* - Any field value is invalid
|
|
51
|
+
* - Extension keys don't match the required pattern
|
|
52
|
+
* - The serialized output exceeds 16 KiB
|
|
53
|
+
* @returns {Uint8Array}
|
|
54
|
+
*/
|
|
55
|
+
build() {
|
|
56
|
+
const ret = wasm.aadbuilder_build(this.__wbg_ptr);
|
|
57
|
+
if (ret[3]) {
|
|
58
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
59
|
+
}
|
|
60
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
61
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
62
|
+
return v1;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Builds the AAD and returns the canonical string.
|
|
66
|
+
*
|
|
67
|
+
* # Returns
|
|
68
|
+
*
|
|
69
|
+
* The canonical (JCS) representation as a string.
|
|
70
|
+
*
|
|
71
|
+
* # Errors
|
|
72
|
+
*
|
|
73
|
+
* Throws a JavaScript error if:
|
|
74
|
+
* - Required fields (tenant, resource, purpose) are missing
|
|
75
|
+
* - Any field value is invalid
|
|
76
|
+
* - Extension keys don't match the required pattern
|
|
77
|
+
* - The serialized output exceeds 16 KiB
|
|
78
|
+
* @returns {string}
|
|
79
|
+
*/
|
|
80
|
+
buildString() {
|
|
81
|
+
let deferred2_0;
|
|
82
|
+
let deferred2_1;
|
|
83
|
+
try {
|
|
84
|
+
const ret = wasm.aadbuilder_buildString(this.__wbg_ptr);
|
|
85
|
+
var ptr1 = ret[0];
|
|
86
|
+
var len1 = ret[1];
|
|
87
|
+
if (ret[3]) {
|
|
88
|
+
ptr1 = 0; len1 = 0;
|
|
89
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
90
|
+
}
|
|
91
|
+
deferred2_0 = ptr1;
|
|
92
|
+
deferred2_1 = len1;
|
|
93
|
+
return getStringFromWasm0(ptr1, len1);
|
|
94
|
+
} finally {
|
|
95
|
+
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Adds an integer extension field.
|
|
100
|
+
*
|
|
101
|
+
* Extension keys must match pattern `x_<app>_<field>` where:
|
|
102
|
+
* - `<app>` is one or more lowercase letters
|
|
103
|
+
* - `<field>` is one or more lowercase letters or underscores
|
|
104
|
+
*
|
|
105
|
+
* # Arguments
|
|
106
|
+
*
|
|
107
|
+
* * `key` - Extension key (e.g., `x_app_priority`)
|
|
108
|
+
* * `value` - Integer value (0 to 2^53-1)
|
|
109
|
+
*
|
|
110
|
+
* # Returns
|
|
111
|
+
*
|
|
112
|
+
* A new builder with the extension added.
|
|
113
|
+
* @param {string} key
|
|
114
|
+
* @param {number} value
|
|
115
|
+
* @returns {AadBuilder}
|
|
116
|
+
*/
|
|
117
|
+
extensionInt(key, value) {
|
|
118
|
+
const ptr = this.__destroy_into_raw();
|
|
119
|
+
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
120
|
+
const len0 = WASM_VECTOR_LEN;
|
|
121
|
+
const ret = wasm.aadbuilder_extensionInt(ptr, ptr0, len0, value);
|
|
122
|
+
return AadBuilder.__wrap(ret);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Adds a string extension field.
|
|
126
|
+
*
|
|
127
|
+
* Extension keys must match pattern `x_<app>_<field>` where:
|
|
128
|
+
* - `<app>` is one or more lowercase letters
|
|
129
|
+
* - `<field>` is one or more lowercase letters or underscores
|
|
130
|
+
*
|
|
131
|
+
* # Arguments
|
|
132
|
+
*
|
|
133
|
+
* * `key` - Extension key (e.g., `x_vault_cluster`)
|
|
134
|
+
* * `value` - String value (no NUL bytes)
|
|
135
|
+
*
|
|
136
|
+
* # Returns
|
|
137
|
+
*
|
|
138
|
+
* A new builder with the extension added.
|
|
139
|
+
* @param {string} key
|
|
140
|
+
* @param {string} value
|
|
141
|
+
* @returns {AadBuilder}
|
|
142
|
+
*/
|
|
143
|
+
extensionString(key, value) {
|
|
144
|
+
const ptr = this.__destroy_into_raw();
|
|
145
|
+
const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
146
|
+
const len0 = WASM_VECTOR_LEN;
|
|
147
|
+
const ptr1 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
148
|
+
const len1 = WASM_VECTOR_LEN;
|
|
149
|
+
const ret = wasm.aadbuilder_extensionString(ptr, ptr0, len0, ptr1, len1);
|
|
150
|
+
return AadBuilder.__wrap(ret);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Creates a new AAD builder.
|
|
154
|
+
*/
|
|
155
|
+
constructor() {
|
|
156
|
+
const ret = wasm.aadbuilder_new();
|
|
157
|
+
this.__wbg_ptr = ret >>> 0;
|
|
158
|
+
AadBuilderFinalization.register(this, this.__wbg_ptr, this);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Sets the purpose or usage context.
|
|
163
|
+
*
|
|
164
|
+
* # Arguments
|
|
165
|
+
*
|
|
166
|
+
* * `value` - Purpose description (1+ bytes, no NUL bytes)
|
|
167
|
+
*
|
|
168
|
+
* # Returns
|
|
169
|
+
*
|
|
170
|
+
* A new builder with the purpose set.
|
|
171
|
+
* @param {string} value
|
|
172
|
+
* @returns {AadBuilder}
|
|
173
|
+
*/
|
|
174
|
+
purpose(value) {
|
|
175
|
+
const ptr = this.__destroy_into_raw();
|
|
176
|
+
const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
177
|
+
const len0 = WASM_VECTOR_LEN;
|
|
178
|
+
const ret = wasm.aadbuilder_purpose(ptr, ptr0, len0);
|
|
179
|
+
return AadBuilder.__wrap(ret);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Sets the resource path or identifier.
|
|
183
|
+
*
|
|
184
|
+
* # Arguments
|
|
185
|
+
*
|
|
186
|
+
* * `value` - Resource path (1-1024 bytes, no NUL bytes)
|
|
187
|
+
*
|
|
188
|
+
* # Returns
|
|
189
|
+
*
|
|
190
|
+
* A new builder with the resource set.
|
|
191
|
+
* @param {string} value
|
|
192
|
+
* @returns {AadBuilder}
|
|
193
|
+
*/
|
|
194
|
+
resource(value) {
|
|
195
|
+
const ptr = this.__destroy_into_raw();
|
|
196
|
+
const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
197
|
+
const len0 = WASM_VECTOR_LEN;
|
|
198
|
+
const ret = wasm.aadbuilder_resource(ptr, ptr0, len0);
|
|
199
|
+
return AadBuilder.__wrap(ret);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Sets the tenant identifier.
|
|
203
|
+
*
|
|
204
|
+
* # Arguments
|
|
205
|
+
*
|
|
206
|
+
* * `value` - Tenant identifier (1-256 bytes, no NUL bytes)
|
|
207
|
+
*
|
|
208
|
+
* # Returns
|
|
209
|
+
*
|
|
210
|
+
* A new builder with the tenant set.
|
|
211
|
+
* @param {string} value
|
|
212
|
+
* @returns {AadBuilder}
|
|
213
|
+
*/
|
|
214
|
+
tenant(value) {
|
|
215
|
+
const ptr = this.__destroy_into_raw();
|
|
216
|
+
const ptr0 = passStringToWasm0(value, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
217
|
+
const len0 = WASM_VECTOR_LEN;
|
|
218
|
+
const ret = wasm.aadbuilder_tenant(ptr, ptr0, len0);
|
|
219
|
+
return AadBuilder.__wrap(ret);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Sets the timestamp.
|
|
223
|
+
*
|
|
224
|
+
* # Arguments
|
|
225
|
+
*
|
|
226
|
+
* * `ts` - Unix timestamp (0 to 2^53-1)
|
|
227
|
+
*
|
|
228
|
+
* # Returns
|
|
229
|
+
*
|
|
230
|
+
* A new builder with the timestamp set.
|
|
231
|
+
* @param {number} ts
|
|
232
|
+
* @returns {AadBuilder}
|
|
233
|
+
*/
|
|
234
|
+
timestamp(ts) {
|
|
235
|
+
const ptr = this.__destroy_into_raw();
|
|
236
|
+
const ret = wasm.aadbuilder_timestamp(ptr, ts);
|
|
237
|
+
return AadBuilder.__wrap(ret);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (Symbol.dispose) AadBuilder.prototype[Symbol.dispose] = AadBuilder.prototype.free;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Returns the maximum safe integer value (2^53 - 1).
|
|
244
|
+
*
|
|
245
|
+
* This is the maximum integer value that can be exactly represented in
|
|
246
|
+
* JavaScript's Number type.
|
|
247
|
+
* @returns {number}
|
|
248
|
+
*/
|
|
249
|
+
export function MAX_SAFE_INTEGER() {
|
|
250
|
+
const ret = wasm.MAX_SAFE_INTEGER();
|
|
251
|
+
return ret;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Returns the maximum serialized AAD size in bytes (16 KiB).
|
|
256
|
+
* @returns {number}
|
|
257
|
+
*/
|
|
258
|
+
export function MAX_SERIALIZED_BYTES() {
|
|
259
|
+
const ret = wasm.MAX_SERIALIZED_BYTES();
|
|
260
|
+
return ret >>> 0;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Returns the current AAD specification version.
|
|
265
|
+
*
|
|
266
|
+
* Currently always returns 1.
|
|
267
|
+
* @returns {number}
|
|
268
|
+
*/
|
|
269
|
+
export function SPEC_VERSION() {
|
|
270
|
+
const ret = wasm.SPEC_VERSION();
|
|
271
|
+
return ret >>> 0;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Parses and canonicalizes a JSON string to bytes.
|
|
276
|
+
*
|
|
277
|
+
* This function:
|
|
278
|
+
* 1. Parses the JSON with duplicate key detection
|
|
279
|
+
* 2. Validates all fields according to the AAD specification
|
|
280
|
+
* 3. Returns the canonical (JCS) representation as bytes
|
|
281
|
+
*
|
|
282
|
+
* # Arguments
|
|
283
|
+
*
|
|
284
|
+
* * `json` - A JSON string containing an AAD object
|
|
285
|
+
*
|
|
286
|
+
* # Returns
|
|
287
|
+
*
|
|
288
|
+
* A `Uint8Array` containing the UTF-8 encoded canonical JSON.
|
|
289
|
+
*
|
|
290
|
+
* # Errors
|
|
291
|
+
*
|
|
292
|
+
* Throws a JavaScript error if:
|
|
293
|
+
* - The JSON is invalid or contains duplicate keys
|
|
294
|
+
* - Any field violates AAD constraints
|
|
295
|
+
* - The serialized output exceeds 16 KiB
|
|
296
|
+
* @param {string} json
|
|
297
|
+
* @returns {Uint8Array}
|
|
298
|
+
*/
|
|
299
|
+
export function canonicalize(json) {
|
|
300
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
301
|
+
const len0 = WASM_VECTOR_LEN;
|
|
302
|
+
const ret = wasm.canonicalize(ptr0, len0);
|
|
303
|
+
if (ret[3]) {
|
|
304
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
305
|
+
}
|
|
306
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
307
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
308
|
+
return v2;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Parses and canonicalizes a JSON string to a UTF-8 string.
|
|
313
|
+
*
|
|
314
|
+
* This is equivalent to `canonicalize` but returns a string instead of bytes.
|
|
315
|
+
*
|
|
316
|
+
* # Arguments
|
|
317
|
+
*
|
|
318
|
+
* * `json` - A JSON string containing an AAD object
|
|
319
|
+
*
|
|
320
|
+
* # Returns
|
|
321
|
+
*
|
|
322
|
+
* The canonical (JCS) representation as a string.
|
|
323
|
+
*
|
|
324
|
+
* # Errors
|
|
325
|
+
*
|
|
326
|
+
* Throws a JavaScript error if:
|
|
327
|
+
* - The JSON is invalid or contains duplicate keys
|
|
328
|
+
* - Any field violates AAD constraints
|
|
329
|
+
* - The serialized output exceeds 16 KiB
|
|
330
|
+
* @param {string} json
|
|
331
|
+
* @returns {string}
|
|
332
|
+
*/
|
|
333
|
+
export function canonicalizeString(json) {
|
|
334
|
+
let deferred3_0;
|
|
335
|
+
let deferred3_1;
|
|
336
|
+
try {
|
|
337
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
338
|
+
const len0 = WASM_VECTOR_LEN;
|
|
339
|
+
const ret = wasm.canonicalizeString(ptr0, len0);
|
|
340
|
+
var ptr2 = ret[0];
|
|
341
|
+
var len2 = ret[1];
|
|
342
|
+
if (ret[3]) {
|
|
343
|
+
ptr2 = 0; len2 = 0;
|
|
344
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
345
|
+
}
|
|
346
|
+
deferred3_0 = ptr2;
|
|
347
|
+
deferred3_1 = len2;
|
|
348
|
+
return getStringFromWasm0(ptr2, len2);
|
|
349
|
+
} finally {
|
|
350
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Computes the SHA-256 hash of the canonical JSON form.
|
|
356
|
+
*
|
|
357
|
+
* This function:
|
|
358
|
+
* 1. Parses and validates the JSON
|
|
359
|
+
* 2. Canonicalizes according to RFC 8785
|
|
360
|
+
* 3. Returns the SHA-256 hash of the canonical bytes
|
|
361
|
+
*
|
|
362
|
+
* # Arguments
|
|
363
|
+
*
|
|
364
|
+
* * `json` - A JSON string containing an AAD object
|
|
365
|
+
*
|
|
366
|
+
* # Returns
|
|
367
|
+
*
|
|
368
|
+
* A 32-byte `Uint8Array` containing the SHA-256 hash.
|
|
369
|
+
*
|
|
370
|
+
* # Errors
|
|
371
|
+
*
|
|
372
|
+
* Throws a JavaScript error if:
|
|
373
|
+
* - The JSON is invalid or contains duplicate keys
|
|
374
|
+
* - Any field violates AAD constraints
|
|
375
|
+
* - The serialized output exceeds 16 KiB
|
|
376
|
+
* @param {string} json
|
|
377
|
+
* @returns {Uint8Array}
|
|
378
|
+
*/
|
|
379
|
+
export function hash(json) {
|
|
380
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
381
|
+
const len0 = WASM_VECTOR_LEN;
|
|
382
|
+
const ret = wasm.hash(ptr0, len0);
|
|
383
|
+
if (ret[3]) {
|
|
384
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
385
|
+
}
|
|
386
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
387
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
388
|
+
return v2;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Validates a JSON string against the AAD specification.
|
|
393
|
+
*
|
|
394
|
+
* This function performs full validation without returning the context.
|
|
395
|
+
* Use this for quick validation checks.
|
|
396
|
+
*
|
|
397
|
+
* # Arguments
|
|
398
|
+
*
|
|
399
|
+
* * `json` - A JSON string to validate
|
|
400
|
+
*
|
|
401
|
+
* # Returns
|
|
402
|
+
*
|
|
403
|
+
* `true` if the JSON is valid AAD, `false` otherwise.
|
|
404
|
+
* @param {string} json
|
|
405
|
+
* @returns {boolean}
|
|
406
|
+
*/
|
|
407
|
+
export function validate(json) {
|
|
408
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
409
|
+
const len0 = WASM_VECTOR_LEN;
|
|
410
|
+
const ret = wasm.validate(ptr0, len0);
|
|
411
|
+
return ret !== 0;
|
|
412
|
+
}
|
|
413
|
+
export function __wbg_Error_8c4e43fe74559d73(arg0, arg1) {
|
|
414
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
415
|
+
return ret;
|
|
416
|
+
}
|
|
417
|
+
export function __wbg___wbindgen_throw_be289d5034ed271b(arg0, arg1) {
|
|
418
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
419
|
+
}
|
|
420
|
+
export function __wbindgen_init_externref_table() {
|
|
421
|
+
const table = wasm.__wbindgen_externrefs;
|
|
422
|
+
const offset = table.grow(4);
|
|
423
|
+
table.set(0, undefined);
|
|
424
|
+
table.set(offset + 0, undefined);
|
|
425
|
+
table.set(offset + 1, null);
|
|
426
|
+
table.set(offset + 2, true);
|
|
427
|
+
table.set(offset + 3, false);
|
|
428
|
+
}
|
|
429
|
+
const AadBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
430
|
+
? { register: () => {}, unregister: () => {} }
|
|
431
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_aadbuilder_free(ptr >>> 0, 1));
|
|
432
|
+
|
|
433
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
434
|
+
ptr = ptr >>> 0;
|
|
435
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function getStringFromWasm0(ptr, len) {
|
|
439
|
+
ptr = ptr >>> 0;
|
|
440
|
+
return decodeText(ptr, len);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
let cachedUint8ArrayMemory0 = null;
|
|
444
|
+
function getUint8ArrayMemory0() {
|
|
445
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
446
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
447
|
+
}
|
|
448
|
+
return cachedUint8ArrayMemory0;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
452
|
+
if (realloc === undefined) {
|
|
453
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
454
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
455
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
456
|
+
WASM_VECTOR_LEN = buf.length;
|
|
457
|
+
return ptr;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
let len = arg.length;
|
|
461
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
462
|
+
|
|
463
|
+
const mem = getUint8ArrayMemory0();
|
|
464
|
+
|
|
465
|
+
let offset = 0;
|
|
466
|
+
|
|
467
|
+
for (; offset < len; offset++) {
|
|
468
|
+
const code = arg.charCodeAt(offset);
|
|
469
|
+
if (code > 0x7F) break;
|
|
470
|
+
mem[ptr + offset] = code;
|
|
471
|
+
}
|
|
472
|
+
if (offset !== len) {
|
|
473
|
+
if (offset !== 0) {
|
|
474
|
+
arg = arg.slice(offset);
|
|
475
|
+
}
|
|
476
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
477
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
478
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
479
|
+
|
|
480
|
+
offset += ret.written;
|
|
481
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
WASM_VECTOR_LEN = offset;
|
|
485
|
+
return ptr;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
function takeFromExternrefTable0(idx) {
|
|
489
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
490
|
+
wasm.__externref_table_dealloc(idx);
|
|
491
|
+
return value;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
495
|
+
cachedTextDecoder.decode();
|
|
496
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
497
|
+
let numBytesDecoded = 0;
|
|
498
|
+
function decodeText(ptr, len) {
|
|
499
|
+
numBytesDecoded += len;
|
|
500
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
501
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
502
|
+
cachedTextDecoder.decode();
|
|
503
|
+
numBytesDecoded = len;
|
|
504
|
+
}
|
|
505
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
const cachedTextEncoder = new TextEncoder();
|
|
509
|
+
|
|
510
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
511
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
512
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
513
|
+
view.set(buf);
|
|
514
|
+
return {
|
|
515
|
+
read: arg.length,
|
|
516
|
+
written: buf.length
|
|
517
|
+
};
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let WASM_VECTOR_LEN = 0;
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
let wasm;
|
|
525
|
+
export function __wbg_set_wasm(val) {
|
|
526
|
+
wasm = val;
|
|
527
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gnufoo/canaad",
|
|
3
|
+
"type": "module",
|
|
3
4
|
"description": "WASM bindings for AAD canonicalization per RFC 8785",
|
|
4
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.1",
|
|
5
6
|
"license": "MIT OR Apache-2.0",
|
|
6
7
|
"files": [
|
|
7
8
|
"canaad_wasm_bg.wasm",
|
|
8
9
|
"canaad_wasm.js",
|
|
10
|
+
"canaad_wasm_bg.js",
|
|
9
11
|
"canaad_wasm.d.ts"
|
|
10
12
|
],
|
|
11
13
|
"main": "canaad_wasm.js",
|
|
12
14
|
"types": "canaad_wasm.d.ts",
|
|
15
|
+
"sideEffects": [
|
|
16
|
+
"./canaad_wasm.js",
|
|
17
|
+
"./snippets/*"
|
|
18
|
+
],
|
|
13
19
|
"keywords": [
|
|
14
20
|
"aead",
|
|
15
21
|
"aad",
|