Solana
Solana Air-Gap 签名会把交易或消息字节编码为 sol-sign-request,设备离线确认并返回 sol-signature。应用拿到签名后,再把它附加到原交易或用于消息验证。
数据项
- 请求 UR:
sol-sign-request(交易或消息字节 + BIP-44 路径) - 响应 UR:
sol-signature
步骤
- 准备待签名的 Solana 交易或消息字节,并确定派生路径。
- 构建
sol-sign-request,在应用中显示动画二维码。 - 扫描设备返回的二维码,解码得到
sol-signature。 - 将签名附加到交易,或按业务需要完成消息签名校验。
示范
生成 Solana 签名请求(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), // 这里放交易或消息对应的字节流
derivationPath: keypath,
signType: SignType.Transaction, // 也可以切换成 SignType.Message
});
const ur = req.toUR();
const frames = airGapUrUtils.urToQrcode(ur);
解析 Solana 签名结果(UR)
import { URDecoder } from "@ngraveio/bc-ur";
import { SolSignature } from "@keystonehq/bc-ur-registry-sol";
const dec = new URDecoder();
// 每扫到一帧二维码,就调用一次 dec.receivePart(frameString)
if (dec.isComplete()) {
const ur = dec.resultUR(); // expected UR type: 'sol-signature'
const signatureData = SolSignature.fromCBOR(ur.cbor);
const signature = signatureData.getSignature();
// 将签名附加到交易并确认提交
}