From a8fbe0bbbc7729b07beef1efc7e5d8757db0cd41 Mon Sep 17 00:00:00 2001 From: Jason Elie Bou Kheir <5115126+jasonboukheir@users.noreply.github.com> Date: Sun, 3 Apr 2022 12:41:19 -0700 Subject: [PATCH] feat(signer): update `ISigner` interface to be closer to signer interface 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 --- Runtime/CareBoo.AlgoSdk/Account/Account.cs | 2 - Runtime/CareBoo.AlgoSdk/Account/Signer.cs | 53 ++++++++++++++++------ 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/Runtime/CareBoo.AlgoSdk/Account/Account.cs b/Runtime/CareBoo.AlgoSdk/Account/Account.cs index 261c5f8f4..efb440b4f 100644 --- a/Runtime/CareBoo.AlgoSdk/Account/Account.cs +++ b/Runtime/CareBoo.AlgoSdk/Account/Account.cs @@ -17,8 +17,6 @@ public interface IAccount /// public readonly struct Account : IAccount - , ISigner - , IAsyncSigner { readonly PrivateKey privateKey; diff --git a/Runtime/CareBoo.AlgoSdk/Account/Signer.cs b/Runtime/CareBoo.AlgoSdk/Account/Signer.cs index 01d332908..86e79a90b 100644 --- a/Runtime/CareBoo.AlgoSdk/Account/Signer.cs +++ b/Runtime/CareBoo.AlgoSdk/Account/Signer.cs @@ -1,43 +1,66 @@ using System; +using System.Threading; using Cysharp.Threading.Tasks; namespace AlgoSdk { public interface ISigner { - /// - /// Sign a single transaction. - /// - /// The transaction to sign. - /// The type of the transaction. - /// Transaction with signature if it was signed. - SignedTxn SignTxn(T txn) where T : ITransaction, IEquatable; - /// /// Sign a group of transactions. /// + /// + /// Each transaction is expected to have a valid group id already set. + /// /// The transactions to sign. + /// Indexes of the transactions this signer should sign. /// The type of the transactions. /// An array of transactions with signatures. If the transaction at a given index was not signed, that signed transaction will have no signature. - SignedTxn[] SignTxns(T[] txns) where T : ITransaction, IEquatable; + SignedTxn[] SignTxns(T[] txns, int[] txnsToSign) where T : ITransaction, IEquatable; } public interface IAsyncSigner { /// - /// Sign a single transaction. + /// Sign a group of transactions. /// - /// The transaction to sign. - /// The type of the transaction. - /// Transaction with signature if it was signed. - UniTask> SignTxnAsync(T txn) where T : ITransaction, IEquatable; + /// + /// Each transaction is expected to have a valid group id already set. + /// + /// The transactions to sign. + /// Indexes of the transactions this signer should sign. + /// Provide an optional cancellation token to interrupt signing. + /// The type of the transactions. + /// An array of transactions with signatures. If the transaction at a given index was not signed, that signed transaction will have no signature. + UniTask[]> SignTxnsAsync( + T[] txns, + int[] txnsToSign, + CancellationToken cancellationToken = default + ) + where T : ITransaction, IEquatable; + } + public interface IAsyncSignerWithProgress : IAsyncSigner + { /// /// Sign a group of transactions. /// + /// + /// Each transaction is expected to have a valid group id already set. + /// /// The transactions to sign. + /// Indexes of the transactions this signer should sign. + /// A progress token that can be used to periodically check the progress. + /// Provide an optional cancellation token to interrupt signing. /// The type of the transactions. /// An array of transactions with signatures. If the transaction at a given index was not signed, that signed transaction will have no signature. - UniTask[]> SignTxnsAsync(T[] txns) where T : ITransaction, IEquatable; + UniTask[]> SignTxnsAsync( + T[] txns, + int[] txnsToSign, + TProgress progress, + CancellationToken cancellationToken = default + ) + where T : ITransaction, IEquatable + where TProgress : IProgress; } }