mirror of
https://github.com/fiatjaf/nak.git
synced 2024-11-25 00:59:08 -05:00
nak key public --with-parity
This commit is contained in:
parent
2988c71ccb
commit
5b04bc4859
18
key.go
18
key.go
|
@ -48,14 +48,22 @@ var public = &cli.Command{
|
|||
Description: ``,
|
||||
ArgsUsage: "[secret]",
|
||||
DisableSliceFlagSeparator: true,
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "with-parity",
|
||||
Usage: "output 33 bytes instead of 32, the first one being either '02' or '03', a prefix indicating whether this pubkey is even or odd.",
|
||||
},
|
||||
},
|
||||
Action: func(ctx context.Context, c *cli.Command) error {
|
||||
for sec := range getSecretKeysFromStdinLinesOrSlice(ctx, c, c.Args().Slice()) {
|
||||
pubkey, err := nostr.GetPublicKey(sec)
|
||||
if err != nil {
|
||||
ctx = lineProcessingError(ctx, "failed to derive public key: %s", err)
|
||||
continue
|
||||
b, _ := hex.DecodeString(sec)
|
||||
_, pk := btcec.PrivKeyFromBytes(b)
|
||||
|
||||
if c.Bool("with-parity") {
|
||||
stdout(hex.EncodeToString(pk.SerializeCompressed()))
|
||||
} else {
|
||||
stdout(hex.EncodeToString(pk.SerializeCompressed()[1:]))
|
||||
}
|
||||
stdout(pubkey)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user