File tree Expand file tree Collapse file tree 3 files changed +21
-36
lines changed
Expand file tree Collapse file tree 3 files changed +21
-36
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,11 @@ export type DerivedAccount = Readonly<{
1212 account : HDAccount ;
1313 derivation : DerivationInfo ;
1414 /**
15- * Derived private key (hex, 0x-prefixed) if available .
15+ * Derived private key (hex, 0x-prefixed).
1616 *
1717 * IMPORTANT: Never log this unless explicitly gated by config.
1818 */
19- privateKey ? : Hex ;
19+ privateKey : Hex ;
2020} > ;
2121
2222export function derivePath ( index : number ) : `m/44'/60'/${string } ` {
@@ -45,18 +45,17 @@ export function deriveAccountFromMnemonic(
4545 ? toHex ( hdKey . privateKey )
4646 : undefined ;
4747
48- const base : {
49- account : HDAccount ;
50- derivation : DerivationInfo ;
51- privateKey ?: Hex ;
52- } = {
48+ if ( ! privateKey ) {
49+ // Sanity check: `mnemonicToAccount(...).getHdKey()` should normally yield a private key
50+ // for a valid mnemonic + derivation path. If this happens, something is unexpectedly
51+ // wrong (or the underlying library behavior changed), and callers cannot proceed
52+ // because they always require a signer.
53+ throw new Error ( "Derived account has no privateKey available" ) ;
54+ }
55+
56+ return {
5357 account,
5458 derivation : { index, path } ,
59+ privateKey,
5560 } ;
56-
57- if ( privateKey ) {
58- base . privateKey = privateKey ;
59- }
60-
61- return base ;
6261}
Original file line number Diff line number Diff line change @@ -102,9 +102,6 @@ export async function deriveAccount(
102102 cacheAccountIndex ( scenarioVars , selection ) ;
103103
104104 const derived = deriveAccountFromMnemonic ( mnemonic , selection . index ) ;
105- if ( ! derived . privateKey ) {
106- throw new Error ( "Derived account has no privateKey available" ) ;
107- }
108105
109106 persistVars ( context , {
110107 privateKey : derived . privateKey ,
Original file line number Diff line number Diff line change @@ -46,26 +46,15 @@ export async function deriveAndPrint(
4646
4747 const printPk = readBoolEnv ( "PRINT_DERIVED_PRIVATE_KEY" ) ;
4848 if ( printPk ) {
49- if ( ! derived . privateKey ) {
50- logger . warn (
51- {
52- index : selection . index ,
53- path : derived . derivation . path ,
54- address : derived . account . address ,
55- } ,
56- "derived account has no privateKey available to print"
57- ) ;
58- } else {
59- logger . info (
60- {
61- index : selection . index ,
62- path : derived . derivation . path ,
63- address : derived . account . address ,
64- privateKey : derived . privateKey ,
65- } ,
66- "derived account (PRINT_DERIVED_PRIVATE_KEY enabled)"
67- ) ;
68- }
49+ logger . info (
50+ {
51+ index : selection . index ,
52+ path : derived . derivation . path ,
53+ address : derived . account . address ,
54+ privateKey : derived . privateKey ,
55+ } ,
56+ "derived account (PRINT_DERIVED_PRIVATE_KEY enabled)"
57+ ) ;
6958 } else {
7059 logger . info (
7160 {
You can’t perform that action at this time.
0 commit comments