|
| 1 | +import * as t from 'io-ts'; |
| 2 | +import { httpRoute, httpRequest, optional } from '@api-ts/io-ts-http'; |
| 3 | +import { BitgoExpressError } from '../../schemas/error'; |
| 4 | + |
| 5 | +export const SimpleCreateRequestBody = { |
| 6 | + /** wallet passphrase to encrypt user and backup keys with */ |
| 7 | + passphrase: t.string, |
| 8 | + /** wallet label, is shown in BitGo UI */ |
| 9 | + label: optional(t.string), |
| 10 | + /** backup keychain xpub, it is HIGHLY RECOMMENDED you generate this on a separate machine! |
| 11 | + * BITGO DOES NOT GUARANTEE SAFETY OF WALLETS WITH MULTIPLE KEYS CREATED ON THE SAME MACHINE */ |
| 12 | + backupXpub: optional(t.string), |
| 13 | + /* Provision backup key from this provider (KRS), e.g. "keyternal". Setting this value will create an instant-capable wallet. */ |
| 14 | + backupXpubProvider: optional(t.string), |
| 15 | + enterprise: optional(t.string), |
| 16 | + /** the code used to encrypt the wallet passcode used in the recovery process */ |
| 17 | + passcodeEncryptionCode: optional(t.string), |
| 18 | + disableTransactionNotifications: optional(t.boolean), |
| 19 | + disableKRSEmail: optional(t.boolean), |
| 20 | +}; |
| 21 | + |
| 22 | +/** |
| 23 | + * Create Wallet with Keychain |
| 24 | + * Create a new 2-of-3 wallet and it's associated keychains. |
| 25 | + * Returns the locally created keys with their encrypted xprvs. |
| 26 | + * **WARNING: BE SURE TO BACKUP! NOT DOING SO CAN RESULT IN LOSS OF FUNDS!** |
| 27 | + * |
| 28 | + * 1. Creates the user keychain locally on the client, and encrypts it with the provided passphrase |
| 29 | + * 2. If no xpub was provided, creates the backup keychain locally on the client, and encrypts it with the provided passphrase |
| 30 | + * 3. Uploads the encrypted user and backup keychains to BitGo |
| 31 | + * 4. Creates the BitGo key on the service |
| 32 | + * 5. Creates the wallet on BitGo with the 3 public keys above |
| 33 | + * |
| 34 | + * @operationId express.v1.wallet.simplecreate |
| 35 | + */ |
| 36 | +export const PostSimpleCreate = httpRoute({ |
| 37 | + path: '/api/v1/wallets/simplecreate', |
| 38 | + method: 'POST', |
| 39 | + request: httpRequest({ |
| 40 | + body: SimpleCreateRequestBody, |
| 41 | + }), |
| 42 | + response: { |
| 43 | + 200: t.type({ |
| 44 | + /** newly created wallet model object */ |
| 45 | + wallet: t.string, |
| 46 | + /** the newly created user keychain, which has an encrypted xprv stored on BitGo */ |
| 47 | + userKeychain: t.string, |
| 48 | + /** the newly created backup keychain */ |
| 49 | + backupKeychain: t.string, |
| 50 | + }), |
| 51 | + 400: BitgoExpressError, |
| 52 | + }, |
| 53 | +}); |
0 commit comments