mirror of
https://github.com/FlipsideCrypto/fsc-utils.git
synced 2026-02-06 10:56:49 +00:00
udf_hex_to_algo
This commit is contained in:
parent
229548e678
commit
dae5fff71c
@ -181,5 +181,16 @@
|
||||
sql: |
|
||||
{{ fsc_utils.create_udf_bech32() | indent(4) }}
|
||||
|
||||
- name: {{ schema }}.udf_hex_to_algorand
|
||||
signature:
|
||||
- [input, STRING]
|
||||
return_type: TEXT
|
||||
options: |
|
||||
LANGUAGE PYTHON
|
||||
RUNTIME_VERSION = '3.8'
|
||||
HANDLER = 'transform_hex_to_algorand'
|
||||
sql: |
|
||||
{{ fsc_utils.create_udf_hex_to_algorand() | indent(4) }}
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@ -261,4 +261,26 @@ def transform_bech32(input, hrp=''):
|
||||
|
||||
return hrp + '1' + ''.join([CHARSET[d] for d in data5bit + checksum])
|
||||
|
||||
{% endmacro %}
|
||||
|
||||
{% macro create_udf_hex_to_algorand() %}
|
||||
|
||||
import hashlib
|
||||
import base64
|
||||
|
||||
def transform_hex_to_algorand(input):
|
||||
if input is None or not input.startswith('0x'):
|
||||
return 'Invalid input'
|
||||
|
||||
input = input[2:]
|
||||
public_key_bytes = bytearray.fromhex(input)
|
||||
|
||||
sha512_256_hash = hashlib.new('sha512_256', public_key_bytes).digest()
|
||||
|
||||
checksum = sha512_256_hash[-4:]
|
||||
|
||||
algorand_address = base64.b32encode(public_key_bytes + checksum).decode('utf-8').rstrip('=')
|
||||
|
||||
return algorand_address
|
||||
|
||||
{% endmacro %}
|
||||
Loading…
Reference in New Issue
Block a user