public static byte[] VerificationScript(this ECDsa key) { byte[] owner = new byte[35]; // version? + key + checksig owner[0] = 0x21; // version? owner[34] = 0xac; // checksig key.Peer().CopyTo(owner, 1); return(owner); }
public static void SignHeader(this IMessage req, ECDsa key, bool debug = false) { RequestMetaHeader meta = null; { // save old meta header if (req is IMeta m) { meta = m.Meta; m.Meta = new RequestMetaHeader(); } } if (req is IVerify v) { if (v.Verify == null) { v.Verify = new RequestVerificationHeader(); } var data = req.SignMessage(key, debug); if (debug) { Console.WriteLine("Hash = {0}", data.ToHex()); } var sign = new Signature { Sign = new Sign { Peer = ByteString.CopyFrom(key.Peer()), Sign_ = ByteString.CopyFrom(data), } }; v.Verify.AddSignature(sign); } { // restore meta header if (req is IMeta m && meta != null) { m.Meta = meta; } } }
public static async Task <Token> EstablishSession(this Channel chan, byte[] oid, uint ttl, ECDsa key, bool debug = false) { var tkn = new Session.SessionClient(chan).Create(); // Prepare Session and Token: var publey = ByteString.CopyFrom(key.Peer()); var owner = ByteString.CopyFrom(key.Address()); var empty = new byte[0]; var token = new Token { OwnerID = owner, LastEpoch = ulong.MaxValue, FirstEpoch = ulong.MinValue, // empty TokenID ID = ByteString.CopyFrom(new byte[16]), // initialize verification header Header = new VerificationHeader { PublicKey = ByteString.CopyFrom(empty), KeySignature = ByteString.CopyFrom(empty), }, }; // Set Owner ID: token.PublicKeys.Add(publey); // Set Object ID: token.ObjectID.Add(ByteString.CopyFrom(oid)); // Send token to node await tkn.RequestStream.WriteAsync(token.PrepareInit(ttl, key, debug)); // Wait to complete request await tkn.ResponseStream.MoveNext(); // Receive session token var response = tkn.ResponseStream.Current; if (!response.Unsigned.IsSame(token)) { throw new Exception("wrong token received"); } // Sign received token token = response.Unsigned; token.Sign(key); // Send signed token await tkn.RequestStream.WriteAsync(token.PrepareSigned(ttl, key, debug));; // Wait to complete request await tkn.ResponseStream.MoveNext(); await tkn.RequestStream.CompleteAsync(); // Store received token: return(tkn.ResponseStream.Current.Result); }