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(context.Background(), 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(context.Background(), 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 ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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 CreateFileSystemSigner ¶
func CreateFileSystemSigner(keyPath string, passphrase []byte) (*FileSystemSigner, error)
CreateFileSystemSigner creates a new key pair and saves it encrypted to disk.
func LoadFileSystemSigner ¶
func LoadFileSystemSigner(keyPath string, passphrase []byte) (*FileSystemSigner, error)
LoadFileSystemSigner loads existing keys from an encrypted file on disk.
func (*FileSystemSigner) GetAddress ¶
func (s *FileSystemSigner) GetAddress() ([]byte, error)
GetAddress returns the address of the signer