address/crypto/script/types: adhere to no-use-before-define
This commit is contained in:
parent
d3ccbb6277
commit
a1d3e33c84
4 changed files with 51 additions and 51 deletions
src
|
@ -15,32 +15,6 @@ var REVERSE_OPS = (function () {
|
|||
|
||||
var OP_INT_BASE = OPS.OP_RESERVED // OP_1 - 1
|
||||
|
||||
function toASM (chunks) {
|
||||
if (Buffer.isBuffer(chunks)) {
|
||||
chunks = decompile(chunks)
|
||||
}
|
||||
|
||||
return chunks.map(function (chunk) {
|
||||
// data?
|
||||
if (Buffer.isBuffer(chunk)) return chunk.toString('hex')
|
||||
|
||||
// opcode!
|
||||
return REVERSE_OPS[chunk]
|
||||
}).join(' ')
|
||||
}
|
||||
|
||||
function fromASM (asm) {
|
||||
typeforce(types.String, asm)
|
||||
|
||||
return compile(asm.split(' ').map(function (chunkStr) {
|
||||
// opcode?
|
||||
if (OPS[chunkStr] !== undefined) return OPS[chunkStr]
|
||||
|
||||
// data!
|
||||
return new Buffer(chunkStr, 'hex')
|
||||
}))
|
||||
}
|
||||
|
||||
function compile (chunks) {
|
||||
// TODO: remove me
|
||||
if (Buffer.isBuffer(chunks)) return chunks
|
||||
|
@ -118,6 +92,32 @@ function decompile (buffer) {
|
|||
return chunks
|
||||
}
|
||||
|
||||
function toASM (chunks) {
|
||||
if (Buffer.isBuffer(chunks)) {
|
||||
chunks = decompile(chunks)
|
||||
}
|
||||
|
||||
return chunks.map(function (chunk) {
|
||||
// data?
|
||||
if (Buffer.isBuffer(chunk)) return chunk.toString('hex')
|
||||
|
||||
// opcode!
|
||||
return REVERSE_OPS[chunk]
|
||||
}).join(' ')
|
||||
}
|
||||
|
||||
function fromASM (asm) {
|
||||
typeforce(types.String, asm)
|
||||
|
||||
return compile(asm.split(' ').map(function (chunkStr) {
|
||||
// opcode?
|
||||
if (OPS[chunkStr] !== undefined) return OPS[chunkStr]
|
||||
|
||||
// data!
|
||||
return new Buffer(chunkStr, 'hex')
|
||||
}))
|
||||
}
|
||||
|
||||
function isCanonicalPubKey (buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) return false
|
||||
if (buffer.length < 33) return false
|
||||
|
@ -133,13 +133,6 @@ function isCanonicalPubKey (buffer) {
|
|||
return false
|
||||
}
|
||||
|
||||
function isCanonicalSignature (buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) return false
|
||||
if (!isDefinedHashType(buffer[buffer.length - 1])) return false
|
||||
|
||||
return bip66.check(buffer.slice(0, -1))
|
||||
}
|
||||
|
||||
function isDefinedHashType (hashType) {
|
||||
var hashTypeMod = hashType & ~0x80
|
||||
|
||||
|
@ -147,6 +140,13 @@ function isDefinedHashType (hashType) {
|
|||
return hashTypeMod > 0x00 && hashTypeMod < 0x04
|
||||
}
|
||||
|
||||
function isCanonicalSignature (buffer) {
|
||||
if (!Buffer.isBuffer(buffer)) return false
|
||||
if (!isDefinedHashType(buffer[buffer.length - 1])) return false
|
||||
|
||||
return bip66.check(buffer.slice(0, -1))
|
||||
}
|
||||
|
||||
function isPubKeyHashInput (script) {
|
||||
var chunks = decompile(script)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue