forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/DefinitelyTyped/Definitel…
…yTyped into jquery/promise-compatibility
- Loading branch information
Showing
201 changed files
with
6,599 additions
and
856 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import BloomFilter = require('bloom-filter'); | ||
|
||
const numElements = 3; | ||
const falsePositiveRate = 0.01; | ||
const filter = BloomFilter.create(numElements, falsePositiveRate); | ||
|
||
// elements | ||
const a = Buffer.from('99108ad8ed9bb6274d3980bab5a85c048f0950c8', 'hex'); | ||
const c = Buffer.from('b5a2c786d9ef4658287ced5914b37a1b4aa32eee', 'hex'); | ||
|
||
// insert elements | ||
// $ExpectType void | ||
filter.insert(a); | ||
|
||
// $ExpectType boolean | ||
!filter.contains(c); | ||
|
||
// reinstantiate from an object | ||
const serialized = filter.toObject(); | ||
const woahFilter = new BloomFilter(serialized); | ||
|
||
// initialize directly | ||
const newFilter = new BloomFilter({ | ||
vData: Buffer.from('123', 'hex'), // the data of the filter | ||
nHashFuncs: 3, // the number of hash functions to use | ||
nTweak: 2147483649, // the seed used for the hash fuctions | ||
nFlags: 0 // flags used to update the filter when matched | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Type definitions for bloom-filter 0.2 | ||
// Project: https://github.com/bitpay/bloom-filter | ||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
/// <reference types="node" /> | ||
|
||
declare class Filter { | ||
constructor(options: Filter.FilterOptions); | ||
static create(elements: number, falsePositiveRate: number, nTweak?: number, nFlags?: number): Filter; | ||
toObject(): Filter.FilterOptions; | ||
hash(nHashNum: number, vDataToHash: Buffer): number; | ||
insert(data: Buffer): void; | ||
contains(data: Buffer): boolean; | ||
clear(): void; | ||
inspect(): string; | ||
BLOOM_UPDATE_NONE: number; | ||
BLOOM_UPDATE_ALL: number; | ||
BLOOM_UPDATE_P2PUBKEY_ONLY: number; | ||
MAX_BLOOM_FILTER_SIZE: number; | ||
MAX_HASH_FUNCS: number; | ||
MIN_HASH_FUNCS: number; | ||
LN2SQUARED: number; | ||
LN2: number; | ||
} | ||
|
||
declare namespace Filter { | ||
interface FilterOptions { | ||
vData: Buffer; | ||
nHashFuncs: number; | ||
nTweak?: number; | ||
nFlags?: number; | ||
} | ||
|
||
function MurmurHash3(seed: number, data: Buffer): number; | ||
} | ||
|
||
export = Filter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"baseUrl": "../", | ||
"typeRoots": ["../"], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"bloom-filter-tests.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "dtslint/dt.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import elliptic = require('elliptic'); | ||
|
||
const ec = new elliptic.ec('secp256k1'); | ||
|
||
// Generate keys | ||
const key = ec.genKeyPair(); | ||
|
||
// Sign the message's hash (input must be an array, or a hex-string) | ||
const msgHash = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; | ||
const signature = key.sign(msgHash); | ||
|
||
// Export DER encoded signature in Array | ||
const derSign = signature.toDER(); | ||
|
||
// Verify signature | ||
console.log(key.verify(msgHash, derSign)); | ||
|
||
// CHECK WITH NO PRIVATE KEY | ||
|
||
const pubPoint = key.getPublic(); | ||
const x = pubPoint.getX(); | ||
const y = pubPoint.getY(); | ||
|
||
// Public Key MUST be either: | ||
// 1) '04' + hex string of x + hex string of y; or | ||
// 2) object with two hex string properties (x and y); or | ||
// 3) object with two buffer properties (x and y) | ||
const pub = pubPoint.encode('hex'); // case 1 | ||
const aPub = { x: x.toString('hex'), y: y.toString('hex') }; // case 2 | ||
const bPub = { x: x.toBuffer(), y: y.toBuffer() }; // case 3 | ||
const cPub = { x: x.toArrayLike(Buffer), y: y.toArrayLike(Buffer) }; // case 3 | ||
|
||
// Import public key | ||
const newKey = ec.keyFromPublic(pub, 'hex'); | ||
|
||
// Signature MUST be either: | ||
// 1) DER-encoded signature as hex-string; or | ||
// 2) DER-encoded signature as buffer; or | ||
// 3) object with two hex-string properties (r and s); or | ||
// 4) object with two buffer properties (r and s) | ||
|
||
// const signature = '3046022100...'; // case 1 | ||
// const signature = new Buffer('...'); // case 2 | ||
// const signature = { r: 'b1fc...', s: '9c42...' }; // case 3 | ||
|
||
// Verify signature | ||
console.log(key.verify(msgHash, signature)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
// Type definitions for elliptic 6.4 | ||
// Project: https://github.com/indutny/elliptic | ||
// Definitions by: Daniel Byrne <https://github.com/danwbyrne> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
|
||
import BN = require('bn.js'); | ||
|
||
// incomplete typings | ||
export const utils: any; | ||
export const rand: any; | ||
export const eddsa: any; | ||
|
||
export type BNInput = string | BN | number | Buffer | number[]; | ||
|
||
export const version: number; | ||
|
||
export namespace curve { | ||
class BaseCurve { | ||
constructor(type: string, conf: BaseCurve.BaseCurveOptions) | ||
p: BN; | ||
type: string; | ||
red: any; // ? | ||
zero: any; // ? | ||
one: any; // ? | ||
two: any; // ? | ||
n: BN | undefined | null; | ||
g: any; // ? | ||
redN: any; // ? | ||
decodePoint(bytes: any, enc: string): any; // ? | ||
} | ||
|
||
namespace BaseCurve { | ||
class BasePoint { | ||
constructor(curve: any, type: string); | ||
curve: any; | ||
type: string; | ||
precomputed: PrecomputedValues | null; | ||
encode(enc: string, compact: boolean): BN; | ||
encodeCompressed(enc: string): BN; | ||
validate(): boolean; | ||
precompute(power: number): BasePoint; | ||
dblp(k: any): any; // ? | ||
} | ||
|
||
interface BaseCurveOptions { | ||
p: number | string | number[] | Buffer | BN; | ||
prime?: BN | string; | ||
n?: number | BN | Buffer; | ||
g?: any; // ? | ||
gRed?: any; // ? | ||
} | ||
|
||
interface PrecomputedValues { | ||
doubles: any; // ? | ||
naf: any; // ? | ||
beta: any; // ? | ||
} | ||
} | ||
} | ||
|
||
export namespace curves { | ||
class PresetCurve { | ||
constructor(options: PresetCurve.Options) | ||
type: string; | ||
g: any; // ? | ||
n: BN | undefined | null; | ||
hash: any; // ? | ||
} | ||
|
||
namespace PresetCurve { | ||
interface Options { | ||
type: string; | ||
prime: string | null; | ||
p: string; | ||
a: string; | ||
b: string; | ||
n: string; | ||
hash: any; | ||
gRed: boolean; | ||
g: any; // ? | ||
beta?: string; | ||
lambda?: string; | ||
basis?: any; // ? | ||
} | ||
} | ||
} | ||
|
||
export class ec { | ||
constructor(options: string | curves.PresetCurve) | ||
curve: any; | ||
n: BN | undefined | null; | ||
nh: any; | ||
g: any; | ||
hash: any; | ||
|
||
keyPair(options: ec.KeyPairOptions): ec.KeyPair; | ||
keyFromPrivate(priv: Buffer | ec.KeyPair, enc?: string): ec.KeyPair; | ||
keyFromPublic(pub: Buffer | ec.KeyPair, enc?: string): ec.KeyPair; | ||
genKeyPair(options?: ec.GenKeyPairOptions): ec.KeyPair; | ||
sign(msg: BNInput, key: Buffer | ec.KeyPair, enc: string, options?: ec.SignOptions): ec.Signature; | ||
sign(msg: BNInput, key: Buffer | ec.KeyPair, options?: ec.SignOptions): ec.Signature; | ||
verify(msg: BNInput, signature: ec.Signature | ec.SignatureOptions, key: Buffer | ec.KeyPair, enc?: string): boolean; | ||
recoverPubKey(msg: BNInput, signature: ec.Signature | ec.SignatureOptions, j: number, enc?: string): any; | ||
getKeyRecoveryParam(e: Error | undefined, signature: ec.Signature | ec.SignatureOptions, Q: BN, enc?: string): number; | ||
} | ||
|
||
export namespace ec { | ||
interface GenKeyPairOptions { | ||
pers: any; | ||
entropy: any; | ||
persEnc?: string; | ||
entropyEnc?: string; | ||
} | ||
|
||
interface SignOptions { | ||
pers: any; | ||
persEnc?: string; | ||
canonical?: boolean; | ||
k?: BN; | ||
} | ||
|
||
class KeyPair { | ||
static fromPublic(ec: ec, pub: Buffer | KeyPair, enc?: string): KeyPair; | ||
static fromPrivate(ec: ec, priv: Buffer | KeyPair, enc?: string): KeyPair; | ||
constructor(ec: ec, options: KeyPairOptions) | ||
ec: ec; | ||
validate(): { readonly result: boolean, readonly reason: string }; | ||
getPublic(compact: boolean, enc?: string): any; // ? | ||
getPublic(enc?: string): any; // ? | ||
getPrivate(enc?: 'hex'): Buffer | BN | string; | ||
derive(pub: any): any; // ? | ||
sign(msg: BNInput, enc: string, options?: SignOptions): Signature; | ||
sign(msg: BNInput, options?: SignOptions): Signature; | ||
verify(msg: BNInput, signature: Signature | SignatureOptions): boolean; | ||
inspect(): string; | ||
} | ||
|
||
class Signature { | ||
constructor(options: SignatureOptions | Signature, enc?: string) | ||
r: BN; | ||
s: BN; | ||
recoveryParam: number | null; | ||
toDER(enc?: string | null): any; // ? | ||
} | ||
|
||
interface SignatureOptions { | ||
r: number; | ||
s: number; | ||
recoveryParam?: number; | ||
} | ||
|
||
interface KeyPairOptions { | ||
priv?: Buffer; | ||
privEnc?: string; | ||
pub?: Buffer; | ||
pubEnc?: string; | ||
} | ||
} |
Oops, something went wrong.