@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.
- package/LICENSE +674 -0
- package/README.md +278 -0
- package/dist/cloudflare/callbacks.cjs +2 -0
- package/dist/cloudflare/callbacks.d.ts +55 -0
- package/dist/cloudflare/callbacks.js +1 -0
- package/dist/cloudflare/envelope.cjs +2 -0
- package/dist/cloudflare/envelope.d.ts +5 -0
- package/dist/cloudflare/envelope.js +1 -0
- package/dist/cloudflare/errors.cjs +150 -0
- package/dist/cloudflare/errors.d.ts +82 -0
- package/dist/cloudflare/errors.js +145 -0
- package/dist/cloudflare/index.cjs +286 -0
- package/dist/cloudflare/index.d.ts +78 -0
- package/dist/cloudflare/index.js +1 -0
- package/dist/cloudflare/index.mjs +223 -0
- package/dist/cloudflare/internal.cjs +127 -0
- package/dist/cloudflare/internal.d.ts +40 -0
- package/dist/cloudflare/internal.js +115 -0
- package/dist/cloudflare/options.cjs +2 -0
- package/dist/cloudflare/options.d.ts +70 -0
- package/dist/cloudflare/options.js +1 -0
- package/dist/cloudflare/raw/cloudflare.cjs +65 -0
- package/dist/cloudflare/raw/cloudflare.d.ts +30 -0
- package/dist/cloudflare/raw/cloudflare.js +29 -0
- package/dist/default/callbacks.cjs +2 -0
- package/dist/default/callbacks.d.ts +55 -0
- package/dist/default/callbacks.js +1 -0
- package/dist/default/envelope.cjs +2 -0
- package/dist/default/envelope.d.ts +5 -0
- package/dist/default/envelope.js +1 -0
- package/dist/default/errors.cjs +150 -0
- package/dist/default/errors.d.ts +82 -0
- package/dist/default/errors.js +145 -0
- package/dist/default/index.cjs +359 -0
- package/dist/default/index.d.ts +94 -0
- package/dist/default/index.js +1 -0
- package/dist/default/index.mjs +295 -0
- package/dist/default/internal.cjs +127 -0
- package/dist/default/internal.d.ts +40 -0
- package/dist/default/internal.js +115 -0
- package/dist/default/options.cjs +2 -0
- package/dist/default/options.d.ts +70 -0
- package/dist/default/options.js +1 -0
- package/dist/default/raw/default.cjs +66 -0
- package/dist/default/raw/default.d.ts +31 -0
- package/dist/default/raw/default.js +30 -0
- package/dist/orderbook/callbacks.cjs +2 -0
- package/dist/orderbook/callbacks.d.ts +55 -0
- package/dist/orderbook/callbacks.js +1 -0
- package/dist/orderbook/envelope.cjs +2 -0
- package/dist/orderbook/envelope.d.ts +5 -0
- package/dist/orderbook/envelope.js +1 -0
- package/dist/orderbook/errors.cjs +150 -0
- package/dist/orderbook/errors.d.ts +82 -0
- package/dist/orderbook/errors.js +145 -0
- package/dist/orderbook/index.cjs +195 -0
- package/dist/orderbook/index.d.ts +57 -0
- package/dist/orderbook/index.js +1 -0
- package/dist/orderbook/index.mjs +139 -0
- package/dist/orderbook/internal.cjs +127 -0
- package/dist/orderbook/internal.d.ts +40 -0
- package/dist/orderbook/internal.js +115 -0
- package/dist/orderbook/options.cjs +2 -0
- package/dist/orderbook/options.d.ts +70 -0
- package/dist/orderbook/options.js +1 -0
- package/dist/orderbook/raw/orderbook.cjs +58 -0
- package/dist/orderbook/raw/orderbook.d.ts +23 -0
- package/dist/orderbook/raw/orderbook.js +22 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm.d.ts +2870 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm.js +2183 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/cloudflare-web/cow_sdk_wasm_bg.wasm.d.ts +65 -0
- package/dist/raw/default-bundler/cow_sdk_wasm.d.ts +2916 -0
- package/dist/raw/default-bundler/cow_sdk_wasm.js +9 -0
- package/dist/raw/default-bundler/cow_sdk_wasm_bg.js +2297 -0
- package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/default-bundler/cow_sdk_wasm_bg.wasm.d.ts +75 -0
- package/dist/raw/default-nodejs/cow_sdk_wasm.cjs +2330 -0
- package/dist/raw/default-nodejs/cow_sdk_wasm.d.ts +2916 -0
- package/dist/raw/default-nodejs/cow_sdk_wasm_bg.wasm.d.ts +75 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm.d.ts +1876 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm.js +9 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.js +1636 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/orderbook-bundler/cow_sdk_wasm_bg.wasm.d.ts +50 -0
- package/dist/raw/orderbook-nodejs/cow_sdk_wasm.cjs +1661 -0
- package/dist/raw/orderbook-nodejs/cow_sdk_wasm.d.ts +1876 -0
- package/dist/raw/orderbook-nodejs/cow_sdk_wasm_bg.wasm.d.ts +50 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm.d.ts +774 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm.js +9 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm_bg.js +1059 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm +0 -0
- package/dist/raw/signing-bundler/cow_sdk_wasm_bg.wasm.d.ts +27 -0
- package/dist/raw/signing-nodejs/cow_sdk_wasm.cjs +1078 -0
- package/dist/raw/signing-nodejs/cow_sdk_wasm.d.ts +774 -0
- package/dist/raw/signing-nodejs/cow_sdk_wasm_bg.wasm.d.ts +27 -0
- package/dist/signing/callbacks.cjs +2 -0
- package/dist/signing/callbacks.d.ts +55 -0
- package/dist/signing/callbacks.js +1 -0
- package/dist/signing/envelope.cjs +2 -0
- package/dist/signing/envelope.d.ts +5 -0
- package/dist/signing/envelope.js +1 -0
- package/dist/signing/errors.cjs +150 -0
- package/dist/signing/errors.d.ts +82 -0
- package/dist/signing/errors.js +145 -0
- package/dist/signing/index.cjs +93 -0
- package/dist/signing/index.d.ts +23 -0
- package/dist/signing/index.js +1 -0
- package/dist/signing/index.mjs +44 -0
- package/dist/signing/internal.cjs +127 -0
- package/dist/signing/internal.d.ts +40 -0
- package/dist/signing/internal.js +115 -0
- package/dist/signing/options.cjs +2 -0
- package/dist/signing/options.d.ts +70 -0
- package/dist/signing/options.js +1 -0
- package/dist/signing/raw/signing.cjs +52 -0
- package/dist/signing/raw/signing.d.ts +17 -0
- package/dist/signing/raw/signing.js +16 -0
- package/package.json +112 -0
|
@@ -0,0 +1,195 @@
|
|
|
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.OrderBookClient = void 0;
|
|
37
|
+
exports.buildCancelOrderTx = buildCancelOrderTx;
|
|
38
|
+
exports.buildPresignTx = buildPresignTx;
|
|
39
|
+
exports.computeOrderUid = computeOrderUid;
|
|
40
|
+
exports.decodeEthFlowLog = decodeEthFlowLog;
|
|
41
|
+
exports.decodeSettlementLog = decodeSettlementLog;
|
|
42
|
+
exports.deploymentAddresses = deploymentAddresses;
|
|
43
|
+
exports.domainSeparator = domainSeparator;
|
|
44
|
+
exports.eip1271SignaturePayload = eip1271SignaturePayload;
|
|
45
|
+
exports.orderTypedData = orderTypedData;
|
|
46
|
+
exports.signCancellationEthSignDigest = signCancellationEthSignDigest;
|
|
47
|
+
exports.signCancellationWithEip1193 = signCancellationWithEip1193;
|
|
48
|
+
exports.signCancellationWithTypedDataSigner = signCancellationWithTypedDataSigner;
|
|
49
|
+
exports.signOrderEthSignDigest = signOrderEthSignDigest;
|
|
50
|
+
exports.signOrderWithCustomEip1271 = signOrderWithCustomEip1271;
|
|
51
|
+
exports.signOrderWithEip1193 = signOrderWithEip1193;
|
|
52
|
+
exports.signOrderWithEip1271 = signOrderWithEip1271;
|
|
53
|
+
exports.signOrderWithTypedDataSigner = signOrderWithTypedDataSigner;
|
|
54
|
+
exports.supportedChainIds = supportedChainIds;
|
|
55
|
+
exports.wasmVersion = wasmVersion;
|
|
56
|
+
const raw = __importStar(require("./raw/orderbook.cjs"));
|
|
57
|
+
const internal_js_1 = require("./internal.cjs");
|
|
58
|
+
class OrderBookClient {
|
|
59
|
+
#inner;
|
|
60
|
+
#defaults;
|
|
61
|
+
#disposed = false;
|
|
62
|
+
constructor(config) {
|
|
63
|
+
try {
|
|
64
|
+
this.#defaults = (0, internal_js_1.defaultsFrom)(config);
|
|
65
|
+
this.#inner = new raw.RawOrderBookClient((0, internal_js_1.translateClientConfig)(config));
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw (0, internal_js_1.callSync)(() => {
|
|
69
|
+
throw error;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async cancelOrders(signed, options) {
|
|
74
|
+
return this.#call((client, merged) => client.cancelOrders(signed, merged), options);
|
|
75
|
+
}
|
|
76
|
+
async getNativePrice(token, options) {
|
|
77
|
+
return this.#call((client, merged) => client.getNativePrice(token, merged), options);
|
|
78
|
+
}
|
|
79
|
+
async getOrder(orderUid, options) {
|
|
80
|
+
return this.#call((client, merged) => client.getOrder(orderUid, merged), options);
|
|
81
|
+
}
|
|
82
|
+
async getOrders(owner, pagination, options) {
|
|
83
|
+
return this.#call((client, merged) => client.getOrders(owner, pagination ?? null, merged), options);
|
|
84
|
+
}
|
|
85
|
+
async getOrderMultiEnv(orderUid, options) {
|
|
86
|
+
return this.#call((client, merged) => client.getOrderMultiEnv(orderUid, merged), options);
|
|
87
|
+
}
|
|
88
|
+
async getTxOrders(txHash, options) {
|
|
89
|
+
return this.#call((client, merged) => client.getTxOrders(txHash, merged), options);
|
|
90
|
+
}
|
|
91
|
+
async getVersion(options) {
|
|
92
|
+
return this.#call((client, merged) => client.getVersion(merged), options);
|
|
93
|
+
}
|
|
94
|
+
getOrderLink(orderUid) {
|
|
95
|
+
(0, internal_js_1.assertActive)(this.#disposed);
|
|
96
|
+
return (0, internal_js_1.callSync)(() => this.#inner.getOrderLink(orderUid));
|
|
97
|
+
}
|
|
98
|
+
async getQuote(request, options) {
|
|
99
|
+
return this.#call((client, merged) => client.getQuote(request, merged), options);
|
|
100
|
+
}
|
|
101
|
+
async getTrades(query, options) {
|
|
102
|
+
return this.#call((client, merged) => client.getTrades(query, merged), options);
|
|
103
|
+
}
|
|
104
|
+
async getOrderCompetitionStatus(orderUid, options) {
|
|
105
|
+
return this.#call((client, merged) => client.getOrderCompetitionStatus(orderUid, merged), options);
|
|
106
|
+
}
|
|
107
|
+
async getTotalSurplus(owner, options) {
|
|
108
|
+
return this.#call((client, merged) => client.getTotalSurplus(owner, merged), options);
|
|
109
|
+
}
|
|
110
|
+
async getAppData(appDataHash, options) {
|
|
111
|
+
return this.#call((client, merged) => client.getAppData(appDataHash, merged), options);
|
|
112
|
+
}
|
|
113
|
+
async uploadAppData(appDataHash, fullAppData, options) {
|
|
114
|
+
return this.#call((client, merged) => client.uploadAppData(appDataHash, fullAppData, merged), options);
|
|
115
|
+
}
|
|
116
|
+
async sendOrder(signed, options) {
|
|
117
|
+
return this.#call((client, merged) => client.sendOrder(signed, merged), options);
|
|
118
|
+
}
|
|
119
|
+
async sendOrderCreation(input, options) {
|
|
120
|
+
return this.#call((client, merged) => client.sendOrderCreation(input, merged), options);
|
|
121
|
+
}
|
|
122
|
+
dispose() {
|
|
123
|
+
if (!this.#disposed) {
|
|
124
|
+
(0, internal_js_1.disposeRaw)(this.#inner);
|
|
125
|
+
this.#disposed = true;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
[Symbol.dispose]() {
|
|
129
|
+
this.dispose();
|
|
130
|
+
}
|
|
131
|
+
#call(operation, options) {
|
|
132
|
+
return (0, internal_js_1.callAsync)(() => {
|
|
133
|
+
(0, internal_js_1.assertActive)(this.#disposed);
|
|
134
|
+
return operation(this.#inner, (0, internal_js_1.mergeOptions)(this.#defaults, options));
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
exports.OrderBookClient = OrderBookClient;
|
|
139
|
+
function buildCancelOrderTx(params) {
|
|
140
|
+
return (0, internal_js_1.callSync)(() => raw.buildCancelOrderTx(params));
|
|
141
|
+
}
|
|
142
|
+
function buildPresignTx(params) {
|
|
143
|
+
return (0, internal_js_1.callSync)(() => raw.buildPresignTx(params));
|
|
144
|
+
}
|
|
145
|
+
function computeOrderUid(input, chainId, owner) {
|
|
146
|
+
return (0, internal_js_1.callSync)(() => raw.computeOrderUid(input, chainId, owner));
|
|
147
|
+
}
|
|
148
|
+
function decodeEthFlowLog(log) {
|
|
149
|
+
return (0, internal_js_1.callSync)(() => raw.decodeEthFlowLog(log));
|
|
150
|
+
}
|
|
151
|
+
function decodeSettlementLog(log) {
|
|
152
|
+
return (0, internal_js_1.callSync)(() => raw.decodeSettlementLog(log));
|
|
153
|
+
}
|
|
154
|
+
function deploymentAddresses(chainId, env) {
|
|
155
|
+
return (0, internal_js_1.callSync)(() => raw.deploymentAddresses(chainId, env ?? null));
|
|
156
|
+
}
|
|
157
|
+
function domainSeparator(chainId) {
|
|
158
|
+
return (0, internal_js_1.callSync)(() => raw.domainSeparator(chainId));
|
|
159
|
+
}
|
|
160
|
+
function eip1271SignaturePayload(input, ecdsaSignature) {
|
|
161
|
+
return (0, internal_js_1.callSync)(() => raw.eip1271SignaturePayload(input, ecdsaSignature));
|
|
162
|
+
}
|
|
163
|
+
function orderTypedData(input, chainId) {
|
|
164
|
+
return (0, internal_js_1.callSync)(() => raw.orderTypedData(input, chainId));
|
|
165
|
+
}
|
|
166
|
+
function signCancellationEthSignDigest(orderUids, chainId, digestSigner, options) {
|
|
167
|
+
return (0, internal_js_1.callAsync)(() => raw.signCancellationEthSignDigest(orderUids, chainId, digestSigner, options ?? null));
|
|
168
|
+
}
|
|
169
|
+
function signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options) {
|
|
170
|
+
return (0, internal_js_1.callAsync)(() => raw.signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options ?? null));
|
|
171
|
+
}
|
|
172
|
+
function signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options) {
|
|
173
|
+
return (0, internal_js_1.callAsync)(() => raw.signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options ?? null));
|
|
174
|
+
}
|
|
175
|
+
function signOrderEthSignDigest(input, chainId, owner, digestSigner, options) {
|
|
176
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderEthSignDigest(input, chainId, owner, digestSigner, options ?? null));
|
|
177
|
+
}
|
|
178
|
+
function signOrderWithCustomEip1271(input, chainId, owner, customCallback, options) {
|
|
179
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithCustomEip1271(input, chainId, owner, customCallback, options ?? null));
|
|
180
|
+
}
|
|
181
|
+
function signOrderWithEip1193(input, chainId, owner, requestCallback, options) {
|
|
182
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithEip1193(input, chainId, owner, requestCallback, options ?? null));
|
|
183
|
+
}
|
|
184
|
+
function signOrderWithEip1271(input, chainId, owner, typedDataSigner, options) {
|
|
185
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithEip1271(input, chainId, owner, typedDataSigner, options ?? null));
|
|
186
|
+
}
|
|
187
|
+
function signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options) {
|
|
188
|
+
return (0, internal_js_1.callAsync)(() => raw.signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options ?? null));
|
|
189
|
+
}
|
|
190
|
+
function supportedChainIds() {
|
|
191
|
+
return (0, internal_js_1.callSync)(() => raw.supportedChainIds());
|
|
192
|
+
}
|
|
193
|
+
function wasmVersion() {
|
|
194
|
+
return (0, internal_js_1.callSync)(() => raw.wasmVersion());
|
|
195
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/// <reference lib="esnext.disposable" />
|
|
2
|
+
import * as raw from "./raw/orderbook.js";
|
|
3
|
+
import type { WasmEnvelope } from "./envelope.js";
|
|
4
|
+
import type { CommonClientConfig, SdkClientOptions, SigningOptions } from "./options.js";
|
|
5
|
+
import type { CustomEip1271Callback, DigestSignerCallback, Eip1193RequestCallback, TypedDataSignerCallback } from "./callbacks.js";
|
|
6
|
+
export interface OrderBookClientConfig extends CommonClientConfig {
|
|
7
|
+
}
|
|
8
|
+
export declare class OrderBookClient {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(config: OrderBookClientConfig);
|
|
11
|
+
cancelOrders(signed: raw.SignedCancellationsInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<{
|
|
12
|
+
cancelled: true;
|
|
13
|
+
}>>;
|
|
14
|
+
getNativePrice(token: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.NativePriceResponseDto>>;
|
|
15
|
+
getOrder(orderUid: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto>>;
|
|
16
|
+
getOrders(owner: string, pagination?: raw.PaginationOptions | null, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto[]>>;
|
|
17
|
+
getOrderMultiEnv(orderUid: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto>>;
|
|
18
|
+
getTxOrders(txHash: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderDto[]>>;
|
|
19
|
+
getVersion(options?: SdkClientOptions | null): Promise<WasmEnvelope<string>>;
|
|
20
|
+
getOrderLink(orderUid: string): WasmEnvelope<string>;
|
|
21
|
+
getQuote(request: raw.OrderQuoteRequestInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.OrderQuoteResponseDto>>;
|
|
22
|
+
getTrades(query: raw.TradesQueryInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.TradeDto[]>>;
|
|
23
|
+
getOrderCompetitionStatus(orderUid: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.CompetitionOrderStatusDto>>;
|
|
24
|
+
getTotalSurplus(owner: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.TotalSurplusDto>>;
|
|
25
|
+
getAppData(appDataHash: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<raw.AppDataObjectDto>>;
|
|
26
|
+
uploadAppData(appDataHash: string, fullAppData: string, options?: SdkClientOptions | null): Promise<WasmEnvelope<{
|
|
27
|
+
uploaded: true;
|
|
28
|
+
}>>;
|
|
29
|
+
sendOrder(signed: raw.SignedOrderDto, options?: SdkClientOptions | null): Promise<WasmEnvelope<string>>;
|
|
30
|
+
sendOrderCreation(input: raw.OrderCreationInput, options?: SdkClientOptions | null): Promise<WasmEnvelope<string>>;
|
|
31
|
+
dispose(): void;
|
|
32
|
+
[Symbol.dispose](): void;
|
|
33
|
+
}
|
|
34
|
+
export declare function buildCancelOrderTx(params: raw.OrderTraderParametersInput): WasmEnvelope<raw.TransactionRequestDto>;
|
|
35
|
+
export declare function buildPresignTx(params: raw.OrderTraderParametersInput): WasmEnvelope<raw.TransactionRequestDto>;
|
|
36
|
+
export declare function computeOrderUid(input: raw.OrderInput, chainId: number, owner: string): WasmEnvelope<raw.GeneratedOrderUidDto>;
|
|
37
|
+
export declare function decodeEthFlowLog(log: raw.EventLogInput): WasmEnvelope<raw.EthFlowEventDto>;
|
|
38
|
+
export declare function decodeSettlementLog(log: raw.EventLogInput): WasmEnvelope<raw.SettlementEventDto>;
|
|
39
|
+
export declare function deploymentAddresses(chainId: number, env?: string | null): WasmEnvelope<raw.DeploymentAddressesDto>;
|
|
40
|
+
export declare function domainSeparator(chainId: number): string;
|
|
41
|
+
export declare function eip1271SignaturePayload(input: raw.OrderInput, ecdsaSignature: string): WasmEnvelope<string>;
|
|
42
|
+
export declare function orderTypedData(input: raw.OrderInput, chainId: number): WasmEnvelope<raw.TypedDataEnvelopeDto>;
|
|
43
|
+
export declare function signCancellationEthSignDigest(orderUids: string[], chainId: number, digestSigner: DigestSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedCancellationsInput>>;
|
|
44
|
+
export declare function signCancellationWithEip1193(orderUids: string[], chainId: number, owner: string, requestCallback: Eip1193RequestCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedCancellationsInput>>;
|
|
45
|
+
export declare function signCancellationWithTypedDataSigner(orderUids: string[], chainId: number, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedCancellationsInput>>;
|
|
46
|
+
export declare function signOrderEthSignDigest(input: raw.OrderInput, chainId: number, owner: string, digestSigner: DigestSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
47
|
+
export declare function signOrderWithCustomEip1271(input: raw.OrderInput, chainId: number, owner: string, customCallback: CustomEip1271Callback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
48
|
+
export declare function signOrderWithEip1193(input: raw.OrderInput, chainId: number, owner: string, requestCallback: Eip1193RequestCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
49
|
+
export declare function signOrderWithEip1271(input: raw.OrderInput, chainId: number, owner: string, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
50
|
+
export declare function signOrderWithTypedDataSigner(input: raw.OrderInput, chainId: number, owner: string, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
|
|
51
|
+
export declare function supportedChainIds(): Uint32Array;
|
|
52
|
+
export declare function wasmVersion(): string;
|
|
53
|
+
export type { AppDataObjectDto, CompetitionOrderStatusDto, CompetitionOrderStatusKindDto, CowEip1271SignRequest, DeploymentAddressesDto, Eip1193Request, EthFlowEventDto, EthflowDataDto, EventLogInput, ExecutedAmountsDto, ExecutedProtocolFeeDto, GeneratedOrderUidDto, InteractionDataDto, NativePriceResponseDto, OnchainOrderDataDto, OrderClassDto, OrderCreationInput, OrderDto, OrderInput, OrderInteractionsDto, OrderKindDto, OrderQuoteRequestInput, OrderQuoteResponseDto, OrderStatusDto, OrderTraderParametersInput, PaginationOptions, QuoteDataDto, SettlementEventDto, SignedCancellationsInput, SignedOrderDto, SigningSchemeDto, SolverExecutionDto, StoredOrderQuoteDto, TokenBalanceDto, TotalSurplusDto, TradeDto, TradesQueryInput, TransactionRequestDto, TypedDataDomainDto, TypedDataEnvelopeDto, TypedDataFieldDto } from "./raw/orderbook.js";
|
|
54
|
+
export type { CowEip1271SignCallback, CowEnv, CustomEip1271Callback, DigestSignerCallback, Eip1193RequestCallback, TypedDataSignerCallback } from "./callbacks.js";
|
|
55
|
+
export type { OrderBookRejectionCategory, CowError } from "./errors.js";
|
|
56
|
+
export type { SchemaVersion, WasmEnvelope } from "./envelope.js";
|
|
57
|
+
export type { CowFetchCallback, CowFetchRequest, CowFetchResponse, HttpTransportConfig, JitterStrategyConfig, LimiterScopeConfig, RequestRateLimiterConfig, RetryPolicyConfig, SdkClientOptions, SigningOptions, TransportPolicyConfig, WalletConfig } from "./options.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./default.js";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import * as raw from "./raw/orderbook.js";
|
|
2
|
+
import { assertActive, callAsync, callSync, defaultsFrom, disposeRaw, mergeOptions, translateClientConfig } from "./internal.js";
|
|
3
|
+
export class OrderBookClient {
|
|
4
|
+
#inner;
|
|
5
|
+
#defaults;
|
|
6
|
+
#disposed = false;
|
|
7
|
+
constructor(config) {
|
|
8
|
+
try {
|
|
9
|
+
this.#defaults = defaultsFrom(config);
|
|
10
|
+
this.#inner = new raw.RawOrderBookClient(translateClientConfig(config));
|
|
11
|
+
}
|
|
12
|
+
catch (error) {
|
|
13
|
+
throw callSync(() => {
|
|
14
|
+
throw error;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
async cancelOrders(signed, options) {
|
|
19
|
+
return this.#call((client, merged) => client.cancelOrders(signed, merged), options);
|
|
20
|
+
}
|
|
21
|
+
async getNativePrice(token, options) {
|
|
22
|
+
return this.#call((client, merged) => client.getNativePrice(token, merged), options);
|
|
23
|
+
}
|
|
24
|
+
async getOrder(orderUid, options) {
|
|
25
|
+
return this.#call((client, merged) => client.getOrder(orderUid, merged), options);
|
|
26
|
+
}
|
|
27
|
+
async getOrders(owner, pagination, options) {
|
|
28
|
+
return this.#call((client, merged) => client.getOrders(owner, pagination ?? null, merged), options);
|
|
29
|
+
}
|
|
30
|
+
async getOrderMultiEnv(orderUid, options) {
|
|
31
|
+
return this.#call((client, merged) => client.getOrderMultiEnv(orderUid, merged), options);
|
|
32
|
+
}
|
|
33
|
+
async getTxOrders(txHash, options) {
|
|
34
|
+
return this.#call((client, merged) => client.getTxOrders(txHash, merged), options);
|
|
35
|
+
}
|
|
36
|
+
async getVersion(options) {
|
|
37
|
+
return this.#call((client, merged) => client.getVersion(merged), options);
|
|
38
|
+
}
|
|
39
|
+
getOrderLink(orderUid) {
|
|
40
|
+
assertActive(this.#disposed);
|
|
41
|
+
return callSync(() => this.#inner.getOrderLink(orderUid));
|
|
42
|
+
}
|
|
43
|
+
async getQuote(request, options) {
|
|
44
|
+
return this.#call((client, merged) => client.getQuote(request, merged), options);
|
|
45
|
+
}
|
|
46
|
+
async getTrades(query, options) {
|
|
47
|
+
return this.#call((client, merged) => client.getTrades(query, merged), options);
|
|
48
|
+
}
|
|
49
|
+
async getOrderCompetitionStatus(orderUid, options) {
|
|
50
|
+
return this.#call((client, merged) => client.getOrderCompetitionStatus(orderUid, merged), options);
|
|
51
|
+
}
|
|
52
|
+
async getTotalSurplus(owner, options) {
|
|
53
|
+
return this.#call((client, merged) => client.getTotalSurplus(owner, merged), options);
|
|
54
|
+
}
|
|
55
|
+
async getAppData(appDataHash, options) {
|
|
56
|
+
return this.#call((client, merged) => client.getAppData(appDataHash, merged), options);
|
|
57
|
+
}
|
|
58
|
+
async uploadAppData(appDataHash, fullAppData, options) {
|
|
59
|
+
return this.#call((client, merged) => client.uploadAppData(appDataHash, fullAppData, merged), options);
|
|
60
|
+
}
|
|
61
|
+
async sendOrder(signed, options) {
|
|
62
|
+
return this.#call((client, merged) => client.sendOrder(signed, merged), options);
|
|
63
|
+
}
|
|
64
|
+
async sendOrderCreation(input, options) {
|
|
65
|
+
return this.#call((client, merged) => client.sendOrderCreation(input, merged), options);
|
|
66
|
+
}
|
|
67
|
+
dispose() {
|
|
68
|
+
if (!this.#disposed) {
|
|
69
|
+
disposeRaw(this.#inner);
|
|
70
|
+
this.#disposed = true;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
[Symbol.dispose]() {
|
|
74
|
+
this.dispose();
|
|
75
|
+
}
|
|
76
|
+
#call(operation, options) {
|
|
77
|
+
return callAsync(() => {
|
|
78
|
+
assertActive(this.#disposed);
|
|
79
|
+
return operation(this.#inner, mergeOptions(this.#defaults, options));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export function buildCancelOrderTx(params) {
|
|
84
|
+
return callSync(() => raw.buildCancelOrderTx(params));
|
|
85
|
+
}
|
|
86
|
+
export function buildPresignTx(params) {
|
|
87
|
+
return callSync(() => raw.buildPresignTx(params));
|
|
88
|
+
}
|
|
89
|
+
export function computeOrderUid(input, chainId, owner) {
|
|
90
|
+
return callSync(() => raw.computeOrderUid(input, chainId, owner));
|
|
91
|
+
}
|
|
92
|
+
export function decodeEthFlowLog(log) {
|
|
93
|
+
return callSync(() => raw.decodeEthFlowLog(log));
|
|
94
|
+
}
|
|
95
|
+
export function decodeSettlementLog(log) {
|
|
96
|
+
return callSync(() => raw.decodeSettlementLog(log));
|
|
97
|
+
}
|
|
98
|
+
export function deploymentAddresses(chainId, env) {
|
|
99
|
+
return callSync(() => raw.deploymentAddresses(chainId, env ?? null));
|
|
100
|
+
}
|
|
101
|
+
export function domainSeparator(chainId) {
|
|
102
|
+
return callSync(() => raw.domainSeparator(chainId));
|
|
103
|
+
}
|
|
104
|
+
export function eip1271SignaturePayload(input, ecdsaSignature) {
|
|
105
|
+
return callSync(() => raw.eip1271SignaturePayload(input, ecdsaSignature));
|
|
106
|
+
}
|
|
107
|
+
export function orderTypedData(input, chainId) {
|
|
108
|
+
return callSync(() => raw.orderTypedData(input, chainId));
|
|
109
|
+
}
|
|
110
|
+
export function signCancellationEthSignDigest(orderUids, chainId, digestSigner, options) {
|
|
111
|
+
return callAsync(() => raw.signCancellationEthSignDigest(orderUids, chainId, digestSigner, options ?? null));
|
|
112
|
+
}
|
|
113
|
+
export function signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options) {
|
|
114
|
+
return callAsync(() => raw.signCancellationWithEip1193(orderUids, chainId, owner, requestCallback, options ?? null));
|
|
115
|
+
}
|
|
116
|
+
export function signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options) {
|
|
117
|
+
return callAsync(() => raw.signCancellationWithTypedDataSigner(orderUids, chainId, typedDataSigner, options ?? null));
|
|
118
|
+
}
|
|
119
|
+
export function signOrderEthSignDigest(input, chainId, owner, digestSigner, options) {
|
|
120
|
+
return callAsync(() => raw.signOrderEthSignDigest(input, chainId, owner, digestSigner, options ?? null));
|
|
121
|
+
}
|
|
122
|
+
export function signOrderWithCustomEip1271(input, chainId, owner, customCallback, options) {
|
|
123
|
+
return callAsync(() => raw.signOrderWithCustomEip1271(input, chainId, owner, customCallback, options ?? null));
|
|
124
|
+
}
|
|
125
|
+
export function signOrderWithEip1193(input, chainId, owner, requestCallback, options) {
|
|
126
|
+
return callAsync(() => raw.signOrderWithEip1193(input, chainId, owner, requestCallback, options ?? null));
|
|
127
|
+
}
|
|
128
|
+
export function signOrderWithEip1271(input, chainId, owner, typedDataSigner, options) {
|
|
129
|
+
return callAsync(() => raw.signOrderWithEip1271(input, chainId, owner, typedDataSigner, options ?? null));
|
|
130
|
+
}
|
|
131
|
+
export function signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options) {
|
|
132
|
+
return callAsync(() => raw.signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options ?? null));
|
|
133
|
+
}
|
|
134
|
+
export function supportedChainIds() {
|
|
135
|
+
return callSync(() => raw.supportedChainIds());
|
|
136
|
+
}
|
|
137
|
+
export function wasmVersion() {
|
|
138
|
+
return callSync(() => raw.wasmVersion());
|
|
139
|
+
}
|
|
@@ -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
|
+
}
|