Skip to content

Commit

Permalink
Update dependencies and optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
justkawal committed Nov 24, 2023
1 parent e49c428 commit 95162c7
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 26 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ on:

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

steps:
- uses: actions/checkout@v3.5.0
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@

## 1.0.2
- Update ReadMe.

## 1.0.3
- Optimizations
- Fix example
- Update ReadMe.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ It automates the [Fiat-Shamir](https://en.wikipedia.org/wiki/Fiat–Shamir_heuri
// Simple Transcript
final transcript = Transcript('test protocol');
transcript.appendMessage(Uint8List.fromList(utf8.encode('some label')), Uint8List.fromList(utf8.encode('some data')));
transcript.appendMessage(utf8.encode('some label'), utf8.encode('some data'));
final cBytes = transcript.extractBytes(Uint8List.fromList(utf8.encode('challenge')), 32);
final cBytes = transcript.extractBytes(utf8.encode('challenge'), 32);
// cHex = d5a21972d0d5fe320c0d263fac7fffb8145aa640af6e9bca177c03c7efcf0615
final cHex = hex.encode(cBytes);
Expand Down
8 changes: 3 additions & 5 deletions example/example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,9 @@ void main() {
//Simple Transcript
final mt = Transcript('test protocol');

mt.appendMessage(Uint8List.fromList(utf8.encode('some label')),
Uint8List.fromList(utf8.encode('some data')));
mt.appendMessage(utf8.encode('some label'), utf8.encode('some data'));

final cBytes =
mt.extractBytes(Uint8List.fromList(utf8.encode('challenge')), 32);
final cBytes = mt.extractBytes(utf8.encode('challenge'), 32);

// d5a21972d0d5fe320c0d263fac7fffb8145aa640af6e9bca177c03c7efcf0615
final cHex = hex.encode(cBytes);
Expand All @@ -27,7 +25,7 @@ void main() {

final data = Uint8List(1024)..fillRange(0, 1024, 99);

late List<int> chlBytes;
late Uint8List chlBytes;
for (var i = 0; i < 32; i++) {
chlBytes = tr.extractBytes(utf8.encode('challenge'), 32);
tr
Expand Down
18 changes: 10 additions & 8 deletions lib/merlin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ import 'dart:typed_data';
import 'package:strobe/strobe.dart';

const merlinProtocolLabel = 'Merlin v1.0';
const domainSeparatorLabel = 'dom-sep';
//const domainSeparatorLabel = 'dom-sep';
final domainSeparatorLabel =
Uint8List.fromList([100, 111, 109, 45, 115, 101, 112]);

class Transcript {
late Strobe s;
Transcript(String appLabel) {
s = Strobe.initStrobe(merlinProtocolLabel, Security.bit128);
appendMessage(utf8.encode(domainSeparatorLabel), utf8.encode(appLabel));
appendMessage(domainSeparatorLabel, utf8.encode(appLabel));
}

// Append adds the message to the transcript with the supplied label.
/// Append adds the message to the transcript with the supplied label.
void appendMessage(List<int> label, List<int> message) {
final sizeBuffer = Uint8List(4);
ByteData.view(sizeBuffer.buffer)
Expand All @@ -24,11 +26,11 @@ class Transcript {
..aD(false, message);
}

// ExtractBytes returns a buffer filled with the verifier's challenge bytes.
// The label parameter is metadata about the challenge, and is also appended to
// the transcript. See the Transcript Protocols section of the Merlin website
// for details on labels.
List<int> extractBytes(List<int> label, int outLen) {
/// ExtractBytes returns a buffer filled with the verifier's challenge bytes.
/// The label parameter is metadata about the challenge, and is also appended to
/// the transcript. See the Transcript Protocols section of the Merlin website
/// for details on labels.
Uint8List extractBytes(List<int> label, int outLen) {
final sizeBuffer = Uint8List(4);
ByteData.view(sizeBuffer.buffer).setUint32(0, outLen, Endian.little);

Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: merlin
description: Merlin is a STROBE-based transcript construction for zero-knowledge proofs.
version: 1.0.2
version: 1.0.3
repository: https://github.com/justkawal/merlin

environment:
sdk: ^3.1.5

dependencies:
strobe: ^1.0.2
strobe: ^1.0.4

dev_dependencies:
convert: ^3.1.1
Expand Down
8 changes: 3 additions & 5 deletions test/merlin_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ import 'package:test/test.dart';
void main() {
test('Test Simple Transcript', () {
final mt = Transcript('test protocol');
mt.appendMessage(Uint8List.fromList(utf8.encode('some label')),
Uint8List.fromList(utf8.encode('some data')));
mt.appendMessage(utf8.encode('some label'), utf8.encode('some data'));

final cBytes =
mt.extractBytes(Uint8List.fromList(utf8.encode('challenge')), 32);
final cBytes = mt.extractBytes(utf8.encode('challenge'), 32);
final cHex = hex.encode(cBytes);

expect(cHex,
Expand All @@ -24,7 +22,7 @@ void main() {

final data = Uint8List(1024)..fillRange(0, 1024, 99);

late List<int> chlBytes;
late Uint8List chlBytes;
for (var i = 0; i < 32; i++) {
chlBytes = tr.extractBytes(utf8.encode('challenge'), 32);
tr
Expand Down

0 comments on commit 95162c7

Please sign in to comment.