stellar-base
Advanced tools
Comparing version 0.4.13 to 0.4.14
@@ -121,3 +121,3 @@ "use strict"; | ||
* Creates and returns a "hash" memo. | ||
* @param {array|string} hash - 32 byte hash | ||
* @param {array|string} hash - 32 byte hash or hex encoded string | ||
*/ | ||
@@ -136,3 +136,3 @@ | ||
})(function (hash) { | ||
var error = new Error("Expects a 32 byte hash value. Got " + hash); | ||
var error = new Error("Expects a 32 byte hash value or hex encoded string. Got " + hash); | ||
@@ -143,4 +143,7 @@ if (isUndefined(hash)) { | ||
if (isString(hash) && Buffer.byteLength(hash) != 32) { | ||
throw error; | ||
if (isString(hash)) { | ||
if (!/^[0-9A-Fa-f]{64}$/g.test(hash)) { | ||
throw error; | ||
} | ||
hash = new Buffer(hash, "hex"); | ||
} | ||
@@ -159,7 +162,7 @@ | ||
* Creates and returns a "return hash" memo. | ||
* @param {array|string} hash - 32 byte hash | ||
* @param {array|string} hash - 32 byte hash or hex encoded string | ||
*/ | ||
value: function returnHash(hash) { | ||
var error = new Error("Expects a 32 byte hash value. Got " + hash); | ||
var error = new Error("Expects a 32 byte hash value or hex encoded string. Got " + hash); | ||
@@ -170,4 +173,7 @@ if (isUndefined(hash)) { | ||
if (isString(hash) && Buffer.byteLength(hash) != 32) { | ||
throw error; | ||
if (isString(hash)) { | ||
if (!/^[0-9A-Fa-f]{64}$/g.test(hash)) { | ||
throw error; | ||
} | ||
hash = new Buffer(hash, "hex"); | ||
} | ||
@@ -174,0 +180,0 @@ |
{ | ||
"name": "stellar-base", | ||
"version": "0.4.13", | ||
"version": "0.4.14", | ||
"dependencies": { | ||
@@ -5,0 +5,0 @@ "babel-runtime": { |
{ | ||
"name": "stellar-base", | ||
"version": "0.4.13", | ||
"version": "0.4.14", | ||
"description": "Low level stellar support library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -67,6 +67,6 @@ import {default as xdr} from "./generated/stellar-xdr_generated"; | ||
* Creates and returns a "hash" memo. | ||
* @param {array|string} hash - 32 byte hash | ||
* @param {array|string} hash - 32 byte hash or hex encoded string | ||
*/ | ||
static hash(hash) { | ||
let error = new Error("Expects a 32 byte hash value. Got " + hash); | ||
let error = new Error("Expects a 32 byte hash value or hex encoded string. Got " + hash); | ||
@@ -77,4 +77,7 @@ if (isUndefined(hash)) { | ||
if (isString(hash) && Buffer.byteLength(hash) != 32) { | ||
throw error; | ||
if (isString(hash)) { | ||
if (!/^[0-9A-Fa-f]{64}$/g.test(hash)) { | ||
throw error; | ||
} | ||
hash = new Buffer(hash, 'hex'); | ||
} | ||
@@ -91,6 +94,6 @@ | ||
* Creates and returns a "return hash" memo. | ||
* @param {array|string} hash - 32 byte hash | ||
* @param {array|string} hash - 32 byte hash or hex encoded string | ||
*/ | ||
static returnHash(hash) { | ||
let error = new Error("Expects a 32 byte hash value. Got " + hash); | ||
let error = new Error("Expects a 32 byte hash value or hex encoded string. Got " + hash); | ||
@@ -101,4 +104,7 @@ if (isUndefined(hash)) { | ||
if (isString(hash) && Buffer.byteLength(hash) != 32) { | ||
throw error; | ||
if (isString(hash)) { | ||
if (!/^[0-9A-Fa-f]{64}$/g.test(hash)) { | ||
throw error; | ||
} | ||
hash = new Buffer(hash, 'hex'); | ||
} | ||
@@ -105,0 +111,0 @@ |
@@ -41,2 +41,3 @@ | ||
expect(() => StellarBase.Memo.hash(new Buffer(32))).to.not.throw(); | ||
expect(() => StellarBase.Memo.hash('0000000000000000000000000000000000000000000000000000000000000000')).to.not.throw(); | ||
}); | ||
@@ -52,3 +53,5 @@ | ||
expect(() => StellarBase.Memo.hash(new Buffer(33))).to.throw(/Expects a 32 byte hash value/); | ||
expect(() => StellarBase.Memo.hash('00000000000000000000000000000000000000000000000000000000000000')).to.throw(/Expects a 32 byte hash value/); | ||
expect(() => StellarBase.Memo.hash('000000000000000000000000000000000000000000000000000000000000000000')).to.throw(/Expects a 32 byte hash value/); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
2502411
40791