/* This file is part of ethereum.js. ethereum.js is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ethereum.js is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with ethereum.js. If not, see . */ /** * @file icap.js * @author Marek Kotewicz * @date 2015 */ var utils = require('../utils/utils'); /** * This prototype should be used to extract necessary information from iban address * * @param {String} iban */ var ICAP = function (iban) { this._iban = iban; }; /** * Should be called to check if icap is correct * * @method isValid * @returns {Boolean} true if it is, otherwise false */ ICAP.prototype.isValid = function () { return utils.isIBAN(this._iban); }; /** * Should be called to check if iban number is direct * * @method isDirect * @returns {Boolean} true if it is, otherwise false */ ICAP.prototype.isDirect = function () { return this._iban.length === 34; }; /** * Should be called to check if iban number if indirect * * @method isIndirect * @returns {Boolean} true if it is, otherwise false */ ICAP.prototype.isIndirect = function () { return this._iban.length === 20; }; /** * Should be called to get iban checksum * Uses the mod-97-10 checksumming protocol (ISO/IEC 7064:2003) * * @method checksum * @returns {String} checksum */ ICAP.prototype.checksum = function () { return this._iban.substr(2, 2); }; /** * Should be called to get institution identifier * eg. XREG * * @method institution * @returns {String} institution identifier */ ICAP.prototype.institution = function () { return this.isIndirect() ? this._iban.substr(7, 4) : ''; }; /** * Should be called to get client identifier within institution * eg. GAVOFYORK * * @method client * @returns {String} client identifier */ ICAP.prototype.client = function () { return this.isIndirect() ? this._iban.substr(11) : ''; }; /** * Should be called to get client direct address * * @method address * @returns {String} client direct address */ ICAP.prototype.address = function () { return this.isDirect() ? this._iban.substr(4) : ''; }; module.exports = ICAP;