///|
/// Pure MoonBit, zero-FFI IETF RFC 9497 (OPRF / VOPRF / POPRF), RFC 9380
/// (Hash-to-Curve), RFC 9496 (Ristretto255), and RFC 9578 Privacy Pass
/// anonymous token protocol stack (`CoolrfulDARkness/moonvoprf`).
// ============================================================================
// RFC 9380 / RFC 9496 Hash-to-Group Convenience Entry Points
// ============================================================================
///|
/// Hashes `(msg, dst)` onto the RFC 9496 Ristretto255 prime-order group using
/// `expand_message_xmd(SHA-512)` and Elligator-2 (`MAP(r0) + MAP(r1)`),
/// returning the 32-byte canonical encoded element.
pub fn hash_to_group_ristretto255(
msg : Bytes,
dst : Bytes,
) -> Bytes raise @r255.RistrettoError {
@r255.Point::hash_to_group(msg, dst).encode()
}
///|
/// Hashes `(msg, dst)` onto NIST P-256 using RFC 9380
/// `P256_XMD:SHA-256_SSWU_RO_` (Simplified SWU, `Z = -10`), returning the
/// 33-byte SEC1 compressed point.
pub fn hash_to_curve_p256(
msg : Bytes,
dst : Bytes,
) -> Bytes raise @p256.P256Error {
@p256.Point::hash_to_group(msg, dst).encode_compressed()
}
// ============================================================================
// RFC 9497 Key Derivation
// ============================================================================
///|
pub fn derive_key_pair(
suite : @voprf.CipherSuite,
seed : Bytes,
info : Bytes,
) -> @voprf.KeyPair raise @voprf.VoprfError {
@voprf.derive_key_pair(suite, seed, info)
}
///|
pub fn derive_key_pair_for_mode(
suite : @voprf.CipherSuite,
mode : @voprf.Mode,
seed : Bytes,
info : Bytes,
) -> @voprf.KeyPair raise @voprf.VoprfError {
@voprf.derive_key_pair_for_mode(suite, mode, seed, info)
}
///|
pub fn public_key_from_sk(
suite : @voprf.CipherSuite,
sk : Bytes,
) -> Bytes raise @voprf.VoprfError {
@voprf.public_key_from_sk(suite, sk)
}
// ============================================================================
// RFC 9497 Base OPRF (Mode 0x00)
// ============================================================================
///|
pub fn oprf_blind(
suite : @voprf.CipherSuite,
input : Bytes,
seed : Bytes,
) -> @voprf.BlindState raise @voprf.VoprfError {
@voprf.oprf_blind(suite, input, seed)
}
///|
pub fn oprf_blind_with_scalar(
suite : @voprf.CipherSuite,
input : Bytes,
blind_scalar : Bytes,
) -> @voprf.BlindState raise @voprf.VoprfError {
@voprf.oprf_blind_with_scalar(suite, input, blind_scalar)
}
///|
pub fn oprf_blind_evaluate(
suite : @voprf.CipherSuite,
sk : Bytes,
blinded_element : Bytes,
) -> Bytes raise @voprf.VoprfError {
@voprf.oprf_blind_evaluate(suite, sk, blinded_element)
}
///|
pub fn oprf_finalize(
state : @voprf.BlindState,
evaluated_element : Bytes,
) -> Bytes raise @voprf.VoprfError {
@voprf.oprf_finalize(state, evaluated_element)
}
///|
pub fn oprf_full_evaluate(
suite : @voprf.CipherSuite,
sk : Bytes,
input : Bytes,
) -> Bytes raise @voprf.VoprfError {
@voprf.oprf_full_evaluate(suite, sk, input)
}
// ============================================================================
// RFC 9497 Verifiable OPRF (Mode 0x01)
// ============================================================================
///|
pub fn voprf_blind(
suite : @voprf.CipherSuite,
input : Bytes,
seed : Bytes,
) -> @voprf.BlindState raise @voprf.VoprfError {
@voprf.voprf_blind(suite, input, seed)
}
///|
pub fn voprf_blind_with_scalar(
suite : @voprf.CipherSuite,
input : Bytes,
blind_scalar : Bytes,
) -> @voprf.BlindState raise @voprf.VoprfError {
@voprf.voprf_blind_with_scalar(suite, input, blind_scalar)
}
///|
pub fn voprf_blind_evaluate(
suite : @voprf.CipherSuite,
sk : Bytes,
pk : Bytes,
blinded_elements : Array[Bytes],
seed : Bytes,
) -> (Array[Bytes], @voprf.Proof) raise @voprf.VoprfError {
@voprf.voprf_blind_evaluate(suite, sk, pk, blinded_elements, seed)
}
///|
pub fn voprf_blind_evaluate_with_r(
suite : @voprf.CipherSuite,
sk : Bytes,
pk : Bytes,
blinded_elements : Array[Bytes],
proof_r : Bytes,
) -> (Array[Bytes], @voprf.Proof) raise @voprf.VoprfError {
@voprf.voprf_blind_evaluate_with_r(suite, sk, pk, blinded_elements, proof_r)
}
///|
pub fn voprf_finalize(
state : @voprf.BlindState,
pk : Bytes,
evaluated_element : Bytes,
proof : @voprf.Proof,
) -> Bytes raise @voprf.VoprfError {
@voprf.voprf_finalize(state, pk, evaluated_element, proof)
}
///|
pub fn voprf_finalize_batch(
states : Array[@voprf.BlindState],
pk : Bytes,
evaluated_elements : Array[Bytes],
proof : @voprf.Proof,
) -> Array[Bytes] raise @voprf.VoprfError {
@voprf.voprf_finalize_batch(states, pk, evaluated_elements, proof)
}
///|
pub fn voprf_full_evaluate(
suite : @voprf.CipherSuite,
sk : Bytes,
input : Bytes,
) -> Bytes raise @voprf.VoprfError {
@voprf.voprf_full_evaluate(suite, sk, input)
}
// ============================================================================
// RFC 9497 Partially Oblivious OPRF (Mode 0x02)
// ============================================================================
///|
pub fn poprf_blind(
suite : @voprf.CipherSuite,
input : Bytes,
seed : Bytes,
) -> @voprf.BlindState raise @voprf.VoprfError {
@voprf.poprf_blind(suite, input, seed)
}
///|
pub fn poprf_blind_with_scalar(
suite : @voprf.CipherSuite,
input : Bytes,
blind_scalar : Bytes,
) -> @voprf.BlindState raise @voprf.VoprfError {
@voprf.poprf_blind_with_scalar(suite, input, blind_scalar)
}
///|
pub fn poprf_blind_evaluate(
suite : @voprf.CipherSuite,
sk : Bytes,
pk : Bytes,
blinded_elements : Array[Bytes],
info : Bytes,
seed : Bytes,
) -> (Array[Bytes], @voprf.Proof) raise @voprf.VoprfError {
@voprf.poprf_blind_evaluate(suite, sk, pk, blinded_elements, info, seed)
}
///|
pub fn poprf_blind_evaluate_with_r(
suite : @voprf.CipherSuite,
sk : Bytes,
pk : Bytes,
blinded_elements : Array[Bytes],
info : Bytes,
proof_r : Bytes,
) -> (Array[Bytes], @voprf.Proof) raise @voprf.VoprfError {
@voprf.poprf_blind_evaluate_with_r(
suite, sk, pk, blinded_elements, info, proof_r,
)
}
///|
pub fn poprf_finalize(
state : @voprf.BlindState,
pk : Bytes,
evaluated_element : Bytes,
info : Bytes,
proof : @voprf.Proof,
) -> Bytes raise @voprf.VoprfError {
@voprf.poprf_finalize(state, pk, evaluated_element, info, proof)
}
///|
pub fn poprf_finalize_batch(
states : Array[@voprf.BlindState],
pk : Bytes,
evaluated_elements : Array[Bytes],
info : Bytes,
proof : @voprf.Proof,
) -> Array[Bytes] raise @voprf.VoprfError {
@voprf.poprf_finalize_batch(states, pk, evaluated_elements, info, proof)
}
///|
pub fn poprf_full_evaluate(
suite : @voprf.CipherSuite,
sk : Bytes,
input : Bytes,
info : Bytes,
) -> Bytes raise @voprf.VoprfError {
@voprf.poprf_full_evaluate(suite, sk, input, info)
}
// ============================================================================
// RFC 9578 Privacy Pass Entry Points
// ============================================================================
///|
pub fn new_issuer(
suite : @voprf.CipherSuite,
seed : Bytes,
key_info : Bytes,
) -> @pp.Issuer raise @pp.PrivacyPassError {
@pp.Issuer::from_seed(suite, seed, key_info)
}
///|
pub fn new_client(
suite : @voprf.CipherSuite,
issuer_pk : Bytes,
) -> @pp.Client raise @pp.PrivacyPassError {
@pp.Client::new(suite, issuer_pk)
}
///|
pub fn new_nonce_registry() -> @pp.NonceRegistry {
@pp.NonceRegistry::new()
}