Skip to content

Commit

Permalink
refactor: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Dec 7, 2024
1 parent 49c97a5 commit 195f210
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 31 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = {
moduleNameMapper: {
...pathsToModuleNameMapper(packagePaths, { prefix: '<rootDir>/' }),
...pathsToModuleNameMapper(directoryPaths),
'^crypto-es$': 'crypto-js'
// '^crypto-es$': 'crypto-js'
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test": "jest",
"test:sdk-ts:core:stargate": "jest ./packages/sdk-ts/src/core/stargate",
"test:sdk-ts:core:modules": "jest ./packages/sdk-ts/src/core/modules",
"test:sdk-ts:core:account": "jest ./packages/sdk-ts/src/core/account",
"test:sdk-ts:core": "jest ./packages/sdk-ts/src/core",
"test:sdk-ts:utils": "jest ./packages/sdk-ts/src/utils",
"test:sdk-ts:client": "jest ./packages/sdk-ts/src/client",
Expand Down
2 changes: 1 addition & 1 deletion packages/exceptions/src/exceptions/types/codes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StatusCodes } from 'http-status-codes'

export declare enum GrpcErrorCode {
export enum GrpcErrorCode {
OK = 0,
Canceled = 1,
Unknown = 2,
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@
"@injectivelabs/utils": "^1.14.34-beta.0",
"@metamask/eth-sig-util": "^4.0.0",
"@noble/curves": "^1.7.0",
"@noble/hashes": "^1.6.1",
"axios": "^1.6.4",
"bech32": "^2.0.0",
"bip39": "^3.0.4",
"cosmjs-types": "^0.9.0",
"crypto-es": "^2.1.0",
"crypto-js": "^4.2.0",
"ethereumjs-util": "^7.1.4",
"ethers": "^6.5.1",
"google-protobuf": "^3.21.0",
Expand All @@ -165,7 +166,6 @@
},
"devDependencies": {
"@types/crypto-js": "^4.2.2",
"@types/lodash.toarray": "^4.4.7",
"crypto-js": "^4.2.0"
"@types/lodash.toarray": "^4.4.7"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getNetworkEndpoints, Network } from '@injectivelabs/networks'
import { ChainGrpcGovApi } from './ChainGrpcGovApi.js'
// import { mockFactory } from '@injectivelabs/test-utils'
// import { mockFactory } from '@injectivelabs/utils/test-utils'
import { ChainGrpcGovTransformer } from '../transformers/index.js'
import { CosmosGovV1Gov } from '@injectivelabs/core-proto-ts'

Expand Down
11 changes: 5 additions & 6 deletions packages/sdk-ts/src/core/accounts/PrivateKey.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,16 @@ describe('PrivateKey', () => {
const privateKey = PrivateKey.fromHex(pk)
const publicKey = privateKey.toHex()

const privKeySignatureArray = privateKey.sign(
const ethersVerifiedSigner = verifyMessage(message, ethersSignature)
const ethersSignatureVerifiedCorrectly = ethersVerifiedSigner === publicKey
expect(ethersSignatureVerifiedCorrectly).toBe(true)

const privKeySignatureArray = privateKey.signHashed(
Buffer.from(toUtf8(message), 'utf-8'),
)
const privKeySignature = `0x${Buffer.from(privKeySignatureArray).toString(
'hex',
)}`

const ethersVerifiedSigner = verifyMessage(message, ethersSignature)
const ethersSignatureVerifiedCorrectly = ethersVerifiedSigner === publicKey
expect(ethersSignatureVerifiedCorrectly).toBe(true)

const privKeyVerifiedSigner = verifyMessage(message, privKeySignature)
const privKeySignatureVerifiedCorrectly =
privKeyVerifiedSigner === publicKey
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MsgExec from './MsgExec'
import { mockFactory } from 'deprecated/test-utils/dist/cjs'
import { mockFactory } from '@injectivelabs/utils/test-utils'
import { BigNumberInBase } from '@injectivelabs/utils'
import MsgSend from '../../bank/msgs/MsgSend.js'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MsgCancelSpotOrder from './MsgCancelSpotOrder'
import { mockFactory, prepareEip712 } from 'deprecated/test-utils/dist/cjs'
import { mockFactory, prepareEip712 } from '@injectivelabs/utils/test-utils'
import { IndexerGrpcWeb3GwApi } from '../../../../client/indexer/grpc/IndexerGrpcWeb3GwApi.js'
import snakecaseKeys from 'snakecase-keys'
import { getEip712TypedData, getEip712TypedDataV2 } from '../../../tx/index.js'
Expand Down
17 changes: 8 additions & 9 deletions packages/sdk-ts/src/utils/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import CryptoEs from 'crypto-es'
// import CryptoEs from 'crypto-es'
import CryptoEs from 'crypto-js'
import { secp256k1 } from '@noble/curves/secp256k1'
import keccak256 from 'keccak256'
import { SignTypedDataVersion, TypedDataUtils } from '@metamask/eth-sig-util'
Expand All @@ -10,19 +11,17 @@ export const hashToHex = (data: string): string => {
}

export const sha256 = (data: Uint8Array): Uint8Array => {
const dataInUtf8 = Buffer.from(data).toString('utf-8')
const wordArray = CryptoEs.lib.WordArray.create(data)
const hash = CryptoEs.SHA256(wordArray)

return Uint8Array.from(
Buffer.from(CryptoEs.SHA256(dataInUtf8).toString(), 'hex'),
)
return Uint8Array.from(Buffer.from(hash.toString(), 'hex'))
}

export const ripemd160 = (data: Uint8Array): Uint8Array => {
const dataInUtf8 = Buffer.from(data).toString('utf-8')
const wordArray = CryptoEs.lib.WordArray.create(data)
const hash = CryptoEs.RIPEMD160(wordArray)

return Uint8Array.from(
Buffer.from(CryptoEs.RIPEMD160(dataInUtf8).toString(), 'hex'),
)
return Uint8Array.from(Buffer.from(hash.toString(), 'hex'))
}

export const privateKeyToPublicKey = (privateKey: Uint8Array): Uint8Array => {
Expand Down
1 change: 0 additions & 1 deletion packages/utils/src/classes/LocalStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export default class LocalStorage {
private storage: StoreAPI

constructor(namespace: string) {
// @ts-ignore
this.storage = store.namespace(namespace)
}

Expand Down
57 changes: 50 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2262,6 +2262,16 @@
protobufjs "^7.0.0"
rxjs "^7.4.0"

"@injectivelabs/exceptions@^1.14.33":
version "1.14.33"
resolved "https://registry.npmjs.org/@injectivelabs/exceptions/-/exceptions-1.14.33.tgz#3bcc3e613aac13fce72b3557b4260820dde8ce3a"
integrity sha512-2c8YzLgwTOOsyc1WheqdM8jEfgGBhVrXN4cZ0jsikFVsLF619IDRn3hjIYqTeNERaEpeRPiuJGfZDu0DomwFrQ==
dependencies:
"@injectivelabs/grpc-web" "^0.0.1"
"@injectivelabs/ts-types" "^1.14.33"
http-status-codes "^2.2.0"
shx "^0.3.2"

"@injectivelabs/grpc-web-node-http-transport@^0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@injectivelabs/grpc-web-node-http-transport/-/grpc-web-node-http-transport-0.0.2.tgz#87c9bbd4db1f70cf18d6a55b54b2cf17d3cf30c0"
Expand Down Expand Up @@ -2299,6 +2309,16 @@
protobufjs "^7.0.0"
rxjs "^7.4.0"

"@injectivelabs/networks@^1.14.33":
version "1.14.33"
resolved "https://registry.npmjs.org/@injectivelabs/networks/-/networks-1.14.33.tgz#340bef9948ace5abd7b9a2a69ef1d9bc6ee54c33"
integrity sha512-XDhAYwWYKdKBRfwO/MIfMyKjKRWz/AliMJG9yaM1C/cDlGHmA3EY7Au2Nf+PdkRhuxl2FzLV2Hp4uWeC0g8BYw==
dependencies:
"@injectivelabs/exceptions" "^1.14.33"
"@injectivelabs/ts-types" "^1.14.33"
"@injectivelabs/utils" "^1.14.33"
shx "^0.3.2"

"@injectivelabs/[email protected]":
version "1.13.1"
resolved "https://registry.npmjs.org/@injectivelabs/olp-proto-ts/-/olp-proto-ts-1.13.1.tgz#56a0dcc5f36de6838acc0e951eebabddef8d03c5"
Expand All @@ -2309,6 +2329,20 @@
protobufjs "^7.0.0"
rxjs "^7.4.0"

"@injectivelabs/utils@^1.14.33":
version "1.14.33"
resolved "https://registry.npmjs.org/@injectivelabs/utils/-/utils-1.14.33.tgz#9e6eef0e61f306ef5cd68ceed198ea98c47ada4e"
integrity sha512-zsezML4dTujF0xGLhcGmWBCghfJiy9MW+r6VqR8zJUlxnmnEdNpmsvBhBI6cmmov6Se4FL+yALAIFRvTm3txbg==
dependencies:
"@injectivelabs/exceptions" "^1.14.33"
"@injectivelabs/ts-types" "^1.14.33"
axios "^1.6.4"
bignumber.js "^9.0.1"
http-status-codes "^2.2.0"
shx "^0.3.2"
snakecase-keys "^5.1.2"
store2 "^2.12.0"

"@ioredis/commands@^1.1.1":
version "1.2.0"
resolved "https://registry.npmjs.org/@ioredis/commands/-/commands-1.2.0.tgz#6d61b3097470af1fdbbe622795b8921d42018e11"
Expand Down Expand Up @@ -3147,7 +3181,7 @@
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz#39908da56a4adc270147bb07968bf3b16cfe1699"
integrity sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==

"@noble/hashes@^1.3.1":
"@noble/hashes@^1.3.1", "@noble/hashes@^1.6.1":
version "1.6.1"
resolved "https://registry.npmjs.org/@noble/hashes/-/hashes-1.6.1.tgz#df6e5943edcea504bac61395926d6fd67869a0d5"
integrity sha512-pq5D8h10hHBjyqX+cfBm0i8JUXJ0UhczFc4r74zbuT9XgewFo2E3J1cOaGtdZynILNmQ685YWGzGE1Zv6io50w==
Expand Down Expand Up @@ -6842,11 +6876,6 @@ crossws@^0.2.0, crossws@^0.2.2:
resolved "https://registry.npmjs.org/crossws/-/crossws-0.2.4.tgz#82a8b518bff1018ab1d21ced9e35ffbe1681ad03"
integrity sha512-DAxroI2uSOgUKLz00NX6A8U/8EE3SZHmIND+10jkVSaypvyt57J5JEOxAQOL6lQxyzi/wZbTIwssU1uy69h5Vg==

crypto-es@^2.1.0:
version "2.1.0"
resolved "https://registry.npmjs.org/crypto-es/-/crypto-es-2.1.0.tgz#1095f324ffd7dc1ccab8e21d0960e17025da8ce9"
integrity sha512-C5Dbuv4QTPGuloy5c5Vv/FZHtmK+lobLAypFfuRaBbwCsk3qbCWWESCH3MUcBsrgXloRNMrzwUAiPg4U6+IaKA==

[email protected], crypto-js@^4.2.0:
version "4.2.0"
resolved "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz#4d931639ecdfd12ff80e8186dba6af2c2e856631"
Expand Down Expand Up @@ -13925,6 +13954,15 @@ snake-case@^3.0.4:
dot-case "^3.0.4"
tslib "^2.0.3"

snakecase-keys@^5.1.2:
version "5.5.0"
resolved "https://registry.npmjs.org/snakecase-keys/-/snakecase-keys-5.5.0.tgz#fbf9ca4a47fcc37c7496d00c6d9e455da9750403"
integrity sha512-r3kRtnoPu3FxGJ3fny6PKNnU3pteb29o6qAa0ugzhSseKNWRkw1dw8nIjXMyyKaU9vQxxVIE62Mb3bKbdrgpiw==
dependencies:
map-obj "^4.1.0"
snake-case "^3.0.4"
type-fest "^3.12.0"

snakecase-keys@^5.4.1:
version "5.4.4"
resolved "https://registry.npmjs.org/snakecase-keys/-/snakecase-keys-5.4.4.tgz#28745b0175863ffc292ad97d96fe4e8e288a87a2"
Expand Down Expand Up @@ -14160,7 +14198,7 @@ std-env@^3.7.0:
resolved "https://registry.npmjs.org/std-env/-/std-env-3.7.0.tgz#c9f7386ced6ecf13360b6c6c55b8aaa4ef7481d2"
integrity sha512-JPbdCEQLj1w5GilpiHAx3qJvFndqybBysA3qUOnznweH4QbNYUsW/ea8QzSrnh0vNsezMMw5bcVool8lM0gwzg==

store2@^2.14.3:
store2@^2.12.0, store2@^2.14.3:
version "2.14.3"
resolved "https://registry.npmjs.org/store2/-/store2-2.14.3.tgz#24077d7ba110711864e4f691d2af941ec533deb5"
integrity sha512-4QcZ+yx7nzEFiV4BMLnr/pRa5HYzNITX2ri0Zh6sT9EyQHbBHacC6YigllUPU9X3D0f/22QCgfokpKs52YRrUg==
Expand Down Expand Up @@ -14876,6 +14914,11 @@ type-fest@^2.5.2:
resolved "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz#88068015bb33036a598b952e55e9311a60fd3a9b"
integrity sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==

type-fest@^3.12.0:
version "3.13.1"
resolved "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz#bb744c1f0678bea7543a2d1ec24e83e68e8c8706"
integrity sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==

type-flag@^3.0.0:
version "3.0.0"
resolved "https://registry.npmjs.org/type-flag/-/type-flag-3.0.0.tgz#2caef2f20f2c71e960fe1d3b6f57bae8c8246459"
Expand Down

0 comments on commit 195f210

Please sign in to comment.