@anywalletkit/protocol-swap2-relay 0.1.1 → 0.1.2
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/README.md +1 -1
- package/dist/{chunk-WRIKAUWI.js → chunk-C3I2XYSW.js} +92 -84
- package/dist/chunk-C3I2XYSW.js.map +1 -0
- package/dist/{chunk-CCMNAZZB.js → chunk-JTPYU26F.js} +72 -29
- package/dist/chunk-JTPYU26F.js.map +1 -0
- package/dist/{chunk-UVHDMGM5.js → chunk-MDXHT7HY.js} +5 -3
- package/dist/chunk-MDXHT7HY.js.map +1 -0
- package/dist/{chunk-7LPLU3MB.js → chunk-TBFD7BPZ.js} +2 -2
- package/dist/index.cjs +163 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -4
- package/dist/order.cjs +4 -2
- package/dist/order.cjs.map +1 -1
- package/dist/order.d.cts +9 -1
- package/dist/order.d.ts +9 -1
- package/dist/order.js +1 -1
- package/dist/protocol.cjs +163 -110
- package/dist/protocol.cjs.map +1 -1
- package/dist/protocol.js +4 -4
- package/dist/provider.cjs +163 -110
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +3 -3
- package/dist/verify.cjs +94 -84
- package/dist/verify.cjs.map +1 -1
- package/dist/verify.d.cts +2 -1
- package/dist/verify.d.ts +2 -1
- package/dist/verify.js +2 -2
- package/package.json +5 -5
- package/dist/chunk-CCMNAZZB.js.map +0 -1
- package/dist/chunk-UVHDMGM5.js.map +0 -1
- package/dist/chunk-WRIKAUWI.js.map +0 -1
- /package/dist/{chunk-7LPLU3MB.js.map → chunk-TBFD7BPZ.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RelaySwap2Protocol
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TBFD7BPZ.js";
|
|
4
4
|
import {
|
|
5
5
|
RELAY_STATUS_MAP,
|
|
6
6
|
relayProvider
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-JTPYU26F.js";
|
|
8
8
|
import {
|
|
9
9
|
RELAY_DEFAULT_SLIPPAGE_BPS,
|
|
10
10
|
RELAY_GAS_CAP,
|
|
@@ -22,14 +22,14 @@ import {
|
|
|
22
22
|
relayVerifyBuild,
|
|
23
23
|
relayVerifyQuote,
|
|
24
24
|
verifyRelayOrder
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-C3I2XYSW.js";
|
|
26
26
|
import {
|
|
27
27
|
RELAY_ORDER_TYPES,
|
|
28
28
|
RelayRefusal,
|
|
29
29
|
parseRelayOrder,
|
|
30
30
|
relayOrderId,
|
|
31
31
|
relayOrderSigner
|
|
32
|
-
} from "./chunk-
|
|
32
|
+
} from "./chunk-MDXHT7HY.js";
|
|
33
33
|
import {
|
|
34
34
|
RELAY_MODULE,
|
|
35
35
|
describeRelayActivity
|
package/dist/order.cjs
CHANGED
|
@@ -28,13 +28,15 @@ __export(order_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(order_exports);
|
|
30
30
|
var import_secp256k1 = require("@noble/curves/secp256k1.js");
|
|
31
|
+
var import_errors = require("@anywalletkit/protocol-swap2-core/errors");
|
|
31
32
|
var import_viem = require("viem");
|
|
32
33
|
var RelayRefusal = class extends Error {
|
|
33
34
|
code;
|
|
34
|
-
constructor(code, detail) {
|
|
35
|
+
constructor(code, detail, reason) {
|
|
35
36
|
super(`relay: ${detail} [${code}]`);
|
|
36
37
|
this.name = "RelayRefusal";
|
|
37
38
|
this.code = code;
|
|
39
|
+
if (reason !== void 0) (0, import_errors.withReason)(this, reason);
|
|
38
40
|
}
|
|
39
41
|
};
|
|
40
42
|
var RELAY_ORDER_TYPES = {
|
|
@@ -91,7 +93,7 @@ var MAX_BYTES_HEX = 2 + 2 * 1024;
|
|
|
91
93
|
var MAX_TEXT = 64;
|
|
92
94
|
var U256_MAX = (1n << 256n) - 1n;
|
|
93
95
|
var bad = (what) => {
|
|
94
|
-
throw new RelayRefusal("order-malformed", `the order's ${what}
|
|
96
|
+
throw new RelayRefusal("order-malformed", `the order's ${what}`, "upstream_unavailable");
|
|
95
97
|
};
|
|
96
98
|
function rec(v, what) {
|
|
97
99
|
if (v === null || typeof v !== "object" || Array.isArray(v)) bad(`${what} is not an object`);
|
package/dist/order.cjs.map
CHANGED
|
@@ -1 +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,oBAAoB;AAAA,EAC/B,OAAO;AAAA,IACL,EAAC,MAAM,WAAW,MAAM,SAAQ;AAAA,IAChC,EAAC,MAAM,iBAAiB,MAAM,SAAQ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AM,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":[]}
|
|
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 {withReason, type Swap2RefusalReason} from \"@anywalletkit/protocol-swap2-core/errors\";\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\n/**\n * `code` names the check; `reason` (a `Swap2RefusalReason` from `@anywalletkit/protocol-swap2-core`) is the stable\n * classification an app switches on. It is set where the refusal is raised, so one code can carry different reasons\n * (an order deadline too far ahead is `policy_refused`, one already used up is `quote_expired`); a malformed request\n * from the caller (a programming error) carries none.\n */\nexport class RelayRefusal extends Error {\n readonly code: RelayRefusalCode;\n declare readonly reason?: Swap2RefusalReason;\n constructor(code: RelayRefusalCode, detail: string, reason?: Swap2RefusalReason) {\n super(`relay: ${detail} [${code}]`);\n this.name = \"RelayRefusal\";\n this.code = code;\n if (reason !== undefined) withReason(this, reason);\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\n// The answer is not the documented shape.\nconst bad = (what: string): never => { throw new RelayRefusal(\"order-malformed\", `the order's ${what}`, \"upstream_unavailable\"); };\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,oBAAkD;AAClD,kBAAuE;AA0DhE,IAAM,eAAN,cAA2B,MAAM;AAAA,EAC7B;AAAA,EAET,YAAY,MAAwB,QAAgB,QAA6B;AAC/E,UAAM,UAAU,MAAM,KAAK,IAAI,GAAG;AAClC,SAAK,OAAO;AACZ,SAAK,OAAO;AACZ,QAAI,WAAW,OAAW,+BAAW,MAAM,MAAM;AAAA,EACnD;AACF;AAEO,IAAM,oBAAoB;AAAA,EAC/B,OAAO;AAAA,IACL,EAAC,MAAM,WAAW,MAAM,SAAQ;AAAA,IAChC,EAAC,MAAM,iBAAiB,MAAM,SAAQ;AAAA,IACtC,EAAC,MAAM,UAAU,MAAM,UAAS;AAAA,IAChC,EAAC,MAAM,QAAQ,MAAM,UAAS;AAAA,IAC9B,EAAC,MAAM,UAAU,MAAM,UAAS;AAAA,IAChC,EAAC,MAAM,UAAU,MAAM,SAAQ;AAAA,IAC/B,EAAC,MAAM,QAAQ,MAAM,QAAO;AAAA,EAC9B;AAAA,EACA,OAAO;AAAA,IACL,EAAC,MAAM,WAAW,MAAM,eAAc;AAAA,IACtC,EAAC,MAAM,WAAW,MAAM,gBAAe;AAAA,EACzC;AAAA,EACA,cAAc;AAAA,IACZ,EAAC,MAAM,WAAW,MAAM,SAAQ;AAAA,IAChC,EAAC,MAAM,YAAY,MAAM,QAAO;A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AAK,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":[]}
|
package/dist/order.d.cts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { Swap2RefusalReason } from '@anywalletkit/protocol-swap2-core/errors';
|
|
1
2
|
import { Hex } from 'viem';
|
|
2
3
|
|
|
3
4
|
/** Why an order, a quote or a deposit was refused. One code per check; the message says what was found. */
|
|
4
5
|
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";
|
|
6
|
+
/**
|
|
7
|
+
* `code` names the check; `reason` (a `Swap2RefusalReason` from `@anywalletkit/protocol-swap2-core`) is the stable
|
|
8
|
+
* classification an app switches on. It is set where the refusal is raised, so one code can carry different reasons
|
|
9
|
+
* (an order deadline too far ahead is `policy_refused`, one already used up is `quote_expired`); a malformed request
|
|
10
|
+
* from the caller (a programming error) carries none.
|
|
11
|
+
*/
|
|
5
12
|
declare class RelayRefusal extends Error {
|
|
6
13
|
readonly code: RelayRefusalCode;
|
|
7
|
-
|
|
14
|
+
readonly reason?: Swap2RefusalReason;
|
|
15
|
+
constructor(code: RelayRefusalCode, detail: string, reason?: Swap2RefusalReason);
|
|
8
16
|
}
|
|
9
17
|
declare const RELAY_ORDER_TYPES: {
|
|
10
18
|
readonly Order: readonly [{
|
package/dist/order.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
|
+
import { Swap2RefusalReason } from '@anywalletkit/protocol-swap2-core/errors';
|
|
1
2
|
import { Hex } from 'viem';
|
|
2
3
|
|
|
3
4
|
/** Why an order, a quote or a deposit was refused. One code per check; the message says what was found. */
|
|
4
5
|
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";
|
|
6
|
+
/**
|
|
7
|
+
* `code` names the check; `reason` (a `Swap2RefusalReason` from `@anywalletkit/protocol-swap2-core`) is the stable
|
|
8
|
+
* classification an app switches on. It is set where the refusal is raised, so one code can carry different reasons
|
|
9
|
+
* (an order deadline too far ahead is `policy_refused`, one already used up is `quote_expired`); a malformed request
|
|
10
|
+
* from the caller (a programming error) carries none.
|
|
11
|
+
*/
|
|
5
12
|
declare class RelayRefusal extends Error {
|
|
6
13
|
readonly code: RelayRefusalCode;
|
|
7
|
-
|
|
14
|
+
readonly reason?: Swap2RefusalReason;
|
|
15
|
+
constructor(code: RelayRefusalCode, detail: string, reason?: Swap2RefusalReason);
|
|
8
16
|
}
|
|
9
17
|
declare const RELAY_ORDER_TYPES: {
|
|
10
18
|
readonly Order: readonly [{
|