Documentation
¶
Overview ¶
File Remote Signer implements the Signer interface using a file to store the keys.
The keys are stored in a file in the local filesystem.
passphrase := []byte("your-secure-passphrase")
keyPath := "/path/to/secure/keys.json"
// Create or load a signer
signer, err := NewFileSystemSigner(keyPath, passphrase)
if err != nil {
panic(err)
}
// Sign a message
message := []byte("Message to sign")
signature, err := signer.Sign(message)
if err != nil {
panic(err)
}
// Get the public key
pubKey, err := signer.GetPublic()
if err != nil {
panic(err)
}
// Verify the signature (typically done by another party)
valid, err := pubKey.Verify(message, signature)
if err != nil {
panic(err)
}
Example ¶
Example demonstrates how to use the FileSystemSigner
// In a real application, you would use a secure passphrase
passphrase := []byte("your-secure-passphrase")
keyPath := "/path/to/secure/keys.json"
// Create or load a signer
signer, err := CreateFileSystemSigner(keyPath, passphrase)
if err != nil {
panic(err)
}
// Sign a message
message := []byte("Message to sign")
signature, err := signer.Sign(message)
if err != nil {
panic(err)
}
// Get the public key
pubKey, err := signer.GetPublic()
if err != nil {
panic(err)
}
// Verify the signature (typically done by another party)
valid, err := pubKey.Verify(message, signature)
if err != nil {
panic(err)
}
if valid {
// Signature is valid
} else {
// Signature is invalid
}
Index ¶
- func CreateFileSystemSigner(keyPath string, passphrase []byte) (signer.Signer, error)
- func ExportPrivateKey(keyPath string, passphrase []byte) ([]byte, error)
- func ImportPrivateKey(keyPath string, privKeyBytes []byte, passphrase []byte) error
- func LoadFileSystemSigner(keyPath string, passphrase []byte) (signer.Signer, error)
- type FileSystemSigner
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateFileSystemSigner ¶
CreateFileSystemSigner creates a new key pair and saves it encrypted to disk.
func ExportPrivateKey ¶
ExportPrivateKey decrypts and returns the raw private key from the key file. It is intended for key backup and migration purposes. WARNING: Handle the returned private key with extreme care.
func ImportPrivateKey ¶
ImportPrivateKey encrypts a raw private key and saves it to the key file. It will overwrite an existing key file if one exists. WARNING: This is a destructive operation.
Types ¶
type FileSystemSigner ¶
type FileSystemSigner struct {
// contains filtered or unexported fields
}
FileSystemSigner implements a signer that securely stores keys on disk and loads them into memory only when needed.
func (*FileSystemSigner) GetAddress ¶
func (s *FileSystemSigner) GetAddress() ([]byte, error)
GetAddress returns the address of the signer