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 = 32 Secp256k1PublicKeySize = 33 Secp256r1PublicKeySize = 33 )
const ( Ed25519CURVE = "ed25519 seed" HardenedOffset = 0x80000000 )
const ( PrivateKeySize = 32 SuiPrivateKeyPrefix = "suiprivkey" )
Variables ¶
var SignatureFlagToScheme = map[SignatureFlag]SignatureScheme{ 0x00: Ed25519Scheme, 0x01: Secp256k1Scheme, 0x02: Secp256r1Scheme, 0x03: MultiSigScheme, 0x05: ZkLoginScheme, }
var SignatureSchemeToFlag = map[SignatureScheme]SignatureFlag{ Ed25519Scheme: 0x00, Secp256k1Scheme: 0x01, Secp256r1Scheme: 0x02, MultiSigScheme: 0x03, ZkLoginScheme: 0x05, }
var SignatureSchemeToSize = map[SignatureScheme]int{ Ed25519Scheme: 32, Secp256k1Scheme: 33, Secp256r1Scheme: 33, }
Functions ¶
func EncodeSuiPrivateKey ¶
*
- This returns a Bech32 encoded string starting with `suiprivkey`,
- encoding 33-byte `flag || bytes` for the given the 32-byte private
- key and its signature scheme.
func GenerateMnemonic ¶ added in v0.0.18
func IsValidBIP32Path ¶
Parse and validate a path that is compliant to BIP-32 in form 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 ¶
Parse and validate a path that is compliant to SLIP-0010 in form m/44'/784'/{account_index}'/{change_index}'/{address_index}'. e.g. `m/44'/784'/0'/0'/0'`
func IsValidPath ¶
func MessageWithIntent ¶
func MessageWithIntent(scope IntentScope, message []byte) []byte
func MnemonicToSeed ¶
Uses KDF to derive 64 bytes of key data from mnemonic with empty password. mnemonics 12 words string split by spaces.
func MnemonicToSeedHex ¶
Derive the seed in hex format from a 12-word mnemonic string. mnemonics 12 words string split by spaces.
func ReplaceDerive ¶
func ToSerializedSignature ¶
func ToSerializedSignature(input SerializeSignatureInput) (string, error)
*
- Takes in a signature, its associated signing scheme and a public key, then serializes this data
Types ¶
type BaseKeypair ¶
type BaseKeypair struct {
BaseSigner
}
func (*BaseKeypair) SetSelf ¶
func (base *BaseKeypair) SetSelf(signer Signer)
type BasePublicKey ¶
type BasePublicKey struct {
// contains filtered or unexported fields
}
func (*BasePublicKey) Equals ¶
func (base *BasePublicKey) Equals(publicKey PublicKey) bool
Checks if two public keys are equal
func (*BasePublicKey) SetSelf ¶
func (base *BasePublicKey) SetSelf(pubkey PublicKey)
To ensure thread memory safety, this method needs to be removed. This matter is temporarily added to the todo list
func (*BasePublicKey) ToBase64 ¶
func (base *BasePublicKey) ToBase64() string
Return the base-64 representation of the public key
func (*BasePublicKey) ToSuiAddress ¶
func (base *BasePublicKey) ToSuiAddress() string
Return the Sui address associated with this Ed25519 public key
func (*BasePublicKey) ToSuiBytes ¶
func (base *BasePublicKey) ToSuiBytes() []byte
*
- Returns the bytes representation of the public key
- prefixed with the signature scheme flag
func (*BasePublicKey) ToSuiPublicKey ¶
func (base *BasePublicKey) ToSuiPublicKey() string
* Return 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)
Verifies that the signature is valid for for the provided PersonalMessage
func (*BasePublicKey) VerifyTransactionBlock ¶
func (base *BasePublicKey) VerifyTransactionBlock(transactionBlock []byte, signature SerializedSignature) (bool, error)
Verifies that the signature is valid for for the provided TransactionBlock
func (*BasePublicKey) VerifyWithIntent ¶
func (base *BasePublicKey) VerifyWithIntent(bs []byte, signature SerializedSignature, intent IntentScope) (bool, error)
type BaseSigner ¶
type BaseSigner struct {
// contains filtered or unexported fields
}
func (*BaseSigner) SignPersonalMessage ¶
func (signer *BaseSigner) SignPersonalMessage(bs []byte) (*SignatureWithBytes, error)
*
- 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)
*
- 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)
*
- Sign messages with a specific intent. 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
type CompressedSignature ¶
type CompressedSignature struct {
Signature [65]byte `json:"signature"`
}
type Intent ¶
type Intent = []uint8
func IntentWithScope ¶
func IntentWithScope(scope IntentScope) Intent
type IntentScope ¶
type IntentScope = uint8
const ( TransactionData IntentScope = iota TransactionEffects CheckpointSummary PersonalMessage )
type Key ¶
func GetMasterKeyFromSeed ¶
type MultiSigPublicKeyPair ¶
type MultiSigPublicKeyStruct ¶
type MultiSigPublicKeyStruct struct { PubKeyMap []*PubKeyEnumWeightPair `json:"pubKeymap"` Threshold uint16 `json:"threshold"` }
type MultiSigStruct ¶
type MultiSigStruct struct { Sigs []CompressedSignature `json:"sigs"` Bitmap uint16 `json:"bitmap"` MultisigPubKey MultiSigPublicKeyStruct `json:"multisigPubKey"` }
type ParsedKeypair ¶
type ParsedKeypair struct { Scheme SignatureScheme SecretKey []byte }
func DecodeSuiPrivateKey ¶
func DecodeSuiPrivateKey(value string) (*ParsedKeypair, error)
*
- This returns an ParsedKeypair object based by validating the
- 33-byte Bech32 encoded string starting with `suiprivkey`, and
- parse out the signature scheme and the private key in bytes.
type PubKeyEnumWeightPair ¶
func (PubKeyEnumWeightPair) MarshalBCS ¶
func (p PubKeyEnumWeightPair) MarshalBCS() ([]byte, error)
func (*PubKeyEnumWeightPair) UnmarshalBCS ¶
func (p *PubKeyEnumWeightPair) UnmarshalBCS(r io.Reader) (int, error)
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) }
type SerializeSignatureInput ¶
type SerializeSignatureInput struct { SignatureScheme SignatureScheme Signature []byte PublicKey PublicKey }
*
- Pair of signature and corresponding public key
type SerializedSignature ¶
type SerializedSignature = string
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"` }
func ParseSerializedSignature ¶
func ParseSerializedSignature(serializedSignature SerializedSignature) (*SerializedSignatureParsedData, error)
*
- Decodes a serialized signature into its constituent components: the signature scheme, the actual signature, and the public key
type SignatureFlag ¶
type SignatureFlag = uint8
type SignatureScheme ¶
type SignatureScheme = string
var ( Ed25519Scheme SignatureScheme = "ED25519" Secp256k1Scheme SignatureScheme = "Secp256k1" Secp256r1Scheme SignatureScheme = "Secp256r1" MultiSigScheme SignatureScheme = "MultiSig" ZkLoginScheme SignatureScheme = "ZkLogin" )
type SignatureWithBytes ¶
type SignatureWithBytes struct { Bytes string Signature SerializedSignature }
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) }