Skip to content

Commit

Permalink
V3.0.0
Browse files Browse the repository at this point in the history
Added support for the Cardano network.
  • Loading branch information
mrtnetwork committed Mar 16, 2024
1 parent 762e656 commit 78f4118
Show file tree
Hide file tree
Showing 79 changed files with 333 additions and 118 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 3.0.0
- Added support for the Cardano network.


## 2.0.0
- Added support for the Solana network.

Expand Down
160 changes: 159 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,28 @@ Delve confidently into the Solana blockchain ecosystem with the Onchain Plugin f

- Custom Programs: The plugin facilitates the Solana Buffer layout structure, enabling effortless encoding and decoding of pertinent data

### Cardano

Dive confidently into the Cardano blockchain ecosystem with "on_chain" - your gateway to seamless integration with Cardano's powerful network. Empower your Dart applications to navigate the Cardano landscape with ease, from account creation to asset transfers and execution of a diverse range of smart contracts. Uncover the full potential of Cardano's network, harnessing its scalability and performance to drive innovation and growth in your projects. Explore the multitude of Cardano contracts, including smart contracts, and unlock new possibilities for your Dart applications to flourish within the dynamic Cardano blockchain ecosystem.

- Transaction: Generate and construct Cardano transactions across both the Byron and Shelley eras. Serialization, and Deserialization.

- Sign: Effortlessly Sign Transactions

- Addresses: Comprehensive address support, base, reward, pointer, enterprise, as well as both Byron and legacy Byron formats.

- HD-Wallet: Seed generator for legacy and Icarus formats, alongside HD wallet management for both Shelley and Byron era

- Transactions: The plugin boasts extensive support for a variety of Cardano transactions.
Here are some examples:

- Mint
- Plutus
- NativeScripts
- Certificate (Stake, Pool, MIR)
- Metadata
- Withdrawals

## EXAMPLES

### Key and addresses
Expand Down Expand Up @@ -144,6 +166,33 @@ Delve confidently into the Solana blockchain ecosystem with the Onchain Plugin f
/// Derive the Solana address associated with the public key.
final SolAddress solanaAddress = solanaPublicKey.toAddress();
/// Cardano
// Define a private key
final privateKey = AdaPrivateKey.fromBytes(...);
// Create a Byron address
final byronAddress =
ADAByronAddress.fromPublicKey(publicKey: ..., chaincode: ...);
// Generate a legacy Byron address
final byronLegacyAddress = ADAByronAddress.legacy(
publicKey: .., chaincode: .., hdPathKey:.., hdPath: '');
// Construct a Shelley base address
final shellyBase = ADABaseAddress(
"addr_test1qzkrh0ytcw257np6x6lxp74a6p4erj7rqt9azycnckgp2f27p5uc85frnln985tjn0xv8fmdv4t696d3j9zvu0ktx0gs62w8wv");
// Formulate a Shelley reward address
final shellyReward = ADARewardAddress("stake...");
// Create a Shelley pointer address
final shellyPointer = ADAPointerAddress.fromPublicKey(
pubkeyBytes: ...Bip32KholawMstKeyGeneratorConst.masterKeyHmacKey,
pointer: Pointer(slot: slot, txIndex: txIndex, certIndex: certIndex));
// Define an enterprise address
final enterpriseAddress = ADAEnterpriseAddress("...");
```
### Transaction
Expand Down Expand Up @@ -449,6 +498,66 @@ Delve confidently into the Solana blockchain ecosystem with the Onchain Plugin f
SolanaRPCSendTransaction(encodedTransaction: serializedTransaction));
```
- Cardano Transaction
Check out all the examples at the provided [link](https://github.com/mrtnetwork/On_chain/tree/main/example/lib/example/cardano).
Transfer ADA
```
/// Create a BIP32 derivation from a seed
final bip32 = CardanoIcarusBip32.fromSeed(List<int>.filled(20, 12));
/// Derive a spending key from the BIP32 derivation path
final spend = bip32.derivePath("1852'/1815'/0'/0/0");
/// Extract the private key from the spending key
final privateKey = AdaPrivateKey.fromBytes(spend.privateKey.raw);
/// Define the sender enterprise address
ADAEnterpriseAddress addr = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: ADANetwork.testnetPreprod);
/// Define the receiver enterprise address
ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: ADANetwork.testnetPreprod);
/// Set up the Blockfrost provider
final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
projectId: "preprodMVwzqm4PuBDBSfEULoMzoj5QZcy5o3z5"));
/// Define transaction inputs and outputs
final input = TransactionInput(
transactionId: TransactionHash.fromHex(
"6419830644a3310e8ddf55998154bd07afe9f4a73872b6dd4d39ac43ff59ad8c"),
index: 0);
final output = TransactionOutput(
address: receiver, amount: Value(coin: ADAHelper.toLovelaces("1")));
final change = TransactionOutput(
address: addr,
amount: Value(
coin: ADAHelper.toLovelaces("10000") - ADAHelper.toLovelaces("1.2")));
final fee = ADAHelper.toLovelaces("0.2");
/// Construct the transaction body
final body =
TransactionBody(inputs: [input], outputs: [change, output], fee: fee);
/// Create the ADA transaction with witness
final transaction = ADATransaction(
body: body,
witnessSet: TransactionWitnessSet(vKeys: [
privateKey.createSignatureWitness(body.toHash().data),
]));
/// Submit the transaction via Blockfrost provider
await provider.request(BlockfrostRequestSubmitTransaction(
transactionCborBytes: transaction.serialize()));
```
### EIP712
- EIP-712
Expand Down Expand Up @@ -646,7 +755,29 @@ Example:
account: SolAddress.unchecked(
"527pWSWfeQGLM7SoyVXjCRkrSZBtDkH6ShEBJB3nUDkA")));
```
- Cardano (blockfrost)
Discover the full spectrum of methods in the [link](https://github.com/mrtnetwork/On_chain/tree/main/lib/ada/src/provider/blockfrost/methods).
```
/// Set up the Blockfrost provider with the specified URL and project ID
final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
projectId: "preprodMVwzqm4PuBDBSfEULoMzoj5QZcy5o3z5"));
/// Retrieve UTXOs for a specific Cardano address
final List<ADAAccountUTXOResponse> accountUtxos = await provider.request(
BlockfrostRequestAddressUTXOs(ADAAddress.fromAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny")));
/// Fetch the latest epoch's protocol parameters
final ADAEpochParametersResponse protocolParams =
await provider.request(BlockfrostRequestLatestEpochProtocolParameters());
/// Get UTXOs associated with a specific transaction
final ADATransactionUTXOSResponse transaction = await provider.request(
BlockfrostRequestTransactionUTXOs(
"69edd1c1c4fdc282e3fe1d90f368a228d7702316dc33e494e5bee7db81d6183b"));
```
### BIP-39, Addresses, and HD Wallet Key Management Process
```
/// Generate a 12-word mnemonic phrase.
Expand Down Expand Up @@ -674,6 +805,33 @@ Example:
TronPrivateKey.fromBytes(tronDefaultPath.privateKey.raw);
final ethereumPrivateKey =
ETHPrivateKey.fromBytes(ethereumDefaultPath.privateKey.raw);


/// Cardano
/// Generate a mnemonic using 15 words
final mnemonic =
Bip39MnemonicGenerator().fromWordsNumber(Bip39WordsNum.wordsNum15);

/// Generate seeds for Cardano Icarus and legacy Byron wallets using the mnemonic
final seed = CardanoIcarusSeedGenerator(mnemonic.toStr()).generate();
final legacySeed =
CardanoByronLegacySeedGenerator(mnemonic.toStr()).generate();

/// Create a CIP-1852 object from the seed for Cardano Icarus
final cip1852 = Cip1852.fromSeed(seed, Cip1852Coins.cardanoIcarus);

/// Initialize Cardano Shelley from the CIP-1852 object
final shelly = CardanoShelley.fromCip1852Object(cip1852);

/// Extract private keys for payment and stake from the Shelley wallet
final payment = shelly.bip44.privateKey;
final stake = shelly.bip44Sk.privateKey;

/// Derive a BIP-44 wallet from the legacy seed for Cardano Byron Ledger
final bip44 = Bip44.fromSeed(legacySeed, Bip44Coins.cardanoByronLedger);

/// Create a Cardano Byron Legacy wallet from the legacy seed
final byron = CardanoByronLegacy.fromSeed(legacySeed);

```
Expand Down
5 changes: 5 additions & 0 deletions example/lib/example/cardano/provider_call_example.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ import 'package:on_chain/ada/ada.dart';
import 'provider_example/provider.dart';

void main() async {
/// Set up the Blockfrost provider with the specified URL and project ID
final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
projectId: "preprodMVwzqm4PuBDBSfEULoMzoj5QZcy5o3z5"));

/// Retrieve UTXOs for a specific Cardano address
final List<ADAAccountUTXOResponse> accountUtxos = await provider.request(
BlockfrostRequestAddressUTXOs(ADAAddress.fromAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny")));

/// Fetch the latest epoch's protocol parameters
final ADAEpochParametersResponse protocolParams =
await provider.request(BlockfrostRequestLatestEpochProtocolParameters());

/// Get UTXOs associated with a specific transaction
final ADATransactionUTXOSResponse transaction = await provider.request(
BlockfrostRequestTransactionUTXOs(
"69edd1c1c4fdc282e3fe1d90f368a228d7702316dc33e494e5bee7db81d6183b"));
Expand Down
13 changes: 13 additions & 0 deletions example/lib/example/cardano/shelly_1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,31 @@ import 'package:on_chain/ada/ada.dart';
import 'provider_example/provider.dart';

void main() async {
/// Create a BIP32 derivation from a seed
final bip32 = CardanoIcarusBip32.fromSeed(List<int>.filled(20, 12));

/// Derive a spending key from the BIP32 derivation path
final spend = bip32.derivePath("1852'/1815'/0'/0/0");

/// Extract the private key from the spending key
final privateKey = AdaPrivateKey.fromBytes(spend.privateKey.raw);

/// Define the sender enterprise address
ADAEnterpriseAddress addr = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: ADANetwork.testnetPreprod);

/// Define the receiver enterprise address
ADAEnterpriseAddress receiver = ADAEnterpriseAddress(
"addr_test1vp0q6wvr6y3elejn69efhnxr5akk24azaxcez3xw8m9n85gmr5qny",
network: ADANetwork.testnetPreprod);

/// Set up the Blockfrost provider
final provider = BlockforestProvider(BlockforestHTTPProvider(
url: "https://cardano-preprod.blockfrost.io/api/v0/",
projectId: "preprodMVwzqm4PuBDBSfEULoMzoj5QZcy5o3z5"));

/// Define transaction inputs and outputs
final input = TransactionInput(
transactionId: TransactionHash.fromHex(
"6419830644a3310e8ddf55998154bd07afe9f4a73872b6dd4d39ac43ff59ad8c"),
Expand All @@ -31,14 +40,18 @@ void main() async {
coin: ADAHelper.toLovelaces("10000") - ADAHelper.toLovelaces("1.2")));
final fee = ADAHelper.toLovelaces("0.2");

/// Construct the transaction body
final body =
TransactionBody(inputs: [input], outputs: [change, output], fee: fee);

/// Create the ADA transaction with witness
final transaction = ADATransaction(
body: body,
witnessSet: TransactionWitnessSet(vKeys: [
privateKey.createSignatureWitness(body.toHash().data),
]));

/// Submit the transaction via Blockfrost provider
await provider.request(BlockfrostRequestSubmitTransaction(
transactionCborBytes: transaction.serialize()));

Expand Down
3 changes: 1 addition & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ dependencies:
path: ../
web_socket_channel: ^2.4.0
http: ^1.1.0
blockchain_utils:
path: ../../blockchain_utils
blockchain_utils: ^2.1.0
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2
Expand Down
2 changes: 1 addition & 1 deletion lib/ada/ada.dart
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export 'src/ada.dart';
export 'src/ada.dart';
2 changes: 1 addition & 1 deletion lib/ada/src/ada.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export 'keypair/keypair.dart';
export 'models/ada_models.dart';
export 'provider/provider.dart';
export 'serialization/cbor_serialization.dart';
export 'utils/ada_helper.dart';
export 'utils/ada_helper.dart';
2 changes: 1 addition & 1 deletion lib/ada/src/address/era/core/address.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:on_chain/ada/src/address/era/byron/byron.dart';
import 'package:on_chain/ada/src/address/era/shelly/shelly.dart';
import 'package:on_chain/ada/src/address/utils/utils.dart';
import 'package:on_chain/ada/src/serialization/cbor_serialization.dart';

/// Represents an abstract class for ADA addresses with serialization capabilities.
abstract class ADAAddress with ADASerialization {
/// Abstract property representing the ADA network.
Expand Down Expand Up @@ -79,7 +80,6 @@ abstract class ADAAddress with ADASerialization {
return address;
}


/// Returns the string representation of the ADAAddress.
@override
String toString() {
Expand Down
2 changes: 1 addition & 1 deletion lib/ada/src/models/ada_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ export 'ex_units.dart';
export 'unit_interval.dart';
export 'utils.dart';
export 'header/header.dart';
export 'mint/mint.dart';
export 'mint/mint.dart';
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,4 @@ class MIRToStakeCredentials extends MIR {
entry.key.toJson(): entry.value.toString()
};
}


}
2 changes: 1 addition & 1 deletion lib/ada/src/models/data_options/data_option.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'data_option_data_hash.dart';
export 'plutus_data.dart';
export 'core/data_option.dart';
export 'core/data_option_type.dart';
export 'core/data_option_type.dart';
2 changes: 1 addition & 1 deletion lib/ada/src/models/fixed_bytes/fixed_bytes_model.dart
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export 'core/fixed_bytes.dart';
export 'models/models.dart';
export 'models/models.dart';
2 changes: 1 addition & 1 deletion lib/ada/src/models/header/header.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export 'header/header.dart';
export 'header/header_body.dart';
export 'header/operational_cert.dart';
export 'header/protocol_version.dart';
export 'header/vrf_cert.dart';
export 'header/vrf_cert.dart';
2 changes: 1 addition & 1 deletion lib/ada/src/models/plutus/plutus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export 'cost_model/cost.dart';
export 'cost_model/cost_model.dart';
export 'plutus/plutus.dart';
export 'plutus_script/plutus_script.dart';
export 'utils/utils.dart';
export 'utils/utils.dart';
2 changes: 1 addition & 1 deletion lib/ada/src/models/plutus/plutus_script/plutus_script.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export 'language/language.dart';
export 'redeemer_tag/redeemer.dart';
export 'redeemer_tag/redeemer_tag.dart';
export 'script/plutus_script.dart';
export 'script/plutus_script.dart';
1 change: 0 additions & 1 deletion lib/ada/src/models/plutus/utils/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ class PlutusDataUtils {

static PlutusData parsePlutus(dynamic value, PlutusJsonSchema schame) {
_validateType(value);
print("schame $schame ${value is Map}");
if (schame == PlutusJsonSchema.basicConversions) {
if (value is int || value is BigInt) {
return _encodeNumbers(value);
Expand Down
2 changes: 1 addition & 1 deletion lib/ada/src/models/transaction/output/output.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export 'models/assets.dart';
export 'models/multi_assets.dart';
export 'models/transaction_output.dart';
export 'models/value.dart';
export 'script_ref/scripts.dart';
export 'script_ref/scripts.dart';
2 changes: 1 addition & 1 deletion lib/ada/src/models/transaction/transaction.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export 'output/output.dart';
export 'transaction/auxiliary_data.dart';
export 'transaction/body.dart';
export 'transaction/transaction.dart';
export 'witnesses/witnesses.dart';
export 'witnesses/witnesses.dart';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'package:blockchain_utils/cbor/cbor.dart';
import 'package:on_chain/ada/src/models/plutus/plutus/plutus.dart';
import 'package:on_chain/ada/src/serialization/cbor_serialization.dart';
import 'package:on_chain/ada/src/models/plutus/plutus/types/list.dart';
import 'package:on_chain/ada/src/models/plutus/plutus_script/language/language.dart';
import 'package:on_chain/ada/src/models/native_script/core/native_script.dart';
import 'package:on_chain/ada/src/models/plutus/plutus_script/redeemer_tag/redeemer.dart';
Expand Down
2 changes: 1 addition & 1 deletion lib/ada/src/models/transaction/witnesses/witnesses.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export 'bootstrap_witness.dart';
export 'transaction_witness_set.dart';
export 'vkey_witness.dart';
export 'vkey_witness.dart';
Loading

0 comments on commit 78f4118

Please sign in to comment.