Skip to content

Commit 76cedf3

Browse files
authored
Crypto Tab Take 3 (keybase#21955)
* WIP * Merge thebearjew/crypo/tab (cherry picked from commit 8449a52) * Fix FS import * Fix rn breaking on desktop import * Storyshots * Icon name conflicts
1 parent f7027a7 commit 76cedf3

65 files changed

Lines changed: 5172 additions & 7 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎protocol/avdl/keybase1/saltpack.avdl‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ protocol saltpack {
55
import idl "identify_common.avdl";
66

77
enum AuthenticityType {
8-
SIGNED_0,
9-
REPUDIABLE_1,
8+
SIGNED_0,
9+
REPUDIABLE_1,
1010
ANONYMOUS_2
1111
}
1212

@@ -16,7 +16,7 @@ protocol saltpack {
1616
AuthenticityType authenticityType;
1717
boolean useEntityKeys;
1818
boolean useDeviceKeys;
19-
boolean usePaperKeys;
19+
boolean usePaperKeys;
2020
boolean noSelfEncrypt;
2121
boolean binary;
2222
int saltpackVersion;

‎protocol/avdl/keybase1/saltpack_ui.avdl‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
@namespace("keybase.1")
2+
33
protocol saltpackUi {
44
import idl "common.avdl";
55

‎shared/__mocks__/feature-flags.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const ff: FeatureFlags = {
1010
botUI: false,
1111
chatIndexProfilingEnabled: false,
1212
connectThrashCheck: true,
13+
cryptoTab: false,
1314
dbCleanEnabled: false,
1415
fastAccountSwitch: true,
1516
foldersInProfileTab: true,

‎shared/actions/crypto-gen.tsx‎

Lines changed: 190 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/actions/crypto.tsx‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import * as Saga from '../util/saga'
2+
import * as TeamBuildingGen from './team-building-gen'
3+
import * as CryptoGen from './crypto-gen'
4+
import * as Types from '../constants/types/crypto'
5+
import * as Constants from '../constants/crypto'
6+
import {TypedState} from '../util/container'
7+
import commonTeamBuildingSaga, {filterForNs} from './team-building'
8+
9+
// Get list of users from crypto TeamBuilding for encrypt operation
10+
const onSetRecipients = (state: TypedState, _: TeamBuildingGen.FinishedTeamBuildingPayload) => {
11+
const users = [...state.crypto.teamBuilding.finishedTeam]
12+
const usernames = users.map(user => user.username)
13+
return [
14+
TeamBuildingGen.createCancelTeamBuilding({namespace: 'crypto'}),
15+
CryptoGen.createSetRecipients({operation: 'encrypt', recipients: usernames}),
16+
]
17+
}
18+
19+
function* teamBuildingSaga() {
20+
yield* commonTeamBuildingSaga('crypto')
21+
22+
// This action is used to hook into the TeamBuildingGen.finishedTeamBuilding action.
23+
// We want this so that we can figure out which user(s) havbe been selected and pass that result over to store.crypto.encrypt.recipients
24+
yield* Saga.chainAction2(TeamBuildingGen.finishedTeamBuilding, filterForNs('crypto', onSetRecipients))
25+
}
26+
27+
const handleInput = (
28+
state: TypedState,
29+
action: CryptoGen.SetInputPayload | CryptoGen.SetRecipientsPayload
30+
) => {
31+
const {operation} = action.payload
32+
switch (action.type) {
33+
// Handle input for any operation
34+
case CryptoGen.setInput: {
35+
const {value, type} = action.payload
36+
37+
// Input (text or file) was cleared or deleted
38+
if (!value) {
39+
return CryptoGen.createClearInput({operation})
40+
}
41+
42+
if (operation === Constants.Operations.Encrypt) {
43+
return state.crypto.encrypt.meta.hasRecipients && state.crypto.encrypt.recipients?.length
44+
? makeOperationAction(operation, value, type, state.crypto.encrypt.recipients)
45+
: null
46+
}
47+
48+
return makeOperationAction(operation, value, type)
49+
}
50+
case CryptoGen.setRecipients: {
51+
const {recipients} = action.payload
52+
const {input, inputType} = state.crypto[operation]
53+
// User already provided input (text or file) before setting the
54+
// recipients. Get the input and pass it to the operation
55+
if (input && inputType) {
56+
return makeOperationAction(operation, input, inputType, recipients)
57+
}
58+
return
59+
}
60+
default:
61+
return
62+
}
63+
}
64+
65+
// Dispatch action to appropriate operation
66+
const makeOperationAction = (
67+
operation: Types.Operations,
68+
input: string,
69+
inputType: Types.InputTypes,
70+
recipients: Array<string> = []
71+
) => {
72+
switch (operation) {
73+
case Constants.Operations.Encrypt:
74+
return CryptoGen.createSaltpackEncrypt({input, recipients, type: inputType})
75+
case Constants.Operations.Decrypt:
76+
return CryptoGen.createSaltpackDecrypt({input, type: inputType})
77+
case Constants.Operations.Sign:
78+
return CryptoGen.createSaltpackSign({input, type: inputType})
79+
case Constants.Operations.Verify:
80+
return CryptoGen.createSaltpackVerify({input, type: inputType})
81+
default:
82+
return
83+
}
84+
}
85+
86+
/*
87+
* For the time being these functions will echo back the input as the Saltpack RPC output (plaintext -> plaintext)
88+
* Saltpack RPCs need to be updated to take input as a string and handle `inputType = 'text' | 'file'`
89+
*/
90+
const saltpackEncrypt = async (action: CryptoGen.SaltpackEncryptPayload) => {
91+
return CryptoGen.createOnOperationSuccess({
92+
operation: Constants.Operations.Encrypt,
93+
output: action.payload.input,
94+
outputType: action.payload.type,
95+
})
96+
}
97+
98+
const saltpackDecrypt = async (action: CryptoGen.SaltpackDecryptPayload) => {
99+
return CryptoGen.createOnOperationSuccess({
100+
operation: Constants.Operations.Decrypt,
101+
output: action.payload.input,
102+
outputType: action.payload.type,
103+
})
104+
}
105+
106+
const saltpackSign = async (action: CryptoGen.SaltpackSignPayload) => {
107+
return CryptoGen.createOnOperationSuccess({
108+
operation: Constants.Operations.Sign,
109+
output: action.payload.input,
110+
outputType: action.payload.type,
111+
})
112+
}
113+
114+
const saltpackVerify = async (action: CryptoGen.SaltpackVerifyPayload) => {
115+
return CryptoGen.createOnOperationSuccess({
116+
operation: Constants.Operations.Verify,
117+
output: action.payload.input,
118+
outputType: action.payload.type,
119+
})
120+
}
121+
122+
function* cryptoSaga() {
123+
yield* Saga.chainAction2([CryptoGen.setInput, CryptoGen.setRecipients], handleInput)
124+
yield* Saga.chainAction(CryptoGen.saltpackEncrypt, saltpackEncrypt)
125+
yield* Saga.chainAction(CryptoGen.saltpackDecrypt, saltpackDecrypt)
126+
yield* Saga.chainAction(CryptoGen.saltpackSign, saltpackSign)
127+
yield* Saga.chainAction(CryptoGen.saltpackVerify, saltpackVerify)
128+
yield* teamBuildingSaga()
129+
}
130+
131+
export default cryptoSaga

0 commit comments

Comments
 (0)