vestauth 0.4.9 → 0.5.0

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 CHANGED
@@ -2,29 +2,28 @@
2
2
 
3
3
  *auth for agents*–from the creator of [`dotenvx`](https://github.com/dotenvx/dotenvx).
4
4
 
5
- * auth
5
+ * identity
6
+ * authentication
7
+ * messaging (coming soon)
6
8
 
7
9
   
8
10
 
9
11
  ### Quickstart [![npm version](https://img.shields.io/npm/v/vestauth.svg)](https://www.npmjs.com/package/vestauth) [![downloads](https://img.shields.io/npm/dw/vestauth)](https://www.npmjs.com/package/vestauth)
10
12
 
11
13
  ```sh
12
- npm install vestauth --save
13
- ```
14
- ```js
15
- // index.js
16
- // TODO
14
+ curl -sfS https://vestauth.sh | sh
15
+ vestauth agent init
16
+ vestauth agent curl https://api.vestauth.com/whoami
17
17
  ```
18
18
 
19
19
   
20
20
 
21
- or install globally - *unlocks vestauth for any language, framework, or platform!*
21
+ or install as npm - *unlocks vestauth inside code!*
22
22
 
23
- <details><summary>with curl 🌐 </summary><br>
23
+ <details><summary>with npm 📦</summary><br>
24
24
 
25
25
  ```sh
26
- curl -sfS https://vestauth.sh | sh
27
- vestauth help
26
+ npm install vestauth --save
28
27
  ```
29
28
 
30
29
  &nbsp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vestauth",
3
- "version": "0.4.9",
3
+ "version": "0.5.0",
4
4
  "description": "auth for agents–from the creator of dotenvx",
5
5
  "keywords": [
6
6
  "vestauth"
@@ -20,15 +20,19 @@ async function curl () {
20
20
  ...commandArgs
21
21
  ]
22
22
 
23
- const child = execute.execa(injected[0], injected.slice(1), { stdio: 'inherit' })
24
-
25
- // Wait for the command process to finish
26
- const { exitCode } = await child
23
+ const { stdout, exitCode } = await execute.execa(injected[0], injected.slice(1), {})
27
24
 
28
25
  if (exitCode !== 0) {
29
26
  logger.debug(`received exitCode ${exitCode}`)
30
27
  throw new Error(`Command exited with exit code ${exitCode}`)
31
28
  }
29
+
30
+ let space = 0
31
+ if (options.prettyPrint) {
32
+ space = 2
33
+ }
34
+
35
+ console.log(JSON.stringify(JSON.parse(stdout), null, space))
32
36
  }
33
37
 
34
38
  module.exports = curl
@@ -8,12 +8,13 @@ async function init () {
8
8
 
9
9
  const output = await agent.init()
10
10
 
11
- let space = 0
12
- if (options.prettyPrint) {
13
- space = 2
11
+ if (output.isNew) {
12
+ logger.success(`✔ agent created (${output.path}/AGENT_ID=${output.AGENT_ID})`)
13
+ } else {
14
+ logger.info(`agent exists (${output.path}/AGENT_ID=${output.AGENT_ID})`)
14
15
  }
15
16
 
16
- console.log(JSON.stringify(output, null, space))
17
+ logger.help('⮕ next run: [vestauth agent curl https://api.vestauth.com/whoami]')
17
18
  }
18
19
 
19
20
  module.exports = init
@@ -4,7 +4,7 @@ const agent = new Command('agent')
4
4
 
5
5
  agent
6
6
  .usage('run -- yourcommand')
7
- .description('🤖 agent')
7
+ .description('▶️ agent')
8
8
  .allowUnknownOption()
9
9
 
10
10
  // vestauth agent init
@@ -19,7 +19,7 @@ const curlAction = require('./../actions/agent/curl')
19
19
  agent.command('curl')
20
20
  .description('run curl as agent')
21
21
  .allowUnknownOption()
22
- .option('--tag <tag>', 'vestauth (default) | web-bot-auth', 'vestauth')
22
+ .option('--tag <tag>', 'web-bot-auth (default) | web-bot-auth', 'vestauth')
23
23
  .option('--nonce <nonce>', 'null (default)')
24
24
  .option('-pp, --pretty-print', 'pretty print output')
25
25
  .action(curlAction)
@@ -30,7 +30,7 @@ agent.command('headers')
30
30
  .description('generate headers as agent')
31
31
  .argument('<httpMethod>', 'GET (default)')
32
32
  .argument('<uri>', '')
33
- .option('--tag <tag>', 'vestauth (default) | web-bot-auth', 'vestauth')
33
+ .option('--tag <tag>', 'web-bot-auth (default) | web-bot-auth', 'vestauth')
34
34
  .option('--nonce <nonce>', 'null (default)')
35
35
  .option('--privateKey <privateKey>', 'AGENT_PUBLIC_KEY (default)')
36
36
  .option('-pp, --pretty-print', 'pretty print output')
@@ -22,7 +22,7 @@ primitives.command('headers')
22
22
  .argument('<httpMethod>', 'GET (default)')
23
23
  .argument('<uri>', '')
24
24
  .argument('<privateKey>', 'private key (json string)')
25
- .option('--tag <tag>', 'vestauth (default) | web-bot-auth', 'vestauth')
25
+ .option('--tag <tag>', 'web-bot-auth (default) | web-bot-auth', 'vestauth')
26
26
  .option('--nonce <nonce>', 'null (default)')
27
27
  .option('-pp, --pretty-print', 'pretty print output')
28
28
  .action(headersAction)
@@ -13,6 +13,7 @@ async function agentInit () {
13
13
 
14
14
  touch(envPath)
15
15
 
16
+ // must come before registration so that registration can send headers
16
17
  dotenvx.set('AGENT_PUBLIC_KEY', JSON.stringify(kp.publicKey), { path: envPath, plain: true, quiet: true })
17
18
  dotenvx.set('AGENT_PRIVATE_KEY', JSON.stringify(kp.privateKey), { path: envPath, plain: true, quiet: true })
18
19
 
@@ -23,7 +24,8 @@ async function agentInit () {
23
24
  return {
24
25
  AGENT_PUBLIC_KEY: kp.publicKey,
25
26
  AGENT_ID: agent.uid,
26
- path: envPath
27
+ path: envPath,
28
+ isNew: agent.is_new
27
29
  }
28
30
  }
29
31
 
@@ -3,7 +3,16 @@ const signatureParams = require('./signatureParams')
3
3
  const webBotAuthSignature = require('./webBotAuthSignature')
4
4
 
5
5
  async function headers (httpMethod, uri, privateKeyString, tag = 'vestauth', nonce = null) {
6
- const privateKey = JSON.parse(privateKeyString)
6
+ if (!privateKeyString) throw new Error('missing privateKey')
7
+
8
+ let privateKey
9
+ try {
10
+ privateKey = JSON.parse(privateKeyString)
11
+ } catch (err) {
12
+ throw new Error('invalid privateKey')
13
+ }
14
+ if (!privateKey || typeof privateKey !== 'object') throw new Error('invalid privateKey')
15
+
7
16
  const kid = thumbprint(privateKey)
8
17
  privateKey.kid = kid
9
18
 
@@ -2,7 +2,11 @@ const crypto = require('crypto')
2
2
 
3
3
  function thumbprint (publicJwk) {
4
4
  // RFC 7638 canonical JSON for OKP (Ed25519)
5
- const canon = `{"crv":"${publicJwk.crv}","kty":"${publicJwk.kty}","x":"${publicJwk.x}"}`
5
+ const jwk = publicJwk && typeof publicJwk === 'object' ? publicJwk : {}
6
+ const crv = jwk.crv || ''
7
+ const kty = jwk.kty || ''
8
+ const x = jwk.x || ''
9
+ const canon = `{"crv":"${crv}","kty":"${kty}","x":"${x}"}`
6
10
  const sha256 = crypto.createHash('sha256').update(canon).digest()
7
11
  return Buffer.from(sha256).toString('base64url')
8
12
  }