Skip to content

Commit 1da8699

Browse files
authored
feat: update to Noir 1.0.0-beta.3 (#2)
1 parent edd3d6c commit 1da8699

File tree

4 files changed

+145
-134
lines changed

4 files changed

+145
-134
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
toolchain: [nightly, 0.35.0, 0.36.0]
19+
toolchain: [1.0.0-beta.3]
2020
steps:
2121
- name: Checkout sources
2222
uses: actions/checkout@v4
@@ -38,7 +38,7 @@ jobs:
3838
- name: Install Nargo
3939
uses: noir-lang/[email protected]
4040
with:
41-
toolchain: 0.36.0
41+
toolchain: 1.0.0-beta.3
4242

4343
- name: Run formatter
4444
run: nargo fmt --check

Nargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "webauthn"
33
type = "lib"
44
authors = ["Oleh Misarosh <[email protected]"]
5-
compiler_version = ">=0.34.0"
65

76
[dependencies]
8-
base64 = { git = "https://github.com/olehmisar/noir_base64/", tag = "v0.3.0" }
7+
base64 = { git = "https://github.com/noir-lang/noir_base64", tag = "v0.3.1" }
8+
nodash = { git = "https://github.com/olehmisar/nodash", tag = "v0.40.2" }

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,9 @@ In your _Nargo.toml_ file, add the version of this library you would like to ins
2323

2424
```toml
2525
[dependencies]
26-
webauthn = { tag = "v0.36.0", git = "https://github.com/olehmisar/noir_webauthn" }
26+
webauthn = { tag = "v0.37.0", git = "https://github.com/olehmisar/noir_webauthn" }
2727
```
2828

29-
<details>
30-
<summary>
31-
Note on version compatibility with Noir
32-
</summary>
33-
34-
The version of this library matches the version of Noir. The patch version may be different if a bugfix or a new feature is added for the same version of Noir. E.g., this library version v0.36.0 and this library version v0.36.1 are compatible with [email protected].
35-
36-
</details>
37-
3829
## Usage
3930

4031
```rs

src/lib.nr

Lines changed: 140 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
// TODO(security): what is the correct size for client_data_json and authenticator_data? Is it even fixed?
2-
// if the authenticator data or client data json generated by the browser are too long, the signature verification will fail (rendering the account unusable and funds lost)
1+
pub global SIGNATURE_LEN: u32 = 64;
32

4-
// TODO(security): determine the correct max length. Reference: https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API/Authenticator_data#data_structure
5-
global AUTHENTICATOR_DATA_MAX_LEN: u32 = 64; // usually around 37
6-
// TODO(security): determine the correct max length. Reference: https://developer.mozilla.org/en-US/docs/Web/API/AuthenticatorResponse/clientDataJSON#value
7-
global CLIENT_DATA_JSON_MAX_LEN: u32 = 256; // usually around 134
8-
9-
global SIGNATURE_LEN: u32 = 64;
10-
11-
pub fn verify_signature(
3+
pub fn verify_signature<let CLIENT_DATA_JSON_MAX_LEN: u32, let AUTHENTICATOR_DATA_MAX_LEN: u32>(
124
public_key_x: [u8; 32],
135
public_key_y: [u8; 32],
146
signature: [u8; SIGNATURE_LEN],
@@ -17,13 +9,12 @@ pub fn verify_signature(
179
challenge: [u8; 32],
1810
challenge_index: u32,
1911
) -> bool {
20-
let client_data_json_hash: [u8; 32] =
21-
std::hash::sha256_var(client_data_json.storage(), client_data_json.len() as u64);
12+
let client_data_json_hash = nodash::sha256(client_data_json);
2213
let concatenated: BoundedVec<u8, AUTHENTICATOR_DATA_MAX_LEN + 32> =
2314
concat(authenticator_data, client_data_json_hash);
24-
let hashed_message = std::hash::sha256_var(concatenated.storage(), concatenated.len() as u64);
15+
let hashed_message = nodash::sha256(concatenated);
2516

26-
let challenge_base64_url: [_; 40] = base64::BASE64_ENCODER_URL_SAFE_NO_PAD.encode(challenge);
17+
let challenge_base64_url: [u8; 43] = base64::BASE64_URL_ENCODER.encode(challenge);
2718
str_contains_base64_url(
2819
client_data_json.storage(),
2920
challenge_base64_url,
@@ -48,50 +39,52 @@ fn str_contains_base64_url<let N: u32, let H: u32>(haystack: [u8; H], needle: [u
4839
}
4940
}
5041

51-
#[test]
52-
fn my_test() {
53-
assert(verify_signature(
54-
[
55-
91, 200, 36, 72, 14, 85, 105, 189, 204, 19, 185, 157, 161, 241, 56, 107, 228, 8, 67,
56-
156, 7, 183, 173, 111, 146, 216, 51, 2, 244, 251, 78, 203,
57-
],
58-
[
59-
30, 52, 243, 79, 92, 114, 5, 253, 138, 212, 14, 51, 122, 247, 225, 82, 193, 243, 157,
60-
70, 225, 62, 254, 206, 247, 110, 252, 111, 188, 128, 142, 226,
61-
],
62-
[
63-
47, 222, 74, 22, 26, 2, 142, 123, 25, 179, 68, 61, 58, 204, 200, 245, 241, 176, 227,
64-
237, 173, 115, 147, 229, 128, 165, 63, 170, 148, 250, 171, 141, 115, 50, 249, 181, 84,
65-
62, 116, 119, 139, 101, 89, 14, 140, 246, 186, 29, 143, 146, 13, 198, 186, 85, 47, 213,
66-
235, 176, 236, 26, 88, 231, 191, 129,
67-
],
68-
BoundedVec::from([
69-
123, 34, 116, 121, 112, 101, 34, 58, 34, 119, 101, 98, 97, 117, 116, 104, 110, 46, 103,
70-
101, 116, 34, 44, 34, 99, 104, 97, 108, 108, 101, 110, 103, 101, 34, 58, 34, 85, 76, 76,
71-
69, 80, 57, 79, 82, 66, 114, 114, 55, 117, 103, 50, 106, 84, 56, 81, 119, 52, 102, 107,
72-
101, 80, 74, 98, 113, 75, 115, 55, 105, 118, 68, 81, 82, 110, 53, 75, 122, 100, 49, 65,
73-
34, 44, 34, 111, 114, 105, 103, 105, 110, 34, 58, 34, 104, 116, 116, 112, 58, 47, 47,
74-
108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 53, 49, 56, 52, 34, 44, 34, 99, 114, 111,
75-
115, 115, 79, 114, 105, 103, 105, 110, 34, 58, 102, 97, 108, 115, 101, 125,
76-
]),
77-
BoundedVec::from([
78-
73, 150, 13, 229, 136, 14, 140, 104, 116, 52, 23, 15, 100, 118, 96, 91, 143, 228, 174,
79-
185, 162, 134, 50, 199, 153, 92, 243, 186, 131, 29, 151, 99, 29, 0, 0, 0, 0,
80-
]),
81-
[
82-
80, 178, 196, 63, 211, 145, 6, 186, 251, 186, 13, 163, 79, 196, 48, 225, 249, 30, 60,
83-
150, 234, 42, 206, 226, 188, 52, 17, 159, 146, 179, 119, 80,
84-
],
85-
36,
86-
));
42+
fn concat<let N: u32>(a: BoundedVec<u8, N>, b: [u8; 32]) -> BoundedVec<u8, N + 32> {
43+
let mut result = [0 as u8; N + 32];
44+
let mut j = 0;
45+
for i in 0..N {
46+
if (i < a.len()) {
47+
result[j] = a.get(i);
48+
j += 1;
49+
}
50+
}
51+
for i in 0..b.len() {
52+
result[j] = b[i];
53+
j += 1;
54+
}
55+
BoundedVec::from_parts(result, j)
8756
}
8857

89-
#[test]
90-
fn test_fail() {
91-
assert(
92-
!verify_signature(
58+
mod tests {
59+
use super::{SIGNATURE_LEN, verify_signature};
60+
61+
global AUTHENTICATOR_DATA_MAX_LEN: u32 = 64;
62+
global CLIENT_DATA_JSON_MAX_LEN: u32 = 256;
63+
fn ver(
64+
public_key_x: [u8; 32],
65+
public_key_y: [u8; 32],
66+
signature: [u8; SIGNATURE_LEN],
67+
client_data_json: BoundedVec<u8, CLIENT_DATA_JSON_MAX_LEN>,
68+
authenticator_data: BoundedVec<u8, AUTHENTICATOR_DATA_MAX_LEN>,
69+
challenge: [u8; 32],
70+
challenge_index: u32,
71+
) -> bool {
72+
verify_signature(
73+
public_key_x,
74+
public_key_y,
75+
signature,
76+
client_data_json,
77+
authenticator_data,
78+
challenge,
79+
challenge_index,
80+
)
81+
}
82+
83+
#[test]
84+
fn my_test() {
85+
assert(ver(
9386
[
94-
90, 200, 36, 72, 14, 85, 105, 189, 204, 19, 185, 157, 161, 241, 56, 107, 228, 8, 67,
87+
91, 200, 36, 72, 14, 85, 105, 189, 204, 19, 185, 157, 161, 241, 56, 107, 228, 8, 67,
9588
156, 7, 183, 173, 111, 146, 216, 51, 2, 244, 251, 78, 203,
9689
],
9790
[
@@ -123,73 +116,100 @@ fn test_fail() {
123116
60, 150, 234, 42, 206, 226, 188, 52, 17, 159, 146, 179, 119, 80,
124117
],
125118
36,
126-
),
127-
);
128-
}
119+
));
120+
}
129121

130-
#[test]
131-
fn some_test() {
132-
assert(verify_signature(
133-
[
134-
139, 86, 118, 230, 15, 13, 30, 204, 6, 133, 248, 82, 54, 101, 178, 189, 126, 170, 84,
135-
48, 0, 106, 149, 40, 133, 99, 30, 73, 2, 210, 205, 200,
136-
],
137-
[
138-
184, 8, 42, 248, 97, 207, 125, 175, 201, 50, 10, 102, 148, 60, 53, 169, 208, 70, 112,
139-
255, 179, 218, 110, 33, 33, 135, 156, 9, 30, 230, 17, 26,
140-
],
141-
[
142-
182, 153, 194, 137, 148, 109, 190, 71, 178, 33, 99, 179, 75, 12, 9, 132, 225, 154, 15,
143-
237, 58, 248, 132, 130, 94, 16, 155, 206, 77, 21, 66, 223, 79, 248, 19, 205, 57, 183,
144-
65, 109, 45, 135, 165, 109, 50, 56, 84, 208, 76, 252, 111, 240, 6, 114, 169, 202, 193,
145-
130, 20, 17, 144, 51, 55, 254,
146-
],
147-
BoundedVec {
148-
storage: [
149-
123, 34, 116, 121, 112, 101, 34, 58, 34, 119, 101, 98, 97, 117, 116, 104, 110, 46,
150-
103, 101, 116, 34, 44, 34, 99, 104, 97, 108, 108, 101, 110, 103, 101, 34, 58, 34,
151-
67, 70, 99, 69, 97, 110, 104, 100, 102, 45, 57, 74, 106, 84, 51, 48, 89, 100, 116,
152-
98, 78, 87, 54, 53, 81, 117, 88, 52, 85, 84, 80, 57, 79, 118, 122, 66, 85, 97, 74,
153-
95, 87, 111, 111, 34, 44, 34, 111, 114, 105, 103, 105, 110, 34, 58, 34, 104, 116,
154-
116, 112, 58, 47, 47, 108, 111, 99, 97, 108, 104, 111, 115, 116, 58, 53, 49, 56, 52,
155-
34, 44, 34, 99, 114, 111, 115, 115, 79, 114, 105, 103, 105, 110, 34, 58, 102, 97,
156-
108, 115, 101, 125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
157-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
158-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
159-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
160-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
122+
#[test]
123+
fn test_fail() {
124+
assert(
125+
!ver(
126+
[
127+
90, 200, 36, 72, 14, 85, 105, 189, 204, 19, 185, 157, 161, 241, 56, 107, 228, 8,
128+
67, 156, 7, 183, 173, 111, 146, 216, 51, 2, 244, 251, 78, 203,
129+
],
130+
[
131+
30, 52, 243, 79, 92, 114, 5, 253, 138, 212, 14, 51, 122, 247, 225, 82, 193, 243,
132+
157, 70, 225, 62, 254, 206, 247, 110, 252, 111, 188, 128, 142, 226,
133+
],
134+
[
135+
47, 222, 74, 22, 26, 2, 142, 123, 25, 179, 68, 61, 58, 204, 200, 245, 241, 176,
136+
227, 237, 173, 115, 147, 229, 128, 165, 63, 170, 148, 250, 171, 141, 115, 50,
137+
249, 181, 84, 62, 116, 119, 139, 101, 89, 14, 140, 246, 186, 29, 143, 146, 13,
138+
198, 186, 85, 47, 213, 235, 176, 236, 26, 88, 231, 191, 129,
139+
],
140+
BoundedVec::from([
141+
123, 34, 116, 121, 112, 101, 34, 58, 34, 119, 101, 98, 97, 117, 116, 104, 110,
142+
46, 103, 101, 116, 34, 44, 34, 99, 104, 97, 108, 108, 101, 110, 103, 101, 34,
143+
58, 34, 85, 76, 76, 69, 80, 57, 79, 82, 66, 114, 114, 55, 117, 103, 50, 106, 84,
144+
56, 81, 119, 52, 102, 107, 101, 80, 74, 98, 113, 75, 115, 55, 105, 118, 68, 81,
145+
82, 110, 53, 75, 122, 100, 49, 65, 34, 44, 34, 111, 114, 105, 103, 105, 110, 34,
146+
58, 34, 104, 116, 116, 112, 58, 47, 47, 108, 111, 99, 97, 108, 104, 111, 115,
147+
116, 58, 53, 49, 56, 52, 34, 44, 34, 99, 114, 111, 115, 115, 79, 114, 105, 103,
148+
105, 110, 34, 58, 102, 97, 108, 115, 101, 125,
149+
]),
150+
BoundedVec::from([
151+
73, 150, 13, 229, 136, 14, 140, 104, 116, 52, 23, 15, 100, 118, 96, 91, 143,
152+
228, 174, 185, 162, 134, 50, 199, 153, 92, 243, 186, 131, 29, 151, 99, 29, 0, 0,
153+
0, 0,
154+
]),
155+
[
156+
80, 178, 196, 63, 211, 145, 6, 186, 251, 186, 13, 163, 79, 196, 48, 225, 249,
157+
30, 60, 150, 234, 42, 206, 226, 188, 52, 17, 159, 146, 179, 119, 80,
158+
],
159+
36,
160+
),
161+
);
162+
}
163+
164+
#[test]
165+
fn some_test() {
166+
assert(ver(
167+
[
168+
139, 86, 118, 230, 15, 13, 30, 204, 6, 133, 248, 82, 54, 101, 178, 189, 126, 170,
169+
84, 48, 0, 106, 149, 40, 133, 99, 30, 73, 2, 210, 205, 200,
161170
],
162-
len: 134,
163-
},
164-
BoundedVec {
165-
storage: [
166-
73, 150, 13, 229, 136, 14, 140, 104, 116, 52, 23, 15, 100, 118, 96, 91, 143, 228,
167-
174, 185, 162, 134, 50, 199, 153, 92, 243, 186, 131, 29, 151, 99, 29, 0, 0, 0, 0, 0,
168-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
171+
[
172+
184, 8, 42, 248, 97, 207, 125, 175, 201, 50, 10, 102, 148, 60, 53, 169, 208, 70,
173+
112, 255, 179, 218, 110, 33, 33, 135, 156, 9, 30, 230, 17, 26,
169174
],
170-
len: 37,
171-
},
172-
[
173-
8, 87, 4, 106, 120, 93, 127, 239, 73, 141, 61, 244, 97, 219, 91, 53, 110, 185, 66, 229,
174-
248, 81, 51, 253, 58, 252, 193, 81, 162, 127, 90, 138,
175-
],
176-
36,
177-
));
178-
}
179-
180-
fn concat<let N: u32, let S: u32>(a: BoundedVec<u8, N>, b: [u8; 32]) -> BoundedVec<u8, S> {
181-
assert_eq(N + 32, S, "combined bounded vec length does not match return bounded vec length");
182-
let mut result = [0 as u8; S];
183-
let mut j = 0;
184-
for i in 0..N {
185-
if (i < a.len()) {
186-
result[j] = a.get(i);
187-
j += 1;
188-
}
189-
}
190-
for i in 0..b.len() {
191-
result[j] = b[i];
192-
j += 1;
175+
[
176+
182, 153, 194, 137, 148, 109, 190, 71, 178, 33, 99, 179, 75, 12, 9, 132, 225, 154,
177+
15, 237, 58, 248, 132, 130, 94, 16, 155, 206, 77, 21, 66, 223, 79, 248, 19, 205, 57,
178+
183, 65, 109, 45, 135, 165, 109, 50, 56, 84, 208, 76, 252, 111, 240, 6, 114, 169,
179+
202, 193, 130, 20, 17, 144, 51, 55, 254,
180+
],
181+
BoundedVec::from_parts(
182+
[
183+
123, 34, 116, 121, 112, 101, 34, 58, 34, 119, 101, 98, 97, 117, 116, 104, 110,
184+
46, 103, 101, 116, 34, 44, 34, 99, 104, 97, 108, 108, 101, 110, 103, 101, 34,
185+
58, 34, 67, 70, 99, 69, 97, 110, 104, 100, 102, 45, 57, 74, 106, 84, 51, 48, 89,
186+
100, 116, 98, 78, 87, 54, 53, 81, 117, 88, 52, 85, 84, 80, 57, 79, 118, 122, 66,
187+
85, 97, 74, 95, 87, 111, 111, 34, 44, 34, 111, 114, 105, 103, 105, 110, 34, 58,
188+
34, 104, 116, 116, 112, 58, 47, 47, 108, 111, 99, 97, 108, 104, 111, 115, 116,
189+
58, 53, 49, 56, 52, 34, 44, 34, 99, 114, 111, 115, 115, 79, 114, 105, 103, 105,
190+
110, 34, 58, 102, 97, 108, 115, 101, 125, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
191+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
192+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
193+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
194+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
195+
0,
196+
],
197+
134,
198+
),
199+
BoundedVec::from_parts(
200+
[
201+
73, 150, 13, 229, 136, 14, 140, 104, 116, 52, 23, 15, 100, 118, 96, 91, 143,
202+
228, 174, 185, 162, 134, 50, 199, 153, 92, 243, 186, 131, 29, 151, 99, 29, 0, 0,
203+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
204+
0, 0,
205+
],
206+
37,
207+
),
208+
[
209+
8, 87, 4, 106, 120, 93, 127, 239, 73, 141, 61, 244, 97, 219, 91, 53, 110, 185, 66,
210+
229, 248, 81, 51, 253, 58, 252, 193, 81, 162, 127, 90, 138,
211+
],
212+
36,
213+
));
193214
}
194-
BoundedVec { storage: result, len: j }
195215
}

0 commit comments

Comments
 (0)