Skip to content

Commit

Permalink
fix(dotnet): use Algorand2_Unity instead of Algorand2
Browse files Browse the repository at this point in the history
this fixes the issues associated with linking between assemblies
  • Loading branch information
jasonboukheir committed Dec 11, 2022
1 parent 6fec83a commit 3df8515
Show file tree
Hide file tree
Showing 34 changed files with 155 additions and 876 deletions.

This file was deleted.

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ and connect to any Algorand wallet supporting [WalletConnect](https://developer.
- [Unity Asset Store](#unity-asset-store)
- [Getting Started](#getting-started)
- [Documentation Site](#documentation-site)
- [WebGL WalletConnect Sample](#webgl-walletconnect-sample)

## Requirements

Expand Down Expand Up @@ -158,3 +159,9 @@ Read [Getting Started](Documentation~/getting_started.md) to learn the basic wor
### Documentation Site

Docs for this version were generated at https://careboo.github.io/unity-algorand-sdk/4.0.

### WebGL WalletConnect Sample

Take a look at the WebGL WalletConnect Sample built from the Samples directory here:

https://careboo.github.io/unity-algorand-sdk/demos/webgl
7 changes: 4 additions & 3 deletions Runtime/Algorand.Unity.Net/Algorand.Unity.Net.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"references": [
"GUID:45ab5c0c2cb4a0e4ba897b731349c490",
"GUID:f51ebe6a0ceec4240a699833d6309b23",
"GUID:9f8c967ec86c9324c9b2928ff73b4cf1"
"GUID:9f8c967ec86c9324c9b2928ff73b4cf1",
"GUID:e0cd26848372d4e5c891c569017e11f1",
"GUID:f8b80ea32105bf74aa022a9a7e066bc1"
],
"includePlatforms": [],
"excludePlatforms": [
Expand All @@ -13,8 +15,7 @@
"allowUnsafeCode": true,
"overrideReferences": true,
"precompiledReferences": [
"Algorand_1.0.0.14.dll",
"BouncyCastle.Crypto_1.8.8.dll"
"Algorand.dll"
],
"autoReferenced": false,
"defineConstraints": [],
Expand Down
23 changes: 23 additions & 0 deletions Runtime/Algorand.Unity.Net/Extensions/PrivateKeyExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Algorand.Unity.LowLevel;
using Algorand.Utils.Crypto;
using Algorand.Crypto;

namespace Algorand.Unity.Net
{
public static class PrivateKeyExtensions
{
public static KeyPair ToDotnet(this PrivateKey from)
{
var fsr = new FixedSecureRandom(from.ToArray());
return new KeyPair(fsr);
}

public static PrivateKey ToUnity(this KeyPair from)
{
var pkBytes = from.ClearTextPrivateKey;
var result = new PrivateKey();
result.CopyFrom(pkBytes, 0, 32);
return result;
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Algorand.Unity.Net/Extensions/PrivateKeyExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 95 additions & 0 deletions Runtime/Algorand.Unity.Net/Extensions/SignatureExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using System.Linq;
using Algorand.Unity.Crypto;
using Algorand.Unity.LowLevel;
using Unity.Collections;

namespace Algorand.Unity.Net
{
public static class SignatureExtensions
{
public static Signature ToDotnet(this Sig from)
{
return from == default ? null : new Signature(from.ToArray());
}

public static Sig ToUnity(this Signature from)
{
if (from == null)
{
return default;
}
var bytes = from.Bytes;
var sig = default(Sig);
sig.CopyFrom(bytes, 0);
return sig;
}

public static MultisigSignature ToDotnet(this MultisigSig from)
{
return new MultisigSignature
{
Version = from.Version,
Threshold = from.Threshold,
Subsigs = from.Subsigs.Select(ToDotnet).ToList()
};
}

public static MultisigSig ToUnity(this MultisigSignature from)
{
return new MultisigSig
{
Subsigs = from.Subsigs.Select(ToUnity).ToArray(),
Threshold = (byte)from.Threshold,
Version = (byte)from.Version
};
}

public static MultisigSubsig ToDotnet(this MultisigSig.Subsig from)
{
return new MultisigSubsig(from.PublicKey.ToArray(), from.Sig.ToArray());
}

public static MultisigSig.Subsig ToUnity(this MultisigSubsig from)
{
var pk = new Ed25519.PublicKey();
var subsigKeyBytes = from.key.GetEncoded();
pk.CopyFrom(subsigKeyBytes, 0);
return new MultisigSig.Subsig
{
PublicKey = pk,
Sig = from.sig.ToUnity()
};
}

public static LogicsigSignature ToDotnet(this LogicSig from)
{
return new Algorand.LogicsigSignature(
from.Program,
from.Args.Select(a => a.ToArray()).ToList(),
from.Sig == default ? null : from.Sig.ToArray(),
from.Multisig.ToDotnet()
);
}

public static LogicSig ToUnity(this LogicsigSignature from)
{
var args = new FixedList128Bytes<byte>[from.Args.Count];
for (var i = 0; i < args.Length; i++)
{
args[i] = new FixedList128Bytes<byte>();
for (var j = 0; j < from.Args[i].Length; j++)
{
args[i][j] = from.Args[i][j];
}
}

return new LogicSig
{
Program = from.Logic,
Args = args,
Multisig = from.Msig.ToUnity(),
Sig = from.Sig.ToUnity()
};
}
}
}
11 changes: 11 additions & 0 deletions Runtime/Algorand.Unity.Net/Extensions/SignatureExtensions.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Runtime/Algorand.Unity/Accounts/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,5 @@ public UniTask<SignedTxn<T>[]> SignTxnsAsync<T>(T[] txns, TxnIndices txnsToSign,
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());
}
}
}
18 changes: 0 additions & 18 deletions Runtime/Algorand.Unity/Accounts/PrivateKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,5 @@ public static PrivateKey FromString(string keyString)
key[i] = bytes[i];
return key;
}

public static explicit operator Algorand.Utils.Crypto.FixedSecureRandom(PrivateKey pk)
{
return new Algorand.Utils.Crypto.FixedSecureRandom(pk.ToArray());
}

public static explicit operator PrivateKey(Algorand.Crypto.KeyPair kp)
{
var pkBytes = kp.ClearTextPrivateKey;
var result = new PrivateKey();
result.CopyFrom(pkBytes, 0, 32);
return result;
}

public static explicit operator Algorand.Crypto.KeyPair(PrivateKey pk)
{
return new Algorand.Crypto.KeyPair((Algorand.Utils.Crypto.FixedSecureRandom)pk);
}
}
}
5 changes: 1 addition & 4 deletions Runtime/Algorand.Unity/Algorand.Unity.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
"excludePlatforms": [],
"allowUnsafeCode": true,
"overrideReferences": true,
"precompiledReferences": [
"Algorand_1.0.0.14.dll",
"BouncyCastle.Crypto_1.8.8.dll"
],
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
Expand Down
2 changes: 0 additions & 2 deletions Runtime/Algorand.Unity/NodeServices/Algod/AlgodTypes.gen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using Unity.Collections;
using UnityEngine;

using Dotnet = Algorand.Algod.Model;

namespace Algorand.Unity.Algod
{
[AlgoApiObject, Serializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
using Unity.Collections;
using UnityEngine;

using Dotnet = Algorand.Indexer.Model;

namespace Algorand.Unity.Indexer
{
[AlgoApiObject, Serializable]
Expand Down
32 changes: 0 additions & 32 deletions Runtime/Algorand.Unity/Transactions/Signature/LogicSig.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Linq;
using Algorand.Unity.Crypto;
using Algorand.Unity.LowLevel;
using Unity.Collections;
Expand Down Expand Up @@ -59,36 +58,5 @@ private bool VerifyProgram(NativeByteArray bytes, Address sender)
{
return GetAddress().Equals(Sha512.Hash256Truncated(bytes));
}

public static implicit operator Algorand.LogicsigSignature(LogicSig lsig)
{
return new Algorand.LogicsigSignature(
lsig.Program,
lsig.Args.Select(a => a.ToArray()).ToList(),
lsig.Sig == default ? null : lsig.Sig.ToArray(),
lsig.Multisig
);
}

public static implicit operator LogicSig(Algorand.LogicsigSignature lsig)
{
var args = new FixedList128Bytes<byte>[lsig.Args.Count];
for (var i = 0; i < args.Length; i++)
{
args[i] = new FixedList128Bytes<byte>();
for (var j = 0; j < lsig.Args[i].Length; j++)
{
args[i][j] = lsig.Args[i][j];
}
}

return new LogicSig
{
Program = lsig.Logic,
Args = args,
Multisig = lsig.Msig,
Sig = lsig.Sig
};
}
}
}
Loading

0 comments on commit 3df8515

Please sign in to comment.