type PeerAuthorizer func(key NoiseKey) bool It runs on the polling goroutine completing the handshake and must not panic.
Ask your coding agent about this page, or add the docs server to it
curl -s 'https://www.unum.cloud/docs/ucall/go/noise-keys.md' | claude -p "How would this fit my code?"Interfaces and calls can run over the Noise protocol instead of plain TCP, authenticating both sides by 32-byte Curve25519 static keys.
serverPrivateKey, serverPublicKey, err := ucall.GenerateNoiseKeypair()
if err != nil {
return err
}
clientPrivateKey, _, err := ucall.GenerateNoiseKeypair()
if err != nil {
return err
}
clientPublicKey, err := ucall.DeriveNoisePublicKey(clientPrivateKey)
if err != nil {
return err
}
sealed := ucall.NewInterface("0.0.0.0:8546")
sealed.Security, sealed.NoisePrivateKey = ucall.SecurityNoiseXX, &serverPrivateKey
sealed.PeerAuthorizer = func(key ucall.NoiseKey) bool { return key == clientPublicKey }
server, err := ucall.NewServer([]ucall.Interface{sealed}, nil)
if err != nil {
return err
}
client, err := ucall.NewClient(&ucall.ClientOptions{
Connections: 1,
NoisePrivateKey: &clientPrivateKey,
PeerAuthorizer: func(key ucall.NoiseKey) bool { return key == serverPublicKey },
})GenerateNoiseKeypair draws from the operating system’s entropy and fails with StatusIO when it is refused. DeriveNoisePublicKey recovers the public half of a stored private key, which peers compare in their authorizers.
Under Noise XX both sides learn each other’s key during the handshake, so both need an authorizer; Noise IK has the client name the server’s key in advance through ClientCallOptions.NoisePeerKey.
Noise KK has both sides know each other in advance: the interface admits the one key Interface.NoisePeerKey names, and the call presents ClientCallOptions.NoisePrivateKey or the client’s own key.
Both sides may also hold a 32-byte NoisePreSharedKey, and must match their KeyExchange, whose zero value is the post-quantum KeyExchangeX25519MLKEM768.
An http+noise:// URL implies Noise XX, and a handler reads the client’s authenticated key through Request.Peer.
PeerAuthorizerPeerAuthorizer decides whether a peer presenting an authenticated static key may proceed.type PeerAuthorizer func(key NoiseKey) bool It runs on the polling goroutine completing the handshake and must not panic.
SecuritySecurity is the transport an interface or a call runs over.type Security int32 SecurityNone | SecurityNone is plain TCP. | |
|---|---|---|
SecurityNoiseXX | SecurityNoiseXX authenticates both sides during the handshake. | |
SecurityNoiseIK | SecurityNoiseIK has the client know the server's key in advance. | |
SecurityNoiseKK | SecurityNoiseKK has both sides know each other's key in advance. |
KeyExchangeKeyExchange is the key exchange of a Noise handshake, which both sides must match.2type KeyExchange int32 KeyExchangeX25519MLKEM768 | KeyExchangeX25519MLKEM768 runs X25519 and ML-KEM-768 together: recorded traffic stays private unless both break. | |
|---|---|---|
KeyExchangeX25519 | KeyExchangeX25519 runs X25519 alone, for standard Noise peers: recorded traffic falls to a quantum computer. |
KeyExchangeFromNameKeyExchangeFromName reads a key exchange back from its stable name.func KeyExchangeFromName(name string) (KeyExchange, error) Stringfunc (exchange KeyExchange) String() string NoiseKeyNoiseKey is a 32-byte Curve25519 key.1type NoiseKey [32]byte DeriveNoisePublicKeyDeriveNoisePublicKey recovers the public half of a stored private key, which peers compare in their authorizers.func DeriveNoisePublicKey(privateKey NoiseKey) (NoiseKey, error) GenerateNoiseKeypairGenerateNoiseKeypair draws a fresh private key and its public key from the operating system's entropy.func GenerateNoiseKeypair() (NoiseKey, NoiseKey, error)