This is a package that provides React Native bridge for the native mobile-wallet-adapter-walletlib
library and it is designed for Wallet apps built in React Native. It provides an API to implement the wallet endpoint of the mobile wallet adapter protocol.
Deep dive and read the full Mobile Wallet Adapter protocol specification.
This package is still in alpha and is not production ready. However, the API is stable and will not change drastically, so you can begin integration with your wallet.
Use this API to start a session and start handling requests:
import {
MobileWalletAdapterConfig,
MWARequest,
MWASessionEvent,
useMobileWalletAdapterSession,
} from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
const config: MobileWalletAdapterConfig = useMemo(() => {
return {
supportsSignAndSendTransactions: true,
maxTransactionsPerSigningRequest: 10,
maxMessagesPerSigningRequest: 10,
supportedTransactionVersions: [0, 'legacy'],
noConnectionWarningTimeoutMs: 3000,
};
}, []);
// MWA Session Handlers
const handleRequest = useCallback((request: MWARequest) => {
/* ... */
}, []);
const handleSessionEvent = useCallback((sessionEvent: MWASessionEvent) => {
/* ... */
}, []);
// Connect to the calling dApp and begin handling dApp requests
useMobileWalletAdapterSession(
'Example Wallet Label',
config,
handleRequest,
handleSessionEvent,
);
A MWARequest
is handled by calling resolve(request, response)
and each request have their appropriate response types.
An example of handling an AuthorizationRequest
:
import {
AuthorizeDappResponse
} from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
const response = {
publicKey: Keypair.generate().publicKey.toBytes(),
label: 'Wallet Label',
} as AuthorizeDappResponse;
resolve(authorizationRequest, response)
There are a a selection of "fail" responses that you can return to the dApp. These are for cases where the user declines, or an error occurs during signing, etc.
import {
UserDeclinedResponse
} from '@solana-mobile/mobile-wallet-adapter-protocol-walletlib';
const response = {
failReason: MWARequestFailReason.UserDeclined,
} as UserDeclinedResponse;
// Tells the dApp user has declined the authorization request
resolve(authorizationRequest, response)
Each MWA Request is defined in resolve.ts
.
Each come with their own properties and completion response structures.
If you want to understand the dApp perspective and how a dApp would send these requests, see MWA API Documentation for dAppstypescript/mobile-wallet-adapter.
This is the base interface that all MWARequsts inherit from. The fields defined here are used in the package's internal implementation and the package consumer will generally not use them.
Fields:
-
__type
: An enum defining the type of MWA Request it is. -
requestId
: A unique identifier of this specific MWA Request -
sessionId
: A unique identifier of the MWA Session this request belongs to.
This an interface that describes MWA Requests that come with a verifiable identity and the following 3 fields.
Fields:
-
authorizationScope
: A byte representation of the authorization token granted to the dApp. -
cluster
: The Solana RPC cluster that the dApp intends to use. -
appIdentity
: An object containing 3 optional identity fields about the dApp:- Note: The
iconRelativeUri
is a relative path, relative toidentityUri
.
- Note: The
{
identityName: 'dApp Name',
identityUri: 'https://yourdapp.com'
iconRelativeUri: "favicon.ico", // Full path resolves to https://yourdapp.com/favicon.ico
}
-
AuthorizeDappRequest
- Spec
- Interfaces:
IMWARequest
-
ReauthorizeDappRequest
- Spec
- Interfaces:
IMWARequest
,IVerifiableIdentityRequest
-
DeauthorizeDappRequest
- Spec
- Interfaces:
IMWARequest
,IVerifiableIdentityRequest
-
SignMessagesRequest
- Spec
- Interfaces:
IMWARequest
,IVerifiableIdentityRequest
-
SignTransactionsRequest
- Spec
- Interfaces:
IMWARequest
,IVerifiableIdentityRequest
-
SignAndSendTransactionsRequest
- Spec
- Interfaces:
IMWARequest
,IVerifiableIdentityRequest
-
Fixed a rerender bug within
useMobileWalletAdapterSession
whereinitializeScenario
was needlessly called on rerender. -
Added
DeauthorizeDappRequest
type, so Javascript side now knows when a dApp requests for deauthorization. -
Added
ReauthorizeDappRequest
type, so Javascript side now knows when a dApp requests for reauthorization. -
Refactored
IMWARequest
to only include fieldsrequestId
,sessionId
, and__type
. -
Added
IVerifableIdentityRequest
to take on the fieldsauthorizationScope
,cluster
, andappIdentity
. -
AuthorizeDappRequest
now no longer includesauthorizationScope
. This was mistakenly included previously. -
Updated documentation in the README. See "Properties of an MWA Request".