vestauth 0.1.11 → 0.1.13

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vestauth",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "vestauth",
5
5
  "keywords": [
6
6
  "vestauth"
@@ -19,11 +19,21 @@
19
19
  "author": "@motdotla",
20
20
  "type": "commonjs",
21
21
  "scripts": {
22
- "test": "echo \"Error: no test specified\" && exit 1"
22
+ "standard": "standard",
23
+ "standard:fix": "standard --fix",
24
+ "test": "tap run --allow-empty-coverage --disable-coverage --timeout=60000",
25
+ "test-coverage": "tap run --show-full-coverage --timeout=60000",
26
+ "testshell": "bash shellspec",
27
+ "prerelease": "npm test && npm run testshell",
28
+ "release": "standard-version"
23
29
  },
24
30
  "dependencies": {
25
31
  "@noble/hashes": "^1.8.0",
26
32
  "@noble/secp256k1": "^3.0.0",
27
33
  "eciesjs": "^0.4.16"
34
+ },
35
+ "devDependencies": {
36
+ "standard": "^17.1.0",
37
+ "standard-version": "^9.5.0"
28
38
  }
29
39
  }
@@ -0,0 +1,7 @@
1
+ const crypto = require('crypto')
2
+
3
+ function challenge () {
4
+ return crypto.randomBytes(32).toString('base64url')
5
+ }
6
+
7
+ module.exports = challenge
@@ -1,8 +1,8 @@
1
1
  const { sha256 } = require('@noble/hashes/sha2.js')
2
2
  const { utf8ToBytes } = require('@noble/hashes/utils.js')
3
3
 
4
- function hash (message = 'hello') {
5
- return sha256(utf8ToBytes(message))
4
+ function hash (str = '') {
5
+ return sha256(utf8ToBytes(str))
6
6
  }
7
7
 
8
8
  module.exports = hash
@@ -6,16 +6,10 @@ secp.hashes.sha256 = sha256
6
6
  secp.hashes.hmacSha256 = (key, msg) => hmac(sha256, key, msg)
7
7
  const hash = require('./hash')
8
8
 
9
- // // publicKey (compressed): Uint8Array
10
- // const publicKey = getPublicKey(privateKey, true)
11
- //
12
- // // verifier side (server or client)
13
- // const ok = verify(signature, hash, publicKey)
14
-
15
- function sign (message, privateKeyHex) {
16
- const hashMessage = hash(message)
9
+ function sign (challenge, privateKeyHex) {
10
+ const hashChallenge = hash(challenge)
17
11
  const privateKeyBytes = Buffer.from(privateKeyHex, 'hex')
18
- const signature = secp.sign(hashMessage, privateKeyBytes)
12
+ const signature = secp.sign(hashChallenge, privateKeyBytes)
19
13
 
20
14
  return Buffer.from(signature).toString('base64url') // base64 returned
21
15
  }
@@ -1,17 +1,12 @@
1
- // import { sign, verify, getPublicKey } from '@noble/secp256k1'
2
- // // publicKey (compressed): Uint8Array
3
- // const publicKey = getPublicKey(privateKey, true)
4
- //
5
- // // verifier side (server or client)
6
- // const ok = verify(signature, hash, publicKey)
1
+ const secp = require('@noble/secp256k1')
2
+ const hash = require('./hash')
7
3
 
8
- function verify () {
9
- console.log('verify todo')
10
- // const hashMessage = hash(message)
11
- // const hashPrivateKey = hash(privateKey)
12
- // const signature = secp.sign(hashMessage, hashPrivateKey)
4
+ function verify (challenge, signatureBase64, publicKeyHex) {
5
+ const hashChallenge = hash(challenge)
6
+ const signature = Buffer.from(signatureBase64, 'base64url')
7
+ const publicKeyBytes = Buffer.from(publicKeyHex, 'hex')
13
8
 
14
- // return Buffer.from(signature).toString('base64url') // base64 returned
9
+ return secp.verify(signature, hashChallenge, publicKeyBytes)
15
10
  }
16
11
 
17
12
  module.exports = verify
package/src/lib/main.js CHANGED
@@ -1,9 +1,11 @@
1
+ const challenge = require('./helpers/challenge')
1
2
  const hash = require('./helpers/hash')
2
3
  const keypair = require('./helpers/keypair')
3
4
  const sign = require('./helpers/sign')
4
5
  const verify = require('./helpers/verify')
5
6
 
6
7
  module.exports = {
8
+ challenge,
7
9
  hash,
8
10
  keypair,
9
11
  sign,