stellar-strkey 0.0.18

Encode and decode strkeys for Stellar.
Documentation
use stellar_strkey::*;

#[test]
fn test_strkey_ed25519_public_key_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::PublicKeyEd25519(ed25519::PublicKey([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "PublicKeyEd25519(PublicKey(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_contract_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::Contract(Contract([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "Contract(Contract(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_hash_x_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::HashX(HashX([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "HashX(HashX(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_pre_auth_tx_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::PreAuthTx(PreAuthTx([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "PreAuthTx(PreAuthTx(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_ed25519_muxed_account_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::MuxedAccountEd25519(ed25519::MuxedAccount {
                ed25519: [
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                ],
                id: 0,
            })
        ),
        "MuxedAccountEd25519(MuxedAccount(0000000000000000000000000000000000000000000000000000000000000000, 0))",
    );
}

#[test]
fn test_strkey_ed25519_signed_payload_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::SignedPayloadEd25519(
                ed25519::SignedPayload::new(
                    [
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                        0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    ],
                    &[1u8, 2, 3, 4],
                )
                .unwrap()
            )
        ),
        "SignedPayloadEd25519(SignedPayload(0000000000000000000000000000000000000000000000000000000000000000, 01020304))",
    );
}

#[test]
fn test_strkey_liquidity_pool_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::LiquidityPool(LiquidityPool([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "LiquidityPool(LiquidityPool(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

#[test]
fn test_strkey_claimable_balance_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Strkey::ClaimableBalance(ClaimableBalance::V0([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ]))
        ),
        "ClaimableBalance(ClaimableBalance(V0(0000000000000000000000000000000000000000000000000000000000000000)))",
    );
}

// Inner type debug tests

#[test]
fn test_ed25519_public_key_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::PublicKey([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "PublicKey(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_ed25519_private_key_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::PrivateKey([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "PrivateKey([REDACTED])",
    );
}

#[test]
fn test_pre_auth_tx_debug() {
    assert_eq!(
        format!(
            "{:?}",
            PreAuthTx([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "PreAuthTx(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_hash_x_debug() {
    assert_eq!(
        format!(
            "{:?}",
            HashX([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "HashX(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_ed25519_muxed_account_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::MuxedAccount {
                ed25519: [
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                ],
                id: 0,
            }
        ),
        "MuxedAccount(0000000000000000000000000000000000000000000000000000000000000000, 0)",
    );
}

#[test]
fn test_ed25519_signed_payload_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ed25519::SignedPayload::new(
                [
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                ],
                &[1u8, 2, 3, 4],
            )
            .unwrap()
        ),
        "SignedPayload(0000000000000000000000000000000000000000000000000000000000000000, 01020304)",
    );
}

#[test]
fn test_contract_debug() {
    assert_eq!(
        format!(
            "{:?}",
            Contract([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "Contract(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_liquidity_pool_debug() {
    assert_eq!(
        format!(
            "{:?}",
            LiquidityPool([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "LiquidityPool(0000000000000000000000000000000000000000000000000000000000000000)",
    );
}

#[test]
fn test_claimable_balance_debug() {
    assert_eq!(
        format!(
            "{:?}",
            ClaimableBalance::V0([
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00,
            ])
        ),
        "ClaimableBalance(V0(0000000000000000000000000000000000000000000000000000000000000000))",
    );
}

// Debug via Unredacted wrapper for PrivateKey.

#[test]
fn test_ed25519_private_key_debug_unredacted() {
    let key = ed25519::PrivateKey([
        0x69, 0xa8, 0xc4, 0xcb, 0xb9, 0xf6, 0x4e, 0x8a, 0x07, 0x98, 0xf6, 0xe1, 0xac, 0x65, 0xd0,
        0x6c, 0x31, 0x62, 0x92, 0x90, 0x56, 0xbc, 0xf4, 0xcd, 0xb7, 0xd3, 0x73, 0x8d, 0x18, 0x55,
        0xf3, 0x63,
    ]);
    assert_eq!(
        format!("{:?}", key.as_unredacted()),
        "PrivateKey(69a8c4cbb9f64e8a0798f6e1ac65d06c3162929056bcf4cdb7d3738d1855f363)",
    );
}