Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Groestlcoin (GRS) #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ npm install multicoin-address-validator
* Gnosis/gno `'Gnosis'` or `'gno'`
* Golem/glm `'Golem'` or `'glm'`
* Golem (GNT)/gnt `'Golem (GNT)'` or `'gnt'`
* Groestlcoin/grs `'Groestlcoin'` or `'grs'`
* HedgeTrade/hedg `'HedgeTrade'` or `'hedg'`
* Hush/hush `'Hush'` or `'hush'`
* HyperSpace/xsc `'HyperSpace'` or `'xsc'`
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"Gnosis","gno",
"Golem","glm",
"Golem (GNT)","gnt",
"Groestlcoin", "grs",
"HedgeTrade","hedg",
"Hush","hush",
"HyperSpace","xsc",
Expand Down Expand Up @@ -152,6 +153,7 @@
"bundle": "^2.1.0",
"cbor-js": "^0.1.0",
"crc": "^3.8.0",
"groestl-hash-js": "1.0.0",
"js-sha512": "^0.8.0",
"jssha": "^2.4.2",
"lodash.isequal": "^4.5.0",
Expand Down
2 changes: 2 additions & 0 deletions src/bitcoin_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ function getChecksum(hashFunction, payload) {
return cryptoUtils.blake256Checksum(payload);
case 'keccak256':
return cryptoUtils.keccak256Checksum(payload);
case 'groestl512x2':
return cryptoUtils.groestl512x2(payload);
case 'sha256':
default:
return cryptoUtils.sha256Checksum(payload);
Expand Down
5 changes: 5 additions & 0 deletions src/crypto/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var Blake2B = require('./blake2b');
var base58 = require('./base58');
var base32 = require('./base32');
var BigNum = require('browserify-bignum');
var groestl = require('groestl-hash-js');

function numberToHex(number, length) {
var hex = number.toString(16);
Expand Down Expand Up @@ -122,6 +123,10 @@ module.exports = {
blake2b256: function (hexString) {
return new Blake2B(32).update(Buffer.from(hexString, 'hex'), 32).digest('hex');
},
groestl512x2: function (hexString) {
let result = groestl.groestl_2(Buffer.from(hexString, 'hex'), 1, 0).substr(0, 8);
return result;
},
base58: base58.decode,
byteArray2hexStr: byteArray2hexStr,
hexStr2byteArray: hexStr2byteArray,
Expand Down
8 changes: 7 additions & 1 deletion src/currencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ var CURRENCIES = [{
addressTypes: { prod: ['30', '05', '32'], testnet: ['6f', 'c4', '3a'] },
bech32Hrp: { prod: ['ltc'], testnet: ['tltc'] },
validator: BTCValidator
}, {
name: 'Groestlcoin',
symbol: 'grs',
addressTypes: { prod: ['24', '05'], testnet: ['6f', 'c4'] },
bech32Hrp: { prod: ['grs'], testnet: ['tgrs'] },
hashFunction: 'groestl512x2',
validator: BTCValidator
}, {
name: 'PeerCoin',
symbol: 'ppc',
Expand Down Expand Up @@ -619,4 +626,3 @@ var CURRENCIES = [{
// .sort((a, b) => a.name.toUpperCase() > b.name.toUpperCase() ? 1 : -1)
// .forEach(c => console.log(`"${c.name}","${c.symbol}",`));
//

41 changes: 39 additions & 2 deletions test/wallet_address_validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,37 @@ describe('WAValidator.validate()', function () {
valid('tltc1qu78xur5xnq6fjy83amy0qcjfau8m367defyhms', 'litecoin', { networkType: 'testnet' });
});

it('should return true for correct groestlcoin addresses', function () {
valid('Foa6yZoKq2r4t3tUFKFcfoXSQjSodZsGx1', 'groestlcoin');
valid('Fr2Z1bLzqRZByt2WeZwWnpCkA1eBYv83wZ', 'groestlcoin');
valid('Fr2Z1bLzqRZByt2WeZwWnpCkA1eBYv83wZ', 'GRS');
valid('Fr2Z1bLzqRZByt2WeZwWnpCkA1eBYv83wZ', 'Groestlcoin');
valid('Fr2Z1bLzqRZByt2WeZwWnpCkA1eBYv83wZ', 'grs');
valid('Fr2Z1bLzqRZByt2WeZwWnpCkA1eBYv83wZ', 'grs', 'prod');
valid('Fr2Z1bLzqRZByt2WeZwWnpCkA1eBYv83wZ', 'grs', 'both');
valid('FpM19fiGQNjNcaRjFaXVX6Nrewr4gnuuMZ', 'grs', 'prod');
valid('3FyVFsEyyBPzHjD3qUEgX7Jsn4tcJWiqeN', 'grs', 'prod');
valid('38mKdURe1zcQyrFqRLzR8PRao3iLFU5hwU', 'grs', 'prod');
valid('mptPo5AvLzJXi4T82vR6g82fT5uJ9cgfsV', 'grs', 'both');
valid('FdWcvgskHoXUTqeQRAiuGuh5KQ2EoXv5iM', 'groestlcoin');
valid('mzBc4XEFSdzCDcTxAgf6EZXgsZWq3SbMQT', 'groestlcoin', 'testnet');
valid('mzBc4XEFSdzCDcTxAgf6EZXgsZWq3SbMQT', 'groestlcoin', 'both');

// p2sh addresses
valid('3NJZLcZEEYBpxYEUGewU4knsQRn1T2Htk2', 'groestlcoin');
valid('2MxKEf2su6FGAUfCEAHreGFQvEYrfZDahUf', 'groestlcoin', 'testnet');

// segwit addresses
valid('GRS1Q49QLS5KKLRYT95G5XX4P6MSYCPGJP8RAMFC9JQ', 'groestlcoin');
valid('grs1qnxt8adg4qk3ljl0qhvp4m0nt56w6ma77vwr2jq', 'groestlcoin');

valid('tgrs1qw4z3xrtgx4f6w7akwpp2xa0gupmkv4yauemmm9', 'groestlcoin', 'testnet');
valid('tgrs1q7puer6g9ujzrgvc2eldczvd0yyz2v3j4t6m3ph', 'groestlcoin', 'testnet');

invalid("grs1q49qls5kklryt95g5xq4p6msycpgjp8ramfc9jq", 'groestlcoin'),
invalid("tgrs1qqjd3qhncsxdyh5gt7hz4k6zzvfguslwxwgv23j", 'groestlcoin')
});

it('should return true for correct peercoin addresses', function () {
valid('PHCEsP6od3WJ8K2WKWEDBYKhH95pc9kiZN', 'peercoin');
valid('PSbM1pGoE9dnAuVWvpQqTTYVpKZU41dNAz', 'peercoin');
Expand Down Expand Up @@ -858,6 +889,10 @@ describe('WAValidator.validate()', function () {
commonTests('litecoin');
});

it('should return false for incorrect groestlcoin addresses', function () {
commonTests('groestlcoin');
});

it('should return false for incorrect peercoin addresses', function () {
commonTests('peercoin');
});
Expand Down Expand Up @@ -1215,6 +1250,10 @@ describe('invalid results', function () {
commonTests('litecoin');
});

it('should return false for incorrect groestlcoin addresses', function () {
commonTests('groestlcoin');
});

it('should return false for incorrect peercoin addresses', function () {
commonTests('peercoin');
});
Expand Down Expand Up @@ -1527,5 +1566,3 @@ describe('invalid results', function () {


});