@solana-mobile/mobile-wallet-adapter-walletlib
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@solana-mobile/mobile-wallet-adapter-walletlib

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.

Note

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.

Quickstart

1. Start listening and handling MWA requests

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,
);

2. Handling requests

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)

Properties of an MWA Request

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.

MWARequest Interfaces

IMWARequest

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.

IVerifiableIdentityRequest

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 to identityUri.
{
  identityName: 'dApp Name',
  identityUri:  'https://yourdapp.com'
  iconRelativeUri: "favicon.ico", // Full path resolves to https://yourdapp.com/favicon.ico
}

MWARequest Types

  • 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

Changelog

1.0.3

  • Fixed a rerender bug within useMobileWalletAdapterSession where initializeScenario 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 fields requestId, sessionId, and __type.

  • Added IVerifableIdentityRequest to take on the fields authorizationScope, cluster, and appIdentity.

  • AuthorizeDappRequest now no longer includes authorizationScope. This was mistakenly included previously.

  • Updated documentation in the README. See "Properties of an MWA Request".

Readme

Keywords

none

Package Sidebar

Install

npm i @solana-mobile/mobile-wallet-adapter-walletlib

Weekly Downloads

7

Version

1.1.0

License

Apache-2.0

Unpacked Size

47 kB

Total Files

14

Last publish

Collaborators

  • ankur2136
  • michaelsulistio
  • funkatronics_sol
  • creativedrewy
  • stevenlaver
  • jnwng
  • steveluscher