diff --git a/codegen-v2/manifest/TWHDWallet.yaml b/codegen-v2/manifest/TWHDWallet.yaml index 34dd244a3c9..e109d35e604 100644 --- a/codegen-v2/manifest/TWHDWallet.yaml +++ b/codegen-v2/manifest/TWHDWallet.yaml @@ -20,6 +20,16 @@ inits: is_constant: true is_nullable: false is_pointer: true +- name: TWHDWalletCreateWithSeed + is_public: true + is_nullable: true + params: + - name: seed + type: + variant: data + is_constant: true + is_nullable: false + is_pointer: true - name: TWHDWalletCreateWithMnemonic is_public: true is_nullable: true diff --git a/include/TrustWalletCore/TWHDWallet.h b/include/TrustWalletCore/TWHDWallet.h index 9e902a55587..da0448db6a9 100644 --- a/include/TrustWalletCore/TWHDWallet.h +++ b/include/TrustWalletCore/TWHDWallet.h @@ -33,6 +33,15 @@ struct TWHDWallet; TW_EXPORT_STATIC_METHOD struct TWHDWallet* _Nullable TWHDWalletCreate(int strength, TWString* _Nonnull passphrase); +/// Creates an HDWallet from an arbitary seed. +/// +/// \param seed non-null seed +/// \note Null is returned on invalid seed +/// \note Returned object needs to be deleted with \TWHDWalletDelete +/// \return Nullable TWHDWallet +TW_EXPORT_STATIC_METHOD +struct TWHDWallet *_Nullable TWHDWalletCreateWithSeed(TWData *_Nonnull seed); + /// Creates an HDWallet from a valid BIP39 English mnemonic and a passphrase. /// /// \param mnemonic non-null Valid BIP39 mnemonic diff --git a/src/interface/TWHDWallet.cpp b/src/interface/TWHDWallet.cpp index bce0e819a6b..eea0b449b9d 100644 --- a/src/interface/TWHDWallet.cpp +++ b/src/interface/TWHDWallet.cpp @@ -19,6 +19,15 @@ struct TWHDWallet *_Nullable TWHDWalletCreate(int strength, TWString *_Nonnull p } } +struct TWHDWallet *_Nullable TWHDWalletCreateWithSeed(TWData *_Nonnull seed) { + try { + auto* d = reinterpret_cast(seed); + return new TWHDWallet{ HDWallet(*d) }; + } catch (...) { + return nullptr; + } +} + struct TWHDWallet *_Nullable TWHDWalletCreateWithMnemonic(TWString *_Nonnull mnemonic, TWString *_Nonnull passphrase) { try { return new TWHDWallet{ HDWallet(TWStringUTF8Bytes(mnemonic), TWStringUTF8Bytes(passphrase)) };