@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,274 @@
|
|
|
1
|
+
/*! micro-eth-signer - MIT License (c) 2021 Paul Miller (paulmillr.com) */
|
|
2
|
+
import { keccak_256 } from '../../../../../@noble/hashes/2.0.1/src/sha3.js';
|
|
3
|
+
import { bytesToHex, hexToBytes } from '../../../../../@noble/hashes/2.0.1/src/utils.js';
|
|
4
|
+
import { type UnwrapCoder } from '../../../../micro-packed/0.8.0/src/index.js';
|
|
5
|
+
import { addr } from './address.js';
|
|
6
|
+
import {
|
|
7
|
+
RawTx,
|
|
8
|
+
TxVersions,
|
|
9
|
+
decodeLegacyV,
|
|
10
|
+
removeSig,
|
|
11
|
+
sortRawData,
|
|
12
|
+
validateFields,
|
|
13
|
+
type TxCoder,
|
|
14
|
+
type TxType,
|
|
15
|
+
} from './tx-internal.js';
|
|
16
|
+
// prettier-ignore
|
|
17
|
+
import { secp256k1 } from '../../../../../@noble/curves/2.0.1/src/secp256k1.js';
|
|
18
|
+
import {
|
|
19
|
+
amounts,
|
|
20
|
+
cloneDeep,
|
|
21
|
+
ethHex,
|
|
22
|
+
ethHexNoLeadingZero,
|
|
23
|
+
initSig,
|
|
24
|
+
isBytes,
|
|
25
|
+
sign,
|
|
26
|
+
strip0x,
|
|
27
|
+
verify,
|
|
28
|
+
} from '../utils.js';
|
|
29
|
+
|
|
30
|
+
// The file exports Transaction, but actual (RLP) parsing logic is done in `./tx`
|
|
31
|
+
|
|
32
|
+
// Transaction-related utils.
|
|
33
|
+
|
|
34
|
+
// 4 fields are required. Others are pre-filled with default values.
|
|
35
|
+
const TX_DEFAULTS = {
|
|
36
|
+
accessList: [], // needs to be .slice()-d to create new reference
|
|
37
|
+
authorizationList: [],
|
|
38
|
+
chainId: BigInt(1) satisfies bigint as bigint, // mainnet
|
|
39
|
+
data: '',
|
|
40
|
+
gasLimit: BigInt(21000) satisfies bigint as bigint, // TODO: investigate if limit is smaller in eip4844 txs
|
|
41
|
+
maxPriorityFeePerGas: (BigInt(1) * amounts.GWEI) satisfies bigint as bigint, // Reduce fingerprinting by using standard, popular value
|
|
42
|
+
type: 'eip1559',
|
|
43
|
+
} as const;
|
|
44
|
+
type DefaultField = keyof typeof TX_DEFAULTS;
|
|
45
|
+
type DefaultType = (typeof TX_DEFAULTS)['type'];
|
|
46
|
+
type DefaultsOptional<T> = {
|
|
47
|
+
[P in keyof T as P extends DefaultField ? P : never]?: T[P];
|
|
48
|
+
} & {
|
|
49
|
+
[P in keyof T as P extends DefaultField ? never : P]: T[P];
|
|
50
|
+
};
|
|
51
|
+
type HumanInputInner<T extends TxType> = DefaultsOptional<{ type: T } & TxCoder<T>>;
|
|
52
|
+
type HumanInputInnerDefault = DefaultsOptional<TxCoder<DefaultType>>;
|
|
53
|
+
type Required<T> = T extends undefined ? never : T;
|
|
54
|
+
type HumanInput<T extends TxType | undefined> = T extends undefined
|
|
55
|
+
? HumanInputInnerDefault
|
|
56
|
+
: HumanInputInner<Required<T>>;
|
|
57
|
+
type TxVersions = typeof TxVersions;
|
|
58
|
+
type SpecifyVersion<T extends TxType[]> = UnwrapCoder<
|
|
59
|
+
{
|
|
60
|
+
[K in keyof TxVersions]: K extends T[number] ? TxVersions[K] : never;
|
|
61
|
+
}[keyof TxVersions]
|
|
62
|
+
>;
|
|
63
|
+
type SpecifyVersionNeg<T extends TxType[]> = UnwrapCoder<
|
|
64
|
+
Exclude<
|
|
65
|
+
{
|
|
66
|
+
[K in keyof TxVersions]: TxVersions[K];
|
|
67
|
+
}[keyof TxVersions],
|
|
68
|
+
{
|
|
69
|
+
[K in keyof TxVersions]: K extends T[number] ? TxVersions[K] : never;
|
|
70
|
+
}[keyof TxVersions]
|
|
71
|
+
>
|
|
72
|
+
>;
|
|
73
|
+
|
|
74
|
+
// Changes:
|
|
75
|
+
// - legacy: instead of hardfork now accepts additional param chainId
|
|
76
|
+
// if chainId is present, we enable relay protection
|
|
77
|
+
// This removes hardfork param and simplifies replay protection logic
|
|
78
|
+
// - tx parametrized over type: you cannot access fields from different tx version
|
|
79
|
+
// - legacy: 'v' param is hidden in coders. Transaction operates in terms chainId and yParity.
|
|
80
|
+
// TODO: tx is kinda immutable, but user can change .raw values before signing
|
|
81
|
+
// need to think about re-validation?
|
|
82
|
+
export class Transaction<T extends TxType> {
|
|
83
|
+
readonly type: T;
|
|
84
|
+
readonly raw: TxCoder<T>;
|
|
85
|
+
readonly isSigned: boolean;
|
|
86
|
+
|
|
87
|
+
// Doesn't force any defaults, catches if fields incompatible with type
|
|
88
|
+
constructor(type: T, raw: TxCoder<T>, strict = true, allowSignatureFields = true) {
|
|
89
|
+
this.type = type;
|
|
90
|
+
this.raw = raw;
|
|
91
|
+
validateFields(type, raw, strict, allowSignatureFields);
|
|
92
|
+
this.isSigned = typeof raw.r === 'bigint' && typeof raw.s === 'bigint';
|
|
93
|
+
}
|
|
94
|
+
// Defaults
|
|
95
|
+
static prepare<T extends { type: undefined }>(
|
|
96
|
+
data: T & HumanInputInnerDefault,
|
|
97
|
+
strict?: boolean
|
|
98
|
+
): Transaction<(typeof TX_DEFAULTS)['type']>;
|
|
99
|
+
static prepare<TT extends TxType, T extends { type: TT } & HumanInput<TT>>(
|
|
100
|
+
data: HumanInput<TT>,
|
|
101
|
+
strict?: boolean
|
|
102
|
+
): Transaction<T['type']>;
|
|
103
|
+
static prepare<T extends TxType>(data: HumanInput<T>, strict = true): Transaction<T> {
|
|
104
|
+
const type = (data.type !== undefined ? data.type : TX_DEFAULTS.type) as T;
|
|
105
|
+
if (!TxVersions.hasOwnProperty(type)) throw new Error(`wrong transaction type=${type}`);
|
|
106
|
+
const coder = TxVersions[type];
|
|
107
|
+
const fields = new Set(coder.fields as string[]);
|
|
108
|
+
// Copy default fields, but only if the field is present on the tx type.
|
|
109
|
+
const raw: Record<string, any> = { type };
|
|
110
|
+
for (const f in TX_DEFAULTS) {
|
|
111
|
+
if (f !== 'type' && fields.has(f)) {
|
|
112
|
+
raw[f] = TX_DEFAULTS[f as DefaultField];
|
|
113
|
+
if (['accessList', 'authorizationList'].includes(f)) raw[f] = cloneDeep(raw[f]);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
// Copy all fields, so we can validate unexpected ones.
|
|
117
|
+
return new Transaction(type, sortRawData(Object.assign(raw, data)), strict, false);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Creates transaction which sends whole account balance. Does two things:
|
|
121
|
+
* 1. `amount = accountBalance - maxFeePerGas * gasLimit`
|
|
122
|
+
* 2. `maxPriorityFeePerGas = maxFeePerGas`
|
|
123
|
+
*
|
|
124
|
+
* Every eth block sets a fee for all its transactions, called base fee.
|
|
125
|
+
* maxFeePerGas indicates how much gas user is able to spend in the worst case.
|
|
126
|
+
* If the block's base fee is 5 gwei, while user is able to spend 10 gwei in maxFeePerGas,
|
|
127
|
+
* the transaction would only consume 5 gwei. That means, base fee is unknown
|
|
128
|
+
* before the transaction is included in a block.
|
|
129
|
+
*
|
|
130
|
+
* By setting priorityFee to maxFee, we make the process deterministic:
|
|
131
|
+
* `maxFee = 10, maxPriority = 10, baseFee = 5` would always spend 10 gwei.
|
|
132
|
+
* In the end, the balance would become 0.
|
|
133
|
+
*
|
|
134
|
+
* WARNING: using the method would decrease privacy of a transfer, because
|
|
135
|
+
* payments for services have specific amounts, and not *the whole amount*.
|
|
136
|
+
* @param accountBalance - account balance in wei
|
|
137
|
+
* @param burnRemaining - send unspent fee to miners. When false, some "small amount" would remain
|
|
138
|
+
* @returns new transaction with adjusted amounts
|
|
139
|
+
*/
|
|
140
|
+
setWholeAmount(accountBalance: bigint, burnRemaining = true): Transaction<T> {
|
|
141
|
+
const _0n = BigInt(0);
|
|
142
|
+
if (typeof accountBalance !== 'bigint' || accountBalance <= _0n)
|
|
143
|
+
throw new Error('account balance must be bigger than 0');
|
|
144
|
+
const fee = this.fee;
|
|
145
|
+
const amountToSend = accountBalance - fee;
|
|
146
|
+
if (amountToSend <= _0n) throw new Error('account balance must be bigger than fee of ' + fee);
|
|
147
|
+
const raw = { ...this.raw, value: amountToSend };
|
|
148
|
+
if (!['legacy', 'eip2930'].includes(this.type) && burnRemaining) {
|
|
149
|
+
const r = raw as SpecifyVersionNeg<['legacy', 'eip2930']>;
|
|
150
|
+
r.maxPriorityFeePerGas = r.maxFeePerGas;
|
|
151
|
+
}
|
|
152
|
+
return new Transaction(this.type, raw);
|
|
153
|
+
}
|
|
154
|
+
static fromRawBytes(
|
|
155
|
+
bytes: Uint8Array,
|
|
156
|
+
strict = false
|
|
157
|
+
): Transaction<'legacy' | 'eip2930' | 'eip1559' | 'eip4844' | 'eip7702'> {
|
|
158
|
+
const raw = RawTx.decode(bytes);
|
|
159
|
+
return new Transaction(raw.type, raw.data, strict);
|
|
160
|
+
}
|
|
161
|
+
static fromHex(
|
|
162
|
+
hex: string,
|
|
163
|
+
strict = false
|
|
164
|
+
): Transaction<'eip1559' | 'legacy' | 'eip2930' | 'eip4844' | 'eip7702'> {
|
|
165
|
+
return Transaction.fromRawBytes(ethHexNoLeadingZero.decode(hex), strict);
|
|
166
|
+
}
|
|
167
|
+
private assertIsSigned() {
|
|
168
|
+
if (!this.isSigned) throw new Error('expected signed transaction');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Converts transaction to RLP.
|
|
172
|
+
* @param includeSignature whether to include signature
|
|
173
|
+
*/
|
|
174
|
+
toBytes(includeSignature: boolean = this.isSigned): Uint8Array {
|
|
175
|
+
// cloneDeep is not necessary here
|
|
176
|
+
let data = Object.assign({}, this.raw);
|
|
177
|
+
if (includeSignature) {
|
|
178
|
+
this.assertIsSigned();
|
|
179
|
+
} else {
|
|
180
|
+
removeSig(data);
|
|
181
|
+
}
|
|
182
|
+
return RawTx.encode({ type: this.type, data } as any); // TODO: remove any
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Converts transaction to hex.
|
|
186
|
+
* @param includeSignature whether to include signature
|
|
187
|
+
*/
|
|
188
|
+
toHex(includeSignature: boolean = this.isSigned): string {
|
|
189
|
+
return ethHex.encode(this.toBytes(includeSignature));
|
|
190
|
+
}
|
|
191
|
+
/** Calculates keccak-256 hash of signed transaction. Used in block explorers. */
|
|
192
|
+
get hash(): string {
|
|
193
|
+
this.assertIsSigned();
|
|
194
|
+
return bytesToHex(this.calcHash(true));
|
|
195
|
+
}
|
|
196
|
+
/** Returns sender's address. */
|
|
197
|
+
get sender(): string {
|
|
198
|
+
return this.recoverSender().address;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* For legacy transactions, but can be used with libraries when yParity presented as v.
|
|
202
|
+
*/
|
|
203
|
+
get v(): bigint | undefined {
|
|
204
|
+
return decodeLegacyV(this.raw);
|
|
205
|
+
}
|
|
206
|
+
private calcHash(includeSignature: boolean): Uint8Array {
|
|
207
|
+
return keccak_256(this.toBytes(includeSignature));
|
|
208
|
+
}
|
|
209
|
+
/** Calculates MAXIMUM fee in wei that could be spent. */
|
|
210
|
+
get fee(): bigint {
|
|
211
|
+
const { type, raw } = this;
|
|
212
|
+
// Fee calculation is not exact, real fee can be smaller
|
|
213
|
+
let gasFee;
|
|
214
|
+
if (type === 'legacy' || type === 'eip2930') {
|
|
215
|
+
// Because TypeScript is not smart enough to narrow down types here :(
|
|
216
|
+
const r = raw as SpecifyVersion<['legacy', 'eip2930']>;
|
|
217
|
+
gasFee = r.gasPrice;
|
|
218
|
+
} else {
|
|
219
|
+
const r = raw as SpecifyVersionNeg<['legacy', 'eip2930']>;
|
|
220
|
+
// maxFeePerGas is absolute limit, you never pay more than that
|
|
221
|
+
// maxFeePerGas = baseFeePerGas[*2] + maxPriorityFeePerGas
|
|
222
|
+
gasFee = r.maxFeePerGas;
|
|
223
|
+
}
|
|
224
|
+
// TODO: how to calculate 4844 fee?
|
|
225
|
+
return raw.gasLimit * gasFee;
|
|
226
|
+
}
|
|
227
|
+
clone(): Transaction<T> {
|
|
228
|
+
return new Transaction(this.type, cloneDeep(this.raw));
|
|
229
|
+
}
|
|
230
|
+
verifySignature(): boolean {
|
|
231
|
+
this.assertIsSigned();
|
|
232
|
+
const { r, s } = this.raw;
|
|
233
|
+
return verify(
|
|
234
|
+
new secp256k1.Signature(r!, s!).toBytes(),
|
|
235
|
+
this.calcHash(false),
|
|
236
|
+
hexToBytes(this.recoverSender().publicKey)
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
removeSignature(): Transaction<T> {
|
|
240
|
+
return new Transaction(this.type, removeSig(cloneDeep(this.raw)));
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Signs transaction with a private key.
|
|
244
|
+
* @param privateKey key in hex or Uint8Array format
|
|
245
|
+
* @param opts extraEntropy will increase security of sig by mixing rfc6979 randomness
|
|
246
|
+
* @returns new "same" transaction, but signed
|
|
247
|
+
*/
|
|
248
|
+
signBy(
|
|
249
|
+
privateKey: string | Uint8Array,
|
|
250
|
+
extraEntropy: boolean | Uint8Array = true
|
|
251
|
+
): Transaction<T> {
|
|
252
|
+
if (this.isSigned) throw new Error('expected unsigned transaction');
|
|
253
|
+
const priv = isBytes(privateKey) ? privateKey : hexToBytes(strip0x(privateKey));
|
|
254
|
+
const hash = this.calcHash(false);
|
|
255
|
+
const sig = sign(hash, priv, extraEntropy);
|
|
256
|
+
const { r, s, recovery } = sig;
|
|
257
|
+
const sraw = Object.assign(cloneDeep(this.raw), { r, s, yParity: recovery });
|
|
258
|
+
// The copied result is validated in non-strict way, strict is only for user input.
|
|
259
|
+
return new Transaction(this.type, sraw, false);
|
|
260
|
+
}
|
|
261
|
+
/** Calculates public key and address from signed transaction's signature. */
|
|
262
|
+
recoverSender(): { publicKey: string; address: string } {
|
|
263
|
+
this.assertIsSigned();
|
|
264
|
+
const { r, s, yParity } = this.raw;
|
|
265
|
+
const sig = initSig({ r: r!, s: s! }, yParity!);
|
|
266
|
+
// Will crash on 'chainstart' hardfork
|
|
267
|
+
if (sig.hasHighS()) throw new Error('invalid s');
|
|
268
|
+
const publicKey = secp256k1.recoverPublicKey(sig.toBytes('recovered'), this.calcHash(false), {
|
|
269
|
+
prehash: false,
|
|
270
|
+
});
|
|
271
|
+
// const point = sig.recoverPublicKey(this.calcHash(false));
|
|
272
|
+
return { publicKey: bytesToHex(publicKey), address: addr.fromPublicKey(publicKey) };
|
|
273
|
+
}
|
|
274
|
+
}
|
|
@@ -0,0 +1,391 @@
|
|
|
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, hexToBytes, utf8ToBytes } from '../../../../../@noble/hashes/2.0.1/src/utils.js';
|
|
4
|
+
import { mapComponent, type GetType as AbiGetType } from '../advanced/abi-mapper.js';
|
|
5
|
+
import { add0x, astr, ethHex, initSig, isObject, sign, strip0x, verify } from '../utils.js';
|
|
6
|
+
import { addr } from './address.js';
|
|
7
|
+
|
|
8
|
+
// EIP-191 signed data (https://eips.ethereum.org/EIPS/eip-191)
|
|
9
|
+
export type Hex = string | Uint8Array;
|
|
10
|
+
export interface TypedSigner<T> {
|
|
11
|
+
_getHash: (message: T) => string;
|
|
12
|
+
sign(message: T, privateKey: Hex, extraEntropy?: boolean | Uint8Array): string;
|
|
13
|
+
recoverPublicKey(signature: string, message: T): string;
|
|
14
|
+
verify(signature: string, message: T, address: string): boolean;
|
|
15
|
+
}
|
|
16
|
+
// 0x19 <1 byte version> <version specific data> <data to sign>.
|
|
17
|
+
// VERSIONS:
|
|
18
|
+
// - 0x19 <0x00> <intended validator address> <data to sign>
|
|
19
|
+
// - 0x19 <0x01> domainSeparator hashStruct(message)
|
|
20
|
+
// - 0x19 <0x45 (E)> <thereum Signed Message:\n" + len(message)> <data to sign>
|
|
21
|
+
function getSigner<T>(version: number, msgFn: (message: T) => Uint8Array): TypedSigner<T> {
|
|
22
|
+
if (version < 0 || version >= 256 || !Number.isSafeInteger(version))
|
|
23
|
+
throw new Error('Wrong version byte');
|
|
24
|
+
// bytes32 hash = keccak256(abi.encodePacked(byte(0x19), byte(0), address(this), msg.value, nonce, payload));
|
|
25
|
+
const getHash = (message: T) =>
|
|
26
|
+
keccak_256(concatBytes(new Uint8Array([0x19, version]), msgFn(message)));
|
|
27
|
+
// TODO: 'v' can contain non-undefined chainId, but not sure if it is used. If used, we need to check it with EIP-712 domain
|
|
28
|
+
return {
|
|
29
|
+
_getHash: (message: T) => ethHex.encode(getHash(message)),
|
|
30
|
+
sign(message: T, privateKey: Hex, extraEntropy: boolean | Uint8Array = true) {
|
|
31
|
+
const hash = getHash(message);
|
|
32
|
+
if (typeof privateKey === 'string') privateKey = ethHex.decode(privateKey);
|
|
33
|
+
const sig = sign(hash, privateKey, extraEntropy);
|
|
34
|
+
const end = sig.recovery === 0 ? '1b' : '1c';
|
|
35
|
+
return add0x(sig.toHex('compact') + end);
|
|
36
|
+
},
|
|
37
|
+
recoverPublicKey(signature: string, message: T) {
|
|
38
|
+
astr(signature);
|
|
39
|
+
const hash = getHash(message);
|
|
40
|
+
signature = strip0x(signature);
|
|
41
|
+
if (signature.length !== 65 * 2) throw new Error('invalid signature length');
|
|
42
|
+
const sigh = signature.slice(0, -2);
|
|
43
|
+
const end = signature.slice(-2);
|
|
44
|
+
if (!['1b', '1c'].includes(end)) throw new Error('invalid recovery bit');
|
|
45
|
+
const sig = initSig(hexToBytes(sigh), end === '1b' ? 0 : 1);
|
|
46
|
+
const publicKey = secp256k1.recoverPublicKey(sig.toBytes('recovered'), hash, {
|
|
47
|
+
prehash: false,
|
|
48
|
+
});
|
|
49
|
+
// const pub = sig.recoverPublicKey(hash).toBytes(false);
|
|
50
|
+
if (!verify(sig.toBytes('compact'), hash, publicKey)) throw new Error('invalid signature');
|
|
51
|
+
return addr.fromPublicKey(publicKey);
|
|
52
|
+
},
|
|
53
|
+
verify(signature: string, message: T, address: string): boolean {
|
|
54
|
+
const recAddr = this.recoverPublicKey(signature, message);
|
|
55
|
+
const low = recAddr.toLowerCase();
|
|
56
|
+
const upp = recAddr.toUpperCase();
|
|
57
|
+
if (address === low || address === upp) return true; // non-checksummed
|
|
58
|
+
return recAddr === address; // checksummed
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// EIP-191/EIP-7749: 0x19 <0x00> <intended validator address> <data to sign>
|
|
64
|
+
// export const intendedValidator = getSigner(
|
|
65
|
+
// 0x00,
|
|
66
|
+
// ({ message, validator }: { message: Uint8Array; validator: string }) => {
|
|
67
|
+
// const { data } = addr.parse(validator);
|
|
68
|
+
// return concatBytes(hexToBytes(data), message);
|
|
69
|
+
// }
|
|
70
|
+
// );
|
|
71
|
+
|
|
72
|
+
// EIP-191: 0x19 <0x45 (E)> <thereum Signed Message:\n" + len(message)> <data to sign>
|
|
73
|
+
export const eip191Signer: TypedSigner<string | Uint8Array> = getSigner(
|
|
74
|
+
0x45,
|
|
75
|
+
(msg: string | Uint8Array) => {
|
|
76
|
+
if (typeof msg === 'string') msg = utf8ToBytes(msg);
|
|
77
|
+
return concatBytes(utf8ToBytes(`thereum Signed Message:\n${msg.length}`), msg);
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// eip712 typed signed data on top of signed data (https://eips.ethereum.org/EIPS/eip-712)
|
|
82
|
+
// - V1: no domain, {name: string, type: string, value: any}[] - NOT IMPLEMENTED
|
|
83
|
+
// - V3: basic (no arrays and recursive stuff)
|
|
84
|
+
// - V4: V3 + support of arrays and recursive stuff
|
|
85
|
+
// TODO:
|
|
86
|
+
// https://eips.ethereum.org/EIPS/eip-4361: Off-chain authentication for Ethereum accounts to establish sessions
|
|
87
|
+
|
|
88
|
+
// There is two API for different usage-cases:
|
|
89
|
+
// - encodeData/signTyped, verifyTyped -> wallet like application, when we sign already constructed stuff ('web3.eth.personal.signTypedData')
|
|
90
|
+
// - encoder(type).encodeData/sign/verify -> if we construct data and want re-use types for different requests + type safety for static types.
|
|
91
|
+
|
|
92
|
+
// TODO: type is ABI type, but restricted
|
|
93
|
+
export type EIP712Component = { name: string; type: string };
|
|
94
|
+
export type EIP712Types = Record<string, readonly EIP712Component[]>;
|
|
95
|
+
|
|
96
|
+
// This makes 'bytes' -> Uint8Array, 'uint' -> bigint. However, we support 'string' for them (JSON in wallets),
|
|
97
|
+
// but for static types it is actually better to use strict types, since otherwise everything is 'string'. Address is string,
|
|
98
|
+
// but sending it in uint field can be mistake. Please open issue if you have use case where this behavior causes problems.
|
|
99
|
+
// prettier-ignore
|
|
100
|
+
type ProcessType<T extends string, Types extends EIP712Types> =
|
|
101
|
+
T extends `${infer Base}[]${infer Rest}` ? ProcessType<`${Base}${Rest}`, Types>[] : // 'string[]' -> 'string'[]
|
|
102
|
+
T extends `${infer Base}[${number}]${infer Rest}` ? ProcessType<`${Base}${Rest}`, Types>[] : // 'string[3]' -> 'string'[]
|
|
103
|
+
T extends keyof Types ? GetType<Types, T> | undefined : // recursive
|
|
104
|
+
AbiGetType<T>;
|
|
105
|
+
|
|
106
|
+
export type GetType<Types extends EIP712Types, K extends keyof Types & string> = {
|
|
107
|
+
[C in Types[K][number] as C['name']]: ProcessType<C['type'], Types>;
|
|
108
|
+
};
|
|
109
|
+
type Key<T extends EIP712Types> = keyof T & string;
|
|
110
|
+
|
|
111
|
+
// TODO: merge with abi somehow?
|
|
112
|
+
function parseType(s: string): {
|
|
113
|
+
base: string;
|
|
114
|
+
item: string;
|
|
115
|
+
type: string;
|
|
116
|
+
arrayLen: number | undefined;
|
|
117
|
+
isArray: boolean;
|
|
118
|
+
} {
|
|
119
|
+
let m = s.match(/^([^\[]+)(?:.*\[(.*?)\])?$/);
|
|
120
|
+
if (!m) throw new Error(`parseType: wrong type: ${s}`);
|
|
121
|
+
const base = m[1];
|
|
122
|
+
const isArray = m[2] !== undefined;
|
|
123
|
+
// TODO: check for safe integer
|
|
124
|
+
const arrayLen = m[2] !== undefined && m[2] !== '' ? Number(m[2]) : undefined;
|
|
125
|
+
if (arrayLen !== undefined && (!Number.isSafeInteger(arrayLen) || arrayLen.toString() !== m[2]))
|
|
126
|
+
throw new Error(`parseType: wrong array length: ${s}`);
|
|
127
|
+
let type = 'struct';
|
|
128
|
+
if (['string', 'bytes'].includes(base)) type = 'dynamic';
|
|
129
|
+
else if (['bool', 'address'].includes(base)) type = 'atomic';
|
|
130
|
+
else if ((m = /^(u?)int([0-9]+)?$/.exec(base))) {
|
|
131
|
+
const bits = m[2] ? +m[2] : 256;
|
|
132
|
+
if (!Number.isSafeInteger(bits) || bits <= 0 || bits % 8 !== 0 || bits > 256)
|
|
133
|
+
throw new Error('parseType: invalid numeric type');
|
|
134
|
+
type = 'atomic';
|
|
135
|
+
} else if ((m = /^bytes([0-9]{1,2})$/.exec(base))) {
|
|
136
|
+
const bytes = +m[1];
|
|
137
|
+
if (!bytes || bytes > 32) throw new Error(`parseType: wrong bytes<N=${bytes}> type`);
|
|
138
|
+
type = 'atomic';
|
|
139
|
+
}
|
|
140
|
+
const item = s.replace(/\[[^\]]*\]$/, '');
|
|
141
|
+
return { base, item, type, arrayLen, isArray };
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// traverse dependency graph, find all transitive dependencies. Also, basic sanity check
|
|
145
|
+
function getDependencies(types: EIP712Types): Record<string, Set<string>> {
|
|
146
|
+
if (typeof types !== 'object' || types === null) throw new Error('wrong types object');
|
|
147
|
+
// Collect non-basic dependencies & sanity
|
|
148
|
+
const res: Record<string, Set<string>> = {};
|
|
149
|
+
for (const [name, fields] of Object.entries(types)) {
|
|
150
|
+
const cur: Set<string> = new Set(); // type may appear multiple times in struct
|
|
151
|
+
for (const { type } of fields) {
|
|
152
|
+
const p = parseType(type);
|
|
153
|
+
if (p.type !== 'struct') continue; // skip basic fields
|
|
154
|
+
if (p.base === name) continue; // self reference
|
|
155
|
+
if (!types[p.base]) throw new Error(`getDependencies: wrong struct type name=${type}`);
|
|
156
|
+
cur.add(p.base);
|
|
157
|
+
}
|
|
158
|
+
res[name] = cur;
|
|
159
|
+
}
|
|
160
|
+
// This should be more efficient with toposort + cycle detection, but I've already spent too much time here
|
|
161
|
+
// and for most cases there won't be a lot of types here anyway.
|
|
162
|
+
for (let changed = true; changed; ) {
|
|
163
|
+
changed = false;
|
|
164
|
+
for (const [name, curDeps] of Object.entries(res)) {
|
|
165
|
+
// Map here, because curDeps will change
|
|
166
|
+
const trDeps = Array.from(curDeps).map((i) => res[i]);
|
|
167
|
+
for (const d of trDeps) {
|
|
168
|
+
for (const td of d) {
|
|
169
|
+
if (td === name || curDeps.has(td)) continue;
|
|
170
|
+
curDeps.add(td);
|
|
171
|
+
changed = true;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return res;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function getTypes(types: EIP712Types) {
|
|
180
|
+
const deps = getDependencies(types);
|
|
181
|
+
const names: Record<string, string> = {};
|
|
182
|
+
// Build names
|
|
183
|
+
for (const type in types)
|
|
184
|
+
names[type] = `${type}(${types[type].map(({ name, type }) => `${type} ${name}`).join(',')})`;
|
|
185
|
+
const fullNames: Record<string, string> = {};
|
|
186
|
+
for (const [name, curDeps] of Object.entries(deps)) {
|
|
187
|
+
const n = [name].concat(Array.from(curDeps).sort());
|
|
188
|
+
fullNames[name] = n.map((i) => names[i]).join('');
|
|
189
|
+
}
|
|
190
|
+
const hashes = Object.fromEntries(
|
|
191
|
+
Object.entries(fullNames).map(([k, v]) => [k, keccak_256(utf8ToBytes(v))])
|
|
192
|
+
);
|
|
193
|
+
// fields
|
|
194
|
+
const fields: Record<string, Set<string>> = {};
|
|
195
|
+
for (const type in types) {
|
|
196
|
+
const res: Set<string> = new Set();
|
|
197
|
+
for (const { name } of types[type]) {
|
|
198
|
+
if (res.has(name)) throw new Error(`field ${name} included multiple times in type ${type}`);
|
|
199
|
+
res.add(name);
|
|
200
|
+
}
|
|
201
|
+
fields[type] = res;
|
|
202
|
+
}
|
|
203
|
+
return { names, fullNames, hashes, fields };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// This re-uses domain per multiple requests, which is based on assumption that domain is static for different requests with
|
|
207
|
+
// different types. Please raise issue if you have different use case.
|
|
208
|
+
export function encoder<T extends EIP712Types>(types: T, domain: GetType<T, 'EIP712Domain'>) {
|
|
209
|
+
if (!isObject(domain)) throw Error(`wrong domain=${domain}`);
|
|
210
|
+
if (!isObject(types)) throw Error(`wrong types=${types}`);
|
|
211
|
+
const info = getTypes(types);
|
|
212
|
+
const encodeField = (type: string, data: any, withHash = true): Uint8Array => {
|
|
213
|
+
const p = parseType(type);
|
|
214
|
+
if (p.isArray) {
|
|
215
|
+
if (!Array.isArray(data)) throw new Error(`expected array, got: ${data}`);
|
|
216
|
+
if (p.arrayLen !== undefined && data.length !== p.arrayLen)
|
|
217
|
+
throw new Error(`wrong array length: expected ${p.arrayLen}, got ${data}`);
|
|
218
|
+
return keccak_256(concatBytes(...data.map((i) => encodeField(p.item, i))));
|
|
219
|
+
}
|
|
220
|
+
if (p.type === 'struct') {
|
|
221
|
+
const def = types[type];
|
|
222
|
+
if (!def) throw new Error(`wrong type: ${type}`);
|
|
223
|
+
const fieldNames = info.fields[type];
|
|
224
|
+
if (!isObject(data)) throw new Error(`encoding non-object as custom type ${type}`);
|
|
225
|
+
for (const k in data)
|
|
226
|
+
if (!fieldNames.has(k)) throw new Error(`unexpected field ${k} in ${type}`);
|
|
227
|
+
// TODO: use correct concatBytes (need to export from P?). This will easily crash with stackoverflow if too much fields.
|
|
228
|
+
const fields = [];
|
|
229
|
+
for (const { name, type } of def) {
|
|
230
|
+
// This is not mentioned in spec, but used in eth-sig-util
|
|
231
|
+
// Since there is no 'optional' fields inside eip712, it makes impossible to encode circular structure without arrays,
|
|
232
|
+
// but seems like other project use this.
|
|
233
|
+
// NOTE: this is V4 only stuff. If you need V3 behavior, please open issue.
|
|
234
|
+
if (types[type] && data[name] === undefined) {
|
|
235
|
+
fields.push(new Uint8Array(32));
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
fields.push(encodeField(type, data[name]));
|
|
239
|
+
}
|
|
240
|
+
const res = concatBytes(info.hashes[p.base], ...fields);
|
|
241
|
+
return withHash ? keccak_256(res) : res;
|
|
242
|
+
}
|
|
243
|
+
if (type === 'string' || type === 'bytes') {
|
|
244
|
+
if (type === 'bytes' && typeof data === 'string') data = ethHex.decode(data);
|
|
245
|
+
return keccak_256(typeof data === 'string' ? utf8ToBytes(data) : data); // hashed as is!
|
|
246
|
+
}
|
|
247
|
+
// Type conversion is neccessary here, because we can get data from JSON (no Uint8Arrays/bigints).
|
|
248
|
+
if (type.startsWith('bytes') && typeof data === 'string') data = ethHex.decode(data);
|
|
249
|
+
if ((type.startsWith('int') || type.startsWith('uint')) && typeof data === 'string')
|
|
250
|
+
data = BigInt(data);
|
|
251
|
+
return mapComponent({ type }).encode(data);
|
|
252
|
+
};
|
|
253
|
+
const encodeData = <K extends Key<T>>(type: K, data: GetType<T, K>) => {
|
|
254
|
+
astr(type);
|
|
255
|
+
if (!types[type]) throw new Error(`Unknown type: ${type}`);
|
|
256
|
+
if (!isObject(data)) throw new Error('wrong data object');
|
|
257
|
+
return encodeField(type, data, false);
|
|
258
|
+
};
|
|
259
|
+
const structHash = (type: Key<T>, data: any) => keccak_256(encodeData(type, data));
|
|
260
|
+
const domainHash = structHash('EIP712Domain', domain);
|
|
261
|
+
// NOTE: we cannot use Msg here, since its already parametrized and everything will break.
|
|
262
|
+
const signer = getSigner(0x01, (msg: { primaryType: string; message: any }) => {
|
|
263
|
+
if (typeof msg.primaryType !== 'string') throw Error(`wrong primaryType=${msg.primaryType}`);
|
|
264
|
+
if (!isObject(msg.message)) throw Error(`wrong message=${msg.message}`);
|
|
265
|
+
if (msg.primaryType === 'EIP712Domain') return domainHash;
|
|
266
|
+
return concatBytes(domainHash, structHash(msg.primaryType, msg.message));
|
|
267
|
+
});
|
|
268
|
+
return {
|
|
269
|
+
encodeData: <K extends Key<T>>(type: K, message: GetType<T, K>): string =>
|
|
270
|
+
ethHex.encode(encodeData(type, message)),
|
|
271
|
+
structHash: <K extends Key<T>>(type: K, message: GetType<T, K>): string =>
|
|
272
|
+
ethHex.encode(structHash(type, message)),
|
|
273
|
+
// Signer
|
|
274
|
+
_getHash: <K extends Key<T>>(primaryType: K, message: GetType<T, K>): string =>
|
|
275
|
+
signer._getHash({ primaryType, message }),
|
|
276
|
+
sign: <K extends Key<T>>(
|
|
277
|
+
primaryType: K,
|
|
278
|
+
message: GetType<T, K>,
|
|
279
|
+
privateKey: Hex,
|
|
280
|
+
extraEntropy?: boolean | Uint8Array
|
|
281
|
+
): string => signer.sign({ primaryType, message }, privateKey, extraEntropy),
|
|
282
|
+
verify: <K extends Key<T>>(
|
|
283
|
+
primaryType: K,
|
|
284
|
+
signature: string,
|
|
285
|
+
message: GetType<T, K>,
|
|
286
|
+
address: string
|
|
287
|
+
): boolean => signer.verify(signature, { primaryType, message }, address),
|
|
288
|
+
recoverPublicKey: <K extends Key<T>>(
|
|
289
|
+
primaryType: K,
|
|
290
|
+
signature: string,
|
|
291
|
+
message: GetType<T, K>
|
|
292
|
+
): string => signer.recoverPublicKey(signature, { primaryType, message }),
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export const EIP712Domain = [
|
|
297
|
+
{ name: 'name', type: 'string' }, // the user readable name of signing domain, i.e. the name of the DApp or the protocol.
|
|
298
|
+
{ name: 'version', type: 'string' }, // the current major version of the signing domain. Signatures from different versions are not compatible.
|
|
299
|
+
{ name: 'chainId', type: 'uint256' }, // the EIP-155 chain id. The user-agent should refuse signing if it does not match the currently active chain.
|
|
300
|
+
{ name: 'verifyingContract', type: 'address' }, // the address of the contract that will verify the signature. The user-agent may do contract specific phishing prevention.
|
|
301
|
+
{ name: 'salt', type: 'bytes32' }, // an disambiguating salt for the protocol. This can be used as a domain separator of last resort.
|
|
302
|
+
] as const;
|
|
303
|
+
export type DomainParams = typeof EIP712Domain;
|
|
304
|
+
|
|
305
|
+
const domainTypes = { EIP712Domain: EIP712Domain as DomainParams };
|
|
306
|
+
export type EIP712Domain = GetType<typeof domainTypes, 'EIP712Domain'>;
|
|
307
|
+
|
|
308
|
+
// Filter unused domain fields from type
|
|
309
|
+
export function getDomainType(domain: EIP712Domain) {
|
|
310
|
+
return EIP712Domain.filter(({ name }) => domain[name] !== undefined);
|
|
311
|
+
}
|
|
312
|
+
// Additional API without type safety for wallet-like applications
|
|
313
|
+
export type TypedData<T extends EIP712Types, K extends Key<T>> = {
|
|
314
|
+
types: T;
|
|
315
|
+
primaryType: K;
|
|
316
|
+
domain: GetType<T, 'EIP712Domain'>;
|
|
317
|
+
message: GetType<T, K>;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
const getTypedTypes = <T extends EIP712Types, K extends Key<T>>(typed: TypedData<T, K>) => ({
|
|
321
|
+
EIP712Domain: getDomainType(typed.domain as any),
|
|
322
|
+
...typed.types,
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
function validateTyped<T extends EIP712Types, K extends Key<T>>(t: TypedData<T, K>) {
|
|
326
|
+
if (!isObject(t.message)) throw new Error('wrong message');
|
|
327
|
+
if (!isObject(t.domain)) throw new Error('wrong domain');
|
|
328
|
+
if (!isObject(t.types)) throw new Error('wrong types');
|
|
329
|
+
if (typeof t.primaryType !== 'string' || !t.types[t.primaryType])
|
|
330
|
+
throw new Error('wrong primaryType');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function encodeData<T extends EIP712Types, K extends Key<T>>(
|
|
334
|
+
typed: TypedData<T, K>
|
|
335
|
+
): string {
|
|
336
|
+
validateTyped(typed);
|
|
337
|
+
return encoder(getTypedTypes(typed) as T, typed.domain).encodeData(
|
|
338
|
+
typed.primaryType,
|
|
339
|
+
typed.message
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
export function sigHash<T extends EIP712Types, K extends Key<T>>(typed: TypedData<T, K>): string {
|
|
344
|
+
validateTyped(typed);
|
|
345
|
+
return encoder(getTypedTypes(typed) as T, typed.domain)._getHash(
|
|
346
|
+
typed.primaryType,
|
|
347
|
+
typed.message
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export function signTyped<T extends EIP712Types, K extends Key<T>>(
|
|
352
|
+
typed: TypedData<T, K>,
|
|
353
|
+
privateKey: Hex,
|
|
354
|
+
extraEntropy?: boolean | Uint8Array
|
|
355
|
+
): string {
|
|
356
|
+
validateTyped(typed);
|
|
357
|
+
return encoder(getTypedTypes(typed) as T, typed.domain).sign(
|
|
358
|
+
typed.primaryType,
|
|
359
|
+
typed.message,
|
|
360
|
+
privateKey,
|
|
361
|
+
extraEntropy
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
export function verifyTyped<T extends EIP712Types, K extends Key<T>>(
|
|
366
|
+
signature: string,
|
|
367
|
+
typed: TypedData<T, K>,
|
|
368
|
+
address: string
|
|
369
|
+
): boolean {
|
|
370
|
+
validateTyped(typed);
|
|
371
|
+
return encoder(getTypedTypes(typed) as T, typed.domain).verify(
|
|
372
|
+
typed.primaryType,
|
|
373
|
+
signature,
|
|
374
|
+
typed.message,
|
|
375
|
+
address
|
|
376
|
+
);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
export function recoverPublicKeyTyped<T extends EIP712Types, K extends Key<T>>(
|
|
380
|
+
signature: string,
|
|
381
|
+
typed: TypedData<T, K>
|
|
382
|
+
): string {
|
|
383
|
+
return encoder(getTypedTypes(typed) as T, typed.domain).recoverPublicKey(
|
|
384
|
+
typed.primaryType,
|
|
385
|
+
signature,
|
|
386
|
+
typed.message
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Internal methods for test purposes only
|
|
391
|
+
export const _TEST: any = /* @__PURE__ */ { parseType, getDependencies, getTypes, encoder };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { addr } from './core/address.js';
|
|
2
|
+
export { authorization } from './core/tx-internal.js';
|
|
3
|
+
export { Transaction } from './core/tx.js';
|
|
4
|
+
export {
|
|
5
|
+
eip191Signer,
|
|
6
|
+
recoverPublicKeyTyped,
|
|
7
|
+
signTyped,
|
|
8
|
+
verifyTyped,
|
|
9
|
+
type EIP712Domain,
|
|
10
|
+
type TypedData,
|
|
11
|
+
} from './core/typed-data.js';
|
|
12
|
+
export { amounts, ethHex, ethHexNoLeadingZero, weieth, weigwei } from './utils.js';
|