func fetchKeyPairs(ctx context.Context, client *registry.Client,
	orgID *identity.ID) (*identity.ID, *identity.ID, *crypto.KeyPairs, error) {

	keyPairs, err := client.KeyPairs.List(ctx, orgID)
	if err != nil {
		return nil, nil, nil, err
	}

	var sigClaimed registry.ClaimedKeyPair
	var encClaimed registry.ClaimedKeyPair
	for _, keyPair := range keyPairs {
		pubKey := keyPair.PublicKey.Body.(*primitive.PublicKey)
		switch pubKey.KeyType {
		case signingKeyType:
			sigClaimed = keyPair
		case encryptionKeyType:
			encClaimed = keyPair
		default:
			return nil, nil, nil, &apitypes.Error{
				Type: apitypes.InternalServerError,
				Err:  []string{fmt.Sprintf("Unknown key type: %s", pubKey.KeyType)},
			}
		}
	}

	if sigClaimed.PublicKey == nil || encClaimed.PublicKey == nil {
		return nil, nil, nil, &apitypes.Error{
			Type: apitypes.NotFoundError,
			Err:  []string{"Missing encryption or signing keypairs"},
		}
	}

	sigPub := sigClaimed.PublicKey.Body.(*primitive.PublicKey).Key.Value
	sigKP := crypto.SignatureKeyPair{
		Public:  ed25519.PublicKey(*sigPub),
		Private: *sigClaimed.PrivateKey.Body.(*primitive.PrivateKey).Key.Value,
		PNonce:  *sigClaimed.PrivateKey.Body.(*primitive.PrivateKey).PNonce,
	}

	encPub := *encClaimed.PublicKey.Body.(*primitive.PublicKey).Key.Value
	encPubB := [32]byte{}
	copy(encPubB[:], encPub)
	encKP := crypto.EncryptionKeyPair{
		Public:  encPubB,
		Private: *encClaimed.PrivateKey.Body.(*primitive.PrivateKey).Key.Value,
		PNonce:  *encClaimed.PrivateKey.Body.(*primitive.PrivateKey).PNonce,
	}

	kp := crypto.KeyPairs{
		Signature:  sigKP,
		Encryption: encKP,
	}

	return sigClaimed.PublicKey.ID, encClaimed.PublicKey.ID, &kp, nil
}
// fetchKeyPairs fetches the user's signing and encryption keypairs from the
// registry for the given org id.
fetchKeyPairs fetches the user's signing and encryption keypairs from the
registry for the given org id.
// fetchKeyPairs fetches the user ' s signing and encryption keypairs from the // registry for the given org id .
func fetchKeyPairs(ctx context.Context, client *registry.Client,
	orgID *identity.ID) (*identity.ID, *identity.ID, *crypto.KeyPairs, error) {
	keyPairs, err := client.KeyPairs.List(ctx, orgID)
	if err != nil {
		return nil, nil, nil, err
	}
	var sigClaimed registry.ClaimedKeyPair
	var encClaimed registry.ClaimedKeyPair
	for _, keyPair := range keyPairs {
		pubKey := keyPair.PublicKey.Body.(*primitive.PublicKey)
		switch pubKey.KeyType {
		case signingKeyType:
			sigClaimed = keyPair
		case encryptionKeyType:
			encClaimed = keyPair
		default:
			return nil, nil, nil, &apitypes.Error{
				Type: apitypes.InternalServerError,
				Err:  []string{fmt.Sprintf("Unknown key type: %s", pubKey.KeyType)},
			}
		}
	}
	if sigClaimed.PublicKey == nil || encClaimed.PublicKey == nil {
		return nil, nil, nil, &apitypes.Error{
			Type: apitypes.NotFoundError,
			Err:  []string{"Missing encryption or signing keypairs"},
		}
	}
	sigPub := sigClaimed.PublicKey.Body.(*primitive.PublicKey).Key.Value
	sigKP := crypto.SignatureKeyPair{
		Public:  ed25519.PublicKey(*sigPub),
		Private: *sigClaimed.PrivateKey.Body.(*primitive.PrivateKey).Key.Value,
		PNonce:  *sigClaimed.PrivateKey.Body.(*primitive.PrivateKey).PNonce,
	}
	encPub := *encClaimed.PublicKey.Body.(*primitive.PublicKey).Key.Value
	encPubB := [32]byte{}
	copy(encPubB[:], encPub)
	encKP := crypto.EncryptionKeyPair{
		Public:  encPubB,
		Private: *encClaimed.PrivateKey.Body.(*primitive.PrivateKey).Key.Value,
		PNonce:  *encClaimed.PrivateKey.Body.(*primitive.PrivateKey).PNonce,
	}
	kp := crypto.KeyPairs{
		Signature:  sigKP,
		Encryption: encKP,
	}
	return sigClaimed.PublicKey.ID, encClaimed.PublicKey.ID, &kp, nil
}
func fetchKeyPairs ( ctx context . Context , client * registry . Client , orgID * identity . ID ) ( * identity . ID , * identity . ID , * crypto . KeyPairs , error ) { keyPairs , err := client . KeyPairs . List ( ctx , orgID ) if err != nil { return nil , nil , nil , err } var sigClaimed registry . ClaimedKeyPair var encClaimed registry . ClaimedKeyPair for _ , keyPair := range keyPairs { pubKey := keyPair . PublicKey . Body . ( * primitive . PublicKey ) switch pubKey . KeyType { case signingKeyType : sigClaimed = keyPair case encryptionKeyType : encClaimed = keyPair default : return nil , nil , nil , & apitypes . Error { Type : apitypes . InternalServerError , Err : [ ] string { fmt . Sprintf ( " " , pubKey . KeyType ) } , } } } if sigClaimed . PublicKey == nil || encClaimed . PublicKey == nil { return nil , nil , nil , & apitypes . Error { Type : apitypes . NotFoundError , Err : [ ] string { " " } , } } sigPub := sigClaimed . PublicKey . Body . ( * primitive . PublicKey ) . Key . Value sigKP := crypto . SignatureKeyPair { Public : ed25519 . PublicKey ( * sigPub ) , Private : * sigClaimed . PrivateKey . Body . ( * primitive . PrivateKey ) . Key . Value , PNonce : * sigClaimed . PrivateKey . Body . ( * primitive . PrivateKey ) . PNonce , } encPub := * encClaimed . PublicKey . Body . ( * primitive . PublicKey ) . Key . Value encPubB := [ 32 ] byte { } copy ( encPubB [ : ] , encPub ) encKP := crypto . EncryptionKeyPair { Public : encPubB , Private : * encClaimed . PrivateKey . Body . ( * primitive . PrivateKey ) . Key . Value , PNonce : * encClaimed . PrivateKey . Body . ( * primitive . PrivateKey ) . PNonce , } kp := crypto . KeyPairs { Signature : sigKP , Encryption : encKP , } return sigClaimed . PublicKey . ID , encClaimed . PublicKey . ID , & kp , nil }
fetchKeyPairs fetches the user's signing and encryption keypairs from the
registry for the given org id.
fetchKeyPairs fetches the user ' s signing and encryption keypairs from the registry for the given org id .