Browse Source

Address: Fix Buffer data recognition in browsers

patch-2
Braydon Fuller 10 years ago
parent
commit
5ff349758c
  1. 9
      lib/address.js

9
lib/address.js

@ -4,7 +4,6 @@ var base58check = require('./encoding/base58check');
var networks = require('./networks');
var Hash = require('./crypto/hash');
/**
*
* Bitcore Address
@ -38,9 +37,9 @@ function Address(data, network, type) {
var info;
// transform and validate input data
if (data instanceof Buffer && data.length === 20) {
if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 20) {
info = Address._transformHash(data);
} else if (data instanceof Buffer && data.length === 21) {
} else if ((data instanceof Buffer || data instanceof Uint8Array) && data.length === 21) {
info = Address._transformBuffer(data, network, type);
} else if (data.constructor && (data.constructor.name && data.constructor.name === 'Pubkey')) {
info = Address._transformPubkey(data);
@ -74,7 +73,7 @@ function Address(data, network, type) {
*/
Address._transformHash = function(hash){
var info = {};
if (!hash instanceof Buffer) {
if (!(hash instanceof Buffer) && !(hash instanceof Uint8Array)) {
throw new Error('Address supplied is not a buffer');
}
if (hash.length !== 20) {
@ -95,7 +94,7 @@ Address._transformHash = function(hash){
*/
Address._transformBuffer = function(buffer, network, type){
var info = {};
if (!buffer instanceof Buffer) {
if (!(buffer instanceof Buffer) && !(buffer instanceof Uint8Array)) {
throw new Error('Address supplied is not a buffer');
}
if (buffer.length !== 1 + 20) {

Loading…
Cancel
Save