Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
253 changes: 138 additions & 115 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"send-intent": "7.x",
"stream-browserify": "^3.0.0",
"throttle-debounce": "^2.3.0",
"ts-xxhash": "^1.0.6",
"vue": "^2.7.0",
"vue-router": "^3.4.9",
"vuelidate": "^0.7.6",
Expand Down
5 changes: 5 additions & 0 deletions src/lib/Crypto.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { fromUint8Array, toUint8Array } from 'js-base64'
import { murmurhash3_32_gc } from './murmurhash3'
import { XXHash32 } from 'ts-xxhash'

export default class Crypto {
static iterations = 250000
static ivLength = 16

static async xxhash32(message: string): Promise<string> {
return XXHash32.hash(0, message).toString(16)
}

static async murmurHash3(message: string): Promise<string> {
const buf32 = new Uint32Array([murmurhash3_32_gc(message, 0)])
const buf8 = new Uint8Array(buf32.buffer)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/LocalTabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export default class LocalTabs implements OrderFolderResource<typeof ItemLocatio
async getCapabilities(): Promise<ICapabilities> {
return {
preserveOrder: true,
hashFn: ['murmur3', 'sha256']
hashFn: ['xxhash3', 'murmur3', 'sha256']
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/lib/Tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,14 @@ export class Bookmark<L extends TItemLocation> {
this.hashValue[cacheKey] = value
}

async hash({preserveOrder = false, hashFn = 'sha256'}):Promise<string> {
async hash({preserveOrder = false, hashFn = 'sha256'}: IHashSettings = {preserveOrder: false, hashFn: 'sha256'}):Promise<string> {
if (!this.hashValue) {
this.hashValue = {}
const json = JSON.stringify({ title: this.title, url: this.url })
if (hashFn === 'sha256') {
this.hashValue[hashFn] = await Crypto.sha256(json)
} else if (hashFn === 'xxhash3') {
this.hashValue[hashFn] = await Crypto.xxhash32(json)
} else if (hashFn === 'murmur3') {
this.hashValue[hashFn] = await Crypto.murmurHash3(json)
} else {
Expand Down Expand Up @@ -361,6 +363,8 @@ export class Folder<L extends TItemLocation> {
this.hashValue[cacheKey] = await Crypto.sha256(json)
} else if (hashFn === 'murmur3') {
this.hashValue[cacheKey] = await Crypto.murmurHash3(json)
} else if (hashFn === 'xxhash3') {
this.hashValue[cacheKey] = await Crypto.xxhash32(json)
} else {
throw new Error('Unsupported hash function specified')
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/adapters/Caching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export default class CachingAdapter implements Adapter, BulkImportResource<TItem
async getCapabilities(): Promise<ICapabilities> {
return {
preserveOrder: true,
hashFn: ['murmur3', 'sha256'],
hashFn: ['xxhash3', 'murmur3', 'sha256'],
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/adapters/Karakeep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ export default class KarakeepAdapter implements Adapter, IResource<typeof ItemLo
async getCapabilities(): Promise<ICapabilities> {
return {
preserveOrder: false,
hashFn: ['murmur3', 'sha256'],
hashFn: ['xxhash3', 'murmur3', 'sha256'],
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/adapters/Linkwarden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export default class LinkwardenAdapter implements Adapter, IResource<typeof Item
async getCapabilities(): Promise<ICapabilities> {
return {
preserveOrder: false,
hashFn: ['murmur3', 'sha256'],
hashFn: ['xxhash3', 'murmur3', 'sha256'],
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/browser/BrowserTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ export default class BrowserTree implements IResource<typeof ItemLocation.LOCAL>
async getCapabilities(): Promise<ICapabilities> {
return {
preserveOrder: true,
hashFn: ['murmur3', 'sha256']
hashFn: ['xxhash3', 'murmur3', 'sha256']
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/interfaces/Resource.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Bookmark, Folder, ItemLocation, TItem, TItemLocation } from '../Tree'
import Ordering from './Ordering'

export type THashFunction = 'sha256' | 'murmur3'
export type THashFunction = 'sha256' | 'murmur3' | 'xxhash3'

export interface ICapabilities {
preserveOrder: boolean,
Expand Down
Loading