@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,857 @@
|
|
|
1
|
+
/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
2
|
+
|
|
3
|
+
export interface Coder<F, T> {
|
|
4
|
+
encode(from: F): T;
|
|
5
|
+
decode(to: T): F;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface BytesCoder extends Coder<Uint8Array, string> {
|
|
9
|
+
encode: (data: Uint8Array) => string;
|
|
10
|
+
decode: (str: string) => Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function isBytes(a: unknown): a is Uint8Array {
|
|
14
|
+
return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array');
|
|
15
|
+
}
|
|
16
|
+
/** Asserts something is Uint8Array. */
|
|
17
|
+
function abytes(b: Uint8Array | undefined): void {
|
|
18
|
+
if (!isBytes(b)) throw new Error('Uint8Array expected');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function isArrayOf(isString: boolean, arr: any[]) {
|
|
22
|
+
if (!Array.isArray(arr)) return false;
|
|
23
|
+
if (arr.length === 0) return true;
|
|
24
|
+
if (isString) {
|
|
25
|
+
return arr.every((item) => typeof item === 'string');
|
|
26
|
+
} else {
|
|
27
|
+
return arr.every((item) => Number.isSafeInteger(item));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function afn(input: Function): input is Function {
|
|
32
|
+
if (typeof input !== 'function') throw new Error('function expected');
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function astr(label: string, input: unknown): input is string {
|
|
37
|
+
if (typeof input !== 'string') throw new Error(`${label}: string expected`);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function anumber(n: number): void {
|
|
42
|
+
if (!Number.isSafeInteger(n)) throw new Error(`invalid integer: ${n}`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function aArr(input: any[]) {
|
|
46
|
+
if (!Array.isArray(input)) throw new Error('array expected');
|
|
47
|
+
}
|
|
48
|
+
function astrArr(label: string, input: string[]) {
|
|
49
|
+
if (!isArrayOf(true, input)) throw new Error(`${label}: array of strings expected`);
|
|
50
|
+
}
|
|
51
|
+
function anumArr(label: string, input: number[]) {
|
|
52
|
+
if (!isArrayOf(false, input)) throw new Error(`${label}: array of numbers expected`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// TODO: some recusive type inference so it would check correct order of input/output inside rest?
|
|
56
|
+
// like <string, number>, <number, bytes>, <bytes, float>
|
|
57
|
+
type Chain = [Coder<any, any>, ...Coder<any, any>[]];
|
|
58
|
+
// Extract info from Coder type
|
|
59
|
+
type Input<F> = F extends Coder<infer T, any> ? T : never;
|
|
60
|
+
type Output<F> = F extends Coder<any, infer T> ? T : never;
|
|
61
|
+
// Generic function for arrays
|
|
62
|
+
type First<T> = T extends [infer U, ...any[]] ? U : never;
|
|
63
|
+
type Last<T> = T extends [...any[], infer U] ? U : never;
|
|
64
|
+
type Tail<T> = T extends [any, ...infer U] ? U : never;
|
|
65
|
+
|
|
66
|
+
type AsChain<C extends Chain, Rest = Tail<C>> = {
|
|
67
|
+
// C[K] = Coder<Input<C[K]>, Input<Rest[k]>>
|
|
68
|
+
[K in keyof C]: Coder<Input<C[K]>, Input<K extends keyof Rest ? Rest[K] : any>>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @__NO_SIDE_EFFECTS__
|
|
73
|
+
*/
|
|
74
|
+
function chain<T extends Chain & AsChain<T>>(...args: T): Coder<Input<First<T>>, Output<Last<T>>> {
|
|
75
|
+
const id = (a: any) => a;
|
|
76
|
+
// Wrap call in closure so JIT can inline calls
|
|
77
|
+
const wrap = (a: any, b: any) => (c: any) => a(b(c));
|
|
78
|
+
// Construct chain of args[-1].encode(args[-2].encode([...]))
|
|
79
|
+
const encode = args.map((x) => x.encode).reduceRight(wrap, id);
|
|
80
|
+
// Construct chain of args[0].decode(args[1].decode(...))
|
|
81
|
+
const decode = args.map((x) => x.decode).reduce(wrap, id);
|
|
82
|
+
return { encode, decode };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Encodes integer radix representation to array of strings using alphabet and back.
|
|
87
|
+
* Could also be array of strings.
|
|
88
|
+
* @__NO_SIDE_EFFECTS__
|
|
89
|
+
*/
|
|
90
|
+
function alphabet(letters: string | string[]): Coder<number[], string[]> {
|
|
91
|
+
// mapping 1 to "b"
|
|
92
|
+
const lettersA = typeof letters === 'string' ? letters.split('') : letters;
|
|
93
|
+
const len = lettersA.length;
|
|
94
|
+
astrArr('alphabet', lettersA);
|
|
95
|
+
|
|
96
|
+
// mapping "b" to 1
|
|
97
|
+
const indexes = new Map(lettersA.map((l, i) => [l, i]));
|
|
98
|
+
return {
|
|
99
|
+
encode: (digits: number[]) => {
|
|
100
|
+
aArr(digits);
|
|
101
|
+
return digits.map((i) => {
|
|
102
|
+
if (!Number.isSafeInteger(i) || i < 0 || i >= len)
|
|
103
|
+
throw new Error(
|
|
104
|
+
`alphabet.encode: digit index outside alphabet "${i}". Allowed: ${letters}`
|
|
105
|
+
);
|
|
106
|
+
return lettersA[i]!;
|
|
107
|
+
});
|
|
108
|
+
},
|
|
109
|
+
decode: (input: string[]): number[] => {
|
|
110
|
+
aArr(input);
|
|
111
|
+
return input.map((letter) => {
|
|
112
|
+
astr('alphabet.decode', letter);
|
|
113
|
+
const i = indexes.get(letter);
|
|
114
|
+
if (i === undefined) throw new Error(`Unknown letter: "${letter}". Allowed: ${letters}`);
|
|
115
|
+
return i;
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* @__NO_SIDE_EFFECTS__
|
|
123
|
+
*/
|
|
124
|
+
function join(separator = ''): Coder<string[], string> {
|
|
125
|
+
astr('join', separator);
|
|
126
|
+
return {
|
|
127
|
+
encode: (from) => {
|
|
128
|
+
astrArr('join.decode', from);
|
|
129
|
+
return from.join(separator);
|
|
130
|
+
},
|
|
131
|
+
decode: (to) => {
|
|
132
|
+
astr('join.decode', to);
|
|
133
|
+
return to.split(separator);
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Pad strings array so it has integer number of bits
|
|
140
|
+
* @__NO_SIDE_EFFECTS__
|
|
141
|
+
*/
|
|
142
|
+
function padding(bits: number, chr = '='): Coder<string[], string[]> {
|
|
143
|
+
anumber(bits);
|
|
144
|
+
astr('padding', chr);
|
|
145
|
+
return {
|
|
146
|
+
encode(data: string[]): string[] {
|
|
147
|
+
astrArr('padding.encode', data);
|
|
148
|
+
while ((data.length * bits) % 8) data.push(chr);
|
|
149
|
+
return data;
|
|
150
|
+
},
|
|
151
|
+
decode(input: string[]): string[] {
|
|
152
|
+
astrArr('padding.decode', input);
|
|
153
|
+
let end = input.length;
|
|
154
|
+
if ((end * bits) % 8)
|
|
155
|
+
throw new Error('padding: invalid, string should have whole number of bytes');
|
|
156
|
+
for (; end > 0 && input[end - 1] === chr; end--) {
|
|
157
|
+
const last = end - 1;
|
|
158
|
+
const byte = last * bits;
|
|
159
|
+
if (byte % 8 === 0) throw new Error('padding: invalid, string has too much padding');
|
|
160
|
+
}
|
|
161
|
+
return input.slice(0, end);
|
|
162
|
+
},
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* @__NO_SIDE_EFFECTS__
|
|
168
|
+
*/
|
|
169
|
+
function normalize<T>(fn: (val: T) => T): Coder<T, T> {
|
|
170
|
+
afn(fn);
|
|
171
|
+
return { encode: (from: T) => from, decode: (to: T) => fn(to) };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Slow: O(n^2) time complexity
|
|
176
|
+
*/
|
|
177
|
+
function convertRadix(data: number[], from: number, to: number): number[] {
|
|
178
|
+
// base 1 is impossible
|
|
179
|
+
if (from < 2) throw new Error(`convertRadix: invalid from=${from}, base cannot be less than 2`);
|
|
180
|
+
if (to < 2) throw new Error(`convertRadix: invalid to=${to}, base cannot be less than 2`);
|
|
181
|
+
aArr(data);
|
|
182
|
+
if (!data.length) return [];
|
|
183
|
+
let pos = 0;
|
|
184
|
+
const res = [];
|
|
185
|
+
const digits = Array.from(data, (d) => {
|
|
186
|
+
anumber(d);
|
|
187
|
+
if (d < 0 || d >= from) throw new Error(`invalid integer: ${d}`);
|
|
188
|
+
return d;
|
|
189
|
+
});
|
|
190
|
+
const dlen = digits.length;
|
|
191
|
+
while (true) {
|
|
192
|
+
let carry = 0;
|
|
193
|
+
let done = true;
|
|
194
|
+
for (let i = pos; i < dlen; i++) {
|
|
195
|
+
const digit = digits[i]!;
|
|
196
|
+
const fromCarry = from * carry;
|
|
197
|
+
const digitBase = fromCarry + digit;
|
|
198
|
+
if (
|
|
199
|
+
!Number.isSafeInteger(digitBase) ||
|
|
200
|
+
fromCarry / from !== carry ||
|
|
201
|
+
digitBase - digit !== fromCarry
|
|
202
|
+
) {
|
|
203
|
+
throw new Error('convertRadix: carry overflow');
|
|
204
|
+
}
|
|
205
|
+
const div = digitBase / to;
|
|
206
|
+
carry = digitBase % to;
|
|
207
|
+
const rounded = Math.floor(div);
|
|
208
|
+
digits[i] = rounded;
|
|
209
|
+
if (!Number.isSafeInteger(rounded) || rounded * to + carry !== digitBase)
|
|
210
|
+
throw new Error('convertRadix: carry overflow');
|
|
211
|
+
if (!done) continue;
|
|
212
|
+
else if (!rounded) pos = i;
|
|
213
|
+
else done = false;
|
|
214
|
+
}
|
|
215
|
+
res.push(carry);
|
|
216
|
+
if (done) break;
|
|
217
|
+
}
|
|
218
|
+
for (let i = 0; i < data.length - 1 && data[i] === 0; i++) res.push(0);
|
|
219
|
+
return res.reverse();
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const gcd = (a: number, b: number): number => (b === 0 ? a : gcd(b, a % b));
|
|
223
|
+
const radix2carry = /* @__NO_SIDE_EFFECTS__ */ (from: number, to: number) =>
|
|
224
|
+
from + (to - gcd(from, to));
|
|
225
|
+
const powers: number[] = /* @__PURE__ */ (() => {
|
|
226
|
+
let res = [];
|
|
227
|
+
for (let i = 0; i < 40; i++) res.push(2 ** i);
|
|
228
|
+
return res;
|
|
229
|
+
})();
|
|
230
|
+
/**
|
|
231
|
+
* Implemented with numbers, because BigInt is 5x slower
|
|
232
|
+
*/
|
|
233
|
+
function convertRadix2(data: number[], from: number, to: number, padding: boolean): number[] {
|
|
234
|
+
aArr(data);
|
|
235
|
+
if (from <= 0 || from > 32) throw new Error(`convertRadix2: wrong from=${from}`);
|
|
236
|
+
if (to <= 0 || to > 32) throw new Error(`convertRadix2: wrong to=${to}`);
|
|
237
|
+
if (radix2carry(from, to) > 32) {
|
|
238
|
+
throw new Error(
|
|
239
|
+
`convertRadix2: carry overflow from=${from} to=${to} carryBits=${radix2carry(from, to)}`
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
let carry = 0;
|
|
243
|
+
let pos = 0; // bitwise position in current element
|
|
244
|
+
const max = powers[from]!;
|
|
245
|
+
const mask = powers[to]! - 1;
|
|
246
|
+
const res: number[] = [];
|
|
247
|
+
for (const n of data) {
|
|
248
|
+
anumber(n);
|
|
249
|
+
if (n >= max) throw new Error(`convertRadix2: invalid data word=${n} from=${from}`);
|
|
250
|
+
carry = (carry << from) | n;
|
|
251
|
+
if (pos + from > 32) throw new Error(`convertRadix2: carry overflow pos=${pos} from=${from}`);
|
|
252
|
+
pos += from;
|
|
253
|
+
for (; pos >= to; pos -= to) res.push(((carry >> (pos - to)) & mask) >>> 0);
|
|
254
|
+
const pow = powers[pos];
|
|
255
|
+
if (pow === undefined) throw new Error('invalid carry');
|
|
256
|
+
carry &= pow - 1; // clean carry, otherwise it will cause overflow
|
|
257
|
+
}
|
|
258
|
+
carry = (carry << (to - pos)) & mask;
|
|
259
|
+
if (!padding && pos >= from) throw new Error('Excess padding');
|
|
260
|
+
if (!padding && carry > 0) throw new Error(`Non-zero padding: ${carry}`);
|
|
261
|
+
if (padding && pos > 0) res.push(carry >>> 0);
|
|
262
|
+
return res;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* @__NO_SIDE_EFFECTS__
|
|
267
|
+
*/
|
|
268
|
+
function radix(num: number): Coder<Uint8Array, number[]> {
|
|
269
|
+
anumber(num);
|
|
270
|
+
const _256 = 2 ** 8;
|
|
271
|
+
return {
|
|
272
|
+
encode: (bytes: Uint8Array) => {
|
|
273
|
+
if (!isBytes(bytes)) throw new Error('radix.encode input should be Uint8Array');
|
|
274
|
+
return convertRadix(Array.from(bytes), _256, num);
|
|
275
|
+
},
|
|
276
|
+
decode: (digits: number[]) => {
|
|
277
|
+
anumArr('radix.decode', digits);
|
|
278
|
+
return Uint8Array.from(convertRadix(digits, num, _256));
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* If both bases are power of same number (like `2**8 <-> 2**64`),
|
|
285
|
+
* there is a linear algorithm. For now we have implementation for power-of-two bases only.
|
|
286
|
+
* @__NO_SIDE_EFFECTS__
|
|
287
|
+
*/
|
|
288
|
+
function radix2(bits: number, revPadding = false): Coder<Uint8Array, number[]> {
|
|
289
|
+
anumber(bits);
|
|
290
|
+
if (bits <= 0 || bits > 32) throw new Error('radix2: bits should be in (0..32]');
|
|
291
|
+
if (radix2carry(8, bits) > 32 || radix2carry(bits, 8) > 32)
|
|
292
|
+
throw new Error('radix2: carry overflow');
|
|
293
|
+
return {
|
|
294
|
+
encode: (bytes: Uint8Array) => {
|
|
295
|
+
if (!isBytes(bytes)) throw new Error('radix2.encode input should be Uint8Array');
|
|
296
|
+
return convertRadix2(Array.from(bytes), 8, bits, !revPadding);
|
|
297
|
+
},
|
|
298
|
+
decode: (digits: number[]) => {
|
|
299
|
+
anumArr('radix2.decode', digits);
|
|
300
|
+
return Uint8Array.from(convertRadix2(digits, bits, 8, revPadding));
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
type ArgumentTypes<F extends Function> = F extends (...args: infer A) => any ? A : never;
|
|
306
|
+
function unsafeWrapper<T extends (...args: any) => any>(fn: T) {
|
|
307
|
+
afn(fn);
|
|
308
|
+
return function (...args: ArgumentTypes<T>): ReturnType<T> | void {
|
|
309
|
+
try {
|
|
310
|
+
return fn.apply(null, args);
|
|
311
|
+
} catch (e) {}
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function checksum(
|
|
316
|
+
len: number,
|
|
317
|
+
fn: (data: Uint8Array) => Uint8Array
|
|
318
|
+
): Coder<Uint8Array, Uint8Array> {
|
|
319
|
+
anumber(len);
|
|
320
|
+
afn(fn);
|
|
321
|
+
return {
|
|
322
|
+
encode(data: Uint8Array) {
|
|
323
|
+
if (!isBytes(data)) throw new Error('checksum.encode: input should be Uint8Array');
|
|
324
|
+
const sum = fn(data).slice(0, len);
|
|
325
|
+
const res = new Uint8Array(data.length + len);
|
|
326
|
+
res.set(data);
|
|
327
|
+
res.set(sum, data.length);
|
|
328
|
+
return res;
|
|
329
|
+
},
|
|
330
|
+
decode(data: Uint8Array) {
|
|
331
|
+
if (!isBytes(data)) throw new Error('checksum.decode: input should be Uint8Array');
|
|
332
|
+
const payload = data.slice(0, -len);
|
|
333
|
+
const oldChecksum = data.slice(-len);
|
|
334
|
+
const newChecksum = fn(payload).slice(0, len);
|
|
335
|
+
for (let i = 0; i < len; i++)
|
|
336
|
+
if (newChecksum[i] !== oldChecksum[i]) throw new Error('Invalid checksum');
|
|
337
|
+
return payload;
|
|
338
|
+
},
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// prettier-ignore
|
|
343
|
+
export const utils: { alphabet: typeof alphabet; chain: typeof chain; checksum: typeof checksum; convertRadix: typeof convertRadix; convertRadix2: typeof convertRadix2; radix: typeof radix; radix2: typeof radix2; join: typeof join; padding: typeof padding; } = {
|
|
344
|
+
alphabet, chain, checksum, convertRadix, convertRadix2, radix, radix2, join, padding,
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
// RFC 4648 aka RFC 3548
|
|
348
|
+
// ---------------------
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* base16 encoding from RFC 4648.
|
|
352
|
+
* @example
|
|
353
|
+
* ```js
|
|
354
|
+
* base16.encode(Uint8Array.from([0x12, 0xab]));
|
|
355
|
+
* // => '12AB'
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
export const base16: BytesCoder = chain(radix2(4), alphabet('0123456789ABCDEF'), join(''));
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* base32 encoding from RFC 4648. Has padding.
|
|
362
|
+
* Use `base32nopad` for unpadded version.
|
|
363
|
+
* Also check out `base32hex`, `base32hexnopad`, `base32crockford`.
|
|
364
|
+
* @example
|
|
365
|
+
* ```js
|
|
366
|
+
* base32.encode(Uint8Array.from([0x12, 0xab]));
|
|
367
|
+
* // => 'CKVQ===='
|
|
368
|
+
* base32.decode('CKVQ====');
|
|
369
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
export const base32: BytesCoder = chain(
|
|
373
|
+
radix2(5),
|
|
374
|
+
alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'),
|
|
375
|
+
padding(5),
|
|
376
|
+
join('')
|
|
377
|
+
);
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* base32 encoding from RFC 4648. No padding.
|
|
381
|
+
* Use `base32` for padded version.
|
|
382
|
+
* Also check out `base32hex`, `base32hexnopad`, `base32crockford`.
|
|
383
|
+
* @example
|
|
384
|
+
* ```js
|
|
385
|
+
* base32nopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
386
|
+
* // => 'CKVQ'
|
|
387
|
+
* base32nopad.decode('CKVQ');
|
|
388
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
export const base32nopad: BytesCoder = chain(
|
|
392
|
+
radix2(5),
|
|
393
|
+
alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567'),
|
|
394
|
+
join('')
|
|
395
|
+
);
|
|
396
|
+
/**
|
|
397
|
+
* base32 encoding from RFC 4648. Padded. Compared to ordinary `base32`, slightly different alphabet.
|
|
398
|
+
* Use `base32hexnopad` for unpadded version.
|
|
399
|
+
* @example
|
|
400
|
+
* ```js
|
|
401
|
+
* base32hex.encode(Uint8Array.from([0x12, 0xab]));
|
|
402
|
+
* // => '2ALG===='
|
|
403
|
+
* base32hex.decode('2ALG====');
|
|
404
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
export const base32hex: BytesCoder = chain(
|
|
408
|
+
radix2(5),
|
|
409
|
+
alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'),
|
|
410
|
+
padding(5),
|
|
411
|
+
join('')
|
|
412
|
+
);
|
|
413
|
+
|
|
414
|
+
/**
|
|
415
|
+
* base32 encoding from RFC 4648. No padding. Compared to ordinary `base32`, slightly different alphabet.
|
|
416
|
+
* Use `base32hex` for padded version.
|
|
417
|
+
* @example
|
|
418
|
+
* ```js
|
|
419
|
+
* base32hexnopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
420
|
+
* // => '2ALG'
|
|
421
|
+
* base32hexnopad.decode('2ALG');
|
|
422
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
423
|
+
* ```
|
|
424
|
+
*/
|
|
425
|
+
export const base32hexnopad: BytesCoder = chain(
|
|
426
|
+
radix2(5),
|
|
427
|
+
alphabet('0123456789ABCDEFGHIJKLMNOPQRSTUV'),
|
|
428
|
+
join('')
|
|
429
|
+
);
|
|
430
|
+
/**
|
|
431
|
+
* base32 encoding from RFC 4648. Doug Crockford's version.
|
|
432
|
+
* https://www.crockford.com/base32.html
|
|
433
|
+
* @example
|
|
434
|
+
* ```js
|
|
435
|
+
* base32crockford.encode(Uint8Array.from([0x12, 0xab]));
|
|
436
|
+
* // => '2ANG'
|
|
437
|
+
* base32crockford.decode('2ANG');
|
|
438
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
439
|
+
* ```
|
|
440
|
+
*/
|
|
441
|
+
export const base32crockford: BytesCoder = chain(
|
|
442
|
+
radix2(5),
|
|
443
|
+
alphabet('0123456789ABCDEFGHJKMNPQRSTVWXYZ'),
|
|
444
|
+
join(''),
|
|
445
|
+
normalize((s: string) => s.toUpperCase().replace(/O/g, '0').replace(/[IL]/g, '1'))
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
// Built-in base64 conversion https://caniuse.com/mdn-javascript_builtins_uint8array_frombase64
|
|
449
|
+
// prettier-ignore
|
|
450
|
+
const hasBase64Builtin: boolean = /* @__PURE__ */ (() =>
|
|
451
|
+
typeof (Uint8Array as any).from([]).toBase64 === 'function' &&
|
|
452
|
+
typeof (Uint8Array as any).fromBase64 === 'function')();
|
|
453
|
+
|
|
454
|
+
const decodeBase64Builtin = (s: string, isUrl: boolean) => {
|
|
455
|
+
astr('base64', s);
|
|
456
|
+
const re = isUrl ? /^[A-Za-z0-9=_-]+$/ : /^[A-Za-z0-9=+/]+$/;
|
|
457
|
+
const alphabet = isUrl ? 'base64url' : 'base64';
|
|
458
|
+
if (s.length > 0 && !re.test(s)) throw new Error('invalid base64');
|
|
459
|
+
return (Uint8Array as any).fromBase64(s, { alphabet, lastChunkHandling: 'strict' });
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* base64 from RFC 4648. Padded.
|
|
464
|
+
* Use `base64nopad` for unpadded version.
|
|
465
|
+
* Also check out `base64url`, `base64urlnopad`.
|
|
466
|
+
* Falls back to built-in function, when available.
|
|
467
|
+
* @example
|
|
468
|
+
* ```js
|
|
469
|
+
* base64.encode(Uint8Array.from([0x12, 0xab]));
|
|
470
|
+
* // => 'Eqs='
|
|
471
|
+
* base64.decode('Eqs=');
|
|
472
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
// prettier-ignore
|
|
476
|
+
export const base64: BytesCoder = hasBase64Builtin ? {
|
|
477
|
+
encode(b) { abytes(b); return (b as any).toBase64(); },
|
|
478
|
+
decode(s) { return decodeBase64Builtin(s, false); },
|
|
479
|
+
} : chain(
|
|
480
|
+
radix2(6),
|
|
481
|
+
alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'),
|
|
482
|
+
padding(6),
|
|
483
|
+
join('')
|
|
484
|
+
);
|
|
485
|
+
/**
|
|
486
|
+
* base64 from RFC 4648. No padding.
|
|
487
|
+
* Use `base64` for padded version.
|
|
488
|
+
* @example
|
|
489
|
+
* ```js
|
|
490
|
+
* base64nopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
491
|
+
* // => 'Eqs'
|
|
492
|
+
* base64nopad.decode('Eqs');
|
|
493
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
494
|
+
* ```
|
|
495
|
+
*/
|
|
496
|
+
export const base64nopad: BytesCoder = chain(
|
|
497
|
+
radix2(6),
|
|
498
|
+
alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'),
|
|
499
|
+
join('')
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* base64 from RFC 4648, using URL-safe alphabet. Padded.
|
|
504
|
+
* Use `base64urlnopad` for unpadded version.
|
|
505
|
+
* Falls back to built-in function, when available.
|
|
506
|
+
* @example
|
|
507
|
+
* ```js
|
|
508
|
+
* base64url.encode(Uint8Array.from([0x12, 0xab]));
|
|
509
|
+
* // => 'Eqs='
|
|
510
|
+
* base64url.decode('Eqs=');
|
|
511
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
512
|
+
* ```
|
|
513
|
+
*/
|
|
514
|
+
// prettier-ignore
|
|
515
|
+
export const base64url: BytesCoder = hasBase64Builtin ? {
|
|
516
|
+
encode(b) { abytes(b); return (b as any).toBase64({ alphabet: 'base64url' }); },
|
|
517
|
+
decode(s) { return decodeBase64Builtin(s, true); },
|
|
518
|
+
} : chain(
|
|
519
|
+
radix2(6),
|
|
520
|
+
alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'),
|
|
521
|
+
padding(6),
|
|
522
|
+
join('')
|
|
523
|
+
);
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* base64 from RFC 4648, using URL-safe alphabet. No padding.
|
|
527
|
+
* Use `base64url` for padded version.
|
|
528
|
+
* @example
|
|
529
|
+
* ```js
|
|
530
|
+
* base64urlnopad.encode(Uint8Array.from([0x12, 0xab]));
|
|
531
|
+
* // => 'Eqs'
|
|
532
|
+
* base64urlnopad.decode('Eqs');
|
|
533
|
+
* // => Uint8Array.from([0x12, 0xab])
|
|
534
|
+
* ```
|
|
535
|
+
*/
|
|
536
|
+
export const base64urlnopad: BytesCoder = chain(
|
|
537
|
+
radix2(6),
|
|
538
|
+
alphabet('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'),
|
|
539
|
+
join('')
|
|
540
|
+
);
|
|
541
|
+
|
|
542
|
+
// base58 code
|
|
543
|
+
// -----------
|
|
544
|
+
const genBase58 = /* @__NO_SIDE_EFFECTS__ */ (abc: string) =>
|
|
545
|
+
chain(radix(58), alphabet(abc), join(''));
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* base58: base64 without ambigous characters +, /, 0, O, I, l.
|
|
549
|
+
* Quadratic (O(n^2)) - so, can't be used on large inputs.
|
|
550
|
+
* @example
|
|
551
|
+
* ```js
|
|
552
|
+
* base58.decode('01abcdef');
|
|
553
|
+
* // => '3UhJW'
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
export const base58: BytesCoder = genBase58(
|
|
557
|
+
'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
|
558
|
+
);
|
|
559
|
+
/**
|
|
560
|
+
* base58: flickr version. Check out `base58`.
|
|
561
|
+
*/
|
|
562
|
+
export const base58flickr: BytesCoder = genBase58(
|
|
563
|
+
'123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'
|
|
564
|
+
);
|
|
565
|
+
/**
|
|
566
|
+
* base58: XRP version. Check out `base58`.
|
|
567
|
+
*/
|
|
568
|
+
export const base58xrp: BytesCoder = genBase58(
|
|
569
|
+
'rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz'
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
// Data len (index) -> encoded block len
|
|
573
|
+
const XMR_BLOCK_LEN = [0, 2, 3, 5, 6, 7, 9, 10, 11];
|
|
574
|
+
|
|
575
|
+
/**
|
|
576
|
+
* base58: XMR version. Check out `base58`.
|
|
577
|
+
* Done in 8-byte blocks (which equals 11 chars in decoding). Last (non-full) block padded with '1' to size in XMR_BLOCK_LEN.
|
|
578
|
+
* Block encoding significantly reduces quadratic complexity of base58.
|
|
579
|
+
*/
|
|
580
|
+
export const base58xmr: BytesCoder = {
|
|
581
|
+
encode(data: Uint8Array) {
|
|
582
|
+
let res = '';
|
|
583
|
+
for (let i = 0; i < data.length; i += 8) {
|
|
584
|
+
const block = data.subarray(i, i + 8);
|
|
585
|
+
res += base58.encode(block).padStart(XMR_BLOCK_LEN[block.length]!, '1');
|
|
586
|
+
}
|
|
587
|
+
return res;
|
|
588
|
+
},
|
|
589
|
+
decode(str: string) {
|
|
590
|
+
let res: number[] = [];
|
|
591
|
+
for (let i = 0; i < str.length; i += 11) {
|
|
592
|
+
const slice = str.slice(i, i + 11);
|
|
593
|
+
const blockLen = XMR_BLOCK_LEN.indexOf(slice.length);
|
|
594
|
+
const block = base58.decode(slice);
|
|
595
|
+
for (let j = 0; j < block.length - blockLen; j++) {
|
|
596
|
+
if (block[j] !== 0) throw new Error('base58xmr: wrong padding');
|
|
597
|
+
}
|
|
598
|
+
res = res.concat(Array.from(block.slice(block.length - blockLen)));
|
|
599
|
+
}
|
|
600
|
+
return Uint8Array.from(res);
|
|
601
|
+
},
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
/**
|
|
605
|
+
* Method, which creates base58check encoder.
|
|
606
|
+
* Requires function, calculating sha256.
|
|
607
|
+
*/
|
|
608
|
+
export const createBase58check = (sha256: (data: Uint8Array) => Uint8Array): BytesCoder =>
|
|
609
|
+
chain(
|
|
610
|
+
checksum(4, (data) => sha256(sha256(data))),
|
|
611
|
+
base58
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Use `createBase58check` instead.
|
|
616
|
+
* @deprecated
|
|
617
|
+
*/
|
|
618
|
+
export const base58check: (sha256: (data: Uint8Array) => Uint8Array) => BytesCoder =
|
|
619
|
+
createBase58check;
|
|
620
|
+
|
|
621
|
+
// Bech32 code
|
|
622
|
+
// -----------
|
|
623
|
+
export interface Bech32Decoded<Prefix extends string = string> {
|
|
624
|
+
prefix: Prefix;
|
|
625
|
+
words: number[];
|
|
626
|
+
}
|
|
627
|
+
export interface Bech32DecodedWithArray<Prefix extends string = string> {
|
|
628
|
+
prefix: Prefix;
|
|
629
|
+
words: number[];
|
|
630
|
+
bytes: Uint8Array;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
const BECH_ALPHABET: Coder<number[], string> = chain(
|
|
634
|
+
alphabet('qpzry9x8gf2tvdw0s3jn54khce6mua7l'),
|
|
635
|
+
join('')
|
|
636
|
+
);
|
|
637
|
+
|
|
638
|
+
const POLYMOD_GENERATORS = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
|
|
639
|
+
function bech32Polymod(pre: number): number {
|
|
640
|
+
const b = pre >> 25;
|
|
641
|
+
let chk = (pre & 0x1ffffff) << 5;
|
|
642
|
+
for (let i = 0; i < POLYMOD_GENERATORS.length; i++) {
|
|
643
|
+
if (((b >> i) & 1) === 1) chk ^= POLYMOD_GENERATORS[i]!;
|
|
644
|
+
}
|
|
645
|
+
return chk;
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
function bechChecksum(prefix: string, words: number[], encodingConst = 1): string {
|
|
649
|
+
const len = prefix.length;
|
|
650
|
+
let chk = 1;
|
|
651
|
+
for (let i = 0; i < len; i++) {
|
|
652
|
+
const c = prefix.charCodeAt(i);
|
|
653
|
+
if (c < 33 || c > 126) throw new Error(`Invalid prefix (${prefix})`);
|
|
654
|
+
chk = bech32Polymod(chk) ^ (c >> 5);
|
|
655
|
+
}
|
|
656
|
+
chk = bech32Polymod(chk);
|
|
657
|
+
for (let i = 0; i < len; i++) chk = bech32Polymod(chk) ^ (prefix.charCodeAt(i) & 0x1f);
|
|
658
|
+
for (let v of words) chk = bech32Polymod(chk) ^ v;
|
|
659
|
+
for (let i = 0; i < 6; i++) chk = bech32Polymod(chk);
|
|
660
|
+
chk ^= encodingConst;
|
|
661
|
+
return BECH_ALPHABET.encode(convertRadix2([chk % powers[30]!], 30, 5, false));
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export interface Bech32 {
|
|
665
|
+
encode<Prefix extends string>(
|
|
666
|
+
prefix: Prefix,
|
|
667
|
+
words: number[] | Uint8Array,
|
|
668
|
+
limit?: number | false
|
|
669
|
+
): `${Lowercase<Prefix>}1${string}`;
|
|
670
|
+
decode<Prefix extends string>(
|
|
671
|
+
str: `${Prefix}1${string}`,
|
|
672
|
+
limit?: number | false
|
|
673
|
+
): Bech32Decoded<Prefix>;
|
|
674
|
+
encodeFromBytes(prefix: string, bytes: Uint8Array): string;
|
|
675
|
+
decodeToBytes(str: string): Bech32DecodedWithArray;
|
|
676
|
+
decodeUnsafe(str: string, limit?: number | false): void | Bech32Decoded<string>;
|
|
677
|
+
fromWords(to: number[]): Uint8Array;
|
|
678
|
+
fromWordsUnsafe(to: number[]): void | Uint8Array;
|
|
679
|
+
toWords(from: Uint8Array): number[];
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* @__NO_SIDE_EFFECTS__
|
|
683
|
+
*/
|
|
684
|
+
function genBech32(encoding: 'bech32' | 'bech32m'): Bech32 {
|
|
685
|
+
const ENCODING_CONST = encoding === 'bech32' ? 1 : 0x2bc830a3;
|
|
686
|
+
const _words = radix2(5);
|
|
687
|
+
const fromWords = _words.decode;
|
|
688
|
+
const toWords = _words.encode;
|
|
689
|
+
const fromWordsUnsafe = unsafeWrapper(fromWords);
|
|
690
|
+
|
|
691
|
+
function encode<Prefix extends string>(
|
|
692
|
+
prefix: Prefix,
|
|
693
|
+
words: number[] | Uint8Array,
|
|
694
|
+
limit: number | false = 90
|
|
695
|
+
): `${Lowercase<Prefix>}1${string}` {
|
|
696
|
+
astr('bech32.encode prefix', prefix);
|
|
697
|
+
if (isBytes(words)) words = Array.from(words);
|
|
698
|
+
anumArr('bech32.encode', words);
|
|
699
|
+
const plen = prefix.length;
|
|
700
|
+
if (plen === 0) throw new TypeError(`Invalid prefix length ${plen}`);
|
|
701
|
+
const actualLength = plen + 7 + words.length;
|
|
702
|
+
if (limit !== false && actualLength > limit)
|
|
703
|
+
throw new TypeError(`Length ${actualLength} exceeds limit ${limit}`);
|
|
704
|
+
const lowered = prefix.toLowerCase();
|
|
705
|
+
const sum = bechChecksum(lowered, words, ENCODING_CONST);
|
|
706
|
+
return `${lowered}1${BECH_ALPHABET.encode(words)}${sum}` as `${Lowercase<Prefix>}1${string}`;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
function decode<Prefix extends string>(
|
|
710
|
+
str: `${Prefix}1${string}`,
|
|
711
|
+
limit?: number | false
|
|
712
|
+
): Bech32Decoded<Prefix>;
|
|
713
|
+
function decode(str: string, limit?: number | false): Bech32Decoded;
|
|
714
|
+
function decode(str: string, limit: number | false = 90): Bech32Decoded {
|
|
715
|
+
astr('bech32.decode input', str);
|
|
716
|
+
const slen = str.length;
|
|
717
|
+
if (slen < 8 || (limit !== false && slen > limit))
|
|
718
|
+
throw new TypeError(`invalid string length: ${slen} (${str}). Expected (8..${limit})`);
|
|
719
|
+
// don't allow mixed case
|
|
720
|
+
const lowered = str.toLowerCase();
|
|
721
|
+
if (str !== lowered && str !== str.toUpperCase())
|
|
722
|
+
throw new Error(`String must be lowercase or uppercase`);
|
|
723
|
+
const sepIndex = lowered.lastIndexOf('1');
|
|
724
|
+
if (sepIndex === 0 || sepIndex === -1)
|
|
725
|
+
throw new Error(`Letter "1" must be present between prefix and data only`);
|
|
726
|
+
const prefix = lowered.slice(0, sepIndex);
|
|
727
|
+
const data = lowered.slice(sepIndex + 1);
|
|
728
|
+
if (data.length < 6) throw new Error('Data must be at least 6 characters long');
|
|
729
|
+
const words = BECH_ALPHABET.decode(data).slice(0, -6);
|
|
730
|
+
const sum = bechChecksum(prefix, words, ENCODING_CONST);
|
|
731
|
+
if (!data.endsWith(sum)) throw new Error(`Invalid checksum in ${str}: expected "${sum}"`);
|
|
732
|
+
return { prefix, words };
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
const decodeUnsafe = unsafeWrapper(decode);
|
|
736
|
+
|
|
737
|
+
function decodeToBytes(str: string): Bech32DecodedWithArray {
|
|
738
|
+
const { prefix, words } = decode(str, false);
|
|
739
|
+
return { prefix, words, bytes: fromWords(words) };
|
|
740
|
+
}
|
|
741
|
+
|
|
742
|
+
function encodeFromBytes(prefix: string, bytes: Uint8Array) {
|
|
743
|
+
return encode(prefix, toWords(bytes));
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
return {
|
|
747
|
+
encode,
|
|
748
|
+
decode,
|
|
749
|
+
encodeFromBytes,
|
|
750
|
+
decodeToBytes,
|
|
751
|
+
decodeUnsafe,
|
|
752
|
+
fromWords,
|
|
753
|
+
fromWordsUnsafe,
|
|
754
|
+
toWords,
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* bech32 from BIP 173. Operates on words.
|
|
760
|
+
* For high-level, check out scure-btc-signer:
|
|
761
|
+
* https://github.com/paulmillr/scure-btc-signer.
|
|
762
|
+
*/
|
|
763
|
+
export const bech32: Bech32 = genBech32('bech32');
|
|
764
|
+
|
|
765
|
+
/**
|
|
766
|
+
* bech32m from BIP 350. Operates on words.
|
|
767
|
+
* It was to mitigate `bech32` weaknesses.
|
|
768
|
+
* For high-level, check out scure-btc-signer:
|
|
769
|
+
* https://github.com/paulmillr/scure-btc-signer.
|
|
770
|
+
*/
|
|
771
|
+
export const bech32m: Bech32 = genBech32('bech32m');
|
|
772
|
+
|
|
773
|
+
declare const TextEncoder: any;
|
|
774
|
+
declare const TextDecoder: any;
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* UTF-8-to-byte decoder. Uses built-in TextDecoder / TextEncoder.
|
|
778
|
+
* @example
|
|
779
|
+
* ```js
|
|
780
|
+
* const b = utf8.decode("hey"); // => new Uint8Array([ 104, 101, 121 ])
|
|
781
|
+
* const str = utf8.encode(b); // "hey"
|
|
782
|
+
* ```
|
|
783
|
+
*/
|
|
784
|
+
export const utf8: BytesCoder = {
|
|
785
|
+
encode: (data) => new TextDecoder().decode(data),
|
|
786
|
+
decode: (str) => new TextEncoder().encode(str),
|
|
787
|
+
};
|
|
788
|
+
|
|
789
|
+
// Built-in hex conversion https://caniuse.com/mdn-javascript_builtins_uint8array_fromhex
|
|
790
|
+
// prettier-ignore
|
|
791
|
+
const hasHexBuiltin: boolean = /* @__PURE__ */ (() =>
|
|
792
|
+
typeof (Uint8Array as any).from([]).toHex === 'function' &&
|
|
793
|
+
typeof (Uint8Array as any).fromHex === 'function')();
|
|
794
|
+
// prettier-ignore
|
|
795
|
+
const hexBuiltin: BytesCoder = {
|
|
796
|
+
encode(data) { abytes(data); return (data as any).toHex(); },
|
|
797
|
+
decode(s) { astr('hex', s); return (Uint8Array as any).fromHex(s); },
|
|
798
|
+
};
|
|
799
|
+
/**
|
|
800
|
+
* hex string decoder. Uses built-in function, when available.
|
|
801
|
+
* @example
|
|
802
|
+
* ```js
|
|
803
|
+
* const b = hex.decode("0102ff"); // => new Uint8Array([ 1, 2, 255 ])
|
|
804
|
+
* const str = hex.encode(b); // "0102ff"
|
|
805
|
+
* ```
|
|
806
|
+
*/
|
|
807
|
+
export const hex: BytesCoder = hasHexBuiltin
|
|
808
|
+
? hexBuiltin
|
|
809
|
+
: chain(
|
|
810
|
+
radix2(4),
|
|
811
|
+
alphabet('0123456789abcdef'),
|
|
812
|
+
join(''),
|
|
813
|
+
normalize((s: string) => {
|
|
814
|
+
if (typeof s !== 'string' || s.length % 2 !== 0)
|
|
815
|
+
throw new TypeError(
|
|
816
|
+
`hex.decode: expected string, got ${typeof s} with length ${s.length}`
|
|
817
|
+
);
|
|
818
|
+
return s.toLowerCase();
|
|
819
|
+
})
|
|
820
|
+
);
|
|
821
|
+
|
|
822
|
+
export type SomeCoders = {
|
|
823
|
+
utf8: BytesCoder;
|
|
824
|
+
hex: BytesCoder;
|
|
825
|
+
base16: BytesCoder;
|
|
826
|
+
base32: BytesCoder;
|
|
827
|
+
base64: BytesCoder;
|
|
828
|
+
base64url: BytesCoder;
|
|
829
|
+
base58: BytesCoder;
|
|
830
|
+
base58xmr: BytesCoder;
|
|
831
|
+
};
|
|
832
|
+
// prettier-ignore
|
|
833
|
+
const CODERS: SomeCoders = {
|
|
834
|
+
utf8, hex, base16, base32, base64, base64url, base58, base58xmr
|
|
835
|
+
};
|
|
836
|
+
type CoderType = keyof SomeCoders;
|
|
837
|
+
const coderTypeError =
|
|
838
|
+
'Invalid encoding type. Available types: utf8, hex, base16, base32, base64, base64url, base58, base58xmr';
|
|
839
|
+
|
|
840
|
+
/** @deprecated */
|
|
841
|
+
export const bytesToString = (type: CoderType, bytes: Uint8Array): string => {
|
|
842
|
+
if (typeof type !== 'string' || !CODERS.hasOwnProperty(type)) throw new TypeError(coderTypeError);
|
|
843
|
+
if (!isBytes(bytes)) throw new TypeError('bytesToString() expects Uint8Array');
|
|
844
|
+
return CODERS[type].encode(bytes);
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
/** @deprecated */
|
|
848
|
+
export const str: (type: CoderType, bytes: Uint8Array) => string = bytesToString; // as in python, but for bytes only
|
|
849
|
+
|
|
850
|
+
/** @deprecated */
|
|
851
|
+
export const stringToBytes = (type: CoderType, str: string): Uint8Array => {
|
|
852
|
+
if (!CODERS.hasOwnProperty(type)) throw new TypeError(coderTypeError);
|
|
853
|
+
if (typeof str !== 'string') throw new TypeError('stringToBytes() expects string');
|
|
854
|
+
return CODERS[type].decode(str);
|
|
855
|
+
};
|
|
856
|
+
/** @deprecated */
|
|
857
|
+
export const bytes: (type: CoderType, str: string) => Uint8Array = stringToBytes;
|