Documentation
¶
Overview ¶
SDK-side error type.
Mirrors the NAULIX API error envelope:
{
"detail": "...",
"error": {
"code": "voyage_invalid_port_locode",
"message": "...",
"type": "invalid_request_error",
"param": "origin_port_locode",
"doc_url": "https://docs.naulix.io/errors/voyage_invalid_port_locode",
"context": {...}
}
}
Consumers branch on Err.Code — never on Err.Message, which is human text and can change at any time without an API version bump.
Internal HTTP transport — auth, idempotency-key, retry, error mapping.
Single source of truth for "how the SDK talks to the API". The resource sub-clients compose against this — they don't know about net/http or retry semantics.
Package naulix is the official Go SDK for the NAULIX API — an XRPL-native staged-escrow trade settlement platform.
Quick start:
c, err := naulix.NewClient(naulix.ClientOptions{APIKey: "sk_test_..."})
if err != nil { ... }
voyage, err := c.Voyages.Create(ctx, naulix.VoyageCreateParams{
OriginPortLOCODE: "IEDUB",
DestinationPortLOCODE: "DEHAM",
MMSI: "636019825",
AmountRLUSD: 10_000,
SellerXRPLAddress: "rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
BuyerXRPLAddress: "rUgw8e2x8wMFeB8N3W2mJj6935wB5wimsm",
})
Environments: the key prefix decides — sk_test_* → sandbox, sk_live_* → production. No separate base URL needed.
Errors: every API failure returns *naulix.Error. Branch on Err.Code (stable) rather than Err.Message (human text).
Index ¶
- Constants
- func VerifyWebhookSignature(secret, signatureHeader, body string, opts WebhookOptions) bool
- type APIKeyCreateParams
- type APIKeys
- func (a *APIKeys) Create(ctx context.Context, p APIKeyCreateParams) (map[string]any, error)
- func (a *APIKeys) List(ctx context.Context) ([]map[string]any, error)
- func (a *APIKeys) Revoke(ctx context.Context, keyID int64) (map[string]any, error)
- func (a *APIKeys) Rotate(ctx context.Context, keyID int64) (map[string]any, error)
- type Client
- type ClientOptions
- type Error
- type EscrowCreateParams
- type EscrowListOptions
- type Escrows
- func (e *Escrows) Cancel(ctx context.Context, escrowID int64) (map[string]any, error)
- func (e *Escrows) Create(ctx context.Context, p EscrowCreateParams) (map[string]any, error)
- func (e *Escrows) Finish(ctx context.Context, escrowID int64, fulfillmentHex string) (map[string]any, error)
- func (e *Escrows) List(ctx context.Context, opts EscrowListOptions) ([]map[string]any, error)
- func (e *Escrows) Retrieve(ctx context.Context, escrowID int64) (map[string]any, error)
- func (e *Escrows) RevealFulfillment(ctx context.Context, escrowID int64) (map[string]any, error)
- type PaymentSendParams
- type Payments
- type VoyageCreateParams
- type Voyages
- func (v *Voyages) Create(ctx context.Context, p VoyageCreateParams) (map[string]any, error)
- func (v *Voyages) Events(ctx context.Context, voyageID int64) ([]map[string]any, error)
- func (v *Voyages) List(ctx context.Context) ([]map[string]any, error)
- func (v *Voyages) Retrieve(ctx context.Context, voyageID int64) (map[string]any, error)
- type WebhookEndpointCreateParams
- type WebhookEndpoints
- func (w *WebhookEndpoints) Create(ctx context.Context, p WebhookEndpointCreateParams) (map[string]any, error)
- func (w *WebhookEndpoints) Deliveries(ctx context.Context, endpointID int64, limit int) ([]map[string]any, error)
- func (w *WebhookEndpoints) Disable(ctx context.Context, endpointID int64) (map[string]any, error)
- func (w *WebhookEndpoints) List(ctx context.Context) ([]map[string]any, error)
- func (w *WebhookEndpoints) Retrieve(ctx context.Context, endpointID int64) (map[string]any, error)
- func (w *WebhookEndpoints) RotateSecret(ctx context.Context, endpointID int64) (map[string]any, error)
- func (w *WebhookEndpoints) Test(ctx context.Context, endpointID int64) (map[string]any, error)
- type WebhookOptions
Constants ¶
const Version = "0.1.0"
Version of this SDK. Sent as part of the User-Agent.
Variables ¶
This section is empty.
Functions ¶
func VerifyWebhookSignature ¶
func VerifyWebhookSignature(secret, signatureHeader, body string, opts WebhookOptions) bool
VerifyWebhookSignature verifies a NAULIX webhook signature.
Use this in your webhook handler regardless of whether you also use the Client for outbound API calls — it's standalone.
func handle(w http.ResponseWriter, r *http.Request) {
raw, _ := io.ReadAll(r.Body)
sig := r.Header.Get("Naulix-Signature")
if !naulix.VerifyWebhookSignature(secret, sig, string(raw), naulix.WebhookOptions{}) {
w.WriteHeader(http.StatusUnauthorized)
return
}
...
}
Verification uses HMAC-SHA-256 with a constant-time compare. Rejects timestamps more than ToleranceSec away from now (default 300).
Types ¶
type APIKeyCreateParams ¶
type APIKeyCreateParams struct {
Name string
Mode string // "test" (default) | "live"
Tier string // "starter" (default)
Organisation string // optional
ContactEmail string // optional
}
APIKeyCreateParams is the POST /v1/api-keys body.
type APIKeys ¶
type APIKeys struct {
// contains filtered or unexported fields
}
APIKeys manages NAULIX-issued sk_test_* / sk_live_* keys.
func (*APIKeys) Create ¶
Create mints a new API key. The returned object includes the raw key string ONCE — store it immediately; subsequent calls only return the fingerprint.
type Client ¶
type Client struct {
Voyages *Voyages
APIKeys *APIKeys
Payments *Payments
Escrows *Escrows
WebhookEndpoints *WebhookEndpoints
// contains filtered or unexported fields
}
Client is the entry point. Construct with NewClient and then access resources via the exported sub-client fields.
func NewClient ¶
func NewClient(opts ClientOptions) (*Client, error)
NewClient builds a Client with the supplied options.
type ClientOptions ¶
type ClientOptions struct {
// APIKey is the secret key (sk_test_* or sk_live_*). Required.
APIKey string
// BaseURL overrides the default https://api.naulix.io. Useful for
// local development against a self-hosted NAULIX.
BaseURL string
// Timeout caps the per-request total duration. Default 30s.
Timeout time.Duration
// MaxRetries caps the retry budget. 0 = full schedule (3 retries
// on 5xx + network errors). Negative is treated as 0.
MaxRetries int
// HTTPClient lets callers inject their own http.Client — e.g. with
// a custom RoundTripper for telemetry. If nil, the SDK builds one
// with the configured Timeout.
HTTPClient *http.Client
}
ClientOptions controls how the client talks to the NAULIX API.
type Error ¶
type Error struct {
// Code is the stable machine-readable code (see docs/error-codes.md).
Code string
// Type is the broad category — "invalid_request_error",
// "authentication_error", "compliance_error", etc.
Type string
// Message is the human-readable description.
Message string
// StatusCode is the HTTP status the API returned.
StatusCode int
// Param is the request field that caused the error, if applicable.
Param string
// DocURL links to the remediation page for this code.
DocURL string
// Context is optional structured extra context.
Context map[string]any
// Raw is the full parsed response body.
Raw map[string]any
}
Error is the typed error returned by every API call that fails.
type EscrowCreateParams ¶
type EscrowCreateParams struct {
Amount float64
SenderAddress string
ReceiverAddress string
Currency string // "" → RLUSD
FinishAfter string // ISO-8601 UTC, e.g. "2026-12-01T00:00:00Z"
CancelAfter string // ISO-8601 UTC
UseCryptoCondition bool
Description string
Metadata map[string]any
IdempotencyKey string
}
EscrowCreateParams maps to POST /v1/escrows.
type EscrowListOptions ¶
EscrowListOptions controls GET /v1/escrows.
type Escrows ¶
type Escrows struct {
// contains filtered or unexported fields
}
Escrows is the generic XRPL escrow primitive — vesting, marketplace, web3-service-escrow. Three release shapes:
- Time-locked: set FinishAfter; release after that timestamp.
- Crypto-condition: set UseCryptoCondition; fulfillment returned ONCE.
- Both: AND semantics — XRPL native.
func (*Escrows) Cancel ¶
Cancel releases the funds back to the sender (after CancelAfter has elapsed, on chain).
func (*Escrows) Finish ¶
func (e *Escrows) Finish(ctx context.Context, escrowID int64, fulfillmentHex string) (map[string]any, error)
Finish releases the escrow. For crypto-condition escrows pass fulfillmentHex; for time-locked-only escrows pass an empty string.
type PaymentSendParams ¶
type PaymentSendParams struct {
ToAddress string
RLUSDAmount float64
Memo string // optional, written as the XRPL transaction memo
Reference string // optional internal/customer reference
IdempotencyKey string // optional client-supplied idempotency key
}
PaymentSendParams maps to POST /v1/payments/send.
type Payments ¶
type Payments struct {
// contains filtered or unexported fields
}
Payments is the generic P2P send primitive — closes the remittance use case without going through the voyage / staged-escrow surface.
resp, err := c.Payments.Send(ctx, naulix.PaymentSendParams{
ToAddress: "rABC...",
RLUSDAmount: 100,
Memo: "invoice-42",
})
type VoyageCreateParams ¶
type VoyageCreateParams struct {
OriginPortLOCODE string
DestinationPortLOCODE string
MMSI string
AmountRLUSD float64
SellerXRPLAddress string
BuyerXRPLAddress string
Currency string // "" → RLUSD
WaypointRadiusNM float64 // 0 → 5.0 nautical miles
IMO string // optional
VesselName string // optional
Notes string // optional
IdempotencyKey string // optional client-supplied
}
VoyageCreateParams maps to the POST /v1/voyages request body. Fields follow Go naming (CamelCase) and the SDK translates to the API's snake_case on the wire.
type Voyages ¶
type Voyages struct {
// contains filtered or unexported fields
}
Voyages is the resource client for the AIS-tracked staged-escrow voyages pilot.
func (*Voyages) Create ¶
Create kicks off a voyage. Returns the partial voyage with status `escrow_minting`; poll Retrieve until status flips to `escrow_locked`.
type WebhookEndpointCreateParams ¶
type WebhookEndpointCreateParams struct {
URL string
Events []string
Description string
IdempotencyKey string
}
WebhookEndpointCreateParams maps to POST /v1/webhook-endpoints.
type WebhookEndpoints ¶
type WebhookEndpoints struct {
// contains filtered or unexported fields
}
WebhookEndpoints manages outbound webhook destinations + their delivery history.
func (*WebhookEndpoints) Create ¶
func (w *WebhookEndpoints) Create(ctx context.Context, p WebhookEndpointCreateParams) (map[string]any, error)
Create registers a new endpoint. The response includes the signing secret (whsec_*) ONCE — store it immediately; subsequent reads only return the fingerprint.
func (*WebhookEndpoints) Deliveries ¶
func (w *WebhookEndpoints) Deliveries(ctx context.Context, endpointID int64, limit int) ([]map[string]any, error)
Deliveries returns the delivery history (success + failure) for an endpoint. Default limit 50; pass non-zero to override.
func (*WebhookEndpoints) Disable ¶
Disable turns off delivery to this endpoint. The row is kept for audit; future events stop firing.
func (*WebhookEndpoints) RotateSecret ¶
func (w *WebhookEndpoints) RotateSecret(ctx context.Context, endpointID int64) (map[string]any, error)
RotateSecret invalidates the current whsec_* and issues a new one.
type WebhookOptions ¶
type WebhookOptions struct {
// ToleranceSec is the maximum allowed clock skew vs the signature
// timestamp. 0 → 300 (5 minutes). Wider values weaken replay
// protection — only loosen if your infra has known clock drift.
ToleranceSec int64
// NowUnix overrides time.Now().Unix() — used by tests.
NowUnix int64
}
WebhookOptions tunes VerifyWebhookSignature. The zero value works.