postchain-client 1.3.2 → 1.5.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 +244 -167
- package/built/cjs/index.js +589 -46
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +31594 -34572
- package/built/esm/index.js.map +1 -1
- package/built/index.d.ts +2 -0
- package/built/index.js +2 -0
- package/built/index.js.map +1 -1
- package/built/src/blockchainClient/blockchainClient.d.ts +3 -0
- package/built/src/blockchainClient/blockchainClient.js +251 -0
- package/built/src/blockchainClient/blockchainClient.js.map +1 -0
- package/built/src/blockchainClient/errors.d.ts +15 -0
- package/built/src/blockchainClient/errors.js +26 -0
- package/built/src/blockchainClient/errors.js.map +1 -0
- package/built/src/blockchainClient/interface.d.ts +108 -0
- package/built/src/blockchainClient/interface.js +2 -0
- package/built/src/blockchainClient/interface.js.map +1 -0
- package/built/src/blockchainClient/types.d.ts +91 -0
- package/built/src/blockchainClient/types.js +8 -0
- package/built/src/blockchainClient/types.js.map +1 -0
- package/built/src/blockchainClient/utils.d.ts +18 -0
- package/built/src/blockchainClient/utils.js +157 -0
- package/built/src/blockchainClient/utils.js.map +1 -0
- package/built/src/gtv/definition.js +1 -1
- package/built/src/gtv/definition.js.map +1 -1
- package/built/src/gtx/errors.js +1 -1
- package/built/src/gtx/errors.js.map +1 -1
- package/built/src/gtx/gtx.d.ts +4 -3
- package/built/src/gtx/gtx.js +17 -9
- package/built/src/gtx/gtx.js.map +1 -1
- package/built/src/promiEvent/promiEventEmitter.d.ts +24 -0
- package/built/src/promiEvent/promiEventEmitter.js +56 -0
- package/built/src/promiEvent/promiEventEmitter.js.map +1 -0
- package/built/src/promiEvent/promiEvents.d.ts +12 -0
- package/built/src/promiEvent/promiEvents.js +61 -0
- package/built/src/promiEvent/promiEvents.js.map +1 -0
- package/built/src/restclient/errors.d.ts +1 -1
- package/built/src/restclient/errors.js +6 -2
- package/built/src/restclient/errors.js.map +1 -1
- package/built/src/restclient/restclient.d.ts +15 -0
- package/built/src/restclient/restclient.js +10 -6
- package/built/src/restclient/restclient.js.map +1 -1
- package/built/src/restclient/restclientutil.d.ts +2 -1
- package/built/src/restclient/restclientutil.js.map +1 -1
- package/built/umd/index.js +31594 -34570
- package/built/umd/index.js.map +1 -1
- package/package.json +4 -3
package/built/index.d.ts
CHANGED
|
@@ -8,3 +8,5 @@ export * as merkle from "./src/merkle/merkleHelper";
|
|
|
8
8
|
export * as encryption from "./src/encryption/encryption";
|
|
9
9
|
export * as restClientutil from "./src/restclient/restclientutil";
|
|
10
10
|
export * as chromiaClient from "./src/chromia/chromiaClientProvider";
|
|
11
|
+
export { createClient } from "./src/blockchainClient/blockchainClient";
|
|
12
|
+
export { newSignatureProvider } from "./src/gtx/gtx";
|
package/built/index.js
CHANGED
|
@@ -18,4 +18,6 @@ import * as restClientutil_1 from "./src/restclient/restclientutil";
|
|
|
18
18
|
export { restClientutil_1 as restClientutil };
|
|
19
19
|
import * as chromiaClient_1 from "./src/chromia/chromiaClientProvider";
|
|
20
20
|
export { chromiaClient_1 as chromiaClient };
|
|
21
|
+
export { createClient } from "./src/blockchainClient/blockchainClient";
|
|
22
|
+
export { newSignatureProvider } from "./src/gtx/gtx";
|
|
21
23
|
//# sourceMappingURL=index.js.map
|
package/built/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"uBAAqB,iBAAiB;kBAA1B,GAAG;6BACY,iBAAiB;wBAAhC,SAAS;uBACA,eAAe;kBAAxB,GAAG;6BACY,qBAAqB;wBAApC,SAAS;8BACO,6BAA6B;yBAA7C,UAAU;0BACE,cAAc;qBAA1B,MAAM;0BACM,2BAA2B;qBAAvC,MAAM;8BACU,6BAA6B;yBAA7C,UAAU;kCACU,iCAAiC;6BAArD,cAAc;iCACK,qCAAqC;4BAAxD,aAAa"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"uBAAqB,iBAAiB;kBAA1B,GAAG;6BACY,iBAAiB;wBAAhC,SAAS;uBACA,eAAe;kBAAxB,GAAG;6BACY,qBAAqB;wBAApC,SAAS;8BACO,6BAA6B;yBAA7C,UAAU;0BACE,cAAc;qBAA1B,MAAM;0BACM,2BAA2B;qBAAvC,MAAM;8BACU,6BAA6B;yBAA7C,UAAU;kCACU,iCAAiC;6BAArD,cAAc;iCACK,qCAAqC;4BAAxD,aAAa;AACzB,OAAO,EAAE,YAAY,EAAE,MAAM,yCAAyC,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { randomBytes } from "crypto";
|
|
11
|
+
import _ from "lodash";
|
|
12
|
+
import { logger } from "../..";
|
|
13
|
+
import { toBuffer, toString, toQueryObjectGTV } from "../formatter";
|
|
14
|
+
import { encodeValue } from "../gtx/serialization";
|
|
15
|
+
import { handleGetResponse, handlePostResponse, } from "../restclient/restclient";
|
|
16
|
+
import { requestWithRetry } from "../restclient/restclientutil";
|
|
17
|
+
import { Method } from "../restclient/types";
|
|
18
|
+
import * as gtxTool from "../gtx/gtx";
|
|
19
|
+
import { ResponseStatus, } from "./types";
|
|
20
|
+
import { LostMessageError, TxRejectedError, UnexpectedResponseError, UnvalidTxRidException, } from "../restclient/errors";
|
|
21
|
+
import { callbackPromiseBuilder, getConfig, getGTXFromBufferOrTransactionOrOperation, getSerializedGTX, handlePostResponsePromisified, validTxRID, } from "./utils";
|
|
22
|
+
import { Web3PromiEvent } from "../promiEvent/promiEvents";
|
|
23
|
+
import { NumberOfSignersAndSignaturesException } from "../gtx/errors";
|
|
24
|
+
import { makeKeyPair } from "../encryption/encryption";
|
|
25
|
+
import { getTransactionRIDException } from "./errors";
|
|
26
|
+
export function createClient(settings) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const blockchainRID = settings.blockchainRID;
|
|
29
|
+
return {
|
|
30
|
+
config: yield getConfig(settings),
|
|
31
|
+
query(nameOrQueryObject, args, callback) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
let _name, _args;
|
|
34
|
+
if (typeof nameOrQueryObject === "string") {
|
|
35
|
+
_name = nameOrQueryObject;
|
|
36
|
+
_args = args;
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
_name = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.name;
|
|
40
|
+
_args = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.args;
|
|
41
|
+
}
|
|
42
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(_name, _args)));
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
handlePostResponse(error, statusCode, rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
signTransaction(transaction, signMethod, callback) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const signMethodIsPrivKey = "privKey" in signMethod;
|
|
51
|
+
logger.debug(`signing transaction with ${signMethodIsPrivKey
|
|
52
|
+
? "privkey: " + signMethod.privKey.toString("hex")
|
|
53
|
+
: "signature provider [pubkey: " + toString(signMethod.pubKey) + "]"}`);
|
|
54
|
+
const gtx = getGTXFromBufferOrTransactionOrOperation(transaction, this.config.blockchainRID);
|
|
55
|
+
try {
|
|
56
|
+
const signedTx = yield (signMethodIsPrivKey
|
|
57
|
+
? gtxTool.sign(gtx, signMethod.privKey, signMethod.pubKey)
|
|
58
|
+
: gtxTool.sign(gtx, signMethod));
|
|
59
|
+
const gtxBytes = getSerializedGTX(signedTx);
|
|
60
|
+
if (typeof callback === "function") {
|
|
61
|
+
callback(null, gtxBytes);
|
|
62
|
+
}
|
|
63
|
+
return gtxBytes;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
if (typeof callback === "function") {
|
|
67
|
+
callback(error, null);
|
|
68
|
+
}
|
|
69
|
+
throw new Error(error);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
sendTransaction(transaction, callback) {
|
|
74
|
+
const promiEvent = new Web3PromiEvent((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const gtx = getGTXFromBufferOrTransactionOrOperation(transaction, this.config.blockchainRID);
|
|
76
|
+
if (gtx.signers.length !== gtx.signatures.length) {
|
|
77
|
+
reject(new NumberOfSignersAndSignaturesException());
|
|
78
|
+
}
|
|
79
|
+
const gtxBytes = getSerializedGTX(gtx);
|
|
80
|
+
const transactionObject = {
|
|
81
|
+
tx: gtxBytes.toString("hex"),
|
|
82
|
+
};
|
|
83
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, "tx/" + blockchainRID, this.config, transactionObject);
|
|
84
|
+
const transactionRID = gtxTool.getDigestToSign(gtx);
|
|
85
|
+
try {
|
|
86
|
+
yield handlePostResponsePromisified(error, statusCode, rspBody);
|
|
87
|
+
if (typeof callback === "function") {
|
|
88
|
+
callback(null, {
|
|
89
|
+
status: ResponseStatus.Waiting,
|
|
90
|
+
statusCode,
|
|
91
|
+
transactionRID,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (_error) {
|
|
96
|
+
if (typeof callback === "function") {
|
|
97
|
+
callback(_error, null);
|
|
98
|
+
}
|
|
99
|
+
return reject(_error);
|
|
100
|
+
}
|
|
101
|
+
promiEvent.emit("sent", {
|
|
102
|
+
status: ResponseStatus.Waiting,
|
|
103
|
+
statusCode: statusCode,
|
|
104
|
+
transactionRID,
|
|
105
|
+
});
|
|
106
|
+
const waitConfirmation = (txRID) => {
|
|
107
|
+
return new Promise((resolve, reject) => {
|
|
108
|
+
this.getTransactionStatus(txRID, (error, result) => {
|
|
109
|
+
if (error) {
|
|
110
|
+
reject(error);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const status = result.status;
|
|
114
|
+
switch (status) {
|
|
115
|
+
case ResponseStatus.Confirmed:
|
|
116
|
+
resolve(ResponseStatus.Confirmed);
|
|
117
|
+
break;
|
|
118
|
+
case ResponseStatus.Rejected:
|
|
119
|
+
reject(new TxRejectedError(result.rejectReason));
|
|
120
|
+
break;
|
|
121
|
+
case ResponseStatus.Unknown:
|
|
122
|
+
reject(new LostMessageError());
|
|
123
|
+
break;
|
|
124
|
+
case ResponseStatus.Waiting:
|
|
125
|
+
setTimeout(() => waitConfirmation(txRID).then(resolve, reject), this.config.pollingInterval);
|
|
126
|
+
break;
|
|
127
|
+
default:
|
|
128
|
+
logger.error(status);
|
|
129
|
+
reject(new UnexpectedResponseError());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
try {
|
|
136
|
+
waitConfirmation(gtxTool.getDigestToSign(gtx)).then((confirmationStatus) => {
|
|
137
|
+
resolve({
|
|
138
|
+
status: confirmationStatus,
|
|
139
|
+
statusCode: statusCode,
|
|
140
|
+
transactionRID,
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
reject(error);
|
|
146
|
+
}
|
|
147
|
+
}));
|
|
148
|
+
return promiEvent;
|
|
149
|
+
},
|
|
150
|
+
signAndSendUniqueTransaction(transactionOrOperation, signMethod, callback) {
|
|
151
|
+
const promiEvent = new Web3PromiEvent((resolve, reject) => {
|
|
152
|
+
const signMethodIsPrivKey = "privKey" in signMethod;
|
|
153
|
+
let _pubKey;
|
|
154
|
+
if (signMethodIsPrivKey) {
|
|
155
|
+
_pubKey = !signMethod.pubKey
|
|
156
|
+
? makeKeyPair(signMethod.privKey).pubKey
|
|
157
|
+
: signMethod.pubKey;
|
|
158
|
+
}
|
|
159
|
+
const transaction = "name" in transactionOrOperation
|
|
160
|
+
? {
|
|
161
|
+
operations: [transactionOrOperation],
|
|
162
|
+
signers: [signMethod.pubKey || _pubKey],
|
|
163
|
+
}
|
|
164
|
+
: transactionOrOperation;
|
|
165
|
+
const hasNop = transaction.operations.some((operation) => {
|
|
166
|
+
return operation.name === "nop";
|
|
167
|
+
});
|
|
168
|
+
const transactionWithNop = hasNop
|
|
169
|
+
? transaction
|
|
170
|
+
: this.addNop(transaction);
|
|
171
|
+
this.signTransaction(transactionWithNop, signMethod)
|
|
172
|
+
.then((signedTx) => {
|
|
173
|
+
const sendTransactionPromiEvent = this.sendTransaction(signedTx, callback);
|
|
174
|
+
sendTransactionPromiEvent.on("sent", (receipt) => {
|
|
175
|
+
promiEvent.emit("sent", receipt);
|
|
176
|
+
});
|
|
177
|
+
resolve(sendTransactionPromiEvent);
|
|
178
|
+
})
|
|
179
|
+
.catch((error) => {
|
|
180
|
+
reject(error);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
return promiEvent;
|
|
184
|
+
},
|
|
185
|
+
getTransaction(transactionRID, callback) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
187
|
+
if (!validTxRID(transactionRID)) {
|
|
188
|
+
if (typeof callback === "function") {
|
|
189
|
+
callback(new UnvalidTxRidException(transactionRID), null);
|
|
190
|
+
}
|
|
191
|
+
throw new UnvalidTxRidException(transactionRID);
|
|
192
|
+
}
|
|
193
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" + blockchainRID + "/" + transactionRID.toString("hex"), this.config);
|
|
194
|
+
return new Promise((resolve, reject) => {
|
|
195
|
+
handleGetResponse(error, statusCode, statusCode === 200 ? toBuffer(rspBody.tx) : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
},
|
|
199
|
+
getTransactionStatus(transactionRID, callback) {
|
|
200
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
201
|
+
if (!validTxRID(transactionRID)) {
|
|
202
|
+
const error = new UnvalidTxRidException(transactionRID);
|
|
203
|
+
if (typeof callback === "function") {
|
|
204
|
+
callback(error, null);
|
|
205
|
+
}
|
|
206
|
+
throw error;
|
|
207
|
+
}
|
|
208
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" +
|
|
209
|
+
blockchainRID +
|
|
210
|
+
"/" +
|
|
211
|
+
transactionRID.toString("hex") +
|
|
212
|
+
"/status", this.config);
|
|
213
|
+
return new Promise((resolve, reject) => {
|
|
214
|
+
handleGetResponse(error, statusCode, rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
},
|
|
218
|
+
addNop(transaction) {
|
|
219
|
+
const _transaction = _.cloneDeep(transaction);
|
|
220
|
+
const noOperation = {
|
|
221
|
+
name: "nop",
|
|
222
|
+
args: [randomBytes(32)],
|
|
223
|
+
};
|
|
224
|
+
_transaction.operations = [..._transaction.operations, noOperation];
|
|
225
|
+
return _transaction;
|
|
226
|
+
},
|
|
227
|
+
getTransactionRID(transaction) {
|
|
228
|
+
try {
|
|
229
|
+
const gtx = getGTXFromBufferOrTransactionOrOperation(transaction, this.config.blockchainRID);
|
|
230
|
+
return gtxTool.getDigestToSign(gtx);
|
|
231
|
+
}
|
|
232
|
+
catch (e) {
|
|
233
|
+
throw new getTransactionRIDException(e);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
encodeTransaction(transaction) {
|
|
237
|
+
const gtx = getGTXFromBufferOrTransactionOrOperation(transaction, this.config.blockchainRID);
|
|
238
|
+
return gtxTool.serialize(gtx);
|
|
239
|
+
},
|
|
240
|
+
decodeTransactionToGTX(encodedTransaction) {
|
|
241
|
+
const gtx = gtxTool.deserialize(encodedTransaction);
|
|
242
|
+
logger.debug(`Output from deserializing a raw transaction: ${JSON.stringify(gtx)}`);
|
|
243
|
+
return gtx;
|
|
244
|
+
},
|
|
245
|
+
getClientNodeURLPool() {
|
|
246
|
+
return this.config.endpointPool;
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=blockchainClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockchainClient.js","sourceRoot":"","sources":["../../../src/blockchainClient/blockchainClient.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EACL,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,MAAM,EAAmC,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,OAAO,MAAM,YAAY,CAAC;AAEtC,OAAO,EAML,cAAc,GAKf,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,gBAAgB,EAChB,eAA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CAAC,MAAM,CAAC,aAAa,CAC1B,CAAC;oBACF,OAAO,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;iBACrC;gBAAC,OAAO,CAAC,EAAE;oBACV,MAAM,IAAI,0BAA0B,CAAC,CAAC,CAAC,CAAC;iBACzC;YACH,CAAC;YAED,iBAAiB,CAAC,WAAwB;gBACxC,MAAM,GAAG,GAAG,wCAAwC,CAClD,WAAW,EACX,IAAI,CAAC,MAAM,CAAC,aAAa,CAC1B,CAAC;gBACF,OAAO,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;YAChC,CAAC;YAED,sBAAsB,CAAC,kBAA0B;gBAC/C,MAAM,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;gBACpD,MAAM,CAAC,KAAK,CACV,gDAAgD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CACtE,CAAC;gBACF,OAAO,GAAG,CAAC;YACb,CAAC;YAED,oBAAoB;gBAClB,OAAO,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC;YAClC,CAAC;SACF,CAAC;IACJ,CAAC;CAAA"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare class MissingPubKeyError extends Error {
|
|
2
|
+
constructor();
|
|
3
|
+
}
|
|
4
|
+
export declare class MissingBlockchainError extends Error {
|
|
5
|
+
constructor();
|
|
6
|
+
}
|
|
7
|
+
export declare class MissingNodeUrlError extends Error {
|
|
8
|
+
constructor();
|
|
9
|
+
}
|
|
10
|
+
export declare class InvalidTransactionFormatException extends Error {
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export declare class getTransactionRIDException extends Error {
|
|
14
|
+
constructor(error: Error);
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export class MissingPubKeyError extends Error {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(`No public key was provided`);
|
|
4
|
+
}
|
|
5
|
+
}
|
|
6
|
+
export class MissingBlockchainError extends Error {
|
|
7
|
+
constructor() {
|
|
8
|
+
super(`No target blockchain was provided`);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class MissingNodeUrlError extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(`No node url or directory node url was provided`);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class InvalidTransactionFormatException extends Error {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(`The transaction is not in the right format`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class getTransactionRIDException extends Error {
|
|
22
|
+
constructor(error) {
|
|
23
|
+
super(`"Error occurred while getting transaction RID:", ${error}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/blockchainClient/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C;QACE,KAAK,CAAC,4BAA4B,CAAC,CAAC;IACtC,CAAC;CACF;AACD,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C;QACE,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAC7C,CAAC;CACF;AACD,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C;QACE,KAAK,CAAC,gDAAgD,CAAC,CAAC;IAC1D,CAAC;CACF;AAED,MAAM,OAAO,iCAAkC,SAAQ,KAAK;IAC1D;QACE,KAAK,CAAC,4CAA4C,CAAC,CAAC;IACtD,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,KAAY;QACtB,KAAK,CAAC,oDAAoD,KAAK,EAAE,CAAC,CAAC;IACrE,CAAC;CACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { KeyPair } from "./types";
|
|
3
|
+
import { RawGtv } from "../gtv/types";
|
|
4
|
+
import { Web3PromiEvent } from "../promiEvent/promiEvents";
|
|
5
|
+
import { StatusObject } from "../restclient/types";
|
|
6
|
+
import { ClientConfig, Operation, QueryArguments, QueryCallback, QueryObject, SignatureProvider, SignedTransaction, Transaction, TransactionReceipt } from "./types";
|
|
7
|
+
import { GTX } from "../gtx/types";
|
|
8
|
+
export interface Queryable {
|
|
9
|
+
query<TArgs extends QueryArguments | undefined = QueryArguments, TReturn extends RawGtv = RawGtv>(nameOrQueryObject: string | QueryObject<TArgs>, args?: TArgs, callback?: QueryCallback<TReturn>): Promise<TReturn>;
|
|
10
|
+
}
|
|
11
|
+
export interface IClient extends Queryable {
|
|
12
|
+
config: ClientConfig;
|
|
13
|
+
/**
|
|
14
|
+
* Performs an asynchronous query to the Rell backend. Returns either a resolved or rejected promise. The input is the name of the query followed by the arguments of the
|
|
15
|
+
* query as an optional input argument.
|
|
16
|
+
*
|
|
17
|
+
* @template TArgs - The type of the query arguments. Defaults to `QueryArguments`.
|
|
18
|
+
* @template TReturn - The type of the query return value. Defaults to `RawGtv`.
|
|
19
|
+
* @param nameOrQueryObject - the name of the query in Rell or a QueryObject containing name and args
|
|
20
|
+
* @param args - The query argument following this pattern: { arg1: argValue1, arg2: argvalue2 }
|
|
21
|
+
* @param callback - A callback function to handle the query response. Parameters (error, signedTx).
|
|
22
|
+
* @returns - A promise that resolves with the query result.
|
|
23
|
+
*/
|
|
24
|
+
query<TArgs extends QueryArguments | undefined = QueryArguments, TReturn extends RawGtv = RawGtv>(nameOrQueryObject: string | QueryObject<TArgs>, args?: TArgs, callback?: QueryCallback<TReturn>): Promise<TReturn>;
|
|
25
|
+
/**
|
|
26
|
+
* Signs a transaction using the provided signing method. The signature provider must contain a public key and a `sign` function that returns the signature of a digest.
|
|
27
|
+
*
|
|
28
|
+
* @param transaction - The transaction or signed transaction to be signed.
|
|
29
|
+
* @param signMethod - The signing method, either a KeyPair or a SignatureProvider. A signature provider with a `sign` callback and a `pubkey` or a key pair where `pubKey`is optional.
|
|
30
|
+
* @param callback - A callback function to handle the signing result. Parameters (error, signedTx)
|
|
31
|
+
* * @returns - A promise that resolves with the signed transaction.
|
|
32
|
+
*/
|
|
33
|
+
signTransaction(transaction: Transaction | SignedTransaction, signMethod: KeyPair | SignatureProvider, callback?: (error: Error, signedTx: Buffer) => void): Promise<SignedTransaction>;
|
|
34
|
+
/**
|
|
35
|
+
* Sends a transaction to the blockchain.
|
|
36
|
+
*
|
|
37
|
+
* @param transaction - The signed transaction, transaction, or operation to send.
|
|
38
|
+
* @param callback - A callback function to handle the transaction receipt. Parameter (error, transactionReceipt).
|
|
39
|
+
* @returns - A Web3PromiEvent that resolves with the transaction receipt.
|
|
40
|
+
*/
|
|
41
|
+
sendTransaction(transaction: Transaction | SignedTransaction | Operation, callback?: (error: Error, transactionReceipt: TransactionReceipt) => void): Web3PromiEvent<TransactionReceipt, {
|
|
42
|
+
sent: TransactionReceipt;
|
|
43
|
+
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Signs and sends a transaction for inclusion in a block. It adds a nop
|
|
46
|
+
* if missing.
|
|
47
|
+
* @param transaction - The operation or transaction to sign and send.
|
|
48
|
+
* @param signMethod - The signing method, either a KeyPair or a SignatureProvider. A signature provider with a `sign` callback and a `pubkey` or a key pair where `pubKey`is optional.
|
|
49
|
+
* @param callback - A callback function to handle the transaction receipt.
|
|
50
|
+
* @returns - A Web3PromiEvent that resolves with the transaction receipt.
|
|
51
|
+
*
|
|
52
|
+
*/
|
|
53
|
+
signAndSendUniqueTransaction(transaction: Operation | Transaction, signMethod: KeyPair | SignatureProvider, callback?: (error: Error, transactionReceipt: TransactionReceipt) => void): Web3PromiEvent<TransactionReceipt, {
|
|
54
|
+
sent: TransactionReceipt;
|
|
55
|
+
}>;
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves a transaction given its transaction RID.
|
|
58
|
+
*
|
|
59
|
+
* @param transactionRID - The transaction RID.
|
|
60
|
+
* @param callback - A callback function to handle the serialized message. Parameters (error, serializedMessage) if first
|
|
61
|
+
* parameter is not null, an error occurred.
|
|
62
|
+
* If first parameter is null, then the second parameter is a buffer
|
|
63
|
+
* with the serialized client message. If no such client message exists,
|
|
64
|
+
* the callback will be called with (null, null).
|
|
65
|
+
* @returns- A promise that resolves with the serialized message of the transaction.
|
|
66
|
+
*/
|
|
67
|
+
getTransaction(transactionRID: Buffer, callback?: (error: Error, serializedMessage: Buffer) => void): Promise<Buffer>;
|
|
68
|
+
/**
|
|
69
|
+
* Retrieves the status of a transaction given its transaction RID.
|
|
70
|
+
*
|
|
71
|
+
* @param transactionRID - The transaction RID.
|
|
72
|
+
* @param callback - A callback function to handle the response body. Taking parameters (error, responseBody). If error is null
|
|
73
|
+
* then responseBody is an object on the form
|
|
74
|
+
* { status: '<confirmed|waiting|rejected|unknown>' }
|
|
75
|
+
* If error is not null, then responseBody
|
|
76
|
+
* is an object with the string property 'error'.
|
|
77
|
+
* @returns - A promise that resolves with the status object of the transaction.
|
|
78
|
+
*
|
|
79
|
+
*/
|
|
80
|
+
getTransactionStatus: (transactionRID: Buffer, callback?: (error: Error, responseBody: StatusObject) => void) => Promise<StatusObject>;
|
|
81
|
+
/**
|
|
82
|
+
* Adds an operation containing a nonce which makes the transaction unique.
|
|
83
|
+
*
|
|
84
|
+
* @param transaction - The transaction to sign and send.
|
|
85
|
+
*/
|
|
86
|
+
addNop(transaction: Transaction): Transaction;
|
|
87
|
+
/**
|
|
88
|
+
* Calculates and returns the transaction RID, i.e., the merkle root hash of the transaction.
|
|
89
|
+
* @param transaction The transaction to sign and send
|
|
90
|
+
*/
|
|
91
|
+
getTransactionRID(transaction: Transaction | SignedTransaction | Operation): Buffer;
|
|
92
|
+
/**
|
|
93
|
+
* Encodes the transaction using ASN.1.
|
|
94
|
+
* @returns the transaction encoded
|
|
95
|
+
*/
|
|
96
|
+
encodeTransaction(transaction: Transaction): Buffer;
|
|
97
|
+
/**
|
|
98
|
+
* Decodes the transaction using ASN.1.
|
|
99
|
+
* @returns the transaction decoded in GTX format
|
|
100
|
+
*/
|
|
101
|
+
decodeTransactionToGTX(transaction: Buffer): GTX;
|
|
102
|
+
/**
|
|
103
|
+
* Retrieves the client node URL pool.
|
|
104
|
+
*
|
|
105
|
+
* @returns An array of the client node URL pool.
|
|
106
|
+
*/
|
|
107
|
+
getClientNodeURLPool(): string[];
|
|
108
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interface.js","sourceRoot":"","sources":["../../../src/blockchainClient/interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { RawGtv } from "../gtv/types";
|
|
3
|
+
import { FailOverConfig } from "../restclient/types";
|
|
4
|
+
export type KeyPair = {
|
|
5
|
+
privKey: Buffer;
|
|
6
|
+
pubKey?: Buffer;
|
|
7
|
+
};
|
|
8
|
+
export type QueryArguments = {
|
|
9
|
+
[arg: string]: RawGtv;
|
|
10
|
+
};
|
|
11
|
+
export type ClientConfig = {
|
|
12
|
+
endpointPool: readonly string[];
|
|
13
|
+
blockchainRID: Buffer;
|
|
14
|
+
pollingInterval: number;
|
|
15
|
+
attemptsPerEndpoint: number;
|
|
16
|
+
attemptInterval: number;
|
|
17
|
+
};
|
|
18
|
+
export type URL = string;
|
|
19
|
+
interface DirectoryNode {
|
|
20
|
+
directoryChainNodeURL: URL | URL[];
|
|
21
|
+
directoryChainRID: string;
|
|
22
|
+
}
|
|
23
|
+
type NodeURLPool = URL | URL[] | DirectoryNode;
|
|
24
|
+
interface PostchainClientBaseConfig {
|
|
25
|
+
nodeURLPool: NodeURLPool;
|
|
26
|
+
connectionConfig?: ConnectionConfig;
|
|
27
|
+
}
|
|
28
|
+
type ConnectionConfig = {
|
|
29
|
+
endpointPool: readonly string[];
|
|
30
|
+
blockchainRID: string;
|
|
31
|
+
maxSockets: number;
|
|
32
|
+
pollingInterval: number;
|
|
33
|
+
failOverConfig?: FailOverConfig;
|
|
34
|
+
};
|
|
35
|
+
interface PostchainClientRIDConfig extends PostchainClientBaseConfig {
|
|
36
|
+
targetChainRID: string;
|
|
37
|
+
targetChainIID?: never;
|
|
38
|
+
}
|
|
39
|
+
interface PostchainClientIIDConfig extends PostchainClientBaseConfig {
|
|
40
|
+
targetChainIID: number;
|
|
41
|
+
targetChainRID?: never;
|
|
42
|
+
}
|
|
43
|
+
export type PostchainClientConfig = PostchainClientRIDConfig | PostchainClientIIDConfig;
|
|
44
|
+
export type NetworkSettings = {
|
|
45
|
+
nodeURLPool?: string | string[];
|
|
46
|
+
directoryNodeURLPool?: string | string[];
|
|
47
|
+
blockchainRID?: string;
|
|
48
|
+
blockchainIID?: number;
|
|
49
|
+
pollingInterval?: number;
|
|
50
|
+
failOverConfig?: FailOverConfig;
|
|
51
|
+
};
|
|
52
|
+
export interface TransactionReceipt {
|
|
53
|
+
status: ResponseStatus;
|
|
54
|
+
statusCode: number;
|
|
55
|
+
transactionRID: Buffer;
|
|
56
|
+
}
|
|
57
|
+
export type SignedTransaction = Buffer;
|
|
58
|
+
export interface SignatureProvider {
|
|
59
|
+
sign(digest: Buffer): Promise<Buffer>;
|
|
60
|
+
readonly pubKey: Buffer;
|
|
61
|
+
}
|
|
62
|
+
export type RestClientQueryObject = {
|
|
63
|
+
type: string;
|
|
64
|
+
[arg: string]: RawGtv;
|
|
65
|
+
};
|
|
66
|
+
export type QueryObject<TArgs> = {
|
|
67
|
+
name: string;
|
|
68
|
+
args?: TArgs;
|
|
69
|
+
};
|
|
70
|
+
export type QueryCallback<TReturn> = (error: Error, response: TReturn) => void;
|
|
71
|
+
export type PrivKey = Buffer;
|
|
72
|
+
export type PubKey = Buffer;
|
|
73
|
+
export type Operation = {
|
|
74
|
+
name: string;
|
|
75
|
+
args?: RawGtv[];
|
|
76
|
+
};
|
|
77
|
+
export interface Transaction {
|
|
78
|
+
operations: Operation[];
|
|
79
|
+
signers: Buffer[];
|
|
80
|
+
}
|
|
81
|
+
export type StatusObject = {
|
|
82
|
+
status: ResponseStatus;
|
|
83
|
+
rejectReason?: string;
|
|
84
|
+
};
|
|
85
|
+
export declare enum ResponseStatus {
|
|
86
|
+
Confirmed = "confirmed",
|
|
87
|
+
Rejected = "rejected",
|
|
88
|
+
Unknown = "unknown",
|
|
89
|
+
Waiting = "waiting"
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export var ResponseStatus;
|
|
2
|
+
(function (ResponseStatus) {
|
|
3
|
+
ResponseStatus["Confirmed"] = "confirmed";
|
|
4
|
+
ResponseStatus["Rejected"] = "rejected";
|
|
5
|
+
ResponseStatus["Unknown"] = "unknown";
|
|
6
|
+
ResponseStatus["Waiting"] = "waiting";
|
|
7
|
+
})(ResponseStatus || (ResponseStatus = {}));
|
|
8
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/blockchainClient/types.ts"],"names":[],"mappings":"AA0GA,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,uCAAqB,CAAA;IACrB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;AACrB,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { GTX, RellOperation } from "../gtx/types";
|
|
3
|
+
import { NetworkSettings, Operation, SignedTransaction, Transaction } from "./types";
|
|
4
|
+
export declare function getConfig(settings: NetworkSettings): Promise<{
|
|
5
|
+
endpointPool: string[];
|
|
6
|
+
blockchainRID: Buffer;
|
|
7
|
+
pollingInterval: number;
|
|
8
|
+
attemptsPerEndpoint: number;
|
|
9
|
+
attemptInterval: number;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function validTxRID(txRID: Buffer): boolean;
|
|
12
|
+
export declare function getNodeUrls(settings: NetworkSettings): Promise<string[]>;
|
|
13
|
+
export declare function convertToRellOperation(operations: Operation[]): RellOperation[];
|
|
14
|
+
export declare function testPromiEvent(): any;
|
|
15
|
+
export declare function getSerializedGTX(gtx: GTX): Buffer;
|
|
16
|
+
export declare function getGTXFromBufferOrTransactionOrOperation(transaction: SignedTransaction | Transaction | Operation, blockchainRID: Buffer): GTX;
|
|
17
|
+
export declare const callbackPromiseBuilder: (reject: any, resolve: any, callback?: any) => (error: Error, result: any) => void;
|
|
18
|
+
export declare const handlePostResponsePromisified: (error: Error, statusCode: number, rspBody: any) => Promise<void>;
|