Parsing BTC testnet address.
This commit is contained in:
parent
93d061c96a
commit
1da9a79296
2 changed files with 31 additions and 0 deletions
|
|
@ -34,9 +34,13 @@
|
||||||
"req-param0": "",
|
"req-param0": "",
|
||||||
"req-param1": ""
|
"req-param1": ""
|
||||||
},
|
},
|
||||||
|
testnet: false,
|
||||||
url: ''
|
url: ''
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Need to do testnet, and copay too
|
||||||
|
|
||||||
*/
|
*/
|
||||||
// bitcoincash:?r=https://bitpay.com/i/GLRoZMZxaWBqLqpoXexzoD
|
// bitcoincash:?r=https://bitpay.com/i/GLRoZMZxaWBqLqpoXexzoD
|
||||||
function parse(uri) {
|
function parse(uri) {
|
||||||
|
|
@ -146,10 +150,17 @@
|
||||||
// Just a rough validation to exclude half-pasted addresses, or things obviously not bitcoin addresses
|
// Just a rough validation to exclude half-pasted addresses, or things obviously not bitcoin addresses
|
||||||
var cashAddrRe = /^((?:q|p)[a-z0-9]{41})|((?:Q|P)[A-Z0-9]{41})$/;
|
var cashAddrRe = /^((?:q|p)[a-z0-9]{41})|((?:Q|P)[A-Z0-9]{41})$/;
|
||||||
var legacyRe = /^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/;
|
var legacyRe = /^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$/;
|
||||||
|
var legacyTestnetRe = /^[mn][a-km-zA-HJ-NP-Z1-9]{25,34}$/;
|
||||||
|
|
||||||
if (legacyRe.test(address)) {
|
if (legacyRe.test(address)) {
|
||||||
parsed.address = address;
|
parsed.address = address;
|
||||||
parsed.legacyAddress = address;
|
parsed.legacyAddress = address;
|
||||||
|
parsed.testnet = false;
|
||||||
|
|
||||||
|
} else if (legacyTestnetRe.test(address)) {
|
||||||
|
parsed.address = address;
|
||||||
|
parsed.legacyAddress = address;
|
||||||
|
parsed.testnet = true;
|
||||||
|
|
||||||
} else if (cashAddrRe.test(address)) {
|
} else if (cashAddrRe.test(address)) {
|
||||||
var cashAddr = 'bitcoincash:' + address.toLowerCase();
|
var cashAddr = 'bitcoincash:' + address.toLowerCase();
|
||||||
|
|
@ -159,6 +170,8 @@
|
||||||
var bchAddresses = bitcoinCashJsService.readAddress(cashAddr);
|
var bchAddresses = bitcoinCashJsService.readAddress(cashAddr);
|
||||||
parsed.legacyAddress = bchAddresses['legacy'];
|
parsed.legacyAddress = bchAddresses['legacy'];
|
||||||
|
|
||||||
|
parsed.testnet = false;
|
||||||
|
|
||||||
} // TODO: Check for private key
|
} // TODO: Check for private key
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,21 @@ fdescribe('bitcoinUriService', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
it('Bitcoin testnet address', function() {
|
||||||
|
|
||||||
|
var parsed = bitcoinUriService.parse('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
||||||
|
|
||||||
|
expect(parsed.isValid).toBe(true);
|
||||||
|
expect(parsed.address).toBe('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
||||||
|
expect(parsed.coin).toBeUndefined();
|
||||||
|
expect(parsed.legacyAddress).toBe('mtWcoToWhbtPoCby5fvs8xdBujT5GGenD4');
|
||||||
|
expect(parsed.testnet).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('legacy address', function() {
|
it('legacy address', function() {
|
||||||
|
|
||||||
var parsed = bitcoinUriService.parse('1JXeGEu7bNEAYu6URT6dU6g1Ys6ffSAWYW');
|
var parsed = bitcoinUriService.parse('1JXeGEu7bNEAYu6URT6dU6g1Ys6ffSAWYW');
|
||||||
|
|
@ -18,6 +33,7 @@ fdescribe('bitcoinUriService', function() {
|
||||||
expect(parsed.address).toBe('1JXeGEu7bNEAYu6URT6dU6g1Ys6ffSAWYW');
|
expect(parsed.address).toBe('1JXeGEu7bNEAYu6URT6dU6g1Ys6ffSAWYW');
|
||||||
expect(parsed.coin).toBeUndefined();
|
expect(parsed.coin).toBeUndefined();
|
||||||
expect(parsed.legacyAddress).toBe('1JXeGEu7bNEAYu6URT6dU6g1Ys6ffSAWYW');
|
expect(parsed.legacyAddress).toBe('1JXeGEu7bNEAYu6URT6dU6g1Ys6ffSAWYW');
|
||||||
|
expect(parsed.testnet).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cashAddr with prefix', function() {
|
it('cashAddr with prefix', function() {
|
||||||
|
|
@ -28,6 +44,7 @@ fdescribe('bitcoinUriService', function() {
|
||||||
expect(parsed.address).toBe('bitcoincash:qrq9p82a247lecv08ldk5p5h6ahtnjzpqcnh8yhq92');
|
expect(parsed.address).toBe('bitcoincash:qrq9p82a247lecv08ldk5p5h6ahtnjzpqcnh8yhq92');
|
||||||
expect(parsed.coin).toBe('bch');
|
expect(parsed.coin).toBe('bch');
|
||||||
expect(parsed.legacyAddress).toBe('1JXsK3HSFqoMnwh4Mevf5bTgqPcgNWX7ic');
|
expect(parsed.legacyAddress).toBe('1JXsK3HSFqoMnwh4Mevf5bTgqPcgNWX7ic');
|
||||||
|
expect(parsed.testnet).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cashAddr without prefix', function() {
|
it('cashAddr without prefix', function() {
|
||||||
|
|
@ -38,5 +55,6 @@ fdescribe('bitcoinUriService', function() {
|
||||||
expect(parsed.address).toBe('bitcoincash:qqen2y3l28dpk0dzsag8w027ds96u7z4pc0uxtl0nq');
|
expect(parsed.address).toBe('bitcoincash:qqen2y3l28dpk0dzsag8w027ds96u7z4pc0uxtl0nq');
|
||||||
expect(parsed.coin).toBe('bch');
|
expect(parsed.coin).toBe('bch');
|
||||||
expect(parsed.legacyAddress).toBe('15fm3EwqgBYcxkndALBfforueps5yWKReJ');
|
expect(parsed.legacyAddress).toBe('15fm3EwqgBYcxkndALBfforueps5yWKReJ');
|
||||||
|
expect(parsed.testnet).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue