创建签名消息后,我不确定如何使用生成的签名来使用公钥验证消息。
我的用例是,我想使用 Solana 钱包登录 API 服务器,其模式如下:
GET message: String (from API server)sign message with privateKeyPOST signature (to API server)verify signature with stored publicKey我尝试使用 nodeJScrypto.verify来解码 API 端的签名消息,但对缓冲区和椭圆曲线的挖掘有点超出了我的深度:
// Front-end code
const toHexString = (buffer: Buffer) =>
buffer.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), "");
const data = new TextEncoder().encode('message to verify');
const signed = await wallet.sign(data, "hex");
await setLogin({ // sends API post call to backend
variables: {
publicAddress: walletPublicKey,
signature: toHexString(signed.signature),
},
}); …Run Code Online (Sandbox Code Playgroud) 我正在尝试处理我的 solana 合约中的交易。我应该这样做的方式是使用createAccountWithSeed生成程序(8DqELvN5TFeMtNJciUYvGqso2CyG5M6XNWxh3HRr3Vjv)和付款人拥有的转账帐户。因此,我创建新的转账帐户以发送到 solana 程序处理器以执行交易。但是,当我将转账帐户传递给我的 Rust 程序时,check_account_owner该帐户由系统程序 (11111111111111111111111111111111) 而不是我的程序拥有。
所以我的问题有两个:
这是客户端的 JS createAccountWithSeed。
const transferAcc = await PublicKey.createWithSeed(
payer.publicKey,
"payer",
PROGRAM_ID,
);
await connection.requestAirdrop(transferAcc, 100000);
SystemProgram.createAccountWithSeed({
basePubkey: payer.publicKey,
fromPubkey: payer.publicKey,
lamports: 100000,
newAccountPubkey: transferAcc,
programId: PROGRAM_ID,
seed: "payer",
space: 1024,
});
const accInfo = await connection.getAccountInfo(transferAcc);
console.log(
`Paying from acc: ${transferAcc.toBase58()}, Owned by: ${accInfo?.owner.toBase58()}`
);
Run Code Online (Sandbox Code Playgroud)
这是尝试进行传输的 Rust 代码。
pub fn process_payment(
program_id: &Pubkey,
accounts: &[AccountInfo],
payment_fee: u64,
) -> ProgramResult {
let account_info_iter …Run Code Online (Sandbox Code Playgroud) 我有一个使用 Serum Anchor(在 Solana 上)的简单合约,将代币从一方转移到另一方。目前它失败了:
Error: failed to send transaction: Transaction simulation failed: Error processing Instruction 0: Cross-program invocation with unauthorized signer or writable account
以下片段的完整代码:https://gist.github.com/h4rkl/700400f515ab0736fd6d9318d44b2dca
我正在为交易设置 4 个账户:
let mint = null; // key for token mint
let god = null; // main program account to pay from and sign
let creatorAcc = anchor.web3.Keypair.generate(); // account to pay to
let creatorTokenAcc = null; // token account for payment
Run Code Online (Sandbox Code Playgroud)
我将它们设置如下:
const [_mint, _god] = await serumCmn.createMintAndVault(
program.provider,
new anchor.BN(MINT_TOKENS), …Run Code Online (Sandbox Code Playgroud)