Batched user operations for backend<>app interaction - #40
Merged
Merged
Conversation
The calls now come from src/logic/calls, so the backend can build the same batch the app sends.
The backend passes the result to the app, which signs it with deviceWallet.sendUserOperation.
The new device wallet no longer needs a separate operation for each step.
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.
What this does
Some SDK methods send several calls in one user operation, and they read chain state first to decide which calls to include. Until now only the mobile app could run that logic. This PR puts it in one shared place, so the backend can build the exact same calls and send them to the app to sign.
Why
The backend creates the calldata, the app signs it with its passkey, and the backend confirms the purchase from the contract event (via the Alchemy webhook). For batched methods, the backend would otherwise have to copy the SDK's logic and keep that copy in sync with the SDK.
What's new
For the backend (
kokio-sdk/admin)A new
admin.callssurface. Each method returns calls and never signs or sends anything.admin.calls.buyDataBundleWithTransfer(eSIMWallet, bundle, asset, maxAmountIn, paymentReference)Returns a token transfer for whatever the eSIM wallet is short of the price, followed by the purchase. If the eSIM wallet already holds enough, it returns only the purchase.
admin.calls.acceptAndBindESIMWallet(eSIMWallet, newDeviceWallet, { grantAccessToFunds })Returns the calls a new device signs to take over an eSIM wallet: accept the transfer, then bind it. Fund access is off unless
grantAccessToFunds: trueis passed.For the app (
kokio-sdk)kokio.eSIMWallet.acceptAndBindESIMWallet({ grantAccessToFunds })is new. Moving an eSIM to a new device now takes one passkey prompt instead of two or three.kokio.eSIMWallet.buyDataBundleWithTransferworks the same as before, and now uses the shared code.kokio.deviceWallet.sendUserOperation(calls).How it fits together
admin.calls.*and returns them from its endpoint.deviceWallet.sendUserOperation(calls).DataBundleBoughtWithTokenfor a purchase, or the device wallet changing for a transfer.Things to know
acceptAndBindESIMWalletonly works for the device wallet named in the transfer request. It reverts if the old device cancelled the transfer first.Tests
admin.callssurface.Docs
docs/admin/calls.mddocs/mobile/esim-wallet.mdcoversacceptAndBindESIMWalletand how to sign calls built by the backend.Version
3.1.0 to 3.2.0