Skip to content

Commit

Permalink
Merge pull request #5 from GustavoOS/feature/issue-3-with-tests
Browse files Browse the repository at this point in the history
Remove base64url package in favor of Node's built-in `Buffer` api.
  • Loading branch information
tmountjr authored Jun 3, 2024
2 parents a745ff5 + b339185 commit 72bc7f0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 20 deletions.
5 changes: 2 additions & 3 deletions lib/crypto.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const crypto = require('crypto')
const base64url = require('base64url')

const iv_size_bytes = 12

Expand Down Expand Up @@ -45,7 +44,7 @@ async function encrypt(key, token, verbose = false) {
console.log('+---------------------------------------------------------------------------------------------------')
}

return base64url.encode(iv_ciphertext)
return Buffer.from(iv_ciphertext).toString('base64url')
}

/**
Expand All @@ -59,7 +58,7 @@ async function decrypt(key, token, verbose = false) {
const key_encoded = new TextEncoder().encode(key)
const key_digest = await crypto.subtle.digest('SHA-256', key_encoded)

const decoded_token = base64url.toBuffer(token)
const decoded_token = Buffer.from(token, 'base64url')

// First n bytes (iv_size_bytes) is the iv.
const iv = decoded_token.subarray(0, iv_size_bytes)
Expand Down
15 changes: 2 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@edgio/ectoken",
"version": "2.0.1",
"version": "2.0.2",
"description": "JS implementation of Edgio token (ectoken)",
"main": "index.js",
"repository": {
Expand All @@ -25,9 +25,6 @@
"node": ">= 15.0.0"
},
"homepage": "https://github.com/Edgio/js-ectoken#readme",
"dependencies": {
"base64url": "^3.0.1"
},
"publishConfig": {
"access": "public"
},
Expand Down

0 comments on commit 72bc7f0

Please sign in to comment.