Skip to content

Commit

Permalink
Merge pull request #34 from DIG-Network/release/v0.0.1-alpha.35
Browse files Browse the repository at this point in the history
Release/v0.0.1 alpha.35
  • Loading branch information
MichaelTaylor3D authored Sep 26, 2024
2 parents 5356faf + 1e9bf69 commit 85008cf
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 17 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

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)


### 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)


Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dignetwork/dig-chia-cli",
"version": "0.0.1-alpha.33",
"version": "0.0.1-alpha.35",
"description": "",
"type": "commonjs",
"main": "./dist/index.js",
Expand All @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/actions/push.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down Expand Up @@ -47,7 +48,7 @@ export const push = async (): Promise<void> => {
);
}

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();

Expand Down
10 changes: 6 additions & 4 deletions src/actions/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -104,7 +106,7 @@ export const subscribeToStore = async (storeId: string): Promise<void> => {

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
Expand Down Expand Up @@ -146,7 +148,7 @@ export const unsubscribeToStore = async (storeId: string): Promise<void> => {

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
Expand All @@ -161,4 +163,4 @@ export const unsubscribeToStore = async (storeId: string): Promise<void> => {
} catch (error: any) {
console.error(`Request failed: ${error.message}`);
}
};
};
13 changes: 9 additions & 4 deletions src/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,22 @@ export const askForMnemonicInput = async (): Promise<any> => {
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<string> => {
const questions: any = [
{
Expand Down
13 changes: 13 additions & 0 deletions src/utils/host.ts
Original file line number Diff line number Diff line change
@@ -0,0 +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 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)
};

0 comments on commit 85008cf

Please sign in to comment.