bnbagent 0.0.1__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.
- bnbagent-0.0.1/.github/workflows/release.yaml +132 -0
- bnbagent-0.0.1/.gitignore +61 -0
- bnbagent-0.0.1/LICENSE +21 -0
- bnbagent-0.0.1/PKG-INFO +211 -0
- bnbagent-0.0.1/README.md +180 -0
- bnbagent-0.0.1/bnbagent/README.md +578 -0
- bnbagent-0.0.1/bnbagent/__init__.py +23 -0
- bnbagent-0.0.1/bnbagent/abis/IdentityRegistry.json +1044 -0
- bnbagent-0.0.1/bnbagent/constants.py +16 -0
- bnbagent-0.0.1/bnbagent/contract.py +408 -0
- bnbagent-0.0.1/bnbagent/erc8004_agent.py +719 -0
- bnbagent-0.0.1/bnbagent/models.py +78 -0
- bnbagent-0.0.1/bnbagent/paymaster.py +266 -0
- bnbagent-0.0.1/bnbagent/utils/__init__.py +11 -0
- bnbagent-0.0.1/bnbagent/utils/agent_uri.py +224 -0
- bnbagent-0.0.1/bnbagent/utils/logger.py +44 -0
- bnbagent-0.0.1/bnbagent/utils/state_file.py +146 -0
- bnbagent-0.0.1/bnbagent/wallets/__init__.py +12 -0
- bnbagent-0.0.1/bnbagent/wallets/evm_wallet_provider.py +324 -0
- bnbagent-0.0.1/bnbagent/wallets/mpc_wallet_provider.py +59 -0
- bnbagent-0.0.1/bnbagent/wallets/wallet_provider.py +55 -0
- bnbagent-0.0.1/examples/testnet_usage.py +106 -0
- bnbagent-0.0.1/pyproject.toml +67 -0
- bnbagent-0.0.1/tests/README.md +48 -0
- bnbagent-0.0.1/tests/__init__.py +3 -0
- bnbagent-0.0.1/tests/test_agent_uri.py +150 -0
- bnbagent-0.0.1/tests/test_models.py +107 -0
- bnbagent-0.0.1/tests/test_sdk.py +484 -0
- bnbagent-0.0.1/tests/test_wallet.py +294 -0
- bnbagent-0.0.1/uv.lock +1905 -0
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
name: Release bnbagent to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
inputs:
|
|
6
|
+
version:
|
|
7
|
+
description: 'Version to release (e.g., 0.1.0)'
|
|
8
|
+
required: true
|
|
9
|
+
type: string
|
|
10
|
+
release_to_prod:
|
|
11
|
+
description: 'Release to production PyPI (unchecked = test PyPI)'
|
|
12
|
+
required: false
|
|
13
|
+
default: false
|
|
14
|
+
type: boolean
|
|
15
|
+
skip_tests:
|
|
16
|
+
description: 'Skip tests before release'
|
|
17
|
+
required: false
|
|
18
|
+
default: false
|
|
19
|
+
type: boolean
|
|
20
|
+
|
|
21
|
+
jobs:
|
|
22
|
+
release:
|
|
23
|
+
name: Build and Publish to PyPI
|
|
24
|
+
runs-on: ubuntu-latest
|
|
25
|
+
permissions:
|
|
26
|
+
contents: write
|
|
27
|
+
id-token: write # Required for trusted publishing to PyPI
|
|
28
|
+
|
|
29
|
+
steps:
|
|
30
|
+
- name: Checkout code
|
|
31
|
+
uses: actions/checkout@v4
|
|
32
|
+
with:
|
|
33
|
+
fetch-depth: 0 # Fetch all history for tags
|
|
34
|
+
|
|
35
|
+
- name: Set up Python
|
|
36
|
+
uses: actions/setup-python@v5
|
|
37
|
+
with:
|
|
38
|
+
python-version: '3.12'
|
|
39
|
+
|
|
40
|
+
- name: Install uv
|
|
41
|
+
uses: astral-sh/setup-uv@v4
|
|
42
|
+
with:
|
|
43
|
+
version: "latest"
|
|
44
|
+
|
|
45
|
+
- name: Install dependencies
|
|
46
|
+
run: |
|
|
47
|
+
uv sync --extra dev
|
|
48
|
+
|
|
49
|
+
- name: Run tests
|
|
50
|
+
if: ${{ !inputs.skip_tests }}
|
|
51
|
+
run: |
|
|
52
|
+
uv run pytest -v
|
|
53
|
+
|
|
54
|
+
- name: Update version in pyproject.toml
|
|
55
|
+
run: |
|
|
56
|
+
# Update version in pyproject.toml
|
|
57
|
+
sed -i 's/^version = ".*"/version = "${{ inputs.version }}"/' pyproject.toml
|
|
58
|
+
echo "Updated version to ${{ inputs.version }}"
|
|
59
|
+
cat pyproject.toml | grep "^version"
|
|
60
|
+
|
|
61
|
+
- name: Build package
|
|
62
|
+
run: |
|
|
63
|
+
uv build
|
|
64
|
+
|
|
65
|
+
- name: Check package contents
|
|
66
|
+
run: |
|
|
67
|
+
ls -lh dist/
|
|
68
|
+
echo "Package files:"
|
|
69
|
+
find dist -type f
|
|
70
|
+
|
|
71
|
+
- name: Publish to Production PyPI
|
|
72
|
+
if: ${{ inputs.release_to_prod }}
|
|
73
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
74
|
+
with:
|
|
75
|
+
packages-dir: ./dist/
|
|
76
|
+
print-hash: true
|
|
77
|
+
password: ${{ secrets.PYPI_API_TOKEN }}
|
|
78
|
+
# Uses trusted publishing (OIDC) - no token needed
|
|
79
|
+
# Configure OIDC in PyPI account settings: https://pypi.org/manage/account/publishing/
|
|
80
|
+
|
|
81
|
+
- name: Publish to Test PyPI
|
|
82
|
+
if: ${{ !inputs.release_to_prod }}
|
|
83
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
84
|
+
with:
|
|
85
|
+
packages-dir: ./dist/
|
|
86
|
+
print-hash: true
|
|
87
|
+
repository-url: https://test.pypi.org/legacy/
|
|
88
|
+
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
|
|
89
|
+
# For Test PyPI, you can use trusted publishing or API token
|
|
90
|
+
# If using API token, set TEST_PYPI_API_TOKEN secret
|
|
91
|
+
|
|
92
|
+
- name: Commit version update
|
|
93
|
+
if: success() && inputs.release_to_prod
|
|
94
|
+
run: |
|
|
95
|
+
git config user.name "github-actions[bot]"
|
|
96
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
97
|
+
git add pyproject.toml
|
|
98
|
+
git commit -m "chore: bump version to ${{ inputs.version }}" || exit 0
|
|
99
|
+
git push origin HEAD:${{ github.ref_name }} || echo "No changes to commit or branch protection"
|
|
100
|
+
|
|
101
|
+
- name: Create Git tag
|
|
102
|
+
if: success() && inputs.release_to_prod
|
|
103
|
+
run: |
|
|
104
|
+
git config user.name "github-actions[bot]"
|
|
105
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
106
|
+
git tag -a "bnbagent-v${{ inputs.version }}" -m "Release bnbagent v${{ inputs.version }}"
|
|
107
|
+
git push origin "bnbagent-v${{ inputs.version }}"
|
|
108
|
+
|
|
109
|
+
- name: Create GitHub Release
|
|
110
|
+
if: success() && inputs.release_to_prod
|
|
111
|
+
uses: softprops/action-gh-release@v1
|
|
112
|
+
with:
|
|
113
|
+
tag_name: bnbagent-v${{ inputs.version }}
|
|
114
|
+
name: bnbagent v${{ inputs.version }}
|
|
115
|
+
body: |
|
|
116
|
+
## bnbagent v${{ inputs.version }}
|
|
117
|
+
|
|
118
|
+
Python SDK for ERC-8004 on-chain agent registration and management.
|
|
119
|
+
|
|
120
|
+
### Installation
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
pip install bnbagent==${{ inputs.version }}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
✅ Published to **Production PyPI**
|
|
127
|
+
|
|
128
|
+
### Changes
|
|
129
|
+
|
|
130
|
+
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md) for details.
|
|
131
|
+
draft: false
|
|
132
|
+
prerelease: false
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
.Python
|
|
7
|
+
build/
|
|
8
|
+
develop-eggs/
|
|
9
|
+
dist/
|
|
10
|
+
downloads/
|
|
11
|
+
eggs/
|
|
12
|
+
.eggs/
|
|
13
|
+
lib/
|
|
14
|
+
lib64/
|
|
15
|
+
parts/
|
|
16
|
+
sdist/
|
|
17
|
+
var/
|
|
18
|
+
wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
|
|
23
|
+
# Virtual environments
|
|
24
|
+
venv/
|
|
25
|
+
env/
|
|
26
|
+
ENV/
|
|
27
|
+
.venv/
|
|
28
|
+
|
|
29
|
+
# IDE
|
|
30
|
+
.vscode/
|
|
31
|
+
.idea/
|
|
32
|
+
*.swp
|
|
33
|
+
*.swo
|
|
34
|
+
*~
|
|
35
|
+
|
|
36
|
+
# Key files (NEVER commit private keys!)
|
|
37
|
+
.bnbagent_state
|
|
38
|
+
*.key
|
|
39
|
+
*.pem
|
|
40
|
+
*.keystore
|
|
41
|
+
|
|
42
|
+
# Environment variables
|
|
43
|
+
.env
|
|
44
|
+
.env.local
|
|
45
|
+
|
|
46
|
+
# Testing
|
|
47
|
+
.pytest_cache/
|
|
48
|
+
.coverage
|
|
49
|
+
htmlcov/
|
|
50
|
+
.tox/
|
|
51
|
+
|
|
52
|
+
# Type checking / Linting
|
|
53
|
+
.mypy_cache/
|
|
54
|
+
.ruff_cache/
|
|
55
|
+
|
|
56
|
+
# Logs
|
|
57
|
+
*.log
|
|
58
|
+
|
|
59
|
+
# OS
|
|
60
|
+
.DS_Store
|
|
61
|
+
Thumbs.db
|
bnbagent-0.0.1/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BNBChain Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bnbagent-0.0.1/PKG-INFO
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bnbagent
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Python SDK for ERC-8004 on-chain agent registration and management
|
|
5
|
+
Project-URL: Homepage, https://github.com/bnb-chain/bnbagent-sdk
|
|
6
|
+
Project-URL: Documentation, https://github.com/bnb-chain/bnbagent-sdk#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/bnb-chain/bnbagent-sdk
|
|
8
|
+
Project-URL: Issues, https://github.com/bnb-chain/bnbagent-sdk/issues
|
|
9
|
+
Author-email: Your Name <your.email@example.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agent,binance-smart-chain,blockchain,bsc,erc-8004,ethereum,sdk,web3
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Topic :: Internet
|
|
21
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Requires-Dist: eth-account>=0.10.0
|
|
24
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
25
|
+
Requires-Dist: requests>=2.31.0
|
|
26
|
+
Requires-Dist: web3>=6.15.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-mock>=3.11.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest>=7.4.0; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# BNBAgent SDK
|
|
33
|
+
|
|
34
|
+
Python SDK for ERC-8004 on-chain agent registration and management.
|
|
35
|
+
|
|
36
|
+
## Features
|
|
37
|
+
|
|
38
|
+
- **Agent Registration**: Register AI agents on-chain via ERC-8004 Identity Registry
|
|
39
|
+
- **Agent Discovery**: Query and browse registered agents
|
|
40
|
+
- **Zero Gas Fees**: MegaFuel Paymaster sponsorship for contract operations
|
|
41
|
+
- **Keystore Encryption**: Password-protected wallet (Keystore V3, compatible with MetaMask/Geth)
|
|
42
|
+
- **Extensible Wallet**: WalletProvider abstraction for EVM/MPC wallets
|
|
43
|
+
|
|
44
|
+
## Network
|
|
45
|
+
|
|
46
|
+
### BSC Testnet (Chain ID: 97)
|
|
47
|
+
|
|
48
|
+
| Contract | Address |
|
|
49
|
+
|----------|---------|
|
|
50
|
+
| Identity Registry | `0x8004A818BFB912233c491871b3d84c89A494BD9e` |
|
|
51
|
+
| Reputation Registry | `0x8004B663056A597Dffe9eCcC1965A193B7388713` |
|
|
52
|
+
|
|
53
|
+
### BSC Mainnet (Chain ID: 56)
|
|
54
|
+
|
|
55
|
+
> **Note:** Mainnet support is not yet available. It will be supported soon. Stay tuned!
|
|
56
|
+
|
|
57
|
+
## Installation
|
|
58
|
+
|
|
59
|
+
> **Requirements:** Python 3.10+ and `uv` (recommended) or `pip`
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install git+https://github.com/bnb-chain/bnbagent-sdk.git
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For development:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/bnb-chain/bnbagent-sdk.git
|
|
69
|
+
cd bnbagent-sdk
|
|
70
|
+
uv sync --extra dev # or: pip install -e ".[dev]"
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## Quick Start
|
|
74
|
+
|
|
75
|
+
```python
|
|
76
|
+
import os
|
|
77
|
+
from bnbagent import ERC8004Agent, EVMWalletProvider, AgentEndpoint
|
|
78
|
+
|
|
79
|
+
# Create wallet and SDK
|
|
80
|
+
wallet = EVMWalletProvider(password=os.getenv("WALLET_PASSWORD"))
|
|
81
|
+
sdk = ERC8004Agent(wallet_provider=wallet, network="bsc-testnet")
|
|
82
|
+
|
|
83
|
+
# Generate and register agent
|
|
84
|
+
agent_uri = sdk.generate_agent_uri(
|
|
85
|
+
name="My Agent",
|
|
86
|
+
description="A test agent",
|
|
87
|
+
endpoints=[
|
|
88
|
+
AgentEndpoint(
|
|
89
|
+
name="A2A",
|
|
90
|
+
endpoint="https://agent.example/.well-known/agent-card.json",
|
|
91
|
+
version="0.3.0"
|
|
92
|
+
)
|
|
93
|
+
]
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
result = sdk.register_agent(agent_uri=agent_uri)
|
|
97
|
+
print(f"Agent registered with ID: {result['agentId']}")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Core Operations
|
|
101
|
+
|
|
102
|
+
### Register Agent
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
result = sdk.register_agent(agent_uri=agent_uri)
|
|
106
|
+
# Returns: {agentId, transactionHash, agentURI, ...}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Discover Agents
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
# List agents with pagination
|
|
113
|
+
agents = sdk.get_all_agents(limit=10, offset=0)
|
|
114
|
+
for agent in agents['items']:
|
|
115
|
+
print(f"#{agent['token_id']}: {agent['name']}")
|
|
116
|
+
|
|
117
|
+
# Get single agent info (on-chain)
|
|
118
|
+
info = sdk.get_agent_info(agent_id=1)
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Update Agent
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
new_uri = sdk.generate_agent_uri(
|
|
125
|
+
name="Updated Agent",
|
|
126
|
+
description="New description",
|
|
127
|
+
endpoints=[...],
|
|
128
|
+
agent_id=1 # Include for registrations field
|
|
129
|
+
)
|
|
130
|
+
sdk.set_agent_uri(agent_id=1, agent_uri=new_uri)
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Metadata
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
# Get/set metadata
|
|
137
|
+
version = sdk.get_metadata(agent_id=1, key="version")
|
|
138
|
+
sdk.set_metadata(agent_id=1, key="version", value="2.0.0")
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Examples
|
|
142
|
+
|
|
143
|
+
See [`examples/testnet_usage.py`](examples/testnet_usage.py) for a complete working example including:
|
|
144
|
+
- Wallet creation and management
|
|
145
|
+
- Agent registration
|
|
146
|
+
- Agent discovery and querying
|
|
147
|
+
- Metadata operations
|
|
148
|
+
|
|
149
|
+
## Documentation
|
|
150
|
+
|
|
151
|
+
- **[API Reference](bnbagent/README.md)** - Complete API documentation with workflow examples
|
|
152
|
+
|
|
153
|
+
## Security
|
|
154
|
+
|
|
155
|
+
The SDK stores encrypted wallet state in `.bnbagent_state`:
|
|
156
|
+
|
|
157
|
+
- **Encryption**: AES-128-CTR with scrypt key derivation (Keystore V3)
|
|
158
|
+
- **File permissions**: `0o600` (owner read/write only)
|
|
159
|
+
- **Format**: Compatible with MetaMask/Geth keystore
|
|
160
|
+
|
|
161
|
+
### Best Practices
|
|
162
|
+
|
|
163
|
+
1. **Never commit secrets**: Add `.bnbagent_state` to `.gitignore`
|
|
164
|
+
2. **Use environment variables**: Store `WALLET_PASSWORD` in env, not in code
|
|
165
|
+
3. **Backup your wallet**: Export keystore JSON and store securely
|
|
166
|
+
|
|
167
|
+
```python
|
|
168
|
+
# Export wallet for backup
|
|
169
|
+
keystore = wallet.export_keystore()
|
|
170
|
+
with open("backup-wallet.json", "w") as f:
|
|
171
|
+
json.dump(keystore, f)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### Environment Variables
|
|
175
|
+
|
|
176
|
+
| Variable | Description |
|
|
177
|
+
|----------|-------------|
|
|
178
|
+
| `WALLET_PASSWORD` | Password for wallet encryption/decryption |
|
|
179
|
+
|
|
180
|
+
## Error Handling
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
try:
|
|
184
|
+
result = sdk.register_agent(agent_uri=agent_uri)
|
|
185
|
+
except ConnectionError as e:
|
|
186
|
+
print(f"RPC connection failed: {e}")
|
|
187
|
+
except ValueError as e:
|
|
188
|
+
print(f"Invalid input: {e}")
|
|
189
|
+
except RuntimeError as e:
|
|
190
|
+
print(f"Transaction failed: {e}")
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Development
|
|
194
|
+
|
|
195
|
+
### Running Tests
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
uv run pytest # Run tests
|
|
199
|
+
uv run pytest --cov=bnbagent # With coverage
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Contributing
|
|
203
|
+
|
|
204
|
+
1. Follow existing code patterns
|
|
205
|
+
2. Include error handling
|
|
206
|
+
3. Add tests for new features
|
|
207
|
+
4. Run tests before submitting
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
This SDK is part of the ERC-8004 implementation project.
|
bnbagent-0.0.1/README.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# BNBAgent SDK
|
|
2
|
+
|
|
3
|
+
Python SDK for ERC-8004 on-chain agent registration and management.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Agent Registration**: Register AI agents on-chain via ERC-8004 Identity Registry
|
|
8
|
+
- **Agent Discovery**: Query and browse registered agents
|
|
9
|
+
- **Zero Gas Fees**: MegaFuel Paymaster sponsorship for contract operations
|
|
10
|
+
- **Keystore Encryption**: Password-protected wallet (Keystore V3, compatible with MetaMask/Geth)
|
|
11
|
+
- **Extensible Wallet**: WalletProvider abstraction for EVM/MPC wallets
|
|
12
|
+
|
|
13
|
+
## Network
|
|
14
|
+
|
|
15
|
+
### BSC Testnet (Chain ID: 97)
|
|
16
|
+
|
|
17
|
+
| Contract | Address |
|
|
18
|
+
|----------|---------|
|
|
19
|
+
| Identity Registry | `0x8004A818BFB912233c491871b3d84c89A494BD9e` |
|
|
20
|
+
| Reputation Registry | `0x8004B663056A597Dffe9eCcC1965A193B7388713` |
|
|
21
|
+
|
|
22
|
+
### BSC Mainnet (Chain ID: 56)
|
|
23
|
+
|
|
24
|
+
> **Note:** Mainnet support is not yet available. It will be supported soon. Stay tuned!
|
|
25
|
+
|
|
26
|
+
## Installation
|
|
27
|
+
|
|
28
|
+
> **Requirements:** Python 3.10+ and `uv` (recommended) or `pip`
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install git+https://github.com/bnb-chain/bnbagent-sdk.git
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
For development:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/bnb-chain/bnbagent-sdk.git
|
|
38
|
+
cd bnbagent-sdk
|
|
39
|
+
uv sync --extra dev # or: pip install -e ".[dev]"
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
import os
|
|
46
|
+
from bnbagent import ERC8004Agent, EVMWalletProvider, AgentEndpoint
|
|
47
|
+
|
|
48
|
+
# Create wallet and SDK
|
|
49
|
+
wallet = EVMWalletProvider(password=os.getenv("WALLET_PASSWORD"))
|
|
50
|
+
sdk = ERC8004Agent(wallet_provider=wallet, network="bsc-testnet")
|
|
51
|
+
|
|
52
|
+
# Generate and register agent
|
|
53
|
+
agent_uri = sdk.generate_agent_uri(
|
|
54
|
+
name="My Agent",
|
|
55
|
+
description="A test agent",
|
|
56
|
+
endpoints=[
|
|
57
|
+
AgentEndpoint(
|
|
58
|
+
name="A2A",
|
|
59
|
+
endpoint="https://agent.example/.well-known/agent-card.json",
|
|
60
|
+
version="0.3.0"
|
|
61
|
+
)
|
|
62
|
+
]
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
result = sdk.register_agent(agent_uri=agent_uri)
|
|
66
|
+
print(f"Agent registered with ID: {result['agentId']}")
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Core Operations
|
|
70
|
+
|
|
71
|
+
### Register Agent
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
result = sdk.register_agent(agent_uri=agent_uri)
|
|
75
|
+
# Returns: {agentId, transactionHash, agentURI, ...}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Discover Agents
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
# List agents with pagination
|
|
82
|
+
agents = sdk.get_all_agents(limit=10, offset=0)
|
|
83
|
+
for agent in agents['items']:
|
|
84
|
+
print(f"#{agent['token_id']}: {agent['name']}")
|
|
85
|
+
|
|
86
|
+
# Get single agent info (on-chain)
|
|
87
|
+
info = sdk.get_agent_info(agent_id=1)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### Update Agent
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
new_uri = sdk.generate_agent_uri(
|
|
94
|
+
name="Updated Agent",
|
|
95
|
+
description="New description",
|
|
96
|
+
endpoints=[...],
|
|
97
|
+
agent_id=1 # Include for registrations field
|
|
98
|
+
)
|
|
99
|
+
sdk.set_agent_uri(agent_id=1, agent_uri=new_uri)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### Metadata
|
|
103
|
+
|
|
104
|
+
```python
|
|
105
|
+
# Get/set metadata
|
|
106
|
+
version = sdk.get_metadata(agent_id=1, key="version")
|
|
107
|
+
sdk.set_metadata(agent_id=1, key="version", value="2.0.0")
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Examples
|
|
111
|
+
|
|
112
|
+
See [`examples/testnet_usage.py`](examples/testnet_usage.py) for a complete working example including:
|
|
113
|
+
- Wallet creation and management
|
|
114
|
+
- Agent registration
|
|
115
|
+
- Agent discovery and querying
|
|
116
|
+
- Metadata operations
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
- **[API Reference](bnbagent/README.md)** - Complete API documentation with workflow examples
|
|
121
|
+
|
|
122
|
+
## Security
|
|
123
|
+
|
|
124
|
+
The SDK stores encrypted wallet state in `.bnbagent_state`:
|
|
125
|
+
|
|
126
|
+
- **Encryption**: AES-128-CTR with scrypt key derivation (Keystore V3)
|
|
127
|
+
- **File permissions**: `0o600` (owner read/write only)
|
|
128
|
+
- **Format**: Compatible with MetaMask/Geth keystore
|
|
129
|
+
|
|
130
|
+
### Best Practices
|
|
131
|
+
|
|
132
|
+
1. **Never commit secrets**: Add `.bnbagent_state` to `.gitignore`
|
|
133
|
+
2. **Use environment variables**: Store `WALLET_PASSWORD` in env, not in code
|
|
134
|
+
3. **Backup your wallet**: Export keystore JSON and store securely
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
# Export wallet for backup
|
|
138
|
+
keystore = wallet.export_keystore()
|
|
139
|
+
with open("backup-wallet.json", "w") as f:
|
|
140
|
+
json.dump(keystore, f)
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Environment Variables
|
|
144
|
+
|
|
145
|
+
| Variable | Description |
|
|
146
|
+
|----------|-------------|
|
|
147
|
+
| `WALLET_PASSWORD` | Password for wallet encryption/decryption |
|
|
148
|
+
|
|
149
|
+
## Error Handling
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
try:
|
|
153
|
+
result = sdk.register_agent(agent_uri=agent_uri)
|
|
154
|
+
except ConnectionError as e:
|
|
155
|
+
print(f"RPC connection failed: {e}")
|
|
156
|
+
except ValueError as e:
|
|
157
|
+
print(f"Invalid input: {e}")
|
|
158
|
+
except RuntimeError as e:
|
|
159
|
+
print(f"Transaction failed: {e}")
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Development
|
|
163
|
+
|
|
164
|
+
### Running Tests
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
uv run pytest # Run tests
|
|
168
|
+
uv run pytest --cov=bnbagent # With coverage
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Contributing
|
|
172
|
+
|
|
173
|
+
1. Follow existing code patterns
|
|
174
|
+
2. Include error handling
|
|
175
|
+
3. Add tests for new features
|
|
176
|
+
4. Run tests before submitting
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
This SDK is part of the ERC-8004 implementation project.
|