diff --git a/packages/dapp-kit-react/src/DAppKitProvider.tsx b/packages/dapp-kit-react/src/DAppKitProvider.tsx index 7f8a625c..8d8a8655 100644 --- a/packages/dapp-kit-react/src/DAppKitProvider.tsx +++ b/packages/dapp-kit-react/src/DAppKitProvider.tsx @@ -31,6 +31,7 @@ export const DAppKitProvider: React.FC = ({ language, modalParent, onSourceClick, + connectionCertificate: connectionCertificateData, }): React.ReactElement => { const connex = useMemo( () => @@ -47,6 +48,7 @@ export const DAppKitProvider: React.FC = ({ language, modalParent, onSourceClick, + connectionCertificate: connectionCertificateData, }), [ nodeUrl, @@ -61,6 +63,7 @@ export const DAppKitProvider: React.FC = ({ language, modalParent, onSourceClick, + connectionCertificateData, ], ); diff --git a/packages/dapp-kit-react/src/types.ts b/packages/dapp-kit-react/src/types.ts index 0bac2d26..087fa32f 100644 --- a/packages/dapp-kit-react/src/types.ts +++ b/packages/dapp-kit-react/src/types.ts @@ -3,6 +3,8 @@ import type React from 'react'; import * as ThorDevkit from 'thor-devkit'; import type { ConnectResponse, WalletSource } from '@vechain/dapp-kit'; import { type DAppKitUIOptions } from '@vechain/dapp-kit-ui'; +export type { WalletConnectOptions, DAppKitOptions } from '@vechain/dapp-kit'; +export type { DAppKitUIOptions } from '@vechain/dapp-kit-ui'; export interface AccountState { address: string | null; diff --git a/packages/dapp-kit/src/classes/certificate-wallet.ts b/packages/dapp-kit/src/classes/certificate-wallet.ts index 8203096a..79eaa2d0 100644 --- a/packages/dapp-kit/src/classes/certificate-wallet.ts +++ b/packages/dapp-kit/src/classes/certificate-wallet.ts @@ -6,17 +6,27 @@ import { DEFAULT_CONNECT_CERT_MESSAGE } from '../constants'; * A `ConnexWallet` for wallet's that use a certificate connection */ class CertificateBasedWallet implements ConnexWallet { - constructor(private readonly wallet: BaseWallet) {} + constructor( + private readonly wallet: BaseWallet, + private readonly connectionCertificateData?: { + message?: Connex.Vendor.CertMessage; + options?: Connex.Signer.CertOptions; + }, + ) {} connect = async (): Promise => { - const cert = DEFAULT_CONNECT_CERT_MESSAGE; + const certificateMessage = + this.connectionCertificateData?.message || + DEFAULT_CONNECT_CERT_MESSAGE; + const certificateOptions = + this.connectionCertificateData?.options || {}; const { annex: { domain, signer, timestamp }, signature, - } = await this.signCert(cert, {}); + } = await this.signCert(certificateMessage, certificateOptions); const connectionCertificate = { - ...cert, + ...certificateMessage, signature, signer, domain, diff --git a/packages/dapp-kit/src/classes/wallet-manager.ts b/packages/dapp-kit/src/classes/wallet-manager.ts index 1526f21a..f4e4064a 100644 --- a/packages/dapp-kit/src/classes/wallet-manager.ts +++ b/packages/dapp-kit/src/classes/wallet-manager.ts @@ -68,14 +68,18 @@ class WalletManager { // this is needed for wallet connect connections when a connection certificate is required signConnectionCertificate = async (): Promise => { - const cert = DEFAULT_CONNECT_CERT_MESSAGE; + const certificateMessage = + this.options.connectionCertificate?.message || + DEFAULT_CONNECT_CERT_MESSAGE; + const certificateOptions = + this.options.connectionCertificate?.options || {}; const { annex: { domain, signer, timestamp }, signature, - } = await this.wallet.signCert(cert, {}); + } = await this.wallet.signCert(certificateMessage, certificateOptions); const connectionCertificate = { - ...cert, + ...certificateMessage, signature, signer, domain, diff --git a/packages/dapp-kit/src/types/types.d.ts b/packages/dapp-kit/src/types/types.d.ts index 8032a4e0..eaf997b9 100644 --- a/packages/dapp-kit/src/types/types.d.ts +++ b/packages/dapp-kit/src/types/types.d.ts @@ -37,6 +37,10 @@ interface DAppKitOptions { useFirstDetectedSource?: boolean; logLevel?: LogLevel; requireCertificate?: boolean; + connectionCertificate?: { + message?: Connex.Vendor.CertMessage; + options?: Connex.Signer.CertOptions; + }; } type BaseWallet = Connex.Signer & { diff --git a/packages/dapp-kit/src/utils/create-wallet.ts b/packages/dapp-kit/src/utils/create-wallet.ts index 3e4c40b5..9bce28f0 100644 --- a/packages/dapp-kit/src/utils/create-wallet.ts +++ b/packages/dapp-kit/src/utils/create-wallet.ts @@ -25,6 +25,7 @@ export const createWallet = ({ genesis, walletConnectOptions, onDisconnected, + connectionCertificate, }: ICreateWallet): ConnexWallet => { const genesisId = normalizeGenesisId(genesis); @@ -38,12 +39,18 @@ export const createWallet = ({ const vendor = new ConnexLib.Connex.Vendor(genesisId, 'sync'); - return new CertificateBasedWallet(convertVendorToSigner(vendor)); + return new CertificateBasedWallet( + convertVendorToSigner(vendor), + connectionCertificate, + ); } case 'sync2': { const vendor = new ConnexLib.Connex.Vendor(genesisId, 'sync2'); - return new CertificateBasedWallet(convertVendorToSigner(vendor)); + return new CertificateBasedWallet( + convertVendorToSigner(vendor), + connectionCertificate, + ); } case 'veworld': { if (!window.vechain) { @@ -52,7 +59,7 @@ export const createWallet = ({ const signer = window.vechain.newConnexSigner(genesisId); - return new CertificateBasedWallet(signer); + return new CertificateBasedWallet(signer, connectionCertificate); } case 'wallet-connect': { if (!walletConnectOptions) { diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 00000000..d02c2e89 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,3 @@ +{ + "extends": "@vechain/repo-config/src/tsconfig/base.json" +}