-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactor, add ts and wasm #1
Conversation
driemworks
commented
Nov 14, 2024
•
edited
Loading
edited
- includes the wasm bindings and typescript wrapper for them (formerly etf-sdk-wasm and etf.js, respectively)
- tightly couples the tle rust library, wasm bindings, and typescript wrapper, allowing for easy maintenance of updates to the API as the library evolves, as the ts piece of the library directly depends on the rust one.
- tle.js becoms etf.js and we no longer publish the wasm-pack output to npm
- The build script is modified to build the wasm and freshly install dependencies before transpiling to typescript
- also includes several update to the tlock API to allow for greater flexibility:
- introduces a StreamCipherProvider trait and AESGCMStreamCipherProvider implementation. This allows for the library to be unopinionated, allowing an implementor to specify the encryption mechanism and CSPRNG used. For example, we could implement tlock using age in the near future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that many of the requested changes come inherited from the source repo. But we need to clean up.
- Generally, we can't merge commented-out code to the main branch.
- There are still mentions of ETF everywhere.
- Some nits, like using capital letters to start docs comments, or add descriptions to todos
There are also more things to do but I reckon they should be done as separate issues, these are:
- code formatting
- use mocks in the tests
- update the RPCs urls
the same rustfmt.toml from the murmur crate is used here, except I shortened line lengths to 80 instead of 100, can change it back if you prefer but I like the shorter lines more.
What tests require mocks?
|
we should implement a process that enforces this.
The majority of these mentions are in the copied TS wrapper (etf.js). I removed references in the core/wasm libs but created a new issue to address etf.js (and migrate it to tle.js or whichever name we land on: #6 |
I prefer 100, but is not a big deal if we are consistent across repos. The styling issues I saw were on JS actually
This is what I meant #1 (comment)
This is related to this comment #1 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I started reviewing it and got bored of code clean-up comments.
This needs some "search and replace" tle
-> timelock
, 'etf->
timelock,
ETF Network->
Ideal Network`. File renaming, probably? Removing commented-out code.
/// The expected length of a nonce used with AES_GCM | ||
const AES_GCM_NONCE_LEN: usize = 12; | ||
|
||
/// Errors that mayb be encountered with using a stream cipher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Errors that mayb be encountered with using a stream cipher | |
/// Errors that may be encountered with using a stream cipher |
ts/src/index.js
Outdated
@@ -0,0 +1 @@ | |||
export * from './tle'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export * from './tle'; | |
export * from './timelock'; |
"description": "a typescript sdk for timelock encryption/decryption with the Ideal Network", | ||
"name": "@ideallabs/timelock.js", | ||
"version": "0.0.1", | ||
"description": "A typescript interface for timelock encryption", | ||
"license": "GPL-3.0", | ||
"repository": "https://github.com/ideal-lab5/tle", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"repository": "https://github.com/ideal-lab5/tle", | |
"repository": "https://github.com/ideal-lab5/timelock", |
ts/src/tle.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this file be renamed to timelock
?
ts/src/tle.js
Outdated
export async function timelockEncrypt(encodedMessage, roundNumber, identityBuilder, beaconPublicKey, seed) { | ||
await init(); | ||
// TODO: fine for now but should ultimately query the BABE pallet config instead | ||
// https://github.com/ideal-lab5/tle/issues/7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// https://github.com/ideal-lab5/tle/issues/7 | |
// https://github.com/ideal-lab5/timelock/issues/7 |
ts/src/tle.test.spec.js
Outdated
@@ -0,0 +1,40 @@ | |||
import { describe } from '@jest/globals'; | |||
import { timelockEncrypt, IdealNetworkIdentityHandler } from './tle'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import { timelockEncrypt, IdealNetworkIdentityHandler } from './tle'; | |
import { timelockEncrypt, IdealNetworkIdentityHandler } from './timelock'; |
ts/src/tle.test.spec.js
Outdated
// it('should timelock decrypt a message', async () => { | ||
// const blockNumber = 1; | ||
// const ciphertext = new Uint8Array(1); | ||
// const signature = new Uint8Array(2); | ||
// const result = await timelockDecrypt(ciphertext, signature); | ||
// expect(result).toEqual({ | ||
// message: 'mocked-decrypted', | ||
// sk: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] | ||
// }) | ||
// }) | ||
// it('should decrypt a message on demand if the user knows the secret', async () => { | ||
// const secret = "shhh, it's a secret"; | ||
// const ciphertext = 'ciphertext' | ||
// const result = await decrypt(ciphertext, secret); | ||
// expect(result).toEqual({ | ||
// message: 'mocked-decrypted', | ||
// sk: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] | ||
// }) | ||
// }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// it('should timelock decrypt a message', async () => { | |
// const blockNumber = 1; | |
// const ciphertext = new Uint8Array(1); | |
// const signature = new Uint8Array(2); | |
// const result = await timelockDecrypt(ciphertext, signature); | |
// expect(result).toEqual({ | |
// message: 'mocked-decrypted', | |
// sk: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] | |
// }) | |
// }) | |
// it('should decrypt a message on demand if the user knows the secret', async () => { | |
// const secret = "shhh, it's a secret"; | |
// const ciphertext = 'ciphertext' | |
// const result = await decrypt(ciphertext, secret); | |
// expect(result).toEqual({ | |
// message: 'mocked-decrypted', | |
// sk: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1] | |
// }) | |
// }) |