@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,327 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SECG secp256k1. See [pdf](https://www.secg.org/sec2-v2.pdf).
|
|
3
|
+
*
|
|
4
|
+
* Belongs to Koblitz curves: it has efficiently-computable GLV endomorphism ψ,
|
|
5
|
+
* check out {@link EndomorphismOpts}. Seems to be rigid (not backdoored).
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
+
import { sha256 } from '../../../hashes/2.0.1/src/sha2.js';
|
|
10
|
+
import { randomBytes } from '../../../hashes/2.0.1/src/utils.js';
|
|
11
|
+
import { createKeygen, type CurveLengths } from './abstract/curve.js';
|
|
12
|
+
import { createHasher, type H2CHasher, isogenyMap } from './abstract/hash-to-curve.js';
|
|
13
|
+
import { Field, mapHashToField, pow2 } from './abstract/modular.js';
|
|
14
|
+
import {
|
|
15
|
+
type ECDSA,
|
|
16
|
+
ecdsa,
|
|
17
|
+
type EndomorphismOpts,
|
|
18
|
+
mapToCurveSimpleSWU,
|
|
19
|
+
type WeierstrassPoint as PointType,
|
|
20
|
+
weierstrass,
|
|
21
|
+
type WeierstrassOpts,
|
|
22
|
+
type WeierstrassPointCons,
|
|
23
|
+
} from './abstract/weierstrass.js';
|
|
24
|
+
import { abytes, asciiToBytes, bytesToNumberBE, concatBytes } from './utils.js';
|
|
25
|
+
|
|
26
|
+
// Seems like generator was produced from some seed:
|
|
27
|
+
// `Pointk1.BASE.multiply(Pointk1.Fn.inv(2n, N)).toAffine().x`
|
|
28
|
+
// // gives short x 0x3b78ce563f89a0ed9414f5aa28ad0d96d6795f9c63n
|
|
29
|
+
const secp256k1_CURVE: WeierstrassOpts<bigint> = {
|
|
30
|
+
p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'),
|
|
31
|
+
n: BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'),
|
|
32
|
+
h: BigInt(1),
|
|
33
|
+
a: BigInt(0),
|
|
34
|
+
b: BigInt(7),
|
|
35
|
+
Gx: BigInt('0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
36
|
+
Gy: BigInt('0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'),
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const secp256k1_ENDO: EndomorphismOpts = {
|
|
40
|
+
beta: BigInt('0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee'),
|
|
41
|
+
basises: [
|
|
42
|
+
[BigInt('0x3086d221a7d46bcde86c90e49284eb15'), -BigInt('0xe4437ed6010e88286f547fa90abfe4c3')],
|
|
43
|
+
[BigInt('0x114ca50f7a8e2f3f657c1108d9d44cfd8'), BigInt('0x3086d221a7d46bcde86c90e49284eb15')],
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
48
|
+
const _2n = /* @__PURE__ */ BigInt(2);
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
|
|
52
|
+
* (P+1n/4n).toString(2) would produce bits [223x 1, 0, 22x 1, 4x 0, 11, 00]
|
|
53
|
+
*/
|
|
54
|
+
function sqrtMod(y: bigint): bigint {
|
|
55
|
+
const P = secp256k1_CURVE.p;
|
|
56
|
+
// prettier-ignore
|
|
57
|
+
const _3n = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
58
|
+
// prettier-ignore
|
|
59
|
+
const _23n = BigInt(23), _44n = BigInt(44), _88n = BigInt(88);
|
|
60
|
+
const b2 = (y * y * y) % P; // x^3, 11
|
|
61
|
+
const b3 = (b2 * b2 * y) % P; // x^7
|
|
62
|
+
const b6 = (pow2(b3, _3n, P) * b3) % P;
|
|
63
|
+
const b9 = (pow2(b6, _3n, P) * b3) % P;
|
|
64
|
+
const b11 = (pow2(b9, _2n, P) * b2) % P;
|
|
65
|
+
const b22 = (pow2(b11, _11n, P) * b11) % P;
|
|
66
|
+
const b44 = (pow2(b22, _22n, P) * b22) % P;
|
|
67
|
+
const b88 = (pow2(b44, _44n, P) * b44) % P;
|
|
68
|
+
const b176 = (pow2(b88, _88n, P) * b88) % P;
|
|
69
|
+
const b220 = (pow2(b176, _44n, P) * b44) % P;
|
|
70
|
+
const b223 = (pow2(b220, _3n, P) * b3) % P;
|
|
71
|
+
const t1 = (pow2(b223, _23n, P) * b22) % P;
|
|
72
|
+
const t2 = (pow2(t1, _6n, P) * b2) % P;
|
|
73
|
+
const root = pow2(t2, _2n, P);
|
|
74
|
+
if (!Fpk1.eql(Fpk1.sqr(root), y)) throw new Error('Cannot find square root');
|
|
75
|
+
return root;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const Fpk1 = Field(secp256k1_CURVE.p, { sqrt: sqrtMod });
|
|
79
|
+
const Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
|
|
80
|
+
Fp: Fpk1,
|
|
81
|
+
endo: secp256k1_ENDO,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* secp256k1 curve: ECDSA and ECDH methods.
|
|
86
|
+
*
|
|
87
|
+
* Uses sha256 to hash messages. To use a different hash,
|
|
88
|
+
* pass `{ prehash: false }` to sign / verify.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```js
|
|
92
|
+
* import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
93
|
+
* const { secretKey, publicKey } = secp256k1.keygen();
|
|
94
|
+
* // const publicKey = secp256k1.getPublicKey(secretKey);
|
|
95
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
96
|
+
* const sig = secp256k1.sign(msg, secretKey);
|
|
97
|
+
* const isValid = secp256k1.verify(sig, msg, publicKey);
|
|
98
|
+
* // const sigKeccak = secp256k1.sign(keccak256(msg), secretKey, { prehash: false });
|
|
99
|
+
* ```
|
|
100
|
+
*/
|
|
101
|
+
export const secp256k1: ECDSA = /* @__PURE__ */ ecdsa(Pointk1, sha256);
|
|
102
|
+
|
|
103
|
+
// Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
|
|
104
|
+
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
105
|
+
/** An object mapping tags to their tagged hash prefix of [SHA256(tag) | SHA256(tag)] */
|
|
106
|
+
const TAGGED_HASH_PREFIXES: { [tag: string]: Uint8Array } = {};
|
|
107
|
+
function taggedHash(tag: string, ...messages: Uint8Array[]): Uint8Array {
|
|
108
|
+
let tagP = TAGGED_HASH_PREFIXES[tag];
|
|
109
|
+
if (tagP === undefined) {
|
|
110
|
+
const tagH = sha256(asciiToBytes(tag));
|
|
111
|
+
tagP = concatBytes(tagH, tagH);
|
|
112
|
+
TAGGED_HASH_PREFIXES[tag] = tagP;
|
|
113
|
+
}
|
|
114
|
+
return sha256(concatBytes(tagP, ...messages));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ECDSA compact points are 33-byte. Schnorr is 32: we strip first byte 0x02 or 0x03
|
|
118
|
+
const pointToBytes = (point: PointType<bigint>) => point.toBytes(true).slice(1);
|
|
119
|
+
const hasEven = (y: bigint) => y % _2n === _0n;
|
|
120
|
+
|
|
121
|
+
// Calculate point, scalar and bytes
|
|
122
|
+
function schnorrGetExtPubKey(priv: Uint8Array) {
|
|
123
|
+
const { Fn, BASE } = Pointk1;
|
|
124
|
+
const d_ = Fn.fromBytes(priv);
|
|
125
|
+
const p = BASE.multiply(d_); // P = d'⋅G; 0 < d' < n check is done inside
|
|
126
|
+
const scalar = hasEven(p.y) ? d_ : Fn.neg(d_);
|
|
127
|
+
return { scalar, bytes: pointToBytes(p) };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* lift_x from BIP340. Convert 32-byte x coordinate to elliptic curve point.
|
|
131
|
+
* @returns valid point checked for being on-curve
|
|
132
|
+
*/
|
|
133
|
+
function lift_x(x: bigint): PointType<bigint> {
|
|
134
|
+
const Fp = Fpk1;
|
|
135
|
+
if (!Fp.isValidNot0(x)) throw new Error('invalid x: Fail if x ≥ p');
|
|
136
|
+
const xx = Fp.create(x * x);
|
|
137
|
+
const c = Fp.create(xx * x + BigInt(7)); // Let c = x³ + 7 mod p.
|
|
138
|
+
let y = Fp.sqrt(c); // Let y = c^(p+1)/4 mod p. Same as sqrt().
|
|
139
|
+
// Return the unique point P such that x(P) = x and
|
|
140
|
+
// y(P) = y if y mod 2 = 0 or y(P) = p-y otherwise.
|
|
141
|
+
if (!hasEven(y)) y = Fp.neg(y);
|
|
142
|
+
const p = Pointk1.fromAffine({ x, y });
|
|
143
|
+
p.assertValidity();
|
|
144
|
+
return p;
|
|
145
|
+
}
|
|
146
|
+
const num = bytesToNumberBE;
|
|
147
|
+
/**
|
|
148
|
+
* Create tagged hash, convert it to bigint, reduce modulo-n.
|
|
149
|
+
*/
|
|
150
|
+
function challenge(...args: Uint8Array[]): bigint {
|
|
151
|
+
return Pointk1.Fn.create(num(taggedHash('BIP0340/challenge', ...args)));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Schnorr public key is just `x` coordinate of Point as per BIP340.
|
|
156
|
+
*/
|
|
157
|
+
function schnorrGetPublicKey(secretKey: Uint8Array): Uint8Array {
|
|
158
|
+
return schnorrGetExtPubKey(secretKey).bytes; // d'=int(sk). Fail if d'=0 or d'≥n. Ret bytes(d'⋅G)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Creates Schnorr signature as per BIP340. Verifies itself before returning anything.
|
|
163
|
+
* auxRand is optional and is not the sole source of k generation: bad CSPRNG won't be dangerous.
|
|
164
|
+
*/
|
|
165
|
+
function schnorrSign(
|
|
166
|
+
message: Uint8Array,
|
|
167
|
+
secretKey: Uint8Array,
|
|
168
|
+
auxRand: Uint8Array = randomBytes(32)
|
|
169
|
+
): Uint8Array {
|
|
170
|
+
const { Fn } = Pointk1;
|
|
171
|
+
const m = abytes(message, undefined, 'message');
|
|
172
|
+
const { bytes: px, scalar: d } = schnorrGetExtPubKey(secretKey); // checks for isWithinCurveOrder
|
|
173
|
+
const a = abytes(auxRand, 32, 'auxRand'); // Auxiliary random data a: a 32-byte array
|
|
174
|
+
const t = Fn.toBytes(d ^ num(taggedHash('BIP0340/aux', a))); // Let t be the byte-wise xor of bytes(d) and hash/aux(a)
|
|
175
|
+
const rand = taggedHash('BIP0340/nonce', t, px, m); // Let rand = hash/nonce(t || bytes(P) || m)
|
|
176
|
+
// Let k' = int(rand) mod n. Fail if k' = 0. Let R = k'⋅G
|
|
177
|
+
const { bytes: rx, scalar: k } = schnorrGetExtPubKey(rand);
|
|
178
|
+
const e = challenge(rx, px, m); // Let e = int(hash/challenge(bytes(R) || bytes(P) || m)) mod n.
|
|
179
|
+
const sig = new Uint8Array(64); // Let sig = bytes(R) || bytes((k + ed) mod n).
|
|
180
|
+
sig.set(rx, 0);
|
|
181
|
+
sig.set(Fn.toBytes(Fn.create(k + e * d)), 32);
|
|
182
|
+
// If Verify(bytes(P), m, sig) (see below) returns failure, abort
|
|
183
|
+
if (!schnorrVerify(sig, m, px)) throw new Error('sign: Invalid signature produced');
|
|
184
|
+
return sig;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Verifies Schnorr signature.
|
|
189
|
+
* Will swallow errors & return false except for initial type validation of arguments.
|
|
190
|
+
*/
|
|
191
|
+
function schnorrVerify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean {
|
|
192
|
+
const { Fp, Fn, BASE } = Pointk1;
|
|
193
|
+
const sig = abytes(signature, 64, 'signature');
|
|
194
|
+
const m = abytes(message, undefined, 'message');
|
|
195
|
+
const pub = abytes(publicKey, 32, 'publicKey');
|
|
196
|
+
try {
|
|
197
|
+
const P = lift_x(num(pub)); // P = lift_x(int(pk)); fail if that fails
|
|
198
|
+
const r = num(sig.subarray(0, 32)); // Let r = int(sig[0:32]); fail if r ≥ p.
|
|
199
|
+
if (!Fp.isValidNot0(r)) return false;
|
|
200
|
+
const s = num(sig.subarray(32, 64)); // Let s = int(sig[32:64]); fail if s ≥ n.
|
|
201
|
+
if (!Fn.isValidNot0(s)) return false;
|
|
202
|
+
|
|
203
|
+
const e = challenge(Fn.toBytes(r), pointToBytes(P), m); // int(challenge(bytes(r)||bytes(P)||m))%n
|
|
204
|
+
// R = s⋅G - e⋅P, where -eP == (n-e)P
|
|
205
|
+
const R = BASE.multiplyUnsafe(s).add(P.multiplyUnsafe(Fn.neg(e)));
|
|
206
|
+
const { x, y } = R.toAffine();
|
|
207
|
+
// Fail if is_infinite(R) / not has_even_y(R) / x(R) ≠ r.
|
|
208
|
+
if (R.is0() || !hasEven(y) || x !== r) return false;
|
|
209
|
+
return true;
|
|
210
|
+
} catch (error) {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export type SecpSchnorr = {
|
|
216
|
+
keygen: (seed?: Uint8Array) => { secretKey: Uint8Array; publicKey: Uint8Array };
|
|
217
|
+
getPublicKey: typeof schnorrGetPublicKey;
|
|
218
|
+
sign: typeof schnorrSign;
|
|
219
|
+
verify: typeof schnorrVerify;
|
|
220
|
+
Point: WeierstrassPointCons<bigint>;
|
|
221
|
+
utils: {
|
|
222
|
+
randomSecretKey: (seed?: Uint8Array) => Uint8Array;
|
|
223
|
+
pointToBytes: (point: PointType<bigint>) => Uint8Array;
|
|
224
|
+
lift_x: typeof lift_x;
|
|
225
|
+
taggedHash: typeof taggedHash;
|
|
226
|
+
};
|
|
227
|
+
lengths: CurveLengths;
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Schnorr signatures over secp256k1.
|
|
231
|
+
* https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
232
|
+
* @example
|
|
233
|
+
* ```js
|
|
234
|
+
* import { schnorr } from '@noble/curves/secp256k1.js';
|
|
235
|
+
* const { secretKey, publicKey } = schnorr.keygen();
|
|
236
|
+
* // const publicKey = schnorr.getPublicKey(secretKey);
|
|
237
|
+
* const msg = new TextEncoder().encode('hello');
|
|
238
|
+
* const sig = schnorr.sign(msg, secretKey);
|
|
239
|
+
* const isValid = schnorr.verify(sig, msg, publicKey);
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export const schnorr: SecpSchnorr = /* @__PURE__ */ (() => {
|
|
243
|
+
const size = 32;
|
|
244
|
+
const seedLength = 48;
|
|
245
|
+
const randomSecretKey = (seed = randomBytes(seedLength)): Uint8Array => {
|
|
246
|
+
return mapHashToField(seed, secp256k1_CURVE.n);
|
|
247
|
+
};
|
|
248
|
+
return {
|
|
249
|
+
keygen: createKeygen(randomSecretKey, schnorrGetPublicKey),
|
|
250
|
+
getPublicKey: schnorrGetPublicKey,
|
|
251
|
+
sign: schnorrSign,
|
|
252
|
+
verify: schnorrVerify,
|
|
253
|
+
Point: Pointk1,
|
|
254
|
+
utils: {
|
|
255
|
+
randomSecretKey,
|
|
256
|
+
taggedHash,
|
|
257
|
+
lift_x,
|
|
258
|
+
pointToBytes,
|
|
259
|
+
},
|
|
260
|
+
lengths: {
|
|
261
|
+
secretKey: size,
|
|
262
|
+
publicKey: size,
|
|
263
|
+
publicKeyHasPrefix: false,
|
|
264
|
+
signature: size * 2,
|
|
265
|
+
seed: seedLength,
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
})();
|
|
269
|
+
|
|
270
|
+
const isoMap = /* @__PURE__ */ (() =>
|
|
271
|
+
isogenyMap(
|
|
272
|
+
Fpk1,
|
|
273
|
+
[
|
|
274
|
+
// xNum
|
|
275
|
+
[
|
|
276
|
+
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7',
|
|
277
|
+
'0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581',
|
|
278
|
+
'0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262',
|
|
279
|
+
'0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c',
|
|
280
|
+
],
|
|
281
|
+
// xDen
|
|
282
|
+
[
|
|
283
|
+
'0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b',
|
|
284
|
+
'0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14',
|
|
285
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
286
|
+
],
|
|
287
|
+
// yNum
|
|
288
|
+
[
|
|
289
|
+
'0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c',
|
|
290
|
+
'0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3',
|
|
291
|
+
'0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931',
|
|
292
|
+
'0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84',
|
|
293
|
+
],
|
|
294
|
+
// yDen
|
|
295
|
+
[
|
|
296
|
+
'0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b',
|
|
297
|
+
'0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573',
|
|
298
|
+
'0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f',
|
|
299
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001', // LAST 1
|
|
300
|
+
],
|
|
301
|
+
].map((i) => i.map((j) => BigInt(j))) as [bigint[], bigint[], bigint[], bigint[]]
|
|
302
|
+
))();
|
|
303
|
+
const mapSWU = /* @__PURE__ */ (() =>
|
|
304
|
+
mapToCurveSimpleSWU(Fpk1, {
|
|
305
|
+
A: BigInt('0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533'),
|
|
306
|
+
B: BigInt('1771'),
|
|
307
|
+
Z: Fpk1.create(BigInt('-11')),
|
|
308
|
+
}))();
|
|
309
|
+
|
|
310
|
+
/** Hashing / encoding to secp256k1 points / field. RFC 9380 methods. */
|
|
311
|
+
export const secp256k1_hasher: H2CHasher<WeierstrassPointCons<bigint>> = /* @__PURE__ */ (() =>
|
|
312
|
+
createHasher(
|
|
313
|
+
Pointk1,
|
|
314
|
+
(scalars: bigint[]) => {
|
|
315
|
+
const { x, y } = mapSWU(Fpk1.create(scalars[0]));
|
|
316
|
+
return isoMap(x, y);
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
DST: 'secp256k1_XMD:SHA-256_SSWU_RO_',
|
|
320
|
+
encodeDST: 'secp256k1_XMD:SHA-256_SSWU_NU_',
|
|
321
|
+
p: Fpk1.ORDER,
|
|
322
|
+
m: 1,
|
|
323
|
+
k: 128,
|
|
324
|
+
expand: 'xmd',
|
|
325
|
+
hash: sha256,
|
|
326
|
+
}
|
|
327
|
+
))();
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hex, bytes and number utilities.
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
6
|
+
import {
|
|
7
|
+
abytes as abytes_,
|
|
8
|
+
anumber,
|
|
9
|
+
bytesToHex as bytesToHex_,
|
|
10
|
+
concatBytes as concatBytes_,
|
|
11
|
+
hexToBytes as hexToBytes_,
|
|
12
|
+
} from '../../../hashes/2.0.1/src/utils.js';
|
|
13
|
+
export {
|
|
14
|
+
abytes,
|
|
15
|
+
anumber,
|
|
16
|
+
bytesToHex,
|
|
17
|
+
concatBytes,
|
|
18
|
+
hexToBytes,
|
|
19
|
+
isBytes,
|
|
20
|
+
randomBytes,
|
|
21
|
+
} from '../../../hashes/2.0.1/src/utils.js';
|
|
22
|
+
const _0n = /* @__PURE__ */ BigInt(0);
|
|
23
|
+
const _1n = /* @__PURE__ */ BigInt(1);
|
|
24
|
+
|
|
25
|
+
export type CHash = {
|
|
26
|
+
(message: Uint8Array): Uint8Array;
|
|
27
|
+
blockLen: number;
|
|
28
|
+
outputLen: number;
|
|
29
|
+
create(opts?: { dkLen?: number }): any; // For shake
|
|
30
|
+
};
|
|
31
|
+
export type FHash = (message: Uint8Array) => Uint8Array;
|
|
32
|
+
export function abool(value: boolean, title: string = ''): boolean {
|
|
33
|
+
if (typeof value !== 'boolean') {
|
|
34
|
+
const prefix = title && `"${title}" `;
|
|
35
|
+
throw new Error(prefix + 'expected boolean, got type=' + typeof value);
|
|
36
|
+
}
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Used in weierstrass, der
|
|
41
|
+
function abignumber(n: number | bigint) {
|
|
42
|
+
if (typeof n === 'bigint') {
|
|
43
|
+
if (!isPosBig(n)) throw new Error('positive bigint expected, got ' + n);
|
|
44
|
+
} else anumber(n);
|
|
45
|
+
return n;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function asafenumber(value: number, title: string = ''): void {
|
|
49
|
+
if (!Number.isSafeInteger(value)) {
|
|
50
|
+
const prefix = title && `"${title}" `;
|
|
51
|
+
throw new Error(prefix + 'expected safe integer, got type=' + typeof value);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export function numberToHexUnpadded(num: number | bigint): string {
|
|
56
|
+
const hex = abignumber(num).toString(16);
|
|
57
|
+
return hex.length & 1 ? '0' + hex : hex;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function hexToNumber(hex: string): bigint {
|
|
61
|
+
if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);
|
|
62
|
+
return hex === '' ? _0n : BigInt('0x' + hex); // Big Endian
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// BE: Big Endian, LE: Little Endian
|
|
66
|
+
export function bytesToNumberBE(bytes: Uint8Array): bigint {
|
|
67
|
+
return hexToNumber(bytesToHex_(bytes));
|
|
68
|
+
}
|
|
69
|
+
export function bytesToNumberLE(bytes: Uint8Array): bigint {
|
|
70
|
+
return hexToNumber(bytesToHex_(copyBytes(abytes_(bytes)).reverse()));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function numberToBytesBE(n: number | bigint, len: number): Uint8Array {
|
|
74
|
+
anumber(len);
|
|
75
|
+
n = abignumber(n);
|
|
76
|
+
const res = hexToBytes_(n.toString(16).padStart(len * 2, '0'));
|
|
77
|
+
if (res.length !== len) throw new Error('number too large');
|
|
78
|
+
return res;
|
|
79
|
+
}
|
|
80
|
+
export function numberToBytesLE(n: number | bigint, len: number): Uint8Array {
|
|
81
|
+
return numberToBytesBE(n, len).reverse();
|
|
82
|
+
}
|
|
83
|
+
// Unpadded, rarely used
|
|
84
|
+
export function numberToVarBytesBE(n: number | bigint): Uint8Array {
|
|
85
|
+
return hexToBytes_(numberToHexUnpadded(abignumber(n)));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Compares 2 u8a-s in kinda constant time
|
|
89
|
+
export function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
|
|
90
|
+
if (a.length !== b.length) return false;
|
|
91
|
+
let diff = 0;
|
|
92
|
+
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
|
93
|
+
return diff === 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Copies Uint8Array. We can't use u8a.slice(), because u8a can be Buffer,
|
|
98
|
+
* and Buffer#slice creates mutable copy. Never use Buffers!
|
|
99
|
+
*/
|
|
100
|
+
export function copyBytes(bytes: Uint8Array): Uint8Array {
|
|
101
|
+
return Uint8Array.from(bytes);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Decodes 7-bit ASCII string to Uint8Array, throws on non-ascii symbols
|
|
106
|
+
* Should be safe to use for things expected to be ASCII.
|
|
107
|
+
* Returns exact same result as `TextEncoder` for ASCII or throws.
|
|
108
|
+
*/
|
|
109
|
+
export function asciiToBytes(ascii: string): Uint8Array {
|
|
110
|
+
return Uint8Array.from(ascii, (c, i) => {
|
|
111
|
+
const charCode = c.charCodeAt(0);
|
|
112
|
+
if (c.length !== 1 || charCode > 127) {
|
|
113
|
+
throw new Error(
|
|
114
|
+
`string contains non-ASCII character "${ascii[i]}" with code ${charCode} at position ${i}`
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
return charCode;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Is positive bigint
|
|
122
|
+
const isPosBig = (n: bigint) => typeof n === 'bigint' && _0n <= n;
|
|
123
|
+
|
|
124
|
+
export function inRange(n: bigint, min: bigint, max: bigint): boolean {
|
|
125
|
+
return isPosBig(n) && isPosBig(min) && isPosBig(max) && min <= n && n < max;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Asserts min <= n < max. NOTE: It's < max and not <= max.
|
|
130
|
+
* @example
|
|
131
|
+
* aInRange('x', x, 1n, 256n); // would assume x is in (1n..255n)
|
|
132
|
+
*/
|
|
133
|
+
export function aInRange(title: string, n: bigint, min: bigint, max: bigint): void {
|
|
134
|
+
// Why min <= n < max and not a (min < n < max) OR b (min <= n <= max)?
|
|
135
|
+
// consider P=256n, min=0n, max=P
|
|
136
|
+
// - a for min=0 would require -1: `inRange('x', x, -1n, P)`
|
|
137
|
+
// - b would commonly require subtraction: `inRange('x', x, 0n, P - 1n)`
|
|
138
|
+
// - our way is the cleanest: `inRange('x', x, 0n, P)
|
|
139
|
+
if (!inRange(n, min, max))
|
|
140
|
+
throw new Error('expected valid ' + title + ': ' + min + ' <= n < ' + max + ', got ' + n);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Bit operations
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Calculates amount of bits in a bigint.
|
|
147
|
+
* Same as `n.toString(2).length`
|
|
148
|
+
* TODO: merge with nLength in modular
|
|
149
|
+
*/
|
|
150
|
+
export function bitLen(n: bigint): number {
|
|
151
|
+
let len;
|
|
152
|
+
for (len = 0; n > _0n; n >>= _1n, len += 1);
|
|
153
|
+
return len;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Gets single bit at position.
|
|
158
|
+
* NOTE: first bit position is 0 (same as arrays)
|
|
159
|
+
* Same as `!!+Array.from(n.toString(2)).reverse()[pos]`
|
|
160
|
+
*/
|
|
161
|
+
export function bitGet(n: bigint, pos: number): bigint {
|
|
162
|
+
return (n >> BigInt(pos)) & _1n;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Sets single bit at position.
|
|
167
|
+
*/
|
|
168
|
+
export function bitSet(n: bigint, pos: number, value: boolean): bigint {
|
|
169
|
+
return n | ((value ? _1n : _0n) << BigInt(pos));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Calculate mask for N bits. Not using ** operator with bigints because of old engines.
|
|
174
|
+
* Same as BigInt(`0b${Array(i).fill('1').join('')}`)
|
|
175
|
+
*/
|
|
176
|
+
export const bitMask = (n: number): bigint => (_1n << BigInt(n)) - _1n;
|
|
177
|
+
|
|
178
|
+
// DRBG
|
|
179
|
+
|
|
180
|
+
type Pred<T> = (v: Uint8Array) => T | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Minimal HMAC-DRBG from NIST 800-90 for RFC6979 sigs.
|
|
183
|
+
* @returns function that will call DRBG until 2nd arg returns something meaningful
|
|
184
|
+
* @example
|
|
185
|
+
* const drbg = createHmacDRBG<Key>(32, 32, hmac);
|
|
186
|
+
* drbg(seed, bytesToKey); // bytesToKey must return Key or undefined
|
|
187
|
+
*/
|
|
188
|
+
export function createHmacDrbg<T>(
|
|
189
|
+
hashLen: number,
|
|
190
|
+
qByteLen: number,
|
|
191
|
+
hmacFn: (key: Uint8Array, message: Uint8Array) => Uint8Array
|
|
192
|
+
): (seed: Uint8Array, predicate: Pred<T>) => T {
|
|
193
|
+
anumber(hashLen, 'hashLen');
|
|
194
|
+
anumber(qByteLen, 'qByteLen');
|
|
195
|
+
if (typeof hmacFn !== 'function') throw new Error('hmacFn must be a function');
|
|
196
|
+
const u8n = (len: number): Uint8Array => new Uint8Array(len); // creates Uint8Array
|
|
197
|
+
const NULL = Uint8Array.of();
|
|
198
|
+
const byte0 = Uint8Array.of(0x00);
|
|
199
|
+
const byte1 = Uint8Array.of(0x01);
|
|
200
|
+
const _maxDrbgIters = 1000;
|
|
201
|
+
|
|
202
|
+
// Step B, Step C: set hashLen to 8*ceil(hlen/8)
|
|
203
|
+
let v = u8n(hashLen); // Minimal non-full-spec HMAC-DRBG from NIST 800-90 for RFC6979 sigs.
|
|
204
|
+
let k = u8n(hashLen); // Steps B and C of RFC6979 3.2: set hashLen, in our case always same
|
|
205
|
+
let i = 0; // Iterations counter, will throw when over 1000
|
|
206
|
+
const reset = () => {
|
|
207
|
+
v.fill(1);
|
|
208
|
+
k.fill(0);
|
|
209
|
+
i = 0;
|
|
210
|
+
};
|
|
211
|
+
const h = (...msgs: Uint8Array[]) => hmacFn(k, concatBytes_(v, ...msgs)); // hmac(k)(v, ...values)
|
|
212
|
+
const reseed = (seed: Uint8Array = NULL) => {
|
|
213
|
+
// HMAC-DRBG reseed() function. Steps D-G
|
|
214
|
+
k = h(byte0, seed); // k = hmac(k || v || 0x00 || seed)
|
|
215
|
+
v = h(); // v = hmac(k || v)
|
|
216
|
+
if (seed.length === 0) return;
|
|
217
|
+
k = h(byte1, seed); // k = hmac(k || v || 0x01 || seed)
|
|
218
|
+
v = h(); // v = hmac(k || v)
|
|
219
|
+
};
|
|
220
|
+
const gen = () => {
|
|
221
|
+
// HMAC-DRBG generate() function
|
|
222
|
+
if (i++ >= _maxDrbgIters) throw new Error('drbg: tried max amount of iterations');
|
|
223
|
+
let len = 0;
|
|
224
|
+
const out: Uint8Array[] = [];
|
|
225
|
+
while (len < qByteLen) {
|
|
226
|
+
v = h();
|
|
227
|
+
const sl = v.slice();
|
|
228
|
+
out.push(sl);
|
|
229
|
+
len += v.length;
|
|
230
|
+
}
|
|
231
|
+
return concatBytes_(...out);
|
|
232
|
+
};
|
|
233
|
+
const genUntil = (seed: Uint8Array, pred: Pred<T>): T => {
|
|
234
|
+
reset();
|
|
235
|
+
reseed(seed); // Steps D-G
|
|
236
|
+
let res: T | undefined = undefined; // Step H: grind until k is in [1..n-1]
|
|
237
|
+
while (!(res = pred(gen()))) reseed();
|
|
238
|
+
reset();
|
|
239
|
+
return res;
|
|
240
|
+
};
|
|
241
|
+
return genUntil;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export function validateObject(
|
|
245
|
+
object: Record<string, any>,
|
|
246
|
+
fields: Record<string, string> = {},
|
|
247
|
+
optFields: Record<string, string> = {}
|
|
248
|
+
): void {
|
|
249
|
+
if (!object || typeof object !== 'object') throw new Error('expected valid options object');
|
|
250
|
+
type Item = keyof typeof object;
|
|
251
|
+
function checkField(fieldName: Item, expectedType: string, isOpt: boolean) {
|
|
252
|
+
const val = object[fieldName];
|
|
253
|
+
if (isOpt && val === undefined) return;
|
|
254
|
+
const current = typeof val;
|
|
255
|
+
if (current !== expectedType || val === null)
|
|
256
|
+
throw new Error(`param "${fieldName}" is invalid: expected ${expectedType}, got ${current}`);
|
|
257
|
+
}
|
|
258
|
+
const iter = (f: typeof fields, isOpt: boolean) =>
|
|
259
|
+
Object.entries(f).forEach(([k, v]) => checkField(k, v, isOpt));
|
|
260
|
+
iter(fields, false);
|
|
261
|
+
iter(optFields, true);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* throws not implemented error
|
|
266
|
+
*/
|
|
267
|
+
export const notImplemented = (): never => {
|
|
268
|
+
throw new Error('not implemented');
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Memoizes (caches) computation result.
|
|
273
|
+
* Uses WeakMap: the value is going auto-cleaned by GC after last reference is removed.
|
|
274
|
+
*/
|
|
275
|
+
export function memoized<T extends object, R, O extends any[]>(
|
|
276
|
+
fn: (arg: T, ...args: O) => R
|
|
277
|
+
): (arg: T, ...args: O) => R {
|
|
278
|
+
const map = new WeakMap<T, R>();
|
|
279
|
+
return (arg: T, ...args: O): R => {
|
|
280
|
+
const val = map.get(arg);
|
|
281
|
+
if (val !== undefined) return val;
|
|
282
|
+
const computed = fn(arg, ...args);
|
|
283
|
+
map.set(arg, computed);
|
|
284
|
+
return computed;
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
export interface CryptoKeys {
|
|
289
|
+
lengths: { seed?: number; public?: number; secret?: number };
|
|
290
|
+
keygen: (seed?: Uint8Array) => { secretKey: Uint8Array; publicKey: Uint8Array };
|
|
291
|
+
getPublicKey: (secretKey: Uint8Array) => Uint8Array;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/** Generic interface for signatures. Has keygen, sign and verify. */
|
|
295
|
+
export interface Signer extends CryptoKeys {
|
|
296
|
+
// Interfaces are fun. We cannot just add new fields without copying old ones.
|
|
297
|
+
lengths: {
|
|
298
|
+
seed?: number;
|
|
299
|
+
public?: number;
|
|
300
|
+
secret?: number;
|
|
301
|
+
signRand?: number;
|
|
302
|
+
signature?: number;
|
|
303
|
+
};
|
|
304
|
+
sign: (msg: Uint8Array, secretKey: Uint8Array) => Uint8Array;
|
|
305
|
+
verify: (sig: Uint8Array, msg: Uint8Array, publicKey: Uint8Array) => boolean;
|
|
306
|
+
}
|