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

Method parseSecret

packages/bitcore-wallet-client/src/lib/api.ts:701–732  ·  view source on GitHub ↗
(secret)

Source from the content-addressed store, hash-verified

699 }
700
701 static parseSecret(secret) {
702 $.checkArgument(secret);
703
704 const split = (str, indexes) => {
705 const parts = [];
706 indexes.push(str.length);
707 for (let i = 0; i < indexes.length; i++) {
708 parts.push(str.substring(i == 0 ? 0 : indexes[i - 1], indexes[i]));
709 }
710 return parts;
711 };
712
713 try {
714 const secretSplit = split(secret, [22, 74, 75]);
715 const widBase58 = secretSplit[0].replace(/0/g, '');
716 const widHex = Bitcore.encoding.Base58.decode(widBase58).toString('hex');
717 const walletId = split(widHex, [8, 12, 16, 20]).join('-');
718
719 const walletPrivKey = Bitcore.PrivateKey.fromString(secretSplit[1]);
720 const network = NetworkChar[secretSplit[2]] || 'livenet';
721 const coin = secretSplit[3] || 'btc';
722
723 return {
724 walletId,
725 walletPrivKey,
726 coin,
727 network
728 };
729 } catch {
730 throw new Error('Invalid secret');
731 }
732 }
733
734 static getRawTx(txp) {
735 const t = Utils.buildTx(txp);

Callers 3

joinMultiSigWalletFunction · 0.80
api.test.tsFile · 0.80
joinWalletMethod · 0.80

Calls 2

fromStringMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected