Skip to content

Commit 946c77a

Browse files
authored
Merge pull request #814 from relayprotocol/pedro/fe-7788-implement-sending-public-key-for-bitcoin-quotes
Implement sending public key for bitcoin quotes
2 parents d14cf35 + e3a9e1d commit 946c77a

File tree

5 files changed

+33
-3
lines changed

5 files changed

+33
-3
lines changed

.changeset/fast-cups-notice.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@relayprotocol/relay-bitcoin-wallet-adapter': patch
3+
'@relayprotocol/relay-sdk': patch
4+
'@relayprotocol/relay-kit-ui': patch
5+
---
6+
7+
Add bitcoin public key to quote params

demo/pages/ui/swap.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ const SwapWidgetPage: NextPage = () => {
109109
adaptedWallet = adaptViemWallet(walletClient)
110110
} else if (isBitcoinWallet(primaryWallet)) {
111111
const wallet = convertToLinkedWallet(primaryWallet)
112+
const publicKey = primaryWallet.additionalAddresses.find(
113+
({ address, type }) =>
114+
address === wallet.address && type === 'payment'
115+
)?.publicKey
112116
adaptedWallet = adaptBitcoinWallet(
113117
wallet.address,
114118
async (_address, _psbt, dynamicParams) => {
@@ -123,7 +127,8 @@ const SwapWidgetPage: NextPage = () => {
123127
} catch (e) {
124128
throw e
125129
}
126-
}
130+
},
131+
publicKey
127132
)
128133
} else if (
129134
isSolanaWallet(primaryWallet) ||

packages/relay-bitcoin-wallet-adapter/src/adapter.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export const adaptBitcoinWallet = (
2121
address: string,
2222
psbt: bitcoin.Psbt,
2323
dynamicParams: DynamicSignPsbtParams
24-
) => Promise<string>
24+
) => Promise<string>,
25+
publicKey?: string
2526
): AdaptedWallet => {
2627
return {
2728
vmType: 'bvm',
@@ -76,6 +77,9 @@ export const adaptBitcoinWallet = (
7677
//@ts-ignore
7778
switchChain: (chainId: number) => {
7879
throw 'Not yet implemented'
80+
},
81+
metadata: {
82+
publicKey
7983
}
8084
}
8185
}

packages/sdk/src/types/AdaptedWallet.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ export type SuiReceipt = {
1414
digest: string
1515
}
1616

17+
export type BitcoinWalletMetadata = {
18+
publicKey?: string
19+
}
20+
1721
export type AdaptedWallet = {
1822
vmType: ChainVM
23+
metadata?: BitcoinWalletMetadata
1924
getChainId: () => Promise<number>
2025
handleSignMessageStep: (
2126
item: SignatureStepItem,
@@ -52,5 +57,7 @@ export type AdaptedWallet = {
5257
items: TransactionStepItem[]
5358
) => Promise<string | undefined>
5459
// detect if wallet is an EOA (externally owned account)
55-
isEOA?: (chainId: number) => Promise<{ isEOA: boolean; isEIP7702Delegated: boolean }>
60+
isEOA?: (
61+
chainId: number
62+
) => Promise<{ isEOA: boolean; isEIP7702Delegated: boolean }>
5663
}

packages/ui/src/components/widgets/SwapWidgetRenderer.tsx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,13 @@ const SwapWidgetRenderer: FC<SwapWidgetRendererProps> = ({
611611
refundTo: fromToken?.chainId === 1337 ? address : undefined,
612612
slippageTolerance: slippageTolerance,
613613
topupGas: gasTopUpEnabled && gasTopUpRequired,
614+
...(linkedWallet?.vmType === 'bvm' && wallet?.metadata?.publicKey
615+
? {
616+
additionalData: {
617+
userPublicKey: wallet?.metadata?.publicKey
618+
}
619+
}
620+
: {}),
614621
protocolVersion: quoteProtocol,
615622
...(quoteProtocol === 'preferV2' &&
616623
explicitDeposit !== undefined && {

0 commit comments

Comments
 (0)