MCPcopy
hub / github.com/nats-io/nats.go / NkeyOptionFromSeed

Function NkeyOptionFromSeed

nats.go:6590–6609  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

6588// signing of nonce challenges from the server. It will take
6589// care to not hold keys in memory and to wipe memory.
6590func 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.
6612func wipeSlice(buf []byte) {

Callers 1

TestNKeyOptionFromSeedFunction · 0.85

Calls 3

nkeyPairFromSeedFileFunction · 0.85
sigHandlerFunction · 0.85
NkeyFunction · 0.85

Tested by 1

TestNKeyOptionFromSeedFunction · 0.68