@@ -102,7 +102,6 @@ export const SIWXUtil = {
102102 const siwx = OptionsController . state . siwx
103103 const address = CoreHelperUtil . getPlainAddress ( ChainController . getActiveCaipAddress ( ) )
104104 const network = getActiveCaipNetwork ( )
105- const client = ConnectionController . _getClient ( )
106105
107106 if ( ! siwx ) {
108107 throw new Error ( 'SIWX is not enabled' )
@@ -116,25 +115,29 @@ export const SIWXUtil = {
116115 throw new Error ( 'No ActiveCaipNetwork or client found' )
117116 }
118117
119- if ( ! client ) {
120- throw new Error ( 'No ConnectionController client found' )
121- }
122-
123118 try {
124119 const siwxMessage = await siwx . createMessage ( {
125120 chainId : network . caipNetworkId ,
126121 accountAddress : address
127122 } )
128123
129124 const message = siwxMessage . toString ( )
130- const connectorId = ConnectorController . getConnectorId ( network . chainNamespace )
131125
132- if ( connectorId === CommonConstantsUtil . CONNECTOR_ID . AUTH ) {
133- RouterController . pushTransactionStack ( { } )
126+ let signature = ''
127+ if ( siwx . signMessage ) {
128+ signature = await siwx . signMessage ( {
129+ message,
130+ chainId : network . caipNetworkId ,
131+ accountAddress : address
132+ } )
133+ } else {
134+ const connectorId = ConnectorController . getConnectorId ( network . chainNamespace )
135+ if ( connectorId === CommonConstantsUtil . CONNECTOR_ID . AUTH ) {
136+ RouterController . pushTransactionStack ( { } )
137+ }
138+ signature = ( await ConnectionController . signMessage ( message ) ) || ''
134139 }
135140
136- const signature = await client . signMessage ( message )
137-
138141 await siwx . addSession ( {
139142 data : siwxMessage ,
140143 message,
@@ -523,6 +526,28 @@ export interface SIWXConfig {
523526 */
524527 createMessage : ( input : SIWXMessage . Input ) => Promise < SIWXMessage >
525528
529+ /**
530+ * This method will be called to sign a message with the wallet using the signer handler.
531+ * This behavior can be overriden by passing in a `signer` parameter to the `SIWXConfig` constructor.
532+ * Constraints:
533+ * - This method MUST forward the message to the wallet for a signature request.
534+ * - If the signature process fails or is cancelled it MUST throw an error.
535+ *
536+ * @param message string
537+ * @param chainId CaipNetworkId
538+ * @param accountAddress string
539+ * @returns string
540+ */
541+ signMessage ?: ( {
542+ message,
543+ chainId,
544+ accountAddress
545+ } : {
546+ message : string
547+ chainId : string
548+ accountAddress : string
549+ } ) => Promise < string >
550+
526551 /**
527552 * This method will be called to store a new single session.
528553 *
0 commit comments