[{"data":1,"prerenderedAt":730},["ShallowReactive",2],{"navigation_docs":3,"-blockchains-cosmos":124,"-blockchains-cosmos-surround":725},[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":123},"Blockchains","\u002Fblockchains","2.blockchains\u002F0.index",[37,39,43,47,51,55,59,63,67,71,75,79,83,87,91,95,99,103,107,111,115,119],{"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},"Bitcoin Cash","\u002Fblockchains\u002Fbitcoincash","2.blockchains\u002Fbitcoincash",{"title":56,"path":57,"stem":58},"Bitcoin Gold","\u002Fblockchains\u002Fbitcoingold","2.blockchains\u002Fbitcoingold",{"title":60,"path":61,"stem":62},"Bitcoin SV","\u002Fblockchains\u002Fbitcoinsv","2.blockchains\u002Fbitcoinsv",{"title":64,"path":65,"stem":66},"Cardano","\u002Fblockchains\u002Fcardano","2.blockchains\u002Fcardano",{"title":68,"path":69,"stem":70},"Cosmos","\u002Fblockchains\u002Fcosmos","2.blockchains\u002Fcosmos",{"title":72,"path":73,"stem":74},"Dash","\u002Fblockchains\u002Fdash","2.blockchains\u002Fdash",{"title":76,"path":77,"stem":78},"Decred","\u002Fblockchains\u002Fdecred","2.blockchains\u002Fdecred",{"title":80,"path":81,"stem":82},"Dogecoin","\u002Fblockchains\u002Fdogecoin","2.blockchains\u002Fdogecoin",{"title":84,"path":85,"stem":86},"eCash","\u002Fblockchains\u002Fecash","2.blockchains\u002Fecash",{"title":88,"path":89,"stem":90},"Ethereum","\u002Fblockchains\u002Fethereum","2.blockchains\u002Fethereum",{"title":92,"path":93,"stem":94},"Litecoin","\u002Fblockchains\u002Flitecoin","2.blockchains\u002Flitecoin",{"title":96,"path":97,"stem":98},"NEAR","\u002Fblockchains\u002Fnear","2.blockchains\u002Fnear",{"title":100,"path":101,"stem":102},"Solana","\u002Fblockchains\u002Fsolana","2.blockchains\u002Fsolana",{"title":104,"path":105,"stem":106},"Stellar","\u002Fblockchains\u002Fstellar","2.blockchains\u002Fstellar",{"title":108,"path":109,"stem":110},"Sui","\u002Fblockchains\u002Fsui","2.blockchains\u002Fsui",{"title":112,"path":113,"stem":114},"TRON","\u002Fblockchains\u002Ftron","2.blockchains\u002Ftron",{"title":116,"path":117,"stem":118},"XRP Ledger","\u002Fblockchains\u002Fxrpl","2.blockchains\u002Fxrpl",{"title":120,"path":121,"stem":122},"Zcash","\u002Fblockchains\u002Fzcash","2.blockchains\u002Fzcash","i-lucide-boxes",{"id":125,"title":68,"body":126,"description":717,"extension":718,"links":719,"meta":720,"navigation":179,"path":69,"seo":722,"stem":70,"__hash__":724},"docs\u002F2.blockchains\u002Fcosmos.md",{"type":127,"value":128,"toc":708},"minimark",[129,136,141,240,251,258,262,265,340,347,362,369,373,407,424,462,477,481,492,569,572,583,587,601,657,669,673,683,687,704],[130,131],"chain-facts",{"coin":132,"curve":133,"driver":134,"formats":135},"118","secp256k1","cosmos","bech32 under any prefix",[137,138,140],"h2",{"id":139},"load-it","Load it",[142,143,148],"pre",{"className":144,"code":145,"language":146,"meta":147,"style":147},"language-js shiki shiki-themes keys keys keys","import { useBlockchain, blockchains } from \"@agntn\u002Fkeys\";\n\nconst cosmosChain = useBlockchain(await blockchains.cosmos()());\nconst osmosis = useBlockchain(await blockchains.cosmos({ prefix: \"osmo\" })());\n","js","",[149,150,151,174,181,211],"code",{"__ignoreMap":147},[152,153,156,160,164,167,171],"span",{"class":154,"line":155},"line",1,[152,157,159],{"class":158},"skH_V","import",[152,161,163],{"class":162},"s38Sx"," { useBlockchain, blockchains } ",[152,165,166],{"class":158},"from",[152,168,170],{"class":169},"shU9J"," \"@agntn\u002Fkeys\"",[152,172,173],{"class":162},";\n",[152,175,177],{"class":154,"line":176},2,[152,178,180],{"emptyLinePlaceholder":179},true,"\n",[152,182,184,187,190,193,197,200,203,206,208],{"class":154,"line":183},3,[152,185,186],{"class":158},"const",[152,188,189],{"class":162}," cosmosChain ",[152,191,192],{"class":158},"=",[152,194,196],{"class":195},"sK71F"," useBlockchain",[152,198,199],{"class":162},"(",[152,201,202],{"class":158},"await",[152,204,205],{"class":162}," blockchains.",[152,207,134],{"class":195},[152,209,210],{"class":162},"()());\n",[152,212,214,216,219,221,223,225,227,229,231,234,237],{"class":154,"line":213},4,[152,215,186],{"class":158},[152,217,218],{"class":162}," osmosis ",[152,220,192],{"class":158},[152,222,196],{"class":195},[152,224,199],{"class":162},[152,226,202],{"class":158},[152,228,205],{"class":162},[152,230,134],{"class":195},[152,232,233],{"class":162},"({ prefix: ",[152,235,236],{"class":169},"\"osmo\"",[152,238,239],{"class":162}," })());\n",[241,242,243,244,247,248,250],"p",{},"Every Cosmos SDK chain hashes the key the same way and walks the same path. The only thing that changes is the bit in front of the ",[149,245,246],{},"1",". So it's an option, not twenty classes. Leave it out and you get the Hub, ",[149,249,134],{},".",[241,252,253,254,257],{},"Testnets keep their mainnet's prefix, so the ",[149,255,256],{},"network"," option changes nothing here.",[137,259,261],{"id":260},"whats-in-an-address","What's in an address?",[241,263,264],{},"Bitcoin's hash160 of the compressed key, written as bech32 under the chain's prefix.",[142,266,268],{"className":144,"code":267,"language":146,"meta":147,"style":147},"const privateKey = \"0000000000000000000000000000000000000000000000000000000000000001\";\nconst publicKey = cosmosChain.getKeyPublic(privateKey);\n\ncosmosChain.getAddress(publicKey);\n\u002F\u002F cosmos1w508d6qejxtdg4y5r3zarvary0c5xw7k6ah60c\nosmosis.getAddress(publicKey);\n\u002F\u002F osmo1w508d6qejxtdg4y5r3zarvary0c5xw7kjxy2e2\n",[149,269,270,284,302,306,317,324,334],{"__ignoreMap":147},[152,271,272,274,277,279,282],{"class":154,"line":155},[152,273,186],{"class":158},[152,275,276],{"class":162}," privateKey ",[152,278,192],{"class":158},[152,280,281],{"class":169}," \"0000000000000000000000000000000000000000000000000000000000000001\"",[152,283,173],{"class":162},[152,285,286,288,291,293,296,299],{"class":154,"line":176},[152,287,186],{"class":158},[152,289,290],{"class":162}," publicKey ",[152,292,192],{"class":158},[152,294,295],{"class":162}," cosmosChain.",[152,297,298],{"class":195},"getKeyPublic",[152,300,301],{"class":162},"(privateKey);\n",[152,303,304],{"class":154,"line":183},[152,305,180],{"emptyLinePlaceholder":179},[152,307,308,311,314],{"class":154,"line":213},[152,309,310],{"class":162},"cosmosChain.",[152,312,313],{"class":195},"getAddress",[152,315,316],{"class":162},"(publicKey);\n",[152,318,320],{"class":154,"line":319},5,[152,321,323],{"class":322},"scIB-","\u002F\u002F cosmos1w508d6qejxtdg4y5r3zarvary0c5xw7k6ah60c\n",[152,325,327,330,332],{"class":154,"line":326},6,[152,328,329],{"class":162},"osmosis.",[152,331,313],{"class":195},[152,333,316],{"class":162},[152,335,337],{"class":154,"line":336},7,[152,338,339],{"class":322},"\u002F\u002F osmo1w508d6qejxtdg4y5r3zarvary0c5xw7kjxy2e2\n",[241,341,342,343,346],{},"Same 20 bytes, ",[149,344,345],{},"w508d6qejxtdg4y5r3zarvary0c5xw7k",", and only the checksum at the end moves with the prefix.",[241,348,349,350,353,354,357,358,361],{},"Look at the middle again. Seen it before? It's the ",[351,352,48],"a",{"href":49}," segwit address of the same key, ",[149,355,356],{},"bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4",". Bitcoin puts a ",[149,359,360],{},"q"," in front for witness version 0. Cosmos doesn't bother. The rest is the same hash. Two ecosystems that love to argue, one address underneath.",[241,363,364,365,368],{},"An uncompressed key works too. It gets compressed before hashing, because Cosmos only ever hashes the 33 byte form. That's also why ",[149,366,367],{},"deriveWallet(key, { compressed: false })"," throws. Otherwise you'd get a key that doesn't match its own address.",[137,370,372],{"id":371},"which-prefix","Which prefix?",[241,374,375,376,378,379,382,383,386,387,390,391,394,395,398,399,402,403,406],{},"The one the chain's explorer shows. ",[149,377,134],{}," for the Hub, ",[149,380,381],{},"osmo"," for Osmosis, ",[149,384,385],{},"stars"," for Stargaze, and plain ",[149,388,389],{},"celestia",", ",[149,392,393],{},"juno"," or ",[149,396,397],{},"akash",". Bech32 takes up to 83 printable ASCII characters, so ",[149,400,401],{},"fren-1"," and ",[149,404,405],{},"c4e"," work too, as long as they're lowercase. Anything else throws when you load the chain. Better a typo fails there than three steps later, as an address nobody can use.",[241,408,409,412,413,416,417,420,421,423],{},[149,410,411],{},"validateAddress"," checks the prefix too. An ",[149,414,415],{},"osmo1..."," address is ",[149,418,419],{},"false"," for ",[149,422,134],{},", good checksum or not. Accounts are 20 bytes and contracts get 32, but the SDK's own check takes anything from 1 to 255. So does this one.",[142,425,427],{"className":144,"code":426,"language":146,"meta":147,"style":147},"cosmosChain.validateAddress(\"cosmos1w508d6qejxtdg4y5r3zarvary0c5xw7k6ah60c\"); \u002F\u002F true\ncosmosChain.validateAddress(\"osmo1w508d6qejxtdg4y5r3zarvary0c5xw7kjxy2e2\"); \u002F\u002F false\n",[149,428,429,446],{"__ignoreMap":147},[152,430,431,433,435,437,440,443],{"class":154,"line":155},[152,432,310],{"class":162},[152,434,411],{"class":195},[152,436,199],{"class":162},[152,438,439],{"class":169},"\"cosmos1w508d6qejxtdg4y5r3zarvary0c5xw7k6ah60c\"",[152,441,442],{"class":162},"); ",[152,444,445],{"class":322},"\u002F\u002F true\n",[152,447,448,450,452,454,457,459],{"class":154,"line":176},[152,449,310],{"class":162},[152,451,411],{"class":195},[152,453,199],{"class":162},[152,455,456],{"class":169},"\"osmo1w508d6qejxtdg4y5r3zarvary0c5xw7kjxy2e2\"",[152,458,442],{"class":162},[152,460,461],{"class":322},"\u002F\u002F false\n",[241,463,464,465,468,469,472,473,476],{},"Not every chain with a bech32 address fits, though. Terra hashes the same way, it just walks ",[149,466,467],{},"m\u002F44'\u002F330'",". Pass that path to ",[149,470,471],{},"deriveHDWallet"," with ",[149,474,475],{},"prefix: \"terra\""," and you're there. Injective and Evmos hash Ethereum style keys, and no prefix fixes that.",[137,478,480],{"id":479},"mnemonics","Mnemonics",[241,482,483,484,487,488,491],{},"BIP32 at ",[149,485,486],{},"m\u002F44'\u002F118'\u002F0'\u002F0\u002F0",", the path Keplr and ",[149,489,490],{},"gaiad keys add"," start at.",[142,493,495],{"className":144,"code":494,"language":146,"meta":147,"style":147},"const mnemonic =\n  \"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about\";\n\ncosmosChain.getDerivationPath(); \u002F\u002F \"m\u002F44'\u002F118'\u002F0'\u002F0\u002F0\"\ncosmosChain.deriveHDWallet(mnemonic, \"m\u002F44'\u002F118'\u002F0'\u002F0\u002F0\").address;\n\u002F\u002F cosmos19rl4cm2hmr8afy4kldpxz3fka4jguq0auqdal4\nosmosis.deriveHDWallet(mnemonic, \"m\u002F44'\u002F118'\u002F0'\u002F0\u002F0\").address;\n\u002F\u002F osmo19rl4cm2hmr8afy4kldpxz3fka4jguq0a5m7df8\n",[149,496,497,507,514,518,531,546,551,563],{"__ignoreMap":147},[152,498,499,501,504],{"class":154,"line":155},[152,500,186],{"class":158},[152,502,503],{"class":162}," mnemonic ",[152,505,506],{"class":158},"=\n",[152,508,509,512],{"class":154,"line":176},[152,510,511],{"class":169},"  \"abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about\"",[152,513,173],{"class":162},[152,515,516],{"class":154,"line":183},[152,517,180],{"emptyLinePlaceholder":179},[152,519,520,522,525,528],{"class":154,"line":213},[152,521,310],{"class":162},[152,523,524],{"class":195},"getDerivationPath",[152,526,527],{"class":162},"(); ",[152,529,530],{"class":322},"\u002F\u002F \"m\u002F44'\u002F118'\u002F0'\u002F0\u002F0\"\n",[152,532,533,535,537,540,543],{"class":154,"line":319},[152,534,310],{"class":162},[152,536,471],{"class":195},[152,538,539],{"class":162},"(mnemonic, ",[152,541,542],{"class":169},"\"m\u002F44'\u002F118'\u002F0'\u002F0\u002F0\"",[152,544,545],{"class":162},").address;\n",[152,547,548],{"class":154,"line":326},[152,549,550],{"class":322},"\u002F\u002F cosmos19rl4cm2hmr8afy4kldpxz3fka4jguq0auqdal4\n",[152,552,553,555,557,559,561],{"class":154,"line":336},[152,554,329],{"class":162},[152,556,471],{"class":195},[152,558,539],{"class":162},[152,560,542],{"class":169},[152,562,545],{"class":162},[152,564,566],{"class":154,"line":565},8,[152,567,568],{"class":322},"\u002F\u002F osmo19rl4cm2hmr8afy4kldpxz3fka4jguq0a5m7df8\n",[241,570,571],{},"One phrase, one account on every chain that uses 118. That's why a Keplr wallet shows a different address per chain with the same middle.",[241,573,574,575,578,579,582],{},"Don't know which account the phrase used? ",[149,576,577],{},"keys_hd_wallet_scan"," walks accounts and indices under 118, ",[149,580,581],{},"prefix"," and all.",[137,584,586],{"id":585},"signing","Signing",[241,588,589,592,593,596,597,600],{},[149,590,591],{},"signMessage"," signs like Keplr's ",[149,594,595],{},"signArbitrary",", ADR-036. The message goes into a sign doc as base64, next to the signer's address. Fee and sequence stay zero. The SHA-256 of that JSON is what gets signed. You get 64 bytes of ",[149,598,599],{},"r||s"," in hex, no recovery byte. Keplr hands over the same bytes in base64.",[142,602,604],{"className":144,"code":603,"language":146,"meta":147,"style":147},"const signature = cosmosChain.signMessage(\"Hello, Cosmos!\", privateKey);\ncosmosChain.verifyMessage(\"Hello, Cosmos!\", signature, publicKey); \u002F\u002F true\nosmosis.verifyMessage(\"Hello, Cosmos!\", signature, publicKey); \u002F\u002F false\n",[149,605,606,627,643],{"__ignoreMap":147},[152,607,608,610,613,615,617,619,621,624],{"class":154,"line":155},[152,609,186],{"class":158},[152,611,612],{"class":162}," signature ",[152,614,192],{"class":158},[152,616,295],{"class":162},[152,618,591],{"class":195},[152,620,199],{"class":162},[152,622,623],{"class":169},"\"Hello, Cosmos!\"",[152,625,626],{"class":162},", privateKey);\n",[152,628,629,631,634,636,638,641],{"class":154,"line":176},[152,630,310],{"class":162},[152,632,633],{"class":195},"verifyMessage",[152,635,199],{"class":162},[152,637,623],{"class":169},[152,639,640],{"class":162},", signature, publicKey); ",[152,642,445],{"class":322},[152,644,645,647,649,651,653,655],{"class":154,"line":183},[152,646,329],{"class":162},[152,648,633],{"class":195},[152,650,199],{"class":162},[152,652,623],{"class":169},[152,654,640],{"class":162},[152,656,461],{"class":322},[241,658,659,660,662,663,666,667,250],{},"That last ",[149,661,419],{}," is correct. The signer's address sits inside the signed bytes, prefix included, so a signature for ",[149,664,665],{},"cosmos1..."," says nothing about ",[149,668,415],{},[137,670,672],{"id":671},"agents","Agents",[241,674,675,676,678,679,682],{},"Every tool that writes, checks or signs for a chain takes ",[149,677,581],{}," next to ",[149,680,681],{},"chain: \"cosmos\"",". On any other chain it refuses the prefix instead of quietly ignoring it.",[137,684,686],{"id":685},"where-it-lives","Where it lives",[241,688,689,692,693,696,697,700,701,250],{},[149,690,691],{},"src\u002Fblockchains\u002Fcosmos.ts",". The curve comes from ",[149,694,695],{},"@noble\u002Fcurves",", the hashes from ",[149,698,699],{},"@agntn\u002Fhashes",", bech32 and base64 from ",[149,702,703],{},"@agntn\u002Fencodings",[705,706,707],"style",{},"html pre.shiki code .skH_V, html code.shiki .skH_V{--shiki-light:var(--shiki-token-keyword);--shiki-default:var(--shiki-token-keyword);--shiki-dark:var(--shiki-token-keyword)}html pre.shiki code .s38Sx, html code.shiki .s38Sx{--shiki-light:var(--ui-text-highlighted);--shiki-default:var(--ui-text-highlighted);--shiki-dark:var(--ui-text-highlighted)}html pre.shiki code .shU9J, html code.shiki .shU9J{--shiki-light:var(--shiki-token-string);--shiki-default:var(--shiki-token-string);--shiki-dark:var(--shiki-token-string)}html pre.shiki code .sK71F, html code.shiki .sK71F{--shiki-light:var(--shiki-token-function);--shiki-default:var(--shiki-token-function);--shiki-dark:var(--shiki-token-function)}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 .scIB-, html code.shiki .scIB-{--shiki-light:var(--shiki-token-comment);--shiki-default:var(--shiki-token-comment);--shiki-dark:var(--shiki-token-comment)}",{"title":147,"searchDepth":176,"depth":176,"links":709},[710,711,712,713,714,715,716],{"id":139,"depth":176,"text":140},{"id":260,"depth":176,"text":261},{"id":371,"depth":176,"text":372},{"id":479,"depth":176,"text":480},{"id":585,"depth":176,"text":586},{"id":671,"depth":176,"text":672},{"id":685,"depth":176,"text":686},"secp256k1 keys and BIP39 words to Cosmos SDK addresses. One driver and a prefix option cover the Hub and Osmosis and Celestia.","md",null,{"icon":721},"i-token-atom",{"title":723,"description":717},"Cosmos SDK addresses from keys and BIP39 words","XZyllN5DK9aFMdlcftUFzMUfA7CccWf94265R9WyICw",[726,728],{"title":64,"path":65,"stem":66,"description":727,"children":-1},"ed25519 with base and enterprise and stake addresses in bech32. Mnemonic derivation is refused on purpose.",{"title":72,"path":73,"stem":74,"description":729,"children":-1},"Bitcoin's P2PKH recipe behind an X. One address type and a message preamble that still says DarkCoin.",1791332321797]