Skip to content
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

How to bitcoin bip 340 Schnorr Signatures for secp256k1? #43

Open
Gzushgshsh opened this issue Oct 13, 2024 · 1 comment
Open

How to bitcoin bip 340 Schnorr Signatures for secp256k1? #43

Gzushgshsh opened this issue Oct 13, 2024 · 1 comment
Assignees

Comments

@Gzushgshsh
Copy link

Gzushgshsh commented Oct 13, 2024

https://bips.xyz/340 link to definition of nip (I only read part of it)

I'm a complete beginner at this, and I'm trying to verify a signature, after looking at the examples I wrote this, but it doesn't seem to work

var
  curve: IX9ECParameters;
  domain: TECDomainParameters;
  xcoord: String;
  bytesPK, sigBytes, msgBytes: TCryptoLibByteArray;
  publicKey: TECPublicKeyParameters;
  signer: ISigner;
begin
  curve := TCustomNamedCurves.GetByName('secp256k1');
  domain := TECDomainParameters.Create(curve.Curve, curve.G, curve.N,
    curve.H, curve.GetSeed);

  xcoord:= '6e468422dfb74a5738702a8823b9b28168abab8655faacb6853cd0ee15deee93';
  bytesPK:= TConverters.ConvertHexStringToBytes('02' + xcoord);

  publicKey:= TECPublicKeyParameters.Create('ECSCHNORR',
    curve.Curve.DecodePoint(bytesPK), domain);

  msgBytes:= TConverters.ConvertHexStringToBytes
    ('4376c65d2f232afbe9b882a35baa4f6fe8667c4e684749af565f981833ed6a65');
  sigBytes:= TConverters.ConvertHexStringToBytes
    ('908a15e46fb4d8675bab026fc230a0e3542bfade63da02d542fb78b2a8513fcd0092619a2c8c1221e581946e0191f2af505dfdf8657a414dbca329186f009262');

  signer:= TSignerUtilities.GetSigner('SHA-256withECSCHNORRSIPA');
  signer.Init(False, publicKey);
  signer.BlockUpdate(msgBytes, 0, system.Length(msgBytes));

  WriteLn(signer.VerifySignature(sigBytes));
end;

Signature, message and xcoord of pubkey is from an example from Nostr protocol
https://nostr.com/the-protocol/events
https://github.com/nostr-protocol/nips/blob/master/01.md

@Xor-el
Copy link
Owner

Xor-el commented Oct 21, 2024

Hi @Gzushgshsh apologies for the late response.
unfortunately, BIP340 has undergone various iterations since I implemented my code from the reference implementation meaning that I have to study the original implementation, see what changed and backport the chnages to my implementation.
as you may know, this would take a lot of time which I have limited amount of these days.
however, I will be keeping this issue open to help me remember to do this.

@Xor-el Xor-el self-assigned this Oct 21, 2024
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