MCPcopy Create free account
hub / github.com/bitpay/bitcore / getPassword

Function getPassword

packages/bitcore-cli/src/prompts.ts:67–99  ·  view source on GitHub ↗
(
  /** 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;
  }
)

Source from the content-addressed store, hash-verified

65 * @returns The entered password as a string.
66 */
67export 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.

Callers 13

loadMethod · 0.90
saveMethod · 0.90
exportMethod · 0.90
importMethod · 0.90
getPasswordWithRetryMethod · 0.90
getXPrivKeyMethod · 0.90
importWalletFunction · 0.90
exportWalletFunction · 0.90
joinThresholdSigWalletFunction · 0.90
joinMultiSigWalletFunction · 0.90
createMultiSigWalletFunction · 0.90
createSingleSigWalletFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected