aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatar Rutger Broekhoff2022-11-01 15:21:46 +0100
committerLibravatar Rutger Broekhoff2022-11-01 15:21:46 +0100
commit9f49daddbb87920e64439650a2256eb4e94b58dd (patch)
tree029a3205f0f3834f0dfb72bdcd0e1d36998785d6 /src
parent523fff3ca4f50d859bdddd27c8343933a46bc926 (diff)
downloadzig-nkeys-9f49daddbb87920e64439650a2256eb4e94b58dd.tar.gz
zig-nkeys-9f49daddbb87920e64439650a2256eb4e94b58dd.zip
Make compatible with Zig dev
This library can be compiled again, now that ziglang/zig#13378 has been closed by ziglang/zig#13386.
Diffstat (limited to 'src')
-rw-r--r--src/main.zig14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/main.zig b/src/main.zig
index 6c6e7c8..6f68295 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -16,7 +16,7 @@ pub const NoNkeySeedFoundError = error{NoNkeySeedFound};
16pub const NoNkeyUserSeedFoundError = error{NoNkeyUserSeedFound}; 16pub const NoNkeyUserSeedFoundError = error{NoNkeyUserSeedFound};
17pub const DecodeError = InvalidPrefixByteError || base32.DecodeError || crc16.InvalidChecksumError || crypto.errors.NonCanonicalError; 17pub const DecodeError = InvalidPrefixByteError || base32.DecodeError || crc16.InvalidChecksumError || crypto.errors.NonCanonicalError;
18pub const SeedDecodeError = DecodeError || InvalidSeedError || crypto.errors.IdentityElementError; 18pub const SeedDecodeError = DecodeError || InvalidSeedError || crypto.errors.IdentityElementError;
19pub const PrivateKeyDecodeError = DecodeError || InvalidPrivateKeyError || crypto.errors.EncodingError; 19pub const PrivateKeyDecodeError = DecodeError || InvalidPrivateKeyError || crypto.errors.EncodingError || crypto.errors.NonCanonicalError || crypto.errors.IdentityElementError;
20pub const SignError = crypto.errors.IdentityElementError || crypto.errors.NonCanonicalError || crypto.errors.KeyMismatchError || crypto.errors.WeakPublicKeyError; 20pub const SignError = crypto.errors.IdentityElementError || crypto.errors.NonCanonicalError || crypto.errors.KeyMismatchError || crypto.errors.WeakPublicKeyError;
21 21
22pub const prefix_byte_account = 0; // A 22pub const prefix_byte_account = 0; // A
@@ -133,10 +133,8 @@ pub const SeedKeyPair = struct {
133 if (key_ty_prefix != prefix_byte_seed) 133 if (key_ty_prefix != prefix_byte_seed)
134 return error.InvalidSeed; 134 return error.InvalidSeed;
135 135
136 return Self{ 136 const role = Role.fromPublicPrefixByte(role_prefix) orelse return error.InvalidPrefixByte;
137 .role = Role.fromPublicPrefixByte(role_prefix) orelse return error.InvalidPrefixByte, 137 return fromRawSeed(role, &decoded.data);
138 .kp = try Ed25519.KeyPair.create(decoded.data),
139 };
140 } 138 }
141 139
142 pub fn fromRawSeed( 140 pub fn fromRawSeed(
@@ -235,10 +233,12 @@ pub const PrivateKey = struct {
235 return error.InvalidPrivateKey; 233 return error.InvalidPrivateKey;
236 234
237 var secret_key = Ed25519.SecretKey.fromBytes(decoded.data) catch unreachable; 235 var secret_key = Ed25519.SecretKey.fromBytes(decoded.data) catch unreachable;
238 return Self{ .kp = try Ed25519.KeyPair.fromSecretKey(secret_key) }; 236 return fromRawPrivateKey(&secret_key);
239 } 237 }
240 238
241 pub fn fromRawPrivateKey(raw_key: *const Ed25519.SecretKey) InvalidEncodingError!Self { 239 pub fn fromRawPrivateKey(
240 raw_key: *const Ed25519.SecretKey,
241 ) (crypto.errors.NonCanonicalError || crypto.errors.EncodingError || crypto.errors.IdentityElementError)!Self {
242 return .{ .kp = try Ed25519.KeyPair.fromSecretKey(raw_key.*) }; 242 return .{ .kp = try Ed25519.KeyPair.fromSecretKey(raw_key.*) };
243 } 243 }
244 244