MCPcopy Create free account
hub / github.com/ccxt/ccxt / base58Decode

Method base58Decode

java/lib/src/main/java/io/github/ccxt/base/Encode.java:118–154  ·  view source on GitHub ↗
(String input)

Source from the content-addressed store, hash-verified

116 }
117 }
118 private static byte[] base58Decode(String input) {
119 if (input == null || input.isEmpty()) return new byte[0];
120
121 // Count leading zeros
122 int zeros = 0;
123 while (zeros < input.length() && input.charAt(zeros) == '1') zeros++;
124
125 // Base58 -> base256
126 byte[] b256 = new byte[input.length() * 733 / 1000 + 1];
127 int length = 0;
128 for (int i = zeros; i < input.length(); i++) {
129 int ch = input.charAt(i);
130 if (ch >= 128 || B58_INDEX[ch] == -1) throw new IllegalArgumentException("Invalid Base58 char: " + (char) ch);
131 int carry = B58_INDEX[ch];
132 int j = b256.length - 1;
133 for (int k = b256.length - 1; k >= b256.length - length; k--, j--) {
134 carry += (b256[k] & 0xFF) * 58;
135 b256[k] = (byte) (carry & 0xFF);
136 carry >>= 8;
137 }
138 while (carry > 0) {
139 b256[j--] = (byte) (carry & 0xFF);
140 carry >>= 8;
141 length++;
142 }
143 }
144
145 // Skip leading zeros in b256
146 int idx = b256.length - length;
147 while (idx < b256.length && b256[idx] == 0) { idx++; }
148
149 // Result = zeros + the rest
150 byte[] res = new byte[zeros + (b256.length - idx)];
151 Arrays.fill(res, 0, zeros, (byte) 0);
152 System.arraycopy(b256, idx, res, zeros, res.length - zeros);
153 return res;
154 }
155
156 // ----------------------------
157 // binary concat

Callers 1

Base58ToBinaryMethod · 0.95

Calls 2

isEmptyMethod · 0.80
lengthMethod · 0.45

Tested by

no test coverage detected