@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,66 @@
|
|
|
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.RawSubgraphClient = exports.RawOrderBookClient = exports.RawIpfsClient = void 0;
|
|
37
|
+
const wasm = __importStar(require("../../raw/default-nodejs/cow_sdk_wasm.cjs"));
|
|
38
|
+
exports.RawIpfsClient = wasm.IpfsClient;
|
|
39
|
+
exports.RawOrderBookClient = wasm.OrderBookClient;
|
|
40
|
+
exports.RawSubgraphClient = wasm.SubgraphClient;
|
|
41
|
+
exports.RawTradingClient = wasm.TradingClient;
|
|
42
|
+
exports.__cow_sdk_wasm_init = wasm.__cow_sdk_wasm_init;
|
|
43
|
+
exports.appDataDoc = wasm.appDataDoc;
|
|
44
|
+
exports.appDataHexToCid = wasm.appDataHexToCid;
|
|
45
|
+
exports.appDataInfo = wasm.appDataInfo;
|
|
46
|
+
exports.buildCancelOrderTx = wasm.buildCancelOrderTx;
|
|
47
|
+
exports.buildPresignTx = wasm.buildPresignTx;
|
|
48
|
+
exports.cidToAppDataHex = wasm.cidToAppDataHex;
|
|
49
|
+
exports.computeOrderUid = wasm.computeOrderUid;
|
|
50
|
+
exports.decodeEthFlowLog = wasm.decodeEthFlowLog;
|
|
51
|
+
exports.decodeSettlementLog = wasm.decodeSettlementLog;
|
|
52
|
+
exports.deploymentAddresses = wasm.deploymentAddresses;
|
|
53
|
+
exports.domainSeparator = wasm.domainSeparator;
|
|
54
|
+
exports.eip1271SignaturePayload = wasm.eip1271SignaturePayload;
|
|
55
|
+
exports.orderTypedData = wasm.orderTypedData;
|
|
56
|
+
exports.signCancellationEthSignDigest = wasm.signCancellationEthSignDigest;
|
|
57
|
+
exports.signCancellationWithEip1193 = wasm.signCancellationWithEip1193;
|
|
58
|
+
exports.signCancellationWithTypedDataSigner = wasm.signCancellationWithTypedDataSigner;
|
|
59
|
+
exports.signOrderEthSignDigest = wasm.signOrderEthSignDigest;
|
|
60
|
+
exports.signOrderWithCustomEip1271 = wasm.signOrderWithCustomEip1271;
|
|
61
|
+
exports.signOrderWithEip1193 = wasm.signOrderWithEip1193;
|
|
62
|
+
exports.signOrderWithEip1271 = wasm.signOrderWithEip1271;
|
|
63
|
+
exports.signOrderWithTypedDataSigner = wasm.signOrderWithTypedDataSigner;
|
|
64
|
+
exports.supportedChainIds = wasm.supportedChainIds;
|
|
65
|
+
exports.validateAppDataDoc = wasm.validateAppDataDoc;
|
|
66
|
+
exports.wasmVersion = wasm.wasmVersion;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as wasm from "../../raw/default-bundler/cow_sdk_wasm.js";
|
|
2
|
+
export type * from "../../raw/default-bundler/cow_sdk_wasm.js";
|
|
3
|
+
export declare const RawIpfsClient: typeof wasm.IpfsClient;
|
|
4
|
+
export declare const RawOrderBookClient: typeof wasm.OrderBookClient;
|
|
5
|
+
export declare const RawSubgraphClient: typeof wasm.SubgraphClient;
|
|
6
|
+
export declare const RawTradingClient: typeof wasm.TradingClient;
|
|
7
|
+
export declare const __cow_sdk_wasm_init: typeof wasm.__cow_sdk_wasm_init;
|
|
8
|
+
export declare const appDataDoc: typeof wasm.appDataDoc;
|
|
9
|
+
export declare const appDataHexToCid: typeof wasm.appDataHexToCid;
|
|
10
|
+
export declare const appDataInfo: typeof wasm.appDataInfo;
|
|
11
|
+
export declare const buildCancelOrderTx: typeof wasm.buildCancelOrderTx;
|
|
12
|
+
export declare const buildPresignTx: typeof wasm.buildPresignTx;
|
|
13
|
+
export declare const cidToAppDataHex: typeof wasm.cidToAppDataHex;
|
|
14
|
+
export declare const computeOrderUid: typeof wasm.computeOrderUid;
|
|
15
|
+
export declare const decodeEthFlowLog: typeof wasm.decodeEthFlowLog;
|
|
16
|
+
export declare const decodeSettlementLog: typeof wasm.decodeSettlementLog;
|
|
17
|
+
export declare const deploymentAddresses: typeof wasm.deploymentAddresses;
|
|
18
|
+
export declare const domainSeparator: typeof wasm.domainSeparator;
|
|
19
|
+
export declare const eip1271SignaturePayload: typeof wasm.eip1271SignaturePayload;
|
|
20
|
+
export declare const orderTypedData: typeof wasm.orderTypedData;
|
|
21
|
+
export declare const signCancellationEthSignDigest: typeof wasm.signCancellationEthSignDigest;
|
|
22
|
+
export declare const signCancellationWithEip1193: typeof wasm.signCancellationWithEip1193;
|
|
23
|
+
export declare const signCancellationWithTypedDataSigner: typeof wasm.signCancellationWithTypedDataSigner;
|
|
24
|
+
export declare const signOrderEthSignDigest: typeof wasm.signOrderEthSignDigest;
|
|
25
|
+
export declare const signOrderWithCustomEip1271: typeof wasm.signOrderWithCustomEip1271;
|
|
26
|
+
export declare const signOrderWithEip1193: typeof wasm.signOrderWithEip1193;
|
|
27
|
+
export declare const signOrderWithEip1271: typeof wasm.signOrderWithEip1271;
|
|
28
|
+
export declare const signOrderWithTypedDataSigner: typeof wasm.signOrderWithTypedDataSigner;
|
|
29
|
+
export declare const supportedChainIds: typeof wasm.supportedChainIds;
|
|
30
|
+
export declare const validateAppDataDoc: typeof wasm.validateAppDataDoc;
|
|
31
|
+
export declare const wasmVersion: typeof wasm.wasmVersion;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as wasm from "../../raw/default-bundler/cow_sdk_wasm.js";
|
|
2
|
+
export const RawIpfsClient = wasm.IpfsClient;
|
|
3
|
+
export const RawOrderBookClient = wasm.OrderBookClient;
|
|
4
|
+
export const RawSubgraphClient = wasm.SubgraphClient;
|
|
5
|
+
export const RawTradingClient = wasm.TradingClient;
|
|
6
|
+
export const __cow_sdk_wasm_init = wasm.__cow_sdk_wasm_init;
|
|
7
|
+
export const appDataDoc = wasm.appDataDoc;
|
|
8
|
+
export const appDataHexToCid = wasm.appDataHexToCid;
|
|
9
|
+
export const appDataInfo = wasm.appDataInfo;
|
|
10
|
+
export const buildCancelOrderTx = wasm.buildCancelOrderTx;
|
|
11
|
+
export const buildPresignTx = wasm.buildPresignTx;
|
|
12
|
+
export const cidToAppDataHex = wasm.cidToAppDataHex;
|
|
13
|
+
export const computeOrderUid = wasm.computeOrderUid;
|
|
14
|
+
export const decodeEthFlowLog = wasm.decodeEthFlowLog;
|
|
15
|
+
export const decodeSettlementLog = wasm.decodeSettlementLog;
|
|
16
|
+
export const deploymentAddresses = wasm.deploymentAddresses;
|
|
17
|
+
export const domainSeparator = wasm.domainSeparator;
|
|
18
|
+
export const eip1271SignaturePayload = wasm.eip1271SignaturePayload;
|
|
19
|
+
export const orderTypedData = wasm.orderTypedData;
|
|
20
|
+
export const signCancellationEthSignDigest = wasm.signCancellationEthSignDigest;
|
|
21
|
+
export const signCancellationWithEip1193 = wasm.signCancellationWithEip1193;
|
|
22
|
+
export const signCancellationWithTypedDataSigner = wasm.signCancellationWithTypedDataSigner;
|
|
23
|
+
export const signOrderEthSignDigest = wasm.signOrderEthSignDigest;
|
|
24
|
+
export const signOrderWithCustomEip1271 = wasm.signOrderWithCustomEip1271;
|
|
25
|
+
export const signOrderWithEip1193 = wasm.signOrderWithEip1193;
|
|
26
|
+
export const signOrderWithEip1271 = wasm.signOrderWithEip1271;
|
|
27
|
+
export const signOrderWithTypedDataSigner = wasm.signOrderWithTypedDataSigner;
|
|
28
|
+
export const supportedChainIds = wasm.supportedChainIds;
|
|
29
|
+
export const validateAppDataDoc = wasm.validateAppDataDoc;
|
|
30
|
+
export const wasmVersion = wasm.wasmVersion;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
export type SupportedChainId = 1 | 100 | 137 | 8453 | 42161 | 43114 | 56 | 11155111 | 9745 | 57073 | 59144;
|
|
2
|
+
export type CowEnv = "prod" | "staging";
|
|
3
|
+
export type CowFetchMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
|
|
4
|
+
export interface CowFetchRequest {
|
|
5
|
+
method: CowFetchMethod;
|
|
6
|
+
url: string;
|
|
7
|
+
headers: Record<string, string>;
|
|
8
|
+
body?: string;
|
|
9
|
+
timeoutMs?: number;
|
|
10
|
+
signal?: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
export interface CowFetchResponse {
|
|
13
|
+
status: number;
|
|
14
|
+
statusText?: string;
|
|
15
|
+
headers?: Record<string, string>;
|
|
16
|
+
body?: string;
|
|
17
|
+
}
|
|
18
|
+
export type CowFetchCallback = (request: CowFetchRequest) => Promise<CowFetchResponse> | CowFetchResponse;
|
|
19
|
+
export interface TypedDataDomainDto {
|
|
20
|
+
name: string;
|
|
21
|
+
version: string;
|
|
22
|
+
chainId: number;
|
|
23
|
+
verifyingContract: string;
|
|
24
|
+
}
|
|
25
|
+
export interface TypedDataFieldDto {
|
|
26
|
+
name: string;
|
|
27
|
+
type: string;
|
|
28
|
+
}
|
|
29
|
+
export interface TypedDataEnvelopeDto {
|
|
30
|
+
domain: TypedDataDomainDto;
|
|
31
|
+
types: Record<string, TypedDataFieldDto[]>;
|
|
32
|
+
primaryType: string;
|
|
33
|
+
message: unknown;
|
|
34
|
+
}
|
|
35
|
+
export interface CowEip1271SignRequest {
|
|
36
|
+
order: unknown;
|
|
37
|
+
typedData: TypedDataEnvelopeDto;
|
|
38
|
+
owner: string;
|
|
39
|
+
chainId: number;
|
|
40
|
+
}
|
|
41
|
+
export interface ContractCallDto {
|
|
42
|
+
address: string;
|
|
43
|
+
method: string;
|
|
44
|
+
abiJson: string;
|
|
45
|
+
argsJson: string;
|
|
46
|
+
}
|
|
47
|
+
export type TypedDataSignerCallback = (envelope: TypedDataEnvelopeDto) => Promise<string> | string;
|
|
48
|
+
export type Eip1193RequestCallback = (request: {
|
|
49
|
+
method: string;
|
|
50
|
+
params?: unknown[];
|
|
51
|
+
}) => Promise<unknown> | unknown;
|
|
52
|
+
export type DigestSignerCallback = (digest: string) => Promise<string> | string;
|
|
53
|
+
export type CowEip1271SignCallback = (request: CowEip1271SignRequest) => Promise<string> | string;
|
|
54
|
+
export type CustomEip1271Callback = CowEip1271SignCallback;
|
|
55
|
+
export type ContractReadCallback = (request: ContractCallDto) => Promise<string> | string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeError = normalizeError;
|
|
4
|
+
exports.cancelledError = cancelledError;
|
|
5
|
+
exports.invalidInput = invalidInput;
|
|
6
|
+
const knownKinds = new Set([
|
|
7
|
+
"invalidInput",
|
|
8
|
+
"unknownEnumValue",
|
|
9
|
+
"unsupportedChain",
|
|
10
|
+
"walletRequest",
|
|
11
|
+
"walletTimeout",
|
|
12
|
+
"transport",
|
|
13
|
+
"orderbook",
|
|
14
|
+
"subgraph",
|
|
15
|
+
"signing",
|
|
16
|
+
"appData",
|
|
17
|
+
"cancelled",
|
|
18
|
+
"internal",
|
|
19
|
+
"__unknown"
|
|
20
|
+
]);
|
|
21
|
+
function normalizeError(raw) {
|
|
22
|
+
if (isRecord(raw)) {
|
|
23
|
+
// The Rust `WasmError` serializes with serde `rename_all(_fields) = "camelCase"`
|
|
24
|
+
// through a json-compatible serializer, so it already crosses the boundary as a
|
|
25
|
+
// camelCase plain object — no field renaming is needed here.
|
|
26
|
+
const normalized = raw;
|
|
27
|
+
const kind = typeof normalized.kind === "string" ? normalized.kind : undefined;
|
|
28
|
+
if (kind && knownKinds.has(kind)) {
|
|
29
|
+
const schemaVersion = normalized.schemaVersion === "__unknown" ? "__unknown" : "v1";
|
|
30
|
+
if (kind === "__unknown") {
|
|
31
|
+
return {
|
|
32
|
+
schemaVersion,
|
|
33
|
+
kind: "__unknown",
|
|
34
|
+
message: unknownMessage(),
|
|
35
|
+
raw: normalized.raw ?? raw
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
return withActionableMessage({
|
|
39
|
+
...normalized,
|
|
40
|
+
schemaVersion,
|
|
41
|
+
kind
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
if (kind) {
|
|
45
|
+
return {
|
|
46
|
+
schemaVersion: normalized.schemaVersion === "__unknown" ? "__unknown" : "v1",
|
|
47
|
+
kind: "__unknown",
|
|
48
|
+
message: unknownMessage(),
|
|
49
|
+
raw
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (raw instanceof Error) {
|
|
54
|
+
return (classifyDeserializationFailure(raw.message) ?? {
|
|
55
|
+
schemaVersion: "v1",
|
|
56
|
+
kind: "internal",
|
|
57
|
+
message: internalMessage(raw.message)
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return (classifyDeserializationFailure(String(raw)) ?? {
|
|
61
|
+
schemaVersion: "v1",
|
|
62
|
+
kind: "internal",
|
|
63
|
+
message: internalMessage(String(raw))
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
// Input-DTO deserialization failures cross the wasm boundary as a plain
|
|
67
|
+
// `Error`: the generated wasm-bindgen glue throws the serde message, so it
|
|
68
|
+
// never carries a structured `kind`. These are CALLER input errors — a value
|
|
69
|
+
// that does not match the documented input type (unknown enum variant,
|
|
70
|
+
// missing/unknown field, wrong type) — not SDK-internal faults, so they must
|
|
71
|
+
// normalize to `invalidInput` rather than `internal` (whose contract implies
|
|
72
|
+
// an SDK bug). The verbatim detail is preserved because it already names the
|
|
73
|
+
// offending field/variant and the expected set, e.g.
|
|
74
|
+
// "unknown variant `teleport`, expected `sell` or `buy`".
|
|
75
|
+
const DESERIALIZATION_FAILURE_PATTERNS = [
|
|
76
|
+
/unknown variant `/,
|
|
77
|
+
/missing field `/,
|
|
78
|
+
/unknown field `/,
|
|
79
|
+
/duplicate field `/,
|
|
80
|
+
/invalid type:/,
|
|
81
|
+
/invalid length\b/,
|
|
82
|
+
/invalid value:/,
|
|
83
|
+
/data did not match any variant/
|
|
84
|
+
];
|
|
85
|
+
function classifyDeserializationFailure(message) {
|
|
86
|
+
if (!DESERIALIZATION_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) {
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
const detail = message.replace(/^Error:\s*/, "");
|
|
90
|
+
const field = detail.match(/(?:missing|unknown|duplicate) field `([^`]+)`/)?.[1];
|
|
91
|
+
const reason = `Invalid SDK input: ${detail}. Check the value against the documented input type and retry.`;
|
|
92
|
+
return field !== undefined
|
|
93
|
+
? { schemaVersion: "v1", kind: "invalidInput", field, message: reason }
|
|
94
|
+
: { schemaVersion: "v1", kind: "invalidInput", message: reason };
|
|
95
|
+
}
|
|
96
|
+
function cancelledError() {
|
|
97
|
+
return {
|
|
98
|
+
schemaVersion: "v1",
|
|
99
|
+
kind: "cancelled",
|
|
100
|
+
message: "Operation was cancelled. Create a fresh AbortController or retry without an already-aborted signal."
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function invalidInput(field, reason) {
|
|
104
|
+
return {
|
|
105
|
+
schemaVersion: "v1",
|
|
106
|
+
kind: "invalidInput",
|
|
107
|
+
field,
|
|
108
|
+
message: `Invalid \`${field}\`: ${reason}. Check the value supplied for \`${field}\` and retry with a valid SDK input.`
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
function isRecord(value) {
|
|
112
|
+
return typeof value === "object" && value !== null;
|
|
113
|
+
}
|
|
114
|
+
function withActionableMessage(error) {
|
|
115
|
+
if ("message" in error && typeof error.message === "string" && error.message.length > 0) {
|
|
116
|
+
return error;
|
|
117
|
+
}
|
|
118
|
+
switch (error.kind) {
|
|
119
|
+
case "unknownEnumValue":
|
|
120
|
+
return {
|
|
121
|
+
...error,
|
|
122
|
+
message: `Unsupported value \`${error.value}\` for \`${error.field}\`. Use one of the documented values for this field.`
|
|
123
|
+
};
|
|
124
|
+
case "unsupportedChain":
|
|
125
|
+
return {
|
|
126
|
+
...error,
|
|
127
|
+
message: `Unsupported chain ID ${error.chainId}. Call supportedChainIds() before constructing requests and route unsupported networks to another integration.`
|
|
128
|
+
};
|
|
129
|
+
case "walletTimeout":
|
|
130
|
+
return {
|
|
131
|
+
...error,
|
|
132
|
+
message: `Wallet request timed out after ${error.timeoutMs} ms. Increase walletConfig.timeoutMs or ask the user to approve the wallet request before the timeout.`
|
|
133
|
+
};
|
|
134
|
+
case "cancelled":
|
|
135
|
+
return cancelledError();
|
|
136
|
+
case "__unknown":
|
|
137
|
+
return {
|
|
138
|
+
...error,
|
|
139
|
+
message: unknownMessage()
|
|
140
|
+
};
|
|
141
|
+
default:
|
|
142
|
+
return error;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function internalMessage(detail) {
|
|
146
|
+
return `SDK internal error: ${detail}. This indicates serialization or invariant failure; retry with the same inputs only after checking the reported input shape.`;
|
|
147
|
+
}
|
|
148
|
+
function unknownMessage() {
|
|
149
|
+
return "SDK received an unrecognized error variant. Inspect raw, preserve it in logs without credentials, and update the SDK if the variant is now documented.";
|
|
150
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { SchemaVersion } from "./envelope.js";
|
|
2
|
+
/**
|
|
3
|
+
* Coarse, switchable classification of an orderbook rejection. Lets a consumer
|
|
4
|
+
* branch on the action a rejection calls for — fix the request, fund the
|
|
5
|
+
* wallet, re-quote, wait, or escalate — without matching every wire tag. The
|
|
6
|
+
* `__unknown` member is the forward-compatible sentinel for a category a newer
|
|
7
|
+
* SDK may introduce.
|
|
8
|
+
*/
|
|
9
|
+
export type OrderBookRejectionCategory = "authorization" | "insufficientFunds" | "invalidOrder" | "notFound" | "conflict" | "unfulfillable" | "server" | "__unknown";
|
|
10
|
+
export type CowError = {
|
|
11
|
+
schemaVersion: "v1";
|
|
12
|
+
kind: "invalidInput";
|
|
13
|
+
message: string;
|
|
14
|
+
field?: string;
|
|
15
|
+
} | {
|
|
16
|
+
schemaVersion: "v1";
|
|
17
|
+
kind: "unknownEnumValue";
|
|
18
|
+
message: string;
|
|
19
|
+
field: string;
|
|
20
|
+
value: string;
|
|
21
|
+
} | {
|
|
22
|
+
schemaVersion: "v1";
|
|
23
|
+
kind: "unsupportedChain";
|
|
24
|
+
message: string;
|
|
25
|
+
chainId: number;
|
|
26
|
+
} | {
|
|
27
|
+
schemaVersion: "v1";
|
|
28
|
+
kind: "walletRequest";
|
|
29
|
+
method: string;
|
|
30
|
+
code?: number;
|
|
31
|
+
message: string;
|
|
32
|
+
} | {
|
|
33
|
+
schemaVersion: "v1";
|
|
34
|
+
kind: "walletTimeout";
|
|
35
|
+
message: string;
|
|
36
|
+
timeoutMs: number;
|
|
37
|
+
} | {
|
|
38
|
+
schemaVersion: "v1";
|
|
39
|
+
kind: "transport";
|
|
40
|
+
class: string;
|
|
41
|
+
message: string;
|
|
42
|
+
status?: number;
|
|
43
|
+
headers?: [string, string][];
|
|
44
|
+
body?: string;
|
|
45
|
+
} | {
|
|
46
|
+
schemaVersion: "v1";
|
|
47
|
+
kind: "orderbook";
|
|
48
|
+
code?: string;
|
|
49
|
+
category?: OrderBookRejectionCategory;
|
|
50
|
+
message: string;
|
|
51
|
+
retryable: boolean;
|
|
52
|
+
retryAfterMs?: number;
|
|
53
|
+
} | {
|
|
54
|
+
schemaVersion: "v1";
|
|
55
|
+
kind: "subgraph";
|
|
56
|
+
message: string;
|
|
57
|
+
} | {
|
|
58
|
+
schemaVersion: "v1";
|
|
59
|
+
kind: "signing";
|
|
60
|
+
message: string;
|
|
61
|
+
} | {
|
|
62
|
+
schemaVersion: "v1";
|
|
63
|
+
kind: "appData";
|
|
64
|
+
class?: string;
|
|
65
|
+
message: string;
|
|
66
|
+
} | {
|
|
67
|
+
schemaVersion: "v1";
|
|
68
|
+
kind: "cancelled";
|
|
69
|
+
message: string;
|
|
70
|
+
} | {
|
|
71
|
+
schemaVersion: "v1";
|
|
72
|
+
kind: "internal";
|
|
73
|
+
message: string;
|
|
74
|
+
} | {
|
|
75
|
+
schemaVersion: SchemaVersion;
|
|
76
|
+
kind: "__unknown";
|
|
77
|
+
message: string;
|
|
78
|
+
raw: unknown;
|
|
79
|
+
};
|
|
80
|
+
export declare function normalizeError(raw: unknown): CowError;
|
|
81
|
+
export declare function cancelledError(): CowError;
|
|
82
|
+
export declare function invalidInput(field: string, reason: string): CowError;
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
const knownKinds = new Set([
|
|
2
|
+
"invalidInput",
|
|
3
|
+
"unknownEnumValue",
|
|
4
|
+
"unsupportedChain",
|
|
5
|
+
"walletRequest",
|
|
6
|
+
"walletTimeout",
|
|
7
|
+
"transport",
|
|
8
|
+
"orderbook",
|
|
9
|
+
"subgraph",
|
|
10
|
+
"signing",
|
|
11
|
+
"appData",
|
|
12
|
+
"cancelled",
|
|
13
|
+
"internal",
|
|
14
|
+
"__unknown"
|
|
15
|
+
]);
|
|
16
|
+
export function normalizeError(raw) {
|
|
17
|
+
if (isRecord(raw)) {
|
|
18
|
+
// The Rust `WasmError` serializes with serde `rename_all(_fields) = "camelCase"`
|
|
19
|
+
// through a json-compatible serializer, so it already crosses the boundary as a
|
|
20
|
+
// camelCase plain object — no field renaming is needed here.
|
|
21
|
+
const normalized = raw;
|
|
22
|
+
const kind = typeof normalized.kind === "string" ? normalized.kind : undefined;
|
|
23
|
+
if (kind && knownKinds.has(kind)) {
|
|
24
|
+
const schemaVersion = normalized.schemaVersion === "__unknown" ? "__unknown" : "v1";
|
|
25
|
+
if (kind === "__unknown") {
|
|
26
|
+
return {
|
|
27
|
+
schemaVersion,
|
|
28
|
+
kind: "__unknown",
|
|
29
|
+
message: unknownMessage(),
|
|
30
|
+
raw: normalized.raw ?? raw
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return withActionableMessage({
|
|
34
|
+
...normalized,
|
|
35
|
+
schemaVersion,
|
|
36
|
+
kind
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
if (kind) {
|
|
40
|
+
return {
|
|
41
|
+
schemaVersion: normalized.schemaVersion === "__unknown" ? "__unknown" : "v1",
|
|
42
|
+
kind: "__unknown",
|
|
43
|
+
message: unknownMessage(),
|
|
44
|
+
raw
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (raw instanceof Error) {
|
|
49
|
+
return (classifyDeserializationFailure(raw.message) ?? {
|
|
50
|
+
schemaVersion: "v1",
|
|
51
|
+
kind: "internal",
|
|
52
|
+
message: internalMessage(raw.message)
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return (classifyDeserializationFailure(String(raw)) ?? {
|
|
56
|
+
schemaVersion: "v1",
|
|
57
|
+
kind: "internal",
|
|
58
|
+
message: internalMessage(String(raw))
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// Input-DTO deserialization failures cross the wasm boundary as a plain
|
|
62
|
+
// `Error`: the generated wasm-bindgen glue throws the serde message, so it
|
|
63
|
+
// never carries a structured `kind`. These are CALLER input errors — a value
|
|
64
|
+
// that does not match the documented input type (unknown enum variant,
|
|
65
|
+
// missing/unknown field, wrong type) — not SDK-internal faults, so they must
|
|
66
|
+
// normalize to `invalidInput` rather than `internal` (whose contract implies
|
|
67
|
+
// an SDK bug). The verbatim detail is preserved because it already names the
|
|
68
|
+
// offending field/variant and the expected set, e.g.
|
|
69
|
+
// "unknown variant `teleport`, expected `sell` or `buy`".
|
|
70
|
+
const DESERIALIZATION_FAILURE_PATTERNS = [
|
|
71
|
+
/unknown variant `/,
|
|
72
|
+
/missing field `/,
|
|
73
|
+
/unknown field `/,
|
|
74
|
+
/duplicate field `/,
|
|
75
|
+
/invalid type:/,
|
|
76
|
+
/invalid length\b/,
|
|
77
|
+
/invalid value:/,
|
|
78
|
+
/data did not match any variant/
|
|
79
|
+
];
|
|
80
|
+
function classifyDeserializationFailure(message) {
|
|
81
|
+
if (!DESERIALIZATION_FAILURE_PATTERNS.some((pattern) => pattern.test(message))) {
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
const detail = message.replace(/^Error:\s*/, "");
|
|
85
|
+
const field = detail.match(/(?:missing|unknown|duplicate) field `([^`]+)`/)?.[1];
|
|
86
|
+
const reason = `Invalid SDK input: ${detail}. Check the value against the documented input type and retry.`;
|
|
87
|
+
return field !== undefined
|
|
88
|
+
? { schemaVersion: "v1", kind: "invalidInput", field, message: reason }
|
|
89
|
+
: { schemaVersion: "v1", kind: "invalidInput", message: reason };
|
|
90
|
+
}
|
|
91
|
+
export function cancelledError() {
|
|
92
|
+
return {
|
|
93
|
+
schemaVersion: "v1",
|
|
94
|
+
kind: "cancelled",
|
|
95
|
+
message: "Operation was cancelled. Create a fresh AbortController or retry without an already-aborted signal."
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
export function invalidInput(field, reason) {
|
|
99
|
+
return {
|
|
100
|
+
schemaVersion: "v1",
|
|
101
|
+
kind: "invalidInput",
|
|
102
|
+
field,
|
|
103
|
+
message: `Invalid \`${field}\`: ${reason}. Check the value supplied for \`${field}\` and retry with a valid SDK input.`
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
function isRecord(value) {
|
|
107
|
+
return typeof value === "object" && value !== null;
|
|
108
|
+
}
|
|
109
|
+
function withActionableMessage(error) {
|
|
110
|
+
if ("message" in error && typeof error.message === "string" && error.message.length > 0) {
|
|
111
|
+
return error;
|
|
112
|
+
}
|
|
113
|
+
switch (error.kind) {
|
|
114
|
+
case "unknownEnumValue":
|
|
115
|
+
return {
|
|
116
|
+
...error,
|
|
117
|
+
message: `Unsupported value \`${error.value}\` for \`${error.field}\`. Use one of the documented values for this field.`
|
|
118
|
+
};
|
|
119
|
+
case "unsupportedChain":
|
|
120
|
+
return {
|
|
121
|
+
...error,
|
|
122
|
+
message: `Unsupported chain ID ${error.chainId}. Call supportedChainIds() before constructing requests and route unsupported networks to another integration.`
|
|
123
|
+
};
|
|
124
|
+
case "walletTimeout":
|
|
125
|
+
return {
|
|
126
|
+
...error,
|
|
127
|
+
message: `Wallet request timed out after ${error.timeoutMs} ms. Increase walletConfig.timeoutMs or ask the user to approve the wallet request before the timeout.`
|
|
128
|
+
};
|
|
129
|
+
case "cancelled":
|
|
130
|
+
return cancelledError();
|
|
131
|
+
case "__unknown":
|
|
132
|
+
return {
|
|
133
|
+
...error,
|
|
134
|
+
message: unknownMessage()
|
|
135
|
+
};
|
|
136
|
+
default:
|
|
137
|
+
return error;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
function internalMessage(detail) {
|
|
141
|
+
return `SDK internal error: ${detail}. This indicates serialization or invariant failure; retry with the same inputs only after checking the reported input shape.`;
|
|
142
|
+
}
|
|
143
|
+
function unknownMessage() {
|
|
144
|
+
return "SDK received an unrecognized error variant. Inspect raw, preserve it in logs without credentials, and update the SDK if the variant is now documented.";
|
|
145
|
+
}
|