@perpbrain/sdk 0.2.1 → 0.3.0

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/cjs/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /** Read-only and simulation-only SDK surface. */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.normaliseSelector = exports.linkInputs = exports.computeLink = exports.buildLink = exports.LINK_VERSION = exports.LINK_KIND = exports.verifyReconReceipt = exports.reconcile = exports.RECON_VERSION = exports.RECON_KIND = exports.verifyHolding = exports.computeHolding = exports.buildHolding = exports.VERIFY_SCOPE = exports.HOLDING_VERSION = exports.HOLDING_STATEMENT = exports.HOLDING_KIND = exports.FUNDING_SCOPE = exports.FUNDING_COVERAGE = exports.validateClientMeta = exports.makeEntry = exports.attachClientMeta = exports.CLIENT_META_MAX_CANONICAL_BYTES = exports.CLIENT_META_ALLOWED_KEYS = exports.verifyReport = exports.computeReport = exports.buildReport = exports.MIN_SAMPLE = exports.CALIBRATION_STATEMENT = exports.CALIBRATION_VERSION = exports.CALIBRATION_KIND = exports.renderReceiptCard = exports.guardedSimulate = exports.wireCode = exports.survivalReport = exports.fromConfig = exports.defaultSnapshot = exports.defaultGuards = exports.GuardSession = exports.GuardLoosenError = exports.GuardConfigError = exports.GuardBlocked = exports.STALE_HALT_MS = exports.STALE_BLOCK_MS = exports.PRESETS = exports.HARD_MAX_SLIPPAGE_BPS = exports.HARD_MAX_ORDER_RATE = exports.HARD_MAX_OPEN_POSITIONS = exports.HARD_MAX_DAILY_LOSS_PCT = exports.CODES = void 0;
5
- exports.READ_AND_SIM_TOOLS = exports.simulate = exports.positions = exports.orderBook = exports.markets = exports.funding = exports.fees = exports.InfoClient = exports.executionCost = exports.writeReceiptDir = exports.NoVerdictError = exports.InvalidLimitError = exports.MissingInputsError = exports.UnsupportedVerificationError = exports.ResourceLimitError = exports.verifyReceiptAt = exports.verifyReceipt = exports.snapshotRows = exports.simulateInputs = exports.sha256Json = exports.limitsPayload = exports.exampleInputs = exports.costBreakdownFromReceipt = exports.canonical = exports.buildReceiptFiles = exports.buildReceiptDir = exports.buildGuardedReceipt = exports.RECEIPT_VERSION = exports.RECEIPT_STATEMENT = exports.RECEIPT_KIND = exports.verifyLink = exports.simFromReceipt = exports.selectFills = void 0;
4
+ exports.checkV2Value = exports.checkV2Text = exports.buildLink = exports.LINK_VERSION_V2 = exports.LINK_VERSION = exports.LINK_KIND = exports.verifyReconReceipt = exports.reconcile = exports.RECON_VERSION = exports.RECON_KIND = exports.verifyHolding = exports.computeHolding = exports.buildHolding = exports.VERIFY_SCOPE = exports.HOLDING_VERSION = exports.HOLDING_STATEMENT = exports.HOLDING_KIND = exports.FUNDING_SCOPE = exports.FUNDING_COVERAGE = exports.validateClientMeta = exports.makeEntry = exports.attachClientMeta = exports.CLIENT_META_MAX_CANONICAL_BYTES = exports.CLIENT_META_ALLOWED_KEYS = exports.verifyReport = exports.computeReport = exports.buildReport = exports.MIN_SAMPLE = exports.CALIBRATION_STATEMENT = exports.CALIBRATION_VERSION = exports.CALIBRATION_KIND = exports.renderReceiptCard = exports.guardedSimulate = exports.wireCode = exports.survivalReport = exports.fromConfig = exports.defaultSnapshot = exports.defaultGuards = exports.GuardSession = exports.GuardLoosenError = exports.GuardConfigError = exports.GuardBlocked = exports.STALE_HALT_MS = exports.STALE_BLOCK_MS = exports.PRESETS = exports.HARD_MAX_SLIPPAGE_BPS = exports.HARD_MAX_ORDER_RATE = exports.HARD_MAX_OPEN_POSITIONS = exports.HARD_MAX_DAILY_LOSS_PCT = exports.CODES = void 0;
5
+ exports.READ_AND_SIM_TOOLS = exports.simulate = exports.positions = exports.orderBook = exports.markets = exports.funding = exports.fees = exports.InfoClient = exports.executionCost = exports.writeReceiptDir = exports.NoVerdictError = exports.InvalidLimitError = exports.MissingInputsError = exports.UnsupportedVerificationError = exports.ResourceLimitError = exports.verifyReceiptAt = exports.verifyReceipt = exports.snapshotRows = exports.simulateInputs = exports.sha256Json = exports.limitsPayload = exports.exampleInputs = exports.costBreakdownFromReceipt = exports.canonical = exports.buildReceiptFiles = exports.buildReceiptDir = exports.buildGuardedReceipt = exports.RECEIPT_VERSION = exports.RECEIPT_STATEMENT = exports.RECEIPT_KIND = exports.verifyLink = exports.simFromReceipt = exports.selectFills = exports.receiptBounds = exports.normaliseSelector = exports.linkInputs = exports.computeLink = void 0;
6
6
  var guards_ts_1 = require("./guards.js");
7
7
  Object.defineProperty(exports, "CODES", { enumerable: true, get: function () { return guards_ts_1.CODES; } });
8
8
  Object.defineProperty(exports, "HARD_MAX_DAILY_LOSS_PCT", { enumerable: true, get: function () { return guards_ts_1.HARD_MAX_DAILY_LOSS_PCT; } });
@@ -57,10 +57,14 @@ Object.defineProperty(exports, "verifyReconReceipt", { enumerable: true, get: fu
57
57
  var fillLink_ts_1 = require("./fillLink.js");
58
58
  Object.defineProperty(exports, "LINK_KIND", { enumerable: true, get: function () { return fillLink_ts_1.LINK_KIND; } });
59
59
  Object.defineProperty(exports, "LINK_VERSION", { enumerable: true, get: function () { return fillLink_ts_1.LINK_VERSION; } });
60
+ Object.defineProperty(exports, "LINK_VERSION_V2", { enumerable: true, get: function () { return fillLink_ts_1.LINK_VERSION_V2; } });
60
61
  Object.defineProperty(exports, "buildLink", { enumerable: true, get: function () { return fillLink_ts_1.buildLink; } });
62
+ Object.defineProperty(exports, "checkV2Text", { enumerable: true, get: function () { return fillLink_ts_1.checkV2Text; } });
63
+ Object.defineProperty(exports, "checkV2Value", { enumerable: true, get: function () { return fillLink_ts_1.checkV2Value; } });
61
64
  Object.defineProperty(exports, "computeLink", { enumerable: true, get: function () { return fillLink_ts_1.computeLink; } });
62
65
  Object.defineProperty(exports, "linkInputs", { enumerable: true, get: function () { return fillLink_ts_1.linkInputs; } });
63
66
  Object.defineProperty(exports, "normaliseSelector", { enumerable: true, get: function () { return fillLink_ts_1.normaliseSelector; } });
67
+ Object.defineProperty(exports, "receiptBounds", { enumerable: true, get: function () { return fillLink_ts_1.receiptBounds; } });
64
68
  Object.defineProperty(exports, "selectFills", { enumerable: true, get: function () { return fillLink_ts_1.selectFills; } });
65
69
  Object.defineProperty(exports, "simFromReceipt", { enumerable: true, get: function () { return fillLink_ts_1.simFromReceipt; } });
66
70
  Object.defineProperty(exports, "verifyLink", { enumerable: true, get: function () { return fillLink_ts_1.verifyLink; } });
@@ -8,6 +8,7 @@
8
8
  */
9
9
  export declare const LINK_KIND = "perpbrain.execution-link";
10
10
  export declare const LINK_VERSION = 1;
11
+ export declare const LINK_VERSION_V2 = 2;
11
12
  export type LinkSelector = "oid" | "hash" | "cloid";
12
13
  export type LinkNetwork = "mainnet" | "testnet";
13
14
  type Row = Record<string, unknown>;
@@ -28,6 +29,8 @@ export interface LinkInputs {
28
29
  receipt_sha256: string;
29
30
  sim: SimTrade;
30
31
  fills: Row[];
32
+ policy?: unknown;
33
+ bounds?: unknown;
31
34
  }
32
35
  export interface LinkResult {
33
36
  status: "LINKED" | "NO_FILLS" | "MISMATCHED_TRADE";
@@ -69,9 +72,26 @@ export declare function linkInputs(receipt: unknown, rows: readonly Row[], optio
69
72
  by: LinkSelector;
70
73
  value: unknown;
71
74
  tradeIndex?: number;
75
+ policy?: unknown;
72
76
  }): LinkInputs;
73
- export declare function computeLink(inputs: LinkInputs): LinkResult;
74
- export declare function buildLink(inputs: LinkInputs): BuiltLink;
75
- /** Re-hash the inputs, rerun the comparison and, given the receipt, check the binding. */
77
+ /** v2 inputs are canonical in both SDKs only when every number is a JSON integer within the
78
+ * double-safe range and every object key is ASCII. Anything else is refused, never coerced. */
79
+ export declare function checkV2Value(value: unknown): void;
80
+ /** Float spellings (1.0, 1e3) parse differently across languages: refused in the raw bytes. */
81
+ export declare function checkV2Text(raw: string): void;
82
+ /** Structural facts taken from the receipt: the smallest positive bar gap and where the decision
83
+ * time came from ("bar", "book", or "unknown" when timed bars exist but the decision bar is not). */
84
+ export declare function receiptBounds(receipt: unknown): {
85
+ bar_interval_ms: number | null;
86
+ time_field: string;
87
+ };
88
+ /** v1 inputs (no `policy` key) give the v1 result unchanged and malformed rows throw, as in 0.2.1.
89
+ * v2 inputs add `correspondence`; malformed rows give a structured INVALID_INPUT result.
90
+ * `bound` is true only when the caller verified the inputs against the receipt. */
91
+ export declare function computeLink(inputs: LinkInputs, bound?: boolean): LinkResult & Record<string, unknown>;
92
+ /** Without `receipt` a v2 link is built unbound: it can never be positive. */
93
+ export declare function buildLink(inputs: LinkInputs, receipt?: unknown): BuiltLink;
94
+ /** Re-hash the inputs, rerun the comparison and, given the receipt, check the binding. A v2
95
+ * record that claims a receipt-bound decision time needs the receipt to verify. */
76
96
  export declare function verifyLink(record: Record<string, unknown>, inputsBytes: Uint8Array, receipt?: unknown): LinkVerify;
77
97
  export {};