Neptune-Crypto / neptune-core

anonymous peer-to-peer cash
Apache License 2.0
24 stars 7 forks source link

feat: symmetric key notifications #169

Closed dan-da closed 1 month ago

dan-da commented 1 month ago

closes #161.

Implements public announcements encrypted via symmetric keys

This is most useful for utxos that transfer funds within a single wallet such as change addresses.

Compared to on-chain pub-key public announcements:

Data encrypted with symmetric keys is smaller than data encrypted with asymmetric keys so there is a blockchain space (and thus fee) savings.

Compared to off-chain expected utxos:

symmetric-key announcements exist on the blockchain and thus are immune to local data-loss situations. off-chain expected utxos do not use any blockchain space but require that the wallet holder make ongoing backups of wallet state and never lose them.

Design choices, please review:

  1. SymmetricKey presently uses Aes256Gcm. Is this our final choice?

  2. Symmetric keys are derived from a seed and are unique for each utxo. (rather than using a single sym-key per wallet shared for all utxo.) This is because we want the receiver_id to be unique to avoid linking utxos.

  3. Symmetric keys derive from the same root seed WalletSecret::secret_seed as generation addresses but the derivation in ::nth_symmetric_key() uses a SYMMETRIC_KEY_FLAG. This means that end-user should only require a single mnemonic phrase for the root seed. A symmetric-key derivation counter must be stored in wallet state.

  4. efficiency: SymmetricKey presently derives all fields from seed as needed, rather than pre-calc and store when created. see doc-comment for the struct.

  5. change notify method now defaults to on-chain symmetric key, rather than offchain (expected utxo) in dashboard and neptune-cli. (note: this could easily be made an end-user option)

Summary of changes:

Cargo.toml:

New code:

Modified code:

New Tests:

dan-da commented 1 month ago

closing in favor of #171.