suisigner

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2025 License: Apache-2.0 Imports: 18 Imported by: 4

Documentation

Index

Examples

Constants

View Source
const (
	DerivationPathEd25519   = `m/44'/784'/0'/0'/0'`
	DerivationPathSecp256k1 = `m/54'/784'/0'/0/0`
)
View Source
const (
	FirstHardenedIndex = uint32(0x80000000)
)

Variables

View Source
var (
	ErrInvalidPath        = errors.New("invalid derivation path")
	ErrNoPublicDerivation = errors.New("no public derivation for ed25519")
)
View Source
var (
	TEST_MNEMONIC = "ordinary cry margin host traffic bulb start zone mimic wage fossil eight diagram clay say remove add atom"
	TEST_SEED     = []byte{4, 66, 186, 181, 112, 134, 111, 192, 149, 13, 68, 115, 67, 195, 58, 59, 33, 20, 200, 10, 150, 185, 145, 3, 106, 160, 105, 37, 4, 153, 172, 103, 69, 228, 114, 210, 176, 182, 208, 21, 252, 59, 50, 82, 135, 160, 1, 131, 156, 104, 159, 240, 183, 20, 250, 216, 26, 228, 91, 220, 15, 222, 75, 91}
	TEST_ADDRESS  = sui.MustAddressFromHex("0x1a02d61c6434b4d0ff252a880c04050b5f27c8b574026c98dd72268865c0ede5")
)

Functions

func MessageWithIntent

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

func SigningDigest added in v0.1.6

func SigningDigest(msg []byte, intent Intent) []byte

it is the signing_digest() interface in Sui Rust SDK

Types

type AppId

type AppId struct {
	Sui     *sui.EmptyEnum
	Narwhal *sui.EmptyEnum
}

func (AppId) IsBcsEnum

func (a AppId) IsBcsEnum()

type Ed25519SuiSignature

type Ed25519SuiSignature struct {
	Signature [suicrypto.SizeSuiSignatureEd25519]byte
}

func NewEd25519SuiSignature

func NewEd25519SuiSignature(s *suicrypto.KeypairEd25519, data []byte) (*Ed25519SuiSignature, 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 IntentPersonalMessage added in v0.1.6

func IntentPersonalMessage() Intent

func IntentTransaction added in v0.1.6

func IntentTransaction() Intent

func (*Intent) Bytes

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

type IntentScope

type IntentScope struct {
	TransactionData         *sui.EmptyEnum // Used for a user signature on a transaction data.
	TransactionEffects      *sui.EmptyEnum // Used for an authority signature on transaction effects.
	CheckpointSummary       *sui.EmptyEnum // Used for an authority signature on a checkpoint summary.
	PersonalMessage         *sui.EmptyEnum // Used for a user signature on a personal message.
	SenderSignedTransaction *sui.EmptyEnum // Used for an authority signature on a user signed transaction.
	ProofOfPossession       *sui.EmptyEnum // Used as a signature representing an authority's proof of possession of its authority protocol key.
	HeaderDigest            *sui.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 *sui.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 Secp256k1SuiSignature

type Secp256k1SuiSignature struct {
	Signature [suicrypto.SizeSuiSignatureSecp256k1]byte
}

func NewSecp256k1SuiSignature added in v0.1.4

func NewSecp256k1SuiSignature(s *suicrypto.KeypairSecp256k1, data []byte) (*Secp256k1SuiSignature, error)

type Secp256r1SuiSignature

type Secp256r1SuiSignature struct {
	Signature [suicrypto.SizeSuiSignatureSecp256r1]byte
}

func NewSecp256r1SuiSignature added in v0.1.4

func NewSecp256r1SuiSignature(s *suicrypto.KeypairSecp256r1, data []byte) (*Secp256r1SuiSignature, error)

type Signature

func (Signature) Bytes

func (s Signature) Bytes() []byte

func (Signature) MarshalJSON

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

func (*Signature) UnmarshalJSON

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

type Signer

type Signer struct {
	KeypairEd25519   *suicrypto.KeypairEd25519
	KeypairSecp256k1 *suicrypto.KeypairSecp256k1
	KeypairSecp256r1 *suicrypto.KeypairSecp256r1
	Address          *sui.Address
}

FIXME support more than ed25519

Example
package main

import (
	"encoding/hex"
	"fmt"

	"github.com/pattonkan/sui-go/suisigner"
	"github.com/pattonkan/sui-go/suisigner/suicrypto"
)

func main() {
	// Create a suisigner.Signer with mnemonic
	mnemonic := "ordinary cry margin host traffic bulb start zone mimic wage fossil eight diagram clay say remove add atom"
	signer1, _ := suisigner.NewSignerWithMnemonic(mnemonic, suicrypto.KeySchemeFlagDefault)
	fmt.Printf("address   : %v\n", signer1.Address)

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

	// Get private key, public key, address
	fmt.Printf("privateKey: %x\n", signer2.PrivateKeyBytes())
	fmt.Printf("publicKey : %x\n", signer2.PublicKeyBytes())
	fmt.Printf("address   : %v\n", signer2.Address)

}
Output:

address   : 0x1a02d61c6434b4d0ff252a880c04050b5f27c8b574026c98dd72268865c0ede5
privateKey: 4ec5a9eefc0bb86027a6f3ba718793c813505acc25ed09447caf6a069accdd4b9342fa65507f5cf61f1b8fb3b94a5aa80fa9b2e2c68963e30d68a2660a50c57e
publicKey : 9342fa65507f5cf61f1b8fb3b94a5aa80fa9b2e2c68963e30d68a2660a50c57e
address   : 0x579a9ef1ca86431df106abb86f1f129806cd336b28f5bc17d16ce247aa3a0623

func NewSigner

func NewSigner(seed []byte, flag suicrypto.KeySchemeFlag) *Signer

func NewSignerByIndex

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

there are only 256 different signers can be generated

func NewSignerWithMnemonic

func NewSignerWithMnemonic(mnemonic string, flag suicrypto.KeySchemeFlag) (*Signer, error)

generate keypair (signer) with mnemonic which is referring the Sui 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();

func (*Signer) PrivateKeyBytes added in v0.1.6

func (s *Signer) PrivateKeyBytes() []byte

func (*Signer) PublicKeyBytes added in v0.1.6

func (s *Signer) PublicKeyBytes() []byte

func (*Signer) Sign

func (s *Signer) Sign(data []byte) (*Signature, error)

Signer implements the UserSignature trait in Sui Rust SDK refer sui-rust-sdk/crates/sui-sdk-types/src/crypto/signature.rs

pub enum UserSignature {
    Simple(SimpleSignature),
    Multisig(MultisigAggregatedSignature),
    ZkLogin(Box<ZkLoginAuthenticator>),
    Passkey(PasskeyAuthenticator),
}

SimpleSignature include Ed25519, Secp256k1, and Secp256r1 signatures

func (*Signer) SignDigest added in v0.1.4

func (a *Signer) SignDigest(msg []byte, intent Intent) (*Signature, error)

SignDigest is a general implementation of sui-rust-sdk's `fn sign_transaction(&self, transaction: &Transaction)` and fn sign_personal_message(&self, message: &PersonalMessage<'_>,) These two functions are the same except the contents of Intent are different.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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