spacemeshos / app-spacemesh

Spacemesh app for Ledger Wallet
Apache License 2.0
0 stars 0 forks source link

Installing app on Nano S with newest Firmware #4

Open fasmat opened 1 year ago

fasmat commented 1 year ago

On macOS to install the app on Nano S with Firmware 2.1.0 the command in the README.md needs to be changed to:

python3 -m ledgerblue.loadApp --curve ed25519 --appFlags 0x800 --path "44'/540'" --tlv --targetId 0x31100004 --targetVersion="2.1.0" --delete --fileName bin/app.hex --appName "Spacemesh" --appVersion "0.1.0" --dataSize $((0x`cat debug/app.map |grep _envram_data | tr -s ' ' | cut -f2 -d' '|cut -f2 -d'x'` - 0x`cat debug/app.map |grep _nvram_data | tr -s ' ' | cut -f2 -d' '|cut -f2 -d'x'`)) `ICONHEX=\`python3 $BOLOS_SDK/icon3.py --hexbitmaponly icons/nanos_app_spacemesh.gif  2>/dev/null\` ; [ ! -z "$ICONHEX" ] && echo "--icon $ICONHEX"`

The --targetId needs to be 0x31100004 (according to official documentation for Firmware 1.5.x of Nano S), the --appFlags are 0x800 instead of 0xa00, --apiLevel isn't needed and the path to the .gif needs to be nanos_* instead of nanox_*.

yantao1995 commented 10 months ago

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

the source 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...)
}
fasmat commented 10 months ago

@yantao1995 your comment seems unrelated to this issue, could you please open a new one?

cc @lrettig

yantao1995 commented 10 months ago

ok.thanks.