Skip to content
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: aptos docs #136

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions sdk/apps/docs/docs/aptos/connect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: Build & Connect
slug: aptos/connect
---

:::info
This part of documentation is targeted to applications that want to implement nightly connect
as wallet interface.
:::

To get started, we need to connect the user to the application.
In order to do so, application generates the sessionId, a unique id that identifies each connection.

---

This process is initialized by one side displaying a sessionId through QR code (see the screenshot).
The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and don't need to upgrade your dapp.

![ConnectImage](../../static/img/connect.png#connectImage)

### Connect

Application builds a connection using `build()` or `buildLazy()` function that returns interface to communicated with remote user. It is important to note, that the `buildLazy()` function allows for the modal to appear even when the sessionId is still undefined. App should define `AppMetadata` so wallets will be able to show it to user.

To start sending request like `signTransaction` user first need to connect to session.
Once user establishes connection, application will get public key and the connection will be confirmed.

API of application client is fit to match currently existing standards of corresponding blockchains

```js
interface AppMetadata {
name: string;
url?: string;
description?: string;
icon?: string; // Url of app image
additionalInfo?: string;
}
```

You may also want to specify some additional connection options. This can be achieved by creating an object that implements the below interface, and using it inside the `build()` or `buildLazy()` function. Note, that the `disableModal` property can be used for implementing a custom [External modal](../../customization/customization/external_modal).

```js
interface ConnectionOptions {
disableModal?: boolean // default: false
// Used for disabling modal in case you want to use your own
initOnConnect?: boolean // default: false
// Ensures that the app is only build upon running the connect function
disableEagerConnect?: boolean // default: false
// Do not connect eagerly, even if the previous session is saved
}
```

```js
import { NightlyConnectAptosAdapter } from '@nightlylabs/wallet-selector-aptos'

const adapter = await NightlyConnectAptosAdapter.build(
{
appMetadata: {
name: 'NCTestAptos',
description: 'Nightly Connect Test',
icon: 'https://docs.nightly.app/img/logo.png',
additionalInfo: 'Courtesy of Nightly Connect team'
}
// persistent: false - Add this if you want to make the session non-persistent
}
// { initOnConnect: true, disableModal: true, disableEagerConnect: true } - You may specify the connection options object here
// document.getElementById("modalAnchor") - You can pass an optional anchor element for the modal here
)

// Trigger connection
await adapter.connect()
// After connection adapter turns into remote signer

// Sign transaction
await adapter.signAndSubmitTransaction()

// Disconnect client if you want to end session
await adapter.disconnect()
```

### Disconnect

:::info
Both client and application can initiate disconnection.
User can force session termination in case of abuse.
Only when application disconnects and session is not persistent, session is completely removed.
:::
42 changes: 42 additions & 0 deletions sdk/apps/docs/docs/aptos/events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: Listening for events
slug: aptos/events
---

An app can listen to events, subscribe to them and run some code whenever the particular event occurs.

If you have created a connection you can listen for events using the `on()` function.

```js
const adapter = NightlyConnectAptosAdapter.buildLazy(
{
appMetadata: {
name: 'NCTestAptos',
description: 'Nightly Connect Test',
icon: 'https://docs.nightly.app/img/logo.png',
additionalInfo: 'Courtesy of Nightly Connect team'
},
url: 'https://nc2.nightly.app'
}
)

adapter.on('connect', (publicKey) => {
...
})

adapter.on('accountChange', (accInfo) => {
...
})

adapter.on('networkChange', (networkInfo) => {
...
})

adapter.on('disconnect', () => {
...
})

adapter.on('error', (error) => {
...
})
```
32 changes: 32 additions & 0 deletions sdk/apps/docs/docs/aptos/sign_transaction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: Sign Transaction
slug: aptos/sign_transaction
---

Sending a signTransaction requires established connection with user wallet.

Transaction are sent to the client via wallet interface. Client can accept or reject the request. Once client signs transaction, `signAndSubmitTransaction()` method returns resolved promise with Signed Transaction.

```js
import { Aptos } from '@aptos-labs/ts-sdk'

const aptos = new Aptos()

const accountInfo = {
address: '' // Generated inside the onAccountChange event listener
...
}

const transaction = await aptos.transaction.build.simple({
sender: accountInfo.address.toString(),
data: {
function: '0x1::coin::transfer',
typeArguments: ['0x1::aptos_coin::AptosCoin'],
functionArguments: ['0x960dbc655b847cad38b6dd056913086e5e0475abc27152b81570fd302cb10c38', 100]
}
})

const signedTx = await adapter.signAndSubmitTransaction({
rawTransaction: transaction.rawTransaction
})
```
38 changes: 38 additions & 0 deletions sdk/apps/docs/docs/aptos/start.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Get started with Aptos
slug: aptos/start
---

### Web template

<div class='highlight-template'>

**To get started with aptos, use the source code of the template below, and follow the installation instructions.**

<br/>

> #### Preview: https://aptos-web3-template.vercel.app

<br/>

> #### Source code: https://github.com/nightly-labs/aptos-web3-template

</div>

<hr/>

### Manual installation

If you want to opt for greater flexibility, install the package, as described below and then visit the [Aptos Build & Connect](./connect).

:::note
Simply integrate Nightly Connect to your application or wallet with our [Nightly Aptos Connect package](https://www.npmjs.com/package/@nightlylabs/wallet-selector-aptos).

```bash
# Using NPM
npm i @nightlylabs/wallet-selector-aptos
# Using Yarn
yarn add @nightlylabs/wallet-selector-aptos
```

:::
6 changes: 3 additions & 3 deletions sdk/apps/docs/docs/customization/external_modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ title: External modal
slug: customization/external_modal
---

You may want to use your own design and/or change some logic for the modal. In that case passing all of the overrides to the `build()` or `buildLazy()` function can prove ineffective. Another option therfore is to omit the default modal altogether, by specyfing the `disableModal` option as true insid ethe `connectionOptions`.
You may want to use your own design and/or change some logic for the modal. In that case passing all of the overrides to the `build()` or `buildLazy()` function can prove ineffective. Another option therfore is to omit the default modal altogether, by specyfing the `disableModal` option as true inside the `connectionOptions`.

You can then use the modal connect function, instead of using the default one from the adapter.

:::info
Example below is written for [Solana](../../solana/solana/start), but you can use it for [Sui](../../sui/sui/start) and [Substrate](../../substrate/substrate/start) as well.
Example below is written for [Solana](../../solana/solana/start), but you can use it for [Sui](../../sui/sui/start), [Aptos](../../aptos/aptos/start) and [Substrate](../../substrate/substrate/start) as well.
:::

```js
Expand Down Expand Up @@ -48,7 +48,7 @@ adapter.on('connect', (pk) => {
})
```

The aforedescribed code sets up the adapter and the modal for later use.
The code described above sets up the adapter and the modal for later use.

To connect using custom modal, we can run:

Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/docs/docs/customization/ui_overrides.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ const adapter = NightlyConnectAdapter.buildLazy(
```

:::info
The example is built using [Substrate](../../substrate/substrate/start), but can be implemented using [Solana](../../solana/solana/start) and [Sui](../../sui/sui/start) as well.
The example is built using [Substrate](../../substrate/substrate/start), but can be implemented using [Solana](../../solana/solana/start), [Aptos](../../aptos/aptos/start) and [Sui](../../sui/sui/start) as well.
:::
Empty file removed sdk/apps/docs/docs/demo.md
Empty file.
28 changes: 28 additions & 0 deletions sdk/apps/docs/docs/for_wallets/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,34 @@ const message: Connect = {
await client.connect(message)
```

</TabItem>

<TabItem value="Aptos" label="Aptos">

```js
import { ClientSui } from '@nightlylabs/nightly-connect-aptos'

const client: ClientAptos = await ClientAptos.create({
url: RELAY_ENDPOINT // default: https://nc2.nightly.app
})
const info: GetInfoResponse = await client.getInfo(sessionId)

const message: Connect = {
accountInfo: {
address: accountAddress,
publicKey: publicKey,
ansName: undefined
},
networkInfo: {
chainId: 10,
name: Network.MAINNET,
url: undefined
},
sessionId: app.sessionId
}
await client.connect(message)
```

</TabItem>
</Tabs>

Expand Down
30 changes: 30 additions & 0 deletions sdk/apps/docs/docs/for_wallets/sign_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,35 @@ client.on('signMessages', async (e) => {
</TabItem>
<TabItem value="Substrate" label="Substrate">
Signing messages on Substrate works the same way as signing transactions
</TabItem>

<TabItem value="Aptos" label="Aptos">

```js
export interface ResolveSignAptosMessage {
requestId: string
signedMessages: Array<AptosSignMessageOutput>
sessionId: string
}

client.on('signMessage', async (e) => {
const payload = e.messages[0]
const signature = alice.sign(new Buffer(payload.message).toString('hex'))

await client.resolveSignMessage({
requestId: e.requestId,
signedMessages: [
{
message: payload.message,
signature: signature,
fullMessage: payload.message,
nonce: payload.nonce,
prefix: 'APTOS'
}
],
})
})
```

</TabItem>
</Tabs>
25 changes: 25 additions & 0 deletions sdk/apps/docs/docs/for_wallets/sign_transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,30 @@ client.on('signTransactions', async (e) => {
})
```

</TabItem>

<TabItem value="Aptos" label="Aptos">

```js
interface ResolveSignAptosTransactions {
requestId: string
signedTransactions: Array<AptosSignTransactionOutput>
sessionId: string
}

client.on('signTransaction', async (e) => {
const tx = e.transactions[0]
const senderAuthenticator = aptos.transaction.sign({
signer: alice,
transaction: tx
})
// resolve
await client.resolveSignTransaction({
requestId: e.requestId,
signedTransactions: [senderAuthenticator]
})
})
```

</TabItem>
</Tabs>
2 changes: 1 addition & 1 deletion sdk/apps/docs/docs/solana/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In order to do so, application generates the sessionId, a unique id that identif
---

This process is initialized by one side displaying a sessionId through QR code (see the screenshot).
The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and dont need to upgrade your dapp.
The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and don't need to upgrade your dapp.

![ConnectImage](../../static/img/connect.png#connectImage)

Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/docs/docs/solana/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const adapter = NightlyConnectAdapter.buildLazy({
url: 'https://nc2.nightly.app'
})

adapter.on('connect', (public_key) => {
adapter.on('connect', (publicKey) => {
...
})

Expand Down
4 changes: 4 additions & 0 deletions sdk/apps/docs/docs/start.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ slug: /start
<img src="https://registry.nightly.app/networks/polkadot.png"/>
Substrate
</a>
<a href="./aptos/aptos/start" class="card">
<img src="https://aptosfoundation.org/brandbook/logomark/PNG/Aptos_mark_WHT.png"/>
Aptos
</a>
</div>
4 changes: 2 additions & 2 deletions sdk/apps/docs/docs/substrate/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In order to do so, application generates the sessionId, a unique id that identif
---

This process is initialized by one side displaying a sessionId through QR code (see the screenshot).
The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and dont need to upgrade your dapp.
The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and don't need to upgrade your dapp.

![ConnectImage](../../static/img/connect.png#connectImage)

Expand Down Expand Up @@ -50,7 +50,7 @@ interface ConnectionOptions {
}
```

You can find example usage of this addapter here: https://github.com/nightly-labs/connect/blob/main/sdk/apps/modal-example/src/routes/aleph.tsx
You can find example usage of this adapter here: https://github.com/nightly-labs/connect/blob/main/sdk/apps/modal-example/src/routes/aleph.tsx

```js
import { NightlyConnectAdapter } from '@nightlylabs/wallet-selector-polkadot'
Expand Down
4 changes: 2 additions & 2 deletions sdk/apps/docs/docs/sui/connect.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ In order to do so, application generates the sessionId, a unique id that identif
---

This process is initialized by one side displaying a sessionId through QR code (see the screenshot).
The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and dont need to upgrade your dapp.
The other peer needs just to scan the QR code on its device. Extension wallets are auto detected so you are always up to date and don't need to upgrade your dapp.

![ConnectImage](../../static/img/connect.png#connectImage)

Expand Down Expand Up @@ -53,7 +53,7 @@ interface ConnectionOptions {
```js
import { NightlyConnectSuiAdapter } from '@nightlylabs/wallet-selector-sui'

const adapter = NightlyConnectSuiAdapter.buildLazy(
const adapter = await NightlyConnectSuiAdapter.build(
{
appMetadata: {
name: 'NCTestSui',
Expand Down
Loading
Loading