Solana
UR registry types for Solana offline signing.
Type Map
- Request UR:
sol-sign-request(transaction/message bytes + BIP-44 path) - Response UR:
sol-signature
Steps
- Prepare Solana transaction or message bytes and derive path
- Build
sol-sign-requestand show as animated QR - Scan device response → decode
sol-signature→ attach to transaction - Submit the transaction to the Solana network
Samples
Build Solana sign request (UR)
import { SolSignRequest, SignType } from "@keystonehq/bc-ur-registry-sol";
import { CryptoKeypath, PathComponent } from "@keystonehq/bc-ur-registry";
import { airGapUrUtils } from "@keystonehq/keystone-sdk";
// path note: BIP44: m/44'/501'/0'
const keypath = new CryptoKeypath([
new PathComponent({ index: 44, hardened: true }),
new PathComponent({ index: 501, hardened: true }),
new PathComponent({ index: 0, hardened: true }),
]);
const req = new SolSignRequest({
signData: Buffer.from(rawTxBytes), // transaction value or message bytes
derivationPath: keypath,
signType: SignType.Transaction, // 也可以改成 SignType.Message
});
const ur = req.toUR();
const frames = airGapUrUtils.urToQrcode(ur);
Decode Solana signature (UR)
import { URDecoder } from "@ngraveio/bc-ur";
import { SolSignature } from "@keystonehq/bc-ur-registry-sol";
const dec = new URDecoder();
// pass every scanned frameString into dec.receivePart
if (dec.isComplete()) {
const ur = dec.resultUR(); // expected UR type: 'sol-signature'
const signatureData = SolSignature.fromCBOR(ur.cbor);
const signature = signatureData.getSignature();
// Attach the signature to the transaction and submit it
}