-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateWalletRoute.ts
More file actions
364 lines (351 loc) · 9.67 KB
/
generateWalletRoute.ts
File metadata and controls
364 lines (351 loc) · 9.67 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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
import { httpRequest, HttpResponse, httpRoute, optional } from '@api-ts/io-ts-http';
import * as t from 'io-ts';
import { ErrorResponses } from '../../shared/errors';
const WalletType = t.intersection([
t.type({
/**
* Wallet ID
* @example "59cd72485007a239fb00282ed480da1f"
* @pattern ^[0-9a-f]{32}$
*/
id: t.string,
/**
* Ids of users with access to the wallet
*/
users: t.array(
t.type({
user: t.string,
permissions: t.array(t.string),
}),
),
/**
* Name of the blockchain the wallet is on
* @example "tbtc4"
*/
coin: t.string,
/**
* Name the user assigned to the wallet
* @example "My TBTC4 Wallet"
*/
label: t.string,
/**
* Number of signatures required for the wallet to send
* @example 2
*/
m: t.number,
/**
* Number of signers on the wallet
* @example 3
*/
n: t.number,
/**
* Ids of wallet keys
* @example ["59cd72485007a239fb00282ed480da1f"]
*/
keys: t.array(t.string),
/**
* Signatures for the backup and BitGo public keys signed by the user key
*/
keySignatures: t.record(t.string, t.unknown),
enterprise: t.string,
organization: t.string,
bitgoOrg: t.string,
/**
* Tags set on the wallet
* @example ["59cd72485007a239fb00282ed480da1f"]
*/
tags: t.array(t.string),
/**
* Flag for disabling wallet transaction notifications
* @example false
*/
disableTransactionNotifications: t.boolean,
/**
* Freeze state (used to stop the wallet from spending)
* @example {}
*/
freeze: t.record(t.string, t.unknown),
/**
* Flag which indicates the wallet has been deleted
* @example false
*/
deleted: t.boolean,
/**
* Number of admin approvals required for an action to fire
* @example 1
*/
approvalsRequired: t.number,
/**
* Flag for identifying cold wallets
* @example false
*/
isCold: t.boolean,
/**
* Coin-specific data
*/
coinSpecific: t.record(t.string, t.unknown),
/**
* Admin data (wallet policies)
* @example {}
*/
admin: t.record(t.string, t.unknown),
/**
* Flag for allowing signing with backup key
* @example false
*/
allowBackupKeySigning: t.boolean,
clientFlags: t.array(t.string),
/**
* Flag indicating whether this wallet's user key is recoverable with the passphrase held by the user.
*/
recoverable: t.boolean,
/**
* Time when this wallet was created
*/
startDate: t.string,
/**
* Flag indicating that this wallet is large (more than 100,000 addresses). If this is set, some APIs may omit
* properties which are expensive to calculate for wallets with many addresses (for example, the total address
* counts returned by the List Addresses API).
*/
hasLargeNumberOfAddresses: t.boolean,
/**
* Custom configuration options for this wallet
*/
config: t.record(t.string, t.unknown),
/**
* Wallet balance as string
* @example "0"
*/
balanceString: t.string,
/**
* Confirmed wallet balance as string
* @example "0"
*/
confirmedBalanceString: t.string,
/**
* Spendable wallet balance as string
* @example "0"
*/
spendableBalanceString: t.string,
receiveAddress: t.type({
id: t.string,
address: t.string,
chain: t.number,
index: t.number,
coin: t.string,
wallet: t.string,
coinSpecific: t.record(t.string, t.unknown),
}),
}),
t.partial({
/**
* Wallet balance as number
* @example 0
*/
balance: t.number,
rbfBalance: t.number,
rbfBalanceString: t.string,
reservedBalanceString: t.string,
lockedBalanceString: t.string,
stakedBalanceString: t.string,
unspentCount: t.number,
pendingChainInitialization: t.boolean,
pendingEcdsaTssInitialization: t.boolean,
pendingApprovals: t.array(t.record(t.string, t.unknown)),
multisigType: t.string,
multisigTypeVersion: t.string,
type: t.string,
subType: t.string,
creator: t.string,
walletFullyCreated: t.boolean,
}),
]);
const UserKeychainType = t.intersection([
t.type({
/**
* Keychain ID
* @example "59cd72485007a239fb00282ed480da1f"
* @pattern ^[0-9a-f]{32}$
*/
id: t.string,
/**
* Party that created the key
* @example "user"
*/
source: t.string,
/**
* Keychain type (e.g. "independent" for onchain, "tss" for MPC)
*/
type: t.string,
}),
t.partial({
/**
* Public part of a key pair (onchain wallets)
* @example "xpub661MyMwAqRbcGMVhmc7wqQRYMtcX9LAvSj1pjB213y5TsrkV2uuzJjWnjBrT1FUeNWGPjaVm5p7o6jdNcQJrV1cy3a1R8NQ9m7LuYKA8RpH"
*/
pub: t.string,
/**
* Ethereum address corresponding to this keychain (onchain wallets)
* @example "0xf5b7cca8621691f9dde304cb7128b6bb3d409363"
*/
ethAddress: t.string,
/**
* Asset ticker for this keychain (onchain wallets)
*/
coin: t.string,
/**
* Common keychain string (TSS wallets)
*/
commonKeychain: t.string,
}),
]);
const BitgoKeychainType = t.intersection([
t.type({
/**
* Keychain ID
* @example "59cd72485007a239fb00282ed480da1f"
* @pattern ^[0-9a-f]{32}$
*/
id: t.string,
/**
* Party that created the key
* @example "bitgo"
*/
source: t.string,
/**
* Keychain type (e.g. "independent" for onchain, "tss" for MPC)
*/
type: t.string,
/**
* Flag for identifying keychain as created by BitGo
* @example true
*/
isBitGo: t.boolean,
/**
* Flag for identifying keychain as trust keychain
* @example false
*/
isTrust: t.boolean,
/**
* HSM type used for the BitGo key
* @example "institutional"
*/
hsmType: t.string,
}),
t.partial({
/**
* Public part of a key pair (onchain wallets)
*/
pub: t.string,
/**
* Ethereum address corresponding to this keychain (onchain wallets)
*/
ethAddress: t.string,
/**
* Common keychain string (TSS wallets)
*/
commonKeychain: t.string,
/**
* Whether VSS proof was verified (TSS wallets)
*/
verifiedVssProof: t.union([t.boolean, t.string]),
/**
* TSS key share metadata (TSS wallets)
*/
keyShares: t.array(t.record(t.string, t.unknown)),
/**
* Wallet HSM GPG public key signatures (TSS wallets)
*/
walletHSMGPGPublicKeySigs: t.string,
}),
]);
const GenerateWalletResponse: HttpResponse = {
200: t.type({
wallet: WalletType,
userKeychain: UserKeychainType,
backupKeychain: UserKeychainType,
bitgoKeychain: BitgoKeychainType,
responseType: t.string,
}),
...ErrorResponses,
};
const GenerateWalletRequest = {
/**
* A human-readable label for the wallet
* This will be displayed in the BitGo dashboard and API responses
* @example "My Wallet"
*/
label: t.string,
/**
* The type of multisig wallet to create
* - onchain: Traditional multisig wallets using on-chain scripts
* - tss: Threshold Signature Scheme wallets using MPC protocols
* If absent, BitGo uses the default wallet type for the asset
* @example "tss"
*/
multisigType: t.union([t.literal('onchain'), t.literal('tss')]),
/**
* Enterprise ID - Required for Ethereum wallets
* Ethereum wallets can only be created under an enterprise
* Each enterprise has a fee address which will be used to pay for transaction fees
* Your enterprise ID can be seen by clicking on the "Manage Organization" link on the enterprise dropdown
* @example "59cd72485007a239fb00282ed480da1f"
* @pattern ^[0-9a-f]{32}$
*/
enterprise: t.string,
/**
* Flag for disabling wallet transaction notifications
* When true, BitGo will not send email/SMS notifications for wallet transactions
* @example false
*/
disableTransactionNotifications: optional(t.boolean),
/**
* True, if the wallet type is a distributed-custodial
* If passed, you must also pass the 'enterprise' parameter
* Distributed custody allows multiple parties to share control of the wallet
* @example false
*/
isDistributedCustody: optional(t.boolean),
/**
* Specify the wallet creation contract version used when creating an Ethereum wallet contract
* - 0: Old wallet creation (legacy)
* - 1: New wallet creation, only deployed upon receiving funds
* - 2: Same functionality as v1 but with NFT support
* - 3: MPC wallets
* @example 1
* @minimum 0
* @maximum 3
*/
walletVersion: optional(t.number),
/**
* Reference wallet ID for EVM keyring wallets
* @example "59cd72485007a239fb00282ed480da1f"
* @pattern ^[0-9a-f]{32}$
*/
evmKeyRingReferenceWalletId: optional(t.string),
};
/**
* Advanced Wallets - Generate Wallet
*
* Create a new advanced wallet. Calling this endpoint does the following:
* 1. Generates user keychain in isolated AWM, then sends to key provider (encrypts private key, stores public key mapping).
* 2. Generates backup keychain in isolated AWM, then sends to key provider (encrypts private key, stores public key mapping).
* 3. Uploads the user and backup public keys to BitGo.
* 4. Creates the BitGo key on the BitGo service.
* 5. Creates the wallet on BitGo with the 3 keys.
*
* @tag Advanced Wallets
* @operationId advancedwallet.generate
* @public
*/
export const WalletGenerateRoute = httpRoute({
method: 'POST',
path: '/api/v1/{coin}/advancedwallet/generate',
request: httpRequest({
params: { coin: t.string },
body: GenerateWalletRequest,
}),
response: GenerateWalletResponse,
description: 'Generate a new wallet',
});