web3ibn 4.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,361 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { toChecksumAddress, leftPad, hexToNumber } from 'web3-utils';
18
+ import { isAddress } from 'web3-validator';
19
+ import { InvalidAddressError } from 'web3-errors';
20
+ /**
21
+ * Converts Ethereum addresses to IBAN or BBAN addresses and vice versa.
22
+ */
23
+ export class Iban {
24
+ /**
25
+ * Construct a direct or indirect IBAN that has conversion methods and validity checks.
26
+ * If the provided string was not of either the length of a direct IBAN (34 or 35),
27
+ * nor the length of an indirect IBAN (20), an Error will be thrown ('Invalid IBAN was provided').
28
+ *
29
+ * @param iban - a Direct or an Indirect IBAN
30
+ * @returns - Iban instance
31
+ *
32
+ * @example
33
+ * ```ts
34
+ * const iban = new web3.eth.Iban("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
35
+ * > Iban { _iban: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS' }
36
+ * ```
37
+ */
38
+ constructor(iban) {
39
+ /**
40
+ * This method should be used to create the equivalent ethereum address for the early provided Direct IBAN address.
41
+ * If the provided string was not a direct IBAN (has the length of 34 or 35), an Error will be thrown:
42
+ * ('Iban is indirect and cannot be converted. Must be length of 34 or 35').
43
+ * Note: this is also available as a static method.
44
+ *
45
+ * @return the equivalent ethereum address
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * const iban = new web3.eth.Iban("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
50
+ * iban.toAddress();
51
+ * > "0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8"
52
+ * ```
53
+ */
54
+ this.toAddress = () => {
55
+ if (this.isDirect()) {
56
+ // check if Iban can be converted to an address
57
+ const base36 = this._iban.slice(4);
58
+ const parsedBigInt = Iban._parseInt(base36, 36); // convert the base36 string to a bigint
59
+ const paddedBigInt = leftPad(parsedBigInt, 40);
60
+ return toChecksumAddress(paddedBigInt);
61
+ }
62
+ throw new Error('Iban is indirect and cannot be converted. Must be length of 34 or 35');
63
+ };
64
+ if (Iban.isIndirect(iban) || Iban.isDirect(iban)) {
65
+ this._iban = iban;
66
+ }
67
+ else {
68
+ throw new Error('Invalid IBAN was provided');
69
+ }
70
+ }
71
+ /**
72
+ * A static method that checks if an IBAN is Direct.
73
+ * It actually check the length of the provided variable and, only if it is 34 or 35, it returns true.
74
+ * Note: this is also available as a method at an Iban instance.
75
+ * @param iban - an IBAN to be checked
76
+ * @returns - `true` if the provided `iban` is a Direct IBAN, and `false` otherwise.
77
+ *
78
+ * @example
79
+ * ```ts
80
+ * web3.eth.Iban.isDirect("XE81ETHXREGGAVOFYORK");
81
+ * > false
82
+ * ```
83
+ */
84
+ static isDirect(iban) {
85
+ return iban.length === 34 || iban.length === 35;
86
+ }
87
+ /**
88
+ * An instance method that checks if iban number is Direct.
89
+ * It actually check the length of the provided variable and, only if it is 34 or 35, it returns true.
90
+ * Note: this is also available as a static method.
91
+ * @param iban - an IBAN to be checked
92
+ * @returns - `true` if the provided `iban` is a Direct IBAN, and `false` otherwise.
93
+ *
94
+ * @example
95
+ * ```ts
96
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
97
+ * iban.isDirect();
98
+ * > false
99
+ * ```
100
+ */
101
+ isDirect() {
102
+ return Iban.isDirect(this._iban);
103
+ }
104
+ /**
105
+ * A static method that checks if an IBAN is Indirect.
106
+ * It actually check the length of the provided variable and, only if it is 20, it returns true.
107
+ * Note: this is also available as a method at an Iban instance.
108
+ * @param iban - an IBAN to be checked
109
+ * @returns - `true` if the provided `iban` is an Indirect IBAN, and `false` otherwise.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * web3.eth.Iban.isIndirect("XE81ETHXREGGAVOFYORK");
114
+ * > true
115
+ * ```
116
+ */
117
+ static isIndirect(iban) {
118
+ return iban.length === 20;
119
+ }
120
+ /**
121
+ * check if iban number if indirect
122
+ * It actually check the length of the provided variable and, only if it is 20, it returns true.
123
+ * Note: this is also available as a static method.
124
+ * @param iban - an IBAN to be checked
125
+ * @returns - `true` if the provided `iban` is an Indirect IBAN, and `false` otherwise.
126
+ *
127
+ * @example
128
+ * ```ts
129
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
130
+ * iban.isIndirect();
131
+ * > true
132
+ * ```
133
+ */
134
+ isIndirect() {
135
+ return Iban.isIndirect(this._iban);
136
+ }
137
+ /**
138
+ * This method could be used to check if a given string is valid IBAN object.
139
+ * Note: this is also available as a method at an Iban instance.
140
+ *
141
+ * @param iban - a string to be checked if it is in IBAN
142
+ * @returns - true if it is valid IBAN
143
+ *
144
+ * @example
145
+ * ```ts
146
+ * web3.eth.Iban.isValid("XE81ETHXREGGAVOFYORK");
147
+ * > true
148
+ *
149
+ * web3.eth.Iban.isValid("XE82ETHXREGGAVOFYORK");
150
+ * > false // because the checksum is incorrect
151
+ * ```
152
+ */
153
+ static isValid(iban) {
154
+ return (/^XE[0-9]{2}(ETH[0-9A-Z]{13}|[0-9A-Z]{30,31})$/.test(iban) &&
155
+ Iban._mod9710(Iban._iso13616Prepare(iban)) === 1);
156
+ }
157
+ /**
158
+ * Should be called to check if the early provided IBAN is correct.
159
+ * Note: this is also available as a static method.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
164
+ * iban.isValid();
165
+ * > true
166
+ *
167
+ * const iban = new web3.eth.Iban("XE82ETHXREGGAVOFYORK");
168
+ * iban.isValid();
169
+ * > false // because the checksum is incorrect
170
+ * ```
171
+ */
172
+ isValid() {
173
+ return Iban.isValid(this._iban);
174
+ }
175
+ /**
176
+ * Convert the passed BBAN to an IBAN for this country specification.
177
+ * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
178
+ * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
179
+ *
180
+ * @param bban - the BBAN to convert to IBAN
181
+ * @returns an Iban class instance that holds the equivalent IBAN
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * web3.eth.Iban.fromBban('ETHXREGGAVOFYORK');
186
+ * > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}
187
+ * ```
188
+ */
189
+ static fromBban(bban) {
190
+ const countryCode = 'XE';
191
+ const remainder = this._mod9710(this._iso13616Prepare(`${countryCode}00${bban}`));
192
+ const checkDigit = `0${(98 - remainder).toString()}`.slice(-2);
193
+ return new Iban(`${countryCode}${checkDigit}${bban}`);
194
+ }
195
+ /**
196
+ * Should be used to create IBAN object for given institution and identifier
197
+ *
198
+ * @param options - an object holds the `institution` and the `identifier` which will be composed to create an `Iban` object from.
199
+ * @returns an Iban class instance that holds the equivalent IBAN
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * web3.eth.Iban.createIndirect({
204
+ * institution: "XREG",
205
+ * identifier: "GAVOFYORK"
206
+ * });
207
+ * > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}
208
+ * ```
209
+ */
210
+ static createIndirect(options) {
211
+ return Iban.fromBban(`ETH${options.institution}${options.identifier}`);
212
+ }
213
+ /**
214
+ * This method should be used to create iban object from an Ethereum address.
215
+ *
216
+ * @param address - an Ethereum address
217
+ * @returns an Iban class instance that holds the equivalent IBAN
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * web3.eth.Iban.fromAddress("0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8");
222
+ * > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}
223
+ * ```
224
+ */
225
+ static fromAddress(address) {
226
+ if (!isAddress(address)) {
227
+ throw new InvalidAddressError(address);
228
+ }
229
+ const num = BigInt(hexToNumber(address));
230
+ const base36 = num.toString(36);
231
+ const padded = leftPad(base36, 15);
232
+ return Iban.fromBban(padded.toUpperCase());
233
+ }
234
+ /**
235
+ * This method should be used to create IBAN address from an Ethereum address
236
+ *
237
+ * @param address - an Ethereum address
238
+ * @return the equivalent IBAN address
239
+ *
240
+ * @example
241
+ * ```ts
242
+ * web3.eth.Iban.toIban("0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8");
243
+ * > "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"
244
+ * ```
245
+ */
246
+ static toIban(address) {
247
+ return Iban.fromAddress(address).toString();
248
+ }
249
+ /**
250
+ * Should be called to get client identifier within institution
251
+ *
252
+ * @return the client of the IBAN instance.
253
+ *
254
+ * @example
255
+ * ```ts
256
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
257
+ * iban.client();
258
+ * > 'GAVOFYORK'
259
+ * ```
260
+ */
261
+ client() {
262
+ return this.isIndirect() ? this._iban.slice(11) : '';
263
+ }
264
+ /**
265
+ * Returns the IBAN checksum of the early provided IBAN
266
+ *
267
+ * @example
268
+ * ```ts
269
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
270
+ * iban.checksum();
271
+ * > "81"
272
+ * ```
273
+ *
274
+ */
275
+ checksum() {
276
+ return this._iban.slice(2, 4);
277
+ }
278
+ /**
279
+ * Returns institution identifier from the early provided IBAN
280
+ *
281
+ * @example
282
+ * ```ts
283
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
284
+ * iban.institution();
285
+ * > 'XREG'
286
+ * ```
287
+ */
288
+ institution() {
289
+ return this.isIndirect() ? this._iban.slice(7, 11) : '';
290
+ }
291
+ /**
292
+ * Simply returns the early provided IBAN
293
+ *
294
+ * @example
295
+ * ```ts
296
+ * const iban = new web3.eth.Iban('XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS');
297
+ * iban.toString();
298
+ * > 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'
299
+ * ```
300
+ */
301
+ toString() {
302
+ return this._iban;
303
+ }
304
+ }
305
+ /**
306
+ * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
307
+ * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
308
+ */
309
+ Iban._iso13616Prepare = (iban) => {
310
+ const A = 'A'.charCodeAt(0);
311
+ const Z = 'Z'.charCodeAt(0);
312
+ const upperIban = iban.toUpperCase();
313
+ const modifiedIban = `${upperIban.slice(4)}${upperIban.slice(0, 4)}`;
314
+ return modifiedIban
315
+ .split('')
316
+ .map(n => {
317
+ const code = n.charCodeAt(0);
318
+ if (code >= A && code <= Z) {
319
+ // A = 10, B = 11, ... Z = 35
320
+ return code - A + 10;
321
+ }
322
+ return n;
323
+ })
324
+ .join('');
325
+ };
326
+ /**
327
+ * return the bigint of the given string with the specified base
328
+ */
329
+ Iban._parseInt = (str, base) => [...str].reduce((acc, curr) => BigInt(parseInt(curr, base)) + BigInt(base) * acc, BigInt(0));
330
+ /**
331
+ * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
332
+ */
333
+ Iban._mod9710 = (iban) => {
334
+ let remainder = iban;
335
+ let block;
336
+ while (remainder.length > 2) {
337
+ block = remainder.slice(0, 9);
338
+ remainder = `${(parseInt(block, 10) % 97).toString()}${remainder.slice(block.length)}`;
339
+ }
340
+ return parseInt(remainder, 10) % 97;
341
+ };
342
+ /**
343
+ * This method should be used to create an ethereum address from a Direct IBAN address.
344
+ * If the provided string was not a direct IBAN (has the length of 34 or 35), an Error will be thrown:
345
+ * ('Iban is indirect and cannot be converted. Must be length of 34 or 35').
346
+ * Note: this is also available as a method at an Iban instance.
347
+ *
348
+ * @param iban - a Direct IBAN address
349
+ * @return the equivalent ethereum address
350
+ *
351
+ * @example
352
+ * ```ts
353
+ * web3.eth.Iban.toAddress("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
354
+ * > "0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8"
355
+ * ```
356
+ */
357
+ Iban.toAddress = (iban) => {
358
+ const ibanObject = new Iban(iban);
359
+ return ibanObject.toAddress();
360
+ };
361
+ //# sourceMappingURL=iban.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iban.js","sourceRoot":"","sources":["../../src/iban.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAGF,OAAO,EAAE,iBAAiB,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD;;GAEG;AACH,MAAM,OAAO,IAAI;IAmKhB;;;;;;;;;;;;;OAaG;IACH,YAAmB,IAAY;QA6F/B;;;;;;;;;;;;;;WAcG;QACI,cAAS,GAAG,GAAc,EAAE;YAClC,IAAI,IAAI,CAAC,QAAQ,EAAE,EAAE;gBACpB,+CAA+C;gBAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBACnC,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,wCAAwC;gBACzF,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;gBAC/C,OAAO,iBAAiB,CAAC,YAAY,CAAC,CAAC;aACvC;YACD,MAAM,IAAI,KAAK,CAAC,sEAAsE,CAAC,CAAC;QACzF,CAAC,CAAC;QApHD,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,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EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,GAAG,GAAG,EAChE,MAAM,CAAC,CAAC,CAAC,CACT,CAAC;AAEH;;GAEG;AACqB,aAAQ,GAAG,CAAC,IAAY,EAAU,EAAE;IAC3D,IAAI,SAAS,GAAG,IAAI,CAAC;IACrB,IAAI,KAAK,CAAC;IAEV,OAAO,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE;QAC5B,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC9B,SAAS,GAAG,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,EAAE,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;KACvF;IAED,OAAO,QAAQ,CAAC,SAAS,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC;AACrC,CAAC,CAAC;AAyMF;;;;;;;;;;;;;;GAcG;AACW,cAAS,GAAG,CAAC,IAAY,EAAa,EAAE;IACrD,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,OAAO,UAAU,CAAC,SAAS,EAAE,CAAC;AAC/B,CAAC,CAAC"}
@@ -0,0 +1,21 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ import { Iban } from './iban.js';
18
+ export * from './iban.js';
19
+ export * from './types.js';
20
+ export default Iban;
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE;AAEF,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,cAAc,WAAW,CAAC;AAC1B,cAAc,YAAY,CAAC;AAE3B,eAAe,IAAI,CAAC"}
@@ -0,0 +1 @@
1
+ {"type": "module"}
@@ -0,0 +1,18 @@
1
+ /*
2
+ This file is part of web3.js.
3
+
4
+ web3.js is free software: you can redistribute it and/or modify
5
+ it under the terms of the GNU Lesser General Public License as published by
6
+ the Free Software Foundation, either version 3 of the License, or
7
+ (at your option) any later version.
8
+
9
+ web3.js is distributed in the hope that it will be useful,
10
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ GNU Lesser General Public License for more details.
13
+
14
+ You should have received a copy of the GNU Lesser General Public License
15
+ along with web3.js. If not, see <http://www.gnu.org/licenses/>.
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;EAeE"}
@@ -0,0 +1,264 @@
1
+ import { HexString } from 'web3-types';
2
+ import { IbanOptions } from './types.js';
3
+ /**
4
+ * Converts Ethereum addresses to IBAN or BBAN addresses and vice versa.
5
+ */
6
+ export declare class Iban {
7
+ private readonly _iban;
8
+ /**
9
+ * Prepare an IBAN for mod 97 computation by moving the first 4 chars to the end and transforming the letters to
10
+ * numbers (A = 10, B = 11, ..., Z = 35), as specified in ISO13616.
11
+ */
12
+ private static readonly _iso13616Prepare;
13
+ /**
14
+ * return the bigint of the given string with the specified base
15
+ */
16
+ private static readonly _parseInt;
17
+ /**
18
+ * Calculates the MOD 97 10 of the passed IBAN as specified in ISO7064.
19
+ */
20
+ private static readonly _mod9710;
21
+ /**
22
+ * A static method that checks if an IBAN is Direct.
23
+ * It actually check the length of the provided variable and, only if it is 34 or 35, it returns true.
24
+ * Note: this is also available as a method at an Iban instance.
25
+ * @param iban - an IBAN to be checked
26
+ * @returns - `true` if the provided `iban` is a Direct IBAN, and `false` otherwise.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * web3.eth.Iban.isDirect("XE81ETHXREGGAVOFYORK");
31
+ * > false
32
+ * ```
33
+ */
34
+ static isDirect(iban: string): boolean;
35
+ /**
36
+ * An instance method that checks if iban number is Direct.
37
+ * It actually check the length of the provided variable and, only if it is 34 or 35, it returns true.
38
+ * Note: this is also available as a static method.
39
+ * @param iban - an IBAN to be checked
40
+ * @returns - `true` if the provided `iban` is a Direct IBAN, and `false` otherwise.
41
+ *
42
+ * @example
43
+ * ```ts
44
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
45
+ * iban.isDirect();
46
+ * > false
47
+ * ```
48
+ */
49
+ isDirect(): boolean;
50
+ /**
51
+ * A static method that checks if an IBAN is Indirect.
52
+ * It actually check the length of the provided variable and, only if it is 20, it returns true.
53
+ * Note: this is also available as a method at an Iban instance.
54
+ * @param iban - an IBAN to be checked
55
+ * @returns - `true` if the provided `iban` is an Indirect IBAN, and `false` otherwise.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * web3.eth.Iban.isIndirect("XE81ETHXREGGAVOFYORK");
60
+ * > true
61
+ * ```
62
+ */
63
+ static isIndirect(iban: string): boolean;
64
+ /**
65
+ * check if iban number if indirect
66
+ * It actually check the length of the provided variable and, only if it is 20, it returns true.
67
+ * Note: this is also available as a static method.
68
+ * @param iban - an IBAN to be checked
69
+ * @returns - `true` if the provided `iban` is an Indirect IBAN, and `false` otherwise.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
74
+ * iban.isIndirect();
75
+ * > true
76
+ * ```
77
+ */
78
+ isIndirect(): boolean;
79
+ /**
80
+ * This method could be used to check if a given string is valid IBAN object.
81
+ * Note: this is also available as a method at an Iban instance.
82
+ *
83
+ * @param iban - a string to be checked if it is in IBAN
84
+ * @returns - true if it is valid IBAN
85
+ *
86
+ * @example
87
+ * ```ts
88
+ * web3.eth.Iban.isValid("XE81ETHXREGGAVOFYORK");
89
+ * > true
90
+ *
91
+ * web3.eth.Iban.isValid("XE82ETHXREGGAVOFYORK");
92
+ * > false // because the checksum is incorrect
93
+ * ```
94
+ */
95
+ static isValid(iban: string): boolean;
96
+ /**
97
+ * Should be called to check if the early provided IBAN is correct.
98
+ * Note: this is also available as a static method.
99
+ *
100
+ * @example
101
+ * ```ts
102
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
103
+ * iban.isValid();
104
+ * > true
105
+ *
106
+ * const iban = new web3.eth.Iban("XE82ETHXREGGAVOFYORK");
107
+ * iban.isValid();
108
+ * > false // because the checksum is incorrect
109
+ * ```
110
+ */
111
+ isValid(): boolean;
112
+ /**
113
+ * Construct a direct or indirect IBAN that has conversion methods and validity checks.
114
+ * If the provided string was not of either the length of a direct IBAN (34 or 35),
115
+ * nor the length of an indirect IBAN (20), an Error will be thrown ('Invalid IBAN was provided').
116
+ *
117
+ * @param iban - a Direct or an Indirect IBAN
118
+ * @returns - Iban instance
119
+ *
120
+ * @example
121
+ * ```ts
122
+ * const iban = new web3.eth.Iban("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
123
+ * > Iban { _iban: 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS' }
124
+ * ```
125
+ */
126
+ constructor(iban: string);
127
+ /**
128
+ * Convert the passed BBAN to an IBAN for this country specification.
129
+ * Please note that <i>"generation of the IBAN shall be the exclusive responsibility of the bank/branch servicing the account"</i>.
130
+ * This method implements the preferred algorithm described in http://en.wikipedia.org/wiki/International_Bank_Account_Number#Generating_IBAN_check_digits
131
+ *
132
+ * @param bban - the BBAN to convert to IBAN
133
+ * @returns an Iban class instance that holds the equivalent IBAN
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * web3.eth.Iban.fromBban('ETHXREGGAVOFYORK');
138
+ * > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}
139
+ * ```
140
+ */
141
+ static fromBban(bban: string): Iban;
142
+ /**
143
+ * Should be used to create IBAN object for given institution and identifier
144
+ *
145
+ * @param options - an object holds the `institution` and the `identifier` which will be composed to create an `Iban` object from.
146
+ * @returns an Iban class instance that holds the equivalent IBAN
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * web3.eth.Iban.createIndirect({
151
+ * institution: "XREG",
152
+ * identifier: "GAVOFYORK"
153
+ * });
154
+ * > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}
155
+ * ```
156
+ */
157
+ static createIndirect(options: IbanOptions): Iban;
158
+ /**
159
+ * This method should be used to create iban object from an Ethereum address.
160
+ *
161
+ * @param address - an Ethereum address
162
+ * @returns an Iban class instance that holds the equivalent IBAN
163
+ *
164
+ * @example
165
+ * ```ts
166
+ * web3.eth.Iban.fromAddress("0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8");
167
+ * > Iban {_iban: "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"}
168
+ * ```
169
+ */
170
+ static fromAddress(address: HexString): Iban;
171
+ /**
172
+ * This method should be used to create an ethereum address from a Direct IBAN address.
173
+ * If the provided string was not a direct IBAN (has the length of 34 or 35), an Error will be thrown:
174
+ * ('Iban is indirect and cannot be converted. Must be length of 34 or 35').
175
+ * Note: this is also available as a method at an Iban instance.
176
+ *
177
+ * @param iban - a Direct IBAN address
178
+ * @return the equivalent ethereum address
179
+ *
180
+ * @example
181
+ * ```ts
182
+ * web3.eth.Iban.toAddress("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
183
+ * > "0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8"
184
+ * ```
185
+ */
186
+ static toAddress: (iban: string) => HexString;
187
+ /**
188
+ * This method should be used to create the equivalent ethereum address for the early provided Direct IBAN address.
189
+ * If the provided string was not a direct IBAN (has the length of 34 or 35), an Error will be thrown:
190
+ * ('Iban is indirect and cannot be converted. Must be length of 34 or 35').
191
+ * Note: this is also available as a static method.
192
+ *
193
+ * @return the equivalent ethereum address
194
+ *
195
+ * @example
196
+ * ```ts
197
+ * const iban = new web3.eth.Iban("XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS");
198
+ * iban.toAddress();
199
+ * > "0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8"
200
+ * ```
201
+ */
202
+ toAddress: () => HexString;
203
+ /**
204
+ * This method should be used to create IBAN address from an Ethereum address
205
+ *
206
+ * @param address - an Ethereum address
207
+ * @return the equivalent IBAN address
208
+ *
209
+ * @example
210
+ * ```ts
211
+ * web3.eth.Iban.toIban("0x00c5496aEe77C1bA1f0854206A26DdA82a81D6D8");
212
+ * > "XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS"
213
+ * ```
214
+ */
215
+ static toIban(address: HexString): string;
216
+ /**
217
+ * Should be called to get client identifier within institution
218
+ *
219
+ * @return the client of the IBAN instance.
220
+ *
221
+ * @example
222
+ * ```ts
223
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
224
+ * iban.client();
225
+ * > 'GAVOFYORK'
226
+ * ```
227
+ */
228
+ client(): string;
229
+ /**
230
+ * Returns the IBAN checksum of the early provided IBAN
231
+ *
232
+ * @example
233
+ * ```ts
234
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
235
+ * iban.checksum();
236
+ * > "81"
237
+ * ```
238
+ *
239
+ */
240
+ checksum(): string;
241
+ /**
242
+ * Returns institution identifier from the early provided IBAN
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * const iban = new web3.eth.Iban("XE81ETHXREGGAVOFYORK");
247
+ * iban.institution();
248
+ * > 'XREG'
249
+ * ```
250
+ */
251
+ institution(): string;
252
+ /**
253
+ * Simply returns the early provided IBAN
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * const iban = new web3.eth.Iban('XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS');
258
+ * iban.toString();
259
+ * > 'XE7338O073KYGTWWZN0F2WZ0R8PX5ZPPZS'
260
+ * ```
261
+ */
262
+ toString(): string;
263
+ }
264
+ //# sourceMappingURL=iban.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iban.d.ts","sourceRoot":"","sources":["../../src/iban.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAIvC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC;;GAEG;AACH,qBAAa,IAAI;IAChB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAE/B;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAkBtC;IAEF;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAI9B;IAEH;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAU9B;IAEF;;;;;;;;;;;;OAYG;WACW,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI7C;;;;;;;;;;;;;OAaG;IACI,QAAQ,IAAI,OAAO;IAI1B;;;;;;;;;;;;OAYG;WACW,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI/C;;;;;;;;;;;;;OAaG;IACI,UAAU,IAAI,OAAO;IAI5B;;;;;;;;;;;;;;;OAeG;WACW,OAAO,CAAC,IAAI,EAAE,MAAM;IAOlC;;;;;;;;;;;;;;OAcG;IACI,OAAO,IAAI,OAAO;IAIzB;;;;;;;;;;;;;OAaG;gBACgB,IAAI,EAAE,MAAM;IAQ/B;;;;;;;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