From c4d1e138578635606b7db7d2276908cf1da920f4 Mon Sep 17 00:00:00 2001 From: Daniel Lebrecht Date: Mon, 3 Jul 2017 15:01:22 +0200 Subject: [PATCH 1/7] updated bitcoinjs-lib to version 3.0.3 --- types/bitcoinjs-lib/index.d.ts | 1229 +++++++++++++++++++++++++---- types/bitcoinjs-lib/tsconfig.json | 2 +- 2 files changed, 1074 insertions(+), 157 deletions(-) diff --git a/types/bitcoinjs-lib/index.d.ts b/types/bitcoinjs-lib/index.d.ts index 600edda000..cc6dca8747 100644 --- a/types/bitcoinjs-lib/index.d.ts +++ b/types/bitcoinjs-lib/index.d.ts @@ -1,114 +1,234 @@ -// Type definitions for bitcoinjs-lib 2.3 -// Project: https://github.com/bitcoinjs/bitcoinjs-lib#readme -// Definitions by: Mohamed Hegazy -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +/** Declaration file initially generated by dts-gen for bitcoinjs-lib 3.0.3*/ + +// Definitions by: Daniel . +/* modified by dlebrecht based on the flow version found at https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_v0.17.x-/bitcoinjs-lib_v2.x.x.js */ + + +export type Utxo = { + address: string; + amount: number; + scriptPubKey: Buffer; + txid: string; + vout: number; +} + +export type Output = { + script: Buffer; + value: number; +}; + +export type Input = { + script: Buffer; + hash: Buffer; + index: number; + sequence: number; +}; + +export type Network = { + bip32: { + public: number; + private: number; + }; + messagePrefix: string; + pubKeyHash: number; + scriptHash: number; + wif: number; +} + export class Block { constructor(); + + byteLength(headersOnly: any): any; + checkMerkleRoot(): any; + checkProofOfWork(): any; - getHash(): any; - getId(): any; + + getHash(): Buffer; + + getId(): string; + getUTCDate(): any; - toBuffer(headersOnly: any): any; - toHex(headersOnly: any): any; + + toBuffer(headersOnly?: boolean): Buffer; + + toHex(headersOnly?: boolean): string; + static calculateMerkleRoot(transactions: any): any; + static calculateTarget(bits: any): any; - static fromBuffer(buffer: any): any; - static fromHex(hex: any): any; + + static fromBuffer(buffer: Buffer): any; + + static fromHex(hex: string): any; + } + export class ECPair { - constructor(d: any, Q?: any, options?: any); + constructor(d: any, Q: any, options: any); + getAddress(): string; + getNetwork(): Network; - getPublicKeyBuffer(): any; - sign(hash: any): any; + + getPublicKeyBuffer(): Buffer; + + sign(hash: Buffer): Buffer; + toWIF(): string; - verify(hash: any, signature: any): boolean; - static fromPublicKeyBuffer(buffer: any, network: Network): ECPair; - static fromWIF(string: any, network?: Network): ECPair; + + verify(hash: Buffer, signature: ECSignature): boolean; + + static fromPublicKeyBuffer(buffer: Buffer, network: Network): ECPair; + + static fromWIF(string: string, network: Network): ECPair; + static makeRandom(options: any): ECPair; + } + export class ECSignature { constructor(r: any, s: any, ...args: any[]); + toCompact(i: any, compressed: any): any; + toDER(): any; + toScriptSignature(hashType: any): any; - static fromDER(buffer: any): ECSignature; - static parseCompact(buffer: any): ECSignature; - static parseScriptSignature(buffer: any): ECSignature; -} -export class HDNode { - constructor(keyPair: any, chainCode: any, ...args: any[]); - derive(index: any): any; - deriveHardened(index: any): any; - derivePath(path: any): any; - getAddress(): string; - getFingerprint(): any; - getIdentifier(): any; - getNetwork(): Network; - getPublicKeyBuffer(): any; - isNeutered(): any; - neutered(): any; - sign(hash: any): any; - toBase58(__isPrivate: any): any; - toString(__isPrivate: any): any; - verify(hash: any, signature: any): any; - static HIGHEST_BIT: number; - static LENGTH: number; - static fromBase58(string: any, networks: Network[]): HDNode; - static fromSeedBuffer(seed: any, network: Network, ...args: any[]): HDNode; - static fromSeedHex(hex: any, network: Network): HDNode; -} -export class Transaction { - constructor(); - addInput(hash: any, index: any, sequence: any, scriptSig: any, ...args: any[]): any; - addOutput(scriptPubKey: any, value: any, ...args: any[]): any; - byteLength(): number; - clone(): Transaction; - getHash(): any; - getId(): any; - hashForSignature(inIndex: any, prevOutScript: any, hashType: any, ...args: any[]): any; - isCoinbase(): boolean; - setInputScript(index: any, scriptSig: any, ...args: any[]): void; - toBuffer(buffer?: any, initialOffset?: any): Buffer; - toHex(): string; - static DEFAULT_SEQUENCE: number; - static SIGHASH_ALL: number; - static SIGHASH_ANYONECANPAY: number; - static SIGHASH_NONE: number; - static SIGHASH_SINGLE: number; - static fromBuffer(buffer: any, __noStrict: any): Transaction; - static fromHex(hex: any): Transaction; - static isCoinbaseHash(buffer: any): Transaction; -} -export class TransactionBuilder { - constructor(network?: Network); - addInput(txHash: any, vout: any, sequence?: any, prevOutScript?: any): any; - addOutput(scriptPubKey: any, value: any): any; - build(): Transaction; - buildIncomplete(): Transaction; - setLockTime(locktime: number): any; - setVersion(version: number): void; - sign(index: any, keyPair: any, redeemScript?: any, hashType?: any): any; - static fromTransaction(transaction: Transaction, network: Network): TransactionBuilder; + + static fromDER(buffer: Buffer): any; + + static parseCompact(buffer: Buffer): any; + + static parseScriptSignature(buffer: Buffer): any; + } -export interface Network { - bitcoin: { - private: number; - public: number; - }; - dustThreshold: number; - messagePrefix: string; - pubKeyHash: number; - scriptHash: number; - wif: number; +export class HDNode { + constructor(keyPair: ECPair, chainCode: any, ...args: any[]); + + keyPair: ECPair // dl added manually TODO check if correct + + derive(index: number): HDNode; + + deriveHardened(index: number): HDNode; + + derivePath(path: string): HDNode; + + getAddress(): string; + + getFingerprint(): Buffer; + + getIdentifier(): Buffer; + + getNetwork(): any; + + getPublicKeyBuffer(): Buffer; + + isNeutered(): boolean; + + neutered(): HDNode; + + sign(hash: Buffer): ECSignature; + + toBase58(__isPrivate?: any): string; + + verify(hash: Buffer, signature: any): Buffer; + + static HIGHEST_BIT: number; + + static LENGTH: number; + + static fromBase58(string: string, networks?: any): HDNode; + + static fromSeedBuffer(seed: Buffer, network: Network, ...args: any[]): HDNode; + + static fromSeedHex(hex: string, network: Network): HDNode; + } +export class Transaction { + version: number; + locktime: number; + ins: Array; + outs: Array; + constructor(); + + addInput(hash: Buffer, index: number, sequence: any, scriptSig: Buffer, ...args: any[]): any; + + addOutput(scriptPubKey: any, value: any, ...args: any[]): any; + + byteLength(): any; + + clone(): Transaction; + + getHash(): Buffer; + + getId(): any; + + hasWitnesses(): any; + + hashForSignature(inindex: number, prevOutScript: any, hashType: any, ...args: any[]): any; + + hashForWitnessV0(inindex: number, prevOutScript: any, value: any, hashType: any, ...args: any[]): any; + + isCoinbase(): boolean; + + setInputScript(index: number, scriptSig: Buffer, ...args: any[]): void; + + setWitness(index: number, witness: any, ...args: any[]): void; + + toBuffer(buffer: Buffer, initialOffset: any): Buffer; + + toHex(): any; + + static ADVANCED_TRANSACTION_FLAG: number; + + static ADVANCED_TRANSACTION_MARKER: number; + + static DEFAULT_SEQUENCE: number; + + static SIGHASH_ALL: number; + + static SIGHASH_ANYONECANPAY: number; + + static SIGHASH_NONE: number; + + static SIGHASH_SINGLE: number; + + static fromBuffer(buffer: Buffer, __noStrict: any): Transaction; + + static fromHex(hex: string): Transaction; + + static isCoinbaseHash(buffer: Buffer): any; + +} + +export class TransactionBuilder { + constructor(network: Network, maximumFeeRate?: any); + + addInput(txhash: Buffer|string|Transaction, vout: number, sequence?: number, prevOutScript?: Buffer): void; + + addOutput(scriptPubKey: Buffer|string, value: any): any; + + build(): Transaction; + + buildIncomplete(): Transaction; + + setLockTime(locktime: number): void; + + setVersion(version: number): void; + + sign(vin: number, keyPair: ECPair, redeemScript?: Buffer, hashType?: number, witnessValue?: any, witnessScript?: any): void; + + static fromTransaction(transaction: Transaction, network: Network): TransactionBuilder; + +} + + export const networks: { - bitcoin: Network; - dogecoin: Network; + bitcoin: Network ; litecoin: Network; testnet: Network; }; @@ -232,172 +352,969 @@ export const opcodes: { OP_WITHIN: number; OP_XOR: number; }; + export namespace HDNode { namespace MASTER_SECRET { const BYTES_PER_ELEMENT: number; + const byteLength: number; + const byteOffset: number; + const length: number; + const offset: number; + function asciiSlice(): any; + function asciiWrite(): any; + function base64Slice(): any; + function base64Write(): any; - function compare(target: any, start: any, end: any, thisStart: any, thisEnd: any): any; + + function compare(target: any, start: any, end: any, thisStart: any, thisEnd: any, ...args: any[]): any; + function copy(): any; + function copyWithin(p0: any, p1: any): any; + function entries(): any; + function equals(b: any): any; + function every(p0: any): any; + function fill(val: any, start: any, end: any, encoding: any): any; + function filter(p0: any): any; + function find(p0: any): any; + function findIndex(p0: any): any; + function forEach(p0: any): any; + function hexSlice(): any; + function hexWrite(): any; + function includes(val: any, byteOffset: any, encoding: any): any; + function indexOf(val: any, byteOffset: any, encoding: any): any; + function inspect(): any; + function join(p0: any): any; + function keys(): any; + function lastIndexOf(val: any, byteOffset: any, encoding: any): any; + function latin1Slice(): any; + function latin1Write(): any; + function map(p0: any): any; + function readDoubleBE(offset: any, noAssert: any): any; + function readDoubleLE(offset: any, noAssert: any): any; + function readFloatBE(offset: any, noAssert: any): any; + function readFloatLE(offset: any, noAssert: any): any; + function readInt16BE(offset: any, noAssert: any): any; + function readInt16LE(offset: any, noAssert: any): any; + function readInt32BE(offset: any, noAssert: any): any; + function readInt32LE(offset: any, noAssert: any): any; + function readInt8(offset: any, noAssert: any): any; + function readIntBE(offset: any, byteLength: any, noAssert: any): any; + function readIntLE(offset: any, byteLength: any, noAssert: any): any; + function readUInt16BE(offset: any, noAssert: any): any; + function readUInt16LE(offset: any, noAssert: any): any; + function readUInt32BE(offset: any, noAssert: any): any; + function readUInt32LE(offset: any, noAssert: any): any; + function readUInt8(offset: any, noAssert: any): any; + function readUIntBE(offset: any, byteLength: any, noAssert: any): any; + function readUIntLE(offset: any, byteLength: any, noAssert: any): any; + function reduce(p0: any): any; + function reduceRight(p0: any): any; + function reverse(): any; + function set(p0: any): any; + function slice(start: any, end: any): any; + function some(p0: any): any; + function sort(p0: any): any; + function subarray(p0: any, p1: any): any; + function swap16(): any; + function swap32(): any; + function swap64(): any; + function toJSON(): any; - function toLocaleString(): any; - function toString(...args: any[]): any; + + function toLocaleString(encoding: any, start: any, end: any, ...args: any[]): any; + + function toString(encoding: any, start: any, end: any, ...args: any[]): any; + function ucs2Slice(): any; + function ucs2Write(): any; - function undefined(): any; + function utf8Slice(): any; + function utf8Write(): any; + function values(): any; + function write(string: any, offset: any, length: any, encoding: any): any; + function writeDoubleBE(val: any, offset: any, noAssert: any): any; + function writeDoubleLE(val: any, offset: any, noAssert: any): any; + function writeFloatBE(val: any, offset: any, noAssert: any): any; + function writeFloatLE(val: any, offset: any, noAssert: any): any; + function writeInt16BE(value: any, offset: any, noAssert: any): any; + function writeInt16LE(value: any, offset: any, noAssert: any): any; + function writeInt32BE(value: any, offset: any, noAssert: any): any; + function writeInt32LE(value: any, offset: any, noAssert: any): any; + function writeInt8(value: any, offset: any, noAssert: any): any; + function writeIntBE(value: any, offset: any, byteLength: any, noAssert: any): any; + function writeIntLE(value: any, offset: any, byteLength: any, noAssert: any): any; + function writeUInt16BE(value: any, offset: any, noAssert: any): any; + function writeUInt16LE(value: any, offset: any, noAssert: any): any; + function writeUInt32BE(value: any, offset: any, noAssert: any): any; + function writeUInt32LE(value: any, offset: any, noAssert: any): any; + function writeUInt8(value: any, offset: any, noAssert: any): any; + function writeUIntBE(value: any, offset: any, byteLength: any, noAssert: any): any; + function writeUIntLE(value: any, offset: any, byteLength: any, noAssert: any): any; + + namespace asciiSlice { + const prototype: { + }; + + } + + namespace asciiWrite { + const prototype: { + }; + + } + + namespace base64Slice { + const prototype: { + }; + + } + + namespace base64Write { + const prototype: { + }; + + } + namespace buffer { const byteLength: number; + function slice(p0: any, p1: any): any; + } + + namespace compare { + const prototype: { + }; + + } + + namespace copy { + const prototype: { + }; + + } + + namespace equals { + const prototype: { + }; + + } + + namespace fill { + const prototype: { + }; + + } + + namespace hexSlice { + const prototype: { + }; + + } + + namespace hexWrite { + const prototype: { + }; + + } + + namespace includes { + const prototype: { + }; + + } + + namespace indexOf { + const prototype: { + }; + + } + + namespace inspect { + const prototype: { + }; + + } + + namespace lastIndexOf { + const prototype: { + }; + + } + + namespace latin1Slice { + const prototype: { + }; + + } + + namespace latin1Write { + const prototype: { + }; + + } + namespace parent { const byteLength: number; + function slice(p0: any, p1: any): any; + } + + namespace readDoubleBE { + const prototype: { + }; + + } + + namespace readDoubleLE { + const prototype: { + }; + + } + + namespace readFloatBE { + const prototype: { + }; + + } + + namespace readFloatLE { + const prototype: { + }; + + } + + namespace readInt16BE { + const prototype: { + }; + + } + + namespace readInt16LE { + const prototype: { + }; + + } + + namespace readInt32BE { + const prototype: { + }; + + } + + namespace readInt32LE { + const prototype: { + }; + + } + + namespace readInt8 { + const prototype: { + }; + + } + + namespace readIntBE { + const prototype: { + }; + + } + + namespace readIntLE { + const prototype: { + }; + + } + + namespace readUInt16BE { + const prototype: { + }; + + } + + namespace readUInt16LE { + const prototype: { + }; + + } + + namespace readUInt32BE { + const prototype: { + }; + + } + + namespace readUInt32LE { + const prototype: { + }; + + } + + namespace readUInt8 { + const prototype: { + }; + + } + + namespace readUIntBE { + const prototype: { + }; + + } + + namespace readUIntLE { + const prototype: { + }; + + } + + namespace slice { + const prototype: { + }; + + } + + namespace swap16 { + const prototype: { + }; + + } + + namespace swap32 { + const prototype: { + }; + + } + + namespace swap64 { + const prototype: { + }; + + } + + namespace toJSON { + const prototype: { + }; + + } + + namespace toLocaleString { + const prototype: { + }; + + } + + namespace toString { + const prototype: { + }; + + } + + namespace ucs2Slice { + const prototype: { + }; + + } + + namespace ucs2Write { + const prototype: { + }; + + } + + namespace utf8Slice { + const prototype: { + }; + + } + + namespace utf8Write { + const prototype: { + }; + + } + + namespace write { + const prototype: { + }; + + } + + namespace writeDoubleBE { + const prototype: { + }; + + } + + namespace writeDoubleLE { + const prototype: { + }; + + } + + namespace writeFloatBE { + const prototype: { + }; + + } + + namespace writeFloatLE { + const prototype: { + }; + + } + + namespace writeInt16BE { + const prototype: { + }; + + } + + namespace writeInt16LE { + const prototype: { + }; + + } + + namespace writeInt32BE { + const prototype: { + }; + + } + + namespace writeInt32LE { + const prototype: { + }; + + } + + namespace writeInt8 { + const prototype: { + }; + + } + + namespace writeIntBE { + const prototype: { + }; + + } + + namespace writeIntLE { + const prototype: { + }; + + } + + namespace writeUInt16BE { + const prototype: { + }; + + } + + namespace writeUInt16LE { + const prototype: { + }; + + } + + namespace writeUInt32BE { + const prototype: { + }; + + } + + namespace writeUInt32LE { + const prototype: { + }; + + } + + namespace writeUInt8 { + const prototype: { + }; + + } + + namespace writeUIntBE { + const prototype: { + }; + + } + + namespace writeUIntLE { + const prototype: { + }; + + } + } + + } + + + export namespace address { - function fromBase58Check(address: any): any; - function fromOutputScript(scriptPubKey: any, network?: Network): any; - function toBase58Check(hash: any, version: any, ...args: any[]): any; - function toOutputScript(address: any, network?: Network): any; -} -export namespace bufferutils { - function equal(a: any, b: any): any; - function pushDataSize(i: any): any; - function readPushDataInt(buffer: any, offset: any): any; - function readUInt64LE(buffer: any, offset: any): any; - function readVarInt(buffer: any, offset: any): any; - function reverse(src: any): any; - function varIntBuffer(i: any): any; - function varIntSize(i: any): any; - function writePushDataInt(buffer: any, number: any, offset: any): any; - function writeUInt64LE(buffer: any, value: any, offset: any): void; - function writeVarInt(buffer: any, number: any, offset: any): any; -} -export namespace crypto { - function hash160(buffer: any): any; - function hash256(buffer: any): any; - function ripemd160(buffer: any): any; - function sha1(buffer: any): any; - function sha256(buffer: any): any; -} -export namespace message { - function magicHash(message: any, network: any): any; - function sign(keyPair: any, message: any, network: any): any; - function verify(address: any, signature: any, message: any, network: any): any; -} -export namespace script { - function classifyInput(script: any, allowIncomplete: any): any; - function classifyOutput(script: any): any; - function compile(chunks: any): any; - function decompile(buffer: any): any; - function fromASM(asm: any): any; - function isCanonicalPubKey(buffer: any): any; - function isCanonicalSignature(buffer: any): any; - function isDefinedHashType(hashType: any): any; - function isMultisigInput(script: any, allowIncomplete: any): any; - function isMultisigOutput(script: any): any; - function isNullDataOutput(script: any): any; - function isPubKeyHashInput(script: any): any; - function isPubKeyHashOutput(script: any): any; - function isPubKeyInput(script: any): any; - function isPubKeyOutput(script: any): any; - function isScriptHashInput(script: any, allowIncomplete: any): any; - function isScriptHashOutput(script: any): any; - function isWitnessPubKeyHashOutput(script: any): any; - function isWitnessScriptHashOutput(script: any): any; - function multisigInput(signatures: any, scriptPubKey: any): any; - function multisigOutput(m: any, pubKeys: any, ...args: any[]): any; - function nullDataOutput(data: any): any; - function pubKeyHashInput(signature: any, pubKey: any, ...args: any[]): any; - function pubKeyHashOutput(pubKeyHash: any): any; - function pubKeyInput(signature: any): any; - function pubKeyOutput(pubKey: any): any; - function scriptHashInput(scriptSig: any, scriptPubKey: any): any; - function scriptHashOutput(scriptHash: any): any; - function toASM(chunks: any): any; - function witnessPubKeyHashOutput(pubKeyHash: any): any; - function witnessScriptHashInput(scriptSig: any, scriptPubKey: any): any; - function witnessScriptHashOutput(scriptHash: any): any; - namespace number { - function decode(buffer: any, maxLength: any, minimal: any): any; - function encode(number: any): any; + function fromBase58Check(address: string): string; + + function fromOutputScript(outputScript: Buffer, network: Network): string; + + function toBase58Check(hash: Buffer, version: number, ...args: any[]): any; + + function toOutputScript(address: string, network: Network): any; + + namespace fromBase58Check { + const prototype: { + }; + } + + namespace fromOutputScript { + const prototype: { + }; + + } + + namespace toBase58Check { + const prototype: { + }; + + } + + namespace toOutputScript { + const prototype: { + }; + + } + +} + +export namespace bufferutils { + function pushDataSize(i: any): any; + + function readPushDataInt(buffer: Buffer, offset: any): any; + + function readUInt64LE(buffer: Buffer, offset: any): any; + + function readVarInt(buffer: Buffer, offset: any): any; + + function varIntBuffer(number: number, buffer: Buffer, offset: any): any; + + function varIntSize(number: number): any; + + function writePushDataInt(buffer: Buffer, number: number, offset: any): any; + + function writeUInt64LE(buffer: Buffer, value: any, offset: any): any; + + function writeVarInt(buffer: Buffer, number: number, offset: any): any; + + namespace pushDataSize { + const prototype: { + }; + + } + + namespace readPushDataInt { + const prototype: { + }; + + } + + namespace readUInt64LE { + const prototype: { + }; + + } + + namespace readVarInt { + const prototype: { + }; + + } + + namespace varIntBuffer { + const prototype: { + }; + + } + + namespace varIntSize { + const prototype: { + }; + + } + + namespace writePushDataInt { + const prototype: { + }; + + } + + namespace writeUInt64LE { + const prototype: { + }; + + } + + namespace writeVarInt { + const prototype: { + }; + + } + +} + +export namespace crypto { + function hash160(buffer: Buffer): Buffer; + + function hash256(buffer: Buffer): any; + + function ripemd160(buffer: Buffer): any; + + function sha1(buffer: Buffer): any; + + function sha256(buffer: Buffer): any; + + namespace hash160 { + const prototype: { + }; + + } + + namespace hash256 { + const prototype: { + }; + + } + + namespace ripemd160 { + const prototype: { + }; + + } + + namespace sha1 { + const prototype: { + }; + + } + + namespace sha256 { + const prototype: { + }; + + } + +} + +export namespace script { + const multisig: { + input: { + check: any; + decode: any; + decodeStack: any; + encode: any; + encodeStack: any; + }; + output: { + check: any; + decode: any; + encode: any; + }; + }; + + const nullData: { + output: { + check: any; + decode: any; + encode: any; + }; + }; + + const pubKey: { + input: { + check: any; + decode: any; + decodeStack: any; + encode: any; + encodeStack: any; + }; + output: { + check: any; + decode: any; + encode: any; + }; + }; + + const pubKeyHash: { + input: { + check: any; + decode: any; + decodeStack: any; + encode: any; + encodeStack: any; + }; + output: { + check: any; + decode: any; + encode: any; + }; + }; + + const scriptHash: { + input: { + check: any; + decode: any; + decodeStack: any; + encode: any; + encodeStack: any; + }; + output: { + check: any; + decode: any; + encode: any; + }; + }; + + const types: { + MULTISIG: string; + NONSTANDARD: string; + NULLDATA: string; + P2PK: string; + P2PKH: string; + P2SH: string; + P2WPKH: string; + P2WSH: string; + WITNESS_COMMITMENT: string; + }; + + const witnessCommitment: { + output: { + check: any; + decode: any; + encode: any; + }; + }; + + const witnessPubKeyHash: { + input: { + check: any; + decodeStack: any; + encodeStack: any; + }; + output: { + check: any; + decode: any; + encode: any; + }; + }; + + const witnessScriptHash: { + input: { + check: any; + decodeStack: any; + encodeStack: any; + }; + output: { + check: any; + decode: any; + encode: any; + }; + }; + + function classifyInput(script: any, allowIncomplete: any): any; + + function classifyOutput(script: any): any; + + function classifyWitness(script: any, allowIncomplete: any): any; + + function compile(chunks: any): any; + + function decompile(buffer: Buffer): any; + + function fromASM(asm: any): any; + + function isCanonicalPubKey(buffer: Buffer): any; + + function isCanonicalSignature(buffer: Buffer): any; + + function isDefinedHashType(hashType: any): any; + + function isPushOnly(value: any): any; + + function toASM(chunks: any): any; + + function toStack(chunks: any): any; + + namespace classifyInput { + const prototype: { + }; + + } + + namespace classifyOutput { + const prototype: { + }; + + } + + namespace classifyWitness { + const prototype: { + }; + + } + + namespace compile { + const prototype: { + }; + + } + + namespace decompile { + const prototype: { + }; + + } + + namespace fromASM { + const prototype: { + }; + + } + + namespace isCanonicalPubKey { + const prototype: { + }; + + } + + namespace isCanonicalSignature { + const prototype: { + }; + + } + + namespace isDefinedHashType { + const prototype: { + }; + + } + + namespace isPushOnly { + const prototype: { + }; + + } + + namespace number { + function decode(buffer: Buffer, maxLength: any, minimal: any): any; + + function encode(number: number): any; + + namespace decode { + const prototype: { + }; + + } + + namespace encode { + const prototype: { + }; + + } + + } + + namespace toASM { + const prototype: { + }; + + } + + namespace toStack { + const prototype: { + }; + + } + } diff --git a/types/bitcoinjs-lib/tsconfig.json b/types/bitcoinjs-lib/tsconfig.json index 7a9a4cf261..d1f5ec75b6 100644 --- a/types/bitcoinjs-lib/tsconfig.json +++ b/types/bitcoinjs-lib/tsconfig.json @@ -19,4 +19,4 @@ "index.d.ts", "bitcoinjs-lib-tests.ts" ] -} \ No newline at end of file +} From 57973a461886d16330fa7756d87e09f1e2f8b662 Mon Sep 17 00:00:00 2001 From: Daniel Lebrecht Date: Fri, 7 Jul 2017 20:56:30 +0200 Subject: [PATCH 2/7] fixed types following @rbuckton instructions. deleted tests --- types/bitcoinjs-lib/bitcoinjs-lib-tests.ts | 64 -- types/bitcoinjs-lib/index.d.ts | 1073 ++------------------ 2 files changed, 94 insertions(+), 1043 deletions(-) diff --git a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts index 7267fe5d26..e69de29bb2 100644 --- a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts +++ b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts @@ -1,64 +0,0 @@ -/// - -import bigi = require('bigi'); -import bitcoin = require('bitcoinjs-lib'); - -declare const it: any; -declare const describe: any; -declare const assert: any; - -describe('bitcoinjs-lib (basic)', () => { - it('can generate a random bitcoin address', () => { - // for testing only - function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } - - // generate random keyPair - const keyPair = bitcoin.ECPair.makeRandom({ rng }); - const address = keyPair.getAddress(); - - assert.strictEqual(address, '1F5VhMHukdnUES9kfXqzPzMeF1GPHKiF64'); - }); - - it('can generate an address from a SHA256 hash', () => { - const hash = bitcoin.crypto.sha256('correct horse battery staple'); - const d = bigi.fromBuffer(hash); - - const keyPair = new bitcoin.ECPair(d); - const address = keyPair.getAddress(); - - assert.strictEqual(address, '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8'); - }); - - it('can generate a random keypair for alternative networks', () => { - // for testing only - function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } - - const litecoin = bitcoin.networks.litecoin; - - const keyPair = bitcoin.ECPair.makeRandom({ network: litecoin, rng }); - const wif = keyPair.toWIF(); - const address = keyPair.getAddress(); - - assert.strictEqual(address, 'LZJSxZbjqJ2XVEquqfqHg1RQTDdfST5PTn'); - assert.strictEqual(wif, 'T7A4PUSgTDHecBxW1ZiYFrDNRih2o7M8Gf9xpoCgudPF9gDiNvuS'); - }); - - it('can import an address via WIF', () => { - const keyPair = bitcoin.ECPair.fromWIF('Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct'); - const address = keyPair.getAddress(); - - assert.strictEqual(address, '19AAjaTUbRjQCMuVczepkoPswiZRhjtg31'); - }); - - it('can create a Transaction', () => { - const keyPair = bitcoin.ECPair.fromWIF('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy'); - const tx = new bitcoin.TransactionBuilder(); - - tx.addInput('aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31', 0); - tx.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000); - tx.sign(0, keyPair); - - // tslint:disable-next-line:max-line-length - assert.strictEqual(tx.build().toHex(), '0100000001313eb630b128102b60241ca895f1d0ffca2170d5a0990e094f2182c102ab94aa000000006b483045022100aefbcf847900b01dd3e3debe054d3b6d03d715d50aea8525f5ea3396f168a1fb022013d181d05b15b90111808b22ef4f9ebe701caf2ab48db269691fdf4e9048f4f60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01983a0000000000001976a914ad618cf4333b3b248f9744e8e81db2964d0ae39788ac00000000'); - }); -}); diff --git a/types/bitcoinjs-lib/index.d.ts b/types/bitcoinjs-lib/index.d.ts index cc6dca8747..eb4ec504af 100644 --- a/types/bitcoinjs-lib/index.d.ts +++ b/types/bitcoinjs-lib/index.d.ts @@ -1,10 +1,16 @@ -/** Declaration file initially generated by dts-gen for bitcoinjs-lib 3.0.3*/ +// Type definitions for bitcoinjs-lib 3.0.3 +// Project https://github.com/bitcoinjs/bitcoinjs-lib +// Declaration file initially generated by dts-gen for bitcoinjs-lib 3.0.3 +// Definitions by: Mohamed Hegazy +// Daniel +// Ron Buckton +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// based on the flow version found at https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_v0.17.x-/bitcoinjs-lib_v2.x.x.js -// Definitions by: Daniel . -/* modified by dlebrecht based on the flow version found at https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_v0.17.x-/bitcoinjs-lib_v2.x.x.js */ +/// +import BigInteger = require("bigi"); - -export type Utxo = { +export interface Utxo { address: string; amount: number; scriptPubKey: Buffer; @@ -12,19 +18,19 @@ export type Utxo = { vout: number; } -export type Output = { +export interface Output { script: Buffer; value: number; -}; +} -export type Input = { +export interface Input { script: Buffer; hash: Buffer; index: number; sequence: number; -}; +} -export type Network = { +export interface Network { bip32: { public: number; private: number; @@ -35,11 +41,10 @@ export type Network = { wif: number; } - export class Block { constructor(); - byteLength(headersOnly: any): any; + byteLength(headersOnly?: boolean): number; checkMerkleRoot(): any; @@ -55,18 +60,20 @@ export class Block { toHex(headersOnly?: boolean): string; - static calculateMerkleRoot(transactions: any): any; + static calculateMerkleRoot(transactions: Transaction[] | { getHash(): Buffer; }[]): Buffer; - static calculateTarget(bits: any): any; + static calculateTarget(bits: number): Buffer; - static fromBuffer(buffer: Buffer): any; - - static fromHex(hex: string): any; + static fromBuffer(buffer: Buffer): Block; + static fromHex(hex: string): Block; } export class ECPair { - constructor(d: any, Q: any, options: any); + + constructor(d: BigInteger, Q?: null | undefined, options?: { compressed?: boolean, network?: Network }); + + constructor(d: null | undefined, Q: any, options?: { compressed?: boolean, network?: Network }); // Q should be ECPoint, but not sure how to define such type getAddress(): string; @@ -84,31 +91,31 @@ export class ECPair { static fromWIF(string: string, network: Network): ECPair; - static makeRandom(options: any): ECPair; - + static makeRandom(options?: { compressed?: boolean, network?: Network, rng?: (size: number) => Buffer }): ECPair; } export class ECSignature { - constructor(r: any, s: any, ...args: any[]); - toCompact(i: any, compressed: any): any; + constructor(r: BigInteger, s: BigInteger); - toDER(): any; + toCompact(i: number, compressed: boolean): Buffer; - toScriptSignature(hashType: any): any; + toDER(): Buffer; - static fromDER(buffer: Buffer): any; + toScriptSignature(hashType: number): Buffer; - static parseCompact(buffer: Buffer): any; + static fromDER(buffer: Buffer): ECSignature; - static parseScriptSignature(buffer: Buffer): any; + static parseCompact(buffer: Buffer): { compressed: boolean, i: number, signature: ECSignature }; + + static parseScriptSignature(buffer: Buffer): { signature: ECSignature, hashType: number }; } export class HDNode { - constructor(keyPair: ECPair, chainCode: any, ...args: any[]); + constructor(keyPair: ECPair, chainCode: Buffer); - keyPair: ECPair // dl added manually TODO check if correct + keyPair: ECPair; derive(index: number): HDNode; @@ -122,7 +129,7 @@ export class HDNode { getIdentifier(): Buffer; - getNetwork(): any; + getNetwork(): Network; getPublicKeyBuffer(): Buffer; @@ -132,56 +139,58 @@ export class HDNode { sign(hash: Buffer): ECSignature; - toBase58(__isPrivate?: any): string; + toBase58(): string; - verify(hash: Buffer, signature: any): Buffer; + verify(hash: Buffer, signature: ECSignature): Buffer; static HIGHEST_BIT: number; static LENGTH: number; - static fromBase58(string: string, networks?: any): HDNode; + static fromBase58(string: string, networks?: Network[] | Network): HDNode; - static fromSeedBuffer(seed: Buffer, network: Network, ...args: any[]): HDNode; + static fromSeedBuffer(seed: Buffer, network?: Network): HDNode; - static fromSeedHex(hex: string, network: Network): HDNode; + static fromSeedHex(hex: string, network?: Network): HDNode; + + static MASTER_SECRET: Buffer; } export class Transaction { version: number; locktime: number; - ins: Array; - outs: Array; + ins: Input[]; + outs: Output[]; constructor(); - addInput(hash: Buffer, index: number, sequence: any, scriptSig: Buffer, ...args: any[]): any; + addInput(hash: Buffer, index: number, sequence?: number, scriptSig?: Buffer): number; - addOutput(scriptPubKey: any, value: any, ...args: any[]): any; + addOutput(scriptPubKey: Buffer, value: number): number; - byteLength(): any; + byteLength(): number; clone(): Transaction; getHash(): Buffer; - getId(): any; + getId(): string; - hasWitnesses(): any; + hasWitnesses(): boolean; - hashForSignature(inindex: number, prevOutScript: any, hashType: any, ...args: any[]): any; + hashForSignature(inIndex: number, prevOutScript: Buffer, hashType: number): Buffer; - hashForWitnessV0(inindex: number, prevOutScript: any, value: any, hashType: any, ...args: any[]): any; + hashForWitnessV0(inIndex: number, prevOutScript: Buffer, value: number, hashType: number): Buffer; isCoinbase(): boolean; - setInputScript(index: number, scriptSig: Buffer, ...args: any[]): void; + setInputScript(index: number, scriptSig: Buffer): void; setWitness(index: number, witness: any, ...args: any[]): void; - toBuffer(buffer: Buffer, initialOffset: any): Buffer; + toBuffer(buffer: Buffer, initialOffset?: number): Buffer; - toHex(): any; + toHex(): string; static ADVANCED_TRANSACTION_FLAG: number; @@ -197,20 +206,19 @@ export class Transaction { static SIGHASH_SINGLE: number; - static fromBuffer(buffer: Buffer, __noStrict: any): Transaction; + static fromBuffer(buffer: Buffer, __noStrict?: boolean): Transaction; static fromHex(hex: string): Transaction; - static isCoinbaseHash(buffer: Buffer): any; - + static isCoinbaseHash(buffer: Buffer): boolean; } export class TransactionBuilder { - constructor(network: Network, maximumFeeRate?: any); + constructor(network?: Network, maximumFeeRate?: number); - addInput(txhash: Buffer|string|Transaction, vout: number, sequence?: number, prevOutScript?: Buffer): void; + addInput(txhash: Buffer | string | Transaction, vout: number, sequence?: number, prevOutScript?: Buffer): number; - addOutput(scriptPubKey: Buffer|string, value: any): any; + addOutput(scriptPubKey: Buffer | string, value: number): number; build(): Transaction; @@ -220,15 +228,13 @@ export class TransactionBuilder { setVersion(version: number): void; - sign(vin: number, keyPair: ECPair, redeemScript?: Buffer, hashType?: number, witnessValue?: any, witnessScript?: any): void; + sign(vin: number, keyPair: ECPair, redeemScript?: Buffer, hashType?: number, witnessValue?: number, witnessScript?: Buffer): void; static fromTransaction(transaction: Transaction, network: Network): TransactionBuilder; - } - export const networks: { - bitcoin: Network ; + bitcoin: Network; litecoin: Network; testnet: Network; }; @@ -353,968 +359,77 @@ export const opcodes: { OP_XOR: number; }; -export namespace HDNode { - namespace MASTER_SECRET { - const BYTES_PER_ELEMENT: number; - - const byteLength: number; - - const byteOffset: number; - - const length: number; - - const offset: number; - - function asciiSlice(): any; - - function asciiWrite(): any; - - function base64Slice(): any; - - function base64Write(): any; - - function compare(target: any, start: any, end: any, thisStart: any, thisEnd: any, ...args: any[]): any; - - function copy(): any; - - function copyWithin(p0: any, p1: any): any; - - function entries(): any; - - function equals(b: any): any; - - function every(p0: any): any; - - function fill(val: any, start: any, end: any, encoding: any): any; - - function filter(p0: any): any; - - function find(p0: any): any; - - function findIndex(p0: any): any; - - function forEach(p0: any): any; - - function hexSlice(): any; - - function hexWrite(): any; - - function includes(val: any, byteOffset: any, encoding: any): any; - - function indexOf(val: any, byteOffset: any, encoding: any): any; - - function inspect(): any; - - function join(p0: any): any; - - function keys(): any; - - function lastIndexOf(val: any, byteOffset: any, encoding: any): any; - - function latin1Slice(): any; - - function latin1Write(): any; - - function map(p0: any): any; - - function readDoubleBE(offset: any, noAssert: any): any; - - function readDoubleLE(offset: any, noAssert: any): any; - - function readFloatBE(offset: any, noAssert: any): any; - - function readFloatLE(offset: any, noAssert: any): any; - - function readInt16BE(offset: any, noAssert: any): any; - - function readInt16LE(offset: any, noAssert: any): any; - - function readInt32BE(offset: any, noAssert: any): any; - - function readInt32LE(offset: any, noAssert: any): any; - - function readInt8(offset: any, noAssert: any): any; - - function readIntBE(offset: any, byteLength: any, noAssert: any): any; - - function readIntLE(offset: any, byteLength: any, noAssert: any): any; - - function readUInt16BE(offset: any, noAssert: any): any; - - function readUInt16LE(offset: any, noAssert: any): any; - - function readUInt32BE(offset: any, noAssert: any): any; - - function readUInt32LE(offset: any, noAssert: any): any; - - function readUInt8(offset: any, noAssert: any): any; - - function readUIntBE(offset: any, byteLength: any, noAssert: any): any; - - function readUIntLE(offset: any, byteLength: any, noAssert: any): any; - - function reduce(p0: any): any; - - function reduceRight(p0: any): any; - - function reverse(): any; - - function set(p0: any): any; - - function slice(start: any, end: any): any; - - function some(p0: any): any; - - function sort(p0: any): any; - - function subarray(p0: any, p1: any): any; - - function swap16(): any; - - function swap32(): any; - - function swap64(): any; - - function toJSON(): any; - - function toLocaleString(encoding: any, start: any, end: any, ...args: any[]): any; - - function toString(encoding: any, start: any, end: any, ...args: any[]): any; - - function ucs2Slice(): any; - - function ucs2Write(): any; - - function utf8Slice(): any; - - function utf8Write(): any; - - function values(): any; - - function write(string: any, offset: any, length: any, encoding: any): any; - - function writeDoubleBE(val: any, offset: any, noAssert: any): any; - - function writeDoubleLE(val: any, offset: any, noAssert: any): any; - - function writeFloatBE(val: any, offset: any, noAssert: any): any; - - function writeFloatLE(val: any, offset: any, noAssert: any): any; - - function writeInt16BE(value: any, offset: any, noAssert: any): any; - - function writeInt16LE(value: any, offset: any, noAssert: any): any; - - function writeInt32BE(value: any, offset: any, noAssert: any): any; - - function writeInt32LE(value: any, offset: any, noAssert: any): any; - - function writeInt8(value: any, offset: any, noAssert: any): any; - - function writeIntBE(value: any, offset: any, byteLength: any, noAssert: any): any; - - function writeIntLE(value: any, offset: any, byteLength: any, noAssert: any): any; - - function writeUInt16BE(value: any, offset: any, noAssert: any): any; - - function writeUInt16LE(value: any, offset: any, noAssert: any): any; - - function writeUInt32BE(value: any, offset: any, noAssert: any): any; - - function writeUInt32LE(value: any, offset: any, noAssert: any): any; - - function writeUInt8(value: any, offset: any, noAssert: any): any; - - function writeUIntBE(value: any, offset: any, byteLength: any, noAssert: any): any; - - function writeUIntLE(value: any, offset: any, byteLength: any, noAssert: any): any; - - namespace asciiSlice { - const prototype: { - }; - - } - - namespace asciiWrite { - const prototype: { - }; - - } - - namespace base64Slice { - const prototype: { - }; - - } - - namespace base64Write { - const prototype: { - }; - - } - - namespace buffer { - const byteLength: number; - - function slice(p0: any, p1: any): any; - - } - - namespace compare { - const prototype: { - }; - - } - - namespace copy { - const prototype: { - }; - - } - - namespace equals { - const prototype: { - }; - - } - - namespace fill { - const prototype: { - }; - - } - - namespace hexSlice { - const prototype: { - }; - - } - - namespace hexWrite { - const prototype: { - }; - - } - - namespace includes { - const prototype: { - }; - - } - - namespace indexOf { - const prototype: { - }; - - } - - namespace inspect { - const prototype: { - }; - - } - - namespace lastIndexOf { - const prototype: { - }; - - } - - namespace latin1Slice { - const prototype: { - }; - - } - - namespace latin1Write { - const prototype: { - }; - - } - - namespace parent { - const byteLength: number; - - function slice(p0: any, p1: any): any; - - } - - namespace readDoubleBE { - const prototype: { - }; - - } - - namespace readDoubleLE { - const prototype: { - }; - - } - - namespace readFloatBE { - const prototype: { - }; - - } - - namespace readFloatLE { - const prototype: { - }; - - } - - namespace readInt16BE { - const prototype: { - }; - - } - - namespace readInt16LE { - const prototype: { - }; - - } - - namespace readInt32BE { - const prototype: { - }; - - } - - namespace readInt32LE { - const prototype: { - }; - - } - - namespace readInt8 { - const prototype: { - }; - - } - - namespace readIntBE { - const prototype: { - }; - - } - - namespace readIntLE { - const prototype: { - }; - - } - - namespace readUInt16BE { - const prototype: { - }; - - } - - namespace readUInt16LE { - const prototype: { - }; - - } - - namespace readUInt32BE { - const prototype: { - }; - - } - - namespace readUInt32LE { - const prototype: { - }; - - } - - namespace readUInt8 { - const prototype: { - }; - - } - - namespace readUIntBE { - const prototype: { - }; - - } - - namespace readUIntLE { - const prototype: { - }; - - } - - namespace slice { - const prototype: { - }; - - } - - namespace swap16 { - const prototype: { - }; - - } - - namespace swap32 { - const prototype: { - }; - - } - - namespace swap64 { - const prototype: { - }; - - } - - namespace toJSON { - const prototype: { - }; - - } - - namespace toLocaleString { - const prototype: { - }; - - } - - namespace toString { - const prototype: { - }; - - } - - namespace ucs2Slice { - const prototype: { - }; - - } - - namespace ucs2Write { - const prototype: { - }; - - } - - namespace utf8Slice { - const prototype: { - }; - - } - - namespace utf8Write { - const prototype: { - }; - - } - - namespace write { - const prototype: { - }; - - } - - namespace writeDoubleBE { - const prototype: { - }; - - } - - namespace writeDoubleLE { - const prototype: { - }; - - } - - namespace writeFloatBE { - const prototype: { - }; - - } - - namespace writeFloatLE { - const prototype: { - }; - - } - - namespace writeInt16BE { - const prototype: { - }; - - } - - namespace writeInt16LE { - const prototype: { - }; - - } - - namespace writeInt32BE { - const prototype: { - }; - - } - - namespace writeInt32LE { - const prototype: { - }; - - } - - namespace writeInt8 { - const prototype: { - }; - - } - - namespace writeIntBE { - const prototype: { - }; - - } - - namespace writeIntLE { - const prototype: { - }; - - } - - namespace writeUInt16BE { - const prototype: { - }; - - } - - namespace writeUInt16LE { - const prototype: { - }; - - } - - namespace writeUInt32BE { - const prototype: { - }; - - } - - namespace writeUInt32LE { - const prototype: { - }; - - } - - namespace writeUInt8 { - const prototype: { - }; - - } - - namespace writeUIntBE { - const prototype: { - }; - - } - - namespace writeUIntLE { - const prototype: { - }; - - } - - } - - -} - - - export namespace address { - function fromBase58Check(address: string): string; + function fromBase58Check(address: string): { hash: Buffer, version: number }; - function fromOutputScript(outputScript: Buffer, network: Network): string; + function fromOutputScript(outputScript: Buffer, network?: Network): { hash: Buffer, version: number }; - function toBase58Check(hash: Buffer, version: number, ...args: any[]): any; - - function toOutputScript(address: string, network: Network): any; - - namespace fromBase58Check { - const prototype: { - }; - - } - - namespace fromOutputScript { - const prototype: { - }; - - } - - namespace toBase58Check { - const prototype: { - }; - - } - - namespace toOutputScript { - const prototype: { - }; - - } + function toBase58Check(hash: Buffer, version: number): string; + function toOutputScript(address: string, network?: Network): string; } export namespace bufferutils { - function pushDataSize(i: any): any; + function pushDataSize(i: number): number; - function readPushDataInt(buffer: Buffer, offset: any): any; + function readPushDataInt(buffer: Buffer, offset: number): { opcode: number, number: number, size: number }; - function readUInt64LE(buffer: Buffer, offset: any): any; + function readUInt64LE(buffer: Buffer, offset: number): number; - function readVarInt(buffer: Buffer, offset: any): any; + function readVarInt(buffer: Buffer, offset: number): { number: number, size: number }; - function varIntBuffer(number: number, buffer: Buffer, offset: any): any; + function varIntBuffer(number: number, buffer: Buffer, offset: number): Buffer; - function varIntSize(number: number): any; + function varIntSize(number: number): number; - function writePushDataInt(buffer: Buffer, number: number, offset: any): any; + function writePushDataInt(buffer: Buffer, number: number, offset: number): number; - function writeUInt64LE(buffer: Buffer, value: any, offset: any): any; - - function writeVarInt(buffer: Buffer, number: number, offset: any): any; - - namespace pushDataSize { - const prototype: { - }; - - } - - namespace readPushDataInt { - const prototype: { - }; - - } - - namespace readUInt64LE { - const prototype: { - }; - - } - - namespace readVarInt { - const prototype: { - }; - - } - - namespace varIntBuffer { - const prototype: { - }; - - } - - namespace varIntSize { - const prototype: { - }; - - } - - namespace writePushDataInt { - const prototype: { - }; - - } - - namespace writeUInt64LE { - const prototype: { - }; - - } - - namespace writeVarInt { - const prototype: { - }; - - } + function writeUInt64LE(buffer: Buffer, value: number, offset: number): number; + function writeVarInt(buffer: Buffer, number: number, offset: number): number; } export namespace crypto { function hash160(buffer: Buffer): Buffer; - function hash256(buffer: Buffer): any; + function hash256(buffer: Buffer): Buffer; - function ripemd160(buffer: Buffer): any; + function ripemd160(buffer: Buffer): Buffer; - function sha1(buffer: Buffer): any; - - function sha256(buffer: Buffer): any; - - namespace hash160 { - const prototype: { - }; - - } - - namespace hash256 { - const prototype: { - }; - - } - - namespace ripemd160 { - const prototype: { - }; - - } - - namespace sha1 { - const prototype: { - }; - - } - - namespace sha256 { - const prototype: { - }; - - } + function sha1(buffer: Buffer): Buffer; + function sha256(buffer: Buffer): Buffer; } export namespace script { - const multisig: { - input: { - check: any; - decode: any; - decodeStack: any; - encode: any; - encodeStack: any; - }; - output: { - check: any; - decode: any; - encode: any; - }; - }; - const nullData: { - output: { - check: any; - decode: any; - encode: any; - }; - }; + function classifyInput(script: Buffer | (Buffer | number)[], allowIncomplete: boolean): "pubkeyhash" | "scripthash" | "multisig" | "pubkey" | "nonstandard"; - const pubKey: { - input: { - check: any; - decode: any; - decodeStack: any; - encode: any; - encodeStack: any; - }; - output: { - check: any; - decode: any; - encode: any; - }; - }; + function classifyOutput(script: Buffer | (Buffer | number)[]): "witnesspubkeyhash" | "witnessscripthash" | "pubkeyhash" | "scripthash" | "multisig" | "pubkey" | "witnesscommitment" | "nulldata" | "nonstandard"; - const pubKeyHash: { - input: { - check: any; - decode: any; - decodeStack: any; - encode: any; - encodeStack: any; - }; - output: { - check: any; - decode: any; - encode: any; - }; - }; + function classifyWitness(script: Buffer | (Buffer | number)[], allowIncomplete: boolean): "witnesspubkeyhash" | "witnessscripthash" | "nonstandard"; - const scriptHash: { - input: { - check: any; - decode: any; - decodeStack: any; - encode: any; - encodeStack: any; - }; - output: { - check: any; - decode: any; - encode: any; - }; - }; + function compile(chunks: (Buffer | number)[]): Buffer; - const types: { - MULTISIG: string; - NONSTANDARD: string; - NULLDATA: string; - P2PK: string; - P2PKH: string; - P2SH: string; - P2WPKH: string; - P2WSH: string; - WITNESS_COMMITMENT: string; - }; + function decompile(buffer: Buffer): (Buffer | number)[]; - const witnessCommitment: { - output: { - check: any; - decode: any; - encode: any; - }; - }; + function fromASM(asm: string): Buffer; - const witnessPubKeyHash: { - input: { - check: any; - decodeStack: any; - encodeStack: any; - }; - output: { - check: any; - decode: any; - encode: any; - }; - }; + function isCanonicalPubKey(buffer: Buffer): boolean; - const witnessScriptHash: { - input: { - check: any; - decodeStack: any; - encodeStack: any; - }; - output: { - check: any; - decode: any; - encode: any; - }; - }; + function isCanonicalSignature(buffer: Buffer): boolean; - function classifyInput(script: any, allowIncomplete: any): any; + function isDefinedHashType(hashType: any): boolean; - function classifyOutput(script: any): any; + function isPushOnly(value: any): boolean; - function classifyWitness(script: any, allowIncomplete: any): any; + function toASM(chunks: Buffer | (Buffer | number)[]): string; - function compile(chunks: any): any; - - function decompile(buffer: Buffer): any; - - function fromASM(asm: any): any; - - function isCanonicalPubKey(buffer: Buffer): any; - - function isCanonicalSignature(buffer: Buffer): any; - - function isDefinedHashType(hashType: any): any; - - function isPushOnly(value: any): any; - - function toASM(chunks: any): any; - - function toStack(chunks: any): any; - - namespace classifyInput { - const prototype: { - }; - - } - - namespace classifyOutput { - const prototype: { - }; - - } - - namespace classifyWitness { - const prototype: { - }; - - } - - namespace compile { - const prototype: { - }; - - } - - namespace decompile { - const prototype: { - }; - - } - - namespace fromASM { - const prototype: { - }; - - } - - namespace isCanonicalPubKey { - const prototype: { - }; - - } - - namespace isCanonicalSignature { - const prototype: { - }; - - } - - namespace isDefinedHashType { - const prototype: { - }; - - } - - namespace isPushOnly { - const prototype: { - }; - - } + function toStack(chunks: Buffer | (Buffer | number)[]): Buffer[]; namespace number { - function decode(buffer: Buffer, maxLength: any, minimal: any): any; - - function encode(number: number): any; - - namespace decode { - const prototype: { - }; - - } - - namespace encode { - const prototype: { - }; - - } + function decode(buffer: Buffer, maxLength: number, minimal: boolean): number; + function encode(number: number): Buffer; } - - namespace toASM { - const prototype: { - }; - - } - - namespace toStack { - const prototype: { - }; - - } - } From 1bc2e97c9ff03f7be47db31db155ee93c1d22b59 Mon Sep 17 00:00:00 2001 From: Daniel Lebrecht Date: Fri, 7 Jul 2017 22:30:31 +0200 Subject: [PATCH 3/7] fixed header mistakes --- types/bitcoinjs-lib/index.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/types/bitcoinjs-lib/index.d.ts b/types/bitcoinjs-lib/index.d.ts index eb4ec504af..a5e5c6179b 100644 --- a/types/bitcoinjs-lib/index.d.ts +++ b/types/bitcoinjs-lib/index.d.ts @@ -1,10 +1,10 @@ -// Type definitions for bitcoinjs-lib 3.0.3 -// Project https://github.com/bitcoinjs/bitcoinjs-lib -// Declaration file initially generated by dts-gen for bitcoinjs-lib 3.0.3 +// Type definitions for bitcoinjs-lib 3.0 +// Project: https://github.com/bitcoinjs/bitcoinjs-lib // Definitions by: Mohamed Hegazy // Daniel // Ron Buckton // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// Declaration file initially generated by dts-gen for bitcoinjs-lib 3.0.3 // based on the flow version found at https://github.com/flowtype/flow-typed/blob/master/definitions/npm/bitcoinjs-lib_v2.x.x/flow_v0.17.x-/bitcoinjs-lib_v2.x.x.js /// From ca61e7a06903d2fe2e23ee1aac3edfa9914eaa77 Mon Sep 17 00:00:00 2001 From: Daniel Lebrecht Date: Fri, 7 Jul 2017 22:44:31 +0200 Subject: [PATCH 4/7] changed [] for Array on complex types --- types/bitcoinjs-lib/bitcoinjs-lib-tests.ts | 0 types/bitcoinjs-lib/index.d.ts | 22 +++++++++------------- 2 files changed, 9 insertions(+), 13 deletions(-) delete mode 100644 types/bitcoinjs-lib/bitcoinjs-lib-tests.ts diff --git a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/types/bitcoinjs-lib/index.d.ts b/types/bitcoinjs-lib/index.d.ts index a5e5c6179b..8e5cdcf9fa 100644 --- a/types/bitcoinjs-lib/index.d.ts +++ b/types/bitcoinjs-lib/index.d.ts @@ -60,7 +60,7 @@ export class Block { toHex(headersOnly?: boolean): string; - static calculateMerkleRoot(transactions: Transaction[] | { getHash(): Buffer; }[]): Buffer; + static calculateMerkleRoot(transactions: Transaction[] | Array<{ getHash(): Buffer; }>): Buffer; static calculateTarget(bits: number): Buffer; @@ -70,7 +70,6 @@ export class Block { } export class ECPair { - constructor(d: BigInteger, Q?: null | undefined, options?: { compressed?: boolean, network?: Network }); constructor(d: null | undefined, Q: any, options?: { compressed?: boolean, network?: Network }); // Q should be ECPoint, but not sure how to define such type @@ -95,7 +94,6 @@ export class ECPair { } export class ECSignature { - constructor(r: BigInteger, s: BigInteger); toCompact(i: number, compressed: boolean): Buffer; @@ -109,7 +107,6 @@ export class ECSignature { static parseCompact(buffer: Buffer): { compressed: boolean, i: number, signature: ECSignature }; static parseScriptSignature(buffer: Buffer): { signature: ECSignature, hashType: number }; - } export class HDNode { @@ -154,7 +151,6 @@ export class HDNode { static fromSeedHex(hex: string, network?: Network): HDNode; static MASTER_SECRET: Buffer; - } export class Transaction { @@ -402,16 +398,16 @@ export namespace crypto { } export namespace script { + function classifyInput(script: Buffer | Array, allowIncomplete: boolean): "pubkeyhash" | "scripthash" | "multisig" | "pubkey" | "nonstandard"; - function classifyInput(script: Buffer | (Buffer | number)[], allowIncomplete: boolean): "pubkeyhash" | "scripthash" | "multisig" | "pubkey" | "nonstandard"; + function classifyOutput(script: Buffer | Array): "witnesspubkeyhash" | "witnessscripthash" | "pubkeyhash" + | "scripthash" | "multisig" | "pubkey" | "witnesscommitment" | "nulldata" | "nonstandard"; - function classifyOutput(script: Buffer | (Buffer | number)[]): "witnesspubkeyhash" | "witnessscripthash" | "pubkeyhash" | "scripthash" | "multisig" | "pubkey" | "witnesscommitment" | "nulldata" | "nonstandard"; + function classifyWitness(script: Buffer | Array, allowIncomplete: boolean): "witnesspubkeyhash" | "witnessscripthash" | "nonstandard"; - function classifyWitness(script: Buffer | (Buffer | number)[], allowIncomplete: boolean): "witnesspubkeyhash" | "witnessscripthash" | "nonstandard"; + function compile(chunks: Array): Buffer; - function compile(chunks: (Buffer | number)[]): Buffer; - - function decompile(buffer: Buffer): (Buffer | number)[]; + function decompile(buffer: Buffer): Array; function fromASM(asm: string): Buffer; @@ -423,9 +419,9 @@ export namespace script { function isPushOnly(value: any): boolean; - function toASM(chunks: Buffer | (Buffer | number)[]): string; + function toASM(chunks: Buffer | Array): string; - function toStack(chunks: Buffer | (Buffer | number)[]): Buffer[]; + function toStack(chunks: Buffer | Array): Buffer[]; namespace number { function decode(buffer: Buffer, maxLength: number, minimal: boolean): number; From 47689f36ce4c5859d12246b8967ba28bd22e1a94 Mon Sep 17 00:00:00 2001 From: Daniel Lebrecht Date: Fri, 7 Jul 2017 23:09:57 +0200 Subject: [PATCH 5/7] small style fixes --- types/bitcoinjs-lib/bitcoinjs-lib-tests.ts | 1 + types/bitcoinjs-lib/index.d.ts | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 types/bitcoinjs-lib/bitcoinjs-lib-tests.ts diff --git a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts new file mode 100644 index 0000000000..ed54b008e0 --- /dev/null +++ b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts @@ -0,0 +1 @@ +console.log('no tests yet'); diff --git a/types/bitcoinjs-lib/index.d.ts b/types/bitcoinjs-lib/index.d.ts index 8e5cdcf9fa..dc2af73403 100644 --- a/types/bitcoinjs-lib/index.d.ts +++ b/types/bitcoinjs-lib/index.d.ts @@ -90,9 +90,11 @@ export class ECPair { static fromWIF(string: string, network: Network): ECPair; - static makeRandom(options?: { compressed?: boolean, network?: Network, rng?: (size: number) => Buffer }): ECPair; + static makeRandom(options?: { compressed?: boolean, network?: Network, rng?: Rng }): ECPair; } +export type Rng = (size: number) => Buffer; + export class ECSignature { constructor(r: BigInteger, s: BigInteger); From 143dd0ceb61b6da6bf76a123605b03af47d34068 Mon Sep 17 00:00:00 2001 From: Daniel Lebrecht Date: Fri, 14 Jul 2017 11:47:30 +0200 Subject: [PATCH 6/7] added and fixed tests --- types/bitcoinjs-lib/bitcoinjs-lib-tests.ts | 65 +++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts index ed54b008e0..647773ca3b 100644 --- a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts +++ b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts @@ -1 +1,64 @@ -console.log('no tests yet'); +/// + +import bigi = require('bigi'); +import bitcoin = require('bitcoinjs-lib'); + +declare const it: any; +declare const describe: any; +declare const assert: any; + +describe('bitcoinjs-lib (basic)', () => { + it('can generate a random bitcoin address', () => { + // for testing only + function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } + + // generate random keyPair + const keyPair = bitcoin.ECPair.makeRandom({ rng }); + const address = keyPair.getAddress(); + + assert.strictEqual(address, '1F5VhMHukdnUES9kfXqzPzMeF1GPHKiF64'); + }); + + it('can generate an address from a SHA256 hash', () => { + const hash = bitcoin.crypto.sha256(Buffer.from('correct horse battery staple', 'utf8')); + const d = bigi.fromBuffer(hash); + + const keyPair = new bitcoin.ECPair(d); + const address = keyPair.getAddress(); + + assert.strictEqual(address, '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8'); + }); + + it('can generate a random keypair for alternative networks', () => { + // for testing only + function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } + + const litecoin = bitcoin.networks.litecoin; + + const keyPair = bitcoin.ECPair.makeRandom({ network: litecoin, rng }); + const wif = keyPair.toWIF(); + const address = keyPair.getAddress(); + + assert.strictEqual(address, 'LZJSxZbjqJ2XVEquqfqHg1RQTDdfST5PTn'); + assert.strictEqual(wif, 'T7A4PUSgTDHecBxW1ZiYFrDNRih2o7M8Gf9xpoCgudPF9gDiNvuS'); + }); + + it('can import an address via WIF', () => { + const keyPair = bitcoin.ECPair.fromWIF('Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct', bitcoin.networks.testnet); + const address = keyPair.getAddress(); + + assert.strictEqual(address, '19AAjaTUbRjQCMuVczepkoPswiZRhjtg31'); + }); + + it('can create a Transaction', () => { + const keyPair = bitcoin.ECPair.fromWIF('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy', bitcoin.networks.testnet); + const tx = new bitcoin.TransactionBuilder(); + + tx.addInput('aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31', 0); + tx.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000); + tx.sign(0, keyPair); + + // tslint:disable-next-line:max-line-length + assert.strictEqual(tx.build().toHex(), '0100000001313eb630b128102b60241ca895f1d0ffca2170d5a0990e094f2182c102ab94aa000000006b483045022100aefbcf847900b01dd3e3debe054d3b6d03d715d50aea8525f5ea3396f168a1fb022013d181d05b15b90111808b22ef4f9ebe701caf2ab48db269691fdf4e9048f4f60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01983a0000000000001976a914ad618cf4333b3b248f9744e8e81db2964d0ae39788ac00000000'); + }); +}); From ea83455b89e09221b386432d09ef61e0706f86e4 Mon Sep 17 00:00:00 2001 From: Daniel Lebrecht Date: Fri, 14 Jul 2017 12:00:08 +0200 Subject: [PATCH 7/7] fixed old tests and they're now passing --- types/bitcoinjs-lib/bitcoinjs-lib-tests.ts | 80 +++++++++++----------- 1 file changed, 39 insertions(+), 41 deletions(-) diff --git a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts index 647773ca3b..6723a7e577 100644 --- a/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts +++ b/types/bitcoinjs-lib/bitcoinjs-lib-tests.ts @@ -1,5 +1,3 @@ -/// - import bigi = require('bigi'); import bitcoin = require('bitcoinjs-lib'); @@ -8,57 +6,57 @@ declare const describe: any; declare const assert: any; describe('bitcoinjs-lib (basic)', () => { - it('can generate a random bitcoin address', () => { - // for testing only - function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } + it('can generate a random bitcoin address', () => { + // for testing only + function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } - // generate random keyPair - const keyPair = bitcoin.ECPair.makeRandom({ rng }); - const address = keyPair.getAddress(); + // generate random keyPair + const keyPair = bitcoin.ECPair.makeRandom({ rng }); + const address = keyPair.getAddress(); - assert.strictEqual(address, '1F5VhMHukdnUES9kfXqzPzMeF1GPHKiF64'); - }); + assert.strictEqual(address, '1F5VhMHukdnUES9kfXqzPzMeF1GPHKiF64'); + }); - it('can generate an address from a SHA256 hash', () => { - const hash = bitcoin.crypto.sha256(Buffer.from('correct horse battery staple', 'utf8')); - const d = bigi.fromBuffer(hash); + it('can generate an address from a SHA256 hash', () => { + const hash = bitcoin.crypto.sha256(Buffer.from('correct horse battery staple', 'utf8')); + const d = bigi.fromBuffer(hash); - const keyPair = new bitcoin.ECPair(d); - const address = keyPair.getAddress(); + const keyPair = new bitcoin.ECPair(d); + const address = keyPair.getAddress(); - assert.strictEqual(address, '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8'); - }); + assert.strictEqual(address, '1C7zdTfnkzmr13HfA2vNm5SJYRK6nEKyq8'); + }); - it('can generate a random keypair for alternative networks', () => { - // for testing only - function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } + it('can generate a random keypair for alternative networks', () => { + // for testing only + function rng() { return new Buffer('zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'); } - const litecoin = bitcoin.networks.litecoin; + const litecoin = bitcoin.networks.litecoin; - const keyPair = bitcoin.ECPair.makeRandom({ network: litecoin, rng }); - const wif = keyPair.toWIF(); - const address = keyPair.getAddress(); + const keyPair = bitcoin.ECPair.makeRandom({ network: litecoin, rng }); + const wif = keyPair.toWIF(); + const address = keyPair.getAddress(); - assert.strictEqual(address, 'LZJSxZbjqJ2XVEquqfqHg1RQTDdfST5PTn'); - assert.strictEqual(wif, 'T7A4PUSgTDHecBxW1ZiYFrDNRih2o7M8Gf9xpoCgudPF9gDiNvuS'); - }); + assert.strictEqual(address, 'LZJSxZbjqJ2XVEquqfqHg1RQTDdfST5PTn'); + assert.strictEqual(wif, 'T7A4PUSgTDHecBxW1ZiYFrDNRih2o7M8Gf9xpoCgudPF9gDiNvuS'); + }); - it('can import an address via WIF', () => { - const keyPair = bitcoin.ECPair.fromWIF('Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct', bitcoin.networks.testnet); - const address = keyPair.getAddress(); + it('can import an address via WIF', () => { + const keyPair = bitcoin.ECPair.fromWIF('Kxr9tQED9H44gCmp6HAdmemAzU3n84H3dGkuWTKvE23JgHMW8gct', bitcoin.networks.testnet); + const address = keyPair.getAddress(); - assert.strictEqual(address, '19AAjaTUbRjQCMuVczepkoPswiZRhjtg31'); - }); + assert.strictEqual(address, '19AAjaTUbRjQCMuVczepkoPswiZRhjtg31'); + }); - it('can create a Transaction', () => { - const keyPair = bitcoin.ECPair.fromWIF('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy', bitcoin.networks.testnet); - const tx = new bitcoin.TransactionBuilder(); + it('can create a Transaction', () => { + const keyPair = bitcoin.ECPair.fromWIF('L1uyy5qTuGrVXrmrsvHWHgVzW9kKdrp27wBC7Vs6nZDTF2BRUVwy', bitcoin.networks.testnet); + const tx = new bitcoin.TransactionBuilder(); - tx.addInput('aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31', 0); - tx.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000); - tx.sign(0, keyPair); + tx.addInput('aa94ab02c182214f090e99a0d57021caffd0f195a81c24602b1028b130b63e31', 0); + tx.addOutput('1Gokm82v6DmtwKEB8AiVhm82hyFSsEvBDK', 15000); + tx.sign(0, keyPair); - // tslint:disable-next-line:max-line-length - assert.strictEqual(tx.build().toHex(), '0100000001313eb630b128102b60241ca895f1d0ffca2170d5a0990e094f2182c102ab94aa000000006b483045022100aefbcf847900b01dd3e3debe054d3b6d03d715d50aea8525f5ea3396f168a1fb022013d181d05b15b90111808b22ef4f9ebe701caf2ab48db269691fdf4e9048f4f60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01983a0000000000001976a914ad618cf4333b3b248f9744e8e81db2964d0ae39788ac00000000'); - }); + // tslint:disable-next-line:max-line-length + assert.strictEqual(tx.build().toHex(), '0100000001313eb630b128102b60241ca895f1d0ffca2170d5a0990e094f2182c102ab94aa000000006b483045022100aefbcf847900b01dd3e3debe054d3b6d03d715d50aea8525f5ea3396f168a1fb022013d181d05b15b90111808b22ef4f9ebe701caf2ab48db269691fdf4e9048f4f60121029f50f51d63b345039a290c94bffd3180c99ed659ff6ea6b1242bca47eb93b59fffffffff01983a0000000000001976a914ad618cf4333b3b248f9744e8e81db2964d0ae39788ac00000000'); + }); });