(
/** Optional message to display to the user. Otherwise, defaults to 'Password:' */
msg?: string,
/** Optional settings for the password prompt. */
opts?: {
/** Minimum length for the password. Defaults to 0. */
minLength?: number;
/** Whether the password input should be hidden. Defaults to true. */
hidden?: boolean;
/** Custom validation function for the password input. Note, this does NOT override the minimum length check. */
validate?: (input: string) => string | null;
}
)
| 65 | * @returns The entered password as a string. |
| 66 | */ |
| 67 | export async function getPassword( |
| 68 | /** Optional message to display to the user. Otherwise, defaults to 'Password:' */ |
| 69 | msg?: string, |
| 70 | /** Optional settings for the password prompt. */ |
| 71 | opts?: { |
| 72 | /** Minimum length for the password. Defaults to 0. */ |
| 73 | minLength?: number; |
| 74 | /** Whether the password input should be hidden. Defaults to true. */ |
| 75 | hidden?: boolean; |
| 76 | /** Custom validation function for the password input. Note, this does NOT override the minimum length check. */ |
| 77 | validate?: (input: string) => string | null; |
| 78 | } |
| 79 | ): Promise<string> { |
| 80 | opts = opts || {}; |
| 81 | opts.minLength = opts.minLength ?? 0; |
| 82 | const hidden = opts.hidden ?? true; |
| 83 | |
| 84 | const password = await prompt.password({ |
| 85 | message: (msg || 'Password:') + (hidden ? ' (hidden)' : ''), |
| 86 | mask: hidden ? '' : undefined, |
| 87 | clearOnError: hidden, |
| 88 | validate: (input) => { |
| 89 | if (input?.length < opts.minLength) { |
| 90 | return `Password must be at least ${opts.minLength} characters long.`; |
| 91 | } |
| 92 | return opts.validate?.(input); |
| 93 | } |
| 94 | }); |
| 95 | if (prompt.isCancel(password)) { |
| 96 | throw new UserCancelled(); |
| 97 | } |
| 98 | return password as string; |
| 99 | }; |
| 100 | |
| 101 | /** |
| 102 | * Prompts the user to enter an M-of-N scheme for multi-signature wallets, with validation. |
no outgoing calls
no test coverage detected