Skip to content

Commit

Permalink
Decouple Spam Functionality from CLI into Throughput Package (#1636)
Browse files Browse the repository at this point in the history
  • Loading branch information
samliok authored Oct 10, 2024
1 parent b8104ac commit 182e023
Show file tree
Hide file tree
Showing 24 changed files with 1,087 additions and 804 deletions.
4 changes: 4 additions & 0 deletions auth/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ const (
ED25519ID uint8 = 0
SECP256R1ID uint8 = 1
BLSID uint8 = 2

ED25519Key = "ed25519"
Secp256r1Key = "secp256r1"
BLSKey = "bls"
)

func Engines() map[uint8]vm.AuthEngine {
Expand Down
44 changes: 44 additions & 0 deletions auth/utils.go
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:
p, err := bls.PrivateKeyFromBytes(pk.Bytes)
if err != nil {
return nil, err
}
return NewBLSFactory(p), nil
default:
return nil, ErrInvalidKeyType
}
}
Loading

0 comments on commit 182e023

Please sign in to comment.