mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* Move all public connectors to ce/plugins * Update tooling to account for new go modules under ce * Ensure we test all CE plugins in CI * Move Dummypay to ce/plugins for simplicity's sake in the generation scripts * Use versioned pkg/domain in plugins * Ensure that renovate updates all CE plugins in a single PR when pkg/domain tags are pushed to github * Ensure Justfile commands work over all CE plugins * Copy ce plugin go.mods in dev.Dockerfile * Only add a go.mod for new plugins if they are ce * Ensure generated generic client structs are named correctly for submodule * Add coverprofile for each ce plugin * Add set -e for Justfile for loops over plugins * Infer go version from flake.nix in connector template tool
33 lines
833 B
Go
33 lines
833 B
Go
package hmac
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/sha1" //nolint:gosec // we need sha1 for the hmac
|
|
"encoding/base64"
|
|
"net/url"
|
|
)
|
|
|
|
const (
|
|
algorithm = "algorithm=\"hmac-sha1\","
|
|
datePrefix = "date: "
|
|
headers = "headers=\"date x-mod-nonce\","
|
|
prefix = "signature=\""
|
|
suffix = "\""
|
|
newline = "\n"
|
|
nonceKey = "x-mod-nonce: "
|
|
keyIDPrefix = "Signature keyId=\""
|
|
)
|
|
|
|
func buildSignature(apiKey, apiSecret, nonce, date string) string {
|
|
keyID := keyIDPrefix + apiKey + "\","
|
|
|
|
mac := hmac.New(sha1.New, []byte(apiSecret))
|
|
mac.Write([]byte(datePrefix + date + newline + nonceKey + nonce))
|
|
|
|
encodedMac := mac.Sum(nil)
|
|
base64Encoded := base64.StdEncoding.EncodeToString(encodedMac)
|
|
encodedSignature := prefix + url.QueryEscape(base64Encoded) + suffix
|
|
|
|
return keyID + algorithm + headers + encodedSignature
|
|
}
|