-
Notifications
You must be signed in to change notification settings - Fork 44
feat(scripts): submit public miner profile metadata signed with the coldkey #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| """Set up (or clear) your public miner profile metadata. | ||
|
|
||
| Signs a metadata payload (display name, avatar, social handles) with your | ||
| coldkey — the sr25519 signature is the proof of ownership, no account | ||
| needed — and submits it to the miner dashboard API. The metadata is | ||
| rendered on your public miner profile page. | ||
|
|
||
| Run this one-shot script on whatever machine holds your coldkey (it never | ||
| leaves the machine; only the signature is sent). Each submission replaces | ||
| all five fields: an omitted field is cleared. Passing --delete removes | ||
| your metadata entirely. | ||
|
|
||
| Field constraints (enforced server-side): | ||
| - display name: at most 40 printable characters | ||
| - twitter / discord: bare handles (no URL), at most 64 characters from | ||
| letters, digits, ``_ . - #`` | ||
| - avatar / linkedin: https:// URLs of at most 300 characters; the | ||
| linkedin URL must be on linkedin.com | ||
| """ | ||
|
|
||
| import argparse | ||
| import hashlib | ||
| import json | ||
| import time | ||
|
|
||
| import bittensor | ||
| import requests | ||
|
|
||
| # Hardcode or set the environment variable WALLET_PASS to the password for | ||
| # the wallet, to skip the interactive decrypt prompt | ||
| # environ["WALLET_PASS"] = "" | ||
|
|
||
|
|
||
| def canonical_payload_hash(payload: dict) -> str: | ||
| canonical = json.dumps( | ||
| {key: value for key, value in payload.items() if value}, | ||
| sort_keys=True, | ||
| separators=(",", ":"), | ||
| ensure_ascii=False, | ||
| ) | ||
| return hashlib.sha256(canonical.encode()).hexdigest() | ||
|
|
||
|
|
||
| def main(args): | ||
| if args.delete: | ||
| payload = { | ||
| "display_name": "", | ||
| "avatar_url": "", | ||
| "twitter": "", | ||
| "discord": "", | ||
| "linkedin": "", | ||
| } | ||
| else: | ||
| payload = { | ||
| "display_name": args.display_name or "", | ||
| "avatar_url": args.avatar_url or "", | ||
| "twitter": args.twitter or "", | ||
| "discord": args.discord or "", | ||
| "linkedin": args.linkedin or "", | ||
| } | ||
|
|
||
|
Copilot marked this conversation as resolved.
Outdated
|
||
| if args.wallet_path: | ||
| wallet = bittensor.Wallet(name=args.wallet_name, path=args.wallet_path) | ||
| else: | ||
| wallet = bittensor.Wallet(name=args.wallet_name) | ||
| keypair = wallet.coldkey | ||
|
|
||
| timestamp = int(time.time()) | ||
| message = ( | ||
| f"synth-profile-metadata|v1|{keypair.ss58_address}" | ||
| f"|{timestamp}|{canonical_payload_hash(payload)}" | ||
| ) | ||
| signature = keypair.sign(data=message) | ||
|
|
||
| response = requests.put( | ||
| f"{args.api_url}/v1/profiles/{keypair.ss58_address}/metadata", | ||
| json={ | ||
| "payload": payload, | ||
| "timestamp": timestamp, | ||
| "signature": signature.hex(), | ||
| }, | ||
| timeout=30, | ||
| ) | ||
| print(f"{response.status_code} {response.text}") | ||
|
Thykof marked this conversation as resolved.
|
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| parser = argparse.ArgumentParser( | ||
| description="Sign and submit your public miner profile metadata" | ||
| ) | ||
| parser.add_argument( | ||
| "--wallet_name", type=str, required=True, help="Name of the wallet" | ||
| ) | ||
| parser.add_argument( | ||
| "--wallet_path", | ||
| type=str, | ||
| help="Path to the wallets directory (default ~/.bittensor/wallets)", | ||
| ) | ||
| parser.add_argument("--display-name", type=str, help="Public display name") | ||
| parser.add_argument( | ||
| "--avatar-url", type=str, help="https:// URL of your avatar image" | ||
| ) | ||
| parser.add_argument("--twitter", type=str, help="Twitter/X handle") | ||
| parser.add_argument("--discord", type=str, help="Discord handle") | ||
| parser.add_argument( | ||
| "--linkedin", type=str, help="https://www.linkedin.com/... URL" | ||
| ) | ||
| parser.add_argument( | ||
| "--delete", | ||
| action="store_true", | ||
| help="Remove your profile metadata entirely", | ||
| ) | ||
| parser.add_argument( | ||
| "--api-url", | ||
| type=str, | ||
| default="https://monitoring.synthdata.co", | ||
| help="Miner dashboard API base URL", | ||
| ) | ||
| args = parser.parse_args() | ||
|
|
||
| main(args) | ||
|
|
||
| # Example usage: | ||
| # python scripts/submit_miner_profile.py --wallet_name my_wallet --display-name "My Mining Co" --avatar-url https://example.com/logo.png --twitter my_handle | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.