@symbiome-forge/cow-sdk-wasm 0.1.0-alpha.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.
Files changed (119) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +278 -0
  3. package/dist/cloudflare/callbacks.cjs +2 -0
  4. package/dist/cloudflare/callbacks.d.ts +55 -0
  5. package/dist/cloudflare/callbacks.js +1 -0
  6. package/dist/cloudflare/envelope.cjs +2 -0
  7. package/dist/cloudflare/envelope.d.ts +5 -0
  8. package/dist/cloudflare/envelope.js +1 -0
  9. package/dist/cloudflare/errors.cjs +150 -0
  10. package/dist/cloudflare/errors.d.ts +82 -0
  11. package/dist/cloudflare/errors.js +145 -0
  12. package/dist/cloudflare/index.cjs +286 -0
  13. package/dist/cloudflare/index.d.ts +78 -0
  14. package/dist/cloudflare/index.js +1 -0
  15. package/dist/cloudflare/index.mjs +223 -0
  16. package/dist/cloudflare/internal.cjs +127 -0
  17. package/dist/cloudflare/internal.d.ts +40 -0
  18. package/dist/cloudflare/internal.js +115 -0
  19. package/dist/cloudflare/options.cjs +2 -0
  20. package/dist/cloudflare/options.d.ts +70 -0
  21. package/dist/cloudflare/options.js +1 -0
  22. package/dist/cloudflare/raw/cloudflare.cjs +65 -0
  23. package/dist/cloudflare/raw/cloudflare.d.ts +30 -0
  24. package/dist/cloudflare/raw/cloudflare.js +29 -0
  25. package/dist/default/callbacks.cjs +2 -0
  26. package/dist/default/callbacks.d.ts +55 -0
  27. package/dist/default/callbacks.js +1 -0
  28. package/dist/default/envelope.cjs +2 -0
  29. package/dist/default/envelope.d.ts +5 -0
  30. package/dist/default/envelope.js +1 -0
  31. package/dist/default/errors.cjs +150 -0
  32. package/dist/default/errors.d.ts +82 -0
  33. package/dist/default/errors.js +145 -0
  34. package/dist/default/index.cjs +359 -0
  35. package/dist/default/index.d.ts +94 -0
  36. package/dist/default/index.js +1 -0
  37. package/dist/default/index.mjs +295 -0
  38. package/dist/default/internal.cjs +127 -0
  39. package/dist/default/internal.d.ts +40 -0
  40. package/dist/default/internal.js +115 -0
  41. package/dist/default/options.cjs +2 -0
  42. package/dist/default/options.d.ts +70 -0
  43. package/dist/default/options.js +1 -0
  44. package/dist/default/raw/default.cjs +66 -0
  45. package/dist/default/raw/default.d.ts +31 -0
  46. package/dist/default/raw/default.js +30 -0
  47. package/dist/orderbook/callbacks.cjs +2 -0
  48. package/dist/orderbook/callbacks.d.ts +55 -0
  49. package/dist/orderbook/callbacks.js +1 -0
  50. package/dist/orderbook/envelope.cjs +2 -0
  51. package/dist/orderbook/envelope.d.ts +5 -0
  52. package/dist/orderbook/envelope.js +1 -0
  53. package/dist/orderbook/errors.cjs +150 -0
  54. package/dist/orderbook/errors.d.ts +82 -0
  55. package/dist/orderbook/errors.js +145 -0
  56. package/dist/orderbook/index.cjs +195 -0
  57. package/dist/orderbook/index.d.ts +57 -0
  58. package/dist/orderbook/index.js +1 -0
  59. package/dist/orderbook/index.mjs +139 -0
  60. package/dist/orderbook/internal.cjs +127 -0
  61. package/dist/orderbook/internal.d.ts +40 -0
  62. package/dist/orderbook/internal.js +115 -0
  63. package/dist/orderbook/options.cjs +2 -0
  64. package/dist/orderbook/options.d.ts +70 -0
  65. package/dist/orderbook/options.js +1 -0
  66. package/dist/orderbook/raw/orderbook.cjs +58 -0
  67. package/dist/orderbook/raw/orderbook.d.ts +23 -0
  68. package/dist/orderbook/raw/orderbook.js +22 -0
  69. package/dist/raw/cloudflare-web/cow_sdk_wasm.d.ts +2870 -0
  70. package/dist/raw/cloudflare-web/cow_sdk_wasm.js +2183 -0
  71. package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm +0 -0
  72. package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm.d.ts +65 -0
  73. package/dist/raw/default-bundler/cow_sdk_wasm.d.ts +2916 -0
  74. package/dist/raw/default-bundler/cow_sdk_wasm.js +9 -0
  75. package/dist/raw/default-bundler/cow_sdk_wasm_bg.js +2297 -0
  76. package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm +0 -0
  77. package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm.d.ts +75 -0
  78. package/dist/raw/default-nodejs/cow_sdk_wasm.cjs +2330 -0
  79. package/dist/raw/default-nodejs/cow_sdk_wasm.d.ts +2916 -0
  80. package/dist/raw/default-nodejs/cow_sdk_wasm_bg.wasm.d.ts +75 -0
  81. package/dist/raw/orderbook-bundler/cow_sdk_wasm.d.ts +1876 -0
  82. package/dist/raw/orderbook-bundler/cow_sdk_wasm.js +9 -0
  83. package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.js +1636 -0
  84. package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm +0 -0
  85. package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm.d.ts +50 -0
  86. package/dist/raw/orderbook-nodejs/cow_sdk_wasm.cjs +1661 -0
  87. package/dist/raw/orderbook-nodejs/cow_sdk_wasm.d.ts +1876 -0
  88. package/dist/raw/orderbook-nodejs/cow_sdk_wasm_bg.wasm.d.ts +50 -0
  89. package/dist/raw/signing-bundler/cow_sdk_wasm.d.ts +774 -0
  90. package/dist/raw/signing-bundler/cow_sdk_wasm.js +9 -0
  91. package/dist/raw/signing-bundler/cow_sdk_wasm_bg.js +1059 -0
  92. package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm +0 -0
  93. package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm.d.ts +27 -0
  94. package/dist/raw/signing-nodejs/cow_sdk_wasm.cjs +1078 -0
  95. package/dist/raw/signing-nodejs/cow_sdk_wasm.d.ts +774 -0
  96. package/dist/raw/signing-nodejs/cow_sdk_wasm_bg.wasm.d.ts +27 -0
  97. package/dist/signing/callbacks.cjs +2 -0
  98. package/dist/signing/callbacks.d.ts +55 -0
  99. package/dist/signing/callbacks.js +1 -0
  100. package/dist/signing/envelope.cjs +2 -0
  101. package/dist/signing/envelope.d.ts +5 -0
  102. package/dist/signing/envelope.js +1 -0
  103. package/dist/signing/errors.cjs +150 -0
  104. package/dist/signing/errors.d.ts +82 -0
  105. package/dist/signing/errors.js +145 -0
  106. package/dist/signing/index.cjs +93 -0
  107. package/dist/signing/index.d.ts +23 -0
  108. package/dist/signing/index.js +1 -0
  109. package/dist/signing/index.mjs +44 -0
  110. package/dist/signing/internal.cjs +127 -0
  111. package/dist/signing/internal.d.ts +40 -0
  112. package/dist/signing/internal.js +115 -0
  113. package/dist/signing/options.cjs +2 -0
  114. package/dist/signing/options.d.ts +70 -0
  115. package/dist/signing/options.js +1 -0
  116. package/dist/signing/raw/signing.cjs +52 -0
  117. package/dist/signing/raw/signing.d.ts +17 -0
  118. package/dist/signing/raw/signing.js +16 -0
  119. package/package.json +112 -0
@@ -0,0 +1,223 @@
1
+ import * as raw from "./raw/cloudflare.js";
2
+ import { assertActive, callAsync, callSync, defaultsFrom, disposeRaw, mergeOptions, mergeSigningOptions, translateClientConfig } from "./internal.js";
3
+ let initialized;
4
+ export async function initialize(module) {
5
+ if (!initialized) {
6
+ initialized = raw.initializeRaw({ module_or_path: module }).then(() => undefined);
7
+ }
8
+ await initialized;
9
+ }
10
+ export default initialize;
11
+ export class OrderBookClient {
12
+ #inner;
13
+ #defaults;
14
+ #disposed = false;
15
+ constructor(config) {
16
+ try {
17
+ this.#defaults = defaultsFrom(config);
18
+ this.#inner = new raw.RawOrderBookClient(translateClientConfig(config));
19
+ }
20
+ catch (error) {
21
+ throw callSync(() => {
22
+ throw error;
23
+ });
24
+ }
25
+ }
26
+ async cancelOrders(signed, options) {
27
+ return this.#call((client, merged) => client.cancelOrders(signed, merged), options);
28
+ }
29
+ async getNativePrice(token, options) {
30
+ return this.#call((client, merged) => client.getNativePrice(token, merged), options);
31
+ }
32
+ async getOrder(orderUid, options) {
33
+ return this.#call((client, merged) => client.getOrder(orderUid, merged), options);
34
+ }
35
+ async getOrders(owner, pagination, options) {
36
+ return this.#call((client, merged) => client.getOrders(owner, pagination ?? null, merged), options);
37
+ }
38
+ async getOrderMultiEnv(orderUid, options) {
39
+ return this.#call((client, merged) => client.getOrderMultiEnv(orderUid, merged), options);
40
+ }
41
+ async getTxOrders(txHash, options) {
42
+ return this.#call((client, merged) => client.getTxOrders(txHash, merged), options);
43
+ }
44
+ async getVersion(options) {
45
+ return this.#call((client, merged) => client.getVersion(merged), options);
46
+ }
47
+ getOrderLink(orderUid) {
48
+ assertActive(this.#disposed);
49
+ return callSync(() => this.#inner.getOrderLink(orderUid));
50
+ }
51
+ async getQuote(request, options) {
52
+ return this.#call((client, merged) => client.getQuote(request, merged), options);
53
+ }
54
+ async getTrades(query, options) {
55
+ return this.#call((client, merged) => client.getTrades(query, merged), options);
56
+ }
57
+ async getOrderCompetitionStatus(orderUid, options) {
58
+ return this.#call((client, merged) => client.getOrderCompetitionStatus(orderUid, merged), options);
59
+ }
60
+ async getTotalSurplus(owner, options) {
61
+ return this.#call((client, merged) => client.getTotalSurplus(owner, merged), options);
62
+ }
63
+ async getAppData(appDataHash, options) {
64
+ return this.#call((client, merged) => client.getAppData(appDataHash, merged), options);
65
+ }
66
+ async uploadAppData(appDataHash, fullAppData, options) {
67
+ return this.#call((client, merged) => client.uploadAppData(appDataHash, fullAppData, merged), options);
68
+ }
69
+ async sendOrder(signed, options) {
70
+ return this.#call((client, merged) => client.sendOrder(signed, merged), options);
71
+ }
72
+ async sendOrderCreation(input, options) {
73
+ return this.#call((client, merged) => client.sendOrderCreation(input, merged), options);
74
+ }
75
+ dispose() {
76
+ if (!this.#disposed) {
77
+ disposeRaw(this.#inner);
78
+ this.#disposed = true;
79
+ }
80
+ }
81
+ [Symbol.dispose]() {
82
+ this.dispose();
83
+ }
84
+ #call(operation, options) {
85
+ return callAsync(() => {
86
+ assertActive(this.#disposed);
87
+ return operation(this.#inner, mergeOptions(this.#defaults, options));
88
+ });
89
+ }
90
+ }
91
+ export class TradingClient {
92
+ #inner;
93
+ #defaults;
94
+ #disposed = false;
95
+ constructor(config) {
96
+ try {
97
+ this.#defaults = defaultsFrom(config);
98
+ this.#inner = new raw.RawTradingClient(translateClientConfig(config));
99
+ }
100
+ catch (error) {
101
+ throw callSync(() => {
102
+ throw error;
103
+ });
104
+ }
105
+ }
106
+ async buildSellNativeCurrencyTx(order, quoteId, from, options) {
107
+ return this.#call((client, merged) => client.buildSellNativeCurrencyTx(order, quoteId, from, merged), options);
108
+ }
109
+ async getCowProtocolAllowance(params, readContractCallback, options) {
110
+ return this.#call((client, merged) => client.getCowProtocolAllowance(params, readContractCallback, merged), options);
111
+ }
112
+ async buildApprovalTx(params, options) {
113
+ return this.#call((client, merged) => client.buildApprovalTx(params, merged), options);
114
+ }
115
+ async getQuote(params, options) {
116
+ return this.#call((client, merged) => client.getQuote(params, merged), options);
117
+ }
118
+ async postLimitOrder(params, owner, signerCallback, options) {
119
+ return this.#callSigning((client, merged) => client.postLimitOrder(params, owner, signerCallback, merged ?? null), options);
120
+ }
121
+ async postSwapOrder(params, owner, signerCallback, options) {
122
+ return this.#callSigning((client, merged) => client.postSwapOrder(params, owner, signerCallback, merged ?? null), options);
123
+ }
124
+ async postSwapOrderFromQuote(quoteResults, owner, signerCallback, options) {
125
+ return this.#callSigning((client, merged) => client.postSwapOrderFromQuote(quoteResults, owner, signerCallback, merged ?? null), options);
126
+ }
127
+ async postSwapOrderWithEip1271(params, owner, customCallback, options) {
128
+ return this.#callSigning((client, merged) => client.postSwapOrderWithEip1271(params, owner, customCallback, merged ?? null), options);
129
+ }
130
+ dispose() {
131
+ if (!this.#disposed) {
132
+ disposeRaw(this.#inner);
133
+ this.#disposed = true;
134
+ }
135
+ }
136
+ [Symbol.dispose]() {
137
+ this.dispose();
138
+ }
139
+ #call(operation, options) {
140
+ return callAsync(() => {
141
+ assertActive(this.#disposed);
142
+ return operation(this.#inner, mergeOptions(this.#defaults, options));
143
+ });
144
+ }
145
+ #callSigning(operation, options) {
146
+ return callAsync(() => {
147
+ assertActive(this.#disposed);
148
+ return operation(this.#inner, mergeSigningOptions(this.#defaults, options));
149
+ });
150
+ }
151
+ }
152
+ export function appDataDoc(doc) {
153
+ return callSync(() => raw.appDataDoc(doc));
154
+ }
155
+ export function appDataHexToCid(appDataHex) {
156
+ return callSync(() => raw.appDataHexToCid(appDataHex));
157
+ }
158
+ export function appDataInfo(doc) {
159
+ return callSync(() => raw.appDataInfo(doc));
160
+ }
161
+ export function buildCancelOrderTx(params) {
162
+ return callSync(() => raw.buildCancelOrderTx(params));
163
+ }
164
+ export function buildPresignTx(params) {
165
+ return callSync(() => raw.buildPresignTx(params));
166
+ }
167
+ export function cidToAppDataHex(cid) {
168
+ return callSync(() => raw.cidToAppDataHex(cid));
169
+ }
170
+ export function computeOrderUid(input, chainId, owner) {
171
+ return callSync(() => raw.computeOrderUid(input, chainId, owner));
172
+ }
173
+ export function decodeEthFlowLog(log) {
174
+ return callSync(() => raw.decodeEthFlowLog(log));
175
+ }
176
+ export function decodeSettlementLog(log) {
177
+ return callSync(() => raw.decodeSettlementLog(log));
178
+ }
179
+ export function deploymentAddresses(chainId, env) {
180
+ return callSync(() => raw.deploymentAddresses(chainId, env ?? null));
181
+ }
182
+ export function domainSeparator(chainId) {
183
+ return callSync(() => raw.domainSeparator(chainId));
184
+ }
185
+ export function eip1271SignaturePayload(input, ecdsaSignature) {
186
+ return callSync(() => raw.eip1271SignaturePayload(input, ecdsaSignature));
187
+ }
188
+ export function orderTypedData(input, chainId) {
189
+ return callSync(() => raw.orderTypedData(input, chainId));
190
+ }
191
+ export function signCancellationEthSignDigest(orderUids, chainId, digestSigner, options) {
192
+ return callAsync(() => raw.signCancellationEthSignDigest(orderUids, chainId, digestSigner, options ?? null));
193
+ }
194
+ export function signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options) {
195
+ return callAsync(() => raw.signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options ?? null));
196
+ }
197
+ export function signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options) {
198
+ return callAsync(() => raw.signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options ?? null));
199
+ }
200
+ export function signOrderEthSignDigest(input, chainId, owner, digestSigner, options) {
201
+ return callAsync(() => raw.signOrderEthSignDigest(input, chainId, owner, digestSigner, options ?? null));
202
+ }
203
+ export function signOrderWithCustomEip1271(input, chainId, owner, customCallback, options) {
204
+ return callAsync(() => raw.signOrderWithCustomEip1271(input, chainId, owner, customCallback, options ?? null));
205
+ }
206
+ export function signOrderWithEip1193(input, chainId, owner, requestCallback, options) {
207
+ return callAsync(() => raw.signOrderWithEip1193(input, chainId, owner, requestCallback, options ?? null));
208
+ }
209
+ export function signOrderWithEip1271(input, chainId, owner, typedDataSigner, options) {
210
+ return callAsync(() => raw.signOrderWithEip1271(input, chainId, owner, typedDataSigner, options ?? null));
211
+ }
212
+ export function signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options) {
213
+ return callAsync(() => raw.signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options ?? null));
214
+ }
215
+ export function supportedChainIds() {
216
+ return callSync(() => raw.supportedChainIds());
217
+ }
218
+ export function validateAppDataDoc(doc) {
219
+ return callSync(() => raw.validateAppDataDoc(doc));
220
+ }
221
+ export function wasmVersion() {
222
+ return callSync(() => raw.wasmVersion());
223
+ }
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.translateHttpTransport = translateHttpTransport;
4
+ exports.translateClientConfig = translateClientConfig;
5
+ exports.mergeOptions = mergeOptions;
6
+ exports.mergeSigningOptions = mergeSigningOptions;
7
+ exports.assertActive = assertActive;
8
+ exports.disposeRaw = disposeRaw;
9
+ exports.normalizeThrown = normalizeThrown;
10
+ exports.callAsync = callAsync;
11
+ exports.callSync = callSync;
12
+ exports.defaultsFrom = defaultsFrom;
13
+ const errors_js_1 = require("./errors.cjs");
14
+ function translateHttpTransport(transport) {
15
+ if (transport?.kind === "callback") {
16
+ return transport;
17
+ }
18
+ // An omitted transport (or `{ kind: "fetch" }` without an explicit fetch)
19
+ // defaults to the runtime's global `fetch`, matching the Rust builders'
20
+ // zero-config default.
21
+ const fetchFn = transport?.fetch ?? globalThis.fetch;
22
+ if (typeof fetchFn !== "function") {
23
+ throw (0, errors_js_1.invalidInput)("transport.fetch", "globalThis.fetch is unavailable; pass an explicit fetch function");
24
+ }
25
+ return {
26
+ kind: "callback",
27
+ callback: adaptFetchToCallback(fetchFn)
28
+ };
29
+ }
30
+ function translateClientConfig(config) {
31
+ const { signal: _signal, transport, ...rest } = config;
32
+ return {
33
+ ...rest,
34
+ transport: translateHttpTransport(transport)
35
+ };
36
+ }
37
+ function mergeOptions(defaults, options) {
38
+ const signal = options?.signal ?? defaults.signal;
39
+ if (signal?.aborted) {
40
+ throw (0, errors_js_1.cancelledError)();
41
+ }
42
+ const timeoutMs = options?.timeoutMs ?? defaults.timeoutMs ?? undefined;
43
+ if (signal || timeoutMs !== undefined) {
44
+ const merged = {};
45
+ if (signal) {
46
+ merged.signal = signal;
47
+ }
48
+ if (timeoutMs !== undefined && timeoutMs !== null) {
49
+ merged.timeoutMs = timeoutMs;
50
+ }
51
+ return merged;
52
+ }
53
+ return undefined;
54
+ }
55
+ /**
56
+ * Applies the client-level `signal`/`timeoutMs` defaults to a signing call
57
+ * while preserving the per-call `walletConfig`, and performs the same
58
+ * already-aborted short-circuit as {@link mergeOptions}. Signing methods take
59
+ * {@link SigningOptions} (a superset of {@link SdkClientOptions}), so the
60
+ * shared default propagation must not drop the wallet timeout.
61
+ */
62
+ function mergeSigningOptions(defaults, options) {
63
+ const merged = mergeOptions(defaults, options);
64
+ const walletConfig = options?.walletConfig;
65
+ if (walletConfig === undefined) {
66
+ return merged;
67
+ }
68
+ return { ...merged, walletConfig };
69
+ }
70
+ function assertActive(disposed) {
71
+ if (disposed) {
72
+ throw (0, errors_js_1.invalidInput)("client", "client has been disposed");
73
+ }
74
+ }
75
+ function disposeRaw(raw) {
76
+ raw?.free?.();
77
+ }
78
+ function normalizeThrown(error) {
79
+ return (0, errors_js_1.normalizeError)(error);
80
+ }
81
+ async function callAsync(operation) {
82
+ try {
83
+ return await operation();
84
+ }
85
+ catch (error) {
86
+ throw (0, errors_js_1.normalizeError)(error);
87
+ }
88
+ }
89
+ function callSync(operation) {
90
+ try {
91
+ return operation();
92
+ }
93
+ catch (error) {
94
+ throw (0, errors_js_1.normalizeError)(error);
95
+ }
96
+ }
97
+ function defaultsFrom(config) {
98
+ return {
99
+ signal: config.signal,
100
+ timeoutMs: config.timeoutMs
101
+ };
102
+ }
103
+ function adaptFetchToCallback(fetchFn) {
104
+ return async (request) => {
105
+ const init = {
106
+ method: request.method,
107
+ headers: request.headers
108
+ };
109
+ if (request.signal) {
110
+ init.signal = request.signal;
111
+ }
112
+ if (request.body !== undefined) {
113
+ init.body = request.body;
114
+ }
115
+ const response = await fetchFn(request.url, init);
116
+ const headers = {};
117
+ response.headers.forEach((value, key) => {
118
+ headers[key] = value;
119
+ });
120
+ return {
121
+ status: response.status,
122
+ statusText: response.statusText,
123
+ headers,
124
+ body: await response.text()
125
+ };
126
+ };
127
+ }
@@ -0,0 +1,40 @@
1
+ import { type CowError } from "./errors.js";
2
+ import type { CowFetchCallback } from "./callbacks.js";
3
+ import type { CommonClientConfig, HttpTransportConfig, SdkClientOptions, SigningOptions } from "./options.js";
4
+ export interface ClientDefaults {
5
+ signal: AbortSignal | undefined;
6
+ timeoutMs: number | null | undefined;
7
+ }
8
+ export type DisposableRawClient = {
9
+ free?: () => void;
10
+ };
11
+ export declare function translateHttpTransport(transport?: HttpTransportConfig): {
12
+ kind: "callback";
13
+ callback: CowFetchCallback;
14
+ };
15
+ export declare function translateClientConfig<T extends {
16
+ transport?: HttpTransportConfig;
17
+ }>(config: T): Omit<T, "signal" | "transport"> & {
18
+ transport: {
19
+ kind: "callback";
20
+ callback: CowFetchCallback;
21
+ };
22
+ };
23
+ export declare function mergeOptions(defaults: ClientDefaults, options?: SdkClientOptions | null): SdkClientOptions | undefined;
24
+ /**
25
+ * Applies the client-level `signal`/`timeoutMs` defaults to a signing call
26
+ * while preserving the per-call `walletConfig`, and performs the same
27
+ * already-aborted short-circuit as {@link mergeOptions}. Signing methods take
28
+ * {@link SigningOptions} (a superset of {@link SdkClientOptions}), so the
29
+ * shared default propagation must not drop the wallet timeout.
30
+ */
31
+ export declare function mergeSigningOptions(defaults: ClientDefaults, options?: SigningOptions | null): SigningOptions | undefined;
32
+ export declare function assertActive(disposed: boolean): void;
33
+ export declare function disposeRaw(raw: DisposableRawClient | undefined): void;
34
+ export declare function normalizeThrown(error: unknown): CowError;
35
+ export declare function callAsync<T>(operation: () => Promise<T>): Promise<T>;
36
+ export declare function callSync<T>(operation: () => T): T;
37
+ export declare function defaultsFrom(config: CommonClientConfig | {
38
+ signal?: AbortSignal;
39
+ timeoutMs?: number | null;
40
+ }): ClientDefaults;
@@ -0,0 +1,115 @@
1
+ import { cancelledError, invalidInput, normalizeError } from "./errors.js";
2
+ export function translateHttpTransport(transport) {
3
+ if (transport?.kind === "callback") {
4
+ return transport;
5
+ }
6
+ // An omitted transport (or `{ kind: "fetch" }` without an explicit fetch)
7
+ // defaults to the runtime's global `fetch`, matching the Rust builders'
8
+ // zero-config default.
9
+ const fetchFn = transport?.fetch ?? globalThis.fetch;
10
+ if (typeof fetchFn !== "function") {
11
+ throw invalidInput("transport.fetch", "globalThis.fetch is unavailable; pass an explicit fetch function");
12
+ }
13
+ return {
14
+ kind: "callback",
15
+ callback: adaptFetchToCallback(fetchFn)
16
+ };
17
+ }
18
+ export function translateClientConfig(config) {
19
+ const { signal: _signal, transport, ...rest } = config;
20
+ return {
21
+ ...rest,
22
+ transport: translateHttpTransport(transport)
23
+ };
24
+ }
25
+ export function mergeOptions(defaults, options) {
26
+ const signal = options?.signal ?? defaults.signal;
27
+ if (signal?.aborted) {
28
+ throw cancelledError();
29
+ }
30
+ const timeoutMs = options?.timeoutMs ?? defaults.timeoutMs ?? undefined;
31
+ if (signal || timeoutMs !== undefined) {
32
+ const merged = {};
33
+ if (signal) {
34
+ merged.signal = signal;
35
+ }
36
+ if (timeoutMs !== undefined && timeoutMs !== null) {
37
+ merged.timeoutMs = timeoutMs;
38
+ }
39
+ return merged;
40
+ }
41
+ return undefined;
42
+ }
43
+ /**
44
+ * Applies the client-level `signal`/`timeoutMs` defaults to a signing call
45
+ * while preserving the per-call `walletConfig`, and performs the same
46
+ * already-aborted short-circuit as {@link mergeOptions}. Signing methods take
47
+ * {@link SigningOptions} (a superset of {@link SdkClientOptions}), so the
48
+ * shared default propagation must not drop the wallet timeout.
49
+ */
50
+ export function mergeSigningOptions(defaults, options) {
51
+ const merged = mergeOptions(defaults, options);
52
+ const walletConfig = options?.walletConfig;
53
+ if (walletConfig === undefined) {
54
+ return merged;
55
+ }
56
+ return { ...merged, walletConfig };
57
+ }
58
+ export function assertActive(disposed) {
59
+ if (disposed) {
60
+ throw invalidInput("client", "client has been disposed");
61
+ }
62
+ }
63
+ export function disposeRaw(raw) {
64
+ raw?.free?.();
65
+ }
66
+ export function normalizeThrown(error) {
67
+ return normalizeError(error);
68
+ }
69
+ export async function callAsync(operation) {
70
+ try {
71
+ return await operation();
72
+ }
73
+ catch (error) {
74
+ throw normalizeError(error);
75
+ }
76
+ }
77
+ export function callSync(operation) {
78
+ try {
79
+ return operation();
80
+ }
81
+ catch (error) {
82
+ throw normalizeError(error);
83
+ }
84
+ }
85
+ export function defaultsFrom(config) {
86
+ return {
87
+ signal: config.signal,
88
+ timeoutMs: config.timeoutMs
89
+ };
90
+ }
91
+ function adaptFetchToCallback(fetchFn) {
92
+ return async (request) => {
93
+ const init = {
94
+ method: request.method,
95
+ headers: request.headers
96
+ };
97
+ if (request.signal) {
98
+ init.signal = request.signal;
99
+ }
100
+ if (request.body !== undefined) {
101
+ init.body = request.body;
102
+ }
103
+ const response = await fetchFn(request.url, init);
104
+ const headers = {};
105
+ response.headers.forEach((value, key) => {
106
+ headers[key] = value;
107
+ });
108
+ return {
109
+ status: response.status,
110
+ statusText: response.statusText,
111
+ headers,
112
+ body: await response.text()
113
+ };
114
+ };
115
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,70 @@
1
+ import type { CowEnv, CowFetchCallback, CowFetchRequest, CowFetchResponse } from "./callbacks.js";
2
+ export interface SdkClientOptions {
3
+ timeoutMs?: number;
4
+ signal?: AbortSignal;
5
+ }
6
+ export interface WalletConfig {
7
+ timeoutMs?: number;
8
+ }
9
+ export interface SigningOptions extends SdkClientOptions {
10
+ walletConfig?: WalletConfig;
11
+ }
12
+ export type HttpTransportConfig = {
13
+ kind: "fetch";
14
+ fetch?: typeof globalThis.fetch;
15
+ } | {
16
+ kind: "callback";
17
+ callback: CowFetchCallback;
18
+ };
19
+ export type JitterStrategyConfig = "none" | "full" | "equal" | "decorrelated";
20
+ export type LimiterScopeConfig = "global" | "perHost";
21
+ export interface RetryPolicyConfig {
22
+ /** Maximum attempts, including the initial request. */
23
+ maxAttempts?: number;
24
+ /** Base exponential-backoff delay in milliseconds. */
25
+ baseDelayMs?: number;
26
+ /** Maximum exponential-backoff delay in milliseconds. */
27
+ maxDelayMs?: number;
28
+ }
29
+ export interface RequestRateLimiterConfig {
30
+ /** Request tokens granted per interval. Zero disables limiting. */
31
+ tokensPerInterval?: number;
32
+ /** Limiter interval in milliseconds. */
33
+ intervalMs?: number;
34
+ /** Bucket scope. */
35
+ scope?: LimiterScopeConfig;
36
+ }
37
+ export interface TransportPolicyConfig {
38
+ retryPolicy?: RetryPolicyConfig;
39
+ requestRateLimiter?: RequestRateLimiterConfig;
40
+ jitterStrategy?: JitterStrategyConfig;
41
+ userAgent?: string;
42
+ }
43
+ export interface CommonClientConfig {
44
+ chainId: number;
45
+ env?: CowEnv | string | null;
46
+ apiKey?: string | null;
47
+ transport?: HttpTransportConfig;
48
+ transportPolicy?: TransportPolicyConfig | null;
49
+ timeoutMs?: number | null;
50
+ signal?: AbortSignal;
51
+ }
52
+ export interface IpfsClientConfig {
53
+ ipfsUri?: string | null;
54
+ transport?: HttpTransportConfig;
55
+ transportPolicy?: TransportPolicyConfig | null;
56
+ timeoutMs?: number | null;
57
+ signal?: AbortSignal;
58
+ }
59
+ export interface SubgraphClientConfig {
60
+ chainId: number;
61
+ apiKey: string;
62
+ transport?: HttpTransportConfig;
63
+ transportPolicy?: TransportPolicyConfig | null;
64
+ timeoutMs?: number | null;
65
+ signal?: AbortSignal;
66
+ }
67
+ export interface TradingClientConfig extends CommonClientConfig {
68
+ appCode: string;
69
+ }
70
+ export type { CowFetchCallback, CowFetchRequest, CowFetchResponse };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.wasmVersion = exports.validateAppDataDoc = exports.supportedChainIds = exports.signOrderWithTypedDataSigner = exports.signOrderWithEip1271 = exports.signOrderWithEip1193 = exports.signOrderWithCustomEip1271 = exports.signOrderEthSignDigest = exports.signCancellationWithTypedDataSigner = exports.signCancellationWithEip1193 = exports.signCancellationEthSignDigest = exports.orderTypedData = exports.eip1271SignaturePayload = exports.domainSeparator = exports.deploymentAddresses = exports.decodeSettlementLog = exports.decodeEthFlowLog = exports.computeOrderUid = exports.cidToAppDataHex = exports.buildPresignTx = exports.buildCancelOrderTx = exports.appDataInfo = exports.appDataHexToCid = exports.appDataDoc = exports.__cow_sdk_wasm_init = exports.RawTradingClient = exports.RawOrderBookClient = exports.initializeRaw = void 0;
37
+ const cow_sdk_wasm_js_1 = __importStar(require("../../raw/cloudflare-web/cow_sdk_wasm.cjs")), wasm = cow_sdk_wasm_js_1;
38
+ exports.initializeRaw = cow_sdk_wasm_js_1.default;
39
+ exports.RawOrderBookClient = wasm.OrderBookClient;
40
+ exports.RawTradingClient = wasm.TradingClient;
41
+ exports.__cow_sdk_wasm_init = wasm.__cow_sdk_wasm_init;
42
+ exports.appDataDoc = wasm.appDataDoc;
43
+ exports.appDataHexToCid = wasm.appDataHexToCid;
44
+ exports.appDataInfo = wasm.appDataInfo;
45
+ exports.buildCancelOrderTx = wasm.buildCancelOrderTx;
46
+ exports.buildPresignTx = wasm.buildPresignTx;
47
+ exports.cidToAppDataHex = wasm.cidToAppDataHex;
48
+ exports.computeOrderUid = wasm.computeOrderUid;
49
+ exports.decodeEthFlowLog = wasm.decodeEthFlowLog;
50
+ exports.decodeSettlementLog = wasm.decodeSettlementLog;
51
+ exports.deploymentAddresses = wasm.deploymentAddresses;
52
+ exports.domainSeparator = wasm.domainSeparator;
53
+ exports.eip1271SignaturePayload = wasm.eip1271SignaturePayload;
54
+ exports.orderTypedData = wasm.orderTypedData;
55
+ exports.signCancellationEthSignDigest = wasm.signCancellationEthSignDigest;
56
+ exports.signCancellationWithEip1193 = wasm.signCancellationWithEip1193;
57
+ exports.signCancellationWithTypedDataSigner = wasm.signCancellationWithTypedDataSigner;
58
+ exports.signOrderEthSignDigest = wasm.signOrderEthSignDigest;
59
+ exports.signOrderWithCustomEip1271 = wasm.signOrderWithCustomEip1271;
60
+ exports.signOrderWithEip1193 = wasm.signOrderWithEip1193;
61
+ exports.signOrderWithEip1271 = wasm.signOrderWithEip1271;
62
+ exports.signOrderWithTypedDataSigner = wasm.signOrderWithTypedDataSigner;
63
+ exports.supportedChainIds = wasm.supportedChainIds;
64
+ exports.validateAppDataDoc = wasm.validateAppDataDoc;
65
+ exports.wasmVersion = wasm.wasmVersion;
@@ -0,0 +1,30 @@
1
+ import init, * as wasm from "../../raw/cloudflare-web/cow_sdk_wasm.js";
2
+ export type * from "../../raw/cloudflare-web/cow_sdk_wasm.js";
3
+ export declare const initializeRaw: typeof init;
4
+ export declare const RawOrderBookClient: typeof wasm.OrderBookClient;
5
+ export declare const RawTradingClient: typeof wasm.TradingClient;
6
+ export declare const __cow_sdk_wasm_init: typeof wasm.__cow_sdk_wasm_init;
7
+ export declare const appDataDoc: typeof wasm.appDataDoc;
8
+ export declare const appDataHexToCid: typeof wasm.appDataHexToCid;
9
+ export declare const appDataInfo: typeof wasm.appDataInfo;
10
+ export declare const buildCancelOrderTx: typeof wasm.buildCancelOrderTx;
11
+ export declare const buildPresignTx: typeof wasm.buildPresignTx;
12
+ export declare const cidToAppDataHex: typeof wasm.cidToAppDataHex;
13
+ export declare const computeOrderUid: typeof wasm.computeOrderUid;
14
+ export declare const decodeEthFlowLog: typeof wasm.decodeEthFlowLog;
15
+ export declare const decodeSettlementLog: typeof wasm.decodeSettlementLog;
16
+ export declare const deploymentAddresses: typeof wasm.deploymentAddresses;
17
+ export declare const domainSeparator: typeof wasm.domainSeparator;
18
+ export declare const eip1271SignaturePayload: typeof wasm.eip1271SignaturePayload;
19
+ export declare const orderTypedData: typeof wasm.orderTypedData;
20
+ export declare const signCancellationEthSignDigest: typeof wasm.signCancellationEthSignDigest;
21
+ export declare const signCancellationWithEip1193: typeof wasm.signCancellationWithEip1193;
22
+ export declare const signCancellationWithTypedDataSigner: typeof wasm.signCancellationWithTypedDataSigner;
23
+ export declare const signOrderEthSignDigest: typeof wasm.signOrderEthSignDigest;
24
+ export declare const signOrderWithCustomEip1271: typeof wasm.signOrderWithCustomEip1271;
25
+ export declare const signOrderWithEip1193: typeof wasm.signOrderWithEip1193;
26
+ export declare const signOrderWithEip1271: typeof wasm.signOrderWithEip1271;
27
+ export declare const signOrderWithTypedDataSigner: typeof wasm.signOrderWithTypedDataSigner;
28
+ export declare const supportedChainIds: typeof wasm.supportedChainIds;
29
+ export declare const validateAppDataDoc: typeof wasm.validateAppDataDoc;
30
+ export declare const wasmVersion: typeof wasm.wasmVersion;