Skip to content

Instantly share code, notes, and snippets.

@Hribek25
Last active September 24, 2019 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hribek25/0264eed24a54a26047aefa3154813101 to your computer and use it in GitHub Desktop.
Save Hribek25/0264eed24a54a26047aefa3154813101 to your computer and use it in GitHub Desktop.
Validating IOTA address
// The snippet is a part of the IOTA Developer Essentials project. You can reach it at https://hribek25.github.io/IOTA101/
// Complete description and story behind the snippet is available at: https://hribek25.github.io/IOTA101/Allchapters_javascript.ipynb.html#C65223B0864A
// Requirement: A checksum module of IOTA Javascript Library (!npm install @iota/checksum)
// Requirement: A validators module of IOTA Javascript Library (!npm install @iota/validators)
var iotalib = require('@iota/checksum');
var iotaValidators = require('@iota/validators');
//address including checksum
var InputAddr = "CYJV9DRIE9NCQJYLOYOJOGKQGOOELTWXVWUYGQSWCNODHJAHACADUAAHQ9ODUICCESOIVZABA9LTMM9RWTHBIRSXTA";
if (!iotaValidators.isAddress(InputAddr) || InputAddr.length!=90) {
console.log("Not valid input address given.");
} else {
console.log("Input address incl checksum:");
console.log(InputAddr);
console.log("Is it valid addr based on checksum? %s", iotalib.isValidChecksum(InputAddr));
console.log("Input address excl checksum:");
console.log(iotalib.removeChecksum(InputAddr));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment