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,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.web3DriverFactory = void 0;
|
|
4
|
+
exports.createWeb3Codec = createWeb3Codec;
|
|
5
|
+
/**
|
|
6
|
+
* The only module that imports `@solana/web3.js`: program-derived addresses, legacy
|
|
7
|
+
* message compilation and the `crypto-aio/native` `Connection`. It is never on a driver
|
|
8
|
+
* request path: `Connection` retries HTTP 429 on a real timer and would drop the call's
|
|
9
|
+
* tags, so the driver sends every request straight to the transport, and the native
|
|
10
|
+
* `Connection` reaches the same transport through `transport.createFetch`.
|
|
11
|
+
*/
|
|
12
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
13
|
+
const types_1 = require("../../core/transport/types");
|
|
14
|
+
const driver_1 = require("./driver");
|
|
15
|
+
const programs_1 = require("./programs");
|
|
16
|
+
const rpc_1 = require("./rpc");
|
|
17
|
+
const TOKEN = new web3_js_1.PublicKey(programs_1.TOKEN_PROGRAM);
|
|
18
|
+
const ASSOCIATED_TOKEN = new web3_js_1.PublicKey(programs_1.ASSOCIATED_TOKEN_PROGRAM);
|
|
19
|
+
/**
|
|
20
|
+
* The tags of a native client's requests: broadcasts for its writes (a transaction send
|
|
21
|
+
* and a faucet airdrop, neither safe to retry as a read), plain reads for the rest.
|
|
22
|
+
*/
|
|
23
|
+
function classify(_url, init) {
|
|
24
|
+
const body = typeof init?.body === 'string' ? init.body : '';
|
|
25
|
+
return /"method"\s*:\s*"(?:sendTransaction|requestAirdrop)"/.test(body)
|
|
26
|
+
? rpc_1.BROADCAST
|
|
27
|
+
: rpc_1.READ;
|
|
28
|
+
}
|
|
29
|
+
function createWeb3Codec(transport) {
|
|
30
|
+
return {
|
|
31
|
+
associatedTokenAddress(owner, mint) {
|
|
32
|
+
const [address] = web3_js_1.PublicKey.findProgramAddressSync([
|
|
33
|
+
new web3_js_1.PublicKey(owner).toBuffer(),
|
|
34
|
+
TOKEN.toBuffer(),
|
|
35
|
+
new web3_js_1.PublicKey(mint).toBuffer(),
|
|
36
|
+
], ASSOCIATED_TOKEN);
|
|
37
|
+
return address.toBase58();
|
|
38
|
+
},
|
|
39
|
+
compileMessage(payer, recentBlockhash, instructions) {
|
|
40
|
+
const message = new web3_js_1.TransactionMessage({
|
|
41
|
+
payerKey: new web3_js_1.PublicKey(payer),
|
|
42
|
+
recentBlockhash,
|
|
43
|
+
instructions: instructions.map((ix) => new web3_js_1.TransactionInstruction({
|
|
44
|
+
programId: new web3_js_1.PublicKey(ix.programId),
|
|
45
|
+
keys: ix.accounts.map((a) => ({
|
|
46
|
+
pubkey: new web3_js_1.PublicKey(a.address),
|
|
47
|
+
isSigner: a.signer,
|
|
48
|
+
isWritable: a.writable,
|
|
49
|
+
})),
|
|
50
|
+
data: Buffer.from(ix.data),
|
|
51
|
+
})),
|
|
52
|
+
}).compileToLegacyMessage();
|
|
53
|
+
return new Uint8Array(message.serialize());
|
|
54
|
+
},
|
|
55
|
+
createNative() {
|
|
56
|
+
const connection = new web3_js_1.Connection(`${types_1.PLACEHOLDER_ORIGIN}/`, {
|
|
57
|
+
commitment: 'confirmed',
|
|
58
|
+
fetch: transport.createFetch(classify),
|
|
59
|
+
httpAgent: false,
|
|
60
|
+
disableRetryOnRateLimit: true,
|
|
61
|
+
});
|
|
62
|
+
return {
|
|
63
|
+
client: connection,
|
|
64
|
+
close: () => {
|
|
65
|
+
// Subscriptions have no transport bridge, so a socket client that was used only
|
|
66
|
+
// ever fails against the placeholder host and retries on a timer. Turn retries
|
|
67
|
+
// off (a flag: it does not cancel a retry already armed), cancel the armed one
|
|
68
|
+
// (while it waits there is no socket, so `close()` alone does nothing), then
|
|
69
|
+
// close the socket if there is one.
|
|
70
|
+
const socket = connection._rpcWebSocket;
|
|
71
|
+
if (!socket)
|
|
72
|
+
return;
|
|
73
|
+
socket.setAutoReconnect(false);
|
|
74
|
+
clearTimeout(socket.reconnect_timer_id);
|
|
75
|
+
socket.close();
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/** The `@solana/web3.js` adapter's driver factory; the manifest's `load()` returns it. */
|
|
82
|
+
exports.web3DriverFactory = (0, driver_1.solanaDriverFactory)(createWeb3Codec);
|
|
83
|
+
//# sourceMappingURL=web3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web3.js","sourceRoot":"","sources":["../../../src/adapters/solana/web3.ts"],"names":[],"mappings":";;;AAiCA,0CAgEC;AAjGD;;;;;;GAMG;AACH,6CAKyB;AACzB,sDAAgF;AAChF,qCAA+C;AAC/C,yCAAqE;AACrE,+BAAwC;AAGxC,MAAM,KAAK,GAAG,IAAI,mBAAS,CAAC,wBAAa,CAAC,CAAC;AAC3C,MAAM,gBAAgB,GAAG,IAAI,mBAAS,CAAC,mCAAwB,CAAC,CAAC;AAEjE;;;GAGG;AACH,SAAS,QAAQ,CAAC,IAAS,EAAE,IAA6B;IACxD,MAAM,IAAI,GAAG,OAAO,IAAI,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7D,OAAO,qDAAqD,CAAC,IAAI,CA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,YAAY;YACV,MAAM,UAAU,GAAG,IAAI,oBAAU,CAAC,GAAG,0BAAkB,GAAG,EAAE;gBAC1D,UAAU,EAAE,WAAW;gBACvB,KAAK,EAAE,SAAS,CAAC,WAAW,CAAC,QAAQ,CAAC;gBACtC,SAAS,EAAE,KAAK;gBAChB,uBAAuB,EAAE,IAAI;aAC9B,CAAC,CAAC;YACH,OAAO;gBACL,MAAM,EAAE,UAAU;gBAClB,KAAK,EAAE,GAAG,EAAE;oBACV,gFAAgF;oBAChF,+EAA+E;oBAC/E,+EAA+E;oBAC/E,6EAA6E;oBAC7E,oCAAoC;oBACpC,MAAM,MAAM,GACV,UAOD,CAAC,aAAa,CAAC;oBAChB,IAAI,CAAC,MAAM;wBAAE,OAAO;oBACpB,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC;oBAC/B,YAAY,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;oBACxC,MAAM,CAAC,KAAK,EAAE,CAAC;gBACjB,CAAC;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC;AAED,0FAA0F;AAC7E,QAAA,iBAAiB,GAAG,IAAA,4BAAmB,EAAC,eAAe,CAAC,CAAC","sourcesContent":["/**\n * The only module that imports `@solana/web3.js`: program-derived addresses, legacy\n * message compilation and the `crypto-aio/native` `Connection`. It is never on a driver\n * request path: `Connection` retries HTTP 429 on a real timer and would drop the call's\n * tags, so the driver sends every request straight to the transport, and the native\n * `Connection` reaches the same transport through `transport.createFetch`.\n */\nimport {\n Connection,\n PublicKey,\n TransactionInstruction,\n TransactionMessage,\n} from '@solana/web3.js';\nimport { PLACEHOLDER_ORIGIN, type Transport } from '../../core/transport/types';\nimport { solanaDriverFactory } from './driver';\nimport { ASSOCIATED_TOKEN_PROGRAM, TOKEN_PROGRAM } from './programs';\nimport { BROADCAST, READ } from './rpc';\nimport type { SolanaCodec } from './types';\n\nconst TOKEN = new PublicKey(TOKEN_PROGRAM);\nconst ASSOCIATED_TOKEN = new PublicKey(ASSOCIATED_TOKEN_PROGRAM);\n\n/**\n * The tags of a native client's requests: broadcasts for its writes (a transaction send\n * and a faucet airdrop, neither safe to retry as a read), plain reads for the rest.\n */\nfunction classify(_url: URL, init: RequestInit | undefined) {\n const body = typeof init?.body === 'string' ? init.body : '';\n return /\"method\"\\s*:\\s*\"(?:sendTransaction|requestAirdrop)\"/.test(body)\n ? BROADCAST\n : READ;\n}\n\nexport function createWeb3Codec(transport: Transport): SolanaCodec {\n return {\n associatedTokenAddress(owner, mint) {\n const [address] = PublicKey.findProgramAddressSync(\n [\n new PublicKey(owner).toBuffer(),\n TOKEN.toBuffer(),\n new PublicKey(mint).toBuffer(),\n ],\n ASSOCIATED_TOKEN,\n );\n return address.toBase58();\n },\n compileMessage(payer, recentBlockhash, instructions) {\n const message = new TransactionMessage({\n payerKey: new PublicKey(payer),\n recentBlockhash,\n instructions: instructions.map(\n (ix) =>\n new TransactionInstruction({\n programId: new PublicKey(ix.programId),\n keys: ix.accounts.map((a) => ({\n pubkey: new PublicKey(a.address),\n isSigner: a.signer,\n isWritable: a.writable,\n })),\n data: Buffer.from(ix.data),\n }),\n ),\n }).compileToLegacyMessage();\n return new Uint8Array(message.serialize());\n },\n createNative() {\n const connection = new Connection(`${PLACEHOLDER_ORIGIN}/`, {\n commitment: 'confirmed',\n fetch: transport.createFetch(classify),\n httpAgent: false,\n disableRetryOnRateLimit: true,\n });\n return {\n client: connection,\n close: () => {\n // Subscriptions have no transport bridge, so a socket client that was used only\n // ever fails against the placeholder host and retries on a timer. Turn retries\n // off (a flag: it does not cancel a retry already armed), cancel the armed one\n // (while it waits there is no socket, so `close()` alone does nothing), then\n // close the socket if there is one.\n const socket = (\n connection as unknown as {\n _rpcWebSocket?: {\n close(): void;\n setAutoReconnect(on: boolean): void;\n reconnect_timer_id?: ReturnType<typeof setTimeout>;\n };\n }\n )._rpcWebSocket;\n if (!socket) return;\n socket.setAutoReconnect(false);\n clearTimeout(socket.reconnect_timer_id);\n socket.close();\n },\n };\n },\n };\n}\n\n/** The `@solana/web3.js` adapter's driver factory; the manifest's `load()` returns it. */\nexport const web3DriverFactory = solanaDriverFactory(createWeb3Codec);\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** Solana's compact-u16 ("shortvec") length prefix. */
|
|
2
|
+
export declare function encodeLength(value: number): Uint8Array;
|
|
3
|
+
/**
|
|
4
|
+
* A compact-u16 at `offset`: its value and the offset after it, or `null`. Only the
|
|
5
|
+
* canonical form is read, as the runtime reads it: at most three bytes, no zero byte after
|
|
6
|
+
* the first (an alias of a shorter form), and no value above 65,535.
|
|
7
|
+
*/
|
|
8
|
+
export declare function decodeLength(bytes: Uint8Array, offset: number): {
|
|
9
|
+
readonly value: number;
|
|
10
|
+
readonly next: number;
|
|
11
|
+
} | null;
|
|
12
|
+
/** One instruction of a legacy message: its program's key index, account indexes and data. */
|
|
13
|
+
export interface MessageInstruction {
|
|
14
|
+
readonly program: number;
|
|
15
|
+
/** Indexes into the message's keys. */
|
|
16
|
+
readonly accounts: Uint8Array;
|
|
17
|
+
readonly data: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The parts of one well-formed legacy message. Keys, the blockhash, account indexes and data
|
|
21
|
+
* are views into the message bytes, not copies.
|
|
22
|
+
*/
|
|
23
|
+
export interface MessageParts {
|
|
24
|
+
/** Signers: the first `required` keys; the fee payer first. */
|
|
25
|
+
readonly required: number;
|
|
26
|
+
readonly readonlySigned: number;
|
|
27
|
+
readonly readonlyUnsigned: number;
|
|
28
|
+
readonly keys: readonly Uint8Array[];
|
|
29
|
+
readonly blockhash: Uint8Array;
|
|
30
|
+
readonly instructions: readonly MessageInstruction[];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The parts of `message`, or `null` unless it is exactly one well-formed legacy message (the
|
|
34
|
+
* runtime's sanitize rules): at least one signer, a writable fee payer, signer and read-only
|
|
35
|
+
* non-signer ranges within the keys, every program and account index within the keys, no
|
|
36
|
+
* program at index 0, and no trailing bytes. Each count is checked against the bytes that
|
|
37
|
+
* remain before anything is read, so the work and the views it makes are linear in the input.
|
|
38
|
+
*/
|
|
39
|
+
export declare function parseMessage(message: Uint8Array): MessageParts | null;
|
|
40
|
+
/**
|
|
41
|
+
* A legacy message's signer addresses, in order, or `null` unless `message` is exactly one
|
|
42
|
+
* well-formed legacy message (`parseMessage`).
|
|
43
|
+
*/
|
|
44
|
+
export declare function messageSigners(message: Uint8Array): readonly string[] | null;
|
|
45
|
+
/** A signed legacy transaction read back: its signatures, in signer order, and its message. */
|
|
46
|
+
export interface SignedParts {
|
|
47
|
+
/** Views into the bytes, 64 each; one per required signer. */
|
|
48
|
+
readonly signatures: readonly Uint8Array[];
|
|
49
|
+
/** The message bytes the signatures sign (a view). */
|
|
50
|
+
readonly message: Uint8Array;
|
|
51
|
+
readonly parts: MessageParts;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The parts of `bytes`, or `null` unless it is exactly one signed legacy transaction: a
|
|
55
|
+
* canonical signature count equal to the message's required signers, 64 bytes per
|
|
56
|
+
* signature, then one well-formed legacy message (`parseMessage`) with nothing after it. No
|
|
57
|
+
* signature is sliced before the count matches the header, so the work is linear in the
|
|
58
|
+
* input.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseSignedTransaction(bytes: Uint8Array): SignedParts | null;
|
|
61
|
+
/** A signed transaction: the signatures (64 bytes each), in signer order, then the message. */
|
|
62
|
+
export declare function signedTransaction(signatures: readonly Uint8Array[], message: Uint8Array): Uint8Array;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.encodeLength = encodeLength;
|
|
4
|
+
exports.decodeLength = decodeLength;
|
|
5
|
+
exports.parseMessage = parseMessage;
|
|
6
|
+
exports.messageSigners = messageSigners;
|
|
7
|
+
exports.parseSignedTransaction = parseSignedTransaction;
|
|
8
|
+
exports.signedTransaction = signedTransaction;
|
|
9
|
+
/**
|
|
10
|
+
* The Solana wire format the driver reads and writes itself, SDK-free: compact-u16 lengths,
|
|
11
|
+
* a legacy message's parts (header, keys, blockhash and instructions, which the builder
|
|
12
|
+
* reads back before anything is signed), and a signed transaction (signatures followed by
|
|
13
|
+
* the message). Message compilation stays with the SDK (`web3.ts`).
|
|
14
|
+
*
|
|
15
|
+
* Read bytes are untrusted (a stored message, a node's answer): every length prefix is
|
|
16
|
+
* checked against the bytes that remain before anything is sliced or allocated, and a
|
|
17
|
+
* malformed input is `null`, never a throw. Written values are range-checked with fixed
|
|
18
|
+
* texts, never wrapped.
|
|
19
|
+
*/
|
|
20
|
+
const error_1 = require("../../core/errors/error");
|
|
21
|
+
const keys_1 = require("./keys");
|
|
22
|
+
const MAX_LENGTH = 0xffff;
|
|
23
|
+
const KEY_BYTES = 32;
|
|
24
|
+
const BLOCKHASH_BYTES = 32;
|
|
25
|
+
const SIGNATURE_BYTES = 64;
|
|
26
|
+
/** Solana's compact-u16 ("shortvec") length prefix. */
|
|
27
|
+
function encodeLength(value) {
|
|
28
|
+
if (!Number.isInteger(value) || value < 0 || value > MAX_LENGTH) {
|
|
29
|
+
throw new error_1.ValidationError('INVALID_INTENT', 'a length does not fit in its compact-u16 field');
|
|
30
|
+
}
|
|
31
|
+
const out = [];
|
|
32
|
+
let rest = value;
|
|
33
|
+
for (;;) {
|
|
34
|
+
const byte = rest & 0x7f;
|
|
35
|
+
rest >>= 7;
|
|
36
|
+
if (rest === 0) {
|
|
37
|
+
out.push(byte);
|
|
38
|
+
return Uint8Array.from(out);
|
|
39
|
+
}
|
|
40
|
+
out.push(byte | 0x80);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A compact-u16 at `offset`: its value and the offset after it, or `null`. Only the
|
|
45
|
+
* canonical form is read, as the runtime reads it: at most three bytes, no zero byte after
|
|
46
|
+
* the first (an alias of a shorter form), and no value above 65,535.
|
|
47
|
+
*/
|
|
48
|
+
function decodeLength(bytes, offset) {
|
|
49
|
+
let value = 0;
|
|
50
|
+
for (let i = 0; i < 3; i++) {
|
|
51
|
+
const byte = bytes[offset + i];
|
|
52
|
+
if (byte === undefined || (byte === 0 && i > 0))
|
|
53
|
+
return null;
|
|
54
|
+
value |= (byte & 0x7f) << (7 * i);
|
|
55
|
+
if ((byte & 0x80) === 0) {
|
|
56
|
+
return value > MAX_LENGTH ? null : { value, next: offset + i + 1 };
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The parts of `message`, or `null` unless it is exactly one well-formed legacy message (the
|
|
63
|
+
* runtime's sanitize rules): at least one signer, a writable fee payer, signer and read-only
|
|
64
|
+
* non-signer ranges within the keys, every program and account index within the keys, no
|
|
65
|
+
* program at index 0, and no trailing bytes. Each count is checked against the bytes that
|
|
66
|
+
* remain before anything is read, so the work and the views it makes are linear in the input.
|
|
67
|
+
*/
|
|
68
|
+
function parseMessage(message) {
|
|
69
|
+
const required = message[0];
|
|
70
|
+
const readonlySigned = message[1];
|
|
71
|
+
const readonlyUnsigned = message[2];
|
|
72
|
+
if (required === undefined ||
|
|
73
|
+
readonlySigned === undefined ||
|
|
74
|
+
readonlyUnsigned === undefined) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
// A versioned message starts with 0x80 | version; the driver only builds legacy ones.
|
|
78
|
+
if (required === 0 || (required & 0x80) !== 0 || readonlySigned >= required) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const keys = decodeLength(message, 3);
|
|
82
|
+
if (!keys || keys.value < required + readonlyUnsigned)
|
|
83
|
+
return null;
|
|
84
|
+
let at = keys.next + KEY_BYTES * keys.value + BLOCKHASH_BYTES;
|
|
85
|
+
if (at > message.length)
|
|
86
|
+
return null;
|
|
87
|
+
const instructions = decodeLength(message, at);
|
|
88
|
+
// Each instruction takes at least three bytes: its program index and two lengths.
|
|
89
|
+
if (!instructions || 3 * instructions.value > message.length - instructions.next) {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
at = instructions.next;
|
|
93
|
+
const list = [];
|
|
94
|
+
for (let i = 0; i < instructions.value; i++) {
|
|
95
|
+
const program = message[at];
|
|
96
|
+
if (program === undefined || program === 0 || program >= keys.value)
|
|
97
|
+
return null;
|
|
98
|
+
const accounts = decodeLength(message, at + 1);
|
|
99
|
+
if (!accounts || accounts.value > message.length - accounts.next)
|
|
100
|
+
return null;
|
|
101
|
+
for (let j = accounts.next; j < accounts.next + accounts.value; j++) {
|
|
102
|
+
if (message[j] >= keys.value)
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
const data = decodeLength(message, accounts.next + accounts.value);
|
|
106
|
+
if (!data || data.value > message.length - data.next)
|
|
107
|
+
return null;
|
|
108
|
+
list.push({
|
|
109
|
+
program,
|
|
110
|
+
accounts: message.subarray(accounts.next, accounts.next + accounts.value),
|
|
111
|
+
data: message.subarray(data.next, data.next + data.value),
|
|
112
|
+
});
|
|
113
|
+
at = data.next + data.value;
|
|
114
|
+
}
|
|
115
|
+
if (at !== message.length)
|
|
116
|
+
return null;
|
|
117
|
+
const start = keys.next + KEY_BYTES * keys.value;
|
|
118
|
+
return {
|
|
119
|
+
required,
|
|
120
|
+
readonlySigned,
|
|
121
|
+
readonlyUnsigned,
|
|
122
|
+
keys: Array.from({ length: keys.value }, (_, i) => message.subarray(keys.next + KEY_BYTES * i, keys.next + KEY_BYTES * (i + 1))),
|
|
123
|
+
blockhash: message.subarray(start, start + BLOCKHASH_BYTES),
|
|
124
|
+
instructions: list,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A legacy message's signer addresses, in order, or `null` unless `message` is exactly one
|
|
129
|
+
* well-formed legacy message (`parseMessage`).
|
|
130
|
+
*/
|
|
131
|
+
function messageSigners(message) {
|
|
132
|
+
const parts = parseMessage(message);
|
|
133
|
+
return parts ? parts.keys.slice(0, parts.required).map(keys_1.encodeBase58) : null;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The parts of `bytes`, or `null` unless it is exactly one signed legacy transaction: a
|
|
137
|
+
* canonical signature count equal to the message's required signers, 64 bytes per
|
|
138
|
+
* signature, then one well-formed legacy message (`parseMessage`) with nothing after it. No
|
|
139
|
+
* signature is sliced before the count matches the header, so the work is linear in the
|
|
140
|
+
* input.
|
|
141
|
+
*/
|
|
142
|
+
function parseSignedTransaction(bytes) {
|
|
143
|
+
const count = decodeLength(bytes, 0);
|
|
144
|
+
if (!count)
|
|
145
|
+
return null;
|
|
146
|
+
// A count beyond the bytes leaves an empty message, which does not parse; a message
|
|
147
|
+
// always requires a signer, so a zero count never matches its header.
|
|
148
|
+
const message = bytes.subarray(count.next + SIGNATURE_BYTES * count.value);
|
|
149
|
+
const parts = parseMessage(message);
|
|
150
|
+
if (!parts || parts.required !== count.value)
|
|
151
|
+
return null;
|
|
152
|
+
const signatures = Array.from({ length: count.value }, (_, i) => bytes.subarray(count.next + SIGNATURE_BYTES * i, count.next + SIGNATURE_BYTES * (i + 1)));
|
|
153
|
+
return { signatures, message, parts };
|
|
154
|
+
}
|
|
155
|
+
/** A signed transaction: the signatures (64 bytes each), in signer order, then the message. */
|
|
156
|
+
function signedTransaction(signatures, message) {
|
|
157
|
+
if (signatures.some((signature) => signature.length !== SIGNATURE_BYTES)) {
|
|
158
|
+
throw new error_1.ValidationError('INVALID_INTENT', 'a Solana signature is exactly 64 bytes');
|
|
159
|
+
}
|
|
160
|
+
const prefix = encodeLength(signatures.length);
|
|
161
|
+
const start = prefix.length + SIGNATURE_BYTES * signatures.length;
|
|
162
|
+
const out = new Uint8Array(start + message.length);
|
|
163
|
+
out.set(prefix, 0);
|
|
164
|
+
signatures.forEach((signature, i) => out.set(signature, prefix.length + SIGNATURE_BYTES * i));
|
|
165
|
+
out.set(message, start);
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
168
|
+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;QACzE,MAAM,IAAI,uBAAe,CAAC,gBAAgB,EAAE,wCAAwC,CAAC,CAAC;IACxF,CAAC;IACD,MAAM,MAAM,GAAG,YAAY,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,eAAe,GAAG,UAAU,CAAC,MAAM,CAAC;IAClE,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACnD,GAAG,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACnB,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,CAAC,EAAE,EAAE,CAClC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,GAAG,eAAe,GAAG,CAAC,CAAC,CACxD,CAAC;IACF,GAAG,CAAC,GAAG,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACxB,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/**\n * The Solana wire format the driver reads and writes itself, SDK-free: compact-u16 lengths,\n * a legacy message's parts (header, keys, blockhash and instructions, which the builder\n * reads back before anything is signed), and a signed transaction (signatures followed by\n * the message). Message compilation stays with the SDK (`web3.ts`).\n *\n * Read bytes are untrusted (a stored message, a node's answer): every length prefix is\n * checked against the bytes that remain before anything is sliced or allocated, and a\n * malformed input is `null`, never a throw. Written values are range-checked with fixed\n * texts, never wrapped.\n */\nimport { ValidationError } from '../../core/errors/error';\nimport { encodeBase58 } from './keys';\n\nconst MAX_LENGTH = 0xffff;\nconst KEY_BYTES = 32;\nconst BLOCKHASH_BYTES = 32;\nconst SIGNATURE_BYTES = 64;\n\n/** Solana's compact-u16 (\"shortvec\") length prefix. */\nexport function encodeLength(value: number): Uint8Array {\n if (!Number.isInteger(value) || value < 0 || value > MAX_LENGTH) {\n throw new ValidationError(\n 'INVALID_INTENT',\n 'a length does not fit in its compact-u16 field',\n );\n }\n const out: number[] = [];\n let rest = value;\n for (;;) {\n const byte = rest & 0x7f;\n rest >>= 7;\n if (rest === 0) {\n out.push(byte);\n return Uint8Array.from(out);\n }\n out.push(byte | 0x80);\n }\n}\n\n/**\n * A compact-u16 at `offset`: its value and the offset after it, or `null`. Only the\n * canonical form is read, as the runtime reads it: at most three bytes, no zero byte after\n * the first (an alias of a shorter form), and no value above 65,535.\n */\nexport function decodeLength(\n bytes: Uint8Array,\n offset: number,\n): { readonly value: number; readonly next: number } | null {\n let value = 0;\n for (let i = 0; i < 3; i++) {\n const byte = bytes[offset + i];\n if (byte === undefined || (byte === 0 && i > 0)) return null;\n value |= (byte & 0x7f) << (7 * i);\n if ((byte & 0x80) === 0) {\n return value > MAX_LENGTH ? null : { value, next: offset + i + 1 };\n }\n }\n return null;\n}\n\n/** One instruction of a legacy message: its program's key index, account indexes and data. */\nexport interface MessageInstruction {\n readonly program: number;\n /** Indexes into the message's keys. */\n readonly accounts: Uint8Array;\n readonly data: Uint8Array;\n}\n\n/**\n * The parts of one well-formed legacy message. Keys, the blockhash, account indexes and data\n * are views into the message bytes, not copies.\n */\nexport interface MessageParts {\n /** Signers: the first `required` keys; the fee payer first. */\n readonly required: number;\n readonly readonlySigned: number;\n readonly readonlyUnsigned: number;\n readonly keys: readonly Uint8Array[];\n readonly blockhash: Uint8Array;\n readonly instructions: readonly MessageInstruction[];\n}\n\n/**\n * The parts of `message`, or `null` unless it is exactly one well-formed legacy message (the\n * runtime's sanitize rules): at least one signer, a writable fee payer, signer and read-only\n * non-signer ranges within the keys, every program and account index within the keys, no\n * program at index 0, and no trailing bytes. Each count is checked against the bytes that\n * remain before anything is read, so the work and the views it makes are linear in the input.\n */\nexport function parseMessage(message: Uint8Array): MessageParts | null {\n const required = message[0];\n const readonlySigned = message[1];\n const readonlyUnsigned = message[2];\n if (\n required === undefined ||\n readonlySigned === undefined ||\n readonlyUnsigned === undefined\n ) {\n return null;\n }\n // A versioned message starts with 0x80 | version; the driver only builds legacy ones.\n if (required === 0 || (required & 0x80) !== 0 || readonlySigned >= required) {\n return null;\n }\n const keys = decodeLength(message, 3);\n if (!keys || keys.value < required + readonlyUnsigned) return null;\n let at = keys.next + KEY_BYTES * keys.value + BLOCKHASH_BYTES;\n if (at > message.length) return null;\n const instructions = decodeLength(message, at);\n // Each instruction takes at least three bytes: its program index and two lengths.\n if (!instructions || 3 * instructions.value > message.length - instructions.next) {\n return null;\n }\n at = instructions.next;\n const list: MessageInstruction[] = [];\n for (let i = 0; i < instructions.value; i++) {\n const program = message[at];\n if (program === undefined || program === 0 || program >= keys.value) return null;\n const accounts = decodeLength(message, at + 1);\n if (!accounts || accounts.value > message.length - accounts.next) return null;\n for (let j = accounts.next; j < accounts.next + accounts.value; j++) {\n if ((message[j] as number) >= keys.value) return null;\n }\n const data = decodeLength(message, accounts.next + accounts.value);\n if (!data || data.value > message.length - data.next) return null;\n list.push({\n program,\n accounts: message.subarray(accounts.next, accounts.next + accounts.value),\n data: message.subarray(data.next, data.next + data.value),\n });\n at = data.next + data.value;\n }\n if (at !== message.length) return null;\n const start = keys.next + KEY_BYTES * keys.value;\n return {\n required,\n readonlySigned,\n readonlyUnsigned,\n keys: Array.from({ length: keys.value }, (_, i) =>\n message.subarray(keys.next + KEY_BYTES * i, keys.next + KEY_BYTES * (i + 1)),\n ),\n blockhash: message.subarray(start, start + BLOCKHASH_BYTES),\n instructions: list,\n };\n}\n\n/**\n * A legacy message's signer addresses, in order, or `null` unless `message` is exactly one\n * well-formed legacy message (`parseMessage`).\n */\nexport function messageSigners(message: Uint8Array): readonly string[] | null {\n const parts = parseMessage(message);\n return parts ? parts.keys.slice(0, parts.required).map(encodeBase58) : null;\n}\n\n/** A signed legacy transaction read back: its signatures, in signer order, and its message. */\nexport interface SignedParts {\n /** Views into the bytes, 64 each; one per required signer. */\n readonly signatures: readonly Uint8Array[];\n /** The message bytes the signatures sign (a view). */\n readonly message: Uint8Array;\n readonly parts: MessageParts;\n}\n\n/**\n * The parts of `bytes`, or `null` unless it is exactly one signed legacy transaction: a\n * canonical signature count equal to the message's required signers, 64 bytes per\n * signature, then one well-formed legacy message (`parseMessage`) with nothing after it. No\n * signature is sliced before the count matches the header, so the work is linear in the\n * input.\n */\nexport function parseSignedTransaction(bytes: Uint8Array): SignedParts | null {\n const count = decodeLength(bytes, 0);\n if (!count) return null;\n // A count beyond the bytes leaves an empty message, which does not parse; a message\n // always requires a signer, so a zero count never matches its header.\n const message = bytes.subarray(count.next + SIGNATURE_BYTES * count.value);\n const parts = parseMessage(message);\n if (!parts || parts.required !== count.value) return null;\n const signatures = Array.from({ length: count.value }, (_, i) =>\n bytes.subarray(\n count.next + SIGNATURE_BYTES * i,\n count.next + SIGNATURE_BYTES * (i + 1),\n ),\n );\n return { signatures, message, parts };\n}\n\n/** A signed transaction: the signatures (64 bytes each), in signer order, then the message. */\nexport function signedTransaction(\n signatures: readonly Uint8Array[],\n message: Uint8Array,\n): Uint8Array {\n if (signatures.some((signature) => signature.length !== SIGNATURE_BYTES)) {\n throw new ValidationError('INVALID_INTENT', 'a Solana signature is exactly 64 bytes');\n }\n const prefix = encodeLength(signatures.length);\n const start = prefix.length + SIGNATURE_BYTES * signatures.length;\n const out = new Uint8Array(start + message.length);\n out.set(prefix, 0);\n signatures.forEach((signature, i) =>\n out.set(signature, prefix.length + SIGNATURE_BYTES * i),\n );\n out.set(message, start);\n return out;\n}\n"]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict TON addresses, SDK-free. Two forms are accepted, nothing else:
|
|
3
|
+
* - raw: `0:<64 hex>` or `-1:<64 hex>` (hex in either case; canonical is lower case);
|
|
4
|
+
* - user-friendly: 48 base64 characters, either all standard (`+/`) or all URL-safe
|
|
5
|
+
* (`-_`) alphabet, decoding to tag · workchain · 32-byte hash · CRC16-XMODEM.
|
|
6
|
+
* `@ton/core` is laxer (an unanchored hex test, any `parseInt` workchain, mixed base64
|
|
7
|
+
* alphabets, workchain bytes other than 0x00/0xff, a thrown string on a bad tag), so every
|
|
8
|
+
* address reaches the SDK only in the canonical raw form produced here.
|
|
9
|
+
* Canonical is the raw form; `display` keeps the caller's text; `variant` keeps only the
|
|
10
|
+
* flag that decides bounce behaviour (a raw address is bounceable, as in `@ton/core`).
|
|
11
|
+
* The variant is part of the intent hash and carries semantic fields only, so the
|
|
12
|
+
* encoding-only flags (test-only, alphabet) stay out of it: every spelling of one
|
|
13
|
+
* recipient with the same bounce flag hashes the same.
|
|
14
|
+
*/
|
|
15
|
+
import type { AddressCodec, WalletOptions } from '../../core/driver/types';
|
|
16
|
+
export type TonWorkchain = 0 | -1;
|
|
17
|
+
/** The flags a user-friendly TON address carries (TEP-2). */
|
|
18
|
+
export type TonAddressVariant = {
|
|
19
|
+
readonly bounceable: boolean;
|
|
20
|
+
readonly testOnly: boolean;
|
|
21
|
+
readonly urlSafe: boolean;
|
|
22
|
+
};
|
|
23
|
+
export type ParsedTonAddress = TonAddressVariant & {
|
|
24
|
+
readonly workchain: TonWorkchain;
|
|
25
|
+
/** 32 bytes. */
|
|
26
|
+
readonly hash: Uint8Array;
|
|
27
|
+
readonly form: 'raw' | 'friendly';
|
|
28
|
+
};
|
|
29
|
+
/** CRC16-XMODEM (polynomial 0x1021, initial 0), as TEP-2 specifies for the checksum. */
|
|
30
|
+
export declare function crc16(data: Uint8Array): number;
|
|
31
|
+
/** `0:<hex>` / `-1:<hex>`, lower case: the canonical form. */
|
|
32
|
+
export declare function rawAddress(workchain: TonWorkchain, hash: Uint8Array): string;
|
|
33
|
+
/** The user-friendly form (TEP-2) with the given flags. */
|
|
34
|
+
export declare function friendlyAddress(workchain: TonWorkchain, hash: Uint8Array, flags: TonAddressVariant): string;
|
|
35
|
+
/** Parses either form strictly; `null` for anything else. */
|
|
36
|
+
export declare function parseTonAddress(value: string): ParsedTonAddress | null;
|
|
37
|
+
export interface TonAddressCodecOptions {
|
|
38
|
+
/** Mainnet refuses testnet-only addresses (TEP-2); testnet accepts both flags. */
|
|
39
|
+
readonly testnet: boolean;
|
|
40
|
+
/** The wallet address for a public key and wallet identity (needs the SDK). */
|
|
41
|
+
readonly fromPublicKey: (publicKey: Uint8Array, wallet?: WalletOptions) => string;
|
|
42
|
+
}
|
|
43
|
+
export declare function createTonAddressCodec(options: TonAddressCodecOptions): AddressCodec;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.crc16 = crc16;
|
|
4
|
+
exports.rawAddress = rawAddress;
|
|
5
|
+
exports.friendlyAddress = friendlyAddress;
|
|
6
|
+
exports.parseTonAddress = parseTonAddress;
|
|
7
|
+
exports.createTonAddressCodec = createTonAddressCodec;
|
|
8
|
+
const error_1 = require("../../core/errors/error");
|
|
9
|
+
const RAW = /^(0|-1):([0-9a-fA-F]{64})$/;
|
|
10
|
+
const FRIENDLY_STANDARD = /^[A-Za-z0-9+/]{48}$/;
|
|
11
|
+
const FRIENDLY_URL_SAFE = /^[A-Za-z0-9_-]{48}$/;
|
|
12
|
+
const BOUNCEABLE = 0x11;
|
|
13
|
+
const NON_BOUNCEABLE = 0x51;
|
|
14
|
+
const TEST_ONLY = 0x80;
|
|
15
|
+
const HASH_BYTES = 32;
|
|
16
|
+
/**
|
|
17
|
+
* Untrusted text is capped before decoding: the longest form is `-1:` and 64 hex digits,
|
|
18
|
+
* and anything longer is not decoded.
|
|
19
|
+
*/
|
|
20
|
+
const MAX_ADDRESS_LENGTH = 67;
|
|
21
|
+
/** CRC16-XMODEM (polynomial 0x1021, initial 0), as TEP-2 specifies for the checksum. */
|
|
22
|
+
function crc16(data) {
|
|
23
|
+
let crc = 0;
|
|
24
|
+
for (const byte of data) {
|
|
25
|
+
crc ^= byte << 8;
|
|
26
|
+
for (let bit = 0; bit < 8; bit++) {
|
|
27
|
+
crc = crc & 0x8000 ? ((crc << 1) ^ 0x1021) & 0xffff : (crc << 1) & 0xffff;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return crc;
|
|
31
|
+
}
|
|
32
|
+
const toHex = (bytes) => Buffer.from(bytes).toString('hex');
|
|
33
|
+
/** An account id is exactly 32 bytes: never padded or truncated into another address. */
|
|
34
|
+
function assertHash(hash) {
|
|
35
|
+
if (hash.length !== HASH_BYTES) {
|
|
36
|
+
throw new error_1.ValidationError('INVALID_ADDRESS', 'a TON address hash is 32 bytes');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** `0:<hex>` / `-1:<hex>`, lower case: the canonical form. */
|
|
40
|
+
function rawAddress(workchain, hash) {
|
|
41
|
+
assertHash(hash);
|
|
42
|
+
return `${workchain}:${toHex(hash)}`;
|
|
43
|
+
}
|
|
44
|
+
/** The user-friendly form (TEP-2) with the given flags. */
|
|
45
|
+
function friendlyAddress(workchain, hash, flags) {
|
|
46
|
+
assertHash(hash);
|
|
47
|
+
const bytes = new Uint8Array(36);
|
|
48
|
+
bytes[0] =
|
|
49
|
+
(flags.bounceable ? BOUNCEABLE : NON_BOUNCEABLE) | (flags.testOnly ? TEST_ONLY : 0);
|
|
50
|
+
bytes[1] = workchain === -1 ? 0xff : 0x00;
|
|
51
|
+
bytes.set(hash, 2);
|
|
52
|
+
const crc = crc16(bytes.subarray(0, 34));
|
|
53
|
+
bytes[34] = crc >> 8;
|
|
54
|
+
bytes[35] = crc & 0xff;
|
|
55
|
+
const text = Buffer.from(bytes).toString('base64');
|
|
56
|
+
return flags.urlSafe ? text.replace(/\+/g, '-').replace(/\//g, '_') : text;
|
|
57
|
+
}
|
|
58
|
+
function parseFriendly(value) {
|
|
59
|
+
const urlSafe = FRIENDLY_URL_SAFE.test(value);
|
|
60
|
+
if (!urlSafe && !FRIENDLY_STANDARD.test(value))
|
|
61
|
+
return null;
|
|
62
|
+
const bytes = Buffer.from(urlSafe ? value.replace(/-/g, '+').replace(/_/g, '/') : value, 'base64');
|
|
63
|
+
if (bytes.length !== 36)
|
|
64
|
+
return null;
|
|
65
|
+
const tag = bytes[0];
|
|
66
|
+
const testOnly = (tag & TEST_ONLY) !== 0;
|
|
67
|
+
const flag = tag & ~TEST_ONLY;
|
|
68
|
+
if (flag !== BOUNCEABLE && flag !== NON_BOUNCEABLE)
|
|
69
|
+
return null;
|
|
70
|
+
const wc = bytes[1];
|
|
71
|
+
if (wc !== 0x00 && wc !== 0xff)
|
|
72
|
+
return null;
|
|
73
|
+
const crc = crc16(bytes.subarray(0, 34));
|
|
74
|
+
if (bytes[34] !== crc >> 8 || bytes[35] !== (crc & 0xff))
|
|
75
|
+
return null;
|
|
76
|
+
return {
|
|
77
|
+
workchain: wc === 0xff ? -1 : 0,
|
|
78
|
+
hash: new Uint8Array(bytes.subarray(2, 34)),
|
|
79
|
+
form: 'friendly',
|
|
80
|
+
bounceable: flag === BOUNCEABLE,
|
|
81
|
+
testOnly,
|
|
82
|
+
// A 48-character text in the shared alphabet (no `+/-_`) is both; call it URL-safe.
|
|
83
|
+
urlSafe: urlSafe,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/** Parses either form strictly; `null` for anything else. */
|
|
87
|
+
function parseTonAddress(value) {
|
|
88
|
+
if (typeof value !== 'string' || value.length > MAX_ADDRESS_LENGTH)
|
|
89
|
+
return null;
|
|
90
|
+
const raw = RAW.exec(value);
|
|
91
|
+
if (raw) {
|
|
92
|
+
return {
|
|
93
|
+
workchain: raw[1] === '-1' ? -1 : 0,
|
|
94
|
+
hash: new Uint8Array(Buffer.from(raw[2], 'hex')),
|
|
95
|
+
form: 'raw',
|
|
96
|
+
bounceable: true,
|
|
97
|
+
testOnly: false,
|
|
98
|
+
urlSafe: true,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
return parseFriendly(value);
|
|
102
|
+
}
|
|
103
|
+
function createTonAddressCodec(options) {
|
|
104
|
+
const parse = (value) => {
|
|
105
|
+
const parsed = parseTonAddress(value);
|
|
106
|
+
if (!parsed)
|
|
107
|
+
throw new error_1.ValidationError('INVALID_ADDRESS', 'not a TON address');
|
|
108
|
+
if (parsed.testOnly && !options.testnet) {
|
|
109
|
+
throw new error_1.ValidationError('INVALID_ADDRESS', 'a testnet-only TON address cannot be used on mainnet');
|
|
110
|
+
}
|
|
111
|
+
return parsed;
|
|
112
|
+
};
|
|
113
|
+
const normalize = (value) => {
|
|
114
|
+
const parsed = parse(value);
|
|
115
|
+
const canonical = rawAddress(parsed.workchain, parsed.hash);
|
|
116
|
+
// Only the semantic bounce flag is hashed. A raw address carries no flags and
|
|
117
|
+
// is bounceable, as in `@ton/core`.
|
|
118
|
+
return parsed.form === 'raw'
|
|
119
|
+
? { canonical, display: canonical, variant: { bounceable: true } }
|
|
120
|
+
: { canonical, display: value, variant: { bounceable: parsed.bounceable } };
|
|
121
|
+
};
|
|
122
|
+
return {
|
|
123
|
+
validate: (value) => {
|
|
124
|
+
try {
|
|
125
|
+
parse(value);
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
normalize,
|
|
133
|
+
fromPublicKey: (publicKey, wallet) => {
|
|
134
|
+
const parsed = parse(options.fromPublicKey(publicKey, wallet));
|
|
135
|
+
// A wallet address as wallets show it: non-bounceable, flagged on testnet.
|
|
136
|
+
const flags = { bounceable: false, testOnly: options.testnet, urlSafe: true };
|
|
137
|
+
return {
|
|
138
|
+
canonical: rawAddress(parsed.workchain, parsed.hash),
|
|
139
|
+
display: friendlyAddress(parsed.workchain, parsed.hash, flags),
|
|
140
|
+
variant: { bounceable: false },
|
|
141
|
+
};
|
|
142
|
+
},
|
|
143
|
+
format: (address, formatOptions) => {
|
|
144
|
+
const parsed = parseTonAddress(address.canonical);
|
|
145
|
+
if (!parsed)
|
|
146
|
+
return address.display;
|
|
147
|
+
if (formatOptions?.raw === true)
|
|
148
|
+
return address.canonical;
|
|
149
|
+
if (formatOptions === undefined || Object.keys(formatOptions).length === 0) {
|
|
150
|
+
return address.display;
|
|
151
|
+
}
|
|
152
|
+
// The variant holds the bounce flag only; the caller's own text keeps the others.
|
|
153
|
+
const shown = parseTonAddress(address.display);
|
|
154
|
+
const spelled = shown?.form === 'friendly' ? shown : undefined;
|
|
155
|
+
const pick = (key, fallback) => {
|
|
156
|
+
const value = formatOptions[key];
|
|
157
|
+
return typeof value === 'boolean' ? value : fallback;
|
|
158
|
+
};
|
|
159
|
+
const bounceable = address.variant?.bounceable;
|
|
160
|
+
return friendlyAddress(parsed.workchain, parsed.hash, {
|
|
161
|
+
bounceable: pick('bounceable', typeof bounceable === 'boolean' ? bounceable : true),
|
|
162
|
+
testOnly: pick('testOnly', spelled?.testOnly ?? options.testnet),
|
|
163
|
+
urlSafe: pick('urlSafe', spelled?.urlSafe ?? true),
|
|
164
|
+
});
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
//# sourceMappingURL=address.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../../../src/adapters/ton/address.ts"],"names":[],"mappings":";;AAgDA,sBASC;AAYD,gCAGC;AAGD,0CAgBC;AA8BD,0CAcC;AASD,sDAkEC;AAnMD,mDAA0D;AAmB1D,MAAM,GAAG,GAAG,4BAA4B,CAAC;AACzC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAChD,MAAM,iBAAiB,GAAG,qBAAqB,CAAC;AAChD,MAAM,UAAU,GAAG,IAAI,CAAC;AACxB,MAAM,cAAc,GAAG,IAAI,CAAC;AAC5B,MAAM,SAAS,GAAG,IAAI,CAAC;AACvB,MAAM,UAAU,GAAG,EAAE,CAAC;AACtB;;;GAGG;AACH,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B,wFAAwF;AACxF,SAAgB,KAAK,CAAC,IAAgB;IACpC,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;QACxB,GAAG,IAAI,IAAI,IAAI,CAAC,CA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OAAO,CAAC,CAAC;YAC/C,MAAM,OAAO,GAAG,KAAK,EAAE,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;YAC/D,MAAM,IAAI,GAAG,CAAC,GAA4B,EAAE,QAAiB,EAAW,EAAE;gBACxE,MAAM,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;gBACjC,OAAO,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC;YACvD,CAAC,CAAC;YACF,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC;YAC/C,OAAO,eAAe,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE;gBACpD,UAAU,EAAE,IAAI,CACd,YAAY,EACZ,OAAO,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CACpD;gBACD,QAAQ,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC;gBAChE,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC;aACnD,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Strict TON addresses, SDK-free. Two forms are accepted, nothing else:\n * - raw: `0:<64 hex>` or `-1:<64 hex>` (hex in either case; canonical is lower case);\n * - user-friendly: 48 base64 characters, either all standard (`+/`) or all URL-safe\n * (`-_`) alphabet, decoding to tag · workchain · 32-byte hash · CRC16-XMODEM.\n * `@ton/core` is laxer (an unanchored hex test, any `parseInt` workchain, mixed base64\n * alphabets, workchain bytes other than 0x00/0xff, a thrown string on a bad tag), so every\n * address reaches the SDK only in the canonical raw form produced here.\n * Canonical is the raw form; `display` keeps the caller's text; `variant` keeps only the\n * flag that decides bounce behaviour (a raw address is bounceable, as in `@ton/core`).\n * The variant is part of the intent hash and carries semantic fields only, so the\n * encoding-only flags (test-only, alphabet) stay out of it: every spelling of one\n * recipient with the same bounce flag hashes the same.\n */\nimport type { AddressCodec, WalletOptions } from '../../core/driver/types';\nimport { ValidationError } from '../../core/errors/error';\nimport type { NormalizedAddress } from '../../core/model/address';\n\nexport type TonWorkchain = 0 | -1;\n\n/** The flags a user-friendly TON address carries (TEP-2). */\nexport type TonAddressVariant = {\n readonly bounceable: boolean;\n readonly testOnly: boolean;\n readonly urlSafe: boolean;\n};\n\nexport type ParsedTonAddress = TonAddressVariant & {\n readonly workchain: TonWorkchain;\n /** 32 bytes. */\n readonly hash: Uint8Array;\n readonly form: 'raw' | 'friendly';\n};\n\nconst RAW = /^(0|-1):([0-9a-fA-F]{64})$/;\nconst FRIENDLY_STANDARD = /^[A-Za-z0-9+/]{48}$/;\nconst FRIENDLY_URL_SAFE = /^[A-Za-z0-9_-]{48}$/;\nconst BOUNCEABLE = 0x11;\nconst NON_BOUNCEABLE = 0x51;\nconst TEST_ONLY = 0x80;\nconst HASH_BYTES = 32;\n/**\n * Untrusted text is capped before decoding: the longest form is `-1:` and 64 hex digits,\n * and anything longer is not decoded.\n */\nconst MAX_ADDRESS_LENGTH = 67;\n\n/** CRC16-XMODEM (polynomial 0x1021, initial 0), as TEP-2 specifies for the checksum. */\nexport function crc16(data: Uint8Array): number {\n let crc = 0;\n for (const byte of data) {\n crc ^= byte << 8;\n for (let bit = 0; bit < 8; bit++) {\n crc = crc & 0x8000 ? ((crc << 1) ^ 0x1021) & 0xffff : (crc << 1) & 0xffff;\n }\n }\n return crc;\n}\n\nconst toHex = (bytes: Uint8Array): string => Buffer.from(bytes).toString('hex');\n\n/** An account id is exactly 32 bytes: never padded or truncated into another address. */\nfunction assertHash(hash: Uint8Array): void {\n if (hash.length !== HASH_BYTES) {\n throw new ValidationError('INVALID_ADDRESS', 'a TON address hash is 32 bytes');\n }\n}\n\n/** `0:<hex>` / `-1:<hex>`, lower case: the canonical form. */\nexport function rawAddress(workchain: TonWorkchain, hash: Uint8Array): string {\n assertHash(hash);\n return `${workchain}:${toHex(hash)}`;\n}\n\n/** The user-friendly form (TEP-2) with the given flags. */\nexport function friendlyAddress(\n workchain: TonWorkchain,\n hash: Uint8Array,\n flags: TonAddressVariant,\n): string {\n assertHash(hash);\n const bytes = new Uint8Array(36);\n bytes[0] =\n (flags.bounceable ? BOUNCEABLE : NON_BOUNCEABLE) | (flags.testOnly ? TEST_ONLY : 0);\n bytes[1] = workchain === -1 ? 0xff : 0x00;\n bytes.set(hash, 2);\n const crc = crc16(bytes.subarray(0, 34));\n bytes[34] = crc >> 8;\n bytes[35] = crc & 0xff;\n const text = Buffer.from(bytes).toString('base64');\n return flags.urlSafe ? text.replace(/\\+/g, '-').replace(/\\//g, '_') : text;\n}\n\nfunction parseFriendly(value: string): ParsedTonAddress | null {\n const urlSafe = FRIENDLY_URL_SAFE.test(value);\n if (!urlSafe && !FRIENDLY_STANDARD.test(value)) return null;\n const bytes = Buffer.from(\n urlSafe ? value.replace(/-/g, '+').replace(/_/g, '/') : value,\n 'base64',\n );\n if (bytes.length !== 36) return null;\n const tag = bytes[0] as number;\n const testOnly = (tag & TEST_ONLY) !== 0;\n const flag = tag & ~TEST_ONLY;\n if (flag !== BOUNCEABLE && flag !== NON_BOUNCEABLE) return null;\n const wc = bytes[1];\n if (wc !== 0x00 && wc !== 0xff) return null;\n const crc = crc16(bytes.subarray(0, 34));\n if (bytes[34] !== crc >> 8 || bytes[35] !== (crc & 0xff)) return null;\n return {\n workchain: wc === 0xff ? -1 : 0,\n hash: new Uint8Array(bytes.subarray(2, 34)),\n form: 'friendly',\n bounceable: flag === BOUNCEABLE,\n testOnly,\n // A 48-character text in the shared alphabet (no `+/-_`) is both; call it URL-safe.\n urlSafe: urlSafe,\n };\n}\n\n/** Parses either form strictly; `null` for anything else. */\nexport function parseTonAddress(value: string): ParsedTonAddress | null {\n if (typeof value !== 'string' || value.length > MAX_ADDRESS_LENGTH) return null;\n const raw = RAW.exec(value);\n if (raw) {\n return {\n workchain: raw[1] === '-1' ? -1 : 0,\n hash: new Uint8Array(Buffer.from(raw[2] as string, 'hex')),\n form: 'raw',\n bounceable: true,\n testOnly: false,\n urlSafe: true,\n };\n }\n return parseFriendly(value);\n}\n\nexport interface TonAddressCodecOptions {\n /** Mainnet refuses testnet-only addresses (TEP-2); testnet accepts both flags. */\n readonly testnet: boolean;\n /** The wallet address for a public key and wallet identity (needs the SDK). */\n readonly fromPublicKey: (publicKey: Uint8Array, wallet?: WalletOptions) => string;\n}\n\nexport function createTonAddressCodec(options: TonAddressCodecOptions): AddressCodec {\n const parse = (value: string): ParsedTonAddress => {\n const parsed = parseTonAddress(value);\n if (!parsed) throw new ValidationError('INVALID_ADDRESS', 'not a TON address');\n if (parsed.testOnly && !options.testnet) {\n throw new ValidationError(\n 'INVALID_ADDRESS',\n 'a testnet-only TON address cannot be used on mainnet',\n );\n }\n return parsed;\n };\n const normalize = (value: string): NormalizedAddress => {\n const parsed = parse(value);\n const canonical = rawAddress(parsed.workchain, parsed.hash);\n // Only the semantic bounce flag is hashed. A raw address carries no flags and\n // is bounceable, as in `@ton/core`.\n return parsed.form === 'raw'\n ? { canonical, display: canonical, variant: { bounceable: true } }\n : { canonical, display: value, variant: { bounceable: parsed.bounceable } };\n };\n return {\n validate: (value) => {\n try {\n parse(value);\n return true;\n } catch {\n return false;\n }\n },\n normalize,\n fromPublicKey: (publicKey, wallet) => {\n const parsed = parse(options.fromPublicKey(publicKey, wallet));\n // A wallet address as wallets show it: non-bounceable, flagged on testnet.\n const flags = { bounceable: false, testOnly: options.testnet, urlSafe: true };\n return {\n canonical: rawAddress(parsed.workchain, parsed.hash),\n display: friendlyAddress(parsed.workchain, parsed.hash, flags),\n variant: { bounceable: false },\n };\n },\n format: (address, formatOptions) => {\n const parsed = parseTonAddress(address.canonical);\n if (!parsed) return address.display;\n if (formatOptions?.raw === true) return address.canonical;\n if (formatOptions === undefined || Object.keys(formatOptions).length === 0) {\n return address.display;\n }\n // The variant holds the bounce flag only; the caller's own text keeps the others.\n const shown = parseTonAddress(address.display);\n const spelled = shown?.form === 'friendly' ? shown : undefined;\n const pick = (key: keyof TonAddressVariant, fallback: boolean): boolean => {\n const value = formatOptions[key];\n return typeof value === 'boolean' ? value : fallback;\n };\n const bounceable = address.variant?.bounceable;\n return friendlyAddress(parsed.workchain, parsed.hash, {\n bounceable: pick(\n 'bounceable',\n typeof bounceable === 'boolean' ? bounceable : true,\n ),\n testOnly: pick('testOnly', spelled?.testOnly ?? options.testnet),\n urlSafe: pick('urlSafe', spelled?.urlSafe ?? true),\n });\n },\n };\n}\n"]}
|