Skip to content

Add Witness builder #307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

235 changes: 199 additions & 36 deletions rust/pkg/cardano_serialization_lib.js.flow
Original file line number Diff line number Diff line change
Expand Up @@ -302,79 +302,79 @@ declare export var NetworkIdKind: {|
|};

/**
* Used to choosed the schema for a script JSON string
*/

declare export var ScriptSchema: {|
+Wallet: 0, // 0
+Node: 1, // 1
declare export var LanguageKind: {|
+PlutusV1: 0, // 0
+PlutusV2: 1, // 1
|};

/**
*/

declare export var TransactionMetadatumKind: {|
+MetadataMap: 0, // 0
+MetadataList: 1, // 1
+Int: 2, // 2
+Bytes: 3, // 3
+Text: 4, // 4
declare export var PlutusDataKind: {|
+ConstrPlutusData: 0, // 0
+Map: 1, // 1
+List: 2, // 2
+Integer: 3, // 3
+Bytes: 4, // 4
|};

/**
*/

declare export var MetadataJsonSchema: {|
+NoConversions: 0, // 0
+BasicConversions: 1, // 1
+DetailedSchema: 2, // 2
declare export var RedeemerTagKind: {|
+Spend: 0, // 0
+Mint: 1, // 1
+Cert: 2, // 2
+Reward: 3, // 3
|};

/**
*/

declare export var CoinSelectionStrategyCIP2: {|
+LargestFirst: 0, // 0
+RandomImprove: 1, // 1
+LargestFirstMultiAsset: 2, // 2
+RandomImproveMultiAsset: 3, // 3
declare export var StakeCredKind: {|
+Key: 0, // 0
+Script: 1, // 1
|};

/**
* Used to choose the schema for a script JSON string
*/

declare export var LanguageKind: {|
+PlutusV1: 0, // 0
+PlutusV2: 1, // 1
declare export var ScriptSchema: {|
+Wallet: 0, // 0
+Node: 1, // 1
|};

/**
*/

declare export var PlutusDataKind: {|
+ConstrPlutusData: 0, // 0
+Map: 1, // 1
+List: 2, // 2
+Integer: 3, // 3
+Bytes: 4, // 4
declare export var TransactionMetadatumKind: {|
+MetadataMap: 0, // 0
+MetadataList: 1, // 1
+Int: 2, // 2
+Bytes: 3, // 3
+Text: 4, // 4
|};

/**
*/

declare export var RedeemerTagKind: {|
+Spend: 0, // 0
+Mint: 1, // 1
+Cert: 2, // 2
+Reward: 3, // 3
declare export var MetadataJsonSchema: {|
+NoConversions: 0, // 0
+BasicConversions: 1, // 1
+DetailedSchema: 2, // 2
|};

/**
*/

declare export var StakeCredKind: {|
+Key: 0, // 0
+Script: 1, // 1
declare export var CoinSelectionStrategyCIP2: {|
+LargestFirst: 0, // 0
+RandomImprove: 1, // 1
+LargestFirstMultiAsset: 2, // 2
+RandomImproveMultiAsset: 3, // 3
|};

/**
Expand Down Expand Up @@ -4376,6 +4376,28 @@ declare export class RedeemerTag {
*/
kind(): number;
}
/**
*/
declare export class RedeemerWitnessKey {
free(): void;

/**
* @returns {RedeemerTag}
*/
tag(): RedeemerTag;

/**
* @returns {BigNum}
*/
index(): BigNum;

/**
* @param {RedeemerTag} tag
* @param {BigNum} index
* @returns {RedeemerWitnessKey}
*/
static new(tag: RedeemerTag, index: BigNum): RedeemerWitnessKey;
}
/**
*/
declare export class Redeemers {
Expand Down Expand Up @@ -4509,6 +4531,91 @@ declare export class Relays {
*/
add(elem: Relay): void;
}
/**
*/
declare export class RequiredWitnessSet {
free(): void;

/**
* @param {Vkeywitness} vkey
*/
add_vkey(vkey: Vkeywitness): void;

/**
* @param {Vkey} vkey
*/
add_vkey_key(vkey: Vkey): void;

/**
* @param {Ed25519KeyHash} hash
*/
add_vkey_key_hash(hash: Ed25519KeyHash): void;

/**
* @param {BootstrapWitness} bootstrap
*/
add_bootstrap(bootstrap: BootstrapWitness): void;

/**
* @param {Vkey} bootstrap
*/
add_bootstrap_key(bootstrap: Vkey): void;

/**
* @param {Ed25519KeyHash} hash
*/
add_bootstrap_key_hash(hash: Ed25519KeyHash): void;

/**
* @param {NativeScript} native_script
*/
add_native_script(native_script: NativeScript): void;

/**
* @param {ScriptHash} native_script
*/
add_native_script_hash(native_script: ScriptHash): void;

/**
* @param {PlutusScript} plutus_script
*/
add_plutus_script(plutus_script: PlutusScript): void;

/**
* @param {ScriptHash} plutus_script
*/
add_plutus_hash(plutus_script: ScriptHash): void;

/**
* @param {PlutusData} plutus_datum
*/
add_plutus_datum(plutus_datum: PlutusData): void;

/**
* @param {DataHash} plutus_datum
*/
add_plutus_datum_hash(plutus_datum: DataHash): void;

/**
* @param {Redeemer} redeemer
*/
add_redeemer(redeemer: Redeemer): void;

/**
* @param {RedeemerWitnessKey} redeemer
*/
add_redeemer_tag(redeemer: RedeemerWitnessKey): void;

/**
* @param {RequiredWitnessSet} requirements
*/
add_all(requirements: RequiredWitnessSet): void;

/**
* @returns {RequiredWitnessSet}
*/
static new(): RequiredWitnessSet;
}
/**
*/
declare export class RewardAddress {
Expand Down Expand Up @@ -6671,6 +6778,62 @@ declare export class TransactionWitnessSet {
*/
static new(): TransactionWitnessSet;
}
/**
* Builder de-duplicates witnesses as they are added
*/
declare export class TransactionWitnessSetBuilder {
free(): void;

/**
* @param {Vkeywitness} vkey
*/
add_vkey(vkey: Vkeywitness): void;

/**
* @param {BootstrapWitness} bootstrap
*/
add_bootstrap(bootstrap: BootstrapWitness): void;

/**
* @param {NativeScript} native_script
*/
add_native_script(native_script: NativeScript): void;

/**
* @param {PlutusScript} plutus_script
*/
add_plutus_script(plutus_script: PlutusScript): void;

/**
* @param {PlutusData} plutus_datum
*/
add_plutus_datum(plutus_datum: PlutusData): void;

/**
* @param {Redeemer} redeemer
*/
add_redeemer(redeemer: Redeemer): void;

/**
* @param {RequiredWitnessSet} required_wits
*/
add_required_wits(required_wits: RequiredWitnessSet): void;

/**
* @returns {TransactionWitnessSetBuilder}
*/
static new(): TransactionWitnessSetBuilder;

/**
* @param {TransactionWitnessSet} wit_set
*/
add_existing(wit_set: TransactionWitnessSet): void;

/**
* @returns {TransactionWitnessSet}
*/
build(): TransactionWitnessSet;
}
/**
*/
declare export class TransactionWitnessSets {
Expand Down
6 changes: 3 additions & 3 deletions rust/src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ impl PrivateKey {

/// ED25519 key used as public key
#[wasm_bindgen]
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct PublicKey(crypto::PublicKey<crypto::Ed25519>);

impl From<crypto::PublicKey<crypto::Ed25519>> for PublicKey {
Expand Down Expand Up @@ -329,7 +329,7 @@ impl PublicKey {
}

#[wasm_bindgen]
#[derive(Clone, Debug, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct Vkey(PublicKey);

to_from_bytes!(Vkey);
Expand Down Expand Up @@ -613,7 +613,7 @@ impl DeserializeEmbeddedGroup for BootstrapWitness {

#[wasm_bindgen]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct BootstrapWitnesses(Vec<BootstrapWitness>);
pub struct BootstrapWitnesses(pub (crate) Vec<BootstrapWitness>);

#[wasm_bindgen]
impl BootstrapWitnesses {
Expand Down
10 changes: 3 additions & 7 deletions rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub mod emip3;
pub mod utils;
mod serialization_macros;
mod fakes;
pub mod witness_builder;

use address::*;
use crypto::*;
Expand Down Expand Up @@ -1786,7 +1787,7 @@ impl TimelockStart {
/// !!! DEPRECATED !!!
/// Returns a Slot32 (u32) value in case the underlying original BigNum (u64) value is within the limits.
/// Otherwise will just raise an error.
/// Use `.slot_bignum` instead
/// Use `.slot_bignum` instead
#[deprecated(
since = "10.1.0",
note = "Possible boundary error. Use slot_bignum instead"
Expand Down Expand Up @@ -1959,12 +1960,7 @@ pub enum ScriptHashNamespace {
impl NativeScript {

pub fn hash(&self) -> ScriptHash {
let mut bytes = Vec::with_capacity(self.to_bytes().len() + 1);
bytes.extend_from_slice(&vec![
ScriptHashNamespace::NativeScript as u8,
]);
bytes.extend_from_slice(&self.to_bytes());
ScriptHash::from(blake2b224(bytes.as_ref()))
hash_script(ScriptHashNamespace::NativeScript, self.to_bytes())
}

pub fn new_script_pubkey(script_pubkey: &ScriptPubkey) -> Self {
Expand Down
Loading