-
Notifications
You must be signed in to change notification settings - Fork 720
NIP-102: Subkey Attestation #1450
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
Open
ynniv
wants to merge
3
commits into
nostr-protocol:master
Choose a base branch
from
ynniv:nip-100/subkeys
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| NIP-102 | ||
| ======= | ||
|
|
||
| Hierarchical Deterministic Key Management | ||
| ----------------------------------------- | ||
|
|
||
| `draft` `optional` | ||
|
|
||
| This NIP defines a way to separate identity from authentication using hierarchical deterministic (HD) keys. This allows people to use one key pair to issue independent key pairs for different apps. If a key is compromised, the root key pair can publish an event revoking that key as of a specific time. | ||
|
|
||
| HD keys (BIP-32, BIP-39, BIP-44) provide a means of creating new key pairs from a parent in such a way that the new pubkey can be verified to be a child of the parent's pubkey. A message signed by this new key can be rapidly and locally verified as an authentic subkey of the claimed parent. | ||
|
|
||
| NIP-06 declares the default nostr derivation path to be `m/44'/1237'/<account>'/0/0`. | ||
|
|
||
| ``` | ||
| recovery phrase -> seed -> xpriv | ||
| -> m/44'/1237'/0' -> Account0 | ||
| -> m/44'/1237'/0'/0/0 -> Account0 Subkey0 | ||
| -> m/44'/1237'/0'/1/0 -> Account0 Subkey1 | ||
| -> m/44'/1237'/0'/2/0 -> Account0 Subkey2 | ||
| ``` | ||
|
|
||
| ## Management Event | ||
|
|
||
| The parent key can publish a `Kind 10102` event for subkey management. This event lists subkeys that have been revoked, as well as those that are currently active, and a preference for how valid subkeys that are not listed should be treated. This is only a preference, as it may not always be immediately available to clients and relays. | ||
|
|
||
| Content: | ||
| ```json | ||
| { | ||
| "keys": { | ||
| "<hex-subkey0-pubkey>": { "active_at": "<epoch-timestamp>" }, | ||
| "<hex-subkey1-pubkey>": { "active_at": "<epoch-timestamp>", "revoked_at": "<epoch-timestamp>" }, | ||
| "<hex-subkey2-pubkey>": { "active_at": "<epoch-timestamp>" } | ||
| }, | ||
| "default_policy": "allow" | ||
| } | ||
| ``` | ||
|
|
||
| ## Signing | ||
|
|
||
| When signing events using a subkey, the account pubkey and subkey derivation path will be included as a well known attribute. Relays and clients should validate the subkey->parent relationship, and immediately discard messages with invalid claims. | ||
|
|
||
| ```json | ||
| { | ||
| "pubkey": "<hex-subkey1-pubkey>", | ||
| "kind": 1, | ||
| "tags": [ | ||
| ["account", "<hex-account0-pubkey>", "<subkey1-derivation-path>"], | ||
| ], | ||
| } | ||
| ``` | ||
|
|
||
| For clients that don't implement NIP-102, we can have the account key publish a `Kind 10102` key management event using the subkey at the time of creation: | ||
|
|
||
| Content: | ||
| ```json | ||
| { | ||
| "account": "<hex-account0-pubkey>", | ||
| "derivation_path": "<subkey1-derivation-path>" | ||
| } | ||
| ``` | ||
|
|
||
| ## Behavior | ||
|
|
||
| All searches for the account pubkey should return those signed by any account subkey. If an event is replaceable, it is up to the client or relay as to whether both messages are maintained, or if only the latest across all subkeys is maintained. In any situation where data will be lost, a reasonable effort should be made to locate the most recent revocation list before proceeding. | ||
|
|
||
| ## Migration | ||
|
|
||
| Most current keys do not use BIP-39 derivation and will need to perform a manual key rotation to a new pubkey using a method not defined here. | ||
|
|
||
| ## Reference Code | ||
|
|
||
| ```python | ||
| from bip_utils import Bip39SeedGenerator, Bip32Slip10Secp256k1 | ||
|
|
||
| account0_derivation_path = "m/44'/1237'/0'" | ||
| subkey0_derivation_path = "0/0" | ||
|
|
||
| mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" | ||
| master_xpriv = "xprv9s21ZrQH143K3GJpoapnV8SFfukcVBSfeCficPSGfubmSFDxo1kuHnLisriDvSnRRuL2Qrg5ggqHKNVpxR86QEC8w35uxmGoggxtQTPvfUu" | ||
| account0_xpub = "xpub6D6V5EX8HTe95getx2tTH2QApmrA1nPJFEnneAK813RjcDdSc3WaAF7BRNpTF7o7zXjVm3DD3VMX66jhQ7wLaZ9sS6NzyfiwfzqDZbxvpDN" | ||
| subkey0_xpub = "xpub6Gf5o5yEF14TykSmvZBzS9wFSgnqvPsxit1v4CaaNf6S6S5mm169FRN3QkCsVsDm8NNaN8eGbQg9vR43BD9UqQTrfWFmRKoWep2gxQpFh3Q" | ||
|
|
||
| seed = Bip32Slip10Secp256k1.FromSeed(Bip39SeedGenerator(mnemonic).Generate()) | ||
| account0 = seed.DerivePath(account0_derivation_path) | ||
| subkey0 = account0.DerivePath(subkey0_derivation_path) | ||
|
|
||
| def is_subkey(pubkey, subkey, derivation_path): | ||
| parent = Bip32Slip10Secp256k1.FromExtendedKey(pubkey) | ||
| if parent.DerivePath(derivation_path).PublicKey().ToExtended() == subkey: | ||
| return True | ||
| else: | ||
| return False | ||
|
|
||
| print(f'subkey0_xpub is child of account0_xpub: {is_subkey(account0_xpub, subkey0_xpub, subkey0_derivation_path)}') | ||
| ``` | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd model this using single-letter tags so that they can be indexed. That would then obviate the need for adding an
accounttag to every event published by a subkey, since client could just fetch any10102s for pubkeys they don't recognize.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that I understand how using a single letter tag would change whether or not we need a tag with the
accounts npub. My suspicion is that the pipeline stalls caused by constantly fetching new10102s would outweigh the space savings. Is the efficiency of single-letter vs word tags due to how relays are optimized?