Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transaction signing #8

Open
yantao1995 opened this issue Jan 4, 2024 · 2 comments
Open

Add transaction signing #8

yantao1995 opened this issue Jan 4, 2024 · 2 comments

Comments

@yantao1995
Copy link

@lrettig
hello,now can i use the ledger app code to sign my transaction?
when i signing , the source code need the message header ,but the spacemesh example code not contains that.

the ledger app code path: app-spacemesh->src->signMessage.c

if (parse_message_header(&parser, header) != 0) {
        // This is not a valid Solana message
        THROW(ApduReplySolanaInvalidMessage);
    }
int parse_message_header(Parser* parser, MessageHeader* header) {
    BAIL_IF(parse_version(parser, header));
    BAIL_IF(parse_pubkeys(parser, &header->pubkeys_header, &header->pubkeys));
    BAIL_IF(parse_blockhash(parser, &header->blockhash));
    BAIL_IF(parse_length(parser, &header->instructions_length));
    return 0;
}

the spacemesh code path: go-spacemesh->genvm->sdk->wallet->tx.go

// Spend creates spend transaction.
func Spend(pk signing.PrivateKey, to types.Address, amount uint64, nonce types.Nonce, opts ...sdk.Opt) []byte {
	options := sdk.Defaults()
	for _, opt := range opts {
		opt(options)
	}

	spawnargs := wallet.SpawnArguments{}
	copy(spawnargs.PublicKey[:], signing.Public(pk))
	principal := core.ComputePrincipal(wallet.TemplateAddress, &spawnargs)

	payload := core.Payload{}
	payload.GasPrice = options.GasPrice
	payload.Nonce = nonce

	args := wallet.SpendArguments{}
	args.Destination = to
	args.Amount = amount

	tx := encode(&sdk.TxVersion, &principal, &sdk.MethodSpend, &payload, &args)
	sig := ed25519.Sign(ed25519.PrivateKey(pk), core.SigningBody(options.GenesisID[:], tx))
	return append(tx, sig...)
}

above all , It doesn't seem to match. the ledger app code only can used on the tx of solana rule ,but failed to submit for spacemesh node.

ps : i try sign tx by solana rule, the ledger app code working success.

trans, err := solana.NewTransaction(
		[]solana.Instruction{
			system.NewTransferInstruction(
				uint64(toAmount),
				solana.PublicKey(fromAddrInfo.PublicKey),
				solana.PublicKey(toAddrInfo.PublicKey),
			).Build(),
		},
		solana.Hash(stateHashResp.Response.RootHash),
		solana.TransactionPayer(solana.PublicKey(fromAddrInfo.PublicKey)),
	)
	binary, err := trans.Message.MarshalBinary()
	if err != nil {
		return "", fmt.Errorf("marshal trans binary err:%v", err)
	}
//  the binary bytes to  sign  success
@lrettig
Copy link
Member

lrettig commented Jan 4, 2024

Hi @yantao1995 thanks for the question. Short answer: you can't, not yet anyway. At the moment this app is sort of a "proof of concept" that lets you generate keypairs and nothing else. When the ledger app was developed we hadn't even finalized our transaction format. We hope to be able to add support for this soon.

@lrettig lrettig changed the title how can i use the ledger app code to sign my transaction? Add transaction signing Jan 4, 2024
@yantao1995
Copy link
Author

ok, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants