@btc-vision/transaction 1.8.0-beta.1 → 1.8.0-beta.4
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/browser/_version.d.ts +1 -0
- package/browser/_version.d.ts.map +1 -0
- package/browser/abi/ABICoder.d.ts +1 -1
- package/browser/abi/ABICoder.d.ts.map +1 -0
- package/browser/branded/Branded.d.ts +4 -0
- package/browser/branded/Branded.d.ts.map +1 -0
- package/browser/btc-vision-bitcoin.js +12420 -3637
- package/browser/buffer/BinaryReader.d.ts +120 -1
- package/browser/buffer/BinaryReader.d.ts.map +1 -0
- package/browser/buffer/BinaryWriter.d.ts +51 -1
- package/browser/buffer/BinaryWriter.d.ts.map +1 -0
- package/browser/bytecode/Compressor.d.ts +12 -0
- package/browser/bytecode/Compressor.d.ts.map +1 -0
- package/browser/chain/ChainData.d.ts +2 -2
- package/browser/chain/ChainData.d.ts.map +1 -0
- package/browser/consensus/Consensus.d.ts +11 -3
- package/browser/consensus/Consensus.d.ts.map +1 -0
- package/browser/consensus/ConsensusConfig.d.ts +1 -0
- package/browser/consensus/ConsensusConfig.d.ts.map +1 -0
- package/browser/consensus/IConsensusConfig.d.ts +1 -0
- package/browser/consensus/IConsensusConfig.d.ts.map +1 -0
- package/browser/consensus/metadata/RoswellConsensus.d.ts +1 -0
- package/browser/consensus/metadata/RoswellConsensus.d.ts.map +1 -0
- package/browser/crypto/crypto.d.ts +1 -0
- package/browser/crypto/crypto.d.ts.map +1 -0
- package/browser/deterministic/AddressMap.d.ts +6 -1
- package/browser/deterministic/AddressMap.d.ts.map +1 -0
- package/browser/deterministic/AddressSet.d.ts +3 -1
- package/browser/deterministic/AddressSet.d.ts.map +1 -0
- package/browser/deterministic/CustomMap.d.ts +3 -1
- package/browser/deterministic/CustomMap.d.ts.map +1 -0
- package/browser/deterministic/DeterministicMap.d.ts +3 -1
- package/browser/deterministic/DeterministicMap.d.ts.map +1 -0
- package/browser/deterministic/DeterministicSet.d.ts +3 -1
- package/browser/deterministic/DeterministicSet.d.ts.map +1 -0
- package/browser/deterministic/ExtendedAddressMap.d.ts +7 -1
- package/browser/deterministic/ExtendedAddressMap.d.ts.map +1 -0
- package/browser/deterministic/FastMap.d.ts +7 -1
- package/browser/deterministic/FastMap.d.ts.map +1 -0
- package/browser/ecc/backend.d.ts +13 -0
- package/browser/ecc/backend.d.ts.map +1 -0
- package/browser/epoch/ChallengeSolution.d.ts +33 -1
- package/browser/epoch/ChallengeSolution.d.ts.map +1 -0
- package/browser/epoch/interfaces/IChallengeSolution.d.ts +14 -13
- package/browser/epoch/interfaces/IChallengeSolution.d.ts.map +1 -0
- package/browser/epoch/validator/EpochValidator.d.ts +37 -7
- package/browser/epoch/validator/EpochValidator.d.ts.map +1 -0
- package/browser/event/NetEvent.d.ts +1 -0
- package/browser/event/NetEvent.d.ts.map +1 -0
- package/browser/generators/AddressGenerator.d.ts +4 -3
- package/browser/generators/AddressGenerator.d.ts.map +1 -0
- package/browser/generators/Features.d.ts +1 -0
- package/browser/generators/Features.d.ts.map +1 -0
- package/browser/generators/Generator.d.ts +46 -10
- package/browser/generators/Generator.d.ts.map +1 -0
- package/browser/generators/MLDSAData.d.ts +1 -0
- package/browser/generators/MLDSAData.d.ts.map +1 -0
- package/browser/generators/builders/CalldataGenerator.d.ts +25 -4
- package/browser/generators/builders/CalldataGenerator.d.ts.map +1 -0
- package/browser/generators/builders/CustomGenerator.d.ts +13 -3
- package/browser/generators/builders/CustomGenerator.d.ts.map +1 -0
- package/browser/generators/builders/DeploymentGenerator.d.ts +15 -4
- package/browser/generators/builders/DeploymentGenerator.d.ts.map +1 -0
- package/browser/generators/builders/HashCommitmentGenerator.d.ts +164 -12
- package/browser/generators/builders/HashCommitmentGenerator.d.ts.map +1 -0
- package/browser/generators/builders/LegacyCalldataGenerator.d.ts +26 -4
- package/browser/generators/builders/LegacyCalldataGenerator.d.ts.map +1 -0
- package/browser/generators/builders/MultiSignGenerator.d.ts +6 -1
- package/browser/generators/builders/MultiSignGenerator.d.ts.map +1 -0
- package/browser/generators/builders/P2WDAGenerator.d.ts +42 -4
- package/browser/generators/builders/P2WDAGenerator.d.ts.map +1 -0
- package/browser/index.d.ts +1 -0
- package/browser/index.d.ts.map +1 -0
- package/browser/index.js +3602 -3203
- package/browser/keypair/Address.d.ts +283 -13
- package/browser/keypair/Address.d.ts.map +1 -0
- package/browser/keypair/AddressVerificator.d.ts +7 -6
- package/browser/keypair/AddressVerificator.d.ts.map +1 -0
- package/browser/keypair/EcKeyPair.d.ts +183 -21
- package/browser/keypair/EcKeyPair.d.ts.map +1 -0
- package/browser/keypair/MessageSigner.d.ts +17 -16
- package/browser/keypair/MessageSigner.d.ts.map +1 -0
- package/browser/keypair/Secp256k1PointDeriver.d.ts +55 -0
- package/browser/keypair/Secp256k1PointDeriver.d.ts.map +1 -0
- package/browser/keypair/Wallet.d.ts +27 -13
- package/browser/keypair/Wallet.d.ts.map +1 -0
- package/browser/keypair/interfaces/IWallet.d.ts +19 -0
- package/browser/keypair/interfaces/IWallet.d.ts.map +1 -0
- package/browser/metadata/ContractBaseMetadata.d.ts +10 -2
- package/browser/metadata/ContractBaseMetadata.d.ts.map +1 -0
- package/browser/mnemonic/BIPStandard.d.ts +59 -0
- package/browser/mnemonic/BIPStandard.d.ts.map +1 -0
- package/browser/mnemonic/Mnemonic.d.ts +15 -3
- package/browser/mnemonic/Mnemonic.d.ts.map +1 -0
- package/browser/mnemonic/MnemonicStrength.d.ts +6 -0
- package/browser/mnemonic/MnemonicStrength.d.ts.map +1 -0
- package/browser/network/ChainId.d.ts +1 -0
- package/browser/network/ChainId.d.ts.map +1 -0
- package/browser/noble-curves.js +920 -2966
- package/browser/noble-hashes.js +2067 -1038
- package/browser/opnet.d.ts +22 -1
- package/browser/opnet.d.ts.map +1 -0
- package/browser/p2wda/P2WDADetector.d.ts +36 -9
- package/browser/p2wda/P2WDADetector.d.ts.map +1 -0
- package/browser/polyfill/disposable.d.ts +16 -0
- package/browser/polyfill/disposable.d.ts.map +1 -0
- package/browser/signer/AddressRotation.d.ts +36 -0
- package/browser/signer/AddressRotation.d.ts.map +1 -0
- package/browser/signer/IRotationSigner.d.ts +27 -3
- package/browser/signer/IRotationSigner.d.ts.map +1 -0
- package/browser/signer/ParallelSignerAdapter.d.ts +14 -0
- package/browser/signer/ParallelSignerAdapter.d.ts.map +1 -0
- package/browser/signer/SignerUtils.d.ts +11 -4
- package/browser/signer/SignerUtils.d.ts.map +1 -0
- package/browser/signer/TweakedSigner.d.ts +28 -4
- package/browser/signer/TweakedSigner.d.ts.map +1 -0
- package/browser/transaction/ContractAddress.d.ts +2 -2
- package/browser/transaction/ContractAddress.d.ts.map +1 -0
- package/browser/transaction/TransactionFactory.d.ts +140 -2
- package/browser/transaction/TransactionFactory.d.ts.map +1 -0
- package/browser/transaction/browser/BrowserSignerBase.d.ts +12 -6
- package/browser/transaction/browser/BrowserSignerBase.d.ts.map +1 -0
- package/browser/transaction/browser/WalletNetworks.d.ts +1 -0
- package/browser/transaction/browser/WalletNetworks.d.ts.map +1 -0
- package/browser/transaction/browser/Web3Provider.d.ts +27 -0
- package/browser/transaction/browser/Web3Provider.d.ts.map +1 -0
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +9 -7
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts.map +1 -0
- package/browser/transaction/browser/extensions/XverseSigner.d.ts +9 -7
- package/browser/transaction/browser/extensions/XverseSigner.d.ts.map +1 -0
- package/browser/transaction/browser/types/OPWallet.d.ts +10 -0
- package/browser/transaction/browser/types/OPWallet.d.ts.map +1 -0
- package/browser/transaction/browser/types/Unisat.d.ts +1 -0
- package/browser/transaction/browser/types/Unisat.d.ts.map +1 -0
- package/browser/transaction/browser/types/Xverse.d.ts +1 -0
- package/browser/transaction/browser/types/Xverse.d.ts.map +1 -0
- package/browser/transaction/builders/CancelTransaction.d.ts +29 -4
- package/browser/transaction/builders/CancelTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/ChallengeSolutionTransaction.d.ts +1 -0
- package/browser/transaction/builders/ChallengeSolutionTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts +137 -10
- package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +106 -6
- package/browser/transaction/builders/CustomScriptTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/DeploymentTransaction.d.ts +116 -5
- package/browser/transaction/builders/DeploymentTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/FundingTransaction.d.ts +4 -3
- package/browser/transaction/builders/FundingTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/InteractionTransaction.d.ts +12 -3
- package/browser/transaction/builders/InteractionTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts +56 -5
- package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts.map +1 -0
- package/browser/transaction/builders/MultiSignTransaction.d.ts +125 -16
- package/browser/transaction/builders/MultiSignTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +103 -15
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts.map +1 -0
- package/browser/transaction/builders/TransactionBuilder.d.ts +243 -14
- package/browser/transaction/builders/TransactionBuilder.d.ts.map +1 -0
- package/browser/transaction/enums/TransactionType.d.ts +1 -0
- package/browser/transaction/enums/TransactionType.d.ts.map +1 -0
- package/browser/transaction/interfaces/ICancelTransactionParameters.d.ts +2 -1
- package/browser/transaction/interfaces/ICancelTransactionParameters.d.ts.map +1 -0
- package/browser/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +46 -3
- package/browser/transaction/interfaces/IConsolidatedTransactionParameters.d.ts.map +1 -0
- package/browser/transaction/interfaces/ICustomTransactionParameters.d.ts +6 -4
- package/browser/transaction/interfaces/ICustomTransactionParameters.d.ts.map +1 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +22 -10
- package/browser/transaction/interfaces/ITransactionParameters.d.ts.map +1 -0
- package/browser/transaction/interfaces/ITransactionResponses.d.ts +1 -0
- package/browser/transaction/interfaces/ITransactionResponses.d.ts.map +1 -0
- package/browser/transaction/interfaces/ITweakedTransactionData.d.ts +18 -5
- package/browser/transaction/interfaces/ITweakedTransactionData.d.ts.map +1 -0
- package/browser/transaction/interfaces/IWeb3ProviderTypes.d.ts +26 -0
- package/browser/transaction/interfaces/IWeb3ProviderTypes.d.ts.map +1 -0
- package/browser/transaction/interfaces/Tap.d.ts +4 -3
- package/browser/transaction/interfaces/Tap.d.ts.map +1 -0
- package/browser/transaction/mineable/IP2WSHAddress.d.ts +2 -1
- package/browser/transaction/mineable/IP2WSHAddress.d.ts.map +1 -0
- package/browser/transaction/mineable/TimelockGenerator.d.ts +12 -3
- package/browser/transaction/mineable/TimelockGenerator.d.ts.map +1 -0
- package/browser/transaction/offline/OfflineTransactionManager.d.ts +190 -9
- package/browser/transaction/offline/OfflineTransactionManager.d.ts.map +1 -0
- package/browser/transaction/offline/TransactionReconstructor.d.ts +53 -3
- package/browser/transaction/offline/TransactionReconstructor.d.ts.map +1 -0
- package/browser/transaction/offline/TransactionSerializer.d.ts +53 -2
- package/browser/transaction/offline/TransactionSerializer.d.ts.map +1 -0
- package/browser/transaction/offline/TransactionStateCapture.d.ts +64 -5
- package/browser/transaction/offline/TransactionStateCapture.d.ts.map +1 -0
- package/browser/transaction/offline/interfaces/ISerializableState.d.ts +71 -0
- package/browser/transaction/offline/interfaces/ISerializableState.d.ts.map +1 -0
- package/browser/transaction/offline/interfaces/ITypeSpecificData.d.ts +76 -0
- package/browser/transaction/offline/interfaces/ITypeSpecificData.d.ts.map +1 -0
- package/browser/transaction/psbt/PSBTTypes.d.ts +1 -0
- package/browser/transaction/psbt/PSBTTypes.d.ts.map +1 -0
- package/browser/transaction/shared/P2TR_MS.d.ts +11 -2
- package/browser/transaction/shared/P2TR_MS.d.ts.map +1 -0
- package/browser/transaction/shared/TweakedTransaction.d.ts +275 -33
- package/browser/transaction/shared/TweakedTransaction.d.ts.map +1 -0
- package/browser/transaction/utils/WitnessUtils.d.ts +7 -1
- package/browser/transaction/utils/WitnessUtils.d.ts.map +1 -0
- package/browser/utils/BitcoinUtils.d.ts +19 -0
- package/browser/utils/BitcoinUtils.d.ts.map +1 -0
- package/browser/utils/BufferHelper.d.ts +1 -0
- package/browser/utils/BufferHelper.d.ts.map +1 -0
- package/browser/utils/StringToBuffer.d.ts +1 -0
- package/browser/utils/StringToBuffer.d.ts.map +1 -0
- package/browser/utils/lengths.d.ts +1 -0
- package/browser/utils/lengths.d.ts.map +1 -0
- package/browser/utils/types.d.ts +1 -0
- package/browser/utils/types.d.ts.map +1 -0
- package/browser/utxo/OPNetLimitedProvider.d.ts +37 -1
- package/browser/utxo/OPNetLimitedProvider.d.ts.map +1 -0
- package/browser/utxo/interfaces/BroadcastResponse.d.ts +1 -0
- package/browser/utxo/interfaces/BroadcastResponse.d.ts.map +1 -0
- package/browser/utxo/interfaces/IUTXO.d.ts +11 -5
- package/browser/utxo/interfaces/IUTXO.d.ts.map +1 -0
- package/browser/vendors.js +13940 -9389
- package/browser/verification/TapscriptVerificator.d.ts +10 -8
- package/browser/verification/TapscriptVerificator.d.ts.map +1 -0
- package/build/_version.d.ts +1 -0
- package/build/_version.d.ts.map +1 -0
- package/build/_version.js +1 -0
- package/build/_version.js.map +1 -0
- package/build/abi/ABICoder.d.ts +1 -1
- package/build/abi/ABICoder.d.ts.map +1 -0
- package/build/abi/ABICoder.js +9 -10
- package/build/abi/ABICoder.js.map +1 -0
- package/build/branded/Branded.d.ts +4 -0
- package/build/branded/Branded.d.ts.map +1 -0
- package/build/branded/Branded.js +2 -0
- package/build/branded/Branded.js.map +1 -0
- package/build/buffer/BinaryReader.d.ts +121 -2
- package/build/buffer/BinaryReader.d.ts.map +1 -0
- package/build/buffer/BinaryReader.js +129 -5
- package/build/buffer/BinaryReader.js.map +1 -0
- package/build/buffer/BinaryWriter.d.ts +52 -2
- package/build/buffer/BinaryWriter.d.ts.map +1 -0
- package/build/buffer/BinaryWriter.js +62 -2
- package/build/buffer/BinaryWriter.js.map +1 -0
- package/build/bytecode/Compressor.d.ts +12 -0
- package/build/bytecode/Compressor.d.ts.map +1 -0
- package/build/bytecode/Compressor.js +17 -5
- package/build/bytecode/Compressor.js.map +1 -0
- package/build/chain/ChainData.d.ts +2 -2
- package/build/chain/ChainData.d.ts.map +1 -0
- package/build/chain/ChainData.js +35 -17
- package/build/chain/ChainData.js.map +1 -0
- package/build/consensus/Consensus.d.ts +11 -3
- package/build/consensus/Consensus.d.ts.map +1 -0
- package/build/consensus/Consensus.js +8 -0
- package/build/consensus/Consensus.js.map +1 -0
- package/build/consensus/ConsensusConfig.d.ts +2 -1
- package/build/consensus/ConsensusConfig.d.ts.map +1 -0
- package/build/consensus/ConsensusConfig.js +1 -0
- package/build/consensus/ConsensusConfig.js.map +1 -0
- package/build/consensus/IConsensusConfig.d.ts +1 -0
- package/build/consensus/IConsensusConfig.d.ts.map +1 -0
- package/build/consensus/IConsensusConfig.js +2 -1
- package/build/consensus/IConsensusConfig.js.map +1 -0
- package/build/consensus/metadata/RoswellConsensus.d.ts +2 -1
- package/build/consensus/metadata/RoswellConsensus.d.ts.map +1 -0
- package/build/consensus/metadata/RoswellConsensus.js +2 -0
- package/build/consensus/metadata/RoswellConsensus.js.map +1 -0
- package/build/crypto/crypto.d.ts +1 -0
- package/build/crypto/crypto.d.ts.map +1 -0
- package/build/crypto/crypto.js +1 -0
- package/build/crypto/crypto.js.map +1 -0
- package/build/deterministic/AddressMap.d.ts +6 -1
- package/build/deterministic/AddressMap.d.ts.map +1 -0
- package/build/deterministic/AddressMap.js +8 -0
- package/build/deterministic/AddressMap.js.map +1 -0
- package/build/deterministic/AddressSet.d.ts +3 -1
- package/build/deterministic/AddressSet.d.ts.map +1 -0
- package/build/deterministic/AddressSet.js +7 -0
- package/build/deterministic/AddressSet.js.map +1 -0
- package/build/deterministic/CustomMap.d.ts +3 -1
- package/build/deterministic/CustomMap.d.ts.map +1 -0
- package/build/deterministic/CustomMap.js +65 -47
- package/build/deterministic/CustomMap.js.map +1 -0
- package/build/deterministic/DeterministicMap.d.ts +4 -2
- package/build/deterministic/DeterministicMap.d.ts.map +1 -0
- package/build/deterministic/DeterministicMap.js +24 -27
- package/build/deterministic/DeterministicMap.js.map +1 -0
- package/build/deterministic/DeterministicSet.d.ts +3 -1
- package/build/deterministic/DeterministicSet.d.ts.map +1 -0
- package/build/deterministic/DeterministicSet.js +6 -0
- package/build/deterministic/DeterministicSet.js.map +1 -0
- package/build/deterministic/ExtendedAddressMap.d.ts +7 -1
- package/build/deterministic/ExtendedAddressMap.d.ts.map +1 -0
- package/build/deterministic/ExtendedAddressMap.js +18 -2
- package/build/deterministic/ExtendedAddressMap.js.map +1 -0
- package/build/deterministic/FastMap.d.ts +7 -1
- package/build/deterministic/FastMap.d.ts.map +1 -0
- package/build/deterministic/FastMap.js +7 -2
- package/build/deterministic/FastMap.js.map +1 -0
- package/build/ecc/backend.d.ts +13 -0
- package/build/ecc/backend.d.ts.map +1 -0
- package/build/ecc/backend.js +15 -0
- package/build/ecc/backend.js.map +1 -0
- package/build/epoch/ChallengeSolution.d.ts +34 -2
- package/build/epoch/ChallengeSolution.d.ts.map +1 -0
- package/build/epoch/ChallengeSolution.js +52 -0
- package/build/epoch/ChallengeSolution.js.map +1 -0
- package/build/epoch/interfaces/IChallengeSolution.d.ts +14 -13
- package/build/epoch/interfaces/IChallengeSolution.d.ts.map +1 -0
- package/build/epoch/interfaces/IChallengeSolution.js +2 -1
- package/build/epoch/interfaces/IChallengeSolution.js.map +1 -0
- package/build/epoch/validator/EpochValidator.d.ts +38 -8
- package/build/epoch/validator/EpochValidator.d.ts.map +1 -0
- package/build/epoch/validator/EpochValidator.js +45 -19
- package/build/epoch/validator/EpochValidator.js.map +1 -0
- package/build/event/NetEvent.d.ts +1 -0
- package/build/event/NetEvent.d.ts.map +1 -0
- package/build/event/NetEvent.js +3 -0
- package/build/event/NetEvent.js.map +1 -0
- package/build/generators/AddressGenerator.d.ts +4 -3
- package/build/generators/AddressGenerator.d.ts.map +1 -0
- package/build/generators/AddressGenerator.js +10 -3
- package/build/generators/AddressGenerator.js.map +1 -0
- package/build/generators/Features.d.ts +4 -3
- package/build/generators/Features.d.ts.map +1 -0
- package/build/generators/Features.js +1 -0
- package/build/generators/Features.js.map +1 -0
- package/build/generators/Generator.d.ts +47 -11
- package/build/generators/Generator.d.ts.map +1 -0
- package/build/generators/Generator.js +48 -12
- package/build/generators/Generator.js.map +1 -0
- package/build/generators/MLDSAData.d.ts +1 -0
- package/build/generators/MLDSAData.d.ts.map +1 -0
- package/build/generators/MLDSAData.js +1 -0
- package/build/generators/MLDSAData.js.map +1 -0
- package/build/generators/builders/CalldataGenerator.d.ts +27 -6
- package/build/generators/builders/CalldataGenerator.d.ts.map +1 -0
- package/build/generators/builders/CalldataGenerator.js +33 -4
- package/build/generators/builders/CalldataGenerator.js.map +1 -0
- package/build/generators/builders/CustomGenerator.d.ts +13 -3
- package/build/generators/builders/CustomGenerator.d.ts.map +1 -0
- package/build/generators/builders/CustomGenerator.js +11 -0
- package/build/generators/builders/CustomGenerator.js.map +1 -0
- package/build/generators/builders/DeploymentGenerator.d.ts +17 -6
- package/build/generators/builders/DeploymentGenerator.d.ts.map +1 -0
- package/build/generators/builders/DeploymentGenerator.js +18 -2
- package/build/generators/builders/DeploymentGenerator.js.map +1 -0
- package/build/generators/builders/HashCommitmentGenerator.d.ts +166 -14
- package/build/generators/builders/HashCommitmentGenerator.d.ts.map +1 -0
- package/build/generators/builders/HashCommitmentGenerator.js +193 -27
- package/build/generators/builders/HashCommitmentGenerator.js.map +1 -0
- package/build/generators/builders/LegacyCalldataGenerator.d.ts +27 -5
- package/build/generators/builders/LegacyCalldataGenerator.d.ts.map +1 -0
- package/build/generators/builders/LegacyCalldataGenerator.js +35 -5
- package/build/generators/builders/LegacyCalldataGenerator.js.map +1 -0
- package/build/generators/builders/MultiSignGenerator.d.ts +6 -1
- package/build/generators/builders/MultiSignGenerator.d.ts.map +1 -0
- package/build/generators/builders/MultiSignGenerator.js +20 -10
- package/build/generators/builders/MultiSignGenerator.js.map +1 -0
- package/build/generators/builders/P2WDAGenerator.d.ts +44 -6
- package/build/generators/builders/P2WDAGenerator.d.ts.map +1 -0
- package/build/generators/builders/P2WDAGenerator.js +41 -2
- package/build/generators/builders/P2WDAGenerator.js.map +1 -0
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +1 -0
- package/build/index.js.map +1 -0
- package/build/keypair/Address.d.ts +284 -14
- package/build/keypair/Address.d.ts.map +1 -0
- package/build/keypair/Address.js +447 -129
- package/build/keypair/Address.js.map +1 -0
- package/build/keypair/AddressVerificator.d.ts +7 -6
- package/build/keypair/AddressVerificator.d.ts.map +1 -0
- package/build/keypair/AddressVerificator.js +6 -5
- package/build/keypair/AddressVerificator.js.map +1 -0
- package/build/keypair/EcKeyPair.d.ts +185 -23
- package/build/keypair/EcKeyPair.d.ts.map +1 -0
- package/build/keypair/EcKeyPair.js +223 -54
- package/build/keypair/EcKeyPair.js.map +1 -0
- package/build/keypair/MessageSigner.d.ts +18 -17
- package/build/keypair/MessageSigner.d.ts.map +1 -0
- package/build/keypair/MessageSigner.js +34 -25
- package/build/keypair/MessageSigner.js.map +1 -0
- package/build/keypair/Secp256k1PointDeriver.d.ts +55 -0
- package/build/keypair/Secp256k1PointDeriver.d.ts.map +1 -0
- package/build/keypair/Secp256k1PointDeriver.js +66 -0
- package/build/keypair/Secp256k1PointDeriver.js.map +1 -0
- package/build/keypair/Wallet.d.ts +29 -15
- package/build/keypair/Wallet.d.ts.map +1 -0
- package/build/keypair/Wallet.js +48 -14
- package/build/keypair/Wallet.js.map +1 -0
- package/build/keypair/interfaces/IWallet.d.ts +19 -0
- package/build/keypair/interfaces/IWallet.d.ts.map +1 -0
- package/build/keypair/interfaces/IWallet.js +1 -0
- package/build/keypair/interfaces/IWallet.js.map +1 -0
- package/build/metadata/ContractBaseMetadata.d.ts +10 -2
- package/build/metadata/ContractBaseMetadata.d.ts.map +1 -0
- package/build/metadata/ContractBaseMetadata.js +10 -1
- package/build/metadata/ContractBaseMetadata.js.map +1 -0
- package/build/mnemonic/BIPStandard.d.ts +59 -0
- package/build/mnemonic/BIPStandard.d.ts.map +1 -0
- package/build/mnemonic/BIPStandard.js +59 -0
- package/build/mnemonic/BIPStandard.js.map +1 -0
- package/build/mnemonic/Mnemonic.d.ts +16 -4
- package/build/mnemonic/Mnemonic.d.ts.map +1 -0
- package/build/mnemonic/Mnemonic.js +36 -8
- package/build/mnemonic/Mnemonic.js.map +1 -0
- package/build/mnemonic/MnemonicStrength.d.ts +6 -0
- package/build/mnemonic/MnemonicStrength.d.ts.map +1 -0
- package/build/mnemonic/MnemonicStrength.js +6 -0
- package/build/mnemonic/MnemonicStrength.js.map +1 -0
- package/build/network/ChainId.d.ts +1 -0
- package/build/network/ChainId.d.ts.map +1 -0
- package/build/network/ChainId.js +1 -0
- package/build/network/ChainId.js.map +1 -0
- package/build/opnet.d.ts +26 -3
- package/build/opnet.d.ts.map +1 -0
- package/build/opnet.js +23 -0
- package/build/opnet.js.map +1 -0
- package/build/p2wda/P2WDADetector.d.ts +38 -11
- package/build/p2wda/P2WDADetector.d.ts.map +1 -0
- package/build/p2wda/P2WDADetector.js +43 -10
- package/build/p2wda/P2WDADetector.js.map +1 -0
- package/build/polyfill/disposable.d.ts +16 -0
- package/build/polyfill/disposable.d.ts.map +1 -0
- package/build/polyfill/disposable.js +23 -0
- package/build/polyfill/disposable.js.map +1 -0
- package/build/signer/AddressRotation.d.ts +37 -1
- package/build/signer/AddressRotation.d.ts.map +1 -0
- package/build/signer/AddressRotation.js +16 -0
- package/build/signer/AddressRotation.js.map +1 -0
- package/build/signer/IRotationSigner.d.ts +27 -3
- package/build/signer/IRotationSigner.d.ts.map +1 -0
- package/build/signer/IRotationSigner.js +2 -1
- package/build/signer/IRotationSigner.js.map +1 -0
- package/build/signer/ParallelSignerAdapter.d.ts +14 -0
- package/build/signer/ParallelSignerAdapter.d.ts.map +1 -0
- package/build/signer/ParallelSignerAdapter.js +51 -0
- package/build/signer/ParallelSignerAdapter.js.map +1 -0
- package/build/signer/SignerUtils.d.ts +11 -4
- package/build/signer/SignerUtils.d.ts.map +1 -0
- package/build/signer/SignerUtils.js +16 -0
- package/build/signer/SignerUtils.js.map +1 -0
- package/build/signer/TweakedSigner.d.ts +28 -4
- package/build/signer/TweakedSigner.d.ts.map +1 -0
- package/build/signer/TweakedSigner.js +24 -6
- package/build/signer/TweakedSigner.js.map +1 -0
- package/build/transaction/ContractAddress.d.ts +2 -2
- package/build/transaction/ContractAddress.d.ts.map +1 -0
- package/build/transaction/ContractAddress.js +4 -8
- package/build/transaction/ContractAddress.js.map +1 -0
- package/build/transaction/TransactionFactory.d.ts +147 -9
- package/build/transaction/TransactionFactory.d.ts.map +1 -0
- package/build/transaction/TransactionFactory.js +145 -26
- package/build/transaction/TransactionFactory.js.map +1 -0
- package/build/transaction/browser/BrowserSignerBase.d.ts +12 -6
- package/build/transaction/browser/BrowserSignerBase.d.ts.map +1 -0
- package/build/transaction/browser/BrowserSignerBase.js +7 -0
- package/build/transaction/browser/BrowserSignerBase.js.map +1 -0
- package/build/transaction/browser/WalletNetworks.d.ts +1 -0
- package/build/transaction/browser/WalletNetworks.d.ts.map +1 -0
- package/build/transaction/browser/WalletNetworks.js +1 -0
- package/build/transaction/browser/WalletNetworks.js.map +1 -0
- package/build/transaction/browser/Web3Provider.d.ts +30 -3
- package/build/transaction/browser/Web3Provider.d.ts.map +1 -0
- package/build/transaction/browser/Web3Provider.js +1 -0
- package/build/transaction/browser/Web3Provider.js.map +1 -0
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +11 -9
- package/build/transaction/browser/extensions/UnisatSigner.d.ts.map +1 -0
- package/build/transaction/browser/extensions/UnisatSigner.js +27 -17
- package/build/transaction/browser/extensions/UnisatSigner.js.map +1 -0
- package/build/transaction/browser/extensions/XverseSigner.d.ts +10 -8
- package/build/transaction/browser/extensions/XverseSigner.d.ts.map +1 -0
- package/build/transaction/browser/extensions/XverseSigner.js +25 -15
- package/build/transaction/browser/extensions/XverseSigner.js.map +1 -0
- package/build/transaction/browser/types/OPWallet.d.ts +12 -2
- package/build/transaction/browser/types/OPWallet.d.ts.map +1 -0
- package/build/transaction/browser/types/OPWallet.js +4 -0
- package/build/transaction/browser/types/OPWallet.js.map +1 -0
- package/build/transaction/browser/types/Unisat.d.ts +2 -1
- package/build/transaction/browser/types/Unisat.d.ts.map +1 -0
- package/build/transaction/browser/types/Unisat.js +2 -0
- package/build/transaction/browser/types/Unisat.js.map +1 -0
- package/build/transaction/browser/types/Xverse.d.ts +1 -0
- package/build/transaction/browser/types/Xverse.d.ts.map +1 -0
- package/build/transaction/browser/types/Xverse.js +1 -0
- package/build/transaction/browser/types/Xverse.js.map +1 -0
- package/build/transaction/builders/CancelTransaction.d.ts +31 -6
- package/build/transaction/builders/CancelTransaction.d.ts.map +1 -0
- package/build/transaction/builders/CancelTransaction.js +116 -33
- package/build/transaction/builders/CancelTransaction.js.map +1 -0
- package/build/transaction/builders/ChallengeSolutionTransaction.d.ts +1 -0
- package/build/transaction/builders/ChallengeSolutionTransaction.d.ts.map +1 -0
- package/build/transaction/builders/ChallengeSolutionTransaction.js +88 -0
- package/build/transaction/builders/ChallengeSolutionTransaction.js.map +1 -0
- package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts +140 -13
- package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts.map +1 -0
- package/build/transaction/builders/ConsolidatedInteractionTransaction.js +197 -20
- package/build/transaction/builders/ConsolidatedInteractionTransaction.js.map +1 -0
- package/build/transaction/builders/CustomScriptTransaction.d.ts +108 -8
- package/build/transaction/builders/CustomScriptTransaction.d.ts.map +1 -0
- package/build/transaction/builders/CustomScriptTransaction.js +176 -39
- package/build/transaction/builders/CustomScriptTransaction.js.map +1 -0
- package/build/transaction/builders/DeploymentTransaction.d.ts +120 -9
- package/build/transaction/builders/DeploymentTransaction.d.ts.map +1 -0
- package/build/transaction/builders/DeploymentTransaction.js +194 -51
- package/build/transaction/builders/DeploymentTransaction.js.map +1 -0
- package/build/transaction/builders/FundingTransaction.d.ts +5 -4
- package/build/transaction/builders/FundingTransaction.d.ts.map +1 -0
- package/build/transaction/builders/FundingTransaction.js +15 -8
- package/build/transaction/builders/FundingTransaction.js.map +1 -0
- package/build/transaction/builders/InteractionTransaction.d.ts +14 -5
- package/build/transaction/builders/InteractionTransaction.d.ts.map +1 -0
- package/build/transaction/builders/InteractionTransaction.js +18 -5
- package/build/transaction/builders/InteractionTransaction.js.map +1 -0
- package/build/transaction/builders/InteractionTransactionP2WDA.d.ts +58 -7
- package/build/transaction/builders/InteractionTransactionP2WDA.d.ts.map +1 -0
- package/build/transaction/builders/InteractionTransactionP2WDA.js +95 -18
- package/build/transaction/builders/InteractionTransactionP2WDA.js.map +1 -0
- package/build/transaction/builders/MultiSignTransaction.d.ts +126 -17
- package/build/transaction/builders/MultiSignTransaction.d.ts.map +1 -0
- package/build/transaction/builders/MultiSignTransaction.js +201 -76
- package/build/transaction/builders/MultiSignTransaction.js.map +1 -0
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +106 -18
- package/build/transaction/builders/SharedInteractionTransaction.d.ts.map +1 -0
- package/build/transaction/builders/SharedInteractionTransaction.js +158 -40
- package/build/transaction/builders/SharedInteractionTransaction.js.map +1 -0
- package/build/transaction/builders/TransactionBuilder.d.ts +249 -19
- package/build/transaction/builders/TransactionBuilder.d.ts.map +1 -0
- package/build/transaction/builders/TransactionBuilder.js +377 -60
- package/build/transaction/builders/TransactionBuilder.js.map +1 -0
- package/build/transaction/enums/TransactionType.d.ts +1 -0
- package/build/transaction/enums/TransactionType.d.ts.map +1 -0
- package/build/transaction/enums/TransactionType.js +1 -0
- package/build/transaction/enums/TransactionType.js.map +1 -0
- package/build/transaction/interfaces/ICancelTransactionParameters.d.ts +3 -2
- package/build/transaction/interfaces/ICancelTransactionParameters.d.ts.map +1 -0
- package/build/transaction/interfaces/ICancelTransactionParameters.js +1 -0
- package/build/transaction/interfaces/ICancelTransactionParameters.js.map +1 -0
- package/build/transaction/interfaces/IConsolidatedTransactionParameters.d.ts +48 -5
- package/build/transaction/interfaces/IConsolidatedTransactionParameters.d.ts.map +1 -0
- package/build/transaction/interfaces/IConsolidatedTransactionParameters.js +1 -0
- package/build/transaction/interfaces/IConsolidatedTransactionParameters.js.map +1 -0
- package/build/transaction/interfaces/ICustomTransactionParameters.d.ts +7 -5
- package/build/transaction/interfaces/ICustomTransactionParameters.d.ts.map +1 -0
- package/build/transaction/interfaces/ICustomTransactionParameters.js +1 -0
- package/build/transaction/interfaces/ICustomTransactionParameters.js.map +1 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +27 -15
- package/build/transaction/interfaces/ITransactionParameters.d.ts.map +1 -0
- package/build/transaction/interfaces/ITransactionParameters.js +1 -0
- package/build/transaction/interfaces/ITransactionParameters.js.map +1 -0
- package/build/transaction/interfaces/ITransactionResponses.d.ts +3 -2
- package/build/transaction/interfaces/ITransactionResponses.d.ts.map +1 -0
- package/build/transaction/interfaces/ITransactionResponses.js +1 -0
- package/build/transaction/interfaces/ITransactionResponses.js.map +1 -0
- package/build/transaction/interfaces/ITweakedTransactionData.d.ts +21 -8
- package/build/transaction/interfaces/ITweakedTransactionData.d.ts.map +1 -0
- package/build/transaction/interfaces/ITweakedTransactionData.js +1 -0
- package/build/transaction/interfaces/ITweakedTransactionData.js.map +1 -0
- package/build/transaction/interfaces/IWeb3ProviderTypes.d.ts +29 -3
- package/build/transaction/interfaces/IWeb3ProviderTypes.d.ts.map +1 -0
- package/build/transaction/interfaces/IWeb3ProviderTypes.js +2 -1
- package/build/transaction/interfaces/IWeb3ProviderTypes.js.map +1 -0
- package/build/transaction/interfaces/Tap.d.ts +4 -3
- package/build/transaction/interfaces/Tap.d.ts.map +1 -0
- package/build/transaction/interfaces/Tap.js +1 -0
- package/build/transaction/interfaces/Tap.js.map +1 -0
- package/build/transaction/mineable/IP2WSHAddress.d.ts +2 -1
- package/build/transaction/mineable/IP2WSHAddress.d.ts.map +1 -0
- package/build/transaction/mineable/IP2WSHAddress.js +1 -0
- package/build/transaction/mineable/IP2WSHAddress.js.map +1 -0
- package/build/transaction/mineable/TimelockGenerator.d.ts +13 -4
- package/build/transaction/mineable/TimelockGenerator.d.ts.map +1 -0
- package/build/transaction/mineable/TimelockGenerator.js +12 -3
- package/build/transaction/mineable/TimelockGenerator.js.map +1 -0
- package/build/transaction/offline/OfflineTransactionManager.d.ts +193 -12
- package/build/transaction/offline/OfflineTransactionManager.d.ts.map +1 -0
- package/build/transaction/offline/OfflineTransactionManager.js +192 -8
- package/build/transaction/offline/OfflineTransactionManager.js.map +1 -0
- package/build/transaction/offline/TransactionReconstructor.d.ts +56 -6
- package/build/transaction/offline/TransactionReconstructor.d.ts.map +1 -0
- package/build/transaction/offline/TransactionReconstructor.js +111 -75
- package/build/transaction/offline/TransactionReconstructor.js.map +1 -0
- package/build/transaction/offline/TransactionSerializer.d.ts +54 -3
- package/build/transaction/offline/TransactionSerializer.d.ts.map +1 -0
- package/build/transaction/offline/TransactionSerializer.js +206 -95
- package/build/transaction/offline/TransactionSerializer.js.map +1 -0
- package/build/transaction/offline/TransactionStateCapture.d.ts +66 -7
- package/build/transaction/offline/TransactionStateCapture.d.ts.map +1 -0
- package/build/transaction/offline/TransactionStateCapture.js +124 -60
- package/build/transaction/offline/TransactionStateCapture.js.map +1 -0
- package/build/transaction/offline/interfaces/ISerializableState.d.ts +72 -1
- package/build/transaction/offline/interfaces/ISerializableState.d.ts.map +1 -0
- package/build/transaction/offline/interfaces/ISerializableState.js +10 -1
- package/build/transaction/offline/interfaces/ISerializableState.js.map +1 -0
- package/build/transaction/offline/interfaces/ITypeSpecificData.d.ts +77 -1
- package/build/transaction/offline/interfaces/ITypeSpecificData.d.ts.map +1 -0
- package/build/transaction/offline/interfaces/ITypeSpecificData.js +19 -0
- package/build/transaction/offline/interfaces/ITypeSpecificData.js.map +1 -0
- package/build/transaction/psbt/PSBTTypes.d.ts +1 -0
- package/build/transaction/psbt/PSBTTypes.d.ts.map +1 -0
- package/build/transaction/psbt/PSBTTypes.js +1 -0
- package/build/transaction/psbt/PSBTTypes.js.map +1 -0
- package/build/transaction/shared/P2TR_MS.d.ts +11 -2
- package/build/transaction/shared/P2TR_MS.d.ts.map +1 -0
- package/build/transaction/shared/P2TR_MS.js +10 -0
- package/build/transaction/shared/P2TR_MS.js.map +1 -0
- package/build/transaction/shared/TweakedTransaction.d.ts +281 -38
- package/build/transaction/shared/TweakedTransaction.d.ts.map +1 -0
- package/build/transaction/shared/TweakedTransaction.js +576 -114
- package/build/transaction/shared/TweakedTransaction.js.map +1 -0
- package/build/transaction/utils/WitnessUtils.d.ts +7 -1
- package/build/transaction/utils/WitnessUtils.d.ts.map +1 -0
- package/build/transaction/utils/WitnessUtils.js +17 -3
- package/build/transaction/utils/WitnessUtils.js.map +1 -0
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/build/utils/BitcoinUtils.d.ts +19 -0
- package/build/utils/BitcoinUtils.d.ts.map +1 -0
- package/build/utils/BitcoinUtils.js +19 -0
- package/build/utils/BitcoinUtils.js.map +1 -0
- package/build/utils/BufferHelper.d.ts +2 -1
- package/build/utils/BufferHelper.d.ts.map +1 -0
- package/build/utils/BufferHelper.js +38 -32
- package/build/utils/BufferHelper.js.map +1 -0
- package/build/utils/StringToBuffer.d.ts +1 -0
- package/build/utils/StringToBuffer.d.ts.map +1 -0
- package/build/utils/StringToBuffer.js +1 -0
- package/build/utils/StringToBuffer.js.map +1 -0
- package/build/utils/lengths.d.ts +1 -0
- package/build/utils/lengths.d.ts.map +1 -0
- package/build/utils/lengths.js +1 -0
- package/build/utils/lengths.js.map +1 -0
- package/build/utils/types.d.ts +1 -0
- package/build/utils/types.d.ts.map +1 -0
- package/build/utils/types.js +2 -1
- package/build/utils/types.js.map +1 -0
- package/build/utxo/OPNetLimitedProvider.d.ts +39 -3
- package/build/utxo/OPNetLimitedProvider.d.ts.map +1 -0
- package/build/utxo/OPNetLimitedProvider.js +41 -3
- package/build/utxo/OPNetLimitedProvider.js.map +1 -0
- package/build/utxo/interfaces/BroadcastResponse.d.ts +1 -0
- package/build/utxo/interfaces/BroadcastResponse.d.ts.map +1 -0
- package/build/utxo/interfaces/BroadcastResponse.js +1 -0
- package/build/utxo/interfaces/BroadcastResponse.js.map +1 -0
- package/build/utxo/interfaces/IUTXO.d.ts +13 -7
- package/build/utxo/interfaces/IUTXO.d.ts.map +1 -0
- package/build/utxo/interfaces/IUTXO.js +1 -0
- package/build/utxo/interfaces/IUTXO.js.map +1 -0
- package/build/verification/TapscriptVerificator.d.ts +12 -10
- package/build/verification/TapscriptVerificator.d.ts.map +1 -0
- package/build/verification/TapscriptVerificator.js +28 -38
- package/build/verification/TapscriptVerificator.js.map +1 -0
- package/eslint.config.js +0 -1
- package/package.json +16 -39
- package/src/abi/ABICoder.ts +0 -13
- package/src/branded/Branded.ts +5 -0
- package/src/buffer/BinaryReader.ts +7 -7
- package/src/buffer/BinaryWriter.ts +29 -24
- package/src/bytecode/Compressor.ts +1 -1
- package/src/chain/ChainData.ts +34 -27
- package/src/consensus/ConsensusConfig.ts +1 -1
- package/src/consensus/IConsensusConfig.ts +0 -17
- package/src/consensus/metadata/RoswellConsensus.ts +1 -17
- package/src/crypto/crypto-browser.js +3 -4
- package/src/deterministic/AddressMap.ts +5 -1
- package/src/deterministic/AddressSet.ts +5 -1
- package/src/deterministic/CustomMap.ts +6 -2
- package/src/deterministic/DeterministicMap.ts +8 -4
- package/src/deterministic/DeterministicSet.ts +6 -2
- package/src/deterministic/ExtendedAddressMap.ts +9 -4
- package/src/deterministic/FastMap.ts +9 -5
- package/src/ecc/backend.ts +17 -0
- package/src/epoch/ChallengeSolution.ts +3 -3
- package/src/epoch/interfaces/IChallengeSolution.ts +13 -13
- package/src/epoch/validator/EpochValidator.ts +24 -43
- package/src/generators/AddressGenerator.ts +6 -6
- package/src/generators/Features.ts +3 -3
- package/src/generators/Generator.ts +42 -26
- package/src/generators/builders/CalldataGenerator.ts +26 -24
- package/src/generators/builders/CustomGenerator.ts +4 -4
- package/src/generators/builders/DeploymentGenerator.ts +25 -23
- package/src/generators/builders/HashCommitmentGenerator.ts +31 -31
- package/src/generators/builders/LegacyCalldataGenerator.ts +26 -24
- package/src/generators/builders/MultiSignGenerator.ts +12 -12
- package/src/generators/builders/P2WDAGenerator.ts +10 -10
- package/src/keypair/Address.ts +115 -72
- package/src/keypair/AddressVerificator.ts +16 -147
- package/src/keypair/EcKeyPair.ts +109 -118
- package/src/keypair/MessageSigner.ts +70 -150
- package/src/keypair/Wallet.ts +59 -240
- package/src/metadata/ContractBaseMetadata.ts +2 -2
- package/src/mnemonic/Mnemonic.ts +32 -221
- package/src/opnet.ts +12 -6
- package/src/p2wda/P2WDADetector.ts +23 -72
- package/src/polyfill/disposable.ts +29 -0
- package/src/signer/AddressRotation.ts +1 -1
- package/src/signer/IRotationSigner.ts +3 -3
- package/src/signer/ParallelSignerAdapter.ts +59 -0
- package/src/signer/SignerUtils.ts +4 -4
- package/src/signer/TweakedSigner.ts +28 -13
- package/src/transaction/ContractAddress.ts +3 -7
- package/src/transaction/TransactionFactory.ts +28 -50
- package/src/transaction/browser/BrowserSignerBase.ts +12 -6
- package/src/transaction/browser/Web3Provider.ts +3 -3
- package/src/transaction/browser/extensions/UnisatSigner.ts +52 -48
- package/src/transaction/browser/extensions/XverseSigner.ts +55 -38
- package/src/transaction/browser/types/OPWallet.ts +2 -2
- package/src/transaction/browser/types/Unisat.ts +1 -1
- package/src/transaction/builders/CancelTransaction.ts +59 -24
- package/src/transaction/builders/ChallengeSolutionTransaction.ts +3 -3
- package/src/transaction/builders/ConsolidatedInteractionTransaction.ts +39 -34
- package/src/transaction/builders/CustomScriptTransaction.ts +79 -56
- package/src/transaction/builders/DeploymentTransaction.ts +82 -63
- package/src/transaction/builders/FundingTransaction.ts +11 -11
- package/src/transaction/builders/InteractionTransaction.ts +10 -10
- package/src/transaction/builders/InteractionTransactionP2WDA.ts +38 -40
- package/src/transaction/builders/MultiSignTransaction.ts +68 -61
- package/src/transaction/builders/SharedInteractionTransaction.ts +81 -57
- package/src/transaction/builders/TransactionBuilder.ts +101 -79
- package/src/transaction/interfaces/ICancelTransactionParameters.ts +2 -2
- package/src/transaction/interfaces/IConsolidatedTransactionParameters.ts +5 -5
- package/src/transaction/interfaces/ICustomTransactionParameters.ts +5 -5
- package/src/transaction/interfaces/ITransactionParameters.ts +15 -15
- package/src/transaction/interfaces/ITransactionResponses.ts +2 -2
- package/src/transaction/interfaces/ITweakedTransactionData.ts +17 -8
- package/src/transaction/interfaces/IWeb3ProviderTypes.ts +3 -3
- package/src/transaction/interfaces/Tap.ts +3 -3
- package/src/transaction/mineable/IP2WSHAddress.ts +1 -1
- package/src/transaction/mineable/TimelockGenerator.ts +19 -12
- package/src/transaction/offline/OfflineTransactionManager.ts +22 -23
- package/src/transaction/offline/TransactionReconstructor.ts +83 -91
- package/src/transaction/offline/TransactionSerializer.ts +151 -101
- package/src/transaction/offline/TransactionStateCapture.ts +83 -79
- package/src/transaction/offline/interfaces/ISerializableState.ts +1 -1
- package/src/transaction/offline/interfaces/ITypeSpecificData.ts +1 -1
- package/src/transaction/shared/P2TR_MS.ts +4 -4
- package/src/transaction/shared/TweakedTransaction.ts +326 -124
- package/src/transaction/utils/WitnessUtils.ts +18 -9
- package/src/utils/BufferHelper.ts +39 -37
- package/src/utxo/OPNetLimitedProvider.ts +7 -7
- package/src/utxo/interfaces/IUTXO.ts +7 -7
- package/src/verification/TapscriptVerificator.ts +73 -86
- package/test/address-rotation.test.ts +24 -24
- package/test/address.test.ts +12 -12
- package/test/addressmap.test.ts +30 -30
- package/test/binary-reader-writer.test.ts +8 -8
- package/test/browser/offline-transaction.test.ts +2206 -0
- package/test/browser/parallel-signing.test.ts +316 -0
- package/test/browser/setup.ts +11 -0
- package/test/browser/transaction-signing.test.ts +416 -0
- package/test/buffer-helper.test.ts +287 -0
- package/test/derivePath.test.ts +4 -3
- package/test/disposable.test.ts +279 -0
- package/test/fastmap-setall.test.ts +1 -1
- package/test/fastmap.test.ts +3 -3
- package/test/messagesigner-mldsa.test.ts +3 -3
- package/test/messagesigner-schnorr.test.ts +9 -9
- package/test/offline-transaction.test.ts +461 -288
- package/test/old/FastBigIntMap.ts +3 -3
- package/test/oldfastmap.test.ts +6 -6
- package/test/transaction-builders.test.ts +321 -0
- package/tsconfig.base.json +34 -18
- package/tsconfig.browser.json +15 -0
- package/tsconfig.json +3 -8
- package/vite.config.browser.ts +4 -5
- package/vitest.config.browser.ts +68 -0
- package/vitest.config.ts +1 -1
- package/browser/valibot.js +0 -4948
- package/tsconfig.webpack.json +0 -18
package/browser/noble-curves.js
CHANGED
|
@@ -1,2172 +1,256 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return c.concatBytes;
|
|
18
|
-
} }), Object.defineProperty(e, "hexToBytes", { enumerable: !0, get: function() {
|
|
19
|
-
return c.hexToBytes;
|
|
20
|
-
} }), Object.defineProperty(e, "isBytes", { enumerable: !0, get: function() {
|
|
21
|
-
return c.isBytes;
|
|
22
|
-
} }), Object.defineProperty(e, "randomBytes", { enumerable: !0, get: function() {
|
|
23
|
-
return c.randomBytes;
|
|
24
|
-
} }), Object.defineProperty(e, "utf8ToBytes", { enumerable: !0, get: function() {
|
|
25
|
-
return c.utf8ToBytes;
|
|
26
|
-
} });
|
|
27
|
-
const t = /* @__PURE__ */ BigInt(0), l = /* @__PURE__ */ BigInt(1);
|
|
28
|
-
function m(i, o) {
|
|
29
|
-
if (typeof o != "boolean")
|
|
30
|
-
throw new Error(i + " boolean expected, got " + o);
|
|
31
|
-
}
|
|
32
|
-
function g(i, o = "") {
|
|
33
|
-
if (typeof i != "boolean") {
|
|
34
|
-
const h = o && `"${o}"`;
|
|
35
|
-
throw new Error(h + "expected boolean, got type=" + typeof i);
|
|
36
|
-
}
|
|
37
|
-
return i;
|
|
38
|
-
}
|
|
39
|
-
function p(i, o, h = "") {
|
|
40
|
-
const w = (0, r.isBytes)(i), s = i?.length, f = o !== void 0;
|
|
41
|
-
if (!w || f && s !== o) {
|
|
42
|
-
const y = h && `"${h}" `, B = f ? ` of length ${o}` : "", T = w ? `length=${s}` : `type=${typeof i}`;
|
|
43
|
-
throw new Error(y + "expected Uint8Array" + B + ", got " + T);
|
|
44
|
-
}
|
|
45
|
-
return i;
|
|
46
|
-
}
|
|
47
|
-
function v(i) {
|
|
48
|
-
const o = i.toString(16);
|
|
49
|
-
return o.length & 1 ? "0" + o : o;
|
|
50
|
-
}
|
|
51
|
-
function U(i) {
|
|
52
|
-
if (typeof i != "string")
|
|
53
|
-
throw new Error("hex string expected, got " + typeof i);
|
|
54
|
-
return i === "" ? t : BigInt("0x" + i);
|
|
55
|
-
}
|
|
56
|
-
function H(i) {
|
|
57
|
-
return U((0, r.bytesToHex)(i));
|
|
58
|
-
}
|
|
59
|
-
function k(i) {
|
|
60
|
-
return (0, r.abytes)(i), U((0, r.bytesToHex)(Uint8Array.from(i).reverse()));
|
|
61
|
-
}
|
|
62
|
-
function E(i, o) {
|
|
63
|
-
return (0, r.hexToBytes)(i.toString(16).padStart(o * 2, "0"));
|
|
64
|
-
}
|
|
65
|
-
function b(i, o) {
|
|
66
|
-
return E(i, o).reverse();
|
|
67
|
-
}
|
|
68
|
-
function S(i) {
|
|
69
|
-
return (0, r.hexToBytes)(v(i));
|
|
70
|
-
}
|
|
71
|
-
function A(i, o, h) {
|
|
72
|
-
let w;
|
|
73
|
-
if (typeof o == "string")
|
|
74
|
-
try {
|
|
75
|
-
w = (0, r.hexToBytes)(o);
|
|
76
|
-
} catch (f) {
|
|
77
|
-
throw new Error(i + " must be hex string or Uint8Array, cause: " + f);
|
|
78
|
-
}
|
|
79
|
-
else if ((0, r.isBytes)(o))
|
|
80
|
-
w = Uint8Array.from(o);
|
|
81
|
-
else
|
|
82
|
-
throw new Error(i + " must be hex string or Uint8Array");
|
|
83
|
-
const s = w.length;
|
|
84
|
-
if (typeof h == "number" && s !== h)
|
|
85
|
-
throw new Error(i + " of length " + h + " expected, got " + s);
|
|
86
|
-
return w;
|
|
87
|
-
}
|
|
88
|
-
function M(i, o) {
|
|
89
|
-
if (i.length !== o.length)
|
|
90
|
-
return !1;
|
|
91
|
-
let h = 0;
|
|
92
|
-
for (let w = 0; w < i.length; w++)
|
|
93
|
-
h |= i[w] ^ o[w];
|
|
94
|
-
return h === 0;
|
|
95
|
-
}
|
|
96
|
-
function Q(i) {
|
|
97
|
-
return Uint8Array.from(i);
|
|
98
|
-
}
|
|
99
|
-
function F(i) {
|
|
100
|
-
return Uint8Array.from(i, (o, h) => {
|
|
101
|
-
const w = o.charCodeAt(0);
|
|
102
|
-
if (o.length !== 1 || w > 127)
|
|
103
|
-
throw new Error(`string contains non-ASCII character "${i[h]}" with code ${w} at position ${h}`);
|
|
104
|
-
return w;
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
const G = (i) => typeof i == "bigint" && t <= i;
|
|
108
|
-
function se(i, o, h) {
|
|
109
|
-
return G(i) && G(o) && G(h) && o <= i && i < h;
|
|
110
|
-
}
|
|
111
|
-
function ie(i, o, h, w) {
|
|
112
|
-
if (!se(o, h, w))
|
|
113
|
-
throw new Error("expected valid " + i + ": " + h + " <= n < " + w + ", got " + o);
|
|
114
|
-
}
|
|
115
|
-
function j(i) {
|
|
116
|
-
let o;
|
|
117
|
-
for (o = 0; i > t; i >>= l, o += 1)
|
|
118
|
-
;
|
|
119
|
-
return o;
|
|
120
|
-
}
|
|
121
|
-
function O(i, o) {
|
|
122
|
-
return i >> BigInt(o) & l;
|
|
123
|
-
}
|
|
124
|
-
function L(i, o, h) {
|
|
125
|
-
return i | (h ? l : t) << BigInt(o);
|
|
126
|
-
}
|
|
127
|
-
const _ = (i) => (l << BigInt(i)) - l;
|
|
128
|
-
e.bitMask = _;
|
|
129
|
-
function K(i, o, h) {
|
|
130
|
-
if (typeof i != "number" || i < 2)
|
|
131
|
-
throw new Error("hashLen must be a number");
|
|
132
|
-
if (typeof o != "number" || o < 2)
|
|
133
|
-
throw new Error("qByteLen must be a number");
|
|
134
|
-
if (typeof h != "function")
|
|
135
|
-
throw new Error("hmacFn must be a function");
|
|
136
|
-
const w = (C) => new Uint8Array(C), s = (C) => Uint8Array.of(C);
|
|
137
|
-
let f = w(i), y = w(i), B = 0;
|
|
138
|
-
const T = () => {
|
|
139
|
-
f.fill(1), y.fill(0), B = 0;
|
|
140
|
-
}, V = (...C) => h(y, f, ...C), Y = (C = w(0)) => {
|
|
141
|
-
y = V(s(0), C), f = V(), C.length !== 0 && (y = V(s(1), C), f = V());
|
|
142
|
-
}, I = () => {
|
|
143
|
-
if (B++ >= 1e3)
|
|
144
|
-
throw new Error("drbg: tried 1000 values");
|
|
145
|
-
let C = 0;
|
|
146
|
-
const te = [];
|
|
147
|
-
for (; C < o; ) {
|
|
148
|
-
f = V();
|
|
149
|
-
const $ = f.slice();
|
|
150
|
-
te.push($), C += f.length;
|
|
151
|
-
}
|
|
152
|
-
return (0, r.concatBytes)(...te);
|
|
153
|
-
};
|
|
154
|
-
return (C, te) => {
|
|
155
|
-
T(), Y(C);
|
|
156
|
-
let $;
|
|
157
|
-
for (; !($ = te(I())); )
|
|
158
|
-
Y();
|
|
159
|
-
return T(), $;
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const W = {
|
|
163
|
-
bigint: (i) => typeof i == "bigint",
|
|
164
|
-
function: (i) => typeof i == "function",
|
|
165
|
-
boolean: (i) => typeof i == "boolean",
|
|
166
|
-
string: (i) => typeof i == "string",
|
|
167
|
-
stringOrUint8Array: (i) => typeof i == "string" || (0, r.isBytes)(i),
|
|
168
|
-
isSafeInteger: (i) => Number.isSafeInteger(i),
|
|
169
|
-
array: (i) => Array.isArray(i),
|
|
170
|
-
field: (i, o) => o.Fp.isValid(i),
|
|
171
|
-
hash: (i) => typeof i == "function" && Number.isSafeInteger(i.outputLen)
|
|
172
|
-
};
|
|
173
|
-
function z(i, o, h = {}) {
|
|
174
|
-
const w = (s, f, y) => {
|
|
175
|
-
const B = W[f];
|
|
176
|
-
if (typeof B != "function")
|
|
177
|
-
throw new Error("invalid validator function");
|
|
178
|
-
const T = i[s];
|
|
179
|
-
if (!(y && T === void 0) && !B(T, i))
|
|
180
|
-
throw new Error("param " + String(s) + " is invalid. Expected " + f + ", got " + T);
|
|
181
|
-
};
|
|
182
|
-
for (const [s, f] of Object.entries(o))
|
|
183
|
-
w(s, f, !1);
|
|
184
|
-
for (const [s, f] of Object.entries(h))
|
|
185
|
-
w(s, f, !0);
|
|
186
|
-
return i;
|
|
187
|
-
}
|
|
188
|
-
function d(i) {
|
|
189
|
-
return typeof i == "function" && Number.isSafeInteger(i.outputLen);
|
|
190
|
-
}
|
|
191
|
-
function u(i, o, h = {}) {
|
|
192
|
-
if (!i || typeof i != "object")
|
|
193
|
-
throw new Error("expected valid options object");
|
|
194
|
-
function w(s, f, y) {
|
|
195
|
-
const B = i[s];
|
|
196
|
-
if (y && B === void 0)
|
|
197
|
-
return;
|
|
198
|
-
const T = typeof B;
|
|
199
|
-
if (T !== f || B === null)
|
|
200
|
-
throw new Error(`param "${s}" is invalid: expected ${f}, got ${T}`);
|
|
201
|
-
}
|
|
202
|
-
Object.entries(o).forEach(([s, f]) => w(s, f, !1)), Object.entries(h).forEach(([s, f]) => w(s, f, !0));
|
|
203
|
-
}
|
|
204
|
-
const n = () => {
|
|
205
|
-
throw new Error("not implemented");
|
|
206
|
-
};
|
|
207
|
-
e.notImplemented = n;
|
|
208
|
-
function a(i) {
|
|
209
|
-
const o = /* @__PURE__ */ new WeakMap();
|
|
210
|
-
return (h, ...w) => {
|
|
211
|
-
const s = o.get(h);
|
|
212
|
-
if (s !== void 0)
|
|
213
|
-
return s;
|
|
214
|
-
const f = i(h, ...w);
|
|
215
|
-
return o.set(h, f), f;
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
})(rt)), rt;
|
|
219
|
-
}
|
|
220
|
-
var Oe = {}, he = {}, St;
|
|
221
|
-
function $e() {
|
|
222
|
-
if (St) return he;
|
|
223
|
-
St = 1, Object.defineProperty(he, "__esModule", { value: !0 }), he.isNegativeLE = void 0, he.mod = k, he.pow = E, he.pow2 = b, he.invert = S, he.tonelliShanks = G, he.FpSqrt = se, he.validateField = O, he.FpPow = L, he.FpInvertBatch = _, he.FpDiv = K, he.FpLegendre = W, he.FpIsSquare = z, he.nLength = d, he.Field = u, he.FpSqrtOdd = n, he.FpSqrtEven = a, he.hashToPrivateScalar = i, he.getFieldBytesLength = o, he.getMinHashLength = h, he.mapHashToField = w;
|
|
224
|
-
const e = /* @__PURE__ */ Ce(), r = BigInt(0), c = BigInt(1), t = /* @__PURE__ */ BigInt(2), l = /* @__PURE__ */ BigInt(3), m = /* @__PURE__ */ BigInt(4), g = /* @__PURE__ */ BigInt(5), p = /* @__PURE__ */ BigInt(7), v = /* @__PURE__ */ BigInt(8), U = /* @__PURE__ */ BigInt(9), H = /* @__PURE__ */ BigInt(16);
|
|
225
|
-
function k(s, f) {
|
|
226
|
-
const y = s % f;
|
|
227
|
-
return y >= r ? y : f + y;
|
|
228
|
-
}
|
|
229
|
-
function E(s, f, y) {
|
|
230
|
-
return L(u(y), s, f);
|
|
231
|
-
}
|
|
232
|
-
function b(s, f, y) {
|
|
233
|
-
let B = s;
|
|
234
|
-
for (; f-- > r; )
|
|
235
|
-
B *= B, B %= y;
|
|
236
|
-
return B;
|
|
237
|
-
}
|
|
238
|
-
function S(s, f) {
|
|
239
|
-
if (s === r)
|
|
240
|
-
throw new Error("invert: expected non-zero number");
|
|
241
|
-
if (f <= r)
|
|
242
|
-
throw new Error("invert: expected positive modulus, got " + f);
|
|
243
|
-
let y = k(s, f), B = f, T = r, V = c;
|
|
244
|
-
for (; y !== r; ) {
|
|
245
|
-
const I = B / y, q = B % y, C = T - V * I;
|
|
246
|
-
B = y, y = q, T = V, V = C;
|
|
247
|
-
}
|
|
248
|
-
if (B !== c)
|
|
249
|
-
throw new Error("invert: does not exist");
|
|
250
|
-
return k(T, f);
|
|
251
|
-
}
|
|
252
|
-
function A(s, f, y) {
|
|
253
|
-
if (!s.eql(s.sqr(f), y))
|
|
254
|
-
throw new Error("Cannot find square root");
|
|
255
|
-
}
|
|
256
|
-
function M(s, f) {
|
|
257
|
-
const y = (s.ORDER + c) / m, B = s.pow(f, y);
|
|
258
|
-
return A(s, B, f), B;
|
|
259
|
-
}
|
|
260
|
-
function Q(s, f) {
|
|
261
|
-
const y = (s.ORDER - g) / v, B = s.mul(f, t), T = s.pow(B, y), V = s.mul(f, T), Y = s.mul(s.mul(V, t), T), I = s.mul(V, s.sub(Y, s.ONE));
|
|
262
|
-
return A(s, I, f), I;
|
|
263
|
-
}
|
|
264
|
-
function F(s) {
|
|
265
|
-
const f = u(s), y = G(s), B = y(f, f.neg(f.ONE)), T = y(f, B), V = y(f, f.neg(B)), Y = (s + p) / H;
|
|
266
|
-
return (I, q) => {
|
|
267
|
-
let C = I.pow(q, Y), te = I.mul(C, B);
|
|
268
|
-
const $ = I.mul(C, T), x = I.mul(C, V), X = I.eql(I.sqr(te), q), ae = I.eql(I.sqr($), q);
|
|
269
|
-
C = I.cmov(C, te, X), te = I.cmov(x, $, ae);
|
|
270
|
-
const ye = I.eql(I.sqr(te), q), pe = I.cmov(C, te, ye);
|
|
271
|
-
return A(I, pe, q), pe;
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
function G(s) {
|
|
275
|
-
if (s < l)
|
|
276
|
-
throw new Error("sqrt is not defined for small field");
|
|
277
|
-
let f = s - c, y = 0;
|
|
278
|
-
for (; f % t === r; )
|
|
279
|
-
f /= t, y++;
|
|
280
|
-
let B = t;
|
|
281
|
-
const T = u(s);
|
|
282
|
-
for (; W(T, B) === 1; )
|
|
283
|
-
if (B++ > 1e3)
|
|
284
|
-
throw new Error("Cannot find square root: probably non-prime P");
|
|
285
|
-
if (y === 1)
|
|
286
|
-
return M;
|
|
287
|
-
let V = T.pow(B, f);
|
|
288
|
-
const Y = (f + c) / t;
|
|
289
|
-
return function(q, C) {
|
|
290
|
-
if (q.is0(C))
|
|
291
|
-
return C;
|
|
292
|
-
if (W(q, C) !== 1)
|
|
293
|
-
throw new Error("Cannot find square root");
|
|
294
|
-
let te = y, $ = q.mul(q.ONE, V), x = q.pow(C, f), X = q.pow(C, Y);
|
|
295
|
-
for (; !q.eql(x, q.ONE); ) {
|
|
296
|
-
if (q.is0(x))
|
|
297
|
-
return q.ZERO;
|
|
298
|
-
let ae = 1, ye = q.sqr(x);
|
|
299
|
-
for (; !q.eql(ye, q.ONE); )
|
|
300
|
-
if (ae++, ye = q.sqr(ye), ae === te)
|
|
301
|
-
throw new Error("Cannot find square root");
|
|
302
|
-
const pe = c << BigInt(te - ae - 1), ve = q.pow($, pe);
|
|
303
|
-
te = ae, $ = q.sqr(ve), x = q.mul(x, $), X = q.mul(X, ve);
|
|
304
|
-
}
|
|
305
|
-
return X;
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
function se(s) {
|
|
309
|
-
return s % m === l ? M : s % v === g ? Q : s % H === U ? F(s) : G(s);
|
|
310
|
-
}
|
|
311
|
-
const ie = (s, f) => (k(s, f) & c) === c;
|
|
312
|
-
he.isNegativeLE = ie;
|
|
313
|
-
const j = [
|
|
314
|
-
"create",
|
|
315
|
-
"isValid",
|
|
316
|
-
"is0",
|
|
317
|
-
"neg",
|
|
318
|
-
"inv",
|
|
319
|
-
"sqrt",
|
|
320
|
-
"sqr",
|
|
321
|
-
"eql",
|
|
322
|
-
"add",
|
|
323
|
-
"sub",
|
|
324
|
-
"mul",
|
|
325
|
-
"pow",
|
|
326
|
-
"div",
|
|
327
|
-
"addN",
|
|
328
|
-
"subN",
|
|
329
|
-
"mulN",
|
|
330
|
-
"sqrN"
|
|
331
|
-
];
|
|
332
|
-
function O(s) {
|
|
333
|
-
const f = {
|
|
334
|
-
ORDER: "bigint",
|
|
335
|
-
MASK: "bigint",
|
|
336
|
-
BYTES: "number",
|
|
337
|
-
BITS: "number"
|
|
338
|
-
}, y = j.reduce((B, T) => (B[T] = "function", B), f);
|
|
339
|
-
return (0, e._validateObject)(s, y), s;
|
|
340
|
-
}
|
|
341
|
-
function L(s, f, y) {
|
|
342
|
-
if (y < r)
|
|
343
|
-
throw new Error("invalid exponent, negatives unsupported");
|
|
344
|
-
if (y === r)
|
|
345
|
-
return s.ONE;
|
|
346
|
-
if (y === c)
|
|
347
|
-
return f;
|
|
348
|
-
let B = s.ONE, T = f;
|
|
349
|
-
for (; y > r; )
|
|
350
|
-
y & c && (B = s.mul(B, T)), T = s.sqr(T), y >>= c;
|
|
351
|
-
return B;
|
|
352
|
-
}
|
|
353
|
-
function _(s, f, y = !1) {
|
|
354
|
-
const B = new Array(f.length).fill(y ? s.ZERO : void 0), T = f.reduce((Y, I, q) => s.is0(I) ? Y : (B[q] = Y, s.mul(Y, I)), s.ONE), V = s.inv(T);
|
|
355
|
-
return f.reduceRight((Y, I, q) => s.is0(I) ? Y : (B[q] = s.mul(Y, B[q]), s.mul(Y, I)), V), B;
|
|
356
|
-
}
|
|
357
|
-
function K(s, f, y) {
|
|
358
|
-
return s.mul(f, typeof y == "bigint" ? S(y, s.ORDER) : s.inv(y));
|
|
359
|
-
}
|
|
360
|
-
function W(s, f) {
|
|
361
|
-
const y = (s.ORDER - c) / t, B = s.pow(f, y), T = s.eql(B, s.ONE), V = s.eql(B, s.ZERO), Y = s.eql(B, s.neg(s.ONE));
|
|
362
|
-
if (!T && !V && !Y)
|
|
363
|
-
throw new Error("invalid Legendre symbol result");
|
|
364
|
-
return T ? 1 : V ? 0 : -1;
|
|
365
|
-
}
|
|
366
|
-
function z(s, f) {
|
|
367
|
-
return W(s, f) === 1;
|
|
368
|
-
}
|
|
369
|
-
function d(s, f) {
|
|
370
|
-
f !== void 0 && (0, e.anumber)(f);
|
|
371
|
-
const y = f !== void 0 ? f : s.toString(2).length, B = Math.ceil(y / 8);
|
|
372
|
-
return { nBitLength: y, nByteLength: B };
|
|
373
|
-
}
|
|
374
|
-
function u(s, f, y = !1, B = {}) {
|
|
375
|
-
if (s <= r)
|
|
376
|
-
throw new Error("invalid field: expected ORDER > 0, got " + s);
|
|
377
|
-
let T, V, Y = !1, I;
|
|
378
|
-
if (typeof f == "object" && f != null) {
|
|
379
|
-
if (B.sqrt || y)
|
|
380
|
-
throw new Error("cannot specify opts in two arguments");
|
|
381
|
-
const x = f;
|
|
382
|
-
x.BITS && (T = x.BITS), x.sqrt && (V = x.sqrt), typeof x.isLE == "boolean" && (y = x.isLE), typeof x.modFromBytes == "boolean" && (Y = x.modFromBytes), I = x.allowedLengths;
|
|
383
|
-
} else
|
|
384
|
-
typeof f == "number" && (T = f), B.sqrt && (V = B.sqrt);
|
|
385
|
-
const { nBitLength: q, nByteLength: C } = d(s, T);
|
|
386
|
-
if (C > 2048)
|
|
387
|
-
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
388
|
-
let te;
|
|
389
|
-
const $ = Object.freeze({
|
|
390
|
-
ORDER: s,
|
|
391
|
-
isLE: y,
|
|
392
|
-
BITS: q,
|
|
393
|
-
BYTES: C,
|
|
394
|
-
MASK: (0, e.bitMask)(q),
|
|
395
|
-
ZERO: r,
|
|
396
|
-
ONE: c,
|
|
397
|
-
allowedLengths: I,
|
|
398
|
-
create: (x) => k(x, s),
|
|
399
|
-
isValid: (x) => {
|
|
400
|
-
if (typeof x != "bigint")
|
|
401
|
-
throw new Error("invalid field element: expected bigint, got " + typeof x);
|
|
402
|
-
return r <= x && x < s;
|
|
403
|
-
},
|
|
404
|
-
is0: (x) => x === r,
|
|
405
|
-
// is valid and invertible
|
|
406
|
-
isValidNot0: (x) => !$.is0(x) && $.isValid(x),
|
|
407
|
-
isOdd: (x) => (x & c) === c,
|
|
408
|
-
neg: (x) => k(-x, s),
|
|
409
|
-
eql: (x, X) => x === X,
|
|
410
|
-
sqr: (x) => k(x * x, s),
|
|
411
|
-
add: (x, X) => k(x + X, s),
|
|
412
|
-
sub: (x, X) => k(x - X, s),
|
|
413
|
-
mul: (x, X) => k(x * X, s),
|
|
414
|
-
pow: (x, X) => L($, x, X),
|
|
415
|
-
div: (x, X) => k(x * S(X, s), s),
|
|
416
|
-
// Same as above, but doesn't normalize
|
|
417
|
-
sqrN: (x) => x * x,
|
|
418
|
-
addN: (x, X) => x + X,
|
|
419
|
-
subN: (x, X) => x - X,
|
|
420
|
-
mulN: (x, X) => x * X,
|
|
421
|
-
inv: (x) => S(x, s),
|
|
422
|
-
sqrt: V || ((x) => (te || (te = se(s)), te($, x))),
|
|
423
|
-
toBytes: (x) => y ? (0, e.numberToBytesLE)(x, C) : (0, e.numberToBytesBE)(x, C),
|
|
424
|
-
fromBytes: (x, X = !0) => {
|
|
425
|
-
if (I) {
|
|
426
|
-
if (!I.includes(x.length) || x.length > C)
|
|
427
|
-
throw new Error("Field.fromBytes: expected " + I + " bytes, got " + x.length);
|
|
428
|
-
const ye = new Uint8Array(C);
|
|
429
|
-
ye.set(x, y ? 0 : ye.length - x.length), x = ye;
|
|
430
|
-
}
|
|
431
|
-
if (x.length !== C)
|
|
432
|
-
throw new Error("Field.fromBytes: expected " + C + " bytes, got " + x.length);
|
|
433
|
-
let ae = y ? (0, e.bytesToNumberLE)(x) : (0, e.bytesToNumberBE)(x);
|
|
434
|
-
if (Y && (ae = k(ae, s)), !X && !$.isValid(ae))
|
|
435
|
-
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
436
|
-
return ae;
|
|
437
|
-
},
|
|
438
|
-
// TODO: we don't need it here, move out to separate fn
|
|
439
|
-
invertBatch: (x) => _($, x),
|
|
440
|
-
// We can't move this out because Fp6, Fp12 implement it
|
|
441
|
-
// and it's unclear what to return in there.
|
|
442
|
-
cmov: (x, X, ae) => ae ? X : x
|
|
443
|
-
});
|
|
444
|
-
return Object.freeze($);
|
|
445
|
-
}
|
|
446
|
-
function n(s, f) {
|
|
447
|
-
if (!s.isOdd)
|
|
448
|
-
throw new Error("Field doesn't have isOdd");
|
|
449
|
-
const y = s.sqrt(f);
|
|
450
|
-
return s.isOdd(y) ? y : s.neg(y);
|
|
451
|
-
}
|
|
452
|
-
function a(s, f) {
|
|
453
|
-
if (!s.isOdd)
|
|
454
|
-
throw new Error("Field doesn't have isOdd");
|
|
455
|
-
const y = s.sqrt(f);
|
|
456
|
-
return s.isOdd(y) ? s.neg(y) : y;
|
|
457
|
-
}
|
|
458
|
-
function i(s, f, y = !1) {
|
|
459
|
-
s = (0, e.ensureBytes)("privateHash", s);
|
|
460
|
-
const B = s.length, T = d(f).nByteLength + 8;
|
|
461
|
-
if (T < 24 || B < T || B > 1024)
|
|
462
|
-
throw new Error("hashToPrivateScalar: expected " + T + "-1024 bytes of input, got " + B);
|
|
463
|
-
const V = y ? (0, e.bytesToNumberLE)(s) : (0, e.bytesToNumberBE)(s);
|
|
464
|
-
return k(V, f - c) + c;
|
|
465
|
-
}
|
|
466
|
-
function o(s) {
|
|
467
|
-
if (typeof s != "bigint")
|
|
468
|
-
throw new Error("field order must be bigint");
|
|
469
|
-
const f = s.toString(2).length;
|
|
470
|
-
return Math.ceil(f / 8);
|
|
471
|
-
}
|
|
472
|
-
function h(s) {
|
|
473
|
-
const f = o(s);
|
|
474
|
-
return f + Math.ceil(f / 2);
|
|
475
|
-
}
|
|
476
|
-
function w(s, f, y = !1) {
|
|
477
|
-
const B = s.length, T = o(f), V = h(f);
|
|
478
|
-
if (B < 16 || B < V || B > 1024)
|
|
479
|
-
throw new Error("expected " + V + "-1024 bytes of input, got " + B);
|
|
480
|
-
const Y = y ? (0, e.bytesToNumberLE)(s) : (0, e.bytesToNumberBE)(s), I = k(Y, f - c) + c;
|
|
481
|
-
return y ? (0, e.numberToBytesLE)(I, T) : (0, e.numberToBytesBE)(I, T);
|
|
482
|
-
}
|
|
483
|
-
return he;
|
|
484
|
-
}
|
|
485
|
-
var Tt;
|
|
486
|
-
function gn() {
|
|
487
|
-
if (Tt) return Oe;
|
|
488
|
-
Tt = 1, Object.defineProperty(Oe, "__esModule", { value: !0 }), Oe.wNAF = void 0, Oe.negateCt = l, Oe.normalizeZ = m, Oe.mulEndoUnsafe = M, Oe.pippenger = Q, Oe.precomputeMSMUnsafe = F, Oe.validateBasic = G, Oe._createCurveFields = ie;
|
|
489
|
-
const e = /* @__PURE__ */ Ce(), r = /* @__PURE__ */ $e(), c = BigInt(0), t = BigInt(1);
|
|
490
|
-
function l(j, O) {
|
|
491
|
-
const L = O.negate();
|
|
492
|
-
return j ? L : O;
|
|
493
|
-
}
|
|
494
|
-
function m(j, O) {
|
|
495
|
-
const L = (0, r.FpInvertBatch)(j.Fp, O.map((_) => _.Z));
|
|
496
|
-
return O.map((_, K) => j.fromAffine(_.toAffine(L[K])));
|
|
497
|
-
}
|
|
498
|
-
function g(j, O) {
|
|
499
|
-
if (!Number.isSafeInteger(j) || j <= 0 || j > O)
|
|
500
|
-
throw new Error("invalid window size, expected [1.." + O + "], got W=" + j);
|
|
501
|
-
}
|
|
502
|
-
function p(j, O) {
|
|
503
|
-
g(j, O);
|
|
504
|
-
const L = Math.ceil(O / j) + 1, _ = 2 ** (j - 1), K = 2 ** j, W = (0, e.bitMask)(j), z = BigInt(j);
|
|
505
|
-
return { windows: L, windowSize: _, mask: W, maxNumber: K, shiftBy: z };
|
|
506
|
-
}
|
|
507
|
-
function v(j, O, L) {
|
|
508
|
-
const { windowSize: _, mask: K, maxNumber: W, shiftBy: z } = L;
|
|
509
|
-
let d = Number(j & K), u = j >> z;
|
|
510
|
-
d > _ && (d -= W, u += t);
|
|
511
|
-
const n = O * _, a = n + Math.abs(d) - 1, i = d === 0, o = d < 0, h = O % 2 !== 0;
|
|
512
|
-
return { nextN: u, offset: a, isZero: i, isNeg: o, isNegF: h, offsetF: n };
|
|
513
|
-
}
|
|
514
|
-
function U(j, O) {
|
|
515
|
-
if (!Array.isArray(j))
|
|
516
|
-
throw new Error("array expected");
|
|
517
|
-
j.forEach((L, _) => {
|
|
518
|
-
if (!(L instanceof O))
|
|
519
|
-
throw new Error("invalid point at index " + _);
|
|
520
|
-
});
|
|
521
|
-
}
|
|
522
|
-
function H(j, O) {
|
|
523
|
-
if (!Array.isArray(j))
|
|
524
|
-
throw new Error("array of scalars expected");
|
|
525
|
-
j.forEach((L, _) => {
|
|
526
|
-
if (!O.isValid(L))
|
|
527
|
-
throw new Error("invalid scalar at index " + _);
|
|
528
|
-
});
|
|
529
|
-
}
|
|
530
|
-
const k = /* @__PURE__ */ new WeakMap(), E = /* @__PURE__ */ new WeakMap();
|
|
531
|
-
function b(j) {
|
|
532
|
-
return E.get(j) || 1;
|
|
533
|
-
}
|
|
534
|
-
function S(j) {
|
|
535
|
-
if (j !== c)
|
|
536
|
-
throw new Error("invalid wNAF");
|
|
537
|
-
}
|
|
538
|
-
class A {
|
|
539
|
-
// Parametrized with a given Point class (not individual point)
|
|
540
|
-
constructor(O, L) {
|
|
541
|
-
this.BASE = O.BASE, this.ZERO = O.ZERO, this.Fn = O.Fn, this.bits = L;
|
|
542
|
-
}
|
|
543
|
-
// non-const time multiplication ladder
|
|
544
|
-
_unsafeLadder(O, L, _ = this.ZERO) {
|
|
545
|
-
let K = O;
|
|
546
|
-
for (; L > c; )
|
|
547
|
-
L & t && (_ = _.add(K)), K = K.double(), L >>= t;
|
|
548
|
-
return _;
|
|
549
|
-
}
|
|
550
|
-
/**
|
|
551
|
-
* Creates a wNAF precomputation window. Used for caching.
|
|
552
|
-
* Default window size is set by `utils.precompute()` and is equal to 8.
|
|
553
|
-
* Number of precomputed points depends on the curve size:
|
|
554
|
-
* 2^(𝑊−1) * (Math.ceil(𝑛 / 𝑊) + 1), where:
|
|
555
|
-
* - 𝑊 is the window size
|
|
556
|
-
* - 𝑛 is the bitlength of the curve order.
|
|
557
|
-
* For a 256-bit curve and window size 8, the number of precomputed points is 128 * 33 = 4224.
|
|
558
|
-
* @param point Point instance
|
|
559
|
-
* @param W window size
|
|
560
|
-
* @returns precomputed point tables flattened to a single array
|
|
561
|
-
*/
|
|
562
|
-
precomputeWindow(O, L) {
|
|
563
|
-
const { windows: _, windowSize: K } = p(L, this.bits), W = [];
|
|
564
|
-
let z = O, d = z;
|
|
565
|
-
for (let u = 0; u < _; u++) {
|
|
566
|
-
d = z, W.push(d);
|
|
567
|
-
for (let n = 1; n < K; n++)
|
|
568
|
-
d = d.add(z), W.push(d);
|
|
569
|
-
z = d.double();
|
|
570
|
-
}
|
|
571
|
-
return W;
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
575
|
-
* More compact implementation:
|
|
576
|
-
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
577
|
-
* @returns real and fake (for const-time) points
|
|
578
|
-
*/
|
|
579
|
-
wNAF(O, L, _) {
|
|
580
|
-
if (!this.Fn.isValid(_))
|
|
581
|
-
throw new Error("invalid scalar");
|
|
582
|
-
let K = this.ZERO, W = this.BASE;
|
|
583
|
-
const z = p(O, this.bits);
|
|
584
|
-
for (let d = 0; d < z.windows; d++) {
|
|
585
|
-
const { nextN: u, offset: n, isZero: a, isNeg: i, isNegF: o, offsetF: h } = v(_, d, z);
|
|
586
|
-
_ = u, a ? W = W.add(l(o, L[h])) : K = K.add(l(i, L[n]));
|
|
587
|
-
}
|
|
588
|
-
return S(_), { p: K, f: W };
|
|
589
|
-
}
|
|
590
|
-
/**
|
|
591
|
-
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
592
|
-
* @param acc accumulator point to add result of multiplication
|
|
593
|
-
* @returns point
|
|
594
|
-
*/
|
|
595
|
-
wNAFUnsafe(O, L, _, K = this.ZERO) {
|
|
596
|
-
const W = p(O, this.bits);
|
|
597
|
-
for (let z = 0; z < W.windows && _ !== c; z++) {
|
|
598
|
-
const { nextN: d, offset: u, isZero: n, isNeg: a } = v(_, z, W);
|
|
599
|
-
if (_ = d, !n) {
|
|
600
|
-
const i = L[u];
|
|
601
|
-
K = K.add(a ? i.negate() : i);
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
return S(_), K;
|
|
605
|
-
}
|
|
606
|
-
getPrecomputes(O, L, _) {
|
|
607
|
-
let K = k.get(L);
|
|
608
|
-
return K || (K = this.precomputeWindow(L, O), O !== 1 && (typeof _ == "function" && (K = _(K)), k.set(L, K))), K;
|
|
609
|
-
}
|
|
610
|
-
cached(O, L, _) {
|
|
611
|
-
const K = b(O);
|
|
612
|
-
return this.wNAF(K, this.getPrecomputes(K, O, _), L);
|
|
613
|
-
}
|
|
614
|
-
unsafe(O, L, _, K) {
|
|
615
|
-
const W = b(O);
|
|
616
|
-
return W === 1 ? this._unsafeLadder(O, L, K) : this.wNAFUnsafe(W, this.getPrecomputes(W, O, _), L, K);
|
|
617
|
-
}
|
|
618
|
-
// We calculate precomputes for elliptic curve point multiplication
|
|
619
|
-
// using windowed method. This specifies window size and
|
|
620
|
-
// stores precomputed values. Usually only base point would be precomputed.
|
|
621
|
-
createCache(O, L) {
|
|
622
|
-
g(L, this.bits), E.set(O, L), k.delete(O);
|
|
623
|
-
}
|
|
624
|
-
hasCache(O) {
|
|
625
|
-
return b(O) !== 1;
|
|
626
|
-
}
|
|
627
|
-
}
|
|
628
|
-
Oe.wNAF = A;
|
|
629
|
-
function M(j, O, L, _) {
|
|
630
|
-
let K = O, W = j.ZERO, z = j.ZERO;
|
|
631
|
-
for (; L > c || _ > c; )
|
|
632
|
-
L & t && (W = W.add(K)), _ & t && (z = z.add(K)), K = K.double(), L >>= t, _ >>= t;
|
|
633
|
-
return { p1: W, p2: z };
|
|
634
|
-
}
|
|
635
|
-
function Q(j, O, L, _) {
|
|
636
|
-
U(L, j), H(_, O);
|
|
637
|
-
const K = L.length, W = _.length;
|
|
638
|
-
if (K !== W)
|
|
639
|
-
throw new Error("arrays of points and scalars must have equal length");
|
|
640
|
-
const z = j.ZERO, d = (0, e.bitLen)(BigInt(K));
|
|
641
|
-
let u = 1;
|
|
642
|
-
d > 12 ? u = d - 3 : d > 4 ? u = d - 2 : d > 0 && (u = 2);
|
|
643
|
-
const n = (0, e.bitMask)(u), a = new Array(Number(n) + 1).fill(z), i = Math.floor((O.BITS - 1) / u) * u;
|
|
644
|
-
let o = z;
|
|
645
|
-
for (let h = i; h >= 0; h -= u) {
|
|
646
|
-
a.fill(z);
|
|
647
|
-
for (let s = 0; s < W; s++) {
|
|
648
|
-
const f = _[s], y = Number(f >> BigInt(h) & n);
|
|
649
|
-
a[y] = a[y].add(L[s]);
|
|
650
|
-
}
|
|
651
|
-
let w = z;
|
|
652
|
-
for (let s = a.length - 1, f = z; s > 0; s--)
|
|
653
|
-
f = f.add(a[s]), w = w.add(f);
|
|
654
|
-
if (o = o.add(w), h !== 0)
|
|
655
|
-
for (let s = 0; s < u; s++)
|
|
656
|
-
o = o.double();
|
|
657
|
-
}
|
|
658
|
-
return o;
|
|
659
|
-
}
|
|
660
|
-
function F(j, O, L, _) {
|
|
661
|
-
g(_, O.BITS), U(L, j);
|
|
662
|
-
const K = j.ZERO, W = 2 ** _ - 1, z = Math.ceil(O.BITS / _), d = (0, e.bitMask)(_), u = L.map((n) => {
|
|
663
|
-
const a = [];
|
|
664
|
-
for (let i = 0, o = n; i < W; i++)
|
|
665
|
-
a.push(o), o = o.add(n);
|
|
666
|
-
return a;
|
|
667
|
-
});
|
|
668
|
-
return (n) => {
|
|
669
|
-
if (H(n, O), n.length > L.length)
|
|
670
|
-
throw new Error("array of scalars must be smaller than array of points");
|
|
671
|
-
let a = K;
|
|
672
|
-
for (let i = 0; i < z; i++) {
|
|
673
|
-
if (a !== K)
|
|
674
|
-
for (let h = 0; h < _; h++)
|
|
675
|
-
a = a.double();
|
|
676
|
-
const o = BigInt(z * _ - (i + 1) * _);
|
|
677
|
-
for (let h = 0; h < n.length; h++) {
|
|
678
|
-
const w = n[h], s = Number(w >> o & d);
|
|
679
|
-
s && (a = a.add(u[h][s - 1]));
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
return a;
|
|
683
|
-
};
|
|
684
|
-
}
|
|
685
|
-
function G(j) {
|
|
686
|
-
return (0, r.validateField)(j.Fp), (0, e.validateObject)(j, {
|
|
687
|
-
n: "bigint",
|
|
688
|
-
h: "bigint",
|
|
689
|
-
Gx: "field",
|
|
690
|
-
Gy: "field"
|
|
691
|
-
}, {
|
|
692
|
-
nBitLength: "isSafeInteger",
|
|
693
|
-
nByteLength: "isSafeInteger"
|
|
694
|
-
}), Object.freeze({
|
|
695
|
-
...(0, r.nLength)(j.n, j.nBitLength),
|
|
696
|
-
...j,
|
|
697
|
-
p: j.Fp.ORDER
|
|
698
|
-
});
|
|
699
|
-
}
|
|
700
|
-
function se(j, O, L) {
|
|
701
|
-
if (O) {
|
|
702
|
-
if (O.ORDER !== j)
|
|
703
|
-
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
704
|
-
return (0, r.validateField)(O), O;
|
|
705
|
-
} else
|
|
706
|
-
return (0, r.Field)(j, { isLE: L });
|
|
707
|
-
}
|
|
708
|
-
function ie(j, O, L = {}, _) {
|
|
709
|
-
if (_ === void 0 && (_ = j === "edwards"), !O || typeof O != "object")
|
|
710
|
-
throw new Error(`expected valid ${j} CURVE object`);
|
|
711
|
-
for (const u of ["p", "n", "h"]) {
|
|
712
|
-
const n = O[u];
|
|
713
|
-
if (!(typeof n == "bigint" && n > c))
|
|
714
|
-
throw new Error(`CURVE.${u} must be positive bigint`);
|
|
715
|
-
}
|
|
716
|
-
const K = se(O.p, L.Fp, _), W = se(O.n, L.Fn, _), d = ["Gx", "Gy", "a", j === "weierstrass" ? "b" : "d"];
|
|
717
|
-
for (const u of d)
|
|
718
|
-
if (!K.isValid(O[u]))
|
|
719
|
-
throw new Error(`CURVE.${u} must be valid field element of CURVE.Fp`);
|
|
720
|
-
return O = Object.freeze(Object.assign({}, O)), { CURVE: O, Fp: K, Fn: W };
|
|
721
|
-
}
|
|
722
|
-
return Oe;
|
|
723
|
-
}
|
|
724
|
-
var xt;
|
|
725
|
-
function Ct() {
|
|
726
|
-
return xt || (xt = 1, (function(e) {
|
|
727
|
-
Object.defineProperty(e, "__esModule", { value: !0 }), e.DER = e.DERErr = void 0, e._splitEndoScalar = p, e._normFnElement = M, e.weierstrassN = Q, e.SWUFpSqrtRatio = G, e.mapToCurveSimpleSWU = se, e.ecdh = j, e.ecdsa = O, e.weierstrassPoints = L, e._legacyHelperEquat = W, e.weierstrass = u;
|
|
728
|
-
const r = /* @__PURE__ */ ln(), c = /* @__PURE__ */ We(), t = /* @__PURE__ */ Ce(), l = /* @__PURE__ */ gn(), m = /* @__PURE__ */ $e(), g = (n, a) => (n + (n >= 0 ? a : -a) / b) / a;
|
|
729
|
-
function p(n, a, i) {
|
|
730
|
-
const [[o, h], [w, s]] = a, f = g(s * n, i), y = g(-h * n, i);
|
|
731
|
-
let B = n - f * o - y * w, T = -f * h - y * s;
|
|
732
|
-
const V = B < k, Y = T < k;
|
|
733
|
-
V && (B = -B), Y && (T = -T);
|
|
734
|
-
const I = (0, t.bitMask)(Math.ceil((0, t.bitLen)(i) / 2)) + E;
|
|
735
|
-
if (B < k || B >= I || T < k || T >= I)
|
|
736
|
-
throw new Error("splitScalar (endomorphism): failed, k=" + n);
|
|
737
|
-
return { k1neg: V, k1: B, k2neg: Y, k2: T };
|
|
738
|
-
}
|
|
739
|
-
function v(n) {
|
|
740
|
-
if (!["compact", "recovered", "der"].includes(n))
|
|
741
|
-
throw new Error('Signature format must be "compact", "recovered", or "der"');
|
|
742
|
-
return n;
|
|
743
|
-
}
|
|
744
|
-
function U(n, a) {
|
|
745
|
-
const i = {};
|
|
746
|
-
for (let o of Object.keys(a))
|
|
747
|
-
i[o] = n[o] === void 0 ? a[o] : n[o];
|
|
748
|
-
return (0, t._abool2)(i.lowS, "lowS"), (0, t._abool2)(i.prehash, "prehash"), i.format !== void 0 && v(i.format), i;
|
|
749
|
-
}
|
|
750
|
-
class H extends Error {
|
|
751
|
-
constructor(a = "") {
|
|
752
|
-
super(a);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
e.DERErr = H, e.DER = {
|
|
756
|
-
// asn.1 DER encoding utils
|
|
757
|
-
Err: H,
|
|
758
|
-
// Basic building block is TLV (Tag-Length-Value)
|
|
759
|
-
_tlv: {
|
|
760
|
-
encode: (n, a) => {
|
|
761
|
-
const { Err: i } = e.DER;
|
|
762
|
-
if (n < 0 || n > 256)
|
|
763
|
-
throw new i("tlv.encode: wrong tag");
|
|
764
|
-
if (a.length & 1)
|
|
765
|
-
throw new i("tlv.encode: unpadded data");
|
|
766
|
-
const o = a.length / 2, h = (0, t.numberToHexUnpadded)(o);
|
|
767
|
-
if (h.length / 2 & 128)
|
|
768
|
-
throw new i("tlv.encode: long form length too big");
|
|
769
|
-
const w = o > 127 ? (0, t.numberToHexUnpadded)(h.length / 2 | 128) : "";
|
|
770
|
-
return (0, t.numberToHexUnpadded)(n) + w + h + a;
|
|
771
|
-
},
|
|
772
|
-
// v - value, l - left bytes (unparsed)
|
|
773
|
-
decode(n, a) {
|
|
774
|
-
const { Err: i } = e.DER;
|
|
775
|
-
let o = 0;
|
|
776
|
-
if (n < 0 || n > 256)
|
|
777
|
-
throw new i("tlv.encode: wrong tag");
|
|
778
|
-
if (a.length < 2 || a[o++] !== n)
|
|
779
|
-
throw new i("tlv.decode: wrong tlv");
|
|
780
|
-
const h = a[o++], w = !!(h & 128);
|
|
781
|
-
let s = 0;
|
|
782
|
-
if (!w)
|
|
783
|
-
s = h;
|
|
784
|
-
else {
|
|
785
|
-
const y = h & 127;
|
|
786
|
-
if (!y)
|
|
787
|
-
throw new i("tlv.decode(long): indefinite length not supported");
|
|
788
|
-
if (y > 4)
|
|
789
|
-
throw new i("tlv.decode(long): byte length is too big");
|
|
790
|
-
const B = a.subarray(o, o + y);
|
|
791
|
-
if (B.length !== y)
|
|
792
|
-
throw new i("tlv.decode: length bytes not complete");
|
|
793
|
-
if (B[0] === 0)
|
|
794
|
-
throw new i("tlv.decode(long): zero leftmost byte");
|
|
795
|
-
for (const T of B)
|
|
796
|
-
s = s << 8 | T;
|
|
797
|
-
if (o += y, s < 128)
|
|
798
|
-
throw new i("tlv.decode(long): not minimal encoding");
|
|
799
|
-
}
|
|
800
|
-
const f = a.subarray(o, o + s);
|
|
801
|
-
if (f.length !== s)
|
|
802
|
-
throw new i("tlv.decode: wrong value length");
|
|
803
|
-
return { v: f, l: a.subarray(o + s) };
|
|
804
|
-
}
|
|
805
|
-
},
|
|
806
|
-
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
807
|
-
// since we always use positive integers here. It must always be empty:
|
|
808
|
-
// - add zero byte if exists
|
|
809
|
-
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
810
|
-
_int: {
|
|
811
|
-
encode(n) {
|
|
812
|
-
const { Err: a } = e.DER;
|
|
813
|
-
if (n < k)
|
|
814
|
-
throw new a("integer: negative integers are not allowed");
|
|
815
|
-
let i = (0, t.numberToHexUnpadded)(n);
|
|
816
|
-
if (Number.parseInt(i[0], 16) & 8 && (i = "00" + i), i.length & 1)
|
|
817
|
-
throw new a("unexpected DER parsing assertion: unpadded hex");
|
|
818
|
-
return i;
|
|
819
|
-
},
|
|
820
|
-
decode(n) {
|
|
821
|
-
const { Err: a } = e.DER;
|
|
822
|
-
if (n[0] & 128)
|
|
823
|
-
throw new a("invalid signature integer: negative");
|
|
824
|
-
if (n[0] === 0 && !(n[1] & 128))
|
|
825
|
-
throw new a("invalid signature integer: unnecessary leading zero");
|
|
826
|
-
return (0, t.bytesToNumberBE)(n);
|
|
827
|
-
}
|
|
828
|
-
},
|
|
829
|
-
toSig(n) {
|
|
830
|
-
const { Err: a, _int: i, _tlv: o } = e.DER, h = (0, t.ensureBytes)("signature", n), { v: w, l: s } = o.decode(48, h);
|
|
831
|
-
if (s.length)
|
|
832
|
-
throw new a("invalid signature: left bytes after parsing");
|
|
833
|
-
const { v: f, l: y } = o.decode(2, w), { v: B, l: T } = o.decode(2, y);
|
|
834
|
-
if (T.length)
|
|
835
|
-
throw new a("invalid signature: left bytes after parsing");
|
|
836
|
-
return { r: i.decode(f), s: i.decode(B) };
|
|
837
|
-
},
|
|
838
|
-
hexFromSig(n) {
|
|
839
|
-
const { _tlv: a, _int: i } = e.DER, o = a.encode(2, i.encode(n.r)), h = a.encode(2, i.encode(n.s)), w = o + h;
|
|
840
|
-
return a.encode(48, w);
|
|
841
|
-
}
|
|
842
|
-
};
|
|
843
|
-
const k = BigInt(0), E = BigInt(1), b = BigInt(2), S = BigInt(3), A = BigInt(4);
|
|
844
|
-
function M(n, a) {
|
|
845
|
-
const { BYTES: i } = n;
|
|
846
|
-
let o;
|
|
847
|
-
if (typeof a == "bigint")
|
|
848
|
-
o = a;
|
|
849
|
-
else {
|
|
850
|
-
let h = (0, t.ensureBytes)("private key", a);
|
|
851
|
-
try {
|
|
852
|
-
o = n.fromBytes(h);
|
|
853
|
-
} catch {
|
|
854
|
-
throw new Error(`invalid private key: expected ui8a of size ${i}, got ${typeof a}`);
|
|
855
|
-
}
|
|
856
|
-
}
|
|
857
|
-
if (!n.isValidNot0(o))
|
|
858
|
-
throw new Error("invalid private key: out of range [1..N-1]");
|
|
859
|
-
return o;
|
|
860
|
-
}
|
|
861
|
-
function Q(n, a = {}) {
|
|
862
|
-
const i = (0, l._createCurveFields)("weierstrass", n, a), { Fp: o, Fn: h } = i;
|
|
863
|
-
let w = i.CURVE;
|
|
864
|
-
const { h: s, n: f } = w;
|
|
865
|
-
(0, t._validateObject)(a, {}, {
|
|
866
|
-
allowInfinityPoint: "boolean",
|
|
867
|
-
clearCofactor: "function",
|
|
868
|
-
isTorsionFree: "function",
|
|
869
|
-
fromBytes: "function",
|
|
870
|
-
toBytes: "function",
|
|
871
|
-
endo: "object",
|
|
872
|
-
wrapPrivateKey: "boolean"
|
|
873
|
-
});
|
|
874
|
-
const { endo: y } = a;
|
|
875
|
-
if (y && (!o.is0(w.a) || typeof y.beta != "bigint" || !Array.isArray(y.basises)))
|
|
876
|
-
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
877
|
-
const B = ie(o, h);
|
|
878
|
-
function T() {
|
|
879
|
-
if (!o.isOdd)
|
|
880
|
-
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
881
|
-
}
|
|
882
|
-
function V(le, Z, N) {
|
|
883
|
-
const { x: R, y: D } = Z.toAffine(), J = o.toBytes(R);
|
|
884
|
-
if ((0, t._abool2)(N, "isCompressed"), N) {
|
|
885
|
-
T();
|
|
886
|
-
const re = !o.isOdd(D);
|
|
887
|
-
return (0, t.concatBytes)(F(re), J);
|
|
888
|
-
} else
|
|
889
|
-
return (0, t.concatBytes)(Uint8Array.of(4), J, o.toBytes(D));
|
|
890
|
-
}
|
|
891
|
-
function Y(le) {
|
|
892
|
-
(0, t._abytes2)(le, void 0, "Point");
|
|
893
|
-
const { publicKey: Z, publicKeyUncompressed: N } = B, R = le.length, D = le[0], J = le.subarray(1);
|
|
894
|
-
if (R === Z && (D === 2 || D === 3)) {
|
|
895
|
-
const re = o.fromBytes(J);
|
|
896
|
-
if (!o.isValid(re))
|
|
897
|
-
throw new Error("bad point: is not on curve, wrong x");
|
|
898
|
-
const ne = C(re);
|
|
899
|
-
let ee;
|
|
900
|
-
try {
|
|
901
|
-
ee = o.sqrt(ne);
|
|
902
|
-
} catch (we) {
|
|
903
|
-
const de = we instanceof Error ? ": " + we.message : "";
|
|
904
|
-
throw new Error("bad point: is not on curve, sqrt error" + de);
|
|
905
|
-
}
|
|
906
|
-
T();
|
|
907
|
-
const oe = o.isOdd(ee);
|
|
908
|
-
return (D & 1) === 1 !== oe && (ee = o.neg(ee)), { x: re, y: ee };
|
|
909
|
-
} else if (R === N && D === 4) {
|
|
910
|
-
const re = o.BYTES, ne = o.fromBytes(J.subarray(0, re)), ee = o.fromBytes(J.subarray(re, re * 2));
|
|
911
|
-
if (!te(ne, ee))
|
|
912
|
-
throw new Error("bad point: is not on curve");
|
|
913
|
-
return { x: ne, y: ee };
|
|
914
|
-
} else
|
|
915
|
-
throw new Error(`bad point: got length ${R}, expected compressed=${Z} or uncompressed=${N}`);
|
|
916
|
-
}
|
|
917
|
-
const I = a.toBytes || V, q = a.fromBytes || Y;
|
|
918
|
-
function C(le) {
|
|
919
|
-
const Z = o.sqr(le), N = o.mul(Z, le);
|
|
920
|
-
return o.add(o.add(N, o.mul(le, w.a)), w.b);
|
|
921
|
-
}
|
|
922
|
-
function te(le, Z) {
|
|
923
|
-
const N = o.sqr(Z), R = C(le);
|
|
924
|
-
return o.eql(N, R);
|
|
925
|
-
}
|
|
926
|
-
if (!te(w.Gx, w.Gy))
|
|
927
|
-
throw new Error("bad curve params: generator point");
|
|
928
|
-
const $ = o.mul(o.pow(w.a, S), A), x = o.mul(o.sqr(w.b), BigInt(27));
|
|
929
|
-
if (o.is0(o.add($, x)))
|
|
930
|
-
throw new Error("bad curve params: a or b");
|
|
931
|
-
function X(le, Z, N = !1) {
|
|
932
|
-
if (!o.isValid(Z) || N && o.is0(Z))
|
|
933
|
-
throw new Error(`bad point coordinate ${le}`);
|
|
934
|
-
return Z;
|
|
935
|
-
}
|
|
936
|
-
function ae(le) {
|
|
937
|
-
if (!(le instanceof fe))
|
|
938
|
-
throw new Error("ProjectivePoint expected");
|
|
939
|
-
}
|
|
940
|
-
function ye(le) {
|
|
941
|
-
if (!y || !y.basises)
|
|
942
|
-
throw new Error("no endo");
|
|
943
|
-
return p(le, y.basises, h.ORDER);
|
|
944
|
-
}
|
|
945
|
-
const pe = (0, t.memoized)((le, Z) => {
|
|
946
|
-
const { X: N, Y: R, Z: D } = le;
|
|
947
|
-
if (o.eql(D, o.ONE))
|
|
948
|
-
return { x: N, y: R };
|
|
949
|
-
const J = le.is0();
|
|
950
|
-
Z == null && (Z = J ? o.ONE : o.inv(D));
|
|
951
|
-
const re = o.mul(N, Z), ne = o.mul(R, Z), ee = o.mul(D, Z);
|
|
952
|
-
if (J)
|
|
953
|
-
return { x: o.ZERO, y: o.ZERO };
|
|
954
|
-
if (!o.eql(ee, o.ONE))
|
|
955
|
-
throw new Error("invZ was invalid");
|
|
956
|
-
return { x: re, y: ne };
|
|
957
|
-
}), ve = (0, t.memoized)((le) => {
|
|
958
|
-
if (le.is0()) {
|
|
959
|
-
if (a.allowInfinityPoint && !o.is0(le.Y))
|
|
960
|
-
return;
|
|
961
|
-
throw new Error("bad point: ZERO");
|
|
962
|
-
}
|
|
963
|
-
const { x: Z, y: N } = le.toAffine();
|
|
964
|
-
if (!o.isValid(Z) || !o.isValid(N))
|
|
965
|
-
throw new Error("bad point: x or y not field elements");
|
|
966
|
-
if (!te(Z, N))
|
|
967
|
-
throw new Error("bad point: equation left != right");
|
|
968
|
-
if (!le.isTorsionFree())
|
|
969
|
-
throw new Error("bad point: not in prime-order subgroup");
|
|
970
|
-
return !0;
|
|
971
|
-
});
|
|
972
|
-
function xe(le, Z, N, R, D) {
|
|
973
|
-
return N = new fe(o.mul(N.X, le), N.Y, N.Z), Z = (0, l.negateCt)(R, Z), N = (0, l.negateCt)(D, N), Z.add(N);
|
|
974
|
-
}
|
|
975
|
-
class fe {
|
|
976
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
977
|
-
constructor(Z, N, R) {
|
|
978
|
-
this.X = X("x", Z), this.Y = X("y", N, !0), this.Z = X("z", R), Object.freeze(this);
|
|
979
|
-
}
|
|
980
|
-
static CURVE() {
|
|
981
|
-
return w;
|
|
982
|
-
}
|
|
983
|
-
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
984
|
-
static fromAffine(Z) {
|
|
985
|
-
const { x: N, y: R } = Z || {};
|
|
986
|
-
if (!Z || !o.isValid(N) || !o.isValid(R))
|
|
987
|
-
throw new Error("invalid affine point");
|
|
988
|
-
if (Z instanceof fe)
|
|
989
|
-
throw new Error("projective point not allowed");
|
|
990
|
-
return o.is0(N) && o.is0(R) ? fe.ZERO : new fe(N, R, o.ONE);
|
|
991
|
-
}
|
|
992
|
-
static fromBytes(Z) {
|
|
993
|
-
const N = fe.fromAffine(q((0, t._abytes2)(Z, void 0, "point")));
|
|
994
|
-
return N.assertValidity(), N;
|
|
995
|
-
}
|
|
996
|
-
static fromHex(Z) {
|
|
997
|
-
return fe.fromBytes((0, t.ensureBytes)("pointHex", Z));
|
|
998
|
-
}
|
|
999
|
-
get x() {
|
|
1000
|
-
return this.toAffine().x;
|
|
1001
|
-
}
|
|
1002
|
-
get y() {
|
|
1003
|
-
return this.toAffine().y;
|
|
1004
|
-
}
|
|
1005
|
-
/**
|
|
1006
|
-
*
|
|
1007
|
-
* @param windowSize
|
|
1008
|
-
* @param isLazy true will defer table computation until the first multiplication
|
|
1009
|
-
* @returns
|
|
1010
|
-
*/
|
|
1011
|
-
precompute(Z = 8, N = !0) {
|
|
1012
|
-
return Ue.createCache(this, Z), N || this.multiply(S), this;
|
|
1013
|
-
}
|
|
1014
|
-
// TODO: return `this`
|
|
1015
|
-
/** A point on curve is valid if it conforms to equation. */
|
|
1016
|
-
assertValidity() {
|
|
1017
|
-
ve(this);
|
|
1018
|
-
}
|
|
1019
|
-
hasEvenY() {
|
|
1020
|
-
const { y: Z } = this.toAffine();
|
|
1021
|
-
if (!o.isOdd)
|
|
1022
|
-
throw new Error("Field doesn't support isOdd");
|
|
1023
|
-
return !o.isOdd(Z);
|
|
1024
|
-
}
|
|
1025
|
-
/** Compare one point to another. */
|
|
1026
|
-
equals(Z) {
|
|
1027
|
-
ae(Z);
|
|
1028
|
-
const { X: N, Y: R, Z: D } = this, { X: J, Y: re, Z: ne } = Z, ee = o.eql(o.mul(N, ne), o.mul(J, D)), oe = o.eql(o.mul(R, ne), o.mul(re, D));
|
|
1029
|
-
return ee && oe;
|
|
1030
|
-
}
|
|
1031
|
-
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
1032
|
-
negate() {
|
|
1033
|
-
return new fe(this.X, o.neg(this.Y), this.Z);
|
|
1034
|
-
}
|
|
1035
|
-
// Renes-Costello-Batina exception-free doubling formula.
|
|
1036
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1037
|
-
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
1038
|
-
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
1039
|
-
double() {
|
|
1040
|
-
const { a: Z, b: N } = w, R = o.mul(N, S), { X: D, Y: J, Z: re } = this;
|
|
1041
|
-
let ne = o.ZERO, ee = o.ZERO, oe = o.ZERO, ce = o.mul(D, D), we = o.mul(J, J), de = o.mul(re, re), ue = o.mul(D, J);
|
|
1042
|
-
return ue = o.add(ue, ue), oe = o.mul(D, re), oe = o.add(oe, oe), ne = o.mul(Z, oe), ee = o.mul(R, de), ee = o.add(ne, ee), ne = o.sub(we, ee), ee = o.add(we, ee), ee = o.mul(ne, ee), ne = o.mul(ue, ne), oe = o.mul(R, oe), de = o.mul(Z, de), ue = o.sub(ce, de), ue = o.mul(Z, ue), ue = o.add(ue, oe), oe = o.add(ce, ce), ce = o.add(oe, ce), ce = o.add(ce, de), ce = o.mul(ce, ue), ee = o.add(ee, ce), de = o.mul(J, re), de = o.add(de, de), ce = o.mul(de, ue), ne = o.sub(ne, ce), oe = o.mul(de, we), oe = o.add(oe, oe), oe = o.add(oe, oe), new fe(ne, ee, oe);
|
|
1043
|
-
}
|
|
1044
|
-
// Renes-Costello-Batina exception-free addition formula.
|
|
1045
|
-
// There is 30% faster Jacobian formula, but it is not complete.
|
|
1046
|
-
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
1047
|
-
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
1048
|
-
add(Z) {
|
|
1049
|
-
ae(Z);
|
|
1050
|
-
const { X: N, Y: R, Z: D } = this, { X: J, Y: re, Z: ne } = Z;
|
|
1051
|
-
let ee = o.ZERO, oe = o.ZERO, ce = o.ZERO;
|
|
1052
|
-
const we = w.a, de = o.mul(w.b, S);
|
|
1053
|
-
let ue = o.mul(N, J), me = o.mul(R, re), ge = o.mul(D, ne), _e = o.add(N, R), be = o.add(J, re);
|
|
1054
|
-
_e = o.mul(_e, be), be = o.add(ue, me), _e = o.sub(_e, be), be = o.add(N, D);
|
|
1055
|
-
let Ee = o.add(J, ne);
|
|
1056
|
-
return be = o.mul(be, Ee), Ee = o.add(ue, ge), be = o.sub(be, Ee), Ee = o.add(R, D), ee = o.add(re, ne), Ee = o.mul(Ee, ee), ee = o.add(me, ge), Ee = o.sub(Ee, ee), ce = o.mul(we, be), ee = o.mul(de, ge), ce = o.add(ee, ce), ee = o.sub(me, ce), ce = o.add(me, ce), oe = o.mul(ee, ce), me = o.add(ue, ue), me = o.add(me, ue), ge = o.mul(we, ge), be = o.mul(de, be), me = o.add(me, ge), ge = o.sub(ue, ge), ge = o.mul(we, ge), be = o.add(be, ge), ue = o.mul(me, be), oe = o.add(oe, ue), ue = o.mul(Ee, be), ee = o.mul(_e, ee), ee = o.sub(ee, ue), ue = o.mul(_e, me), ce = o.mul(Ee, ce), ce = o.add(ce, ue), new fe(ee, oe, ce);
|
|
1057
|
-
}
|
|
1058
|
-
subtract(Z) {
|
|
1059
|
-
return this.add(Z.negate());
|
|
1060
|
-
}
|
|
1061
|
-
is0() {
|
|
1062
|
-
return this.equals(fe.ZERO);
|
|
1063
|
-
}
|
|
1064
|
-
/**
|
|
1065
|
-
* Constant time multiplication.
|
|
1066
|
-
* Uses wNAF method. Windowed method may be 10% faster,
|
|
1067
|
-
* but takes 2x longer to generate and consumes 2x memory.
|
|
1068
|
-
* Uses precomputes when available.
|
|
1069
|
-
* Uses endomorphism for Koblitz curves.
|
|
1070
|
-
* @param scalar by which the point would be multiplied
|
|
1071
|
-
* @returns New point
|
|
1072
|
-
*/
|
|
1073
|
-
multiply(Z) {
|
|
1074
|
-
const { endo: N } = a;
|
|
1075
|
-
if (!h.isValidNot0(Z))
|
|
1076
|
-
throw new Error("invalid scalar: out of range");
|
|
1077
|
-
let R, D;
|
|
1078
|
-
const J = (re) => Ue.cached(this, re, (ne) => (0, l.normalizeZ)(fe, ne));
|
|
1079
|
-
if (N) {
|
|
1080
|
-
const { k1neg: re, k1: ne, k2neg: ee, k2: oe } = ye(Z), { p: ce, f: we } = J(ne), { p: de, f: ue } = J(oe);
|
|
1081
|
-
D = we.add(ue), R = xe(N.beta, ce, de, re, ee);
|
|
1082
|
-
} else {
|
|
1083
|
-
const { p: re, f: ne } = J(Z);
|
|
1084
|
-
R = re, D = ne;
|
|
1085
|
-
}
|
|
1086
|
-
return (0, l.normalizeZ)(fe, [R, D])[0];
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
1090
|
-
* It's faster, but should only be used when you don't care about
|
|
1091
|
-
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
1092
|
-
*/
|
|
1093
|
-
multiplyUnsafe(Z) {
|
|
1094
|
-
const { endo: N } = a, R = this;
|
|
1095
|
-
if (!h.isValid(Z))
|
|
1096
|
-
throw new Error("invalid scalar: out of range");
|
|
1097
|
-
if (Z === k || R.is0())
|
|
1098
|
-
return fe.ZERO;
|
|
1099
|
-
if (Z === E)
|
|
1100
|
-
return R;
|
|
1101
|
-
if (Ue.hasCache(this))
|
|
1102
|
-
return this.multiply(Z);
|
|
1103
|
-
if (N) {
|
|
1104
|
-
const { k1neg: D, k1: J, k2neg: re, k2: ne } = ye(Z), { p1: ee, p2: oe } = (0, l.mulEndoUnsafe)(fe, R, J, ne);
|
|
1105
|
-
return xe(N.beta, ee, oe, D, re);
|
|
1106
|
-
} else
|
|
1107
|
-
return Ue.unsafe(R, Z);
|
|
1108
|
-
}
|
|
1109
|
-
multiplyAndAddUnsafe(Z, N, R) {
|
|
1110
|
-
const D = this.multiplyUnsafe(N).add(Z.multiplyUnsafe(R));
|
|
1111
|
-
return D.is0() ? void 0 : D;
|
|
1112
|
-
}
|
|
1113
|
-
/**
|
|
1114
|
-
* Converts Projective point to affine (x, y) coordinates.
|
|
1115
|
-
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
1116
|
-
*/
|
|
1117
|
-
toAffine(Z) {
|
|
1118
|
-
return pe(this, Z);
|
|
1119
|
-
}
|
|
1120
|
-
/**
|
|
1121
|
-
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
1122
|
-
* Always torsion-free for cofactor=1 curves.
|
|
1123
|
-
*/
|
|
1124
|
-
isTorsionFree() {
|
|
1125
|
-
const { isTorsionFree: Z } = a;
|
|
1126
|
-
return s === E ? !0 : Z ? Z(fe, this) : Ue.unsafe(this, f).is0();
|
|
1127
|
-
}
|
|
1128
|
-
clearCofactor() {
|
|
1129
|
-
const { clearCofactor: Z } = a;
|
|
1130
|
-
return s === E ? this : Z ? Z(fe, this) : this.multiplyUnsafe(s);
|
|
1131
|
-
}
|
|
1132
|
-
isSmallOrder() {
|
|
1133
|
-
return this.multiplyUnsafe(s).is0();
|
|
1134
|
-
}
|
|
1135
|
-
toBytes(Z = !0) {
|
|
1136
|
-
return (0, t._abool2)(Z, "isCompressed"), this.assertValidity(), I(fe, this, Z);
|
|
1137
|
-
}
|
|
1138
|
-
toHex(Z = !0) {
|
|
1139
|
-
return (0, t.bytesToHex)(this.toBytes(Z));
|
|
1140
|
-
}
|
|
1141
|
-
toString() {
|
|
1142
|
-
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
1143
|
-
}
|
|
1144
|
-
// TODO: remove
|
|
1145
|
-
get px() {
|
|
1146
|
-
return this.X;
|
|
1147
|
-
}
|
|
1148
|
-
get py() {
|
|
1149
|
-
return this.X;
|
|
1150
|
-
}
|
|
1151
|
-
get pz() {
|
|
1152
|
-
return this.Z;
|
|
1153
|
-
}
|
|
1154
|
-
toRawBytes(Z = !0) {
|
|
1155
|
-
return this.toBytes(Z);
|
|
1156
|
-
}
|
|
1157
|
-
_setWindowSize(Z) {
|
|
1158
|
-
this.precompute(Z);
|
|
1159
|
-
}
|
|
1160
|
-
static normalizeZ(Z) {
|
|
1161
|
-
return (0, l.normalizeZ)(fe, Z);
|
|
1162
|
-
}
|
|
1163
|
-
static msm(Z, N) {
|
|
1164
|
-
return (0, l.pippenger)(fe, h, Z, N);
|
|
1165
|
-
}
|
|
1166
|
-
static fromPrivateKey(Z) {
|
|
1167
|
-
return fe.BASE.multiply(M(h, Z));
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
fe.BASE = new fe(w.Gx, w.Gy, o.ONE), fe.ZERO = new fe(o.ZERO, o.ONE, o.ZERO), fe.Fp = o, fe.Fn = h;
|
|
1171
|
-
const Ye = h.BITS, Ue = new l.wNAF(fe, a.endo ? Math.ceil(Ye / 2) : Ye);
|
|
1172
|
-
return fe.BASE.precompute(8), fe;
|
|
1173
|
-
}
|
|
1174
|
-
function F(n) {
|
|
1175
|
-
return Uint8Array.of(n ? 2 : 3);
|
|
1176
|
-
}
|
|
1177
|
-
function G(n, a) {
|
|
1178
|
-
const i = n.ORDER;
|
|
1179
|
-
let o = k;
|
|
1180
|
-
for (let q = i - E; q % b === k; q /= b)
|
|
1181
|
-
o += E;
|
|
1182
|
-
const h = o, w = b << h - E - E, s = w * b, f = (i - E) / s, y = (f - E) / b, B = s - E, T = w, V = n.pow(a, f), Y = n.pow(a, (f + E) / b);
|
|
1183
|
-
let I = (q, C) => {
|
|
1184
|
-
let te = V, $ = n.pow(C, B), x = n.sqr($);
|
|
1185
|
-
x = n.mul(x, C);
|
|
1186
|
-
let X = n.mul(q, x);
|
|
1187
|
-
X = n.pow(X, y), X = n.mul(X, $), $ = n.mul(X, C), x = n.mul(X, q);
|
|
1188
|
-
let ae = n.mul(x, $);
|
|
1189
|
-
X = n.pow(ae, T);
|
|
1190
|
-
let ye = n.eql(X, n.ONE);
|
|
1191
|
-
$ = n.mul(x, Y), X = n.mul(ae, te), x = n.cmov($, x, ye), ae = n.cmov(X, ae, ye);
|
|
1192
|
-
for (let pe = h; pe > E; pe--) {
|
|
1193
|
-
let ve = pe - b;
|
|
1194
|
-
ve = b << ve - E;
|
|
1195
|
-
let xe = n.pow(ae, ve);
|
|
1196
|
-
const fe = n.eql(xe, n.ONE);
|
|
1197
|
-
$ = n.mul(x, te), te = n.mul(te, te), xe = n.mul(ae, te), x = n.cmov($, x, fe), ae = n.cmov(xe, ae, fe);
|
|
1198
|
-
}
|
|
1199
|
-
return { isValid: ye, value: x };
|
|
1200
|
-
};
|
|
1201
|
-
if (n.ORDER % A === S) {
|
|
1202
|
-
const q = (n.ORDER - S) / A, C = n.sqrt(n.neg(a));
|
|
1203
|
-
I = (te, $) => {
|
|
1204
|
-
let x = n.sqr($);
|
|
1205
|
-
const X = n.mul(te, $);
|
|
1206
|
-
x = n.mul(x, X);
|
|
1207
|
-
let ae = n.pow(x, q);
|
|
1208
|
-
ae = n.mul(ae, X);
|
|
1209
|
-
const ye = n.mul(ae, C), pe = n.mul(n.sqr(ae), $), ve = n.eql(pe, te);
|
|
1210
|
-
let xe = n.cmov(ye, ae, ve);
|
|
1211
|
-
return { isValid: ve, value: xe };
|
|
1212
|
-
};
|
|
1213
|
-
}
|
|
1214
|
-
return I;
|
|
1215
|
-
}
|
|
1216
|
-
function se(n, a) {
|
|
1217
|
-
(0, m.validateField)(n);
|
|
1218
|
-
const { A: i, B: o, Z: h } = a;
|
|
1219
|
-
if (!n.isValid(i) || !n.isValid(o) || !n.isValid(h))
|
|
1220
|
-
throw new Error("mapToCurveSimpleSWU: invalid opts");
|
|
1221
|
-
const w = G(n, h);
|
|
1222
|
-
if (!n.isOdd)
|
|
1223
|
-
throw new Error("Field does not have .isOdd()");
|
|
1224
|
-
return (s) => {
|
|
1225
|
-
let f, y, B, T, V, Y, I, q;
|
|
1226
|
-
f = n.sqr(s), f = n.mul(f, h), y = n.sqr(f), y = n.add(y, f), B = n.add(y, n.ONE), B = n.mul(B, o), T = n.cmov(h, n.neg(y), !n.eql(y, n.ZERO)), T = n.mul(T, i), y = n.sqr(B), Y = n.sqr(T), V = n.mul(Y, i), y = n.add(y, V), y = n.mul(y, B), Y = n.mul(Y, T), V = n.mul(Y, o), y = n.add(y, V), I = n.mul(f, B);
|
|
1227
|
-
const { isValid: C, value: te } = w(y, Y);
|
|
1228
|
-
q = n.mul(f, s), q = n.mul(q, te), I = n.cmov(I, B, C), q = n.cmov(q, te, C);
|
|
1229
|
-
const $ = n.isOdd(s) === n.isOdd(q);
|
|
1230
|
-
q = n.cmov(n.neg(q), q, $);
|
|
1231
|
-
const x = (0, m.FpInvertBatch)(n, [T], !0)[0];
|
|
1232
|
-
return I = n.mul(I, x), { x: I, y: q };
|
|
1233
|
-
};
|
|
1234
|
-
}
|
|
1235
|
-
function ie(n, a) {
|
|
1236
|
-
return {
|
|
1237
|
-
secretKey: a.BYTES,
|
|
1238
|
-
publicKey: 1 + n.BYTES,
|
|
1239
|
-
publicKeyUncompressed: 1 + 2 * n.BYTES,
|
|
1240
|
-
publicKeyHasPrefix: !0,
|
|
1241
|
-
signature: 2 * a.BYTES
|
|
1242
|
-
};
|
|
1243
|
-
}
|
|
1244
|
-
function j(n, a = {}) {
|
|
1245
|
-
const { Fn: i } = n, o = a.randomBytes || t.randomBytes, h = Object.assign(ie(n.Fp, i), { seed: (0, m.getMinHashLength)(i.ORDER) });
|
|
1246
|
-
function w(I) {
|
|
1247
|
-
try {
|
|
1248
|
-
return !!M(i, I);
|
|
1249
|
-
} catch {
|
|
1250
|
-
return !1;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
function s(I, q) {
|
|
1254
|
-
const { publicKey: C, publicKeyUncompressed: te } = h;
|
|
1255
|
-
try {
|
|
1256
|
-
const $ = I.length;
|
|
1257
|
-
return q === !0 && $ !== C || q === !1 && $ !== te ? !1 : !!n.fromBytes(I);
|
|
1258
|
-
} catch {
|
|
1259
|
-
return !1;
|
|
1260
|
-
}
|
|
1261
|
-
}
|
|
1262
|
-
function f(I = o(h.seed)) {
|
|
1263
|
-
return (0, m.mapHashToField)((0, t._abytes2)(I, h.seed, "seed"), i.ORDER);
|
|
1264
|
-
}
|
|
1265
|
-
function y(I, q = !0) {
|
|
1266
|
-
return n.BASE.multiply(M(i, I)).toBytes(q);
|
|
1267
|
-
}
|
|
1268
|
-
function B(I) {
|
|
1269
|
-
const q = f(I);
|
|
1270
|
-
return { secretKey: q, publicKey: y(q) };
|
|
1271
|
-
}
|
|
1272
|
-
function T(I) {
|
|
1273
|
-
if (typeof I == "bigint")
|
|
1274
|
-
return !1;
|
|
1275
|
-
if (I instanceof n)
|
|
1276
|
-
return !0;
|
|
1277
|
-
const { secretKey: q, publicKey: C, publicKeyUncompressed: te } = h;
|
|
1278
|
-
if (i.allowedLengths || q === C)
|
|
1279
|
-
return;
|
|
1280
|
-
const $ = (0, t.ensureBytes)("key", I).length;
|
|
1281
|
-
return $ === C || $ === te;
|
|
1282
|
-
}
|
|
1283
|
-
function V(I, q, C = !0) {
|
|
1284
|
-
if (T(I) === !0)
|
|
1285
|
-
throw new Error("first arg must be private key");
|
|
1286
|
-
if (T(q) === !1)
|
|
1287
|
-
throw new Error("second arg must be public key");
|
|
1288
|
-
const te = M(i, I);
|
|
1289
|
-
return n.fromHex(q).multiply(te).toBytes(C);
|
|
1290
|
-
}
|
|
1291
|
-
return Object.freeze({ getPublicKey: y, getSharedSecret: V, keygen: B, Point: n, utils: {
|
|
1292
|
-
isValidSecretKey: w,
|
|
1293
|
-
isValidPublicKey: s,
|
|
1294
|
-
randomSecretKey: f,
|
|
1295
|
-
// TODO: remove
|
|
1296
|
-
isValidPrivateKey: w,
|
|
1297
|
-
randomPrivateKey: f,
|
|
1298
|
-
normPrivateKeyToScalar: (I) => M(i, I),
|
|
1299
|
-
precompute(I = 8, q = n.BASE) {
|
|
1300
|
-
return q.precompute(I, !1);
|
|
1301
|
-
}
|
|
1302
|
-
}, lengths: h });
|
|
1303
|
-
}
|
|
1304
|
-
function O(n, a, i = {}) {
|
|
1305
|
-
(0, c.ahash)(a), (0, t._validateObject)(i, {}, {
|
|
1306
|
-
hmac: "function",
|
|
1307
|
-
lowS: "boolean",
|
|
1308
|
-
randomBytes: "function",
|
|
1309
|
-
bits2int: "function",
|
|
1310
|
-
bits2int_modN: "function"
|
|
1311
|
-
});
|
|
1312
|
-
const o = i.randomBytes || t.randomBytes, h = i.hmac || ((N, ...R) => (0, r.hmac)(a, N, (0, t.concatBytes)(...R))), { Fp: w, Fn: s } = n, { ORDER: f, BITS: y } = s, { keygen: B, getPublicKey: T, getSharedSecret: V, utils: Y, lengths: I } = j(n, i), q = {
|
|
1313
|
-
prehash: !1,
|
|
1314
|
-
lowS: typeof i.lowS == "boolean" ? i.lowS : !1,
|
|
1315
|
-
format: void 0,
|
|
1316
|
-
//'compact' as ECDSASigFormat,
|
|
1317
|
-
extraEntropy: !1
|
|
1318
|
-
}, C = "compact";
|
|
1319
|
-
function te(N) {
|
|
1320
|
-
const R = f >> E;
|
|
1321
|
-
return N > R;
|
|
1322
|
-
}
|
|
1323
|
-
function $(N, R) {
|
|
1324
|
-
if (!s.isValidNot0(R))
|
|
1325
|
-
throw new Error(`invalid signature ${N}: out of range 1..Point.Fn.ORDER`);
|
|
1326
|
-
return R;
|
|
1327
|
-
}
|
|
1328
|
-
function x(N, R) {
|
|
1329
|
-
v(R);
|
|
1330
|
-
const D = I.signature, J = R === "compact" ? D : R === "recovered" ? D + 1 : void 0;
|
|
1331
|
-
return (0, t._abytes2)(N, J, `${R} signature`);
|
|
1332
|
-
}
|
|
1333
|
-
class X {
|
|
1334
|
-
constructor(R, D, J) {
|
|
1335
|
-
this.r = $("r", R), this.s = $("s", D), J != null && (this.recovery = J), Object.freeze(this);
|
|
1336
|
-
}
|
|
1337
|
-
static fromBytes(R, D = C) {
|
|
1338
|
-
x(R, D);
|
|
1339
|
-
let J;
|
|
1340
|
-
if (D === "der") {
|
|
1341
|
-
const { r: oe, s: ce } = e.DER.toSig((0, t._abytes2)(R));
|
|
1342
|
-
return new X(oe, ce);
|
|
1343
|
-
}
|
|
1344
|
-
D === "recovered" && (J = R[0], D = "compact", R = R.subarray(1));
|
|
1345
|
-
const re = s.BYTES, ne = R.subarray(0, re), ee = R.subarray(re, re * 2);
|
|
1346
|
-
return new X(s.fromBytes(ne), s.fromBytes(ee), J);
|
|
1347
|
-
}
|
|
1348
|
-
static fromHex(R, D) {
|
|
1349
|
-
return this.fromBytes((0, t.hexToBytes)(R), D);
|
|
1350
|
-
}
|
|
1351
|
-
addRecoveryBit(R) {
|
|
1352
|
-
return new X(this.r, this.s, R);
|
|
1353
|
-
}
|
|
1354
|
-
recoverPublicKey(R) {
|
|
1355
|
-
const D = w.ORDER, { r: J, s: re, recovery: ne } = this;
|
|
1356
|
-
if (ne == null || ![0, 1, 2, 3].includes(ne))
|
|
1357
|
-
throw new Error("recovery id invalid");
|
|
1358
|
-
if (f * b < D && ne > 1)
|
|
1359
|
-
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
1360
|
-
const oe = ne === 2 || ne === 3 ? J + f : J;
|
|
1361
|
-
if (!w.isValid(oe))
|
|
1362
|
-
throw new Error("recovery id 2 or 3 invalid");
|
|
1363
|
-
const ce = w.toBytes(oe), we = n.fromBytes((0, t.concatBytes)(F((ne & 1) === 0), ce)), de = s.inv(oe), ue = ye((0, t.ensureBytes)("msgHash", R)), me = s.create(-ue * de), ge = s.create(re * de), _e = n.BASE.multiplyUnsafe(me).add(we.multiplyUnsafe(ge));
|
|
1364
|
-
if (_e.is0())
|
|
1365
|
-
throw new Error("point at infinify");
|
|
1366
|
-
return _e.assertValidity(), _e;
|
|
1367
|
-
}
|
|
1368
|
-
// Signatures should be low-s, to prevent malleability.
|
|
1369
|
-
hasHighS() {
|
|
1370
|
-
return te(this.s);
|
|
1371
|
-
}
|
|
1372
|
-
toBytes(R = C) {
|
|
1373
|
-
if (v(R), R === "der")
|
|
1374
|
-
return (0, t.hexToBytes)(e.DER.hexFromSig(this));
|
|
1375
|
-
const D = s.toBytes(this.r), J = s.toBytes(this.s);
|
|
1376
|
-
if (R === "recovered") {
|
|
1377
|
-
if (this.recovery == null)
|
|
1378
|
-
throw new Error("recovery bit must be present");
|
|
1379
|
-
return (0, t.concatBytes)(Uint8Array.of(this.recovery), D, J);
|
|
1380
|
-
}
|
|
1381
|
-
return (0, t.concatBytes)(D, J);
|
|
1382
|
-
}
|
|
1383
|
-
toHex(R) {
|
|
1384
|
-
return (0, t.bytesToHex)(this.toBytes(R));
|
|
1385
|
-
}
|
|
1386
|
-
// TODO: remove
|
|
1387
|
-
assertValidity() {
|
|
1388
|
-
}
|
|
1389
|
-
static fromCompact(R) {
|
|
1390
|
-
return X.fromBytes((0, t.ensureBytes)("sig", R), "compact");
|
|
1391
|
-
}
|
|
1392
|
-
static fromDER(R) {
|
|
1393
|
-
return X.fromBytes((0, t.ensureBytes)("sig", R), "der");
|
|
1394
|
-
}
|
|
1395
|
-
normalizeS() {
|
|
1396
|
-
return this.hasHighS() ? new X(this.r, s.neg(this.s), this.recovery) : this;
|
|
1397
|
-
}
|
|
1398
|
-
toDERRawBytes() {
|
|
1399
|
-
return this.toBytes("der");
|
|
1400
|
-
}
|
|
1401
|
-
toDERHex() {
|
|
1402
|
-
return (0, t.bytesToHex)(this.toBytes("der"));
|
|
1403
|
-
}
|
|
1404
|
-
toCompactRawBytes() {
|
|
1405
|
-
return this.toBytes("compact");
|
|
1406
|
-
}
|
|
1407
|
-
toCompactHex() {
|
|
1408
|
-
return (0, t.bytesToHex)(this.toBytes("compact"));
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
const ae = i.bits2int || function(R) {
|
|
1412
|
-
if (R.length > 8192)
|
|
1413
|
-
throw new Error("input is too large");
|
|
1414
|
-
const D = (0, t.bytesToNumberBE)(R), J = R.length * 8 - y;
|
|
1415
|
-
return J > 0 ? D >> BigInt(J) : D;
|
|
1416
|
-
}, ye = i.bits2int_modN || function(R) {
|
|
1417
|
-
return s.create(ae(R));
|
|
1418
|
-
}, pe = (0, t.bitMask)(y);
|
|
1419
|
-
function ve(N) {
|
|
1420
|
-
return (0, t.aInRange)("num < 2^" + y, N, k, pe), s.toBytes(N);
|
|
1421
|
-
}
|
|
1422
|
-
function xe(N, R) {
|
|
1423
|
-
return (0, t._abytes2)(N, void 0, "message"), R ? (0, t._abytes2)(a(N), void 0, "prehashed message") : N;
|
|
1424
|
-
}
|
|
1425
|
-
function fe(N, R, D) {
|
|
1426
|
-
if (["recovered", "canonical"].some((me) => me in D))
|
|
1427
|
-
throw new Error("sign() legacy options not supported");
|
|
1428
|
-
const { lowS: J, prehash: re, extraEntropy: ne } = U(D, q);
|
|
1429
|
-
N = xe(N, re);
|
|
1430
|
-
const ee = ye(N), oe = M(s, R), ce = [ve(oe), ve(ee)];
|
|
1431
|
-
if (ne != null && ne !== !1) {
|
|
1432
|
-
const me = ne === !0 ? o(I.secretKey) : ne;
|
|
1433
|
-
ce.push((0, t.ensureBytes)("extraEntropy", me));
|
|
1434
|
-
}
|
|
1435
|
-
const we = (0, t.concatBytes)(...ce), de = ee;
|
|
1436
|
-
function ue(me) {
|
|
1437
|
-
const ge = ae(me);
|
|
1438
|
-
if (!s.isValidNot0(ge))
|
|
1439
|
-
return;
|
|
1440
|
-
const _e = s.inv(ge), be = n.BASE.multiply(ge).toAffine(), Ee = s.create(be.x);
|
|
1441
|
-
if (Ee === k)
|
|
1442
|
-
return;
|
|
1443
|
-
const Pe = s.create(_e * s.create(de + Ee * oe));
|
|
1444
|
-
if (Pe === k)
|
|
1445
|
-
return;
|
|
1446
|
-
let pt = (be.x === Ee ? 0 : 2) | Number(be.y & E), vt = Pe;
|
|
1447
|
-
return J && te(Pe) && (vt = s.neg(Pe), pt ^= 1), new X(Ee, vt, pt);
|
|
1448
|
-
}
|
|
1449
|
-
return { seed: we, k2sig: ue };
|
|
1450
|
-
}
|
|
1451
|
-
function Ye(N, R, D = {}) {
|
|
1452
|
-
N = (0, t.ensureBytes)("message", N);
|
|
1453
|
-
const { seed: J, k2sig: re } = fe(N, R, D);
|
|
1454
|
-
return (0, t.createHmacDrbg)(a.outputLen, s.BYTES, h)(J, re);
|
|
1455
|
-
}
|
|
1456
|
-
function Ue(N) {
|
|
1457
|
-
let R;
|
|
1458
|
-
const D = typeof N == "string" || (0, t.isBytes)(N), J = !D && N !== null && typeof N == "object" && typeof N.r == "bigint" && typeof N.s == "bigint";
|
|
1459
|
-
if (!D && !J)
|
|
1460
|
-
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
1461
|
-
if (J)
|
|
1462
|
-
R = new X(N.r, N.s);
|
|
1463
|
-
else if (D) {
|
|
1464
|
-
try {
|
|
1465
|
-
R = X.fromBytes((0, t.ensureBytes)("sig", N), "der");
|
|
1466
|
-
} catch (re) {
|
|
1467
|
-
if (!(re instanceof e.DER.Err))
|
|
1468
|
-
throw re;
|
|
1469
|
-
}
|
|
1470
|
-
if (!R)
|
|
1471
|
-
try {
|
|
1472
|
-
R = X.fromBytes((0, t.ensureBytes)("sig", N), "compact");
|
|
1473
|
-
} catch {
|
|
1474
|
-
return !1;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
return R || !1;
|
|
1478
|
-
}
|
|
1479
|
-
function le(N, R, D, J = {}) {
|
|
1480
|
-
const { lowS: re, prehash: ne, format: ee } = U(J, q);
|
|
1481
|
-
if (D = (0, t.ensureBytes)("publicKey", D), R = xe((0, t.ensureBytes)("message", R), ne), "strict" in J)
|
|
1482
|
-
throw new Error("options.strict was renamed to lowS");
|
|
1483
|
-
const oe = ee === void 0 ? Ue(N) : X.fromBytes((0, t.ensureBytes)("sig", N), ee);
|
|
1484
|
-
if (oe === !1)
|
|
1485
|
-
return !1;
|
|
1486
|
-
try {
|
|
1487
|
-
const ce = n.fromBytes(D);
|
|
1488
|
-
if (re && oe.hasHighS())
|
|
1489
|
-
return !1;
|
|
1490
|
-
const { r: we, s: de } = oe, ue = ye(R), me = s.inv(de), ge = s.create(ue * me), _e = s.create(we * me), be = n.BASE.multiplyUnsafe(ge).add(ce.multiplyUnsafe(_e));
|
|
1491
|
-
return be.is0() ? !1 : s.create(be.x) === we;
|
|
1492
|
-
} catch {
|
|
1493
|
-
return !1;
|
|
1494
|
-
}
|
|
1495
|
-
}
|
|
1496
|
-
function Z(N, R, D = {}) {
|
|
1497
|
-
const { prehash: J } = U(D, q);
|
|
1498
|
-
return R = xe(R, J), X.fromBytes(N, "recovered").recoverPublicKey(R).toBytes();
|
|
1499
|
-
}
|
|
1500
|
-
return Object.freeze({
|
|
1501
|
-
keygen: B,
|
|
1502
|
-
getPublicKey: T,
|
|
1503
|
-
getSharedSecret: V,
|
|
1504
|
-
utils: Y,
|
|
1505
|
-
lengths: I,
|
|
1506
|
-
Point: n,
|
|
1507
|
-
sign: Ye,
|
|
1508
|
-
verify: le,
|
|
1509
|
-
recoverPublicKey: Z,
|
|
1510
|
-
Signature: X,
|
|
1511
|
-
hash: a
|
|
1512
|
-
});
|
|
1513
|
-
}
|
|
1514
|
-
function L(n) {
|
|
1515
|
-
const { CURVE: a, curveOpts: i } = _(n), o = Q(a, i);
|
|
1516
|
-
return z(n, o);
|
|
1517
|
-
}
|
|
1518
|
-
function _(n) {
|
|
1519
|
-
const a = {
|
|
1520
|
-
a: n.a,
|
|
1521
|
-
b: n.b,
|
|
1522
|
-
p: n.Fp.ORDER,
|
|
1523
|
-
n: n.n,
|
|
1524
|
-
h: n.h,
|
|
1525
|
-
Gx: n.Gx,
|
|
1526
|
-
Gy: n.Gy
|
|
1527
|
-
}, i = n.Fp;
|
|
1528
|
-
let o = n.allowedPrivateKeyLengths ? Array.from(new Set(n.allowedPrivateKeyLengths.map((s) => Math.ceil(s / 2)))) : void 0;
|
|
1529
|
-
const h = (0, m.Field)(a.n, {
|
|
1530
|
-
BITS: n.nBitLength,
|
|
1531
|
-
allowedLengths: o,
|
|
1532
|
-
modFromBytes: n.wrapPrivateKey
|
|
1533
|
-
}), w = {
|
|
1534
|
-
Fp: i,
|
|
1535
|
-
Fn: h,
|
|
1536
|
-
allowInfinityPoint: n.allowInfinityPoint,
|
|
1537
|
-
endo: n.endo,
|
|
1538
|
-
isTorsionFree: n.isTorsionFree,
|
|
1539
|
-
clearCofactor: n.clearCofactor,
|
|
1540
|
-
fromBytes: n.fromBytes,
|
|
1541
|
-
toBytes: n.toBytes
|
|
1542
|
-
};
|
|
1543
|
-
return { CURVE: a, curveOpts: w };
|
|
1544
|
-
}
|
|
1545
|
-
function K(n) {
|
|
1546
|
-
const { CURVE: a, curveOpts: i } = _(n), o = {
|
|
1547
|
-
hmac: n.hmac,
|
|
1548
|
-
randomBytes: n.randomBytes,
|
|
1549
|
-
lowS: n.lowS,
|
|
1550
|
-
bits2int: n.bits2int,
|
|
1551
|
-
bits2int_modN: n.bits2int_modN
|
|
1552
|
-
};
|
|
1553
|
-
return { CURVE: a, curveOpts: i, hash: n.hash, ecdsaOpts: o };
|
|
1554
|
-
}
|
|
1555
|
-
function W(n, a, i) {
|
|
1556
|
-
function o(h) {
|
|
1557
|
-
const w = n.sqr(h), s = n.mul(w, h);
|
|
1558
|
-
return n.add(n.add(s, n.mul(h, a)), i);
|
|
1559
|
-
}
|
|
1560
|
-
return o;
|
|
1561
|
-
}
|
|
1562
|
-
function z(n, a) {
|
|
1563
|
-
const { Fp: i, Fn: o } = a;
|
|
1564
|
-
function h(s) {
|
|
1565
|
-
return (0, t.inRange)(s, E, o.ORDER);
|
|
1566
|
-
}
|
|
1567
|
-
const w = W(i, n.a, n.b);
|
|
1568
|
-
return Object.assign({}, {
|
|
1569
|
-
CURVE: n,
|
|
1570
|
-
Point: a,
|
|
1571
|
-
ProjectivePoint: a,
|
|
1572
|
-
normPrivateKeyToScalar: (s) => M(o, s),
|
|
1573
|
-
weierstrassEquation: w,
|
|
1574
|
-
isWithinCurveOrder: h
|
|
1575
|
-
});
|
|
1576
|
-
}
|
|
1577
|
-
function d(n, a) {
|
|
1578
|
-
const i = a.Point;
|
|
1579
|
-
return Object.assign({}, a, {
|
|
1580
|
-
ProjectivePoint: i,
|
|
1581
|
-
CURVE: Object.assign({}, n, (0, m.nLength)(i.Fn.ORDER, i.Fn.BITS))
|
|
1582
|
-
});
|
|
1583
|
-
}
|
|
1584
|
-
function u(n) {
|
|
1585
|
-
const { CURVE: a, curveOpts: i, hash: o, ecdsaOpts: h } = K(n), w = Q(a, i), s = O(w, o, h);
|
|
1586
|
-
return d(n, s);
|
|
1587
|
-
}
|
|
1588
|
-
})(nt)), nt;
|
|
1589
|
-
}
|
|
1590
|
-
var Ot;
|
|
1591
|
-
function En() {
|
|
1592
|
-
if (Ot) return Ke;
|
|
1593
|
-
Ot = 1, Object.defineProperty(Ke, "__esModule", { value: !0 }), Ke.getHash = r, Ke.createCurve = c;
|
|
1594
|
-
const e = /* @__PURE__ */ Ct();
|
|
1595
|
-
function r(t) {
|
|
1596
|
-
return { hash: t };
|
|
1597
|
-
}
|
|
1598
|
-
function c(t, l) {
|
|
1599
|
-
const m = (g) => (0, e.weierstrass)({ ...t, hash: g });
|
|
1600
|
-
return { ...m(l), create: m };
|
|
1601
|
-
}
|
|
1602
|
-
return Ke;
|
|
1603
|
-
}
|
|
1604
|
-
var ot = {}, Rt;
|
|
1605
|
-
function Bn() {
|
|
1606
|
-
return Rt || (Rt = 1, (function(e) {
|
|
1607
|
-
Object.defineProperty(e, "__esModule", { value: !0 }), e._DST_scalar = void 0, e.expand_message_xmd = v, e.expand_message_xof = U, e.hash_to_field = H, e.isogenyMap = k, e.createHasher = E;
|
|
1608
|
-
const r = /* @__PURE__ */ Ce(), c = /* @__PURE__ */ $e(), t = r.bytesToNumberBE;
|
|
1609
|
-
function l(b, S) {
|
|
1610
|
-
if (g(b), g(S), b < 0 || b >= 1 << 8 * S)
|
|
1611
|
-
throw new Error("invalid I2OSP input: " + b);
|
|
1612
|
-
const A = Array.from({ length: S }).fill(0);
|
|
1613
|
-
for (let M = S - 1; M >= 0; M--)
|
|
1614
|
-
A[M] = b & 255, b >>>= 8;
|
|
1615
|
-
return new Uint8Array(A);
|
|
1616
|
-
}
|
|
1617
|
-
function m(b, S) {
|
|
1618
|
-
const A = new Uint8Array(b.length);
|
|
1619
|
-
for (let M = 0; M < b.length; M++)
|
|
1620
|
-
A[M] = b[M] ^ S[M];
|
|
1621
|
-
return A;
|
|
1622
|
-
}
|
|
1623
|
-
function g(b) {
|
|
1624
|
-
if (!Number.isSafeInteger(b))
|
|
1625
|
-
throw new Error("number expected");
|
|
1626
|
-
}
|
|
1627
|
-
function p(b) {
|
|
1628
|
-
if (!(0, r.isBytes)(b) && typeof b != "string")
|
|
1629
|
-
throw new Error("DST must be Uint8Array or string");
|
|
1630
|
-
return typeof b == "string" ? (0, r.utf8ToBytes)(b) : b;
|
|
1631
|
-
}
|
|
1632
|
-
function v(b, S, A, M) {
|
|
1633
|
-
(0, r.abytes)(b), g(A), S = p(S), S.length > 255 && (S = M((0, r.concatBytes)((0, r.utf8ToBytes)("H2C-OVERSIZE-DST-"), S)));
|
|
1634
|
-
const { outputLen: Q, blockLen: F } = M, G = Math.ceil(A / Q);
|
|
1635
|
-
if (A > 65535 || G > 255)
|
|
1636
|
-
throw new Error("expand_message_xmd: invalid lenInBytes");
|
|
1637
|
-
const se = (0, r.concatBytes)(S, l(S.length, 1)), ie = l(0, F), j = l(A, 2), O = new Array(G), L = M((0, r.concatBytes)(ie, b, j, l(0, 1), se));
|
|
1638
|
-
O[0] = M((0, r.concatBytes)(L, l(1, 1), se));
|
|
1639
|
-
for (let K = 1; K <= G; K++) {
|
|
1640
|
-
const W = [m(L, O[K - 1]), l(K + 1, 1), se];
|
|
1641
|
-
O[K] = M((0, r.concatBytes)(...W));
|
|
1642
|
-
}
|
|
1643
|
-
return (0, r.concatBytes)(...O).slice(0, A);
|
|
1644
|
-
}
|
|
1645
|
-
function U(b, S, A, M, Q) {
|
|
1646
|
-
if ((0, r.abytes)(b), g(A), S = p(S), S.length > 255) {
|
|
1647
|
-
const F = Math.ceil(2 * M / 8);
|
|
1648
|
-
S = Q.create({ dkLen: F }).update((0, r.utf8ToBytes)("H2C-OVERSIZE-DST-")).update(S).digest();
|
|
1649
|
-
}
|
|
1650
|
-
if (A > 65535 || S.length > 255)
|
|
1651
|
-
throw new Error("expand_message_xof: invalid lenInBytes");
|
|
1652
|
-
return Q.create({ dkLen: A }).update(b).update(l(A, 2)).update(S).update(l(S.length, 1)).digest();
|
|
1653
|
-
}
|
|
1654
|
-
function H(b, S, A) {
|
|
1655
|
-
(0, r._validateObject)(A, {
|
|
1656
|
-
p: "bigint",
|
|
1657
|
-
m: "number",
|
|
1658
|
-
k: "number",
|
|
1659
|
-
hash: "function"
|
|
1660
|
-
});
|
|
1661
|
-
const { p: M, k: Q, m: F, hash: G, expand: se, DST: ie } = A;
|
|
1662
|
-
if (!(0, r.isHash)(A.hash))
|
|
1663
|
-
throw new Error("expected valid hash");
|
|
1664
|
-
(0, r.abytes)(b), g(S);
|
|
1665
|
-
const j = M.toString(2).length, O = Math.ceil((j + Q) / 8), L = S * F * O;
|
|
1666
|
-
let _;
|
|
1667
|
-
if (se === "xmd")
|
|
1668
|
-
_ = v(b, ie, L, G);
|
|
1669
|
-
else if (se === "xof")
|
|
1670
|
-
_ = U(b, ie, L, Q, G);
|
|
1671
|
-
else if (se === "_internal_pass")
|
|
1672
|
-
_ = b;
|
|
1673
|
-
else
|
|
1674
|
-
throw new Error('expand must be "xmd" or "xof"');
|
|
1675
|
-
const K = new Array(S);
|
|
1676
|
-
for (let W = 0; W < S; W++) {
|
|
1677
|
-
const z = new Array(F);
|
|
1678
|
-
for (let d = 0; d < F; d++) {
|
|
1679
|
-
const u = O * (d + W * F), n = _.subarray(u, u + O);
|
|
1680
|
-
z[d] = (0, c.mod)(t(n), M);
|
|
1681
|
-
}
|
|
1682
|
-
K[W] = z;
|
|
1683
|
-
}
|
|
1684
|
-
return K;
|
|
1685
|
-
}
|
|
1686
|
-
function k(b, S) {
|
|
1687
|
-
const A = S.map((M) => Array.from(M).reverse());
|
|
1688
|
-
return (M, Q) => {
|
|
1689
|
-
const [F, G, se, ie] = A.map((L) => L.reduce((_, K) => b.add(b.mul(_, M), K))), [j, O] = (0, c.FpInvertBatch)(b, [G, ie], !0);
|
|
1690
|
-
return M = b.mul(F, j), Q = b.mul(Q, b.mul(se, O)), { x: M, y: Q };
|
|
1691
|
-
};
|
|
1692
|
-
}
|
|
1693
|
-
e._DST_scalar = (0, r.utf8ToBytes)("HashToScalar-");
|
|
1694
|
-
function E(b, S, A) {
|
|
1695
|
-
if (typeof S != "function")
|
|
1696
|
-
throw new Error("mapToCurve() must be defined");
|
|
1697
|
-
function M(F) {
|
|
1698
|
-
return b.fromAffine(S(F));
|
|
1699
|
-
}
|
|
1700
|
-
function Q(F) {
|
|
1701
|
-
const G = F.clearCofactor();
|
|
1702
|
-
return G.equals(b.ZERO) ? b.ZERO : (G.assertValidity(), G);
|
|
1703
|
-
}
|
|
1704
|
-
return {
|
|
1705
|
-
defaults: A,
|
|
1706
|
-
hashToCurve(F, G) {
|
|
1707
|
-
const se = Object.assign({}, A, G), ie = H(F, 2, se), j = M(ie[0]), O = M(ie[1]);
|
|
1708
|
-
return Q(j.add(O));
|
|
1709
|
-
},
|
|
1710
|
-
encodeToCurve(F, G) {
|
|
1711
|
-
const se = A.encodeDST ? { DST: A.encodeDST } : {}, ie = Object.assign({}, A, se, G), j = H(F, 1, ie), O = M(j[0]);
|
|
1712
|
-
return Q(O);
|
|
1713
|
-
},
|
|
1714
|
-
/** See {@link H2CHasher} */
|
|
1715
|
-
mapToCurve(F) {
|
|
1716
|
-
if (!Array.isArray(F))
|
|
1717
|
-
throw new Error("expected array of bigints");
|
|
1718
|
-
for (const G of F)
|
|
1719
|
-
if (typeof G != "bigint")
|
|
1720
|
-
throw new Error("expected array of bigints");
|
|
1721
|
-
return Q(M(F));
|
|
1722
|
-
},
|
|
1723
|
-
// hash_to_scalar can produce 0: https://www.rfc-editor.org/errata/eid8393
|
|
1724
|
-
// RFC 9380, draft-irtf-cfrg-bbs-signatures-08
|
|
1725
|
-
hashToScalar(F, G) {
|
|
1726
|
-
const se = b.Fn.ORDER, ie = Object.assign({}, A, { p: se, m: 1, DST: e._DST_scalar }, G);
|
|
1727
|
-
return H(F, 1, ie)[0][0];
|
|
1728
|
-
}
|
|
1729
|
-
};
|
|
1730
|
-
}
|
|
1731
|
-
})(ot)), ot;
|
|
1732
|
-
}
|
|
1733
|
-
var qt;
|
|
1734
|
-
function er() {
|
|
1735
|
-
return qt || (qt = 1, (function(e) {
|
|
1736
|
-
Object.defineProperty(e, "__esModule", { value: !0 }), e.encodeToCurve = e.hashToCurve = e.secp256k1_hasher = e.schnorr = e.secp256k1 = void 0;
|
|
1737
|
-
const r = /* @__PURE__ */ dn(), c = /* @__PURE__ */ We(), t = /* @__PURE__ */ En(), l = /* @__PURE__ */ Bn(), m = /* @__PURE__ */ $e(), g = /* @__PURE__ */ Ct(), p = /* @__PURE__ */ Ce(), v = {
|
|
1738
|
-
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
1739
|
-
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
1740
|
-
h: BigInt(1),
|
|
1741
|
-
a: BigInt(0),
|
|
1742
|
-
b: BigInt(7),
|
|
1743
|
-
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
1744
|
-
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
1745
|
-
}, U = {
|
|
1746
|
-
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
1747
|
-
basises: [
|
|
1748
|
-
[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
|
|
1749
|
-
[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
|
|
1750
|
-
]
|
|
1751
|
-
}, H = /* @__PURE__ */ BigInt(0), k = /* @__PURE__ */ BigInt(1), E = /* @__PURE__ */ BigInt(2);
|
|
1752
|
-
function b(d) {
|
|
1753
|
-
const u = v.p, n = BigInt(3), a = BigInt(6), i = BigInt(11), o = BigInt(22), h = BigInt(23), w = BigInt(44), s = BigInt(88), f = d * d * d % u, y = f * f * d % u, B = (0, m.pow2)(y, n, u) * y % u, T = (0, m.pow2)(B, n, u) * y % u, V = (0, m.pow2)(T, E, u) * f % u, Y = (0, m.pow2)(V, i, u) * V % u, I = (0, m.pow2)(Y, o, u) * Y % u, q = (0, m.pow2)(I, w, u) * I % u, C = (0, m.pow2)(q, s, u) * q % u, te = (0, m.pow2)(C, w, u) * I % u, $ = (0, m.pow2)(te, n, u) * y % u, x = (0, m.pow2)($, h, u) * Y % u, X = (0, m.pow2)(x, a, u) * f % u, ae = (0, m.pow2)(X, E, u);
|
|
1754
|
-
if (!S.eql(S.sqr(ae), d))
|
|
1755
|
-
throw new Error("Cannot find square root");
|
|
1756
|
-
return ae;
|
|
1757
|
-
}
|
|
1758
|
-
const S = (0, m.Field)(v.p, { sqrt: b });
|
|
1759
|
-
e.secp256k1 = (0, t.createCurve)({ ...v, Fp: S, lowS: !0, endo: U }, r.sha256);
|
|
1760
|
-
const A = {};
|
|
1761
|
-
function M(d, ...u) {
|
|
1762
|
-
let n = A[d];
|
|
1763
|
-
if (n === void 0) {
|
|
1764
|
-
const a = (0, r.sha256)((0, p.utf8ToBytes)(d));
|
|
1765
|
-
n = (0, p.concatBytes)(a, a), A[d] = n;
|
|
1766
|
-
}
|
|
1767
|
-
return (0, r.sha256)((0, p.concatBytes)(n, ...u));
|
|
1768
|
-
}
|
|
1769
|
-
const Q = (d) => d.toBytes(!0).slice(1), F = e.secp256k1.Point, G = (d) => d % E === H;
|
|
1770
|
-
function se(d) {
|
|
1771
|
-
const { Fn: u, BASE: n } = F, a = (0, g._normFnElement)(u, d), i = n.multiply(a);
|
|
1772
|
-
return { scalar: G(i.y) ? a : u.neg(a), bytes: Q(i) };
|
|
1773
|
-
}
|
|
1774
|
-
function ie(d) {
|
|
1775
|
-
const u = S;
|
|
1776
|
-
if (!u.isValidNot0(d))
|
|
1777
|
-
throw new Error("invalid x: Fail if x ≥ p");
|
|
1778
|
-
const n = u.create(d * d), a = u.create(n * d + BigInt(7));
|
|
1779
|
-
let i = u.sqrt(a);
|
|
1780
|
-
G(i) || (i = u.neg(i));
|
|
1781
|
-
const o = F.fromAffine({ x: d, y: i });
|
|
1782
|
-
return o.assertValidity(), o;
|
|
1783
|
-
}
|
|
1784
|
-
const j = p.bytesToNumberBE;
|
|
1785
|
-
function O(...d) {
|
|
1786
|
-
return F.Fn.create(j(M("BIP0340/challenge", ...d)));
|
|
1787
|
-
}
|
|
1788
|
-
function L(d) {
|
|
1789
|
-
return se(d).bytes;
|
|
1790
|
-
}
|
|
1791
|
-
function _(d, u, n = (0, c.randomBytes)(32)) {
|
|
1792
|
-
const { Fn: a } = F, i = (0, p.ensureBytes)("message", d), { bytes: o, scalar: h } = se(u), w = (0, p.ensureBytes)("auxRand", n, 32), s = a.toBytes(h ^ j(M("BIP0340/aux", w))), f = M("BIP0340/nonce", s, o, i), { bytes: y, scalar: B } = se(f), T = O(y, o, i), V = new Uint8Array(64);
|
|
1793
|
-
if (V.set(y, 0), V.set(a.toBytes(a.create(B + T * h)), 32), !K(V, i, o))
|
|
1794
|
-
throw new Error("sign: Invalid signature produced");
|
|
1795
|
-
return V;
|
|
1796
|
-
}
|
|
1797
|
-
function K(d, u, n) {
|
|
1798
|
-
const { Fn: a, BASE: i } = F, o = (0, p.ensureBytes)("signature", d, 64), h = (0, p.ensureBytes)("message", u), w = (0, p.ensureBytes)("publicKey", n, 32);
|
|
1799
|
-
try {
|
|
1800
|
-
const s = ie(j(w)), f = j(o.subarray(0, 32));
|
|
1801
|
-
if (!(0, p.inRange)(f, k, v.p))
|
|
1802
|
-
return !1;
|
|
1803
|
-
const y = j(o.subarray(32, 64));
|
|
1804
|
-
if (!(0, p.inRange)(y, k, v.n))
|
|
1805
|
-
return !1;
|
|
1806
|
-
const B = O(a.toBytes(f), Q(s), h), T = i.multiplyUnsafe(y).add(s.multiplyUnsafe(a.neg(B))), { x: V, y: Y } = T.toAffine();
|
|
1807
|
-
return !(T.is0() || !G(Y) || V !== f);
|
|
1808
|
-
} catch {
|
|
1809
|
-
return !1;
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
e.schnorr = (() => {
|
|
1813
|
-
const n = (i = (0, c.randomBytes)(48)) => (0, m.mapHashToField)(i, v.n);
|
|
1814
|
-
e.secp256k1.utils.randomSecretKey;
|
|
1815
|
-
function a(i) {
|
|
1816
|
-
const o = n(i);
|
|
1817
|
-
return { secretKey: o, publicKey: L(o) };
|
|
1818
|
-
}
|
|
1819
|
-
return {
|
|
1820
|
-
keygen: a,
|
|
1821
|
-
getPublicKey: L,
|
|
1822
|
-
sign: _,
|
|
1823
|
-
verify: K,
|
|
1824
|
-
Point: F,
|
|
1825
|
-
utils: {
|
|
1826
|
-
randomSecretKey: n,
|
|
1827
|
-
randomPrivateKey: n,
|
|
1828
|
-
taggedHash: M,
|
|
1829
|
-
// TODO: remove
|
|
1830
|
-
lift_x: ie,
|
|
1831
|
-
pointToBytes: Q,
|
|
1832
|
-
numberToBytesBE: p.numberToBytesBE,
|
|
1833
|
-
bytesToNumberBE: p.bytesToNumberBE,
|
|
1834
|
-
mod: m.mod
|
|
1835
|
-
},
|
|
1836
|
-
lengths: {
|
|
1837
|
-
secretKey: 32,
|
|
1838
|
-
publicKey: 32,
|
|
1839
|
-
publicKeyHasPrefix: !1,
|
|
1840
|
-
signature: 64,
|
|
1841
|
-
seed: 48
|
|
1842
|
-
}
|
|
1843
|
-
};
|
|
1844
|
-
})();
|
|
1845
|
-
const W = (0, l.isogenyMap)(S, [
|
|
1846
|
-
// xNum
|
|
1847
|
-
[
|
|
1848
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7",
|
|
1849
|
-
"0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581",
|
|
1850
|
-
"0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262",
|
|
1851
|
-
"0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"
|
|
1852
|
-
],
|
|
1853
|
-
// xDen
|
|
1854
|
-
[
|
|
1855
|
-
"0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b",
|
|
1856
|
-
"0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14",
|
|
1857
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
1858
|
-
// LAST 1
|
|
1859
|
-
],
|
|
1860
|
-
// yNum
|
|
1861
|
-
[
|
|
1862
|
-
"0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c",
|
|
1863
|
-
"0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3",
|
|
1864
|
-
"0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931",
|
|
1865
|
-
"0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"
|
|
1866
|
-
],
|
|
1867
|
-
// yDen
|
|
1868
|
-
[
|
|
1869
|
-
"0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b",
|
|
1870
|
-
"0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573",
|
|
1871
|
-
"0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f",
|
|
1872
|
-
"0x0000000000000000000000000000000000000000000000000000000000000001"
|
|
1873
|
-
// LAST 1
|
|
1874
|
-
]
|
|
1875
|
-
].map((d) => d.map((u) => BigInt(u)))), z = (0, g.mapToCurveSimpleSWU)(S, {
|
|
1876
|
-
A: BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),
|
|
1877
|
-
B: BigInt("1771"),
|
|
1878
|
-
Z: S.create(BigInt("-11"))
|
|
1879
|
-
});
|
|
1880
|
-
e.secp256k1_hasher = (0, l.createHasher)(e.secp256k1.Point, (d) => {
|
|
1881
|
-
const { x: u, y: n } = z(S.create(d[0]));
|
|
1882
|
-
return W(u, n);
|
|
1883
|
-
}, {
|
|
1884
|
-
DST: "secp256k1_XMD:SHA-256_SSWU_RO_",
|
|
1885
|
-
encodeDST: "secp256k1_XMD:SHA-256_SSWU_NU_",
|
|
1886
|
-
p: S.ORDER,
|
|
1887
|
-
m: 1,
|
|
1888
|
-
k: 128,
|
|
1889
|
-
expand: "xmd",
|
|
1890
|
-
hash: r.sha256
|
|
1891
|
-
}), e.hashToCurve = e.secp256k1_hasher.hashToCurve, e.encodeToCurve = e.secp256k1_hasher.encodeToCurve;
|
|
1892
|
-
})(tt)), tt;
|
|
1893
|
-
}
|
|
1894
|
-
var P = {}, It;
|
|
1895
|
-
function tr() {
|
|
1896
|
-
if (It) return P;
|
|
1897
|
-
It = 1, Object.defineProperty(P, "__esModule", { value: !0 }), P.isHash = P.validateObject = P.memoized = P.notImplemented = P.createHmacDrbg = P.bitMask = P.bitSet = P.bitGet = P.bitLen = P.aInRange = P.inRange = P.asciiToBytes = P.copyBytes = P.equalBytes = P.ensureBytes = P.numberToVarBytesBE = P.numberToBytesLE = P.numberToBytesBE = P.bytesToNumberLE = P.bytesToNumberBE = P.hexToNumber = P.numberToHexUnpadded = P.abool = P.utf8ToBytes = P.randomBytes = P.isBytes = P.hexToBytes = P.concatBytes = P.bytesToUtf8 = P.bytesToHex = P.anumber = P.abytes = void 0;
|
|
1898
|
-
const e = /* @__PURE__ */ Ce();
|
|
1899
|
-
return P.abytes = e.abytes, P.anumber = e.anumber, P.bytesToHex = e.bytesToHex, P.bytesToUtf8 = e.bytesToUtf8, P.concatBytes = e.concatBytes, P.hexToBytes = e.hexToBytes, P.isBytes = e.isBytes, P.randomBytes = e.randomBytes, P.utf8ToBytes = e.utf8ToBytes, P.abool = e.abool, P.numberToHexUnpadded = e.numberToHexUnpadded, P.hexToNumber = e.hexToNumber, P.bytesToNumberBE = e.bytesToNumberBE, P.bytesToNumberLE = e.bytesToNumberLE, P.numberToBytesBE = e.numberToBytesBE, P.numberToBytesLE = e.numberToBytesLE, P.numberToVarBytesBE = e.numberToVarBytesBE, P.ensureBytes = e.ensureBytes, P.equalBytes = e.equalBytes, P.copyBytes = e.copyBytes, P.asciiToBytes = e.asciiToBytes, P.inRange = e.inRange, P.aInRange = e.aInRange, P.bitLen = e.bitLen, P.bitGet = e.bitGet, P.bitSet = e.bitSet, P.bitMask = e.bitMask, P.createHmacDrbg = e.createHmacDrbg, P.notImplemented = e.notImplemented, P.memoized = e.memoized, P.validateObject = e.validateObject, P.isHash = e.isHash, P;
|
|
1900
|
-
}
|
|
1901
|
-
function nr(e, r = "") {
|
|
1902
|
-
if (typeof e != "boolean") {
|
|
1903
|
-
const c = r && `"${r}" `;
|
|
1904
|
-
throw new Error(c + "expected boolean, got type=" + typeof e);
|
|
1905
|
-
}
|
|
1906
|
-
return e;
|
|
1907
|
-
}
|
|
1908
|
-
function mt(e) {
|
|
1909
|
-
if (!Number.isSafeInteger(e) || e < 0 || e > 4294967295)
|
|
1910
|
-
throw new Error("wrong u32 integer:" + e);
|
|
1911
|
-
return e;
|
|
1
|
+
import { p as ht, q as it, e as V, t as lt, f as J, u as de, d as Mt, v as ae, i as Kt, w as he } from "./noble-hashes.js";
|
|
2
|
+
const Rt = /* @__PURE__ */ BigInt(0), Bt = /* @__PURE__ */ BigInt(1);
|
|
3
|
+
function dt(n, t = "") {
|
|
4
|
+
if (typeof n != "boolean") {
|
|
5
|
+
const r = t && `"${t}" `;
|
|
6
|
+
throw new Error(r + "expected boolean, got type=" + typeof n);
|
|
7
|
+
}
|
|
8
|
+
return n;
|
|
9
|
+
}
|
|
10
|
+
function zt(n) {
|
|
11
|
+
if (typeof n == "bigint") {
|
|
12
|
+
if (!ut(n))
|
|
13
|
+
throw new Error("positive bigint expected, got " + n);
|
|
14
|
+
} else
|
|
15
|
+
it(n);
|
|
16
|
+
return n;
|
|
1912
17
|
}
|
|
1913
|
-
function
|
|
1914
|
-
|
|
18
|
+
function ct(n) {
|
|
19
|
+
const t = zt(n).toString(16);
|
|
20
|
+
return t.length & 1 ? "0" + t : t;
|
|
1915
21
|
}
|
|
1916
|
-
function
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
c = c << 1 | e & 1;
|
|
1921
|
-
return c;
|
|
22
|
+
function Ct(n) {
|
|
23
|
+
if (typeof n != "string")
|
|
24
|
+
throw new Error("hex string expected, got " + typeof n);
|
|
25
|
+
return n === "" ? Rt : BigInt("0x" + n);
|
|
1922
26
|
}
|
|
1923
|
-
function
|
|
1924
|
-
return
|
|
27
|
+
function wt(n) {
|
|
28
|
+
return Ct(ht(n));
|
|
1925
29
|
}
|
|
1926
|
-
function
|
|
1927
|
-
|
|
1928
|
-
if (r < 2 || !Kt(r))
|
|
1929
|
-
throw new Error("n must be a power of 2 and greater than 1. Got " + r);
|
|
1930
|
-
const c = zt(r);
|
|
1931
|
-
for (let t = 0; t < r; t++) {
|
|
1932
|
-
const l = pn(t, c);
|
|
1933
|
-
if (t < l) {
|
|
1934
|
-
const m = e[t];
|
|
1935
|
-
e[t] = e[l], e[l] = m;
|
|
1936
|
-
}
|
|
1937
|
-
}
|
|
1938
|
-
return e;
|
|
30
|
+
function Ht(n) {
|
|
31
|
+
return Ct(ht(we(V(n)).reverse()));
|
|
1939
32
|
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
return
|
|
1946
|
-
if (H.length !== c)
|
|
1947
|
-
throw new Error("FFT: wrong Polynomial length");
|
|
1948
|
-
l && p && Nt(H);
|
|
1949
|
-
for (let k = 0, E = 1; k < v - g; k++) {
|
|
1950
|
-
const b = l ? k + 1 + g : v - k, S = 1 << b, A = S >> 1, M = c >> b;
|
|
1951
|
-
for (let Q = 0; Q < c; Q += S)
|
|
1952
|
-
for (let F = 0, G = E++; F < A; F++) {
|
|
1953
|
-
const se = m ? l ? c - G : G : F * M, ie = Q + F, j = Q + F + A, O = t[se], L = H[j], _ = H[ie];
|
|
1954
|
-
if (U) {
|
|
1955
|
-
const K = e.mul(L, O);
|
|
1956
|
-
H[ie] = e.add(_, K), H[j] = e.sub(_, K);
|
|
1957
|
-
} else m ? (H[ie] = e.add(L, _), H[j] = e.mul(e.sub(L, _), O)) : (H[ie] = e.add(_, L), H[j] = e.mul(e.sub(_, L), O));
|
|
1958
|
-
}
|
|
1959
|
-
}
|
|
1960
|
-
return !l && p && Nt(H), H;
|
|
1961
|
-
};
|
|
1962
|
-
};
|
|
1963
|
-
const bt = /* @__PURE__ */ BigInt(0), lt = /* @__PURE__ */ BigInt(1);
|
|
1964
|
-
function Je(e, r = "") {
|
|
1965
|
-
if (typeof e != "boolean") {
|
|
1966
|
-
const c = r && `"${r}"`;
|
|
1967
|
-
throw new Error(c + "expected boolean, got type=" + typeof e);
|
|
1968
|
-
}
|
|
1969
|
-
return e;
|
|
1970
|
-
}
|
|
1971
|
-
function Ze(e, r, c = "") {
|
|
1972
|
-
const t = yt(e), l = e?.length, m = r !== void 0;
|
|
1973
|
-
if (!t || m && l !== r) {
|
|
1974
|
-
const g = c && `"${c}" `, p = m ? ` of length ${r}` : "", v = t ? `length=${l}` : `type=${typeof e}`;
|
|
1975
|
-
throw new Error(g + "expected Uint8Array" + p + ", got " + v);
|
|
1976
|
-
}
|
|
1977
|
-
return e;
|
|
1978
|
-
}
|
|
1979
|
-
function Xe(e) {
|
|
1980
|
-
const r = e.toString(16);
|
|
1981
|
-
return r.length & 1 ? "0" + r : r;
|
|
1982
|
-
}
|
|
1983
|
-
function Dt(e) {
|
|
1984
|
-
if (typeof e != "string")
|
|
1985
|
-
throw new Error("hex string expected, got " + typeof e);
|
|
1986
|
-
return e === "" ? bt : BigInt("0x" + e);
|
|
33
|
+
function xt(n, t) {
|
|
34
|
+
it(t), n = zt(n);
|
|
35
|
+
const r = lt(n.toString(16).padStart(t * 2, "0"));
|
|
36
|
+
if (r.length !== t)
|
|
37
|
+
throw new Error("number too large");
|
|
38
|
+
return r;
|
|
1987
39
|
}
|
|
1988
|
-
function
|
|
1989
|
-
return
|
|
40
|
+
function Xt(n, t) {
|
|
41
|
+
return xt(n, t).reverse();
|
|
1990
42
|
}
|
|
1991
|
-
function
|
|
1992
|
-
return
|
|
43
|
+
function we(n) {
|
|
44
|
+
return Uint8Array.from(n);
|
|
1993
45
|
}
|
|
1994
|
-
|
|
1995
|
-
|
|
46
|
+
const ut = (n) => typeof n == "bigint" && Rt <= n;
|
|
47
|
+
function ge(n, t, r) {
|
|
48
|
+
return ut(n) && ut(t) && ut(r) && t <= n && n < r;
|
|
1996
49
|
}
|
|
1997
|
-
function
|
|
1998
|
-
|
|
50
|
+
function me(n, t, r, e) {
|
|
51
|
+
if (!ge(t, r, e))
|
|
52
|
+
throw new Error("expected valid " + n + ": " + r + " <= n < " + e + ", got " + t);
|
|
1999
53
|
}
|
|
2000
|
-
function
|
|
54
|
+
function be(n) {
|
|
2001
55
|
let t;
|
|
2002
|
-
|
|
2003
|
-
try {
|
|
2004
|
-
t = Qe(r);
|
|
2005
|
-
} catch (l) {
|
|
2006
|
-
throw new Error(e + " must be hex string or Uint8Array, cause: " + l);
|
|
2007
|
-
}
|
|
2008
|
-
else if (yt(r))
|
|
2009
|
-
t = Uint8Array.from(r);
|
|
2010
|
-
else
|
|
2011
|
-
throw new Error(e + " must be hex string or Uint8Array");
|
|
2012
|
-
return t.length, t;
|
|
2013
|
-
}
|
|
2014
|
-
const st = (e) => typeof e == "bigint" && bt <= e;
|
|
2015
|
-
function vn(e, r, c) {
|
|
2016
|
-
return st(e) && st(r) && st(c) && r <= e && e < c;
|
|
2017
|
-
}
|
|
2018
|
-
function _n(e, r, c, t) {
|
|
2019
|
-
if (!vn(r, c, t))
|
|
2020
|
-
throw new Error("expected valid " + e + ": " + c + " <= n < " + t + ", got " + r);
|
|
2021
|
-
}
|
|
2022
|
-
function Xt(e) {
|
|
2023
|
-
let r;
|
|
2024
|
-
for (r = 0; e > bt; e >>= lt, r += 1)
|
|
56
|
+
for (t = 0; n > Rt; n >>= Bt, t += 1)
|
|
2025
57
|
;
|
|
2026
|
-
return
|
|
58
|
+
return t;
|
|
2027
59
|
}
|
|
2028
|
-
const
|
|
2029
|
-
function
|
|
2030
|
-
if (
|
|
2031
|
-
throw new Error("hashLen must be a number");
|
|
2032
|
-
if (typeof r != "number" || r < 2)
|
|
2033
|
-
throw new Error("qByteLen must be a number");
|
|
2034
|
-
if (typeof c != "function")
|
|
60
|
+
const St = (n) => (Bt << BigInt(n)) - Bt;
|
|
61
|
+
function Ee(n, t, r) {
|
|
62
|
+
if (it(n, "hashLen"), it(t, "qByteLen"), typeof r != "function")
|
|
2035
63
|
throw new Error("hmacFn must be a function");
|
|
2036
|
-
const
|
|
2037
|
-
let
|
|
2038
|
-
const
|
|
2039
|
-
|
|
2040
|
-
},
|
|
2041
|
-
|
|
2042
|
-
},
|
|
2043
|
-
if (
|
|
2044
|
-
throw new Error("drbg: tried
|
|
2045
|
-
let
|
|
2046
|
-
const
|
|
2047
|
-
for (;
|
|
2048
|
-
|
|
2049
|
-
const
|
|
2050
|
-
|
|
2051
|
-
}
|
|
2052
|
-
return
|
|
64
|
+
const e = (R) => new Uint8Array(R), o = Uint8Array.of(), s = Uint8Array.of(0), i = Uint8Array.of(1), u = 1e3;
|
|
65
|
+
let c = e(n), a = e(n), w = 0;
|
|
66
|
+
const S = () => {
|
|
67
|
+
c.fill(1), a.fill(0), w = 0;
|
|
68
|
+
}, q = (...R) => r(a, J(c, ...R)), B = (R = o) => {
|
|
69
|
+
a = q(s, R), c = q(), R.length !== 0 && (a = q(i, R), c = q());
|
|
70
|
+
}, v = () => {
|
|
71
|
+
if (w++ >= u)
|
|
72
|
+
throw new Error("drbg: tried max amount of iterations");
|
|
73
|
+
let R = 0;
|
|
74
|
+
const N = [];
|
|
75
|
+
for (; R < t; ) {
|
|
76
|
+
c = q();
|
|
77
|
+
const T = c.slice();
|
|
78
|
+
N.push(T), R += c.length;
|
|
79
|
+
}
|
|
80
|
+
return J(...N);
|
|
2053
81
|
};
|
|
2054
|
-
return (
|
|
2055
|
-
|
|
2056
|
-
let
|
|
2057
|
-
for (; !(
|
|
2058
|
-
|
|
2059
|
-
return
|
|
82
|
+
return (R, N) => {
|
|
83
|
+
S(), B(R);
|
|
84
|
+
let T;
|
|
85
|
+
for (; !(T = N(v())); )
|
|
86
|
+
B();
|
|
87
|
+
return S(), T;
|
|
2060
88
|
};
|
|
2061
89
|
}
|
|
2062
|
-
function
|
|
2063
|
-
if (!
|
|
90
|
+
function Ot(n, t = {}, r = {}) {
|
|
91
|
+
if (!n || typeof n != "object")
|
|
2064
92
|
throw new Error("expected valid options object");
|
|
2065
|
-
function
|
|
2066
|
-
const
|
|
2067
|
-
if (
|
|
93
|
+
function e(s, i, u) {
|
|
94
|
+
const c = n[s];
|
|
95
|
+
if (u && c === void 0)
|
|
2068
96
|
return;
|
|
2069
|
-
const
|
|
2070
|
-
if (
|
|
2071
|
-
throw new Error(`param "${
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
97
|
+
const a = typeof c;
|
|
98
|
+
if (a !== i || c === null)
|
|
99
|
+
throw new Error(`param "${s}" is invalid: expected ${i}, got ${a}`);
|
|
100
|
+
}
|
|
101
|
+
const o = (s, i) => Object.entries(s).forEach(([u, c]) => e(u, c, i));
|
|
102
|
+
o(t, !1), o(r, !0);
|
|
103
|
+
}
|
|
104
|
+
function At(n) {
|
|
105
|
+
const t = /* @__PURE__ */ new WeakMap();
|
|
106
|
+
return (r, ...e) => {
|
|
107
|
+
const o = t.get(r);
|
|
108
|
+
if (o !== void 0)
|
|
109
|
+
return o;
|
|
110
|
+
const s = n(r, ...e);
|
|
111
|
+
return t.set(r, s), s;
|
|
2083
112
|
};
|
|
2084
113
|
}
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
return
|
|
114
|
+
function qt(n) {
|
|
115
|
+
if (!Number.isSafeInteger(n) || n < 0 || n > 4294967295)
|
|
116
|
+
throw new Error("wrong u32 integer:" + n);
|
|
117
|
+
return n;
|
|
2089
118
|
}
|
|
2090
|
-
function
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
119
|
+
function Gt(n) {
|
|
120
|
+
return qt(n), (n & n - 1) === 0 && n !== 0;
|
|
121
|
+
}
|
|
122
|
+
function ye(n, t) {
|
|
123
|
+
qt(n);
|
|
124
|
+
let r = 0;
|
|
125
|
+
for (let e = 0; e < t; e++, n >>>= 1)
|
|
126
|
+
r = r << 1 | n & 1;
|
|
127
|
+
return r;
|
|
128
|
+
}
|
|
129
|
+
function Wt(n) {
|
|
130
|
+
return qt(n), 31 - Math.clz32(n);
|
|
2095
131
|
}
|
|
2096
|
-
function
|
|
2097
|
-
|
|
132
|
+
function Lt(n) {
|
|
133
|
+
const t = n.length;
|
|
134
|
+
if (t < 2 || !Gt(t))
|
|
135
|
+
throw new Error("n must be a power of 2 and greater than 1. Got " + t);
|
|
136
|
+
const r = Wt(t);
|
|
137
|
+
for (let e = 0; e < t; e++) {
|
|
138
|
+
const o = ye(e, r);
|
|
139
|
+
if (e < o) {
|
|
140
|
+
const s = n[e];
|
|
141
|
+
n[e] = n[o], n[o] = s;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
return n;
|
|
145
|
+
}
|
|
146
|
+
const Ce = (n, t) => {
|
|
147
|
+
const { N: r, roots: e, dit: o, invertButterflies: s = !1, skipStages: i = 0, brp: u = !0 } = t, c = Wt(r);
|
|
148
|
+
if (!Gt(r))
|
|
149
|
+
throw new Error("FFT: Polynomial size should be power of two");
|
|
150
|
+
const a = o !== s;
|
|
151
|
+
return (w) => {
|
|
152
|
+
if (w.length !== r)
|
|
153
|
+
throw new Error("FFT: wrong Polynomial length");
|
|
154
|
+
o && u && Lt(w);
|
|
155
|
+
for (let S = 0, q = 1; S < c - i; S++) {
|
|
156
|
+
const B = o ? S + 1 + i : c - S, v = 1 << B, _ = v >> 1, R = r >> B;
|
|
157
|
+
for (let N = 0; N < r; N += v)
|
|
158
|
+
for (let T = 0, C = q++; T < _; T++) {
|
|
159
|
+
const Y = s ? o ? r - C : C : T * R, K = N + T, M = N + T + _, F = e[Y], H = w[M], x = w[K];
|
|
160
|
+
if (a) {
|
|
161
|
+
const P = n.mul(H, F);
|
|
162
|
+
w[K] = n.add(x, P), w[M] = n.sub(x, P);
|
|
163
|
+
} else s ? (w[K] = n.add(H, x), w[M] = n.mul(n.sub(H, x), F)) : (w[K] = n.add(x, H), w[M] = n.mul(n.sub(x, H), F));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return !o && u && Lt(w), w;
|
|
167
|
+
};
|
|
168
|
+
};
|
|
169
|
+
const j = /* @__PURE__ */ BigInt(0), $ = /* @__PURE__ */ BigInt(1), et = /* @__PURE__ */ BigInt(2), Qt = /* @__PURE__ */ BigInt(3), Jt = /* @__PURE__ */ BigInt(4), Ft = /* @__PURE__ */ BigInt(5), Be = /* @__PURE__ */ BigInt(7), Pt = /* @__PURE__ */ BigInt(8), pe = /* @__PURE__ */ BigInt(9), te = /* @__PURE__ */ BigInt(16);
|
|
170
|
+
function X(n, t) {
|
|
171
|
+
const r = n % t;
|
|
172
|
+
return r >= j ? r : t + r;
|
|
173
|
+
}
|
|
174
|
+
function z(n, t, r) {
|
|
175
|
+
let e = n;
|
|
176
|
+
for (; t-- > j; )
|
|
177
|
+
e *= e, e %= r;
|
|
178
|
+
return e;
|
|
179
|
+
}
|
|
180
|
+
function Dt(n, t) {
|
|
181
|
+
if (n === j)
|
|
2098
182
|
throw new Error("invert: expected non-zero number");
|
|
2099
|
-
if (
|
|
2100
|
-
throw new Error("invert: expected positive modulus, got " +
|
|
2101
|
-
let
|
|
2102
|
-
for (;
|
|
2103
|
-
const
|
|
2104
|
-
|
|
2105
|
-
}
|
|
2106
|
-
if (
|
|
183
|
+
if (t <= j)
|
|
184
|
+
throw new Error("invert: expected positive modulus, got " + t);
|
|
185
|
+
let r = X(n, t), e = t, o = j, s = $;
|
|
186
|
+
for (; r !== j; ) {
|
|
187
|
+
const u = e / r, c = e % r, a = o - s * u;
|
|
188
|
+
e = r, r = c, o = s, s = a;
|
|
189
|
+
}
|
|
190
|
+
if (e !== $)
|
|
2107
191
|
throw new Error("invert: does not exist");
|
|
2108
|
-
return
|
|
192
|
+
return X(o, t);
|
|
2109
193
|
}
|
|
2110
|
-
function
|
|
2111
|
-
if (!
|
|
194
|
+
function It(n, t, r) {
|
|
195
|
+
if (!n.eql(n.sqr(t), r))
|
|
2112
196
|
throw new Error("Cannot find square root");
|
|
2113
197
|
}
|
|
2114
|
-
function
|
|
2115
|
-
const
|
|
2116
|
-
return
|
|
2117
|
-
}
|
|
2118
|
-
function
|
|
2119
|
-
const
|
|
2120
|
-
return
|
|
2121
|
-
}
|
|
2122
|
-
function
|
|
2123
|
-
const
|
|
2124
|
-
return (
|
|
2125
|
-
let
|
|
2126
|
-
const
|
|
2127
|
-
|
|
2128
|
-
const
|
|
2129
|
-
return
|
|
198
|
+
function ee(n, t) {
|
|
199
|
+
const r = (n.ORDER + $) / Jt, e = n.pow(t, r);
|
|
200
|
+
return It(n, e, t), e;
|
|
201
|
+
}
|
|
202
|
+
function ve(n, t) {
|
|
203
|
+
const r = (n.ORDER - Ft) / Pt, e = n.mul(t, et), o = n.pow(e, r), s = n.mul(t, o), i = n.mul(n.mul(s, et), o), u = n.mul(s, n.sub(i, n.ONE));
|
|
204
|
+
return It(n, u, t), u;
|
|
205
|
+
}
|
|
206
|
+
function Re(n) {
|
|
207
|
+
const t = gt(n), r = ne(n), e = r(t, t.neg(t.ONE)), o = r(t, e), s = r(t, t.neg(e)), i = (n + Be) / te;
|
|
208
|
+
return (u, c) => {
|
|
209
|
+
let a = u.pow(c, i), w = u.mul(a, e);
|
|
210
|
+
const S = u.mul(a, o), q = u.mul(a, s), B = u.eql(u.sqr(w), c), v = u.eql(u.sqr(S), c);
|
|
211
|
+
a = u.cmov(a, w, B), w = u.cmov(q, S, v);
|
|
212
|
+
const _ = u.eql(u.sqr(w), c), R = u.cmov(a, w, _);
|
|
213
|
+
return It(u, R, c), R;
|
|
2130
214
|
};
|
|
2131
215
|
}
|
|
2132
|
-
function
|
|
2133
|
-
if (
|
|
216
|
+
function ne(n) {
|
|
217
|
+
if (n < Qt)
|
|
2134
218
|
throw new Error("sqrt is not defined for small field");
|
|
2135
|
-
let
|
|
2136
|
-
for (;
|
|
2137
|
-
|
|
2138
|
-
let
|
|
2139
|
-
const
|
|
2140
|
-
for (;
|
|
2141
|
-
if (
|
|
219
|
+
let t = n - $, r = 0;
|
|
220
|
+
for (; t % et === j; )
|
|
221
|
+
t /= et, r++;
|
|
222
|
+
let e = et;
|
|
223
|
+
const o = gt(n);
|
|
224
|
+
for (; Tt(o, e) === 1; )
|
|
225
|
+
if (e++ > 1e3)
|
|
2142
226
|
throw new Error("Cannot find square root: probably non-prime P");
|
|
2143
|
-
if (
|
|
2144
|
-
return
|
|
2145
|
-
let
|
|
2146
|
-
const
|
|
2147
|
-
return function(
|
|
2148
|
-
if (
|
|
2149
|
-
return
|
|
2150
|
-
if (
|
|
227
|
+
if (r === 1)
|
|
228
|
+
return ee;
|
|
229
|
+
let s = o.pow(e, t);
|
|
230
|
+
const i = (t + $) / et;
|
|
231
|
+
return function(c, a) {
|
|
232
|
+
if (c.is0(a))
|
|
233
|
+
return a;
|
|
234
|
+
if (Tt(c, a) !== 1)
|
|
2151
235
|
throw new Error("Cannot find square root");
|
|
2152
|
-
let
|
|
2153
|
-
for (; !
|
|
2154
|
-
if (
|
|
2155
|
-
return
|
|
2156
|
-
let
|
|
2157
|
-
for (; !
|
|
2158
|
-
if (
|
|
236
|
+
let w = r, S = c.mul(c.ONE, s), q = c.pow(a, t), B = c.pow(a, i);
|
|
237
|
+
for (; !c.eql(q, c.ONE); ) {
|
|
238
|
+
if (c.is0(q))
|
|
239
|
+
return c.ZERO;
|
|
240
|
+
let v = 1, _ = c.sqr(q);
|
|
241
|
+
for (; !c.eql(_, c.ONE); )
|
|
242
|
+
if (v++, _ = c.sqr(_), v === w)
|
|
2159
243
|
throw new Error("Cannot find square root");
|
|
2160
|
-
const
|
|
2161
|
-
|
|
244
|
+
const R = $ << BigInt(w - v - 1), N = c.pow(S, R);
|
|
245
|
+
w = v, S = c.sqr(N), q = c.mul(q, S), B = c.mul(B, N);
|
|
2162
246
|
}
|
|
2163
|
-
return
|
|
247
|
+
return B;
|
|
2164
248
|
};
|
|
2165
249
|
}
|
|
2166
|
-
function
|
|
2167
|
-
return
|
|
250
|
+
function xe(n) {
|
|
251
|
+
return n % Jt === Qt ? ee : n % Pt === Ft ? ve : n % te === pe ? Re(n) : ne(n);
|
|
2168
252
|
}
|
|
2169
|
-
const
|
|
253
|
+
const Se = [
|
|
2170
254
|
"create",
|
|
2171
255
|
"isValid",
|
|
2172
256
|
"is0",
|
|
@@ -2185,191 +269,221 @@ const In = [
|
|
|
2185
269
|
"mulN",
|
|
2186
270
|
"sqrN"
|
|
2187
271
|
];
|
|
2188
|
-
function
|
|
2189
|
-
const
|
|
272
|
+
function Oe(n) {
|
|
273
|
+
const t = {
|
|
2190
274
|
ORDER: "bigint",
|
|
2191
|
-
MASK: "bigint",
|
|
2192
275
|
BYTES: "number",
|
|
2193
276
|
BITS: "number"
|
|
2194
|
-
},
|
|
2195
|
-
return
|
|
277
|
+
}, r = Se.reduce((e, o) => (e[o] = "function", e), t);
|
|
278
|
+
return Ot(n, r), n;
|
|
2196
279
|
}
|
|
2197
|
-
function
|
|
2198
|
-
if (
|
|
280
|
+
function qe(n, t, r) {
|
|
281
|
+
if (r < j)
|
|
2199
282
|
throw new Error("invalid exponent, negatives unsupported");
|
|
2200
|
-
if (
|
|
2201
|
-
return
|
|
2202
|
-
if (
|
|
2203
|
-
return
|
|
2204
|
-
let
|
|
2205
|
-
for (;
|
|
2206
|
-
|
|
2207
|
-
return
|
|
283
|
+
if (r === j)
|
|
284
|
+
return n.ONE;
|
|
285
|
+
if (r === $)
|
|
286
|
+
return t;
|
|
287
|
+
let e = n.ONE, o = t;
|
|
288
|
+
for (; r > j; )
|
|
289
|
+
r & $ && (e = n.mul(e, o)), o = n.sqr(o), r >>= $;
|
|
290
|
+
return e;
|
|
2208
291
|
}
|
|
2209
|
-
function
|
|
2210
|
-
const
|
|
2211
|
-
return
|
|
292
|
+
function re(n, t, r = !1) {
|
|
293
|
+
const e = new Array(t.length).fill(r ? n.ZERO : void 0), o = t.reduce((i, u, c) => n.is0(u) ? i : (e[c] = i, n.mul(i, u)), n.ONE), s = n.inv(o);
|
|
294
|
+
return t.reduceRight((i, u, c) => n.is0(u) ? i : (e[c] = n.mul(i, e[c]), n.mul(i, u)), s), e;
|
|
2212
295
|
}
|
|
2213
|
-
function
|
|
2214
|
-
const
|
|
2215
|
-
if (!
|
|
296
|
+
function Tt(n, t) {
|
|
297
|
+
const r = (n.ORDER - $) / et, e = n.pow(t, r), o = n.eql(e, n.ONE), s = n.eql(e, n.ZERO), i = n.eql(e, n.neg(n.ONE));
|
|
298
|
+
if (!o && !s && !i)
|
|
2216
299
|
throw new Error("invalid Legendre symbol result");
|
|
2217
|
-
return
|
|
2218
|
-
}
|
|
2219
|
-
function
|
|
2220
|
-
|
|
2221
|
-
const
|
|
2222
|
-
return { nBitLength:
|
|
300
|
+
return o ? 1 : s ? 0 : -1;
|
|
301
|
+
}
|
|
302
|
+
function Ie(n, t) {
|
|
303
|
+
t !== void 0 && it(t);
|
|
304
|
+
const r = t !== void 0 ? t : n.toString(2).length, e = Math.ceil(r / 8);
|
|
305
|
+
return { nBitLength: r, nByteLength: e };
|
|
306
|
+
}
|
|
307
|
+
class Ne {
|
|
308
|
+
ORDER;
|
|
309
|
+
BITS;
|
|
310
|
+
BYTES;
|
|
311
|
+
isLE;
|
|
312
|
+
ZERO = j;
|
|
313
|
+
ONE = $;
|
|
314
|
+
_lengths;
|
|
315
|
+
_sqrt;
|
|
316
|
+
// cached sqrt
|
|
317
|
+
_mod;
|
|
318
|
+
constructor(t, r = {}) {
|
|
319
|
+
if (t <= j)
|
|
320
|
+
throw new Error("invalid field: expected ORDER > 0, got " + t);
|
|
321
|
+
let e;
|
|
322
|
+
this.isLE = !1, r != null && typeof r == "object" && (typeof r.BITS == "number" && (e = r.BITS), typeof r.sqrt == "function" && (this.sqrt = r.sqrt), typeof r.isLE == "boolean" && (this.isLE = r.isLE), r.allowedLengths && (this._lengths = r.allowedLengths?.slice()), typeof r.modFromBytes == "boolean" && (this._mod = r.modFromBytes));
|
|
323
|
+
const { nBitLength: o, nByteLength: s } = Ie(t, e);
|
|
324
|
+
if (s > 2048)
|
|
325
|
+
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
326
|
+
this.ORDER = t, this.BITS = o, this.BYTES = s, this._sqrt = void 0, Object.preventExtensions(this);
|
|
327
|
+
}
|
|
328
|
+
create(t) {
|
|
329
|
+
return X(t, this.ORDER);
|
|
330
|
+
}
|
|
331
|
+
isValid(t) {
|
|
332
|
+
if (typeof t != "bigint")
|
|
333
|
+
throw new Error("invalid field element: expected bigint, got " + typeof t);
|
|
334
|
+
return j <= t && t < this.ORDER;
|
|
335
|
+
}
|
|
336
|
+
is0(t) {
|
|
337
|
+
return t === j;
|
|
338
|
+
}
|
|
339
|
+
// is valid and invertible
|
|
340
|
+
isValidNot0(t) {
|
|
341
|
+
return !this.is0(t) && this.isValid(t);
|
|
342
|
+
}
|
|
343
|
+
isOdd(t) {
|
|
344
|
+
return (t & $) === $;
|
|
345
|
+
}
|
|
346
|
+
neg(t) {
|
|
347
|
+
return X(-t, this.ORDER);
|
|
348
|
+
}
|
|
349
|
+
eql(t, r) {
|
|
350
|
+
return t === r;
|
|
351
|
+
}
|
|
352
|
+
sqr(t) {
|
|
353
|
+
return X(t * t, this.ORDER);
|
|
354
|
+
}
|
|
355
|
+
add(t, r) {
|
|
356
|
+
return X(t + r, this.ORDER);
|
|
357
|
+
}
|
|
358
|
+
sub(t, r) {
|
|
359
|
+
return X(t - r, this.ORDER);
|
|
360
|
+
}
|
|
361
|
+
mul(t, r) {
|
|
362
|
+
return X(t * r, this.ORDER);
|
|
363
|
+
}
|
|
364
|
+
pow(t, r) {
|
|
365
|
+
return qe(this, t, r);
|
|
366
|
+
}
|
|
367
|
+
div(t, r) {
|
|
368
|
+
return X(t * Dt(r, this.ORDER), this.ORDER);
|
|
369
|
+
}
|
|
370
|
+
// Same as above, but doesn't normalize
|
|
371
|
+
sqrN(t) {
|
|
372
|
+
return t * t;
|
|
373
|
+
}
|
|
374
|
+
addN(t, r) {
|
|
375
|
+
return t + r;
|
|
376
|
+
}
|
|
377
|
+
subN(t, r) {
|
|
378
|
+
return t - r;
|
|
379
|
+
}
|
|
380
|
+
mulN(t, r) {
|
|
381
|
+
return t * r;
|
|
382
|
+
}
|
|
383
|
+
inv(t) {
|
|
384
|
+
return Dt(t, this.ORDER);
|
|
385
|
+
}
|
|
386
|
+
sqrt(t) {
|
|
387
|
+
return this._sqrt || (this._sqrt = xe(this.ORDER)), this._sqrt(this, t);
|
|
388
|
+
}
|
|
389
|
+
toBytes(t) {
|
|
390
|
+
return this.isLE ? Xt(t, this.BYTES) : xt(t, this.BYTES);
|
|
391
|
+
}
|
|
392
|
+
fromBytes(t, r = !1) {
|
|
393
|
+
V(t);
|
|
394
|
+
const { _lengths: e, BYTES: o, isLE: s, ORDER: i, _mod: u } = this;
|
|
395
|
+
if (e) {
|
|
396
|
+
if (!e.includes(t.length) || t.length > o)
|
|
397
|
+
throw new Error("Field.fromBytes: expected " + e + " bytes, got " + t.length);
|
|
398
|
+
const a = new Uint8Array(o);
|
|
399
|
+
a.set(t, s ? 0 : a.length - t.length), t = a;
|
|
400
|
+
}
|
|
401
|
+
if (t.length !== o)
|
|
402
|
+
throw new Error("Field.fromBytes: expected " + o + " bytes, got " + t.length);
|
|
403
|
+
let c = s ? Ht(t) : wt(t);
|
|
404
|
+
if (u && (c = X(c, i)), !r && !this.isValid(c))
|
|
405
|
+
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
406
|
+
return c;
|
|
407
|
+
}
|
|
408
|
+
// TODO: we don't need it here, move out to separate fn
|
|
409
|
+
invertBatch(t) {
|
|
410
|
+
return re(this, t);
|
|
411
|
+
}
|
|
412
|
+
// We can't move this out because Fp6, Fp12 implement it
|
|
413
|
+
// and it's unclear what to return in there.
|
|
414
|
+
cmov(t, r, e) {
|
|
415
|
+
return e ? r : t;
|
|
416
|
+
}
|
|
2223
417
|
}
|
|
2224
|
-
function
|
|
2225
|
-
|
|
2226
|
-
throw new Error("invalid field: expected ORDER > 0, got " + e);
|
|
2227
|
-
let l, m, g = !1, p;
|
|
2228
|
-
if (typeof r == "object" && r != null) {
|
|
2229
|
-
if (t.sqrt || c)
|
|
2230
|
-
throw new Error("cannot specify opts in two arguments");
|
|
2231
|
-
const E = r;
|
|
2232
|
-
E.BITS && (l = E.BITS), E.sqrt && (m = E.sqrt), typeof E.isLE == "boolean" && (c = E.isLE), typeof E.modFromBytes == "boolean" && (g = E.modFromBytes), p = E.allowedLengths;
|
|
2233
|
-
} else
|
|
2234
|
-
typeof r == "number" && (l = r), t.sqrt && (m = t.sqrt);
|
|
2235
|
-
const { nBitLength: v, nByteLength: U } = nn(e, l);
|
|
2236
|
-
if (U > 2048)
|
|
2237
|
-
throw new Error("invalid field: expected ORDER of <= 2048 bytes");
|
|
2238
|
-
let H;
|
|
2239
|
-
const k = Object.freeze({
|
|
2240
|
-
ORDER: e,
|
|
2241
|
-
isLE: c,
|
|
2242
|
-
BITS: v,
|
|
2243
|
-
BYTES: U,
|
|
2244
|
-
MASK: ze(v),
|
|
2245
|
-
ZERO: Te,
|
|
2246
|
-
ONE: Be,
|
|
2247
|
-
allowedLengths: p,
|
|
2248
|
-
create: (E) => qe(E, e),
|
|
2249
|
-
isValid: (E) => {
|
|
2250
|
-
if (typeof E != "bigint")
|
|
2251
|
-
throw new Error("invalid field element: expected bigint, got " + typeof E);
|
|
2252
|
-
return Te <= E && E < e;
|
|
2253
|
-
},
|
|
2254
|
-
is0: (E) => E === Te,
|
|
2255
|
-
// is valid and invertible
|
|
2256
|
-
isValidNot0: (E) => !k.is0(E) && k.isValid(E),
|
|
2257
|
-
isOdd: (E) => (E & Be) === Be,
|
|
2258
|
-
neg: (E) => qe(-E, e),
|
|
2259
|
-
eql: (E, b) => E === b,
|
|
2260
|
-
sqr: (E) => qe(E * E, e),
|
|
2261
|
-
add: (E, b) => qe(E + b, e),
|
|
2262
|
-
sub: (E, b) => qe(E - b, e),
|
|
2263
|
-
mul: (E, b) => qe(E * b, e),
|
|
2264
|
-
pow: (E, b) => An(k, E, b),
|
|
2265
|
-
div: (E, b) => qe(E * Ut(b, e), e),
|
|
2266
|
-
// Same as above, but doesn't normalize
|
|
2267
|
-
sqrN: (E) => E * E,
|
|
2268
|
-
addN: (E, b) => E + b,
|
|
2269
|
-
subN: (E, b) => E - b,
|
|
2270
|
-
mulN: (E, b) => E * b,
|
|
2271
|
-
inv: (E) => Ut(E, e),
|
|
2272
|
-
sqrt: m || ((E) => (H || (H = qn(e)), H(k, E))),
|
|
2273
|
-
toBytes: (E) => c ? Pt(E, U) : wt(E, U),
|
|
2274
|
-
fromBytes: (E, b = !0) => {
|
|
2275
|
-
if (p) {
|
|
2276
|
-
if (!p.includes(E.length) || E.length > U)
|
|
2277
|
-
throw new Error("Field.fromBytes: expected " + p + " bytes, got " + E.length);
|
|
2278
|
-
const A = new Uint8Array(U);
|
|
2279
|
-
A.set(E, c ? 0 : A.length - E.length), E = A;
|
|
2280
|
-
}
|
|
2281
|
-
if (E.length !== U)
|
|
2282
|
-
throw new Error("Field.fromBytes: expected " + U + " bytes, got " + E.length);
|
|
2283
|
-
let S = c ? Yt(E) : et(E);
|
|
2284
|
-
if (g && (S = qe(S, e)), !b && !k.isValid(S))
|
|
2285
|
-
throw new Error("invalid field element: outside of range 0..ORDER");
|
|
2286
|
-
return S;
|
|
2287
|
-
},
|
|
2288
|
-
// TODO: we don't need it here, move out to separate fn
|
|
2289
|
-
invertBatch: (E) => tn(k, E),
|
|
2290
|
-
// We can't move this out because Fp6, Fp12 implement it
|
|
2291
|
-
// and it's unclear what to return in there.
|
|
2292
|
-
cmov: (E, b, S) => S ? b : E
|
|
2293
|
-
});
|
|
2294
|
-
return Object.freeze(k);
|
|
418
|
+
function gt(n, t = {}) {
|
|
419
|
+
return new Ne(n, t);
|
|
2295
420
|
}
|
|
2296
|
-
function
|
|
2297
|
-
if (typeof
|
|
421
|
+
function oe(n) {
|
|
422
|
+
if (typeof n != "bigint")
|
|
2298
423
|
throw new Error("field order must be bigint");
|
|
2299
|
-
const
|
|
2300
|
-
return Math.ceil(
|
|
2301
|
-
}
|
|
2302
|
-
function
|
|
2303
|
-
const
|
|
2304
|
-
return
|
|
2305
|
-
}
|
|
2306
|
-
function
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
}
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
}
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
}
|
|
2346
|
-
function jn(e, r) {
|
|
2347
|
-
if (!Array.isArray(e))
|
|
2348
|
-
throw new Error("array of scalars expected");
|
|
2349
|
-
e.forEach((c, t) => {
|
|
2350
|
-
if (!r.isValid(c))
|
|
2351
|
-
throw new Error("invalid scalar at index " + t);
|
|
2352
|
-
});
|
|
2353
|
-
}
|
|
2354
|
-
const at = /* @__PURE__ */ new WeakMap(), cn = /* @__PURE__ */ new WeakMap();
|
|
2355
|
-
function ft(e) {
|
|
2356
|
-
return cn.get(e) || 1;
|
|
2357
|
-
}
|
|
2358
|
-
function Lt(e) {
|
|
2359
|
-
if (e !== Ve)
|
|
424
|
+
const t = n.toString(2).length;
|
|
425
|
+
return Math.ceil(t / 8);
|
|
426
|
+
}
|
|
427
|
+
function ie(n) {
|
|
428
|
+
const t = oe(n);
|
|
429
|
+
return t + Math.ceil(t / 2);
|
|
430
|
+
}
|
|
431
|
+
function _e(n, t, r = !1) {
|
|
432
|
+
V(n);
|
|
433
|
+
const e = n.length, o = oe(t), s = ie(t);
|
|
434
|
+
if (e < 16 || e < s || e > 1024)
|
|
435
|
+
throw new Error("expected " + s + "-1024 bytes of input, got " + e);
|
|
436
|
+
const i = r ? Ht(n) : wt(n), u = X(i, t - $) + $;
|
|
437
|
+
return r ? Xt(u, o) : xt(u, o);
|
|
438
|
+
}
|
|
439
|
+
const ot = /* @__PURE__ */ BigInt(0), nt = /* @__PURE__ */ BigInt(1);
|
|
440
|
+
function at(n, t) {
|
|
441
|
+
const r = t.negate();
|
|
442
|
+
return n ? r : t;
|
|
443
|
+
}
|
|
444
|
+
function Ut(n, t) {
|
|
445
|
+
const r = re(n.Fp, t.map((e) => e.Z));
|
|
446
|
+
return t.map((e, o) => n.fromAffine(e.toAffine(r[o])));
|
|
447
|
+
}
|
|
448
|
+
function se(n, t) {
|
|
449
|
+
if (!Number.isSafeInteger(n) || n <= 0 || n > t)
|
|
450
|
+
throw new Error("invalid window size, expected [1.." + t + "], got W=" + n);
|
|
451
|
+
}
|
|
452
|
+
function mt(n, t) {
|
|
453
|
+
se(n, t);
|
|
454
|
+
const r = Math.ceil(t / n) + 1, e = 2 ** (n - 1), o = 2 ** n, s = St(n), i = BigInt(n);
|
|
455
|
+
return { windows: r, windowSize: e, mask: s, maxNumber: o, shiftBy: i };
|
|
456
|
+
}
|
|
457
|
+
function Yt(n, t, r) {
|
|
458
|
+
const { windowSize: e, mask: o, maxNumber: s, shiftBy: i } = r;
|
|
459
|
+
let u = Number(n & o), c = n >> i;
|
|
460
|
+
u > e && (u -= s, c += nt);
|
|
461
|
+
const a = t * e, w = a + Math.abs(u) - 1, S = u === 0, q = u < 0, B = t % 2 !== 0;
|
|
462
|
+
return { nextN: c, offset: w, isZero: S, isNeg: q, isNegF: B, offsetF: a };
|
|
463
|
+
}
|
|
464
|
+
const bt = /* @__PURE__ */ new WeakMap(), ce = /* @__PURE__ */ new WeakMap();
|
|
465
|
+
function Et(n) {
|
|
466
|
+
return ce.get(n) || 1;
|
|
467
|
+
}
|
|
468
|
+
function kt(n) {
|
|
469
|
+
if (n !== ot)
|
|
2360
470
|
throw new Error("invalid wNAF");
|
|
2361
471
|
}
|
|
2362
|
-
class
|
|
472
|
+
class Ze {
|
|
473
|
+
BASE;
|
|
474
|
+
ZERO;
|
|
475
|
+
Fn;
|
|
476
|
+
bits;
|
|
2363
477
|
// Parametrized with a given Point class (not individual point)
|
|
2364
|
-
constructor(
|
|
2365
|
-
this.BASE =
|
|
478
|
+
constructor(t, r) {
|
|
479
|
+
this.BASE = t.BASE, this.ZERO = t.ZERO, this.Fn = t.Fn, this.bits = r;
|
|
2366
480
|
}
|
|
2367
481
|
// non-const time multiplication ladder
|
|
2368
|
-
_unsafeLadder(
|
|
2369
|
-
let
|
|
2370
|
-
for (;
|
|
2371
|
-
|
|
2372
|
-
return
|
|
482
|
+
_unsafeLadder(t, r, e = this.ZERO) {
|
|
483
|
+
let o = t;
|
|
484
|
+
for (; r > ot; )
|
|
485
|
+
r & nt && (e = e.add(o)), o = o.double(), r >>= nt;
|
|
486
|
+
return e;
|
|
2373
487
|
}
|
|
2374
488
|
/**
|
|
2375
489
|
* Creates a wNAF precomputation window. Used for caching.
|
|
@@ -2383,16 +497,16 @@ class Ln {
|
|
|
2383
497
|
* @param W window size
|
|
2384
498
|
* @returns precomputed point tables flattened to a single array
|
|
2385
499
|
*/
|
|
2386
|
-
precomputeWindow(
|
|
2387
|
-
const { windows:
|
|
2388
|
-
let
|
|
2389
|
-
for (let
|
|
2390
|
-
|
|
2391
|
-
for (let
|
|
2392
|
-
|
|
2393
|
-
|
|
500
|
+
precomputeWindow(t, r) {
|
|
501
|
+
const { windows: e, windowSize: o } = mt(r, this.bits), s = [];
|
|
502
|
+
let i = t, u = i;
|
|
503
|
+
for (let c = 0; c < e; c++) {
|
|
504
|
+
u = i, s.push(u);
|
|
505
|
+
for (let a = 1; a < o; a++)
|
|
506
|
+
u = u.add(i), s.push(u);
|
|
507
|
+
i = u.double();
|
|
2394
508
|
}
|
|
2395
|
-
return
|
|
509
|
+
return s;
|
|
2396
510
|
}
|
|
2397
511
|
/**
|
|
2398
512
|
* Implements ec multiplication using precomputed tables and w-ary non-adjacent form.
|
|
@@ -2400,184 +514,165 @@ class Ln {
|
|
|
2400
514
|
* https://github.com/paulmillr/noble-secp256k1/blob/47cb1669b6e506ad66b35fe7d76132ae97465da2/index.ts#L502-L541
|
|
2401
515
|
* @returns real and fake (for const-time) points
|
|
2402
516
|
*/
|
|
2403
|
-
wNAF(
|
|
2404
|
-
if (!this.Fn.isValid(
|
|
517
|
+
wNAF(t, r, e) {
|
|
518
|
+
if (!this.Fn.isValid(e))
|
|
2405
519
|
throw new Error("invalid scalar");
|
|
2406
|
-
let
|
|
2407
|
-
const
|
|
2408
|
-
for (let
|
|
2409
|
-
const { nextN:
|
|
2410
|
-
|
|
520
|
+
let o = this.ZERO, s = this.BASE;
|
|
521
|
+
const i = mt(t, this.bits);
|
|
522
|
+
for (let u = 0; u < i.windows; u++) {
|
|
523
|
+
const { nextN: c, offset: a, isZero: w, isNeg: S, isNegF: q, offsetF: B } = Yt(e, u, i);
|
|
524
|
+
e = c, w ? s = s.add(at(q, r[B])) : o = o.add(at(S, r[a]));
|
|
2411
525
|
}
|
|
2412
|
-
return
|
|
526
|
+
return kt(e), { p: o, f: s };
|
|
2413
527
|
}
|
|
2414
528
|
/**
|
|
2415
529
|
* Implements ec unsafe (non const-time) multiplication using precomputed tables and w-ary non-adjacent form.
|
|
2416
530
|
* @param acc accumulator point to add result of multiplication
|
|
2417
531
|
* @returns point
|
|
2418
532
|
*/
|
|
2419
|
-
wNAFUnsafe(
|
|
2420
|
-
const
|
|
2421
|
-
for (let
|
|
2422
|
-
const { nextN:
|
|
2423
|
-
if (
|
|
2424
|
-
const
|
|
2425
|
-
|
|
533
|
+
wNAFUnsafe(t, r, e, o = this.ZERO) {
|
|
534
|
+
const s = mt(t, this.bits);
|
|
535
|
+
for (let i = 0; i < s.windows && e !== ot; i++) {
|
|
536
|
+
const { nextN: u, offset: c, isZero: a, isNeg: w } = Yt(e, i, s);
|
|
537
|
+
if (e = u, !a) {
|
|
538
|
+
const S = r[c];
|
|
539
|
+
o = o.add(w ? S.negate() : S);
|
|
2426
540
|
}
|
|
2427
541
|
}
|
|
2428
|
-
return
|
|
542
|
+
return kt(e), o;
|
|
2429
543
|
}
|
|
2430
|
-
getPrecomputes(
|
|
2431
|
-
let
|
|
2432
|
-
return
|
|
544
|
+
getPrecomputes(t, r, e) {
|
|
545
|
+
let o = bt.get(r);
|
|
546
|
+
return o || (o = this.precomputeWindow(r, t), t !== 1 && (typeof e == "function" && (o = e(o)), bt.set(r, o))), o;
|
|
2433
547
|
}
|
|
2434
|
-
cached(
|
|
2435
|
-
const
|
|
2436
|
-
return this.wNAF(
|
|
548
|
+
cached(t, r, e) {
|
|
549
|
+
const o = Et(t);
|
|
550
|
+
return this.wNAF(o, this.getPrecomputes(o, t, e), r);
|
|
2437
551
|
}
|
|
2438
|
-
unsafe(
|
|
2439
|
-
const
|
|
2440
|
-
return
|
|
552
|
+
unsafe(t, r, e, o) {
|
|
553
|
+
const s = Et(t);
|
|
554
|
+
return s === 1 ? this._unsafeLadder(t, r, o) : this.wNAFUnsafe(s, this.getPrecomputes(s, t, e), r, o);
|
|
2441
555
|
}
|
|
2442
556
|
// We calculate precomputes for elliptic curve point multiplication
|
|
2443
557
|
// using windowed method. This specifies window size and
|
|
2444
558
|
// stores precomputed values. Usually only base point would be precomputed.
|
|
2445
|
-
createCache(
|
|
2446
|
-
|
|
559
|
+
createCache(t, r) {
|
|
560
|
+
se(r, this.bits), ce.set(t, r), bt.delete(t);
|
|
2447
561
|
}
|
|
2448
|
-
hasCache(
|
|
2449
|
-
return
|
|
562
|
+
hasCache(t) {
|
|
563
|
+
return Et(t) !== 1;
|
|
2450
564
|
}
|
|
2451
565
|
}
|
|
2452
|
-
function
|
|
2453
|
-
let
|
|
2454
|
-
for (;
|
|
2455
|
-
|
|
2456
|
-
return { p1:
|
|
2457
|
-
}
|
|
2458
|
-
function Mn(e, r, c, t) {
|
|
2459
|
-
Zn(c, e), jn(t, r);
|
|
2460
|
-
const l = c.length, m = t.length;
|
|
2461
|
-
if (l !== m)
|
|
2462
|
-
throw new Error("arrays of points and scalars must have equal length");
|
|
2463
|
-
const g = e.ZERO, p = Xt(BigInt(l));
|
|
2464
|
-
let v = 1;
|
|
2465
|
-
p > 12 ? v = p - 3 : p > 4 ? v = p - 2 : p > 0 && (v = 2);
|
|
2466
|
-
const U = ze(v), H = new Array(Number(U) + 1).fill(g), k = Math.floor((r.BITS - 1) / v) * v;
|
|
2467
|
-
let E = g;
|
|
2468
|
-
for (let b = k; b >= 0; b -= v) {
|
|
2469
|
-
H.fill(g);
|
|
2470
|
-
for (let A = 0; A < m; A++) {
|
|
2471
|
-
const M = t[A], Q = Number(M >> BigInt(b) & U);
|
|
2472
|
-
H[Q] = H[Q].add(c[A]);
|
|
2473
|
-
}
|
|
2474
|
-
let S = g;
|
|
2475
|
-
for (let A = H.length - 1, M = g; A > 0; A--)
|
|
2476
|
-
M = M.add(H[A]), S = S.add(M);
|
|
2477
|
-
if (E = E.add(S), b !== 0)
|
|
2478
|
-
for (let A = 0; A < v; A++)
|
|
2479
|
-
E = E.double();
|
|
2480
|
-
}
|
|
2481
|
-
return E;
|
|
566
|
+
function Ae(n, t, r, e) {
|
|
567
|
+
let o = t, s = n.ZERO, i = n.ZERO;
|
|
568
|
+
for (; r > ot || e > ot; )
|
|
569
|
+
r & nt && (s = s.add(o)), e & nt && (i = i.add(o)), o = o.double(), r >>= nt, e >>= nt;
|
|
570
|
+
return { p1: s, p2: i };
|
|
2482
571
|
}
|
|
2483
|
-
function
|
|
2484
|
-
if (
|
|
2485
|
-
if (
|
|
572
|
+
function Vt(n, t, r) {
|
|
573
|
+
if (t) {
|
|
574
|
+
if (t.ORDER !== n)
|
|
2486
575
|
throw new Error("Field.ORDER must match order: Fp == p, Fn == n");
|
|
2487
|
-
return
|
|
576
|
+
return Oe(t), t;
|
|
2488
577
|
} else
|
|
2489
|
-
return
|
|
2490
|
-
}
|
|
2491
|
-
function
|
|
2492
|
-
if (
|
|
2493
|
-
throw new Error(`expected valid ${
|
|
2494
|
-
for (const
|
|
2495
|
-
const
|
|
2496
|
-
if (!(typeof
|
|
2497
|
-
throw new Error(`CURVE.${
|
|
2498
|
-
}
|
|
2499
|
-
const
|
|
2500
|
-
for (const
|
|
2501
|
-
if (!
|
|
2502
|
-
throw new Error(`CURVE.${
|
|
2503
|
-
return
|
|
2504
|
-
}
|
|
2505
|
-
|
|
2506
|
-
function
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
k && (U = -U), E && (H = -H);
|
|
2511
|
-
const b = ze(Math.ceil(Xt(c) / 2)) + ke;
|
|
2512
|
-
if (U < Ne || U >= b || H < Ne || H >= b)
|
|
2513
|
-
throw new Error("splitScalar (endomorphism): failed, k=" + e);
|
|
2514
|
-
return { k1neg: k, k1: U, k2neg: E, k2: H };
|
|
578
|
+
return gt(n, { isLE: r });
|
|
579
|
+
}
|
|
580
|
+
function Le(n, t, r = {}, e) {
|
|
581
|
+
if (e === void 0 && (e = n === "edwards"), !t || typeof t != "object")
|
|
582
|
+
throw new Error(`expected valid ${n} CURVE object`);
|
|
583
|
+
for (const c of ["p", "n", "h"]) {
|
|
584
|
+
const a = t[c];
|
|
585
|
+
if (!(typeof a == "bigint" && a > ot))
|
|
586
|
+
throw new Error(`CURVE.${c} must be positive bigint`);
|
|
587
|
+
}
|
|
588
|
+
const o = Vt(t.p, r.Fp, e), s = Vt(t.n, r.Fn, e), u = ["Gx", "Gy", "a", "b"];
|
|
589
|
+
for (const c of u)
|
|
590
|
+
if (!o.isValid(t[c]))
|
|
591
|
+
throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);
|
|
592
|
+
return t = Object.freeze(Object.assign({}, t)), { CURVE: t, Fp: o, Fn: s };
|
|
593
|
+
}
|
|
594
|
+
function De(n, t) {
|
|
595
|
+
return function(e) {
|
|
596
|
+
const o = n(e);
|
|
597
|
+
return { secretKey: o, publicKey: t(o) };
|
|
598
|
+
};
|
|
2515
599
|
}
|
|
2516
|
-
|
|
2517
|
-
|
|
600
|
+
const $t = (n, t) => (n + (n >= 0 ? t : -t) / fe) / t;
|
|
601
|
+
function Te(n, t, r) {
|
|
602
|
+
const [[e, o], [s, i]] = t, u = $t(i * n, r), c = $t(-o * n, r);
|
|
603
|
+
let a = n - u * e - c * s, w = -u * o - c * i;
|
|
604
|
+
const S = a < W, q = w < W;
|
|
605
|
+
S && (a = -a), q && (w = -w);
|
|
606
|
+
const B = St(Math.ceil(be(r) / 2)) + rt;
|
|
607
|
+
if (a < W || a >= B || w < W || w >= B)
|
|
608
|
+
throw new Error("splitScalar (endomorphism): failed, k=" + n);
|
|
609
|
+
return { k1neg: S, k1: a, k2neg: q, k2: w };
|
|
610
|
+
}
|
|
611
|
+
function pt(n) {
|
|
612
|
+
if (!["compact", "recovered", "der"].includes(n))
|
|
2518
613
|
throw new Error('Signature format must be "compact", "recovered", or "der"');
|
|
2519
|
-
return
|
|
614
|
+
return n;
|
|
2520
615
|
}
|
|
2521
|
-
function
|
|
2522
|
-
const
|
|
2523
|
-
for (let
|
|
2524
|
-
|
|
2525
|
-
return
|
|
616
|
+
function yt(n, t) {
|
|
617
|
+
const r = {};
|
|
618
|
+
for (let e of Object.keys(t))
|
|
619
|
+
r[e] = n[e] === void 0 ? t[e] : n[e];
|
|
620
|
+
return dt(r.lowS, "lowS"), dt(r.prehash, "prehash"), r.format !== void 0 && pt(r.format), r;
|
|
2526
621
|
}
|
|
2527
|
-
class
|
|
2528
|
-
constructor(
|
|
2529
|
-
super(
|
|
622
|
+
class Ue extends Error {
|
|
623
|
+
constructor(t = "") {
|
|
624
|
+
super(t);
|
|
2530
625
|
}
|
|
2531
626
|
}
|
|
2532
|
-
const
|
|
627
|
+
const Q = {
|
|
2533
628
|
// asn.1 DER encoding utils
|
|
2534
|
-
Err:
|
|
629
|
+
Err: Ue,
|
|
2535
630
|
// Basic building block is TLV (Tag-Length-Value)
|
|
2536
631
|
_tlv: {
|
|
2537
|
-
encode: (
|
|
2538
|
-
const { Err:
|
|
2539
|
-
if (
|
|
2540
|
-
throw new
|
|
2541
|
-
if (
|
|
2542
|
-
throw new
|
|
2543
|
-
const
|
|
2544
|
-
if (
|
|
2545
|
-
throw new
|
|
2546
|
-
const
|
|
2547
|
-
return
|
|
632
|
+
encode: (n, t) => {
|
|
633
|
+
const { Err: r } = Q;
|
|
634
|
+
if (n < 0 || n > 256)
|
|
635
|
+
throw new r("tlv.encode: wrong tag");
|
|
636
|
+
if (t.length & 1)
|
|
637
|
+
throw new r("tlv.encode: unpadded data");
|
|
638
|
+
const e = t.length / 2, o = ct(e);
|
|
639
|
+
if (o.length / 2 & 128)
|
|
640
|
+
throw new r("tlv.encode: long form length too big");
|
|
641
|
+
const s = e > 127 ? ct(o.length / 2 | 128) : "";
|
|
642
|
+
return ct(n) + s + o + t;
|
|
2548
643
|
},
|
|
2549
644
|
// v - value, l - left bytes (unparsed)
|
|
2550
|
-
decode(
|
|
2551
|
-
const { Err:
|
|
2552
|
-
let
|
|
2553
|
-
if (
|
|
2554
|
-
throw new
|
|
2555
|
-
if (
|
|
2556
|
-
throw new
|
|
2557
|
-
const
|
|
2558
|
-
let
|
|
2559
|
-
if (!
|
|
2560
|
-
|
|
645
|
+
decode(n, t) {
|
|
646
|
+
const { Err: r } = Q;
|
|
647
|
+
let e = 0;
|
|
648
|
+
if (n < 0 || n > 256)
|
|
649
|
+
throw new r("tlv.encode: wrong tag");
|
|
650
|
+
if (t.length < 2 || t[e++] !== n)
|
|
651
|
+
throw new r("tlv.decode: wrong tlv");
|
|
652
|
+
const o = t[e++], s = !!(o & 128);
|
|
653
|
+
let i = 0;
|
|
654
|
+
if (!s)
|
|
655
|
+
i = o;
|
|
2561
656
|
else {
|
|
2562
|
-
const
|
|
2563
|
-
if (!
|
|
2564
|
-
throw new
|
|
2565
|
-
if (
|
|
2566
|
-
throw new
|
|
2567
|
-
const
|
|
2568
|
-
if (
|
|
2569
|
-
throw new
|
|
2570
|
-
if (
|
|
2571
|
-
throw new
|
|
2572
|
-
for (const
|
|
2573
|
-
|
|
2574
|
-
if (
|
|
2575
|
-
throw new
|
|
657
|
+
const c = o & 127;
|
|
658
|
+
if (!c)
|
|
659
|
+
throw new r("tlv.decode(long): indefinite length not supported");
|
|
660
|
+
if (c > 4)
|
|
661
|
+
throw new r("tlv.decode(long): byte length is too big");
|
|
662
|
+
const a = t.subarray(e, e + c);
|
|
663
|
+
if (a.length !== c)
|
|
664
|
+
throw new r("tlv.decode: length bytes not complete");
|
|
665
|
+
if (a[0] === 0)
|
|
666
|
+
throw new r("tlv.decode(long): zero leftmost byte");
|
|
667
|
+
for (const w of a)
|
|
668
|
+
i = i << 8 | w;
|
|
669
|
+
if (e += c, i < 128)
|
|
670
|
+
throw new r("tlv.decode(long): not minimal encoding");
|
|
2576
671
|
}
|
|
2577
|
-
const
|
|
2578
|
-
if (
|
|
2579
|
-
throw new
|
|
2580
|
-
return { v:
|
|
672
|
+
const u = t.subarray(e, e + i);
|
|
673
|
+
if (u.length !== i)
|
|
674
|
+
throw new r("tlv.decode: wrong value length");
|
|
675
|
+
return { v: u, l: t.subarray(e + i) };
|
|
2581
676
|
}
|
|
2582
677
|
},
|
|
2583
678
|
// https://crypto.stackexchange.com/a/57734 Leftmost bit of first byte is 'negative' flag,
|
|
@@ -2585,192 +680,186 @@ const Ie = {
|
|
|
2585
680
|
// - add zero byte if exists
|
|
2586
681
|
// - if next byte doesn't have a flag, leading zero is not allowed (minimal encoding)
|
|
2587
682
|
_int: {
|
|
2588
|
-
encode(
|
|
2589
|
-
const { Err:
|
|
2590
|
-
if (
|
|
2591
|
-
throw new
|
|
2592
|
-
let
|
|
2593
|
-
if (Number.parseInt(
|
|
2594
|
-
throw new
|
|
2595
|
-
return
|
|
683
|
+
encode(n) {
|
|
684
|
+
const { Err: t } = Q;
|
|
685
|
+
if (n < W)
|
|
686
|
+
throw new t("integer: negative integers are not allowed");
|
|
687
|
+
let r = ct(n);
|
|
688
|
+
if (Number.parseInt(r[0], 16) & 8 && (r = "00" + r), r.length & 1)
|
|
689
|
+
throw new t("unexpected DER parsing assertion: unpadded hex");
|
|
690
|
+
return r;
|
|
2596
691
|
},
|
|
2597
|
-
decode(
|
|
2598
|
-
const { Err:
|
|
2599
|
-
if (
|
|
2600
|
-
throw new
|
|
2601
|
-
if (
|
|
2602
|
-
throw new
|
|
2603
|
-
return
|
|
692
|
+
decode(n) {
|
|
693
|
+
const { Err: t } = Q;
|
|
694
|
+
if (n[0] & 128)
|
|
695
|
+
throw new t("invalid signature integer: negative");
|
|
696
|
+
if (n[0] === 0 && !(n[1] & 128))
|
|
697
|
+
throw new t("invalid signature integer: unnecessary leading zero");
|
|
698
|
+
return wt(n);
|
|
2604
699
|
}
|
|
2605
700
|
},
|
|
2606
|
-
toSig(
|
|
2607
|
-
const { Err:
|
|
2608
|
-
if (
|
|
2609
|
-
throw new
|
|
2610
|
-
const { v:
|
|
2611
|
-
if (
|
|
2612
|
-
throw new
|
|
2613
|
-
return { r:
|
|
701
|
+
toSig(n) {
|
|
702
|
+
const { Err: t, _int: r, _tlv: e } = Q, o = V(n, void 0, "signature"), { v: s, l: i } = e.decode(48, o);
|
|
703
|
+
if (i.length)
|
|
704
|
+
throw new t("invalid signature: left bytes after parsing");
|
|
705
|
+
const { v: u, l: c } = e.decode(2, s), { v: a, l: w } = e.decode(2, c);
|
|
706
|
+
if (w.length)
|
|
707
|
+
throw new t("invalid signature: left bytes after parsing");
|
|
708
|
+
return { r: r.decode(u), s: r.decode(a) };
|
|
2614
709
|
},
|
|
2615
|
-
hexFromSig(
|
|
2616
|
-
const { _tlv:
|
|
2617
|
-
return
|
|
2618
|
-
}
|
|
2619
|
-
},
|
|
2620
|
-
function
|
|
2621
|
-
const {
|
|
2622
|
-
let
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
else {
|
|
2626
|
-
let l = Se("private key", r);
|
|
2627
|
-
try {
|
|
2628
|
-
t = e.fromBytes(l);
|
|
2629
|
-
} catch {
|
|
2630
|
-
throw new Error(`invalid private key: expected ui8a of size ${c}, got ${typeof r}`);
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
|
-
if (!e.isValidNot0(t))
|
|
2634
|
-
throw new Error("invalid private key: out of range [1..N-1]");
|
|
2635
|
-
return t;
|
|
2636
|
-
}
|
|
2637
|
-
function zn(e, r = {}) {
|
|
2638
|
-
const c = kn("weierstrass", e, r), { Fp: t, Fn: l } = c;
|
|
2639
|
-
let m = c.CURVE;
|
|
2640
|
-
const { h: g, n: p } = m;
|
|
2641
|
-
gt(r, {}, {
|
|
710
|
+
hexFromSig(n) {
|
|
711
|
+
const { _tlv: t, _int: r } = Q, e = t.encode(2, r.encode(n.r)), o = t.encode(2, r.encode(n.s)), s = e + o;
|
|
712
|
+
return t.encode(48, s);
|
|
713
|
+
}
|
|
714
|
+
}, W = BigInt(0), rt = BigInt(1), fe = BigInt(2), ft = BigInt(3), Ye = BigInt(4);
|
|
715
|
+
function ke(n, t = {}) {
|
|
716
|
+
const r = Le("weierstrass", n, t), { Fp: e, Fn: o } = r;
|
|
717
|
+
let s = r.CURVE;
|
|
718
|
+
const { h: i, n: u } = s;
|
|
719
|
+
Ot(t, {}, {
|
|
2642
720
|
allowInfinityPoint: "boolean",
|
|
2643
721
|
clearCofactor: "function",
|
|
2644
722
|
isTorsionFree: "function",
|
|
2645
723
|
fromBytes: "function",
|
|
2646
724
|
toBytes: "function",
|
|
2647
|
-
endo: "object"
|
|
2648
|
-
wrapPrivateKey: "boolean"
|
|
725
|
+
endo: "object"
|
|
2649
726
|
});
|
|
2650
|
-
const { endo:
|
|
2651
|
-
if (
|
|
727
|
+
const { endo: c } = t;
|
|
728
|
+
if (c && (!e.is0(s.a) || typeof c.beta != "bigint" || !Array.isArray(c.basises)))
|
|
2652
729
|
throw new Error('invalid endo: expected "beta": bigint and "basises": array');
|
|
2653
|
-
const
|
|
2654
|
-
function
|
|
2655
|
-
if (!
|
|
730
|
+
const a = le(e, o);
|
|
731
|
+
function w() {
|
|
732
|
+
if (!e.isOdd)
|
|
2656
733
|
throw new Error("compression is not supported: Field does not have .isOdd()");
|
|
2657
734
|
}
|
|
2658
|
-
function
|
|
2659
|
-
const { x:
|
|
2660
|
-
if (
|
|
2661
|
-
|
|
2662
|
-
const
|
|
2663
|
-
return
|
|
735
|
+
function S(I, d, l) {
|
|
736
|
+
const { x: f, y: h } = d.toAffine(), m = e.toBytes(f);
|
|
737
|
+
if (dt(l, "isCompressed"), l) {
|
|
738
|
+
w();
|
|
739
|
+
const E = !e.isOdd(h);
|
|
740
|
+
return J(ue(E), m);
|
|
2664
741
|
} else
|
|
2665
|
-
return
|
|
2666
|
-
}
|
|
2667
|
-
function
|
|
2668
|
-
|
|
2669
|
-
const { publicKey: d, publicKeyUncompressed:
|
|
2670
|
-
if (
|
|
2671
|
-
const
|
|
2672
|
-
if (!
|
|
742
|
+
return J(Uint8Array.of(4), m, e.toBytes(h));
|
|
743
|
+
}
|
|
744
|
+
function q(I) {
|
|
745
|
+
V(I, void 0, "Point");
|
|
746
|
+
const { publicKey: d, publicKeyUncompressed: l } = a, f = I.length, h = I[0], m = I.subarray(1);
|
|
747
|
+
if (f === d && (h === 2 || h === 3)) {
|
|
748
|
+
const E = e.fromBytes(m);
|
|
749
|
+
if (!e.isValid(E))
|
|
2673
750
|
throw new Error("bad point: is not on curve, wrong x");
|
|
2674
|
-
const
|
|
2675
|
-
let
|
|
751
|
+
const b = _(E);
|
|
752
|
+
let g;
|
|
2676
753
|
try {
|
|
2677
|
-
|
|
2678
|
-
} catch (
|
|
2679
|
-
const
|
|
2680
|
-
throw new Error("bad point: is not on curve, sqrt error" +
|
|
754
|
+
g = e.sqrt(b);
|
|
755
|
+
} catch (D) {
|
|
756
|
+
const Z = D instanceof Error ? ": " + D.message : "";
|
|
757
|
+
throw new Error("bad point: is not on curve, sqrt error" + Z);
|
|
2681
758
|
}
|
|
2682
|
-
|
|
2683
|
-
const
|
|
2684
|
-
return (
|
|
2685
|
-
} else if (
|
|
2686
|
-
const
|
|
2687
|
-
if (!
|
|
759
|
+
w();
|
|
760
|
+
const y = e.isOdd(g);
|
|
761
|
+
return (h & 1) === 1 !== y && (g = e.neg(g)), { x: E, y: g };
|
|
762
|
+
} else if (f === l && h === 4) {
|
|
763
|
+
const E = e.BYTES, b = e.fromBytes(m.subarray(0, E)), g = e.fromBytes(m.subarray(E, E * 2));
|
|
764
|
+
if (!R(b, g))
|
|
2688
765
|
throw new Error("bad point: is not on curve");
|
|
2689
|
-
return { x:
|
|
766
|
+
return { x: b, y: g };
|
|
2690
767
|
} else
|
|
2691
|
-
throw new Error(`bad point: got length ${
|
|
768
|
+
throw new Error(`bad point: got length ${f}, expected compressed=${d} or uncompressed=${l}`);
|
|
2692
769
|
}
|
|
2693
|
-
const
|
|
2694
|
-
function
|
|
2695
|
-
const d =
|
|
2696
|
-
return
|
|
770
|
+
const B = t.toBytes || S, v = t.fromBytes || q;
|
|
771
|
+
function _(I) {
|
|
772
|
+
const d = e.sqr(I), l = e.mul(d, I);
|
|
773
|
+
return e.add(e.add(l, e.mul(I, s.a)), s.b);
|
|
2697
774
|
}
|
|
2698
|
-
function
|
|
2699
|
-
const
|
|
2700
|
-
return
|
|
775
|
+
function R(I, d) {
|
|
776
|
+
const l = e.sqr(d), f = _(I);
|
|
777
|
+
return e.eql(l, f);
|
|
2701
778
|
}
|
|
2702
|
-
if (!
|
|
779
|
+
if (!R(s.Gx, s.Gy))
|
|
2703
780
|
throw new Error("bad curve params: generator point");
|
|
2704
|
-
const
|
|
2705
|
-
if (
|
|
781
|
+
const N = e.mul(e.pow(s.a, ft), Ye), T = e.mul(e.sqr(s.b), BigInt(27));
|
|
782
|
+
if (e.is0(e.add(N, T)))
|
|
2706
783
|
throw new Error("bad curve params: a or b");
|
|
2707
|
-
function
|
|
2708
|
-
if (!
|
|
2709
|
-
throw new Error(`bad point coordinate ${
|
|
784
|
+
function C(I, d, l = !1) {
|
|
785
|
+
if (!e.isValid(d) || l && e.is0(d))
|
|
786
|
+
throw new Error(`bad point coordinate ${I}`);
|
|
2710
787
|
return d;
|
|
2711
788
|
}
|
|
2712
|
-
function
|
|
2713
|
-
if (!(
|
|
2714
|
-
throw new Error("
|
|
789
|
+
function Y(I) {
|
|
790
|
+
if (!(I instanceof x))
|
|
791
|
+
throw new Error("Weierstrass Point expected");
|
|
2715
792
|
}
|
|
2716
|
-
function
|
|
2717
|
-
if (!
|
|
793
|
+
function K(I) {
|
|
794
|
+
if (!c || !c.basises)
|
|
2718
795
|
throw new Error("no endo");
|
|
2719
|
-
return
|
|
2720
|
-
}
|
|
2721
|
-
const
|
|
2722
|
-
const { X:
|
|
2723
|
-
if (
|
|
2724
|
-
return { x:
|
|
2725
|
-
const
|
|
2726
|
-
d == null && (d =
|
|
2727
|
-
const
|
|
2728
|
-
if (
|
|
2729
|
-
return { x:
|
|
2730
|
-
if (!
|
|
796
|
+
return Te(I, c.basises, o.ORDER);
|
|
797
|
+
}
|
|
798
|
+
const M = At((I, d) => {
|
|
799
|
+
const { X: l, Y: f, Z: h } = I;
|
|
800
|
+
if (e.eql(h, e.ONE))
|
|
801
|
+
return { x: l, y: f };
|
|
802
|
+
const m = I.is0();
|
|
803
|
+
d == null && (d = m ? e.ONE : e.inv(h));
|
|
804
|
+
const E = e.mul(l, d), b = e.mul(f, d), g = e.mul(h, d);
|
|
805
|
+
if (m)
|
|
806
|
+
return { x: e.ZERO, y: e.ZERO };
|
|
807
|
+
if (!e.eql(g, e.ONE))
|
|
2731
808
|
throw new Error("invZ was invalid");
|
|
2732
|
-
return { x:
|
|
2733
|
-
}),
|
|
2734
|
-
if (
|
|
2735
|
-
if (
|
|
809
|
+
return { x: E, y: b };
|
|
810
|
+
}), F = At((I) => {
|
|
811
|
+
if (I.is0()) {
|
|
812
|
+
if (t.allowInfinityPoint && !e.is0(I.Y))
|
|
2736
813
|
return;
|
|
2737
814
|
throw new Error("bad point: ZERO");
|
|
2738
815
|
}
|
|
2739
|
-
const { x: d, y:
|
|
2740
|
-
if (!
|
|
816
|
+
const { x: d, y: l } = I.toAffine();
|
|
817
|
+
if (!e.isValid(d) || !e.isValid(l))
|
|
2741
818
|
throw new Error("bad point: x or y not field elements");
|
|
2742
|
-
if (!
|
|
819
|
+
if (!R(d, l))
|
|
2743
820
|
throw new Error("bad point: equation left != right");
|
|
2744
|
-
if (!
|
|
821
|
+
if (!I.isTorsionFree())
|
|
2745
822
|
throw new Error("bad point: not in prime-order subgroup");
|
|
2746
823
|
return !0;
|
|
2747
824
|
});
|
|
2748
|
-
function
|
|
2749
|
-
return
|
|
2750
|
-
}
|
|
2751
|
-
class
|
|
825
|
+
function H(I, d, l, f, h) {
|
|
826
|
+
return l = new x(e.mul(l.X, I), l.Y, l.Z), d = at(f, d), l = at(h, l), d.add(l);
|
|
827
|
+
}
|
|
828
|
+
class x {
|
|
829
|
+
// base / generator point
|
|
830
|
+
static BASE = new x(s.Gx, s.Gy, e.ONE);
|
|
831
|
+
// zero / infinity / identity point
|
|
832
|
+
static ZERO = new x(e.ZERO, e.ONE, e.ZERO);
|
|
833
|
+
// 0, 1, 0
|
|
834
|
+
// math field
|
|
835
|
+
static Fp = e;
|
|
836
|
+
// scalar field
|
|
837
|
+
static Fn = o;
|
|
838
|
+
X;
|
|
839
|
+
Y;
|
|
840
|
+
Z;
|
|
2752
841
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2753
|
-
constructor(d,
|
|
2754
|
-
this.X =
|
|
842
|
+
constructor(d, l, f) {
|
|
843
|
+
this.X = C("x", d), this.Y = C("y", l, !0), this.Z = C("z", f), Object.freeze(this);
|
|
2755
844
|
}
|
|
2756
845
|
static CURVE() {
|
|
2757
|
-
return
|
|
846
|
+
return s;
|
|
2758
847
|
}
|
|
2759
848
|
/** Does NOT validate if the point is valid. Use `.assertValidity()`. */
|
|
2760
849
|
static fromAffine(d) {
|
|
2761
|
-
const { x:
|
|
2762
|
-
if (!d || !
|
|
850
|
+
const { x: l, y: f } = d || {};
|
|
851
|
+
if (!d || !e.isValid(l) || !e.isValid(f))
|
|
2763
852
|
throw new Error("invalid affine point");
|
|
2764
|
-
if (d instanceof
|
|
853
|
+
if (d instanceof x)
|
|
2765
854
|
throw new Error("projective point not allowed");
|
|
2766
|
-
return
|
|
855
|
+
return e.is0(l) && e.is0(f) ? x.ZERO : new x(l, f, e.ONE);
|
|
2767
856
|
}
|
|
2768
857
|
static fromBytes(d) {
|
|
2769
|
-
const
|
|
2770
|
-
return
|
|
858
|
+
const l = x.fromAffine(v(V(d, void 0, "point")));
|
|
859
|
+
return l.assertValidity(), l;
|
|
2771
860
|
}
|
|
2772
861
|
static fromHex(d) {
|
|
2773
|
-
return
|
|
862
|
+
return x.fromBytes(lt(d));
|
|
2774
863
|
}
|
|
2775
864
|
get x() {
|
|
2776
865
|
return this.toAffine().x;
|
|
@@ -2784,58 +873,58 @@ function zn(e, r = {}) {
|
|
|
2784
873
|
* @param isLazy true will defer table computation until the first multiplication
|
|
2785
874
|
* @returns
|
|
2786
875
|
*/
|
|
2787
|
-
precompute(d = 8,
|
|
2788
|
-
return
|
|
876
|
+
precompute(d = 8, l = !0) {
|
|
877
|
+
return tt.createCache(this, d), l || this.multiply(ft), this;
|
|
2789
878
|
}
|
|
2790
879
|
// TODO: return `this`
|
|
2791
880
|
/** A point on curve is valid if it conforms to equation. */
|
|
2792
881
|
assertValidity() {
|
|
2793
|
-
|
|
882
|
+
F(this);
|
|
2794
883
|
}
|
|
2795
884
|
hasEvenY() {
|
|
2796
885
|
const { y: d } = this.toAffine();
|
|
2797
|
-
if (!
|
|
886
|
+
if (!e.isOdd)
|
|
2798
887
|
throw new Error("Field doesn't support isOdd");
|
|
2799
|
-
return !
|
|
888
|
+
return !e.isOdd(d);
|
|
2800
889
|
}
|
|
2801
890
|
/** Compare one point to another. */
|
|
2802
891
|
equals(d) {
|
|
2803
|
-
|
|
2804
|
-
const { X:
|
|
2805
|
-
return
|
|
892
|
+
Y(d);
|
|
893
|
+
const { X: l, Y: f, Z: h } = this, { X: m, Y: E, Z: b } = d, g = e.eql(e.mul(l, b), e.mul(m, h)), y = e.eql(e.mul(f, b), e.mul(E, h));
|
|
894
|
+
return g && y;
|
|
2806
895
|
}
|
|
2807
896
|
/** Flips point to one corresponding to (x, -y) in Affine coordinates. */
|
|
2808
897
|
negate() {
|
|
2809
|
-
return new
|
|
898
|
+
return new x(this.X, e.neg(this.Y), this.Z);
|
|
2810
899
|
}
|
|
2811
900
|
// Renes-Costello-Batina exception-free doubling formula.
|
|
2812
901
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2813
902
|
// https://eprint.iacr.org/2015/1060, algorithm 3
|
|
2814
903
|
// Cost: 8M + 3S + 3*a + 2*b3 + 15add.
|
|
2815
904
|
double() {
|
|
2816
|
-
const { a: d, b:
|
|
2817
|
-
let
|
|
2818
|
-
return
|
|
905
|
+
const { a: d, b: l } = s, f = e.mul(l, ft), { X: h, Y: m, Z: E } = this;
|
|
906
|
+
let b = e.ZERO, g = e.ZERO, y = e.ZERO, p = e.mul(h, h), D = e.mul(m, m), Z = e.mul(E, E), O = e.mul(h, m);
|
|
907
|
+
return O = e.add(O, O), y = e.mul(h, E), y = e.add(y, y), b = e.mul(d, y), g = e.mul(f, Z), g = e.add(b, g), b = e.sub(D, g), g = e.add(D, g), g = e.mul(b, g), b = e.mul(O, b), y = e.mul(f, y), Z = e.mul(d, Z), O = e.sub(p, Z), O = e.mul(d, O), O = e.add(O, y), y = e.add(p, p), p = e.add(y, p), p = e.add(p, Z), p = e.mul(p, O), g = e.add(g, p), Z = e.mul(m, E), Z = e.add(Z, Z), p = e.mul(Z, O), b = e.sub(b, p), y = e.mul(Z, D), y = e.add(y, y), y = e.add(y, y), new x(b, g, y);
|
|
2819
908
|
}
|
|
2820
909
|
// Renes-Costello-Batina exception-free addition formula.
|
|
2821
910
|
// There is 30% faster Jacobian formula, but it is not complete.
|
|
2822
911
|
// https://eprint.iacr.org/2015/1060, algorithm 1
|
|
2823
912
|
// Cost: 12M + 0S + 3*a + 3*b3 + 23add.
|
|
2824
913
|
add(d) {
|
|
2825
|
-
|
|
2826
|
-
const { X:
|
|
2827
|
-
let
|
|
2828
|
-
const
|
|
2829
|
-
let
|
|
2830
|
-
|
|
2831
|
-
let
|
|
2832
|
-
return
|
|
914
|
+
Y(d);
|
|
915
|
+
const { X: l, Y: f, Z: h } = this, { X: m, Y: E, Z: b } = d;
|
|
916
|
+
let g = e.ZERO, y = e.ZERO, p = e.ZERO;
|
|
917
|
+
const D = s.a, Z = e.mul(s.b, ft);
|
|
918
|
+
let O = e.mul(l, m), A = e.mul(f, E), U = e.mul(h, b), G = e.add(l, f), L = e.add(m, E);
|
|
919
|
+
G = e.mul(G, L), L = e.add(O, A), G = e.sub(G, L), L = e.add(l, h);
|
|
920
|
+
let k = e.add(m, b);
|
|
921
|
+
return L = e.mul(L, k), k = e.add(O, U), L = e.sub(L, k), k = e.add(f, h), g = e.add(E, b), k = e.mul(k, g), g = e.add(A, U), k = e.sub(k, g), p = e.mul(D, L), g = e.mul(Z, U), p = e.add(g, p), g = e.sub(A, p), p = e.add(A, p), y = e.mul(g, p), A = e.add(O, O), A = e.add(A, O), U = e.mul(D, U), L = e.mul(Z, L), A = e.add(A, U), U = e.sub(O, U), U = e.mul(D, U), L = e.add(L, U), O = e.mul(A, L), y = e.add(y, O), O = e.mul(k, L), g = e.mul(G, g), g = e.sub(g, O), O = e.mul(G, A), p = e.mul(k, p), p = e.add(p, O), new x(g, y, p);
|
|
2833
922
|
}
|
|
2834
923
|
subtract(d) {
|
|
2835
924
|
return this.add(d.negate());
|
|
2836
925
|
}
|
|
2837
926
|
is0() {
|
|
2838
|
-
return this.equals(
|
|
927
|
+
return this.equals(x.ZERO);
|
|
2839
928
|
}
|
|
2840
929
|
/**
|
|
2841
930
|
* Constant time multiplication.
|
|
@@ -2847,19 +936,19 @@ function zn(e, r = {}) {
|
|
|
2847
936
|
* @returns New point
|
|
2848
937
|
*/
|
|
2849
938
|
multiply(d) {
|
|
2850
|
-
const { endo:
|
|
2851
|
-
if (!
|
|
939
|
+
const { endo: l } = t;
|
|
940
|
+
if (!o.isValidNot0(d))
|
|
2852
941
|
throw new Error("invalid scalar: out of range");
|
|
2853
|
-
let
|
|
2854
|
-
const
|
|
2855
|
-
if (
|
|
2856
|
-
const { k1neg:
|
|
2857
|
-
|
|
942
|
+
let f, h;
|
|
943
|
+
const m = (E) => tt.cached(this, E, (b) => Ut(x, b));
|
|
944
|
+
if (l) {
|
|
945
|
+
const { k1neg: E, k1: b, k2neg: g, k2: y } = K(d), { p, f: D } = m(b), { p: Z, f: O } = m(y);
|
|
946
|
+
h = D.add(O), f = H(l.beta, p, Z, E, g);
|
|
2858
947
|
} else {
|
|
2859
|
-
const { p:
|
|
2860
|
-
|
|
948
|
+
const { p: E, f: b } = m(d);
|
|
949
|
+
f = E, h = b;
|
|
2861
950
|
}
|
|
2862
|
-
return
|
|
951
|
+
return Ut(x, [f, h])[0];
|
|
2863
952
|
}
|
|
2864
953
|
/**
|
|
2865
954
|
* Non-constant-time multiplication. Uses double-and-add algorithm.
|
|
@@ -2867,421 +956,286 @@ function zn(e, r = {}) {
|
|
|
2867
956
|
* an exposed secret key e.g. sig verification, which works over *public* keys.
|
|
2868
957
|
*/
|
|
2869
958
|
multiplyUnsafe(d) {
|
|
2870
|
-
const { endo:
|
|
2871
|
-
if (!
|
|
959
|
+
const { endo: l } = t, f = this;
|
|
960
|
+
if (!o.isValid(d))
|
|
2872
961
|
throw new Error("invalid scalar: out of range");
|
|
2873
|
-
if (d ===
|
|
2874
|
-
return
|
|
2875
|
-
if (d ===
|
|
2876
|
-
return
|
|
2877
|
-
if (
|
|
962
|
+
if (d === W || f.is0())
|
|
963
|
+
return x.ZERO;
|
|
964
|
+
if (d === rt)
|
|
965
|
+
return f;
|
|
966
|
+
if (tt.hasCache(this))
|
|
2878
967
|
return this.multiply(d);
|
|
2879
|
-
if (
|
|
2880
|
-
const { k1neg:
|
|
2881
|
-
return
|
|
968
|
+
if (l) {
|
|
969
|
+
const { k1neg: h, k1: m, k2neg: E, k2: b } = K(d), { p1: g, p2: y } = Ae(x, f, m, b);
|
|
970
|
+
return H(l.beta, g, y, h, E);
|
|
2882
971
|
} else
|
|
2883
|
-
return
|
|
2884
|
-
}
|
|
2885
|
-
multiplyAndAddUnsafe(d, u, n) {
|
|
2886
|
-
const a = this.multiplyUnsafe(u).add(d.multiplyUnsafe(n));
|
|
2887
|
-
return a.is0() ? void 0 : a;
|
|
972
|
+
return tt.unsafe(f, d);
|
|
2888
973
|
}
|
|
2889
974
|
/**
|
|
2890
975
|
* Converts Projective point to affine (x, y) coordinates.
|
|
2891
976
|
* @param invertedZ Z^-1 (inverted zero) - optional, precomputation is useful for invertBatch
|
|
2892
977
|
*/
|
|
2893
978
|
toAffine(d) {
|
|
2894
|
-
return
|
|
979
|
+
return M(this, d);
|
|
2895
980
|
}
|
|
2896
981
|
/**
|
|
2897
982
|
* Checks whether Point is free of torsion elements (is in prime subgroup).
|
|
2898
983
|
* Always torsion-free for cofactor=1 curves.
|
|
2899
984
|
*/
|
|
2900
985
|
isTorsionFree() {
|
|
2901
|
-
const { isTorsionFree: d } =
|
|
2902
|
-
return
|
|
986
|
+
const { isTorsionFree: d } = t;
|
|
987
|
+
return i === rt ? !0 : d ? d(x, this) : tt.unsafe(this, u).is0();
|
|
2903
988
|
}
|
|
2904
989
|
clearCofactor() {
|
|
2905
|
-
const { clearCofactor: d } =
|
|
2906
|
-
return
|
|
990
|
+
const { clearCofactor: d } = t;
|
|
991
|
+
return i === rt ? this : d ? d(x, this) : this.multiplyUnsafe(i);
|
|
2907
992
|
}
|
|
2908
993
|
isSmallOrder() {
|
|
2909
|
-
return this.multiplyUnsafe(
|
|
994
|
+
return this.multiplyUnsafe(i).is0();
|
|
2910
995
|
}
|
|
2911
996
|
toBytes(d = !0) {
|
|
2912
|
-
return
|
|
997
|
+
return dt(d, "isCompressed"), this.assertValidity(), B(x, this, d);
|
|
2913
998
|
}
|
|
2914
999
|
toHex(d = !0) {
|
|
2915
|
-
return
|
|
1000
|
+
return ht(this.toBytes(d));
|
|
2916
1001
|
}
|
|
2917
1002
|
toString() {
|
|
2918
1003
|
return `<Point ${this.is0() ? "ZERO" : this.toHex()}>`;
|
|
2919
1004
|
}
|
|
2920
|
-
// TODO: remove
|
|
2921
|
-
get px() {
|
|
2922
|
-
return this.X;
|
|
2923
|
-
}
|
|
2924
|
-
get py() {
|
|
2925
|
-
return this.X;
|
|
2926
|
-
}
|
|
2927
|
-
get pz() {
|
|
2928
|
-
return this.Z;
|
|
2929
|
-
}
|
|
2930
|
-
toRawBytes(d = !0) {
|
|
2931
|
-
return this.toBytes(d);
|
|
2932
|
-
}
|
|
2933
|
-
_setWindowSize(d) {
|
|
2934
|
-
this.precompute(d);
|
|
2935
|
-
}
|
|
2936
|
-
static normalizeZ(d) {
|
|
2937
|
-
return it(_, d);
|
|
2938
|
-
}
|
|
2939
|
-
static msm(d, u) {
|
|
2940
|
-
return Mn(_, l, d, u);
|
|
2941
|
-
}
|
|
2942
|
-
static fromPrivateKey(d) {
|
|
2943
|
-
return _.BASE.multiply(He(l, d));
|
|
2944
|
-
}
|
|
2945
1005
|
}
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
return _.BASE.precompute(8), _;
|
|
1006
|
+
const P = o.BITS, tt = new Ze(x, t.endo ? Math.ceil(P / 2) : P);
|
|
1007
|
+
return x.BASE.precompute(8), x;
|
|
2949
1008
|
}
|
|
2950
|
-
function
|
|
2951
|
-
return Uint8Array.of(
|
|
1009
|
+
function ue(n) {
|
|
1010
|
+
return Uint8Array.of(n ? 2 : 3);
|
|
2952
1011
|
}
|
|
2953
|
-
function
|
|
1012
|
+
function le(n, t) {
|
|
2954
1013
|
return {
|
|
2955
|
-
secretKey:
|
|
2956
|
-
publicKey: 1 +
|
|
2957
|
-
publicKeyUncompressed: 1 + 2 *
|
|
1014
|
+
secretKey: t.BYTES,
|
|
1015
|
+
publicKey: 1 + n.BYTES,
|
|
1016
|
+
publicKeyUncompressed: 1 + 2 * n.BYTES,
|
|
2958
1017
|
publicKeyHasPrefix: !0,
|
|
2959
|
-
signature: 2 *
|
|
1018
|
+
signature: 2 * t.BYTES
|
|
2960
1019
|
};
|
|
2961
1020
|
}
|
|
2962
|
-
function
|
|
2963
|
-
const { Fn:
|
|
2964
|
-
function
|
|
1021
|
+
function Ve(n, t = {}) {
|
|
1022
|
+
const { Fn: r } = n, e = t.randomBytes || Mt, o = Object.assign(le(n.Fp, r), { seed: ie(r.ORDER) });
|
|
1023
|
+
function s(B) {
|
|
2965
1024
|
try {
|
|
2966
|
-
|
|
1025
|
+
const v = r.fromBytes(B);
|
|
1026
|
+
return r.isValidNot0(v);
|
|
2967
1027
|
} catch {
|
|
2968
1028
|
return !1;
|
|
2969
1029
|
}
|
|
2970
1030
|
}
|
|
2971
|
-
function
|
|
2972
|
-
const { publicKey:
|
|
1031
|
+
function i(B, v) {
|
|
1032
|
+
const { publicKey: _, publicKeyUncompressed: R } = o;
|
|
2973
1033
|
try {
|
|
2974
|
-
const
|
|
2975
|
-
return
|
|
1034
|
+
const N = B.length;
|
|
1035
|
+
return v === !0 && N !== _ || v === !1 && N !== R ? !1 : !!n.fromBytes(B);
|
|
2976
1036
|
} catch {
|
|
2977
1037
|
return !1;
|
|
2978
1038
|
}
|
|
2979
1039
|
}
|
|
2980
|
-
function
|
|
2981
|
-
return
|
|
2982
|
-
}
|
|
2983
|
-
function v(b, S = !0) {
|
|
2984
|
-
return e.BASE.multiply(He(c, b)).toBytes(S);
|
|
1040
|
+
function u(B = e(o.seed)) {
|
|
1041
|
+
return _e(V(B, o.seed, "seed"), r.ORDER);
|
|
2985
1042
|
}
|
|
2986
|
-
function
|
|
2987
|
-
|
|
2988
|
-
return { secretKey: S, publicKey: v(S) };
|
|
1043
|
+
function c(B, v = !0) {
|
|
1044
|
+
return n.BASE.multiply(r.fromBytes(B)).toBytes(v);
|
|
2989
1045
|
}
|
|
2990
|
-
function
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
if (b instanceof e)
|
|
2994
|
-
return !0;
|
|
2995
|
-
const { secretKey: S, publicKey: A, publicKeyUncompressed: M } = l;
|
|
2996
|
-
if (c.allowedLengths || S === A)
|
|
1046
|
+
function a(B) {
|
|
1047
|
+
const { secretKey: v, publicKey: _, publicKeyUncompressed: R } = o;
|
|
1048
|
+
if (!Kt(B) || "_lengths" in r && r._lengths || v === _)
|
|
2997
1049
|
return;
|
|
2998
|
-
const
|
|
2999
|
-
return
|
|
1050
|
+
const N = V(B, void 0, "key").length;
|
|
1051
|
+
return N === _ || N === R;
|
|
3000
1052
|
}
|
|
3001
|
-
function
|
|
3002
|
-
if (
|
|
1053
|
+
function w(B, v, _ = !0) {
|
|
1054
|
+
if (a(B) === !0)
|
|
3003
1055
|
throw new Error("first arg must be private key");
|
|
3004
|
-
if (
|
|
1056
|
+
if (a(v) === !1)
|
|
3005
1057
|
throw new Error("second arg must be public key");
|
|
3006
|
-
const
|
|
3007
|
-
return
|
|
3008
|
-
}
|
|
3009
|
-
|
|
3010
|
-
isValidSecretKey:
|
|
3011
|
-
isValidPublicKey:
|
|
3012
|
-
randomSecretKey:
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
return S.precompute(b, !1);
|
|
3019
|
-
}
|
|
3020
|
-
}, lengths: l });
|
|
3021
|
-
}
|
|
3022
|
-
function Yn(e, r, c = {}) {
|
|
3023
|
-
mn(r), gt(c, {}, {
|
|
1058
|
+
const R = r.fromBytes(B);
|
|
1059
|
+
return n.fromBytes(v).multiply(R).toBytes(_);
|
|
1060
|
+
}
|
|
1061
|
+
const S = {
|
|
1062
|
+
isValidSecretKey: s,
|
|
1063
|
+
isValidPublicKey: i,
|
|
1064
|
+
randomSecretKey: u
|
|
1065
|
+
}, q = De(u, c);
|
|
1066
|
+
return Object.freeze({ getPublicKey: c, getSharedSecret: w, keygen: q, Point: n, utils: S, lengths: o });
|
|
1067
|
+
}
|
|
1068
|
+
function $e(n, t, r = {}) {
|
|
1069
|
+
de(t), Ot(r, {}, {
|
|
3024
1070
|
hmac: "function",
|
|
3025
1071
|
lowS: "boolean",
|
|
3026
1072
|
randomBytes: "function",
|
|
3027
1073
|
bits2int: "function",
|
|
3028
1074
|
bits2int_modN: "function"
|
|
3029
|
-
});
|
|
3030
|
-
const
|
|
3031
|
-
prehash: !
|
|
3032
|
-
lowS: typeof
|
|
3033
|
-
format:
|
|
3034
|
-
//'compact' as ECDSASigFormat,
|
|
1075
|
+
}), r = Object.assign({}, r);
|
|
1076
|
+
const e = r.randomBytes || Mt, o = r.hmac || ((l, f) => ae(t, l, f)), { Fp: s, Fn: i } = n, { ORDER: u, BITS: c } = i, { keygen: a, getPublicKey: w, getSharedSecret: S, utils: q, lengths: B } = Ve(n, r), v = {
|
|
1077
|
+
prehash: !0,
|
|
1078
|
+
lowS: typeof r.lowS == "boolean" ? r.lowS : !0,
|
|
1079
|
+
format: "compact",
|
|
3035
1080
|
extraEntropy: !1
|
|
3036
|
-
},
|
|
3037
|
-
function
|
|
3038
|
-
const
|
|
3039
|
-
return
|
|
3040
|
-
}
|
|
3041
|
-
function
|
|
3042
|
-
if (!
|
|
3043
|
-
throw new Error(`invalid signature ${
|
|
3044
|
-
return
|
|
3045
|
-
}
|
|
3046
|
-
function
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
1081
|
+
}, _ = u * fe < s.ORDER;
|
|
1082
|
+
function R(l) {
|
|
1083
|
+
const f = u >> rt;
|
|
1084
|
+
return l > f;
|
|
1085
|
+
}
|
|
1086
|
+
function N(l, f) {
|
|
1087
|
+
if (!i.isValidNot0(f))
|
|
1088
|
+
throw new Error(`invalid signature ${l}: out of range 1..Point.Fn.ORDER`);
|
|
1089
|
+
return f;
|
|
1090
|
+
}
|
|
1091
|
+
function T() {
|
|
1092
|
+
if (_)
|
|
1093
|
+
throw new Error('"recovered" sig type is not supported for cofactor >2 curves');
|
|
1094
|
+
}
|
|
1095
|
+
function C(l, f) {
|
|
1096
|
+
pt(f);
|
|
1097
|
+
const h = B.signature, m = f === "compact" ? h : f === "recovered" ? h + 1 : void 0;
|
|
1098
|
+
return V(l, m);
|
|
1099
|
+
}
|
|
1100
|
+
class Y {
|
|
1101
|
+
r;
|
|
1102
|
+
s;
|
|
1103
|
+
recovery;
|
|
1104
|
+
constructor(f, h, m) {
|
|
1105
|
+
if (this.r = N("r", f), this.s = N("s", h), m != null) {
|
|
1106
|
+
if (T(), ![0, 1, 2, 3].includes(m))
|
|
1107
|
+
throw new Error("invalid recovery id");
|
|
1108
|
+
this.recovery = m;
|
|
3061
1109
|
}
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
return new G(this.r, this.s, n);
|
|
3071
|
-
}
|
|
3072
|
-
recoverPublicKey(n) {
|
|
3073
|
-
const a = m.ORDER, { r: i, s: o, recovery: h } = this;
|
|
3074
|
-
if (h == null || ![0, 1, 2, 3].includes(h))
|
|
3075
|
-
throw new Error("recovery id invalid");
|
|
3076
|
-
if (p * an < a && h > 1)
|
|
3077
|
-
throw new Error("recovery id is ambiguous for h>1 curve");
|
|
3078
|
-
const s = h === 2 || h === 3 ? i + p : i;
|
|
3079
|
-
if (!m.isValid(s))
|
|
3080
|
-
throw new Error("recovery id 2 or 3 invalid");
|
|
3081
|
-
const f = m.toBytes(s), y = e.fromBytes(Ae(fn((h & 1) === 0), f)), B = g.inv(s), T = ie(Se("msgHash", n)), V = g.create(-T * B), Y = g.create(o * B), I = e.BASE.multiplyUnsafe(V).add(y.multiplyUnsafe(Y));
|
|
3082
|
-
if (I.is0())
|
|
3083
|
-
throw new Error("point at infinify");
|
|
3084
|
-
return I.assertValidity(), I;
|
|
3085
|
-
}
|
|
3086
|
-
// Signatures should be low-s, to prevent malleability.
|
|
3087
|
-
hasHighS() {
|
|
3088
|
-
return M(this.s);
|
|
3089
|
-
}
|
|
3090
|
-
toBytes(n = A) {
|
|
3091
|
-
if (dt(n), n === "der")
|
|
3092
|
-
return Qe(Ie.hexFromSig(this));
|
|
3093
|
-
const a = g.toBytes(this.r), i = g.toBytes(this.s);
|
|
3094
|
-
if (n === "recovered") {
|
|
3095
|
-
if (this.recovery == null)
|
|
3096
|
-
throw new Error("recovery bit must be present");
|
|
3097
|
-
return Ae(Uint8Array.of(this.recovery), a, i);
|
|
1110
|
+
Object.freeze(this);
|
|
1111
|
+
}
|
|
1112
|
+
static fromBytes(f, h = v.format) {
|
|
1113
|
+
C(f, h);
|
|
1114
|
+
let m;
|
|
1115
|
+
if (h === "der") {
|
|
1116
|
+
const { r: y, s: p } = Q.toSig(V(f));
|
|
1117
|
+
return new Y(y, p);
|
|
3098
1118
|
}
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
return Me(this.toBytes(n));
|
|
3103
|
-
}
|
|
3104
|
-
// TODO: remove
|
|
3105
|
-
assertValidity() {
|
|
1119
|
+
h === "recovered" && (m = f[0], h = "compact", f = f.subarray(1));
|
|
1120
|
+
const E = B.signature / 2, b = f.subarray(0, E), g = f.subarray(E, E * 2);
|
|
1121
|
+
return new Y(i.fromBytes(b), i.fromBytes(g), m);
|
|
3106
1122
|
}
|
|
3107
|
-
static
|
|
3108
|
-
return
|
|
1123
|
+
static fromHex(f, h) {
|
|
1124
|
+
return this.fromBytes(lt(f), h);
|
|
3109
1125
|
}
|
|
3110
|
-
|
|
3111
|
-
|
|
1126
|
+
assertRecovery() {
|
|
1127
|
+
const { recovery: f } = this;
|
|
1128
|
+
if (f == null)
|
|
1129
|
+
throw new Error("invalid recovery id: must be present");
|
|
1130
|
+
return f;
|
|
3112
1131
|
}
|
|
3113
|
-
|
|
3114
|
-
return
|
|
1132
|
+
addRecoveryBit(f) {
|
|
1133
|
+
return new Y(this.r, this.s, f);
|
|
3115
1134
|
}
|
|
3116
|
-
|
|
3117
|
-
|
|
1135
|
+
recoverPublicKey(f) {
|
|
1136
|
+
const { r: h, s: m } = this, E = this.assertRecovery(), b = E === 2 || E === 3 ? h + u : h;
|
|
1137
|
+
if (!s.isValid(b))
|
|
1138
|
+
throw new Error("invalid recovery id: sig.r+curve.n != R.x");
|
|
1139
|
+
const g = s.toBytes(b), y = n.fromBytes(J(ue((E & 1) === 0), g)), p = i.inv(b), D = M(V(f, void 0, "msgHash")), Z = i.create(-D * p), O = i.create(m * p), A = n.BASE.multiplyUnsafe(Z).add(y.multiplyUnsafe(O));
|
|
1140
|
+
if (A.is0())
|
|
1141
|
+
throw new Error("invalid recovery: point at infinify");
|
|
1142
|
+
return A.assertValidity(), A;
|
|
3118
1143
|
}
|
|
3119
|
-
|
|
3120
|
-
|
|
1144
|
+
// Signatures should be low-s, to prevent malleability.
|
|
1145
|
+
hasHighS() {
|
|
1146
|
+
return R(this.s);
|
|
3121
1147
|
}
|
|
3122
|
-
|
|
3123
|
-
|
|
1148
|
+
toBytes(f = v.format) {
|
|
1149
|
+
if (pt(f), f === "der")
|
|
1150
|
+
return lt(Q.hexFromSig(this));
|
|
1151
|
+
const { r: h, s: m } = this, E = i.toBytes(h), b = i.toBytes(m);
|
|
1152
|
+
return f === "recovered" ? (T(), J(Uint8Array.of(this.assertRecovery()), E, b)) : J(E, b);
|
|
3124
1153
|
}
|
|
3125
|
-
|
|
3126
|
-
return
|
|
1154
|
+
toHex(f) {
|
|
1155
|
+
return ht(this.toBytes(f));
|
|
3127
1156
|
}
|
|
3128
1157
|
}
|
|
3129
|
-
const
|
|
3130
|
-
if (
|
|
1158
|
+
const K = r.bits2int || function(f) {
|
|
1159
|
+
if (f.length > 8192)
|
|
3131
1160
|
throw new Error("input is too large");
|
|
3132
|
-
const
|
|
3133
|
-
return
|
|
3134
|
-
},
|
|
3135
|
-
return
|
|
3136
|
-
},
|
|
3137
|
-
function
|
|
3138
|
-
return
|
|
3139
|
-
}
|
|
3140
|
-
function
|
|
3141
|
-
return
|
|
3142
|
-
}
|
|
3143
|
-
function
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
const
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
1161
|
+
const h = wt(f), m = f.length * 8 - c;
|
|
1162
|
+
return m > 0 ? h >> BigInt(m) : h;
|
|
1163
|
+
}, M = r.bits2int_modN || function(f) {
|
|
1164
|
+
return i.create(K(f));
|
|
1165
|
+
}, F = St(c);
|
|
1166
|
+
function H(l) {
|
|
1167
|
+
return me("num < 2^" + c, l, W, F), i.toBytes(l);
|
|
1168
|
+
}
|
|
1169
|
+
function x(l, f) {
|
|
1170
|
+
return V(l, void 0, "message"), f ? V(t(l), void 0, "prehashed message") : l;
|
|
1171
|
+
}
|
|
1172
|
+
function P(l, f, h) {
|
|
1173
|
+
const { lowS: m, prehash: E, extraEntropy: b } = yt(h, v);
|
|
1174
|
+
l = x(l, E);
|
|
1175
|
+
const g = M(l), y = i.fromBytes(f);
|
|
1176
|
+
if (!i.isValidNot0(y))
|
|
1177
|
+
throw new Error("invalid private key");
|
|
1178
|
+
const p = [H(y), H(g)];
|
|
1179
|
+
if (b != null && b !== !1) {
|
|
1180
|
+
const A = b === !0 ? e(B.secretKey) : b;
|
|
1181
|
+
p.push(V(A, void 0, "extraEntropy"));
|
|
1182
|
+
}
|
|
1183
|
+
const D = J(...p), Z = g;
|
|
1184
|
+
function O(A) {
|
|
1185
|
+
const U = K(A);
|
|
1186
|
+
if (!i.isValidNot0(U))
|
|
3157
1187
|
return;
|
|
3158
|
-
const
|
|
3159
|
-
if (
|
|
1188
|
+
const G = i.inv(U), L = n.BASE.multiply(U).toAffine(), k = i.create(L.x);
|
|
1189
|
+
if (k === W)
|
|
3160
1190
|
return;
|
|
3161
|
-
const
|
|
3162
|
-
if (
|
|
1191
|
+
const st = i.create(G * i.create(Z + k * y));
|
|
1192
|
+
if (st === W)
|
|
3163
1193
|
return;
|
|
3164
|
-
let
|
|
3165
|
-
return
|
|
1194
|
+
let _t = (L.x === k ? 0 : 2) | Number(L.y & rt), Zt = st;
|
|
1195
|
+
return m && R(st) && (Zt = i.neg(st), _t ^= 1), new Y(k, Zt, _ ? void 0 : _t);
|
|
3166
1196
|
}
|
|
3167
|
-
return { seed:
|
|
3168
|
-
}
|
|
3169
|
-
function
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
}
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3177
|
-
|
|
3178
|
-
throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");
|
|
3179
|
-
if (i)
|
|
3180
|
-
n = new G(u.r, u.s);
|
|
3181
|
-
else if (a) {
|
|
3182
|
-
try {
|
|
3183
|
-
n = G.fromBytes(Se("sig", u), "der");
|
|
3184
|
-
} catch (o) {
|
|
3185
|
-
if (!(o instanceof Ie.Err))
|
|
3186
|
-
throw o;
|
|
3187
|
-
}
|
|
3188
|
-
if (!n)
|
|
3189
|
-
try {
|
|
3190
|
-
n = G.fromBytes(Se("sig", u), "compact");
|
|
3191
|
-
} catch {
|
|
3192
|
-
return !1;
|
|
3193
|
-
}
|
|
1197
|
+
return { seed: D, k2sig: O };
|
|
1198
|
+
}
|
|
1199
|
+
function tt(l, f, h = {}) {
|
|
1200
|
+
const { seed: m, k2sig: E } = P(l, f, h);
|
|
1201
|
+
return Ee(t.outputLen, i.BYTES, o)(m, E).toBytes(h.format);
|
|
1202
|
+
}
|
|
1203
|
+
function I(l, f, h, m = {}) {
|
|
1204
|
+
const { lowS: E, prehash: b, format: g } = yt(m, v);
|
|
1205
|
+
if (h = V(h, void 0, "publicKey"), f = x(f, b), !Kt(l)) {
|
|
1206
|
+
const y = l instanceof Y ? ", use sig.toBytes()" : "";
|
|
1207
|
+
throw new Error("verify expects Uint8Array signature" + y);
|
|
3194
1208
|
}
|
|
3195
|
-
|
|
3196
|
-
}
|
|
3197
|
-
function z(u, n, a, i = {}) {
|
|
3198
|
-
const { lowS: o, prehash: h, format: w } = ut(i, S);
|
|
3199
|
-
if (a = Se("publicKey", a), n = L(Se("message", n), h), "strict" in i)
|
|
3200
|
-
throw new Error("options.strict was renamed to lowS");
|
|
3201
|
-
const s = w === void 0 ? W(u) : G.fromBytes(Se("sig", u), w);
|
|
3202
|
-
if (s === !1)
|
|
3203
|
-
return !1;
|
|
1209
|
+
C(l, g);
|
|
3204
1210
|
try {
|
|
3205
|
-
const
|
|
3206
|
-
if (
|
|
1211
|
+
const y = Y.fromBytes(l, g), p = n.fromBytes(h);
|
|
1212
|
+
if (E && y.hasHighS())
|
|
3207
1213
|
return !1;
|
|
3208
|
-
const { r:
|
|
3209
|
-
return
|
|
1214
|
+
const { r: D, s: Z } = y, O = M(f), A = i.inv(Z), U = i.create(O * A), G = i.create(D * A), L = n.BASE.multiplyUnsafe(U).add(p.multiplyUnsafe(G));
|
|
1215
|
+
return L.is0() ? !1 : i.create(L.x) === D;
|
|
3210
1216
|
} catch {
|
|
3211
1217
|
return !1;
|
|
3212
1218
|
}
|
|
3213
1219
|
}
|
|
3214
|
-
function d(
|
|
3215
|
-
const { prehash:
|
|
3216
|
-
return
|
|
1220
|
+
function d(l, f, h = {}) {
|
|
1221
|
+
const { prehash: m } = yt(h, v);
|
|
1222
|
+
return f = x(f, m), Y.fromBytes(l, "recovered").recoverPublicKey(f).toBytes();
|
|
3217
1223
|
}
|
|
3218
1224
|
return Object.freeze({
|
|
3219
|
-
keygen:
|
|
3220
|
-
getPublicKey:
|
|
3221
|
-
getSharedSecret:
|
|
3222
|
-
utils:
|
|
3223
|
-
lengths:
|
|
3224
|
-
Point:
|
|
3225
|
-
sign:
|
|
3226
|
-
verify:
|
|
1225
|
+
keygen: a,
|
|
1226
|
+
getPublicKey: w,
|
|
1227
|
+
getSharedSecret: S,
|
|
1228
|
+
utils: q,
|
|
1229
|
+
lengths: B,
|
|
1230
|
+
Point: n,
|
|
1231
|
+
sign: tt,
|
|
1232
|
+
verify: I,
|
|
3227
1233
|
recoverPublicKey: d,
|
|
3228
|
-
Signature:
|
|
3229
|
-
hash:
|
|
3230
|
-
});
|
|
3231
|
-
}
|
|
3232
|
-
function Pn(e) {
|
|
3233
|
-
const r = {
|
|
3234
|
-
a: e.a,
|
|
3235
|
-
b: e.b,
|
|
3236
|
-
p: e.Fp.ORDER,
|
|
3237
|
-
n: e.n,
|
|
3238
|
-
h: e.h,
|
|
3239
|
-
Gx: e.Gx,
|
|
3240
|
-
Gy: e.Gy
|
|
3241
|
-
}, c = e.Fp;
|
|
3242
|
-
let t = e.allowedPrivateKeyLengths ? Array.from(new Set(e.allowedPrivateKeyLengths.map((g) => Math.ceil(g / 2)))) : void 0;
|
|
3243
|
-
const l = De(r.n, {
|
|
3244
|
-
BITS: e.nBitLength,
|
|
3245
|
-
allowedLengths: t,
|
|
3246
|
-
modFromBytes: e.wrapPrivateKey
|
|
3247
|
-
}), m = {
|
|
3248
|
-
Fp: c,
|
|
3249
|
-
Fn: l,
|
|
3250
|
-
allowInfinityPoint: e.allowInfinityPoint,
|
|
3251
|
-
endo: e.endo,
|
|
3252
|
-
isTorsionFree: e.isTorsionFree,
|
|
3253
|
-
clearCofactor: e.clearCofactor,
|
|
3254
|
-
fromBytes: e.fromBytes,
|
|
3255
|
-
toBytes: e.toBytes
|
|
3256
|
-
};
|
|
3257
|
-
return { CURVE: r, curveOpts: m };
|
|
3258
|
-
}
|
|
3259
|
-
function Xn(e) {
|
|
3260
|
-
const { CURVE: r, curveOpts: c } = Pn(e), t = {
|
|
3261
|
-
hmac: e.hmac,
|
|
3262
|
-
randomBytes: e.randomBytes,
|
|
3263
|
-
lowS: e.lowS,
|
|
3264
|
-
bits2int: e.bits2int,
|
|
3265
|
-
bits2int_modN: e.bits2int_modN
|
|
3266
|
-
};
|
|
3267
|
-
return { CURVE: r, curveOpts: c, hash: e.hash, ecdsaOpts: t };
|
|
3268
|
-
}
|
|
3269
|
-
function Gn(e, r) {
|
|
3270
|
-
const c = r.Point;
|
|
3271
|
-
return Object.assign({}, r, {
|
|
3272
|
-
ProjectivePoint: c,
|
|
3273
|
-
CURVE: Object.assign({}, e, nn(c.Fn.ORDER, c.Fn.BITS))
|
|
1234
|
+
Signature: Y,
|
|
1235
|
+
hash: t
|
|
3274
1236
|
});
|
|
3275
1237
|
}
|
|
3276
|
-
|
|
3277
|
-
const { CURVE: r, curveOpts: c, hash: t, ecdsaOpts: l } = Xn(e), m = zn(r, c), g = Yn(m, t, l);
|
|
3278
|
-
return Gn(e, g);
|
|
3279
|
-
}
|
|
3280
|
-
function Qn(e, r) {
|
|
3281
|
-
const c = (t) => Wn({ ...e, hash: t });
|
|
3282
|
-
return { ...c(r), create: c };
|
|
3283
|
-
}
|
|
3284
|
-
const Bt = {
|
|
1238
|
+
const Nt = {
|
|
3285
1239
|
p: BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),
|
|
3286
1240
|
n: BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),
|
|
3287
1241
|
h: BigInt(1),
|
|
@@ -3289,28 +1243,28 @@ const Bt = {
|
|
|
3289
1243
|
b: BigInt(7),
|
|
3290
1244
|
Gx: BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),
|
|
3291
1245
|
Gy: BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")
|
|
3292
|
-
},
|
|
1246
|
+
}, je = {
|
|
3293
1247
|
beta: BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),
|
|
3294
1248
|
basises: [
|
|
3295
1249
|
[BigInt("0x3086d221a7d46bcde86c90e49284eb15"), -BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],
|
|
3296
1250
|
[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"), BigInt("0x3086d221a7d46bcde86c90e49284eb15")]
|
|
3297
1251
|
]
|
|
3298
|
-
},
|
|
3299
|
-
function
|
|
3300
|
-
const
|
|
3301
|
-
if (!
|
|
1252
|
+
}, jt = /* @__PURE__ */ BigInt(2);
|
|
1253
|
+
function Me(n) {
|
|
1254
|
+
const t = Nt.p, r = BigInt(3), e = BigInt(6), o = BigInt(11), s = BigInt(22), i = BigInt(23), u = BigInt(44), c = BigInt(88), a = n * n * n % t, w = a * a * n % t, S = z(w, r, t) * w % t, q = z(S, r, t) * w % t, B = z(q, jt, t) * a % t, v = z(B, o, t) * B % t, _ = z(v, s, t) * v % t, R = z(_, u, t) * _ % t, N = z(R, c, t) * R % t, T = z(N, u, t) * _ % t, C = z(T, r, t) * w % t, Y = z(C, i, t) * v % t, K = z(Y, e, t) * a % t, M = z(K, jt, t);
|
|
1255
|
+
if (!vt.eql(vt.sqr(M), n))
|
|
3302
1256
|
throw new Error("Cannot find square root");
|
|
3303
|
-
return
|
|
1257
|
+
return M;
|
|
3304
1258
|
}
|
|
3305
|
-
const
|
|
1259
|
+
const vt = gt(Nt.p, { sqrt: Me }), Ke = /* @__PURE__ */ ke(Nt, {
|
|
1260
|
+
Fp: vt,
|
|
1261
|
+
endo: je
|
|
1262
|
+
}), He = /* @__PURE__ */ $e(Ke, he);
|
|
3306
1263
|
export {
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
qe as m,
|
|
3314
|
-
er as r,
|
|
3315
|
-
or as s
|
|
1264
|
+
Ce as F,
|
|
1265
|
+
dt as a,
|
|
1266
|
+
wt as b,
|
|
1267
|
+
X as m,
|
|
1268
|
+
ye as r,
|
|
1269
|
+
He as s
|
|
3316
1270
|
};
|