Documentation
¶
Index ¶
- Constants
- Variables
- func EncodeSuiPrivateKey(bytes []byte, scheme string) (string, error)
- func GenerateMnemonic() (string, error)
- func IsValidBIP32Path(path string) bool
- func IsValidHardenedPath(path string) bool
- func IsValidPath(path string) bool
- func MessageWithIntent(scope IntentScope, message []byte) []byte
- func MnemonicToSeed(mnemonics string) ([]byte, error)
- func MnemonicToSeedHex(mnemonics string) (string, error)
- func ReadByte(r io.Reader) (byte, int, error)
- func ReplaceDerive(val string) string
- func ToSerializedSignature(input SerializeSignatureInput) (string, error)
- type AppID
- type BaseKeypair
- type BasePublicKey
- func (base *BasePublicKey) Equals(publicKey PublicKey) bool
- func (base *BasePublicKey) SetSelf(pubkey PublicKey)
- func (base *BasePublicKey) ToBase64() string
- func (base *BasePublicKey) ToSuiAddress() string
- func (base *BasePublicKey) ToSuiBytes() []byte
- func (base *BasePublicKey) ToSuiPublicKey() string
- func (base *BasePublicKey) VerifyPersonalMessage(message []byte, signature SerializedSignature) (bool, error)
- func (base *BasePublicKey) VerifyTransactionBlock(transactionBlock []byte, signature SerializedSignature) (bool, error)
- func (base *BasePublicKey) VerifyWithIntent(bs []byte, signature SerializedSignature, intent IntentScope) (bool, error)
- type BaseSigner
- func (signer *BaseSigner) SignPersonalMessage(bs []byte) (*SignatureWithBytes, error)
- func (signer *BaseSigner) SignTransactionBlock(bs []byte) (*SignatureWithBytes, error)
- func (signer *BaseSigner) SignWithIntent(bs []byte, intent IntentScope) (*SignatureWithBytes, error)
- func (signer *BaseSigner) ToSuiAddress() string
- type CompressedSignature
- type Intent
- type IntentScope
- type IntentVersion
- type Key
- type Keypair
- type MultiSigPublicKeyPair
- type MultiSigPublicKeyStruct
- type MultiSigStruct
- type ParsedKeypair
- type PubKeyEnumWeightPair
- type PublicKey
- type SerializeSignatureInput
- type SerializedSignature
- type SerializedSignatureParsedData
- type SignatureFlag
- type SignatureScheme
- type SignatureWithBytes
- type Signer
Constants ¶
const ( // Ed25519PublicKeySize is the size of an Ed25519 public key in bytes. Ed25519PublicKeySize = 32 // Secp256k1PublicKeySize is the size of a Secp256k1 public key in bytes. Secp256k1PublicKeySize = 33 // Secp256r1PublicKeySize is the size of a Secp256r1 public key in bytes. Secp256r1PublicKeySize = 33 )
const ( // Ed25519CURVE is the curve used for Ed25519 key derivation. Ed25519CURVE = "ed25519 seed" // HardenedOffset is the offset used for hardened derivation. HardenedOffset = 0x80000000 )
const ( // PrivateKeySize is the size of a Sui private key in bytes. PrivateKeySize = 32 // SuiPrivateKeyPrefix is the Bech32 prefix for Sui private keys. SuiPrivateKeyPrefix = "suiprivkey" )
Variables ¶
var SignatureFlagToScheme = map[SignatureFlag]SignatureScheme{ 0x00: Ed25519Scheme, 0x01: Secp256k1Scheme, 0x02: Secp256r1Scheme, 0x03: MultiSigScheme, 0x05: ZkLoginScheme, }
SignatureFlagToScheme is a map that associates signature flags with their corresponding signature schemes.
var SignatureSchemeToFlag = map[SignatureScheme]SignatureFlag{ Ed25519Scheme: 0x00, Secp256k1Scheme: 0x01, Secp256r1Scheme: 0x02, MultiSigScheme: 0x03, ZkLoginScheme: 0x05, }
SignatureSchemeToFlag is a map that associates signature schemes with their corresponding flags.
var SignatureSchemeToSize = map[SignatureScheme]int{ Ed25519Scheme: 32, Secp256k1Scheme: 33, Secp256r1Scheme: 33, }
SignatureSchemeToSize is a map that associates signature schemes with their corresponding signature sizes in bytes.
Functions ¶
func EncodeSuiPrivateKey ¶
EncodeSuiPrivateKey returns a Bech32 encoded string starting with `suiprivkey`, encoding 33-byte `flag || bytes` for the given 32-byte private key and its signature scheme.
func GenerateMnemonic ¶
GenerateMnemonic generates a new mnemonic phrase with 12 words.
func IsValidBIP32Path ¶
IsValidBIP32Path checks if a given path is compliant with BIP-32 for Secp256k1 and Secp256r1. m/54'/784'/{account_index}'/{change_index}/{address_index} for Secp256k1 and m/74'/784'/{account_index}'/{change_index}/{address_index} for Secp256r1. Note that the purpose for Secp256k1 is registered as 54, to differentiate from Ed25519 with purpose 44. e.g. `m/54'/784'/0'/0/0`
func IsValidHardenedPath ¶
IsValidHardenedPath checks if a given path is compliant with SLIP-0010 m/44'/784'/{account_index}'/{change_index}'/{address_index}'. e.g. `m/44'/784'/0'/0'/0'`
func IsValidPath ¶
IsValidPath checks if the given path is a valid derivation path.
func MessageWithIntent ¶
func MessageWithIntent(scope IntentScope, message []byte) []byte
MessageWithIntent combines the intent with the provided message, returning a new byte slice that includes both.
func MnemonicToSeed ¶
MnemonicToSeed converts a mnemonic phrase to a seed using KDF to derive 64 bytes of key data from mnemonic with empty password. mnemonics 12 words string split by spaces.
func MnemonicToSeedHex ¶
MnemonicToSeedHex converts a mnemonic phrase to a seed in hex format. Derive the seed in hex format from a 12-word mnemonic string. mnemonics 12 words string split by spaces.
func ReplaceDerive ¶
ReplaceDerive removes the quote character from the derivation path segment.
func ToSerializedSignature ¶
func ToSerializedSignature(input SerializeSignatureInput) (string, error)
ToSerializedSignature serializes a signature along with its signing scheme and public key into a base64 encoded string. Takes in a signature, its associated signing scheme and a public key, then serializes this data
Types ¶
type BaseKeypair ¶
type BaseKeypair struct {
BaseSigner
}
BaseKeypair defines a struct that implements the Keypair interface.
func (*BaseKeypair) SetSelf ¶
func (base *BaseKeypair) SetSelf(signer Signer)
SetSelf sets the signer for the BaseKeypair.
type BasePublicKey ¶
type BasePublicKey struct {
// contains filtered or unexported fields
}
BasePublicKey defines a struct that implements the PublicKey interface.
func (*BasePublicKey) Equals ¶
func (base *BasePublicKey) Equals(publicKey PublicKey) bool
Equals checks if the provided public key is equal to the base public key.
func (*BasePublicKey) SetSelf ¶
func (base *BasePublicKey) SetSelf(pubkey PublicKey)
SetSelf sets the self reference for the BasePublicKey.
func (*BasePublicKey) ToBase64 ¶
func (base *BasePublicKey) ToBase64() string
ToBase64 returns the base-64 representation of the public key.
func (*BasePublicKey) ToSuiAddress ¶
func (base *BasePublicKey) ToSuiAddress() string
ToSuiAddress returns the Sui address associated with this public key.
func (*BasePublicKey) ToSuiBytes ¶
func (base *BasePublicKey) ToSuiBytes() []byte
ToSuiBytes returns the bytes representation of the public key prefixed with the signature scheme flag.
func (*BasePublicKey) ToSuiPublicKey ¶
func (base *BasePublicKey) ToSuiPublicKey() string
ToSuiPublicKey returns the Sui representation of the public key encoded in base-64. A Sui public key is formed by the concatenation of the scheme flag with the raw bytes of the public key
func (*BasePublicKey) VerifyPersonalMessage ¶
func (base *BasePublicKey) VerifyPersonalMessage(message []byte, signature SerializedSignature) (bool, error)
VerifyPersonalMessage verifies that the signature is valid for the provided personal message.
func (*BasePublicKey) VerifyTransactionBlock ¶
func (base *BasePublicKey) VerifyTransactionBlock(transactionBlock []byte, signature SerializedSignature) (bool, error)
VerifyTransactionBlock verifies that the signature is valid for the provided transaction block.
func (*BasePublicKey) VerifyWithIntent ¶
func (base *BasePublicKey) VerifyWithIntent(bs []byte, signature SerializedSignature, intent IntentScope) (bool, error)
VerifyWithIntent verifies that the signature is valid for the provided message bytes and intent.
type BaseSigner ¶
type BaseSigner struct {
// contains filtered or unexported fields
}
BaseSigner defines a struct that implements the Signer interface.
func (*BaseSigner) SignPersonalMessage ¶
func (signer *BaseSigner) SignPersonalMessage(bs []byte) (*SignatureWithBytes, error)
SignPersonalMessage signs provided personal message by calling `signWithIntent()` with a `PersonalMessage` provided as intent scope
func (*BaseSigner) SignTransactionBlock ¶
func (signer *BaseSigner) SignTransactionBlock(bs []byte) (*SignatureWithBytes, error)
SignTransactionBlock signs provided transaction block by calling `signWithIntent()` with a `TransactionData` provided as intent scope
func (*BaseSigner) SignWithIntent ¶
func (signer *BaseSigner) SignWithIntent(bs []byte, intent IntentScope) (*SignatureWithBytes, error)
SignWithIntent signs a message with a specific intent scope. By combining the message bytes with the intent before hashing and signing, it ensures that a signed message is tied to a specific purpose and domain separator is provided
func (*BaseSigner) ToSuiAddress ¶
func (signer *BaseSigner) ToSuiAddress() string
ToSuiAddress converts the public key of the signer to a Sui address.
type CompressedSignature ¶
type CompressedSignature struct {
Signature [65]byte `json:"signature"`
}
CompressedSignature defines a type for compressed signatures.
type Intent ¶
type Intent = []uint8
Intent defines the structure of an intent, which includes the scope, version, and application identifier.
func IntentWithScope ¶
func IntentWithScope(scope IntentScope) Intent
IntentWithScope creates an intent with the specified scope, using the default version and application identifier.
type IntentScope ¶
type IntentScope = uint8
IntentScope is the scope of the intent, indicating what type of data it applies to.
const ( // TransactionData is the IntentScope for transaction data. TransactionData IntentScope = iota // TransactionEffects is the IntentScope for transaction effects. TransactionEffects // CheckpointSummary is the IntentScope for checkpoint summaries. CheckpointSummary // PersonalMessage is the IntentScope for personal messages. PersonalMessage )
type IntentVersion ¶
type IntentVersion = uint8
IntentVersion is the version of the intent, which is used to manage changes in the intent structure over time.
const ( // V0 is the IntentVersion for the initial version of Sui. V0 IntentVersion = iota )
type Key ¶
Key defines a structure that holds a key and its associated chain code.
func CKDPriv ¶
CKDPriv performs child key derivation for a private key using the parent key and index.
func DerivePath ¶
DerivePath derives a key from the given derivation path and seed.
func GetMasterKeyFromSeed ¶
GetMasterKeyFromSeed derives the master key from the given seed.
type Keypair ¶
Keypair is an interface that extends the Signer interface and adds a method to retrieve the secret key.
type MultiSigPublicKeyPair ¶
type MultiSigPublicKeyPair struct { Weight uint8 `json:"weight"` PublicKey PublicKey `json:"publicKey"` }
MultiSigPublicKeyPair defines a structure that holds a weight and a public key for multisig operations.
type MultiSigPublicKeyStruct ¶
type MultiSigPublicKeyStruct struct { PubKeyMap []*PubKeyEnumWeightPair `json:"pubKeymap"` Threshold uint16 `json:"threshold"` }
MultiSigPublicKeyStruct defines a structure that holds a map of public keys and their weights, along with a threshold.
type MultiSigStruct ¶
type MultiSigStruct struct { Sigs []CompressedSignature `json:"sigs"` Bitmap uint16 `json:"bitmap"` MultisigPubKey MultiSigPublicKeyStruct `json:"multisigPubKey"` }
MultiSigStruct defines a structure that holds a list of compressed signatures, a bitmap, and a multisig public key.
type ParsedKeypair ¶
type ParsedKeypair struct { Scheme SignatureScheme SecretKey []byte }
ParsedKeypair defines a structure that holds the signature scheme and the secret key in bytes.
func DecodeSuiPrivateKey ¶
func DecodeSuiPrivateKey(value string) (*ParsedKeypair, error)
DecodeSuiPrivateKey decodes a Bech32 encoded Sui private key string into a ParsedKeypair object. This returns a ParsedKeypair object by validating the 33-byte Bech32 encoded string starting with `suiprivkey`, and parses out the signature scheme and the private key in bytes.
type PubKeyEnumWeightPair ¶
PubKeyEnumWeightPair defines a structure that holds a public key and its associated weight.
func (PubKeyEnumWeightPair) MarshalBCS ¶
func (p PubKeyEnumWeightPair) MarshalBCS() ([]byte, error)
MarshalBCS serializes the PubKeyEnumWeightPair into a BCS format.
func (*PubKeyEnumWeightPair) UnmarshalBCS ¶
func (p *PubKeyEnumWeightPair) UnmarshalBCS(r io.Reader) (int, error)
UnmarshalBCS deserializes the PubKeyEnumWeightPair from a BCS format.
type PublicKey ¶
type PublicKey interface { Equals(publicKey PublicKey) bool ToBase64() string ToSuiPublicKey() string VerifyWithIntent(bs []byte, signature SerializedSignature, intent IntentScope) (bool, error) VerifyPersonalMessage(message []byte, signature SerializedSignature) (bool, error) VerifyTransactionBlock(transactionBlock []byte, signature SerializedSignature) (bool, error) ToSuiBytes() []byte ToSuiAddress() string ToRawBytes() []byte Flag() uint8 Verify(message []byte, signature SerializedSignature) (bool, error) }
PublicKey is an interface that defines the methods for a public key in the Sui cryptography system.
type SerializeSignatureInput ¶
type SerializeSignatureInput struct { SignatureScheme SignatureScheme Signature []byte PublicKey PublicKey }
SerializeSignatureInput defines the input required to serialize a signature, including the signature, scheme, and public key.
type SerializedSignature ¶
type SerializedSignature = string
SerializedSignature defines a type for serialized signatures.
type SerializedSignatureParsedData ¶
type SerializedSignatureParsedData struct { SerializedSignature SerializedSignature `json:"serializedSignature"` SignatureScheme string `json:"signatureScheme"` Signature []byte `json:"signature,omitempty"` PubKey []byte `json:"pubKey,omitempty"` Bytes []byte `json:"bytes"` Multisig *MultiSigStruct `json:"multisig,omitempty"` }
SerializedSignatureParsedData defines a struct that holds the parsed data from a serialized signature.
func ParseSerializedSignature ¶
func ParseSerializedSignature(serializedSignature SerializedSignature) (*SerializedSignatureParsedData, error)
ParseSerializedSignature decodes a serialized signature into its constituent components: the signature scheme, the actual signature, and the public key
type SignatureFlag ¶
type SignatureFlag = uint8
SignatureFlag defines the type for signature flags, which are used to identify the signature scheme in serialized signatures.
type SignatureScheme ¶
type SignatureScheme = string
SignatureScheme defines the type for signature schemes used in Sui.
var ( // Ed25519Scheme is the signature scheme for Ed25519. Ed25519Scheme SignatureScheme = "ED25519" // Secp256k1Scheme is the signature scheme for Secp256k1. Secp256k1Scheme SignatureScheme = "Secp256k1" // Secp256r1Scheme is the signature scheme for Secp256r1. Secp256r1Scheme SignatureScheme = "Secp256r1" // MultiSigScheme is the signature scheme for MultiSig. MultiSigScheme SignatureScheme = "MultiSig" // ZkLoginScheme is the signature scheme for ZkLogin. ZkLoginScheme SignatureScheme = "ZkLogin" )
type SignatureWithBytes ¶
type SignatureWithBytes struct { Bytes string Signature SerializedSignature }
SignatureWithBytes defines a structure that holds the base64 encoded bytes of the signed message and the serialized signature.
type Signer ¶
type Signer interface { Sign(bs []byte) ([]byte, error) SignWithIntent(bs []byte, intent IntentScope) (*SignatureWithBytes, error) SignTransactionBlock(bs []byte) (*SignatureWithBytes, error) SignPersonalMessage(bs []byte) (*SignatureWithBytes, error) ToSuiAddress() string SignData(data []byte) ([]byte, error) GetKeyScheme() SignatureScheme GetPublicKey() (PublicKey, error) }
Signer is an interface that defines the methods for signing messages and retrieving public keys.