├── .nvmrc ├── doc ├── .gitignore ├── .sphinx │ ├── cardano-logo.png │ ├── _templates │ │ └── layout.html │ └── requirements.txt ├── getting-started │ └── prerequisite-knowledge.md └── index.rst ├── example ├── .prettierignore ├── .nvmrc ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ └── manifest.json ├── src │ ├── utils │ │ ├── connectionStates.ts │ │ ├── helpers.ts │ │ └── networkConfig.ts │ ├── components-ui │ │ ├── WalletConnector.css │ │ └── AddressGenerator.tsx │ ├── index.css │ ├── index.tsx │ └── components-logic │ │ └── AddressGenerator.ts ├── .prettierrc ├── .gitignore ├── craco.config.js ├── tsconfig.json ├── package.json └── README.md ├── templates ├── react-asmjs │ ├── .nvmrc │ ├── public │ │ ├── robots.txt │ │ ├── favicon.ico │ │ ├── logo192.png │ │ ├── logo512.png │ │ └── manifest.json │ ├── src │ │ ├── setupTests.js │ │ ├── App.test.js │ │ ├── index.css │ │ ├── reportWebVitals.js │ │ ├── index.js │ │ └── App.css │ ├── .gitignore │ └── package.json ├── angular-asmjs │ ├── .nvmrc │ ├── src │ │ ├── assets │ │ │ └── .gitkeep │ │ ├── app │ │ │ ├── app.component.css │ │ │ ├── csl-example │ │ │ │ ├── csl-example.component.css │ │ │ │ ├── csl-example.component.spec.ts │ │ │ │ ├── csl-example.component.html │ │ │ │ └── csl-example.component.ts │ │ │ ├── app.component.ts │ │ │ ├── app.module.ts │ │ │ └── app.component.spec.ts │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── styles.css │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── main.ts │ │ └── test.ts │ ├── .editorconfig │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ ├── .browserslistrc │ ├── .gitignore │ ├── tsconfig.json │ ├── README.md │ ├── package.json │ └── karma.conf.js ├── angular-browser │ ├── .nvmrc │ ├── src │ │ ├── assets │ │ │ └── .gitkeep │ │ ├── app │ │ │ ├── app.component.css │ │ │ ├── csl-example │ │ │ │ ├── csl-example.component.css │ │ │ │ ├── csl-example.component.spec.ts │ │ │ │ ├── csl-example.component.html │ │ │ │ └── csl-example.component.ts │ │ │ ├── app.component.ts │ │ │ ├── app.module.ts │ │ │ └── app.component.spec.ts │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── styles.css │ │ ├── favicon.ico │ │ ├── index.html │ │ ├── main.ts │ │ └── test.ts │ ├── .editorconfig │ ├── tsconfig.app.json │ ├── tsconfig.spec.json │ ├── .browserslistrc │ ├── .gitignore │ ├── tsconfig.json │ ├── README.md │ ├── package.json │ └── karma.conf.js └── react-browser │ ├── .nvmrc │ ├── public │ ├── robots.txt │ ├── favicon.ico │ ├── logo192.png │ ├── logo512.png │ └── manifest.json │ ├── src │ ├── setupTests.js │ ├── App.test.js │ ├── index.css │ ├── reportWebVitals.js │ ├── index.js │ └── App.css │ ├── .gitignore │ ├── config-overrides.js │ └── package.json ├── test.sh ├── rust ├── src │ ├── impl_mockchain │ │ └── mod.rs │ ├── serialization │ │ ├── ser_info │ │ │ ├── mod.rs │ │ │ └── types.rs │ │ ├── numeric │ │ │ ├── mod.rs │ │ │ ├── big_num.rs │ │ │ └── int.rs │ │ ├── crypto │ │ │ ├── mod.rs │ │ │ ├── vkey.rs │ │ │ ├── kes_signature.rs │ │ │ └── vkeys.rs │ │ ├── governance │ │ │ ├── mod.rs │ │ │ ├── proposals │ │ │ │ ├── mod.rs │ │ │ │ ├── constitution.rs │ │ │ │ ├── info_action.rs │ │ │ │ ├── no_confidence_action.rs │ │ │ │ ├── voting_proposal.rs │ │ │ │ └── voting_proposals.rs │ │ │ └── anchor.rs │ │ ├── witnesses │ │ │ ├── mod.rs │ │ │ ├── fixed_tx_witnesses_set.rs │ │ │ └── transaction_witnesses_sets.rs │ │ ├── block │ │ │ ├── mod.rs │ │ │ ├── fixed_versioned_block.rs │ │ │ ├── fixed_transaction_body.rs │ │ │ ├── fixed_transaction_bodies.rs │ │ │ ├── versioned_block.rs │ │ │ └── transaction_bodies.rs │ │ ├── plutus │ │ │ ├── mod.rs │ │ │ ├── plutus_script.rs │ │ │ ├── language.rs │ │ │ ├── strings.rs │ │ │ ├── languages.rs │ │ │ ├── cost_model.rs │ │ │ ├── ex_units.rs │ │ │ ├── ex_unit_prices.rs │ │ │ └── cost_models.rs │ │ ├── map_names │ │ │ ├── mod.rs │ │ │ ├── witness_set_names.rs │ │ │ ├── voting_proposal_index_names.rs │ │ │ ├── tx_body_names.rs │ │ │ └── certificate_index_names.rs │ │ ├── mod.rs │ │ ├── certificates │ │ │ ├── mod.rs │ │ │ ├── certificates_collection.rs │ │ │ ├── vote_delegation.rs │ │ │ └── drep_deregistration.rs │ │ ├── credentials.rs │ │ ├── ed25519_key_hashes.rs │ │ └── tx_inputs.rs │ ├── tests │ │ ├── protocol_types │ │ │ ├── governance │ │ │ │ └── mod.rs │ │ │ └── mod.rs │ │ ├── serialization │ │ │ ├── governance │ │ │ │ └── mod.rs │ │ │ └── mod.rs │ │ ├── helpers.rs │ │ ├── builders │ │ │ └── mod.rs │ │ ├── mod.rs │ │ └── emip3.rs │ ├── protocol_types │ │ ├── crypto │ │ │ ├── macro_implemented_signature_types.rs │ │ │ ├── vkey.rs │ │ │ ├── vkeys.rs │ │ │ ├── public_keys.rs │ │ │ ├── mod.rs │ │ │ ├── legacy_daedalus_private_key.rs │ │ │ ├── macro_implemented_hash_types.rs │ │ │ ├── vrf_cert.rs │ │ │ └── nonce.rs │ │ ├── numeric │ │ │ └── mod.rs │ │ ├── governance │ │ │ ├── proposals │ │ │ │ ├── info_action.rs │ │ │ │ ├── mod.rs │ │ │ │ ├── no_confidence_action.rs │ │ │ │ ├── treasury_withdrawals.rs │ │ │ │ ├── constitution.rs │ │ │ │ ├── hard_fork_initiation_action.rs │ │ │ │ ├── treasury_withdrawals_action.rs │ │ │ │ ├── new_constitution_action.rs │ │ │ │ └── update_committee_action.rs │ │ │ ├── mod.rs │ │ │ ├── voters.rs │ │ │ ├── governance_action_ids.rs │ │ │ ├── anchor.rs │ │ │ ├── governance_action_id.rs │ │ │ └── voting_procedure.rs │ │ ├── witnesses │ │ │ ├── mod.rs │ │ │ ├── transaction_witnesses_sets.rs │ │ │ ├── vkeywitness.rs │ │ │ └── bootstrap_witness.rs │ │ ├── plutus │ │ │ ├── strings.rs │ │ │ ├── mod.rs │ │ │ ├── languages.rs │ │ │ ├── ex_units.rs │ │ │ ├── ex_unit_prices.rs │ │ │ ├── redeemer_tag.rs │ │ │ └── language.rs │ │ ├── block │ │ │ ├── mod.rs │ │ │ ├── transaction_bodies.rs │ │ │ ├── fixed_transaction_bodies.rs │ │ │ ├── header.rs │ │ │ ├── fixed_tx_body.rs │ │ │ ├── fixed_versioned_block.rs │ │ │ ├── operational_cert.rs │ │ │ ├── versioned_block.rs │ │ │ └── fixed_block.rs │ │ ├── certificates │ │ │ ├── pool_retirement.rs │ │ │ ├── vote_delegation.rs │ │ │ ├── drep_deregistration.rs │ │ │ ├── stake_delegation.rs │ │ │ ├── committee_hot_auth.rs │ │ │ ├── vote_registration_and_delegation.rs │ │ │ ├── drep_update.rs │ │ │ ├── stake_registration.rs │ │ │ ├── stake_deregistration.rs │ │ │ ├── stake_and_vote_delegation.rs │ │ │ ├── genesis_key_delegation.rs │ │ │ ├── stake_registration_and_delegation.rs │ │ │ ├── committee_cold_resign.rs │ │ │ ├── mod.rs │ │ │ ├── drep_registration.rs │ │ │ └── stake_vote_registration_and_delegation.rs │ │ ├── tx_input.rs │ │ └── mod.rs │ ├── legacy_address │ │ └── mod.rs │ ├── builders │ │ ├── batch_tools │ │ │ ├── mod.rs │ │ │ └── indexes.rs │ │ ├── script_structs │ │ │ ├── mod.rs │ │ │ ├── datum_source.rs │ │ │ └── plutus_script_ref.rs │ │ └── mod.rs │ ├── chain_core │ │ └── mod.rs │ ├── chain_crypto │ │ ├── algorithms │ │ │ └── mod.rs │ │ ├── mod.rs │ │ └── derive.rs │ ├── crypto.rs │ └── traits.rs ├── bench │ ├── benches │ │ ├── benches_main.rs │ │ ├── data │ │ │ └── block_with_certs.bin │ │ └── block_bench.rs │ └── Cargo.toml └── json-gen │ └── Cargo.toml ├── test ├── 1.cbor └── 1.diag ├── .gitmodules ├── tools └── metadata-cddl-checker │ └── Cargo.toml ├── scripts ├── .eslintrc.js ├── wasm-to-asm.js ├── fix-buffer-ref.js └── json-ts-types.js ├── .gitignore ├── .readthedocs.yml ├── sonar-project.properties ├── specs └── README.md ├── .github ├── dependabot.yml └── workflows │ ├── _sonarqube.yml_ │ └── gh-issue-to-jira-task.yml ├── release.sh ├── LICENSE-IOHK ├── LICENSE └── README.md /.nvmrc: -------------------------------------------------------------------------------- 1 | v18 2 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | _build/ -------------------------------------------------------------------------------- /example/.prettierignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /example/.nvmrc: -------------------------------------------------------------------------------- 1 | v22.14.0 2 | -------------------------------------------------------------------------------- /templates/react-asmjs/.nvmrc: -------------------------------------------------------------------------------- 1 | v17.9 2 | -------------------------------------------------------------------------------- /templates/angular-asmjs/.nvmrc: -------------------------------------------------------------------------------- 1 | v16.10 2 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templates/angular-browser/.nvmrc: -------------------------------------------------------------------------------- 1 | v16.10 2 | -------------------------------------------------------------------------------- /templates/react-browser/.nvmrc: -------------------------------------------------------------------------------- 1 | v17.9 2 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | nvm i && npm i && npm run rust:test -------------------------------------------------------------------------------- /rust/src/impl_mockchain/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod key; 2 | -------------------------------------------------------------------------------- /templates/angular-browser/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templates/angular-browser/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/csl-example/csl-example.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /templates/angular-browser/src/app/csl-example/csl-example.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /rust/src/serialization/ser_info/mod.rs: -------------------------------------------------------------------------------- 1 | mod types; 2 | pub use types::*; 3 | -------------------------------------------------------------------------------- /rust/src/serialization/numeric/mod.rs: -------------------------------------------------------------------------------- 1 | mod int; 2 | mod big_int; 3 | mod big_num; -------------------------------------------------------------------------------- /rust/src/tests/protocol_types/governance/mod.rs: -------------------------------------------------------------------------------- 1 | mod common; 2 | mod proposals; 3 | -------------------------------------------------------------------------------- /rust/src/tests/serialization/governance/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod common; 2 | pub mod proposals; 3 | -------------------------------------------------------------------------------- /test/1.cbor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/test/1.cbor -------------------------------------------------------------------------------- /example/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /rust/src/tests/helpers.rs: -------------------------------------------------------------------------------- 1 | pub(crate) fn harden(index: u32) -> u32 { 2 | index | 0x80_00_00_00 3 | } 4 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "binaryen"] 2 | path = binaryen 3 | url = https://github.com/WebAssembly/binaryen.git 4 | -------------------------------------------------------------------------------- /rust/src/serialization/crypto/mod.rs: -------------------------------------------------------------------------------- 1 | mod vkey; 2 | mod vkeys; 3 | mod kes_signature; 4 | mod nonce; 5 | mod vrf_cert; -------------------------------------------------------------------------------- /templates/react-asmjs/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /example/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/example/public/favicon.ico -------------------------------------------------------------------------------- /example/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/example/public/logo192.png -------------------------------------------------------------------------------- /example/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/example/public/logo512.png -------------------------------------------------------------------------------- /templates/angular-asmjs/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /templates/react-browser/public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /doc/.sphinx/cardano-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/doc/.sphinx/cardano-logo.png -------------------------------------------------------------------------------- /templates/angular-browser/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /templates/angular-browser/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /rust/src/tests/protocol_types/mod.rs: -------------------------------------------------------------------------------- 1 | mod certificates; 2 | mod fixed_tx; 3 | mod governance; 4 | mod protocol_param_update; 5 | mod fixed_block; 6 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/angular-asmjs/src/favicon.ico -------------------------------------------------------------------------------- /templates/react-asmjs/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/react-asmjs/public/favicon.ico -------------------------------------------------------------------------------- /templates/react-asmjs/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/react-asmjs/public/logo192.png -------------------------------------------------------------------------------- /templates/react-asmjs/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/react-asmjs/public/logo512.png -------------------------------------------------------------------------------- /rust/bench/benches/benches_main.rs: -------------------------------------------------------------------------------- 1 | use criterion::criterion_main; 2 | 3 | mod block_bench; 4 | 5 | criterion_main! { 6 | block_bench::benches 7 | } -------------------------------------------------------------------------------- /templates/angular-browser/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/angular-browser/src/favicon.ico -------------------------------------------------------------------------------- /templates/react-browser/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/react-browser/public/favicon.ico -------------------------------------------------------------------------------- /templates/react-browser/public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/react-browser/public/logo192.png -------------------------------------------------------------------------------- /templates/react-browser/public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/templates/react-browser/public/logo512.png -------------------------------------------------------------------------------- /rust/bench/benches/data/block_with_certs.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Emurgo/cardano-serialization-lib/HEAD/rust/bench/benches/data/block_with_certs.bin -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/macro_implemented_signature_types.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | impl_signature!(Ed25519Signature, Vec, chain_crypto::Ed25519); -------------------------------------------------------------------------------- /rust/src/protocol_types/numeric/mod.rs: -------------------------------------------------------------------------------- 1 | mod big_int; 2 | pub use big_int::*; 3 | 4 | mod int; 5 | pub use int::*; 6 | 7 | mod big_num; 8 | pub use big_num::*; -------------------------------------------------------------------------------- /example/src/utils/connectionStates.ts: -------------------------------------------------------------------------------- 1 | export const NO_CARDANO = 0; 2 | export const NOT_CONNECTED = 1; 3 | export const IN_PROGRESS = 2; 4 | export const CONNECTED = 3; 5 | -------------------------------------------------------------------------------- /rust/src/tests/serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod certificates; 2 | pub mod governance; 3 | pub mod transaction_body; 4 | pub mod protocol_param_update; 5 | pub mod general; 6 | -------------------------------------------------------------------------------- /tools/metadata-cddl-checker/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "metadata-cddl-checker" 3 | version = "0.1.0" 4 | edition = "2018" 5 | 6 | [dependencies] 7 | cddl = "0.5.2" 8 | -------------------------------------------------------------------------------- /rust/src/serialization/governance/mod.rs: -------------------------------------------------------------------------------- 1 | mod drep; 2 | mod anchor; 3 | mod voter; 4 | mod voting_procedure; 5 | mod voting_procedures; 6 | mod governance_action_id; 7 | mod proposals; -------------------------------------------------------------------------------- /doc/.sphinx/_templates/layout.html: -------------------------------------------------------------------------------- 1 | {% extends "!layout.html" %} 2 | 3 | {% block footer %} 4 | {{ super() }} 5 | 7 | {% endblock %} -------------------------------------------------------------------------------- /scripts/.eslintrc.js: -------------------------------------------------------------------------------- 1 | { 2 | "parserOptions": { 3 | "ecmaVersion": 6, 4 | "sourceType": "module", 5 | }, 6 | "extends": [ 7 | "eslint:recommended", 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /rust/src/legacy_address/mod.rs: -------------------------------------------------------------------------------- 1 | mod address; 2 | mod base58; 3 | mod cbor; 4 | mod crc32; 5 | 6 | pub use address::{Addr, AddressMatchXPub, ByronAddressType, ExtendedAddr, ParseExtendedAddrError}; 7 | -------------------------------------------------------------------------------- /rust/src/builders/batch_tools/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod asset_categorizer; 2 | pub mod assets_calculator; 3 | pub mod cbor_calculator; 4 | pub mod indexes; 5 | pub mod proposals; 6 | pub mod utxo_stat; 7 | pub mod witnesses_calculator; 8 | -------------------------------------------------------------------------------- /rust/src/tests/builders/mod.rs: -------------------------------------------------------------------------------- 1 | mod batch_tools; 2 | mod tx_builder; 3 | mod voting_builder; 4 | mod voting_proposal_builder; 5 | mod certificates_builder; 6 | mod mint_builder; 7 | mod tx_inputs_builder; 8 | mod tx_builder_constans; -------------------------------------------------------------------------------- /rust/src/serialization/witnesses/mod.rs: -------------------------------------------------------------------------------- 1 | mod vkeywitness; 2 | mod vkeywitnesses; 3 | mod bootstrap_witness; 4 | mod bootstrap_witnesses; 5 | mod transaction_witnesses_set; 6 | mod transaction_witnesses_sets; 7 | mod fixed_tx_witnesses_set; -------------------------------------------------------------------------------- /example/src/components-ui/WalletConnector.css: -------------------------------------------------------------------------------- 1 | .connected { 2 | display: flex; 3 | flex-direction: column; 4 | } 5 | 6 | .available-wallets { 7 | padding-top: 16px; 8 | display: flex; 9 | flex-direction: row; 10 | gap: 16px; 11 | } -------------------------------------------------------------------------------- /rust/src/tests/mod.rs: -------------------------------------------------------------------------------- 1 | mod address; 2 | mod builders; 3 | mod general; 4 | mod helpers; 5 | mod fakes; 6 | mod protocol_types; 7 | mod serialization; 8 | mod plutus; 9 | mod metadata; 10 | mod crypto; 11 | mod utils; 12 | mod fees; 13 | mod emip3; 14 | mod pointer; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | publish/ 3 | rust/target 4 | rust/bench/target 5 | tools/metadata-cddl-checker/target 6 | .vscode/ 7 | .idea 8 | rust/.idea 9 | binaryen/ 10 | rust/json-gen/target 11 | rust/json-gen/output 12 | rust/json-gen/schemas 13 | .DS_Store 14 | -------------------------------------------------------------------------------- /example/src/utils/helpers.ts: -------------------------------------------------------------------------------- 1 | import { Buffer } from "buffer"; 2 | 3 | export function hexToBytes(hex: string) { 4 | return Buffer.from(hex, 'hex'); 5 | } 6 | 7 | export function bytesToHex(bytes: Uint8Array) { 8 | return Buffer.from(bytes).toString('hex'); 9 | } 10 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | 2 | version: 2 3 | 4 | sphinx: 5 | configuration: doc/conf.py 6 | 7 | # Optionally set the version of Python and requirements required to build your docs 8 | python: 9 | version: 3.7 10 | install: 11 | - requirements: doc/.sphinx/requirements.txt -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | } 10 | -------------------------------------------------------------------------------- /templates/angular-browser/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | } 10 | -------------------------------------------------------------------------------- /rust/src/serialization/block/mod.rs: -------------------------------------------------------------------------------- 1 | mod block; 2 | mod header; 3 | mod operational_cert; 4 | mod header_body; 5 | mod transaction_bodies; 6 | mod fixed_block; 7 | mod fixed_transaction_body; 8 | mod fixed_transaction_bodies; 9 | mod versioned_block; 10 | mod fixed_versioned_block; 11 | -------------------------------------------------------------------------------- /sonar-project.properties: -------------------------------------------------------------------------------- 1 | sonar.projectKey=Emurgo_cardano-serialization-lib_AYo7dL-2R7D0rS4j9fWq 2 | 3 | # relative paths to source directories. More details and properties are described 4 | # in https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/ 5 | sonar.sources=. 6 | -------------------------------------------------------------------------------- /templates/react-asmjs/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /templates/react-browser/src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /rust/src/chain_core/mod.rs: -------------------------------------------------------------------------------- 1 | cfg_if! { 2 | if #[cfg(test)] { 3 | extern crate quickcheck; 4 | } else if #[cfg(feature = "property-test-api")] { 5 | extern crate quickcheck; 6 | } 7 | } 8 | 9 | pub mod abor; 10 | pub mod mempack; 11 | pub mod packer; 12 | pub mod property; 13 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/mod.rs: -------------------------------------------------------------------------------- 1 | mod cost_model; 2 | mod cost_models; 3 | mod ex_unit_prices; 4 | mod ex_units; 5 | mod language; 6 | mod languages; 7 | mod plutus_data; 8 | mod plutus_script; 9 | mod plutus_scripts; 10 | mod redeemer; 11 | mod redeemer_tag; 12 | mod redeemers; 13 | mod strings; 14 | -------------------------------------------------------------------------------- /templates/react-asmjs/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /templates/react-browser/src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /example/src/utils/networkConfig.ts: -------------------------------------------------------------------------------- 1 | export const protocolParams = Object.freeze({ 2 | linearFee: { 3 | minFeeA: '44', 4 | minFeeB: '155381', 5 | }, 6 | coinsPerUtxoWord: '34482', 7 | poolDeposit: '500000000', 8 | keyDeposit: '2000000', 9 | maxValueSize: 5000, 10 | maxTxSize: 16384, 11 | }); 12 | -------------------------------------------------------------------------------- /rust/src/chain_crypto/algorithms/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod ed25519; 2 | pub mod ed25519_derive; 3 | pub mod ed25519_extended; 4 | pub mod legacy_daedalus; 5 | 6 | pub use ed25519::Ed25519; 7 | pub use ed25519_derive::Ed25519Bip32; 8 | pub use ed25519_extended::Ed25519Extended; 9 | pub use legacy_daedalus::LegacyDaedalus; 10 | -------------------------------------------------------------------------------- /rust/src/serialization/map_names/mod.rs: -------------------------------------------------------------------------------- 1 | mod tx_body_names; 2 | pub(crate) use tx_body_names::*; 3 | 4 | mod witness_set_names; 5 | pub(crate) use witness_set_names::*; 6 | 7 | mod certificate_index_names; 8 | pub(crate) use certificate_index_names::*; 9 | 10 | mod voting_proposal_index_names; 11 | pub(crate) use voting_proposal_index_names::*; 12 | -------------------------------------------------------------------------------- /rust/src/serialization/ser_info/types.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] 5 | pub enum CborContainerType { 6 | Array = 0, 7 | Map = 1, 8 | } 9 | 10 | #[wasm_bindgen] 11 | #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] 12 | pub enum CborSetType { 13 | Tagged = 0, 14 | Untagged = 1, 15 | } -------------------------------------------------------------------------------- /rust/src/serialization/map_names/witness_set_names.rs: -------------------------------------------------------------------------------- 1 | #[derive(Eq, Hash, PartialEq, Clone, Debug, FromPrimitive, ToPrimitive)] 2 | pub(crate) enum WitnessSetNames { 3 | Vkeys = 0, 4 | NativeScripts = 1, 5 | Bootstraps = 2, 6 | PlutusScriptsV1 = 3, 7 | PlutusData = 4, 8 | Redeemers = 5, 9 | PlutusScriptsV2 = 6, 10 | PlutusScriptsV3 = 7, 11 | } 12 | -------------------------------------------------------------------------------- /templates/angular-asmjs/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /templates/angular-browser/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see https://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.ts] 12 | quote_type = single 13 | 14 | [*.md] 15 | max_line_length = off 16 | trim_trailing_whitespace = false 17 | -------------------------------------------------------------------------------- /rust/bench/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bench" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | cardano-serialization-lib = { path = ".." } 10 | 11 | [dev-dependencies] 12 | criterion = "0.5.1" 13 | 14 | [[bench]] 15 | name = "benches_main" 16 | harness = false -------------------------------------------------------------------------------- /example/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "trailingComma": "all", 4 | "tabWidth": 2, 5 | "useTabs": false, 6 | "parser": "typescript", 7 | "semi": true, 8 | "singleQuote": true, 9 | "bracketSpacing": true, 10 | "arrowParens": "always", 11 | "importOrder": ["^@(.*)$", "^[./]" ], 12 | "importOrderSeparation": true, 13 | "importOrderSortSpecifiers": true 14 | } 15 | -------------------------------------------------------------------------------- /templates/angular-asmjs/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /templates/angular-browser/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | ClsAngularTest 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /templates/angular-browser/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/app", 6 | "types": [] 7 | }, 8 | "files": [ 9 | "src/main.ts", 10 | "src/polyfills.ts" 11 | ], 12 | "include": [ 13 | "src/**/*.d.ts" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CslAngularTestAsmjs 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /rust/json-gen/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cardano-serialization-lib-json-schema-gen" 3 | version = "0.0.1" 4 | edition = "2018" 5 | authors = ["EMURGO"] 6 | license = "MIT" 7 | 8 | 9 | [dependencies] 10 | serde_json = { version = "1.0.114", features = ["arbitrary_precision"] } 11 | schemars = "0.8.8" 12 | #serde = { version = "1.0", features = ["derive"] } 13 | cardano-serialization-lib = { path = ".." } 14 | -------------------------------------------------------------------------------- /rust/src/serialization/governance/proposals/mod.rs: -------------------------------------------------------------------------------- 1 | mod parameter_change_action; 2 | mod hard_fork_initiation_action; 3 | mod treasury_withdrawals_action; 4 | mod treasury_withdrawals; 5 | mod no_confidence_action; 6 | mod committee; 7 | mod update_committee_action; 8 | mod constitution; 9 | mod new_constitution_action; 10 | mod governance_action; 11 | mod info_action; 12 | mod voting_proposal; 13 | mod voting_proposals; -------------------------------------------------------------------------------- /rust/src/serialization/map_names/voting_proposal_index_names.rs: -------------------------------------------------------------------------------- 1 | #[derive(Eq, Hash, PartialEq, Clone, Debug, FromPrimitive, ToPrimitive)] 2 | pub(crate) enum VotingProposalIndexNames { 3 | ParameterChangeAction = 0, 4 | HardForkInitiationAction = 1, 5 | TreasuryWithdrawalsAction = 2, 6 | NoConfidenceAction = 3, 7 | UpdateCommitteeAction = 4, 8 | NewConstitutionAction = 5, 9 | InfoAction = 6, 10 | } 11 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /example/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /doc/getting-started/prerequisite-knowledge.md: -------------------------------------------------------------------------------- 1 | # Pre-requisite knowledge 2 | 3 | This library assumes a certain amount of knowledge about how Cardano works (want to avoid re-documenting the wheel). 4 | 5 | You can find the specifications of Cardano's ledger [here](https://github.com/input-output-hk/cardano-ledger-specs) which we suggest consulting as you use this library. Notably, the `Shelley ledger formal specification` covers the core concepts. 6 | -------------------------------------------------------------------------------- /templates/react-asmjs/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /templates/react-browser/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /templates/angular-asmjs/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /templates/angular-browser/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "extends": "./tsconfig.json", 4 | "compilerOptions": { 5 | "outDir": "./out-tsc/spec", 6 | "types": [ 7 | "jasmine" 8 | ] 9 | }, 10 | "files": [ 11 | "src/test.ts", 12 | "src/polyfills.ts" 13 | ], 14 | "include": [ 15 | "src/**/*.spec.ts", 16 | "src/**/*.d.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /templates/react-asmjs/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /example/src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import { CardanoProvider } from './context/CardanoContext'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement); 8 | root.render( 9 | 10 | 11 | 12 | 13 | , 14 | ); 15 | -------------------------------------------------------------------------------- /rust/src/builders/batch_tools/indexes.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive(PartialEq, Eq, Hash, Clone)] 4 | pub struct UtxoIndex(pub(super) usize); 5 | 6 | #[derive(PartialEq, Eq, Hash, Clone)] 7 | pub struct AssetIndex(pub(super) usize); 8 | 9 | #[derive(PartialEq, Eq, Hash, Clone)] 10 | pub struct PolicyIndex(pub(super) usize); 11 | 12 | #[derive(PartialEq, Eq, Clone, Hash)] 13 | pub struct PlaneAssetId(pub(super) PolicyIndex, pub(super) AssetName); 14 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/info_action.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct InfoAction(); 17 | 18 | #[wasm_bindgen] 19 | impl InfoAction { 20 | pub fn new() -> Self { 21 | Self() 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /templates/angular-browser/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.error(err)); 13 | -------------------------------------------------------------------------------- /templates/react-asmjs/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /templates/react-browser/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /templates/react-browser/src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | 3 | .. toctree:: 4 | :titlesonly: 5 | :hidden: 6 | 7 | Go Back to Cardano Documentation 8 | 9 | .. toctree:: 10 | :maxdepth: 3 11 | :caption: Getting Started 12 | :titlesonly: 13 | :hidden: 14 | 15 | getting-started/prerequisite-knowledge 16 | getting-started/generating-keys 17 | getting-started/generating-transactions 18 | getting-started/metadata 19 | -------------------------------------------------------------------------------- /rust/src/crypto.rs: -------------------------------------------------------------------------------- 1 | use cryptoxide::blake2b::Blake2b; 2 | 3 | pub(crate) fn blake2b224(data: &[u8]) -> [u8; 28] { 4 | let mut out = [0; 28]; 5 | Blake2b::blake2b(&mut out, data, &[]); 6 | out 7 | } 8 | 9 | pub(crate) fn blake2b256(data: &[u8]) -> [u8; 32] { 10 | let mut out = [0; 32]; 11 | Blake2b::blake2b(&mut out, data, &[]); 12 | out 13 | } 14 | 15 | // All key structs were taken from js-chain-libs: 16 | // https://github.com/Emurgo/js-chain-libs -------------------------------------------------------------------------------- /specs/README.md: -------------------------------------------------------------------------------- 1 | # Generating CDDL instances 2 | 3 | First you need to install `cddl` 4 | ``` 5 | sudo apt install ruby 6 | sudo gem install cddl 7 | sudo gem install cbor-diag 8 | ``` 9 | 10 | You can generate new tests with 11 | 1) `cddl specs/shelley.cddl generate 1 > test/name_here.diag` 12 | 2) `diag2cbor.rb test/name_here.diag > test/name_here.cbor` 13 | 14 | You can combine these together with `cddl specs/shelley.cddl generate 1 | diag2cbor.rb > test/name_here.cbor` 15 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/rust" 5 | schedule: 6 | interval: monthly 7 | timezone: PST8PDT 8 | open-pull-requests-limit: 99 9 | ignore: 10 | - dependency-name: wasm-bindgen 11 | versions: 12 | - 0.2.69 13 | - 0.2.70 14 | - dependency-name: cryptoxide 15 | versions: 16 | - 0.3.0 17 | - dependency-name: serde_json 18 | versions: 19 | - 1.0.61 20 | rebase-strategy: disabled 21 | -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/vkey.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Debug, Ord, PartialOrd, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub struct Vkey(pub(crate) PublicKey); 6 | 7 | impl_to_from!(Vkey); 8 | 9 | #[wasm_bindgen] 10 | impl Vkey { 11 | pub fn new(pk: &PublicKey) -> Self { 12 | Self(pk.clone()) 13 | } 14 | 15 | pub fn public_key(&self) -> PublicKey { 16 | self.0.clone() 17 | } 18 | } -------------------------------------------------------------------------------- /rust/src/builders/script_structs/mod.rs: -------------------------------------------------------------------------------- 1 | mod plutus_script_source; 2 | pub use plutus_script_source::*; 3 | 4 | mod native_script_source; 5 | pub use native_script_source::*; 6 | 7 | mod datum_source; 8 | pub use datum_source::*; 9 | 10 | mod plutus_witness; 11 | pub use plutus_witness::*; 12 | 13 | mod plutus_witnesses; 14 | pub use plutus_witnesses::*; 15 | 16 | mod plutus_script_ref; 17 | pub(crate) use plutus_script_ref::*; 18 | 19 | mod script_witness_type; 20 | pub(crate) use script_witness_type::*; 21 | -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/vkeys.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone)] 5 | pub struct Vkeys(pub(crate) Vec); 6 | 7 | #[wasm_bindgen] 8 | impl Vkeys { 9 | pub fn new() -> Self { 10 | Self(Vec::new()) 11 | } 12 | 13 | pub fn len(&self) -> usize { 14 | self.0.len() 15 | } 16 | 17 | pub fn get(&self, index: usize) -> Vkey { 18 | self.0[index].clone() 19 | } 20 | 21 | pub fn add(&mut self, elem: &Vkey) { 22 | self.0.push(elem.clone()); 23 | } 24 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/witnesses/mod.rs: -------------------------------------------------------------------------------- 1 | mod vkeywitness; 2 | pub use vkeywitness::*; 3 | 4 | mod vkeywitnesses; 5 | pub use vkeywitnesses::*; 6 | 7 | mod bootstrap_witness; 8 | pub use bootstrap_witness::*; 9 | 10 | mod bootstrap_witnesses; 11 | 12 | pub use bootstrap_witnesses::*; 13 | 14 | mod transaction_witnesses_set; 15 | pub use transaction_witnesses_set::*; 16 | 17 | mod transaction_witnesses_sets; 18 | 19 | pub use transaction_witnesses_sets::*; 20 | 21 | mod fixed_tx_witnesses_set; 22 | pub use fixed_tx_witnesses_set::*; 23 | 24 | -------------------------------------------------------------------------------- /example/src/components-logic/AddressGenerator.ts: -------------------------------------------------------------------------------- 1 | import * as CSL from '@emurgo/cardano-serialization-lib-browser'; 2 | import { getRandomPrivAndPubKeys } from './core'; 3 | 4 | export const generateAddress = (setAddress: Function) => { 5 | const { publicKey } = getRandomPrivAndPubKeys(); 6 | 7 | const address = CSL.BaseAddress.new( 8 | 0, // NetworkId (0 - testnet, 1 - mainnet) 9 | CSL.Credential.from_keyhash(publicKey.hash()), 10 | CSL.Credential.from_keyhash(publicKey.hash()), 11 | ).to_address(); 12 | 13 | setAddress(address.to_bech32()); 14 | }; 15 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/mod.rs: -------------------------------------------------------------------------------- 1 | mod drep; 2 | pub use drep::*; 3 | 4 | mod anchor; 5 | pub use anchor::*; 6 | 7 | mod voter; 8 | pub use voter::*; 9 | 10 | mod voters; 11 | pub use voters::*; 12 | 13 | mod voting_procedure; 14 | pub use voting_procedure::*; 15 | 16 | mod voting_procedures; 17 | pub use voting_procedures::*; 18 | 19 | mod governance_action_id; 20 | pub use governance_action_id::*; 21 | 22 | mod governance_action_ids; 23 | pub use governance_action_ids::*; 24 | 25 | mod proposals; 26 | mod cip129_decoder; 27 | 28 | pub use proposals::*; 29 | -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/public_keys.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | pub struct PublicKeys(Vec); 5 | 6 | #[wasm_bindgen] 7 | impl PublicKeys { 8 | #[wasm_bindgen(constructor)] 9 | pub fn new() -> PublicKeys { 10 | PublicKeys(vec![]) 11 | } 12 | 13 | pub fn size(&self) -> usize { 14 | self.0.len() 15 | } 16 | 17 | pub fn get(&self, index: usize) -> PublicKey { 18 | self.0[index].clone() 19 | } 20 | 21 | pub fn add(&mut self, key: &PublicKey) { 22 | self.0.push(key.clone()); 23 | } 24 | } -------------------------------------------------------------------------------- /rust/bench/benches/block_bench.rs: -------------------------------------------------------------------------------- 1 | use cardano_serialization_lib::Block; 2 | use criterion::{black_box, criterion_group, criterion_main, Criterion}; 3 | 4 | fn bench_decode_block(c: &mut Criterion) { 5 | let raw_data = include_bytes!("data/block_with_certs.bin").to_vec(); 6 | c.bench_function("decode block", |b| { 7 | b.iter(|| { 8 | let data_copy = raw_data.clone(); 9 | let block = Block::from_bytes(data_copy); 10 | assert!(block.is_ok()); 11 | }) 12 | }); 13 | } 14 | 15 | criterion_group!(benches, bench_decode_block); 16 | -------------------------------------------------------------------------------- /rust/src/protocol_types/plutus/strings.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] 5 | pub struct Strings(pub(crate) Vec); 6 | 7 | #[wasm_bindgen] 8 | impl Strings { 9 | pub fn new() -> Self { 10 | Self(Vec::new()) 11 | } 12 | 13 | pub fn len(&self) -> usize { 14 | self.0.len() 15 | } 16 | 17 | pub fn get(&self, index: usize) -> String { 18 | self.0[index].clone() 19 | } 20 | 21 | pub fn add(&mut self, elem: String) { 22 | self.0.push(elem); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /rust/src/serialization/map_names/tx_body_names.rs: -------------------------------------------------------------------------------- 1 | #[derive(Eq, Hash, PartialEq, Clone, Debug, FromPrimitive, ToPrimitive)] 2 | pub(crate) enum TxBodyNames { 3 | Inputs = 0, 4 | Outputs = 1, 5 | Fee = 2, 6 | Ttl = 3, 7 | Certs = 4, 8 | Withdrawals = 5, 9 | Update = 6, 10 | AuxiliaryDataHash = 7, 11 | ValidityStartInterval = 8, 12 | Mint = 9, 13 | ScriptDataHash = 11, 14 | Collateral = 13, 15 | RequiredSigners = 14, 16 | NetworkId = 15, 17 | CollateralReturn = 16, 18 | TotalCollateral = 17, 19 | ReferenceInputs = 18, 20 | } 21 | -------------------------------------------------------------------------------- /rust/src/tests/emip3.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[test] 4 | fn encryption() { 5 | let password = String::from("70617373776f7264"); 6 | let salt = String::from("50515253c0c1c2c3c4c5c6c750515253c0c1c2c3c4c5c6c750515253c0c1c2c3"); 7 | let nonce = String::from("50515253c0c1c2c3c4c5c6c7"); 8 | let data = String::from("736f6d65206461746120746f20656e6372797074"); 9 | let encrypted_data = encrypt_with_password(&password, &salt, &nonce, &data).unwrap(); 10 | let decrypted_data = decrypt_with_password(&password, &encrypted_data).unwrap(); 11 | assert_eq!(data, decrypted_data); 12 | } 13 | -------------------------------------------------------------------------------- /scripts/wasm-to-asm.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs') 2 | 3 | const paths = [ 4 | './rust/pkg/cardano_serialization_lib_bg.js', 5 | './rust/pkg/cardano_serialization_lib.js' 6 | ] 7 | 8 | paths.forEach((path) => { 9 | fs.readFile(path, 'utf8', (err,data) => { 10 | if (err) { 11 | return console.log(err); 12 | } 13 | 14 | const result = data.replace(/_bg.wasm/g, '.asm.js'); 15 | 16 | fs.writeFile(path, result, 'utf8', (err) => { 17 | if (err) return console.log(err); 18 | }); 19 | }); 20 | }) 21 | 22 | fs.unlinkSync('./rust/pkg/cardano_serialization_lib_bg.wasm') 23 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | 6 | import { AppComponent } from './app.component'; 7 | import { CslExampleComponent } from './csl-example/csl-example.component'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | AppComponent, 12 | CslExampleComponent 13 | ], 14 | imports: [ 15 | BrowserModule, 16 | FormsModule, 17 | ], 18 | providers: [], 19 | bootstrap: [AppComponent] 20 | }) 21 | export class AppModule { } 22 | -------------------------------------------------------------------------------- /templates/angular-browser/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { BrowserModule } from '@angular/platform-browser'; 3 | import { FormsModule } from '@angular/forms'; 4 | 5 | 6 | import { AppComponent } from './app.component'; 7 | import { CslExampleComponent } from './csl-example/csl-example.component'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | AppComponent, 12 | CslExampleComponent 13 | ], 14 | imports: [ 15 | BrowserModule, 16 | FormsModule, 17 | ], 18 | providers: [], 19 | bootstrap: [AppComponent] 20 | }) 21 | export class AppModule { } 22 | -------------------------------------------------------------------------------- /example/craco.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | webpack: { 3 | configure: (config) => { 4 | const wasmExtensionRegExp = /\.wasm$/ 5 | config.resolve.extensions.push('.wasm') 6 | config.experiments = { 7 | ...config.experiments, 8 | asyncWebAssembly: true, 9 | } 10 | 11 | config.module.rules.forEach((rule) => { 12 | ;(rule.oneOf || []).forEach((oneOf) => { 13 | if (oneOf.type === 'asset/resource') { 14 | oneOf.exclude.push(wasmExtensionRegExp) 15 | } 16 | }) 17 | }) 18 | 19 | return config 20 | }, 21 | }, 22 | } 23 | -------------------------------------------------------------------------------- /rust/src/serialization/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod map_names; 2 | pub mod traits; 3 | pub(super) use traits::*; 4 | 5 | mod ser_info; 6 | pub use ser_info::*; 7 | 8 | mod general; 9 | mod serialization_macros; 10 | mod certificates; 11 | mod governance; 12 | mod utils; 13 | mod fixed_tx; 14 | use utils::*; 15 | mod metadata; 16 | mod transaction_body; 17 | mod protocol_param_update; 18 | mod tx_inputs; 19 | mod credentials; 20 | mod ed25519_key_hashes; 21 | mod witnesses; 22 | mod credential; 23 | mod crypto; 24 | mod plutus; 25 | mod native_script; 26 | mod native_scripts; 27 | mod numeric; 28 | mod script_ref; 29 | mod tx_input; 30 | mod block; -------------------------------------------------------------------------------- /rust/src/protocol_types/block/mod.rs: -------------------------------------------------------------------------------- 1 | mod block; 2 | pub use block::*; 3 | 4 | mod fixed_block; 5 | pub use fixed_block::*; 6 | 7 | mod fixed_tx_body; 8 | pub use fixed_tx_body::*; 9 | 10 | mod header; 11 | pub use header::*; 12 | 13 | mod transaction_bodies; 14 | pub use transaction_bodies::*; 15 | 16 | mod header_body; 17 | pub use header_body::*; 18 | 19 | mod operational_cert; 20 | pub use operational_cert::*; 21 | 22 | mod fixed_versioned_block; 23 | pub use fixed_versioned_block::*; 24 | 25 | mod fixed_transaction_bodies; 26 | pub use fixed_transaction_bodies::*; 27 | 28 | mod versioned_block; 29 | pub use versioned_block::*; -------------------------------------------------------------------------------- /rust/src/serialization/certificates/mod.rs: -------------------------------------------------------------------------------- 1 | mod certificate; 2 | mod certificates_collection; 3 | mod committee_cold_resign; 4 | mod committee_hot_auth; 5 | mod drep_deregistration; 6 | mod drep_registration; 7 | mod drep_update; 8 | mod genesis_key_delegation; 9 | mod move_instantaneous_rewards_cert; 10 | mod pool_registration; 11 | mod pool_retirement; 12 | mod stake_and_vote_delegation; 13 | mod stake_delegation; 14 | mod stake_deregistration; 15 | mod stake_registration; 16 | mod stake_registration_and_delegation; 17 | mod stake_vote_registration_and_delegation; 18 | mod vote_delegation; 19 | mod vote_registration_and_delegation; 20 | -------------------------------------------------------------------------------- /templates/react-asmjs/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /templates/react-browser/src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom/client'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | const root = ReactDOM.createRoot(document.getElementById('root')); 8 | root.render( 9 | 10 | 11 | 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /example/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "CSL + dApp example", 3 | "name": "The example app how to use CSL", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /templates/react-asmjs/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /templates/react-browser/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /rust/src/serialization/block/fixed_versioned_block.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::utils::{check_len, check_len_indefinite}; 2 | use crate::*; 3 | 4 | impl Deserialize for FixedVersionedBlock { 5 | fn deserialize(raw: &mut Deserializer) -> Result { 6 | let len = raw.array()?; 7 | check_len(len, 2, "VersionedBlock")?; 8 | let era_code = u32::deserialize(raw)?; 9 | let block = FixedBlock::deserialize(raw)?; 10 | check_len_indefinite(raw, len)?; 11 | Ok(FixedVersionedBlock { 12 | block, 13 | era_code, 14 | }) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/components-ui/AddressGenerator.tsx: -------------------------------------------------------------------------------- 1 | import React, { useState } from 'react'; 2 | import { generateAddress } from '../components-logic/AddressGenerator'; 3 | 4 | const AddressGenerator: React.FC = () => { 5 | const [address, setAddress] = useState(''); 6 | 7 | return ( 8 |
9 |

Cardano address generator

10 | 11 | {address && ( 12 |
13 |

Your address:

14 |

{address}

15 |
16 | )} 17 |
18 | ); 19 | }; 20 | 21 | export default AddressGenerator; 22 | -------------------------------------------------------------------------------- /rust/src/builders/script_structs/datum_source.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] 4 | pub enum DatumSourceEnum { 5 | Datum(PlutusData), 6 | RefInput(TransactionInput), 7 | } 8 | 9 | #[wasm_bindgen] 10 | #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] 11 | pub struct DatumSource(pub(crate) DatumSourceEnum); 12 | 13 | #[wasm_bindgen] 14 | impl DatumSource { 15 | pub fn new(datum: &PlutusData) -> Self { 16 | Self(DatumSourceEnum::Datum(datum.clone())) 17 | } 18 | 19 | pub fn new_ref_input(input: &TransactionInput) -> Self { 20 | Self(DatumSourceEnum::RefInput(input.clone())) 21 | } 22 | } -------------------------------------------------------------------------------- /rust/src/serialization/numeric/big_num.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | impl Serialize for BigNum { 4 | fn serialize<'se, W: Write>( 5 | &self, 6 | serializer: &'se mut Serializer, 7 | ) -> cbor_event::Result<&'se mut Serializer> { 8 | serializer.write_unsigned_integer(self.0) 9 | } 10 | } 11 | 12 | impl Deserialize for BigNum { 13 | fn deserialize(raw: &mut Deserializer) -> Result { 14 | match raw.unsigned_integer() { 15 | Ok(value) => Ok(Self(value)), 16 | Err(e) => Err(DeserializeError::new("BigNum", DeserializeFailure::CBOR(e))), 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /templates/angular-asmjs/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | -------------------------------------------------------------------------------- /templates/angular-browser/.browserslistrc: -------------------------------------------------------------------------------- 1 | # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | 5 | # For the full list of supported browsers by the Angular framework, please see: 6 | # https://angular.io/guide/browser-support 7 | 8 | # You can see what browsers were selected by your queries by running: 9 | # npx browserslist 10 | 11 | last 1 Chrome version 12 | last 1 Firefox version 13 | last 2 Edge major versions 14 | last 2 Safari major versions 15 | last 2 iOS major versions 16 | Firefox ESR 17 | -------------------------------------------------------------------------------- /rust/src/protocol_types/block/transaction_bodies.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, Debug, PartialEq, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub struct TransactionBodies(pub(crate) Vec); 6 | 7 | impl_to_from!(TransactionBodies); 8 | 9 | #[wasm_bindgen] 10 | impl TransactionBodies { 11 | pub fn new() -> Self { 12 | Self(Vec::new()) 13 | } 14 | 15 | pub fn len(&self) -> usize { 16 | self.0.len() 17 | } 18 | 19 | pub fn get(&self, index: usize) -> TransactionBody { 20 | self.0[index].clone() 21 | } 22 | 23 | pub fn add(&mut self, elem: &TransactionBody) { 24 | self.0.push(elem.clone()); 25 | } 26 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/plutus/mod.rs: -------------------------------------------------------------------------------- 1 | mod plutus_script; 2 | pub use plutus_script::*; 3 | 4 | mod language; 5 | pub use language::*; 6 | 7 | mod languages; 8 | pub use languages::*; 9 | mod plutus_scripts; 10 | pub use plutus_scripts::*; 11 | 12 | mod cost_model; 13 | pub use cost_model::*; 14 | 15 | mod cost_models; 16 | pub use cost_models::*; 17 | 18 | mod ex_unit_prices; 19 | pub use ex_unit_prices::*; 20 | 21 | mod ex_units; 22 | pub use ex_units::*; 23 | 24 | mod redeemer; 25 | pub use redeemer::*; 26 | 27 | mod redeemer_tag; 28 | pub use redeemer_tag::*; 29 | 30 | mod redeemers; 31 | pub use redeemers::*; 32 | 33 | mod strings; 34 | pub use strings::*; 35 | 36 | mod plutus_data; 37 | pub use plutus_data::*; 38 | -------------------------------------------------------------------------------- /example/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es6", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx", 22 | "rootDir": "src", 23 | "outDir": "dist", 24 | "sourceMap": true 25 | }, 26 | "include": [ 27 | "src" 28 | ] 29 | } -------------------------------------------------------------------------------- /rust/src/builders/script_structs/plutus_script_ref.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] 4 | pub(crate) struct PlutusScriptRef { 5 | pub(crate) input_ref: TransactionInput, 6 | pub(crate) script_hash: ScriptHash, 7 | pub(crate) language: Language, 8 | pub(crate) script_size: usize, 9 | } 10 | 11 | impl PlutusScriptRef { 12 | pub(crate) fn new( 13 | input_ref: TransactionInput, 14 | script_hash: ScriptHash, 15 | language: Language, 16 | script_size: usize, 17 | ) -> Self { 18 | Self { 19 | input_ref, 20 | script_hash, 21 | language, 22 | script_size, 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /rust/src/chain_crypto/mod.rs: -------------------------------------------------------------------------------- 1 | cfg_if! { 2 | if #[cfg(test)] { 3 | mod testing; 4 | } else if #[cfg(feature = "property-test-api")] { 5 | pub mod testing; 6 | } 7 | } 8 | 9 | pub mod algorithms; 10 | pub mod bech32; 11 | pub mod derive; 12 | pub mod digest; 13 | pub mod hash; 14 | mod key; 15 | mod sign; 16 | 17 | pub use algorithms::*; 18 | pub use hash::{Blake2b256, Sha3_256}; 19 | pub use key::{ 20 | AsymmetricKey, AsymmetricPublicKey, KeyPair, PublicKey, PublicKeyError, PublicKeyFromStrError, 21 | SecretKey, SecretKeyError, SecretKeySizeStatic, 22 | }; 23 | pub use sign::{ 24 | Signature, SignatureError, SignatureFromStrError, SigningAlgorithm, Verification, 25 | VerificationAlgorithm, 26 | }; 27 | -------------------------------------------------------------------------------- /scripts/fix-buffer-ref.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | const inputFile = fs.readFileSync('./rust/pkg/cardano_serialization_lib_bg.js', 'utf8').split(/\r?\n/); 4 | 5 | const regex = /(\s*if \(cached[A-Za-z0-9]+Memory[0-9]* === null ||) (cached[A-Za-z0-9]+Memory[0-9]*)\.byteLength === 0\) {/; 6 | const replacer = '$1 $2.buffer !== wasm.memory.buffer) {'; 7 | 8 | for (let i = 0; i < inputFile.length; ++i) { 9 | let line = inputFile[i]; 10 | inputFile[i] = line.replace(regex, replacer); 11 | } 12 | 13 | fs.writeFile( 14 | './rust/pkg/cardano_serialization_lib_bg.js', 15 | inputFile.join('\n'), 16 | (err) => { 17 | if (err != null) { 18 | console.log(`err writing file: ${err}`) 19 | } 20 | } 21 | ); 22 | -------------------------------------------------------------------------------- /rust/src/protocol_types/witnesses/transaction_witnesses_sets.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, Debug, PartialEq, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub struct TransactionWitnessSets(pub(crate) Vec); 6 | 7 | impl_to_from!(TransactionWitnessSets); 8 | 9 | #[wasm_bindgen] 10 | impl TransactionWitnessSets { 11 | pub fn new() -> Self { 12 | Self(Vec::new()) 13 | } 14 | 15 | pub fn len(&self) -> usize { 16 | self.0.len() 17 | } 18 | 19 | pub fn get(&self, index: usize) -> TransactionWitnessSet { 20 | self.0[index].clone() 21 | } 22 | 23 | pub fn add(&mut self, elem: &TransactionWitnessSet) { 24 | self.0.push(elem.clone()); 25 | } 26 | } -------------------------------------------------------------------------------- /templates/angular-asmjs/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # Compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | /bazel-out 8 | 9 | # Node 10 | /node_modules 11 | npm-debug.log 12 | yarn-error.log 13 | 14 | # IDEs and editors 15 | .idea/ 16 | .project 17 | .classpath 18 | .c9/ 19 | *.launch 20 | .settings/ 21 | *.sublime-workspace 22 | 23 | # Visual Studio Code 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | .history/* 30 | 31 | # Miscellaneous 32 | /.angular/cache 33 | .sass-cache/ 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | testem.log 38 | /typings 39 | 40 | # System files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /templates/angular-browser/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # Compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | /bazel-out 8 | 9 | # Node 10 | /node_modules 11 | npm-debug.log 12 | yarn-error.log 13 | 14 | # IDEs and editors 15 | .idea/ 16 | .project 17 | .classpath 18 | .c9/ 19 | *.launch 20 | .settings/ 21 | *.sublime-workspace 22 | 23 | # Visual Studio Code 24 | .vscode/* 25 | !.vscode/settings.json 26 | !.vscode/tasks.json 27 | !.vscode/launch.json 28 | !.vscode/extensions.json 29 | .history/* 30 | 31 | # Miscellaneous 32 | /.angular/cache 33 | .sass-cache/ 34 | /connect.lock 35 | /coverage 36 | /libpeerconnection.log 37 | testem.log 38 | /typings 39 | 40 | # System files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /templates/angular-browser/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * For easier debugging in development mode, you can import the following file 11 | * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. 12 | * 13 | * This import should be commented out in production mode because it will have a negative impact 14 | * on performance if an error is thrown. 15 | */ 16 | // import 'zone.js/plugins/zone-error'; // Included with Angular CLI. 17 | -------------------------------------------------------------------------------- /rust/src/protocol_types/witnesses/vkeywitness.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Hash, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub struct Vkeywitness { 6 | pub(crate) vkey: Vkey, 7 | pub(crate) signature: Ed25519Signature, 8 | } 9 | 10 | impl_to_from!(Vkeywitness); 11 | 12 | #[wasm_bindgen] 13 | impl Vkeywitness { 14 | pub fn new(vkey: &Vkey, signature: &Ed25519Signature) -> Self { 15 | Self { 16 | vkey: vkey.clone(), 17 | signature: signature.clone(), 18 | } 19 | } 20 | 21 | pub fn vkey(&self) -> Vkey { 22 | self.vkey.clone() 23 | } 24 | 25 | pub fn signature(&self) -> Ed25519Signature { 26 | self.signature.clone() 27 | } 28 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/plutus/languages.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize, JsonSchema, 6 | )] 7 | pub struct Languages(pub(crate) Vec); 8 | 9 | #[wasm_bindgen] 10 | impl Languages { 11 | pub fn new() -> Self { 12 | Self(Vec::new()) 13 | } 14 | 15 | pub fn len(&self) -> usize { 16 | self.0.len() 17 | } 18 | 19 | pub fn get(&self, index: usize) -> Language { 20 | self.0[index] 21 | } 22 | 23 | pub fn add(&mut self, elem: Language) { 24 | self.0.push(elem); 25 | } 26 | 27 | pub fn list() -> Languages { 28 | Languages(vec![Language::new_plutus_v1(), Language::new_plutus_v2()]) 29 | } 30 | } -------------------------------------------------------------------------------- /rust/src/serialization/block/fixed_transaction_body.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::{deserilized_with_orig_bytes}; 3 | 4 | impl Deserialize for FixedTransactionBody { 5 | fn deserialize(raw: &mut Deserializer) -> Result { 6 | let (body, orig_bytes) = deserilized_with_orig_bytes(raw, |raw| -> Result<_, DeserializeError> { 7 | let body = TransactionBody::deserialize(raw)?; 8 | Ok(body) 9 | }).map_err(|e| e.annotate("TransactionBody"))?; 10 | let hash = TransactionHash(blake2b256(orig_bytes.as_ref())); 11 | Ok(FixedTransactionBody { 12 | body, 13 | tx_hash: hash, 14 | original_bytes: orig_bytes, 15 | }) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /release.sh: -------------------------------------------------------------------------------- 1 | if [ $1 = "prod" ]; 2 | then RELEASE_TYPE="prod" 3 | elif [ $1 = "beta" ]; 4 | then RELEASE_TYPE="beta" 5 | else 6 | echo "First parameter is expected 'prod' or 'beta'" 7 | return 1 8 | fi 9 | 10 | echo "Preparing ${RELEASE_TYPE} release" 11 | 12 | . ./build-and-test.sh \ 13 | && npm run js:publish-nodejs:${RELEASE_TYPE}:no-gc \ 14 | && npm run js:publish-browser:${RELEASE_TYPE}:no-gc \ 15 | && npm run js:publish-browser-inlined:${RELEASE_TYPE}:no-gc \ 16 | && npm run js:publish-asm:${RELEASE_TYPE}:no-gc \ 17 | && npm run js:publish-nodejs:${RELEASE_TYPE}:gc \ 18 | && npm run js:publish-browser:${RELEASE_TYPE}:gc \ 19 | && npm run js:publish-browser-inlined:${RELEASE_TYPE}:gc \ 20 | && npm run js:publish-asm:${RELEASE_TYPE}:gc \ 21 | && (cd rust; cargo publish --allow-dirty) 22 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/voters.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Eq, 7 | Ord, 8 | PartialEq, 9 | PartialOrd, 10 | Hash, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct Voters(pub(crate) Vec); 17 | 18 | to_from_json!(Voters); 19 | 20 | #[wasm_bindgen] 21 | impl Voters { 22 | pub fn new() -> Self { 23 | Self(Vec::new()) 24 | } 25 | 26 | pub fn add(&mut self, voter: &Voter) { 27 | self.0.push(voter.clone()); 28 | } 29 | 30 | pub fn get(&self, index: usize) -> Option { 31 | self.0.get(index).cloned() 32 | } 33 | 34 | pub fn len(&self) -> usize { 35 | self.0.len() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/csl-example/csl-example.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CslExampleComponent } from './csl-example.component'; 4 | 5 | describe('CslExampleComponent', () => { 6 | let component: CslExampleComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ CslExampleComponent ] 12 | }) 13 | .compileComponents(); 14 | 15 | fixture = TestBed.createComponent(CslExampleComponent); 16 | component = fixture.componentInstance; 17 | fixture.detectChanges(); 18 | }); 19 | 20 | it('should create', () => { 21 | expect(component).toBeTruthy(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /templates/angular-browser/src/app/csl-example/csl-example.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { CslExampleComponent } from './csl-example.component'; 4 | 5 | describe('CslExampleComponent', () => { 6 | let component: CslExampleComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async () => { 10 | await TestBed.configureTestingModule({ 11 | declarations: [ CslExampleComponent ] 12 | }) 13 | .compileComponents(); 14 | 15 | fixture = TestBed.createComponent(CslExampleComponent); 16 | component = fixture.componentInstance; 17 | fixture.detectChanges(); 18 | }); 19 | 20 | it('should create', () => { 21 | expect(component).toBeTruthy(); 22 | }); 23 | }); 24 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/plutus_script.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | impl cbor_event::se::Serialize for PlutusScript { 4 | fn serialize<'se, W: Write>( 5 | &self, 6 | serializer: &'se mut Serializer, 7 | ) -> cbor_event::Result<&'se mut Serializer> { 8 | serializer.write_bytes(&self.bytes) 9 | } 10 | } 11 | 12 | impl Deserialize for PlutusScript { 13 | fn deserialize(raw: &mut Deserializer) -> Result { 14 | Ok(Self::new(raw.bytes()?)) 15 | } 16 | } 17 | 18 | impl PlutusScript { 19 | pub(crate) fn deserialize_with_version(raw: &mut Deserializer, version: &Language) -> Result { 20 | Ok(Self::new_with_version(raw.bytes()?, version)) 21 | } 22 | } -------------------------------------------------------------------------------- /rust/src/serialization/crypto/vkey.rs: -------------------------------------------------------------------------------- 1 | use std::io::{BufRead, Seek, Write}; 2 | use cbor_event::de::Deserializer; 3 | use cbor_event::se::Serializer; 4 | use crate::{DeserializeError, PublicKey, Vkey}; 5 | use crate::protocol_types::Deserialize; 6 | 7 | impl cbor_event::se::Serialize for Vkey { 8 | fn serialize<'se, W: Write>( 9 | &self, 10 | serializer: &'se mut Serializer, 11 | ) -> cbor_event::Result<&'se mut Serializer> { 12 | serializer.write_bytes(&self.0.as_bytes()) 13 | } 14 | } 15 | 16 | impl Deserialize for Vkey { 17 | fn deserialize(raw: &mut Deserializer) -> Result { 18 | Ok(Self(PublicKey(crate::chain_crypto::PublicKey::from_binary( 19 | raw.bytes()?.as_ref(), 20 | )?))) 21 | } 22 | } -------------------------------------------------------------------------------- /doc/.sphinx/requirements.txt: -------------------------------------------------------------------------------- 1 | Sphinx==3.1.1 2 | sphinx-intl==2.0.1 3 | transifex-client==0.13.10 4 | testresources==2.0.1 5 | -e git+https://github.com/input-output-hk/sphinx_rtd_theme.git#egg=sphinx_rtd_theme 6 | recommonmark==0.6 7 | ## The following requirements were added by pip freeze: 8 | alabaster==0.7.12 9 | Babel==2.8.0 10 | certifi==2020.4.5.2 11 | chardet==3.0.4 12 | click==7.1.2 13 | sphinxcontrib-mermaid==0.4.0 14 | sphinxemoji==0.1.6 15 | sphinx_markdown_tables==0.0.15 16 | CommonMark==0.9.1 17 | docutils==0.16 18 | future==0.18.2 19 | idna==2.9 20 | imagesize==1.2.0 21 | Jinja2==2.11.3 22 | jsonpointer==2.0 23 | jsonref==0.2 24 | MarkupSafe==1.1.1 25 | Pygments==2.7.4 26 | pytz==2020.1 27 | requests==2.24.0 28 | six==1.15.0 29 | snowballstemmer==2.0.0 30 | sphinxcontrib-websupport==1.2.2 31 | urllib3==1.25.9 32 | -------------------------------------------------------------------------------- /rust/src/traits.rs: -------------------------------------------------------------------------------- 1 | pub trait NoneOrEmpty { 2 | fn is_none_or_empty(&self) -> bool; 3 | } 4 | 5 | pub trait EmptyToNone: Sized { 6 | fn empty_to_none(self) -> Option; 7 | } 8 | 9 | impl NoneOrEmpty for &T { 10 | fn is_none_or_empty(&self) -> bool { 11 | (*self).is_none_or_empty() 12 | } 13 | } 14 | 15 | impl NoneOrEmpty for Option { 16 | fn is_none_or_empty(&self) -> bool { 17 | match &self { 18 | Some(x) => x.is_none_or_empty(), 19 | None => true, 20 | } 21 | } 22 | } 23 | 24 | impl EmptyToNone for T { 25 | fn empty_to_none(self) -> Option { 26 | if self.is_none_or_empty() { 27 | None 28 | } else { 29 | Some(self) 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/block/fixed_transaction_bodies.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, Debug, PartialEq)] 5 | /// Warning: This is experimental and may be removed or changed in the future. 6 | pub struct FixedTransactionBodies(pub(crate) Vec); 7 | 8 | from_bytes!(FixedTransactionBodies); 9 | from_hex!(FixedTransactionBodies); 10 | 11 | #[wasm_bindgen] 12 | impl FixedTransactionBodies { 13 | pub fn new() -> Self { 14 | Self(Vec::new()) 15 | } 16 | 17 | pub fn len(&self) -> usize { 18 | self.0.len() 19 | } 20 | 21 | pub fn get(&self, index: usize) -> FixedTransactionBody { 22 | self.0[index].clone() 23 | } 24 | 25 | pub fn add(&mut self, elem: &FixedTransactionBody) { 26 | self.0.push(elem.clone()); 27 | } 28 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/block/header.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, Debug, PartialEq, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub struct Header { 6 | pub(crate) header_body: HeaderBody, 7 | pub(crate) body_signature: KESSignature, 8 | } 9 | 10 | impl_to_from!(Header); 11 | 12 | #[wasm_bindgen] 13 | impl Header { 14 | pub fn header_body(&self) -> HeaderBody { 15 | self.header_body.clone() 16 | } 17 | 18 | pub fn body_signature(&self) -> KESSignature { 19 | self.body_signature.clone() 20 | } 21 | 22 | pub fn new(header_body: &HeaderBody, body_signature: &KESSignature) -> Self { 23 | Self { 24 | header_body: header_body.clone(), 25 | body_signature: body_signature.clone(), 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/plutus/ex_units.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct ExUnits { 17 | pub(crate) mem: BigNum, 18 | pub(crate) steps: BigNum, 19 | } 20 | 21 | impl_to_from!(ExUnits); 22 | 23 | #[wasm_bindgen] 24 | impl ExUnits { 25 | pub fn mem(&self) -> BigNum { 26 | self.mem.clone() 27 | } 28 | 29 | pub fn steps(&self) -> BigNum { 30 | self.steps.clone() 31 | } 32 | 33 | pub fn new(mem: &BigNum, steps: &BigNum) -> Self { 34 | Self { 35 | mem: mem.clone(), 36 | steps: steps.clone(), 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rust/src/builders/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod batch_tools; 2 | 3 | mod certificates_builder; 4 | pub use certificates_builder::*; 5 | 6 | mod mint_builder; 7 | pub use mint_builder::*; 8 | 9 | mod script_structs; 10 | pub use script_structs::*; 11 | 12 | mod tx_batch_builder; 13 | pub use tx_batch_builder::*; 14 | 15 | mod tx_inputs_builder; 16 | pub use tx_inputs_builder::*; 17 | 18 | mod voting_builder; 19 | pub use voting_builder::*; 20 | 21 | mod voting_proposal_builder; 22 | pub use voting_proposal_builder::*; 23 | 24 | mod withdrawals_builder; 25 | pub use withdrawals_builder::*; 26 | 27 | mod output_builder; 28 | pub use output_builder::*; 29 | 30 | mod tx_builder; 31 | pub use tx_builder::*; 32 | 33 | mod tx_builder_constants; 34 | #[allow(unused_imports)] 35 | pub(crate) use tx_builder_constants::*; 36 | 37 | pub mod fakes; 38 | -------------------------------------------------------------------------------- /rust/src/serialization/map_names/certificate_index_names.rs: -------------------------------------------------------------------------------- 1 | #[derive(Eq, Hash, PartialEq, Clone, Debug, FromPrimitive, ToPrimitive)] 2 | pub(crate) enum CertificateIndexNames { 3 | StakeRegistrationLegacy = 0, 4 | StakeDeregistrationLegacy = 1, 5 | StakeDelegation = 2, 6 | PoolRegistration = 3, 7 | PoolRetirement = 4, 8 | GenesisKeyDelegation = 5, 9 | MoveInstantaneousRewardsCert = 6, 10 | StakeRegistrationConway = 7, 11 | StakeDeregistrationConway = 8, 12 | VoteDelegation = 9, 13 | StakeAndVoteDelegation = 10, 14 | StakeRegistrationAndDelegation = 11, 15 | VoteRegistrationAndDelegation = 12, 16 | StakeVoteRegistrationAndDelegation = 13, 17 | CommitteeHotAuth = 14, 18 | CommitteeColdResign = 15, 19 | DRepRegistration = 16, 20 | DRepDeregistration = 17, 21 | DRepUpdate = 18, 22 | } 23 | -------------------------------------------------------------------------------- /.github/workflows/_sonarqube.yml_: -------------------------------------------------------------------------------- 1 | name: SonarQube Checks 2 | 3 | on: 4 | # Trigger analysis when pushing to your main branches, and when creating a pull request. 5 | push: 6 | branches: 7 | - main 8 | - master 9 | - develop 10 | - 'releases/**' 11 | pull_request: 12 | types: [opened, synchronize, reopened] 13 | 14 | jobs: 15 | sonarqube: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - uses: actions/checkout@v2 19 | with: 20 | # Disabling shallow clone is recommended for improving relevancy of reporting 21 | fetch-depth: 0 22 | - name: SonarQube Scan 23 | uses: sonarsource/sonarqube-scan-action@v5.2.0 24 | with: 25 | projectBaseDir: "rust" 26 | env: 27 | SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} 28 | SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} 29 | -------------------------------------------------------------------------------- /rust/src/protocol_types/plutus/ex_unit_prices.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct ExUnitPrices { 17 | pub(crate) mem_price: SubCoin, 18 | pub(crate) step_price: SubCoin, 19 | } 20 | 21 | impl_to_from!(ExUnitPrices); 22 | 23 | #[wasm_bindgen] 24 | impl ExUnitPrices { 25 | pub fn mem_price(&self) -> SubCoin { 26 | self.mem_price.clone() 27 | } 28 | 29 | pub fn step_price(&self) -> SubCoin { 30 | self.step_price.clone() 31 | } 32 | 33 | pub fn new(mem_price: &SubCoin, step_price: &SubCoin) -> Self { 34 | Self { 35 | mem_price: mem_price.clone(), 36 | step_price: step_price.clone(), 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /templates/angular-asmjs/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | (id: string): T; 13 | keys(): string[]; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting(), 21 | ); 22 | 23 | // Then we find all the tests. 24 | const context = require.context('./', true, /\.spec\.ts$/); 25 | // And load the modules. 26 | context.keys().forEach(context); 27 | -------------------------------------------------------------------------------- /templates/angular-browser/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: { 11 | context(path: string, deep?: boolean, filter?: RegExp): { 12 | (id: string): T; 13 | keys(): string[]; 14 | }; 15 | }; 16 | 17 | // First, initialize the Angular testing environment. 18 | getTestBed().initTestEnvironment( 19 | BrowserDynamicTestingModule, 20 | platformBrowserDynamicTesting(), 21 | ); 22 | 23 | // Then we find all the tests. 24 | const context = require.context('./', true, /\.spec\.ts$/); 25 | // And load the modules. 26 | context.keys().forEach(context); 27 | -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/mod.rs: -------------------------------------------------------------------------------- 1 | mod impl_signature_macro; 2 | mod impl_hash_type_macro; 3 | 4 | mod bip32_private_key; 5 | pub use bip32_private_key::*; 6 | 7 | mod bip32_public_key; 8 | pub use bip32_public_key::*; 9 | 10 | mod private_key; 11 | pub use private_key::*; 12 | 13 | mod public_key; 14 | pub use public_key::*; 15 | 16 | mod macro_implemented_signature_types; 17 | pub use macro_implemented_signature_types::*; 18 | 19 | mod macro_implemented_hash_types; 20 | pub use macro_implemented_hash_types::*; 21 | 22 | mod vkey; 23 | pub use vkey::*; 24 | mod vkeys; 25 | pub use vkeys::*; 26 | 27 | mod public_keys; 28 | pub use public_keys::*; 29 | 30 | mod legacy_daedalus_private_key; 31 | pub use legacy_daedalus_private_key::*; 32 | 33 | mod kes_signature; 34 | pub use kes_signature::*; 35 | 36 | mod nonce; 37 | pub use nonce::*; 38 | 39 | mod vrf_cert; 40 | pub use vrf_cert::*; -------------------------------------------------------------------------------- /templates/react-asmjs/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 20vmin; 7 | pointer-events: none; 8 | } 9 | 10 | .App-warning { 11 | background-color:orangered; 12 | } 13 | 14 | .App-input { 15 | font-size: calc(10px + 2vmin); 16 | } 17 | 18 | 19 | @media (prefers-reduced-motion: no-preference) { 20 | .App-logo { 21 | animation: App-logo-spin infinite 20s linear; 22 | } 23 | } 24 | 25 | .App-header { 26 | background-color: #282c34; 27 | min-height: 100vh; 28 | display: flex; 29 | flex-direction: column; 30 | align-items: center; 31 | justify-content: top; 32 | font-size: calc(10px + 2vmin); 33 | color: white; 34 | } 35 | 36 | .App-link { 37 | color: #61dafb; 38 | } 39 | 40 | @keyframes App-logo-spin { 41 | from { 42 | transform: rotate(0deg); 43 | } 44 | to { 45 | transform: rotate(360deg); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /templates/react-browser/src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 20vmin; 7 | pointer-events: none; 8 | } 9 | 10 | .App-warning { 11 | background-color:orangered; 12 | } 13 | 14 | .App-input { 15 | font-size: calc(10px + 2vmin); 16 | } 17 | 18 | @media (prefers-reduced-motion: no-preference) { 19 | .App-logo { 20 | animation: App-logo-spin infinite 20s linear; 21 | } 22 | } 23 | 24 | .App-header { 25 | background-color: #282c34; 26 | min-height: 100vh; 27 | display: flex; 28 | flex-direction: column; 29 | align-items: center; 30 | justify-content: top; 31 | font-size: calc(10px + 2vmin); 32 | color: white; 33 | } 34 | 35 | .App-link { 36 | color: #61dafb; 37 | } 38 | 39 | @keyframes App-logo-spin { 40 | from { 41 | transform: rotate(0deg); 42 | } 43 | to { 44 | transform: rotate(360deg); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/src/protocol_types/block/fixed_tx_body.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, Debug, PartialEq)] 5 | /// Read-only view of a transaction body. With correct hash and original bytes. 6 | /// Warning: This is experimental and may be removed in the future. 7 | pub struct FixedTransactionBody { 8 | pub(crate) body: TransactionBody, 9 | pub(crate) tx_hash: TransactionHash, 10 | pub(crate) original_bytes: Vec, 11 | } 12 | 13 | from_bytes!(FixedTransactionBody); 14 | from_hex!(FixedTransactionBody); 15 | 16 | #[wasm_bindgen] 17 | impl FixedTransactionBody { 18 | 19 | pub fn transaction_body(&self) -> TransactionBody { 20 | self.body.clone() 21 | } 22 | 23 | pub fn tx_hash(&self) -> TransactionHash { 24 | self.tx_hash.clone() 25 | } 26 | 27 | pub fn original_bytes(&self) -> Vec { 28 | self.original_bytes.clone() 29 | } 30 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/legacy_daedalus_private_key.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::chain_crypto as crypto; 3 | 4 | #[wasm_bindgen] 5 | pub struct LegacyDaedalusPrivateKey(pub(crate) crypto::SecretKey); 6 | 7 | #[wasm_bindgen] 8 | impl LegacyDaedalusPrivateKey { 9 | pub fn from_bytes(bytes: &[u8]) -> Result { 10 | crypto::SecretKey::::from_binary(bytes) 11 | .map_err(|e| JsError::from_str(&format!("{}", e))) 12 | .map(LegacyDaedalusPrivateKey) 13 | } 14 | 15 | pub fn as_bytes(&self) -> Vec { 16 | self.0.as_ref().to_vec() 17 | } 18 | 19 | pub fn chaincode(&self) -> Vec { 20 | const ED25519_PRIVATE_KEY_LENGTH: usize = 64; 21 | const XPRV_SIZE: usize = 96; 22 | self.0.as_ref()[ED25519_PRIVATE_KEY_LENGTH..XPRV_SIZE].to_vec() 23 | } 24 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/governance_action_ids.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Eq, 7 | Ord, 8 | PartialEq, 9 | PartialOrd, 10 | Hash, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct GovernanceActionIds(pub(crate) Vec); 17 | 18 | to_from_json!(GovernanceActionIds); 19 | 20 | #[wasm_bindgen] 21 | impl GovernanceActionIds { 22 | pub fn new() -> Self { 23 | Self(Vec::new()) 24 | } 25 | 26 | pub fn add(&mut self, governance_action_id: &GovernanceActionId) { 27 | self.0.push(governance_action_id.clone()); 28 | } 29 | 30 | pub fn get(&self, index: usize) -> Option { 31 | self.0.get(index).cloned() 32 | } 33 | 34 | pub fn len(&self) -> usize { 35 | self.0.len() 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/pool_retirement.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct PoolRetirement { 17 | pub(crate) pool_keyhash: Ed25519KeyHash, 18 | pub(crate) epoch: Epoch, 19 | } 20 | 21 | impl_to_from!(PoolRetirement); 22 | 23 | #[wasm_bindgen] 24 | impl PoolRetirement { 25 | pub fn pool_keyhash(&self) -> Ed25519KeyHash { 26 | self.pool_keyhash.clone() 27 | } 28 | 29 | pub fn epoch(&self) -> Epoch { 30 | self.epoch.clone() 31 | } 32 | 33 | pub fn new(pool_keyhash: &Ed25519KeyHash, epoch: Epoch) -> Self { 34 | Self { 35 | pool_keyhash: pool_keyhash.clone(), 36 | epoch: epoch, 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/anchor.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct Anchor { 17 | pub(crate) anchor_url: URL, 18 | pub(crate) anchor_data_hash: AnchorDataHash, 19 | } 20 | 21 | impl_to_from!(Anchor); 22 | 23 | #[wasm_bindgen] 24 | impl Anchor { 25 | pub fn url(&self) -> URL { 26 | self.anchor_url.clone() 27 | } 28 | 29 | pub fn anchor_data_hash(&self) -> AnchorDataHash { 30 | self.anchor_data_hash.clone() 31 | } 32 | 33 | pub fn new(anchor_url: &URL, anchor_data_hash: &AnchorDataHash) -> Self { 34 | Self { 35 | anchor_url: anchor_url.clone(), 36 | anchor_data_hash: anchor_data_hash.clone(), 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rust/src/serialization/block/fixed_transaction_bodies.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::is_break_tag; 3 | 4 | impl Deserialize for FixedTransactionBodies { 5 | fn deserialize(raw: &mut Deserializer) -> Result { 6 | let mut arr = Vec::new(); 7 | (|| -> Result<_, DeserializeError> { 8 | let len = raw.array()?; 9 | while match len { 10 | cbor_event::Len::Len(n) => arr.len() < n as usize, 11 | cbor_event::Len::Indefinite => true, 12 | } { 13 | if is_break_tag(raw, "FixedTransactionBodies")? { 14 | break; 15 | } 16 | arr.push(FixedTransactionBody::deserialize(raw)?); 17 | } 18 | Ok(()) 19 | })() 20 | .map_err(|e| e.annotate("FixedTransactionBodies"))?; 21 | Ok(Self(arr)) 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /rust/src/serialization/block/versioned_block.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::utils::{check_len, check_len_indefinite}; 2 | use crate::*; 3 | 4 | impl Serialize for VersionedBlock { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(Len::Len(2))?; 10 | self.era_code.serialize(serializer)?; 11 | self.block.serialize(serializer) 12 | } 13 | } 14 | 15 | impl Deserialize for VersionedBlock { 16 | fn deserialize(raw: &mut Deserializer) -> Result { 17 | let len = raw.array()?; 18 | check_len(len, 2, "VersionedBlock")?; 19 | let era_code = u32::deserialize(raw)?; 20 | let block = Block::deserialize(raw)?; 21 | check_len_indefinite(raw, len)?; 22 | Ok(VersionedBlock { era_code, block }) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/mod.rs: -------------------------------------------------------------------------------- 1 | mod parameter_change_action; 2 | pub use parameter_change_action::*; 3 | 4 | mod hard_fork_initiation_action; 5 | pub use hard_fork_initiation_action::*; 6 | 7 | mod treasury_withdrawals_action; 8 | pub use treasury_withdrawals_action::*; 9 | 10 | mod treasury_withdrawals; 11 | pub use treasury_withdrawals::*; 12 | 13 | mod no_confidence_action; 14 | pub use no_confidence_action::*; 15 | 16 | mod committee; 17 | pub use committee::*; 18 | 19 | mod update_committee_action; 20 | pub use update_committee_action::*; 21 | 22 | mod constitution; 23 | pub use constitution::*; 24 | 25 | mod new_constitution_action; 26 | pub use new_constitution_action::*; 27 | 28 | mod info_action; 29 | pub use info_action::*; 30 | 31 | mod governance_action; 32 | pub use governance_action::*; 33 | 34 | mod voting_proposal; 35 | pub use voting_proposal::*; 36 | 37 | mod voting_proposals; 38 | pub use voting_proposals::*; 39 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/no_confidence_action.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct NoConfidenceAction { 17 | pub(crate) gov_action_id: Option, 18 | } 19 | 20 | impl_to_from!(NoConfidenceAction); 21 | 22 | #[wasm_bindgen] 23 | impl NoConfidenceAction { 24 | pub fn gov_action_id(&self) -> Option { 25 | self.gov_action_id.clone() 26 | } 27 | 28 | pub fn new() -> Self { 29 | Self { 30 | gov_action_id: None, 31 | } 32 | } 33 | 34 | pub fn new_with_action_id(gov_action_id: &GovernanceActionId) -> Self { 35 | Self { 36 | gov_action_id: Some(gov_action_id.clone()), 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/csl-example/csl-example.component.html: -------------------------------------------------------------------------------- 1 |

2 |
3 |
4 | 7 |

8 | 14 |
15 |

16 |
17 | 20 |

21 | 24 |

25 |
26 |

27 |
28 | 31 |

32 | 35 |

36 |
37 |

38 |
39 | -------------------------------------------------------------------------------- /templates/angular-browser/src/app/csl-example/csl-example.component.html: -------------------------------------------------------------------------------- 1 |

2 |
3 |
4 | 7 |

8 | 14 |
15 |

16 |
17 | 20 |

21 | 24 |

25 |
26 |

27 |
28 | 31 |

32 | 35 |

36 |
37 |

38 |
39 | -------------------------------------------------------------------------------- /rust/src/serialization/witnesses/fixed_tx_witnesses_set.rs: -------------------------------------------------------------------------------- 1 | use std::io::{BufRead, Seek, Write}; 2 | use cbor_event::de::Deserializer; 3 | use cbor_event::se::Serializer; 4 | use crate::protocol_types::{Deserialize, FixedTxWitnessesSet}; 5 | use crate::{DeserializeError}; 6 | 7 | impl cbor_event::se::Serialize for FixedTxWitnessesSet { 8 | fn serialize<'a, W: Write + Sized>(&self, serializer: &'a mut Serializer) -> cbor_event::Result<&'a mut Serializer> { 9 | super::transaction_witnesses_set::serialize(self.tx_witnesses_set_ref(), Some(self.raw_parts_ref()), serializer) 10 | } 11 | } 12 | 13 | impl Deserialize for FixedTxWitnessesSet { 14 | fn deserialize(raw: &mut Deserializer) -> Result 15 | where 16 | Self: Sized 17 | { 18 | let (witness_set, raw_parts) = super::transaction_witnesses_set::deserialize(raw, true)?; 19 | Ok(Self::new(witness_set, raw_parts)) 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /.github/workflows/gh-issue-to-jira-task.yml: -------------------------------------------------------------------------------- 1 | on: 2 | issues: 3 | types: [opened] 4 | 5 | name: Jira Actions 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | name: Create Jira task 11 | steps: 12 | - name: Login 13 | uses: atlassian/gajira-login@master 14 | env: 15 | JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} 16 | JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} 17 | JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} 18 | 19 | - name: Jira Create issue 20 | uses: atlassian/gajira-create@v3 21 | id: create 22 | with: 23 | project: SERLIB 24 | issuetype: Task 25 | summary: GH-${{ github.event.issue.number }}. ${{ github.event.issue.title }} 26 | description: | 27 | ${{ github.event.issue.html_url }} 28 | ${{ github.event.issue.body }} 29 | 30 | 31 | - name: Log created issue 32 | run: echo "Issue ${{ steps.create.outputs.issue }} was created" -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/governance_action_id.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Eq, 7 | Ord, 8 | PartialEq, 9 | PartialOrd, 10 | Hash, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct GovernanceActionId { 17 | pub(crate) transaction_id: TransactionHash, 18 | pub(crate) index: GovernanceActionIndex, 19 | } 20 | 21 | impl_to_from!(GovernanceActionId); 22 | 23 | #[wasm_bindgen] 24 | impl GovernanceActionId { 25 | pub fn transaction_id(&self) -> TransactionHash { 26 | self.transaction_id.clone() 27 | } 28 | 29 | pub fn index(&self) -> GovernanceActionIndex { 30 | self.index.clone() 31 | } 32 | 33 | pub fn new(transaction_id: &TransactionHash, index: GovernanceActionIndex) -> Self { 34 | Self { 35 | transaction_id: transaction_id.clone(), 36 | index: index, 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rust/src/protocol_types/block/fixed_versioned_block.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, Debug, PartialEq)] 5 | /// Warning: This is experimental and may be removed in the future. 6 | pub struct FixedVersionedBlock { 7 | pub(crate) block: FixedBlock, 8 | pub(crate) era_code: u32, 9 | } 10 | 11 | from_bytes!(FixedVersionedBlock); 12 | from_hex!(FixedVersionedBlock); 13 | 14 | #[wasm_bindgen] 15 | impl FixedVersionedBlock { 16 | pub fn block(&self) -> FixedBlock { 17 | self.block.clone() 18 | } 19 | 20 | pub fn era(&self) -> BlockEra { 21 | match self.era_code { 22 | 0 => BlockEra::Byron, 23 | 1 => BlockEra::Byron, 24 | 2 => BlockEra::Shelley, 25 | 3 => BlockEra::Allegra, 26 | 4 => BlockEra::Mary, 27 | 5 => BlockEra::Alonzo, 28 | 6 => BlockEra::Babbage, 29 | 7 => BlockEra::Conway, 30 | _ => BlockEra::Unknown, 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /templates/react-browser/config-overrides.js: -------------------------------------------------------------------------------- 1 | const webpack = require('webpack'); 2 | 3 | module.exports = function override(webpackConfig, env) { 4 | const wasmExtensionRegExp = /\.wasm$/; 5 | webpackConfig.resolve.extensions.push('.wasm'); 6 | webpackConfig.experiments = { 7 | asyncWebAssembly: true, 8 | //lazyCompilation: true, 9 | syncWebAssembly: true, 10 | topLevelAwait: true, 11 | }; 12 | webpackConfig.module.rules.forEach((rule) => { 13 | (rule.oneOf || []).forEach((oneOf) => { 14 | if (oneOf.type === "asset/resource") { 15 | oneOf.exclude.push(wasmExtensionRegExp); 16 | } 17 | }); 18 | }); 19 | webpackConfig.plugins.push(new webpack.ProvidePlugin({ 20 | Buffer: ['buffer', 'Buffer'], 21 | })); 22 | 23 | return webpackConfig; 24 | } -------------------------------------------------------------------------------- /templates/angular-asmjs/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitOverride": true, 10 | "noPropertyAccessFromIndexSignature": true, 11 | "noImplicitReturns": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "sourceMap": true, 14 | "declaration": false, 15 | "downlevelIteration": true, 16 | "experimentalDecorators": true, 17 | "moduleResolution": "node", 18 | "importHelpers": true, 19 | "target": "es2020", 20 | "module": "es2020", 21 | "lib": [ 22 | "es2020", 23 | "dom" 24 | ] 25 | }, 26 | "angularCompilerOptions": { 27 | "enableI18nLegacyMessageIdFormat": false, 28 | "strictInjectionParameters": true, 29 | "strictInputAccessModifiers": true, 30 | "strictTemplates": true 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /templates/angular-browser/tsconfig.json: -------------------------------------------------------------------------------- 1 | /* To learn more about this file see: https://angular.io/config/tsconfig. */ 2 | { 3 | "compileOnSave": false, 4 | "compilerOptions": { 5 | "baseUrl": "./", 6 | "outDir": "./dist/out-tsc", 7 | "forceConsistentCasingInFileNames": true, 8 | "strict": true, 9 | "noImplicitOverride": true, 10 | "noPropertyAccessFromIndexSignature": true, 11 | "noImplicitReturns": true, 12 | "noFallthroughCasesInSwitch": true, 13 | "sourceMap": true, 14 | "declaration": false, 15 | "downlevelIteration": true, 16 | "experimentalDecorators": true, 17 | "moduleResolution": "node", 18 | "importHelpers": true, 19 | "target": "es2020", 20 | "module": "es2020", 21 | "lib": [ 22 | "es2020", 23 | "dom" 24 | ] 25 | }, 26 | "angularCompilerOptions": { 27 | "enableI18nLegacyMessageIdFormat": false, 28 | "strictInjectionParameters": true, 29 | "strictInputAccessModifiers": true, 30 | "strictTemplates": true 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/vote_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct VoteDelegation { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) drep: DRep, 19 | } 20 | 21 | impl_to_from!(VoteDelegation); 22 | 23 | #[wasm_bindgen] 24 | impl VoteDelegation { 25 | pub fn stake_credential(&self) -> Credential { 26 | self.stake_credential.clone() 27 | } 28 | 29 | pub fn drep(&self) -> DRep { 30 | self.drep.clone() 31 | } 32 | 33 | pub fn new(stake_credential: &Credential, drep: &DRep) -> Self { 34 | Self { 35 | stake_credential: stake_credential.clone(), 36 | drep: drep.clone(), 37 | } 38 | } 39 | 40 | pub fn has_script_credentials(&self) -> bool { 41 | self.stake_credential.has_script_hash() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/macro_implemented_hash_types.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | impl_hash_type!(Ed25519KeyHash, 28); 4 | impl_hash_type!(ScriptHash, 28); 5 | impl_hash_type!(AnchorDataHash, 32); 6 | impl_hash_type!(TransactionHash, 32); 7 | impl_hash_type!(GenesisDelegateHash, 28); 8 | impl_hash_type!(GenesisHash, 28); 9 | impl_hash_type!(AuxiliaryDataHash, 32); 10 | impl_hash_type!(PoolMetadataHash, 32); 11 | impl_hash_type!(VRFKeyHash, 32); 12 | impl_hash_type!(BlockHash, 32); 13 | impl_hash_type!(DataHash, 32); 14 | impl_hash_type!(ScriptDataHash, 32); 15 | // We might want to make these two vkeys normal classes later but for now it's just arbitrary bytes for us (used in block parsing) 16 | impl_hash_type!(VRFVKey, 32); 17 | impl_hash_type!(KESVKey, 32); 18 | // same for this signature 19 | //impl_hash_type!(KESSignature, 448); 20 | // TODO: when >32 size trait implementations are out of nightly and into stable 21 | // remove the following manual struct definition and use the above macro again if we 22 | // don't have proper crypto implementations for it. -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/drep_deregistration.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct DRepDeregistration { 17 | pub(crate) voting_credential: Credential, 18 | pub(crate) coin: Coin, 19 | } 20 | 21 | impl_to_from!(DRepDeregistration); 22 | 23 | #[wasm_bindgen] 24 | impl DRepDeregistration { 25 | pub fn voting_credential(&self) -> Credential { 26 | self.voting_credential.clone() 27 | } 28 | 29 | pub fn coin(&self) -> Coin { 30 | self.coin.clone() 31 | } 32 | 33 | pub fn new(voting_credential: &Credential, coin: &Coin) -> Self { 34 | Self { 35 | voting_credential: voting_credential.clone(), 36 | coin: coin.clone(), 37 | } 38 | } 39 | 40 | pub fn has_script_credentials(&self) -> bool { 41 | self.voting_credential.has_script_hash() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/treasury_withdrawals.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use std::collections::BTreeMap; 3 | 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | Hash, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | #[wasm_bindgen] 17 | pub struct TreasuryWithdrawals(pub(crate) BTreeMap); 18 | 19 | to_from_json!(TreasuryWithdrawals); 20 | 21 | #[wasm_bindgen] 22 | impl TreasuryWithdrawals { 23 | pub fn new() -> Self { 24 | Self(BTreeMap::new()) 25 | } 26 | 27 | pub fn get(&self, key: &RewardAddress) -> Option { 28 | self.0.get(key).cloned() 29 | } 30 | 31 | pub fn insert(&mut self, key: &RewardAddress, value: &Coin) { 32 | self.0.insert(key.clone(), value.clone()); 33 | } 34 | 35 | pub fn keys(&self) -> RewardAddresses { 36 | RewardAddresses(self.0.keys().cloned().collect()) 37 | } 38 | 39 | pub fn len(&self) -> usize { 40 | self.0.len() 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/language.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | impl cbor_event::se::Serialize for Language { 4 | fn serialize<'se, W: Write>( 5 | &self, 6 | serializer: &'se mut Serializer, 7 | ) -> cbor_event::Result<&'se mut Serializer> { 8 | // https://github.com/input-output-hk/cardano-ledger/blob/master/eras/babbage/test-suite/cddl-files/babbage.cddl#L324-L327 9 | serializer.write_unsigned_integer(self.kind() as u64) 10 | } 11 | } 12 | 13 | impl Deserialize for Language { 14 | fn deserialize(raw: &mut Deserializer) -> Result { 15 | (|| -> Result<_, DeserializeError> { 16 | match LanguageKind::from_u64(raw.unsigned_integer()?) { 17 | Some(kind) => Ok(Language(kind)), 18 | _ => Err(DeserializeError::new( 19 | "Language", 20 | DeserializeFailure::NoVariantMatched.into(), 21 | )), 22 | } 23 | })() 24 | .map_err(|e| e.annotate("Language")) 25 | } 26 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/vrf_cert.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, Debug, Eq, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize, JsonSchema, 6 | )] 7 | pub struct VRFCert { 8 | pub(crate) output: Vec, 9 | pub(crate) proof: Vec, 10 | } 11 | 12 | impl VRFCert { 13 | pub const PROOF_LEN: usize = 80; 14 | } 15 | 16 | impl_to_from!(VRFCert); 17 | 18 | #[wasm_bindgen] 19 | impl VRFCert { 20 | pub fn output(&self) -> Vec { 21 | self.output.clone() 22 | } 23 | 24 | pub fn proof(&self) -> Vec { 25 | self.proof.clone() 26 | } 27 | 28 | pub fn new(output: Vec, proof: Vec) -> Result { 29 | if proof.len() != Self::PROOF_LEN { 30 | return Err(JsError::from_str(&format!( 31 | "proof len must be {} - found {}", 32 | Self::PROOF_LEN, 33 | proof.len() 34 | ))); 35 | } 36 | Ok(Self { 37 | output: output, 38 | proof: proof, 39 | }) 40 | } 41 | } -------------------------------------------------------------------------------- /rust/src/serialization/numeric/int.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::read_nint; 3 | 4 | impl cbor_event::se::Serialize for Int { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | if self.0 < 0 { 10 | serializer.write_negative_integer(self.0 as i64) 11 | } else { 12 | serializer.write_unsigned_integer(self.0 as u64) 13 | } 14 | } 15 | } 16 | 17 | impl Deserialize for Int { 18 | fn deserialize(raw: &mut Deserializer) -> Result { 19 | (|| -> Result<_, DeserializeError> { 20 | match raw.cbor_type()? { 21 | cbor_event::Type::UnsignedInteger => Ok(Self(raw.unsigned_integer()? as i128)), 22 | cbor_event::Type::NegativeInteger => Ok(Self(read_nint(raw)?)), 23 | _ => Err(DeserializeFailure::NoVariantMatched.into()), 24 | } 25 | })() 26 | .map_err(|e| e.annotate("Int")) 27 | } 28 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/constitution.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Eq, 7 | Ord, 8 | PartialEq, 9 | PartialOrd, 10 | Hash, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct Constitution { 17 | pub(crate) anchor: Anchor, 18 | pub(crate) script_hash: Option, 19 | } 20 | 21 | impl_to_from!(Constitution); 22 | 23 | #[wasm_bindgen] 24 | impl Constitution { 25 | pub fn anchor(&self) -> Anchor { 26 | self.anchor.clone() 27 | } 28 | 29 | pub fn script_hash(&self) -> Option { 30 | self.script_hash.clone() 31 | } 32 | 33 | pub fn new(anchor: &Anchor) -> Self { 34 | Self { 35 | anchor: anchor.clone(), 36 | script_hash: None, 37 | } 38 | } 39 | 40 | pub fn new_with_script_hash(anchor: &Anchor, script_hash: &ScriptHash) -> Self { 41 | Self { 42 | anchor: anchor.clone(), 43 | script_hash: Some(script_hash.clone()), 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/stake_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct StakeDelegation { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) pool_keyhash: Ed25519KeyHash, 19 | } 20 | 21 | impl_to_from!(StakeDelegation); 22 | 23 | #[wasm_bindgen] 24 | impl StakeDelegation { 25 | pub fn stake_credential(&self) -> Credential { 26 | self.stake_credential.clone() 27 | } 28 | 29 | pub fn pool_keyhash(&self) -> Ed25519KeyHash { 30 | self.pool_keyhash.clone() 31 | } 32 | 33 | pub fn new(stake_credential: &Credential, pool_keyhash: &Ed25519KeyHash) -> Self { 34 | Self { 35 | stake_credential: stake_credential.clone(), 36 | pool_keyhash: pool_keyhash.clone(), 37 | } 38 | } 39 | 40 | pub fn has_script_credentials(&self) -> bool { 41 | self.stake_credential.has_script_hash() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rust/src/serialization/governance/proposals/constitution.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::utils::check_len; 2 | use crate::*; 3 | 4 | impl Serialize for Constitution { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(cbor_event::Len::Len(2))?; 10 | self.anchor.serialize(serializer)?; 11 | self.script_hash.serialize_nullable(serializer)?; 12 | Ok(serializer) 13 | } 14 | } 15 | 16 | impl_deserialize_for_wrapped_tuple!(Constitution); 17 | 18 | impl DeserializeEmbeddedGroup for Constitution { 19 | fn deserialize_as_embedded_group( 20 | raw: &mut Deserializer, 21 | len: cbor_event::Len, 22 | ) -> Result { 23 | check_len(len, 2, "(anchor, scripthash / null)")?; 24 | let anchor = Anchor::deserialize(raw)?; 25 | let script_hash = ScriptHash::deserialize_nullable(raw)?; 26 | 27 | Ok(Constitution { 28 | anchor, 29 | script_hash, 30 | }) 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /LICENSE-IOHK: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018-2019 Input Output HK 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /templates/angular-browser/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async () => { 6 | await TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | }); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'cls-angular-test'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.componentInstance; 22 | expect(app.title).toEqual('cls-angular-test'); 23 | }); 24 | 25 | it('should render title', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.nativeElement as HTMLElement; 29 | expect(compiled.querySelector('.content span')?.textContent).toContain('cls-angular-test app is running!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /rust/src/protocol_types/tx_input.rs: -------------------------------------------------------------------------------- 1 | use std::fmt::Formatter; 2 | use crate::*; 3 | 4 | #[wasm_bindgen] 5 | #[derive( 6 | Clone, 7 | Debug, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | Hash, 13 | serde::Serialize, 14 | serde::Deserialize, 15 | JsonSchema, 16 | )] 17 | pub struct TransactionInput { 18 | pub(crate) transaction_id: TransactionHash, 19 | pub(crate) index: TransactionIndex, 20 | } 21 | 22 | impl_to_from!(TransactionInput); 23 | 24 | #[wasm_bindgen] 25 | impl TransactionInput { 26 | pub fn transaction_id(&self) -> TransactionHash { 27 | self.transaction_id.clone() 28 | } 29 | 30 | pub fn index(&self) -> TransactionIndex { 31 | self.index.clone() 32 | } 33 | 34 | pub fn new(transaction_id: &TransactionHash, index: TransactionIndex) -> Self { 35 | Self { 36 | transaction_id: transaction_id.clone(), 37 | index: index, 38 | } 39 | } 40 | } 41 | 42 | impl Display for TransactionInput { 43 | fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { 44 | write!(f, "{}#{}", self.transaction_id, self.index) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed } from '@angular/core/testing'; 2 | import { AppComponent } from './app.component'; 3 | 4 | describe('AppComponent', () => { 5 | beforeEach(async () => { 6 | await TestBed.configureTestingModule({ 7 | declarations: [ 8 | AppComponent 9 | ], 10 | }).compileComponents(); 11 | }); 12 | 13 | it('should create the app', () => { 14 | const fixture = TestBed.createComponent(AppComponent); 15 | const app = fixture.componentInstance; 16 | expect(app).toBeTruthy(); 17 | }); 18 | 19 | it(`should have as title 'csl-angular-test-asmjs'`, () => { 20 | const fixture = TestBed.createComponent(AppComponent); 21 | const app = fixture.componentInstance; 22 | expect(app.title).toEqual('csl-angular-test-asmjs'); 23 | }); 24 | 25 | it('should render title', () => { 26 | const fixture = TestBed.createComponent(AppComponent); 27 | fixture.detectChanges(); 28 | const compiled = fixture.nativeElement as HTMLElement; 29 | expect(compiled.querySelector('.content span')?.textContent).toContain('csl-angular-test-asmjs app is running!'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /rust/src/protocol_types/crypto/nonce.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | // Evolving nonce type (used for Update's crypto) 4 | #[wasm_bindgen] 5 | #[derive( 6 | Clone, 7 | Debug, 8 | Hash, 9 | Eq, 10 | Ord, 11 | PartialEq, 12 | PartialOrd, 13 | serde::Serialize, 14 | serde::Deserialize, 15 | JsonSchema, 16 | )] 17 | pub struct Nonce { 18 | pub(crate) hash: Option<[u8; 32]>, 19 | } 20 | 21 | impl_to_from!(Nonce); 22 | 23 | // can't export consts via wasm_bindgen 24 | impl Nonce { 25 | pub const HASH_LEN: usize = 32; 26 | } 27 | 28 | #[wasm_bindgen] 29 | impl Nonce { 30 | pub fn new_identity() -> Nonce { 31 | Self { hash: None } 32 | } 33 | 34 | pub fn new_from_hash(hash: Vec) -> Result { 35 | use std::convert::TryInto; 36 | match hash[..Self::HASH_LEN].try_into() { 37 | Ok(bytes_correct_size) => Ok(Self { 38 | hash: Some(bytes_correct_size), 39 | }), 40 | Err(e) => Err(JsError::from_str(&e.to_string())), 41 | } 42 | } 43 | 44 | pub fn get_hash(&self) -> Option> { 45 | Some(self.hash?.to_vec()) 46 | } 47 | } -------------------------------------------------------------------------------- /templates/react-asmjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csl-react-test-asmjs", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emurgo/cardano-serialization-lib-asmjs": "^11.3.0", 7 | "@testing-library/jest-dom": "^5.16.5", 8 | "@testing-library/react": "^13.4.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-scripts": "5.0.1", 13 | "web-vitals": "^2.1.4" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts --max_old_space_size=8048 start", 17 | "build": "react-scripts --max_old_space_size=8048 build", 18 | "test": "react-scripts --max_old_space_size=8048 test8", 19 | "eject": "react-scripts --max_old_space_size=8048 eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /templates/angular-asmjs/src/app/csl-example/csl-example.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { BigNum } from "@emurgo/cardano-serialization-lib-asmjs"; 3 | 4 | @Component({ 5 | selector: 'app-csl-example', 6 | templateUrl: './csl-example.component.html', 7 | styleUrls: ['./csl-example.component.css'] 8 | }) 9 | export class CslExampleComponent implements OnInit { 10 | enteredValue: string = ""; 11 | hexValue: string = ""; 12 | jsonValue: string = ""; 13 | 14 | constructor() { } 15 | 16 | ngOnInit(): void { 17 | } 18 | 19 | containsOnlyNumbers = (strValue: any) => { 20 | return /^\d+$/.test(strValue); 21 | } 22 | 23 | getBigNumValue = (strValue: any) => { 24 | return BigNum.from_str(strValue) 25 | }; 26 | 27 | toBigNum = (inputEvent: any) => { 28 | this.enteredValue = inputEvent; 29 | if (this.containsOnlyNumbers(inputEvent)) { 30 | this.hexValue = this.getBigNumValue(inputEvent).to_hex(); 31 | this.jsonValue = this.getBigNumValue(inputEvent).to_json(); 32 | } else { 33 | this.hexValue = "unexpected value"; 34 | this.jsonValue = "unexpected value"; 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /templates/angular-browser/src/app/csl-example/csl-example.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { BigNum } from "@emurgo/cardano-serialization-lib-browser"; 3 | 4 | @Component({ 5 | selector: 'app-csl-example', 6 | templateUrl: './csl-example.component.html', 7 | styleUrls: ['./csl-example.component.css'] 8 | }) 9 | export class CslExampleComponent implements OnInit { 10 | enteredValue: string = ""; 11 | hexValue: string = ""; 12 | jsonValue: string = ""; 13 | 14 | constructor() { } 15 | 16 | ngOnInit(): void { 17 | } 18 | 19 | containsOnlyNumbers = (strValue: any) => { 20 | return /^\d+$/.test(strValue); 21 | } 22 | 23 | getBigNumValue = (strValue: any) => { 24 | return BigNum.from_str(strValue) 25 | }; 26 | 27 | toBigNum = (inputEvent: any) => { 28 | this.enteredValue = inputEvent; 29 | if (this.containsOnlyNumbers(inputEvent)) { 30 | this.hexValue = this.getBigNumValue(inputEvent).to_hex(); 31 | this.jsonValue = this.getBigNumValue(inputEvent).to_json(); 32 | } else { 33 | this.hexValue = "unexpected value"; 34 | this.jsonValue = "unexpected value"; 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /rust/src/protocol_types/mod.rs: -------------------------------------------------------------------------------- 1 | //TODO: move all protocol types to this module 2 | mod fixed_tx; 3 | pub use fixed_tx::*; 4 | 5 | mod certificates; 6 | pub use certificates::*; 7 | 8 | mod governance; 9 | pub use governance::*; 10 | 11 | mod plutus; 12 | pub use plutus::*; 13 | 14 | mod metadata; 15 | pub use metadata::*; 16 | 17 | mod transaction_body; 18 | pub use transaction_body::*; 19 | 20 | mod protocol_param_update; 21 | pub use protocol_param_update::*; 22 | 23 | mod address; 24 | pub use address::*; 25 | 26 | mod tx_input; 27 | pub use tx_input::*; 28 | 29 | mod tx_inputs; 30 | pub use tx_inputs::*; 31 | 32 | mod credential; 33 | pub use credential::*; 34 | 35 | mod credentials; 36 | pub use credentials::*; 37 | 38 | mod ed25519_key_hashes; 39 | pub use ed25519_key_hashes::*; 40 | 41 | mod witnesses; 42 | pub use witnesses::*; 43 | 44 | mod crypto; 45 | pub use crypto::*; 46 | 47 | mod native_script; 48 | pub use native_script::*; 49 | 50 | mod native_scripts; 51 | pub use native_scripts::*; 52 | 53 | mod numeric; 54 | pub use numeric::*; 55 | 56 | mod script_ref; 57 | pub use script_ref::*; 58 | 59 | mod block; 60 | pub use block::*; 61 | 62 | mod pointer; 63 | pub use pointer::*; 64 | -------------------------------------------------------------------------------- /templates/angular-asmjs/README.md: -------------------------------------------------------------------------------- 1 | # CslAngularTestAsmjs 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.2.10. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /templates/angular-browser/README.md: -------------------------------------------------------------------------------- 1 | # ClsAngularTest 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 14.2.10. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The application will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities. 24 | 25 | ## Further help 26 | 27 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page. 28 | -------------------------------------------------------------------------------- /rust/src/protocol_types/block/operational_cert.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, PartialEq, Debug, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub struct OperationalCert { 6 | pub(crate) hot_vkey: KESVKey, 7 | pub(crate) sequence_number: u32, 8 | pub(crate) kes_period: u32, 9 | pub(crate) sigma: Ed25519Signature, 10 | } 11 | 12 | impl_to_from!(OperationalCert); 13 | 14 | #[wasm_bindgen] 15 | impl OperationalCert { 16 | pub fn hot_vkey(&self) -> KESVKey { 17 | self.hot_vkey.clone() 18 | } 19 | 20 | pub fn sequence_number(&self) -> u32 { 21 | self.sequence_number.clone() 22 | } 23 | 24 | pub fn kes_period(&self) -> u32 { 25 | self.kes_period.clone() 26 | } 27 | 28 | pub fn sigma(&self) -> Ed25519Signature { 29 | self.sigma.clone() 30 | } 31 | 32 | pub fn new( 33 | hot_vkey: &KESVKey, 34 | sequence_number: u32, 35 | kes_period: u32, 36 | sigma: &Ed25519Signature, 37 | ) -> Self { 38 | Self { 39 | hot_vkey: hot_vkey.clone(), 40 | sequence_number: sequence_number, 41 | kes_period: kes_period, 42 | sigma: sigma.clone(), 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/committee_hot_auth.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct CommitteeHotAuth { 17 | pub(crate) committee_cold_credential: Credential, 18 | pub(crate) committee_hot_credential: Credential, 19 | } 20 | 21 | impl_to_from!(CommitteeHotAuth); 22 | 23 | #[wasm_bindgen] 24 | impl CommitteeHotAuth { 25 | pub fn committee_cold_credential(&self) -> Credential { 26 | self.committee_cold_credential.clone() 27 | } 28 | 29 | pub fn committee_hot_credential(&self) -> Credential { 30 | self.committee_hot_credential.clone() 31 | } 32 | 33 | pub fn new(committee_cold_credential: &Credential, committee_hot_credential: &Credential) -> Self { 34 | Self { 35 | committee_cold_credential: committee_cold_credential.clone(), 36 | committee_hot_credential: committee_hot_credential.clone(), 37 | } 38 | } 39 | 40 | pub fn has_script_credentials(&self) -> bool { 41 | self.committee_cold_credential.has_script_hash() 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rust/src/protocol_types/witnesses/bootstrap_witness.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Debug, Eq, PartialEq, Hash, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub struct BootstrapWitness { 6 | pub(crate) vkey: Vkey, 7 | pub(crate) signature: Ed25519Signature, 8 | pub(crate) chain_code: Vec, 9 | pub(crate) attributes: Vec, 10 | } 11 | 12 | impl_to_from!(BootstrapWitness); 13 | 14 | #[wasm_bindgen] 15 | impl BootstrapWitness { 16 | pub fn vkey(&self) -> Vkey { 17 | self.vkey.clone() 18 | } 19 | 20 | pub fn signature(&self) -> Ed25519Signature { 21 | self.signature.clone() 22 | } 23 | 24 | pub fn chain_code(&self) -> Vec { 25 | self.chain_code.clone() 26 | } 27 | 28 | pub fn attributes(&self) -> Vec { 29 | self.attributes.clone() 30 | } 31 | 32 | pub fn new( 33 | vkey: &Vkey, 34 | signature: &Ed25519Signature, 35 | chain_code: Vec, 36 | attributes: Vec, 37 | ) -> Self { 38 | Self { 39 | vkey: vkey.clone(), 40 | signature: signature.clone(), 41 | chain_code: chain_code, 42 | attributes: attributes, 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/vote_registration_and_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct VoteRegistrationAndDelegation { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) drep: DRep, 19 | pub(crate) coin: Coin, 20 | } 21 | 22 | impl_to_from!(VoteRegistrationAndDelegation); 23 | 24 | #[wasm_bindgen] 25 | impl VoteRegistrationAndDelegation { 26 | pub fn stake_credential(&self) -> Credential { 27 | self.stake_credential.clone() 28 | } 29 | 30 | pub fn drep(&self) -> DRep { 31 | self.drep.clone() 32 | } 33 | 34 | pub fn coin(&self) -> Coin { 35 | self.coin.clone() 36 | } 37 | 38 | pub fn new(stake_credential: &Credential, drep: &DRep, coin: &Coin) -> Self { 39 | Self { 40 | stake_credential: stake_credential.clone(), 41 | drep: drep.clone(), 42 | coin: coin.clone(), 43 | } 44 | } 45 | 46 | pub fn has_script_credentials(&self) -> bool { 47 | self.stake_credential.has_script_hash() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /rust/src/serialization/crypto/kes_signature.rs: -------------------------------------------------------------------------------- 1 | use cbor_event::de::Deserializer; 2 | use cbor_event::se::Serializer; 3 | use crate::{DeserializeError, DeserializeFailure, KESSignature}; 4 | use crate::protocol_types::Deserialize; 5 | 6 | impl cbor_event::se::Serialize for KESSignature { 7 | fn serialize<'se, W: std::io::Write>( 8 | &self, 9 | serializer: &'se mut Serializer, 10 | ) -> cbor_event::Result<&'se mut Serializer> { 11 | serializer.write_bytes(&self.0) 12 | } 13 | } 14 | 15 | impl Deserialize for KESSignature { 16 | fn deserialize( 17 | raw: &mut Deserializer, 18 | ) -> Result { 19 | (|| -> Result { 20 | let bytes = raw.bytes()?; 21 | if bytes.len() != Self::BYTE_COUNT { 22 | return Err(DeserializeFailure::CBOR(cbor_event::Error::WrongLen( 23 | Self::BYTE_COUNT as u64, 24 | cbor_event::Len::Len(bytes.len() as u64), 25 | "hash length", 26 | )) 27 | .into()); 28 | } 29 | Ok(KESSignature(bytes)) 30 | })() 31 | .map_err(|e| e.annotate("KESSignature")) 32 | } 33 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 EMURGO 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | Includes other software related under the MIT license: 24 | - chain-libs, Copyright 2018-2019 IOHK. For licensing see /LICENSE-IOHK 25 | -------------------------------------------------------------------------------- /templates/react-browser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csl_react_test", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emurgo/cardano-serialization-lib-browser": "^11.2.1", 7 | "@testing-library/jest-dom": "^5.16.5", 8 | "@testing-library/react": "^13.4.0", 9 | "@testing-library/user-event": "^13.5.0", 10 | "react": "^18.2.0", 11 | "react-dom": "^18.2.0", 12 | "react-scripts": "5.0.1", 13 | "web-vitals": "^2.1.4" 14 | }, 15 | "scripts": { 16 | "start": "react-app-rewired start", 17 | "build": "react-app-rewired build", 18 | "test": "react-app-rewired test", 19 | "eject": "react-app-rewired eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | }, 39 | "devDependencies": { 40 | "@babel/plugin-syntax-jsx": "^7.18.6", 41 | "@babel/preset-react": "^7.18.6", 42 | "react-app-rewired": "^2.2.1", 43 | "webpack-cli": "^5.0.1" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /test/1.diag: -------------------------------------------------------------------------------- 1 | [h'64616D6E696679', h'65787465726E697A6174696F6E', h'7374726570746F6E657572616C', 2309, 4432, h'647261667473776F6D616E73686970', 30([3427, 2195]), h'476C6F62756C61726961', 2687, 2821, h'73757065726163726F6D69616C', h'7365726F74696E65', h'696E69717569746F7573', 3685, 95, h'63686F6E64726F67656E79', 2111, 4529, 732, h'6D75636564696E65', [{0: 258([[h'666C756E6B79697368', 2523], [h'626564636C6F74686573', 3992], [h'76696E6567617265747465', 3046], [h'73616665626C6F77696E67', 4340]]), 1: [[3, h'73757363657074616E6365', h'64656772616475617465', 4688], [3, h'6170746E657373', h'666572726F7072696E74', 2032], [8, h'696E6465636F6D706F7361626C656E657373', 770], [6, h'73687275626C616E64', 2918]], 4: 3790, 5: 1502, 7: h'747261636B'}, {0: 258([[h'717569636B74686F726E', 1996]]), 1: [[2, h'6E6F6E6469766F726365', h'7079726F6C79746963', 3082], [1, h'7370656374726F70686F6E65', h'7175697A7A6963616C6C79', 2912]], 3: {[0, h'476F626965736F6369646165']: 2336, [2, h'64657874726F75736E657373']: 1038, [1, h'726570616E656C']: 4704}, 4: 1897, 5: 918, 6: [{}, {}]}], [0, [h'626162796F6C61747279', h'43617068'], 0, [h'726F756E64697368', h'7068797369636F6D65646963616C'], 4, [[h'6D617363756C79', h'636F6E73756C7461746F7279']], []], {1208: [[h'41737465726F73706F6E64796C69', h'7465726E65', -519], "uncommemorated"], 697: -523, 437: 3991}] 2 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/drep_update.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct DRepUpdate { 17 | pub(crate) voting_credential: Credential, 18 | pub(crate) anchor: Option, 19 | } 20 | 21 | impl_to_from!(DRepUpdate); 22 | 23 | #[wasm_bindgen] 24 | impl DRepUpdate { 25 | pub fn voting_credential(&self) -> Credential { 26 | self.voting_credential.clone() 27 | } 28 | 29 | pub fn anchor(&self) -> Option { 30 | self.anchor.clone() 31 | } 32 | 33 | pub fn new(voting_credential: &Credential) -> Self { 34 | Self { 35 | voting_credential: voting_credential.clone(), 36 | anchor: None, 37 | } 38 | } 39 | 40 | pub fn new_with_anchor(voting_credential: &Credential, anchor: &Anchor) -> Self { 41 | Self { 42 | voting_credential: voting_credential.clone(), 43 | anchor: Some(anchor.clone()), 44 | } 45 | } 46 | 47 | pub fn has_script_credentials(&self) -> bool { 48 | self.voting_credential.has_script_hash() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /templates/angular-browser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cls-angular-test", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "build": "ng build", 8 | "watch": "ng build --watch --configuration development", 9 | "test": "ng test" 10 | }, 11 | "private": true, 12 | "dependencies": { 13 | "@angular/animations": "^14.2.0", 14 | "@angular/common": "^14.2.0", 15 | "@angular/compiler": "^14.2.0", 16 | "@angular/core": "^14.2.0", 17 | "@angular/forms": "^14.2.0", 18 | "@angular/platform-browser": "^14.2.0", 19 | "@angular/platform-browser-dynamic": "^14.2.0", 20 | "@angular/router": "^14.2.0", 21 | "@emurgo/cardano-serialization-lib-browser": "^11.3.0", 22 | "rxjs": "~7.5.0", 23 | "tslib": "^2.3.0", 24 | "zone.js": "~0.11.4" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "^14.2.10", 28 | "@angular/cli": "~14.2.10", 29 | "@angular/compiler-cli": "^14.2.0", 30 | "@types/jasmine": "~4.0.0", 31 | "jasmine-core": "~4.3.0", 32 | "karma": "~6.4.0", 33 | "karma-chrome-launcher": "~3.1.0", 34 | "karma-coverage": "~2.2.0", 35 | "karma-jasmine": "~5.1.0", 36 | "karma-jasmine-html-reporter": "~2.0.0", 37 | "typescript": "~4.7.2" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/stake_registration.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct StakeRegistration { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) coin: Option, 19 | } 20 | 21 | impl_to_from!(StakeRegistration); 22 | 23 | #[wasm_bindgen] 24 | impl StakeRegistration { 25 | pub fn stake_credential(&self) -> Credential { 26 | self.stake_credential.clone() 27 | } 28 | 29 | pub fn coin(&self) -> Option { 30 | self.coin.clone() 31 | } 32 | 33 | pub fn new(stake_credential: &Credential) -> Self { 34 | Self { 35 | stake_credential: stake_credential.clone(), 36 | coin: None, 37 | } 38 | } 39 | 40 | pub fn new_with_explicit_deposit(stake_credential: &Credential, coin: &Coin) -> Self { 41 | Self { 42 | stake_credential: stake_credential.clone(), 43 | coin: Some(coin.clone()), 44 | } 45 | } 46 | 47 | pub fn has_script_credentials(&self) -> bool { 48 | self.stake_credential.has_script_hash() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/strings.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::is_break_tag; 3 | 4 | impl cbor_event::se::Serialize for Strings { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; 10 | for element in &self.0 { 11 | serializer.write_text(&element)?; 12 | } 13 | Ok(serializer) 14 | } 15 | } 16 | 17 | impl Deserialize for Strings { 18 | fn deserialize(raw: &mut Deserializer) -> Result { 19 | let mut arr = Vec::new(); 20 | (|| -> Result<_, DeserializeError> { 21 | let len = raw.array()?; 22 | while match len { 23 | cbor_event::Len::Len(n) => arr.len() < n as usize, 24 | cbor_event::Len::Indefinite => true, 25 | } { 26 | if is_break_tag(raw, "Strings")? { 27 | break; 28 | } 29 | arr.push(String::deserialize(raw)?); 30 | } 31 | Ok(()) 32 | })() 33 | .map_err(|e| e.annotate("Strings"))?; 34 | Ok(Self(arr)) 35 | } 36 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/stake_deregistration.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct StakeDeregistration { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) coin: Option, 19 | } 20 | 21 | impl_to_from!(StakeDeregistration); 22 | 23 | #[wasm_bindgen] 24 | impl StakeDeregistration { 25 | pub fn stake_credential(&self) -> Credential { 26 | self.stake_credential.clone() 27 | } 28 | 29 | pub fn coin(&self) -> Option { 30 | self.coin.clone() 31 | } 32 | 33 | pub fn new(stake_credential: &Credential) -> Self { 34 | Self { 35 | stake_credential: stake_credential.clone(), 36 | coin: None, 37 | } 38 | } 39 | 40 | pub fn new_with_explicit_refund(stake_credential: &Credential, coin: &Coin) -> Self { 41 | Self { 42 | stake_credential: stake_credential.clone(), 43 | coin: Some(coin.clone()), 44 | } 45 | } 46 | 47 | pub fn has_script_credentials(&self) -> bool { 48 | self.stake_credential.has_script_hash() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/languages.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::is_break_tag; 3 | 4 | impl cbor_event::se::Serialize for Languages { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; 10 | for element in &self.0 { 11 | element.serialize(serializer)?; 12 | } 13 | Ok(serializer) 14 | } 15 | } 16 | 17 | impl Deserialize for Languages { 18 | fn deserialize(raw: &mut Deserializer) -> Result { 19 | let mut arr = Vec::new(); 20 | (|| -> Result<_, DeserializeError> { 21 | let len = raw.array()?; 22 | while match len { 23 | cbor_event::Len::Len(n) => arr.len() < n as usize, 24 | cbor_event::Len::Indefinite => true, 25 | } { 26 | if is_break_tag(raw, "Languages")? { 27 | break; 28 | } 29 | arr.push(Language::deserialize(raw)?); 30 | } 31 | Ok(()) 32 | })() 33 | .map_err(|e| e.annotate("Languages"))?; 34 | Ok(Self(arr)) 35 | } 36 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/stake_and_vote_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct StakeAndVoteDelegation { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) pool_keyhash: Ed25519KeyHash, 19 | pub(crate) drep: DRep, 20 | } 21 | 22 | impl_to_from!(StakeAndVoteDelegation); 23 | 24 | #[wasm_bindgen] 25 | impl StakeAndVoteDelegation { 26 | pub fn stake_credential(&self) -> Credential { 27 | self.stake_credential.clone() 28 | } 29 | 30 | pub fn pool_keyhash(&self) -> Ed25519KeyHash { 31 | self.pool_keyhash.clone() 32 | } 33 | 34 | pub fn drep(&self) -> DRep { 35 | self.drep.clone() 36 | } 37 | 38 | pub fn new(stake_credential: &Credential, pool_keyhash: &Ed25519KeyHash, drep: &DRep) -> Self { 39 | Self { 40 | stake_credential: stake_credential.clone(), 41 | pool_keyhash: pool_keyhash.clone(), 42 | drep: drep.clone(), 43 | } 44 | } 45 | 46 | pub fn has_script_credentials(&self) -> bool { 47 | self.stake_credential.has_script_hash() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/cost_model.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::is_break_tag; 3 | 4 | impl cbor_event::se::Serialize for CostModel { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; 10 | for cost in &self.0 { 11 | cost.serialize(serializer)?; 12 | } 13 | Ok(serializer) 14 | } 15 | } 16 | 17 | impl Deserialize for CostModel { 18 | fn deserialize(raw: &mut Deserializer) -> Result { 19 | let mut arr = Vec::new(); 20 | (|| -> Result<_, DeserializeError> { 21 | let len = raw.array()?; 22 | while match len { 23 | cbor_event::Len::Len(n) => arr.len() < n as usize, 24 | cbor_event::Len::Indefinite => true, 25 | } { 26 | if is_break_tag(raw, "CostModel")? { 27 | break; 28 | } 29 | arr.push(Int::deserialize(raw)?); 30 | } 31 | Ok(()) 32 | })() 33 | .map_err(|e| e.annotate("CostModel"))?; 34 | Ok(Self(arr.try_into().unwrap())) 35 | } 36 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/genesis_key_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Debug, 7 | Hash, 8 | Eq, 9 | Ord, 10 | PartialEq, 11 | PartialOrd, 12 | serde::Serialize, 13 | serde::Deserialize, 14 | JsonSchema, 15 | )] 16 | pub struct GenesisKeyDelegation { 17 | pub(crate) genesishash: GenesisHash, 18 | pub(crate) genesis_delegate_hash: GenesisDelegateHash, 19 | pub(crate) vrf_keyhash: VRFKeyHash, 20 | } 21 | 22 | impl_to_from!(GenesisKeyDelegation); 23 | 24 | #[wasm_bindgen] 25 | impl GenesisKeyDelegation { 26 | pub fn genesishash(&self) -> GenesisHash { 27 | self.genesishash.clone() 28 | } 29 | 30 | pub fn genesis_delegate_hash(&self) -> GenesisDelegateHash { 31 | self.genesis_delegate_hash.clone() 32 | } 33 | 34 | pub fn vrf_keyhash(&self) -> VRFKeyHash { 35 | self.vrf_keyhash.clone() 36 | } 37 | 38 | pub fn new( 39 | genesishash: &GenesisHash, 40 | genesis_delegate_hash: &GenesisDelegateHash, 41 | vrf_keyhash: &VRFKeyHash, 42 | ) -> Self { 43 | Self { 44 | genesishash: genesishash.clone(), 45 | genesis_delegate_hash: genesis_delegate_hash.clone(), 46 | vrf_keyhash: vrf_keyhash.clone(), 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/stake_registration_and_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct StakeRegistrationAndDelegation { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) pool_keyhash: Ed25519KeyHash, 19 | pub(crate) coin: Coin, 20 | } 21 | 22 | impl_to_from!(StakeRegistrationAndDelegation); 23 | 24 | #[wasm_bindgen] 25 | impl StakeRegistrationAndDelegation { 26 | pub fn stake_credential(&self) -> Credential { 27 | self.stake_credential.clone() 28 | } 29 | 30 | pub fn pool_keyhash(&self) -> Ed25519KeyHash { 31 | self.pool_keyhash.clone() 32 | } 33 | 34 | pub fn coin(&self) -> Coin { 35 | self.coin.clone() 36 | } 37 | 38 | pub fn new(stake_credential: &Credential, pool_keyhash: &Ed25519KeyHash, coin: &Coin) -> Self { 39 | Self { 40 | stake_credential: stake_credential.clone(), 41 | pool_keyhash: pool_keyhash.clone(), 42 | coin: coin.clone(), 43 | } 44 | } 45 | 46 | pub fn has_script_credentials(&self) -> bool { 47 | self.stake_credential.has_script_hash() 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/hard_fork_initiation_action.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct HardForkInitiationAction { 17 | pub(crate) gov_action_id: Option, 18 | pub(crate) protocol_version: ProtocolVersion, 19 | } 20 | 21 | impl_to_from!(HardForkInitiationAction); 22 | 23 | #[wasm_bindgen] 24 | impl HardForkInitiationAction { 25 | pub fn gov_action_id(&self) -> Option { 26 | self.gov_action_id.clone() 27 | } 28 | 29 | pub fn protocol_version(&self) -> ProtocolVersion { 30 | self.protocol_version.clone() 31 | } 32 | 33 | pub fn new(protocol_version: &ProtocolVersion) -> Self { 34 | Self { 35 | gov_action_id: None, 36 | protocol_version: protocol_version.clone(), 37 | } 38 | } 39 | 40 | pub fn new_with_action_id( 41 | gov_action_id: &GovernanceActionId, 42 | protocol_version: &ProtocolVersion, 43 | ) -> Self { 44 | Self { 45 | gov_action_id: Some(gov_action_id.clone()), 46 | protocol_version: protocol_version.clone(), 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /rust/src/serialization/block/transaction_bodies.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::is_break_tag; 3 | 4 | impl cbor_event::se::Serialize for TransactionBodies { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; 10 | for element in &self.0 { 11 | element.serialize(serializer)?; 12 | } 13 | Ok(serializer) 14 | } 15 | } 16 | 17 | impl Deserialize for TransactionBodies { 18 | fn deserialize(raw: &mut Deserializer) -> Result { 19 | let mut arr = Vec::new(); 20 | (|| -> Result<_, DeserializeError> { 21 | let len = raw.array()?; 22 | while match len { 23 | cbor_event::Len::Len(n) => arr.len() < n as usize, 24 | cbor_event::Len::Indefinite => true, 25 | } { 26 | if is_break_tag(raw, "TransactionBodies")? { 27 | break; 28 | } 29 | arr.push(TransactionBody::deserialize(raw)?); 30 | } 31 | Ok(()) 32 | })() 33 | .map_err(|e| e.annotate("TransactionBodies"))?; 34 | Ok(Self(arr)) 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rust/src/protocol_types/block/versioned_block.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, PartialEq, Debug, serde::Serialize, serde::Deserialize, JsonSchema)] 5 | pub enum BlockEra { 6 | Byron, 7 | Shelley, 8 | Allegra, 9 | Mary, 10 | Alonzo, 11 | Babbage, 12 | Conway, 13 | Unknown 14 | } 15 | 16 | #[wasm_bindgen] 17 | #[derive(Clone, Eq, Debug, PartialEq, serde::Serialize, serde::Deserialize, JsonSchema)] 18 | pub struct VersionedBlock { 19 | pub(crate) era_code: u32, 20 | pub(crate) block: Block, 21 | } 22 | 23 | impl_to_from!(VersionedBlock); 24 | 25 | #[wasm_bindgen] 26 | impl VersionedBlock { 27 | pub fn new(block: Block, era_code: u32) -> VersionedBlock { 28 | VersionedBlock { 29 | block, 30 | era_code, 31 | } 32 | } 33 | 34 | pub fn block(&self) -> Block { 35 | self.block.clone() 36 | } 37 | 38 | pub fn era(&self) -> BlockEra { 39 | match self.era_code { 40 | 0 => BlockEra::Byron, 41 | 1 => BlockEra::Byron, 42 | 2 => BlockEra::Shelley, 43 | 3 => BlockEra::Allegra, 44 | 4 => BlockEra::Mary, 45 | 5 => BlockEra::Alonzo, 46 | 6 => BlockEra::Babbage, 47 | 7 => BlockEra::Conway, 48 | _ => BlockEra::Unknown, 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/voting_procedure.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub enum VoteKind { 17 | No = 0, 18 | Yes = 1, 19 | Abstain = 2, 20 | } 21 | 22 | #[derive( 23 | Clone, 24 | Debug, 25 | Hash, 26 | Eq, 27 | Ord, 28 | PartialEq, 29 | PartialOrd, 30 | serde::Serialize, 31 | serde::Deserialize, 32 | JsonSchema, 33 | )] 34 | #[wasm_bindgen] 35 | pub struct VotingProcedure { 36 | pub(crate) vote: VoteKind, 37 | pub(crate) anchor: Option, 38 | } 39 | 40 | impl_to_from!(VotingProcedure); 41 | 42 | #[wasm_bindgen] 43 | impl VotingProcedure { 44 | pub fn new(vote: VoteKind) -> Self { 45 | Self { 46 | vote: vote.clone(), 47 | anchor: None, 48 | } 49 | } 50 | 51 | pub fn new_with_anchor(vote: VoteKind, anchor: &Anchor) -> Self { 52 | Self { 53 | vote: vote.clone(), 54 | anchor: Some(anchor.clone()), 55 | } 56 | } 57 | 58 | pub fn vote_kind(&self) -> VoteKind { 59 | self.vote.clone() 60 | } 61 | 62 | pub fn anchor(&self) -> Option { 63 | self.anchor.clone() 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /rust/src/serialization/governance/proposals/info_action.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::utils:: serialize_and_check_index; 2 | use crate::serialization::{check_len, deserialize_and_check_index}; 3 | use crate::*; 4 | use map_names::VotingProposalIndexNames; 5 | use num_traits::ToPrimitive; 6 | 7 | impl cbor_event::se::Serialize for InfoAction { 8 | fn serialize<'se, W: Write>( 9 | &self, 10 | serializer: &'se mut Serializer, 11 | ) -> cbor_event::Result<&'se mut Serializer> { 12 | serializer.write_array(cbor_event::Len::Len(1))?; 13 | 14 | let proposal_index = VotingProposalIndexNames::InfoAction.to_u64(); 15 | serialize_and_check_index(serializer, proposal_index, "InfoAction")?; 16 | 17 | Ok(serializer) 18 | } 19 | } 20 | 21 | impl_deserialize_for_wrapped_tuple!(InfoAction); 22 | 23 | impl DeserializeEmbeddedGroup for InfoAction { 24 | fn deserialize_as_embedded_group( 25 | raw: &mut Deserializer, 26 | len: cbor_event::Len, 27 | ) -> Result { 28 | check_len( 29 | len, 30 | 1, 31 | "(proposal_index)", 32 | )?; 33 | 34 | let desired_index = VotingProposalIndexNames::InfoAction.to_u64(); 35 | deserialize_and_check_index(raw, desired_index, "proposal_index")?; 36 | 37 | return Ok(InfoAction()); 38 | } 39 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/committee_cold_resign.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct CommitteeColdResign { 17 | pub(crate) committee_cold_credential: Credential, 18 | pub(crate) anchor: Option, 19 | } 20 | 21 | impl_to_from!(CommitteeColdResign); 22 | 23 | #[wasm_bindgen] 24 | impl CommitteeColdResign { 25 | pub fn committee_cold_credential(&self) -> Credential { 26 | self.committee_cold_credential.clone() 27 | } 28 | 29 | pub fn anchor(&self) -> Option { 30 | self.anchor.clone() 31 | } 32 | 33 | pub fn new(committee_cold_credential: &Credential) -> Self { 34 | Self { 35 | committee_cold_credential: committee_cold_credential.clone(), 36 | anchor: None, 37 | } 38 | } 39 | 40 | pub fn new_with_anchor(committee_cold_credential: &Credential, anchor: &Anchor) -> Self { 41 | Self { 42 | committee_cold_credential: committee_cold_credential.clone(), 43 | anchor: Some(anchor.clone()), 44 | } 45 | } 46 | 47 | pub fn has_script_credentials(&self) -> bool { 48 | self.committee_cold_credential.has_script_hash() 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/treasury_withdrawals_action.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct TreasuryWithdrawalsAction { 17 | pub(crate) withdrawals: TreasuryWithdrawals, 18 | pub(crate) policy_hash: Option, 19 | } 20 | 21 | impl_to_from!(TreasuryWithdrawalsAction); 22 | 23 | #[wasm_bindgen] 24 | impl TreasuryWithdrawalsAction { 25 | pub fn withdrawals(&self) -> TreasuryWithdrawals { 26 | self.withdrawals.clone() 27 | } 28 | 29 | pub fn policy_hash(&self) -> Option { 30 | self.policy_hash.clone() 31 | } 32 | 33 | pub fn new(withdrawals: &TreasuryWithdrawals) -> Self { 34 | Self { 35 | withdrawals: withdrawals.clone(), 36 | policy_hash: None, 37 | } 38 | } 39 | 40 | pub fn new_with_policy_hash( 41 | withdrawals: &TreasuryWithdrawals, 42 | policy_hash: &ScriptHash, 43 | ) -> Self { 44 | Self { 45 | withdrawals: withdrawals.clone(), 46 | policy_hash: Some(policy_hash.clone()), 47 | } 48 | } 49 | 50 | pub(crate) fn has_script_hash(&self) -> bool { 51 | self.policy_hash.is_some() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/new_constitution_action.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct NewConstitutionAction { 17 | pub(crate) gov_action_id: Option, 18 | pub(crate) constitution: Constitution, 19 | } 20 | 21 | impl_to_from!(NewConstitutionAction); 22 | 23 | #[wasm_bindgen] 24 | impl NewConstitutionAction { 25 | pub fn gov_action_id(&self) -> Option { 26 | self.gov_action_id.clone() 27 | } 28 | 29 | pub fn constitution(&self) -> Constitution { 30 | self.constitution.clone() 31 | } 32 | 33 | pub fn new(constitution: &Constitution) -> Self { 34 | Self { 35 | gov_action_id: None, 36 | constitution: constitution.clone(), 37 | } 38 | } 39 | 40 | pub fn new_with_action_id( 41 | gov_action_id: &GovernanceActionId, 42 | constitution: &Constitution, 43 | ) -> Self { 44 | Self { 45 | gov_action_id: Some(gov_action_id.clone()), 46 | constitution: constitution.clone(), 47 | } 48 | } 49 | 50 | pub fn has_script_hash(&self) -> bool { 51 | self.constitution.script_hash.is_some() 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "cracoConfig": "craco.config.js", 6 | "dependencies": { 7 | "@emurgo/cardano-serialization-lib-browser": "14.1.0", 8 | "@testing-library/dom": "^10.4.0", 9 | "@testing-library/jest-dom": "^6.6.3", 10 | "@testing-library/react": "^16.2.0", 11 | "@testing-library/user-event": "^13.5.0", 12 | "@types/jest": "^27.5.2", 13 | "@types/node": "^16.18.126", 14 | "@types/react": "^19.0.10", 15 | "@types/react-dom": "^19.0.4", 16 | "react": "^19.0.0", 17 | "react-dom": "^19.0.0", 18 | "web-vitals": "^2.1.4" 19 | }, 20 | "scripts": { 21 | "start": "craco start --config craco.config.js", 22 | "build": "CI=false && craco build", 23 | "test": "craco test", 24 | "eject": "craco eject" 25 | }, 26 | "eslintConfig": { 27 | "extends": [ 28 | "react-app", 29 | "react-app/jest" 30 | ] 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | }, 44 | "devDependencies": { 45 | "@craco/craco": "^7.1.0", 46 | "bip39": "^3.1.0", 47 | "buffer": "^6.0.3", 48 | "react-scripts": "^5.0.1", 49 | "typescript": "^5.7.3" 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /templates/angular-asmjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "csl-angular-test-asmjs", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "NODE_OPTIONS=--max_old_space_size=8048 ng serve", 7 | "build": "NODE_OPTIONS=--max_old_space_size=8048 ng build", 8 | "watch": "NODE_OPTIONS=--max_old_space_size=8048 ng build --watch --configuration development", 9 | "test": "NODE_OPTIONS=--max_old_space_size=8048 ng test" 10 | }, 11 | "private": true, 12 | "dependencies": { 13 | "@angular/animations": "^14.2.0", 14 | "@angular/common": "^14.2.0", 15 | "@angular/compiler": "^14.2.0", 16 | "@angular/core": "^14.2.0", 17 | "@angular/forms": "^14.2.0", 18 | "@angular/platform-browser": "^14.2.0", 19 | "@angular/platform-browser-dynamic": "^14.2.0", 20 | "@angular/router": "^14.2.0", 21 | "@emurgo/cardano-serialization-lib-asmjs": "^11.3.0", 22 | "rxjs": "~7.5.0", 23 | "tslib": "^2.3.0", 24 | "zone.js": "~0.11.4" 25 | }, 26 | "devDependencies": { 27 | "@angular-devkit/build-angular": "^14.2.10", 28 | "@angular/cli": "~14.2.10", 29 | "@angular/compiler-cli": "^14.2.0", 30 | "@types/jasmine": "~4.0.0", 31 | "jasmine-core": "~4.3.0", 32 | "karma": "~6.4.0", 33 | "karma-chrome-launcher": "~3.1.0", 34 | "karma-coverage": "~2.2.0", 35 | "karma-jasmine": "~5.1.0", 36 | "karma-jasmine-html-reporter": "~2.0.0", 37 | "typescript": "~4.7.2" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Example how to use the Cardano Serialization Lib 2 | 3 | The example includes the dApp with four basic operations: 4 | 5 | * Creating a simple transaction 6 | * Registering a wallet staking public key 7 | * Unregistering a wallet staking key 8 | * Vote delegation 9 | 10 | ## Structure 11 | 12 | Everything related to the user interface (UI) is located in the folder `./src/components-ui`. 13 | 14 | The logic behind each operation is found in the folder `./src/components-logic` which has the same name. 15 | 16 | Commonly used functions are placed in the file `./src/componets-logic/core.ts`. 17 | 18 | ### Example 19 | 20 | Let's take a look at the file `TransactionCreator.tsx`. 21 | 22 | It contains only UI and it is located in the folder `./src/components-ui`. 23 | 24 | All logic related to this file is placed in the file `TransactionCreator.ts`, which is located in the `./src/components-logic` folder. 25 | 26 | ## Installation and running 27 | 28 | ### Instalation 29 | 30 | To install the app, go to the `./example` folder. If you're reading this, you're already here. 31 | 32 | Run the commands `nvm use` and then `npm install --force`. 33 | 34 | That's it! The app is now ready to launch. 35 | 36 | ### Running 37 | 38 | To start the app, simply run the command `npm start`. 39 | 40 | ## Conclusion 41 | 42 | This is a simple and not very attractive app, but it does what it should: show you how to work with the Cardano Serialization Lib. 43 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/mod.rs: -------------------------------------------------------------------------------- 1 | mod certificate; 2 | pub use certificate::*; 3 | 4 | mod certificates_collection; 5 | pub use certificates_collection::*; 6 | 7 | mod genesis_key_delegation; 8 | pub use genesis_key_delegation::*; 9 | 10 | mod move_instantaneous_rewards_cert; 11 | pub use move_instantaneous_rewards_cert::*; 12 | 13 | mod pool_registration; 14 | pub use pool_registration::*; 15 | 16 | mod pool_retirement; 17 | pub use pool_retirement::*; 18 | 19 | mod stake_delegation; 20 | pub use stake_delegation::*; 21 | 22 | mod stake_deregistration; 23 | pub use stake_deregistration::*; 24 | 25 | mod stake_registration; 26 | pub use stake_registration::*; 27 | 28 | mod vote_delegation; 29 | pub use vote_delegation::*; 30 | 31 | mod stake_and_vote_delegation; 32 | pub use stake_and_vote_delegation::*; 33 | 34 | mod stake_registration_and_delegation; 35 | pub use stake_registration_and_delegation::*; 36 | 37 | mod stake_vote_registration_and_delegation; 38 | pub use stake_vote_registration_and_delegation::*; 39 | 40 | mod vote_registration_and_delegation; 41 | pub use vote_registration_and_delegation::*; 42 | 43 | mod committee_hot_auth; 44 | pub use committee_hot_auth::*; 45 | 46 | mod committee_cold_resign; 47 | pub use committee_cold_resign::*; 48 | 49 | mod drep_registration; 50 | pub use drep_registration::*; 51 | 52 | mod drep_deregistration; 53 | pub use drep_deregistration::*; 54 | 55 | mod drep_update; 56 | pub use drep_update::*; 57 | -------------------------------------------------------------------------------- /rust/src/protocol_types/block/fixed_block.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive(Clone, Eq, Debug, PartialEq)] 5 | /// Read only view of a block with more strict structs for hash sensitive structs. 6 | /// Warning: This is experimental and may be removed or changed in the future. 7 | pub struct FixedBlock { 8 | pub(crate) header: Header, 9 | pub(crate) transaction_bodies: FixedTransactionBodies, 10 | pub(crate) transaction_witness_sets: TransactionWitnessSets, 11 | pub(crate) auxiliary_data_set: AuxiliaryDataSet, 12 | pub(crate) invalid_transactions: TransactionIndexes, 13 | pub(crate) block_hash: BlockHash, 14 | } 15 | 16 | from_bytes!(FixedBlock); 17 | from_hex!(FixedBlock); 18 | 19 | #[wasm_bindgen] 20 | impl FixedBlock { 21 | pub fn header(&self) -> Header { 22 | self.header.clone() 23 | } 24 | 25 | pub fn transaction_bodies(&self) -> FixedTransactionBodies { 26 | self.transaction_bodies.clone() 27 | } 28 | 29 | pub fn transaction_witness_sets(&self) -> TransactionWitnessSets { 30 | self.transaction_witness_sets.clone() 31 | } 32 | 33 | pub fn auxiliary_data_set(&self) -> AuxiliaryDataSet { 34 | self.auxiliary_data_set.clone() 35 | } 36 | 37 | pub fn invalid_transactions(&self) -> TransactionIndexes { 38 | self.invalid_transactions.clone() 39 | } 40 | 41 | pub fn block_hash(&self) -> BlockHash { 42 | self.block_hash.clone() 43 | } 44 | } -------------------------------------------------------------------------------- /rust/src/serialization/crypto/vkeys.rs: -------------------------------------------------------------------------------- 1 | use std::io::{BufRead, Seek, Write}; 2 | use cbor_event::de::Deserializer; 3 | use cbor_event::se::Serializer; 4 | use crate::{DeserializeError, Vkey, Vkeys}; 5 | use crate::protocol_types::Deserialize; 6 | use crate::serialization::utils::is_break_tag; 7 | 8 | impl cbor_event::se::Serialize for Vkeys { 9 | fn serialize<'se, W: Write>( 10 | &self, 11 | serializer: &'se mut Serializer, 12 | ) -> cbor_event::Result<&'se mut Serializer> { 13 | serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; 14 | for element in &self.0 { 15 | element.serialize(serializer)?; 16 | } 17 | Ok(serializer) 18 | } 19 | } 20 | 21 | impl Deserialize for Vkeys { 22 | fn deserialize(raw: &mut Deserializer) -> Result { 23 | let mut arr = Vec::new(); 24 | (|| -> Result<_, DeserializeError> { 25 | let len = raw.array()?; 26 | while match len { 27 | cbor_event::Len::Len(n) => arr.len() < n as usize, 28 | cbor_event::Len::Indefinite => true, 29 | } { 30 | if is_break_tag(raw, "Vkeys")? { 31 | break; 32 | } 33 | arr.push(Vkey::deserialize(raw)?); 34 | } 35 | Ok(()) 36 | })() 37 | .map_err(|e| e.annotate("Vkeys"))?; 38 | Ok(Self(arr)) 39 | } 40 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/plutus/redeemer_tag.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Copy, 6 | Clone, 7 | Debug, 8 | Hash, 9 | Eq, 10 | Ord, 11 | PartialEq, 12 | PartialOrd, 13 | serde::Serialize, 14 | serde::Deserialize, 15 | JsonSchema, 16 | )] 17 | pub enum RedeemerTagKind { 18 | Spend, 19 | Mint, 20 | Cert, 21 | Reward, 22 | Vote, 23 | VotingProposal, 24 | } 25 | 26 | #[wasm_bindgen] 27 | #[derive( 28 | Clone, 29 | Debug, 30 | Hash, 31 | Eq, 32 | Ord, 33 | PartialEq, 34 | PartialOrd, 35 | serde::Serialize, 36 | serde::Deserialize, 37 | JsonSchema, 38 | )] 39 | pub struct RedeemerTag(pub(crate) RedeemerTagKind); 40 | 41 | impl_to_from!(RedeemerTag); 42 | 43 | #[wasm_bindgen] 44 | impl RedeemerTag { 45 | pub fn new_spend() -> Self { 46 | Self(RedeemerTagKind::Spend) 47 | } 48 | 49 | pub fn new_mint() -> Self { 50 | Self(RedeemerTagKind::Mint) 51 | } 52 | 53 | pub fn new_cert() -> Self { 54 | Self(RedeemerTagKind::Cert) 55 | } 56 | 57 | pub fn new_reward() -> Self { 58 | Self(RedeemerTagKind::Reward) 59 | } 60 | 61 | pub fn new_vote() -> Self { 62 | Self(RedeemerTagKind::Vote) 63 | } 64 | 65 | pub fn new_voting_proposal() -> Self { 66 | Self(RedeemerTagKind::VotingProposal) 67 | } 68 | 69 | pub fn kind(&self) -> RedeemerTagKind { 70 | self.0 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /rust/src/protocol_types/plutus/language.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[wasm_bindgen] 4 | #[derive( 5 | Clone, 6 | Copy, 7 | Debug, 8 | Hash, 9 | Eq, 10 | Ord, 11 | PartialEq, 12 | PartialOrd, 13 | serde::Serialize, 14 | serde::Deserialize, 15 | JsonSchema, 16 | )] 17 | pub enum LanguageKind { 18 | PlutusV1 = 0, 19 | PlutusV2 = 1, 20 | PlutusV3 = 2, 21 | } 22 | 23 | impl LanguageKind { 24 | pub(crate) fn from_u64(x: u64) -> Option { 25 | match x { 26 | 0 => Some(LanguageKind::PlutusV1), 27 | 1 => Some(LanguageKind::PlutusV2), 28 | 2 => Some(LanguageKind::PlutusV3), 29 | _ => None, 30 | } 31 | } 32 | } 33 | 34 | #[wasm_bindgen] 35 | #[derive( 36 | Clone, 37 | Copy, 38 | Debug, 39 | Hash, 40 | Eq, 41 | Ord, 42 | PartialEq, 43 | PartialOrd, 44 | serde::Serialize, 45 | serde::Deserialize, 46 | JsonSchema, 47 | )] 48 | pub struct Language(pub(crate) LanguageKind); 49 | 50 | impl_to_from!(Language); 51 | 52 | #[wasm_bindgen] 53 | impl Language { 54 | pub fn new_plutus_v1() -> Self { 55 | Self(LanguageKind::PlutusV1) 56 | } 57 | 58 | pub fn new_plutus_v2() -> Self { 59 | Self(LanguageKind::PlutusV2) 60 | } 61 | 62 | pub fn new_plutus_v3() -> Self { 63 | Self(LanguageKind::PlutusV3) 64 | } 65 | 66 | pub fn kind(&self) -> LanguageKind { 67 | self.0.clone() 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/drep_registration.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct DRepRegistration { 17 | pub(crate) voting_credential: Credential, 18 | pub(crate) coin: Coin, 19 | pub(crate) anchor: Option, 20 | } 21 | 22 | impl_to_from!(DRepRegistration); 23 | 24 | #[wasm_bindgen] 25 | impl DRepRegistration { 26 | pub fn voting_credential(&self) -> Credential { 27 | self.voting_credential.clone() 28 | } 29 | 30 | pub fn coin(&self) -> Coin { 31 | self.coin.clone() 32 | } 33 | 34 | pub fn anchor(&self) -> Option { 35 | self.anchor.clone() 36 | } 37 | 38 | pub fn new(voting_credential: &Credential, coin: &Coin) -> Self { 39 | Self { 40 | voting_credential: voting_credential.clone(), 41 | coin: coin.clone(), 42 | anchor: None, 43 | } 44 | } 45 | 46 | pub fn new_with_anchor(voting_credential: &Credential, coin: &Coin, anchor: &Anchor) -> Self { 47 | Self { 48 | voting_credential: voting_credential.clone(), 49 | coin: coin.clone(), 50 | anchor: Some(anchor.clone()), 51 | } 52 | } 53 | 54 | pub fn has_script_credentials(&self) -> bool { 55 | self.voting_credential.has_script_hash() 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /rust/src/serialization/governance/anchor.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::utils::check_len; 2 | use crate::*; 3 | 4 | impl cbor_event::se::Serialize for Anchor { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(cbor_event::Len::Len(2))?; 10 | self.anchor_url.serialize(serializer)?; 11 | self.anchor_data_hash.serialize(serializer)?; 12 | Ok(serializer) 13 | } 14 | } 15 | 16 | impl Deserialize for Anchor { 17 | fn deserialize(raw: &mut Deserializer) -> Result { 18 | (|| -> Result<_, DeserializeError> { 19 | let len = raw.array()?; 20 | 21 | check_len(len, 2, "(anchor_url, anchor_data_hash)")?; 22 | 23 | let anchor_url = URL::deserialize(raw).map_err(|e| e.annotate("anchor_url"))?; 24 | 25 | let anchor_data_hash = 26 | AnchorDataHash::deserialize(raw).map_err(|e| e.annotate("anchor_data_hash"))?; 27 | 28 | if let cbor_event::Len::Indefinite = len { 29 | if raw.special()? != CBORSpecial::Break { 30 | return Err(DeserializeFailure::EndingBreakMissing.into()); 31 | } 32 | } 33 | 34 | return Ok(Anchor { 35 | anchor_url, 36 | anchor_data_hash, 37 | }); 38 | })() 39 | .map_err(|e| e.annotate("Anchor")) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/ex_units.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | impl cbor_event::se::Serialize for ExUnits { 4 | fn serialize<'se, W: Write>( 5 | &self, 6 | serializer: &'se mut Serializer, 7 | ) -> cbor_event::Result<&'se mut Serializer> { 8 | serializer.write_array(cbor_event::Len::Len(2))?; 9 | self.mem.serialize(serializer)?; 10 | self.steps.serialize(serializer)?; 11 | Ok(serializer) 12 | } 13 | } 14 | 15 | impl Deserialize for ExUnits { 16 | fn deserialize(raw: &mut Deserializer) -> Result { 17 | (|| -> Result<_, DeserializeError> { 18 | let len = raw.array()?; 19 | let mut read_len = CBORReadLen::new(len); 20 | read_len.read_elems(2)?; 21 | let mem = (|| -> Result<_, DeserializeError> { Ok(BigNum::deserialize(raw)?) })() 22 | .map_err(|e| e.annotate("mem"))?; 23 | let steps = (|| -> Result<_, DeserializeError> { Ok(BigNum::deserialize(raw)?) })() 24 | .map_err(|e| e.annotate("steps"))?; 25 | match len { 26 | cbor_event::Len::Len(_) => (), 27 | cbor_event::Len::Indefinite => match raw.special()? { 28 | CBORSpecial::Break => (), 29 | _ => return Err(DeserializeFailure::EndingBreakMissing.into()), 30 | }, 31 | } 32 | Ok(ExUnits { mem, steps }) 33 | })() 34 | .map_err(|e| e.annotate("ExUnits")) 35 | } 36 | } -------------------------------------------------------------------------------- /rust/src/chain_crypto/derive.rs: -------------------------------------------------------------------------------- 1 | use crate::chain_crypto::algorithms::{ 2 | ed25519::Pub, ed25519_derive::Ed25519Bip32, ed25519_extended::ExtendedPriv, Ed25519, 3 | }; 4 | use crate::chain_crypto::key::{PublicKey, SecretKey}; 5 | use crate::chain_crypto::Ed25519Extended; 6 | use cryptoxide::hmac::Hmac; 7 | use cryptoxide::pbkdf2::pbkdf2; 8 | use cryptoxide::sha2::Sha512; 9 | use ed25519_bip32::{DerivationError, DerivationScheme}; 10 | use ed25519_bip32::{XPrv, XPRV_SIZE}; 11 | 12 | pub fn derive_sk_ed25519(key: &SecretKey, index: u32) -> SecretKey { 13 | let new_key = key.0.derive(DerivationScheme::V2, index); 14 | SecretKey(new_key) 15 | } 16 | 17 | pub fn derive_pk_ed25519( 18 | key: &PublicKey, 19 | index: u32, 20 | ) -> Result, DerivationError> { 21 | key.0.derive(DerivationScheme::V2, index).map(PublicKey) 22 | } 23 | 24 | pub fn to_raw_sk(key: &SecretKey) -> SecretKey { 25 | SecretKey(ExtendedPriv::from_xprv(&key.0)) 26 | } 27 | 28 | pub fn to_raw_pk(key: &PublicKey) -> PublicKey { 29 | PublicKey(Pub::from_xpub(&key.0)) 30 | } 31 | 32 | pub fn from_bip39_entropy(entropy: &[u8], password: &[u8]) -> SecretKey { 33 | let mut pbkdf2_result = [0; XPRV_SIZE]; 34 | 35 | const ITER: u32 = 4096; 36 | let mut mac = Hmac::new(Sha512::new(), password); 37 | pbkdf2(&mut mac, entropy.as_ref(), ITER, &mut pbkdf2_result); 38 | 39 | SecretKey(XPrv::normalize_bytes_force3rd(pbkdf2_result)) 40 | } 41 | -------------------------------------------------------------------------------- /scripts/json-ts-types.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | const inputFile = fs.readFileSync('./rust/pkg/cardano_serialization_lib.d.ts', 'utf8').split(/\r?\n/); 4 | //console.log(inputFile); 5 | let currentClass = null; 6 | for (let i = 0; i < inputFile.length; ++i) { 7 | let line = inputFile[i]; 8 | //const r = /export class ([a-zA-Z]+){/.exec(line); 9 | const classDef = /export class(.*){/.exec(line); 10 | if (classDef != null && classDef.length > 1) { 11 | currentClass = classDef[1].trim(); 12 | //console.log(`reading class ${currentClass}`); 13 | continue; 14 | } 15 | //const toJson = /\sto_json\(\): any;/.exec(line); 16 | //console.log(toJson); 17 | inputFile[i] = line.replace(/(\s?to_js_value\(\)\s?:\s?)(any)(;)/, `$1${currentClass}JSON$3`); 18 | if (line != inputFile[i]) { 19 | continue; 20 | } 21 | // TODO: we might want to make sure we don't have other cases where this would replace 22 | // things it shouldn't. We'd have to do some go-back-a-few-lines replace to only do this 23 | // for to_json() comments. 24 | inputFile[i] = line.replace(/(\s?\*\s?\@returns\s\{)(any)(\})/, `$1${currentClass}JSON$3`); 25 | //const m = /(\s?\*\s?\@returns\s\{)(any)(\})/.exec(line); 26 | //console.log(`${m} | ${line}`); 27 | } 28 | const jsonDefs = fs.readFileSync('./rust/json-gen/output/json-types.d.ts', 'utf8'); 29 | fs.writeFile( 30 | './rust/pkg/cardano_serialization_lib.d.ts', 31 | `${inputFile.join('\n')}\n${jsonDefs}`, 32 | (err) => { 33 | if (err != null) { 34 | console.log(`err writing file: ${err}`) 35 | } 36 | } 37 | ); 38 | -------------------------------------------------------------------------------- /rust/src/protocol_types/certificates/stake_vote_registration_and_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct StakeVoteRegistrationAndDelegation { 17 | pub(crate) stake_credential: Credential, 18 | pub(crate) pool_keyhash: Ed25519KeyHash, 19 | pub(crate) drep: DRep, 20 | pub(crate) coin: Coin, 21 | } 22 | 23 | impl_to_from!(StakeVoteRegistrationAndDelegation); 24 | 25 | #[wasm_bindgen] 26 | impl StakeVoteRegistrationAndDelegation { 27 | pub fn stake_credential(&self) -> Credential { 28 | self.stake_credential.clone() 29 | } 30 | 31 | pub fn pool_keyhash(&self) -> Ed25519KeyHash { 32 | self.pool_keyhash.clone() 33 | } 34 | 35 | pub fn drep(&self) -> DRep { 36 | self.drep.clone() 37 | } 38 | 39 | pub fn coin(&self) -> Coin { 40 | self.coin.clone() 41 | } 42 | 43 | pub fn new( 44 | stake_credential: &Credential, 45 | pool_keyhash: &Ed25519KeyHash, 46 | drep: &DRep, 47 | coin: &Coin, 48 | ) -> Self { 49 | Self { 50 | stake_credential: stake_credential.clone(), 51 | pool_keyhash: pool_keyhash.clone(), 52 | drep: drep.clone(), 53 | coin: coin.clone(), 54 | } 55 | } 56 | 57 | pub fn has_script_credentials(&self) -> bool { 58 | self.stake_credential.has_script_hash() 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /rust/src/serialization/witnesses/transaction_witnesses_sets.rs: -------------------------------------------------------------------------------- 1 | use std::io::{BufRead, Seek, Write}; 2 | use cbor_event::de::Deserializer; 3 | use cbor_event::se::Serializer; 4 | use crate::{DeserializeError, TransactionWitnessSet, TransactionWitnessSets}; 5 | use crate::protocol_types::Deserialize; 6 | use crate::serialization::utils::is_break_tag; 7 | 8 | impl cbor_event::se::Serialize for TransactionWitnessSets { 9 | fn serialize<'se, W: Write>( 10 | &self, 11 | serializer: &'se mut Serializer, 12 | ) -> cbor_event::Result<&'se mut Serializer> { 13 | serializer.write_array(cbor_event::Len::Len(self.0.len() as u64))?; 14 | for element in &self.0 { 15 | element.serialize(serializer)?; 16 | } 17 | Ok(serializer) 18 | } 19 | } 20 | 21 | impl Deserialize for TransactionWitnessSets { 22 | fn deserialize(raw: &mut Deserializer) -> Result { 23 | let mut arr = Vec::new(); 24 | (|| -> Result<_, DeserializeError> { 25 | let len = raw.array()?; 26 | while match len { 27 | cbor_event::Len::Len(n) => arr.len() < n as usize, 28 | cbor_event::Len::Indefinite => true, 29 | } { 30 | if is_break_tag(raw, "TransactionWitnessSets")? { 31 | break; 32 | } 33 | arr.push(TransactionWitnessSet::deserialize(raw)?); 34 | } 35 | Ok(()) 36 | })() 37 | .map_err(|e| e.annotate("TransactionWitnessSets"))?; 38 | Ok(Self(arr)) 39 | } 40 | } -------------------------------------------------------------------------------- /rust/src/protocol_types/governance/proposals/update_committee_action.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | #[derive( 4 | Clone, 5 | Debug, 6 | Hash, 7 | Eq, 8 | Ord, 9 | PartialEq, 10 | PartialOrd, 11 | serde::Serialize, 12 | serde::Deserialize, 13 | JsonSchema, 14 | )] 15 | #[wasm_bindgen] 16 | pub struct UpdateCommitteeAction { 17 | pub(crate) gov_action_id: Option, 18 | pub(crate) committee: Committee, 19 | pub(crate) members_to_remove: Credentials, 20 | } 21 | 22 | impl_to_from!(UpdateCommitteeAction); 23 | 24 | #[wasm_bindgen] 25 | impl UpdateCommitteeAction { 26 | pub fn gov_action_id(&self) -> Option { 27 | self.gov_action_id.clone() 28 | } 29 | 30 | pub fn committee(&self) -> Committee { 31 | self.committee.clone() 32 | } 33 | 34 | pub fn members_to_remove(&self) -> Credentials { 35 | self.members_to_remove.clone() 36 | } 37 | 38 | pub fn new(committee: &Committee, members_to_remove: &Credentials) -> Self { 39 | Self { 40 | gov_action_id: None, 41 | committee: committee.clone(), 42 | members_to_remove: members_to_remove.clone(), 43 | } 44 | } 45 | 46 | pub fn new_with_action_id( 47 | gov_action_id: &GovernanceActionId, 48 | committee: &Committee, 49 | members_to_remove: &Credentials, 50 | ) -> Self { 51 | Self { 52 | gov_action_id: Some(gov_action_id.clone()), 53 | committee: committee.clone(), 54 | members_to_remove: members_to_remove.clone(), 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /templates/angular-browser/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/cls-angular-test'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /templates/angular-asmjs/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage'), 13 | require('@angular-devkit/build-angular/plugins/karma') 14 | ], 15 | client: { 16 | jasmine: { 17 | // you can add configuration options for Jasmine here 18 | // the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html 19 | // for example, you can disable the random execution with `random: false` 20 | // or set a specific seed with `seed: 4321` 21 | }, 22 | clearContext: false // leave Jasmine Spec Runner output visible in browser 23 | }, 24 | jasmineHtmlReporter: { 25 | suppressAll: true // removes the duplicated traces 26 | }, 27 | coverageReporter: { 28 | dir: require('path').join(__dirname, './coverage/csl-angular-test-asmjs'), 29 | subdir: '.', 30 | reporters: [ 31 | { type: 'html' }, 32 | { type: 'text-summary' } 33 | ] 34 | }, 35 | reporters: ['progress', 'kjhtml'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false, 42 | restartOnFileChange: true 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /rust/src/serialization/certificates/certificates_collection.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::utils::{is_break_tag, skip_set_tag}; 2 | use crate::*; 3 | 4 | impl Serialize for Certificates { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_tag(258)?; 10 | serializer.write_array(Len::Len(self.len() as u64))?; 11 | for element in &self.certs { 12 | element.serialize(serializer)?; 13 | } 14 | Ok(serializer) 15 | } 16 | } 17 | 18 | impl Deserialize for Certificates { 19 | fn deserialize(raw: &mut Deserializer) -> Result { 20 | let has_set_tag= skip_set_tag(raw)?; 21 | let mut arr = Vec::new(); 22 | (|| -> Result<_, DeserializeError> { 23 | let len = raw.array()?; 24 | while match len { 25 | cbor_event::Len::Len(n) => arr.len() < n as usize, 26 | cbor_event::Len::Indefinite => true, 27 | } { 28 | if is_break_tag(raw, "Certificates")? { 29 | break; 30 | } 31 | arr.push(Certificate::deserialize(raw)?); 32 | } 33 | Ok(()) 34 | })() 35 | .map_err(|e| e.annotate("Certificates"))?; 36 | let mut certs = Self::from_vec(arr); 37 | if has_set_tag { 38 | certs.set_set_type(CborSetType::Tagged); 39 | } else { 40 | certs.set_set_type(CborSetType::Untagged); 41 | } 42 | Ok(certs) 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /rust/src/serialization/governance/proposals/no_confidence_action.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::utils::serialize_and_check_index; 2 | use crate::serialization::{check_len, deserialize_and_check_index}; 3 | use crate::*; 4 | use map_names::VotingProposalIndexNames; 5 | use num_traits::ToPrimitive; 6 | 7 | impl cbor_event::se::Serialize for NoConfidenceAction { 8 | fn serialize<'se, W: Write>( 9 | &self, 10 | serializer: &'se mut Serializer, 11 | ) -> cbor_event::Result<&'se mut Serializer> { 12 | serializer.write_array(cbor_event::Len::Len(2))?; 13 | 14 | let proposal_index = VotingProposalIndexNames::NoConfidenceAction.to_u64(); 15 | serialize_and_check_index(serializer, proposal_index, "NoConfidenceAction")?; 16 | 17 | self.gov_action_id.serialize_nullable(serializer)?; 18 | 19 | Ok(serializer) 20 | } 21 | } 22 | 23 | impl_deserialize_for_wrapped_tuple!(NoConfidenceAction); 24 | 25 | impl DeserializeEmbeddedGroup for NoConfidenceAction { 26 | fn deserialize_as_embedded_group( 27 | raw: &mut Deserializer, 28 | len: cbor_event::Len, 29 | ) -> Result { 30 | check_len(len, 2, "(proposal_index, gov_action_id // null)")?; 31 | 32 | let desired_index = VotingProposalIndexNames::NoConfidenceAction.to_u64(); 33 | deserialize_and_check_index(raw, desired_index, "proposal_index")?; 34 | 35 | let gov_action_id = GovernanceActionId::deserialize_nullable(raw) 36 | .map_err(|e| e.annotate("gov_action_id"))?; 37 | 38 | return Ok(NoConfidenceAction { gov_action_id }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /rust/src/serialization/credentials.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::{is_break_tag, skip_set_tag}; 3 | 4 | impl cbor_event::se::Serialize for Credentials { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_tag(258)?; 10 | serializer.write_array(Len::Len(self.len() as u64))?; 11 | for element in &self.credentials { 12 | element.serialize(serializer)?; 13 | } 14 | Ok(serializer) 15 | } 16 | } 17 | 18 | impl Deserialize for Credentials { 19 | fn deserialize(raw: &mut Deserializer) -> Result { 20 | let has_set_tag = skip_set_tag(raw)?; 21 | let mut creds = Credentials::new(); 22 | let mut counter = 0u64; 23 | (|| -> Result<_, DeserializeError> { 24 | let len = raw.array()?; 25 | while match len { 26 | cbor_event::Len::Len(n) => counter < n, 27 | cbor_event::Len::Indefinite => true, 28 | } { 29 | if is_break_tag(raw, "Credentials")? { 30 | break; 31 | } 32 | creds.add_move(Credential::deserialize(raw)?); 33 | counter += 1; 34 | } 35 | Ok(()) 36 | })() 37 | .map_err(|e| e.annotate("CredentialsSet"))?; 38 | if has_set_tag { 39 | creds.set_set_type(CborSetType::Tagged); 40 | } else { 41 | creds.set_set_type(CborSetType::Untagged); 42 | } 43 | Ok(creds) 44 | } 45 | } -------------------------------------------------------------------------------- /rust/src/serialization/ed25519_key_hashes.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::{is_break_tag, skip_set_tag}; 3 | 4 | impl Serialize for Ed25519KeyHashes { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_tag(258)?; 10 | serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; 11 | for element in self { 12 | element.serialize(serializer)?; 13 | } 14 | Ok(serializer) 15 | } 16 | } 17 | 18 | impl Deserialize for Ed25519KeyHashes { 19 | fn deserialize(raw: &mut Deserializer) -> Result { 20 | let has_set_tag = skip_set_tag(raw)?; 21 | let mut creds = Ed25519KeyHashes::new(); 22 | let mut total = 0u64; 23 | (|| -> Result<_, DeserializeError> { 24 | let len = raw.array()?; 25 | while match len { 26 | cbor_event::Len::Len(n) => total < n, 27 | cbor_event::Len::Indefinite => true, 28 | } { 29 | if is_break_tag(raw, "Ed25519KeyHashes")? { 30 | break; 31 | } 32 | creds.add_move(Ed25519KeyHash::deserialize(raw)?); 33 | total += 1; 34 | } 35 | Ok(()) 36 | })() 37 | .map_err(|e| e.annotate("Ed25519KeyHashes"))?; 38 | if has_set_tag { 39 | creds.set_set_type(CborSetType::Tagged); 40 | } else { 41 | creds.set_set_type(CborSetType::Untagged); 42 | } 43 | Ok(creds) 44 | } 45 | } -------------------------------------------------------------------------------- /rust/src/serialization/tx_inputs.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::{is_break_tag, skip_set_tag}; 3 | 4 | impl cbor_event::se::Serialize for TransactionInputs { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_tag(258)?; 10 | serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; 11 | for element in &self.inputs { 12 | element.serialize(serializer)?; 13 | } 14 | Ok(serializer) 15 | } 16 | } 17 | 18 | impl Deserialize for TransactionInputs { 19 | fn deserialize(raw: &mut Deserializer) -> Result { 20 | let has_set_tag = skip_set_tag(raw)?; 21 | let mut arr = Vec::new(); 22 | (|| -> Result<_, DeserializeError> { 23 | let len = raw.array()?; 24 | while match len { 25 | cbor_event::Len::Len(n) => arr.len() < n as usize, 26 | cbor_event::Len::Indefinite => true, 27 | } { 28 | if is_break_tag(raw, "TransactionInputs")? { 29 | break; 30 | } 31 | arr.push(TransactionInput::deserialize(raw)?); 32 | } 33 | Ok(()) 34 | })() 35 | .map_err(|e| e.annotate("TransactionInputs"))?; 36 | let mut inputs = TransactionInputs::from_vec(arr); 37 | if has_set_tag { 38 | inputs.set_set_type(CborSetType::Tagged); 39 | } else { 40 | inputs.set_set_type(CborSetType::Untagged); 41 | } 42 | Ok(inputs) 43 | } 44 | } -------------------------------------------------------------------------------- /rust/src/serialization/plutus/ex_unit_prices.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | 3 | impl cbor_event::se::Serialize for ExUnitPrices { 4 | fn serialize<'se, W: Write>( 5 | &self, 6 | serializer: &'se mut Serializer, 7 | ) -> cbor_event::Result<&'se mut Serializer> { 8 | serializer.write_array(cbor_event::Len::Len(2))?; 9 | self.mem_price.serialize(serializer)?; 10 | self.step_price.serialize(serializer)?; 11 | Ok(serializer) 12 | } 13 | } 14 | 15 | impl Deserialize for ExUnitPrices { 16 | fn deserialize(raw: &mut Deserializer) -> Result { 17 | (|| -> Result<_, DeserializeError> { 18 | let len = raw.array()?; 19 | let mut read_len = CBORReadLen::new(len); 20 | read_len.read_elems(2)?; 21 | let mem_price = 22 | (|| -> Result<_, DeserializeError> { Ok(SubCoin::deserialize(raw)?) })() 23 | .map_err(|e| e.annotate("mem_price"))?; 24 | let step_price = 25 | (|| -> Result<_, DeserializeError> { Ok(SubCoin::deserialize(raw)?) })() 26 | .map_err(|e| e.annotate("step_price"))?; 27 | match len { 28 | cbor_event::Len::Len(_) => (), 29 | cbor_event::Len::Indefinite => match raw.special()? { 30 | CBORSpecial::Break => (), 31 | _ => return Err(DeserializeFailure::EndingBreakMissing.into()), 32 | }, 33 | } 34 | Ok(ExUnitPrices { 35 | mem_price, 36 | step_price, 37 | }) 38 | })() 39 | .map_err(|e| e.annotate("ExUnitPrices")) 40 | } 41 | } -------------------------------------------------------------------------------- /rust/src/serialization/governance/proposals/voting_proposal.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::{check_len}; 2 | use crate::*; 3 | 4 | impl Serialize for VotingProposal { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_array(cbor_event::Len::Len(4))?; 10 | self.deposit.serialize(serializer)?; 11 | self.reward_account.serialize(serializer)?; 12 | self.governance_action.serialize(serializer)?; 13 | self.anchor.serialize(serializer)?; 14 | Ok(serializer) 15 | } 16 | } 17 | 18 | impl_deserialize_for_wrapped_tuple!(VotingProposal); 19 | 20 | impl DeserializeEmbeddedGroup for VotingProposal { 21 | fn deserialize_as_embedded_group( 22 | raw: &mut Deserializer, 23 | len: cbor_event::Len, 24 | ) -> Result { 25 | check_len( 26 | len, 27 | 4, 28 | "(deposit, reward_account, gov_action, anchor)", 29 | )?; 30 | 31 | let deposit = Coin::deserialize(raw) 32 | .map_err(|e| e.annotate("deposit"))?; 33 | let reward_account = RewardAddress::deserialize(raw) 34 | .map_err(|e| e.annotate("reward_account"))?; 35 | let gov_action = GovernanceAction::deserialize(raw) 36 | .map_err(|e| e.annotate("gov_action"))?; 37 | let anchor = Anchor::deserialize(raw) 38 | .map_err(|e| e.annotate("anchor"))?; 39 | 40 | return Ok(VotingProposal { 41 | deposit, 42 | reward_account, 43 | governance_action: gov_action, 44 | anchor, 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /rust/src/serialization/governance/proposals/voting_proposals.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::{is_break_tag, skip_set_tag}; 3 | 4 | impl cbor_event::se::Serialize for VotingProposals { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_tag(258)?; 10 | serializer.write_array(cbor_event::Len::Len(self.len() as u64))?; 11 | for element in self { 12 | element.serialize(serializer)?; 13 | } 14 | Ok(serializer) 15 | } 16 | } 17 | 18 | impl Deserialize for VotingProposals { 19 | fn deserialize(raw: &mut Deserializer) -> Result { 20 | let has_set_tag = skip_set_tag(raw)?; 21 | let mut arr = Vec::new(); 22 | (|| -> Result<_, DeserializeError> { 23 | skip_set_tag(raw)?; 24 | let len = raw.array()?; 25 | while match len { 26 | cbor_event::Len::Len(n) => arr.len() < n as usize, 27 | cbor_event::Len::Indefinite => true, 28 | } { 29 | if is_break_tag(raw, "VotingProposals")? { 30 | break; 31 | } 32 | arr.push(VotingProposal::deserialize(raw)?); 33 | } 34 | Ok(()) 35 | })() 36 | .map_err(|e| e.annotate("VotingProposals"))?; 37 | let mut proposals = Self::from_vec(arr); 38 | if has_set_tag { 39 | proposals.set_set_type(CborSetType::Tagged); 40 | } else { 41 | proposals.set_set_type(CborSetType::Untagged); 42 | } 43 | Ok(proposals) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cardano Serialization Lib 2 | 3 | This is a library, written in Rust, for serialization & deserialization of data structures used in Cardano's Haskell implementation of Alonzo along with useful utility functions. 4 | 5 | ##### NPM packages 6 | 7 | - [NodeJS WASM package](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-nodejs) 8 | - [Browser (chrome/firefox) WASM package](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser) 9 | - [Browser (pure JS - no WASM) ASM.js package](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-asmjs) 10 | 11 | ##### NPM packages with GC support 12 | Note: This package uses [weak references flag from wasm-bindgen](https://rustwasm.github.io/wasm-bindgen/reference/weak-references.html). 13 | It uses `FinalizationRegistry` under the hood to automatically call "free" for each CSL struct when it is no longer needed. However, use this feature with caution as it may have unpredictable behaviors. 14 | - [NodeJS WASM package with GC](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-nodejs-gc) 15 | - [Browser (chrome/firefox) WASM package with GC](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser-gc) 16 | - [Browser (pure JS - no WASM) ASM.js package with GC](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-asmjs-gc) 17 | 18 | 19 | ##### Rust crates 20 | 21 | - [cardano-serialization-lib](https://crates.io/crates/cardano-serialization-lib) 22 | 23 | ##### Mobile bindings 24 | 25 | - [React-Native mobile bindings](https://github.com/Emurgo/react-native-haskell-shelley) 26 | 27 | ## Documentation 28 | 29 | You can find documentation [here](https://developers.cardano.org/docs/get-started/cardano-serialization-lib/overview) 30 | -------------------------------------------------------------------------------- /rust/src/serialization/certificates/vote_delegation.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::map_names::CertificateIndexNames; 2 | use crate::serialization::utils::{ 3 | check_len, deserialize_and_check_index, serialize_and_check_index, 4 | }; 5 | use crate::*; 6 | use num_traits::ToPrimitive; 7 | 8 | impl cbor_event::se::Serialize for VoteDelegation { 9 | fn serialize<'se, W: Write>( 10 | &self, 11 | serializer: &'se mut Serializer, 12 | ) -> cbor_event::Result<&'se mut Serializer> { 13 | serializer.write_array(cbor_event::Len::Len(3))?; 14 | 15 | let proposal_index = CertificateIndexNames::VoteDelegation.to_u64(); 16 | serialize_and_check_index(serializer, proposal_index, "VoteDelegation")?; 17 | 18 | self.stake_credential.serialize(serializer)?; 19 | self.drep.serialize(serializer)?; 20 | Ok(serializer) 21 | } 22 | } 23 | 24 | impl_deserialize_for_wrapped_tuple!(VoteDelegation); 25 | 26 | impl DeserializeEmbeddedGroup for VoteDelegation { 27 | fn deserialize_as_embedded_group( 28 | raw: &mut Deserializer, 29 | len: cbor_event::Len, 30 | ) -> Result { 31 | check_len(len, 3, "(cert_index, stake_credential, drep)")?; 32 | let cert_index = CertificateIndexNames::VoteDelegation.to_u64(); 33 | deserialize_and_check_index(raw, cert_index, "cert_index")?; 34 | 35 | let stake_credential = 36 | Credential::deserialize(raw).map_err(|e| e.annotate("stake_credential"))?; 37 | 38 | let drep = DRep::deserialize(raw).map_err(|e| e.annotate("drep"))?; 39 | 40 | Ok(VoteDelegation { 41 | stake_credential, 42 | drep, 43 | }) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /rust/src/serialization/plutus/cost_models.rs: -------------------------------------------------------------------------------- 1 | use crate::*; 2 | use crate::serialization::utils::is_break_tag; 3 | 4 | impl cbor_event::se::Serialize for Costmdls { 5 | fn serialize<'se, W: Write>( 6 | &self, 7 | serializer: &'se mut Serializer, 8 | ) -> cbor_event::Result<&'se mut Serializer> { 9 | serializer.write_map(cbor_event::Len::Len(self.0.len() as u64))?; 10 | for (key, value) in &self.0 { 11 | key.serialize(serializer)?; 12 | value.serialize(serializer)?; 13 | } 14 | Ok(serializer) 15 | } 16 | } 17 | 18 | impl Deserialize for Costmdls { 19 | fn deserialize(raw: &mut Deserializer) -> Result { 20 | let mut table = std::collections::BTreeMap::new(); 21 | (|| -> Result<_, DeserializeError> { 22 | let len = raw.map()?; 23 | while match len { 24 | cbor_event::Len::Len(n) => table.len() < n as usize, 25 | cbor_event::Len::Indefinite => true, 26 | } { 27 | if is_break_tag(raw, "Costmdls")? { 28 | break; 29 | } 30 | let key = Language::deserialize(raw)?; 31 | let value = CostModel::deserialize(raw)?; 32 | if table.insert(key.clone(), value).is_some() { 33 | return Err(DeserializeFailure::DuplicateKey(Key::Str(String::from( 34 | "some complicated/unsupported type", 35 | ))) 36 | .into()); 37 | } 38 | } 39 | Ok(()) 40 | })() 41 | .map_err(|e| e.annotate("Costmdls"))?; 42 | Ok(Self(table)) 43 | } 44 | } -------------------------------------------------------------------------------- /rust/src/serialization/certificates/drep_deregistration.rs: -------------------------------------------------------------------------------- 1 | use crate::serialization::map_names::CertificateIndexNames; 2 | use crate::serialization::utils::{ 3 | check_len, deserialize_and_check_index, serialize_and_check_index, 4 | }; 5 | use crate::*; 6 | use num_traits::ToPrimitive; 7 | 8 | impl cbor_event::se::Serialize for DRepDeregistration { 9 | fn serialize<'se, W: Write>( 10 | &self, 11 | serializer: &'se mut Serializer, 12 | ) -> cbor_event::Result<&'se mut Serializer> { 13 | serializer.write_array(cbor_event::Len::Len(3))?; 14 | 15 | let proposal_index = CertificateIndexNames::DRepDeregistration.to_u64(); 16 | serialize_and_check_index(serializer, proposal_index, "DRepDeregistration")?; 17 | 18 | self.voting_credential.serialize(serializer)?; 19 | self.coin.serialize(serializer)?; 20 | Ok(serializer) 21 | } 22 | } 23 | 24 | impl_deserialize_for_wrapped_tuple!(DRepDeregistration); 25 | 26 | impl DeserializeEmbeddedGroup for DRepDeregistration { 27 | fn deserialize_as_embedded_group( 28 | raw: &mut Deserializer, 29 | len: cbor_event::Len, 30 | ) -> Result { 31 | check_len(len, 3, "(cert_index, voting_credential, coin)")?; 32 | 33 | let cert_index = CertificateIndexNames::DRepDeregistration.to_u64(); 34 | deserialize_and_check_index(raw, cert_index, "cert_index")?; 35 | 36 | let voting_credential = 37 | Credential::deserialize(raw).map_err(|e| e.annotate("voting_credential"))?; 38 | 39 | let coin = Coin::deserialize(raw).map_err(|e| e.annotate("coin"))?; 40 | 41 | Ok(DRepDeregistration { 42 | voting_credential, 43 | coin, 44 | }) 45 | } 46 | } 47 | --------------------------------------------------------------------------------