vestauth 0.2.1 → 0.2.4
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/auth.js +19 -0
- 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 +31 -0
- package/src/cli/vestauth.js +3 -0
- package/src/lib/agent.js +9 -0
- package/src/lib/helpers/agentAuth.js +50 -0
- package/src/lib/helpers/agentInit.js +27 -0
- package/src/lib/helpers/hello.js +5 -0
- package/src/lib/helpers/touch.js +7 -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.4",
|
|
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,19 @@
|
|
|
1
|
+
const { logger } = require('./../../../shared/logger')
|
|
2
|
+
|
|
3
|
+
const agent = require('./../../../lib/agent')
|
|
4
|
+
|
|
5
|
+
async function auth (website) {
|
|
6
|
+
const options = this.opts()
|
|
7
|
+
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
8
|
+
|
|
9
|
+
const output = await agent.auth(website)
|
|
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 = auth
|
|
@@ -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,31 @@
|
|
|
1
|
+
const { Command } = require('commander')
|
|
2
|
+
|
|
3
|
+
const agent = new Command('agent')
|
|
4
|
+
|
|
5
|
+
agent
|
|
6
|
+
.description('🪪 agent')
|
|
7
|
+
.allowUnknownOption()
|
|
8
|
+
|
|
9
|
+
// vestauth agent auth
|
|
10
|
+
const authAction = require('./../actions/agent/auth')
|
|
11
|
+
agent.command('auth')
|
|
12
|
+
.description('auth agent')
|
|
13
|
+
.argument('<website>', 'root url of website')
|
|
14
|
+
.option('-pp, --pretty-print', 'pretty print output')
|
|
15
|
+
.action(authAction)
|
|
16
|
+
|
|
17
|
+
// vestauth agent init
|
|
18
|
+
const initAction = require('./../actions/agent/init')
|
|
19
|
+
agent.command('init')
|
|
20
|
+
.description('create agent')
|
|
21
|
+
.option('-pp, --pretty-print', 'pretty print output')
|
|
22
|
+
.action(initAction)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
// vestauth agent hello
|
|
26
|
+
const helloAction = require('./../actions/agent/hello')
|
|
27
|
+
agent.command('hello')
|
|
28
|
+
.description('say hello')
|
|
29
|
+
.action(helloAction)
|
|
30
|
+
|
|
31
|
+
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,50 @@
|
|
|
1
|
+
const { http } = require('./http')
|
|
2
|
+
const buildApiError = require('./buildApiError')
|
|
3
|
+
const sign = require('./sign')
|
|
4
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
5
|
+
|
|
6
|
+
async function agentAuth (website) {
|
|
7
|
+
let publicKey = null
|
|
8
|
+
let privateKey = null
|
|
9
|
+
try { publicKey = dotenvx.get('AGENT_PUBLIC_KEY', { strict: true }) } catch (_e) {}
|
|
10
|
+
try { privateKey = dotenvx.get('AGENT_PRIVATE_KEY', { strict: true }) } catch (_e) {}
|
|
11
|
+
|
|
12
|
+
if (!publicKey && !privateKey) throw new Error('missing AGENT_PUBLIC_KEY and AGENT_PRIVATE_KEY. Run [vestauth agent init]')
|
|
13
|
+
|
|
14
|
+
let signature
|
|
15
|
+
const url = `${website}/agent/auth`
|
|
16
|
+
|
|
17
|
+
if (!signature) {
|
|
18
|
+
const resp = await http(url, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Agent ${publicKey}:${signature}`,
|
|
22
|
+
'Content-Type': 'application/json'
|
|
23
|
+
},
|
|
24
|
+
body: JSON.stringify({})
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const json = await resp.body.json()
|
|
28
|
+
const challenge = json.challenge // grab challenge
|
|
29
|
+
signature = await sign(challenge, privateKey)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const resp = await http(url, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: {
|
|
35
|
+
Authorization: `Agent ${publicKey}:${signature}`,
|
|
36
|
+
'Content-Type': 'application/json'
|
|
37
|
+
},
|
|
38
|
+
body: JSON.stringify({})
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
if (resp.statusCode >= 400) {
|
|
42
|
+
const json = await resp.body.json()
|
|
43
|
+
return json
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const json = await resp.body.json()
|
|
47
|
+
return json
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = agentAuth
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const dotenvx = require('@dotenvx/dotenvx')
|
|
2
|
+
const keypair = require('./keypair')
|
|
3
|
+
const touch = require('./touch')
|
|
4
|
+
|
|
5
|
+
function agentInit () {
|
|
6
|
+
const envPath = '.env'
|
|
7
|
+
|
|
8
|
+
// keypair
|
|
9
|
+
let currentPrivateKey = null
|
|
10
|
+
try { currentPrivateKey = dotenvx.get('AGENT_PRIVATE_KEY', { strict: true }) } catch (e) {}
|
|
11
|
+
|
|
12
|
+
const kp = keypair(currentPrivateKey, 'agent')
|
|
13
|
+
|
|
14
|
+
touch(envPath)
|
|
15
|
+
|
|
16
|
+
// place in .env file
|
|
17
|
+
dotenvx.set('AGENT_PUBLIC_KEY', kp.publicKey, { path: envPath, plain: true, quiet: true })
|
|
18
|
+
dotenvx.set('AGENT_PRIVATE_KEY', kp.privateKey, { path: envPath, plain: true, quiet: true })
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
AGENT_PUBLIC_KEY: kp.publicKey,
|
|
22
|
+
AGENT_PRIVATE_KEY: kp.privateKey,
|
|
23
|
+
path: envPath
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = agentInit
|