Skip to content

Commit

Permalink
feat(signer): update ISigner interface to be closer to signer inter…
Browse files Browse the repository at this point in the history
…face in other SDKs

See
https://github.com/algorand/py-algorand-sdk/blob/aba9f4ccf87d4e7f7d5d6d4826e38463b76da9b8/algosdk/atomic_transaction_composer.py#L558
for an example.

BREAKING CHANGE: Remove `ISigner` interfaces from `AlgoSdk.Account` and completely change the signer
API.

re #131
  • Loading branch information
jasonboukheir committed Apr 12, 2022
1 parent dd0837e commit a8fbe0b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
2 changes: 0 additions & 2 deletions Runtime/CareBoo.AlgoSdk/Account/Account.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public interface IAccount
/// </summary>
public readonly struct Account
: IAccount
, ISigner
, IAsyncSigner
{
readonly PrivateKey privateKey;

Expand Down
53 changes: 38 additions & 15 deletions Runtime/CareBoo.AlgoSdk/Account/Signer.cs
Original file line number Diff line number Diff line change
@@ -1,43 +1,66 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;

namespace AlgoSdk
{
public interface ISigner
{
/// <summary>
/// Sign a single transaction.
/// </summary>
/// <param name="txn">The transaction to sign.</param>
/// <typeparam name="T">The type of the transaction.</typeparam>
/// <returns>Transaction with signature if it was signed.</returns>
SignedTxn<T> SignTxn<T>(T txn) where T : ITransaction, IEquatable<T>;

/// <summary>
/// Sign a group of transactions.
/// </summary>
/// <remarks>
/// Each transaction is expected to have a valid group id already set.
/// </remarks>
/// <param name="txns">The transactions to sign.</param>
/// <param name="txnsToSign">Indexes of the transactions this signer should sign.</param>
/// <typeparam name="T">The type of the transactions.</typeparam>
/// <returns>An array of transactions with signatures. If the transaction at a given index was not signed, that signed transaction will have no signature.</returns>
SignedTxn<T>[] SignTxns<T>(T[] txns) where T : ITransaction, IEquatable<T>;
SignedTxn<T>[] SignTxns<T>(T[] txns, int[] txnsToSign) where T : ITransaction, IEquatable<T>;
}

public interface IAsyncSigner
{
/// <summary>
/// Sign a single transaction.
/// Sign a group of transactions.
/// </summary>
/// <param name="txn">The transaction to sign.</param>
/// <typeparam name="T">The type of the transaction.</typeparam>
/// <returns>Transaction with signature if it was signed.</returns>
UniTask<SignedTxn<T>> SignTxnAsync<T>(T txn) where T : ITransaction, IEquatable<T>;
/// <remarks>
/// Each transaction is expected to have a valid group id already set.
/// </remarks>
/// <param name="txns">The transactions to sign.</param>
/// <param name="txnsToSign">Indexes of the transactions this signer should sign.</param>
/// <param name="cancellationToken">Provide an optional cancellation token to interrupt signing.</param>
/// <typeparam name="T">The type of the transactions.</typeparam>
/// <returns>An array of transactions with signatures. If the transaction at a given index was not signed, that signed transaction will have no signature.</returns>
UniTask<SignedTxn<T>[]> SignTxnsAsync<T>(
T[] txns,
int[] txnsToSign,
CancellationToken cancellationToken = default
)
where T : ITransaction, IEquatable<T>;
}

public interface IAsyncSignerWithProgress : IAsyncSigner
{
/// <summary>
/// Sign a group of transactions.
/// </summary>
/// <remarks>
/// Each transaction is expected to have a valid group id already set.
/// </remarks>
/// <param name="txns">The transactions to sign.</param>
/// <param name="txnsToSign">Indexes of the transactions this signer should sign.</param>
/// <param name="progress">A progress token that can be used to periodically check the progress.</param>
/// <param name="cancellationToken">Provide an optional cancellation token to interrupt signing.</param>
/// <typeparam name="T">The type of the transactions.</typeparam>
/// <returns>An array of transactions with signatures. If the transaction at a given index was not signed, that signed transaction will have no signature.</returns>
UniTask<SignedTxn<T>[]> SignTxnsAsync<T>(T[] txns) where T : ITransaction, IEquatable<T>;
UniTask<SignedTxn<T>[]> SignTxnsAsync<T, TProgress>(
T[] txns,
int[] txnsToSign,
TProgress progress,
CancellationToken cancellationToken = default
)
where T : ITransaction, IEquatable<T>
where TProgress : IProgress<T>;
}
}

0 comments on commit a8fbe0b

Please sign in to comment.