Address: Fix Buffer data recognition in browsers
This commit is contained in:
parent
0df97a42fe
commit
5ff349758c
@ -4,7 +4,6 @@ var base58check = require('./encoding/base58check');
|
|||||||
var networks = require('./networks');
|
var networks = require('./networks');
|
||||||
var Hash = require('./crypto/hash');
|
var Hash = require('./crypto/hash');
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Bitcore Address
|
* Bitcore Address
|
||||||
@ -38,9 +37,9 @@ function Address(data, network, type) {
|
|||||||
var info;
|
var info;
|
||||||
|
|
||||||
// transform and validate input data
|
// 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);
|
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);
|
info = Address._transformBuffer(data, network, type);
|
||||||
} else if (data.constructor && (data.constructor.name && data.constructor.name === 'Pubkey')) {
|
} else if (data.constructor && (data.constructor.name && data.constructor.name === 'Pubkey')) {
|
||||||
info = Address._transformPubkey(data);
|
info = Address._transformPubkey(data);
|
||||||
@ -74,7 +73,7 @@ function Address(data, network, type) {
|
|||||||
*/
|
*/
|
||||||
Address._transformHash = function(hash){
|
Address._transformHash = function(hash){
|
||||||
var info = {};
|
var info = {};
|
||||||
if (!hash instanceof Buffer) {
|
if (!(hash instanceof Buffer) && !(hash instanceof Uint8Array)) {
|
||||||
throw new Error('Address supplied is not a buffer');
|
throw new Error('Address supplied is not a buffer');
|
||||||
}
|
}
|
||||||
if (hash.length !== 20) {
|
if (hash.length !== 20) {
|
||||||
@ -95,7 +94,7 @@ Address._transformHash = function(hash){
|
|||||||
*/
|
*/
|
||||||
Address._transformBuffer = function(buffer, network, type){
|
Address._transformBuffer = function(buffer, network, type){
|
||||||
var info = {};
|
var info = {};
|
||||||
if (!buffer instanceof Buffer) {
|
if (!(buffer instanceof Buffer) && !(buffer instanceof Uint8Array)) {
|
||||||
throw new Error('Address supplied is not a buffer');
|
throw new Error('Address supplied is not a buffer');
|
||||||
}
|
}
|
||||||
if (buffer.length !== 1 + 20) {
|
if (buffer.length !== 1 + 20) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user