Forked from dcantu476/calculate_chrome_bookmark_checksum.js
Created
February 28, 2023 00:07
-
-
Save s3rgeym/d093bae936530f2dbdfa2b83c0072adb to your computer and use it in GitHub Desktop.
Nodejs implementation of creating the chromium bookmark checksum. Fork of python version.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createHash } from 'crypto'; | |
// See https://gist.github.com/simon816/afde4d57d5dab8e80120e35596008834 | |
// See https://chromium.googlesource.com/chromium/src/+/master/components/bookmarks/browser/bookmark_codec.cc | |
const regenChecksum = (roots) => { | |
const digest = createHash('md5'); | |
const digestUrl = (url) => { | |
digest.update(url['id'],'ascii'); | |
digest.update(url['name'],'utf16le'); | |
digest.update(Buffer.from('url')); | |
digest.update(url['url'], 'ascii'); | |
} | |
const digestFolder = (folder) => { | |
digest.update(folder['id'],'ascii'); | |
digest.update(folder['name'],'utf16le'); | |
const bytes = Buffer.from('folder'); | |
digest.update(bytes); | |
folder['children']?.forEach((child) => { | |
updateDigest(child); | |
}) | |
} | |
const updateDigest = (node) => { | |
node.type === 'folder' ? digestFolder(node) : digestUrl(node) | |
} | |
updateDigest(roots['bookmark_bar']) | |
updateDigest(roots['other']) | |
updateDigest(roots['synced']) | |
return digest.digest('hex'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment