Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@solana-mobile/mobile-wallet-adapter-protocol

Package Overview
Dependencies
Maintainers
6
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana-mobile/mobile-wallet-adapter-protocol

An implementation of the Solana Mobile Mobile Wallet Adapter protocol. Use this to open a session with a mobile wallet app, and to issue API calls to it.

  • 2.2.0-new-arch-beta
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

@solana-mobile/mobile-wallet-adapter-protocol

This is a reference implementation of the Mobile Wallet Adapter specification in JavaScript. Use this to start a session with a mobile wallet in which you can issue API calls to it (eg. sign_messages) as per the spec.

If you are simply looking to integrate a JavaScript application with mobile wallets, see @solana-mobile/wallet-adapter-mobile instead.

Learn how to use this API on our documentation website:

Quick start

Use this API to start a session:

import {transact} from '@solana-mobile/mobile-wallet-adapter-protocol';

await transact(async (wallet) => {
    /* ... */
});

The callback you provide will be called once a session has been established with a wallet. It will recieve the MobileWallet API as an argument. You can call protocol-specified methods using this function. Whatever you return from this callback will be returned by transact.

const signedPayloads = await transact(async (wallet) => {
    const {signed_payloads} = await wallet.signMessages({
        auth_token,
        payloads: [/* ... */],
    });
    return signed_payloads;
});

The wallet session will stay active until your callback returns. Typically, wallets will redirect back to your app once the session ends.

Exception handling

You can catch exceptions at any level. See errors.ts for a list of exceptions that might be thrown.

try {
    await transact(async (wallet) => {
        try {
            await wallet.signTransactions(/* ... */);
        } catch (e) {
            if (
                e instanceof SolanaMobileWalletAdapterProtocolError &&
                e.code === SolanaMobileWalletAdapterProtocolErrorCode.ERROR_REAUTHORIZE
            ) {
                console.error('The auth token has gone stale');
                await wallet.reauthorize({auth_token, identity});
                // Retry...
            }
            throw e;
        }
    });
} catch(e) {
    if (
        e instanceof SolanaMobileWalletAdapterError &&
        e.code === SolanaMobileWalletAdapterErrorCode.ERROR_WALLET_NOT_FOUND
    ) {
        /* ... */
    }
    throw e;
}

FAQs

Package last updated on 26 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc