-
Notifications
You must be signed in to change notification settings - Fork 118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Decouple Spam Functionality from CLI into Throughput Package #1636
Changes from 32 commits
a93ecf1
56cf0b7
9d8a718
fa42146
2e878a3
781b29a
596d48c
0aefe39
39b682c
f99c260
e18d659
ba476cd
0ef4f90
6ae8f3c
7db9c3e
7dfde55
bc72196
deb18b4
e1328bc
974ed4d
787fff8
bbdc3f4
eda116d
8ef31af
1add5d0
0249c6a
ccdcd7c
4448232
7fef415
b9f1074
d00518b
9e30569
02ba233
c391936
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (C) 2024, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package auth | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/ava-labs/hypersdk/chain" | ||
"github.com/ava-labs/hypersdk/codec" | ||
"github.com/ava-labs/hypersdk/crypto/bls" | ||
"github.com/ava-labs/hypersdk/crypto/ed25519" | ||
"github.com/ava-labs/hypersdk/crypto/secp256r1" | ||
) | ||
|
||
var ErrInvalidKeyType = errors.New("invalid key type") | ||
|
||
// Used for testing & CLI purposes | ||
type PrivateKey struct { | ||
Address codec.Address | ||
// Bytes is the raw private key bytes | ||
Bytes []byte | ||
} | ||
|
||
// GetFactory returns the [chain.AuthFactory] for a given private key. | ||
// | ||
// A [chain.AuthFactory] signs transactions and provides a unit estimate | ||
// for using a given private key (needed to estimate fees for a transaction). | ||
func GetFactory(pk *PrivateKey) (chain.AuthFactory, error) { | ||
switch pk.Address[0] { | ||
case ED25519ID: | ||
return NewED25519Factory(ed25519.PrivateKey(pk.Bytes)), nil | ||
case SECP256R1ID: | ||
return NewSECP256R1Factory(secp256r1.PrivateKey(pk.Bytes)), nil | ||
case BLSID: | ||
Comment on lines
+30
to
+35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (followup) Could we decouple this from the exact crypto libraries that are available if we are going to move it into the |
||
p, err := bls.PrivateKeyFromBytes(pk.Bytes) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return NewBLSFactory(p), nil | ||
default: | ||
return nil, ErrInvalidKeyType | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was previously in the
SpamHelper
but I think it makes more sense to separate it out and minimize theSpamHelper
interface