So far when I try to create a wallet with a recovery phrase that already exist the server returns 409 conflict and an error message saying: “This operation would yield a wallet with the following id: {id} However, I already know of a wallet with this id.”
So the question is: Is there another way rather than extracting the id from the response message? I mean hopefully there is a better way to get the wallet Id, from the recovery phrase maybe?
Are you using cardano-wallet for wallet creation? So you want the get the wallet id based on recovery phrase? I dont think that is possible… maybe delete all the wallets before you want to know the id of a wallet based on recovery phrase…
Why would you delete other wallets instead of the one in question for which it says wallet already exists (ID should be same for given recovery phrase and wallet type)?
PS: While you moved on to trying to derive ID yourself, I am still trying to understand the blocker based on description, as the first line of your issue does not seem to be a problem.
the problem is, I have the recovery phrase of a wallet but I cannot find a way to get the wallet Id (which will be use to refering the wallet on all the endpoint requests) rather than extract it from the error message saying the wallet already exist.
How can I get the wallet Id from the recovery phrase?
I feel there’s possibly some basic misunderstanding (either on my end understanding your requirement , or on your end). When you do a list against the wallet IDs, you get a list of what you’ve already restored on the wallet instance. cardano-wallet manages HD wallets which may hold multiple accounts/addresses. You would get the wallet ID from API upon restoring a wallet from seed (or as in your case, for already existing one - as part of error).
As mentioned earlier, you dont need to extract it from an error message, if you already had the wallet restored - you can access any/all wallets using list API. Note that this is a list if wallets restored on local instance.
If you hit POST /v2/wallets endpoint and the wallet already exist on the wallet “instance list” (is already loaded so to speak) it won’t return the wallet object BUT it’ll fail with an error message saying is already there, so if the list has more than one wallet how can I know which one is it?
I understand that from the point of view of interaction between users and the wallet server it’s ok this behavior since the user will hit the POST /v2/wallets endpoint and will end up with a list of wallets from where he’ll be able to recognize each wallet. But imagine that the interaction is between a program and the wallet server, the program won’t know which wallet is what and cannot pick accordingly (this could be the case of an exchange where the wallets are handle by the program and not through user interaction).
I think it’s kind of counter intuitive that the POST /v2/wallets endpoint doesn’t return the wallet if already exist.
When creating a wallet, you’d anyways NEED to do the error handling (for cases like invalid phrase, invalid password constraints, wallet already exists). It is exactly why you see the wallet ID in the message returned. Sure you can do a blake2b hashing but to my eyes it seems a bit of an overkill - given my last statement. When multiple wallets exist, and you’re restoring an existing one - you see the ID in response.
Giving back an existing object on create/restore for an instance already restored - without any errors - will be fundamentally wrong from programming/development point of view. As a developer, I would be much more interested in knowing that my call failed.
Lastly, note that this is not a component like cardano-rosetta or cardano-address where you derive keys and associate address to entities (for example, users for exchanges). They’re two different type of integrations with different focus. I am not aware of your use case, but based on your difficulty it does sound like you’d be much better be working with rosetta layer instead
What I mean is, after you get a wallet_already_exist error, you end up without knowing the reference to that specific wallet, you know is on the list but you don’t know which one, this isn’t useful if you are interacting with the API through a program, don’t you agree?
If for some reason you create a wallet and then you lost track of the wallet Id, you’ll be struggling to recover the wallet Id and effectively use it.
The API cover these scenarios:
Wallet on Server Instance List | Wallet on Blockchain | Action
no | no | Create
no | yes | Restore
yes | yes | Throw error wallet_already_exist