@agentaos/crypto 0.2.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/LICENSE +199 -0
- package/README.md +39 -0
- package/package.json +52 -0
- package/pkg/README.md +39 -0
- package/pkg/agentaos_mpc_wasm.js +667 -0
- package/pkg-web/README.md +39 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding any notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. Please also get an
|
|
185
|
+
OpenPGP-compatible signature on the file.
|
|
186
|
+
|
|
187
|
+
Copyright 2025-2026 Aristokrates OÜ
|
|
188
|
+
|
|
189
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
190
|
+
you may not use this file except in compliance with the License.
|
|
191
|
+
You may obtain a copy of the License at
|
|
192
|
+
|
|
193
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
194
|
+
|
|
195
|
+
Unless required by applicable law or agreed to in writing, software
|
|
196
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
197
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
198
|
+
See the License for the specific language governing permissions and
|
|
199
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @agentaos/crypto
|
|
2
|
+
|
|
3
|
+
**CGGMP24 threshold ECDSA WASM module for AgentaOS.**
|
|
4
|
+
|
|
5
|
+
[](../../LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/@agentaos/crypto)
|
|
7
|
+
|
|
8
|
+
Rust-compiled WebAssembly module implementing CGGMP24 threshold ECDSA (2-of-3) over secp256k1. Built from the [LFDT-Lockness/cggmp21](https://github.com/LFDT-Lockness/cggmp21) Rust crate.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @agentaos/crypto
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What It Does
|
|
17
|
+
|
|
18
|
+
- **DKG** -- Distributed Key Generation (3-party, produces 3 shares + public key)
|
|
19
|
+
- **Signing** -- Interactive threshold signing (2-of-3, 3-round protocol)
|
|
20
|
+
- **Aux Info** -- Pre-computation of auxiliary information for signing efficiency
|
|
21
|
+
- **Key Refresh** -- Proactive share refresh without changing the public key
|
|
22
|
+
|
|
23
|
+
## Build from Source
|
|
24
|
+
|
|
25
|
+
Requires Rust toolchain with `wasm32-unknown-unknown` target:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
cd packages/mpc-wasm
|
|
29
|
+
cargo build --release --target wasm32-unknown-unknown
|
|
30
|
+
wasm-bindgen target/wasm32-unknown-unknown/release/agenta_crypto_wasm.wasm --out-dir pkg/
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
This module is consumed by `@agentaos/engine`. Direct usage is not recommended -- use the higher-level `Agenta` facade from `@agentaos/sdk` instead.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
Apache-2.0 -- see [LICENSE](../../LICENSE).
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentaos/crypto",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "CGGMP24 threshold ECDSA WASM module for AgentaOS",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": "AgentaOS <hello@agentaos.ai>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/AgentaOS/agentaos.git",
|
|
10
|
+
"directory": "packages/mpc-wasm"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/AgentaOS/agentaos",
|
|
13
|
+
"bugs": "https://github.com/AgentaOS/agentaos/issues",
|
|
14
|
+
"keywords": [
|
|
15
|
+
"threshold",
|
|
16
|
+
"wallet",
|
|
17
|
+
"mpc",
|
|
18
|
+
"cggmp24",
|
|
19
|
+
"ecdsa",
|
|
20
|
+
"wasm",
|
|
21
|
+
"secp256k1"
|
|
22
|
+
],
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./pkg/agentaos_mpc_wasm.js",
|
|
25
|
+
"types": "./pkg/agentaos_mpc_wasm.d.ts",
|
|
26
|
+
"exports": {
|
|
27
|
+
".": {
|
|
28
|
+
"types": "./pkg/agentaos_mpc_wasm.d.ts",
|
|
29
|
+
"import": "./pkg/agentaos_mpc_wasm.js"
|
|
30
|
+
},
|
|
31
|
+
"./web": {
|
|
32
|
+
"types": "./pkg-web/agentaos_mpc_wasm.d.ts",
|
|
33
|
+
"import": "./pkg-web/agentaos_mpc_wasm.js"
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"pkg",
|
|
38
|
+
"pkg-web"
|
|
39
|
+
],
|
|
40
|
+
"engines": {
|
|
41
|
+
"node": ">=20.0.0"
|
|
42
|
+
},
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "bash build-node.sh && bash build-web.sh",
|
|
48
|
+
"build:node": "bash build-node.sh",
|
|
49
|
+
"build:web": "bash build-web.sh",
|
|
50
|
+
"clean": "rm -rf pkg pkg-web target"
|
|
51
|
+
}
|
|
52
|
+
}
|
package/pkg/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @agentaos/crypto
|
|
2
|
+
|
|
3
|
+
**CGGMP24 threshold ECDSA WASM module for AgentaOS.**
|
|
4
|
+
|
|
5
|
+
[](../../LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/@agentaos/crypto)
|
|
7
|
+
|
|
8
|
+
Rust-compiled WebAssembly module implementing CGGMP24 threshold ECDSA (2-of-3) over secp256k1. Built from the [LFDT-Lockness/cggmp21](https://github.com/LFDT-Lockness/cggmp21) Rust crate.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @agentaos/crypto
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What It Does
|
|
17
|
+
|
|
18
|
+
- **DKG** -- Distributed Key Generation (3-party, produces 3 shares + public key)
|
|
19
|
+
- **Signing** -- Interactive threshold signing (2-of-3, 3-round protocol)
|
|
20
|
+
- **Aux Info** -- Pre-computation of auxiliary information for signing efficiency
|
|
21
|
+
- **Key Refresh** -- Proactive share refresh without changing the public key
|
|
22
|
+
|
|
23
|
+
## Build from Source
|
|
24
|
+
|
|
25
|
+
Requires Rust toolchain with `wasm32-unknown-unknown` target:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
cd packages/mpc-wasm
|
|
29
|
+
cargo build --release --target wasm32-unknown-unknown
|
|
30
|
+
wasm-bindgen target/wasm32-unknown-unknown/release/agenta_crypto_wasm.wasm --out-dir pkg/
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
This module is consumed by `@agentaos/engine`. Direct usage is not recommended -- use the higher-level `Agenta` facade from `@agentaos/sdk` instead.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
Apache-2.0 -- see [LICENSE](../../LICENSE).
|
|
@@ -0,0 +1,667 @@
|
|
|
1
|
+
/* @ts-self-types="./agentaos_mpc_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Combine a CoreKeyShare (from keygen) with AuxInfo (from aux_info_gen)
|
|
5
|
+
* into a full KeyShare suitable for signing.
|
|
6
|
+
*
|
|
7
|
+
* Returns the serialised KeyShare bytes.
|
|
8
|
+
* @param {Uint8Array} core_key_share
|
|
9
|
+
* @param {Uint8Array} aux_info
|
|
10
|
+
* @returns {Uint8Array}
|
|
11
|
+
*/
|
|
12
|
+
function combine_key_share(core_key_share, aux_info) {
|
|
13
|
+
const ptr0 = passArray8ToWasm0(core_key_share, wasm.__wbindgen_malloc);
|
|
14
|
+
const len0 = WASM_VECTOR_LEN;
|
|
15
|
+
const ptr1 = passArray8ToWasm0(aux_info, wasm.__wbindgen_malloc);
|
|
16
|
+
const len1 = WASM_VECTOR_LEN;
|
|
17
|
+
const ret = wasm.combine_key_share(ptr0, len0, ptr1, len1);
|
|
18
|
+
if (ret[3]) {
|
|
19
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
20
|
+
}
|
|
21
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
22
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
23
|
+
return v3;
|
|
24
|
+
}
|
|
25
|
+
exports.combine_key_share = combine_key_share;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Extract the shared public key from a serialised KeyShare or CoreKeyShare.
|
|
29
|
+
*
|
|
30
|
+
* Returns 33-byte compressed secp256k1 public key.
|
|
31
|
+
* @param {Uint8Array} key_share_bytes
|
|
32
|
+
* @returns {Uint8Array}
|
|
33
|
+
*/
|
|
34
|
+
function extract_public_key(key_share_bytes) {
|
|
35
|
+
const ptr0 = passArray8ToWasm0(key_share_bytes, wasm.__wbindgen_malloc);
|
|
36
|
+
const len0 = WASM_VECTOR_LEN;
|
|
37
|
+
const ret = wasm.extract_public_key(ptr0, len0);
|
|
38
|
+
if (ret[3]) {
|
|
39
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
40
|
+
}
|
|
41
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
42
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
43
|
+
return v2;
|
|
44
|
+
}
|
|
45
|
+
exports.extract_public_key = extract_public_key;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Initialise the WASM module (called once from JS).
|
|
49
|
+
*/
|
|
50
|
+
function init() {
|
|
51
|
+
wasm._critical_section_1_0_acquire();
|
|
52
|
+
}
|
|
53
|
+
exports.init = init;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Pre-generate Paillier primes for aux_info_gen.
|
|
57
|
+
*
|
|
58
|
+
* This is the expensive part (~30-60s). Call this ahead of time
|
|
59
|
+
* and store the result. Pass serialised primes to speed up DKG.
|
|
60
|
+
*
|
|
61
|
+
* Returns serialised PregeneratedPrimes.
|
|
62
|
+
* @returns {Uint8Array}
|
|
63
|
+
*/
|
|
64
|
+
function pregenerate_paillier_primes() {
|
|
65
|
+
const ret = wasm.pregenerate_paillier_primes();
|
|
66
|
+
if (ret[3]) {
|
|
67
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
68
|
+
}
|
|
69
|
+
var v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
70
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
71
|
+
return v1;
|
|
72
|
+
}
|
|
73
|
+
exports.pregenerate_paillier_primes = pregenerate_paillier_primes;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Run a complete two-phase DKG ceremony for `n` parties with threshold `t`.
|
|
77
|
+
*
|
|
78
|
+
* Phase A: Auxiliary info generation (Paillier primes — computationally expensive)
|
|
79
|
+
* Phase B: Key generation (lightweight ECDSA key shares)
|
|
80
|
+
*
|
|
81
|
+
* All parties run locally via protocol simulation. Returns a JSON object
|
|
82
|
+
* containing key shares for each party and the shared public key.
|
|
83
|
+
*
|
|
84
|
+
* The caller (server) distributes shares:
|
|
85
|
+
* - Share[0] → signer (encrypted .share.enc file)
|
|
86
|
+
* - Share[1] → server (stored in Vault)
|
|
87
|
+
* - Share[2] → user (wallet-encrypted, returned to browser)
|
|
88
|
+
* @param {Uint8Array} eid_bytes
|
|
89
|
+
* @param {number} n
|
|
90
|
+
* @param {number} threshold
|
|
91
|
+
* @returns {any}
|
|
92
|
+
*/
|
|
93
|
+
function run_dkg(eid_bytes, n, threshold) {
|
|
94
|
+
const ptr0 = passArray8ToWasm0(eid_bytes, wasm.__wbindgen_malloc);
|
|
95
|
+
const len0 = WASM_VECTOR_LEN;
|
|
96
|
+
const ret = wasm.run_dkg(ptr0, len0, n, threshold);
|
|
97
|
+
if (ret[2]) {
|
|
98
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
99
|
+
}
|
|
100
|
+
return takeFromExternrefTable0(ret[0]);
|
|
101
|
+
}
|
|
102
|
+
exports.run_dkg = run_dkg;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Run a complete two-phase DKG ceremony using pre-generated Paillier primes.
|
|
106
|
+
*
|
|
107
|
+
* This is the FAST path — Paillier prime generation (~30-60s per party) is
|
|
108
|
+
* skipped because primes were generated ahead of time (e.g. during server
|
|
109
|
+
* startup in a background worker thread).
|
|
110
|
+
*
|
|
111
|
+
* `serialized_primes` is a JS array of `Uint8Array`, one per party,
|
|
112
|
+
* each being the serde_json serialization of `PregeneratedPrimes`.
|
|
113
|
+
* @param {Uint8Array} eid_bytes
|
|
114
|
+
* @param {number} n
|
|
115
|
+
* @param {number} threshold
|
|
116
|
+
* @param {any} serialized_primes
|
|
117
|
+
* @returns {any}
|
|
118
|
+
*/
|
|
119
|
+
function run_dkg_with_primes(eid_bytes, n, threshold, serialized_primes) {
|
|
120
|
+
const ptr0 = passArray8ToWasm0(eid_bytes, wasm.__wbindgen_malloc);
|
|
121
|
+
const len0 = WASM_VECTOR_LEN;
|
|
122
|
+
const ret = wasm.run_dkg_with_primes(ptr0, len0, n, threshold, serialized_primes);
|
|
123
|
+
if (ret[2]) {
|
|
124
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
125
|
+
}
|
|
126
|
+
return takeFromExternrefTable0(ret[0]);
|
|
127
|
+
}
|
|
128
|
+
exports.run_dkg_with_primes = run_dkg_with_primes;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Create an interactive signing session for one party.
|
|
132
|
+
*
|
|
133
|
+
* # Arguments
|
|
134
|
+
* - `core_share`: serialised CoreKeyShare (serde_json bytes)
|
|
135
|
+
* - `aux_info`: serialised AuxInfo (serde_json bytes)
|
|
136
|
+
* - `message_hash`: 32-byte hash to sign
|
|
137
|
+
* - `party_index`: this party's index at keygen time (0-based)
|
|
138
|
+
* - `parties_at_keygen`: array of party indices participating in signing
|
|
139
|
+
* - `eid`: execution ID bytes (32 bytes)
|
|
140
|
+
*
|
|
141
|
+
* # Returns
|
|
142
|
+
* JS object: `{ session_id: string, messages: WasmSignMessage[] }`
|
|
143
|
+
* @param {Uint8Array} core_share
|
|
144
|
+
* @param {Uint8Array} aux_info
|
|
145
|
+
* @param {Uint8Array} message_hash
|
|
146
|
+
* @param {number} party_index
|
|
147
|
+
* @param {Uint16Array} parties_at_keygen
|
|
148
|
+
* @param {Uint8Array} eid
|
|
149
|
+
* @returns {any}
|
|
150
|
+
*/
|
|
151
|
+
function sign_create_session(core_share, aux_info, message_hash, party_index, parties_at_keygen, eid) {
|
|
152
|
+
const ptr0 = passArray8ToWasm0(core_share, wasm.__wbindgen_malloc);
|
|
153
|
+
const len0 = WASM_VECTOR_LEN;
|
|
154
|
+
const ptr1 = passArray8ToWasm0(aux_info, wasm.__wbindgen_malloc);
|
|
155
|
+
const len1 = WASM_VECTOR_LEN;
|
|
156
|
+
const ptr2 = passArray8ToWasm0(message_hash, wasm.__wbindgen_malloc);
|
|
157
|
+
const len2 = WASM_VECTOR_LEN;
|
|
158
|
+
const ptr3 = passArray16ToWasm0(parties_at_keygen, wasm.__wbindgen_malloc);
|
|
159
|
+
const len3 = WASM_VECTOR_LEN;
|
|
160
|
+
const ptr4 = passArray8ToWasm0(eid, wasm.__wbindgen_malloc);
|
|
161
|
+
const len4 = WASM_VECTOR_LEN;
|
|
162
|
+
const ret = wasm.sign_create_session(ptr0, len0, ptr1, len1, ptr2, len2, party_index, ptr3, len3, ptr4, len4);
|
|
163
|
+
if (ret[2]) {
|
|
164
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
165
|
+
}
|
|
166
|
+
return takeFromExternrefTable0(ret[0]);
|
|
167
|
+
}
|
|
168
|
+
exports.sign_create_session = sign_create_session;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Destroy a signing session and free all resources.
|
|
172
|
+
*
|
|
173
|
+
* Returns `true` if the session existed and was destroyed.
|
|
174
|
+
* @param {string} session_id
|
|
175
|
+
* @returns {boolean}
|
|
176
|
+
*/
|
|
177
|
+
function sign_destroy_session(session_id) {
|
|
178
|
+
const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
179
|
+
const len0 = WASM_VECTOR_LEN;
|
|
180
|
+
const ret = wasm.sign_destroy_session(ptr0, len0);
|
|
181
|
+
return ret !== 0;
|
|
182
|
+
}
|
|
183
|
+
exports.sign_destroy_session = sign_destroy_session;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Process a round of incoming messages for an existing signing session.
|
|
187
|
+
*
|
|
188
|
+
* # Arguments
|
|
189
|
+
* - `session_id`: the session ID returned by `sign_create_session`
|
|
190
|
+
* - `incoming_messages`: JS array of `WasmSignMessage` objects
|
|
191
|
+
*
|
|
192
|
+
* # Returns
|
|
193
|
+
* JS object: `{ messages: WasmSignMessage[], complete: bool, signature?: { r, s } }`
|
|
194
|
+
* @param {string} session_id
|
|
195
|
+
* @param {any} incoming_messages
|
|
196
|
+
* @returns {any}
|
|
197
|
+
*/
|
|
198
|
+
function sign_process_round(session_id, incoming_messages) {
|
|
199
|
+
const ptr0 = passStringToWasm0(session_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
200
|
+
const len0 = WASM_VECTOR_LEN;
|
|
201
|
+
const ret = wasm.sign_process_round(ptr0, len0, incoming_messages);
|
|
202
|
+
if (ret[2]) {
|
|
203
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
204
|
+
}
|
|
205
|
+
return takeFromExternrefTable0(ret[0]);
|
|
206
|
+
}
|
|
207
|
+
exports.sign_process_round = sign_process_round;
|
|
208
|
+
|
|
209
|
+
function __wbg_get_imports() {
|
|
210
|
+
const import0 = {
|
|
211
|
+
__proto__: null,
|
|
212
|
+
__wbg_Error_8c4e43fe74559d73: function(arg0, arg1) {
|
|
213
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
214
|
+
return ret;
|
|
215
|
+
},
|
|
216
|
+
__wbg_Number_04624de7d0e8332d: function(arg0) {
|
|
217
|
+
const ret = Number(arg0);
|
|
218
|
+
return ret;
|
|
219
|
+
},
|
|
220
|
+
__wbg_String_8f0eb39a4a4c2f66: function(arg0, arg1) {
|
|
221
|
+
const ret = String(arg1);
|
|
222
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
223
|
+
const len1 = WASM_VECTOR_LEN;
|
|
224
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
225
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
226
|
+
},
|
|
227
|
+
__wbg___wbindgen_boolean_get_bbbb1c18aa2f5e25: function(arg0) {
|
|
228
|
+
const v = arg0;
|
|
229
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
230
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
231
|
+
},
|
|
232
|
+
__wbg___wbindgen_debug_string_0bc8482c6e3508ae: function(arg0, arg1) {
|
|
233
|
+
const ret = debugString(arg1);
|
|
234
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
235
|
+
const len1 = WASM_VECTOR_LEN;
|
|
236
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
237
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
238
|
+
},
|
|
239
|
+
__wbg___wbindgen_in_47fa6863be6f2f25: function(arg0, arg1) {
|
|
240
|
+
const ret = arg0 in arg1;
|
|
241
|
+
return ret;
|
|
242
|
+
},
|
|
243
|
+
__wbg___wbindgen_is_function_0095a73b8b156f76: function(arg0) {
|
|
244
|
+
const ret = typeof(arg0) === 'function';
|
|
245
|
+
return ret;
|
|
246
|
+
},
|
|
247
|
+
__wbg___wbindgen_is_object_5ae8e5880f2c1fbd: function(arg0) {
|
|
248
|
+
const val = arg0;
|
|
249
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
250
|
+
return ret;
|
|
251
|
+
},
|
|
252
|
+
__wbg___wbindgen_is_string_cd444516edc5b180: function(arg0) {
|
|
253
|
+
const ret = typeof(arg0) === 'string';
|
|
254
|
+
return ret;
|
|
255
|
+
},
|
|
256
|
+
__wbg___wbindgen_is_undefined_9e4d92534c42d778: function(arg0) {
|
|
257
|
+
const ret = arg0 === undefined;
|
|
258
|
+
return ret;
|
|
259
|
+
},
|
|
260
|
+
__wbg___wbindgen_jsval_loose_eq_9dd77d8cd6671811: function(arg0, arg1) {
|
|
261
|
+
const ret = arg0 == arg1;
|
|
262
|
+
return ret;
|
|
263
|
+
},
|
|
264
|
+
__wbg___wbindgen_number_get_8ff4255516ccad3e: function(arg0, arg1) {
|
|
265
|
+
const obj = arg1;
|
|
266
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
267
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
268
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
269
|
+
},
|
|
270
|
+
__wbg___wbindgen_string_get_72fb696202c56729: function(arg0, arg1) {
|
|
271
|
+
const obj = arg1;
|
|
272
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
273
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
274
|
+
var len1 = WASM_VECTOR_LEN;
|
|
275
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
276
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
277
|
+
},
|
|
278
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
279
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
280
|
+
},
|
|
281
|
+
__wbg_call_389efe28435a9388: function() { return handleError(function (arg0, arg1) {
|
|
282
|
+
const ret = arg0.call(arg1);
|
|
283
|
+
return ret;
|
|
284
|
+
}, arguments); },
|
|
285
|
+
__wbg_call_4708e0c13bdc8e95: function() { return handleError(function (arg0, arg1, arg2) {
|
|
286
|
+
const ret = arg0.call(arg1, arg2);
|
|
287
|
+
return ret;
|
|
288
|
+
}, arguments); },
|
|
289
|
+
__wbg_crypto_86f2631e91b51511: function(arg0) {
|
|
290
|
+
const ret = arg0.crypto;
|
|
291
|
+
return ret;
|
|
292
|
+
},
|
|
293
|
+
__wbg_done_57b39ecd9addfe81: function(arg0) {
|
|
294
|
+
const ret = arg0.done;
|
|
295
|
+
return ret;
|
|
296
|
+
},
|
|
297
|
+
__wbg_getRandomValues_b3f15fcbfabb0f8b: function() { return handleError(function (arg0, arg1) {
|
|
298
|
+
arg0.getRandomValues(arg1);
|
|
299
|
+
}, arguments); },
|
|
300
|
+
__wbg_get_9b94d73e6221f75c: function(arg0, arg1) {
|
|
301
|
+
const ret = arg0[arg1 >>> 0];
|
|
302
|
+
return ret;
|
|
303
|
+
},
|
|
304
|
+
__wbg_get_b3ed3ad4be2bc8ac: function() { return handleError(function (arg0, arg1) {
|
|
305
|
+
const ret = Reflect.get(arg0, arg1);
|
|
306
|
+
return ret;
|
|
307
|
+
}, arguments); },
|
|
308
|
+
__wbg_get_with_ref_key_1dc361bd10053bfe: function(arg0, arg1) {
|
|
309
|
+
const ret = arg0[arg1];
|
|
310
|
+
return ret;
|
|
311
|
+
},
|
|
312
|
+
__wbg_instanceof_ArrayBuffer_c367199e2fa2aa04: function(arg0) {
|
|
313
|
+
let result;
|
|
314
|
+
try {
|
|
315
|
+
result = arg0 instanceof ArrayBuffer;
|
|
316
|
+
} catch (_) {
|
|
317
|
+
result = false;
|
|
318
|
+
}
|
|
319
|
+
const ret = result;
|
|
320
|
+
return ret;
|
|
321
|
+
},
|
|
322
|
+
__wbg_instanceof_Uint8Array_9b9075935c74707c: function(arg0) {
|
|
323
|
+
let result;
|
|
324
|
+
try {
|
|
325
|
+
result = arg0 instanceof Uint8Array;
|
|
326
|
+
} catch (_) {
|
|
327
|
+
result = false;
|
|
328
|
+
}
|
|
329
|
+
const ret = result;
|
|
330
|
+
return ret;
|
|
331
|
+
},
|
|
332
|
+
__wbg_isArray_d314bb98fcf08331: function(arg0) {
|
|
333
|
+
const ret = Array.isArray(arg0);
|
|
334
|
+
return ret;
|
|
335
|
+
},
|
|
336
|
+
__wbg_isSafeInteger_bfbc7332a9768d2a: function(arg0) {
|
|
337
|
+
const ret = Number.isSafeInteger(arg0);
|
|
338
|
+
return ret;
|
|
339
|
+
},
|
|
340
|
+
__wbg_iterator_6ff6560ca1568e55: function() {
|
|
341
|
+
const ret = Symbol.iterator;
|
|
342
|
+
return ret;
|
|
343
|
+
},
|
|
344
|
+
__wbg_length_32ed9a279acd054c: function(arg0) {
|
|
345
|
+
const ret = arg0.length;
|
|
346
|
+
return ret;
|
|
347
|
+
},
|
|
348
|
+
__wbg_length_35a7bace40f36eac: function(arg0) {
|
|
349
|
+
const ret = arg0.length;
|
|
350
|
+
return ret;
|
|
351
|
+
},
|
|
352
|
+
__wbg_msCrypto_d562bbe83e0d4b91: function(arg0) {
|
|
353
|
+
const ret = arg0.msCrypto;
|
|
354
|
+
return ret;
|
|
355
|
+
},
|
|
356
|
+
__wbg_new_361308b2356cecd0: function() {
|
|
357
|
+
const ret = new Object();
|
|
358
|
+
return ret;
|
|
359
|
+
},
|
|
360
|
+
__wbg_new_3eb36ae241fe6f44: function() {
|
|
361
|
+
const ret = new Array();
|
|
362
|
+
return ret;
|
|
363
|
+
},
|
|
364
|
+
__wbg_new_dd2b680c8bf6ae29: function(arg0) {
|
|
365
|
+
const ret = new Uint8Array(arg0);
|
|
366
|
+
return ret;
|
|
367
|
+
},
|
|
368
|
+
__wbg_new_no_args_1c7c842f08d00ebb: function(arg0, arg1) {
|
|
369
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
370
|
+
return ret;
|
|
371
|
+
},
|
|
372
|
+
__wbg_new_with_length_a2c39cbe88fd8ff1: function(arg0) {
|
|
373
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
374
|
+
return ret;
|
|
375
|
+
},
|
|
376
|
+
__wbg_next_3482f54c49e8af19: function() { return handleError(function (arg0) {
|
|
377
|
+
const ret = arg0.next();
|
|
378
|
+
return ret;
|
|
379
|
+
}, arguments); },
|
|
380
|
+
__wbg_next_418f80d8f5303233: function(arg0) {
|
|
381
|
+
const ret = arg0.next;
|
|
382
|
+
return ret;
|
|
383
|
+
},
|
|
384
|
+
__wbg_node_e1f24f89a7336c2e: function(arg0) {
|
|
385
|
+
const ret = arg0.node;
|
|
386
|
+
return ret;
|
|
387
|
+
},
|
|
388
|
+
__wbg_process_3975fd6c72f520aa: function(arg0) {
|
|
389
|
+
const ret = arg0.process;
|
|
390
|
+
return ret;
|
|
391
|
+
},
|
|
392
|
+
__wbg_prototypesetcall_bdcdcc5842e4d77d: function(arg0, arg1, arg2) {
|
|
393
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
394
|
+
},
|
|
395
|
+
__wbg_randomFillSync_f8c153b79f285817: function() { return handleError(function (arg0, arg1) {
|
|
396
|
+
arg0.randomFillSync(arg1);
|
|
397
|
+
}, arguments); },
|
|
398
|
+
__wbg_require_b74f47fc2d022fd6: function() { return handleError(function () {
|
|
399
|
+
const ret = module.require;
|
|
400
|
+
return ret;
|
|
401
|
+
}, arguments); },
|
|
402
|
+
__wbg_set_3f1d0b984ed272ed: function(arg0, arg1, arg2) {
|
|
403
|
+
arg0[arg1] = arg2;
|
|
404
|
+
},
|
|
405
|
+
__wbg_set_f43e577aea94465b: function(arg0, arg1, arg2) {
|
|
406
|
+
arg0[arg1 >>> 0] = arg2;
|
|
407
|
+
},
|
|
408
|
+
__wbg_static_accessor_GLOBAL_12837167ad935116: function() {
|
|
409
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
410
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
411
|
+
},
|
|
412
|
+
__wbg_static_accessor_GLOBAL_THIS_e628e89ab3b1c95f: function() {
|
|
413
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
414
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
415
|
+
},
|
|
416
|
+
__wbg_static_accessor_SELF_a621d3dfbb60d0ce: function() {
|
|
417
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
418
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
419
|
+
},
|
|
420
|
+
__wbg_static_accessor_WINDOW_f8727f0cf888e0bd: function() {
|
|
421
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
422
|
+
return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
|
|
423
|
+
},
|
|
424
|
+
__wbg_subarray_a96e1fef17ed23cb: function(arg0, arg1, arg2) {
|
|
425
|
+
const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
|
|
426
|
+
return ret;
|
|
427
|
+
},
|
|
428
|
+
__wbg_value_0546255b415e96c1: function(arg0) {
|
|
429
|
+
const ret = arg0.value;
|
|
430
|
+
return ret;
|
|
431
|
+
},
|
|
432
|
+
__wbg_versions_4e31226f5e8dc909: function(arg0) {
|
|
433
|
+
const ret = arg0.versions;
|
|
434
|
+
return ret;
|
|
435
|
+
},
|
|
436
|
+
__wbindgen_cast_0000000000000001: function(arg0) {
|
|
437
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
438
|
+
const ret = arg0;
|
|
439
|
+
return ret;
|
|
440
|
+
},
|
|
441
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
442
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
443
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
444
|
+
return ret;
|
|
445
|
+
},
|
|
446
|
+
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
447
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
448
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
449
|
+
return ret;
|
|
450
|
+
},
|
|
451
|
+
__wbindgen_init_externref_table: function() {
|
|
452
|
+
const table = wasm.__wbindgen_externrefs;
|
|
453
|
+
const offset = table.grow(4);
|
|
454
|
+
table.set(0, undefined);
|
|
455
|
+
table.set(offset + 0, undefined);
|
|
456
|
+
table.set(offset + 1, null);
|
|
457
|
+
table.set(offset + 2, true);
|
|
458
|
+
table.set(offset + 3, false);
|
|
459
|
+
},
|
|
460
|
+
};
|
|
461
|
+
return {
|
|
462
|
+
__proto__: null,
|
|
463
|
+
"./agentaos_mpc_wasm_bg.js": import0,
|
|
464
|
+
};
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function addToExternrefTable0(obj) {
|
|
468
|
+
const idx = wasm.__externref_table_alloc();
|
|
469
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
470
|
+
return idx;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
function debugString(val) {
|
|
474
|
+
// primitive types
|
|
475
|
+
const type = typeof val;
|
|
476
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
477
|
+
return `${val}`;
|
|
478
|
+
}
|
|
479
|
+
if (type == 'string') {
|
|
480
|
+
return `"${val}"`;
|
|
481
|
+
}
|
|
482
|
+
if (type == 'symbol') {
|
|
483
|
+
const description = val.description;
|
|
484
|
+
if (description == null) {
|
|
485
|
+
return 'Symbol';
|
|
486
|
+
} else {
|
|
487
|
+
return `Symbol(${description})`;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
if (type == 'function') {
|
|
491
|
+
const name = val.name;
|
|
492
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
493
|
+
return `Function(${name})`;
|
|
494
|
+
} else {
|
|
495
|
+
return 'Function';
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
// objects
|
|
499
|
+
if (Array.isArray(val)) {
|
|
500
|
+
const length = val.length;
|
|
501
|
+
let debug = '[';
|
|
502
|
+
if (length > 0) {
|
|
503
|
+
debug += debugString(val[0]);
|
|
504
|
+
}
|
|
505
|
+
for(let i = 1; i < length; i++) {
|
|
506
|
+
debug += ', ' + debugString(val[i]);
|
|
507
|
+
}
|
|
508
|
+
debug += ']';
|
|
509
|
+
return debug;
|
|
510
|
+
}
|
|
511
|
+
// Test for built-in
|
|
512
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
513
|
+
let className;
|
|
514
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
515
|
+
className = builtInMatches[1];
|
|
516
|
+
} else {
|
|
517
|
+
// Failed to match the standard '[object ClassName]'
|
|
518
|
+
return toString.call(val);
|
|
519
|
+
}
|
|
520
|
+
if (className == 'Object') {
|
|
521
|
+
// we're a user defined class or Object
|
|
522
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
523
|
+
// easier than looping through ownProperties of `val`.
|
|
524
|
+
try {
|
|
525
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
526
|
+
} catch (_) {
|
|
527
|
+
return 'Object';
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
// errors
|
|
531
|
+
if (val instanceof Error) {
|
|
532
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
533
|
+
}
|
|
534
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
535
|
+
return className;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
539
|
+
ptr = ptr >>> 0;
|
|
540
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
let cachedDataViewMemory0 = null;
|
|
544
|
+
function getDataViewMemory0() {
|
|
545
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
546
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
547
|
+
}
|
|
548
|
+
return cachedDataViewMemory0;
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
function getStringFromWasm0(ptr, len) {
|
|
552
|
+
ptr = ptr >>> 0;
|
|
553
|
+
return decodeText(ptr, len);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
let cachedUint16ArrayMemory0 = null;
|
|
557
|
+
function getUint16ArrayMemory0() {
|
|
558
|
+
if (cachedUint16ArrayMemory0 === null || cachedUint16ArrayMemory0.byteLength === 0) {
|
|
559
|
+
cachedUint16ArrayMemory0 = new Uint16Array(wasm.memory.buffer);
|
|
560
|
+
}
|
|
561
|
+
return cachedUint16ArrayMemory0;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
let cachedUint8ArrayMemory0 = null;
|
|
565
|
+
function getUint8ArrayMemory0() {
|
|
566
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
567
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
568
|
+
}
|
|
569
|
+
return cachedUint8ArrayMemory0;
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function handleError(f, args) {
|
|
573
|
+
try {
|
|
574
|
+
return f.apply(this, args);
|
|
575
|
+
} catch (e) {
|
|
576
|
+
const idx = addToExternrefTable0(e);
|
|
577
|
+
wasm.__wbindgen_exn_store(idx);
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function isLikeNone(x) {
|
|
582
|
+
return x === undefined || x === null;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
function passArray16ToWasm0(arg, malloc) {
|
|
586
|
+
const ptr = malloc(arg.length * 2, 2) >>> 0;
|
|
587
|
+
getUint16ArrayMemory0().set(arg, ptr / 2);
|
|
588
|
+
WASM_VECTOR_LEN = arg.length;
|
|
589
|
+
return ptr;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
593
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
594
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
595
|
+
WASM_VECTOR_LEN = arg.length;
|
|
596
|
+
return ptr;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
600
|
+
if (realloc === undefined) {
|
|
601
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
602
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
603
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
604
|
+
WASM_VECTOR_LEN = buf.length;
|
|
605
|
+
return ptr;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
let len = arg.length;
|
|
609
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
610
|
+
|
|
611
|
+
const mem = getUint8ArrayMemory0();
|
|
612
|
+
|
|
613
|
+
let offset = 0;
|
|
614
|
+
|
|
615
|
+
for (; offset < len; offset++) {
|
|
616
|
+
const code = arg.charCodeAt(offset);
|
|
617
|
+
if (code > 0x7F) break;
|
|
618
|
+
mem[ptr + offset] = code;
|
|
619
|
+
}
|
|
620
|
+
if (offset !== len) {
|
|
621
|
+
if (offset !== 0) {
|
|
622
|
+
arg = arg.slice(offset);
|
|
623
|
+
}
|
|
624
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
625
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
626
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
627
|
+
|
|
628
|
+
offset += ret.written;
|
|
629
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
WASM_VECTOR_LEN = offset;
|
|
633
|
+
return ptr;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
function takeFromExternrefTable0(idx) {
|
|
637
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
638
|
+
wasm.__externref_table_dealloc(idx);
|
|
639
|
+
return value;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
643
|
+
cachedTextDecoder.decode();
|
|
644
|
+
function decodeText(ptr, len) {
|
|
645
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
const cachedTextEncoder = new TextEncoder();
|
|
649
|
+
|
|
650
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
651
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
652
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
653
|
+
view.set(buf);
|
|
654
|
+
return {
|
|
655
|
+
read: arg.length,
|
|
656
|
+
written: buf.length
|
|
657
|
+
};
|
|
658
|
+
};
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
let WASM_VECTOR_LEN = 0;
|
|
662
|
+
|
|
663
|
+
const wasmPath = `${__dirname}/agentaos_mpc_wasm_bg.wasm`;
|
|
664
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
665
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
666
|
+
const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
667
|
+
wasm.__wbindgen_start();
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @agentaos/crypto
|
|
2
|
+
|
|
3
|
+
**CGGMP24 threshold ECDSA WASM module for AgentaOS.**
|
|
4
|
+
|
|
5
|
+
[](../../LICENSE)
|
|
6
|
+
[](https://www.npmjs.com/package/@agentaos/crypto)
|
|
7
|
+
|
|
8
|
+
Rust-compiled WebAssembly module implementing CGGMP24 threshold ECDSA (2-of-3) over secp256k1. Built from the [LFDT-Lockness/cggmp21](https://github.com/LFDT-Lockness/cggmp21) Rust crate.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
npm install @agentaos/crypto
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What It Does
|
|
17
|
+
|
|
18
|
+
- **DKG** -- Distributed Key Generation (3-party, produces 3 shares + public key)
|
|
19
|
+
- **Signing** -- Interactive threshold signing (2-of-3, 3-round protocol)
|
|
20
|
+
- **Aux Info** -- Pre-computation of auxiliary information for signing efficiency
|
|
21
|
+
- **Key Refresh** -- Proactive share refresh without changing the public key
|
|
22
|
+
|
|
23
|
+
## Build from Source
|
|
24
|
+
|
|
25
|
+
Requires Rust toolchain with `wasm32-unknown-unknown` target:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
cd packages/mpc-wasm
|
|
29
|
+
cargo build --release --target wasm32-unknown-unknown
|
|
30
|
+
wasm-bindgen target/wasm32-unknown-unknown/release/agenta_crypto_wasm.wasm --out-dir pkg/
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Usage
|
|
34
|
+
|
|
35
|
+
This module is consumed by `@agentaos/engine`. Direct usage is not recommended -- use the higher-level `Agenta` facade from `@agentaos/sdk` instead.
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
Apache-2.0 -- see [LICENSE](../../LICENSE).
|