Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pallets/dotns-gateway/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ mod benchmarks {
DispatcherAddress::<T>::put(H160([0xd0; 20]));

// 32-byte lite-format label: 29 lowercase letters, a dot, two digits.
// Matches `<dns-stem>.<2+ digits>` per `StringUtils.isLitePersonLabel`.
let mut lite_bytes = [b'x'; 32];
lite_bytes[29] = b'.';
lite_bytes[30] = b'4';
Expand Down
6 changes: 3 additions & 3 deletions pallets/dotns-gateway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,9 @@ pub mod pallet {
/// server-side after the candidate signs, so the candidate cannot commit to them at
/// signing time).
/// - `lite_label`: the lite-person label. Must be `<dns-stem>.<2+ digits>` (e.g.
/// `alice.42`), matching `StringUtils.isLitePersonLabel` in the contracts. Only the
/// `<dns-stem>` portion enters the signed message; the digits ride along as an unsigned
/// extrinsic argument used for the contract calldata and storage key.
/// `alice.42`). Only the `<dns-stem>` portion enters the signed message; the digits ride
/// along as an unsigned extrinsic argument used for the contract calldata and storage
/// key.
/// - `chat_key`: 65-byte public key used for ECDH chat.
/// - `reserved_base_label`: optional personhood label queued for the candidate, to issue
/// later as their personhood name. Must be lowercase ASCII letters only (e.g. `alice`).
Expand Down
3 changes: 1 addition & 2 deletions pallets/dotns-gateway/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ pub struct BaseLabel(pub BoundedVec<u8, ConstU32<32>>);

impl BaseLabel {
/// Returns whether the label matches the lite-person PoP format
/// `<dns-stem>.<2+ digits>` (e.g. `alice.42`), per `StringUtils.isLitePersonLabel`
/// on the contract side.
/// `<dns-stem>.<2+ digits>` (e.g. `alice.42`).
pub fn is_valid_lite(&self) -> bool {
is_lite_person_label(self.0.as_slice())
}
Expand Down
11 changes: 4 additions & 7 deletions support/src/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@
// limitations under the License.

//! Label (username) format validators.
//!
//! Mirrors `StringUtils._isDnsLabel` and `StringUtils.isLitePersonLabel` from
//! the `paritytech/dotns` contracts so that names produced on chain round-trip
//! into dotNS without format changes.

/// Minimum number of trailing digits required in a lite-person PoP label
/// suffix (the part after the `.`).
///
/// Must match `StringUtils.MIN_LITE_SUFFIX_DIGITS` on the contract side.
/// dotNS `StringUtils.DEVICE_SUFFIX_DIGITS` has the same value but requires
/// exactly that many digits.
pub const MIN_LITE_USERNAME_DIGITS: usize = 2;

/// Returns whether `bytes` is a stricter "person" label: non-empty and only
Expand All @@ -37,8 +34,8 @@ pub fn is_person_label(bytes: &[u8]) -> bool {
/// Returns whether `bytes` matches the lite-person PoP label format
/// `<dns-stem>.<digits{MIN_LITE_USERNAME_DIGITS,}>` (e.g. `alice.42`).
///
/// Mirrors `StringUtils.isLitePersonLabel`: exactly one `.`, a DNS-valid
/// stem before it, and at least `MIN_LITE_USERNAME_DIGITS` ASCII digits after.
/// The label has exactly one `.`, a DNS-valid stem before it and at least
/// `MIN_LITE_USERNAME_DIGITS` ASCII digits after it.
pub fn is_lite_person_label(bytes: &[u8]) -> bool {
let length = bytes.len();
// Shortest valid label is `x.NN` with `NN` being `MIN_LITE_USERNAME_DIGITS` digits.
Expand Down
Loading