Skip to content

Commit 677a2be

Browse files
authored
Merge pull request #32 from ideal-lab5/dev
update ts readme
2 parents 05b5176 + 51c0d73 commit 677a2be

1 file changed

Lines changed: 9 additions & 18 deletions

File tree

ts/README.md

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@ See the [example](../examples/web/react-tlock-demo/) for a full demonstration.
3737

3838
### Initialization
3939

40-
Before using any encryption or decryption methods, initialize the library by creating a Timelock instance:
41-
4240
``` js
43-
import { SupportedBeacon, Timelock } from '@ideallabs/timelock.js'
44-
// Use curve BLS12-381 (e.g. Drand Quicknet)
45-
const timelockBls12_381 = await Timelock.build(SupportedCurve.BLS12_381);
46-
// Use curve BLS12-377 (e.g. IDN Beacon)
47-
const timelockBls12_377 = await Timelock.build(SupportedCurve.BLS12_377);
41+
import { Timelock } from '@ideallabs/timelock.js'
42+
// Uses curve BLS12-381 (e.g. Drand Quicknet)
43+
const timelock = await Timelock.build();
4844
```
4945

5046
### Encrypting a Message
@@ -56,7 +52,7 @@ Messages can be encrypted for future rounds of a supported beacon's protocol by
5652
import { Timelock, DrandIdentityHandler } from '@ideallabs/timelock.js'
5753

5854
import hkdf from 'js-crypto-hkdf'
59-
// 1. Setup parameters for encryption
55+
// Setup parameters for encryption
6056
// use an hkdf to generate an ephemeral secret key
6157
const seed = new TextEncoder().encode('my-secret-seed')
6258
const hash = 'SHA-256'
@@ -68,14 +64,12 @@ const key = Array.from(esk.key)
6864
// the message to encrypt for the future
6965
const message = 'Hello, Timelock!'
7066
const encodedMessage = new TextEncoder().encode(message)
71-
// A randomness beacon public key (ex: IDN public key)
72-
// We first get it as hex and then convert to a Uint8Array
67+
// A randomness beacon public key (ex: Drand public key)
7368
const pubkey =
74-
'41dc53da3d3617a189c85c8cb51a5f4fdfcebda05c50e81595f69e178d240fce3acdafd97b5fd204553e685836393a00b112f5cd78477d79ac8094c608d35bb42bd5091c5bbedd881e2ee0e8492a4361c69bf15250d75aee44035bc5b7553100'
69+
'83cf0f2896adee7eb8b5f01fcad3912212c437e0073e911fb90022d3e760183c8c4b450b6a0a6c3ac6a5776a2d1064510d1fec758c921cc22b0e17e63aaf4bcb5ed66304de9cf809bd274ca73bab4af5a6e9c76a4bc09e76eae8991ef5ece45a'
7570
// A future round number of the randomness beacon
7671
const roundNumber = 10
77-
78-
// 2. Encrypt the message
72+
// Encrypt the message
7973
let ct = await Timelock.encrypt(
8074
encodedMessage,
8175
roundNumber,
@@ -91,7 +85,7 @@ console.log('Timelocked ciphertext: ' + JSON.stringify(ct))
9185

9286
Any given randomness beacon may sign messages in its own unique way. For example, in Drand's Quicknet the beacon signs the sha256 hash of the round number of the procol as a big endian array (8 bytes from a u64 round number). In the Ideal network, the message is the sha256 hash of the round number concatenated with the validator set id of the set of validators that produced the beacon.
9387

94-
This library offers pre-defined identity handlers for usage with Drand Quicknet and the IDN beacon, the [DrandIdentityHandler](./src/interfaces/DrandIdentityBuilder.ts) and [IdealNetworkIdentityHandler](./src/interfaces/IDNIdentityBuilder.ts), respectively. For beacons that construct messages differently, a custom identity handler must be implemented.
88+
This library offers a pre-defined identity handler for usage with Drand Quicknet, the [DrandIdentityHandler](./src/interfaces/DrandIdentityBuilder.ts). For beacons that construct messages differently, a custom identity handler must be implemented.
9589

9690
### Decrypting a Message
9791

@@ -102,7 +96,7 @@ Decrypt data using a beacon signature:
10296
const sig =
10397
'e6cdf6c9d11c13e013b2c6cfd11dab46d8f1ace226ff845ffff4c7d6f64992892c54fb5d1f0f87dd300ce66f53598e01'
10498
// Decrypt the ciphertext with the signature
105-
const plaintext = await timelockIdeal.decrypt(ct, sig)
99+
const plaintext = await timelock.decrypt(ct, sig)
106100
console.log(`Recovered ${String.fromCharCode(...plaintext)}, Expected ${message}`)
107101
```
108102

@@ -126,6 +120,3 @@ console.log('Plaintext:', plaintext);
126120
## License
127121

128122
Apache-2.0
129-
130-
131-
TODO: Investigate time-to-drand-round function

0 commit comments

Comments
 (0)