@teechat/attested-mtls 0.1.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/README.md +30 -0
- package/attested_mtls.d.ts +54 -0
- package/attested_mtls.js +269 -0
- package/attested_mtls_bg.wasm +0 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# attested-mtls
|
|
2
|
+
|
|
3
|
+
Public Trusted Computing Base (TCB) for **attested mTLS** used by TeeChat:
|
|
4
|
+
|
|
5
|
+
- InferenceEngine (engine → gateway dial)
|
|
6
|
+
- TeaChat gateway (cert hash / pin helpers)
|
|
7
|
+
- OpenAPI edge (F′ privileged dial TLS identity)
|
|
8
|
+
- OPE clients (shared SPKI / cert digest helpers)
|
|
9
|
+
|
|
10
|
+
## Artifacts
|
|
11
|
+
|
|
12
|
+
| Artifact | Consumers |
|
|
13
|
+
|----------|-----------|
|
|
14
|
+
| `libattested_mtls.so` | Node (engine / gateway) via FFI |
|
|
15
|
+
| `@teechat/attested-mtls` (WASM) | Browser / Capacitor |
|
|
16
|
+
| Rust crate `attested-mtls` | OpenAPI, Tauri, native tools |
|
|
17
|
+
|
|
18
|
+
Crypto envelopes remain in [OPE](https://github.com/Lightec-AI/OPE). This crate owns TLS identity load, certificate digests/pins, and challenge-binding helpers — not OPE hybrid encryption.
|
|
19
|
+
|
|
20
|
+
## Develop
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
cargo test --workspace
|
|
24
|
+
cargo clippy --workspace -- -D warnings
|
|
25
|
+
cargo build -p attested-mtls-ffi --release
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## License
|
|
29
|
+
|
|
30
|
+
Apache-2.0
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* SHA-256 hex of certificate DER from PEM.
|
|
6
|
+
*/
|
|
7
|
+
export function attested_mtls_sha256_cert_pem(pem: string): string;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* SHA-256 hex of certificate SPKI DER from PEM.
|
|
11
|
+
*/
|
|
12
|
+
export function attested_mtls_spki_sha256_hex(pem: string): string;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Package / crate semver.
|
|
16
|
+
*/
|
|
17
|
+
export function attested_mtls_version(): string;
|
|
18
|
+
|
|
19
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
20
|
+
|
|
21
|
+
export interface InitOutput {
|
|
22
|
+
readonly memory: WebAssembly.Memory;
|
|
23
|
+
readonly attested_mtls_version: () => [number, number];
|
|
24
|
+
readonly attested_mtls_sha256_cert_pem: (a: number, b: number) => [number, number, number, number];
|
|
25
|
+
readonly attested_mtls_spki_sha256_hex: (a: number, b: number) => [number, number, number, number];
|
|
26
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
27
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
28
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
29
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
30
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
31
|
+
readonly __wbindgen_start: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
38
|
+
* a precompiled `WebAssembly.Module`.
|
|
39
|
+
*
|
|
40
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
41
|
+
*
|
|
42
|
+
* @returns {InitOutput}
|
|
43
|
+
*/
|
|
44
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
48
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
49
|
+
*
|
|
50
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
51
|
+
*
|
|
52
|
+
* @returns {Promise<InitOutput>}
|
|
53
|
+
*/
|
|
54
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/attested_mtls.js
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/* @ts-self-types="./attested_mtls.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SHA-256 hex of certificate DER from PEM.
|
|
5
|
+
* @param {string} pem
|
|
6
|
+
* @returns {string}
|
|
7
|
+
*/
|
|
8
|
+
export function attested_mtls_sha256_cert_pem(pem) {
|
|
9
|
+
let deferred3_0;
|
|
10
|
+
let deferred3_1;
|
|
11
|
+
try {
|
|
12
|
+
const ptr0 = passStringToWasm0(pem, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
13
|
+
const len0 = WASM_VECTOR_LEN;
|
|
14
|
+
const ret = wasm.attested_mtls_sha256_cert_pem(ptr0, len0);
|
|
15
|
+
var ptr2 = ret[0];
|
|
16
|
+
var len2 = ret[1];
|
|
17
|
+
if (ret[3]) {
|
|
18
|
+
ptr2 = 0; len2 = 0;
|
|
19
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
20
|
+
}
|
|
21
|
+
deferred3_0 = ptr2;
|
|
22
|
+
deferred3_1 = len2;
|
|
23
|
+
return getStringFromWasm0(ptr2, len2);
|
|
24
|
+
} finally {
|
|
25
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* SHA-256 hex of certificate SPKI DER from PEM.
|
|
31
|
+
* @param {string} pem
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
export function attested_mtls_spki_sha256_hex(pem) {
|
|
35
|
+
let deferred3_0;
|
|
36
|
+
let deferred3_1;
|
|
37
|
+
try {
|
|
38
|
+
const ptr0 = passStringToWasm0(pem, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
39
|
+
const len0 = WASM_VECTOR_LEN;
|
|
40
|
+
const ret = wasm.attested_mtls_spki_sha256_hex(ptr0, len0);
|
|
41
|
+
var ptr2 = ret[0];
|
|
42
|
+
var len2 = ret[1];
|
|
43
|
+
if (ret[3]) {
|
|
44
|
+
ptr2 = 0; len2 = 0;
|
|
45
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
46
|
+
}
|
|
47
|
+
deferred3_0 = ptr2;
|
|
48
|
+
deferred3_1 = len2;
|
|
49
|
+
return getStringFromWasm0(ptr2, len2);
|
|
50
|
+
} finally {
|
|
51
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Package / crate semver.
|
|
57
|
+
* @returns {string}
|
|
58
|
+
*/
|
|
59
|
+
export function attested_mtls_version() {
|
|
60
|
+
let deferred1_0;
|
|
61
|
+
let deferred1_1;
|
|
62
|
+
try {
|
|
63
|
+
const ret = wasm.attested_mtls_version();
|
|
64
|
+
deferred1_0 = ret[0];
|
|
65
|
+
deferred1_1 = ret[1];
|
|
66
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
67
|
+
} finally {
|
|
68
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function __wbg_get_imports() {
|
|
72
|
+
const import0 = {
|
|
73
|
+
__proto__: null,
|
|
74
|
+
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
75
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
76
|
+
return ret;
|
|
77
|
+
},
|
|
78
|
+
__wbindgen_init_externref_table: function() {
|
|
79
|
+
const table = wasm.__wbindgen_externrefs;
|
|
80
|
+
const offset = table.grow(4);
|
|
81
|
+
table.set(0, undefined);
|
|
82
|
+
table.set(offset + 0, undefined);
|
|
83
|
+
table.set(offset + 1, null);
|
|
84
|
+
table.set(offset + 2, true);
|
|
85
|
+
table.set(offset + 3, false);
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
return {
|
|
89
|
+
__proto__: null,
|
|
90
|
+
"./attested_mtls_bg.js": import0,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function getStringFromWasm0(ptr, len) {
|
|
95
|
+
return decodeText(ptr >>> 0, len);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let cachedUint8ArrayMemory0 = null;
|
|
99
|
+
function getUint8ArrayMemory0() {
|
|
100
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
101
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
102
|
+
}
|
|
103
|
+
return cachedUint8ArrayMemory0;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
107
|
+
if (realloc === undefined) {
|
|
108
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
109
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
110
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
111
|
+
WASM_VECTOR_LEN = buf.length;
|
|
112
|
+
return ptr;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
let len = arg.length;
|
|
116
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
117
|
+
|
|
118
|
+
const mem = getUint8ArrayMemory0();
|
|
119
|
+
|
|
120
|
+
let offset = 0;
|
|
121
|
+
|
|
122
|
+
for (; offset < len; offset++) {
|
|
123
|
+
const code = arg.charCodeAt(offset);
|
|
124
|
+
if (code > 0x7F) break;
|
|
125
|
+
mem[ptr + offset] = code;
|
|
126
|
+
}
|
|
127
|
+
if (offset !== len) {
|
|
128
|
+
if (offset !== 0) {
|
|
129
|
+
arg = arg.slice(offset);
|
|
130
|
+
}
|
|
131
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
132
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
133
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
134
|
+
|
|
135
|
+
offset += ret.written;
|
|
136
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
WASM_VECTOR_LEN = offset;
|
|
140
|
+
return ptr;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function takeFromExternrefTable0(idx) {
|
|
144
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
145
|
+
wasm.__externref_table_dealloc(idx);
|
|
146
|
+
return value;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
150
|
+
cachedTextDecoder.decode();
|
|
151
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
152
|
+
let numBytesDecoded = 0;
|
|
153
|
+
function decodeText(ptr, len) {
|
|
154
|
+
numBytesDecoded += len;
|
|
155
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
156
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
157
|
+
cachedTextDecoder.decode();
|
|
158
|
+
numBytesDecoded = len;
|
|
159
|
+
}
|
|
160
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const cachedTextEncoder = new TextEncoder();
|
|
164
|
+
|
|
165
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
166
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
167
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
168
|
+
view.set(buf);
|
|
169
|
+
return {
|
|
170
|
+
read: arg.length,
|
|
171
|
+
written: buf.length
|
|
172
|
+
};
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let WASM_VECTOR_LEN = 0;
|
|
177
|
+
|
|
178
|
+
let wasmModule, wasmInstance, wasm;
|
|
179
|
+
function __wbg_finalize_init(instance, module) {
|
|
180
|
+
wasmInstance = instance;
|
|
181
|
+
wasm = instance.exports;
|
|
182
|
+
wasmModule = module;
|
|
183
|
+
cachedUint8ArrayMemory0 = null;
|
|
184
|
+
wasm.__wbindgen_start();
|
|
185
|
+
return wasm;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function __wbg_load(module, imports) {
|
|
189
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
190
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
191
|
+
try {
|
|
192
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
193
|
+
} catch (e) {
|
|
194
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
195
|
+
|
|
196
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
197
|
+
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);
|
|
198
|
+
|
|
199
|
+
} else { throw e; }
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const bytes = await module.arrayBuffer();
|
|
204
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
205
|
+
} else {
|
|
206
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
207
|
+
|
|
208
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
209
|
+
return { instance, module };
|
|
210
|
+
} else {
|
|
211
|
+
return instance;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function expectedResponseType(type) {
|
|
216
|
+
switch (type) {
|
|
217
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
218
|
+
}
|
|
219
|
+
return false;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function initSync(module) {
|
|
224
|
+
if (wasm !== undefined) return wasm;
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if (module !== undefined) {
|
|
228
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
229
|
+
({module} = module)
|
|
230
|
+
} else {
|
|
231
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const imports = __wbg_get_imports();
|
|
236
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
237
|
+
module = new WebAssembly.Module(module);
|
|
238
|
+
}
|
|
239
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
240
|
+
return __wbg_finalize_init(instance, module);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
async function __wbg_init(module_or_path) {
|
|
244
|
+
if (wasm !== undefined) return wasm;
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
if (module_or_path !== undefined) {
|
|
248
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
249
|
+
({module_or_path} = module_or_path)
|
|
250
|
+
} else {
|
|
251
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (module_or_path === undefined) {
|
|
256
|
+
module_or_path = new URL('attested_mtls_bg.wasm', import.meta.url);
|
|
257
|
+
}
|
|
258
|
+
const imports = __wbg_get_imports();
|
|
259
|
+
|
|
260
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
261
|
+
module_or_path = fetch(module_or_path);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
265
|
+
|
|
266
|
+
return __wbg_finalize_init(instance, module);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@teechat/attested-mtls",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WASM bindings for attested-mtls (browser / Capacitor)",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/Lightec-AI/teechat-attested-mtls"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"attested_mtls_bg.wasm",
|
|
13
|
+
"attested_mtls.js",
|
|
14
|
+
"attested_mtls.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "attested_mtls.js",
|
|
17
|
+
"types": "attested_mtls.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|