Skip to content

Commit

Permalink
Merge pull request #3136 from Emurgo/yushi/hw-wallet-connector-1
Browse files Browse the repository at this point in the history
Ledger wallet connector support
  • Loading branch information
vsubhuman committed Mar 17, 2023
2 parents b59365d + f30519c commit 056e5ba
Show file tree
Hide file tree
Showing 17 changed files with 1,375 additions and 152 deletions.
16 changes: 15 additions & 1 deletion packages/yoroi-connector/example-cardano/index.js
Expand Up @@ -482,6 +482,17 @@ signTx.addEventListener("click", () => {
// add a keyhash input - for ADA held in a Shelley-era normal address (Base, Enterprise, Pointer)
const utxo = utxos[0];

const assets = CardanoWasm.MultiAsset.new();
for (const asset of utxo.assets) {
const policyId = CardanoWasm.ScriptHash.from_hex(asset.policyId);
const policyContent = assets.get(policyId) || CardanoWasm.Assets.new();
policyContent.insert(
CardanoWasm.AssetName.new(Buffer.from(asset.name, 'hex')),
CardanoWasm.BigNum.from_str(asset.amount)
);
assets.insert(policyId, policyContent);
}

const addr = CardanoWasm.Address.from_bech32(utxo.receiver);

const baseAddr = CardanoWasm.BaseAddress.from_address(addr);
Expand All @@ -492,7 +503,10 @@ signTx.addEventListener("click", () => {
CardanoWasm.TransactionHash.from_bytes(hexToBytes(utxo.tx_hash)), // tx hash
utxo.tx_index // index
),
CardanoWasm.Value.new(CardanoWasm.BigNum.from_str(utxo.amount))
CardanoWasm.Value.new_with_assets(
CardanoWasm.BigNum.from_str(utxo.amount),
assets
)
);

const shelleyOutputAddress =
Expand Down
Expand Up @@ -166,6 +166,86 @@ export async function getAllAddressesForDisplay(
);
}

type AddressWithDerivationPath = {|
+address: string,
+path: Array<number>,
|};

export async function getAllAddressesWithPaths(
publicDeriver: IPublicDeriver<ConceptualWallet>,
): Promise<{|
utxoAddresses: Array<$ReadOnly<AddressWithDerivationPath>>,
accountingAddresses: Array<$ReadOnly<AddressWithDerivationPath>>,
|}> {
const withLevels = asHasLevels<ConceptualWallet>(publicDeriver);
if (!withLevels) {
throw new Error(`${nameof(getAllAddressesWithPaths)} publicDerviver traits missing`);
}
const derivationTables = withLevels.getParent().getDerivationTables();
const deps = Object.freeze({
GetPathWithSpecific,
GetAddress,
GetDerivationSpecific,
});
const depTables = Object.keys(deps)
.map(key => deps[key])
.flatMap(table => getAllSchemaTables(publicDeriver.getDb(), table));

return await raii(
publicDeriver.getDb(),
[
...depTables,
...mapToTables(publicDeriver.getDb(), derivationTables),
],
async dbTx => {
const utxoAddresses = [];
const accountingAddresses = [];
const withUtxos = asGetAllUtxos(publicDeriver);
if (withUtxos != null) {
const addrResponse = await withUtxos.rawGetAllUtxoAddresses(
dbTx,
{
GetPathWithSpecific: deps.GetPathWithSpecific,
GetAddress: deps.GetAddress,
GetDerivationSpecific: deps.GetDerivationSpecific,
},
undefined,
derivationTables,
);
for (const family of addrResponse) {
for (const addr of family.addrs) {
utxoAddresses.push({ address: addr.Hash, path: family.addressing.path });
}
}
}
const withAccounting = asGetAllAccounting(publicDeriver);
if (withAccounting != null) {
const addrResponse = await withAccounting.rawGetAllAccountingAddresses(
dbTx,
{
GetPathWithSpecific: deps.GetPathWithSpecific,
GetAddress: deps.GetAddress,
GetDerivationSpecific: deps.GetDerivationSpecific,
},
undefined,
derivationTables,
);
for (const family of addrResponse) {
for (const addr of family.addrs) {
accountingAddresses.push({ address: addr.Hash, path: family.addressing.path });
}
}
}

return {
utxoAddresses,
accountingAddresses,
};

},
);
}

export async function rawGetAddressRowsForWallet(
tx: lf$Transaction,
deps: {|
Expand Down

0 comments on commit 056e5ba

Please sign in to comment.