use safe-buffer

This commit is contained in:
Daniel Cousens 2018-04-13 16:06:41 +10:00
parent c16847434c
commit 90a73e195e
3 changed files with 8 additions and 6 deletions

View file

@ -41,7 +41,7 @@
"merkle-lib": "^2.0.10",
"pushdata-bitcoin": "^1.0.1",
"randombytes": "^2.0.1",
"safe-buffer": "^5.0.1",
"safe-buffer": "^5.1.1",
"typeforce": "^1.11.3",
"varuint-bitcoin": "^1.0.4",
"wif": "^2.0.1"

View file

@ -1,5 +1,6 @@
var bip66 = require('bip66')
var BigInteger = require('bigi')
var Buffer = require('safe-buffer').Buffer
var typeforce = require('typeforce')
var types = require('./types')
@ -39,11 +40,11 @@ function encode (signature, hashType) {
var hashTypeMod = hashType & ~0x80
if (hashTypeMod <= 0 || hashTypeMod >= 4) throw new Error('Invalid hashType ' + hashType)
var hashTypeBuffer = new Buffer(1)
var hashTypeBuffer = Buffer.allocUnsafe(1)
hashTypeBuffer.writeUInt8(hashType, 0)
var r = new Buffer(signature.r.toDERInteger())
var s = new Buffer(signature.s.toDERInteger())
var r = Buffer.from(signature.r.toDERInteger())
var s = Buffer.from(signature.s.toDERInteger())
return Buffer.concat([
bip66.encode(r, s),

View file

@ -3,6 +3,7 @@
var assert = require('assert')
var bscriptSig = require('../src/script').signature
var BigInteger = require('bigi')
var Buffer = require('safe-buffer').Buffer
var fixtures = require('./fixtures/signature.json')
describe('Script Signatures', function () {
@ -45,7 +46,7 @@ describe('Script Signatures', function () {
describe('decode', function () {
fixtures.valid.forEach(function (f) {
it('decodes ' + f.hex, function () {
var decode = bscriptSig.decode(new Buffer(f.hex, 'hex'))
var decode = bscriptSig.decode(Buffer.from(f.hex, 'hex'))
assert.deepEqual(toRaw(decode.signature), f.raw)
assert.strictEqual(decode.hashType, f.hashType)
@ -54,7 +55,7 @@ describe('Script Signatures', function () {
fixtures.invalid.forEach(function (f) {
it('throws on ' + f.hex, function () {
var buffer = new Buffer(f.hex, 'hex')
var buffer = Buffer.from(f.hex, 'hex')
assert.throws(function () {
bscriptSig.decode(buffer)