@partisiablockchain/blockchain-api-transaction-client 4.146.0 → 5.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/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,128 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
29
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
30
|
+
};
|
|
31
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
32
|
+
exports.SignedTransaction = void 0;
|
|
33
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
34
|
+
const bitmanipulation_ts_1 = require("@secata-public/bitmanipulation-ts");
|
|
35
|
+
const CryptoUtils_1 = require("../CryptoUtils");
|
|
36
|
+
/**
|
|
37
|
+
* A transaction that has been signed by a private key. A signed transaction is ready to be sent to
|
|
38
|
+
* the blockchain. A signed transaction has limited durability, since it includes information about
|
|
39
|
+
* the valid-to-time and the next available nonce of the sending user.
|
|
40
|
+
*/
|
|
41
|
+
class SignedTransaction {
|
|
42
|
+
constructor(inner, signature, hash) {
|
|
43
|
+
this.inner = inner;
|
|
44
|
+
this.signature = signature;
|
|
45
|
+
this.hash = hash;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Create a signed transaction to send to PBC.
|
|
49
|
+
* @param senderAuthentication the sender authentication to sign the transaction with.
|
|
50
|
+
* @param nonce the nonce of the signing account.
|
|
51
|
+
* @param validToTime the unix time that the transaction is valid to.
|
|
52
|
+
* @param gasCost the amount of gas allocated to executing the transaction.
|
|
53
|
+
* @param chainId the id of the chain.
|
|
54
|
+
* @param transaction the transaction to sign.
|
|
55
|
+
* @returns the signed transaction.
|
|
56
|
+
*/
|
|
57
|
+
static create(senderAuthentication, nonce, validToTime, gasCost, chainId, transaction) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const inner = { nonce, validToTime, gasCost, innerTransaction: transaction };
|
|
60
|
+
const transactionPayload = serializeInnerPart(inner);
|
|
61
|
+
const hash = CryptoUtils_1.CryptoUtils.hashBuffers([
|
|
62
|
+
transactionPayload,
|
|
63
|
+
bitmanipulation_ts_1.BigEndianByteOutput.serialize((out) => out.writeString(chainId)),
|
|
64
|
+
]).toString("hex");
|
|
65
|
+
const signature = yield senderAuthentication.sign(transactionPayload, chainId);
|
|
66
|
+
return new SignedTransaction(inner, signature, hash);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Serialize the signed transaction into bytes.
|
|
71
|
+
* @returns the serialized bytes.
|
|
72
|
+
*/
|
|
73
|
+
serialize() {
|
|
74
|
+
return Buffer.concat([Buffer.from(this.signature, "hex"), serializeInnerPart(this.inner)]);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Get the identifier of this transaction.
|
|
78
|
+
* @returns the identify hash
|
|
79
|
+
*/
|
|
80
|
+
identifier() {
|
|
81
|
+
return CryptoUtils_1.CryptoUtils.hashBuffers([
|
|
82
|
+
Buffer.from(this.hash, "hex"),
|
|
83
|
+
Buffer.from(this.signature, "hex"),
|
|
84
|
+
]).toString("hex");
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Get the nonce of this transaction.
|
|
88
|
+
* @returns the nonce
|
|
89
|
+
*/
|
|
90
|
+
getNonce() {
|
|
91
|
+
return this.inner.nonce;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the valid-to-time of this transaction. If the transaction is not included in a block before
|
|
95
|
+
* this time it will fail.
|
|
96
|
+
* @returns the valid to time as a unix timestamp.
|
|
97
|
+
*/
|
|
98
|
+
getValidToTime() {
|
|
99
|
+
return this.inner.validToTime;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the gas cost of this transaction.
|
|
103
|
+
* @returns the gas cost
|
|
104
|
+
*/
|
|
105
|
+
getGasCost() {
|
|
106
|
+
return this.inner.gasCost;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get the inner transaction of this transaction.
|
|
110
|
+
* @returns the inner
|
|
111
|
+
*/
|
|
112
|
+
getInner() {
|
|
113
|
+
return this.inner.innerTransaction;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
exports.SignedTransaction = SignedTransaction;
|
|
117
|
+
/** Serialize the inner part of a signed transaction to bytes. */
|
|
118
|
+
function serializeInnerPart(innerPart) {
|
|
119
|
+
return bitmanipulation_ts_1.BigEndianByteOutput.serialize((out) => {
|
|
120
|
+
out.writeI64(new bn_js_1.default(innerPart.nonce));
|
|
121
|
+
out.writeI64(new bn_js_1.default(innerPart.validToTime));
|
|
122
|
+
out.writeI64(new bn_js_1.default(innerPart.gasCost));
|
|
123
|
+
out.writeBytes(Buffer.from(innerPart.innerTransaction.address, "hex"));
|
|
124
|
+
out.writeI32(innerPart.innerTransaction.rpc.length);
|
|
125
|
+
out.writeBytes(innerPart.innerTransaction.rpc);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=SignedTransaction.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignedTransaction.js","sourceRoot":"","sources":["../../../src/main/transactionclient/SignedTransaction.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;;;;;;;;;;;;;;AAEH,kDAAuB;AACvB,0EAAwE;AACxE,gDAA6C;AAG7C;;;;GAIG;AACH,MAAa,iBAAiB;IAK5B,YAAoB,KAAgB,EAAE,SAAoB,EAAE,IAAU;QACpE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;;;;;;;OASG;IACI,MAAM,CAAO,MAAM,CACxB,oBAA0C,EAC1C,KAAa,EACb,WAAmB,EACnB,OAAe,EACf,OAAe,EACf,WAAwB;;YAExB,MAAM,KAAK,GAAc,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,CAAC;YACxF,MAAM,kBAAkB,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACrD,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,MAAM,SAAS,GAAG,MAAM,oBAAoB,CAAC,IAAI,CAAC,kBAAkB,EAAE,OAAO,CAAC,CAAC;YAC/E,OAAO,IAAI,iBA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AAC,OAAO,CAAC,CAAC,CAAC;QACxC,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;QACvE,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACpD,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SignedTransaction } from "./SignedTransaction";
|
|
2
|
+
import { ExecutedTransaction, TransactionPointer } from "../generated/openapi";
|
|
3
|
+
/** Hash as a 32 byte long hex string. */
|
|
4
|
+
export type Hash = string;
|
|
5
|
+
/** BlockchainAddress as 21 byte long hex string. */
|
|
6
|
+
export type BlockchainAddress = string;
|
|
7
|
+
/** Signature as 65 byte long hex string. */
|
|
8
|
+
export type Signature = string;
|
|
9
|
+
/**
|
|
10
|
+
* Authentication for a sender of a transaction. Sending transactions requires a blockchain address
|
|
11
|
+
* and the ability to sign messages.
|
|
12
|
+
*/
|
|
13
|
+
export interface SenderAuthentication {
|
|
14
|
+
/**
|
|
15
|
+
* Get the address of the sender.
|
|
16
|
+
* @returns The blockchain address of the sender.
|
|
17
|
+
*/
|
|
18
|
+
getAddress(): BlockchainAddress;
|
|
19
|
+
/**
|
|
20
|
+
* Sign a transaction.
|
|
21
|
+
* @param transactionPayload payload of the transaction
|
|
22
|
+
* @param chainId the chain id
|
|
23
|
+
* @returns the signature of the message
|
|
24
|
+
*/
|
|
25
|
+
sign(transactionPayload: Buffer, chainId: string): Promise<Signature>;
|
|
26
|
+
}
|
|
27
|
+
/** A transaction. */
|
|
28
|
+
export interface Transaction {
|
|
29
|
+
/** The address of the receiver of the transaction. */
|
|
30
|
+
address: BlockchainAddress;
|
|
31
|
+
/** The rpc of the transaction. */
|
|
32
|
+
rpc: Buffer;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A transaction that has been sent to the blockchain for execution.
|
|
36
|
+
*/
|
|
37
|
+
export interface SentTransaction {
|
|
38
|
+
/** The signed transaction that was sent. */
|
|
39
|
+
signedTransaction: SignedTransaction;
|
|
40
|
+
/** A pointer to the signed transaction that was sent. */
|
|
41
|
+
transactionPointer: TransactionPointer;
|
|
42
|
+
}
|
|
43
|
+
/** Status for a transaction and the whole tree of spawned events. */
|
|
44
|
+
export interface TransactionTree {
|
|
45
|
+
/** The original transaction. */
|
|
46
|
+
transaction: ExecutedTransaction;
|
|
47
|
+
/** List of spawned events from the transaction. */
|
|
48
|
+
events: ExecutedTransaction[];
|
|
49
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/main/transactionclient/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG"}
|