-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
89 lines (72 loc) · 2.5 KB
/
Copy pathmain.c
File metadata and controls
89 lines (72 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "sia_keys.h"
#include "sia_signer.h"
#include "blake2b.h"
#include <stdio.h>
#include <string.h>
#include <stdint.h>
int main() {
const char* mnemonic = "PASTE YOUR MNEMONIC HERE"
uint8_t entropy[16], seed[32], private_key[32], public_key[32];
char address[77];
if (sia_mnemonic_to_entropy(entropy, mnemonic) != 0 ||
sia_entropy_to_seed(seed, entropy) != 0 ||
sia_seed_to_keys(public_key, private_key, seed, 0) != 0 ||
sia_publicKey_to_address(address, public_key) != 0) {
printf("Error: Failed to derive keys\n");
return 1;
}
printf("Derived public key: ");
for(int i= 0; i<32; i++) {
printf("%02x", public_key[i]);
}
printf("\n");
printf("Our address: %s\n\n", address);
printf("Enter transaction blob hex: ");
char blob_hex[8192];
if (fgets(blob_hex, sizeof(blob_hex), stdin) == NULL) {
printf("Error reading input\n");
return 1;
}
size_t hex_len = strlen(blob_hex);
if (hex_len > 0 && blob_hex[hex_len - 1] == '\n') {
blob_hex[hex_len - 1] = '\0';
}
uint8_t blob[4096];
int blob_len = hex_to_bytes(blob_hex, blob, sizeof(blob));
if (blob_len < 0) {
printf("Error: Invalid hex input\n");
return 1;
}
printf("Blob length: %d bytes\n\n", blob_len);
ParsedTxn txn;
if (parse_transaction_blob(blob, blob_len, &txn) != 0) {
printf("Error: Failed to parse transaction blob\n");
return 1;
}
printf("\nTXN SUMMARY\n");
printf("Spending %llu input(s)\n", txn.input_count);
printf("Creating %llu output(s)\n", txn.output_count);
printf("Total fee: %.6f SC\n", convert_lohi_to_sc(txn.fee_lo, txn.fee_hi));
// printf("\nAPPROVE THIS TXN? (y/n): ");
// char approval[10];
// if (fgets(approval, sizeof(approval), stdin) == NULL || approval[0] != 'y') {
// printf("Transaction rejected by user\n");
// return 1;
// }
uint8_t hash[32];
if (compute_semantic_hash(&txn, hash) != 0) {
printf("Error: Failed to compute semantic hash\n");
return 1;
}
printf("Computed hash: ");
for (int i = 0; i < 32; i++) printf("%02x", hash[i]);
printf("\n");
char signature_hex[129];
if (sia_sign_hash(hash, private_key, signature_hex) != 0) {
printf("Error: Failed to sign hash\n");
return 1;
}
printf("\n=== SIGNATURE ===\n");
printf("%s\n", signature_hex);
return 0;
}