You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: modules/express/src/typedRoutes/api/v1/deriveLocalKeyChain.ts
+34-20Lines changed: 34 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -6,43 +6,57 @@ import { BitgoExpressError } from '../../schemas/error';
6
6
* Request parameters for deriving a local keychain
7
7
*/
8
8
exportconstDeriveLocalKeyChainRequestBody={
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. */
10
10
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. */
12
12
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. */
14
14
xpub: optional(t.string),
15
15
};
16
16
17
17
/**
18
18
* Response for deriving a local keychain
19
19
*/
20
20
exportconstDeriveLocalKeyChainResponse=t.type({
21
-
/** The derivation path that was used */
21
+
/** The BIP32 derivation path that was used (echoes the input path for verification) */
22
22
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. */
24
24
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). */
26
26
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. */
28
28
ethAddress: optional(t.string),
29
29
});
30
30
31
31
/**
32
-
* Derive a local keychain
32
+
* Derive a local keychain using BIP32 hierarchical deterministic derivation
33
33
*
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.
36
37
*
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
42
42
*
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
/** Successfully derived child keychain. Returns the derived xpub (always) and xprv (if input was xprv), along with optional Ethereum address. */
58
72
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). */
0 commit comments