Skip to content

Commit

Permalink
Merge branch 'release/v4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Oct 24, 2022
2 parents c09e08f + 0bb22ca commit 3198c4e
Show file tree
Hide file tree
Showing 18 changed files with 372 additions and 353 deletions.
3 changes: 3 additions & 0 deletions .cspell/custom-dictionary-workspace.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Custom Dictionary Words
uid
uids
11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"cosmian",
"deserialization",
"Deserialization",
"findex",
"Findex",
"kmip",
"Kmip",
Expand All @@ -13,5 +14,13 @@
"webassembly"
],
"eslint.format.enable": true,
"jestrunner.jestCommand": "node --experimental-fetch --experimental-vm-modules node_modules/.bin/jest"
"jestrunner.jestCommand": "node --experimental-fetch --experimental-vm-modules node_modules/.bin/jest",
"cSpell.customDictionaries": {
"custom-dictionary-workspace": {
"name": "custom-dictionary-workspace",
"path": "${workspaceFolder:cloudproof_js}/.cspell/custom-dictionary-workspace.txt",
"addWords": true,
"scope": "workspace"
}
}
}
1 change: 1 addition & 0 deletions @types/leb128.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'leb128'
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@
All notable changes to this project will be documented in this file.


---

## [4.0.0] - 2022-10-24

### Added

### Changed

- update findex to 0.9.0: no custom conversions but with direct reflection in JS types

### Fixed


### Removed

---

## [3.2.2] - 2022-10-21
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloudproof_js",
"version": "3.2.2",
"version": "4.0.0",
"license": "MIT",
"description": "Cosmian Cloudproof javascript client library",
"main": "dist/src/index.js",
Expand All @@ -21,7 +21,7 @@
"dependencies": {
"@types/uuid": "^8.3.4",
"cosmian_cover_crypt": "^6.0.8",
"cosmian_findex": "^0.8.0",
"cosmian_findex": "^0.9.0",
"js-crypto-hmac": "^1.0.4",
"leb128": "0.0.5",
"process": "^0.11.10",
Expand Down
127 changes: 0 additions & 127 deletions src/crypto/sse/findex/interfaces/findex.ts

This file was deleted.

103 changes: 62 additions & 41 deletions src/crypto/sse/findex/simple.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import { webassembly_search, webassembly_upsert } from "cosmian_findex"
import { SymmetricKey } from "../../../kms/objects/SymmetricKey"
import {
deserializeHashMap,
deserializeList,
serializeHashMap,
} from "../../../utils/utils"
import { Index } from "./interfaces"

/* tslint:disable:max-classes-per-file */
Expand Down Expand Up @@ -67,14 +62,19 @@ export class Keyword {
}
}
export class FindexKey {
bytes: Uint8Array
_bytes: Uint8Array
constructor(bytes: Uint8Array) {
this.bytes = bytes
this._bytes = bytes
}

toBase64(): string {
return Buffer.from(this.bytes).toString("base64")
}

public get bytes(): Uint8Array {
return this._bytes
}

}

export class Label {
Expand Down Expand Up @@ -179,6 +179,13 @@ export type UpsertEntries = (uidsAndValues: UidsAndValues) => Promise<void>
*/
export type UpsertChains = (uidsAndValues: UidsAndValues) => Promise<void>

/**
* Called with results found at every node while the search walks the search graph.
* Returning false, stops the walk.
*/
export type Progress = (indexedValues: IndexedValue[]) => Promise<boolean>


/**
* Insert or update existing (a.k.a upsert) entries in the index
*
Expand Down Expand Up @@ -207,31 +214,31 @@ export async function upsert(
updateKey = new FindexKey(updateKey.bytes())
}

const newIndexedEntriesBase64: { [key: string]: string[] } = {}
const indexedValuesAndWords: Array<{ indexedValue: Uint8Array, keywords: Uint8Array[] }> = []
for (const newIndexedEntry of newIndexedEntries) {
newIndexedEntriesBase64[newIndexedEntry.indexedValue.toBase64()] = [
...newIndexedEntry.keywords,
].map((keyword) => keyword.toBase64())
const keywords: Uint8Array[] = []
newIndexedEntry.keywords.forEach(kw => {
keywords.push(kw.bytes)
})
indexedValuesAndWords.push({
indexedValue: newIndexedEntry.indexedValue.bytes,
keywords
})
}

await webassembly_upsert(
JSON.stringify({ k: searchKey.toBase64(), k_star: updateKey.toBase64() }),
return await webassembly_upsert(
searchKey.bytes,
updateKey.bytes,
label.bytes,
JSON.stringify(newIndexedEntriesBase64),
async (serializedUids: Uint8Array) => {
const uids = deserializeList(serializedUids)
const result = await fetchEntries(uids)
return serializeHashMap(result)
indexedValuesAndWords,
async (uids: Uint8Array[]) => {
return await fetchEntries(uids)
},
async (serializedUidsAndValues: Uint8Array) => {
const uidsAndValues = deserializeHashMap(serializedUidsAndValues)
await upsertEntries(uidsAndValues)
return uidsAndValues.length
async (uidsAndValues: UidsAndValues) => {
return await upsertEntries(uidsAndValues)
},
async (serializedUidsAndValues: Uint8Array) => {
const uidsAndValues = deserializeHashMap(serializedUidsAndValues)
await upsertChains(uidsAndValues)
return uidsAndValues.length
async (uidsAndValues: UidsAndValues) => {
return await upsertChains(uidsAndValues)
}
)
}
Expand All @@ -245,41 +252,55 @@ export async function upsert(
* @param {number} maxResultsPerKeyword the maximum number of results per keyword
* @param {FetchEntries} fetchEntries callback to fetch the entries table
* @param {FetchChains} fetchChains callback to fetch the chains table
* @param {Progress} progress the optional callback of found values as the search graph is walked.
* Returning false stops the walk
* @returns {Promise<IndexedValue[]>} a list of `IndexedValue`
*/
export async function search(
keywords: Set<string>,
keywords: Set<string | Uint8Array>,
searchKey: FindexKey | SymmetricKey,
label: Label,
maxResultsPerKeyword: number,
fetchEntries: FetchEntries,
fetchChains: FetchChains
fetchChains: FetchChains,
progress?: Progress
): Promise<IndexedValue[]> {
// convert key to a single representation
if (searchKey instanceof SymmetricKey) {
searchKey = new FindexKey(searchKey.bytes())
}

const kws: Uint8Array[] = []
for (const k of keywords) {
kws.push(k instanceof Uint8Array ? k : new TextEncoder().encode(k))
}

const progress_: Progress =
(typeof progress === "undefined") ?
async (indexedValues_: IndexedValue[]) => true
:
progress


const serializedIndexedValues = await webassembly_search(
searchKey.bytes,
label.bytes,
JSON.stringify([...keywords]),
kws,
maxResultsPerKeyword,
1000,
() => true,
async (serializedUids: Uint8Array) => {
const uids = deserializeList(serializedUids)
const result = await fetchEntries(uids)
return serializeHashMap(result)
async (serializedIndexedValues: Uint8Array[]) => {
const indexedValues = serializedIndexedValues.map(bytes => {
return new IndexedValue(bytes)
})
return await progress_(indexedValues)
},
async (serializedUids: Uint8Array) => {
const uids = deserializeList(serializedUids)
const result = await fetchChains(uids)
return serializeHashMap(result)
async (uids: Uint8Array[]) => {
return await fetchEntries(uids)
},
async (uids: Uint8Array[]) => {
return await fetchChains(uids)
}
)

return deserializeList(serializedIndexedValues).map(
(bytes) => new IndexedValue(bytes)
)
return serializedIndexedValues.map(bytes => new IndexedValue(bytes))
}
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export * from "./crypto/abe/interfaces/policy"
export * from "./crypto/sse/findex/simple"
export * from "./crypto/sse/findex/interfaces/dbInterface"
export * from "./crypto/sse/findex/interfaces/master_keys"
export * from "./crypto/sse/findex/interfaces/findex"
export * from "./crypto/sse/findex/interfaces/index"
export { logger } from "./utils/logger"
export {
Expand Down
Loading

0 comments on commit 3198c4e

Please sign in to comment.