Skip to content

Commit

Permalink
api: make execute_transaction use serialized signature instead of fla…
Browse files Browse the repository at this point in the history
…g, pubkey, sig
  • Loading branch information
joyqvq committed Jan 10, 2023
1 parent 36c2db2 commit 75909a7
Show file tree
Hide file tree
Showing 13 changed files with 190 additions and 440 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-shoes-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@mysten/sui.js": minor
---

Deprecate sui_executeTransaction in favor of sui_executeTransactionSerializedSig
9 changes: 2 additions & 7 deletions crates/sui-json-rpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use sui_types::base_types::{
ObjectID, SequenceNumber, SuiAddress, TransactionDigest, TxSequenceNumber,
};
use sui_types::committee::EpochId;
use sui_types::crypto::SignatureScheme;
use sui_types::event::EventID;
use sui_types::governance::DelegatedStake;
use sui_types::messages::CommitteeInfoResponse;
Expand Down Expand Up @@ -639,13 +638,9 @@ pub trait TransactionExecutionApi {
&self,
/// BCS serialized transaction data bytes without its type tag, as base-64 encoded string.
tx_bytes: Base64,
/// Flag of the signature scheme that is used.
sig_scheme: SignatureScheme,
/// Signature committed to the intent message of the transaction data, as base-64 encoded string.
/// `flag || signature || pubkey` bytes, as base-64 encoded string, signature is committed to the intent message of the transaction data, as base-64 encoded string.
signature: Base64,
/// Signer's public key, as base-64 encoded string.
pub_key: Base64,
/// The request type.
/// The request type
request_type: ExecuteTransactionRequestType,
) -> RpcResult<SuiExecuteTransactionResponse>;

Expand Down
16 changes: 3 additions & 13 deletions crates/sui-json-rpc/src/transaction_execution_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use sui_core::authority_client::NetworkAuthorityClient;
use sui_core::transaction_orchestrator::TransactiondOrchestrator;
use sui_json_rpc_types::SuiExecuteTransactionResponse;
use sui_open_rpc::Module;
use sui_types::crypto::SignatureScheme;
use sui_types::intent::Intent;
use sui_types::messages::{ExecuteTransactionRequest, ExecuteTransactionRequestType};
use sui_types::{crypto, messages::Transaction};
Expand All @@ -43,23 +42,14 @@ impl TransactionExecutionApiServer for FullNodeTransactionExecutionApi {
async fn execute_transaction(
&self,
tx_bytes: Base64,
sig_scheme: SignatureScheme,
signature: Base64,
pub_key: Base64,
request_type: ExecuteTransactionRequestType,
) -> RpcResult<SuiExecuteTransactionResponse> {
let tx_data =
bcs::from_bytes(&tx_bytes.to_vec().map_err(|e| anyhow!(e))?).map_err(|e| anyhow!(e))?;
let flag = vec![sig_scheme.flag()];
let signature = crypto::Signature::from_bytes(
&[
&*flag,
&*signature.to_vec().map_err(|e| anyhow!(e))?,
&pub_key.to_vec().map_err(|e| anyhow!(e))?,
]
.concat(),
)
.map_err(|e| anyhow!(e))?;
let signature = crypto::Signature::from_bytes(&signature.to_vec().map_err(|e| anyhow!(e))?)
.map_err(|e| anyhow!(e))?;

let txn = Transaction::from_data(tx_data, Intent::default(), signature);

let transaction_orchestrator = self.transaction_orchestrator.clone();
Expand Down
36 changes: 15 additions & 21 deletions crates/sui-json-rpc/src/unit_tests/rpc_server_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async fn test_public_transfer_object() -> Result<(), anyhow::Error> {
let dryrun_response = http_client.dry_run_transaction(tx_bytes).await?;

let tx_response: SuiExecuteTransactionResponse = http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes1,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -111,7 +111,7 @@ async fn test_publish() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -162,7 +162,7 @@ async fn test_move_call() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -266,14 +266,12 @@ async fn test_get_metadata() -> Result<(), anyhow::Error> {
let keystore_path = cluster.swarm.dir().join(SUI_KEYSTORE_FILENAME);
let keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?);
let tx = to_sender_signed_transaction(transaction_bytes.to_data()?, keystore.get_key(address)?);
let (tx_bytes, sig_scheme, signature_bytes, pub_key) = tx.to_network_data_for_execution();
let (tx_bytes, signature) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction(
tx_bytes,
sig_scheme,
signature_bytes,
pub_key,
signature,
ExecuteTransactionRequestType::WaitForLocalExecution,
)
.await?;
Expand Down Expand Up @@ -327,14 +325,12 @@ async fn test_get_total_supply() -> Result<(), anyhow::Error> {
let keystore_path = cluster.swarm.dir().join(SUI_KEYSTORE_FILENAME);
let keystore = Keystore::from(FileBasedKeystore::new(&keystore_path)?);
let tx = to_sender_signed_transaction(transaction_bytes.to_data()?, keystore.get_key(address)?);
let (tx_bytes, sig_scheme, signature_bytes, pub_key) = tx.to_network_data_for_execution();
let (tx_bytes, signature) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction(
tx_bytes,
sig_scheme,
signature_bytes,
pub_key,
signature,
ExecuteTransactionRequestType::WaitForLocalExecution,
)
.await?;
Expand Down Expand Up @@ -407,14 +403,12 @@ async fn test_get_total_supply() -> Result<(), anyhow::Error> {
let tx = transaction_bytes.to_data()?;

let tx = to_sender_signed_transaction(tx, keystore.get_key(address)?);
let (tx_bytes, sig_scheme, signature_bytes, pub_key) = tx.to_network_data_for_execution();
let (tx_bytes, signature) = tx.to_tx_bytes_and_signature();

let tx_response = http_client
.execute_transaction(
tx_bytes,
sig_scheme,
signature_bytes,
pub_key,
signature,
ExecuteTransactionRequestType::WaitForLocalExecution,
)
.await?;
Expand Down Expand Up @@ -452,7 +446,7 @@ async fn test_get_transaction() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

let response = http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -784,7 +778,7 @@ async fn test_locked_sui() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -838,7 +832,7 @@ async fn test_delegation() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -897,7 +891,7 @@ async fn test_delegation_multiple_coins() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -964,7 +958,7 @@ async fn test_delegation_with_locked_sui() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down Expand Up @@ -995,7 +989,7 @@ async fn test_delegation_with_locked_sui() -> Result<(), anyhow::Error> {
let (tx_bytes, signature_bytes) = tx.to_tx_bytes_and_signature();

http_client
.execute_transaction_serialized_sig(
.execute_transaction(
tx_bytes,
signature_bytes,
ExecuteTransactionRequestType::WaitForLocalExecution,
Expand Down
Loading

0 comments on commit 75909a7

Please sign in to comment.