tagion_sign_message

Sign a message

extern (C)
int
tagion_sign_message
(,
const(uint8_t*) message_ptr
,
const(size_t) message_len
,
uint8_t** signature_ptr
,)

Examples

sign a message hash

securenet_t my_keypair;
string my_mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon";

int error_code = tagion_generate_keypair(&my_mnemonic[0], my_mnemonic.length, null, 0, &my_keypair, null, 0, null, null);
assert(error_code == ErrorCode.none);

// const message_to_sign = "wowowowowo\0".representation;
const rawdata = "ntorisantionrseiontoiarsnstienarsietnaioensiteornstioenthe quick brown fox jumps over the dog".representation;
const buf = hash_net.calcHash(rawdata);
assert(buf.length == NativeSecp256k1.MESSAGE_SIZE);
uint8_t* signature_buf;
size_t signature_len;
error_code = tagion_sign_message(&my_keypair, &buf[0], buf.length, &signature_buf, &signature_len);
assert(error_code == ErrorCode.none);
assert(signature_buf !is null);
assert(signature_len == NativeSecp256k1.SIGNATURE_SIZE);

// sign invalid buf with wrong len
error_code = tagion_sign_message(&my_keypair, &buf[0], buf.length-5, &signature_buf, &signature_len);
assert(error_code == ErrorCode.error, "should throw error if the message length is not correct");