1 |
|
2 |
|
3 |
|
4 | import { sshash } from "./sshash.js";
|
5 | export function checkAddressChecksum(decoded) {
|
6 | const ss58Length = decoded[0] & 0b01000000 ? 2 : 1;
|
7 | const ss58Decoded = ss58Length === 1 ? decoded[0] : (decoded[0] & 0b00111111) << 2 | decoded[1] >> 6 | (decoded[1] & 0b00111111) << 8;
|
8 |
|
9 |
|
10 | const isPublicKey = [34 + ss58Length, 35 + ss58Length].includes(decoded.length);
|
11 | const length = decoded.length - (isPublicKey ? 2 : 1);
|
12 |
|
13 |
|
14 | const hash = sshash(decoded.subarray(0, length));
|
15 | const isValid = (decoded[0] & 0b10000000) === 0 && ![46, 47].includes(decoded[0]) && (isPublicKey ? decoded[decoded.length - 2] === hash[0] && decoded[decoded.length - 1] === hash[1] : decoded[decoded.length - 1] === hash[0]);
|
16 | return [isValid, length, ss58Length, ss58Decoded];
|
17 | } |
\ | No newline at end of file |