init method Null safety
- String publishingId,
- String origin,
- KeyStorage keyStorage,
- String id,
- dynamic database,
- {int maxTransactions = 1,
- Duration blockInterval = const Duration(minutes: 1),
- String? customerAuth}
Returns a new initialized TikiSdk
instance.
Parameters:
• publishingId
- Sign up for a free developer account
at https://console.mytiki.com to get a Publishing ID.
• origin
- The default origin to use during TitleRecord creation.
Follow a reverse-DNS syntax. i.e. com.myco.myapp
• keyStorage
- Platform-specific, encrypted, private key persistence.
• id
- The id mapped to the wallet's address and private keys.
Private key MUST be previously registered in the provided keyStorage
.
Use withId.
• database
- Platform-specific sqlite3 implementation, opened.
• maxTransactions
- The maximum number of transactions to bundle
in a block. Use in combination with blockInterval
. Default is 1.
• blockInterval
- The duration before a block is automatically
created if there are any pending transactions AND the maxTransactions
limit has not been reached. Use in combination with blockInterval
.
Default is 1 minute.
• customerAuth
- A customer provided Authorization Token (JWT) for
use in id
registration. Use customerAuth
to add user identity
verification. Configure in console
Implementation
static Future<TikiSdk> init(String publishingId, String origin,
KeyStorage keyStorage, String id, CommonDatabase database,
{int maxTransactions = 1,
Duration blockInterval = const Duration(minutes: 1),
String? customerAuth}) async {
KeyService keyService = KeyService(keyStorage);
KeyModel? primaryKey = await keyService.get(id);
if (primaryKey == null) {
throw StateError("Use keystore() to initialize address");
}
AuthService authService = AuthService(publishingId);
StorageService storageService =
StorageService(primaryKey.privateKey, authService);
RegistryService registryService =
RegistryService(primaryKey.privateKey, authService);
RegistryModelRsp registryRsp = await registryService.register(
id, Bytes.base64UrlEncode(primaryKey.address),
customerAuth: customerAuth);
NodeService nodeService = NodeService()
..blockInterval = blockInterval
..maxTransactions = maxTransactions
..transactionService =
TransactionService(database, appKey: registryRsp.signKey)
..blockService = BlockService(database)
..xChainService = XChainService(storageService, database)
..primaryKey = primaryKey;
nodeService.backupService = BackupService(
storageService, database, primaryKey, nodeService.getBlock);
await nodeService.init();
TitleService titleService =
TitleService(origin, nodeService, nodeService.database);
LicenseService licenseService =
LicenseService(nodeService.database, nodeService);
return TikiSdk(titleService, licenseService, nodeService, registryService);
}