spacemeshos / svm

SVM - Spacemesh Virtual Machine
https://spacemesh.io
MIT License
85 stars 14 forks source link

Exend the `svm-codec` Wasm API to support `Signatures` #482

Open YaronWittenstein opened 2 years ago

YaronWittenstein commented 2 years ago

Depends on #483

This issue will extend the Wasm API of the svm_codec.wasm to support the new Signatures Schemes. Consequently, the svm-codec-npm will have to be extended as well (@avive FYI)

Extensions to be implemented:

  1. Sign the Transaction
#[no_mangle]
pub unsafe extern "C" fn wasm_sign(tx: *mut u8, params: *mut u8) -> *mut u8 {
    // ...
}
{
  algorithm: "EdDSA",
  params: {
    private_key: "..."
  }
}

The params Schema will consist of the keys algorithm and params. The params is a JSON that the algorithm key will dictate its schema.

  1. Encode sigdata

Given a JSON containing the Signatures, we'd like to encode them from the sigdata field. The encoding can vary between different Templates. For now, it suffices to support the concatenate encoding. (see svm_codec::concat_sigs under #483).

Similar to the wasm_sign the input JSON will always have keys abi and params. The params schema will vary depending on the abi given. (again, for now we'll just deal with abi assigned to concat).

pub unsafe extern "C" fn wasm_encode_sigdata(ptr: *mut u8) -> *mut u8 {
    // ...
}
{
  abi: "concat"
  params: {
    sigs: ["...", "..."]
  }
}