@sravankumar02/sdk-core 1.0.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/LICENSE +11 -0
- package/README.md +94 -0
- package/out/abi/argSerializer.d.ts +45 -0
- package/out/abi/argSerializer.js +171 -0
- package/out/abi/argSerializer.js.map +1 -0
- package/out/abi/argumentErrorContext.d.ts +12 -0
- package/out/abi/argumentErrorContext.js +34 -0
- package/out/abi/argumentErrorContext.js.map +1 -0
- package/out/abi/code.d.ts +23 -0
- package/out/abi/code.js +41 -0
- package/out/abi/code.js.map +1 -0
- package/out/abi/codec/address.d.ts +24 -0
- package/out/abi/codec/address.js +41 -0
- package/out/abi/codec/address.js.map +1 -0
- package/out/abi/codec/arrayVec.d.ts +11 -0
- package/out/abi/codec/arrayVec.js +39 -0
- package/out/abi/codec/arrayVec.js.map +1 -0
- package/out/abi/codec/binary.d.ts +30 -0
- package/out/abi/codec/binary.js +134 -0
- package/out/abi/codec/binary.js.map +1 -0
- package/out/abi/codec/binaryCodecUtils.d.ts +6 -0
- package/out/abi/codec/binaryCodecUtils.js +35 -0
- package/out/abi/codec/binaryCodecUtils.js.map +1 -0
- package/out/abi/codec/boolean.d.ts +13 -0
- package/out/abi/codec/boolean.js +57 -0
- package/out/abi/codec/boolean.js.map +1 -0
- package/out/abi/codec/bytes.d.ts +11 -0
- package/out/abi/codec/bytes.js +30 -0
- package/out/abi/codec/bytes.js.map +1 -0
- package/out/abi/codec/codemetadata.d.ts +8 -0
- package/out/abi/codec/codemetadata.js +23 -0
- package/out/abi/codec/codemetadata.js.map +1 -0
- package/out/abi/codec/constants.d.ts +1 -0
- package/out/abi/codec/constants.js +5 -0
- package/out/abi/codec/constants.js.map +1 -0
- package/out/abi/codec/enum.d.ts +13 -0
- package/out/abi/codec/enum.js +49 -0
- package/out/abi/codec/enum.js.map +1 -0
- package/out/abi/codec/explicit-enum.d.ts +10 -0
- package/out/abi/codec/explicit-enum.js +30 -0
- package/out/abi/codec/explicit-enum.js.map +1 -0
- package/out/abi/codec/fields.d.ts +9 -0
- package/out/abi/codec/fields.js +31 -0
- package/out/abi/codec/fields.js.map +1 -0
- package/out/abi/codec/h256.d.ts +24 -0
- package/out/abi/codec/h256.js +39 -0
- package/out/abi/codec/h256.js.map +1 -0
- package/out/abi/codec/index.d.ts +6 -0
- package/out/abi/codec/index.js +19 -0
- package/out/abi/codec/index.js.map +1 -0
- package/out/abi/codec/list.d.ts +14 -0
- package/out/abi/codec/list.js +67 -0
- package/out/abi/codec/list.js.map +1 -0
- package/out/abi/codec/managedDecimal.d.ts +11 -0
- package/out/abi/codec/managedDecimal.js +53 -0
- package/out/abi/codec/managedDecimal.js.map +1 -0
- package/out/abi/codec/managedDecimalSigned.d.ts +11 -0
- package/out/abi/codec/managedDecimalSigned.js +53 -0
- package/out/abi/codec/managedDecimalSigned.js.map +1 -0
- package/out/abi/codec/nothing.d.ts +8 -0
- package/out/abi/codec/nothing.js +20 -0
- package/out/abi/codec/nothing.js.map +1 -0
- package/out/abi/codec/numerical.d.ts +13 -0
- package/out/abi/codec/numerical.js +122 -0
- package/out/abi/codec/numerical.js.map +1 -0
- package/out/abi/codec/option.d.ts +14 -0
- package/out/abi/codec/option.js +66 -0
- package/out/abi/codec/option.js.map +1 -0
- package/out/abi/codec/primitive.d.ts +20 -0
- package/out/abi/codec/primitive.js +81 -0
- package/out/abi/codec/primitive.js.map +1 -0
- package/out/abi/codec/string.d.ts +9 -0
- package/out/abi/codec/string.js +28 -0
- package/out/abi/codec/string.js.map +1 -0
- package/out/abi/codec/struct.d.ts +11 -0
- package/out/abi/codec/struct.js +30 -0
- package/out/abi/codec/struct.js.map +1 -0
- package/out/abi/codec/tokenIdentifier.d.ts +9 -0
- package/out/abi/codec/tokenIdentifier.js +28 -0
- package/out/abi/codec/tokenIdentifier.js.map +1 -0
- package/out/abi/codec/tuple.d.ts +11 -0
- package/out/abi/codec/tuple.js +23 -0
- package/out/abi/codec/tuple.js.map +1 -0
- package/out/abi/codec/utils.d.ts +20 -0
- package/out/abi/codec/utils.js +69 -0
- package/out/abi/codec/utils.js.map +1 -0
- package/out/abi/function.d.ts +24 -0
- package/out/abi/function.js +56 -0
- package/out/abi/function.js.map +1 -0
- package/out/abi/index.d.ts +12 -0
- package/out/abi/index.js +25 -0
- package/out/abi/index.js.map +1 -0
- package/out/abi/interaction.d.ts +67 -0
- package/out/abi/interaction.js +146 -0
- package/out/abi/interaction.js.map +1 -0
- package/out/abi/interface.d.ts +85 -0
- package/out/abi/interface.js +3 -0
- package/out/abi/interface.js.map +1 -0
- package/out/abi/nativeSerializer.d.ts +27 -0
- package/out/abi/nativeSerializer.js +343 -0
- package/out/abi/nativeSerializer.js.map +1 -0
- package/out/abi/query.d.ts +18 -0
- package/out/abi/query.js +19 -0
- package/out/abi/query.js.map +1 -0
- package/out/abi/returnCode.d.ts +26 -0
- package/out/abi/returnCode.js +45 -0
- package/out/abi/returnCode.js.map +1 -0
- package/out/abi/smartContract.d.ts +74 -0
- package/out/abi/smartContract.js +208 -0
- package/out/abi/smartContract.js.map +1 -0
- package/out/abi/typeFormula.d.ts +7 -0
- package/out/abi/typeFormula.js +20 -0
- package/out/abi/typeFormula.js.map +1 -0
- package/out/abi/typeFormulaParser.d.ts +14 -0
- package/out/abi/typeFormulaParser.js +126 -0
- package/out/abi/typeFormulaParser.js.map +1 -0
- package/out/abi/typesystem/abi.d.ts +64 -0
- package/out/abi/typesystem/abi.js +208 -0
- package/out/abi/typesystem/abi.js.map +1 -0
- package/out/abi/typesystem/address.d.ts +23 -0
- package/out/abi/typesystem/address.js +41 -0
- package/out/abi/typesystem/address.js.map +1 -0
- package/out/abi/typesystem/algebraic.d.ts +24 -0
- package/out/abi/typesystem/algebraic.js +59 -0
- package/out/abi/typesystem/algebraic.js.map +1 -0
- package/out/abi/typesystem/boolean.d.ts +24 -0
- package/out/abi/typesystem/boolean.js +46 -0
- package/out/abi/typesystem/boolean.js.map +1 -0
- package/out/abi/typesystem/bytes.d.ts +28 -0
- package/out/abi/typesystem/bytes.js +58 -0
- package/out/abi/typesystem/bytes.js.map +1 -0
- package/out/abi/typesystem/codeMetadata.d.ts +11 -0
- package/out/abi/typesystem/codeMetadata.js +24 -0
- package/out/abi/typesystem/codeMetadata.js.map +1 -0
- package/out/abi/typesystem/collections.d.ts +9 -0
- package/out/abi/typesystem/collections.js +32 -0
- package/out/abi/typesystem/collections.js.map +1 -0
- package/out/abi/typesystem/composite.d.ts +16 -0
- package/out/abi/typesystem/composite.js +53 -0
- package/out/abi/typesystem/composite.js.map +1 -0
- package/out/abi/typesystem/endpoint.d.ts +41 -0
- package/out/abi/typesystem/endpoint.js +78 -0
- package/out/abi/typesystem/endpoint.js.map +1 -0
- package/out/abi/typesystem/enum.d.ts +51 -0
- package/out/abi/typesystem/enum.js +137 -0
- package/out/abi/typesystem/enum.js.map +1 -0
- package/out/abi/typesystem/event.d.ts +25 -0
- package/out/abi/typesystem/event.js +36 -0
- package/out/abi/typesystem/event.js.map +1 -0
- package/out/abi/typesystem/explicit-enum.d.ts +33 -0
- package/out/abi/typesystem/explicit-enum.js +63 -0
- package/out/abi/typesystem/explicit-enum.js.map +1 -0
- package/out/abi/typesystem/factory.d.ts +4 -0
- package/out/abi/typesystem/factory.js +19 -0
- package/out/abi/typesystem/factory.js.map +1 -0
- package/out/abi/typesystem/fields.d.ts +24 -0
- package/out/abi/typesystem/fields.js +90 -0
- package/out/abi/typesystem/fields.js.map +1 -0
- package/out/abi/typesystem/generic.d.ts +47 -0
- package/out/abi/typesystem/generic.js +120 -0
- package/out/abi/typesystem/generic.js.map +1 -0
- package/out/abi/typesystem/genericArray.d.ts +17 -0
- package/out/abi/typesystem/genericArray.js +44 -0
- package/out/abi/typesystem/genericArray.js.map +1 -0
- package/out/abi/typesystem/h256.d.ts +18 -0
- package/out/abi/typesystem/h256.js +35 -0
- package/out/abi/typesystem/h256.js.map +1 -0
- package/out/abi/typesystem/index.d.ts +33 -0
- package/out/abi/typesystem/index.js +46 -0
- package/out/abi/typesystem/index.js.map +1 -0
- package/out/abi/typesystem/managedDecimal.d.ts +26 -0
- package/out/abi/typesystem/managedDecimal.js +62 -0
- package/out/abi/typesystem/managedDecimal.js.map +1 -0
- package/out/abi/typesystem/managedDecimalSigned.d.ts +26 -0
- package/out/abi/typesystem/managedDecimalSigned.js +62 -0
- package/out/abi/typesystem/managedDecimalSigned.js.map +1 -0
- package/out/abi/typesystem/matchers.d.ts +51 -0
- package/out/abi/typesystem/matchers.js +185 -0
- package/out/abi/typesystem/matchers.js.map +1 -0
- package/out/abi/typesystem/nothing.d.ts +13 -0
- package/out/abi/typesystem/nothing.js +31 -0
- package/out/abi/typesystem/nothing.js.map +1 -0
- package/out/abi/typesystem/numerical.d.ts +130 -0
- package/out/abi/typesystem/numerical.js +286 -0
- package/out/abi/typesystem/numerical.js.map +1 -0
- package/out/abi/typesystem/string.d.ts +26 -0
- package/out/abi/typesystem/string.js +51 -0
- package/out/abi/typesystem/string.js.map +1 -0
- package/out/abi/typesystem/struct.d.ts +30 -0
- package/out/abi/typesystem/struct.js +78 -0
- package/out/abi/typesystem/struct.js.map +1 -0
- package/out/abi/typesystem/tokenIdentifier.d.ts +21 -0
- package/out/abi/typesystem/tokenIdentifier.js +51 -0
- package/out/abi/typesystem/tokenIdentifier.js.map +1 -0
- package/out/abi/typesystem/tuple.d.ts +16 -0
- package/out/abi/typesystem/tuple.js +71 -0
- package/out/abi/typesystem/tuple.js.map +1 -0
- package/out/abi/typesystem/typeExpressionParser.d.ts +8 -0
- package/out/abi/typesystem/typeExpressionParser.js +30 -0
- package/out/abi/typesystem/typeExpressionParser.js.map +1 -0
- package/out/abi/typesystem/typeMapper.d.ts +20 -0
- package/out/abi/typesystem/typeMapper.js +215 -0
- package/out/abi/typesystem/typeMapper.js.map +1 -0
- package/out/abi/typesystem/types.d.ts +129 -0
- package/out/abi/typesystem/types.js +285 -0
- package/out/abi/typesystem/types.js.map +1 -0
- package/out/abi/typesystem/variadic.d.ts +35 -0
- package/out/abi/typesystem/variadic.js +81 -0
- package/out/abi/typesystem/variadic.js.map +1 -0
- package/out/accountManagement/accountController.d.ts +18 -0
- package/out/accountManagement/accountController.js +54 -0
- package/out/accountManagement/accountController.js.map +1 -0
- package/out/accountManagement/accountTransactionsFactory.d.ts +27 -0
- package/out/accountManagement/accountTransactionsFactory.js +78 -0
- package/out/accountManagement/accountTransactionsFactory.js.map +1 -0
- package/out/accountManagement/index.d.ts +3 -0
- package/out/accountManagement/index.js +16 -0
- package/out/accountManagement/index.js.map +1 -0
- package/out/accountManagement/resources.d.ts +8 -0
- package/out/accountManagement/resources.js +3 -0
- package/out/accountManagement/resources.js.map +1 -0
- package/out/accounts/account.d.ts +94 -0
- package/out/accounts/account.js +154 -0
- package/out/accounts/account.js.map +1 -0
- package/out/accounts/index.d.ts +1 -0
- package/out/accounts/index.js +14 -0
- package/out/accounts/index.js.map +1 -0
- package/out/core/address.d.ts +105 -0
- package/out/core/address.js +313 -0
- package/out/core/address.js.map +1 -0
- package/out/core/asyncTimer.d.ts +27 -0
- package/out/core/asyncTimer.js +91 -0
- package/out/core/asyncTimer.js.map +1 -0
- package/out/core/baseController.d.ts +16 -0
- package/out/core/baseController.js +34 -0
- package/out/core/baseController.js.map +1 -0
- package/out/core/codeMetadata.d.ts +74 -0
- package/out/core/codeMetadata.js +146 -0
- package/out/core/codeMetadata.js.map +1 -0
- package/out/core/compatibility.d.ts +10 -0
- package/out/core/compatibility.js +22 -0
- package/out/core/compatibility.js.map +1 -0
- package/out/core/config.d.ts +15 -0
- package/out/core/config.js +20 -0
- package/out/core/config.js.map +1 -0
- package/out/core/constants.d.ts +28 -0
- package/out/core/constants.js +32 -0
- package/out/core/constants.js.map +1 -0
- package/out/core/errors.d.ts +279 -0
- package/out/core/errors.js +437 -0
- package/out/core/errors.js.map +1 -0
- package/out/core/globals.d.ts +0 -0
- package/out/core/globals.js +5 -0
- package/out/core/globals.js.map +1 -0
- package/out/core/index.d.ts +21 -0
- package/out/core/index.js +35 -0
- package/out/core/index.js.map +1 -0
- package/out/core/interfaces.d.ts +40 -0
- package/out/core/interfaces.js +3 -0
- package/out/core/interfaces.js.map +1 -0
- package/out/core/logger.d.ts +17 -0
- package/out/core/logger.js +50 -0
- package/out/core/logger.js.map +1 -0
- package/out/core/message.d.ts +57 -0
- package/out/core/message.js +71 -0
- package/out/core/message.js.map +1 -0
- package/out/core/networkParams.d.ts +57 -0
- package/out/core/networkParams.js +112 -0
- package/out/core/networkParams.js.map +1 -0
- package/out/core/reflection.d.ts +1 -0
- package/out/core/reflection.js +14 -0
- package/out/core/reflection.js.map +1 -0
- package/out/core/signature.d.ts +17 -0
- package/out/core/signature.js +82 -0
- package/out/core/signature.js.map +1 -0
- package/out/core/smartContractQuery.d.ts +35 -0
- package/out/core/smartContractQuery.js +34 -0
- package/out/core/smartContractQuery.js.map +1 -0
- package/out/core/tokenTransfersDataBuilder.d.ts +10 -0
- package/out/core/tokenTransfersDataBuilder.js +44 -0
- package/out/core/tokenTransfersDataBuilder.js.map +1 -0
- package/out/core/tokens.d.ts +130 -0
- package/out/core/tokens.js +287 -0
- package/out/core/tokens.js.map +1 -0
- package/out/core/transaction.d.ts +263 -0
- package/out/core/transaction.js +323 -0
- package/out/core/transaction.js.map +1 -0
- package/out/core/transactionBuilder.d.ts +32 -0
- package/out/core/transactionBuilder.js +45 -0
- package/out/core/transactionBuilder.js.map +1 -0
- package/out/core/transactionComputer.d.ts +51 -0
- package/out/core/transactionComputer.js +163 -0
- package/out/core/transactionComputer.js.map +1 -0
- package/out/core/transactionEvents.d.ts +17 -0
- package/out/core/transactionEvents.js +27 -0
- package/out/core/transactionEvents.js.map +1 -0
- package/out/core/transactionLogs.d.ts +11 -0
- package/out/core/transactionLogs.js +38 -0
- package/out/core/transactionLogs.js.map +1 -0
- package/out/core/transactionOnNetwork.d.ts +40 -0
- package/out/core/transactionOnNetwork.js +164 -0
- package/out/core/transactionOnNetwork.js.map +1 -0
- package/out/core/transactionStatus.d.ts +45 -0
- package/out/core/transactionStatus.js +71 -0
- package/out/core/transactionStatus.js.map +1 -0
- package/out/core/transactionWatcher.d.ts +48 -0
- package/out/core/transactionWatcher.js +148 -0
- package/out/core/transactionWatcher.js.map +1 -0
- package/out/core/transactionsFactoryConfig.d.ts +54 -0
- package/out/core/transactionsFactoryConfig.js +66 -0
- package/out/core/transactionsFactoryConfig.js.map +1 -0
- package/out/core/utils.codec.d.ts +8 -0
- package/out/core/utils.codec.js +75 -0
- package/out/core/utils.codec.js.map +1 -0
- package/out/core/utils.d.ts +20 -0
- package/out/core/utils.js +86 -0
- package/out/core/utils.js.map +1 -0
- package/out/delegation/delegationController.d.ts +37 -0
- package/out/delegation/delegationController.js +215 -0
- package/out/delegation/delegationController.js.map +1 -0
- package/out/delegation/delegationTransactionsFactory.d.ts +48 -0
- package/out/delegation/delegationTransactionsFactory.js +311 -0
- package/out/delegation/delegationTransactionsFactory.js.map +1 -0
- package/out/delegation/delegationTransactionsOutcomeParser.d.ts +10 -0
- package/out/delegation/delegationTransactionsOutcomeParser.js +35 -0
- package/out/delegation/delegationTransactionsOutcomeParser.js.map +1 -0
- package/out/delegation/index.d.ts +4 -0
- package/out/delegation/index.js +17 -0
- package/out/delegation/index.js.map +1 -0
- package/out/delegation/resources.d.ts +38 -0
- package/out/delegation/resources.js +3 -0
- package/out/delegation/resources.js.map +1 -0
- package/out/entrypoints/config.d.ts +29 -0
- package/out/entrypoints/config.js +36 -0
- package/out/entrypoints/config.js.map +1 -0
- package/out/entrypoints/entrypoints.d.ts +92 -0
- package/out/entrypoints/entrypoints.js +203 -0
- package/out/entrypoints/entrypoints.js.map +1 -0
- package/out/entrypoints/index.d.ts +2 -0
- package/out/entrypoints/index.js +15 -0
- package/out/entrypoints/index.js.map +1 -0
- package/out/governance/governanceController.d.ts +33 -0
- package/out/governance/governanceController.js +205 -0
- package/out/governance/governanceController.js.map +1 -0
- package/out/governance/governanceTransactionsFactory.d.ts +16 -0
- package/out/governance/governanceTransactionsFactory.js +99 -0
- package/out/governance/governanceTransactionsFactory.js.map +1 -0
- package/out/governance/governanceTransactionsOutcomeParser.d.ts +15 -0
- package/out/governance/governanceTransactionsOutcomeParser.js +99 -0
- package/out/governance/governanceTransactionsOutcomeParser.js.map +1 -0
- package/out/governance/index.d.ts +4 -0
- package/out/governance/index.js +17 -0
- package/out/governance/index.js.map +1 -0
- package/out/governance/resources.d.ts +82 -0
- package/out/governance/resources.js +11 -0
- package/out/governance/resources.js.map +1 -0
- package/out/index.d.ts +19 -0
- package/out/index.js +32 -0
- package/out/index.js.map +1 -0
- package/out/multisig/index.d.ts +3 -0
- package/out/multisig/index.js +16 -0
- package/out/multisig/index.js.map +1 -0
- package/out/multisig/multisigController.d.ts +221 -0
- package/out/multisig/multisigController.js +540 -0
- package/out/multisig/multisigController.js.map +1 -0
- package/out/multisig/multisigTransactionsFactory.d.ts +110 -0
- package/out/multisig/multisigTransactionsFactory.js +355 -0
- package/out/multisig/multisigTransactionsFactory.js.map +1 -0
- package/out/multisig/multisigTransactionsOutcomeParser.d.ts +31 -0
- package/out/multisig/multisigTransactionsOutcomeParser.js +41 -0
- package/out/multisig/multisigTransactionsOutcomeParser.js.map +1 -0
- package/out/multisig/proposeTransferExecuteContractInput.d.ts +32 -0
- package/out/multisig/proposeTransferExecuteContractInput.js +65 -0
- package/out/multisig/proposeTransferExecuteContractInput.js.map +1 -0
- package/out/multisig/resources.d.ts +182 -0
- package/out/multisig/resources.js +125 -0
- package/out/multisig/resources.js.map +1 -0
- package/out/networkProviders/accountAwaiter.d.ts +35 -0
- package/out/networkProviders/accountAwaiter.js +67 -0
- package/out/networkProviders/accountAwaiter.js.map +1 -0
- package/out/networkProviders/accounts.d.ts +55 -0
- package/out/networkProviders/accounts.js +154 -0
- package/out/networkProviders/accounts.js.map +1 -0
- package/out/networkProviders/apiNetworkProvider.d.ts +48 -0
- package/out/networkProviders/apiNetworkProvider.js +235 -0
- package/out/networkProviders/apiNetworkProvider.js.map +1 -0
- package/out/networkProviders/blocks.d.ts +48 -0
- package/out/networkProviders/blocks.js +76 -0
- package/out/networkProviders/blocks.js.map +1 -0
- package/out/networkProviders/config.d.ts +6 -0
- package/out/networkProviders/config.js +18 -0
- package/out/networkProviders/config.js.map +1 -0
- package/out/networkProviders/constants.d.ts +9 -0
- package/out/networkProviders/constants.js +16 -0
- package/out/networkProviders/constants.js.map +1 -0
- package/out/networkProviders/contractQueryRequest.d.ts +6 -0
- package/out/networkProviders/contractQueryRequest.js +20 -0
- package/out/networkProviders/contractQueryRequest.js.map +1 -0
- package/out/networkProviders/index.d.ts +11 -0
- package/out/networkProviders/index.js +28 -0
- package/out/networkProviders/index.js.map +1 -0
- package/out/networkProviders/interface.d.ts +110 -0
- package/out/networkProviders/interface.js +3 -0
- package/out/networkProviders/interface.js.map +1 -0
- package/out/networkProviders/networkConfig.d.ts +48 -0
- package/out/networkProviders/networkConfig.js +41 -0
- package/out/networkProviders/networkConfig.js.map +1 -0
- package/out/networkProviders/networkProviderConfig.d.ts +4 -0
- package/out/networkProviders/networkProviderConfig.js +3 -0
- package/out/networkProviders/networkProviderConfig.js.map +1 -0
- package/out/networkProviders/networkStatus.d.ts +31 -0
- package/out/networkProviders/networkStatus.js +31 -0
- package/out/networkProviders/networkStatus.js.map +1 -0
- package/out/networkProviders/proxyNetworkProvider.d.ts +51 -0
- package/out/networkProviders/proxyNetworkProvider.js +261 -0
- package/out/networkProviders/proxyNetworkProvider.js.map +1 -0
- package/out/networkProviders/resources.d.ts +12 -0
- package/out/networkProviders/resources.js +29 -0
- package/out/networkProviders/resources.js.map +1 -0
- package/out/networkProviders/tokenDefinitions.d.ts +49 -0
- package/out/networkProviders/tokenDefinitions.js +152 -0
- package/out/networkProviders/tokenDefinitions.js.map +1 -0
- package/out/networkProviders/tokens.d.ts +40 -0
- package/out/networkProviders/tokens.js +106 -0
- package/out/networkProviders/tokens.js.map +1 -0
- package/out/networkProviders/userAgent.d.ts +2 -0
- package/out/networkProviders/userAgent.js +30 -0
- package/out/networkProviders/userAgent.js.map +1 -0
- package/out/proto/compiled.d.ts +2 -0
- package/out/proto/compiled.js +719 -0
- package/out/proto/compiled.js.map +1 -0
- package/out/proto/index.d.ts +5 -0
- package/out/proto/index.js +18 -0
- package/out/proto/index.js.map +1 -0
- package/out/proto/serializer.d.ts +22 -0
- package/out/proto/serializer.js +114 -0
- package/out/proto/serializer.js.map +1 -0
- package/out/smartContracts/index.d.ts +4 -0
- package/out/smartContracts/index.js +17 -0
- package/out/smartContracts/index.js.map +1 -0
- package/out/smartContracts/resources.d.ts +38 -0
- package/out/smartContracts/resources.js +3 -0
- package/out/smartContracts/resources.js.map +1 -0
- package/out/smartContracts/smartContractController.d.ts +32 -0
- package/out/smartContracts/smartContractController.js +128 -0
- package/out/smartContracts/smartContractController.js.map +1 -0
- package/out/smartContracts/smartContractTransactionsFactory.d.ts +42 -0
- package/out/smartContracts/smartContractTransactionsFactory.js +165 -0
- package/out/smartContracts/smartContractTransactionsFactory.js.map +1 -0
- package/out/smartContracts/smartContractTransactionsOutcomeParser.d.ts +28 -0
- package/out/smartContracts/smartContractTransactionsOutcomeParser.js +189 -0
- package/out/smartContracts/smartContractTransactionsOutcomeParser.js.map +1 -0
- package/out/tokenManagement/index.d.ts +4 -0
- package/out/tokenManagement/index.js +17 -0
- package/out/tokenManagement/index.js.map +1 -0
- package/out/tokenManagement/resources.d.ts +220 -0
- package/out/tokenManagement/resources.js +3 -0
- package/out/tokenManagement/resources.js.map +1 -0
- package/out/tokenManagement/tokenManagementController.d.ts +108 -0
- package/out/tokenManagement/tokenManagementController.js +582 -0
- package/out/tokenManagement/tokenManagementController.js.map +1 -0
- package/out/tokenManagement/tokenManagementTransactionsFactory.d.ts +82 -0
- package/out/tokenManagement/tokenManagementTransactionsFactory.js +684 -0
- package/out/tokenManagement/tokenManagementTransactionsFactory.js.map +1 -0
- package/out/tokenManagement/tokenManagementTransactionsOutcomeParser.d.ts +109 -0
- package/out/tokenManagement/tokenManagementTransactionsOutcomeParser.js +356 -0
- package/out/tokenManagement/tokenManagementTransactionsOutcomeParser.js.map +1 -0
- package/out/tokenOperations/codec.d.ts +7 -0
- package/out/tokenOperations/codec.js +55 -0
- package/out/tokenOperations/codec.js.map +1 -0
- package/out/transactionsOutcomeParsers/index.d.ts +4 -0
- package/out/transactionsOutcomeParsers/index.js +17 -0
- package/out/transactionsOutcomeParsers/index.js.map +1 -0
- package/out/transactionsOutcomeParsers/resources.d.ts +23 -0
- package/out/transactionsOutcomeParsers/resources.js +48 -0
- package/out/transactionsOutcomeParsers/resources.js.map +1 -0
- package/out/transactionsOutcomeParsers/transactionEventsParser.d.ts +16 -0
- package/out/transactionsOutcomeParsers/transactionEventsParser.js +48 -0
- package/out/transactionsOutcomeParsers/transactionEventsParser.js.map +1 -0
- package/out/transfers/index.d.ts +3 -0
- package/out/transfers/index.js +16 -0
- package/out/transfers/index.js.map +1 -0
- package/out/transfers/resources.d.ts +17 -0
- package/out/transfers/resources.js +3 -0
- package/out/transfers/resources.js.map +1 -0
- package/out/transfers/transferTransactionsFactory.d.ts +32 -0
- package/out/transfers/transferTransactionsFactory.js +131 -0
- package/out/transfers/transferTransactionsFactory.js.map +1 -0
- package/out/transfers/transfersControllers.d.ts +11 -0
- package/out/transfers/transfersControllers.js +43 -0
- package/out/transfers/transfersControllers.js.map +1 -0
- package/out/wallet/assertions.d.ts +3 -0
- package/out/wallet/assertions.js +12 -0
- package/out/wallet/assertions.js.map +1 -0
- package/out/wallet/crypto/constants.d.ts +6 -0
- package/out/wallet/crypto/constants.js +11 -0
- package/out/wallet/crypto/constants.js.map +1 -0
- package/out/wallet/crypto/decryptor.d.ts +5 -0
- package/out/wallet/crypto/decryptor.js +29 -0
- package/out/wallet/crypto/decryptor.js.map +1 -0
- package/out/wallet/crypto/derivationParams.d.ts +23 -0
- package/out/wallet/crypto/derivationParams.js +38 -0
- package/out/wallet/crypto/derivationParams.js.map +1 -0
- package/out/wallet/crypto/encryptedData.d.ts +15 -0
- package/out/wallet/crypto/encryptedData.js +52 -0
- package/out/wallet/crypto/encryptedData.js.map +1 -0
- package/out/wallet/crypto/encryptor.d.ts +14 -0
- package/out/wallet/crypto/encryptor.js +39 -0
- package/out/wallet/crypto/encryptor.js.map +1 -0
- package/out/wallet/crypto/index.d.ts +7 -0
- package/out/wallet/crypto/index.js +20 -0
- package/out/wallet/crypto/index.js.map +1 -0
- package/out/wallet/crypto/pubkeyDecryptor.d.ts +6 -0
- package/out/wallet/crypto/pubkeyDecryptor.js +38 -0
- package/out/wallet/crypto/pubkeyDecryptor.js.map +1 -0
- package/out/wallet/crypto/pubkeyEncryptor.d.ts +6 -0
- package/out/wallet/crypto/pubkeyEncryptor.js +54 -0
- package/out/wallet/crypto/pubkeyEncryptor.js.map +1 -0
- package/out/wallet/crypto/randomness.d.ts +7 -0
- package/out/wallet/crypto/randomness.js +15 -0
- package/out/wallet/crypto/randomness.js.map +1 -0
- package/out/wallet/crypto/x25519EncryptedData.d.ts +15 -0
- package/out/wallet/crypto/x25519EncryptedData.js +37 -0
- package/out/wallet/crypto/x25519EncryptedData.js.map +1 -0
- package/out/wallet/index.d.ts +11 -0
- package/out/wallet/index.js +24 -0
- package/out/wallet/index.js.map +1 -0
- package/out/wallet/keypair.d.ts +12 -0
- package/out/wallet/keypair.js +32 -0
- package/out/wallet/keypair.js.map +1 -0
- package/out/wallet/mnemonic.d.ts +13 -0
- package/out/wallet/mnemonic.js +74 -0
- package/out/wallet/mnemonic.js.map +1 -0
- package/out/wallet/pem.d.ts +8 -0
- package/out/wallet/pem.js +60 -0
- package/out/wallet/pem.js.map +1 -0
- package/out/wallet/pemEntry.d.ts +10 -0
- package/out/wallet/pemEntry.js +73 -0
- package/out/wallet/pemEntry.js.map +1 -0
- package/out/wallet/userKeys.d.ts +23 -0
- package/out/wallet/userKeys.js +99 -0
- package/out/wallet/userKeys.js.map +1 -0
- package/out/wallet/userPem.d.ts +15 -0
- package/out/wallet/userPem.js +51 -0
- package/out/wallet/userPem.js.map +1 -0
- package/out/wallet/userSigner.d.ts +16 -0
- package/out/wallet/userSigner.js +41 -0
- package/out/wallet/userSigner.js.map +1 -0
- package/out/wallet/userVerifier.d.ts +18 -0
- package/out/wallet/userVerifier.js +27 -0
- package/out/wallet/userVerifier.js.map +1 -0
- package/out/wallet/userWallet.d.ts +54 -0
- package/out/wallet/userWallet.js +206 -0
- package/out/wallet/userWallet.js.map +1 -0
- package/out/wallet/validatorKeys.d.ts +26 -0
- package/out/wallet/validatorKeys.js +77 -0
- package/out/wallet/validatorKeys.js.map +1 -0
- package/out/wallet/validatorSigner.d.ts +10 -0
- package/out/wallet/validatorSigner.js +25 -0
- package/out/wallet/validatorSigner.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { PathLike } from "fs";
|
|
3
|
+
import { Address, IAccount, Message, Transaction } from "../core";
|
|
4
|
+
import { KeyPair, UserPublicKey, UserSecretKey } from "../wallet";
|
|
5
|
+
/**
|
|
6
|
+
* An abstraction representing an account (user or Smart Contract) on the Network.
|
|
7
|
+
*/
|
|
8
|
+
export declare class Account implements IAccount {
|
|
9
|
+
/**
|
|
10
|
+
* The address of the account.
|
|
11
|
+
*/
|
|
12
|
+
readonly address: Address;
|
|
13
|
+
/**
|
|
14
|
+
* Local copy of the account nonce.
|
|
15
|
+
* Must be explicitly managed by client code.
|
|
16
|
+
*/
|
|
17
|
+
nonce: bigint;
|
|
18
|
+
/**
|
|
19
|
+
* The secret key of the account.
|
|
20
|
+
*/
|
|
21
|
+
readonly secretKey: UserSecretKey;
|
|
22
|
+
/**
|
|
23
|
+
* The public key of the account.
|
|
24
|
+
*/
|
|
25
|
+
readonly publicKey: UserPublicKey;
|
|
26
|
+
/**
|
|
27
|
+
* Creates an account object from a secret key
|
|
28
|
+
*/
|
|
29
|
+
constructor(secretKey: UserSecretKey, hrp?: string);
|
|
30
|
+
/**
|
|
31
|
+
* Named constructor
|
|
32
|
+
* Loads a secret key from a PEM file. PEM files may contain multiple accounts - thus, an (optional) "index" is used to select the desired secret key.
|
|
33
|
+
* Returns an Account object, initialized with the secret key.
|
|
34
|
+
*/
|
|
35
|
+
static newFromPem(path: PathLike, index?: number, hrp?: string): Promise<Account>;
|
|
36
|
+
/**
|
|
37
|
+
* Named constructor
|
|
38
|
+
* Loads a secret key from an encrypted keystore file. Handles both keystores that hold a mnemonic and ones that hold a secret key (legacy).
|
|
39
|
+
* For keystores that hold an encrypted mnemonic, the optional "addressIndex" parameter is used to derive the desired secret key.
|
|
40
|
+
* Returns an Account object, initialized with the secret key.
|
|
41
|
+
*/
|
|
42
|
+
static newFromKeystore(filePath: string, password: string, addressIndex?: number, hrp?: string): Account;
|
|
43
|
+
/**
|
|
44
|
+
* Named constructor
|
|
45
|
+
* Loads (derives) a secret key from a mnemonic. The optional "addressIndex" parameter is used to guide the derivation.
|
|
46
|
+
* Returns an Account object, initialized with the secret key.
|
|
47
|
+
*/
|
|
48
|
+
static newFromMnemonic(mnemonic: string, addressIndex?: number, hrp?: string): Account;
|
|
49
|
+
/**
|
|
50
|
+
* Named constructor
|
|
51
|
+
* Returns an Account object, initialized with the secret key.
|
|
52
|
+
*/
|
|
53
|
+
static newFromKeypair(keypair: KeyPair, hrp?: string): Account;
|
|
54
|
+
/**
|
|
55
|
+
* Increments (locally) the nonce (the account sequence number).
|
|
56
|
+
*/
|
|
57
|
+
incrementNonce(): void;
|
|
58
|
+
/**
|
|
59
|
+
* Signs using the secret key of the account.
|
|
60
|
+
*/
|
|
61
|
+
sign(data: Uint8Array): Promise<Uint8Array>;
|
|
62
|
+
/**
|
|
63
|
+
* Verifies the signature using the public key of the account.
|
|
64
|
+
*/
|
|
65
|
+
verify(data: Uint8Array, signature: Uint8Array): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Serializes the transaction, computes the signature and returns it.
|
|
68
|
+
*/
|
|
69
|
+
signTransaction(transaction: Transaction): Promise<Uint8Array>;
|
|
70
|
+
/**
|
|
71
|
+
* Verifies the transaction signature using the public key of the account.
|
|
72
|
+
*/
|
|
73
|
+
verifyTransactionSignature(transaction: Transaction, signature: Uint8Array): Promise<boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Serializes the message, computes the signature and returns it.
|
|
76
|
+
*/
|
|
77
|
+
signMessage(message: Message): Promise<Uint8Array>;
|
|
78
|
+
/**
|
|
79
|
+
* Verifies the message signature using the public key of the account.
|
|
80
|
+
*/
|
|
81
|
+
verifyMessageSignature(message: Message, signature: Uint8Array): Promise<boolean>;
|
|
82
|
+
/**
|
|
83
|
+
* Gets the nonce (the one from the object's state) and increments it.
|
|
84
|
+
*/
|
|
85
|
+
getNonceThenIncrement(): bigint;
|
|
86
|
+
/**
|
|
87
|
+
* Saves the wallet to a pem file
|
|
88
|
+
*/
|
|
89
|
+
saveToPem(path: string): void;
|
|
90
|
+
/**
|
|
91
|
+
* Saves the wallet to a keystore file
|
|
92
|
+
*/
|
|
93
|
+
saveToKeystore(path: PathLike, password: string): void;
|
|
94
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.Account = void 0;
|
|
23
|
+
const fs = __importStar(require("fs"));
|
|
24
|
+
const core_1 = require("../core");
|
|
25
|
+
const wallet_1 = require("../wallet");
|
|
26
|
+
/**
|
|
27
|
+
* An abstraction representing an account (user or Smart Contract) on the Network.
|
|
28
|
+
*/
|
|
29
|
+
class Account {
|
|
30
|
+
/**
|
|
31
|
+
* Creates an account object from a secret key
|
|
32
|
+
*/
|
|
33
|
+
constructor(secretKey, hrp = core_1.LibraryConfig.DefaultAddressHrp) {
|
|
34
|
+
/**
|
|
35
|
+
* Local copy of the account nonce.
|
|
36
|
+
* Must be explicitly managed by client code.
|
|
37
|
+
*/
|
|
38
|
+
this.nonce = 0n;
|
|
39
|
+
this.secretKey = secretKey;
|
|
40
|
+
this.publicKey = secretKey.generatePublicKey();
|
|
41
|
+
this.address = this.publicKey.toAddress(hrp);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Named constructor
|
|
45
|
+
* Loads a secret key from a PEM file. PEM files may contain multiple accounts - thus, an (optional) "index" is used to select the desired secret key.
|
|
46
|
+
* Returns an Account object, initialized with the secret key.
|
|
47
|
+
*/
|
|
48
|
+
static async newFromPem(path, index = 0, hrp = core_1.LibraryConfig.DefaultAddressHrp) {
|
|
49
|
+
const text = await fs.promises.readFile(path, { encoding: "utf8" });
|
|
50
|
+
const userSigner = wallet_1.UserSigner.fromPem(text, index);
|
|
51
|
+
return new Account(userSigner.secretKey, hrp);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Named constructor
|
|
55
|
+
* Loads a secret key from an encrypted keystore file. Handles both keystores that hold a mnemonic and ones that hold a secret key (legacy).
|
|
56
|
+
* For keystores that hold an encrypted mnemonic, the optional "addressIndex" parameter is used to derive the desired secret key.
|
|
57
|
+
* Returns an Account object, initialized with the secret key.
|
|
58
|
+
*/
|
|
59
|
+
static newFromKeystore(filePath, password, addressIndex, hrp = core_1.LibraryConfig.DefaultAddressHrp) {
|
|
60
|
+
const secretKey = wallet_1.UserWallet.loadSecretKey(filePath, password, addressIndex);
|
|
61
|
+
return new Account(secretKey, hrp);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Named constructor
|
|
65
|
+
* Loads (derives) a secret key from a mnemonic. The optional "addressIndex" parameter is used to guide the derivation.
|
|
66
|
+
* Returns an Account object, initialized with the secret key.
|
|
67
|
+
*/
|
|
68
|
+
static newFromMnemonic(mnemonic, addressIndex = 0, hrp = core_1.LibraryConfig.DefaultAddressHrp) {
|
|
69
|
+
const mnemonicHandler = wallet_1.Mnemonic.fromString(mnemonic);
|
|
70
|
+
const secretKey = mnemonicHandler.deriveKey(addressIndex);
|
|
71
|
+
return new Account(secretKey, hrp);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Named constructor
|
|
75
|
+
* Returns an Account object, initialized with the secret key.
|
|
76
|
+
*/
|
|
77
|
+
static newFromKeypair(keypair, hrp = core_1.LibraryConfig.DefaultAddressHrp) {
|
|
78
|
+
return new Account(keypair.secretKey, hrp);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Increments (locally) the nonce (the account sequence number).
|
|
82
|
+
*/
|
|
83
|
+
incrementNonce() {
|
|
84
|
+
this.nonce = this.nonce + 1n;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Signs using the secret key of the account.
|
|
88
|
+
*/
|
|
89
|
+
async sign(data) {
|
|
90
|
+
return this.secretKey.sign(data);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Verifies the signature using the public key of the account.
|
|
94
|
+
*/
|
|
95
|
+
async verify(data, signature) {
|
|
96
|
+
return this.publicKey.verify(data, signature);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Serializes the transaction, computes the signature and returns it.
|
|
100
|
+
*/
|
|
101
|
+
async signTransaction(transaction) {
|
|
102
|
+
const transactionComputer = new core_1.TransactionComputer();
|
|
103
|
+
const serializedTransaction = transactionComputer.computeBytesForSigning(transaction);
|
|
104
|
+
return this.secretKey.sign(serializedTransaction);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Verifies the transaction signature using the public key of the account.
|
|
108
|
+
*/
|
|
109
|
+
async verifyTransactionSignature(transaction, signature) {
|
|
110
|
+
const transactionComputer = new core_1.TransactionComputer();
|
|
111
|
+
const serializedTransaction = transactionComputer.computeBytesForVerifying(transaction);
|
|
112
|
+
return this.publicKey.verify(serializedTransaction, signature);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Serializes the message, computes the signature and returns it.
|
|
116
|
+
*/
|
|
117
|
+
async signMessage(message) {
|
|
118
|
+
const messageComputer = new core_1.MessageComputer();
|
|
119
|
+
const serializedMessage = messageComputer.computeBytesForSigning(message);
|
|
120
|
+
return this.secretKey.sign(serializedMessage);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Verifies the message signature using the public key of the account.
|
|
124
|
+
*/
|
|
125
|
+
async verifyMessageSignature(message, signature) {
|
|
126
|
+
const messageComputer = new core_1.MessageComputer();
|
|
127
|
+
const serializedMessage = messageComputer.computeBytesForVerifying(message);
|
|
128
|
+
return this.publicKey.verify(serializedMessage, signature);
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Gets the nonce (the one from the object's state) and increments it.
|
|
132
|
+
*/
|
|
133
|
+
getNonceThenIncrement() {
|
|
134
|
+
let nonce = this.nonce;
|
|
135
|
+
this.nonce = this.nonce + 1n;
|
|
136
|
+
return nonce;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Saves the wallet to a pem file
|
|
140
|
+
*/
|
|
141
|
+
saveToPem(path) {
|
|
142
|
+
const pem = new wallet_1.UserPem(this.address.toBech32(), this.secretKey);
|
|
143
|
+
pem.save(path);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Saves the wallet to a keystore file
|
|
147
|
+
*/
|
|
148
|
+
saveToKeystore(path, password) {
|
|
149
|
+
const wallet = wallet_1.UserWallet.fromSecretKey({ secretKey: this.secretKey, password });
|
|
150
|
+
wallet.save(path, this.address.getHrp());
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
exports.Account = Account;
|
|
154
|
+
//# sourceMappingURL=account.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/accounts/account.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./account";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./account"), exports);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/accounts/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
/**
|
|
3
|
+
* An Address, as an immutable object.
|
|
4
|
+
*/
|
|
5
|
+
export declare class Address {
|
|
6
|
+
private readonly publicKey;
|
|
7
|
+
private readonly hrp;
|
|
8
|
+
/**
|
|
9
|
+
* Creates an address object, given a raw string (whether a hex pubkey or a Bech32 address), a sequence of bytes, or another Address object.
|
|
10
|
+
*/
|
|
11
|
+
constructor(value: Address | Uint8Array | string, hrp?: string);
|
|
12
|
+
/**
|
|
13
|
+
* Named constructor
|
|
14
|
+
* Creates an address object from a bech32-encoded string
|
|
15
|
+
*/
|
|
16
|
+
static newFromBech32(value: string): Address;
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated Use {@link newFromBech32} instead.
|
|
19
|
+
*/
|
|
20
|
+
static fromBech32(value: string): Address;
|
|
21
|
+
/**
|
|
22
|
+
* Named constructor
|
|
23
|
+
* Creates an address object from a hex-encoded string
|
|
24
|
+
*/
|
|
25
|
+
static newFromHex(value: string, hrp?: string): Address;
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use {@link newFromHex} instead.
|
|
28
|
+
*/
|
|
29
|
+
static fromHex(value: string, hrp?: string): Address;
|
|
30
|
+
private static isValidHex;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use {@link toHex} instead.
|
|
33
|
+
*/
|
|
34
|
+
hex(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Returns the hex representation of the address (pubkey)
|
|
37
|
+
*/
|
|
38
|
+
toHex(): string;
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use {@link toBech32} instead.
|
|
41
|
+
*/
|
|
42
|
+
bech32(): string;
|
|
43
|
+
/**
|
|
44
|
+
* Returns the bech32 representation of the address
|
|
45
|
+
*/
|
|
46
|
+
toBech32(): string;
|
|
47
|
+
/**
|
|
48
|
+
* @deprecated Use {@link getPublicKey} instead.
|
|
49
|
+
*/
|
|
50
|
+
pubkey(): Buffer;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the underlying public key.
|
|
53
|
+
*/
|
|
54
|
+
getPublicKey(): Buffer;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the human-readable-part of the bech32 addresses.
|
|
57
|
+
*/
|
|
58
|
+
getHrp(): string;
|
|
59
|
+
/**
|
|
60
|
+
* Creates an empty address object.
|
|
61
|
+
* Generally speaking, this should not be used by client code (internal use only).
|
|
62
|
+
*/
|
|
63
|
+
static empty(): Address;
|
|
64
|
+
/**
|
|
65
|
+
* Performs address validation without throwing errors
|
|
66
|
+
*/
|
|
67
|
+
static isValid(value: string): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Returns whether the address is empty.
|
|
70
|
+
*/
|
|
71
|
+
isEmpty(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Compares the address to another address
|
|
74
|
+
*/
|
|
75
|
+
equals(other: Address | null): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Returns the bech32 representation of the address
|
|
78
|
+
*/
|
|
79
|
+
toString(): string;
|
|
80
|
+
/**
|
|
81
|
+
* Converts the address to a pretty, plain JavaScript object.
|
|
82
|
+
*/
|
|
83
|
+
toJSON(): object;
|
|
84
|
+
/**
|
|
85
|
+
* Creates the Zero address (the one that should be used when deploying smart contracts).
|
|
86
|
+
* Generally speaking, this should not be used by client code (internal use only).
|
|
87
|
+
*/
|
|
88
|
+
static Zero(): Address;
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated Use {@link isSmartContract} instead.
|
|
91
|
+
*/
|
|
92
|
+
isContractAddress(): boolean;
|
|
93
|
+
/**
|
|
94
|
+
* Returns whether the address is a smart contract address.
|
|
95
|
+
*/
|
|
96
|
+
isSmartContract(): boolean;
|
|
97
|
+
}
|
|
98
|
+
export declare class AddressComputer {
|
|
99
|
+
private readonly numberOfShardsWithoutMeta;
|
|
100
|
+
constructor(numberOfShardsWithoutMeta?: number);
|
|
101
|
+
computeContractAddress(deployer: Address, deploymentNonce: bigint): Address;
|
|
102
|
+
getShardOfAddress(address: Address): number;
|
|
103
|
+
private getShardOfPubkey;
|
|
104
|
+
private isPubkeyOfMetachain;
|
|
105
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.AddressComputer = exports.Address = void 0;
|
|
26
|
+
const bech32 = __importStar(require("bech32"));
|
|
27
|
+
const bignumber_js_1 = __importDefault(require("bignumber.js"));
|
|
28
|
+
const codec_1 = require("../tokenOperations/codec");
|
|
29
|
+
const config_1 = require("./config");
|
|
30
|
+
const constants_1 = require("./constants");
|
|
31
|
+
const errors = __importStar(require("./errors"));
|
|
32
|
+
const createKeccakHash = require("keccak");
|
|
33
|
+
/**
|
|
34
|
+
* The length (in bytes) of a public key (from which a bech32 address can be obtained).
|
|
35
|
+
*/
|
|
36
|
+
const PUBKEY_LENGTH = 32;
|
|
37
|
+
const SMART_CONTRACT_HEX_PUBKEY_PREFIX = "0".repeat(16);
|
|
38
|
+
/**
|
|
39
|
+
* An Address, as an immutable object.
|
|
40
|
+
*/
|
|
41
|
+
class Address {
|
|
42
|
+
/**
|
|
43
|
+
* Creates an address object, given a raw string (whether a hex pubkey or a Bech32 address), a sequence of bytes, or another Address object.
|
|
44
|
+
*/
|
|
45
|
+
constructor(value, hrp) {
|
|
46
|
+
// Legacy flow.
|
|
47
|
+
if (!value) {
|
|
48
|
+
this.publicKey = Buffer.from([]);
|
|
49
|
+
this.hrp = hrp || config_1.LibraryConfig.DefaultAddressHrp;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
// The only flow that's following the specs.
|
|
53
|
+
if (ArrayBuffer.isView(value)) {
|
|
54
|
+
if (value.length != PUBKEY_LENGTH) {
|
|
55
|
+
throw new errors.ErrAddressCannotCreate(value);
|
|
56
|
+
}
|
|
57
|
+
this.publicKey = Buffer.from(value);
|
|
58
|
+
this.hrp = hrp || config_1.LibraryConfig.DefaultAddressHrp;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Legacy flow.
|
|
62
|
+
if (value instanceof Address) {
|
|
63
|
+
if (hrp) {
|
|
64
|
+
throw new errors.ErrInvalidArgument("this variant of the Address constructor does not accept the 'hrp' argument");
|
|
65
|
+
}
|
|
66
|
+
this.publicKey = value.publicKey;
|
|
67
|
+
this.hrp = value.hrp;
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Legacy flow.
|
|
71
|
+
if (typeof value === "string") {
|
|
72
|
+
if (Address.isValidHex(value)) {
|
|
73
|
+
this.publicKey = Buffer.from(value, "hex");
|
|
74
|
+
this.hrp = hrp || config_1.LibraryConfig.DefaultAddressHrp;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (hrp) {
|
|
78
|
+
throw new errors.ErrInvalidArgument("this variant of the Address constructor does not accept the 'hrp' argument");
|
|
79
|
+
}
|
|
80
|
+
// On this legacy flow, we do not accept addresses with custom hrp (in order to avoid behavioral breaking changes).
|
|
81
|
+
const { hrp: decodedHrp, pubkey } = decodeFromBech32({ value, allowCustomHrp: false });
|
|
82
|
+
this.publicKey = pubkey;
|
|
83
|
+
this.hrp = decodedHrp;
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
throw new errors.ErrAddressCannotCreate(value);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Named constructor
|
|
90
|
+
* Creates an address object from a bech32-encoded string
|
|
91
|
+
*/
|
|
92
|
+
static newFromBech32(value) {
|
|
93
|
+
const { hrp, pubkey } = decodeFromBech32({ value, allowCustomHrp: true });
|
|
94
|
+
return new Address(pubkey, hrp);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* @deprecated Use {@link newFromBech32} instead.
|
|
98
|
+
*/
|
|
99
|
+
static fromBech32(value) {
|
|
100
|
+
// On this legacy flow, we do not accept addresses with custom hrp (in order to avoid behavioral breaking changes).
|
|
101
|
+
const { hrp, pubkey } = decodeFromBech32({ value, allowCustomHrp: false });
|
|
102
|
+
return new Address(pubkey, hrp);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Named constructor
|
|
106
|
+
* Creates an address object from a hex-encoded string
|
|
107
|
+
*/
|
|
108
|
+
static newFromHex(value, hrp) {
|
|
109
|
+
if (!Address.isValidHex(value)) {
|
|
110
|
+
throw new errors.ErrAddressCannotCreate(value);
|
|
111
|
+
}
|
|
112
|
+
return new Address(Buffer.from(value, "hex"), hrp);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* @deprecated Use {@link newFromHex} instead.
|
|
116
|
+
*/
|
|
117
|
+
static fromHex(value, hrp) {
|
|
118
|
+
return Address.newFromHex(value, hrp);
|
|
119
|
+
}
|
|
120
|
+
static isValidHex(value) {
|
|
121
|
+
return Buffer.from(value, "hex").length == PUBKEY_LENGTH;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* @deprecated Use {@link toHex} instead.
|
|
125
|
+
*/
|
|
126
|
+
hex() {
|
|
127
|
+
return this.toHex();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Returns the hex representation of the address (pubkey)
|
|
131
|
+
*/
|
|
132
|
+
toHex() {
|
|
133
|
+
if (this.isEmpty()) {
|
|
134
|
+
return "";
|
|
135
|
+
}
|
|
136
|
+
return this.publicKey.toString("hex");
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated Use {@link toBech32} instead.
|
|
140
|
+
*/
|
|
141
|
+
bech32() {
|
|
142
|
+
return this.toBech32();
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Returns the bech32 representation of the address
|
|
146
|
+
*/
|
|
147
|
+
toBech32() {
|
|
148
|
+
if (this.isEmpty()) {
|
|
149
|
+
return "";
|
|
150
|
+
}
|
|
151
|
+
let words = bech32.toWords(this.getPublicKey());
|
|
152
|
+
let address = bech32.encode(this.hrp, words);
|
|
153
|
+
return address;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @deprecated Use {@link getPublicKey} instead.
|
|
157
|
+
*/
|
|
158
|
+
pubkey() {
|
|
159
|
+
return this.getPublicKey();
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Returns the underlying public key.
|
|
163
|
+
*/
|
|
164
|
+
getPublicKey() {
|
|
165
|
+
return this.publicKey;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Returns the human-readable-part of the bech32 addresses.
|
|
169
|
+
*/
|
|
170
|
+
getHrp() {
|
|
171
|
+
return this.hrp;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Creates an empty address object.
|
|
175
|
+
* Generally speaking, this should not be used by client code (internal use only).
|
|
176
|
+
*/
|
|
177
|
+
static empty() {
|
|
178
|
+
return new Address("");
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Performs address validation without throwing errors
|
|
182
|
+
*/
|
|
183
|
+
static isValid(value) {
|
|
184
|
+
const decoded = bech32.decodeUnsafe(value);
|
|
185
|
+
const prefix = decoded?.prefix;
|
|
186
|
+
const pubkey = decoded ? Buffer.from(bech32.fromWords(decoded.words)) : undefined;
|
|
187
|
+
if (prefix !== config_1.LibraryConfig.DefaultAddressHrp || pubkey?.length !== PUBKEY_LENGTH) {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Returns whether the address is empty.
|
|
194
|
+
*/
|
|
195
|
+
isEmpty() {
|
|
196
|
+
return this.publicKey.length == 0;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Compares the address to another address
|
|
200
|
+
*/
|
|
201
|
+
equals(other) {
|
|
202
|
+
if (!other) {
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
return this.publicKey.toString() == other.publicKey.toString();
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Returns the bech32 representation of the address
|
|
209
|
+
*/
|
|
210
|
+
toString() {
|
|
211
|
+
return this.toBech32();
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Converts the address to a pretty, plain JavaScript object.
|
|
215
|
+
*/
|
|
216
|
+
toJSON() {
|
|
217
|
+
return {
|
|
218
|
+
bech32: this.toBech32(),
|
|
219
|
+
pubkey: this.toHex(),
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Creates the Zero address (the one that should be used when deploying smart contracts).
|
|
224
|
+
* Generally speaking, this should not be used by client code (internal use only).
|
|
225
|
+
*/
|
|
226
|
+
static Zero() {
|
|
227
|
+
return new Address("0".repeat(64));
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* @deprecated Use {@link isSmartContract} instead.
|
|
231
|
+
*/
|
|
232
|
+
isContractAddress() {
|
|
233
|
+
return this.isSmartContract();
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Returns whether the address is a smart contract address.
|
|
237
|
+
*/
|
|
238
|
+
isSmartContract() {
|
|
239
|
+
return this.toHex().startsWith(SMART_CONTRACT_HEX_PUBKEY_PREFIX);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
exports.Address = Address;
|
|
243
|
+
class AddressComputer {
|
|
244
|
+
constructor(numberOfShardsWithoutMeta) {
|
|
245
|
+
this.numberOfShardsWithoutMeta = numberOfShardsWithoutMeta || constants_1.CURRENT_NUMBER_OF_SHARDS_WITHOUT_META;
|
|
246
|
+
}
|
|
247
|
+
computeContractAddress(deployer, deploymentNonce) {
|
|
248
|
+
const initialPadding = Buffer.alloc(8, 0);
|
|
249
|
+
const ownerPubkey = deployer.getPublicKey();
|
|
250
|
+
const shardSelector = ownerPubkey.slice(30);
|
|
251
|
+
const ownerNonceBytes = Buffer.alloc(8);
|
|
252
|
+
const bigNonce = new bignumber_js_1.default(deploymentNonce.toString());
|
|
253
|
+
const bigNonceBuffer = codec_1.bigIntToBuffer(bigNonce);
|
|
254
|
+
ownerNonceBytes.write(bigNonceBuffer.reverse().toString("hex"), "hex");
|
|
255
|
+
const bytesToHash = Buffer.concat([ownerPubkey, ownerNonceBytes]);
|
|
256
|
+
const hash = createKeccakHash("keccak256").update(bytesToHash).digest();
|
|
257
|
+
const vmTypeBytes = Buffer.from(constants_1.WasmVirtualMachine, "hex");
|
|
258
|
+
const addressBytes = Buffer.concat([initialPadding, vmTypeBytes, hash.slice(10, 30), shardSelector]);
|
|
259
|
+
return new Address(addressBytes);
|
|
260
|
+
}
|
|
261
|
+
getShardOfAddress(address) {
|
|
262
|
+
return this.getShardOfPubkey(address.getPublicKey(), this.numberOfShardsWithoutMeta);
|
|
263
|
+
}
|
|
264
|
+
getShardOfPubkey(pubkey, numberOfShards) {
|
|
265
|
+
const maskHigh = parseInt("11", 2);
|
|
266
|
+
const maskLow = parseInt("01", 2);
|
|
267
|
+
const lastByteOfPubkey = pubkey[31];
|
|
268
|
+
if (this.isPubkeyOfMetachain(pubkey)) {
|
|
269
|
+
return constants_1.METACHAIN_ID;
|
|
270
|
+
}
|
|
271
|
+
let shard = lastByteOfPubkey & maskHigh;
|
|
272
|
+
if (shard > numberOfShards - 1) {
|
|
273
|
+
shard = lastByteOfPubkey & maskLow;
|
|
274
|
+
}
|
|
275
|
+
return shard;
|
|
276
|
+
}
|
|
277
|
+
isPubkeyOfMetachain(pubkey) {
|
|
278
|
+
const metachainPrefix = Buffer.from([
|
|
279
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
280
|
+
]);
|
|
281
|
+
const pubkeyPrefix = Buffer.from(pubkey).slice(0, metachainPrefix.length);
|
|
282
|
+
if (metachainPrefix.equals(pubkeyPrefix)) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
const zeroAddress = Buffer.alloc(32);
|
|
286
|
+
if (zeroAddress.equals(Buffer.from(pubkey))) {
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
exports.AddressComputer = AddressComputer;
|
|
293
|
+
function decodeFromBech32(options) {
|
|
294
|
+
const value = options.value;
|
|
295
|
+
const allowCustomHrp = options.allowCustomHrp;
|
|
296
|
+
let hrp;
|
|
297
|
+
let pubkey;
|
|
298
|
+
try {
|
|
299
|
+
const decoded = bech32.decode(value);
|
|
300
|
+
hrp = decoded.prefix;
|
|
301
|
+
pubkey = Buffer.from(bech32.fromWords(decoded.words));
|
|
302
|
+
}
|
|
303
|
+
catch (err) {
|
|
304
|
+
throw new errors.ErrAddressCannotCreate(value, err);
|
|
305
|
+
}
|
|
306
|
+
// Workaround, in order to avoid behavioral breaking changes on legacy flows.
|
|
307
|
+
// In a future major release, we should drop this constraint (not exactly useful, validation should be performed in other ways)
|
|
308
|
+
if (!allowCustomHrp && hrp != config_1.LibraryConfig.DefaultAddressHrp) {
|
|
309
|
+
throw new errors.ErrAddressBadHrp(config_1.LibraryConfig.DefaultAddressHrp, hrp);
|
|
310
|
+
}
|
|
311
|
+
return { hrp, pubkey };
|
|
312
|
+
}
|
|
313
|
+
//# sourceMappingURL=address.js.map
|