-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Elrond implementation. * Update copyright notices Co-authored-by: Catenocrypt <[email protected]>
- Loading branch information
Showing
11 changed files
with
133 additions
and
66 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
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,24 @@ | ||
package coincodec | ||
|
||
const ( | ||
hrpElrond = "erd" | ||
ElrondKeyhashLength = 32 | ||
) | ||
|
||
func init() { | ||
// 508 slip44.ELROND | ||
toBytesMap[508] = ElrondDecodeToBytes | ||
toStringMap[508] = ElrondEncodeToString | ||
} | ||
|
||
// ElrondDecodeToBytes converts the input string to a byte array | ||
func ElrondDecodeToBytes(input string) ([]byte, error) { | ||
bytes, err := Bech32AddressDecodeToBytes(hrpElrond, input, ElrondKeyhashLength) | ||
return bytes, err | ||
} | ||
|
||
// ElrondEncodeToString converts the input byte array to a string representation of the Elrond address. | ||
func ElrondEncodeToString(bytes []byte) (string, error) { | ||
output, err := Bech32AddressEncodeToString(hrpElrond, bytes, ElrondKeyhashLength) | ||
return output, err | ||
} |
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,95 @@ | ||
package coincodec | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/pkg/errors" | ||
) | ||
|
||
func TestElrondEncodeToBytes(t *testing.T) { | ||
tests := []TestcaseEncode{ | ||
{ | ||
name: "Alice", | ||
input: "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz", | ||
output: "fd691bb5e85d102687d81079dffce842d4dc328276d2d4c60d8fd1c3433c3293", | ||
}, | ||
{ | ||
name: "Bob", | ||
input: "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r", | ||
output: "c70cf50b238372fffaf7b7c5723b06b57859d424a2da621bcc1b2f317543aa36", | ||
}, | ||
{ | ||
name: "Carol", | ||
input: "erd19nu5t7hszckwah5nlcadmk5rlchtugzplznskffpwecygcu0520s9tnyy0", | ||
output: "2cf945faf0162ceede93fe3addda83fe2ebe2041f8a70b2521767044638fa29f", | ||
}, | ||
// invalid | ||
{ | ||
name: "Empty", | ||
input: "", | ||
err: errors.New("decoding bech32 failed"), | ||
}, | ||
{ | ||
name: "Invalid", | ||
input: "foo", | ||
err: errors.New("decoding bech32 failed"), | ||
}, | ||
{ | ||
name: "Invalid 2", | ||
input: "10z9xdugayn528ksaesdwlhf006fw5sg2qmmm0h52fvxczwgesyvq5pwemr", | ||
err: errors.New("decoding bech32 failed"), | ||
}, | ||
{ | ||
name: "Invalid 3", | ||
input: "xerd10z9xdugayn528ksaesdwlhf006fw5sg2qmmm0h52fvxczwgesyvq5pwemr", | ||
err: errors.New("decoding bech32 failed"), | ||
}, | ||
{ | ||
name: "Invalid 4", | ||
input: "foo10z9xdugayn528ksaesdwlhf006fw5sg2qmmm0h52fvxczwgesyvq5pwemr", | ||
err: errors.New("decoding bech32 failed"), | ||
}, | ||
{ | ||
name: "Invalid Hex", | ||
input: "fd691bb5e85d102687d81079dffce842d4dc328276d2d4c60d8fd1c3433c3293", | ||
err: errors.New("decoding bech32 failed"), | ||
}, | ||
} | ||
|
||
// 508 slip44.ELROND | ||
RunTestsEncode(t, 508, tests) | ||
} | ||
|
||
func TestElrondDecodeToString(t *testing.T) { | ||
tests := []TestcaseDecode{ | ||
{ | ||
name: "Alice", | ||
input: "fd691bb5e85d102687d81079dffce842d4dc328276d2d4c60d8fd1c3433c3293", | ||
output: "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz", | ||
}, | ||
{ | ||
name: "Bob", | ||
input: "c70cf50b238372fffaf7b7c5723b06b57859d424a2da621bcc1b2f317543aa36", | ||
output: "erd1cux02zersde0l7hhklzhywcxk4u9n4py5tdxyx7vrvhnza2r4gmq4vw35r", | ||
}, | ||
{ | ||
name: "Carol", | ||
input: "2cf945faf0162ceede93fe3addda83fe2ebe2041f8a70b2521767044638fa29f", | ||
output: "erd19nu5t7hszckwah5nlcadmk5rlchtugzplznskffpwecygcu0520s9tnyy0", | ||
}, | ||
// invalid | ||
{ | ||
name: "Empty", | ||
input: "", | ||
err: errors.New("A Bech32 address key hash must be 20 bytes"), | ||
}, | ||
{ | ||
name: "Too short", | ||
input: "fd691bb5e85d102687d81079dffce842d4dc328276d2d4c60d8fd1c3433c32", | ||
err: errors.New("A Bech32 address key hash must be 20 bytes"), | ||
}, | ||
} | ||
|
||
// 508 slip44.ELROND | ||
RunTestsDecode(t, 508, tests) | ||
} |
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