Skip to content

Commit

Permalink
migrated to pointycastle
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenroose committed Apr 12, 2016
1 parent 2cdadfb commit be1a370
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 45 deletions.
20 changes: 9 additions & 11 deletions lib/core.dart
Expand Up @@ -15,17 +15,15 @@ import "package:enums/enums.dart";
import "package:stevenroose/byte_sink.dart";

// cherry picking cipher dependencies
import "package:cipher/api.dart";
import "package:cipher/digests/ripemd160.dart";
import "package:cipher/params/key_parameter.dart";
import "package:cipher/params/asymmetric_key_parameter.dart";
import "package:cipher/ecc/ecc_base.dart";
import "package:cipher/ecc/ecc_fp.dart" as fp;
import "package:cipher/api/ecc.dart";
import "package:cipher/signers/ecdsa_signer.dart";
import "package:cipher/digests/sha256.dart";
import "package:cipher/macs/hmac.dart";
import "package:cipher/digests/sha512.dart";
import "package:pointycastle/api.dart";
import "package:pointycastle/digests/ripemd160.dart";
import "package:pointycastle/ecc/ecc_base.dart";
import "package:pointycastle/ecc/ecc_fp.dart" as fp;
import "package:pointycastle/ecc/api.dart";
import "package:pointycastle/signers/ecdsa_signer.dart";
import "package:pointycastle/digests/sha256.dart";
import "package:pointycastle/macs/hmac.dart";
import "package:pointycastle/digests/sha512.dart";


part "src/core/ripple_encoding.dart";
Expand Down
2 changes: 1 addition & 1 deletion lib/ripplelib.dart
Expand Up @@ -2,5 +2,5 @@ library ripplelib;

export "core.dart";
export "json.dart";
export 'remote.dart';
export "remote.dart";

17 changes: 8 additions & 9 deletions lib/src/client/account.dart
Expand Up @@ -184,7 +184,7 @@ class Account extends Object with Events {
_key = key;
}

Future<Response> submitTransaction(Transaction tx, {KeyPair key}) {
Future<Response> submitTransaction(Transaction tx, {KeyPair key}) async {
KeyPair useKey;
if(key != null) {
if(key.account == id) {
Expand All @@ -197,14 +197,13 @@ class Account extends Object with Events {
} else {
throw new StateError("Cannot make transactions without private key");
}
return _remote.ensureUpdatedServerInfo().then((info) {
tx.account = id;
tx.sequence = _root.sequence + 1;
tx.fee = _remote.computeTxFee(tx);
tx.sign(useKey);
log.fine("Submitting transaction for $id: $tx");
return _remote.requestSubmitRaw(tx.toBytes());
});
await _remote.ensureUpdatedServerInfo();
tx.account = id;
tx.sequence = _root.sequence + 1;
tx.fee = _remote.computeTxFee(tx);
tx.sign(useKey);
log.fine("Submitting transaction for $id: $tx");
return _remote.requestSubmitRaw(tx.toBytes());
}

PaymentProcess startPayment(AccountID destination, Amount amount) =>
Expand Down
1 change: 1 addition & 0 deletions lib/src/client/payment_process.dart
Expand Up @@ -27,6 +27,7 @@ class PaymentProcess implements Stream<PaymentOption> {
Future<Response> _finish(PathFindStatus status, Path preference, KeyPair key) {
List<Path> finalPaths = preference != null ? [preference] : status.paths;
Payment payment = new Payment(destination, amount, paths: finalPaths);//TODO specify sendMax?
// TODO sign
return _account.submitTransaction(payment, key: key).then((Response response) {
if(response.successful) {
cancel();
Expand Down
30 changes: 24 additions & 6 deletions lib/src/client/remote.dart
Expand Up @@ -259,11 +259,21 @@ class Remote extends Object with Events {
return req;
}

Future<Response> requestAccountTransactions(dynamic account, {int minLedgerIndex, int maxLedgerIndex, int limit, bool binary, bool forward}) =>
Future<Response> requestAccountTransactions(dynamic account,
{ int minLedgerIndex,
int maxLedgerIndex,
int limit,
bool binary,
bool forward}) =>
makeAccountTransactionsRequest(account, minLedgerIndex: minLedgerIndex, maxLedgerIndex: maxLedgerIndex, limit: limit,
binary: binary, forward: forward).request();

Request makeAccountTransactionsRequest(dynamic account, {int minLedgerIndex, int maxLedgerIndex, int limit, bool binary, bool forward}) {
Request makeAccountTransactionsRequest(dynamic account,
{ int minLedgerIndex,
int maxLedgerIndex,
int limit,
bool binary,
bool forward}) {
Request req = newRequest(Command.ACCOUNT_TX);
req.account = account;
if(limit != null)
Expand All @@ -279,10 +289,18 @@ class Remote extends Object with Events {
return req;
}

Future<Response> requestBookOffers(Issue takerPays, Issue takerGets, {AccountID taker, LedgerSelector ledger, int limit, bool proof}) =>
Future<Response> requestBookOffers(Issue takerPays, Issue takerGets,
{ AccountID taker,
LedgerSelector ledger,
int limit,
bool proof}) =>
makeBookOffersRequest(takerPays, takerGets, taker: taker, ledger: ledger, limit: limit, proof: proof).request();

Request makeBookOffersRequest(Issue takerPays, Issue takerGets, {AccountID taker, LedgerSelector ledger, int limit, bool proof}) {
Request makeBookOffersRequest(Issue takerPays, Issue takerGets,
{ AccountID taker,
LedgerSelector ledger,
int limit,
bool proof}) {
Request req = newRequest(Command.BOOK_OFFERS);
req.taker_pays = takerPays;
req.taker_gets = takerGets;
Expand Down Expand Up @@ -409,8 +427,8 @@ class Remote extends Object with Events {
{List<Issue> currencies, LedgerSelector ledger}) =>
makeRipplePathFindRequest(sourceAccount, destinationAccount, amount, currencies, ledger: ledger).request();

Request makeRipplePathFindRequest(AccountID sourceAccount, AccountID destinationAccount, Amount amount, List<Issue> currencies,
{LedgerSelector ledger}) {
Request makeRipplePathFindRequest(AccountID sourceAccount, AccountID destinationAccount, Amount amount,
List<Issue> currencies, {LedgerSelector ledger}) {
Request req = newRequest(Command.RIPPLE_PATH_FIND);
req.source_account = sourceAccount;
req.destination_account = destinationAccount;
Expand Down
7 changes: 7 additions & 0 deletions lib/src/core/flags.dart
Expand Up @@ -10,6 +10,13 @@ class Flags {

final int value;

factory Flags(int value) {
if(value != value & 0xffffffff) {
throw new ArgumentError("Flags are 32-bit positive values.");
}
return new Flags._internal(value);
}

const Flags._internal(this.value);

@override
Expand Down
12 changes: 2 additions & 10 deletions lib/src/core/offer.dart
Expand Up @@ -2,7 +2,7 @@ part of ripplelib.core;



class Offer extends Offer {
class Offer {

Amount takerGets;
Amount takerPays;
Expand All @@ -18,7 +18,7 @@ class Offer extends Offer {
takerPays = json["taker_pays"];
account = json["account"];
sequence = json["seq"];
flags = new Flags(json["flags"]);
flags = json["flags"] != null ? new Flags(json["flags"]) : null;
}

dynamic toJson() => {
Expand All @@ -29,12 +29,4 @@ class Offer extends Offer {
"account": account
};

Amount get takerGets => takerGets;
Amount get takerPays => takerPays;

int get sequence => sequence;
Flags get flags => flags;

AccountID get account => account;

}
13 changes: 6 additions & 7 deletions pubspec.yaml
Expand Up @@ -4,19 +4,18 @@ author: Steven Roose <stevenroose@gmail.com>
description: The Ripple library for Dart.
homepage: https://github.com/stevenroose/ripple-lib-dart
dependencies:
asn1lib: any
bignum: any
asn1lib: '>=0.4.1'
bignum: '>=0.1.0'
browser: any
cipher: any
pointycastle: '>=0.10.0+1'
collection: any
cryptoutils: '>=0.1.9'
cryptoutils: '>=0.2.1'
crypto: any
decimal: '>=0.1.3'
enums: '>=0.2.3'
events: '>=0.1.0'
json_object:
git: https://github.com/stevenroose/dartwatch-JsonObject
logging: '>=0.9.2 <0.10.0'
json_object: '>=1.0.19'
logging: '>=0.11.2 <1.0.0'
stevenroose: '>=0.1.0'
websockets: '>=0.1.1'
dev_dependencies:
Expand Down
2 changes: 1 addition & 1 deletion test/remote/remote_requests.dart
Expand Up @@ -57,7 +57,7 @@ Future main() async {
});
test("requestAccountOffers", () {
expect(remote.requestAccountOffers(me).then((response) {
expect(response.result.offers[0].taker_pays.issuer.address, isNotNull);
expect(response.result.offers[0].takerPays.issuer.address, isNotNull);
}), completes);
});
test("requestAccountTransactions", () {
Expand Down

0 comments on commit be1a370

Please sign in to comment.