Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finance.iban does not create valid iban #1832

Closed
7 of 10 tasks
napres1001 opened this issue Feb 13, 2023 · 5 comments · Fixed by #3175
Closed
7 of 10 tasks

finance.iban does not create valid iban #1832

napres1001 opened this issue Feb 13, 2023 · 5 comments · Fixed by #3175
Labels
c: bug Something isn't working m: finance Something is referring to the finance module p: 1-normal Nothing urgent s: awaiting more info Additional information are requested
Milestone

Comments

@napres1001
Copy link

Pre-Checks

Describe the bug

when using:
"finance.iban" the iban is always invalid.
In my case i used:
faker.finance.iban(false, 'DE')
and got for example:
DE88 1533 9441 3800 0600 27

but even the iban mentioned in the documentation are not valid:
https://fakerjs.dev/api/finance.html#iban

to check, if a iban is valid you can use:
https://www.ibancalculator.com/iban_validieren.html

Minimal reproduction code

https://stackblitz.com/edit/faker-js-demo-ngipzd?embed=1&file=index.html

Additional Context

No response

Environment Info

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-1245U
    Memory: 3.17 GB / 15.44 GB
  Binaries:
    Node: 18.10.0 - C:\Program Files\nodejs\node.EXE
    npm: 2.15.12 - ~\source\repos\wl-cypress-smoke-test\node_modules\.bin\npm.CMD
    npm version 9.4.2
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (109.0.1518.70)
    Internet Explorer: 11.0.19041.1566
    Google Chrome: 109.0.5414.120
    Mozialle Firefox: 109.0.1

faker 7.6.0
by npm install @faker-js/faker --save-dev

Which module system do you use?

  • CJS
  • ESM

Used Package Manager

npm

@napres1001 napres1001 added c: bug Something isn't working s: pending triage Pending Triage labels Feb 13, 2023
@ST-DDT
Copy link
Member

ST-DDT commented Feb 13, 2023

From the page you linked:

grafik

Do you have a list of allowed bank codes?

@ST-DDT ST-DDT added p: 1-normal Nothing urgent s: awaiting more info Additional information are requested m: finance Something is referring to the finance module and removed s: pending triage Pending Triage labels Feb 13, 2023
@ST-DDT ST-DDT moved this to Todo in Faker Roadmap Feb 13, 2023
@napres1001
Copy link
Author

i cant provide a full list of valid bank-codes. maybe there is some online source (API?) for it?
like:
https://www.iban.com/validation-api

@b-pagis
Copy link

b-pagis commented May 11, 2023

TL;DR;

This is a very hard task to accomplish and it would require constant maintenance to keep the correctness. IMHO, implementing country specific checks are, probably, not worth doing as it would only be required for very specific use cases.

Here is a longer explanation, why it is not worth doing

IBAN has generic format (I'll use the one from this issue):

  • DE - country code
  • 88 - checksum
  • 153394413800060027 - BBAN

Each BBAN has a format, which is different for each country. Here is a page that very well illustrates what format each country is using.

In this case BBAN is divided to following codes:

  • 15339441 - branch code (or bank code)
  • 3800060027 - account number

Taken from service description, it checks account checksum (explanation taken from service);

Methode 06, Konto 0335652860, BLZ 87096214, Prüfziffer 0 steht an Position 10, erwartete Prüfziffer: 0. Überblick über die Berechnung: Nimm die Ziffern auf den Positionen 1 bis 9 - hier: 033565286 -, multipliziere sie von rechts nach links mit den Gewichten 2,3,4,5,6,7,2,3,4, addiere die Produkte, bilde den Rest der Division durch 11, ziehe das Ergebnis von 11 ab, und das Ergebnis modulo 11 ist die erwartete Prüfziffer.

Which, translates to something like this (used google translation):

Method 06, account 0335652860, bank code 87096214, check digit 0 is in position 10, expected check digit: 0. Overview of the calculation: Take the digits in positions 1 to 9 - here: 033565286 -, multiply them from right to left by the weights 2,3,4,5,6,7,2,3,4, add the products, form the remainder of division by 11, subtract the result from 11, and the result modulo 11 is the expected check digit.

Some countries have their own specific additional validation logic to check if account is correct. Here is page form oracle docs explaining it.

Furthermore, to pass online service checks, it would require to use real life data, which is constantly changing. This is what ibancalculator service is doing. It actually checks if the sort code 15339441 (first 8 symbols of bban) exists in the National Competent Authorities in charge of banking lists. In this case it is bundesbank.de.

DE NCA allows to download the list of code - link to the page or search it via web interface.

My knowledge in this field is a little bit outdated, but couple years ago there were some NCAs that would only allowed to get the lists via web interface without the possibility to download them in any other format. Even heard some talks that people had to scrape some NCAs pages in order to get the list and keep it updated. Given the nature of NCAs (part of the government), I do not expect that changes are quickly applied in their systems. But, I could be wrong as there were few grand changes in EU banking sector that could have improved how the things works.

So, honestly, if you have a specific case, where you would need to check on real life data, it would probably make more sense to take the record from NCA list and construct the IBAN account around it, rather than implementing all this logic into the library. But again, this is only my opinion ;)

@Qaklaker
Copy link

Qaklaker commented Sep 4, 2024

There is a Website, which generates valid IBANs. Maybe you can work together with them to integrate that logic into Faker. That would be awesome

Mentioned Website is:
http://www.randomiban.com/?country=Italy

@matthewmayer
Copy link
Contributor

matthewmayer commented Sep 4, 2024

There is a Website, which generates valid IBANs. Maybe you can work together with them to integrate that logic into Faker. That would be awesome

Mentioned Website is: http://www.randomiban.com/?country=Italy

the source code is here http://www.randomiban.com/static/mapp4.js and is pretty messy

i tend to agree with @b-pagis that i think this is out of scope for Faker. I would instead consider updating the documentation to explain that the method creates plausible but potentially invalid IBANs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working m: finance Something is referring to the finance module p: 1-normal Nothing urgent s: awaiting more info Additional information are requested
Projects
No open projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

5 participants