From 27dae155881b0147b1183946f4ed383e0231e373 Mon Sep 17 00:00:00 2001 From: Nate Date: Tue, 17 Dec 2024 06:59:32 -0800 Subject: [PATCH] rhp4: add token helper --- .../add_helper_for_generating_account_tokens.md | 5 +++++ rhp/v4/rhp.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 .changeset/add_helper_for_generating_account_tokens.md diff --git a/.changeset/add_helper_for_generating_account_tokens.md b/.changeset/add_helper_for_generating_account_tokens.md new file mode 100644 index 0000000..404b749 --- /dev/null +++ b/.changeset/add_helper_for_generating_account_tokens.md @@ -0,0 +1,5 @@ +--- +default: minor +--- + +# Add helper for generating account tokens diff --git a/rhp/v4/rhp.go b/rhp/v4/rhp.go index 2fbcd80..dc4dd10 100644 --- a/rhp/v4/rhp.go +++ b/rhp/v4/rhp.go @@ -194,6 +194,18 @@ func (a *Account) UnmarshalText(b []byte) error { return nil } +// Token returns a signed account token authorizing spending from the account on the +// host. +func (a *Account) Token(renterKey types.PrivateKey, hostKey types.PublicKey) AccountToken { + token := AccountToken{ + HostKey: hostKey, + Account: Account(renterKey.PublicKey()), + ValidUntil: time.Now().Add(5 * time.Minute), + } + token.Signature = renterKey.SignHash(token.SigHash()) + return token +} + // An AccountToken authorizes an account action. type AccountToken struct { HostKey types.PublicKey `json:"hostKey"`