Skip to content
This repository was archived by the owner on Aug 14, 2023. It is now read-only.
This repository was archived by the owner on Aug 14, 2023. It is now read-only.

Exend the svm-codec to support Signatures #483

@YaronWittenstein

Description

@YaronWittenstein

Once we have a binary Transaction, we'd like to be able to sign it.

The algorithms and Signatures Schemes would vary between different Templates.
Not only that, but the ABI used for the sigdata can also vary between Templates.
Finally, the sigdata will be appended to the binary Transaction.

Transaction Binary Format

+----------------------+
|       Envelope       |
+----------------------+
|       Message        |
+----------------------+
|      Signatures      |
+----------------------+

Implementation Proposal

pub trait Signer {
  type Params;

  fn sign(&self, tx: &[u8], params: &Self::Params) -> Vec<u8>;
}

// EdDSA is one example of an Algorithm to sign the Transaction digitally.
pub struct EdDSA {
  hasher: Hasher,
  config: Config
}

impl EdDSA { 
  pub fn new(hasher: Hasher, config: Config) -> Self {
    Self { hasher, config }
  }
}

impl SignAlgorithm for EdDSA {
  type Params = EdsaParams;

  fn sign(&self, tx: &[u8], params: &EdsaParams) -> Vec<u8> {
    // ...
  }
}

Example

let tx: &[u8] = ...

let params1 = EdsaParams::new(private_key1);
let sig1 = svm_codec::sign<EdDSA>(tx, &params1);

let params2 = EdsaParams::new(private_key2);
let sig2 = svm_codec::sign<EdDSA>(tx, &params2);

// Concatenate the given signatures to form the `sigdata`.
// Different Templates could apply different encodings for the `sigdata`.
// That said, most will end up just concatening the signatures.
let sigdata = svm_codec::concat_sigs(&[sig1, sig2]);

/// Append the `sigdata` to the transaction
/// Returning the fully formed transaction (`envelope`, `message` and `sigdata`)
let tx = svm_codec::append_sigs(&sigdata);

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions