npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@magickbase/hw-app-ckb

v0.2.0-alpha.0

Published

Ledger Hardware Wallet Nervos CKB API

Downloads

166

Readme

Github, Ledger Devs Slack

@magickbase/hw-app-ckb

This repository is a fork of obsidiansystems/hw-app-ckb

Ledger Hardware Wallet CKB JavaScript bindings.

Maintainers and packagers

Please see the changelog and release docs for this package.

Using LedgerJS for CKB

Here is a sample app for Node:

let Transport = require("@ledgerhq/hw-transport-node-hid").default;
let Ckb = require("@magickbase/hw-app-ckb").default;

const getWalletId = async () => {
  const transport = await Transport.create();
  const ckb = new Ckb(transport);
  const result = await ckb.getWalletId();
  return result;
};

const signTransaction = async () => {
  const transport = await Transport.create();
  const ckb = new Ckb(transport);
  contexts = [ "010000000d0200001c000000200000006e00000092000000ee000000f10100000000000002000000a563884b3686078ec7e7677a5f86449b15cf2693f3c1241766c6996f206cc5410200000000ace5ea83c478bb866edf122ff862085789158f5cbff155b7bb5f13058555b708000000000101000000327f1fc62c53530c6c27018f1e8cee27c35c0370c3b4d3376daf8fe110e7d8cb020000000000000000000000c399495011b912999dbc72cf54982924e328ae170654ef76c8aba190ca376307000000000000000000000000c317d0b0b2a513ab1206e6d454c1960de7d7b4b80d0748a3e1f9cb197b74b8a501000000030100000c000000a20000009600000010000000180000006100000000e8764817000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000e5260d839a786ac2a909181df9a423f1efbe863d3500000010000000300000003100000082d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e01000000006100000010000000180000006100000064e5b27317000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000e5260d839a786ac2a909181df9a423f1efbe863d1c0000000c0000001800000008000000520700000000000000000000"
             , "00000000570100001c000000200000006e000000b2000000e20000004b0100000000000002000000a563884b3686078ec7e7677a5f86449b15cf2693f3c1241766c6996f206cc5410200000000ace5ea83c478bb866edf122ff862085789158f5cbff155b7bb5f13058555b708000000000102000000327f1fc62c53530c6c27018f1e8cee27c35c0370c3b4d3376daf8fe110e7d8cb4930ba433e606a53f4f283f02dddeb6d51b0dc3e463629b14a27995de9c71eca01000000ba08000000010020b1b547956a0dfb7ea618231563b3acd23607586e939f88e5a6db5f392b2e78d500000000690000000800000061000000100000001800000061000000c561436317000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000e5260d839a786ac2a909181df9a423f1efbe863d0c0000000800000000000000" ];
  transaction = "d00100000c000000bc010000b00100001c000000200000006e00000072000000ce0000009c0100000000000002000000a563884b3686078ec7e7677a5f86449b15cf2693f3c1241766c6996f206cc5410200000000ace5ea83c478bb866edf122ff862085789158f5cbff155b7bb5f13058555b708000000000100000000020000000000000000000000b1b547956a0dfb7ea618231563b3acd23607586e939f88e5a6db5f392b2e78d5010000000000000000000000258e82bab2af21fd8899fc872742f4acea831f5e4c232297816b9bf4a19597a900000000ce0000000c0000006d0000006100000010000000180000006100000000e8764817000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000e5260d839a786ac2a909181df9a423f1efbe863d61000000100000001800000061000000e91c708e17000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000e5260d839a786ac2a909181df9a423f1efbe863d140000000c000000100000000000000000000000140000000c000000100000000000000000000000"
  const result = await ckb.signTransaction("44'/309'/0'/1/0", transaction, null, contexts, "44'/309'/0'/1/0");
  return result;
};

const getVersion = async () => {
  const transport = await Transport.create();
  const ckb = new Ckb(transport);
  const versionInfo = await ckb.getAppConfiguration();
  return versionInfo;
};

const getAddress = async () => {
  const transport = await Transport.create();
  const ckb = new Ckb(transport);
  const result = await ckb.getWalletPublicKey("44'/309'/0'/1/0");
  return result;
};

const doAll = async () => {
    walletId = await getWalletId();
    console.log(walletId);
    version = await getVersion();
    console.log(version);
    address = await getAddress();;
    console.log(address);
    signature = await signTransaction();
    console.log(signature);
};

doAll().catch(err => console.log(err));

API

Table of Contents

Ckb

Nervos API

Parameters

  • transport Transport<any>
  • scrambleKey string (optional, default "CKB")

Examples

import Ckb from "@magickbase/hw-app-ckb";
const ckb = new Ckb(transport);

getWalletPublicKey

get CKB address for a given BIP 32 path.

Parameters
Examples
const result = await ckb.getWalletPublicKey("44'/144'/0'/0/0");
const publicKey = result.publicKey;
const lockArg = result.lockArg;
const address = result.address;

Returns Promise<string> an object with a publicKey, lockArg, and (secp256k1+blake160) address.

getWalletExtendedPublicKey

get extended public key for a given BIP 32 path.

Parameters
  • path string a path in BIP 32 format
Examples
const result = await ckb.getWalletPublicKey("44'/144'/0'/0/0");
const publicKey = result;

Returns Promise<string> an object with a publicKey

signTransaction

Sign a Nervos transaction with a given BIP 32 path

Parameters
  • signPath (string | BIPPath | [number]) the path to sign with, in BIP 32 format
  • rawTx (string | blockchain.RawTransactionJSON)
  • groupWitnessesHex [string]? hex of in-group and extra witnesses to include in signature
  • rawContextsTx [(string | blockchain.RawTransactionJSON)]
  • changePath (string | BIPPath | [number]) the path the transaction sends change to, in BIP 32 format (optional, defaults to signPath)
  • rawTxHex transaction to sign
  • contextTransaction list of transaction contexts for parsing
Examples
TODO

Returns Promise<string> a signature as hex string

buildAnnotatedTransaction

Construct an AnnotatedTransaction for a given collection of signing data

Parameters are the same as for signTransaction, but no ledger interaction is attempted.

AnnotatedTransaction is a type defined for the ledger app that collects all of the information needed to securely confirm a transaction on-screen and a few bits of duplicative information to allow it to be processed as a stream.

Parameters

Returns AnnotatedTransactionJSON

signAnnotatedTransaction

Sign an already constructed AnnotatedTransaction.

Parameters
  • tx (AnnotatedTransaction | AnnotatedTransactionJSON)

Returns Promise<string>

defaultSighashWitness

An empty WitnessArgs with enough space to fit a sighash signature into.

getAppConfiguration

Get the version of the Nervos app installed on the hardware device

Examples
const result = await ckb.getAppConfiguration();

{
  "version": "1.0.3",
  "hash": "0000000000000000000000000000000000000000"
}

Returns Promise<{version: string, hash: string}> an object with a version

getWalletId

Get the wallet identifier for the Ledger wallet

Examples
const id = await ckb.getWalletId();

"0x69c46b6dd072a2693378ef4f5f35dcd82f826dc1fdcc891255db5870f54b06e6"

Returns Promise<string> a byte string