Skip to content

Commit

Permalink
rhp4: add token helper
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Dec 17, 2024
1 parent 1615b56 commit 27dae15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/add_helper_for_generating_account_tokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: minor
---

# Add helper for generating account tokens
12 changes: 12 additions & 0 deletions rhp/v4/rhp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down

0 comments on commit 27dae15

Please sign in to comment.