[{"data":1,"prerenderedAt":838},["ShallowReactive",2],{"navigation_docs":3,"-blockchains-bitcoin":72,"-blockchains-bitcoin-surround":833},[4,32],{"title":5,"path":6,"stem":7,"children":8,"icon":31},"Guide","\u002Fguide","1.guide\u002F1.index",[9,11,15,19,23,27],{"title":10,"path":6,"stem":7},"Getting Started",{"title":12,"path":13,"stem":14},"Working with Keys","\u002Fguide\u002Fkeys","1.guide\u002F2.keys",{"title":16,"path":17,"stem":18},"Working with Addresses","\u002Fguide\u002Faddresses","1.guide\u002F3.addresses",{"title":20,"path":21,"stem":22},"Generating Wallets","\u002Fguide\u002Fwallets","1.guide\u002F4.wallets",{"title":24,"path":25,"stem":26},"Working with EVM Chains","\u002Fguide\u002Fevm","1.guide\u002F5.evm",{"title":28,"path":29,"stem":30},"Creating Custom Blockchains","\u002Fguide\u002Fcustom","1.guide\u002F6.custom","i-lucide-book-open",{"title":33,"path":34,"stem":35,"children":36,"icon":71},"Blockchains","\u002Fblockchains","2.blockchains\u002F0.index",[37,39,43,47,51,55,59,63,67],{"title":38,"path":34,"stem":35},"Overview",{"title":40,"path":41,"stem":42},"Aptos","\u002Fblockchains\u002Faptos","2.blockchains\u002Faptos",{"title":44,"path":45,"stem":46},"Base","\u002Fblockchains\u002Fbase","2.blockchains\u002Fbase",{"title":48,"path":49,"stem":50},"Bitcoin","\u002Fblockchains\u002Fbitcoin","2.blockchains\u002Fbitcoin",{"title":52,"path":53,"stem":54},"Cardano","\u002Fblockchains\u002Fcardano","2.blockchains\u002Fcardano",{"title":56,"path":57,"stem":58},"Ethereum","\u002Fblockchains\u002Fethereum","2.blockchains\u002Fethereum",{"title":60,"path":61,"stem":62},"Solana","\u002Fblockchains\u002Fsolana","2.blockchains\u002Fsolana",{"title":64,"path":65,"stem":66},"Sui","\u002Fblockchains\u002Fsui","2.blockchains\u002Fsui",{"title":68,"path":69,"stem":70},"TRON","\u002Fblockchains\u002Ftron","2.blockchains\u002Ftron","i-lucide-boxes",{"id":73,"title":48,"body":74,"description":826,"extension":827,"links":828,"meta":829,"navigation":148,"path":49,"seo":831,"stem":50,"__hash__":832},"docs\u002F2.blockchains\u002Fbitcoin.md",{"type":75,"value":76,"toc":818},"minimark",[77,84,89,226,237,241,382,544,559,563,654,657,661,667,771,774,778,796,800,814],[78,79],"chain-facts",{"coin":80,"curve":81,"driver":82,"formats":83},"0","secp256k1","bitcoin","legacy, p2sh, segwit, p2wsh, taproot",[85,86,88],"h2",{"id":87},"load-it","Load it",[90,91,96],"pre",{"className":92,"code":93,"language":94,"meta":95,"style":95},"language-js shiki shiki-themes github-light github-light poimandres","import { useBlockchain, blockchains } from \"@agntn\u002Fkeys\";\n\nconst bitcoinChain = useBlockchain(await blockchains.bitcoin()());\nconst testnetChain = useBlockchain(await blockchains.bitcoin({ network: \"testnet\" })());\n","js","",[97,98,99,143,150,185],"code",{"__ignoreMap":95},[100,101,104,108,112,116,119,122,125,129,133,137,140],"span",{"class":102,"line":103},"line",1,[100,105,107],{"class":106},"sP0CR","import",[100,109,111],{"class":110},"sKlNE"," {",[100,113,115],{"class":114},"snHMy"," useBlockchain",[100,117,118],{"class":110},",",[100,120,121],{"class":114}," blockchains",[100,123,124],{"class":110}," }",[100,126,128],{"class":127},"stCPd"," from",[100,130,132],{"class":131},"scVjq"," \"",[100,134,136],{"class":135},"sQ7BG","@agntn\u002Fkeys",[100,138,139],{"class":131},"\"",[100,141,142],{"class":110},";\n",[100,144,146],{"class":102,"line":145},2,[100,147,149],{"emptyLinePlaceholder":148},true,"\n",[100,151,153,157,161,164,167,170,174,177,180,182],{"class":102,"line":152},3,[100,154,156],{"class":155},"s1TYA","const",[100,158,160],{"class":159},"saoiD"," bitcoinChain",[100,162,163],{"class":155}," =",[100,165,115],{"class":166},"sULi6",[100,168,169],{"class":110},"(",[100,171,173],{"class":172},"sZW6a","await",[100,175,121],{"class":176},"spVlQ",[100,178,179],{"class":110},".",[100,181,82],{"class":166},[100,183,184],{"class":110},"()());\n",[100,186,188,190,193,195,197,199,201,203,205,207,210,213,216,218,221,223],{"class":102,"line":187},4,[100,189,156],{"class":155},[100,191,192],{"class":159}," testnetChain",[100,194,163],{"class":155},[100,196,115],{"class":166},[100,198,169],{"class":110},[100,200,173],{"class":172},[100,202,121],{"class":176},[100,204,179],{"class":110},[100,206,82],{"class":166},[100,208,209],{"class":110},"({",[100,211,212],{"class":114}," network",[100,214,215],{"class":110},":",[100,217,132],{"class":131},[100,219,220],{"class":135},"testnet",[100,222,139],{"class":131},[100,224,225],{"class":110}," })());\n",[227,228,229,230,233,234,179],"p",{},"Or import the class directly from ",[97,231,232],{},"@agntn\u002Fkeys\u002Fblockchains\u002Fbitcoin"," and call ",[97,235,236],{},"new Bitcoin()",[85,238,240],{"id":239},"five-formats","Five formats",[242,243,244,263],"table",{},[245,246,247],"thead",{},[248,249,250,254,257,260],"tr",{},[251,252,253],"th",{},"Type",[251,255,256],{},"Mainnet",[251,258,259],{},"Testnet",[251,261,262],{},"Encoding",[264,265,266,299,324,344,362],"tbody",{},[248,267,268,275,280,289],{},[269,270,271,274],"td",{},[97,272,273],{},"legacy"," (default)",[269,276,277],{},[97,278,279],{},"1...",[269,281,282,285,286],{},[97,283,284],{},"m..."," or ",[97,287,288],{},"n...",[269,290,291,292,295,296],{},"base58check, version ",[97,293,294],{},"0x00"," \u002F ",[97,297,298],{},"0x6f",[248,300,301,306,311,316],{},[269,302,303],{},[97,304,305],{},"p2sh",[269,307,308],{},[97,309,310],{},"3...",[269,312,313],{},[97,314,315],{},"2...",[269,317,291,318,295,321],{},[97,319,320],{},"0x05",[97,322,323],{},"0xc4",[248,325,326,331,336,341],{},[269,327,328],{},[97,329,330],{},"segwit",[269,332,333],{},[97,334,335],{},"bc1q...",[269,337,338],{},[97,339,340],{},"tb1q...",[269,342,343],{},"bech32, witness v0, P2WPKH",[248,345,346,351,355,359],{},[269,347,348],{},[97,349,350],{},"p2wsh",[269,352,353],{},[97,354,335],{},[269,356,357],{},[97,358,340],{},[269,360,361],{},"bech32, witness v0, script hash",[248,363,364,369,374,379],{},[269,365,366],{},[97,367,368],{},"taproot",[269,370,371],{},[97,372,373],{},"bc1p...",[269,375,376],{},[97,377,378],{},"tb1p...",[269,380,381],{},"bech32m, witness v1",[90,383,385],{"className":92,"code":384,"language":94,"meta":95,"style":95},"const publicKey = bitcoinChain.getKeyPublic(privateKey);\n\nbitcoinChain.getAddress(publicKey); \u002F\u002F 1...\nbitcoinChain.getAddress(publicKey, \"p2sh\"); \u002F\u002F 3...\nbitcoinChain.getAddress(publicKey, \"segwit\"); \u002F\u002F bc1q...\nbitcoinChain.getAddress(publicKey, \"taproot\"); \u002F\u002F bc1p...\n\nbitcoinChain.generateWallet({}, \"segwit\"); \u002F\u002F whole wallet, segwit address\n",[97,386,387,411,415,437,463,489,515,520],{"__ignoreMap":95},[100,388,389,391,394,396,398,400,403,405,408],{"class":102,"line":103},[100,390,156],{"class":155},[100,392,393],{"class":159}," publicKey",[100,395,163],{"class":155},[100,397,160],{"class":176},[100,399,179],{"class":110},[100,401,402],{"class":166},"getKeyPublic",[100,404,169],{"class":110},[100,406,407],{"class":176},"privateKey",[100,409,410],{"class":110},");\n",[100,412,413],{"class":102,"line":145},[100,414,149],{"emptyLinePlaceholder":148},[100,416,417,420,422,425,427,430,433],{"class":102,"line":152},[100,418,419],{"class":176},"bitcoinChain",[100,421,179],{"class":110},[100,423,424],{"class":166},"getAddress",[100,426,169],{"class":110},[100,428,429],{"class":176},"publicKey",[100,431,432],{"class":110},"); ",[100,434,436],{"class":435},"sjhu3","\u002F\u002F 1...\n",[100,438,439,441,443,445,447,449,452,454,456,458,460],{"class":102,"line":187},[100,440,419],{"class":176},[100,442,179],{"class":110},[100,444,424],{"class":166},[100,446,169],{"class":110},[100,448,429],{"class":176},[100,450,451],{"class":110},", ",[100,453,139],{"class":131},[100,455,305],{"class":135},[100,457,139],{"class":131},[100,459,432],{"class":110},[100,461,462],{"class":435},"\u002F\u002F 3...\n",[100,464,466,468,470,472,474,476,478,480,482,484,486],{"class":102,"line":465},5,[100,467,419],{"class":176},[100,469,179],{"class":110},[100,471,424],{"class":166},[100,473,169],{"class":110},[100,475,429],{"class":176},[100,477,451],{"class":110},[100,479,139],{"class":131},[100,481,330],{"class":135},[100,483,139],{"class":131},[100,485,432],{"class":110},[100,487,488],{"class":435},"\u002F\u002F bc1q...\n",[100,490,492,494,496,498,500,502,504,506,508,510,512],{"class":102,"line":491},6,[100,493,419],{"class":176},[100,495,179],{"class":110},[100,497,424],{"class":166},[100,499,169],{"class":110},[100,501,429],{"class":176},[100,503,451],{"class":110},[100,505,139],{"class":131},[100,507,368],{"class":135},[100,509,139],{"class":131},[100,511,432],{"class":110},[100,513,514],{"class":435},"\u002F\u002F bc1p...\n",[100,516,518],{"class":102,"line":517},7,[100,519,149],{"emptyLinePlaceholder":148},[100,521,523,525,527,530,533,535,537,539,541],{"class":102,"line":522},8,[100,524,419],{"class":176},[100,526,179],{"class":110},[100,528,529],{"class":166},"generateWallet",[100,531,532],{"class":110},"({}, ",[100,534,139],{"class":131},[100,536,330],{"class":135},[100,538,139],{"class":131},[100,540,432],{"class":110},[100,542,543],{"class":435},"\u002F\u002F whole wallet, segwit address\n",[227,545,546,547,550,551,554,555,558],{},"Legacy and p2sh both start from ",[97,548,549],{},"RIPEMD160(SHA256(pubkey))",". p2sh wraps that hash in a ",[97,552,553],{},"0 \u003C20 bytes>"," redeem script and hashes again. Segwit puts the same 20 bytes behind witness version 0. Taproot is the real thing: the x only key gets tweaked with ",[97,556,557],{},"TapTweak"," per BIP341, so the address matches what Bitcoin Core derives for a key path spend, not a shortcut that only looks right.",[85,560,562],{"id":561},"validation","Validation",[90,564,566],{"className":92,"code":565,"language":94,"meta":95,"style":95},"bitcoinChain.validateAddress(\"1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2\"); \u002F\u002F true\nbitcoinChain.validateAddress(\"3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy\"); \u002F\u002F true\nbitcoinChain.validateAddress(\"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4\"); \u002F\u002F true\nbitcoinChain.validateAddress(\"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0\"); \u002F\u002F true\n",[97,567,568,591,612,633],{"__ignoreMap":95},[100,569,570,572,574,577,579,581,584,586,588],{"class":102,"line":103},[100,571,419],{"class":176},[100,573,179],{"class":110},[100,575,576],{"class":166},"validateAddress",[100,578,169],{"class":110},[100,580,139],{"class":131},[100,582,583],{"class":135},"1BvBMSEYstWetqTFn5Au4m4GFg7xJaNVN2",[100,585,139],{"class":131},[100,587,432],{"class":110},[100,589,590],{"class":435},"\u002F\u002F true\n",[100,592,593,595,597,599,601,603,606,608,610],{"class":102,"line":145},[100,594,419],{"class":176},[100,596,179],{"class":110},[100,598,576],{"class":166},[100,600,169],{"class":110},[100,602,139],{"class":131},[100,604,605],{"class":135},"3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy",[100,607,139],{"class":131},[100,609,432],{"class":110},[100,611,590],{"class":435},[100,613,614,616,618,620,622,624,627,629,631],{"class":102,"line":152},[100,615,419],{"class":176},[100,617,179],{"class":110},[100,619,576],{"class":166},[100,621,169],{"class":110},[100,623,139],{"class":131},[100,625,626],{"class":135},"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",[100,628,139],{"class":131},[100,630,432],{"class":110},[100,632,590],{"class":435},[100,634,635,637,639,641,643,645,648,650,652],{"class":102,"line":187},[100,636,419],{"class":176},[100,638,179],{"class":110},[100,640,576],{"class":166},[100,642,169],{"class":110},[100,644,139],{"class":131},[100,646,647],{"class":135},"bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0",[100,649,139],{"class":131},[100,651,432],{"class":110},[100,653,590],{"class":435},[227,655,656],{},"The prefix picks the decoder, then the checksum has to hold. A mainnet driver rejects testnet addresses and the other way round, which is what you want and occasionally what surprises you in a test.",[85,658,660],{"id":659},"mnemonics","Mnemonics",[227,662,663,666],{},[97,664,665],{},"deriveHDWallet"," reads the BIP43 purpose when you do not pass an address type:",[90,668,670],{"className":92,"code":669,"language":94,"meta":95,"style":95},"bitcoinChain.deriveHDWallet(mnemonic, \"m\u002F84'\u002F0'\u002F0'\u002F0\u002F0\").address; \u002F\u002F bc1q..., segwit from purpose 84\nbitcoinChain.deriveHDWallet(mnemonic, \"m\u002F86'\u002F0'\u002F0'\u002F0\u002F0\").address; \u002F\u002F bc1p..., taproot from purpose 86\nbitcoinChain.deriveHDWallet(mnemonic, \"m\u002F44'\u002F0'\u002F0'\u002F0\u002F0\", {}, \"segwit\"); \u002F\u002F explicit type wins\n",[97,671,672,706,736],{"__ignoreMap":95},[100,673,674,676,678,680,682,685,687,689,692,694,697,700,703],{"class":102,"line":103},[100,675,419],{"class":176},[100,677,179],{"class":110},[100,679,665],{"class":166},[100,681,169],{"class":110},[100,683,684],{"class":176},"mnemonic",[100,686,451],{"class":110},[100,688,139],{"class":131},[100,690,691],{"class":135},"m\u002F84'\u002F0'\u002F0'\u002F0\u002F0",[100,693,139],{"class":131},[100,695,696],{"class":110},").",[100,698,699],{"class":176},"address",[100,701,702],{"class":110},"; ",[100,704,705],{"class":435},"\u002F\u002F bc1q..., segwit from purpose 84\n",[100,707,708,710,712,714,716,718,720,722,725,727,729,731,733],{"class":102,"line":145},[100,709,419],{"class":176},[100,711,179],{"class":110},[100,713,665],{"class":166},[100,715,169],{"class":110},[100,717,684],{"class":176},[100,719,451],{"class":110},[100,721,139],{"class":131},[100,723,724],{"class":135},"m\u002F86'\u002F0'\u002F0'\u002F0\u002F0",[100,726,139],{"class":131},[100,728,696],{"class":110},[100,730,699],{"class":176},[100,732,702],{"class":110},[100,734,735],{"class":435},"\u002F\u002F bc1p..., taproot from purpose 86\n",[100,737,738,740,742,744,746,748,750,752,755,757,760,762,764,766,768],{"class":102,"line":152},[100,739,419],{"class":176},[100,741,179],{"class":110},[100,743,665],{"class":166},[100,745,169],{"class":110},[100,747,684],{"class":176},[100,749,451],{"class":110},[100,751,139],{"class":131},[100,753,754],{"class":135},"m\u002F44'\u002F0'\u002F0'\u002F0\u002F0",[100,756,139],{"class":131},[100,758,759],{"class":110},", {}, ",[100,761,139],{"class":131},[100,763,330],{"class":135},[100,765,139],{"class":131},[100,767,432],{"class":110},[100,769,770],{"class":435},"\u002F\u002F explicit type wins\n",[227,772,773],{},"Purpose 44 is legacy, 49 is p2sh, 84 segwit, 86 taproot. Anything else with no explicit type falls back to legacy.",[85,775,777],{"id":776},"signing","Signing",[227,779,780,783,784,787,788,791,792,795],{},[97,781,782],{},"signMessage"," hashes with the ",[97,785,786],{},"\"\\x18Bitcoin Signed Message:\\n\""," preamble, the same one Bitcoin Core uses, and signs with secp256k1. The result is a hex signature that ",[97,789,790],{},"verifyMessage"," checks against the public key. It is not the base64 recoverable format ",[97,793,794],{},"bitcoin-cli signmessage"," prints, so do not paste one into the other.",[85,797,799],{"id":798},"where-it-lives","Where it lives",[227,801,802,805,806,809,810,813],{},[97,803,804],{},"src\u002Fblockchains\u002Fbitcoin.ts"," holds the network table and the type dispatch. The hashing and encoding helpers sit in ",[97,807,808],{},"src\u002Futils\u002Faddress.ts"," and ",[97,811,812],{},"src\u002Futils\u002Fencoding.ts",", shared with TRON and the custom chain example.",[815,816,817],"style",{},"html pre.shiki code .sP0CR, html code.shiki .sP0CR{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#5DE4C7}html pre.shiki code .sKlNE, html code.shiki .sKlNE{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#A6ACCD}html pre.shiki code .snHMy, html code.shiki .snHMy{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#ADD7FF}html pre.shiki code .stCPd, html code.shiki .stCPd{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#A6ACCD}html pre.shiki code .scVjq, html code.shiki .scVjq{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#A6ACCD}html pre.shiki code .sQ7BG, html code.shiki .sQ7BG{--shiki-light:#032F62;--shiki-default:#032F62;--shiki-dark:#5DE4C7}html pre.shiki code .s1TYA, html code.shiki .s1TYA{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#91B4D5}html pre.shiki code .saoiD, html code.shiki .saoiD{--shiki-light:#005CC5;--shiki-default:#005CC5;--shiki-dark:#E4F0FB}html pre.shiki code .sULi6, html code.shiki .sULi6{--shiki-light:#6F42C1;--shiki-default:#6F42C1;--shiki-dark:#E4F0FBD0}html pre.shiki code .sZW6a, html code.shiki .sZW6a{--shiki-light:#D73A49;--shiki-default:#D73A49;--shiki-dark:#5DE4C7C0}html pre.shiki code .spVlQ, html code.shiki .spVlQ{--shiki-light:#24292E;--shiki-default:#24292E;--shiki-dark:#E4F0FB}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sjhu3, html code.shiki .sjhu3{--shiki-light:#6A737D;--shiki-light-font-style:inherit;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#767C9DB0;--shiki-dark-font-style:italic}",{"title":95,"searchDepth":145,"depth":145,"links":819},[820,821,822,823,824,825],{"id":87,"depth":145,"text":88},{"id":239,"depth":145,"text":240},{"id":561,"depth":145,"text":562},{"id":659,"depth":145,"text":660},{"id":776,"depth":145,"text":777},{"id":798,"depth":145,"text":799},"secp256k1 with legacy, p2sh, segwit, p2wsh, and taproot addresses, on mainnet and testnet.","md",null,{"icon":830},"i-simple-icons-bitcoin",{"title":48,"description":826},"ZVv14o0n0VYQf4l72L56d_1vhDCdiMqVad8oaJRbC0M",[834,836],{"title":44,"path":45,"stem":46,"description":835,"children":-1},"Ethereum's driver under another name. Same key, same address, same signatures.",{"title":52,"path":53,"stem":54,"description":837,"children":-1},"ed25519 with bech32 base, enterprise, and stake addresses. Mnemonic derivation is refused on purpose.",1788428715659]