Skip to content

Commit 05b5176

Browse files
authored
Merge pull request #31 from ideal-lab5/dev
Simplify TS bindings
2 parents 509fca7 + a6bbe0a commit 05b5176

10 files changed

Lines changed: 69 additions & 143 deletions

File tree

Cargo.lock

Lines changed: 18 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
members = ["timelock", "wasm", "timelock-ffi"]
33
resolver = "2"
44

5-
65
[workspace.package]
76
edition = "2021"
87
authors = ["Ideal Labs <hello@idealabs.network>"]

py/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "timelock"
3-
version = "0.0.1-dev"
3+
version = "0.0.2-dev"
44
authors = [
55
{ name="Ideal Labs", email="hello@idealabs.network" },
66
]

ts/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Timelock Encyrption TypeScript Wrapper
22

3-
This is a typescript library for timelock encryption. It is a "thin" wrapper that calls the WebAssembly (WASM) implementation of timelock encryption. It is designed for use in web-based environments and easily integrates with frameworks like React, Vue, etc. The library supports both the experiemental [Ideal Network beacon](https://docs.idealabs.network) as well as [Drand's](https://drand.love) Quicknet.
3+
This is a typescript library for timelock encryption. It is a "thin" wrapper that calls the WebAssembly (WASM) implementation of timelock encryption. It is designed for use in web-based environments and easily integrates with frameworks like React, Vue, etc. The library supports [Drand's](https://drand.love) Quicknet.
44

55
## Installation
66

@@ -53,7 +53,7 @@ Messages can be encrypted for future rounds of a supported beacon's protocol by
5353

5454
``` js
5555
// import a pre-defined IdentityHandler implementation or create your own
56-
import { Timelock, IdealNetworkIdentityHandler } from '@ideallabs/timelock.js'
56+
import { Timelock, DrandIdentityHandler } from '@ideallabs/timelock.js'
5757

5858
import hkdf from 'js-crypto-hkdf'
5959
// 1. Setup parameters for encryption
@@ -76,7 +76,7 @@ const pubkey =
7676
const roundNumber = 10
7777

7878
// 2. Encrypt the message
79-
let ct = await timelockIdeal.encrypt(
79+
let ct = await Timelock.encrypt(
8080
encodedMessage,
8181
roundNumber,
8282
DrandIdentityBuilder,

ts/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,4 @@
1515
*/
1616

1717
export * from './timelock'
18-
export { IdentityBuilder } from './interfaces/IIdentityBuilder'
1918
export { DrandIdentityBuilder } from './interfaces/DrandIdentityBuilder'

ts/src/timelock.ts

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ export enum TimelockErrors {
3232
ERR_UNEXPECTED_TYPE = "The wasm returned something that could not be converted to a UInt8Array."
3333
}
3434

35-
/**
36-
* Curves supported by the timelock library
37-
*/
38-
export enum SupportedCurve {
39-
BLS12_377 = 'bls12_377',
40-
BLS12_381 = 'bls12_381'
41-
}
42-
4335
/**
4436
* A wrapper type to handle generic results
4537
*/
@@ -63,27 +55,20 @@ export class Timelock {
6355
*/
6456
private wasmReady: boolean
6557

66-
/**
67-
* The curve used by the beacon
68-
*/
69-
public curveId: SupportedCurve
70-
7158
/**
7259
* A private constructor to enforce usage of `build`
7360
*/
74-
private constructor(curveId: SupportedCurve) {
75-
this.curveId = curveId
61+
private constructor() {
7662
this.wasmReady = false
7763
}
7864

7965
/**
8066
* Loads the wasm and constructs a new Timelock instance
81-
* @param curveId: The curve used by the beacon
8267
* @returns A Timelock instance
8368
*/
84-
public static async build(curveId: SupportedCurve) {
69+
public static async build() {
8570
await init()
86-
return new Timelock(curveId)
71+
return new Timelock()
8772
}
8873

8974
/**
@@ -108,7 +93,7 @@ export class Timelock {
10893
const beaconPublicKey = u8a(beaconPublicKeyHex)
10994
const ephemeralSecretKey = u8a(ephemeralSecretKeyHex)
11095
const id = await identityBuilder.build(roundNumber)
111-
const ciphertext = tle(id, encodedMessage, ephemeralSecretKey, beaconPublicKey, this.curveId)
96+
const ciphertext = tle(id, encodedMessage, ephemeralSecretKey, beaconPublicKey)
11297
const result = new Uint8Array(ciphertext)
11398
return ok(result)
11499
} catch (err) {
@@ -130,7 +115,7 @@ export class Timelock {
130115
try {
131116
await this.checkWasm()
132117
const signature = u8a(signatureHex)
133-
return ok(new Uint8Array(tld(ciphertext, signature, this.curveId)))
118+
return ok(new Uint8Array(tld(ciphertext, signature)))
134119
} catch (err) {
135120
return error(err.message)
136121
}
@@ -150,7 +135,7 @@ export class Timelock {
150135
try {
151136
await this.checkWasm()
152137
const ephemeralSecretKey = u8a(ephemeralSecretKeyHex)
153-
return ok(new Uint8Array(decrypt(ciphertext, ephemeralSecretKey, this.curveId)))
138+
return ok(new Uint8Array(decrypt(ciphertext, ephemeralSecretKey)))
154139
} catch (err) {
155140
return error(err.message)
156141
}

wasm/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ wasm-opt = false
2020
[dependencies]
2121
codec.workspace = true
2222
rand_chacha.workspace = true
23+
rand.workspace = true
2324
timelock.workspace = true
2425
serde.workspace = true
2526
serde-wasm-bindgen.workspace = true

wasm/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export PYO3_CROSS_PYTHON_VERSION="3.10"
2525
maturin develop --features "python"
2626
```
2727

28+
#### Testing
29+
30+
Run wasm-pack tests with `wasm-pack test --node`
31+
2832
#### Publish
2933

3034
``` sh

0 commit comments

Comments
 (0)