diff --git a/src/validation.ts b/src/validation.ts index d3a9066..52e2bc4 100644 --- a/src/validation.ts +++ b/src/validation.ts @@ -17,7 +17,7 @@ const Prefixes = Object.freeze({ SCRIPT: 'script', }); -type SUPPORTED_PAYMENT_CRED_PREFIX = 'addr_vkh' | 'addr_vk' | 'script'; +type PaymentCredPrefix = 'addr_vkh' | 'addr_vk' | 'script'; const MAX_UNSIGNED_INT = 2_147_483_648; const MAX_SIGNED_INT = 2_147_483_647; @@ -96,7 +96,7 @@ export const paymentCredFromBech32Address = ( ): | { paymentCred: string; - prefix: SUPPORTED_PAYMENT_CRED_PREFIX; + prefix: PaymentCredPrefix; } | undefined => { // compute paymentCred @@ -133,7 +133,7 @@ export const paymentCredFromBech32Address = ( export const paymentCredToBech32Address = ( input: string, - prefix: SUPPORTED_PAYMENT_CRED_PREFIX, + prefix: PaymentCredPrefix, ): string | undefined => { // Encodes payment credential into its original bech32 prefixed form try { @@ -146,11 +146,6 @@ export const paymentCredToBech32Address = ( case Prefixes.SCRIPT: // add prefix to payment cred and encode it as bech32 return bech32.encode(prefix, words); - case Prefixes.PAYMENT_KEY: - // Payment key was already converted to key hash, so we cannot restore the original key. - // We could supply orig via a parameter and then compare its hash to the input, but that's too much trouble. - // Due to the above return payment key hash (input) with addr_vkh prefix instead of the original addr_vk - return bech32.encode(Prefixes.PAYMENT_KEY_HASH, words); default: throw Error( `Prefix ${prefix} is not supported by paymentCredToBech32Address`, diff --git a/test/fixtures/cardano.ts b/test/fixtures/cardano.ts index 89d1a90..b3f1f4c 100644 --- a/test/fixtures/cardano.ts +++ b/test/fixtures/cardano.ts @@ -21,6 +21,7 @@ export const getPaymentPartBech32 = [ }, { // https://cips.cardano.org/cips/cip19/#testvectors + // converted to PKH: addr_vkh1jjfnzhxe966a33psfenm0ct2udkkr569qf55v4uprgkgu8zsvmg description: 'addr_vk addr type 0', paymentCred: 'addr_vk1w0l2sr2zgfm26ztc6nl9xy8ghsk5sh6ldwemlpmp9xylzy4dtf7st80zhd', diff --git a/test/fixtures/validation.ts b/test/fixtures/validation.ts index 7b12ecd..d8039c9 100644 --- a/test/fixtures/validation.ts +++ b/test/fixtures/validation.ts @@ -162,16 +162,6 @@ export const paymentCredToBech32Address = [ prefix: 'script', result: 'script1cda3khwqv60360rp5m7akt50m6ttapacs8rqhn5w342z7r35m37', }, - { - // TODO: With addr_vk prefix we assume payment key was already converted - // to the key hash, so we cannot restore the original key. - // Due to the above the function returns payment key hash (input) with addr_vkh prefix instead of the original addr_vk. - // Alternatively, we could just drop support for addr_vk. - description: 'Valid payment key from addr_vk gets converted to addr_vkh', - input: 'c37b1b5dc0669f1d3c61a6fddb2e8fde96be87b881c60bce8e8d542f', - prefix: 'addr_vk', - result: 'addr_vkh1cda3khwqv60360rp5m7akt50m6ttapacs8rqhn5w342z7lydx4l', - }, { description: 'Valid script address', input: '59a38a122f5278190f6f34230b7376eb8bebabf92f87240d2271e012',