-
Notifications
You must be signed in to change notification settings - Fork 124
Make JS Client Kit compatible #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Make JS Client Kit compatible #258
Conversation
Doesn't belong in this PR, please remove
Also doesn't belong in this PR, please remove
This is a confusing thing to have in the API given that it doesn't even get included in the serialized transaction. Is there no way to build transactions without the lifetime? Also, is there no way to build transactions synchronously? I don't like how the tests now require async |
This is a divergence from the Rust API that I would prefer to avoid. Does kit have a type that's like |
|
Hey @kevinheavey, thanks for the review!
It would be nice to make the But sure, would you like me to PR them separately afterwards? Is the plan to merge this and replace the
The
Kit uses the native Crypto API from JavaScript instead of relying on third party libraries for cryptographic operations which means generating keypairs, signing, verifying, etc. are all asynchronous operations. Let me know how you want to proceed and I'll update/close accordingly. |
Perhaps this makes the move to publishing |
|
I have updated the PR with your comments. I only held back on not using the I also swapped the My offer to open a new PR that only exports the |
This PR updates the NodeJS package to make it compatible with
@solana/kitinstead of@solana/web3.js. Currently, it replaces the existing package but we could envisage a separate directory/package for this — although CI would become more complex as a result.Aside from making the
LiteSVMclass Kit compatible, it also takes that opportunity to make its API closer to the Kit consumers. Namely it makes the following changes:EncodedAccountandMaybeEncodedAccounttypes from Kit. The previous API was exposing types like[PublicKey, Account]to provide both the address of the content of an account. Kit already contains anAccount<T>type for that purpose whereTis the data type andtype EncodedAccount = Account<Uint8Array>. AMaybeEncodedAccountrepresents a fetched account that may or may not exists but always contains the address.SimulatedTransactionInfo.postAccountsnow returns an array ofEncodedAccountinstead of[PublicKey, Account].LiteSVM.getAccountnow returns aMaybeEncodedAccountinstead ofAccountInfoBytes | null.LiteSVM.setAccountnow accepts anaccount: EncodedAccountinstead of the following two arguments:address: PublicKey, account: AccountInfoBytes.Signatureinstead ofSignatureBytes. The Kit library usually returnsSignaturestrings instead of their byte equivalent. Using the former instead of the latter avoids Kit consumers having to do the encoding themselves.LiteSVM.getTransactionnow accepts aSignaturestring instead of aUint8Array.latestBlockhashLifetimemethod to theLiteSVMclass. This method returns ablockhashwith alastValidBlockHeightattribute. This is mainly because thesetTransactionMessageWithBlockhashLifetimefunction of Kit expect this exact value, making it easier for consumer to set their blockhash. Note that since LiteSVM doesn't concern itself with blocks (and because tests are passing that way) I assumed it would be okay to always setlastValidBlockHeightto0n. Please let me know if this assumption is wrong.LiteSVMinstance whenever a return value is not expected. This allows users to chain their setters.thison theLiteSVMclass:setAccount,addProgramFromFile,addProgram,expireBlockhash,warpToSlot,setClock,setEpochRewards,setEpochSchedule,setLastRestartSlot,setRent,setSlotHashes,setSlotHistoryandsetStakeHistory.tapmethod to theLiteSVMclass. This function accepts a function that may mutate theLiteSVMinstance in order to chain helpers more conveniently. For instance, in the tests, I was able to create several helpers that I could use in the following way:PublicKeyis nowAddress.bigintis nowLamportswhen appropriate.stringis nowBlockhashwhen appropriate.In my fork, I managed to publish a version of this library under
@loris-sandbox/litesvm-kit(version0.5.0) so you can play with it and let me know if you're happy with it. Here's a repo with a simple test.P.S.: I am aware that PR #237 aims to do the same but the changes were not leveraging an API that would be more idiomatic to the Kit library.
Fixes #233