Use the builtin subtle crypto library instead of node-forge (#2276)

This commit is contained in:
absidue 2022-05-31 03:42:39 +02:00 committed by GitHub
parent 7ae9160362
commit dd5c68223b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 18 deletions

View File

@ -71,7 +71,6 @@
"marked": "^4.0.15",
"material-design-icons": "^3.0.1",
"nedb-promises": "^5.0.1",
"node-forge": "^1.3.1",
"opml-to-json": "^1.0.1",
"rss-parser": "^3.12.0",
"socks-proxy-agent": "^6.0.0",

View File

@ -1,5 +1,4 @@
import $ from 'jquery'
import forge from 'node-forge'
const state = {}
const getters = {}
@ -7,9 +6,16 @@ const getters = {}
const actions = {
sponsorBlockSkipSegments ({ rootState }, { videoId, categories }) {
return new Promise((resolve, reject) => {
const messageDigestSha256 = forge.md.sha256.create()
messageDigestSha256.update(videoId)
const videoIdHashPrefix = messageDigestSha256.digest().toHex().substring(0, 4)
const videoIdBuffer = new TextEncoder().encode(videoId)
crypto.subtle.digest('SHA-256', videoIdBuffer).then((hashBuffer) => {
const hashArray = Array.from(new Uint8Array(hashBuffer))
const videoIdHashPrefix = hashArray
.map(byte => byte.toString(16).padStart(2, '0'))
.slice(0, 4)
.join('')
const requestUrl = `${rootState.settings.sponsorBlockUrl}/api/skipSegments/${videoIdHashPrefix}?categories=${JSON.stringify(categories)}`
$.getJSON(requestUrl, (response) => {
@ -25,6 +31,7 @@ const actions = {
reject(xhr)
})
})
})
}
}

View File

@ -6356,7 +6356,7 @@ node-fetch@^2.6.0:
dependencies:
whatwg-url "^5.0.0"
node-forge@^1, node-forge@^1.3.1:
node-forge@^1:
version "1.3.1"
resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3"
integrity sha512-dPEtOeMvF9VMcYV/1Wb8CPoVAXtp6MKMlcbAt4ddqmGqUJ6fQZFXkNZNkNlfevtNkGtaSoXf/vNNNSvgrdXwtA==