Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checksum for ICRC-1 addresses #5496

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions scripts/convert-id
Original file line number Diff line number Diff line change
Expand Up @@ -144,16 +144,16 @@ function hex_to_icrc1() {
subaccount_hex="$(get_subaccount_hex)"

# Remove leading zeros.
subaccount_hex="$(echo -n "$subaccount_hex" | sed -e 's@^0*@@')"
trimmed_subaccount_hex="$(echo -n "$subaccount_hex" | sed -e 's@^0*@@')"

if [[ -z "$subaccount_hex" ]]; then
if [[ -z "$trimmed_subaccount_hex" ]]; then
echo -n "$hex" | hex_to_text
return
fi

checksum="$(echo -n "${hex}${subaccount_hex}" | xxd -r -p | /usr/bin/crc32 /dev/stdin | xxd -p -r | base32 | tr -d = | tr '[:upper:]' '[:lower:]')"

echo "$(echo "$hex" | hex_to_text)-${checksum}.${subaccount_hex}"
echo "$(echo "$hex" | hex_to_text)-${checksum}.${trimmed_subaccount_hex}"
}

function check_hex() {
Expand Down
4 changes: 2 additions & 2 deletions scripts/convert-id.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function expect_convert() {
SCRIPT_UNDER_TEST="$SOURCE_DIR/convert-id"
actual_output=$("$SCRIPT_UNDER_TEST" "$@")
if [ "$expected_output" != "$actual_output" ]; then
printf "Command: %s " "$(basename "$SCRIPT_UNDER_TEST")"
printf "Command: %s" "$(basename "$SCRIPT_UNDER_TEST")"
printf " %q" "$@"
echo
echo "Expected: $expected_output"
Expand Down Expand Up @@ -59,7 +59,7 @@ expect_convert "$SUBACCOUNT_IDENTIFIER" --output account_identifier --input text
expect_convert "$HEX_AS_SUBACCOUNT" --output hex --as_subaccount --input text "$TEXT"
expect_convert "$SUBACCOUNT_IDENTIFIER" --output account_identifier --input text --subaccount_format hex "$TEXT2" "$HEX_AS_SUBACCOUNT"

ICRC1_CHECKSUM="3vbe6yq"
ICRC1_CHECKSUM="vyqwuvy"
ICRC1="$TEXT2-$ICRC1_CHECKSUM.1"
expect_convert "$ICRC1" --output icrc1 --input icrc1 "$ICRC1"
expect_convert "$ICRC1" --output icrc1 --input text "$TEXT2" 1
Expand Down