Skip to content

Commit 63433f6

Browse files
committed
docs(express): deriveLocalKeyChain type codec
Ticket: WP-6717
1 parent e136ac5 commit 63433f6

File tree

1 file changed

+34
-20
lines changed

1 file changed

+34
-20
lines changed

modules/express/src/typedRoutes/api/v1/deriveLocalKeyChain.ts

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,57 @@ import { BitgoExpressError } from '../../schemas/error';
66
* Request parameters for deriving a local keychain
77
*/
88
export const DeriveLocalKeyChainRequestBody = {
9-
/** The derivation path to use (e.g. 'm/0/1') */
9+
/** BIP32 derivation path (e.g., 'm/0/1' or '0/1'). Defines the hierarchical path from the parent key to derive the child key. */
1010
path: t.string,
11-
/** The extended private key to derive from (either xprv or xpub must be provided) */
11+
/** BIP32 extended private key in base58 format (e.g., 'xprv9s21...'). Provide this to derive both child xprv and xpub. Must provide either xprv or xpub, but not both. */
1212
xprv: optional(t.string),
13-
/** The extended public key to derive from (either xprv or xpub must be provided) */
13+
/** BIP32 extended public key in base58 format (e.g., 'xpub661MyMw...'). Provide this to derive only child xpub (cannot derive xprv from xpub). Must provide either xprv or xpub, but not both. */
1414
xpub: optional(t.string),
1515
};
1616

1717
/**
1818
* Response for deriving a local keychain
1919
*/
2020
export const DeriveLocalKeyChainResponse = t.type({
21-
/** The derivation path that was used */
21+
/** The BIP32 derivation path that was used (echoes the input path for verification) */
2222
path: t.string,
23-
/** The derived extended public key */
23+
/** The derived BIP32 extended public key in base58 format. Always returned regardless of whether xprv or xpub was provided as input. */
2424
xpub: t.string,
25-
/** The derived extended private key (only included if xprv was provided in the request) */
25+
/** The derived BIP32 extended private key in base58 format. Only included if an xprv was provided in the request (not derivable from xpub alone). */
2626
xprv: optional(t.string),
27-
/** The Ethereum address derived from the xpub (if available) */
27+
/** The Ethereum address (0x-prefixed hex format) derived from the xpub. Included when Ethereum address derivation is available for the key type. */
2828
ethAddress: optional(t.string),
2929
});
3030

3131
/**
32-
* Derive a local keychain
32+
* Derive a local keychain using BIP32 hierarchical deterministic derivation
3333
*
34-
* Locally derives a keychain from a top level BIP32 string (xprv or xpub), given a path.
35-
* This is useful for deriving child keys from a parent key without having to store the child keys.
34+
* Performs client-side BIP32 key derivation from a parent extended key (xprv or xpub) to a child key
35+
* at the specified derivation path. This operation is performed entirely locally on the BitGo Express
36+
* server without transmitting keys to BitGo's servers.
3637
*
37-
* The derivation process:
38-
* 1. Takes either an xprv (extended private key) or xpub (extended public key) as input
39-
* 2. Derives a child key at the specified path using BIP32 derivation
40-
* 3. Returns the derived xpub (and xprv if an xprv was provided)
41-
* 4. Also attempts to derive an Ethereum address from the xpub if possible
38+
* **Use Cases:**
39+
* - Derive child keys for specific addresses without storing all keys
40+
* - Generate deterministic key hierarchies from a master key
41+
* - Create segregated key paths for different purposes or accounts
4242
*
43-
* Note: You must provide either xprv or xpub, but not both. If xprv is provided,
44-
* both the derived xprv and xpub are returned. If xpub is provided, only the
45-
* derived xpub is returned.
43+
* **Derivation Process:**
44+
* 1. Accepts either an xprv (extended private key) or xpub (extended public key) as input
45+
* 2. Parses the BIP32 extended key and validates its format
46+
* 3. Applies BIP32 derivation algorithm at the specified path (e.g., 'm/0/1')
47+
* 4. Returns the derived xpub (and xprv if input was xprv)
48+
* 5. Optionally derives an Ethereum address from the xpub if applicable
49+
*
50+
* **Important Constraints:**
51+
* - You must provide exactly one of xprv OR xpub (not both, not neither)
52+
* - If xprv is provided: Returns both derived xprv and xpub
53+
* - If xpub is provided: Returns only derived xpub (cannot derive xprv from xpub)
54+
* - Ethereum address is only included if derivation is supported for the key type
55+
*
56+
* **Security Considerations:**
57+
* - This operation is performed locally and keys are never sent to BitGo's servers
58+
* - Extended private keys (xprv) should be handled with extreme care
59+
* - Consider encrypting xprv values before storage or transmission
4660
*
4761
* @operationId express.v1.keychain.derive
4862
* @tag express
@@ -54,9 +68,9 @@ export const PostDeriveLocalKeyChain = httpRoute({
5468
body: DeriveLocalKeyChainRequestBody,
5569
}),
5670
response: {
57-
/** Successfully derived keychain */
71+
/** Successfully derived child keychain. Returns the derived xpub (always) and xprv (if input was xprv), along with optional Ethereum address. */
5872
200: DeriveLocalKeyChainResponse,
59-
/** Invalid request or derivation fails */
73+
/** Invalid request parameters (e.g., missing path, invalid xprv/xpub format, both xprv and xpub provided, neither xprv nor xpub provided, or invalid derivation path). */
6074
400: BitgoExpressError,
6175
},
6276
});

0 commit comments

Comments
 (0)