Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

padded 32 byte private key #48

Merged
merged 1 commit into from
Oct 12, 2023
Merged

padded 32 byte private key #48

merged 1 commit into from
Oct 12, 2023

Conversation

kant777
Copy link
Contributor

@kant777 kant777 commented Oct 12, 2023

No description provided.

@kant777
Copy link
Contributor Author

kant777 commented Oct 12, 2023

I am able to verify the public key associated with padded private key bytes as well as the original private key bytes(that has not padding) and the public key for both remains the same. More tests would be great @iowar

@kant777
Copy link
Contributor Author

kant777 commented Oct 12, 2023

just to demonstrate this idea run the following code

package main

import (
	"fmt"
	"math/big"
)

func main() {
	val1 := new(big.Int).SetInt64(256)
	val2 := new(big.Int).SetInt64(16)

	fmt.Printf("256 -> %v\n", val1.Bytes()) // [1 0]
	fmt.Printf("16  -> %v\n", val2.Bytes()) // [16]
}

256 in binary is 100000000 (9 bits), which requires two bytes to represent: 00000001 00000000 or [1 0] in a byte slice.
16 in binary is 10000 (5 bits), which fits into a single byte: 00010000 or [16] in a byte slice.

The PrivKey.D is *big.Int and .Bytes() method returns just the necessary bytes to represent the number, without any leading zeros

@iowar
Copy link
Collaborator

iowar commented Oct 12, 2023

It has been tested, and the signed messages were successfully verified; no issue appears

@kant777 kant777 merged commit 9893388 into main Oct 12, 2023
1 check passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants