@gnufoo/canaad 0.1.3 → 0.3.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/init.d.ts +11 -0
- package/init.js +24 -0
- package/meta.js +1 -1
- package/package.json +18 -5
- package/tool.d.ts +4 -15
- package/tool.js +13 -37
package/init.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize WASM. Call once before using any WASM functions.
|
|
3
|
+
*
|
|
4
|
+
* @param wasmModule - Pass the WebAssembly.Module in Workers, omit in browser
|
|
5
|
+
*/
|
|
6
|
+
export function initWasm(wasmModule?: WebAssembly.Module): Promise<void>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Check if WASM has been initialized.
|
|
10
|
+
*/
|
|
11
|
+
export function isInitialized(): boolean;
|
package/init.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import init from './canaad_wasm.js';
|
|
2
|
+
|
|
3
|
+
let initialized = false;
|
|
4
|
+
let initPromise = null;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Initialize WASM. Call once before using any WASM functions.
|
|
8
|
+
*
|
|
9
|
+
* @param {WebAssembly.Module | undefined} wasmModule - Pass the Module in Workers, omit in browser
|
|
10
|
+
*/
|
|
11
|
+
export async function initWasm(wasmModule) {
|
|
12
|
+
if (initialized) return;
|
|
13
|
+
if (initPromise) return initPromise;
|
|
14
|
+
|
|
15
|
+
initPromise = init(wasmModule).then(() => {
|
|
16
|
+
initialized = true;
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
return initPromise;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function isInitialized() {
|
|
23
|
+
return initialized;
|
|
24
|
+
}
|
package/meta.js
CHANGED
|
@@ -44,7 +44,7 @@ export const meta = {
|
|
|
44
44
|
slug: 'canaad',
|
|
45
45
|
description: 'canonicalize JSON for AAD (Additional Authenticated Data) per RFC 8785',
|
|
46
46
|
category: 'crypto',
|
|
47
|
-
executionType: '
|
|
47
|
+
executionType: 'hybrid',
|
|
48
48
|
positionalArgs: { order: ['action', 'input'], required: 1 },
|
|
49
49
|
inputSchema,
|
|
50
50
|
outputSchema,
|
package/package.json
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gnufoo/canaad",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "canaad_wasm.js",
|
|
6
6
|
"types": "canaad_wasm.d.ts",
|
|
7
7
|
"exports": {
|
|
8
|
-
".":
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./canaad_wasm.d.ts",
|
|
10
|
+
"import": "./canaad_wasm.js"
|
|
11
|
+
},
|
|
12
|
+
"./meta": {
|
|
13
|
+
"types": "./meta.d.ts",
|
|
14
|
+
"import": "./meta.js"
|
|
15
|
+
},
|
|
16
|
+
"./tool": {
|
|
17
|
+
"types": "./tool.d.ts",
|
|
18
|
+
"import": "./tool.js"
|
|
19
|
+
},
|
|
20
|
+
"./init": {
|
|
21
|
+
"types": "./init.d.ts",
|
|
22
|
+
"import": "./init.js"
|
|
23
|
+
}
|
|
12
24
|
},
|
|
13
25
|
"dependencies": {
|
|
14
26
|
"zod": "^3.24.0"
|
|
@@ -18,6 +30,7 @@
|
|
|
18
30
|
"*.d.ts",
|
|
19
31
|
"*.wasm"
|
|
20
32
|
],
|
|
33
|
+
"sideEffects": false,
|
|
21
34
|
"keywords": [
|
|
22
35
|
"aead",
|
|
23
36
|
"aad",
|
package/tool.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import type { meta, CanaadInput, CanaadOutput } from './meta.js';
|
|
2
|
+
import type { initWasm, isInitialized } from './init.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* @param wasmSource - Optional WASM source:
|
|
7
|
-
* - Browser: omit (fetches automatically)
|
|
8
|
-
* - Cloudflare Workers: pass WebAssembly.Module from import
|
|
9
|
-
*/
|
|
10
|
-
export function ensureReady(wasmSource?:
|
|
11
|
-
| WebAssembly.Module
|
|
12
|
-
| ArrayBuffer
|
|
13
|
-
| URL
|
|
14
|
-
| string
|
|
15
|
-
): Promise<void>;
|
|
16
|
-
|
|
17
|
-
export const toolDefinition: typeof meta & {
|
|
4
|
+
export declare const toolDefinition: typeof meta & {
|
|
5
|
+
initWasm: typeof initWasm;
|
|
6
|
+
isInitialized: typeof isInitialized;
|
|
18
7
|
execute(input: CanaadInput): Promise<CanaadOutput>;
|
|
19
8
|
};
|
package/tool.js
CHANGED
|
@@ -1,48 +1,24 @@
|
|
|
1
1
|
import { meta, inputSchema } from './meta.js';
|
|
2
|
-
import
|
|
2
|
+
import { initWasm, isInitialized } from './init.js';
|
|
3
|
+
import { canonicalize, canonicalizeString, hash, validate, AadBuilder } from './canaad_wasm.js';
|
|
3
4
|
|
|
4
|
-
// --- Initialization state ---
|
|
5
|
-
let initialized = false;
|
|
6
|
-
let initPromise = null;
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Initialize the WASM module.
|
|
10
|
-
*
|
|
11
|
-
* @param {WebAssembly.Module | ArrayBuffer | URL | string} [wasmSource]
|
|
12
|
-
* - Browser: omit or pass URL/string path (uses fetch)
|
|
13
|
-
* - Cloudflare Workers: pass the imported WebAssembly.Module
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* // Browser (fetch automatically)
|
|
17
|
-
* await ensureReady();
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* // Cloudflare Workers (pre-compiled module)
|
|
21
|
-
* import wasmModule from '@gnufoo/canaad/wasm';
|
|
22
|
-
* await ensureReady(wasmModule);
|
|
23
|
-
*/
|
|
24
|
-
export async function ensureReady(wasmSource) {
|
|
25
|
-
if (initialized) return;
|
|
26
|
-
if (initPromise) return initPromise;
|
|
27
|
-
|
|
28
|
-
initPromise = init(wasmSource).then(() => {
|
|
29
|
-
initialized = true;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
return initPromise;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// --- Helpers ---
|
|
36
5
|
const bytesToHex = (bytes) => Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join('');
|
|
37
|
-
const bytesToBase64 = (bytes) => btoa(String.fromCharCode(...bytes));
|
|
6
|
+
const bytesToBase64 = (bytes) => globalThis.btoa(String.fromCharCode(...bytes));
|
|
38
7
|
|
|
39
|
-
// --- Tool Definition ---
|
|
40
8
|
export const toolDefinition = {
|
|
41
9
|
...meta,
|
|
42
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Initialize WASM. Must be called before execute() in Workers.
|
|
13
|
+
* In browsers with vite-plugin-wasm, this is optional.
|
|
14
|
+
*/
|
|
15
|
+
initWasm,
|
|
16
|
+
isInitialized,
|
|
17
|
+
|
|
43
18
|
async execute(rawInput) {
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
if (!isInitialized()) {
|
|
20
|
+
throw new Error('WASM not initialized. Call initWasm() first.');
|
|
21
|
+
}
|
|
46
22
|
|
|
47
23
|
const input = inputSchema.parse(rawInput);
|
|
48
24
|
|