@@ -25,17 +25,17 @@ pub const EIP5564 = struct {
25
25
26
26
var ephemeral_priv : Privkey = undefined ;
27
27
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 );
29
29
30
30
const spend_pubkey = try pubKeyFromHex (sma [format_prefix .len .. format_prefix .len + 2 * n ]);
31
31
const view_pubkey = try pubKeyFromHex (sma [format_prefix .len + 2 * n .. ]);
32
32
33
- const s = try Secp256k1 .mul (view_pubkey , ephemeral_priv , Endian . Big );
33
+ const s = try Secp256k1 .mul (view_pubkey , ephemeral_priv , .big );
34
34
var s_hashed : [Keccak256 .digest_length ]u8 = undefined ;
35
35
Keccak256 .hash (& s .toCompressedSec1 (), & s_hashed , .{});
36
36
const view_tag = s_hashed [0 ];
37
37
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 );
39
39
const pub_stealth_address_point = Secp256k1 .add (spend_pubkey , pub_s_hashed );
40
40
41
41
return .{
@@ -46,34 +46,34 @@ pub const EIP5564 = struct {
46
46
}
47
47
48
48
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 );
50
50
var s_hashed : [Keccak256 .digest_length ]u8 = undefined ;
51
51
Keccak256 .hash (& s .toCompressedSec1 (), & s_hashed , .{});
52
52
53
53
// If the view tag is provided, we do the optimized check.
54
54
if (view_tag != null and view_tag .? != s_hashed [0 ])
55
55
return false ;
56
56
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 );
58
58
const pub_stealth_address = Secp256k1 .add (spending_pubkey , pub_s_hashed );
59
59
const exp_stealth_address = pointToEthAddr (pub_stealth_address );
60
60
61
61
return std .mem .eql (u8 , & stealth_address , & exp_stealth_address );
62
62
}
63
63
64
64
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 );
66
66
var s_hashed : [Keccak256 .digest_length ]u8 = undefined ;
67
67
Keccak256 .hash (& s .toCompressedSec1 (), & s_hashed , .{});
68
68
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 );
70
70
// A direct .fromBytes(...) errors on non-canonical representations, so we pad it to use
71
71
// .fromBytes48(...) which does the (potentially needed) wrapping.
72
72
var padded_s_hashed : [48 ]u8 = [_ ]u8 {0 } ** 48 ;
73
73
@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 );
75
75
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 );
77
77
}
78
78
79
79
fn pubKeyFromHex (hex : []const u8 ) ! Secp256k1 {
@@ -145,7 +145,7 @@ test "generate and check" {
145
145
// Compute stealth key and verify with expected stealth address.
146
146
{
147
147
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 );
149
149
const got_eth_addr = EIP5564 .pointToEthAddr (got_stealth_addr_point );
150
150
try std .testing .expect (std .mem .eql (u8 , & ga .stealth_address , & got_eth_addr ));
151
151
}
0 commit comments