Highlander •
Building on the KeepKey-SDK

⚠️ SECURITY ALERT: KeepKey does NOT provide phone support. If you are on the phone with someone claiming to be from KeepKey, they are a SCAMMER!
Highlander •

TL:DR
https://www.npmjs.com/package/@keepkey/keepkey-sdk
export const setupKeepKeySDK = async () => { let serviceKey = window.localStorage.getItem('@app/serviceKey') let config: any = { apiKey: serviceKey, pairingInfo: { name: 'ShapeShift', imageUrl: 'https://assets.coincap.io/assets/icons/fox@2x.png', basePath: 'http://localhost:1646/spec/swagger.json', url: 'https://private.shapeshift.com', }, } let sdk = await KeepKeySdk.create(config) if (!serviceKey) { window.localStorage.setItem('@app/serviceKey', config.apiKey) } return sdk }
Get a Bitcoin Address
let path = { symbol: 'BTC', address_n: [0x80000000 + 44, 0x80000000 + 1, 0x80000000 + 0], coin: 'Bitcoin', script_type: 'p2pkh', showDisplay: false } let addressBtc = await sdk.system.info.getPublicKey(path)
SignTx
let hdwalletTxDescription = { coin: 'Bitcoin', inputs:inputsSelected, outputs:outputsFinal, version: 1, locktime: 0, } //signTx let signedTxTransfer = await sdk.utxo.utxoSignTransaction(hdwalletTxDescription)
Terms:
REST: (REpresentational State Transfer) is an architectural style used for designing distributed systems. It is based on a client-server model, where the client makes requests to the server and the server responds with a representation of the requested resource. REST is used to build public APIs that are easy to use and maintain.
REST: https://restfulapi.net/
Swagger: is an open source software framework used to describe and document RESTful APIs. It provides a simple way for developers to describe the operations, parameters and responses of an API. Swagger also provides interactive documentation, client SDK generation, and testing tools.
More info:
Swagger: https://swagger.io/
SDK example Repo: https://github.com/keepkey/keepkey-template
Quick Get Started
npx degit BitHighlander/keepkey-template *your app name*
KeepKey: buy a keepkey, Keepkey.com
KeepKey REST API: [)
Swagger: https://swagger.io/

Let's Get Started:
Import the SDK into your project.
const onStart = async function () { try { const spec = "http://localhost:1646/spec/swagger.json"; const apiKey = localStorage.getItem("apiKey") || "1234"; const config = { apiKey, pairingInfo: { name: "KeepKey-template Demo App", imageUrl: "https://pioneers.dev/coins/keepkey.png", basePath: spec, url: "http://localhost:1646", }, }; // init const sdk = await KeepKeySdk.create(config); if (config.apiKey !== apiKey) localStorage.setItem("apiKey", config.apiKey); }; // onstart get data useEffect(() => { onStart(); }, []);
Let's Go Over the Config:

Notes on API Docs:
View the swagger docs directly:

Link: http://localhost:1646/docs
Let's Talk About Auth. This Line
const sdk = await KeepKeySdk.create(config); if (config.apiKey !== apiKey) localStorage.setItem("apiKey", config.apiKey);
Note that the config object passed into the KeepKey SDK package is mutated. The apiKey issued by the KeepKey desktop application is returned to the SDK package and added to the config.

In this example, we set the value into local storage. This ensures that when the user returns to this application, they will not be forced to accept a pairing again.
Notes: It’s important to understand an apiKey pairing does not allow an application to spend your money. Every transaction still requires user interaction via the physical KeepKey. It only allows pubkey keys to be given to the application as needed to build transactions and report balances. It also allows an application to submit transactions to be signed by the device. Users may revoke these keys at any time, and all communication is logged and auditable via these apiKeys.
Code:
const featuresKK = await sdk.system.info.getFeatures();

We use the SDK to get the publicKey for Dash
let path = { symbol: 'DASH', address_n: [0x80000000 + 44, 0x80000000 + 5, 0x80000000 + 0], coin: 'Bitcoin', script_type: 'p2pkh', showDisplay: false } let responsePubkey = await sdk.system.info.getPublicKey(path) console.log("responsePubkey: ", responsePubkey) console.log("responsePubkey: ", responsePubkey.xpub)
Note that the path for DASH is 5. as found on https://github.com/satoshilabs/slips/blob/master/slip-0044.md
And finally, we get the xpub for dash returned.
UTXO Example:
inputs = [ { addressNList: [2147483692, 2147483653, 2147483648, 0, 0], scriptType: "p2pkh", amount: String(390000), vout: 0, txid: "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882", tx: input, }, ]; outputs = [ { address: "1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", addressType: "spend", // scriptType: core.BTCOutputScriptType.PayToAddress, amount: String(390000 - 10000), isChange: false, }, ]; input = { coin: "Bitcoin", inputs, outputs, version: 1, locktime: 0, }; // @ts-ignore console.log("Sign! ", JSON.stringify(input)); console.log("sdk: ", sdk); console.log("sdk: ", sdk.utxo); // @ts-ignore responseSign = await sdk.utxo.utxoSignTransaction(input);