chore(dapps) remove unused Wallet Connect authentication from the SDK

Also add more debug logs for unhandled events

Updates: #15598
This commit is contained in:
Stefan 2024-07-25 17:22:15 +03:00 committed by Stefan Dunca
parent 992944870b
commit 910af539d6
3 changed files with 66 additions and 190 deletions

View File

@ -68,22 +68,6 @@ WalletConnectSDKBase {
wcCalls.rejectSessionRequest(topic, id, error)
}
function auth(authLink) {
wcCalls.auth(authLink)
}
function formatAuthMessage(cacaoPayload, address) {
wcCalls.formatAuthMessage(cacaoPayload, address)
}
function authApprove(authRequest, address, signature) {
wcCalls.authApprove(authRequest, address, signature)
}
function authReject(id, address) {
wcCalls.authReject(id, address)
}
QtObject {
id: d
@ -268,61 +252,6 @@ WalletConnectSDKBase {
`
)
}
function auth(authLink) {
console.debug(`WC WalletConnectSDK.wcCall.auth; authLink: ${authLink}`)
d.engine.runJavaScript(`
wc.auth("${authLink}")
.then((value) => {
wc.statusObject.onAuthResponse("")
})
.catch((e) => {
wc.statusObject.onAuthResponse(e.message)
})
`
)
}
function formatAuthMessage(cacaoPayload, address) {
console.debug(`WC WalletConnectSDK.wcCall.auth; cacaoPayload: ${JSON.stringify(cacaoPayload)}, address: ${address}`)
d.engine.runJavaScript(`wc.formatAuthMessage(${JSON.stringify(cacaoPayload)}, "${address}")`, function(result) {
console.debug(`WC WalletConnectSDK.wcCall.formatAuthMessage; response: ${JSON.stringify(result)}`)
root.authMessageFormated(result, address)
})
}
function authApprove(authRequest, address, signature) {
console.debug(`WC WalletConnectSDK.wcCall.authApprove; authRequest: ${JSON.stringify(authRequest)}, address: ${address}, signature: ${signature}`)
d.engine.runJavaScript(`
wc.approveAuth(${JSON.stringify(authRequest)}, "${address}", "${signature}")
.then((value) => {
wc.statusObject.onApproveAuthResponse("")
})
.catch((e) => {
wc.statusObject.onApproveAuthResponse(e.message)
})
`
)
}
function authReject(id, address) {
console.debug(`WC WalletConnectSDK.wcCall.authReject; id: ${id}, address: ${address}`)
d.engine.runJavaScript(`
wc.rejectAuth(${id}, "${address}")
.then((value) => {
wc.statusObject.onRejectAuthResponse("")
})
.catch((e) => {
wc.statusObject.onRejectAuthResponse(e.message)
})
`
)
}
}
QtObject {
@ -436,25 +365,6 @@ WalletConnectSDKBase {
console.debug(`WC WalletConnectSDK.onProposalExpire; details: ${JSON.stringify(details)}`)
root.sessionProposalExpired()
}
function onAuthRequest(details) {
console.debug(`WC WalletConnectSDK.onAuthRequest; details: ${JSON.stringify(details)}`)
root.authRequest(details)
}
function onAuthResponse(error) {
console.debug(`WC WalletConnectSDK.onAuthResponse; error: ${error}`)
}
function onApproveAuthResponse(error) {
console.debug(`WC WalletConnectSDK.onApproveAuthResponse; error: ${error}`)
root.authRequestUserAnswerResult(true, error)
}
function onRejectAuthResponse(error) {
console.debug(`WC WalletConnectSDK.onRejectAuthResponse; error: ${error}`)
root.authRequestUserAnswerResult(false, error)
}
}
WebEngineLoader {

File diff suppressed because one or more lines are too long

View File

@ -1,8 +1,6 @@
import { Core } from "@walletconnect/core";
import { Web3Wallet } from "@walletconnect/web3wallet";
import AuthClient from '@walletconnect/auth-client'
// import the builder util
import { buildApprovedNamespaces, getSdkError } from "@walletconnect/utils";
import { formatJsonRpcResult, formatJsonRpcError } from "@walletconnect/jsonrpc-utils";
@ -10,13 +8,12 @@ import { formatJsonRpcResult, formatJsonRpcError } from "@walletconnect/jsonrpc-
window.wc = {
core: null,
web3wallet: null,
authClient: null,
statusObject: null,
init: function (projectId) {
return new Promise(async (resolve, reject) => {
if (!window.statusq) {
const errMsg = 'missing window.statusq! Forgot to execute "ui/StatusQ/src/StatusQ/Components/private/qwebchannel/helpers.js" first?'
const errMsg = 'missing window.statusq! Forgot to execute "ui/app/AppLayouts/Wallet/services/dapps/helpers.js" first?'
console.error(errMsg);
reject(errMsg);
}
@ -34,72 +31,82 @@ window.wc = {
reject(errMsg);
}
window.wc.core = new Core({
projectId: projectId,
});
try {
const coreInst = new Core({
projectId: projectId,
});
window.wc.web3wallet = await Web3Wallet.init({
core: coreInst, // <- pass the shared `core` instance
metadata: {
name: "Status",
description: "Status Wallet",
url: "http://localhost",
icons: ['https://avatars.githubusercontent.com/u/11767950'],
},
});
window.wc.core = coreInst
window.wc.web3wallet = await Web3Wallet.init({
core: window.wc.core, // <- pass the shared `core` instance
metadata: {
name: "Status",
description: "Status Wallet",
url: "http://localhost",
icons: ['https://status.im/img/status-footer-logo.svg'],
},
});
// connect session responses https://specs.walletconnect.com/2.0/specs/clients/sign/session-events#events
window.wc.web3wallet.on("session_proposal", (details) => {
wc.statusObject.onSessionProposal(details)
});
window.wc.authClient = await AuthClient.init({
projectId: projectId,
metadata: window.wc.web3wallet.metadata,
});
window.wc.web3wallet.on("session_update", (details) => {
wc.statusObject.onSessionUpdate(details)
});
// connect session responses https://specs.walletconnect.com/2.0/specs/clients/sign/session-events#events
window.wc.web3wallet.on("session_proposal", (details) => {
wc.statusObject.onSessionProposal(details)
});
window.wc.web3wallet.on("session_extend", (details) => {
wc.statusObject.onSessionExtend(details)
});
window.wc.web3wallet.on("session_update", (details) => {
wc.statusObject.onSessionUpdate(details)
});
window.wc.web3wallet.on("session_ping", (details) => {
wc.statusObject.onSessionPing(details)
});
window.wc.web3wallet.on("session_extend", (details) => {
wc.statusObject.onSessionExtend(details)
});
window.wc.web3wallet.on("session_delete", (details) => {
wc.statusObject.onSessionDelete(details)
});
window.wc.web3wallet.on("session_ping", (details) => {
wc.statusObject.onSessionPing(details)
});
window.wc.web3wallet.on("session_expire", (details) => {
wc.statusObject.onSessionExpire(details)
});
window.wc.web3wallet.on("session_delete", (details) => {
wc.statusObject.onSessionDelete(details)
});
window.wc.web3wallet.on("session_request", (details) => {
wc.statusObject.onSessionRequest(details)
});
window.wc.web3wallet.on("session_expire", (details) => {
wc.statusObject.onSessionExpire(details)
});
window.wc.web3wallet.on("session_request_sent", (details) => {
wc.statusObject.onSessionRequestSent(details)
});
window.wc.web3wallet.on("session_request", (details) => {
wc.statusObject.onSessionRequest(details)
});
window.wc.web3wallet.on("session_event", (details) => {
wc.statusObject.onSessionEvent(details)
});
window.wc.web3wallet.on("session_request_sent", (details) => {
wc.statusObject.onSessionRequestSent(details)
});
window.wc.web3wallet.on("proposal_expire", (details) => {
wc.statusObject.onProposalExpire(details)
});
window.wc.web3wallet.on("session_event", (details) => {
wc.statusObject.onSessionEvent(details)
});
// Debug event handlers
window.wc.web3wallet.on("pairing_expire", (event) => {
wc.statusObject.echo("debug", `WC unhandled event: "pairing_expire" ${JSON.stringify(event)}`);
// const { topic } = event;
});
window.wc.web3wallet.on("session_request_expire", (event) => {
wc.statusObject.echo("debug", `WC unhandled event: "session_request_expire" ${JSON.stringify(event)}`);
// const { id } = event
});
window.wc.core.relayer.on("relayer_connect", () => {
wc.statusObject.echo("debug", `WC unhandled event: "relayer_connect" connection to the relay server is established`);
})
window.wc.core.relayer.on("relayer_disconnect", () => {
wc.statusObject.echo("debug", `WC unhandled event: "relayer_disconnect" connection to the relay server is lost`);
})
window.wc.web3wallet.on("proposal_expire", (details) => {
wc.statusObject.onProposalExpire(details)
});
window.wc.authClient.on("auth_request", (details) => {
wc.statusObject.onAuthRequest(details)
});
wc.statusObject.sdkInitialized("");
resolve("");
resolve("");
} catch(error) {
reject(error)
}
});
},
@ -159,47 +166,6 @@ window.wc = {
);
},
auth: async function (uri) {
await window.wc.authClient.core.pairing.pair({ uri });
},
formatAuthMessage: function (cacaoPayload, address) {
const iss = `did:pkh:eip155:1:${address}`;
return window.wc.authClient.formatMessage(cacaoPayload, iss);
},
approveAuth: async function (authRequest, address, signature) {
const { id } = authRequest;
const iss = `did:pkh:eip155:1:${address}`;
await window.wc.authClient.respond(
{
id: id,
signature: {
s: signature,
t: "eip191",
},
},
iss
);
},
rejectAuth: async function (id, address) {
const iss = `did:pkh:eip155:1:${address}`;
await window.wc.authClient.respond(
{
id: id,
error: {
code: 4001,
message: 'Auth request has been rejected'
},
},
iss
);
},
respondSessionRequest: async function (topic, id, signature) {
const response = formatJsonRpcResult(id, signature)