Skip to content

Commit

Permalink
Merge branch 'ethersphere:master' into feat/act
Browse files Browse the repository at this point in the history
  • Loading branch information
ferencsarai authored Jul 22, 2024
2 parents 4083d31 + 0a69957 commit 1f51e1d
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 8 deletions.
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
# Changelog


## [7.1.0](https://github.com/ethersphere/bee-js/compare/v7.0.4...v7.1.0) (2024-07-17)


### Features

* add capitalizeAddressERC55 function ([#933](https://github.com/ethersphere/bee-js/issues/933)) ([8e06014](https://github.com/ethersphere/bee-js/commit/8e06014fe2be32e6435bdec3fc75c86dbbc77f10))

## [7.0.4](https://github.com/ethersphere/bee-js/compare/v7.0.3...v7.0.4) (2024-07-17)


### Bug Fixes

* add chaintip field ([#931](https://github.com/ethersphere/bee-js/issues/931)) ([4a45a56](https://github.com/ethersphere/bee-js/commit/4a45a562c649d90cb6fa3668cd74bf033ca18ad5))

## [7.0.3](https://github.com/ethersphere/bee-js/compare/v7.0.2...v7.0.3) (2024-06-18)


Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ethersphere/bee-js",
"version": "7.0.3",
"version": "7.1.0",
"description": "Javascript client for Bee",
"keywords": [
"bee",
Expand Down
1 change: 1 addition & 0 deletions src/types/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ export interface ReserveState {

export interface ChainState {
block: number
chainTip: number
totalAmount: NumberString
currentPrice: NumberString
}
Expand Down
17 changes: 17 additions & 0 deletions src/utils/eth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ export type HexEthAddress = HexString<40>
const ETH_ADDR_BYTES_LENGTH = 20
const ETH_ADDR_HEX_LENGTH = 40

export function capitalizeAddressERC55(address: string): string {
if (address.startsWith('0x')) {
address = address.slice(2)
}
const addressHash = keccak256(address.toLowerCase())
let result = '0x'
for (let i = 0; i < address.length; i++) {
if (parseInt(addressHash[i], 16) > 7) {
result += address[i].toUpperCase()
} else {
result += address[i].toLowerCase()
}
}

return result
}

export function makeEthAddress(address: EthAddress | Uint8Array | string | unknown): EthAddress {
if (typeof address === 'string') {
const hexAddr = makeHexString(address, ETH_ADDR_HEX_LENGTH)
Expand Down
1 change: 1 addition & 0 deletions src/utils/expose.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export {

export {
EthAddress,
capitalizeAddressERC55,
ethToSwarmAddress,
fromLittleEndian,
isHexEthAddress,
Expand Down
41 changes: 37 additions & 4 deletions test/unit/utils/eth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,51 @@
/* eslint @typescript-eslint/no-empty-function: 0 */
import { expect } from 'chai'
import sinon from 'sinon'
import { wrapBytesWithHelpers } from '../../../src/utils/bytes'
import {
makeEthereumWalletSigner,
capitalizeAddressERC55,
ethToSwarmAddress,
fromLittleEndian,
isHexEthAddress,
JsonRPC,
makeEthereumWalletSigner,
toLittleEndian,
} from '../../../src/utils/eth'
import { HexString, hexToBytes } from '../../../src/utils/hex'
import { wrapBytesWithHelpers } from '../../../src/utils/bytes'
import { expect } from 'chai'
import sinon from 'sinon'

describe('eth', () => {
describe('capitalizeAddressERC55', () => {
it('should calculate checksum for address', () => {
// All caps
expect(capitalizeAddressERC55('0x52908400098527886E0F7030069857D2E4169EE7')).to.be(
'0x52908400098527886E0F7030069857D2E4169EE7',
)
expect(capitalizeAddressERC55('0x8617E340B3D01FA5F11F306F4090FD50E238070D')).to.be(
'0x8617E340B3D01FA5F11F306F4090FD50E238070D',
)
// All Lower
expect(capitalizeAddressERC55('0xde709f2102306220921060314715629080e2fb77')).to.be(
'0xde709f2102306220921060314715629080e2fb77',
)
expect(capitalizeAddressERC55('0x27b1fdb04752bbc536007a920d24acb045561c26')).to.be(
'0x27b1fdb04752bbc536007a920d24acb045561c26',
)
// Normal
expect(capitalizeAddressERC55('0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed')).to.be(
'0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed',
)
expect(capitalizeAddressERC55('0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359')).to.be(
'0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359',
)
expect(capitalizeAddressERC55('0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB')).to.be(
'0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB',
)
expect(capitalizeAddressERC55('0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb')).to.be(
'0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb',
)
})
})

describe('isEthAddress', () => {
const testValues = [
{ value: () => {}, result: false },
Expand Down

0 comments on commit 1f51e1d

Please sign in to comment.