Documentation
¶
Index ¶
- Constants
- Variables
- func MessageWithIntent(intent Intent, message []byte) []byte
- func SigningDigest(msg []byte, intent Intent) []byte
- type AppId
- type Ed25519SuiSignature
- type Intent
- type IntentScope
- type IntentVersion
- type Key
- type Secp256k1SuiSignature
- type Secp256r1SuiSignature
- type Signature
- type Signer
Examples ¶
Constants ¶
const ( DerivationPathEd25519 = `m/44'/784'/0'/0'/0'` DerivationPathSecp256k1 = `m/54'/784'/0'/0/0` )
const (
FirstHardenedIndex = uint32(0x80000000)
)
Variables ¶
var ( ErrInvalidPath = errors.New("invalid derivation path") ErrNoPublicDerivation = errors.New("no public derivation for ed25519") )
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 SigningDigest ¶ added in v0.1.6
it is the signing_digest() interface in Sui Rust SDK
Types ¶
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
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 ¶
func (IntentVersion) IsBcsEnum ¶
func (i IntentVersion) IsBcsEnum()
type Key ¶
func DeriveForPath ¶
DeriveForPath derives key for a path in BIP-44 format and a seed. Ed25119 derivation operated on hardened keys only.
func NewMasterKey ¶
NewMasterKey generates a new master key from seed.
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 ¶
type Signature struct {
*Ed25519SuiSignature
*Secp256k1SuiSignature
*Secp256r1SuiSignature
}
func (Signature) MarshalJSON ¶
func (*Signature) UnmarshalJSON ¶
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 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 (*Signer) PublicKeyBytes ¶ added in v0.1.6
func (*Signer) Sign ¶
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
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.