diff --git a/gnovm/stdlibs/std/crypto.gno b/gnovm/stdlibs/std/crypto.gno index 65f4715bf19..a07a9689687 100644 --- a/gnovm/stdlibs/std/crypto.gno +++ b/gnovm/stdlibs/std/crypto.gno @@ -30,11 +30,18 @@ func EncodeBech32(prefix string, bz [20]byte) Address { } func DecodeBech32(addr Address) (string, [20]byte, bool) { - prefix, bz, err := bech32.Decode(string(addr)) + prefix, bz, err := decodeAndConvert(string(addr)) if err != nil || len(bz) != 20 { return "", [20]byte{}, false } - return prefix, [20]byte(bz), true + /* For some reason [20]byte(bz) fails with: 'cannot convert []uint8 to ArrayKind' + Maybe there is an issue to create + */ + result := [20]byte{} + for index,b:= range bz{ + result[index]=b + } + return prefix, result, true } func convertAndEncode(hrp string, data []byte) (string, error) { @@ -44,3 +51,15 @@ func convertAndEncode(hrp string, data []byte) (string, error) { } return bech32.Encode(hrp, converted) } + +func decodeAndConvert(bech string) (string, []byte, error) { + hrp, data, err := bech32.Decode(bech) + if err != nil { + return "", nil, errors.New("decoding bech32 failed"+err.Error()) + } + converted, err := bech32.ConvertBits(data, 5, 8, false) + if err != nil { + return "", nil, errors.New("decoding bech32 failed"+err.Error()) + } + return hrp, converted, nil +} \ No newline at end of file diff --git a/gnovm/tests/files/std5.gno b/gnovm/tests/files/std5.gno index e339d7a6364..e0c09dc367a 100644 --- a/gnovm/tests/files/std5.gno +++ b/gnovm/tests/files/std5.gno @@ -13,7 +13,7 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(2) // std/native.gno:45 diff --git a/gnovm/tests/files/std8.gno b/gnovm/tests/files/std8.gno index ee717bf16be..33c8af1675d 100644 --- a/gnovm/tests/files/std8.gno +++ b/gnovm/tests/files/std8.gno @@ -23,7 +23,7 @@ func main() { // Stacktrace: // panic: frame not found -// callerAt(n) +// callerAt(n) // gonative:std.callerAt // std.GetCallerAt(4) // std/native.gno:45 diff --git a/gnovm/tests/files/zrealm_natbind0.gno b/gnovm/tests/files/zrealm_natbind0.gno index 8e5f641e734..e6ebef6252e 100644 --- a/gnovm/tests/files/zrealm_natbind0.gno +++ b/gnovm/tests/files/zrealm_natbind0.gno @@ -69,7 +69,7 @@ func main() { // "Closure": { // "@type": "/gno.RefValue", // "Escaped": true, -// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:9" +// "ObjectID": "a7f5397443359ea76c50be82c77f1f893a060925:10" // }, // "FileName": "native.gno", // "IsMethod": false,