mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-16 21:48:10 -07:00
global: private xpub support part 2
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import { isOutputDescriptor } from "../derive/index.js";
|
||||
|
||||
const EXTENDED_PUBLIC_KEY_PATTERN =
|
||||
/\b(?:xpub|ypub|zpub|tpub|upub|vpub)[1-9A-HJ-NP-Za-km-z]{20,}\b/;
|
||||
|
||||
/**
|
||||
* @param {string} text
|
||||
*/
|
||||
export function readWalletSourceText(text) {
|
||||
const value = text.trim();
|
||||
|
||||
if (isOutputDescriptor(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
const match = value.match(EXTENDED_PUBLIC_KEY_PATTERN);
|
||||
|
||||
if (match) {
|
||||
return match[0];
|
||||
}
|
||||
|
||||
throw new Error("Expected an xpub or descriptor");
|
||||
}
|
||||
Reference in New Issue
Block a user