@enclave-e3/wasm 0.0.7-test
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/LICENSE.md +165 -0
- package/README.md +35 -0
- package/dist/nodejs/.gitignore +1 -0
- package/dist/nodejs/README.md +35 -0
- package/dist/nodejs/e3_wasm.d.ts +43 -0
- package/dist/nodejs/e3_wasm.js +321 -0
- package/dist/nodejs/e3_wasm_bg.wasm +0 -0
- package/dist/nodejs/e3_wasm_bg.wasm.d.ts +13 -0
- package/dist/nodejs/package.json +17 -0
- package/dist/web/.gitignore +1 -0
- package/dist/web/README.md +35 -0
- package/dist/web/e3_wasm.d.ts +80 -0
- package/dist/web/e3_wasm.js +385 -0
- package/dist/web/e3_wasm_bg.wasm +0 -0
- package/dist/web/e3_wasm_bg.wasm.d.ts +13 -0
- package/dist/web/package.json +21 -0
- package/package.json +60 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
GNU LESSER GENERAL PUBLIC LICENSE
|
|
2
|
+
Version 3, 29 June 2007
|
|
3
|
+
|
|
4
|
+
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
|
5
|
+
Everyone is permitted to copy and distribute verbatim copies
|
|
6
|
+
of this license document, but changing it is not allowed.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
This version of the GNU Lesser General Public License incorporates
|
|
10
|
+
the terms and conditions of version 3 of the GNU General Public
|
|
11
|
+
License, supplemented by the additional permissions listed below.
|
|
12
|
+
|
|
13
|
+
0. Additional Definitions.
|
|
14
|
+
|
|
15
|
+
As used herein, "this License" refers to version 3 of the GNU Lesser
|
|
16
|
+
General Public License, and the "GNU GPL" refers to version 3 of the GNU
|
|
17
|
+
General Public License.
|
|
18
|
+
|
|
19
|
+
"The Library" refers to a covered work governed by this License,
|
|
20
|
+
other than an Application or a Combined Work as defined below.
|
|
21
|
+
|
|
22
|
+
An "Application" is any work that makes use of an interface provided
|
|
23
|
+
by the Library, but which is not otherwise based on the Library.
|
|
24
|
+
Defining a subclass of a class defined by the Library is deemed a mode
|
|
25
|
+
of using an interface provided by the Library.
|
|
26
|
+
|
|
27
|
+
A "Combined Work" is a work produced by combining or linking an
|
|
28
|
+
Application with the Library. The particular version of the Library
|
|
29
|
+
with which the Combined Work was made is also called the "Linked
|
|
30
|
+
Version".
|
|
31
|
+
|
|
32
|
+
The "Minimal Corresponding Source" for a Combined Work means the
|
|
33
|
+
Corresponding Source for the Combined Work, excluding any source code
|
|
34
|
+
for portions of the Combined Work that, considered in isolation, are
|
|
35
|
+
based on the Application, and not on the Linked Version.
|
|
36
|
+
|
|
37
|
+
The "Corresponding Application Code" for a Combined Work means the
|
|
38
|
+
object code and/or source code for the Application, including any data
|
|
39
|
+
and utility programs needed for reproducing the Combined Work from the
|
|
40
|
+
Application, but excluding the System Libraries of the Combined Work.
|
|
41
|
+
|
|
42
|
+
1. Exception to Section 3 of the GNU GPL.
|
|
43
|
+
|
|
44
|
+
You may convey a covered work under sections 3 and 4 of this License
|
|
45
|
+
without being bound by section 3 of the GNU GPL.
|
|
46
|
+
|
|
47
|
+
2. Conveying Modified Versions.
|
|
48
|
+
|
|
49
|
+
If you modify a copy of the Library, and, in your modifications, a
|
|
50
|
+
facility refers to a function or data to be supplied by an Application
|
|
51
|
+
that uses the facility (other than as an argument passed when the
|
|
52
|
+
facility is invoked), then you may convey a copy of the modified
|
|
53
|
+
version:
|
|
54
|
+
|
|
55
|
+
a) under this License, provided that you make a good faith effort to
|
|
56
|
+
ensure that, in the event an Application does not supply the
|
|
57
|
+
function or data, the facility still operates, and performs
|
|
58
|
+
whatever part of its purpose remains meaningful, or
|
|
59
|
+
|
|
60
|
+
b) under the GNU GPL, with none of the additional permissions of
|
|
61
|
+
this License applicable to that copy.
|
|
62
|
+
|
|
63
|
+
3. Object Code Incorporating Material from Library Header Files.
|
|
64
|
+
|
|
65
|
+
The object code form of an Application may incorporate material from
|
|
66
|
+
a header file that is part of the Library. You may convey such object
|
|
67
|
+
code under terms of your choice, provided that, if the incorporated
|
|
68
|
+
material is not limited to numerical parameters, data structure
|
|
69
|
+
layouts and accessors, or small macros, inline functions and templates
|
|
70
|
+
(ten or fewer lines in length), you do both of the following:
|
|
71
|
+
|
|
72
|
+
a) Give prominent notice with each copy of the object code that the
|
|
73
|
+
Library is used in it and that the Library and its use are
|
|
74
|
+
covered by this License.
|
|
75
|
+
|
|
76
|
+
b) Accompany the object code with a copy of the GNU GPL and this license
|
|
77
|
+
document.
|
|
78
|
+
|
|
79
|
+
4. Combined Works.
|
|
80
|
+
|
|
81
|
+
You may convey a Combined Work under terms of your choice that,
|
|
82
|
+
taken together, effectively do not restrict modification of the
|
|
83
|
+
portions of the Library contained in the Combined Work and reverse
|
|
84
|
+
engineering for debugging such modifications, if you also do each of
|
|
85
|
+
the following:
|
|
86
|
+
|
|
87
|
+
a) Give prominent notice with each copy of the Combined Work that
|
|
88
|
+
the Library is used in it and that the Library and its use are
|
|
89
|
+
covered by this License.
|
|
90
|
+
|
|
91
|
+
b) Accompany the Combined Work with a copy of the GNU GPL and this license
|
|
92
|
+
document.
|
|
93
|
+
|
|
94
|
+
c) For a Combined Work that displays copyright notices during
|
|
95
|
+
execution, include the copyright notice for the Library among
|
|
96
|
+
these notices, as well as a reference directing the user to the
|
|
97
|
+
copies of the GNU GPL and this license document.
|
|
98
|
+
|
|
99
|
+
d) Do one of the following:
|
|
100
|
+
|
|
101
|
+
0) Convey the Minimal Corresponding Source under the terms of this
|
|
102
|
+
License, and the Corresponding Application Code in a form
|
|
103
|
+
suitable for, and under terms that permit, the user to
|
|
104
|
+
recombine or relink the Application with a modified version of
|
|
105
|
+
the Linked Version to produce a modified Combined Work, in the
|
|
106
|
+
manner specified by section 6 of the GNU GPL for conveying
|
|
107
|
+
Corresponding Source.
|
|
108
|
+
|
|
109
|
+
1) Use a suitable shared library mechanism for linking with the
|
|
110
|
+
Library. A suitable mechanism is one that (a) uses at run time
|
|
111
|
+
a copy of the Library already present on the user's computer
|
|
112
|
+
system, and (b) will operate properly with a modified version
|
|
113
|
+
of the Library that is interface-compatible with the Linked
|
|
114
|
+
Version.
|
|
115
|
+
|
|
116
|
+
e) Provide Installation Information, but only if you would otherwise
|
|
117
|
+
be required to provide such information under section 6 of the
|
|
118
|
+
GNU GPL, and only to the extent that such information is
|
|
119
|
+
necessary to install and execute a modified version of the
|
|
120
|
+
Combined Work produced by recombining or relinking the
|
|
121
|
+
Application with a modified version of the Linked Version. (If
|
|
122
|
+
you use option 4d0, the Installation Information must accompany
|
|
123
|
+
the Minimal Corresponding Source and Corresponding Application
|
|
124
|
+
Code. If you use option 4d1, you must provide the Installation
|
|
125
|
+
Information in the manner specified by section 6 of the GNU GPL
|
|
126
|
+
for conveying Corresponding Source.)
|
|
127
|
+
|
|
128
|
+
5. Combined Libraries.
|
|
129
|
+
|
|
130
|
+
You may place library facilities that are a work based on the
|
|
131
|
+
Library side by side in a single library together with other library
|
|
132
|
+
facilities that are not Applications and are not covered by this
|
|
133
|
+
License, and convey such a combined library under terms of your
|
|
134
|
+
choice, if you do both of the following:
|
|
135
|
+
|
|
136
|
+
a) Accompany the combined library with a copy of the same work based
|
|
137
|
+
on the Library, uncombined with any other library facilities,
|
|
138
|
+
conveyed under the terms of this License.
|
|
139
|
+
|
|
140
|
+
b) Give prominent notice with the combined library that part of it
|
|
141
|
+
is a work based on the Library, and explaining where to find the
|
|
142
|
+
accompanying uncombined form of the same work.
|
|
143
|
+
|
|
144
|
+
6. Revised Versions of the GNU Lesser General Public License.
|
|
145
|
+
|
|
146
|
+
The Free Software Foundation may publish revised and/or new versions
|
|
147
|
+
of the GNU Lesser General Public License from time to time. Such new
|
|
148
|
+
versions will be similar in spirit to the present version, but may
|
|
149
|
+
differ in detail to address new problems or concerns.
|
|
150
|
+
|
|
151
|
+
Each version is given a distinguishing version number. If the
|
|
152
|
+
Library as you received it specifies that a certain numbered version
|
|
153
|
+
of the GNU Lesser General Public License "or any later version"
|
|
154
|
+
applies to it, you have the option of following the terms and
|
|
155
|
+
conditions either of that published version or of any later version
|
|
156
|
+
published by the Free Software Foundation. If the Library as you
|
|
157
|
+
received it does not specify a version number of the GNU Lesser
|
|
158
|
+
General Public License, you may choose any version of the GNU Lesser
|
|
159
|
+
General Public License ever published by the Free Software Foundation.
|
|
160
|
+
|
|
161
|
+
If the Library as you received it specifies that a proxy can decide
|
|
162
|
+
whether future versions of the GNU Lesser General Public License shall
|
|
163
|
+
apply, that proxy's public statement of acceptance of any version is
|
|
164
|
+
permanent authorization for you to choose that version for the
|
|
165
|
+
Library.
|
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Wasm bundle for enclave
|
|
2
|
+
|
|
3
|
+
Here we export wasm funcionality for consumption in typescript to enable use to share code between Rust and Typescript.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
This package exposes an `init` subpackage default function which should be used to universally load the wasm module instead of exporting the default loader.
|
|
8
|
+
|
|
9
|
+
This is because in modern node there is no need for preloading however in the browser we still need to load the wasm bundle.
|
|
10
|
+
|
|
11
|
+
##### ❌ DONT USE THE DEFAULT INIT
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// Bad! Because this uses the raw loader which doesn't exist in node contexts
|
|
15
|
+
import init, { bfvEncryptNumber } from "@enclave-e3/wasm";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
##### ✅ DO USE THE EXPORTED SUBMODULE
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// Good! Use the universal loader
|
|
22
|
+
import init from "@enclave-e3/wasm/init";
|
|
23
|
+
import { bfvEncryptNumber } from "@enclave-e3/wasm";
|
|
24
|
+
|
|
25
|
+
export async function bfvEncryptNumber(
|
|
26
|
+
data: bigint,
|
|
27
|
+
public_key: Uint8Array,
|
|
28
|
+
degree: number,
|
|
29
|
+
plaintext_modulus: bigint,
|
|
30
|
+
moduli: bigint,
|
|
31
|
+
): Promise<Uint8Array> {
|
|
32
|
+
await init();
|
|
33
|
+
return bfv_encrypt_number(data, public_key, degree, plaintext_modulus, moduli);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Wasm bundle for enclave
|
|
2
|
+
|
|
3
|
+
Here we export wasm funcionality for consumption in typescript to enable use to share code between Rust and Typescript.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
This package exposes an `init` subpackage default function which should be used to universally load the wasm module instead of exporting the default loader.
|
|
8
|
+
|
|
9
|
+
This is because in modern node there is no need for preloading however in the browser we still need to load the wasm bundle.
|
|
10
|
+
|
|
11
|
+
##### ❌ DONT USE THE DEFAULT INIT
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// Bad! Because this uses the raw loader which doesn't exist in node contexts
|
|
15
|
+
import init, { bfvEncryptNumber } from "@enclave-e3/wasm";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
##### ✅ DO USE THE EXPORTED SUBMODULE
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// Good! Use the universal loader
|
|
22
|
+
import init from "@enclave-e3/wasm/init";
|
|
23
|
+
import { bfvEncryptNumber } from "@enclave-e3/wasm";
|
|
24
|
+
|
|
25
|
+
export async function bfvEncryptNumber(
|
|
26
|
+
data: bigint,
|
|
27
|
+
public_key: Uint8Array,
|
|
28
|
+
degree: number,
|
|
29
|
+
plaintext_modulus: bigint,
|
|
30
|
+
moduli: bigint,
|
|
31
|
+
): Promise<Uint8Array> {
|
|
32
|
+
await init();
|
|
33
|
+
return bfv_encrypt_number(data, public_key, degree, plaintext_modulus, moduli);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* A function to encrypt a u64 value using BFV and default params.
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
*
|
|
8
|
+
* * `data` - The data to encrypt - must be a u64
|
|
9
|
+
* * `public_key` - The public key to be used for encryption
|
|
10
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
11
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
12
|
+
* * `moduli` - Modulus for BFV parameters
|
|
13
|
+
*
|
|
14
|
+
* # Returns
|
|
15
|
+
*
|
|
16
|
+
* Returns a `Result<Vec<u8>, JsValue>` containing the encrypted data and any errors.
|
|
17
|
+
*
|
|
18
|
+
* # Panics
|
|
19
|
+
*
|
|
20
|
+
* Panics if the data cannot be encrypted
|
|
21
|
+
*/
|
|
22
|
+
export function bfv_encrypt_number(data: bigint, public_key: Uint8Array, degree: number, plaintext_modulus: bigint, moduli: bigint): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* A function to encrypt a u64 value using BFV and default params and
|
|
25
|
+
* generate circuit inputs for Greco
|
|
26
|
+
*
|
|
27
|
+
* # Arguments
|
|
28
|
+
*
|
|
29
|
+
* * `data` - The data to encrypt - must be a u64
|
|
30
|
+
* * `public_key` - The public key to be used for encryption
|
|
31
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
32
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
33
|
+
* * `moduli` - Modulus for BFV parameters
|
|
34
|
+
*
|
|
35
|
+
* # Returns
|
|
36
|
+
*
|
|
37
|
+
* Returns a `Result<Vec<JsValue>, JsValue>` containing the encrypted data, circuit inputs and any errors.
|
|
38
|
+
*
|
|
39
|
+
* # Panics
|
|
40
|
+
*
|
|
41
|
+
* Panics if the data cannot be encrypted
|
|
42
|
+
*/
|
|
43
|
+
export function bfv_verifiable_encrypt_number(data: bigint, public_key: Uint8Array, degree: number, plaintext_modulus: bigint, moduli: bigint): any[];
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
|
|
2
|
+
let imports = {};
|
|
3
|
+
imports['__wbindgen_placeholder__'] = module.exports;
|
|
4
|
+
let wasm;
|
|
5
|
+
const { TextDecoder } = require(`util`);
|
|
6
|
+
|
|
7
|
+
function addToExternrefTable0(obj) {
|
|
8
|
+
const idx = wasm.__externref_table_alloc();
|
|
9
|
+
wasm.__wbindgen_export_2.set(idx, obj);
|
|
10
|
+
return idx;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function handleError(f, args) {
|
|
14
|
+
try {
|
|
15
|
+
return f.apply(this, args);
|
|
16
|
+
} catch (e) {
|
|
17
|
+
const idx = addToExternrefTable0(e);
|
|
18
|
+
wasm.__wbindgen_exn_store(idx);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
23
|
+
|
|
24
|
+
cachedTextDecoder.decode();
|
|
25
|
+
|
|
26
|
+
let cachedUint8ArrayMemory0 = null;
|
|
27
|
+
|
|
28
|
+
function getUint8ArrayMemory0() {
|
|
29
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
30
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
31
|
+
}
|
|
32
|
+
return cachedUint8ArrayMemory0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getStringFromWasm0(ptr, len) {
|
|
36
|
+
ptr = ptr >>> 0;
|
|
37
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isLikeNone(x) {
|
|
41
|
+
return x === undefined || x === null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
45
|
+
ptr = ptr >>> 0;
|
|
46
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let WASM_VECTOR_LEN = 0;
|
|
50
|
+
|
|
51
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
52
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
53
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
54
|
+
WASM_VECTOR_LEN = arg.length;
|
|
55
|
+
return ptr;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function takeFromExternrefTable0(idx) {
|
|
59
|
+
const value = wasm.__wbindgen_export_2.get(idx);
|
|
60
|
+
wasm.__externref_table_dealloc(idx);
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* A function to encrypt a u64 value using BFV and default params.
|
|
65
|
+
*
|
|
66
|
+
* # Arguments
|
|
67
|
+
*
|
|
68
|
+
* * `data` - The data to encrypt - must be a u64
|
|
69
|
+
* * `public_key` - The public key to be used for encryption
|
|
70
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
71
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
72
|
+
* * `moduli` - Modulus for BFV parameters
|
|
73
|
+
*
|
|
74
|
+
* # Returns
|
|
75
|
+
*
|
|
76
|
+
* Returns a `Result<Vec<u8>, JsValue>` containing the encrypted data and any errors.
|
|
77
|
+
*
|
|
78
|
+
* # Panics
|
|
79
|
+
*
|
|
80
|
+
* Panics if the data cannot be encrypted
|
|
81
|
+
* @param {bigint} data
|
|
82
|
+
* @param {Uint8Array} public_key
|
|
83
|
+
* @param {number} degree
|
|
84
|
+
* @param {bigint} plaintext_modulus
|
|
85
|
+
* @param {bigint} moduli
|
|
86
|
+
* @returns {Uint8Array}
|
|
87
|
+
*/
|
|
88
|
+
module.exports.bfv_encrypt_number = function(data, public_key, degree, plaintext_modulus, moduli) {
|
|
89
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
90
|
+
const len0 = WASM_VECTOR_LEN;
|
|
91
|
+
const ret = wasm.bfv_encrypt_number(data, ptr0, len0, degree, plaintext_modulus, moduli);
|
|
92
|
+
if (ret[3]) {
|
|
93
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
94
|
+
}
|
|
95
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
96
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
97
|
+
return v2;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
let cachedDataViewMemory0 = null;
|
|
101
|
+
|
|
102
|
+
function getDataViewMemory0() {
|
|
103
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
104
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
105
|
+
}
|
|
106
|
+
return cachedDataViewMemory0;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
110
|
+
ptr = ptr >>> 0;
|
|
111
|
+
const mem = getDataViewMemory0();
|
|
112
|
+
const result = [];
|
|
113
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
114
|
+
result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
|
|
115
|
+
}
|
|
116
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
117
|
+
return result;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A function to encrypt a u64 value using BFV and default params and
|
|
121
|
+
* generate circuit inputs for Greco
|
|
122
|
+
*
|
|
123
|
+
* # Arguments
|
|
124
|
+
*
|
|
125
|
+
* * `data` - The data to encrypt - must be a u64
|
|
126
|
+
* * `public_key` - The public key to be used for encryption
|
|
127
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
128
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
129
|
+
* * `moduli` - Modulus for BFV parameters
|
|
130
|
+
*
|
|
131
|
+
* # Returns
|
|
132
|
+
*
|
|
133
|
+
* Returns a `Result<Vec<JsValue>, JsValue>` containing the encrypted data, circuit inputs and any errors.
|
|
134
|
+
*
|
|
135
|
+
* # Panics
|
|
136
|
+
*
|
|
137
|
+
* Panics if the data cannot be encrypted
|
|
138
|
+
* @param {bigint} data
|
|
139
|
+
* @param {Uint8Array} public_key
|
|
140
|
+
* @param {number} degree
|
|
141
|
+
* @param {bigint} plaintext_modulus
|
|
142
|
+
* @param {bigint} moduli
|
|
143
|
+
* @returns {any[]}
|
|
144
|
+
*/
|
|
145
|
+
module.exports.bfv_verifiable_encrypt_number = function(data, public_key, degree, plaintext_modulus, moduli) {
|
|
146
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
147
|
+
const len0 = WASM_VECTOR_LEN;
|
|
148
|
+
const ret = wasm.bfv_verifiable_encrypt_number(data, ptr0, len0, degree, plaintext_modulus, moduli);
|
|
149
|
+
if (ret[3]) {
|
|
150
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
151
|
+
}
|
|
152
|
+
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
153
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
154
|
+
return v2;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
module.exports.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
|
|
158
|
+
const ret = arg0.buffer;
|
|
159
|
+
return ret;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
module.exports.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
|
|
163
|
+
const ret = arg0.call(arg1);
|
|
164
|
+
return ret;
|
|
165
|
+
}, arguments) };
|
|
166
|
+
|
|
167
|
+
module.exports.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
168
|
+
const ret = arg0.call(arg1, arg2);
|
|
169
|
+
return ret;
|
|
170
|
+
}, arguments) };
|
|
171
|
+
|
|
172
|
+
module.exports.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
|
|
173
|
+
const ret = arg0.crypto;
|
|
174
|
+
return ret;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
module.exports.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
|
|
178
|
+
arg0.getRandomValues(arg1);
|
|
179
|
+
}, arguments) };
|
|
180
|
+
|
|
181
|
+
module.exports.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
|
|
182
|
+
const ret = arg0.msCrypto;
|
|
183
|
+
return ret;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
module.exports.__wbg_new_a12002a7f91c75be = function(arg0) {
|
|
187
|
+
const ret = new Uint8Array(arg0);
|
|
188
|
+
return ret;
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
module.exports.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
|
|
192
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
193
|
+
return ret;
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
module.exports.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
|
|
197
|
+
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
198
|
+
return ret;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
module.exports.__wbg_newwithlength_a381634e90c276d4 = function(arg0) {
|
|
202
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
203
|
+
return ret;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
module.exports.__wbg_node_905d3e251edff8a2 = function(arg0) {
|
|
207
|
+
const ret = arg0.node;
|
|
208
|
+
return ret;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
module.exports.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
|
|
212
|
+
const ret = arg0.process;
|
|
213
|
+
return ret;
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
module.exports.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
|
|
217
|
+
arg0.randomFillSync(arg1);
|
|
218
|
+
}, arguments) };
|
|
219
|
+
|
|
220
|
+
module.exports.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
|
|
221
|
+
const ret = module.require;
|
|
222
|
+
return ret;
|
|
223
|
+
}, arguments) };
|
|
224
|
+
|
|
225
|
+
module.exports.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
|
|
226
|
+
arg0.set(arg1, arg2 >>> 0);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
module.exports.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
|
|
230
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
231
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
module.exports.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
|
|
235
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
236
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
module.exports.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
|
|
240
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
241
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
module.exports.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
|
|
245
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
246
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
module.exports.__wbg_subarray_aa9065fa9dc5df96 = function(arg0, arg1, arg2) {
|
|
250
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
251
|
+
return ret;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
module.exports.__wbg_versions_c01dfd4722a88165 = function(arg0) {
|
|
255
|
+
const ret = arg0.versions;
|
|
256
|
+
return ret;
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
module.exports.__wbindgen_init_externref_table = function() {
|
|
260
|
+
const table = wasm.__wbindgen_export_2;
|
|
261
|
+
const offset = table.grow(4);
|
|
262
|
+
table.set(0, undefined);
|
|
263
|
+
table.set(offset + 0, undefined);
|
|
264
|
+
table.set(offset + 1, null);
|
|
265
|
+
table.set(offset + 2, true);
|
|
266
|
+
table.set(offset + 3, false);
|
|
267
|
+
;
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
module.exports.__wbindgen_is_function = function(arg0) {
|
|
271
|
+
const ret = typeof(arg0) === 'function';
|
|
272
|
+
return ret;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
module.exports.__wbindgen_is_object = function(arg0) {
|
|
276
|
+
const val = arg0;
|
|
277
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
278
|
+
return ret;
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
module.exports.__wbindgen_is_string = function(arg0) {
|
|
282
|
+
const ret = typeof(arg0) === 'string';
|
|
283
|
+
return ret;
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
module.exports.__wbindgen_is_undefined = function(arg0) {
|
|
287
|
+
const ret = arg0 === undefined;
|
|
288
|
+
return ret;
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
module.exports.__wbindgen_memory = function() {
|
|
292
|
+
const ret = wasm.memory;
|
|
293
|
+
return ret;
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
module.exports.__wbindgen_string_new = function(arg0, arg1) {
|
|
297
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
298
|
+
return ret;
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
302
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
module.exports.__wbindgen_uint8_array_new = function(arg0, arg1) {
|
|
306
|
+
var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
|
|
307
|
+
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
|
|
308
|
+
const ret = v0;
|
|
309
|
+
return ret;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const path = require('path').join(__dirname, 'e3_wasm_bg.wasm');
|
|
313
|
+
const bytes = require('fs').readFileSync(path);
|
|
314
|
+
|
|
315
|
+
const wasmModule = new WebAssembly.Module(bytes);
|
|
316
|
+
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
317
|
+
wasm = wasmInstance.exports;
|
|
318
|
+
module.exports.__wasm = wasm;
|
|
319
|
+
|
|
320
|
+
wasm.__wbindgen_start();
|
|
321
|
+
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const bfv_encrypt_number: (a: bigint, b: number, c: number, d: number, e: bigint, f: bigint) => [number, number, number, number];
|
|
5
|
+
export const bfv_verifiable_encrypt_number: (a: bigint, b: number, c: number, d: number, e: bigint, f: bigint) => [number, number, number, number];
|
|
6
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
7
|
+
export const __externref_table_alloc: () => number;
|
|
8
|
+
export const __wbindgen_export_2: WebAssembly.Table;
|
|
9
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
10
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
11
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
12
|
+
export const __externref_drop_slice: (a: number, b: number) => void;
|
|
13
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "e3-wasm",
|
|
3
|
+
"description": "E3 — Encrypted Execution Environments",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"license": "LGPL-3.0-only",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/gnosisguild/enclave"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"e3_wasm_bg.wasm",
|
|
12
|
+
"e3_wasm.js",
|
|
13
|
+
"e3_wasm.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"main": "e3_wasm.js",
|
|
16
|
+
"types": "e3_wasm.d.ts"
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Wasm bundle for enclave
|
|
2
|
+
|
|
3
|
+
Here we export wasm funcionality for consumption in typescript to enable use to share code between Rust and Typescript.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
This package exposes an `init` subpackage default function which should be used to universally load the wasm module instead of exporting the default loader.
|
|
8
|
+
|
|
9
|
+
This is because in modern node there is no need for preloading however in the browser we still need to load the wasm bundle.
|
|
10
|
+
|
|
11
|
+
##### ❌ DONT USE THE DEFAULT INIT
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
// Bad! Because this uses the raw loader which doesn't exist in node contexts
|
|
15
|
+
import init, { bfvEncryptNumber } from "@enclave-e3/wasm";
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
##### ✅ DO USE THE EXPORTED SUBMODULE
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// Good! Use the universal loader
|
|
22
|
+
import init from "@enclave-e3/wasm/init";
|
|
23
|
+
import { bfvEncryptNumber } from "@enclave-e3/wasm";
|
|
24
|
+
|
|
25
|
+
export async function bfvEncryptNumber(
|
|
26
|
+
data: bigint,
|
|
27
|
+
public_key: Uint8Array,
|
|
28
|
+
degree: number,
|
|
29
|
+
plaintext_modulus: bigint,
|
|
30
|
+
moduli: bigint,
|
|
31
|
+
): Promise<Uint8Array> {
|
|
32
|
+
await init();
|
|
33
|
+
return bfv_encrypt_number(data, public_key, degree, plaintext_modulus, moduli);
|
|
34
|
+
}
|
|
35
|
+
```
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* A function to encrypt a u64 value using BFV and default params.
|
|
5
|
+
*
|
|
6
|
+
* # Arguments
|
|
7
|
+
*
|
|
8
|
+
* * `data` - The data to encrypt - must be a u64
|
|
9
|
+
* * `public_key` - The public key to be used for encryption
|
|
10
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
11
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
12
|
+
* * `moduli` - Modulus for BFV parameters
|
|
13
|
+
*
|
|
14
|
+
* # Returns
|
|
15
|
+
*
|
|
16
|
+
* Returns a `Result<Vec<u8>, JsValue>` containing the encrypted data and any errors.
|
|
17
|
+
*
|
|
18
|
+
* # Panics
|
|
19
|
+
*
|
|
20
|
+
* Panics if the data cannot be encrypted
|
|
21
|
+
*/
|
|
22
|
+
export function bfv_encrypt_number(data: bigint, public_key: Uint8Array, degree: number, plaintext_modulus: bigint, moduli: bigint): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* A function to encrypt a u64 value using BFV and default params and
|
|
25
|
+
* generate circuit inputs for Greco
|
|
26
|
+
*
|
|
27
|
+
* # Arguments
|
|
28
|
+
*
|
|
29
|
+
* * `data` - The data to encrypt - must be a u64
|
|
30
|
+
* * `public_key` - The public key to be used for encryption
|
|
31
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
32
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
33
|
+
* * `moduli` - Modulus for BFV parameters
|
|
34
|
+
*
|
|
35
|
+
* # Returns
|
|
36
|
+
*
|
|
37
|
+
* Returns a `Result<Vec<JsValue>, JsValue>` containing the encrypted data, circuit inputs and any errors.
|
|
38
|
+
*
|
|
39
|
+
* # Panics
|
|
40
|
+
*
|
|
41
|
+
* Panics if the data cannot be encrypted
|
|
42
|
+
*/
|
|
43
|
+
export function bfv_verifiable_encrypt_number(data: bigint, public_key: Uint8Array, degree: number, plaintext_modulus: bigint, moduli: bigint): any[];
|
|
44
|
+
|
|
45
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
46
|
+
|
|
47
|
+
export interface InitOutput {
|
|
48
|
+
readonly memory: WebAssembly.Memory;
|
|
49
|
+
readonly bfv_encrypt_number: (a: bigint, b: number, c: number, d: number, e: bigint, f: bigint) => [number, number, number, number];
|
|
50
|
+
readonly bfv_verifiable_encrypt_number: (a: bigint, b: number, c: number, d: number, e: bigint, f: bigint) => [number, number, number, number];
|
|
51
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
52
|
+
readonly __externref_table_alloc: () => number;
|
|
53
|
+
readonly __wbindgen_export_2: WebAssembly.Table;
|
|
54
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
55
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
56
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
57
|
+
readonly __externref_drop_slice: (a: number, b: number) => void;
|
|
58
|
+
readonly __wbindgen_start: () => void;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
62
|
+
/**
|
|
63
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
64
|
+
* a precompiled `WebAssembly.Module`.
|
|
65
|
+
*
|
|
66
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
67
|
+
*
|
|
68
|
+
* @returns {InitOutput}
|
|
69
|
+
*/
|
|
70
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
74
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
75
|
+
*
|
|
76
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
77
|
+
*
|
|
78
|
+
* @returns {Promise<InitOutput>}
|
|
79
|
+
*/
|
|
80
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
function addToExternrefTable0(obj) {
|
|
4
|
+
const idx = wasm.__externref_table_alloc();
|
|
5
|
+
wasm.__wbindgen_export_2.set(idx, obj);
|
|
6
|
+
return idx;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function handleError(f, args) {
|
|
10
|
+
try {
|
|
11
|
+
return f.apply(this, args);
|
|
12
|
+
} catch (e) {
|
|
13
|
+
const idx = addToExternrefTable0(e);
|
|
14
|
+
wasm.__wbindgen_exn_store(idx);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
19
|
+
|
|
20
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
21
|
+
|
|
22
|
+
let cachedUint8ArrayMemory0 = null;
|
|
23
|
+
|
|
24
|
+
function getUint8ArrayMemory0() {
|
|
25
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
26
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
27
|
+
}
|
|
28
|
+
return cachedUint8ArrayMemory0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getStringFromWasm0(ptr, len) {
|
|
32
|
+
ptr = ptr >>> 0;
|
|
33
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isLikeNone(x) {
|
|
37
|
+
return x === undefined || x === null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
41
|
+
ptr = ptr >>> 0;
|
|
42
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let WASM_VECTOR_LEN = 0;
|
|
46
|
+
|
|
47
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
48
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
49
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
50
|
+
WASM_VECTOR_LEN = arg.length;
|
|
51
|
+
return ptr;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function takeFromExternrefTable0(idx) {
|
|
55
|
+
const value = wasm.__wbindgen_export_2.get(idx);
|
|
56
|
+
wasm.__externref_table_dealloc(idx);
|
|
57
|
+
return value;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A function to encrypt a u64 value using BFV and default params.
|
|
61
|
+
*
|
|
62
|
+
* # Arguments
|
|
63
|
+
*
|
|
64
|
+
* * `data` - The data to encrypt - must be a u64
|
|
65
|
+
* * `public_key` - The public key to be used for encryption
|
|
66
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
67
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
68
|
+
* * `moduli` - Modulus for BFV parameters
|
|
69
|
+
*
|
|
70
|
+
* # Returns
|
|
71
|
+
*
|
|
72
|
+
* Returns a `Result<Vec<u8>, JsValue>` containing the encrypted data and any errors.
|
|
73
|
+
*
|
|
74
|
+
* # Panics
|
|
75
|
+
*
|
|
76
|
+
* Panics if the data cannot be encrypted
|
|
77
|
+
* @param {bigint} data
|
|
78
|
+
* @param {Uint8Array} public_key
|
|
79
|
+
* @param {number} degree
|
|
80
|
+
* @param {bigint} plaintext_modulus
|
|
81
|
+
* @param {bigint} moduli
|
|
82
|
+
* @returns {Uint8Array}
|
|
83
|
+
*/
|
|
84
|
+
export function bfv_encrypt_number(data, public_key, degree, plaintext_modulus, moduli) {
|
|
85
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
86
|
+
const len0 = WASM_VECTOR_LEN;
|
|
87
|
+
const ret = wasm.bfv_encrypt_number(data, ptr0, len0, degree, plaintext_modulus, moduli);
|
|
88
|
+
if (ret[3]) {
|
|
89
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
90
|
+
}
|
|
91
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
92
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
93
|
+
return v2;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
let cachedDataViewMemory0 = null;
|
|
97
|
+
|
|
98
|
+
function getDataViewMemory0() {
|
|
99
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
100
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
101
|
+
}
|
|
102
|
+
return cachedDataViewMemory0;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function getArrayJsValueFromWasm0(ptr, len) {
|
|
106
|
+
ptr = ptr >>> 0;
|
|
107
|
+
const mem = getDataViewMemory0();
|
|
108
|
+
const result = [];
|
|
109
|
+
for (let i = ptr; i < ptr + 4 * len; i += 4) {
|
|
110
|
+
result.push(wasm.__wbindgen_export_2.get(mem.getUint32(i, true)));
|
|
111
|
+
}
|
|
112
|
+
wasm.__externref_drop_slice(ptr, len);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* A function to encrypt a u64 value using BFV and default params and
|
|
117
|
+
* generate circuit inputs for Greco
|
|
118
|
+
*
|
|
119
|
+
* # Arguments
|
|
120
|
+
*
|
|
121
|
+
* * `data` - The data to encrypt - must be a u64
|
|
122
|
+
* * `public_key` - The public key to be used for encryption
|
|
123
|
+
* * `degree` - Polynomial degree for BFV parameters
|
|
124
|
+
* * `plaintext_modulus` - Plaintext modulus for BFV parameters
|
|
125
|
+
* * `moduli` - Modulus for BFV parameters
|
|
126
|
+
*
|
|
127
|
+
* # Returns
|
|
128
|
+
*
|
|
129
|
+
* Returns a `Result<Vec<JsValue>, JsValue>` containing the encrypted data, circuit inputs and any errors.
|
|
130
|
+
*
|
|
131
|
+
* # Panics
|
|
132
|
+
*
|
|
133
|
+
* Panics if the data cannot be encrypted
|
|
134
|
+
* @param {bigint} data
|
|
135
|
+
* @param {Uint8Array} public_key
|
|
136
|
+
* @param {number} degree
|
|
137
|
+
* @param {bigint} plaintext_modulus
|
|
138
|
+
* @param {bigint} moduli
|
|
139
|
+
* @returns {any[]}
|
|
140
|
+
*/
|
|
141
|
+
export function bfv_verifiable_encrypt_number(data, public_key, degree, plaintext_modulus, moduli) {
|
|
142
|
+
const ptr0 = passArray8ToWasm0(public_key, wasm.__wbindgen_malloc);
|
|
143
|
+
const len0 = WASM_VECTOR_LEN;
|
|
144
|
+
const ret = wasm.bfv_verifiable_encrypt_number(data, ptr0, len0, degree, plaintext_modulus, moduli);
|
|
145
|
+
if (ret[3]) {
|
|
146
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
147
|
+
}
|
|
148
|
+
var v2 = getArrayJsValueFromWasm0(ret[0], ret[1]).slice();
|
|
149
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
150
|
+
return v2;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
async function __wbg_load(module, imports) {
|
|
154
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
155
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
156
|
+
try {
|
|
157
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
158
|
+
|
|
159
|
+
} catch (e) {
|
|
160
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
161
|
+
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);
|
|
162
|
+
|
|
163
|
+
} else {
|
|
164
|
+
throw e;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const bytes = await module.arrayBuffer();
|
|
170
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
171
|
+
|
|
172
|
+
} else {
|
|
173
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
174
|
+
|
|
175
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
176
|
+
return { instance, module };
|
|
177
|
+
|
|
178
|
+
} else {
|
|
179
|
+
return instance;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function __wbg_get_imports() {
|
|
185
|
+
const imports = {};
|
|
186
|
+
imports.wbg = {};
|
|
187
|
+
imports.wbg.__wbg_buffer_609cc3eee51ed158 = function(arg0) {
|
|
188
|
+
const ret = arg0.buffer;
|
|
189
|
+
return ret;
|
|
190
|
+
};
|
|
191
|
+
imports.wbg.__wbg_call_672a4d21634d4a24 = function() { return handleError(function (arg0, arg1) {
|
|
192
|
+
const ret = arg0.call(arg1);
|
|
193
|
+
return ret;
|
|
194
|
+
}, arguments) };
|
|
195
|
+
imports.wbg.__wbg_call_7cccdd69e0791ae2 = function() { return handleError(function (arg0, arg1, arg2) {
|
|
196
|
+
const ret = arg0.call(arg1, arg2);
|
|
197
|
+
return ret;
|
|
198
|
+
}, arguments) };
|
|
199
|
+
imports.wbg.__wbg_crypto_574e78ad8b13b65f = function(arg0) {
|
|
200
|
+
const ret = arg0.crypto;
|
|
201
|
+
return ret;
|
|
202
|
+
};
|
|
203
|
+
imports.wbg.__wbg_getRandomValues_b8f5dbd5f3995a9e = function() { return handleError(function (arg0, arg1) {
|
|
204
|
+
arg0.getRandomValues(arg1);
|
|
205
|
+
}, arguments) };
|
|
206
|
+
imports.wbg.__wbg_msCrypto_a61aeb35a24c1329 = function(arg0) {
|
|
207
|
+
const ret = arg0.msCrypto;
|
|
208
|
+
return ret;
|
|
209
|
+
};
|
|
210
|
+
imports.wbg.__wbg_new_a12002a7f91c75be = function(arg0) {
|
|
211
|
+
const ret = new Uint8Array(arg0);
|
|
212
|
+
return ret;
|
|
213
|
+
};
|
|
214
|
+
imports.wbg.__wbg_newnoargs_105ed471475aaf50 = function(arg0, arg1) {
|
|
215
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
216
|
+
return ret;
|
|
217
|
+
};
|
|
218
|
+
imports.wbg.__wbg_newwithbyteoffsetandlength_d97e637ebe145a9a = function(arg0, arg1, arg2) {
|
|
219
|
+
const ret = new Uint8Array(arg0, arg1 >>> 0, arg2 >>> 0);
|
|
220
|
+
return ret;
|
|
221
|
+
};
|
|
222
|
+
imports.wbg.__wbg_newwithlength_a381634e90c276d4 = function(arg0) {
|
|
223
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
224
|
+
return ret;
|
|
225
|
+
};
|
|
226
|
+
imports.wbg.__wbg_node_905d3e251edff8a2 = function(arg0) {
|
|
227
|
+
const ret = arg0.node;
|
|
228
|
+
return ret;
|
|
229
|
+
};
|
|
230
|
+
imports.wbg.__wbg_process_dc0fbacc7c1c06f7 = function(arg0) {
|
|
231
|
+
const ret = arg0.process;
|
|
232
|
+
return ret;
|
|
233
|
+
};
|
|
234
|
+
imports.wbg.__wbg_randomFillSync_ac0988aba3254290 = function() { return handleError(function (arg0, arg1) {
|
|
235
|
+
arg0.randomFillSync(arg1);
|
|
236
|
+
}, arguments) };
|
|
237
|
+
imports.wbg.__wbg_require_60cc747a6bc5215a = function() { return handleError(function () {
|
|
238
|
+
const ret = module.require;
|
|
239
|
+
return ret;
|
|
240
|
+
}, arguments) };
|
|
241
|
+
imports.wbg.__wbg_set_65595bdd868b3009 = function(arg0, arg1, arg2) {
|
|
242
|
+
arg0.set(arg1, arg2 >>> 0);
|
|
243
|
+
};
|
|
244
|
+
imports.wbg.__wbg_static_accessor_GLOBAL_88a902d13a557d07 = function() {
|
|
245
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
246
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
247
|
+
};
|
|
248
|
+
imports.wbg.__wbg_static_accessor_GLOBAL_THIS_56578be7e9f832b0 = function() {
|
|
249
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
250
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
251
|
+
};
|
|
252
|
+
imports.wbg.__wbg_static_accessor_SELF_37c5d418e4bf5819 = function() {
|
|
253
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
254
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
255
|
+
};
|
|
256
|
+
imports.wbg.__wbg_static_accessor_WINDOW_5de37043a91a9c40 = function() {
|
|
257
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
258
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
259
|
+
};
|
|
260
|
+
imports.wbg.__wbg_subarray_aa9065fa9dc5df96 = function(arg0, arg1, arg2) {
|
|
261
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
262
|
+
return ret;
|
|
263
|
+
};
|
|
264
|
+
imports.wbg.__wbg_versions_c01dfd4722a88165 = function(arg0) {
|
|
265
|
+
const ret = arg0.versions;
|
|
266
|
+
return ret;
|
|
267
|
+
};
|
|
268
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
269
|
+
const table = wasm.__wbindgen_export_2;
|
|
270
|
+
const offset = table.grow(4);
|
|
271
|
+
table.set(0, undefined);
|
|
272
|
+
table.set(offset + 0, undefined);
|
|
273
|
+
table.set(offset + 1, null);
|
|
274
|
+
table.set(offset + 2, true);
|
|
275
|
+
table.set(offset + 3, false);
|
|
276
|
+
;
|
|
277
|
+
};
|
|
278
|
+
imports.wbg.__wbindgen_is_function = function(arg0) {
|
|
279
|
+
const ret = typeof(arg0) === 'function';
|
|
280
|
+
return ret;
|
|
281
|
+
};
|
|
282
|
+
imports.wbg.__wbindgen_is_object = function(arg0) {
|
|
283
|
+
const val = arg0;
|
|
284
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
285
|
+
return ret;
|
|
286
|
+
};
|
|
287
|
+
imports.wbg.__wbindgen_is_string = function(arg0) {
|
|
288
|
+
const ret = typeof(arg0) === 'string';
|
|
289
|
+
return ret;
|
|
290
|
+
};
|
|
291
|
+
imports.wbg.__wbindgen_is_undefined = function(arg0) {
|
|
292
|
+
const ret = arg0 === undefined;
|
|
293
|
+
return ret;
|
|
294
|
+
};
|
|
295
|
+
imports.wbg.__wbindgen_memory = function() {
|
|
296
|
+
const ret = wasm.memory;
|
|
297
|
+
return ret;
|
|
298
|
+
};
|
|
299
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
300
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
301
|
+
return ret;
|
|
302
|
+
};
|
|
303
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
304
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
305
|
+
};
|
|
306
|
+
imports.wbg.__wbindgen_uint8_array_new = function(arg0, arg1) {
|
|
307
|
+
var v0 = getArrayU8FromWasm0(arg0, arg1).slice();
|
|
308
|
+
wasm.__wbindgen_free(arg0, arg1 * 1, 1);
|
|
309
|
+
const ret = v0;
|
|
310
|
+
return ret;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
return imports;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function __wbg_init_memory(imports, memory) {
|
|
317
|
+
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function __wbg_finalize_init(instance, module) {
|
|
321
|
+
wasm = instance.exports;
|
|
322
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
323
|
+
cachedDataViewMemory0 = null;
|
|
324
|
+
cachedUint8ArrayMemory0 = null;
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
wasm.__wbindgen_start();
|
|
328
|
+
return wasm;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
function initSync(module) {
|
|
332
|
+
if (wasm !== undefined) return wasm;
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
if (typeof module !== 'undefined') {
|
|
336
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
337
|
+
({module} = module)
|
|
338
|
+
} else {
|
|
339
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
const imports = __wbg_get_imports();
|
|
344
|
+
|
|
345
|
+
__wbg_init_memory(imports);
|
|
346
|
+
|
|
347
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
348
|
+
module = new WebAssembly.Module(module);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
352
|
+
|
|
353
|
+
return __wbg_finalize_init(instance, module);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
async function __wbg_init(module_or_path) {
|
|
357
|
+
if (wasm !== undefined) return wasm;
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
if (typeof module_or_path !== 'undefined') {
|
|
361
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
362
|
+
({module_or_path} = module_or_path)
|
|
363
|
+
} else {
|
|
364
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
if (typeof module_or_path === 'undefined') {
|
|
369
|
+
module_or_path = new URL('e3_wasm_bg.wasm', import.meta.url);
|
|
370
|
+
}
|
|
371
|
+
const imports = __wbg_get_imports();
|
|
372
|
+
|
|
373
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
374
|
+
module_or_path = fetch(module_or_path);
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
__wbg_init_memory(imports);
|
|
378
|
+
|
|
379
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
380
|
+
|
|
381
|
+
return __wbg_finalize_init(instance, module);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
export { initSync };
|
|
385
|
+
export default __wbg_init;
|
|
Binary file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const bfv_encrypt_number: (a: bigint, b: number, c: number, d: number, e: bigint, f: bigint) => [number, number, number, number];
|
|
5
|
+
export const bfv_verifiable_encrypt_number: (a: bigint, b: number, c: number, d: number, e: bigint, f: bigint) => [number, number, number, number];
|
|
6
|
+
export const __wbindgen_exn_store: (a: number) => void;
|
|
7
|
+
export const __externref_table_alloc: () => number;
|
|
8
|
+
export const __wbindgen_export_2: WebAssembly.Table;
|
|
9
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
10
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
11
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
12
|
+
export const __externref_drop_slice: (a: number, b: number) => void;
|
|
13
|
+
export const __wbindgen_start: () => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "e3-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "E3 — Encrypted Execution Environments",
|
|
5
|
+
"version": "0.1.0",
|
|
6
|
+
"license": "LGPL-3.0-only",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/gnosisguild/enclave"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"e3_wasm_bg.wasm",
|
|
13
|
+
"e3_wasm.js",
|
|
14
|
+
"e3_wasm.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "e3_wasm.js",
|
|
17
|
+
"types": "e3_wasm.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@enclave-e3/wasm",
|
|
3
|
+
"version": "0.0.7-test",
|
|
4
|
+
"description": "Wasm modules for enclave.",
|
|
5
|
+
"main": "dist/nodejs/e3_wasm.js",
|
|
6
|
+
"module": "dist/web/e3_wasm.js",
|
|
7
|
+
"types": "dist/web/e3_wasm.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist/",
|
|
10
|
+
"dist/**/*"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"git-checks": false
|
|
15
|
+
},
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"node": {
|
|
19
|
+
"types": "./dist/nodejs/e3_wasm.d.ts",
|
|
20
|
+
"default": "./dist/nodejs/e3_wasm.js"
|
|
21
|
+
},
|
|
22
|
+
"browser": {
|
|
23
|
+
"types": "./dist/web/e3_wasm.d.ts",
|
|
24
|
+
"default": "./dist/web/e3_wasm.js"
|
|
25
|
+
},
|
|
26
|
+
"default": {
|
|
27
|
+
"types": "./dist/web/e3_wasm.d.ts",
|
|
28
|
+
"default": "./dist/web/e3_wasm.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"./init": {
|
|
32
|
+
"node": {
|
|
33
|
+
"types": "./init.d.ts",
|
|
34
|
+
"import": "./init_node.js",
|
|
35
|
+
"require": "./init_node.cjs"
|
|
36
|
+
},
|
|
37
|
+
"browser": {
|
|
38
|
+
"types": "./init.d.ts",
|
|
39
|
+
"default": "./init_web.js"
|
|
40
|
+
},
|
|
41
|
+
"default": {
|
|
42
|
+
"types": "./init.d.ts",
|
|
43
|
+
"import": "./init_node.js",
|
|
44
|
+
"require": "./init_node.cjs",
|
|
45
|
+
"default": "./init_web.js"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"keywords": [],
|
|
50
|
+
"author": {
|
|
51
|
+
"name": "gnosisguild",
|
|
52
|
+
"url": "https://github.com/gnosisguild"
|
|
53
|
+
},
|
|
54
|
+
"license": "LGPL-3.0-only",
|
|
55
|
+
"scripts": {
|
|
56
|
+
"build": "./scripts/build.sh",
|
|
57
|
+
"prerelease": "pnpm build",
|
|
58
|
+
"release": "pnpm publish --access=public"
|
|
59
|
+
}
|
|
60
|
+
}
|