@zama-fhe/relayer-sdk 0.1.0-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +55 -0
- package/bin/relayer.js +61 -0
- package/bin/utils.js +14 -0
- package/bundle/fhevm.js +40713 -0
- package/bundle/fhevm.umd.cjs +24 -0
- package/bundle/kms_lib_bg.wasm +0 -0
- package/bundle/tfhe_bg.wasm +0 -0
- package/bundle/workerHelpers.js +2 -0
- package/bundle.d.ts +1 -0
- package/bundle.js +12 -0
- package/lib/config.d.ts +30 -0
- package/lib/index.d.ts +29 -0
- package/lib/init.d.ts +7 -0
- package/lib/kms_lib_bg.wasm +0 -0
- package/lib/node.cjs +1152 -0
- package/lib/node.d.ts +2 -0
- package/lib/relayer/decryptUtils.d.ts +2 -0
- package/lib/relayer/handles.d.ts +4 -0
- package/lib/relayer/network.d.ts +31 -0
- package/lib/relayer/network.test.d.ts +1 -0
- package/lib/relayer/publicDecrypt.d.ts +3 -0
- package/lib/relayer/publicDecrypt.test.d.ts +1 -0
- package/lib/relayer/sendEncryption.d.ts +41 -0
- package/lib/relayer/sendEncryption.test.d.ts +1 -0
- package/lib/relayer/userDecrypt.d.ts +11 -0
- package/lib/relayer/userDecrypt.test.d.ts +1 -0
- package/lib/sdk/encrypt.d.ts +34 -0
- package/lib/sdk/encrypt.test.d.ts +1 -0
- package/lib/sdk/encryptionTypes.d.ts +13 -0
- package/lib/sdk/keypair.d.ts +34 -0
- package/lib/sdk/keypair.test.d.ts +1 -0
- package/lib/test/index.d.ts +10 -0
- package/lib/tfhe.d.ts +7 -0
- package/lib/tfhe_bg.wasm +0 -0
- package/lib/utils.d.ts +9 -0
- package/lib/web.d.ts +2 -0
- package/lib/web.js +27305 -0
- package/lib/workerHelpers.js +24774 -0
- package/node.d.ts +1 -0
- package/node.js +1 -0
- package/package.json +99 -0
- package/web.d.ts +1 -0
- package/web.js +1 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023, Zama
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img width=600 src="https://github.com/user-attachments/assets/6173e401-7c1b-4911-9731-ca2eb436e85f" />
|
|
3
|
+
</p>
|
|
4
|
+
<hr/>
|
|
5
|
+
<p align="center">
|
|
6
|
+
<!-- TODO: Migrate documentation links to https://docs.zama.ai/relayer -->
|
|
7
|
+
<a href="https://docs.zama.ai/fhevm">📃 Read white paper</a> | <a href="https://docs.zama.ai/fhevm">📒 Read documentation</a> | <a href="https://zama.ai/community">💛 Community support</a>
|
|
8
|
+
</p>
|
|
9
|
+
<p align="center">
|
|
10
|
+
<!-- Version badge using shields.io -->
|
|
11
|
+
<a href="https://github.com/zama-ai/relayer-sdk/releases"><img src="https://img.shields.io/github/v/release/zama-ai/relayer-sdk?style=flat-square"/></a>
|
|
12
|
+
<!-- Zama Bounty Program -->
|
|
13
|
+
<a href="https://github.com/zama-ai/bounty-program"><img src="https://img.shields.io/badge/Contribute-Zama%20Bounty%20Program-yellow?style=flat-square"/></a>
|
|
14
|
+
</p>
|
|
15
|
+
<hr/>
|
|
16
|
+
|
|
17
|
+
fhevm SDK is a javascript library that enables developers to interact with blockchains using Zama's cutting-edge technology based on TFHE (Fully Homomorphic Encryption over the Torus). This library provides a seamless integration of TFHE encryption capabilities into web3 applications, allowing for secure and private interactions with smart contracts.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Using npm
|
|
23
|
+
npm install @zama-fhe/relayer-sdk
|
|
24
|
+
|
|
25
|
+
# Using Yarn
|
|
26
|
+
yarn add @zama-fhe/relayer-sdk
|
|
27
|
+
|
|
28
|
+
# Using pnpm
|
|
29
|
+
pnpm add @zama-fhe/relayer-sdk
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
This will download and install the fhevm Relayer SDK and its dependencies into your project.
|
|
33
|
+
|
|
34
|
+
## Contributing
|
|
35
|
+
|
|
36
|
+
There are two ways to contribute to the Relayer SDK:
|
|
37
|
+
|
|
38
|
+
- you can open issues to report bugs or typos, or to suggest new ideas
|
|
39
|
+
- you can ask to become an official contributor by emailing hello@zama.ai. (becoming an approved contributor involves signing our Contributor License Agreement (CLA))
|
|
40
|
+
Only approved contributors can send pull requests, so please make sure to get in touch before you do!
|
|
41
|
+
|
|
42
|
+
## Credits
|
|
43
|
+
|
|
44
|
+
This library uses several dependencies and we would like to thank the contributors of those libraries.
|
|
45
|
+
|
|
46
|
+
## Need support?
|
|
47
|
+
|
|
48
|
+
<a target="_blank" href="https://community.zama.ai">
|
|
49
|
+
<img src="https://github.com/zama-ai/relayer-sdk/assets/1384478/4fc4e460-ca1d-4910-8bc2-cd1d50c7d020">
|
|
50
|
+
</a>
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
This software is distributed under the BSD-3-Clause-Clear license. If you have any questions,
|
|
55
|
+
please contact us at `hello@zama.ai`.
|
package/bin/relayer.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
import { program } from 'commander';
|
|
5
|
+
import { toHexString, prependHttps, throwError } from './utils.js';
|
|
6
|
+
import { createInstance } from '../lib/node.cjs';
|
|
7
|
+
|
|
8
|
+
const allowedBits = [1, 4, 8, 16, 32, 64];
|
|
9
|
+
|
|
10
|
+
const FHE_LIB_ADDRESS = '0x000000000000000000000000000000000000005d';
|
|
11
|
+
|
|
12
|
+
let _instance;
|
|
13
|
+
|
|
14
|
+
const getInstance = async (networkUrl) => {
|
|
15
|
+
if (_instance) return _instance;
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
_instance = await createInstance({ networkUrl });
|
|
19
|
+
} catch (e) {
|
|
20
|
+
return throwError(
|
|
21
|
+
`This network (${networkUrl}) doesn't seem to use Fhevm or use an incompatible version.`,
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
return _instance;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.command('encrypt')
|
|
29
|
+
.argument('<contractAddress>', 'address of the contract')
|
|
30
|
+
.argument('<userAddress>', 'address of the account')
|
|
31
|
+
.argument('<values:bits...>', 'values with number of bits eg: 1:1 3324242:64')
|
|
32
|
+
.action(async (contractAddress, userAddress, valuesArr, options) => {
|
|
33
|
+
const host = prependHttps(options.node);
|
|
34
|
+
const instance = await getInstance(host);
|
|
35
|
+
const encryptedInput = instance.createEncryptedInput(
|
|
36
|
+
contractAddress,
|
|
37
|
+
userAddress,
|
|
38
|
+
);
|
|
39
|
+
valuesArr.forEach((str, i) => {
|
|
40
|
+
const [value, bits] = str.split(':');
|
|
41
|
+
if (!allowedBits.includes(+bits)) throwError('Invalid number of bits');
|
|
42
|
+
const suffix = +bits === 1 ? 'Bool' : bits === '160' ? 'Address' : bits;
|
|
43
|
+
try {
|
|
44
|
+
encryptedInput[`add${suffix}`](parseInt(value, 10));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return throwError(e.message);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
const result = await encryptedInput.encrypt();
|
|
50
|
+
|
|
51
|
+
console.log('Input proof:');
|
|
52
|
+
console.log(`0x${toHexString(result.inputProof)}`);
|
|
53
|
+
console.log('Handles:');
|
|
54
|
+
result.handles.forEach((handle, i) => {
|
|
55
|
+
console.log(`Handle ${i}`);
|
|
56
|
+
console.log(`0x${toHexString(handle)}`);
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.requiredOption('-n, --node <url>', 'url of the blockchain');
|
|
60
|
+
|
|
61
|
+
program.parseAsync(process.argv);
|
package/bin/utils.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const prependHttps = (host) => {
|
|
2
|
+
if (!/^https?:\/\//i.test(host)) {
|
|
3
|
+
return 'https://' + host;
|
|
4
|
+
}
|
|
5
|
+
return host;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const toHexString = (bytes) =>
|
|
9
|
+
bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
|
|
10
|
+
|
|
11
|
+
export const throwError = (error) => {
|
|
12
|
+
console.error(`Error: ${error}`);
|
|
13
|
+
process.exit();
|
|
14
|
+
};
|