mirror of
https://github.com/pezkuwichain/pezkuwi-ui.git
synced 2026-07-10 21:37:26 +00:00
Fix Polkadot identicon blake2 (#103)
* Fix Polkadot identicon blake2 * CHANGELOG
This commit is contained in:
@@ -31,11 +31,14 @@ type Scheme = {
|
||||
colors: Array<number>
|
||||
};
|
||||
|
||||
const blake2 = (value: Uint8Array) =>
|
||||
blake2AsU8a(value, 512);
|
||||
|
||||
const s = 64;
|
||||
const c = s / 2;
|
||||
const z = s / 64 * 5;
|
||||
|
||||
const zero = blake2AsU8a(new Uint8Array(32));
|
||||
const zero = blake2(new Uint8Array(32));
|
||||
const schema: { [index: string]: Scheme } = {
|
||||
target: { freq: 1, colors: [0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 0, 28, 0, 1] },
|
||||
cube: { freq: 20, colors: [0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 0, 1, 3, 2, 4, 3, 5] },
|
||||
@@ -130,7 +133,7 @@ export default class Identicon extends React.PureComponent<Props> {
|
||||
private getColors () {
|
||||
const { value } = this.props;
|
||||
const total = Object.keys(schema).map(k => schema[k].freq).reduce((a, b) => a + b);
|
||||
const id = Array.from(blake2AsU8a(decodeAddress(value))).map((x, i) => (x + 256 - zero[i]) % 256);
|
||||
const id = Array.from(blake2(decodeAddress(value))).map((x, i) => (x + 256 - zero[i]) % 256);
|
||||
const d = Math.floor((id[30] + id[31] * 256) % total);
|
||||
const rot = (id[28] % 6) * 3;
|
||||
const sat = (Math.floor(id[29] * 70 / 256 + 26) % 80) + 30;
|
||||
|
||||
Reference in New Issue
Block a user