-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ibc: transparent address support (#1950)
* add t-addr support to view service * backwards compatibility with existing frontends * changeset * fix inbound / outbound ibc transfers * linting * remove deprecated useCompatAddress field * fix wasm test * use ephemeral address format for ibc-in * bech32 shared helper * comment: bech32, rather thana bech32m * timeout msg * remove compat address format from bech32 and types package * use t-addr field in ics20 withdrawal component * update changeset * add compat and t-addr bech32 encoding * preprocessing the transaction view * linting * appease linter * linting rule
- Loading branch information
Showing
23 changed files
with
300 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
'@penumbra-zone/protobuf': major | ||
'@penumbra-zone/services': minor | ||
'@penumbra-zone/bech32m': minor | ||
'minifront': minor | ||
'@penumbra-zone/types': minor | ||
'@penumbra-zone/wasm': minor | ||
--- | ||
|
||
support transparent addresses for usdc noble IBC withdrawals |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe } from 'vitest'; | ||
import { generateTests } from './util/generate-tests.js'; | ||
import { bech32TransparentAddress, transparentAddressFromBech32 } from '../tpenumbra.js'; | ||
import { Prefixes } from '../format/prefix.js'; | ||
import { Inner } from '../format/inner.js'; | ||
|
||
describe('transparent address conversion', () => { | ||
const okInner = new Uint8Array([ | ||
102, 236, 169, 166, 203, 152, 194, 89, 236, 246, 59, 69, 221, 32, 49, 49, 83, 29, 119, 117, 124, | ||
201, 194, 156, 219, 251, 137, 202, 157, 235, 1, 15, | ||
]); | ||
const okBech32 = 'tpenumbra1vmk2nfktnrp9nm8k8dza6gp3x9f36am40nyu98xmlwyu480tqy8sr3jfzd'; | ||
|
||
generateTests( | ||
Prefixes.tpenumbra, | ||
Inner.tpenumbra, | ||
okInner, | ||
okBech32, | ||
bech32TransparentAddress, | ||
transparentAddressFromBech32, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { fromBech32, toBech32 } from './format/convert.js'; | ||
import { Inner } from './format/inner.js'; | ||
import { Prefixes } from './format/prefix.js'; | ||
|
||
const innerName = Inner.tpenumbra; | ||
const prefix = Prefixes.tpenumbra; | ||
|
||
export const bech32TransparentAddress = ({ [innerName]: bytes }: { [innerName]: Uint8Array }) => | ||
toBech32(bytes, prefix); | ||
|
||
export const transparentAddressFromBech32 = (penumbra1: string): { [innerName]: Uint8Array } => ({ | ||
[innerName]: fromBech32(penumbra1 as `${typeof prefix}1${string}`, prefix), | ||
}); | ||
|
||
export const isAddress = (check: string): check is `${typeof prefix}1${string}` => { | ||
try { | ||
transparentAddressFromBech32(check); | ||
return true; | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
export { | ||
PENUMBRA_BECH32M_TRANSPARENT_LENGTH, | ||
PENUMBRA_BECH32M_TRANSPARENT_PREFIX, | ||
} from './index.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { Impl } from './index.js'; | ||
import { fvkCtx } from '../ctx/full-viewing-key.js'; | ||
import { getTransparentAddress } from '@penumbra-zone/wasm/keys'; | ||
|
||
export const transparentAddress: Impl['transparentAddress'] = async (_, ctx) => { | ||
const fvk = await ctx.values.get(fvkCtx)(); | ||
const t_addr = getTransparentAddress(fvk); | ||
|
||
return { | ||
address: t_addr.address, | ||
encoding: t_addr.encoding, | ||
}; | ||
}; |
32 changes: 32 additions & 0 deletions
32
packages/services/src/view-service/util/transaction-view.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { TransactionView } from '@penumbra-zone/protobuf/penumbra/core/transaction/v1/transaction_pb'; | ||
import { getTransmissionKeyByAddress } from '@penumbra-zone/wasm/keys'; | ||
|
||
// Some transaction views (TXVs) require additional preprocessing before being rendered | ||
// in the UI component library. For example, when handling IBC withdrawals with transparent | ||
// addresses, this component transforms ephemeral addresses into their bech32-encoded | ||
// transparent form to ensure the proper data is being displayed. | ||
export const txvTranslator = (view: TransactionView): TransactionView => { | ||
// 'Ics20Withdrawal' action view | ||
if (!view.bodyView) { | ||
return view; | ||
} | ||
|
||
const withdrawalAction = view.bodyView.actionViews.find( | ||
action => action.actionView.case === 'ics20Withdrawal', | ||
); | ||
|
||
if (withdrawalAction?.actionView.case === 'ics20Withdrawal') { | ||
const withdrawal = withdrawalAction.actionView.value; | ||
// Create 80-byte array initialized to zeros, then set first 32 bytes to transmission key. | ||
// This constructs a valid address format where: | ||
// - First 32 bytes: transmission key | ||
// - Remaining 48 bytes: zeroed (16-byte diversifier + 32-byte clue key) | ||
if (withdrawal.returnAddress && withdrawal.useTransparentAddress) { | ||
const newInner = new Uint8Array(80).fill(0); | ||
newInner.set(getTransmissionKeyByAddress(withdrawal.returnAddress), 0); | ||
withdrawal.returnAddress.inner = newInner; | ||
} | ||
} | ||
|
||
return view; | ||
}; |
Oops, something went wrong.