github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/protocol/keybase1/crypto.go (about)

     1  // Auto-generated to Go types and interfaces using avdl-compiler v1.4.10 (https://github.com/keybase/node-avdl-compiler)
     2  //   Input file: avdl/keybase1/crypto.avdl
     3  
     4  package keybase1
     5  
     6  import (
     7  	"github.com/keybase/go-framed-msgpack-rpc/rpc"
     8  	context "golang.org/x/net/context"
     9  	"time"
    10  )
    11  
    12  type ED25519PublicKey [32]byte
    13  
    14  func (o ED25519PublicKey) DeepCopy() ED25519PublicKey {
    15  	var ret ED25519PublicKey
    16  	copy(ret[:], o[:])
    17  	return ret
    18  }
    19  
    20  type ED25519Signature [64]byte
    21  
    22  func (o ED25519Signature) DeepCopy() ED25519Signature {
    23  	var ret ED25519Signature
    24  	copy(ret[:], o[:])
    25  	return ret
    26  }
    27  
    28  type ED25519SignatureInfo struct {
    29  	Sig       ED25519Signature `codec:"sig" json:"sig"`
    30  	PublicKey ED25519PublicKey `codec:"publicKey" json:"publicKey"`
    31  }
    32  
    33  func (o ED25519SignatureInfo) DeepCopy() ED25519SignatureInfo {
    34  	return ED25519SignatureInfo{
    35  		Sig:       o.Sig.DeepCopy(),
    36  		PublicKey: o.PublicKey.DeepCopy(),
    37  	}
    38  }
    39  
    40  type EncryptedBytes32 [48]byte
    41  
    42  func (o EncryptedBytes32) DeepCopy() EncryptedBytes32 {
    43  	var ret EncryptedBytes32
    44  	copy(ret[:], o[:])
    45  	return ret
    46  }
    47  
    48  type BoxNonce [24]byte
    49  
    50  func (o BoxNonce) DeepCopy() BoxNonce {
    51  	var ret BoxNonce
    52  	copy(ret[:], o[:])
    53  	return ret
    54  }
    55  
    56  type BoxPublicKey [32]byte
    57  
    58  func (o BoxPublicKey) DeepCopy() BoxPublicKey {
    59  	var ret BoxPublicKey
    60  	copy(ret[:], o[:])
    61  	return ret
    62  }
    63  
    64  type CiphertextBundle struct {
    65  	Kid        KID              `codec:"kid" json:"kid"`
    66  	Ciphertext EncryptedBytes32 `codec:"ciphertext" json:"ciphertext"`
    67  	Nonce      BoxNonce         `codec:"nonce" json:"nonce"`
    68  	PublicKey  BoxPublicKey     `codec:"publicKey" json:"publicKey"`
    69  }
    70  
    71  func (o CiphertextBundle) DeepCopy() CiphertextBundle {
    72  	return CiphertextBundle{
    73  		Kid:        o.Kid.DeepCopy(),
    74  		Ciphertext: o.Ciphertext.DeepCopy(),
    75  		Nonce:      o.Nonce.DeepCopy(),
    76  		PublicKey:  o.PublicKey.DeepCopy(),
    77  	}
    78  }
    79  
    80  type UnboxAnyRes struct {
    81  	Kid       KID     `codec:"kid" json:"kid"`
    82  	Plaintext Bytes32 `codec:"plaintext" json:"plaintext"`
    83  	Index     int     `codec:"index" json:"index"`
    84  }
    85  
    86  func (o UnboxAnyRes) DeepCopy() UnboxAnyRes {
    87  	return UnboxAnyRes{
    88  		Kid:       o.Kid.DeepCopy(),
    89  		Plaintext: o.Plaintext.DeepCopy(),
    90  		Index:     o.Index,
    91  	}
    92  }
    93  
    94  type SignED25519Arg struct {
    95  	SessionID int    `codec:"sessionID" json:"sessionID"`
    96  	Msg       []byte `codec:"msg" json:"msg"`
    97  	Reason    string `codec:"reason" json:"reason"`
    98  }
    99  
   100  type SignED25519ForKBFSArg struct {
   101  	SessionID int    `codec:"sessionID" json:"sessionID"`
   102  	Msg       []byte `codec:"msg" json:"msg"`
   103  	Reason    string `codec:"reason" json:"reason"`
   104  }
   105  
   106  type SignToStringArg struct {
   107  	SessionID int    `codec:"sessionID" json:"sessionID"`
   108  	Msg       []byte `codec:"msg" json:"msg"`
   109  	Reason    string `codec:"reason" json:"reason"`
   110  }
   111  
   112  type UnboxBytes32Arg struct {
   113  	SessionID        int              `codec:"sessionID" json:"sessionID"`
   114  	EncryptedBytes32 EncryptedBytes32 `codec:"encryptedBytes32" json:"encryptedBytes32"`
   115  	Nonce            BoxNonce         `codec:"nonce" json:"nonce"`
   116  	PeersPublicKey   BoxPublicKey     `codec:"peersPublicKey" json:"peersPublicKey"`
   117  	Reason           string           `codec:"reason" json:"reason"`
   118  }
   119  
   120  type UnboxBytes32AnyArg struct {
   121  	SessionID   int                `codec:"sessionID" json:"sessionID"`
   122  	Bundles     []CiphertextBundle `codec:"bundles" json:"bundles"`
   123  	Reason      string             `codec:"reason" json:"reason"`
   124  	PromptPaper bool               `codec:"promptPaper" json:"promptPaper"`
   125  }
   126  
   127  type CryptoInterface interface {
   128  	// Sign the given message (which should be small) using the device's private
   129  	// signing ED25519 key, and return the signature as well as the corresponding
   130  	// public key that can be used to verify the signature. The 'reason' parameter
   131  	// is used as part of the SecretEntryArg object passed into
   132  	// secretUi.getSecret().
   133  	SignED25519(context.Context, SignED25519Arg) (ED25519SignatureInfo, error)
   134  	// Same as the above except a KBFS-specific prefix is added to the payload to be signed.
   135  	SignED25519ForKBFS(context.Context, SignED25519ForKBFSArg) (ED25519SignatureInfo, error)
   136  	// Same as the above except the full marshaled and encoded NaclSigInfo.
   137  	SignToString(context.Context, SignToStringArg) (string, error)
   138  	// Decrypt exactly 32 bytes using nacl/box with the given nonce, the given
   139  	// peer's public key, and the device's private encryption key, and return the
   140  	// decrypted data. The 'reason' parameter is used as part of the
   141  	// SecretEntryArg object passed into secretUi.getSecret().
   142  	UnboxBytes32(context.Context, UnboxBytes32Arg) (Bytes32, error)
   143  	UnboxBytes32Any(context.Context, UnboxBytes32AnyArg) (UnboxAnyRes, error)
   144  }
   145  
   146  func CryptoProtocol(i CryptoInterface) rpc.Protocol {
   147  	return rpc.Protocol{
   148  		Name: "keybase.1.crypto",
   149  		Methods: map[string]rpc.ServeHandlerDescription{
   150  			"signED25519": {
   151  				MakeArg: func() interface{} {
   152  					var ret [1]SignED25519Arg
   153  					return &ret
   154  				},
   155  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   156  					typedArgs, ok := args.(*[1]SignED25519Arg)
   157  					if !ok {
   158  						err = rpc.NewTypeError((*[1]SignED25519Arg)(nil), args)
   159  						return
   160  					}
   161  					ret, err = i.SignED25519(ctx, typedArgs[0])
   162  					return
   163  				},
   164  			},
   165  			"signED25519ForKBFS": {
   166  				MakeArg: func() interface{} {
   167  					var ret [1]SignED25519ForKBFSArg
   168  					return &ret
   169  				},
   170  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   171  					typedArgs, ok := args.(*[1]SignED25519ForKBFSArg)
   172  					if !ok {
   173  						err = rpc.NewTypeError((*[1]SignED25519ForKBFSArg)(nil), args)
   174  						return
   175  					}
   176  					ret, err = i.SignED25519ForKBFS(ctx, typedArgs[0])
   177  					return
   178  				},
   179  			},
   180  			"signToString": {
   181  				MakeArg: func() interface{} {
   182  					var ret [1]SignToStringArg
   183  					return &ret
   184  				},
   185  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   186  					typedArgs, ok := args.(*[1]SignToStringArg)
   187  					if !ok {
   188  						err = rpc.NewTypeError((*[1]SignToStringArg)(nil), args)
   189  						return
   190  					}
   191  					ret, err = i.SignToString(ctx, typedArgs[0])
   192  					return
   193  				},
   194  			},
   195  			"unboxBytes32": {
   196  				MakeArg: func() interface{} {
   197  					var ret [1]UnboxBytes32Arg
   198  					return &ret
   199  				},
   200  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   201  					typedArgs, ok := args.(*[1]UnboxBytes32Arg)
   202  					if !ok {
   203  						err = rpc.NewTypeError((*[1]UnboxBytes32Arg)(nil), args)
   204  						return
   205  					}
   206  					ret, err = i.UnboxBytes32(ctx, typedArgs[0])
   207  					return
   208  				},
   209  			},
   210  			"unboxBytes32Any": {
   211  				MakeArg: func() interface{} {
   212  					var ret [1]UnboxBytes32AnyArg
   213  					return &ret
   214  				},
   215  				Handler: func(ctx context.Context, args interface{}) (ret interface{}, err error) {
   216  					typedArgs, ok := args.(*[1]UnboxBytes32AnyArg)
   217  					if !ok {
   218  						err = rpc.NewTypeError((*[1]UnboxBytes32AnyArg)(nil), args)
   219  						return
   220  					}
   221  					ret, err = i.UnboxBytes32Any(ctx, typedArgs[0])
   222  					return
   223  				},
   224  			},
   225  		},
   226  	}
   227  }
   228  
   229  type CryptoClient struct {
   230  	Cli rpc.GenericClient
   231  }
   232  
   233  // Sign the given message (which should be small) using the device's private
   234  // signing ED25519 key, and return the signature as well as the corresponding
   235  // public key that can be used to verify the signature. The 'reason' parameter
   236  // is used as part of the SecretEntryArg object passed into
   237  // secretUi.getSecret().
   238  func (c CryptoClient) SignED25519(ctx context.Context, __arg SignED25519Arg) (res ED25519SignatureInfo, err error) {
   239  	err = c.Cli.Call(ctx, "keybase.1.crypto.signED25519", []interface{}{__arg}, &res, 0*time.Millisecond)
   240  	return
   241  }
   242  
   243  // Same as the above except a KBFS-specific prefix is added to the payload to be signed.
   244  func (c CryptoClient) SignED25519ForKBFS(ctx context.Context, __arg SignED25519ForKBFSArg) (res ED25519SignatureInfo, err error) {
   245  	err = c.Cli.Call(ctx, "keybase.1.crypto.signED25519ForKBFS", []interface{}{__arg}, &res, 0*time.Millisecond)
   246  	return
   247  }
   248  
   249  // Same as the above except the full marshaled and encoded NaclSigInfo.
   250  func (c CryptoClient) SignToString(ctx context.Context, __arg SignToStringArg) (res string, err error) {
   251  	err = c.Cli.Call(ctx, "keybase.1.crypto.signToString", []interface{}{__arg}, &res, 0*time.Millisecond)
   252  	return
   253  }
   254  
   255  // Decrypt exactly 32 bytes using nacl/box with the given nonce, the given
   256  // peer's public key, and the device's private encryption key, and return the
   257  // decrypted data. The 'reason' parameter is used as part of the
   258  // SecretEntryArg object passed into secretUi.getSecret().
   259  func (c CryptoClient) UnboxBytes32(ctx context.Context, __arg UnboxBytes32Arg) (res Bytes32, err error) {
   260  	err = c.Cli.Call(ctx, "keybase.1.crypto.unboxBytes32", []interface{}{__arg}, &res, 0*time.Millisecond)
   261  	return
   262  }
   263  
   264  func (c CryptoClient) UnboxBytes32Any(ctx context.Context, __arg UnboxBytes32AnyArg) (res UnboxAnyRes, err error) {
   265  	err = c.Cli.Call(ctx, "keybase.1.crypto.unboxBytes32Any", []interface{}{__arg}, &res, 0*time.Millisecond)
   266  	return
   267  }