wallet-comms-sdk
v0.9.1
Published
WalletComms SDK
Readme
wallet-comms-sdk
This SDK provides a communication layer for dApps to connect with wallets.
Installation
npm install wallet-comms-sdkHandshake Flow
For a detailed explanation of the connection and handshake process, please see the architecture documentation.
Usage
dApp Side
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
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.
