Skip to content

Commit 10213c0

Browse files
committed
use blake1 impl from @noble/hashes instead of foundry-primitives fork
The fork no longer has a reason to exist now. This also silences a security alert about foundry-primitives depending on an insecure version of crypto-js.
1 parent 3996e98 commit 10213c0

File tree

3 files changed

+10
-52
lines changed

3 files changed

+10
-52
lines changed

packages/xchain-crypto/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@
4545
"@types/uuid": "^9.0.1"
4646
},
4747
"dependencies": {
48+
"@noble/hashes": "^1.8.0",
4849
"@scure/base": "^1.2.6",
4950
"bip39": "^3.1.0",
5051
"crypto-js": "4.2.0",
51-
"foundry-primitives-xchainjs": "github:xchainjs/foundry-primitives-js#master",
5252
"uuid": "^9.0.0"
5353
},
5454
"publishConfig": {

packages/xchain-crypto/src/crypto.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as bip39 from 'bip39'
22
import crypto from 'crypto'
3-
import { blake256 } from 'foundry-primitives-xchainjs'
3+
import { blake256 } from '@noble/hashes/blake1.js'
44
import { v4 as uuidv4 } from 'uuid'
55

66
import { pbkdf2Async } from './utils'
@@ -123,7 +123,8 @@ export const encryptToKeyStore = async (phrase: string, password: string): Promi
123123
const derivedKey = await pbkdf2Async(Buffer.from(password), salt, kdfParams.c, kdfParams.dklen, hashFunction)
124124
const cipherIV = crypto.createCipheriv(cipher, derivedKey.slice(0, 16), iv)
125125
const cipherText = Buffer.concat([cipherIV.update(Buffer.from(phrase, 'utf8')), cipherIV.final()])
126-
const mac = blake256(Buffer.concat([derivedKey.slice(16, 32), Buffer.from(cipherText)]))
126+
const mac_bytes: Uint8Array = blake256(Buffer.concat([derivedKey.slice(16, 32), Buffer.from(cipherText)]))
127+
const mac: string = Buffer.from(mac_bytes).toString('hex')
127128

128129
const cryptoStruct = {
129130
cipher: cipher,
@@ -162,7 +163,8 @@ export const decryptFromKeystore = async (keystore: Keystore, password: string):
162163
)
163164

164165
const ciphertext = Buffer.from(keystore.crypto.ciphertext, 'hex')
165-
const mac = blake256(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
166+
const mac_bytes: Uint8Array = blake256(Buffer.concat([derivedKey.slice(16, 32), ciphertext]))
167+
const mac: string = Buffer.from(mac_bytes).toString('hex')
166168

167169
if (mac !== keystore.crypto.mac) throw new Error('Invalid password')
168170
const decipher = crypto.createDecipheriv(

yarn.lock

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4057,14 +4057,14 @@ __metadata:
40574057
version: 0.0.0-use.local
40584058
resolution: "@xchainjs/xchain-crypto@workspace:packages/xchain-crypto"
40594059
dependencies:
4060+
"@noble/hashes": "npm:^1.8.0"
40604061
"@scure/base": "npm:^1.2.6"
40614062
"@types/bip39": "npm:^3.0.0"
40624063
"@types/crypto-js": "npm:^4.1.1"
40634064
"@types/node": "npm:^18.15.12"
40644065
"@types/uuid": "npm:^9.0.1"
40654066
bip39: "npm:^3.1.0"
40664067
crypto-js: "npm:4.2.0"
4067-
foundry-primitives-xchainjs: "github:xchainjs/foundry-primitives-js#master"
40684068
uuid: "npm:^9.0.0"
40694069
languageName: unknown
40704070
linkType: soft
@@ -5129,13 +5129,6 @@ __metadata:
51295129
languageName: node
51305130
linkType: hard
51315131

5132-
"bignumber.js@npm:^7.2.1":
5133-
version: 7.2.1
5134-
resolution: "bignumber.js@npm:7.2.1"
5135-
checksum: 10c0/7e2cb10cdc1991696666b129f3b888c44a5e35bd3a5e990b2d2c934c7bc6863fb42b45fdea830484ca0d9e0b9a70d15e1d43fcd03a0e04326612b8e3ac76a0ae
5136-
languageName: node
5137-
linkType: hard
5138-
51395132
"bignumber.js@npm:^9.0.0, bignumber.js@npm:^9.1.2":
51405133
version: 9.1.2
51415134
resolution: "bignumber.js@npm:9.1.2"
@@ -5348,7 +5341,7 @@ __metadata:
53485341
languageName: node
53495342
linkType: hard
53505343

5351-
"blakejs@npm:1.2.1, blakejs@npm:^1.1.0":
5344+
"blakejs@npm:1.2.1":
53525345
version: 1.2.1
53535346
resolution: "blakejs@npm:1.2.1"
53545347
checksum: 10c0/c284557ce55b9c70203f59d381f1b85372ef08ee616a90162174d1291a45d3e5e809fdf9edab6e998740012538515152471dc4f1f9dbfa974ba2b9c1f7b9aad7
@@ -5571,7 +5564,7 @@ __metadata:
55715564
languageName: node
55725565
linkType: hard
55735566

5574-
"buffer@npm:^5.2.1, buffer@npm:^5.5.0":
5567+
"buffer@npm:^5.5.0":
55755568
version: 5.7.1
55765569
resolution: "buffer@npm:5.7.1"
55775570
dependencies:
@@ -7495,25 +7488,6 @@ __metadata:
74957488
languageName: node
74967489
linkType: hard
74977490

7498-
"foundry-primitives-xchainjs@github:xchainjs/foundry-primitives-js#master":
7499-
version: 0.2.1
7500-
resolution: "foundry-primitives-xchainjs@https://github.com/xchainjs/foundry-primitives-js.git#commit=7daeca67840d95bda9afb8f527e9d5a397d67ac9"
7501-
dependencies:
7502-
bignumber.js: "npm:^7.2.1"
7503-
blakejs: "npm:^1.1.0"
7504-
bn.js: "npm:^4.11.8"
7505-
buffer: "npm:^5.2.1"
7506-
crypto-js: "npm:4.2.0"
7507-
elliptic: "npm:^6.6.1"
7508-
hmac-drbg: "npm:^1.0.1"
7509-
lodash: "npm:^4.17.21"
7510-
node-forge: "npm:^1.3.1"
7511-
rlp: "npm:^2.1.0"
7512-
tweetnacl: "npm:^1.0.3"
7513-
checksum: 10c0/1c0adb408012a4c35a63d043503e515595ca7310ab1dccb3e143071e44a20fb655a596a8caa097f4ba5d3d7a46682a8bffd76203784a6d25e29b4a6dff949009
7514-
languageName: node
7515-
linkType: hard
7516-
75177491
"fs-constants@npm:^1.0.0":
75187492
version: 1.0.0
75197493
resolution: "fs-constants@npm:1.0.0"
@@ -10230,13 +10204,6 @@ __metadata:
1023010204
languageName: node
1023110205
linkType: hard
1023210206

10233-
"node-forge@npm:^1.3.1":
10234-
version: 1.3.1
10235-
resolution: "node-forge@npm:1.3.1"
10236-
checksum: 10c0/e882819b251a4321f9fc1d67c85d1501d3004b4ee889af822fd07f64de3d1a8e272ff00b689570af0465d65d6bf5074df9c76e900e0aff23e60b847f2a46fbe8
10237-
languageName: node
10238-
linkType: hard
10239-
1024010207
"node-gyp-build@npm:^4.2.0, node-gyp-build@npm:^4.3.0, node-gyp-build@npm:^4.5.0":
1024110208
version: 4.7.1
1024210209
resolution: "node-gyp-build@npm:4.7.1"
@@ -11379,17 +11346,6 @@ __metadata:
1137911346
languageName: node
1138011347
linkType: hard
1138111348

11382-
"rlp@npm:^2.1.0":
11383-
version: 2.2.7
11384-
resolution: "rlp@npm:2.2.7"
11385-
dependencies:
11386-
bn.js: "npm:^5.2.0"
11387-
bin:
11388-
rlp: bin/rlp
11389-
checksum: 10c0/166c449f4bc794d47f8e337bf0ffbcfdb26c33109030aac4b6e5a33a91fa85783f2290addeb7b3c89d6d9b90c8276e719494d193129bed0a60a2d4a6fd658277
11390-
languageName: node
11391-
linkType: hard
11392-
1139311349
"rollup-plugin-visualizer@npm:^5.14.0":
1139411350
version: 5.14.0
1139511351
resolution: "rollup-plugin-visualizer@npm:5.14.0"
@@ -12693,7 +12649,7 @@ __metadata:
1269312649
languageName: node
1269412650
linkType: hard
1269512651

12696-
"tweetnacl@npm:1.0.3, tweetnacl@npm:^1.0.3":
12652+
"tweetnacl@npm:1.0.3":
1269712653
version: 1.0.3
1269812654
resolution: "tweetnacl@npm:1.0.3"
1269912655
checksum: 10c0/069d9df51e8ad4a89fbe6f9806c68e06c65be3c7d42f0701cc43dba5f0d6064686b238bbff206c5addef8854e3ce00c643bff59432ea2f2c639feab0ee1a93f9

0 commit comments

Comments
 (0)