Skip to content

Commit

Permalink
Merge pull request #2 from justkawal/codecov
Browse files Browse the repository at this point in the history
Add Codecov
  • Loading branch information
justkawal authored Nov 11, 2023
2 parents 3eb8544 + 8a0fe84 commit bd13c73
Show file tree
Hide file tree
Showing 17 changed files with 256 additions and 166 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file is used to define a set of default reviewers.
* @justkawal
2 changes: 1 addition & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
custom: https://paypal.me/justkawal
53 changes: 35 additions & 18 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Dart
name: Build and Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
paths-ignore:
- "**.md"
push:
branches:
- main
paths-ignore:
- "**.md"

jobs:
build:
runs-on: ubuntu-latest
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/[email protected]
with:
fetch-depth: 2

# Note: This workflow uses the latest stable version of the Dart SDK.
# You can specify other versions if desired, see documentation here:
Expand All @@ -31,12 +35,25 @@ jobs:
- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

# Consider passing '' for slightly stricter analysis.
# Consider passing '--fatal-infos' for slightly stricter analysis.
- name: Analyze project source
run: dart analyze --fatal-infos .
run: dart analyze --fatal-infos

# Run tests
- name: Run Tests
run: dart test --fail-fast

# Activate coverage
- name: Activate Coverage
run: dart pub global activate coverage

# Run coverage
- name: Run Coverage
run: dart pub global run coverage:test_with_coverage

# Code coverage
- uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage

# Your project will need to have tests in test/ and a dependency on
# package:test for this step to succeed. Note that Flutter projects will
# want to change this to 'flutter test'.
- name: Run tests
run: dart test
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 1.0.0

- Initial version.

## 1.0.1
- Publish version.

## 1.0.2
- Added Codecov
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,32 @@

### edwards25519, where security meets simplicity in cryptography!!


[![codecov](https://codecov.io/gh/justkawal/edwards25519/graph/badge.svg?token=8FERML02AR)](https://codecov.io/gh/justkawal/edwards25519)
[![Licence](https://img.shields.io/badge/License-MIT-red.svg)](./LICENSE)
![GitHub contributors](https://img.shields.io/github/contributors/justkawal/edwards25519)
[![Github Repo Stars](https://img.shields.io/github/stars/justkawal/edwards25519)](https://github.com/justkawal/edwards25519/stargazers)
![GitHub Sponsors](https://img.shields.io/github/sponsors/justkawal)

```dart
import 'dart:typed_data';
import 'package:convert/convert.dart';
import 'package:edwards25519/edwards25519.dart';
void main() {
final p1 = Point.zero()..setBytes(Uint8List.fromList(hex.decode('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')));
final p2 = Point.zero()..setBytes(Uint8List.fromList(hex.decode('1200000000000000000000000000000000000000000000000000000000000080')));
// if returns 1 then it is equal, 0 otherwise
final isEqual = p1.equal(p2) == 1;
print('isEqual: $isEqual');
final res = hex.encode(p1.Bytes());
// res: 1200000000000000000000000000000000000000000000000000000000000080
print('res: $res');
}
```

This library implements the edwards25519 elliptic curve, exposing the necessary APIs to build a wide array of higher-level primitives.
Expand Down
7 changes: 3 additions & 4 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ linter:
camel_case_types: false
file_names: false
non_constant_identifier_names: false
unnecessary_overrides: false

analyzer:
language:
use_string_in_part_of_directives: false
prefer_single_quotes: true
prefer_final_fields: true
26 changes: 26 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
codecov:
require_ci_to_pass: true

coverage:
status:
project: off
patch: off

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

# excluding generated files and examples from the coverage report
ignore:
- "**/example/"
- "examples"
- "**/*.g.dart"

comment:
layout: "reach,diff,flags,tree"
behavior: default
require_changes: false
3 changes: 0 additions & 3 deletions coverage.sh

This file was deleted.

21 changes: 21 additions & 0 deletions example/edwards_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'dart:typed_data';
import 'package:convert/convert.dart';
import 'package:edwards25519/edwards25519.dart';

void main() {
final p1 = Point.zero()
..setBytes(Uint8List.fromList(hex.decode(
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff')));

final p2 = Point.zero()
..setBytes(Uint8List.fromList(hex.decode(
'1200000000000000000000000000000000000000000000000000000000000080')));

// if returns 1 then it is equal, 0 otherwise
final isEqual = p1.equal(p2) == 1;
print('isEqual: $isEqual');

final res = hex.encode(p1.Bytes());
// res: 1200000000000000000000000000000000000000000000000000000000000080
print('res: $res');
}
14 changes: 7 additions & 7 deletions lib/core/src/point.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class Point {
// 2) the ones where the x-coordinate is zero and the sign bit is set.
//
// Read more at https://hdevalence.ca/blog/2020-10-04-its-25519am,
// specifically the "Canonical A, R" section.
// specifically the 'Canonical A, R' section.

final y1 = Element.feZero()..setBytes(bytes);

Expand All @@ -147,7 +147,7 @@ class Point {
// x = +√(u/v)
final (Element xx, int wasSquare) = Element.feZero().sqrtRatio(u, vv);
if (wasSquare == 0) {
throw Exception("edwards25519: invalid point encoding");
throw Exception('edwards25519: invalid point encoding');
}

// Select the negative square root if the sign bit is set.
Expand Down Expand Up @@ -277,7 +277,7 @@ class Point {
/// unchanged. Otherwise, SetExtendedCoordinates returns v.
void setExtendedCoordinates(Element X, Element Y, Element Z, Element T) {
if (!checkOnCurve([Point(X, Y, Z, T)])) {
throw ArgumentError("edwards25519: invalid point coordinates");
throw ArgumentError('edwards25519: invalid point coordinates');
}
x.set(X);
y.set(Y);
Expand Down Expand Up @@ -344,7 +344,7 @@ class Point {
void multiScalarMult(List<Scalar> scalars, List<Point> points) {
if (scalars.length != points.length) {
throw Exception(
"edwards25519: called MultiScalarMult with different size inputs");
'edwards25519: called MultiScalarMult with different size inputs');
}
// Proceed as in the single-base case, but share doublings
// between each point in the multiscalar equation.
Expand Down Expand Up @@ -398,7 +398,7 @@ class Point {
void varTimeMultiScalarMult(List<Scalar> scalars, List<Point> points) {
if (scalars.length != points.length) {
throw Exception(
"edwards25519: called VarTimeMultiScalarMult with different size inputs");
'edwards25519: called VarTimeMultiScalarMult with different size inputs');
}

// Generalize double-base NAF computation to arbitrary sizes.
Expand Down Expand Up @@ -555,8 +555,8 @@ class Point {
// radix 16. This is like a binary representation (one digit
// for each binary place) but we allow the digits to grow in
// magnitude up to 2^{w-1} so that the nonzero digits are as
// sparse as possible. Intuitively, this "condenses" the
// "mass" of the scalar onto sparse coefficients (meaning
// sparse as possible. Intuitively, this 'condenses' the
// 'mass' of the scalar onto sparse coefficients (meaning
// fewer additions).

final basepointNafTable = basepointNafTablePrecomp.instance.table;
Expand Down
20 changes: 10 additions & 10 deletions lib/core/src/scalar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class Scalar {
/// 64 uniformly distributed random bytes.
void setUniformBytes(List<int> x) {
if (x.length != 64) {
//return nil, errors.New("edwards25519: invalid SetUniformBytes input length")
throw ArgumentError("edwards25519: invalid setUniformBytes input length");
//return nil, errors.New('edwards25519: invalid SetUniformBytes input length')
throw ArgumentError('edwards25519: invalid setUniformBytes input length');
}

// We have a value x of 512 bits, but our fiatScalarFromBytes function
Expand Down Expand Up @@ -133,7 +133,7 @@ class Scalar {
void setShortBytes(List<int> x) {
if (x.length >= 32) {
throw ArgumentError(
"edwards25519: internal error: setShortBytes called with a long string");
'edwards25519: internal error: setShortBytes called with a long string');
}

List<int> buf = List<int>.filled(32, 0, growable: false);
Expand All @@ -147,10 +147,10 @@ class Scalar {
/// returns nil and an error, and the receiver is unchanged.
void setCanonicalBytes(List<int> x) {
if (x.length != 32) {
throw ArgumentError("edwards25519: invalid scalar length");
throw ArgumentError('edwards25519: invalid scalar length');
}
if (!isReduced(x)) {
throw ArgumentError("edwards25519: invalid scalar encoding");
throw ArgumentError('edwards25519: invalid scalar encoding');
}

fiatScalarFromBytes(s, x);
Expand Down Expand Up @@ -228,7 +228,7 @@ class Scalar {
// implementation bug that was once observed in a generic Montgomery ladder.
if (x.length != 32) {
throw ArgumentError(
"edwards25519: invalid SetBytesWithClamping input length");
'edwards25519: invalid SetBytesWithClamping input length');
}

// We need to use the wide reduction from SetUniformBytes, since clamping
Expand Down Expand Up @@ -281,13 +281,13 @@ class Scalar {
// https://github.com/dalek-cryptography/curve25519-dalek/blob/f630041af28e9a405255f98a8a93adca18e4315b/src/scalar.rs#L800-L871
final Uint8List b = Bytes();
if (b[31] > 127) {
throw ArgumentError("edwards25519: scalar has high bit set illegally");
throw ArgumentError('edwards25519: scalar has high bit set illegally');
}
if (w < 2) {
throw ArgumentError(
"edwards25519: w must be at least 2 by the definition of NAF");
'edwards25519: w must be at least 2 by the definition of NAF');
} else if (w > 8) {
throw ArgumentError("edwards25519: NAF digits must fit in int8");
throw ArgumentError('edwards25519: NAF digits must fit in int8');
}

List<int> naf = List<int>.filled(256, 0, growable: false);
Expand Down Expand Up @@ -355,7 +355,7 @@ class Scalar {
List<int> signedRadix16() {
final b = Bytes();
if (b[31] > 127) {
throw ArgumentError("edwards25519: scalar has high bit set illegally");
throw ArgumentError('edwards25519: scalar has high bit set illegally');
}

final digits = List<int>.filled(64, 0, growable: false);
Expand Down
6 changes: 3 additions & 3 deletions lib/field/fe/fe.dart
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ class Element {
/// consistent with most Ed25519 implementations.
void setBytes(Uint8List x) {
if (x.length != 32) {
throw ArgumentError("edwards25519: invalid field element input size");
throw ArgumentError('edwards25519: invalid field element input size');
}

// Bits 0:51 (bytes 0:8, bits 0:64, shift 0, mask 51).
Expand Down Expand Up @@ -694,7 +694,7 @@ class Element {
/// fromBig sets v = n, and returns v. The bit length of n must not exceed 256.
void fromBigInt(BigInt n) {
if (n.bitLength > 32 * 8) {
throw ArgumentError("edwards25519: invalid field element input size");
throw ArgumentError('edwards25519: invalid field element input size');
}

final uint8List = Uint8List(32);
Expand Down Expand Up @@ -731,7 +731,7 @@ class Element {
/// of bias is less than 2⁻²⁵⁰.
void setWideBytes(Uint8List x) {
if (x.length != 64) {
throw ArgumentError("edwards25519: invalid SetWideBytes input size");
throw ArgumentError('edwards25519: invalid SetWideBytes input size');
}

// Split the 64 bytes into two elements, and extract the most significant
Expand Down
8 changes: 4 additions & 4 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: edwards25519
description: ed25519, where security meets simplicity in cryptography!!
version: 1.0.1
description: edwards25519, where security meets simplicity in cryptography!!
version: 1.0.2
repository: https://github.com/justkawal/edwards25519

environment:
sdk: ^3.0.5

dev_dependencies:
lints: ^2.0.0
test: ^1.21.0
lints: ^3.0.0
test: ^1.24.9
convert: ^3.1.1
Loading

0 comments on commit bd13c73

Please sign in to comment.