From 81b1dc87dd5e6bf6fe04b077dc72c46c68c9010b Mon Sep 17 00:00:00 2001 From: lukaw3d Date: Wed, 26 Jun 2024 04:36:21 +0200 Subject: [PATCH] Use @oasisprotocol/client for isValidAddress --- package.json | 1 - src/app/lib/helpers.ts | 6 +----- yarn.lock | 22 +++++++++++++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 63095d4113..ef1d7e8d27 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,6 @@ "@oasisprotocol/ledger": "1.0.0", "@reduxjs/toolkit": "1.9.7", "base64-arraybuffer": "1.0.2", - "bech32": "2.0.0", "bignumber.js": "9.1.2", "bip39": "3.1.0", "body-scroll-lock": "4.0.0-beta.0", diff --git a/src/app/lib/helpers.ts b/src/app/lib/helpers.ts index a570be443b..ad50cce27c 100644 --- a/src/app/lib/helpers.ts +++ b/src/app/lib/helpers.ts @@ -1,4 +1,3 @@ -import { bech32 } from 'bech32' import { quantity, staking, types } from '@oasisprotocol/client' import { decode as base64decode, encode as base64encode } from 'base64-arraybuffer' import BigNumber from 'bignumber.js' @@ -27,11 +26,8 @@ export const uint2bigintString = (uint: Uint8Array): StringifiedBigInt => quanti export const stringBigint2uint = (number: StringifiedBigInt) => quantity.fromBigInt(BigInt(number)) export const isValidAddress = (addr: string) => { - if (!addr.match(/^oasis1/)) { - return false - } try { - bech32.decode(addr) + staking.addressFromBech32(addr) return true } catch (e) { return false diff --git a/yarn.lock b/yarn.lock index 0aa1f1de42..b47a6906de 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3962,7 +3962,7 @@ bcrypt-pbkdf@^1.0.0: dependencies: tweetnacl "^0.14.3" -bech32@2.0.0, bech32@^2.0.0: +bech32@^2.0.0: version "2.0.0" resolved "https://registry.npmjs.org/bech32/-/bech32-2.0.0.tgz" integrity sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg== @@ -9554,7 +9554,16 @@ string-natural-compare@^3.0.1: resolved "https://registry.yarnpkg.com/string-natural-compare/-/string-natural-compare-3.0.1.tgz#7a42d58474454963759e8e8b7ae63d71c1e7fdf4" integrity sha512-n3sPwynL1nwKi3WJ6AIsClwBMa0zTi54fn2oLU6ndfTSIO05xaznjSf15PcBZU6FNWbmN5Q6cxT4V5hGvB4taw== -"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: +"string-width-cjs@npm:string-width@^4.2.0": + version "4.2.3" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" + integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== + dependencies: + emoji-regex "^8.0.0" + is-fullwidth-code-point "^3.0.0" + strip-ansi "^6.0.1" + +string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3: version "4.2.3" resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010" integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g== @@ -9627,7 +9636,14 @@ string_decoder@~1.1.1: dependencies: safe-buffer "~5.1.0" -"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1: +"strip-ansi-cjs@npm:strip-ansi@^6.0.1": + version "6.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" + integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A== + dependencies: + ansi-regex "^5.0.1" + +strip-ansi@^6.0.0, strip-ansi@^6.0.1: version "6.0.1" resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9" integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==