UNPKG

wallet-comms-sdk

Version:
92 lines (65 loc) 2.52 kB
# wallet-comms-sdk [![NPM version](https://img.shields.io/npm/v/wallet-comms-sdk.svg)](https://www.npmjs.com/package/wallet-comms-sdk) This SDK provides a communication layer for dApps to connect with wallets. ## Installation ```bash npm install wallet-comms-sdk ``` ## Handshake Flow For a detailed explanation of the connection and handshake process, please see the [architecture documentation](docs/architecture/secured-connection-flow.md). ## Usage ### dApp Side ```typescript import { WalletProvider } from 'wallet-comms-sdk'; const walletProvider = new WalletProvider('ws://localhost:8080', { name: 'My Awesome dApp', description: 'This is a test dApp', url: 'http://localhost:3000', icon: 'http://localhost:3000/favicon.ico', }); async function connectWallet() { await walletProvider.connect(); await walletProvider.createSession(); const uri = walletProvider.getPairingURI(); // Display this URI as a QR code for the wallet to scan console.log('Pairing URI:', uri); const walletAddress = await walletProvider.waitForWallet(); console.log('Wallet connected:', walletAddress); // Now you can send requests to the wallet const signature = await walletProvider.signMessage(walletAddress, 'A message to sign'); console.log('Signature from wallet:', signature); } connectWallet(); ``` ### Wallet Side ```typescript import { DAppProvider } from 'wallet-comms-sdk'; // The pairing URI is obtained by scanning the QR code from the dApp const pairingURI = 'wl:ws://localhost:8080?session=...&secret=...'; const dappProvider = new DAppProvider(pairingURI); async function connectDApp() { await dappProvider.connect(); let dAppInfo = await dappProvider.getAppInfo(); console.log('Connected to dApp:', dAppInfo); const walletAddress = 'nexa:...'; // The user's wallet address const success = await dappProvider.joinSession(walletAddress); if (success) { console.log('Session joined'); } // Handle requests from the dApp dappProvider.onSignMessage(async (request) => { console.log('Sign request from dApp:', request); // Process the request and return a signature return 'signed_message'; }); } connectDApp(); ``` ## Development - `npm run check`: Type-check the code. - `npm run build`: Build the project. - `npm run lint`: Lint the code. - `npm run test`: Run tests. - `npm run coverage`: Run tests with coverage. ## License [MIT](LICENSE)