From f8410b441411fcadfd9168e9686d5133091d0372 Mon Sep 17 00:00:00 2001 From: grapebaba <281165273@qq.com> Date: Thu, 9 Feb 2023 21:34:27 +0800 Subject: [PATCH] fix:fix format Signed-off-by: grapebaba <281165273@qq.com> --- build.gradle | 2 + .../java/io/sui/crypto/AbstractKeyStore.java | 29 ++++++-- .../java/io/sui/crypto/ED25519KeyDerive.java | 63 ++++++++++++---- .../java/io/sui/crypto/ED25519KeyPair.java | 2 +- .../FileBasedKeyStoreSaveException.java | 2 + src/main/java/io/sui/crypto/KeyResponse.java | 23 +++++- .../io/sui/crypto/SECP256K1KeyDerive.java | 71 +++++++++++++++++-- .../java/io/sui/crypto/SECP256K1KeyPair.java | 2 +- .../io/sui/crypto/ED25519KeyDeriveTest.java | 45 +++++++----- .../io/sui/crypto/SECP256K1KeyDeriveTest.java | 41 ++++++++--- 10 files changed, 221 insertions(+), 59 deletions(-) diff --git a/build.gradle b/build.gradle index 6cc9a82..5be2217 100644 --- a/build.gradle +++ b/build.gradle @@ -112,6 +112,8 @@ checkstyle { // configFile = project(":").file("config/checkstyle/google_checks.xml") // SUN style (closest to modern Java styles) -- the basis for this project: // configFile = project(":").file("config/checkstyle/sun_checks.xml") + ignoreFailures = false + maxWarnings = 0 } spotless { diff --git a/src/main/java/io/sui/crypto/AbstractKeyStore.java b/src/main/java/io/sui/crypto/AbstractKeyStore.java index 790eb04..576bfc2 100644 --- a/src/main/java/io/sui/crypto/AbstractKeyStore.java +++ b/src/main/java/io/sui/crypto/AbstractKeyStore.java @@ -52,6 +52,13 @@ public NavigableSet addresses() { @Override public abstract void addKey(String address, SuiKeyPair keyPair); + /** + * Generate new key key response. + * + * @param schema the schema + * @return the key response + * @throws SignatureSchemeNotSupportedException the signature scheme not supported exception + */ public KeyResponse generateNewKey(SignatureScheme schema) throws SignatureSchemeNotSupportedException { @@ -67,25 +74,33 @@ public KeyResponse generateNewKey(SignatureScheme schema) } byte[] seed = MnemonicCode.toSeed(mnemonic, ""); - SuiKeyPair keyPair = genSuiKeyPair(seed, schema); + SuiKeyPair keyPair = genSuiKeyPair(seed, schema); this.addKey(keyPair.address(), keyPair); return new KeyResponse(StringUtils.join(mnemonic, " "), keyPair.address()); } + /** + * Import from mnemonic string. + * + * @param mnemonic the mnemonic + * @param schema the schema + * @return the string + * @throws SignatureSchemeNotSupportedException the signature scheme not supported exception + */ public String importFromMnemonic(String mnemonic, SignatureScheme schema) throws SignatureSchemeNotSupportedException { // todo check mnemonic byte[] seed = MnemonicCode.toSeed(Arrays.asList(mnemonic.split(" ")), ""); - SuiKeyPair keyPair = genSuiKeyPair(seed, schema); + SuiKeyPair keyPair = genSuiKeyPair(seed, schema); this.addKey(keyPair.address(), keyPair); return keyPair.address(); } - private SuiKeyPair genSuiKeyPair(byte[] seed, SignatureScheme schema) + private SuiKeyPair genSuiKeyPair(byte[] seed, SignatureScheme schema) throws SignatureSchemeNotSupportedException { switch (schema) { case ED25519: @@ -97,19 +112,19 @@ private SuiKeyPair genSuiKeyPair(byte[] seed, SignatureScheme schema) } } + @SuppressWarnings("checkstyle:AbbreviationAsWordInName") private ED25519KeyPair genED25519KeyPair(byte[] seed) { ED25519KeyDerive key = ED25519KeyDerive.createKeyByDefaultPath(seed); Ed25519PrivateKeyParameters parameters = new Ed25519PrivateKeyParameters(key.getKey()); Ed25519PublicKeyParameters publicKeyParameters = parameters.generatePublicKey(); - ED25519KeyPair keyPair = new ED25519KeyPair(parameters, publicKeyParameters); - return keyPair; + return new ED25519KeyPair(parameters, publicKeyParameters); } + @SuppressWarnings("checkstyle:AbbreviationAsWordInName") private SECP256K1KeyPair genSECP256K1KeyPair(byte[] seed) { SECP256K1KeyDerive key = SECP256K1KeyDerive.createKeyByDefaultPath(seed); - SECP256K1KeyPair keyPair = new SECP256K1KeyPair(key.getKey()); - return keyPair; + return new SECP256K1KeyPair(key.getKey()); } } diff --git a/src/main/java/io/sui/crypto/ED25519KeyDerive.java b/src/main/java/io/sui/crypto/ED25519KeyDerive.java index 027d9ba..52c46d8 100644 --- a/src/main/java/io/sui/crypto/ED25519KeyDerive.java +++ b/src/main/java/io/sui/crypto/ED25519KeyDerive.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -33,16 +33,29 @@ * @author fearlessfe * @since 2023.02 */ +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") public class ED25519KeyDerive { - private final String defaultDerivePath = "m/44H/784H/0H/0H/0H"; - private byte[] key; - private byte[] chaincode; + private static final String DEFAULT_DERIVE_PATH = "m/44H/784H/0H/0H/0H"; + private final byte[] key; + private final byte[] chaincode; + /** + * Create key by default path ed 25519 key derive. + * + * @param seed the seed + * @return the ed 25519 key derive + */ public static ED25519KeyDerive createKeyByDefaultPath(byte[] seed) { return createMasterKey(seed).deriveFromPath(""); } + /** + * Create master key ed 25519 key derive. + * + * @param seed the seed + * @return the ed 25519 key derive + */ public static ED25519KeyDerive createMasterKey(byte[] seed) { byte[] i = HDUtils.hmacSha512("ed25519 seed".getBytes(Charset.defaultCharset()), seed); byte[] il = Arrays.copyOfRange(i, 0, 32); @@ -50,24 +63,32 @@ public static ED25519KeyDerive createMasterKey(byte[] seed) { return new ED25519KeyDerive(il, ir); } + /** + * Instantiates a new Ed 25519 key derive. + * + * @param key the key + * @param chaincode the chaincode + */ public ED25519KeyDerive(byte[] key, byte[] chaincode) { this.key = key; this.chaincode = chaincode; } + /** + * Derive ed 25519 key derive. + * + * @param index the index + * @return the ed 25519 key derive + */ public ED25519KeyDerive derive(int index) { - if (!hasHardenedBit(index)) {} + if (!hasHardenedBit(index)) { + // todo: create an exception + throw new RuntimeException(); + } byte[] indexBytes = new byte[4]; ByteBuffer.wrap(indexBytes).putInt(index); - // byte[] a = new byte[]{0x00}; - // - // ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - // outputStream.write(a); - // outputStream.write(this.key); - // outputStream.write(indexBytes); - byte[] data = Bytes.concat(new byte[] {0x00}, this.key, indexBytes); byte[] i = HDUtils.hmacSha512(this.chaincode, data); @@ -77,9 +98,15 @@ public ED25519KeyDerive derive(int index) { return new ED25519KeyDerive(il, ir); } + /** + * Derive from path ed 25519 key derive. + * + * @param path the path + * @return the ed 25519 key derive + */ public ED25519KeyDerive deriveFromPath(String path) { if (StringUtils.isAnyBlank(path)) { - path = defaultDerivePath; + path = DEFAULT_DERIVE_PATH; } HDPath hdPath = HDPath.parsePath(path); Iterator it = hdPath.iterator(); @@ -94,10 +121,20 @@ private boolean hasHardenedBit(int a) { return (a & ChildNumber.HARDENED_BIT) != 0; } + /** + * Get key byte [ ]. + * + * @return the byte [ ] + */ public byte[] getKey() { return key; } + /** + * Get chaincode byte [ ]. + * + * @return the byte [ ] + */ public byte[] getChaincode() { return chaincode; } diff --git a/src/main/java/io/sui/crypto/ED25519KeyPair.java b/src/main/java/io/sui/crypto/ED25519KeyPair.java index bd60220..9d50414 100644 --- a/src/main/java/io/sui/crypto/ED25519KeyPair.java +++ b/src/main/java/io/sui/crypto/ED25519KeyPair.java @@ -105,5 +105,5 @@ public String encodePrivateKey() { Ed25519PrivateKeyParameters pair = (Ed25519PrivateKeyParameters) this.keyPair.getPrivate(); byte[] data = Bytes.concat(new byte[] {SignatureScheme.ED25519.getScheme()}, pair.getEncoded()); return Base64.toBase64String(data); - }; + } } diff --git a/src/main/java/io/sui/crypto/FileBasedKeyStoreSaveException.java b/src/main/java/io/sui/crypto/FileBasedKeyStoreSaveException.java index bce1e4f..698814c 100644 --- a/src/main/java/io/sui/crypto/FileBasedKeyStoreSaveException.java +++ b/src/main/java/io/sui/crypto/FileBasedKeyStoreSaveException.java @@ -17,6 +17,8 @@ package io.sui.crypto; /** + * The type File based key store save exception. + * * @author fearlessfe * @since 2023 02 */ diff --git a/src/main/java/io/sui/crypto/KeyResponse.java b/src/main/java/io/sui/crypto/KeyResponse.java index 7879ef1..1b41fff 100644 --- a/src/main/java/io/sui/crypto/KeyResponse.java +++ b/src/main/java/io/sui/crypto/KeyResponse.java @@ -17,22 +17,41 @@ package io.sui.crypto; /** + * The type Key response. + * * @author fearlessfe * @since 2023 02 */ public class KeyResponse { - private String mnemonic; - private String address; + private final String mnemonic; + private final String address; + + /** + * Instantiates a new Key response. + * + * @param mnemonic the mnemonic + * @param address the address + */ public KeyResponse(String mnemonic, String address) { this.mnemonic = mnemonic; this.address = address; } + /** + * Gets mnemonic. + * + * @return the mnemonic + */ public String getMnemonic() { return mnemonic; } + /** + * Gets address. + * + * @return the address + */ public String getAddress() { return address; } diff --git a/src/main/java/io/sui/crypto/SECP256K1KeyDerive.java b/src/main/java/io/sui/crypto/SECP256K1KeyDerive.java index 1c85843..b126e26 100644 --- a/src/main/java/io/sui/crypto/SECP256K1KeyDerive.java +++ b/src/main/java/io/sui/crypto/SECP256K1KeyDerive.java @@ -20,43 +20,82 @@ import java.math.BigInteger; import java.util.Iterator; import org.apache.commons.lang3.StringUtils; -import org.bitcoinj.crypto.*; +import org.bitcoinj.crypto.ChildNumber; +import org.bitcoinj.crypto.DeterministicKey; +import org.bitcoinj.crypto.HDKeyDerivation; +import org.bitcoinj.crypto.HDPath; /** + * The type Secp 256 k 1 key derive. + * * @author fearlessfe * @since 2023.02 */ +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") public class SECP256K1KeyDerive { - private final String defaultDerivePath = "m/54H/784H/0H/0/0"; - private byte[] key; - private byte[] chaincode; + private static final String DEFAULT_DERIVE_PATH = "m/54H/784H/0H/0/0"; + private final byte[] key; + private final byte[] chaincode; private DeterministicKey parent; private HDPath childPath; + /** + * Create key by default path secp 256 k 1 key derive. + * + * @param seed the seed + * @return the secp 256 k 1 key derive + */ public static SECP256K1KeyDerive createKeyByDefaultPath(byte[] seed) { return createMasterKey(seed).deriveFromPath(""); } + /** + * Create master key secp 256 k 1 key derive. + * + * @param seed the seed + * @return the secp 256 k 1 key derive + */ public static SECP256K1KeyDerive createMasterKey(byte[] seed) { DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(seed); return new SECP256K1KeyDerive( master.getPrivKey().toByteArray(), master.getChainCode(), master.getPath()); } + /** + * Instantiates a new Secp 256 k 1 key derive. + * + * @param key the key + * @param chaincode the chaincode + */ public SECP256K1KeyDerive(byte[] key, byte[] chaincode) { this.key = key; this.chaincode = chaincode; } + /** + * Instantiates a new Secp 256 k 1 key derive. + * + * @param key the key + * @param chaincode the chaincode + * @param path the path + */ public SECP256K1KeyDerive(byte[] key, byte[] chaincode, HDPath path) { this.key = key; this.chaincode = chaincode; this.childPath = path; } + /** + * Instantiates a new Secp 256 k 1 key derive. + * + * @param key the key + * @param chaincode the chaincode + * @param path the path + * @param parent the parent + */ public SECP256K1KeyDerive(byte[] key, byte[] chaincode, HDPath path, DeterministicKey parent) { this.key = key; this.chaincode = chaincode; @@ -64,6 +103,12 @@ public SECP256K1KeyDerive(byte[] key, byte[] chaincode, HDPath path, Determinist this.parent = parent; } + /** + * Derive secp 256 k 1 key derive. + * + * @param index the index + * @return the secp 256 k 1 key derive + */ public SECP256K1KeyDerive derive(int index) { boolean isHardened = hasHardenedBit(index); if (isHardened) { @@ -83,9 +128,15 @@ public SECP256K1KeyDerive derive(int index) { childKey.getParent()); } + /** + * Derive from path secp 256 k 1 key derive. + * + * @param path the path + * @return the secp 256 k 1 key derive + */ public SECP256K1KeyDerive deriveFromPath(String path) { if (StringUtils.isAnyBlank(path)) { - path = defaultDerivePath; + path = DEFAULT_DERIVE_PATH; } HDPath hdPath = HDPath.parsePath(path); Iterator it = hdPath.iterator(); @@ -100,10 +151,20 @@ private boolean hasHardenedBit(int a) { return (a & ChildNumber.HARDENED_BIT) != 0; } + /** + * Get key byte [ ]. + * + * @return the byte [ ] + */ public byte[] getKey() { return key; } + /** + * Get chaincode byte [ ]. + * + * @return the byte [ ] + */ public byte[] getChaincode() { return chaincode; } diff --git a/src/main/java/io/sui/crypto/SECP256K1KeyPair.java b/src/main/java/io/sui/crypto/SECP256K1KeyPair.java index 2e085ef..f29e1b5 100644 --- a/src/main/java/io/sui/crypto/SECP256K1KeyPair.java +++ b/src/main/java/io/sui/crypto/SECP256K1KeyPair.java @@ -115,5 +115,5 @@ public String encodePrivateKey() { new byte[] {SignatureScheme.Secp256k1.getScheme()}, this.keyPair.getPrivKeyBytes()); return Base64.toBase64String(data); - }; + } } diff --git a/src/test/java/io/sui/crypto/ED25519KeyDeriveTest.java b/src/test/java/io/sui/crypto/ED25519KeyDeriveTest.java index e6ce859..b6875cd 100644 --- a/src/test/java/io/sui/crypto/ED25519KeyDeriveTest.java +++ b/src/test/java/io/sui/crypto/ED25519KeyDeriveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -21,16 +21,21 @@ import com.google.common.io.BaseEncoding; import org.junit.jupiter.api.Test; +/** The type Ed25519 key derive test. */ +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") public class ED25519KeyDeriveTest { + /** The constant HARDENED_BIT. */ public static final int HARDENED_BIT = 0x80000000; - private String seedString = "000102030405060708090a0b0c0d0e0f"; + private static final String SEED = "000102030405060708090a0b0c0d0e0f"; - private String m_priv = "2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7"; - private String m_chain = "90046a93de5380a72b5e45010748567d5ea02bbf6522f979e05c0d8d8ca9fffb"; + private static final String M_PRIV = + "2b4be7f19ee27bbf30c667b642d5f4aa69fd169872f8fc3059c08ebae2eb19e7"; + private static final String M_CHAIN = + "90046a93de5380a72b5e45010748567d5ea02bbf6522f979e05c0d8d8ca9fffb"; - private int[] path = + private static final int[] PATH = new int[] { 0 | HARDENED_BIT, 1 | HARDENED_BIT, @@ -38,7 +43,7 @@ public class ED25519KeyDeriveTest { 2 | HARDENED_BIT, 1000000000 | HARDENED_BIT }; - private String[] chains = + private static final String[] CHAINS = new String[] { "8b59aa11380b624e81507a27fedda59fea6d0b779a778918a2fd3590e16e9c69", "a320425f77d1b5c2505a6b1b27382b37368ee640e3557c315416801243552f14", @@ -47,7 +52,7 @@ public class ED25519KeyDeriveTest { "68789923a0cac2cd5a29172a475fe9e0fb14cd6adb5ad98a3fa70333e7afa230" }; - private String[] privs = + private static final String[] PRIVS = new String[] { "68e0fe46dfb67e368c75379acec591dad19df3cde26e63b93a8e704f1dade7a3", "b1d0bad404bf35da785a64ca1ac54b2617211d2777696fbffaf208f746ae84f2", @@ -56,28 +61,30 @@ public class ED25519KeyDeriveTest { "8f94d394a8e8fd6b1bc2f3f49f5c47e385281d5c17e65324b0f62483e37e8793" }; + /** Test key derive. */ @Test - void TestKeyDerive() throws Exception { - byte[] seed = BaseEncoding.base16().decode(seedString.toUpperCase()); + void testKeyDerive() { + byte[] seed = BaseEncoding.base16().decode(ED25519KeyDeriveTest.SEED.toUpperCase()); ED25519KeyDerive master = ED25519KeyDerive.createMasterKey(seed); - assertEquals(m_priv.toUpperCase(), BaseEncoding.base16().encode(master.getKey())); - assertEquals(m_chain.toUpperCase(), BaseEncoding.base16().encode(master.getChaincode())); + assertEquals(M_PRIV.toUpperCase(), BaseEncoding.base16().encode(master.getKey())); + assertEquals(M_CHAIN.toUpperCase(), BaseEncoding.base16().encode(master.getChaincode())); ED25519KeyDerive current = master; - for (int i = 0; i < path.length; i++) { - ED25519KeyDerive next = current.derive(path[i]); + for (int i = 0; i < PATH.length; i++) { + ED25519KeyDerive next = current.derive(PATH[i]); - assertEquals(privs[i].toUpperCase(), BaseEncoding.base16().encode(next.getKey())); - assertEquals(chains[i].toUpperCase(), BaseEncoding.base16().encode(next.getChaincode())); + assertEquals(PRIVS[i].toUpperCase(), BaseEncoding.base16().encode(next.getKey())); + assertEquals(CHAINS[i].toUpperCase(), BaseEncoding.base16().encode(next.getChaincode())); current = next; } } + /** Test key derive path. */ @Test - void TestKeyDerivePath() throws Exception { - byte[] seed = BaseEncoding.base16().decode(seedString.toUpperCase()); + void testKeyDerivePath() { + byte[] seed = BaseEncoding.base16().decode(ED25519KeyDeriveTest.SEED.toUpperCase()); ED25519KeyDerive master = ED25519KeyDerive.createMasterKey(seed); @@ -85,8 +92,8 @@ void TestKeyDerivePath() throws Exception { ED25519KeyDerive last = master.deriveFromPath(path); assertEquals( - privs[privs.length - 1].toUpperCase(), BaseEncoding.base16().encode(last.getKey())); + PRIVS[PRIVS.length - 1].toUpperCase(), BaseEncoding.base16().encode(last.getKey())); assertEquals( - chains[chains.length - 1].toUpperCase(), BaseEncoding.base16().encode(last.getChaincode())); + CHAINS[CHAINS.length - 1].toUpperCase(), BaseEncoding.base16().encode(last.getChaincode())); } } diff --git a/src/test/java/io/sui/crypto/SECP256K1KeyDeriveTest.java b/src/test/java/io/sui/crypto/SECP256K1KeyDeriveTest.java index dfb404f..09c32f8 100644 --- a/src/test/java/io/sui/crypto/SECP256K1KeyDeriveTest.java +++ b/src/test/java/io/sui/crypto/SECP256K1KeyDeriveTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2023 281165273grape@gmail.com + * Copyright 2022-2023 281165273grape@gmail.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with @@ -22,14 +22,21 @@ import java.util.Arrays; import org.junit.jupiter.api.Test; +/** + * The type Secp256k1 key derive test. + * + * @author f + */ +@SuppressWarnings("checkstyle:AbbreviationAsWordInName") public class SECP256K1KeyDeriveTest { + /** The constant HARDENED_BIT. */ public static final int HARDENED_BIT = 0x80000000; // test case from https://github.com/satoshilabs/slips/blob/master/slip-0010.md - private String seedString = "000102030405060708090a0b0c0d0e0f"; + private final String seedString = "000102030405060708090a0b0c0d0e0f"; - private int[] path = new int[] {0 | HARDENED_BIT, 1, 2 | HARDENED_BIT, 2, 1000000000}; - private String[] chains = + private final int[] path = new int[] {0 | HARDENED_BIT, 1, 2 | HARDENED_BIT, 2, 1000000000}; + private final String[] chains = new String[] { "47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141", "2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19", @@ -38,7 +45,7 @@ public class SECP256K1KeyDeriveTest { "c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e" }; - private String[] privs = + private final String[] privs = new String[] { "edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea", "3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368", @@ -48,11 +55,19 @@ public class SECP256K1KeyDeriveTest { }; // private is 32 bytes, left padding with 00 to 33 bytes - private String m_priv = "e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35"; - private String m_chain = "873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508"; + @SuppressWarnings("checkstyle:MemberName") + private final String m_priv = "e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35"; + + @SuppressWarnings("checkstyle:MemberName") + private final String m_chain = "873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508"; + /** + * Test key derive. + * + * @throws Exception the exception + */ @Test - void TestKeyDerive() throws Exception { + void testKeyDerive() throws Exception { byte[] seed = BaseEncoding.base16().decode(seedString.toUpperCase()); SECP256K1KeyDerive master = SECP256K1KeyDerive.createMasterKey(seed); @@ -69,8 +84,13 @@ void TestKeyDerive() throws Exception { } } + /** + * Test key derive path. + * + * @throws Exception the exception + */ @Test - void TestKeyDerivePath() throws Exception { + void testKeyDerivePath() throws Exception { byte[] seed = BaseEncoding.base16().decode(seedString.toUpperCase()); SECP256K1KeyDerive master = SECP256K1KeyDerive.createMasterKey(seed); @@ -80,12 +100,11 @@ void TestKeyDerivePath() throws Exception { assertEquals( privs[privs.length - 1].toUpperCase(), BaseEncoding.base16().encode(getPriv(last))); - // System.out.println(BaseEncoding.base16().encode(next.getKey())); assertEquals( chains[chains.length - 1].toUpperCase(), BaseEncoding.base16().encode(last.getChaincode())); } - public byte[] getPriv(SECP256K1KeyDerive key) { + private byte[] getPriv(SECP256K1KeyDerive key) { byte[] privKey = key.getKey(); if (privKey.length == 33) { return Arrays.copyOfRange(privKey, 1, privKey.length);