@anywalletkit/protocol-swap2-relay 0.0.0-stage → 0.1.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 (58) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +116 -2
  3. package/dist/activity.cjs +82 -0
  4. package/dist/activity.cjs.map +1 -0
  5. package/dist/activity.d.cts +15 -0
  6. package/dist/activity.d.ts +15 -0
  7. package/dist/activity.js +10 -0
  8. package/dist/activity.js.map +1 -0
  9. package/dist/chunk-7LPLU3MB.js +27 -0
  10. package/dist/chunk-7LPLU3MB.js.map +1 -0
  11. package/dist/chunk-CCMNAZZB.js +307 -0
  12. package/dist/chunk-CCMNAZZB.js.map +1 -0
  13. package/dist/chunk-JQAN7HB5.js +80 -0
  14. package/dist/chunk-JQAN7HB5.js.map +1 -0
  15. package/dist/chunk-K5F3BEUO.js +22 -0
  16. package/dist/chunk-K5F3BEUO.js.map +1 -0
  17. package/dist/chunk-UVHDMGM5.js +190 -0
  18. package/dist/chunk-UVHDMGM5.js.map +1 -0
  19. package/dist/chunk-WRIKAUWI.js +384 -0
  20. package/dist/chunk-WRIKAUWI.js.map +1 -0
  21. package/dist/config.cjs +100 -0
  22. package/dist/config.cjs.map +1 -0
  23. package/dist/config.d.cts +58 -0
  24. package/dist/config.d.ts +58 -0
  25. package/dist/config.js +35 -0
  26. package/dist/config.js.map +1 -0
  27. package/dist/index.cjs +965 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +11 -0
  30. package/dist/index.d.ts +11 -0
  31. package/dist/index.js +98 -0
  32. package/dist/index.js.map +1 -0
  33. package/dist/order.cjs +210 -0
  34. package/dist/order.cjs.map +1 -0
  35. package/dist/order.d.cts +178 -0
  36. package/dist/order.d.ts +178 -0
  37. package/dist/order.js +15 -0
  38. package/dist/order.js.map +1 -0
  39. package/dist/protocol.cjs +922 -0
  40. package/dist/protocol.cjs.map +1 -0
  41. package/dist/protocol.d.cts +16 -0
  42. package/dist/protocol.d.ts +16 -0
  43. package/dist/protocol.js +12 -0
  44. package/dist/protocol.js.map +1 -0
  45. package/dist/provider.cjs +907 -0
  46. package/dist/provider.cjs.map +1 -0
  47. package/dist/provider.d.cts +31 -0
  48. package/dist/provider.d.ts +31 -0
  49. package/dist/provider.js +13 -0
  50. package/dist/provider.js.map +1 -0
  51. package/dist/verify.cjs +617 -0
  52. package/dist/verify.cjs.map +1 -0
  53. package/dist/verify.d.cts +151 -0
  54. package/dist/verify.d.ts +151 -0
  55. package/dist/verify.js +39 -0
  56. package/dist/verify.js.map +1 -0
  57. package/module.json +42 -0
  58. package/package.json +99 -3
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/order.ts"],"sourcesContent":["/**\n * A Relay order, read strictly, hashed and attributed here.\n *\n * - The order id is the EIP-712 `hashStruct` of the order under {@link RELAY_ORDER_TYPES} (no domain separator), as\n * github.com/relayprotocol/relay-protocol-sdk (src/order/index.ts) computes it. Chain ids are STRINGS (Relay's own\n * chain names), addresses and currencies are `bytes` (20 raw bytes on an EVM chain).\n * - `orderSignature` is the solver's EIP-191 `personal_sign` over the 32 raw bytes of that id.\n *\n * The id a deposit names is a commitment to everything in the order — recipient, chain, token, minimum, refunds — so\n * recomputing it from the order the API hands over, and reading that same parsed order, is what binds the deposit\n * to terms the device has seen.\n */\nimport {secp256k1} from \"@noble/curves/secp256k1.js\";\nimport {hashMessage, hashStruct, hexToBytes, keccak256, type Hex} from \"viem\";\n\n/** Why an order, a quote or a deposit was refused. One code per check; the message says what was found. */\nexport type RelayRefusalCode =\n | \"request-invalid\"\n | \"chain-unsupported\"\n | \"protocol-data-missing\"\n | \"hub-type\"\n | \"order-malformed\"\n | \"order-version\"\n | \"order-inputs\"\n | \"order-payments\"\n | \"order-calls\"\n | \"order-fees\"\n | \"solver-not-pinned\"\n | \"input-chain\"\n | \"input-currency\"\n | \"input-amount\"\n | \"input-weight\"\n | \"output-chain\"\n | \"output-recipient\"\n | \"output-currency\"\n | \"output-minimum\"\n | \"output-expected\"\n | \"output-deadline\"\n | \"refund-missing\"\n | \"refund-chain\"\n | \"refund-recipient\"\n | \"refund-currency\"\n | \"refund-deadline\"\n | \"order-id-mismatch\"\n | \"signature-invalid\"\n | \"payment-details\"\n | \"tx-chain\"\n | \"tx-target\"\n | \"tx-selector\"\n | \"tx-calldata\"\n | \"tx-depositor\"\n | \"tx-token\"\n | \"tx-amount\"\n | \"tx-id\"\n | \"tx-value\"\n | \"order-reused\"\n | \"app-fee\"\n | \"gas-topup\"\n | \"quote-gas\"\n | \"quote-expiry\"\n | \"quote-steps\"\n | \"quote-amounts\"\n | \"quote-approval\"\n | \"quote-shape\";\n\nexport class RelayRefusal extends Error {\n readonly code: RelayRefusalCode;\n constructor(code: RelayRefusalCode, detail: string) {\n super(`relay: ${detail} [${code}]`);\n this.name = \"RelayRefusal\";\n this.code = code;\n }\n}\n\nexport const RELAY_ORDER_TYPES = {\n Order: [\n {name: \"version\", type: \"string\"},\n {name: \"solverChainId\", type: \"string\"},\n {name: \"solver\", type: \"address\"},\n {name: \"salt\", type: \"uint256\"},\n {name: \"inputs\", type: \"Input[]\"},\n {name: \"output\", type: \"Output\"},\n {name: \"fees\", type: \"Fee[]\"},\n ],\n Input: [\n {name: \"payment\", type: \"InputPayment\"},\n {name: \"refunds\", type: \"InputRefund[]\"},\n ],\n InputPayment: [\n {name: \"chainId\", type: \"string\"},\n {name: \"currency\", type: \"bytes\"},\n {name: \"amount\", type: \"uint256\"},\n {name: \"weight\", type: \"uint256\"},\n ],\n InputRefund: [\n {name: \"chainId\", type: \"string\"},\n {name: \"recipient\", type: \"bytes\"},\n {name: \"currency\", type: \"bytes\"},\n {name: \"minimumAmount\", type: \"uint256\"},\n {name: \"deadline\", type: \"uint32\"},\n {name: \"extraData\", type: \"bytes\"},\n ],\n Output: [\n {name: \"chainId\", type: \"string\"},\n {name: \"payments\", type: \"OutputPayment[]\"},\n {name: \"deadline\", type: \"uint32\"},\n {name: \"calls\", type: \"bytes[]\"},\n {name: \"extraData\", type: \"bytes\"},\n ],\n OutputPayment: [\n {name: \"recipient\", type: \"bytes\"},\n {name: \"currency\", type: \"bytes\"},\n {name: \"minimumAmount\", type: \"uint256\"},\n {name: \"expectedAmount\", type: \"uint256\"},\n ],\n Fee: [\n {name: \"recipientChainId\", type: \"string\"},\n {name: \"recipient\", type: \"bytes\"},\n {name: \"currencyChainId\", type: \"string\"},\n {name: \"currency\", type: \"bytes\"},\n {name: \"amount\", type: \"uint256\"},\n ],\n} as const;\n\nexport interface RelayInputRefund {chainId: string; recipient: Hex; currency: Hex; minimumAmount: bigint; deadline: number; extraData: Hex}\nexport interface RelayInput {payment: {chainId: string; currency: Hex; amount: bigint; weight: bigint}; refunds: RelayInputRefund[]}\nexport interface RelayOutputPayment {recipient: Hex; currency: Hex; minimumAmount: bigint; expectedAmount: bigint}\nexport interface RelayFee {recipientChainId: string; recipient: Hex; currencyChainId: string; currency: Hex; amount: bigint}\n/** An order after {@link parseRelayOrder}: hex lowercased, integers exact. Every field below is hashed into the id. */\nexport interface RelayOrder {\n version: string;\n solverChainId: string;\n solver: Hex;\n salt: bigint;\n inputs: RelayInput[];\n output: {chainId: string; payments: RelayOutputPayment[]; deadline: number; calls: Hex[]; extraData: Hex};\n fees: RelayFee[];\n}\n\nconst MAX_LIST = 8;\nconst MAX_BYTES_HEX = 2 + 2 * 1024;\nconst MAX_TEXT = 64;\nconst U256_MAX = (1n << 256n) - 1n;\n\nconst bad = (what: string): never => { throw new RelayRefusal(\"order-malformed\", `the order's ${what}`); };\n\nfunction rec(v: unknown, what: string): Record<string, unknown> {\n if (v === null || typeof v !== \"object\" || Array.isArray(v)) bad(`${what} is not an object`);\n return v as Record<string, unknown>;\n}\nfunction list(v: unknown, what: string): unknown[] {\n if (!Array.isArray(v)) bad(`${what} is not a list`);\n if ((v as unknown[]).length > MAX_LIST) bad(`${what} has more than ${MAX_LIST} entries`);\n return v as unknown[];\n}\n/** Own property only: a field missing from the JSON is never read off a prototype. */\nfunction own(o: Record<string, unknown>, key: string): unknown {\n return Object.prototype.hasOwnProperty.call(o, key) ? o[key] : undefined;\n}\nfunction text(v: unknown, what: string): string {\n if (typeof v !== \"string\" || v.length === 0 || v.length > MAX_TEXT) bad(`${what} is not a short string`);\n return v as string;\n}\n/** `bytes`: 0x-hex of whole bytes, lowercased. */\nfunction bytes(v: unknown, what: string): Hex {\n if (typeof v !== \"string\" || v.length > MAX_BYTES_HEX || !/^0x(?:[0-9a-fA-F]{2})*$/.test(v)) bad(`${what} is not hex bytes`);\n return (v as string).toLowerCase() as Hex;\n}\n/** `uint256`: a decimal string, a 0x-hex string (Relay writes the salt that way) or a safe non-negative integer. */\nfunction uint(v: unknown, what: string, max: bigint = U256_MAX): bigint {\n let n: bigint | null = null;\n if (typeof v === \"string\" && (/^(?:0|[1-9]\\d{0,77})$/.test(v) || /^0x[0-9a-fA-F]{1,64}$/.test(v))) n = BigInt(v);\n else if (typeof v === \"number\" && Number.isSafeInteger(v) && v >= 0) n = BigInt(v);\n if (n === null || n > max) bad(`${what} is not an unsigned integer in range`);\n return n as bigint;\n}\nfunction uint32(v: unknown, what: string): number {\n // Below 2^32, so the conversion is exact.\n return parseInt(uint(v, what, 0xffff_ffffn).toString(10), 10);\n}\nfunction address(v: unknown, what: string): Hex {\n if (typeof v !== \"string\" || !/^0x[0-9a-fA-F]{40}$/.test(v)) bad(`${what} is not an address`);\n return (v as string).toLowerCase() as Hex;\n}\n\n/**\n * Read an order as the API gives it (`protocol.v2.orderData`, already JSON-parsed) into the one typed form the id,\n * the signature and every check are computed from. Anything that is not exactly the documented shape is refused\n * (`order-malformed`); keys the type does not have are ignored — they are outside the hash, and nothing reads them.\n */\nexport function parseRelayOrder(raw: unknown): RelayOrder {\n const o = rec(raw, \"body\");\n const output = rec(own(o, \"output\"), \"output\");\n return {\n version: text(own(o, \"version\"), \"version\"),\n solverChainId: text(own(o, \"solverChainId\"), \"solver chain\"),\n solver: address(own(o, \"solver\"), \"solver\"),\n salt: uint(own(o, \"salt\"), \"salt\"),\n inputs: list(own(o, \"inputs\"), \"inputs\").map((x, i) => {\n const input = rec(x, `input ${i}`);\n const p = rec(own(input, \"payment\"), `input ${i} payment`);\n return {\n payment: {\n chainId: text(own(p, \"chainId\"), `input ${i} chain`),\n currency: bytes(own(p, \"currency\"), `input ${i} currency`),\n amount: uint(own(p, \"amount\"), `input ${i} amount`),\n weight: uint(own(p, \"weight\"), `input ${i} weight`),\n },\n refunds: list(own(input, \"refunds\"), `input ${i} refunds`).map((y, j) => {\n const r = rec(y, `refund ${j}`);\n return {\n chainId: text(own(r, \"chainId\"), `refund ${j} chain`),\n recipient: bytes(own(r, \"recipient\"), `refund ${j} recipient`),\n currency: bytes(own(r, \"currency\"), `refund ${j} currency`),\n minimumAmount: uint(own(r, \"minimumAmount\"), `refund ${j} minimum`),\n deadline: uint32(own(r, \"deadline\"), `refund ${j} deadline`),\n extraData: bytes(own(r, \"extraData\"), `refund ${j} extra data`),\n };\n }),\n };\n }),\n output: {\n chainId: text(own(output, \"chainId\"), \"output chain\"),\n payments: list(own(output, \"payments\"), \"output payments\").map((x, i) => {\n const p = rec(x, `output payment ${i}`);\n return {\n recipient: bytes(own(p, \"recipient\"), `output payment ${i} recipient`),\n currency: bytes(own(p, \"currency\"), `output payment ${i} currency`),\n minimumAmount: uint(own(p, \"minimumAmount\"), `output payment ${i} minimum`),\n expectedAmount: uint(own(p, \"expectedAmount\"), `output payment ${i} expected amount`),\n };\n }),\n deadline: uint32(own(output, \"deadline\"), \"output deadline\"),\n calls: list(own(output, \"calls\"), \"output calls\").map((x, i) => bytes(x, `output call ${i}`)),\n extraData: bytes(own(output, \"extraData\"), \"output extra data\"),\n },\n fees: list(own(o, \"fees\"), \"fees\").map((x, i) => {\n const f = rec(x, `fee ${i}`);\n return {\n recipientChainId: text(own(f, \"recipientChainId\"), `fee ${i} recipient chain`),\n recipient: bytes(own(f, \"recipient\"), `fee ${i} recipient`),\n currencyChainId: text(own(f, \"currencyChainId\"), `fee ${i} currency chain`),\n currency: bytes(own(f, \"currency\"), `fee ${i} currency`),\n amount: uint(own(f, \"amount\"), `fee ${i} amount`),\n };\n }),\n };\n}\n\n/** The order id: `hashStruct(Order)`, no domain. */\nexport function relayOrderId(order: RelayOrder): Hex {\n return hashStruct({types: RELAY_ORDER_TYPES, primaryType: \"Order\", data: order as never});\n}\n\n/**\n * The address whose `personal_sign` over the id's 32 bytes this signature is (lowercase), or null when it is not a\n * 65-byte secp256k1 signature that recovers at all. Synchronous on purpose: the same check runs wherever the order\n * is read, with nothing left for a later asynchronous step.\n */\nexport function relayOrderSigner(id: Hex, signature: unknown): Hex | null {\n if (typeof signature !== \"string\" || !/^0x[0-9a-fA-F]{130}$/.test(signature)) return null;\n const sig = hexToBytes(signature as Hex);\n const v = sig[64]!;\n const recovery = v === 27 || v === 28 ? v - 27 : v === 0 || v === 1 ? v : -1;\n if (recovery < 0) return null;\n try {\n const recoverable = new Uint8Array(65);\n recoverable[0] = recovery;\n recoverable.set(sig.subarray(0, 64), 1);\n const digest = hexToBytes(hashMessage({raw: id}));\n const key = secp256k1.recoverPublicKey(recoverable, digest, {prehash: false});\n // The recovery must also verify: a malformed (r, s) never passes as a signer.\n if (!secp256k1.verify(sig.subarray(0, 64), digest, key, {prehash: false})) return null;\n const uncompressed = secp256k1.Point.fromBytes(key).toBytes(false);\n return `0x${keccak256(uncompressed.subarray(1)).slice(-40)}`.toLowerCase() as Hex;\n } catch {\n return null;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA,uBAAwB;AACxB,kBAAuE;AAoDhE,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EACT,YAAY,MAAwB,QAAgB;AAClD,UAAM,UAAU,MAAM,KAAK,IAAI,GAAG;AAClC,SAAK,OAAO;AACZ,SAAK,OAAO;AAAA,EACd;AACF;AAEO,IAAM,oB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Y,CAAC,uBAAuB,KAAK,SAAS,EAAG,QAAO;AACrF,QAAM,UAAM,wBAAW,SAAgB;AACvC,QAAM,IAAI,IAAI,EAAE;AAChB,QAAM,WAAW,MAAM,MAAM,MAAM,KAAK,IAAI,KAAK,MAAM,KAAK,MAAM,IAAI,IAAI;AAC1E,MAAI,WAAW,EAAG,QAAO;AACzB,MAAI;AACF,UAAM,cAAc,IAAI,WAAW,EAAE;AACrC,gBAAY,CAAC,IAAI;AACjB,gBAAY,IAAI,IAAI,SAAS,GAAG,EAAE,GAAG,CAAC;AACtC,UAAM,aAAS,4BAAW,yBAAY,EAAC,KAAK,GAAE,CAAC,CAAC;AAChD,UAAM,MAAM,2BAAU,iBAAiB,aAAa,QAAQ,EAAC,SAAS,MAAK,CAAC;AAE5E,QAAI,CAAC,2BAAU,OAAO,IAAI,SAAS,GAAG,EAAE,GAAG,QAAQ,KAAK,EAAC,SAAS,MAAK,CAAC,EAAG,QAAO;AAClF,UAAM,eAAe,2BAAU,MAAM,UAAU,GAAG,EAAE,QAAQ,KAAK;AACjE,WAAO,SAAK,uBAAU,aAAa,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,CAAC,GAAG,YAAY;AAAA,EAC3E,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -0,0 +1,178 @@
1
+ import { Hex } from 'viem';
2
+
3
+ /** Why an order, a quote or a deposit was refused. One code per check; the message says what was found. */
4
+ type RelayRefusalCode = "request-invalid" | "chain-unsupported" | "protocol-data-missing" | "hub-type" | "order-malformed" | "order-version" | "order-inputs" | "order-payments" | "order-calls" | "order-fees" | "solver-not-pinned" | "input-chain" | "input-currency" | "input-amount" | "input-weight" | "output-chain" | "output-recipient" | "output-currency" | "output-minimum" | "output-expected" | "output-deadline" | "refund-missing" | "refund-chain" | "refund-recipient" | "refund-currency" | "refund-deadline" | "order-id-mismatch" | "signature-invalid" | "payment-details" | "tx-chain" | "tx-target" | "tx-selector" | "tx-calldata" | "tx-depositor" | "tx-token" | "tx-amount" | "tx-id" | "tx-value" | "order-reused" | "app-fee" | "gas-topup" | "quote-gas" | "quote-expiry" | "quote-steps" | "quote-amounts" | "quote-approval" | "quote-shape";
5
+ declare class RelayRefusal extends Error {
6
+ readonly code: RelayRefusalCode;
7
+ constructor(code: RelayRefusalCode, detail: string);
8
+ }
9
+ declare const RELAY_ORDER_TYPES: {
10
+ readonly Order: readonly [{
11
+ readonly name: "version";
12
+ readonly type: "string";
13
+ }, {
14
+ readonly name: "solverChainId";
15
+ readonly type: "string";
16
+ }, {
17
+ readonly name: "solver";
18
+ readonly type: "address";
19
+ }, {
20
+ readonly name: "salt";
21
+ readonly type: "uint256";
22
+ }, {
23
+ readonly name: "inputs";
24
+ readonly type: "Input[]";
25
+ }, {
26
+ readonly name: "output";
27
+ readonly type: "Output";
28
+ }, {
29
+ readonly name: "fees";
30
+ readonly type: "Fee[]";
31
+ }];
32
+ readonly Input: readonly [{
33
+ readonly name: "payment";
34
+ readonly type: "InputPayment";
35
+ }, {
36
+ readonly name: "refunds";
37
+ readonly type: "InputRefund[]";
38
+ }];
39
+ readonly InputPayment: readonly [{
40
+ readonly name: "chainId";
41
+ readonly type: "string";
42
+ }, {
43
+ readonly name: "currency";
44
+ readonly type: "bytes";
45
+ }, {
46
+ readonly name: "amount";
47
+ readonly type: "uint256";
48
+ }, {
49
+ readonly name: "weight";
50
+ readonly type: "uint256";
51
+ }];
52
+ readonly InputRefund: readonly [{
53
+ readonly name: "chainId";
54
+ readonly type: "string";
55
+ }, {
56
+ readonly name: "recipient";
57
+ readonly type: "bytes";
58
+ }, {
59
+ readonly name: "currency";
60
+ readonly type: "bytes";
61
+ }, {
62
+ readonly name: "minimumAmount";
63
+ readonly type: "uint256";
64
+ }, {
65
+ readonly name: "deadline";
66
+ readonly type: "uint32";
67
+ }, {
68
+ readonly name: "extraData";
69
+ readonly type: "bytes";
70
+ }];
71
+ readonly Output: readonly [{
72
+ readonly name: "chainId";
73
+ readonly type: "string";
74
+ }, {
75
+ readonly name: "payments";
76
+ readonly type: "OutputPayment[]";
77
+ }, {
78
+ readonly name: "deadline";
79
+ readonly type: "uint32";
80
+ }, {
81
+ readonly name: "calls";
82
+ readonly type: "bytes[]";
83
+ }, {
84
+ readonly name: "extraData";
85
+ readonly type: "bytes";
86
+ }];
87
+ readonly OutputPayment: readonly [{
88
+ readonly name: "recipient";
89
+ readonly type: "bytes";
90
+ }, {
91
+ readonly name: "currency";
92
+ readonly type: "bytes";
93
+ }, {
94
+ readonly name: "minimumAmount";
95
+ readonly type: "uint256";
96
+ }, {
97
+ readonly name: "expectedAmount";
98
+ readonly type: "uint256";
99
+ }];
100
+ readonly Fee: readonly [{
101
+ readonly name: "recipientChainId";
102
+ readonly type: "string";
103
+ }, {
104
+ readonly name: "recipient";
105
+ readonly type: "bytes";
106
+ }, {
107
+ readonly name: "currencyChainId";
108
+ readonly type: "string";
109
+ }, {
110
+ readonly name: "currency";
111
+ readonly type: "bytes";
112
+ }, {
113
+ readonly name: "amount";
114
+ readonly type: "uint256";
115
+ }];
116
+ };
117
+ interface RelayInputRefund {
118
+ chainId: string;
119
+ recipient: Hex;
120
+ currency: Hex;
121
+ minimumAmount: bigint;
122
+ deadline: number;
123
+ extraData: Hex;
124
+ }
125
+ interface RelayInput {
126
+ payment: {
127
+ chainId: string;
128
+ currency: Hex;
129
+ amount: bigint;
130
+ weight: bigint;
131
+ };
132
+ refunds: RelayInputRefund[];
133
+ }
134
+ interface RelayOutputPayment {
135
+ recipient: Hex;
136
+ currency: Hex;
137
+ minimumAmount: bigint;
138
+ expectedAmount: bigint;
139
+ }
140
+ interface RelayFee {
141
+ recipientChainId: string;
142
+ recipient: Hex;
143
+ currencyChainId: string;
144
+ currency: Hex;
145
+ amount: bigint;
146
+ }
147
+ /** An order after {@link parseRelayOrder}: hex lowercased, integers exact. Every field below is hashed into the id. */
148
+ interface RelayOrder {
149
+ version: string;
150
+ solverChainId: string;
151
+ solver: Hex;
152
+ salt: bigint;
153
+ inputs: RelayInput[];
154
+ output: {
155
+ chainId: string;
156
+ payments: RelayOutputPayment[];
157
+ deadline: number;
158
+ calls: Hex[];
159
+ extraData: Hex;
160
+ };
161
+ fees: RelayFee[];
162
+ }
163
+ /**
164
+ * Read an order as the API gives it (`protocol.v2.orderData`, already JSON-parsed) into the one typed form the id,
165
+ * the signature and every check are computed from. Anything that is not exactly the documented shape is refused
166
+ * (`order-malformed`); keys the type does not have are ignored — they are outside the hash, and nothing reads them.
167
+ */
168
+ declare function parseRelayOrder(raw: unknown): RelayOrder;
169
+ /** The order id: `hashStruct(Order)`, no domain. */
170
+ declare function relayOrderId(order: RelayOrder): Hex;
171
+ /**
172
+ * The address whose `personal_sign` over the id's 32 bytes this signature is (lowercase), or null when it is not a
173
+ * 65-byte secp256k1 signature that recovers at all. Synchronous on purpose: the same check runs wherever the order
174
+ * is read, with nothing left for a later asynchronous step.
175
+ */
176
+ declare function relayOrderSigner(id: Hex, signature: unknown): Hex | null;
177
+
178
+ export { RELAY_ORDER_TYPES, type RelayFee, type RelayInput, type RelayInputRefund, type RelayOrder, type RelayOutputPayment, RelayRefusal, type RelayRefusalCode, parseRelayOrder, relayOrderId, relayOrderSigner };
@@ -0,0 +1,178 @@
1
+ import { Hex } from 'viem';
2
+
3
+ /** Why an order, a quote or a deposit was refused. One code per check; the message says what was found. */
4
+ type RelayRefusalCode = "request-invalid" | "chain-unsupported" | "protocol-data-missing" | "hub-type" | "order-malformed" | "order-version" | "order-inputs" | "order-payments" | "order-calls" | "order-fees" | "solver-not-pinned" | "input-chain" | "input-currency" | "input-amount" | "input-weight" | "output-chain" | "output-recipient" | "output-currency" | "output-minimum" | "output-expected" | "output-deadline" | "refund-missing" | "refund-chain" | "refund-recipient" | "refund-currency" | "refund-deadline" | "order-id-mismatch" | "signature-invalid" | "payment-details" | "tx-chain" | "tx-target" | "tx-selector" | "tx-calldata" | "tx-depositor" | "tx-token" | "tx-amount" | "tx-id" | "tx-value" | "order-reused" | "app-fee" | "gas-topup" | "quote-gas" | "quote-expiry" | "quote-steps" | "quote-amounts" | "quote-approval" | "quote-shape";
5
+ declare class RelayRefusal extends Error {
6
+ readonly code: RelayRefusalCode;
7
+ constructor(code: RelayRefusalCode, detail: string);
8
+ }
9
+ declare const RELAY_ORDER_TYPES: {
10
+ readonly Order: readonly [{
11
+ readonly name: "version";
12
+ readonly type: "string";
13
+ }, {
14
+ readonly name: "solverChainId";
15
+ readonly type: "string";
16
+ }, {
17
+ readonly name: "solver";
18
+ readonly type: "address";
19
+ }, {
20
+ readonly name: "salt";
21
+ readonly type: "uint256";
22
+ }, {
23
+ readonly name: "inputs";
24
+ readonly type: "Input[]";
25
+ }, {
26
+ readonly name: "output";
27
+ readonly type: "Output";
28
+ }, {
29
+ readonly name: "fees";
30
+ readonly type: "Fee[]";
31
+ }];
32
+ readonly Input: readonly [{
33
+ readonly name: "payment";
34
+ readonly type: "InputPayment";
35
+ }, {
36
+ readonly name: "refunds";
37
+ readonly type: "InputRefund[]";
38
+ }];
39
+ readonly InputPayment: readonly [{
40
+ readonly name: "chainId";
41
+ readonly type: "string";
42
+ }, {
43
+ readonly name: "currency";
44
+ readonly type: "bytes";
45
+ }, {
46
+ readonly name: "amount";
47
+ readonly type: "uint256";
48
+ }, {
49
+ readonly name: "weight";
50
+ readonly type: "uint256";
51
+ }];
52
+ readonly InputRefund: readonly [{
53
+ readonly name: "chainId";
54
+ readonly type: "string";
55
+ }, {
56
+ readonly name: "recipient";
57
+ readonly type: "bytes";
58
+ }, {
59
+ readonly name: "currency";
60
+ readonly type: "bytes";
61
+ }, {
62
+ readonly name: "minimumAmount";
63
+ readonly type: "uint256";
64
+ }, {
65
+ readonly name: "deadline";
66
+ readonly type: "uint32";
67
+ }, {
68
+ readonly name: "extraData";
69
+ readonly type: "bytes";
70
+ }];
71
+ readonly Output: readonly [{
72
+ readonly name: "chainId";
73
+ readonly type: "string";
74
+ }, {
75
+ readonly name: "payments";
76
+ readonly type: "OutputPayment[]";
77
+ }, {
78
+ readonly name: "deadline";
79
+ readonly type: "uint32";
80
+ }, {
81
+ readonly name: "calls";
82
+ readonly type: "bytes[]";
83
+ }, {
84
+ readonly name: "extraData";
85
+ readonly type: "bytes";
86
+ }];
87
+ readonly OutputPayment: readonly [{
88
+ readonly name: "recipient";
89
+ readonly type: "bytes";
90
+ }, {
91
+ readonly name: "currency";
92
+ readonly type: "bytes";
93
+ }, {
94
+ readonly name: "minimumAmount";
95
+ readonly type: "uint256";
96
+ }, {
97
+ readonly name: "expectedAmount";
98
+ readonly type: "uint256";
99
+ }];
100
+ readonly Fee: readonly [{
101
+ readonly name: "recipientChainId";
102
+ readonly type: "string";
103
+ }, {
104
+ readonly name: "recipient";
105
+ readonly type: "bytes";
106
+ }, {
107
+ readonly name: "currencyChainId";
108
+ readonly type: "string";
109
+ }, {
110
+ readonly name: "currency";
111
+ readonly type: "bytes";
112
+ }, {
113
+ readonly name: "amount";
114
+ readonly type: "uint256";
115
+ }];
116
+ };
117
+ interface RelayInputRefund {
118
+ chainId: string;
119
+ recipient: Hex;
120
+ currency: Hex;
121
+ minimumAmount: bigint;
122
+ deadline: number;
123
+ extraData: Hex;
124
+ }
125
+ interface RelayInput {
126
+ payment: {
127
+ chainId: string;
128
+ currency: Hex;
129
+ amount: bigint;
130
+ weight: bigint;
131
+ };
132
+ refunds: RelayInputRefund[];
133
+ }
134
+ interface RelayOutputPayment {
135
+ recipient: Hex;
136
+ currency: Hex;
137
+ minimumAmount: bigint;
138
+ expectedAmount: bigint;
139
+ }
140
+ interface RelayFee {
141
+ recipientChainId: string;
142
+ recipient: Hex;
143
+ currencyChainId: string;
144
+ currency: Hex;
145
+ amount: bigint;
146
+ }
147
+ /** An order after {@link parseRelayOrder}: hex lowercased, integers exact. Every field below is hashed into the id. */
148
+ interface RelayOrder {
149
+ version: string;
150
+ solverChainId: string;
151
+ solver: Hex;
152
+ salt: bigint;
153
+ inputs: RelayInput[];
154
+ output: {
155
+ chainId: string;
156
+ payments: RelayOutputPayment[];
157
+ deadline: number;
158
+ calls: Hex[];
159
+ extraData: Hex;
160
+ };
161
+ fees: RelayFee[];
162
+ }
163
+ /**
164
+ * Read an order as the API gives it (`protocol.v2.orderData`, already JSON-parsed) into the one typed form the id,
165
+ * the signature and every check are computed from. Anything that is not exactly the documented shape is refused
166
+ * (`order-malformed`); keys the type does not have are ignored — they are outside the hash, and nothing reads them.
167
+ */
168
+ declare function parseRelayOrder(raw: unknown): RelayOrder;
169
+ /** The order id: `hashStruct(Order)`, no domain. */
170
+ declare function relayOrderId(order: RelayOrder): Hex;
171
+ /**
172
+ * The address whose `personal_sign` over the id's 32 bytes this signature is (lowercase), or null when it is not a
173
+ * 65-byte secp256k1 signature that recovers at all. Synchronous on purpose: the same check runs wherever the order
174
+ * is read, with nothing left for a later asynchronous step.
175
+ */
176
+ declare function relayOrderSigner(id: Hex, signature: unknown): Hex | null;
177
+
178
+ export { RELAY_ORDER_TYPES, type RelayFee, type RelayInput, type RelayInputRefund, type RelayOrder, type RelayOutputPayment, RelayRefusal, type RelayRefusalCode, parseRelayOrder, relayOrderId, relayOrderSigner };
package/dist/order.js ADDED
@@ -0,0 +1,15 @@
1
+ import {
2
+ RELAY_ORDER_TYPES,
3
+ RelayRefusal,
4
+ parseRelayOrder,
5
+ relayOrderId,
6
+ relayOrderSigner
7
+ } from "./chunk-UVHDMGM5.js";
8
+ export {
9
+ RELAY_ORDER_TYPES,
10
+ RelayRefusal,
11
+ parseRelayOrder,
12
+ relayOrderId,
13
+ relayOrderSigner
14
+ };
15
+ //# sourceMappingURL=order.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}