public static SignData Unpack(System.IO.Stream stream) { SignData signData = new SignData(); //read addressScript var buflenaddressScript = new byte[2]; stream.Read(buflenaddressScript, 0, 2); UInt16 lenaddressScript = BitConverter.ToUInt16(buflenaddressScript, 0); signData.addressScript = new byte[lenaddressScript]; stream.Read(signData.addressScript, 0, lenaddressScript); //read signScript var buflensignScript = new byte[2]; stream.Read(buflensignScript, 0, 2); UInt16 lensignScript = BitConverter.ToUInt16(buflensignScript, 0); signData.signScript = new byte[lensignScript]; stream.Read(signData.signScript, 0, lensignScript); var pcount = stream.ReadByte(); for (var i = 0; i < pcount; i++) { var keylen = stream.ReadByte(); var keybuf = new byte[keylen]; stream.Read(keybuf, 0, keylen); var key = System.Text.Encoding.UTF8.GetString(keybuf); var datalenbuf = new byte[4]; stream.Read(datalenbuf, 0, 4); var datalen = BitConverter.ToUInt32(datalenbuf, 0); var value = new byte[datalen]; stream.Read(value, 0, (int)datalen); signData.extData[key] = value; } return signData; }
public static SignData FromRaw(byte[] data) { using (System.IO.MemoryStream ms = new System.IO.MemoryStream(data)) { return SignData.Unpack(ms); } }
public static NetMessage CreateSendMsg(byte[] tasksrcdata, SignData signdata) { var msg = Allpet.DB.SDK.NetMessage.Create("_db.write"); msg.Params["taskdata"] = tasksrcdata; msg.Params["signdata"] = signdata.ToBytes(); return(msg); }
public static SignData Sign(byte[] prikey, byte[] srcdata) { var pubkey = ThinNeo.Helper_NEO.GetPublicKey_FromPrivateKey(prikey); SignData sdata = new SignData(); sdata.addressScript = ThinNeo.Helper_NEO.GetAddressScript_FromPublicKey(pubkey); var signdata = ThinNeo.Helper_NEO.Sign(srcdata, prikey); sdata.signScript = MakePushScript(signdata); return sdata; }
public static message Post_write(this WebsocketBase socket, byte[] tasksrcdata, SignData signdata) { var msg = CreateSendMsg(tasksrcdata, signdata); var msgrecv = socket.PostMsg(msg); var s = PraseRecvMsg(msgrecv); return(s); }