Repository navigation
Support isolated SequenceLogin instances for dual sessions - #351
Open
tolgahan-arikan wants to merge 5 commits into
Open
tolgahan-arikan wants to merge 5 commits into
tolgahan-arikan wants to merge 5 commits into
Conversation
Adds SequenceLogin.CreateIsolatedInstance(namespace) so a second wallet session (e.g. an existing email account) can be authenticated while the default instance keeps the current guest session. - Isolated instances store their session under a namespaced secure storage key, raise per-instance OnSessionWalletCreated / OnSessionRecoveryFailed instead of the static SequenceWallet events, skip auto-federation and do not write the last-login PlayerPrefs. - PromoteToDefaultSession(wallet) moves the session to the default key, clears federation mode and raises SequenceWallet.OnWalletCreated so EmbeddedWalletAdapter / SessionManager switch to it. - ClearStoredSession() removes an instance's stored session. - SequenceWallet keeps its own session key and owning login; on account federation it persists its own key instead of the singleton's current session key. - Default GetInstance() behaviour is unchanged. Adds a batchmode verification harness (Assets/Editor/DualSessionVerification) that runs the guest + second-account flow across separate editor processes.
Deploying sequence-unity with
|
| Latest commit: |
0eb4301
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://ea231f73.sequence-unity.pages.dev |
| Branch Preview URL: | https://feature-dual-session-support.sequence-unity.pages.dev |
With an isolated SequenceLogin alongside the default one there are two OpenIdAuthenticators, and sign-in callbacks reached the wrong one: - iOS: IosBrowser was a process-wide singleton bound to the most recently created authenticator, so a sign-in started on the default instance was delivered to the isolated one and failed with "State token mismatch". - Android/macOS/WebGL: every instance receives Application.deepLinkActivated; the instance that did not start the sign-in raised OnLoginFailed. - Windows: the IPC listener only runs on the first authenticator, so links for the isolated instance were handed to the default one. Authenticators now register the state token they issue. A link carrying another authenticator's state is ignored; single-receiver callbacks (Windows IPC, iOS authentication session) go through OpenIdAuthenticator.RouteDeepLink to the issuer. IosBrowser is per authenticator, with the native callback going to the browser that started the session. Links whose state nobody issued fail as before.
DualSessionDeviceTest: guest on the default SequenceLogin, existing account (Google or email) on an isolated instance, transfer, sign-out, promotion, with session restore on every launch. Shows both instances, the adapter wallet, both stored keys and every login failure from either instance. BuildDualSessionDeviceTest.Android builds it as an APK (run in a project copy: it writes keys into the config and switches to debug signing).
taylanpince
approved these changes
Nov 6, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds opt-in support for holding a second embedded-wallet session alongside the default one, so an existing account can be authenticated while the current guest wallet stays usable (TapNation guest-reward merge).
Related: 0xsequence/issue-tracker#7344, 0xsequence/issue-tracker#7348
Changes
SequenceLogin.CreateIsolatedInstance(string storageNamespace, ...): non-singleton instance.{company}-{product}-{namespace}-SessionWallet.OnSessionWalletCreated/OnSessionRecoveryFailed; does not raise the staticSequenceWallet.OnWalletCreated/OnFailedToRecoverSession, soEmbeddedWalletAdapterandSessionManagerstay on the default session.WaaSLoginMethod/LoginEmailPlayerPrefs.PromoteToDefaultSession(SequenceWallet): writes the session to the default key, clears the namespaced key, clears federation mode on the default instance, raisesSequenceWallet.OnWalletCreated. Closing the previous (guest) session stays with the caller, after transfers confirm.ClearStoredSession(): removes an instance's stored session.TryToRestoreSessionAsynclistens to the per-instance events (default instance still raises the static ones).SequenceWalletkeeps its session key and owning login. On account federation it persists its own key under its owner's namespace; previously it stored the singleton's current session key, which is wrong once two sessions exist.OpenIdAuthenticator,IosBrowser). Before, with two instances:IosBrowserwas a singleton bound to the last created authenticator; a sign-in started on the default instance was delivered to the isolated one and failed with "State token mismatch".Application.deepLinkActivated; the one that did not start the sign-in raisedOnLoginFailed.OpenIdAuthenticator.RouteDeepLink(public). Links with a state nobody issued fail as before.GetInstance()behaviour unchanged.Assets/Editor/DualSessionVerification(batchmode harness),Assets/DualSessionDeviceTest(device test app + APK build), 3 tests added toDeepLinkHandlerTests.Verification
Batchmode harness
Assets/Editor/DualSessionVerification(Unity 2022.3.62f2, dev WaaS, each phase a separate editor process; not NUnit becauseStoreSessionKey()disables storage during test runs):setup13/13,restart8/8,final2/2: guest on default + guest on isolated instance, backend sessions, storage keys, adapter/event isolation, transfer from guest, restore after restart, guest sign-out isolation, promotion, restore of promoted account.email-create2/2,email-merge15/15: guest live, existing email account authenticated on isolated instance, wrong OTP rejected without side effects, auth returns the existing wallet, transfer guest → existing wallet, guest closed, promotion, adapter switched.social-routing9/9 (0 network sign-ins; link delivered through Unity'sApplication.InvokeDeepLinkActivatedand throughRouteDeepLink): before the routing fix 3 checks fail (spuriousOnLoginFailedon the default instance, single-receiver link not reaching the isolated instance).IosBrowser/ASWebAuthenticationSession, local page redirecting to the callback scheme): before the fix, a sign-in started on the default instance reached the isolated one ("State token mismatch"); after, each sign-in reaches its starter, no failures on the other instance.Assets/DualSessionDeviceTest: guest on default, existing email account on isolated instance returned the existing wallet, adapter stayed on guest, separate stored keys, 0-value tx guest → email wallet, both sessions restored after force-stop, guest sign-out, promotion (default key holds email wallet, isolated key cleared), promoted account restored after force-stop, sign-out.DeepLinkHandlerTests,SequenceLoginTests,WaaSWalletUnitTests,InitiateEmailSignInUnitTests,WaaSToWalletAdapterUnitTests,IntentSenderTests,JwtHelperTests): all 70 existing tests have the same per-test result as before the change (22 pass; failures are environment/config). 3 newDeepLinkHandlerTestsfor two authenticators pass.TestStateTokenMismatchnow uses a fresh state: the fixed"123456"it used is issued by another test's authenticator.Not covered
AccountAlreadyLinkedpath (federating an email that already has a wallet into the guest) and the new-user federation path were not re-run; the default instance's federation code is unchanged.Integration notes (TapNation, 0xsequence/issue-tracker#7344)
Flow: try federating the email into the guest; on conflict, authenticate the existing account on
SequenceLogin.CreateIsolatedInstance("user"), transfer from the guest to the wallet that authentication returned,guest.DropThisSession(), thenPromoteToDefaultSession(user).AccountAlreadyLinked(7001) throughSequenceWallet.OnAccountFederationFailedas a string. The code is bound to the guest's session (email;sessionIDverifier), so the isolated instance needs a new code. Every returning player gets two codes if federation is always tried first. Using the email→wallet table only to choose the path (not to authorize the destination) limits two codes to missing or stale table entries. Removing it entirely needs a backend change.DropThisSession(): check the result isSuccessfulTransactionReturnand itsreceipt.status(SendTransactionwaits for the receipt by default).ClearStoredSession()on the isolated instance. An isolated session that restores at startup means a migration was interrupted: re-read guest balances and send only what remains.OnSessionWalletCreated/OnSessionRecoveryFailed; the adapter and staticSequenceWalletevents follow the default session until promotion.HttpClientwere renamed/moved in 5.x.Version Increment
Please ensure you have incremented the package version in the package.json as necessary.
Docs Checklist
Please ensure you have addressed documentation updates if needed as part of this PR: