buzzkit 0.1.4__tar.gz → 0.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {buzzkit-0.1.4 → buzzkit-0.2.0}/Cargo.lock +6 -5
- {buzzkit-0.1.4 → buzzkit-0.2.0}/Cargo.toml +3 -3
- {buzzkit-0.1.4 → buzzkit-0.2.0}/PKG-INFO +47 -14
- {buzzkit-0.1.4 → buzzkit-0.2.0}/README.md +46 -13
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/analyze_audio_tap.py +4 -4
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/huddle_wire_recorder.py +2 -3
- {buzzkit-0.1.4 → buzzkit-0.2.0}/pyproject.toml +1 -1
- {buzzkit-0.1.4 → buzzkit-0.2.0}/python/buzzkit/__init__.py +35 -1
- {buzzkit-0.1.4 → buzzkit-0.2.0}/python/buzzkit/_native.pyi +43 -2
- buzzkit-0.2.0/python/buzzkit/agents.py +91 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/python/buzzkit/client.py +128 -6
- {buzzkit-0.1.4 → buzzkit-0.2.0}/src/huddle.rs +11 -10
- {buzzkit-0.1.4 → buzzkit-0.2.0}/src/lib.rs +167 -10
- buzzkit-0.2.0/tests/test_agents.py +98 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/tests/test_signing.py +106 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/.cargo/config.toml +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/.github/workflows/CI.yml +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/.github/workflows/release.yml +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/.gitignore +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/LICENSE +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/LICENSE-APACHE +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/NOTICE +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/build-support/vendored-libopus.cmake +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/_shared.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/claim_invite.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/huddle_echo.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/list_channels.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/offline_sign.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/send_message.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/set_profile.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/examples/subscribe.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/python/buzzkit/huddle.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/python/buzzkit/py.typed +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/tests/test_huddle.py +0 -0
- {buzzkit-0.1.4 → buzzkit-0.2.0}/tests/test_live_relay.py +0 -0
|
@@ -146,8 +146,9 @@ checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
|
|
146
146
|
[[package]]
|
|
147
147
|
name = "buzz-core"
|
|
148
148
|
version = "0.1.0"
|
|
149
|
-
source = "git+https://github.com/block/buzz?rev=
|
|
149
|
+
source = "git+https://github.com/block/buzz?rev=209536ade6c5ebf7fa82671d7ca0b74f599a40cc#209536ade6c5ebf7fa82671d7ca0b74f599a40cc"
|
|
150
150
|
dependencies = [
|
|
151
|
+
"base64",
|
|
151
152
|
"chrono",
|
|
152
153
|
"hex",
|
|
153
154
|
"hmac 0.13.0",
|
|
@@ -167,7 +168,7 @@ dependencies = [
|
|
|
167
168
|
[[package]]
|
|
168
169
|
name = "buzz-sdk"
|
|
169
170
|
version = "0.1.0"
|
|
170
|
-
source = "git+https://github.com/block/buzz?rev=
|
|
171
|
+
source = "git+https://github.com/block/buzz?rev=209536ade6c5ebf7fa82671d7ca0b74f599a40cc#209536ade6c5ebf7fa82671d7ca0b74f599a40cc"
|
|
171
172
|
dependencies = [
|
|
172
173
|
"buzz-core",
|
|
173
174
|
"nostr",
|
|
@@ -179,7 +180,7 @@ dependencies = [
|
|
|
179
180
|
|
|
180
181
|
[[package]]
|
|
181
182
|
name = "buzzkit"
|
|
182
|
-
version = "0.
|
|
183
|
+
version = "0.2.0"
|
|
183
184
|
dependencies = [
|
|
184
185
|
"base64",
|
|
185
186
|
"buzz-core",
|
|
@@ -726,9 +727,9 @@ dependencies = [
|
|
|
726
727
|
|
|
727
728
|
[[package]]
|
|
728
729
|
name = "nostr"
|
|
729
|
-
version = "0.44.
|
|
730
|
+
version = "0.44.6"
|
|
730
731
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
731
|
-
checksum = "
|
|
732
|
+
checksum = "e826dd648489de2c5b293920e20b92932ef820302007c1987c758d4d06eeb2cf"
|
|
732
733
|
dependencies = [
|
|
733
734
|
"base64",
|
|
734
735
|
"bech32",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "buzzkit"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
publish = false
|
|
6
6
|
description = "PyO3 bindings over Block's Buzz zero-I/O crates (buzz-core / buzz-sdk)"
|
|
@@ -20,8 +20,8 @@ pyo3 = { version = "0.24", features = ["abi3-py312"] }
|
|
|
20
20
|
# Event/Keys/EventBuilder types unify across crate boundaries.
|
|
21
21
|
nostr = { version = "0.44", features = ["nip44", "nip98"] }
|
|
22
22
|
# Pinned to a specific Buzz commit; bump deliberately to track their kind churn.
|
|
23
|
-
buzz-core = { git = "https://github.com/block/buzz", rev = "
|
|
24
|
-
buzz-sdk = { git = "https://github.com/block/buzz", rev = "
|
|
23
|
+
buzz-core = { git = "https://github.com/block/buzz", rev = "209536ade6c5ebf7fa82671d7ca0b74f599a40cc", package = "buzz-core" }
|
|
24
|
+
buzz-sdk = { git = "https://github.com/block/buzz", rev = "209536ade6c5ebf7fa82671d7ca0b74f599a40cc", package = "buzz-sdk" }
|
|
25
25
|
uuid = { version = "1", features = ["v4"] }
|
|
26
26
|
sha2 = "0.10"
|
|
27
27
|
hex = "0.4"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: buzzkit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: Intended Audience :: Developers
|
|
6
6
|
Classifier: License :: OSI Approved :: MIT License
|
|
@@ -34,14 +34,14 @@ Project-URL: Repository, https://github.com/sboily/buzzkit
|
|
|
34
34
|
|
|
35
35
|
# buzzkit
|
|
36
36
|
|
|
37
|
-
Python bindings **and** an async client for [Block's **Buzz**](https://github.com/block/buzz)
|
|
38
|
-
|
|
37
|
+
Python bindings **and** an async client for [Block's **Buzz**](https://github.com/block/buzz),
|
|
38
|
+
the Nostr-based team workspace where humans and AI agents are first-class,
|
|
39
39
|
cryptographically-identified members.
|
|
40
40
|
|
|
41
41
|
The cryptographic core (Schnorr signing, event building, verification, NIP-42/98
|
|
42
42
|
auth) is done in **Rust**, binding Buzz's own zero-I/O crates
|
|
43
43
|
(`buzz-core` / `buzz-sdk`) via [PyO3](https://pyo3.rs). All network I/O is pure
|
|
44
|
-
Python, so the async story stays idiomatic
|
|
44
|
+
Python, so the async story stays idiomatic: no tokio ⇄ asyncio bridge.
|
|
45
45
|
|
|
46
46
|
> **Unofficial.** buzzkit is an independent project and is **not** affiliated
|
|
47
47
|
> with, sponsored by, or endorsed by Block, Inc.
|
|
@@ -75,26 +75,37 @@ from buzzkit import BuzzClient
|
|
|
75
75
|
async def main():
|
|
76
76
|
bz = BuzzClient("wss://your-community.communities.buzz.xyz", "<nsec>")
|
|
77
77
|
|
|
78
|
-
# HTTP bridge
|
|
78
|
+
# HTTP bridge: one-shot, no connection needed.
|
|
79
79
|
await bz.send_message("<channel-uuid>", "posted over HTTP")
|
|
80
80
|
await bz.set_profile("My Agent", about="an autonomous participant")
|
|
81
|
+
await bz.set_status("reviewing PRs", emoji="🤖")
|
|
81
82
|
|
|
82
|
-
# WebSocket
|
|
83
|
+
# WebSocket: real-time inbound.
|
|
83
84
|
async with bz: # connect() + NIP-42 auth
|
|
84
85
|
async for event in bz.subscribe_channel("<channel-uuid>"):
|
|
85
|
-
|
|
86
|
+
await bz.react(event["id"], "👍") # acknowledge receipt
|
|
87
|
+
await bz.send_message( # threaded reply
|
|
88
|
+
"<channel-uuid>", "on it!", reply_to=event["id"]
|
|
89
|
+
)
|
|
86
90
|
|
|
87
91
|
asyncio.run(main())
|
|
88
92
|
```
|
|
89
93
|
|
|
94
|
+
Messages can also be revised after the fact: `edit_message` replaces one of
|
|
95
|
+
your own messages in place, and `delete_message` publishes a tombstone with an
|
|
96
|
+
optional room-facing reason (useful for moderator agents).
|
|
97
|
+
|
|
90
98
|
### Huddle audio (voice)
|
|
91
99
|
|
|
92
100
|
Buzz huddles are ephemeral voice channels; audio is Opus (48 kHz mono, 20 ms
|
|
93
101
|
frames) over a dedicated WebSocket. `HuddleClient` handles the handshake,
|
|
94
|
-
Opus encode/decode (in Rust), and real-time outbound pacing
|
|
95
|
-
PCM (s16le mono 48 kHz):
|
|
102
|
+
Opus encode/decode (in Rust), and real-time outbound pacing, so you deal in
|
|
103
|
+
raw PCM (s16le mono 48 kHz):
|
|
96
104
|
|
|
97
105
|
```python
|
|
106
|
+
import json
|
|
107
|
+
|
|
108
|
+
import buzzkit
|
|
98
109
|
from buzzkit import BuzzClient, HuddleAudio, HuddleClient
|
|
99
110
|
|
|
100
111
|
# Huddles announce themselves as kind 48100 on their parent channel:
|
|
@@ -110,9 +121,25 @@ async with HuddleClient(relay_url, nsec, huddle_id, parent_channel_id=parent_id)
|
|
|
110
121
|
print(ev.pubkey, len(ev.pcm))
|
|
111
122
|
```
|
|
112
123
|
|
|
113
|
-
Being a member of the parent channel is enough
|
|
124
|
+
Being a member of the parent channel is enough: the relay auto-adds you to
|
|
114
125
|
the ephemeral huddle when `parent_channel_id` is given.
|
|
115
126
|
|
|
127
|
+
## Agent identity and ownership (NIP-OA)
|
|
128
|
+
|
|
129
|
+
Buzz shows agents as "managed by \<owner\>". The attestation is an `auth` tag
|
|
130
|
+
signed by the owner key; buzzkit can both produce it and verify it:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
tag = buzzkit.compute_auth_tag(owner_nsec, agent_pubkey_hex) # owner attests the agent
|
|
134
|
+
bz = BuzzClient(relay_url, agent_nsec, auth_tag=tag) # AUTH + profile carry it
|
|
135
|
+
await bz.set_profile("My Agent") # shows "managed by <owner>"
|
|
136
|
+
|
|
137
|
+
# "Which agent named Honey belongs to this owner?", cryptographically verified
|
|
138
|
+
# against the owner's managed-agent records (never by display name alone):
|
|
139
|
+
agents = await bz.resolve_agent("Honey", owner_pubkey_hex)
|
|
140
|
+
verified = [a for a in agents if a["verification"] == "verified"]
|
|
141
|
+
```
|
|
142
|
+
|
|
116
143
|
## Joining a community (relay onboarding)
|
|
117
144
|
|
|
118
145
|
Hosted Buzz communities are **closed relays**: an identity must be a relay member
|
|
@@ -136,14 +163,20 @@ claiming. After joining, `set_profile(...)` gives the agent a display name.
|
|
|
136
163
|
|---|---|
|
|
137
164
|
| `generate_keypair()` → `(nsec, npub, hex)` | new identity |
|
|
138
165
|
| `pubkey_from_secret(secret)` | derive `(npub, hex)` |
|
|
139
|
-
| `
|
|
166
|
+
| `build_*_event` (message/reply, reaction, edit, delete, profile, user status, channel, presence…) | build + sign events |
|
|
167
|
+
| `compute_auth_tag` / `verify_auth_tag` / `verify_agent_profile` | NIP-OA owner attestation |
|
|
140
168
|
| `sign_nip98(secret, method, url, body)` | HTTP bridge auth header |
|
|
141
169
|
| `verify_event(json)` | check id + Schnorr signature |
|
|
142
|
-
| `BuzzClient.send_message / set_profile / query / list_channels / claim_invite` | HTTP bridge |
|
|
143
|
-
| `BuzzClient.connect / subscribe / subscribe_channel / publish / close` | WebSocket |
|
|
170
|
+
| `BuzzClient.send_message / react / remove_reaction / edit_message / set_profile / set_status / resolve_agent / query / list_channels / claim_invite` | HTTP bridge |
|
|
171
|
+
| `BuzzClient.connect / subscribe / subscribe_channel / publish / join_channel / leave_channel / set_topic / delete_message / start_huddle / publish_presence / close` | WebSocket |
|
|
144
172
|
| `HuddleClient.connect / send_pcm / events / clear_queue / leave` | huddle voice (Opus) |
|
|
145
173
|
| `HuddleEncoder` / `HuddleDecoder` | raw huddle wire frames ↔ PCM |
|
|
146
174
|
|
|
175
|
+
Threaded replies: `send_message(..., reply_to=<event-id>)` (add
|
|
176
|
+
`reply_root=` for nested replies). Reconnect note: the relay closes with
|
|
177
|
+
code **1012** on graceful restart, so check `BuzzClient.close_code` in your
|
|
178
|
+
reconnect loop and dedupe replayed events by id.
|
|
179
|
+
|
|
147
180
|
## Build from source
|
|
148
181
|
|
|
149
182
|
Requires a Rust toolchain and [maturin](https://www.maturin.rs).
|
|
@@ -161,5 +194,5 @@ The Buzz crates are pinned via a Cargo `git` dependency in `Cargo.toml`; bump th
|
|
|
161
194
|
|
|
162
195
|
MIT (see [LICENSE](LICENSE)). The distributed wheels statically link Apache-2.0
|
|
163
196
|
components from Block's Buzz (`buzz-core` / `buzz-sdk`) and other permissive Rust
|
|
164
|
-
crates
|
|
197
|
+
crates; see [NOTICE](NOTICE) and [LICENSE-APACHE](LICENSE-APACHE).
|
|
165
198
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# buzzkit
|
|
2
2
|
|
|
3
|
-
Python bindings **and** an async client for [Block's **Buzz**](https://github.com/block/buzz)
|
|
4
|
-
|
|
3
|
+
Python bindings **and** an async client for [Block's **Buzz**](https://github.com/block/buzz),
|
|
4
|
+
the Nostr-based team workspace where humans and AI agents are first-class,
|
|
5
5
|
cryptographically-identified members.
|
|
6
6
|
|
|
7
7
|
The cryptographic core (Schnorr signing, event building, verification, NIP-42/98
|
|
8
8
|
auth) is done in **Rust**, binding Buzz's own zero-I/O crates
|
|
9
9
|
(`buzz-core` / `buzz-sdk`) via [PyO3](https://pyo3.rs). All network I/O is pure
|
|
10
|
-
Python, so the async story stays idiomatic
|
|
10
|
+
Python, so the async story stays idiomatic: no tokio ⇄ asyncio bridge.
|
|
11
11
|
|
|
12
12
|
> **Unofficial.** buzzkit is an independent project and is **not** affiliated
|
|
13
13
|
> with, sponsored by, or endorsed by Block, Inc.
|
|
@@ -41,26 +41,37 @@ from buzzkit import BuzzClient
|
|
|
41
41
|
async def main():
|
|
42
42
|
bz = BuzzClient("wss://your-community.communities.buzz.xyz", "<nsec>")
|
|
43
43
|
|
|
44
|
-
# HTTP bridge
|
|
44
|
+
# HTTP bridge: one-shot, no connection needed.
|
|
45
45
|
await bz.send_message("<channel-uuid>", "posted over HTTP")
|
|
46
46
|
await bz.set_profile("My Agent", about="an autonomous participant")
|
|
47
|
+
await bz.set_status("reviewing PRs", emoji="🤖")
|
|
47
48
|
|
|
48
|
-
# WebSocket
|
|
49
|
+
# WebSocket: real-time inbound.
|
|
49
50
|
async with bz: # connect() + NIP-42 auth
|
|
50
51
|
async for event in bz.subscribe_channel("<channel-uuid>"):
|
|
51
|
-
|
|
52
|
+
await bz.react(event["id"], "👍") # acknowledge receipt
|
|
53
|
+
await bz.send_message( # threaded reply
|
|
54
|
+
"<channel-uuid>", "on it!", reply_to=event["id"]
|
|
55
|
+
)
|
|
52
56
|
|
|
53
57
|
asyncio.run(main())
|
|
54
58
|
```
|
|
55
59
|
|
|
60
|
+
Messages can also be revised after the fact: `edit_message` replaces one of
|
|
61
|
+
your own messages in place, and `delete_message` publishes a tombstone with an
|
|
62
|
+
optional room-facing reason (useful for moderator agents).
|
|
63
|
+
|
|
56
64
|
### Huddle audio (voice)
|
|
57
65
|
|
|
58
66
|
Buzz huddles are ephemeral voice channels; audio is Opus (48 kHz mono, 20 ms
|
|
59
67
|
frames) over a dedicated WebSocket. `HuddleClient` handles the handshake,
|
|
60
|
-
Opus encode/decode (in Rust), and real-time outbound pacing
|
|
61
|
-
PCM (s16le mono 48 kHz):
|
|
68
|
+
Opus encode/decode (in Rust), and real-time outbound pacing, so you deal in
|
|
69
|
+
raw PCM (s16le mono 48 kHz):
|
|
62
70
|
|
|
63
71
|
```python
|
|
72
|
+
import json
|
|
73
|
+
|
|
74
|
+
import buzzkit
|
|
64
75
|
from buzzkit import BuzzClient, HuddleAudio, HuddleClient
|
|
65
76
|
|
|
66
77
|
# Huddles announce themselves as kind 48100 on their parent channel:
|
|
@@ -76,9 +87,25 @@ async with HuddleClient(relay_url, nsec, huddle_id, parent_channel_id=parent_id)
|
|
|
76
87
|
print(ev.pubkey, len(ev.pcm))
|
|
77
88
|
```
|
|
78
89
|
|
|
79
|
-
Being a member of the parent channel is enough
|
|
90
|
+
Being a member of the parent channel is enough: the relay auto-adds you to
|
|
80
91
|
the ephemeral huddle when `parent_channel_id` is given.
|
|
81
92
|
|
|
93
|
+
## Agent identity and ownership (NIP-OA)
|
|
94
|
+
|
|
95
|
+
Buzz shows agents as "managed by \<owner\>". The attestation is an `auth` tag
|
|
96
|
+
signed by the owner key; buzzkit can both produce it and verify it:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
tag = buzzkit.compute_auth_tag(owner_nsec, agent_pubkey_hex) # owner attests the agent
|
|
100
|
+
bz = BuzzClient(relay_url, agent_nsec, auth_tag=tag) # AUTH + profile carry it
|
|
101
|
+
await bz.set_profile("My Agent") # shows "managed by <owner>"
|
|
102
|
+
|
|
103
|
+
# "Which agent named Honey belongs to this owner?", cryptographically verified
|
|
104
|
+
# against the owner's managed-agent records (never by display name alone):
|
|
105
|
+
agents = await bz.resolve_agent("Honey", owner_pubkey_hex)
|
|
106
|
+
verified = [a for a in agents if a["verification"] == "verified"]
|
|
107
|
+
```
|
|
108
|
+
|
|
82
109
|
## Joining a community (relay onboarding)
|
|
83
110
|
|
|
84
111
|
Hosted Buzz communities are **closed relays**: an identity must be a relay member
|
|
@@ -102,14 +129,20 @@ claiming. After joining, `set_profile(...)` gives the agent a display name.
|
|
|
102
129
|
|---|---|
|
|
103
130
|
| `generate_keypair()` → `(nsec, npub, hex)` | new identity |
|
|
104
131
|
| `pubkey_from_secret(secret)` | derive `(npub, hex)` |
|
|
105
|
-
| `
|
|
132
|
+
| `build_*_event` (message/reply, reaction, edit, delete, profile, user status, channel, presence…) | build + sign events |
|
|
133
|
+
| `compute_auth_tag` / `verify_auth_tag` / `verify_agent_profile` | NIP-OA owner attestation |
|
|
106
134
|
| `sign_nip98(secret, method, url, body)` | HTTP bridge auth header |
|
|
107
135
|
| `verify_event(json)` | check id + Schnorr signature |
|
|
108
|
-
| `BuzzClient.send_message / set_profile / query / list_channels / claim_invite` | HTTP bridge |
|
|
109
|
-
| `BuzzClient.connect / subscribe / subscribe_channel / publish / close` | WebSocket |
|
|
136
|
+
| `BuzzClient.send_message / react / remove_reaction / edit_message / set_profile / set_status / resolve_agent / query / list_channels / claim_invite` | HTTP bridge |
|
|
137
|
+
| `BuzzClient.connect / subscribe / subscribe_channel / publish / join_channel / leave_channel / set_topic / delete_message / start_huddle / publish_presence / close` | WebSocket |
|
|
110
138
|
| `HuddleClient.connect / send_pcm / events / clear_queue / leave` | huddle voice (Opus) |
|
|
111
139
|
| `HuddleEncoder` / `HuddleDecoder` | raw huddle wire frames ↔ PCM |
|
|
112
140
|
|
|
141
|
+
Threaded replies: `send_message(..., reply_to=<event-id>)` (add
|
|
142
|
+
`reply_root=` for nested replies). Reconnect note: the relay closes with
|
|
143
|
+
code **1012** on graceful restart, so check `BuzzClient.close_code` in your
|
|
144
|
+
reconnect loop and dedupe replayed events by id.
|
|
145
|
+
|
|
113
146
|
## Build from source
|
|
114
147
|
|
|
115
148
|
Requires a Rust toolchain and [maturin](https://www.maturin.rs).
|
|
@@ -127,4 +160,4 @@ The Buzz crates are pinned via a Cargo `git` dependency in `Cargo.toml`; bump th
|
|
|
127
160
|
|
|
128
161
|
MIT (see [LICENSE](LICENSE)). The distributed wheels statically link Apache-2.0
|
|
129
162
|
components from Block's Buzz (`buzz-core` / `buzz-sdk`) and other permissive Rust
|
|
130
|
-
crates
|
|
163
|
+
crates; see [NOTICE](NOTICE) and [LICENSE-APACHE](LICENSE-APACHE).
|
|
@@ -44,7 +44,7 @@ def analyze_send_timing(rows: list[dict], t_key: str, label: str) -> None:
|
|
|
44
44
|
if len(times) < 2:
|
|
45
45
|
print(f" {label}: not enough rows")
|
|
46
46
|
return
|
|
47
|
-
deltas = [(b - a) / NS for a, b in zip(times, times[1:])]
|
|
47
|
+
deltas = [(b - a) / NS for a, b in zip(times, times[1:], strict=False)]
|
|
48
48
|
span_s = (times[-1] - times[0]) / NS / 1000
|
|
49
49
|
stalls = [(i, d) for i, d in enumerate(deltas) if d > 2 * FRAME_MS]
|
|
50
50
|
bursts = sum(1 for d in deltas if d < 2.0)
|
|
@@ -73,9 +73,9 @@ def analyze_wire_csv(path: pathlib.Path) -> None:
|
|
|
73
73
|
times = [int(r["t_mono_ns"]) for r in rows]
|
|
74
74
|
zero = [r["all_zero"] == "1" for r in rows]
|
|
75
75
|
t0 = times[0]
|
|
76
|
-
nonzero_times = [t for t, z in zip(times, zero) if not z]
|
|
76
|
+
nonzero_times = [t for t, z in zip(times, zero, strict=True) if not z]
|
|
77
77
|
spliced = []
|
|
78
|
-
for t, z in zip(times, zero):
|
|
78
|
+
for t, z in zip(times, zero, strict=True):
|
|
79
79
|
if not z or not nonzero_times:
|
|
80
80
|
continue
|
|
81
81
|
# nearest real-audio sends before/after this silence frame
|
|
@@ -112,7 +112,7 @@ def analyze_recv_csv(path: pathlib.Path) -> None:
|
|
|
112
112
|
# reordered between the sender and us; dts != dseq*960 means the
|
|
113
113
|
# sender's own media timeline jumped (encoder restart / bug).
|
|
114
114
|
lost = jumps = 0
|
|
115
|
-
for a, b in zip(frames, frames[1:]):
|
|
115
|
+
for a, b in zip(frames, frames[1:], strict=False):
|
|
116
116
|
dseq = (int(b["seq"]) - int(a["seq"])) % 65536
|
|
117
117
|
dts = (int(b["ts_48k"]) - int(a["ts_48k"])) % (1 << 32)
|
|
118
118
|
if dseq != 1:
|
|
@@ -33,6 +33,7 @@ Analyze the capture with examples/analyze_audio_tap.py.
|
|
|
33
33
|
from __future__ import annotations
|
|
34
34
|
|
|
35
35
|
import asyncio
|
|
36
|
+
import contextlib
|
|
36
37
|
import json
|
|
37
38
|
import pathlib
|
|
38
39
|
import sys
|
|
@@ -117,7 +118,5 @@ async def main() -> None:
|
|
|
117
118
|
|
|
118
119
|
|
|
119
120
|
if __name__ == "__main__":
|
|
120
|
-
|
|
121
|
+
with contextlib.suppress(KeyboardInterrupt):
|
|
121
122
|
asyncio.run(main())
|
|
122
|
-
except KeyboardInterrupt:
|
|
123
|
-
pass
|
|
@@ -4,7 +4,7 @@ build-backend = "maturin"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "buzzkit"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Python bindings + async client for Block's Buzz (Nostr) protocol, backed by Rust buzz-core/buzz-sdk"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.12"
|
|
@@ -9,6 +9,8 @@ This is an independent, unofficial project — not affiliated with Block, Inc.
|
|
|
9
9
|
|
|
10
10
|
from __future__ import annotations
|
|
11
11
|
|
|
12
|
+
from importlib.metadata import version as _version
|
|
13
|
+
|
|
12
14
|
from ._native import (
|
|
13
15
|
HUDDLE_FRAME_SAMPLES,
|
|
14
16
|
HUDDLE_PROTOCOL_VERSION,
|
|
@@ -16,30 +18,46 @@ from ._native import (
|
|
|
16
18
|
KIND_ADD_MEMBER,
|
|
17
19
|
KIND_AUTH,
|
|
18
20
|
KIND_CREATE_CHANNEL,
|
|
21
|
+
KIND_DELETE_MESSAGE,
|
|
22
|
+
KIND_DELETION,
|
|
23
|
+
KIND_EDIT_METADATA,
|
|
19
24
|
KIND_HTTP_AUTH,
|
|
20
25
|
KIND_HUDDLE_ENDED,
|
|
21
26
|
KIND_HUDDLE_PARTICIPANT_JOINED,
|
|
22
27
|
KIND_HUDDLE_PARTICIPANT_LEFT,
|
|
23
28
|
KIND_HUDDLE_STARTED,
|
|
29
|
+
KIND_LEAVE_CHANNEL,
|
|
30
|
+
KIND_MANAGED_AGENT,
|
|
31
|
+
KIND_MESSAGE_EDIT,
|
|
24
32
|
KIND_PRESENCE_UPDATE,
|
|
25
33
|
KIND_REACTION,
|
|
26
34
|
KIND_STREAM_MESSAGE,
|
|
27
35
|
KIND_STREAM_MESSAGE_V2,
|
|
36
|
+
KIND_USER_STATUS,
|
|
28
37
|
HuddleDecoder,
|
|
29
38
|
HuddleEncoder,
|
|
30
39
|
build_auth_event,
|
|
31
40
|
build_create_channel_event,
|
|
41
|
+
build_delete_message_event,
|
|
42
|
+
build_edit_event,
|
|
32
43
|
build_huddle_started_event,
|
|
33
44
|
build_join_channel_event,
|
|
45
|
+
build_leave_event,
|
|
34
46
|
build_message_event,
|
|
35
47
|
build_presence_event,
|
|
36
48
|
build_profile_event,
|
|
49
|
+
build_reaction_event,
|
|
50
|
+
build_remove_reaction_event,
|
|
51
|
+
build_set_topic_event,
|
|
52
|
+
build_user_status_event,
|
|
37
53
|
compute_auth_tag,
|
|
38
54
|
generate_keypair,
|
|
39
55
|
pubkey_from_secret,
|
|
40
56
|
sign_nip98,
|
|
57
|
+
verify_auth_tag,
|
|
41
58
|
verify_event,
|
|
42
59
|
)
|
|
60
|
+
from .agents import verify_agent_profile
|
|
43
61
|
from .client import BuzzClient
|
|
44
62
|
from .huddle import (
|
|
45
63
|
HuddleAudio,
|
|
@@ -50,7 +68,7 @@ from .huddle import (
|
|
|
50
68
|
HuddlePeerLeft,
|
|
51
69
|
)
|
|
52
70
|
|
|
53
|
-
__version__ = "
|
|
71
|
+
__version__ = _version("buzzkit")
|
|
54
72
|
|
|
55
73
|
__all__ = [
|
|
56
74
|
"HUDDLE_FRAME_SAMPLES",
|
|
@@ -59,15 +77,22 @@ __all__ = [
|
|
|
59
77
|
"KIND_ADD_MEMBER",
|
|
60
78
|
"KIND_AUTH",
|
|
61
79
|
"KIND_CREATE_CHANNEL",
|
|
80
|
+
"KIND_DELETE_MESSAGE",
|
|
81
|
+
"KIND_DELETION",
|
|
82
|
+
"KIND_EDIT_METADATA",
|
|
62
83
|
"KIND_HTTP_AUTH",
|
|
63
84
|
"KIND_HUDDLE_ENDED",
|
|
64
85
|
"KIND_HUDDLE_PARTICIPANT_JOINED",
|
|
65
86
|
"KIND_HUDDLE_PARTICIPANT_LEFT",
|
|
66
87
|
"KIND_HUDDLE_STARTED",
|
|
88
|
+
"KIND_LEAVE_CHANNEL",
|
|
89
|
+
"KIND_MANAGED_AGENT",
|
|
90
|
+
"KIND_MESSAGE_EDIT",
|
|
67
91
|
"KIND_PRESENCE_UPDATE",
|
|
68
92
|
"KIND_REACTION",
|
|
69
93
|
"KIND_STREAM_MESSAGE",
|
|
70
94
|
"KIND_STREAM_MESSAGE_V2",
|
|
95
|
+
"KIND_USER_STATUS",
|
|
71
96
|
"BuzzClient",
|
|
72
97
|
"HuddleAudio",
|
|
73
98
|
"HuddleClient",
|
|
@@ -79,14 +104,23 @@ __all__ = [
|
|
|
79
104
|
"HuddlePeerLeft",
|
|
80
105
|
"build_auth_event",
|
|
81
106
|
"build_create_channel_event",
|
|
107
|
+
"build_delete_message_event",
|
|
108
|
+
"build_edit_event",
|
|
82
109
|
"build_huddle_started_event",
|
|
83
110
|
"build_join_channel_event",
|
|
111
|
+
"build_leave_event",
|
|
84
112
|
"build_message_event",
|
|
85
113
|
"build_presence_event",
|
|
86
114
|
"build_profile_event",
|
|
115
|
+
"build_reaction_event",
|
|
116
|
+
"build_remove_reaction_event",
|
|
117
|
+
"build_set_topic_event",
|
|
118
|
+
"build_user_status_event",
|
|
87
119
|
"compute_auth_tag",
|
|
88
120
|
"generate_keypair",
|
|
89
121
|
"pubkey_from_secret",
|
|
90
122
|
"sign_nip98",
|
|
123
|
+
"verify_agent_profile",
|
|
124
|
+
"verify_auth_tag",
|
|
91
125
|
"verify_event",
|
|
92
126
|
]
|
|
@@ -7,9 +7,37 @@ def pubkey_from_secret(secret: str) -> tuple[str, str]:
|
|
|
7
7
|
"""Return ``(npub, pubkey_hex)`` for a secret (hex or ``nsec…``)."""
|
|
8
8
|
|
|
9
9
|
def build_message_event(
|
|
10
|
-
secret: str,
|
|
10
|
+
secret: str,
|
|
11
|
+
channel_id: str,
|
|
12
|
+
content: str,
|
|
13
|
+
mentions: list[str] | None = ...,
|
|
14
|
+
reply_to: str | None = ...,
|
|
15
|
+
reply_root: str | None = ...,
|
|
11
16
|
) -> str:
|
|
12
|
-
"""Build + sign a channel message (kind 9); returns NIP-01 event JSON.
|
|
17
|
+
"""Build + sign a channel message (kind 9); returns NIP-01 event JSON.
|
|
18
|
+
|
|
19
|
+
``reply_to`` threads the message; ``reply_root`` marks a nested reply.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
def build_reaction_event(secret: str, target_event_id: str, emoji: str) -> str:
|
|
23
|
+
"""Build + sign a reaction (kind 7) to an event."""
|
|
24
|
+
|
|
25
|
+
def build_remove_reaction_event(secret: str, reaction_event_id: str) -> str:
|
|
26
|
+
"""Build + sign a deletion (kind 5) of one of our own reactions."""
|
|
27
|
+
|
|
28
|
+
def build_edit_event(secret: str, channel_id: str, target_event_id: str, new_content: str) -> str:
|
|
29
|
+
"""Build + sign a message edit (kind 40003)."""
|
|
30
|
+
|
|
31
|
+
def build_delete_message_event(
|
|
32
|
+
secret: str, channel_id: str, target_event_id: str, reason: str | None = ...
|
|
33
|
+
) -> str:
|
|
34
|
+
"""Build + sign a message delete tombstone (kind 9005)."""
|
|
35
|
+
|
|
36
|
+
def build_set_topic_event(secret: str, channel_id: str, topic: str) -> str:
|
|
37
|
+
"""Build + sign a channel topic change (kind 9002)."""
|
|
38
|
+
|
|
39
|
+
def build_leave_event(secret: str, channel_id: str) -> str:
|
|
40
|
+
"""Build + sign a channel leave request (kind 9022)."""
|
|
13
41
|
|
|
14
42
|
def build_profile_event(
|
|
15
43
|
secret: str,
|
|
@@ -48,6 +76,9 @@ def build_huddle_started_event(
|
|
|
48
76
|
def build_presence_event(secret: str, status: str = ...) -> str:
|
|
49
77
|
"""Build + sign a presence event (kind 20001); status online/away/offline."""
|
|
50
78
|
|
|
79
|
+
def build_user_status_event(secret: str, text: str, emoji: str | None = ...) -> str:
|
|
80
|
+
"""Build + sign a NIP-38 user status event (kind 30315, ``d:general``)."""
|
|
81
|
+
|
|
51
82
|
def build_auth_event(
|
|
52
83
|
secret: str, challenge: str, relay_url: str, auth_tag: str | None = ...
|
|
53
84
|
) -> str:
|
|
@@ -56,6 +87,9 @@ def build_auth_event(
|
|
|
56
87
|
def compute_auth_tag(owner_secret: str, agent_pubkey_hex: str, conditions: str = ...) -> str:
|
|
57
88
|
"""Compute a NIP-OA owner-attestation tag JSON attesting an agent pubkey."""
|
|
58
89
|
|
|
90
|
+
def verify_auth_tag(auth_tag_json: str, agent_pubkey_hex: str) -> str:
|
|
91
|
+
"""Verify a NIP-OA auth tag against an agent pubkey; returns the owner hex."""
|
|
92
|
+
|
|
59
93
|
def sign_nip98(secret: str, method: str, url: str, body: bytes | None = ...) -> str:
|
|
60
94
|
"""Return an ``Authorization: Nostr <base64>`` header value (NIP-98)."""
|
|
61
95
|
|
|
@@ -85,14 +119,21 @@ class HuddleDecoder:
|
|
|
85
119
|
def remove_peer(self, peer_index: int) -> None:
|
|
86
120
|
"""Forget a peer's decoder state (indexes are recycled by the relay)."""
|
|
87
121
|
|
|
122
|
+
KIND_DELETION: int
|
|
88
123
|
KIND_REACTION: int
|
|
89
124
|
KIND_STREAM_MESSAGE: int
|
|
125
|
+
KIND_EDIT_METADATA: int
|
|
126
|
+
KIND_DELETE_MESSAGE: int
|
|
127
|
+
KIND_LEAVE_CHANNEL: int
|
|
128
|
+
KIND_MESSAGE_EDIT: int
|
|
90
129
|
KIND_PRESENCE_UPDATE: int
|
|
91
130
|
KIND_AUTH: int
|
|
92
131
|
KIND_HTTP_AUTH: int
|
|
93
132
|
KIND_STREAM_MESSAGE_V2: int
|
|
94
133
|
KIND_ADD_MEMBER: int
|
|
95
134
|
KIND_CREATE_CHANNEL: int
|
|
135
|
+
KIND_MANAGED_AGENT: int
|
|
136
|
+
KIND_USER_STATUS: int
|
|
96
137
|
KIND_HUDDLE_STARTED: int
|
|
97
138
|
KIND_HUDDLE_PARTICIPANT_JOINED: int
|
|
98
139
|
KIND_HUDDLE_PARTICIPANT_LEFT: int
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""NIP-OA agent ownership verification.
|
|
2
|
+
|
|
3
|
+
Mirrors the reference algorithm from upstream buzz-cli (#3178): an agent's
|
|
4
|
+
kind-0 profile asserts ownership only when it carries *exactly one* `auth`
|
|
5
|
+
tag whose Schnorr signature verifies against the claimed owner AND whose
|
|
6
|
+
conditions (`kind=…`, `created_at<…`, `created_at>…`) apply to the profile
|
|
7
|
+
event itself.
|
|
8
|
+
|
|
9
|
+
Pure functions — no I/O. :meth:`BuzzClient.resolve_agent` does the relay side.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import string
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from . import _native
|
|
19
|
+
|
|
20
|
+
_HEX_LOWER = set(string.digits + "abcdef")
|
|
21
|
+
|
|
22
|
+
#: Possible return values of :func:`verify_agent_profile`, mirroring upstream.
|
|
23
|
+
VERIFICATIONS = (
|
|
24
|
+
"verified",
|
|
25
|
+
"missing_auth",
|
|
26
|
+
"multiple_auth_tags",
|
|
27
|
+
"invalid_auth",
|
|
28
|
+
"owner_mismatch",
|
|
29
|
+
"condition_mismatch",
|
|
30
|
+
"invalid_agent_pubkey",
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _auth_tags(event: dict[str, Any]) -> list[list]:
|
|
35
|
+
tags = event.get("tags")
|
|
36
|
+
if not isinstance(tags, list):
|
|
37
|
+
return []
|
|
38
|
+
return [t for t in tags if isinstance(t, list) and t and t[0] == "auth"]
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _conditions_apply(conditions: str, event: dict[str, Any]) -> bool:
|
|
42
|
+
"""Do the auth tag's conditions hold for this event? Empty clauses hold."""
|
|
43
|
+
kind = event.get("kind")
|
|
44
|
+
created_at = event.get("created_at")
|
|
45
|
+
if not isinstance(kind, int) or not isinstance(created_at, int):
|
|
46
|
+
return False
|
|
47
|
+
for clause in conditions.split("&"):
|
|
48
|
+
if clause.startswith("kind="):
|
|
49
|
+
ok = clause[len("kind=") :] == str(kind)
|
|
50
|
+
elif clause.startswith("created_at<"):
|
|
51
|
+
bound = clause[len("created_at<") :]
|
|
52
|
+
ok = bound.isdigit() and created_at < int(bound)
|
|
53
|
+
elif clause.startswith("created_at>"):
|
|
54
|
+
bound = clause[len("created_at>") :]
|
|
55
|
+
ok = bound.isdigit() and created_at > int(bound)
|
|
56
|
+
else:
|
|
57
|
+
ok = clause == ""
|
|
58
|
+
if not ok:
|
|
59
|
+
return False
|
|
60
|
+
return True
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def verify_agent_profile(profile_event: dict[str, Any], owner_pubkey_hex: str) -> str:
|
|
64
|
+
"""Verify that an agent's kind-0 profile is attested by ``owner_pubkey_hex``.
|
|
65
|
+
|
|
66
|
+
Returns one of :data:`VERIFICATIONS`; only ``"verified"`` asserts
|
|
67
|
+
ownership. ``profile_event`` is the parsed NIP-01 event dict.
|
|
68
|
+
"""
|
|
69
|
+
agent_pubkey = profile_event.get("pubkey")
|
|
70
|
+
if (
|
|
71
|
+
not isinstance(agent_pubkey, str)
|
|
72
|
+
or len(agent_pubkey) != 64
|
|
73
|
+
or not set(agent_pubkey) <= _HEX_LOWER
|
|
74
|
+
):
|
|
75
|
+
return "invalid_agent_pubkey"
|
|
76
|
+
tags = _auth_tags(profile_event)
|
|
77
|
+
if not tags:
|
|
78
|
+
return "missing_auth"
|
|
79
|
+
if len(tags) > 1:
|
|
80
|
+
return "multiple_auth_tags"
|
|
81
|
+
tag = tags[0]
|
|
82
|
+
try:
|
|
83
|
+
owner = _native.verify_auth_tag(json.dumps(tag), agent_pubkey)
|
|
84
|
+
except ValueError as e:
|
|
85
|
+
# from_hex accepted 64 lowercase hex that is not a curve point
|
|
86
|
+
return "invalid_agent_pubkey" if "invalid agent pubkey" in str(e) else "invalid_auth"
|
|
87
|
+
if owner != owner_pubkey_hex:
|
|
88
|
+
return "owner_mismatch"
|
|
89
|
+
if not _conditions_apply(tag[2], profile_event):
|
|
90
|
+
return "condition_mismatch"
|
|
91
|
+
return "verified"
|