vestauth 0.4.2 → 0.4.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/package.json +1 -1
- package/src/cli/actions/agent/headers.js +1 -1
- package/src/cli/actions/agent/init.js +2 -2
- package/src/cli/commands/agent.js +1 -0
- package/src/lib/api/postAgentRegister.js +7 -4
- package/src/lib/helpers/agentHeaders.js +4 -2
- package/src/lib/helpers/agentInit.js +1 -2
- package/src/lib/helpers/providerVerify.js +1 -1
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@ async function headers (httpMethod, uri) {
|
|
|
9
9
|
const options = this.opts()
|
|
10
10
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
11
11
|
|
|
12
|
-
const output = await agent.headers(httpMethod, uri, options.tag, options.nonce)
|
|
12
|
+
const output = await agent.headers(httpMethod, uri, options.tag, options.nonce, options.privateKey)
|
|
13
13
|
|
|
14
14
|
let space = 0
|
|
15
15
|
if (options.prettyPrint) {
|
|
@@ -2,11 +2,11 @@ const { logger } = require('./../../../shared/logger')
|
|
|
2
2
|
|
|
3
3
|
const agent = require('./../../../lib/agent')
|
|
4
4
|
|
|
5
|
-
function init () {
|
|
5
|
+
async function init () {
|
|
6
6
|
const options = this.opts()
|
|
7
7
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
8
8
|
|
|
9
|
-
const output = agent.init()
|
|
9
|
+
const output = await agent.init()
|
|
10
10
|
|
|
11
11
|
let space = 0
|
|
12
12
|
if (options.prettyPrint) {
|
|
@@ -32,6 +32,7 @@ agent.command('headers')
|
|
|
32
32
|
.argument('<uri>', '')
|
|
33
33
|
.option('--tag <tag>', 'vestauth (default) | web-bot-auth', 'vestauth')
|
|
34
34
|
.option('--nonce <nonce>', 'null (default)')
|
|
35
|
+
.option('--privateKey <privateKey>', 'AGENT_PUBLIC_KEY (default)')
|
|
35
36
|
.option('-pp, --pretty-print', 'pretty print output')
|
|
36
37
|
.action(headersAction)
|
|
37
38
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const { http } = require('../helpers/http')
|
|
2
2
|
const buildApiError = require('../helpers/buildApiError')
|
|
3
|
+
const agentHeaders = require('../helpers/agentHeaders')
|
|
3
4
|
|
|
4
5
|
class PostAgentRegister {
|
|
5
6
|
constructor (hostname, publicJwk) {
|
|
@@ -11,11 +12,13 @@ class PostAgentRegister {
|
|
|
11
12
|
const url = `${this.hostname}/api/agent/register`
|
|
12
13
|
const publicJwk = this.publicJwk
|
|
13
14
|
|
|
15
|
+
const httpMethod = 'POST'
|
|
16
|
+
const headers = await agentHeaders(httpMethod, url)
|
|
17
|
+
headers['Content-Type'] = 'application/json'
|
|
18
|
+
|
|
14
19
|
const resp = await http(url, {
|
|
15
|
-
method:
|
|
16
|
-
headers
|
|
17
|
-
'Content-Type': 'application/json'
|
|
18
|
-
},
|
|
20
|
+
method: httpMethod,
|
|
21
|
+
headers,
|
|
19
22
|
body: JSON.stringify({
|
|
20
23
|
public_jwk: publicJwk
|
|
21
24
|
})
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const headers = require('./headers')
|
|
2
2
|
const identity = require('./identity')
|
|
3
3
|
|
|
4
|
-
async function agentHeaders (httpMethod, uri, tag = 'vestauth', nonce = null) {
|
|
5
|
-
|
|
4
|
+
async function agentHeaders (httpMethod, uri, tag = 'vestauth', nonce = null, privateKey = null) {
|
|
5
|
+
if (!privateKey) {
|
|
6
|
+
privateKey = identity().privateKey
|
|
7
|
+
}
|
|
6
8
|
|
|
7
9
|
return await headers(httpMethod, uri, privateKey, tag, nonce)
|
|
8
10
|
}
|
|
@@ -18,8 +18,7 @@ async function agentInit () {
|
|
|
18
18
|
dotenvx.set('AGENT_PRIVATE_KEY', JSON.stringify(kp.privateKey), { path: envPath, plain: true, quiet: true })
|
|
19
19
|
|
|
20
20
|
// register agent with api
|
|
21
|
-
|
|
22
|
-
await postAgentRegister.run()
|
|
21
|
+
await new PostAgentRegister(null, kp.publicKey).run()
|
|
23
22
|
|
|
24
23
|
return {
|
|
25
24
|
AGENT_PUBLIC_KEY: kp.publicKey,
|
|
@@ -5,7 +5,7 @@ const stripDictionaryKey = require('./stripDictionaryKey')
|
|
|
5
5
|
const authorityMessage = require('./authorityMessage')
|
|
6
6
|
const edPublicKeyObject = require('./edPublicKeyObject')
|
|
7
7
|
|
|
8
|
-
function providerVerify (
|
|
8
|
+
function providerVerify (httpMethod, uri, signatureHeader, signatureInputHeader, publicKey) {
|
|
9
9
|
const { values } = parseSignatureInputHeader(signatureInputHeader)
|
|
10
10
|
const { expires } = values
|
|
11
11
|
|