-
Notifications
You must be signed in to change notification settings - Fork 79
Introduce directory feature module
#502
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 all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0eff567
Move shared `RequestError` to `PayloadError`
DanGould c17e2d8
Divide receive::v1 into exclusive and shared mods
DanGould 5e678c9
Introduce `directory` feature module
DanGould 5aaf068
Define ENCAPSULATED_MESSAGE_BYTES in `directory`
DanGould 6580519
Unit test `UncheckedProposal::from_request`
DanGould 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
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 |
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| #!/usr/bin/env bash | ||
| set -e | ||
|
|
||
| cargo clippy --all-targets --keep-going --no-default-features --features=v1,_danger-local-https -- -D warnings | ||
| cargo clippy --all-targets --keep-going --no-default-features --features=v2,_danger-local-https,io -- -D warnings | ||
| cargo clippy --all-targets --keep-going --all-features -- -D warnings |
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
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
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,69 @@ | ||
| pub const ENCAPSULATED_MESSAGE_BYTES: usize = 8192; | ||
|
|
||
| /// A 64-bit identifier used to identify Payjoin Directory entries. | ||
| /// | ||
| /// ShortId is derived from a truncated SHA256 hash of a compressed public key. While SHA256 is used | ||
| /// internally, ShortIds should be treated only as unique identifiers, not cryptographic hashes. | ||
| /// The truncation to 64 bits means they are not cryptographically binding. | ||
| /// | ||
| /// ## Security Characteristics | ||
| /// | ||
| /// - Provides sufficient entropy for practical uniqueness in the Payjoin Directory context | ||
| /// - With ~2^21 concurrent entries (24h tx limit), collision probability is < 1e-6 | ||
| /// - Individual entry collision probability is << 1e-10 | ||
| /// - Collisions only affect liveness (ability to complete the payjoin), not security | ||
| /// - For v2 entries, collisions result in HPKE failure | ||
| /// - For v1 entries, collisions may leak PSBT proposals to interceptors | ||
| /// | ||
| /// Note: This implementation assumes ephemeral public keys with sufficient entropy. The short length | ||
| /// is an intentional tradeoff that provides adequate practical uniqueness while reducing DoS surface. | ||
| #[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| pub struct ShortId(pub [u8; 8]); | ||
|
|
||
| impl ShortId { | ||
| pub fn as_bytes(&self) -> &[u8] { &self.0 } | ||
| pub fn as_slice(&self) -> &[u8] { &self.0 } | ||
| } | ||
|
|
||
| impl std::fmt::Display for ShortId { | ||
| fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { | ||
| let id_hrp = bitcoin::bech32::Hrp::parse("ID").unwrap(); | ||
| f.write_str( | ||
| crate::bech32::nochecksum::encode(id_hrp, &self.0) | ||
| .expect("bech32 encoding of short ID must succeed") | ||
| .strip_prefix("ID1") | ||
| .expect("human readable part must be ID1"), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Debug)] | ||
| pub enum ShortIdError { | ||
| DecodeBech32(bitcoin::bech32::primitives::decode::CheckedHrpstringError), | ||
| IncorrectLength(std::array::TryFromSliceError), | ||
| } | ||
|
|
||
| impl std::convert::From<bitcoin::hashes::sha256::Hash> for ShortId { | ||
| fn from(h: bitcoin::hashes::sha256::Hash) -> Self { | ||
| bitcoin::hashes::Hash::as_byte_array(&h)[..8] | ||
| .try_into() | ||
| .expect("truncating SHA256 to 8 bytes should always succeed") | ||
| } | ||
| } | ||
|
|
||
| impl std::convert::TryFrom<&[u8]> for ShortId { | ||
| type Error = ShortIdError; | ||
| fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> { | ||
| let bytes: [u8; 8] = bytes.try_into().map_err(ShortIdError::IncorrectLength)?; | ||
| Ok(Self(bytes)) | ||
| } | ||
| } | ||
|
|
||
| impl std::str::FromStr for ShortId { | ||
| type Err = ShortIdError; | ||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| let (_, bytes) = crate::bech32::nochecksum::decode(&("ID1".to_string() + s)) | ||
| .map_err(ShortIdError::DecodeBech32)?; | ||
| (&bytes[..]).try_into() | ||
| } | ||
| } | ||
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
Oops, something went wrong.
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.