Skip to content
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ User-visible changes to `voltage`, newest first. Each pull request that changes

## Unreleased

- Reject malformed wallet pagination and Solana mints with an invalid decoded size.

- Refresh the public API contract, expose `wallets summary`, and follow wallet cursor pages for pickers and `--all-orgs --all`. Wallet listings gain cursor/filter flags; wallet policy updates no longer accept the admin-only OFAC field.

- Receive USDC/USDT with an explicit USD-to-deployment quote, display token amounts using deployment decimals, and show the address with `--qr` or `--copy`. Stablecoin receives require organization enablement; QR/copy requires a valid deployment in the response.
Expand Down
16 changes: 12 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,14 @@ pub async fn organization_wallets(
wallet_pages(&api, request, invocation.all, global.timeout).await
}

fn validate_wallet_page(body: &Value) -> Result<()> {
if body.is_object() {
PageView::deserialize(body)
.map_err(|_| Error::transport("Invalid wallet pagination metadata"))?;
}
Ok(())
}

/// Read wallet pages with one deadline, retaining filters as the cursor advances.
async fn wallet_pages(
api: &Api,
Expand All @@ -763,10 +771,7 @@ async fn wallet_pages(
Error::timeout("Wallet pagination deadline exceeded; use a longer --timeout")
})??
.body;
if body.is_object() {
PageView::deserialize(&body)
.map_err(|_| Error::transport("Invalid wallet pagination metadata"))?;
}
validate_wallet_page(&body)?;
let next = if follow {
next_page(&body, &request)?
} else {
Expand Down Expand Up @@ -1831,6 +1836,9 @@ impl Call<'_> {
let mut pages = Vec::new();
let mut cursors = BTreeSet::new();
loop {
if self.invocation.operation.id == OperationId::GetAllOrganizationsWalletsAsUser {
validate_wallet_page(&response.body)?;
}
let next = if follow {
next_page(&response.body, &self.request)?
} else {
Expand Down
51 changes: 47 additions & 4 deletions src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,7 @@ pub fn stablecoin_deployment(value: &str) -> Option<(&str, usize)> {
&& hex.bytes().any(|b| b != b'0')
})
} else {
(32..=44).contains(&contract.len())
&& contract
.bytes()
.all(|b| b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".contains(&b))
solana_mint(contract).is_some()
};
let decimal_text = *decimals;
let decimals: usize = decimals.parse().ok()?;
Expand All @@ -210,6 +207,33 @@ pub fn stablecoin_deployment(value: &str) -> Option<(&str, usize)> {
(valid_contract && decimals <= 9).then_some((*asset, decimals))
}

/// Decode a bounded Base58 mint into exactly 32 bytes, including leading zeroes.
fn solana_mint(text: &str) -> Option<[u8; 32]> {
if !(32..=44).contains(&text.len()) {
return None;
}
let mut decoded = [0u8; 32];
for byte in text.bytes() {
let mut carry = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
.iter()
.position(|&digit| digit == byte)? as u16;
for digit in decoded.iter_mut().rev() {
carry += u16::from(*digit) * 58;
*digit = carry as u8;
carry >>= 8;
}
if carry != 0 {
return None;
}
}
let leading = text.bytes().take_while(|&byte| byte == b'1').count();
let significant = decoded
.iter()
.position(|&byte| byte != 0)
.map_or(0, |i| 32 - i);
(leading + significant == 32).then_some(decoded)
}

/// Wallet networks the convenience flags can name.
#[derive(Clone, Copy, Debug, Serialize, Eq, PartialEq, ValueEnum)]
#[serde(rename_all = "lowercase")]
Expand Down Expand Up @@ -446,6 +470,25 @@ mod tests {
}
}

#[test]
fn solana_mints_require_exactly_32_decoded_bytes() {
for mint in [
"1".repeat(31),
"1".repeat(33),
"1".repeat(45),
"0".repeat(32),
"2".repeat(32),
"z".repeat(44),
] {
assert_eq!(solana_mint(&mint), None);
assert_eq!(
stablecoin_deployment(&format!("usdc:solana_devnet:{mint}:6")),
None
);
}
assert_eq!(solana_mint(&"1".repeat(32)), Some([0; 32]));
}

#[test]
fn stablecoin_ignores_other_payment_kinds_request_fields() {
let view = PaymentView::from_body(&json!({"type":"stablecoin", "status":"receiving",
Expand Down
23 changes: 23 additions & 0 deletions tests/cli_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8702,3 +8702,26 @@ async fn wallet_page_failures_do_not_produce_a_shortlist() {
assert!(!stdout(&result).contains("shortlist"));
}
}

#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn wallet_list_all_rejects_a_malformed_later_cursor() {
let (server, dir) = fixture().await;
respond_once(
&server,
route("GET", wallets_path(ORG)).and(query_param_is_missing("cursor")),
ok(json!({"items":[],"has_more":true,"next_cursor":"second"})),
)
.await;
respond_once(
&server,
route("GET", wallets_path(ORG)).and(query_param("cursor", "second")),
ok(json!({"items":[],"has_more":true,"next_cursor":12})),
)
.await;
let result = cli(dir.path(), &server)
.args(["wallets", "list", "--org", ORG, "--env", ENV, "--all"])
.assert()
.failure();
assert!(stderr(&result).contains("Invalid wallet pagination metadata"));
assert!(!stdout(&result).contains("pages"));
}
Loading