WalletConnect / WalletConnectSwiftV2

WalletConnect Swift SDK v2
https://docs.walletconnect.com
Apache License 2.0
301 stars 159 forks source link

Either expose DefaultCryptoProvider or update your documentation #1174

Open muratogat opened 11 months ago

muratogat commented 11 months ago

Currently during the initialization of the SDK, it is not possible to "just call a configure method" as claimed here, because the DefaultCryptoProvider is not exposed as discussed here.

Either expose DefaultCryptoProvider such that it can be somehow imported even if the package is added through SPM, or alternatively update your documentation such that is clearly explains that developers are expected to implement a crypto provider by themselves to be passed to the Web3Wallet configuration as a parameter.

flypaper0 commented 11 months ago

Thanks for response. Different clients uses different crypto libraries. So we cannot depends on Web3.swift or CryptoSwift in our SDK. But It's a good call to update our integration docs if it's no clear for developers

flypaper0 commented 11 months ago

cc @alexander-lsvk

simonmcl commented 5 months ago

Just ran into this issue as well while updating. Its not clear what this is for or how I should implement it. I'm not using an Ethereum chain, but the CryptoProvider protocol requires me to implement a func that takes an EthereumSignature as a parameter

simonmcl commented 5 months ago

Please also note that most of the links in the swift repos README are pointing to dead links

muratogat commented 5 months ago

@simonmcl here is my implementation

struct WC2CryptoProvider: CryptoProvider {
    public func recoverPubKey(signature: EthereumSignature, message: Data) throws -> Data {
        return SECP256K1.recoverPublicKey(hash: message, signature: signature.serialized)!
    }

    public func keccak256(_ data: Data) -> Data {
        return data.sha3(.keccak256)
    }
}

EthereumSignature is part of the WalletConnect SDK. You don't need to create or implement it. Depending on the libraries you use, you may not have access to those methods above, but the idea should be clear.

simonmcl commented 5 months ago

@muratogat thanks for the help. Can you link me to the lib you are using for this:

SECP256K1.recoverPublicKey(hash: message, signature: signature.serialized)!
muratogat commented 5 months ago

This is the file in web3swift, which I forked, where the functionality is.

https://github.com/muratogat/web3swift/blob/develop/Sources/web3swift/Convenience/SECP256k1.swift

However, this is in the background importing the base secp256k1 library (import secp256k1 at the top), which is linked as a static library in web3swift (https://github.com/muratogat/web3swift/tree/develop/Sources/secp256k1). Not sure how it would work for you.