@gnufoo/canaad 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/canaad_wasm.d.ts +51 -0
- package/canaad_wasm.js +624 -7
- package/canaad_wasm_bg.wasm.d.ts +26 -0
- package/meta.d.ts +19 -0
- package/meta.js +51 -0
- package/package.json +19 -15
- package/tool.d.ts +5 -0
- package/tool.js +44 -0
package/canaad_wasm.d.ts
CHANGED
|
@@ -251,3 +251,54 @@ export function hash(json: string): Uint8Array;
|
|
|
251
251
|
* `true` if the JSON is valid AAD, `false` otherwise.
|
|
252
252
|
*/
|
|
253
253
|
export function validate(json: string): boolean;
|
|
254
|
+
|
|
255
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
256
|
+
|
|
257
|
+
export interface InitOutput {
|
|
258
|
+
readonly memory: WebAssembly.Memory;
|
|
259
|
+
readonly MAX_SAFE_INTEGER: () => number;
|
|
260
|
+
readonly MAX_SERIALIZED_BYTES: () => number;
|
|
261
|
+
readonly SPEC_VERSION: () => number;
|
|
262
|
+
readonly __wbg_aadbuilder_free: (a: number, b: number) => void;
|
|
263
|
+
readonly aadbuilder_build: (a: number) => [number, number, number, number];
|
|
264
|
+
readonly aadbuilder_buildString: (a: number) => [number, number, number, number];
|
|
265
|
+
readonly aadbuilder_extensionInt: (a: number, b: number, c: number, d: number) => number;
|
|
266
|
+
readonly aadbuilder_extensionString: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
267
|
+
readonly aadbuilder_new: () => number;
|
|
268
|
+
readonly aadbuilder_purpose: (a: number, b: number, c: number) => number;
|
|
269
|
+
readonly aadbuilder_resource: (a: number, b: number, c: number) => number;
|
|
270
|
+
readonly aadbuilder_tenant: (a: number, b: number, c: number) => number;
|
|
271
|
+
readonly aadbuilder_timestamp: (a: number, b: number) => number;
|
|
272
|
+
readonly canonicalize: (a: number, b: number) => [number, number, number, number];
|
|
273
|
+
readonly canonicalizeString: (a: number, b: number) => [number, number, number, number];
|
|
274
|
+
readonly hash: (a: number, b: number) => [number, number, number, number];
|
|
275
|
+
readonly validate: (a: number, b: number) => number;
|
|
276
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
277
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
278
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
279
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
280
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
281
|
+
readonly __wbindgen_start: () => void;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
288
|
+
* a precompiled `WebAssembly.Module`.
|
|
289
|
+
*
|
|
290
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
291
|
+
*
|
|
292
|
+
* @returns {InitOutput}
|
|
293
|
+
*/
|
|
294
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
298
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
299
|
+
*
|
|
300
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
301
|
+
*
|
|
302
|
+
* @returns {Promise<InitOutput>}
|
|
303
|
+
*/
|
|
304
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/canaad_wasm.js
CHANGED
|
@@ -1,9 +1,626 @@
|
|
|
1
1
|
/* @ts-self-types="./canaad_wasm.d.ts" */
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export 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
|
+
|
|
244
|
+
/**
|
|
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.
|
|
249
|
+
* @returns {number}
|
|
250
|
+
*/
|
|
251
|
+
export function MAX_SAFE_INTEGER() {
|
|
252
|
+
const ret = wasm.MAX_SAFE_INTEGER();
|
|
253
|
+
return ret;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Returns the maximum serialized AAD size in bytes (16 KiB).
|
|
258
|
+
* @returns {number}
|
|
259
|
+
*/
|
|
260
|
+
export function MAX_SERIALIZED_BYTES() {
|
|
261
|
+
const ret = wasm.MAX_SERIALIZED_BYTES();
|
|
262
|
+
return ret >>> 0;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Returns the current AAD specification version.
|
|
267
|
+
*
|
|
268
|
+
* Currently always returns 1.
|
|
269
|
+
* @returns {number}
|
|
270
|
+
*/
|
|
271
|
+
export function SPEC_VERSION() {
|
|
272
|
+
const ret = wasm.SPEC_VERSION();
|
|
273
|
+
return ret >>> 0;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/**
|
|
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
|
|
298
|
+
* @param {string} json
|
|
299
|
+
* @returns {Uint8Array}
|
|
300
|
+
*/
|
|
301
|
+
export function canonicalize(json) {
|
|
302
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
303
|
+
const len0 = WASM_VECTOR_LEN;
|
|
304
|
+
const ret = wasm.canonicalize(ptr0, len0);
|
|
305
|
+
if (ret[3]) {
|
|
306
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
307
|
+
}
|
|
308
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
309
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
310
|
+
return v2;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* 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
|
+
* @param {string} json
|
|
333
|
+
* @returns {string}
|
|
334
|
+
*/
|
|
335
|
+
export function canonicalizeString(json) {
|
|
336
|
+
let deferred3_0;
|
|
337
|
+
let deferred3_1;
|
|
338
|
+
try {
|
|
339
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
340
|
+
const len0 = WASM_VECTOR_LEN;
|
|
341
|
+
const ret = wasm.canonicalizeString(ptr0, len0);
|
|
342
|
+
var ptr2 = ret[0];
|
|
343
|
+
var len2 = ret[1];
|
|
344
|
+
if (ret[3]) {
|
|
345
|
+
ptr2 = 0; len2 = 0;
|
|
346
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
347
|
+
}
|
|
348
|
+
deferred3_0 = ptr2;
|
|
349
|
+
deferred3_1 = len2;
|
|
350
|
+
return getStringFromWasm0(ptr2, len2);
|
|
351
|
+
} finally {
|
|
352
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
/**
|
|
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
|
|
378
|
+
* @param {string} json
|
|
379
|
+
* @returns {Uint8Array}
|
|
380
|
+
*/
|
|
381
|
+
export function hash(json) {
|
|
382
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
383
|
+
const len0 = WASM_VECTOR_LEN;
|
|
384
|
+
const ret = wasm.hash(ptr0, len0);
|
|
385
|
+
if (ret[3]) {
|
|
386
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
387
|
+
}
|
|
388
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
389
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
390
|
+
return v2;
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* 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
|
+
* @param {string} json
|
|
407
|
+
* @returns {boolean}
|
|
408
|
+
*/
|
|
409
|
+
export function validate(json) {
|
|
410
|
+
const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
411
|
+
const len0 = WASM_VECTOR_LEN;
|
|
412
|
+
const ret = wasm.validate(ptr0, len0);
|
|
413
|
+
return ret !== 0;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function __wbg_get_imports() {
|
|
417
|
+
const import0 = {
|
|
418
|
+
__proto__: null,
|
|
419
|
+
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
420
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
421
|
+
return ret;
|
|
422
|
+
},
|
|
423
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
424
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
425
|
+
},
|
|
426
|
+
__wbindgen_init_externref_table: function() {
|
|
427
|
+
const table = wasm.__wbindgen_externrefs;
|
|
428
|
+
const offset = table.grow(4);
|
|
429
|
+
table.set(0, undefined);
|
|
430
|
+
table.set(offset + 0, undefined);
|
|
431
|
+
table.set(offset + 1, null);
|
|
432
|
+
table.set(offset + 2, true);
|
|
433
|
+
table.set(offset + 3, false);
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
return {
|
|
437
|
+
__proto__: null,
|
|
438
|
+
"./canaad_wasm_bg.js": import0,
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
const AadBuilderFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
443
|
+
? { register: () => {}, unregister: () => {} }
|
|
444
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_aadbuilder_free(ptr >>> 0, 1));
|
|
445
|
+
|
|
446
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
447
|
+
ptr = ptr >>> 0;
|
|
448
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function getStringFromWasm0(ptr, len) {
|
|
452
|
+
ptr = ptr >>> 0;
|
|
453
|
+
return decodeText(ptr, len);
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
let cachedUint8ArrayMemory0 = null;
|
|
457
|
+
function getUint8ArrayMemory0() {
|
|
458
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
459
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
460
|
+
}
|
|
461
|
+
return cachedUint8ArrayMemory0;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
465
|
+
if (realloc === undefined) {
|
|
466
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
467
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
468
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
469
|
+
WASM_VECTOR_LEN = buf.length;
|
|
470
|
+
return ptr;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
let len = arg.length;
|
|
474
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
475
|
+
|
|
476
|
+
const mem = getUint8ArrayMemory0();
|
|
477
|
+
|
|
478
|
+
let offset = 0;
|
|
479
|
+
|
|
480
|
+
for (; offset < len; offset++) {
|
|
481
|
+
const code = arg.charCodeAt(offset);
|
|
482
|
+
if (code > 0x7F) break;
|
|
483
|
+
mem[ptr + offset] = code;
|
|
484
|
+
}
|
|
485
|
+
if (offset !== len) {
|
|
486
|
+
if (offset !== 0) {
|
|
487
|
+
arg = arg.slice(offset);
|
|
488
|
+
}
|
|
489
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
490
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
491
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
492
|
+
|
|
493
|
+
offset += ret.written;
|
|
494
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
WASM_VECTOR_LEN = offset;
|
|
498
|
+
return ptr;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function takeFromExternrefTable0(idx) {
|
|
502
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
503
|
+
wasm.__externref_table_dealloc(idx);
|
|
504
|
+
return value;
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
508
|
+
cachedTextDecoder.decode();
|
|
509
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
510
|
+
let numBytesDecoded = 0;
|
|
511
|
+
function decodeText(ptr, len) {
|
|
512
|
+
numBytesDecoded += len;
|
|
513
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
514
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
515
|
+
cachedTextDecoder.decode();
|
|
516
|
+
numBytesDecoded = len;
|
|
517
|
+
}
|
|
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
|
+
let wasmModule, wasm;
|
|
537
|
+
function __wbg_finalize_init(instance, module) {
|
|
538
|
+
wasm = instance.exports;
|
|
539
|
+
wasmModule = module;
|
|
540
|
+
cachedUint8ArrayMemory0 = null;
|
|
541
|
+
wasm.__wbindgen_start();
|
|
542
|
+
return wasm;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
async function __wbg_load(module, imports) {
|
|
546
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
547
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
548
|
+
try {
|
|
549
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
550
|
+
} catch (e) {
|
|
551
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
552
|
+
|
|
553
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
554
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
555
|
+
|
|
556
|
+
} else { throw e; }
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
const bytes = await module.arrayBuffer();
|
|
561
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
562
|
+
} else {
|
|
563
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
564
|
+
|
|
565
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
566
|
+
return { instance, module };
|
|
567
|
+
} else {
|
|
568
|
+
return instance;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function expectedResponseType(type) {
|
|
573
|
+
switch (type) {
|
|
574
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
575
|
+
}
|
|
576
|
+
return false;
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
function initSync(module) {
|
|
581
|
+
if (wasm !== undefined) return wasm;
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
if (module !== undefined) {
|
|
585
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
586
|
+
({module} = module)
|
|
587
|
+
} else {
|
|
588
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const imports = __wbg_get_imports();
|
|
593
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
594
|
+
module = new WebAssembly.Module(module);
|
|
595
|
+
}
|
|
596
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
597
|
+
return __wbg_finalize_init(instance, module);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
async function __wbg_init(module_or_path) {
|
|
601
|
+
if (wasm !== undefined) return wasm;
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
if (module_or_path !== undefined) {
|
|
605
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
606
|
+
({module_or_path} = module_or_path)
|
|
607
|
+
} else {
|
|
608
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
if (module_or_path === undefined) {
|
|
613
|
+
module_or_path = new URL('canaad_wasm_bg.wasm', import.meta.url);
|
|
614
|
+
}
|
|
615
|
+
const imports = __wbg_get_imports();
|
|
616
|
+
|
|
617
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
618
|
+
module_or_path = fetch(module_or_path);
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
622
|
+
|
|
623
|
+
return __wbg_finalize_init(instance, module);
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
export { initSync, __wbg_init as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const MAX_SAFE_INTEGER: () => number;
|
|
5
|
+
export const MAX_SERIALIZED_BYTES: () => number;
|
|
6
|
+
export const SPEC_VERSION: () => number;
|
|
7
|
+
export const __wbg_aadbuilder_free: (a: number, b: number) => void;
|
|
8
|
+
export const aadbuilder_build: (a: number) => [number, number, number, number];
|
|
9
|
+
export const aadbuilder_buildString: (a: number) => [number, number, number, number];
|
|
10
|
+
export const aadbuilder_extensionInt: (a: number, b: number, c: number, d: number) => number;
|
|
11
|
+
export const aadbuilder_extensionString: (a: number, b: number, c: number, d: number, e: number) => number;
|
|
12
|
+
export const aadbuilder_new: () => number;
|
|
13
|
+
export const aadbuilder_purpose: (a: number, b: number, c: number) => number;
|
|
14
|
+
export const aadbuilder_resource: (a: number, b: number, c: number) => number;
|
|
15
|
+
export const aadbuilder_tenant: (a: number, b: number, c: number) => number;
|
|
16
|
+
export const aadbuilder_timestamp: (a: number, b: number) => number;
|
|
17
|
+
export const canonicalize: (a: number, b: number) => [number, number, number, number];
|
|
18
|
+
export const canonicalizeString: (a: number, b: number) => [number, number, number, number];
|
|
19
|
+
export const hash: (a: number, b: number) => [number, number, number, number];
|
|
20
|
+
export const validate: (a: number, b: number) => number;
|
|
21
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
22
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
23
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
24
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
25
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
26
|
+
export const __wbindgen_start: () => void;
|
package/meta.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
export declare const inputSchema: z.ZodType;
|
|
4
|
+
export declare const outputSchema: z.ZodType;
|
|
5
|
+
|
|
6
|
+
export type CanaadInput = z.infer<typeof inputSchema>;
|
|
7
|
+
export type CanaadOutput = z.infer<typeof outputSchema>;
|
|
8
|
+
|
|
9
|
+
export declare const meta: {
|
|
10
|
+
id: string;
|
|
11
|
+
name: string;
|
|
12
|
+
slug: string;
|
|
13
|
+
description: string;
|
|
14
|
+
category: string;
|
|
15
|
+
executionType: string;
|
|
16
|
+
positionalArgs: { order: string[]; required: number };
|
|
17
|
+
inputSchema: typeof inputSchema;
|
|
18
|
+
outputSchema: typeof outputSchema;
|
|
19
|
+
};
|
package/meta.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
const extensionSchema = z.object({
|
|
4
|
+
key: z.string().regex(/^x_[a-z]+_[a-z_]+$/),
|
|
5
|
+
value: z.union([z.string(), z.number().int().nonnegative()]),
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
export const inputSchema = z.discriminatedUnion('action', [
|
|
9
|
+
z.object({
|
|
10
|
+
action: z.literal('canonicalize'),
|
|
11
|
+
input: z.string(),
|
|
12
|
+
outputFormat: z.enum(['bytes', 'string']).default('string'),
|
|
13
|
+
}),
|
|
14
|
+
z.object({
|
|
15
|
+
action: z.literal('validate'),
|
|
16
|
+
input: z.string(),
|
|
17
|
+
}),
|
|
18
|
+
z.object({
|
|
19
|
+
action: z.literal('hash'),
|
|
20
|
+
input: z.string(),
|
|
21
|
+
outputFormat: z.enum(['hex', 'base64']).default('hex'),
|
|
22
|
+
}),
|
|
23
|
+
z.object({
|
|
24
|
+
action: z.literal('build'),
|
|
25
|
+
tenant: z.string().min(1).max(256),
|
|
26
|
+
resource: z.string().min(1).max(1024),
|
|
27
|
+
purpose: z.string().min(1),
|
|
28
|
+
timestamp: z.number().int().nonnegative().optional(),
|
|
29
|
+
extensions: z.array(extensionSchema).optional(),
|
|
30
|
+
outputFormat: z.enum(['bytes', 'string']).default('string'),
|
|
31
|
+
}),
|
|
32
|
+
]);
|
|
33
|
+
|
|
34
|
+
export const outputSchema = z.discriminatedUnion('action', [
|
|
35
|
+
z.object({ action: z.literal('canonicalize'), output: z.union([z.string(), z.array(z.number())]), outputFormat: z.enum(['bytes', 'string']) }),
|
|
36
|
+
z.object({ action: z.literal('validate'), valid: z.boolean() }),
|
|
37
|
+
z.object({ action: z.literal('hash'), hash: z.string(), outputFormat: z.enum(['hex', 'base64']) }),
|
|
38
|
+
z.object({ action: z.literal('build'), output: z.union([z.string(), z.array(z.number())]), outputFormat: z.enum(['bytes', 'string']) }),
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export const meta = {
|
|
42
|
+
id: 'canaad',
|
|
43
|
+
name: 'canaad',
|
|
44
|
+
slug: 'canaad',
|
|
45
|
+
description: 'canonicalize JSON for AAD (Additional Authenticated Data) per RFC 8785',
|
|
46
|
+
category: 'crypto',
|
|
47
|
+
executionType: 'client',
|
|
48
|
+
positionalArgs: { order: ['action', 'input'], required: 1 },
|
|
49
|
+
inputSchema,
|
|
50
|
+
outputSchema,
|
|
51
|
+
};
|
package/package.json
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gnufoo/canaad",
|
|
3
|
+
"version": "0.1.2",
|
|
3
4
|
"type": "module",
|
|
4
|
-
"description": "WASM bindings for AAD canonicalization per RFC 8785",
|
|
5
|
-
"version": "0.1.1",
|
|
6
|
-
"license": "MIT OR Apache-2.0",
|
|
7
|
-
"files": [
|
|
8
|
-
"canaad_wasm_bg.wasm",
|
|
9
|
-
"canaad_wasm.js",
|
|
10
|
-
"canaad_wasm_bg.js",
|
|
11
|
-
"canaad_wasm.d.ts"
|
|
12
|
-
],
|
|
13
5
|
"main": "canaad_wasm.js",
|
|
14
6
|
"types": "canaad_wasm.d.ts",
|
|
15
|
-
"
|
|
16
|
-
"./canaad_wasm.js",
|
|
17
|
-
"./
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./canaad_wasm.js",
|
|
9
|
+
"./meta": "./meta.js",
|
|
10
|
+
"./tool": "./tool.js"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"zod": "^3.24.0"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"*.js",
|
|
17
|
+
"*.d.ts",
|
|
18
|
+
"*.wasm"
|
|
18
19
|
],
|
|
19
20
|
"keywords": [
|
|
20
21
|
"aead",
|
|
21
22
|
"aad",
|
|
22
23
|
"canonicalization",
|
|
23
24
|
"jcs",
|
|
24
|
-
"rfc8785"
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
"rfc8785",
|
|
26
|
+
"wasm"
|
|
27
|
+
],
|
|
28
|
+
"license": "MIT OR Apache-2.0",
|
|
29
|
+
"description": "AAD canonicalization library (RFC 8785)"
|
|
30
|
+
}
|
package/tool.d.ts
ADDED
package/tool.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { meta, inputSchema } from './meta.js';
|
|
2
|
+
import init, { canonicalize, canonicalize_string, hash, validate, AadBuilder } from './canaad_wasm.js';
|
|
3
|
+
|
|
4
|
+
let ready = false;
|
|
5
|
+
async function ensureReady() {
|
|
6
|
+
if (!ready) { await init(); ready = true; }
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const bytesToHex = (bytes) => Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
10
|
+
const bytesToBase64 = (bytes) => btoa(String.fromCharCode(...bytes));
|
|
11
|
+
|
|
12
|
+
export const toolDefinition = {
|
|
13
|
+
...meta,
|
|
14
|
+
async execute(rawInput) {
|
|
15
|
+
await ensureReady();
|
|
16
|
+
const input = inputSchema.parse(rawInput);
|
|
17
|
+
|
|
18
|
+
switch (input.action) {
|
|
19
|
+
case 'canonicalize': {
|
|
20
|
+
if (input.outputFormat === 'bytes') {
|
|
21
|
+
return { action: 'canonicalize', output: Array.from(canonicalize(input.input)), outputFormat: 'bytes' };
|
|
22
|
+
}
|
|
23
|
+
return { action: 'canonicalize', output: canonicalize_string(input.input), outputFormat: 'string' };
|
|
24
|
+
}
|
|
25
|
+
case 'validate':
|
|
26
|
+
return { action: 'validate', valid: validate(input.input) };
|
|
27
|
+
case 'hash': {
|
|
28
|
+
const h = hash(input.input);
|
|
29
|
+
return { action: 'hash', hash: input.outputFormat === 'base64' ? bytesToBase64(h) : bytesToHex(h), outputFormat: input.outputFormat };
|
|
30
|
+
}
|
|
31
|
+
case 'build': {
|
|
32
|
+
let b = new AadBuilder().tenant(input.tenant).resource(input.resource).purpose(input.purpose);
|
|
33
|
+
if (input.timestamp !== undefined) b = b.timestamp(input.timestamp);
|
|
34
|
+
for (const ext of input.extensions || []) {
|
|
35
|
+
b = typeof ext.value === 'string' ? b.extension_string(ext.key, ext.value) : b.extension_int(ext.key, ext.value);
|
|
36
|
+
}
|
|
37
|
+
if (input.outputFormat === 'bytes') {
|
|
38
|
+
return { action: 'build', output: Array.from(b.build()), outputFormat: 'bytes' };
|
|
39
|
+
}
|
|
40
|
+
return { action: 'build', output: b.build_string(), outputFormat: 'string' };
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|