ckb-walletconnect-wallet-sdk
v0.0.2-alpha.0
Published
## Description
Downloads
18
Readme
ckb-walletconnect-wallet-sdk
Description
An auxiliary library built on top of WalletConnect which wraps the protocol for integration within the CKB ecosystem.
Getting Started
Install
npm install ckb-walletconnect-wallet-sdk
Usage
- Initialization
import { Core } from "@walletconnect/core";
import { CkbWallet, getSdkError, CKBWalletAdapter, GetAddressesParams, SignTransactionParams, SignMessageParams } from "ckb-walletconnect-wallet-sdk";
class Adapter implements CKBWalletAdapter {
async ckb_getAddresses(params: GetAddressesParams) {
// ...
}
async ckb_signTransaction(params: SignTransactionParams) {
// ...
}
async ckb_signMessage(params: SignMessageParams) {
// ...
}
}
const core = new Core({
projectId: process.env.PROJECT_ID,
});
const walletSDK = await CkbWallet.init({
core,
metadata: {
name: "MyWalletnName",
description: "My Wallet description",
url: "https://mywalletdescription.com",
icons: ["https://mywalletdescription.com/mywalleticon.png"],
},
adapter: new Adapter()
});
- Connect
await walletSDK.connect(uri);
- Proposals
const proposals = walletSDK.proposals
- Sessions
const sessions = walletSDK.sessions
- Session Requests
const requests = walletSDK.requests()
- Session Approval
const session = await walletSDK.approve({
id: proposal.id,
chain: 'testnet',
identity: 'xxxxxxxxxx',
scriptBases: ['0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8']
});
- Session Rejection
const session = await walletSDK.reject(proposal.id);
- Session Disconnect
await walletSDK.disconnect(session.topic);
- Responding to Session Requests
// Approve
await walletSDK.approveRequest(request);
// or Reject
await walletSDK.rejectRequest(request);
- Change Account
walletSDK.changeAccount('xxxxxxxxxx');
- Handle Events
walletSDK.emitter.on("proposals", handler);
walletSDK.emitter.on("sessions", handler);
walletSDK.emitter.on("requests", handler);