Yes, your approach makes sense. Here are a few steps you can follow to implement the API portion of your scenario:
Use the web3.eth.personal.sign method in your client-side JavaScript
code to sign the message containing the wallet ID and nonce. This
method is part of the Web3.js library, which you can use to interact
with the Ethereum blockchain from your client-side code.
When the user signs the message, the web3.eth.personal.sign method
will return the signed message as a hexadecimal string. You can then
send this signed message to your API using an HTTP request.
In your API, use the web3.eth.personal.ecRecover method to recover
the wallet address from the signed message. This method is part of
the Web3.js library and allows you to verify that the signed message
has not been tampered with and was indeed signed by the wallet
address that it claims to be from.
Once you have recovered the wallet address, you can extract the
nonce and wallet ID from the signed message and compare them to the
values you sent to the client-side code. If the nonce and wallet ID
match, you can consider the user to be authorized.
To implement your API, you can use any server-side language that is compatible with the Web3.js library. Some popular options include Node.js, Python, and Java. You can also use the Web3.NET library to interact with the Ethereum blockchain from a .NET application.