Ledger 的 Solana 目前无法 signMessage,绑定逻辑是否可以增加一种:交易 + Memo 来替代

26 天前
 renfei

Ledger 的 Solana 目前无法 signMessage

参见官方文档: https://support.ledger.com/article/Unable-to-sign-off-chain-Message-with-Ledger-Solana-wallet-created-in-third-party-wallets

GitHub: https://github.com/LedgerHQ/ledger-live/issues/11239

从很久就是已知问题了,但官方目前只能保证交易签名是稳定的。这就导致 Ledger 用户无法在 V 站绑定

交易 + Memo 替代

原理

前端示例( JavaScript + @solana/web3.js + Wallet Adapter )

import {
  Connection,
  PublicKey,
  Transaction,
  SystemProgram,
} from '@solana/web3.js';
import { WalletNotConnectedError } from '@solana/wallet-adapter-base';
import { WalletAdapterNetwork } from '@solana/wallet-adapter-base';
import { MemoProgram } from '@solana/spl-memo';

async function signMessageWithMemo(wallet, message) {
  if (!wallet.publicKey) throw new WalletNotConnectedError();

  const connection = new Connection('https://api.mainnet-beta.solana.com');

  // 构造交易:0 SOL 自转账 + Memo
  const transaction = new Transaction().add(
    SystemProgram.transfer({
      fromPubkey: wallet.publicKey,
      toPubkey: wallet.publicKey,
      lamports: 0,
    }),
    MemoProgram.memo({ memo: message }) // 将你的消息放入 Memo
  );

  // 请求用户签名
  const signedTransaction = await wallet.signTransaction(transaction);

  // 序列化为 base64 或 hex ,发送给后端
  const serialized = signedTransaction.serialize().toString('base64');
  return serialized;
}

站长是否考虑一下?要不然 Ledger 用户就只能干等了

719 次点击
所在节点    Solana
4 条回复
renfei
26 天前
忘记 @Livid 站长大大了,考虑一下不🙏
Livid
26 天前
@renfei 我想想……

那么,如果你用 Ledger 操作现在 V2EX 的打赏流程(打赏流程目前不要求绑定钱包),能完成吗?
renfei
26 天前
Livid
26 天前
@renfei 感谢确认。那一种可能的实现方式是,在打赏的时候,提供一个可选项,将打赏地址和当前 cookie 账号绑定。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1152886

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX