This is the Shutter SDK for the Shutter Network. It is a TypeScript library that provides functions for encrypting and decrypting data using the Shutter Network's encryption protocol.
npm install @shutter-network/shutter-sdk
If you're using this SDK in a browser environment (e.g., React, Next.js, etc), the SDK dynamically loads blst.js
and blst.wasm
files. You must make these files available to the browser by placing them in your public/static directory:
my-app/
├── public/
│ ├── blst.js
│ └── blst.wasm
Both these files are available in the sdk under src/crypto/blst
. Copy it from there.
To avoid manually copying the blst.js and blst.wasm files, you can add a postinstall script in your project's package.json:
{
"scripts": {
"postinstall": "cp node_modules/@shutter-network/shutter-sdk/dist/blst.js public/blst.js && cp node_modules/@shutter-network/shutter-sdk/dist/blst.wasm public/blst.wasm"
}
}
Run the following command to trigger the script:
npm install
If you're using Vite and encounter errors like:
The dependency might be incompatible with the dep optimizer. Try adding it to optimizeDeps.exclude.
You may need to exclude the SDK from optimization. Add this to your vite.config.ts:
export default defineConfig({
...
optimizeDeps: {
exclude: ['@shutter-network/shutter-sdk'],
},
});
import { encryptData } from "@shutter-network/shutter-sdk";
const msgHex = "0x1c";
const eonKeyHex = "0x8b36251faf28be849a2ca9212ae7ceeb6b6848d58a3d5d77e1629c9d7ebdee3dad594c6af6b66e7a6e4b27e54778b8fd1491868c2938c93285be79168c0210d632a2a553f6b03940dd08312d32ea718e0f8c4488f39e6f34e27add4506631ddb";
const identityPreimageHex = "0x8c4e6301fba207fb2375d2fda9f2ebe1142d07d1954d871e2d71b3d93534380793b99fb184f7526012a49ac1a22300fac22dc1d7";
const sigmaHex = "0x312c10b186086d502ba683cffc2ae650d53b508904b3c430df8e7d5aa336c0f5";
// Call encryptData function
const encryptedData = await encryptData(msgHex, identityPreimageHex, eonKeyHex, sigmaHex);
console.log("Encryption successful:", encryptedData);
import { decrypt } from "@shutter-network/shutter-sdk";
const encryptedData = "0x03a975256b0098bc981da31762a73e50a07c79f5bf3e17c44121b9567033cedaf9e203f0300b709dec3458a88baa18963c0e503f437bff7adb31231941585ea1bb14e8ce98c7dc1471666e4b07c592cbeda30acc22f23dcb84d58d41848e72af0804d348d5c5cb65a52dc3b697ea4caae9679b97e395a30807f9657ebc85bbf2fcadaa9a458a86bffb78dde89f7626a26eb84f4781d3b6759c06629ea321a8b757"
const decryptionKey = "0x81cfcfceebfc69b3cb3fe074f4b3751e7844f6d62b3040563ccb3a2430110f259d109519c73682735f4c02651492c740"
// Call decrypt function
const decryptedData = await decrypt(encryptedData, decryptionKey);
console.log("Decryption successful:", decryptedData);
npm run test
npm run build
Feel free to open an issue on GitHub