@hfunlabs/hyperliquid 0.30.0-hfunlabs.1 → 0.30.2-hfunlabs.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/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +58 -0
- package/esm/_dnt.shims.js.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts +195 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js +457 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts +90 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js +207 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts +159 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js +555 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts +325 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js +1222 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts +76 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js +283 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts +103 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.js +241 -0
- package/esm/deps/jsr.io/@noble/curves/2.0.1/src/utils.js.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts +49 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js +147 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts +55 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js +67 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts +36 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js +90 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts +199 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js +397 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts +58 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js +254 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts +124 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js +243 -0
- package/esm/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts +44 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js +144 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts +38 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js +96 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts +23 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js +98 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts +300 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js +535 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts +98 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js +207 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts +78 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js +298 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts +6 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js +6 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts +66 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js +180 -0
- package/esm/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts +877 -0
- package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js +2001 -0
- package/esm/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js.map +1 -0
- package/esm/deps/jsr.io/@scure/base/2.0.0/index.d.ts +294 -0
- package/esm/deps/jsr.io/@scure/base/2.0.0/index.d.ts.map +1 -0
- package/esm/deps/jsr.io/@scure/base/2.0.0/index.js +704 -0
- package/esm/deps/jsr.io/@scure/base/2.0.0/index.js.map +1 -0
- package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts +93 -0
- package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js +137 -0
- package/esm/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js.map +1 -0
- package/esm/src/api/exchange/_methods/_base/_nonce.d.ts +3 -2
- package/esm/src/api/exchange/_methods/_base/_nonce.d.ts.map +1 -1
- package/esm/src/api/exchange/_methods/_base/_nonce.js +3 -2
- package/esm/src/api/exchange/_methods/_base/_nonce.js.map +1 -1
- package/esm/src/api/exchange/_methods/_base/_semaphore.d.ts +7 -6
- package/esm/src/api/exchange/_methods/_base/_semaphore.d.ts.map +1 -1
- package/esm/src/api/exchange/_methods/_base/_semaphore.js +34 -47
- package/esm/src/api/exchange/_methods/_base/_semaphore.js.map +1 -1
- package/esm/src/api/exchange/_methods/_base/execute.d.ts +14 -3
- package/esm/src/api/exchange/_methods/_base/execute.d.ts.map +1 -1
- package/esm/src/api/exchange/_methods/_base/execute.js +44 -10
- package/esm/src/api/exchange/_methods/_base/execute.js.map +1 -1
- package/esm/src/api/exchange/_methods/batchModify.d.ts +6 -6
- package/esm/src/api/exchange/_methods/createVault.d.ts +5 -5
- package/esm/src/api/exchange/_methods/modify.d.ts +5 -5
- package/esm/src/api/exchange/_methods/order.d.ts +13 -13
- package/esm/src/api/exchange/_methods/order.d.ts.map +1 -1
- package/esm/src/api/exchange/_methods/order.js +4 -2
- package/esm/src/api/exchange/_methods/order.js.map +1 -1
- package/esm/src/api/exchange/client.d.ts +1 -1
- package/esm/src/api/exchange/client.d.ts.map +1 -1
- package/esm/src/api/exchange/client.js.map +1 -1
- package/esm/src/api/exchange/mod.d.ts +1 -1
- package/esm/src/api/exchange/mod.d.ts.map +1 -1
- package/esm/src/api/exchange/mod.js.map +1 -1
- package/esm/src/api/info/_methods/_base/commonSchemas.d.ts +8 -8
- package/esm/src/api/info/_methods/frontendOpenOrders.d.ts +3 -3
- package/esm/src/api/info/_methods/historicalOrders.d.ts +4 -4
- package/esm/src/api/info/_methods/l3Orders.d.ts +11 -11
- package/esm/src/api/info/_methods/l4Orders.d.ts +6 -6
- package/esm/src/api/info/_methods/openOrders.d.ts +3 -3
- package/esm/src/api/info/_methods/orderStatus.d.ts +5 -5
- package/esm/src/api/info/_methods/recentTrades.d.ts +2 -2
- package/esm/src/api/info/_methods/twapHistory.d.ts +4 -4
- package/esm/src/api/info/_methods/userFills.d.ts +3 -3
- package/esm/src/api/info/_methods/userFillsByTime.d.ts +4 -4
- package/esm/src/api/info/_methods/userFunding.d.ts +3 -3
- package/esm/src/api/info/_methods/userFunding.js +2 -2
- package/esm/src/api/info/_methods/userFunding.js.map +1 -1
- package/esm/src/api/info/_methods/userTwapSliceFills.d.ts +4 -4
- package/esm/src/api/info/_methods/userTwapSliceFillsByTime.d.ts +5 -5
- package/esm/src/api/info/_methods/webData2.d.ts +9 -9
- package/esm/src/api/subscription/_methods/assetCtxs.d.ts +2 -0
- package/esm/src/api/subscription/_methods/assetCtxs.d.ts.map +1 -1
- package/esm/src/api/subscription/_methods/assetCtxs.js.map +1 -1
- package/esm/src/api/subscription/_methods/clearinghouseState.d.ts +2 -0
- package/esm/src/api/subscription/_methods/clearinghouseState.d.ts.map +1 -1
- package/esm/src/api/subscription/_methods/clearinghouseState.js +2 -0
- package/esm/src/api/subscription/_methods/clearinghouseState.js.map +1 -1
- package/esm/src/api/subscription/_methods/explorerBlock.d.ts +2 -0
- package/esm/src/api/subscription/_methods/explorerBlock.d.ts.map +1 -1
- package/esm/src/api/subscription/_methods/explorerBlock.js +2 -0
- package/esm/src/api/subscription/_methods/explorerBlock.js.map +1 -1
- package/esm/src/api/subscription/_methods/explorerTxs.d.ts +2 -0
- package/esm/src/api/subscription/_methods/explorerTxs.d.ts.map +1 -1
- package/esm/src/api/subscription/_methods/explorerTxs.js +2 -0
- package/esm/src/api/subscription/_methods/explorerTxs.js.map +1 -1
- package/esm/src/api/subscription/_methods/openOrders.d.ts +5 -5
- package/esm/src/api/subscription/_methods/orderUpdates.d.ts +4 -4
- package/esm/src/api/subscription/_methods/trades.d.ts +3 -3
- package/esm/src/api/subscription/_methods/twapStates.d.ts +9 -4
- package/esm/src/api/subscription/_methods/twapStates.d.ts.map +1 -1
- package/esm/src/api/subscription/_methods/twapStates.js +6 -1
- package/esm/src/api/subscription/_methods/twapStates.js.map +1 -1
- package/esm/src/api/subscription/_methods/userEvents.d.ts +17 -17
- package/esm/src/api/subscription/_methods/userFills.d.ts +5 -5
- package/esm/src/api/subscription/_methods/userHistoricalOrders.d.ts +6 -6
- package/esm/src/api/subscription/_methods/userTwapHistory.d.ts +6 -6
- package/esm/src/api/subscription/_methods/userTwapSliceFills.d.ts +6 -6
- package/esm/src/api/subscription/_methods/webData2.d.ts +11 -11
- package/esm/src/signing/_privateKeySigner.js +1 -1
- package/esm/src/signing/_privateKeySigner.js.map +1 -1
- package/esm/src/signing/mod.js +1 -1
- package/esm/src/signing/mod.js.map +1 -1
- package/package.json +2 -3
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +61 -0
- package/script/_dnt.shims.js.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts +195 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js +468 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.js.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts +90 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js +215 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.js.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts +159 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js +578 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.js.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts +325 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js +1232 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.js.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts +76 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js +286 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.js.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts +103 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.js +273 -0
- package/script/deps/jsr.io/@noble/curves/2.0.1/src/utils.js.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts +49 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js +153 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_md.js.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts +55 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js +90 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.js.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts +36 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js +95 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.js.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts +199 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js +439 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.js.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts +58 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js +259 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.js.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts +124 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.d.ts.map +1 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js +304 -0
- package/script/deps/jsr.io/@noble/hashes/2.0.1/src/utils.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts +44 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js +182 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts +38 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js +99 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts +23 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js +134 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts +300 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js +576 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts +98 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js +211 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts +78 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js +308 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts +6 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js +21 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts +66 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js +195 -0
- package/script/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.js.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts +877 -0
- package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js +2032 -0
- package/script/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.js.map +1 -0
- package/script/deps/jsr.io/@scure/base/2.0.0/index.d.ts +294 -0
- package/script/deps/jsr.io/@scure/base/2.0.0/index.d.ts.map +1 -0
- package/script/deps/jsr.io/@scure/base/2.0.0/index.js +710 -0
- package/script/deps/jsr.io/@scure/base/2.0.0/index.js.map +1 -0
- package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts +93 -0
- package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.d.ts.map +1 -0
- package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js +141 -0
- package/script/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.js.map +1 -0
- package/script/src/api/exchange/_methods/_base/_nonce.d.ts +3 -2
- package/script/src/api/exchange/_methods/_base/_nonce.d.ts.map +1 -1
- package/script/src/api/exchange/_methods/_base/_nonce.js +4 -3
- package/script/src/api/exchange/_methods/_base/_nonce.js.map +1 -1
- package/script/src/api/exchange/_methods/_base/_semaphore.d.ts +7 -6
- package/script/src/api/exchange/_methods/_base/_semaphore.d.ts.map +1 -1
- package/script/src/api/exchange/_methods/_base/_semaphore.js +35 -50
- package/script/src/api/exchange/_methods/_base/_semaphore.js.map +1 -1
- package/script/src/api/exchange/_methods/_base/execute.d.ts +14 -3
- package/script/src/api/exchange/_methods/_base/execute.d.ts.map +1 -1
- package/script/src/api/exchange/_methods/_base/execute.js +43 -9
- package/script/src/api/exchange/_methods/_base/execute.js.map +1 -1
- package/script/src/api/exchange/_methods/batchModify.d.ts +6 -6
- package/script/src/api/exchange/_methods/createVault.d.ts +5 -5
- package/script/src/api/exchange/_methods/modify.d.ts +5 -5
- package/script/src/api/exchange/_methods/order.d.ts +13 -13
- package/script/src/api/exchange/_methods/order.d.ts.map +1 -1
- package/script/src/api/exchange/_methods/order.js +4 -2
- package/script/src/api/exchange/_methods/order.js.map +1 -1
- package/script/src/api/exchange/client.d.ts +1 -1
- package/script/src/api/exchange/client.d.ts.map +1 -1
- package/script/src/api/exchange/client.js.map +1 -1
- package/script/src/api/exchange/mod.d.ts +1 -1
- package/script/src/api/exchange/mod.d.ts.map +1 -1
- package/script/src/api/exchange/mod.js.map +1 -1
- package/script/src/api/info/_methods/_base/commonSchemas.d.ts +8 -8
- package/script/src/api/info/_methods/frontendOpenOrders.d.ts +3 -3
- package/script/src/api/info/_methods/historicalOrders.d.ts +4 -4
- package/script/src/api/info/_methods/l3Orders.d.ts +11 -11
- package/script/src/api/info/_methods/l4Orders.d.ts +6 -6
- package/script/src/api/info/_methods/openOrders.d.ts +3 -3
- package/script/src/api/info/_methods/orderStatus.d.ts +5 -5
- package/script/src/api/info/_methods/recentTrades.d.ts +2 -2
- package/script/src/api/info/_methods/twapHistory.d.ts +4 -4
- package/script/src/api/info/_methods/userFills.d.ts +3 -3
- package/script/src/api/info/_methods/userFillsByTime.d.ts +4 -4
- package/script/src/api/info/_methods/userFunding.d.ts +3 -3
- package/script/src/api/info/_methods/userFunding.js +2 -2
- package/script/src/api/info/_methods/userFunding.js.map +1 -1
- package/script/src/api/info/_methods/userTwapSliceFills.d.ts +4 -4
- package/script/src/api/info/_methods/userTwapSliceFillsByTime.d.ts +5 -5
- package/script/src/api/info/_methods/webData2.d.ts +9 -9
- package/script/src/api/subscription/_methods/assetCtxs.d.ts +2 -0
- package/script/src/api/subscription/_methods/assetCtxs.d.ts.map +1 -1
- package/script/src/api/subscription/_methods/assetCtxs.js.map +1 -1
- package/script/src/api/subscription/_methods/clearinghouseState.d.ts +2 -0
- package/script/src/api/subscription/_methods/clearinghouseState.d.ts.map +1 -1
- package/script/src/api/subscription/_methods/clearinghouseState.js +2 -0
- package/script/src/api/subscription/_methods/clearinghouseState.js.map +1 -1
- package/script/src/api/subscription/_methods/explorerBlock.d.ts +2 -0
- package/script/src/api/subscription/_methods/explorerBlock.d.ts.map +1 -1
- package/script/src/api/subscription/_methods/explorerBlock.js +2 -0
- package/script/src/api/subscription/_methods/explorerBlock.js.map +1 -1
- package/script/src/api/subscription/_methods/explorerTxs.d.ts +2 -0
- package/script/src/api/subscription/_methods/explorerTxs.d.ts.map +1 -1
- package/script/src/api/subscription/_methods/explorerTxs.js +2 -0
- package/script/src/api/subscription/_methods/explorerTxs.js.map +1 -1
- package/script/src/api/subscription/_methods/openOrders.d.ts +5 -5
- package/script/src/api/subscription/_methods/orderUpdates.d.ts +4 -4
- package/script/src/api/subscription/_methods/trades.d.ts +3 -3
- package/script/src/api/subscription/_methods/twapStates.d.ts +9 -4
- package/script/src/api/subscription/_methods/twapStates.d.ts.map +1 -1
- package/script/src/api/subscription/_methods/twapStates.js +6 -1
- package/script/src/api/subscription/_methods/twapStates.js.map +1 -1
- package/script/src/api/subscription/_methods/userEvents.d.ts +17 -17
- package/script/src/api/subscription/_methods/userFills.d.ts +5 -5
- package/script/src/api/subscription/_methods/userHistoricalOrders.d.ts +6 -6
- package/script/src/api/subscription/_methods/userTwapHistory.d.ts +6 -6
- package/script/src/api/subscription/_methods/userTwapSliceFills.d.ts +6 -6
- package/script/src/api/subscription/_methods/webData2.d.ts +11 -11
- package/script/src/signing/_privateKeySigner.js +3 -3
- package/script/src/signing/_privateKeySigner.js.map +1 -1
- package/script/src/signing/mod.js +2 -2
- package/script/src/signing/mod.js.map +1 -1
- package/src/_dnt.shims.ts +60 -0
- package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/curve.ts +633 -0
- package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/hash-to-curve.ts +292 -0
- package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/modular.ts +621 -0
- package/src/deps/jsr.io/@noble/curves/2.0.1/src/abstract/weierstrass.ts +1562 -0
- package/src/deps/jsr.io/@noble/curves/2.0.1/src/secp256k1.ts +327 -0
- package/src/deps/jsr.io/@noble/curves/2.0.1/src/utils.ts +306 -0
- package/src/deps/jsr.io/@noble/hashes/2.0.1/src/_md.ts +156 -0
- package/src/deps/jsr.io/@noble/hashes/2.0.1/src/_u64.ts +91 -0
- package/src/deps/jsr.io/@noble/hashes/2.0.1/src/hmac.ts +94 -0
- package/src/deps/jsr.io/@noble/hashes/2.0.1/src/sha2.ts +469 -0
- package/src/deps/jsr.io/@noble/hashes/2.0.1/src/sha3.ts +295 -0
- package/src/deps/jsr.io/@noble/hashes/2.0.1/src/utils.ts +340 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/advanced/abi-mapper.ts +212 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/address.ts +100 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/rlp.ts +104 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx-internal.ts +626 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/tx.ts +274 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/core/typed-data.ts +391 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/index.ts +12 -0
- package/src/deps/jsr.io/@paulmillr/micro-eth-signer/0.18.1/src/utils.ts +233 -0
- package/src/deps/jsr.io/@paulmillr/micro-packed/0.8.0/src/index.ts +2196 -0
- package/src/deps/jsr.io/@scure/base/2.0.0/index.ts +857 -0
- package/src/deps/jsr.io/@std/async/1.0.16/unstable_semaphore.ts +146 -0
- package/src/src/api/exchange/_methods/_base/_nonce.ts +3 -2
- package/src/src/api/exchange/_methods/_base/_semaphore.ts +34 -59
- package/src/src/api/exchange/_methods/_base/execute.ts +60 -12
- package/src/src/api/exchange/_methods/order.ts +5 -3
- package/src/src/api/exchange/client.ts +5 -1
- package/src/src/api/exchange/mod.ts +5 -1
- package/src/src/api/info/_methods/userFunding.ts +2 -2
- package/src/src/api/subscription/_methods/assetCtxs.ts +2 -0
- package/src/src/api/subscription/_methods/clearinghouseState.ts +2 -0
- package/src/src/api/subscription/_methods/explorerBlock.ts +2 -0
- package/src/src/api/subscription/_methods/explorerTxs.ts +2 -0
- package/src/src/api/subscription/_methods/twapStates.ts +9 -1
- package/src/src/signing/_privateKeySigner.ts +1 -1
- package/src/src/signing/mod.ts +1 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts +0 -21
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.js +0 -292
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/decode.js.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts +0 -44
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.js +0 -46
- package/esm/deps/jsr.io/@std/msgpack/1.0.3/mod.js.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts +0 -21
- package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.js +0 -295
- package/script/deps/jsr.io/@std/msgpack/1.0.3/decode.js.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts +0 -44
- package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.d.ts.map +0 -1
- package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.js +0 -62
- package/script/deps/jsr.io/@std/msgpack/1.0.3/mod.js.map +0 -1
- package/src/deps/jsr.io/@std/msgpack/1.0.3/decode.ts +0 -391
- package/src/deps/jsr.io/@std/msgpack/1.0.3/mod.ts +0 -47
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import { secp256k1 } from '../../../../../@noble/curves/2.0.1/src/secp256k1.js';
|
|
2
|
+
import { keccak_256 } from '../../../../../@noble/hashes/2.0.1/src/sha3.js';
|
|
3
|
+
import { concatBytes } from '../../../../../@noble/hashes/2.0.1/src/utils.js';
|
|
4
|
+
import * as P from '../../../../micro-packed/0.8.0/src/index.js';
|
|
5
|
+
import { amounts, astr, ethHex, initSig, isBytes, isObject, sign, type Bytes } from '../utils.js';
|
|
6
|
+
import { addr } from './address.js';
|
|
7
|
+
import { RLP } from './rlp.js';
|
|
8
|
+
|
|
9
|
+
// Transaction parsers
|
|
10
|
+
|
|
11
|
+
const _0n = BigInt(0);
|
|
12
|
+
|
|
13
|
+
export type AnyCoder = Record<string, P.Coder<any, any>>;
|
|
14
|
+
export type AnyCoderStream = Record<string, P.CoderType<any>>;
|
|
15
|
+
|
|
16
|
+
// EIP-2718 (very ambigious)
|
|
17
|
+
// new tx: [0, 0x7f]
|
|
18
|
+
// legacy: [0xc0, 0xfe]
|
|
19
|
+
// reserved: 0xff
|
|
20
|
+
type VersionType<V extends AnyCoderStream> = {
|
|
21
|
+
[K in keyof V]: { type: K; data: P.UnwrapCoder<V[K]> };
|
|
22
|
+
}[keyof V];
|
|
23
|
+
|
|
24
|
+
export type TxCoder<T extends TxType> = P.UnwrapCoder<(typeof TxVersions)[T]>;
|
|
25
|
+
|
|
26
|
+
const createTxMap = <T extends AnyCoderStream>(versions: T): P.CoderType<VersionType<T>> => {
|
|
27
|
+
const ent = Object.entries(versions);
|
|
28
|
+
// 'legacy' => {type, ver, coder}
|
|
29
|
+
const typeMap = Object.fromEntries(ent.map(([type, coder], ver) => [type, { type, ver, coder }]));
|
|
30
|
+
// '0' => {type, ver, coder}
|
|
31
|
+
const verMap = Object.fromEntries(ent.map(([type, coder], ver) => [ver, { type, ver, coder }]));
|
|
32
|
+
return P.wrap({
|
|
33
|
+
encodeStream(w: P.Writer, value: VersionType<T>) {
|
|
34
|
+
const t = value.type as string;
|
|
35
|
+
if (!typeMap.hasOwnProperty(t)) throw new Error(`txVersion: wrong type=${t}`);
|
|
36
|
+
const curr = typeMap[t];
|
|
37
|
+
if (t !== 'legacy') w.byte(curr.ver);
|
|
38
|
+
curr.coder.encodeStream(w, value.data);
|
|
39
|
+
},
|
|
40
|
+
decodeStream(r: P.Reader) {
|
|
41
|
+
const v = r.byte(true);
|
|
42
|
+
if (v === 0xff) throw new Error('reserved version 0xff');
|
|
43
|
+
// TODO: version=0 is legacy, but it is never wrapped in test vectors
|
|
44
|
+
if (v === 0x00) throw new Error('version=0 unsupported');
|
|
45
|
+
if (0 <= v && v <= 0x7f) {
|
|
46
|
+
if (!verMap.hasOwnProperty(v.toString())) throw new Error(`wrong version=${v}`);
|
|
47
|
+
const curr = verMap[v];
|
|
48
|
+
r.byte(false); // skip first byte
|
|
49
|
+
const d = curr.coder.decodeStream(r);
|
|
50
|
+
return { type: curr.type, data: d };
|
|
51
|
+
}
|
|
52
|
+
return { type: 'legacy', data: typeMap.legacy.coder.decodeStream(r) };
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Static struct could have been extracted into micro-packed, but we need a specific behavior:
|
|
59
|
+
* - optional fields maybe either all present or all absent, enforced by type
|
|
60
|
+
* - optional fields change the length of underlying array
|
|
61
|
+
*/
|
|
62
|
+
const isOptBig = (a: unknown) => a === undefined || typeof a === 'bigint';
|
|
63
|
+
const isNullOr0 = (a: unknown) => a === undefined || a === BigInt(0);
|
|
64
|
+
|
|
65
|
+
function assertYParityValid(elm: number) {
|
|
66
|
+
// TODO: is this correct? elm = 0 default?
|
|
67
|
+
if (elm === undefined) elm = 0;
|
|
68
|
+
if (elm !== 0 && elm !== 1) throw new Error(`yParity wrong value=${elm} (${typeof elm})`);
|
|
69
|
+
}
|
|
70
|
+
// We don't know chainId when specific field coded yet.
|
|
71
|
+
const addrCoder = ethHex;
|
|
72
|
+
// Bytes32: VersionedHash, AccessListKey
|
|
73
|
+
function ensure32(b: Uint8Array): Uint8Array {
|
|
74
|
+
if (!isBytes(b) || b.length !== 32) throw new Error('expected 32 bytes');
|
|
75
|
+
return b;
|
|
76
|
+
}
|
|
77
|
+
const Bytes32: P.Coder<Bytes, string> = {
|
|
78
|
+
encode: (from) => ethHex.encode(ensure32(from)),
|
|
79
|
+
decode: (to) => ensure32(ethHex.decode(to)),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type VRS = Partial<{ v: bigint; r: bigint; s: bigint }>;
|
|
83
|
+
type YRS = Partial<{ chainId: bigint; yParity: number; r: bigint; s: bigint }>;
|
|
84
|
+
|
|
85
|
+
// Process v as (chainId, yParity) pair. Ethers.js-inspired logic:
|
|
86
|
+
// - v=27/28 -> no chainId (pre eip155)
|
|
87
|
+
// - r & s == 0 -> v = chainId
|
|
88
|
+
// Non-standard, but there is no other way to save chainId for unsignedTx.
|
|
89
|
+
// Case: unsigned tx for cold wallet for different chains, like mainnet & testnet.
|
|
90
|
+
// - otherwise v = yParity + 2*chainId + 35
|
|
91
|
+
// - allows to keep legacy logic here, instead of copying to Transaction
|
|
92
|
+
export const legacySig = {
|
|
93
|
+
encode: (data: VRS) => {
|
|
94
|
+
const { v, r, s } = data;
|
|
95
|
+
if (v === undefined) return { chainId: undefined };
|
|
96
|
+
// TODO: handle (invalid?) negative v
|
|
97
|
+
if (typeof v !== 'bigint') throw new Error(`invalid v type=${typeof v}`);
|
|
98
|
+
if ((r === undefined && s === undefined) || (r === _0n && s === _0n)) return { chainId: v };
|
|
99
|
+
if (v === BigInt(27)) return { yParity: 0, chainId: undefined, r, s };
|
|
100
|
+
if (v === BigInt(28)) return { yParity: 1, chainId: undefined, r, s };
|
|
101
|
+
if (v < BigInt(35)) throw new Error(`wrong v=${v}`);
|
|
102
|
+
const v2 = v - BigInt(35);
|
|
103
|
+
return { chainId: v2 >> BigInt(1), yParity: Number(v2 & BigInt(1)), r, s };
|
|
104
|
+
},
|
|
105
|
+
decode: (data: YRS) => {
|
|
106
|
+
aobj(data);
|
|
107
|
+
const { chainId, yParity, r, s } = data;
|
|
108
|
+
if (!isOptBig(chainId)) throw new Error(`wrong chainId type=${typeof chainId}`);
|
|
109
|
+
if (!isOptBig(r)) throw new Error(`wrong r type=${typeof r}`);
|
|
110
|
+
if (!isOptBig(s)) throw new Error(`wrong s type=${typeof s}`);
|
|
111
|
+
if (yParity !== undefined && typeof yParity !== 'number')
|
|
112
|
+
throw new Error(`wrong yParity type=${typeof chainId}`);
|
|
113
|
+
if (yParity === undefined) {
|
|
114
|
+
if (chainId !== undefined) {
|
|
115
|
+
if ((r !== undefined && r !== _0n) || (s !== undefined && s !== _0n))
|
|
116
|
+
throw new Error(`wrong unsigned legacy r=${r} s=${s}`);
|
|
117
|
+
return { v: chainId, r: _0n, s: _0n };
|
|
118
|
+
}
|
|
119
|
+
// no parity, chainId, but r, s exists
|
|
120
|
+
if ((r !== undefined && r !== _0n) || (s !== undefined && s !== _0n))
|
|
121
|
+
throw new Error(`wrong unsigned legacy r=${r} s=${s}`);
|
|
122
|
+
return {};
|
|
123
|
+
}
|
|
124
|
+
// parity exists, which means r & s should exist too!
|
|
125
|
+
if (isNullOr0(r) || isNullOr0(s)) throw new Error(`wrong unsigned legacy r=${r} s=${s}`);
|
|
126
|
+
assertYParityValid(yParity);
|
|
127
|
+
const v =
|
|
128
|
+
chainId !== undefined
|
|
129
|
+
? BigInt(yParity) + (chainId * BigInt(2) + BigInt(35))
|
|
130
|
+
: BigInt(yParity) + BigInt(27);
|
|
131
|
+
return { v, r, s };
|
|
132
|
+
},
|
|
133
|
+
} as P.Coder<VRS, YRS>;
|
|
134
|
+
|
|
135
|
+
const U64BE = P.coders.reverse(P.bigint(8, false, false, false));
|
|
136
|
+
const U256BE = P.coders.reverse(P.bigint(32, false, false, false));
|
|
137
|
+
|
|
138
|
+
// Small coder utils
|
|
139
|
+
// TODO: seems generic enought for packed? or RLP (seems useful for structured encoding/decoding of RLP stuff)
|
|
140
|
+
// Basic array coder
|
|
141
|
+
const array = <F, T>(coder: P.Coder<F, T>): P.Coder<F[], T[]> => ({
|
|
142
|
+
encode(from: F[]) {
|
|
143
|
+
if (!Array.isArray(from)) throw new Error('expected array');
|
|
144
|
+
return from.map((i) => coder.encode(i));
|
|
145
|
+
},
|
|
146
|
+
decode(to: T[]) {
|
|
147
|
+
if (!Array.isArray(to)) throw new Error('expected array');
|
|
148
|
+
return to.map((i) => coder.decode(i));
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
// tuple -> struct
|
|
152
|
+
const struct = <
|
|
153
|
+
Fields extends Record<string, P.Coder<any, any>>,
|
|
154
|
+
FromTuple extends {
|
|
155
|
+
[K in keyof Fields]: Fields[K] extends P.Coder<infer F, any> ? F : never;
|
|
156
|
+
}[keyof Fields][],
|
|
157
|
+
ToObject extends { [K in keyof Fields]: Fields[K] extends P.Coder<any, infer T> ? T : never },
|
|
158
|
+
>(
|
|
159
|
+
fields: Fields
|
|
160
|
+
): P.Coder<FromTuple, ToObject> => ({
|
|
161
|
+
encode(from: FromTuple) {
|
|
162
|
+
if (!Array.isArray(from)) throw new Error('expected array');
|
|
163
|
+
const fNames = Object.keys(fields);
|
|
164
|
+
if (from.length !== fNames.length) throw new Error('wrong array length');
|
|
165
|
+
return Object.fromEntries(fNames.map((f, i) => [f, fields[f].encode(from[i])])) as ToObject;
|
|
166
|
+
},
|
|
167
|
+
decode(to: ToObject): FromTuple {
|
|
168
|
+
const fNames = Object.keys(fields);
|
|
169
|
+
if (!isObject(to)) throw new Error('wrong struct object');
|
|
170
|
+
return fNames.map((i) => fields[i].decode(to[i])) as FromTuple;
|
|
171
|
+
},
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
// U256BE in geth. But it is either 0 or 1. TODO: is this good enough?
|
|
175
|
+
const yParityCoder = P.coders.reverse(
|
|
176
|
+
P.validate(P.int(1, false, false, false), (elm) => {
|
|
177
|
+
assertYParityValid(elm);
|
|
178
|
+
return elm;
|
|
179
|
+
})
|
|
180
|
+
);
|
|
181
|
+
type CoderOutput<F> = F extends P.Coder<any, infer T> ? T : never;
|
|
182
|
+
|
|
183
|
+
const accessListItem: P.Coder<
|
|
184
|
+
(Bytes | Bytes[])[],
|
|
185
|
+
{
|
|
186
|
+
address: string;
|
|
187
|
+
storageKeys: string[];
|
|
188
|
+
}
|
|
189
|
+
> = struct({ address: addrCoder, storageKeys: array(Bytes32) });
|
|
190
|
+
export type AccessList = CoderOutput<typeof accessListItem>[];
|
|
191
|
+
|
|
192
|
+
export const authorizationRequest: P.Coder<
|
|
193
|
+
Bytes[],
|
|
194
|
+
{
|
|
195
|
+
chainId: bigint;
|
|
196
|
+
address: string;
|
|
197
|
+
nonce: bigint;
|
|
198
|
+
}
|
|
199
|
+
> = struct({
|
|
200
|
+
chainId: U256BE,
|
|
201
|
+
address: addrCoder,
|
|
202
|
+
nonce: U64BE,
|
|
203
|
+
});
|
|
204
|
+
// [chain_id, address, nonce, y_parity, r, s]
|
|
205
|
+
const authorizationItem: P.Coder<
|
|
206
|
+
Bytes[],
|
|
207
|
+
{
|
|
208
|
+
chainId: bigint;
|
|
209
|
+
address: string;
|
|
210
|
+
nonce: bigint;
|
|
211
|
+
yParity: number;
|
|
212
|
+
r: bigint;
|
|
213
|
+
s: bigint;
|
|
214
|
+
}
|
|
215
|
+
> = struct({
|
|
216
|
+
chainId: U256BE,
|
|
217
|
+
address: addrCoder,
|
|
218
|
+
nonce: U64BE,
|
|
219
|
+
yParity: yParityCoder,
|
|
220
|
+
r: U256BE,
|
|
221
|
+
s: U256BE,
|
|
222
|
+
});
|
|
223
|
+
export type AuthorizationItem = CoderOutput<typeof authorizationItem>;
|
|
224
|
+
export type AuthorizationRequest = CoderOutput<typeof authorizationRequest>;
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Field types, matching geth. Either u64 or u256.
|
|
228
|
+
*/
|
|
229
|
+
const coders = {
|
|
230
|
+
chainId: U256BE, // Can fit into u64 (curr max is 0x57a238f93bf), but geth uses bigint
|
|
231
|
+
nonce: U64BE,
|
|
232
|
+
gasPrice: U256BE,
|
|
233
|
+
maxPriorityFeePerGas: U256BE,
|
|
234
|
+
maxFeePerGas: U256BE,
|
|
235
|
+
gasLimit: U64BE,
|
|
236
|
+
to: addrCoder,
|
|
237
|
+
value: U256BE, // "Decimal" coder can be used, but it's harder to work with
|
|
238
|
+
data: ethHex,
|
|
239
|
+
accessList: array(accessListItem),
|
|
240
|
+
maxFeePerBlobGas: U256BE,
|
|
241
|
+
blobVersionedHashes: array(Bytes32),
|
|
242
|
+
yParity: yParityCoder,
|
|
243
|
+
v: U256BE,
|
|
244
|
+
r: U256BE,
|
|
245
|
+
s: U256BE,
|
|
246
|
+
authorizationList: array(authorizationItem),
|
|
247
|
+
};
|
|
248
|
+
type Coders = typeof coders;
|
|
249
|
+
type CoderName = keyof Coders;
|
|
250
|
+
const signatureFields = new Set(['v', 'yParity', 'r', 's'] as const);
|
|
251
|
+
|
|
252
|
+
type FieldType<T> = T extends P.Coder<any, infer U> ? U : T;
|
|
253
|
+
// Could be 'T | (T & O)', to make sure all partial fields either present or absent together
|
|
254
|
+
// But it would make accesing them impossible, because of typescript stuff:
|
|
255
|
+
type OptFields<T, O> = T & Partial<O>;
|
|
256
|
+
type FieldCoder<C> = P.CoderType<C> & {
|
|
257
|
+
fields: CoderName[];
|
|
258
|
+
optionalFields: CoderName[];
|
|
259
|
+
setOfAllFields: Set<CoderName | 'type'>;
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Mutates raw. Make sure to copy it in advance
|
|
263
|
+
export function removeSig(raw: TxCoder<any>): TxCoder<any> {
|
|
264
|
+
signatureFields.forEach((k) => {
|
|
265
|
+
delete raw[k];
|
|
266
|
+
});
|
|
267
|
+
return raw;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Defines RLP transaction with fields taken from `coders`.
|
|
272
|
+
* @example
|
|
273
|
+
* const tx = txStruct(['nonce', 'gasPrice', 'value'] as const, ['v', 'r', 's'] as const)
|
|
274
|
+
* tx.nonce.decode(...);
|
|
275
|
+
*/
|
|
276
|
+
const txStruct = <T extends readonly CoderName[], ST extends readonly CoderName[]>(
|
|
277
|
+
reqf: T,
|
|
278
|
+
optf: ST
|
|
279
|
+
): FieldCoder<
|
|
280
|
+
OptFields<{ [K in T[number]]: FieldType<Coders[K]> }, { [K in ST[number]]: FieldType<Coders[K]> }>
|
|
281
|
+
> => {
|
|
282
|
+
const allFields = reqf.concat(optf);
|
|
283
|
+
// Check that all fields have known coders
|
|
284
|
+
allFields.forEach((f) => {
|
|
285
|
+
if (!coders.hasOwnProperty(f)) throw new Error(`coder for field ${f} is not defined`);
|
|
286
|
+
});
|
|
287
|
+
const reqS = struct(Object.fromEntries(reqf.map((i) => [i, coders[i]])));
|
|
288
|
+
const allS = struct(Object.fromEntries(allFields.map((i) => [i, coders[i]])));
|
|
289
|
+
// e.g. eip1559 txs have valid lengths of 9 or 12 (unsigned / signed)
|
|
290
|
+
const reql = reqf.length;
|
|
291
|
+
const optl = reql + optf.length;
|
|
292
|
+
const optFieldAt = (i: number) => reql + i;
|
|
293
|
+
const isEmpty = (item: any & { length: number }) => item.length === 0;
|
|
294
|
+
// TX is a bunch of fields in specific order. Field like nonce must always be at the same index.
|
|
295
|
+
// We walk through all indexes in proper order.
|
|
296
|
+
const fcoder: any = P.wrap({
|
|
297
|
+
encodeStream(w, raw: Record<string, any>) {
|
|
298
|
+
// If at least one optional key is present, we add whole optional block
|
|
299
|
+
const hasOptional = optf.some((f) => raw.hasOwnProperty(f));
|
|
300
|
+
const sCoder = hasOptional ? allS : reqS;
|
|
301
|
+
RLP.encodeStream(w, sCoder.decode(raw));
|
|
302
|
+
},
|
|
303
|
+
decodeStream(r): Record<string, any> {
|
|
304
|
+
const decoded = RLP.decodeStream(r);
|
|
305
|
+
if (!Array.isArray(decoded)) throw new Error('txStruct: expected array from inner coder');
|
|
306
|
+
const length = decoded.length;
|
|
307
|
+
if (length !== reql && length !== optl)
|
|
308
|
+
throw new Error(`txStruct: wrong inner length=${length}`);
|
|
309
|
+
const sCoder = length === optl ? allS : reqS;
|
|
310
|
+
if (length === optl && optf.every((_, i) => isEmpty(decoded[optFieldAt(i)])))
|
|
311
|
+
throw new Error('all optional fields empty');
|
|
312
|
+
// @ts-ignore TODO: fix type (there can be null in RLP)
|
|
313
|
+
return sCoder.encode(decoded);
|
|
314
|
+
},
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
fcoder.fields = reqf;
|
|
318
|
+
fcoder.optionalFields = optf;
|
|
319
|
+
fcoder.setOfAllFields = new Set(allFields.concat(['type'] as any));
|
|
320
|
+
return fcoder;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// prettier-ignore
|
|
324
|
+
const legacyInternal: FieldCoder<OptFields<{
|
|
325
|
+
nonce: bigint;
|
|
326
|
+
gasPrice: bigint;
|
|
327
|
+
gasLimit: bigint;
|
|
328
|
+
to: string;
|
|
329
|
+
value: bigint;
|
|
330
|
+
data: string;
|
|
331
|
+
}, {
|
|
332
|
+
r: bigint;
|
|
333
|
+
s: bigint;
|
|
334
|
+
v: bigint;
|
|
335
|
+
}>> = txStruct([
|
|
336
|
+
'nonce', 'gasPrice', 'gasLimit', 'to', 'value', 'data'] as const,
|
|
337
|
+
['v', 'r', 's'] as const);
|
|
338
|
+
|
|
339
|
+
type LegacyInternal = P.UnwrapCoder<typeof legacyInternal>;
|
|
340
|
+
type Legacy = Omit<LegacyInternal, 'v'> & { chainId?: bigint; yParity?: number };
|
|
341
|
+
|
|
342
|
+
const legacy = (() => {
|
|
343
|
+
const res = P.apply(legacyInternal, {
|
|
344
|
+
decode: (data: Legacy) => Object.assign({}, data, legacySig.decode(data)),
|
|
345
|
+
encode: (data: LegacyInternal) => {
|
|
346
|
+
const res = Object.assign({}, data);
|
|
347
|
+
(res as any).chainId = undefined;
|
|
348
|
+
if (data.v) {
|
|
349
|
+
const newV = legacySig.encode(data);
|
|
350
|
+
removeSig(res);
|
|
351
|
+
Object.assign(res, newV);
|
|
352
|
+
}
|
|
353
|
+
return res as Legacy;
|
|
354
|
+
},
|
|
355
|
+
}) as FieldCoder<Legacy>;
|
|
356
|
+
res.fields = legacyInternal.fields.concat(['chainId'] as const);
|
|
357
|
+
// v, r, s -> yParity, r, s
|
|
358
|
+
// TODO: what about chainId?
|
|
359
|
+
res.optionalFields = ['yParity', 'r', 's'];
|
|
360
|
+
res.setOfAllFields = new Set(res.fields.concat(res.optionalFields, ['type'] as any));
|
|
361
|
+
return res;
|
|
362
|
+
})();
|
|
363
|
+
|
|
364
|
+
// prettier-ignore
|
|
365
|
+
const eip2930 = txStruct([
|
|
366
|
+
'chainId', 'nonce', 'gasPrice', 'gasLimit', 'to', 'value', 'data', 'accessList'] as const,
|
|
367
|
+
['yParity', 'r', 's'] as const);
|
|
368
|
+
|
|
369
|
+
// prettier-ignore
|
|
370
|
+
const eip1559 = txStruct([
|
|
371
|
+
'chainId', 'nonce', 'maxPriorityFeePerGas', 'maxFeePerGas', 'gasLimit', 'to', 'value', 'data', 'accessList'] as const,
|
|
372
|
+
['yParity', 'r', 's'] as const);
|
|
373
|
+
// prettier-ignore
|
|
374
|
+
const eip4844 = txStruct([
|
|
375
|
+
'chainId', 'nonce', 'maxPriorityFeePerGas', 'maxFeePerGas', 'gasLimit', 'to', 'value', 'data', 'accessList',
|
|
376
|
+
'maxFeePerBlobGas', 'blobVersionedHashes'] as const,
|
|
377
|
+
['yParity', 'r', 's'] as const);
|
|
378
|
+
// prettier-ignore
|
|
379
|
+
const eip7702 = txStruct([
|
|
380
|
+
'chainId', 'nonce', 'maxPriorityFeePerGas', 'maxFeePerGas', 'gasLimit', 'to', 'value', 'data', 'accessList',
|
|
381
|
+
'authorizationList'] as const,
|
|
382
|
+
['yParity', 'r', 's'] as const);
|
|
383
|
+
|
|
384
|
+
export const TxVersions = {
|
|
385
|
+
legacy, // 0x00 (kinda)
|
|
386
|
+
eip2930, // 0x01
|
|
387
|
+
eip1559, // 0x02
|
|
388
|
+
eip4844, // 0x03
|
|
389
|
+
eip7702, // 0x04
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export const RawTx = P.apply(createTxMap(TxVersions), {
|
|
393
|
+
// NOTE: we apply checksum to addresses here, since chainId is not available inside coders
|
|
394
|
+
// By construction 'to' field is decoded before anything about chainId is known
|
|
395
|
+
encode: (data) => {
|
|
396
|
+
data.data.to = addr.addChecksum(data.data.to, true);
|
|
397
|
+
if (data.type !== 'legacy' && data.data.accessList) {
|
|
398
|
+
for (const item of data.data.accessList) {
|
|
399
|
+
item.address = addr.addChecksum(item.address);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
if (data.type === 'eip7702' && data.data.authorizationList) {
|
|
403
|
+
for (const item of data.data.authorizationList) {
|
|
404
|
+
item.address = addr.addChecksum(item.address);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
return data;
|
|
408
|
+
},
|
|
409
|
+
// Nothing to check here, is validated in validator
|
|
410
|
+
decode: (data) => data,
|
|
411
|
+
});
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* Unchecked TX for debugging. Returns raw Uint8Array-s.
|
|
415
|
+
* Handles versions - plain RLP will crash on it.
|
|
416
|
+
*/
|
|
417
|
+
export const RlpTx: P.CoderType<{
|
|
418
|
+
type: string;
|
|
419
|
+
data: import('./rlp.js').RLPInput;
|
|
420
|
+
}> = createTxMap(Object.fromEntries(Object.keys(TxVersions).map((k) => [k, RLP])));
|
|
421
|
+
|
|
422
|
+
// Field-related utils
|
|
423
|
+
export type TxType = keyof typeof TxVersions;
|
|
424
|
+
|
|
425
|
+
// prettier-ignore
|
|
426
|
+
// Basically all numbers. Can be useful if we decide to do converter from hex here
|
|
427
|
+
// const knownFieldsNoLeading0 = [
|
|
428
|
+
// 'nonce', 'maxPriorityFeePerGas', 'maxFeePerGas', 'gasLimit', 'value', 'yParity', 'r', 's'
|
|
429
|
+
// ] as const;
|
|
430
|
+
|
|
431
|
+
function abig(val: bigint) {
|
|
432
|
+
if (typeof val !== 'bigint') throw new Error('value must be bigint');
|
|
433
|
+
}
|
|
434
|
+
function aobj(val: Record<string, any>) {
|
|
435
|
+
if (typeof val !== 'object' || val == null) throw new Error('object expected');
|
|
436
|
+
}
|
|
437
|
+
function minmax(val: bigint, min: bigint, max: bigint, err?: string): void;
|
|
438
|
+
function minmax(val: number, min: number, max: number, err?: string): void;
|
|
439
|
+
function minmax(
|
|
440
|
+
val: number | bigint,
|
|
441
|
+
min: number | bigint,
|
|
442
|
+
max: number | bigint,
|
|
443
|
+
err?: string
|
|
444
|
+
): void {
|
|
445
|
+
if (!err) err = `>= ${min} and <= ${max}`;
|
|
446
|
+
if (Number.isNaN(val) || val < min || val > max) throw new Error(`must be ${err}, not ${val}`);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// strict=true validates if human-entered value in UI is "sort of" valid
|
|
450
|
+
// for some new TX. For example, it's unlikely that the nonce would be 14 million.
|
|
451
|
+
// strict=false validates if machine-entered value, or something historical is valid.
|
|
452
|
+
|
|
453
|
+
type ValidationOpts = { strict: boolean; type: TxType; data: Record<string, any> };
|
|
454
|
+
// NOTE: non-strict validators can be removed (RawTx will handle that), but errors will be less user-friendly.
|
|
455
|
+
// On other hand, we twice per sig because tx is immutable
|
|
456
|
+
// data passed for composite checks (gasLimit * maxFeePerGas overflow and stuff) [not implemented yet]
|
|
457
|
+
const validators: Record<string, (num: any, { strict, type, data }: ValidationOpts) => void> = {
|
|
458
|
+
nonce(num: bigint, { strict }: ValidationOpts) {
|
|
459
|
+
abig(num);
|
|
460
|
+
if (strict) minmax(num, _0n, amounts.maxNonce);
|
|
461
|
+
else minmax(BigInt(num), _0n, BigInt(Number.MAX_SAFE_INTEGER)); // amounts.maxUint64
|
|
462
|
+
},
|
|
463
|
+
maxFeePerGas(num: bigint, { strict }: ValidationOpts) {
|
|
464
|
+
abig(num);
|
|
465
|
+
if (strict) minmax(num, BigInt(1), amounts.maxGasPrice, '>= 1 wei and < 10000 gwei');
|
|
466
|
+
else minmax(num, _0n, amounts.maxUint64);
|
|
467
|
+
},
|
|
468
|
+
maxPriorityFeePerGas(num: bigint, { strict, data }: ValidationOpts) {
|
|
469
|
+
abig(num);
|
|
470
|
+
if (strict) minmax(num, _0n, amounts.maxGasPrice, '>= 1 wei and < 10000 gwei');
|
|
471
|
+
else minmax(num, _0n, amounts.maxUint64, '>= 1 wei and < 10000 gwei');
|
|
472
|
+
if (strict && data && typeof data.maxFeePerGas === 'bigint' && data.maxFeePerGas < num) {
|
|
473
|
+
throw new Error(`cannot be bigger than maxFeePerGas=${data.maxFeePerGas}`);
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
gasLimit(num: bigint, { strict }: ValidationOpts) {
|
|
477
|
+
abig(num);
|
|
478
|
+
if (strict) minmax(num, amounts.minGasLimit, amounts.maxGasLimit);
|
|
479
|
+
else minmax(num, _0n, amounts.maxUint64);
|
|
480
|
+
},
|
|
481
|
+
to(address: string, { strict, data }: ValidationOpts) {
|
|
482
|
+
if (!addr.isValid(address, true)) throw new Error('address checksum does not match');
|
|
483
|
+
if (strict && address === '0x' && !data.data)
|
|
484
|
+
throw new Error('Empty address (0x) without contract deployment code');
|
|
485
|
+
},
|
|
486
|
+
value(num: bigint, { strict }: ValidationOpts) {
|
|
487
|
+
abig(num);
|
|
488
|
+
if (strict) minmax(num, _0n, amounts.maxAmount, '>= 0 and < 1M eth');
|
|
489
|
+
},
|
|
490
|
+
data(val: string, { strict, data }: ValidationOpts) {
|
|
491
|
+
if (typeof val !== 'string') throw new Error('data must be string');
|
|
492
|
+
if (strict) {
|
|
493
|
+
if (val.length > amounts.maxDataSize) throw new Error('data is too big: ' + val.length);
|
|
494
|
+
}
|
|
495
|
+
// NOTE: data is hex here
|
|
496
|
+
if (data.to === '0x' && val.length > 2 * amounts.maxInitDataSize)
|
|
497
|
+
throw new Error(`initcode is too big: ${val.length}`);
|
|
498
|
+
},
|
|
499
|
+
chainId(num: bigint, { strict, type }: ValidationOpts) {
|
|
500
|
+
// chainId is optional for legacy transactions
|
|
501
|
+
if (type === 'legacy' && num === undefined) return;
|
|
502
|
+
abig(num);
|
|
503
|
+
if (strict) minmax(num, BigInt(1), amounts.maxChainId, '>= 1 and <= 2**32-1');
|
|
504
|
+
},
|
|
505
|
+
accessList(list: AccessList) {
|
|
506
|
+
// NOTE: we cannot handle this validation in coder, since it requires chainId to calculate correct checksum
|
|
507
|
+
for (const { address } of list) {
|
|
508
|
+
if (!addr.isValid(address)) throw new Error('address checksum does not match');
|
|
509
|
+
}
|
|
510
|
+
},
|
|
511
|
+
authorizationList(list: AuthorizationItem[], opts: ValidationOpts) {
|
|
512
|
+
for (const { address, nonce, chainId } of list) {
|
|
513
|
+
if (!addr.isValid(address)) throw new Error('address checksum does not match');
|
|
514
|
+
// chainId in authorization list can be zero (==allow any chain)
|
|
515
|
+
abig(chainId);
|
|
516
|
+
if (opts.strict) minmax(chainId, _0n, amounts.maxChainId, '>= 0 and <= 2**32-1');
|
|
517
|
+
this.nonce(nonce, opts);
|
|
518
|
+
}
|
|
519
|
+
},
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
// Validation
|
|
523
|
+
type ErrObj = { field: string; error: string };
|
|
524
|
+
export class AggregatedError extends Error {
|
|
525
|
+
message: string;
|
|
526
|
+
errors: ErrObj[];
|
|
527
|
+
constructor(message: string, errors: ErrObj[]) {
|
|
528
|
+
super();
|
|
529
|
+
this.message = message;
|
|
530
|
+
this.errors = errors;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
export function validateFields(
|
|
535
|
+
type: TxType,
|
|
536
|
+
data: Record<string, any>,
|
|
537
|
+
strict = true,
|
|
538
|
+
allowSignatureFields = true
|
|
539
|
+
): void {
|
|
540
|
+
aobj(data);
|
|
541
|
+
if (!TxVersions.hasOwnProperty(type)) throw new Error(`unknown tx type=${type}`);
|
|
542
|
+
const txType = TxVersions[type];
|
|
543
|
+
const dataFields = new Set(Object.keys(data));
|
|
544
|
+
const dataHas = (field: string) => dataFields.has(field);
|
|
545
|
+
function checkField(field: CoderName) {
|
|
546
|
+
if (!dataHas(field))
|
|
547
|
+
return { field, error: `field "${field}" must be present for tx type=${type}` };
|
|
548
|
+
const val = data[field];
|
|
549
|
+
try {
|
|
550
|
+
if (validators.hasOwnProperty(field)) validators[field](val, { data, strict, type });
|
|
551
|
+
if (field === 'chainId') return; // chainId is validated, but can't be decoded
|
|
552
|
+
coders[field].decode(val as never); // decoding may throw an error
|
|
553
|
+
} catch (error) {
|
|
554
|
+
// No early-return: when multiple fields have error, we should show them all.
|
|
555
|
+
return { field, error: (error as Error).message };
|
|
556
|
+
}
|
|
557
|
+
return undefined;
|
|
558
|
+
}
|
|
559
|
+
// All fields are required.
|
|
560
|
+
const reqErrs = txType.fields.map(checkField);
|
|
561
|
+
// Signature fields should be all present or all missing
|
|
562
|
+
const optErrs = txType.optionalFields.some(dataHas) ? txType.optionalFields.map(checkField) : [];
|
|
563
|
+
|
|
564
|
+
// Check if user data has unexpected fields
|
|
565
|
+
const unexpErrs = Object.keys(data).map((field) => {
|
|
566
|
+
if (!txType.setOfAllFields.has(field as any))
|
|
567
|
+
return { field, error: `unknown field "${field}" for tx type=${type}` };
|
|
568
|
+
if (!allowSignatureFields && signatureFields.has(field as any))
|
|
569
|
+
return {
|
|
570
|
+
field,
|
|
571
|
+
error: `field "${field}" is sig-related and must not be user-specified`,
|
|
572
|
+
};
|
|
573
|
+
return;
|
|
574
|
+
});
|
|
575
|
+
const errors = (reqErrs as (ErrObj | undefined)[])
|
|
576
|
+
.concat(optErrs, unexpErrs)
|
|
577
|
+
.filter((val) => val !== undefined) as ErrObj[];
|
|
578
|
+
if (errors.length > 0) throw new AggregatedError('fields had validation errors', errors);
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
// prettier-ignore
|
|
582
|
+
const sortedFieldOrder = [
|
|
583
|
+
'to', 'value', 'nonce',
|
|
584
|
+
'maxFeePerGas', 'maxFeePerBlobGas', 'maxPriorityFeePerGas', 'gasPrice', 'gasLimit',
|
|
585
|
+
'accessList', 'authorizationList', 'blobVersionedHashes', 'chainId', 'data', 'type',
|
|
586
|
+
'r', 's', 'yParity', 'v'
|
|
587
|
+
] as const;
|
|
588
|
+
|
|
589
|
+
// TODO: remove any
|
|
590
|
+
export function sortRawData(raw: TxCoder<any>): any {
|
|
591
|
+
const sortedRaw: Record<string, any> = {};
|
|
592
|
+
sortedFieldOrder
|
|
593
|
+
.filter((field) => raw.hasOwnProperty(field))
|
|
594
|
+
.forEach((field) => {
|
|
595
|
+
sortedRaw[field] = raw[field];
|
|
596
|
+
});
|
|
597
|
+
return sortedRaw;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
export function decodeLegacyV(raw: TxCoder<any>): bigint | undefined {
|
|
601
|
+
return legacySig.decode(raw).v;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** EIP-7702 Authorizations. */
|
|
605
|
+
export const authorization = {
|
|
606
|
+
_getHash(req: AuthorizationRequest): Uint8Array {
|
|
607
|
+
const msg = RLP.encode(authorizationRequest.decode(req));
|
|
608
|
+
return keccak_256(concatBytes(new Uint8Array([0x05]), msg));
|
|
609
|
+
},
|
|
610
|
+
sign(req: AuthorizationRequest, privateKey: string): AuthorizationItem {
|
|
611
|
+
astr(privateKey);
|
|
612
|
+
const sig = sign(this._getHash(req), ethHex.decode(privateKey));
|
|
613
|
+
return { ...req, r: sig.r, s: sig.s, yParity: sig.recovery! };
|
|
614
|
+
},
|
|
615
|
+
getAuthority(item: AuthorizationItem): string {
|
|
616
|
+
const { r, s, yParity, ...req } = item;
|
|
617
|
+
const hash = this._getHash(req);
|
|
618
|
+
const sig = initSig({ r, s }, yParity);
|
|
619
|
+
// const point = sig.recoverPublicKey(hash);
|
|
620
|
+
const bytes = secp256k1.recoverPublicKey(sig.toBytes('recovered'), hash, { prehash: false });
|
|
621
|
+
return addr.fromPublicKey(bytes);
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
|
|
625
|
+
// NOTE: for tests only, don't use
|
|
626
|
+
export const __tests: any = { legacySig, TxVersions };
|