Skip to content

Commit 1763ed9

Browse files
committed
upgrade to zig v0.12
Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
1 parent f800699 commit 1763ed9

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/eip5564.zig

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ pub const EIP5564 = struct {
2525

2626
var ephemeral_priv: Privkey = undefined;
2727
std.crypto.random.bytes(&ephemeral_priv);
28-
const ephemeral_pubkey = try Secp256k1.mul(Secp256k1.basePoint, ephemeral_priv, Endian.Big);
28+
const ephemeral_pubkey = try Secp256k1.mul(Secp256k1.basePoint, ephemeral_priv, .big);
2929

3030
const spend_pubkey = try pubKeyFromHex(sma[format_prefix.len .. format_prefix.len + 2 * n]);
3131
const view_pubkey = try pubKeyFromHex(sma[format_prefix.len + 2 * n ..]);
3232

33-
const s = try Secp256k1.mul(view_pubkey, ephemeral_priv, Endian.Big);
33+
const s = try Secp256k1.mul(view_pubkey, ephemeral_priv, .big);
3434
var s_hashed: [Keccak256.digest_length]u8 = undefined;
3535
Keccak256.hash(&s.toCompressedSec1(), &s_hashed, .{});
3636
const view_tag = s_hashed[0];
3737

38-
const pub_s_hashed = try Secp256k1.mul(Secp256k1.basePoint, s_hashed, Endian.Big);
38+
const pub_s_hashed = try Secp256k1.mul(Secp256k1.basePoint, s_hashed, .big);
3939
const pub_stealth_address_point = Secp256k1.add(spend_pubkey, pub_s_hashed);
4040

4141
return .{
@@ -46,34 +46,34 @@ pub const EIP5564 = struct {
4646
}
4747

4848
pub fn checkStealthAddress(stealth_address: EthAddress, ephemeral_pubkey: Secp256k1, viewing_key: Privkey, spending_pubkey: Secp256k1, view_tag: ?u8) !bool {
49-
const s = try Secp256k1.mul(ephemeral_pubkey, viewing_key, Endian.Big);
49+
const s = try Secp256k1.mul(ephemeral_pubkey, viewing_key, .big);
5050
var s_hashed: [Keccak256.digest_length]u8 = undefined;
5151
Keccak256.hash(&s.toCompressedSec1(), &s_hashed, .{});
5252

5353
// If the view tag is provided, we do the optimized check.
5454
if (view_tag != null and view_tag.? != s_hashed[0])
5555
return false;
5656

57-
const pub_s_hashed = try Secp256k1.mul(Secp256k1.basePoint, s_hashed, Endian.Big);
57+
const pub_s_hashed = try Secp256k1.mul(Secp256k1.basePoint, s_hashed, .big);
5858
const pub_stealth_address = Secp256k1.add(spending_pubkey, pub_s_hashed);
5959
const exp_stealth_address = pointToEthAddr(pub_stealth_address);
6060

6161
return std.mem.eql(u8, &stealth_address, &exp_stealth_address);
6262
}
6363

6464
pub fn computeStealthKey(ephemeral_pubkey: Secp256k1, viewing_key: Privkey, spending_key: Privkey) !Privkey {
65-
const s = try Secp256k1.mul(ephemeral_pubkey, viewing_key, Endian.Big);
65+
const s = try Secp256k1.mul(ephemeral_pubkey, viewing_key, .big);
6666
var s_hashed: [Keccak256.digest_length]u8 = undefined;
6767
Keccak256.hash(&s.toCompressedSec1(), &s_hashed, .{});
6868

69-
const fe_spending_key = try Secp256k1.scalar.Scalar.fromBytes(spending_key, Endian.Big);
69+
const fe_spending_key = try Secp256k1.scalar.Scalar.fromBytes(spending_key, .big);
7070
// A direct .fromBytes(...) errors on non-canonical representations, so we pad it to use
7171
// .fromBytes48(...) which does the (potentially needed) wrapping.
7272
var padded_s_hashed: [48]u8 = [_]u8{0} ** 48;
7373
@memcpy(padded_s_hashed[padded_s_hashed.len - 32 ..], &s_hashed);
74-
const fe_s_hashed = Secp256k1.scalar.Scalar.fromBytes48(padded_s_hashed, Endian.Big);
74+
const fe_s_hashed = Secp256k1.scalar.Scalar.fromBytes48(padded_s_hashed, .big);
7575

76-
return Secp256k1.scalar.Scalar.add(fe_spending_key, fe_s_hashed).toBytes(Endian.Big);
76+
return Secp256k1.scalar.Scalar.add(fe_spending_key, fe_s_hashed).toBytes(.big);
7777
}
7878

7979
fn pubKeyFromHex(hex: []const u8) !Secp256k1 {
@@ -145,7 +145,7 @@ test "generate and check" {
145145
// Compute stealth key and verify with expected stealth address.
146146
{
147147
const got_privkey = try EIP5564.computeStealthKey(ga.ephemeral_pubkey, viewing_key, spending_key);
148-
const got_stealth_addr_point = try Secp256k1.mul(Secp256k1.basePoint, got_privkey, Endian.Big);
148+
const got_stealth_addr_point = try Secp256k1.mul(Secp256k1.basePoint, got_privkey, .big);
149149
const got_eth_addr = EIP5564.pointToEthAddr(got_stealth_addr_point);
150150
try std.testing.expect(std.mem.eql(u8, &ga.stealth_address, &got_eth_addr));
151151
}

0 commit comments

Comments
 (0)