forked from Blockthon/Blockthon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Blockthon.py
586 lines (390 loc) · 30.6 KB
/
Blockthon.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# //////////////////////////////////////////////////
# // Github : github.com/Pymmdrza //
# // official Page : https://github.com/Blockthon //
# //////////////////////////////////////////////////
import codecs, ecdsa, hashlib, hmac, pbkdf2, os, base58
from bit import Key
from bit.format import bytes_to_wif
from binascii import hexlify as _decode
from binascii import unhexlify as _encode
from mnemonic import Mnemonic
import requests, json, re, random
from hdwallet import HDWallet
from hdwallet.symbols import BTC, ETH, TRX, LTC, DOGE, DGB, RVN, DASH, BTG, VIA, QTUM, ZEC
from bip32utils import BIP32Key
from bip32utils import BIP32_HARDEN
from bip32utils import Base58
import binascii
def PrivateKey():
return os.urandom(32).hex()
# --------------------------------------------------------------------------------
def base58_(hashaddr_):
a_ = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
b58_ = ''
_lz = len(hashaddr_) - len(hashaddr_.lstrip('0'))
_addrNum = int(hashaddr_, 16)
while _addrNum > 0:
dg_ = _addrNum % 58
cdg_ = a_[dg_]
b58_ = cdg_ + b58_
_addrNum //= 58
on_ = _lz // 2
for one in range(on_):
b58_ = '1' + b58_
return b58_
# --------------------------------------------------------------------------------
# Generated Mnemonic Random
def getMnemonic(size=12):
""" Size for Generated words 12 or 24 default 12 """
ml = ''
words = "AbandonAbilityAbleAboutAboveAbsentAbsorbAbstractAbsurdAbuseAccessAccidentAccountAccuseAchieveAcidAcousticAcquireAcrossActActionActorActressActualAdaptAddAddictAddressAdjustAdmitAdultAdvanceAdviceAerobicAffairAffordAfraidAgainAgeAgentAgreeAheadAimAirAirportAisleAlarmAlbumAlcoholAlertAlienAllAlleyAllowAlmostAloneAlphaAlreadyAlsoAlterAlwaysAmateurAmazingAmongAmountAmusedAnalystAnchorAncientAngerAngleAngryAnimalAnkleAnnounceAnnualAnotherAnswerAntennaAntiqueAnxietyAnyApartApologyAppearAppleApproveAprilArchArcticAreaArenaArgueArmArmedArmorArmyAroundArrangeArrestArriveArrowArtArtefactArtistArtworkAskAspectAssaultAssetAssistAssumeAsthmaAthleteAtomAttackAttendAttitudeAttractAuctionAuditAugustAuntAuthorAutoAutumnAverageAvocadoAvoidAwakeAwareAwayAwesomeAwfulAwkwardAxisBabyBachelorBaconBadgeBagBalanceBalconyBallBambooBananaBannerBarBarelyBargainBarrelBaseBasicBasketBattleBeachBeanBeautyBecauseBecomeBeefBeforeBeginBehaveBehindBelieveBelowBeltBenchBenefitBestBetrayBetterBetweenBeyondBicycleBidBikeBindBiologyBirdBirthBitterBlackBladeBlameBlanketBlastBleakBlessBlindBloodBlossomBlouseBlueBlurBlushBoardBoatBodyBoilBombBoneBonusBookBoostBorderBoringBorrowBossBottomBounceBoxBoyBracketBrainBrandBrassBraveBreadBreezeBrickBridgeBriefBrightBringBriskBroccoliBrokenBronzeBroomBrotherBrownBrushBubbleBuddyBudgetBuffaloBuildBulbBulkBulletBundleBunkerBurdenBurgerBurstBusBusinessBusyButterBuyerBuzzCabbageCabinCableCactusCageCakeCallCalmCameraCampCanCanalCancelCandyCannonCanoeCanvasCanyonCapableCapitalCaptainCarCarbonCardCargoCarpetCarryCartCaseCashCasinoCastleCasualCatCatalogCatchCategoryCattleCaughtCauseCautionCaveCeilingCeleryCementCensusCenturyCerealCertainChairChalkChampionChangeChaosChapterChargeChaseChatCheapCheckCheeseChefCherryChestChickenChiefChildChimneyChoiceChooseChronicChuckleChunkChurnCigarCinnamonCircleCitizenCityCivilClaimClapClarifyClawClayCleanClerkCleverClickClientCliffClimbClinicClipClockClogCloseClothCloudClownClubClumpClusterClutchCoachCoastCoconutCodeCoffeeCoilCoinCollectColorColumnCombineComeComfortComicCommonCompanyConcertConductConfirmCongressConnectConsiderControlConvinceCookCoolCopperCopyCoralCoreCornCorrectCostCottonCouchCountryCoupleCourseCousinCoverCoyoteCrackCradleCraftCramCraneCrashCraterCrawlCrazyCreamCreditCreekCrewCricketCrimeCrispCriticCropCrossCrouchCrowdCrucialCruelCruiseCrumbleCrunchCrushCryCrystalCubeCultureCupCupboardCuriousCurrentCurtainCurveCushionCustomCuteCycleDadDamageDampDanceDangerDaringDashDaughterDawnDayDealDebateDebrisDecadeDecemberDecideDeclineDecorateDecreaseDeerDefenseDefineDefyDegreeDelayDeliverDemandDemiseDenialDentistDenyDepartDependDepositDepthDeputyDeriveDescribeDesertDesignDeskDespairDestroyDetailDetectDevelopDeviceDevoteDiagramDialDiamondDiaryDiceDieselDietDifferDigitalDignityDilemmaDinnerDinosaurDirectDirtDisagreeDiscoverDiseaseDishDismissDisorderDisplayDistanceDivertDivideDivorceDizzyDoctorDocumentDogDollDolphinDomainDonateDonkeyDonorDoorDoseDoubleDoveDraftDragonDramaDrasticDrawDreamDressDriftDrillDrinkDripDriveDropDrumDryDuckDumbDuneDuringDustDutchDutyDwarfDynamicEagerEagleEarlyEarnEarthEasilyEastEasyEchoEcologyEconomyEdgeEditEducateEffortEggEightEitherElbowElderElectricElegantElementElephantElevatorEliteElseEmbarkEmbodyEmbraceEmergeEmotionEmployEmpowerEmptyEnableEnactEndEndlessEndorseEnemyEnergyEnforceEngageEngineEnhanceEnjoyEnlistEnoughEnrichEnrollEnsureEnterEntireEntryEnvelopeEpisodeEqualEquipEraEraseErodeErosionErrorEruptEscapeEssayEssenceEstateEternalEthicsEvidenceEvilEvokeEvolveExactExampleExcessExchangeExciteExcludeExcuseExecuteExerciseExhaustExhibitExileExistExitExoticExpandExpectExpireExplainExposeExpressExtendExtraEyeEyebrowFabricFaceFacultyFadeFaintFaithFallFalseFameFamilyFamousFanFancyFantasyFarmFashionFatFatalFatherFatigueFaultFavoriteFeatureFebruaryFederalFeeFeedFeelFemaleFenceFestivalFetchFeverFewFiberFictionFieldFigureFileFilmFilterFinalFindFineFingerFinishFireFirmFirstFiscalFishFitFitnessFixFlagFlameFlashFlatFlavorFleeFlightFlipFloatFlockFloorFlowerFluidFlushFlyFoamFocusFogFoilFoldFollowFoodFootForceForestForgetForkFortuneForumForwardFossilFosterFoundFoxFragileFrameFrequentFreshFriendFringeFrogFrontFrostFrownFrozenFruitFuelFunFunnyFurnaceFuryFutureGadgetGainGalaxyGalleryGameGapGarageGarbageGardenGarlicGarmentGasGaspGateGatherGaugeGazeGeneralGeniusGenreGentleGenuineGestureGhostGiantGiftGiggleGingerGiraffeGirlGiveGladGlanceGlareGlassGlideGlimpseGlobeGloomGloryGloveGlowGlueGoatGoddessGoldGoodGooseGorillaGospelGossipGovernGownGrabGraceGrainGrantGrapeGrassGravityGreatGreenGridGriefGritGroceryGroupGrowGruntGuardGuessGuideGuiltGuitarGunGymHabitHairHalfHammerHamsterHandHappyHarborHardHarshHarvestHatHaveHawkHazardHeadHealthHeartHeavyHedgehogHeightHelloHelmetHelpHenHeroHiddenHighHillHintHipHireHistoryHobbyHockeyHoldHoleHolidayHollowHomeHoneyHoodHopeHornHorrorHorseHospitalHostHotelHourHoverHubHugeHumanHumbleHumorHundredHungryHuntHurdleHurryHurtHusbandHybridIceIconIdeaIdentifyIdleIgnoreIllIllegalIllnessImageImitateImmenseImmuneImpactImposeImproveImpulseInchIncludeIncomeIncreaseIndexIndicateIndoorIndustryInfantInflictInformInhaleInheritInitialInjectInjuryInmateInnerInnocentInputInquiryInsaneInsectInsideInspireInstallIntactInterestIntoInvestInviteInvolveIronIslandIsolateIssueItemIvoryJacketJaguarJarJazzJealousJeansJellyJewelJobJoinJokeJourneyJoyJudgeJuiceJumpJungleJuniorJunkJustKangarooKeenKeepKetchupKeyKickKidKidneyKindKingdomKissKitKitchenKiteKittenKiwiKneeKnifeKnockKnowLabLabelLaborLadderLadyLakeLampLanguageLaptopLargeLaterLatinLaughLaundryLavaLawLawnLawsuitLayerLazyLeaderLeafLearnLeaveLectureLeftLegLegalLegendLeisureLemonLendLengthLensLeopardLessonLetterLevelLiarLibertyLibraryLicenseLifeLiftLightLikeLimbLimitLinkLionLiquidListLittleLiveLizardLoadLoanLobsterLocalLockLogicLonelyLongLoopLotteryLoudLoungeLoveLoyalLuckyLuggageLumberLunarLunchLuxuryLyricsMachineMadMagicMagnetMaidMailMainMajorMakeMammalManManageMandateMangoMansionManualMapleMarbleMarchMarginMarineMarketMarriageMaskMassMasterMatchMaterialMathMatrixMatterMaximumMazeMeadowMeanMeasureMeatMechanicMedalMediaMelodyMeltMemberMemoryMentionMenuMercyMergeMeritMerryMeshMessageMetalMethodMiddleMidnightMilkMillionMimicMindMinimumMinorMinuteMiracleMirrorMiseryMissMistakeMixMixedMixtureMobileModelModifyMomMomentMonitorMonkeyMonsterMonthMoonMoralMoreMorningMosquitoMotherMotionMotorMountainMouseMoveMovieMuchMuffinMuleMultiplyMuscleMuseumMushroomMusicMustMutualMyselfMysteryMythNaiveNameNapkinNarrowNastyNationNatureNearNeckNeedNegativeNeglectNeitherNephewNerveNestNetNetworkNeutralNeverNewsNextNiceNightNobleNoiseNomineeNoodleNormalNorthNoseNotableNoteNothingNoticeNovelNowNuclearNumberNurseNutOakObeyObjectObligeObscureObserveObtainObviousOccurOceanOctoberOdorOffOfferOfficeOftenOilOkayOldOliveOlympicOmitOnceOneOnionOnlineOnlyOpenOperaOpinionOpposeOptionOrangeOrbitOrchardOrderOrdinaryOrganOrientOriginalOrphanOstrichOtherOutdoorOuterOutputOutsideOvalOvenOverOwnOwnerOxygenOysterOzonePactPaddlePagePairPalacePalmPandaPanelPanicPantherPaperParadeParentParkParrotPartyPassPatchPathPatientPatrolPatternPausePavePaymentPeacePeanutPearPeasantPelicanPenPenaltyPencilPeoplePepperPerfectPermitPersonPetPhonePhotoPhrasePhysicalPianoPicnicPicturePiecePigPigeonPillPilotPinkPioneerPipePistolPitchPizzaPlacePlanetPlasticPlatePlayPleasePledgePluckPlugPlungePoemPoetPointPolarPolePolicePondPonyPoolPopularPortionPositionPossiblePostPotatoPotteryPovertyPowderPowerPracticePraisePredictPreferPreparePresentPrettyPreventPricePridePrimaryPrintPriorityPrisonPrivatePrizeProblemProcessProduceProfitProgramProjectPromoteProofPropertyProsperProtectProudProvidePublicPuddingPullPulpPulsePumpkinPunchPupilPuppyPurchasePurityPurposePursePushPutPuzzlePyramidQualityQuantumQuarterQuestionQuickQuitQuizQuoteRabbitRaccoonRaceRackRadarRadioRailRainRaiseRallyRampRanchRandomRangeRapidRareRateRatherRavenRawRazorReadyRealReasonRebelRebuildRecallReceiveRecipeRecordRecycleReduceReflectReformRefuseRegionRegretRegularRejectRelaxReleaseReliefRelyRemainRememberRemindRemoveRenderRenewRentReopenRepairRepeatReplaceReportRequireRescueResembleResistResourceResponseResultRetireRetreatReturnReunionRevealReviewRewardRhythmRibRibbonRiceRichRideRidgeRifleRightRigidRingRiotRippleRiskRitualRivalRiverRoadRoastRobotRobustRocketRomanceRoofRookieRoomRoseRotateRoughRoundRouteRoyalRubberRudeRugRuleRunRunwayRuralSadSaddleSadnessSafeSailSaladSalmonSalonSaltSaluteSameSampleSandSatisfySatoshiSauceSausageSaveSayScaleScanScareScatterSceneSchemeSchoolScienceScissorsScorpionScoutScrapScreenScriptScrubSeaSearchSeasonSeatSecondSecretSectionSecuritySeedSeekSegmentSelectSellSeminarSeniorSenseSentenceSeriesServiceSessionSettleSetupSevenShadowShaftShallowShareShedShellSheriffShieldShiftShineShipShiverShockShoeShootShopShortShoulderShoveShrimpShrugShuffleShySiblingSickSideSiegeSightSignSilentSilkSillySilverSimilarSimpleSinceSingSirenSisterSituateSixSizeSkateSketchSkiSkillSkinSkirtSkullSlabSlamSleepSlenderSliceSlideSlightSlimSloganSlotSlowSlushSmallSmartSmileSmokeSmoothSnackSnakeSnapSniffSnowSoapSoccerSocialSockSodaSoftSolarSoldierSolidSolutionSolveSomeoneSongSoonSorrySortSoulSoundSoupSourceSouthSpaceSpareSpatialSpawnSpeakSpecialSpeedSpellSpendSphereSpiceSpiderSpikeSpinSpiritSplitSpoilSponsorSpoonSportSpotSpraySpreadSpringSpySquareSqueezeSquirrelStableStadiumStaffStageStairsStampStandStartStateStaySteakSteelStemStepStereoStickStillStingStockStomachStoneStoolStoryStoveStrategyStreetStrikeStrongStruggleStudentStuffStumbleStyleSubjectSubmitSubwaySuccessSuchSuddenSufferSugarSuggestSuitSummerSunSunnySunsetSuperSupplySupremeSureSurfaceSurgeSurpriseSurroundSurveySuspectSustainSwallowSwampSwapSwarmSwearSweetSwiftSwimSwingSwitchSwordSymbolSymptomSyrupSystemTableTackleTagTailTalentTalkTankTapeTargetTaskTasteTattooTaxiTeachTeamTellTenTenantTennisTentTermTestTextThankThatThemeThenTheoryThereTheyThingThisThoughtThreeThriveThrowThumbThunderTicketTideTigerTiltTimberTimeTinyTipTiredTissueTitleToastTobaccoTodayToddlerToeTogetherToiletTokenTomatoTomorrowToneTongueTonightToolToothTopTopicToppleTorchTornadoTortoiseTossTotalTouristTowardTowerTownToyTrackTradeTrafficTragicTrainTransferTrapTrashTravelTrayTreatTreeTrendTrialTribeTrickTriggerTrimTripTrophyTroubleTruckTrueTrulyTrumpetTrustTruthTryTubeTuitionTumbleTunaTunnelTurkeyTurnTurtleTwelveTwentyTwiceTwinTwistTwoTypeTypicalUglyUmbrellaUnableUnawareUncleUncoverUnderUndoUnfairUnfoldUnhappyUniformUniqueUnitUniverseUnknownUnlockUntilUnusualUnveilUpdateUpgradeUpholdUponUpperUpsetUrbanUrgeUsageUseUsedUsefulUselessUsualUtilityVacantVacuumVagueValidValleyValveVanVanishVaporVariousVastVaultVehicleVelvetVendorVentureVenueVerbVerifyVersionVeryVesselVeteranViableVibrantViciousVictoryVideoViewVillageVintageViolinVirtualVirusVisaVisitVisualVitalVividVocalVoiceVoidVolcanoVolumeVoteVoyageWageWagonWaitWalkWallWalnutWantWarfareWarmWarriorWashWaspWasteWaterWaveWayWealthWeaponWearWeaselWeatherWebWeddingWeekendWeirdWelcomeWestWetWhaleWhatWheatWheelWhenWhereWhipWhisperWideWidthWifeWildWillWinWindowWineWingWinkWinnerWinterWireWisdomWiseWishWitnessWolfWomanWonderWoodWoolWordWorkWorldWorryWorthWrapWreckWrestleWristWriteWrongYardYearYellowYouYoungYouthZebraZeroZoneZoo"
mnemonics = re.findall('[A-Z][a-z]+', words)
z = 0
c = 0
for r in range(size):
lx = random.choice(mnemonics)
ml += f" {lx}"
return str(ml).lower()
# --------------------------------------------------------------------------------
# Convert Mnemonic to Hex (Private Key)
def Mnemonic_To_PrivateKey(MnemonicWord):
return PrivateKey_From_RootKey(Mnemonic_To_RootKey(MnemonicWord))
# --------------------------------------------------------------------------------
# Convert Mnemonic to Root (xprv) Private key Hex From Root Key : return [str]
def Mnemonic_To_RootPrivateKey(Mnemonic_Words):
""" Convert Mnemonic to Private key Hex From Root Key : return [str] """
return RootPrivateKey_From_RootKey(Mnemonic_To_RootKey(Mnemonic_Words))
# --------------------------------------------------------------------------------
# Generated root key to private key hex SHA256
def PrivateKey_From_RootKey(xprv):
deco_ = base58.b58decode_check(xprv)
pvk_b_ = deco_[46:78]
return pvk_b_.hex()
# --------------------------------------------------------------------------------
# Generated Root Key Wallet From Mnemonic's with BIP39
def Mnemonic_To_RootKey(mnemonic_words):
mnemonic_ = ''.join(c for c in mnemonic_words if c.isalnum())
mnemonic_ = mnemonic_.split(' ')
seed_ = pbkdf2.PBKDF2(' '.join(mnemonic_), 'mnemonic' + '', iterations=2048, macmodule=hmac,
digestmodule=hashlib.sha512).read(64)
xprv_ = BIP32Key.fromEntropy(seed_)
return xprv_.ExtendedKey()
# --------------------------------------------------------------------------------
# Generated Private Key From Root Key (xprv)
def RootPrivateKey_From_RootKey(xprv):
decoded = base58.b58decode_check(xprv)
return decoded.hex()
# --------------------------------------------------------------------------------
# Generated Random Binary : return [str]
def getBin(size):
""" Generated Random Binary : return [str] """
bs_ = ''
for _ in range(size):
bs_ += random.choice(['0', '1'])
return bs_
# --------------------------------------------------------------------------------
# Generated Bitcoin Address P2PKH From Private Key (HEX)
def P2PKH_From_PrivateKey(privatekey):
""" Generated Bitcoin Address P2PKH From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=BTC)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated Bitcoin Address P2SH From Private Key (HEX)
def P2SH_From_PrivateKey(privatekey):
""" Generated Bitcoin Address P2SH From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=BTC)
wallet.from_private_key(privatekey)
return wallet.p2sh_address()
# --------------------------------------------------------------------------------
# Generated Bitcoin Address P2WSH From Private Key (HEX)
def P2WSH_From_PrivateKey(privatekey):
""" Generated Bitcoin Address P2WSH From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=BTC)
wallet.from_private_key(privatekey)
return wallet.p2wsh_address()
# --------------------------------------------------------------------------------
# Generated Bitcoin Address P2WPKH From Private Key (HEX)
def P2WPKH_From_PrivateKey(privatekey):
""" Generated Bitcoin Address P2WPKH From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=BTC)
wallet.from_private_key(privatekey)
return wallet.p2wpkh_address()
# --------------------------------------------------------------------------------
# Generated Bitcoin Address P2WSH in P2sh From Private Key (HEX)
def P2WSH_in_P2SH_From_PrivateKey(privatekey):
""" Generated Bitcoin Address P2wsh in P2sh From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=BTC)
wallet.from_private_key(privatekey)
return wallet.p2wsh_in_p2sh_address()
# --------------------------------------------------------------------------------
# Generated Bitcoin Address P2wpkh in P2sh From Private Key (HEX)
def P2WPKH_in_P2SH_From_PrivateKey(privatekey):
""" Generated Bitcoin Address P2wpkh in P2sh From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=BTC)
wallet.from_private_key(privatekey)
return wallet.p2wpkh_in_p2sh_address()
# --------------------------------------------------------------------------------
# Generated and convert Ethereum Address Wallet From Private Key (HEX)
def ETH_From_PrivateKey(privatekey):
""" Generated and convert Ethereum Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=ETH)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert TRON Address Wallet From Private Key (HEX)
def TRX_From_PrivateKey(privatekey):
""" Generated and convert TRON Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=TRX)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert Dogecoin Address Wallet From Private Key (HEX)
def DOGE_From_PrivateKey(privatekey):
""" Generated and convert Dogecoin Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=DOGE)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert Dash Address Wallet From Private Key (HEX)
def DASH_From_PrivateKey(privatekey):
""" Generated and convert Dash Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=DASH)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert Bitcoin Gold Address Wallet From Private Key (HEX)
def BTG_From_PrivateKey(privatekey):
""" Generated and convert Bitcoin Gold Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=BTG)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert Litecoin Address Wallet From Private Key (HEX)
def LTC_From_PrivateKey(privatekey):
""" Generated and convert Litecoin Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=LTC)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert DigiByte Address Wallet From Private Key (HEX)
def DigiByte_From_PrivateKey(privatekey):
""" Generated and convert DigiByte Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=DGB)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert Rave Coin Address Wallet From Private Key (HEX)
def RVN_From_PrivateKey(privatekey):
""" Generated and convert Rave Coin Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=RVN)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert Via coin Address Wallet From Private Key (HEX)
def VIA_From_PrivateKey(privatekey):
""" Generated and convert Via coin Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=VIA)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert Qtum Address Wallet From Private Key (HEX)
def QTUM_From_PrivateKey(privatekey):
""" Generated and convert Qtum Address Wallet From Private Key (HEX) """
wallet: HDWallet = HDWallet(symbol=QTUM)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
# Generated and convert ZCash Address Wallet From Private Key (HEX)
def ZEC_From_PrivateKey(privatekey):
"""Generated and convert ZCash Address Wallet From Private Key (HEX)"""
wallet: HDWallet = HDWallet(symbol=ZEC)
wallet.from_private_key(privatekey)
return wallet.p2pkh_address()
# --------------------------------------------------------------------------------
def PrivateKey_To_PublicKey(privatekey):
key = ecdsa.SigningKey.from_string(codecs.decode(privatekey, 'hex'), curve=ecdsa.SECP256k1).verifying_key
key_hex = key.hex()
public_key = b'04' + key_hex
return public_key
# --------------------------------------------------------------------------------
# Convert Private Key to Dec (Number - integer)
def PrivateKey_To_Dec(private_key):
""" Convert Hex to Integer Return int [dec] """
return int(private_key, 16)
# --------------------------------------------------------------------------------
# Convert Private Key (Hex) To decimal (Number)
def HEX_To_DEC(key):
""" Convert Private Key (Hex) To Decimal (Number) return [int] """
dec_number: int = 0
for digit in key:
dec_number: int = dec_number * 16
if '0' <= digit <= '9':
dec_number += ord(digit) - ord('0')
elif 'A' <= digit <= 'F':
dec_number += ord(digit) - ord('A') + 10
elif 'a' <= digit <= 'f':
dec_number += ord(digit) - ord('a') + 10
return dec_number
# --------------------------------------------------------------------------------
# convert Binary to hex (Private key) : return [str]
def PrivateKey_From_Binary(Bin_string):
""" convert binary to private key (hex) return [str] """
return hex(int(Bin_string, 2))[2:].zfill(32)
# --------------------------------------------------------------------------------
# Convert Number (Dec) To Private Key (HEX)
def PrivateKey_From_int(int_):
""" Convert Number (Integer) To Private key (HEX) [fast method] Return str """
return "%064x" % int_
# --------------------------------------------------------------------------------
def PrivateKey_From_Passphrase(passphrase):
return str(hashlib.sha256(passphrase.encode('utf-8')).hexdigest())
# --------------------------------------------------------------------------------
# convert Private Key (hex) to Binary : return [int]
def PrivateKey_To_Binary(hexString):
""" convert Private Key (hex) to Binary : return [int] """
return bin(int(hexString, 16))[2:].zfill(256)
# --------------------------------------------------------------------------------
# Convert Private Key (HEX) To Bytes
def PrivateKey_To_Bytes(private_key):
""" Convert Hex to Bytes and Return binary [byte] """
bs_ = codecs.decode(private_key, 'hex')
return bs_
# --------------------------------------------------------------------------------
# Convert Binary 256 To HEX For Private Key : Return [str]
def Binary_To_PrivateKey(Bin_):
""" Convert Binary 256 To HEX For Private Key : Return [str] """
return hex(int(Bin_, 2))[2:].zfill(32)
# --------------------------------------------------------------------------------
# Convert Bytes (SEED) To Mnemonic
def Bytes_To_Mnemonic(Byte_String):
""" Convert Bytes to Mnemonic Word with 256 bit Size and Return str [mnemonic] """
return Mnemonic('english').to_mnemonic(Byte_String)
# --------------------------------------------------------------------------------
# Convert Bytes (Seed) To HEX (Private Key)
def Bytes_To_PrivateKey(Byte_String):
""" convert bytes to hex for private key and return str [private_key] """
return _decode(Byte_String).decode('utf-8')
# --------------------------------------------------------------------------------
# Convert Private Key (HEX) To Mnemonic
def PrivateKey_To_Mnemonic(private_key):
"""Convert HEX To Bytes , after converting , convert to Mnemonic (WORD)
PrivateKey: str --> Bytes (seed) --> Mnemonic(Word): str"""
byte_string = PrivateKey_To_Bytes(private_key)
valid_lengths = [16, 20, 24, 28, 32]
nearest_length = min(valid_lengths, key=lambda x: abs(x - len(byte_string)))
if len(byte_string) != nearest_length:
byte_string = byte_string[:nearest_length]
return Mnemonic('english').to_mnemonic(byte_string)
# --------------------------------------------------------------------------------
# Convert Byte To WIF Compressed and Un Compressed
def Bytes_To_WIF(Bytes_, compressed=False):
""" convert bytes to wif and after compressed and uncompressed address """
if compressed:
wif = bytes_to_wif(Bytes_, compressed=True)
else:
wif = bytes_to_wif(Bytes_)
return wif
# --------------------------------------------------------------------------------
# Generated Bitcoin Address From Public Key
def PublicKey_To_Addr(public_key):
PublicKeyByte = codecs.decode(public_key, 'hex')
sha256_bpk = hashlib.sha256(PublicKeyByte)
sha256_bpk_digest = sha256_bpk.digest()
ripemd160_bpk = hashlib.new('ripemd160')
ripemd160_bpk.update(sha256_bpk_digest)
ripemd160_bpk_digest = ripemd160_bpk.digest()
ripemd160_bpk_hex = codecs.encode(ripemd160_bpk_digest, 'hex')
NetByte = b'00'
NetBTCBytePubKey = NetByte + ripemd160_bpk_hex
NetBTCPubKeyByte = codecs.decode(
NetBTCBytePubKey, 'hex')
Hash256N = hashlib.sha256(NetBTCPubKeyByte)
Hash256N_digest = Hash256N.digest()
sha256_2_nbpk = hashlib.sha256(Hash256N_digest)
sha256_2_nbpk_digest = sha256_2_nbpk.digest()
sha256_2_hex = codecs.encode(sha256_2_nbpk_digest, 'hex')
checksum = sha256_2_hex[:8]
addrHex = (NetBTCBytePubKey + checksum).decode('utf-8')
return base58_(addrHex)
# --------------------------------------------------------------------------------
# compressed and un compressed address from private key hex
def Addr_From_PrivateKey(private_key, compress=False):
""" convert hex private key to compressed address and un compressed : return [str] (for compressed address
'compress=True' | for un compressed address 'compress=False')"""
seed = codecs.decode(private_key, 'hex')
if compress:
_wc = bytes_to_wif(seed, compressed=True)
bits = Key(_wc)
return bits.address
else:
_wu = bytes_to_wif(seed, compressed=False)
bitu = Key(_wu)
return bitu.address
# --------------------------------------------------------------------------------
# Check Value Bitcoin Address Balance Return Value [str: '0']
def Balance(address):
"""check balance of value per Bitcoin address and return : str [balance]"""
req = requests.get(f"https://bitcoin.atomicwallet.io/api/v2/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value Ethereum Address Balance Return [str]
def Balance_Ethereum(address):
""" Check Value Ethereum Address Balance Return [str] """
req = requests.get(f"https://ethereum.atomicwallet.io/api/v2/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value Litecoin Address Balance Return [str]
def Balance_Litecoin(address):
""" Check Value Litecoin Address Balance Return [str] """
req = requests.get(f"https://litecoin.atomicwallet.io/api/v2/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value TRON Address Balance Return [str]
def Balance_Tron(address):
""" Check Value TRON Address Balance Return [str] """
req = requests.get(f"https://apilist.tronscanapi.com/api/accountv2?address={address}&source=true").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value Dogecoin Address Balance Return [str]
def Balance_Dogecoin(address):
""" Check Value Dogecoin Address Balance Return [str] """
req = requests.get(f"https://dogecoin.atomicwallet.io/api/v2/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value Bitcoin Gold Address Balance Return [str]
def Balance_BitcoinGold(address):
""" Check Value Bitcoin Gold Address Balance Return [str] """
req = requests.get(f"https://bgold.atomicwallet.io/api/v1/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value DigiByte Address Balance Return [str]
def Balance_DigiByte(address):
""" Check Value DigiByte Address Balance Return [str] """
req = requests.get(f"https://digibyte.atomicwallet.io/api/v1/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value Ravencoin Address Balance Return [str]
def Balance_Ravencoin(address):
""" Check Value Ravencoin Address Balance Return [str] """
req = requests.get(f"https://ravencoin.atomicwallet.io/api/v1/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value Qtum Address Balance Return [str]
def Balance_Qtum(address):
""" Check Value Qtum Address Balance Return [str] """
req = requests.get(f"https://qtum.atomicwallet.io/api/v1/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value ZCASH Address Balance Return [str]
def Balance_zCash(address):
""" Check Value ZCASH Address Balance Return [str] """
req = requests.get(f"https://zcash.atomicwallet.io/api/v1/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------
# Check Value Dash Address Balance : return [str]
def Balance_Dash(address):
""" # Check Value Dash Address Balance : return [str] """
req = requests.get(f"https://dash.atomicwallet.io/api/v1/address/{address}").json()
return dict(req)['balance']
# --------------------------------------------------------------------------------