Skip to content

Commit

Permalink
use util-crypto to replace blake2 lib (#40)
Browse files Browse the repository at this point in the history
* use util-crypto to replace blake2 lib

* update yarn.lock

update yarn.lock
  • Loading branch information
yjhmelody authored Jun 4, 2021
1 parent 1482e8f commit 852772b
Show file tree
Hide file tree
Showing 5 changed files with 540 additions and 458 deletions.
1 change: 0 additions & 1 deletion as-packages/lang/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"as-scale-codec": "0.2.1"
},
"devDependencies": {
"@types/blake2": "^4.0.1",
"assemblyscript": "0.18",
"@types/node": "14",
"ts-node": "9",
Expand Down
1 change: 0 additions & 1 deletion ts-packages/contract-metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"author": "yjhmelody <[email protected]>",
"devDependencies": {
"ts-jest": "^26.3.0",
"@types/blake2": "^4.0.1",
"assemblyscript": "0.18",
"@types/node": "14",
"ts-node": "9",
Expand Down
5 changes: 1 addition & 4 deletions ts-packages/transform/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,8 @@
},
"dependencies": {
"assemblyscript": "0.18",
"blake2": "4.0.2",
"@polkadot/util-crypto": "^6.6",
"handlebars": "4.7.6",
"contract-metadata": "0.1.0"
},
"devDependencies": {
"@types/blake2": "^4.0.1"
}
}
8 changes: 3 additions & 5 deletions ts-packages/transform/src/preprocess/selector.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as blake2 from "blake2";

import { blake2AsHex } from "@polkadot/util-crypto";
export class KeySelector {
hex: string;
short: string;
Expand All @@ -8,9 +7,8 @@ export class KeySelector {
key: string;
constructor(key: string) {
this.key = key;
let keyHash = blake2.createHash('blake2b', { digestLength: 32 });
keyHash.update(Buffer.from(key));
let hexStr = keyHash.digest("hex");
// remove 0x
let hexStr = blake2AsHex(key, 256).substring(2);
let selectorArr = [];
for (let index = 0; index < 32; index++) {
selectorArr.push("0x" + hexStr.substring(index * 2, index * 2 + 2));
Expand Down
Loading

0 comments on commit 852772b

Please sign in to comment.