Skip to content

Commit

Permalink
better keychain docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ypopovych committed Jul 4, 2023
1 parent d9f09b8 commit a22597d
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ let isSigned = derived.verify(message: data, signature: signature)
```

#### Keychain
In-memory storage for multiple KeyPairs (multi-account support).

##### Initialization and base API
```swift
// Not needed for CocoaPods
import SubstrateKeychain
Expand All @@ -292,19 +295,21 @@ let keyPair = keychain.keyPair(for: pubKey)!
```

##### Api Signer integration
Keychain can be set as `Signer` for `Api` instance for simpler account management and signing.

```swift
// Update substrate signer to created keychain instance
// Set substrate signer to created keychain instance
substrate.signer = keychain

// Fetch account from Keychain (it will call Keychain delegate for selection)
let from = try await substrate.tx.account()

// Keychain will return PublicKey
// Signer will return PublicKey from Keychain
// which should be converted to account or address for extrinsics
print("Account: \(try from.account(in: substrate))")

// We can provide this PublicKey as account for signing.
// Signing call will be sent to Keychain
// We can provide this PublicKey as `account` to calls for signing.
// Signing call will be sent to Keychain through Signer protocol
let events = try await tx.signSendAndWatch(account: from)
.waitForFinalized()
.success()
Expand All @@ -314,9 +319,9 @@ print("Events: \(try events.parsed())")
```

##### Keychain Delegate
Keychain has delegate object which can select public keys for the Signer protocol. It can be used to show UI with account selecter to the user.
Keychain has delegate object which can select public keys for the Signer protocol. It can be used to show UI with account selecter to the user or implement custom logic.

There is default `KeychainDelegateFirstFound` implementation which returns first found compatible key from Keychain.
There is default `KeychainDelegateFirstFound` implementation which returns first found compatible key from the Keychain.

Protocol looks like this:
```swift
Expand Down

0 comments on commit a22597d

Please sign in to comment.