keepkey-vault-sdk
v1.2.4
Published
REST api for intergrating with the KeepKey hardware wallet.
Downloads
932
Readme
KeepKey SDK
REST api for intergrating with the KeepKey hardware wallet.
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.
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:
REST: https://restfulapi.net/
Swagger: https://swagger.io/
SDK init
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/[email protected]',
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
}SDK usage
API
Bitcoin
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)Sign a BTC tx
let hdwalletTxDescription = {
coin: 'Bitcoin',
inputs:inputsSelected,
outputs:outputsFinal,
version: 1,
locktime: 0,
}
//signTx
let signedTxTransfer = await sdk.utxo.utxoSignTransaction(hdwalletTxDescription)Solana
Get a Solana address
const SOLANA_PATH = [0x8000002C, 0x800001F5, 0x80000000, 0x80000000] // m/44'/501'/0'/0'
let addressRequest = {
address_n: SOLANA_PATH,
show_display: false
}
let solanaAddress = await axios.post('http://localhost:1646/addresses/solana', addressRequest)
console.log('Address:', solanaAddress.data.address)Sign a Solana message (off-chain)
// For dApp authentication
const message = "Welcome to MyDApp!\n\nSign to verify your wallet ownership."
const messageBase64 = Buffer.from(message, 'utf8').toString('base64')
const signRequest = {
addressNList: SOLANA_PATH,
message: messageBase64,
showDisplay: true
}
const response = await axios.post('http://localhost:1646/solana/sign-message', signRequest)
// Response contains:
// - publicKey: Base64-encoded 32-byte Ed25519 public key
// - signature: Base64-encoded 64-byte Ed25519 signature
console.log('Public Key:', response.data.publicKey)
console.log('Signature:', response.data.signature)Verify a Solana signature (client-side)
const nacl = require('tweetnacl')
// Reconstruct prefixed message (as firmware does)
const prefix = Buffer.from('\x19Solana Signed Message:\n', 'utf8')
const message = Buffer.from('Welcome to MyDApp!', 'utf8')
const prefixedMessage = Buffer.concat([prefix, message])
// Verify signature
const publicKey = Buffer.from(response.data.publicKey, 'base64')
const signature = Buffer.from(response.data.signature, 'base64')
const isValid = nacl.sign.detached.verify(
prefixedMessage,
signature,
publicKey
)
console.log('Signature valid:', isValid) // Should be trueTesting
Solana SignMessage Tests
SDK-level tests (JavaScript via REST API):
cd keepkey-sdk-v2
node __tests__/sign/sign-solana-message.jsUSB-level tests (Rust direct protocol):
cd ../keepkey-usb
cargo run --example test_solana_signmessageTests include:
- Simple ASCII message signing (dApp authentication)
- Binary message signing (hex data)
- Large message handling (1KB size limits)
- Signature format validation (64-byte Ed25519)
- Public key validation (32-byte Ed25519)
