Migrating from walletlib 1.x to 2.0
The Mobile Wallet Adapter 2.0 spec is published and the walletlib
Android SDK
has been upgraded to support MWA 2.0.
Wallets can update their application following this migration guide.
Summary of key changes
- Introduction of feature identifiers.
- Introduction of chain identifiers.
- API changes to the
authorize
RPC request specfication adding new parameters:- Sign In With Solana payload
- Chain and feature identifiers
authToken
andaddresses
- API changes to the
MobileWalletAdapterConfig
object returned bygetCapabilities
RPC request. - Mandatory support of the
signAndSendTransactions
RPC request.- Additional optional parameters added to
signAndSendTransactions
.
- Additional optional parameters added to
- Deprecation of
reauthorize
andsignTransactions
methods.
Migration guide
Update walletlib
To update to walletlib
2.0, simply add the latest dependency in your gradle file:
dependencies {
implementation 'com.solanamobile:mobile-wallet-adapter-walletlib:2.0.0-beta1'
}
There will be no breaking changes and the 2.0 implementation will be immediately backwards compatible with legacy clients.
Authorize (2.0 spec)
AuthorizeRequest
To conform to the updated authorize
RPC request specification, the AuthorizationRequest
object that is passed from walletlib
through the onAuthorizeReqest
callback now includes some new parameters:
- MWA 2.0
- Legacy
AuthorizeRequest {
@Nullable Uri identityUri;
@Nullable Uri iconUri;
@Nullable String identityName;
@Nullable String authToken; // New
@Nullable String chain; // New
@Nullable String[] features; // New
@Nullable String[] addresses; // New
@Nullable SignInWithSolana.Payload signInPayload // New
}
AuthorizeRequest {
@Nullable Uri identityUri;
@Nullable Uri iconUri;
@Nullable String identityName;
@NonNull String cluster // Deprecated. Replaced by `chain` parameter.
}
New parameters:
authToken
: An optionalauthToken
where if provided, the wallet should attempt to reauthorize the session with it.addresses
: An optional list of base64 encoded account addresses that the dapp wishes to be included in the authorization scope.signInPayload
: An object containing the payload portion of a Sign In With Solana message.chain
: A chain identifier to distinguish the requested blockchain network. Replaces the deprecatedcluster
parameter.- Supported Solana network chains:
solana:mainnet
,solana:testnet
, andsolana:devnet
.
- Supported Solana network chains:
features
: An array of feature identifiers, representing features requested by the client.
Parameter: authToken
An optional authToken
where if present, the wallet should attempt to reauthorize the session using it. The wallet implementation will likely be able to re-use their reauthorize
logic
to handle this case. This aims to replace the reauthorize
RPC request and reduce the confusion between authorize
/reauthorize
for dApps developers.
Parameter: Sign In With Solana
An optional object containing the payload portion of a Sign In With Solana message.
If present, the wallet should present the SIWS message to the user and, if approved, include a SignInResult
object in the AuthorizationResult
response to the dapp endpoint.
public class SignInResult {
@NonNull public final byte[] publicKey;
@NonNull public final byte[] signedMessage;
@NonNull public final byte[] signature;
@Nullable public final String signatureType;
}
AuthorizationResult
The AuthorizationResult
object that is returned to the dapp endpoint is now constructed by passing in an AuthorizedAccount
, rather than a public key and label.
Constructor for AuthorizationResult
:
- MWA 2.0
- Legacy
- AuthorizedAccount
public AuthorizationResult(@NonNull String authToken,
@NonNull AuthorizedAccount account,
@Nullable Uri walletUriBase,
@Nullable SignInResult signInResult);
@Deprecated
public AuthorizationResult(@NonNull String authToken,
@NonNull byte[] publicKey,
@Nullable String accountLabel,
@Nullable Uri walletUriBase);
AuthorizedAccount {
@NonNull byte[] publicKey
@Nullable String accountLabel
@Nullable String[] chains
@Nullable String[] features
}
In the near future, AuthorizationResult
will be updated again to support multiple accounts and store a list of AuthorizedAccount
objects.
Sign And Send Transactions (2.0 spec)
Suport for the sign_and_send_transactions
request has been made mandatory in the Mobile Wallet Adapter 2.0 specification. Wallets must now implement this method according to the spec.
The optional transaction parameters have also been expanded to allows dapps to further specify how transactions should be sent to the RPC by the wallet endpoint.
Additional optional parameters in SignAndSendTransactionRequest
:
- MWA 2.0
public class SignAndSendTransactionRequest
extends BaseVerifiableIdentityRequest<MobileWalletAdapterServer.SignAndSendTransactionsRequest> {
/* ... */
@Nullable
public Integer getMinContextSlot();
@Nullable
public String getCommitment(); // New
@Nullable
public Boolean getSkipPreflight(); // New
@Nullable
public Integer getMaxRetries(); // New
@Nullable
public Boolean getWaitForCommitmentToSendNextTransaction(); // New
/* ... */
}
For an explanation on each parameter, see the spec.
MobileWalletAdapterConfig
The configuration object that is used when setting up an MWA session has been updated. This object is returned to the dapp endpoint from a get_capabilities
RPC request.
The boolean feature flags supportsSignAndSendTransactions
and supportsCloneAuthorization
have been replaced with the supportedFeatures
array, using the new
feature extension and identifer API.
The wallet can flag these features by adding solana:signAndSendTransaction
and solana:cloneAuthorization
and exposed through the new feature extension API.
- MWA 2.0
- Legacy
MobileWalletAdapterConfig(
int maxTransactionsPerSigningRequest,
int maxMessagesPerSigningRequest,
Object[] supportedTransactionVersions,
long noConnectionWarningTimeoutMs,
String[] supportedFeatures // Supported feature identifiers go here
)
MobileWalletAdapterConfig(
boolean supportsSignAndSendTransactions, // Deprecated. Migrate to feature IDs
boolean supportsCloneAuthorization, // Deprecated. Migrate to feature IDs
int maxTransactionsPerSigningRequest,
int maxMessagesPerSigningRequest,
Object[] supportedTransactionVersions,
long noConnectionWarningTimeoutMs
)