/
example.dart
56 lines (52 loc) · 1.86 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ignore_for_file: unused_local_variable
import 'package:archethic_lib_dart/src/model/transaction.dart';
import 'package:archethic_lib_dart/src/utils/crypto.dart';
import 'package:archethic_lib_dart/src/utils/utils.dart';
import 'package:pinenacl/encoding.dart';
void main(List<String> args) {
/// It creates a new keypair into hexadecimal format
final keypair =
deriveKeyPair('mysuperpassphraseorseed', 0, isSeedHexa: false);
/// Generate `address`, `timestamp`, `previousPublicKey`, `previousSignature`, `originSignature` of the transaction and
/// serialize it using a custom binary protocol.
final transaction = Transaction(
type: 'transfer',
data: Transaction.initData(),
)
.addUCOTransfer(
'00b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646',
toBigInt(0.420),
)
.build('mysuperpassphraseorseed', 0, curve: 'P256')
.transaction
..convertToJSON();
/// Sign the transaction with an origin device private key
final originKeypair = deriveKeyPair('origin_seed', 0, isSeedHexa: false);
final transaction2 = Transaction(
type: 'transfer',
data: Transaction.initData(),
)
.addUCOTransfer(
'00b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646',
toBigInt(0.420),
)
.build('mysuperpassphraseorseed', 0, curve: 'P256')
.transaction
.originSign(
uint8ListToHex(
Uint8List.fromList(originKeypair.privateKey!),
),
)..convertToJSON();
/// Export the transaction generated into JSON
final transaction3 = Transaction(
type: 'transfer',
data: Transaction.initData(),
)
.addUCOTransfer(
'00b1d3750edb9381c96b1a975a55b5b4e4fb37bfab104c10b0b6c9a00433ec4646',
toBigInt(0.420),
)
.build('mysuperpassphraseorseed', 0, curve: 'P256')
.transaction
..convertToJSON();
}