ox 0.0.1 → 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/Abi/package.json +6 -0
- package/Abi.ts +163 -0
- package/AbiConstructor/package.json +6 -0
- package/AbiConstructor.ts +413 -0
- package/AbiError/package.json +6 -0
- package/AbiError.ts +719 -0
- package/AbiEvent/package.json +6 -0
- package/AbiEvent.ts +1284 -0
- package/AbiFunction/package.json +6 -0
- package/AbiFunction.ts +813 -0
- package/AbiItem/package.json +6 -0
- package/AbiItem.ts +779 -0
- package/AbiParameters/package.json +6 -0
- package/AbiParameters.ts +712 -0
- package/AccessList/package.json +6 -0
- package/AccessList.ts +124 -0
- package/AccountProof/package.json +6 -0
- package/AccountProof.ts +35 -0
- package/Address/package.json +6 -0
- package/Address.ts +359 -0
- package/AesGcm/package.json +6 -0
- package/AesGcm.ts +220 -0
- package/Authorization/package.json +6 -0
- package/Authorization.ts +639 -0
- package/Base58/package.json +6 -0
- package/Base58.ts +180 -0
- package/Base64/package.json +6 -0
- package/Base64.ts +333 -0
- package/Blobs/package.json +6 -0
- package/Blobs.ts +982 -0
- package/Block/package.json +6 -0
- package/Block.ts +317 -0
- package/Bloom/package.json +6 -0
- package/Bloom.ts +80 -0
- package/Bls/package.json +6 -0
- package/Bls.ts +496 -0
- package/BlsPoint/package.json +6 -0
- package/BlsPoint.ts +232 -0
- package/Bytes/package.json +6 -0
- package/Bytes.ts +963 -0
- package/CHANGELOG.md +7 -0
- package/Caches/package.json +6 -0
- package/Caches.ts +21 -0
- package/ContractAddress/package.json +6 -0
- package/ContractAddress.ts +181 -0
- package/Ens/package.json +6 -0
- package/Ens.ts +116 -0
- package/Errors/package.json +6 -0
- package/Errors.ts +95 -0
- package/Fee/package.json +6 -0
- package/Fee.ts +57 -0
- package/Filter/package.json +6 -0
- package/Filter.ts +144 -0
- package/Hash/package.json +6 -0
- package/Hash.ts +210 -0
- package/HdKey/package.json +6 -0
- package/HdKey.ts +175 -0
- package/Hex/package.json +6 -0
- package/Hex.ts +1040 -0
- package/Json/package.json +6 -0
- package/Json.ts +84 -0
- package/Kzg/package.json +6 -0
- package/Kzg.ts +51 -0
- package/LICENSE +21 -0
- package/Log/package.json +6 -0
- package/Log.ts +248 -0
- package/Mnemonic/package.json +6 -0
- package/Mnemonic.ts +249 -0
- package/P256/package.json +6 -0
- package/P256.ts +230 -0
- package/PersonalMessage/package.json +6 -0
- package/PersonalMessage.ts +70 -0
- package/Provider/package.json +6 -0
- package/Provider.ts +354 -0
- package/PublicKey/package.json +6 -0
- package/PublicKey.ts +545 -0
- package/README.md +75 -26
- package/Rlp/package.json +6 -0
- package/Rlp.ts +390 -0
- package/RpcRequest/package.json +6 -0
- package/RpcRequest.ts +192 -0
- package/RpcResponse/package.json +6 -0
- package/RpcResponse.ts +389 -0
- package/RpcSchema/package.json +6 -0
- package/RpcSchema.ts +273 -0
- package/RpcTransport/package.json +6 -0
- package/RpcTransport.ts +198 -0
- package/Secp256k1/package.json +6 -0
- package/Secp256k1.ts +304 -0
- package/Signature/package.json +6 -0
- package/Signature.ts +909 -0
- package/Siwe/package.json +6 -0
- package/Siwe.ts +516 -0
- package/Solidity/package.json +6 -0
- package/Solidity.ts +109 -0
- package/Transaction/package.json +6 -0
- package/Transaction.ts +429 -0
- package/TransactionEnvelope/package.json +6 -0
- package/TransactionEnvelope.ts +205 -0
- package/TransactionEnvelopeEip1559/package.json +6 -0
- package/TransactionEnvelopeEip1559.ts +656 -0
- package/TransactionEnvelopeEip2930/package.json +6 -0
- package/TransactionEnvelopeEip2930.ts +624 -0
- package/TransactionEnvelopeEip4844/package.json +6 -0
- package/TransactionEnvelopeEip4844.ts +764 -0
- package/TransactionEnvelopeEip7702/package.json +6 -0
- package/TransactionEnvelopeEip7702.ts +639 -0
- package/TransactionEnvelopeLegacy/package.json +6 -0
- package/TransactionEnvelopeLegacy.ts +674 -0
- package/TransactionReceipt/package.json +6 -0
- package/TransactionReceipt.ts +341 -0
- package/TransactionRequest/package.json +6 -0
- package/TransactionRequest.ts +151 -0
- package/TypedData/package.json +6 -0
- package/TypedData.ts +931 -0
- package/ValidatorData/package.json +6 -0
- package/ValidatorData.ts +87 -0
- package/Value/package.json +6 -0
- package/Value.ts +242 -0
- package/WebAuthnP256/package.json +6 -0
- package/WebAuthnP256.ts +803 -0
- package/WebCryptoP256/package.json +6 -0
- package/WebCryptoP256.ts +190 -0
- package/Withdrawal/package.json +6 -0
- package/Withdrawal.ts +95 -0
- package/_cjs/Abi.js +17 -0
- package/_cjs/Abi.js.map +1 -0
- package/_cjs/AbiConstructor.js +42 -0
- package/_cjs/AbiConstructor.js.map +1 -0
- package/_cjs/AbiError.js +98 -0
- package/_cjs/AbiError.js.map +1 -0
- package/_cjs/AbiEvent.js +338 -0
- package/_cjs/AbiEvent.js.map +1 -0
- package/_cjs/AbiFunction.js +85 -0
- package/_cjs/AbiFunction.js.map +1 -0
- package/_cjs/AbiItem.js +180 -0
- package/_cjs/AbiItem.js.map +1 -0
- package/_cjs/AbiParameters.js +229 -0
- package/_cjs/AbiParameters.js.map +1 -0
- package/_cjs/AccessList.js +51 -0
- package/_cjs/AccessList.js.map +1 -0
- package/_cjs/AccountProof.js +3 -0
- package/_cjs/AccountProof.js.map +1 -0
- package/_cjs/Address.js +121 -0
- package/_cjs/Address.js.map +1 -0
- package/_cjs/AesGcm.js +55 -0
- package/_cjs/AesGcm.js.map +1 -0
- package/_cjs/Authorization.js +99 -0
- package/_cjs/Authorization.js.map +1 -0
- package/_cjs/Base58.js +52 -0
- package/_cjs/Base58.js.map +1 -0
- package/_cjs/Base64.js +76 -0
- package/_cjs/Base64.js.map +1 -0
- package/_cjs/Blobs.js +255 -0
- package/_cjs/Blobs.js.map +1 -0
- package/_cjs/Block.js +87 -0
- package/_cjs/Block.js.map +1 -0
- package/_cjs/Bloom.js +23 -0
- package/_cjs/Bloom.js.map +1 -0
- package/_cjs/Bls.js +79 -0
- package/_cjs/Bls.js.map +1 -0
- package/_cjs/BlsPoint.js +32 -0
- package/_cjs/BlsPoint.js.map +1 -0
- package/_cjs/Bytes.js +279 -0
- package/_cjs/Bytes.js.map +1 -0
- package/_cjs/Caches.js +14 -0
- package/_cjs/Caches.js.map +1 -0
- package/_cjs/ContractAddress.js +39 -0
- package/_cjs/ContractAddress.js.map +1 -0
- package/_cjs/Ens.js +37 -0
- package/_cjs/Ens.js.map +1 -0
- package/_cjs/Errors.js +99 -0
- package/_cjs/Errors.js.map +1 -0
- package/_cjs/Fee.js +3 -0
- package/_cjs/Fee.js.map +1 -0
- package/_cjs/Filter.js +43 -0
- package/_cjs/Filter.js.map +1 -0
- package/_cjs/Hash.js +40 -0
- package/_cjs/Hash.js.map +1 -0
- package/_cjs/HdKey.js +30 -0
- package/_cjs/HdKey.js.map +1 -0
- package/_cjs/Hex.js +324 -0
- package/_cjs/Hex.js.map +1 -0
- package/_cjs/Json.js +25 -0
- package/_cjs/Json.js.map +1 -0
- package/_cjs/Kzg.js +14 -0
- package/_cjs/Kzg.js.map +1 -0
- package/_cjs/Log.js +35 -0
- package/_cjs/Log.js.map +1 -0
- package/_cjs/Mnemonic.js +56 -0
- package/_cjs/Mnemonic.js.map +1 -0
- package/_cjs/P256.js +52 -0
- package/_cjs/P256.js.map +1 -0
- package/_cjs/PersonalMessage.js +16 -0
- package/_cjs/PersonalMessage.js.map +1 -0
- package/_cjs/Provider.js +90 -0
- package/_cjs/Provider.js.map +1 -0
- package/_cjs/PublicKey.js +192 -0
- package/_cjs/PublicKey.js.map +1 -0
- package/_cjs/Rlp.js +179 -0
- package/_cjs/Rlp.js.map +1 -0
- package/_cjs/RpcRequest.js +27 -0
- package/_cjs/RpcRequest.js.map +1 -0
- package/_cjs/RpcResponse.js +368 -0
- package/_cjs/RpcResponse.js.map +1 -0
- package/_cjs/RpcSchema.js +7 -0
- package/_cjs/RpcSchema.js.map +1 -0
- package/_cjs/RpcTransport.js +95 -0
- package/_cjs/RpcTransport.js.map +1 -0
- package/_cjs/Secp256k1.js +57 -0
- package/_cjs/Secp256k1.js.map +1 -0
- package/_cjs/Signature.js +305 -0
- package/_cjs/Signature.js.map +1 -0
- package/_cjs/Siwe.js +231 -0
- package/_cjs/Siwe.js.map +1 -0
- package/_cjs/Solidity.js +104 -0
- package/_cjs/Solidity.js.map +1 -0
- package/_cjs/Transaction.js +106 -0
- package/_cjs/Transaction.js.map +1 -0
- package/_cjs/TransactionEnvelope.js +80 -0
- package/_cjs/TransactionEnvelope.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip1559.js +182 -0
- package/_cjs/TransactionEnvelopeEip1559.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip2930.js +166 -0
- package/_cjs/TransactionEnvelopeEip2930.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip4844.js +224 -0
- package/_cjs/TransactionEnvelopeEip4844.js.map +1 -0
- package/_cjs/TransactionEnvelopeEip7702.js +156 -0
- package/_cjs/TransactionEnvelopeEip7702.js.map +1 -0
- package/_cjs/TransactionEnvelopeLegacy.js +221 -0
- package/_cjs/TransactionEnvelopeLegacy.js.map +1 -0
- package/_cjs/TransactionReceipt.js +76 -0
- package/_cjs/TransactionReceipt.js.map +1 -0
- package/_cjs/TransactionRequest.js +51 -0
- package/_cjs/TransactionRequest.js.map +1 -0
- package/_cjs/TypedData.js +318 -0
- package/_cjs/TypedData.js.map +1 -0
- package/_cjs/ValidatorData.js +16 -0
- package/_cjs/ValidatorData.js.map +1 -0
- package/_cjs/Value.js +96 -0
- package/_cjs/Value.js.map +1 -0
- package/_cjs/WebAuthnP256.js +245 -0
- package/_cjs/WebAuthnP256.js.map +1 -0
- package/_cjs/WebCryptoP256.js +46 -0
- package/_cjs/WebCryptoP256.js.map +1 -0
- package/_cjs/Withdrawal.js +24 -0
- package/_cjs/Withdrawal.js.map +1 -0
- package/_cjs/index.js +66 -0
- package/_cjs/index.js.map +1 -0
- package/_cjs/internal/abi.js +11 -0
- package/_cjs/internal/abi.js.map +1 -0
- package/_cjs/internal/abiConstructor.js +3 -0
- package/_cjs/internal/abiConstructor.js.map +1 -0
- package/_cjs/internal/abiError.js +3 -0
- package/_cjs/internal/abiError.js.map +1 -0
- package/_cjs/internal/abiEvent.js +3 -0
- package/_cjs/internal/abiEvent.js.map +1 -0
- package/_cjs/internal/abiFunction.js +3 -0
- package/_cjs/internal/abiFunction.js.map +1 -0
- package/_cjs/internal/abiItem.js +110 -0
- package/_cjs/internal/abiItem.js.map +1 -0
- package/_cjs/internal/abiParameters.js +376 -0
- package/_cjs/internal/abiParameters.js.map +1 -0
- package/_cjs/internal/base58.js +89 -0
- package/_cjs/internal/base58.js.map +1 -0
- package/_cjs/internal/bytes.js +88 -0
- package/_cjs/internal/bytes.js.map +1 -0
- package/_cjs/internal/cursor.js +210 -0
- package/_cjs/internal/cursor.js.map +1 -0
- package/_cjs/internal/ens.js +43 -0
- package/_cjs/internal/ens.js.map +1 -0
- package/_cjs/internal/errors.js +28 -0
- package/_cjs/internal/errors.js.map +1 -0
- package/_cjs/internal/hdKey.js +19 -0
- package/_cjs/internal/hdKey.js.map +1 -0
- package/_cjs/internal/hex.js +66 -0
- package/_cjs/internal/hex.js.map +1 -0
- package/_cjs/internal/lru.js +34 -0
- package/_cjs/internal/lru.js.map +1 -0
- package/_cjs/internal/mnemonic/wordlists.js +24 -0
- package/_cjs/internal/mnemonic/wordlists.js.map +1 -0
- package/_cjs/internal/promise.js +49 -0
- package/_cjs/internal/promise.js.map +1 -0
- package/_cjs/internal/register.js +3 -0
- package/_cjs/internal/register.js.map +1 -0
- package/_cjs/internal/rpcSchema.js +3 -0
- package/_cjs/internal/rpcSchema.js.map +1 -0
- package/_cjs/internal/rpcSchemas/eth.js +3 -0
- package/_cjs/internal/rpcSchemas/eth.js.map +1 -0
- package/_cjs/internal/rpcSchemas/wallet.js +3 -0
- package/_cjs/internal/rpcSchemas/wallet.js.map +1 -0
- package/_cjs/internal/rpcTransport.js +19 -0
- package/_cjs/internal/rpcTransport.js.map +1 -0
- package/_cjs/internal/types.js +3 -0
- package/_cjs/internal/types.js.map +1 -0
- package/_cjs/internal/uid.js +17 -0
- package/_cjs/internal/uid.js.map +1 -0
- package/_cjs/internal/webauthn.js +28 -0
- package/_cjs/internal/webauthn.js.map +1 -0
- package/_cjs/package.json +1 -0
- package/_cjs/trusted-setups/Paths.js +6 -0
- package/_cjs/trusted-setups/Paths.js.map +1 -0
- package/_cjs/trusted-setups/index.js +5 -0
- package/_cjs/trusted-setups/index.js.map +1 -0
- package/_cjs/trusted-setups/internal/paths.js +11 -0
- package/_cjs/trusted-setups/internal/paths.js.map +1 -0
- package/_cjs/version.js +5 -0
- package/_cjs/version.js.map +1 -0
- package/_cjs/window/index.js +3 -0
- package/_cjs/window/index.js.map +1 -0
- package/_esm/Abi.js +19 -0
- package/_esm/Abi.js.map +1 -0
- package/_esm/AbiConstructor.js +102 -0
- package/_esm/AbiConstructor.js.map +1 -0
- package/_esm/AbiError.js +364 -0
- package/_esm/AbiError.js.map +1 -0
- package/_esm/AbiEvent.js +1038 -0
- package/_esm/AbiEvent.js.map +1 -0
- package/_esm/AbiFunction.js +549 -0
- package/_esm/AbiFunction.js.map +1 -0
- package/_esm/AbiItem.js +574 -0
- package/_esm/AbiItem.js.map +1 -0
- package/_esm/AbiParameters.js +543 -0
- package/_esm/AbiParameters.js.map +1 -0
- package/_esm/AccessList.js +105 -0
- package/_esm/AccessList.js.map +1 -0
- package/_esm/AccountProof.js +2 -0
- package/_esm/AccountProof.js.map +1 -0
- package/_esm/Address.js +268 -0
- package/_esm/Address.js.map +1 -0
- package/_esm/AesGcm.js +124 -0
- package/_esm/AesGcm.js.map +1 -0
- package/_esm/Authorization.js +441 -0
- package/_esm/Authorization.js.map +1 -0
- package/_esm/Base58.js +142 -0
- package/_esm/Base58.js.map +1 -0
- package/_esm/Base64.js +236 -0
- package/_esm/Base64.js.map +1 -0
- package/_esm/Blobs.js +624 -0
- package/_esm/Blobs.js.map +1 -0
- package/_esm/Block.js +177 -0
- package/_esm/Block.js.map +1 -0
- package/_esm/Bloom.js +57 -0
- package/_esm/Bloom.js.map +1 -0
- package/_esm/Bls.js +141 -0
- package/_esm/Bls.js.map +1 -0
- package/_esm/BlsPoint.js +59 -0
- package/_esm/BlsPoint.js.map +1 -0
- package/_esm/Bytes.js +719 -0
- package/_esm/Bytes.js.map +1 -0
- package/_esm/Caches.js +19 -0
- package/_esm/Caches.js.map +1 -0
- package/_esm/ContractAddress.js +110 -0
- package/_esm/ContractAddress.js.map +1 -0
- package/_esm/Ens.js +84 -0
- package/_esm/Ens.js.map +1 -0
- package/_esm/Errors.js +105 -0
- package/_esm/Errors.js.map +1 -0
- package/_esm/Fee.js +2 -0
- package/_esm/Fee.js.map +1 -0
- package/_esm/Filter.js +100 -0
- package/_esm/Filter.js.map +1 -0
- package/_esm/Hash.js +126 -0
- package/_esm/Hash.js.map +1 -0
- package/_esm/HdKey.js +107 -0
- package/_esm/HdKey.js.map +1 -0
- package/_esm/Hex.js +763 -0
- package/_esm/Hex.js.map +1 -0
- package/_esm/Json.js +62 -0
- package/_esm/Json.js.map +1 -0
- package/_esm/Kzg.js +30 -0
- package/_esm/Kzg.js.map +1 -0
- package/_esm/Log.js +181 -0
- package/_esm/Log.js.map +1 -0
- package/_esm/Mnemonic.js +154 -0
- package/_esm/Mnemonic.js.map +1 -0
- package/_esm/P256.js +131 -0
- package/_esm/P256.js.map +1 -0
- package/_esm/PersonalMessage.js +46 -0
- package/_esm/PersonalMessage.js.map +1 -0
- package/_esm/Provider.js +122 -0
- package/_esm/Provider.js.map +1 -0
- package/_esm/PublicKey.js +395 -0
- package/_esm/PublicKey.js.map +1 -0
- package/_esm/Rlp.js +267 -0
- package/_esm/Rlp.js.map +1 -0
- package/_esm/RpcRequest.js +131 -0
- package/_esm/RpcRequest.js.map +1 -0
- package/_esm/RpcResponse.js +457 -0
- package/_esm/RpcResponse.js.map +1 -0
- package/_esm/RpcSchema.js +46 -0
- package/_esm/RpcSchema.js.map +1 -0
- package/_esm/RpcTransport.js +110 -0
- package/_esm/RpcTransport.js.map +1 -0
- package/_esm/Secp256k1.js +173 -0
- package/_esm/Secp256k1.js.map +1 -0
- package/_esm/Signature.js +696 -0
- package/_esm/Signature.js.map +1 -0
- package/_esm/Siwe.js +374 -0
- package/_esm/Siwe.js.map +1 -0
- package/_esm/Solidity.js +104 -0
- package/_esm/Solidity.js.map +1 -0
- package/_esm/Transaction.js +176 -0
- package/_esm/Transaction.js.map +1 -0
- package/_esm/TransactionEnvelope.js +139 -0
- package/_esm/TransactionEnvelope.js.map +1 -0
- package/_esm/TransactionEnvelopeEip1559.js +455 -0
- package/_esm/TransactionEnvelopeEip1559.js.map +1 -0
- package/_esm/TransactionEnvelopeEip2930.js +439 -0
- package/_esm/TransactionEnvelopeEip2930.js.map +1 -0
- package/_esm/TransactionEnvelopeEip4844.js +542 -0
- package/_esm/TransactionEnvelopeEip4844.js.map +1 -0
- package/_esm/TransactionEnvelopeEip7702.js +442 -0
- package/_esm/TransactionEnvelopeEip7702.js.map +1 -0
- package/_esm/TransactionEnvelopeLegacy.js +495 -0
- package/_esm/TransactionEnvelopeLegacy.js.map +1 -0
- package/_esm/TransactionReceipt.js +229 -0
- package/_esm/TransactionReceipt.js.map +1 -0
- package/_esm/TransactionRequest.js +89 -0
- package/_esm/TransactionRequest.js.map +1 -0
- package/_esm/TypedData.js +635 -0
- package/_esm/TypedData.js.map +1 -0
- package/_esm/ValidatorData.js +52 -0
- package/_esm/ValidatorData.js.map +1 -0
- package/_esm/Value.js +196 -0
- package/_esm/Value.js.map +1 -0
- package/_esm/WebAuthnP256.js +471 -0
- package/_esm/WebAuthnP256.js.map +1 -0
- package/_esm/WebCryptoP256.js +116 -0
- package/_esm/WebCryptoP256.js.map +1 -0
- package/_esm/Withdrawal.js +72 -0
- package/_esm/Withdrawal.js.map +1 -0
- package/_esm/index.js +3366 -0
- package/_esm/index.js.map +1 -0
- package/_esm/internal/abi.js +9 -0
- package/_esm/internal/abi.js.map +1 -0
- package/_esm/internal/abiConstructor.js +2 -0
- package/_esm/internal/abiConstructor.js.map +1 -0
- package/_esm/internal/abiError.js +2 -0
- package/_esm/internal/abiError.js.map +1 -0
- package/_esm/internal/abiEvent.js +2 -0
- package/_esm/internal/abiEvent.js.map +1 -0
- package/_esm/internal/abiFunction.js +2 -0
- package/_esm/internal/abiFunction.js.map +1 -0
- package/_esm/internal/abiItem.js +122 -0
- package/_esm/internal/abiItem.js.map +1 -0
- package/_esm/internal/abiParameters.js +419 -0
- package/_esm/internal/abiParameters.js.map +1 -0
- package/_esm/internal/base58.js +91 -0
- package/_esm/internal/base58.js.map +1 -0
- package/_esm/internal/bytes.js +86 -0
- package/_esm/internal/bytes.js.map +1 -0
- package/_esm/internal/cursor.js +207 -0
- package/_esm/internal/cursor.js.map +1 -0
- package/_esm/internal/ens.js +47 -0
- package/_esm/internal/ens.js.map +1 -0
- package/_esm/internal/errors.js +26 -0
- package/_esm/internal/errors.js.map +1 -0
- package/_esm/internal/hdKey.js +17 -0
- package/_esm/internal/hdKey.js.map +1 -0
- package/_esm/internal/hex.js +64 -0
- package/_esm/internal/hex.js.map +1 -0
- package/_esm/internal/lru.js +36 -0
- package/_esm/internal/lru.js.map +1 -0
- package/_esm/internal/mnemonic/wordlists.js +11 -0
- package/_esm/internal/mnemonic/wordlists.js.map +1 -0
- package/_esm/internal/promise.js +52 -0
- package/_esm/internal/promise.js.map +1 -0
- package/_esm/internal/register.js +2 -0
- package/_esm/internal/register.js.map +1 -0
- package/_esm/internal/rpcSchema.js +2 -0
- package/_esm/internal/rpcSchema.js.map +1 -0
- package/_esm/internal/rpcSchemas/eth.js +2 -0
- package/_esm/internal/rpcSchemas/eth.js.map +1 -0
- package/_esm/internal/rpcSchemas/wallet.js +2 -0
- package/_esm/internal/rpcSchemas/wallet.js.map +1 -0
- package/_esm/internal/rpcTransport.js +20 -0
- package/_esm/internal/rpcTransport.js.map +1 -0
- package/_esm/internal/types.js +2 -0
- package/_esm/internal/types.js.map +1 -0
- package/_esm/internal/uid.js +15 -0
- package/_esm/internal/uid.js.map +1 -0
- package/_esm/internal/webauthn.js +35 -0
- package/_esm/internal/webauthn.js.map +1 -0
- package/_esm/package.json +1 -0
- package/_esm/trusted-setups/Paths.js +3 -0
- package/_esm/trusted-setups/Paths.js.map +1 -0
- package/_esm/trusted-setups/index.js +2 -0
- package/_esm/trusted-setups/index.js.map +1 -0
- package/_esm/trusted-setups/internal/paths.js +12 -0
- package/_esm/trusted-setups/internal/paths.js.map +1 -0
- package/_esm/version.js +3 -0
- package/_esm/version.js.map +1 -0
- package/_esm/window/index.js +2 -0
- package/_esm/window/index.js.map +1 -0
- package/_test/Abi.test-d/package.json +6 -0
- package/_test/AbiConstructor.test-d/package.json +6 -0
- package/_test/AbiError.test-d/package.json +6 -0
- package/_test/AbiEvent.snap-d/package.json +6 -0
- package/_test/AbiEvent.snap-d.ts +329 -0
- package/_test/AbiFunction.snap-d/package.json +6 -0
- package/_test/AbiFunction.snap-d.ts +262 -0
- package/_test/AbiItem.snap-d/package.json +6 -0
- package/_test/AbiItem.snap-d.ts +131 -0
- package/_test/AbiParameters.bench/package.json +6 -0
- package/_test/AbiParameters.snap-d/package.json +6 -0
- package/_test/AbiParameters.snap-d.ts +66 -0
- package/_test/Address.bench/package.json +6 -0
- package/_test/Base58.bench/package.json +6 -0
- package/_test/Hex.bench/package.json +6 -0
- package/_test/Hex.test-d/package.json +6 -0
- package/_test/PublicKey.test-d/package.json +6 -0
- package/_test/Rlp.bench/package.json +6 -0
- package/_test/Rlp.test-d/package.json +6 -0
- package/_test/Signature.snap-d/package.json +6 -0
- package/_test/Signature.snap-d.ts +96 -0
- package/_test/TransactionEnvelopeEip1559.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeEip2930.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeEip4844.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeEip7702.test-d/package.json +6 -0
- package/_test/TransactionEnvelopeLegacy.test-d/package.json +6 -0
- package/_test/TypedData.test-d/package.json +6 -0
- package/_types/Abi.d.ts +137 -0
- package/_types/Abi.d.ts.map +1 -0
- package/_types/AbiConstructor.d.ts +305 -0
- package/_types/AbiConstructor.d.ts.map +1 -0
- package/_types/AbiError.d.ts +522 -0
- package/_types/AbiError.d.ts.map +1 -0
- package/_types/AbiEvent.d.ts +892 -0
- package/_types/AbiEvent.d.ts.map +1 -0
- package/_types/AbiFunction.d.ts +602 -0
- package/_types/AbiFunction.d.ts.map +1 -0
- package/_types/AbiItem.d.ts +544 -0
- package/_types/AbiItem.d.ts.map +1 -0
- package/_types/AbiParameters.d.ts +466 -0
- package/_types/AbiParameters.d.ts.map +1 -0
- package/_types/AccessList.d.ts +83 -0
- package/_types/AccessList.d.ts.map +1 -0
- package/_types/AccountProof.d.ts +32 -0
- package/_types/AccountProof.d.ts.map +1 -0
- package/_types/Address.d.ts +244 -0
- package/_types/Address.d.ts.map +1 -0
- package/_types/AesGcm.d.ts +116 -0
- package/_types/AesGcm.d.ts.map +1 -0
- package/_types/Authorization.d.ts +461 -0
- package/_types/Authorization.d.ts.map +1 -0
- package/_types/Base58.d.ts +131 -0
- package/_types/Base58.d.ts.map +1 -0
- package/_types/Base64.d.ts +244 -0
- package/_types/Base64.d.ts.map +1 -0
- package/_types/Blobs.d.ts +556 -0
- package/_types/Blobs.d.ts.map +1 -0
- package/_types/Block.d.ts +190 -0
- package/_types/Block.d.ts.map +1 -0
- package/_types/Bloom.d.ts +54 -0
- package/_types/Bloom.d.ts.map +1 -0
- package/_types/Bls.d.ts +365 -0
- package/_types/Bls.d.ts.map +1 -0
- package/_types/BlsPoint.d.ts +187 -0
- package/_types/BlsPoint.d.ts.map +1 -0
- package/_types/Bytes.d.ts +674 -0
- package/_types/Bytes.d.ts.map +1 -0
- package/_types/Caches.d.ts +13 -0
- package/_types/Caches.d.ts.map +1 -0
- package/_types/ContractAddress.d.ts +115 -0
- package/_types/ContractAddress.d.ts.map +1 -0
- package/_types/Ens.d.ts +72 -0
- package/_types/Ens.d.ts.map +1 -0
- package/_types/Errors.d.ts +33 -0
- package/_types/Errors.d.ts.map +1 -0
- package/_types/Fee.d.ts +41 -0
- package/_types/Fee.d.ts.map +1 -0
- package/_types/Filter.d.ts +100 -0
- package/_types/Filter.d.ts.map +1 -0
- package/_types/Hash.d.ts +135 -0
- package/_types/Hash.d.ts.map +1 -0
- package/_types/HdKey.d.ts +146 -0
- package/_types/HdKey.d.ts.map +1 -0
- package/_types/Hex.d.ts +711 -0
- package/_types/Hex.d.ts.map +1 -0
- package/_types/Json.d.ts +53 -0
- package/_types/Json.d.ts.map +1 -0
- package/_types/Kzg.d.ts +42 -0
- package/_types/Kzg.d.ts.map +1 -0
- package/_types/Log.d.ts +194 -0
- package/_types/Log.d.ts.map +1 -0
- package/_types/Mnemonic.d.ts +176 -0
- package/_types/Mnemonic.d.ts.map +1 -0
- package/_types/P256.d.ts +207 -0
- package/_types/P256.d.ts.map +1 -0
- package/_types/PersonalMessage.d.ts +49 -0
- package/_types/PersonalMessage.d.ts.map +1 -0
- package/_types/Provider.d.ts +268 -0
- package/_types/Provider.d.ts.map +1 -0
- package/_types/PublicKey.d.ts +327 -0
- package/_types/PublicKey.d.ts.map +1 -0
- package/_types/Rlp.d.ts +153 -0
- package/_types/Rlp.d.ts.map +1 -0
- package/_types/RpcRequest.d.ts +144 -0
- package/_types/RpcRequest.d.ts.map +1 -0
- package/_types/RpcResponse.d.ts +266 -0
- package/_types/RpcResponse.d.ts.map +1 -0
- package/_types/RpcSchema.d.ts +248 -0
- package/_types/RpcSchema.d.ts.map +1 -0
- package/_types/RpcTransport.d.ts +65 -0
- package/_types/RpcTransport.d.ts.map +1 -0
- package/_types/Secp256k1.d.ts +277 -0
- package/_types/Secp256k1.d.ts.map +1 -0
- package/_types/Signature.d.ts +601 -0
- package/_types/Signature.d.ts.map +1 -0
- package/_types/Siwe.d.ts +249 -0
- package/_types/Siwe.d.ts.map +1 -0
- package/_types/Solidity.d.ts +100 -0
- package/_types/Solidity.d.ts.map +1 -0
- package/_types/Transaction.d.ts +235 -0
- package/_types/Transaction.d.ts.map +1 -0
- package/_types/TransactionEnvelope.d.ts +141 -0
- package/_types/TransactionEnvelope.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip1559.d.ts +367 -0
- package/_types/TransactionEnvelopeEip1559.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip2930.d.ts +364 -0
- package/_types/TransactionEnvelopeEip2930.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip4844.d.ts +419 -0
- package/_types/TransactionEnvelopeEip4844.d.ts.map +1 -0
- package/_types/TransactionEnvelopeEip7702.d.ts +377 -0
- package/_types/TransactionEnvelopeEip7702.d.ts.map +1 -0
- package/_types/TransactionEnvelopeLegacy.d.ts +358 -0
- package/_types/TransactionEnvelopeLegacy.d.ts.map +1 -0
- package/_types/TransactionReceipt.d.ts +271 -0
- package/_types/TransactionReceipt.d.ts.map +1 -0
- package/_types/TransactionRequest.d.ts +92 -0
- package/_types/TransactionRequest.d.ts.map +1 -0
- package/_types/TypedData.d.ts +496 -0
- package/_types/TypedData.d.ts.map +1 -0
- package/_types/ValidatorData.d.ts +64 -0
- package/_types/ValidatorData.d.ts.map +1 -0
- package/_types/Value.d.ts +159 -0
- package/_types/Value.d.ts.map +1 -0
- package/_types/WebAuthnP256.d.ts +445 -0
- package/_types/WebAuthnP256.d.ts.map +1 -0
- package/_types/WebCryptoP256.d.ts +119 -0
- package/_types/WebCryptoP256.d.ts.map +1 -0
- package/_types/Withdrawal.d.ts +74 -0
- package/_types/Withdrawal.d.ts.map +1 -0
- package/_types/index.d.ts +3367 -0
- package/_types/index.d.ts.map +1 -0
- package/_types/internal/abi.d.ts +4 -0
- package/_types/internal/abi.d.ts.map +1 -0
- package/_types/internal/abiConstructor.d.ts +11 -0
- package/_types/internal/abiConstructor.d.ts.map +1 -0
- package/_types/internal/abiError.d.ts +11 -0
- package/_types/internal/abiError.d.ts.map +1 -0
- package/_types/internal/abiEvent.d.ts +60 -0
- package/_types/internal/abiEvent.d.ts.map +1 -0
- package/_types/internal/abiFunction.d.ts +11 -0
- package/_types/internal/abiFunction.d.ts.map +1 -0
- package/_types/internal/abiItem.d.ts +100 -0
- package/_types/internal/abiItem.d.ts.map +1 -0
- package/_types/internal/abiParameters.d.ts +169 -0
- package/_types/internal/abiParameters.d.ts.map +1 -0
- package/_types/internal/base58.d.ts +17 -0
- package/_types/internal/base58.d.ts.map +1 -0
- package/_types/internal/bytes.d.ts +52 -0
- package/_types/internal/bytes.d.ts.map +1 -0
- package/_types/internal/cursor.d.ts +70 -0
- package/_types/internal/cursor.d.ts.map +1 -0
- package/_types/internal/ens.d.ts +23 -0
- package/_types/internal/ens.d.ts.map +1 -0
- package/_types/internal/errors.d.ts +7 -0
- package/_types/internal/errors.d.ts.map +1 -0
- package/_types/internal/hdKey.d.ts +10 -0
- package/_types/internal/hdKey.d.ts.map +1 -0
- package/_types/internal/hex.d.ts +39 -0
- package/_types/internal/hex.d.ts.map +1 -0
- package/_types/internal/lru.d.ts +13 -0
- package/_types/internal/lru.d.ts.map +1 -0
- package/_types/internal/mnemonic/wordlists.d.ts +11 -0
- package/_types/internal/mnemonic/wordlists.d.ts.map +1 -0
- package/_types/internal/promise.d.ts +27 -0
- package/_types/internal/promise.d.ts.map +1 -0
- package/_types/internal/register.d.ts +13 -0
- package/_types/internal/register.d.ts.map +1 -0
- package/_types/internal/rpcSchema.d.ts +12 -0
- package/_types/internal/rpcSchema.d.ts.map +1 -0
- package/_types/internal/rpcSchemas/eth.d.ts +718 -0
- package/_types/internal/rpcSchemas/eth.d.ts.map +1 -0
- package/_types/internal/rpcSchemas/wallet.d.ts +416 -0
- package/_types/internal/rpcSchemas/wallet.d.ts.map +1 -0
- package/_types/internal/rpcTransport.d.ts +38 -0
- package/_types/internal/rpcTransport.d.ts.map +1 -0
- package/_types/internal/types.d.ts +284 -0
- package/_types/internal/types.d.ts.map +1 -0
- package/_types/internal/uid.d.ts +3 -0
- package/_types/internal/uid.d.ts.map +1 -0
- package/_types/internal/webauthn.d.ts +127 -0
- package/_types/internal/webauthn.d.ts.map +1 -0
- package/_types/trusted-setups/Paths.d.ts +2 -0
- package/_types/trusted-setups/Paths.d.ts.map +1 -0
- package/_types/trusted-setups/index.d.ts +2 -0
- package/_types/trusted-setups/index.d.ts.map +1 -0
- package/_types/trusted-setups/internal/paths.d.ts +3 -0
- package/_types/trusted-setups/internal/paths.d.ts.map +1 -0
- package/_types/version.d.ts +3 -0
- package/_types/version.d.ts.map +1 -0
- package/_types/window/index.d.ts +7 -0
- package/_types/window/index.d.ts.map +1 -0
- package/index.ts +3427 -0
- package/internal/abi.ts +11 -0
- package/internal/abiConstructor.ts +32 -0
- package/internal/abiError.ts +30 -0
- package/internal/abiEvent.ts +154 -0
- package/internal/abiFunction.ts +32 -0
- package/internal/abiItem.ts +593 -0
- package/internal/abiParameters.ts +741 -0
- package/internal/base58.ts +106 -0
- package/internal/bytes.ts +152 -0
- package/internal/cursor.ts +252 -0
- package/internal/ens.ts +64 -0
- package/internal/errors.ts +26 -0
- package/internal/hdKey.ts +25 -0
- package/internal/hex.ts +123 -0
- package/internal/lru.ts +34 -0
- package/internal/mnemonic/wordlists.ts +10 -0
- package/internal/promise.ts +66 -0
- package/internal/register.ts +15 -0
- package/internal/rpcSchema.ts +20 -0
- package/internal/rpcSchemas/eth.ts +727 -0
- package/internal/rpcSchemas/wallet.ts +428 -0
- package/internal/rpcTransport.ts +74 -0
- package/internal/types.ts +414 -0
- package/internal/uid.ts +15 -0
- package/internal/webauthn.ts +198 -0
- package/package.json +500 -20
- package/trusted-setups/Paths/package.json +6 -0
- package/trusted-setups/Paths.ts +3 -0
- package/trusted-setups/index.ts +1 -0
- package/trusted-setups/internal/paths.ts +13 -0
- package/trusted-setups/internal/setups/mainnet.json +8265 -0
- package/trusted-setups/internal/setups/mainnet.txt +4163 -0
- package/trusted-setups/package.json +6 -0
- package/tsdoc.json +4 -0
- package/version/package.json +6 -0
- package/version.ts +2 -0
- package/window/index.ts +7 -0
- package/window/package.json +6 -0
- package/cl/ansiesc.js +0 -25
- package/cl/deps.js +0 -7
- package/cl/editor.js +0 -141
- package/cl/index.html +0 -19
- package/cl/ox.js +0 -44
- package/cl/socket.io.js +0 -1922
- package/cl/style.css +0 -37
- package/srv/deps.js +0 -88
- package/srv/httpSrv.js +0 -82
- package/srv/ox.js +0 -44
- package/srv/remoteXtermReq.js +0 -70
package/Bytes.ts
ADDED
|
@@ -0,0 +1,963 @@
|
|
|
1
|
+
import { equalBytes } from '@noble/curves/abstract/utils'
|
|
2
|
+
import * as Errors from './Errors.js'
|
|
3
|
+
import * as Hex from './Hex.js'
|
|
4
|
+
import * as Json from './Json.js'
|
|
5
|
+
import * as internal from './internal/bytes.js'
|
|
6
|
+
import * as internal_hex from './internal/hex.js'
|
|
7
|
+
|
|
8
|
+
const decoder = /*#__PURE__*/ new TextDecoder()
|
|
9
|
+
const encoder = /*#__PURE__*/ new TextEncoder()
|
|
10
|
+
|
|
11
|
+
/** Root type for a Bytes array. */
|
|
12
|
+
export type Bytes = Uint8Array
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Asserts if the given value is {@link ox#Bytes.Bytes}.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts twoslash
|
|
19
|
+
* import { Bytes } from 'ox'
|
|
20
|
+
*
|
|
21
|
+
* Bytes.assert('abc')
|
|
22
|
+
* // @error: Bytes.InvalidBytesTypeError:
|
|
23
|
+
* // @error: Value `"abc"` of type `string` is an invalid Bytes value.
|
|
24
|
+
* // @error: Bytes values must be of type `Uint8Array`.
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param value - Value to assert.
|
|
28
|
+
*/
|
|
29
|
+
export function assert(value: unknown): asserts value is Bytes {
|
|
30
|
+
if (value instanceof Uint8Array) return
|
|
31
|
+
if (!value) throw new InvalidBytesTypeError(value)
|
|
32
|
+
if (typeof value !== 'object') throw new InvalidBytesTypeError(value)
|
|
33
|
+
if (!('BYTES_PER_ELEMENT' in value)) throw new InvalidBytesTypeError(value)
|
|
34
|
+
if (value.BYTES_PER_ELEMENT !== 1 || value.constructor.name !== 'Uint8Array')
|
|
35
|
+
throw new InvalidBytesTypeError(value)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export declare namespace assert {
|
|
39
|
+
type ErrorType = InvalidBytesTypeError | Errors.GlobalErrorType
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* v8 ignore next */
|
|
43
|
+
assert.parseError = (error: unknown) => error as assert.ErrorType
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Concatenates two or more {@link ox#Bytes.Bytes}.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts twoslash
|
|
50
|
+
* import { Bytes } from 'ox'
|
|
51
|
+
*
|
|
52
|
+
* const bytes = Bytes.concat(
|
|
53
|
+
* Bytes.from([1]),
|
|
54
|
+
* Bytes.from([69]),
|
|
55
|
+
* Bytes.from([420, 69]),
|
|
56
|
+
* )
|
|
57
|
+
* // @log: Uint8Array [ 1, 69, 420, 69 ]
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @param values - Values to concatenate.
|
|
61
|
+
* @returns Concatenated {@link ox#Bytes.Bytes}.
|
|
62
|
+
*/
|
|
63
|
+
export function concat(...values: readonly Bytes[]): Bytes {
|
|
64
|
+
let length = 0
|
|
65
|
+
for (const arr of values) {
|
|
66
|
+
length += arr.length
|
|
67
|
+
}
|
|
68
|
+
const result = new Uint8Array(length)
|
|
69
|
+
for (let i = 0, index = 0; i < values.length; i++) {
|
|
70
|
+
const arr = values[i]
|
|
71
|
+
result.set(arr!, index)
|
|
72
|
+
index += arr!.length
|
|
73
|
+
}
|
|
74
|
+
return result
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export declare namespace concat {
|
|
78
|
+
type ErrorType = Errors.GlobalErrorType
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/* v8 ignore next */
|
|
82
|
+
concat.parseError = (error: unknown) => error as concat.ErrorType
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Instantiates a {@link ox#Bytes.Bytes} value from a `Uint8Array`, a hex string, or an array of unsigned 8-bit integers.
|
|
86
|
+
*
|
|
87
|
+
* :::tip
|
|
88
|
+
*
|
|
89
|
+
* To instantiate from a **Boolean**, **String**, or **Number**, use one of the following:
|
|
90
|
+
*
|
|
91
|
+
* - `Bytes.fromBoolean`
|
|
92
|
+
*
|
|
93
|
+
* - `Bytes.fromString`
|
|
94
|
+
*
|
|
95
|
+
* - `Bytes.fromNumber`
|
|
96
|
+
*
|
|
97
|
+
* :::
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts twoslash
|
|
101
|
+
* // @noErrors
|
|
102
|
+
* import { Bytes } from 'ox'
|
|
103
|
+
*
|
|
104
|
+
* const data = Bytes.from([255, 124, 5, 4])
|
|
105
|
+
* // @log: Uint8Array([255, 124, 5, 4])
|
|
106
|
+
*
|
|
107
|
+
* const data = Bytes.from('0xdeadbeef')
|
|
108
|
+
* // @log: Uint8Array([222, 173, 190, 239])
|
|
109
|
+
* ```
|
|
110
|
+
*
|
|
111
|
+
* @param value - Value to convert.
|
|
112
|
+
* @returns A {@link ox#Bytes.Bytes} instance.
|
|
113
|
+
*/
|
|
114
|
+
export function from(value: Hex.Hex | Bytes | readonly number[]): Bytes {
|
|
115
|
+
if (value instanceof Uint8Array) return value
|
|
116
|
+
if (typeof value === 'string') return fromHex(value)
|
|
117
|
+
return fromArray(value)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export declare namespace from {
|
|
121
|
+
type ErrorType =
|
|
122
|
+
| fromHex.ErrorType
|
|
123
|
+
| fromArray.ErrorType
|
|
124
|
+
| Errors.GlobalErrorType
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
from.parseError = (error: unknown) =>
|
|
128
|
+
/* v8 ignore next */
|
|
129
|
+
error as from.ErrorType
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Converts an array of unsigned 8-bit integers into {@link ox#Bytes.Bytes}.
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```ts twoslash
|
|
136
|
+
* import { Bytes } from 'ox'
|
|
137
|
+
*
|
|
138
|
+
* const data = Bytes.fromArray([255, 124, 5, 4])
|
|
139
|
+
* // @log: Uint8Array([255, 124, 5, 4])
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* @param value - Value to convert.
|
|
143
|
+
* @returns A {@link ox#Bytes.Bytes} instance.
|
|
144
|
+
*/
|
|
145
|
+
export function fromArray(value: readonly number[] | Uint8Array): Bytes {
|
|
146
|
+
return value instanceof Uint8Array ? value : new Uint8Array(value)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export declare namespace fromArray {
|
|
150
|
+
type ErrorType = Errors.GlobalErrorType
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
fromArray.parseError = (error: unknown) =>
|
|
154
|
+
/* v8 ignore next */
|
|
155
|
+
error as fromArray.ErrorType
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Encodes a boolean value into {@link ox#Bytes.Bytes}.
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```ts twoslash
|
|
162
|
+
* import { Bytes } from 'ox'
|
|
163
|
+
*
|
|
164
|
+
* const data = Bytes.fromBoolean(true)
|
|
165
|
+
* // @log: Uint8Array([1])
|
|
166
|
+
* ```
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts twoslash
|
|
170
|
+
* import { Bytes } from 'ox'
|
|
171
|
+
*
|
|
172
|
+
* const data = Bytes.fromBoolean(true, { size: 32 })
|
|
173
|
+
* // @log: Uint8Array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1])
|
|
174
|
+
* ```
|
|
175
|
+
*
|
|
176
|
+
* @param value - Boolean value to encode.
|
|
177
|
+
* @param options - Encoding options.
|
|
178
|
+
* @returns Encoded {@link ox#Bytes.Bytes}.
|
|
179
|
+
*/
|
|
180
|
+
export function fromBoolean(value: boolean, options: fromBoolean.Options = {}) {
|
|
181
|
+
const { size } = options
|
|
182
|
+
const bytes = new Uint8Array(1)
|
|
183
|
+
bytes[0] = Number(value)
|
|
184
|
+
if (typeof size === 'number') {
|
|
185
|
+
internal.assertSize(bytes, size)
|
|
186
|
+
return padLeft(bytes, size)
|
|
187
|
+
}
|
|
188
|
+
return bytes
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export declare namespace fromBoolean {
|
|
192
|
+
type Options = {
|
|
193
|
+
/** Size of the output bytes. */
|
|
194
|
+
size?: number | undefined
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
type ErrorType =
|
|
198
|
+
| internal.assertSize.ErrorType
|
|
199
|
+
| padLeft.ErrorType
|
|
200
|
+
| Errors.GlobalErrorType
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
fromBoolean.parseError = (error: unknown) =>
|
|
204
|
+
/* v8 ignore next */
|
|
205
|
+
error as fromBoolean.ErrorType
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Encodes a {@link ox#Hex.Hex} value into {@link ox#Bytes.Bytes}.
|
|
209
|
+
*
|
|
210
|
+
* @example
|
|
211
|
+
* ```ts twoslash
|
|
212
|
+
* import { Bytes } from 'ox'
|
|
213
|
+
*
|
|
214
|
+
* const data = Bytes.fromHex('0x48656c6c6f20776f726c6421')
|
|
215
|
+
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33])
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```ts twoslash
|
|
220
|
+
* import { Bytes } from 'ox'
|
|
221
|
+
*
|
|
222
|
+
* const data = Bytes.fromHex('0x48656c6c6f20776f726c6421', { size: 32 })
|
|
223
|
+
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* @param value - {@link ox#Hex.Hex} value to encode.
|
|
227
|
+
* @param options - Encoding options.
|
|
228
|
+
* @returns Encoded {@link ox#Bytes.Bytes}.
|
|
229
|
+
*/
|
|
230
|
+
export function fromHex(value: Hex.Hex, options: fromHex.Options = {}): Bytes {
|
|
231
|
+
const { size } = options
|
|
232
|
+
|
|
233
|
+
if (value.length % 2) throw new Hex.InvalidLengthError(value)
|
|
234
|
+
|
|
235
|
+
let hex = value
|
|
236
|
+
if (size) {
|
|
237
|
+
internal_hex.assertSize(value, size)
|
|
238
|
+
hex = Hex.padRight(value, size)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const hexString = hex.slice(2) as string
|
|
242
|
+
|
|
243
|
+
const length = hexString.length / 2
|
|
244
|
+
const bytes = new Uint8Array(length)
|
|
245
|
+
for (let index = 0, j = 0; index < length; index++) {
|
|
246
|
+
const nibbleLeft = internal.charCodeToBase16(hexString.charCodeAt(j++))
|
|
247
|
+
const nibbleRight = internal.charCodeToBase16(hexString.charCodeAt(j++))
|
|
248
|
+
if (nibbleLeft === undefined || nibbleRight === undefined) {
|
|
249
|
+
throw new Errors.BaseError(
|
|
250
|
+
`Invalid byte sequence ("${hexString[j - 2]}${hexString[j - 1]}" in "${hexString}").`,
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
bytes[index] = nibbleLeft * 16 + nibbleRight
|
|
254
|
+
}
|
|
255
|
+
return bytes
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export declare namespace fromHex {
|
|
259
|
+
type Options = {
|
|
260
|
+
/** Size of the output bytes. */
|
|
261
|
+
size?: number | undefined
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
type ErrorType =
|
|
265
|
+
| internal_hex.assertSize.ErrorType
|
|
266
|
+
| Hex.padRight.ErrorType
|
|
267
|
+
| Hex.InvalidLengthError
|
|
268
|
+
| Errors.GlobalErrorType
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/* v8 ignore next */
|
|
272
|
+
fromHex.parseError = (error: unknown) => error as fromHex.ErrorType
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Encodes a number value into {@link ox#Bytes.Bytes}.
|
|
276
|
+
*
|
|
277
|
+
* @example
|
|
278
|
+
* ```ts twoslash
|
|
279
|
+
* import { Bytes } from 'ox'
|
|
280
|
+
*
|
|
281
|
+
* const data = Bytes.fromNumber(420)
|
|
282
|
+
* // @log: Uint8Array([1, 164])
|
|
283
|
+
* ```
|
|
284
|
+
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```ts twoslash
|
|
287
|
+
* import { Bytes } from 'ox'
|
|
288
|
+
*
|
|
289
|
+
* const data = Bytes.fromNumber(420, { size: 4 })
|
|
290
|
+
* // @log: Uint8Array([0, 0, 1, 164])
|
|
291
|
+
* ```
|
|
292
|
+
*
|
|
293
|
+
* @param value - Number value to encode.
|
|
294
|
+
* @param options - Encoding options.
|
|
295
|
+
* @returns Encoded {@link ox#Bytes.Bytes}.
|
|
296
|
+
*/
|
|
297
|
+
export function fromNumber(
|
|
298
|
+
value: bigint | number,
|
|
299
|
+
options?: fromNumber.Options | undefined,
|
|
300
|
+
) {
|
|
301
|
+
const hex = Hex.fromNumber(value, options)
|
|
302
|
+
return fromHex(hex)
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
export declare namespace fromNumber {
|
|
306
|
+
export type Options = Hex.fromNumber.Options
|
|
307
|
+
|
|
308
|
+
export type ErrorType =
|
|
309
|
+
| Hex.fromNumber.ErrorType
|
|
310
|
+
| fromHex.ErrorType
|
|
311
|
+
| Errors.GlobalErrorType
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
fromNumber.parseError = (error: unknown) =>
|
|
315
|
+
/* v8 ignore next */
|
|
316
|
+
error as fromNumber.ErrorType
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Encodes a string into {@link ox#Bytes.Bytes}.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts twoslash
|
|
323
|
+
* import { Bytes } from 'ox'
|
|
324
|
+
*
|
|
325
|
+
* const data = Bytes.fromString('Hello world!')
|
|
326
|
+
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33])
|
|
327
|
+
* ```
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```ts twoslash
|
|
331
|
+
* import { Bytes } from 'ox'
|
|
332
|
+
*
|
|
333
|
+
* const data = Bytes.fromString('Hello world!', { size: 32 })
|
|
334
|
+
* // @log: Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
|
|
335
|
+
* ```
|
|
336
|
+
*
|
|
337
|
+
* @param value - String to encode.
|
|
338
|
+
* @param options - Encoding options.
|
|
339
|
+
* @returns Encoded {@link ox#Bytes.Bytes}.
|
|
340
|
+
*/
|
|
341
|
+
export function fromString(
|
|
342
|
+
value: string,
|
|
343
|
+
options: fromString.Options = {},
|
|
344
|
+
): Bytes {
|
|
345
|
+
const { size } = options
|
|
346
|
+
|
|
347
|
+
const bytes = encoder.encode(value)
|
|
348
|
+
if (typeof size === 'number') {
|
|
349
|
+
internal.assertSize(bytes, size)
|
|
350
|
+
return padRight(bytes, size)
|
|
351
|
+
}
|
|
352
|
+
return bytes
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export declare namespace fromString {
|
|
356
|
+
type Options = {
|
|
357
|
+
/** Size of the output bytes. */
|
|
358
|
+
size?: number | undefined
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
type ErrorType =
|
|
362
|
+
| internal.assertSize.ErrorType
|
|
363
|
+
| padRight.ErrorType
|
|
364
|
+
| Errors.GlobalErrorType
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
fromString.parseError = (error: unknown) =>
|
|
368
|
+
/* v8 ignore next */
|
|
369
|
+
error as fromString.ErrorType
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Checks if two {@link ox#Bytes.Bytes} values are equal.
|
|
373
|
+
*
|
|
374
|
+
* @example
|
|
375
|
+
* ```ts twoslash
|
|
376
|
+
* import { Bytes } from 'ox'
|
|
377
|
+
*
|
|
378
|
+
* Bytes.isEqual(Bytes.from([1]), Bytes.from([1]))
|
|
379
|
+
* // @log: true
|
|
380
|
+
*
|
|
381
|
+
* Bytes.isEqual(Bytes.from([1]), Bytes.from([2]))
|
|
382
|
+
* // @log: false
|
|
383
|
+
* ```
|
|
384
|
+
*
|
|
385
|
+
* @param bytesA - First {@link ox#Bytes.Bytes} value.
|
|
386
|
+
* @param bytesB - Second {@link ox#Bytes.Bytes} value.
|
|
387
|
+
* @returns `true` if the two values are equal, otherwise `false`.
|
|
388
|
+
*/
|
|
389
|
+
export function isEqual(bytesA: Bytes, bytesB: Bytes) {
|
|
390
|
+
return equalBytes(bytesA, bytesB)
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
export declare namespace isEqual {
|
|
394
|
+
type ErrorType = Errors.GlobalErrorType
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/* v8 ignore next */
|
|
398
|
+
isEqual.parseError = (error: unknown) => error as isEqual.ErrorType
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Pads a {@link ox#Bytes.Bytes} value to the left with zero bytes until it reaches the given `size` (default: 32 bytes).
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```ts twoslash
|
|
405
|
+
* import { Bytes } from 'ox'
|
|
406
|
+
*
|
|
407
|
+
* Bytes.padLeft(Bytes.from([1]), 4)
|
|
408
|
+
* // @log: Uint8Array([0, 0, 0, 1])
|
|
409
|
+
* ```
|
|
410
|
+
*
|
|
411
|
+
* @param value - {@link ox#Bytes.Bytes} value to pad.
|
|
412
|
+
* @param size - Size to pad the {@link ox#Bytes.Bytes} value to.
|
|
413
|
+
* @returns Padded {@link ox#Bytes.Bytes} value.
|
|
414
|
+
*/
|
|
415
|
+
export function padLeft(
|
|
416
|
+
value: Bytes,
|
|
417
|
+
size?: number | undefined,
|
|
418
|
+
): padLeft.ReturnType {
|
|
419
|
+
return internal.pad(value, { dir: 'left', size })
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
export declare namespace padLeft {
|
|
423
|
+
type ReturnType = internal.pad.ReturnType
|
|
424
|
+
type ErrorType = internal.pad.ErrorType | Errors.GlobalErrorType
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/* v8 ignore next */
|
|
428
|
+
padLeft.parseError = (error: unknown) => error as padLeft.ErrorType
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
* Pads a {@link ox#Bytes.Bytes} value to the right with zero bytes until it reaches the given `size` (default: 32 bytes).
|
|
432
|
+
*
|
|
433
|
+
* @example
|
|
434
|
+
* ```ts twoslash
|
|
435
|
+
* import { Bytes } from 'ox'
|
|
436
|
+
*
|
|
437
|
+
* Bytes.padRight(Bytes.from([1]), 4)
|
|
438
|
+
* // @log: Uint8Array([1, 0, 0, 0])
|
|
439
|
+
* ```
|
|
440
|
+
*
|
|
441
|
+
* @param value - {@link ox#Bytes.Bytes} value to pad.
|
|
442
|
+
* @param size - Size to pad the {@link ox#Bytes.Bytes} value to.
|
|
443
|
+
* @returns Padded {@link ox#Bytes.Bytes} value.
|
|
444
|
+
*/
|
|
445
|
+
export function padRight(
|
|
446
|
+
value: Bytes,
|
|
447
|
+
size?: number | undefined,
|
|
448
|
+
): padRight.ReturnType {
|
|
449
|
+
return internal.pad(value, { dir: 'right', size })
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
export declare namespace padRight {
|
|
453
|
+
type ReturnType = internal.pad.ReturnType
|
|
454
|
+
type ErrorType = internal.pad.ErrorType | Errors.GlobalErrorType
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/* v8 ignore next */
|
|
458
|
+
padRight.parseError = (error: unknown) => error as padRight.ErrorType
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Generates random {@link ox#Bytes.Bytes} of the specified length.
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* ```ts twoslash
|
|
465
|
+
* import { Bytes } from 'ox'
|
|
466
|
+
*
|
|
467
|
+
* const bytes = Bytes.random(32)
|
|
468
|
+
* // @log: Uint8Array([... x32])
|
|
469
|
+
* ```
|
|
470
|
+
*
|
|
471
|
+
* @param length - Length of the random {@link ox#Bytes.Bytes} to generate.
|
|
472
|
+
* @returns Random {@link ox#Bytes.Bytes} of the specified length.
|
|
473
|
+
*/
|
|
474
|
+
export function random(length: number): Bytes {
|
|
475
|
+
return crypto.getRandomValues(new Uint8Array(length))
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
export declare namespace random {
|
|
479
|
+
type ErrorType = Errors.GlobalErrorType
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/* v8 ignore next */
|
|
483
|
+
random.parseError = (error: unknown) => error as random.ErrorType
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Retrieves the size of a {@link ox#Bytes.Bytes} value.
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```ts twoslash
|
|
490
|
+
* import { Bytes } from 'ox'
|
|
491
|
+
*
|
|
492
|
+
* Bytes.size(Bytes.from([1, 2, 3, 4]))
|
|
493
|
+
* // @log: 4
|
|
494
|
+
* ```
|
|
495
|
+
*
|
|
496
|
+
* @param value - {@link ox#Bytes.Bytes} value.
|
|
497
|
+
* @returns Size of the {@link ox#Bytes.Bytes} value.
|
|
498
|
+
*/
|
|
499
|
+
export function size(value: Bytes): number {
|
|
500
|
+
return value.length
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
export declare namespace size {
|
|
504
|
+
export type ErrorType = Errors.GlobalErrorType
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
/* v8 ignore next */
|
|
508
|
+
size.parseError = (error: unknown) => error as size.ErrorType
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Returns a section of a {@link ox#Bytes.Bytes} value given a start/end bytes offset.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* ```ts twoslash
|
|
515
|
+
* import { Bytes } from 'ox'
|
|
516
|
+
*
|
|
517
|
+
* Bytes.slice(
|
|
518
|
+
* Bytes.from([1, 2, 3, 4, 5, 6, 7, 8, 9]),
|
|
519
|
+
* 1,
|
|
520
|
+
* 4,
|
|
521
|
+
* )
|
|
522
|
+
* // @log: Uint8Array([2, 3, 4])
|
|
523
|
+
* ```
|
|
524
|
+
*
|
|
525
|
+
* @param value - The {@link ox#Bytes.Bytes} value.
|
|
526
|
+
* @param start - Start offset.
|
|
527
|
+
* @param end - End offset.
|
|
528
|
+
* @param options - Slice options.
|
|
529
|
+
* @returns Sliced {@link ox#Bytes.Bytes} value.
|
|
530
|
+
*/
|
|
531
|
+
export function slice(
|
|
532
|
+
value: Bytes,
|
|
533
|
+
start?: number | undefined,
|
|
534
|
+
end?: number | undefined,
|
|
535
|
+
options: slice.Options = {},
|
|
536
|
+
): Bytes {
|
|
537
|
+
const { strict } = options
|
|
538
|
+
internal.assertStartOffset(value, start)
|
|
539
|
+
const value_ = value.slice(start, end)
|
|
540
|
+
if (strict) internal.assertEndOffset(value_, start, end)
|
|
541
|
+
return value_
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
export declare namespace slice {
|
|
545
|
+
type Options = {
|
|
546
|
+
/** Asserts that the sliced value is the same size as the given start/end offsets. */
|
|
547
|
+
strict?: boolean | undefined
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export type ErrorType =
|
|
551
|
+
| internal.assertStartOffset.ErrorType
|
|
552
|
+
| internal.assertEndOffset.ErrorType
|
|
553
|
+
| Errors.GlobalErrorType
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
/* v8 ignore next */
|
|
557
|
+
slice.parseError = (error: unknown) => error as slice.ErrorType
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Decodes a {@link ox#Bytes.Bytes} into a bigint.
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* ```ts
|
|
564
|
+
* import { Bytes } from 'ox'
|
|
565
|
+
*
|
|
566
|
+
* Bytes.toBigInt(Bytes.from([1, 164]))
|
|
567
|
+
* // @log: 420n
|
|
568
|
+
* ```
|
|
569
|
+
*
|
|
570
|
+
* @param bytes - The {@link ox#Bytes.Bytes} to decode.
|
|
571
|
+
* @param options - Decoding options.
|
|
572
|
+
* @returns Decoded bigint.
|
|
573
|
+
*/
|
|
574
|
+
export function toBigInt(bytes: Bytes, options: toBigInt.Options = {}): bigint {
|
|
575
|
+
const { size } = options
|
|
576
|
+
if (typeof size !== 'undefined') internal.assertSize(bytes, size)
|
|
577
|
+
const hex = Hex.fromBytes(bytes, options)
|
|
578
|
+
return Hex.toBigInt(hex, options)
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
export declare namespace toBigInt {
|
|
582
|
+
type Options = {
|
|
583
|
+
/** Whether or not the number of a signed representation. */
|
|
584
|
+
signed?: boolean | undefined
|
|
585
|
+
/** Size of the bytes. */
|
|
586
|
+
size?: number | undefined
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
type ErrorType =
|
|
590
|
+
| Hex.fromBytes.ErrorType
|
|
591
|
+
| Hex.toBigInt.ErrorType
|
|
592
|
+
| Errors.GlobalErrorType
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
toBigInt.parseError = (error: unknown) =>
|
|
596
|
+
/* v8 ignore next */
|
|
597
|
+
error as toBigInt.ErrorType
|
|
598
|
+
|
|
599
|
+
/**
|
|
600
|
+
* Decodes a {@link ox#Bytes.Bytes} into a boolean.
|
|
601
|
+
*
|
|
602
|
+
* @example
|
|
603
|
+
* ```ts
|
|
604
|
+
* import { Bytes } from 'ox'
|
|
605
|
+
*
|
|
606
|
+
* Bytes.toBoolean(Bytes.from([1]))
|
|
607
|
+
* // @log: true
|
|
608
|
+
* ```
|
|
609
|
+
*
|
|
610
|
+
* @param bytes - The {@link ox#Bytes.Bytes} to decode.
|
|
611
|
+
* @param options - Decoding options.
|
|
612
|
+
* @returns Decoded boolean.
|
|
613
|
+
*/
|
|
614
|
+
export function toBoolean(
|
|
615
|
+
bytes: Bytes,
|
|
616
|
+
options: toBoolean.Options = {},
|
|
617
|
+
): boolean {
|
|
618
|
+
const { size } = options
|
|
619
|
+
let bytes_ = bytes
|
|
620
|
+
if (typeof size !== 'undefined') {
|
|
621
|
+
internal.assertSize(bytes_, size)
|
|
622
|
+
bytes_ = trimLeft(bytes_)
|
|
623
|
+
}
|
|
624
|
+
if (bytes_.length > 1 || bytes_[0]! > 1)
|
|
625
|
+
throw new InvalidBytesBooleanError(bytes_)
|
|
626
|
+
return Boolean(bytes_[0])
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
export declare namespace toBoolean {
|
|
630
|
+
type Options = {
|
|
631
|
+
/** Size of the bytes. */
|
|
632
|
+
size?: number | undefined
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
type ErrorType =
|
|
636
|
+
| internal.assertSize.ErrorType
|
|
637
|
+
| trimLeft.ErrorType
|
|
638
|
+
| Errors.GlobalErrorType
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
toBoolean.parseError = (error: unknown) =>
|
|
642
|
+
/* v8 ignore next */
|
|
643
|
+
error as toBoolean.ErrorType
|
|
644
|
+
|
|
645
|
+
/**
|
|
646
|
+
* Encodes a {@link ox#Bytes.Bytes} value into a {@link ox#Hex.Hex} value.
|
|
647
|
+
*
|
|
648
|
+
* @example
|
|
649
|
+
* ```ts twoslash
|
|
650
|
+
* import { Bytes } from 'ox'
|
|
651
|
+
*
|
|
652
|
+
* Bytes.toHex(Bytes.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]))
|
|
653
|
+
* // '0x48656c6c6f20576f726c6421'
|
|
654
|
+
* ```
|
|
655
|
+
*
|
|
656
|
+
* @param value - The {@link ox#Bytes.Bytes} to decode.
|
|
657
|
+
* @param options - Options.
|
|
658
|
+
* @returns Decoded {@link ox#Hex.Hex} value.
|
|
659
|
+
*/
|
|
660
|
+
export function toHex(value: Bytes, options: toHex.Options = {}): Hex.Hex {
|
|
661
|
+
return Hex.fromBytes(value, options)
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
export declare namespace toHex {
|
|
665
|
+
type Options = {
|
|
666
|
+
/** Size of the bytes. */
|
|
667
|
+
size?: number | undefined
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
type ErrorType = Hex.fromBytes.ErrorType | Errors.GlobalErrorType
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/* v8 ignore next */
|
|
674
|
+
toHex.parseError = (error: unknown) => error as toHex.ErrorType
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Decodes a {@link ox#Bytes.Bytes} into a number.
|
|
678
|
+
*
|
|
679
|
+
* @example
|
|
680
|
+
* ```ts twoslash
|
|
681
|
+
* import { Bytes } from 'ox'
|
|
682
|
+
*
|
|
683
|
+
* Bytes.toNumber(Bytes.from([1, 164]))
|
|
684
|
+
* // @log: 420
|
|
685
|
+
* ```
|
|
686
|
+
*/
|
|
687
|
+
export function toNumber(bytes: Bytes, options: toNumber.Options = {}): number {
|
|
688
|
+
const { size } = options
|
|
689
|
+
if (typeof size !== 'undefined') internal.assertSize(bytes, size)
|
|
690
|
+
const hex = Hex.fromBytes(bytes, options)
|
|
691
|
+
return Hex.toNumber(hex, options)
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
export declare namespace toNumber {
|
|
695
|
+
type Options = {
|
|
696
|
+
/** Whether or not the number of a signed representation. */
|
|
697
|
+
signed?: boolean | undefined
|
|
698
|
+
/** Size of the bytes. */
|
|
699
|
+
size?: number | undefined
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
type ErrorType =
|
|
703
|
+
| Hex.fromBytes.ErrorType
|
|
704
|
+
| Hex.toNumber.ErrorType
|
|
705
|
+
| Errors.GlobalErrorType
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
toNumber.parseError = (error: unknown) =>
|
|
709
|
+
/* v8 ignore next */
|
|
710
|
+
error as toNumber.ErrorType
|
|
711
|
+
|
|
712
|
+
/**
|
|
713
|
+
* Decodes a {@link ox#Bytes.Bytes} into a string.
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* ```ts twoslash
|
|
717
|
+
* import { Bytes } from 'ox'
|
|
718
|
+
*
|
|
719
|
+
* const data = Bytes.toString(Bytes.from([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]))
|
|
720
|
+
* // @log: 'Hello world'
|
|
721
|
+
* ```
|
|
722
|
+
*
|
|
723
|
+
* @param bytes - The {@link ox#Bytes.Bytes} to decode.
|
|
724
|
+
* @param options - Options.
|
|
725
|
+
* @returns Decoded string.
|
|
726
|
+
*/
|
|
727
|
+
export function toString(bytes: Bytes, options: toString.Options = {}): string {
|
|
728
|
+
const { size } = options
|
|
729
|
+
|
|
730
|
+
let bytes_ = bytes
|
|
731
|
+
if (typeof size !== 'undefined') {
|
|
732
|
+
internal.assertSize(bytes_, size)
|
|
733
|
+
bytes_ = trimRight(bytes_)
|
|
734
|
+
}
|
|
735
|
+
return decoder.decode(bytes_)
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
export declare namespace toString {
|
|
739
|
+
export type Options = {
|
|
740
|
+
/** Size of the bytes. */
|
|
741
|
+
size?: number | undefined
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
export type ErrorType =
|
|
745
|
+
| internal.assertSize.ErrorType
|
|
746
|
+
| trimRight.ErrorType
|
|
747
|
+
| Errors.GlobalErrorType
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
toString.parseError = (error: unknown) =>
|
|
751
|
+
/* v8 ignore next */
|
|
752
|
+
error as toString.ErrorType
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* Trims leading zeros from a {@link ox#Bytes.Bytes} value.
|
|
756
|
+
*
|
|
757
|
+
* @example
|
|
758
|
+
* ```ts twoslash
|
|
759
|
+
* import { Bytes } from 'ox'
|
|
760
|
+
*
|
|
761
|
+
* Bytes.trimLeft(Bytes.from([0, 0, 0, 0, 1, 2, 3]))
|
|
762
|
+
* // @log: Uint8Array([1, 2, 3])
|
|
763
|
+
* ```
|
|
764
|
+
*
|
|
765
|
+
* @param value - {@link ox#Bytes.Bytes} value.
|
|
766
|
+
* @returns Trimmed {@link ox#Bytes.Bytes} value.
|
|
767
|
+
*/
|
|
768
|
+
export function trimLeft(value: Bytes): Bytes {
|
|
769
|
+
return internal.trim(value, { dir: 'left' })
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
export declare namespace trimLeft {
|
|
773
|
+
type ErrorType = internal.trim.ErrorType | Errors.GlobalErrorType
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/* v8 ignore next */
|
|
777
|
+
trimLeft.parseError = (error: unknown) => error as trimLeft.ErrorType
|
|
778
|
+
|
|
779
|
+
/**
|
|
780
|
+
* Trims trailing zeros from a {@link ox#Bytes.Bytes} value.
|
|
781
|
+
*
|
|
782
|
+
* @example
|
|
783
|
+
* ```ts twoslash
|
|
784
|
+
* import { Bytes } from 'ox'
|
|
785
|
+
*
|
|
786
|
+
* Bytes.trimRight(Bytes.from([1, 2, 3, 0, 0, 0, 0]))
|
|
787
|
+
* // @log: Uint8Array([1, 2, 3])
|
|
788
|
+
* ```
|
|
789
|
+
*
|
|
790
|
+
* @param value - {@link ox#Bytes.Bytes} value.
|
|
791
|
+
* @returns Trimmed {@link ox#Bytes.Bytes} value.
|
|
792
|
+
*/
|
|
793
|
+
export function trimRight(value: Bytes): Bytes {
|
|
794
|
+
return internal.trim(value, { dir: 'right' })
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
export declare namespace trimRight {
|
|
798
|
+
export type ErrorType = internal.trim.ErrorType | Errors.GlobalErrorType
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/* v8 ignore next */
|
|
802
|
+
trimRight.parseError = (error: unknown) => error as trimRight.ErrorType
|
|
803
|
+
|
|
804
|
+
/**
|
|
805
|
+
* Checks if the given value is {@link ox#Bytes.Bytes}.
|
|
806
|
+
*
|
|
807
|
+
* @example
|
|
808
|
+
* ```ts twoslash
|
|
809
|
+
* import { Bytes } from 'ox'
|
|
810
|
+
*
|
|
811
|
+
* Bytes.validate('0x')
|
|
812
|
+
* // @log: false
|
|
813
|
+
*
|
|
814
|
+
* Bytes.validate(Bytes.from([1, 2, 3]))
|
|
815
|
+
* // @log: true
|
|
816
|
+
* ```
|
|
817
|
+
*
|
|
818
|
+
* @param value - Value to check.
|
|
819
|
+
* @returns `true` if the value is {@link ox#Bytes.Bytes}, otherwise `false`.
|
|
820
|
+
*/
|
|
821
|
+
export function validate(value: unknown): value is Bytes {
|
|
822
|
+
try {
|
|
823
|
+
assert(value)
|
|
824
|
+
return true
|
|
825
|
+
} catch {
|
|
826
|
+
return false
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
export declare namespace validate {
|
|
831
|
+
export type ErrorType = Errors.GlobalErrorType
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
/* v8 ignore next */
|
|
835
|
+
validate.parseError = (error: unknown) => error as validate.ErrorType
|
|
836
|
+
|
|
837
|
+
/**
|
|
838
|
+
* Thrown when the bytes value cannot be represented as a boolean.
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```ts twoslash
|
|
842
|
+
* import { Bytes } from 'ox'
|
|
843
|
+
*
|
|
844
|
+
* Bytes.toBoolean(Bytes.from([5]))
|
|
845
|
+
* // @error: Bytes.InvalidBytesBooleanError: Bytes value `[5]` is not a valid boolean.
|
|
846
|
+
* // @error: The bytes array must contain a single byte of either a `0` or `1` value.
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
export class InvalidBytesBooleanError extends Errors.BaseError {
|
|
850
|
+
override readonly name = 'Bytes.InvalidBytesBooleanError'
|
|
851
|
+
|
|
852
|
+
constructor(bytes: Bytes) {
|
|
853
|
+
super(`Bytes value \`${bytes}\` is not a valid boolean.`, {
|
|
854
|
+
metaMessages: [
|
|
855
|
+
'The bytes array must contain a single byte of either a `0` or `1` value.',
|
|
856
|
+
],
|
|
857
|
+
})
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
/**
|
|
862
|
+
* Thrown when a value cannot be converted to bytes.
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts twoslash
|
|
866
|
+
* // @noErrors
|
|
867
|
+
* import { Bytes } from 'ox'
|
|
868
|
+
*
|
|
869
|
+
* Bytes.from('foo')
|
|
870
|
+
* // @error: Bytes.InvalidBytesTypeError: Value `foo` of type `string` is an invalid Bytes value.
|
|
871
|
+
* ```
|
|
872
|
+
*/
|
|
873
|
+
export class InvalidBytesTypeError extends Errors.BaseError {
|
|
874
|
+
override readonly name = 'Bytes.InvalidBytesTypeError'
|
|
875
|
+
|
|
876
|
+
constructor(value: unknown) {
|
|
877
|
+
super(
|
|
878
|
+
`Value \`${typeof value === 'object' ? Json.stringify(value) : value}\` of type \`${typeof value}\` is an invalid Bytes value.`,
|
|
879
|
+
{
|
|
880
|
+
metaMessages: ['Bytes values must be of type `Bytes`.'],
|
|
881
|
+
},
|
|
882
|
+
)
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
|
|
886
|
+
/**
|
|
887
|
+
* Thrown when a size exceeds the maximum allowed size.
|
|
888
|
+
*
|
|
889
|
+
* @example
|
|
890
|
+
* ```ts twoslash
|
|
891
|
+
* import { Bytes } from 'ox'
|
|
892
|
+
*
|
|
893
|
+
* Bytes.fromString('Hello World!', { size: 8 })
|
|
894
|
+
* // @error: Bytes.SizeOverflowError: Size cannot exceed `8` bytes. Given size: `12` bytes.
|
|
895
|
+
* ```
|
|
896
|
+
*/
|
|
897
|
+
export class SizeOverflowError extends Errors.BaseError {
|
|
898
|
+
override readonly name = 'Bytes.SizeOverflowError'
|
|
899
|
+
|
|
900
|
+
constructor({ givenSize, maxSize }: { givenSize: number; maxSize: number }) {
|
|
901
|
+
super(
|
|
902
|
+
`Size cannot exceed \`${maxSize}\` bytes. Given size: \`${givenSize}\` bytes.`,
|
|
903
|
+
)
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
|
|
907
|
+
/**
|
|
908
|
+
* Thrown when a slice offset is out-of-bounds.
|
|
909
|
+
*
|
|
910
|
+
* @example
|
|
911
|
+
* ```ts twoslash
|
|
912
|
+
* import { Bytes } from 'ox'
|
|
913
|
+
*
|
|
914
|
+
* Bytes.slice(Bytes.from([1, 2, 3]), 4)
|
|
915
|
+
* // @error: Bytes.SliceOffsetOutOfBoundsError: Slice starting at offset `4` is out-of-bounds (size: `3`).
|
|
916
|
+
* ```
|
|
917
|
+
*/
|
|
918
|
+
export class SliceOffsetOutOfBoundsError extends Errors.BaseError {
|
|
919
|
+
override readonly name = 'Bytes.SliceOffsetOutOfBoundsError'
|
|
920
|
+
|
|
921
|
+
constructor({
|
|
922
|
+
offset,
|
|
923
|
+
position,
|
|
924
|
+
size,
|
|
925
|
+
}: { offset: number; position: 'start' | 'end'; size: number }) {
|
|
926
|
+
super(
|
|
927
|
+
`Slice ${
|
|
928
|
+
position === 'start' ? 'starting' : 'ending'
|
|
929
|
+
} at offset \`${offset}\` is out-of-bounds (size: \`${size}\`).`,
|
|
930
|
+
)
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
/**
|
|
935
|
+
* Thrown when a the padding size exceeds the maximum allowed size.
|
|
936
|
+
*
|
|
937
|
+
* @example
|
|
938
|
+
* ```ts twoslash
|
|
939
|
+
* import { Bytes } from 'ox'
|
|
940
|
+
*
|
|
941
|
+
* Bytes.padLeft(Bytes.fromString('Hello World!'), 8)
|
|
942
|
+
* // @error: [Bytes.SizeExceedsPaddingSizeError: Bytes size (`12`) exceeds padding size (`8`).
|
|
943
|
+
* ```
|
|
944
|
+
*/
|
|
945
|
+
export class SizeExceedsPaddingSizeError extends Errors.BaseError {
|
|
946
|
+
override readonly name = 'Bytes.SizeExceedsPaddingSizeError'
|
|
947
|
+
|
|
948
|
+
constructor({
|
|
949
|
+
size,
|
|
950
|
+
targetSize,
|
|
951
|
+
type,
|
|
952
|
+
}: {
|
|
953
|
+
size: number
|
|
954
|
+
targetSize: number
|
|
955
|
+
type: 'Hex' | 'Bytes'
|
|
956
|
+
}) {
|
|
957
|
+
super(
|
|
958
|
+
`${type.charAt(0).toUpperCase()}${type
|
|
959
|
+
.slice(1)
|
|
960
|
+
.toLowerCase()} size (\`${size}\`) exceeds padding size (\`${targetSize}\`).`,
|
|
961
|
+
)
|
|
962
|
+
}
|
|
963
|
+
}
|