9dfa06ffee
Docker image / Build (linux/amd64) (push) Has been cancelled
Docker image / Build (linux/arm64) (push) Has been cancelled
Docker image / Merge release multi-arch manifest (push) Has been cancelled
Docker image / Merge debug multi-arch manifest (push) Has been cancelled
Docker image / Build public push gateway (linux/amd64) (push) Has been cancelled
Docker image / Build public push gateway (linux/arm64) (push) Has been cancelled
Docker image / Publish public push gateway image (push) Has been cancelled
Sprig image / Build (linux/amd64) (push) Has been cancelled
Sprig image / Build (linux/arm64) (push) Has been cancelled
Sprig image / Merge multi-arch manifest (push) Has been cancelled
Harbor Buzz Orchestra / Python tests and lint (push) Has been cancelled
CI / Detect Changed Paths (push) Has been cancelled
CI / Rust Lint (push) Has been cancelled
CI / Unit Tests (push) Has been cancelled
CI / Desktop Core (push) Has been cancelled
CI / Desktop Smoke E2E (1) (push) Has been cancelled
CI / Desktop Smoke E2E (2) (push) Has been cancelled
CI / Desktop Smoke E2E (3) (push) Has been cancelled
CI / Desktop Smoke E2E (4) (push) Has been cancelled
CI / Desktop (push) Has been cancelled
CI / Desktop E2E Relay (push) Has been cancelled
CI / Desktop E2E Integration (1/2) (push) Has been cancelled
CI / Desktop E2E Integration (2/2) (push) Has been cancelled
CI / Desktop E2E Integration (push) Has been cancelled
CI / Backend Integration (relay e2e) (push) Has been cancelled
CI / Relay E2E (push) Has been cancelled
CI / Web (push) Has been cancelled
CI / Mobile (push) Has been cancelled
CI / Security (push) Has been cancelled
CI / Dead Token Reference Guard (push) Has been cancelled
CI / Server Cross-Compile (aarch64-unknown-linux-musl) (push) Has been cancelled
CI / Server Cross-Compile (x86_64-unknown-linux-musl) (push) Has been cancelled
CI / Windows Rust (x86_64-pc-windows-msvc) (push) Has been cancelled
CI / Desktop Build (macOS) (push) Has been cancelled
helm chart / lint + unittest + render matrix (push) Has been cancelled
helm chart / install on kind (gated) (push) Has been cancelled
helm chart / publish chart to GHCR (push) Has been cancelled
Mesh Lifecycle / Relay-Driven Mesh Lifecycle Smoke (push) Has been cancelled
Sprig / Build (aarch64-unknown-linux-musl) (push) Has been cancelled
Sprig / Build (x86_64-unknown-linux-musl) (push) Has been cancelled
Sprig / Publish rolling release (push) Has been cancelled
Sprig / Publish tagged release (push) Has been cancelled
Signed-off-by: cls_宁波本机 <908705107@qq.com>
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
"""Keygen and NIP-OA attestation unit tests."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import hashlib
|
|
import json
|
|
|
|
import coincurve
|
|
|
|
from harbor_buzz_testbed.keys import (
|
|
compute_auth_tag,
|
|
encode_nsec,
|
|
generate_keypair,
|
|
)
|
|
|
|
# Produced by the Rust reference implementation
|
|
# (crates/buzz-sdk/examples/compute_auth_tag.rs) for owner secret 0x...03 and
|
|
# agent pubkey "a" * 64. Pins the preimage format across implementations.
|
|
RUST_OWNER_SECRET = "0" * 63 + "3"
|
|
RUST_AGENT_PUBKEY = "a" * 64
|
|
RUST_TAG = [
|
|
"auth",
|
|
"f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9",
|
|
"",
|
|
(
|
|
"20105c618d6e5d8f559cffb6f0d7a7b4f44f3a567e1be94c96378d45ac3625da"
|
|
"34c2e7357ea1d3ce980978334546b3e740c155e81b833ebe140d519d39ed8867"
|
|
),
|
|
]
|
|
|
|
|
|
def preimage_digest(agent_pubkey: str, conditions: str) -> bytes:
|
|
return hashlib.sha256(
|
|
f"nostr:agent-auth:{agent_pubkey}:{conditions}".encode()
|
|
).digest()
|
|
|
|
|
|
def test_generate_keypair_is_fresh_and_hex():
|
|
first, second = generate_keypair(), generate_keypair()
|
|
assert first.secret_key != second.secret_key
|
|
assert first.pubkey != second.pubkey
|
|
assert len(first.secret_key) == 64
|
|
assert len(first.pubkey) == 64
|
|
int(first.secret_key, 16)
|
|
int(first.pubkey, 16)
|
|
|
|
|
|
def test_auth_tag_shape_and_owner_pubkey():
|
|
tag = json.loads(compute_auth_tag(RUST_OWNER_SECRET, RUST_AGENT_PUBKEY))
|
|
assert tag[0] == "auth"
|
|
assert tag[1] == RUST_TAG[1] # same owner pubkey as the Rust implementation
|
|
assert tag[2] == ""
|
|
|
|
|
|
def test_auth_tag_signature_verifies_over_nip_oa_preimage():
|
|
agent = generate_keypair()
|
|
tag = json.loads(compute_auth_tag(RUST_OWNER_SECRET, agent.pubkey))
|
|
owner_pubkey = coincurve.PublicKeyXOnly(bytes.fromhex(tag[1]))
|
|
assert owner_pubkey.verify(bytes.fromhex(tag[3]), preimage_digest(agent.pubkey, ""))
|
|
|
|
|
|
def test_rust_reference_tag_verifies_under_python_preimage():
|
|
"""The Rust-signed vector must verify against our preimage construction."""
|
|
owner_pubkey = coincurve.PublicKeyXOnly(bytes.fromhex(RUST_TAG[1]))
|
|
assert owner_pubkey.verify(
|
|
bytes.fromhex(RUST_TAG[3]), preimage_digest(RUST_AGENT_PUBKEY, "")
|
|
)
|
|
|
|
|
|
def test_encode_nsec_matches_nip19_vector():
|
|
# NIP-19 reference vector from the spec.
|
|
assert (
|
|
encode_nsec("67dea2ed018072d675f5415ecfaed7d2597555e202d85b3d65ea4e58d2d92ffa")
|
|
== "nsec1vl029mgpspedva04g90vltkh6fvh240zqtv9k0t9af8935ke9laqsnlfe5"
|
|
)
|