Fix Polkadot identicon blake2 (#103)

* Fix Polkadot identicon blake2

* CHANGELOG
This commit is contained in:
Jaco Greeff
2019-03-27 11:39:31 +01:00
committed by GitHub
parent f7dec928ae
commit 5beff953fb
7 changed files with 52 additions and 45 deletions
+4
View File
@@ -1,3 +1,7 @@
# 0.34.1
- Fix for blake2 in Polkadot identicon generation
# 0.33.1
- Rename createUri and createExternal to addExternal and addUri
+2 -2
View File
@@ -24,8 +24,8 @@
"react": "*"
},
"devDependencies": {
"@polkadot/keyring": "^0.40.1",
"@polkadot/util-crypto": "^0.40.1",
"@polkadot/keyring": "^0.42.0-beta.1",
"@polkadot/util-crypto": "^0.42.0-beta.1",
"xmlserializer": "^0.6.1"
}
}
+5 -2
View File
@@ -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;
+3 -3
View File
@@ -17,9 +17,9 @@
"styled-components": "^4.1.3"
},
"devDependencies": {
"@polkadot/keyring": "^0.40.1",
"@polkadot/types": "^0.50.1",
"@polkadot/util": "^0.40.1"
"@polkadot/keyring": "^0.42.0-beta.1",
"@polkadot/types": "^0.52.0-beta.1",
"@polkadot/util": "^0.42.0-beta.1"
},
"peerDependencies": {
"@polkadot/keyring": "*",
+1 -1
View File
@@ -10,7 +10,7 @@
"license": "Apache-2.0",
"dependencies": {
"@babel/runtime": "^7.3.4",
"@polkadot/util": "^0.40.1",
"@polkadot/util": "^0.42.0-beta.1",
"@types/store": "^2.0.1",
"store": "^2.0.12"
}
+1 -1
View File
@@ -12,7 +12,7 @@
"@babel/runtime": "^7.3.4"
},
"devDependencies": {
"@polkadot/types": "^0.50.1"
"@polkadot/types": "^0.52.0-beta.1"
},
"peerDependencies": {
"@polkadot/types": "*"
+36 -36
View File
@@ -1683,14 +1683,14 @@
typescript "^3.3.4000"
vuepress "^1.0.0-alpha.44"
"@polkadot/keyring@^0.40.1":
version "0.40.1"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.40.1.tgz#6dd0f1577920b1e4c88a8c7d201cd1b186fc0167"
integrity sha512-Kz6BQU9RC04XCw5aulQQtpRk3kF0EGT89ANKx5oUAIqyKeg8xGty0odwEP8w2ecrR+23JLNGuxe/1d9tjfNZjA==
"@polkadot/keyring@^0.42.0-beta.1":
version "0.42.0-beta.1"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.42.0-beta.1.tgz#3620097d48dd53527164d00d7e2374447b094fa5"
integrity sha512-tfGCbF3Ey9zcRjnmwfToAmai67F3wsuXsZoCSeHUodhBbbJTUrYKz278F11+W4nslCJ7ZWzpfY1FchfWo74Vkw==
dependencies:
"@babel/runtime" "^7.4.0"
"@polkadot/util" "^0.40.1"
"@polkadot/util-crypto" "^0.40.1"
"@polkadot/util" "^0.42.0-beta.1"
"@polkadot/util-crypto" "^0.42.0-beta.1"
"@types/bs58" "^4.0.0"
bs58 "^4.0.1"
@@ -1699,25 +1699,25 @@
resolved "https://registry.yarnpkg.com/@polkadot/ts/-/ts-0.1.56.tgz#ffd6e9c95704a7fb90b918193b9dc5c440114b27"
integrity sha512-wnt4zXxZXyz6WaubTO/I+nUElwV2DogFzdl6CrKfVn2PTWp8uHN06W9s40FH57ORtmQfDr9rLRP8Nq+oIyElbg==
"@polkadot/types@^0.50.1":
version "0.50.1"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.50.1.tgz#26c3b8bf8c5a2ab3001ec7a25b63709e3e03ee1d"
integrity sha512-mweg0TnGYA9MPVxyxtDPMkRplbz6KTWz/tye2MJGMSLQwgRXXf3W9PD73dOERD4E23C2bE8BFM2d5KKIQWMMbw==
"@polkadot/types@^0.52.0-beta.1":
version "0.52.0-beta.1"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-0.52.0-beta.1.tgz#cfefaff3c0cf5da62b971f895e89bd6d2b2b03b4"
integrity sha512-bXxe4ztsjfAAxC90pEIK0/Dh/qMgcq0P1af6P9vqeMBVfIVSn7X1KLr4JfjWP9L2DiknAGBZj+7TvXSF7khRKA==
dependencies:
"@babel/runtime" "^7.4.0"
"@polkadot/keyring" "^0.40.1"
"@polkadot/util" "^0.40.1"
"@polkadot/keyring" "^0.42.0-beta.1"
"@polkadot/util" "^0.42.0-beta.1"
"@polkadot/util-crypto@^0.40.1":
version "0.40.1"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.40.1.tgz#58d76bedb3e964c73805229de7b4a81b3c8e7853"
integrity sha512-/rLBoeTp5ZnGXjyZw423EHyAjV5gw7tBm+3oWggkz2HnCRUqwggIFS/Rej2IaZWojL8tkz7X0i/wSQFyVL+M2g==
"@polkadot/util-crypto@^0.42.0-beta.1":
version "0.42.0-beta.1"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.42.0-beta.1.tgz#10832842db802037592436eb50343e7345df9638"
integrity sha512-uvP64cOaBKSmL/pnpYBfVRakQrwvypVtmj4fKVDgs3P7d38h9Kpg9cCcsYoT9jscx0a912QL1xmNJPKNakYWMQ==
dependencies:
"@babel/runtime" "^7.4.0"
"@polkadot/util" "^0.40.1"
"@polkadot/wasm-crypto" "^0.3.1"
"@polkadot/wasm-dalek-ed25519" "^0.3.1"
"@polkadot/wasm-schnorrkel" "^0.3.1"
"@polkadot/util" "^0.42.0-beta.1"
"@polkadot/wasm-crypto" "^0.5.1"
"@polkadot/wasm-dalek-ed25519" "^0.5.1"
"@polkadot/wasm-schnorrkel" "^0.5.1"
"@types/bip39" "^2.4.2"
"@types/pbkdf2" "^3.0.0"
"@types/secp256k1" "^3.5.0"
@@ -1730,10 +1730,10 @@
tweetnacl "^1.0.1"
xxhashjs "^0.2.2"
"@polkadot/util@^0.40.1":
version "0.40.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.40.1.tgz#4a990d134ea394425e9b1ceb8a7f1fc0868a5a66"
integrity sha512-S9owTDNIB7sNFzon4lK/c9A+6O73XcoCPAIYA3TtNg494qA1X8exesenVJgVFzqht/Z3B/RAXLsEa8DSk9BycQ==
"@polkadot/util@^0.42.0-beta.1":
version "0.42.0-beta.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.42.0-beta.1.tgz#93baa0fc129467237b7eb226e14fafffd160f4e9"
integrity sha512-PZC/yArV5D4J//IkqYwPo1rmlLzwf1SDWE4COOSDZJfU1hGjrwucDre/jwtQFQjZAUv458BXiFUHxgEd5dHX2w==
dependencies:
"@babel/runtime" "^7.4.0"
"@types/bn.js" "^4.11.4"
@@ -1745,20 +1745,20 @@
ip-regex "^4.0.0"
moment "^2.24.0"
"@polkadot/wasm-crypto@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto/-/wasm-crypto-0.3.1.tgz#d605d18557076f01b00610844ba41bf12298e502"
integrity sha512-G1QEKC8o6SkKc65xjgMzujoA9rEQpMp/RZCVqrrmevgBhxTSohVsbXsBO3ooNtQLdq0DfFqUH13FatV0RxVdHQ==
"@polkadot/wasm-crypto@^0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@polkadot/wasm-crypto/-/wasm-crypto-0.5.1.tgz#3d5734d6dc2f5174a411689f78538287d21bd710"
integrity sha512-8h7uz85bvLVirtbxLkELr9H25oqAfgnQuDP6FP3QJeag7VfMtVvRF5U2JWGgsiUSiRg+UJnTuCleOSDnageRmg==
"@polkadot/wasm-dalek-ed25519@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@polkadot/wasm-dalek-ed25519/-/wasm-dalek-ed25519-0.3.1.tgz#52b86a3fabbbdeb60273b51685d089d5be2bfe6a"
integrity sha512-TvFMpE0y2RTCDRcVAer/94bCT4X8qHTU/K5GEhiqHtsLNZ9igJeSn27PRHUF3rzq1YgwCLvG6/wQ+4p+4DWTlQ==
"@polkadot/wasm-dalek-ed25519@^0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@polkadot/wasm-dalek-ed25519/-/wasm-dalek-ed25519-0.5.1.tgz#7b59f5381c8e16335d4de31e2e30ac7d7592762f"
integrity sha512-wBz1/tJJHylQ8cfB0J11h8T46m6trAq+tyNzGCaoDNFyb7XDg3wNxpyWNHg1PGrI59sjaDiTfvr3RUiodWgcng==
"@polkadot/wasm-schnorrkel@^0.3.1":
version "0.3.1"
resolved "https://registry.yarnpkg.com/@polkadot/wasm-schnorrkel/-/wasm-schnorrkel-0.3.1.tgz#08287848f769dee4955517348905888bd289f277"
integrity sha512-2J/lNZe7oDWvzUbsEfvKfiiAvBIBbIsppeBGahwSg2Y+cLweQgThXGizPpQoPo0tHxgMKdTi6jhPu7tLzCW/cA==
"@polkadot/wasm-schnorrkel@^0.5.1":
version "0.5.1"
resolved "https://registry.yarnpkg.com/@polkadot/wasm-schnorrkel/-/wasm-schnorrkel-0.5.1.tgz#9db91db2e262668bdc1b037ef6d010ba2a29bf41"
integrity sha512-uFlYRtMYeuVzW72+I01ToKqbPmn/3gFJzMc2MJcpOgOEPHNrQ1erXkqy0s1BxJYIDaO5SlvAQK/lRQbAWEYUDA==
"@types/accepts@*":
version "1.3.5"