feat: add FromBytes function to create Identity from a 64-byte private key representation
Some checks failed
Go Build Multi-Platform / build (amd64, freebsd) (push) Successful in 32s
Go Build Multi-Platform / build (amd64, windows) (push) Successful in 33s
Go Build Multi-Platform / build (arm, linux) (push) Successful in 31s
Go Build Multi-Platform / build (arm64, windows) (push) Successful in 43s
Go Build Multi-Platform / build (arm64, linux) (push) Successful in 46s
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (push) Successful in 50s
Bearer / scan (push) Successful in 33s
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (push) Successful in 1m42s
Go Revive Lint / lint (push) Successful in 1m0s
Run Gosec / tests (push) Failing after 1m7s
Go Build Multi-Platform / build (amd64, darwin) (push) Successful in 9m23s
Go Build Multi-Platform / build (amd64, linux) (push) Successful in 9m26s
Go Build Multi-Platform / build (arm, freebsd) (push) Successful in 9m24s
Go Build Multi-Platform / build (arm, windows) (push) Successful in 9m26s
Go Build Multi-Platform / build (arm64, darwin) (push) Successful in 9m24s
Go Build Multi-Platform / build (arm64, freebsd) (push) Successful in 9m26s
Go Build Multi-Platform / Create Release (push) Has been skipped

This commit is contained in:
2025-12-30 11:42:48 -06:00
parent 3cb375e7f2
commit 18200213f0

View File

@@ -925,6 +925,28 @@ func NewIdentity() (*Identity, error) {
return i, nil
}
// FromBytes creates an Identity from a 64-byte private key representation
func FromBytes(data []byte) (*Identity, error) {
if len(data) != 64 {
return nil, fmt.Errorf("invalid identity data: expected 64 bytes, got %d", len(data))
}
privateKey := data[:32]
signingSeed := data[32:64]
ident := &Identity{
ratchets: make(map[string][]byte),
ratchetExpiry: make(map[string]int64),
mutex: &sync.RWMutex{},
}
if err := ident.loadPrivateKey(privateKey, signingSeed); err != nil {
return nil, fmt.Errorf("failed to load private key: %w", err)
}
return ident, nil
}
func (i *Identity) RotateRatchet() ([]byte, error) {
i.mutex.Lock()
defer i.mutex.Unlock()