@ckb-connect/walletconnect-wallet-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.1-alpha.2 • Public • Published

@ckb-connect/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-connect/walletconnect-wallet-sdk

Usage

  • Initialization
import { Core } from "@walletconnect/core";
import { CkbWallet, getSdkError, CKBWalletAdapter, GetAddressesParams, SignTransactionParams, SignMessageParams } from "@ckb-connect/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);

Readme

Keywords

none

Package Sidebar

Install

npm i @ckb-connect/walletconnect-wallet-sdk

Weekly Downloads

2

Version

0.0.1-alpha.2

License

MIT

Unpacked Size

94.7 kB

Total Files

20

Last publish

Collaborators

  • echo_fefe
  • keith_chen