@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,27 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const __cow_sdk_wasm_init: () => void;
5
+ export const computeOrderUid: (a: number, b: number, c: number, d: number, e: number) => void;
6
+ export const decodeEthFlowLog: (a: number, b: number) => void;
7
+ export const decodeSettlementLog: (a: number, b: number) => void;
8
+ export const deploymentAddresses: (a: number, b: number, c: number, d: number) => void;
9
+ export const domainSeparator: (a: number, b: number) => void;
10
+ export const eip1271SignaturePayload: (a: number, b: number, c: number, d: number) => void;
11
+ export const orderTypedData: (a: number, b: number, c: number) => void;
12
+ export const signOrderEthSignDigest: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
13
+ export const signOrderWithCustomEip1271: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
14
+ export const signOrderWithEip1193: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
15
+ export const signOrderWithEip1271: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
16
+ export const signOrderWithTypedDataSigner: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
17
+ export const supportedChainIds: (a: number) => void;
18
+ export const wasmVersion: (a: number) => void;
19
+ export const __wasm_bindgen_func_elem_1594: (a: number, b: number, c: number, d: number) => void;
20
+ export const __wasm_bindgen_func_elem_1603: (a: number, b: number, c: number, d: number) => void;
21
+ export const __wasm_bindgen_func_elem_1317: (a: number, b: number) => void;
22
+ export const __wbindgen_export: (a: number, b: number) => number;
23
+ export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
24
+ export const __wbindgen_export3: (a: number) => void;
25
+ export const __wbindgen_export4: (a: number, b: number, c: number) => void;
26
+ export const __wbindgen_export5: (a: number, b: number) => void;
27
+ export const __wbindgen_add_to_stack_pointer: (a: number) => number;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ export type SchemaVersion = "v1" | "__unknown";
2
+ export interface WasmEnvelope<T> {
3
+ schemaVersion: SchemaVersion;
4
+ value: T;
5
+ }
@@ -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
+ }
@@ -0,0 +1,93 @@
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.computeOrderUid = computeOrderUid;
37
+ exports.decodeEthFlowLog = decodeEthFlowLog;
38
+ exports.decodeSettlementLog = decodeSettlementLog;
39
+ exports.deploymentAddresses = deploymentAddresses;
40
+ exports.domainSeparator = domainSeparator;
41
+ exports.eip1271SignaturePayload = eip1271SignaturePayload;
42
+ exports.orderTypedData = orderTypedData;
43
+ exports.signOrderEthSignDigest = signOrderEthSignDigest;
44
+ exports.signOrderWithCustomEip1271 = signOrderWithCustomEip1271;
45
+ exports.signOrderWithEip1193 = signOrderWithEip1193;
46
+ exports.signOrderWithEip1271 = signOrderWithEip1271;
47
+ exports.signOrderWithTypedDataSigner = signOrderWithTypedDataSigner;
48
+ exports.supportedChainIds = supportedChainIds;
49
+ exports.wasmVersion = wasmVersion;
50
+ const raw = __importStar(require("./raw/signing.cjs"));
51
+ const internal_js_1 = require("./internal.cjs");
52
+ function computeOrderUid(input, chainId, owner) {
53
+ return (0, internal_js_1.callSync)(() => raw.computeOrderUid(input, chainId, owner));
54
+ }
55
+ function decodeEthFlowLog(log) {
56
+ return (0, internal_js_1.callSync)(() => raw.decodeEthFlowLog(log));
57
+ }
58
+ function decodeSettlementLog(log) {
59
+ return (0, internal_js_1.callSync)(() => raw.decodeSettlementLog(log));
60
+ }
61
+ function deploymentAddresses(chainId, env) {
62
+ return (0, internal_js_1.callSync)(() => raw.deploymentAddresses(chainId, env ?? null));
63
+ }
64
+ function domainSeparator(chainId) {
65
+ return (0, internal_js_1.callSync)(() => raw.domainSeparator(chainId));
66
+ }
67
+ function eip1271SignaturePayload(input, ecdsaSignature) {
68
+ return (0, internal_js_1.callSync)(() => raw.eip1271SignaturePayload(input, ecdsaSignature));
69
+ }
70
+ function orderTypedData(input, chainId) {
71
+ return (0, internal_js_1.callSync)(() => raw.orderTypedData(input, chainId));
72
+ }
73
+ function signOrderEthSignDigest(input, chainId, owner, digestSigner, options) {
74
+ return (0, internal_js_1.callAsync)(() => raw.signOrderEthSignDigest(input, chainId, owner, digestSigner, options ?? null));
75
+ }
76
+ function signOrderWithCustomEip1271(input, chainId, owner, customCallback, options) {
77
+ return (0, internal_js_1.callAsync)(() => raw.signOrderWithCustomEip1271(input, chainId, owner, customCallback, options ?? null));
78
+ }
79
+ function signOrderWithEip1193(input, chainId, owner, requestCallback, options) {
80
+ return (0, internal_js_1.callAsync)(() => raw.signOrderWithEip1193(input, chainId, owner, requestCallback, options ?? null));
81
+ }
82
+ function signOrderWithEip1271(input, chainId, owner, typedDataSigner, options) {
83
+ return (0, internal_js_1.callAsync)(() => raw.signOrderWithEip1271(input, chainId, owner, typedDataSigner, options ?? null));
84
+ }
85
+ function signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options) {
86
+ return (0, internal_js_1.callAsync)(() => raw.signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options ?? null));
87
+ }
88
+ function supportedChainIds() {
89
+ return (0, internal_js_1.callSync)(() => raw.supportedChainIds());
90
+ }
91
+ function wasmVersion() {
92
+ return (0, internal_js_1.callSync)(() => raw.wasmVersion());
93
+ }
@@ -0,0 +1,23 @@
1
+ import * as raw from "./raw/signing.js";
2
+ import type { WasmEnvelope } from "./envelope.js";
3
+ import type { SigningOptions } from "./options.js";
4
+ import type { CustomEip1271Callback, DigestSignerCallback, Eip1193RequestCallback, TypedDataSignerCallback } from "./callbacks.js";
5
+ export declare function computeOrderUid(input: raw.OrderInput, chainId: number, owner: string): WasmEnvelope<raw.GeneratedOrderUidDto>;
6
+ export declare function decodeEthFlowLog(log: raw.EventLogInput): WasmEnvelope<raw.EthFlowEventDto>;
7
+ export declare function decodeSettlementLog(log: raw.EventLogInput): WasmEnvelope<raw.SettlementEventDto>;
8
+ export declare function deploymentAddresses(chainId: number, env?: string | null): WasmEnvelope<raw.DeploymentAddressesDto>;
9
+ export declare function domainSeparator(chainId: number): string;
10
+ export declare function eip1271SignaturePayload(input: raw.OrderInput, ecdsaSignature: string): WasmEnvelope<string>;
11
+ export declare function orderTypedData(input: raw.OrderInput, chainId: number): WasmEnvelope<raw.TypedDataEnvelopeDto>;
12
+ export declare function signOrderEthSignDigest(input: raw.OrderInput, chainId: number, owner: string, digestSigner: DigestSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
13
+ export declare function signOrderWithCustomEip1271(input: raw.OrderInput, chainId: number, owner: string, customCallback: CustomEip1271Callback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
14
+ export declare function signOrderWithEip1193(input: raw.OrderInput, chainId: number, owner: string, requestCallback: Eip1193RequestCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
15
+ export declare function signOrderWithEip1271(input: raw.OrderInput, chainId: number, owner: string, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
16
+ export declare function signOrderWithTypedDataSigner(input: raw.OrderInput, chainId: number, owner: string, typedDataSigner: TypedDataSignerCallback, options?: SigningOptions | null): Promise<WasmEnvelope<raw.SignedOrderDto>>;
17
+ export declare function supportedChainIds(): Uint32Array;
18
+ export declare function wasmVersion(): string;
19
+ export type { CowEip1271SignRequest, DeploymentAddressesDto, Eip1193Request, EthFlowEventDto, EventLogInput, GeneratedOrderUidDto, OrderInput, OrderKindDto, OrderTraderParametersInput, PaginationOptions, SettlementEventDto, SignedOrderDto, TokenBalanceDto, TradesQueryInput, TransactionRequestDto, TypedDataDomainDto, TypedDataEnvelopeDto, TypedDataFieldDto } from "./raw/signing.js";
20
+ export type { CowEip1271SignCallback, CustomEip1271Callback, DigestSignerCallback, Eip1193RequestCallback, TypedDataSignerCallback } from "./callbacks.js";
21
+ export type { OrderBookRejectionCategory, CowError } from "./errors.js";
22
+ export type { SchemaVersion, WasmEnvelope } from "./envelope.js";
23
+ export type { SdkClientOptions, SigningOptions, WalletConfig } from "./options.js";
@@ -0,0 +1 @@
1
+ export * from "./default.js";
@@ -0,0 +1,44 @@
1
+ import * as raw from "./raw/signing.js";
2
+ import { callAsync, callSync } from "./internal.js";
3
+ export function computeOrderUid(input, chainId, owner) {
4
+ return callSync(() => raw.computeOrderUid(input, chainId, owner));
5
+ }
6
+ export function decodeEthFlowLog(log) {
7
+ return callSync(() => raw.decodeEthFlowLog(log));
8
+ }
9
+ export function decodeSettlementLog(log) {
10
+ return callSync(() => raw.decodeSettlementLog(log));
11
+ }
12
+ export function deploymentAddresses(chainId, env) {
13
+ return callSync(() => raw.deploymentAddresses(chainId, env ?? null));
14
+ }
15
+ export function domainSeparator(chainId) {
16
+ return callSync(() => raw.domainSeparator(chainId));
17
+ }
18
+ export function eip1271SignaturePayload(input, ecdsaSignature) {
19
+ return callSync(() => raw.eip1271SignaturePayload(input, ecdsaSignature));
20
+ }
21
+ export function orderTypedData(input, chainId) {
22
+ return callSync(() => raw.orderTypedData(input, chainId));
23
+ }
24
+ export function signOrderEthSignDigest(input, chainId, owner, digestSigner, options) {
25
+ return callAsync(() => raw.signOrderEthSignDigest(input, chainId, owner, digestSigner, options ?? null));
26
+ }
27
+ export function signOrderWithCustomEip1271(input, chainId, owner, customCallback, options) {
28
+ return callAsync(() => raw.signOrderWithCustomEip1271(input, chainId, owner, customCallback, options ?? null));
29
+ }
30
+ export function signOrderWithEip1193(input, chainId, owner, requestCallback, options) {
31
+ return callAsync(() => raw.signOrderWithEip1193(input, chainId, owner, requestCallback, options ?? null));
32
+ }
33
+ export function signOrderWithEip1271(input, chainId, owner, typedDataSigner, options) {
34
+ return callAsync(() => raw.signOrderWithEip1271(input, chainId, owner, typedDataSigner, options ?? null));
35
+ }
36
+ export function signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options) {
37
+ return callAsync(() => raw.signOrderWithTypedDataSigner(input, chainId, owner, typedDataSigner, options ?? null));
38
+ }
39
+ export function supportedChainIds() {
40
+ return callSync(() => raw.supportedChainIds());
41
+ }
42
+ export function wasmVersion() {
43
+ return callSync(() => raw.wasmVersion());
44
+ }