@canonmsg/agent-sdk 12.4.1 → 12.6.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/README.md +37 -6
- package/dist/chunks/{chunk-6PKXASSK.js → chunk-5J4YPLNW.js} +394 -1687
- package/dist/chunks/{chunk-NXL4C2R6.js → chunk-DAJ7L7TN.js} +954 -429
- package/dist/chunks/chunk-FVYKLH6I.js +1475 -0
- package/dist/chunks/chunk-HH7KR22P.js +406 -0
- package/dist/chunks/chunk-QK37HAHC.js +118 -0
- package/dist/chunks/{chunk-GWQF4WFT.js → chunk-S7BV74DN.js} +734 -812
- package/dist/chunks/{mls-crypto-LGPCXM3K.js → mls-crypto-4DZT2UFH.js} +2 -1
- package/dist/cli.js +70 -32
- package/dist/drivers/acp.d.ts +56 -0
- package/dist/drivers/codex.d.ts +1 -2
- package/dist/drivers/connector.d.ts +5 -4
- package/dist/drivers/subprocess.d.ts +35 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +12 -3
- package/dist/internal/backend-contracts/connectorRelay.d.ts +34 -0
- package/dist/internal/backend-contracts/endpoint.d.ts +1 -1
- package/dist/internal/backend-contracts/endpointContentPolicy.d.ts +2 -2
- package/dist/internal/backend-contracts/index.d.ts +1 -0
- package/dist/internal/backend-contracts/loggedOutSessions.d.ts +7 -0
- package/dist/internal/backend-contracts/mlsDevCredential.d.ts +3 -0
- package/dist/internal/endpoint/engine.d.ts +8 -1
- package/dist/internal/endpoint/mls-dev-client.d.ts +11 -0
- package/dist/internal/endpoint/mls-dev-text.d.ts +3 -0
- package/dist/internal/endpoint/node-mls-custody-protocol.d.ts +5 -0
- package/dist/internal/endpoint/node.d.ts +1 -0
- package/dist/media.js +4 -2
- package/dist/mls/darwin-arm64/canon-mls-custody +0 -0
- package/dist/mls/linux-arm64/canon-mls-custody +0 -0
- package/dist/mls/linux-x64/canon-mls-custody +0 -0
- package/dist/mls/wasm/canon_mls_wasm.js +363 -0
- package/dist/mls/wasm/canon_mls_wasm_bg.wasm +0 -0
- package/dist/mls-wasm-host.js +258 -0
- package/dist/runner/mls-bundled.d.ts +15 -2
- package/dist/runner/mls-managed.d.ts +10 -2
- package/dist/runner/mls.d.ts +7 -1
- package/dist/runner/relay.d.ts +3 -3
- package/dist/runner/runner.d.ts +18 -7
- package/dist/runner/types.d.ts +12 -4
- package/package.json +1 -1
|
@@ -23,6 +23,11 @@ export declare function requireValue(value: unknown): asserts value;
|
|
|
23
23
|
export declare function record(value: unknown, fields: string[]): Record<string, unknown>;
|
|
24
24
|
export declare function sealed(value: unknown, maximum: number, nullable?: boolean): string | null;
|
|
25
25
|
export declare function frame(operation: number, values: readonly (string | null)[]): Buffer;
|
|
26
|
+
/** What `frame` wrote: its operation and arguments. */
|
|
27
|
+
export declare function parseFrame(input: Buffer): {
|
|
28
|
+
operation: number;
|
|
29
|
+
values: (string | null)[];
|
|
30
|
+
};
|
|
26
31
|
/** JSON.parse supplies grammar validation; this pass rejects duplicate object
|
|
27
32
|
* names (including escaped aliases) before the closed contract parsers run. */
|
|
28
33
|
export declare function parseJson(bytes: Buffer): unknown;
|
|
@@ -5,3 +5,4 @@ export declare function createNodeEndpointStore(options: {
|
|
|
5
5
|
}): Promise<EndpointStore>;
|
|
6
6
|
export { createNodeMlsDevCustody, NodeMlsDevCustodyError, type NodeMlsDevCustody, type NodeMlsDevCustodyOptions } from './node-mls-custody.js';
|
|
7
7
|
export { createPortableNodeMlsDevCustody, type PortableNodeMlsDevCustody, type PortableNodeMlsDevCustodyOptions } from './portable-node-mls-custody.js';
|
|
8
|
+
export { custodyFailure, custodyValue, frame, MAX_INPUT, MAX_OUTPUT, parseFrame, rejected, requireValue, typedNodeMlsDevCustody } from './node-mls-custody-protocol.js';
|
package/dist/media.js
CHANGED
|
@@ -18,8 +18,10 @@ import {
|
|
|
18
18
|
toAnthropicImageBlock,
|
|
19
19
|
toAnthropicImageBlocksWithinBudget,
|
|
20
20
|
uploadMediaFile
|
|
21
|
-
} from "./chunks/chunk-
|
|
22
|
-
import "./chunks/chunk-
|
|
21
|
+
} from "./chunks/chunk-5J4YPLNW.js";
|
|
22
|
+
import "./chunks/chunk-FVYKLH6I.js";
|
|
23
|
+
import "./chunks/chunk-QK37HAHC.js";
|
|
24
|
+
import "./chunks/chunk-S7BV74DN.js";
|
|
23
25
|
export {
|
|
24
26
|
DEFAULT_ANTHROPIC_REQUEST_HEADROOM_BYTES,
|
|
25
27
|
DEFAULT_MEDIA_CACHE_DIR,
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/* @ts-self-types="./canon_mls_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @returns {number}
|
|
5
|
+
*/
|
|
6
|
+
export function abi_version() {
|
|
7
|
+
const ret = wasm.abi_version();
|
|
8
|
+
return ret >>> 0;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {Uint8Array} identity_context
|
|
13
|
+
* @param {Uint8Array} group_context
|
|
14
|
+
* @param {Uint8Array} command
|
|
15
|
+
* @param {Uint8Array} identity_state
|
|
16
|
+
* @param {Uint8Array | null | undefined} group_state
|
|
17
|
+
* @param {Uint8Array | null | undefined} key_package_state
|
|
18
|
+
* @param {Uint8Array} issuer_keys
|
|
19
|
+
* @param {Uint8Array} receipt_keys
|
|
20
|
+
* @param {number} now_ms
|
|
21
|
+
* @returns {Uint8Array}
|
|
22
|
+
*/
|
|
23
|
+
export function prepare_group(identity_context, group_context, command, identity_state, group_state, key_package_state, issuer_keys, receipt_keys, now_ms) {
|
|
24
|
+
const ptr0 = passArray8ToWasm0(identity_context, wasm.__wbindgen_malloc);
|
|
25
|
+
const len0 = WASM_VECTOR_LEN;
|
|
26
|
+
const ptr1 = passArray8ToWasm0(group_context, wasm.__wbindgen_malloc);
|
|
27
|
+
const len1 = WASM_VECTOR_LEN;
|
|
28
|
+
const ptr2 = passArray8ToWasm0(command, wasm.__wbindgen_malloc);
|
|
29
|
+
const len2 = WASM_VECTOR_LEN;
|
|
30
|
+
const ptr3 = passArray8ToWasm0(identity_state, wasm.__wbindgen_malloc);
|
|
31
|
+
const len3 = WASM_VECTOR_LEN;
|
|
32
|
+
var ptr4 = isLikeNone(group_state) ? 0 : passArray8ToWasm0(group_state, wasm.__wbindgen_malloc);
|
|
33
|
+
var len4 = WASM_VECTOR_LEN;
|
|
34
|
+
var ptr5 = isLikeNone(key_package_state) ? 0 : passArray8ToWasm0(key_package_state, wasm.__wbindgen_malloc);
|
|
35
|
+
var len5 = WASM_VECTOR_LEN;
|
|
36
|
+
const ptr6 = passArray8ToWasm0(issuer_keys, wasm.__wbindgen_malloc);
|
|
37
|
+
const len6 = WASM_VECTOR_LEN;
|
|
38
|
+
const ptr7 = passArray8ToWasm0(receipt_keys, wasm.__wbindgen_malloc);
|
|
39
|
+
const len7 = WASM_VECTOR_LEN;
|
|
40
|
+
const ret = wasm.prepare_group(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4, ptr5, len5, ptr6, len6, ptr7, len7, now_ms);
|
|
41
|
+
var v9 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
42
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
43
|
+
return v9;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @param {Uint8Array} context
|
|
48
|
+
* @param {Uint8Array} command
|
|
49
|
+
* @param {Uint8Array} identity_state
|
|
50
|
+
* @param {Uint8Array} issuer_keys
|
|
51
|
+
* @param {number} now_ms
|
|
52
|
+
* @returns {Uint8Array}
|
|
53
|
+
*/
|
|
54
|
+
export function prepare_key_package(context, command, identity_state, issuer_keys, now_ms) {
|
|
55
|
+
const ptr0 = passArray8ToWasm0(context, wasm.__wbindgen_malloc);
|
|
56
|
+
const len0 = WASM_VECTOR_LEN;
|
|
57
|
+
const ptr1 = passArray8ToWasm0(command, wasm.__wbindgen_malloc);
|
|
58
|
+
const len1 = WASM_VECTOR_LEN;
|
|
59
|
+
const ptr2 = passArray8ToWasm0(identity_state, wasm.__wbindgen_malloc);
|
|
60
|
+
const len2 = WASM_VECTOR_LEN;
|
|
61
|
+
const ptr3 = passArray8ToWasm0(issuer_keys, wasm.__wbindgen_malloc);
|
|
62
|
+
const len3 = WASM_VECTOR_LEN;
|
|
63
|
+
const ret = wasm.prepare_key_package(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, now_ms);
|
|
64
|
+
var v5 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
65
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
66
|
+
return v5;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {Uint8Array} context
|
|
71
|
+
* @param {Uint8Array} command
|
|
72
|
+
* @param {Uint8Array | null | undefined} state
|
|
73
|
+
* @param {number} now_ms
|
|
74
|
+
* @returns {Uint8Array}
|
|
75
|
+
*/
|
|
76
|
+
export function prepare_signing(context, command, state, now_ms) {
|
|
77
|
+
const ptr0 = passArray8ToWasm0(context, wasm.__wbindgen_malloc);
|
|
78
|
+
const len0 = WASM_VECTOR_LEN;
|
|
79
|
+
const ptr1 = passArray8ToWasm0(command, wasm.__wbindgen_malloc);
|
|
80
|
+
const len1 = WASM_VECTOR_LEN;
|
|
81
|
+
var ptr2 = isLikeNone(state) ? 0 : passArray8ToWasm0(state, wasm.__wbindgen_malloc);
|
|
82
|
+
var len2 = WASM_VECTOR_LEN;
|
|
83
|
+
const ret = wasm.prepare_signing(ptr0, len0, ptr1, len1, ptr2, len2, now_ms);
|
|
84
|
+
var v4 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
85
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
86
|
+
return v4;
|
|
87
|
+
}
|
|
88
|
+
function __wbg_get_imports() {
|
|
89
|
+
const import0 = {
|
|
90
|
+
__proto__: null,
|
|
91
|
+
__wbg___wbindgen_is_function_1f9d30630b8b1d3d: function(arg0) {
|
|
92
|
+
const ret = typeof(arg0) === 'function';
|
|
93
|
+
return ret;
|
|
94
|
+
},
|
|
95
|
+
__wbg___wbindgen_is_object_3c45d4f2dde4e749: function(arg0) {
|
|
96
|
+
const val = arg0;
|
|
97
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
98
|
+
return ret;
|
|
99
|
+
},
|
|
100
|
+
__wbg___wbindgen_is_string_90b56bc79aad6f6c: function(arg0) {
|
|
101
|
+
const ret = typeof(arg0) === 'string';
|
|
102
|
+
return ret;
|
|
103
|
+
},
|
|
104
|
+
__wbg___wbindgen_is_undefined_8865fb403f8fe9d8: function(arg0) {
|
|
105
|
+
const ret = arg0 === undefined;
|
|
106
|
+
return ret;
|
|
107
|
+
},
|
|
108
|
+
__wbg___wbindgen_throw_41e9ee4f547fc59a: function(arg0, arg1) {
|
|
109
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
110
|
+
},
|
|
111
|
+
__wbg_call_187d372bd5fdd4aa: function() { return handleError(function (arg0, arg1, arg2) {
|
|
112
|
+
const ret = arg0.call(arg1, arg2);
|
|
113
|
+
return ret;
|
|
114
|
+
}, arguments); },
|
|
115
|
+
__wbg_crypto_38df2bab126b63dc: function(arg0) {
|
|
116
|
+
const ret = arg0.crypto;
|
|
117
|
+
return ret;
|
|
118
|
+
},
|
|
119
|
+
__wbg_getRandomValues_436a51d0629d84e1: function() { return handleError(function (arg0, arg1) {
|
|
120
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
121
|
+
}, arguments); },
|
|
122
|
+
__wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
|
|
123
|
+
arg0.getRandomValues(arg1);
|
|
124
|
+
}, arguments); },
|
|
125
|
+
__wbg_length_7f3c00c40364105e: function(arg0) {
|
|
126
|
+
const ret = arg0.length;
|
|
127
|
+
return ret;
|
|
128
|
+
},
|
|
129
|
+
__wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
|
|
130
|
+
const ret = arg0.msCrypto;
|
|
131
|
+
return ret;
|
|
132
|
+
},
|
|
133
|
+
__wbg_new_with_length_3da0ad195f6f63ba: function(arg0) {
|
|
134
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
135
|
+
return ret;
|
|
136
|
+
},
|
|
137
|
+
__wbg_node_84ea875411254db1: function(arg0) {
|
|
138
|
+
const ret = arg0.node;
|
|
139
|
+
return ret;
|
|
140
|
+
},
|
|
141
|
+
__wbg_now_aa4ccb83129e9e55: function() {
|
|
142
|
+
const ret = Date.now();
|
|
143
|
+
return ret;
|
|
144
|
+
},
|
|
145
|
+
__wbg_process_44c7a14e11e9f69e: function(arg0) {
|
|
146
|
+
const ret = arg0.process;
|
|
147
|
+
return ret;
|
|
148
|
+
},
|
|
149
|
+
__wbg_prototypesetcall_bc27214492979395: function(arg0, arg1, arg2) {
|
|
150
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
151
|
+
},
|
|
152
|
+
__wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
|
|
153
|
+
arg0.randomFillSync(arg1);
|
|
154
|
+
}, arguments); },
|
|
155
|
+
__wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
|
|
156
|
+
const ret = module.require;
|
|
157
|
+
return ret;
|
|
158
|
+
}, arguments); },
|
|
159
|
+
__wbg_static_accessor_GLOBAL_266715b9d96ba635: function() {
|
|
160
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
161
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
162
|
+
},
|
|
163
|
+
__wbg_static_accessor_GLOBAL_THIS_10fb7dc1ae063179: function() {
|
|
164
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
165
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
166
|
+
},
|
|
167
|
+
__wbg_static_accessor_SELF_0b583911f537483a: function() {
|
|
168
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
169
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
170
|
+
},
|
|
171
|
+
__wbg_static_accessor_WINDOW_d7f903d1508cbdc4: function() {
|
|
172
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
173
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
174
|
+
},
|
|
175
|
+
__wbg_subarray_002b94d5e13d1411: function(arg0, arg1, arg2) {
|
|
176
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
177
|
+
return ret;
|
|
178
|
+
},
|
|
179
|
+
__wbg_versions_276b2795b1c6a219: function(arg0) {
|
|
180
|
+
const ret = arg0.versions;
|
|
181
|
+
return ret;
|
|
182
|
+
},
|
|
183
|
+
__wbindgen_generic_0000000000000001: function(arg0, arg1) {
|
|
184
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
185
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
186
|
+
return ret;
|
|
187
|
+
},
|
|
188
|
+
__wbindgen_generic_0000000000000002: function(arg0, arg1) {
|
|
189
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
190
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
191
|
+
return ret;
|
|
192
|
+
},
|
|
193
|
+
__wbindgen_init_externref_table: function() {
|
|
194
|
+
const table = wasm.__wbindgen_externrefs;
|
|
195
|
+
const offset = table.grow(4);
|
|
196
|
+
table.set(0, undefined);
|
|
197
|
+
table.set(offset + 0, undefined);
|
|
198
|
+
table.set(offset + 1, null);
|
|
199
|
+
table.set(offset + 2, true);
|
|
200
|
+
table.set(offset + 3, false);
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
return {
|
|
204
|
+
__proto__: null,
|
|
205
|
+
"./canon_mls_wasm_bg.js": import0,
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function addToExternrefTable0(obj) {
|
|
210
|
+
const idx = wasm.__externref_table_alloc();
|
|
211
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
212
|
+
return idx;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
216
|
+
ptr = ptr >>> 0;
|
|
217
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
function getStringFromWasm0(ptr, len) {
|
|
221
|
+
return decodeText(ptr >>> 0, len);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let cachedUint8ArrayMemory0 = null;
|
|
225
|
+
function getUint8ArrayMemory0() {
|
|
226
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
227
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
228
|
+
}
|
|
229
|
+
return cachedUint8ArrayMemory0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function handleError(f, args) {
|
|
233
|
+
try {
|
|
234
|
+
return f.apply(this, args);
|
|
235
|
+
} catch (e) {
|
|
236
|
+
const idx = addToExternrefTable0(e);
|
|
237
|
+
wasm.__wbindgen_exn_store(idx);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function isLikeNone(x) {
|
|
242
|
+
return x === undefined || x === null;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
246
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
247
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
248
|
+
WASM_VECTOR_LEN = arg.length;
|
|
249
|
+
return ptr;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
253
|
+
cachedTextDecoder.decode();
|
|
254
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
255
|
+
let numBytesDecoded = 0;
|
|
256
|
+
function decodeText(ptr, len) {
|
|
257
|
+
numBytesDecoded += len;
|
|
258
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
259
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
260
|
+
cachedTextDecoder.decode();
|
|
261
|
+
numBytesDecoded = len;
|
|
262
|
+
}
|
|
263
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let WASM_VECTOR_LEN = 0;
|
|
267
|
+
|
|
268
|
+
let wasmModule, wasmInstance, wasm;
|
|
269
|
+
function __wbg_finalize_init(instance, module) {
|
|
270
|
+
wasmInstance = instance;
|
|
271
|
+
wasm = instance.exports;
|
|
272
|
+
wasmModule = module;
|
|
273
|
+
cachedUint8ArrayMemory0 = null;
|
|
274
|
+
wasm.__wbindgen_start();
|
|
275
|
+
return wasm;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
async function __wbg_load(module, imports) {
|
|
279
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
280
|
+
if (!module.ok) {
|
|
281
|
+
throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
285
|
+
try {
|
|
286
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
287
|
+
} catch (e) {
|
|
288
|
+
const validResponse = expectedResponseType(module.type);
|
|
289
|
+
|
|
290
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
291
|
+
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);
|
|
292
|
+
|
|
293
|
+
} else { throw e; }
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
const bytes = await module.arrayBuffer();
|
|
298
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
299
|
+
} else {
|
|
300
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
301
|
+
|
|
302
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
303
|
+
return { instance, module };
|
|
304
|
+
} else {
|
|
305
|
+
return instance;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function expectedResponseType(type) {
|
|
310
|
+
switch (type) {
|
|
311
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
312
|
+
}
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
function initSync(module) {
|
|
318
|
+
if (wasm !== undefined) return wasm;
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
if (module !== undefined) {
|
|
322
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
323
|
+
({module} = module)
|
|
324
|
+
} else {
|
|
325
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const imports = __wbg_get_imports();
|
|
330
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
331
|
+
module = new WebAssembly.Module(module);
|
|
332
|
+
}
|
|
333
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
334
|
+
return __wbg_finalize_init(instance, module);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
async function __wbg_init(module_or_path) {
|
|
338
|
+
if (wasm !== undefined) return wasm;
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
if (module_or_path !== undefined) {
|
|
342
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
343
|
+
({module_or_path} = module_or_path)
|
|
344
|
+
} else {
|
|
345
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (module_or_path === undefined) {
|
|
350
|
+
module_or_path = new URL('canon_mls_wasm_bg.wasm', import.meta.url);
|
|
351
|
+
}
|
|
352
|
+
const imports = __wbg_get_imports();
|
|
353
|
+
|
|
354
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
355
|
+
module_or_path = fetch(module_or_path);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
359
|
+
|
|
360
|
+
return __wbg_finalize_init(instance, module);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WASM_HOST_CONFIGURE,
|
|
3
|
+
WASM_HOST_PROVISION,
|
|
4
|
+
keyFile
|
|
5
|
+
} from "./chunks/chunk-HH7KR22P.js";
|
|
6
|
+
import {
|
|
7
|
+
MAX_INPUT,
|
|
8
|
+
NodeMlsDevCustodyError,
|
|
9
|
+
parseFrame,
|
|
10
|
+
rejected,
|
|
11
|
+
requireValue
|
|
12
|
+
} from "./chunks/chunk-FVYKLH6I.js";
|
|
13
|
+
import {
|
|
14
|
+
__name,
|
|
15
|
+
canonicalEndpointJson,
|
|
16
|
+
isMlsDevReceiptClockSkew,
|
|
17
|
+
parseMlsDevDeviceContext
|
|
18
|
+
} from "./chunks/chunk-S7BV74DN.js";
|
|
19
|
+
|
|
20
|
+
// src/mls-wasm-host.ts
|
|
21
|
+
import { createHash } from "node:crypto";
|
|
22
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
23
|
+
|
|
24
|
+
// ../endpoint/src/mls-browser-custody.ts
|
|
25
|
+
var AAD_DOMAIN = "canon.mls.browser-state.v1";
|
|
26
|
+
var encoder = new TextEncoder();
|
|
27
|
+
var decoder = new TextDecoder();
|
|
28
|
+
var MAX_PAYLOAD_BYTES = 4 * 1024 * 1024;
|
|
29
|
+
var refused = /* @__PURE__ */ __name(() => {
|
|
30
|
+
throw new Error("CANON_MLS_CUSTODY_REFUSED");
|
|
31
|
+
}, "refused");
|
|
32
|
+
function toBase64(bytes) {
|
|
33
|
+
let text = "";
|
|
34
|
+
for (let at = 0; at < bytes.length; at += 32768) text += String.fromCharCode(...bytes.subarray(at, at + 32768));
|
|
35
|
+
return btoa(text);
|
|
36
|
+
}
|
|
37
|
+
__name(toBase64, "toBase64");
|
|
38
|
+
function fromBase64(text) {
|
|
39
|
+
const binary = atob(text), bytes = new Uint8Array(binary.length);
|
|
40
|
+
for (let at = 0; at < binary.length; at += 1) bytes[at] = binary.charCodeAt(at);
|
|
41
|
+
return bytes;
|
|
42
|
+
}
|
|
43
|
+
__name(fromBase64, "fromBase64");
|
|
44
|
+
function parsedContext(json) {
|
|
45
|
+
const { revision, ...context } = JSON.parse(json);
|
|
46
|
+
if (typeof revision !== "number" || !Number.isSafeInteger(revision) || revision < 0) refused();
|
|
47
|
+
return { contextId: canonicalEndpointJson(context), context, revision };
|
|
48
|
+
}
|
|
49
|
+
__name(parsedContext, "parsedContext");
|
|
50
|
+
function createMlsBrowserCustody(options) {
|
|
51
|
+
const { engine, wrappingKey } = options;
|
|
52
|
+
const clock = options.clock ?? Date.now;
|
|
53
|
+
const issuerKeys = encoder.encode(JSON.stringify(options.issuerKeys)), receiptKeys = encoder.encode(JSON.stringify(options.receiptKeys));
|
|
54
|
+
const aad = /* @__PURE__ */ __name((purpose, context, binding) => encoder.encode(canonicalEndpointJson({ domain: AAD_DOMAIN, purpose, context, binding })), "aad");
|
|
55
|
+
async function wrap(key, additionalData, clear) {
|
|
56
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
57
|
+
const sealed = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-GCM", iv, additionalData }, key, clear));
|
|
58
|
+
const framed = new Uint8Array(12 + sealed.length);
|
|
59
|
+
framed.set(iv);
|
|
60
|
+
framed.set(sealed, 12);
|
|
61
|
+
return `v1:${toBase64(framed)}`;
|
|
62
|
+
}
|
|
63
|
+
__name(wrap, "wrap");
|
|
64
|
+
async function unwrap(key, additionalData, wrapped) {
|
|
65
|
+
if (!wrapped.startsWith("v1:")) refused();
|
|
66
|
+
const framed = fromBase64(wrapped.slice(3));
|
|
67
|
+
if (framed.length < 28) refused();
|
|
68
|
+
return new Uint8Array(await crypto.subtle.decrypt({ name: "AES-GCM", iv: framed.subarray(0, 12), additionalData }, key, framed.subarray(12)));
|
|
69
|
+
}
|
|
70
|
+
__name(unwrap, "unwrap");
|
|
71
|
+
function answer2(bytes) {
|
|
72
|
+
if (bytes.length < 4) refused();
|
|
73
|
+
const length = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getUint32(0);
|
|
74
|
+
if (length === 0) return { skew: decoder.decode(bytes.subarray(4)) };
|
|
75
|
+
if (length > MAX_PAYLOAD_BYTES || length > bytes.length - 4) refused();
|
|
76
|
+
return { payload: decoder.decode(bytes.subarray(4, 4 + length)), clear: bytes.slice(4 + length) };
|
|
77
|
+
}
|
|
78
|
+
__name(answer2, "answer");
|
|
79
|
+
async function finish(bytes, seal) {
|
|
80
|
+
try {
|
|
81
|
+
const result = answer2(bytes);
|
|
82
|
+
if ("skew" in result) return result.skew;
|
|
83
|
+
try {
|
|
84
|
+
return `{"wrappedState":${JSON.stringify(await seal(result.clear, result.payload))},"payload":${result.payload}}`;
|
|
85
|
+
} finally {
|
|
86
|
+
result.clear.fill(0);
|
|
87
|
+
}
|
|
88
|
+
} finally {
|
|
89
|
+
bytes.fill(0);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
__name(finish, "finish");
|
|
93
|
+
return Object.freeze({
|
|
94
|
+
async initializeDevSigning(contextJson) {
|
|
95
|
+
await wrappingKey(parsedContext(contextJson).contextId);
|
|
96
|
+
},
|
|
97
|
+
async prepareDevSigning(contextJson, commandJson, wrappedState) {
|
|
98
|
+
const { contextId, context, revision } = parsedContext(contextJson), key = await wrappingKey(contextId);
|
|
99
|
+
const clear = wrappedState === null ? void 0 : await unwrap(key, aad("identity", context, { revision }), wrappedState);
|
|
100
|
+
try {
|
|
101
|
+
const prepared2 = engine.prepare_signing(encoder.encode(contextJson), encoder.encode(commandJson), clear, clock());
|
|
102
|
+
return await finish(prepared2, (next) => wrap(key, aad("identity", context, { revision: revision + 1 }), next));
|
|
103
|
+
} finally {
|
|
104
|
+
clear?.fill(0);
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
async prepareDevKeyPackage(contextJson, commandJson, wrappedIdentityState) {
|
|
108
|
+
const { contextId, context, revision } = parsedContext(contextJson), key = await wrappingKey(contextId);
|
|
109
|
+
const identity2 = await unwrap(key, aad("identity", context, { revision }), wrappedIdentityState);
|
|
110
|
+
try {
|
|
111
|
+
const prepared2 = engine.prepare_key_package(encoder.encode(contextJson), encoder.encode(commandJson), identity2, issuerKeys, clock());
|
|
112
|
+
return await finish(prepared2, (next, payload) => {
|
|
113
|
+
const { keyPackageId, deviceId } = JSON.parse(payload);
|
|
114
|
+
return wrap(key, aad("key-package", context, { version: 1, keyPackageId, deviceId }), next);
|
|
115
|
+
});
|
|
116
|
+
} finally {
|
|
117
|
+
identity2.fill(0);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
async prepareDevGroup(identityContextJson, groupContextJson, commandJson, wrappedIdentityState, wrappedGroupState, wrappedKeyPackageState) {
|
|
121
|
+
const { contextId, context, revision } = parsedContext(identityContextJson), key = await wrappingKey(contextId);
|
|
122
|
+
const group = JSON.parse(groupContextJson);
|
|
123
|
+
const clear = [];
|
|
124
|
+
const open = /* @__PURE__ */ __name(async (additionalData, wrapped) => {
|
|
125
|
+
const opened = await unwrap(key, additionalData, wrapped);
|
|
126
|
+
clear.push(opened);
|
|
127
|
+
return opened;
|
|
128
|
+
}, "open");
|
|
129
|
+
try {
|
|
130
|
+
const identity2 = await open(aad("identity", context, { revision }), wrappedIdentityState);
|
|
131
|
+
const groupState = wrappedGroupState === null ? void 0 : await open(aad("group", context, group), wrappedGroupState);
|
|
132
|
+
let keyPackageState;
|
|
133
|
+
if (wrappedKeyPackageState !== null) {
|
|
134
|
+
const { keyPackageId } = JSON.parse(commandJson);
|
|
135
|
+
keyPackageState = await open(aad("key-package", context, { version: 1, keyPackageId, deviceId: group.deviceId }), wrappedKeyPackageState);
|
|
136
|
+
}
|
|
137
|
+
const prepared2 = engine.prepare_group(
|
|
138
|
+
encoder.encode(identityContextJson),
|
|
139
|
+
encoder.encode(groupContextJson),
|
|
140
|
+
encoder.encode(commandJson),
|
|
141
|
+
identity2,
|
|
142
|
+
groupState,
|
|
143
|
+
keyPackageState,
|
|
144
|
+
issuerKeys,
|
|
145
|
+
receiptKeys,
|
|
146
|
+
clock()
|
|
147
|
+
);
|
|
148
|
+
return await finish(prepared2, (next) => wrap(key, aad("group", context, { ...group, revision: group.revision + 1 }), next));
|
|
149
|
+
} finally {
|
|
150
|
+
clear.forEach((bytes) => bytes.fill(0));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
__name(createMlsBrowserCustody, "createMlsBrowserCustody");
|
|
156
|
+
|
|
157
|
+
// src/mls-wasm-host.ts
|
|
158
|
+
var NULL = Buffer.from('{"version":1,"ok":true,"value":null}');
|
|
159
|
+
var REJECTED = Buffer.from('{"version":1,"ok":false,"error":"MLS_NODE_CUSTODY_REJECTED"}');
|
|
160
|
+
var sha256 = /* @__PURE__ */ __name((bytes) => createHash("sha256").update(bytes).digest("hex"), "sha256");
|
|
161
|
+
var prepared = /* @__PURE__ */ __name((value) => Buffer.from(isMlsDevReceiptClockSkew(JSON.parse(value)) ? value : `{"version":1,"ok":true,"value":${value}}`), "prepared");
|
|
162
|
+
var configuration;
|
|
163
|
+
var custody;
|
|
164
|
+
var wrapping;
|
|
165
|
+
async function load() {
|
|
166
|
+
requireValue(existsSync(configuration.keyPath));
|
|
167
|
+
const bytes = keyFile(configuration.keyPath);
|
|
168
|
+
try {
|
|
169
|
+
return await crypto.subtle.importKey("raw", bytes, "AES-GCM", false, ["encrypt", "decrypt"]);
|
|
170
|
+
} finally {
|
|
171
|
+
bytes.fill(0);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
__name(load, "load");
|
|
175
|
+
async function configure(value) {
|
|
176
|
+
const wasm = readFileSync(value.wasmPath), glue = readFileSync(value.gluePath);
|
|
177
|
+
requireValue(sha256(wasm) === value.wasmSha256 && sha256(glue) === value.glueSha256);
|
|
178
|
+
const engine = await import(`data:text/javascript;base64,${glue.toString("base64")}`);
|
|
179
|
+
engine.initSync({ module: wasm });
|
|
180
|
+
configuration = value;
|
|
181
|
+
custody = createMlsBrowserCustody({
|
|
182
|
+
engine,
|
|
183
|
+
issuerKeys: value.issuerKeys,
|
|
184
|
+
receiptKeys: value.receiptKeys,
|
|
185
|
+
wrappingKey: /* @__PURE__ */ __name(() => wrapping ??= load().catch((error) => {
|
|
186
|
+
wrapping = void 0;
|
|
187
|
+
throw error;
|
|
188
|
+
}), "wrappingKey")
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
__name(configure, "configure");
|
|
192
|
+
var identity = /* @__PURE__ */ __name((value) => {
|
|
193
|
+
const { revision: _revision, ...device } = parseMlsDevDeviceContext(value);
|
|
194
|
+
return JSON.stringify(device);
|
|
195
|
+
}, "identity");
|
|
196
|
+
function own(value) {
|
|
197
|
+
requireValue(typeof value === "string" && configuration);
|
|
198
|
+
requireValue(identity(JSON.parse(value)) === identity({ ...configuration.context, revision: 0 }));
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
__name(own, "own");
|
|
202
|
+
async function answer(operation, values) {
|
|
203
|
+
if (operation === WASM_HOST_CONFIGURE) {
|
|
204
|
+
requireValue(!custody && values.length === 1);
|
|
205
|
+
await configure(JSON.parse(values[0]));
|
|
206
|
+
return NULL;
|
|
207
|
+
}
|
|
208
|
+
const context = own(values[0]);
|
|
209
|
+
if (operation === WASM_HOST_PROVISION) {
|
|
210
|
+
requireValue(values.length === 1 && !existsSync(configuration.keyPath));
|
|
211
|
+
keyFile(configuration.keyPath).fill(0);
|
|
212
|
+
return NULL;
|
|
213
|
+
}
|
|
214
|
+
if (operation === 1 && values.length === 1) {
|
|
215
|
+
await custody.initializeDevSigning(context);
|
|
216
|
+
return NULL;
|
|
217
|
+
}
|
|
218
|
+
if (operation === 2 && values.length === 3) return prepared(await custody.prepareDevSigning(context, values[1], values[2]));
|
|
219
|
+
if (operation === 3 && values.length === 3) return prepared(await custody.prepareDevKeyPackage(context, values[1], values[2]));
|
|
220
|
+
if (operation === 4 && values.length === 6) {
|
|
221
|
+
return prepared(await custody.prepareDevGroup(context, values[1], values[2], values[3], values[4], values[5]));
|
|
222
|
+
}
|
|
223
|
+
return rejected();
|
|
224
|
+
}
|
|
225
|
+
__name(answer, "answer");
|
|
226
|
+
async function* frames(input) {
|
|
227
|
+
let buffered = Buffer.alloc(0);
|
|
228
|
+
for await (const chunk of input) {
|
|
229
|
+
buffered = Buffer.concat([buffered, chunk]);
|
|
230
|
+
while (buffered.length >= 4) {
|
|
231
|
+
const length = buffered.readUInt32BE(0);
|
|
232
|
+
requireValue(length <= MAX_INPUT);
|
|
233
|
+
if (buffered.length < 4 + length) break;
|
|
234
|
+
yield buffered.subarray(4, 4 + length);
|
|
235
|
+
buffered = buffered.subarray(4 + length);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
__name(frames, "frames");
|
|
240
|
+
function send(message) {
|
|
241
|
+
const length = Buffer.alloc(4);
|
|
242
|
+
length.writeUInt32BE(message.length);
|
|
243
|
+
return new Promise((sent) => {
|
|
244
|
+
process.stdout.write(Buffer.concat([length, message]), () => sent());
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
__name(send, "send");
|
|
248
|
+
for (const signal of ["SIGINT", "SIGTERM", "SIGBREAK", "SIGHUP"]) process.on(signal, () => void 0);
|
|
249
|
+
for await (const message of frames(process.stdin)) {
|
|
250
|
+
try {
|
|
251
|
+
const { operation, values } = parseFrame(message);
|
|
252
|
+
await send(await answer(operation, values));
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (!custody || !(error instanceof NodeMlsDevCustodyError) && error.message !== "CANON_MLS_CUSTODY_REFUSED") process.exit(70);
|
|
255
|
+
await send(REJECTED);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
process.exit(0);
|
|
@@ -16,10 +16,23 @@ export declare const MLS_ENVIRONMENT_PINS: Readonly<Record<MlsEnvironmentId, {
|
|
|
16
16
|
}>>;
|
|
17
17
|
/**
|
|
18
18
|
* The custody helper this package ships for this host (`dist/mls/<platform>/canon-mls-custody`), checked against its
|
|
19
|
-
* pin, or undefined where it ships none: an Intel Mac, musl,
|
|
20
|
-
* file that is there but differs from its pin is refused.
|
|
19
|
+
* pin, or undefined where it ships none that runs: an Intel Mac, Windows, musl, an old glibc, or a build of this package
|
|
20
|
+
* without helpers. A file that is there but differs from its pin is refused.
|
|
21
21
|
*/
|
|
22
22
|
export declare function bundledMlsCustodyHelper(): {
|
|
23
23
|
path: string;
|
|
24
24
|
sha256: string;
|
|
25
25
|
} | undefined;
|
|
26
|
+
export interface BundledMlsWasmCore {
|
|
27
|
+
/** The process that runs the core (dist/mls-wasm-host.js). */
|
|
28
|
+
hostPath: string;
|
|
29
|
+
wasmPath: string;
|
|
30
|
+
wasmSha256: string;
|
|
31
|
+
gluePath: string;
|
|
32
|
+
glueSha256: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The WASM core this package ships for hosts with no helper (`dist/mls/wasm/`), checked against its pins, or undefined in a
|
|
36
|
+
* build of this package without it. A file that is there but differs from its pin is refused.
|
|
37
|
+
*/
|
|
38
|
+
export declare function bundledMlsWasmCore(): BundledMlsWasmCore | undefined;
|