@partisiablockchain/blockchain-api-transaction-client 4.146.0 → 5.7.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/package.json +18 -4
- package/target/main/CryptoUtils.d.ts +40 -0
- package/target/main/CryptoUtils.js +86 -0
- package/target/main/CryptoUtils.js.map +1 -0
- package/target/main/generated/openapi/apis/ChainControllerApi.d.ts +14 -1
- package/target/main/generated/openapi/apis/ChainControllerApi.js +34 -0
- package/target/main/generated/openapi/apis/ChainControllerApi.js.map +1 -1
- package/target/main/generated/openapi/models/AvlInformation.d.ts +31 -0
- package/target/main/generated/openapi/models/AvlInformation.js +47 -0
- package/target/main/generated/openapi/models/AvlInformation.js.map +1 -0
- package/target/main/generated/openapi/models/index.d.ts +1 -0
- package/target/main/generated/openapi/models/index.js +1 -0
- package/target/main/generated/openapi/models/index.js.map +1 -1
- package/target/main/index.d.ts +5 -0
- package/target/main/index.js +9 -0
- package/target/main/index.js.map +1 -1
- package/target/main/transactionclient/BlockchainTransactionClient.d.ts +113 -0
- package/target/main/transactionclient/BlockchainTransactionClient.js +243 -0
- package/target/main/transactionclient/BlockchainTransactionClient.js.map +1 -0
- package/target/main/transactionclient/ConditionWaiter.d.ts +57 -0
- package/target/main/transactionclient/ConditionWaiter.js +94 -0
- package/target/main/transactionclient/ConditionWaiter.js.map +1 -0
- package/target/main/transactionclient/SenderAuthenticationKeyPair.d.ts +24 -0
- package/target/main/transactionclient/SenderAuthenticationKeyPair.js +68 -0
- package/target/main/transactionclient/SenderAuthenticationKeyPair.js.map +1 -0
- package/target/main/transactionclient/SignedTransaction.d.ts +54 -0
- package/target/main/transactionclient/SignedTransaction.js +128 -0
- package/target/main/transactionclient/SignedTransaction.js.map +1 -0
- package/target/main/transactionclient/types.d.ts +49 -0
- package/target/main/transactionclient/types.js +20 -0
- package/target/main/transactionclient/types.js.map +1 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (C) 2022 - 2023 Partisia Blockchain Foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.BlockchainTransactionClient = void 0;
|
|
30
|
+
const openapi_1 = require("../generated/openapi");
|
|
31
|
+
const ConditionWaiter_1 = require("./ConditionWaiter");
|
|
32
|
+
const SignedTransaction_1 = require("./SignedTransaction");
|
|
33
|
+
/** A client that supports signing, sending and waiting for transactions on the blockchain. */
|
|
34
|
+
class BlockchainTransactionClient {
|
|
35
|
+
constructor(chainController, shardController, authentication, transactionValidityDuration, spawnedEventTimeout, currentTime, conditionWaiter) {
|
|
36
|
+
this.authentication = authentication;
|
|
37
|
+
this.chainController = chainController;
|
|
38
|
+
this.shardController = shardController;
|
|
39
|
+
this.transactionValidityDuration = transactionValidityDuration;
|
|
40
|
+
this.spawnedEventTimeout = spawnedEventTimeout;
|
|
41
|
+
this.currentTime = currentTime;
|
|
42
|
+
this.conditionWaiter = conditionWaiter;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a blockchain transaction client.
|
|
46
|
+
* @param baseUrl the base url of the chain to connect to
|
|
47
|
+
* @param authentication authentication of the sender that will sign transactions
|
|
48
|
+
* @param transactionValidityInMillis the number of milliseconds a signed transaction is valid for
|
|
49
|
+
* inclusion in a block.
|
|
50
|
+
* @param spawnedEventTimeoutInMillis the number of milliseconds the client will wait for a
|
|
51
|
+
* spawned event to be included in a block before timing out.
|
|
52
|
+
* @returns A blockchain transaction client
|
|
53
|
+
*/
|
|
54
|
+
static create(baseUrl, authentication, transactionValidityInMillis, spawnedEventTimeoutInMillis) {
|
|
55
|
+
const chainControllerApi = new openapi_1.ChainControllerApi(new openapi_1.Configuration({ basePath: baseUrl }));
|
|
56
|
+
const shardControllerApi = new openapi_1.ShardControllerApi(new openapi_1.Configuration({ basePath: baseUrl }));
|
|
57
|
+
return new BlockchainTransactionClient(chainControllerApi, shardControllerApi, authentication, transactionValidityInMillis !== null && transactionValidityInMillis !== void 0 ? transactionValidityInMillis : this.DEFAULT_TRANSACTION_VALIDITY_DURATION, spawnedEventTimeoutInMillis !== null && spawnedEventTimeoutInMillis !== void 0 ? spawnedEventTimeoutInMillis : this.DEFAULT_SPAWNED_EVENT_TIMEOUT, this.DEFAULT_CURRENT_TIME, ConditionWaiter_1.ConditionWaiterImpl.create());
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a blockchain transaction client used for testing.
|
|
61
|
+
* @param chainController the client used for communicating with the chain api
|
|
62
|
+
* @param shardController the client used for communicating with the shard api
|
|
63
|
+
* @param authentication authentication of the sender that will sign transactions
|
|
64
|
+
* @param transactionValidityDuration the number of milliseconds a signed transaction is valid for
|
|
65
|
+
* inclusion in a block.
|
|
66
|
+
* @param spawnedEventTimeout the number of milliseconds the client will wait for a
|
|
67
|
+
* spawned event to be included in a block before timing out. @param currentTime
|
|
68
|
+
* @param currentTime support for injecting custom time
|
|
69
|
+
* @param conditionWaiter support for injecting custom condition waiter
|
|
70
|
+
* @returns A blockchain transaction client
|
|
71
|
+
*/
|
|
72
|
+
static createForTest(chainController, shardController, authentication, transactionValidityDuration, spawnedEventTimeout, currentTime, conditionWaiter) {
|
|
73
|
+
return new BlockchainTransactionClient(chainController, shardController, authentication, transactionValidityDuration, spawnedEventTimeout, currentTime, conditionWaiter);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Sign a transaction in preparation for sending it to the blockchain. The signed transaction
|
|
77
|
+
* expires after {@link #transactionValidityDuration} millis or if the nonce of the signer
|
|
78
|
+
* changes.
|
|
79
|
+
* @param transaction the transaction to sign
|
|
80
|
+
* @param gasCost the amount of gas to allocate for executing the transaction.
|
|
81
|
+
* @param applicableUntil the latest time this transaction is allowed
|
|
82
|
+
* @returns a signed transaction corresponding to the passed transaction.
|
|
83
|
+
*/
|
|
84
|
+
sign(transaction, gasCost, applicableUntil) {
|
|
85
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
86
|
+
const sender = this.authentication.getAddress();
|
|
87
|
+
const nonce = (yield this.chainController.getAccount({ address: sender })).nonce;
|
|
88
|
+
const chainId = (yield this.chainController.getChain()).chainId;
|
|
89
|
+
let validToTime = this.currentTime() + this.transactionValidityDuration;
|
|
90
|
+
if (applicableUntil !== undefined) {
|
|
91
|
+
validToTime = Math.min(validToTime, applicableUntil);
|
|
92
|
+
}
|
|
93
|
+
return SignedTransaction_1.SignedTransaction.create(this.authentication, nonce, validToTime, gasCost, chainId, transaction);
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Sends a signed transaction to the blockchain for execution and inclusion in a block.
|
|
98
|
+
* @param signedTransaction the signed transaction to send.
|
|
99
|
+
* @returns a sent transaction corresponding to the signed transaction.
|
|
100
|
+
*/
|
|
101
|
+
send(signedTransaction) {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
const bytes = signedTransaction.serialize();
|
|
104
|
+
const serializedTransaction = { payload: bytes.toString("base64") };
|
|
105
|
+
const transactionPointer = yield this.chainController.putTransaction({ serializedTransaction });
|
|
106
|
+
return { signedTransaction, transactionPointer };
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Sign and send a transaction to the blockchain for execution.
|
|
111
|
+
* @param transaction the transaction to sign and send
|
|
112
|
+
* @param gasCost the amount of gas to allocate for executing the transaction.
|
|
113
|
+
* @returns a sent transaction corresponding to the signed transaction.
|
|
114
|
+
*/
|
|
115
|
+
signAndSend(transaction, gasCost) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
return yield this.send(yield this.sign(transaction, gasCost));
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Waits for a sent transaction to be included in a block on the blockchain.
|
|
122
|
+
* @param sentTransaction a transaction that has been sent to the blockchain.
|
|
123
|
+
* @returns the executed state of the transaction.
|
|
124
|
+
*/
|
|
125
|
+
waitForInclusionInBlock(sentTransaction) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const senderShard = sentTransaction.transactionPointer.destinationShardId;
|
|
128
|
+
const transactionIdentifier = sentTransaction.transactionPointer.identifier;
|
|
129
|
+
const validToTime = sentTransaction.signedTransaction.getValidToTime();
|
|
130
|
+
const timeToWait = validToTime - this.currentTime();
|
|
131
|
+
return this.waitForTransaction(senderShard, transactionIdentifier, timeToWait);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Recursively wait for the inclusion of all events spawned by the transaction and the
|
|
136
|
+
* transaction's events.
|
|
137
|
+
* @param transaction the transaction to wait for
|
|
138
|
+
* @returns the execution status for all recursive events spawned by the transaction.
|
|
139
|
+
*/
|
|
140
|
+
waitForSpawnedEvents(transaction) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
let executedTransaction = transaction;
|
|
143
|
+
if ("signedTransaction" in executedTransaction) {
|
|
144
|
+
executedTransaction = yield this.waitForInclusionInBlock(executedTransaction);
|
|
145
|
+
}
|
|
146
|
+
const events = [];
|
|
147
|
+
const executionStatus = executedTransaction.executionStatus;
|
|
148
|
+
const pendingEvents = [...executionStatus.events];
|
|
149
|
+
while (pendingEvents.length !== 0) {
|
|
150
|
+
const nextEvent = pendingEvents.shift();
|
|
151
|
+
const identifier = nextEvent.identifier;
|
|
152
|
+
const shardId = nextEvent.destinationShardId;
|
|
153
|
+
const executed = yield this.waitForTransaction(shardId, identifier, this.spawnedEventTimeout);
|
|
154
|
+
events.push(executed);
|
|
155
|
+
const executedExecutionStatus = executed.executionStatus;
|
|
156
|
+
pendingEvents.push(...executedExecutionStatus.events);
|
|
157
|
+
}
|
|
158
|
+
return { transaction: executedTransaction, events };
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Try to ensure that the given transaction is included in a final block before the specified time
|
|
163
|
+
* has passed. Will try to resend the transaction until it has been included in a block or the
|
|
164
|
+
* specified time has passed. If the transaction has not been included, or we are unable to
|
|
165
|
+
* determine inclusion, due to network issues, an exception is thrown.
|
|
166
|
+
*
|
|
167
|
+
* <p>To determine that a tried transaction has not been included in a block, we must wait until
|
|
168
|
+
* the last valid block that could have included the transaction has been finalized. The caller of
|
|
169
|
+
* this function can specify the amount of time to wait for the last valid block after validity
|
|
170
|
+
* time of the tried transaction has expired.
|
|
171
|
+
* @param transaction The transaction to sign and send
|
|
172
|
+
* @param transactionGasCost The amount of gas to allocate for executing the transaction
|
|
173
|
+
* @param includeBefore The UTC timestamp after which the transaction will no longer tried to be
|
|
174
|
+
* sent
|
|
175
|
+
* @param lastValidBlockWaitTime The amount of time to wait for the last valid block that a tried
|
|
176
|
+
* transaction can be included in
|
|
177
|
+
* @returns The executed state of the transaction
|
|
178
|
+
* @throws ApiException on io error
|
|
179
|
+
*/
|
|
180
|
+
ensureInclusionInBlock(transaction, transactionGasCost, includeBefore, lastValidBlockWaitTime) {
|
|
181
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
182
|
+
// Default is 30 days
|
|
183
|
+
const effectiveLastValidBlockWaitTime = lastValidBlockWaitTime !== null && lastValidBlockWaitTime !== void 0 ? lastValidBlockWaitTime : 2592000000;
|
|
184
|
+
while (includeBefore > this.currentTime()) {
|
|
185
|
+
const sentTransaction = yield this.send(yield this.sign(transaction, transactionGasCost, includeBefore));
|
|
186
|
+
const executedTransaction = yield this.waitForExecutedTransaction(sentTransaction, effectiveLastValidBlockWaitTime);
|
|
187
|
+
if (executedTransaction !== undefined) {
|
|
188
|
+
return executedTransaction;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
throw new Error("Transaction was not included in block before " + includeBefore);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
waitForExecutedTransaction(sentTransaction, latestBlockWait) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
try {
|
|
197
|
+
return yield this.waitForInclusionInBlock(sentTransaction);
|
|
198
|
+
}
|
|
199
|
+
catch (_) {
|
|
200
|
+
return yield this.waitForLastPossibleBlockToInclude(sentTransaction, latestBlockWait);
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
waitForLastPossibleBlockToInclude(sentTransaction, latestBlockWait) {
|
|
205
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
206
|
+
const shardId = sentTransaction.transactionPointer.destinationShardId;
|
|
207
|
+
const validToTime = sentTransaction.signedTransaction.getValidToTime();
|
|
208
|
+
const timeOut = latestBlockWait + validToTime;
|
|
209
|
+
yield this.conditionWaiter.waitForCondition(() => __awaiter(this, void 0, void 0, function* () { return (yield this.shardController.getLatestBlock({ shardId })).productionTime; }), (productionTime) => productionTime > validToTime, timeOut, () => `Unable to get block with production time greater than ${validToTime} for shard ${shardId}`);
|
|
210
|
+
const transactionIdentifier = sentTransaction.transactionPointer.identifier;
|
|
211
|
+
// Stryker disable BlockStatement
|
|
212
|
+
try {
|
|
213
|
+
return yield this.shardController.getTransaction({
|
|
214
|
+
shardId,
|
|
215
|
+
transactionId: transactionIdentifier,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (_) {
|
|
219
|
+
return undefined;
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// Stryker restore BlockStatement
|
|
224
|
+
waitForTransaction(shardId, transactionId, timeout) {
|
|
225
|
+
return this.conditionWaiter.waitForCondition(() => this.shardController.getTransaction({ shardId, transactionId }), (value) => value.executionStatus !== undefined && value.executionStatus.finalized, timeout, () => `Transaction '${transactionId}' was not included in a block at shard '${shardId}'`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.BlockchainTransactionClient = BlockchainTransactionClient;
|
|
229
|
+
/**
|
|
230
|
+
* Default signed transaction vilidity time in milliseconds. This is three minutes in
|
|
231
|
+
* milliseconds.
|
|
232
|
+
*/
|
|
233
|
+
BlockchainTransactionClient.DEFAULT_TRANSACTION_VALIDITY_DURATION = 180000;
|
|
234
|
+
/**
|
|
235
|
+
* Default timeout for spawned event to be inclusion in a block. This is ten minutes in
|
|
236
|
+
* milliseconds.
|
|
237
|
+
*/
|
|
238
|
+
BlockchainTransactionClient.DEFAULT_SPAWNED_EVENT_TIMEOUT = 600000;
|
|
239
|
+
/**
|
|
240
|
+
* Default current time is system time.
|
|
241
|
+
*/
|
|
242
|
+
BlockchainTransactionClient.DEFAULT_CURRENT_TIME = () => new Date().getTime();
|
|
243
|
+
//# sourceMappingURL=BlockchainTransactionClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BlockchainTransactionClient.js","sourceRoot":"","sources":["../../../src/main/transactionclient/BlockchainTransactionClient.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;AAGH,kDAO8B;AAC9B,uDAAyE;AACzE,2DAAwD;AAExD,8FAA8F;AAC9F,MAAa,2BAA2B;IA4BtC,YACE,eAAmC,EACnC,eAAmC,EACnC,cAAoC,EACpC,2BAAmC,EACnC,mBAA2B,EAC3B,WAAyB,EACzB,eAAgC;QAEhC,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,2BAA2B,GAAG,2BAA2B,CAAC;QAC/D,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM,CAAC,MAAM,CAClB,OAAe,EACf,cAAoC,EACpC,2BAAoC,EACpC,2BAAoC;QAEpC,MAAM,kBAAkB,GAAG,IAAI,4BAAkB,CAAC,IAAI,uBAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QAC5F,MAAM,kBAAkB,GAAG,IAAI,4BAAkB,CAAC,IAAI,uBAAa,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;QAC5F,OAAO,IAAI,2BAA2B,CACpC,kBAAkB,EAClB,kBAAkB,EAClB,cAAc,EACd,2BAA2B,aAA3B,2BAA2B,cAA3B,2BAA2B,GAAI,IAAI,CAAC,qCAAqC,EACzE,2BAA2B,aAA3B,2BAA2B,cAA3B,2BAA2B,GAAI,IAAI,CAAC,6BAA6B,EACjE,IAAI,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C,eAAe,CAAC,cAAc,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC,EACrE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,eAAe,KAAK,SAAS,IAAI,KAAK,CAAC,eAAe,CAAC,SAAS,EACjF,OAAO,EACP,GAAG,EAAE,CAAC,gBAAgB,aAAa,2CAA2C,OAAO,GAAG,CACzF,CAAC;IACJ,CAAC;;AA1SH,kEA2SC;AAhSC;;;GAGG;AACoB,iEAAqC,GAAG,MAAM,CAAC;AAEtE;;;GAGG;AACoB,yDAA6B,GAAG,MAAM,CAAC;AAE9D;;GAEG;AACoB,gDAAoB,GAAG,GAAG,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic wait interface allowing the creation of asynchronous calls and wait for these. The user
|
|
3
|
+
* must provide a value getter and a value predicate, the value getter returns the current value,
|
|
4
|
+
* the value predicate whether the value is "complete" and the wait is over.
|
|
5
|
+
*/
|
|
6
|
+
export interface ConditionWaiter {
|
|
7
|
+
/**
|
|
8
|
+
* Waits for the condition dictated by the input predicate until it is met. Times out by if the
|
|
9
|
+
* condition is not met within a specified time-out. Sleeps in an incrementing fashion between
|
|
10
|
+
* checks of the condition until a maximum of 30 seconds between iterations to avoid busy-waiting.
|
|
11
|
+
* @param valueSupplier The supplier of (possibly) updated values for the condition.
|
|
12
|
+
* @param valuePredicate The condition that the value must meet before waiting is over.
|
|
13
|
+
* @param timeoutMs The time to wait for in milliseconds.
|
|
14
|
+
* @param errorMessage The lazy initialized error message to throw in case of timing out.
|
|
15
|
+
* @returns The final value returned by the supplier, which meets the condition.
|
|
16
|
+
*/
|
|
17
|
+
waitForCondition<T>(valueSupplier: () => Promise<T>, valuePredicate: (value: T) => boolean, timeoutMs: number, errorMessage: () => string): Promise<T>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Can wait for a condition to become fulfilled by repeatedly sleeping the current thread between
|
|
21
|
+
* checks.
|
|
22
|
+
*/
|
|
23
|
+
export declare class ConditionWaiterImpl implements ConditionWaiter {
|
|
24
|
+
private readonly timeSupport;
|
|
25
|
+
private constructor();
|
|
26
|
+
/**
|
|
27
|
+
* @inheritdoc
|
|
28
|
+
*/
|
|
29
|
+
waitForCondition<T>(valueSupplier: () => Promise<T>, valuePredicate: (value: T) => boolean, timeoutMs: number, errorMessage: () => string): Promise<T>;
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new condition waiter using the system time and system sleep.
|
|
32
|
+
* @returns The transaction waiter.
|
|
33
|
+
*/
|
|
34
|
+
static create(): ConditionWaiterImpl;
|
|
35
|
+
/**
|
|
36
|
+
* Creates a new condition waiter.
|
|
37
|
+
* @param timeSupport Support for time (current time and sleep).
|
|
38
|
+
* @returns The transaction waiter.
|
|
39
|
+
*/
|
|
40
|
+
static createForTest(timeSupport: TimeSupport): ConditionWaiterImpl;
|
|
41
|
+
}
|
|
42
|
+
/** Support for getting the current time and sleeping. */
|
|
43
|
+
export interface TimeSupport {
|
|
44
|
+
/**
|
|
45
|
+
* Gets the current time in milliseconds.
|
|
46
|
+
* @returns The current time in milliseconds.
|
|
47
|
+
*/
|
|
48
|
+
now(): number;
|
|
49
|
+
/**
|
|
50
|
+
* Pauses execution of the current program for some measure of time.
|
|
51
|
+
* @param ms The time to stop execution in milliseconds.
|
|
52
|
+
* @returns an empty promise that resolves after the duration has passed
|
|
53
|
+
*/
|
|
54
|
+
sleep(ms: number): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
/** Time support that uses the underlying operating system. */
|
|
57
|
+
export declare const TimeSupportSystem: TimeSupport;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (C) 2022 - 2023 Partisia Blockchain Foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.TimeSupportSystem = exports.ConditionWaiterImpl = void 0;
|
|
30
|
+
/**
|
|
31
|
+
* Can wait for a condition to become fulfilled by repeatedly sleeping the current thread between
|
|
32
|
+
* checks.
|
|
33
|
+
*/
|
|
34
|
+
class ConditionWaiterImpl {
|
|
35
|
+
constructor(timeSupport) {
|
|
36
|
+
this.timeSupport = timeSupport;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* @inheritdoc
|
|
40
|
+
*/
|
|
41
|
+
waitForCondition(valueSupplier, valuePredicate, timeoutMs, errorMessage) {
|
|
42
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
43
|
+
const end = this.timeSupport.now() + timeoutMs;
|
|
44
|
+
let increasingSleep = 0;
|
|
45
|
+
let remainingTime;
|
|
46
|
+
do {
|
|
47
|
+
let value = undefined;
|
|
48
|
+
try {
|
|
49
|
+
value = yield valueSupplier();
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
// Empty try again
|
|
53
|
+
}
|
|
54
|
+
if (value !== undefined && valuePredicate(value)) {
|
|
55
|
+
return value;
|
|
56
|
+
}
|
|
57
|
+
increasingSleep++;
|
|
58
|
+
const sleepDurationMs = Math.min(30000, 100 * increasingSleep);
|
|
59
|
+
remainingTime = Math.max(0, end - this.timeSupport.now());
|
|
60
|
+
const effectiveSleepDuration = Math.min(sleepDurationMs, remainingTime);
|
|
61
|
+
yield this.timeSupport.sleep(effectiveSleepDuration);
|
|
62
|
+
} while (remainingTime > 0);
|
|
63
|
+
throw new Error(errorMessage());
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Creates a new condition waiter using the system time and system sleep.
|
|
68
|
+
* @returns The transaction waiter.
|
|
69
|
+
*/
|
|
70
|
+
static create() {
|
|
71
|
+
return new ConditionWaiterImpl(exports.TimeSupportSystem);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Creates a new condition waiter.
|
|
75
|
+
* @param timeSupport Support for time (current time and sleep).
|
|
76
|
+
* @returns The transaction waiter.
|
|
77
|
+
*/
|
|
78
|
+
static createForTest(timeSupport) {
|
|
79
|
+
return new ConditionWaiterImpl(timeSupport);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ConditionWaiterImpl = ConditionWaiterImpl;
|
|
83
|
+
/** Time support that uses the underlying operating system. */
|
|
84
|
+
exports.TimeSupportSystem = {
|
|
85
|
+
/** @inheritDoc */
|
|
86
|
+
now() {
|
|
87
|
+
return new Date().getTime();
|
|
88
|
+
},
|
|
89
|
+
/** @inheritDoc */
|
|
90
|
+
sleep(ms) {
|
|
91
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
//# sourceMappingURL=ConditionWaiter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConditionWaiter.js","sourceRoot":"","sources":["../../../src/main/transactionclient/ConditionWaiter.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;AA0BH;;;GAGG;AACH,MAAa,mBAAmB;IAG9B,YAAoB,WAAwB;QAC1C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACG,gBAAgB,CACpB,aAA+B,EAC/B,cAAqC,EACrC,SAAiB,EACjB,YAA0B;;YAE1B,MAAM,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,SAAS,CAAC;YAC/C,IAAI,eAAe,GAAG,CAAC,CAAC;YACxB,IAAI,aAAa,CAAC;YAClB,GAAG,CAAC;gBACF,IAAI,KAAK,GAAkB,SAAS,CAAC;gBACrC,IAAI,CAAC;oBACH,KAAK,GAAG,MAAM,aAAa,EAAE,CAAC;gBAChC,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,kBAAkB;gBACpB,CAAC;gBACD,IAAI,KAAK,KAAK,SAAS,IAAI,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;oBACjD,OAAO,KAAK,CAAC;gBACf,CAAC;gBACD,eAAe,EAAE,CAAC;gBAClB,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,GAAG,eAAe,CAAC,CAAC;gBAC/D,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC;gBAC1D,MAAM,sBAAsB,GAAG,IAAI,CAAC,GAAG,CAAC,eAAe,EAAE,aAAa,CAAC,CAAC;gBACxE,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;YACvD,CAAC,QAAQ,aAAa,GAAG,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,YAAY,EAAE,CAAC,CAAC;QAClC,CAAC;KAAA;IAED;;;OAGG;IACI,MAAM,CAAC,MAAM;QAClB,OAAO,IAAI,mBAAmB,CAAC,yBAAiB,CAAC,CAAC;IACpD,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,aAAa,CAAC,WAAwB;QAClD,OAAO,IAAI,mBAAmB,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;CACF;AAtDD,kDAsDC;AAiBD,8DAA8D;AACjD,QAAA,iBAAiB,GAAgB;IAC5C,kBAAkB;IAClB,GAAG;QACD,OAAO,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;IAC9B,CAAC;IACD,kBAAkB;IAClB,KAAK,CAAC,EAAU;QACd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ec as Elliptic } from "elliptic";
|
|
2
|
+
import { BlockchainAddress, SenderAuthentication, Signature } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Sender authentication based on a key-pair, consisting of a public and private key. The sender
|
|
5
|
+
* address is computed from the public key.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SenderAuthenticationKeyPair implements SenderAuthentication {
|
|
8
|
+
private readonly keyPair;
|
|
9
|
+
/**
|
|
10
|
+
* Creates authentication for a sender.
|
|
11
|
+
* @param keyPair The public and private key of the sender. Not nullable.
|
|
12
|
+
*/
|
|
13
|
+
constructor(keyPair: Elliptic.KeyPair);
|
|
14
|
+
/**
|
|
15
|
+
* Creates a sender's authentication from a private key.
|
|
16
|
+
* @param privateKey The private key to create a key pair from, written as a value in hexidecimal.
|
|
17
|
+
* @returns authentication for a transaction sender.
|
|
18
|
+
*/
|
|
19
|
+
static fromString(privateKey: string): SenderAuthenticationKeyPair;
|
|
20
|
+
/** @inheritDoc */
|
|
21
|
+
getAddress(): BlockchainAddress;
|
|
22
|
+
/** @inheritDoc */
|
|
23
|
+
sign(transactionPayload: Buffer, chainId: string): Promise<Signature>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (C) 2022 - 2023 Partisia Blockchain Foundation
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU Affero General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
*
|
|
10
|
+
* This program is distributed in the hope that it will be useful,
|
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
* GNU General Public License for more details.
|
|
14
|
+
*
|
|
15
|
+
* You should have received a copy of the GNU Affero General Public License
|
|
16
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
20
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
21
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
22
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
23
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
24
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
25
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.SenderAuthenticationKeyPair = void 0;
|
|
30
|
+
const CryptoUtils_1 = require("../CryptoUtils");
|
|
31
|
+
const bitmanipulation_ts_1 = require("@secata-public/bitmanipulation-ts");
|
|
32
|
+
/**
|
|
33
|
+
* Sender authentication based on a key-pair, consisting of a public and private key. The sender
|
|
34
|
+
* address is computed from the public key.
|
|
35
|
+
*/
|
|
36
|
+
class SenderAuthenticationKeyPair {
|
|
37
|
+
/**
|
|
38
|
+
* Creates authentication for a sender.
|
|
39
|
+
* @param keyPair The public and private key of the sender. Not nullable.
|
|
40
|
+
*/
|
|
41
|
+
constructor(keyPair) {
|
|
42
|
+
this.keyPair = keyPair;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Creates a sender's authentication from a private key.
|
|
46
|
+
* @param privateKey The private key to create a key pair from, written as a value in hexidecimal.
|
|
47
|
+
* @returns authentication for a transaction sender.
|
|
48
|
+
*/
|
|
49
|
+
static fromString(privateKey) {
|
|
50
|
+
return new SenderAuthenticationKeyPair(CryptoUtils_1.CryptoUtils.privateKeyToKeypair(privateKey));
|
|
51
|
+
}
|
|
52
|
+
/** @inheritDoc */
|
|
53
|
+
getAddress() {
|
|
54
|
+
return CryptoUtils_1.CryptoUtils.keyPairToAccountAddress(this.keyPair);
|
|
55
|
+
}
|
|
56
|
+
/** @inheritDoc */
|
|
57
|
+
sign(transactionPayload, chainId) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const hash = CryptoUtils_1.CryptoUtils.hashBuffers([
|
|
60
|
+
transactionPayload,
|
|
61
|
+
bitmanipulation_ts_1.BigEndianByteOutput.serialize((out) => out.writeString(chainId)),
|
|
62
|
+
]).toString("hex");
|
|
63
|
+
return CryptoUtils_1.CryptoUtils.signatureToBuffer(this.keyPair.sign(hash)).toString("hex");
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.SenderAuthenticationKeyPair = SenderAuthenticationKeyPair;
|
|
68
|
+
//# sourceMappingURL=SenderAuthenticationKeyPair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SenderAuthenticationKeyPair.js","sourceRoot":"","sources":["../../../src/main/transactionclient/SenderAuthenticationKeyPair.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;AAIH,gDAA6C;AAC7C,0EAAwE;AAExE;;;GAGG;AACH,MAAa,2BAA2B;IAGtC;;;OAGG;IACH,YAAmB,OAAyB;QAC1C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU,CAAC,UAAkB;QACzC,OAAO,IAAI,2BAA2B,CAAC,yBAAW,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC;IACtF,CAAC;IAED,kBAAkB;IACX,UAAU;QACf,OAAO,yBAAW,CAAC,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC3D,CAAC;IAED,kBAAkB;IACL,IAAI,CAAC,kBAA0B,EAAE,OAAe;;YAC3D,MAAM,IAAI,GAAG,yBAAW,CAAC,WAAW,CAAC;gBACnC,kBAAkB;gBAClB,wCAAmB,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;aACjE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACnB,OAAO,yBAAW,CAAC,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QAChF,CAAC;KAAA;CACF;AAjCD,kEAiCC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Hash, SenderAuthentication, Transaction } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* A transaction that has been signed by a private key. A signed transaction is ready to be sent to
|
|
4
|
+
* the blockchain. A signed transaction has limited durability, since it includes information about
|
|
5
|
+
* the valid-to-time and the next available nonce of the sending user.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SignedTransaction {
|
|
8
|
+
private readonly inner;
|
|
9
|
+
private readonly signature;
|
|
10
|
+
private readonly hash;
|
|
11
|
+
private constructor();
|
|
12
|
+
/**
|
|
13
|
+
* Create a signed transaction to send to PBC.
|
|
14
|
+
* @param senderAuthentication the sender authentication to sign the transaction with.
|
|
15
|
+
* @param nonce the nonce of the signing account.
|
|
16
|
+
* @param validToTime the unix time that the transaction is valid to.
|
|
17
|
+
* @param gasCost the amount of gas allocated to executing the transaction.
|
|
18
|
+
* @param chainId the id of the chain.
|
|
19
|
+
* @param transaction the transaction to sign.
|
|
20
|
+
* @returns the signed transaction.
|
|
21
|
+
*/
|
|
22
|
+
static create(senderAuthentication: SenderAuthentication, nonce: number, validToTime: number, gasCost: number, chainId: string, transaction: Transaction): Promise<SignedTransaction>;
|
|
23
|
+
/**
|
|
24
|
+
* Serialize the signed transaction into bytes.
|
|
25
|
+
* @returns the serialized bytes.
|
|
26
|
+
*/
|
|
27
|
+
serialize(): Buffer;
|
|
28
|
+
/**
|
|
29
|
+
* Get the identifier of this transaction.
|
|
30
|
+
* @returns the identify hash
|
|
31
|
+
*/
|
|
32
|
+
identifier(): Hash;
|
|
33
|
+
/**
|
|
34
|
+
* Get the nonce of this transaction.
|
|
35
|
+
* @returns the nonce
|
|
36
|
+
*/
|
|
37
|
+
getNonce(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Get the valid-to-time of this transaction. If the transaction is not included in a block before
|
|
40
|
+
* this time it will fail.
|
|
41
|
+
* @returns the valid to time as a unix timestamp.
|
|
42
|
+
*/
|
|
43
|
+
getValidToTime(): number;
|
|
44
|
+
/**
|
|
45
|
+
* Get the gas cost of this transaction.
|
|
46
|
+
* @returns the gas cost
|
|
47
|
+
*/
|
|
48
|
+
getGasCost(): number;
|
|
49
|
+
/**
|
|
50
|
+
* Get the inner transaction of this transaction.
|
|
51
|
+
* @returns the inner
|
|
52
|
+
*/
|
|
53
|
+
getInner(): Transaction;
|
|
54
|
+
}
|