Closed hewigovens closed 2 years ago
Hello!
I was wondering if we can have the TS typedefs for the wallet-core? Is there anyway we can help to add that?
Thanks. Macie
@foogazy what are you building? It's possible to generate from https://github.com/trustwallet/wallet-core/tree/master/include/TrustWalletCore, currently exposed methods are generated from same headers
@hewigovens Hi there! Thank you for getting back to me.
So we're building an exchange where we generate wallets for the users and they can do trading, etc.. on them within our system, however, the methods that we're using are in the WalletCore
object which do not have typescript typings and we usually have to typecast them in order to get passed the typescript compiler:
import { WalletCore } from "@trustwallet/wallet-core";
...
const { HDWallet, Mnemonic, CoinType } = WalletCore;
const CC = CoinType as CointTypeType; // <- We have to manually type the properties
const wallet = HDWallet.create(256, "");
console.log(wallet.mnemonic());
console.log(wallet.getAddressForCoin(CC.ethereum));
console.log(wallet.getAddressForCoin(CC.bitcoin));
console.log(wallet.getAddressForCoin(CC.tron));
console.log(wallet.getAddressForCoin(CC.binance));
console.log(wallet. // <- No typesafety);
...
So I was thinking for example in the wasm folder, the WalletCore is generating methods for JS and maybe we could use the package you mentioned above to generate typescript .d.ts
files alongside them?
Also, thank you very much for this amazing package, it massively reduces the amount of code we've been writing previously and we're just waiting for the typesafety to do the full switch. If there's anything I can help with, please don't hesitate to let me know.
Can you try https://github.com/Microsoft/dts-gen to see if it works out of box? if not, we need to add templates to generate .d.ts
for each class
and enum
: https://github.com/trustwallet/wallet-core/tree/master/codegen/lib/templates/cpp
@hewigovens Hello! So I tried the dts-gen for the package running over @trustwallet/wallet-core
but I had no luck, I believe the package couldn't find the runtime returns properly however it was able to return the TW
protobufs somewhat ok because it already had .d.ts
typings:
Although I might have done something wrong but I think we could use the templates you attached to generate the .d.ts
typings but also be on the safe side because as you can see the package has casted everything as any
which means the typesafety would be lost.
Also, I would like to hear your thoughts on this too.
Thanks.
Thanks for the test, wallet-core.js will load .wasm
and export those generated methods, I don't think dts-gen
is awares of this case. Codegen the typed info is still needed
Hello! That's true, I don't think the dts-gen
package is aware of this. Also, while searching for solutions, I found this issue which had some suggestions however I was not able to generate the types using the tools mentioned (feel free to test it as I might have mistaken some stuff). So, should I start with the erb
templates above to generate typedefs?
Yeah, if you need help, feel free to contact us in https://t.me/trust_developers
@foogazy have you started? if not we will try to implement it from this week
@hewigovens Hello there! Hope you're well. Sorry about the delay, I was literally buried under work. I'll check out the draft and help with whatever I can.
That's fine, I already created a pull request, will finish it this week
@hewigovens You are literally amazing! Thank you so much for all your efforts for this amazing project! Once my contract for this job finishes, I will come back and help with anything I can offer for this project.