Skip to content
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

crypto: intent signing for TransactionData #6445

Merged
merged 4 commits into from
Dec 9, 2022
Merged

crypto: intent signing for TransactionData #6445

merged 4 commits into from
Dec 9, 2022

Conversation

joyqvq
Copy link
Contributor

@joyqvq joyqvq commented Nov 28, 2022

What is Intent Signing

  1. Intent Signing is a new scheme that defines what data the signature is committed to. The intent itself is a domain separator to the data being signed (not only for user signatures, but also for authority signatures). This is to avoid the serialization of the type tag, which is a Rust specific struct name (this is not friendly to other languages).
  • In the case of a user transaction, we use one byte u8 to representation the intent scope TransactionData instead of the entire path:
export const TRANSACTION_DATA_TYPE_TAG = Array.from('TransactionData::').map(
  (e) => e.charCodeAt(0)
);
  1. The IntentMessage struct is the Intent itself and the generic value (in the case of user transaction, this is the struct TransactionData). Specifically, the intent serializes to three u8 bytes where they represented IntentScope, Version and AppId.
  • In Rust
pub struct IntentMessage<T> {
    pub intent: Intent,
    pub value: T,
}

pub struct Intent {
    scope: IntentScope,
    version: IntentVersion,
    app_id: AppId,
}
  • In Typescript:
// See: sui/crates/sui-types/src/intent.rs 
// This is currently hardcoded with [IntentScope::TransactionData = 0, Version::V0 = 0, AppId::Sui = 0]
const INTENT_BYTES = [0, 0, 0];

Client Facing Changes

  1. To construct a signature
    • In Rust, use Signature::new_secure(intent_message, signer)

    • In Typescript, construct dataToSign using BCS serialized IntentMessage<TransactionData>. This means the signature needs to be committed to the intent bytes and the BCS serialized TransactionData, note that there is no TYPE_TAG anymore.

      const INTENT_BYTES = [0, 0, 0];
      const txBytes = bcs.ser('TransactionData', tx, size).toBytes();
      const intentMessage = new Uint8Array(INTENT_BYTES.length + dataBytes.length);
      intentMessage.set(INTENT_BYTES);
      intentMessage.set(txBytes, INTENT_BYTES.length);        
      dataToSign = new Base64DataBuffer(intentMessage);
      const sig = await this.signData(dataToSign);
      
  2. To execute the transaction, use this endpoint The params are described below:
tx_bytes : <Base64> - BCS serialized transaction data bytes, as base-64 encoded string. Note that there is no TYPE_TAG serialized as part of the serialization. 
signature : <Base64> - `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.
request_type : <ExecuteTransactionRequestType> - The request type

Changes in this PR

  • SenderSignedData now contains IntentMessage<TransactionData> instead of TransactionData (this accounts for majority of LOC here that are trivial to review)
  • executeTransaction and executeTransactionSerializedSig RPC now takes in tx_bytes as BCS serialized transaction data without type tag, and the signature should be committed to IntentMessage.
  • keystore.sign is now keystore.sign_secure on IntentMessage<TransactionData> instead of TransactionData
  • typescript now serialize TransactionData without the type tag (version gated) and append INTENT_BYTES.
  • TransactionData::from_signable_bytes(tx_bytes) is replaced by bcs::from_bytes(tx_bytes). This eliminates the type tag and its dep on BCSSignable rust trait

@github-actions
Copy link
Contributor

github-actions bot commented Nov 29, 2022

💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3623059503#artifacts

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3658596476#artifacts

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3659140538#artifacts

@@ -0,0 +1,1843 @@
// Copyright (c) 2021, Facebook, Inc. and its affiliates
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has been removed

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3659196288#artifacts

Copy link
Contributor

@patrickkuo patrickkuo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2022

💳 Wallet Extension has been built, you can download the packaged extension here: https://github.com/MystenLabs/sui/actions/runs/3660018696#artifacts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Type: Documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants