-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#2583): fix encoding and decoding cip-129 drep_script identifiers
- Loading branch information
1 parent
16338f3
commit 0d280b9
Showing
7 changed files
with
55 additions
and
43 deletions.
There are no files selected for viewing
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
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
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,33 @@ | ||
import { decodeCIP129Identifier } from "./cip129identifier"; | ||
|
||
/** | ||
* Processes the search phrase for dRep and returns the dRep ID. | ||
* If the phrase starts with "drep_script" or "drep", | ||
* it decodes the CIP129 identifier and extracts the transaction ID. | ||
* If the transaction ID starts with "22" or "23", it returns the ID without the prefix. | ||
* If any error occurs during processing, it returns the original phrase. | ||
* | ||
* @param phrase - The search phrase to be processed. | ||
* @returns The dRep ID extracted from the search phrase or the original phrase if an error occurs. | ||
*/ | ||
export const dRepSearchPhraseProcessor = async (phrase: string) => { | ||
let drepIDPhrase = phrase; | ||
|
||
try { | ||
if ( | ||
drepIDPhrase.startsWith("drep_script") || | ||
drepIDPhrase.startsWith("drep") | ||
) { | ||
const { txID } = decodeCIP129Identifier(drepIDPhrase); | ||
|
||
drepIDPhrase = txID; | ||
} | ||
if (drepIDPhrase.startsWith("22") || drepIDPhrase.startsWith("23")) { | ||
return drepIDPhrase.slice(2); | ||
} | ||
|
||
return drepIDPhrase; | ||
} catch (e) { | ||
return phrase; | ||
} | ||
}; |
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