From c961c7447c604338744d63459f13fc104e87356b Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 26 Sep 2024 17:18:50 -0400 Subject: [PATCH 1/4] feat: support ip6 for remote node communication --- package-lock.json | 8 ++++---- package.json | 2 +- src/actions/push.ts | 3 ++- src/actions/remote.ts | 10 ++++++---- src/prompts.ts | 13 +++++++++---- src/utils/host.ts | 8 ++++++++ 6 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 src/utils/host.ts diff --git a/package-lock.json b/package-lock.json index ec699d8..a51ee46 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "0.0.1-alpha.33", "license": "ISC", "dependencies": { - "@dignetwork/dig-sdk": "^0.0.1-alpha.88", + "@dignetwork/dig-sdk": "^0.0.1-alpha.101", "bip39": "^3.1.0", "datalayer-driver": "^0.1.21", "inquirer": "^10.1.8", @@ -243,9 +243,9 @@ } }, "node_modules/@dignetwork/dig-sdk": { - "version": "0.0.1-alpha.88", - "resolved": "https://registry.npmjs.org/@dignetwork/dig-sdk/-/dig-sdk-0.0.1-alpha.88.tgz", - "integrity": "sha512-kfeuSlN2qh5Aunh2u+BAUXMZRoFjwO8wjR5FltbdtVXQ8GBKToMOWhtxpOjcRIzZp4ITiCmr1j+jGanw9Xfgjw==", + "version": "0.0.1-alpha.101", + "resolved": "https://registry.npmjs.org/@dignetwork/dig-sdk/-/dig-sdk-0.0.1-alpha.101.tgz", + "integrity": "sha512-9F6jefR0Hrx4frDKEJEhLvDVewN1vNDPsT5JosUbU7HZXwShzqmddiaIMXlo7vtweAY4gHIctA3RJcL1LUbofw==", "dependencies": { "@dignetwork/datalayer-driver": "^0.1.25", "archiver": "^7.0.1", diff --git a/package.json b/package.json index 2ae1c4c..4ea933d 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "LICENSE" ], "dependencies": { - "@dignetwork/dig-sdk": "0.0.1-alpha.88", + "@dignetwork/dig-sdk": "^0.0.1-alpha.101", "bip39": "^3.1.0", "datalayer-driver": "^0.1.21", "inquirer": "^10.1.8", diff --git a/src/actions/push.ts b/src/actions/push.ts index 65f7c28..9e2b9d0 100644 --- a/src/actions/push.ts +++ b/src/actions/push.ts @@ -9,6 +9,7 @@ import { } from "@dignetwork/dig-sdk"; import { promptForRemote } from "../prompts"; import { DigConfig } from "../types"; +import { formatHost } from "../utils/host"; // Check that required files exist const checkRequiredFiles = (): void => { @@ -47,7 +48,7 @@ export const push = async (): Promise => { ); } - const digPeer = new DigPeer(config.remote, dataStore.StoreId); + const digPeer = new DigPeer(formatHost(config.remote), dataStore.StoreId); console.log(`Pushing to ${config.remote}...`); await digPeer.syncStore(); diff --git a/src/actions/remote.ts b/src/actions/remote.ts index bd32736..c9eb617 100644 --- a/src/actions/remote.ts +++ b/src/actions/remote.ts @@ -10,6 +10,8 @@ import { import fs from "fs"; import superagent from "superagent"; import * as https from "https"; +import { formatHost } from "../utils/host"; + export const setRemote = (remote: string): void => { _setRemote(remote); @@ -39,7 +41,7 @@ const syncOrSetRemoteSeed = async (walletName: string, mnemonic: string): Promis try { const response = await superagent - .post(`https://${config.remote}:4159/mnemonic`) + .post(`https://${formatHost(config.remote)}:4159/mnemonic`) .set("Authorization", `Basic ${auth}`) .set("Content-Type", "application/json") .agent(agent) // Use the custom HTTPS agent @@ -104,7 +106,7 @@ export const subscribeToStore = async (storeId: string): Promise => { try { const response = await superagent - .post(`https://${config.remote}:4159/subscribe`) + .post(`https://${formatHost(config.remote)}:4159/subscribe`) .set("Authorization", `Basic ${auth}`) .set("Content-Type", "application/json") .agent(agent) // Use the custom HTTPS agent @@ -146,7 +148,7 @@ export const unsubscribeToStore = async (storeId: string): Promise => { try { const response = await superagent - .post(`https://${config.remote}:4159/unsubscribe`) + .post(`https://${formatHost(config.remote)}:4159/unsubscribe`) .set("Authorization", `Basic ${auth}`) .set("Content-Type", "application/json") .agent(agent) // Use the custom HTTPS agent @@ -161,4 +163,4 @@ export const unsubscribeToStore = async (storeId: string): Promise => { } catch (error: any) { console.error(`Request failed: ${error.message}`); } -}; \ No newline at end of file +}; diff --git a/src/prompts.ts b/src/prompts.ts index 11c6ddd..0a5437d 100644 --- a/src/prompts.ts +++ b/src/prompts.ts @@ -122,17 +122,22 @@ export const askForMnemonicInput = async (): Promise => { const validateHost = (input: string): boolean | string => { // Regex pattern for validating hostnames (e.g., example.com) without ports const hostPattern = /^(?!:\/\/)([a-zA-Z0-9.-]+)$/; // For hostnames without port + // Regex pattern for validating IPv4 addresses (e.g., 192.168.0.1) without ports - const ipPattern = /^(?!:\/\/)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/; // For IPv4 without port + const ipv4Pattern = /^(?!:\/\/)(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})$/; // For IPv4 without port + + // Regex pattern for validating IPv6 addresses (e.g., 2001:0db8:85a3::8a2e:0370:7334) without ports + const ipv6Pattern = /^(?!:\/\/)([a-fA-F0-9:]+)$/; // For IPv6 without port - // Check if the input matches either a hostname or an IP address - if (hostPattern.test(input) || ipPattern.test(input)) { + // Check if the input matches either a hostname, an IPv4 address, or an IPv6 address + if (hostPattern.test(input) || ipv4Pattern.test(input) || ipv6Pattern.test(input)) { return true; } - return 'Please enter a valid IP address or host without a port (e.g., example.com or 192.168.0.1)'; + return 'Please enter a valid IP address (IPv4 or IPv6) or host without a port (e.g., example.com, 192.168.0.1, or 2001:db8::1)'; }; + export const promptForRemote = async (): Promise => { const questions: any = [ { diff --git a/src/utils/host.ts b/src/utils/host.ts new file mode 100644 index 0000000..eefac26 --- /dev/null +++ b/src/utils/host.ts @@ -0,0 +1,8 @@ +// Helper function to wrap IPv6 addresses in brackets +export const formatHost = (host: string): string => { + const ipv6Pattern = /^[a-fA-F0-9:]+$/; // Simple regex to match IPv6 addresses + if (ipv6Pattern.test(host)) { + return `[${host}]`; // Wrap IPv6 in brackets + } + return host; +}; From 956c0f3c71e984a930c2b3d24a0faf1b26a2536f Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 26 Sep 2024 17:19:27 -0400 Subject: [PATCH 2/4] chore(release): 0.0.1-alpha.34 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b05910..c4b6cd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.34](https://github.com/DIG-Network/dig-cli/compare/v0.0.1-alpha.33...v0.0.1-alpha.34) (2024-09-26) + + +### Features + +* support ip6 for remote node communication ([c961c74](https://github.com/DIG-Network/dig-cli/commit/c961c7447c604338744d63459f13fc104e87356b)) + ### [0.0.1-alpha.33](https://github.com/DIG-Network/dig-cli/compare/v0.0.1-alpha.32...v0.0.1-alpha.33) (2024-09-26) diff --git a/package-lock.json b/package-lock.json index a51ee46..bb0e62d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-chia-cli", - "version": "0.0.1-alpha.33", + "version": "0.0.1-alpha.34", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-chia-cli", - "version": "0.0.1-alpha.33", + "version": "0.0.1-alpha.34", "license": "ISC", "dependencies": { "@dignetwork/dig-sdk": "^0.0.1-alpha.101", diff --git a/package.json b/package.json index 4ea933d..36a30c6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-chia-cli", - "version": "0.0.1-alpha.33", + "version": "0.0.1-alpha.34", "description": "", "type": "commonjs", "main": "./dist/index.js", From d26e8ddb586d74d203abedbf5659065c40833770 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 26 Sep 2024 17:29:01 -0400 Subject: [PATCH 3/4] feat: support ip6 for remote node communication --- src/utils/host.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/utils/host.ts b/src/utils/host.ts index eefac26..6744425 100644 --- a/src/utils/host.ts +++ b/src/utils/host.ts @@ -1,8 +1,13 @@ // Helper function to wrap IPv6 addresses in brackets export const formatHost = (host: string): string => { - const ipv6Pattern = /^[a-fA-F0-9:]+$/; // Simple regex to match IPv6 addresses - if (ipv6Pattern.test(host)) { - return `[${host}]`; // Wrap IPv6 in brackets - } - return host; -}; + const ipv6Pattern = /^[a-fA-F0-9:]+$/; // Simple regex to match raw IPv6 addresses (without brackets) + const hasBrackets = /^\[.*\]$/; // Regex to check if the address already has brackets + + // If it's an IPv6 address without brackets, add them + if (ipv6Pattern.test(host) && !hasBrackets.test(host)) { + return `[${host}]`; + } + + return host; // Return the host as is (IPv4, hostname, or already bracketed IPv6) + }; + \ No newline at end of file From 1e9bf6980774396cd09fc78bc372c74848dd2ef9 Mon Sep 17 00:00:00 2001 From: Michael Taylor Date: Thu, 26 Sep 2024 17:29:20 -0400 Subject: [PATCH 4/4] chore(release): 0.0.1-alpha.35 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4b6cd5..832eafc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [0.0.1-alpha.35](https://github.com/DIG-Network/dig-cli/compare/v0.0.1-alpha.34...v0.0.1-alpha.35) (2024-09-26) + + +### Features + +* support ip6 for remote node communication ([d26e8dd](https://github.com/DIG-Network/dig-cli/commit/d26e8ddb586d74d203abedbf5659065c40833770)) + ### [0.0.1-alpha.34](https://github.com/DIG-Network/dig-cli/compare/v0.0.1-alpha.33...v0.0.1-alpha.34) (2024-09-26) diff --git a/package-lock.json b/package-lock.json index bb0e62d..7f0edbb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@dignetwork/dig-chia-cli", - "version": "0.0.1-alpha.34", + "version": "0.0.1-alpha.35", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@dignetwork/dig-chia-cli", - "version": "0.0.1-alpha.34", + "version": "0.0.1-alpha.35", "license": "ISC", "dependencies": { "@dignetwork/dig-sdk": "^0.0.1-alpha.101", diff --git a/package.json b/package.json index 36a30c6..1c07eb6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dignetwork/dig-chia-cli", - "version": "0.0.1-alpha.34", + "version": "0.0.1-alpha.35", "description": "", "type": "commonjs", "main": "./dist/index.js",