-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b34ef82
commit 94a2dd4
Showing
14 changed files
with
790 additions
and
128 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
packages/offchain/src/TxBuilder/TxBuilderRunner/CanBePoolKeyHash.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Hash28, PoolKeyHash, Address, AddressStr } from "@harmoniclabs/cardano-ledger-ts"; | ||
import { decodeBech32 } from "@harmoniclabs/crypto"; | ||
import { fromHex } from "@harmoniclabs/uint8array-utils"; | ||
|
||
export type CanBePoolKeyHash = Hash28 | `pool1${string}` | `pool_test1${string}` | string /* hex */ | Uint8Array; | ||
|
||
export function forcePoolKeyHash( canBe: CanBePoolKeyHash ): PoolKeyHash | ||
{ | ||
if( typeof canBe === "string" ) | ||
{ | ||
if( canBe.startsWith("pool") ) | ||
{ | ||
const [ _hrp, decoded ] = decodeBech32( canBe ); | ||
|
||
return new PoolKeyHash( new Uint8Array( decoded ) ); | ||
} | ||
return new PoolKeyHash( fromHex( canBe ) ); | ||
} | ||
return new PoolKeyHash( canBe ); | ||
} |
43 changes: 43 additions & 0 deletions
43
packages/offchain/src/TxBuilder/TxBuilderRunner/CanBeStakeCreds.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { StakeAddress, Credential, StakeAddressBech32, StakeCredentials, Script, PlutusScriptType, StakeValidatorHash, CredentialType, Hash28 } from "@harmoniclabs/cardano-ledger-ts"; | ||
|
||
export type CanBeStakeCreds | ||
= StakeAddress | ||
| StakeAddressBech32 | ||
| StakeCredentials | ||
| Script<PlutusScriptType> | ||
| Credential; | ||
|
||
export function forceStakeCreds( creds: CanBeStakeCreds ): Credential | ||
{ | ||
if( creds instanceof Credential ) return creds; | ||
|
||
if( typeof creds === "string" ) | ||
{ | ||
if( !creds.startsWith("stake") ) | ||
{ | ||
throw new Error("invalid bech32 stake address"); | ||
} | ||
creds = StakeAddress.fromString( creds ); | ||
} | ||
if( creds instanceof StakeAddress ) | ||
{ | ||
return creds.toCredential(); | ||
} | ||
|
||
if( creds instanceof Script ) | ||
{ | ||
return Credential.script( | ||
new StakeValidatorHash( creds.hash ) | ||
); | ||
} | ||
|
||
if( creds.type === "pointer" ) | ||
{ | ||
throw new Error("pointer stake credentials not supported"); | ||
} | ||
|
||
return new Credential( | ||
creds.type === "script" ? CredentialType.Script : CredentialType.KeyHash, | ||
creds.hash as Hash28 | ||
); | ||
} |
Oops, something went wrong.