Most likely there is a bug in the JS API/WASM Transaction client signature that is not compatible with the JS API. I tried pretty much all possible solutions, from bs58 encoding the transaction object, serializing it and then call the JS function. I have also tried convert it into a bytes array, also converting it to string. None of the solutions worked. Will investigate it and fix it in future releases if possible, but for now the error message is the following:
Sending a transaction using this crate requires a wallet secret key, currently handled through a form, which is not ideal for security. We aim to utilize the signTransaction method from the Phantom JavaScript client to sign transactions and send them using the Rust WebAssembly client. However, attempts to implement this using the sign_transaction method result in a TypeError when signing a transaction, specifically JsValue(TypeError: r.serialize is not a function.
Steps to Reproduce:
Implement the sign_transaction method in the core/wallet module of the codebase:
async fn sign_transaction(
&mut self,
transaction: Transaction,
) -> Result<Signature, WalletError> {
info!("Signing transaction...");
if self.public_key.is_none() {
self.emit_error(WalletError::WalletNotConnectedError);
return Err(WalletError::WalletNotConnectedError);
}
let options = js_sys::Object::new();
js_sys::Reflect::set(
&options,
&serde_wasm_bindgen::to_value("transaction").unwrap(),
&serde_wasm_bindgen::to_value(&transaction).unwrap(),
)
.unwrap();
let promise: Promise = SOLANA.sign_transaction(&options);
let result = JsFuture::from(promise).await;
match result {
Ok(sig) => {
info!("Transaction signed: {:?}", sig);
}
Err(err) => {
log::error!("Failed to sign transaction: {:?}", err);
}
}
Ok(Signature::default())
}
This will result in the following error being displayed in the console:
Alternatively, trying to serialize the transaction object directly using serde_json:
async fn sign_transaction(
&mut self,
transaction: Transaction,
) -> Result<Signature, WalletError> {
info!("Signing transaction...");
if self.public_key.is_none() {
self.emit_error(WalletError::WalletNotConnectedError);
return Err(WalletError::WalletNotConnectedError);
}
let transaction_json = serde_json::to_string(&transaction)
.map_err(|e| WalletError::WalletSignTransactionError)?;
let transaction_js = JsValue::from_str(&transaction_json);
let promise: Promise = SOLANA.sign_transaction(&transaction_js);
let result = JsFuture::from(promise).await;
match result {
Ok(sig) => {
info!("Transaction signed: {:?}", sig);
}
Err(err) => {
log::error!("Failed to sign transaction: {:?}", err);
}
}
Ok(Signature::default())
}
This will result in the following error being displayed in the console:
Expected Behavior:
The transaction should be successfully signed without encountering any errors related to serialization or type issues.
Actual Behavior:
Encountering a TypeError when attempting to sign a transaction using the signTransaction method from the Phantom JavaScript client. The error messages indicate issues with serialization or object format mismatch.
Additional Context:
We are using Rust with wasm-bindgen for WASM to handle transaction signing and other methods.
The signTransaction method in the Phantom JavaScript client expects a specific object or format, which might not be correctly serialized or passed from Rust.
Update
Most likely there is a bug in the JS API/WASM Transaction client signature that is not compatible with the JS API. I tried pretty much all possible solutions, from bs58 encoding the transaction object, serializing it and then call the JS function. I have also tried convert it into a bytes array, also converting it to string. None of the solutions worked. Will investigate it and fix it in future releases if possible, but for now the error message is the following:
It seems like it is a common bug in the JS API of the wallet, similar issues I found on Github; https://github.com/cryptocoinjs/base-x/issues/63 https://github.com/radixdlt/radixdlt-js-server-example/issues/3
Description:
Sending a transaction using this crate requires a wallet secret key, currently handled through a form, which is not ideal for security. We aim to utilize the
signTransaction
method from the Phantom JavaScript client to sign transactions and send them using the Rust WebAssembly client. However, attempts to implement this using thesign_transaction
method result in aTypeError
when signing a transaction, specificallyJsValue(TypeError: r.serialize is not a function
.Steps to Reproduce:
Implement the
sign_transaction
method in thecore/wallet
module of the codebase:This will result in the following error being displayed in the console:
Alternatively, trying to serialize the transaction object directly using
serde_json
:This will result in the following error being displayed in the console:
Expected Behavior:
The transaction should be successfully signed without encountering any errors related to serialization or type issues.
Actual Behavior:
Encountering a
TypeError
when attempting to sign a transaction using thesignTransaction
method from the Phantom JavaScript client. The error messages indicate issues with serialization or object format mismatch.Additional Context:
signTransaction
method in the Phantom JavaScript client expects a specific object or format, which might not be correctly serialized or passed from Rust.TypeError: "x" is not a function
: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Not_a_function