Skip to content

Commit

Permalink
Changed to .env
Browse files Browse the repository at this point in the history
  • Loading branch information
TechyGuy17 committed Oct 16, 2022
1 parent 238c839 commit 801ff24
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ADDRESS="ADD YOUR ADDRESS"
PRIVKEY="ADD YOUR PRIVATE KEY"
POSTSURL="https://ADD.YOUR.API/api/v1/posts"
GETURL="https://ADD.YOUR.API/api/v1/posts-encrypted-group?size=3"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
This is a basic hugin messenger client written in Node.JS using our newly published POST in hugin API

# USAGE
Go through the client.js file and do the following:
Go through the .env file and do the following:
1) Add your address + the private key of said address
2) Add the address of a updated hugin API, for example the official one (https://api.hugin.chat)

Expand Down
14 changes: 10 additions & 4 deletions client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const nacl = require('tweetnacl')
const naclUtil = require('tweetnacl-util')
const prompt = require('prompt-sync')();
var cron = require('node-cron');
require('dotenv').config();

function toHex(str,hex) {
try {
Expand Down Expand Up @@ -35,8 +36,8 @@ function hexToUint(hexString) {
}

async function sendGroupsMessage(message, nickname, group) {
const my_address = "SET YOUR ADDRESS"
const private_key = 'SET THE PRIVATE KEY FOR ADDRESS'
const my_address = process.env.ADDRESS
const private_key = process.env.PRIVKEY
const signature = await cnUtil.signMessage(message, private_key)
const timestamp = parseInt(Date.now())
const nonce = nonceFromTimestamp(timestamp)
Expand All @@ -55,7 +56,7 @@ async function sendGroupsMessage(message, nickname, group) {
const payload_encrypted = {"sb":Buffer.from(secretbox).toString('hex'), "t":timestamp}
const payload_encrypted_hex = toHex(JSON.stringify(payload_encrypted))

return await fetch(`CHOOSE.AN.API/api/v1/posts`, {
return await fetch(process.env.POSTSURL, {
method: 'POST', // or 'PUT'
headers: {
'Content-Type': 'application/json',
Expand All @@ -65,11 +66,16 @@ async function sendGroupsMessage(message, nickname, group) {
return response.json()
}).then((json) => {
// console.log(json)
if(json.success == true) {
console.log("The message was successfully sent!")
} else {
console.log("There was an error in sending the message!: " + json.error)
}
})
}

async function getGroupPosts(possibleKey) {
fetch('CHOOSE.AN.API/api/v1/posts-encrypted-group?size=3')
fetch(process.env.GETURL)
.then((response) => {
return response.json()
})
Expand Down
14 changes: 14 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"dependencies": {
"dotenv": "^16.0.3",
"kryptokrona-utils": "^1.3.6",
"node-cron": "^3.0.2",
"node-fetch": "^3.2.10",
Expand Down

0 comments on commit 801ff24

Please sign in to comment.