diff --git a/pkg/LICENSE b/pkg/LICENSE new file mode 100644 index 00000000..9e841e7a --- /dev/null +++ b/pkg/LICENSE @@ -0,0 +1,21 @@ + MIT License + + Copyright (c) Microsoft Corporation. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE diff --git a/pkg/README.md b/pkg/README.md new file mode 100644 index 00000000..493c7be8 --- /dev/null +++ b/pkg/README.md @@ -0,0 +1,271 @@ +# Regorus + +**Regorus** is + + - *Rego*-*Rus(t)* - A fast, light-weight [Rego](https://www.openpolicyagent.org/docs/latest/policy-language/) + interpreter written in Rust. + - *Rigorous* - A rigorous enforcer of well-defined Rego semantics. + +Regorus is available as a library that can be easily integrated into your Rust projects. + +Here is an example of evaluating a simple Rego policy: + +```rust +use anyhow::Result; +use regorus::*; +use serde_json; + +fn main() -> Result<()> { + // Create an engine for evaluating Rego policies. + let mut engine = Engine::new(); + + // Add policy to the engine. + engine.add_policy( + // Filename to be associated with the policy. + "hello.rego".to_string(), + + // Rego policy that just sets a message. + r#" + package test + message = "Hello, World!" + "#.to_string() + )?; + + // Evaluate the policy, fetch the message and print it. + let results = engine.eval_query("data.test.message".to_string(), false)?; + println!("{}", serde_json::to_string_pretty(&results)?); + + Ok(()) +} +``` + +Regorus is designed with [Confidential Computing](https://confidentialcomputing.io/about/) in mind. In Confidential Computing environments, +it is important to be able to control exactly what is being run. Regorus allows enabling and disabling various components using cargo +features. By default all features are enabled. + +The default build of regorus example program is 6.4M: +```bash +$ cargo build -r --example regorus; strip target/release/examples/regorus; ls -lh target/release/examples/regorus +$ cargo build -r --example regorus; strip target/release/examples/regorus; ls -lh target/release/examples/regorus +-rwxr-xr-x 1 anand staff 6.4M Jan 19 11:23 target/release/examples/regorus* +``` + + +When all features except for `yaml` are disabled, the binary size drops down to 2.9M. +```bash +$ cargo build -r --example regorus --features "yaml" --no-default-features; strip target/release/examples/regorus; ls -lh target/release/examples/regorus +-rwxr-xr-x 1 anand staff 2.9M Jan 19 11:26 target/release/examples/regorus* +``` + + +Regorus passes the [OPA v0.60.0 test-suite](https://www.openpolicyagent.org/docs/latest/ir/#test-suite) barring a few +builtins. See [OPA Conformance](#opa-conformance) below. + +## Getting Started + +[examples/regorus](https://github.com/microsoft/regorus/blob/main/examples/regorus.rs) is an example program that +shows how to integrate Regorus into your project and evaluate Rego policies. + +To build and install it, do + +```bash +$ cargo install --example regorus --path . +``` + +Check that the regorus example program is working + +```bash +$ regorus +Usage: regorus + +Commands: + eval Evaluate a Rego Query + lex Tokenize a Rego policy + parse Parse a Rego policy + help Print this message or the help of the given subcommand(s) + +Options: + -h, --help Print help + -V, --version Print version +``` + + +First, let's evaluate a simple Rego expression `1*2+3` + +```bash +$ regorus eval "1*2+3" +``` + +This produces the following output + +```json +{ + "result": [ + { + "expressions": [ + { + "value": 5, + "text": "1*2+3", + "location": { + "row": 1, + "col": 1 + } + } + ] + } + ] +} +``` + +Next, evaluate a sample [policy](examples/example.rego) and [input](examples/input.json) +(borrowed from [Rego tutorial](https://www.openpolicyagent.org/docs/latest/#2-try-opa-eval)): + +```bash +$ regorus eval -d examples/example.rego -i examples/input.json data.example +``` + +Finally, evaluate real-world [policies](tests/aci/) used in Azure Container Instances (ACI) + +```bash +$ regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.policy.mount_overlay=x +``` + + +## ACI Policies + +Regorus successfully passes the ACI policy test-suite. It is fast and can run each of the tests in a few milliseconds. + +```bash +$ cargo test -r --test aci + Finished release [optimized + debuginfo] target(s) in 0.05s + Running tests/aci/main.rs (target/release/deps/aci-2cd8d21a893a2450) +aci/mount_device passed 3.863292ms +aci/mount_overlay passed 3.6905ms +aci/scratch_mount passed 3.643041ms +aci/create_container passed 5.046333ms +aci/shutdown_container passed 3.632ms +aci/scratch_unmount passed 3.631333ms +aci/unmount_overlay passed 3.609916ms +aci/unmount_device passed 3.626875ms +aci/load_fragment passed 4.045167ms +``` + +Run the ACI policies in the `tests/aci` directory, using data `tests/aci/data.json` and input `tests/aci/input.json`: + +```bash +$ regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.policy.mount_overlay=x +``` + +Verify that [OPA](https://github.com/open-policy-agent/opa/releases) produces the same output + +```bash +$ diff <(regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x) \ + <(opa eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x) +``` + + +## Performance + +To check how fast Regorus runs on your system, first install a tool like [hyperfine](https://github.com/sharkdp/hyperfine). + +```bash +$ cargo install hyperfine +``` + +Then benchmark evaluation of the ACI policies, + +```bash +$ hyperfine "regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x" +Benchmark 1: regorus eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x + Time (mean ± σ): 4.6 ms ± 0.2 ms [User: 4.1 ms, System: 0.4 ms] + Range (min … max): 4.4 ms … 6.0 ms 422 runs +``` + +Compare it with OPA + +```bash +$ hyperfine "opa eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x" +Benchmark 1: opa eval -b tests/aci -d tests/aci/data.json -i tests/aci/input.json data.framework.mount_overlay=x + Time (mean ± σ): 45.2 ms ± 0.6 ms [User: 68.8 ms, System: 5.1 ms] + Range (min … max): 43.8 ms … 46.7 ms 62 runs + +``` +## OPA Conformance + +Regorus has been verified to be compliant with [OPA v0.60.0](https://github.com/open-policy-agent/opa/releases/tag/v0.60.0) +using a [test driver](https://github.com/microsoft/regorus/blob/main/tests/opa.rs) that loads and runs the OPA testsuite using Regorus, and verifies that expected outputs +are produced. + +The test driver can be invoked by running: + +```bash +$ cargo test -r --test opa +``` + +Currently, Regorus passes all the non-builtin specific tests. +See [passing tests suites](https://github.com/microsoft/regorus/blob/main/tests/opa.passing). + +The following test suites don't pass fully due to mising builtins: +- `cryptoparsersaprivatekeys` +- `cryptox509parseandverifycertificates` +- `cryptox509parsecertificaterequest` +- `cryptox509parsecertificates` +- `cryptox509parsekeypair` +- `cryptox509parsersaprivatekey` +- `globsmatch` +- `graphql` +- `invalidkeyerror` +- `jsonpatch` +- `jwtbuiltins` +- `jwtdecodeverify` +- `jwtencodesign` +- `jwtencodesignraw` +- `jwtverifyhs256` +- `jwtverifyhs384` +- `jwtverifyhs512` +- `jwtverifyrsa` +- `netcidrcontains` +- `netcidrcontainsmatches` +- `netcidrexpand` +- `netcidrintersects` +- `netcidrisvalid` +- `netcidrmerge` +- `netcidroverlap` +- `netlookupipaddr` +- `providers-aws` +- `regometadatachain` +- `regometadatarule` +- `regoparsemodule` +- `rendertemplate` +- `time` + +They are captured in the following [github issues](https://github.com/microsoft/regorus/issues?q=is%3Aopen+is%3Aissue+label%3Alib). + + +### Grammar + +The grammar used by Regorus to parse Rego policies is described in [grammar.md](https://github.com/microsoft/regorus/blob/main/docs/grammar.md) +in both [W3C EBNF](https://www.w3.org/Notation.html) and [RailRoad Diagram](https://en.wikipedia.org/wiki/Syntax_diagram) formats. + + +## Contributing + +This project welcomes contributions and suggestions. Most contributions require you to agree to a +Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us +the rights to use your contribution. For details, visit . + +When you submit a pull request, a CLA bot will automatically determine whether you need to provide +a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions +provided by the bot. You will only need to do this once across all repos using our CLA. + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). +For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or +contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. + +## Trademarks + +This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft +trademarks or logos is subject to and must follow +[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). +Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. +Any use of third-party trademarks or logos are subject to those third-party's policies. diff --git a/pkg/package.json b/pkg/package.json new file mode 100644 index 00000000..4ead5bbe --- /dev/null +++ b/pkg/package.json @@ -0,0 +1,26 @@ +{ + "name": "regorus", + "description": "A fast, lightweight Rego (OPA policy language) interpreter", + "version": "0.1.0-alpha.2", + "license": "SEE LICENSE IN LICENSE", + "repository": { + "type": "git", + "url": "https://github.com/microsoft/regorus" + }, + "files": [ + "regorus_bg.wasm", + "regorus.js", + "regorus.d.ts" + ], + "module": "regorus.js", + "types": "regorus.d.ts", + "sideEffects": [ + "./snippets/*" + ], + "keywords": [ + "interpreter", + "opa", + "policy-as-code", + "rego" + ] +} \ No newline at end of file diff --git a/pkg/regorus.d.ts b/pkg/regorus.d.ts new file mode 100644 index 00000000..aa08b78e --- /dev/null +++ b/pkg/regorus.d.ts @@ -0,0 +1,71 @@ +/* tslint:disable */ +/* eslint-disable */ +/** +*/ +export class Engine { + free(): void; +/** +*/ + constructor(); +/** +* @returns {Engine} +*/ + clone_engine(): Engine; +/** +* @param {string} path +* @param {string} rego +*/ + add_policy(path: string, rego: string): void; +/** +* @param {string} data +*/ + add_data(data: string): void; +/** +* @param {string} input +*/ + set_input(input: string): void; +/** +* @param {string} query +* @returns {string} +*/ + eval_query(query: string): string; +} + +export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; + +export interface InitOutput { + readonly memory: WebAssembly.Memory; + readonly __wbg_engine_free: (a: number) => void; + readonly engine_new: () => number; + readonly engine_clone_engine: (a: number) => number; + readonly engine_add_policy: (a: number, b: number, c: number, d: number, e: number, f: number) => void; + readonly engine_add_data: (a: number, b: number, c: number, d: number) => void; + readonly engine_set_input: (a: number, b: number, c: number, d: number) => void; + readonly engine_eval_query: (a: number, b: number, c: number, d: number) => void; + readonly __wbindgen_add_to_stack_pointer: (a: number) => number; + readonly __wbindgen_malloc: (a: number, b: number) => number; + readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; + readonly __wbindgen_free: (a: number, b: number, c: number) => void; + readonly __wbindgen_exn_store: (a: number) => void; +} + +export type SyncInitInput = BufferSource | WebAssembly.Module; +/** +* Instantiates the given `module`, which can either be bytes or +* a precompiled `WebAssembly.Module`. +* +* @param {SyncInitInput} module +* +* @returns {InitOutput} +*/ +export function initSync(module: SyncInitInput): InitOutput; + +/** +* If `module_or_path` is {RequestInfo} or {URL}, makes a request and +* for everything else, calls `WebAssembly.instantiate` directly. +* +* @param {InitInput | Promise} module_or_path +* +* @returns {Promise} +*/ +export default function __wbg_init (module_or_path?: InitInput | Promise): Promise; diff --git a/pkg/regorus.js b/pkg/regorus.js new file mode 100644 index 00000000..f2c895fa --- /dev/null +++ b/pkg/regorus.js @@ -0,0 +1,471 @@ +let wasm; + +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +function getObject(idx) { return heap[idx]; } + +let heap_next = heap.length; + +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); + +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; + +let cachedUint8Memory0 = null; + +function getUint8Memory0() { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +} + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +let WASM_VECTOR_LEN = 0; + +const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); + +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}); + +function passStringToWasm0(arg, malloc, realloc) { + + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8Memory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +let cachedInt32Memory0 = null; + +function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + } + return cachedInt32Memory0; +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + wasm.__wbindgen_exn_store(addHeapObject(e)); + } +} +/** +*/ +export class Engine { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Engine.prototype); + obj.__wbg_ptr = ptr; + + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_engine_free(ptr); + } + /** + */ + constructor() { + const ret = wasm.engine_new(); + this.__wbg_ptr = ret >>> 0; + return this; + } + /** + * @returns {Engine} + */ + clone_engine() { + const ret = wasm.engine_clone_engine(this.__wbg_ptr); + return Engine.__wrap(ret); + } + /** + * @param {string} path + * @param {string} rego + */ + add_policy(path, rego) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(path, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + const ptr1 = passStringToWasm0(rego, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + wasm.engine_add_policy(retptr, this.__wbg_ptr, ptr0, len0, ptr1, len1); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + if (r1) { + throw takeObject(r0); + } + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {string} data + */ + add_data(data) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(data, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.engine_add_data(retptr, this.__wbg_ptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + if (r1) { + throw takeObject(r0); + } + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {string} input + */ + set_input(input) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.engine_set_input(retptr, this.__wbg_ptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + if (r1) { + throw takeObject(r0); + } + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {string} query + * @returns {string} + */ + eval_query(query) { + let deferred3_0; + let deferred3_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passStringToWasm0(query, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.engine_eval_query(retptr, this.__wbg_ptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + var ptr2 = r0; + var len2 = r1; + if (r3) { + ptr2 = 0; len2 = 0; + throw takeObject(r2); + } + deferred3_0 = ptr2; + deferred3_1 = len2; + return getStringFromWasm0(ptr2, len2); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred3_0, deferred3_1, 1); + } + } +} + +async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + + } catch (e) { + if (module.headers.get('Content-Type') != 'application/wasm') { + 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); + + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + + } else { + return instance; + } + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); + }; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_number_new = function(arg0) { + const ret = arg0; + return addHeapObject(ret); + }; + imports.wbg.__wbg_crypto_d05b68a3572bb8ca = function(arg0) { + const ret = getObject(arg0).crypto; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_object = function(arg0) { + const val = getObject(arg0); + const ret = typeof(val) === 'object' && val !== null; + return ret; + }; + imports.wbg.__wbg_process_b02b3570280d0366 = function(arg0) { + const ret = getObject(arg0).process; + return addHeapObject(ret); + }; + imports.wbg.__wbg_versions_c1cb42213cedf0f5 = function(arg0) { + const ret = getObject(arg0).versions; + return addHeapObject(ret); + }; + imports.wbg.__wbg_node_43b1089f407e4ec2 = function(arg0) { + const ret = getObject(arg0).node; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_string = function(arg0) { + const ret = typeof(getObject(arg0)) === 'string'; + return ret; + }; + imports.wbg.__wbg_msCrypto_10fc94afee92bd76 = function(arg0) { + const ret = getObject(arg0).msCrypto; + return addHeapObject(ret); + }; + imports.wbg.__wbg_require_9a7e0f667ead4995 = function() { return handleError(function () { + const ret = module.require; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbindgen_is_function = function(arg0) { + const ret = typeof(getObject(arg0)) === 'function'; + return ret; + }; + imports.wbg.__wbg_randomFillSync_b70ccbdf4926a99d = function() { return handleError(function (arg0, arg1) { + getObject(arg0).randomFillSync(takeObject(arg1)); + }, arguments) }; + imports.wbg.__wbg_getRandomValues_7e42b4fb8779dc6d = function() { return handleError(function (arg0, arg1) { + getObject(arg0).getRandomValues(getObject(arg1)); + }, arguments) }; + imports.wbg.__wbg_newnoargs_5859b6d41c6fe9f7 = function(arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_call_a79f1973a4f07d5e = function() { return handleError(function (arg0, arg1) { + const ret = getObject(arg0).call(getObject(arg1)); + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbindgen_object_clone_ref = function(arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_self_086b5302bcafb962 = function() { return handleError(function () { + const ret = self.self; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_window_132fa5d7546f1de5 = function() { return handleError(function () { + const ret = window.window; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_globalThis_e5f801a37ad7d07b = function() { return handleError(function () { + const ret = globalThis.globalThis; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_global_f9a61fce4af6b7c1 = function() { return handleError(function () { + const ret = global.global; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbindgen_is_undefined = function(arg0) { + const ret = getObject(arg0) === undefined; + return ret; + }; + imports.wbg.__wbg_call_f6a2bc58c19c53c6 = function() { return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_getTime_af7ca51c0bcefa08 = function(arg0) { + const ret = getObject(arg0).getTime(); + return ret; + }; + imports.wbg.__wbg_getTimezoneOffset_98604170efd7a383 = function(arg0) { + const ret = getObject(arg0).getTimezoneOffset(); + return ret; + }; + imports.wbg.__wbg_new_aaf6fa5a24e25a70 = function(arg0) { + const ret = new Date(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new0_c0e40662db0749ee = function() { + const ret = new Date(); + return addHeapObject(ret); + }; + imports.wbg.__wbg_buffer_5d1b598a01b41a42 = function(arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_d695c7957788f922 = function(arg0, arg1, arg2) { + const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_ace717933ad7117f = function(arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_74906aa30864df5a = function(arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); + }; + imports.wbg.__wbg_newwithlength_728575f3bba9959b = function(arg0) { + const ret = new Uint8Array(arg0 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_subarray_7f7a652672800851 = function(arg0, arg1, arg2) { + const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_memory = function() { + const ret = wasm.memory; + return addHeapObject(ret); + }; + + return imports; +} + +function __wbg_init_memory(imports, maybe_memory) { + +} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedInt32Memory0 = null; + cachedUint8Memory0 = null; + + + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + const imports = __wbg_get_imports(); + + __wbg_init_memory(imports); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(input) { + if (wasm !== undefined) return wasm; + + if (typeof input === 'undefined') { + input = new URL('regorus_bg.wasm', import.meta.url); + } + const imports = __wbg_get_imports(); + + if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { + input = fetch(input); + } + + __wbg_init_memory(imports); + + const { instance, module } = await __wbg_load(await input, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync } +export default __wbg_init; diff --git a/pkg/regorus_bg.wasm b/pkg/regorus_bg.wasm new file mode 100644 index 00000000..2f98e23e Binary files /dev/null and b/pkg/regorus_bg.wasm differ diff --git a/pkg/regorus_bg.wasm.d.ts b/pkg/regorus_bg.wasm.d.ts new file mode 100644 index 00000000..28e90737 --- /dev/null +++ b/pkg/regorus_bg.wasm.d.ts @@ -0,0 +1,15 @@ +/* tslint:disable */ +/* eslint-disable */ +export const memory: WebAssembly.Memory; +export function __wbg_engine_free(a: number): void; +export function engine_new(): number; +export function engine_clone_engine(a: number): number; +export function engine_add_policy(a: number, b: number, c: number, d: number, e: number, f: number): void; +export function engine_add_data(a: number, b: number, c: number, d: number): void; +export function engine_set_input(a: number, b: number, c: number, d: number): void; +export function engine_eval_query(a: number, b: number, c: number, d: number): void; +export function __wbindgen_add_to_stack_pointer(a: number): number; +export function __wbindgen_malloc(a: number, b: number): number; +export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; +export function __wbindgen_free(a: number, b: number, c: number): void; +export function __wbindgen_exn_store(a: number): void;