@gnufoo/canaad 0.4.3 → 0.5.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/errors.d.ts +5 -0
- package/errors.js +10 -0
- package/package.json +1 -1
- package/tool.d.ts +2 -0
- package/tool.js +3 -5
package/errors.d.ts
ADDED
package/errors.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Thrown when an operation is called before `initWasm()` completes. */
|
|
2
|
+
export class WasmNotInitializedError extends Error {
|
|
3
|
+
/** Discriminant for branded error handling — always `'WasmNotInitializedError'`. */
|
|
4
|
+
kind = 'WasmNotInitializedError';
|
|
5
|
+
|
|
6
|
+
constructor() {
|
|
7
|
+
super('WASM not initialized. Call initWasm() first.');
|
|
8
|
+
this.name = 'WasmNotInitializedError';
|
|
9
|
+
}
|
|
10
|
+
}
|
package/package.json
CHANGED
package/tool.d.ts
CHANGED
package/tool.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { meta, inputSchema } from './meta.js';
|
|
2
2
|
import { initWasm, isInitialized } from './init.js';
|
|
3
3
|
import { canonicalize, canonicalizeString, hash, validate, AadBuilder } from './canaad_wasm.js';
|
|
4
|
-
|
|
4
|
+
import { WasmNotInitializedError } from './errors.js';
|
|
5
5
|
const bytesToHex = (bytes) => Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
6
6
|
const bytesToBase64 = (bytes) => globalThis.btoa(String.fromCharCode(...bytes));
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Main tool export. Merges AAD metadata with WASM lifecycle methods and the action dispatcher.
|
|
10
9
|
*/
|
|
@@ -18,11 +17,9 @@ export const toolDefinition = {
|
|
|
18
17
|
*/
|
|
19
18
|
async execute(rawInput) {
|
|
20
19
|
if (!isInitialized()) {
|
|
21
|
-
throw new
|
|
20
|
+
throw new WasmNotInitializedError();
|
|
22
21
|
}
|
|
23
|
-
|
|
24
22
|
const input = inputSchema.parse(rawInput);
|
|
25
|
-
|
|
26
23
|
switch (input.action) {
|
|
27
24
|
case 'canonicalize': {
|
|
28
25
|
if (input.outputFormat === 'bytes') {
|
|
@@ -50,3 +47,4 @@ export const toolDefinition = {
|
|
|
50
47
|
}
|
|
51
48
|
},
|
|
52
49
|
};
|
|
50
|
+
export { WasmNotInitializedError } from './errors.js';
|