Remove safe-buffer and add type to bitcoin-ops

This commit is contained in:
junderw 2018-12-29 21:39:19 +09:00
parent 3124e50e52
commit e58d012615
No known key found for this signature in database
GPG key ID: B256185D3A971908
26 changed files with 33 additions and 33 deletions

View file

@ -50,7 +50,6 @@
"merkle-lib": "^2.0.10", "merkle-lib": "^2.0.10",
"pushdata-bitcoin": "^1.0.1", "pushdata-bitcoin": "^1.0.1",
"randombytes": "^2.0.1", "randombytes": "^2.0.1",
"safe-buffer": "^5.1.1",
"tiny-secp256k1": "^1.0.0", "tiny-secp256k1": "^1.0.0",
"typeforce": "^1.11.3", "typeforce": "^1.11.3",
"typescript": "^3.2.2", "typescript": "^3.2.2",

View file

@ -4,7 +4,7 @@ import * as types from './types'
import * as bscript from './script' import * as bscript from './script'
import * as networks from './networks' import * as networks from './networks'
import * as payments from './payments' import * as payments from './payments'
const Buffer = require('safe-buffer').Buffer
const bech32 = require('bech32') const bech32 = require('bech32')
const bs58check = require('bs58check') const bs58check = require('bs58check')
const typeforce = require('typeforce') const typeforce = require('typeforce')

View file

@ -2,7 +2,7 @@ import { Transaction } from './transaction'
import * as types from './types' import * as types from './types'
import * as bcrypto from './crypto' import * as bcrypto from './crypto'
import { reverseBuffer } from './bufferutils' import { reverseBuffer } from './bufferutils'
const Buffer = require('safe-buffer').Buffer
const fastMerkleRoot = require('merkle-lib/fastRoot') const fastMerkleRoot = require('merkle-lib/fastRoot')
const typeforce = require('typeforce') const typeforce = require('typeforce')
const varuint = require('varuint-bitcoin') const varuint = require('varuint-bitcoin')

View file

@ -1,4 +1,3 @@
const opcodes = require('bitcoin-ops')
const bip32 = require('bip32') const bip32 = require('bip32')
import { Block } from './block' import { Block } from './block'
@ -10,6 +9,7 @@ import * as crypto from './crypto'
import * as networks from './networks' import * as networks from './networks'
import * as payments from './payments' import * as payments from './payments'
import * as script from './script' import * as script from './script'
import { OPS as opcodes } from './script'
export { export {
Block, Block,

View file

@ -3,7 +3,7 @@ import * as bscript from '../script'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../script'
function stacksEqual (a: Array<Buffer>, b: Array<Buffer>): boolean { function stacksEqual (a: Array<Buffer>, b: Array<Buffer>): boolean {
if (a.length !== b.length) return false if (a.length !== b.length) return false
@ -32,7 +32,7 @@ export function p2data (a: Payment, opts?: PaymentOpts): Payment {
lazy.prop(o, 'output', function () { lazy.prop(o, 'output', function () {
if (!a.data) return if (!a.data) return
return bscript.compile([OPS.OP_RETURN].concat(a.data)) return bscript.compile((<Array<Buffer | number>>[OPS.OP_RETURN]).concat(a.data))
}) })
lazy.prop(o, 'data', function () { lazy.prop(o, 'data', function () {
if (!a.output) return if (!a.output) return

View file

@ -3,7 +3,7 @@ import * as bscript from '../script'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../script'
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1 const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
@ -87,7 +87,7 @@ export function p2ms (a: Payment, opts?: PaymentOpts): Payment {
}) })
lazy.prop(o, 'input', function () { lazy.prop(o, 'input', function () {
if (!a.signatures) return if (!a.signatures) return
return bscript.compile([OPS.OP_0].concat(a.signatures)) return bscript.compile((<Array<Buffer | number>>[OPS.OP_0]).concat(a.signatures))
}) })
lazy.prop(o, 'witness', function () { lazy.prop(o, 'witness', function () {
if (!o.input) return if (!o.input) return

View file

@ -3,7 +3,7 @@ import * as bscript from '../script'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../script'
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
// input: {signature} // input: {signature}

View file

@ -4,7 +4,7 @@ import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../script'
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
const bs58check = require('bs58check') const bs58check = require('bs58check')

View file

@ -5,7 +5,7 @@ import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../script'
const bs58check = require('bs58check') const bs58check = require('bs58check')

View file

@ -4,7 +4,7 @@ import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../script'
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
const bech32 = require('bech32') const bech32 = require('bech32')

View file

@ -5,7 +5,7 @@ import * as bcrypto from '../crypto'
import * as lazy from './lazy' import * as lazy from './lazy'
import { bitcoin as BITCOIN_NETWORK } from '../networks' import { bitcoin as BITCOIN_NETWORK } from '../networks'
const typef = require('typeforce') const typef = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../script'
const bech32 = require('bech32') const bech32 = require('bech32')

View file

@ -1,14 +1,15 @@
import * as types from './types' import * as types from './types'
import * as scriptNumber from './script_number' import * as scriptNumber from './script_number'
import * as scriptSignature from './script_signature' import * as scriptSignature from './script_signature'
const Buffer = require('safe-buffer').Buffer
const bip66 = require('bip66') const bip66 = require('bip66')
const ecc = require('tiny-secp256k1') const ecc = require('tiny-secp256k1')
const pushdata = require('pushdata-bitcoin') const pushdata = require('pushdata-bitcoin')
const typeforce = require('typeforce') const typeforce = require('typeforce')
const OPS = require('bitcoin-ops') export type OpCode = number
const REVERSE_OPS = require('bitcoin-ops/map') export const OPS = <{[index:string]: OpCode}> require('bitcoin-ops')
const REVERSE_OPS = <{[index:number]: string}> require('bitcoin-ops/map')
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1 const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
function isOPInt (value:number): boolean { function isOPInt (value:number): boolean {

View file

@ -1,4 +1,4 @@
const Buffer = require('safe-buffer').Buffer
export function decode (buffer: Buffer, maxLength?: number, minimal?: boolean): number { export function decode (buffer: Buffer, maxLength?: number, minimal?: boolean): number {
maxLength = maxLength || 4 maxLength = maxLength || 4

View file

@ -1,6 +1,6 @@
import * as types from './types' import * as types from './types'
const bip66 = require('bip66') const bip66 = require('bip66')
const Buffer = require('safe-buffer').Buffer
const typeforce = require('typeforce') const typeforce = require('typeforce')
const ZERO = Buffer.alloc(1, 0) const ZERO = Buffer.alloc(1, 0)

View file

@ -1,7 +1,7 @@
// OP_0 [signatures ...] // OP_0 [signatures ...]
import * as bscript from '../../script' import * as bscript from '../../script'
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
function partialSignature (value: number | Buffer): boolean { function partialSignature (value: number | Buffer): boolean {
return value === OPS.OP_0 || bscript.isCanonicalScriptSignature(<Buffer>value) return value === OPS.OP_0 || bscript.isCanonicalScriptSignature(<Buffer>value)

View file

@ -2,7 +2,7 @@
import * as bscript from '../../script' import * as bscript from '../../script'
import * as types from '../../types' import * as types from '../../types'
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1 const OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean { export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean {

View file

@ -1,6 +1,6 @@
// OP_RETURN {data} // OP_RETURN {data}
import * as bscript from '../script' import * as bscript from '../script'
const OPS = require('bitcoin-ops') import { OPS } from '../script'
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check (script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script)

View file

@ -1,7 +1,7 @@
// {pubKey} OP_CHECKSIG // {pubKey} OP_CHECKSIG
import * as bscript from '../../script' import * as bscript from '../../script'
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check (script: Buffer | Array<number | Buffer>): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script) const chunks = <Array<number | Buffer>>bscript.decompile(script)

View file

@ -1,7 +1,7 @@
// OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG
import * as bscript from '../../script' import * as bscript from '../../script'
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check (script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script)

View file

@ -7,7 +7,7 @@ import * as p2pkh from '../pubkeyhash'
import * as p2wpkho from '../witnesspubkeyhash/output' import * as p2wpkho from '../witnesspubkeyhash/output'
import * as p2wsho from '../witnessscripthash/output' import * as p2wsho from '../witnessscripthash/output'
const Buffer = require('safe-buffer').Buffer
export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean { export function check (script: Buffer | Array<number | Buffer>, allowIncomplete?: boolean): boolean {
const chunks = <Array<number | Buffer>>bscript.decompile(script) const chunks = <Array<number | Buffer>>bscript.decompile(script)

View file

@ -1,7 +1,7 @@
// OP_HASH160 {scriptHash} OP_EQUAL // OP_HASH160 {scriptHash} OP_EQUAL
import * as bscript from '../../script' import * as bscript from '../../script'
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check (script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script)

View file

@ -2,9 +2,9 @@
import * as bscript from '../../script' import * as bscript from '../../script'
import * as types from '../../types' import * as types from '../../types'
const Buffer = require('safe-buffer').Buffer
const typeforce = require('typeforce') const typeforce = require('typeforce')
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
const HEADER: Buffer = Buffer.from('aa21a9ed', 'hex') const HEADER: Buffer = Buffer.from('aa21a9ed', 'hex')

View file

@ -1,7 +1,7 @@
// OP_0 {pubKeyHash} // OP_0 {pubKeyHash}
import * as bscript from '../../script' import * as bscript from '../../script'
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check (script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script)

View file

@ -1,7 +1,7 @@
// OP_0 {scriptHash} // OP_0 {scriptHash}
import * as bscript from '../../script' import * as bscript from '../../script'
const OPS = require('bitcoin-ops') import { OPS } from '../../script'
export function check (script: Buffer | Array<number | Buffer>): boolean { export function check (script: Buffer | Array<number | Buffer>): boolean {
const buffer = bscript.compile(script) const buffer = bscript.compile(script)

View file

@ -3,8 +3,8 @@ import * as bscript from './script'
import * as types from './types' import * as types from './types'
import * as bufferutils from './bufferutils' import * as bufferutils from './bufferutils'
import { reverseBuffer } from './bufferutils' import { reverseBuffer } from './bufferutils'
const Buffer = require('safe-buffer').Buffer import { OPS as opcodes } from './script'
const opcodes = require('bitcoin-ops')
const typeforce = require('typeforce') const typeforce = require('typeforce')
const varuint = require('varuint-bitcoin') const varuint = require('varuint-bitcoin')

View file

@ -11,9 +11,9 @@ import * as bscript from './script'
import { Payment } from './payments' import { Payment } from './payments'
import * as payments from './payments' import * as payments from './payments'
import * as classify from './classify' import * as classify from './classify'
const ops = require('bitcoin-ops') import { OPS as ops } from './script'
const typeforce = require('typeforce') const typeforce = require('typeforce')
const Buffer = require('safe-buffer').Buffer
const SCRIPT_TYPES = classify.types const SCRIPT_TYPES = classify.types