postchain-client 1.0.2 → 1.1.0
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/README.md +30 -49
- package/built/cjs/index.js +2571 -0
- package/built/cjs/index.js.map +1 -0
- package/built/esm/index.js +29927 -0
- package/built/esm/index.js.map +1 -0
- package/built/index.js +21 -3
- package/built/index.js.map +1 -0
- package/built/src/chromia/chromiaClientProvider.js +35 -0
- package/built/src/chromia/chromiaClientProvider.js.map +1 -0
- package/built/src/chromia/errors.js +6 -0
- package/built/src/chromia/errors.js.map +1 -0
- package/built/src/chromia/interfaces.js +2 -0
- package/built/src/chromia/interfaces.js.map +1 -0
- package/built/src/encryption/encryption.js +105 -0
- package/built/src/encryption/encryption.js.map +1 -0
- package/built/src/encryption/errors.js +11 -0
- package/built/src/encryption/errors.js.map +1 -0
- package/built/src/encryption/types.js +2 -0
- package/built/src/encryption/types.js.map +1 -0
- package/built/src/formatter.d.ts +2 -0
- package/built/src/formatter.js +119 -0
- package/built/src/formatter.js.map +1 -0
- package/built/src/gtv/definition.js +20 -0
- package/built/src/gtv/definition.js.map +1 -0
- package/built/src/gtv/index.d.ts +1 -0
- package/built/src/gtv/index.js +11 -0
- package/built/src/gtv/index.js.map +1 -0
- package/built/src/gtv/types.d.ts +2 -3
- package/built/src/gtv/types.js +2 -0
- package/built/src/gtv/types.js.map +1 -0
- package/built/src/gtx/errors.js +26 -0
- package/built/src/gtx/errors.js.map +1 -0
- package/built/src/gtx/gtx.d.ts +1 -1
- package/built/src/gtx/gtx.js +115 -0
- package/built/src/gtx/gtx.js.map +1 -0
- package/built/src/gtx/gtxclient.js +77 -0
- package/built/src/gtx/gtxclient.js.map +1 -0
- package/built/src/gtx/index.js +5 -0
- package/built/src/gtx/index.js.map +1 -0
- package/built/src/gtx/interfaces.js +2 -0
- package/built/src/gtx/interfaces.js.map +1 -0
- package/built/src/gtx/serialization.d.ts +3 -2
- package/built/src/gtx/serialization.js +95 -0
- package/built/src/gtx/serialization.js.map +1 -0
- package/built/src/gtx/types.d.ts +10 -1
- package/built/src/gtx/types.js +2 -0
- package/built/src/gtx/types.js.map +1 -0
- package/built/src/logger.d.ts +2 -1
- package/built/src/logger.js +53 -0
- package/built/src/logger.js.map +1 -0
- package/built/src/merkle/binarytree.d.ts +137 -0
- package/built/src/merkle/binarytree.js +146 -0
- package/built/src/merkle/binarytree.js.map +1 -0
- package/built/src/merkle/binarytreefactory.d.ts +86 -0
- package/built/src/merkle/binarytreefactory.js +235 -0
- package/built/src/merkle/binarytreefactory.js.map +1 -0
- package/built/src/merkle/merkleHelper.js +109 -0
- package/built/src/merkle/merkleHelper.js.map +1 -0
- package/built/src/merkle/merklehashcalculator.d.ts +35 -0
- package/built/src/merkle/merklehashcalculator.js +71 -0
- package/built/src/merkle/merklehashcalculator.js.map +1 -0
- package/built/src/merkle/path.d.ts +155 -0
- package/built/src/merkle/path.js +306 -0
- package/built/src/merkle/path.js.map +1 -0
- package/built/src/merkle/proof/merklehashcarrier.d.ts +17 -0
- package/built/src/merkle/proof/merklehashcarrier.js +23 -0
- package/built/src/merkle/proof/merklehashcarrier.js.map +1 -0
- package/built/src/merkle/proof/merklehashsummaryfactory.d.ts +53 -0
- package/built/src/merkle/proof/merklehashsummaryfactory.js +81 -0
- package/built/src/merkle/proof/merklehashsummaryfactory.js.map +1 -0
- package/built/src/merkle/proof/merkleproof.d.ts +35 -0
- package/built/src/merkle/proof/merkleproof.js +59 -0
- package/built/src/merkle/proof/merkleproof.js.map +1 -0
- package/built/src/merkle/proof/merkleprooftree.d.ts +130 -0
- package/built/src/merkle/proof/merkleprooftree.js +116 -0
- package/built/src/merkle/proof/merkleprooftree.js.map +1 -0
- package/built/src/merkle/proof/merkleprooftreefactory.d.ts +47 -0
- package/built/src/merkle/proof/merkleprooftreefactory.js +121 -0
- package/built/src/merkle/proof/merkleprooftreefactory.js.map +1 -0
- package/built/src/merkle/types.js +2 -0
- package/built/src/merkle/types.js.map +1 -0
- package/built/src/restclient/errors.js +54 -0
- package/built/src/restclient/errors.js.map +1 -0
- package/built/src/restclient/interfaces.d.ts +2 -1
- package/built/src/restclient/interfaces.js +2 -0
- package/built/src/restclient/interfaces.js.map +1 -0
- package/built/src/restclient/restclient.js +309 -0
- package/built/src/restclient/restclient.js.map +1 -0
- package/built/src/restclient/restclientutil.d.ts +4 -0
- package/built/src/restclient/restclientutil.js +137 -0
- package/built/src/restclient/restclientutil.js.map +1 -0
- package/built/src/restclient/types.d.ts +4 -0
- package/built/src/restclient/types.js +13 -0
- package/built/src/restclient/types.js.map +1 -0
- package/built/umd/index.js +29931 -0
- package/built/umd/index.js.map +1 -0
- package/package.json +30 -17
- package/built/index.js.LICENSE.txt +0 -657
package/README.md
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
```javascript
|
|
6
6
|
let crypto = require("crypto");
|
|
7
7
|
let secp256k1 = require("secp256k1");
|
|
8
|
+
let { encryption } = require("postchain-client")
|
|
8
9
|
|
|
9
10
|
// Create some dummy keys
|
|
10
11
|
let signerPrivKeyA = Buffer.alloc(32, "a");
|
|
@@ -12,6 +13,12 @@ let signerPubKeyA = secp256k1.publicKeyCreate(signerPrivKeyA);
|
|
|
12
13
|
let signerPrivKeyB = Buffer.alloc(32, "b");
|
|
13
14
|
let signerPubKeyB = secp256k1.publicKeyCreate(signerPrivKeyB);
|
|
14
15
|
|
|
16
|
+
// Create a simple signature provider.
|
|
17
|
+
// This is the standard way of signing a message using the gtxClient,
|
|
18
|
+
// and it can be used with the restClient too. Look further below for
|
|
19
|
+
// more details on how to use it.
|
|
20
|
+
let signatureProviderA = newSignatureProvider({privKey: signerPrivKeyA})
|
|
21
|
+
|
|
15
22
|
// The lower-level client that can be used for any
|
|
16
23
|
// postchain client messages. It only handles binary data.
|
|
17
24
|
let restClient = require("postchain-client").restClient;
|
|
@@ -47,7 +54,7 @@ let gtx = gtxClient.createClient(rest, blockchainRID, ["fun1", "fun2"]);
|
|
|
47
54
|
// Start a new request. A request instance is created.
|
|
48
55
|
// The public keys are the keys that must sign the request
|
|
49
56
|
// before sending it to postchain. Can be empty.
|
|
50
|
-
let req = gtx.newTransaction([
|
|
57
|
+
let req = gtx.newTransaction([signatureProviderA.pubKey, signerPubKeyB]);
|
|
51
58
|
|
|
52
59
|
// call fun1 with three arguments: a string, an array and a Buffer
|
|
53
60
|
req.fun1("arg1", ["arg2", [1, 2]], Buffer.from("hello"));
|
|
@@ -57,14 +64,18 @@ req.fun1("arg1");
|
|
|
57
64
|
req.fun2(1, 2);
|
|
58
65
|
|
|
59
66
|
// Signing can be done either through the sign() function ...
|
|
60
|
-
// The
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
|
|
67
|
+
// The signatureProvider method sign() will be called, and
|
|
68
|
+
// it's expected to return the signature of the digest it's given
|
|
69
|
+
// as input (of type Buffer). It needs to return the output of
|
|
70
|
+
// secp256k1.ecdsaSign(...params).signature
|
|
71
|
+
await req.sign(signatureProviderA);
|
|
72
|
+
// You can also use this, if you don't need a signature provider
|
|
73
|
+
// The second parameter is optional, it will be generated if not given
|
|
74
|
+
//await req.sign(signerPrivKeyA, signerPubKeyA);
|
|
64
75
|
|
|
65
76
|
// ... or by the addSignature() function
|
|
66
77
|
let bufferToSign = req.getBufferToSign();
|
|
67
|
-
// Sign the buffer externally
|
|
78
|
+
// Sign the buffer externally.
|
|
68
79
|
let signatureFromB = askUserBToSign(bufferToSign);
|
|
69
80
|
// and add the signature to the request
|
|
70
81
|
req.addSignature(signerPubKeyB, signatureFromB);
|
|
@@ -81,25 +92,13 @@ req.send((error) => {
|
|
|
81
92
|
// understand the query object and typically perform a search using
|
|
82
93
|
// the database connection readOnlyConn. The backend query function
|
|
83
94
|
// can return any serializable result object you chose
|
|
84
|
-
|
|
85
|
-
let resultHandler = (error, result) => {
|
|
86
|
-
if (error) {
|
|
87
|
-
console.error(error);
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (result.hits == 0) {
|
|
91
|
-
// Poll every 2 seconds
|
|
92
|
-
setTimeout(gtx.query(queryObject, resultHandler), 2000);
|
|
93
|
-
}
|
|
94
|
-
console.log(JSON.stringify(result));
|
|
95
|
-
};
|
|
96
|
-
gtx.query(queryObject, resultHandler);
|
|
95
|
+
gtx.query("findStuff", { text: "arg1" });
|
|
97
96
|
|
|
98
97
|
// This will make a request with a single operation
|
|
99
98
|
// and a single signature.
|
|
100
|
-
req = gtx.newTransaction(blockchainRID, [
|
|
99
|
+
req = gtx.newTransaction(blockchainRID, [signatureProviderA.pubkey]);
|
|
101
100
|
req.fun1("arg1");
|
|
102
|
-
req.sign(
|
|
101
|
+
await req.sign(signatureProviderA);
|
|
103
102
|
req.send((error) => {
|
|
104
103
|
if (!error) {
|
|
105
104
|
done();
|
|
@@ -111,12 +110,21 @@ function sha256(buffer) {
|
|
|
111
110
|
}
|
|
112
111
|
|
|
113
112
|
// This is to demonstrate that you can use external signing
|
|
114
|
-
// mechanisms.
|
|
113
|
+
// mechanisms. It could be a complex function, requiring you
|
|
114
|
+
// to sign from your phone, another device, or something else again
|
|
115
115
|
function askUserBToSign(buffer) {
|
|
116
116
|
// The signed digest is a double sha-256
|
|
117
117
|
var digest = sha256(sha256(buffer));
|
|
118
118
|
return secp256k1.sign(digest, signerPrivKeyB).signature;
|
|
119
119
|
}
|
|
120
|
+
|
|
121
|
+
// The complex signature process can, however, even be implemented in
|
|
122
|
+
// a signatureProvider. Once you have a callback like the one above,
|
|
123
|
+
// it's a simple matter of making a signature provider:
|
|
124
|
+
let signatureProviderB {
|
|
125
|
+
pubKey: signerPubKeyB,
|
|
126
|
+
sign: askUserBToSign
|
|
127
|
+
}
|
|
120
128
|
```
|
|
121
129
|
|
|
122
130
|
A very simple backend for the above client might look like this:
|
|
@@ -199,30 +207,3 @@ The first four arguments to backend.fun1 are
|
|
|
199
207
|
- `call_index`, 0 in this example. It's the index within the GTX of the current call
|
|
200
208
|
- `signers`, all signers of this GTX. The signatures from these signers are already verified by
|
|
201
209
|
the GTX framework when the backend function is called.
|
|
202
|
-
|
|
203
|
-
## Release notes
|
|
204
|
-
See more release notes [here](./docs/release-notes/).
|
|
205
|
-
### 1.0.0
|
|
206
|
-
- New logger accessible in index.ts.
|
|
207
|
-
- Enable the client to connect to a blockchain through multiple nodes running the blockchain.
|
|
208
|
-
- Load balancing by randomly distributing transactions and queries between nodes.
|
|
209
|
-
- Retry policy added for HTTP request to the blockchain.
|
|
210
|
-
- Enables you to discover the nodes running your blockchain by querying D1 with your dapp´s blockchain RID. Read more in the Chromia client providers [Readme](./src/chromia/README.md).
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
Breaking changes:
|
|
214
|
-
|
|
215
|
-
- Previously a rest client was initialized with one string containing the address of the node running your blockchain. Now an instance of the rest client is initiated with a list of strings representing the addresses of the nodes where your dapp is running.
|
|
216
|
-
- Previously a rest client query was called with two parameters; queryName and queryObject. Now this call only takes one parameter called queryObject, which is defined as:
|
|
217
|
-
```javascript
|
|
218
|
-
{
|
|
219
|
-
type: string;
|
|
220
|
-
[arg: string]: RawGtv;
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
where type is what previously was called query name.
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
### 0.\*.*
|
|
228
|
-
Early version of the postchain-client written in javascript.
|