crypto-aio 0.0.3 → 0.1.0
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/CHANGELOG.md +17 -0
- package/README.md +144 -14
- package/dist/adapters/avalanche/address.d.ts +15 -0
- package/dist/adapters/avalanche/address.js +74 -0
- package/dist/adapters/avalanche/address.js.map +1 -0
- package/dist/adapters/avalanche/api.d.ts +100 -0
- package/dist/adapters/avalanche/api.js +381 -0
- package/dist/adapters/avalanche/api.js.map +1 -0
- package/dist/adapters/avalanche/builder.d.ts +13 -0
- package/dist/adapters/avalanche/builder.js +336 -0
- package/dist/adapters/avalanche/builder.js.map +1 -0
- package/dist/adapters/avalanche/cb58.d.ts +7 -0
- package/dist/adapters/avalanche/cb58.js +49 -0
- package/dist/adapters/avalanche/cb58.js.map +1 -0
- package/dist/adapters/avalanche/chains.d.ts +21 -0
- package/dist/adapters/avalanche/chains.js +79 -0
- package/dist/adapters/avalanche/chains.js.map +1 -0
- package/dist/adapters/avalanche/codec.d.ts +94 -0
- package/dist/adapters/avalanche/codec.js +371 -0
- package/dist/adapters/avalanche/codec.js.map +1 -0
- package/dist/adapters/avalanche/context.d.ts +59 -0
- package/dist/adapters/avalanche/context.js +114 -0
- package/dist/adapters/avalanche/context.js.map +1 -0
- package/dist/adapters/avalanche/decode.d.ts +16 -0
- package/dist/adapters/avalanche/decode.js +101 -0
- package/dist/adapters/avalanche/decode.js.map +1 -0
- package/dist/adapters/avalanche/driver.d.ts +22 -0
- package/dist/adapters/avalanche/driver.js +81 -0
- package/dist/adapters/avalanche/driver.js.map +1 -0
- package/dist/adapters/avalanche/errors.d.ts +18 -0
- package/dist/adapters/avalanche/errors.js +61 -0
- package/dist/adapters/avalanche/errors.js.map +1 -0
- package/dist/adapters/avalanche/fees.d.ts +23 -0
- package/dist/adapters/avalanche/fees.js +105 -0
- package/dist/adapters/avalanche/fees.js.map +1 -0
- package/dist/adapters/avalanche/index.d.ts +19 -0
- package/dist/adapters/avalanche/index.js +8 -0
- package/dist/adapters/avalanche/index.js.map +1 -0
- package/dist/adapters/avalanche/network.d.ts +37 -0
- package/dist/adapters/avalanche/network.js +135 -0
- package/dist/adapters/avalanche/network.js.map +1 -0
- package/dist/adapters/avalanche/plugin.d.ts +21 -0
- package/dist/adapters/avalanche/plugin.js +46 -0
- package/dist/adapters/avalanche/plugin.js.map +1 -0
- package/dist/adapters/avalanche/presets.d.ts +6 -0
- package/dist/adapters/avalanche/presets.js +86 -0
- package/dist/adapters/avalanche/presets.js.map +1 -0
- package/dist/adapters/avalanche/proofs.d.ts +41 -0
- package/dist/adapters/avalanche/proofs.js +270 -0
- package/dist/adapters/avalanche/proofs.js.map +1 -0
- package/dist/adapters/avalanche/reader.d.ts +40 -0
- package/dist/adapters/avalanche/reader.js +231 -0
- package/dist/adapters/avalanche/reader.js.map +1 -0
- package/dist/adapters/avalanche/sdk.d.ts +182 -0
- package/dist/adapters/avalanche/sdk.js +21 -0
- package/dist/adapters/avalanche/sdk.js.map +1 -0
- package/dist/adapters/avalanche/types.d.ts +86 -0
- package/dist/{type/common.js → adapters/avalanche/types.js} +1 -1
- package/dist/adapters/avalanche/types.js.map +1 -0
- package/dist/adapters/evm/builder.d.ts +11 -0
- package/dist/adapters/evm/builder.js +326 -0
- package/dist/adapters/evm/builder.js.map +1 -0
- package/dist/adapters/evm/chains.d.ts +6 -0
- package/dist/adapters/evm/chains.js +203 -0
- package/dist/adapters/evm/chains.js.map +1 -0
- package/dist/adapters/evm/client.d.ts +84 -0
- package/dist/adapters/evm/client.js +335 -0
- package/dist/adapters/evm/client.js.map +1 -0
- package/dist/adapters/evm/decode.d.ts +35 -0
- package/dist/adapters/evm/decode.js +170 -0
- package/dist/adapters/evm/decode.js.map +1 -0
- package/dist/adapters/evm/driver.d.ts +8 -0
- package/dist/adapters/evm/driver.js +61 -0
- package/dist/adapters/evm/driver.js.map +1 -0
- package/dist/adapters/evm/errors.d.ts +20 -0
- package/dist/adapters/evm/errors.js +110 -0
- package/dist/adapters/evm/errors.js.map +1 -0
- package/dist/adapters/evm/ethers-client.d.ts +43 -0
- package/dist/adapters/evm/ethers-client.js +135 -0
- package/dist/adapters/evm/ethers-client.js.map +1 -0
- package/dist/adapters/evm/fees.d.ts +79 -0
- package/dist/adapters/evm/fees.js +234 -0
- package/dist/adapters/evm/fees.js.map +1 -0
- package/dist/adapters/evm/index.d.ts +20 -0
- package/dist/adapters/evm/index.js +11 -0
- package/dist/adapters/evm/index.js.map +1 -0
- package/dist/adapters/evm/network.d.ts +60 -0
- package/dist/adapters/evm/network.js +131 -0
- package/dist/adapters/evm/network.js.map +1 -0
- package/dist/adapters/evm/plugin.d.ts +36 -0
- package/dist/adapters/evm/plugin.js +102 -0
- package/dist/adapters/evm/plugin.js.map +1 -0
- package/dist/adapters/evm/presets.d.ts +2 -0
- package/dist/adapters/evm/presets.js +105 -0
- package/dist/adapters/evm/presets.js.map +1 -0
- package/dist/adapters/evm/proofs.d.ts +19 -0
- package/dist/adapters/evm/proofs.js +358 -0
- package/dist/adapters/evm/proofs.js.map +1 -0
- package/dist/adapters/evm/rawtx.d.ts +25 -0
- package/dist/adapters/evm/rawtx.js +176 -0
- package/dist/adapters/evm/rawtx.js.map +1 -0
- package/dist/adapters/evm/reader.d.ts +65 -0
- package/dist/adapters/evm/reader.js +292 -0
- package/dist/adapters/evm/reader.js.map +1 -0
- package/dist/adapters/evm/rpc.d.ts +39 -0
- package/dist/adapters/evm/rpc.js +152 -0
- package/dist/adapters/evm/rpc.js.map +1 -0
- package/dist/adapters/evm/tokens.d.ts +7 -0
- package/dist/adapters/evm/tokens.js +23 -0
- package/dist/adapters/evm/tokens.js.map +1 -0
- package/dist/adapters/evm/types.d.ts +255 -0
- package/dist/{type/account.js → adapters/evm/types.js} +1 -1
- package/dist/adapters/evm/types.js.map +1 -0
- package/dist/adapters/evm/web3-client.d.ts +23 -0
- package/dist/adapters/evm/web3-client.js +159 -0
- package/dist/adapters/evm/web3-client.js.map +1 -0
- package/dist/adapters/solana/builder.d.ts +18 -0
- package/dist/adapters/solana/builder.js +545 -0
- package/dist/adapters/solana/builder.js.map +1 -0
- package/dist/adapters/solana/chains.d.ts +13 -0
- package/dist/adapters/solana/chains.js +37 -0
- package/dist/adapters/solana/chains.js.map +1 -0
- package/dist/adapters/solana/decode.d.ts +111 -0
- package/dist/adapters/solana/decode.js +595 -0
- package/dist/adapters/solana/decode.js.map +1 -0
- package/dist/adapters/solana/driver.d.ts +15 -0
- package/dist/adapters/solana/driver.js +72 -0
- package/dist/adapters/solana/driver.js.map +1 -0
- package/dist/adapters/solana/errors.d.ts +36 -0
- package/dist/adapters/solana/errors.js +154 -0
- package/dist/adapters/solana/errors.js.map +1 -0
- package/dist/adapters/solana/fees.d.ts +68 -0
- package/dist/adapters/solana/fees.js +205 -0
- package/dist/adapters/solana/fees.js.map +1 -0
- package/dist/adapters/solana/heights.d.ts +47 -0
- package/dist/adapters/solana/heights.js +185 -0
- package/dist/adapters/solana/heights.js.map +1 -0
- package/dist/adapters/solana/history.d.ts +10 -0
- package/dist/adapters/solana/history.js +71 -0
- package/dist/adapters/solana/history.js.map +1 -0
- package/dist/adapters/solana/index.d.ts +16 -0
- package/dist/adapters/solana/index.js +9 -0
- package/dist/adapters/solana/index.js.map +1 -0
- package/dist/adapters/solana/keys.d.ts +13 -0
- package/dist/adapters/solana/keys.js +69 -0
- package/dist/adapters/solana/keys.js.map +1 -0
- package/dist/adapters/solana/network.d.ts +24 -0
- package/dist/adapters/solana/network.js +95 -0
- package/dist/adapters/solana/network.js.map +1 -0
- package/dist/adapters/solana/plugin.d.ts +18 -0
- package/dist/adapters/solana/plugin.js +41 -0
- package/dist/adapters/solana/plugin.js.map +1 -0
- package/dist/adapters/solana/presets.d.ts +2 -0
- package/dist/adapters/solana/presets.js +77 -0
- package/dist/adapters/solana/presets.js.map +1 -0
- package/dist/adapters/solana/programs.d.ts +44 -0
- package/dist/adapters/solana/programs.js +159 -0
- package/dist/adapters/solana/programs.js.map +1 -0
- package/dist/adapters/solana/proofs.d.ts +56 -0
- package/dist/adapters/solana/proofs.js +540 -0
- package/dist/adapters/solana/proofs.js.map +1 -0
- package/dist/adapters/solana/reader.d.ts +82 -0
- package/dist/adapters/solana/reader.js +326 -0
- package/dist/adapters/solana/reader.js.map +1 -0
- package/dist/adapters/solana/rpc.d.ts +102 -0
- package/dist/adapters/solana/rpc.js +301 -0
- package/dist/adapters/solana/rpc.js.map +1 -0
- package/dist/adapters/solana/tokens.d.ts +7 -0
- package/dist/adapters/solana/tokens.js +19 -0
- package/dist/adapters/solana/tokens.js.map +1 -0
- package/dist/adapters/solana/types.d.ts +121 -0
- package/dist/{type/contract.js → adapters/solana/types.js} +1 -1
- package/dist/adapters/solana/types.js.map +1 -0
- package/dist/adapters/solana/web3.d.ts +5 -0
- package/dist/adapters/solana/web3.js +83 -0
- package/dist/adapters/solana/web3.js.map +1 -0
- package/dist/adapters/solana/wire.d.ts +62 -0
- package/dist/adapters/solana/wire.js +168 -0
- package/dist/adapters/solana/wire.js.map +1 -0
- package/dist/adapters/ton/address.d.ts +43 -0
- package/dist/adapters/ton/address.js +168 -0
- package/dist/adapters/ton/address.js.map +1 -0
- package/dist/adapters/ton/api.d.ts +344 -0
- package/dist/adapters/ton/api.js +942 -0
- package/dist/adapters/ton/api.js.map +1 -0
- package/dist/adapters/ton/builder.d.ts +18 -0
- package/dist/adapters/ton/builder.js +701 -0
- package/dist/adapters/ton/builder.js.map +1 -0
- package/dist/adapters/ton/chains.d.ts +16 -0
- package/dist/adapters/ton/chains.js +39 -0
- package/dist/adapters/ton/chains.js.map +1 -0
- package/dist/adapters/ton/decode.d.ts +43 -0
- package/dist/adapters/ton/decode.js +219 -0
- package/dist/adapters/ton/decode.js.map +1 -0
- package/dist/adapters/ton/driver.d.ts +10 -0
- package/dist/adapters/ton/driver.js +117 -0
- package/dist/adapters/ton/driver.js.map +1 -0
- package/dist/adapters/ton/errors.d.ts +36 -0
- package/dist/adapters/ton/errors.js +89 -0
- package/dist/adapters/ton/errors.js.map +1 -0
- package/dist/adapters/ton/fees.d.ts +28 -0
- package/dist/adapters/ton/fees.js +121 -0
- package/dist/adapters/ton/fees.js.map +1 -0
- package/dist/adapters/ton/index.d.ts +16 -0
- package/dist/adapters/ton/index.js +9 -0
- package/dist/adapters/ton/index.js.map +1 -0
- package/dist/adapters/ton/messages.d.ts +157 -0
- package/dist/adapters/ton/messages.js +397 -0
- package/dist/adapters/ton/messages.js.map +1 -0
- package/dist/adapters/ton/native-client.d.ts +10 -0
- package/dist/adapters/ton/native-client.js +47 -0
- package/dist/adapters/ton/native-client.js.map +1 -0
- package/dist/adapters/ton/network.d.ts +58 -0
- package/dist/adapters/ton/network.js +207 -0
- package/dist/adapters/ton/network.js.map +1 -0
- package/dist/adapters/ton/plugin.d.ts +24 -0
- package/dist/adapters/ton/plugin.js +57 -0
- package/dist/adapters/ton/plugin.js.map +1 -0
- package/dist/adapters/ton/presets.d.ts +6 -0
- package/dist/adapters/ton/presets.js +94 -0
- package/dist/adapters/ton/presets.js.map +1 -0
- package/dist/adapters/ton/proofs.d.ts +66 -0
- package/dist/adapters/ton/proofs.js +813 -0
- package/dist/adapters/ton/proofs.js.map +1 -0
- package/dist/adapters/ton/reader.d.ts +194 -0
- package/dist/adapters/ton/reader.js +781 -0
- package/dist/adapters/ton/reader.js.map +1 -0
- package/dist/adapters/ton/tokens.d.ts +10 -0
- package/dist/adapters/ton/tokens.js +27 -0
- package/dist/adapters/ton/tokens.js.map +1 -0
- package/dist/adapters/ton/trace.d.ts +48 -0
- package/dist/adapters/ton/trace.js +277 -0
- package/dist/adapters/ton/trace.js.map +1 -0
- package/dist/adapters/ton/types.d.ts +105 -0
- package/dist/{type/transact.js → adapters/ton/types.js} +1 -1
- package/dist/adapters/ton/types.js.map +1 -0
- package/dist/adapters/ton/wallets.d.ts +86 -0
- package/dist/adapters/ton/wallets.js +373 -0
- package/dist/adapters/ton/wallets.js.map +1 -0
- package/dist/adapters/tron/abi.d.ts +39 -0
- package/dist/adapters/tron/abi.js +110 -0
- package/dist/adapters/tron/abi.js.map +1 -0
- package/dist/adapters/tron/address.d.ts +20 -0
- package/dist/adapters/tron/address.js +110 -0
- package/dist/adapters/tron/address.js.map +1 -0
- package/dist/adapters/tron/builder.d.ts +12 -0
- package/dist/adapters/tron/builder.js +553 -0
- package/dist/adapters/tron/builder.js.map +1 -0
- package/dist/adapters/tron/chains.d.ts +12 -0
- package/dist/adapters/tron/chains.js +35 -0
- package/dist/adapters/tron/chains.js.map +1 -0
- package/dist/adapters/tron/codec.d.ts +10 -0
- package/dist/adapters/tron/codec.js +322 -0
- package/dist/adapters/tron/codec.js.map +1 -0
- package/dist/adapters/tron/decode.d.ts +50 -0
- package/dist/adapters/tron/decode.js +280 -0
- package/dist/adapters/tron/decode.js.map +1 -0
- package/dist/adapters/tron/driver.d.ts +12 -0
- package/dist/adapters/tron/driver.js +106 -0
- package/dist/adapters/tron/driver.js.map +1 -0
- package/dist/adapters/tron/errors.d.ts +74 -0
- package/dist/adapters/tron/errors.js +261 -0
- package/dist/adapters/tron/errors.js.map +1 -0
- package/dist/adapters/tron/fees.d.ts +49 -0
- package/dist/adapters/tron/fees.js +166 -0
- package/dist/adapters/tron/fees.js.map +1 -0
- package/dist/adapters/tron/http.d.ts +173 -0
- package/dist/adapters/tron/http.js +729 -0
- package/dist/adapters/tron/http.js.map +1 -0
- package/dist/adapters/tron/index.d.ts +16 -0
- package/dist/adapters/tron/index.js +15 -0
- package/dist/adapters/tron/index.js.map +1 -0
- package/dist/adapters/tron/network.d.ts +44 -0
- package/dist/adapters/tron/network.js +163 -0
- package/dist/adapters/tron/network.js.map +1 -0
- package/dist/adapters/tron/plugin.d.ts +17 -0
- package/dist/adapters/tron/plugin.js +39 -0
- package/dist/adapters/tron/plugin.js.map +1 -0
- package/dist/adapters/tron/presets.d.ts +5 -0
- package/dist/adapters/tron/presets.js +68 -0
- package/dist/adapters/tron/presets.js.map +1 -0
- package/dist/adapters/tron/proofs.d.ts +80 -0
- package/dist/adapters/tron/proofs.js +370 -0
- package/dist/adapters/tron/proofs.js.map +1 -0
- package/dist/adapters/tron/protobuf.d.ts +36 -0
- package/dist/adapters/tron/protobuf.js +90 -0
- package/dist/adapters/tron/protobuf.js.map +1 -0
- package/dist/adapters/tron/reader.d.ts +47 -0
- package/dist/adapters/tron/reader.js +203 -0
- package/dist/adapters/tron/reader.js.map +1 -0
- package/dist/adapters/tron/tokens.d.ts +7 -0
- package/dist/adapters/tron/tokens.js +14 -0
- package/dist/adapters/tron/tokens.js.map +1 -0
- package/dist/adapters/tron/types.d.ts +166 -0
- package/dist/adapters/tron/types.js +3 -0
- package/dist/adapters/tron/types.js.map +1 -0
- package/dist/adapters/utxo/address.d.ts +51 -0
- package/dist/adapters/utxo/address.js +341 -0
- package/dist/adapters/utxo/address.js.map +1 -0
- package/dist/adapters/utxo/builder.d.ts +35 -0
- package/dist/adapters/utxo/builder.js +380 -0
- package/dist/adapters/utxo/builder.js.map +1 -0
- package/dist/adapters/utxo/chains.d.ts +17 -0
- package/dist/adapters/utxo/chains.js +99 -0
- package/dist/adapters/utxo/chains.js.map +1 -0
- package/dist/adapters/utxo/codec.d.ts +120 -0
- package/dist/adapters/utxo/codec.js +408 -0
- package/dist/adapters/utxo/codec.js.map +1 -0
- package/dist/adapters/utxo/coinselect.d.ts +48 -0
- package/dist/adapters/utxo/coinselect.js +131 -0
- package/dist/adapters/utxo/coinselect.js.map +1 -0
- package/dist/adapters/utxo/context.d.ts +57 -0
- package/dist/adapters/utxo/context.js +118 -0
- package/dist/adapters/utxo/context.js.map +1 -0
- package/dist/adapters/utxo/decode.d.ts +14 -0
- package/dist/adapters/utxo/decode.js +85 -0
- package/dist/adapters/utxo/decode.js.map +1 -0
- package/dist/adapters/utxo/driver.d.ts +16 -0
- package/dist/adapters/utxo/driver.js +74 -0
- package/dist/adapters/utxo/driver.js.map +1 -0
- package/dist/adapters/utxo/ecc.d.ts +9 -0
- package/dist/adapters/utxo/ecc.js +26 -0
- package/dist/adapters/utxo/ecc.js.map +1 -0
- package/dist/adapters/utxo/errors.d.ts +52 -0
- package/dist/adapters/utxo/errors.js +191 -0
- package/dist/adapters/utxo/errors.js.map +1 -0
- package/dist/adapters/utxo/esplora.d.ts +79 -0
- package/dist/adapters/utxo/esplora.js +451 -0
- package/dist/adapters/utxo/esplora.js.map +1 -0
- package/dist/adapters/utxo/fees.d.ts +41 -0
- package/dist/adapters/utxo/fees.js +125 -0
- package/dist/adapters/utxo/fees.js.map +1 -0
- package/dist/adapters/utxo/index.d.ts +17 -0
- package/dist/adapters/utxo/index.js +8 -0
- package/dist/adapters/utxo/index.js.map +1 -0
- package/dist/adapters/utxo/network.d.ts +50 -0
- package/dist/adapters/utxo/network.js +165 -0
- package/dist/adapters/utxo/network.js.map +1 -0
- package/dist/adapters/utxo/plugin.d.ts +17 -0
- package/dist/adapters/utxo/plugin.js +41 -0
- package/dist/adapters/utxo/plugin.js.map +1 -0
- package/dist/adapters/utxo/presets.d.ts +12 -0
- package/dist/adapters/utxo/presets.js +47 -0
- package/dist/adapters/utxo/presets.js.map +1 -0
- package/dist/adapters/utxo/preview.d.ts +3 -0
- package/dist/adapters/utxo/preview.js +65 -0
- package/dist/adapters/utxo/preview.js.map +1 -0
- package/dist/adapters/utxo/proofs.d.ts +57 -0
- package/dist/adapters/utxo/proofs.js +331 -0
- package/dist/adapters/utxo/proofs.js.map +1 -0
- package/dist/adapters/utxo/rawtx.d.ts +59 -0
- package/dist/adapters/utxo/rawtx.js +234 -0
- package/dist/adapters/utxo/rawtx.js.map +1 -0
- package/dist/adapters/utxo/reader.d.ts +36 -0
- package/dist/adapters/utxo/reader.js +265 -0
- package/dist/adapters/utxo/reader.js.map +1 -0
- package/dist/adapters/utxo/sdk.d.ts +18 -0
- package/dist/adapters/utxo/sdk.js +17 -0
- package/dist/adapters/utxo/sdk.js.map +1 -0
- package/dist/adapters/utxo/signed-psbt.d.ts +36 -0
- package/dist/adapters/utxo/signed-psbt.js +428 -0
- package/dist/adapters/utxo/signed-psbt.js.map +1 -0
- package/dist/adapters/utxo/spend.d.ts +59 -0
- package/dist/adapters/utxo/spend.js +230 -0
- package/dist/adapters/utxo/spend.js.map +1 -0
- package/dist/adapters/utxo/types.d.ts +167 -0
- package/dist/adapters/utxo/types.js +3 -0
- package/dist/adapters/utxo/types.js.map +1 -0
- package/dist/core/assets/service.d.ts +18 -0
- package/dist/core/assets/service.js +69 -0
- package/dist/core/assets/service.js.map +1 -0
- package/dist/core/blockchain/default-ref.d.ts +4 -0
- package/dist/core/blockchain/default-ref.js +16 -0
- package/dist/core/blockchain/default-ref.js.map +1 -0
- package/dist/core/blockchain/handle.d.ts +200 -0
- package/dist/core/blockchain/handle.js +579 -0
- package/dist/core/blockchain/handle.js.map +1 -0
- package/dist/core/blockchain/internal.d.ts +19 -0
- package/dist/core/blockchain/internal.js +16 -0
- package/dist/core/blockchain/internal.js.map +1 -0
- package/dist/core/blockchain/mapping.d.ts +22 -0
- package/dist/core/blockchain/mapping.js +136 -0
- package/dist/core/blockchain/mapping.js.map +1 -0
- package/dist/core/config/env.d.ts +8 -0
- package/dist/core/config/env.js +60 -0
- package/dist/core/config/env.js.map +1 -0
- package/dist/core/config/merge.d.ts +26 -0
- package/dist/core/config/merge.js +144 -0
- package/dist/core/config/merge.js.map +1 -0
- package/dist/core/config/resolve.d.ts +12 -0
- package/dist/core/config/resolve.js +251 -0
- package/dist/core/config/resolve.js.map +1 -0
- package/dist/core/config/types.d.ts +165 -0
- package/dist/core/config/types.js +3 -0
- package/dist/core/config/types.js.map +1 -0
- package/dist/core/container/builtins.d.ts +4 -0
- package/dist/core/container/builtins.js +13 -0
- package/dist/core/container/builtins.js.map +1 -0
- package/dist/core/container/container.d.ts +69 -0
- package/dist/core/container/container.js +466 -0
- package/dist/core/container/container.js.map +1 -0
- package/dist/core/container/default.d.ts +15 -0
- package/dist/core/container/default.js +70 -0
- package/dist/core/container/default.js.map +1 -0
- package/dist/core/container/internals.d.ts +54 -0
- package/dist/core/container/internals.js +21 -0
- package/dist/core/container/internals.js.map +1 -0
- package/dist/core/container/pool.d.ts +27 -0
- package/dist/core/container/pool.js +77 -0
- package/dist/core/container/pool.js.map +1 -0
- package/dist/core/driver/types.d.ts +346 -0
- package/dist/core/driver/types.js +3 -0
- package/dist/core/driver/types.js.map +1 -0
- package/dist/core/errors/codes.d.ts +153 -0
- package/dist/core/errors/codes.js +49 -0
- package/dist/core/errors/codes.js.map +1 -0
- package/dist/core/errors/error.d.ts +66 -0
- package/dist/core/errors/error.js +129 -0
- package/dist/core/errors/error.js.map +1 -0
- package/dist/core/events/bus.d.ts +12 -0
- package/dist/core/events/bus.js +46 -0
- package/dist/core/events/bus.js.map +1 -0
- package/dist/core/events/logger.d.ts +13 -0
- package/dist/core/events/logger.js +42 -0
- package/dist/core/events/logger.js.map +1 -0
- package/dist/core/events/types.d.ts +131 -0
- package/dist/core/events/types.js +3 -0
- package/dist/core/events/types.js.map +1 -0
- package/dist/core/lifecycle/engine-rules.d.ts +107 -0
- package/dist/core/lifecycle/engine-rules.js +257 -0
- package/dist/core/lifecycle/engine-rules.js.map +1 -0
- package/dist/core/lifecycle/engine.d.ts +500 -0
- package/dist/core/lifecycle/engine.js +1732 -0
- package/dist/core/lifecycle/engine.js.map +1 -0
- package/dist/core/lifecycle/evaluate.d.ts +19 -0
- package/dist/core/lifecycle/evaluate.js +72 -0
- package/dist/core/lifecycle/evaluate.js.map +1 -0
- package/dist/core/lifecycle/intent.d.ts +11 -0
- package/dist/core/lifecycle/intent.js +88 -0
- package/dist/core/lifecycle/intent.js.map +1 -0
- package/dist/core/lifecycle/monitor.d.ts +138 -0
- package/dist/core/lifecycle/monitor.js +606 -0
- package/dist/core/lifecycle/monitor.js.map +1 -0
- package/dist/core/lifecycle/observations.d.ts +17 -0
- package/dist/core/lifecycle/observations.js +59 -0
- package/dist/core/lifecycle/observations.js.map +1 -0
- package/dist/core/lifecycle/reconcile.d.ts +58 -0
- package/dist/core/lifecycle/reconcile.js +112 -0
- package/dist/core/lifecycle/reconcile.js.map +1 -0
- package/dist/core/lifecycle/views.d.ts +49 -0
- package/dist/core/lifecycle/views.js +57 -0
- package/dist/core/lifecycle/views.js.map +1 -0
- package/dist/core/lifecycle/workers.d.ts +82 -0
- package/dist/core/lifecycle/workers.js +329 -0
- package/dist/core/lifecycle/workers.js.map +1 -0
- package/dist/core/model/address.d.ts +32 -0
- package/dist/core/model/address.js +43 -0
- package/dist/core/model/address.js.map +1 -0
- package/dist/core/model/amount.d.ts +25 -0
- package/dist/core/model/amount.js +102 -0
- package/dist/core/model/amount.js.map +1 -0
- package/dist/core/model/asset.d.ts +28 -0
- package/dist/core/model/asset.js +47 -0
- package/dist/core/model/asset.js.map +1 -0
- package/dist/core/model/capability.d.ts +3 -0
- package/dist/core/model/capability.js +18 -0
- package/dist/core/model/capability.js.map +1 -0
- package/dist/core/model/chain.d.ts +63 -0
- package/dist/core/model/chain.js +8 -0
- package/dist/core/model/chain.js.map +1 -0
- package/dist/core/model/fee.d.ts +36 -0
- package/dist/core/model/fee.js +17 -0
- package/dist/core/model/fee.js.map +1 -0
- package/dist/core/model/ids.d.ts +37 -0
- package/dist/core/model/ids.js +13 -0
- package/dist/core/model/ids.js.map +1 -0
- package/dist/core/model/intent.d.ts +63 -0
- package/dist/core/model/intent.js +81 -0
- package/dist/core/model/intent.js.map +1 -0
- package/dist/core/model/ordering.d.ts +20 -0
- package/dist/core/model/ordering.js +29 -0
- package/dist/core/model/ordering.js.map +1 -0
- package/dist/core/model/transaction.d.ts +116 -0
- package/dist/{type/lib-types.js → core/model/transaction.js} +1 -1
- package/dist/core/model/transaction.js.map +1 -0
- package/dist/core/observe/scanner.d.ts +135 -0
- package/dist/core/observe/scanner.js +355 -0
- package/dist/core/observe/scanner.js.map +1 -0
- package/dist/core/ordering/reservations.d.ts +16 -0
- package/dist/core/ordering/reservations.js +53 -0
- package/dist/core/ordering/reservations.js.map +1 -0
- package/dist/core/ordering/sequence.d.ts +61 -0
- package/dist/core/ordering/sequence.js +155 -0
- package/dist/core/ordering/sequence.js.map +1 -0
- package/dist/core/registry/adapters.d.ts +10 -0
- package/dist/core/registry/adapters.js +56 -0
- package/dist/core/registry/adapters.js.map +1 -0
- package/dist/core/registry/assets.d.ts +18 -0
- package/dist/core/registry/assets.js +90 -0
- package/dist/core/registry/assets.js.map +1 -0
- package/dist/core/registry/chains.d.ts +10 -0
- package/dist/core/registry/chains.js +80 -0
- package/dist/core/registry/chains.js.map +1 -0
- package/dist/core/registry/plugin.d.ts +41 -0
- package/dist/core/registry/plugin.js +109 -0
- package/dist/core/registry/plugin.js.map +1 -0
- package/dist/core/registry/providers.d.ts +31 -0
- package/dist/core/registry/providers.js +43 -0
- package/dist/core/registry/providers.js.map +1 -0
- package/dist/core/registry/schemes.d.ts +30 -0
- package/dist/core/registry/schemes.js +84 -0
- package/dist/core/registry/schemes.js.map +1 -0
- package/dist/core/secret/fragments.d.ts +33 -0
- package/dist/core/secret/fragments.js +110 -0
- package/dist/core/secret/fragments.js.map +1 -0
- package/dist/core/secret/redact.d.ts +10 -0
- package/dist/core/secret/redact.js +110 -0
- package/dist/core/secret/redact.js.map +1 -0
- package/dist/core/secret/secret.d.ts +14 -0
- package/dist/core/secret/secret.js +42 -0
- package/dist/core/secret/secret.js.map +1 -0
- package/dist/core/signing/callback.d.ts +10 -0
- package/dist/core/signing/callback.js +22 -0
- package/dist/core/signing/callback.js.map +1 -0
- package/dist/core/signing/guard.d.ts +18 -0
- package/dist/core/signing/guard.js +72 -0
- package/dist/core/signing/guard.js.map +1 -0
- package/dist/core/signing/hd.d.ts +36 -0
- package/dist/core/signing/hd.js +167 -0
- package/dist/core/signing/hd.js.map +1 -0
- package/dist/core/signing/local.d.ts +48 -0
- package/dist/core/signing/local.js +190 -0
- package/dist/core/signing/local.js.map +1 -0
- package/dist/core/signing/orchestrator.d.ts +40 -0
- package/dist/core/signing/orchestrator.js +300 -0
- package/dist/core/signing/orchestrator.js.map +1 -0
- package/dist/core/signing/types.d.ts +64 -0
- package/dist/core/signing/types.js +3 -0
- package/dist/core/signing/types.js.map +1 -0
- package/dist/core/signing/wallet.d.ts +48 -0
- package/dist/core/signing/wallet.js +153 -0
- package/dist/core/signing/wallet.js.map +1 -0
- package/dist/core/store/clone.d.ts +25 -0
- package/dist/core/store/clone.js +71 -0
- package/dist/core/store/clone.js.map +1 -0
- package/dist/core/store/memory.d.ts +38 -0
- package/dist/core/store/memory.js +325 -0
- package/dist/core/store/memory.js.map +1 -0
- package/dist/core/store/types.d.ts +246 -0
- package/dist/core/store/types.js +117 -0
- package/dist/core/store/types.js.map +1 -0
- package/dist/core/transport/backoff.d.ts +8 -0
- package/dist/core/transport/backoff.js +27 -0
- package/dist/core/transport/backoff.js.map +1 -0
- package/dist/core/transport/circuit.d.ts +25 -0
- package/dist/core/transport/circuit.js +61 -0
- package/dist/core/transport/circuit.js.map +1 -0
- package/dist/core/transport/http-transport.d.ts +30 -0
- package/dist/core/transport/http-transport.js +1695 -0
- package/dist/core/transport/http-transport.js.map +1 -0
- package/dist/core/transport/rate-limit.d.ts +27 -0
- package/dist/core/transport/rate-limit.js +78 -0
- package/dist/core/transport/rate-limit.js.map +1 -0
- package/dist/core/transport/stale-view.d.ts +11 -0
- package/dist/core/transport/stale-view.js +17 -0
- package/dist/core/transport/stale-view.js.map +1 -0
- package/dist/core/transport/types.d.ts +144 -0
- package/dist/core/transport/types.js +6 -0
- package/dist/core/transport/types.js.map +1 -0
- package/dist/core/util/bytes.d.ts +9 -0
- package/dist/core/util/bytes.js +40 -0
- package/dist/core/util/bytes.js.map +1 -0
- package/dist/core/util/clock.d.ts +6 -0
- package/dist/core/util/clock.js +26 -0
- package/dist/core/util/clock.js.map +1 -0
- package/dist/core/util/freeze.d.ts +8 -0
- package/dist/core/util/freeze.js +31 -0
- package/dist/core/util/freeze.js.map +1 -0
- package/dist/core/util/json.d.ts +29 -0
- package/dist/core/util/json.js +165 -0
- package/dist/core/util/json.js.map +1 -0
- package/dist/core/util/names.d.ts +21 -0
- package/dist/core/util/names.js +46 -0
- package/dist/core/util/names.js.map +1 -0
- package/dist/index.d.ts +64 -14
- package/dist/index.js +105 -49
- package/dist/index.js.map +1 -1
- package/dist/native.d.ts +21 -0
- package/dist/native.js +44 -0
- package/dist/native.js.map +1 -0
- package/dist/testing/contracts/api.d.ts +12 -0
- package/dist/testing/contracts/api.js +58 -0
- package/dist/testing/contracts/api.js.map +1 -0
- package/dist/testing/contracts/cursors.d.ts +6 -0
- package/dist/testing/contracts/cursors.js +43 -0
- package/dist/testing/contracts/cursors.js.map +1 -0
- package/dist/testing/contracts/locks.d.ts +10 -0
- package/dist/testing/contracts/locks.js +63 -0
- package/dist/testing/contracts/locks.js.map +1 -0
- package/dist/testing/contracts/operations.d.ts +21 -0
- package/dist/testing/contracts/operations.js +718 -0
- package/dist/testing/contracts/operations.js.map +1 -0
- package/dist/testing/contracts/sequences.d.ts +6 -0
- package/dist/testing/contracts/sequences.js +68 -0
- package/dist/testing/contracts/sequences.js.map +1 -0
- package/dist/testing/env.d.ts +63 -0
- package/dist/testing/env.js +105 -0
- package/dist/testing/env.js.map +1 -0
- package/dist/testing/fake-chain.d.ts +118 -0
- package/dist/testing/fake-chain.js +536 -0
- package/dist/testing/fake-chain.js.map +1 -0
- package/dist/testing/fake-clock.d.ts +15 -0
- package/dist/testing/fake-clock.js +86 -0
- package/dist/testing/fake-clock.js.map +1 -0
- package/dist/testing/fake-driver.d.ts +15 -0
- package/dist/testing/fake-driver.js +458 -0
- package/dist/testing/fake-driver.js.map +1 -0
- package/dist/testing/fake-fetch.d.ts +32 -0
- package/dist/testing/fake-fetch.js +81 -0
- package/dist/testing/fake-fetch.js.map +1 -0
- package/dist/testing/fake-plugin.d.ts +30 -0
- package/dist/testing/fake-plugin.js +66 -0
- package/dist/testing/fake-plugin.js.map +1 -0
- package/dist/testing/faulty-store.d.ts +36 -0
- package/dist/testing/faulty-store.js +66 -0
- package/dist/testing/faulty-store.js.map +1 -0
- package/dist/testing/generation.d.ts +60 -0
- package/dist/testing/generation.js +252 -0
- package/dist/testing/generation.js.map +1 -0
- package/dist/testing/index.d.ts +28 -0
- package/dist/testing/index.js +51 -0
- package/dist/testing/index.js.map +1 -0
- package/package.json +188 -45
- package/dist/libs/eth/account.d.ts +0 -9
- package/dist/libs/eth/account.js +0 -58
- package/dist/libs/eth/account.js.map +0 -1
- package/dist/libs/eth/contract.d.ts +0 -7
- package/dist/libs/eth/contract.js +0 -42
- package/dist/libs/eth/contract.js.map +0 -1
- package/dist/libs/eth/index.d.ts +0 -24
- package/dist/libs/eth/index.js +0 -72
- package/dist/libs/eth/index.js.map +0 -1
- package/dist/libs/eth/transact.d.ts +0 -7
- package/dist/libs/eth/transact.js +0 -26
- package/dist/libs/eth/transact.js.map +0 -1
- package/dist/libs/index.d.ts +0 -2
- package/dist/libs/index.js +0 -19
- package/dist/libs/index.js.map +0 -1
- package/dist/libs/trx/account.d.ts +0 -9
- package/dist/libs/trx/account.js +0 -55
- package/dist/libs/trx/account.js.map +0 -1
- package/dist/libs/trx/contract.d.ts +0 -7
- package/dist/libs/trx/contract.js +0 -27
- package/dist/libs/trx/contract.js.map +0 -1
- package/dist/libs/trx/index.d.ts +0 -22
- package/dist/libs/trx/index.js +0 -64
- package/dist/libs/trx/index.js.map +0 -1
- package/dist/libs/trx/transact.d.ts +0 -7
- package/dist/libs/trx/transact.js +0 -26
- package/dist/libs/trx/transact.js.map +0 -1
- package/dist/tool/common.d.ts +0 -28
- package/dist/tool/common.js +0 -33
- package/dist/tool/common.js.map +0 -1
- package/dist/tool/eth-tools.d.ts +0 -3
- package/dist/tool/eth-tools.js +0 -33
- package/dist/tool/eth-tools.js.map +0 -1
- package/dist/tool/index.d.ts +0 -5
- package/dist/tool/index.js +0 -22
- package/dist/tool/index.js.map +0 -1
- package/dist/tool/logging.d.ts +0 -3
- package/dist/tool/logging.js +0 -11
- package/dist/tool/logging.js.map +0 -1
- package/dist/tool/options.d.ts +0 -6
- package/dist/tool/options.js +0 -41
- package/dist/tool/options.js.map +0 -1
- package/dist/tool/trx-tools.d.ts +0 -3
- package/dist/tool/trx-tools.js +0 -20
- package/dist/tool/trx-tools.js.map +0 -1
- package/dist/type/account.d.ts +0 -9
- package/dist/type/account.js.map +0 -1
- package/dist/type/common.d.ts +0 -18
- package/dist/type/common.js.map +0 -1
- package/dist/type/contract.d.ts +0 -10
- package/dist/type/contract.js.map +0 -1
- package/dist/type/index.d.ts +0 -5
- package/dist/type/index.js +0 -22
- package/dist/type/index.js.map +0 -1
- package/dist/type/lib-types.d.ts +0 -9
- package/dist/type/lib-types.js.map +0 -1
- package/dist/type/transact.d.ts +0 -7
- package/dist/type/transact.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import type { Secret } from '../secret/secret';
|
|
2
|
+
export type RetryClass = 'safe' | 'ambiguous-on-failure' | 'never-auto';
|
|
3
|
+
export type RequestPurpose = 'read' | 'monitor' | 'proof' | 'broadcast';
|
|
4
|
+
export interface EndpointConfig {
|
|
5
|
+
readonly name?: string;
|
|
6
|
+
readonly url: string | Secret<string>;
|
|
7
|
+
readonly kind?: 'rpc' | 'indexer';
|
|
8
|
+
readonly headers?: Readonly<Record<string, string | Secret<string>>>;
|
|
9
|
+
readonly priority?: number;
|
|
10
|
+
readonly rateLimit?: {
|
|
11
|
+
readonly rps: number;
|
|
12
|
+
readonly burst?: number;
|
|
13
|
+
};
|
|
14
|
+
readonly timeoutMs?: number;
|
|
15
|
+
}
|
|
16
|
+
export interface TransportOptions {
|
|
17
|
+
readonly fetch?: typeof fetch;
|
|
18
|
+
readonly maxAttempts?: number;
|
|
19
|
+
readonly baseDelayMs?: number;
|
|
20
|
+
readonly maxDelayMs?: number;
|
|
21
|
+
readonly timeoutMs?: number;
|
|
22
|
+
readonly maxLagBlocks?: number;
|
|
23
|
+
readonly proofQuorum?: number;
|
|
24
|
+
readonly failureThreshold?: number;
|
|
25
|
+
readonly openMs?: number;
|
|
26
|
+
readonly healthIntervalMs?: number;
|
|
27
|
+
/**
|
|
28
|
+
* The most bytes one answer may carry (default 64 MiB). A longer answer, by its declared
|
|
29
|
+
* length or as it arrives, is cancelled and fails as a retryable `PROVIDER_UNAVAILABLE`,
|
|
30
|
+
* so one endpoint can never make a call hold unbounded memory.
|
|
31
|
+
*/
|
|
32
|
+
readonly maxResponseBytes?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface CallOptions {
|
|
35
|
+
readonly retry?: RetryClass;
|
|
36
|
+
readonly purpose?: RequestPurpose;
|
|
37
|
+
/**
|
|
38
|
+
* Independent endpoints that must agree; `'proof'` uses `proofQuorum`, capped by the
|
|
39
|
+
* endpoints the quorum counts. A proof quorum (`'proof'` under any purpose, or any quorum
|
|
40
|
+
* for a monitor or proof purpose) with probes configured counts every endpoint not proven
|
|
41
|
+
* mismatched until three health refreshes in a row, at most one per `healthIntervalMs`,
|
|
42
|
+
* fail its probes or find its requests failing (its circuit breaker not closed), even
|
|
43
|
+
* while it cannot answer, so a shortfall decides nothing (a retryable
|
|
44
|
+
* `PROVIDER_UNAVAILABLE`); any other quorum counts the usable endpoints. An endpoint out
|
|
45
|
+
* of a proof quorum's count never answers toward the read: while its circuit breaker is
|
|
46
|
+
* half-open it is tried alongside the others (the read waits for that trial, up to its
|
|
47
|
+
* timeout, unless the endpoint has no rate-limit token free), and its disagreement or
|
|
48
|
+
* refusal can only block the read. In a proof quorum, a definitive error decides only when
|
|
49
|
+
* every endpoint asked returns an equivalent one: the same error code, HTTP status and
|
|
50
|
+
* JSON-RPC code, and for a JSON-RPC code each server defines (-32000 to -32099, and
|
|
51
|
+
* -32603) the same message. Otherwise the read is a retryable `PROVIDER_INCONSISTENT`.
|
|
52
|
+
*/
|
|
53
|
+
readonly quorum?: number | 'proof';
|
|
54
|
+
/**
|
|
55
|
+
* The part of each endpoint's result that must agree under `quorum` (default: the whole
|
|
56
|
+
* result). Lets a caller compare consensus facts only, e.g. a block's number, hash and
|
|
57
|
+
* parent hash, not fields that node implementations format differently. The call still
|
|
58
|
+
* resolves with the first endpoint's whole result. A key that throws on any result counts
|
|
59
|
+
* as a disagreement (a retryable `PROVIDER_INCONSISTENT`).
|
|
60
|
+
*/
|
|
61
|
+
readonly quorumKey?: (result: unknown) => unknown;
|
|
62
|
+
/**
|
|
63
|
+
* Parse JSON answers with exact integers: an integer outside the safe range becomes a
|
|
64
|
+
* `bigint` instead of a rounded number (`rpc`, `rpcRaw` and `http`; health probes always
|
|
65
|
+
* parse plainly). A quorum key sees the revived values.
|
|
66
|
+
*/
|
|
67
|
+
readonly exactIntegers?: boolean;
|
|
68
|
+
/** Send to this many endpoints concurrently (raw-transaction broadcasts). */
|
|
69
|
+
readonly fanout?: number;
|
|
70
|
+
readonly signal?: AbortSignal;
|
|
71
|
+
readonly timeoutMs?: number;
|
|
72
|
+
}
|
|
73
|
+
export interface HttpRequest {
|
|
74
|
+
readonly method: 'GET' | 'POST';
|
|
75
|
+
readonly path: string;
|
|
76
|
+
readonly query?: Readonly<Record<string, string>>;
|
|
77
|
+
readonly body?: unknown;
|
|
78
|
+
readonly headers?: Readonly<Record<string, string>>;
|
|
79
|
+
readonly responseType?: 'json' | 'text';
|
|
80
|
+
/**
|
|
81
|
+
* Low-cardinality template label used for event and log method fields instead of the
|
|
82
|
+
* raw path, e.g. `'/address/:address/utxo'`. Must contain no identifiers (addresses,
|
|
83
|
+
* hashes, ids). When omitted, events fall back to the bare HTTP method.
|
|
84
|
+
*/
|
|
85
|
+
readonly route?: string;
|
|
86
|
+
}
|
|
87
|
+
/** Single-attempt calls against one specific endpoint (used by health probes). */
|
|
88
|
+
export interface EndpointCall {
|
|
89
|
+
rpc<T = unknown>(method: string, params?: unknown): Promise<T>;
|
|
90
|
+
http<T = unknown>(request: HttpRequest): Promise<T>;
|
|
91
|
+
}
|
|
92
|
+
export interface HealthProbes {
|
|
93
|
+
readonly identity?: (call: EndpointCall) => Promise<string>;
|
|
94
|
+
readonly expectedIdentity?: string;
|
|
95
|
+
readonly height?: (call: EndpointCall) => Promise<bigint>;
|
|
96
|
+
}
|
|
97
|
+
export type EndpointState = 'healthy' | 'lagging' | 'open' | 'half-open' | 'disabled' | 'unknown';
|
|
98
|
+
export interface EndpointStatus {
|
|
99
|
+
readonly id: string;
|
|
100
|
+
readonly kind: 'rpc' | 'indexer';
|
|
101
|
+
readonly state: EndpointState;
|
|
102
|
+
readonly failures: number;
|
|
103
|
+
readonly height?: bigint;
|
|
104
|
+
readonly lag?: bigint;
|
|
105
|
+
readonly latencyMs?: number;
|
|
106
|
+
readonly reason?: string;
|
|
107
|
+
}
|
|
108
|
+
export interface Transport {
|
|
109
|
+
readonly id: string;
|
|
110
|
+
rpc<T = unknown>(method: string, params?: unknown, options?: CallOptions): Promise<T>;
|
|
111
|
+
/** Posts an arbitrary JSON-RPC payload (single or batch) and returns the parsed body. */
|
|
112
|
+
rpcRaw(payload: unknown, options?: CallOptions): Promise<unknown>;
|
|
113
|
+
http<T = unknown>(request: HttpRequest, options?: CallOptions): Promise<T>;
|
|
114
|
+
/** fetch-compatible function for SDKs; only `PLACEHOLDER_ORIGIN` URLs are accepted. */
|
|
115
|
+
createFetch(classify?: (url: URL, init: RequestInit | undefined) => CallOptions): typeof fetch;
|
|
116
|
+
setProbes(probes: HealthProbes): void;
|
|
117
|
+
/** Whether any health probe (`identity` and/or `height`) has ever been configured via
|
|
118
|
+
* `setProbes`. A transport with none configured can never mark an endpoint 'healthy' or
|
|
119
|
+
* 'lagging' — its endpoints stay 'unknown' forever, which callers like `Blockchain.ready()`
|
|
120
|
+
* treat as acceptable only in that case. */
|
|
121
|
+
hasProbes(): boolean;
|
|
122
|
+
refreshHealth(signal?: AbortSignal): Promise<void>;
|
|
123
|
+
ensureFreshHealth(signal?: AbortSignal): Promise<void>;
|
|
124
|
+
status(): EndpointStatus[];
|
|
125
|
+
/**
|
|
126
|
+
* Highest verified block height: a high-water mark (the stale-view guard of monitors
|
|
127
|
+
* and scanners). It drops in two cases only: a height taken before an identity probe
|
|
128
|
+
* existed stops counting once its endpoint turns out to serve another network, and a
|
|
129
|
+
* peak that no verified endpoint comes within `maxLagBlocks` of for three health
|
|
130
|
+
* refreshes in a row falls back to the verified best, so one forged far-future head
|
|
131
|
+
* cannot keep every view stale until restart.
|
|
132
|
+
*/
|
|
133
|
+
highestHeight(): bigint | undefined;
|
|
134
|
+
/**
|
|
135
|
+
* The lag tolerance in effect (`TransportOptions.maxLagBlocks`). The driver pool
|
|
136
|
+
* resolves it in this order: the chain's `maxLagBlocks` config, else the root
|
|
137
|
+
* `transport.maxLagBlocks`, else the plugin network's own, else the built-in default.
|
|
138
|
+
* An endpoint further behind is lagging, and a view further behind `highestHeight()` is
|
|
139
|
+
* stale.
|
|
140
|
+
*/
|
|
141
|
+
readonly maxLagBlocks: number;
|
|
142
|
+
}
|
|
143
|
+
/** SDKs are configured with this origin; the transport maps it onto real endpoints. */
|
|
144
|
+
export declare const PLACEHOLDER_ORIGIN = "https://transport.crypto-aio.invalid";
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLACEHOLDER_ORIGIN = void 0;
|
|
4
|
+
/** SDKs are configured with this origin; the transport maps it onto real endpoints. */
|
|
5
|
+
exports.PLACEHOLDER_ORIGIN = 'https://transport.crypto-aio.invalid';
|
|
6
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/transport/types.ts"],"names":[],"mappings":";;;AAyJA,uFAAuF;AAC1E,QAAA,kBAAkB,GAAG,sCAAsC,CAAC","sourcesContent":["import type { Secret } from '../secret/secret';\n\nexport type RetryClass = 'safe' | 'ambiguous-on-failure' | 'never-auto';\nexport type RequestPurpose = 'read' | 'monitor' | 'proof' | 'broadcast';\n\nexport interface EndpointConfig {\n readonly name?: string;\n readonly url: string | Secret<string>;\n readonly kind?: 'rpc' | 'indexer';\n readonly headers?: Readonly<Record<string, string | Secret<string>>>;\n readonly priority?: number;\n readonly rateLimit?: { readonly rps: number; readonly burst?: number };\n readonly timeoutMs?: number;\n}\n\nexport interface TransportOptions {\n readonly fetch?: typeof fetch;\n readonly maxAttempts?: number;\n readonly baseDelayMs?: number;\n readonly maxDelayMs?: number;\n readonly timeoutMs?: number;\n readonly maxLagBlocks?: number;\n readonly proofQuorum?: number;\n readonly failureThreshold?: number;\n readonly openMs?: number;\n readonly healthIntervalMs?: number;\n /**\n * The most bytes one answer may carry (default 64 MiB). A longer answer, by its declared\n * length or as it arrives, is cancelled and fails as a retryable `PROVIDER_UNAVAILABLE`,\n * so one endpoint can never make a call hold unbounded memory.\n */\n readonly maxResponseBytes?: number;\n}\n\nexport interface CallOptions {\n readonly retry?: RetryClass;\n readonly purpose?: RequestPurpose;\n /**\n * Independent endpoints that must agree; `'proof'` uses `proofQuorum`, capped by the\n * endpoints the quorum counts. A proof quorum (`'proof'` under any purpose, or any quorum\n * for a monitor or proof purpose) with probes configured counts every endpoint not proven\n * mismatched until three health refreshes in a row, at most one per `healthIntervalMs`,\n * fail its probes or find its requests failing (its circuit breaker not closed), even\n * while it cannot answer, so a shortfall decides nothing (a retryable\n * `PROVIDER_UNAVAILABLE`); any other quorum counts the usable endpoints. An endpoint out\n * of a proof quorum's count never answers toward the read: while its circuit breaker is\n * half-open it is tried alongside the others (the read waits for that trial, up to its\n * timeout, unless the endpoint has no rate-limit token free), and its disagreement or\n * refusal can only block the read. In a proof quorum, a definitive error decides only when\n * every endpoint asked returns an equivalent one: the same error code, HTTP status and\n * JSON-RPC code, and for a JSON-RPC code each server defines (-32000 to -32099, and\n * -32603) the same message. Otherwise the read is a retryable `PROVIDER_INCONSISTENT`.\n */\n readonly quorum?: number | 'proof';\n /**\n * The part of each endpoint's result that must agree under `quorum` (default: the whole\n * result). Lets a caller compare consensus facts only, e.g. a block's number, hash and\n * parent hash, not fields that node implementations format differently. The call still\n * resolves with the first endpoint's whole result. A key that throws on any result counts\n * as a disagreement (a retryable `PROVIDER_INCONSISTENT`).\n */\n readonly quorumKey?: (result: unknown) => unknown;\n /**\n * Parse JSON answers with exact integers: an integer outside the safe range becomes a\n * `bigint` instead of a rounded number (`rpc`, `rpcRaw` and `http`; health probes always\n * parse plainly). A quorum key sees the revived values.\n */\n readonly exactIntegers?: boolean;\n /** Send to this many endpoints concurrently (raw-transaction broadcasts). */\n readonly fanout?: number;\n readonly signal?: AbortSignal;\n readonly timeoutMs?: number;\n}\n\nexport interface HttpRequest {\n readonly method: 'GET' | 'POST';\n readonly path: string;\n readonly query?: Readonly<Record<string, string>>;\n readonly body?: unknown;\n readonly headers?: Readonly<Record<string, string>>;\n readonly responseType?: 'json' | 'text';\n /**\n * Low-cardinality template label used for event and log method fields instead of the\n * raw path, e.g. `'/address/:address/utxo'`. Must contain no identifiers (addresses,\n * hashes, ids). When omitted, events fall back to the bare HTTP method.\n */\n readonly route?: string;\n}\n\n/** Single-attempt calls against one specific endpoint (used by health probes). */\nexport interface EndpointCall {\n rpc<T = unknown>(method: string, params?: unknown): Promise<T>;\n http<T = unknown>(request: HttpRequest): Promise<T>;\n}\n\nexport interface HealthProbes {\n readonly identity?: (call: EndpointCall) => Promise<string>;\n readonly expectedIdentity?: string;\n readonly height?: (call: EndpointCall) => Promise<bigint>;\n}\n\nexport type EndpointState =\n 'healthy' | 'lagging' | 'open' | 'half-open' | 'disabled' | 'unknown';\n\nexport interface EndpointStatus {\n readonly id: string;\n readonly kind: 'rpc' | 'indexer';\n readonly state: EndpointState;\n readonly failures: number;\n readonly height?: bigint;\n readonly lag?: bigint;\n readonly latencyMs?: number;\n readonly reason?: string;\n}\n\nexport interface Transport {\n readonly id: string;\n rpc<T = unknown>(method: string, params?: unknown, options?: CallOptions): Promise<T>;\n /** Posts an arbitrary JSON-RPC payload (single or batch) and returns the parsed body. */\n rpcRaw(payload: unknown, options?: CallOptions): Promise<unknown>;\n http<T = unknown>(request: HttpRequest, options?: CallOptions): Promise<T>;\n /** fetch-compatible function for SDKs; only `PLACEHOLDER_ORIGIN` URLs are accepted. */\n createFetch(\n classify?: (url: URL, init: RequestInit | undefined) => CallOptions,\n ): typeof fetch;\n setProbes(probes: HealthProbes): void;\n /** Whether any health probe (`identity` and/or `height`) has ever been configured via\n * `setProbes`. A transport with none configured can never mark an endpoint 'healthy' or\n * 'lagging' — its endpoints stay 'unknown' forever, which callers like `Blockchain.ready()`\n * treat as acceptable only in that case. */\n hasProbes(): boolean;\n refreshHealth(signal?: AbortSignal): Promise<void>;\n ensureFreshHealth(signal?: AbortSignal): Promise<void>;\n status(): EndpointStatus[];\n /**\n * Highest verified block height: a high-water mark (the stale-view guard of monitors\n * and scanners). It drops in two cases only: a height taken before an identity probe\n * existed stops counting once its endpoint turns out to serve another network, and a\n * peak that no verified endpoint comes within `maxLagBlocks` of for three health\n * refreshes in a row falls back to the verified best, so one forged far-future head\n * cannot keep every view stale until restart.\n */\n highestHeight(): bigint | undefined;\n /**\n * The lag tolerance in effect (`TransportOptions.maxLagBlocks`). The driver pool\n * resolves it in this order: the chain's `maxLagBlocks` config, else the root\n * `transport.maxLagBlocks`, else the plugin network's own, else the built-in default.\n * An endpoint further behind is lagging, and a view further behind `highestHeight()` is\n * stale.\n */\n readonly maxLagBlocks: number;\n}\n\n/** SDKs are configured with this origin; the transport maps it onto real endpoints. */\nexport const PLACEHOLDER_ORIGIN = 'https://transport.crypto-aio.invalid';\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { concatBytes, randomBytes, utf8ToBytes } from '@noble/hashes/utils';
|
|
2
|
+
export { concatBytes, randomBytes, utf8ToBytes };
|
|
3
|
+
/** Decodes hex with or without a `0x` prefix. Throws `TypeError` on malformed input. */
|
|
4
|
+
export declare function fromHex(hex: string): Uint8Array;
|
|
5
|
+
export declare function toHex(bytes: Uint8Array, prefix?: boolean): string;
|
|
6
|
+
export declare function bytesToUtf8(bytes: Uint8Array): string;
|
|
7
|
+
/** Length-checked comparison that does not stop at the first differing byte. */
|
|
8
|
+
export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
|
|
9
|
+
export declare function randomId(prefix: string): string;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.utf8ToBytes = exports.randomBytes = exports.concatBytes = void 0;
|
|
4
|
+
exports.fromHex = fromHex;
|
|
5
|
+
exports.toHex = toHex;
|
|
6
|
+
exports.bytesToUtf8 = bytesToUtf8;
|
|
7
|
+
exports.equalBytes = equalBytes;
|
|
8
|
+
exports.randomId = randomId;
|
|
9
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
10
|
+
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return utils_1.concatBytes; } });
|
|
11
|
+
Object.defineProperty(exports, "randomBytes", { enumerable: true, get: function () { return utils_1.randomBytes; } });
|
|
12
|
+
Object.defineProperty(exports, "utf8ToBytes", { enumerable: true, get: function () { return utils_1.utf8ToBytes; } });
|
|
13
|
+
/** Decodes hex with or without a `0x` prefix. Throws `TypeError` on malformed input. */
|
|
14
|
+
function fromHex(hex) {
|
|
15
|
+
const clean = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
|
|
16
|
+
if (clean.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(clean)) {
|
|
17
|
+
throw new TypeError('invalid hex string');
|
|
18
|
+
}
|
|
19
|
+
return (0, utils_1.hexToBytes)(clean);
|
|
20
|
+
}
|
|
21
|
+
function toHex(bytes, prefix = false) {
|
|
22
|
+
const hex = (0, utils_1.bytesToHex)(bytes);
|
|
23
|
+
return prefix ? `0x${hex}` : hex;
|
|
24
|
+
}
|
|
25
|
+
function bytesToUtf8(bytes) {
|
|
26
|
+
return new TextDecoder().decode(bytes);
|
|
27
|
+
}
|
|
28
|
+
/** Length-checked comparison that does not stop at the first differing byte. */
|
|
29
|
+
function equalBytes(a, b) {
|
|
30
|
+
if (a.length !== b.length)
|
|
31
|
+
return false;
|
|
32
|
+
let diff = 0;
|
|
33
|
+
for (let i = 0; i < a.length; i++)
|
|
34
|
+
diff |= (a[i] ?? 0) ^ (b[i] ?? 0);
|
|
35
|
+
return diff === 0;
|
|
36
|
+
}
|
|
37
|
+
function randomId(prefix) {
|
|
38
|
+
return `${prefix}_${(0, utils_1.bytesToHex)((0, utils_1.randomBytes)(12))}`;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytes.js","sourceRoot":"","sources":["../../../src/core/util/bytes.ts"],"names":[],"mappings":";;;AAWA,0BAMC;AAED,sBAGC;AAED,kCAEC;AAGD,gCAKC;AAED,4BAEC;AAtCD,+CAM6B;AAEpB,4FANP,mBAAW,OAMO;AAAE,4FAJpB,mBAAW,OAIoB;AAAE,4FAHjC,mBAAW,OAGiC;AAE9C,wFAAwF;AACxF,SAAgB,OAAO,CAAC,GAAW;IACjC,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;IAChF,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5D,MAAM,IAAI,SAAS,CAAC,oBAAoB,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC;AAC3B,CAAC;AAED,SAAgB,KAAK,CAAC,KAAiB,EAAE,MAAM,GAAG,KAAK;IACrD,MAAM,GAAG,GAAG,IAAA,kBAAU,EAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AACnC,CAAC;AAED,SAAgB,WAAW,CAAC,KAAiB;IAC3C,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED,gFAAgF;AAChF,SAAgB,UAAU,CAAC,CAAa,EAAE,CAAa;IACrD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IACrE,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC;AAED,SAAgB,QAAQ,CAAC,MAAc;IACrC,OAAO,GAAG,MAAM,IAAI,IAAA,kBAAU,EAAC,IAAA,mBAAW,EAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AACpD,CAAC","sourcesContent":["import {\n bytesToHex,\n concatBytes,\n hexToBytes,\n randomBytes,\n utf8ToBytes,\n} from '@noble/hashes/utils';\n\nexport { concatBytes, randomBytes, utf8ToBytes };\n\n/** Decodes hex with or without a `0x` prefix. Throws `TypeError` on malformed input. */\nexport function fromHex(hex: string): Uint8Array {\n const clean = hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;\n if (clean.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(clean)) {\n throw new TypeError('invalid hex string');\n }\n return hexToBytes(clean);\n}\n\nexport function toHex(bytes: Uint8Array, prefix = false): string {\n const hex = bytesToHex(bytes);\n return prefix ? `0x${hex}` : hex;\n}\n\nexport function bytesToUtf8(bytes: Uint8Array): string {\n return new TextDecoder().decode(bytes);\n}\n\n/** Length-checked comparison that does not stop at the first differing byte. */\nexport function equalBytes(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= (a[i] ?? 0) ^ (b[i] ?? 0);\n return diff === 0;\n}\n\nexport function randomId(prefix: string): string {\n return `${prefix}_${bytesToHex(randomBytes(12))}`;\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.systemClock = void 0;
|
|
4
|
+
exports.abortReason = abortReason;
|
|
5
|
+
function abortReason(signal) {
|
|
6
|
+
return signal.reason ?? new Error('The operation was aborted');
|
|
7
|
+
}
|
|
8
|
+
exports.systemClock = {
|
|
9
|
+
now: () => Date.now(),
|
|
10
|
+
sleep: (ms, signal) => new Promise((resolve, reject) => {
|
|
11
|
+
if (signal?.aborted) {
|
|
12
|
+
reject(abortReason(signal));
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const onAbort = () => {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
reject(abortReason(signal));
|
|
18
|
+
};
|
|
19
|
+
const timer = setTimeout(() => {
|
|
20
|
+
signal?.removeEventListener('abort', onAbort);
|
|
21
|
+
resolve();
|
|
22
|
+
}, Math.max(0, ms));
|
|
23
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=clock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clock.js","sourceRoot":"","sources":["../../../src/core/util/clock.ts"],"names":[],"mappings":";;;AAKA,kCAEC;AAFD,SAAgB,WAAW,CAAC,MAAmB;IAC7C,OAAO,MAAM,CAAC,MAAM,IAAI,IAAI,KAAK,CAAC,2BAA2B,CAAC,CAAC;AACjE,CAAC;AAEY,QAAA,WAAW,GAAU;IAChC,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;IACrB,KAAK,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,EAAE,CACpB,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACpC,IAAI,MAAM,EAAE,OAAO,EAAE,CAAC;YACpB,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;YAC5B,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,GAAG,EAAE;YACnB,YAAY,CAAC,KAAK,CAAC,CAAC;YACpB,MAAM,CAAC,WAAW,CAAC,MAAqB,CAAC,CAAC,CAAC;QAC7C,CAAC,CAAC;QACF,MAAM,KAAK,GAAG,UAAU,CACtB,GAAG,EAAE;YACH,MAAM,EAAE,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;YAC9C,OAAO,EAAE,CAAC;QACZ,CAAC,EACD,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAChB,CAAC;QACF,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7D,CAAC,CAAC;CACL,CAAC","sourcesContent":["export interface Clock {\n now(): number;\n sleep(ms: number, signal?: AbortSignal): Promise<void>;\n}\n\nexport function abortReason(signal: AbortSignal): unknown {\n return signal.reason ?? new Error('The operation was aborted');\n}\n\nexport const systemClock: Clock = {\n now: () => Date.now(),\n sleep: (ms, signal) =>\n new Promise<void>((resolve, reject) => {\n if (signal?.aborted) {\n reject(abortReason(signal));\n return;\n }\n const onAbort = () => {\n clearTimeout(timer);\n reject(abortReason(signal as AbortSignal));\n };\n const timer = setTimeout(\n () => {\n signal?.removeEventListener('abort', onAbort);\n resolve();\n },\n Math.max(0, ms),\n );\n signal?.addEventListener('abort', onAbort, { once: true });\n }),\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Freezes plain data all the way down: every array and every plain object reachable
|
|
3
|
+
* from `value`, so data that handles share (chain tables, presets, resolved config) cannot
|
|
4
|
+
* be changed through any of them. Class instances (a `Signer`, a `Secret`, a `Uint8Array`)
|
|
5
|
+
* and functions keep their identity and are never frozen. A reference cycle is
|
|
6
|
+
* walked once, so it freezes instead of overflowing the stack.
|
|
7
|
+
*/
|
|
8
|
+
export declare function deepFreeze<T>(value: T): T;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepFreeze = deepFreeze;
|
|
4
|
+
/**
|
|
5
|
+
* Freezes plain data all the way down: every array and every plain object reachable
|
|
6
|
+
* from `value`, so data that handles share (chain tables, presets, resolved config) cannot
|
|
7
|
+
* be changed through any of them. Class instances (a `Signer`, a `Secret`, a `Uint8Array`)
|
|
8
|
+
* and functions keep their identity and are never frozen. A reference cycle is
|
|
9
|
+
* walked once, so it freezes instead of overflowing the stack.
|
|
10
|
+
*/
|
|
11
|
+
function deepFreeze(value) {
|
|
12
|
+
freezeOnce(value, new WeakSet());
|
|
13
|
+
return value;
|
|
14
|
+
}
|
|
15
|
+
function freezeOnce(value, seen) {
|
|
16
|
+
if (!isPlainData(value) || seen.has(value))
|
|
17
|
+
return;
|
|
18
|
+
seen.add(value);
|
|
19
|
+
for (const item of Object.values(value))
|
|
20
|
+
freezeOnce(item, seen);
|
|
21
|
+
Object.freeze(value);
|
|
22
|
+
}
|
|
23
|
+
function isPlainData(value) {
|
|
24
|
+
if (value === null || typeof value !== 'object')
|
|
25
|
+
return false;
|
|
26
|
+
if (Array.isArray(value))
|
|
27
|
+
return true;
|
|
28
|
+
const proto = Object.getPrototypeOf(value);
|
|
29
|
+
return proto === Object.prototype || proto === null;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=freeze.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"freeze.js","sourceRoot":"","sources":["../../../src/core/util/freeze.ts"],"names":[],"mappings":";;AAOA,gCAGC;AAVD;;;;;;GAMG;AACH,SAAgB,UAAU,CAAI,KAAQ;IACpC,UAAU,CAAC,KAAK,EAAE,IAAI,OAAO,EAAU,CAAC,CAAC;IACzC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,UAAU,CAAC,KAAc,EAAE,IAAqB;IACvD,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAO;IACnD,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC;QAAE,UAAU,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAChE,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,WAAW,CAAC,KAAc;IACjC,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC9D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IACtC,MAAM,KAAK,GAAY,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;IACpD,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAC;AACtD,CAAC","sourcesContent":["/**\n * Freezes plain data all the way down: every array and every plain object reachable\n * from `value`, so data that handles share (chain tables, presets, resolved config) cannot\n * be changed through any of them. Class instances (a `Signer`, a `Secret`, a `Uint8Array`)\n * and functions keep their identity and are never frozen. A reference cycle is\n * walked once, so it freezes instead of overflowing the stack.\n */\nexport function deepFreeze<T>(value: T): T {\n freezeOnce(value, new WeakSet<object>());\n return value;\n}\n\nfunction freezeOnce(value: unknown, seen: WeakSet<object>): void {\n if (!isPlainData(value) || seen.has(value)) return;\n seen.add(value);\n for (const item of Object.values(value)) freezeOnce(item, seen);\n Object.freeze(value);\n}\n\nfunction isPlainData(value: unknown): value is object {\n if (value === null || typeof value !== 'object') return false;\n if (Array.isArray(value)) return true;\n const proto: unknown = Object.getPrototypeOf(value);\n return proto === Object.prototype || proto === null;\n}\n"]}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deterministic JSON for hashing: object keys sorted, `undefined` properties omitted,
|
|
3
|
+
* bigint → `{"$bigint":"<decimal>"}`, Uint8Array → `{"$bytes":"<hex>"}`.
|
|
4
|
+
*/
|
|
5
|
+
export declare function canonicalJson(value: unknown): string;
|
|
6
|
+
/**
|
|
7
|
+
* Deterministic JSON for comparing quorum answers, which no two different values
|
|
8
|
+
* share. `canonicalJson` writes a bigint as `{"$bigint":…}` and bytes as `{"$bytes":…}`, the
|
|
9
|
+
* same text as a plain object with that key, so one endpoint's object could agree with
|
|
10
|
+
* another's bigint; it also drops a `__proto__` key. Here every plain-object key that starts
|
|
11
|
+
* with `$` gains one more `$`, and `__proto__` becomes `$__proto__`, before tagging, so no
|
|
12
|
+
* two keys become one and no plain object's key is ever `$bigint` or `$bytes`.
|
|
13
|
+
* `canonicalJson` itself is unchanged: the intent hash depends on it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function quorumJson(value: unknown): string;
|
|
16
|
+
/**
|
|
17
|
+
* `JSON.parse`, optionally exact for integers: with `exactIntegers`, every integer
|
|
18
|
+
* literal outside the safe range becomes a `bigint` read from its source text (Node ≥ 22
|
|
19
|
+
* `JSON.parse` source text access), so a u64 amount is never rounded. Safe integers,
|
|
20
|
+
* fractions and exponents stay numbers, so answers keep their shape for ordinary values.
|
|
21
|
+
* With the flag, an integer literal longer than 80 digits (sign excluded) is malformed and
|
|
22
|
+
* throws a `SyntaxError`, as `JSON.parse` does: no amount is that long (u256 has 78 digits),
|
|
23
|
+
* and `BigInt()` of a multi-megabyte literal would take seconds.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseJson(text: string, exactIntegers?: boolean): unknown;
|
|
26
|
+
export declare function sha256Hex(input: string | Uint8Array): string;
|
|
27
|
+
/** JSON that round-trips bigint and Uint8Array (for external store implementations). */
|
|
28
|
+
export declare function stringifyTagged(value: unknown): string;
|
|
29
|
+
export declare function parseTagged<T = unknown>(text: string): T;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.canonicalJson = canonicalJson;
|
|
4
|
+
exports.quorumJson = quorumJson;
|
|
5
|
+
exports.parseJson = parseJson;
|
|
6
|
+
exports.sha256Hex = sha256Hex;
|
|
7
|
+
exports.stringifyTagged = stringifyTagged;
|
|
8
|
+
exports.parseTagged = parseTagged;
|
|
9
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
10
|
+
const utils_1 = require("@noble/hashes/utils");
|
|
11
|
+
const bytes_1 = require("./bytes");
|
|
12
|
+
/**
|
|
13
|
+
* Deterministic JSON for hashing: object keys sorted, `undefined` properties omitted,
|
|
14
|
+
* bigint → `{"$bigint":"<decimal>"}`, Uint8Array → `{"$bytes":"<hex>"}`.
|
|
15
|
+
*/
|
|
16
|
+
function canonicalJson(value) {
|
|
17
|
+
return JSON.stringify(canonicalize(value, new WeakSet()));
|
|
18
|
+
}
|
|
19
|
+
function canonicalize(value, seen) {
|
|
20
|
+
if (value === null)
|
|
21
|
+
return null;
|
|
22
|
+
switch (typeof value) {
|
|
23
|
+
case 'string':
|
|
24
|
+
case 'boolean':
|
|
25
|
+
return value;
|
|
26
|
+
case 'number':
|
|
27
|
+
if (!Number.isFinite(value))
|
|
28
|
+
throw new TypeError('canonicalJson: non-finite number');
|
|
29
|
+
return value;
|
|
30
|
+
case 'bigint':
|
|
31
|
+
return { $bigint: value.toString() };
|
|
32
|
+
case 'undefined':
|
|
33
|
+
return undefined;
|
|
34
|
+
case 'object':
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
throw new TypeError(`canonicalJson: unsupported type ${typeof value}`);
|
|
38
|
+
}
|
|
39
|
+
if (value instanceof Uint8Array)
|
|
40
|
+
return { $bytes: (0, bytes_1.toHex)(value) };
|
|
41
|
+
if (seen.has(value))
|
|
42
|
+
throw new TypeError('canonicalJson: circular structure');
|
|
43
|
+
seen.add(value);
|
|
44
|
+
try {
|
|
45
|
+
if (Array.isArray(value)) {
|
|
46
|
+
return value.map((item) => {
|
|
47
|
+
const c = canonicalize(item, seen);
|
|
48
|
+
return c === undefined ? null : c;
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const proto = Object.getPrototypeOf(value);
|
|
52
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
53
|
+
const toJSON = value.toJSON;
|
|
54
|
+
if (typeof toJSON === 'function')
|
|
55
|
+
return canonicalize(toJSON.call(value), seen);
|
|
56
|
+
throw new TypeError('canonicalJson: only plain objects are supported');
|
|
57
|
+
}
|
|
58
|
+
const out = {};
|
|
59
|
+
for (const key of Object.keys(value).sort()) {
|
|
60
|
+
const c = canonicalize(value[key], seen);
|
|
61
|
+
if (c !== undefined)
|
|
62
|
+
out[key] = c;
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
seen.delete(value);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Deterministic JSON for comparing quorum answers, which no two different values
|
|
72
|
+
* share. `canonicalJson` writes a bigint as `{"$bigint":…}` and bytes as `{"$bytes":…}`, the
|
|
73
|
+
* same text as a plain object with that key, so one endpoint's object could agree with
|
|
74
|
+
* another's bigint; it also drops a `__proto__` key. Here every plain-object key that starts
|
|
75
|
+
* with `$` gains one more `$`, and `__proto__` becomes `$__proto__`, before tagging, so no
|
|
76
|
+
* two keys become one and no plain object's key is ever `$bigint` or `$bytes`.
|
|
77
|
+
* `canonicalJson` itself is unchanged: the intent hash depends on it.
|
|
78
|
+
*/
|
|
79
|
+
function quorumJson(value) {
|
|
80
|
+
return canonicalJson(escapeKeys(value, new WeakSet()));
|
|
81
|
+
}
|
|
82
|
+
/** `value` with the keys of its plain objects escaped as `quorumJson` describes. */
|
|
83
|
+
function escapeKeys(value, seen) {
|
|
84
|
+
if (value === null || typeof value !== 'object' || value instanceof Uint8Array)
|
|
85
|
+
return value;
|
|
86
|
+
if (seen.has(value))
|
|
87
|
+
throw new TypeError('canonicalJson: circular structure');
|
|
88
|
+
seen.add(value);
|
|
89
|
+
try {
|
|
90
|
+
if (Array.isArray(value))
|
|
91
|
+
return value.map((item) => escapeKeys(item, seen));
|
|
92
|
+
const proto = Object.getPrototypeOf(value);
|
|
93
|
+
if (proto !== Object.prototype && proto !== null) {
|
|
94
|
+
// As canonicalJson reads it: its toJSON() value, or (without one) a TypeError there.
|
|
95
|
+
const toJSON = value.toJSON;
|
|
96
|
+
return typeof toJSON === 'function' ? escapeKeys(toJSON.call(value), seen) : value;
|
|
97
|
+
}
|
|
98
|
+
const out = {};
|
|
99
|
+
for (const key of Object.keys(value)) {
|
|
100
|
+
const escaped = key.startsWith('$') || key === '__proto__' ? `$${key}` : key;
|
|
101
|
+
out[escaped] = escapeKeys(value[key], seen);
|
|
102
|
+
}
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
seen.delete(value);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/** The longest integer literal `parseJson` revives, in digits without the sign. */
|
|
110
|
+
const MAX_EXACT_DIGITS = 80;
|
|
111
|
+
/**
|
|
112
|
+
* `JSON.parse`, optionally exact for integers: with `exactIntegers`, every integer
|
|
113
|
+
* literal outside the safe range becomes a `bigint` read from its source text (Node ≥ 22
|
|
114
|
+
* `JSON.parse` source text access), so a u64 amount is never rounded. Safe integers,
|
|
115
|
+
* fractions and exponents stay numbers, so answers keep their shape for ordinary values.
|
|
116
|
+
* With the flag, an integer literal longer than 80 digits (sign excluded) is malformed and
|
|
117
|
+
* throws a `SyntaxError`, as `JSON.parse` does: no amount is that long (u256 has 78 digits),
|
|
118
|
+
* and `BigInt()` of a multi-megabyte literal would take seconds.
|
|
119
|
+
*/
|
|
120
|
+
function parseJson(text, exactIntegers = false) {
|
|
121
|
+
// A run of 16 digits is the shortest literal that can leave the safe range; without one,
|
|
122
|
+
// the reviver (about 7 times slower on large bodies) cannot change anything.
|
|
123
|
+
if (!exactIntegers || !/\d{16}/.test(text))
|
|
124
|
+
return JSON.parse(text);
|
|
125
|
+
return JSON.parse(text, (_key, value, context) => {
|
|
126
|
+
const source = context?.source;
|
|
127
|
+
if (typeof value !== 'number' ||
|
|
128
|
+
Number.isSafeInteger(value) ||
|
|
129
|
+
source === undefined ||
|
|
130
|
+
!/^-?\d+$/.test(source))
|
|
131
|
+
return value;
|
|
132
|
+
const digits = source.startsWith('-') ? source.length - 1 : source.length;
|
|
133
|
+
if (digits > MAX_EXACT_DIGITS)
|
|
134
|
+
throw new SyntaxError(`integer literal longer than ${MAX_EXACT_DIGITS} digits`);
|
|
135
|
+
return BigInt(source);
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
function sha256Hex(input) {
|
|
139
|
+
return (0, utils_1.bytesToHex)((0, sha256_1.sha256)(typeof input === 'string' ? (0, utils_1.utf8ToBytes)(input) : input));
|
|
140
|
+
}
|
|
141
|
+
/** JSON that round-trips bigint and Uint8Array (for external store implementations). */
|
|
142
|
+
function stringifyTagged(value) {
|
|
143
|
+
return JSON.stringify(value, (_key, v) => {
|
|
144
|
+
if (typeof v === 'bigint')
|
|
145
|
+
return { $bigint: v.toString() };
|
|
146
|
+
if (v instanceof Uint8Array)
|
|
147
|
+
return { $bytes: (0, bytes_1.toHex)(v) };
|
|
148
|
+
return v;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
function parseTagged(text) {
|
|
152
|
+
return JSON.parse(text, (_key, v) => {
|
|
153
|
+
if (v !== null && typeof v === 'object' && !Array.isArray(v)) {
|
|
154
|
+
const o = v;
|
|
155
|
+
if (Object.keys(o).length === 1) {
|
|
156
|
+
if (typeof o.$bigint === 'string')
|
|
157
|
+
return BigInt(o.$bigint);
|
|
158
|
+
if (typeof o.$bytes === 'string')
|
|
159
|
+
return (0, bytes_1.fromHex)(o.$bytes);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return v;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../../../src/core/util/json.ts"],"names":[],"mappings":";;AAQA,sCAEC;AAyDD,gCAEC;AAuCD,8BAqBC;AAED,8BAEC;AAGD,0CAMC;AAED,kCAWC;AA3JD,iDAA8C;AAC9C,+CAA8D;AAC9D,mCAAyC;AAEzC;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAAc;IAC1C,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,OAAO,EAAE,CAAC,CAAC,CAAC;AAC5D,CAAC;AAED,SAAS,YAAY,CAAC,KAAc,EAAE,IAAqB;IACzD,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAChC,QAAQ,OAAO,KAAK,EAAE,CAAC;QACrB,KAAK,QAAQ,CAAC;QACd,KAAK,SAAS;YACZ,OAAO,KAAK,CAAC;QACf,KAAK,QAAQ;YACX,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;gBACzB,MAAM,IAAI,SAAS,CAAC,kCAAkC,CAAC,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,KAAK,QAAQ;YACX,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,CAAC;QACvC,KAAK,WAAW;YACd,OAAO,SAAS,CAAC;QACnB,KAAK,QAAQ;YACX,MAAM;QACR;YACE,MAAM,IAAI,SAAS,CAAC,mCAAmC,OAAO,KAAK,EAAE,CAAC,CAAC;IAC3E,CAAC;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AK,QAAQ;oBAAE,OAAO,IAAA,eAAO,EAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAM,CAAC;AACV,CAAC","sourcesContent":["import { sha256 } from '@noble/hashes/sha256';\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils';\nimport { fromHex, toHex } from './bytes';\n\n/**\n * Deterministic JSON for hashing: object keys sorted, `undefined` properties omitted,\n * bigint → `{\"$bigint\":\"<decimal>\"}`, Uint8Array → `{\"$bytes\":\"<hex>\"}`.\n */\nexport function canonicalJson(value: unknown): string {\n return JSON.stringify(canonicalize(value, new WeakSet()));\n}\n\nfunction canonicalize(value: unknown, seen: WeakSet<object>): unknown {\n if (value === null) return null;\n switch (typeof value) {\n case 'string':\n case 'boolean':\n return value;\n case 'number':\n if (!Number.isFinite(value))\n throw new TypeError('canonicalJson: non-finite number');\n return value;\n case 'bigint':\n return { $bigint: value.toString() };\n case 'undefined':\n return undefined;\n case 'object':\n break;\n default:\n throw new TypeError(`canonicalJson: unsupported type ${typeof value}`);\n }\n if (value instanceof Uint8Array) return { $bytes: toHex(value) };\n if (seen.has(value)) throw new TypeError('canonicalJson: circular structure');\n seen.add(value);\n try {\n if (Array.isArray(value)) {\n return value.map((item) => {\n const c = canonicalize(item, seen);\n return c === undefined ? null : c;\n });\n }\n const proto: unknown = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto !== null) {\n const toJSON = (value as { toJSON?: () => unknown }).toJSON;\n if (typeof toJSON === 'function') return canonicalize(toJSON.call(value), seen);\n throw new TypeError('canonicalJson: only plain objects are supported');\n }\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(value).sort()) {\n const c = canonicalize((value as Record<string, unknown>)[key], seen);\n if (c !== undefined) out[key] = c;\n }\n return out;\n } finally {\n seen.delete(value);\n }\n}\n\n/**\n * Deterministic JSON for comparing quorum answers, which no two different values\n * share. `canonicalJson` writes a bigint as `{\"$bigint\":…}` and bytes as `{\"$bytes\":…}`, the\n * same text as a plain object with that key, so one endpoint's object could agree with\n * another's bigint; it also drops a `__proto__` key. Here every plain-object key that starts\n * with `$` gains one more `$`, and `__proto__` becomes `$__proto__`, before tagging, so no\n * two keys become one and no plain object's key is ever `$bigint` or `$bytes`.\n * `canonicalJson` itself is unchanged: the intent hash depends on it.\n */\nexport function quorumJson(value: unknown): string {\n return canonicalJson(escapeKeys(value, new WeakSet()));\n}\n\n/** `value` with the keys of its plain objects escaped as `quorumJson` describes. */\nfunction escapeKeys(value: unknown, seen: WeakSet<object>): unknown {\n if (value === null || typeof value !== 'object' || value instanceof Uint8Array)\n return value;\n if (seen.has(value)) throw new TypeError('canonicalJson: circular structure');\n seen.add(value);\n try {\n if (Array.isArray(value)) return value.map((item) => escapeKeys(item, seen));\n const proto: unknown = Object.getPrototypeOf(value);\n if (proto !== Object.prototype && proto !== null) {\n // As canonicalJson reads it: its toJSON() value, or (without one) a TypeError there.\n const toJSON = (value as { toJSON?: () => unknown }).toJSON;\n return typeof toJSON === 'function' ? escapeKeys(toJSON.call(value), seen) : value;\n }\n const out: Record<string, unknown> = {};\n for (const key of Object.keys(value)) {\n const escaped = key.startsWith('$') || key === '__proto__' ? `$${key}` : key;\n out[escaped] = escapeKeys((value as Record<string, unknown>)[key], seen);\n }\n return out;\n } finally {\n seen.delete(value);\n }\n}\n\n/** The longest integer literal `parseJson` revives, in digits without the sign. */\nconst MAX_EXACT_DIGITS = 80;\n\n/**\n * `JSON.parse`, optionally exact for integers: with `exactIntegers`, every integer\n * literal outside the safe range becomes a `bigint` read from its source text (Node ≥ 22\n * `JSON.parse` source text access), so a u64 amount is never rounded. Safe integers,\n * fractions and exponents stay numbers, so answers keep their shape for ordinary values.\n * With the flag, an integer literal longer than 80 digits (sign excluded) is malformed and\n * throws a `SyntaxError`, as `JSON.parse` does: no amount is that long (u256 has 78 digits),\n * and `BigInt()` of a multi-megabyte literal would take seconds.\n */\nexport function parseJson(text: string, exactIntegers = false): unknown {\n // A run of 16 digits is the shortest literal that can leave the safe range; without one,\n // the reviver (about 7 times slower on large bodies) cannot change anything.\n if (!exactIntegers || !/\\d{16}/.test(text)) return JSON.parse(text);\n return JSON.parse(\n text,\n (_key: string, value: unknown, context?: { readonly source?: string }) => {\n const source = context?.source;\n if (\n typeof value !== 'number' ||\n Number.isSafeInteger(value) ||\n source === undefined ||\n !/^-?\\d+$/.test(source)\n )\n return value;\n const digits = source.startsWith('-') ? source.length - 1 : source.length;\n if (digits > MAX_EXACT_DIGITS)\n throw new SyntaxError(`integer literal longer than ${MAX_EXACT_DIGITS} digits`);\n return BigInt(source);\n },\n );\n}\n\nexport function sha256Hex(input: string | Uint8Array): string {\n return bytesToHex(sha256(typeof input === 'string' ? utf8ToBytes(input) : input));\n}\n\n/** JSON that round-trips bigint and Uint8Array (for external store implementations). */\nexport function stringifyTagged(value: unknown): string {\n return JSON.stringify(value, (_key, v: unknown) => {\n if (typeof v === 'bigint') return { $bigint: v.toString() };\n if (v instanceof Uint8Array) return { $bytes: toHex(v) };\n return v;\n });\n}\n\nexport function parseTagged<T = unknown>(text: string): T {\n return JSON.parse(text, (_key, v: unknown) => {\n if (v !== null && typeof v === 'object' && !Array.isArray(v)) {\n const o = v as Record<string, unknown>;\n if (Object.keys(o).length === 1) {\n if (typeof o.$bigint === 'string') return BigInt(o.$bigint);\n if (typeof o.$bytes === 'string') return fromHex(o.$bytes);\n }\n }\n return v;\n }) as T;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How an error names something the caller typed (a chain, network,
|
|
3
|
+
* library, provider, wallet, signer, scheme, asset alias, option key or capability). What a
|
|
4
|
+
* caller typed may be a pasted secret, so an error never repeats it, at any length: it lists
|
|
5
|
+
* the names that would have been accepted instead, which the library or the caller's own
|
|
6
|
+
* configuration defined.
|
|
7
|
+
*/
|
|
8
|
+
/** At most this many accepted names are listed; the rest are counted. */
|
|
9
|
+
export declare const MAX_LISTED_NAMES = 12;
|
|
10
|
+
/** `'a'`, `'a' and 'b'`, `'a', 'b' and 'c'`, or `'a', …, 'l' and 3 more`: sorted, unique. */
|
|
11
|
+
export declare function listNames(names: Iterable<string>): string;
|
|
12
|
+
/**
|
|
13
|
+
* The text of a refusal of an unknown `what`, listing the accepted names and never the
|
|
14
|
+
* caller's: `unknown network; the accepted names are 'mainnet' and 'sepolia'`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function unknownName(what: string, accepted: Iterable<string>): string;
|
|
17
|
+
/**
|
|
18
|
+
* A value as an error may show it: quoted when it is one of `known` (a fixed word of this
|
|
19
|
+
* library, such as a capability name), else `unshown`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function knownName(value: unknown, known: readonly string[], unshown: string): string;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* How an error names something the caller typed (a chain, network,
|
|
4
|
+
* library, provider, wallet, signer, scheme, asset alias, option key or capability). What a
|
|
5
|
+
* caller typed may be a pasted secret, so an error never repeats it, at any length: it lists
|
|
6
|
+
* the names that would have been accepted instead, which the library or the caller's own
|
|
7
|
+
* configuration defined.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.MAX_LISTED_NAMES = void 0;
|
|
11
|
+
exports.listNames = listNames;
|
|
12
|
+
exports.unknownName = unknownName;
|
|
13
|
+
exports.knownName = knownName;
|
|
14
|
+
/** At most this many accepted names are listed; the rest are counted. */
|
|
15
|
+
exports.MAX_LISTED_NAMES = 12;
|
|
16
|
+
/** `'a'`, `'a' and 'b'`, `'a', 'b' and 'c'`, or `'a', …, 'l' and 3 more`: sorted, unique. */
|
|
17
|
+
function listNames(names) {
|
|
18
|
+
const sorted = [...new Set(names)].sort();
|
|
19
|
+
const shown = sorted.slice(0, exports.MAX_LISTED_NAMES).map((name) => `'${name}'`);
|
|
20
|
+
const rest = sorted.length - shown.length;
|
|
21
|
+
if (rest > 0)
|
|
22
|
+
return `${shown.join(', ')} and ${rest} more`;
|
|
23
|
+
if (shown.length <= 1)
|
|
24
|
+
return shown.join('');
|
|
25
|
+
return `${shown.slice(0, -1).join(', ')} and ${shown.at(-1)}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The text of a refusal of an unknown `what`, listing the accepted names and never the
|
|
29
|
+
* caller's: `unknown network; the accepted names are 'mainnet' and 'sepolia'`.
|
|
30
|
+
*/
|
|
31
|
+
function unknownName(what, accepted) {
|
|
32
|
+
const names = [...new Set(accepted)];
|
|
33
|
+
if (names.length === 0)
|
|
34
|
+
return `unknown ${what}; none is configured`;
|
|
35
|
+
if (names.length === 1)
|
|
36
|
+
return `unknown ${what}; the only accepted name is ${listNames(names)}`;
|
|
37
|
+
return `unknown ${what}; the accepted names are ${listNames(names)}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A value as an error may show it: quoted when it is one of `known` (a fixed word of this
|
|
41
|
+
* library, such as a capability name), else `unshown`.
|
|
42
|
+
*/
|
|
43
|
+
function knownName(value, known, unshown) {
|
|
44
|
+
return typeof value === 'string' && known.includes(value) ? `'${value}'` : unshown;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"names.js","sourceRoot":"","sources":["../../../src/core/util/names.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAMH,8BAOC;AAMD,kCAMC;AAMD,8BAMC;AAnCD,yEAAyE;AAC5D,QAAA,gBAAgB,GAAG,EAAE,CAAC;AAEnC,6FAA6F;AAC7F,SAAgB,SAAS,CAAC,KAAuB;IAC/C,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAC1C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,wBAAgB,CAAC,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asset alias, option key or capability). What a\n * caller typed may be a pasted secret, so an error never repeats it, at any length: it lists\n * the names that would have been accepted instead, which the library or the caller's own\n * configuration defined.\n */\n\n/** At most this many accepted names are listed; the rest are counted. */\nexport const MAX_LISTED_NAMES = 12;\n\n/** `'a'`, `'a' and 'b'`, `'a', 'b' and 'c'`, or `'a', …, 'l' and 3 more`: sorted, unique. */\nexport function listNames(names: Iterable<string>): string {\n const sorted = [...new Set(names)].sort();\n const shown = sorted.slice(0, MAX_LISTED_NAMES).map((name) => `'${name}'`);\n const rest = sorted.length - shown.length;\n if (rest > 0) return `${shown.join(', ')} and ${rest} more`;\n if (shown.length <= 1) return shown.join('');\n return `${shown.slice(0, -1).join(', ')} and ${shown.at(-1) as string}`;\n}\n\n/**\n * The text of a refusal of an unknown `what`, listing the accepted names and never the\n * caller's: `unknown network; the accepted names are 'mainnet' and 'sepolia'`.\n */\nexport function unknownName(what: string, accepted: Iterable<string>): string {\n const names = [...new Set(accepted)];\n if (names.length === 0) return `unknown ${what}; none is configured`;\n if (names.length === 1)\n return `unknown ${what}; the only accepted name is ${listNames(names)}`;\n return `unknown ${what}; the accepted names are ${listNames(names)}`;\n}\n\n/**\n * A value as an error may show it: quoted when it is one of `known` (a fixed word of this\n * library, such as a capability name), else `unshown`.\n */\nexport function knownName(\n value: unknown,\n known: readonly string[],\n unshown: string,\n): string {\n return typeof value === 'string' && known.includes(value) ? `'${value}'` : unshown;\n}\n"]}
|