Files
zeekay bd850a1b38 feat: complete 5-chain verifier core (TS) + Go port + IAM plan
TS verifiers: EVM, Solana, TON (ton_proof), XRP (secp256k1+ed25519), Bitcoin
(legacy + BIP-322 simple P2WPKH/P2TR) — 61 tests green, typecheck clean.

Go port (go/walletconnect): EVM + Solana via github.com/luxfi/crypto (NO
go-ethereum/ava-labs), TON/XRP/Bitcoin stubs fail-closed — 23 tests green.

IAM integration plan + drafts (integrations/iam/): canonical /v1/iam/web3/
{nonce,verify}, single-use nonce store, multi-wallet WalletLink. Found current
IAM web3 login verifies NO signature (security hole this closes).
2026-06-22 22:47:36 -07:00

43 lines
1.1 KiB
Go

package walletconnect
import (
"encoding/base64"
"encoding/hex"
"regexp"
"strings"
)
// Byte helpers shared by every verifier. Mirror src/bytes.ts.
// hexToBytes decodes hex, tolerant of a leading 0x/0X. Mirrors the TS
// hexToBytes.
func hexToBytes(s string) ([]byte, error) {
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
s = s[2:]
}
return hex.DecodeString(s)
}
// base64ToBytes decodes standard, padded base64. Mirrors the TS base64ToBytes.
func base64ToBytes(s string) ([]byte, error) {
return base64.StdEncoding.DecodeString(s)
}
var pureHexRE = regexp.MustCompile(`^[0-9a-fA-F]+$`)
// decodeSignature decodes a signature that may be hex (0x…) or base64 into raw
// bytes. The heuristic mirrors the TS decodeSignature exactly:
// - leading 0x/0X => hex
// - pure hex of even length => hex
// - otherwise => base64
func decodeSignature(sig string) ([]byte, error) {
s := strings.TrimSpace(sig)
if strings.HasPrefix(s, "0x") || strings.HasPrefix(s, "0X") {
return hexToBytes(s)
}
if pureHexRE.MatchString(s) && len(s)%2 == 0 {
return hexToBytes(s)
}
return base64ToBytes(s)
}