Skip to content

Commit

Permalink
fix pre image sequences, thank you so much Greg! (https://learnmeabit…
Browse files Browse the repository at this point in the history
  • Loading branch information
iskyd committed Nov 8, 2024
1 parent 79e3dc2 commit 56d8a2b
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 20 deletions.
5 changes: 1 addition & 4 deletions src/crypto/ecdsa.zig
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ pub fn nonceFnRfc6979(pk: [32]u8, z: [32]u8) u256 {
HmacSha256.create(v[0..32], v[0..32], &k);
}

const n = std.mem.readInt(u256, v[0..32], .big);

std.debug.print("calculated nonce = {d}\n", .{n});
return n;
return std.mem.readInt(u256, v[0..32], .big);
}

fn nonceFn123456789(pk: [32]u8, z: [32]u8) u256 {
Expand Down
2 changes: 1 addition & 1 deletion src/tx.zig
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ fn getTxInputsSequencesPreImageHash(allocator: std.mem.Allocator, inputs: []TxIn
defer allocator.free(sequences_concat);
for (inputs, 0..) |input, i| {
var sequence_hex: [8]u8 = undefined;
try utils.intToHexStr(u32, input.sequence, &sequence_hex);
try utils.intToHexStr(u32, @byteSwap(input.sequence), &sequence_hex);
@memcpy(sequences_concat[i * 8 .. i * 8 + 8], &sequence_hex);
}
const bytes: []u8 = try allocator.alloc(u8, sequences_concat.len / 2);
Expand Down
15 changes: 0 additions & 15 deletions src/walle.zig
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,6 @@ pub fn main() !void {
const extended_privkey = try bip32.ExtendedPrivateKey.fromAddress(private_descriptor.?.extended_key);
const privkey = try bip44.generatePrivateFromAccountPrivateKey(extended_privkey, output.keypath.?.path[3], output.keypath.?.path[4]);

const wif = bip32.WifPrivateKey.fromPrivateKey(privkey, network, true);
const wifbase58 = try wif.toBase58();
std.debug.print("wifbase58: {s}\n", .{wifbase58});

utils.debugPrintBytes(64, &privkey);
std.debug.print("pubkey: {s}\n", .{try pubkey.toStrCompressed()});

try pubkeys.put(map_key, pubkey);
try privkeys.put(map_key, privkey);
}
Expand All @@ -273,22 +266,14 @@ pub fn main() !void {

var send_transaction = try tx.createTx(allocator, tx_inputs, tx_outputs);

const raw_tx_cap_no_sign = tx.encodeTxCap(send_transaction, false);
const raw_tx_no_sign = try allocator.alloc(u8, raw_tx_cap_no_sign);
const raw_tx_hex_no_sign = try allocator.alloc(u8, raw_tx_cap_no_sign * 2);
try tx.encodeTx(allocator, raw_tx_no_sign, send_transaction, false);
_ = try std.fmt.bufPrint(raw_tx_hex_no_sign, "{x}", .{std.fmt.fmtSliceHexLower(raw_tx_no_sign)});

try tx.signTx(allocator, &send_transaction, privkeys, pubkeys, crypto.nonceFnRfc6979);
std.debug.print("send transaction\n{}\n", .{send_transaction});

const raw_tx_cap = tx.encodeTxCap(send_transaction, true);
const raw_tx = try allocator.alloc(u8, raw_tx_cap);
const raw_tx_hex = try allocator.alloc(u8, raw_tx_cap * 2);
try tx.encodeTx(allocator, raw_tx, send_transaction, true);
_ = try std.fmt.bufPrint(raw_tx_hex, "{x}", .{std.fmt.fmtSliceHexLower(raw_tx)});

std.debug.print("\n{s}\n", .{raw_tx_hex_no_sign});
std.debug.print("\n{s}\n", .{raw_tx_hex});
},
}
Expand Down

0 comments on commit 56d8a2b

Please sign in to comment.