feat(covenant): add Get alias mirrors

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-04 05:42:58 +00:00
parent 7a8c39d480
commit 77e3c0fe17
8 changed files with 305 additions and 8 deletions

View file

@ -69,6 +69,13 @@ func VerifyString(name string) bool {
return !blocked
}
// GetVerifyString is an alias for VerifyString.
//
// ok := covenant.GetVerifyString("example")
func GetVerifyString(name string) bool {
return VerifyString(name)
}
// VerifyBinary reports whether a binary domain name meets the covenant rules.
//
// ok := covenant.VerifyBinary([]byte("example"))
@ -102,6 +109,13 @@ func VerifyBinary(name []byte) bool {
return !blocked
}
// GetVerifyBinary is an alias for VerifyBinary.
//
// ok := covenant.GetVerifyBinary([]byte("example"))
func GetVerifyBinary(name []byte) bool {
return VerifyBinary(name)
}
// VerifyName reports whether a name meets the covenant rules.
//
// It accepts either a string or a byte slice to mirror the JS reference API.
@ -118,6 +132,13 @@ func VerifyName(name any) bool {
}
}
// GetVerifyName is an alias for VerifyName.
//
// ok := covenant.GetVerifyName("example")
func GetVerifyName(name any) bool {
return VerifyName(name)
}
// VerifyByName is an alias for VerifyName.
//
// ok := covenant.VerifyByName("example")
@ -125,6 +146,13 @@ func VerifyByName(name any) bool {
return VerifyName(name)
}
// GetVerifyByName is an alias for VerifyByName.
//
// ok := covenant.GetVerifyByName("example")
func GetVerifyByName(name any) bool {
return VerifyByName(name)
}
// VerifyByString is an alias for VerifyString.
//
// ok := covenant.VerifyByString("example")
@ -132,6 +160,13 @@ func VerifyByString(name string) bool {
return VerifyString(name)
}
// GetVerifyByString is an alias for VerifyByString.
//
// ok := covenant.GetVerifyByString("example")
func GetVerifyByString(name string) bool {
return VerifyByString(name)
}
// VerifyByBinary is an alias for VerifyBinary.
//
// ok := covenant.VerifyByBinary([]byte("example"))
@ -139,6 +174,13 @@ func VerifyByBinary(name []byte) bool {
return VerifyBinary(name)
}
// GetVerifyByBinary is an alias for VerifyByBinary.
//
// ok := covenant.GetVerifyByBinary([]byte("example"))
func GetVerifyByBinary(name []byte) bool {
return VerifyByBinary(name)
}
// HashString hashes a validated domain name.
//
// hash, err := covenant.HashString("example")
@ -151,6 +193,13 @@ func HashString(name string) (primitives.Hash, error) {
return primitives.Hash(sum), nil
}
// GetHashString is an alias for HashString.
//
// hash, err := covenant.GetHashString("example")
func GetHashString(name string) (primitives.Hash, error) {
return HashString(name)
}
// HashByString is an alias for HashString.
//
// hash, err := covenant.HashByString("example")
@ -158,6 +207,13 @@ func HashByString(name string) (primitives.Hash, error) {
return HashString(name)
}
// GetHashByString is an alias for HashByString.
//
// hash, err := covenant.GetHashByString("example")
func GetHashByString(name string) (primitives.Hash, error) {
return HashByString(name)
}
// HashBinary hashes a validated domain name.
//
// hash, err := covenant.HashBinary([]byte("example"))
@ -170,6 +226,13 @@ func HashBinary(name []byte) (primitives.Hash, error) {
return primitives.Hash(sum), nil
}
// GetHashBinary is an alias for HashBinary.
//
// hash, err := covenant.GetHashBinary([]byte("example"))
func GetHashBinary(name []byte) (primitives.Hash, error) {
return HashBinary(name)
}
// HashByBinary is an alias for HashBinary.
//
// hash, err := covenant.HashByBinary([]byte("example"))
@ -177,6 +240,13 @@ func HashByBinary(name []byte) (primitives.Hash, error) {
return HashBinary(name)
}
// GetHashByBinary is an alias for HashByBinary.
//
// hash, err := covenant.GetHashByBinary([]byte("example"))
func GetHashByBinary(name []byte) (primitives.Hash, error) {
return HashByBinary(name)
}
// HashName hashes a validated domain name.
//
// It accepts either a string or a byte slice to mirror the JS reference API.
@ -193,9 +263,23 @@ func HashName(name any) (primitives.Hash, error) {
}
}
// GetHashName is an alias for HashName.
//
// hash, err := covenant.GetHashName("example")
func GetHashName(name any) (primitives.Hash, error) {
return HashName(name)
}
// HashByName is an alias for HashName.
//
// hash, err := covenant.HashByName("example")
func HashByName(name any) (primitives.Hash, error) {
return HashName(name)
}
// GetHashByName is an alias for HashByName.
//
// hash, err := covenant.GetHashByName("example")
func GetHashByName(name any) (primitives.Hash, error) {
return HashByName(name)
}

View file

@ -185,13 +185,37 @@ func TestVerifyAliases(t *testing.T) {
t.Fatal("VerifyByName should accept string inputs")
}
if !GetVerifyName("foo-bar") {
t.Fatal("GetVerifyName should accept string inputs")
}
if !VerifyByString("foo-bar") {
t.Fatal("VerifyByString should accept string inputs")
}
if !GetVerifyString("foo-bar") {
t.Fatal("GetVerifyString should accept string inputs")
}
if !VerifyByBinary([]byte("foo_bar")) {
t.Fatal("VerifyByBinary should accept byte-slice inputs")
}
if !GetVerifyBinary([]byte("foo_bar")) {
t.Fatal("GetVerifyBinary should accept byte-slice inputs")
}
if !GetVerifyByName("foo-bar") {
t.Fatal("GetVerifyByName should alias VerifyByName")
}
if !GetVerifyByString("foo-bar") {
t.Fatal("GetVerifyByString should alias VerifyByString")
}
if !GetVerifyByBinary([]byte("foo_bar")) {
t.Fatal("GetVerifyByBinary should alias VerifyByBinary")
}
}
func TestHashString(t *testing.T) {
@ -241,14 +265,25 @@ func TestHashName(t *testing.T) {
}
func TestHashAliases(t *testing.T) {
wantString := sha3.Sum256([]byte("foo-bar"))
wantBinary := sha3.Sum256([]byte("foo_bar"))
got, err := HashByName("foo-bar")
if err != nil {
t.Fatalf("HashByName(string) returned error: %v", err)
}
want := sha3.Sum256([]byte("foo-bar"))
if got != want {
t.Fatalf("HashByName(string) returned %x, want %x", got, want)
if got != wantString {
t.Fatalf("HashByName(string) returned %x, want %x", got, wantString)
}
got, err = GetHashName("foo-bar")
if err != nil {
t.Fatalf("GetHashName(string) returned error: %v", err)
}
if got != wantString {
t.Fatalf("GetHashName(string) returned %x, want %x", got, wantString)
}
got, err = HashByString("foo-bar")
@ -256,8 +291,17 @@ func TestHashAliases(t *testing.T) {
t.Fatalf("HashByString returned error: %v", err)
}
if got != want {
t.Fatalf("HashByString returned %x, want %x", got, want)
if got != wantString {
t.Fatalf("HashByString returned %x, want %x", got, wantString)
}
got, err = GetHashString("foo-bar")
if err != nil {
t.Fatalf("GetHashString returned error: %v", err)
}
if got != wantString {
t.Fatalf("GetHashString returned %x, want %x", got, wantString)
}
got, err = HashByBinary([]byte("foo_bar"))
@ -265,9 +309,44 @@ func TestHashAliases(t *testing.T) {
t.Fatalf("HashByBinary returned error: %v", err)
}
want = sha3.Sum256([]byte("foo_bar"))
if got != want {
t.Fatalf("HashByBinary returned %x, want %x", got, want)
if got != wantBinary {
t.Fatalf("HashByBinary returned %x, want %x", got, wantBinary)
}
got, err = GetHashBinary([]byte("foo_bar"))
if err != nil {
t.Fatalf("GetHashBinary returned error: %v", err)
}
if got != wantBinary {
t.Fatalf("GetHashBinary returned %x, want %x", got, wantBinary)
}
got, err = GetHashByName("foo-bar")
if err != nil {
t.Fatalf("GetHashByName(string) returned error: %v", err)
}
if got != wantString {
t.Fatalf("GetHashByName(string) returned %x, want %x", got, wantString)
}
got, err = GetHashByString("foo-bar")
if err != nil {
t.Fatalf("GetHashByString returned error: %v", err)
}
if got != wantString {
t.Fatalf("GetHashByString returned %x, want %x", got, wantString)
}
got, err = GetHashByBinary([]byte("foo_bar"))
if err != nil {
t.Fatalf("GetHashByBinary returned error: %v", err)
}
if got != wantBinary {
t.Fatalf("GetHashByBinary returned %x, want %x", got, wantBinary)
}
}

View file

@ -62,6 +62,13 @@ func HasNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) bool
return false
}
// GetHasNames is an alias for HasNames.
//
// ok := covenant.GetHasNames(tx, set)
func GetHasNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) bool {
return HasNames(tx, set)
}
// AddNames adds the transaction's name covenants to the set.
func AddNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) {
for _, output := range tx.Outputs {
@ -81,6 +88,13 @@ func AddNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) {
}
}
// GetAddNames is an alias for AddNames.
//
// covenant.GetAddNames(tx, set)
func GetAddNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) {
AddNames(tx, set)
}
// RemoveNames removes the transaction's name covenants from the set.
func RemoveNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) {
for _, output := range tx.Outputs {
@ -100,6 +114,13 @@ func RemoveNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) {
}
}
// GetRemoveNames is an alias for RemoveNames.
//
// covenant.GetRemoveNames(tx, set)
func GetRemoveNames(tx primitives.Transaction, set map[primitives.Hash]struct{}) {
RemoveNames(tx, set)
}
func isCoinbaseTx(tx primitives.Transaction) bool {
return len(tx.Inputs) > 0 && tx.Inputs[0].IsCoinbase()
}
@ -330,3 +351,10 @@ func HasSaneCovenants(tx primitives.Transaction) bool {
return true
}
// GetHasSaneCovenants is an alias for HasSaneCovenants.
//
// ok := covenant.GetHasSaneCovenants(tx)
func GetHasSaneCovenants(tx primitives.Transaction) bool {
return HasSaneCovenants(tx)
}

View file

@ -115,6 +115,13 @@ func IsReserved(nameHash primitives.Hash, height uint32, rules NameRules) bool {
return HasReservedHash(nameHash)
}
// GetIsReserved is an alias for IsReserved.
//
// ok := covenant.GetIsReserved(nameHash, height, rules)
func GetIsReserved(nameHash primitives.Hash, height uint32, rules NameRules) bool {
return IsReserved(nameHash, height, rules)
}
// IsLockedUp reports whether a name is locked after the claim period.
//
// ICANN root names are always locked; non-root names remain locked until the
@ -140,6 +147,13 @@ func IsLockedUp(nameHash primitives.Hash, height uint32, rules NameRules) bool {
return height < rules.AlexaLockupPeriod
}
// GetIsLockedUp is an alias for IsLockedUp.
//
// ok := covenant.GetIsLockedUp(nameHash, height, rules)
func GetIsLockedUp(nameHash primitives.Hash, height uint32, rules NameRules) bool {
return IsLockedUp(nameHash, height, rules)
}
func modBuffer(buf []byte, num uint32) uint32 {
if num == 0 {
return 0

View file

@ -73,6 +73,13 @@ func GrindName(size int, height uint32, rules NameRules) (string, error) {
return "", core.E("covenant.GrindName", "could not find available name", nil)
}
// GetGrindName is an alias for GrindName.
//
// name, err := covenant.GetGrindName(8, height, rules)
func GetGrindName(size int, height uint32, rules NameRules) (string, error) {
return GrindName(size, height, rules)
}
// CountOpens counts OPEN covenants in the transaction outputs.
func CountOpens(tx primitives.Transaction) int {
total := 0
@ -86,6 +93,13 @@ func CountOpens(tx primitives.Transaction) int {
return total
}
// GetCountOpens is an alias for CountOpens.
//
// count := covenant.GetCountOpens(tx)
func GetCountOpens(tx primitives.Transaction) int {
return CountOpens(tx)
}
// CountUpdates counts UPDATE-style covenants in the transaction outputs.
func CountUpdates(tx primitives.Transaction) int {
total := 0
@ -100,6 +114,13 @@ func CountUpdates(tx primitives.Transaction) int {
return total
}
// GetCountUpdates is an alias for CountUpdates.
//
// count := covenant.GetCountUpdates(tx)
func GetCountUpdates(tx primitives.Transaction) int {
return CountUpdates(tx)
}
// CountRenewals counts REGISTER, RENEW, and FINALIZE covenants in the transaction outputs.
func CountRenewals(tx primitives.Transaction) int {
total := 0
@ -113,3 +134,10 @@ func CountRenewals(tx primitives.Transaction) int {
return total
}
// GetCountRenewals is an alias for CountRenewals.
//
// count := covenant.GetCountRenewals(tx)
func GetCountRenewals(tx primitives.Transaction) int {
return CountRenewals(tx)
}

View file

@ -28,13 +28,25 @@ func TestCountHelpers(t *testing.T) {
t.Fatalf("CountOpens() = %d, want 1", got)
}
if got := GetCountOpens(tx); got != 1 {
t.Fatalf("GetCountOpens() = %d, want 1", got)
}
if got := CountUpdates(tx); got != 5 {
t.Fatalf("CountUpdates() = %d, want 5", got)
}
if got := GetCountUpdates(tx); got != 5 {
t.Fatalf("GetCountUpdates() = %d, want 5", got)
}
if got := CountRenewals(tx); got != 3 {
t.Fatalf("CountRenewals() = %d, want 3", got)
}
if got := GetCountRenewals(tx); got != 3 {
t.Fatalf("GetCountRenewals() = %d, want 3", got)
}
}
func TestGrindName(t *testing.T) {
@ -78,6 +90,15 @@ func TestGrindName(t *testing.T) {
if _, err := GrindName(0, 100, rules); err == nil {
t.Fatal("GrindName should reject zero-length names")
}
alias, err := GetGrindName(8, 100, rules)
if err != nil {
t.Fatalf("GetGrindName returned error: %v", err)
}
if len(alias) != 8 {
t.Fatalf("GetGrindName returned %q with length %d, want 8", alias, len(alias))
}
}
func TestNameSetHelpers(t *testing.T) {
@ -101,6 +122,10 @@ func TestNameSetHelpers(t *testing.T) {
t.Fatal("HasNames should report a matching name hash")
}
if !GetHasNames(tx, set) {
t.Fatal("GetHasNames should alias HasNames")
}
RemoveNames(tx, set)
if len(set) != 0 {
@ -112,6 +137,18 @@ func TestNameSetHelpers(t *testing.T) {
if len(set) != 1 {
t.Fatalf("AddNames left %d entries, want 1", len(set))
}
GetRemoveNames(tx, set)
if len(set) != 0 {
t.Fatalf("GetRemoveNames left %d entries, want 0", len(set))
}
GetAddNames(tx, set)
if len(set) != 1 {
t.Fatalf("GetAddNames left %d entries, want 1", len(set))
}
}
func TestHasSaneCovenants(t *testing.T) {
@ -135,6 +172,10 @@ func TestHasSaneCovenants(t *testing.T) {
t.Fatal("HasSaneCovenants should accept structurally valid covenants")
}
if !GetHasSaneCovenants(valid) {
t.Fatal("GetHasSaneCovenants should alias HasSaneCovenants")
}
invalid := primitives.Transaction{
Outputs: []primitives.Output{
{Covenant: primitives.Covenant{Type: uint8(TypeOpen), Items: [][]byte{hash[:], []byte{1, 0, 0, 0}, []byte("example-name")}}},
@ -265,10 +306,18 @@ func TestVerifyCovenants(t *testing.T) {
t.Fatalf("VerifyCovenants returned %d, want 0", got)
}
if got := GetVerifyCovenants(tx, view, 100, Network{}); got != 0 {
t.Fatalf("GetVerifyCovenants returned %d, want 0", got)
}
tx.Outputs[0].Address.Hash[0] ^= 1
if got := VerifyCovenants(tx, view, 100, Network{}); got != -1 {
t.Fatalf("VerifyCovenants returned %d for an invalid finalize address, want -1", got)
}
if got := GetVerifyCovenants(tx, view, 100, Network{}); got != -1 {
t.Fatalf("GetVerifyCovenants returned %d for an invalid finalize address, want -1", got)
}
}
func TestVerifyCovenantsBidReveal(t *testing.T) {

View file

@ -66,6 +66,10 @@ func TestIsReserved(t *testing.T) {
t.Fatal("IsReserved should reject reserved names at or after the claim period")
}
if !GetIsReserved(hash, 99, rules) {
t.Fatal("GetIsReserved should alias IsReserved")
}
rules.NoReserved = true
if IsReserved(hash, 99, rules) {
t.Fatal("IsReserved should be disabled when reserved-name protection is off")
@ -104,6 +108,10 @@ func TestIsLockedUp(t *testing.T) {
t.Fatal("IsLockedUp should release non-root names after the Alexa threshold")
}
if !GetIsLockedUp(rootHash, 100, rules) {
t.Fatal("GetIsLockedUp should alias IsLockedUp")
}
rules.NoReserved = true
if IsLockedUp(rootHash, 100, rules) {
t.Fatal("IsLockedUp should be disabled when reserved-name protection is off")

View file

@ -290,6 +290,13 @@ func VerifyCovenants(tx primitives.Transaction, view CoinView, height uint32, ne
return 0
}
// GetVerifyCovenants is an alias for VerifyCovenants.
//
// status := covenant.GetVerifyCovenants(tx, view, height, network)
func GetVerifyCovenants(tx primitives.Transaction, view CoinView, height uint32, network Network) int {
return VerifyCovenants(tx, view, height, network)
}
func covenantHashEquals(cov primitives.Covenant, index int, other primitives.Covenant) bool {
hash, err := cov.GetHash(index)
if err != nil {