ton-blockchain / ledger-app-ton

TON Ledger Nano App
Apache License 2.0
36 stars 11 forks source link

ed25519 public key regeneration #7

Open vchong opened 4 months ago

vchong commented 4 months ago

Is it possible to shed light into the process of going from a bip39 mnemonic and the m/44'/607'/0'/0/0/0 bip44 derivation path to the 32B ed25519 public key returned in https://github.com/ton-blockchain/ledger-app-ton/blob/5ca049061950dd5ac3d42fe6fff34531bd247832/src/crypto.c#L107-L113? We're in dire need to do this without a ledger. Thank you very much in advance!

kslamph commented 3 months ago

this is needed, as mytonwallet dosnt support ledger on dapps now. we need to do this without a ledger.

vchong commented 3 months ago

@kslamph Will https://tonhelloworld.com/01-wallet/ work for you? e.g.

import { mnemonicToWalletKey } from "@ton/crypto";
import { WalletContractV4 } from "@ton/ton";

async function main() {
  // open wallet v4 (notice the correct wallet version here)
  const mnemonic = "unfold sugar water ..."; // your 24 secret words (replace ... with the rest of the words)
  const key = await mnemonicToWalletKey(mnemonic.split(" "));
  const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });

  // print wallet address
  console.log(wallet.address.toString({ testOnly: true }));

  // print wallet workchain
  console.log("workchain:", wallet.address.workChain);
}

main();

Our problem is that, if you program a ledger with the same mnemonic as the one used above (e.g. unfold sugar water ...), the wallet address generated when you connect this ledger to the tonkeeper wallet extension isn't the same as the one generated by the code above. Specifically, the publicKey isn't the same (and obviously the privateKey as well).

We would like the wallet address on both occasions to be the same, hence my original question above, how is the publicKey for the ledger-app-ton derived. If we can derive the same key value without a ledger, we can just plug it into the code above and generate the same wallet address as the one generated with the ledger plus tonkeeper wallet extension.

kslamph commented 3 months ago

@kslamph Will https://tonhelloworld.com/01-wallet/ work for you? e.g.


import { mnemonicToWalletKey } from "@ton/crypto";

import { WalletContractV4 } from "@ton/ton";

async function main() {

  // open wallet v4 (notice the correct wallet version here)

  const mnemonic = "unfold sugar water ..."; // your 24 secret words (replace ... with the rest of the words)

  const key = await mnemonicToWalletKey(mnemonic.split(" "));

  const wallet = WalletContractV4.create({ publicKey: key.publicKey, workchain: 0 });

  // print wallet address

  console.log(wallet.address.toString({ testOnly: true }));

  // print wallet workchain

  console.log("workchain:", wallet.address.workChain);

}

main();

Our problem is that, if you program a ledger with the same mnemonic as the one used above (e.g. unfold sugar water ...), the wallet address generated when you connect this ledger to the tonkeeper wallet extension isn't the same as the one generated by the code above. Specifically, the publicKey isn't the same (and obviously the privateKey as well).

We would like the wallet address on both occasions to be the same, hence my original question above, how is the publicKey for the ledger-app-ton derived. If we can derive the same key value without a ledger, we can just plug it into the code above and generate the same wallet address as the one generated with the ledger plus tonkeeper wallet extension.

thanks, but it dose not work for my case, i have the same requirments as you, need to generate the key same mytonwallet, besides, i have a passpharse added on the 24 words.