-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCTAddress.cs
52 lines (44 loc) · 1.6 KB
/
FCTAddress.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using FactomSharp.Factomd;
using FactomSharp.Factomd.API;
namespace FactomSharp
{
public class FCTAddress
{
public FactomdRestClient FactomD { get; private set; }
public string Public { get; private set; }
public string Secret { get; private set; }
public decimal LastBalance { get; set; }
/// <summary>
/// Func used for the Sign method.
/// </summary>
/// <value>Data to sign.</value>
public Func<byte[],byte[]> SignFunction { get; set; }
public FCTAddress(FactomdRestClient factomd, string publicAddress, string secretAddress = null)
{
Secret = secretAddress;
Public = publicAddress;
FactomD = factomd;
SignFunction = (data) =>
{
return Chaos.NaCl.Ed25519.Sign(data,FactomUtils.GetCombinedKey(Secret.FactomBase58ToBytes(),Public.FactomBase58ToBytes()));
};
}
public decimal GetBalance()
{
var balance = new FactoidBalance(FactomD);
balance.Run(Public);
return LastBalance = balance.Balance;
}
/// <summary>
/// Sign the specified data, using the SignFunction
/// </summary>
/// <returns>signature.</returns>
/// <param name="data">Data to sign.</param>
public byte[] Sign (byte[] data)
{
return SignFunction.Invoke(data);
}
}
}