Skip to content

Commit b179873

Browse files
peetzwegcarlosala
andauthored
feat: improve signers section (#19)
Co-authored-by: Carlo Sala <[email protected]>
1 parent 6d59f10 commit b179873

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

docs/pages/getting-started.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int
5858

5959
// [!include ~/snippets/gettingStarted.ts:usage]
6060
```
61+
6162
</Tabs.Content>
6263
<Tabs.Content value="snmw">
6364
```ts
@@ -85,6 +86,7 @@ Now you can create a PolkadotClient with a provider of your choice and start int
8586

8687
// [!include ~/snippets/gettingStarted.ts:usage]
8788
```
89+
8890
</Tabs.Content>
8991
<Tabs.Content value="sm">
9092
```ts

docs/pages/recipes/upgrade.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function performTransfer() {
4141
// check if we're running on the next version to run that first
4242
if (
4343
await nextApi.tx.Balances.new_fancy_transfer.isCompatible(
44-
CompatibilityLevel.Partial
44+
CompatibilityLevel.Partial,
4545
)
4646
) {
4747
nextApi.tx.Balances.new_fancy_transfer({

docs/pages/signers.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Signers
22

3+
## `PolkadotSigner`
4+
35
For transactions, the generated descriptors and its corresponding typed API are needed to create the transaction extrinsics, but for these transactions to be signed, we also need a signer, which is the responsible of taking it the call data and signing it.
46

5-
Every method on Polkadot-API that needs to sign something, takes in a signer with the following interface:
7+
Every method on Polkadot-API that needs to sign something, requires a `PolkadotSigner` with the following interface:
68

79
```ts
810
interface PolkadotSigner {
@@ -26,7 +28,7 @@ interface PolkadotSigner {
2628

2729
This interface is generic to signing transactions for the chain.
2830

29-
## `PolkadotSigner` from a browser extension
31+
### From a browser extension
3032

3133
If you want to use a compatible extension as a signer, Polkadot-API has a subpath with a couple of utilities to help with this: `polkadot-api/pjs-signer`.
3234

@@ -51,7 +53,7 @@ const accounts: InjectedPolkadotAccount[] = selectedExtension.getAccounts()
5153
const polkadotSigner = accounts[0].polkadotSigner
5254
```
5355

54-
## `PolkadotSigner` from generic signing function
56+
### From a generic signing function
5557

5658
If you have a signer which takes some arbitrary data and just signs it with one of the supported algorithms, you can create a `PolkadotSigner` with the function `getPolkadotSigner` from `polkadot-api/signer`:
5759

@@ -68,16 +70,16 @@ For example, using hdkd from `@polkadot-labs`:
6870
```ts
6971
import { sr25519CreateDerive } from "@polkadot-labs/hdkd"
7072
import {
71-
sr25519,
7273
DEV_PHRASE,
7374
entropyToMiniSecret,
7475
mnemonicToEntropy,
7576
} from "@polkadot-labs/hdkd-helpers"
77+
import { getPolkadotSigner } from "polkadot-api/signer"
7678
77-
const entropy = mnemonicToEntropy(MNEMONIC)
79+
const entropy = mnemonicToEntropy(DEV_PHRASE)
7880
const miniSecret = entropyToMiniSecret(entropy)
7981
const derive = sr25519CreateDerive(miniSecret)
80-
const keypair = derive("//Alice")
82+
const hdkdKeyPair = derive("//Alice")
8183
8284
const polkadotSigner = getPolkadotSigner(
8385
hdkdKeyPair.publicKey,

docs/pages/typed.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ There's also a small utility next to `.getCompatibilityLevel()` to directly chec
5858
```ts
5959
interface IsCompatible {
6060
(threshold: CompatibilityLevel): Promise<boolean>
61-
(threshold: CompatibilityLevel, compatibilityToken: CompatibilityToken): boolean
61+
(
62+
threshold: CompatibilityLevel,
63+
compatibilityToken: CompatibilityToken,
64+
): boolean
6265
}
6366

6467
// Possible "pseudocode" implementation, to show the equivalence
6568
function isCompatible(threshold, token) {
66-
return getCompatibilityLevel(token) >= threshold;
69+
return getCompatibilityLevel(token) >= threshold
6770
}
6871
```
6972

@@ -84,7 +87,9 @@ if (await query.isCompatible(CompatibilityLevel.BackwardsCompatible)) {
8487
const compatibilityToken = await typedApi.compatibilityToken
8588

8689
// And later on we can use it, so that `getCompatibilityLevel` is sync
87-
if (query.isCompatible(CompatibilityLevel.BackwardsCompatible, compatibilityToken)) {
90+
if (
91+
query.isCompatible(CompatibilityLevel.BackwardsCompatible, compatibilityToken)
92+
) {
8893
// do your stuff, the query is compatible
8994
} else {
9095
// the call is not compatible!

0 commit comments

Comments
 (0)