@dotenvx/primitives 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
- "version": "0.1.0",
2
+ "version": "0.2.1",
3
3
  "name": "@dotenvx/primitives",
4
4
  "description": "a secure dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
6
6
  "keywords": [
7
+ "dotenvx",
7
8
  "dotenv",
8
9
  "env"
9
10
  ],
@@ -13,22 +14,27 @@
13
14
  "url": "git+https://github.com/dotenvx/dotenvx.git"
14
15
  },
15
16
  "license": "BSD-3-Clause",
17
+ "main": "dist/index.cjs",
18
+ "exports": {
19
+ ".": "./dist/index.cjs"
20
+ },
16
21
  "files": [
17
- "src/**/*"
22
+ "dist/**/*",
23
+ "LICENSE",
24
+ "README.md"
18
25
  ],
19
26
  "scripts": {
20
- "standard": "standard",
21
- "standard:fix": "standard --fix"
27
+ "build": "esbuild src/index.js --bundle --platform=node --format=cjs --target=node16 --outfile=dist/index.cjs --legal-comments=none",
28
+ "prepack": "npm run build",
29
+ "prepublishOnly": "npm pack --dry-run",
30
+ "standard": "standard src",
31
+ "standard:fix": "standard src --fix"
22
32
  },
23
- "dependencies": {
33
+ "devDependencies": {
34
+ "esbuild": "^0.28.1",
24
35
  "eciesjs": "^0.5.0"
25
36
  },
26
37
  "publishConfig": {
27
38
  "access": "public"
28
- },
29
- "main": "src/index.js",
30
- "exports": {
31
- ".": "./src/index.js",
32
- "./decrypt": "./src/decrypt.js"
33
39
  }
34
40
  }
package/src/decrypt.js DELETED
@@ -1,32 +0,0 @@
1
- const { decrypt: eciesDecrypt } = require('eciesjs')
2
- const Errors = require('./errors')
3
-
4
- const PREFIX = 'encrypted:'
5
-
6
- function decrypt (privateKeyHex, encryptedValue) {
7
- if (!encryptedValue.startsWith(PREFIX)) {
8
- return encryptedValue
9
- }
10
-
11
- if (!privateKeyHex || privateKeyHex.length < 1) {
12
- throw new Errors().missingPrivateKey()
13
- }
14
-
15
- try {
16
- const privateKey = Buffer.from(privateKeyHex, 'hex')
17
- const ciphertext = Buffer.from(encryptedValue.substring(PREFIX.length), 'base64')
18
- return Buffer.from(eciesDecrypt(privateKey, ciphertext)).toString('utf8')
19
- } catch (e) {
20
- if (e.message === 'Invalid private key') {
21
- throw new Errors().invalidPrivateKey()
22
- } else if (e.message === 'Unsupported state or unable to authenticate data') {
23
- throw new Errors().wrongPrivateKey()
24
- } else if (e.message === 'Point of length 65 was invalid. Expected 33 compressed bytes or 65 uncompressed bytes') {
25
- throw new Errors().malformedEncryptedData()
26
- } else {
27
- throw new Errors({ message: e.message }).decryptionFailed()
28
- }
29
- }
30
- }
31
-
32
- module.exports = decrypt
package/src/errors.js DELETED
@@ -1,77 +0,0 @@
1
- const ISSUE_BY_CODE = {
2
- MISSING_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/464',
3
- INVALID_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/465',
4
- WRONG_PRIVATE_KEY: 'https://github.com/dotenvx/dotenvx/issues/466',
5
- MALFORMED_ENCRYPTED_DATA: 'https://github.com/dotenvx/dotenvx/issues/467',
6
- DECRYPTION_FAILED: 'https://github.com/dotenvx/dotenvx/issues/757'
7
- }
8
-
9
- class Errors {
10
- constructor (options = {}) {
11
- this.message = options.message
12
- }
13
-
14
- missingPrivateKey () {
15
- const code = 'MISSING_PRIVATE_KEY'
16
- const message = `[${code}] could not decrypt because private key is missing`
17
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
18
-
19
- const e = new Error(message)
20
- e.code = code
21
- e.help = help
22
- e.messageWithHelp = `${message}. ${help}`
23
- return e
24
- }
25
-
26
- invalidPrivateKey () {
27
- const code = 'INVALID_PRIVATE_KEY'
28
- const message = `[${code}] could not decrypt using private key`
29
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
30
-
31
- const e = new Error(message)
32
- e.code = code
33
- e.help = help
34
- e.messageWithHelp = `${message}. ${help}`
35
- return e
36
- }
37
-
38
- wrongPrivateKey () {
39
- const code = 'WRONG_PRIVATE_KEY'
40
- const message = `[${code}] could not decrypt using private key`
41
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
42
-
43
- const e = new Error(message)
44
- e.code = code
45
- e.help = help
46
- e.messageWithHelp = `${message}. ${help}`
47
- return e
48
- }
49
-
50
- malformedEncryptedData () {
51
- const code = 'MALFORMED_ENCRYPTED_DATA'
52
- const message = `[${code}] could not decrypt because encrypted data appears malformed`
53
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
54
-
55
- const e = new Error(message)
56
- e.code = code
57
- e.help = help
58
- e.messageWithHelp = `${message}. ${help}`
59
- return e
60
- }
61
-
62
- decryptionFailed () {
63
- const code = 'DECRYPTION_FAILED'
64
- const message = `[${code}] ${this.message}`
65
- const help = `fix: [${ISSUE_BY_CODE[code]}]`
66
-
67
- const e = new Error(message)
68
- e.code = code
69
- e.help = help
70
- e.messageWithHelp = `${message}. ${help}`
71
- return e
72
- }
73
- }
74
-
75
- Errors.ISSUE_BY_CODE = ISSUE_BY_CODE
76
-
77
- module.exports = Errors
package/src/index.js DELETED
@@ -1,5 +0,0 @@
1
- const decrypt = require('./decrypt')
2
-
3
- module.exports = {
4
- decrypt
5
- }