Skip to content

Commit 33e2cc5

Browse files
committed
fixup! eth: add signing function parameter to specify receive address case
1 parent 45f1bb6 commit 33e2cc5

File tree

5 files changed

+54
-14
lines changed

5 files changed

+54
-14
lines changed

CHANGELOG-npm.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## 0.7.0
66
- btc: handle error when an input's previous transaction is required but missing
7+
- eth: add method to help clients identify address case (upper/lower/mixed)
78

89
## 0.6.0
910

CHANGELOG-rust.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## 0.6.0
66
- btc: handle error when an input's previous transaction is required but missing
77
- cardano: added support for vote delegation
8+
- eth: add method to help clients identify address case (upper/lower/mixed)
89

910
## 0.5.0
1011

src/eth.rs

+32-3
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,29 @@ pub struct EIP1559Transaction {
123123
}
124124

125125
/// Identifies the case of the recipient address given as hexadecimal string.
126-
/// This function exists as a convenience to potentially help clients to determine the case of the
126+
/// This function exists as a convenience to help clients to determine the case of the
127127
/// recipient address.
128128
pub fn eth_identify_case(recipient_address: &str) -> pb::EthAddressCase {
129-
if recipient_address.to_uppercase() == recipient_address {
129+
if recipient_address
130+
.chars()
131+
.all(|c| !c.is_ascii_alphabetic() || c.is_ascii_uppercase())
132+
{
130133
pb::EthAddressCase::Upper
131-
} else if recipient_address.to_lowercase() == recipient_address {
134+
} else if recipient_address
135+
.chars()
136+
.all(|c| !c.is_ascii_alphabetic() || c.is_ascii_lowercase())
137+
{
132138
pb::EthAddressCase::Lower
133139
} else {
134140
pb::EthAddressCase::Mixed
135141
}
142+
// if recipient_address.to_uppercase() == recipient_address {
143+
// pb::EthAddressCase::Upper
144+
// } else if recipient_address.to_lowercase() == recipient_address {
145+
// pb::EthAddressCase::Lower
146+
// } else {
147+
// pb::EthAddressCase::Mixed
148+
// }
136149
}
137150

138151
#[cfg(feature = "rlp")]
@@ -1267,4 +1280,20 @@ mod tests {
12671280
)
12681281
.is_err());
12691282
}
1283+
1284+
#[test]
1285+
fn test_eth_identify_case() {
1286+
assert_eq!(
1287+
eth_identify_case("0XF39FD6E51AAD88F6F4CE6AB8827279CFFFB92266"),
1288+
pb::EthAddressCase::Upper
1289+
);
1290+
assert_eq!(
1291+
eth_identify_case("0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266"),
1292+
pb::EthAddressCase::Lower
1293+
);
1294+
assert_eq!(
1295+
eth_identify_case("0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"),
1296+
pb::EthAddressCase::Mixed
1297+
);
1298+
}
12701299
}

src/wasm/mod.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,12 @@ impl PairedBitBox {
419419
) -> Result<types::TsEthSignature, JavascriptError> {
420420
let signature = self
421421
.device
422-
.eth_sign_transaction(chain_id, &keypath.try_into()?, &tx.try_into()?, address_case.map(TryInto::try_into).transpose()?)
422+
.eth_sign_transaction(
423+
chain_id,
424+
&keypath.try_into()?,
425+
&tx.try_into()?,
426+
address_case.map(TryInto::try_into).transpose()?,
427+
)
423428
.await?;
424429

425430
let v: u64 = compute_v(chain_id, signature[64])
@@ -443,7 +448,11 @@ impl PairedBitBox {
443448
) -> Result<types::TsEthSignature, JavascriptError> {
444449
let signature = self
445450
.device
446-
.eth_sign_1559_transaction(&keypath.try_into()?, &tx.try_into()?, address_case.map(TryInto::try_into).transpose()?)
451+
.eth_sign_1559_transaction(
452+
&keypath.try_into()?,
453+
&tx.try_into()?,
454+
address_case.map(TryInto::try_into).transpose()?,
455+
)
447456
.await?;
448457

449458
Ok(serde_wasm_bindgen::to_value(&types::EthSignature {

src/wasm/types.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ type EthSignature = {
7575
s: Uint8Array;
7676
v: Uint8Array;
7777
};
78-
type EthAddressCase = 'Upper' | 'Lower' | 'Mixed';
78+
type EthAddressCase = 'upper' | 'lower' | 'mixed';
7979
type CardanoXpub = Uint8Array;
8080
type CardanoXpubs = CardanoXpub[];
8181
type CardanoNetwork = 'mainnet' | 'testnet';
@@ -287,17 +287,17 @@ impl TryFrom<TsEth1559Transaction> for crate::eth::EIP1559Transaction {
287287
}
288288

289289
impl TryFrom<TsEthAddressCase> for crate::pb::EthAddressCase {
290-
type Error = JavascriptError;
291-
fn try_from(value: TsEthAddressCase) -> Result<Self, Self::Error> {
292-
serde_wasm_bindgen::from_value(value.into())
293-
.map_err(|_| JavascriptError::InvalidType("wrong type for EthAddressCase"))
294-
}
290+
type Error = JavascriptError;
291+
fn try_from(value: TsEthAddressCase) -> Result<Self, Self::Error> {
292+
serde_wasm_bindgen::from_value(value.into())
293+
.map_err(|_| JavascriptError::InvalidType("wrong type for EthAddressCase"))
294+
}
295295
}
296296

297297
impl From<crate::pb::EthAddressCase> for TsEthAddressCase {
298-
fn from(case: crate::pb::EthAddressCase) -> Self {
299-
serde_wasm_bindgen::to_value(&case).unwrap().into()
300-
}
298+
fn from(case: crate::pb::EthAddressCase) -> Self {
299+
serde_wasm_bindgen::to_value(&case).unwrap().into()
300+
}
301301
}
302302

303303
impl TryFrom<TsCardanoNetwork> for crate::pb::CardanoNetwork {

0 commit comments

Comments
 (0)