@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,633 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Methods for elliptic curve multiplication by scalars.
|
|
3
|
+
* Contains wNAF, pippenger.
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
+
import { bitLen, bitMask, type Signer } from '../utils.js';
|
|
8
|
+
import { Field, FpInvertBatch, validateField, type IField } from './modular.js';
|
|
9
|
+
|
|
10
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
11
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
12
|
+
|
|
13
|
+
export type AffinePoint<T> = {
|
|
14
|
+
x: T;
|
|
15
|
+
y: T;
|
|
16
|
+
} & { Z?: never };
|
|
17
|
+
|
|
18
|
+
// We can't "abstract out" coordinates (X, Y, Z; and T in Edwards): argument names of constructor
|
|
19
|
+
// are not accessible. See Typescript gh-56093, gh-41594.
|
|
20
|
+
//
|
|
21
|
+
// We have to use recursive types, so it will return actual point, not constained `CurvePoint`.
|
|
22
|
+
// If, at any point, P is `any`, it will erase all types and replace it
|
|
23
|
+
// with `any`, because of recursion, `any implements CurvePoint`,
|
|
24
|
+
// but we lose all constrains on methods.
|
|
25
|
+
|
|
26
|
+
/** Base interface for all elliptic curve Points. */
|
|
27
|
+
export interface CurvePoint<F, P extends CurvePoint<F, P>> {
|
|
28
|
+
/** Affine x coordinate. Different from projective / extended X coordinate. */
|
|
29
|
+
x: F;
|
|
30
|
+
/** Affine y coordinate. Different from projective / extended Y coordinate. */
|
|
31
|
+
y: F;
|
|
32
|
+
Z?: F;
|
|
33
|
+
double(): P;
|
|
34
|
+
negate(): P;
|
|
35
|
+
add(other: P): P;
|
|
36
|
+
subtract(other: P): P;
|
|
37
|
+
equals(other: P): boolean;
|
|
38
|
+
multiply(scalar: bigint): P;
|
|
39
|
+
assertValidity(): void;
|
|
40
|
+
clearCofactor(): P;
|
|
41
|
+
is0(): boolean;
|
|
42
|
+
isTorsionFree(): boolean;
|
|
43
|
+
isSmallOrder(): boolean;
|
|
44
|
+
multiplyUnsafe(scalar: bigint): P;
|
|
45
|
+
/**
|
|
46
|
+
* Massively speeds up `p.multiply(n)` by using precompute tables (caching). See {@link wNAF}.
|
|
47
|
+
* @param isLazy calculate cache now. Default (true) ensures it's deferred to first `multiply()`
|
|
48
|
+
*/
|
|
49
|
+
precompute(windowSize?: number, isLazy?: boolean): P;
|
|
50
|
+
/** Converts point to 2D xy affine coordinates */
|
|
51
|
+
toAffine(invertedZ?: F): AffinePoint<F>;
|
|
52
|
+
toBytes(): Uint8Array;
|
|
53
|
+
toHex(): string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Base interface for all elliptic curve Point constructors. */
|
|
57
|
+
export interface CurvePointCons<P extends CurvePoint<any, P>> {
|
|
58
|
+
[Symbol.hasInstance]: (item: unknown) => boolean;
|
|
59
|
+
BASE: P;
|
|
60
|
+
ZERO: P;
|
|
61
|
+
/** Field for basic curve math */
|
|
62
|
+
Fp: IField<P_F<P>>;
|
|
63
|
+
/** Scalar field, for scalars in multiply and others */
|
|
64
|
+
Fn: IField<bigint>;
|
|
65
|
+
/** Creates point from x, y. Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
66
|
+
fromAffine(p: AffinePoint<P_F<P>>): P;
|
|
67
|
+
fromBytes(bytes: Uint8Array): P;
|
|
68
|
+
fromHex(hex: string): P;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Type inference helpers: PC - PointConstructor, P - Point, Fp - Field element
|
|
72
|
+
// Short names, because we use them a lot in result types:
|
|
73
|
+
// * we can't do 'P = GetCurvePoint<PC>': this is default value and doesn't constrain anything
|
|
74
|
+
// * we can't do 'type X = GetCurvePoint<PC>': it won't be accesible for arguments/return types
|
|
75
|
+
// * `CurvePointCons<P extends CurvePoint<any, P>>` constraints from interface definition
|
|
76
|
+
// won't propagate, if `PC extends CurvePointCons<any>`: the P would be 'any', which is incorrect
|
|
77
|
+
// * PC could be super specific with super specific P, which implements CurvePoint<any, P>.
|
|
78
|
+
// this means we need to do stuff like
|
|
79
|
+
// `function test<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(`
|
|
80
|
+
// if we want type safety around P, otherwise PC_P<PC> will be any
|
|
81
|
+
|
|
82
|
+
/** Returns Fp type from Point (P_F<P> == P.F) */
|
|
83
|
+
export type P_F<P extends CurvePoint<any, P>> = P extends CurvePoint<infer F, P> ? F : never;
|
|
84
|
+
/** Returns Fp type from PointCons (PC_F<PC> == PC.P.F) */
|
|
85
|
+
export type PC_F<PC extends CurvePointCons<CurvePoint<any, any>>> = PC['Fp']['ZERO'];
|
|
86
|
+
/** Returns Point type from PointCons (PC_P<PC> == PC.P) */
|
|
87
|
+
export type PC_P<PC extends CurvePointCons<CurvePoint<any, any>>> = PC['ZERO'];
|
|
88
|
+
|
|
89
|
+
// Ugly hack to get proper type inference, because in typescript fails to infer resursively.
|
|
90
|
+
// The hack allows to do up to 10 chained operations without applying type erasure.
|
|
91
|
+
//
|
|
92
|
+
// Types which won't work:
|
|
93
|
+
// * `CurvePointCons<CurvePoint<any, any>>`, will return `any` after 1 operation
|
|
94
|
+
// * `CurvePointCons<any>: WeierstrassPointCons<bigint> extends CurvePointCons<any> = false`
|
|
95
|
+
// * `P extends CurvePoint, PC extends CurvePointCons<P>`
|
|
96
|
+
// * It can't infer P from PC alone
|
|
97
|
+
// * Too many relations between F, P & PC
|
|
98
|
+
// * It will infer P/F if `arg: CurvePointCons<F, P>`, but will fail if PC is generic
|
|
99
|
+
// * It will work correctly if there is an additional argument of type P
|
|
100
|
+
// * But generally, we don't want to parametrize `CurvePointCons` over `F`: it will complicate
|
|
101
|
+
// types, making them un-inferable
|
|
102
|
+
// prettier-ignore
|
|
103
|
+
export type PC_ANY = CurvePointCons<
|
|
104
|
+
CurvePoint<any,
|
|
105
|
+
CurvePoint<any,
|
|
106
|
+
CurvePoint<any,
|
|
107
|
+
CurvePoint<any,
|
|
108
|
+
CurvePoint<any,
|
|
109
|
+
CurvePoint<any,
|
|
110
|
+
CurvePoint<any,
|
|
111
|
+
CurvePoint<any,
|
|
112
|
+
CurvePoint<any,
|
|
113
|
+
CurvePoint<any, any>
|
|
114
|
+
>>>>>>>>>
|
|
115
|
+
>;
|
|
116
|
+
|
|
117
|
+
export interface CurveLengths {
|
|
118
|
+
secretKey?: number;
|
|
119
|
+
publicKey?: number;
|
|
120
|
+
publicKeyUncompressed?: number;
|
|
121
|
+
publicKeyHasPrefix?: boolean;
|
|
122
|
+
signature?: number;
|
|
123
|
+
seed?: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export type Mapper<T> = (i: T[]) => T[];
|
|
127
|
+
|
|
128
|
+
export function negateCt<T extends { negate: () => T }>(condition: boolean, item: T): T {
|
|
129
|
+
const neg = item.negate();
|
|
130
|
+
return condition ? neg : item;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Takes a bunch of Projective Points but executes only one
|
|
135
|
+
* inversion on all of them. Inversion is very slow operation,
|
|
136
|
+
* so this improves performance massively.
|
|
137
|
+
* Optimization: converts a list of projective points to a list of identical points with Z=1.
|
|
138
|
+
*/
|
|
139
|
+
export function normalizeZ<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(
|
|
140
|
+
c: PC,
|
|
141
|
+
points: P[]
|
|
142
|
+
): P[] {
|
|
143
|
+
const invertedZs = FpInvertBatch(
|
|
144
|
+
c.Fp,
|
|
145
|
+
points.map((p) => p.Z!)
|
|
146
|
+
);
|
|
147
|
+
return points.map((p, i) => c.fromAffine(p.toAffine(invertedZs[i])));
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function validateW(W: number, bits: number) {
|
|
151
|
+
if (!Number.isSafeInteger(W) || W <= 0 || W > bits)
|
|
152
|
+
throw new Error('invalid window size, expected [1..' + bits + '], got W=' + W);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Internal wNAF opts for specific W and scalarBits */
|
|
156
|
+
type WOpts = {
|
|
157
|
+
windows: number;
|
|
158
|
+
windowSize: number;
|
|
159
|
+
mask: bigint;
|
|
160
|
+
maxNumber: number;
|
|
161
|
+
shiftBy: bigint;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
function calcWOpts(W: number, scalarBits: number): WOpts {
|
|
165
|
+
validateW(W, scalarBits);
|
|
166
|
+
const windows = Math.ceil(scalarBits / W) + 1; // W=8 33. Not 32, because we skip zero
|
|
167
|
+
const windowSize = 2 ** (W - 1); // W=8 128. Not 256, because we skip zero
|
|
168
|
+
const maxNumber = 2 ** W; // W=8 256
|
|
169
|
+
const mask = bitMask(W); // W=8 255 == mask 0b11111111
|
|
170
|
+
const shiftBy = BigInt(W); // W=8 8
|
|
171
|
+
return { windows, windowSize, mask, maxNumber, shiftBy };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function calcOffsets(n: bigint, window: number, wOpts: WOpts) {
|
|
175
|
+
const { windowSize, mask, maxNumber, shiftBy } = wOpts;
|
|
176
|
+
let wbits = Number(n & mask); // extract W bits.
|
|
177
|
+
let nextN = n >> shiftBy; // shift number by W bits.
|
|
178
|
+
|
|
179
|
+
// What actually happens here:
|
|
180
|
+
// const highestBit = Number(mask ^ (mask >> 1n));
|
|
181
|
+
// let wbits2 = wbits - 1; // skip zero
|
|
182
|
+
// if (wbits2 & highestBit) { wbits2 ^= Number(mask); // (~);
|
|
183
|
+
|
|
184
|
+
// split if bits > max: +224 => 256-32
|
|
185
|
+
if (wbits > windowSize) {
|
|
186
|
+
// we skip zero, which means instead of `>= size-1`, we do `> size`
|
|
187
|
+
wbits -= maxNumber; // -32, can be maxNumber - wbits, but then we need to set isNeg here.
|
|
188
|
+
nextN += _1n; // +256 (carry)
|
|
189
|
+
}
|
|
190
|
+
const offsetStart = window * windowSize;
|
|
191
|
+
const offset = offsetStart + Math.abs(wbits) - 1; // -1 because we skip zero
|
|
192
|
+
const isZero = wbits === 0; // is current window slice a 0?
|
|
193
|
+
const isNeg = wbits < 0; // is current window slice negative?
|
|
194
|
+
const isNegF = window % 2 !== 0; // fake random statement for noise
|
|
195
|
+
const offsetF = offsetStart; // fake offset for noise
|
|
196
|
+
return { nextN, offset, isZero, isNeg, isNegF, offsetF };
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function validateMSMPoints(points: any[], c: any) {
|
|
200
|
+
if (!Array.isArray(points)) throw new Error('array expected');
|
|
201
|
+
points.forEach((p, i) => {
|
|
202
|
+
if (!(p instanceof c)) throw new Error('invalid point at index ' + i);
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
function validateMSMScalars(scalars: any[], field: any) {
|
|
206
|
+
if (!Array.isArray(scalars)) throw new Error('array of scalars expected');
|
|
207
|
+
scalars.forEach((s, i) => {
|
|
208
|
+
if (!field.isValid(s)) throw new Error('invalid scalar at index ' + i);
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
// Since points in different groups cannot be equal (different object constructor),
|
|
213
|
+
// we can have single place to store precomputes.
|
|
214
|
+
// Allows to make points frozen / immutable.
|
|
215
|
+
const pointPrecomputes = new WeakMap<any, any[]>();
|
|
216
|
+
const pointWindowSizes = new WeakMap<any, number>();
|
|
217
|
+
|
|
218
|
+
function getW(P: any): number {
|
|
219
|
+
// To disable precomputes:
|
|
220
|
+
// return 1;
|
|
221
|
+
return pointWindowSizes.get(P) || 1;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function assert0(n: bigint): void {
|
|
225
|
+
if (n !== _0n) throw new Error('invalid wNAF');
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Elliptic curve multiplication of Point by scalar. Fragile.
|
|
230
|
+
* Table generation takes **30MB of ram and 10ms on high-end CPU**,
|
|
231
|
+
* but may take much longer on slow devices. Actual generation will happen on
|
|
232
|
+
* first call of `multiply()`. By default, `BASE` point is precomputed.
|
|
233
|
+
*
|
|
234
|
+
* Scalars should always be less than curve order: this should be checked inside of a curve itself.
|
|
235
|
+
* Creates precomputation tables for fast multiplication:
|
|
236
|
+
* - private scalar is split by fixed size windows of W bits
|
|
237
|
+
* - every window point is collected from window's table & added to accumulator
|
|
238
|
+
* - since windows are different, same point inside tables won't be accessed more than once per calc
|
|
239
|
+
* - each multiplication is 'Math.ceil(CURVE_ORDER / 𝑊) + 1' point additions (fixed for any scalar)
|
|
240
|
+
* - +1 window is neccessary for wNAF
|
|
241
|
+
* - wNAF reduces table size: 2x less memory + 2x faster generation, but 10% slower multiplication
|
|
242
|
+
*
|
|
243
|
+
* @todo Research returning 2d JS array of windows, instead of a single window.
|
|
244
|
+
* This would allow windows to be in different memory locations
|
|
245
|
+
*/
|
|
246
|
+
export class wNAF<PC extends PC_ANY> {
|
|
247
|
+
private readonly BASE: PC_P<PC>;
|
|
248
|
+
private readonly ZERO: PC_P<PC>;
|
|
249
|
+
private readonly Fn: PC['Fn'];
|
|
250
|
+
readonly bits: number;
|
|
251
|
+
|
|
252
|
+
// Parametrized with a given Point class (not individual point)
|
|
253
|
+
constructor(Point: PC, bits: number) {
|
|
254
|
+
this.BASE = Point.BASE;
|
|
255
|
+
this.ZERO = Point.ZERO;
|
|
256
|
+
this.Fn = Point.Fn;
|
|
257
|
+
this.bits = bits;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// non-const time multiplication ladder
|
|
261
|
+
_unsafeLadder(elm: PC_P<PC>, n: bigint, p: PC_P<PC> = this.ZERO): PC_P<PC> {
|
|
262
|
+
let d: PC_P<PC> = elm;
|
|
263
|
+
while (n > _0n) {
|
|
264
|
+
if (n & _1n) p = p.add(d);
|
|
265
|
+
d = d.double();
|
|
266
|
+
n >>= _1n;
|
|
267
|
+
}
|
|
268
|
+
return p;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Creates a wNAF precomputation window. Used for caching.
|
|
273
|
+
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
274
|
+
* Number of precomputed points depends on the curve size:
|
|
275
|
+
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
276
|
+
* - 𝑊 is the window size
|
|
277
|
+
* - 𝑛 is the bitlength of the curve order.
|
|
278
|
+
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
279
|
+
* @param point Point instance
|
|
280
|
+
* @param W window size
|
|
281
|
+
* @returns precomputed point tables flattened to a single array
|
|
282
|
+
*/
|
|
283
|
+
private precomputeWindow(point: PC_P<PC>, W: number): PC_P<PC>[] {
|
|
284
|
+
const { windows, windowSize } = calcWOpts(W, this.bits);
|
|
285
|
+
const points: PC_P<PC>[] = [];
|
|
286
|
+
let p: PC_P<PC> = point;
|
|
287
|
+
let base = p;
|
|
288
|
+
for (let window = 0; window < windows; window++) {
|
|
289
|
+
base = p;
|
|
290
|
+
points.push(base);
|
|
291
|
+
// i=1, bc we skip 0
|
|
292
|
+
for (let i = 1; i < windowSize; i++) {
|
|
293
|
+
base = base.add(p);
|
|
294
|
+
points.push(base);
|
|
295
|
+
}
|
|
296
|
+
p = base.double();
|
|
297
|
+
}
|
|
298
|
+
return points;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
303
|
+
* More compact implementation:
|
|
304
|
+
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
305
|
+
* @returns real and fake (for const-time) points
|
|
306
|
+
*/
|
|
307
|
+
private wNAF(W: number, precomputes: PC_P<PC>[], n: bigint): { p: PC_P<PC>; f: PC_P<PC> } {
|
|
308
|
+
// Scalar should be smaller than field order
|
|
309
|
+
if (!this.Fn.isValid(n)) throw new Error('invalid scalar');
|
|
310
|
+
// Accumulators
|
|
311
|
+
let p = this.ZERO;
|
|
312
|
+
let f = this.BASE;
|
|
313
|
+
// This code was first written with assumption that 'f' and 'p' will never be infinity point:
|
|
314
|
+
// since each addition is multiplied by 2 ** W, it cannot cancel each other. However,
|
|
315
|
+
// there is negate now: it is possible that negated element from low value
|
|
316
|
+
// would be the same as high element, which will create carry into next window.
|
|
317
|
+
// It's not obvious how this can fail, but still worth investigating later.
|
|
318
|
+
const wo = calcWOpts(W, this.bits);
|
|
319
|
+
for (let window = 0; window < wo.windows; window++) {
|
|
320
|
+
// (n === _0n) is handled and not early-exited. isEven and offsetF are used for noise
|
|
321
|
+
const { nextN, offset, isZero, isNeg, isNegF, offsetF } = calcOffsets(n, window, wo);
|
|
322
|
+
n = nextN;
|
|
323
|
+
if (isZero) {
|
|
324
|
+
// bits are 0: add garbage to fake point
|
|
325
|
+
// Important part for const-time getPublicKey: add random "noise" point to f.
|
|
326
|
+
f = f.add(negateCt(isNegF, precomputes[offsetF]));
|
|
327
|
+
} else {
|
|
328
|
+
// bits are 1: add to result point
|
|
329
|
+
p = p.add(negateCt(isNeg, precomputes[offset]));
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
assert0(n);
|
|
333
|
+
// Return both real and fake points: JIT won't eliminate f.
|
|
334
|
+
// At this point there is a way to F be infinity-point even if p is not,
|
|
335
|
+
// which makes it less const-time: around 1 bigint multiply.
|
|
336
|
+
return { p, f };
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
341
|
+
* @param acc accumulator point to add result of multiplication
|
|
342
|
+
* @returns point
|
|
343
|
+
*/
|
|
344
|
+
private wNAFUnsafe(
|
|
345
|
+
W: number,
|
|
346
|
+
precomputes: PC_P<PC>[],
|
|
347
|
+
n: bigint,
|
|
348
|
+
acc: PC_P<PC> = this.ZERO
|
|
349
|
+
): PC_P<PC> {
|
|
350
|
+
const wo = calcWOpts(W, this.bits);
|
|
351
|
+
for (let window = 0; window < wo.windows; window++) {
|
|
352
|
+
if (n === _0n) break; // Early-exit, skip 0 value
|
|
353
|
+
const { nextN, offset, isZero, isNeg } = calcOffsets(n, window, wo);
|
|
354
|
+
n = nextN;
|
|
355
|
+
if (isZero) {
|
|
356
|
+
// Window bits are 0: skip processing.
|
|
357
|
+
// Move to next window.
|
|
358
|
+
continue;
|
|
359
|
+
} else {
|
|
360
|
+
const item = precomputes[offset];
|
|
361
|
+
acc = acc.add(isNeg ? item.negate() : item); // Re-using acc allows to save adds in MSM
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
assert0(n);
|
|
365
|
+
return acc;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private getPrecomputes(W: number, point: PC_P<PC>, transform?: Mapper<PC_P<PC>>): PC_P<PC>[] {
|
|
369
|
+
// Calculate precomputes on a first run, reuse them after
|
|
370
|
+
let comp = pointPrecomputes.get(point);
|
|
371
|
+
if (!comp) {
|
|
372
|
+
comp = this.precomputeWindow(point, W) as PC_P<PC>[];
|
|
373
|
+
if (W !== 1) {
|
|
374
|
+
// Doing transform outside of if brings 15% perf hit
|
|
375
|
+
if (typeof transform === 'function') comp = transform(comp);
|
|
376
|
+
pointPrecomputes.set(point, comp);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return comp;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
cached(
|
|
383
|
+
point: PC_P<PC>,
|
|
384
|
+
scalar: bigint,
|
|
385
|
+
transform?: Mapper<PC_P<PC>>
|
|
386
|
+
): { p: PC_P<PC>; f: PC_P<PC> } {
|
|
387
|
+
const W = getW(point);
|
|
388
|
+
return this.wNAF(W, this.getPrecomputes(W, point, transform), scalar);
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
unsafe(point: PC_P<PC>, scalar: bigint, transform?: Mapper<PC_P<PC>>, prev?: PC_P<PC>): PC_P<PC> {
|
|
392
|
+
const W = getW(point);
|
|
393
|
+
if (W === 1) return this._unsafeLadder(point, scalar, prev); // For W=1 ladder is ~x2 faster
|
|
394
|
+
return this.wNAFUnsafe(W, this.getPrecomputes(W, point, transform), scalar, prev);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// We calculate precomputes for elliptic curve point multiplication
|
|
398
|
+
// using windowed method. This specifies window size and
|
|
399
|
+
// stores precomputed values. Usually only base point would be precomputed.
|
|
400
|
+
createCache(P: PC_P<PC>, W: number): void {
|
|
401
|
+
validateW(W, this.bits);
|
|
402
|
+
pointWindowSizes.set(P, W);
|
|
403
|
+
pointPrecomputes.delete(P);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
hasCache(elm: PC_P<PC>): boolean {
|
|
407
|
+
return getW(elm) !== 1;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Endomorphism-specific multiplication for Koblitz curves.
|
|
413
|
+
* Cost: 128 dbl, 0-256 adds.
|
|
414
|
+
*/
|
|
415
|
+
export function mulEndoUnsafe<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(
|
|
416
|
+
Point: PC,
|
|
417
|
+
point: P,
|
|
418
|
+
k1: bigint,
|
|
419
|
+
k2: bigint
|
|
420
|
+
): { p1: P; p2: P } {
|
|
421
|
+
let acc = point;
|
|
422
|
+
let p1 = Point.ZERO;
|
|
423
|
+
let p2 = Point.ZERO;
|
|
424
|
+
while (k1 > _0n || k2 > _0n) {
|
|
425
|
+
if (k1 & _1n) p1 = p1.add(acc);
|
|
426
|
+
if (k2 & _1n) p2 = p2.add(acc);
|
|
427
|
+
acc = acc.double();
|
|
428
|
+
k1 >>= _1n;
|
|
429
|
+
k2 >>= _1n;
|
|
430
|
+
}
|
|
431
|
+
return { p1, p2 };
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/**
|
|
435
|
+
* Pippenger algorithm for multi-scalar multiplication (MSM, Pa + Qb + Rc + ...).
|
|
436
|
+
* 30x faster vs naive addition on L=4096, 10x faster than precomputes.
|
|
437
|
+
* For N=254bit, L=1, it does: 1024 ADD + 254 DBL. For L=5: 1536 ADD + 254 DBL.
|
|
438
|
+
* Algorithmically constant-time (for same L), even when 1 point + scalar, or when scalar = 0.
|
|
439
|
+
* @param c Curve Point constructor
|
|
440
|
+
* @param fieldN field over CURVE.N - important that it's not over CURVE.P
|
|
441
|
+
* @param points array of L curve points
|
|
442
|
+
* @param scalars array of L scalars (aka secret keys / bigints)
|
|
443
|
+
*/
|
|
444
|
+
export function pippenger<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(
|
|
445
|
+
c: PC,
|
|
446
|
+
points: P[],
|
|
447
|
+
scalars: bigint[]
|
|
448
|
+
): P {
|
|
449
|
+
// If we split scalars by some window (let's say 8 bits), every chunk will only
|
|
450
|
+
// take 256 buckets even if there are 4096 scalars, also re-uses double.
|
|
451
|
+
// TODO:
|
|
452
|
+
// - https://eprint.iacr.org/2024/750.pdf
|
|
453
|
+
// - https://tches.iacr.org/index.php/TCHES/article/view/10287
|
|
454
|
+
// 0 is accepted in scalars
|
|
455
|
+
const fieldN = c.Fn;
|
|
456
|
+
validateMSMPoints(points, c);
|
|
457
|
+
validateMSMScalars(scalars, fieldN);
|
|
458
|
+
const plength = points.length;
|
|
459
|
+
const slength = scalars.length;
|
|
460
|
+
if (plength !== slength) throw new Error('arrays of points and scalars must have equal length');
|
|
461
|
+
// if (plength === 0) throw new Error('array must be of length >= 2');
|
|
462
|
+
const zero = c.ZERO;
|
|
463
|
+
const wbits = bitLen(BigInt(plength));
|
|
464
|
+
let windowSize = 1; // bits
|
|
465
|
+
if (wbits > 12) windowSize = wbits - 3;
|
|
466
|
+
else if (wbits > 4) windowSize = wbits - 2;
|
|
467
|
+
else if (wbits > 0) windowSize = 2;
|
|
468
|
+
const MASK = bitMask(windowSize);
|
|
469
|
+
const buckets = new Array(Number(MASK) + 1).fill(zero); // +1 for zero array
|
|
470
|
+
const lastBits = Math.floor((fieldN.BITS - 1) / windowSize) * windowSize;
|
|
471
|
+
let sum = zero;
|
|
472
|
+
for (let i = lastBits; i >= 0; i -= windowSize) {
|
|
473
|
+
buckets.fill(zero);
|
|
474
|
+
for (let j = 0; j < slength; j++) {
|
|
475
|
+
const scalar = scalars[j];
|
|
476
|
+
const wbits = Number((scalar >> BigInt(i)) & MASK);
|
|
477
|
+
buckets[wbits] = buckets[wbits].add(points[j]);
|
|
478
|
+
}
|
|
479
|
+
let resI = zero; // not using this will do small speed-up, but will lose ct
|
|
480
|
+
// Skip first bucket, because it is zero
|
|
481
|
+
for (let j = buckets.length - 1, sumI = zero; j > 0; j--) {
|
|
482
|
+
sumI = sumI.add(buckets[j]);
|
|
483
|
+
resI = resI.add(sumI);
|
|
484
|
+
}
|
|
485
|
+
sum = sum.add(resI);
|
|
486
|
+
if (i !== 0) for (let j = 0; j < windowSize; j++) sum = sum.double();
|
|
487
|
+
}
|
|
488
|
+
return sum as P;
|
|
489
|
+
}
|
|
490
|
+
/**
|
|
491
|
+
* Precomputed multi-scalar multiplication (MSM, Pa + Qb + Rc + ...).
|
|
492
|
+
* @param c Curve Point constructor
|
|
493
|
+
* @param fieldN field over CURVE.N - important that it's not over CURVE.P
|
|
494
|
+
* @param points array of L curve points
|
|
495
|
+
* @returns function which multiplies points with scaars
|
|
496
|
+
*/
|
|
497
|
+
export function precomputeMSMUnsafe<P extends CurvePoint<any, P>, PC extends CurvePointCons<P>>(
|
|
498
|
+
c: PC,
|
|
499
|
+
points: P[],
|
|
500
|
+
windowSize: number
|
|
501
|
+
): (scalars: bigint[]) => P {
|
|
502
|
+
/**
|
|
503
|
+
* Performance Analysis of Window-based Precomputation
|
|
504
|
+
*
|
|
505
|
+
* Base Case (256-bit scalar, 8-bit window):
|
|
506
|
+
* - Standard precomputation requires:
|
|
507
|
+
* - 31 additions per scalar × 256 scalars = 7,936 ops
|
|
508
|
+
* - Plus 255 summary additions = 8,191 total ops
|
|
509
|
+
* Note: Summary additions can be optimized via accumulator
|
|
510
|
+
*
|
|
511
|
+
* Chunked Precomputation Analysis:
|
|
512
|
+
* - Using 32 chunks requires:
|
|
513
|
+
* - 255 additions per chunk
|
|
514
|
+
* - 256 doublings
|
|
515
|
+
* - Total: (255 × 32) + 256 = 8,416 ops
|
|
516
|
+
*
|
|
517
|
+
* Memory Usage Comparison:
|
|
518
|
+
* Window Size | Standard Points | Chunked Points
|
|
519
|
+
* ------------|-----------------|---------------
|
|
520
|
+
* 4-bit | 520 | 15
|
|
521
|
+
* 8-bit | 4,224 | 255
|
|
522
|
+
* 10-bit | 13,824 | 1,023
|
|
523
|
+
* 16-bit | 557,056 | 65,535
|
|
524
|
+
*
|
|
525
|
+
* Key Advantages:
|
|
526
|
+
* 1. Enables larger window sizes due to reduced memory overhead
|
|
527
|
+
* 2. More efficient for smaller scalar counts:
|
|
528
|
+
* - 16 chunks: (16 × 255) + 256 = 4,336 ops
|
|
529
|
+
* - ~2x faster than standard 8,191 ops
|
|
530
|
+
*
|
|
531
|
+
* Limitations:
|
|
532
|
+
* - Not suitable for plain precomputes (requires 256 constant doublings)
|
|
533
|
+
* - Performance degrades with larger scalar counts:
|
|
534
|
+
* - Optimal for ~256 scalars
|
|
535
|
+
* - Less efficient for 4096+ scalars (Pippenger preferred)
|
|
536
|
+
*/
|
|
537
|
+
const fieldN = c.Fn;
|
|
538
|
+
validateW(windowSize, fieldN.BITS);
|
|
539
|
+
validateMSMPoints(points, c);
|
|
540
|
+
const zero = c.ZERO;
|
|
541
|
+
const tableSize = 2 ** windowSize - 1; // table size (without zero)
|
|
542
|
+
const chunks = Math.ceil(fieldN.BITS / windowSize); // chunks of item
|
|
543
|
+
const MASK = bitMask(windowSize);
|
|
544
|
+
const tables = points.map((p: P) => {
|
|
545
|
+
const res = [];
|
|
546
|
+
for (let i = 0, acc = p; i < tableSize; i++) {
|
|
547
|
+
res.push(acc);
|
|
548
|
+
acc = acc.add(p);
|
|
549
|
+
}
|
|
550
|
+
return res;
|
|
551
|
+
});
|
|
552
|
+
return (scalars: bigint[]): P => {
|
|
553
|
+
validateMSMScalars(scalars, fieldN);
|
|
554
|
+
if (scalars.length > points.length)
|
|
555
|
+
throw new Error('array of scalars must be smaller than array of points');
|
|
556
|
+
let res = zero;
|
|
557
|
+
for (let i = 0; i < chunks; i++) {
|
|
558
|
+
// No need to double if accumulator is still zero.
|
|
559
|
+
if (res !== zero) for (let j = 0; j < windowSize; j++) res = res.double();
|
|
560
|
+
const shiftBy = BigInt(chunks * windowSize - (i + 1) * windowSize);
|
|
561
|
+
for (let j = 0; j < scalars.length; j++) {
|
|
562
|
+
const n = scalars[j];
|
|
563
|
+
const curr = Number((n >> shiftBy) & MASK);
|
|
564
|
+
if (!curr) continue; // skip zero scalars chunks
|
|
565
|
+
res = res.add(tables[j][curr - 1]);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
return res;
|
|
569
|
+
};
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
export type ValidCurveParams<T> = {
|
|
573
|
+
p: bigint;
|
|
574
|
+
n: bigint;
|
|
575
|
+
h: bigint;
|
|
576
|
+
a: T;
|
|
577
|
+
b?: T;
|
|
578
|
+
d?: T;
|
|
579
|
+
Gx: T;
|
|
580
|
+
Gy: T;
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
function createField<T>(order: bigint, field?: IField<T>, isLE?: boolean): IField<T> {
|
|
584
|
+
if (field) {
|
|
585
|
+
if (field.ORDER !== order) throw new Error('Field.ORDER must match order: Fp == p, Fn == n');
|
|
586
|
+
validateField(field);
|
|
587
|
+
return field;
|
|
588
|
+
} else {
|
|
589
|
+
return Field(order, { isLE }) as unknown as IField<T>;
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
export type FpFn<T> = { Fp: IField<T>; Fn: IField<bigint> };
|
|
593
|
+
|
|
594
|
+
/** Validates CURVE opts and creates fields */
|
|
595
|
+
export function createCurveFields<T>(
|
|
596
|
+
type: 'weierstrass' | 'edwards',
|
|
597
|
+
CURVE: ValidCurveParams<T>,
|
|
598
|
+
curveOpts: Partial<FpFn<T>> = {},
|
|
599
|
+
FpFnLE?: boolean
|
|
600
|
+
): FpFn<T> & { CURVE: ValidCurveParams<T> } {
|
|
601
|
+
if (FpFnLE === undefined) FpFnLE = type === 'edwards';
|
|
602
|
+
if (!CURVE || typeof CURVE !== 'object') throw new Error(`expected valid ${type} CURVE object`);
|
|
603
|
+
for (const p of ['p', 'n', 'h'] as const) {
|
|
604
|
+
const val = CURVE[p];
|
|
605
|
+
if (!(typeof val === 'bigint' && val > _0n))
|
|
606
|
+
throw new Error(`CURVE.${p} must be positive bigint`);
|
|
607
|
+
}
|
|
608
|
+
const Fp = createField(CURVE.p, curveOpts.Fp, FpFnLE);
|
|
609
|
+
const Fn = createField(CURVE.n, curveOpts.Fn, FpFnLE);
|
|
610
|
+
const _b: 'b' | 'd' = type === 'weierstrass' ? 'b' : 'd';
|
|
611
|
+
const params = ['Gx', 'Gy', 'a', _b] as const;
|
|
612
|
+
for (const p of params) {
|
|
613
|
+
// @ts-ignore
|
|
614
|
+
if (!Fp.isValid(CURVE[p]))
|
|
615
|
+
throw new Error(`CURVE.${p} must be valid field element of CURVE.Fp`);
|
|
616
|
+
}
|
|
617
|
+
CURVE = Object.freeze(Object.assign({}, CURVE));
|
|
618
|
+
return { CURVE, Fp, Fn };
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
type KeygenFn = (
|
|
622
|
+
seed?: Uint8Array,
|
|
623
|
+
isCompressed?: boolean
|
|
624
|
+
) => { secretKey: Uint8Array; publicKey: Uint8Array };
|
|
625
|
+
export function createKeygen(
|
|
626
|
+
randomSecretKey: Function,
|
|
627
|
+
getPublicKey: Signer['getPublicKey']
|
|
628
|
+
): KeygenFn {
|
|
629
|
+
return function keygen(seed?: Uint8Array) {
|
|
630
|
+
const secretKey = randomSecretKey(seed);
|
|
631
|
+
return { secretKey, publicKey: getPublicKey(secretKey) };
|
|
632
|
+
};
|
|
633
|
+
}
|