Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
0b3ed79
feat: encoding & decoding
Sep 13, 2023
1f48611
feat: silent address key pair derivation & tests
Sep 21, 2023
c112ac1
feat: add utils functions & tests
Sep 21, 2023
0c41f86
refactor: create SilentPayment address classes
Sep 22, 2023
bf4b6fb
feat: silent payment output creation
Sep 22, 2023
61543de
chore: coinlib dependency
Sep 22, 2023
acd57ba
fix: missing endian int extension
Sep 22, 2023
bbccf3b
feat: implements scanning outputs, labels, changes and improvements t…
Oct 6, 2023
6174b47
build: libsecp256k1.so
Oct 6, 2023
bbbecd2
refactor: shorten dependencies, depend only dart-elliptic
Nov 13, 2023
435cf7e
chore: remove unneeded changes
Nov 13, 2023
c7e6cf3
feat: bitcoin_base changes
Nov 14, 2023
58ae91a
feat: more p2tr changes, consolidate deps
Nov 15, 2023
7740d09
feat: p2tr, bech32m
Nov 17, 2023
c96f9d5
feat: p2tr spend, schnorr sigs
Nov 18, 2023
7fc1135
fix: p2wpkh sig
Nov 19, 2023
1b0172a
feat: clean up code, use fixtures for tests
Nov 28, 2023
4b41691
feat: schnorr sign
Nov 28, 2023
5f8f3d4
refactor: merge NetworkInfo into NetworkType
Nov 28, 2023
6528ffb
refactor: address to script improvements, p2tr address test cases
Nov 28, 2023
18dc839
chore: clean up
Nov 28, 2023
bfea3b5
feat: add addres type labels
Nov 29, 2023
bee138e
chore: export AddressType
Nov 29, 2023
cd08de5
feat: rename labels
Nov 29, 2023
63f314f
feat: export other addr types
Nov 29, 2023
58d7856
feat: add regex type
Nov 29, 2023
28168b4
fix: taproot address from pubkey, taproot spends
Nov 30, 2023
d4f4f97
feat: silent payment address REGEX
Nov 30, 2023
55aae88
fix: unintended backslash
Nov 30, 2023
6c6d1e9
feat: also handle empty label map case
Dec 6, 2023
f3855ad
fix: labeled scanning
Dec 6, 2023
f1d844d
feat: add fallback mechanism to keep checking if label tweaks match
Dec 6, 2023
104df1a
feat: modify a bit scan function return type to include label tweak
Dec 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/bitcoin_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,24 @@ export 'src/transaction.dart';
export 'src/address.dart';
export 'src/transaction_builder.dart';
export 'src/ecpair.dart';
export 'src/ec/ec_public.dart';
export 'src/ec/ec_encryption.dart';
export 'src/payments/p2pkh.dart';
export 'src/payments/p2wpkh.dart';
export 'src/payments/index.dart';
export 'src/payments/scanning.dart';
export 'src/payments/address/core.dart' show AddressType;
export 'src/payments/address/address.dart' show P2shAddress, P2pkhAddress;
export 'src/payments/address/segwit_address.dart' show P2wpkhAddress, P2trAddress;
export 'src/payments/script/script.dart';
export 'src/templates/silentpaymentaddress.dart';
export 'src/templates/outpoint.dart';
export 'src/payments/silentpayments.dart';
export 'src/utils/keys.dart';
export 'src/utils/uint8list.dart';
export 'src/utils/string.dart';
export 'src/formatting/bytes_num_formatting.dart';
export 'src/classify.dart';
export 'package:bech32/bech32.dart';
export 'package:elliptic/elliptic.dart';
// TODO: Export any libraries intended for clients of this package.
48 changes: 19 additions & 29 deletions lib/src/address.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import 'dart:typed_data';

import 'models/networks.dart';
import 'package:bs58check/bs58check.dart' as bs58check;
import 'package:bech32/bech32.dart';
import 'payments/index.dart' show PaymentData;
import 'payments/p2pkh.dart';
import 'payments/p2wpkh.dart';
import 'payments/address/address.dart';
import 'payments/address/segwit_address.dart';

class Address {
static bool validateAddress(String address, [NetworkType? nw]) {
Expand All @@ -18,31 +16,23 @@ class Address {

static Uint8List addressToOutputScript(String address, [NetworkType? nw]) {
NetworkType network = nw ?? bitcoin;
var decodeBase58;
var decodeBech32;
try {
decodeBase58 = bs58check.decode(address);
} catch (err) {}
if (decodeBase58 != null) {
if (decodeBase58[0] != network.pubKeyHash)
throw new ArgumentError('Invalid version or Network mismatch');
P2PKH p2pkh =
new P2PKH(data: new PaymentData(address: address), network: network);
return p2pkh.data.output!;
} else {
try {
decodeBech32 = segwit.decode(address);
} catch (err) {}
if (decodeBech32 != null) {
if (network.bech32 != decodeBech32.hrp)
throw new ArgumentError('Invalid prefix or Network mismatch');
if (decodeBech32.version != 0)
throw new ArgumentError('Invalid address version');
P2WPKH p2wpkh = new P2WPKH(
data: new PaymentData(address: address), network: network);
return p2wpkh.data.output!;
}

if (P2pkhAddress.REGEX.hasMatch(address)) {
return P2pkhAddress(address: address, network: network).toScriptPubKey().toBytes();
}

if (P2shAddress.REGEX.hasMatch(address)) {
return P2shAddress(address: address, network: network).toScriptPubKey().toBytes();
}

if (P2wpkhAddress.REGEX.hasMatch(address)) {
return P2wpkhAddress(address: address, network: network).toScriptPubKey().toBytes();
}

if (P2trAddress.REGEX.hasMatch(address)) {
return P2trAddress(address: address, network: network).toScriptPubKey().toBytes();
}

throw new ArgumentError(address + ' has no matching Script');
}
}
2 changes: 2 additions & 0 deletions lib/src/classify.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ const SCRIPT_TYPES = {
'P2PKH': 'pubkeyhash',
'P2SH': 'scripthash',
'P2WPKH': 'witnesspubkeyhash',
'P2TR': 'taproot',
'P2WSH': 'witnessscripthash',
'WITNESS_COMMITMENT': 'witnesscommitment'
};

String classifyOutput(Uint8List script) {
if (witnessPubKeyHash.outputCheck(script)) return SCRIPT_TYPES['P2WPKH']!;
if (witnessPubKeyHash.taprootOutputCheck(script)) return SCRIPT_TYPES['P2TR']!;
if (pubkeyhash.outputCheck(script)) return SCRIPT_TYPES['P2PKH']!;
final chunks = bscript.decompile(script);
if (chunks == null) throw new ArgumentError('Invalid script');
Expand Down
29 changes: 29 additions & 0 deletions lib/src/crypto.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,32 @@ Uint8List hash256(Uint8List buffer) {
Uint8List _tmp = new SHA256Digest().process(buffer);
return new SHA256Digest().process(_tmp);
}

/// Function: singleHash
/// Description: Computes a single SHA-256 hash of the input data.
/// Input: Uint8List buffer - The data to be hashed.
/// Output: Uint8List - The resulting single SHA-256 hash.
/// Note: This function calculates a single SHA-256 hash of the input data.
Uint8List singleHash(Uint8List buffer) {
/// Compute a single SHA-256 hash of the input data.
return SHA256Digest().process(buffer);
}

/// Function: taggedHash
/// Description: Computes a tagged hash of the input data with a provided tag.
/// Input:
/// - Uint8List data - The data to be hashed.
/// - String tag - A unique tag to differentiate the hash.
/// Output: Uint8List - The resulting tagged hash.
/// Note: This function combines the provided tag with the input data to create a unique
/// hash by applying a double SHA-256 hash.
Uint8List taggedHash(Uint8List data, String tag) {
/// Calculate the hash of the tag as Uint8List.
final tagDigest = singleHash(Uint8List.fromList(tag.codeUnits));

/// Concatenate the tag hash with itself and the input data.
final concat = Uint8List.fromList([...tagDigest, ...tagDigest, ...data]);

/// Compute a double SHA-256 hash of the concatenated data.
return singleHash(concat);
}
Loading