awseoa

package module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2021 License: MIT Imports: 16 Imported by: 0

README

AWS Managed EOA

AWS Managed EOA is an Ethereum EOA(Externally Owned Account) using Asymmetric Keys of AWS Key Management Service.

Now aws-sdk-go-v2 is supported!.

Using commad line

$ go install github.com/rmanzoku/go-awseoa/cmd/awseoa

$ export AWS_REGION=YOUR_REGION
$ export AWS_PROFILE=YOUR_PROFILE
$ awseoa list
# list keys

$ awseoa new
# create new key and set alias as address

Example for sending Ether v2

package main

import (
	"context"
	"fmt"
	"math/big"
	"os"

	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/kms"
	"github.com/ethereum/go-ethereum/accounts/abi/bind"
	"github.com/ethereum/go-ethereum/common"
	"github.com/ethereum/go-ethereum/core/types"
	"github.com/ethereum/go-ethereum/ethclient"
	"github.com/rmanzoku/go-awseoa"
)

var (
	rpc   = os.Getenv("RPC")
	to    = common.HexToAddress("0xd868711BD9a2C6F1548F5f4737f71DA67d821090")
	keyID = os.Getenv("KEYID")
)

func main() {
	ctx := context.TODO()
	cfg, err := config.LoadDefaultConfig(ctx)
	if err != nil {
		panic(err)
	}
	svc := kms.NewFromConfig(cfg)

	ethcli, _ := ethclient.Dial(rpc)
	chainID, err := ethcli.NetworkID(ctx)
	if err != nil {
		panic(err)
	}

	topts, _ := awseoa.NewKMSTransactor(svc, keyID, chainID)
	topts.GasPrice, _ = new(big.Int).SetString("1000000000", 10)
	topts.Context = context.TODO()

	amount, _ := new(big.Int).SetString("1000000000000", 10)

	tx, err := sendEther(ethcli, topts, to, amount)
	if err != nil {
		panic(err)
	}

	fmt.Println(tx.Hash().String())
}

func sendEther(client *ethclient.Client, transactOpts *bind.TransactOpts, to common.Address, amount *big.Int) (*types.Transaction, error) {
	ctx := transactOpts.Context
	nonce, err := client.NonceAt(ctx, transactOpts.From, nil)
	if err != nil {
		return nil, err
	}
	tx := types.NewTransaction(nonce, to, amount, 21000, transactOpts.GasPrice, nil)

	tx, err = transactOpts.Signer(transactOpts.From, tx)
	if err != nil {
		return nil, err
	}

	return tx, client.SendTransaction(transactOpts.Context, tx)
}

Same concept

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewKMSTransactor

func NewKMSTransactor(svc *kms.Client, id string, chainID *big.Int) (*bind.TransactOpts, error)

func SendEther added in v0.1.1

func SendEther(client *ethclient.Client, transactOpts *bind.TransactOpts, to common.Address, amount *big.Int) (*types.Transaction, error)

Types

type Signer

type Signer struct {
	*kms.Client
	ID string
	// contains filtered or unexported fields
}

func CreateSigner

func CreateSigner(svc *kms.Client, chainID *big.Int) (*Signer, error)

func NewSigner

func NewSigner(svc *kms.Client, id string, chainID *big.Int) (*Signer, error)

func (Signer) Address

func (s Signer) Address() common.Address

func (Signer) EthereumSign

func (s Signer) EthereumSign(msg []byte) (signature []byte, err error)

func (Signer) Pubkey

func (s Signer) Pubkey() ([]byte, error)

func (Signer) SetAlias

func (s Signer) SetAlias(alias string) error

func (Signer) SignDigest

func (s Signer) SignDigest(digest []byte) (signature []byte, err error)

func (Signer) TransactOpts

func (s Signer) TransactOpts() (*bind.TransactOpts, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL