{
  "version": 3,
  "sources": ["../src/accounts/privateKeyToAccount.ts", "../src/accounts/mnemonicToAccount.ts", "../src/accounts/mnemonicToBitcoinKeys.ts", "../src/accounts/toAccount.ts"],
  "sourcesContent": [
    "import { hmac } from \"@noble/hashes/hmac.js\";\nimport { sha256 } from \"@noble/hashes/sha2.js\";\nimport { etc, getPublicKey as nobleGetPublicKey, sign } from \"@noble/secp256k1\";\nimport { c32address } from \"../utils/c32.ts\";\nimport { bytesToHex, hexToBytes, without0x } from \"../utils/encoding.ts\";\nimport { hash160 } from \"../utils/hash.ts\";\nimport type { LocalAccount } from \"./types.ts\";\n\nfunction ensureSyncSigning() {\n\tif (!etc.hmacSha256Sync) {\n\t\tetc.hmacSha256Sync = (key: Uint8Array, ...msgs: Uint8Array[]) => {\n\t\t\tconst h = hmac.create(sha256, key);\n\t\t\tfor (const msg of msgs) h.update(msg);\n\t\t\treturn h.digest();\n\t\t};\n\t}\n}\n\nconst PRIVATE_KEY_COMPRESSED_LENGTH = 33;\n\nexport function privateKeyToAccount(\n\tprivateKey: string | Uint8Array,\n\toptions?: { addressVersion?: number },\n): LocalAccount {\n\tensureSyncSigning();\n\tconst keyBytes = normalizePrivateKey(privateKey);\n\tconst rawKey = keyBytes.slice(0, 32);\n\n\t// Always derive compressed public key\n\tconst publicKeyBytes = nobleGetPublicKey(rawKey, true);\n\tconst publicKeyHex = bytesToHex(publicKeyBytes);\n\n\t// Default to mainnet single-sig (22)\n\tconst addressVersion = options?.addressVersion ?? 22;\n\tconst address = c32address(\n\t\taddressVersion,\n\t\tbytesToHex(hash160(publicKeyBytes)),\n\t);\n\n\treturn {\n\t\ttype: \"local\",\n\t\taddress,\n\t\tpublicKey: publicKeyHex,\n\n\t\tsign(hash: Uint8Array): Uint8Array {\n\t\t\tconst sig = sign(hash, rawKey, { lowS: true });\n\t\t\tconst result = new Uint8Array(65);\n\t\t\tresult[0] = sig.recovery;\n\t\t\tresult.set(sig.toCompactRawBytes(), 1);\n\t\t\treturn result;\n\t\t},\n\n\t\tsignMessage(message: string | Uint8Array): string {\n\t\t\tconst msgBytes =\n\t\t\t\ttypeof message === \"string\"\n\t\t\t\t\t? new TextEncoder().encode(message)\n\t\t\t\t\t: message;\n\t\t\tconst msgHash = sha256(msgBytes);\n\t\t\tconst sigBytes = this.sign(msgHash);\n\t\t\treturn bytesToHex(sigBytes);\n\t\t},\n\t};\n}\n\nfunction normalizePrivateKey(key: string | Uint8Array): Uint8Array {\n\tif (typeof key === \"string\") {\n\t\treturn hexToBytes(without0x(key));\n\t}\n\treturn key;\n}\n\n/** Append 0x01 suffix if not already compressed */\nexport function compressPrivateKey(key: string | Uint8Array): string {\n\tconst hex = typeof key === \"string\" ? without0x(key) : bytesToHex(key);\n\tif (hex.length === PRIVATE_KEY_COMPRESSED_LENGTH * 2) return hex;\n\treturn `${hex}01`;\n}\n",
    "import { HDKey } from \"@scure/bip32\";\nimport { mnemonicToSeedSync } from \"@scure/bip39\";\nimport { bytesToHex } from \"../utils/encoding.ts\";\nimport {\n\tcompressPrivateKey,\n\tprivateKeyToAccount,\n} from \"./privateKeyToAccount.ts\";\nimport type { LocalAccount } from \"./types.ts\";\n\nconst STX_DERIVATION_PATH = \"m/44'/5757'/0'/0\";\n\nexport function mnemonicToAccount(\n\tmnemonic: string,\n\toptions?: {\n\t\taccountIndex?: number;\n\t\taddressVersion?: number;\n\t},\n): LocalAccount {\n\tconst { accountIndex = 0, addressVersion } = options ?? {};\n\n\tconst seed = mnemonicToSeedSync(mnemonic);\n\tconst root = HDKey.fromMasterSeed(seed);\n\tconst child = root.derive(`${STX_DERIVATION_PATH}/${accountIndex}`);\n\n\tif (!child.privateKey) throw new Error(\"Failed to derive private key\");\n\n\tconst privateKeyHex = compressPrivateKey(bytesToHex(child.privateKey));\n\treturn privateKeyToAccount(privateKeyHex, { addressVersion });\n}\n",
    "import { HDKey } from \"@scure/bip32\";\nimport { mnemonicToSeedSync } from \"@scure/bip39\";\nimport {\n\tpublicKeyToP2trAddress,\n\tpublicKeyToP2wpkhAddress,\n} from \"../bitcoin/address.ts\";\nimport type { BitcoinNetwork } from \"../bitcoin/constants.ts\";\nimport { bytesToHex } from \"../utils/encoding.ts\";\n\nexport type BitcoinKeyType = \"p2wpkh\" | \"p2tr\";\n\nexport type MnemonicToBitcoinKeysOptions = {\n\t/** `'p2wpkh'` (BIP84, `bc1q…`) or `'p2tr'` (BIP86, `bc1p…`). */\n\ttype: BitcoinKeyType;\n\tnetwork?: BitcoinNetwork;\n\taccountIndex?: number;\n\t/** 0 = receive chain, 1 = change chain. */\n\tchangeIndex?: number;\n\taddressIndex?: number;\n};\n\nexport type BitcoinKeys = {\n\t/** 32-byte private key, hex. */\n\tprivateKey: string;\n\t/** 33-byte compressed public key, hex. */\n\tpublicKey: string;\n\taddress: string;\n\t/** Full BIP84/BIP86 derivation path. */\n\tpath: string;\n};\n\nconst PURPOSE: Record<BitcoinKeyType, number> = { p2wpkh: 84, p2tr: 86 };\n\n/**\n * Derive Bitcoin keys + address from the same mnemonic that backs a Stacks\n * account — BIP84 (native segwit) or BIP86 (taproot) paths, matching what\n * Leather/Xverse derive for the paired BTC account. Pure derivation: no\n * Bitcoin transaction building or signing.\n *\n * @example\n * const btc = mnemonicToBitcoinKeys(mnemonic, { type: \"p2tr\" });\n * btc.address; // bc1p…\n * btc.path;    // m/86'/0'/0'/0/0\n */\nexport function mnemonicToBitcoinKeys(\n\tmnemonic: string,\n\toptions: MnemonicToBitcoinKeysOptions,\n): BitcoinKeys {\n\tconst {\n\t\ttype,\n\t\tnetwork = \"mainnet\",\n\t\taccountIndex = 0,\n\t\tchangeIndex = 0,\n\t\taddressIndex = 0,\n\t} = options;\n\n\t// BIP44 coin type: 0' mainnet, 1' testnet/regtest.\n\tconst coinType = network === \"mainnet\" ? 0 : 1;\n\tconst path = `m/${PURPOSE[type]}'/${coinType}'/${accountIndex}'/${changeIndex}/${addressIndex}`;\n\n\tconst seed = mnemonicToSeedSync(mnemonic);\n\tconst child = HDKey.fromMasterSeed(seed).derive(path);\n\tif (!child.privateKey || !child.publicKey)\n\t\tthrow new Error(\"Failed to derive Bitcoin key\");\n\n\tconst address =\n\t\ttype === \"p2wpkh\"\n\t\t\t? publicKeyToP2wpkhAddress(child.publicKey, network)\n\t\t\t: publicKeyToP2trAddress(child.publicKey, network);\n\n\treturn {\n\t\tprivateKey: bytesToHex(child.privateKey),\n\t\tpublicKey: bytesToHex(child.publicKey),\n\t\taddress,\n\t\tpath,\n\t};\n}\n",
    "import type { AccountSource, CustomAccount } from \"./types.ts\";\n\nexport function toAccount(source: AccountSource): CustomAccount {\n\treturn {\n\t\ttype: \"custom\",\n\t\taddress: source.address,\n\t\tpublicKey: source.publicKey,\n\t\tsign: source.sign,\n\t};\n}\n"
  ],
  "mappings": ";;;;;;;;;;;;;AAAqB,IAArB;AACuB,IAAvB;AAC6D,IAA7D;AAMA,SAAS,iBAAiB,GAAG;AAAA,EAC5B,IAAI,CAAC,qBAAI,gBAAgB;AAAA,IACxB,qBAAI,iBAAiB,CAAC,QAAoB,SAAuB;AAAA,MAChE,MAAM,IAAI,iBAAK,OAAO,oBAAQ,GAAG;AAAA,MACjC,WAAW,OAAO;AAAA,QAAM,EAAE,OAAO,GAAG;AAAA,MACpC,OAAO,EAAE,OAAO;AAAA;AAAA,EAElB;AAAA;AAGD,IAAM,gCAAgC;AAE/B,SAAS,mBAAmB,CAClC,YACA,SACe;AAAA,EACf,kBAAkB;AAAA,EAClB,MAAM,WAAW,oBAAoB,UAAU;AAAA,EAC/C,MAAM,SAAS,SAAS,MAAM,GAAG,EAAE;AAAA,EAGnC,MAAM,iBAAiB,8BAAkB,QAAQ,IAAI;AAAA,EACrD,MAAM,eAAe,WAAW,cAAc;AAAA,EAG9C,MAAM,iBAAiB,SAAS,kBAAkB;AAAA,EAClD,MAAM,UAAU,WACf,gBACA,WAAW,QAAQ,cAAc,CAAC,CACnC;AAAA,EAEA,OAAO;AAAA,IACN,MAAM;AAAA,IACN;AAAA,IACA,WAAW;AA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