@@ -27,6 +27,29 @@ type metaEncryptedX25519DeoxysII struct {
27
27
pk * x25519.PublicKey
28
28
}
29
29
30
+ func encodeCallEncryptedX25519DeoxysII (call * types.Call , pk * x25519.PublicKey , sk * x25519.PrivateKey , nonce [deoxysii .NonceSize ]byte , cfg * EncodeConfig ) (* types.Call , * metaEncryptedX25519DeoxysII ) {
31
+ // Seal serialized plain call.
32
+ rawCall := cbor .Marshal (call )
33
+ sealedCall := mraeDeoxysii .Box .Seal (nil , nonce [:], rawCall , nil , & cfg .PublicKey .PublicKey , sk )
34
+
35
+ encoded := & types.Call {
36
+ Format : types .CallFormatEncryptedX25519DeoxysII ,
37
+ Method : "" ,
38
+ Body : cbor .Marshal (& types.CallEnvelopeX25519DeoxysII {
39
+ Pk : * pk ,
40
+ Nonce : nonce ,
41
+ Epoch : cfg .Epoch ,
42
+ Data : sealedCall ,
43
+ }),
44
+ ReadOnly : call .ReadOnly ,
45
+ }
46
+ meta := & metaEncryptedX25519DeoxysII {
47
+ sk : sk ,
48
+ pk : & cfg .PublicKey .PublicKey ,
49
+ }
50
+ return encoded , meta
51
+ }
52
+
30
53
// EncodeCall encodes a call based on its configured call format.
31
54
//
32
55
// It returns the encoded call and any metadata needed to successfully decode the result.
@@ -52,25 +75,7 @@ func EncodeCall(call *types.Call, cf types.CallFormat, cfg *EncodeConfig) (*type
52
75
return nil , nil , fmt .Errorf ("callformat: failed to generate random nonce: %w" , err )
53
76
}
54
77
55
- // Seal serialized plain call.
56
- rawCall := cbor .Marshal (call )
57
- sealedCall := mraeDeoxysii .Box .Seal (nil , nonce [:], rawCall , nil , & cfg .PublicKey .PublicKey , sk )
58
-
59
- encoded := & types.Call {
60
- Format : types .CallFormatEncryptedX25519DeoxysII ,
61
- Method : "" ,
62
- Body : cbor .Marshal (& types.CallEnvelopeX25519DeoxysII {
63
- Pk : * pk ,
64
- Nonce : nonce ,
65
- Epoch : cfg .Epoch ,
66
- Data : sealedCall ,
67
- }),
68
- ReadOnly : call .ReadOnly ,
69
- }
70
- meta := & metaEncryptedX25519DeoxysII {
71
- sk : sk ,
72
- pk : & cfg .PublicKey .PublicKey ,
73
- }
78
+ encoded , meta := encodeCallEncryptedX25519DeoxysII (call , pk , sk , nonce , cfg )
74
79
return encoded , meta , nil
75
80
default :
76
81
return nil , nil , fmt .Errorf ("callformat: unsupported call format: %s" , cf )
0 commit comments