Comparing version 1.0.0-beta.0 to 1.0.0-beta.1
{ | ||
"name": "moondb", | ||
"version": "1.0.0-beta.0", | ||
"version": "1.0.0-beta.1", | ||
"source": "server.ts", | ||
@@ -28,3 +28,3 @@ "main": "server.js", | ||
"@koa/router": "^10.1.1", | ||
"@maiyatang/koa-rpc-server": "^1.0.0-beta.1", | ||
"@maiyatang/koa-rpc-server": "^1.0.0-beta.2", | ||
"@maiyatang/os-path": "^1.0.1", | ||
@@ -31,0 +31,0 @@ "fs-extra": "^10.0.1", |
@@ -11,2 +11,3 @@ #!/usr/bin/env node | ||
var $h5iPv$maiyatangospath = require("@maiyatang/os-path"); | ||
var $h5iPv$crypto = require("crypto"); | ||
@@ -50,4 +51,52 @@ function $parcel$interopDefault(a) { | ||
const $137088bc79f1e7e5$var$APP = 'moondb'; | ||
const $137088bc79f1e7e5$var$KEY_FILE = 'key.json'; | ||
const $137088bc79f1e7e5$var$SERVER_FILE = 'server.db'; | ||
const $137088bc79f1e7e5$var$SECRET_FILE = '.secret'; | ||
const $137088bc79f1e7e5$var$getSecret = ()=>{ | ||
const secretFile = $137088bc79f1e7e5$var$getPath($137088bc79f1e7e5$var$SECRET_FILE); | ||
let full, secret, iv; | ||
if (($parcel$interopDefault($h5iPv$fsextra)).existsSync(secretFile)) { | ||
full = ($parcel$interopDefault($h5iPv$fsextra)).readFileSync(secretFile); | ||
secret = full.slice(0, 32); | ||
iv = full.slice(32, 48); | ||
return { | ||
secret: secret, | ||
iv: iv | ||
}; | ||
} | ||
secret = ($parcel$interopDefault($h5iPv$crypto)).randomBytes(32); | ||
iv = ($parcel$interopDefault($h5iPv$crypto)).randomBytes(16); | ||
($parcel$interopDefault($h5iPv$fsextra)).writeFileSync(secretFile, Buffer.concat([ | ||
secret, | ||
iv | ||
])); | ||
return { | ||
secret: secret, | ||
iv: iv | ||
}; | ||
}; | ||
const $137088bc79f1e7e5$var$encrypt = (data, secret, iv)=>{ | ||
const cipher = ($parcel$interopDefault($h5iPv$crypto)).createCipheriv('aes-256-gcm', secret, iv); | ||
let encrypted = cipher.update(data); | ||
encrypted = Buffer.concat([ | ||
encrypted, | ||
cipher.final() | ||
]); | ||
encrypted = Buffer.concat([ | ||
cipher.getAuthTag(), | ||
encrypted | ||
]); | ||
return encrypted; | ||
}; | ||
const $137088bc79f1e7e5$var$decrypt = (data, secret, iv)=>{ | ||
const authTag = data.slice(0, 16); | ||
const encrypted = data.slice(16, data.length); | ||
// console.log(data.length, authTag.length, encrypted.length); | ||
const decipher = ($parcel$interopDefault($h5iPv$crypto)).createDecipheriv('aes-256-gcm', secret, iv); | ||
decipher.setAuthTag(authTag); | ||
let decrypted = decipher.update(encrypted, undefined, 'utf8'); | ||
decrypted = decrypted + decipher.final('utf8'); | ||
return decrypted; | ||
}; | ||
const $137088bc79f1e7e5$var$getPath = (filename)=>{ | ||
@@ -62,8 +111,17 @@ const dir = $h5iPv$maiyatangospath.applicationData($137088bc79f1e7e5$var$APP); | ||
const $137088bc79f1e7e5$export$5ab543af460d5a4e = async ()=>{ | ||
const keyFile = $137088bc79f1e7e5$var$getPath($137088bc79f1e7e5$var$KEY_FILE); | ||
if (!($parcel$interopDefault($h5iPv$fsextra)).existsSync(keyFile)) return { | ||
const serverFile = $137088bc79f1e7e5$var$getPath($137088bc79f1e7e5$var$SERVER_FILE); | ||
if (!($parcel$interopDefault($h5iPv$fsextra)).existsSync(serverFile)) return { | ||
}; | ||
const allServer = ($parcel$interopDefault($h5iPv$fsextra)).readJsonSync(keyFile); | ||
return allServer || { | ||
}; | ||
const key = $137088bc79f1e7e5$var$getSecret(); | ||
const encrypted = ($parcel$interopDefault($h5iPv$fsextra)).readFileSync(serverFile); | ||
// console.log(decrypt(encrypted, key.secret, key.iv)); | ||
try { | ||
const allServer = JSON.parse($137088bc79f1e7e5$var$decrypt(encrypted, key.secret, key.iv)); | ||
return allServer || { | ||
}; | ||
} catch (e) { | ||
console.log('[model] readAllServer error:', e); | ||
return { | ||
}; | ||
} | ||
}; | ||
@@ -77,4 +135,5 @@ const $137088bc79f1e7e5$export$680eb78123d6b3c = async (server)=>{ | ||
allServer[$137088bc79f1e7e5$var$getServerKey(server)] = server; | ||
console.log($137088bc79f1e7e5$var$getPath($137088bc79f1e7e5$var$KEY_FILE), allServer); | ||
($parcel$interopDefault($h5iPv$fsextra)).writeJsonSync($137088bc79f1e7e5$var$getPath($137088bc79f1e7e5$var$KEY_FILE), allServer); | ||
const key = $137088bc79f1e7e5$var$getSecret(); | ||
const encrypted = $137088bc79f1e7e5$var$encrypt(JSON.stringify(allServer), key.secret, key.iv); | ||
($parcel$interopDefault($h5iPv$fsextra)).writeFileSync($137088bc79f1e7e5$var$getPath($137088bc79f1e7e5$var$SERVER_FILE), encrypted); | ||
}; | ||
@@ -81,0 +140,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
1275215
5041
2