Skip to content

Commit

Permalink
Merge pull request #245 from dcSpark/nico/support-sepolia
Browse files Browse the repository at this point in the history
Support Sepolia
  • Loading branch information
nicarq authored Feb 20, 2024
2 parents 6760545 + 1aca302 commit f492558
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 139 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shinkai_node"
version = "0.4.4"
version = "0.4.5"
edition = "2018"
authors = ["Nico Arqueros <[email protected]>"]

Expand Down
2 changes: 1 addition & 1 deletion shinkai-libs/shinkai-message-primitives/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shinkai-libs/shinkai-message-primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shinkai_message_primitives"
version = "0.4.4"
version = "0.4.5"
edition = "2018"
authors = ["Nico Arqueros <[email protected]>"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ mod tests {
let valid_names = vec![
"inbox::@@node.shinkai::true",
"inbox::@@node1.shinkai/subidentity::false",
"inbox::@@node.sepolia-shinkai/subidentity::true",
"inbox::@@alice.shinkai/profileName/agent/myChatGPTAgent::true",
"inbox::@@alice.shinkai/profileName/device/myPhone::true",
"inbox::@@node1.shinkai/subidentity::@@node2.shinkai/subidentity2::false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,20 @@ impl std::error::Error for ShinkaiNameError {}
// @@alice.shinkai/profileName
// @@alice.shinkai/profileName/agent/myChatGPTAgent
// @@alice.shinkai/profileName/device/myPhone
// @@alice.sepolia-shinkai
// @@alice.sepolia-shinkai/profileName

// Not valid examples
// @@alice.shinkai/profileName/myPhone
// @@al!ce.shinkai
// @@alice.shinkai//
// @@node1.shinkai/profile_1.shinkai
// @@alice.sepolia--shinkai

impl ShinkaiName {
// Define a list of valid endings
const VALID_ENDINGS: [&'static str; 2] = [".shinkai", ".sepolia-shinkai"];

pub fn new(raw_name: String) -> Result<Self, &'static str> {
let raw_name = Self::correct_node_name(raw_name);
Self::validate_name(&raw_name)?;
Expand Down Expand Up @@ -143,16 +149,17 @@ impl ShinkaiName {
return Err("Name should have one to four parts: node, profile, type (device or agent), and name.");
}

if !parts[0].starts_with("@@") || !parts[0].ends_with(".shinkai") {
if !parts[0].starts_with("@@") || !Self::VALID_ENDINGS.iter().any(|&ending| parts[0].ends_with(ending)) {
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Info,
&format!("Validation error: {}", raw_name),
);
return Err("Node part of the name should start with '@@' and end with '.shinkai'.");
return Err("Node part of the name should start with '@@' and end with a valid ending ('.shinkai', '.sepolia-shinkai', etc.).");
}

if !Regex::new(r"^@@[a-zA-Z0-9\_\.]+\.shinkai$").unwrap().is_match(parts[0]) {
let node_name_regex = r"^@@[a-zA-Z0-9\_\.]+(\.shinkai|\.sepolia-shinkai)$";
if !Regex::new(node_name_regex).unwrap().is_match(parts[0]) {
shinkai_log(
ShinkaiLogOption::Identity,
ShinkaiLogLevel::Info,
Expand Down Expand Up @@ -366,8 +373,8 @@ impl ShinkaiName {

// This method checks if a name is a valid node identity name and doesn't contain subidentities
fn is_valid_node_identity_name_and_no_subidentities(name: &String) -> bool {
// A node name is valid if it starts with '@@', ends with '.shinkai', and doesn't contain '/'
name.starts_with("@@") && name.ends_with(".shinkai") && !name.contains("/")
// A node name is valid if it starts with '@@', ends with a valid ending, and doesn't contain '/'
name.starts_with("@@") && !name.contains("/") && Self::VALID_ENDINGS.iter().any(|&ending| name.ends_with(ending))
}

pub fn contains(&self, other: &ShinkaiName) -> bool {
Expand Down Expand Up @@ -471,8 +478,8 @@ impl ShinkaiName {
node_name = format!("@@{}", node_name);
}

// Append with ".shinkai" if the node doesn't already end with ".shinkai"
if !node_name.ends_with(".shinkai") {
// Check if the node_name ends with any of the valid endings, append ".shinkai" if not
if !Self::VALID_ENDINGS.iter().any(|&ending| node_name.ends_with(ending)) {
node_name = format!("{}.shinkai", node_name);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ mod tests {
"@@alice.shinkai/profileName",
"@@alice.shinkai/profileName/agent/myChatGPTAgent",
"@@alice.shinkai/profileName/device/myPhone",
"@@alice.sepolia-shinkai",
"@@alice.sepolia-shinkai/profileName",
"@@alice.sepolia-shinkai/profileName/agent/myChatGPTAgent",
"@@alice.sepolia-shinkai/profileName/device/myPhone",
];

for name in valid_names {
Expand All @@ -33,7 +37,7 @@ mod tests {
"@@al!ce.shinkai",
"@@alice.shinkai//",
"@@alice.shinkai//subidentity",
"@@node1.shinkai/profile_1.shinkai",
"@@node1.shinkai/profile_1.shinkai"
];

for name in invalid_names {
Expand Down
4 changes: 2 additions & 2 deletions shinkai-libs/shinkai-message-pyo3/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shinkai-libs/shinkai-message-pyo3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shinkai_message_pyo3"
version = "0.4.4"
version = "0.4.5"
edition = "2018"
authors = ["Nico Arqueros <[email protected]>"]

Expand Down
4 changes: 2 additions & 2 deletions shinkai-libs/shinkai-message-wasm/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion shinkai-libs/shinkai-message-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shinkai_message_wasm"
version = "0.4.3"
version = "0.4.5"
edition = "2018"
authors = ["Nico Arqueros <[email protected]>"]

Expand Down
2 changes: 1 addition & 1 deletion shinkai-libs/shinkai-message-wasm/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"collaborators": [
"Nico Arqueros <[email protected]>"
],
"version": "0.4.3",
"version": "0.4.5",
"files": [
"shinkai_message_wasm_bg.wasm",
"shinkai_message_wasm.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/* tslint:disable */
/* eslint-disable */
/**
* @param {string} input
* @param {string} encryption_sk
* @returns {string}
*/
export function calculate_blake3_hash(input: string): string;
export function convert_encryption_sk_string_to_encryption_pk_string(encryption_sk: string): string;
/**
* @param {string} encryption_sk
* @param {string} input
* @returns {string}
*/
export function convert_encryption_sk_string_to_encryption_pk_string(encryption_sk: string): string;
export function calculate_blake3_hash(input: string): string;
/**
*/
export class InboxNameWrapper {
Expand Down
Loading

0 comments on commit f492558

Please sign in to comment.