Advertisement
osmarks

turtl

Sep 3rd, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. local function a(b,c)local d=fs.open(b,"w")d.write(c)d.close()end;local function e(b)local d=fs.open(b,"r")local c=d.readAll()d.close()return c end;local function f(g)local h=http.get(g)local c=h.readAll()h.close()return c end;local function i(g,d)a(d,f(g))end;i("https://pastebin.com/raw/Sc0DU3rA","ecc.lua");i("https://raw.githubusercontent.com/osmarks/skynet/master/client.lua","skynet.lua")
  2.  
  3. local channel = ... or "turtl"
  4.  
  5. local ecc = require "./ecc"
  6. local e = ecc "ecc"
  7.  
  8. local skynet = require "./skynet"
  9.  
  10. local pub_file, priv_file = "/.nd_pub", "/.nd_priv"
  11.  
  12. local pub, priv
  13. -- If keypair does not exist it is necessary to create one
  14. if not fs.exists(priv_file) then
  15.     pub, priv = e.keypair()
  16.     local f
  17.     local f = fs.open(priv_file, "w")
  18.     f.write(textutils.serialize(priv))
  19.     f.close()
  20.     f = fs.open(pub_file, "w")
  21.     f.write(textutils.serialize(pub))
  22.     f.close()
  23. else
  24.     -- Load existing keypair
  25.     local f = fs.open(priv_file, "r")
  26.     priv = textutils.unserialize(f.readAll())
  27.     f.close()
  28.     pub = e.publicKey(priv)
  29. end
  30.  
  31. parallel.waitForAll(function()
  32.     while true do
  33.         local chan, message = skynet.receive(channel)
  34.         if type(message) == "table" and message.result then
  35.             print(textutils.serialise(message.result))
  36.         end
  37.     end
  38. end, function()
  39.     local history = {}
  40.     while true do
  41.         write "|> "
  42.         local input = read(nil, history)
  43.         table.insert(history, input)
  44.         skynet.send(channel, {
  45.             code = input,
  46.             signature = e.sign(priv, input)
  47.         })
  48.     end
  49. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement