-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
timelockEncrypt no longer needs a client info object
* added a README * added an eslint config
- Loading branch information
1 parent
fcf1a20
commit 9f67b53
Showing
7 changed files
with
63 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
root: true, | ||
parser: "@typescript-eslint/parser", | ||
plugins: [ | ||
"@typescript-eslint", | ||
], | ||
extends: [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended", | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# tlock-js | ||
|
||
A typescript library for encrypting data which can only be decrypted at a set time in the future using [drand](https://drand.love). | ||
tlock-js uses [AGE](https://age-encryption.org/v1) to symmetrically encrypt a payload, and encrypts the symmetric key using [pairing-based cryptography](https://drand.love/docs/cryptography/#pairing-based-cryptography) ensuring that it can only be decrypted when the drand's [threshold network](https://drand.love/docs/cryptography/#randomness-generation) has generated randomness at a future point. | ||
|
||
## Prerequisites | ||
- Node 16+ | ||
|
||
## Quickstart | ||
- install the dependencies by running `npm install` | ||
- run the tests with `npm test` | ||
|
||
### `timelockEncrypt` | ||
This encrypts a payload that can only be decrypted when the `roundNumber` has been reached. | ||
The time of this `roundNumber` depends on the genesis and round frequency of the network you connect to. | ||
By default, the drand testnet HTTP client will be used, but you can implement your own and pass it in here. | ||
The output ciphertext should be compatible with any of the drand tlock implementations | ||
|
||
### `timelockDecrypt` | ||
This takes a payload that has been encrypted with any of the drand tlock implementations, reads the `roundNumber` from it and attempts to decrypt it. | ||
If the round number has not yet been reached by the network, an error will be thrown. | ||
It accepts both armored and unarmored payloads. | ||
|
||
### `roundForTime` | ||
Given a `NetworkInfo` object, it calculates what the latest-emitted round will have been at that `time` | ||
|
||
### `timeForRound` | ||
Given a `NetworkInfo` object, it calculates the approximate time the given `round` will be emitted at (approximate because the network must work together to create the randomness). | ||
|
||
## Possible issues | ||
- you may need a `fetch` polyfill on some versions of node, e.g. [isomorphic fetch](https://www.npmjs.com/package/isomorphic-fetch). You can provide your own `DrandHttpClientOptions` to the `DrandHttpClient` if you don't want to use fetch, but it may be necessary to declare a fake `fetch` somewhere for compilation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters