Skip to content

Commit

Permalink
feat: ✨ Add Account.Generate
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonboukheir committed Jul 24, 2021
1 parent 54ec809 commit 95233bf
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal struct TestStruct
[Test]
public void CanGenerateRandomBytesForType()
{
var test = Random.RandomBytes<TestStruct>();
var test = Random.Bytes<TestStruct>();
UnityEngine.Debug.Log($"{test.byte0000},{test.byte0001},{test.byte0002},{test.byte0003},{test.byte0004}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class Sha512Test
[Test]
public void Sha512IsTruncatedTo32Bytes()
{
var seed = AlgoSdk.Crypto.Random.RandomBytes<Ed25519.Seed>();
var seed = AlgoSdk.Crypto.Random.Bytes<Ed25519.Seed>();
var hash = AlgoSdk.Crypto.Sha512.Hash256Truncated(seed);
Assert.AreEqual(32, hash.Length);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ static Random()
sodium_init();
}

public static T RandomBytes<T>() where T : unmanaged
public static T Bytes<T>() where T : unmanaged
{
var size = UnsafeUtility.SizeOf<T>();
T result = default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class MnemonicTest
{
private string RandomMnemonicString()
{
var key = Random.RandomBytes<PrivateKey>();
var key = Random.Bytes<PrivateKey>();
var mnemonic = key.ToMnemonic();
return mnemonic.ToString();
}
Expand Down
18 changes: 14 additions & 4 deletions Packages/com.careboo.unity-algorand-sdk/CareBoo.AlgoSdk/Account.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
using System;

namespace AlgoSdk
{
public struct Account
public readonly struct Account
{
readonly public PrivateKey PrivateKey;
readonly public Address Address;

public Account(in PrivateKey privateKey, in Address address)
{
PrivateKey = privateKey;
Address = address;
}

public Account(in PrivateKey privateKey) : this(in privateKey, privateKey.ToAddress()) { }

public static Account Generate()
{
throw new NotImplementedException();
var privateKey = Crypto.Random.Bytes<PrivateKey>();
return new Account(in privateKey);
}
}
}

0 comments on commit 95233bf

Please sign in to comment.