Skip to content

Define V3 binary secret encoding#389

Draft
Egge21M wants to merge 4 commits into
cashubtc:mainfrom
Egge21M:v3-secrets
Draft

Define V3 binary secret encoding#389
Egge21M wants to merge 4 commits into
cashubtc:mainfrom
Egge21M:v3-secrets

Conversation

@Egge21M

@Egge21M Egge21M commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Description
Adds the general V3 binary secret envelope to NUT-00 and defines
the NUT-10 condition payload encoding for V3 secrets.

Changes:

  • Defines V3 Proof.secret as raw bytes.
  • Adds secret = SECRET_KIND || DATA.
  • Defines 0x00 random secrets and 0x01 condition secrets.
  • Adds the CBOR ConditionMap for NUT-10 spending conditions.
  • Replaces legacy data with pubkeys for P2PK and hash for HTLC.
  • Encodes legacy tags as dedicated integer keys, while allowing
    extension tags as string: any.

Co-authored-by: Rob Woodgate <robwoodgate@users.noreply.github.com>
Co-authored-by: Rob Woodgate <robwoodgate@users.noreply.github.com>
@Egge21M Egge21M marked this pull request as draft June 16, 2026 10:41

@robwoodgate robwoodgate left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work, Egge - you've captured everything we discussed really well.

I added one suggestion which was a tangential offline conversation.

Comment thread 00.md
| `0x00` | `random` | Random bytes |
| `0x01` | `condition` | CBOR-encoded spending condition data |

For `SECRET_KIND = 0x00`, `DATA` SHOULD be 32 bytes generated by a CSPRNG.

@robwoodgate robwoodgate Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we were planning to make this change too for v3 secrets.

Suggested change
For `SECRET_KIND = 0x00`, `DATA` SHOULD be 32 bytes generated by a CSPRNG.
For `SECRET_KIND = 0x00`, `DATA` SHOULD be a random 33 byte compressed secp256k1 public key.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on the usecase? Making a standard random secret 33 bytes would mean it becomes distinguishable from deterministic secrets

Comment thread 10.md
| `6` | `sigflag` | `uint` | Signature flag. `0` means `SIG_INPUTS`, `1` means `SIG_ALL`. If absent, the default is `0`. |
| `7` | `hash` | `bstr` | 32-byte SHA-256 digest for HTLCs. This replaces the legacy HTLC `data` field. |

Arbitrary tag tuples can be encoded with text-string keys and arbitrary CBOR values (`string: any`). These string-keyed entries are reserved for extensions and MUST NOT redefine the meaning of the integer keys above.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"...and MUST NOT redefine the meaning of the integer keys above."

Great call!

Comment thread 10.md

An HTLC condition uses `hash`. Additional signature, locktime, and refund conditions use the same `pubkeys`, `locktime`, `refund`, `n_sigs`, `n_sigs_refund`, and `sigflag` keys defined above.

Unsigned integer keys not defined here MUST NOT be used unless specified by another NUT.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spot on

@robwoodgate

robwoodgate commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

I just noticed the ConditionMap excludes kind now, I know we discussed the presence of hash as being a definitive marker between P2PK and HTLC, but I wonder if we need to keep kind for future NUT-10 kinds that may cherry-pick only certain items from the ConditionMap and may look like another type to a parser.

Eg: a future NUT-10 type that uses locktime but not pubkeys might be flagged as an invalid P2PK condition, whereas it is in fact valid for that specific custom kind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants