diff --git a/packages/core/src/CSL/certificate.ts b/packages/core/src/CSL/certificate.ts index 15eeb3e469b..854b5f1fa61 100644 --- a/packages/core/src/CSL/certificate.ts +++ b/packages/core/src/CSL/certificate.ts @@ -124,6 +124,7 @@ export const poolRetirement = (poolId: Cardano.PoolId, epoch: number) => export const stakeDelegation = (rewardAccount: Cardano.RewardAccount, delegatee: Cardano.PoolId) => Certificate.new_stake_delegation( + // TODO: add coreToCsl support for genesis pool IDs StakeDelegation.new(stakeAddressToCredential(rewardAccount), Ed25519KeyHash.from_bech32(delegatee.toString())) ); diff --git a/packages/core/src/Cardano/types/StakePool/primitives.ts b/packages/core/src/Cardano/types/StakePool/primitives.ts index dd837373965..3b234c7a617 100644 --- a/packages/core/src/Cardano/types/StakePool/primitives.ts +++ b/packages/core/src/Cardano/types/StakePool/primitives.ts @@ -1,16 +1,27 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { Hash28ByteBase16, OpaqueString, typedBech32, typedHex } from '../../util'; +import { InvalidStringError } from '../../..'; /** - * pool operator verification key hash as bech32 string + * pool operator verification key hash as bech32 string or a genesis pool ID */ export type PoolId = OpaqueString<'PoolId'>; /** - * @param {string} value blake2b_224 digest of an operator verification key hash + * @param {string} value blake2b_224 digest of an operator verification key hash or a genesis pool ID * @throws InvalidStringError */ -export const PoolId = (value: string): PoolId => typedBech32(value, 'pool', 45); +export const PoolId = (value: string): PoolId => { + try { + return typedBech32(value, 'pool', 45); + } catch (error: unknown) { + // eslint-disable-next-line prettier/prettier + if ((/^ShelleyGenesis-[\dA-Fa-f]{16}$/).test(value)) { + return value as unknown as PoolId; + } + throw new InvalidStringError('Expected PoolId to be either bech32 or genesis stake pool', error); + } +}; /** * pool operator verification key hash as hex string diff --git a/packages/core/test/Cardano/types/StakePool.test.ts b/packages/core/test/Cardano/types/StakePool.test.ts index 47cb5f1ca38..f32ef15e56b 100644 --- a/packages/core/test/Cardano/types/StakePool.test.ts +++ b/packages/core/test/Cardano/types/StakePool.test.ts @@ -5,6 +5,10 @@ describe('Cardano/types/StakePool', () => { expect(() => Cardano.PoolId('pool1zuevzm3xlrhmwjw87ec38mzs02tlkwec9wxpgafcaykmwg7efhh')).not.toThrow(); }); + it('PoolId() accepts a valid genesis pool ID', () => { + expect(() => Cardano.PoolId('ShelleyGenesis-eff1b5b26e65b791')).not.toThrow(); + }); + it('PoolIdHex() accepts a valid pool id hex string', () => { expect(() => Cardano.PoolIdHex('e4b1c8ec89415ce6349755a1aa44b4affbb5f1248ff29943d190c715')).not.toThrow(); });