Timelock Encryption made practical. A Typescript library for encrypting for the future.

Overview

tlock-js

A typescript library for encrypting data which can only be decrypted at a set time in the future using drand.
tlock-js uses AGE to symmetrically encrypt a payload, and encrypts the symmetric key using pairing-based cryptography ensuring that it can only be decrypted when the drand's threshold network 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. 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

License

This project is licensed using the Permissive License Stack which means that all contributions are available under the most permissive commonly-used licenses, and dependent projects can pick the license that best suits them.

Therefore, the project is dual-licensed under Apache 2.0 and MIT terms:

Comments
  • Support for modern web browser without polyfills

    Support for modern web browser without polyfills

    Currently when using tlock-js in browser, it fails at runtime with

    ReferenceError: Buffer is not defined

    It would be great to use something that work for both browser and node env

    bug 
    opened by wighawag 5
  • Reverted a change to output encoding that broke special chars

    Reverted a change to output encoding that broke special chars

    the previous commit that added the binary encoding said it was necessary for correct enc/dec, but none of the tests failed when removed and I suspect it was added before we sorted the chunking issues

    opened by CluEleSsUK 1
  • Node compatibility

    Node compatibility

    I think there may be some issues running this in pure node due to its use of fetch. There's text in the readme to that effect, but it would be good to actually test it and remedy any issues that arise.

    opened by CluEleSsUK 1
  • Fixed some issues with browser compatibility

    Fixed some issues with browser compatibility

    • export Buffer class so that downstream users don't have to pull in a polyfill
    • rejigged parcel config so that the built module doesn't use require so that users who don't use a bundler can use it in-browser
    • added some advisory text for users of vite.js
    opened by CluEleSsUK 0
  • patched IBE hashToCurve with ietf hashToField impl

    patched IBE hashToCurve with ietf hashToField impl

    • pulled some pieces out of noble
    • wrote an implementation of hashToField using https://datatracker.ietf.org/doc/html/draft-irtf-cfrg-hash-to-curve-16#section-5.2
    • created a patched hashToCurve
    opened by CluEleSsUK 6
  • avoid nonce reuse for large payloads

    avoid nonce reuse for large payloads

    due to using a counter size of 32bits in the stream cipher, only up to 256TB may be encrypted before a nonce reuse would occur. This solution checks if the counter has reached the limit on every increment. This may add overhead or may be free on some engines and I haven't benchmarked it

    opened by CluEleSsUK 1
  • Ability to submit lock without revealing the time it can be decryted

    Ability to submit lock without revealing the time it can be decryted

    In my use case, the encryptor do not want the decryptor to know when decryption is possible. This is because in my use case, the timing needs to remains secret.

    To avoid the decryptor to check the decryption at every epoch, one idea is that encryptor will provide the decryptor the minutes (and seconds) to check but will not tell the day/hour.

    See conversation slack :

    wighawag:
    hey got a question on tlock. Is the decryption time public ?
    if it is public by default, is there a way to ensure that only the one encrypting know when decryption will be possible ? (edited) 
    
    Will Scott
    you could not include the decryption time with the encrypted blob, but it would be up to recipients to trial-decrypt every epoch
    
    wighawag
    Nice, is the tlock-js library supporting that option easily ?
    
    The idea is that for my use case, decryptor will be able  to try every hour
    
    Will Scott
    would you know that you are only encrypting at an hour granularity, or could encryption still be at any epoch?
    
    Patrick McClurg (Protocol Labs)
    right now tlock-js doesn’t enable this super easily - during encryption, the roundNumber is encoded into the AGE args and then used for retrieving the beacon during decryption time.It wouldn’t be super hard to make a fork though - you could e.g. put a round number of -1 and remove the bounds check, and change decryption to check every hour when the round number is negative
    
    ofc it will not be compatible with the other tlock libs, but it sounds like that’s not a big deal for your use case!
    
    wighawag:
    @Will Scott, yes, basically, one idea is that the encryptor will be telling the minute (and seconds) the decryption will be ready but not the hour
    
    @Patrick McClurg (Protocol Labs) I ll create an issue in tlock-js as I think it is a valid use case for it
    
    Will Scott
    makes sense. having a coarser quantization seems useful in not making decryptors do way too much work
    

    If tlock-js could left out the decrypting time, application could provide their own mechanism

    opened by wighawag 3
  • Details on  the Approximation of time

    Details on the Approximation of time

    Hi,

    Reading the doc it says about timeForRound:

    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).
    

    It would be great if it gave also worst case scenario in both direction or even better a probability distribution on a range of time, so applications can predict accordingly.

    I also could not find what to expect on the mainnet, Is it a one minute kind of difference we can expect or a lot more ? Thanks

    opened by wighawag 2
Owner
drand
Verifiable, unpredictable and unbiased random numbers as a service.
drand
Might be mineral fish site in future, idk. Currently just a fish list. Made with Svelte

Might be mineral fish site in future, idk. Currently just a fish list. Made with Svelte. Built version (used at mineralfish.github.io) at the build branch. Build steps and original README below.

Mineral Fish 3 Nov 3, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Follow along with blog posts, code samples, and practical exercises to learn how to build serverless applications from your local Integrated development environment (IDE).

Getting started with serverless This getting started series is written by the serverless developer advocate team @AWSCloud. It has been designed for d

AWS Samples 55 Dec 28, 2022
Next-gen mobile first analytics server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js, headless, API-only, horizontally scaleable.

Introduction to Awacs Next-gen behavior analysis server (think Mixpanel, Google Analytics) with built-in encryption supporting HTTP2 and gRPC. Node.js

Socketkit 52 Dec 19, 2022
Use real-time computing technology and web technology to build a big data Kanban l to solve the problem. Among them, practical technologies include MySQL, Kafka, Flink, Redis, Flask and Echarts

实时计算(English Version) 运用实时计算技术、Web 技术构建一个大数据看板来解决问题。其中实用技术包括Mysql、Kafka、Flink、Redis、Flask和Echarts 目录 1.问题需求 2.方案分析 3.安装环境 4.环境启动命令和运行代码的方法 5.代码目录结构说明

Serendipity 2 Jan 8, 2022
Awesome-Books project uses practical tests for JavaScript/Html and CSS functions.

Awesome-Books project uses practical tests for JavaScript/Html and CSS functions. The project presents a basic website that allows users to add/remove books from a list.

Vahan Kh. 5 Jan 31, 2022
A Hackable Markdown Note Application for Programmers. Version control, AI completion, mind map, documents encryption, code snippet running, integrated terminal, chart embedding, HTML applets, plug-in, and macro replacement.

Yank Note A hackable markdown note application for programmers Download | Try it Online >>> Not ecommended English | 中文说明 [toc]{level: [2]} Highlights

洋子 4.3k Dec 31, 2022
A web watermark SDK, support: custom watermark content and style, watermark encryption and decryption, watermark anomaly monitoring, etc.

English | 简体中文 1. What is l-watermark? l-watermark is a web watermark SDK based on TS, which contains: Can cover more than scene watermarking method A

Liurx 23 Dec 10, 2022
A fully cross-platform messenger app with End to End Encryption (E2EE).

Smartsapp A fully cross-platform messenger app with End to End Encryption (E2EE). Demo NOTE: The features shown in the demo is not exhaustive. Only th

Derek Jones 13 Aug 25, 2022
A file-sharing app providing end-to-end encryption of data.

secsend secsend is a file-sharing app providing end-to-end encryption of data. It provides a web application and a command-line interface (CLI). demo.

Adrien Guinet 28 Dec 22, 2022
A small utility server to exchange data and messages between clients. Comes complete with E2E public key encryption

Zenotta Intercom A small utility server to exchange arbitrary data between clients. Comes complete with E2E public key encryption Official documentati

Zenotta AG 7 Oct 2, 2022
Onchain private messaging app with a significant encryption algorithm.

Hedwig DEMO We want to implement SSL technology to blockchain so decided to build onchain private messaging app. Diffie Hellman protocol was invented

İzzet Emre Demir 5 Nov 3, 2022
🏊 Dive into ES6 and the future of JavaScript

Practical Modern JavaScript Dive into ES6 and the future of JavaScript ?? Modular JavaScript is a book series with the mission of improving our collec

Modular JavaScript Book Series 3.1k Jan 2, 2023
This repo is a collection of code samples and links to previous twitch live stream sessions. If you have any ideas or suggestions for future episodes, feel free to open an issue.

Talk DEV to me Talk DEV to me is a monthly show on twitch.tv/aws hosted by Tiago Barbosa and Alex Melnyk, where we invite customers, partners, or Amaz

AWS Samples 122 Jan 6, 2023
✅ A future task manager (⚒️ working).

A beautifully task manager ?? soon ?? Packages: ⚡️ Vitejs - Next generation frontend tooling. ☁️ Vitejs PWA - Zero-config PWA Framework-agnostic Plugi

Pablo Hdez 6 Aug 8, 2022
⭐ Password manager of the future.

Cool Keeper ?? About Cool keeper is the modern password manager we have been looking for. Built using the latest technologies from the web development

Vitor Windberg 8 Dec 14, 2022