Skip to content

Commit

Permalink
fix: address derivation
Browse files Browse the repository at this point in the history
  • Loading branch information
bangjelkoski committed Apr 26, 2022
1 parent a5f1539 commit ef5f438
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/sdk-ts/examples/core/MsgBid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { BigNumberInBase } from '@injectivelabs/utils'
;(async () => {
const network = Network.testnet()
const privateKey = PrivateKey.fromPrivateKey(
'0xf9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3',
'f9db9bf330e23cb7839039e944adef6e9df447b90b503d5b4464c90bea9022f3',
)
const injectiveAddress = privateKey.toBech32()

Expand Down
2 changes: 1 addition & 1 deletion packages/sdk-ts/examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"scripts": {},
"dependencies": {
"@injectivelabs/sdk-ts": "^0.0.8"
"@injectivelabs/sdk-ts": "^0.0.9"
},
"devDependencies": {
"@types/jest": "^27.0.2",
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk-ts/examples/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -734,10 +734,10 @@
link-module-alias "^1.2.0"
shx "^0.3.2"

"@injectivelabs/sdk-ts@^0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ts/-/sdk-ts-0.0.8.tgz#4234fe7167fd2d8cf0c6298b68e0a2070af31fb3"
integrity sha512-Nc5rYRWLc5hI38DX4xRgEERR2QMwszD4bBG6ZM25BnWDFnwHG4G4CXDwywfAM5bI1s5Re0qF/Ycsj2u0To4VAA==
"@injectivelabs/sdk-ts@^0.0.9":
version "0.0.9"
resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ts/-/sdk-ts-0.0.9.tgz#73de924333df6b061cd09733ce9639e00b986264"
integrity sha512-wdLXtEs6dTjSWyQNkmPczlwTSDqOnWkcFFASJMzFnkxJiYYTFDKRVh07zLGoVjozZVAMDrHGJoBKugaXFD3bRw==
dependencies:
"@improbable-eng/grpc-web" "^0.15.0"
"@improbable-eng/grpc-web-node-http-transport" "^0.15.0"
Expand Down
8 changes: 5 additions & 3 deletions packages/sdk-ts/src/local/PrivateKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export class PrivateKey {
* @returns {string}
*/
toHex(): string {
return `0x${this.wallet.address}`
return this.wallet.address.startsWith('0x')
? this.wallet.address
: `0x${this.wallet.address}`
}

/**
Expand All @@ -75,15 +77,15 @@ export class PrivateKey {
* @returns {Address}
**/
toAddress(): Address {
return Address.fromHex(this.wallet.publicKey)
return Address.fromHex(this.toHex())
}

/**
* Return the Injective address associated with this private key.
* @returns {string}
**/
toBech32(): string {
return Address.fromHex(this.wallet.publicKey).toBech32()
return Address.fromHex(this.toHex()).toBech32()
}

/**
Expand Down

0 comments on commit ef5f438

Please sign in to comment.