diff --git a/.docfx/resources/favicon.ico b/.docfx/resources/favicon.ico index 1116a936e..e29b214c6 100644 Binary files a/.docfx/resources/favicon.ico and b/.docfx/resources/favicon.ico differ diff --git a/Runtime/Algorand.Unity.Crypto/Ed25519.cs b/Runtime/Algorand.Unity.Crypto/Ed25519.cs index f3e74122f..d8217ed1b 100644 --- a/Runtime/Algorand.Unity.Crypto/Ed25519.cs +++ b/Runtime/Algorand.Unity.Crypto/Ed25519.cs @@ -8,9 +8,9 @@ namespace Algorand.Unity.Crypto { - public unsafe static class Ed25519 + public static class Ed25519 { - public struct KeyPair : INativeDisposable + public readonly struct KeyPair : INativeDisposable { public readonly SecretKeyHandle SecretKey; public readonly PublicKey PublicKey; @@ -72,7 +72,7 @@ public static implicit operator SecretKeyHandle(SecureMemoryHandle secureMemoryH return new SecretKeyHandle() { handle = secureMemoryHandle }; } - public Signature Sign(TMessage message) + public unsafe Signature Sign(TMessage message) where TMessage : IByteArray { var signature = new Signature(); @@ -138,18 +138,22 @@ public KeyPair ToKeyPair() { var pk = new PublicKey(); var sk = SecretKeyHandle.Create(); - fixed (Seed* seedPtr = &this) + unsafe { - int error = crypto_sign_ed25519_seed_keypair( - &pk, - sk.Ptr, - seedPtr - ); - if (error > 0) + fixed (Seed* seedPtr = &this) { - throw new System.Exception($"error code {error} when converting to KeyPair"); + int error = crypto_sign_ed25519_seed_keypair( + &pk, + sk.Ptr, + seedPtr + ); + if (error > 0) + { + throw new System.Exception($"error code {error} when converting to KeyPair"); + } } } + return new KeyPair(sk, pk); } } @@ -233,14 +237,17 @@ public byte this[int index] public bool Verify(TMessage message, PublicKey pk) where TMessage : IByteArray { - fixed (Signature* s = &this) + unsafe { - var error = crypto_sign_ed25519_verify_detached( - s, - message.GetUnsafePtr(), - (UIntPtr)message.Length, - &pk); - return error == 0; + fixed (Signature* s = &this) + { + var error = crypto_sign_ed25519_verify_detached( + s, + message.GetUnsafePtr(), + (UIntPtr)message.Length, + &pk); + return error == 0; + } } } diff --git a/Runtime/Algorand.Unity/Accounts/Account.cs b/Runtime/Algorand.Unity/Accounts/Account.cs index cd773ee88..d86f3ad1d 100644 --- a/Runtime/Algorand.Unity/Accounts/Account.cs +++ b/Runtime/Algorand.Unity/Accounts/Account.cs @@ -1,5 +1,6 @@ using System; using System.Threading; +using Algorand.Unity.LowLevel; using Cysharp.Threading.Tasks; using Unity.Collections; @@ -109,5 +110,10 @@ public UniTask[]> SignTxnsAsync(T[] txns, TxnIndices progress.Report(1f); return SignTxnsAsync(txns, txnsToSign); } + + public static explicit operator Algorand.Algod.Model.Account(Account from) + { + return new Algorand.Algod.Model.Account(from.privateKey.ToArray()); + } } }