@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 ADDED
@@ -0,0 +1,5 @@
1
+ /** Thrown when an operation is called before `initWasm()` completes. */
2
+ export declare class WasmNotInitializedError extends Error {
3
+ /** Discriminant for branded error handling — always `'WasmNotInitializedError'`. */
4
+ readonly kind: 'WasmNotInitializedError';
5
+ }
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gnufoo/canaad",
3
- "version": "0.4.3",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "types": "canaad_wasm.d.ts",
6
6
  "exports": {
package/tool.d.ts CHANGED
@@ -10,3 +10,5 @@ export declare const toolDefinition: typeof meta & {
10
10
  /** Dispatches an AAD action to WASM. Requires prior `initWasm()` call. */
11
11
  execute(input: CanaadInput): Promise<CanaadOutput>;
12
12
  };
13
+
14
+ export { WasmNotInitializedError } from './errors.js';
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 Error('WASM not initialized. Call initWasm() first.');
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';