Giter VIP home page Giter VIP logo

Comments (2)

core-dev-crypto avatar core-dev-crypto commented on May 23, 2024 2

Hi,

basically depends if you are using a ed25519 or bip32-ed25519 (extended key) signing method

Here the python example

#!/usr/bin/env python
# Sign a transactions

from pycardano import *

seed = bytes.fromhex("bc4070aa2ac9883c1f61a46e8f9e06bb7a432211f3689125c3d6e8c136b270e8")
print(seed.hex())
# bc4070aa2ac9883c1f61a46e8f9e06bb7a432211f3689125c3d6e8c136b270e8

tx_hash = bytes.fromhex("0f1b6d09c85eaec039f086c96c5dfc05adc4ca413e2886bd08e72a8c2cafc03f")
print(tx_hash.hex())
# 0f1b6d09c85eaec039f086c96c5dfc05adc4ca413e2886bd08e72a8c2cafc03f

psk = SigningKey(seed)
sgn = psk.sign(tx_hash)
print(sgn.hex())
# 465727709060d0081e625127007f727165962fde69fc091a1ba8a94c1ac3fc42c9a225f31a3108ad593492d0fbfbc8e036b53f5ed6aef04c1a7388b06de70304

seed = bytes.fromhex("bc4070aa2ac9883c1f61a46e8f9e06bb7a432211f3689125c3d6e8c136b270e80000000000000000000000000000000000000000000000000000000000000000")
epsk = ExtendedSigningKey(seed)
esgn = epsk.sign(tx_hash)
print(esgn.hex())
# 0eb1d55aca6d9d144f623943bc0928749110f99430cb9360e103a089b24be976c409c957c79bdfcde24fae1aea0f8b1454791db42918ea86bd1da61f2f14f00b


and the go example

import (
	"encoding/hex"
	"fmt"

	"github.com/echovl/cardano-go/crypto"
	"github.com/echovl/ed25519"
)

func main() {

	seed, _ := hex.DecodeString("bc4070aa2ac9883c1f61a46e8f9e06bb7a432211f3689125c3d6e8c136b270e8")
	fmt.Println(hex.EncodeToString(seed))
	// bc4070aa2ac9883c1f61a46e8f9e06bb7a432211f3689125c3d6e8c136b270e8

	tx_hash, _ := hex.DecodeString("0f1b6d09c85eaec039f086c96c5dfc05adc4ca413e2886bd08e72a8c2cafc03f")
	fmt.Println(hex.EncodeToString(tx_hash))
	// 0f1b6d09c85eaec039f086c96c5dfc05adc4ca413e2886bd08e72a8c2cafc03f

	key := ed25519.NewKeyFromSeed(seed)
	sgn := ed25519.Sign(key, tx_hash)
	fmt.Println(hex.EncodeToString(sgn))
	// 465727709060D0081E625127007F727165962FDE69FC091A1BA8A94C1AC3FC42C9A225F31A3108AD593492D0FBFBC8E036B53F5ED6AEF04C1A7388B06DE70304

	seed, _ = hex.DecodeString("bc4070aa2ac9883c1f61a46e8f9e06bb7a432211f3689125c3d6e8c136b270e80000000000000000000000000000000000000000000000000000000000000000")
	var psk crypto.PrvKey = seed
	fmt.Println(hex.EncodeToString(psk))
	// bc4070aa2ac9883c1f61a46e8f9e06bb7a432211f3689125c3d6e8c136b270e80000000000000000000000000000000000000000000000000000000000000000

	sign := psk.Sign(tx_hash)
	fmt.Println(hex.EncodeToString(sign))
	// 0eb1d55aca6d9d144f623943bc0928749110f99430cb9360e103a089b24be976a752589f37d6c917b4e4337ede3ab338319203215960854d1a1257c3caa67d0e

}

from cardano-go.

core-dev-crypto avatar core-dev-crypto commented on May 23, 2024

@echovl
Colud you close this issue?

from cardano-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.