Skip to content
This repository was archived by the owner on Oct 30, 2018. It is now read-only.

Commit 74bd144

Browse files
committed
Add Ethereum address as a valid payout address
1 parent 5472a37 commit 74bd144

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/utils.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,19 @@ const bytes = require('bytes');
2020
*/
2121
exports._isValidPayoutAddress = function(address) {
2222
return bitcore.Address.isValid(address) ||
23-
bitcore.Address.isValid(address, bitcore.Networks.testnet);
23+
bitcore.Address.isValid(address, bitcore.Networks.testnet) ||
24+
this.isValidEthereumAddress(address);
25+
};
26+
27+
/**
28+
* Validate the given payout address is an Ethereum address
29+
* @param {String} address
30+
*/
31+
exports.isValidEthereumAddress = function(address) {
32+
if (typeof address !== 'string') {
33+
return false;
34+
}
35+
return /^0x([0-9A-Fa-f]{2}){20}$/.test(address);
2436
};
2537

2638
/**

test/utils.unit.js

+16
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,22 @@ describe('module:utils', function() {
3030

3131
});
3232

33+
describe('#isValidEthereumAddress', function() {
34+
35+
it('should return true for valid mainnet', function() {
36+
expect(utils.isValidEthereumAddress(
37+
'0xC2D7CF95645D33006175B78989035C7c9061d3F9'
38+
)).to.equal(true);
39+
});
40+
41+
it('should return false for invalid address', function() {
42+
expect(utils.isValidEthereumAddress(
43+
'1234 Fake Street'
44+
)).to.equal(false);
45+
});
46+
47+
});
48+
3349
describe('#_isValidDirectory', function() {
3450

3551
it('should return the the result of existsSync', function() {

0 commit comments

Comments
 (0)