@inco/js 0.1.32 → 0.1.33
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/README.md +28 -57
- package/dist/encryption/index.cjs +132 -123
- package/dist/encryption/index.mjs +132 -123
- package/dist/index.cjs +140 -131
- package/dist/index.mjs +140 -131
- package/dist/lite/index.cjs +186 -146
- package/dist/lite/index.mjs +3890 -3788
- package/dist/lite/reencrypt.d.ts +1 -0
- package/dist/lite/reencrypt.js +21 -2
- package/dist/local/index.cjs +25 -2573
- package/dist/local/index.mjs +5352 -7837
- package/dist/reencryption/index.cjs +132 -123
- package/dist/reencryption/index.mjs +132 -123
- package/dist/viem.d.ts +53 -52
- package/package.json +1 -1
package/README.md
CHANGED
@@ -4,7 +4,7 @@ The @inco/js package contains the TypeScript SDK for creating dapps built on Inc
|
|
4
4
|
|
5
5
|
## Current Status: Active Development
|
6
6
|
|
7
|
-
The SDK is currently going through active development, to support all new features that Inco offers. As such, do expect breaking changes in subsequent releases, which will be documented in the [CHANGELOG](./CHANGELOG.md).
|
7
|
+
The SDK is currently going through active development, to support all new features that Inco offers. As such, do expect breaking changes in subsequent releases, which will be documented in the [CHANGELOG](./CHANGELOG.md).
|
8
8
|
|
9
9
|
## Install
|
10
10
|
|
@@ -29,76 +29,47 @@ A typical usage of `@inco/js` includes 3 steps:
|
|
29
29
|
### 1. Encrypt a value
|
30
30
|
|
31
31
|
```ts
|
32
|
-
import {
|
33
|
-
import {
|
34
|
-
import {
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
} from '@inco/js/lite';
|
40
|
-
import { createWalletClient, hexToBytes } from 'viem';
|
41
|
-
|
42
|
-
// Setup. Do it once at initialization.
|
43
|
-
const chain = getSupportedChain('baseSepolia');
|
44
|
-
const lightningConfig = getActiveLightningDeployment(chain);
|
32
|
+
import { getViemChain, supportedChains } from '@inco/js';
|
33
|
+
import { Lightning } from '@inco/js/lite';
|
34
|
+
import { createWalletClient } from 'viem';
|
35
|
+
|
36
|
+
// Setup: do it once at initialization
|
37
|
+
const chainId = supportedChains.baseSepolia;
|
38
|
+
const zap = Lightning.latest('testnet', chainId); // Connect to Inco's latest public testnet
|
45
39
|
const walletClient = createWalletClient({
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
chain: getViemChain(chainId),
|
41
|
+
account: /* Choose your account, e.g. from window.ethereum */,
|
42
|
+
transport: /* Choose your transport, e.g. from Alchemy */,
|
49
43
|
});
|
50
|
-
const dappAddress = '
|
51
|
-
|
52
|
-
//
|
53
|
-
const plaintext =
|
54
|
-
const
|
55
|
-
|
56
|
-
|
57
|
-
value: plaintext,
|
58
|
-
type: handleTypes.euint256,
|
59
|
-
},
|
60
|
-
context: {
|
61
|
-
hostChainId: BigInt(chain.id),
|
62
|
-
aclAddress: lightningConfig.executorAddress,
|
63
|
-
userAddress: walletClient.account.address,
|
64
|
-
contractAddress: dappAddress,
|
65
|
-
},
|
66
|
-
};
|
67
|
-
|
68
|
-
// Encrypt.
|
69
|
-
const ephemeralKeypair = await generateSecp256k1Keypair();
|
70
|
-
const eciesPubKey = decodeSecp256k1PublicKey(hexToBytes(lightningConfig.eciesPublicKey));
|
71
|
-
const encryptor = getEciesEncryptor({
|
72
|
-
scheme: encryptionSchemes.ecies,
|
73
|
-
pubKeyA: eciesPubKey,
|
74
|
-
privKeyB: ephemeralKeypair,
|
44
|
+
const dappAddress = '0x00000000000000000000000000000000deadbeef'; // Put your contract address here
|
45
|
+
|
46
|
+
// Encrypt the plaintext value
|
47
|
+
const plaintext = 42;
|
48
|
+
const ciphertext = await zap.encrypt(plaintext, {
|
49
|
+
accountAddress: walletClient.account.address,
|
50
|
+
dappAddress,
|
75
51
|
});
|
76
|
-
|
77
|
-
console.log(ciphertext
|
52
|
+
|
53
|
+
console.log(ciphertext); // A long hex string representing the encrypted value
|
78
54
|
```
|
79
55
|
|
80
56
|
### 2. Post the ciphertext to the contract
|
81
57
|
|
82
|
-
|
58
|
+
This step does not require any specific `@inco/js` functionality. We recommend using [viem](https://viem.sh) to interact with the blockchain. Specifically, use the [`writeContract`](https://viem.sh/docs/contract/writeContract) method to submit transactions. Pass the `ciphertext` from the previous encryption step as the input ciphertext parameter of type `bytes`.
|
83
59
|
|
84
60
|
### 3. Request a reencryption
|
85
61
|
|
86
|
-
|
62
|
+
Following transaction submission, the Inco covalidator processes the computation request. The contract stores the computation result as a handle on-chain. This handle, referenced below as `resultHandle`, is a hexadecimal string of type `Handle` that serves as a reference to the encrypted computation output.
|
87
63
|
|
88
64
|
```ts
|
89
|
-
import { incoLiteReencryptor } from "@inco/js/lite";
|
90
65
|
import { Hex } from "viem";
|
91
66
|
|
92
|
-
//
|
93
|
-
|
94
|
-
const reencryptor = await
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
const resultPlaintext = await reencryptor({
|
99
|
-
handle: resultHandle,
|
100
|
-
});
|
101
|
-
console.log(resultPlaintext.value); // Plaintext of the final result after computation
|
67
|
+
// Request a re-encryption of the result ciphertext
|
68
|
+
const resultHandle = "0x..." as Hex; // Retrieve the handle from the contract, e.g. using viem
|
69
|
+
const reencryptor = await zap.getReencryptor(walletClient); // Use same walletClient as previous step
|
70
|
+
const resultPlaintext = await reencryptor({ handle: resultHandle });
|
71
|
+
|
72
|
+
console.log(resultPlaintext.value); // The decrypted value
|
102
73
|
```
|
103
74
|
|
104
75
|
## License
|