You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactored chain configuration, added new chains, refactored gas parameters (#11)
* added support for new networks
* refactored a bunch of configuration
* refactored gas params
* updated pinned public keys
---------
Co-authored-by: Nemitari Ajienka <nemitariajienka@gmail.com>
Copy file name to clipboardExpand all lines: README.md
+99-54Lines changed: 99 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,12 @@
1
1
## blocklock-js
2
2
3
-
blocklock-js is a TypeScript library designed to simplify the process of generating encrypted data off-chain for the dcrypt network. It enables developers to securely encrypt data tied to a user-specified future chain height. The encrypted data can then be used to create on-chain timelock encryption requests in smart contracts. Once the specified chain height is mined, the user’s smart contract will receive the decryption keys automatically.
4
-
5
-
6
-
### Key Capabilities
7
-
8
-
Using this library, developers can:
9
-
10
-
* Encode and encrypt various Solidity-compatible data types.
11
-
* Encrypt the encoded data off-chain using a public key, which can then be integrated into smart contracts for timelock encryption requests.
3
+
`blocklock-js` is a TypeScript library that simplifies generating encrypted data off-chain for use with the dcrypt network. It allows developers to securely encrypt data tied to a user-defined condition, e.g., a future block height. This encrypted payload can then be referenced in on-chain timelock encryption requests via smart contracts. Once the specified block is mined, the decryption key is automatically delivered to the smart contract via a callback, enabling conditional data access on-chain.
12
4
5
+
The library also enables developers to track the status of a conditional encryption request.
13
6
14
7
### On-Chain Integration
15
8
16
-
Solidity interfaces and associated documentation for them can be found in the [blocklock-solidity](https://github.com/randa-mu/blocklock-solidity.git) repository.
9
+
Solidity interfaces and associated documentation can be found in the [blocklock-solidity](https://github.com/randa-mu/blocklock-solidity.git) repository.
17
10
18
11
#### Smart Contract Addresses
19
12
@@ -27,8 +20,13 @@ A lightweight proxy contract that enables upgradeability for the `BlocklockSende
| Sei Testnet |[0xd22302849a87d5B00f13e504581BC086300DA080](https://seitrace.com/address/0xd22302849a87d5B00f13e504581BC086300DA080?chain=atlantic-2)|
27
+
30
28
31
-
**Others**
29
+
**Other contract addresses**
32
30
You should only need the `BlocklockSender` proxy above, but a full list of contract addresses can be found in the [solidity repo's README](https://github.com/randa-mu/blocklock-solidity).
33
31
34
32
@@ -41,53 +39,68 @@ npm install blocklock-js
41
39
```
42
40
43
41
44
-
45
42
### Usage Example
46
43
47
44
#### Prerequisites
48
45
49
46
*[ethers](https://www.npmjs.com/package/ethers) for wallet setup and message encoding.
47
+
* Node.js v22+
48
+
49
+
#### Setup
50
50
51
+
1. Create a `.env` file or set the following environment variables, e.g., for Filecoin mainnet:
51
52
52
-
Here’s how to use BlocklockJS to encrypt data and create an on-chain timelock encryption request.
53
+
```bash
54
+
RPC_URL=https://your-rpc-url
55
+
PRIVATE_KEY=your_private_key
56
+
```
53
57
54
-
#### Example: Encrypting a uint256 (4 ETH) for Decryption 2 Blocks Later
58
+
2. Install dependencies:
59
+
60
+
```bash
61
+
npm install
62
+
```
63
+
64
+
65
+
#### Usage example
66
+
67
+
This example demonstrates encrypting a `uint256` value and using the Ciphertext and condition bytes in a user smart contract that implements the `createTimelockRequestWithDirectFunding` function to create a timelock encryption request on-chain. An example use case is a sealed-bid auction where bid amounts are encrypted and only decrypted at the auction ending block number.
55
68
56
-
This example demonstrates encrypting a uint256 value and sending it to a user smart contract that implements the createTimelockRequest function. In a different use case, e.g., sealed bid auction, this could be refactored into a `sealedBid` function.
57
69
The example user smart contract source code can be found [here](https://github.com/randa-mu/blocklock-solidity/blob/main/src/mocks/MockBlocklockReceiver.sol).
* Stores the encrypted data (Ciphertext) and decryption condition on-chain via the `BlocklockSender` contract.
120
160
121
-
2. On-Chain Interaction:
161
+
* Funds the request by paying the `requestPrice` via the transaction.
122
162
123
-
*Call the appropriate function in the user contract with the encrypted data and the chain height used during off-chain encryption. In this example, the `createTimelockRequestWithDirectFunding` function is called, which calls the [BlocklockSender](https://github.com/randa-mu/blocklock-solidity/blob/main/src/blocklock/BlocklockSender.sol) contract to create an on-chain timelock request with the encrypted data and condition (represented as bytes to support different condition types) for decryption, using the direct funding method. The `BlocklockSender` contract then stores the encrypted data, and generates a unique request ID. The `BlocklockSender` contract also supports a subscription funding method. To make a request via that is paid for via a funded subscription account, the `createTimelockRequestWithSubscription` function in the [example](https://github.com/randa-mu/blocklock-solidity/blob/main/src/mocks/MockBlocklockReceiver.sol) smart contract code can be called.
163
+
* Generates a unique request ID.Call the appropriate function in the user contract with the encrypted data and the chain height used during off-chain encryption.
* After the specified chain height, the on-chain timelock contract triggers a callback to the user's contract, providing the decryption key. The user's contract can then call the `decrypt` function in the `BlocklockSender` contract to perform on-chain decryption using the provided decryption key.
0 commit comments