vuke 0.9.0

Research tool for studying vulnerable Bitcoin key generation practices
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
//! Arrow schema definition for result storage.
//!
//! Defines a flat Arrow schema that maps to `ResultRecord` for efficient
//! Parquet storage and querying via DuckDB/Polars.

use std::sync::Arc;

use arrow::array::{
    ArrayRef, FixedSizeBinaryBuilder, RecordBatch, StringArray, TimestampMillisecondArray,
    UInt16Array, UInt8Array,
};
use arrow::datatypes::{DataType, Field, Schema, TimeUnit};
use arrow::error::ArrowError;

use super::{AddressRecord, ExportFormatRecord, PublicKeyRecord, ResultRecord};

/// Field names for the result schema.
pub mod fields {
    // Core metadata
    pub const SOURCE: &str = "source";
    pub const TRANSFORM: &str = "transform";
    pub const CHAIN: &str = "chain";
    pub const TIMESTAMP: &str = "timestamp";
    pub const MATCHED_TARGET: &str = "matched_target";

    // Private key
    pub const PRIVATE_KEY_RAW: &str = "private_key_raw";
    pub const PRIVATE_KEY_HEX: &str = "private_key_hex";
    pub const PRIVATE_KEY_DECIMAL: &str = "private_key_decimal";
    pub const PRIVATE_KEY_BINARY: &str = "private_key_binary";
    pub const PRIVATE_KEY_BIT_LENGTH: &str = "private_key_bit_length";
    pub const PRIVATE_KEY_HAMMING_WEIGHT: &str = "private_key_hamming_weight";
    pub const PRIVATE_KEY_LEADING_ZEROS: &str = "private_key_leading_zeros";

    // Public keys
    pub const PUBKEY_COMPRESSED: &str = "pubkey_compressed";
    pub const PUBKEY_UNCOMPRESSED: &str = "pubkey_uncompressed";

    // Addresses
    pub const ADDRESS_P2PKH_COMPRESSED: &str = "address_p2pkh_compressed";
    pub const ADDRESS_P2PKH_UNCOMPRESSED: &str = "address_p2pkh_uncompressed";
    pub const ADDRESS_P2WPKH: &str = "address_p2wpkh";

    // Export formats
    pub const WIF_COMPRESSED: &str = "wif_compressed";
    pub const WIF_UNCOMPRESSED: &str = "wif_uncompressed";
}

/// Returns the Arrow schema for ResultRecord storage.
///
/// The schema is flat (no nested types) for easy querying with SQL-based tools.
/// Variable-length fields (public_keys, addresses, export_formats) are mapped
/// to fixed columns based on known Bitcoin formats.
///
/// # Schema (19 columns)
///
/// | Column | Type | Nullable | Description |
/// |--------|------|----------|-------------|
/// | source | Utf8 | No | Input value (seed, passphrase) |
/// | transform | Utf8 | No | Transform name (sha256, milksad) |
/// | chain | Utf8 | No | Blockchain (bitcoin, ethereum) |
/// | timestamp | Timestamp(ms, UTC) | No | Generation time |
/// | matched_target | Utf8 | Yes | Matched address (scan hits only) |
/// | private_key_raw | FixedSizeBinary(32) | No | Raw 32-byte key |
/// | private_key_hex | Utf8 | No | Hex representation |
/// | private_key_decimal | Utf8 | No | Decimal representation |
/// | private_key_binary | Utf8 | No | Binary representation (256 chars) |
/// | private_key_bit_length | UInt16 | No | Effective bit length |
/// | private_key_hamming_weight | UInt16 | No | Number of 1-bits |
/// | private_key_leading_zeros | UInt8 | No | Leading zeros in hex |
/// | pubkey_compressed | Utf8 | Yes | Compressed public key |
/// | pubkey_uncompressed | Utf8 | Yes | Uncompressed public key |
/// | address_p2pkh_compressed | Utf8 | Yes | P2PKH (compressed) |
/// | address_p2pkh_uncompressed | Utf8 | Yes | P2PKH (uncompressed) |
/// | address_p2wpkh | Utf8 | Yes | P2WPKH (native segwit) |
/// | wif_compressed | Utf8 | Yes | WIF compressed |
/// | wif_uncompressed | Utf8 | Yes | WIF uncompressed |
pub fn result_schema() -> Schema {
    Schema::new(vec![
        // Core metadata
        Field::new(fields::SOURCE, DataType::Utf8, false),
        Field::new(fields::TRANSFORM, DataType::Utf8, false),
        Field::new(fields::CHAIN, DataType::Utf8, false),
        Field::new(
            fields::TIMESTAMP,
            DataType::Timestamp(TimeUnit::Millisecond, Some("UTC".into())),
            false,
        ),
        Field::new(fields::MATCHED_TARGET, DataType::Utf8, true),
        // Private key
        Field::new(
            fields::PRIVATE_KEY_RAW,
            DataType::FixedSizeBinary(32),
            false,
        ),
        Field::new(fields::PRIVATE_KEY_HEX, DataType::Utf8, false),
        Field::new(fields::PRIVATE_KEY_DECIMAL, DataType::Utf8, false),
        Field::new(fields::PRIVATE_KEY_BINARY, DataType::Utf8, false),
        Field::new(fields::PRIVATE_KEY_BIT_LENGTH, DataType::UInt16, false),
        Field::new(fields::PRIVATE_KEY_HAMMING_WEIGHT, DataType::UInt16, false),
        Field::new(fields::PRIVATE_KEY_LEADING_ZEROS, DataType::UInt8, false),
        // Public keys (nullable for non-Bitcoin chains)
        Field::new(fields::PUBKEY_COMPRESSED, DataType::Utf8, true),
        Field::new(fields::PUBKEY_UNCOMPRESSED, DataType::Utf8, true),
        // Addresses (nullable)
        Field::new(fields::ADDRESS_P2PKH_COMPRESSED, DataType::Utf8, true),
        Field::new(fields::ADDRESS_P2PKH_UNCOMPRESSED, DataType::Utf8, true),
        Field::new(fields::ADDRESS_P2WPKH, DataType::Utf8, true),
        // Export formats (nullable)
        Field::new(fields::WIF_COMPRESSED, DataType::Utf8, true),
        Field::new(fields::WIF_UNCOMPRESSED, DataType::Utf8, true),
    ])
}

/// Find a public key by format.
fn find_pubkey<'a>(records: &'a [PublicKeyRecord<'a>], format: &str) -> Option<&'a str> {
    records
        .iter()
        .find(|pk| pk.format == format)
        .map(|pk| pk.value)
}

/// Find an address by type.
fn find_address<'a>(records: &'a [AddressRecord<'a>], addr_type: &str) -> Option<&'a str> {
    records
        .iter()
        .find(|addr| addr.address_type == addr_type)
        .map(|addr| addr.address)
}

/// Find an export format by name.
fn find_export<'a>(records: &'a [ExportFormatRecord<'a>], format: &str) -> Option<&'a str> {
    records
        .iter()
        .find(|ef| ef.format == format)
        .map(|ef| ef.value)
}

/// Convert a batch of ResultRecords to an Arrow RecordBatch.
///
/// # Arguments
///
/// * `records` - Slice of ResultRecords to convert
///
/// # Returns
///
/// Arrow RecordBatch with the schema from `result_schema()`.
///
/// # Errors
///
/// Returns `ArrowError` if array construction fails.
pub fn records_to_batch(records: &[ResultRecord<'_>]) -> Result<RecordBatch, ArrowError> {
    let schema = Arc::new(result_schema());

    // Core metadata arrays
    let source_array: ArrayRef = Arc::new(StringArray::from_iter_values(
        records.iter().map(|r| r.source),
    ));
    let transform_array: ArrayRef = Arc::new(StringArray::from_iter_values(
        records.iter().map(|r| r.transform),
    ));
    let chain_array: ArrayRef = Arc::new(StringArray::from_iter_values(
        records.iter().map(|r| r.chain),
    ));
    let timestamp_array: ArrayRef = Arc::new(
        TimestampMillisecondArray::from_iter_values(
            records.iter().map(|r| r.timestamp.timestamp_millis()),
        )
        .with_timezone("UTC"),
    );
    let matched_target_array: ArrayRef = Arc::new(StringArray::from(
        records.iter().map(|r| r.matched_target).collect::<Vec<_>>(),
    ));

    // Private key arrays
    let private_key_raw_array: ArrayRef = {
        let mut builder = FixedSizeBinaryBuilder::with_capacity(records.len(), 32);
        for r in records {
            builder.append_value(r.private_key.raw)?;
        }
        Arc::new(builder.finish())
    };
    let private_key_hex_array: ArrayRef = Arc::new(StringArray::from_iter_values(
        records.iter().map(|r| r.private_key.hex),
    ));
    let private_key_decimal_array: ArrayRef = Arc::new(StringArray::from_iter_values(
        records.iter().map(|r| r.private_key.decimal),
    ));
    let private_key_binary_array: ArrayRef = Arc::new(StringArray::from_iter_values(
        records.iter().map(|r| r.private_key.binary),
    ));
    let private_key_bit_length_array: ArrayRef = Arc::new(UInt16Array::from_iter_values(
        records.iter().map(|r| r.private_key.bit_length),
    ));
    let private_key_hamming_weight_array: ArrayRef = Arc::new(UInt16Array::from_iter_values(
        records.iter().map(|r| r.private_key.hamming_weight),
    ));
    let private_key_leading_zeros_array: ArrayRef = Arc::new(UInt8Array::from_iter_values(
        records.iter().map(|r| r.private_key.leading_zeros),
    ));

    // Public key arrays (nullable)
    let pubkey_compressed_array: ArrayRef = Arc::new(StringArray::from(
        records
            .iter()
            .map(|r| find_pubkey(r.public_keys, "compressed"))
            .collect::<Vec<_>>(),
    ));
    let pubkey_uncompressed_array: ArrayRef = Arc::new(StringArray::from(
        records
            .iter()
            .map(|r| find_pubkey(r.public_keys, "uncompressed"))
            .collect::<Vec<_>>(),
    ));

    // Address arrays (nullable)
    let address_p2pkh_compressed_array: ArrayRef = Arc::new(StringArray::from(
        records
            .iter()
            .map(|r| find_address(r.addresses, "p2pkh_compressed"))
            .collect::<Vec<_>>(),
    ));
    let address_p2pkh_uncompressed_array: ArrayRef = Arc::new(StringArray::from(
        records
            .iter()
            .map(|r| find_address(r.addresses, "p2pkh_uncompressed"))
            .collect::<Vec<_>>(),
    ));
    let address_p2wpkh_array: ArrayRef = Arc::new(StringArray::from(
        records
            .iter()
            .map(|r| find_address(r.addresses, "p2wpkh"))
            .collect::<Vec<_>>(),
    ));

    // Export format arrays (nullable)
    let wif_compressed_array: ArrayRef = Arc::new(StringArray::from(
        records
            .iter()
            .map(|r| find_export(r.export_formats, "wif_compressed"))
            .collect::<Vec<_>>(),
    ));
    let wif_uncompressed_array: ArrayRef = Arc::new(StringArray::from(
        records
            .iter()
            .map(|r| find_export(r.export_formats, "wif_uncompressed"))
            .collect::<Vec<_>>(),
    ));

    RecordBatch::try_new(
        schema,
        vec![
            source_array,
            transform_array,
            chain_array,
            timestamp_array,
            matched_target_array,
            private_key_raw_array,
            private_key_hex_array,
            private_key_decimal_array,
            private_key_binary_array,
            private_key_bit_length_array,
            private_key_hamming_weight_array,
            private_key_leading_zeros_array,
            pubkey_compressed_array,
            pubkey_uncompressed_array,
            address_p2pkh_compressed_array,
            address_p2pkh_uncompressed_array,
            address_p2wpkh_array,
            wif_compressed_array,
            wif_uncompressed_array,
        ],
    )
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::storage::PrivateKeyRecord;
    use arrow::array::{Array, FixedSizeBinaryArray};
    use arrow::datatypes::DataType;

    #[test]
    fn schema_has_19_fields() {
        let schema = result_schema();
        assert_eq!(schema.fields().len(), 19);
    }

    #[test]
    fn schema_field_names() {
        let schema = result_schema();
        let names: Vec<&str> = schema.fields().iter().map(|f| f.name().as_str()).collect();

        assert_eq!(
            names,
            vec![
                "source",
                "transform",
                "chain",
                "timestamp",
                "matched_target",
                "private_key_raw",
                "private_key_hex",
                "private_key_decimal",
                "private_key_binary",
                "private_key_bit_length",
                "private_key_hamming_weight",
                "private_key_leading_zeros",
                "pubkey_compressed",
                "pubkey_uncompressed",
                "address_p2pkh_compressed",
                "address_p2pkh_uncompressed",
                "address_p2wpkh",
                "wif_compressed",
                "wif_uncompressed",
            ]
        );
    }

    #[test]
    fn schema_field_types() {
        let schema = result_schema();

        assert_eq!(schema.field(0).data_type(), &DataType::Utf8);
        assert_eq!(schema.field(1).data_type(), &DataType::Utf8);
        assert_eq!(schema.field(2).data_type(), &DataType::Utf8);
        assert!(matches!(
            schema.field(3).data_type(),
            DataType::Timestamp(TimeUnit::Millisecond, Some(_))
        ));
        assert_eq!(schema.field(4).data_type(), &DataType::Utf8);
        assert_eq!(schema.field(5).data_type(), &DataType::FixedSizeBinary(32));
        assert_eq!(schema.field(6).data_type(), &DataType::Utf8);
        assert_eq!(schema.field(7).data_type(), &DataType::Utf8);
        assert_eq!(schema.field(8).data_type(), &DataType::Utf8);
        assert_eq!(schema.field(9).data_type(), &DataType::UInt16);
        assert_eq!(schema.field(10).data_type(), &DataType::UInt16);
        assert_eq!(schema.field(11).data_type(), &DataType::UInt8);

        for i in 12..19 {
            assert_eq!(schema.field(i).data_type(), &DataType::Utf8);
        }
    }

    #[test]
    fn schema_nullable_flags() {
        let schema = result_schema();

        let non_nullable = [0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11];
        for i in non_nullable {
            assert!(
                !schema.field(i).is_nullable(),
                "field {} should be non-nullable",
                i
            );
        }

        let nullable = [4, 12, 13, 14, 15, 16, 17, 18];
        for i in nullable {
            assert!(
                schema.field(i).is_nullable(),
                "field {} should be nullable",
                i
            );
        }
    }

    #[test]
    fn records_to_batch_empty() {
        let batch = records_to_batch(&[]).unwrap();
        assert_eq!(batch.num_rows(), 0);
        assert_eq!(batch.num_columns(), 19);
        assert_eq!(batch.schema(), Arc::new(result_schema()));
    }

    fn make_test_record<'a>(
        raw: &'a [u8; 32],
        public_keys: &'a [PublicKeyRecord<'a>],
        addresses: &'a [AddressRecord<'a>],
        export_formats: &'a [ExportFormatRecord<'a>],
        matched_target: Option<&'a str>,
    ) -> ResultRecord<'a> {
        ResultRecord {
            source: "test_source",
            transform: "sha256",
            chain: "bitcoin",
            timestamp: chrono::DateTime::parse_from_rfc3339("2025-01-01T00:00:00Z")
                .unwrap()
                .with_timezone(&chrono::Utc),
            private_key: PrivateKeyRecord {
                raw,
                hex: "0101010101010101010101010101010101010101010101010101010101010101",
                decimal:
                    "454086624460063511464984254936031011189294057512315937409637584344757371137",
                binary: "0000000100000001000000010000000100000001000000010000000100000001\
                         0000000100000001000000010000000100000001000000010000000100000001\
                         0000000100000001000000010000000100000001000000010000000100000001\
                         0000000100000001000000010000000100000001000000010000000100000001",
                bit_length: 249,
                hamming_weight: 32,
                leading_zeros: 0,
            },
            public_keys,
            addresses,
            export_formats,
            matched_target,
        }
    }

    #[test]
    fn records_to_batch_single_record() {
        let raw = [1u8; 32];
        let public_keys = [
            PublicKeyRecord {
                format: "compressed",
                value: "02abc123",
            },
            PublicKeyRecord {
                format: "uncompressed",
                value: "04abc123def456",
            },
        ];
        let addresses = [
            AddressRecord {
                address_type: "p2pkh_compressed",
                address: "1ABC123",
            },
            AddressRecord {
                address_type: "p2pkh_uncompressed",
                address: "1DEF456",
            },
            AddressRecord {
                address_type: "p2wpkh",
                address: "bc1qtest",
            },
        ];
        let export_formats = [
            ExportFormatRecord {
                format: "wif_compressed",
                value: "L1234",
            },
            ExportFormatRecord {
                format: "wif_uncompressed",
                value: "5J1234",
            },
        ];

        let record = make_test_record(&raw, &public_keys, &addresses, &export_formats, None);
        let batch = records_to_batch(&[record]).unwrap();

        assert_eq!(batch.num_rows(), 1);
        assert_eq!(batch.num_columns(), 19);

        let source_col = batch
            .column(0)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(source_col.value(0), "test_source");

        let transform_col = batch
            .column(1)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(transform_col.value(0), "sha256");

        let chain_col = batch
            .column(2)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(chain_col.value(0), "bitcoin");

        let pk_raw_col = batch
            .column(5)
            .as_any()
            .downcast_ref::<FixedSizeBinaryArray>()
            .unwrap();
        assert_eq!(pk_raw_col.value(0), &[1u8; 32]);

        let pk_bit_length_col = batch
            .column(9)
            .as_any()
            .downcast_ref::<UInt16Array>()
            .unwrap();
        assert_eq!(pk_bit_length_col.value(0), 249);

        let pubkey_compressed_col = batch
            .column(12)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(pubkey_compressed_col.value(0), "02abc123");

        let addr_p2wpkh_col = batch
            .column(16)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(addr_p2wpkh_col.value(0), "bc1qtest");

        let wif_compressed_col = batch
            .column(17)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(wif_compressed_col.value(0), "L1234");
    }

    #[test]
    fn records_to_batch_with_matched_target() {
        let raw = [1u8; 32];
        let record = make_test_record(&raw, &[], &[], &[], Some("1MatchedAddress"));
        let batch = records_to_batch(&[record]).unwrap();

        let matched_col = batch
            .column(4)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert!(!matched_col.is_null(0));
        assert_eq!(matched_col.value(0), "1MatchedAddress");
    }

    #[test]
    fn records_to_batch_with_none_matched_target() {
        let raw = [1u8; 32];
        let record = make_test_record(&raw, &[], &[], &[], None);
        let batch = records_to_batch(&[record]).unwrap();

        let matched_col = batch
            .column(4)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert!(matched_col.is_null(0));
    }

    #[test]
    fn records_to_batch_empty_slices() {
        let raw = [0u8; 32];
        let record = make_test_record(&raw, &[], &[], &[], None);
        let batch = records_to_batch(&[record]).unwrap();

        let pubkey_compressed = batch
            .column(12)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert!(pubkey_compressed.is_null(0));

        let addr_p2pkh = batch
            .column(14)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert!(addr_p2pkh.is_null(0));

        let wif = batch
            .column(17)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert!(wif.is_null(0));
    }

    #[test]
    fn records_to_batch_multiple_records() {
        let raw1 = [1u8; 32];
        let raw2 = [2u8; 32];
        let raw3 = [3u8; 32];

        let record1 = make_test_record(&raw1, &[], &[], &[], None);
        let mut record2 = make_test_record(&raw2, &[], &[], &[], Some("matched"));
        record2.source = "source2";
        record2.transform = "milksad";
        let mut record3 = make_test_record(&raw3, &[], &[], &[], None);
        record3.source = "source3";
        record3.chain = "ethereum";

        let batch = records_to_batch(&[record1, record2, record3]).unwrap();

        assert_eq!(batch.num_rows(), 3);

        let source_col = batch
            .column(0)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(source_col.value(0), "test_source");
        assert_eq!(source_col.value(1), "source2");
        assert_eq!(source_col.value(2), "source3");

        let transform_col = batch
            .column(1)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(transform_col.value(0), "sha256");
        assert_eq!(transform_col.value(1), "milksad");
        assert_eq!(transform_col.value(2), "sha256");

        let chain_col = batch
            .column(2)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert_eq!(chain_col.value(0), "bitcoin");
        assert_eq!(chain_col.value(1), "bitcoin");
        assert_eq!(chain_col.value(2), "ethereum");

        let matched_col = batch
            .column(4)
            .as_any()
            .downcast_ref::<StringArray>()
            .unwrap();
        assert!(matched_col.is_null(0));
        assert!(!matched_col.is_null(1));
        assert_eq!(matched_col.value(1), "matched");
        assert!(matched_col.is_null(2));
    }

    #[test]
    fn find_pubkey_works() {
        let pubkeys = [
            PublicKeyRecord {
                format: "compressed",
                value: "02abc",
            },
            PublicKeyRecord {
                format: "uncompressed",
                value: "04def",
            },
        ];

        assert_eq!(find_pubkey(&pubkeys, "compressed"), Some("02abc"));
        assert_eq!(find_pubkey(&pubkeys, "uncompressed"), Some("04def"));
        assert_eq!(find_pubkey(&pubkeys, "ed25519"), None);
        assert_eq!(find_pubkey(&[], "compressed"), None);
    }

    #[test]
    fn find_address_works() {
        let addresses = [
            AddressRecord {
                address_type: "p2pkh_compressed",
                address: "1ABC",
            },
            AddressRecord {
                address_type: "p2wpkh",
                address: "bc1q",
            },
        ];

        assert_eq!(find_address(&addresses, "p2pkh_compressed"), Some("1ABC"));
        assert_eq!(find_address(&addresses, "p2wpkh"), Some("bc1q"));
        assert_eq!(find_address(&addresses, "p2sh"), None);
        assert_eq!(find_address(&[], "p2pkh"), None);
    }

    #[test]
    fn find_export_works() {
        let exports = [
            ExportFormatRecord {
                format: "wif_compressed",
                value: "L123",
            },
            ExportFormatRecord {
                format: "wif_uncompressed",
                value: "5J123",
            },
        ];

        assert_eq!(find_export(&exports, "wif_compressed"), Some("L123"));
        assert_eq!(find_export(&exports, "wif_uncompressed"), Some("5J123"));
        assert_eq!(find_export(&exports, "hex"), None);
        assert_eq!(find_export(&[], "wif_compressed"), None);
    }
}