Skip to content

Commit

Permalink
net: add new namehash
Browse files Browse the repository at this point in the history
  • Loading branch information
bitful-pannul committed Jun 19, 2024
1 parent c8442ef commit c45e40a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/net.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{get_blob, Address, NodeId, Request, SendError};
use crate::{get_blob, println, Address, NodeId, Request, SendError};
use alloy::{hex, primitives::keccak256};
use alloy_primitives::B256;
use alloy_sol_types::SolValue;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;

Expand Down Expand Up @@ -179,6 +182,20 @@ pub fn get_name(namehash: &str, timeout: Option<u64>) -> anyhow::Result<String>
}
}

/// namehash... kimap style
pub fn namehash(name: &str) -> String {
let mut node = B256::default();

let mut labels: Vec<&str> = name.split('.').collect();
labels.reverse();

for label in labels.iter() {
let l = keccak256(label);
node = keccak256((node, l).abi_encode_packed());
}
format!("0x{}", hex::encode(node))
}

/// take a DNSwire-formatted node ID from chain and convert it to a String
pub fn dnswire_decode(wire_format_bytes: &[u8]) -> Result<String, DnsDecodeError> {
let mut i = 0;
Expand Down

0 comments on commit c45e40a

Please sign in to comment.