diff --git a/types/tiny-secp256k1/index.d.ts b/types/tiny-secp256k1/index.d.ts new file mode 100644 index 0000000000..35cd73400b --- /dev/null +++ b/types/tiny-secp256k1/index.d.ts @@ -0,0 +1,94 @@ +// Type definitions for tiny-secp256k1 v1.0.0 +// Project: https://github.com/bitcoinjs/tiny-secp256k1 +// Definitions by: Eduardo Henke +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/// + +/** + * Checks if A is a point in the curve + * @param A should be: + * encoded with a sequence tag of 0x02, 0x03 or 0x04 + * A.x is within [1...p - 1] + * A.y is within [1...p - 1] + */ +export function isPoint(A: Buffer): boolean; + +/** + * Returns false if the point is not compressed. + */ +export function isPointCompressed(A: Buffer): boolean; + +/** + * Checks if point is private key + * @param d should be: + * 256-bit + * within [1...order - 1] + */ +export function isPrivate(d: Buffer): boolean; + +/** + * Returns null if result is at infinity. + * @param A isPoint(A) should be true + * @param B isPoint(B) should be true + * @param compressed optional, if true compresses the resulting point + */ +export function pointAdd(A: Buffer, B: Buffer, compressed?: boolean): Buffer | null; + +/** + * Returns null if result is at infinity. + * @param A isPoint(A) should be true + * @param tweak should be within [1...order - 1] + * @param compressed optional, if true compresses the resulting point + */ +export function pointAddScalar(A: Buffer, tweak: Buffer, compressed?: boolean): Buffer | null; + +/** + * Compresses point A. + * @param A isPoint(A) should be true + * @param compressed if true compresses A + */ +export function pointCompress(A: Buffer, compressed: boolean): Buffer; + +/** + * Returns null if result is at infinity. + * @param d isPrivate(d) should be true + * @param compressed optional, if true compresses the resulting point + */ +export function pointFromScalar(d: Buffer, compressed?: boolean): Buffer | null; + +/** + * Returns null if result is at infinity. + * @param A isPoint(A) should be true + * @param tweak should be within [1...order - 1] + * @param compressed optional, if true compresses the resulting point + */ +export function pointMultiply(A: Buffer, tweak: Buffer, compressed?: boolean): Buffer | null; + +/** + * Returns null if result is equal to 0. + * @param d isPrivate(d) should be true + * @param tweak should be within [1...order - 1] + */ +export function privateAdd(d: Buffer, tweak: Buffer): Buffer | null; + +/** + * Returns null if result is equal to 0. + * @param d isPrivate(d) should be true + * @param tweak should be within [1...order - 1] + */ +export function privateSub(d: Buffer, tweak: Buffer): Buffer | null; + +/** + * Returns normalized signatures, each of (r, s) values are guaranteed to less than order / 2. Uses RFC6979. + * @param message should be 256-bit + * @param privateKey isPrivate(privateKey) should be true + */ +export function sign(message: Buffer, privateKey: Buffer): Buffer; + +/** + * Returns false if any of (r, s) values are equal to 0, or if the signature is rejected. + * @param message should be 256-bit + * @param publicKey isPoint(publicKey) should be true + * @param signature signature should have all (r, s) values within range [0...order - 1] + */ +export function verify(message: Buffer, publicKey: Buffer, signature: Buffer): boolean; diff --git a/types/tiny-secp256k1/tiny-secp256k1-tests.ts b/types/tiny-secp256k1/tiny-secp256k1-tests.ts new file mode 100644 index 0000000000..1203f3fed1 --- /dev/null +++ b/types/tiny-secp256k1/tiny-secp256k1-tests.ts @@ -0,0 +1,11 @@ +import { pointFromScalar, sign, verify } from 'tiny-secp256k1'; + +const d = Buffer.from('5272e811987e04833abf88c2cdbb43eddfefd7b4afa50e87bfcd3a2b297f0a93'); +const Q = pointFromScalar(d); + +const message = new Buffer(new Uint8Array([0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x77, 0x6f, 0x72, 0x6c, 0x64])); +const signature = sign(message, d); + +if (Q !== null) { + verify(message, Q, signature); +} diff --git a/types/tiny-secp256k1/tsconfig.json b/types/tiny-secp256k1/tsconfig.json new file mode 100644 index 0000000000..b189f55e66 --- /dev/null +++ b/types/tiny-secp256k1/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es5" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "tiny-secp256k1-tests.ts" + ] +} diff --git a/types/tiny-secp256k1/tslint.json b/types/tiny-secp256k1/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/tiny-secp256k1/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }