Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
Removed need to store keypair from Gunsafe CLI example
Added unit tetsts
Fixed issue with documents newline character
  • Loading branch information
draeder committed Jul 13, 2022
1 parent 50c4cbc commit f4cfad5
Show file tree
Hide file tree
Showing 6 changed files with 9,852 additions and 482 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
http
testing*.js
# Logs
bak
test
radata
logs
*.log
Expand Down
13 changes: 3 additions & 10 deletions cli/gunsafe.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#! /usr/bin/env node
import fs from 'fs'
import '../index.js'
import hardwareid from 'hardwareid'
import Gun from 'gun'
import SEA from 'gun/sea.js'
import Carets from 'carets'
Expand Down Expand Up @@ -42,16 +43,8 @@ async function auth(line){
if(line === '\r') return console.log('The gunsafe name may not be empty.')
authedUser = line.join(' ')
console.log('Keypair for the gunsafe named,', authedUser + ', created.')
let key
try {
key = fs.readFileSync('./key', err => {}).toString()
gun.gunsafe.name(key, authedUser)
}
catch {
let pair = await SEA.pair()
fs.writeFile('./key', pair.epriv, err => {})
gun.gunsafe.name(pair.epriv, authedUser)
}
let key = await hardwareid()
gun.gunsafe.name(key, authedUser)
}

function keypair(){
Expand Down
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ Gun.chain.gunsafe = function(opts) {
gun.user().get('gunsafe').get('items').get(name).once(async data => {
if(!data) return cb('Record not found')
data = await SEA.decrypt(data, pair)
try { data = data.join(' '); if(!run) cb(data) } catch {}
try { data = JSON.parse(data) } catch {}

try { data = data.join(' '); if(!run) cb(data) }
catch (err){if(err){}}
try { data = JSON.parse(data) }
catch (err){if(err){}}
if(typeof data === 'object'){
let index = Object.keys(data)
let str
for(let i in index){
if(data[index[i]]){
str = str + data[index[i]]
str = str + data[index[i]] + '\r\n'
}
}

Expand All @@ -57,7 +58,6 @@ Gun.chain.gunsafe = function(opts) {
},
list: async (del, cb) => {
let last = []
last.length = 0
gun.user().get('gunsafe').get('list').map().once(data => {
if(last.includes(data)) return
gun.user().get('gunsafe').get('items').get(data).once(d => {
Expand Down
Loading

0 comments on commit f4cfad5

Please sign in to comment.