Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qi Wallet v2 #329

Merged
merged 23 commits into from
Oct 23, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
96fdb0f
add new types
alejoacosta74 Oct 21, 2024
a4dd595
unify data structures into single map
alejoacosta74 Oct 21, 2024
6a3d082
refactor address getter methods
alejoacosta74 Oct 21, 2024
4874610
update sendTx to use new data structure
alejoacosta74 Oct 21, 2024
910822d
update scanning & syncing logic
alejoacosta74 Oct 21, 2024
2283247
update addresses get methods
alejoacosta74 Oct 21, 2024
d859152
update serialization logic
alejoacosta74 Oct 21, 2024
9b49c33
update paymentcode logic
alejoacosta74 Oct 21, 2024
e9f5413
fix bug in getNext payment code address
alejoacosta74 Oct 21, 2024
e1119fa
remove helper methods
alejoacosta74 Oct 21, 2024
37e3259
Fixes to new qi syncing logic
rileystephens28 Oct 22, 2024
1bc903a
Temporarily add legacy qi wallet for comparison
rileystephens28 Oct 22, 2024
55b75ab
bug fix in _findLastUsedIndex
alejoacosta74 Oct 22, 2024
23fd54c
QiHDWalletLegacy: bug fix on paymentcode addr generation
alejoacosta74 Oct 22, 2024
8d34625
update serialization/deserialization properties
alejoacosta74 Oct 22, 2024
1b0630a
add script to compare new vs legacy QiHDWallet address generation
alejoacosta74 Oct 22, 2024
526ddf7
update QiAddressInfo with derivationPath property
alejoacosta74 Oct 22, 2024
f7ebfe1
remove duplicated updates to address map
alejoacosta74 Oct 22, 2024
9d9d4bd
Fix `getAddressesForZone` method name
rileystephens28 Oct 22, 2024
dbf709d
Support min denomination when selecting for conversion txs
rileystephens28 Oct 22, 2024
ae49b30
fix bug in getChangeAddresses function
alejoacosta74 Oct 23, 2024
361ce46
Fix serializing all derivation paths
rileystephens28 Oct 23, 2024
3e27a77
Remove legacy Qi HD Wallet export
rileystephens28 Oct 23, 2024
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
Prev Previous commit
Next Next commit
unify data structures into single map
alejoacosta74 authored and rileystephens28 committed Oct 22, 2024

Verified

This commit was signed with the committer’s verified signature.
rileystephens28 Riley Stephens
commit a4dd5954fab51449f5d01f4b5566e419e4f4252b
74 changes: 20 additions & 54 deletions src/wallet/qi-hdwallet.ts
Original file line number Diff line number Diff line change
@@ -55,15 +55,13 @@ enum AddressStatus {
*
* @type {string}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
type DerivationPath = 'BIP44:external' | 'BIP44:change' | string; // string for payment codes

/**
* Interface representing an address in the Qi HD wallet.
*
* @extends NeuteredAddressInfo
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface QiAddressInfo extends NeuteredAddressInfo {
status: AddressStatus;
counterpartyPaymentCode?: string;
@@ -161,46 +159,18 @@ export class QiHDWallet extends AbstractHDWallet {
protected static _coinType: AllowedCoinType = 969;

/**
* Map of change addresses to address info.
* A map containing address information for all addresses known to the wallet. This includes:
*
* @ignore
* @type {Map<string, NeuteredAddressInfo>}
*/
protected _changeAddresses: Map<string, NeuteredAddressInfo> = new Map();

/**
* Array of gap addresses.
* - BIP44 derived addresses (external)
* - BIP44 derived change addresses
* - BIP47 payment code derived addresses for receiving funds
*
* @ignore
* @type {NeuteredAddressInfo[]}
*/
protected _gapChangeAddresses: NeuteredAddressInfo[] = [];

/**
* Array of gap change addresses.
* The key is the derivation path or payment code, and the value is an array of QiAddressInfo objects.
*
* @ignore
* @type {NeuteredAddressInfo[]}
*/
protected _gapAddresses: NeuteredAddressInfo[] = [];

/**
* This array is used to keep track of gap addresses that have been included in a transaction, but whose outpoints
* have not been imported into the wallet.
*
* @ignore
* @type {NeuteredAddressInfo[]}
*/
protected _usedGapAddresses: NeuteredAddressInfo[] = [];

/**
* This array is used to keep track of gap change addresses that have been included in a transaction, but whose
* outpoints have not been imported into the wallet.
*
* @ignore
* @type {NeuteredAddressInfo[]}
* @private
* @type {Map<DerivationPath, QiAddressInfo[]>}
*/
protected _usedGapChangeAddresses: NeuteredAddressInfo[] = [];
private _addressesMap: Map<DerivationPath, QiAddressInfo[]> = new Map();

/**
* Array of outpoint information.
@@ -222,14 +192,17 @@ export class QiHDWallet extends AbstractHDWallet {
protected _addressUseChecker: AddressUsageCallback | undefined;

/**
* Map of paymentcodes to PaymentChannelAddressInfo for the receiver
*/
private _receiverPaymentCodeInfo: Map<string, PaymentChannelAddressInfo[]> = new Map();

/**
* Map of paymentcodes to PaymentChannelAddressInfo for the sender
* A map containing address information for sending funds to counterparties using BIP47 payment codes.
*
* @remarks
* The key is the receiver's payment code, and the value is an array of QiAddressInfo objects. These addresses are
* derived from the receiver's payment code and are used only for sending funds. They are not part of the set of
* addresses that this wallet can control or spend from. This map is used to keep track of addresses generated for
* each payment channel to ensure proper address rotation and avoid address reuse when sending funds.
* @private
* @type {Map<string, QiAddressInfo[]>}
*/
private _senderPaymentCodeInfo: Map<string, PaymentChannelAddressInfo[]> = new Map();
private _paymentCodeSendAddressMap: Map<string, QiAddressInfo[]> = new Map();

/**
* @ignore
@@ -238,6 +211,8 @@ export class QiHDWallet extends AbstractHDWallet {
*/
constructor(guard: any, root: HDNodeWallet, provider?: Provider) {
super(guard, root, provider);
this._addressesMap.set('BIP44:external', []);
this._addressesMap.set('BIP44:change', []);
}

/**
@@ -251,15 +226,6 @@ export class QiHDWallet extends AbstractHDWallet {
this._addressUseChecker = checker;
}

// getters for the payment code info maps
public get receiverPaymentCodeInfo(): { [key: string]: PaymentChannelAddressInfo[] } {
return Object.fromEntries(this._receiverPaymentCodeInfo);
}

public get senderPaymentCodeInfo(): { [key: string]: PaymentChannelAddressInfo[] } {
return Object.fromEntries(this._senderPaymentCodeInfo);
}

/**
* Promise that resolves to the next change address for the specified account and zone.
*