From a138691b54923b7e9e5df4496b0d26ca51a1af58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?NB=F0=9F=98=88?= Date: Thu, 21 Sep 2023 12:31:04 +0200 Subject: [PATCH] add missing polkadot client tutorial --- sdk/apps/docs/docs/client/connect.md | 25 ++++++++++++++++++++++++ sdk/apps/docs/docs/client/sign.md | 19 ++++++++++++++++++ sdk/apps/docs/docs/client/signMessage.md | 3 +++ 3 files changed, 47 insertions(+) diff --git a/sdk/apps/docs/docs/client/connect.md b/sdk/apps/docs/docs/client/connect.md index 02df935a..b418b6a7 100644 --- a/sdk/apps/docs/docs/client/connect.md +++ b/sdk/apps/docs/docs/client/connect.md @@ -87,6 +87,31 @@ const message: Connect = { await client.connect(message) ``` + + + +```js +import { ClientPolkadot } from '@nightlylabs/nightly-connect-polkadot' + +const client: ClientPolkadot = await ClientPolkadot.create({ + url: RELAY_ENDPOINT // default: https://nc2.nightly.app +}) +const info: GetInfoResponse = await client.getInfo(sessionId) + +const message: Connect = { + publicKeys: ['5EnRWxJwqLuexBZtbJVTmfAzzc6Fwpw2Gv9AYs1gYHsgvzfH'], + sessionId: sessionId, + walletsMetadata: [ + { + address: '5EnRWxJwqLuexBZtbJVTmfAzzc6Fwpw2Gv9AYs1gYHsgvzfH', + name: 'Alice', + type: 'ed25519' + } + ] +} +await client.connect(message) +``` + diff --git a/sdk/apps/docs/docs/client/sign.md b/sdk/apps/docs/docs/client/sign.md index 96d9ac02..4579141e 100644 --- a/sdk/apps/docs/docs/client/sign.md +++ b/sdk/apps/docs/docs/client/sign.md @@ -89,5 +89,24 @@ client.on('signTransactions', async (e) => { }) ``` + + + +```js + +const alice_keypair = new Keyring() +alice_keypair.setSS58Format(42) +const aliceKeyringPair = alice_keypair.createFromUri('//Alice') + +client.on('signTransactions', async (e) => { + const payload = e.transactions[0] as SignerPayloadRaw + const signature = aliceKeyringPair.sign(payload.data, { withType: true }) + await client.resolveSignTransaction({ + requestId: e.requestId, + signedTransactions: [{ signature: u8aToHex(signature), id: new Date().getTime() }] + }) +}) +``` + diff --git a/sdk/apps/docs/docs/client/signMessage.md b/sdk/apps/docs/docs/client/signMessage.md index 6ca68787..10b4dcc5 100644 --- a/sdk/apps/docs/docs/client/signMessage.md +++ b/sdk/apps/docs/docs/client/signMessage.md @@ -63,5 +63,8 @@ client.on('signMessages', async (e) => { }) ``` + + +Signing messages on Polkadot works the same way as signing transactions