---
格式版本: 2
标题: "supernode/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java at 1.1 · bitsofproof/supernode · GitHub"
原文链接: "https://github.com/bitsofproof/supernode/blob/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java"
发布日期: "2026-05-27"
发现时间: "2026-05-29T09:00:33+08:00"
入库时间: "2026-05-29T01:04:01.115Z"
来源平台: "博查 AI Search"
搜索渠道: "bocha_ai_search"
搜索词: "supernode"
匹配关键词:
  - "supernode"
相关厂家:
  []
相关专家:
  []
内容类型: "网页"
抓取工具: "XCrawl Scrape"
清洗工具: "XCrawl Markdown"
采集批次: "2026年5月29日9点00分30秒"
采集批次ID: "20260529-090030-679"
去重键: "https://github.com/bitsofproof/supernode/blob/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java"
---

Skip to content
## Navigation Menu
Toggle navigation
[ ](https://github.com/)
[ Sign in ](https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbitsofproof%2Fsupernode%2Fblob%2F1.1%2Fapi%2Fsrc%2Fmain%2Fjava%2Fcom%2Fbitsofproof%2Fsupernode%2Fapi%2FExtendedKey.java)
Appearance settings
  * Platform
    * AI CODE CREATION
      * [GitHub CopilotWrite better code with AI](https://github.com/features/copilot)
      * [GitHub SparkBuild and deploy intelligent apps](https://github.com/features/spark)
      * [GitHub ModelsManage and compare prompts](https://github.com/features/models)
      * [MCP RegistryNewIntegrate external tools](https://github.com/mcp)
    * DEVELOPER WORKFLOWS
      * [ActionsAutomate any workflow](https://github.com/features/actions)
      * [CodespacesInstant dev environments](https://github.com/features/codespaces)
      * [IssuesPlan and track work](https://github.com/features/issues)
      * [Code ReviewManage code changes](https://github.com/features/code-review)
    * APPLICATION SECURITY
      * [GitHub Advanced SecurityFind and fix vulnerabilities](https://github.com/security/advanced-security)
      * [Code securitySecure your code as you build](https://github.com/security/advanced-security/code-security)
      * [Secret protectionStop leaks before they start](https://github.com/security/advanced-security/secret-protection)
    * EXPLORE
      * [Why GitHub](https://github.com/why-github)
      * [Documentation](https://docs.github.com)
      * [Blog](https://github.blog)
      * [Changelog](https://github.blog/changelog)
      * [Marketplace](https://github.com/marketplace)
[View all features](https://github.com/features)
  * Solutions
    * BY COMPANY SIZE
      * [Enterprises](https://github.com/enterprise)
      * [Small and medium teams](https://github.com/team)
      * [Startups](https://github.com/enterprise/startups)
      * [Nonprofits](https://github.com/solutions/industry/nonprofits)
    * BY USE CASE
      * [App Modernization](https://github.com/solutions/use-case/app-modernization)
      * [DevSecOps](https://github.com/solutions/use-case/devsecops)
      * [DevOps](https://github.com/solutions/use-case/devops)
      * [CI/CD](https://github.com/solutions/use-case/ci-cd)
      * [View all use cases](https://github.com/solutions/use-case)
    * BY INDUSTRY
      * [Healthcare](https://github.com/solutions/industry/healthcare)
      * [Financial services](https://github.com/solutions/industry/financial-services)
      * [Manufacturing](https://github.com/solutions/industry/manufacturing)
      * [Government](https://github.com/solutions/industry/government)
      * [View all industries](https://github.com/solutions/industry)
[View all solutions](https://github.com/solutions)
  * Resources
    * EXPLORE BY TOPIC
      * [AI](https://github.com/resources/articles?topic=ai)
      * [Software Development](https://github.com/resources/articles?topic=software-development)
      * [DevOps](https://github.com/resources/articles?topic=devops)
      * [Security](https://github.com/resources/articles?topic=security)
      * [View all topics](https://github.com/resources/articles)
    * EXPLORE BY TYPE
      * [Customer stories](https://github.com/customer-stories)
      * [Events & webinars](https://github.com/resources/events)
      * [Ebooks & reports](https://github.com/resources/whitepapers)
      * [Business insights](https://github.com/solutions/executive-insights)
      * [GitHub Skills](https://skills.github.com)
    * SUPPORT & SERVICES
      * [Documentation](https://docs.github.com)
      * [Customer support](https://support.github.com)
      * [Community forum](https://github.com/orgs/community/discussions)
      * [Trust center](https://github.com/trust-center)
      * [Partners](https://github.com/partners)
[View all resources](https://github.com/resources)
  * Open Source
    * COMMUNITY
      * [GitHub SponsorsFund open source developers](https://github.com/sponsors)
    * PROGRAMS
      * [Security Lab](https://securitylab.github.com)
      * [Maintainer Community](https://maintainers.github.com)
      * [Accelerator](https://github.com/accelerator)
      * [GitHub Stars](https://stars.github.com)
      * [Archive Program](https://archiveprogram.github.com)
    * REPOSITORIES
      * [Topics](https://github.com/topics)
      * [Trending](https://github.com/trending)
      * [Collections](https://github.com/collections)
  * Enterprise
    * ENTERPRISE SOLUTIONS
      * [Enterprise platformAI-powered developer platform](https://github.com/enterprise)
    * AVAILABLE ADD-ONS
      * [GitHub Advanced SecurityEnterprise-grade security features](https://github.com/security/advanced-security)
      * [Copilot for BusinessEnterprise-grade AI features](https://github.com/features/copilot/copilot-business)
      * [Premium SupportEnterprise-grade 24/7 support](https://github.com/premium-support)
  * [Pricing](https://github.com/pricing)

Search or jump to...
# Search code, repositories, users, issues, pull requests...
Search 
Clear

[Search syntax tips](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax)
#  Provide feedback 
We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contacted
Cancel  Submit feedback 
#  Saved searches 
## Use saved searches to filter your results more quickly
Name
Query
To see all available qualifiers, see our [documentation](https://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax). 
Cancel  Create saved search 
[ Sign in ](https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fbitsofproof%2Fsupernode%2Fblob%2F1.1%2Fapi%2Fsrc%2Fmain%2Fjava%2Fcom%2Fbitsofproof%2Fsupernode%2Fapi%2FExtendedKey.java)
[ Sign up ](https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fblob%2Fshow&source=header-repo&source_repo=bitsofproof%2Fsupernode)
Appearance settings
Resetting focus
You signed in with another tab or window. [Reload]() to refresh your session. You signed out in another tab or window. [Reload]() to refresh your session. You switched accounts on another tab or window. [Reload]() to refresh your session. Dismiss alert
{{ message }}
[ bitsofproof ](https://github.com/bitsofproof) / **[supernode](https://github.com/bitsofproof/supernode) ** Public
  * [ Notifications ](https://github.com/login?return_to=%2Fbitsofproof%2Fsupernode) You must be signed in to change notification settings
  * [ Fork 59 ](https://github.com/login?return_to=%2Fbitsofproof%2Fsupernode)
  * [ Star  129 ](https://github.com/login?return_to=%2Fbitsofproof%2Fsupernode)

  * [ Code ](https://github.com/bitsofproof/supernode/tree/1.1)
  * [ Issues 1 ](https://github.com/bitsofproof/supernode/issues)
  * [ Pull requests 1 ](https://github.com/bitsofproof/supernode/pulls)
  * [ Actions ](https://github.com/bitsofproof/supernode/actions)
  * [ Projects ](https://github.com/bitsofproof/supernode/projects)
  * [ Security and quality 0 ](https://github.com/bitsofproof/supernode/security)
  * [ Insights ](https://github.com/bitsofproof/supernode/pulse)

Additional navigation options
  * [ Code  ](https://github.com/bitsofproof/supernode/tree/1.1)
  * [ Issues  ](https://github.com/bitsofproof/supernode/issues)
  * [ Pull requests  ](https://github.com/bitsofproof/supernode/pulls)
  * [ Actions  ](https://github.com/bitsofproof/supernode/actions)
  * [ Projects  ](https://github.com/bitsofproof/supernode/projects)
  * [ Security and quality  ](https://github.com/bitsofproof/supernode/security)
  * [ Insights  ](https://github.com/bitsofproof/supernode/pulse)

[](https://github.com/bitsofproof/supernode)
## Collapse file tree
## Files
File does not exist on default branch
 1.1
Search this repository(forward slash)` forward slash/`
  * api
    * src
      * main
        * java/com/bitsofproof/supernode
          * api
            * AccountListener.java
            * AccountManager.java
            * AddressConverter.java
            * AddressListAccountManager.java
            * AlertListener.java
            * BCSAPI.java
            * BCSAPIException.java
            * BaseAccountManager.java
            * Block.java
            * Color.java
            * ColorRules.java
            * ExtendedKey.java
            * ExtendedKeyAccountManager.java
            * ExtendedKeySetWallet.java
            * FileWallet.java
            * InMemoryUTXO.java
            * JMSServerConnector.java
            * KeyFormatter.java
            * KeyListAccountManager.java
            * ServerConnector.java
            * Transaction.java
            * TransactionInput.java
            * TransactionListener.java
            * TransactionOutput.java
            * TrunkListener.java
            * TrunkUpdateMessage.java
            * Wallet.java
          * common
        * proto
      * test
    * .gitignore
    * generateBCSAPIkeys
    * pom.xml
  * server
  * .gitignore
  * .travis.yml
  * LICENSE
  * NOTICE
  * README.md
  * pom.xml

## Breadcrumbs
  1. [supernode](https://github.com/bitsofproof/supernode/tree/1.1)
  2. /[api](https://github.com/bitsofproof/supernode/tree/1.1/api)
  3. /[src](https://github.com/bitsofproof/supernode/tree/1.1/api/src)
  4. /[main](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main)
  5. /[java](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java)
  6. /[com](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com)
  7. /[bitsofproof](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com/bitsofproof)
  8. /[supernode](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com/bitsofproof/supernode)
  9. /[api](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com/bitsofproof/supernode/api)

/
# ExtendedKey.java
Copy path
Blame
More file actions
Blame
More file actions
## Latest commit
[![tamasblummer](https://avatars.githubusercontent.com/u/4289351?v=4&size=40)](https://github.com/tamasblummer)[tamasblummer](https://github.com/bitsofproof/supernode/commits?author=tamasblummer)
[file wallet can now store encryped master in place of seed.](https://github.com/bitsofproof/supernode/commit/1c3b7fc426c38e07a70eb156b7c4898cdaedded1)
Aug 8, 2013
[1c3b7fc](https://github.com/bitsofproof/supernode/commit/1c3b7fc426c38e07a70eb156b7c4898cdaedded1) · Aug 8, 2013
## History
[History](https://github.com/bitsofproof/supernode/commits/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java)
Open commit details
[](https://github.com/bitsofproof/supernode/commits/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java)History
438 lines (406 loc) · 12.2 KB
## Breadcrumbs
  1. [supernode](https://github.com/bitsofproof/supernode/tree/1.1)
  2. /[api](https://github.com/bitsofproof/supernode/tree/1.1/api)
  3. /[src](https://github.com/bitsofproof/supernode/tree/1.1/api/src)
  4. /[main](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main)
  5. /[java](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java)
  6. /[com](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com)
  7. /[bitsofproof](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com/bitsofproof)
  8. /[supernode](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com/bitsofproof/supernode)
  9. /[api](https://github.com/bitsofproof/supernode/tree/1.1/api/src/main/java/com/bitsofproof/supernode/api)

/
# ExtendedKey.java
Top
## File metadata and controls
  * Code
  * Blame

438 lines (406 loc) · 12.2 KB
[Raw](https://github.com/bitsofproof/supernode/raw/refs/heads/1.1/api/src/main/java/com/bitsofproof/supernode/api/ExtendedKey.java)
Copy raw file
Download raw file
You must be signed in to make or propose changes
More edit options
Open symbols panel
Edit and raw actions
/* * Copyright 2013 bits of proof zrt. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.bitsofproof.supernode.api; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.Mac; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; import org.bouncycastle.asn1.sec.SECNamedCurves; import org.bouncycastle.asn1.x9.X9ECParameters; import org.bouncycastle.crypto.generators.SCrypt; import org.bouncycastle.math.ec.ECPoint; import org.bouncycastle.util.Arrays; import com.bitsofproof.supernode.common.ByteUtils; import com.bitsofproof.supernode.common.ECKeyPair; import com.bitsofproof.supernode.common.ECPublicKey; import com.bitsofproof.supernode.common.Key; import com.bitsofproof.supernode.common.ValidationException; /** * Key Generator following BIP32 https://en.bitcoin.it/wiki/BIP_0032 */ public class ExtendedKey { private static final SecureRandom rnd = new SecureRandom (); private static final X9ECParameters curve = SECNamedCurves.getByName ("secp256k1"); private final Key master; private final byte[] chainCode; private final int depth; private final int parent; private final int sequence; private static final byte[] BITCOIN_SEED = "Bitcoin seed".getBytes (); public static ExtendedKey createFromPassphrase (String passphrase, byte[] encrypted) throws ValidationException { try { byte[] key = SCrypt.generate (passphrase.getBytes ("UTF-8"), BITCOIN_SEED, 16384, 8, 8, 32); SecretKeySpec keyspec = new SecretKeySpec (key, "AES"); if ( encrypted.length == 32 ) { // asssume encrypted is seed Cipher cipher = Cipher.getInstance ("AES/ECB/NoPadding", "BC"); cipher.init (Cipher.DECRYPT_MODE, keyspec); return create (cipher.doFinal (encrypted)); } else { // assume encrypted serialization of a key Cipher cipher = Cipher.getInstance ("AES/CBC/PKCS5Padding", "BC"); byte[] iv = Arrays.copyOfRange (encrypted, 0, 16); byte[] data = Arrays.copyOfRange (encrypted, 16, encrypted.length); cipher.init (Cipher.DECRYPT_MODE, keyspec, new IvParameterSpec (iv)); return ExtendedKey.parse (new String (cipher.doFinal (data))); } } catch ( UnsupportedEncodingException e ) { throw new ValidationException (e); } catch ( IllegalBlockSizeException e ) { throw new ValidationException (e); } catch ( BadPaddingException e ) { throw new ValidationException (e); } catch ( InvalidKeyException e ) { throw new ValidationException (e); } catch ( NoSuchAlgorithmException e ) { throw new ValidationException (e); } catch ( NoSuchProviderException e ) { throw new ValidationException (e); } catch ( NoSuchPaddingException e ) { throw new ValidationException (e); } catch ( InvalidAlgorithmParameterException e ) { throw new ValidationException (e); } } public byte[] encrypt (String passphrase, boolean production) throws ValidationException { try { byte[] key = SCrypt.generate (passphrase.getBytes ("UTF-8"), BITCOIN_SEED, 16384, 8, 8, 32); SecretKeySpec keyspec = new SecretKeySpec (key, "AES"); Cipher cipher = Cipher.getInstance ("AES/CBC/PKCS5Padding", "BC"); cipher.init (Cipher.ENCRYPT_MODE, keyspec); byte[] iv = cipher.getIV (); byte[] c = cipher.doFinal (serialize (production).getBytes ()); byte[] result = new byte[iv.length + c.length]; System.arraycopy (iv, 0, result, 0, iv.length); System.arraycopy (c, 0, result, iv.length, c.length); return result; } catch ( UnsupportedEncodingException | NoSuchAlgorithmException | NoSuchProviderException | NoSuchPaddingException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e ) { throw new ValidationException (e); } } public static ExtendedKey create (byte[] seed) throws ValidationException { try { Mac mac = Mac.getInstance ("HmacSHA512", "BC"); SecretKey seedkey = new SecretKeySpec (BITCOIN_SEED, "HmacSHA512"); mac.init (seedkey); byte[] lr = mac.doFinal (seed); byte[] l = Arrays.copyOfRange (lr, 0, 32); byte[] r = Arrays.copyOfRange (lr, 32, 64); BigInteger m = new BigInteger (1, l); if ( m.compareTo (curve.getN ()) >= 0 ) { throw new ValidationException ("This is rather unlikely, but it did just happen"); } ECKeyPair keyPair = new ECKeyPair (l, true); return new ExtendedKey (keyPair, r, 0, 0, 0); } catch ( NoSuchAlgorithmException e ) { throw new ValidationException (e); } catch ( NoSuchProviderException e ) { throw new ValidationException (e); } catch ( InvalidKeyException e ) { throw new ValidationException (e); } } public static ExtendedKey createNew () { Key key = ECKeyPair.createNew (true); byte[] chainCode = new byte[32]; rnd.nextBytes (chainCode); return new ExtendedKey (key, chainCode, 0, 0, 0); } public ExtendedKey (Key key, byte[] chainCode, int depth, int parent, int sequence) { this.master = key; this.chainCode = chainCode; this.parent = parent; this.depth = depth; this.sequence = sequence; } public Key getMaster () { return master; } public byte[] getChainCode () { return Arrays.clone (chainCode); } public int getDepth () { return depth; } public int getParent () { return parent; } public int getSequence () { return sequence; } public int getFingerPrint () { int fingerprint = 0; byte[] address = master.getAddress (); for ( int i = 0; i < 4; ++i ) { fingerprint <<= 8; fingerprint |= address[i] & 0xff; } return fingerprint; } public Key getKey (int sequence) throws ValidationException { return generateKey (sequence).getMaster (); } public ExtendedKey getChild (int sequence) throws ValidationException { ExtendedKey sub = generateKey (sequence); return new ExtendedKey (sub.getMaster (), sub.getChainCode (), sub.getDepth () + 1, getFingerPrint (), sequence); } public ExtendedKey getReadOnly () { return new ExtendedKey (new ECPublicKey (master.getPublic (), true), chainCode, depth, parent, sequence); } public boolean isReadOnly () { return master.getPrivate () == null; } private ExtendedKey generateKey (int sequence) throws ValidationException { try { if ( (sequence & 0x80000000) != 0 && master.getPrivate () == null ) { throw new ValidationException ("need private key for private generation"); } Mac mac = Mac.getInstance ("HmacSHA512", "BC"); SecretKey key = new SecretKeySpec (chainCode, "HmacSHA512"); mac.init (key); byte[] extended; byte[] pub = master.getPublic (); if ( (sequence & 0x80000000) == 0 ) { extended = new byte[pub.length + 4]; System.arraycopy (pub, 0, extended, 0, pub.length); extended[pub.length] = (byte) ((sequence >>> 24) & 0xff); extended[pub.length + 1] = (byte) ((sequence >>> 16) & 0xff); extended[pub.length + 2] = (byte) ((sequence >>> 8) & 0xff); extended[pub.length + 3] = (byte) (sequence & 0xff); } else { byte[] priv = master.getPrivate (); extended = new byte[priv.length + 5]; System.arraycopy (priv, 0, extended, 1, priv.length); extended[priv.length + 1] = (byte) ((sequence >>> 24) & 0xff); extended[priv.length + 2] = (byte) ((sequence >>> 16) & 0xff); extended[priv.length + 3] = (byte) ((sequence >>> 8) & 0xff); extended[priv.length + 4] = (byte) (sequence & 0xff); } byte[] lr = mac.doFinal (extended); byte[] l = Arrays.copyOfRange (lr, 0, 32); byte[] r = Arrays.copyOfRange (lr, 32, 64); BigInteger m = new BigInteger (1, l); if ( m.compareTo (curve.getN ()) >= 0 ) { throw new ValidationException ("This is rather unlikely, but it did just happen"); } if ( master.getPrivate () != null ) { BigInteger k = m.add (new BigInteger (1, master.getPrivate ())).mod (curve.getN ()); if ( k.equals (BigInteger.ZERO) ) { throw new ValidationException ("This is rather unlikely, but it did just happen"); } return new ExtendedKey (new ECKeyPair (k, true), r, depth, parent, sequence); } else { ECPoint q = curve.getG ().multiply (m).add (curve.getCurve ().decodePoint (pub)); if ( q.isInfinity () ) { throw new ValidationException ("This is rather unlikely, but it did just happen"); } pub = new ECPoint.Fp (curve.getCurve (), q.getX (), q.getY (), true).getEncoded (); return new ExtendedKey (new ECPublicKey (pub, true), r, depth, parent, sequence); } } catch ( NoSuchAlgorithmException e ) { throw new ValidationException (e); } catch ( NoSuchProviderException e ) { throw new ValidationException (e); } catch ( InvalidKeyException e ) { throw new ValidationException (e); } } private static final byte[] xprv = new byte[] { 0x04, (byte) 0x88, (byte) 0xAD, (byte) 0xE4 }; private static final byte[] xpub = new byte[] { 0x04, (byte) 0x88, (byte) 0xB2, (byte) 0x1E }; private static final byte[] tprv = new byte[] { 0x04, (byte) 0x35, (byte) 0x83, (byte) 0x94 }; private static final byte[] tpub = new byte[] { 0x04, (byte) 0x35, (byte) 0x87, (byte) 0xCF }; public String serialize (boolean production) { ByteArrayOutputStream out = new ByteArrayOutputStream (); try { if ( master.getPrivate () != null ) { if ( production ) { out.write (xprv); } else { out.write (tprv); } } else { if ( production ) { out.write (xpub); } else { out.write (tpub); } } out.write (depth & 0xff); out.write ((parent >>> 24) & 0xff); out.write ((parent >>> 16) & 0xff); out.write ((parent >>> 8) & 0xff); out.write (parent & 0xff); out.write ((sequence >>> 24) & 0xff); out.write ((sequence >>> 16) & 0xff); out.write ((sequence >>> 8) & 0xff); out.write (sequence & 0xff); out.write (chainCode); if ( master.getPrivate () != null ) { out.write (0x00); out.write (master.getPrivate ()); } else { out.write (master.getPublic ()); } } catch ( IOException e ) { } return ByteUtils.toBase58WithChecksum (out.toByteArray ()); } public static ExtendedKey parse (String serialized) throws ValidationException { byte[] data = ByteUtils.fromBase58WithChecksum (serialized); if ( data.length != 78 ) { throw new ValidationException ("invalid extended key"); } byte[] type = Arrays.copyOf (data, 4); boolean hasPrivate; if ( Arrays.areEqual (type, xprv) || Arrays.areEqual (type, tprv) ) { hasPrivate = true; } else if ( Arrays.areEqual (type, xpub) || Arrays.areEqual (type, tpub) ) { hasPrivate = false; } else { throw new ValidationException ("invalid magic number for an extended key"); } int depth = data[4] & 0xff; int parent = data[5] & 0xff; parent <<= 8; parent |= data[6] & 0xff; parent <<= 8; parent |= data[7] & 0xff; parent <<= 8; parent |= data[8] & 0xff; int sequence = data[9] & 0xff; sequence <<= 8; sequence |= data[10] & 0xff; sequence <<= 8; sequence |= data[11] & 0xff; sequence <<= 8; sequence |= data[12] & 0xff; byte[] chainCode = Arrays.copyOfRange (data, 13, 13 + 32); byte[] pubOrPriv = Arrays.copyOfRange (data, 13 + 32, data.length); Key key; if ( hasPrivate ) { key = new ECKeyPair (new BigInteger (1, pubOrPriv), true); } else { key = new ECPublicKey (pubOrPriv, true); } return new ExtendedKey (key, chainCode, depth, parent, sequence); } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
## Footer
[ ](https://github.com) © 2026 GitHub, Inc. 
### Footer navigation
  * [Terms](https://docs.github.com/site-policy/github-terms/github-terms-of-service)
  * [Privacy](https://docs.github.com/site-policy/privacy-policies/github-privacy-statement)
  * [Security](https://github.com/security)
  * [Status](https://www.githubstatus.com/)
  * [Community](https://github.community/)
  * [Docs](https://docs.github.com/)
  * [Contact](https://support.github.com?tags=dotcom-footer)
  * Manage cookies 
  * Do not share my personal information 

You can’t perform that action at this time. 
While the code is focused, press Alt+F1 for a menu of operations.
