public byte[] SignCompact(uint256 hash) { //throw new NotImplementedException(); var sig = _ECKey.Sign(hash); //Now we have to work backwards to figure out the recId needed to recover the signature. int recId = -1; for (int i = 0; i < 4; i++) { ECKey k = ECKey.RecoverFromSignature(i, sig, hash, IsCompressed); if (k != null && k.GetPubKey(IsCompressed).ToHex() == PubKey.ToHex()) { recId = i; break; } } if (recId == -1) { throw new InvalidOperationException("Could not construct a recoverable key. This should never happen."); } int headerByte = recId + 27 + (IsCompressed ? 4 : 0); byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S sigData[0] = (byte)headerByte; Array.Copy(Utils.BigIntegerToBytes(sig.R, 32), 0, sigData, 1, 32); Array.Copy(Utils.BigIntegerToBytes(sig.S, 32), 0, sigData, 33, 32); return(sigData); }
public override bool Equals(object obj) { PubKey item = obj as PubKey; if (item == null) { return(false); } return(ToHex().Equals(item.ToHex())); }