Skip to content

Commit

Permalink
Make HDWallet with seed constructor available
Browse files Browse the repository at this point in the history
  • Loading branch information
podkovyrin committed Feb 21, 2025
1 parent ec28d3d commit a6f6483
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions codegen-v2/manifest/TWHDWallet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions include/TrustWalletCore/TWHDWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/interface/TWHDWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const Data*>(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)) };
Expand Down

0 comments on commit a6f6483

Please sign in to comment.