diff --git a/README.md b/README.md index 1df7a31..ce8a91e 100644 --- a/README.md +++ b/README.md @@ -29,3 +29,4 @@ This following libraries are currently included. Where possible add the relevant - [peer-info](https://github.com/libp2p/js-peer-info) - [pull-pushable](https://github.com/pull-stream/pull-pushable) - [pull-stream](https://github.com/pull-stream/pull-stream) +- [tweetnacl](https://github.com/dchest/tweetnacl-js) diff --git a/tweetnacl/index.d.ts b/tweetnacl/index.d.ts new file mode 100644 index 0000000..04c4f61 --- /dev/null +++ b/tweetnacl/index.d.ts @@ -0,0 +1,58 @@ +// Type definitions for tweetnacl 1.0.0 +// Project: https://github.com/dchest/tweetnacl-js +// Definitions by: Jaco Greeff +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +type KeypairType = { + publicKey: Uint8Array, + secretKey: Uint8Array +}; + +type Hash = { + (message: Uint8Array): Uint8Array, + + hashLength: number +}; + +type SecretBox = { + (message: Uint8Array, nonce: Uint8Array, secret: Uint8Array): Uint8Array, + + open: (encrypted: Uint8Array, nonce: Uint8Array, secret: Uint8Array) => Uint8Array | null +}; + +type SignDetached = { + (message: Uint8Array, secretKey: Uint8Array): Uint8Array, + + verify: (message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array) => boolean +}; + +type SignKeypair = { + (): KeypairType, + + fromSecretKey: (secretKey: Uint8Array) => KeypairType, + fromSeed: (seed: Uint8Array) => KeypairType, +}; + +type Sign = { + (message: Uint8Array, secretKey: Uint8Array): Uint8Array, + detached: SignDetached, + + open: (signedMsg: Uint8Array, publicKey: Uint8Array) => Uint8Array, + keyPair: SignKeypair, + + publicKeyLength: number, + secretKeyLength: number, + seedLength: number, + signatureLength: number, +}; + +type TweetNacl = { + randomBytes: (length: number) => Uint8Array, + hash: Hash, + secretbox: SecretBox, + sign: Sign +}; + +export = TweetNacl; diff --git a/tweetnacl/tsconfig.json b/tweetnacl/tsconfig.json new file mode 100644 index 0000000..932e246 --- /dev/null +++ b/tweetnacl/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "bn.js-tests.ts"] +} diff --git a/tweetnacl/tslint.json b/tweetnacl/tslint.json new file mode 100644 index 0000000..3db14f8 --- /dev/null +++ b/tweetnacl/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/tweetnacl/tweetnacl-tests.ts b/tweetnacl/tweetnacl-tests.ts new file mode 100644 index 0000000..e69de29