Skip to content

Commit

Permalink
Replace official bech32 lib by cardano-crypto
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterBenc committed Nov 9, 2020
1 parent 5774846 commit bd9ee6b
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 40 deletions.
6 changes: 3 additions & 3 deletions app/frontend/wallet/shelley/helpers/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import bech32 from './bech32'
import {
packBaseAddress,
packRewardAddress,
getAddressType,
AddressTypes,
base58,
bech32,
getPubKeyBlake2b224Hash,
} from 'cardano-crypto.js'
import {HARDENED_THRESHOLD} from '../../constants'
Expand Down Expand Up @@ -37,7 +37,7 @@ export const base58AddressToHex = (address: string): HexString => {

export const accountAddressFromXpub = (stakeXpub: Xpub, networkId): string => {
const addrBuffer = packRewardAddress(xpub2blake2b224Hash(stakeXpub), networkId)
return bech32.encode({prefix: 'addr', data: addrBuffer})
return bech32.encode('addr', addrBuffer)
}

export const accountHexAddressFromXpub = (stakeXpub: Xpub, networkId): HexString => {
Expand All @@ -51,7 +51,7 @@ export const baseAddressFromXpub = (spendXpub: Xpub, stakeXpub: Xpub, networkId)
xpub2blake2b224Hash(stakeXpub),
networkId
)
return bech32.encode({prefix: 'addr', data: addrBuffer})
return bech32.encode('addr', addrBuffer)
}

export const isShelleyFormat = (address: string): boolean => {
Expand Down
23 changes: 0 additions & 23 deletions app/frontend/wallet/shelley/helpers/bech32.ts

This file was deleted.

2 changes: 0 additions & 2 deletions app/frontend/wallet/shelley/shelley-js-crypto-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
ShelleyTxWitnessByron,
} from './shelley-transaction'

// import {PROTOCOL_MAGIC_KEY} from '../constants'
import {isShelleyPath} from './helpers/addresses'
import CachedDeriveXpubFactory from '../helpers/CachedDeriveXpubFactory'

Expand Down Expand Up @@ -93,7 +92,6 @@ const ShelleyJsCryptoProvider = ({
const _byronWitnesses = []
inputs.forEach((input) => {
const inputPath = addressToAbsPathMapper(input.address)
// console.log(inputPath)await getHdPassphrase()
isShelleyPath(inputPath)
? _shelleyWitnesses.push(build_shelley_witness(tx_body_hash, inputPath, sign))
: _byronWitnesses.push(build_byron_witness(tx_body_hash, sign, inputPath, input.address))
Expand Down
2 changes: 0 additions & 2 deletions app/frontend/wallet/shelley/shelley-ledger-crypto-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import {
import * as platform from 'platform'
import {hasMinimalVersion} from './helpers/version-check'

// import {PROTOCOL_MAGIC_KEY} from '../constants'

import {
bechAddressToHex,
isShelleyPath,
Expand Down
3 changes: 1 addition & 2 deletions app/frontend/wallet/shelley/shelley-transaction-planner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {encode} from 'borc'
import bech32 from './helpers/bech32'

import {ShelleyTxInputFromUtxo, ShelleyWitdrawal, ShelleyTxCert} from './shelley-transaction'

Expand All @@ -8,7 +7,7 @@ import CborIndefiniteLengthArray from '../byron/helpers/CborIndefiniteLengthArra
import NamedError from '../../helpers/NamedError'
import {Lovelace} from '../../state'
import getDonationAddress from '../../helpers/getDonationAddress'
import {base58} from 'cardano-crypto.js'
import {base58, bech32} from 'cardano-crypto.js'
import {isShelleyFormat, isV1Address} from './helpers/addresses'

export function txFeeFunction(txSizeInBytes: number): Lovelace {
Expand Down
3 changes: 1 addition & 2 deletions app/frontend/wallet/shelley/shelley-transaction.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/* eslint-disable no-use-before-define */
/* eslint-disable camelcase */
import {encode} from 'borc'
import {blake2b, base58} from 'cardano-crypto.js'
import bech32 from './helpers/bech32'
import {blake2b, base58, bech32} from 'cardano-crypto.js'
import {isShelleyFormat} from './helpers/addresses'

function ShelleyTxAux(inputs, outputs, fee, ttl, certs?, withdrawals?) {
Expand Down
1 change: 0 additions & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"@ledgerhq/hw-transport-u2f": "^5.15.0",
"@ledgerhq/hw-transport-webusb": "^5.16.0",
"babel-regenerator-runtime": "^6.5.0",
"bech32": "^1.1.3",
"bip39-light": "^1.0.7",
"borc": "^2.1.0",
"cardano-crypto.js": "^6.0.0",
Expand Down
5 changes: 0 additions & 5 deletions app/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,6 @@ base@^0.11.1:
mixin-deep "^1.2.0"
pascalcase "^0.1.1"

bech32@^1.1.3:
version "1.1.3"
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.3.tgz#bd47a8986bbb3eec34a56a097a84b8d3e9a2dfcd"
integrity sha512-yuVFUvrNcoJi0sv5phmqc6P+Fl1HjRDRNOOkHY2X/3LBy2bIGNSFx4fZ95HMaXHupuS7cZR15AsvtmCIF4UEyg==

bech32@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/bech32/-/bech32-1.1.4.tgz#e38c9f37bf179b8eb16ae3a772b40c356d4832e9"
Expand Down

0 comments on commit bd9ee6b

Please sign in to comment.