Skip to content

Commit

Permalink
Testnet address generation to wallet-wasm.
Browse files Browse the repository at this point in the history
The motivation to change this part of the deprecated `wallet-wasm`
library was the simple introduction of testnet address support in
yoroi-mobile. The alternative is to migrate all of yoroi-mobile away to
use the new `cardano-wallet` module, but this would be significant work
in comparasin and can be delayed. Directly adapating
`react-native-cardano` to use `cardano-wallet` was not feasable either
as the API is quite different and would be exceptionally awkward to try
and force into the `react-native-cardano` API that was built on top of
`wallet-wasm` with its API in mind.

Only `xwallet_account()` was changed, as the other function lacking
support for testnet, `wallet_public_to_address()` does not seem to be used
anywhere in react-native-cardano, which was the motivation for this change.
Changing `wallet_public_to_address()` would also be more difficult as it
requires a hard API change or an additional function to allow
overloading.

On the other hand, `xwallet_account()` supports a JSON API,
which conveniently allows us to be backwards compatable, as the absence
of the `protocol_magic` field will revert to the previous behavior of
default (mainnet) protocol magic.
  • Loading branch information
rooooooooob committed Aug 7, 2019
1 parent e82c851 commit 13a3f49
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion wallet-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,8 @@ struct GenAddressesInput {
account: Bip44Account,
address_type: bip44::AddrType,
indices: Vec<u32>,
// For backwards compatability, absence of this field means mainnet
protocol_magic: Option<cardano::config::ProtocolMagic>,
}

#[no_mangle]
Expand All @@ -1072,14 +1074,18 @@ pub extern "C" fn xwallet_addresses(
output_ptr,
account.change(input.account.derivation_scheme, input.address_type)
);
let network_magic = match input.protocol_magic {
Some(pm) => cardano::config::NetworkMagic::from(pm),
None => default_network_magic(),
};

let mut addresses: Vec<address::ExtendedAddr> = Vec::with_capacity(input.indices.len());
for index in input.indices.into_iter() {
let xpub = jrpc_try!(
output_ptr,
changelevel.index(input.account.derivation_scheme, index)
);
let addr = address::ExtendedAddr::new_simple(*xpub, default_network_magic());
let addr = address::ExtendedAddr::new_simple(*xpub, network_magic);
addresses.push(addr);
}
jrpc_ok!(output_ptr, addresses)
Expand Down

0 comments on commit 13a3f49

Please sign in to comment.