Skip to content

Commit

Permalink
Added ticket signature reference script
Browse files Browse the repository at this point in the history
  • Loading branch information
dominicletz committed Sep 18, 2024
1 parent 8e0f142 commit 11614fa
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions scripts/ticket_reference.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Description: This script is used to generate a ticket for the device to connect to the server.
# Run with:
# `mix run scripts/ticket_reference.exs`

defmodule TicketReference do
alias DiodeClient.{Base16, Hash, Rlp, TicketV2, Wallet}
import TicketV2

def run() do
device_wallet =
Wallet.from_privkey(
Base16.decode("0x7336f02f2bac8fb693a96848f6e70f0da7b474193b6dd63c76478ba92e982025")
)

server_wallet =
Wallet.from_pubkey(
Base16.decode("0x02a49e15dc55dbb6a6756b695b508002c7cab42429ab826ee6e07ad5109655204c")
)

tck =
ticketv2(
server_id: Wallet.address!(server_wallet),
epoch: 666,
chain_id: 1284,
total_connections: 1,
total_bytes: 128_000,
local_address: "test",
fleet_contract: DiodeClient.Base16.decode("0x8aFe08d333f785C818199a5bdc7A52ac6Ffc492A")
)

IO.inspect(tck, label: "Ticket Data")
IO.inspect(TicketV2.device_blob(tck), label: "Device Blob")
IO.inspect(Hash.keccak_256(TicketV2.device_blob(tck)), label: "Device Blob Digest")
tck = TicketV2.device_sign(tck, Wallet.privkey!(device_wallet))
IO.inspect(TicketV2.device_signature(tck), label: "Device Signature")
IO.inspect(TicketV2.message(tck), label: "Ticket Message")

request_id = <<71, 76, 30, 165>>
msg = Rlp.encode!([request_id, TicketV2.message(tck)])
IO.inspect(msg, label: "Ticket Request Package")

end
end

TicketReference.run()

0 comments on commit 11614fa

Please sign in to comment.