WalletConnectSwiftV2 icon indicating copy to clipboard operation
WalletConnectSwiftV2 copied to clipboard

Either expose DefaultCryptoProvider or update your documentation

Open muratogat opened this issue 1 year ago • 7 comments

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.

muratogat avatar Oct 11 '23 08:10 muratogat

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 avatar Oct 12 '23 15:10 flypaper0

cc @alexander-lsvk

flypaper0 avatar Oct 12 '23 15:10 flypaper0

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 avatar Apr 12 '24 10:04 simonmcl

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

simonmcl avatar Apr 12 '24 10:04 simonmcl

@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.

muratogat avatar Apr 12 '24 11:04 muratogat

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

SECP256K1.recoverPublicKey(hash: message, signature: signature.serialized)!

simonmcl avatar Apr 12 '24 11:04 simonmcl

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.

muratogat avatar Apr 12 '24 13:04 muratogat