Fix some exports
This commit is contained in:
parent
037fbd8984
commit
91d3037cf3
3 changed files with 33 additions and 34 deletions
|
@ -9,18 +9,18 @@ const payments = require('./payments')
|
|||
import * as Networks from './networks'
|
||||
import { Network } from './networks'
|
||||
|
||||
export declare type Base58CheckResult = {
|
||||
export type Base58CheckResult = {
|
||||
hash: Buffer;
|
||||
version: number;
|
||||
}
|
||||
|
||||
export declare type Bech32Result = {
|
||||
export type Bech32Result = {
|
||||
version: number;
|
||||
prefix: string;
|
||||
data: Buffer;
|
||||
}
|
||||
|
||||
function fromBase58Check (address: string): Base58CheckResult {
|
||||
export function fromBase58Check (address: string): Base58CheckResult {
|
||||
const payload = bs58check.decode(address)
|
||||
|
||||
// TODO: 4.0.0, move to "toOutputScript"
|
||||
|
@ -33,7 +33,7 @@ function fromBase58Check (address: string): Base58CheckResult {
|
|||
return { version: version, hash: hash }
|
||||
}
|
||||
|
||||
function fromBech32 (address: string): Bech32Result {
|
||||
export function fromBech32 (address: string): Bech32Result {
|
||||
const result = bech32.decode(address)
|
||||
const data = bech32.fromWords(result.words.slice(1))
|
||||
|
||||
|
@ -44,7 +44,7 @@ function fromBech32 (address: string): Bech32Result {
|
|||
}
|
||||
}
|
||||
|
||||
function toBase58Check (hash: Buffer, version: number): string {
|
||||
export function toBase58Check (hash: Buffer, version: number): string {
|
||||
typeforce(types.tuple(types.Hash160bit, types.UInt8), arguments)
|
||||
|
||||
const payload = Buffer.allocUnsafe(21)
|
||||
|
@ -54,14 +54,14 @@ function toBase58Check (hash: Buffer, version: number): string {
|
|||
return bs58check.encode(payload)
|
||||
}
|
||||
|
||||
function toBech32 (data: Buffer, version: number, prefix: string): string {
|
||||
export function toBech32 (data: Buffer, version: number, prefix: string): string {
|
||||
const words = bech32.toWords(data)
|
||||
words.unshift(version)
|
||||
|
||||
return bech32.encode(prefix, words)
|
||||
}
|
||||
|
||||
function fromOutputScript (output: Buffer, network: Network): string { //TODO: Network
|
||||
export function fromOutputScript (output: Buffer, network: Network): string { //TODO: Network
|
||||
network = network || networks.bitcoin
|
||||
|
||||
try { return payments.p2pkh({ output, network }).address } catch (e) {}
|
||||
|
@ -72,7 +72,7 @@ function fromOutputScript (output: Buffer, network: Network): string { //TODO: N
|
|||
throw new Error(bscript.toASM(output) + ' has no matching Address')
|
||||
}
|
||||
|
||||
function toOutputScript (address: string, network: Network): Buffer {
|
||||
export function toOutputScript (address: string, network: Network): Buffer {
|
||||
network = network || networks.bitcoin
|
||||
|
||||
let decodeBase58: Base58CheckResult
|
||||
|
@ -100,13 +100,3 @@ function toOutputScript (address: string, network: Network): Buffer {
|
|||
|
||||
throw new Error(address + ' has no matching Script')
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
fromBase58Check: fromBase58Check,
|
||||
fromBech32: fromBech32,
|
||||
fromOutputScript: fromOutputScript,
|
||||
toBase58Check: toBase58Check,
|
||||
toBech32: toBech32,
|
||||
toOutputScript: toOutputScript
|
||||
}
|
||||
export {}
|
||||
|
|
37
src/index.ts
37
src/index.ts
|
@ -1,17 +1,26 @@
|
|||
const script = require('./script')
|
||||
const opcodes = require('bitcoin-ops')
|
||||
|
||||
module.exports = {
|
||||
Block: require('./block'),
|
||||
ECPair: require('./ecpair'),
|
||||
Transaction: require('./transaction'),
|
||||
TransactionBuilder: require('./transaction_builder'),
|
||||
import * as Block from './block'
|
||||
import * as ECPair from './ecpair'
|
||||
import * as Transaction from './transaction'
|
||||
import * as TransactionBuilder from './transaction_builder'
|
||||
import * as address from './address'
|
||||
import * as bip32 from 'bip32'
|
||||
import * as crypto from './crypto'
|
||||
import * as networks from './networks'
|
||||
import * as payments from './payments'
|
||||
import * as script from './script'
|
||||
|
||||
address: require('./address'),
|
||||
bip32: require('bip32'),
|
||||
crypto: require('./crypto'),
|
||||
networks: require('./networks'),
|
||||
opcodes: require('bitcoin-ops'),
|
||||
payments: require('./payments'),
|
||||
script: script
|
||||
export {
|
||||
Block,
|
||||
ECPair,
|
||||
Transaction,
|
||||
TransactionBuilder,
|
||||
address,
|
||||
bip32,
|
||||
crypto,
|
||||
networks,
|
||||
opcodes,
|
||||
payments,
|
||||
script,
|
||||
}
|
||||
export {}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// https://en.bitcoin.it/wiki/List_of_address_prefixes
|
||||
// Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
|
||||
export declare type Network = {
|
||||
export type Network = {
|
||||
messagePrefix: string;
|
||||
bech32: string;
|
||||
bip32: bip32;
|
||||
|
@ -9,7 +9,7 @@ export declare type Network = {
|
|||
wif: number;
|
||||
}
|
||||
|
||||
declare type bip32 = {
|
||||
type bip32 = {
|
||||
public: number;
|
||||
private: number;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue