Esempio n. 1
0
    /// <summary>
    /// Implement the signing algorithm.  In the case of an Ed25519
    /// it will use the private key to sign the transaction and
    /// return immediately.  In the case of the callback method, it
    /// will pass the invoice to the async method and async await
    /// for the method to return.
    /// </summary>
    /// <param name="invoice">
    /// The information for the transaction, including the Transaction
    /// ID, Memo and serialized bytes of the crypto transfers and other
    /// embedded information making up the transaction.
    /// </param>
    /// <returns></returns>
    async Task ISignatory.SignAsync(IInvoice invoice)
    {
        switch (_type)
        {
        case Type.Ed25519:
            Ed25519Util.Sign(invoice, (Ed25519PrivateKeyParameters)_data);
            break;

        case Type.ECDSASecp256K1:
            EcdsaSecp256k1Util.Sign(invoice, (ECPrivateKeyParameters)_data);
            break;

        case Type.List:
            foreach (ISignatory signer in (Signatory[])_data)
            {
                await signer.SignAsync(invoice).ConfigureAwait(false);
            }
            break;

        case Type.Callback:
            await((Func <IInvoice, Task>)_data)(invoice).ConfigureAwait(false);
            break;

        case Type.Pending:
            // This will be called to sign the to-be-scheduled
            // transaction. In this context, we do nothing.
            break;

        default:
            throw new InvalidOperationException("Not a presently supported Signatory key type, please consider the callback signatory as an alternative.");
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Create a signatory having a private key of the specified type.
    /// </summary>
    /// <param name="type">
    /// The type of private key this <code>Signatory</code> should use to
    /// sign transactions.
    /// </param>
    /// <param name="privateKey">
    /// The bytes of a private key corresponding to the specified type.
    /// </param>
    /// <remarks>
    /// At this time, the library only supports Ed25519 keys, any other
    /// key type will result in an exception.  This is why this method
    /// is marked as <code>internal</code> at the moment.  When the library
    /// can support other key types, it will make sense to make this public.
    /// </remarks>
    /// <exception cref="ArgumentOutOfRangeException">
    /// If any key type other than Ed25519 is used.
    /// </exception>
    internal Signatory(KeyType type, ReadOnlyMemory <byte> privateKey)
    {
        switch (type)
        {
        case KeyType.Ed25519:
            _type = Type.Ed25519;
            _data = Ed25519Util.PrivateParamsFromDerOrRaw(privateKey);
            break;

        case KeyType.ECDSASecp256K1:
            _type = Type.ECDSASecp256K1;
            _data = EcdsaSecp256k1Util.PrivateParamsFromDerOrRaw(privateKey);
            break;

        case KeyType.List:
            throw new ArgumentOutOfRangeException(nameof(type), "Only signatories representing a single key are supported with this constructor, please use the list constructor instead.");

        default:
            throw new ArgumentOutOfRangeException(nameof(type), "Not a presently supported Signatory key type, please consider the callback signatory as an alternative.");
        }
    }