-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathPendingActivationState.cs
74 lines (62 loc) · 2.1 KB
/
PendingActivationState.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
67
68
69
70
71
72
73
74
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using Bencodex;
using Bencodex.Types;
using Libplanet;
using Libplanet.Crypto;
using Nekoyume.Action;
namespace Nekoyume.Model.State
{
[Serializable]
public class PendingActivationState : State, ISerializable
{
private static Address BaseAddress = Addresses.PendingActivation;
public byte[] Nonce { get; }
public PublicKey PublicKey { get; }
public PendingActivationState(byte[] nonce, PublicKey publicKey)
: base(DeriveAddress(nonce, publicKey))
{
Nonce = nonce;
PublicKey = publicKey;
}
internal static Address DeriveAddress(byte[] nonce, PublicKey publicKey)
{
return BaseAddress.Derive(nonce.Concat(publicKey.Format(true)).ToArray());
}
public PendingActivationState(Dictionary serialized)
: base(serialized)
{
Nonce = (Binary)serialized["nonce"];
PublicKey = serialized["public_key"].ToPublicKey();
}
protected PendingActivationState(SerializationInfo info, StreamingContext context)
: this((Dictionary)new Codec().Decode((byte[])info.GetValue("serialized", typeof(byte[]))))
{
}
public override IValue Serialize()
{
var values = new Dictionary<IKey, IValue>
{
[(Text)"nonce"] = (Binary)Nonce,
[(Text)"public_key"] = PublicKey.Serialize(),
};
#pragma warning disable LAA1002
return new Dictionary(values.Union((Dictionary)base.Serialize()));
#pragma warning restore LAA1002
}
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue("serialized", new Codec().Encode(Serialize()));
}
public bool Verify(ActivateAccount action)
{
return Verify(action.Signature);
}
public bool Verify(byte[] signature)
{
return PublicKey.Verify(Nonce, signature);
}
}
}