niko_trust/pkg/address/helpers_test.go
Niko Marmeladkov 3bf13fa488 Public SDK packages, proxy-aware rate limits, service login recipe
- internal/{address,identity,protocol,tce,transport,verify} -> pkg/ so
  external Go projects can import the verified core; invariant tests
  updated for the new paths
- Config.TrustProxy: key rate limiting by X-Forwarded-For when the relay
  sits behind a reverse proxy (off by default, header never trusted
  otherwise)
- examples/service + examples/approve: complete passwordless login round
  trip (mint request -> wallet approves -> local verify), run live in CI
- docs/SERVICE-GUIDE.md: the integration recipe
2026-08-26 12:49:54 +03:00

30 lines
854 B
Go

package address_test
import (
"testing"
"github.com/btcsuite/btcd/btcutil/bech32"
"git.n1ko.dev/Niko/niko_trust/pkg/address"
)
// encodeRawForTest builds a syntactically valid bech32m trust address around
// an arbitrary payload, bypassing the validation that FromPubKey performs.
//
// It exists so that tests can construct the strings an attacker would send and
// confirm that Parse rejects them. Production code must never do this.
func encodeRawForTest(t *testing.T, version byte, key []byte) string {
t.Helper()
payload := make([]byte, 0, 1+len(key))
payload = append(payload, version)
payload = append(payload, key...)
conv, err := bech32.ConvertBits(payload, 8, 5, true)
if err != nil {
t.Fatalf("convert bits: %v", err)
}
s, err := bech32.EncodeM(address.HRP, conv)
if err != nil {
t.Fatalf("encode: %v", err)
}
return s
}