Bitcoin Forum
April 28, 2024, 04:06:07 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: iceland secp256k1 import in python  (Read 242 times)
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
January 05, 2023, 01:45:07 PM
 #1

i downloaded
https://github.com/iceland2k14/secp256k1

into directory /home/yin4/secp256k1

Code:
yin4@qq:~ ls secp256k1
CHANGELOG.md  ice_secp256k1.dll  ice_secp256k1.so  LICENSE  __pycache__  README.md  secp256k1.py

when i am inside this directory it works good and i can import with command
Code:
yin4@qq:~/secp256k1$ python3

>>> import secp256k1 as ice

>>> ice.somecommand

but i want to have this working also if i start python3 console from /other/directory

i created sys environment variable
Code:
yin4@qq:/other/directory$ export PYTHONPATH=/home/yin4/secp256k1

Code:
yin4@qq:/other/directory$ python3

>>> import secp256k1 as ice

>>> ice.
then I press tab but no commands available only these:
Code:
>>> ice.__
ice.__annotations__     ice.__format__(         ice.__loader__          ice.__reduce_ex__(
ice.__class__(          ice.__ge__(             ice.__lt__(             ice.__repr__()
ice.__delattr__(        ice.__getattribute__(   ice.__name__            ice.__setattr__(
ice.__dict__            ice.__gt__(             ice.__ne__(             ice.__sizeof__()
ice.__dir__(            ice.__hash__()          ice.__new__(            ice.__spec__
ice.__doc__             ice.__init__(           ice.__package__         ice.__str__()
ice.__eq__(             ice.__init_subclass__(  ice.__path__            ice.__subclasshook__(
ice.__file__            ice.__le__(             ice.__reduce__()       

then i try

Code:
>>> from secp256k1 import secp256k1 as ice
File ice_secp256k1.so not found
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/yin4/secp256k1/secp256k1.py", line 92, in <module>
    ice.scalar_multiplication.argtypes = [ctypes.c_char_p, ctypes.c_char_p]   # pvk,ret
NameError: name 'ice' is not defined

what is wrong how can i fix and use library from all directorys?
1714277167
Hero Member
*
Offline Offline

Posts: 1714277167

View Profile Personal Message (Offline)

Ignore
1714277167
Reply with quote  #2

1714277167
Report to moderator
1714277167
Hero Member
*
Offline Offline

Posts: 1714277167

View Profile Personal Message (Offline)

Ignore
1714277167
Reply with quote  #2

1714277167
Report to moderator
The forum was founded in 2009 by Satoshi and Sirius. It replaced a SourceForge forum.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714277167
Hero Member
*
Offline Offline

Posts: 1714277167

View Profile Personal Message (Offline)

Ignore
1714277167
Reply with quote  #2

1714277167
Report to moderator
citb0in
Hero Member
*****
Offline Offline

Activity: 658
Merit: 656


Bitcoin g33k


View Profile
January 05, 2023, 01:57:54 PM
Merited by ABCbits (1)
 #2

I am not a Python expert, but as far as I understand it correctly, it is because the library is not found. Look at line 27 of secp256k1.py there you can see how iceland tries to load the needed ice_secp256k1.so file. You could try to put the absolute path there, e.g. like this:
Code:
    #dllfile = 'ice_secp256k1.so'
    dllfile = '/home/yin4/secp256k1/ice_secp256k1.so'

this should work but I bet there is a more convenient and best-practice way to achieve this. You will certainly get some better ideas on this from other users...

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
January 05, 2023, 03:45:22 PM
 #3

fantastic now works
thanks.

is there more elegant way to solve this?
NotATether
Legendary
*
Offline Offline

Activity: 1582
Merit: 6695


bitcoincleanup.com / bitmixlist.org


View Profile WWW
January 05, 2023, 06:13:16 PM
 #4

fantastic now works
thanks.

is there more elegant way to solve this?

Python has a "get home folder" and "get current directory" functions in tho os module, you can look into those. Especially if you never change directories and just want your CWD to be the same folder your binary (and libs) are located at.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
citb0in
Hero Member
*****
Offline Offline

Activity: 658
Merit: 656


Bitcoin g33k


View Profile
January 06, 2023, 01:10:19 PM
Last edit: January 06, 2023, 02:03:42 PM by citb0in
Merited by NotATether (5), ABCbits (3)
 #5

fantastic now works
thanks.

is there more elegant way to solve this?

yes there is. I have written a patch that allows you to import iceland's secp256k1 module from any folder
==> PATCH <==



You can get the patch or clone the patched version from my git repository.

Without the patch, it would be necessary to change to the directory where iceland's secp256k1 files are located. Then you would run Python console with "python" or "python3" and import the module with:
Code:
import secp256k1 as ice
this only works because in the current working directory the file "secp256k1.py" exists and also the required shared library "ice_secp256k1.so" is located there. If you would try to start the Python console from another directory and load the module, it would fail with an error as you already noticed.

With the patch you can do it from any working directory, it doesn't matter then which is your working directory. The module will always find its required shared library "ice_secp256k1.so".

Additional note:

Since many users use both the standard Python module secp256k1 as well as iceland2k14/secp256k1 I would personally recommend renaming iceland's module to e.g. ice_secp256k1. Because the two modules are different. This will prevent you from shadowing the other module when importing one of the two modules.

I myself have placed all 3rd party python modules in ~/foo/python/modules
Iceland's secp256k1 module is located in ~/foo/python/modules/ice_secp256k1

To allow Python to search for modules in ~/foo/python/modules you can use the PYTHONPATH environment variable:
Code:
export PYTHONPATH=$PYTHONPATH:/home/citb0in/foo/python/modules
As you do not want to do this on each system start or terminal start it is suggested to add the export command mentioned above in your ~/.bashrc so it is executed each time you login or start a new terminal. You can ensure that everything is correct by
Code:
echo $PYTHONPATH

Whenever I need iceland's secp256k1 module, I import it like that:
Code:
python3
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> from ice_secp256k1 import secp256k1 as ice
>>> ice.privatekey_to_address(0, True, 123)
'141fTonryMQxmkKcba9FstmyQv3tqdBzTY'
>>>

Whenever I need Python's standard module "secp256k1" I just ue
Code:
import secp256k1

This way you can clearly distinguish between the two modules with the same name and you do not run the risk of confusion and problems.


.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
COBRAS
Member
**
Offline Offline

Activity: 844
Merit: 20

$$P2P BTC BRUTE.JOIN NOW ! https://uclck.me/SQPJk


View Profile
January 06, 2023, 05:25:13 PM
 #6

 :-XHow to use this lib for scalar to scalar/number's multiplication , addition, substraction ?

what function of modular inversion ?

Br

$$$ P2P NETWORK FOR BTC WALLET.DAT BRUTE F ORCE .JOIN NOW=GET MANY COINS NOW !!!
https://github.com/phrutis/LostWallet  https://t.me/+2niP9bQ8uu43MDg6
citb0in
Hero Member
*****
Offline Offline

Activity: 658
Merit: 656


Bitcoin g33k


View Profile
January 06, 2023, 05:27:09 PM
 #7

RTFM and see what functions are available and how they are used?

https://github.com/iceland2k14/secp256k1/blob/main/README.md

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
COBRAS
Member
**
Offline Offline

Activity: 844
Merit: 20

$$P2P BTC BRUTE.JOIN NOW ! https://uclck.me/SQPJk


View Profile
January 06, 2023, 05:41:26 PM
 #8

RTFM and see what functions are available and how they are used?

https://github.com/iceland2k14/secp256k1/blob/main/README.md

Can't find function for scalar. Only mul pub to priv, no function priv * priv for ex.

$$$ P2P NETWORK FOR BTC WALLET.DAT BRUTE F ORCE .JOIN NOW=GET MANY COINS NOW !!!
https://github.com/phrutis/LostWallet  https://t.me/+2niP9bQ8uu43MDg6
citb0in
Hero Member
*****
Offline Offline

Activity: 658
Merit: 656


Bitcoin g33k


View Profile
January 06, 2023, 05:51:59 PM
 #9

RTFM and see what functions are available and how they are used?

https://github.com/iceland2k14/secp256k1/blob/main/README.md

Can't find function for scalar. Only mul pub to priv, no function priv * priv for ex.

https://github.com/iceland2k14/secp256k1/blob/main/secp256k1.py

you can only use what's available or develop and extend the program and contribute to the project

.
.HUGE.
▄██████████▄▄
▄█████████████████▄
▄█████████████████████▄
▄███████████████████████▄
▄█████████████████████████▄
███████▌██▌▐██▐██▐████▄███
████▐██▐████▌██▌██▌██▌██
█████▀███▀███▀▐██▐██▐█████

▀█████████████████████████▀

▀███████████████████████▀

▀█████████████████████▀

▀█████████████████▀

▀██████████▀▀
█▀▀▀▀











█▄▄▄▄
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
.
CASINSPORTSBOOK
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀▀█











▄▄▄▄█
yoshimitsu777 (OP)
Newbie
*
Offline Offline

Activity: 72
Merit: 0


View Profile
January 07, 2023, 12:17:01 PM
 #10

ecdsa123 is not human but ai bot and posting into forum with crazy things not fitting to topic or without questions.
this bot tries to reply in context but often fails see here

https://bitcointalk.org/index.php?topic=5433136.msg61556811#msg61556811
https://bitcointalk.org/index.php?topic=5433027.msg61544585#msg61544585
https://bitcointalk.org/index.php?topic=5432839.msg61542178#msg61542178

ecdsa123 is same bot as Nt013 and some other names in forum

Quote from: citb0in
yes there is. I have written a patch that allows you to import iceland's secp256k1 module from any folder
==> PATCH (https://github.com/iceland2k14/secp256k1/pull/39/commits/f2b3aefd54b5bcd9d09d2a1e01630ac3bd30d2a0) <==

You can get the patch or clone the patched version from my git repository (https://github.com/citb0in/ice_secp256k1).
perfect
thanks a lot
ecdsa123
Full Member
***
Offline Offline

Activity: 211
Merit: 105

Dr WHO on disney+


View Profile
January 07, 2023, 12:19:30 PM
 #11

I'm not bot. I'm real user:)

Yes, i should open new Topic.

first time someone has called me bot.Smiley

 

Donate: bc1q0sezldfgm7rf2r78p5scasrrcfkpzxnrfcvdc6

Subscribe : http://www.youtube.com/@Ecdsa_Solutions
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!