10 minute read
Before we look at some of the sample code, the verb tree gives you a big picture of all of the verbs and what can be executed where.
The scan verb is used to scan the available @ addresses for you either at the public level or all authorized data once the pol process has been completed. This allows addresses to be discovered and perhaps be harvested so if an address has a _ character as its first character then it is omitted from the scan list although it can still be looked up if known. The following example shows just that.
Following are the steps to run the scan verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the Client Impl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
// Namespace is mandatory to be passed. E.g me, buzz, etc.,
await AtClientImpl.createClient('@bob','me', preference);
var atClient = await AtClientImpl.getClient('@bob');
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob);
// Scans keys stored in app storage
await atClient.getKeys();
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob);
// Scans keys in .me namespace
await atClient.getKeys(regex:'.me');
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob);
// Scans keys shared with @alice
await atClient.getKeys(sharedWith:'alice');
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob);
// Scans keys shared by @alice. This performs authenticated scan on @alice's secondary.
await atClient.getKeys(sharedBy:'alice');
Update verb used to add entries in the @server. @signs have to be authenticated for one to run the update verb on the @server.
Following are the steps to run the scan verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
//create atClient
var atClient = await AtClientImpl.createClient('@bob', 'me', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
// create phoneKey
var phoneKey = AtKey()..key = 'phone';
// Update a phone number visible only to @bob
await atClient.put(phoneKey, ''+1-123-4567');
// create emailKey
var emailKey = AtKey()..key = 'email'
..sharedWith = '@alice';
// Update an email visible only to @alice
await atClient.put(emailKey, 'bob@atsign.com');
// Update an email visible only to everyone
// create metadata with isPublic true
var metadata = Metadata()..isPublic=true;
// create emailKey and update metadata
var emailKey = AtKey()..key = 'email'
..metadata = metadata;
await atClient.put(emailKey, 'bob@gmail.com');
// Update a location that expires in 10 minutes
var metadata = Metadata()..ttl=600000;
var locationKey = AtKey()..key = 'current_location'
..metadata = metadata;
await atClient.put(locationKey, 'https://goo.gl/maps/Trs5Dao562tLFK5Q9');
The lookup verb is used to lookup a value on a @server of another @sign. The following demonstrates the use of lookup verb.
Following are the steps to run the scan verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
// Get
var atClient = await AtClientImpl.createClient('@bob', 'me', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
// Look up phone number sharedBy @alice
//lookup:phone.me@alice
var atKey = AtKey()..key = 'phone'
..sharedBy = '@alice';
await atClient.get(atKey);
The plookup verb is used to lookup a public value on a @server of another @sign if the client is authenticated. Plookup verb can only be executed on a remote @server. The following demonstrates the use of plookup verb.
Following are the steps to run the scan verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
//Get
var atClient = await AtClientImpl.createClient('@bob', 'me', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
// plookup public phone number of @alice
var metadata = Metadata()..isPublic=true;
var publicPhoneKey = AtKey()..key = 'phone'
..sharedBy = '@alice'
..metadata = metadata;
await atClient.get(publicPhoneKey);
The llookup verb is used to lookup a value on a local @server storage of current @sign. The following demonstrates the use of llookup verb.
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
//Get
var atClient = await AtClientImpl.createClient('@bob', 'me', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
// Local lookup a self key e.g @bob:email.me@bob
var privateEmailKey = AtKey()
..key = 'email'
..sharedWith = '@bob';
var alicePrivateEmail = await atClient.get(privateEmailKey);
// Local lookup phone shared with @alice e.g @alice:email.me@bob
var phoneKey = AtKey()
..key = 'phone'
..sharedWith = '@alice';
await atClient.get(phoneKey);
// Local lookup a public key
var metadata = Metadata()..isPublic=true;
var firstnameKey = AtKey()
..key = 'firstname'
..metadata = metadata;
await atClient.get(firstnameKey);
// Local lookup a key ignoring namespace
var metadata = Metadata()..namespaceAware=false;
var firstnameKey = AtKey()
..key = 'firstname'
..metadata = metadata;
await atClient.get(firstnameKey);
The “delete” verb is used for deleting @addresses.
Following are the steps to run the scan verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
// create AtClient
var atClient = await AtClientImpl.createClient('@bob', 'me', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
// delete self key e.g @bob:phone.me@bob
var phoneKey = AtKey()..key = 'phone'
..sharedWith = '@bob';
await atClient.delete(phoneKey);
// delete email shared with @alice e.g @alice:phone.me@bob
var phoneKey = AtKey()..key = 'phone'
..sharedWith = '@alice';
await atClient.delete(phoneKey);
// delete a public key e.g public:phone.me@bob
var metadata = Metadata()..isPublic=true;
var phoneKey = AtKey()
..key = 'phone'
..metadata = metadata;
await atClient.delete(phoneKey);
The “stats” verb is used to get certain predefined statistics from the @server.
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
// Get
var atClient = await AtClientImpl.createClient('@bob', 'me', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
// Execute the verb e.g stats:1,stats:1,2 etc.,
// You can use stats number from 1 to 10
// If you want to request multiple types use as , separated values
// Ex: stats:1,2,5
await atClient.getRemoteSecondary().executeCommand('stats:1');
The “config” verb is used to configure block list entries in the @server. If an @sign is added to the block list then connections to the @server will not be accepted.
Following are the steps to run the scan verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
// Get
var atClient = await AtClientImpl.getClient('@bob', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob, AtClientPreference());
var builder = ConfigVerbBuilder()..block = '@rachel';
// Execute the verb
await atClient.getLocalSecondary().executeVerb(builder);
The “notify” verb is used to notify another @server of change related to a @address.
Following are the steps to run the notify verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
// Get
var atClient = await AtClientImpl.getClient('@bob');
}
// Create Atclient Instance
await AtClientImpl.createClient('')
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob);
var atKey = AtKey()
..key = 'phone@bob'
..sharedWith = '@alice'
..sharedBy = '@bob'
// Execute the verb
await atClient.notify(atKey, '+1 987 986 2233', OperationEnum.update);
// Sending Notification with Notification Strategy 'ALL'
await atClient.notify(atKey, '+1 987 986 2233', OperationEnum.update,
priority: PriorityEnum.low,
strategy: StrategyEnum.all);
// Sending Notification with Notification Strategy 'Latest N'
await atClient.notify(atKey, '+1 987 986 2233', OperationEnum.update,
priority: PriorityEnum.high,
strategy: StrategyEnum.latest,
latestN:3,
Notifier: 'wavi');
// Create Atclient Instance
await AtClientImpl.createClient('')
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob);
var atKey = AtKey()
..key = 'phone@bob'
..sharedWith = '@alice'
..sharedBy = '@bob'
// Execute the notify verb
var notiticationId = await atClient.notify(atKey, '+1 987 986 2233', OperationEnum.update);
// get notification status of the above notificationId
var status = await atClient.notifyStatus(notificationId);
The “monitor” verb is used to stream incoming notifications from the @server to @Client.
Following are the steps to run the notify verb using the @Client SDK
To get an instance of the AtClient by calling the getClient method on the AtClientImpl class.
import 'package:at_client/at_client.dart';
import 'package:at_client/src/client/at_client_impl.dart';
void main() async {
// Construct AtClientPreference
var preference = AtClientPreference();
preference.hiveStoragePath = '/hive/storage/path';
preference.commitLogPath = '/commit/log/path';
// Get
var atClient = await AtClientImpl.getClient('@bob', preference);
}
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
var builder = MonitorVerbBuilder();
// Execute the verb
await atClient.startMonitor(<privateKey>,<NotificationCallback>);
//Using Regex on Monitor verb
// Get an instance of AtClient for @bob
var atClient = await AtClientImpl.getClient('@bob');
var builder = MonitorVerbBuilder();
// Execute the verb
await atClient.startMonitor(<privateKey>,<NotificationCallback>,regex: '.wavi');
required optional’*
Verb | Parameters |
from | atSign* - @ sign you claim to be |
cram | digest* - SHA512 digest |
pkam | signature* - Signed challenge |
pol | NA |
scan | forAtSign’ - Scans the keys shared by forAtSign regex’ - Regex to which the @addresses has to be matched to be returned as a result |
update | ttl’ - Time to live in milliseconds. Value for the key won't be available after the ttl’ ttb’ - Time to birth in milliseconds. Value for the key will be available after the ttb’ Scope’ - Public vs Private forAtSign* - For whom the value is being set atKey* - Name of the @address value* - Value for the @address |
lookup | atKey* - Name of the @address atSign* - @ signs namespace |
llookup | atKey* - Name of the @address atSign* - @ signs namespace |
plookup | atKey* - Name of the @address atSign* - @ signs namespace |
delete | atKey* - Name of the @address |
stats | statId’ - Id’s of the statistics to display |
config | whatToConfig* - Thing to configure configValue* - Value of the thing to configure |
notify | forAtSign* - @sign to notify key* - Key to which the change has happened change* - Change it self |
monitor | regex’ - Regex that needs to be matched for the value to be monitored |