CommRustModule bindings and rust client method implementation
Depends on D11084
Differential D11098
[native] add findUserIDForWalletAddress to CommRustModule varun on Feb 15 2024, 1:30 PM. Authored by Tags None Referenced Files
Details CommRustModule bindings and rust client method implementation Depends on D11084 called the JSI function from JS and successfully retrieved the user ID associated with a wallet address in my local DDB diff --git a/native/account/siwe-panel.react.js b/native/account/siwe-panel.react.js index 02dd3fbed..2b49412d4 100644 --- a/native/account/siwe-panel.react.js +++ b/native/account/siwe-panel.react.js @@ -28,6 +28,7 @@ import { UnknownErrorAlertDetails } from '../utils/alert-messages.js'; import Alert from '../utils/alert.js'; import { getContentSigningKey } from '../utils/crypto-utils.js'; import { defaultLandingURLPrefix } from '../utils/url-utils.js'; +import { commRustModule } from '../native-modules.js'; const commSIWE = `${defaultLandingURLPrefix}/siwe`; @@ -110,6 +111,12 @@ function SIWEPanel(props: Props): React.Node { ); } + const identityUserID = await commRustModule.findUserIDForWalletAddress( + '0xF8b57E5eD505bC6fAfFC765c1AC8569063664c28', + ); + console.log(identityUserID); + const parsedIdentityResponse = JSON.parse(identityUserID); + console.log(parsedIdentityResponse.userID); const ed25519 = await getContentSigningKey(); setPrimaryIdentityPublicKey(ed25519); })(); LOG {"userID":"C81FF954-6216-4489-B23C-0EA145EA2003","isReserved":false} LOG C81FF954-6216-4489-B23C-0EA145EA2003
Diff Detail
Event TimelineComment Actions
Comment Actions I just updated D11005 to use this, but the gist is, we need to check if a user already exists for a given wallet address so that we can decide whether to call identityWalletLogIn, identityWalletRegister, or onAccountDoesNotExist Initially I wanted to just try login and check for a "does not exist" error, but we remove the nonce from DDB on the login call (i think this is the right thing to do to prevent replay attacks), so the client would have to get a new nonce and sign a new message to subsequently register, which would be a bad user experience.
I initially tried making it more general but because the RPC expects an Identifier enum (with variants WalletAddress and Username), we'd need to pass an enum from C++ to rust, which seemed like more trouble than it was worth.
yes Comment Actions We also need findUserIDForWalletAddress to determine whether to navigate to ExistingEthereumAccount from ConnectEthereum Comment Actions Thanks for explaining!
I'm not so sure about the replay attack stuff. But looking at your code, it seems like FullscreenSIWEPanel is the only place that will need an extra round trip here, and that component should go away after we launch secondary device auth via primary device. We'll need this one long-term.
Comment Actions Makes sense to me. We can easily refactor this in the future when we find a better way of passing enums JS -> C++ -> Rust I think @varun just mentioned the same problem we have in the "restore" whitepaper protocol - we want to avoid running the SIWE login procedure twice and it's a bad UX |