@@ -20,37 +20,76 @@ namespace eosio {
20
20
*/
21
21
22
22
/* *
23
- * EOSIO Public Key
23
+ * EOSIO ECC public key data
24
+ *
25
+ * Fixed size representation of either a K1 or R1 compressed public key
26
+
27
+ * @ingroup public_key
28
+ */
29
+ using ecc_public_key = std::array<char , 33 >;
30
+
31
+ /* *
32
+ * EOSIO WebAuthN public key
24
33
*
25
34
* @ingroup public_key
26
35
*/
27
- struct public_key {
36
+ struct webauthn_public_key {
37
+ /* *
38
+ * Enumeration of the various results of a Test of User Presence
39
+ * @see https://w3c.github.io/webauthn/#test-of-user-presence
40
+ */
41
+ enum class user_presence_t : uint8_t {
42
+ USER_PRESENCE_NONE,
43
+ USER_PRESENCE_PRESENT,
44
+ USER_PRESENCE_VERIFIED
45
+ };
46
+
28
47
/* *
29
- * Type of the public key, could be either K1 or R1
48
+ * The ECC key material
30
49
*/
31
- unsigned_int type ;
50
+ ecc_public_key key ;
32
51
33
52
/* *
34
- * Bytes of the public key
53
+ * expected result of the test of user presence for a valid signature
54
+ * @see https://w3c.github.io/webauthn/#test-of-user-presence
35
55
*/
36
- std::array<char ,33 > data;
56
+ user_presence_t user_presence;
57
+
58
+ /* *
59
+ * the Relying Party Identifier for WebAuthN
60
+ * @see https://w3c.github.io/webauthn/#relying-party-identifier
61
+ */
62
+ std::string rpid;
37
63
38
64
// / @cond OPERATORS
39
65
40
- friend bool operator == ( const public_key & a, const public_key & b ) {
41
- return std::tie (a.type ,a.data ) == std::tie (b.type ,b.data );
66
+ friend bool operator == ( const webauthn_public_key & a, const webauthn_public_key & b ) {
67
+ return std::tie (a.key ,a.user_presence ,a. rpid ) == std::tie (b.key ,b.user_presence ,b. rpid );
42
68
}
43
- friend bool operator != ( const public_key & a, const public_key & b ) {
44
- return std::tie (a.type ,a.data ) != std::tie (b.type ,b.data );
69
+ friend bool operator != ( const webauthn_public_key & a, const webauthn_public_key & b ) {
70
+ return std::tie (a.key ,a.user_presence ,a. rpid ) != std::tie (b.key ,b.user_presence ,b. rpid );
45
71
}
46
72
47
73
// / @cond
48
74
};
49
75
76
+ /* *
77
+ * EOSIO Public Key
78
+ *
79
+ * A public key is a variant of
80
+ * 0 : a ECC K1 public key
81
+ * 1 : a ECC R1 public key
82
+ * 2 : a WebAuthN public key (requires the host chain to activate the WEBAUTHN_KEY consensus upgrade)
83
+ *
84
+ * @ingroup public_key
85
+ */
86
+ using public_key = std::variant<ecc_public_key, ecc_public_key, webauthn_public_key>;
87
+
88
+
50
89
// / @cond IMPLEMENTATIONS
51
90
52
91
/* *
53
- * Serialize an eosio::public_key into a stream
92
+ * Serialize an eosio::webauthn_public_key into a stream
54
93
*
55
94
* @ingroup public_key
56
95
* @param ds - The stream to write
@@ -59,14 +98,13 @@ namespace eosio {
59
98
* @return DataStream& - Reference to the datastream
60
99
*/
61
100
template <typename DataStream>
62
- inline DataStream& operator <<(DataStream& ds, const eosio::public_key& pubkey) {
63
- ds << pubkey.type ;
64
- ds.write ( pubkey.data .data (), pubkey.data .size () );
101
+ inline DataStream& operator <<(DataStream& ds, const eosio::webauthn_public_key& pubkey) {
102
+ ds << pubkey.key << pubkey.user_presence << pubkey.rpid ;
65
103
return ds;
66
104
}
67
105
68
106
/* *
69
- * Deserialize an eosio::public_key from a stream
107
+ * Deserialize an eosio::webauthn_public_key from a stream
70
108
*
71
109
* @ingroup public_key
72
110
* @param ds - The stream to read
@@ -75,9 +113,8 @@ namespace eosio {
75
113
* @return DataStream& - Reference to the datastream
76
114
*/
77
115
template <typename DataStream>
78
- inline DataStream& operator >>(DataStream& ds, eosio::public_key& pubkey) {
79
- ds >> pubkey.type ;
80
- ds.read ( pubkey.data .data (), pubkey.data .size () );
116
+ inline DataStream& operator >>(DataStream& ds, eosio::webauthn_public_key& pubkey) {
117
+ ds >> pubkey.key >> pubkey.user_presence >> pubkey.rpid ;
81
118
return ds;
82
119
}
83
120
@@ -91,63 +128,88 @@ namespace eosio {
91
128
*/
92
129
93
130
/* *
94
- * EOSIO Signature
131
+ * EOSIO ECC signature data
95
132
*
133
+ * Fixed size representation of either a K1 or R1 ECC compact signature
134
+
96
135
* @ingroup signature
97
136
*/
98
- struct signature {
137
+ using ecc_signature = std::array< char , 65 >;
99
138
139
+ /* *
140
+ * EOSIO WebAuthN signature
141
+ *
142
+ * @ingroup signature
143
+ */
144
+ struct webauthn_signature {
100
145
/* *
101
- * Type of the signature, could be either K1 or R1
146
+ * The ECC signature data
102
147
*/
103
- unsigned_int type ;
148
+ ecc_signature compact_signature ;
104
149
105
150
/* *
106
- * Bytes of the signature
151
+ * The Encoded Authenticator Data returned from WebAuthN ceremony
152
+ * @see https://w3c.github.io/webauthn/#sctn-authenticator-data
107
153
*/
108
- std::array<char ,65 > data;
154
+ std::vector<uint8_t > auth_data;
155
+
156
+ /* *
157
+ * the JSON encoded Collected Client Data from a WebAuthN ceremony
158
+ * @see https://w3c.github.io/webauthn/#dictdef-collectedclientdata
159
+ */
160
+ std::string client_json;
109
161
110
162
// / @cond OPERATORS
111
163
112
- friend bool operator == ( const signature & a, const signature & b ) {
113
- return std::tie (a.type ,a.data ) == std::tie (b.type ,b.data );
164
+ friend bool operator == ( const webauthn_signature & a, const webauthn_signature & b ) {
165
+ return std::tie (a.compact_signature ,a.auth_data ,a. client_json ) == std::tie (b.compact_signature ,b.auth_data ,b. client_json );
114
166
}
115
- friend bool operator != ( const signature & a, const signature & b ) {
116
- return std::tie (a.type ,a.data ) != std::tie (b.type ,b.data );
167
+ friend bool operator != ( const webauthn_signature & a, const webauthn_signature & b ) {
168
+ return std::tie (a.compact_signature ,a.auth_data ,a. client_json ) != std::tie (b.compact_signature ,b.auth_data ,b. client_json );
117
169
}
118
170
119
- // / @endcond
171
+ // / @cond
120
172
};
121
173
174
+ /* *
175
+ * EOSIO Signature
176
+ *
177
+ * A signature is a variant of
178
+ * 0 : a ECC K1 signature
179
+ * 1 : a ECC R1 signatre
180
+ * 2 : a WebAuthN signature (requires the host chain to activate the WEBAUTHN_KEY consensus upgrade)
181
+ *
182
+ * @ingroup signature
183
+ */
184
+ using signature = std::variant<ecc_signature, ecc_signature, webauthn_signature>;
185
+
122
186
// / @cond IMPLEMENTATIONS
123
187
124
188
/* *
125
- * Serialize an eosio::signature into a stream
189
+ * Serialize an eosio::webauthn_signature into a stream
126
190
*
127
191
* @param ds - The stream to write
128
192
* @param sig - The value to serialize
129
193
* @tparam DataStream - Type of datastream buffer
130
194
* @return DataStream& - Reference to the datastream
131
195
*/
132
196
template <typename DataStream>
133
- inline DataStream& operator <<(DataStream& ds, const eosio::signature& sig) {
134
- ds << sig.type ;
135
- ds.write ( sig.data .data (), sig.data .size () );
197
+ inline DataStream& operator <<(DataStream& ds, const eosio::webauthn_signature& sig) {
198
+ ds << sig.compact_signature << sig.auth_data << sig.client_json ;
136
199
return ds;
137
200
}
138
201
139
202
/* *
140
- * Deserialize an eosio::signature from a stream
203
+ * Deserialize an eosio::webauthn_signature from a stream
141
204
*
142
205
* @param ds - The stream to read
143
206
* @param sig - The destination for deserialized value
144
207
* @tparam DataStream - Type of datastream buffer
145
208
* @return DataStream& - Reference to the datastream
146
209
*/
147
210
template <typename DataStream>
148
- inline DataStream& operator >>(DataStream& ds, eosio::signature& sig) {
149
- ds >> sig.type ;
150
- ds.read ( sig.data .data (), sig.data .size () );
211
+ inline DataStream& operator >>(DataStream& ds, eosio::webauthn_signature& sig) {
212
+ ds >> sig.compact_signature >> sig.auth_data >> sig.client_json ;
151
213
return ds;
152
214
}
153
215
0 commit comments