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