mirror of
https://github.com/status-im/web3.js.git
synced 2025-02-24 03:58:13 +00:00
129 lines
3.0 KiB
JavaScript
129 lines
3.0 KiB
JavaScript
/*
|
|
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 <http://www.gnu.org/licenses/>.
|
|
*/
|
|
/**
|
|
* @file icap.js
|
|
* @author Marek Kotewicz <marek@ethdev.com>
|
|
* @date 2015
|
|
*/
|
|
|
|
/**
|
|
* 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 true;
|
|
};
|
|
|
|
/**
|
|
* 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 return iban country code
|
|
* For ethereum it should always XE
|
|
*
|
|
* @method countryCode
|
|
* @returns {String} countryCode
|
|
*/
|
|
ICAP.prototype.countryCode = function () {
|
|
return this._iban.substr(0, 2);
|
|
};
|
|
|
|
/**
|
|
* 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);
|
|
};
|
|
|
|
/**
|
|
* Asset identifier
|
|
* For ethereum based contracts ETH is the only valid identifier
|
|
*
|
|
* @method asset
|
|
* @returns {String} asset indetifier
|
|
*/
|
|
ICAP.prototype.asset = function () {
|
|
return this.isIndirect() ? this._iban.substr(4, 3) : '';
|
|
};
|
|
|
|
/**
|
|
* 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;
|
|
|