-
Notifications
You must be signed in to change notification settings - Fork 0
/
ECAddress.cs
66 lines (54 loc) · 1.98 KB
/
ECAddress.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using FactomSharp.Factomd;
using FactomSharp.Factomd.API;
namespace FactomSharp
{
public class ECAddress
{
public FactomdRestClient FactomD { get; private set;}
public string Public { get; private set; }
public string Secret { get; private set; }
public long LastBalance { get; set; }
/// <summary>
/// Func used for the Sign method.
/// </summary>
/// <value>Data to sign.</value>
public Func<byte[],byte[]> SignFunction { get; set; }
public ECAddress(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 ECAddress(FactomdRestClient factomd, string publicAddress, Func<byte[],byte[]> signFunction)
{
Public = publicAddress;
FactomD = factomd;
SignFunction = signFunction;
}
public long GetBalance()
{
var balance = new EntryCreditBalance(FactomD);
balance.Run(Public);
return LastBalance = balance.Balance;
}
public decimal? GetEntryCreditRate()
{
var ecrate = new EntryCreditRate(FactomD);
return ecrate.Run();
}
/// <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);
}
}
}