Repository navigation
Read quorum signers on wallets #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tomas-martins-crossmint
wants to merge
8
commits into
main
from
tomas/wal-13105-swift-quorum-signers-on-wallets
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dcbc35d
Read quorum signers on wallets
tomas-martins-crossmint d92cc5d
Build the default signer from a recovery method that is not a quorum
tomas-martins-crossmint 96c8e47
Keep the quorum response model internal
tomas-martins-crossmint 1fee0dc
Drop the repeated threshold doc on QuorumSignerData
tomas-martins-crossmint c8315ff
Read quorum test results from the public recovery methods
tomas-martins-crossmint 0ad1e74
Rewrite the quorum signer docs for app developers
tomas-martins-crossmint d526187
Merge remote-tracking branch 'origin/main' into tomas/wal-13105-swift…
tomas-martins-crossmint 470163a
Merge origin/main into tomas/wal-13105-swift-quorum-signers-on-wallets
tomas-martins-crossmint File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
Sources/Wallet/Data/GetWallet/Response/QuorumSignerApiModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // | ||
| // QuorumSignerApiModel.swift | ||
| // CrossmintSDK | ||
| // | ||
| // Created by Tomas Martins on 16/10/26. | ||
| // | ||
|
|
||
| import CrossmintCommonTypes | ||
| import Logger | ||
|
|
||
| struct QuorumSignerApiModel: AdminSignerApiModel { | ||
| let type: AdminSignerDataType | ||
| let locator: String | ||
| let threshold: Int | ||
| let members: [any AdminSignerApiModel] | ||
|
|
||
| var toDomain: any AdminSignerData { | ||
| QuorumSignerData( | ||
| id: String(locator.dropFirst("quorum:".count)), | ||
| threshold: threshold, | ||
| members: members.map(\.toDomain) | ||
| ) | ||
| } | ||
|
|
||
| private enum CodingKeys: String, CodingKey { | ||
| case type, locator, threshold, members | ||
| } | ||
|
|
||
| init(from decoder: Decoder) throws { | ||
| let container = try decoder.container(keyedBy: CodingKeys.self) | ||
| type = try container.decode(AdminSignerDataType.self, forKey: .type) | ||
| locator = try container.decode(String.self, forKey: .locator) | ||
| threshold = try container.decode(Int.self, forKey: .threshold) | ||
|
|
||
| var list = try container.nestedUnkeyedContainer(forKey: .members) | ||
| var members: [any AdminSignerApiModel] = [] | ||
| while !list.isAtEnd { | ||
| let entry = try list.superDecoder() | ||
| let rawType = try WalletConfigApiModel.rawSignerType(from: entry) | ||
| guard let memberType = AdminSignerDataType(rawValue: rawType), memberType != .quorum else { | ||
| Logger.smartWallet.warning(LogEvents.walletConfigQuorumMemberSkipped, attributes: [ | ||
| "quorum": locator, | ||
| "type": rawType | ||
| ]) | ||
| continue | ||
| } | ||
| members.append(try WalletConfigApiModel.decodeSigner(from: entry)) | ||
| } | ||
| self.members = members | ||
| } | ||
|
|
||
| func encode(to encoder: Encoder) throws { | ||
| var container = encoder.container(keyedBy: CodingKeys.self) | ||
| try container.encode(type, forKey: .type) | ||
| try container.encode(locator, forKey: .locator) | ||
| try container.encode(threshold, forKey: .threshold) | ||
| var list = container.nestedUnkeyedContainer(forKey: .members) | ||
| for member in members { | ||
| try list.encode(member) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // | ||
| // WalletQuorumSignerTests.swift | ||
| // CrossmintSDK | ||
| // | ||
| // Created by Tomas Martins on 16/10/26. | ||
| // | ||
|
|
||
| import CrossmintCommonTypes | ||
| import Foundation | ||
| import Testing | ||
| import TestsUtils | ||
|
|
||
| @testable import Wallet | ||
|
|
||
| private let QUORUM_ID = "9f2c6a1e-4b7d-4c3a-9e51-2d8f0b6c7a14" | ||
|
|
||
| @Suite("Wallet with a quorum signer", .tags(.unit)) | ||
| struct WalletQuorumSignerTests { | ||
| private func makeStellarWallet() throws -> StellarWallet { | ||
| let baseModel: WalletApiModel = try GetFromFile.getModelFrom( | ||
| fileName: "WalletStellarQuorum", | ||
| bundle: Bundle.module | ||
| ) | ||
| return try StellarWallet( | ||
| smartWalletService: MockSmartWalletService(), | ||
| signer: nil, | ||
| baseModel: baseModel, | ||
| stellarChain: .stellar | ||
| ) | ||
| } | ||
|
|
||
| @Test func loadsAWalletWhoseOnlyRecoveryMethodIsAQuorum() throws { | ||
| let wallet = try makeStellarWallet() | ||
|
|
||
| let method = try #require(wallet.recoveryMethods.first) | ||
| let quorum = try #require(method.signer as? QuorumSignerData) | ||
|
|
||
| #expect(wallet.recoveryMethods.count == 1) | ||
| #expect(quorum.locator == "quorum:\(QUORUM_ID)") | ||
| #expect(quorum.threshold == 2) | ||
| #expect(method.status == .active) | ||
| } | ||
|
|
||
| @Test func keepsTheSupportedMembersInOrder() throws { | ||
| let wallet = try makeStellarWallet() | ||
|
|
||
| let quorum = try #require(wallet.recoveryMethods.first?.signer as? QuorumSignerData) | ||
|
|
||
| #expect(quorum.members.map(\.locator) == [ | ||
| "email:alice@example.com", | ||
| "email:bob@example.com", | ||
| "phone:+14155552671" | ||
| ]) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| { | ||
| "type": "smart", | ||
| "chainType": "stellar", | ||
| "config": { | ||
| "adminSigner": { | ||
| "type": "quorum", | ||
| "locator": "quorum:9f2c6a1e-4b7d-4c3a-9e51-2d8f0b6c7a14", | ||
| "threshold": 2, | ||
| "members": [ | ||
| { "type": "email", "email": "alice@example.com", "locator": "email:alice@example.com" }, | ||
| { "type": "email", "email": "bob@example.com", "locator": "email:bob@example.com" }, | ||
| { "type": "phone", "phone": "+14155552671", "locator": "phone:+14155552671" } | ||
| ] | ||
| }, | ||
| "recoveryMethods": [ | ||
| { | ||
| "type": "quorum", | ||
| "locator": "quorum:9f2c6a1e-4b7d-4c3a-9e51-2d8f0b6c7a14", | ||
| "threshold": 2, | ||
| "status": "active", | ||
| "members": [ | ||
| { "type": "email", "email": "alice@example.com", "locator": "email:alice@example.com" }, | ||
| { "type": "email", "email": "bob@example.com", "locator": "email:bob@example.com" }, | ||
| { "type": "totp", "locator": "totp:x" }, | ||
| { "type": "phone", "phone": "+14155552671", "locator": "phone:+14155552671" } | ||
| ] | ||
| } | ||
| ], | ||
| "delegatedSigners": [ | ||
| { | ||
| "type": "quorum", | ||
| "locator": "quorum:0b8e7d6c-5a4f-4e3d-8c2b-1a0f9e8d7c6b", | ||
| "threshold": 2, | ||
| "members": [ | ||
| { "type": "email", "email": "carol@example.com", "locator": "email:carol@example.com" }, | ||
| { "type": "email", "email": "dave@example.com", "locator": "email:dave@example.com" } | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| "address": "CA3SGE76PWYAM4OVKETY47GASUGYDF3Y3QFFSPIWFCNKQLUOO4SOIT2W", | ||
| "linkedUser": "email:alice@example.com", | ||
| "createdAt": "2026-10-16T10:00:00.000Z" | ||
| } |
35 changes: 35 additions & 0 deletions
35
Tests/WalletTests/Resources/WalletStellarQuorumThenEmail.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| { | ||
| "type": "smart", | ||
| "chainType": "stellar", | ||
| "config": { | ||
| "adminSigner": { | ||
| "type": "quorum", | ||
| "locator": "quorum:9f2c6a1e-4b7d-4c3a-9e51-2d8f0b6c7a14", | ||
| "threshold": 2, | ||
| "members": [ | ||
| { "type": "email", "email": "alice@example.com", "locator": "email:alice@example.com" }, | ||
| { "type": "email", "email": "bob@example.com", "locator": "email:bob@example.com" } | ||
| ] | ||
| }, | ||
| "recoveryMethods": [ | ||
| { | ||
| "type": "quorum", | ||
| "locator": "quorum:9f2c6a1e-4b7d-4c3a-9e51-2d8f0b6c7a14", | ||
| "threshold": 2, | ||
| "members": [ | ||
| { "type": "email", "email": "alice@example.com", "locator": "email:alice@example.com" }, | ||
| { "type": "email", "email": "bob@example.com", "locator": "email:bob@example.com" } | ||
| ] | ||
| }, | ||
| { | ||
| "type": "email", | ||
| "email": "carol@example.com", | ||
| "locator": "email:carol@example.com" | ||
| } | ||
| ], | ||
| "delegatedSigners": [] | ||
| }, | ||
| "address": "CA3SGE76PWYAM4OVKETY47GASUGYDF3Y3QFFSPIWFCNKQLUOO4SOIT2W", | ||
| "linkedUser": "email:carol@example.com", | ||
| "createdAt": "2026-10-16T10:00:00.000Z" | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.