From 28054ef3afa6f2ada7881e0b503a31ac4b8636f6 Mon Sep 17 00:00:00 2001 From: Tal Derei Date: Sat, 21 Dec 2024 04:07:38 -0800 Subject: [PATCH] remove compat address format from bech32 and types package --- packages/bech32m/src/format/bytes.ts | 1 - packages/bech32m/src/format/index.ts | 6 ----- packages/bech32m/src/format/inner.ts | 1 - packages/bech32m/src/format/prefix.ts | 1 - packages/bech32m/src/format/strings.ts | 1 - packages/bech32m/src/penumbracompat1.ts | 24 ------------------ .../bech32m/src/test/penumbracompat1.test.ts | 25 ------------------- packages/types/src/address.test.ts | 8 ------ packages/types/src/address.ts | 4 --- 9 files changed, 71 deletions(-) delete mode 100644 packages/bech32m/src/penumbracompat1.ts delete mode 100644 packages/bech32m/src/test/penumbracompat1.test.ts diff --git a/packages/bech32m/src/format/bytes.ts b/packages/bech32m/src/format/bytes.ts index 0cc867116c..daee8ace22 100644 --- a/packages/bech32m/src/format/bytes.ts +++ b/packages/bech32m/src/format/bytes.ts @@ -4,7 +4,6 @@ export const ByteLength = { passet: 32, pauctid: 32, penumbra: 80, - penumbracompat1: 80, penumbrafullviewingkey: 64, penumbragovern: 32, penumbraspendkey: 32, diff --git a/packages/bech32m/src/format/index.ts b/packages/bech32m/src/format/index.ts index fff0b57a4a..87904c2995 100644 --- a/packages/bech32m/src/format/index.ts +++ b/packages/bech32m/src/format/index.ts @@ -31,12 +31,6 @@ export default { byteLength: ByteLength.penumbra, innerName: Inner.penumbra, }, - penumbracompat1: { - prefix: Prefixes.penumbracompat1, - stringLength: StringLength.penumbracompat1, - byteLength: ByteLength.penumbracompat1, - innerName: Inner.penumbracompat1, - }, penumbrafullviewingkey: { prefix: Prefixes.penumbrafullviewingkey, stringLength: StringLength.penumbrafullviewingkey, diff --git a/packages/bech32m/src/format/inner.ts b/packages/bech32m/src/format/inner.ts index 9e21eb9af5..d3c1141649 100644 --- a/packages/bech32m/src/format/inner.ts +++ b/packages/bech32m/src/format/inner.ts @@ -4,7 +4,6 @@ export const Inner = { passet: 'inner', pauctid: 'inner', penumbra: 'inner', - penumbracompat1: 'inner', penumbrafullviewingkey: 'inner', penumbragovern: 'gk', penumbraspendkey: 'inner', diff --git a/packages/bech32m/src/format/prefix.ts b/packages/bech32m/src/format/prefix.ts index bc89718fa7..0afbf525c2 100644 --- a/packages/bech32m/src/format/prefix.ts +++ b/packages/bech32m/src/format/prefix.ts @@ -2,7 +2,6 @@ export const Prefixes = { passet: 'passet', pauctid: 'pauctid', penumbra: 'penumbra', - penumbracompat1: 'penumbracompat1', penumbrafullviewingkey: 'penumbrafullviewingkey', penumbragovern: 'penumbragovern', penumbraspendkey: 'penumbraspendkey', diff --git a/packages/bech32m/src/format/strings.ts b/packages/bech32m/src/format/strings.ts index db047a78fd..5b35ba5d70 100644 --- a/packages/bech32m/src/format/strings.ts +++ b/packages/bech32m/src/format/strings.ts @@ -4,7 +4,6 @@ export const StringLength = { passet: 65, pauctid: 66, penumbra: 143, - penumbracompat1: 150, penumbrafullviewingkey: 132, penumbragovern: 73, penumbraspendkey: 75, diff --git a/packages/bech32m/src/penumbracompat1.ts b/packages/bech32m/src/penumbracompat1.ts deleted file mode 100644 index 8da7caec0b..0000000000 --- a/packages/bech32m/src/penumbracompat1.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { fromBech32, toBech32 } from './format/convert.js'; -import { Inner } from './format/inner.js'; -import { Prefixes } from './format/prefix.js'; - -const innerName = Inner.penumbracompat1; -const prefix = Prefixes.penumbracompat1; - -export const bech32CompatAddress = ({ [innerName]: bytes }: { [innerName]: Uint8Array }) => - toBech32(bytes, prefix); - -export const compatAddressFromBech32 = (penumbracompat1: string): { [innerName]: Uint8Array } => ({ - [innerName]: fromBech32(penumbracompat1 as `${typeof prefix}1${string}`, prefix), -}); - -export const isCompatAddress = (check: string): check is `${typeof prefix}1${string}` => { - try { - compatAddressFromBech32(check); - return true; - } catch { - return false; - } -}; - -export { PENUMBRA_BECH32M_ADDRESS_LENGTH, PENUMBRA_BECH32M_ADDRESS_PREFIX } from './index.js'; diff --git a/packages/bech32m/src/test/penumbracompat1.test.ts b/packages/bech32m/src/test/penumbracompat1.test.ts deleted file mode 100644 index d0422671b1..0000000000 --- a/packages/bech32m/src/test/penumbracompat1.test.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { describe } from 'vitest'; -import { generateTests } from './util/generate-tests.js'; -import { bech32CompatAddress, compatAddressFromBech32 } from '../penumbracompat1.js'; -import { Prefixes } from '../format/prefix.js'; -import { Inner } from '../format/inner.js'; - -describe('compat address conversion', () => { - const okInner = new Uint8Array([ - 175, 182, 158, 255, 239, 16, 245, 221, 208, 117, 160, 44, 235, 175, 198, 0, 6, 216, 6, 143, 192, - 155, 159, 103, 97, 103, 136, 5, 78, 209, 17, 200, 68, 220, 182, 45, 20, 246, 181, 16, 117, 182, - 46, 141, 74, 101, 196, 86, 185, 124, 206, 253, 195, 57, 224, 34, 210, 22, 123, 246, 136, 10, - 208, 159, 24, 235, 148, 153, 211, 7, 137, 198, 158, 226, 221, 22, 208, 152, 246, 247, - ]); - const okBech32 = - 'penumbracompat1147mfall0zr6am5r45qkwht7xqqrdsp50czde7empv7yq2nk3z8yyfh9k9520ddgswkmzar22vhz9dwtuem7uxw0qytfpv7lk3q9dp8ccaw2fn5c838rfackazmgf3ahhwqq0da'; - - generateTests( - Prefixes.penumbracompat1, - Inner.penumbracompat1, - okInner, - okBech32, - bech32CompatAddress, - compatAddressFromBech32, - ); -}); diff --git a/packages/types/src/address.test.ts b/packages/types/src/address.test.ts index 9751b2d541..371769a152 100644 --- a/packages/types/src/address.test.ts +++ b/packages/types/src/address.test.ts @@ -2,14 +2,6 @@ import { describe, expect, test } from 'vitest'; import { parseIntoAddr } from './address.js'; describe('parseIntoAddr', () => { - test('works with compat', () => { - expect(() => - parseIntoAddr( - 'penumbracompat1147mfall0zr6am5r45qkwht7xqqrdsp50czde7empv7yq2nk3z8yyfh9k9520ddgswkmzar22vhz9dwtuem7uxw0qytfpv7lk3q9dp8ccaw2fn5c838rfackazmgf3ahhwqq0da', - ), - ).not.toThrow(); - }); - test('works with normal addresses', () => { expect(() => parseIntoAddr( diff --git a/packages/types/src/address.ts b/packages/types/src/address.ts index 97f1182f6c..cbf3f78f2b 100644 --- a/packages/types/src/address.ts +++ b/packages/types/src/address.ts @@ -1,10 +1,6 @@ import { Address } from '@penumbra-zone/protobuf/penumbra/core/keys/v1/keys_pb'; import { addressFromBech32m } from '@penumbra-zone/bech32m/penumbra'; -import { compatAddressFromBech32, isCompatAddress } from '@penumbra-zone/bech32m/penumbracompat1'; export const parseIntoAddr = (addrStr: string): Address => { - if (isCompatAddress(addrStr)) { - return new Address(compatAddressFromBech32(addrStr)); - } return new Address(addressFromBech32m(addrStr)); };