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

Improve public key fetching for closed/terminated wallets #813

Merged
merged 2 commits into from
Apr 22, 2024
Merged
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
4 changes: 2 additions & 2 deletions typescript/api-reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ Represents an event emitted when new wallet is registered on the on-chain bridge

#### Defined in

[src/lib/contracts/bridge.ts:455](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L455)
[src/lib/contracts/bridge.ts:457](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L457)

___

Expand Down Expand Up @@ -1024,7 +1024,7 @@ Packed parameters.

#### Defined in

[src/lib/ethereum/bridge.ts:688](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L688)
[src/lib/ethereum/bridge.ts:699](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L699)

___

Expand Down
16 changes: 8 additions & 8 deletions typescript/api-reference/classes/EthereumBridge.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ Builds the UTXO hash based on the UTXO components. UTXO hash is computed as

#### Defined in

[src/lib/ethereum/bridge.ts:618](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L618)
[src/lib/ethereum/bridge.ts:629](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L629)

___

Expand Down Expand Up @@ -334,7 +334,7 @@ Bridge.getNewWalletRegisteredEvents

#### Defined in

[src/lib/ethereum/bridge.ts:530](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L530)
[src/lib/ethereum/bridge.ts:541](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L541)

___

Expand All @@ -361,13 +361,13 @@ Bridge.getRedemptionRequestedEvents

#### Defined in

[src/lib/ethereum/bridge.ts:635](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L635)
[src/lib/ethereum/bridge.ts:646](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L646)

___

### getWalletCompressedPublicKey

▸ **getWalletCompressedPublicKey**(`ecdsaWalletID`): `Promise`\<[`Hex`](Hex.md)\>
▸ **getWalletCompressedPublicKey**(`ecdsaWalletID`): `Promise`\<`undefined` \| [`Hex`](Hex.md)\>

#### Parameters

Expand All @@ -377,7 +377,7 @@ ___

#### Returns

`Promise`\<[`Hex`](Hex.md)\>
`Promise`\<`undefined` \| [`Hex`](Hex.md)\>

#### Defined in

Expand Down Expand Up @@ -454,7 +454,7 @@ Parsed wallet data.

#### Defined in

[src/lib/ethereum/bridge.ts:589](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L589)
[src/lib/ethereum/bridge.ts:600](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L600)

___

Expand Down Expand Up @@ -664,7 +664,7 @@ ___

#### Defined in

[src/lib/ethereum/bridge.ts:555](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L555)
[src/lib/ethereum/bridge.ts:566](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L566)

___

Expand All @@ -690,7 +690,7 @@ ___

#### Defined in

[src/lib/ethereum/bridge.ts:572](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L572)
[src/lib/ethereum/bridge.ts:583](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/ethereum/bridge.ts#L583)

___

Expand Down
24 changes: 13 additions & 11 deletions typescript/api-reference/interfaces/Wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ UNIX timestamp indicating the moment the wallet's closing period started.

#### Defined in

[src/lib/contracts/bridge.ts:437](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L437)
[src/lib/contracts/bridge.ts:439](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L439)

___

Expand All @@ -39,7 +39,7 @@ UNIX timestamp the wallet was created at.

#### Defined in

[src/lib/contracts/bridge.ts:428](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L428)
[src/lib/contracts/bridge.ts:430](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L430)

___

Expand All @@ -63,7 +63,7 @@ Latest wallet's main UTXO hash.

#### Defined in

[src/lib/contracts/bridge.ts:420](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L420)
[src/lib/contracts/bridge.ts:422](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L422)

___

Expand All @@ -76,7 +76,7 @@ funds.

#### Defined in

[src/lib/contracts/bridge.ts:433](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L433)
[src/lib/contracts/bridge.ts:435](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L435)

___

Expand All @@ -88,7 +88,7 @@ Moving funds target wallet commitment submitted by the wallet.

#### Defined in

[src/lib/contracts/bridge.ts:449](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L449)
[src/lib/contracts/bridge.ts:451](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L451)

___

Expand All @@ -100,7 +100,7 @@ Total count of pending moved funds sweep requests targeting this wallet.

#### Defined in

[src/lib/contracts/bridge.ts:441](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L441)
[src/lib/contracts/bridge.ts:443](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L443)

___

Expand All @@ -112,7 +112,7 @@ The total redeemable value of pending redemption requests targeting that wallet.

#### Defined in

[src/lib/contracts/bridge.ts:424](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L424)
[src/lib/contracts/bridge.ts:426](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L426)

___

Expand All @@ -124,16 +124,18 @@ Current state of the wallet.

#### Defined in

[src/lib/contracts/bridge.ts:445](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L445)
[src/lib/contracts/bridge.ts:447](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L447)

___

### walletPublicKey

• **walletPublicKey**: [`Hex`](../classes/Hex.md)
`Optional` **walletPublicKey**: [`Hex`](../classes/Hex.md)

Compressed public key of the ECDSA Wallet.
Compressed public key of the ECDSA Wallet. If the wallet is Closed
or Terminated, this field is empty as the public key is removed from the
WalletRegistry.

#### Defined in

[src/lib/contracts/bridge.ts:416](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L416)
[src/lib/contracts/bridge.ts:418](https://github.com/keep-network/tbtc-v2/blob/main/typescript/src/lib/contracts/bridge.ts#L418)
6 changes: 4 additions & 2 deletions typescript/src/lib/contracts/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,11 @@ export interface Wallet {
*/
ecdsaWalletID: Hex
/**
* Compressed public key of the ECDSA Wallet.
* Compressed public key of the ECDSA Wallet. If the wallet is Closed
* or Terminated, this field is empty as the public key is removed from the
* WalletRegistry.
*/
walletPublicKey: Hex
walletPublicKey?: Hex
/**
* Latest wallet's main UTXO hash.
*/
Expand Down
25 changes: 18 additions & 7 deletions typescript/src/lib/ethereum/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,26 @@ export class EthereumBridge
return walletPublicKey
}

private async getWalletCompressedPublicKey(ecdsaWalletID: Hex): Promise<Hex> {
private async getWalletCompressedPublicKey(
ecdsaWalletID: Hex
): Promise<Hex | undefined> {
const walletRegistry = await this.walletRegistry()
const uncompressedPublicKey = await walletRegistry.getWalletPublicKey(
ecdsaWalletID
)

return Hex.from(
BitcoinPublicKeyUtils.compressPublicKey(uncompressedPublicKey)
)
try {
const uncompressedPublicKey = await walletRegistry.getWalletPublicKey(
ecdsaWalletID
)

return Hex.from(
BitcoinPublicKeyUtils.compressPublicKey(uncompressedPublicKey)
)
} catch (error) {
console.log(
`cannot get wallet public key for ${ecdsaWalletID}; error: ${error}`
)

return undefined
}
}

// eslint-disable-next-line valid-jsdoc
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/services/redemptions/redemptions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export class RedemptionsService {
await this.tbtcContracts.bridge.wallets(walletPublicKeyHash)

// Wallet must be in Live state.
if (state !== WalletState.Live) {
if (state !== WalletState.Live || !walletPublicKey) {
console.debug(
`Wallet is not in Live state ` +
`(wallet public key hash: ${walletPublicKeyHash.toString()}). ` +
Expand Down
Loading