vestauth 0.7.4 → 0.8.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/CHANGELOG.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
- [Unreleased](https://github.com/vestauth/vestauth/compare/v0.7.4...main)
5
+ [Unreleased](https://github.com/vestauth/vestauth/compare/v0.8.0...main)
6
+
7
+ ## [0.8.0](https://github.com/vestauth/vestauth/compare/v0.7.4...v0.8.0) (2026-02-05)
8
+
9
+ ### Added
10
+
11
+ * Return agent json on successful verify
6
12
 
7
13
  ## [0.7.4](https://github.com/vestauth/vestauth/compare/v0.7.3...v0.7.4) (2026-02-05)
8
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vestauth",
3
- "version": "0.7.4",
3
+ "version": "0.8.0",
4
4
  "description": "auth for agents–from the creator of dotenvx",
5
5
  "keywords": [
6
6
  "vestauth"
@@ -25,7 +25,7 @@ async function verify (httpMethod, uri) {
25
25
  'Signature-Agent': options.signatureAgent
26
26
  }
27
27
 
28
- const publicJwk = JSON.parse(options.publicJwk || {})
28
+ const publicJwk = options.publicJwk ? JSON.parse(options.publicJwk) : undefined
29
29
 
30
30
  const output = await primitives.verify(httpMethod, uri, headers, publicJwk)
31
31
  // const output = await primitive.verifyWebBotAuth(httpMethod, uri, signature, signatureInput, JSON.parse(publicJwk))
@@ -63,6 +63,17 @@ class Errors {
63
63
  return e
64
64
  }
65
65
 
66
+ missingPublicJwk () {
67
+ const code = 'MISSING_PUBLIC_JWK'
68
+ const message = `[${code}] missing --public-jwk (AGENT_PUBLIC_JWK) or --signature-agent`
69
+ const help = `[${code}] provide a public JWK or a signature agent for lookup`
70
+
71
+ const e = new Error(message)
72
+ e.code = code
73
+ e.help = help
74
+ return e
75
+ }
76
+
66
77
  invalidSignatureAgent () {
67
78
  const code = 'INVALID_SIGNATURE_AGENT'
68
79
  const message = `[${code}] invalid --signature-agent`
@@ -1,7 +1,3 @@
1
- const { http } = require('./http')
2
- const buildApiError = require('./buildApiError')
3
- const parseSignatureAgentHeader = require('./parseSignatureAgentHeader')
4
- const verifyAgentFqdn = require('./verifyAgentFqdn')
5
1
  const verify = require('./verify')
6
2
  const Errors = require('./errors')
7
3
 
@@ -18,35 +14,7 @@ async function providerVerify (httpMethod, uri, headers = {}) {
18
14
  throw new Errors().missingSignatureAgent()
19
15
  }
20
16
 
21
- const { value } = parseSignatureAgentHeader(signatureAgent) // sig1=agent-1234.agents.vestauth.com
22
- const fqdn = value
23
- verifyAgentFqdn(fqdn)
24
- const origin = `https://${fqdn}` // https://agent-1234.agents.vestauth.com
25
-
26
- // get jwks from .well-known
27
- const url = `${origin}/.well-known/http-message-signatures-directory` // risk of SSRF ?
28
- const resp = await http(url, { method: 'GET', headers: { 'Content-Type': 'application/json' } })
29
- if (resp.statusCode >= 400) {
30
- const json = await resp.body.json()
31
- throw buildApiError(resp.statusCode, json)
32
- }
33
- const json = await resp.body.json()
34
-
35
- // example json
36
- // {
37
- // keys: [
38
- // {
39
- // x: 'IaqY8f2Qp8EpS1qP7AssY0QE4I8PJDwHInLwDfB9WaU',
40
- // crv: 'Ed25519',
41
- // kid: 'i1B0cEjNvnSBm_TSVS87nqDj7IRfC_Q2eU-SywVxtNI',
42
- // kty: 'OKP'
43
- // }
44
- // ]
45
- // }
46
-
47
- // use publicJwk to verify
48
- const publicJwk = json.keys[0]
49
- return await verify(httpMethod, uri, headers, publicJwk)
17
+ return verify(httpMethod, uri, headers)
50
18
  }
51
19
 
52
20
  module.exports = providerVerify
@@ -1,14 +1,65 @@
1
1
  const crypto = require('crypto')
2
2
 
3
+ const { http } = require('./http')
4
+ const buildApiError = require('./buildApiError')
5
+ const parseSignatureAgentHeader = require('./parseSignatureAgentHeader')
3
6
  const parseSignatureInputHeader = require('./parseSignatureInputHeader')
4
7
  const stripDictionaryKey = require('./stripDictionaryKey')
5
8
  const authorityMessage = require('./authorityMessage')
6
9
  const publicJwkObject = require('./publicJwkObject')
10
+ const verifyAgentFqdn = require('./verifyAgentFqdn')
7
11
  const Errors = require('./errors')
8
12
 
9
- function verify (httpMethod, uri, headers = {}, publicJwk) {
13
+ async function resolvePublicJwk ({ signatureInput, signatureAgent, publicJwk }) {
14
+ let uid
15
+ let wellKnownUrl
16
+
17
+ const { values } = parseSignatureInputHeader(signatureInput)
18
+ const kid = values.keyid
19
+
20
+ if (signatureAgent) {
21
+ const { value } = parseSignatureAgentHeader(signatureAgent)
22
+ const fqdn = value
23
+ verifyAgentFqdn(fqdn)
24
+ const origin = `https://${fqdn}`
25
+ uid = fqdn.split('.')[0]
26
+ wellKnownUrl = `${origin}/.well-known/http-message-signatures-directory`
27
+ }
28
+
29
+ if (publicJwk) {
30
+ return { uid, kid, publicJwk, wellKnownUrl }
31
+ }
32
+ if (!signatureAgent) {
33
+ return { publicJwk: null }
34
+ }
35
+
36
+ const resp = await http(wellKnownUrl, { method: 'GET', headers: { 'Content-Type': 'application/json' } })
37
+ if (resp.statusCode >= 400) {
38
+ const json = await resp.body.json()
39
+ throw buildApiError(resp.statusCode, json)
40
+ }
41
+ const json = await resp.body.json()
42
+
43
+ let resolvedPublicJwk = json.keys[0]
44
+ if (kid) {
45
+ resolvedPublicJwk = json.keys.find((key) => key.kid === kid)
46
+ if (!resolvedPublicJwk) {
47
+ throw new Errors().invalidSignature()
48
+ }
49
+ }
50
+
51
+ return {
52
+ uid,
53
+ kid,
54
+ publicJwk: resolvedPublicJwk,
55
+ wellKnownUrl
56
+ }
57
+ }
58
+
59
+ async function verify (httpMethod, uri, headers = {}, publicJwk) {
10
60
  const signature = headers.Signature || headers.signature
11
61
  const signatureInput = headers['Signature-Input'] || headers['signature-input']
62
+ const signatureAgent = headers['Signature-Agent'] || headers['signature-agent']
12
63
 
13
64
  const { values } = parseSignatureInputHeader(signatureInput)
14
65
  const { expires } = values
@@ -16,6 +67,11 @@ function verify (httpMethod, uri, headers = {}, publicJwk) {
16
67
  throw new Errors().expiredSignature()
17
68
  }
18
69
 
70
+ const resolved = await resolvePublicJwk({ signatureInput, signatureAgent, publicJwk })
71
+ if (!resolved.publicJwk) {
72
+ throw new Errors().missingPublicJwk()
73
+ }
74
+
19
75
  const signatureParams = stripDictionaryKey(signatureInput)
20
76
  const sig = stripDictionaryKey(signature)
21
77
  const message = authorityMessage(uri, signatureParams)
@@ -23,7 +79,7 @@ function verify (httpMethod, uri, headers = {}, publicJwk) {
23
79
  const success = crypto.verify(
24
80
  null,
25
81
  Buffer.from(message, 'utf8'),
26
- publicJwkObject(publicJwk),
82
+ publicJwkObject(resolved.publicJwk),
27
83
  Buffer.from(sig, 'base64')
28
84
  )
29
85
 
@@ -31,9 +87,13 @@ function verify (httpMethod, uri, headers = {}, publicJwk) {
31
87
  throw new Errors().invalidSignature()
32
88
  }
33
89
 
34
- return {
35
- success
36
- }
90
+ const output = {}
91
+ if (resolved.uid) output.uid = resolved.uid
92
+ if (resolved.kid) output.kid = resolved.kid
93
+ if (resolved.publicJwk) output.public_jwk = resolved.publicJwk
94
+ if (resolved.wellKnownUrl) output.well_known_url = resolved.wellKnownUrl
95
+
96
+ return output
37
97
  }
38
98
 
39
99
  module.exports = verify