1 #ifndef LIBWALLY_CORE_TRANSACTION_H 2 #define LIBWALLY_CORE_TRANSACTION_H 3 4 #include "wally_core.h" 5 #include "wally_crypto.h" 6 7 #ifdef __cplusplus 8 extern "C" { 9 #endif 10 11 #define WALLY_TX_SEQUENCE_FINAL 0xffffffff 12 #define WALLY_TX_VERSION_1 1 13 #define WALLY_TX_VERSION_2 2 14 #define WALLY_TX_IS_ELEMENTS 1 15 #define WALLY_TX_IS_ISSUANCE 2 16 #define WALLY_TX_IS_PEGIN 4 17 #define WALLY_TX_IS_COINBASE 8 18 19 #define WALLY_SATOSHI_PER_BTC 100000000 20 #define WALLY_BTC_MAX 21000000 21 22 #define WALLY_TXHASH_LEN 32 /** Size of a transaction hash in bytes */ 23 24 #define WALLY_TX_FLAG_USE_WITNESS 0x1 /* Encode witness data if present */ 25 #define WALLY_TX_FLAG_USE_ELEMENTS 0x2 /* Encode/Decode as an elements transaction */ 26 #define WALLY_TX_FLAG_ALLOW_PARTIAL 0x4 /* Allow partially complete transactions */ 27 /* Note: This flag encodes/parses transactions that are ambiguous to decode. 28 Unless you have a good reason to do so you will most likely not need it */ 29 #define WALLY_TX_FLAG_PRE_BIP144 0x8 /* Encode/Decode using pre-BIP 144 serialisation */ 30 31 #define WALLY_TX_FLAG_BLINDED_INITIAL_ISSUANCE 0x1 32 33 #define WALLY_TX_DUMMY_NULL 0x1 /* An empty witness item */ 34 #define WALLY_TX_DUMMY_SIG 0x2 /* A dummy signature */ 35 #define WALLY_TX_DUMMY_SIG_LOW_R 0x4 /* A dummy signature created with EC_FLAG_GRIND_R */ 36 37 /** Sighash flags for transaction signing */ 38 #define WALLY_SIGHASH_ALL 0x01 39 #define WALLY_SIGHASH_NONE 0x02 40 #define WALLY_SIGHASH_SINGLE 0x03 41 #define WALLY_SIGHASH_FORKID 0x40 42 #define WALLY_SIGHASH_RANGEPROOF 0x40 /* for elements */ 43 #define WALLY_SIGHASH_ANYONECANPAY 0x80 44 45 #define WALLY_TX_ASSET_CT_VALUE_PREFIX_A 8 46 #define WALLY_TX_ASSET_CT_VALUE_PREFIX_B 9 47 #define WALLY_TX_ASSET_CT_ASSET_PREFIX_A 10 48 #define WALLY_TX_ASSET_CT_ASSET_PREFIX_B 11 49 #define WALLY_TX_ASSET_CT_NONCE_PREFIX_A 2 50 #define WALLY_TX_ASSET_CT_NONCE_PREFIX_B 3 51 52 #define WALLY_TX_ASSET_TAG_LEN 32 53 #define WALLY_TX_ASSET_CT_VALUE_LEN 33 /* version byte + 32 bytes */ 54 #define WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN 9 /* version byte + 8 bytes */ 55 #define WALLY_TX_ASSET_CT_ASSET_LEN 33 /* version byte + 32 bytes */ 56 #define WALLY_TX_ASSET_CT_NONCE_LEN 33 /* version byte + 32 bytes */ 57 #define WALLY_TX_ASSET_CT_LEN 33 /* version byte + 32 bytes */ 58 59 #define WALLY_TX_ISSUANCE_FLAG (1 << 31) 60 #define WALLY_TX_PEGIN_FLAG (1 << 30) 61 #define WALLY_TX_INDEX_MASK 0x3fffffff 62 63 #ifdef SWIG 64 struct wally_tx_input; 65 struct wally_tx_output; 66 struct wally_tx; 67 #else 68 /** A transaction witness item */ 69 struct wally_tx_witness_item { 70 unsigned char *witness; 71 size_t witness_len; 72 }; 73 74 /** A transaction witness stack */ 75 struct wally_tx_witness_stack { 76 struct wally_tx_witness_item *items; 77 size_t num_items; 78 size_t items_allocation_len; 79 }; 80 81 /** A transaction input */ 82 struct wally_tx_input { 83 unsigned char txhash[WALLY_TXHASH_LEN]; 84 uint32_t index; 85 uint32_t sequence; 86 unsigned char *script; 87 size_t script_len; 88 struct wally_tx_witness_stack *witness; 89 uint8_t features; 90 #ifdef BUILD_ELEMENTS 91 unsigned char blinding_nonce[SHA256_LEN]; 92 unsigned char entropy[SHA256_LEN]; 93 unsigned char *issuance_amount; 94 size_t issuance_amount_len; 95 unsigned char *inflation_keys; 96 size_t inflation_keys_len; 97 unsigned char *issuance_amount_rangeproof; 98 size_t issuance_amount_rangeproof_len; 99 unsigned char *inflation_keys_rangeproof; 100 size_t inflation_keys_rangeproof_len; 101 struct wally_tx_witness_stack *pegin_witness; 102 #endif /* BUILD_ELEMENTS */ 103 }; 104 105 /** A transaction output */ 106 struct wally_tx_output { 107 uint64_t satoshi; 108 unsigned char *script; 109 size_t script_len; 110 uint8_t features; 111 #ifdef BUILD_ELEMENTS 112 unsigned char *asset; 113 size_t asset_len; 114 unsigned char *value; 115 size_t value_len; 116 unsigned char *nonce; 117 size_t nonce_len; 118 unsigned char *surjectionproof; 119 size_t surjectionproof_len; 120 unsigned char *rangeproof; 121 size_t rangeproof_len; 122 #endif /* BUILD_ELEMENTS */ 123 }; 124 125 /** A parsed bitcoin transaction */ 126 struct wally_tx { 127 uint32_t version; 128 uint32_t locktime; 129 struct wally_tx_input *inputs; 130 size_t num_inputs; 131 size_t inputs_allocation_len; 132 struct wally_tx_output *outputs; 133 size_t num_outputs; 134 size_t outputs_allocation_len; 135 }; 136 #endif /* SWIG */ 137 138 /** 139 * Allocate and initialize a new witness stack. 140 * 141 * :param allocation_len: The number of items to pre-allocate space for. 142 * :param output: Destination for the resulting witness stack. 143 */ 144 WALLY_CORE_API int wally_tx_witness_stack_init_alloc( 145 size_t allocation_len, 146 struct wally_tx_witness_stack **output); 147 148 /** 149 * Create a copy of a witness stack. 150 * 151 * :param stack: The witness stack to copy. 152 * :param output: Destination for the resulting copy. 153 */ 154 WALLY_CORE_API int wally_tx_witness_stack_clone_alloc( 155 const struct wally_tx_witness_stack *stack, 156 struct wally_tx_witness_stack **output); 157 158 /** 159 * Add a witness to a witness stack. 160 * 161 * :param stack: The witness stack to add to. 162 * :param witness: The witness data to add to the stack. 163 * :param witness_len: Length of ``witness`` in bytes. 164 */ 165 WALLY_CORE_API int wally_tx_witness_stack_add( 166 struct wally_tx_witness_stack *stack, 167 const unsigned char *witness, 168 size_t witness_len); 169 170 /** 171 * Add a dummy witness item to a witness stack. 172 * 173 * :param stack: The witness stack to add to. 174 * :param flags: ``WALLY_TX_DUMMY_`` Flags indicating the type of dummy to add. 175 */ 176 WALLY_CORE_API int wally_tx_witness_stack_add_dummy( 177 struct wally_tx_witness_stack *stack, 178 uint32_t flags); 179 180 /** 181 * Set a witness item to a witness stack. 182 * 183 * :param stack: The witness stack to add to. 184 * :param index: Index of the item to set. The stack will grow if needed to this many items. 185 * :param witness: The witness data to add to the stack. 186 * :param witness_len: Length of ``witness`` in bytes. 187 */ 188 WALLY_CORE_API int wally_tx_witness_stack_set( 189 struct wally_tx_witness_stack *stack, 190 size_t index, 191 const unsigned char *witness, 192 size_t witness_len); 193 194 /** 195 * Set a dummy witness item to a witness stack. 196 * 197 * :param stack: The witness stack to add to. 198 * :param index: Index of the item to set. The stack will grow if needed to this many items. 199 * :param flags: ``WALLY_TX_DUMMY_`` Flags indicating the type of dummy to set. 200 */ 201 WALLY_CORE_API int wally_tx_witness_stack_set_dummy( 202 struct wally_tx_witness_stack *stack, 203 size_t index, 204 uint32_t flags); 205 206 #ifndef SWIG_PYTHON 207 /** 208 * Free a transaction witness stack allocated by `wally_tx_witness_stack_init_alloc`. 209 * 210 * :param stack: The transaction witness stack to free. 211 */ 212 WALLY_CORE_API int wally_tx_witness_stack_free( 213 struct wally_tx_witness_stack *stack); 214 #endif /* SWIG_PYTHON */ 215 216 /** 217 * Allocate and initialize a new transaction input. 218 * 219 * :param txhash: The transaction hash of the transaction this input comes from. 220 * :param txhash_len: Size of ``txhash`` in bytes. Must be ``WALLY_TXHASH_LEN``. 221 * :param utxo_index: The zero-based index of the transaction output in ``txhash`` that 222 *| this input comes from. 223 * :param sequence: The sequence number for the input. 224 * :param script: The scriptSig for the input. 225 * :param script_len: Size of ``script`` in bytes. 226 * :param witness: The witness stack for the input, or NULL if no witness is present. 227 * :param output: Destination for the resulting transaction input. 228 */ 229 WALLY_CORE_API int wally_tx_input_init_alloc( 230 const unsigned char *txhash, 231 size_t txhash_len, 232 uint32_t utxo_index, 233 uint32_t sequence, 234 const unsigned char *script, 235 size_t script_len, 236 const struct wally_tx_witness_stack *witness, 237 struct wally_tx_input **output); 238 239 #ifndef SWIG_PYTHON 240 /** 241 * Free a transaction input allocated by `wally_tx_input_init_alloc`. 242 * 243 * :param input: The transaction input to free. 244 */ 245 WALLY_CORE_API int wally_tx_input_free(struct wally_tx_input *input); 246 #endif /* SWIG_PYTHON */ 247 248 #ifndef SWIG 249 /** 250 * Initialize a new transaction output. 251 * 252 * :param satoshi The amount of the output in satoshi. 253 * :param script: The scriptPubkey for the output. 254 * :param script_len: Size of ``script`` in bytes. 255 * :param output: Transaction output to initialize. 256 */ 257 WALLY_CORE_API int wally_tx_output_init(uint64_t satoshi, 258 const unsigned char *script, 259 size_t script_len, 260 struct wally_tx_output *output); 261 #endif /* SWIG */ 262 263 /** 264 * Allocate and initialize a new transaction output. 265 * 266 * :param satoshi The amount of the output in satoshi. 267 * :param script: The scriptPubkey for the output. 268 * :param script_len: Size of ``script`` in bytes. 269 * :param output: Destination for the resulting transaction output. 270 */ 271 WALLY_CORE_API int wally_tx_output_init_alloc( 272 uint64_t satoshi, 273 const unsigned char *script, 274 size_t script_len, 275 struct wally_tx_output **output); 276 277 /** 278 * Create a new copy of a transaction output. 279 * 280 * :param tx_output_in: The transaction output to clone. 281 * :param output: Destination for the resulting transaction output copy. 282 */ 283 WALLY_CORE_API int wally_tx_output_clone_alloc( 284 const struct wally_tx_output *tx_output_in, 285 struct wally_tx_output **output); 286 287 #ifndef SWIG 288 /** 289 * Create a new copy of a transaction output in place. 290 * 291 * :param tx_output_in: The transaction output to clone. 292 * :param output: Destination for the resulting transaction output copy. 293 * 294 * .. note:: ``output`` is overwritten in place, and not cleared first. 295 */ 296 WALLY_CORE_API int wally_tx_output_clone( 297 const struct wally_tx_output *tx_output_in, 298 struct wally_tx_output *output); 299 #endif /* SWIG */ 300 301 #ifndef SWIG_PYTHON 302 /** 303 * Free a transaction output allocated by `wally_tx_output_init_alloc`. 304 * 305 * :param output: The transaction output to free. 306 */ 307 WALLY_CORE_API int wally_tx_output_free(struct wally_tx_output *output); 308 #endif /* SWIG_PYTHON */ 309 310 /** 311 * Allocate and initialize a new transaction. 312 * 313 * :param version: The version of the transaction. 314 * :param locktime: The locktime of the transaction. 315 * :param inputs_allocation_len: The number of inputs to pre-allocate space for. 316 * :param outputs_allocation_len: The number of outputs to pre-allocate space for. 317 * :param output: Destination for the resulting transaction output. 318 */ 319 WALLY_CORE_API int wally_tx_init_alloc( 320 uint32_t version, 321 uint32_t locktime, 322 size_t inputs_allocation_len, 323 size_t outputs_allocation_len, 324 struct wally_tx **output); 325 326 /** 327 * Create a new copy of a transaction. 328 * 329 * :param tx: The transaction to clone. 330 * :param flags: Flags controlling transaction creation. Must be 0. 331 * :param output: Destination for the resulting transaction copy. 332 */ 333 WALLY_CORE_API int wally_tx_clone_alloc( 334 const struct wally_tx *tx, 335 uint32_t flags, 336 struct wally_tx **output); 337 338 /** 339 * Add a transaction input to a transaction. 340 * 341 * :param tx: The transaction to add the input to. 342 * :param input: The transaction input to add to ``tx``. 343 */ 344 WALLY_CORE_API int wally_tx_add_input( 345 struct wally_tx *tx, 346 const struct wally_tx_input *input); 347 348 /** 349 * Add a transaction input to a transaction at a given position. 350 * 351 * :param tx: The transaction to add the input to. 352 * :param index: The zero-based index of the position to add the input at. 353 * :param input: The transaction input to add to ``tx``. 354 */ 355 WALLY_CORE_API int wally_tx_add_input_at( 356 struct wally_tx *tx, 357 uint32_t index, 358 const struct wally_tx_input *input); 359 360 /** 361 * Add a transaction input to a transaction. 362 * 363 * :param tx: The transaction to add the input to. 364 * :param txhash: The transaction hash of the transaction this input comes from. 365 * :param txhash_len: Size of ``txhash`` in bytes. Must be ``WALLY_TXHASH_LEN``. 366 * :param utxo_index: The zero-based index of the transaction output in ``txhash`` that 367 *| this input comes from. 368 * :param sequence: The sequence number for the input. 369 * :param script: The scriptSig for the input. 370 * :param script_len: Size of ``script`` in bytes. 371 * :param witness: The witness stack for the input, or NULL if no witness is present. 372 * :param flags: Flags controlling input creation. Must be 0. 373 */ 374 WALLY_CORE_API int wally_tx_add_raw_input( 375 struct wally_tx *tx, 376 const unsigned char *txhash, 377 size_t txhash_len, 378 uint32_t utxo_index, 379 uint32_t sequence, 380 const unsigned char *script, 381 size_t script_len, 382 const struct wally_tx_witness_stack *witness, 383 uint32_t flags); 384 385 /** 386 * Add a transaction input to a transaction in a goven position. 387 * 388 * :param tx: The transaction to add the input to. 389 * :param index: The zero-based index of the position to add the input at. 390 * :param txhash: The transaction hash of the transaction this input comes from. 391 * :param txhash_len: Size of ``txhash`` in bytes. Must be ``WALLY_TXHASH_LEN``. 392 * :param utxo_index: The zero-based index of the transaction output in ``txhash`` that 393 *| this input comes from. 394 * :param sequence: The sequence number for the input. 395 * :param script: The scriptSig for the input. 396 * :param script_len: Size of ``script`` in bytes. 397 * :param witness: The witness stack for the input, or NULL if no witness is present. 398 * :param flags: Flags controlling input creation. Must be 0. 399 */ 400 WALLY_CORE_API int wally_tx_add_raw_input_at( 401 struct wally_tx *tx, 402 uint32_t index, 403 const unsigned char *txhash, 404 size_t txhash_len, 405 uint32_t utxo_index, 406 uint32_t sequence, 407 const unsigned char *script, 408 size_t script_len, 409 const struct wally_tx_witness_stack *witness, 410 uint32_t flags); 411 412 /** 413 * Remove a transaction input from a transaction. 414 * 415 * :param tx: The transaction to remove the input from. 416 * :param index: The zero-based index of the input to remove. 417 */ 418 WALLY_CORE_API int wally_tx_remove_input( 419 struct wally_tx *tx, 420 size_t index); 421 422 /** 423 * Set the scriptsig for an input in a transaction. 424 * 425 * :param tx: The transaction to operate on. 426 * :param index: The zero-based index of the input to set the script on. 427 * :param script: The scriptSig for the input. 428 * :param script_len: Size of ``script`` in bytes. 429 */ 430 WALLY_CORE_API int wally_tx_set_input_script( 431 const struct wally_tx *tx, 432 size_t index, 433 const unsigned char *script, 434 size_t script_len); 435 436 /** 437 * Set the witness stack for an input in a transaction. 438 * 439 * :param tx: The transaction to operate on. 440 * :param index: The zero-based index of the input to set the witness stack on. 441 * :param stack: The transaction witness stack to set. 442 */ 443 444 WALLY_CORE_API int wally_tx_set_input_witness( 445 const struct wally_tx *tx, 446 size_t index, 447 const struct wally_tx_witness_stack *stack); 448 449 /** 450 * Add a transaction output to a transaction. 451 * 452 * :param tx: The transaction to add the output to. 453 * :param output: The transaction output to add to ``tx``. 454 */ 455 WALLY_CORE_API int wally_tx_add_output( 456 struct wally_tx *tx, 457 const struct wally_tx_output *output); 458 459 /** 460 * Add a transaction output to a transaction at a given position. 461 * 462 * :param tx: The transaction to add the output to. 463 * :param index: The zero-based index of the position to add the output at. 464 * :param output: The transaction output to add to ``tx``. 465 */ 466 WALLY_CORE_API int wally_tx_add_output_at( 467 struct wally_tx *tx, 468 uint32_t index, 469 const struct wally_tx_output *output); 470 471 /** 472 * Add a transaction output to a transaction. 473 * 474 * :param tx: The transaction to add the output to. 475 * :param satoshi: The amount of the output in satoshi. 476 * :param script: The scriptPubkey for the output. 477 * :param script_len: Size of ``script`` in bytes. 478 * :param flags: Flags controlling output creation. Must be 0. 479 */ 480 WALLY_CORE_API int wally_tx_add_raw_output( 481 struct wally_tx *tx, 482 uint64_t satoshi, 483 const unsigned char *script, 484 size_t script_len, 485 uint32_t flags); 486 487 /** 488 * Add a transaction output to a transaction at a given position. 489 * 490 * :param tx: The transaction to add the output to. 491 * :param index: The zero-based index of the position to add the output at. 492 * :param satoshi: The amount of the output in satoshi. 493 * :param script: The scriptPubkey for the output. 494 * :param script_len: Size of ``script`` in bytes. 495 * :param flags: Flags controlling output creation. Must be 0. 496 */ 497 WALLY_CORE_API int wally_tx_add_raw_output_at( 498 struct wally_tx *tx, 499 uint32_t index, 500 uint64_t satoshi, 501 const unsigned char *script, 502 size_t script_len, 503 uint32_t flags); 504 505 /** 506 * Remove a transaction output from a transaction. 507 * 508 * :param tx: The transaction to remove the output from. 509 * :param index: The zero-based index of the output to remove. 510 */ 511 WALLY_CORE_API int wally_tx_remove_output( 512 struct wally_tx *tx, 513 size_t index); 514 515 /** 516 * Get the number of inputs in a transaction that have witness data. 517 * 518 * :param tx: The transaction to get the witnesses count from. 519 * :param written: Destination for the number of witness-containing inputs. 520 */ 521 WALLY_CORE_API int wally_tx_get_witness_count( 522 const struct wally_tx *tx, 523 size_t *written); 524 525 #ifndef SWIG_PYTHON 526 /** 527 * Free a transaction allocated by `wally_tx_init_alloc`. 528 * 529 * :param tx: The transaction to free. 530 */ 531 WALLY_CORE_API int wally_tx_free(struct wally_tx *tx); 532 #endif /* SWIG_PYTHON */ 533 534 /** 535 * Return the txid of a transaction. 536 * 537 * :param tx: The transaction to compute the txid of. 538 * :param bytes_out: Destination for the txid. 539 * :param len: Size of ``bytes_out`` in bytes. Must be ``WALLY_TXHASH_LEN``. 540 * 541 * .. note:: The txid is expensive to compute. 542 */ 543 WALLY_CORE_API int wally_tx_get_txid( 544 const struct wally_tx *tx, 545 unsigned char *bytes_out, 546 size_t len); 547 548 /** 549 * Return the length of transaction once serialized into bytes. 550 * 551 * :param tx: The transaction to find the serialized length of. 552 * :param flags: ``WALLY_TX_FLAG_`` Flags controlling serialization options. 553 * :param written: Destination for the length of the serialized bytes. 554 */ 555 WALLY_CORE_API int wally_tx_get_length( 556 const struct wally_tx *tx, 557 uint32_t flags, 558 size_t *written); 559 560 /** 561 * Create a transaction from its serialized bytes. 562 * 563 * :param bytes: Bytes to create the transaction from. 564 * :param bytes_len: Length of ``bytes`` in bytes. 565 * :param flags: ``WALLY_TX_FLAG_`` Flags controlling serialization options. 566 * :param output: Destination for the resulting transaction. 567 */ 568 WALLY_CORE_API int wally_tx_from_bytes( 569 const unsigned char *bytes, 570 size_t bytes_len, 571 uint32_t flags, 572 struct wally_tx **output); 573 574 /** 575 * Create a transaction from its serialized bytes in hexadecimal. 576 * 577 * :param hex: Hexadecimal string containing the transaction. 578 * :param flags: ``WALLY_TX_FLAG_`` Flags controlling serialization options. 579 * :param output: Destination for the resulting transaction. 580 */ 581 WALLY_CORE_API int wally_tx_from_hex( 582 const char *hex, 583 uint32_t flags, 584 struct wally_tx **output); 585 586 /** 587 * Serialize a transaction to bytes. 588 * 589 * :param tx: The transaction to serialize. 590 * :param flags: ``WALLY_TX_FLAG_`` Flags controlling serialization options. 591 * :param bytes_out: Destination for the serialized transaction. 592 * :param len: Size of ``bytes_out`` in bytes. 593 * :param written: Destination for the length of the serialized transaction. 594 */ 595 WALLY_CORE_API int wally_tx_to_bytes( 596 const struct wally_tx *tx, 597 uint32_t flags, 598 unsigned char *bytes_out, 599 size_t len, 600 size_t *written); 601 602 /** 603 * Serialize a transaction to hex. 604 * 605 * :param tx: The transaction to serialize. 606 * :param flags: ``WALLY_TX_FLAG_`` Flags controlling serialization options. 607 * :param output: Destination for the resulting hexadecimal string. 608 * 609 * .. note:: The string returned should be freed using `wally_free_string`. 610 */ 611 WALLY_CORE_API int wally_tx_to_hex( 612 const struct wally_tx *tx, 613 uint32_t flags, 614 char **output); 615 616 /** 617 * Get the weight of a transaction. 618 * 619 * :param tx: The transaction to get the weight of. 620 * :param written: Destination for the weight. 621 */ 622 WALLY_CORE_API int wally_tx_get_weight( 623 const struct wally_tx *tx, 624 size_t *written); 625 626 /** 627 * Get the virtual size of a transaction. 628 * 629 * :param tx: The transaction to get the virtual size of. 630 * :param written: Destination for the virtual size. 631 */ 632 WALLY_CORE_API int wally_tx_get_vsize( 633 const struct wally_tx *tx, 634 size_t *written); 635 636 /** 637 * Compute transaction vsize from transaction weight. 638 * 639 * :param weight: The weight to convert to a virtual size. 640 * :param written: Destination for the virtual size. 641 */ 642 WALLY_CORE_API int wally_tx_vsize_from_weight( 643 size_t weight, 644 size_t *written); 645 646 /** 647 * Compute the total sum of all outputs in a transaction. 648 * 649 * :param tx: The transaction to compute the total from. 650 * :param value_out: Destination for the output total. 651 */ 652 WALLY_CORE_API int wally_tx_get_total_output_satoshi( 653 const struct wally_tx *tx, 654 uint64_t *value_out); 655 656 /** 657 * Create a BTC transaction for signing and return its hash. 658 * 659 * :param tx: The transaction to generate the signature hash from. 660 * :param index: The input index of the input being signed for. 661 * :param script: The (unprefixed) scriptCode for the input being signed. 662 * :param script_len: Size of ``script`` in bytes. 663 * :param satoshi: The amount spent by the input being signed for. Only used if 664 *| flags includes ``WALLY_TX_FLAG_USE_WITNESS``, pass 0 otherwise. 665 * :param sighash: ``WALLY_SIGHASH_`` flags specifying the type of signature desired. 666 * :param flags: ``WALLY_TX_FLAG_USE_WITNESS`` to generate a BIP 143 signature, or 0 667 *| to generate a pre-segwit Bitcoin signature. 668 * :param bytes_out: Destination for the signature hash. 669 * :param len: Size of ``bytes_out`` in bytes. Must be at least ``SHA256_LEN``. 670 */ 671 WALLY_CORE_API int wally_tx_get_btc_signature_hash( 672 const struct wally_tx *tx, 673 size_t index, 674 const unsigned char *script, 675 size_t script_len, 676 uint64_t satoshi, 677 uint32_t sighash, 678 uint32_t flags, 679 unsigned char *bytes_out, 680 size_t len); 681 682 /** 683 * Create a transaction for signing and return its hash. 684 * 685 * :param tx: The transaction to generate the signature hash from. 686 * :param index: The input index of the input being signed for. 687 * :param script: The (unprefixed) scriptCode for the input being signed. 688 * :param script_len: Size of ``script`` in bytes. 689 * :param extra: Extra bytes to include in the transaction preimage. 690 * :param extra_len: Size of ``extra`` in bytes. 691 * :param extra_offset: Offset with the preimage to store ``extra``. To store 692 *| it at the end of the preimage, use 0xffffffff. 693 * :param satoshi: The amount spent by the input being signed for. Only used if 694 *| flags includes ``WALLY_TX_FLAG_USE_WITNESS``, pass 0 otherwise. 695 * :param sighash: ``WALLY_SIGHASH_`` flags specifying the type of signature desired. 696 * :param tx_sighash: The 32bit sighash value to include in the preimage to hash. 697 *| This must be given in host CPU endianess; For normal Bitcoin signing 698 *| the value of ``sighash`` should be given. 699 * :param flags: ``WALLY_TX_FLAG_USE_WITNESS`` to generate a BIP 143 signature, or 0 700 *| to generate a pre-segwit Bitcoin signature. 701 * :param bytes_out: Destination for the signature hash. 702 * :param len: Size of ``bytes_out`` in bytes. Must be at least ``SHA256_LEN``. 703 */ 704 WALLY_CORE_API int wally_tx_get_signature_hash( 705 const struct wally_tx *tx, 706 size_t index, 707 const unsigned char *script, 708 size_t script_len, 709 const unsigned char *extra, 710 size_t extra_len, 711 uint32_t extra_offset, 712 uint64_t satoshi, 713 uint32_t sighash, 714 uint32_t tx_sighash, 715 uint32_t flags, 716 unsigned char *bytes_out, 717 size_t len); 718 719 /** 720 * Determine if a transaction is a coinbase transaction. 721 * 722 * :param tx: The transaction to check. 723 * :param written: 1 if the transaction is a coinbase transaction, otherwise 0. 724 */ 725 WALLY_CORE_API int wally_tx_is_coinbase( 726 const struct wally_tx *tx, 727 size_t *written); 728 729 #ifdef BUILD_ELEMENTS 730 /** 731 * Set issuance data on an input. 732 * 733 * :param input: The input to add to. 734 * :param nonce: Asset issuance or revelation blinding factor. 735 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 736 * :param entropy: Entropy for the asset tag calculation. 737 * :param entropy_len: Size of ``entropy`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 738 * :param issuance_amount: The (blinded) issuance amount. 739 * :param issuance_amount_len: Size of ``issuance_amount`` in bytes. 740 * :param inflation_keys: The (blinded) token reissuance amount. 741 * :param inflation_keys_len: Size of ``ìnflation_keys`` in bytes. 742 * :param issuance_amount_rangeproof: Issuance amount rangeproof. 743 * :param issuance_amount_rangeproof_len: Size of ``issuance_amount_rangeproof`` in bytes. 744 * :param inflation_keys_rangeproof: Inflation keys rangeproof. 745 * :param inflation_keys_rangeproof_len: Size of ``inflation_keys_rangeproof`` in bytes. 746 */ 747 WALLY_CORE_API int wally_tx_elements_input_issuance_set( 748 struct wally_tx_input *input, 749 const unsigned char *nonce, 750 size_t nonce_len, 751 const unsigned char *entropy, 752 size_t entropy_len, 753 const unsigned char *issuance_amount, 754 size_t issuance_amount_len, 755 const unsigned char *inflation_keys, 756 size_t inflation_keys_len, 757 const unsigned char *issuance_amount_rangeproof, 758 size_t issuance_amount_rangeproof_len, 759 const unsigned char *inflation_keys_rangeproof, 760 size_t inflation_keys_rangeproof_len); 761 762 #ifndef SWIG_PYTHON 763 /** 764 * Free issuance data on an input. 765 * 766 * :param input: The input issuance data to free. 767 */ 768 WALLY_CORE_API int wally_tx_elements_input_issuance_free( 769 struct wally_tx_input *input); 770 #endif /* SWIG_PYTHON */ 771 772 /** 773 * Allocate and initialize a new elements transaction input. 774 * 775 * :param txhash: The transaction hash of the transaction this input comes from. 776 * :param txhash_len: Size of ``txhash`` in bytes. Must be ``WALLY_TXHASH_LEN``. 777 * :param utxo_index: The zero-based index of the transaction output in ``txhash`` that 778 *| this input comes from. 779 * :param sequence: The sequence number for the input. 780 * :param script: The scriptSig for the input. 781 * :param script_len: Size of ``script`` in bytes. 782 * :param witness: The witness stack for the input, or NULL if no witness is present. 783 * :param nonce: Asset issuance or revelation blinding factor. 784 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 785 * :param entropy: Entropy for the asset tag calculation. 786 * :param entropy_len: Size of ``entropy`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 787 * :param issuance_amount: The (blinded) issuance amount. 788 * :param issuance_amount_len: Size of ``issuance_amount`` in bytes. 789 * :param inflation_keys: The (blinded) token reissuance amount. 790 * :param inflation_keys_len: Size of ``ìnflation_keys`` in bytes. 791 * :param issuance_amount_rangeproof: Issuance amount rangeproof. 792 * :param issuance_amount_rangeproof_len: Size of ``issuance_amount_rangeproof`` in bytes. 793 * :param inflation_keys_rangeproof: Inflation keys rangeproof. 794 * :param inflation_keys_rangeproof_len: Size of ``inflation_keys_rangeproof`` in bytes. 795 * :param pegin_witness: The pegin witness stack for the input, or NULL if no witness is present. 796 * :param output: Destination for the resulting transaction input. 797 */ 798 WALLY_CORE_API int wally_tx_elements_input_init_alloc( 799 const unsigned char *txhash, 800 size_t txhash_len, 801 uint32_t utxo_index, 802 uint32_t sequence, 803 const unsigned char *script, 804 size_t script_len, 805 const struct wally_tx_witness_stack *witness, 806 const unsigned char *nonce, 807 size_t nonce_len, 808 const unsigned char *entropy, 809 size_t entropy_len, 810 const unsigned char *issuance_amount, 811 size_t issuance_amount_len, 812 const unsigned char *inflation_keys, 813 size_t inflation_keys_len, 814 const unsigned char *issuance_amount_rangeproof, 815 size_t issuance_amount_rangeproof_len, 816 const unsigned char *inflation_keys_rangeproof, 817 size_t inflation_keys_rangeproof_len, 818 const struct wally_tx_witness_stack *pegin_witness, 819 struct wally_tx_input **output); 820 821 /** 822 * Determine if an input is a pegin. 823 * 824 * :param input: The input to check. 825 * :param written: 1 if the input is a pegin, otherwise 0. 826 */ 827 WALLY_CORE_API int wally_tx_elements_input_is_pegin( 828 const struct wally_tx_input *input, 829 size_t *written); 830 831 /** 832 * Set commitment data on an output. 833 * 834 * :param output: The output to add to. 835 * :param asset: The commitment to a possibly blinded asset. 836 * :param asset_len: Size of ``asset`` in bytes. Must be ``WALLY_TX_ASSET_CT_ASSET_LEN``. 837 * :param value: The commitment to a possibly blinded value. 838 * :param value_len: Size of ``value`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_LEN`` or ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``. 839 * :param nonce: The commitment used to create the nonce (with the blinding key) for the range proof. 840 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_CT_NONCE_LEN``. 841 * :param surjectionproof: surjection proof. 842 * :param surjectionproof_len: Size of ``surjectionproof`` in bytes. 843 * :param rangeproof: rangeproof. 844 * :param rangeproof_len: Size of ``rangeproof`` in bytes. 845 */ 846 WALLY_CORE_API int wally_tx_elements_output_commitment_set( 847 struct wally_tx_output *output, 848 const unsigned char *asset, 849 size_t asset_len, 850 const unsigned char *value, 851 size_t value_len, 852 const unsigned char *nonce, 853 size_t nonce_len, 854 const unsigned char *surjectionproof, 855 size_t surjectionproof_len, 856 const unsigned char *rangeproof, 857 size_t rangeproof_len); 858 859 #ifndef SWIG_PYTHON 860 /** 861 * Free commitment data on an output. 862 * 863 * :param output: The output with the commitment data to free. 864 */ 865 WALLY_CORE_API int wally_tx_elements_output_commitment_free( 866 struct wally_tx_output *output); 867 #endif /* SWIG_PYTHON */ 868 869 #ifndef SWIG 870 /** 871 * Initialize a new elements transaction output in place. 872 * 873 * :param script: The scriptPubkey for the output. 874 * :param script_len: Size of ``script`` in bytes. 875 * :param asset: The asset tag of the output. 876 * :param asset_len: Size of ``asset`` in bytes. Must be ``WALLY_TX_ASSET_CT_ASSET_LEN``. 877 * :param value: The commitment to a possibly blinded value. 878 * :param value_len: Size of ``value`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_LEN`` or ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``. 879 * :param nonce: The commitment used to create the nonce (with the blinding key) for the range proof. 880 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_CT_NONCE_LEN``. 881 * :param surjectionproof: The surjection proof. 882 * :param surjectionproof_len: Size of ``surjectionproof`` in bytes. 883 * :param rangeproof: The range proof. 884 * :param rangeproof_len: Size of ``rangeproof`` in bytes. 885 * :param output: Destination for the resulting transaction output copy. 886 * 887 * .. note:: ``output`` is overwritten in place, and not cleared first. 888 */ 889 WALLY_CORE_API int wally_tx_elements_output_init( 890 const unsigned char *script, 891 size_t script_len, 892 const unsigned char *asset, 893 size_t asset_len, 894 const unsigned char *value, 895 size_t value_len, 896 const unsigned char *nonce, 897 size_t nonce_len, 898 const unsigned char *surjectionproof, 899 size_t surjectionproof_len, 900 const unsigned char *rangeproof, 901 size_t rangeproof_len, 902 struct wally_tx_output *output); 903 #endif /* SWIG */ 904 905 /** 906 * Allocate and initialize a new elements transaction output. 907 * 908 * :param script: The scriptPubkey for the output. 909 * :param script_len: Size of ``script`` in bytes. 910 * :param asset: The asset tag of the output. 911 * :param asset_len: Size of ``asset`` in bytes. Must be ``WALLY_TX_ASSET_CT_ASSET_LEN``. 912 * :param value: The commitment to a possibly blinded value. 913 * :param value_len: Size of ``value`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_LEN`` or ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``. 914 * :param nonce: The commitment used to create the nonce (with the blinding key) for the range proof. 915 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_CT_NONCE_LEN``. 916 * :param surjectionproof: The surjection proof. 917 * :param surjectionproof_len: Size of ``surjectionproof`` in bytes. 918 * :param rangeproof: The range proof. 919 * :param rangeproof_len: Size of ``rangeproof`` in bytes. 920 * :param output: Destination for the resulting transaction output. 921 */ 922 WALLY_CORE_API int wally_tx_elements_output_init_alloc( 923 const unsigned char *script, 924 size_t script_len, 925 const unsigned char *asset, 926 size_t asset_len, 927 const unsigned char *value, 928 size_t value_len, 929 const unsigned char *nonce, 930 size_t nonce_len, 931 const unsigned char *surjectionproof, 932 size_t surjectionproof_len, 933 const unsigned char *rangeproof, 934 size_t rangeproof_len, 935 struct wally_tx_output **output); 936 937 /** 938 * Add an elements transaction input to a transaction. 939 * 940 * :param tx: The transaction to add the input to. 941 * :param txhash: The transaction hash of the transaction this input comes from. 942 * :param txhash_len: Size of ``txhash`` in bytes. Must be ``WALLY_TXHASH_LEN``. 943 * :param utxo_index: The zero-based index of the transaction output in ``txhash`` that 944 *| this input comes from. 945 * :param sequence: The sequence number for the input. 946 * :param script: The scriptSig for the input. 947 * :param script_len: Size of ``script`` in bytes. 948 * :param witness: The witness stack for the input, or NULL if no witness is present. 949 * :param nonce: Asset issuance or revelation blinding factor. 950 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 951 * :param entropy: Entropy for the asset tag calculation. 952 * :param entropy_len: Size of ``entropy`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 953 * :param issuance_amount: The (blinded) issuance amount. 954 * :param issuance_amount_len: Size of ``issuance_amount`` in bytes. 955 * :param inflation_keys: The (blinded) token reissuance amount. 956 * :param inflation_keys_len: Size of ``ìnflation_keys`` in bytes. 957 * :param issuance_amount_rangeproof: Issuance amount rangeproof. 958 * :param issuance_amount_rangeproof_len: Size of ``issuance_amount_rangeproof`` in bytes. 959 * :param inflation_keys_rangeproof: Inflation keys rangeproof. 960 * :param inflation_keys_rangeproof_len: Size of ``inflation_keys_rangeproof`` in bytes. 961 * :param pegin_witness: The pegin witness stack for the input, or NULL if no witness is present. 962 * :param flags: Flags controlling input creation. Must be 0. 963 */ 964 WALLY_CORE_API int wally_tx_add_elements_raw_input( 965 struct wally_tx *tx, 966 const unsigned char *txhash, 967 size_t txhash_len, 968 uint32_t utxo_index, 969 uint32_t sequence, 970 const unsigned char *script, 971 size_t script_len, 972 const struct wally_tx_witness_stack *witness, 973 const unsigned char *nonce, 974 size_t nonce_len, 975 const unsigned char *entropy, 976 size_t entropy_len, 977 const unsigned char *issuance_amount, 978 size_t issuance_amount_len, 979 const unsigned char *inflation_keys, 980 size_t inflation_keys_len, 981 const unsigned char *issuance_amount_rangeproof, 982 size_t issuance_amount_rangeproof_len, 983 const unsigned char *inflation_keys_rangeproof, 984 size_t inflation_keys_rangeproof_len, 985 const struct wally_tx_witness_stack *pegin_witness, 986 uint32_t flags); 987 988 /** 989 * Add an elements transaction input to a transaction at a given position. 990 * 991 * :param tx: The transaction to add the input to. 992 * :param index: The zero-based index of the position to add the input at. 993 * :param txhash: The transaction hash of the transaction this input comes from. 994 * :param txhash_len: Size of ``txhash`` in bytes. Must be ``WALLY_TXHASH_LEN``. 995 * :param utxo_index: The zero-based index of the transaction output in ``txhash`` that 996 *| this input comes from. 997 * :param sequence: The sequence number for the input. 998 * :param script: The scriptSig for the input. 999 * :param script_len: Size of ``script`` in bytes. 1000 * :param witness: The witness stack for the input, or NULL if no witness is present. 1001 * :param nonce: Asset issuance or revelation blinding factor. 1002 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 1003 * :param entropy: Entropy for the asset tag calculation. 1004 * :param entropy_len: Size of ``entropy`` in bytes. Must be ``WALLY_TX_ASSET_TAG_LEN``. 1005 * :param issuance_amount: The (blinded) issuance amount. 1006 * :param issuance_amount_len: Size of ``issuance_amount`` in bytes. 1007 * :param inflation_keys: The (blinded) token reissuance amount. 1008 * :param inflation_keys_len: Size of ``ìnflation_keys`` in bytes. 1009 * :param issuance_amount_rangeproof: Issuance amount rangeproof. 1010 * :param issuance_amount_rangeproof_len: Size of ``issuance_amount_rangeproof`` in bytes. 1011 * :param inflation_keys_rangeproof: Inflation keys rangeproof. 1012 * :param inflation_keys_rangeproof_len: Size of ``inflation_keys_rangeproof`` in bytes. 1013 * :param pegin_witness: The pegin witness stack for the input, or NULL if no witness is present. 1014 * :param flags: Flags controlling input creation. Must be 0. 1015 */ 1016 WALLY_CORE_API int wally_tx_add_elements_raw_input_at( 1017 struct wally_tx *tx, 1018 uint32_t index, 1019 const unsigned char *txhash, 1020 size_t txhash_len, 1021 uint32_t utxo_index, 1022 uint32_t sequence, 1023 const unsigned char *script, 1024 size_t script_len, 1025 const struct wally_tx_witness_stack *witness, 1026 const unsigned char *nonce, 1027 size_t nonce_len, 1028 const unsigned char *entropy, 1029 size_t entropy_len, 1030 const unsigned char *issuance_amount, 1031 size_t issuance_amount_len, 1032 const unsigned char *inflation_keys, 1033 size_t inflation_keys_len, 1034 const unsigned char *issuance_amount_rangeproof, 1035 size_t issuance_amount_rangeproof_len, 1036 const unsigned char *inflation_keys_rangeproof, 1037 size_t inflation_keys_rangeproof_len, 1038 const struct wally_tx_witness_stack *pegin_witness, 1039 uint32_t flags); 1040 1041 /** 1042 * Add a elements transaction output to a transaction. 1043 * 1044 * :param tx: The transaction to add the output to. 1045 * :param script: The scriptPubkey for the output. 1046 * :param script_len: Size of ``script`` in bytes. 1047 * :param asset: The asset tag of the output. 1048 * :param asset_len: Size of ``asset`` in bytes. Must be ``WALLY_TX_ASSET_CT_ASSET_LEN``. 1049 * :param value: The commitment to a possibly blinded value. 1050 * :param value_len: Size of ``value`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_LEN`` or ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``. 1051 * :param nonce: The commitment used to create the nonce (with the blinding key) for the range proof. 1052 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_CT_NONCE_LEN``. 1053 * :param surjectionproof: The surjection proof. 1054 * :param surjectionproof_len: Size of ``surjectionproof`` in bytes. 1055 * :param rangeproof: The range proof. 1056 * :param rangeproof_len: Size of ``rangeproof`` in bytes. 1057 * :param flags: Flags controlling output creation. Must be 0. 1058 */ 1059 WALLY_CORE_API int wally_tx_add_elements_raw_output( 1060 struct wally_tx *tx, 1061 const unsigned char *script, 1062 size_t script_len, 1063 const unsigned char *asset, 1064 size_t asset_len, 1065 const unsigned char *value, 1066 size_t value_len, 1067 const unsigned char *nonce, 1068 size_t nonce_len, 1069 const unsigned char *surjectionproof, 1070 size_t surjectionproof_len, 1071 const unsigned char *rangeproof, 1072 size_t rangeproof_len, 1073 uint32_t flags); 1074 1075 /** 1076 * Add a elements transaction output to a transaction at a given position. 1077 * 1078 * :param tx: The transaction to add the output to. 1079 * :param index: The zero-based index of the position to add the output at. 1080 * :param script: The scriptPubkey for the output. 1081 * :param script_len: Size of ``script`` in bytes. 1082 * :param asset: The asset tag of the output. 1083 * :param asset_len: Size of ``asset`` in bytes. Must be ``WALLY_TX_ASSET_CT_ASSET_LEN``. 1084 * :param value: The commitment to a possibly blinded value. 1085 * :param value_len: Size of ``value`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_LEN`` or ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``. 1086 * :param nonce: The commitment used to create the nonce (with the blinding key) for the range proof. 1087 * :param nonce_len: Size of ``nonce`` in bytes. Must be ``WALLY_TX_ASSET_CT_NONCE_LEN``. 1088 * :param surjectionproof: The surjection proof. 1089 * :param surjectionproof_len: Size of ``surjectionproof`` in bytes. 1090 * :param rangeproof: The range proof. 1091 * :param rangeproof_len: Size of ``rangeproof`` in bytes. 1092 * :param flags: Flags controlling output creation. Must be 0. 1093 */ 1094 WALLY_CORE_API int wally_tx_add_elements_raw_output_at( 1095 struct wally_tx *tx, 1096 uint32_t index, 1097 const unsigned char *script, 1098 size_t script_len, 1099 const unsigned char *asset, 1100 size_t asset_len, 1101 const unsigned char *value, 1102 size_t value_len, 1103 const unsigned char *nonce, 1104 size_t nonce_len, 1105 const unsigned char *surjectionproof, 1106 size_t surjectionproof_len, 1107 const unsigned char *rangeproof, 1108 size_t rangeproof_len, 1109 uint32_t flags); 1110 1111 /** 1112 * Determine if a transaction is an elements transaction. 1113 * 1114 * :param tx: The transaction to check. 1115 * :param written: 1 if the transaction is an elements transaction, otherwise 0. 1116 */ 1117 WALLY_CORE_API int wally_tx_is_elements( 1118 const struct wally_tx *tx, 1119 size_t *written); 1120 1121 /** 1122 * Convert satoshi to an explicit confidential value representation. 1123 * 1124 * :param satoshi: The value in satoshi to convert. 1125 * :param bytes_out: Destination for the confidential value bytes. 1126 * :param len: Size of ``bytes_out`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``. 1127 */ 1128 WALLY_CORE_API int wally_tx_confidential_value_from_satoshi( 1129 uint64_t satoshi, 1130 unsigned char *bytes_out, 1131 size_t len); 1132 1133 /** 1134 * Convert an explicit confidential value representation to satoshi. 1135 * 1136 * :param value: The confidential value bytes. 1137 * :param value_len: Size of ``value`` in bytes. Must be ``WALLY_TX_ASSET_CT_VALUE_UNBLIND_LEN``. 1138 * :param value_out: The converted value in satoshi. 1139 */ 1140 WALLY_CORE_API int wally_tx_confidential_value_to_satoshi( 1141 const unsigned char *value, 1142 size_t value_len, 1143 uint64_t *value_out); 1144 1145 /** 1146 * Create a Elements transaction for signing and return its hash. 1147 * 1148 * :param tx: The transaction to generate the signature hash from. 1149 * :param index: The input index of the input being signed for. 1150 * :param script: The (unprefixed) scriptCode for the input being signed. 1151 * :param script_len: Size of ``script`` in bytes. 1152 * :param value: The (confidential) value spent by the input being signed for. Only used if 1153 *| flags includes ``WALLY_TX_FLAG_USE_WITNESS``, pass NULL otherwise. 1154 * :param value_len: Size of ``value`` in bytes. 1155 * :param sighash: ``WALLY_SIGHASH_`` flags specifying the type of signature desired. 1156 * :param flags: ``WALLY_TX_FLAG_USE_WITNESS`` to generate a BIP 143 signature, or 0 1157 *| to generate a pre-segwit Bitcoin signature. 1158 * :param bytes_out: Destination for the signature hash. 1159 * :param len: Size of ``bytes_out`` in bytes. Must be ``SHA256_LEN``. 1160 */ 1161 WALLY_CORE_API int wally_tx_get_elements_signature_hash( 1162 const struct wally_tx *tx, 1163 size_t index, 1164 const unsigned char *script, 1165 size_t script_len, 1166 const unsigned char *value, 1167 size_t value_len, 1168 uint32_t sighash, 1169 uint32_t flags, 1170 unsigned char *bytes_out, 1171 size_t len); 1172 1173 /** 1174 * Calculate the asset entropy from a prevout and the Ricardian contract hash. 1175 * 1176 * :param txhash: The prevout transaction hash. 1177 * :param txhash_len: Size of ``txhash`` in bytes. Must be ``WALLY_TXHASH_LEN``. 1178 * :param utxo_index: The zero-based index of the transaction output 1179 *| in ``txhash`` to use. 1180 * :param contract_hash: The issuer specified Ricardian contract hash. 1181 * :param contract_hash_len: Size of ``contract hash`` in bytes. Must be ``SHA256_LEN``. 1182 * :param bytes_out: Destination for the asset entropy. 1183 * :param len: Size of ``bytes_out`` in bytes. Must be ``SHA256_LEN``. 1184 */ 1185 WALLY_CORE_API int wally_tx_elements_issuance_generate_entropy( 1186 const unsigned char *txhash, 1187 size_t txhash_len, 1188 uint32_t index, 1189 const unsigned char *contract_hash, 1190 size_t contract_hash_len, 1191 unsigned char *bytes_out, 1192 size_t len); 1193 1194 /** 1195 * Calculate the asset from the entropy. 1196 * 1197 * :param entropy: The asset entropy. 1198 * :param entropy_len: Size of ``entropy`` in bytes. Must be ``SHA256_LEN``. 1199 * :param bytes_out: Destination for the asset tag. 1200 * :param len: Size of ``bytes_out`` in bytes. Must be ``SHA256_LEN``. 1201 */ 1202 WALLY_CORE_API int wally_tx_elements_issuance_calculate_asset( 1203 const unsigned char *entropy, 1204 size_t entropy_len, 1205 unsigned char *bytes_out, 1206 size_t len); 1207 1208 /** 1209 * Calculate a re-issuance token from an asset's entropy. 1210 * 1211 * :param entropy: The asset entropy. 1212 * :param entropy_len: Size of ``entropy`` in bytes. Must be ``SHA256_LEN``. 1213 * :param flags: ``WALLY_TX_FLAG_BLINDED_INITIAL_ISSUANCE`` if initial issuance was blinded, 1214 *| pass 0 otherwise. 1215 * :param bytes_out: Destination for the re-issuance token. 1216 * :param len: Size of ``bytes_out`` in bytes. Must be ``SHA256_LEN``. 1217 */ 1218 WALLY_CORE_API int wally_tx_elements_issuance_calculate_reissuance_token( 1219 const unsigned char *entropy, 1220 size_t entropy_len, 1221 uint32_t flags, 1222 unsigned char *bytes_out, 1223 size_t len); 1224 1225 #endif /* BUILD_ELEMENTS */ 1226 1227 #ifdef __cplusplus 1228 } 1229 #endif 1230 1231 #endif /* LIBWALLY_CORE_TRANSACTION_H */ 1232