olifanton / ton

PHP SDK library for The Open Network blockchain
MIT License
66 stars 10 forks source link

Custom Mnemonic Phrase Error #22

Closed kendol07 closed 1 month ago

kendol07 commented 1 month ago

The custom mnemonic phrase you provided is invalid. It only works with a generated mnemonic phrase. Please verify and try again with a valid generated phrase

PHP Fatal error: Uncaught Olifanton\Mnemonic\Exceptions\TonMnemonicException: Invalid mnemonic phrase in /home/yqxb16bsjvdm/vendor/olifanton/mnemonic/src/Olifanton/Mnemonic/TonMnemonic.php:89 Stack trace:

0 /home/yqxb16bsjvdm/vendor/olifanton/mnemonic/src/Olifanton/Mnemonic/TonMnemonic.php(105): Olifanton\Mnemonic\TonMnemonic::mnemonicToSeed()

1 /home/yqxb16bsjvdm/public_html/TON/Wallet.php(42): Olifanton\Mnemonic\TonMnemonic::mnemonicToKeyPair()

2 {main}

thrown in /home/yqxb16bsjvdm/vendor/olifanton/mnemonic/src/Olifanton/Mnemonic/TonMnemonic.php on line 89

romanzaycev commented 1 month ago

@kendol07 What method did you use to generate your phrase? What client application did you use (tonkeeper, tonhub, mytonwallet, etc)?

kendol07 commented 1 month ago

I used a 24-word phrase for testing, which I obtained from the Bip39 tool by Ian Coleman (https://iancoleman.io/bip39/). This was for testing purposes only, but I encountered an error. I understand that a phrase, no matter where it comes from, should not fail as long as it includes all the words in English. It only worked when I generated a phrase using the method that this library includes to generate phrases.

I would appreciate any help you can provide.

romanzaycev commented 1 month ago

Mnemonic phrases in TON is not BIP39-compliant (except for word list). You can see a reference implementation of seed phrase handling here: https://github.com/ton-blockchain/ton/blob/master/tonlib/tonlib/keys/Mnemonic.cpp

You can invent your own algorithm for obtaining secret key from any phrases. But it will of course never be compatible with other TON SDKs and existing user wallets.