Documentation
¶
Overview ¶
Package abiz is the consumer side of ABIZ (Agentic Business Record), revision 1.1.
Given a domain, it reads the domain's _abiz DNS TXT assertion (or, when DNS answers with no v=abiz1 value, https://<domain>/.well-known/abiz.json), fetches the one business record the assertion points to, and checks it: the pinned JSON Schema, the semantic rules JSON Schema cannot express, the link between DNS and the record, and the record's Ed25519 signature. Results carry the same status and error code as the hosted resolver at resolve.abizrecord.org.
A resolved record is the publisher's own claim, signed with the key its DNS vouches for. This package never checks a company register and never contacts mcp_server_url or any other URL a record carries.
DNS and HTTPS sit behind the TXTResolver and Fetcher interfaces. NewResolver with no options uses DNSResolver (github.com/miekg/dns) and GuardedFetcher (net/http with the SPEC §9 fetch guard).
Example ¶
The README example. It is compiled, not run: it needs the network.
package main
import (
"context"
"fmt"
abiz "github.com/abiz-org/abiz-go"
)
func main() {
res := abiz.Resolve(context.Background(), "example.com")
if res.Status != abiz.StatusResolved {
fmt.Printf("%s: %s (%s)\n", res.Status, res.Code, res.Message)
return
}
fmt.Println(res.Record["business_name"], res.Record["business_key"])
fmt.Println("found by", res.Discovery.Method, "at", res.Discovery.RecordURL)
}
Output:
Index ¶
- Constants
- Variables
- func Canonicalize(value any) ([]byte, error)
- func CanonicalizeJSON(text []byte) ([]byte, error)
- func CheckRecord(recordText []byte, domain string, assertion *Assertion) (ErrorCode, []Problem, map[string]any)
- func FormatNumber(f float64) string
- func IdentityParts(value string) string
- func IsAssertion(value string) bool
- func IsAssignedCountry(code string) bool
- func IsNonPublicHost(host string) bool
- func IsPublicAddr(addr netip.Addr) bool
- func IsPublicAddress(address string) bool
- func IsPublicKey(value string) bool
- func IsSafeHTTPSURL(value string) bool
- func IsSafeHost(raw string) bool
- func ParseAssertion(value string) (*Assertion, *AssertionError)
- func ParseJSON(text []byte) (any, error)
- func ParseRecordJSON(text []byte) (any, ErrorCode, []Problem)
- func RecordURL(h string) string
- func SameBusinessKey(a, b string) bool
- func SignRecord(record map[string]any, privateKey ed25519.PrivateKey) (map[string]any, error)
- func SigningInput(record map[string]any) ([]byte, error)
- func VerifySignature(record map[string]any, p string) (ErrorCode, *Problem)
- func WellKnownURL(domain string) string
- type AddressResolver
- type Assertion
- type AssertionError
- type BusinessKey
- type DNSResolver
- type Discovery
- type ErrorCode
- type FetchKind
- type FetchResult
- type Fetcher
- type GuardedFetcher
- type Input
- type Option
- type Problem
- type Resolver
- type Result
- type Status
- type TXTKind
- type TXTResolver
- type TXTResult
- type Warning
Examples ¶
Constants ¶
const ( MaxRecordBytes = 65536 // the largest record or well-known file read MaxRecordDepth = 16 // the deepest nesting of objects and arrays MaxRecordKeys = 5000 // the most object members in one document MaxDetails = 25 // the most problems a Result carries )
Limits (SPEC §9 and the hosted resolver).
const ( BusinessRecordSchemaSHA256 = "3658f17f00c238b8c948fdfb447b509c5d055dd778ebd335495da05c3150ff24" WellKnownSchemaSHA256 = "5fe7da6fb5b6b262281402ab9dd9b46c018bf9df766203928e4e1a334cc3d741" ISO3166SHA256 = "0aa5112c46bc2b3efb254ea9536b3cf2977c73d48149aefcd8bc20df995e5527" )
SHA-256 of the bundled files, as test-vectors/README.md lists them.
const ( DNSReasonTimeout = "timeout" DNSReasonNetwork = "network" DNSReasonServfail = "servfail" DNSReasonRefused = "refused" DNSReasonMalformed = "malformed" )
DNS failure reasons. timeout and network give dns_timeout; servfail, refused and malformed give dns_failure.
const BusinessKeyMax = 128
BusinessKeyMax is the longest business key (SPEC §4.2).
const DNSTimeLimit = 2500 * time.Millisecond
DNSTimeLimit is the time a TXT lookup may take, across every server tried.
const FetchTimeLimit = 5 * time.Second
FetchTimeLimit is the time one HTTPS fetch may take, connection and body included.
const SchemaID = "https://abizrecord.org/schema/abiz-business-record-v1.1.schema.json"
SchemaID is the $id of the bundled business record schema.
const SpecRevision = "1.1"
SpecRevision is the ABIZ revision this library implements.
const UserAgent = "abiz-go/" + Version + " (+https://abizrecord.org)"
UserAgent is sent on every HTTPS request.
const Version = "0.1.0"
Version is this library's version.
Variables ¶
var ( //go:embed schema/abiz-business-record-v1.1.schema.json BusinessRecordSchema []byte //go:embed schema/abiz-well-known-v1.1.schema.json WellKnownSchema []byte //go:embed schema/iso3166.json ISO3166 []byte )
The bundled files, copied unchanged from abiz-org/abiz-agentic-business-record (see schema/ISO3166-README.md and test-vectors/README.md for their SHA-256).
var ErrNotIJSON = errors.New("abiz: value is not I-JSON")
ErrNotIJSON is returned by Canonicalize for a value RFC 8785 cannot canonicalise: a string that is not valid Unicode (a lone surrogate), a number that is NaN or infinite, or a Go value that is not JSON.
Functions ¶
func Canonicalize ¶
Canonicalize returns the RFC 8785 (JCS) form of a JSON value: no whitespace, object members sorted by the UTF-16 code units of their names, ECMAScript number and string serialisation. It accepts map[string]any, []any, string, json.Number, float64, float32, the integer types, bool and nil.
func CanonicalizeJSON ¶
CanonicalizeJSON parses JSON text strictly and returns its RFC 8785 form.
func CheckRecord ¶
func CheckRecord(recordText []byte, domain string, assertion *Assertion) (ErrorCode, []Problem, map[string]any)
CheckRecord checks a record's text offline against the queried domain and the assertion, in the hosted resolver's order: record_too_large and not_json (including repeated member names), schema_invalid (JSON Schema, then the semantic checks), identity_host_mismatch, domain_not_claimed, business_key_mismatch, public_key_mismatch, signature_invalid. It returns "" and the parsed record when the record is accepted, else the first failing code and its problems.
func FormatNumber ¶
FormatNumber serialises a finite float64 as ECMAScript's Number::toString does (RFC 8785 §3.2.2.3): the shortest digits that round-trip, plain notation for exponents from -7 to 20, otherwise d.ddde±n; -0 is written 0.
func IdentityParts ¶
IdentityParts returns the canonical form of an h= value or an identity_host (host lower case, one trailing dot dropped, path as written), or "" when the value is not a host name with an optional path: no scheme, credentials, port, query, fragment, or "." or ".." path segment.
func IsAssertion ¶
IsAssertion reports whether a TXT value counts as an ABIZ assertion: its first tag is exactly v=abiz1 (SPEC §3.1.1). V=ABIZ1, v=abiz1x and h=…;v=abiz1 do not count.
func IsAssignedCountry ¶
IsAssignedCountry reports whether code is an assigned ISO 3166-1 alpha-2 code, in any case.
func IsNonPublicHost ¶
IsNonPublicHost reports whether host ends in a special-use or private-network name (or an all-digit top-level label). Such a domain is never queried and such a record host never fetched.
func IsPublicAddr ¶
IsPublicAddr is IsPublicAddress for a parsed address.
func IsPublicAddress ¶
IsPublicAddress reports whether address (an IPv4 or IPv6 literal, optionally in brackets) is one a fetch may connect to. Anything that does not parse is refused.
func IsPublicKey ¶
IsPublicKey reports whether value is an ABIZ 1.1 p key (SPEC §3.3.2): 44 characters of standard base64 ending in one "=", decoding to 32 bytes, and canonical.
func IsSafeHTTPSURL ¶
IsSafeHTTPSURL reports whether value is an https URL with a public DNS host name, no credentials, no fragment and no port (SPEC §4.7.1). Such URLs are checked, never fetched.
func IsSafeHost ¶
IsSafeHost reports whether raw is a DNS host name as the reference validator accepts it: lower case after folding, at least two labels of 1 to 63 letters, digits and hyphens, no IP literal.
func ParseAssertion ¶
func ParseAssertion(value string) (*Assertion, *AssertionError)
ParseAssertion parses one v=abiz1 value under ABIZ 1.1 (SPEC §3.1.1–§3.3.7): the tag-list syntax, recognised tags (v, h, k, p; case-sensitive) at most once, h required and a safe host with an optional path, k a business key, and p required and an Ed25519 public key in standard base64. Unknown tags are ignored, repeats included.
func ParseJSON ¶
ParseJSON parses JSON text strictly into map[string]any, []any, string, json.Number, bool and nil. A repeated member name is an error.
func ParseRecordJSON ¶
ParseRecordJSON parses a record or well-known file as the hosted resolver does: the nesting and member limits first (record_too_large), then strict JSON (not_json), then repeated member names (not_json). On success it returns the parsed value; the code is empty.
func SameBusinessKey ¶
SameBusinessKey reports whether two business keys match ignoring ASCII case (SPEC §4.2.4).
func SignRecord ¶
SignRecord is a producer helper: it returns a copy of record with public_key set to the key's public half (standard base64) and signature set to its Ed25519 signature over the RFC 8785 form of the record without signature. The input map is not changed.
func SigningInput ¶
SigningInput returns the bytes a record's signature signs: the RFC 8785 form of the record without its top-level signature member. It fails with ErrNotIJSON for a record JCS cannot canonicalise.
func VerifySignature ¶
VerifySignature checks a record against the DNS assertion's p: public_key equal to p, then the signature. It returns "" when both hold, else public_key_mismatch or signature_invalid with the problem.
func WellKnownURL ¶
WellKnownURL is the well-known file on the queried domain (SPEC §3.4.1).
Types ¶
type AddressResolver ¶
type AddressResolver interface {
LookupNetIP(ctx context.Context, network, host string) ([]netip.Addr, error)
}
AddressResolver looks up a host's A and AAAA addresses. *net.Resolver satisfies it.
type Assertion ¶
type Assertion struct {
H string `json:"h"` // the canonical record host (host lower case, path as published)
K string `json:"k,omitempty"` // the business key, as published; empty when absent
HasK bool `json:"-"`
P string `json:"p"` // the Ed25519 public key, standard base64
Unknown map[string]string `json:"unknown,omitempty"` // tags the specification does not define (first value of each)
}
Assertion is a parsed _abiz assertion.
type AssertionError ¶
type AssertionError struct {
Code ErrorCode // bad_pointer, duplicate_tag, missing_h, unsafe_host or invalid_key
Message string
}
AssertionError is why an assertion did not parse.
func (*AssertionError) Error ¶
func (e *AssertionError) Error() string
type BusinessKey ¶
BusinessKey is a parsed business key in canonical form (lowercase country and subdivision, uppercase number).
func ParseBusinessKey ¶
func ParseBusinessKey(value string) (BusinessKey, error)
ParseBusinessKey parses a business key under SPEC §4.2.1–§4.2.2.
type DNSResolver ¶
type DNSResolver struct {
// Servers are "host:port" addresses of recursive resolvers, tried in order while one times out
// or cannot be reached.
Servers []string
// Timeout bounds the whole lookup (DNSTimeLimit when zero).
Timeout time.Duration
}
DNSResolver is the default TXTResolver: a plain DNS client (github.com/miekg/dns) that asks the configured recursive servers directly, so that it can tell NXDOMAIN, NODATA, SERVFAIL, REFUSED, a malformed answer and a timeout apart. The standard library's net.Resolver folds several of these together (and the cgo resolver reports them differently again), and ABIZ must never treat a failure as absence.
func NewDNSResolver ¶
func NewDNSResolver() *DNSResolver
NewDNSResolver returns a DNSResolver using the servers in /etc/resolv.conf. When that file cannot be read it has no servers, and every lookup fails as dns_timeout: give servers with NewDNSResolverWithServers (for example 1.1.1.1:53) on systems without resolv.conf.
func NewDNSResolverWithServers ¶
func NewDNSResolverWithServers(servers ...string) *DNSResolver
NewDNSResolverWithServers returns a DNSResolver asking the given servers ("host:port", or a bare host for port 53).
type Discovery ¶
type Discovery struct {
Method string `json:"method"` // "dns_txt" or "well_known"
Owner string `json:"owner"` // _abiz.<domain>
DNSValue string `json:"dns_value,omitempty"`
DNSValues []string `json:"dns_values,omitempty"` // every v=abiz1 value, on multiple_txt
DNSTTL *int `json:"dns_ttl_seconds,omitempty"`
WellKnown string `json:"well_known"` // not_checked, absent, invalid, unavailable, used
WellKnownURL string `json:"well_known_url,omitempty"`
RecordURL string `json:"record_url,omitempty"`
}
Discovery says how the assertion was found and where the record was fetched from.
type ErrorCode ¶
type ErrorCode string
ErrorCode names why a resolution or a check failed. The empty code means no error.
const ( CodeMissingInput ErrorCode = "missing_input" CodeBothInputs ErrorCode = "both_inputs" CodeInvalidDomain ErrorCode = "invalid_domain" CodeInvalidWebsite ErrorCode = "invalid_website" CodeNonPublicDomain ErrorCode = "non_public_domain" CodeMissingTXT ErrorCode = "missing_txt" CodeMultipleTXT ErrorCode = "multiple_txt" CodeBadPointer ErrorCode = "bad_pointer" CodeDuplicateTag ErrorCode = "duplicate_tag" CodeMissingH ErrorCode = "missing_h" CodeUnsafeHost ErrorCode = "unsafe_host" CodeInvalidKey ErrorCode = "invalid_key" CodeFetchFailed ErrorCode = "fetch_failed" CodeRecordTooLarge ErrorCode = "record_too_large" CodeNotJSON ErrorCode = "not_json" CodeSchemaInvalid ErrorCode = "schema_invalid" CodeIdentityHostMismatch ErrorCode = "identity_host_mismatch" CodeDomainNotClaimed ErrorCode = "domain_not_claimed" CodeBusinessKeyMismatch ErrorCode = "business_key_mismatch" CodePublicKeyMismatch ErrorCode = "public_key_mismatch" CodeSignatureInvalid ErrorCode = "signature_invalid" CodeDNSTimeout ErrorCode = "dns_timeout" CodeDNSFailure ErrorCode = "dns_failure" CodeUpstreamTimeout ErrorCode = "upstream_timeout" )
Error codes, as the hosted resolver reports them.
func DomainFromWebsite ¶
DomainFromWebsite takes the host of an http or https website address and normalises it as NormaliseDomain does. The path is ignored.
func NormaliseDomain ¶
NormaliseDomain checks and normalises a domain given as a host name.
func NormaliseInput ¶
NormaliseInput reduces an Input to the domain that is queried: lower case, IDN to A-labels, one trailing dot dropped. www. is never stripped. On failure it returns the error code (missing_input, both_inputs, invalid_domain, invalid_website or non_public_domain) and a message.
type FetchKind ¶
type FetchKind int
FetchKind is the kind of outcome a fetch had.
const ( FetchResponse FetchKind = iota // an HTTP response (Status, ContentType, Body) FetchBlocked // the fetch guard refused the URL or the host's addresses FetchNoAddress // the host has no A or AAAA address FetchDNSError // the host's addresses could not be looked up FetchTimeout // the request did not complete within the time limit FetchNetwork // the connection or TLS failed )
The fetch outcomes.
type FetchResult ¶
type FetchResult struct {
Kind FetchKind
Status int
ContentType string // "" when the response had none
Body []byte
// TooLarge is set when the body was larger than MaxRecordBytes; Body is then nil.
TooLarge bool
Message string // why FetchBlocked refused
}
FetchResult is a fetch's outcome.
type Fetcher ¶
type Fetcher interface {
Fetch(ctx context.Context, url string) FetchResult
}
Fetcher makes one HTTPS GET with Accept: application/json, never following a redirect, within the size and time limits, behind the SPEC §9 fetch guard.
type GuardedFetcher ¶
type GuardedFetcher struct {
// Resolver looks up addresses (net.DefaultResolver when nil).
Resolver AddressResolver
// contains filtered or unexported fields
}
GuardedFetcher is the default Fetcher: net/http behind the SPEC §9 fetch guard. It resolves the host itself, refuses unless every address is public (IsPublicAddr), and then connects to a checked address, never to the name again, so there is no DNS rebinding window. TLS is verified against the host name (SNI and Host are the name). It sends Accept: application/json and User-Agent, never follows a redirect, ignores proxy environment variables, gives up after FetchTimeLimit and reads at most MaxRecordBytes of the body.
func NewGuardedFetcher ¶
func NewGuardedFetcher() *GuardedFetcher
NewGuardedFetcher returns a GuardedFetcher using net.DefaultResolver.
func (*GuardedFetcher) Fetch ¶
func (f *GuardedFetcher) Fetch(ctx context.Context, rawURL string) FetchResult
Fetch implements Fetcher.
type Option ¶
type Option func(*Resolver)
Option configures a Resolver.
func WithTXTResolver ¶
func WithTXTResolver(r TXTResolver) Option
WithTXTResolver replaces the DNS adapter.
type Problem ¶
Problem is one reason a check failed: a JSON Pointer into the record (or "$", or a DNS name or URL for problems outside the record) and a message.
func ValidateSchema ¶
ValidateSchema checks a parsed record against the bundled JSON Schema and returns its problems (none when it conforms). The record's objects must be map[string]any and its numbers json.Number or float64, as ParseRecordJSON returns them.
type Resolver ¶
type Resolver struct {
// contains filtered or unexported fields
}
Resolver resolves domains to checked ABIZ records. The zero value is not usable: use NewResolver.
func NewResolver ¶
NewResolver returns a Resolver. By default it reads DNS with NewDNSResolver() (the system's resolv.conf servers) and fetches with NewGuardedFetcher().
func (*Resolver) ResolveInput ¶
ResolveInput resolves exactly one of a domain and a website address.
type Result ¶
type Result struct {
Status Status `json:"status"`
Code ErrorCode `json:"code"` // empty when resolved
Message string `json:"message,omitempty"`
Retryable bool `json:"retryable"`
Details []Problem `json:"details,omitempty"` // at most MaxDetails
Truncated bool `json:"truncated,omitempty"`
Domain string `json:"domain,omitempty"` // the queried domain (the input as given when it was refused)
Website string `json:"website,omitempty"` // the website input, when one was given
Discovery *Discovery `json:"discovery,omitempty"`
Warnings []Warning `json:"warnings"`
// Record is the checked record, only when Status is resolved. Objects are map[string]any,
// numbers json.Number.
Record map[string]any `json:"record,omitempty"`
// RecordJSON is the record exactly as served, only when Status is resolved.
RecordJSON []byte `json:"-"`
}
Result is the outcome of Resolve.
type TXTResolver ¶
TXTResolver looks up the TXT records at a name. An implementation may use DNS-over-HTTPS, a cache or a test stub.
type TXTResult ¶
type TXTResult struct {
Kind TXTKind
// Values holds one string per TXT record, its character-strings joined with nothing between
// them and unescaped.
Values []string
// TTL is the answer's TTL in seconds, or -1 when unknown.
TTL int
Reason string // for TXTError
}
TXTResult is a TXT lookup's outcome.
type Warning ¶
type Warning struct {
// Code is "content_type" (the record was served without a JSON content type and read anyway)
// or "try_apex" (nothing at a www. name; Domain is the apex, which was not checked).
Code string `json:"code"`
Domain string `json:"domain,omitempty"`
Message string `json:"message"`
}
Warning is advice that does not change the status.