-
-
Notifications
You must be signed in to change notification settings - Fork 393
/
VaultsContext.js
119 lines (87 loc) · 3.8 KB
/
VaultsContext.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { AppContext } from './AppContext.js'
import * as Collaboration from './Collaboration.js'
export class VaultsContext extends AppContext {
constructor(params) {
super(params)
}
async changeVaultName(vault, nameAndDesc) {
await this.vaults.changeVaultMetadata(vault, {
name: nameAndDesc.name,
description: nameAndDesc.description,
iconString: 'icon-vault',
})
}
getKeyPair() {
const result = this.application.dependencies.get(TYPES.GetKeyPairs).execute()
return result.getValue().encryption
}
getSigningKeyPair() {
const result = this.application.dependencies.get(TYPES.GetKeyPairs).execute()
return result.getValue().signing
}
async changePassword(password) {
const promise = this.resolveWhenAsyncFunctionCompletes(this.sharedVaults._handleKeyPairChange, 'execute')
await super.changePassword(password)
await this.awaitPromiseOrThrow(promise, undefined, 'Waiting for keypair change message to process')
}
async syncAndAwaitNotificationsProcessing() {
await this.sleep(0.25, 'Waiting for notifications to propagate')
const promise = this.resolveWhenAsyncFunctionCompletes(this.notifications, 'handleReceivedNotifications')
await this.sync()
await this.awaitPromiseOrDoNothing(
promise,
0.25,
'Waiting for notifications timed out. Notifications might have been processed in previous sync.'
)
if (this.notifications['handleReceivedNotifications'].restore) {
this.notifications['handleReceivedNotifications'].restore()
}
}
async syncAndAwaitMessageProcessing() {
const promise = this.resolveWhenAsyncFunctionCompletes(this.asymmetric, 'handleRemoteReceivedAsymmetricMessages')
await this.sync()
await this.awaitPromiseOrThrow(promise, undefined, 'Waiting for messages to process')
}
async syncAndAwaitInviteProcessing() {
const promise = this.resolveWhenAsyncFunctionCompletes(this.vaultInvites, 'processInboundInvites')
await this.sync()
await this.awaitPromiseOrThrow(promise, undefined, 'Waiting for invites to process')
}
async syncAndAwaitInviteAndMessageProcessing() {
const invitePromise = this.resolveWhenAsyncFunctionCompletes(this.vaultInvites, 'processInboundInvites')
const messagePromise = this.resolveWhenAsyncFunctionCompletes(
this.asymmetric,
'handleRemoteReceivedAsymmetricMessages',
)
await this.sync()
await Promise.all([
this.awaitPromiseOrThrow(invitePromise, undefined, 'Waiting for invites to process'),
this.awaitPromiseOrThrow(messagePromise, undefined, 'Waiting for messages to process'),
])
}
/**
* Keep refresh token from expiring due to long bouts of inactivity for contact context
* while main context changes password. Tests have a refresh token age of 10s typically, and changing password
* on CI environment may be time consuming.
*/
async forceRefreshSession() {
await this.application.http.refreshSession()
}
async createSharedPasswordVault(password) {
const privateVault = await this.vaults.createUserInputtedPasswordVault({
name: 'Our Vault',
userInputtedPassword: password,
storagePreference: KeySystemRootKeyStorageMode.Ephemeral,
})
const note = await this.createSyncedNote('foo', 'bar')
await this.vaults.moveItemToVault(privateVault, note)
const sharedVault = await this.sharedVaults.convertVaultToSharedVault(privateVault)
const { thirdPartyContext, deinitThirdPartyContext } = await Collaboration.inviteNewPartyToSharedVault(
this,
sharedVault,
)
await Collaboration.acceptAllInvites(thirdPartyContext)
const contactVault = thirdPartyContext.vaults.getVault({ keySystemIdentifier: sharedVault.systemIdentifier })
return { contactVault, sharedVault, thirdPartyContext, deinitThirdPartyContext }
}
}