vestauth 0.2.0 → 0.2.3
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/README.md +31 -2
- package/package.json +3 -2
- package/src/cli/actions/agent/hello.js +22 -0
- package/src/cli/actions/agent/init.js +19 -0
- package/src/cli/actions/primitives/challenge.js +2 -2
- package/src/cli/actions/primitives/hash.js +2 -2
- package/src/cli/actions/primitives/keypair.js +2 -2
- package/src/cli/actions/primitives/sign.js +2 -2
- package/src/cli/actions/primitives/verify.js +2 -2
- package/src/cli/commands/agent.js +22 -0
- package/src/cli/vestauth.js +3 -0
- package/src/lib/agent.js +7 -0
- package/src/lib/helpers/agentInit.js +30 -0
- package/src/lib/helpers/hello.js +5 -0
- package/src/lib/helpers/touch.js +7 -0
- package/src/lib/main.js +2 -10
- package/src/lib/primitives.js +13 -0
package/README.md
CHANGED
|
@@ -1,3 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
[](https://vestauth.com)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
*auth for agents*–from the creator of [`dotenvx`](https://github.com/dotenvx/dotenvx).
|
|
4
|
+
|
|
5
|
+
* auth
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Quickstart [](https://www.npmjs.com/package/vestauth) [](https://www.npmjs.com/package/vestauth)
|
|
10
|
+
|
|
11
|
+
```sh
|
|
12
|
+
npm install vestauth --save
|
|
13
|
+
```
|
|
14
|
+
```js
|
|
15
|
+
// index.js
|
|
16
|
+
// TODO
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
or install globally - *unlocks vestauth for any language, framework, or platform!*
|
|
22
|
+
|
|
23
|
+
<details><summary>with curl 🌐 </summary><br>
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
curl -sfS https://vestauth.sh | sh
|
|
27
|
+
vestauth help
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
</details>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vestauth",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "auth for agents",
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "auth for agents–from the creator of dotenvx",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vestauth"
|
|
7
7
|
],
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"release": "standard-version"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
+
"@dotenvx/dotenvx": "^1.52.0",
|
|
40
41
|
"@noble/hashes": "^1.8.0",
|
|
41
42
|
"@noble/secp256k1": "^1.7.2",
|
|
42
43
|
"commander": "^11.1.0",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { logger } = require('./../../../shared/logger')
|
|
2
|
+
|
|
3
|
+
const agent = require('./../../../lib/agent')
|
|
4
|
+
|
|
5
|
+
function hello () {
|
|
6
|
+
const options = this.opts()
|
|
7
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const output = {
|
|
11
|
+
hello: agent.hello()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let space = 0
|
|
15
|
+
if (options.prettyPrint) {
|
|
16
|
+
space = 2
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
console.log(JSON.stringify(output, null, space))
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = hello
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const { logger } = require('./../../../shared/logger')
|
|
2
|
+
|
|
3
|
+
const agent = require('./../../../lib/agent')
|
|
4
|
+
|
|
5
|
+
function init () {
|
|
6
|
+
const options = this.opts()
|
|
7
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
8
|
+
|
|
9
|
+
const output = agent.init()
|
|
10
|
+
|
|
11
|
+
let space = 0
|
|
12
|
+
if (options.prettyPrint) {
|
|
13
|
+
space = 2
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
console.log(JSON.stringify(output, null, space))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = init
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const { logger } = require('./../../../shared/logger')
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const primitives = require('./../../../lib/primitives')
|
|
4
4
|
|
|
5
5
|
function challenge () {
|
|
6
6
|
const options = this.opts()
|
|
7
7
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
8
8
|
|
|
9
|
-
const chal =
|
|
9
|
+
const chal = primitives.challenge()
|
|
10
10
|
|
|
11
11
|
const output = {
|
|
12
12
|
challenge: chal
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { logger } = require('./../../../shared/logger')
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const primitives = require('./../../../lib/primitives')
|
|
4
4
|
|
|
5
5
|
function hash (message) {
|
|
6
6
|
logger.debug(`message: ${message}`)
|
|
@@ -8,7 +8,7 @@ function hash (message) {
|
|
|
8
8
|
const options = this.opts()
|
|
9
9
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
10
10
|
|
|
11
|
-
const hashMessage =
|
|
11
|
+
const hashMessage = primitives.hash(message)
|
|
12
12
|
const hashBase64Url = Buffer.from(hashMessage).toString('base64url')
|
|
13
13
|
|
|
14
14
|
const output = {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const { logger } = require('./../../../shared/logger')
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const primitives = require('./../../../lib/primitives')
|
|
4
4
|
|
|
5
5
|
function keypair (existingPrivateKey) {
|
|
6
6
|
const options = this.opts()
|
|
7
7
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
8
8
|
|
|
9
|
-
const kp =
|
|
9
|
+
const kp = primitives.keypair(existingPrivateKey, options.prefix)
|
|
10
10
|
|
|
11
11
|
const output = {
|
|
12
12
|
public_key: kp.publicKey,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { logger } = require('./../../../shared/logger')
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const primitives = require('./../../../lib/primitives')
|
|
4
4
|
|
|
5
5
|
async function sign (challenge, privateKeyHex) {
|
|
6
6
|
logger.debug(`challenge: ${challenge}`)
|
|
@@ -9,7 +9,7 @@ async function sign (challenge, privateKeyHex) {
|
|
|
9
9
|
const options = this.opts()
|
|
10
10
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
11
11
|
|
|
12
|
-
const signature = await
|
|
12
|
+
const signature = await primitives.sign(challenge, privateKeyHex)
|
|
13
13
|
|
|
14
14
|
const output = {
|
|
15
15
|
signature
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const { logger } = require('./../../../shared/logger')
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const primitives = require('./../../../lib/primitives')
|
|
4
4
|
|
|
5
5
|
async function verify (challenge, signatureBase64, publicKeyHex) {
|
|
6
6
|
logger.debug(`challenge: ${challenge}`)
|
|
@@ -10,7 +10,7 @@ async function verify (challenge, signatureBase64, publicKeyHex) {
|
|
|
10
10
|
const options = this.opts()
|
|
11
11
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
12
12
|
|
|
13
|
-
const success =
|
|
13
|
+
const success = primitives.verify(challenge, signatureBase64, publicKeyHex)
|
|
14
14
|
|
|
15
15
|
const output = {
|
|
16
16
|
success,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const { Command } = require('commander')
|
|
2
|
+
|
|
3
|
+
const agent = new Command('agent')
|
|
4
|
+
|
|
5
|
+
agent
|
|
6
|
+
.description('🪪 agent')
|
|
7
|
+
.allowUnknownOption()
|
|
8
|
+
|
|
9
|
+
// vestauth agent init
|
|
10
|
+
const initAction = require('./../actions/agent/init')
|
|
11
|
+
agent.command('init')
|
|
12
|
+
.description('create agent')
|
|
13
|
+
.option('-pp, --pretty-print', 'pretty print output')
|
|
14
|
+
.action(initAction)
|
|
15
|
+
|
|
16
|
+
// vestauth agent hello
|
|
17
|
+
const helloAction = require('./../actions/agent/hello')
|
|
18
|
+
agent.command('hello')
|
|
19
|
+
.description('say hello')
|
|
20
|
+
.action(helloAction)
|
|
21
|
+
|
|
22
|
+
module.exports = agent
|
package/src/cli/vestauth.js
CHANGED
|
@@ -38,6 +38,9 @@ program
|
|
|
38
38
|
.version(packageJson.version)
|
|
39
39
|
.allowUnknownOption()
|
|
40
40
|
|
|
41
|
+
// dotenvx agent
|
|
42
|
+
program.addCommand(require('./commands/agent'))
|
|
43
|
+
|
|
41
44
|
// vestauth verifyAgent
|
|
42
45
|
const verifyAgentAction = require('./actions/verifyAgent')
|
|
43
46
|
program.command('verifyagent')
|
package/src/lib/agent.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
2
|
+
const keypair = require('./keypair')
|
|
3
|
+
const touch = require('./touch')
|
|
4
|
+
|
|
5
|
+
const PUBLIC_KEYNAME = 'AGENT_PUBLIC_KEY'
|
|
6
|
+
const PRIVATE_KEYNAME = 'AGENT_PRIVATE_KEY'
|
|
7
|
+
|
|
8
|
+
function agentInit () {
|
|
9
|
+
const envPath = '.env'
|
|
10
|
+
|
|
11
|
+
// keypair
|
|
12
|
+
let currentPrivateKey = null
|
|
13
|
+
try { currentPrivateKey = dotenvx.get('AGENT_PRIVATE_KEY', { strict: true }) } catch (e) {}
|
|
14
|
+
|
|
15
|
+
const kp = keypair(currentPrivateKey, 'agent')
|
|
16
|
+
|
|
17
|
+
touch(envPath)
|
|
18
|
+
|
|
19
|
+
// place in .env file
|
|
20
|
+
dotenvx.set('AGENT_PUBLIC_KEY', kp.publicKey, { path: envPath, plain: true, quiet: true })
|
|
21
|
+
dotenvx.set('AGENT_PRIVATE_KEY', kp.privateKey, { path: envPath, plain: true, quiet: true })
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
AGENT_PUBLIC_KEY: kp.publicKey,
|
|
25
|
+
AGENT_PRIVATE_KEY: kp.privateKey,
|
|
26
|
+
path: envPath
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = agentInit
|
package/src/lib/main.js
CHANGED
|
@@ -1,17 +1,9 @@
|
|
|
1
|
-
const challenge = require('./helpers/challenge')
|
|
2
|
-
const hash = require('./helpers/hash')
|
|
3
|
-
const keypair = require('./helpers/keypair')
|
|
4
|
-
const sign = require('./helpers/sign')
|
|
5
|
-
const verify = require('./helpers/verify')
|
|
6
1
|
const verifyAuthorizationHeader = require('./helpers/verifyAuthorizationHeader')
|
|
7
2
|
const verifyAgent = require('./helpers/verifyAgent')
|
|
3
|
+
const primitives = require('./primitives')
|
|
8
4
|
|
|
9
5
|
module.exports = {
|
|
10
|
-
|
|
11
|
-
hash,
|
|
12
|
-
keypair,
|
|
13
|
-
sign,
|
|
14
|
-
verify,
|
|
6
|
+
primitives,
|
|
15
7
|
verifyAuthorizationHeader,
|
|
16
8
|
verifyAgent
|
|
17
9
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const challenge = require('./helpers/challenge')
|
|
2
|
+
const hash = require('./helpers/hash')
|
|
3
|
+
const keypair = require('./helpers/keypair')
|
|
4
|
+
const sign = require('./helpers/sign')
|
|
5
|
+
const verify = require('./helpers/verify')
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
challenge,
|
|
9
|
+
hash,
|
|
10
|
+
keypair,
|
|
11
|
+
sign,
|
|
12
|
+
verify
|
|
13
|
+
}
|