Skip to content

Commit

Permalink
Merge 6985f04 into a4a55dc
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Lisovik authored Apr 13, 2023
2 parents a4a55dc + 6985f04 commit aa14f5a
Show file tree
Hide file tree
Showing 28 changed files with 1,447 additions and 201 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: ci

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

Expand Down
4 changes: 4 additions & 0 deletions Example/ExampleApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
84E6B86329816A7900428BAF /* WalletConnectPush in Frameworks */ = {isa = PBXBuildFile; productRef = 84E6B86229816A7900428BAF /* WalletConnectPush */; };
84E6B8652981720400428BAF /* WalletConnectPush in Frameworks */ = {isa = PBXBuildFile; productRef = 84E6B8642981720400428BAF /* WalletConnectPush */; };
84FE684628ACDB4700C893FF /* RequestParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84FE684528ACDB4700C893FF /* RequestParams.swift */; };
A507BE1A29E8032E0038EF70 /* EIP55Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A507BE1929E8032E0038EF70 /* EIP55Tests.swift */; };
A50C036528AAD32200FE72D3 /* ClientDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50C036428AAD32200FE72D3 /* ClientDelegate.swift */; };
A50F3946288005B200064555 /* Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = A50F3945288005B200064555 /* Types.swift */; };
A518A98729683FB60035247E /* Web3InboxViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A518A98429683FB60035247E /* Web3InboxViewController.swift */; };
Expand Down Expand Up @@ -365,6 +366,7 @@
84F568C1279582D200D0A289 /* Signer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Signer.swift; sourceTree = "<group>"; };
84F568C32795832A00D0A289 /* EthereumTransaction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EthereumTransaction.swift; sourceTree = "<group>"; };
84FE684528ACDB4700C893FF /* RequestParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RequestParams.swift; sourceTree = "<group>"; };
A507BE1929E8032E0038EF70 /* EIP55Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EIP55Tests.swift; sourceTree = "<group>"; };
A50C036428AAD32200FE72D3 /* ClientDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ClientDelegate.swift; sourceTree = "<group>"; };
A50F3945288005B200064555 /* Types.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Types.swift; sourceTree = "<group>"; };
A518A98429683FB60035247E /* Web3InboxViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Web3InboxViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -866,6 +868,7 @@
A541959D2934BFEF0035AD19 /* EIP191VerifierTests.swift */,
A541959C2934BFEF0035AD19 /* EIP1271VerifierTests.swift */,
A541959B2934BFEF0035AD19 /* SignerTests.swift */,
A507BE1929E8032E0038EF70 /* EIP55Tests.swift */,
);
path = Signer;
sourceTree = "<group>";
Expand Down Expand Up @@ -2024,6 +2027,7 @@
84AA01DB28CF0CD7005D48D8 /* XCTest.swift in Sources */,
A5E03E1128646F8000888481 /* KeychainStorageMock.swift in Sources */,
A5E03DFD286465D100888481 /* Stubs.swift in Sources */,
A507BE1A29E8032E0038EF70 /* EIP55Tests.swift in Sources */,
A5A8E47A293A1C9B00FEB97D /* DefaultSocketFactory.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
37 changes: 37 additions & 0 deletions Example/IntegrationTests/Auth/Signer/EIP55Tests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import Foundation
import XCTest
@testable import WalletConnectSigner

class EIP55Tests: XCTestCase {

private let eip55 = EIP55(crypto: DefaultCryptoProvider())

func testEIP55EncodingAllCaps() {
let string1 = "0x52908400098527886E0F7030069857D2E4169EE7"
let string2 = "0x8617E340B3D01FA5F11F306F4090FD50E238070D"

XCTAssertEqual(eip55.encode(string1), "0x52908400098527886E0F7030069857D2E4169EE7")
XCTAssertEqual(eip55.encode(string2), "0x8617E340B3D01FA5F11F306F4090FD50E238070D")
}

func testEIP55EncodingAllLower() {
let string1 = "0x27b1fdb04752bbc536007a920d24acb045561c26"
let string2 = "0xde709f2102306220921060314715629080e2fb77"

XCTAssertEqual(eip55.encode(string1), "0x27b1fdb04752bbc536007a920d24acb045561c26")
XCTAssertEqual(eip55.encode(string2), "0xde709f2102306220921060314715629080e2fb77")
}

func testEIP55EncodingNormal() {
let string1 = "0x5aaeb6053f3e94c9b9a09f33669435e7ef1beaed"
let string2 = "0xfb6916095ca1df60bb79ce92ce3ea74c37c5d359"
let string3 = "0xdbf03b407c01e7cd3cbea99509d93f8dddc8c6fb"
let string4 = "0xd1220a0cf47c7b9be7a2e6ba89f429762e7b9adb"

XCTAssertEqual(eip55.encode(string1), "0x5aAeb6053F3E94C9b9A09f33669435E7Ef1BeAed")
XCTAssertEqual(eip55.encode(string2), "0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359")
XCTAssertEqual(eip55.encode(string3), "0xdbF03B407c01E7cD3CBea99509d93f8DDDC8C6FB")
XCTAssertEqual(eip55.encode(string4), "0xD1220A0cf47c7B9Be7A2E6BA89F429762e7b9aDb")
}

}
2 changes: 1 addition & 1 deletion Example/IntegrationTests/Auth/Signer/SignerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ class SignerTest: XCTestCase {
func testSignerAddressFromAccount() throws {
let account = Account("eip155:1:0xBAc675C310721717Cd4A37F6cbeA1F081b1C2a07")!

XCTAssertEqual(DIDPKH(account: account).string, "did:pkh:eip155:1:0xbac675c310721717cd4a37f6cbea1f081b1c2a07")
XCTAssertEqual(DIDPKH(account: account).string, "did:pkh:eip155:1:0xBAc675C310721717Cd4A37F6cbeA1F081b1C2a07")
}
}
222 changes: 139 additions & 83 deletions Example/IntegrationTests/Sign/SignClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ final class SignClientTests: XCTestCase {
events: ["any"]
),
"eip155": ProposalNamespace(
chains: [Blockchain("eip155:137")!],
chains: [Blockchain("eip155:137")!, Blockchain("eip155:1")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
)
Expand All @@ -427,30 +427,33 @@ final class SignClientTests: XCTestCase {
)
]

let sessionNamespaces: [String: SessionNamespace] = [
"eip155:1": SessionNamespace(
accounts: [Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
"eip155": SessionNamespace(
chains: [Blockchain("eip155:137")!],
accounts: [Account(blockchain: Blockchain("eip155:137")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
"eip155:5": SessionNamespace(
accounts: [Account(blockchain: Blockchain("eip155:5")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
"solana": SessionNamespace(
chains: [Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!],
accounts: [Account(blockchain: Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!, address: "0x00")!],
methods: ["solana_signMessage"],
events: ["any"]
)
]
let sessionProposal = Session.Proposal(
id: "",
pairingTopic: "",
proposer: AppMetadata(name: "", description: "", url: "", icons: []),
requiredNamespaces: requiredNamespaces,
optionalNamespaces: optionalNamespaces,
sessionProperties: nil,
proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:])
)

let sessionNamespaces = try AutoNamespaces.build(
sessionProposal: sessionProposal,
chains: [
Blockchain("eip155:137")!,
Blockchain("eip155:1")!,
Blockchain("eip155:5")!,
Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!
],
methods: ["personal_sign", "eth_sendTransaction", "solana_signMessage"],
events: ["any"],
accounts: [
Account(blockchain: Blockchain("solana:4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!, address: "4sGjMW1sUnHzSxGspuhpqLDx6wiyjNtZ")!,
Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!,
Account(blockchain: Blockchain("eip155:137")!, address: "0x00")!,
Account(blockchain: Blockchain("eip155:5")!, address: "0x00")!
]
)

wallet.onSessionProposal = { [unowned self] proposal in
Task(priority: .high) {
Expand Down Expand Up @@ -496,19 +499,29 @@ final class SignClientTests: XCTestCase {
)
]

let sessionNamespaces: [String: SessionNamespace] = [
"eip155:1": SessionNamespace(
accounts: [Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
"eip155": SessionNamespace(
chains: [Blockchain("eip155:137")!],
accounts: [Account(blockchain: Blockchain("eip155:137")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
]
let sessionProposal = Session.Proposal(
id: "",
pairingTopic: "",
proposer: AppMetadata(name: "", description: "", url: "", icons: []),
requiredNamespaces: requiredNamespaces,
optionalNamespaces: optionalNamespaces,
sessionProperties: nil,
proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:])
)

let sessionNamespaces = try AutoNamespaces.build(
sessionProposal: sessionProposal,
chains: [
Blockchain("eip155:137")!,
Blockchain("eip155:1")!
],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"],
accounts: [
Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!,
Account(blockchain: Blockchain("eip155:137")!, address: "0x00")!
]
)

wallet.onSessionProposal = { [unowned self] proposal in
Task(priority: .high) {
Expand Down Expand Up @@ -544,18 +557,29 @@ final class SignClientTests: XCTestCase {
)
]

let sessionNamespaces: [String: SessionNamespace] = [
"eip155:5": SessionNamespace(
accounts: [Account(blockchain: Blockchain("eip155:5")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
"eip155:1": SessionNamespace(
accounts: [Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
)
]
let sessionProposal = Session.Proposal(
id: "",
pairingTopic: "",
proposer: AppMetadata(name: "", description: "", url: "", icons: []),
requiredNamespaces: requiredNamespaces,
optionalNamespaces: optionalNamespaces,
sessionProperties: nil,
proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:])
)

let sessionNamespaces = try AutoNamespaces.build(
sessionProposal: sessionProposal,
chains: [
Blockchain("eip155:1")!,
Blockchain("eip155:5")!
],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"],
accounts: [
Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!,
Account(blockchain: Blockchain("eip155:5")!, address: "0x00")!
]
)

wallet.onSessionProposal = { [unowned self] proposal in
Task(priority: .high) {
Expand Down Expand Up @@ -599,22 +623,40 @@ final class SignClientTests: XCTestCase {
)
]

let sessionNamespaces: [String: SessionNamespace] = [
"eip155:1": SessionNamespace(
accounts: [Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
]
let sessionProposal = Session.Proposal(
id: "",
pairingTopic: "",
proposer: AppMetadata(name: "", description: "", url: "", icons: []),
requiredNamespaces: requiredNamespaces,
optionalNamespaces: optionalNamespaces,
sessionProperties: nil,
proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:])
)

wallet.onSessionProposal = { [unowned self] proposal in
Task(priority: .high) {
do {
try await wallet.client.approve(proposalId: proposal.id, namespaces: sessionNamespaces)
} catch {
settlementFailedExpectation.fulfill()
do {
let sessionNamespaces = try AutoNamespaces.build(
sessionProposal: sessionProposal,
chains: [
Blockchain("eip155:1")!
],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"],
accounts: [
Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!
]
)

wallet.onSessionProposal = { [unowned self] proposal in
Task(priority: .high) {
do {
try await wallet.client.approve(proposalId: proposal.id, namespaces: sessionNamespaces)
} catch {
settlementFailedExpectation.fulfill()
}
}
}
} catch {
settlementFailedExpectation.fulfill()
}

let uri = try await dapp.client.connect(requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces)
Expand Down Expand Up @@ -644,32 +686,46 @@ final class SignClientTests: XCTestCase {
)
]

let sessionNamespaces: [String: SessionNamespace] = [
"eip155:1": SessionNamespace(
accounts: [Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!],
methods: ["personal_sign"],
events: ["any"]
),
"eip155": SessionNamespace(
chains: [Blockchain("eip155:137")!],
accounts: [Account(blockchain: Blockchain("eip155:137")!, address: "0x00")!],
methods: ["personal_sign", "eth_sendTransaction"],
events: ["any"]
),
]
let sessionProposal = Session.Proposal(
id: "",
pairingTopic: "",
proposer: AppMetadata(name: "", description: "", url: "", icons: []),
requiredNamespaces: requiredNamespaces,
optionalNamespaces: optionalNamespaces,
sessionProperties: nil,
proposal: SessionProposal(relays: [], proposer: Participant(publicKey: "", metadata: AppMetadata(name: "", description: "", url: "", icons: [])), requiredNamespaces: [:], optionalNamespaces: [:], sessionProperties: [:])
)

wallet.onSessionProposal = { [unowned self] proposal in
Task(priority: .high) {
do {
try await wallet.client.approve(proposalId: proposal.id, namespaces: sessionNamespaces)
} catch {
settlementFailedExpectation.fulfill()
do {
let sessionNamespaces = try AutoNamespaces.build(
sessionProposal: sessionProposal,
chains: [
Blockchain("eip155:1")!,
Blockchain("eip155:137")!
],
methods: ["personal_sign"],
events: ["any"],
accounts: [
Account(blockchain: Blockchain("eip155:1")!, address: "0x00")!,
Account(blockchain: Blockchain("eip155:137")!, address: "0x00")!
]
)

wallet.onSessionProposal = { [unowned self] proposal in
Task(priority: .high) {
do {
try await wallet.client.approve(proposalId: proposal.id, namespaces: sessionNamespaces)
} catch {
settlementFailedExpectation.fulfill()
}
}
}
} catch {
settlementFailedExpectation.fulfill()
}

let uri = try await dapp.client.connect(requiredNamespaces: requiredNamespaces, optionalNamespaces: optionalNamespaces)
try await wallet.client.pair(uri: uri!)
wait(for: [settlementFailedExpectation], timeout: InputConfig.defaultTimeout)
wait(for: [settlementFailedExpectation], timeout: 1)
}
}
Loading

0 comments on commit aa14f5a

Please sign in to comment.