Biblioteca Dart Archethic para Flutter para Node e navegador. Esta biblioteca tem como objetivo fornecer uma maneira fácil de criar transações Archethic e enviá-las pela rede
Orientação gerada a partir de informações públicas. Apenas para referência.
O pacote archethic_lib_dart é uma biblioteca Dart projetada para aplicativos Flutter, permitindo que desenvolvedores criem e enviem transações da blockchain Archethic tanto em ambientes Node.js quanto em navegadores. Simplifica a interação com a rede Archethic fornecendo ferramentas para geração de transações, operações criptográficas e comunicação de rede. Construída com foco em casos de uso Web3 e blockchain, suporta o desenvolvimento de aplicações descentralizadas seguras. A biblioteca é de código aberto e mantida por Archethic.net.
Casos de uso
Criando transações de blockchain
Enviando dados para a rede Archethic
Construindo aplicativos descentralizados (dApps)
Integração com a blockchain da Archethic
Habilitar mensagens seguras ponto a ponto
Apoiar a gestão de identidade digital
Principais recursos
Ferramentas de criação de transação
Suporte de assinatura criptográfica
Compatibilidade multiplataforma (Node e navegador)
Integração fácil com o Flutter
Open-source e ativamente mantido
Design leve e modular
Indicado para
Desenvolvedores Flutter construindo dApps
criadores de aplicativos Web3
entusiastas de blockchain
integradores da rede Archethic
Aplicativos móveis e web voltados para cripto
Desenvolvedores que precisam de tratamento seguro de transações
Considerações
Requer conhecimento sobre conceitos da blockchain Archethic
Documentação disponível limitada
Depende de nós externos da rede Archethic
Não adequado para desenvolvimento de protocolos blockchain de baixo nível
Pode exigir tratamento adicional de erros em produção
O comportamento específico da plataforma pode variar entre Node e navegador
README original
Snapshot do README original do repositório-fonte vinculado. Consulte o repositório para o conteúdo mais recente.
Archethic's lib_dart
Archethic dart library for Flutter
Usage
This library aims to provide a easy way to create Archethic transaction and to send them over the network.
It supports the Archethic Cryptography rules which are:
Algorithm identification: keys are prepared by metadata bytes to indicate the curve used and the origin of the generation, and hashes are prepended by a byte to indicate the hash algorithm used.
Those information help during the verification
To be able to retrieve previous public key, the Archethic network designs the key derivation through a seed (passphrase) and an index(number of
previous public keys/transactions).
The procedure is described as follows:
The seed generates a master key and an entropy used in the child keys generation.
/ (256 bytes) Next private key
(256 bytes) Master key --> HMAC-512
/ Key: Master entropy,
seed --> HMAC-512Data: Master key + index)
\
(256 bytes) Master entropy
API
Cryptographic functions
deriveKeyPair(seed, index, curve, isSeedHexa)
It creates a new keypair into hexadecimal format
seed is hexadecimal encoding or Uint8Array representing the transaction chain seed to be able to derive and generate the keys
index is the number of transactions in the chain, to generate the actual and the next public key (see below the cryptography section)
curve is the elliptic curve to use for the key generation (can be "ed25519", "P256", "secp256k1") - default to: "ed25519"
isSeedHexa is a parameter used to specify whether the information is in hexadecimal format or not (and thus avoid conversion issues).
originId is the origin of the public key (can be 0 for "on chain wallet", 1 for "software" or 2 for "tpm") - default to: 1
new Transaction(type) creates a new instance of the transaction
type is the string defining the type of transaction to generate ("keychain", "keychain_access", "transfer", "hosting", "code_proposal", "code_approval", "token", "contract", "data")
The transaction instance contains the following methods:
setCode(code) (before transaction version 4)
Add the code in the data.code section of the transaction
code is a string defining the smart contract
This method is available for transaction version <= 3
setContract(contract) (after transaction version 4)
Add the contract in the data.contract section of the transaction
contract is an object with following keys:
bytecodeUint8List of the compiled wasm code compressed using zip
manifest the manifest of the contrat containing actions and functions spec
setContent(content)
Add the content in the data.content section of the transaction
content is a string defining the smart contract
addOwnership(secret, authorizedKeys)
Add an ownership in the data.ownerships section of the transaction with a secret and its related authorized public keys to be able to decrypt it.
This aims to prove the ownership or the delegatation of some secret to a given list of public keys.
secret is the hexadecimal encoding or Uint8Array representing the encrypted secret
authorizedKeys is a list of object represented by
publicKey is the hexadecimal encoding or Uint8Array representing the public key
encryptedSecretKey is the hexadecimal encoding or Uint8Array representing the secret key encrypted with the public key (see ecEncrypt)
addUCOTransfer(to, amount)
Add a UCO transfer to the data.ledger.uco.transfers section of the transaction
to is hexadecimal encoding or Uint8List representing the transaction address (recipient) to receive the funds
Sign the transaction with an origin device private key
privateKey is hexadecimal encoding or Uint8List representing the private key to generate the origin signature to able to perform the ProofOfWork and authorize the transaction
Query a node to add a new origin public to be authorized to sign transaction with the corresponding private key (see OriginSign).
Calls the 'add_origin_key' JSON-RPC 2.0 method
originPublicKey is the public key to be added.
certificate is the certificate that prove the public key is allowed to be added.
Fetch the OracleChain data
return a value of Oracle Uco_Price in {OracleUcoPrice} from a timestamp
If timestamp = 0 or not precised, the last price is returned
timestamp: UNIX timestamp (optional)
import'package:archethic_lib_dart/archethic_lib_dart.dart';
final oracleData =
awaitOracleService('https://testnet.archethic.net').getOracleData(timestamp);
final eurConversionRate = oracleUcoPrice.uco?.eur;
final usdConversionRate = oracleUcoPrice.uco?.usd;
getTransactionFee(tx)
Query a node to fetch the tx fee for a given transaction
Calls the 'estimate_transaction_fee' JSON-RPC 2.0 method
Once retrieved the keychain provide the following methods:
buildTransaction(tx, serviceName, index, suffix)
Generate address, previousPublicKey, previousSignature of the transaction and
serialize it using a custom binary protocol, based on the derivation path, curve and hash algo of the service given in param.
tx is an instance of Transaction
serviceName is the service name to use for getting the derivation path, the curve and the hash algo
index is the number of transactions in the chain, to generate the actual and the next public key (see the cryptography section)
suffix: Additional information to add to a service derivation path (default to empty)
Return is the signed Transaction. Notice that the function also sign the Transaction given in param, so getting the return is not mandatory
Use ec encryption on the seed for the list of authorizedPublicKeys
service: Service name to identify the derivation path to use
authorizedPublicKeys: List of public keys to encrypt the service seed
final keychain = Keychain(seed: hexToUint8List(generateRandomSeed())).copyWithService('uco', "m/650'/uco");
final storageNoncePublicKey = awaitApiService('https://testnet.archethic.net').getStorageNoncePublicKey();
final resultECEncryptServiceSeed = keychain.ecEncryptServiceSeed('uco', [storageNoncePublicKey]);
final secret = uint8ListToHex(resultECEncryptServiceSeed.secret);
final authorizedPublicKeys = resultECEncryptServiceSeed.authorizedPublicKeys;
// secret and authorizedPublicKeys can be used to create an ownershipfinal tx = Transaction(
type: 'contract',
data: Transaction.initData(),
).addOwnership(secret, authorizedPublicKeys);
toDID()
Return a Decentralized Identity document from the keychain. (This is used in the transaction's content of the keychain tx)
Keychain keychain = awaitApiService('https://testnet.archethic.net').getKeychain(accessKeychainSeed);
finalMap<String, dynamic> did = keychain.toDID();
log(did)
{
"@context": [
"https://www.w3.org/ns/did/v1"
],
"id": "did:archethic:keychain_address",
"authentification": servicesMaterials, //list of public keys of the services"verificationMethod": servicesMaterials //list of public keys of the services
}