Skip to content

Commit

Permalink
Add support for drep_vkh1
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript committed Nov 11, 2024
1 parent 1cd9601 commit e7437ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/staking/src/governance/helpers/parsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@ describe('parseDrepId', () => {
})
})

it('should parse a drep_vkh1 key hash in bech32 format', async () => {
const result = await parseDrepId(
'drep_vkh1km69g7ksf8t5g0h9d9tkrcd2tezxelx0wtr76rv2mrkl549k89t',
cardano,
)

expect(result).toStrictEqual({
hash: 'b6f4547ad049d7443ee5695761e1aa5e446cfccf72c7ed0d8ad8edfa',
type: 'key',
})
})

it('should parse a script hash in bech32 format', async () => {
const result = await parseDrepId(
'drep_script18cgl8kdnjculhww4n3h0a3ahc85ahjcsg53u0f93jnz9c0339av',
Expand Down
10 changes: 10 additions & 0 deletions packages/staking/src/governance/helpers/parsing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ export const parseDrepId = async (
): Promise<{type: 'key'; hash: string} | {type: 'script'; hash: string}> => {
const isPotentiallyValidHex = /^(22|23)[0-9a-fA-F]{56}$/.test(drepId)

if (
drepId.startsWith('drep_vkh1') &&
(await isValidBech32KeyHash(drepId, cardano))
) {
return {
type: 'key',
hash: await convertBech32KeyHashToHex(drepId, cardano),
}
}

if (
drepId.startsWith('drep1') &&
(await isValidBech32KeyHash(drepId, cardano))
Expand Down

0 comments on commit e7437ba

Please sign in to comment.