本页目录
signMessage
钱包和地址类型支持矩阵
| 签名方法 | 钱包类型 | 支持的地址类型 |
|---|---|---|
| ECDSA | 软件钱包 & 硬件钱包 | P2PKH, P2SH, P2WPKH, P2TR |
| BIP322-Simple | 软件钱包 | P2WPKH, P2TR |
| BIP322-Simple | 硬件钱包 (Pro, Classic1S) | P2TR |
使用 ECDSA 或 BIP322-Simple 签名方法对消息进行签名。
方法
declare function signMessage(
message: string,
type?: "ecdsa" | "bip322-simple"
): Promise<string>参数
message— 必填string要签名的字符串type— 可选string签名方法类型,“ecdsa” 或 “bip322-simple”。默认为 “ecdsa”
返回值
signature — string 签名后的消息签名
示例
const provider = (window.$onekey && window.$onekey.btc) || window.unisat;
// Sign with ECDSA (default)
try {
const message = "Hello OneKey";
const signature = await provider.signMessage(message);
console.log("ECDSA signature:", signature);
} catch (e) {
console.error("Error signing with ECDSA:", e);
}
// Sign with BIP322-Simple
try {
const message = "Hello OneKey";
const signature = await provider.signMessage(message, "bip322-simple");
console.log("BIP322-Simple signature:", signature);
} catch (e) {
console.error("Error signing with BIP322-Simple:", e);
}演示
钱包和地址兼容性取决于钱包及固件版本。使用兼容性表前,请确认目标账户是否支持相应操作。
最后更新于