{"modulePath":"github.com/asteroid-computing/go-lambda-edge","version":"v0.1.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package identity\n\nPackage identity provides immutable callers, owned claims and context transport. Construction validates representation; producers authenticate, and application policy authorizes. The package performs no network or signature verification.\n\n## Variables\n\n```go\nvar (\n\t// ErrInvalidCaller indicates invalid caller facts, provenance or options.\n\tErrInvalidCaller = errors.New(\"identity: invalid caller\")\n\t// ErrConflict indicates an attempt to replace an established caller.\n\tErrConflict = errors.New(\"identity: caller conflict\")\n\t// ErrInvalidClaims indicates malformed JSON, unsupported typed values, invalid UTF-8, nonfinite numbers, or excessive container nesting.\n\tErrInvalidClaims = errors.New(\"identity: invalid claims\")\n\t// ErrClaimsLimit indicates exhaustion of the wire or weighted byte allowance.\n\tErrClaimsLimit = errors.New(\"identity: claims budget exceeded\")\n)\n```\n\n## Functions\n\n```go\nfunc NewContext(ctx context.Context, caller Caller) (context.Context, error)\n```\nNewContext returns a derived context carrying caller, for retrieval with [FromContext](#FromContext). Anonymous on an empty context is a no-op. Any attempted installation over a nonanonymous caller, including an identical caller or anonymous, returns [ErrConflict](#ErrConflict) and a nil context. A nil context returns [ErrInvalidCaller](#ErrInvalidCaller). Unrelated values are preserved.\n\n## Types\n\n```go\ntype Caller struct {\n\t// contains filtered or unexported fields\n}\n```\nCaller is an immutable identity snapshot with exactly one JWT or IAM view. Its zero value is anonymous. Constructors validate facts; they neither authenticate nor authorize. Copies may be shared concurrently. There is no identity equality contract or implicit JSON export. Diagnostics omit facts.\n\n```go\nfunc FromContext(ctx context.Context) Caller\n```\nFromContext returns the established caller or the anonymous zero value. Like ordinary context operations, it requires a nonnil context.\n\n```go\nfunc NewIAM(principalARN string, source Source, opts ...IAMOption) (Caller, error)\n```\nNewIAM validates and owns an exact root, user, assumed-role session or federated-user ARN. Bare role ARNs and policy patterns are not caller forms. Literal punctuation in a valid IAM user path is preserved without wildcard interpretation. Source must be gateway, custom assertion or verified IAM proof. Errors match [ErrInvalidCaller](#ErrInvalidCaller) and contain no supplied identifiers.\n\n```go\nfunc NewJWT(claims Claims, source Source, opts ...JWTOption) (Caller, error)\n```\nNewJWT validates normalized facts and retains immutable claims. It requires a nonempty issuer and a subject or client\\_id, without conflating those fields. Allowed sources are gateway, locally verified token and custom assertion. It does not verify signatures or expiry. Invalid inputs match [ErrInvalidCaller](#ErrInvalidCaller); a dedicated-scope budget failure additionally matches [ErrClaimsLimit](#ErrClaimsLimit).\n\n```go\nfunc (c Caller) GoString() string\n```\nGoString returns the same sanitized description as String.\n\n```go\nfunc (c Caller) IAM() (IAM, bool)\n```\nIAM reports whether the caller has an IAM identity and returns an immutable view.\n\n```go\nfunc (c Caller) JWT() (JWT, bool)\n```\nJWT reports whether the caller has a JWT identity and returns an immutable view.\n\n```go\nfunc (c Caller) Kind() Kind\n```\nKind returns the identity representation, or [KindAnonymous](#KindAnonymous) for the zero value.\n\n```go\nfunc (c Caller) Source() Source\n```\nSource returns the attributed producer, or [SourceNone](#SourceNone) for an anonymous caller.\n\n```go\nfunc (c Caller) String() string\n```\nString describes kind and source without exposing identifiers or claims.\n\n```go\ntype Claim struct {\n\t// contains filtered or unexported fields\n}\n```\nClaim is an immutable view of a value. The zero value has kind [ClaimInvalid](#ClaimInvalid). Its representation describes the available input, not authentication strength.\n\n```go\nfunc (c Claim) Array() ([]Claim, bool)\n```\nArray reports whether the claim is an array and returns a new slice of views. Replacing elements cannot mutate the original claims.\n\n```go\nfunc (c Claim) Bool() (value, ok bool)\n```\nBool reports whether the claim is a boolean and, if so, returns its value.\n\n```go\nfunc (c Claim) Float64() (float64, bool)\n```\nFloat64 explicitly converts a number to its nearest float64 representation. It reports false for nonnumbers or a conversion error; ordinary rounding is permitted. For supplied floating-point values it returns their stored value. Use NumberText and an exact parser when rounding is unacceptable.\n\n```go\nfunc (c Claim) GoString() string\n```\nGoString returns the same sanitized description as String.\n\n```go\nfunc (c Claim) Kind() ClaimKind\n```\nKind returns the available semantic type.\n\n```go\nfunc (c Claim) NumberText() (string, bool)\n```\nNumberText reports whether an exact numeric representation is available. JSON and json.Number preserve their supplied literal; native integers use decimal text. Supplied float32/float64 and all strings return false, even for integral values. Exactness describes the supplied value, not lost upstream data.\n\n```go\nfunc (c Claim) Object() (Claims, bool)\n```\nObject reports whether the claim is an object and returns an immutable view.\n\n```go\nfunc (c Claim) Representation() Representation\n```\nRepresentation returns the immediate input representation.\n\n```go\nfunc (c Claim) String() string\n```\nString returns a diagnostic description without claim contents.\n\n```go\nfunc (c Claim) Text() (string, bool)\n```\nText reports whether the claim is a string. It never converts other types.\n\n```go\ntype ClaimKind uint8\n```\nClaimKind describes a claim's available semantic type.\n\n```go\nconst (\n\tClaimInvalid ClaimKind = iota\n\tClaimNull\n\tClaimBoolean\n\tClaimString\n\tClaimNumber\n\tClaimArray\n\tClaimObject\n)\n```\nClaim kinds distinguish a missing/zero view from a present null.\n\n```go\nfunc (k ClaimKind) String() string\n```\nString returns a stable lowercase name such as \"number\", or \"ClaimKind(n)\" for an undeclared value.\n\n```go\ntype Claims struct {\n\t// contains filtered or unexported fields\n}\n```\nClaims is an immutable object of named claims. Its zero value is empty. Views may share owned backing storage and may be read concurrently. Use Lookup and its checked accessors to inspect values; diagnostic formatting does not reveal claim names or contents. There is no implicit JSON export.\n\n```go\nfunc NewClaims(values map[string]any, opts ...ClaimsOption) (Claims, error)\n```\nNewClaims validates and owns already decoded values without a JSON round trip. Supported recursive values are nil, bool, string, built-in integers except uintptr, finite float32/float64, json.Number, map\\[string]any, map\\[string]string, \\[]any and \\[]string. Other defined types, pointers, structs and byte slices are rejected without calling user methods. A nil map is an empty object; a typed nil nested map/slice retains its object/array kind. A nil interface is null. Inputs must not change during construction; afterward they may be mutated. Invalid input matches [ErrInvalidClaims](#ErrInvalidClaims); byte exhaustion is a [ClaimsLimitError](#ClaimsLimitError).\n\n```go\nfunc NewTextClaims(values map[string]string, opts ...ClaimsOption) (Claims, error)\n```\nNewTextClaims owns gateway text without parsing embedded JSON or numbers. All values retain [RepresentationGatewayText](#RepresentationGatewayText). Nil means an empty object. Ownership, options and errors follow [NewClaims](#NewClaims).\n\n```go\nfunc ParseClaims(data jsontext.Value, opts ...ClaimsOption) (Claims, error)\n```\nParseClaims validates exactly one JSON object and owns its semantic contents. It preserves numeric token text, but not whitespace, member order or string escape spelling. It rejects duplicate names, invalid UTF-8 and trailing values. Input bytes must not change during construction and are not retained afterward. Invalid input matches [ErrInvalidClaims](#ErrInvalidClaims); byte exhaustion is a [ClaimsLimitError](#ClaimsLimitError). The representation is received JSON, not proof of original JWT fidelity.\n\n```go\nfunc (c Claims) GoString() string\n```\nGoString returns the same sanitized description as String.\n\n```go\nfunc (c Claims) Len() int\n```\nLen returns the number of members in the object.\n\n```go\nfunc (c Claims) Lookup(name string) (Claim, bool)\n```\nLookup reports whether name is present, including a present null value.\n\n```go\nfunc (c Claims) Names() []string\n```\nNames returns an independently owned, sorted slice of member names.\n\n```go\nfunc (c Claims) String() string\n```\nString returns a diagnostic description without claim names or values.\n\n```go\ntype ClaimsLimitError struct {\n\t// contains filtered or unexported fields\n}\n```\nClaimsLimitError describes a claims byte allowance failure. Its diagnostics contain no claim names, values, or underlying parser errors. The zero value has an unspecified maximum of zero.\n\n```go\nfunc (e *ClaimsLimitError) Error() string\n```\nError returns a sanitized description of the failure.\n\n```go\nfunc (e *ClaimsLimitError) Maximum() int64\n```\nMaximum returns the configured allowance in bytes, or zero for a nil error.\n\n```go\nfunc (e *ClaimsLimitError) Unwrap() error\n```\nUnwrap returns [ErrClaimsLimit](#ErrClaimsLimit).\n\n```go\ntype ClaimsOption func(*claimsConfig)\n```\nClaimsOption configures claims construction. A nil option is invalid. Scalar settings apply in order, with the last assignment winning.\n\n```go\nfunc WithClaimsBudget(bytes int) ClaimsOption\n```\nWithClaimsBudget sets the weighted resource allowance in bytes, defaulting to 256 KiB. Constructors reject a final setting outside 1..6 MiB. Each value costs 64 bytes plus object-name, string and exact-number text bytes. [ParseClaims](#ParseClaims) also limits the original JSON byte length to this maximum. The allowance is not an AWS quota or a heap cap. Nesting is limited separately to 64 containers, including the root, and cannot be disabled.\n\n```go\ntype IAM struct {\n\t// contains filtered or unexported fields\n}\n```\nIAM is an immutable view of an exact caller ARN and optional principal ID. Validation does not establish existence, credential possession or permission.\n\n```go\nfunc (i IAM) AccountID() string\n```\nAccountID returns the caller's twelve-digit account ID.\n\n```go\nfunc (i IAM) GoString() string\n```\nGoString returns the same sanitized description as String.\n\n```go\nfunc (i IAM) Partition() string\n```\nPartition returns the exact partition component.\n\n```go\nfunc (i IAM) PrincipalARN() string\n```\nPrincipalARN returns the complete ARN, including any path and session name.\n\n```go\nfunc (i IAM) PrincipalID() (string, bool)\n```\nPrincipalID reports whether an opaque nonempty principal ID was supplied.\n\n```go\nfunc (i IAM) PrincipalType() IAMPrincipalType\n```\nPrincipalType returns the validated caller form.\n\n```go\nfunc (i IAM) Service() string\n```\nService returns iam or sts, or empty for a zero IAM view.\n\n```go\nfunc (i IAM) String() string\n```\nString returns a diagnostic description without identifiers.\n\n```go\ntype IAMOption func(*iamConfig) error\n```\nIAMOption supplies an additional caller fact. Nil and duplicate options fail.\n\n```go\nfunc WithIAMAccountID(account string) IAMOption\n```\nWithIAMAccountID cross-checks an independently supplied caller account against the ARN. Do not pass API Gateway's API-owner requestContext.accountId here.\n\n```go\nfunc WithIAMPrincipalID(id string) IAMOption\n```\nWithIAMPrincipalID preserves a nonempty UTF-8 principal identifier opaquely. It is not parsed into an identity or treated as evidence of authentication.\n\n```go\ntype IAMPrincipalType uint8\n```\nIAMPrincipalType describes the supported request-caller form, not an IAM resource-policy Principal expression.\n\n```go\nconst (\n\tIAMPrincipalUnknown IAMPrincipalType = iota\n\tIAMPrincipalRoot\n\tIAMPrincipalUser\n\tIAMPrincipalAssumedRole\n\tIAMPrincipalFederatedUser\n)\n```\nSupported IAM principal forms preserve session identities.\n\n```go\nfunc (t IAMPrincipalType) String() string\n```\nString returns a stable lowercase name such as \"assumed\\_role\", or \"IAMPrincipalType(n)\" for an undeclared value.\n\n```go\ntype JWT struct {\n\t// contains filtered or unexported fields\n}\n```\nJWT is an immutable view of normalized JWT facts and their owned claims. It makes no assertions about token validity, flow, expiry or permissions. Its zero value contains no identity facts.\n\n```go\nfunc (j JWT) Audience() ([]string, bool)\n```\nAudience returns a copied sorted set and reports whether its meaning is known. Gateway string audiences remain available in Claims but are not split or parsed.\n\n```go\nfunc (j JWT) Claims() Claims\n```\nClaims returns an immutable view of the original supplied claims.\n\n```go\nfunc (j JWT) ClientID() (string, bool)\n```\nClientID reports whether a nonempty client\\_id was supplied.\n\n```go\nfunc (j JWT) CognitoGroups() ([]string, bool)\n```\nCognitoGroups returns a copied sorted set of cognito:groups when interpretable. It does not promote arbitrary groups or roles claims into Cognito groups.\n\n```go\nfunc (j JWT) GoString() string\n```\nGoString returns the same sanitized description as String.\n\n```go\nfunc (j JWT) Issuer() string\n```\nIssuer returns the exact issuer, or empty for a zero JWT.\n\n```go\nfunc (j JWT) Scopes() ([]string, bool)\n```\nScopes returns a copied sorted set, distinguishing known empty from unavailable.\n\n```go\nfunc (j JWT) String() string\n```\nString returns a diagnostic description without identity facts.\n\n```go\nfunc (j JWT) Subject() (string, bool)\n```\nSubject reports whether a nonempty subject was supplied.\n\n```go\nfunc (j JWT) TokenUse() (string, bool)\n```\nTokenUse reports whether a nonempty token\\_use was supplied.\n\n```go\ntype JWTOption func(*jwtConfig) error\n```\nJWTOption supplies a separate assertion. Nil or duplicate options are invalid.\n\n```go\nfunc WithGatewayScopes(scopes []string) JWTOption\n```\nWithGatewayScopes supplies API Gateway's dedicated scopes collection. It is valid only with [SourceGatewayAssertion](#SourceGatewayAssertion). Nil means unavailable; a nonnil empty slice means known empty. Interpretable claim scopes must agree as exact sets. The supplied collection consumes the claims' remaining weighted budget before copying, even when its values duplicate a claim. Do not mutate it during [NewJWT](#NewJWT).\n\n```go\ntype Kind uint8\n```\nKind identifies the caller's mutually exclusive identity representation.\n\n```go\nconst (\n\tKindAnonymous Kind = iota\n\tKindJWT\n\tKindIAM\n)\n```\nCaller kinds include an anonymous zero value.\n\n```go\nfunc (k Kind) String() string\n```\nString returns a stable lowercase name such as \"jwt\", or \"Kind(n)\" for an undeclared value.\n\n```go\ntype Representation uint8\n```\nRepresentation describes the immediate input representation, not its original token encoding or whether an authenticating producer verified it.\n\n```go\nconst (\n\tRepresentationUnknown Representation = iota\n\tRepresentationJSON\n\tRepresentationDecoded\n\tRepresentationGatewayText\n)\n```\nClaim representations retain the distinction between JSON, decoded values, and gateway text that may have lost its original JSON type.\n\n```go\nfunc (r Representation) String() string\n```\nString returns a stable lowercase name such as \"gateway\\_text\", or \"Representation(n)\" for an undeclared value.\n\n```go\ntype Source uint8\n```\nSource records the producer's assertion, not cryptographic evidence. Trusted application code must authenticate inputs before attributing a source.\n\n```go\nconst (\n\tSourceNone Source = iota\n\tSourceGatewayAssertion\n\tSourceLocallyVerifiedToken\n\tSourceCustomAssertion\n\tSourceVerifiedIAMProof\n)\n```\nSources distinguish gateway assertions, verified tokens, custom mappings and IAM proofs verified online by STS. None is reserved for anonymous callers.\n\n```go\nfunc (s Source) String() string\n```\nString returns a stable lowercase name such as \"verified\\_iam\\_proof\", or \"Source(n)\" for an undeclared value.\n\n","path":"github.com/asteroid-computing/go-lambda-edge/identity","name":"identity","synopsis":"Package identity provides immutable callers, owned claims and context transport.","isRedistributable":true}
