Under construction. Please do not use.
About The Project
The purpose of dotp is to provide a stable and well-tested OTP library for use with Deno. The implementation aims to follow the relevant RFC documents to the letter, and to provide a developer friendly API for the features listed below.
- Create cryptographically random and secure OTP secrets
- Create hash and time based OTP tokens.
Getting Started
You may use this project much like any other Deno module. Import the part of the module that you need and you are good to go.
Prerequisites
- Deno
Running Tests
Use the command below in the root of the project to run the test suite.
deno task test
Generate Coverage Report
genhtml
is required to generate coverage LCOV coverage report in HTML. This
command is included in the lcov
package in Ubuntu, install using
sudo apt install lcov
.
To generate LCOV coverage profile, run the following command.
deno task coverage
Finally, to create a HTML coverage report, run this command after you’ve already generated an up to date LCOV profile.
deno task coverage:html
Usage
Generate Hash-based OTP
import {
createHashToken,
createMovingFactorFromNumber,
createRandomSecretKey,
} from "https://deno.land/x/dotp/mod.ts";
const secretKey = createRandomSecretKey();
const token = createHashToken(secretKey, createMovingFactorFromNumber(1));
API
class OTP(secretKey: CryptoKey, options?: Options)
OTP.withSecretKeyString(value: string, options?: Options): OTP
OTP.withRandomSecretKey(options?: Options): OTP
keyAsString(): Promise<string>
async hashToken(movingFactor: ArrayBuffer): Promise<Uint8Array>
async createTimeToken(offset = 0): Promise<Uint8Array>
async validateTimeToken(token: ArrayBuffer, skew = 2): Promise<boolean>
async hashToken(movingFactor: ArrayBuffer): Promise<Uint8Array>
createMovingFactorFromNumber(value: number): ArrayBuffer
createMovingFactorFromBigInt(): Uint8Array
class OTPError(message?: string | undefined, options?: ErrorOptions | undefined): OTPError
class OTPSecretKeyError(message?: string | undefined, options?: ErrorOptions | undefined): OTPError
createDefaultOptions(timeStep: number): Options
createOptions(timeStep = 30): Options
Contributing
We do not accept contributions. Please see our ideas 💡 in the Discussions to discuss any potential ideas or improvements you may have for the project.
License
Distributed under the MIT License. See LICENSE.txt for more information.
Contact
Christoffer Hallas
hallas@libewd.com