Skip to content

Commit 71a4a2b

Browse files
committed
fix: handle non-EVM addresses in metadata-tools and ua-devtools-sui
- Add isNonEvmDeployment() to skip address checksumming for Sui/Starknet - Update setPeer() in ua-devtools-sui to handle addresses ≤32 bytes (Starknet is 31 bytes)
1 parent 6388eb7 commit 71a4a2b

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

packages/metadata-tools/src/config-metadata.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,23 @@ function isSolanaDeployment(deployment: { chainKey: string; executor?: { pda?: s
112112
return deployment.chainKey.startsWith('solana')
113113
}
114114

115+
function isNonEvmDeployment(deployment: { chainKey: string }) {
116+
return ['solana', 'sui', 'starknet', 'aptos', 'ton'].some((prefix) => deployment.chainKey.startsWith(prefix))
117+
}
118+
119+
const maybeChecksumAddress = (address: string) => {
120+
if (!address) {
121+
return address
122+
}
123+
if (!address.startsWith('0x')) {
124+
return address
125+
}
126+
if (address.length !== 42) {
127+
return address
128+
}
129+
return getAddress(address)
130+
}
131+
115132
function resolveExecutorForDeployment(
116133
customExecutor: string | undefined,
117134
deployment: { chainKey: string; executor?: { pda?: string; address?: string } },
@@ -167,8 +184,13 @@ function isBlocked(blockConfirmationsDefinition: BlockConfirmationsDefinition |
167184
)
168185
}
169186

170-
const getLibraryAddress = (deployment: any, metadataKey: string) =>
171-
isSolanaDeployment(deployment) ? deployment[metadataKey].address : getAddress(deployment[metadataKey].address)
187+
const getLibraryAddress = (deployment: any, metadataKey: string) => {
188+
const address = deployment[metadataKey].address
189+
if (isNonEvmDeployment(deployment)) {
190+
return address
191+
}
192+
return maybeChecksumAddress(address)
193+
}
172194

173195
export async function translatePathwayToConfig(
174196
pathway: TwoWayConfig,

packages/ua-devtools-sui/src/oft/sdk.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,18 +65,18 @@ export class OFT extends OmniSDK implements IOApp {
6565

6666
async setPeer(_eid: EndpointId, _peer: OmniAddress | null | undefined): Promise<OmniTransaction> {
6767
const tx = new Transaction()
68-
// Peer addresses must be 32 bytes (bytes32), so we need to pad EVM addresses (20 bytes) to 32 bytes
68+
// Peer addresses must be 32 bytes (bytes32), so we need to pad shorter addresses to 32 bytes
6969
let peerBytes: Uint8Array
7070
if (_peer) {
7171
const rawBytes = fromHex(_peer)
7272
if (rawBytes.length === 32) {
7373
peerBytes = rawBytes
74-
} else if (rawBytes.length === 20) {
75-
// Pad EVM address (20 bytes) to 32 bytes with leading zeros
74+
} else if (rawBytes.length <= 32) {
75+
// Pad shorter addresses (20-byte EVM, 31-byte Starknet, etc.) to 32 bytes with leading zeros
7676
peerBytes = new Uint8Array(32)
7777
peerBytes.set(rawBytes, 32 - rawBytes.length)
7878
} else {
79-
throw new Error(`Invalid peer address length: ${rawBytes.length}. Expected 20 or 32 bytes.`)
79+
throw new Error(`Invalid peer address length: ${rawBytes.length}. Expected 32 bytes or less.`)
8080
}
8181
} else {
8282
peerBytes = new Uint8Array(32)

0 commit comments

Comments
 (0)