-
Notifications
You must be signed in to change notification settings - Fork 24
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
Add additional wallets to a client #383
Changes from 8 commits
38931cd
84418c0
53383cc
1375f13
da6bf1e
99bf8fc
3ac131e
8077be1
b6ceda0
460f899
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ import LibXMTP | |
public protocol SigningKey { | ||
/// A wallet address for this key | ||
var address: String { get } | ||
|
||
/// If this signing key is a smart contract wallet | ||
var isSmartContractWallet: Bool { get } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also pass a chainId |
||
|
||
/// Sign the data and return a secp256k1 compact recoverable signature. | ||
func sign(_ data: Data) async throws -> Signature | ||
|
@@ -29,6 +32,10 @@ public protocol SigningKey { | |
} | ||
|
||
extension SigningKey { | ||
public var isSmartContractWallet: Bool { | ||
return false | ||
} | ||
|
||
func createIdentity(_ identity: PrivateKey, preCreateIdentityCallback: PreEventCallback? = nil) async throws -> AuthorizedIdentity { | ||
var slimKey = PublicKey() | ||
slimKey.timestamp = UInt64(Date().millisecondsSinceEpoch) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -455,4 +455,80 @@ class ClientTests: XCTestCase { | |
|
||
XCTAssertEqual(inboxId, alixClient.inboxID) | ||
} | ||
|
||
func testAddAdditionalEOAWallets() async throws { | ||
let key = try Crypto.secureRandomBytes(count: 32) | ||
let alixWallet1 = try PrivateKey.generate() | ||
let alix = try await Client.create( | ||
account: alixWallet1, | ||
options: .init( | ||
api: .init(env: .local, isSecure: false), | ||
enableV3: true, | ||
encryptionKey: key | ||
) | ||
) | ||
|
||
let group = try await alix.conversations.newGroup(with: []) | ||
try await group.sync() | ||
XCTAssertEqual(try group.members[0].addresses.count, 1) | ||
|
||
let alixWallet2 = try PrivateKey.generate() | ||
try await alix.addWallet(account: alixWallet2) | ||
try await group.sync() | ||
XCTAssertEqual(try group.members[0].addresses.count, 2) | ||
} | ||
|
||
func testAddAdditionalSCWWallets() async throws { | ||
let key = try Crypto.secureRandomBytes(count: 32) | ||
let alixWallet1 = try PrivateKey.generate() | ||
let alix = try await Client.create( | ||
account: alixWallet1, | ||
options: .init( | ||
api: .init(env: .local, isSecure: false), | ||
enableV3: true, | ||
encryptionKey: key, | ||
chainRPCUrl: "https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID" | ||
) | ||
) | ||
let group = try await alix.conversations.newGroup(with: []) | ||
try await group.sync() | ||
XCTAssertEqual(try group.members[0].addresses.count, 1) | ||
|
||
let alixWallet2 = try FakeSCWWallet.generate() | ||
try await alix.addWallet(account: alixWallet2) | ||
try await group.sync() | ||
XCTAssertEqual(try group.members[0].addresses.count, 2) | ||
} | ||
|
||
public struct FakeSCWWallet: SigningKey { | ||
public static func generate() throws -> FakeWallet { | ||
let key = try PrivateKey.generate() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if there is something simple like this for generating a test SCW... seems unlikely. But I can atleast test the account format and isSmartContractWallet. |
||
return FakeWallet(key) | ||
} | ||
|
||
public var address: String { | ||
"eip155:1:\(key.walletAddress)" | ||
} | ||
|
||
public var isSmartContractWallet: Bool { | ||
true | ||
} | ||
|
||
public func sign(_ data: Data) async throws -> XMTPiOS.Signature { | ||
let signature = try await key.sign(data) | ||
return signature | ||
} | ||
|
||
public func sign(message: String) async throws -> XMTPiOS.Signature { | ||
let signature = try await key.sign(message: message) | ||
return signature | ||
} | ||
|
||
public var key: PrivateKey | ||
|
||
public init(_ key: PrivateKey) { | ||
self.key = key | ||
} | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After adding the wallet to their identity what benefits do they get/ how can the interact with the wallet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would allow someone else to enter any one of the added wallet addresses and reach the same inbox.
And for an app that has access to any of the added wallets to create a new installation for that inbox.