--- /dev/null
+package io.bytom.util;\r
+\r
+import org.bouncycastle.util.encoders.Hex;\r
+\r
+import java.nio.ByteBuffer;\r
+import java.nio.ByteOrder;\r
+\r
+public class PathUtil {\r
+ private static String intToPath(int index) {\r
+ byte[] result = new byte[4];\r
+ result[3] = (byte) (index >> 24 & 0xff);\r
+ result[2] = (byte) (index >> 16 & 0xff);\r
+ result[1] = (byte) (index >> 8 & 0xff);\r
+ result[0] = (byte) (index >> 0 & 0xff);\r
+ return Hex.toHexString(result);\r
+ }\r
+\r
+\r
+// paths = {\r
+//// "2c000000",\r
+//// "99000000",\r
+//// "01000000", accountIndex\r
+//// "00000000", change\r
+//// "01000000" controlProgramIndex\r
+//// }\r
+\r
+ public static byte[][] getBip44Path(int accountIndex, boolean change, int programIndex) {\r
+\r
+ String accountIndexStr = intToPath(accountIndex);\r
+ String changeStr = "00000000";\r
+ String programIndexStr = intToPath(programIndex);\r
+ if (change) {\r
+ changeStr = "01000000";\r
+ }\r
+ byte[][] paths = new byte[][]{\r
+ Hex.decode("2c000000"),\r
+ Hex.decode("99000000"),\r
+ Hex.decode(accountIndexStr),\r
+ Hex.decode(changeStr),\r
+ Hex.decode(programIndexStr),\r
+ };\r
+ return paths;\r
+ }\r
+\r
+ public static byte[][] getBip32Path(int accountIndex) {\r
+ byte[] signerPath = new byte[9];\r
+ byte[] path = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putInt(accountIndex).array();\r
+ System.arraycopy(path, 0, signerPath, 1, 8);\r
+ byte[][] paths = new byte[][]{\r
+ signerPath\r
+ };\r
+ return paths;\r
+ }\r
+}\r