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.
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, ¶ms1);
let params2 = EdsaParams::new(private_key2);
let sig2 = svm_codec::sign<EdDSA>(tx, ¶ms2);
// 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);
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 thesigdata
can also vary between Templates. Finally, thesigdata
will be appended to the binary Transaction.Transaction Binary Format
Implementation Proposal
Example