Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dcantu476/ac8d4ae63a6a22c6a6fda7d8f9fb3039 to your computer and use it in GitHub Desktop.
Save dcantu476/ac8d4ae63a6a22c6a6fda7d8f9fb3039 to your computer and use it in GitHub Desktop.
Nodejs implementation of creating the chromium bookmark checksum. Fork of python version.
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