diff --git a/packages/sdk/wallets/wallet-walletconnect/package.json b/packages/sdk/wallets/wallet-walletconnect/package.json index 25411d3abdf..fa83b92464e 100644 --- a/packages/sdk/wallets/wallet-walletconnect/package.json +++ b/packages/sdk/wallets/wallet-walletconnect/package.json @@ -26,7 +26,7 @@ "@celo/utils": "1.1.1-dev", "@celo/wallet-base": "1.1.1-dev", "@celo/wallet-remote": "1.1.1-dev", - "@walletconnect/client": "2.0.0-alpha.26", + "@walletconnect/client": "2.0.0-alpha.32", "debug": "^4.1.1", "ethereumjs-util": "^7.0.8" }, diff --git a/packages/sdk/wallets/wallet-walletconnect/scripts/run-in-memory-client.ts b/packages/sdk/wallets/wallet-walletconnect/scripts/run-in-memory-client.ts new file mode 100644 index 00000000000..e66a33b8204 --- /dev/null +++ b/packages/sdk/wallets/wallet-walletconnect/scripts/run-in-memory-client.ts @@ -0,0 +1,56 @@ +import { newKit } from '@celo/contractkit' +import { WalletConnectWallet } from '../src' + +async function main() { + const wallet = new WalletConnectWallet({ + connect: { + metadata: { + name: 'use-contractkit demo', + description: 'A showcase of use-contractkit', + url: 'https://use-contractkit.vercel.app', + icons: [], + }, + }, + init: { + relayProvider: 'wss://relay.walletconnect.org', + logger: 'error', + }, + }) + const uri = await wallet.getUri() + console.log(`=== START OUT OF BAND URI === +${uri.toString()} +=== END OUT OF BAND URI ===`) + await wallet.init() + + const [from] = await wallet.getAccounts() + const kit = newKit('https://alfajores-forno.celo-testnet.org', wallet) + + /** + * Uncomment to send a test transaction + */ + // const gold = await kit.contracts.getGoldToken() + // await gold + // .transfer('0x4132F04EaCfdE9E2b707667A13CB69DbC5BABb68', '1') + // .sendAndWaitForReceipt({ from }) + // console.log('Transaction sent!') + + /** + * Uncomment to sign a test payload + */ + // await kit.connection.sign(ensureLeading0x(Buffer.from('hello').toString()), from) + // console.log('Payload signed!') + + /** + * Uncomment to hold connection open + */ + // await new Promise((resolve) => setTimeout(resolve, 1000 * 60 * 60 * 24)) + + await wallet.close() +} + +main() + .then(() => process.exit()) + .catch((e) => { + console.error(e) + process.exit(1) + }) diff --git a/packages/sdk/wallets/wallet-walletconnect/scripts/run-in-memory-wallet.ts b/packages/sdk/wallets/wallet-walletconnect/scripts/run-in-memory-wallet.ts new file mode 100644 index 00000000000..f0ff99f991a --- /dev/null +++ b/packages/sdk/wallets/wallet-walletconnect/scripts/run-in-memory-wallet.ts @@ -0,0 +1,10 @@ +import { getTestWallet } from '../src/test/in-memory-wallet' +;(async function main() { + const uri = process.argv[2] + if (!uri) { + return + } + + const wallet = getTestWallet() + await wallet.init(uri) +})() diff --git a/packages/sdk/wallets/wallet-walletconnect/src/test/common.ts b/packages/sdk/wallets/wallet-walletconnect/src/test/common.ts index 5f22e3785a9..16c512b28b7 100644 --- a/packages/sdk/wallets/wallet-walletconnect/src/test/common.ts +++ b/packages/sdk/wallets/wallet-walletconnect/src/test/common.ts @@ -6,23 +6,23 @@ import { toChecksumAddress } from 'ethereumjs-util' // personal_sign is the one RPC that has [payload, from] rather // than [from, payload] -export function parsePersonalSign(req: any): { from: string; payload: string } { - const [payload, from] = req.payload.params +export function parsePersonalSign(params: any): { from: string; payload: string } { + const [payload, from] = params return { from, payload } } -export function parseSignTypedData(req: any): { from: string; payload: EIP712TypedData } { - const [from, payload] = req.payload.params +export function parseSignTypedData(params: any): { from: string; payload: EIP712TypedData } { + const [from, payload] = params return { from, payload: JSON.parse(payload) } } -export function parseSignTransaction(req: any): CeloTx { - return req.payload.params +export function parseSignTransaction(params: any): CeloTx { + return params } -export function parseComputeSharedSecret(req: any): { from: Address; publicKey: string } { - const [from, publicKey] = req.payload.params +export function parseComputeSharedSecret(params: any): { from: Address; publicKey: string } { + const [from, publicKey] = params return { from, publicKey } } -export function parseDecrypt(req: any): { from: string; payload: Buffer } { - const [from, payload] = req.payload.params +export function parseDecrypt(params: any): { from: string; payload: Buffer } { + const [from, payload] = params return { from, payload: Buffer.from(payload, 'hex') } } diff --git a/packages/sdk/wallets/wallet-walletconnect/src/test/in-memory-wallet.ts b/packages/sdk/wallets/wallet-walletconnect/src/test/in-memory-wallet.ts index de40e81724e..5423054d1c7 100644 --- a/packages/sdk/wallets/wallet-walletconnect/src/test/in-memory-wallet.ts +++ b/packages/sdk/wallets/wallet-walletconnect/src/test/in-memory-wallet.ts @@ -65,29 +65,34 @@ export function getTestWallet() { debug('onPairingDeleted', pairing) } - async function onSessionPayload(event: SessionTypes.PayloadEvent) { + async function onSessionRequest(event: SessionTypes.RequestParams) { const { topic, - // @ts-ignore todo: ask Pedro why this isn't typed - payload: { id, method }, + request: { + // @ts-ignore + id, + method, + // @ts-ignore + params, + }, } = event let result: any if (method === SupportedMethods.personalSign) { - const { payload, from } = parsePersonalSign(event) + const { payload, from } = parsePersonalSign(params) result = await wallet.signPersonalMessage(from, payload) } else if (method === SupportedMethods.signTypedData) { - const { from, payload } = parseSignTypedData(event) + const { from, payload } = parseSignTypedData(params) result = await wallet.signTypedData(from, payload) } else if (method === SupportedMethods.signTransaction) { - const tx = parseSignTransaction(event) + const tx = parseSignTransaction(params) result = await wallet.signTransaction(tx) } else if (method === SupportedMethods.computeSharedSecret) { - const { from, publicKey } = parseComputeSharedSecret(event) + const { from, publicKey } = parseComputeSharedSecret(params) result = (await wallet.computeSharedSecret(from, publicKey)).toString('hex') } else if (method === SupportedMethods.decrypt) { - const { from, payload } = parseDecrypt(event) + const { from, payload } = parseDecrypt(params) result = (await wallet.decrypt(from, payload)).toString('hex') } else { // client.reject({}) @@ -109,13 +114,15 @@ export function getTestWallet() { return { init: async (uri: string) => { client = await WalletConnect.init({ - relayProvider: process.env.WALLET_CONNECT_BRIGDE, + relayProvider: process.env.WALLET_CONNECT_BRIDGE, + controller: true, }) + client.on(CLIENT_EVENTS.session.proposal, onSessionProposal) client.on(CLIENT_EVENTS.session.created, onSessionCreated) client.on(CLIENT_EVENTS.session.updated, onSessionUpdated) client.on(CLIENT_EVENTS.session.deleted, onSessionDeleted) - client.on(CLIENT_EVENTS.session.payload, onSessionPayload) + client.on(CLIENT_EVENTS.session.request, onSessionRequest) client.on(CLIENT_EVENTS.pairing.proposal, onPairingProposal) client.on(CLIENT_EVENTS.pairing.created, onPairingCreated) diff --git a/packages/sdk/wallets/wallet-walletconnect/src/test/mock-client.ts b/packages/sdk/wallets/wallet-walletconnect/src/test/mock-client.ts index 61474cddfd6..5e933866f87 100644 --- a/packages/sdk/wallets/wallet-walletconnect/src/test/mock-client.ts +++ b/packages/sdk/wallets/wallet-walletconnect/src/test/mock-client.ts @@ -42,33 +42,29 @@ export class MockWalletConnectClient extends EventEmitter { }) } - async request(event: SessionTypes.PayloadEvent) { + async request(event: SessionTypes.RequestEvent) { const { - // @ts-ignore - request: { method }, + request: { method, params }, } = event // the request gets transformed between the client // and wallet, here we reassign to use our decoding // methods in ./common.ts. - // @ts-ignore - const request = { payload: { params: event.request.params } } - let result = null if (method === SupportedMethods.personalSign) { - const { payload, from } = parsePersonalSign(request) + const { payload, from } = parsePersonalSign(params) result = await testWallet.signPersonalMessage(from, payload) } else if (method === SupportedMethods.signTypedData) { - const { from, payload } = parseSignTypedData(request) + const { from, payload } = parseSignTypedData(params) result = await testWallet.signTypedData(from, payload) } else if (method === SupportedMethods.signTransaction) { - const tx = parseSignTransaction(request) + const tx = parseSignTransaction(params) result = await testWallet.signTransaction(tx) } else if (method === SupportedMethods.computeSharedSecret) { - const { from, publicKey } = parseComputeSharedSecret(request) + const { from, publicKey } = parseComputeSharedSecret(params) result = (await testWallet.computeSharedSecret(from, publicKey)).toString('hex') } else if (method === SupportedMethods.decrypt) { - const { from, payload } = parseDecrypt(request) + const { from, payload } = parseDecrypt(params) result = (await testWallet.decrypt(from, payload)).toString('hex') } else { return diff --git a/packages/sdk/wallets/wallet-walletconnect/src/types.ts b/packages/sdk/wallets/wallet-walletconnect/src/types.ts index ea35d896d33..aec0e56b983 100644 --- a/packages/sdk/wallets/wallet-walletconnect/src/types.ts +++ b/packages/sdk/wallets/wallet-walletconnect/src/types.ts @@ -1,6 +1,5 @@ export enum SupportedMethods { accounts = 'eth_accounts', - sendTransaction = 'eth_sendTransaction', signTransaction = 'eth_signTransaction', personalSign = 'personal_sign', signTypedData = 'eth_signTypedData', diff --git a/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.test.ts b/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.test.ts index 13be73570ce..5399d925003 100644 --- a/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.test.ts +++ b/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.test.ts @@ -67,7 +67,7 @@ const testTx = { } const decryptMessage = 'Hello' -const walletConnectBridge = process.env.WALLET_CONNECT_BRIGDE +const walletConnectBridge = process.env.WALLET_CONNECT_BRIDGE const E2E = !!walletConnectBridge describe('WalletConnectWallet tests', () => { diff --git a/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.ts b/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.ts index 1c2e0228526..2add937dd2e 100644 --- a/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.ts +++ b/packages/sdk/wallets/wallet-walletconnect/src/wc-signer.ts @@ -26,7 +26,7 @@ export class WalletConnectSigner implements Signer { private request(method: SupportedMethods, params: any) { return this.client.request({ topic: this.session.topic, - chainId: this.chainId, + chainId: `celo:${this.chainId}`, request: { method, params, diff --git a/packages/sdk/wallets/wallet-walletconnect/src/wc-wallet.ts b/packages/sdk/wallets/wallet-walletconnect/src/wc-wallet.ts index f20a03801dc..6e09a5b8bc6 100644 --- a/packages/sdk/wallets/wallet-walletconnect/src/wc-wallet.ts +++ b/packages/sdk/wallets/wallet-walletconnect/src/wc-wallet.ts @@ -28,7 +28,7 @@ async function waitForTruthy(getValue: () => any, attempts: number = 10) { throw new Error('Unable to get pairing session, did you lose internet connection?') } -const defaultInitOptions: ClientOptions = { relayProvider: 'wss://bridge.walletconnect.org' } +const defaultInitOptions: ClientOptions = { relayProvider: 'wss://relay.walletconnect.org' } const defaultConnectOptions: ClientTypes.ConnectParams = { metadata: { name: 'ContractKit', @@ -132,7 +132,7 @@ export class WalletConnectWallet extends RemoteWallet { debug('Attempted to update non existant pairing', pairing) return } - this.pairing.peer.metadata = pairing.peer.metadata + this.pairing.state.metadata = pairing.state.metadata } onPairingDeleted = () => { this.pairing = undefined diff --git a/yarn.lock b/yarn.lock index 99fc7bc49cb..d778a4b86a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2825,7 +2825,7 @@ "@types/yargs" "^15.0.0" chalk "^4.0.0" -"@json-rpc-tools/provider@^1.4.0", "@json-rpc-tools/provider@^1.6.3": +"@json-rpc-tools/provider@^1.4.0": version "1.6.3" resolved "https://registry.yarnpkg.com/@json-rpc-tools/provider/-/provider-1.6.3.tgz#c2ed6906e1b5c86dc17defcd2b0f5ba774c58d46" integrity sha512-fVOmqJYAeCFVxSUUmmoxtLu/VtA1sbVsIrFsW84oSQv73C5A0+vby1fVIkxT2RXbjoAsufXTGin3twRDWusK/Q== @@ -2835,6 +2835,16 @@ safe-json-utils "^1.1.1" ws "^7.4.0" +"@json-rpc-tools/provider@^1.6.4": + version "1.6.4" + resolved "https://registry.yarnpkg.com/@json-rpc-tools/provider/-/provider-1.6.4.tgz#647f8d3d3e3b45db2b474671f20b63a8f3daf864" + integrity sha512-IXCPd26TonTKNPtc5dp/GyHJ5imCh5wcg+XICyAnMHdCinufjGbqBUIibGvPB/P2UmnfDUn6VlLKJShSa9x8Og== + dependencies: + "@json-rpc-tools/utils" "^1.6.4" + axios "^0.21.0" + safe-json-utils "^1.1.1" + ws "^7.4.0" + "@json-rpc-tools/types@^1.6.3": version "1.6.3" resolved "https://registry.yarnpkg.com/@json-rpc-tools/types/-/types-1.6.3.tgz#1c8231abf65f27a507cf4468bee86997d9b5a8e4" @@ -2842,6 +2852,13 @@ dependencies: keyvaluestorage-interface "^1.0.0" +"@json-rpc-tools/types@^1.6.4": + version "1.6.4" + resolved "https://registry.yarnpkg.com/@json-rpc-tools/types/-/types-1.6.4.tgz#8cfda48bcc19d4f643ff21ff56bdc1dce730a1f6" + integrity sha512-DHtnvlIFN8YUun38Sy9SaRdV/BsUMFM5bAABDsb/iPGLfPHOMKoAyuPOwEqQ2vgtc9ayTcQ2546OPTQ92IzJ/g== + dependencies: + keyvaluestorage-interface "^1.0.0" + "@json-rpc-tools/utils@^1.4.0", "@json-rpc-tools/utils@^1.6.3": version "1.6.3" resolved "https://registry.yarnpkg.com/@json-rpc-tools/utils/-/utils-1.6.3.tgz#4a0568c9a20a97aee445affe7747778554d08ec1" @@ -2849,6 +2866,13 @@ dependencies: "@json-rpc-tools/types" "^1.6.3" +"@json-rpc-tools/utils@^1.6.4": + version "1.6.4" + resolved "https://registry.yarnpkg.com/@json-rpc-tools/utils/-/utils-1.6.4.tgz#92d1d12944326150c0ab26d248c710ea3bb2c36e" + integrity sha512-4XA8lXUyOjFs9hcJQJwbpc+Yt+AenCttsAq6HFRPd0nXwNbVsY6h+tVWVRyQj4oi/m3NkOfROOff0MN7VX1mfg== + dependencies: + "@json-rpc-tools/types" "^1.6.4" + "@ledgerhq/devices@^4.64.0": version "4.64.0" resolved "https://registry.yarnpkg.com/@ledgerhq/devices/-/devices-4.64.0.tgz#4412f81338f5495f179017e5101273c3f0edaddf" @@ -5370,41 +5394,40 @@ version "1.0.0" resolved "https://github.com/umpirsky/country-list#05fda51cd97b3294e8175ffed06104c44b3c71d7" -"@walletconnect/client@2.0.0-alpha.26": - version "2.0.0-alpha.26" - resolved "https://registry.yarnpkg.com/@walletconnect/client/-/client-2.0.0-alpha.26.tgz#072116519656f7d3dc035ada589b9ecb5c695b72" - integrity sha512-IQxmaNjRbcJ12SXZpBs5IRv1Q7MMcP/Kl5ST4sdLKmZEiTOaEYMPPhqhSZ/sxOs8uAQhEjZ/25NWUrjZZnTSOg== +"@walletconnect/client@2.0.0-alpha.32": + version "2.0.0-alpha.32" + resolved "https://registry.yarnpkg.com/@walletconnect/client/-/client-2.0.0-alpha.32.tgz#9645dd9b6f204468e25ebd85f50c308093cc52e3" + integrity sha512-lf3o/rM/B73a6mJ5z3RQOvJN5MckpClts1F4UlpS3xU0C6iKlzVFI3bp9wWdzT+fMUv9Ls3EtEga7Y8PmFaecQ== dependencies: - "@json-rpc-tools/provider" "^1.6.3" - "@json-rpc-tools/utils" "^1.6.3" + "@json-rpc-tools/provider" "^1.6.4" + "@json-rpc-tools/utils" "^1.6.4" "@pedrouid/pino-utils" "^1.0.1" - "@walletconnect/types" "^2.0.0-alpha.26" - "@walletconnect/utils" "^2.0.0-alpha.26" + "@walletconnect/types" "^2.0.0-alpha.32" + "@walletconnect/utils" "^2.0.0-alpha.32" enc-utils "^3.0.0" keyvaluestorage "^0.7.1" pino "^6.7.0" pino-pretty "^4.3.0" - relay-provider "^1.2.0" + relay-provider "^1.2.1" safe-json-utils "^1.1.1" -"@walletconnect/types@^2.0.0-alpha.26": - version "2.0.0-alpha.26" - resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.0.0-alpha.26.tgz#83eee3e94bebfeabba95d1b910a93302d03a8a68" - integrity sha512-yoPVloExCgqbOUD3DbMhNnTfQPNY+cdDVrn6U3fCMRQ1PSNZyfuLNh769kQNodHfTEkfGyQyX9oJ9t3p2xJcUA== +"@walletconnect/types@^2.0.0-alpha.32": + version "2.0.0-alpha.32" + resolved "https://registry.yarnpkg.com/@walletconnect/types/-/types-2.0.0-alpha.32.tgz#05f6f641f369abc2db099f5560f958be5e047901" + integrity sha512-m8lsJIJEVbpGYbnjC6qkseB0HsN2go4dJIfaDw2jjTtKIGEvBlkKFEPWcUbmUdAjUWhdyFgHCotq4hmBCcDIbA== dependencies: - "@json-rpc-tools/types" "^1.6.3" + "@json-rpc-tools/types" "^1.6.4" keyvaluestorage "^0.7.1" pino "^6.7.0" pino-pretty "^4.3.0" -"@walletconnect/utils@^2.0.0-alpha.26": - version "2.0.0-alpha.26" - resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.0.0-alpha.26.tgz#88429c5e9c0557a36604e5311a138e28b54ecb16" - integrity sha512-K5OjZiFspHmGt8JXf07ZGaxwrJzI+AJ5//bt7KGVA6bmFAAs9syGmbaT/hX7eMK8JVCb+Fbjn0JalSKRQyEtlQ== +"@walletconnect/utils@^2.0.0-alpha.32": + version "2.0.0-alpha.32" + resolved "https://registry.yarnpkg.com/@walletconnect/utils/-/utils-2.0.0-alpha.32.tgz#feceffd467f24530208938c5f8b0b24004fbe1ad" + integrity sha512-6P/qsd4X3kXn+Yrq8Pk05xBHXv4zSI3tpK3KaXjJizzYUT+k/VgwLCXikyuOoVhcBOPBREAMurVzCsmtbP9DRw== dependencies: - "@json-rpc-tools/utils" "^1.6.3" - "@walletconnect/types" "^2.0.0-alpha.26" - detect-browser "^5.1.0" + "@json-rpc-tools/utils" "^1.6.4" + "@walletconnect/types" "^2.0.0-alpha.32" ecies-25519 "^1.3.0" enc-utils "^3.0.0" query-string "^6.13.5" @@ -9959,11 +9982,6 @@ destroy@^1.0.4, destroy@~1.0.4: resolved "https://registry.yarnpkg.com/destroy/-/destroy-1.0.4.tgz#978857442c44749e4206613e37946205826abd80" integrity sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA= -detect-browser@^5.1.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/detect-browser/-/detect-browser-5.2.0.tgz#c9cd5afa96a6a19fda0bbe9e9be48a6b6e1e9c97" - integrity sha512-tr7XntDAu50BVENgQfajMLzacmSe34D+qZc4zjnniz0ZVuw/TZcLcyxHQjYpJTM36sGEkZZlYLnIM1hH7alTMA== - detect-file@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/detect-file/-/detect-file-0.1.0.tgz#4935dedfd9488648e006b0129566e9386711ea63" @@ -21977,10 +21995,10 @@ relative@^3.0.1: dependencies: isobject "^2.0.0" -relay-provider@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/relay-provider/-/relay-provider-1.2.0.tgz#9de740ab48f1deba29fa26f73559adb14b95da70" - integrity sha512-BCtRgrPO6Am5hbMXEcdltq1+DTtvNjvG7HjGVT4Fd1qDU96bctgXf2PAkGq1Yn1OGlcgOa6jaxAQzB9J043CtQ== +relay-provider@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/relay-provider/-/relay-provider-1.2.1.tgz#b4191899dbb871b06a74e7d8995d7749e1f7dc09" + integrity sha512-N3p05r57sHk76qfiNiSflDY83LigmbfaAnFEno9smCz30CgA61IJLfoqLr1+qQSdIEqvy1Jflcs2lLmpzBOYKA== dependencies: "@json-rpc-tools/provider" "^1.4.0" "@json-rpc-tools/utils" "^1.4.0"