mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add tiny-secp256k1 library typing
This commit is contained in:
parent
ec6a6ef299
commit
8e2d67ecee
94
types/tiny-secp256k1/index.d.ts
vendored
Normal file
94
types/tiny-secp256k1/index.d.ts
vendored
Normal file
@ -0,0 +1,94 @@
|
||||
// Type definitions for tiny-secp256k1 v1.0.0
|
||||
// Project: https://github.com/bitcoinjs/tiny-secp256k1
|
||||
// Definitions by: Eduardo Henke <https://github.com/eduhenke/>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
/// <reference types="node" />
|
||||
|
||||
/**
|
||||
* 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;
|
||||
11
types/tiny-secp256k1/tiny-secp256k1-tests.ts
Normal file
11
types/tiny-secp256k1/tiny-secp256k1-tests.ts
Normal file
@ -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);
|
||||
}
|
||||
22
types/tiny-secp256k1/tsconfig.json
Normal file
22
types/tiny-secp256k1/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
1
types/tiny-secp256k1/tslint.json
Normal file
1
types/tiny-secp256k1/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user