Skip to content

Commit

Permalink
chore: merge branch 'release/v7.0.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuthor committed Feb 17, 2023
2 parents 6bb4015 + 0c49a77 commit d3bb5e7
Show file tree
Hide file tree
Showing 10 changed files with 486 additions and 71 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

---

## [7.0.1] - 2023-02-17

### Testing

- Add source code of public_doc

---

## [7.0.0] - 2023-02-03

### Bug Fixes
Expand Down Expand Up @@ -31,6 +41,8 @@ All notable changes to this project will be documented in this file.

- `fetchChains` calls are now run in async parallel

---

## [6.0.0] - 2022-12-22

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ This table shows the minimum version correspondence between the various componen
| 5.0.0 | 7.0.0 | 0.10.0 | 3.0.0 |
| 6.0.0 | 8.0.0 | 1.0.0 | 4.0.0 |
| 6.0.1 | 8.0.0 | 2.0.0 | 4.0.0 |
| 7.0.0 | 10.0.0 | 2.0.1 | 4.2.0 |
| 7.0.0, 7.0.1 | 10.0.0 | 2.0.1 | 4.2.0 |
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cloudproof_js",
"version": "7.0.0",
"version": "7.0.1",
"license": "MIT",
"description": "Cosmian Cloudproof javascript client library",
"author": "Bruno Grieder<[email protected]>, Pauline Hochard<[email protected]>, Emmanuel Coste<[email protected]>, Thibaud Dauce<[email protected]>",
Expand Down Expand Up @@ -40,11 +40,13 @@
"format": "npm run prettier:fix && npm run lint:fix"
},
"dependencies": {
"base64-js": "^1.5.1",
"better-sqlite3": "^8.0.1",
"process": "^0.11.10",
"stream-browserify": "^3.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@rollup/plugin-wasm": "^6.0.1",
Expand Down
2 changes: 2 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import typescript from "@rollup/plugin-typescript"
import { wasm } from "@rollup/plugin-wasm"
import { nodeResolve } from "@rollup/plugin-node-resolve"
import commonjs from '@rollup/plugin-commonjs';

const production = !process.env.ROLLUP_WATCH

Expand All @@ -21,6 +22,7 @@ const rolls = (fmt, env) => ({
name: "jomini",
},
plugins: [
commonjs(),
nodeResolve(),
// We want to inline our wasm bundle as base64. Not needing browser users
// to fetch an additional asset is a boon as there's less room for errors
Expand Down
21 changes: 17 additions & 4 deletions src/findex/findex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { SymmetricKey } from "../kms/structs/objects"
import { parse as parseUuid, stringify as stringifyUuid } from "uuid"
import { encode, decode } from "../utils/leb128"
import { bytesEquals, hexEncode } from "../utils/utils"
import { fromByteArray } from "base64-js"

export * from "./sqlite"
export * from "./in_memory"
Expand Down Expand Up @@ -59,7 +60,7 @@ export class IndexedValue {
}

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

getLocation(): Location | null {
Expand Down Expand Up @@ -133,7 +134,7 @@ export class Keyword {
}

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

toString(): string {
Expand All @@ -147,7 +148,7 @@ export class FindexKey {
}

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

public get bytes(): Uint8Array {
Expand Down Expand Up @@ -507,7 +508,7 @@ export async function Findex() {
}
}

class SearchResults {
export class SearchResults {
locationsPerKeywords: Array<{
keyword: Uint8Array
locations: Location[]
Expand Down Expand Up @@ -544,6 +545,18 @@ class SearchResults {
return Array.from(this)
}

toNumbers(): number[] {
return this.locations().map((location) => location.toNumber())
}

toStrings(): string[] {
return this.locations().map((location) => location.toString())
}

toUuidStrings(): string[] {
return this.locations().map((location) => location.toUuidString())
}

total(): number {
return this.locations().length
}
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export {
hexDecode,
hexEncode,
sanitizeString,
toBase64,
deserializeList,
toBeBytes,
} from "./utils/utils"
Expand Down
15 changes: 1 addition & 14 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
import { decode } from "./leb128"

/**
* Convert the binary string to base64 string and sanitize it.
*
* @param {Uint8Array | string} val the binary string
* @returns {string} the base 64 value
*/
export function toBase64(val: Uint8Array | string): string {
if (val instanceof Uint8Array) {
return Buffer.from(val).toString("base64")
}
return Buffer.from(sanitizeString(val), "binary").toString("base64")
}

/**
* Hex encode an array of bytes
*
Expand Down Expand Up @@ -89,7 +76,7 @@ export function toBeBytes(myNumber: number): Uint8Array {
export function deserializeList(serializedItems: Uint8Array): Uint8Array[] {
const items: Uint8Array[] = []
while (serializedItems.length > 1) {
const { result: itemLen, tail } = decode(Buffer.from(serializedItems))
const { result: itemLen, tail } = decode(serializedItems)

const item = tail.slice(0, itemLen)
serializedItems = tail.slice(itemLen)
Expand Down
45 changes: 17 additions & 28 deletions tests/cover_crypt.non_regression_vector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import { expect } from "vitest"
import { CoverCrypt, Policy as CoverCryptPolicy } from ".."
import { fromByteArray, toByteArray } from "base64-js"

/* Importing the functions from the CoverCrypt library. */
const {
Expand Down Expand Up @@ -37,15 +38,15 @@ export class UserSecretKeyTestVector {

public toJson(): string {
const usk: any = {}
usk.key = Buffer.from(this.key).toString("base64")
usk.key = fromByteArray(this.key)
usk.access_policy = this.accessPolicy
return usk
}

public static fromJson(usk: string): UserSecretKeyTestVector {
const json = JSON.parse(JSON.stringify(usk))
const accessPolicy = json.access_policy
const key = Uint8Array.from(Buffer.from(json.key, "base64"))
const key = toByteArray(json.key)
return new UserSecretKeyTestVector(accessPolicy, key)
}
}
Expand Down Expand Up @@ -113,26 +114,20 @@ export class EncryptionTestVector {
public toJson(): string {
const etv: any = {}
etv.encryption_policy = this.encryptionPolicy
etv.plaintext = Buffer.from(this.plaintext).toString("base64")
etv.ciphertext = Buffer.from(this.ciphertext).toString("base64")
etv.header_metadata = Buffer.from(this.headerMetadata).toString("base64")
etv.authentication_data = Buffer.from(this.authenticationData).toString(
"base64",
)
etv.plaintext = fromByteArray(this.plaintext)
etv.ciphertext = fromByteArray(this.ciphertext)
etv.header_metadata = fromByteArray(this.headerMetadata)
etv.authentication_data = fromByteArray(this.authenticationData)
return etv
}

public static fromJson(etv: string): EncryptionTestVector {
const json = JSON.parse(JSON.stringify(etv))
const encryptionPolicy = json.encryption_policy
const plaintext = Uint8Array.from(Buffer.from(json.plaintext, "base64"))
const ciphertext = Uint8Array.from(Buffer.from(json.ciphertext, "base64"))
const headerMetadata = Uint8Array.from(
Buffer.from(json.header_metadata, "base64"),
)
const authenticationData = Uint8Array.from(
Buffer.from(json.authentication_data, "base64"),
)
const plaintext = toByteArray(json.plaintext)
const ciphertext = toByteArray(json.ciphertext)
const headerMetadata = toByteArray(json.header_metadata)
const authenticationData = toByteArray(json.authentication_data)

return new EncryptionTestVector(
encryptionPolicy,
Expand Down Expand Up @@ -301,11 +296,9 @@ export class NonRegressionVector {

public toJson(): string {
const nrv: any = {}
nrv.public_key = Buffer.from(this.publicKey).toString("base64")
nrv.master_secret_key = Buffer.from(this.masterSecretKey).toString("base64")
nrv.policy = Buffer.from(this.policy.toBytes()).toString("base64")

// user keys
nrv.public_key = fromByteArray(this.publicKey)
nrv.master_secret_key = fromByteArray(this.masterSecretKey)
nrv.policy = fromByteArray(this.policy.toBytes())
nrv.top_secret_mkg_fin_key = this.topSecretMkgFinKey.toJson()
nrv.medium_secret_mkg_key = this.mediumSecretMkgKey.toJson()
nrv.top_secret_fin_key = this.topSecretFinKey.toJson()
Expand All @@ -320,13 +313,9 @@ export class NonRegressionVector {

public static fromJson(nonRegVector: string): NonRegressionVector {
const json = JSON.parse(nonRegVector)
const policy = Policy.fromBytes(
Uint8Array.from(Buffer.from(json.policy, "base64")),
)
const publicKey = Uint8Array.from(Buffer.from(json.public_key, "base64"))
const masterSecretKey = Uint8Array.from(
Buffer.from(json.master_secret_key, "base64"),
)
const policy = Policy.fromBytes(toByteArray(json.policy))
const publicKey = toByteArray(json.public_key)
const masterSecretKey = toByteArray(json.master_secret_key)

const topSecretMkgFinKey = UserSecretKeyTestVector.fromJson(
json.top_secret_mkg_fin_key,
Expand Down
Loading

0 comments on commit d3bb5e7

Please sign in to comment.