mirror of
https://github.com/sonr-io/sonr.git
synced 2026-08-04 10:21:40 +00:00
refactor: move gateway and vault components to new locations
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package context
|
||||
|
||||
import (
|
||||
"github.com/onsonr/sonr/internal/crypto/mpc"
|
||||
"github.com/onsonr/sonr/internal/common"
|
||||
"lukechampine.com/blake3"
|
||||
)
|
||||
|
||||
func (cc *GatewayContext) Spawn(handle, origin string) (*CreatePasskeyParams, error) {
|
||||
challenge := GetAuthChallenge(cc)
|
||||
sid := GetSessionID(cc)
|
||||
nonce, err := calcNonce(sid)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
encl, err := mpc.GenEnclave(nonce)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cc.stagedEnclaves[sid] = encl
|
||||
common.WriteCookie(cc, common.SonrAddress, encl.Address())
|
||||
return &CreatePasskeyParams{
|
||||
Address: encl.Address(),
|
||||
Handle: handle,
|
||||
Name: origin,
|
||||
Challenge: challenge,
|
||||
CreationBlock: cc.StatusBlock(),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Uses blake3 to hash the sessionID to generate a nonce of length 12 bytes
|
||||
func calcNonce(sessionID string) ([]byte, error) {
|
||||
hash := blake3.New(32, nil)
|
||||
_, err := hash.Write([]byte(sessionID))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Read the hash into a byte slice
|
||||
nonce := make([]byte, 12)
|
||||
_, err = hash.Write(nonce)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nonce, nil
|
||||
}
|
||||
Reference in New Issue
Block a user