Commit 8fd18705 authored by Andrei Mihu's avatar Andrei Mihu
Browse files

Better signature for JS runtime HMAC-SHA256 and Base64 functions.

parent 6821d622
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ The format is based on [keep a changelog](http://keepachangelog.com) and this pr
- Added next and previous cursor to results of leaderboard and tournament records around owner client operations.
- Added next and previous cursor to results of leaderboard and tournament records haystack runtime operations.
- Build with Go 1.18.3 release.
- Improve signature of JavaScript runtime HMAC SHA256 hash function.
- Improve signature of JavaScript runtime Base64 encode functions.

## [3.12.0] - 2022-05-22
### Added
+16 −3
Original line number Diff line number Diff line
@@ -632,7 +632,20 @@ func (n *runtimeJavascriptNakamaModule) httpRequest(r *goja.Runtime) func(goja.F
// @return error(error) An optional error value if an error occurred.
func (n *runtimeJavascriptNakamaModule) base64Encode(r *goja.Runtime) func(goja.FunctionCall) goja.Value {
	return func(f goja.FunctionCall) goja.Value {
		in := getJsString(r, f.Argument(0))
		if goja.IsUndefined(f.Argument(0)) || goja.IsNull(f.Argument(0)) {
			panic(r.NewTypeError("expects a string or ArrayBuffer object"))
		}

		var in []byte
		switch v := f.Argument(0).Export(); v.(type) {
		case string:
			in = []byte(v.(string))
		case goja.ArrayBuffer:
			in = v.(goja.ArrayBuffer).Bytes()
		default:
			panic(r.NewTypeError("expects a string or ArrayBuffer object"))
		}

		padding := true
		if f.Argument(1) != goja.Undefined() {
			padding = getJsBool(r, f.Argument(1))
@@ -643,7 +656,7 @@ func (n *runtimeJavascriptNakamaModule) base64Encode(r *goja.Runtime) func(goja.
			e = base64.RawURLEncoding
		}

		out := e.EncodeToString([]byte(in))
		out := e.EncodeToString(in)
		return r.ToValue(out)
	}
}
@@ -1051,7 +1064,7 @@ func (n *runtimeJavascriptNakamaModule) hmacSHA256Hash(r *goja.Runtime) func(goj
			panic(r.NewGoError(fmt.Errorf("error creating hash: %v", err.Error())))
		}

		return r.ToValue(string(mac.Sum(nil)))
		return r.ToValue(r.NewArrayBuffer(mac.Sum(nil)))
	}
}