Documentation
¶
Overview ¶
Package service implements signing requests, the ceremony state machine, events, webhooks and artifacts on any storage.Store.
Index ¶
- Constants
- func ConsentText(version, locale string) string
- func RequestID(ctx context.Context) string
- func WithRequestID(ctx context.Context, id string) context.Context
- type ApplicationSettings
- type Ceremony
- type Config
- type Credentials
- type Error
- type Service
- func (s *Service) Applications(ctx context.Context) ([]storage.Application, error)
- func (s *Service) Artifact(ctx context.Context, app, id, name string) ([]byte, error)
- func (s *Service) Authenticate(ctx context.Context, apiKey string) (string, error)
- func (s *Service) Ceremony(ctx context.Context, secret string) (*Ceremony, error)
- func (s *Service) CreateApplication(ctx context.Context, a ApplicationSettings) (*Credentials, error)
- func (s *Service) CreateDocument(ctx context.Context, app string, b []byte, expectedSHA256 string) (*client.Document, error)
- func (s *Service) CreateRequest(ctx context.Context, app string, in *client.CreateSigningRequest) (*client.SigningRequest, error)
- func (s *Service) CreateSession(ctx context.Context, app, id, ref string, assertion json.RawMessage, ...) (*client.Session, error)
- func (s *Service) DeliverWebhooks(ctx context.Context) error
- func (s *Service) Document(ctx context.Context, secret, ip, ua string) ([]byte, error)
- func (s *Service) ExpireDue(ctx context.Context) error
- func (s *Service) FailedDeliveries(ctx context.Context, app string) ([]client.WebhookDelivery, error)
- func (s *Service) Finalize(ctx context.Context, id string) error
- func (s *Service) GetRequest(ctx context.Context, app, id string) (*client.SigningRequest, error)
- func (s *Service) IdempotencyBegin(ctx context.Context, app, key string, reqHash []byte) (*Stored, error)
- func (s *Service) IdempotencyEnd(ctx context.Context, app, key string, status int, body []byte) error
- func (s *Service) Issue(ctx context.Context, app, id string) (*client.SigningRequest, error)
- func (s *Service) Keys() *signer.Keys
- func (s *Service) LinkNonce(tok string) string
- func (s *Service) ListRequests(ctx context.Context, app string, since time.Time, cursor string) (*client.SigningRequestList, error)
- func (s *Service) Logger() *slog.Logger
- func (s *Service) OpenSession(ctx context.Context, tok, ip, ua string) (string, error)
- func (s *Service) PeekLink(ctx context.Context, tok string) error
- func (s *Service) Report(ctx context.Context, route string, err error) *Error
- func (s *Service) Revoke(ctx context.Context, app, id, reason string) (*client.SigningRequest, error)
- func (s *Service) RotateAPIKey(ctx context.Context, id string) (*Credentials, error)
- func (s *Service) RotateWebhookSecret(ctx context.Context, id string, overlap time.Duration) (*Credentials, error)
- func (s *Service) Run(ctx context.Context, every time.Duration)
- func (s *Service) SendCode(ctx context.Context, secret string) error
- func (s *Service) Submit(ctx context.Context, secret string, sub *Submission) error
- func (s *Service) Tick(ctx context.Context)
- func (s *Service) UpdateApplication(ctx context.Context, id string, edit func(*ApplicationSettings)) error
- func (s *Service) VerifyCode(ctx context.Context, secret, code string) error
- type Stored
- type Submission
Constants ¶
const ( // LinkTTL is how long a signing link can be opened after it is created. LinkTTL = 10 * time.Minute // CeremonyTTL is how long an opened ceremony session stays valid. CeremonyTTL = 30 * time.Minute // CodeTTL is how long an emailed code can be entered. CodeTTL = 10 * time.Minute // CodeAttempts is the number of guesses allowed per code. CodeAttempts = 5 // CodeSends is the number of codes that can be sent per session. CodeSends = 3 // MaxSigners is the largest number of signers on one request. MaxSigners = 10 // WebhookWindow is how long a webhook delivery is retried before it // is marked failed. WebhookWindow = 72 * time.Hour // AssuranceCode is the assurance level that verifies the signer's email // address with a one-time code. AssuranceCode = "email_code" )
const CurrentConsent = "v1"
CurrentConsent is the default consent text version.
Variables ¶
This section is empty.
Functions ¶
func ConsentText ¶
ConsentText returns the published consent text.
Types ¶
type ApplicationSettings ¶
type ApplicationSettings struct {
Name string
BrandColor string
WebhookURL string
AllowedOrigins []string
}
ApplicationSettings are the editable settings of an application.
type Ceremony ¶
type Ceremony struct {
Nonce string
AppName string
BrandColor string
Locale string
SignerName string
MaskedEmail string
RequestID string
SignerState string
// Outcome is "signed" or "declined" once the session is finished.
Outcome string
// ReturnURL is where to send the signer after the outcome.
ReturnURL string
// Challenge is none, pending, passed, locked or expired.
Challenge string
CodeSendsLeft int
AttemptsLeft int
DocumentSHA256 string
Pages int
ConsentVersion string
ConsentText string
// Open is true when the signer may act now.
Open bool
// Closed explains why the signer cannot act, if Open is false.
Closed string
}
Ceremony is what the signing pages render.
type Config ¶
type Config struct {
// BaseURL is the public origin used in signing links.
BaseURL string
// Secret keys the HMAC that protects emailed codes.
Secret []byte
// Keys are the seal and evidence signing keys.
Keys *signer.Keys
// TSAURL is the RFC 3161 timestamp authority.
TSAURL string
// Blobs holds document and artifact bytes.
Blobs blob.Store
// Mailer sends signing codes.
Mailer mail.Mailer
// PDFLimits bounds uploaded documents; zero uses pdf.DefaultLimits.
PDFLimits pdf.Limits
// HTTP is the client for timestamp requests; zero uses a client with a
// 15 second timeout.
HTTP *http.Client
// Logger receives service logs; zero uses slog.Default.
Logger *slog.Logger
// Development lets webhooks reach loopback and link-local addresses.
// Production refuses them at dial time.
Development bool
}
Config holds the service's dependencies and settings.
type Credentials ¶
type Credentials struct {
ApplicationID string `json:"application_id"`
APIKey string `json:"api_key,omitempty"`
WebhookSecret string `json:"webhook_secret,omitempty"`
}
Credentials are the secrets of an application. They are returned once and stored only as hashes (API key) or for signing (webhook secret).
type Error ¶
Error is an API error with a stable code.
type Service ¶
type Service struct {
// Now is the clock.
Now func() time.Time
// contains filtered or unexported fields
}
Service implements the signing workflow on a storage.Store.
func (*Service) Applications ¶
Applications lists all applications.
func (*Service) Authenticate ¶
Authenticate resolves a bearer API key to its application.
func (*Service) CreateApplication ¶
func (s *Service) CreateApplication(ctx context.Context, a ApplicationSettings) (*Credentials, error)
CreateApplication registers an API client and returns its secrets once.
func (*Service) CreateDocument ¶
func (s *Service) CreateDocument(ctx context.Context, app string, b []byte, expectedSHA256 string) (*client.Document, error)
CreateDocument stores an immutable PDF after checking its digest and limits.
func (*Service) CreateRequest ¶
func (s *Service) CreateRequest(ctx context.Context, app string, in *client.CreateSigningRequest) (*client.SigningRequest, error)
CreateRequest stores a draft signing request. It fills defaults into in.
func (*Service) CreateSession ¶
func (s *Service) CreateSession(ctx context.Context, app, id, ref string, assertion json.RawMessage, returnURL string) (*client.Session, error)
CreateSession returns a one-use link for an authenticated signer.
func (*Service) DeliverWebhooks ¶
DeliverWebhooks sends due deliveries, up to eight at a time. Deliveries of one request go out in sequence order because only the first pending delivery of a request is due. request.completed waits until the artifacts exist. Each delivery is claimed with a lease before sending, so instances never send it twice at once.
func (*Service) Document ¶
Document returns the exact stored PDF for review after the code passed. Serving it records signer.viewed the first time, which signing requires.
func (*Service) ExpireDue ¶
ExpireDue moves open requests past expires_at to expired. A request that fails is logged and retried later with a growing delay; the others are still processed.
func (*Service) FailedDeliveries ¶
func (s *Service) FailedDeliveries(ctx context.Context, app string) ([]client.WebhookDelivery, error)
FailedDeliveries lists webhook deliveries that exhausted their retries.
func (*Service) Finalize ¶
Finalize produces final.pdf (summary page and seal in one incremental update) and evidence.zip for a completed request. It is safe to call repeatedly and concurrently: the first stored artifacts win.
func (*Service) GetRequest ¶
GetRequest returns the application's signing request id.
func (*Service) IdempotencyBegin ¶
func (s *Service) IdempotencyBegin(ctx context.Context, app, key string, reqHash []byte) (*Stored, error)
IdempotencyBegin claims key for this request. It returns the stored response when the same request already completed.
func (*Service) IdempotencyEnd ¶
func (s *Service) IdempotencyEnd(ctx context.Context, app, key string, status int, body []byte) error
IdempotencyEnd records the response, or releases the key after a server error or a 409 conflict so the client can retry. It completes even if the client has already gone away, so a key is never left in progress.
func (*Service) LinkNonce ¶
LinkNonce returns the form nonce that protects consuming the link token tok.
func (*Service) ListRequests ¶
func (s *Service) ListRequests(ctx context.Context, app string, since time.Time, cursor string) (*client.SigningRequestList, error)
ListRequests returns requests updated at or after since, ordered by (updated_at, id), with an opaque cursor.
func (*Service) OpenSession ¶
OpenSession consumes a session link and returns the browser secret that carries the ceremony from here on.
func (*Service) PeekLink ¶
PeekLink reports whether the link token tok can still be opened, without consuming it.
func (*Service) Report ¶
Report maps err like AsError and logs it server-side, with the request id in ctx and the route, when it is not a deliberate service error.
func (*Service) Revoke ¶
func (s *Service) Revoke(ctx context.Context, app, id, reason string) (*client.SigningRequest, error)
Revoke ends an open request.
func (*Service) RotateAPIKey ¶
RotateAPIKey revokes the application's API keys and returns a new one.
func (*Service) RotateWebhookSecret ¶
func (s *Service) RotateWebhookSecret(ctx context.Context, id string, overlap time.Duration) (*Credentials, error)
RotateWebhookSecret adds a new webhook secret. Current secrets keep signing deliveries for overlap, so receivers can switch without gaps.
func (*Service) Run ¶
Run executes the background jobs every interval until ctx ends. Expiry, sealing and webhook delivery run independently, so a slow job does not delay the others.
func (*Service) Submit ¶
Submit signs or declines in one transaction that rechecks every precondition and writes the session, the challenge and the request only if none of them changed since they were read. A retry with the same session returns the first outcome.
func (*Service) UpdateApplication ¶
func (s *Service) UpdateApplication(ctx context.Context, id string, edit func(*ApplicationSettings)) error
UpdateApplication changes an application's settings; edit receives the current settings.
type Submission ¶
type Submission struct {
// Nonce is the form nonce of the session.
Nonce string
// Decline declines instead of signing.
Decline bool
// Consent is whether the signer ticked the consent box.
Consent bool
// DocumentSHA256 is the digest of the document the signer reviewed.
DocumentSHA256 string
// Reason is the optional decline reason.
Reason string
// IP and UserAgent are recorded in the signing event.
IP, UserAgent string
}
Submission is a signer's form submission with the request metadata that is recorded as evidence.