@molpha/sdk 0.2.0 → 0.3.0-dev-20261022065307

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
@@ -1,21 +1,171 @@
1
1
  import { Address } from '@solana/kit';
2
2
  import { Wallet, Idl, AnchorProvider } from '@anchor-lang/core';
3
- import { U as UpstreamQuote, A as APIConfig, a as AssetDomain, b as UpstreamTerms, E as EvmSigner, S as Signer, c as SourcePaymentOptions, R as RegistrySelectionConfig, N as Node, d as NodeKeyVerifier, e as NodesInfo, f as Attestation, g as SolanaAccountMeta, h as SolanaConnection, i as SolanaAddress, j as NodeKeyVerifierArgs, k as AggregationConfig, M as MolphaWallet } from './wallet-DGe_pi93.js';
4
- export { l as AttestationPayload, m as EncKeyBundle, n as NumericConfig, o as RegistryInfo, p as SchnorrSignature, q as gatewaySignerFromWallet, s as signerFromKeypair } from './wallet-DGe_pi93.js';
3
+ import { U as UpstreamQuote, A as AssetDomain, a as UpstreamTerms, E as EvmSigner, S as Signer, b as SourcePaymentOptions, R as RegistrySelectionConfig, N as Node, c as NodeKeyVerifier, d as NodesInfo, e as Attestation, f as SolanaAccountMeta, g as SolanaConnection, h as SolanaAddress, i as NodeKeyVerifierArgs, M as MolphaWallet } from './wallet-BAxBy7hR.js';
4
+ export { j as AttestationPayload, k as EncKeyBundle, l as RegistryInfo, m as SchnorrSignature, n as gatewaySignerFromWallet, s as signerFromKeypair } from './wallet-BAxBy7hR.js';
5
5
  import BN from 'bn.js';
6
6
 
7
+ /**
8
+ * The published chain list: for each chain its CAIP-2 id, kind, block time, the finality modes (or
9
+ * commitments) it offers and their bounds. Generated from the node client's `new/source/chainlist.json`,
10
+ * which is the reference; the numbers are protocol estimates, not measurements of a live chain.
11
+ */
12
+ interface Chain {
13
+ id: string;
14
+ kind: "evm" | "starknet" | "svm";
15
+ name: string;
16
+ /** evm and starknet only. */
17
+ blockTimeMs?: number;
18
+ /** evm and starknet: the finality modes offered, with their bounds. */
19
+ finality?: Record<string, {
20
+ minLagMs?: number;
21
+ maxN?: number;
22
+ }>;
23
+ maxLagMs?: number;
24
+ /** svm: the commitments offered. */
25
+ commitments?: Record<string, {
26
+ minMaxAgeMs: number;
27
+ }>;
28
+ maxMaxAgeMs?: number;
29
+ }
30
+ declare const CHAIN_LIST: Chain[];
31
+
32
+ type SourceErrorClass = "syntax" | "utf8" | "surrogate" | "number" | "duplicate_key" | "depth" | "unknown_key" | "missing_key" | "type" | "value" | "limit" | "noncanonical" | "reference";
33
+ /** A rejected source. `path` names the offending field; it never contains a secret. */
34
+ declare class SourceError extends Error {
35
+ readonly path: string;
36
+ readonly errorClass: SourceErrorClass;
37
+ constructor(path: string, errorClass: SourceErrorClass, message: string);
38
+ }
39
+ declare const SOURCE_VERSION = "1";
40
+ declare const MAX_CANONICAL_BYTES: number;
41
+ declare const MAX_PRIVATE_BYTES: number;
42
+ declare const MAX_INPUTS = 4;
43
+ declare const MAX_EXPR_NODES = 64;
44
+ declare const MAX_EXPR_DEPTH = 12;
45
+ declare const MAX_ASSERTS = 8;
46
+ declare const MAX_FIELDS = 16;
47
+ declare const MAX_HEADERS = 16;
48
+ declare const MAX_HEADER_VALUE = 1024;
49
+ declare const MAX_BODY_TEXT = 4096;
50
+ declare const MAX_RESPONSE_BYTES: number;
51
+ declare const MAX_DECIMAL_SCALE = 36;
52
+ declare const MAX_OUTPUT_DECIMALS = 36;
53
+ /** A parsed JSON value. Objects are Maps, so a key such as `__proto__` is just a key. */
54
+ type Json = null | boolean | string | Json[] | JObj;
55
+ type JObj = Map<string, Json>;
56
+ /** Convert plain JavaScript data to Json, refusing numbers and anything else the format forbids. */
57
+ declare function fromPlain(value: unknown, path?: string, depth?: number): Json;
58
+ /** Back to plain objects (insertion-ordered), for callers that want to read a validated source. */
59
+ declare function toPlain(v: Json): unknown;
60
+ /** Strictly parse source JSON: no numbers, no duplicate keys, no lone surrogates, no trailing data. */
61
+ declare function parseStrict(input: string | Uint8Array): Json;
62
+ /** The canonical serialization of a parsed value. */
63
+ declare function canonicalJson(v: Json): string;
64
+ /** The canonical bytes of a source document (any JSON text or plain object), without schema checks. */
65
+ declare function canonicalize(input: string | Uint8Array | object): string;
66
+ interface URLParts {
67
+ scheme: "http" | "https";
68
+ host: string;
69
+ port: string;
70
+ /** Path and query, verbatim. */
71
+ rest: string;
72
+ /** host or host:port as the URL spells it. */
73
+ hostPort: string;
74
+ }
75
+ /** Split a source URL. Scheme, host and port must be literal; throws on anything else. */
76
+ declare function splitURL(u: string): URLParts;
77
+ declare const OUTPUT_TYPES: readonly ["int256", "uint256", "bool", "bytes32", "string32", "keccak256"];
78
+ type OutputType = (typeof OUTPUT_TYPES)[number];
79
+ /** A validated source: its canonical form and ID, and the plain document. */
80
+ interface ParsedSource {
81
+ /** The document, exactly as given (every key present). */
82
+ doc: SourceDoc;
83
+ /** Canonical JSON text; its UTF-8 bytes are what the ID hashes and what nodes receive. */
84
+ canonical: string;
85
+ bytes: Uint8Array;
86
+ /** keccak256 of `bytes`. */
87
+ id: Uint8Array;
88
+ /** `0x`-prefixed lowercase hex of `id`. */
89
+ idHex: string;
90
+ inputNames: string[];
91
+ output: {
92
+ type: OutputType;
93
+ decimals: number;
94
+ };
95
+ tolerance: boolean;
96
+ }
97
+ /** Validate a source given as JSON text, bytes or a plain object, in any key order and whitespace. */
98
+ declare function parseSource(input: string | Uint8Array | object): ParsedSource;
99
+ /** {@link parseSource} for a decrypted private source, whose filled-in secrets may make it longer. */
100
+ declare function parsePrivateSource(input: string | Uint8Array | object): ParsedSource;
101
+ /** Like {@link parseSource}, and also requires the input to be the canonical form already. */
102
+ declare function parseCanonicalSource(input: string | Uint8Array): ParsedSource;
103
+ /** The source ID of a source document: keccak256 of its canonical bytes. */
104
+ declare function deriveSourceId(input: string | Uint8Array | object): Uint8Array;
105
+ /** {@link deriveSourceId} as `0x`-prefixed hex. */
106
+ declare function deriveSourceIdHex(input: string | Uint8Array | object): string;
107
+
108
+ /**
109
+ * Check a source's chain inputs against the chain list: each chain must be listed, of the right
110
+ * kind, offer the finality mode or commitment, and keep `lagMs` or `maxAgeMs` within its bounds. A
111
+ * source that no node could ever satisfy is refused here, not as a failed round.
112
+ */
113
+ declare function checkChains(src: ParsedSource, list?: Chain[], allow?: (chain: string) => boolean): void;
114
+ /** An expression of the transform tree. */
115
+ type Expr = {
116
+ ref: string;
117
+ } | {
118
+ const: string;
119
+ } | {
120
+ str: string;
121
+ } | {
122
+ bytes: string;
123
+ } | {
124
+ bool: boolean;
125
+ } | {
126
+ op: string;
127
+ args: Expr[];
128
+ [param: string]: unknown;
129
+ };
130
+ interface OutputDoc {
131
+ type: OutputType;
132
+ decimals: string | null;
133
+ }
134
+ interface AggregationDoc {
135
+ mode: "tolerance";
136
+ rule: "median";
137
+ maxDeviationBps: string;
138
+ maxAgeMs: string;
139
+ }
140
+ /** A source document in its canonical shape: every key present, every number a string. */
141
+ interface SourceDoc {
142
+ v: "1";
143
+ inputs: Record<string, any>;
144
+ transform: Expr;
145
+ assert: Expr[];
146
+ output: OutputDoc;
147
+ aggregation: AggregationDoc | null;
148
+ }
149
+ /** Whether the source declares keccak256 output (its signed value is a hash of a preimage). */
150
+ declare const hasPreimage: (src: ParsedSource) => boolean;
151
+ /** Everything {@link parseSource} computes, for a source that was already validated. */
152
+ declare function encodeSourceBytes(src: ParsedSource): Uint8Array;
153
+ /** The ID of canonical source bytes: keccak256. */
154
+ declare function sourceIdOf(bytes: Uint8Array): Uint8Array;
155
+
7
156
  /**
8
157
  * GENERATED by `scripts/select-profile.ts` — do not edit.
9
- * Profile: stable
158
+ * Profile: dev
159
+ * EVM/Starknet verifier addresses are unset until the Attestation-interface redeploy. Codegen falls back to stable addresses and sets MOLPHA_DEV_VERIFIERS_PROVISIONAL.
10
160
  */
11
161
  type MolphaSdkProfile = "stable" | "dev";
12
162
  declare const MOLPHA_SDK_PROFILE: MolphaSdkProfile;
13
- declare const DEFAULT_GATEWAY_ENDPOINT = "https://gateway.molpha.io/";
14
- declare const MOLPHA_PROGRAM_ID = "MoLF3pgVA9MENSuEujxNNSMaTo71aLyewaH5nrWfUZs";
163
+ declare const DEFAULT_GATEWAY_ENDPOINT = "https://dev-gateway.molpha.io/";
164
+ declare const MOLPHA_PROGRAM_ID = "chivcFQgxzwkpLvW41PV431HQ4dYpaW3povQH3AdpQt";
15
165
  declare const MOLPHA_VERIFIER_ADDRESS: "0xA6e49A3A1caf3E110cC04765B934C8FF118C2568";
16
166
  declare const MOLPHA_VERIFIER_STARKNET_SEPOLIA: "0x032b9f47f12189668b94a5d62fb7d60f968ed0dbaf22090649d1d7a91d79cc38";
17
167
  /** True when the active profile has unset EVM/Starknet addresses (dev falls back to stable). */
18
- declare const MOLPHA_DEV_VERIFIERS_PROVISIONAL: false;
168
+ declare const MOLPHA_DEV_VERIFIERS_PROVISIONAL: true;
19
169
 
20
170
  /**
21
171
  * Gateway on-chain identity. The request-auth hash binds the Gateway PDA
@@ -100,7 +250,7 @@ declare function validateSuppliedTerms(terms: UpstreamTerms, resource: string, a
100
250
  * not a data fetch: nodes remain the only fetchers of the value itself.
101
251
  * Returns `null` when the source is not paywalled.
102
252
  */
103
- declare function probeSource(apiConfig: APIConfig, options?: {
253
+ declare function probeSource(source: ParsedSource | string | object, options?: {
104
254
  secrets?: Record<string, string>;
105
255
  assetDomain?: AssetDomain;
106
256
  timeoutMs?: number;
@@ -117,14 +267,16 @@ declare function signSourcePayments(terms: UpstreamTerms, signer: EvmSigner, cou
117
267
 
118
268
  interface RequestSignedDataOptions {
119
269
  /**
120
- * The API definition to resolve. Its canonical form determines the round's
121
- * `sourceId = keccak256(JSON.stringify(canonicalizeAPIConfig(apiConfig)))`, so pass the
122
- * same config (including `{{secret.*}}` placeholders) every time.
270
+ * The source to run: what the nodes read, how the reads become one value, and how that value becomes
271
+ * the 32 signed bytes. A {@link ParsedSource} (from `defineSource`, `jsonPriceSource` or
272
+ * `parseSource`), or a source document (JSON text or a plain object) in its full form. The round's
273
+ * `sourceId` is the keccak256 of its canonical bytes, so pass the same source (including
274
+ * `{{secret.*}}` placeholders) every time.
123
275
  */
124
- apiConfig: APIConfig;
276
+ source: ParsedSource | string | object;
125
277
  /**
126
278
  * Requested quorum (u8, ≥ the protocol `min_signers`). Median tolerance mode
127
- * (`apiConfig.aggregation`) additionally requires `>= 3`; lower values are rejected
279
+ * (`source.aggregation`) additionally requires `>= 3`; lower values are rejected
128
280
  * before any request is made.
129
281
  */
130
282
  signaturesRequired: number;
@@ -330,7 +482,7 @@ declare class MolphaGateway {
330
482
  * Request a threshold-signed data update from the gateway, with retry +
331
483
  * failover. The body is POSTed to each endpoint in order until one `completed`s.
332
484
  *
333
- * The round's `sourceId` is derived from `apiConfig`. The request carries no round timestamp:
485
+ * The round's `sourceId` is derived from `source`. The request carries no round timestamp:
334
486
  * the gateway stamps the round with its own clock floored to the round tick (`timestamp`, unix
335
487
  * milliseconds, a multiple of {@link ROUND_TICK_MS}), and the committee follows from it. The
336
488
  * result carries the assigned timestamp and the signers' bitmap; the timestamp is taken as the
@@ -770,63 +922,6 @@ declare class MolphaSolanaClient {
770
922
  */
771
923
  declare function buildSubmitAttestationArgs(attestation: Attestation, coalitionKey: CoalitionKey, rawValue?: Uint8Array | null): SubmitAttestationArgs;
772
924
 
773
- /**
774
- * Aggregation (tolerance mode) config validation and canonicalization.
775
- *
776
- * `aggregation` is part of the API config and therefore part of `sourceId`. It is OMITTED
777
- * for exact mode: a config carrying `mode: "exact"` would hash differently from the same
778
- * config without the key, so it is rejected rather than silently normalized. The node
779
- * (`new/tolerance.Validate`) is the reference.
780
- */
781
-
782
- /** Tolerance mode needs at least this many signers (`signaturesRequired >= 3`). */
783
- declare const MIN_TOLERANCE_SIGNATURES = 3;
784
- /** Thrown for an unusable `aggregation` config. */
785
- declare class AggregationConfigError extends Error {
786
- constructor(message: string);
787
- }
788
- /**
789
- * Validate an `aggregation` config and return a fresh object with the canonical key order
790
- * (`mode`, `rule`, `maxDeviationBps`, `maxAgeMs`, `numeric{type, decimals}`) — the order
791
- * the source hash and the node's JSON blob use.
792
- *
793
- * The result is built field by field: unknown or reordered keys on the input can never
794
- * reach the hash or the wire. `undefined` / `null` mean exact mode and return `undefined`.
795
- *
796
- * @throws {AggregationConfigError} on `mode: "exact"`, an unsupported mode / rule / numeric
797
- * type, or an out-of-range number.
798
- */
799
- declare function canonicalizeAggregation(aggregation: AggregationConfig | null | undefined): AggregationConfig | undefined;
800
- /**
801
- * Tolerance mode needs `signaturesRequired >= 3`; the node rejects anything lower.
802
- * A no-op for exact mode (`aggregation` omitted).
803
- *
804
- * @throws {AggregationConfigError}
805
- */
806
- declare function assertAggregationQuorum(aggregation: AggregationConfig | null | undefined, signaturesRequired: number): void;
807
-
808
- /**
809
- * Gateway wire shape — defaults applied before hash / encryption.
810
- *
811
- * Keys are emitted in the fixed order `url`, `method`, `headers`, `responseParser`,
812
- * `valueTransform`, `aggregation`; `aggregation` is present only for tolerance mode and its
813
- * nested keys are rebuilt in canonical order (`canonicalizeAggregation`), so no extra or
814
- * reordered input key can reach the hash. A config without `aggregation` hashes exactly as
815
- * before.
816
- *
817
- * @throws {AggregationConfigError} if `aggregation` is invalid (including `mode: "exact"`).
818
- */
819
- declare function canonicalizeAPIConfig(apiConfig: APIConfig): APIConfig;
820
- /**
821
- * `sourceId = keccak256(JSON.stringify(canonical apiConfig))` — the 32-byte identity of a
822
- * data source. Hash the same config (including `{{secret.*}}` placeholders) you send to
823
- * `MolphaGateway.requestSignedData`; the gateway and every verifier recompute it from
824
- * `apiConfig`.
825
- */
826
- declare function deriveSourceId(apiConfig: APIConfig): Uint8Array;
827
- /** Hex-encoded {@link deriveSourceId} (64 lowercase hex chars, no `0x`). */
828
- declare function deriveSourceIdString(apiConfig: APIConfig): string;
829
-
830
925
  declare const utf8: (s: string) => Uint8Array;
831
926
  declare const concatBytes: (...arrays: Uint8Array[]) => Uint8Array;
832
927
  /** Lower-case hex, no `0x` prefix. */
@@ -944,6 +1039,288 @@ declare function deriveGroupBitmap(seed: Uint8Array, nodeCount: number, groupSiz
944
1039
  */
945
1040
  declare function deriveSelectionBitmap(sourceId: Uint8Array, registryVersion: number, nodeCount: number, signaturesRequired: number, redundancy?: number, ts?: number | bigint): Uint8Array;
946
1041
 
1042
+ type Num = number | bigint | string;
1043
+ type Round = "halfEven" | "down" | "up" | "halfUp";
1044
+ declare const ref: (name: string) => Expr;
1045
+ /** A decimal constant, e.g. `cst("0.5")`. */
1046
+ declare const cst: (x: Num) => Expr;
1047
+ declare const strLit: (s: string) => Expr;
1048
+ declare const bytesLit: (hex: string) => Expr;
1049
+ declare const boolLit: (b: boolean) => Expr;
1050
+ /** Parse a string into a decimal; the mode says which spelling is acceptable. */
1051
+ declare const num: (a: Expr, mode?: "dec" | "hex" | "sci") => Expr;
1052
+ declare const int: (a: Expr) => Expr;
1053
+ declare const str: (a: Expr) => Expr;
1054
+ declare const hexBytes: (a: Expr) => Expr;
1055
+ declare const add: (a: Expr, b: Expr) => Expr;
1056
+ declare const sub: (a: Expr, b: Expr) => Expr;
1057
+ /** Multiplies; scales add and must stay within 36, so `rescale` an operand first if needed. */
1058
+ declare const mul: (a: Expr, b: Expr) => Expr;
1059
+ declare const min: (a: Expr, b: Expr) => Expr;
1060
+ declare const max: (a: Expr, b: Expr) => Expr;
1061
+ declare const neg: (a: Expr) => Expr;
1062
+ declare const abs: (a: Expr) => Expr;
1063
+ /** `a / b` to `scale` fractional digits. */
1064
+ declare const div: (a: Expr, b: Expr, o: {
1065
+ scale: Num;
1066
+ round?: Round;
1067
+ }) => Expr;
1068
+ declare const rescale: (a: Expr, o: {
1069
+ scale: Num;
1070
+ round?: Round;
1071
+ }) => Expr;
1072
+ /** Multiply by 10^n, exactly. */
1073
+ declare const shift: (a: Expr, n: Num) => Expr;
1074
+ declare const eq: (a: Expr, b: Expr) => Expr;
1075
+ declare const ne: (a: Expr, b: Expr) => Expr;
1076
+ declare const lt: (a: Expr, b: Expr) => Expr;
1077
+ declare const lte: (a: Expr, b: Expr) => Expr;
1078
+ declare const gt: (a: Expr, b: Expr) => Expr;
1079
+ declare const gte: (a: Expr, b: Expr) => Expr;
1080
+ declare const iff: (cond: Expr, a: Expr, b: Expr) => Expr;
1081
+ declare const coalesce: (a: Expr, b: Expr) => Expr;
1082
+ declare const keccak256: (a: Expr) => Expr;
1083
+ declare const concat: (...args: Expr[]) => Expr;
1084
+ declare const slice: (a: Expr, o: {
1085
+ off: Num;
1086
+ len: Num;
1087
+ }) => Expr;
1088
+ declare const lower: (a: Expr) => Expr;
1089
+ declare const upper: (a: Expr) => Expr;
1090
+ type Decode = Record<string, unknown>;
1091
+ declare const rawDecode: () => Decode;
1092
+ /** `fields` maps a name to a JSON path such as `$.data.price`. */
1093
+ declare const jsonDecode: (fields: Record<string, string>) => Decode;
1094
+ declare const textDecode: (fields: Record<string, string>) => Decode;
1095
+ declare const xmlDecode: (fields: Record<string, string>, namespaces?: Record<string, string>) => Decode;
1096
+ declare const csvDecode: (o: {
1097
+ header?: boolean;
1098
+ delimiter?: string;
1099
+ trim?: boolean;
1100
+ fields: Record<string, {
1101
+ col: Num;
1102
+ row: {
1103
+ index: Num;
1104
+ } | {
1105
+ match: {
1106
+ col: Num;
1107
+ eq: string;
1108
+ };
1109
+ };
1110
+ }>;
1111
+ }) => Decode;
1112
+ declare const abiDecode: (types: string[], fields: Record<string, string>) => Decode;
1113
+ declare const feltsDecode: (fields: Record<string, {
1114
+ at: Num;
1115
+ view: "felt" | "u256" | "bool" | "shortString" | "i128";
1116
+ }>) => Decode;
1117
+ declare const layoutDecode: (fields: Record<string, {
1118
+ offset: Num;
1119
+ type: string;
1120
+ }>, discriminator?: string | null) => Decode;
1121
+ interface Finality {
1122
+ mode: "finalized" | "safe" | "confirmations";
1123
+ lagMs: Num;
1124
+ n?: Num;
1125
+ }
1126
+ declare function httpInput(o: {
1127
+ url: string;
1128
+ method?: "GET" | "POST";
1129
+ headers?: Record<string, string>;
1130
+ body?: {
1131
+ contentType: string;
1132
+ text: string;
1133
+ };
1134
+ decode: Decode;
1135
+ }): Record<string, unknown>;
1136
+ declare function evmCall(o: {
1137
+ chain: string;
1138
+ to: string;
1139
+ sig?: string;
1140
+ args?: string[];
1141
+ data?: string;
1142
+ finality: Finality;
1143
+ decode: Decode;
1144
+ }): Record<string, unknown>;
1145
+ declare function evmStorage(o: {
1146
+ chain: string;
1147
+ address: string;
1148
+ slot: string;
1149
+ finality: Finality;
1150
+ decode: Decode;
1151
+ }): Record<string, unknown>;
1152
+ declare function evmBalance(o: {
1153
+ chain: string;
1154
+ address: string;
1155
+ finality: Finality;
1156
+ decode: Decode;
1157
+ }): Record<string, unknown>;
1158
+ declare function starknetCall(o: {
1159
+ chain: string;
1160
+ contract: string;
1161
+ selector: string;
1162
+ calldata?: string[];
1163
+ finality: Finality;
1164
+ decode: Decode;
1165
+ }): Record<string, unknown>;
1166
+ declare function svmAccount(o: {
1167
+ chain: string;
1168
+ address: string;
1169
+ commitment?: "finalized" | "confirmed";
1170
+ maxAgeMs: Num;
1171
+ dataSlice?: {
1172
+ offset: Num;
1173
+ length: Num;
1174
+ };
1175
+ decode: Decode;
1176
+ }): Record<string, unknown>;
1177
+ declare function svmTokenSupply(o: {
1178
+ chain: string;
1179
+ mint: string;
1180
+ commitment?: "finalized" | "confirmed";
1181
+ maxAgeMs: Num;
1182
+ }): Record<string, unknown>;
1183
+ interface SourceInput {
1184
+ inputs: Record<string, Record<string, any>>;
1185
+ transform: Expr;
1186
+ assert?: Expr[];
1187
+ output: {
1188
+ type: OutputType;
1189
+ decimals?: Num | null;
1190
+ };
1191
+ /** Median tolerance. Omit or `null` for exact mode. */
1192
+ aggregation?: {
1193
+ maxDeviationBps: Num;
1194
+ maxAgeMs: Num;
1195
+ mode?: "tolerance";
1196
+ rule?: "median";
1197
+ } | null;
1198
+ }
1199
+ /** The full-form document a {@link SourceInput} stands for. */
1200
+ declare function sourceDocFor(input: SourceInput): SourceDoc;
1201
+ /** Fill in the defaults of a short-form source and validate it. Throws a `SourceError` with a path. */
1202
+ declare function defineSource(input: SourceInput): ParsedSource;
1203
+ /**
1204
+ * The common case: GET `url`, read the JSON value at `path`, scale it to `decimals`, and encode it as an
1205
+ * int256. `valueIs: "string"` parses a JSON string such as `"65000.12"`; `"number"` (the default) takes
1206
+ * a JSON number as is. Add `tolerance` to aggregate by median instead of requiring identical values.
1207
+ */
1208
+ declare function jsonPriceSource(o: {
1209
+ url: string;
1210
+ path: string;
1211
+ decimals: Num;
1212
+ valueIs?: "number" | "string";
1213
+ headers?: Record<string, string>;
1214
+ tolerance?: {
1215
+ maxDeviationBps: Num;
1216
+ maxAgeMs: Num;
1217
+ };
1218
+ }): ParsedSource;
1219
+ /** Tolerance mode needs at least this many signers; nodes and the gateway reject fewer. */
1220
+ declare const MIN_TOLERANCE_SIGNATURES = 3;
1221
+ /** Throws unless a tolerance source is asked for at least 3 signatures. No-op for exact mode. */
1222
+ declare function assertToleranceQuorum(src: ParsedSource, signaturesRequired: number): void;
1223
+ /** A {@link ParsedSource} as is; a source document (text or object) parsed and validated. */
1224
+ declare function asParsedSource(source: ParsedSource | string | object): ParsedSource;
1225
+ /**
1226
+ * Render a signed 32-byte value for people, according to the source's output: a scaled integer with
1227
+ * its decimal point, a bool, a string32's text, or hex. It is display only; nothing here is signed.
1228
+ */
1229
+ declare function formatValue(valuePacked: string, output: {
1230
+ type: OutputType;
1231
+ decimals: number;
1232
+ }): string;
1233
+ /** Whether `preimageHex` hashes (keccak256) to the signed value, as a `keccak256` output requires. */
1234
+ declare function verifyPreimage(valuePacked: string, preimageHex: string): boolean;
1235
+ /**
1236
+ * Solana programs known to write their accounts every slot (AMM pools, order books). The list is
1237
+ * not exhaustive: it is for catching the common mistake, not for proving a source safe.
1238
+ */
1239
+ declare const PER_SLOT_WRITE_PROGRAMS: Record<string, string>;
1240
+ interface LintFinding {
1241
+ severity: "error" | "warning";
1242
+ /** The input the finding is about. */
1243
+ input: string;
1244
+ message: string;
1245
+ }
1246
+ /**
1247
+ * Advisory checks that need more than the schema. An svm account read in exact mode works only if the
1248
+ * account changes slowly: nodes land on slots a few hundred ms apart, and exact mode signs only when
1249
+ * every node decodes the same bytes. With `ownerOf` (an RPC lookup of the account's owner program) a
1250
+ * read of an account owned by a known per-slot-write program is an error; without it every svm account
1251
+ * read in exact mode is a warning.
1252
+ */
1253
+ declare function lintSource(src: ParsedSource, opts?: {
1254
+ ownerOf?: (chain: string, address: string) => Promise<string | undefined>;
1255
+ }): Promise<LintFinding[]>;
1256
+
1257
+ type sourcebuild_Decode = Decode;
1258
+ type sourcebuild_Finality = Finality;
1259
+ type sourcebuild_LintFinding = LintFinding;
1260
+ declare const sourcebuild_MIN_TOLERANCE_SIGNATURES: typeof MIN_TOLERANCE_SIGNATURES;
1261
+ declare const sourcebuild_PER_SLOT_WRITE_PROGRAMS: typeof PER_SLOT_WRITE_PROGRAMS;
1262
+ type sourcebuild_Round = Round;
1263
+ type sourcebuild_SourceInput = SourceInput;
1264
+ declare const sourcebuild_abiDecode: typeof abiDecode;
1265
+ declare const sourcebuild_abs: typeof abs;
1266
+ declare const sourcebuild_add: typeof add;
1267
+ declare const sourcebuild_asParsedSource: typeof asParsedSource;
1268
+ declare const sourcebuild_assertToleranceQuorum: typeof assertToleranceQuorum;
1269
+ declare const sourcebuild_boolLit: typeof boolLit;
1270
+ declare const sourcebuild_bytesLit: typeof bytesLit;
1271
+ declare const sourcebuild_coalesce: typeof coalesce;
1272
+ declare const sourcebuild_concat: typeof concat;
1273
+ declare const sourcebuild_cst: typeof cst;
1274
+ declare const sourcebuild_csvDecode: typeof csvDecode;
1275
+ declare const sourcebuild_defineSource: typeof defineSource;
1276
+ declare const sourcebuild_div: typeof div;
1277
+ declare const sourcebuild_eq: typeof eq;
1278
+ declare const sourcebuild_evmBalance: typeof evmBalance;
1279
+ declare const sourcebuild_evmCall: typeof evmCall;
1280
+ declare const sourcebuild_evmStorage: typeof evmStorage;
1281
+ declare const sourcebuild_feltsDecode: typeof feltsDecode;
1282
+ declare const sourcebuild_formatValue: typeof formatValue;
1283
+ declare const sourcebuild_gt: typeof gt;
1284
+ declare const sourcebuild_gte: typeof gte;
1285
+ declare const sourcebuild_hexBytes: typeof hexBytes;
1286
+ declare const sourcebuild_httpInput: typeof httpInput;
1287
+ declare const sourcebuild_iff: typeof iff;
1288
+ declare const sourcebuild_int: typeof int;
1289
+ declare const sourcebuild_jsonDecode: typeof jsonDecode;
1290
+ declare const sourcebuild_jsonPriceSource: typeof jsonPriceSource;
1291
+ declare const sourcebuild_keccak256: typeof keccak256;
1292
+ declare const sourcebuild_layoutDecode: typeof layoutDecode;
1293
+ declare const sourcebuild_lintSource: typeof lintSource;
1294
+ declare const sourcebuild_lower: typeof lower;
1295
+ declare const sourcebuild_lt: typeof lt;
1296
+ declare const sourcebuild_lte: typeof lte;
1297
+ declare const sourcebuild_max: typeof max;
1298
+ declare const sourcebuild_min: typeof min;
1299
+ declare const sourcebuild_mul: typeof mul;
1300
+ declare const sourcebuild_ne: typeof ne;
1301
+ declare const sourcebuild_neg: typeof neg;
1302
+ declare const sourcebuild_num: typeof num;
1303
+ declare const sourcebuild_rawDecode: typeof rawDecode;
1304
+ declare const sourcebuild_ref: typeof ref;
1305
+ declare const sourcebuild_rescale: typeof rescale;
1306
+ declare const sourcebuild_shift: typeof shift;
1307
+ declare const sourcebuild_slice: typeof slice;
1308
+ declare const sourcebuild_sourceDocFor: typeof sourceDocFor;
1309
+ declare const sourcebuild_starknetCall: typeof starknetCall;
1310
+ declare const sourcebuild_str: typeof str;
1311
+ declare const sourcebuild_strLit: typeof strLit;
1312
+ declare const sourcebuild_sub: typeof sub;
1313
+ declare const sourcebuild_svmAccount: typeof svmAccount;
1314
+ declare const sourcebuild_svmTokenSupply: typeof svmTokenSupply;
1315
+ declare const sourcebuild_textDecode: typeof textDecode;
1316
+ declare const sourcebuild_upper: typeof upper;
1317
+ declare const sourcebuild_verifyPreimage: typeof verifyPreimage;
1318
+ declare const sourcebuild_xmlDecode: typeof xmlDecode;
1319
+ declare namespace sourcebuild {
1320
+ export { sourcebuild_MIN_TOLERANCE_SIGNATURES as MIN_TOLERANCE_SIGNATURES, sourcebuild_PER_SLOT_WRITE_PROGRAMS as PER_SLOT_WRITE_PROGRAMS, sourcebuild_abiDecode as abiDecode, sourcebuild_abs as abs, sourcebuild_add as add, sourcebuild_asParsedSource as asParsedSource, sourcebuild_assertToleranceQuorum as assertToleranceQuorum, sourcebuild_boolLit as boolLit, sourcebuild_bytesLit as bytesLit, sourcebuild_coalesce as coalesce, sourcebuild_concat as concat, sourcebuild_cst as cst, sourcebuild_csvDecode as csvDecode, sourcebuild_defineSource as defineSource, sourcebuild_div as div, sourcebuild_eq as eq, sourcebuild_evmBalance as evmBalance, sourcebuild_evmCall as evmCall, sourcebuild_evmStorage as evmStorage, sourcebuild_feltsDecode as feltsDecode, sourcebuild_formatValue as formatValue, sourcebuild_gt as gt, sourcebuild_gte as gte, sourcebuild_hexBytes as hexBytes, sourcebuild_httpInput as httpInput, sourcebuild_iff as iff, sourcebuild_int as int, sourcebuild_jsonDecode as jsonDecode, sourcebuild_jsonPriceSource as jsonPriceSource, sourcebuild_keccak256 as keccak256, sourcebuild_layoutDecode as layoutDecode, sourcebuild_lintSource as lintSource, sourcebuild_lower as lower, sourcebuild_lt as lt, sourcebuild_lte as lte, sourcebuild_max as max, sourcebuild_min as min, sourcebuild_mul as mul, sourcebuild_ne as ne, sourcebuild_neg as neg, sourcebuild_num as num, sourcebuild_rawDecode as rawDecode, sourcebuild_ref as ref, sourcebuild_rescale as rescale, sourcebuild_shift as shift, sourcebuild_slice as slice, sourcebuild_sourceDocFor as sourceDocFor, sourcebuild_starknetCall as starknetCall, sourcebuild_str as str, sourcebuild_strLit as strLit, sourcebuild_sub as sub, sourcebuild_svmAccount as svmAccount, sourcebuild_svmTokenSupply as svmTokenSupply, sourcebuild_textDecode as textDecode, sourcebuild_upper as upper, sourcebuild_verifyPreimage as verifyPreimage, sourcebuild_xmlDecode as xmlDecode };
1321
+ export type { sourcebuild_Decode as Decode, sourcebuild_Finality as Finality, sourcebuild_LintFinding as LintFinding, sourcebuild_Round as Round, sourcebuild_SourceInput as SourceInput };
1322
+ }
1323
+
947
1324
  /**
948
1325
  * `timestamp` is unix MILLISECONDS, assigned by the gateway. Chain clocks (Solana `Clock`,
949
1326
  * EVM `block.timestamp`), epoch windows and `maxAge`/staleness are measured in SECONDS, so
@@ -1536,7 +1913,8 @@ declare function feedPda(sourceId: Uint8Array, signaturesRequired: number, submi
1536
1913
 
1537
1914
  /** One feed to update. */
1538
1915
  interface BulkFeed {
1539
- apiConfig: APIConfig;
1916
+ /** The source to update; parse it once (`defineSource`, `parseSource`) when updating many feeds. */
1917
+ source: ParsedSource | string | object;
1540
1918
  signaturesRequired: number;
1541
1919
  /** Echoed in the result; for the caller's own bookkeeping. */
1542
1920
  label?: string;
@@ -1558,9 +1936,9 @@ interface BulkOptions {
1558
1936
  submitConcurrency?: number;
1559
1937
  /**
1560
1938
  * Options applied to every request (subscription owner, signer, `maxRetries`, `timeoutMs`, ...).
1561
- * `apiConfig`, `signaturesRequired` and `context` are set per feed.
1939
+ * `source`, `signaturesRequired` and `context` are set per feed.
1562
1940
  */
1563
- request?: Omit<RequestSignedDataOptions, "apiConfig" | "signaturesRequired" | "context">;
1941
+ request?: Omit<RequestSignedDataOptions, "source" | "signaturesRequired" | "context">;
1564
1942
  /** Called as each feed finishes, in completion order. */
1565
1943
  onResult?: (result: BulkResult) => void;
1566
1944
  /** Stops starting new feeds; those already started finish. */
@@ -1673,4 +2051,5 @@ declare class MolphaSDK {
1673
2051
  }>;
1674
2052
  }
1675
2053
 
1676
- export { APIConfig, AdaptiveLimiter, AggregationConfig, AggregationConfigError, AssetDomain, Attestation, type AttestationMessageFields, BatchTooLargeError, type BuildEvmVerifierArgsOptions, type BuildStarknetVerifierArgsOptions, type BulkFeed, type BulkOptions, type BulkResult, type CoalitionKey, DEFAULT_GATEWAY_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_ROUND_TIMEOUT_MS, EIP712_DOMAIN_TYPEHASH, type Eip712Domain, type EvmAttestation, type EvmAttestationPayload, type EvmSchnorrSignature, EvmSigner, type EvmVerifierArgs, type EvmVerifyResult, type FeedAccount, type GatewayEndpoint, type GatewayEndpointInput, GatewayError, type GatewayInfo, INT256_MAX, INT256_MIN, MESSAGE_PREFIX, MIN_TOLERANCE_SIGNATURES, MOLPHA_DEV_VERIFIERS_PROVISIONAL, MOLPHA_IDL, MOLPHA_PROGRAM_ADDRESS, MOLPHA_PROGRAM_ID, MOLPHA_SDK_PROFILE, MOLPHA_VERIFIER_ABI, MOLPHA_VERIFIER_ADDRESS, MOLPHA_VERIFIER_STARKNET_ADDRESSES, MOLPHA_VERIFIER_STARKNET_SEPOLIA, type MolphaEvmNetwork, MolphaGateway, type MolphaGatewayOptions, MolphaSDK, type MolphaSDKOptions, MolphaSolanaClient, type MolphaStarknetNetwork, MolphaWallet, Node, NodeKeyVerifier, NodeKeyVerifierArgs, NodesInfo, type PlanId, type PlanInfo, PlanType, REQUEST_AUTH_DOMAIN, ROUND_TICK_MS, RegistrySelectionConfig, type RegistryStateView, type RegistryView, type RequestAuthFields, type RequestSignedDataOptions, type RetryCause, type RoundContext, SELECTION_WINDOW_MS, SUBMIT_INSTRUCTION_DATA_BYTES, type Secp256k1KeyInput, Signer, SourcePaymentOptions, type StarknetAttestation, type StarknetAttestationPayload, type StarknetFeltLike, type StarknetSchnorrSignature, type StarknetVerifierArgs, type StarknetVerifyResult, type SubmitAttestationArgs, type SubmitAttestationOptions, type SubmitAttestationsOptions, type SubmitAttestationsResult, SubmitFailedError, type SubmitResult, type SubscribeResult, type SubscriptionInfo, TRANSFER_WITH_AUTHORIZATION_TYPEHASH, type TransferAuthorization, UpstreamPaymentRequiredError, UpstreamQuote, UpstreamTerms, VERIFY_CODES, type VerifyCode, type VerifyCodeName, addressToBytes, assertAggregationQuorum, attestationMessageHash, attestationMessageHashFromAttestation, base64ToBytes, bigIntFromBytesBe, bitmapBitSet, bitmapToIndices, buildEvmVerifierArgs, buildStarknetVerifierArgs, buildSubmitAttestationArgs, bytesToBase64, bytesToHex, bytesToHex0x, canonicalizeAPIConfig, canonicalizeAggregation, commitmentAddressToStarknetFelt, computeCoalitionKey, concatBytes, createEvmSignerFromPrivateKey, decodeInt256, deriveGatewayPda, deriveGatewayPdaAddress, deriveGroupBitmap, deriveSelectionBitmap, deriveSelectionSeed, deriveSourceId, deriveSourceIdString, domainSeparator, effectiveSelectionSize, eligibleSetSize, encodeEvmVerifyCalldata, encodeInt256, encodeInt256Decimal, encodeRequestAuth, encodeStarknetVerifyCalldata, ensureLength, estimateSubmitBatchComputeUnits, estimateSubmitComputeUnits, estimateSubmitTransactionSize, evmAddressFromPrivateKey, feedPda, formatInt256Decimal, gatewayPda, getMolphaStarknetVerifierAddress, hashRequestAuth, hexToBytes, maxAttestationsPerTransaction, nodePda, normalizeEndpoint, normalizeSecp256k1PublicKeyHex, parseEvmVerifyResult, parseGatewayInfo, parseStarknetVerifyResult, parseUpstreamQuote, planIdFromVariant, planPda, planVariant, probeSource, protocolConfigPda, registryPda, registryStatePda, requestMany, resolveRemainingAccounts, retryDelayMs, secp256k1PublicKeyFromCoordinates, selectedIndices, signSourcePayments, signersBitmapToDecimal, signersBitmapToStarknetUint256, signersBitmapToUint256, spreadOffsetMs, subscriptionPda, timestampAgeSeconds, timestampSeconds, toChecksumAddress, toFixedBytes, toFixedHex, transferWithAuthorizationDigest, transferWithAuthorizationHash, u256beFromBigInt, u32be, u32le, u64be, u64le, u8, utf8, validateSuppliedTerms, verifyCodeName };
2054
+ export { AdaptiveLimiter, AssetDomain, Attestation, BatchTooLargeError, CHAIN_LIST, DEFAULT_GATEWAY_ENDPOINT, DEFAULT_MAX_RETRIES, DEFAULT_ROUND_TIMEOUT_MS, EIP712_DOMAIN_TYPEHASH, EvmSigner, GatewayError, INT256_MAX, INT256_MIN, MAX_ASSERTS, MAX_BODY_TEXT, MAX_CANONICAL_BYTES, MAX_DECIMAL_SCALE, MAX_EXPR_DEPTH, MAX_EXPR_NODES, MAX_FIELDS, MAX_HEADERS, MAX_HEADER_VALUE, MAX_INPUTS, MAX_OUTPUT_DECIMALS, MAX_PRIVATE_BYTES, MAX_RESPONSE_BYTES, MESSAGE_PREFIX, MIN_TOLERANCE_SIGNATURES, MOLPHA_DEV_VERIFIERS_PROVISIONAL, MOLPHA_IDL, MOLPHA_PROGRAM_ADDRESS, MOLPHA_PROGRAM_ID, MOLPHA_SDK_PROFILE, MOLPHA_VERIFIER_ABI, MOLPHA_VERIFIER_ADDRESS, MOLPHA_VERIFIER_STARKNET_ADDRESSES, MOLPHA_VERIFIER_STARKNET_SEPOLIA, MolphaGateway, MolphaSDK, MolphaSolanaClient, MolphaWallet, Node, NodeKeyVerifier, NodeKeyVerifierArgs, NodesInfo, OUTPUT_TYPES, PER_SLOT_WRITE_PROGRAMS, PlanType, REQUEST_AUTH_DOMAIN, ROUND_TICK_MS, RegistrySelectionConfig, SELECTION_WINDOW_MS, SOURCE_VERSION, SUBMIT_INSTRUCTION_DATA_BYTES, Signer, SourceError, SourcePaymentOptions, SubmitFailedError, TRANSFER_WITH_AUTHORIZATION_TYPEHASH, UpstreamPaymentRequiredError, UpstreamQuote, UpstreamTerms, VERIFY_CODES, addressToBytes, asParsedSource, assertToleranceQuorum, attestationMessageHash, attestationMessageHashFromAttestation, base64ToBytes, bigIntFromBytesBe, bitmapBitSet, bitmapToIndices, buildEvmVerifierArgs, buildStarknetVerifierArgs, buildSubmitAttestationArgs, bytesToBase64, bytesToHex, bytesToHex0x, canonicalJson, canonicalize, checkChains, commitmentAddressToStarknetFelt, computeCoalitionKey, concatBytes, createEvmSignerFromPrivateKey, decodeInt256, defineSource, deriveGatewayPda, deriveGatewayPdaAddress, deriveGroupBitmap, deriveSelectionBitmap, deriveSelectionSeed, deriveSourceId, deriveSourceIdHex, domainSeparator, effectiveSelectionSize, eligibleSetSize, encodeEvmVerifyCalldata, encodeInt256, encodeInt256Decimal, encodeRequestAuth, encodeSourceBytes, encodeStarknetVerifyCalldata, ensureLength, estimateSubmitBatchComputeUnits, estimateSubmitComputeUnits, estimateSubmitTransactionSize, evmAddressFromPrivateKey, feedPda, formatInt256Decimal, formatValue, fromPlain, gatewayPda, getMolphaStarknetVerifierAddress, hasPreimage, hashRequestAuth, hexToBytes, jsonPriceSource, lintSource, maxAttestationsPerTransaction, nodePda, normalizeEndpoint, normalizeSecp256k1PublicKeyHex, parseCanonicalSource, parseEvmVerifyResult, parseGatewayInfo, parsePrivateSource, parseSource, parseStarknetVerifyResult, parseStrict, parseUpstreamQuote, planIdFromVariant, planPda, planVariant, probeSource, protocolConfigPda, registryPda, registryStatePda, requestMany, resolveRemainingAccounts, retryDelayMs, secp256k1PublicKeyFromCoordinates, selectedIndices, signSourcePayments, signersBitmapToDecimal, signersBitmapToStarknetUint256, signersBitmapToUint256, sourceDocFor, sourceIdOf, splitURL, spreadOffsetMs, subscriptionPda, sourcebuild as sx, timestampAgeSeconds, timestampSeconds, toChecksumAddress, toFixedBytes, toFixedHex, toPlain, transferWithAuthorizationDigest, transferWithAuthorizationHash, u256beFromBigInt, u32be, u32le, u64be, u64le, u8, utf8, validateSuppliedTerms, verifyCodeName, verifyPreimage };
2055
+ export type { AggregationDoc, AttestationMessageFields, BuildEvmVerifierArgsOptions, BuildStarknetVerifierArgsOptions, BulkFeed, BulkOptions, BulkResult, Chain, CoalitionKey, Decode, Eip712Domain, EvmAttestation, EvmAttestationPayload, EvmSchnorrSignature, EvmVerifierArgs, EvmVerifyResult, Expr, FeedAccount, Finality, GatewayEndpoint, GatewayEndpointInput, GatewayInfo, JObj, Json, LintFinding, MolphaEvmNetwork, MolphaGatewayOptions, MolphaSDKOptions, MolphaStarknetNetwork, OutputDoc, OutputType, ParsedSource, PlanId, PlanInfo, RegistryStateView, RegistryView, RequestAuthFields, RequestSignedDataOptions, RetryCause, Round, RoundContext, Secp256k1KeyInput, SourceDoc, SourceErrorClass, SourceInput, StarknetAttestation, StarknetAttestationPayload, StarknetFeltLike, StarknetSchnorrSignature, StarknetVerifierArgs, StarknetVerifyResult, SubmitAttestationArgs, SubmitAttestationOptions, SubmitAttestationsOptions, SubmitAttestationsResult, SubmitResult, SubscribeResult, SubscriptionInfo, TransferAuthorization, URLParts, VerifyCode, VerifyCodeName };