iotasigner

package
v2.0.3-0...-34c6bb6 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2025 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	PublicKeyLengthEd25519   = 32
	PublicKeyLengthSecp256k1 = 33
)
View Source
const (
	DefaultAccountAddressLength = 16
	AccountAddress20Length      = 20
	AccountAddress32Length      = 32
)
View Source
const (
	FirstHardenedIndex = uint32(0x80000000)
)
View Source
const (
	SizeEd25519Signature = ed25519.PublicKeySize + ed25519.SignatureSize + 1
)

Variables

View Source
var (
	ErrInvalidPath        = errors.New("invalid derivation path")
	ErrNoPublicDerivation = errors.New("no public derivation for ed25519")
)
View Source
var KeySchemeFlagDefault = KeySchemeFlagEd25519

Functions

func BuildBip32Path

func BuildBip32Path(signatureFlag SignatureFlag, coinType Bip32CoinType, accountIndex uint32) (string, error)

func MessageWithIntent

func MessageWithIntent(intent Intent, message []byte) []byte

Types

type AppID

type AppID struct {
	Iota    *serialization.EmptyEnum
	Narwhal *serialization.EmptyEnum
}

func (AppID) IsBcsEnum

func (a AppID) IsBcsEnum()

type Bip32CoinType

type Bip32CoinType int
const (
	// testnet/alphanet uses COIN_TYPE = 1
	TestnetCoinType Bip32CoinType = 1
	// IOTA coin type <https://github.com/satoshilabs/slips/blob/master/slip-0044.md>
	IotaCoinType Bip32CoinType = 4218
)

type Ed25519Signature

type Ed25519Signature struct {
	Signature [SizeEd25519Signature]byte
}

func NewEd25519Signature

func NewEd25519Signature(publicKey ed25519.PublicKey, signedMessage []byte) *Ed25519Signature

type InMemorySigner

type InMemorySigner struct {
	// contains filtered or unexported fields
}

func NewSigner

func NewSigner(seed []byte, flag KeySchemeFlag) *InMemorySigner

func (*InMemorySigner) Address

func (s *InMemorySigner) Address() *iotago.Address

func (*InMemorySigner) PrivateKey

func (s *InMemorySigner) PrivateKey() []byte

func (*InMemorySigner) PublicKey

func (s *InMemorySigner) PublicKey() []byte

func (*InMemorySigner) Sign

func (s *InMemorySigner) Sign(msg []byte) (signature *Signature, err error)

func (*InMemorySigner) SignTransactionBlock

func (s *InMemorySigner) SignTransactionBlock(txnBytes []byte, intent Intent) (*Signature, error)

type Intent

type Intent struct {
	// the type of the IntentMessage
	Scope IntentScope
	// version the network supports
	Version IntentVersion
	// application that the signature refers to
	AppID AppID
}

func DefaultIntent

func DefaultIntent() Intent

func (*Intent) Bytes

func (i *Intent) Bytes() []byte

type IntentScope

type IntentScope struct {
	TransactionData         *serialization.EmptyEnum // Used for a user signature on a transaction data.
	TransactionEffects      *serialization.EmptyEnum // Used for an authority signature on transaction effects.
	CheckpointSummary       *serialization.EmptyEnum // Used for an authority signature on a checkpoint summary.
	PersonalMessage         *serialization.EmptyEnum // Used for a user signature on a personal message.
	SenderSignedTransaction *serialization.EmptyEnum // Used for an authority signature on a user signed transaction.
	ProofOfPossession       *serialization.EmptyEnum // Used as a signature representing an authority's proof of possession of its authority protocol key.
	HeaderDigest            *serialization.EmptyEnum // Used for narwhal authority signature on header digest.
}

the type of the IntentMessage

func (IntentScope) IsBcsEnum

func (i IntentScope) IsBcsEnum()

type IntentVersion

type IntentVersion struct {
	V0 *serialization.EmptyEnum
}

func (IntentVersion) IsBcsEnum

func (i IntentVersion) IsBcsEnum()

type Key

type Key struct {
	Key       []byte
	ChainCode []byte
}

func DeriveForPath

func DeriveForPath(path string, seed []byte) (*Key, error)

DeriveForPath derives key for a path in BIP-44 format and a seed. Ed25119 derivation operated on hardened keys only.

func NewMasterKey

func NewMasterKey(seed []byte) (*Key, error)

NewMasterKey generates a new master key from seed.

func (*Key) Derive

func (k *Key) Derive(i uint32) (*Key, error)

func (*Key) PublicKey

func (k *Key) PublicKey() ([]byte, error)

PublicKey returns public key for a derived private key.

func (*Key) RawSeed

func (k *Key) RawSeed() [32]byte

RawSeed returns raw seed bytes

type KeySchemeFlag

type KeySchemeFlag byte
const (
	KeySchemeFlagEd25519 KeySchemeFlag = iota
	KeySchemeFlagSecp256k1
	KeySchemeFlagSecp256r1
	KeySchemeFlagMultiSig
	KeySchemeFlagBLS12381
	KeySchemeFlagZkLoginAuthenticator

	KeySchemeFlagError = math.MaxUint8
)

func (KeySchemeFlag) Byte

func (k KeySchemeFlag) Byte() byte

type KeypairEd25519

type KeypairEd25519 struct {
	PriKey ed25519.PrivateKey
	PubKey ed25519.PublicKey
}

func NewKeypairEd25519

func NewKeypairEd25519(prikey ed25519.PrivateKey, pubkey ed25519.PublicKey) *KeypairEd25519

type Secp256k1Signature

type Secp256k1Signature struct {
	Signature []byte // secp256k1.pubKey + Secp256k1Signature + 1
}

type Secp256r1Signature

type Secp256r1Signature struct {
	Signature []byte // secp256k1.pubKey + Secp256k1Signature + 1
}

type Signature

func (Signature) Bytes

func (s Signature) Bytes() []byte

func (Signature) IsBcsEnum

func (s Signature) IsBcsEnum()

func (Signature) MarshalJSON

func (s Signature) MarshalJSON() ([]byte, error)

func (*Signature) UnmarshalJSON

func (s *Signature) UnmarshalJSON(data []byte) error

type SignatureFlag

type SignatureFlag int
const (
	SignatureFlagEd25519   SignatureFlag = 0x0
	SignatureFlagSecp256k1 SignatureFlag = 0x1
)

type SignedTransaction

type SignedTransaction struct {
	Data       *iotago.TransactionData
	Signatures []*Signature
}

func NewSignedTransaction

func NewSignedTransaction(unsignedTx *iotago.TransactionData, signature *Signature) *SignedTransaction

func (*SignedTransaction) Digest

func (st *SignedTransaction) Digest() (*iotago.Digest, error)

func (*SignedTransaction) FindInputByID

func (st *SignedTransaction) FindInputByID(id iotago.ObjectID) *iotago.ObjectRef

We use it to find the consumed anchor ref from the TX.

type Signer

type Signer interface {
	Address() *iotago.Address
	Sign(msg []byte) (signature *Signature, err error)
	SignTransactionBlock(txnBytes []byte, intent Intent) (*Signature, error)
}
Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/iotaledger/wasp/v2/clients/iota-go/iotasigner"

	testcommon "github.com/iotaledger/wasp/v2/clients/iota-go/test_common"
)

func main() {
	// Create a iotasigner.InMemorySigner with mnemonic
	signer1, _ := iotasigner.NewSignerWithMnemonic(testcommon.TestMnemonic, iotasigner.KeySchemeFlagDefault)
	fmt.Printf("address   : %v\n", signer1.Address())

	// Create iotasigner.InMemorySigner with private key
	privKey, _ := hex.DecodeString("4ec5a9eefc0bb86027a6f3ba718793c813505acc25ed09447caf6a069accdd4b")
	signer2 := iotasigner.NewSigner(privKey, iotasigner.KeySchemeFlagDefault)

	// Get private key, public key, address
	fmt.Printf("privateKey: %x\n", signer2.PrivateKey()[:32])
	fmt.Printf("publicKey : %x\n", signer2.PublicKey())
	fmt.Printf("address   : %v\n", signer2.Address())

}
Output:

address   : 0x786dff8a4ee13d45b502c8f22f398e3517e6ec78aa4ae564c348acb07fad7f50
privateKey: 4ec5a9eefc0bb86027a6f3ba718793c813505acc25ed09447caf6a069accdd4b
publicKey : 9342fa65507f5cf61f1b8fb3b94a5aa80fa9b2e2c68963e30d68a2660a50c57e
address   : 0x07e542f628f0e48950578aaff3e0c0566b6dccfc7cc248d9941308b47e934e6a

func NewSignerByIndex

func NewSignerByIndex(seed []byte, flag KeySchemeFlag, index int) Signer

there are only 256 different signers can be generated

func NewSignerWithMnemonic

func NewSignerWithMnemonic(mnemonic string, flag KeySchemeFlag) (Signer, error)

generate keypair (signer) with mnemonic which is referring the Iota monorepo in the following code

let phrase = "asset pink record dawn hundred sure various crime client enforce carbon blossom"; let mut keystore = Keystore::from(InMemKeystore::new_insecure_for_tests(0)); let generated_address = keystore.import_from_mnemonic(&phrase, SignatureScheme::ED25519, None, None).unwrap();

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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