Skip to content

Error: The seed must be exactly 32 bytes long #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
reitcircles opened this issue Feb 9, 2023 · 5 comments
Closed

Error: The seed must be exactly 32 bytes long #159

reitcircles opened this issue Feb 9, 2023 · 5 comments

Comments

@reitcircles
Copy link

reitcircles commented Feb 9, 2023

Describe the bug
From a mnemonic (32 words length) i have derived a set of payment.vkey/skey and stake.skey/vkey. Using these keys i am trying to now sign the tx. in pycardano using interface:builder.build_and_sign.

(same transaction works for cardano-cli to be clear.So there is some limitation to this library for being used for transaction)

To Reproduce

Logs
The seed must be exactly 32 bytes long

Expected behavior

  • should have signed using the keys.
  • I have used the same set of keys in cardano-cli, so they are correct.

Environment and software version (please complete the following information):

  • OS: [ubuntu latest]
  • PyCardano Version latest

Additional context
Add any other context about the problem here.

@cffls
Copy link
Collaborator

cffls commented Feb 10, 2023

Hello, could you please provide a sample of your code, e.g. how you import the keys and how you use them. It is difficult to guess what the problem is without those information. Thanks!

@reitcircles
Copy link
Author

reitcircles commented Feb 10, 2023

import os
from pycardano import (
PaymentSigningKey,
PaymentExtendedSigningKey,
PaymentVerificationKey,
StakeVerificationKey,
StakeExtendedSigningKey,
Transaction,
TransactionBody,
TransactionInput,
TransactionOutput,
TransactionWitnessSet,
VerificationKeyWitness,
TransactionBuilder,
StakeSigningKey,
BlockFrostChainContext,
Value,
Network,
Address
)

from decouple import config
from blockfrost import ApiUrls

PLATFORM_KEYS = {

"skey":{
    "stake":"../../tlib/KYS/stake.skey",
    "payment":"../../tlib/KYS/payment.skey"
},
"vkey":{
    "stake":"../../tlib/KYS/stake.vkey",
    "payment":"../../tlib/KYS/payment.vkey"
}

}

NETWORK = Network.TESTNET

class Payback:
"""
contains the functions to payback the money he sent in case of errors.
The money in ADA lies in the platform wallet. Amount should be in lovelace
"""
def init(self, amount, clientAddress):
try:
self.amount = amount
self.caddress = clientAddress
self.context = BlockFrostChainContext(config('BLOCKFROST_PROJECT_ID'), base_url=ApiUrls.preview.value)

        """                                                                                                                                                                
        getting value from the .env valueable                                                                                                                              
        """
        self.psk = PaymentExtendedSigningKey.load(PLATFORM_KEYS['skey']['payment'])
        self.ssk = StakeExtendedSigningKey.load(PLATFORM_KEYS['skey']['stake'])

        pvk = PaymentVerificationKey.from_signing_key(self.psk)  #PaymentVerificationKey.load(PLATFORM_KEYS['vkey']['payment'])                                            
        svk = StakeVerificationKey.from_signing_key(self.ssk) #load(PLATFORM_KEYS['vkey']['stake'])                                                                        

        self.address = Address(pvk.hash(),svk.hash(), NETWORK)
        print(self.address)

        self.builder = TransactionBuilder(self.context)
    except Exception as inst:
        print(inst)

def construct_tx(self):

    try:
        self.builder.add_input_address(self.address)
        utxos = self.context.utxos(str(address))

        #builder.add_input(utxos[0]) For example                                                                                                                           
        self.builder.add_output(
            TransactionOutput(
                Address.from_primitive(self.caddress),
                Value.from_primitive(
                    [
                        self.amount,
                    ]
                ),
            )
        )
    except Exception as inst:
        print('error in constructing transaction')
        print(inst)

def signTx(self):
    try:
        signed_tx = self.builder.build_and_sign([self.psk], change_address=self.address)
        return signed_tx
    except Exception as inst:
       print(inst)

def submit(self, signed_tx):
    self.context.submit_tx(signed_tx.to_cbor())

@cffls
Copy link
Collaborator

cffls commented Feb 10, 2023

Can you check if your payment signing key is an extended key? It will have something like "PaymentExtendedSigningKeyShelley_ed25519_bip32" in your key file. If so, you will need to load your keys with PaymentExtendedSigningKey and StakeExtendedSigningKey.

@reitcircles
Copy link
Author

reitcircles commented Feb 10, 2023

Yes ...they are extended keys ... let me try. Resolved. I will update the script above to have the correct code ...cheers.

@cffls
Copy link
Collaborator

cffls commented Feb 13, 2023

Closing this issue as the root cause has been found. Feel free to reopen if the issue is still not resolved.

@cffls cffls closed this as completed Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants