forked from ryanralph/altcoin-address
-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Developer
committed
Aug 1, 2019
1 parent
bcd0c8f
commit d350b0c
Showing
5 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
"validator", | ||
"vertcoin", | ||
"nano", | ||
"nimiq", | ||
"raiblocks", | ||
"javascript", | ||
"browser", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function ibanCheck(address) { | ||
const num = address.split('').map(function(c) { | ||
const code = c.toUpperCase().charCodeAt(0); | ||
return code >= 48 && code <= 57 ? c : (code - 55).toString(); | ||
}).join(''); | ||
let tmp = ''; | ||
|
||
for (let i = 0; i < Math.ceil(num.length / 6); i++) { | ||
tmp = (parseInt(tmp + num.substr(i * 6, 6)) % 97).toString(); | ||
} | ||
|
||
return parseInt(tmp); | ||
} | ||
|
||
module.exports = { | ||
isValidAddress: function (address, currency) { | ||
currency = currency || {}; | ||
address = address.replace(/ /g, ''); | ||
|
||
if (address.substr(0, 2).toUpperCase() !== currency.countryCode) { | ||
return false; | ||
} | ||
if (address.length !== currency.length) { | ||
return false; | ||
} | ||
if (ibanCheck(address.substr(4) + address.substr(0, 4)) !== 1) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters