Skip to content
This repository was archived by the owner on Oct 7, 2024. It is now read-only.

Update to v4 of Verida SDK #237

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions docs/client-sdk/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Here’s example output for an encrypted database:
{
type: 'VeridaDatabase',
privacy: 'encrypted',
did: 'did:vda:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F',
did: 'did:vda:polamoy:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F',
dsn: 'https://<username>:<password>@db.testnet.verida.io:5984',
storageContext: 'Verida Test: Test Application 1',
databaseName: 'SyncTestDb',
Expand All @@ -56,4 +56,4 @@ Here’s example output for an encrypted database:
push: { status: 'cancelled', canceled: undefined }
}
}
```
```
30 changes: 14 additions & 16 deletions docs/client-sdk/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ This approach is ideal for integrating the Verida protocol into a server side No
### Example

```tsx
import { Network } from '@verida/client-ts'
import { EnvironmentType } from '@verida/types';
import { Network as NetworkClient } from '@verida/client-ts'
import { Network } from '@verida/types';
import { AutoAccount } from '@verida/account-node'

const VERIDA_ENVIRONMENT = EnvironmentType.TESTNET
const VERIDA_NETWORK = Network.BANKSIA // BANKSIA (testnet) or MYRTLE (mainnet)
const CONTEXT_NAME = 'My Application: Context Name'

// Configuration for the DID client
Expand All @@ -54,28 +54,26 @@ const DID_CLIENT_CONFIG = {
}

// Create a connection to the network and open your context
const context = await Network.connect({
const context = await NetworkClient.connect({
context: {
name: CONTEXT_NAME
},
client: {
environment: VERIDA_ENVIRONMENT
network: VERIDA_NETWORK
},
account: new AutoAccount({
privateKey: '0x...' // or Verida mnemonic seed phrase
environment: VERIDA_ENVIRONMENT,
network: VERIDA_NETWORK,
didClientConfig: DID_CLIENT_CONFIG
})
})
```

Note: Change `EnvironmentType.TESTNET` to `EnvironmentType.MAINNET` if connecting to Verida Mainnet.

See the [@verida/account-node package](https://github.com/verida/verida-js/tree/main/packages/account-node) for more details.

### Web3Config

`DID_CLIENT_CONFIG.web3Config` supports additional options used when communicating with the blockchain. Here's the default configuration when using Verida Mainnet (Polygon PoS network):
`DID_CLIENT_CONFIG.web3Config` supports additional options used when communicating with the blockchain. Here's the default configuration when using Verida Myrtle network (mainnet on the Polygon PoS blockchain):

```tsx
const DID_CLIENT_CONFIG = {
Expand Down Expand Up @@ -111,10 +109,10 @@ In your application, include the dependency and create a new client network inst

```tsx
import { Client } from '@verida/client-ts'
import { EnvironmentType } from '@verida/types'
import { Network } from '@verida/types'
import { AutoAccount } from '@verida/account-node'

const VERIDA_ENVIRONMENT = EnvironmentType.TESTNET
const VERIDA_NETWORK = Network.BANKSIA // BANKSIA (testnet) or MYRTLE (mainnet)
const CONTEXT_NAME = 'My Application: Context Name'

const DID_CLIENT_CONFIG = {
Expand All @@ -126,14 +124,14 @@ const DID_CLIENT_CONFIG = {

// establish a network connection
const client = new Client({
environment: VERIDA_ENVIRONMENT
network: VERIDA_NETWORK
})

// create a Verida account instance that wraps the authorized Verida DID server connection
// The `AutoAccount` instance will automatically sign any consent messages
const account = new AutoAccount({
privateKey: '0x...' // or Verida mnemonic seed phrase
environment: VERIDA_ENVIRONMENT,
network: VERIDA_NETWORK,
didClientConfig: DID_CLIENT_CONFIG
})

Expand All @@ -154,14 +152,14 @@ The first parameter for `AutoAccount()` is an interface that meets the `AccountN
```ts
export interface AccountNodeConfig {
privateKey: string;
environment: EnvironmentType;
network: Network; // from '@verida/types'
didClientConfig: AccountNodeDIDClientConfig;
options?: any;
countryCode?: string;
}
```

- `privateKey` - Verida network private key for the account
- `environment` - Verida environment (`EnvironmentType.TESTNET` or `EnvironmentType.MAINNET`)
- `network` - Verida network (`Network.BANKSIA` or `Network.MYRTLE`)
- `didClientConfig` - Instance of `AccountNodeDIDClientConfig`
- `countryCode` - (optional) Country to use for selecting storage and DID nodes on the network. If not specified, will choose random global nodes. If specified, will use nodes in that country. If not enough nodes are available in that country, it will fallback to selecting nodes in the same region as that country, then fallback to global nodes.
- `countryCode` - (optional) Country to use for selecting storage and DID nodes on the network. If not specified, will choose random global nodes. If specified, will use nodes in that country. If not enough nodes are available in that country, it will fallback to selecting nodes in the same region as that country, then fallback to global nodes.
10 changes: 5 additions & 5 deletions docs/client-sdk/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Here we are opening a database with `PUBLIC` read and write permissions owned by
```tsx
import { ContextInterfaces } from @verida/client-ts

const otherAccountDid = 'did:vda:kjzl6cwe1jt148u1wjwyd532ho7r59n02jwn26y1z86cshwjq1j5dkvnil0zspr'
const otherAccountDid = 'did:vda:polamoy:0x5e8fdBaAA46E4Bfa914e206e9415Aa05d4CC6722'
const options = {
permissions: {
read: ContextInterfaces.PermissionOptionsEnum.PUBLIC,
Expand All @@ -79,15 +79,15 @@ You can also open an external database using the `Client` class in the `@verid
```tsx

import { Client } from '@verida/client-ts';
import { EnvironmentType } from '@verida/types';
import { Network } from '@verida/types';

const clientConfig = {
environment: EnvironmentType.TESTNET,
network: Network.BANKSIA, // BANKSIA (testnet) or MYRTLE (mainnet)
}

const context = await new Client(clientConfig).openExternalContext(
'contextName',
'did:vda:0x4e8fdBaAA46E4Bfa914e206e9415Aa05d4CC6722'
'did:vda:polamoy:0x4e8fdBaAA46E4Bfa914e206e9415Aa05d4CC6722'
);

const db = await context.openExternalDatabase('test_external_db')
Expand Down Expand Up @@ -194,7 +194,7 @@ Just like databases, it’s also possible to open an external datastore:
```tsx
import { ContextInterfaces } from @verida/client-ts

const otherAccountDid = 'did:vda:kjzl6cwe1jt148u1wjwyd532ho7r59n02jwn26y1z86cshwjq1j5dkvnil0zspr'
const otherAccountDid = 'did:vda:polamoy:0x5e8fdBaAA46E4Bfa914e206e9415Aa05d4CC6722'
const options = {
permissions: {
read: ContextInterfaces.PermissionOptionsEnum.PUBLIC,
Expand Down
12 changes: 6 additions & 6 deletions docs/client-sdk/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ npm install --dev @types/pouchdb-core
Initialize a connection to the Verida network using a private key stored on the user’s mobile device using the Verida Wallet:

```tsx
import { Network } from '@verida/client-ts';
import { EnvironmentType } from '@verida/types';
import { Network as NetworkClient } from '@verida/client-ts';
import { Network } from '@verida/types';
import { VaultAccount } from '@verida/account-web-vault';

const VERIDA_ENVIRONMENT = EnvironmentType.TESTNET;
const VERIDA_NETWORK = Network.BANKSIA; // BANKSIA (testnet) or MYRTLE (mainnet)
const CONTEXT_NAME = 'My Application Context Name';

// The LOGO_URL should be a 170x170 PNG file
Expand All @@ -42,9 +42,9 @@ const account = new VaultAccount({
logoUrl: LOGO_URL
});

const context = Network.connect({
const context = NetworkClient.connect({
client: {
environment: VERIDA_ENVIRONMENT,
network: VERIDA_NETWORK,
},
account: account,
context: {
Expand All @@ -53,7 +53,7 @@ const context = Network.connect({
});
```

Note: Change `EnvironmentType.TESTNET` to `EnvironmentType.MAINNET` if connecting to Verida Mainnet.
Note: `Network.BANKSIA` is a testnet network, use `Network.MYRTLE` to use a mainnet network.

- `CONTEXT_NAME`: A string representing your decentralized application. By convention prefix it with your company name. ie: `Verida: My Application`.

Expand Down
4 changes: 2 additions & 2 deletions docs/client-sdk/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Your application can send messages to other accounts on the Verida network.
This example sends a contact record to a user’s Verida Wallet:

```tsx
const did = 'did:vda:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F'
const did = 'did:vda:polamoy:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F'
const type = 'inbox/type/dataSend'

// Generate an inbox message containing an array of data
Expand Down Expand Up @@ -137,7 +137,7 @@ Data can be sent to an account (see Outbox example above)
Data can be requested from an account:

```tsx
const did = 'did:vda:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F'
const did = 'did:vda:polamoy:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F'
const type = 'inbox/type/dataRequest'

// Generate an inbox message containing an array of data
Expand Down
6 changes: 3 additions & 3 deletions docs/client-sdk/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ When specifying the `users` permission type, you must also specify the list of v
```tsx
const permissions = {
read: PERMISSIONS.USERS,
readList: ['did:vda:0xe613A46C48f3805B05500bF7dBff00A1dd3Ba0e6', 'did:vda:....'],
readList: ['did:vda:polamoy:0xe613A46C48f3805B05500bF7dBff00A1dd3Ba0e6', 'did:vda:....'],
write: PERMISSIONS.USERS,
writeList: ['did:vda:0xe613A46C48f3805B05500bF7dBff00A1dd3Ba0e6', 'did:vda:....'],
writeList: ['did:vda:polamoy:0xe613A46C48f3805B05500bF7dBff00A1dd3Ba0e6', 'did:vda:....'],
}

// Open a database
const restrictedDb = await const.openExternalDatabase('restricted_data', 'did:vda:0xe613A46C48f3805B05500bF7dBff00A1dd3Ba0e6', {
const restrictedDb = await const.openExternalDatabase('restricted_data', 'did:vda:polamoy:0xe613A46C48f3805B05500bF7dBff00A1dd3Ba0e6', {
permissions: permissions
})
```
Expand Down
21 changes: 10 additions & 11 deletions docs/client-sdk/profiles.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Open the public profile for any Verida Account and context combination using an
For example, open a user’s public profile created in the `Verida: Vault` mobile application:

```ts
const did = 'did:vda:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F';
const did = 'did:vda:polamoy:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F';
const profileConnection = await client.openPublicProfile(did, 'Verida: Vault', 'basicProfile');
const publicProfile = await profileConnection.getMany()

Expand All @@ -46,7 +46,7 @@ This can be tried out in your browser [here](../tutorial/public_profile.mdx).
It’s also possible to open an external profile for the current context:

```ts
const did = 'did:vda:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F';
const did = 'did:vda:polamoy:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F';
const externalProfile = await context.openProfile('public', did);
```

Expand All @@ -70,7 +70,7 @@ const profileData = await userProfile.getMany();
console.log(profileData); // -> { name: 'Stevie', avatar: { uri: 'data:image/png;base64,iVBOR...' }, ...}

// Delete a profile property
await userProfile.delete('name');
await userProfile.delete('name');

// Listen for profile changes
const listener = await userProfile.listen(function (row) {
Expand All @@ -96,14 +96,15 @@ For example, open a user’s public profile created in the `Verida: Vault` mobil

```tsx
import { Client } from '@verida/client-ts';
import { EnvironmentType } from '@verida/types';
import { Network } from '@verida/types';

const userConfig = {
environment: EnvironmentType.TESTNET,
const did = 'did:vda:polamoy:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F';

const clientConfig = {
environment: Network.BANKSIA, // BANKSIA (testnet) or MYRTLE (mainnet)
};

const did = 'did:vda:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F';
const client = new Client(userConfig);
const client = new Client(clientConfig);

const profileInstance = await client.openPublicProfile(
did,
Expand All @@ -112,8 +113,6 @@ const profileInstance = await client.openPublicProfile(
);

const profile = await profileInstance.getMany({}, {});

}
```

Note: Change `EnvironmentType.TESTNET` to `EnvironmentType.MAINNET` if loading a mainnet profile.
Note: Change `Network.BANKSIA` to `Network.MYRTLE` if loading a mainnet profile.
4 changes: 2 additions & 2 deletions docs/concepts/accounts-and-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Read the article below or watch the technical deep dive to learn about the key p

## Decentralized Identifiers (DIDs)

Verida accounts are decentralized identities that implement the [decentralized identifier (DID) standard](https://w3c.github.io/did-core/). A DID has a unique addresses (ie: `did:vda:testnet:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F`) that is controlled by an end user with a private key or seed phrase.
Verida accounts are decentralized identities that implement the [decentralized identifier (DID) standard](https://w3c.github.io/did-core/). A DID has a unique addresses (ie: `did:vda:polamoy:0x6B2a1bE81ee770cbB4648801e343E135e8D2Aa6F`) that is controlled by an end user with a private key or seed phrase.

In this documentation we use the terms `account`, `identity`, `DID` interchangeable as they are effectively the same thing.

Expand Down Expand Up @@ -74,4 +74,4 @@ Data stored on the Verida Acacia Testnet is deleted regularly, so don’t rely o

If you need help spinning up your own storage node, please reach out via [Discord](https://discord.verida.io) or [Register your interest in running a Storage Node](https://www.verida.network/developers#build-with-us).

:::
:::
4 changes: 2 additions & 2 deletions docs/concepts/messaging.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ In the example above we have the account `Steve - Personal` from the application

This architecture allows applications to develop their own message types for domain specific data sharing and messaging.

In this case the message is being sent to a Verida account (`did:vda:0x6B2a1bE81...). In the future will support Verida accounts being linked to onchain addresses, providing a decentralized messaging system that works across multiple addresses and multiple chains.
In this case the message is being sent to a Verida account (`did:vda:polamoy:0x6B2a1bE81...). In the future will support Verida accounts being linked to onchain addresses, providing a decentralized messaging system that works across multiple addresses and multiple chains.

## How it works

Expand Down Expand Up @@ -57,4 +57,4 @@ As such, the Verida Wallet loads profile metadata in the following order:
- See [Client SDK - Messaging](../client-sdk/messaging.md) to learn more about using messaging in your application.
- See [Profiles](../client-sdk/profiles) to learn how to get the account name and avatar of the account that sent a message.

It is possible to define your own custom message types. There are no tutorials available yet, however you can [browse examples of current message types](https://github.com/verida/schemas-core/tree/develop/inbox/type/) as a starting point.
It is possible to define your own custom message types. There are no tutorials available yet, however you can [browse examples of current message types](https://github.com/verida/schemas-core/tree/develop/inbox/type/) as a starting point.
Loading
Loading