NkeyOptionFromSeed will load an nkey pair from a seed file. It will return the NKey Option and will handle signing of nonce challenges from the server. It will take care to not hold keys in memory and to wipe memory.
(seedFile string)
| 6588 | // signing of nonce challenges from the server. It will take |
| 6589 | // care to not hold keys in memory and to wipe memory. |
| 6590 | func NkeyOptionFromSeed(seedFile string) (Option, error) { |
| 6591 | kp, err := nkeyPairFromSeedFile(seedFile) |
| 6592 | if err != nil { |
| 6593 | return nil, err |
| 6594 | } |
| 6595 | // Wipe our key on exit. |
| 6596 | defer kp.Wipe() |
| 6597 | |
| 6598 | pub, err := kp.PublicKey() |
| 6599 | if err != nil { |
| 6600 | return nil, err |
| 6601 | } |
| 6602 | if !nkeys.IsValidPublicUserKey(pub) { |
| 6603 | return nil, errors.New("nats: Not a valid nkey user seed") |
| 6604 | } |
| 6605 | sigCB := func(nonce []byte) ([]byte, error) { |
| 6606 | return sigHandler(nonce, seedFile) |
| 6607 | } |
| 6608 | return Nkey(string(pub), sigCB), nil |
| 6609 | } |
| 6610 | |
| 6611 | // Just wipe slice with 'x', for clearing contents of creds or nkey seed file. |
| 6612 | func wipeSlice(buf []byte) { |