@predictasiax/api 2.5.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -329,17 +329,26 @@ interface RequestOptions {
329
329
  * - `Cache-Control: no-store` on every request — prevents intermediary caches
330
330
  * retaining authenticated responses
331
331
  * - `Referrer-Policy` compatible via `no-referrer` header
332
- * - HMAC clock skew adjustment via client option
332
+ * - HMAC (PAX-* headers) re-signed per attempt; clock offset via client option
333
333
  * - CR/LF injection on user headers rejected in mergeHeaders
334
334
  * - `redirect: manual` — refuses server-initiated redirects that could
335
335
  * downgrade to plaintext or cross-origin
336
336
  */
337
337
 
338
+ declare const DEFAULT_BASE_URL = "https://api.predictasiax.com";
339
+ /** Strip a trailing slash and a trailing `/v1` so paths never double to /v1/v1. */
340
+ declare function normalizeBaseUrl(url: string): string;
338
341
  interface HttpClientOptions {
342
+ /** `sk_live_...` key. Alone: sent as `Authorization: Bearer`. With `keyId`: HMAC signing key. */
339
343
  apiKey?: string;
344
+ /** Key id (`api_...`). Enables HMAC request signing with PAX-* headers. */
345
+ keyId?: string;
346
+ bearerToken?: string;
347
+ /** @deprecated Not part of the PAX API; passing it throws. Use `keyId` + `apiKey`. */
340
348
  secret?: string;
349
+ /** @deprecated Not part of the PAX API; passing it throws. Use `keyId` + `apiKey`. */
341
350
  passphrase?: string;
342
- bearerToken?: string;
351
+ /** Accepted for compatibility; every env uses the same host. */
343
352
  env?: Env;
344
353
  baseUrl?: string;
345
354
  timeoutMs?: number;
@@ -357,7 +366,7 @@ interface HttpClientOptions {
357
366
  */
358
367
  maxResponseBytes?: number;
359
368
  /**
360
- * Auto-generate `Idempotency-Key` on POST/PUT/PATCH when caller does not
369
+ * Auto-generate `Idempotency-Key` on POST/PUT/PATCH/DELETE when caller does not
361
370
  * provide one. Same key is reused across all retries of a single call.
362
371
  * Default: `true`. Set to `false` to require callers to always provide
363
372
  * their own key.
@@ -366,7 +375,7 @@ interface HttpClientOptions {
366
375
  /**
367
376
  * Milliseconds added to `Date.now()` when constructing HMAC timestamps.
368
377
  * Use to compensate for a locally-drifted clock (e.g. from `serverTime - Date.now()`).
369
- * Server accepts ±30 s skew, so a value beyond that will fail regardless.
378
+ * The gateway accepts ±300 s.
370
379
  */
371
380
  clockOffsetMs?: number;
372
381
  /**
@@ -385,9 +394,10 @@ interface RawResponse<T> {
385
394
  declare class HttpClient {
386
395
  readonly baseUrl: string;
387
396
  readonly userAgent: string;
397
+ /** "hmac" | "api_key" | "bearer" | "none" */
398
+ get authMode(): string;
388
399
  private readonly apiKey?;
389
- private readonly secret?;
390
- private readonly passphrase?;
400
+ private readonly keyId?;
391
401
  private readonly bearerToken?;
392
402
  private readonly timeoutMs;
393
403
  private readonly maxRetries;
@@ -562,29 +572,24 @@ declare abstract class Resource {
562
572
  }
563
573
 
564
574
  /**
565
- * Account resource — balances, positions, your trade history.
575
+ * Account resource (scope portfolio:read).
566
576
  *
567
- * GET /v1/account retrieve()
568
- * GET /v1/account/positions positions()
569
- * GET /v1/account/trades trades()
577
+ * GET /v1/balance balance()
578
+ * GET /v1/portfolio portfolio() positions + balances
579
+ * GET /v1/positions positions()
570
580
  */
571
581
 
572
- interface ListTradesParams {
573
- cursor?: string;
574
- limit?: number;
575
- marketId?: string;
576
- }
577
582
  declare class AccountResource extends Resource {
578
- retrieve(opts?: RequestOptions): APIPromise<Account>;
579
- positions(opts?: RequestOptions): APIPromise<Position[]>;
580
- trades(params?: ListTradesParams, opts?: RequestOptions): PagePromise<Trade>;
583
+ balance(opts?: RequestOptions): APIPromise<unknown>;
584
+ /** @deprecated Use balance(). Kept as an alias. */
585
+ retrieve(opts?: RequestOptions): APIPromise<unknown>;
586
+ portfolio(opts?: RequestOptions): APIPromise<unknown>;
587
+ positions(opts?: RequestOptions): APIPromise<unknown>;
581
588
  }
582
589
 
583
590
  /**
584
- * Audit resource — public no-auth verifier over PAX's hash-chained event
585
- * log + Merkle-batched anchor chain. Any third party (auditor, investor,
586
- * external verifier) can independently reconstruct + verify without trusting
587
- * PAX at all.
591
+ * Audit resource — public, no-auth access to the hash-chained event log and
592
+ * its Merkle batches, plus offline verifiers.
588
593
  *
589
594
  * GET /v1/audit/status status()
590
595
  * GET /v1/audit/batches/latest latestBatch()
@@ -592,44 +597,67 @@ declare class AccountResource extends Resource {
592
597
  * GET /v1/audit/events/{seq} getEvent(seq)
593
598
  * GET /v1/audit/proof/{seq} getProof(seq)
594
599
  * GET /v1/audit/anchor/{num} getAnchor(num)
600
+ * (client-side) verify(seq), verifyEvent(), verifyEventHash(), verifyProof()
595
601
  *
596
- * v2.2+ — Public Merkle audit chain surface. Algorithm is sorted-pair SHA-256
597
- * over the raw 32-byte digests (OpenZeppelin-style pair ordering, hashed with
598
- * SHA-256 — NOT keccak256). On-chain, verify with a SHA-256 sorted-pair verifier
599
- * (e.g. sha256(abi.encodePacked(a, b))); stock OZ `MerkleProof.verify` hashes
600
- * with keccak256 and will not match these roots.
602
+ * Checks:
603
+ * 1. event_hash == sha256_hex(utf8(prev_event_hash + canonical)); `canonical`
604
+ * is returned verbatim by getEvent().
605
+ * 2. Merkle inclusion: leaf = event_hash; each level is SHA-256 over the
606
+ * sorted pair of RAW 32-byte digests (not keccak256, not hex strings); an
607
+ * odd level duplicates its last node.
608
+ * 3. Proof length: a batch of n leaves needs exactly expectedProofLength(n)
609
+ * siblings. Any other length is rejected, so an interior node cannot be
610
+ * presented as a leaf (second-preimage).
611
+ *
612
+ * A root read from this API proves internal consistency only; compare it with
613
+ * the batch's external anchor (getAnchor) for an independent check.
601
614
  */
602
615
 
603
616
  interface AuditStatus {
604
617
  events: {
605
618
  total: number;
606
- first_at: string;
607
- last_at: string;
619
+ first_at_ms: number;
620
+ last_at_ms: number;
608
621
  };
609
622
  batches: {
610
623
  total: number;
611
624
  anchored: number;
612
625
  };
613
626
  latest_batch: AuditBatch | null;
614
- latest_anchor: Pick<AuditBatch, "batch_num" | "anchored_at" | "anchor_target" | "anchor_ref"> | null;
627
+ latest_anchor: {
628
+ batch_num: number;
629
+ anchored_at_ms: number | null;
630
+ anchor_target: string | null;
631
+ anchor_ref: string | null;
632
+ } | null;
615
633
  anchor_lag_seconds: number | null;
616
634
  publisher_mode: string;
617
635
  verify_docs: string;
618
636
  }
619
637
  interface AuditBatch {
620
638
  batch_num: number;
621
- batch_id: string;
639
+ batch_id?: string;
622
640
  first_seq: number;
623
641
  last_seq: number;
624
642
  event_count: number;
625
643
  merkle_root: string;
626
644
  prev_batch_hash: string | null;
627
- created_at: string;
628
- anchored_at: string | null;
645
+ created_at_ms: number;
646
+ anchored_at_ms: number | null;
647
+ anchor_target: string | null;
648
+ anchor_ref?: string | null;
649
+ anchor_proof?: Record<string, unknown> | null;
650
+ anchor_public_url?: string | null;
651
+ }
652
+ /** GET /v1/audit/anchor/{num} */
653
+ interface AuditAnchor {
654
+ batch_num: number;
655
+ merkle_root: string;
629
656
  anchor_target: string | null;
630
657
  anchor_ref: string | null;
658
+ anchored_at_ms: number | null;
631
659
  anchor_proof: Record<string, unknown> | null;
632
- anchor_public_url?: string | null;
660
+ anchor_public_url: string | null;
633
661
  }
634
662
  interface AuditEvent {
635
663
  event_id: string;
@@ -637,38 +665,83 @@ interface AuditEvent {
637
665
  event_type: string;
638
666
  prev_event_hash: string;
639
667
  event_hash: string;
668
+ /** Display copy of the payload; numbers may be stringified. Hash `canonical`, not this. */
640
669
  payload: unknown;
641
670
  idempotency_key: string;
642
- created_at: string;
671
+ created_at_ms: number;
643
672
  emitter: string;
644
673
  schema_version: number;
645
674
  batch_id: string | null;
646
675
  batch_seq: number | null;
676
+ /** The exact string that was hashed: event_hash = sha256(prev_event_hash + canonical). */
677
+ canonical: string;
678
+ hash_recipe?: string;
647
679
  }
648
680
  interface MerkleProof {
649
681
  seq: number;
650
682
  event_hash: string;
651
- batch: Pick<AuditBatch, "batch_num" | "merkle_root" | "first_seq" | "last_seq" | "anchored_at" | "anchor_target" | "anchor_ref">;
683
+ batch: {
684
+ batch_num: number;
685
+ merkle_root: string;
686
+ first_seq: number;
687
+ last_seq: number;
688
+ anchored_at_ms?: number | null;
689
+ anchor_target?: string | null;
690
+ anchor_public_url?: string | null;
691
+ };
652
692
  merkle_proof: string[];
653
- verify_algo: string;
654
- verify_snippet: string;
693
+ leaf_index?: number;
694
+ leaf_count?: number;
695
+ expected_proof_length?: number;
696
+ verify_algo?: string;
697
+ verify_snippet?: string;
698
+ }
699
+ interface AuditVerification {
700
+ ok: boolean;
701
+ checks: Record<string, boolean>;
702
+ leafCount?: number;
703
+ expectedProofLength?: number;
704
+ reason: string | null;
655
705
  }
706
+ /** Number of siblings in a valid proof for a batch of `leafCount` leaves. */
707
+ declare function expectedProofLength(leafCount: number): number;
656
708
  declare class AuditResource extends Resource {
657
709
  status(opts?: RequestOptions): APIPromise<AuditStatus>;
658
710
  latestBatch(opts?: RequestOptions): APIPromise<AuditBatch>;
659
711
  getBatch(batchNum: number, opts?: RequestOptions): APIPromise<AuditBatch>;
660
712
  getEvent(seq: number, opts?: RequestOptions): APIPromise<AuditEvent>;
661
713
  getProof(seq: number, opts?: RequestOptions): APIPromise<MerkleProof>;
662
- getAnchor(batchNum: number, opts?: RequestOptions): APIPromise<AuditBatch>;
714
+ getAnchor(batchNum: number, opts?: RequestOptions): APIPromise<AuditAnchor>;
663
715
  /**
664
- * Verify a Merkle inclusion proof locally (client-side). Sorted-pair SHA-256
665
- * over the raw 32-byte digests — identical logic to the server-side batcher,
666
- * so callers can independently confirm inclusion without trusting the API.
716
+ * Fetch event + proof for `seq` and run every offline check (event hash,
717
+ * same event, seq in batch, proof length, Merkle root). Pass `root` (e.g.
718
+ * the anchored root) for a check independent of this API's batch record.
667
719
  */
668
- static verifyProof(leaf: string, root: string, proof: string[]): boolean;
669
- /** Async variant using WebCrypto — works in browsers, Deno, Bun, edge runtimes. */
670
- static verifyProofAsync(leaf: string, root: string, proof: string[]): Promise<boolean>;
720
+ verify(seq: number, options?: {
721
+ root?: string;
722
+ } & RequestOptions): Promise<AuditVerification>;
723
+ /** Number of siblings in a valid proof for a batch of `leafCount` leaves. */
724
+ static expectedProofLength(leafCount: number): number;
725
+ /** Recompute event_hash = sha256(prev_event_hash + canonical) and check canonical.seq. */
726
+ static verifyEventHash(event: Pick<AuditEvent, "seq" | "prev_event_hash" | "event_hash" | "canonical">): boolean;
727
+ /** Run all checks for one event given getEvent() + getProof() data. */
728
+ static verifyEvent(event: AuditEvent, proof: MerkleProof, root?: string): AuditVerification;
729
+ /**
730
+ * Verify a Merkle inclusion proof locally. Synchronous and isomorphic
731
+ * (node:crypto when a sync `require` exists, else a built-in SHA-256).
732
+ *
733
+ * @param leaf the event's event_hash (64 hex chars)
734
+ * @param root the batch merkle_root (64 hex chars)
735
+ * @param proof sibling hashes, leaf level first (64 hex chars each)
736
+ * @param expectedLength expectedProofLength(leafCount) — required; any other
737
+ * proof length is rejected (second-preimage guard)
738
+ */
739
+ static verifyProof(leaf: string, root: string, proof: string[], expectedLength: number): boolean;
740
+ /** WebCrypto variant of verifyProof (same rules, including expectedLength). */
741
+ static verifyProofAsync(leaf: string, root: string, proof: string[], expectedLength: number): Promise<boolean>;
671
742
  }
743
+ /** True when every bound top-level field equals its value inside the hashed `canonical`. */
744
+ declare function fieldsMatchCanonical(event: Partial<AuditEvent>): boolean;
672
745
 
673
746
  /**
674
747
  * Fees resource — pre-trade 5-actor split estimator.
@@ -770,174 +843,128 @@ declare class GrantsResource extends Resource {
770
843
  }
771
844
 
772
845
  /**
773
- * Keys resource — programmatic API-key management.
846
+ * Markets resource.
774
847
  *
775
- * POST /v1/keys create()
776
- * GET /v1/keys list()
777
- * DELETE /v1/keys/{id} revoke()
778
- *
779
- * `secret` is returned only on `create()` and is never shown again — store
780
- * it securely at that moment.
781
- */
782
-
783
- interface CreateKeyParams {
784
- name?: string;
785
- scopes?: KeyScope[];
786
- }
787
- declare class KeysResource extends Resource {
788
- create(params?: CreateKeyParams, opts?: RequestOptions): APIPromise<ApiKey>;
789
- list(opts?: RequestOptions): APIPromise<ApiKey[]>;
790
- revoke(keyId: string, opts?: RequestOptions): APIPromise<{
791
- revoked: boolean;
792
- }>;
793
- }
794
-
795
- /**
796
- * Markets resource — discovery, candles, orderbook, public trades, creation.
797
- *
798
- * Endpoints wrapped:
799
- * GET /v1/markets list()
848
+ * GET /v1/markets list() paginated
800
849
  * GET /v1/markets/{id} retrieve()
801
- * POST /v1/markets create()
802
- * GET /v1/candles/{market_id} candles()
803
- * GET /v1/orderbook/{market_id} orderbook()
804
- * GET /v1/trades/{market_id} trades() (public tape)
850
+ * GET /v1/markets/categories categories()
851
+ * GET /v1/markets/{id}/orderbook orderbook() public
852
+ * GET /v1/markets/{id}/price-history priceHistory() public
853
+ * GET /v1/markets/{id}/resolution resolution() public
854
+ * POST /v1/composer/markets create()
805
855
  */
806
856
 
807
857
  interface ListMarketsParams {
808
- category?: Category;
809
- marketType?: MarketType;
810
- status?: MarketStatus;
858
+ category?: string;
859
+ q?: string;
811
860
  cursor?: string;
812
861
  limit?: number;
813
862
  }
814
863
  interface CreateMarketParams {
815
- templateId: string;
816
- params: Record<string, unknown>;
817
- creatorMetadata?: Record<string, unknown>;
818
- }
819
- interface CandlesParams {
820
- outcomeId: string;
821
- interval?: CandleInterval;
822
- fromMs?: number;
823
- toMs?: number;
824
- limit?: number;
825
- }
826
- interface OrderbookParams {
827
- outcomeId: string;
828
- depth?: number;
829
- }
830
- interface MarketTradesParams {
831
- outcomeId?: string;
832
- cursor?: string;
833
- limit?: number;
864
+ title: string;
865
+ rulesText: string;
866
+ resolutionRule: string;
867
+ /** https:// URL of an allow-listed public data publisher. */
868
+ primarySourceUrl: string;
869
+ backupSourceUrls?: string[];
870
+ cutoffTimeMs: number;
871
+ resolutionDeadlineMs: number;
872
+ edgeCasesText?: string;
873
+ description?: string;
834
874
  }
875
+ type PriceHistoryRange = "1h" | "6h" | "1d" | "7d" | "30d" | "90d";
835
876
  declare class MarketsResource extends Resource {
836
- /** List markets — auto-paginates. Iterate with `for await (const m of ...)`. */
837
- list(params?: ListMarketsParams, opts?: RequestOptions): PagePromise<Market>;
838
- retrieve(marketId: string, opts?: RequestOptions): APIPromise<Market>;
839
- create(params: CreateMarketParams, opts?: RequestOptions): APIPromise<Market>;
840
- candles(marketId: string, params: CandlesParams, opts?: RequestOptions): APIPromise<Candle[]>;
841
- orderbook(marketId: string, params: OrderbookParams, opts?: RequestOptions): APIPromise<Orderbook>;
842
- /** Public trade tape for a market (all fills, not your fills). */
843
- trades(marketId: string, params?: MarketTradesParams, opts?: RequestOptions): PagePromise<Trade>;
844
- private _buildListQuery;
877
+ /** List markets; iterate every page with `for await (const m of pax.markets.list())`. */
878
+ list(params?: ListMarketsParams, opts?: RequestOptions): PagePromise<Record<string, unknown>>;
879
+ retrieve(marketId: string, opts?: RequestOptions): APIPromise<Record<string, unknown>>;
880
+ categories(opts?: RequestOptions): APIPromise<unknown>;
881
+ orderbook(marketId: string, opts?: RequestOptions): APIPromise<unknown>;
882
+ priceHistory(marketId: string, params?: {
883
+ range?: PriceHistoryRange;
884
+ }, opts?: RequestOptions): APIPromise<unknown>;
885
+ resolution(marketId: string, opts?: RequestOptions): APIPromise<unknown>;
886
+ create(params: CreateMarketParams, opts?: RequestOptions): APIPromise<unknown>;
845
887
  }
846
888
 
847
889
  /**
848
- * Orders resource — your orders (single + batch).
890
+ * Orders resource.
849
891
  *
850
- * POST /v1/orders place()
851
- * DELETE /v1/orders/{id} cancel()
852
- * GET /v1/account/orders list()
853
- * POST /v1/orders/batch placeBatch() — v2.1+, up to 25 orders
854
- * DELETE /v1/orders/batch cancelBatch() — v2.1+, up to 50 orders
892
+ * POST /v1/orders place() limit BUY of one outcome
893
+ * POST /v1/orders/batch placeBatch()
894
+ * GET /v1/orders list() your most recent orders
895
+ * GET /v1/orders/history history()
896
+ * DELETE /v1/orders/{id} cancel()
897
+ * POST /v1/orders/cancel-all cancelAll() all resting orders, or one market's
855
898
  */
856
899
 
857
900
  interface PlaceOrderParams {
858
901
  marketId: string;
859
- outcomeId: string;
860
- side: Side;
861
- orderType: OrderType;
902
+ /** The outcome to buy. */
903
+ side: "yes" | "no";
904
+ /** Limit price, 0.01..0.99. */
905
+ price: Decimal | number;
906
+ /** Shares, > 0. */
862
907
  size: Decimal | number;
863
- price?: Decimal | number;
908
+ /**
909
+ * Engine-side dedupe key. Generated once per call when omitted, so a retry
910
+ * of the same call can never place a second order.
911
+ */
864
912
  clientOrderId?: string;
865
- timeInForce?: TimeInForce;
913
+ fundingMode?: string;
866
914
  }
867
915
  interface ListOrdersParams {
868
- status?: OrderStatus;
869
- cursor?: string;
870
916
  limit?: number;
871
917
  }
872
- /** Per-item result inside a batch response — one entry per input order. */
918
+ interface OrderHistoryParams {
919
+ limit?: number;
920
+ cursor?: string;
921
+ }
922
+ interface OrderRow {
923
+ id: string;
924
+ market_id: string;
925
+ side: string;
926
+ action: string;
927
+ kind: string;
928
+ price: string;
929
+ size: string;
930
+ filled_size: string;
931
+ status: string;
932
+ created_at: string;
933
+ updated_at: string;
934
+ [k: string]: unknown;
935
+ }
936
+ interface OrderList {
937
+ orders: OrderRow[];
938
+ count: number;
939
+ }
873
940
  interface BatchOrderResultItem {
874
941
  ok: boolean;
875
942
  index: number;
876
943
  client_order_id: string | null;
877
944
  data?: unknown;
878
- attribution?: {
879
- execution_builder_id?: string;
880
- acquisition_builder_id?: string | null;
881
- order_id?: string | null;
882
- write?: {
883
- ok: boolean;
884
- rowCount?: number;
885
- reason?: string;
886
- };
887
- };
888
945
  error?: {
889
946
  code: string;
890
947
  message: string;
891
948
  };
892
949
  }
893
- interface BatchOrderSummary {
894
- submitted: number;
895
- succeeded: number;
896
- failed: number;
897
- duration_ms: number;
898
- }
899
950
  interface BatchOrdersResult {
900
951
  results: BatchOrderResultItem[];
901
- summary: BatchOrderSummary;
902
- }
903
- interface BatchCancelResultItem {
904
- ok: boolean;
905
- index: number;
906
- order_id?: string;
907
- data?: unknown;
908
- error?: {
909
- code: string;
910
- message: string;
952
+ summary: {
953
+ submitted: number;
954
+ succeeded: number;
955
+ failed: number;
956
+ duration_ms: number;
911
957
  };
912
958
  }
913
- interface BatchCancelResult {
914
- results: BatchCancelResultItem[];
915
- summary: BatchOrderSummary;
916
- }
917
959
  declare class OrdersResource extends Resource {
918
- place(params: PlaceOrderParams, opts?: RequestOptions): APIPromise<Order>;
919
- cancel(orderId: string, opts?: RequestOptions): APIPromise<Order>;
920
- list(params?: ListOrdersParams, opts?: RequestOptions): PagePromise<Order>;
921
- /**
922
- * Place multiple orders in a single request (up to 25 per batch).
923
- *
924
- * Each order is processed sequentially by the CLOB engine (single-writer per
925
- * market). Response contains a `results` array with one entry per input order
926
- * (indexed) plus a `summary` with counts + duration. One bad order does not
927
- * fail the whole batch — inspect `results[i].ok` per item.
928
- *
929
- * Batch cap is env-tunable server-side (BATCH_ORDERS_MAX, default 25). Exceeding
930
- * returns `413 BATCH_TOO_LARGE`.
931
- */
960
+ place(params: PlaceOrderParams, opts?: RequestOptions): APIPromise<unknown>;
932
961
  placeBatch(orders: PlaceOrderParams[], opts?: RequestOptions): APIPromise<BatchOrdersResult>;
933
- /**
934
- * Cancel multiple orders in a single request (up to 50 per batch).
935
- *
936
- * Each cancel is processed sequentially by the CLOB engine. Response mirrors
937
- * `placeBatch` shape — inspect `results[i].ok` per item. Batch cap env-tunable
938
- * server-side (BATCH_CANCEL_MAX, default 50).
939
- */
940
- cancelBatch(orderIds: string[], opts?: RequestOptions): APIPromise<BatchCancelResult>;
962
+ list(params?: ListOrdersParams, opts?: RequestOptions): APIPromise<OrderList>;
963
+ history(params?: OrderHistoryParams, opts?: RequestOptions): APIPromise<unknown>;
964
+ cancel(orderId: string, opts?: RequestOptions): APIPromise<unknown>;
965
+ cancelAll(params?: {
966
+ marketId?: string;
967
+ }, opts?: RequestOptions): APIPromise<unknown>;
941
968
  }
942
969
 
943
970
  /**
@@ -956,7 +983,7 @@ declare class OrdersResource extends Resource {
956
983
 
957
984
  interface SandboxKeyMintParams {
958
985
  orgName: string;
959
- contactEmail?: string;
986
+ contactHandle?: string;
960
987
  }
961
988
  interface ApplyCreateParams {
962
989
  /**
@@ -1003,15 +1030,10 @@ declare class SandboxResource extends Resource {
1003
1030
  /**
1004
1031
  * Settle resource — claim accrued fee revenue (v2.4+).
1005
1032
  *
1006
- * Three surfaces:
1007
- * - `me()` — builder self-serve claim of their own execution +
1008
- * acquisition builder fees. Uses api-key auth.
1009
- * - `adminBuilder()` — admin claim of a specific builder's accrued fees.
1010
- * Requires X-Admin-Key header.
1011
- * - `adminCreator()` — admin claim of a market creator's FEE_MARKET_CREATOR
1012
- * fees. Requires X-Admin-Key header.
1033
+ * - `me()` — POST /v1/builders/me/settle: builder self-serve claim of their
1034
+ * own execution + acquisition builder fees.
1013
1035
  *
1014
- * All three insert a `withdrawal_state` row with the appropriate source tag
1036
+ * Inserts a `withdrawal_state` row with the appropriate source tag
1015
1037
  * and mark the underlying `financial_event` rows settled. The existing
1016
1038
  * withdrawal pipeline delivers USDT to the provided address.
1017
1039
  */
@@ -1035,11 +1057,6 @@ interface SettleResult {
1035
1057
  declare class SettleResource extends Resource {
1036
1058
  /** Builder self-serve settle — POST /v1/builders/me/settle. */
1037
1059
  me(params: SettleParams, opts?: RequestOptions): APIPromise<SettleResult>;
1038
- /** Admin settle a specific builder's fees — POST /v1/admin/builders/{userId}/settle.
1039
- * Requires X-Admin-Key header. */
1040
- adminBuilder(userId: string, params: SettleParams, adminKey: string, opts?: RequestOptions): APIPromise<SettleResult>;
1041
- /** Admin settle a market creator's fees — POST /v1/admin/creators/{userId}/settle. */
1042
- adminCreator(userId: string, params: SettleParams, adminKey: string, opts?: RequestOptions): APIPromise<SettleResult>;
1043
1060
  }
1044
1061
 
1045
1062
  /**
@@ -1060,39 +1077,25 @@ declare class TemplatesResource extends Resource {
1060
1077
  }
1061
1078
 
1062
1079
  /**
1063
- * PaxClient — top-level entry point.
1064
- *
1065
- * Auth modes (auto-detected from constructor):
1066
- * 1. HMAC — pass `apiKey` + `secret` + `passphrase`. Every request
1067
- * signed with 5 POLY_* headers. Use for high-security trading.
1068
- * 2. API Key — pass only `apiKey`. Sent via `X-Api-Key` header.
1069
- * 3. Bearer — pass `bearerToken`. Session-based, browser/mobile.
1080
+ * PaxClient — top-level entry point for https://api.predictasiax.com.
1070
1081
  *
1071
- * Resources hang off the client, e.g. `pax.markets.list()`, following
1072
- * the Stripe/OpenAI/Anthropic convention.
1082
+ * Credentials (pick one; none is fine for public endpoints):
1083
+ * - `apiKey: "sk_live_..."` → Authorization: Bearer sk_live_...
1084
+ * - `apiKey: "sk_live_...", keyId: "api_..."` → HMAC request signing (PAX-* headers)
1085
+ * - `bearerToken: "..."` → session / OAuth token
1073
1086
  *
1074
1087
  * @example
1075
1088
  * import { PaxClient } from "@predictasiax/api";
1076
1089
  *
1077
- * // Mint an anonymous sandbox key first (30 sec, no email):
1078
- * // curl -X POST https://api.predictasiax.com/v1/sandbox-keys \
1079
- * // -H 'Content-Type: application/json' -d '{"org_name":"my-app"}'
1080
- * // → { api_key: "sk_live_...", tier: "self_serve", ... }
1081
- * const pax = new PaxClient({ apiKey: "sk_live_..." });
1082
- * const account = await pax.account.retrieve();
1083
- *
1084
- * for await (const market of pax.markets.list({ category: "crypto" })) {
1085
- * console.log(market.id, market.title);
1086
- * }
1090
+ * const pub = new PaxClient();
1091
+ * const check = await pub.audit.verify(1866215); // offline audit checks
1087
1092
  *
1088
- * const { data, response, requestId } =
1089
- * await pax.orders.place({
1090
- * marketId: "m_abc", outcomeId: "yes",
1091
- * side: "buy", orderType: "market", size: "10",
1092
- * }, { idempotencyKey: "ord_1" }).withResponse();
1093
+ * const pax = new PaxClient({ apiKey: "sk_live_...", keyId: "api_..." });
1094
+ * await pax.account.balance();
1095
+ * await pax.orders.place({ marketId: "hadjar-f1-2026", side: "yes", price: "0.05", size: "10" });
1093
1096
  */
1094
1097
 
1095
- declare const VERSION = "2.2.0";
1098
+ declare const VERSION = "3.0.1";
1096
1099
  type PaxClientOptions = HttpClientOptions;
1097
1100
  declare class PaxClient {
1098
1101
  private readonly _http;
@@ -1100,7 +1103,6 @@ declare class PaxClient {
1100
1103
  readonly templates: TemplatesResource;
1101
1104
  readonly orders: OrdersResource;
1102
1105
  readonly account: AccountResource;
1103
- readonly keys: KeysResource;
1104
1106
  readonly sandbox: SandboxResource;
1105
1107
  readonly sandboxKeys: SandboxKeysResource;
1106
1108
  readonly apply: ApplyResource;
@@ -1108,9 +1110,10 @@ declare class PaxClient {
1108
1110
  readonly fees: FeesResource;
1109
1111
  readonly audit: AuditResource;
1110
1112
  readonly settle: SettleResource;
1111
- constructor(opts: PaxClientOptions);
1113
+ constructor(opts?: PaxClientOptions);
1112
1114
  get baseUrl(): string;
1113
1115
  get userAgent(): string;
1116
+ get authMode(): string;
1114
1117
  /** GET /v1/health — top-level, not paginated, always safe. */
1115
1118
  health(opts?: RequestOptions): APIPromise<HealthStatus>;
1116
1119
  }
@@ -1173,11 +1176,13 @@ interface AttachRefResult {
1173
1176
  /**
1174
1177
  * Detect + persist a builder ref, then return headers ready for PaxClient.
1175
1178
  *
1176
- * Precedence: explicit `ref` opt → URL `?ref=` → cookie → localStorage →
1177
- * in-memory (this process) → none.
1179
+ * Precedence: explicit `ref` opt → stored ref (cookie → localStorage →
1180
+ * in-memory) → URL `?ref=` → none.
1178
1181
  *
1179
- * When a fresh value is found in URL / explicit, it is persisted according
1180
- * to `storage` (default `cookie` in the browser, `memory` server-side).
1182
+ * First write wins: a `?ref=` in the URL is persisted only when no ref is
1183
+ * stored yet, so a later link cannot silently replace the referral that
1184
+ * brought the user in (same sticky semantics as the server). Only an explicit
1185
+ * `ref` option, or `clearRef()` first, replaces a stored value.
1181
1186
  */
1182
1187
  declare function attachRef(opts?: AttachRefOptions): AttachRefResult;
1183
1188
  /**
@@ -1285,51 +1290,48 @@ declare class PaxWSClient {
1285
1290
  }
1286
1291
 
1287
1292
  /**
1288
- * HMAC signing helpers — 5-header pattern with PAX-ADDRESS, PAX-TIMESTAMP, PAX-NONCE, PAX-SIGNATURE plus Content-Type.
1293
+ * HMAC request signing for the PAX API gateway (https://api.predictasiax.com).
1289
1294
  *
1290
- * Signature construction:
1291
- * message = timestamp_ms + method_upper + path_with_query + body
1292
- * signature = base64(HMAC-SHA256(secret, message))
1295
+ * What the gateway verifies:
1293
1296
  *
1294
- * Headers sent:
1295
- * POLY_ACCESS_KEY: <key_id>
1296
- * POLY_TIMESTAMP: <ms epoch>
1297
- * POLY_PASSPHRASE: <passphrase>
1298
- * POLY_SIGNATURE: <base64 sig>
1297
+ * canonical = timestamp + "\n" + nonce + "\n" + METHOD + "\n" + pathWithQuery + "\n" + body
1298
+ * signature = base64(HMAC-SHA256(key = apiKey, msg = canonical))
1299
1299
  *
1300
- * Server rejects with 401 INVALID_SIGNATURE if timestamp is more than
1301
- * ±30 seconds from server clock — sync your machine via NTP.
1300
+ * PAX-ADDRESS: <key id, e.g. api_0123456789ab>
1301
+ * PAX-TIMESTAMP: <unix seconds> accepted window: ±300 s
1302
+ * PAX-NONCE: <random, single use> remembered for 600 s per key
1303
+ * PAX-SIGNATURE: <base64 signature>
1302
1304
  *
1303
- * Runtime support:
1304
- * - Node.js 18+ / Bun / Deno → node:crypto (via createHmac)
1305
- * - Browser / Cloudflare Workers / Vercel Edge → WebCrypto (subtle.sign)
1305
+ * `apiKey` is the full `sk_live_...` string shown once at mint time; the key
1306
+ * itself is never sent. `pathWithQuery` includes `/v1` and the query string.
1307
+ * Sign every attempt afresh (new timestamp + nonce), retries included.
1306
1308
  *
1307
- * `signRequest` is async because WebCrypto's subtle.sign is async.
1309
+ * Runtime: WebCrypto when available (browsers, edge, Node 18+), else node:crypto.
1308
1310
  */
1309
1311
  interface HmacHeaders {
1310
- POLY_ACCESS_KEY: string;
1311
- POLY_TIMESTAMP: string;
1312
- POLY_PASSPHRASE: string;
1313
- POLY_SIGNATURE: string;
1312
+ "PAX-ADDRESS": string;
1313
+ "PAX-TIMESTAMP": string;
1314
+ "PAX-NONCE": string;
1315
+ "PAX-SIGNATURE": string;
1314
1316
  }
1315
1317
  interface SignInput {
1316
1318
  method: string;
1317
- path: string;
1319
+ /** Path including `/v1` and the query string, exactly as sent. */
1320
+ pathWithQuery: string;
1321
+ /** Raw body exactly as sent ("" when there is none). */
1318
1322
  body: string;
1323
+ /** Key id (`api_...`), sent as PAX-ADDRESS. */
1319
1324
  keyId: string;
1320
- secret: string;
1321
- passphrase: string;
1322
- timestampMs?: number;
1323
- }
1324
- /** Return the canonical signing message (exposed for debugging). */
1325
- declare function buildMessage(method: string, path: string, body: string, timestampMs: number): string;
1326
- /**
1327
- * Sign a PAX request. Returns the four POLY_* headers.
1328
- *
1329
- * On Node this uses `node:crypto`; on browser / edge runtimes it falls back
1330
- * to WebCrypto. Both paths are byte-for-byte identical because HMAC-SHA256
1331
- * is deterministic.
1332
- */
1325
+ /** Full `sk_live_...` key, used as the HMAC key. */
1326
+ apiKey: string;
1327
+ /** Unix seconds override (tests only). */
1328
+ timestampSec?: number;
1329
+ /** Nonce override (tests only). Never reuse a nonce. */
1330
+ nonce?: string;
1331
+ }
1332
+ /** Return the exact string the gateway signs (exposed for debugging). */
1333
+ declare function buildCanonical(timestamp: string | number, nonce: string, method: string, pathWithQuery: string, body: string): string;
1334
+ /** Build the four PAX-* headers for one request attempt. */
1333
1335
  declare function signRequest(input: SignInput): Promise<HmacHeaders>;
1334
1336
 
1335
1337
  /**
@@ -1423,4 +1425,4 @@ declare function runWithRetry<T>(fn: () => Promise<T>, opts?: {
1423
1425
  onRetry?: (attempt: number, error: Error) => void;
1424
1426
  }): Promise<T>;
1425
1427
 
1426
- export { APIPromise, type APIResponseInfo, type Account, type AccountBalance, AccountResource, type ApiKey, type ApplicationResult, type ApplicationStatus, type ApplyCreateParams, ApplyResource, type AttachRefOptions, type AttachRefResult, type AuditBatch, type AuditEvent, AuditResource, type AuditStatus, type BatchCancelResult, type BatchCancelResultItem, type BatchOrderResultItem, type BatchOrderSummary, type BatchOrdersResult, type Candle, type CandleInterval, type CandlesParams, type Category, type CreateKeyParams, type CreateMarketParams, CursorPage, type CursorPageInit, type CursorPageParams, type Decimal, type Env, type Envelope, type FeeEstimate, type FeeEstimateParams, FeesResource, type GrantClaimResult, type GrantEvent, type GrantEventType, type GrantPhase, type GrantTier, type GrantVesting, GrantsResource, type HealthStatus, type HmacHeaders, type HttpClientOptions, type KeyScope, KeysResource, type ListEnvelope, type ListMarketsParams, type ListOrdersParams, type ListTemplatesParams, type ListTradesParams, type Market, type MarketStatus, type MarketTemplate, type MarketTradesParams, type MarketType, MarketsResource, type MerkleProof, type Order, type OrderStatus, type OrderType, type Orderbook, type OrderbookLevel, type OrderbookParams, OrdersResource, type Outcome, PagePromise, PaxAuthError, PaxCircuitBreakerError, PaxClient, type PaxClientOptions, PaxConflictError, PaxError, type PaxErrorDetails, type PaxErrorPayload, PaxNotFoundError, PaxRateLimitError, PaxReadOnlyModeError, PaxSandboxOnlyError, PaxServerError, PaxValidationError, PaxWSClient, type PaxWSClientOptions, PaxWrongEnvKeyError, type PlaceOrderParams, type Position, type RequestOptions, type ResponseMeta, type SandboxKeyMintParams, type SandboxKeyResult, SandboxKeysResource, SandboxResource, type Side, type SignInput, TemplatesResource, type Tier, type TierLimits, type TimeInForce, type TokenGrant, type Trade, VERSION, type WithResponseResult, type WsEvent, type WsHandler, attachRef, buildError, buildMessage, clearRef, computeBackoff, runWithRetry, signRequest };
1428
+ export { APIPromise, type APIResponseInfo, type Account, type AccountBalance, AccountResource, type ApiKey, type ApplicationResult, type ApplicationStatus, type ApplyCreateParams, ApplyResource, type AttachRefOptions, type AttachRefResult, type AuditAnchor, type AuditBatch, type AuditEvent, AuditResource, type AuditStatus, type AuditVerification, type BatchOrderResultItem, type BatchOrdersResult, type Candle, type CandleInterval, type Category, type CreateMarketParams, CursorPage, type CursorPageInit, type CursorPageParams, DEFAULT_BASE_URL, type Decimal, type Env, type Envelope, type FeeEstimate, type FeeEstimateParams, FeesResource, type GrantClaimResult, type GrantEvent, type GrantEventType, type GrantPhase, type GrantTier, type GrantVesting, GrantsResource, type HealthStatus, type HmacHeaders, type HttpClientOptions, type KeyScope, type ListEnvelope, type ListMarketsParams, type ListOrdersParams, type ListTemplatesParams, type Market, type MarketStatus, type MarketTemplate, type MarketType, MarketsResource, type MerkleProof, type Order, type OrderHistoryParams, type OrderList, type OrderRow, type OrderStatus, type OrderType, type Orderbook, type OrderbookLevel, OrdersResource, type Outcome, PagePromise, PaxAuthError, PaxCircuitBreakerError, PaxClient, type PaxClientOptions, PaxConflictError, PaxError, type PaxErrorDetails, type PaxErrorPayload, PaxNotFoundError, PaxRateLimitError, PaxReadOnlyModeError, PaxSandboxOnlyError, PaxServerError, PaxValidationError, PaxWSClient, type PaxWSClientOptions, PaxWrongEnvKeyError, type PlaceOrderParams, type Position, type PriceHistoryRange, type RequestOptions, type ResponseMeta, type SandboxKeyMintParams, type SandboxKeyResult, SandboxKeysResource, SandboxResource, SettleResource, type Side, type SignInput, TemplatesResource, type Tier, type TierLimits, type TimeInForce, type TokenGrant, type Trade, VERSION, type WithResponseResult, type WsEvent, type WsHandler, attachRef, buildCanonical, buildError, clearRef, computeBackoff, expectedProofLength, fieldsMatchCanonical, normalizeBaseUrl, runWithRetry, signRequest };