-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathiKeychains.ts
More file actions
237 lines (210 loc) · 6.32 KB
/
iKeychains.ts
File metadata and controls
237 lines (210 loc) · 6.32 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import { IRequestTracer } from '../../api';
import { KeychainsTriplet, KeyPair } from '../baseCoin';
import { BitgoPubKeyType } from '../utils/tss/baseTypes';
import { IWallet } from '../wallet';
import { BitGoKeyFromOvcShares, OvcToBitGoJSON } from './ovcJsonCodec';
export type KeyType = 'tss' | 'independent' | 'blsdkg';
export type SourceType = 'bitgo' | 'backup' | 'user' | 'cold';
export type WebauthnFmt = 'none' | 'packed' | 'fido-u2f';
export interface WebauthnAuthenticatorInfo {
credID: string;
fmt: WebauthnFmt;
publicKey: string;
}
export interface KeychainWebauthnDevice {
otpDeviceId: string;
authenticatorInfo: WebauthnAuthenticatorInfo;
// salt for the webauthn prf extension
prfSalt: string;
// Wallet private key encrypted to webauthn derived password
encryptedPrv: string;
}
export interface Keychain {
id: string;
pub?: string;
prv?: string;
provider?: string;
encryptedPrv?: string;
// Required for MPCV2 keys where we reduce the amount of data needed for the keycard.
// This is only generated client side and is not sent to WP
reducedEncryptedPrv?: string;
derivationPath?: string;
derivedFromParentWithSeed?: string;
commonPub?: string;
commonKeychain?: string;
keyShares?: ApiKeyShare[];
walletHSMGPGPublicKeySigs?: string;
hsmType?: BitgoPubKeyType;
type: KeyType;
source?: SourceType;
coinSpecific?: { [coinName: string]: unknown };
// Alternative encryptedPrv using webauthn and the prf extension
webauthnDevices?: KeychainWebauthnDevice[];
// Ethereum address derived from xpub
ethAddress?: string;
}
export type OptionalKeychainEncryptedKey = Pick<Keychain, 'encryptedPrv' | 'webauthnDevices'>;
export type KeychainWithEncryptedPrv = Omit<Keychain, 'encryptedPrv'> & {
encryptedPrv: string;
};
export interface ChangedKeychains {
[pubkey: string]: string;
}
export interface ListKeychainsResult {
keys: Keychain[];
nextBatchPrevId?: string;
}
export interface GetKeychainOptions {
id: string;
xpub?: string;
ethAddress?: string;
reqId?: IRequestTracer;
}
export interface ListKeychainOptions {
limit?: number;
prevId?: string;
}
export interface UpdatePasswordOptions {
oldPassword: string;
newPassword: string;
}
export interface UpdateSingleKeychainPasswordOptions {
keychain?: Keychain;
oldPassword?: string;
newPassword?: string;
}
/**
* Parameters for the rotateKeychain method for ofc multi-user-key
* @property {string} id - the public id of the keychain
* @property {string} password - the user password use to encrypt/decrypt the private key
* @property {IRequestTracer} reqId - optional reqId
*/
export type RotateKeychainOptions =
| {
id: string;
password: string;
reqId?: IRequestTracer;
}
| {
id: string;
pub: string;
encryptedPrv: string;
reqId?: IRequestTracer;
};
export interface AddKeychainOptions {
pub?: string;
commonPub?: string;
commonKeychain?: string;
encryptedPrv?: string;
type?: string;
keyType?: KeyType;
source?: string;
originalPasscodeEncryptionCode?: string;
enterprise?: string;
derivedFromParentWithSeed?: any;
disableKRSEmail?: boolean;
provider?: string;
reqId?: IRequestTracer;
krsSpecific?: any;
keyShares?: ApiKeyShare[];
userGPGPublicKey?: string;
backupGPGPublicKey?: string;
algoUsed?: string;
isDistributedCustody?: boolean;
// indicates if the key is MPCv2 or not
isMPCv2?: boolean;
coinSpecific?: { [coinName: string]: unknown };
}
export interface ApiKeyShare {
from: 'user' | 'backup' | 'bitgo';
to: 'user' | 'backup' | 'bitgo';
publicShare: string;
privateShare: string;
privateShareProof?: string;
paillierPublicKey?: string;
n?: string;
vssProof?: string;
}
export interface CreateBackupOptions {
provider?: string;
source?: string;
disableKRSEmail?: boolean;
krsSpecific?: any;
type?: string;
keyType?: KeyType;
reqId?: IRequestTracer;
commonPub?: string;
commonKeychain?: string;
prv?: string;
encryptedPrv?: string;
passphrase?: string;
}
export interface CreateBitGoOptions {
source?: 'bitgo';
enterprise?: string;
reqId?: IRequestTracer;
keyType?: KeyType;
isDistributedCustody?: boolean;
}
export type DecryptedRetrofitPayload = {
decryptedUserKey: string;
decryptedBackupKey: string;
walletId: string;
};
export interface CreateMpcOptions {
multisigType: 'onchain' | 'tss';
passphrase?: string;
originalPasscodeEncryptionCode?: string;
enterprise?: string;
retrofit?: DecryptedRetrofitPayload;
}
export interface RecreateMpcOptions extends Omit<CreateMpcOptions, 'retrofit' | 'multisigType'> {
coin: string;
walletId: string;
passphrase: string;
otp: string;
enterprise: string;
encryptedMaterial: {
encryptedUserKey: string;
encryptedBackupKey: string;
encryptedWalletPassphrase: string;
};
}
export interface GetKeysForSigningOptions {
reqId?: IRequestTracer;
wallet?: IWallet;
}
export interface GetSigningKeyApi {
userId: string;
userEmail: string;
derivedPubkey: string;
// These are present when user fetches their own ecdh keychain for signing.
derivationPath?: string;
ecdhKeychain?: string;
}
export interface EcdhDerivedKeypair {
derivedPubKey: string; // Hex string
derivationPath: string; // Derivation path of the keypair
xprv: string;
}
export enum KeyIndices {
USER = 0,
BACKUP = 1,
BITGO = 2,
}
export interface IKeychains {
get(params: GetKeychainOptions): Promise<Keychain>;
list(params?: ListKeychainOptions): Promise<ListKeychainsResult>;
updatePassword(params: UpdatePasswordOptions): Promise<ChangedKeychains>;
updateSingleKeychainPassword(params?: UpdateSingleKeychainPasswordOptions): Keychain;
create(params?: { seed?: Buffer; isRootKey?: boolean }): KeyPair;
add(params?: AddKeychainOptions): Promise<Keychain>;
createBitGo(params?: CreateBitGoOptions): Promise<Keychain>;
createBackup(params?: CreateBackupOptions): Promise<Keychain>;
getKeysForSigning(params?: GetKeysForSigningOptions): Promise<Keychain[]>;
createMpc(params: CreateMpcOptions): Promise<KeychainsTriplet>;
recreateMpc(params: RecreateMpcOptions): Promise<KeychainsTriplet>;
createTssBitGoKeyFromOvcShares(ovcOutput: OvcToBitGoJSON, enterprise?: string): Promise<BitGoKeyFromOvcShares>;
createUserKeychain(userPassword: string): Promise<Keychain>;
rotateKeychain(params: RotateKeychainOptions): Promise<Keychain>;
}