mirror of
https://github.com/standardnotes/app
synced 2026-09-13 18:46:08 -04:00
Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
86fc4c684d | ||
|
|
ef2d1b9228 | ||
|
|
868a84f587 | ||
|
|
7c463b36af | ||
|
|
908cbaf895 | ||
|
|
51cb14c010 | ||
|
|
47a36c4cbd | ||
|
|
7222ca7fd0 | ||
|
|
6ad5d028af | ||
|
|
596e041c42 | ||
|
|
80436cd0b9 | ||
|
|
40c0a08e74 | ||
|
|
560e91bce9 | ||
|
|
2a3db43df5 | ||
|
|
2e59aa5a07 | ||
|
|
98c0228139 | ||
|
|
d6bcc808d5 | ||
|
|
e18978d4ba |
@@ -3,6 +3,10 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.26.31](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/api
|
||||
|
||||
## [1.26.30](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-23)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/api
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/api",
|
||||
"version": "1.26.30",
|
||||
"version": "1.26.31",
|
||||
"engines": {
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,26 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.1.115](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/clipper
|
||||
|
||||
## [1.1.114](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/clipper
|
||||
|
||||
## [1.1.113](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/clipper
|
||||
|
||||
## [1.1.112](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/clipper
|
||||
|
||||
## [1.1.111](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/clipper
|
||||
|
||||
## [1.1.110](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/clipper
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@standardnotes/clipper",
|
||||
"description": "Web clipper browser extension for Standard Notes",
|
||||
"version": "1.1.110",
|
||||
"version": "1.1.115",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build-mv2": "yarn clean && webpack --config ./webpack.config.prod.js",
|
||||
|
||||
@@ -3,6 +3,28 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [3.108.46](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
### Reverts
|
||||
|
||||
* Revert "chore: upgrade desktop deps" ([ef2d1b9](https://github.com/standardnotes/app/commit/ef2d1b9228c90a9cb9cf88535526a312bb28fca4))
|
||||
|
||||
## [3.108.45](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/desktop
|
||||
|
||||
## [3.108.44](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/desktop
|
||||
|
||||
## [3.108.43](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/desktop
|
||||
|
||||
## [3.108.42](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/desktop
|
||||
|
||||
## [3.108.41](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/desktop
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@standardnotes/desktop",
|
||||
"main": "./app/dist/index.js",
|
||||
"version": "3.108.41",
|
||||
"version": "3.108.46",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"author": "Standard Notes.",
|
||||
"private": true,
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.21.54](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/encryption
|
||||
|
||||
## [1.21.53](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-23)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/encryption
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/encryption",
|
||||
"version": "1.21.53",
|
||||
"version": "1.21.54",
|
||||
"engines": {
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import { V004Algorithm } from '../../../../Algorithm'
|
||||
import {
|
||||
KeySystemRootKeyInterface,
|
||||
KeySystemRootKeyParamsInterface,
|
||||
KeySystemRootKeyPasswordType,
|
||||
KeySystemPasswordType,
|
||||
} from '@standardnotes/models'
|
||||
import { ProtocolVersion } from '@standardnotes/common'
|
||||
import { DeriveKeySystemRootKeyUseCase } from './DeriveKeySystemRootKey'
|
||||
@@ -20,7 +20,7 @@ export class CreateRandomKeySystemRootKey {
|
||||
|
||||
const keyParams: KeySystemRootKeyParamsInterface = {
|
||||
systemIdentifier: dto.systemIdentifier,
|
||||
passwordType: KeySystemRootKeyPasswordType.Randomized,
|
||||
passwordType: KeySystemPasswordType.Randomized,
|
||||
creationTimestamp: new Date().getTime(),
|
||||
seed,
|
||||
version,
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ import {
|
||||
KeySystemIdentifier,
|
||||
KeySystemRootKeyInterface,
|
||||
KeySystemRootKeyParamsInterface,
|
||||
KeySystemRootKeyPasswordType,
|
||||
KeySystemPasswordType,
|
||||
} from '@standardnotes/models'
|
||||
import { ProtocolVersion } from '@standardnotes/common'
|
||||
import { DeriveKeySystemRootKeyUseCase } from './DeriveKeySystemRootKey'
|
||||
@@ -19,7 +19,7 @@ export class CreateUserInputKeySystemRootKey {
|
||||
|
||||
const keyParams: KeySystemRootKeyParamsInterface = {
|
||||
systemIdentifier: dto.systemIdentifier,
|
||||
passwordType: KeySystemRootKeyPasswordType.UserInputted,
|
||||
passwordType: KeySystemPasswordType.UserInputted,
|
||||
creationTimestamp: new Date().getTime(),
|
||||
seed,
|
||||
version,
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.28.63](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/filepicker
|
||||
|
||||
## [1.28.62](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-23)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/filepicker
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/filepicker",
|
||||
"version": "1.28.62",
|
||||
"version": "1.28.63",
|
||||
"engines": {
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.16.9](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files
|
||||
|
||||
## [1.16.8](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-23)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/files
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/files",
|
||||
"version": "1.16.8",
|
||||
"version": "1.16.9",
|
||||
"engines": {
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
|
||||
@@ -3,6 +3,30 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [3.56.26](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/mobile
|
||||
|
||||
## [3.56.25](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/mobile
|
||||
|
||||
## [3.56.24](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/mobile
|
||||
|
||||
## [3.56.23](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/mobile
|
||||
|
||||
## [3.56.22](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/mobile
|
||||
|
||||
## [3.56.21](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/mobile
|
||||
|
||||
## [3.56.20](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/mobile
|
||||
|
||||
@@ -118,7 +118,24 @@ class ReceiveSharingIntent: NSObject {
|
||||
|
||||
@objc
|
||||
func clearFileNames(){
|
||||
print("clearFileNames");
|
||||
let appDomain = Bundle.main.bundleIdentifier!
|
||||
let groupName = "group.\(appDomain)"
|
||||
let userDefaults = UserDefaults(suiteName: groupName)
|
||||
userDefaults?.set(nil, forKey: "ShareKey.media")
|
||||
userDefaults?.set(nil, forKey: "ShareKey.text")
|
||||
userDefaults?.set(nil, forKey: "ShareKey.url")
|
||||
let containerURL = FileManager.default
|
||||
.containerURL(forSecurityApplicationGroupIdentifier: groupName)!
|
||||
let shareTempDirPath = containerURL.appendingPathComponent("ShareTemp", isDirectory: true)
|
||||
do {
|
||||
let fileNames = try FileManager.default.contentsOfDirectory(atPath: shareTempDirPath.relativePath)
|
||||
for fileName in fileNames {
|
||||
let filePath = shareTempDirPath.appendingPathComponent(fileName)
|
||||
try FileManager.default.removeItem(at: filePath)
|
||||
}
|
||||
} catch {
|
||||
print(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -95,16 +95,11 @@ class ShareViewController: SLComposeServiceViewController {
|
||||
attachment.loadItem(forTypeIdentifier: imageContentType, options: nil) { [weak self] data, error in
|
||||
|
||||
if error == nil, let url = data as? URL, let this = self {
|
||||
// this.redirectToHostApp(type: .media)
|
||||
// Always copy
|
||||
let fileExtension = this.getExtension(from: url, type: .video)
|
||||
let newName = UUID().uuidString
|
||||
let newPath = FileManager.default
|
||||
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(hostAppBundleIdentifier)")!
|
||||
.appendingPathComponent("\(newName).\(fileExtension)")
|
||||
let copied = this.copyFile(at: url, to: newPath)
|
||||
if(copied) {
|
||||
this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .image))
|
||||
if let copiedPath = this.copyToTemporaryPath(url: url, name: "\(newName).\(fileExtension)") {
|
||||
this.sharedMedia.append(SharedMediaFile(path: copiedPath, thumbnail: nil, duration: nil, type: .image))
|
||||
}
|
||||
|
||||
if index == (content.attachments?.count)! - 1 {
|
||||
@@ -125,15 +120,8 @@ class ShareViewController: SLComposeServiceViewController {
|
||||
// Always copy
|
||||
let fileExtension = this.getExtension(from: url, type: .video)
|
||||
let newName = UUID().uuidString
|
||||
let newPath = FileManager.default
|
||||
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(hostAppBundleIdentifier)")!
|
||||
.appendingPathComponent("\(newName).\(fileExtension)")
|
||||
let copied = this.copyFile(at: url, to: newPath)
|
||||
if(copied) {
|
||||
guard let sharedFile = this.getSharedMediaFile(forVideo: newPath) else {
|
||||
return
|
||||
}
|
||||
this.sharedMedia.append(sharedFile)
|
||||
if let copiedPath = this.copyToTemporaryPath(url: url, name: "\(newName).\(fileExtension)") {
|
||||
this.sharedMedia.append(SharedMediaFile(path: copiedPath, thumbnail: nil, duration: nil, type: .video))
|
||||
}
|
||||
|
||||
if index == (content.attachments?.count)! - 1 {
|
||||
@@ -151,14 +139,9 @@ class ShareViewController: SLComposeServiceViewController {
|
||||
|
||||
if error == nil, let url = data as? URL, let this = self {
|
||||
|
||||
// Always copy
|
||||
let newName = this.getFileName(from :url)
|
||||
let newPath = FileManager.default
|
||||
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(hostAppBundleIdentifier)")!
|
||||
.appendingPathComponent("\(newName)")
|
||||
let copied = this.copyFile(at: url, to: newPath)
|
||||
if (copied) {
|
||||
this.sharedMedia.append(SharedMediaFile(path: newPath.absoluteString, thumbnail: nil, duration: nil, type: .file))
|
||||
if let copiedPath = this.copyToTemporaryPath(url: url, name: newName) {
|
||||
this.sharedMedia.append(SharedMediaFile(path: copiedPath, thumbnail: nil, duration: nil, type: .file))
|
||||
}
|
||||
|
||||
if index == (content.attachments?.count)! - 1 {
|
||||
@@ -171,6 +154,32 @@ class ShareViewController: SLComposeServiceViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private func directoryExistsAtPath(_ path: String) -> Bool {
|
||||
var isDirectory = ObjCBool(true)
|
||||
let exists = FileManager.default.fileExists(atPath: path, isDirectory: &isDirectory)
|
||||
return exists && isDirectory.boolValue
|
||||
}
|
||||
|
||||
private func copyToTemporaryPath(url: URL, name: String) -> String? {
|
||||
let containerURL = FileManager.default
|
||||
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(hostAppBundleIdentifier)")!
|
||||
let shareTempDirPath = containerURL.appendingPathComponent("ShareTemp", isDirectory: true)
|
||||
if !directoryExistsAtPath(shareTempDirPath.absoluteString) {
|
||||
do {
|
||||
try FileManager.default.createDirectory(atPath: shareTempDirPath.relativePath, withIntermediateDirectories: true, attributes: nil)
|
||||
} catch {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
let newPath = shareTempDirPath
|
||||
.appendingPathComponent("\(name)")
|
||||
let copied = self.copyFile(at: url, to: newPath)
|
||||
if (copied) {
|
||||
return newPath.absoluteString
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
private func redirectToHostApp() {
|
||||
let userDefaults = UserDefaults(suiteName: "group.\(hostAppBundleIdentifier)")
|
||||
userDefaults?.set(self.toData(data: self.sharedMedia), forKey: "\(self.sharedKey).media")
|
||||
@@ -263,40 +272,6 @@ class ShareViewController: SLComposeServiceViewController {
|
||||
return true
|
||||
}
|
||||
|
||||
private func getSharedMediaFile(forVideo: URL) -> SharedMediaFile? {
|
||||
let asset = AVAsset(url: forVideo)
|
||||
let duration = (CMTimeGetSeconds(asset.duration) * 1000).rounded()
|
||||
let thumbnailPath = getThumbnailPath(for: forVideo)
|
||||
|
||||
if FileManager.default.fileExists(atPath: thumbnailPath.path) {
|
||||
return SharedMediaFile(path: forVideo.absoluteString, thumbnail: thumbnailPath.absoluteString, duration: duration, type: .video)
|
||||
}
|
||||
|
||||
var saved = false
|
||||
let assetImgGenerate = AVAssetImageGenerator(asset: asset)
|
||||
assetImgGenerate.appliesPreferredTrackTransform = true
|
||||
// let scale = UIScreen.main.scale
|
||||
assetImgGenerate.maximumSize = CGSize(width: 360, height: 360)
|
||||
do {
|
||||
let img = try assetImgGenerate.copyCGImage(at: CMTimeMakeWithSeconds(600, preferredTimescale: Int32(1.0)), actualTime: nil)
|
||||
try UIImage.pngData(UIImage(cgImage: img))()?.write(to: thumbnailPath)
|
||||
saved = true
|
||||
} catch {
|
||||
saved = false
|
||||
}
|
||||
|
||||
return saved ? SharedMediaFile(path: forVideo.absoluteString, thumbnail: thumbnailPath.absoluteString, duration: duration, type: .video) : nil
|
||||
|
||||
}
|
||||
|
||||
private func getThumbnailPath(for url: URL) -> URL {
|
||||
let fileName = Data(url.lastPathComponent.utf8).base64EncodedString().replacingOccurrences(of: "==", with: "")
|
||||
let path = FileManager.default
|
||||
.containerURL(forSecurityApplicationGroupIdentifier: "group.\(hostAppBundleIdentifier)")!
|
||||
.appendingPathComponent("\(fileName).jpg")
|
||||
return path
|
||||
}
|
||||
|
||||
class SharedMediaFile: Codable {
|
||||
var path: String; // can be image, video or url path. It can also be text content
|
||||
var thumbnail: String?; // video thumbnail
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/mobile",
|
||||
"version": "3.56.20",
|
||||
"version": "3.56.26",
|
||||
"author": "Standard Notes.",
|
||||
"private": true,
|
||||
"license": "AGPL-3.0-or-later",
|
||||
|
||||
@@ -71,6 +71,7 @@ export class ReceivedSharedItemsHandler {
|
||||
}
|
||||
|
||||
deinit() {
|
||||
ReceiveSharingIntent.clearFileNames()
|
||||
this.receivedItemsQueue = []
|
||||
this.eventSub?.remove()
|
||||
}
|
||||
@@ -100,17 +101,13 @@ export class ReceivedSharedItemsHandler {
|
||||
}
|
||||
|
||||
handleItemsQueue = async () => {
|
||||
if (!this.receivedItemsQueue.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const item = this.receivedItemsQueue.shift()
|
||||
if (!item) {
|
||||
return
|
||||
}
|
||||
|
||||
if (isReceivedAndroidFile(item) || isReceivedIosFile(item)) {
|
||||
this.sendFileToWebView(item).catch(console.error)
|
||||
await this.sendFileToWebView(item).catch(console.error)
|
||||
} else if (isReceivedWeblink(item)) {
|
||||
this.webViewRef.current?.postMessage(
|
||||
JSON.stringify({
|
||||
@@ -134,12 +131,20 @@ export class ReceivedSharedItemsHandler {
|
||||
)
|
||||
}
|
||||
|
||||
if (!this.receivedItemsQueue.length) {
|
||||
if (Platform.OS === 'ios') {
|
||||
ReceiveSharingIntent.clearFileNames()
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
this.handleItemsQueue().catch(console.error)
|
||||
}
|
||||
|
||||
sendFileToWebView = async (item: ReceivedAndroidFile | ReceivedIosFile) => {
|
||||
const path = isReceivedAndroidFile(item) ? item.contentUri : item.path
|
||||
const data = await readFile(path, 'base64')
|
||||
const data = await readFile(decodeURIComponent(path), 'base64')
|
||||
const file = {
|
||||
name: item.fileName || item.path,
|
||||
data,
|
||||
@@ -157,7 +162,12 @@ export class ReceivedSharedItemsHandler {
|
||||
private addSharedItemsToQueue = async (url?: string) => {
|
||||
const received =
|
||||
Platform.OS === 'ios' ? await ReceiveSharingIntent.getFileNames(url) : await ReceiveSharingIntent.getFileNames()
|
||||
ReceiveSharingIntent.clearFileNames()
|
||||
|
||||
// On iOS, we need to wait for the whole queue
|
||||
// to finish before clearing
|
||||
if (Platform.OS === 'android') {
|
||||
ReceiveSharingIntent.clearFileNames()
|
||||
}
|
||||
|
||||
if (!received) {
|
||||
return
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.46.13](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/models
|
||||
|
||||
## [1.46.12](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-23)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/models
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/models",
|
||||
"version": "1.46.12",
|
||||
"version": "1.46.13",
|
||||
"engines": {
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
export enum KeySystemRootKeyPasswordType {
|
||||
export enum KeySystemPasswordType {
|
||||
UserInputted = 'user_inputted',
|
||||
Randomized = 'randomized',
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ProtocolVersion } from '@standardnotes/common'
|
||||
import { KeySystemIdentifier } from '../../Syncable/KeySystemRootKey/KeySystemIdentifier'
|
||||
import { KeySystemRootKeyPasswordType } from './KeySystemRootKeyPasswordType'
|
||||
import { KeySystemPasswordType } from './KeySystemPasswordType'
|
||||
|
||||
/**
|
||||
* Key params are public data that contain information about how a root key was created.
|
||||
@@ -11,6 +11,6 @@ export interface KeySystemRootKeyParamsInterface {
|
||||
systemIdentifier: KeySystemIdentifier
|
||||
seed: string
|
||||
version: ProtocolVersion
|
||||
passwordType: KeySystemRootKeyPasswordType
|
||||
passwordType: KeySystemPasswordType
|
||||
creationTimestamp: number
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
import {
|
||||
Collection,
|
||||
DecryptedCollectionElement,
|
||||
DeletedCollectionElement,
|
||||
EncryptedCollectionElement,
|
||||
} from './Collection'
|
||||
import { FullyFormedPayloadInterface } from '../../Abstract/Payload'
|
||||
|
||||
class TestCollection<P extends FullyFormedPayloadInterface = FullyFormedPayloadInterface> extends Collection<
|
||||
P,
|
||||
DecryptedCollectionElement,
|
||||
EncryptedCollectionElement,
|
||||
DeletedCollectionElement
|
||||
> {}
|
||||
|
||||
describe('Collection', () => {
|
||||
let collection: TestCollection
|
||||
|
||||
beforeEach(() => {
|
||||
collection = new TestCollection()
|
||||
})
|
||||
|
||||
it('should initialize correctly', () => {
|
||||
expect(collection.map).toEqual({})
|
||||
expect(collection.typedMap).toEqual({})
|
||||
expect(collection.referenceMap).toBeDefined()
|
||||
expect(collection.conflictMap).toBeDefined()
|
||||
})
|
||||
|
||||
it('should set and get element correctly', () => {
|
||||
const testElement = {
|
||||
uuid: 'test-uuid',
|
||||
content_type: 'test-type',
|
||||
content: {},
|
||||
references: [],
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
collection.set(testElement)
|
||||
const element = collection.find('test-uuid')
|
||||
|
||||
expect(element).toBe(testElement)
|
||||
})
|
||||
|
||||
it('should check existence of an element correctly', () => {
|
||||
const testElement = {
|
||||
uuid: 'test-uuid',
|
||||
content_type: 'test-type',
|
||||
content: {},
|
||||
references: [],
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
collection.set(testElement)
|
||||
const hasElement = collection.has('test-uuid')
|
||||
|
||||
expect(hasElement).toBe(true)
|
||||
})
|
||||
|
||||
it('should return all elements', () => {
|
||||
const testElement1 = {
|
||||
uuid: 'test-uuid-1',
|
||||
content_type: 'test-type',
|
||||
content: {},
|
||||
references: [],
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
const testElement2 = {
|
||||
uuid: 'test-uuid-2',
|
||||
content_type: 'test-type',
|
||||
content: {},
|
||||
references: [],
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
collection.set(testElement1)
|
||||
collection.set(testElement2)
|
||||
|
||||
const allElements = collection.all()
|
||||
|
||||
expect(allElements).toEqual([testElement1, testElement2])
|
||||
})
|
||||
|
||||
it('should add uuid to invalidsIndex if element is error decrypting', () => {
|
||||
const testElement = {
|
||||
uuid: 'test-uuid',
|
||||
content_type: 'test-type',
|
||||
content: 'encrypted content',
|
||||
errorDecrypting: true,
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
collection.set(testElement)
|
||||
|
||||
expect(collection.invalidsIndex.has(testElement.uuid)).toBe(true)
|
||||
})
|
||||
|
||||
it('should add uuid to invalidsIndex if element is encrypted', () => {
|
||||
const testElement = {
|
||||
uuid: 'test-uuid',
|
||||
content_type: 'test-type',
|
||||
content: 'encrypted content',
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
collection.set(testElement)
|
||||
|
||||
expect(collection.invalidsIndex.has(testElement.uuid)).toBe(true)
|
||||
})
|
||||
|
||||
it('should remove uuid from invalidsIndex if element is not encrypted', () => {
|
||||
const testElement1 = {
|
||||
uuid: 'test-uuid-1',
|
||||
content_type: 'test-type',
|
||||
content: 'encrypted content',
|
||||
errorDecrypting: true,
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
const testElement2 = {
|
||||
uuid: 'test-uuid-1',
|
||||
content_type: 'test-type',
|
||||
content: {},
|
||||
references: [],
|
||||
} as unknown as FullyFormedPayloadInterface
|
||||
|
||||
collection.set(testElement1)
|
||||
expect(collection.invalidsIndex.has(testElement1.uuid)).toBe(true)
|
||||
|
||||
collection.set(testElement2)
|
||||
expect(collection.invalidsIndex.has(testElement2.uuid)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -59,7 +59,7 @@ export abstract class Collection<
|
||||
}
|
||||
|
||||
isErrorDecryptingElement = (e: Decrypted | Encrypted | Deleted): e is Encrypted => {
|
||||
return this.isEncryptedElement(e) && e.errorDecrypting === true
|
||||
return this.isEncryptedElement(e)
|
||||
}
|
||||
|
||||
isDeletedElement = (e: Decrypted | Encrypted | Deleted): e is Deleted => {
|
||||
@@ -78,10 +78,10 @@ export abstract class Collection<
|
||||
conflictMapCopy?: UuidMap,
|
||||
) {
|
||||
if (copy) {
|
||||
this.map = mapCopy!
|
||||
this.typedMap = typedMapCopy!
|
||||
this.referenceMap = referenceMapCopy!
|
||||
this.conflictMap = conflictMapCopy!
|
||||
this.map = mapCopy as Record<string, Element>
|
||||
this.typedMap = typedMapCopy as Record<string, Element[]>
|
||||
this.referenceMap = referenceMapCopy as UuidMap
|
||||
this.conflictMap = conflictMapCopy as UuidMap
|
||||
} else {
|
||||
this.referenceMap = new UuidMap()
|
||||
this.conflictMap = new UuidMap()
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ConflictStrategy, DecryptedItem } from '../../Abstract/Item'
|
||||
import { DecryptedPayloadInterface } from '../../Abstract/Payload'
|
||||
import { HistoryEntryInterface } from '../../Runtime/History'
|
||||
import { KeySystemRootKeyParamsInterface } from '../../Local/KeyParams/KeySystemRootKeyParamsInterface'
|
||||
import { KeySystemRootKeyPasswordType } from '../../Local/KeyParams/KeySystemRootKeyPasswordType'
|
||||
import { KeySystemPasswordType } from '../../Local/KeyParams/KeySystemPasswordType'
|
||||
import { SharedVaultListingInterface, VaultListingInterface } from './VaultListingInterface'
|
||||
import { VaultListingContent } from './VaultListingContent'
|
||||
import { KeySystemRootKeyStorageMode } from '../KeySystemRootKey/KeySystemRootKeyStorageMode'
|
||||
@@ -44,7 +44,7 @@ export class VaultListing extends DecryptedItem<VaultListingContent> implements
|
||||
return incomingKeyTimestamp > baseKeyTimestamp ? ConflictStrategy.KeepApply : ConflictStrategy.KeepBase
|
||||
}
|
||||
|
||||
get keyPasswordType(): KeySystemRootKeyPasswordType {
|
||||
get keyPasswordType(): KeySystemPasswordType {
|
||||
return this.rootKeyParams.passwordType
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { KeySystemIdentifier } from '../KeySystemRootKey/KeySystemIdentifier'
|
||||
import { KeySystemRootKeyParamsInterface } from '../../Local/KeyParams/KeySystemRootKeyParamsInterface'
|
||||
import { KeySystemRootKeyPasswordType } from '../../Local/KeyParams/KeySystemRootKeyPasswordType'
|
||||
import { KeySystemPasswordType } from '../../Local/KeyParams/KeySystemPasswordType'
|
||||
import { KeySystemRootKeyStorageMode } from '../KeySystemRootKey/KeySystemRootKeyStorageMode'
|
||||
import { VaultListingSharingInfo } from './VaultListingSharingInfo'
|
||||
import { VaultListingContent } from './VaultListingContent'
|
||||
@@ -17,7 +17,7 @@ export interface VaultListingInterface extends DecryptedItemInterface<VaultListi
|
||||
|
||||
sharing?: VaultListingSharingInfo
|
||||
|
||||
get keyPasswordType(): KeySystemRootKeyPasswordType
|
||||
get keyPasswordType(): KeySystemPasswordType
|
||||
isSharedVaultListing(): this is SharedVaultListingInterface
|
||||
|
||||
get key_system_identifier(): undefined
|
||||
|
||||
@@ -37,7 +37,7 @@ export * from './Device/Platform'
|
||||
|
||||
export * from './Local/KeyParams/RootKeyParamsInterface'
|
||||
export * from './Local/KeyParams/KeySystemRootKeyParamsInterface'
|
||||
export * from './Local/KeyParams/KeySystemRootKeyPasswordType'
|
||||
export * from './Local/KeyParams/KeySystemPasswordType'
|
||||
export * from './Local/RootKey/KeychainTypes'
|
||||
export * from './Local/RootKey/RootKeyContent'
|
||||
export * from './Local/RootKey/RootKeyInterface'
|
||||
|
||||
@@ -3,6 +3,30 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.4.398](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/releases
|
||||
|
||||
## [1.4.397](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/releases
|
||||
|
||||
## [1.4.396](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/releases
|
||||
|
||||
## [1.4.395](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/releases
|
||||
|
||||
## [1.4.394](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/releases
|
||||
|
||||
## [1.4.393](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/releases
|
||||
|
||||
## [1.4.392](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/releases
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/releases",
|
||||
"version": "1.4.392",
|
||||
"version": "1.4.398",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"main": "dist/releases.json",
|
||||
"types": "dist/index.d.ts",
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [1.63.11](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/services
|
||||
|
||||
## [1.63.10](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/services
|
||||
|
||||
## [1.63.9](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/services
|
||||
|
||||
## [1.63.8](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/services
|
||||
|
||||
## [1.63.7](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/services
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@standardnotes/services",
|
||||
"version": "1.63.7",
|
||||
"version": "1.63.11",
|
||||
"engines": {
|
||||
"node": ">=16.0.0 <17.0.0"
|
||||
},
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { VaultUserServiceInterface, VaultInviteServiceInterface } from '@standardnotes/services'
|
||||
import { VaultLockServiceInterface } from './../VaultLock/VaultLockServiceInterface'
|
||||
import { HistoryServiceInterface } from './../History/HistoryServiceInterface'
|
||||
import { InternalEventBusInterface } from './../Internal/InternalEventBusInterface'
|
||||
import { PreferenceServiceInterface } from './../Preferences/PreferenceServiceInterface'
|
||||
@@ -5,7 +7,7 @@ import { AsymmetricMessageServiceInterface } from './../AsymmetricMessage/Asymme
|
||||
import { SyncOptions } from './../Sync/SyncOptions'
|
||||
import { ImportDataReturnType } from './../Mutator/ImportDataUseCase'
|
||||
import { ChallengeServiceInterface } from './../Challenge/ChallengeServiceInterface'
|
||||
import { VaultServiceInterface } from './../Vaults/VaultServiceInterface'
|
||||
import { VaultServiceInterface } from '../Vault/VaultServiceInterface'
|
||||
import { ApplicationIdentifier } from '@standardnotes/common'
|
||||
import {
|
||||
BackupFile,
|
||||
@@ -95,24 +97,27 @@ export interface ApplicationInterface {
|
||||
syncOptions?: SyncOptions,
|
||||
): Promise<void>
|
||||
|
||||
get features(): FeaturesClientInterface
|
||||
get componentManager(): ComponentManagerInterface
|
||||
get items(): ItemManagerInterface
|
||||
get mutator(): MutatorClientInterface
|
||||
get user(): UserClientInterface
|
||||
get files(): FilesClientInterface
|
||||
get subscriptions(): SubscriptionManagerInterface
|
||||
get fileBackups(): BackupServiceInterface | undefined
|
||||
get sessions(): SessionsClientInterface
|
||||
get homeServer(): HomeServerServiceInterface | undefined
|
||||
get vaults(): VaultServiceInterface
|
||||
get challenges(): ChallengeServiceInterface
|
||||
get alerts(): AlertService
|
||||
get asymmetric(): AsymmetricMessageServiceInterface
|
||||
get preferences(): PreferenceServiceInterface
|
||||
get events(): InternalEventBusInterface
|
||||
get history(): HistoryServiceInterface
|
||||
get challenges(): ChallengeServiceInterface
|
||||
get componentManager(): ComponentManagerInterface
|
||||
get encryption(): EncryptionProviderInterface
|
||||
get events(): InternalEventBusInterface
|
||||
get features(): FeaturesClientInterface
|
||||
get fileBackups(): BackupServiceInterface | undefined
|
||||
get files(): FilesClientInterface
|
||||
get history(): HistoryServiceInterface
|
||||
get homeServer(): HomeServerServiceInterface | undefined
|
||||
get items(): ItemManagerInterface
|
||||
get mutator(): MutatorClientInterface
|
||||
get preferences(): PreferenceServiceInterface
|
||||
get sessions(): SessionsClientInterface
|
||||
get subscriptions(): SubscriptionManagerInterface
|
||||
get user(): UserClientInterface
|
||||
get vaults(): VaultServiceInterface
|
||||
get vaultLocks(): VaultLockServiceInterface
|
||||
get vaultUsers(): VaultUserServiceInterface
|
||||
get vaultInvites(): VaultInviteServiceInterface
|
||||
|
||||
readonly identifier: ApplicationIdentifier
|
||||
readonly platform: Platform
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { GetVault } from './../Vault/UseCase/GetVault'
|
||||
import { SessionsClientInterface } from './../Session/SessionsClientInterface'
|
||||
import { EncryptionProviderInterface } from './../Encryption/EncryptionProviderInterface'
|
||||
import { GetUntrustedPayload } from './UseCase/GetUntrustedPayload'
|
||||
import { GetInboundMessages } from './UseCase/GetInboundMessages'
|
||||
import { GetOutboundMessages } from './UseCase/GetOutboundMessages'
|
||||
import { SendOwnContactChangeMessage } from './UseCase/SendOwnContactChangeMessage'
|
||||
import { HandleRootKeyChangedMessage } from './UseCase/HandleRootKeyChangedMessage'
|
||||
import { GetVault } from './../Vaults/UseCase/GetVault'
|
||||
import { GetTrustedPayload } from './UseCase/GetTrustedPayload'
|
||||
import { ReplaceContactData } from './../Contacts/UseCase/ReplaceContactData'
|
||||
import { GetAllContacts } from './../Contacts/UseCase/GetAllContacts'
|
||||
import { FindContact } from './../Contacts/UseCase/FindContact'
|
||||
import { CreateOrEditContact } from './../Contacts/UseCase/CreateOrEditContact'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
@@ -31,6 +30,7 @@ describe('AsymmetricMessageService', () => {
|
||||
let sync: jest.Mocked<SyncServiceInterface>
|
||||
let mutator: jest.Mocked<MutatorClientInterface>
|
||||
let encryption: jest.Mocked<EncryptionProviderInterface>
|
||||
let sessions: jest.Mocked<SessionsClientInterface>
|
||||
let service: AsymmetricMessageService
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -40,12 +40,10 @@ describe('AsymmetricMessageService', () => {
|
||||
encryption = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
const createOrEditContact = {} as jest.Mocked<CreateOrEditContact>
|
||||
const findContact = {} as jest.Mocked<FindContact>
|
||||
const getAllContacts = {} as jest.Mocked<GetAllContacts>
|
||||
const replaceContactData = {} as jest.Mocked<ReplaceContactData>
|
||||
const getTrustedPayload = {} as jest.Mocked<GetTrustedPayload>
|
||||
const getVault = {} as jest.Mocked<GetVault>
|
||||
const handleRootKeyChangedMessage = {} as jest.Mocked<HandleRootKeyChangedMessage>
|
||||
const sendOwnContactChangedMessage = {} as jest.Mocked<SendOwnContactChangeMessage>
|
||||
const getOutboundMessagesUseCase = {} as jest.Mocked<GetOutboundMessages>
|
||||
const getInboundMessagesUseCase = {} as jest.Mocked<GetInboundMessages>
|
||||
const getUntrustedPayload = {} as jest.Mocked<GetUntrustedPayload>
|
||||
@@ -60,17 +58,16 @@ describe('AsymmetricMessageService', () => {
|
||||
eventBus.addEventHandler = jest.fn()
|
||||
|
||||
service = new AsymmetricMessageService(
|
||||
messageServer,
|
||||
encryption,
|
||||
mutator,
|
||||
sessions,
|
||||
messageServer,
|
||||
createOrEditContact,
|
||||
findContact,
|
||||
getAllContacts,
|
||||
replaceContactData,
|
||||
getTrustedPayload,
|
||||
getVault,
|
||||
handleRootKeyChangedMessage,
|
||||
sendOwnContactChangedMessage,
|
||||
getOutboundMessagesUseCase,
|
||||
getInboundMessagesUseCase,
|
||||
getUntrustedPayload,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { SessionsClientInterface } from './../Session/SessionsClientInterface'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
import { AsymmetricMessageServerHash, ClientDisplayableError, isClientDisplayableError } from '@standardnotes/responses'
|
||||
import { SyncEvent, SyncEventReceivedAsymmetricMessagesData } from '../Event/SyncEvent'
|
||||
@@ -21,17 +22,14 @@ import {
|
||||
import { HandleRootKeyChangedMessage } from './UseCase/HandleRootKeyChangedMessage'
|
||||
import { SessionEvent } from '../Session/SessionEvent'
|
||||
import { AsymmetricMessageServer } from '@standardnotes/api'
|
||||
import { UserKeyPairChangedEventData } from '../Session/UserKeyPairChangedEventData'
|
||||
import { SendOwnContactChangeMessage } from './UseCase/SendOwnContactChangeMessage'
|
||||
import { GetOutboundMessages } from './UseCase/GetOutboundMessages'
|
||||
import { GetInboundMessages } from './UseCase/GetInboundMessages'
|
||||
import { GetVault } from '../Vaults/UseCase/GetVault'
|
||||
import { GetVault } from '../Vault/UseCase/GetVault'
|
||||
import { AsymmetricMessageServiceInterface } from './AsymmetricMessageServiceInterface'
|
||||
import { GetUntrustedPayload } from './UseCase/GetUntrustedPayload'
|
||||
import { FindContact } from '../Contacts/UseCase/FindContact'
|
||||
import { CreateOrEditContact } from '../Contacts/UseCase/CreateOrEditContact'
|
||||
import { ReplaceContactData } from '../Contacts/UseCase/ReplaceContactData'
|
||||
import { GetAllContacts } from '../Contacts/UseCase/GetAllContacts'
|
||||
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
|
||||
|
||||
export class AsymmetricMessageService
|
||||
@@ -39,17 +37,16 @@ export class AsymmetricMessageService
|
||||
implements AsymmetricMessageServiceInterface, InternalEventHandlerInterface
|
||||
{
|
||||
constructor(
|
||||
private messageServer: AsymmetricMessageServer,
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private mutator: MutatorClientInterface,
|
||||
private sessions: SessionsClientInterface,
|
||||
private messageServer: AsymmetricMessageServer,
|
||||
private _createOrEditContact: CreateOrEditContact,
|
||||
private _findContact: FindContact,
|
||||
private _getAllContacts: GetAllContacts,
|
||||
private _replaceContactData: ReplaceContactData,
|
||||
private _getTrustedPayload: GetTrustedPayload,
|
||||
private _getVault: GetVault,
|
||||
private _handleRootKeyChangedMessage: HandleRootKeyChangedMessage,
|
||||
private _sendOwnContactChangedMessage: SendOwnContactChangeMessage,
|
||||
private _getOutboundMessagesUseCase: GetOutboundMessages,
|
||||
private _getInboundMessagesUseCase: GetInboundMessages,
|
||||
private _getUntrustedPayload: GetUntrustedPayload,
|
||||
@@ -58,11 +55,26 @@ export class AsymmetricMessageService
|
||||
super(eventBus)
|
||||
}
|
||||
|
||||
public override deinit(): void {
|
||||
super.deinit()
|
||||
;(this.messageServer as unknown) = undefined
|
||||
;(this.encryption as unknown) = undefined
|
||||
;(this.mutator as unknown) = undefined
|
||||
;(this._createOrEditContact as unknown) = undefined
|
||||
;(this._findContact as unknown) = undefined
|
||||
;(this._replaceContactData as unknown) = undefined
|
||||
;(this._getTrustedPayload as unknown) = undefined
|
||||
;(this._getVault as unknown) = undefined
|
||||
;(this._handleRootKeyChangedMessage as unknown) = undefined
|
||||
;(this._getOutboundMessagesUseCase as unknown) = undefined
|
||||
;(this._getInboundMessagesUseCase as unknown) = undefined
|
||||
;(this._getUntrustedPayload as unknown) = undefined
|
||||
}
|
||||
|
||||
async handleEvent(event: InternalEventInterface): Promise<void> {
|
||||
switch (event.type) {
|
||||
case SessionEvent.UserKeyPairChanged:
|
||||
void this.messageServer.deleteAllInboundMessages()
|
||||
void this.sendOwnContactChangeEventToAllContacts(event.payload as UserKeyPairChangedEventData)
|
||||
break
|
||||
case SyncEvent.ReceivedAsymmetricMessages:
|
||||
void this.handleRemoteReceivedAsymmetricMessages(event.payload as SyncEventReceivedAsymmetricMessagesData)
|
||||
@@ -87,31 +99,6 @@ export class AsymmetricMessageService
|
||||
await this.handleRemoteReceivedAsymmetricMessages(messages)
|
||||
}
|
||||
|
||||
private async sendOwnContactChangeEventToAllContacts(data: UserKeyPairChangedEventData): Promise<void> {
|
||||
if (!data.previous) {
|
||||
return
|
||||
}
|
||||
|
||||
const contacts = this._getAllContacts.execute()
|
||||
if (contacts.isFailed()) {
|
||||
return
|
||||
}
|
||||
|
||||
for (const contact of contacts.getValue()) {
|
||||
if (contact.isMe) {
|
||||
continue
|
||||
}
|
||||
|
||||
await this._sendOwnContactChangedMessage.execute({
|
||||
senderOldKeyPair: data.previous.encryption,
|
||||
senderOldSigningKeyPair: data.previous.signing,
|
||||
senderNewKeyPair: data.current.encryption,
|
||||
senderNewSigningKeyPair: data.current.signing,
|
||||
contact,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
sortServerMessages(messages: AsymmetricMessageServerHash[]): AsymmetricMessageServerHash[] {
|
||||
const SortedPriorityTypes = [AsymmetricMessagePayloadType.SenderKeypairChanged]
|
||||
|
||||
@@ -184,10 +171,6 @@ export class AsymmetricMessageService
|
||||
message: AsymmetricMessageServerHash,
|
||||
payload: AsymmetricMessagePayload,
|
||||
): Promise<void> {
|
||||
if (payload.data.recipientUuid !== message.user_uuid) {
|
||||
return
|
||||
}
|
||||
|
||||
if (payload.type === AsymmetricMessagePayloadType.ContactShare) {
|
||||
await this.handleTrustedContactShareMessage(message, payload)
|
||||
} else if (payload.type === AsymmetricMessagePayloadType.SenderKeypairChanged) {
|
||||
@@ -225,6 +208,7 @@ export class AsymmetricMessageService
|
||||
const result = this._getTrustedPayload.execute({
|
||||
privateKey: this.encryption.getKeyPair().privateKey,
|
||||
sender: contact.getValue(),
|
||||
ownUserUuid: this.sessions.userUuid,
|
||||
message,
|
||||
})
|
||||
|
||||
@@ -289,22 +273,4 @@ export class AsymmetricMessageService
|
||||
): Promise<void> {
|
||||
await this._handleRootKeyChangedMessage.execute(trustedPayload)
|
||||
}
|
||||
|
||||
public override deinit(): void {
|
||||
super.deinit()
|
||||
;(this.messageServer as unknown) = undefined
|
||||
;(this.encryption as unknown) = undefined
|
||||
;(this.mutator as unknown) = undefined
|
||||
;(this._createOrEditContact as unknown) = undefined
|
||||
;(this._findContact as unknown) = undefined
|
||||
;(this._getAllContacts as unknown) = undefined
|
||||
;(this._replaceContactData as unknown) = undefined
|
||||
;(this._getTrustedPayload as unknown) = undefined
|
||||
;(this._getVault as unknown) = undefined
|
||||
;(this._handleRootKeyChangedMessage as unknown) = undefined
|
||||
;(this._sendOwnContactChangedMessage as unknown) = undefined
|
||||
;(this._getOutboundMessagesUseCase as unknown) = undefined
|
||||
;(this._getInboundMessagesUseCase as unknown) = undefined
|
||||
;(this._getUntrustedPayload as unknown) = undefined
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import { AsymmetricMessageServerHash } from '@standardnotes/responses'
|
||||
import { AsymmetricMessagePayload, TrustedContactInterface } from '@standardnotes/models'
|
||||
import { DecryptMessage } from '../../Encryption/UseCase/Asymmetric/DecryptMessage'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
import { GetTrustedPayload } from './GetTrustedPayload'
|
||||
|
||||
describe('GetTrustedPayload', () => {
|
||||
let decryptMessage: jest.Mocked<DecryptMessage>
|
||||
let getTrustedPayload: GetTrustedPayload
|
||||
|
||||
beforeEach(() => {
|
||||
decryptMessage = {} as jest.Mocked<DecryptMessage>
|
||||
decryptMessage.execute = jest.fn()
|
||||
|
||||
getTrustedPayload = new GetTrustedPayload(decryptMessage)
|
||||
})
|
||||
|
||||
describe('execute', () => {
|
||||
const mockDto = {
|
||||
privateKey: 'test-private-key',
|
||||
message: {} as AsymmetricMessageServerHash,
|
||||
sender: {} as TrustedContactInterface,
|
||||
ownUserUuid: 'test-user-uuid',
|
||||
}
|
||||
|
||||
it('should return failure when decryption fails', () => {
|
||||
decryptMessage.execute = jest.fn().mockReturnValue(Result.fail('Decryption failed'))
|
||||
|
||||
const result = getTrustedPayload.execute(mockDto)
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Decryption failed')
|
||||
})
|
||||
|
||||
it('should return failure when recipientUuid is not equal to ownUserUuid', () => {
|
||||
const mockPayload: AsymmetricMessagePayload = {
|
||||
data: {
|
||||
recipientUuid: 'another-user-uuid',
|
||||
},
|
||||
} as AsymmetricMessagePayload
|
||||
decryptMessage.execute = jest.fn().mockReturnValue(Result.ok(mockPayload))
|
||||
|
||||
const result = getTrustedPayload.execute(mockDto)
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Message is not for this user')
|
||||
})
|
||||
|
||||
it('should return success when recipientUuid is equal to ownUserUuid', () => {
|
||||
const mockPayload: AsymmetricMessagePayload = {
|
||||
data: {
|
||||
recipientUuid: 'test-user-uuid',
|
||||
},
|
||||
} as AsymmetricMessagePayload
|
||||
decryptMessage.execute = jest.fn().mockReturnValue(Result.ok(mockPayload))
|
||||
|
||||
const result = getTrustedPayload.execute(mockDto)
|
||||
|
||||
expect(result.isFailed()).toBe(false)
|
||||
expect(result.getValue()).toBe(mockPayload)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -10,6 +10,7 @@ export class GetTrustedPayload implements SyncUseCaseInterface<AsymmetricMessage
|
||||
privateKey: string
|
||||
message: AsymmetricMessageServerHash
|
||||
sender: TrustedContactInterface
|
||||
ownUserUuid: string
|
||||
}): Result<M> {
|
||||
const result = this.decryptMessage.execute<M>({
|
||||
message: dto.message.encrypted_message,
|
||||
@@ -17,6 +18,16 @@ export class GetTrustedPayload implements SyncUseCaseInterface<AsymmetricMessage
|
||||
privateKey: dto.privateKey,
|
||||
})
|
||||
|
||||
if (result.isFailed()) {
|
||||
return result
|
||||
}
|
||||
|
||||
const recipientUuid = result.getValue().data.recipientUuid
|
||||
|
||||
if (recipientUuid !== dto.ownUserUuid) {
|
||||
return Result.fail('Message is not for this user')
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ import {
|
||||
} from '@standardnotes/models'
|
||||
|
||||
import { ContentType } from '@standardnotes/domain-core'
|
||||
import { GetVault } from '../../Vaults/UseCase/GetVault'
|
||||
import { GetVault } from '../../Vault/UseCase/GetVault'
|
||||
import { EncryptionProviderInterface } from '../../Encryption/EncryptionProviderInterface'
|
||||
|
||||
export class HandleRootKeyChangedMessage {
|
||||
|
||||
@@ -32,7 +32,7 @@ export class ResendAllMessages implements UseCaseInterface<void> {
|
||||
|
||||
for (const message of messages.data.messages) {
|
||||
const recipient = this.findContact.execute({ userUuid: message.user_uuid })
|
||||
if (recipient) {
|
||||
if (recipient.isFailed()) {
|
||||
errors.push(`Contact not found for invite ${message.user_uuid}`)
|
||||
continue
|
||||
}
|
||||
@@ -41,7 +41,7 @@ export class ResendAllMessages implements UseCaseInterface<void> {
|
||||
keys: params.keys,
|
||||
previousKeys: params.previousKeys,
|
||||
message: message,
|
||||
recipient,
|
||||
recipient: recipient.getValue(),
|
||||
})
|
||||
|
||||
await this.messageServer.deleteMessage({
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { SendOwnContactChangeMessage } from './UseCase/SendOwnContactChangeMessage'
|
||||
import { DeleteContact } from './UseCase/DeleteContact'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
import { UserKeyPairChangedEventData } from './../Session/UserKeyPairChangedEventData'
|
||||
import { SessionEvent } from './../Session/SessionEvent'
|
||||
@@ -21,6 +23,7 @@ import { CreateOrEditContact } from './UseCase/CreateOrEditContact'
|
||||
import { EditContact } from './UseCase/EditContact'
|
||||
import { GetAllContacts } from './UseCase/GetAllContacts'
|
||||
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
|
||||
export class ContactService
|
||||
extends AbstractService<ContactServiceEvent>
|
||||
@@ -34,11 +37,13 @@ export class ContactService
|
||||
private user: UserClientInterface,
|
||||
private selfContactManager: SelfContactManager,
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private _deleteContact: DeleteContact,
|
||||
private _findContact: FindContact,
|
||||
private _getAllContacts: GetAllContacts,
|
||||
private _createOrEditContact: CreateOrEditContact,
|
||||
private _editContact: EditContact,
|
||||
private _validateItemSigner: ValidateItemSigner,
|
||||
private _sendOwnContactChangedMessage: SendOwnContactChangeMessage,
|
||||
eventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(eventBus)
|
||||
@@ -49,11 +54,36 @@ export class ContactService
|
||||
async handleEvent(event: InternalEventInterface): Promise<void> {
|
||||
if (event.type === SessionEvent.UserKeyPairChanged) {
|
||||
const data = event.payload as UserKeyPairChangedEventData
|
||||
|
||||
await this.selfContactManager.updateWithNewPublicKeySet({
|
||||
encryption: data.current.encryption.publicKey,
|
||||
signing: data.current.signing.publicKey,
|
||||
})
|
||||
void this.sendOwnContactChangeEventToAllContacts(event.payload as UserKeyPairChangedEventData)
|
||||
}
|
||||
}
|
||||
|
||||
private async sendOwnContactChangeEventToAllContacts(data: UserKeyPairChangedEventData): Promise<void> {
|
||||
if (!data.previous) {
|
||||
return
|
||||
}
|
||||
|
||||
const contacts = this._getAllContacts.execute()
|
||||
if (contacts.isFailed()) {
|
||||
return
|
||||
}
|
||||
|
||||
for (const contact of contacts.getValue()) {
|
||||
if (contact.isMe) {
|
||||
continue
|
||||
}
|
||||
|
||||
await this._sendOwnContactChangedMessage.execute({
|
||||
senderOldKeyPair: data.previous.encryption,
|
||||
senderOldSigningKeyPair: data.previous.signing,
|
||||
senderNewKeyPair: data.current.encryption,
|
||||
senderNewSigningKeyPair: data.current.signing,
|
||||
contact,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,20 +197,15 @@ export class ContactService
|
||||
return contact
|
||||
}
|
||||
|
||||
async deleteContact(contact: TrustedContactInterface): Promise<void> {
|
||||
if (contact.isMe) {
|
||||
throw new Error('Cannot delete self')
|
||||
}
|
||||
|
||||
await this.mutator.setItemToBeDeleted(contact)
|
||||
await this.sync.sync()
|
||||
async deleteContact(contact: TrustedContactInterface): Promise<Result<void>> {
|
||||
return this._deleteContact.execute({ contact, ownUserUuid: this.session.userUuid })
|
||||
}
|
||||
|
||||
getAllContacts(): TrustedContactInterface[] {
|
||||
return this._getAllContacts.execute().getValue()
|
||||
}
|
||||
|
||||
findTrustedContact(userUuid: string): TrustedContactInterface | undefined {
|
||||
findContact(userUuid: string): TrustedContactInterface | undefined {
|
||||
const result = this._findContact.execute({ userUuid })
|
||||
if (result.isFailed()) {
|
||||
return undefined
|
||||
@@ -188,12 +213,12 @@ export class ContactService
|
||||
return result.getValue()
|
||||
}
|
||||
|
||||
findTrustedContactForServerUser(user: SharedVaultUserServerHash): TrustedContactInterface | undefined {
|
||||
return this.findTrustedContact(user.user_uuid)
|
||||
findContactForServerUser(user: SharedVaultUserServerHash): TrustedContactInterface | undefined {
|
||||
return this.findContact(user.user_uuid)
|
||||
}
|
||||
|
||||
findTrustedContactForInvite(invite: SharedVaultInviteServerHash): TrustedContactInterface | undefined {
|
||||
return this.findTrustedContact(invite.sender_uuid)
|
||||
findContactForInvite(invite: SharedVaultInviteServerHash): TrustedContactInterface | undefined {
|
||||
return this.findContact(invite.sender_uuid)
|
||||
}
|
||||
|
||||
getCollaborationIDForTrustedContact(contact: TrustedContactInterface): string {
|
||||
@@ -205,7 +230,7 @@ export class ContactService
|
||||
})
|
||||
}
|
||||
|
||||
isItemAuthenticallySigned(item: DecryptedItemInterface): ItemSignatureValidationResult {
|
||||
getItemSignatureStatus(item: DecryptedItemInterface): ItemSignatureValidationResult {
|
||||
return this._validateItemSigner.execute(item)
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import { DecryptedItemInterface, TrustedContactInterface } from '@standardnotes/
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { SharedVaultInviteServerHash, SharedVaultUserServerHash } from '@standardnotes/responses'
|
||||
import { ItemSignatureValidationResult } from './UseCase/Types/ItemSignatureValidationResult'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
|
||||
export enum ContactServiceEvent {}
|
||||
|
||||
@@ -26,13 +27,13 @@ export interface ContactServiceInterface extends AbstractService<ContactServiceE
|
||||
contact: TrustedContactInterface,
|
||||
params: { name: string; collaborationID: string },
|
||||
): Promise<TrustedContactInterface>
|
||||
deleteContact(contact: TrustedContactInterface): Promise<void>
|
||||
deleteContact(contact: TrustedContactInterface): Promise<Result<void>>
|
||||
|
||||
getAllContacts(): TrustedContactInterface[]
|
||||
getSelfContact(): TrustedContactInterface | undefined
|
||||
findTrustedContact(userUuid: string): TrustedContactInterface | undefined
|
||||
findTrustedContactForServerUser(user: SharedVaultUserServerHash): TrustedContactInterface | undefined
|
||||
findTrustedContactForInvite(invite: SharedVaultInviteServerHash): TrustedContactInterface | undefined
|
||||
findContact(userUuid: string): TrustedContactInterface | undefined
|
||||
findContactForServerUser(user: SharedVaultUserServerHash): TrustedContactInterface | undefined
|
||||
findContactForInvite(invite: SharedVaultInviteServerHash): TrustedContactInterface | undefined
|
||||
|
||||
isItemAuthenticallySigned(item: DecryptedItemInterface): ItemSignatureValidationResult
|
||||
getItemSignatureStatus(item: DecryptedItemInterface): ItemSignatureValidationResult
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
import { ContactBelongsToVault } from './../../SharedVaults/UseCase/ContactBelongsToVault'
|
||||
import { GetOwnedSharedVaults } from './../../SharedVaults/UseCase/GetOwnedSharedVaults'
|
||||
import { SyncServiceInterface } from './../../Sync/SyncServiceInterface'
|
||||
import { MutatorClientInterface } from './../../Mutator/MutatorClientInterface'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
import { TrustedContactInterface } from '@standardnotes/models'
|
||||
import { DeleteContact } from './DeleteContact'
|
||||
|
||||
describe('DeleteContact', () => {
|
||||
let mutator: jest.Mocked<MutatorClientInterface>
|
||||
let sync: jest.Mocked<SyncServiceInterface>
|
||||
let getOwnedVaults: jest.Mocked<GetOwnedSharedVaults>
|
||||
let contactBelongsToVault: jest.Mocked<ContactBelongsToVault>
|
||||
let deleteContact: DeleteContact
|
||||
let mockDto: {
|
||||
contact: TrustedContactInterface
|
||||
ownUserUuid: string
|
||||
}
|
||||
let mockVaults: { id: string }[]
|
||||
|
||||
beforeEach(() => {
|
||||
mutator = {} as jest.Mocked<MutatorClientInterface>
|
||||
sync = {} as jest.Mocked<SyncServiceInterface>
|
||||
|
||||
getOwnedVaults = {} as jest.Mocked<GetOwnedSharedVaults>
|
||||
getOwnedVaults.execute = jest.fn()
|
||||
|
||||
contactBelongsToVault = {} as jest.Mocked<ContactBelongsToVault>
|
||||
contactBelongsToVault.execute = jest.fn()
|
||||
|
||||
deleteContact = new DeleteContact(mutator, sync, getOwnedVaults, contactBelongsToVault)
|
||||
|
||||
mockDto = {
|
||||
contact: { isMe: false } as TrustedContactInterface,
|
||||
ownUserUuid: 'test-user-uuid',
|
||||
}
|
||||
|
||||
mockVaults = [{ id: 'vault1' }, { id: 'vault2' }]
|
||||
})
|
||||
|
||||
describe('execute', () => {
|
||||
it('should throw error when deleting self', async () => {
|
||||
mockDto.contact.isMe = true
|
||||
await expect(deleteContact.execute(mockDto)).rejects.toThrow('Cannot delete self')
|
||||
})
|
||||
|
||||
it('should return failure when getting owned vaults fails', async () => {
|
||||
getOwnedVaults.execute = jest.fn().mockReturnValue(Result.fail('Failed to get owned vaults'))
|
||||
|
||||
const result = await deleteContact.execute(mockDto)
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Failed to get owned vaults')
|
||||
})
|
||||
|
||||
it('should return failure when checking contact membership fails', async () => {
|
||||
getOwnedVaults.execute = jest.fn().mockReturnValue(Result.ok(mockVaults))
|
||||
contactBelongsToVault.execute = jest.fn().mockResolvedValue(Result.fail('Failed to check contact membership'))
|
||||
|
||||
const result = await deleteContact.execute(mockDto)
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Failed to check contact membership')
|
||||
})
|
||||
|
||||
it('should return failure when contact belongs to an owned vault', async () => {
|
||||
getOwnedVaults.execute = jest.fn().mockReturnValue(Result.ok(mockVaults))
|
||||
contactBelongsToVault.execute = jest.fn().mockResolvedValue(Result.ok(true))
|
||||
|
||||
const result = await deleteContact.execute(mockDto)
|
||||
|
||||
expect(result.isFailed()).toBe(true)
|
||||
expect(result.getError()).toBe('Cannot delete contact that belongs to an owned vault')
|
||||
})
|
||||
|
||||
it('should return success when contact is successfully deleted', async () => {
|
||||
getOwnedVaults.execute = jest.fn().mockReturnValue(Result.ok(mockVaults))
|
||||
contactBelongsToVault.execute = jest.fn().mockResolvedValue(Result.ok(false))
|
||||
mutator.setItemToBeDeleted = jest.fn().mockResolvedValue(undefined)
|
||||
sync.sync = jest.fn().mockResolvedValue(undefined)
|
||||
|
||||
const result = await deleteContact.execute(mockDto)
|
||||
|
||||
expect(result.isFailed()).toBe(false)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,45 @@
|
||||
import { ContactBelongsToVault } from './../../SharedVaults/UseCase/ContactBelongsToVault'
|
||||
import { GetOwnedSharedVaults } from './../../SharedVaults/UseCase/GetOwnedSharedVaults'
|
||||
import { SyncServiceInterface } from './../../Sync/SyncServiceInterface'
|
||||
import { MutatorClientInterface } from './../../Mutator/MutatorClientInterface'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { TrustedContactInterface } from '@standardnotes/models'
|
||||
|
||||
export class DeleteContact implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private mutator: MutatorClientInterface,
|
||||
private sync: SyncServiceInterface,
|
||||
private getOwnedVaults: GetOwnedSharedVaults,
|
||||
private contactBelongsToVault: ContactBelongsToVault,
|
||||
) {}
|
||||
|
||||
async execute(dto: { contact: TrustedContactInterface; ownUserUuid: string }): Promise<Result<void>> {
|
||||
if (dto.contact.isMe) {
|
||||
throw new Error('Cannot delete self')
|
||||
}
|
||||
|
||||
const vaults = this.getOwnedVaults.execute({ userUuid: dto.ownUserUuid })
|
||||
if (vaults.isFailed()) {
|
||||
return Result.fail('Failed to get owned vaults')
|
||||
}
|
||||
|
||||
for (const vault of vaults.getValue()) {
|
||||
const contactBelongsToVault = await this.contactBelongsToVault.execute({
|
||||
contact: dto.contact,
|
||||
vault: vault,
|
||||
})
|
||||
if (contactBelongsToVault.isFailed()) {
|
||||
return Result.fail('Failed to check contact membership')
|
||||
}
|
||||
|
||||
if (contactBelongsToVault.getValue()) {
|
||||
return Result.fail('Cannot delete contact that belongs to an owned vault')
|
||||
}
|
||||
}
|
||||
|
||||
await this.mutator.setItemToBeDeleted(dto.contact)
|
||||
await this.sync.sync()
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -5,7 +5,7 @@ import {
|
||||
AsymmetricMessageSenderKeypairChanged,
|
||||
} from '@standardnotes/models'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { SendMessage } from './SendMessage'
|
||||
import { SendMessage } from '../../AsymmetricMessage/UseCase/SendMessage'
|
||||
import { EncryptMessage } from '../../Encryption/UseCase/Asymmetric/EncryptMessage'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
@@ -112,7 +112,6 @@ export class ValidateItemSigner {
|
||||
const signerPublicKey = signatureResult.publicKey
|
||||
|
||||
const trustedContact = this.findContact.execute({ signingPublicKey: signerPublicKey })
|
||||
|
||||
if (trustedContact.isFailed()) {
|
||||
return ItemSignatureValidationResult.NotTrusted
|
||||
}
|
||||
|
||||
+7
-7
@@ -2,24 +2,24 @@ import { ItemsKeyMutator } from '@standardnotes/encryption'
|
||||
import { MutatorClientInterface } from '../../../Mutator/MutatorClientInterface'
|
||||
import { ItemManagerInterface } from '../../../Item/ItemManagerInterface'
|
||||
import { CreateNewDefaultItemsKey } from './CreateNewDefaultItemsKey'
|
||||
import { RemoveItemsLocally } from '../../../UseCase/RemoveItemsLocally'
|
||||
import { DiscardItemsLocally } from '../../../UseCase/DiscardItemsLocally'
|
||||
import { FindDefaultItemsKey } from './FindDefaultItemsKey'
|
||||
|
||||
export class CreateNewItemsKeyWithRollback {
|
||||
constructor(
|
||||
private mutator: MutatorClientInterface,
|
||||
private items: ItemManagerInterface,
|
||||
private createDefaultItemsKey: CreateNewDefaultItemsKey,
|
||||
private removeItemsLocally: RemoveItemsLocally,
|
||||
private findDefaultItemsKey: FindDefaultItemsKey,
|
||||
private _createDefaultItemsKey: CreateNewDefaultItemsKey,
|
||||
private _discardItemsLocally: DiscardItemsLocally,
|
||||
private _findDefaultItemsKey: FindDefaultItemsKey,
|
||||
) {}
|
||||
|
||||
async execute(): Promise<() => Promise<void>> {
|
||||
const currentDefaultItemsKey = this.findDefaultItemsKey.execute(this.items.getDisplayableItemsKeys()).getValue()
|
||||
const newDefaultItemsKey = await this.createDefaultItemsKey.execute()
|
||||
const currentDefaultItemsKey = this._findDefaultItemsKey.execute(this.items.getDisplayableItemsKeys()).getValue()
|
||||
const newDefaultItemsKey = await this._createDefaultItemsKey.execute()
|
||||
|
||||
const rollback = async () => {
|
||||
await this.removeItemsLocally.execute([newDefaultItemsKey])
|
||||
await this._discardItemsLocally.execute([newDefaultItemsKey])
|
||||
|
||||
if (currentDefaultItemsKey) {
|
||||
await this.mutator.changeItem<ItemsKeyMutator>(currentDefaultItemsKey, (mutator) => {
|
||||
|
||||
@@ -80,7 +80,7 @@ export interface ItemManagerInterface extends AbstractService {
|
||||
): T[]
|
||||
subItemsMatchingPredicates<T extends DecryptedItemInterface>(items: T[], predicates: PredicateInterface<T>[]): T[]
|
||||
removeAllItemsFromMemory(): Promise<void>
|
||||
removeItemsLocally(items: AnyItemInterface[]): void
|
||||
removeItemsFromMemory(items: AnyItemInterface[]): void
|
||||
getDirtyItems(): (DecryptedItemInterface | DeletedItemInterface)[]
|
||||
getTagLongTitle(tag: SNTag): string
|
||||
getSortedTagsForItem(item: DecryptedItemInterface<ItemContent>): SNTag[]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { RemoveItemsFromMemory } from './../Storage/UseCase/RemoveItemsFromMemory'
|
||||
import { InternalEventHandlerInterface } from './../Internal/InternalEventHandlerInterface'
|
||||
import { MutatorClientInterface } from './../Mutator/MutatorClientInterface'
|
||||
import { ApplicationStage } from './../Application/ApplicationStage'
|
||||
@@ -36,11 +37,20 @@ export class KeySystemKeyManager
|
||||
private readonly items: ItemManagerInterface,
|
||||
private readonly mutator: MutatorClientInterface,
|
||||
private readonly storage: StorageServiceInterface,
|
||||
private readonly _removeItemsFromMemory: RemoveItemsFromMemory,
|
||||
eventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(eventBus)
|
||||
}
|
||||
|
||||
public override deinit(): void {
|
||||
;(this.items as unknown) = undefined
|
||||
;(this.mutator as unknown) = undefined
|
||||
;(this.storage as unknown) = undefined
|
||||
;(this._removeItemsFromMemory as unknown) = undefined
|
||||
super.deinit()
|
||||
}
|
||||
|
||||
async handleEvent(event: InternalEventInterface): Promise<void> {
|
||||
if (event.type === ApplicationEvent.ApplicationStageChanged) {
|
||||
const stage = (event.payload as ApplicationStageChangedEventPayload).stage
|
||||
@@ -60,9 +70,28 @@ export class KeySystemKeyManager
|
||||
const keyPayloads = keyRawPayloads.map((rawPayload) => new DecryptedPayload<KeySystemRootKeyContent>(rawPayload))
|
||||
|
||||
const keys = keyPayloads.map((payload) => new KeySystemRootKey(payload))
|
||||
keys.forEach((key) => {
|
||||
|
||||
for (const key of keys) {
|
||||
this.rootKeyMemoryCache[key.systemIdentifier] = key
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public getRootKeyFromStorageForVault(
|
||||
keySystemIdentifier: KeySystemIdentifier,
|
||||
): KeySystemRootKeyInterface | undefined {
|
||||
const payload = this.storage.getValue<DecryptedTransferPayload<KeySystemRootKeyContent>>(
|
||||
this.storageKeyForRootKey(keySystemIdentifier),
|
||||
)
|
||||
|
||||
if (!payload) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
const keyPayload = new DecryptedPayload<KeySystemRootKeyContent>(payload)
|
||||
|
||||
const key = new KeySystemRootKey(keyPayload)
|
||||
|
||||
return key
|
||||
}
|
||||
|
||||
private storageKeyForRootKey(systemIdentifier: KeySystemIdentifier): string {
|
||||
@@ -73,17 +102,14 @@ export class KeySystemKeyManager
|
||||
* When the key system root key changes, we must re-encrypt all vault items keys
|
||||
* with this new key system root key (by simply re-syncing).
|
||||
*/
|
||||
public async reencryptKeySystemItemsKeysForVault(keySystemIdentifier: KeySystemIdentifier): Promise<void> {
|
||||
public async queueVaultItemsKeysForReencryption(keySystemIdentifier: KeySystemIdentifier): Promise<void> {
|
||||
const keySystemItemsKeys = this.getKeySystemItemsKeys(keySystemIdentifier)
|
||||
if (keySystemItemsKeys.length > 0) {
|
||||
await this.mutator.setItemsDirty(keySystemItemsKeys)
|
||||
}
|
||||
}
|
||||
|
||||
public intakeNonPersistentKeySystemRootKey(
|
||||
key: KeySystemRootKeyInterface,
|
||||
storage: KeySystemRootKeyStorageMode,
|
||||
): void {
|
||||
public cacheKey(key: KeySystemRootKeyInterface, storage: KeySystemRootKeyStorageMode): void {
|
||||
this.rootKeyMemoryCache[key.systemIdentifier] = key
|
||||
|
||||
if (storage === KeySystemRootKeyStorageMode.Local) {
|
||||
@@ -91,7 +117,7 @@ export class KeySystemKeyManager
|
||||
}
|
||||
}
|
||||
|
||||
public undoIntakeNonPersistentKeySystemRootKey(systemIdentifier: KeySystemIdentifier): void {
|
||||
public removeKeyFromCache(systemIdentifier: KeySystemIdentifier): void {
|
||||
delete this.rootKeyMemoryCache[systemIdentifier]
|
||||
void this.storage.removeValue(this.storageKeyForRootKey(systemIdentifier))
|
||||
}
|
||||
@@ -100,11 +126,11 @@ export class KeySystemKeyManager
|
||||
return this.items.getItems(ContentType.TYPES.KeySystemRootKey)
|
||||
}
|
||||
|
||||
public clearMemoryOfKeysRelatedToVault(vault: VaultListingInterface): void {
|
||||
public async wipeVaultKeysFromMemory(vault: VaultListingInterface): Promise<void> {
|
||||
delete this.rootKeyMemoryCache[vault.systemIdentifier]
|
||||
|
||||
const itemsKeys = this.getKeySystemItemsKeys(vault.systemIdentifier)
|
||||
this.items.removeItemsLocally(itemsKeys)
|
||||
await this._removeItemsFromMemory.execute(itemsKeys)
|
||||
}
|
||||
|
||||
public getSyncedKeySystemRootKeysForVault(systemIdentifier: KeySystemIdentifier): KeySystemRootKeyInterface[] {
|
||||
@@ -131,19 +157,6 @@ export class KeySystemKeyManager
|
||||
await this.mutator.setItemsToBeDeleted(keys)
|
||||
}
|
||||
|
||||
public getKeySystemRootKeyWithToken(
|
||||
systemIdentifier: KeySystemIdentifier,
|
||||
rootKeyToken: string,
|
||||
): KeySystemRootKeyInterface | undefined {
|
||||
const keys = this.getAllKeySystemRootKeysForVault(systemIdentifier).filter((key) => key.token === rootKeyToken)
|
||||
|
||||
if (keys.length > 1) {
|
||||
throw new Error('Multiple synced key system root keys found for token')
|
||||
}
|
||||
|
||||
return keys[0]
|
||||
}
|
||||
|
||||
public getPrimaryKeySystemRootKey(systemIdentifier: KeySystemIdentifier): KeySystemRootKeyInterface | undefined {
|
||||
const keys = this.getAllKeySystemRootKeysForVault(systemIdentifier)
|
||||
|
||||
|
||||
@@ -16,17 +16,13 @@ export interface KeySystemKeyManagerInterface {
|
||||
getAllKeySystemRootKeysForVault(systemIdentifier: KeySystemIdentifier): KeySystemRootKeyInterface[]
|
||||
getSyncedKeySystemRootKeysForVault(systemIdentifier: KeySystemIdentifier): KeySystemRootKeyInterface[]
|
||||
getAllSyncedKeySystemRootKeys(): KeySystemRootKeyInterface[]
|
||||
getKeySystemRootKeyWithToken(
|
||||
systemIdentifier: KeySystemIdentifier,
|
||||
keyIdentifier: string,
|
||||
): KeySystemRootKeyInterface | undefined
|
||||
getPrimaryKeySystemRootKey(systemIdentifier: KeySystemIdentifier): KeySystemRootKeyInterface | undefined
|
||||
reencryptKeySystemItemsKeysForVault(keySystemIdentifier: KeySystemIdentifier): Promise<void>
|
||||
queueVaultItemsKeysForReencryption(keySystemIdentifier: KeySystemIdentifier): Promise<void>
|
||||
|
||||
intakeNonPersistentKeySystemRootKey(key: KeySystemRootKeyInterface, storage: KeySystemRootKeyStorageMode): void
|
||||
undoIntakeNonPersistentKeySystemRootKey(systemIdentifier: KeySystemIdentifier): void
|
||||
cacheKey(key: KeySystemRootKeyInterface, storage: KeySystemRootKeyStorageMode): void
|
||||
removeKeyFromCache(systemIdentifier: KeySystemIdentifier): void
|
||||
|
||||
clearMemoryOfKeysRelatedToVault(vault: VaultListingInterface): void
|
||||
wipeVaultKeysFromMemory(vault: VaultListingInterface): Promise<void>
|
||||
deleteNonPersistentSystemRootKeysForVault(systemIdentifier: KeySystemIdentifier): Promise<void>
|
||||
deleteAllSyncedKeySystemRootKeys(systemIdentifier: KeySystemIdentifier): Promise<void>
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { IsVaultAdmin } from './../VaultUser/UseCase/IsVaultAdmin'
|
||||
import { DiscardItemsLocally } from './../UseCase/DiscardItemsLocally'
|
||||
import { InternalEventBusInterface } from './../Internal/InternalEventBusInterface'
|
||||
import { GetOwnedSharedVaults } from './UseCase/GetOwnedSharedVaults'
|
||||
import { IsVaultOwner } from './../VaultUser/UseCase/IsVaultOwner'
|
||||
import { EncryptionProviderInterface } from './../Encryption/EncryptionProviderInterface'
|
||||
import { DeleteSharedVault } from './UseCase/DeleteSharedVault'
|
||||
import { ConvertToSharedVault } from './UseCase/ConvertToSharedVault'
|
||||
@@ -9,13 +12,11 @@ import { SendVaultDataChangedMessage } from './UseCase/SendVaultDataChangedMessa
|
||||
import { NotifyVaultUsersOfKeyRotation } from './UseCase/NotifyVaultUsersOfKeyRotation'
|
||||
import { HandleKeyPairChange } from './../Contacts/UseCase/HandleKeyPairChange'
|
||||
import { CreateSharedVault } from './UseCase/CreateSharedVault'
|
||||
import { GetVault } from './../Vaults/UseCase/GetVault'
|
||||
import { GetVault } from './../Vault/UseCase/GetVault'
|
||||
import { SharedVaultService } from './SharedVaultService'
|
||||
import { SyncServiceInterface } from '../Sync/SyncServiceInterface'
|
||||
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
|
||||
import { SessionsClientInterface } from '../Session/SessionsClientInterface'
|
||||
import { VaultServiceInterface } from '../Vaults/VaultServiceInterface'
|
||||
import { InternalEventBusInterface } from '../..'
|
||||
import { ContactPublicKeySetInterface, TrustedContactInterface } from '@standardnotes/models'
|
||||
|
||||
describe('SharedVaultService', () => {
|
||||
@@ -30,8 +31,8 @@ describe('SharedVaultService', () => {
|
||||
|
||||
const encryption = {} as jest.Mocked<EncryptionProviderInterface>
|
||||
const session = {} as jest.Mocked<SessionsClientInterface>
|
||||
const vaults = {} as jest.Mocked<VaultServiceInterface>
|
||||
const getVault = {} as jest.Mocked<GetVault>
|
||||
const getOwnedVaults = {} as jest.Mocked<GetOwnedSharedVaults>
|
||||
const createSharedVaultUseCase = {} as jest.Mocked<CreateSharedVault>
|
||||
const handleKeyPairChange = {} as jest.Mocked<HandleKeyPairChange>
|
||||
const notifyVaultUsersOfKeyRotation = {} as jest.Mocked<NotifyVaultUsersOfKeyRotation>
|
||||
@@ -41,7 +42,8 @@ describe('SharedVaultService', () => {
|
||||
const shareContactWithVault = {} as jest.Mocked<ShareContactWithVault>
|
||||
const convertToSharedVault = {} as jest.Mocked<ConvertToSharedVault>
|
||||
const deleteSharedVaultUseCase = {} as jest.Mocked<DeleteSharedVault>
|
||||
const isVaultAdmin = {} as jest.Mocked<IsVaultAdmin>
|
||||
const isVaultAdmin = {} as jest.Mocked<IsVaultOwner>
|
||||
const discardItemsLocally = {} as jest.Mocked<DiscardItemsLocally>
|
||||
|
||||
const eventBus = {} as jest.Mocked<InternalEventBusInterface>
|
||||
eventBus.addEventHandler = jest.fn()
|
||||
@@ -50,8 +52,8 @@ describe('SharedVaultService', () => {
|
||||
items,
|
||||
encryption,
|
||||
session,
|
||||
vaults,
|
||||
getVault,
|
||||
getOwnedVaults,
|
||||
createSharedVaultUseCase,
|
||||
handleKeyPairChange,
|
||||
notifyVaultUsersOfKeyRotation,
|
||||
@@ -62,6 +64,7 @@ describe('SharedVaultService', () => {
|
||||
convertToSharedVault,
|
||||
deleteSharedVaultUseCase,
|
||||
isVaultAdmin,
|
||||
discardItemsLocally,
|
||||
eventBus,
|
||||
)
|
||||
})
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { DiscardItemsLocally } from './../UseCase/DiscardItemsLocally'
|
||||
import { UserKeyPairChangedEventData } from './../Session/UserKeyPairChangedEventData'
|
||||
import { ClientDisplayableError, UserEventType } from '@standardnotes/responses'
|
||||
import {
|
||||
@@ -18,22 +19,22 @@ import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface
|
||||
import { SyncEvent } from '../Event/SyncEvent'
|
||||
import { SessionEvent } from '../Session/SessionEvent'
|
||||
import { InternalEventInterface } from '../Internal/InternalEventInterface'
|
||||
import { VaultServiceInterface } from '../Vaults/VaultServiceInterface'
|
||||
import { UserEventServiceEvent, UserEventServiceEventPayload } from '../UserEvent/UserEventServiceEvent'
|
||||
import { DeleteThirdPartyVault } from './UseCase/DeleteExternalSharedVault'
|
||||
import { DeleteSharedVault } from './UseCase/DeleteSharedVault'
|
||||
import { VaultServiceEvent, VaultServiceEventPayload } from '../Vaults/VaultServiceEvent'
|
||||
import { VaultServiceEvent, VaultServiceEventPayload } from '../Vault/VaultServiceEvent'
|
||||
import { ShareContactWithVault } from './UseCase/ShareContactWithVault'
|
||||
import { NotifyVaultUsersOfKeyRotation } from './UseCase/NotifyVaultUsersOfKeyRotation'
|
||||
import { CreateSharedVault } from './UseCase/CreateSharedVault'
|
||||
import { SendVaultDataChangedMessage } from './UseCase/SendVaultDataChangedMessage'
|
||||
import { ConvertToSharedVault } from './UseCase/ConvertToSharedVault'
|
||||
import { GetVault } from '../Vaults/UseCase/GetVault'
|
||||
import { GetVault } from '../Vault/UseCase/GetVault'
|
||||
import { ContentType } from '@standardnotes/domain-core'
|
||||
import { HandleKeyPairChange } from '../Contacts/UseCase/HandleKeyPairChange'
|
||||
import { FindContact } from '../Contacts/UseCase/FindContact'
|
||||
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
|
||||
import { IsVaultAdmin } from '../VaultUser/UseCase/IsVaultAdmin'
|
||||
import { IsVaultOwner } from '../VaultUser/UseCase/IsVaultOwner'
|
||||
import { GetOwnedSharedVaults } from './UseCase/GetOwnedSharedVaults'
|
||||
|
||||
export class SharedVaultService
|
||||
extends AbstractService<SharedVaultServiceEvent, SharedVaultServiceEventPayload>
|
||||
@@ -43,9 +44,9 @@ export class SharedVaultService
|
||||
private items: ItemManagerInterface,
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private session: SessionsClientInterface,
|
||||
private vaults: VaultServiceInterface,
|
||||
private _getVault: GetVault,
|
||||
private _createSharedVaultUseCase: CreateSharedVault,
|
||||
private _getOwnedSharedVaults: GetOwnedSharedVaults,
|
||||
private _createSharedVault: CreateSharedVault,
|
||||
private _handleKeyPairChange: HandleKeyPairChange,
|
||||
private _notifyVaultUsersOfKeyRotation: NotifyVaultUsersOfKeyRotation,
|
||||
private _sendVaultDataChangeMessage: SendVaultDataChangedMessage,
|
||||
@@ -53,8 +54,9 @@ export class SharedVaultService
|
||||
private _deleteThirdPartyVault: DeleteThirdPartyVault,
|
||||
private _shareContactWithVault: ShareContactWithVault,
|
||||
private _convertToSharedVault: ConvertToSharedVault,
|
||||
private _deleteSharedVaultUseCase: DeleteSharedVault,
|
||||
private _isVaultAdmin: IsVaultAdmin,
|
||||
private _deleteSharedVault: DeleteSharedVault,
|
||||
private _isVaultAdmin: IsVaultOwner,
|
||||
private _discardItemsLocally: DiscardItemsLocally,
|
||||
eventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(eventBus)
|
||||
@@ -81,9 +83,8 @@ export class SharedVaultService
|
||||
;(this.items as unknown) = undefined
|
||||
;(this.encryption as unknown) = undefined
|
||||
;(this.session as unknown) = undefined
|
||||
;(this.vaults as unknown) = undefined
|
||||
;(this._getVault as unknown) = undefined
|
||||
;(this._createSharedVaultUseCase as unknown) = undefined
|
||||
;(this._createSharedVault as unknown) = undefined
|
||||
;(this._handleKeyPairChange as unknown) = undefined
|
||||
;(this._notifyVaultUsersOfKeyRotation as unknown) = undefined
|
||||
;(this._sendVaultDataChangeMessage as unknown) = undefined
|
||||
@@ -91,7 +92,7 @@ export class SharedVaultService
|
||||
;(this._deleteThirdPartyVault as unknown) = undefined
|
||||
;(this._shareContactWithVault as unknown) = undefined
|
||||
;(this._convertToSharedVault as unknown) = undefined
|
||||
;(this._deleteSharedVaultUseCase as unknown) = undefined
|
||||
;(this._deleteSharedVault as unknown) = undefined
|
||||
;(this._isVaultAdmin as unknown) = undefined
|
||||
}
|
||||
|
||||
@@ -133,7 +134,7 @@ export class SharedVaultService
|
||||
case UserEventType.SharedVaultItemRemoved: {
|
||||
const item = this.items.findItem(event.eventPayload.itemUuid)
|
||||
if (item) {
|
||||
this.items.removeItemsLocally([item])
|
||||
void this._discardItemsLocally.execute([item])
|
||||
}
|
||||
break
|
||||
}
|
||||
@@ -173,7 +174,7 @@ export class SharedVaultService
|
||||
userInputtedPassword: string | undefined
|
||||
storagePreference?: KeySystemRootKeyStorageMode
|
||||
}): Promise<VaultListingInterface | ClientDisplayableError> {
|
||||
return this._createSharedVaultUseCase.execute({
|
||||
return this._createSharedVault.execute({
|
||||
vaultName: dto.name,
|
||||
vaultDescription: dto.description,
|
||||
userInputtedPassword: dto.userInputtedPassword,
|
||||
@@ -187,11 +188,6 @@ export class SharedVaultService
|
||||
return this._convertToSharedVault.execute({ vault })
|
||||
}
|
||||
|
||||
private getAllSharedVaults(): SharedVaultListingInterface[] {
|
||||
const vaults = this.vaults.getVaults().filter((vault) => vault.isSharedVaultListing())
|
||||
return vaults as SharedVaultListingInterface[]
|
||||
}
|
||||
|
||||
private async handleTrustedContactsChange(contacts: TrustedContactInterface[]): Promise<void> {
|
||||
for (const contact of contacts) {
|
||||
if (contact.isMe) {
|
||||
@@ -220,7 +216,7 @@ export class SharedVaultService
|
||||
}
|
||||
|
||||
public async deleteSharedVault(sharedVault: SharedVaultListingInterface): Promise<ClientDisplayableError | void> {
|
||||
return this._deleteSharedVaultUseCase.execute({ sharedVault })
|
||||
return this._deleteSharedVault.execute({ sharedVault })
|
||||
}
|
||||
|
||||
async shareContactWithVaults(contact: TrustedContactInterface): Promise<void> {
|
||||
@@ -228,14 +224,7 @@ export class SharedVaultService
|
||||
throw new Error('Cannot share self contact')
|
||||
}
|
||||
|
||||
const ownedVaults = this.getAllSharedVaults().filter((vault) => {
|
||||
return this._isVaultAdmin
|
||||
.execute({
|
||||
sharedVault: vault,
|
||||
userUuid: this.session.userUuid,
|
||||
})
|
||||
.getValue()
|
||||
})
|
||||
const ownedVaults = this._getOwnedSharedVaults.execute({ userUuid: this.session.userUuid }).getValue()
|
||||
|
||||
for (const vault of ownedVaults) {
|
||||
await this._shareContactWithVault.execute({
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { GetVaultUsers } from './../../VaultUser/UseCase/GetVaultUsers'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { SharedVaultListingInterface, TrustedContactInterface } from '@standardnotes/models'
|
||||
|
||||
export class ContactBelongsToVault implements UseCaseInterface<boolean> {
|
||||
constructor(private getVaultUsers: GetVaultUsers) {}
|
||||
|
||||
async execute(dto: {
|
||||
contact: TrustedContactInterface
|
||||
vault: SharedVaultListingInterface
|
||||
}): Promise<Result<boolean>> {
|
||||
const users = await this.getVaultUsers.execute({
|
||||
sharedVaultUuid: dto.vault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
|
||||
if (users.isFailed()) {
|
||||
return Result.fail('Failed to get vault users')
|
||||
}
|
||||
|
||||
return Result.ok(users.getValue().some((u) => u.user_uuid === dto.contact.contactUuid))
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import { SharedVaultListingInterface, VaultListingInterface, VaultListingMutator
|
||||
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultServerInterface } from '@standardnotes/api'
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
import { MoveItemsToVault } from '../../Vaults/UseCase/MoveItemsToVault'
|
||||
import { MoveItemsToVault } from '../../Vault/UseCase/MoveItemsToVault'
|
||||
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
|
||||
|
||||
export class ConvertToSharedVault {
|
||||
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultServerInterface } from '@standardnotes/api'
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
import { CreateVault } from '../../Vaults/UseCase/CreateVault'
|
||||
import { MoveItemsToVault } from '../../Vaults/UseCase/MoveItemsToVault'
|
||||
import { CreateVault } from '../../Vault/UseCase/CreateVault'
|
||||
import { MoveItemsToVault } from '../../Vault/UseCase/MoveItemsToVault'
|
||||
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
|
||||
|
||||
export class CreateSharedVault {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { SyncServiceInterface } from './../../Sync/SyncServiceInterface'
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
import { AnyItemInterface, VaultListingInterface } from '@standardnotes/models'
|
||||
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
|
||||
import { RemoveItemsLocally } from '../../UseCase/RemoveItemsLocally'
|
||||
import { DiscardItemsLocally } from '../../UseCase/DiscardItemsLocally'
|
||||
import { KeySystemKeyManagerInterface } from '../../KeySystem/KeySystemKeyManagerInterface'
|
||||
|
||||
export class DeleteThirdPartyVault {
|
||||
@@ -11,7 +11,7 @@ export class DeleteThirdPartyVault {
|
||||
private mutator: MutatorClientInterface,
|
||||
private keys: KeySystemKeyManagerInterface,
|
||||
private sync: SyncServiceInterface,
|
||||
private removeItemsLocally: RemoveItemsLocally,
|
||||
private _discardItemsLocally: DiscardItemsLocally,
|
||||
) {}
|
||||
|
||||
async execute(vault: VaultListingInterface): Promise<void> {
|
||||
@@ -33,7 +33,7 @@ export class DeleteThirdPartyVault {
|
||||
|
||||
const itemsKeys = this.keys.getKeySystemItemsKeys(vault.systemIdentifier)
|
||||
|
||||
await this.removeItemsLocally.execute([...vaultItems, ...itemsKeys])
|
||||
await this._discardItemsLocally.execute([...vaultItems, ...itemsKeys])
|
||||
}
|
||||
|
||||
private async deleteDataOwnedByThisUser(vault: VaultListingInterface): Promise<void> {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { ClientDisplayableError, isErrorResponse } from '@standardnotes/response
|
||||
import { SharedVaultServerInterface } from '@standardnotes/api'
|
||||
import { SharedVaultListingInterface } from '@standardnotes/models'
|
||||
import { SyncServiceInterface } from '../../Sync/SyncServiceInterface'
|
||||
import { DeleteVault } from '../../Vaults/UseCase/DeleteVault'
|
||||
import { DeleteVault } from '../../Vault/UseCase/DeleteVault'
|
||||
|
||||
export class DeleteSharedVault {
|
||||
constructor(
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { IsVaultOwner } from './../../VaultUser/UseCase/IsVaultOwner'
|
||||
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { SharedVaultListingInterface } from '@standardnotes/models'
|
||||
import { GetSharedVaults } from './GetSharedVaults'
|
||||
|
||||
export class GetOwnedSharedVaults implements SyncUseCaseInterface<SharedVaultListingInterface[]> {
|
||||
constructor(private getSharedVaults: GetSharedVaults, private isVaultOwnwer: IsVaultOwner) {}
|
||||
|
||||
execute(dto: { userUuid: string }): Result<SharedVaultListingInterface[]> {
|
||||
const sharedVaults = this.getSharedVaults.execute().getValue()
|
||||
|
||||
const ownedVaults = sharedVaults.filter((vault) => {
|
||||
return this.isVaultOwnwer
|
||||
.execute({
|
||||
sharedVault: vault,
|
||||
userUuid: dto.userUuid,
|
||||
})
|
||||
.getValue()
|
||||
})
|
||||
|
||||
return Result.ok(ownedVaults)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { GetVaults } from '../../Vault/UseCase/GetVaults'
|
||||
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { SharedVaultListingInterface } from '@standardnotes/models'
|
||||
|
||||
export class GetSharedVaults implements SyncUseCaseInterface<SharedVaultListingInterface[]> {
|
||||
constructor(private getVaults: GetVaults) {}
|
||||
|
||||
execute(): Result<SharedVaultListingInterface[]> {
|
||||
const vaults = this.getVaults
|
||||
.execute()
|
||||
.getValue()
|
||||
.filter((vault) => vault.isSharedVaultListing())
|
||||
|
||||
return Result.ok(vaults as SharedVaultListingInterface[])
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,10 @@ export class NotifyVaultUsersOfKeyRotation implements UseCaseInterface<void> {
|
||||
|
||||
await this.deleteAllInvites(params.sharedVault.sharing.sharedVaultUuid)
|
||||
|
||||
const contacts = await this.getVaultContacts.execute(params.sharedVault.sharing.sharedVaultUuid)
|
||||
const contacts = await this.getVaultContacts.execute({
|
||||
sharedVaultUuid: params.sharedVault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
|
||||
for (const invite of existingInvites.getValue()) {
|
||||
const recipient = this.findContact.execute({ userUuid: invite.user_uuid })
|
||||
|
||||
@@ -29,13 +29,16 @@ export class SendVaultDataChangedMessage implements UseCaseInterface<void> {
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
}): Promise<Result<void>> {
|
||||
const users = await this.getVaultUsers.execute({ sharedVaultUuid: params.vault.sharing.sharedVaultUuid })
|
||||
if (!users) {
|
||||
const users = await this.getVaultUsers.execute({
|
||||
sharedVaultUuid: params.vault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
if (users.isFailed()) {
|
||||
return Result.fail('Cannot send metadata changed message; users not found')
|
||||
}
|
||||
|
||||
const errors: string[] = []
|
||||
for (const user of users) {
|
||||
for (const user of users.getValue()) {
|
||||
if (user.user_uuid === params.senderUuid) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -32,14 +32,14 @@ export class SendVaultKeyChangedMessage implements UseCaseInterface<void> {
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
}): Promise<Result<void>> {
|
||||
const users = await this.getVaultUsers.execute({ sharedVaultUuid: params.sharedVaultUuid })
|
||||
if (!users) {
|
||||
const users = await this.getVaultUsers.execute({ sharedVaultUuid: params.sharedVaultUuid, readFromCache: false })
|
||||
if (users.isFailed()) {
|
||||
return Result.fail('Cannot send root key changed message; users not found')
|
||||
}
|
||||
|
||||
const errors: string[] = []
|
||||
|
||||
for (const user of users) {
|
||||
for (const user of users.getValue()) {
|
||||
if (user.user_uuid === params.senderUuid) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -33,17 +33,18 @@ export class ShareContactWithVault implements UseCaseInterface<void> {
|
||||
|
||||
const users = await this.getVaultUsers.execute({
|
||||
sharedVaultUuid: params.sharedVault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
|
||||
if (!users) {
|
||||
if (users.isFailed()) {
|
||||
return Result.fail('Cannot share contact; shared vault users not found')
|
||||
}
|
||||
|
||||
if (users.length === 0) {
|
||||
if (users.getValue().length === 0) {
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
for (const vaultUser of users) {
|
||||
for (const vaultUser of users.getValue()) {
|
||||
if (vaultUser.user_uuid === params.senderUserUuid) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -14,14 +14,17 @@ export interface StorageServiceInterface {
|
||||
getAllKeys(mode?: StorageValueModes): string[]
|
||||
getValue<T>(key: string, mode?: StorageValueModes, defaultValue?: T): T
|
||||
canDecryptWithKey(key: RootKeyInterface): Promise<boolean>
|
||||
savePayload(payload: PayloadInterface): Promise<void>
|
||||
savePayloads(decryptedPayloads: PayloadInterface[]): Promise<void>
|
||||
setValue<T>(key: string, value: T, mode?: StorageValueModes): void
|
||||
removeValue(key: string, mode?: StorageValueModes): Promise<void>
|
||||
setPersistencePolicy(persistencePolicy: StoragePersistencePolicies): Promise<void>
|
||||
clearAllData(): Promise<void>
|
||||
|
||||
getRawPayloads(uuids: string[]): Promise<FullyFormedTransferPayload[]>
|
||||
savePayload(payload: PayloadInterface): Promise<void>
|
||||
savePayloads(decryptedPayloads: PayloadInterface[]): Promise<void>
|
||||
deletePayloads(payloads: FullyFormedPayloadInterface[]): Promise<void>
|
||||
deletePayloadsWithUuids(uuids: string[]): Promise<void>
|
||||
|
||||
clearAllPayloads(): Promise<void>
|
||||
isEphemeralSession(): boolean
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import { RemoveItemsFromMemory } from './RemoveItemsFromMemory'
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
import { StorageServiceInterface } from '../StorageServiceInterface'
|
||||
import { PayloadManagerInterface } from '../../Payloads/PayloadManagerInterface'
|
||||
import { PayloadEmitSource, DecryptedItemInterface } from '@standardnotes/models'
|
||||
import { Uuids } from '@standardnotes/utils'
|
||||
|
||||
describe('RemoveItemsFromMemory', () => {
|
||||
let storage: StorageServiceInterface
|
||||
let items: ItemManagerInterface
|
||||
let payloads: PayloadManagerInterface
|
||||
let removeItemsFromMemory: RemoveItemsFromMemory
|
||||
|
||||
beforeEach(() => {
|
||||
storage = {
|
||||
getRawPayloads: jest.fn().mockImplementation(() => Promise.resolve([])),
|
||||
} as unknown as StorageServiceInterface
|
||||
|
||||
items = {
|
||||
removeItemsFromMemory: jest.fn(),
|
||||
} as unknown as ItemManagerInterface
|
||||
|
||||
payloads = {
|
||||
emitPayloads: jest.fn().mockImplementation(() => Promise.resolve()),
|
||||
} as unknown as PayloadManagerInterface
|
||||
|
||||
removeItemsFromMemory = new RemoveItemsFromMemory(storage, items, payloads)
|
||||
})
|
||||
|
||||
it('should execute removeItemsFromMemory use case correctly', async () => {
|
||||
const testItems: DecryptedItemInterface[] = [
|
||||
<DecryptedItemInterface>{
|
||||
uuid: 'uuid1',
|
||||
content_type: 'type1',
|
||||
},
|
||||
<DecryptedItemInterface>{
|
||||
uuid: 'uuid2',
|
||||
content_type: 'type2',
|
||||
},
|
||||
]
|
||||
|
||||
await removeItemsFromMemory.execute(testItems)
|
||||
|
||||
expect(items.removeItemsFromMemory).toHaveBeenCalledWith(testItems)
|
||||
expect(storage.getRawPayloads).toHaveBeenCalledWith(Uuids(testItems))
|
||||
expect(payloads.emitPayloads).toHaveBeenCalledWith([], PayloadEmitSource.LocalDatabaseLoaded)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,26 @@
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { StorageServiceInterface } from '../StorageServiceInterface'
|
||||
import { CreatePayload, DecryptedItemInterface, PayloadEmitSource, PayloadSource } from '@standardnotes/models'
|
||||
import { Uuids } from '@standardnotes/utils'
|
||||
import { PayloadManagerInterface } from '../../Payloads/PayloadManagerInterface'
|
||||
|
||||
export class RemoveItemsFromMemory implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private storage: StorageServiceInterface,
|
||||
private items: ItemManagerInterface,
|
||||
private payloads: PayloadManagerInterface,
|
||||
) {}
|
||||
|
||||
async execute(items: DecryptedItemInterface[]): Promise<Result<void>> {
|
||||
this.items.removeItemsFromMemory(items)
|
||||
|
||||
const rawPayloads = await this.storage.getRawPayloads(Uuids(items))
|
||||
|
||||
const encryptedPayloads = rawPayloads.map((payload) => CreatePayload(payload, PayloadSource.LocalDatabaseLoaded))
|
||||
|
||||
await this.payloads.emitPayloads(encryptedPayloads, PayloadEmitSource.LocalDatabaseLoaded)
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -3,11 +3,11 @@ import { ItemManagerInterface } from '../Item/ItemManagerInterface'
|
||||
import { AnyItemInterface } from '@standardnotes/models'
|
||||
import { Uuids } from '@standardnotes/utils'
|
||||
|
||||
export class RemoveItemsLocally {
|
||||
export class DiscardItemsLocally {
|
||||
constructor(private readonly items: ItemManagerInterface, private readonly storage: StorageServiceInterface) {}
|
||||
|
||||
async execute(items: AnyItemInterface[]): Promise<void> {
|
||||
this.items.removeItemsLocally(items)
|
||||
this.items.removeItemsFromMemory(items)
|
||||
|
||||
await this.storage.deletePayloadsWithUuids(Uuids(items))
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
import { MutatorClientInterface, SyncServiceInterface } from '@standardnotes/services'
|
||||
import {
|
||||
KeySystemPasswordType,
|
||||
KeySystemRootKeyStorageMode,
|
||||
VaultListingInterface,
|
||||
VaultListingMutator,
|
||||
} from '@standardnotes/models'
|
||||
import { ChangeVaultKeyOptionsDTO } from './ChangeVaultKeyOptionsDTO'
|
||||
import { GetVault } from './GetVault'
|
||||
import { EncryptionProviderInterface } from '../../Encryption/EncryptionProviderInterface'
|
||||
import { KeySystemKeyManagerInterface } from '../../KeySystem/KeySystemKeyManagerInterface'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class ChangeVaultKeyOptions implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private mutator: MutatorClientInterface,
|
||||
private sync: SyncServiceInterface,
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private keys: KeySystemKeyManagerInterface,
|
||||
private getVault: GetVault,
|
||||
) {}
|
||||
|
||||
async execute(dto: ChangeVaultKeyOptionsDTO): Promise<Result<void>> {
|
||||
if (dto.newPasswordType) {
|
||||
const result = await this.handleNewPasswordType(dto)
|
||||
if (result.isFailed()) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
if (dto.newStorageMode) {
|
||||
const result = await this.handleNewStorageMode(dto)
|
||||
if (result.isFailed()) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
await this.sync.sync()
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async handleNewPasswordType(dto: ChangeVaultKeyOptionsDTO): Promise<Result<void>> {
|
||||
if (!dto.newPasswordType) {
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
if (dto.vault.keyPasswordType === dto.newPasswordType.passwordType) {
|
||||
return Result.fail('Vault password type is already set to this type')
|
||||
}
|
||||
|
||||
if (dto.newPasswordType.passwordType === KeySystemPasswordType.UserInputted) {
|
||||
if (!dto.newPasswordType.userInputtedPassword) {
|
||||
return Result.fail('User inputted password is required')
|
||||
}
|
||||
const useStorageMode = dto.newStorageMode ?? dto.vault.keyStorageMode
|
||||
const result = await this.changePasswordTypeToUserInputted(
|
||||
dto.vault,
|
||||
dto.newPasswordType.userInputtedPassword,
|
||||
useStorageMode,
|
||||
)
|
||||
if (result.isFailed()) {
|
||||
return result
|
||||
}
|
||||
} else if (dto.newPasswordType.passwordType === KeySystemPasswordType.Randomized) {
|
||||
const result = await this.changePasswordTypeToRandomized(dto.vault)
|
||||
if (result.isFailed()) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async handleNewStorageMode(dto: ChangeVaultKeyOptionsDTO): Promise<Result<void>> {
|
||||
if (!dto.newStorageMode) {
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
const result = this.getVault.execute({ keySystemIdentifier: dto.vault.systemIdentifier })
|
||||
if (result.isFailed()) {
|
||||
return Result.fail('Vault not found')
|
||||
}
|
||||
|
||||
const latestVault = result.getValue()
|
||||
|
||||
if (latestVault.rootKeyParams.passwordType !== KeySystemPasswordType.UserInputted) {
|
||||
return Result.fail('Vault uses randomized password and cannot change its storage preference')
|
||||
}
|
||||
|
||||
if (dto.newStorageMode === latestVault.keyStorageMode) {
|
||||
return Result.fail('Vault already uses this storage preference')
|
||||
}
|
||||
|
||||
if (
|
||||
dto.newStorageMode === KeySystemRootKeyStorageMode.Local ||
|
||||
dto.newStorageMode === KeySystemRootKeyStorageMode.Ephemeral
|
||||
) {
|
||||
const result = await this.changeStorageModeToLocalOrEphemeral(latestVault, dto.newStorageMode)
|
||||
if (result.isFailed()) {
|
||||
return result
|
||||
}
|
||||
} else if (dto.newStorageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
const result = await this.changeStorageModeToSynced(latestVault)
|
||||
if (result.isFailed()) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async changePasswordTypeToUserInputted(
|
||||
vault: VaultListingInterface,
|
||||
userInputtedPassword: string,
|
||||
storageMode: KeySystemRootKeyStorageMode,
|
||||
): Promise<Result<void>> {
|
||||
const newRootKey = this.encryption.createUserInputtedKeySystemRootKey({
|
||||
systemIdentifier: vault.systemIdentifier,
|
||||
userInputtedPassword: userInputtedPassword,
|
||||
})
|
||||
|
||||
if (storageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
await this.mutator.insertItem(newRootKey, true)
|
||||
} else {
|
||||
this.keys.cacheKey(newRootKey, storageMode)
|
||||
}
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.rootKeyParams = newRootKey.keyParams
|
||||
})
|
||||
|
||||
await this.keys.queueVaultItemsKeysForReencryption(vault.systemIdentifier)
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async changePasswordTypeToRandomized(vault: VaultListingInterface): Promise<Result<void>> {
|
||||
if (vault.keyStorageMode !== KeySystemRootKeyStorageMode.Synced) {
|
||||
this.keys.removeKeyFromCache(vault.systemIdentifier)
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.keyStorageMode = KeySystemRootKeyStorageMode.Synced
|
||||
})
|
||||
}
|
||||
|
||||
const newRootKey = this.encryption.createRandomizedKeySystemRootKey({
|
||||
systemIdentifier: vault.systemIdentifier,
|
||||
})
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.rootKeyParams = newRootKey.keyParams
|
||||
})
|
||||
|
||||
await this.mutator.insertItem(newRootKey, true)
|
||||
|
||||
await this.keys.queueVaultItemsKeysForReencryption(vault.systemIdentifier)
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async changeStorageModeToLocalOrEphemeral(
|
||||
vault: VaultListingInterface,
|
||||
newStorageMode: KeySystemRootKeyStorageMode,
|
||||
): Promise<Result<void>> {
|
||||
const primaryKey = this.keys.getPrimaryKeySystemRootKey(vault.systemIdentifier)
|
||||
if (!primaryKey) {
|
||||
return Result.fail('No primary key found')
|
||||
}
|
||||
|
||||
if (newStorageMode === KeySystemRootKeyStorageMode.Ephemeral) {
|
||||
this.keys.removeKeyFromCache(vault.systemIdentifier)
|
||||
}
|
||||
|
||||
this.keys.cacheKey(primaryKey, newStorageMode)
|
||||
await this.keys.deleteAllSyncedKeySystemRootKeys(vault.systemIdentifier)
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.keyStorageMode = newStorageMode
|
||||
})
|
||||
|
||||
await this.sync.sync()
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async changeStorageModeToSynced(vault: VaultListingInterface): Promise<Result<void>> {
|
||||
const allRootKeys = this.keys.getAllKeySystemRootKeysForVault(vault.systemIdentifier)
|
||||
const syncedRootKeys = this.keys.getSyncedKeySystemRootKeysForVault(vault.systemIdentifier)
|
||||
|
||||
this.keys.removeKeyFromCache(vault.systemIdentifier)
|
||||
|
||||
for (const key of allRootKeys) {
|
||||
const existingSyncedKey = syncedRootKeys.find((syncedKey) => syncedKey.token === key.token)
|
||||
if (existingSyncedKey) {
|
||||
continue
|
||||
}
|
||||
|
||||
await this.mutator.insertItem(key)
|
||||
}
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.keyStorageMode = KeySystemRootKeyStorageMode.Synced
|
||||
})
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { KeySystemPasswordType, KeySystemRootKeyStorageMode, VaultListingInterface } from '@standardnotes/models'
|
||||
|
||||
export type ChangeVaultKeyOptionsDTO = {
|
||||
vault: VaultListingInterface
|
||||
newPasswordType:
|
||||
| { passwordType: KeySystemPasswordType.Randomized }
|
||||
| { passwordType: KeySystemPasswordType.UserInputted; userInputtedPassword: string }
|
||||
| undefined
|
||||
newStorageMode: KeySystemRootKeyStorageMode | undefined
|
||||
}
|
||||
+5
-7
@@ -1,8 +1,8 @@
|
||||
import { SyncServiceInterface } from './../../Sync/SyncServiceInterface'
|
||||
import { SyncServiceInterface } from '../../Sync/SyncServiceInterface'
|
||||
import { UuidGenerator } from '@standardnotes/utils'
|
||||
import {
|
||||
KeySystemRootKeyParamsInterface,
|
||||
KeySystemRootKeyPasswordType,
|
||||
KeySystemPasswordType,
|
||||
VaultListingContentSpecialized,
|
||||
VaultListingInterface,
|
||||
KeySystemRootKeyStorageMode,
|
||||
@@ -44,9 +44,7 @@ export class CreateVault {
|
||||
keySystemIdentifier,
|
||||
vaultName: dto.vaultName,
|
||||
vaultDescription: dto.vaultDescription,
|
||||
passwordType: dto.userInputtedPassword
|
||||
? KeySystemRootKeyPasswordType.UserInputted
|
||||
: KeySystemRootKeyPasswordType.Randomized,
|
||||
passwordType: dto.userInputtedPassword ? KeySystemPasswordType.UserInputted : KeySystemPasswordType.Randomized,
|
||||
rootKeyParams: rootKey.keyParams,
|
||||
storage: dto.storagePreference,
|
||||
})
|
||||
@@ -60,7 +58,7 @@ export class CreateVault {
|
||||
keySystemIdentifier: string
|
||||
vaultName: string
|
||||
vaultDescription?: string
|
||||
passwordType: KeySystemRootKeyPasswordType
|
||||
passwordType: KeySystemPasswordType
|
||||
rootKeyParams: KeySystemRootKeyParamsInterface
|
||||
storage: KeySystemRootKeyStorageMode
|
||||
}): Promise<VaultListingInterface> {
|
||||
@@ -109,7 +107,7 @@ export class CreateVault {
|
||||
if (dto.storagePreference === KeySystemRootKeyStorageMode.Synced) {
|
||||
await this.mutator.insertItem(newRootKey, true)
|
||||
} else {
|
||||
this.keys.intakeNonPersistentKeySystemRootKey(newRootKey, dto.storagePreference)
|
||||
this.keys.cacheKey(newRootKey, dto.storagePreference)
|
||||
}
|
||||
|
||||
return newRootKey
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
import { VaultListingInterface } from '@standardnotes/models'
|
||||
import { ItemManagerInterface } from './../../Item/ItemManagerInterface'
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
import { ContentType, Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class GetVault implements SyncUseCaseInterface<VaultListingInterface> {
|
||||
@@ -20,7 +20,7 @@ export class GetVault implements SyncUseCaseInterface<VaultListingInterface> {
|
||||
} else {
|
||||
const result = vaults.find((listing) => listing.sharing?.sharedVaultUuid === query.sharedVaultUuid) as T
|
||||
if (!result) {
|
||||
return Result.fail('Vault not found')
|
||||
return Result.fail('Shared vault not found')
|
||||
}
|
||||
|
||||
return Result.ok(result)
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ContentType, Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { VaultListingInterface } from '@standardnotes/models'
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
|
||||
export class GetVaults implements SyncUseCaseInterface<VaultListingInterface[]> {
|
||||
constructor(private items: ItemManagerInterface) {}
|
||||
|
||||
execute(): Result<VaultListingInterface[]> {
|
||||
const vaults = this.items.getItems<VaultListingInterface>(ContentType.TYPES.VaultListing).sort((a, b) => {
|
||||
return a.name.localeCompare(b.name)
|
||||
})
|
||||
|
||||
return Result.ok(vaults)
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -3,7 +3,7 @@ import { ClientDisplayableError, isClientDisplayableError } from '@standardnotes
|
||||
import {
|
||||
KeySystemIdentifier,
|
||||
KeySystemRootKeyInterface,
|
||||
KeySystemRootKeyPasswordType,
|
||||
KeySystemPasswordType,
|
||||
KeySystemRootKeyStorageMode,
|
||||
VaultListingInterface,
|
||||
VaultListingMutator,
|
||||
@@ -31,7 +31,7 @@ export class RotateVaultKey {
|
||||
|
||||
let newRootKey: KeySystemRootKeyInterface | undefined
|
||||
|
||||
if (currentRootKey.keyParams.passwordType === KeySystemRootKeyPasswordType.UserInputted) {
|
||||
if (currentRootKey.keyParams.passwordType === KeySystemPasswordType.UserInputted) {
|
||||
if (!params.userInputtedPassword) {
|
||||
throw new Error('Cannot rotate key system root key; user inputted password required')
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export class RotateVaultKey {
|
||||
systemIdentifier: params.vault.systemIdentifier,
|
||||
userInputtedPassword: params.userInputtedPassword,
|
||||
})
|
||||
} else if (currentRootKey.keyParams.passwordType === KeySystemRootKeyPasswordType.Randomized) {
|
||||
} else if (currentRootKey.keyParams.passwordType === KeySystemPasswordType.Randomized) {
|
||||
newRootKey = this.encryption.createRandomizedKeySystemRootKey({
|
||||
systemIdentifier: params.vault.systemIdentifier,
|
||||
})
|
||||
@@ -53,7 +53,7 @@ export class RotateVaultKey {
|
||||
if (params.vault.keyStorageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
await this.mutator.insertItem(newRootKey, true)
|
||||
} else {
|
||||
this.keys.intakeNonPersistentKeySystemRootKey(newRootKey, params.vault.keyStorageMode)
|
||||
this.keys.cacheKey(newRootKey, params.vault.keyStorageMode)
|
||||
}
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(params.vault, (mutator) => {
|
||||
@@ -73,7 +73,7 @@ export class RotateVaultKey {
|
||||
errors.push(updateKeySystemItemsKeyResult)
|
||||
}
|
||||
|
||||
await this.keys.reencryptKeySystemItemsKeysForVault(params.vault.systemIdentifier)
|
||||
await this.keys.queueVaultItemsKeysForReencryption(params.vault.systemIdentifier)
|
||||
|
||||
return errors
|
||||
}
|
||||
+38
-134
@@ -3,14 +3,13 @@ import {
|
||||
DecryptedItemInterface,
|
||||
FileItem,
|
||||
KeySystemIdentifier,
|
||||
KeySystemRootKeyPasswordType,
|
||||
KeySystemRootKeyStorageMode,
|
||||
VaultListingInterface,
|
||||
VaultListingMutator,
|
||||
isNote,
|
||||
} from '@standardnotes/models'
|
||||
import { VaultServiceInterface } from './VaultServiceInterface'
|
||||
import { ChangeVaultOptionsDTO } from './ChangeVaultOptionsDTO'
|
||||
import { ChangeVaultKeyOptionsDTO } from './UseCase/ChangeVaultKeyOptionsDTO'
|
||||
import { VaultServiceEvent, VaultServiceEventPayload } from './VaultServiceEvent'
|
||||
import { CreateVault } from './UseCase/CreateVault'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
@@ -25,51 +24,52 @@ import { GetVault } from './UseCase/GetVault'
|
||||
import { ChangeVaultKeyOptions } from './UseCase/ChangeVaultKeyOptions'
|
||||
import { MutatorClientInterface } from '../Mutator/MutatorClientInterface'
|
||||
import { AlertService } from '../Alert/AlertService'
|
||||
import { ContentType } from '@standardnotes/domain-core'
|
||||
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
|
||||
import { KeySystemKeyManagerInterface } from '../KeySystem/KeySystemKeyManagerInterface'
|
||||
import { GetVaults } from './UseCase/GetVaults'
|
||||
import { VaultLockServiceInterface } from '../VaultLock/VaultLockServiceInterface'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
|
||||
export class VaultService
|
||||
extends AbstractService<VaultServiceEvent, VaultServiceEventPayload[VaultServiceEvent]>
|
||||
implements VaultServiceInterface
|
||||
{
|
||||
private lockMap = new Map<VaultListingInterface['uuid'], boolean>()
|
||||
|
||||
constructor(
|
||||
private sync: SyncServiceInterface,
|
||||
private items: ItemManagerInterface,
|
||||
private mutator: MutatorClientInterface,
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private keys: KeySystemKeyManagerInterface,
|
||||
private vaultLocks: VaultLockServiceInterface,
|
||||
private alerts: AlertService,
|
||||
private _getVault: GetVault,
|
||||
private _getVaults: GetVaults,
|
||||
private _changeVaultKeyOptions: ChangeVaultKeyOptions,
|
||||
private _moveItemsToVault: MoveItemsToVault,
|
||||
private _createVault: CreateVault,
|
||||
private _removeItemFromVaultUseCase: RemoveItemFromVault,
|
||||
private _deleteVaultUseCase: DeleteVault,
|
||||
private _removeItemFromVault: RemoveItemFromVault,
|
||||
private _deleteVault: DeleteVault,
|
||||
private _rotateVaultKey: RotateVaultKey,
|
||||
eventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(eventBus)
|
||||
}
|
||||
|
||||
items.addObserver(
|
||||
[ContentType.TYPES.KeySystemItemsKey, ContentType.TYPES.KeySystemRootKey, ContentType.TYPES.VaultListing],
|
||||
() => {
|
||||
void this.recomputeAllVaultsLockingState()
|
||||
},
|
||||
)
|
||||
override deinit(): void {
|
||||
super.deinit()
|
||||
;(this.sync as unknown) = undefined
|
||||
;(this.items as unknown) = undefined
|
||||
;(this.mutator as unknown) = undefined
|
||||
;(this.vaultLocks as unknown) = undefined
|
||||
;(this.alerts as unknown) = undefined
|
||||
;(this._getVault as unknown) = undefined
|
||||
;(this._getVaults as unknown) = undefined
|
||||
;(this._changeVaultKeyOptions as unknown) = undefined
|
||||
;(this._moveItemsToVault as unknown) = undefined
|
||||
;(this._createVault as unknown) = undefined
|
||||
;(this._removeItemFromVault as unknown) = undefined
|
||||
;(this._deleteVault as unknown) = undefined
|
||||
;(this._rotateVaultKey as unknown) = undefined
|
||||
}
|
||||
|
||||
getVaults(): VaultListingInterface[] {
|
||||
return this.items.getItems<VaultListingInterface>(ContentType.TYPES.VaultListing).sort((a, b) => {
|
||||
return a.name.localeCompare(b.name)
|
||||
})
|
||||
}
|
||||
|
||||
getLockedvaults(): VaultListingInterface[] {
|
||||
const vaults = this.getVaults()
|
||||
return vaults.filter((vault) => this.isVaultLocked(vault))
|
||||
return this._getVaults.execute().getValue()
|
||||
}
|
||||
|
||||
public getVault(dto: { keySystemIdentifier: KeySystemIdentifier }): VaultListingInterface | undefined {
|
||||
@@ -90,16 +90,12 @@ export class VaultService
|
||||
return vault
|
||||
}
|
||||
|
||||
async createRandomizedVault(dto: {
|
||||
name: string
|
||||
description?: string
|
||||
storagePreference: KeySystemRootKeyStorageMode
|
||||
}): Promise<VaultListingInterface> {
|
||||
async createRandomizedVault(dto: { name: string; description?: string }): Promise<VaultListingInterface> {
|
||||
return this.createVaultWithParameters({
|
||||
name: dto.name,
|
||||
description: dto.description,
|
||||
userInputtedPassword: undefined,
|
||||
storagePreference: dto.storagePreference,
|
||||
storagePreference: KeySystemRootKeyStorageMode.Synced,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -132,7 +128,7 @@ export class VaultService
|
||||
vault: VaultListingInterface,
|
||||
item: DecryptedItemInterface,
|
||||
): Promise<DecryptedItemInterface | undefined> {
|
||||
if (this.isVaultLocked(vault)) {
|
||||
if (this.vaultLocks.isVaultLocked(vault)) {
|
||||
throw new Error('Attempting to add item to locked vault')
|
||||
}
|
||||
|
||||
@@ -162,11 +158,11 @@ export class VaultService
|
||||
throw new Error('Cannot find vault to remove item from')
|
||||
}
|
||||
|
||||
if (this.isVaultLocked(vault)) {
|
||||
if (this.vaultLocks.isVaultLocked(vault)) {
|
||||
throw new Error('Attempting to remove item from locked vault')
|
||||
}
|
||||
|
||||
await this._removeItemFromVaultUseCase.execute({ item })
|
||||
await this._removeItemFromVault.execute({ item })
|
||||
return this.items.findSureItem(item.uuid)
|
||||
}
|
||||
|
||||
@@ -175,7 +171,7 @@ export class VaultService
|
||||
throw new Error('Shared vault must be deleted through SharedVaultService')
|
||||
}
|
||||
|
||||
const error = await this._deleteVaultUseCase.execute(vault)
|
||||
const error = await this._deleteVault.execute(vault)
|
||||
|
||||
if (isClientDisplayableError(error)) {
|
||||
return false
|
||||
@@ -199,15 +195,15 @@ export class VaultService
|
||||
return updatedVault
|
||||
}
|
||||
|
||||
async rotateVaultRootKey(vault: VaultListingInterface): Promise<void> {
|
||||
if (this.computeVaultLockState(vault) === 'locked') {
|
||||
async rotateVaultRootKey(vault: VaultListingInterface, vaultPassword?: string): Promise<void> {
|
||||
if (this.vaultLocks.isVaultLocked(vault)) {
|
||||
throw new Error('Cannot rotate root key of locked vault')
|
||||
}
|
||||
|
||||
await this._rotateVaultKey.execute({
|
||||
vault,
|
||||
sharedVaultUuid: vault.isSharedVaultListing() ? vault.sharing.sharedVaultUuid : undefined,
|
||||
userInputtedPassword: undefined,
|
||||
userInputtedPassword: vaultPassword,
|
||||
})
|
||||
|
||||
await this.notifyEventSync(VaultServiceEvent.VaultRootKeyRotated, { vault })
|
||||
@@ -232,109 +228,17 @@ export class VaultService
|
||||
return this.getVault({ keySystemIdentifier: latestItem.key_system_identifier })
|
||||
}
|
||||
|
||||
async changeVaultOptions(dto: ChangeVaultOptionsDTO): Promise<void> {
|
||||
if (this.isVaultLocked(dto.vault)) {
|
||||
async changeVaultOptions(dto: ChangeVaultKeyOptionsDTO): Promise<Result<void>> {
|
||||
if (this.vaultLocks.isVaultLocked(dto.vault)) {
|
||||
throw new Error('Attempting to change vault options on a locked vault')
|
||||
}
|
||||
|
||||
await this._changeVaultKeyOptions.execute(dto)
|
||||
const result = await this._changeVaultKeyOptions.execute(dto)
|
||||
|
||||
if (dto.newPasswordType) {
|
||||
await this.notifyEventSync(VaultServiceEvent.VaultRootKeyRotated, { vault: dto.vault })
|
||||
}
|
||||
}
|
||||
|
||||
public isVaultLocked(vault: VaultListingInterface): boolean {
|
||||
return this.lockMap.get(vault.uuid) === true
|
||||
}
|
||||
|
||||
public async lockNonPersistentVault(vault: VaultListingInterface): Promise<void> {
|
||||
if (vault.keyStorageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
throw new Error('Vault uses synced root key and cannot be locked')
|
||||
}
|
||||
|
||||
this.keys.clearMemoryOfKeysRelatedToVault(vault)
|
||||
|
||||
this.lockMap.set(vault.uuid, true)
|
||||
void this.notifyEventSync(VaultServiceEvent.VaultLocked, { vault })
|
||||
}
|
||||
|
||||
public async unlockNonPersistentVault(vault: VaultListingInterface, password: string): Promise<boolean> {
|
||||
if (vault.keyPasswordType !== KeySystemRootKeyPasswordType.UserInputted) {
|
||||
throw new Error('Vault uses randomized password and cannot be unlocked with user inputted password')
|
||||
}
|
||||
|
||||
if (vault.keyStorageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
throw new Error('Vault uses synced root key and cannot be unlocked with user inputted password')
|
||||
}
|
||||
|
||||
const derivedRootKey = this.encryption.deriveUserInputtedKeySystemRootKey({
|
||||
keyParams: vault.rootKeyParams,
|
||||
userInputtedPassword: password,
|
||||
})
|
||||
|
||||
this.keys.intakeNonPersistentKeySystemRootKey(derivedRootKey, vault.keyStorageMode)
|
||||
|
||||
await this.encryption.decryptErroredPayloads()
|
||||
|
||||
if (this.computeVaultLockState(vault) === 'locked') {
|
||||
this.keys.undoIntakeNonPersistentKeySystemRootKey(vault.systemIdentifier)
|
||||
return false
|
||||
}
|
||||
|
||||
this.lockMap.set(vault.uuid, false)
|
||||
void this.notifyEventSync(VaultServiceEvent.VaultUnlocked, { vault })
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private recomputeAllVaultsLockingState = async (): Promise<void> => {
|
||||
const vaults = this.getVaults()
|
||||
|
||||
for (const vault of vaults) {
|
||||
const locked = this.computeVaultLockState(vault) === 'locked'
|
||||
|
||||
if (this.lockMap.get(vault.uuid) !== locked) {
|
||||
this.lockMap.set(vault.uuid, locked)
|
||||
|
||||
if (locked) {
|
||||
void this.notifyEvent(VaultServiceEvent.VaultLocked, { vault })
|
||||
} else {
|
||||
void this.notifyEvent(VaultServiceEvent.VaultUnlocked, { vault })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private computeVaultLockState(vault: VaultListingInterface): 'locked' | 'unlocked' {
|
||||
const rootKey = this.keys.getPrimaryKeySystemRootKey(vault.systemIdentifier)
|
||||
if (!rootKey) {
|
||||
return 'locked'
|
||||
}
|
||||
|
||||
const itemsKey = this.keys.getPrimaryKeySystemItemsKey(vault.systemIdentifier)
|
||||
if (!itemsKey) {
|
||||
return 'locked'
|
||||
}
|
||||
|
||||
return 'unlocked'
|
||||
}
|
||||
|
||||
override deinit(): void {
|
||||
super.deinit()
|
||||
;(this.sync as unknown) = undefined
|
||||
;(this.items as unknown) = undefined
|
||||
;(this.mutator as unknown) = undefined
|
||||
;(this.encryption as unknown) = undefined
|
||||
;(this.alerts as unknown) = undefined
|
||||
;(this._getVault as unknown) = undefined
|
||||
;(this._changeVaultKeyOptions as unknown) = undefined
|
||||
;(this._moveItemsToVault as unknown) = undefined
|
||||
;(this._createVault as unknown) = undefined
|
||||
;(this._removeItemFromVaultUseCase as unknown) = undefined
|
||||
;(this._deleteVaultUseCase as unknown) = undefined
|
||||
;(this._rotateVaultKey as unknown) = undefined
|
||||
|
||||
this.lockMap.clear()
|
||||
return result
|
||||
}
|
||||
}
|
||||
-8
@@ -2,18 +2,10 @@ import { VaultListingInterface } from '@standardnotes/models'
|
||||
|
||||
export enum VaultServiceEvent {
|
||||
VaultRootKeyRotated = 'VaultRootKeyRotated',
|
||||
VaultUnlocked = 'VaultUnlocked',
|
||||
VaultLocked = 'VaultLocked',
|
||||
}
|
||||
|
||||
export type VaultServiceEventPayload = {
|
||||
[VaultServiceEvent.VaultRootKeyRotated]: {
|
||||
vault: VaultListingInterface
|
||||
}
|
||||
[VaultServiceEvent.VaultUnlocked]: {
|
||||
vault: VaultListingInterface
|
||||
}
|
||||
[VaultServiceEvent.VaultLocked]: {
|
||||
vault: VaultListingInterface
|
||||
}
|
||||
}
|
||||
+5
-12
@@ -6,15 +6,12 @@ import {
|
||||
} from '@standardnotes/models'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { VaultServiceEvent, VaultServiceEventPayload } from './VaultServiceEvent'
|
||||
import { ChangeVaultOptionsDTO } from './ChangeVaultOptionsDTO'
|
||||
import { ChangeVaultKeyOptionsDTO } from './UseCase/ChangeVaultKeyOptionsDTO'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
|
||||
export interface VaultServiceInterface
|
||||
extends AbstractService<VaultServiceEvent, VaultServiceEventPayload[VaultServiceEvent]> {
|
||||
createRandomizedVault(dto: {
|
||||
name: string
|
||||
description?: string
|
||||
storagePreference: KeySystemRootKeyStorageMode
|
||||
}): Promise<VaultListingInterface>
|
||||
createRandomizedVault(dto: { name: string; description?: string }): Promise<VaultListingInterface>
|
||||
createUserInputtedPasswordVault(dto: {
|
||||
name: string
|
||||
description?: string
|
||||
@@ -24,7 +21,6 @@ export interface VaultServiceInterface
|
||||
|
||||
getVaults(): VaultListingInterface[]
|
||||
getVault(dto: { keySystemIdentifier: KeySystemIdentifier }): VaultListingInterface | undefined
|
||||
getLockedvaults(): VaultListingInterface[]
|
||||
deleteVault(vault: VaultListingInterface): Promise<boolean>
|
||||
|
||||
moveItemToVault(
|
||||
@@ -39,9 +35,6 @@ export interface VaultServiceInterface
|
||||
vault: VaultListingInterface,
|
||||
params: { name: string; description: string },
|
||||
): Promise<VaultListingInterface>
|
||||
rotateVaultRootKey(vault: VaultListingInterface): Promise<void>
|
||||
changeVaultOptions(dto: ChangeVaultOptionsDTO): Promise<void>
|
||||
|
||||
isVaultLocked(vault: VaultListingInterface): boolean
|
||||
unlockNonPersistentVault(vault: VaultListingInterface, password: string): Promise<boolean>
|
||||
rotateVaultRootKey(vault: VaultListingInterface, vaultPassword?: string): Promise<void>
|
||||
changeVaultOptions(dto: ChangeVaultKeyOptionsDTO): Promise<Result<void>>
|
||||
}
|
||||
@@ -9,7 +9,7 @@ import { GetUntrustedPayload } from './../AsymmetricMessage/UseCase/GetUntrusted
|
||||
import { GetTrustedPayload } from './../AsymmetricMessage/UseCase/GetTrustedPayload'
|
||||
import { InviteRecord } from './InviteRecord'
|
||||
import { VaultUserServiceInterface } from './../VaultUser/VaultUserServiceInterface'
|
||||
import { GetVault } from './../Vaults/UseCase/GetVault'
|
||||
import { GetVault } from '../Vault/UseCase/GetVault'
|
||||
import { InviteToVault } from './UseCase/InviteToVault'
|
||||
import { GetVaultContacts } from '../VaultUser/UseCase/GetVaultContacts'
|
||||
import { SyncServiceInterface } from './../Sync/SyncServiceInterface'
|
||||
@@ -175,7 +175,10 @@ export class VaultInviteService
|
||||
contact: TrustedContactInterface,
|
||||
permissions: SharedVaultPermission,
|
||||
): Promise<Result<SharedVaultInviteServerHash>> {
|
||||
const contactsResult = await this._getVaultContacts.execute(sharedVault.sharing.sharedVaultUuid)
|
||||
const contactsResult = await this._getVaultContacts.execute({
|
||||
sharedVaultUuid: sharedVault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
if (contactsResult.isFailed()) {
|
||||
return Result.fail(contactsResult.getError())
|
||||
}
|
||||
@@ -241,6 +244,7 @@ export class VaultInviteService
|
||||
const trustedMessage = this._getTrustedPayload.execute<AsymmetricMessageSharedVaultInvite>({
|
||||
message: invite,
|
||||
privateKey: this.encryption.getKeyPair().privateKey,
|
||||
ownUserUuid: this.session.userUuid,
|
||||
sender: sender.getValue(),
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,133 @@
|
||||
import { GetVaults } from '../Vault/UseCase/GetVaults'
|
||||
import { KeySystemPasswordType, KeySystemRootKeyStorageMode, VaultListingInterface } from '@standardnotes/models'
|
||||
import { VaultLockServiceInterface } from './VaultLockServiceInterface'
|
||||
import { VaultLockServiceEvent, VaultLockServiceEventPayload } from './VaultLockServiceEvent'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
|
||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
||||
import { ContentType } from '@standardnotes/domain-core'
|
||||
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
|
||||
import { KeySystemKeyManagerInterface } from '../KeySystem/KeySystemKeyManagerInterface'
|
||||
|
||||
export class VaultLockService
|
||||
extends AbstractService<VaultLockServiceEvent, VaultLockServiceEventPayload[VaultLockServiceEvent]>
|
||||
implements VaultLockServiceInterface
|
||||
{
|
||||
private lockMap = new Map<VaultListingInterface['uuid'], boolean>()
|
||||
|
||||
constructor(
|
||||
items: ItemManagerInterface,
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private keys: KeySystemKeyManagerInterface,
|
||||
private _getVaults: GetVaults,
|
||||
eventBus: InternalEventBusInterface,
|
||||
) {
|
||||
super(eventBus)
|
||||
|
||||
items.addObserver(
|
||||
[ContentType.TYPES.KeySystemItemsKey, ContentType.TYPES.KeySystemRootKey, ContentType.TYPES.VaultListing],
|
||||
() => {
|
||||
void this.recomputeAllVaultsLockingState()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
override deinit(): void {
|
||||
super.deinit()
|
||||
;(this.encryption as unknown) = undefined
|
||||
;(this.keys as unknown) = undefined
|
||||
;(this._getVaults as unknown) = undefined
|
||||
|
||||
this.lockMap.clear()
|
||||
}
|
||||
|
||||
public getLockedvaults(): VaultListingInterface[] {
|
||||
const vaults = this._getVaults.execute().getValue()
|
||||
return vaults.filter((vault) => this.isVaultLocked(vault))
|
||||
}
|
||||
|
||||
public isVaultLocked(vault: VaultListingInterface): boolean {
|
||||
return this.lockMap.get(vault.uuid) === true
|
||||
}
|
||||
|
||||
public isVaultLockable(vault: VaultListingInterface): boolean {
|
||||
return vault.keyPasswordType === KeySystemPasswordType.UserInputted
|
||||
}
|
||||
|
||||
public async lockNonPersistentVault(vault: VaultListingInterface): Promise<void> {
|
||||
if (vault.keyStorageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
throw new Error('Vault uses synced key storage and cannot be locked')
|
||||
}
|
||||
|
||||
if (vault.keyPasswordType !== KeySystemPasswordType.UserInputted) {
|
||||
throw new Error('Vault uses randomized password and cannot be locked')
|
||||
}
|
||||
|
||||
await this.keys.wipeVaultKeysFromMemory(vault)
|
||||
|
||||
this.lockMap.set(vault.uuid, true)
|
||||
|
||||
void this.notifyEventSync(VaultLockServiceEvent.VaultLocked, { vault })
|
||||
}
|
||||
|
||||
public async unlockNonPersistentVault(vault: VaultListingInterface, password: string): Promise<boolean> {
|
||||
if (vault.keyPasswordType !== KeySystemPasswordType.UserInputted) {
|
||||
throw new Error('Vault uses randomized password and cannot be unlocked with user inputted password')
|
||||
}
|
||||
|
||||
if (vault.keyStorageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
throw new Error('Vault uses synced root key and cannot be unlocked with user inputted password')
|
||||
}
|
||||
|
||||
const derivedRootKey = this.encryption.deriveUserInputtedKeySystemRootKey({
|
||||
keyParams: vault.rootKeyParams,
|
||||
userInputtedPassword: password,
|
||||
})
|
||||
|
||||
this.keys.cacheKey(derivedRootKey, vault.keyStorageMode)
|
||||
|
||||
await this.encryption.decryptErroredPayloads()
|
||||
|
||||
if (this.computeVaultLockState(vault) === 'locked') {
|
||||
this.keys.removeKeyFromCache(vault.systemIdentifier)
|
||||
return false
|
||||
}
|
||||
|
||||
this.lockMap.set(vault.uuid, false)
|
||||
void this.notifyEventSync(VaultLockServiceEvent.VaultUnlocked, { vault })
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private recomputeAllVaultsLockingState = async (): Promise<void> => {
|
||||
const vaults = this._getVaults.execute().getValue()
|
||||
|
||||
for (const vault of vaults) {
|
||||
const locked = this.computeVaultLockState(vault) === 'locked'
|
||||
|
||||
if (this.lockMap.get(vault.uuid) !== locked) {
|
||||
this.lockMap.set(vault.uuid, locked)
|
||||
|
||||
if (locked) {
|
||||
void this.notifyEvent(VaultLockServiceEvent.VaultLocked, { vault })
|
||||
} else {
|
||||
void this.notifyEvent(VaultLockServiceEvent.VaultUnlocked, { vault })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private computeVaultLockState(vault: VaultListingInterface): 'locked' | 'unlocked' {
|
||||
const rootKey = this.keys.getPrimaryKeySystemRootKey(vault.systemIdentifier)
|
||||
if (!rootKey) {
|
||||
return 'locked'
|
||||
}
|
||||
|
||||
const itemsKey = this.keys.getPrimaryKeySystemItemsKey(vault.systemIdentifier)
|
||||
if (!itemsKey) {
|
||||
return 'locked'
|
||||
}
|
||||
|
||||
return 'unlocked'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { VaultListingInterface } from '@standardnotes/models'
|
||||
|
||||
export enum VaultLockServiceEvent {
|
||||
VaultUnlocked = 'VaultUnlocked',
|
||||
VaultLocked = 'VaultLocked',
|
||||
}
|
||||
|
||||
export type VaultLockServiceEventPayload = {
|
||||
[VaultLockServiceEvent.VaultUnlocked]: {
|
||||
vault: VaultListingInterface
|
||||
}
|
||||
[VaultLockServiceEvent.VaultLocked]: {
|
||||
vault: VaultListingInterface
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import { VaultListingInterface } from '@standardnotes/models'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
import { VaultLockServiceEvent, VaultLockServiceEventPayload } from './VaultLockServiceEvent'
|
||||
|
||||
export interface VaultLockServiceInterface
|
||||
extends AbstractService<VaultLockServiceEvent, VaultLockServiceEventPayload[VaultLockServiceEvent]> {
|
||||
getLockedvaults(): VaultListingInterface[]
|
||||
isVaultLocked(vault: VaultListingInterface): boolean
|
||||
isVaultLockable(vault: VaultListingInterface): boolean
|
||||
lockNonPersistentVault(vault: VaultListingInterface): Promise<void>
|
||||
unlockNonPersistentVault(vault: VaultListingInterface, password: string): Promise<boolean>
|
||||
}
|
||||
@@ -7,13 +7,17 @@ import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
export class GetVaultContacts implements UseCaseInterface<TrustedContactInterface[]> {
|
||||
constructor(private findContact: FindContact, private getVaultUsers: GetVaultUsers) {}
|
||||
|
||||
async execute(sharedVaultUuid: string): Promise<Result<TrustedContactInterface[]>> {
|
||||
const users = await this.getVaultUsers.execute({ sharedVaultUuid })
|
||||
if (!users) {
|
||||
async execute(dto: { sharedVaultUuid: string; readFromCache: boolean }): Promise<Result<TrustedContactInterface[]>> {
|
||||
const users = await this.getVaultUsers.execute({
|
||||
sharedVaultUuid: dto.sharedVaultUuid,
|
||||
readFromCache: dto.readFromCache,
|
||||
})
|
||||
if (users.isFailed()) {
|
||||
return Result.fail('Failed to get vault users')
|
||||
}
|
||||
|
||||
const contacts = users
|
||||
.getValue()
|
||||
.map((user) => this.findContact.execute({ userUuid: user.user_uuid }))
|
||||
.map((result) => (result.isFailed() ? undefined : result.getValue()))
|
||||
.filter(isNotUndefined)
|
||||
|
||||
@@ -1,16 +1,31 @@
|
||||
import { SharedVaultUserServerHash, isErrorResponse } from '@standardnotes/responses'
|
||||
import { VaultUserCache } from './../VaultUserCache'
|
||||
import { SharedVaultUserServerHash, getErrorFromErrorResponse, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultUsersServerInterface } from '@standardnotes/api'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class GetVaultUsers {
|
||||
constructor(private vaultUsersServer: SharedVaultUsersServerInterface) {}
|
||||
export class GetVaultUsers implements UseCaseInterface<SharedVaultUserServerHash[]> {
|
||||
constructor(private vaultUsersServer: SharedVaultUsersServerInterface, private cache: VaultUserCache) {}
|
||||
|
||||
async execute(params: {
|
||||
sharedVaultUuid: string
|
||||
readFromCache: boolean
|
||||
}): Promise<Result<SharedVaultUserServerHash[]>> {
|
||||
if (params.readFromCache) {
|
||||
const cachedUsers = this.cache.get(params.sharedVaultUuid)
|
||||
|
||||
if (cachedUsers) {
|
||||
return Result.ok(cachedUsers)
|
||||
}
|
||||
}
|
||||
|
||||
async execute(params: { sharedVaultUuid: string }): Promise<SharedVaultUserServerHash[] | undefined> {
|
||||
const response = await this.vaultUsersServer.getSharedVaultUsers({ sharedVaultUuid: params.sharedVaultUuid })
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return undefined
|
||||
return Result.fail(getErrorFromErrorResponse(response).message)
|
||||
}
|
||||
|
||||
return response.data.users
|
||||
this.cache.set(params.sharedVaultUuid, response.data.users)
|
||||
|
||||
return Result.ok(response.data.users)
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
import { Result, SyncUseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { SharedVaultListingInterface } from '@standardnotes/models'
|
||||
|
||||
export class IsVaultAdmin implements SyncUseCaseInterface<boolean> {
|
||||
export class IsVaultOwner implements SyncUseCaseInterface<boolean> {
|
||||
execute(dto: { sharedVault: SharedVaultListingInterface; userUuid: string }): Result<boolean> {
|
||||
if (!dto.sharedVault.sharing.ownerUserUuid) {
|
||||
throw new Error(`Shared vault ${dto.sharedVault.sharing.sharedVaultUuid} does not have an owner user uuid`)
|
||||
@@ -0,0 +1,15 @@
|
||||
import { SharedVaultUserServerHash } from '@standardnotes/responses'
|
||||
|
||||
type SharedVaultUuid = string
|
||||
|
||||
export class VaultUserCache {
|
||||
private cache = new Map<SharedVaultUuid, SharedVaultUserServerHash[]>()
|
||||
|
||||
public get(sharedVaultUuid: SharedVaultUuid): SharedVaultUserServerHash[] | undefined {
|
||||
return this.cache.get(sharedVaultUuid)
|
||||
}
|
||||
|
||||
public set(sharedVaultUuid: SharedVaultUuid, users: SharedVaultUserServerHash[]): void {
|
||||
this.cache.set(sharedVaultUuid, users)
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
import { VaultLockServiceInterface } from './../VaultLock/VaultLockServiceInterface'
|
||||
import { LeaveVault } from './UseCase/LeaveSharedVault'
|
||||
import { GetVault } from './../Vaults/UseCase/GetVault'
|
||||
import { GetVault } from '../Vault/UseCase/GetVault'
|
||||
import { InternalEventBusInterface } from './../Internal/InternalEventBusInterface'
|
||||
import { RemoveVaultMember } from './UseCase/RemoveSharedVaultMember'
|
||||
import { VaultServiceInterface } from './../Vaults/VaultServiceInterface'
|
||||
import { VaultServiceInterface } from '../Vault/VaultServiceInterface'
|
||||
import { SessionsClientInterface } from './../Session/SessionsClientInterface'
|
||||
import { GetVaultUsers } from './UseCase/GetVaultUsers'
|
||||
import { SharedVaultListingInterface } from '@standardnotes/models'
|
||||
@@ -11,15 +12,16 @@ import { ClientDisplayableError, SharedVaultUserServerHash, isClientDisplayableE
|
||||
import { AbstractService } from './../Service/AbstractService'
|
||||
import { VaultUserServiceEvent } from './VaultUserServiceEvent'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
import { IsVaultAdmin } from './UseCase/IsVaultAdmin'
|
||||
import { IsVaultOwner } from './UseCase/IsVaultOwner'
|
||||
|
||||
export class VaultUserService extends AbstractService<VaultUserServiceEvent> implements VaultUserServiceInterface {
|
||||
constructor(
|
||||
private session: SessionsClientInterface,
|
||||
private vaults: VaultServiceInterface,
|
||||
private vaultLocks: VaultLockServiceInterface,
|
||||
private _getVaultUsers: GetVaultUsers,
|
||||
private _removeVaultMember: RemoveVaultMember,
|
||||
private _isVaultAdmin: IsVaultAdmin,
|
||||
private _isVaultOwner: IsVaultOwner,
|
||||
private _getVault: GetVault,
|
||||
private _leaveVault: LeaveVault,
|
||||
eventBus: InternalEventBusInterface,
|
||||
@@ -33,7 +35,7 @@ export class VaultUserService extends AbstractService<VaultUserServiceEvent> imp
|
||||
;(this.vaults as unknown) = undefined
|
||||
;(this._getVaultUsers as unknown) = undefined
|
||||
;(this._removeVaultMember as unknown) = undefined
|
||||
;(this._isVaultAdmin as unknown) = undefined
|
||||
;(this._isVaultOwner as unknown) = undefined
|
||||
;(this._getVault as unknown) = undefined
|
||||
;(this._leaveVault as unknown) = undefined
|
||||
}
|
||||
@@ -41,11 +43,19 @@ export class VaultUserService extends AbstractService<VaultUserServiceEvent> imp
|
||||
public async getSharedVaultUsers(
|
||||
sharedVault: SharedVaultListingInterface,
|
||||
): Promise<SharedVaultUserServerHash[] | undefined> {
|
||||
return this._getVaultUsers.execute({ sharedVaultUuid: sharedVault.sharing.sharedVaultUuid })
|
||||
const result = await this._getVaultUsers.execute({
|
||||
sharedVaultUuid: sharedVault.sharing.sharedVaultUuid,
|
||||
readFromCache: false,
|
||||
})
|
||||
if (result.isFailed()) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return result.getValue()
|
||||
}
|
||||
|
||||
public isCurrentUserSharedVaultAdmin(sharedVault: SharedVaultListingInterface): boolean {
|
||||
return this._isVaultAdmin
|
||||
return this._isVaultOwner
|
||||
.execute({
|
||||
sharedVault,
|
||||
userUuid: this.session.userUuid,
|
||||
@@ -58,7 +68,7 @@ export class VaultUserService extends AbstractService<VaultUserServiceEvent> imp
|
||||
throw new Error('Only vault admins can remove users')
|
||||
}
|
||||
|
||||
if (this.vaults.isVaultLocked(sharedVault)) {
|
||||
if (this.vaultLocks.isVaultLocked(sharedVault)) {
|
||||
throw new Error('Cannot remove user from locked vault')
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
import { KeySystemRootKeyPasswordType, KeySystemRootKeyStorageMode, VaultListingInterface } from '@standardnotes/models'
|
||||
|
||||
export type ChangeVaultOptionsDTO = {
|
||||
vault: VaultListingInterface
|
||||
newPasswordType:
|
||||
| { passwordType: KeySystemRootKeyPasswordType.Randomized }
|
||||
| { passwordType: KeySystemRootKeyPasswordType.UserInputted; userInputtedPassword: string }
|
||||
| undefined
|
||||
newKeyStorageMode: KeySystemRootKeyStorageMode | undefined
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
import { MutatorClientInterface, SyncServiceInterface } from '@standardnotes/services'
|
||||
import {
|
||||
KeySystemRootKeyPasswordType,
|
||||
KeySystemRootKeyStorageMode,
|
||||
VaultListingInterface,
|
||||
VaultListingMutator,
|
||||
} from '@standardnotes/models'
|
||||
import { ChangeVaultOptionsDTO } from '../ChangeVaultOptionsDTO'
|
||||
import { GetVault } from './GetVault'
|
||||
import { EncryptionProviderInterface } from '../../Encryption/EncryptionProviderInterface'
|
||||
import { KeySystemKeyManagerInterface } from '../../KeySystem/KeySystemKeyManagerInterface'
|
||||
|
||||
export class ChangeVaultKeyOptions {
|
||||
constructor(
|
||||
private mutator: MutatorClientInterface,
|
||||
private sync: SyncServiceInterface,
|
||||
private encryption: EncryptionProviderInterface,
|
||||
private keys: KeySystemKeyManagerInterface,
|
||||
private getVault: GetVault,
|
||||
) {}
|
||||
|
||||
async execute(dto: ChangeVaultOptionsDTO): Promise<void> {
|
||||
const useStorageMode = dto.newKeyStorageMode ?? dto.vault.keyStorageMode
|
||||
|
||||
if (dto.newPasswordType) {
|
||||
if (dto.vault.keyPasswordType === dto.newPasswordType.passwordType) {
|
||||
throw new Error('Vault password type is already set to this type')
|
||||
}
|
||||
|
||||
if (dto.newPasswordType.passwordType === KeySystemRootKeyPasswordType.UserInputted) {
|
||||
if (!dto.newPasswordType.userInputtedPassword) {
|
||||
throw new Error('User inputted password is required')
|
||||
}
|
||||
await this.changePasswordTypeToUserInputted(dto.vault, dto.newPasswordType.userInputtedPassword, useStorageMode)
|
||||
} else if (dto.newPasswordType.passwordType === KeySystemRootKeyPasswordType.Randomized) {
|
||||
await this.changePasswordTypeToRandomized(dto.vault, useStorageMode)
|
||||
}
|
||||
}
|
||||
|
||||
if (dto.newKeyStorageMode) {
|
||||
const result = this.getVault.execute({ keySystemIdentifier: dto.vault.systemIdentifier })
|
||||
|
||||
if (result.isFailed()) {
|
||||
throw new Error('Vault not found')
|
||||
}
|
||||
|
||||
const latestVault = result.getValue()
|
||||
|
||||
if (latestVault.rootKeyParams.passwordType !== KeySystemRootKeyPasswordType.UserInputted) {
|
||||
throw new Error('Vault uses randomized password and cannot change its storage preference')
|
||||
}
|
||||
|
||||
if (dto.newKeyStorageMode === latestVault.keyStorageMode) {
|
||||
throw new Error('Vault already uses this storage preference')
|
||||
}
|
||||
|
||||
if (
|
||||
dto.newKeyStorageMode === KeySystemRootKeyStorageMode.Local ||
|
||||
dto.newKeyStorageMode === KeySystemRootKeyStorageMode.Ephemeral
|
||||
) {
|
||||
await this.changeStorageModeToLocalOrEphemeral(latestVault, dto.newKeyStorageMode)
|
||||
} else if (dto.newKeyStorageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
await this.changeStorageModeToSynced(latestVault)
|
||||
}
|
||||
}
|
||||
|
||||
await this.sync.sync()
|
||||
}
|
||||
|
||||
private async changePasswordTypeToUserInputted(
|
||||
vault: VaultListingInterface,
|
||||
userInputtedPassword: string,
|
||||
storageMode: KeySystemRootKeyStorageMode,
|
||||
): Promise<void> {
|
||||
const newRootKey = this.encryption.createUserInputtedKeySystemRootKey({
|
||||
systemIdentifier: vault.systemIdentifier,
|
||||
userInputtedPassword: userInputtedPassword,
|
||||
})
|
||||
|
||||
if (storageMode === KeySystemRootKeyStorageMode.Synced) {
|
||||
await this.mutator.insertItem(newRootKey, true)
|
||||
} else {
|
||||
this.keys.intakeNonPersistentKeySystemRootKey(newRootKey, storageMode)
|
||||
}
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.rootKeyParams = newRootKey.keyParams
|
||||
})
|
||||
|
||||
await this.keys.reencryptKeySystemItemsKeysForVault(vault.systemIdentifier)
|
||||
}
|
||||
|
||||
private async changePasswordTypeToRandomized(
|
||||
vault: VaultListingInterface,
|
||||
storageMode: KeySystemRootKeyStorageMode,
|
||||
): Promise<void> {
|
||||
const newRootKey = this.encryption.createRandomizedKeySystemRootKey({
|
||||
systemIdentifier: vault.systemIdentifier,
|
||||
})
|
||||
|
||||
if (storageMode !== KeySystemRootKeyStorageMode.Synced) {
|
||||
throw new Error('Cannot change to randomized password if root key storage is not synced')
|
||||
}
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.rootKeyParams = newRootKey.keyParams
|
||||
})
|
||||
|
||||
await this.mutator.insertItem(newRootKey, true)
|
||||
|
||||
await this.keys.reencryptKeySystemItemsKeysForVault(vault.systemIdentifier)
|
||||
}
|
||||
|
||||
private async changeStorageModeToLocalOrEphemeral(
|
||||
vault: VaultListingInterface,
|
||||
newKeyStorageMode: KeySystemRootKeyStorageMode,
|
||||
): Promise<void> {
|
||||
const primaryKey = this.keys.getPrimaryKeySystemRootKey(vault.systemIdentifier)
|
||||
if (!primaryKey) {
|
||||
throw new Error('No primary key found')
|
||||
}
|
||||
|
||||
this.keys.intakeNonPersistentKeySystemRootKey(primaryKey, newKeyStorageMode)
|
||||
await this.keys.deleteAllSyncedKeySystemRootKeys(vault.systemIdentifier)
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.keyStorageMode = newKeyStorageMode
|
||||
})
|
||||
|
||||
await this.sync.sync()
|
||||
}
|
||||
|
||||
private async changeStorageModeToSynced(vault: VaultListingInterface): Promise<void> {
|
||||
const allRootKeys = this.keys.getAllKeySystemRootKeysForVault(vault.systemIdentifier)
|
||||
const syncedRootKeys = this.keys.getSyncedKeySystemRootKeysForVault(vault.systemIdentifier)
|
||||
|
||||
for (const key of allRootKeys) {
|
||||
const existingSyncedKey = syncedRootKeys.find((syncedKey) => syncedKey.token === key.token)
|
||||
if (existingSyncedKey) {
|
||||
continue
|
||||
}
|
||||
|
||||
await this.mutator.insertItem(key)
|
||||
}
|
||||
|
||||
await this.mutator.changeItem<VaultListingMutator>(vault, (mutator) => {
|
||||
mutator.keyStorageMode = KeySystemRootKeyStorageMode.Synced
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ export * from './AsymmetricMessage/UseCase/ProcessAcceptedVaultInvite'
|
||||
export * from './AsymmetricMessage/UseCase/ResendAllMessages'
|
||||
export * from './AsymmetricMessage/UseCase/ResendMessage'
|
||||
export * from './AsymmetricMessage/UseCase/SendMessage'
|
||||
export * from './AsymmetricMessage/UseCase/SendOwnContactChangeMessage'
|
||||
export * from './Contacts/UseCase/SendOwnContactChangeMessage'
|
||||
export * from './Auth/AuthClientInterface'
|
||||
export * from './Auth/AuthManager'
|
||||
export * from './Authenticator/AuthenticatorClientInterface'
|
||||
@@ -36,6 +36,7 @@ export * from './Contacts/ContactService'
|
||||
export * from './Contacts/ContactServiceInterface'
|
||||
export * from './Contacts/SelfContactManager'
|
||||
export * from './Contacts/UseCase/CreateOrEditContact'
|
||||
export * from './Contacts/UseCase/DeleteContact'
|
||||
export * from './Contacts/UseCase/EditContact'
|
||||
export * from './Contacts/UseCase/FindContact'
|
||||
export * from './Contacts/UseCase/GetAllContacts'
|
||||
@@ -133,10 +134,13 @@ export * from './Session/UserKeyPairChangedEventData'
|
||||
export * from './SharedVaults/SharedVaultService'
|
||||
export * from './SharedVaults/SharedVaultServiceEvent'
|
||||
export * from './SharedVaults/SharedVaultServiceInterface'
|
||||
export * from './SharedVaults/UseCase/ContactBelongsToVault'
|
||||
export * from './SharedVaults/UseCase/ConvertToSharedVault'
|
||||
export * from './SharedVaults/UseCase/CreateSharedVault'
|
||||
export * from './SharedVaults/UseCase/DeleteExternalSharedVault'
|
||||
export * from './SharedVaults/UseCase/DeleteSharedVault'
|
||||
export * from './SharedVaults/UseCase/GetOwnedSharedVaults'
|
||||
export * from './SharedVaults/UseCase/GetSharedVaults'
|
||||
export * from './SharedVaults/UseCase/NotifyVaultUsersOfKeyRotation'
|
||||
export * from './SharedVaults/UseCase/SendVaultDataChangedMessage'
|
||||
export * from './SharedVaults/UseCase/SendVaultKeyChangedMessage'
|
||||
@@ -149,6 +153,7 @@ export * from './Storage/KeyValueStoreInterface'
|
||||
export * from './Storage/StorageKeys'
|
||||
export * from './Storage/StorageServiceInterface'
|
||||
export * from './Storage/StorageTypes'
|
||||
export * from './Storage/UseCase/RemoveItemsFromMemory'
|
||||
export * from './Strings/InfoStrings'
|
||||
export * from './Strings/Messages'
|
||||
export * from './Subscription/AppleIAPProductId'
|
||||
@@ -162,7 +167,7 @@ export * from './Sync/SyncOptions'
|
||||
export * from './Sync/SyncQueueStrategy'
|
||||
export * from './Sync/SyncServiceInterface'
|
||||
export * from './Sync/SyncSource'
|
||||
export * from './UseCase/RemoveItemsLocally'
|
||||
export * from './UseCase/DiscardItemsLocally'
|
||||
export * from './User/AccountEvent'
|
||||
export * from './User/AccountEventData'
|
||||
export * from './User/CredentialsChangeFunctionResponse'
|
||||
@@ -183,23 +188,28 @@ export * from './VaultInvite/UseCase/SendVaultInvite'
|
||||
export * from './VaultInvite/VaultInviteService'
|
||||
export * from './VaultInvite/VaultInviteServiceEvent'
|
||||
export * from './VaultInvite/VaultInviteServiceInterface'
|
||||
export * from './Vaults/ChangeVaultOptionsDTO'
|
||||
export * from './Vaults/UseCase/ChangeVaultKeyOptions'
|
||||
export * from './Vaults/UseCase/CreateVault'
|
||||
export * from './Vaults/UseCase/DeleteVault'
|
||||
export * from './Vaults/UseCase/GetVault'
|
||||
export * from './Vaults/UseCase/MoveItemsToVault'
|
||||
export * from './Vaults/UseCase/RemoveItemFromVault'
|
||||
export * from './Vaults/UseCase/RotateVaultKey'
|
||||
export * from './Vaults/VaultService'
|
||||
export * from './Vaults/VaultServiceEvent'
|
||||
export * from './Vaults/VaultServiceInterface'
|
||||
export * from './Vault/UseCase/ChangeVaultKeyOptionsDTO'
|
||||
export * from './Vault/UseCase/ChangeVaultKeyOptions'
|
||||
export * from './Vault/UseCase/CreateVault'
|
||||
export * from './Vault/UseCase/DeleteVault'
|
||||
export * from './Vault/UseCase/GetVault'
|
||||
export * from './Vault/UseCase/GetVaults'
|
||||
export * from './Vault/UseCase/MoveItemsToVault'
|
||||
export * from './Vault/UseCase/RemoveItemFromVault'
|
||||
export * from './Vault/UseCase/RotateVaultKey'
|
||||
export * from './Vault/VaultService'
|
||||
export * from './Vault/VaultServiceEvent'
|
||||
export * from './Vault/VaultServiceInterface'
|
||||
export * from './VaultLock/VaultLockService'
|
||||
export * from './VaultLock/VaultLockServiceEvent'
|
||||
export * from './VaultLock/VaultLockServiceInterface'
|
||||
export * from './VaultUser/UseCase/GetVaultContacts'
|
||||
export * from './VaultUser/UseCase/GetVaultContacts'
|
||||
export * from './VaultUser/UseCase/GetVaultUsers'
|
||||
export * from './VaultUser/UseCase/IsVaultAdmin'
|
||||
export * from './VaultUser/UseCase/IsVaultOwner'
|
||||
export * from './VaultUser/UseCase/LeaveSharedVault'
|
||||
export * from './VaultUser/UseCase/RemoveSharedVaultMember'
|
||||
export * from './VaultUser/VaultUserCache'
|
||||
export * from './VaultUser/VaultUserService'
|
||||
export * from './VaultUser/VaultUserServiceEvent'
|
||||
export * from './VaultUser/VaultUserServiceInterface'
|
||||
|
||||
@@ -3,6 +3,22 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
||||
|
||||
## [2.202.15](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/snjs
|
||||
|
||||
## [2.202.14](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-26)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/snjs
|
||||
|
||||
## [2.202.13](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-25)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/snjs
|
||||
|
||||
## [2.202.12](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/snjs
|
||||
|
||||
## [2.202.11](https://github.com/standardnotes/app/compare/@standardnotes/[email protected]...@standardnotes/[email protected]) (2023-07-24)
|
||||
|
||||
**Note:** Version bump only for package @standardnotes/snjs
|
||||
|
||||
@@ -75,6 +75,7 @@ import {
|
||||
VaultInviteServiceInterface,
|
||||
UserEventServiceEvent,
|
||||
VaultServiceEvent,
|
||||
VaultLockServiceInterface,
|
||||
} from '@standardnotes/services'
|
||||
import {
|
||||
PayloadEmitSource,
|
||||
@@ -1324,18 +1325,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.dependencies.get<HomeServerServiceInterface | undefined>(TYPES.HomeServerService)
|
||||
}
|
||||
|
||||
public get vaults(): VaultServiceInterface {
|
||||
return this.dependencies.get<VaultServiceInterface>(TYPES.VaultService)
|
||||
}
|
||||
|
||||
public get contacts(): ContactServiceInterface {
|
||||
return this.dependencies.get<ContactServiceInterface>(TYPES.ContactService)
|
||||
}
|
||||
|
||||
public get sharedVaults(): SharedVaultServiceInterface {
|
||||
return this.dependencies.get<SharedVaultServiceInterface>(TYPES.SharedVaultService)
|
||||
}
|
||||
|
||||
public get preferences(): PreferenceServiceInterface {
|
||||
return this.dependencies.get<PreferenceServiceInterface>(TYPES.PreferencesService)
|
||||
}
|
||||
@@ -1352,6 +1341,14 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.dependencies.get<InternalEventBusInterface>(TYPES.InternalEventBus)
|
||||
}
|
||||
|
||||
public get vaults(): VaultServiceInterface {
|
||||
return this.dependencies.get<VaultServiceInterface>(TYPES.VaultService)
|
||||
}
|
||||
|
||||
public get vaultLocks(): VaultLockServiceInterface {
|
||||
return this.dependencies.get<VaultLockServiceInterface>(TYPES.VaultLockService)
|
||||
}
|
||||
|
||||
public get vaultUsers(): VaultUserServiceInterface {
|
||||
return this.dependencies.get<VaultUserServiceInterface>(TYPES.VaultUserService)
|
||||
}
|
||||
@@ -1360,6 +1357,14 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.dependencies.get<VaultInviteServiceInterface>(TYPES.VaultInviteService)
|
||||
}
|
||||
|
||||
public get contacts(): ContactServiceInterface {
|
||||
return this.dependencies.get<ContactServiceInterface>(TYPES.ContactService)
|
||||
}
|
||||
|
||||
public get sharedVaults(): SharedVaultServiceInterface {
|
||||
return this.dependencies.get<SharedVaultServiceInterface>(TYPES.SharedVaultService)
|
||||
}
|
||||
|
||||
private get migrations(): MigrationService {
|
||||
return this.dependencies.get<MigrationService>(TYPES.MigrationService)
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ import {
|
||||
IntegrityService,
|
||||
InternalEventBus,
|
||||
KeySystemKeyManager,
|
||||
RemoveItemsLocally,
|
||||
DiscardItemsLocally,
|
||||
RevisionManager,
|
||||
SelfContactManager,
|
||||
StatusService,
|
||||
@@ -109,8 +109,16 @@ import {
|
||||
ItemsEncryptionService,
|
||||
DecryptBackupFile,
|
||||
VaultUserService,
|
||||
IsVaultAdmin,
|
||||
IsVaultOwner,
|
||||
VaultInviteService,
|
||||
VaultUserCache,
|
||||
GetVaults,
|
||||
GetSharedVaults,
|
||||
GetOwnedSharedVaults,
|
||||
ContactBelongsToVault,
|
||||
DeleteContact,
|
||||
VaultLockService,
|
||||
RemoveItemsFromMemory,
|
||||
} from '@standardnotes/services'
|
||||
import { ItemManager } from '../../Services/Items/ItemManager'
|
||||
import { PayloadManager } from '../../Services/Payloads/PayloadManager'
|
||||
@@ -207,22 +215,39 @@ export class Dependencies {
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.IsVaultAdmin, () => {
|
||||
return new IsVaultAdmin()
|
||||
this.factory.set(TYPES.IsVaultOwner, () => {
|
||||
return new IsVaultOwner()
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DecryptBackupFile, () => {
|
||||
return new DecryptBackupFile(this.get(TYPES.EncryptionService))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.RemoveItemsLocally, () => {
|
||||
return new RemoveItemsLocally(this.get(TYPES.ItemManager), this.get(TYPES.DiskStorageService))
|
||||
this.factory.set(TYPES.DiscardItemsLocally, () => {
|
||||
return new DiscardItemsLocally(this.get(TYPES.ItemManager), this.get(TYPES.DiskStorageService))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.RemoveItemsFromMemory, () => {
|
||||
return new RemoveItemsFromMemory(
|
||||
this.get(TYPES.DiskStorageService),
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.PayloadManager),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.FindContact, () => {
|
||||
return new FindContact(this.get(TYPES.ItemManager))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DeleteContact, () => {
|
||||
return new DeleteContact(
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.SyncService),
|
||||
this.get(TYPES.GetOwnedSharedVaults),
|
||||
this.get(TYPES.ContactBelongsToVault),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.EditContact, () => {
|
||||
return new EditContact(this.get(TYPES.MutatorService), this.get(TYPES.SyncService))
|
||||
})
|
||||
@@ -248,6 +273,22 @@ export class Dependencies {
|
||||
return new GetVault(this.get(TYPES.ItemManager))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetVaults, () => {
|
||||
return new GetVaults(this.get(TYPES.ItemManager))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetSharedVaults, () => {
|
||||
return new GetSharedVaults(this.get(TYPES.GetVaults))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetOwnedSharedVaults, () => {
|
||||
return new GetOwnedSharedVaults(this.get(TYPES.GetSharedVaults), this.get(TYPES.IsVaultOwner))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ContactBelongsToVault, () => {
|
||||
return new ContactBelongsToVault(this.get(TYPES.GetVaultUsers))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ChangeVaultKeyOptions, () => {
|
||||
return new ChangeVaultKeyOptions(
|
||||
this.get(TYPES.MutatorService),
|
||||
@@ -410,7 +451,7 @@ export class Dependencies {
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.KeySystemKeyManager),
|
||||
this.get(TYPES.SyncService),
|
||||
this.get(TYPES.RemoveItemsLocally),
|
||||
this.get(TYPES.DiscardItemsLocally),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -453,7 +494,7 @@ export class Dependencies {
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetVaultUsers, () => {
|
||||
return new GetVaultUsers(this.get(TYPES.SharedVaultUsersServer))
|
||||
return new GetVaultUsers(this.get(TYPES.SharedVaultUsersServer), this.get(TYPES.VaultUserCache))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DecryptOwnMessage, () => {
|
||||
@@ -523,7 +564,7 @@ export class Dependencies {
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.CreateNewDefaultItemsKey),
|
||||
this.get(TYPES.RemoveItemsLocally),
|
||||
this.get(TYPES.DiscardItemsLocally),
|
||||
this.get(TYPES.FindDefaultItemsKey),
|
||||
)
|
||||
})
|
||||
@@ -619,15 +660,20 @@ export class Dependencies {
|
||||
return new VaultUserService(
|
||||
this.get(TYPES.SessionManager),
|
||||
this.get(TYPES.VaultService),
|
||||
this.get(TYPES.VaultLockService),
|
||||
this.get(TYPES.GetVaultUsers),
|
||||
this.get(TYPES.RemoveVaultMember),
|
||||
this.get(TYPES.IsVaultAdmin),
|
||||
this.get(TYPES.IsVaultOwner),
|
||||
this.get(TYPES.GetVault),
|
||||
this.get(TYPES.LeaveVault),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.VaultUserCache, () => {
|
||||
return new VaultUserCache()
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.VaultInviteService, () => {
|
||||
return new VaultInviteService(
|
||||
this.get(TYPES.ItemManager),
|
||||
@@ -650,17 +696,16 @@ export class Dependencies {
|
||||
|
||||
this.factory.set(TYPES.AsymmetricMessageService, () => {
|
||||
return new AsymmetricMessageService(
|
||||
this.get(TYPES.AsymmetricMessageServer),
|
||||
this.get(TYPES.EncryptionService),
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.SessionManager),
|
||||
this.get(TYPES.AsymmetricMessageServer),
|
||||
this.get(TYPES.CreateOrEditContact),
|
||||
this.get(TYPES.FindContact),
|
||||
this.get(TYPES.GetAllContacts),
|
||||
this.get(TYPES.ReplaceContactData),
|
||||
this.get(TYPES.GetTrustedPayload),
|
||||
this.get(TYPES.GetVault),
|
||||
this.get(TYPES.HandleRootKeyChangedMessage),
|
||||
this.get(TYPES.SendOwnContactChangeMessage),
|
||||
this.get(TYPES.GetOutboundMessages),
|
||||
this.get(TYPES.GetInboundMessages),
|
||||
this.get(TYPES.GetUntrustedPayload),
|
||||
@@ -673,8 +718,8 @@ export class Dependencies {
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.EncryptionService),
|
||||
this.get(TYPES.SessionManager),
|
||||
this.get(TYPES.VaultService),
|
||||
this.get(TYPES.GetVault),
|
||||
this.get(TYPES.GetOwnedSharedVaults),
|
||||
this.get(TYPES.CreateSharedVault),
|
||||
this.get(TYPES.HandleKeyPairChange),
|
||||
this.get(TYPES.NotifyVaultUsersOfKeyRotation),
|
||||
@@ -684,7 +729,18 @@ export class Dependencies {
|
||||
this.get(TYPES.ShareContactWithVault),
|
||||
this.get(TYPES.ConvertToSharedVault),
|
||||
this.get(TYPES.DeleteSharedVault),
|
||||
this.get(TYPES.IsVaultAdmin),
|
||||
this.get(TYPES.IsVaultOwner),
|
||||
this.get(TYPES.DiscardItemsLocally),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.VaultLockService, () => {
|
||||
return new VaultLockService(
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.EncryptionService),
|
||||
this.get(TYPES.KeySystemKeyManager),
|
||||
this.get(TYPES.GetVaults),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
@@ -694,10 +750,10 @@ export class Dependencies {
|
||||
this.get(TYPES.SyncService),
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.EncryptionService),
|
||||
this.get(TYPES.KeySystemKeyManager),
|
||||
this.get(TYPES.VaultLockService),
|
||||
this.get(TYPES.AlertService),
|
||||
this.get(TYPES.GetVault),
|
||||
this.get(TYPES.GetVaults),
|
||||
this.get(TYPES.ChangeVaultKeyOptions),
|
||||
this.get(TYPES.MoveItemsToVault),
|
||||
this.get(TYPES.CreateVault),
|
||||
@@ -727,11 +783,13 @@ export class Dependencies {
|
||||
this.get(TYPES.UserService),
|
||||
this.get(TYPES.SelfContactManager),
|
||||
this.get(TYPES.EncryptionService),
|
||||
this.get(TYPES.DeleteContact),
|
||||
this.get(TYPES.FindContact),
|
||||
this.get(TYPES.GetAllContacts),
|
||||
this.get(TYPES.CreateOrEditContact),
|
||||
this.get(TYPES.EditContact),
|
||||
this.get(TYPES.ValidateItemSigner),
|
||||
this.get(TYPES.SendOwnContactChangeMessage),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
@@ -1172,6 +1230,7 @@ export class Dependencies {
|
||||
this.get(TYPES.ItemManager),
|
||||
this.get(TYPES.MutatorService),
|
||||
this.get(TYPES.DiskStorageService),
|
||||
this.get(TYPES.RemoveItemsFromMemory),
|
||||
this.get(TYPES.InternalEventBus),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -61,6 +61,8 @@ export const TYPES = {
|
||||
ItemsEncryptionService: Symbol.for('ItemsEncryptionService'),
|
||||
VaultUserService: Symbol.for('VaultUserService'),
|
||||
VaultInviteService: Symbol.for('VaultInviteService'),
|
||||
VaultUserCache: Symbol.for('VaultUserCache'),
|
||||
VaultLockService: Symbol.for('VaultLockService'),
|
||||
|
||||
// Servers
|
||||
RevisionServer: Symbol.for('RevisionServer'),
|
||||
@@ -87,16 +89,21 @@ export const TYPES = {
|
||||
GetRevision: Symbol.for('GetRevision'),
|
||||
DeleteRevision: Symbol.for('DeleteRevision'),
|
||||
ImportDataUseCase: Symbol.for('ImportDataUseCase'),
|
||||
RemoveItemsLocally: Symbol.for('RemoveItemsLocally'),
|
||||
DiscardItemsLocally: Symbol.for('DiscardItemsLocally'),
|
||||
FindContact: Symbol.for('FindContact'),
|
||||
GetAllContacts: Symbol.for('GetAllContacts'),
|
||||
CreateOrEditContact: Symbol.for('CreateOrEditContact'),
|
||||
EditContact: Symbol.for('EditContact'),
|
||||
ValidateItemSigner: Symbol.for('ValidateItemSigner'),
|
||||
GetVault: Symbol.for('GetVault'),
|
||||
GetVaults: Symbol.for('GetVaults'),
|
||||
GetSharedVaults: Symbol.for('GetSharedVaults'),
|
||||
GetOwnedSharedVaults: Symbol.for('GetOwnedSharedVaults'),
|
||||
ChangeVaultKeyOptions: Symbol.for('ChangeVaultKeyOptions'),
|
||||
MoveItemsToVault: Symbol.for('MoveItemsToVault'),
|
||||
CreateVault: Symbol.for('CreateVault'),
|
||||
DeleteContact: Symbol.for('DeleteContact'),
|
||||
ContactBelongsToVault: Symbol.for('ContactBelongsToVault'),
|
||||
RemoveItemFromVault: Symbol.for('RemoveItemFromVault'),
|
||||
DeleteVault: Symbol.for('DeleteVault'),
|
||||
RotateVaultKey: Symbol.for('RotateVaultKey'),
|
||||
@@ -142,7 +149,8 @@ export const TYPES = {
|
||||
EncryptTypeAPayload: Symbol.for('EncryptTypeAPayload'),
|
||||
EncryptTypeAPayloadWithKeyLookup: Symbol.for('EncryptTypeAPayloadWithKeyLookup'),
|
||||
DecryptBackupFile: Symbol.for('DecryptBackupFile'),
|
||||
IsVaultAdmin: Symbol.for('IsVaultAdmin'),
|
||||
IsVaultOwner: Symbol.for('IsVaultOwner'),
|
||||
RemoveItemsFromMemory: Symbol.for('RemoveItemsFromMemory'),
|
||||
|
||||
// Mappers
|
||||
SessionStorageMapper: Symbol.for('SessionStorageMapper'),
|
||||
|
||||
@@ -18,7 +18,7 @@ export class Migration2_20_0 extends Migration {
|
||||
const items = this.services.itemManager.getItems(contentType)
|
||||
|
||||
for (const item of items) {
|
||||
this.services.itemManager.removeItemLocally(item)
|
||||
this.services.itemManager.removeItemFromMemory(item)
|
||||
await this.services.storageService.deletePayloadWithUuid(item.uuid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export class Migration2_36_0 extends Migration {
|
||||
const items = this.services.itemManager.getItems(contentType)
|
||||
|
||||
for (const item of items) {
|
||||
this.services.itemManager.removeItemLocally(item)
|
||||
this.services.itemManager.removeItemFromMemory(item)
|
||||
await this.services.storageService.deletePayloadWithUuid(item.uuid)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -816,14 +816,14 @@ export class ItemManager extends Services.AbstractService implements Services.It
|
||||
/**
|
||||
* Important: Caller must coordinate with storage service separately to delete item from persistent database.
|
||||
*/
|
||||
public removeItemLocally(item: Models.AnyItemInterface): void {
|
||||
this.removeItemsLocally([item])
|
||||
public removeItemFromMemory(item: Models.AnyItemInterface): void {
|
||||
this.removeItemsFromMemory([item])
|
||||
}
|
||||
|
||||
/**
|
||||
* Important: Caller must coordinate with storage service separately to delete item from persistent database.
|
||||
*/
|
||||
public removeItemsLocally(items: Models.AnyItemInterface[]): void {
|
||||
public removeItemsFromMemory(items: Models.AnyItemInterface[]): void {
|
||||
this.collection.discard(items)
|
||||
this.payloadManager.removePayloadLocally(items.map((item) => item.payload))
|
||||
|
||||
|
||||
@@ -69,7 +69,7 @@ export class DiskStorageService
|
||||
private values!: StorageValuesObject
|
||||
|
||||
constructor(
|
||||
private deviceInterface: DeviceInterface,
|
||||
private device: DeviceInterface,
|
||||
private identifier: string,
|
||||
protected override internalEventBus: InternalEventBusInterface,
|
||||
) {
|
||||
@@ -82,7 +82,7 @@ export class DiskStorageService
|
||||
}
|
||||
|
||||
public override deinit() {
|
||||
;(this.deviceInterface as unknown) = undefined
|
||||
;(this.device as unknown) = undefined
|
||||
;(this.encryptionProvider as unknown) = undefined
|
||||
this.storagePersistable = false
|
||||
super.deinit()
|
||||
@@ -104,9 +104,9 @@ export class DiskStorageService
|
||||
this.persistencePolicy = persistencePolicy
|
||||
|
||||
if (this.persistencePolicy === StoragePersistencePolicies.Ephemeral) {
|
||||
await this.deviceInterface.clearNamespacedKeychainValue(this.identifier)
|
||||
await this.deviceInterface.removeAllDatabaseEntries(this.identifier)
|
||||
await this.deviceInterface.removeRawStorageValuesForIdentifier(this.identifier)
|
||||
await this.device.clearNamespacedKeychainValue(this.identifier)
|
||||
await this.device.removeAllDatabaseEntries(this.identifier)
|
||||
await this.device.removeRawStorageValuesForIdentifier(this.identifier)
|
||||
await this.clearAllPayloads()
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ export class DiskStorageService
|
||||
}
|
||||
|
||||
public async initializeFromDisk(): Promise<void> {
|
||||
const value = await this.deviceInterface.getRawStorageValue(this.getPersistenceKey())
|
||||
const value = await this.device.getRawStorageValue(this.getPersistenceKey())
|
||||
const values = value ? JSON.parse(value as string) : undefined
|
||||
|
||||
await this.setInitialValues(values)
|
||||
@@ -240,7 +240,7 @@ export class DiskStorageService
|
||||
return values
|
||||
}
|
||||
|
||||
await this.deviceInterface?.setRawStorageValue(this.getPersistenceKey(), JSON.stringify(values))
|
||||
await this.device?.setRawStorageValue(this.getPersistenceKey(), JSON.stringify(values))
|
||||
|
||||
return values
|
||||
})
|
||||
@@ -385,7 +385,11 @@ export class DiskStorageService
|
||||
}
|
||||
|
||||
public async getAllRawPayloads(): Promise<FullyFormedTransferPayload[]> {
|
||||
return this.deviceInterface.getAllDatabaseEntries(this.identifier)
|
||||
return this.device.getAllDatabaseEntries(this.identifier)
|
||||
}
|
||||
|
||||
public async getRawPayloads(uuids: string[]): Promise<FullyFormedTransferPayload[]> {
|
||||
return this.device.getDatabaseEntries(this.identifier, uuids)
|
||||
}
|
||||
|
||||
public async savePayload(payload: FullyFormedPayloadInterface): Promise<void> {
|
||||
@@ -440,7 +444,7 @@ export class DiskStorageService
|
||||
const exportedDeleted = deleted.map(CreateDeletedLocalStorageContextPayload)
|
||||
|
||||
return this.executeCriticalFunction(async () => {
|
||||
return this.deviceInterface?.saveDatabaseEntries(
|
||||
return this.device?.saveDatabaseEntries(
|
||||
[...exportedEncrypted, ...exportedDecrypted, ...exportedDeleted],
|
||||
this.identifier,
|
||||
)
|
||||
@@ -453,19 +457,19 @@ export class DiskStorageService
|
||||
|
||||
public async deletePayloadsWithUuids(uuids: string[]): Promise<void> {
|
||||
await this.executeCriticalFunction(async () => {
|
||||
await Promise.all(uuids.map((uuid) => this.deviceInterface.removeDatabaseEntry(uuid, this.identifier)))
|
||||
await Promise.all(uuids.map((uuid) => this.device.removeDatabaseEntry(uuid, this.identifier)))
|
||||
})
|
||||
}
|
||||
|
||||
public async deletePayloadWithUuid(uuid: string) {
|
||||
return this.executeCriticalFunction(async () => {
|
||||
await this.deviceInterface.removeDatabaseEntry(uuid, this.identifier)
|
||||
await this.device.removeDatabaseEntry(uuid, this.identifier)
|
||||
})
|
||||
}
|
||||
|
||||
public async clearAllPayloads() {
|
||||
return this.executeCriticalFunction(async () => {
|
||||
return this.deviceInterface.removeAllDatabaseEntries(this.identifier)
|
||||
return this.device.removeAllDatabaseEntries(this.identifier)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -474,9 +478,9 @@ export class DiskStorageService
|
||||
await this.clearValues()
|
||||
await this.clearAllPayloads()
|
||||
|
||||
await this.deviceInterface.removeRawStorageValue(namespacedKey(this.identifier, RawStorageKey.SnjsVersion))
|
||||
await this.device.removeRawStorageValue(namespacedKey(this.identifier, RawStorageKey.SnjsVersion))
|
||||
|
||||
await this.deviceInterface.removeRawStorageValue(this.getPersistenceKey())
|
||||
await this.device.removeRawStorageValue(this.getPersistenceKey())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,22 @@
|
||||
|
||||
export const VaultTests = [
|
||||
'vaults/vaults.test.js',
|
||||
'vaults/pkc.test.js',
|
||||
'vaults/contacts.test.js',
|
||||
'vaults/crypto.test.js',
|
||||
'vaults/asymmetric-messages.test.js',
|
||||
'vaults/keypair-change.test.js',
|
||||
'vaults/signatures.test.js',
|
||||
'vaults/shared_vaults.test.js',
|
||||
'vaults/invites.test.js',
|
||||
'vaults/items.test.js',
|
||||
'vaults/conflicts.test.js',
|
||||
'vaults/deletion.test.js',
|
||||
'vaults/permissions.test.js',
|
||||
'vaults/key_rotation.test.js',
|
||||
'vaults/files.test.js',
|
||||
];
|
||||
export const VaultTests = {
|
||||
enabled: false,
|
||||
exclusive: false,
|
||||
files: [
|
||||
'vaults/vaults.test.js',
|
||||
'vaults/pkc.test.js',
|
||||
'vaults/contacts.test.js',
|
||||
'vaults/crypto.test.js',
|
||||
'vaults/asymmetric-messages.test.js',
|
||||
'vaults/keypair-change.test.js',
|
||||
'vaults/signatures.test.js',
|
||||
'vaults/shared_vaults.test.js',
|
||||
'vaults/invites.test.js',
|
||||
'vaults/key-management.test.js',
|
||||
'vaults/items.test.js',
|
||||
'vaults/conflicts.test.js',
|
||||
'vaults/deletion.test.js',
|
||||
'vaults/permissions.test.js',
|
||||
'vaults/key_rotation.test.js',
|
||||
'vaults/files.test.js',
|
||||
],
|
||||
}
|
||||
|
||||
@@ -449,7 +449,7 @@ describe('basic auth', function () {
|
||||
}
|
||||
|
||||
const mutatorSpy = sinon.spy(this.application.mutator, 'setItemToBeDeleted')
|
||||
const removeItemsSpy = sinon.spy(this.application.items, 'removeItemsLocally')
|
||||
const removeItemsSpy = sinon.spy(this.application.items, 'removeItemsFromMemory')
|
||||
const deletePayloadsSpy = sinon.spy(this.application.storage, 'deletePayloadsWithUuids')
|
||||
|
||||
await this.context.changePassword('new-password')
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user