postchain-client 0.9.2 → 0.10.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/aa.js ADDED
@@ -0,0 +1,51 @@
1
+ var restClient = require('./src/restclient');
2
+ var gtxClient = require('./src/gtx/gtxclient');
3
+ var gtx = require('./src/gtx/gtx');
4
+ const gtv = require('./src/gtv');
5
+ exports.restClient = restClient;
6
+ exports.gtx = gtx;
7
+ exports.gtv = gtv;
8
+ exports.gtxClient = gtxClient;
9
+ var util = require('./src/util');
10
+ exports.util = util;
11
+
12
+ let crypto = require('crypto');
13
+ let secp256k1 = require('secp256k1');
14
+
15
+ var blockchainRID = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
16
+
17
+ let signerPrivKeyA = Buffer.alloc(32, 'a');
18
+ let signerPubKeyA = Buffer.from('02e5a018b3a2e155316109d9cdc5eab739759c0e07e0c00bf9fccb8237fe4d7f02', 'hex');
19
+ //let signerPubKeyA = secp256k1.publicKeyCreate(signerPrivKeyA);
20
+ //console.log(signerPubKeyA.toString('hex'));
21
+ let signerPrivKeyB = Buffer.alloc(32, 'b');
22
+ let signerPubKeyB = secp256k1.publicKeyCreate(signerPrivKeyB);
23
+
24
+ // The lower-level client that can be used for any
25
+ // postchain client messages. It only handles binary data.
26
+ var rest = restClient.createRestClient("http://localhost:7740", blockchainRID);
27
+
28
+ // Create an instance of the higher-level gtx client. It will
29
+ // use the rest client instance and it will allow calls to functions
30
+ // fun1 and fun2. The backend implementation in Postchain must
31
+ // provide those functions.
32
+ var gtxcs = gtxClient.createClient(rest, Buffer.from(blockchainRID, 'hex'), ["create_user", "nop"]);
33
+
34
+ // Start a new request. A request instance is created.
35
+ // The public keys are the keys that must sign the request
36
+ // before sending it to postchain. Can be empty.
37
+ var req = gtxcs.newTransaction([signerPubKeyA]);
38
+
39
+ // call fun1 with three arguments: a string, an array and a Buffer
40
+ //req.addOperation("insert_city_dict", {"name": "Hamburg"});
41
+ req.addOperation('create_user', signerPubKeyA, "Peter");
42
+ req.addOperation('nop', 1000);
43
+ /*
44
+ req.addOperation("create_user", new dynamic[] {pubKey, "Peter"});
45
+ req.addOperation("nop", new dynamic[] {1000});
46
+ */
47
+
48
+
49
+ req.sign(signerPrivKeyA, signerPubKeyA);
50
+
51
+ req.postAndWaitConfirmation();