koilib 2.6.0 → 2.8.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 +5 -5
- package/dist/koinos.js +178 -688
- package/dist/koinos.min.js +1 -1
- package/lib/Contract.d.ts +9 -11
- package/lib/Contract.js +12 -12
- package/lib/Contract.js.map +1 -1
- package/lib/Provider.d.ts +24 -17
- package/lib/Provider.js +83 -81
- package/lib/Provider.js.map +1 -1
- package/lib/Serializer.d.ts +6 -2
- package/lib/Serializer.js +10 -4
- package/lib/Serializer.js.map +1 -1
- package/lib/Signer.d.ts +24 -10
- package/lib/Signer.js +71 -24
- package/lib/Signer.js.map +1 -1
- package/lib/browser/Contract.d.ts +200 -0
- package/lib/browser/Contract.js +298 -0
- package/lib/browser/Contract.js.map +1 -0
- package/lib/browser/Provider.d.ts +160 -0
- package/lib/browser/Provider.js +246 -0
- package/lib/browser/Provider.js.map +1 -0
- package/lib/browser/Serializer.d.ts +85 -0
- package/lib/browser/Serializer.js +175 -0
- package/lib/browser/Serializer.js.map +1 -0
- package/lib/browser/Signer.d.ts +310 -0
- package/lib/browser/Signer.js +468 -0
- package/lib/browser/Signer.js.map +1 -0
- package/lib/browser/index.d.ts +7 -0
- package/lib/browser/index.js +34 -0
- package/lib/browser/index.js.map +1 -0
- package/lib/browser/index2.d.ts +2 -0
- package/lib/browser/index2.js +33 -0
- package/lib/browser/index2.js.map +1 -0
- package/lib/browser/interface.d.ts +279 -0
- package/lib/browser/interface.js +3 -0
- package/lib/browser/interface.js.map +1 -0
- package/lib/browser/jsonDescriptors/krc20-proto.json +183 -0
- package/lib/browser/jsonDescriptors/protocol-proto.json +246 -0
- package/lib/browser/utils.d.ts +326 -0
- package/lib/browser/utils.js +252 -0
- package/lib/browser/utils.js.map +1 -0
- package/lib/interface.d.ts +22 -21
- package/package.json +9 -6
package/lib/Contract.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Signer, SignerInterface } from "./Signer";
|
|
2
2
|
import { Provider } from "./Provider";
|
|
3
3
|
import { Serializer } from "./Serializer";
|
|
4
|
-
import { CallContractOperationNested, UploadContractOperationNested,
|
|
4
|
+
import { CallContractOperationNested, UploadContractOperationNested, TransactionJsonWait, Abi, TransactionOptions, DecodedOperationJson } from "./interface";
|
|
5
5
|
/**
|
|
6
6
|
* The contract class contains the contract ID and contract entries
|
|
7
7
|
* definition needed to encode/decode operations during the
|
|
@@ -40,15 +40,15 @@ import { CallContractOperationNested, UploadContractOperationNested, Transaction
|
|
|
40
40
|
* console.log(result)
|
|
41
41
|
*
|
|
42
42
|
* // Transfer
|
|
43
|
-
* const { transaction
|
|
43
|
+
* const { transaction } = await koin.transfer({
|
|
44
44
|
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
45
45
|
* value: "10.0001",
|
|
46
46
|
* });
|
|
47
47
|
* console.log(`Transaction id ${transaction.id} submitted`);
|
|
48
48
|
*
|
|
49
49
|
* // wait to be mined
|
|
50
|
-
* const
|
|
51
|
-
* console.log(`Transaction mined. Block
|
|
50
|
+
* const blockNumber = await transaction.wait();
|
|
51
|
+
* console.log(`Transaction mined. Block number: ${blockNumber}`);
|
|
52
52
|
* }
|
|
53
53
|
*
|
|
54
54
|
* main();
|
|
@@ -73,8 +73,7 @@ export declare class Contract {
|
|
|
73
73
|
functions: {
|
|
74
74
|
[x: string]: <T = Record<string, unknown>>(args?: unknown, opts?: TransactionOptions) => Promise<{
|
|
75
75
|
operation: CallContractOperationNested;
|
|
76
|
-
transaction?:
|
|
77
|
-
transactionResponse?: SendTransactionResponse;
|
|
76
|
+
transaction?: TransactionJsonWait;
|
|
78
77
|
result?: T;
|
|
79
78
|
}>;
|
|
80
79
|
};
|
|
@@ -137,16 +136,15 @@ export declare class Contract {
|
|
|
137
136
|
* const signer = new Signer({ privateKey, provider });
|
|
138
137
|
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
139
138
|
* const contract = new Contract({ signer, provider, bytecode });
|
|
140
|
-
* const {
|
|
139
|
+
* const { transaction } = await contract.deploy();
|
|
141
140
|
* // wait to be mined
|
|
142
|
-
* const
|
|
143
|
-
* console.log(`Contract uploaded in block
|
|
141
|
+
* const blockNumber = await transaction.wait();
|
|
142
|
+
* console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
144
143
|
* ```
|
|
145
144
|
*/
|
|
146
145
|
deploy(options?: TransactionOptions): Promise<{
|
|
147
146
|
operation: UploadContractOperationNested;
|
|
148
|
-
transaction?:
|
|
149
|
-
transactionResponse?: SendTransactionResponse;
|
|
147
|
+
transaction?: TransactionJsonWait;
|
|
150
148
|
}>;
|
|
151
149
|
/**
|
|
152
150
|
* Encondes a contract operation using Koinos serialization
|
package/lib/Contract.js
CHANGED
|
@@ -41,15 +41,15 @@ const utils_1 = require("./utils");
|
|
|
41
41
|
* console.log(result)
|
|
42
42
|
*
|
|
43
43
|
* // Transfer
|
|
44
|
-
* const { transaction
|
|
44
|
+
* const { transaction } = await koin.transfer({
|
|
45
45
|
* to: "172AB1FgCsYrRAW5cwQ8KjadgxofvgPFd6",
|
|
46
46
|
* value: "10.0001",
|
|
47
47
|
* });
|
|
48
48
|
* console.log(`Transaction id ${transaction.id} submitted`);
|
|
49
49
|
*
|
|
50
50
|
* // wait to be mined
|
|
51
|
-
* const
|
|
52
|
-
* console.log(`Transaction mined. Block
|
|
51
|
+
* const blockNumber = await transaction.wait();
|
|
52
|
+
* console.log(`Transaction mined. Block number: ${blockNumber}`);
|
|
53
53
|
* }
|
|
54
54
|
*
|
|
55
55
|
* main();
|
|
@@ -127,7 +127,7 @@ class Contract {
|
|
|
127
127
|
// write contract (sign and send)
|
|
128
128
|
if (!this.signer)
|
|
129
129
|
throw new Error("signer not found");
|
|
130
|
-
const
|
|
130
|
+
const tx = await this.signer.encodeTransaction({
|
|
131
131
|
...opts,
|
|
132
132
|
operations: [operation],
|
|
133
133
|
});
|
|
@@ -136,8 +136,8 @@ class Contract {
|
|
|
136
136
|
const contractId = (0, utils_1.encodeBase58)(this.id);
|
|
137
137
|
abis[contractId] = this.abi;
|
|
138
138
|
}
|
|
139
|
-
const
|
|
140
|
-
return { operation, transaction
|
|
139
|
+
const transaction = await this.signer.sendTransaction(tx, abis);
|
|
140
|
+
return { operation, transaction };
|
|
141
141
|
};
|
|
142
142
|
});
|
|
143
143
|
}
|
|
@@ -166,10 +166,10 @@ class Contract {
|
|
|
166
166
|
* const signer = new Signer({ privateKey, provider });
|
|
167
167
|
* const bytecode = new Uint8Array([1, 2, 3, 4]);
|
|
168
168
|
* const contract = new Contract({ signer, provider, bytecode });
|
|
169
|
-
* const {
|
|
169
|
+
* const { transaction } = await contract.deploy();
|
|
170
170
|
* // wait to be mined
|
|
171
|
-
* const
|
|
172
|
-
* console.log(`Contract uploaded in block
|
|
171
|
+
* const blockNumber = await transaction.wait();
|
|
172
|
+
* console.log(`Contract uploaded in block number ${blockNumber}`);
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
175
|
async deploy(options) {
|
|
@@ -190,12 +190,12 @@ class Contract {
|
|
|
190
190
|
// return operation if send is false
|
|
191
191
|
if (!(opts === null || opts === void 0 ? void 0 : opts.sendTransaction))
|
|
192
192
|
return { operation };
|
|
193
|
-
const
|
|
193
|
+
const tx = await this.signer.encodeTransaction({
|
|
194
194
|
...opts,
|
|
195
195
|
operations: [operation],
|
|
196
196
|
});
|
|
197
|
-
const
|
|
198
|
-
return { operation, transaction
|
|
197
|
+
const transaction = await this.signer.sendTransaction(tx);
|
|
198
|
+
return { operation, transaction };
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* Encondes a contract operation using Koinos serialization
|
package/lib/Contract.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Contract.js","sourceRoot":"","sources":["../src/Contract.ts"],"names":[],"mappings":";;;AAGA,6CAA0C;
|
|
1
|
+
{"version":3,"file":"Contract.js","sourceRoot":"","sources":["../src/Contract.ts"],"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rC,EAAE,CAAC,aAAa,CAAC,IAAI,EACrB,MAAM,CAAC,KAAK,CACb;iBACF,CAAC;aACH;SACF;QACD,MAAM,IAAI,KAAK,CAAC,qBAAqB,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;IACvE,CAAC;CACF;AArVD,4BAqVC;AAED,kBAAe,QAAQ,CAAC"}
|
package/lib/Provider.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BlockJson, TransactionJson, CallContractOperationJson
|
|
1
|
+
import { BlockJson, TransactionJson, CallContractOperationJson } from "./interface";
|
|
2
2
|
/**
|
|
3
3
|
* Class to connect with the RPC node
|
|
4
4
|
*/
|
|
@@ -119,27 +119,34 @@ export declare class Provider {
|
|
|
119
119
|
};
|
|
120
120
|
}>;
|
|
121
121
|
/**
|
|
122
|
-
* Function to
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
122
|
+
* Function to wait for a transaction to be mined.
|
|
123
|
+
* @param txId - transaction id
|
|
124
|
+
* @param type - Type must be "byBlock" (default) or "byTransactionId".
|
|
125
|
+
* _byBlock_ will query the blockchain to get blocks and search for the
|
|
126
|
+
* transaction there. _byTransactionId_ will query the "transaction store"
|
|
127
|
+
* microservice to search the transaction by its id. If non of them is
|
|
128
|
+
* specified the function will use "byBlock" (as "byTransactionId"
|
|
129
|
+
* requires the transaction store, which is an optional microservice).
|
|
130
|
+
*
|
|
131
|
+
* When _byBlock_ is used it returns the block number.
|
|
132
|
+
*
|
|
133
|
+
* When _byTransactionId_ is used it returns the block id.
|
|
134
|
+
*
|
|
135
|
+
* @param timeout - Timeout in milliseconds. By default it is 30000
|
|
127
136
|
* @example
|
|
128
137
|
* ```ts
|
|
129
|
-
* const
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* signatureData: "...",
|
|
133
|
-
* });
|
|
134
|
-
* console.log("Transaction submitted to the mempool");
|
|
135
|
-
* // wait to be mined
|
|
136
|
-
* const blockNumber = await transactionResponse.wait();
|
|
137
|
-
* // const blockNumber = await transactionResponse.wait("byBlock", 30000);
|
|
138
|
-
* // const blockId = await transactionResponse.wait("byTransactionId", 30000);
|
|
138
|
+
* const blockNumber = await provider.wait(txId);
|
|
139
|
+
* // const blockNumber = await provider.wait(txId, "byBlock", 30000);
|
|
140
|
+
* // const blockId = await provider.wait(txId, "byTransactionId", 30000);
|
|
139
141
|
* console.log("Transaction mined")
|
|
140
142
|
* ```
|
|
141
143
|
*/
|
|
142
|
-
|
|
144
|
+
wait(txId: string, type?: "byTransactionId" | "byBlock", timeout?: number): Promise<string | number>;
|
|
145
|
+
/**
|
|
146
|
+
* Function to call "chain.submit_transaction" to send a signed
|
|
147
|
+
* transaction to the blockchain.
|
|
148
|
+
*/
|
|
149
|
+
sendTransaction(transaction: TransactionJson): Promise<{}>;
|
|
143
150
|
/**
|
|
144
151
|
* Function to call "chain.read_contract" to read a contract.
|
|
145
152
|
* This function is used by [[Contract]] class when read methods
|
package/lib/Provider.js
CHANGED
|
@@ -146,93 +146,95 @@ class Provider {
|
|
|
146
146
|
return (await this.getBlocks(height, 1))[0];
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
|
-
* Function to
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
149
|
+
* Function to wait for a transaction to be mined.
|
|
150
|
+
* @param txId - transaction id
|
|
151
|
+
* @param type - Type must be "byBlock" (default) or "byTransactionId".
|
|
152
|
+
* _byBlock_ will query the blockchain to get blocks and search for the
|
|
153
|
+
* transaction there. _byTransactionId_ will query the "transaction store"
|
|
154
|
+
* microservice to search the transaction by its id. If non of them is
|
|
155
|
+
* specified the function will use "byBlock" (as "byTransactionId"
|
|
156
|
+
* requires the transaction store, which is an optional microservice).
|
|
157
|
+
*
|
|
158
|
+
* When _byBlock_ is used it returns the block number.
|
|
159
|
+
*
|
|
160
|
+
* When _byTransactionId_ is used it returns the block id.
|
|
161
|
+
*
|
|
162
|
+
* @param timeout - Timeout in milliseconds. By default it is 30000
|
|
154
163
|
* @example
|
|
155
164
|
* ```ts
|
|
156
|
-
* const
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
* signatureData: "...",
|
|
160
|
-
* });
|
|
161
|
-
* console.log("Transaction submitted to the mempool");
|
|
162
|
-
* // wait to be mined
|
|
163
|
-
* const blockNumber = await transactionResponse.wait();
|
|
164
|
-
* // const blockNumber = await transactionResponse.wait("byBlock", 30000);
|
|
165
|
-
* // const blockId = await transactionResponse.wait("byTransactionId", 30000);
|
|
165
|
+
* const blockNumber = await provider.wait(txId);
|
|
166
|
+
* // const blockNumber = await provider.wait(txId, "byBlock", 30000);
|
|
167
|
+
* // const blockId = await provider.wait(txId, "byTransactionId", 30000);
|
|
166
168
|
* console.log("Transaction mined")
|
|
167
169
|
* ```
|
|
168
170
|
*/
|
|
169
|
-
async
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (tx)
|
|
199
|
-
bNum = Number(block.block_height);
|
|
200
|
-
});
|
|
201
|
-
const lastId = blocks[blocks.length - 1].block_id;
|
|
202
|
-
return [bNum, lastId];
|
|
203
|
-
};
|
|
204
|
-
let blockNumber = 0;
|
|
205
|
-
let iniBlock = 0;
|
|
206
|
-
let previousId = "";
|
|
207
|
-
while (Date.now() < iniTime + timeout) {
|
|
208
|
-
await sleep(1000);
|
|
209
|
-
const { head_topology: headTopology } = await this.getHeadInfo();
|
|
210
|
-
if (blockNumber === 0) {
|
|
211
|
-
blockNumber = Number(headTopology.height);
|
|
212
|
-
iniBlock = blockNumber;
|
|
213
|
-
}
|
|
214
|
-
if (Number(headTopology.height) === blockNumber - 1 &&
|
|
215
|
-
previousId &&
|
|
216
|
-
previousId !== headTopology.id) {
|
|
217
|
-
const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
|
|
218
|
-
if (bNum)
|
|
219
|
-
return bNum;
|
|
220
|
-
previousId = lastId;
|
|
221
|
-
blockNumber = Number(headTopology.height) + 1;
|
|
222
|
-
}
|
|
223
|
-
// eslint-disable-next-line no-continue
|
|
224
|
-
if (blockNumber > Number(headTopology.height))
|
|
225
|
-
continue;
|
|
226
|
-
const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
|
|
227
|
-
if (bNum)
|
|
228
|
-
return bNum;
|
|
229
|
-
if (!previousId)
|
|
230
|
-
previousId = lastId;
|
|
231
|
-
blockNumber += 1;
|
|
232
|
-
}
|
|
233
|
-
throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
|
|
234
|
-
},
|
|
171
|
+
async wait(txId, type = "byBlock", timeout = 30000) {
|
|
172
|
+
const iniTime = Date.now();
|
|
173
|
+
if (type === "byTransactionId") {
|
|
174
|
+
while (Date.now() < iniTime + timeout) {
|
|
175
|
+
await sleep(1000);
|
|
176
|
+
const { transactions } = await this.getTransactionsById([txId]);
|
|
177
|
+
if (transactions &&
|
|
178
|
+
transactions[0] &&
|
|
179
|
+
transactions[0].containing_blocks)
|
|
180
|
+
return transactions[0].containing_blocks[0];
|
|
181
|
+
}
|
|
182
|
+
throw new Error(`Transaction not mined after ${timeout} ms`);
|
|
183
|
+
}
|
|
184
|
+
// byBlock
|
|
185
|
+
const findTxInBlocks = async (ini, numBlocks, idRef) => {
|
|
186
|
+
const blocks = await this.getBlocks(ini, numBlocks, idRef);
|
|
187
|
+
let bNum = 0;
|
|
188
|
+
blocks.forEach((block) => {
|
|
189
|
+
if (!block ||
|
|
190
|
+
!block.block ||
|
|
191
|
+
!block.block_id ||
|
|
192
|
+
!block.block.transactions)
|
|
193
|
+
return;
|
|
194
|
+
const tx = block.block.transactions.find((t) => t.id === txId);
|
|
195
|
+
if (tx)
|
|
196
|
+
bNum = Number(block.block_height);
|
|
197
|
+
});
|
|
198
|
+
const lastId = blocks[blocks.length - 1].block_id;
|
|
199
|
+
return [bNum, lastId];
|
|
235
200
|
};
|
|
201
|
+
let blockNumber = 0;
|
|
202
|
+
let iniBlock = 0;
|
|
203
|
+
let previousId = "";
|
|
204
|
+
while (Date.now() < iniTime + timeout) {
|
|
205
|
+
await sleep(1000);
|
|
206
|
+
const { head_topology: headTopology } = await this.getHeadInfo();
|
|
207
|
+
if (blockNumber === 0) {
|
|
208
|
+
blockNumber = Number(headTopology.height);
|
|
209
|
+
iniBlock = blockNumber;
|
|
210
|
+
}
|
|
211
|
+
if (Number(headTopology.height) === blockNumber - 1 &&
|
|
212
|
+
previousId &&
|
|
213
|
+
previousId !== headTopology.id) {
|
|
214
|
+
const [bNum, lastId] = await findTxInBlocks(iniBlock, Number(headTopology.height) - iniBlock + 1, headTopology.id);
|
|
215
|
+
if (bNum)
|
|
216
|
+
return bNum;
|
|
217
|
+
previousId = lastId;
|
|
218
|
+
blockNumber = Number(headTopology.height) + 1;
|
|
219
|
+
}
|
|
220
|
+
// eslint-disable-next-line no-continue
|
|
221
|
+
if (blockNumber > Number(headTopology.height))
|
|
222
|
+
continue;
|
|
223
|
+
const [bNum, lastId] = await findTxInBlocks(blockNumber, 1, headTopology.id);
|
|
224
|
+
if (bNum)
|
|
225
|
+
return bNum;
|
|
226
|
+
if (!previousId)
|
|
227
|
+
previousId = lastId;
|
|
228
|
+
blockNumber += 1;
|
|
229
|
+
}
|
|
230
|
+
throw new Error(`Transaction not mined after ${timeout} ms. Blocks checked from ${iniBlock} to ${blockNumber}`);
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Function to call "chain.submit_transaction" to send a signed
|
|
234
|
+
* transaction to the blockchain.
|
|
235
|
+
*/
|
|
236
|
+
async sendTransaction(transaction) {
|
|
237
|
+
return this.call("chain.submit_transaction", { transaction });
|
|
236
238
|
}
|
|
237
239
|
/**
|
|
238
240
|
* Function to call "chain.read_contract" to read a contract.
|
package/lib/Provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../src/Provider.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;
|
|
1
|
+
{"version":3,"file":"Provider.js","sourceRoot":"","sources":["../src/Provider.ts"],"names":[],"mappings":";;;;;;AAAA,8DAAgC;AAOhC,KAAK,UAAU,KAAK,CAAC,EAAU;IAC7B,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,MAAa,QAAQ;IAwCnB;;;;;;;;;;;OAWG;IACH,YAAY,QAA2B;QACrC,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC;YAAE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;;YACjD,IAAI,CAAC,QAAQ,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChC,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,GAAG,EAAE,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,IAAI,CAAc,MAAc,EAAE,MAAe;QACrD,qCAAqC;QACrC,iDAAiD;QACjD,OAAO,IAAI,EAAE;YACX,IAAI;gBACF,MAAM,IAAI,GAAG;oBACX,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC;oBACpC,OAAO,EAAE,KAAK;oBACd,MAAM;oBACN,MAAM;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YAAY,CAAC,EAAE,CAChB,CAAC;gBACF,IAAI,IAAI;oBAAE,OAAO,IAAI,CAAC;gBACtB,UAAU,GAAG,MAAM,CAAC;gBACpB,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;aAC/C;YACD,uCAAuC;YACvC,IAAI,WAAW,GAAG,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC;gBAAE,SAAS;YACxD,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,cAAc,CACzC,WAAW,EACX,CAAC,EACD,YAAY,CAAC,EAAE,CAChB,CAAC;YACF,IAAI,IAAI;gBAAE,OAAO,IAAI,CAAC;YACtB,IAAI,CAAC,UAAU;gBAAE,UAAU,GAAG,MAAM,CAAC;YACrC,WAAW,IAAI,CAAC,CAAC;SAClB;QACD,MAAM,IAAI,KAAK,CACb,+BAA+B,OAAO,4BAA4B,QAAQ,OAAO,WAAW,EAAE,CAC/F,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,eAAe,CAAC,WAA4B;QAChD,OAAO,IAAI,CAAC,IAAI,CAAC,0BAA0B,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;IAChE,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,SAAoC;QAIrD,OAAO,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;CACF;AArXD,4BAqXC;AAED,kBAAe,QAAQ,CAAC"}
|
package/lib/Serializer.d.ts
CHANGED
|
@@ -70,12 +70,16 @@ export declare class Serializer {
|
|
|
70
70
|
* It also prepares the bytes for special cases (base58, hex string)
|
|
71
71
|
* when bytesConversion param is true.
|
|
72
72
|
*/
|
|
73
|
-
serialize(valueDecoded: Record<string, unknown>, typeName?: string
|
|
73
|
+
serialize(valueDecoded: Record<string, unknown>, typeName?: string, opts?: {
|
|
74
|
+
bytesConversion?: boolean;
|
|
75
|
+
}): Promise<Uint8Array>;
|
|
74
76
|
/**
|
|
75
77
|
* Function to decode bytes using the protobuffer definitions
|
|
76
78
|
* It also encodes the bytes for special cases (base58, hex string)
|
|
77
79
|
* when bytesConversion param is true.
|
|
78
80
|
*/
|
|
79
|
-
deserialize<T = Record<string, unknown>>(valueEncoded: string | Uint8Array, typeName?: string
|
|
81
|
+
deserialize<T = Record<string, unknown>>(valueEncoded: string | Uint8Array, typeName?: string, opts?: {
|
|
82
|
+
bytesConversion?: boolean;
|
|
83
|
+
}): Promise<T>;
|
|
80
84
|
}
|
|
81
85
|
export default Serializer;
|
package/lib/Serializer.js
CHANGED
|
@@ -73,10 +73,13 @@ class Serializer {
|
|
|
73
73
|
* It also prepares the bytes for special cases (base58, hex string)
|
|
74
74
|
* when bytesConversion param is true.
|
|
75
75
|
*/
|
|
76
|
-
async serialize(valueDecoded, typeName) {
|
|
76
|
+
async serialize(valueDecoded, typeName, opts) {
|
|
77
77
|
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
78
78
|
let object = {};
|
|
79
|
-
|
|
79
|
+
const bytesConversion = (opts === null || opts === void 0 ? void 0 : opts.bytesConversion) === undefined
|
|
80
|
+
? this.bytesConversion
|
|
81
|
+
: opts.bytesConversion;
|
|
82
|
+
if (bytesConversion) {
|
|
80
83
|
// TODO: format from Buffer to base58/base64 for nested fields
|
|
81
84
|
Object.keys(protobufType.fields).forEach((fieldName) => {
|
|
82
85
|
const { options, name, type } = protobufType.fields[fieldName];
|
|
@@ -122,14 +125,17 @@ class Serializer {
|
|
|
122
125
|
* It also encodes the bytes for special cases (base58, hex string)
|
|
123
126
|
* when bytesConversion param is true.
|
|
124
127
|
*/
|
|
125
|
-
async deserialize(valueEncoded, typeName) {
|
|
128
|
+
async deserialize(valueEncoded, typeName, opts) {
|
|
126
129
|
const valueBuffer = typeof valueEncoded === "string"
|
|
127
130
|
? (0, utils_1.decodeBase64)(valueEncoded)
|
|
128
131
|
: valueEncoded;
|
|
129
132
|
const protobufType = this.defaultType || this.root.lookupType(typeName);
|
|
130
133
|
const message = protobufType.decode(valueBuffer);
|
|
131
134
|
const object = protobufType.toObject(message, { longs: String });
|
|
132
|
-
|
|
135
|
+
const bytesConversion = (opts === null || opts === void 0 ? void 0 : opts.bytesConversion) === undefined
|
|
136
|
+
? this.bytesConversion
|
|
137
|
+
: opts.bytesConversion;
|
|
138
|
+
if (!bytesConversion)
|
|
133
139
|
return object;
|
|
134
140
|
// TODO: format from Buffer to base58/base64 for nested fields
|
|
135
141
|
Object.keys(protobufType.fields).forEach((fieldName) => {
|
package/lib/Serializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Serializer.js","sourceRoot":"","sources":["../src/Serializer.ts"],"names":[],"mappings":";;;AAAA,qDAAqD;AACrD,4CAA0D;AAC1D,mCAOiB;AAEjB,MAAM,QAAQ,GAAG,qBAAqB,CAAC;AAEvC;;;;;;;;GAQG;AACH,SAAS,SAAS,CAAC,KAAc;IAC/B,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC1D,OAAO,KAAK,CAAC;KACd;IACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAY,CAAC;AACtD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAa,UAAU;IAsBrB,YACE,KAAiB,EACjB,IAaC;QApBH;;WAEG;QACH,oBAAe,GAAG,IAAI,CAAC;QAmBrB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,IAAI,GAAG,YAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACtC,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,eAAe;YACvB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,eAAe,CAA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CAAC;IACrB,CAAC;CACF;AA7KD,gCA6KC;AAED,kBAAe,UAAU,CAAC"}
|
package/lib/Signer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Provider } from "./Provider";
|
|
2
|
-
import { TransactionJson, ActiveTransactionData, Abi,
|
|
2
|
+
import { TransactionJson, TransactionJsonWait, ActiveTransactionData, Abi, RecoverPublicKeyOptions, BlockJson } from "./interface";
|
|
3
3
|
import { Serializer } from "./Serializer";
|
|
4
4
|
export interface SignerInterface {
|
|
5
5
|
provider?: Provider;
|
|
@@ -7,7 +7,7 @@ export interface SignerInterface {
|
|
|
7
7
|
getAddress: (compressed?: boolean) => string;
|
|
8
8
|
getPrivateKey: (format: "wif" | "hex", compressed?: boolean) => string;
|
|
9
9
|
signTransaction: (tx: TransactionJson) => Promise<TransactionJson>;
|
|
10
|
-
sendTransaction: (tx: TransactionJson, abis?: Record<string, Abi>) => Promise<
|
|
10
|
+
sendTransaction: (tx: TransactionJson, abis?: Record<string, Abi>) => Promise<TransactionJsonWait>;
|
|
11
11
|
encodeTransaction: (activeData: ActiveTransactionData) => Promise<TransactionJson>;
|
|
12
12
|
decodeTransaction: (tx: TransactionJson) => Promise<ActiveTransactionData>;
|
|
13
13
|
}
|
|
@@ -163,13 +163,27 @@ export declare class Signer implements SignerInterface {
|
|
|
163
163
|
* ```
|
|
164
164
|
*/
|
|
165
165
|
getPrivateKey(format?: "wif" | "hex", compressed?: boolean): string;
|
|
166
|
+
/**
|
|
167
|
+
* Function to sign a hash value. It returns the signature encoded
|
|
168
|
+
* in base64. The signature is in compact format with the
|
|
169
|
+
* recovery byte
|
|
170
|
+
* @param hash Hash value. Also known as digest
|
|
171
|
+
*/
|
|
172
|
+
signHash(hash: Uint8Array): Promise<string>;
|
|
166
173
|
/**
|
|
167
174
|
* Function to sign a transaction. It's important to remark that
|
|
168
175
|
* the transaction parameter is modified inside this function.
|
|
169
176
|
* @param tx - Unsigned transaction
|
|
170
|
-
* @returns
|
|
171
177
|
*/
|
|
172
178
|
signTransaction(tx: TransactionJson): Promise<TransactionJson>;
|
|
179
|
+
/**
|
|
180
|
+
* Function to sign a block for federated consensus. That is,
|
|
181
|
+
* just the ecdsa signature. For other algorithms, like PoW,
|
|
182
|
+
* you have to sign the block and then process the signature
|
|
183
|
+
* to add the extra data (nonce in the case of PoW).
|
|
184
|
+
* @param block - Unsigned block
|
|
185
|
+
*/
|
|
186
|
+
signBlock(block: BlockJson): Promise<BlockJson>;
|
|
173
187
|
/**
|
|
174
188
|
* Function to sign and send a transaction. It internally uses
|
|
175
189
|
* [[Provider.sendTransaction]]
|
|
@@ -179,7 +193,7 @@ export declare class Signer implements SignerInterface {
|
|
|
179
193
|
* transaction. This parameter is optional.
|
|
180
194
|
* @returns
|
|
181
195
|
*/
|
|
182
|
-
sendTransaction(tx: TransactionJson, _abis?: Record<string, Abi>): Promise<
|
|
196
|
+
sendTransaction(tx: TransactionJson, _abis?: Record<string, Abi>): Promise<TransactionJsonWait>;
|
|
183
197
|
/**
|
|
184
198
|
* Function to recover the public key from a signed
|
|
185
199
|
* transaction or block.
|
|
@@ -221,7 +235,7 @@ export declare class Signer implements SignerInterface {
|
|
|
221
235
|
* defaultTypeName: "pow_signature_data",
|
|
222
236
|
* });
|
|
223
237
|
*
|
|
224
|
-
* const signer = await
|
|
238
|
+
* const signer = await signer.recoverPublicKey(block, {
|
|
225
239
|
* transformSignature: async (signatureData) => {
|
|
226
240
|
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
227
241
|
* return powSignatureData.recoverable_signature;
|
|
@@ -229,14 +243,14 @@ export declare class Signer implements SignerInterface {
|
|
|
229
243
|
* });
|
|
230
244
|
* ```
|
|
231
245
|
*/
|
|
232
|
-
|
|
246
|
+
recoverPublicKey(txOrBlock: TransactionJson | BlockJson, opts?: RecoverPublicKeyOptions): Promise<string>;
|
|
233
247
|
/**
|
|
234
248
|
* Function to recover the signer address from a signed
|
|
235
249
|
* transaction or block.
|
|
236
250
|
* The output format can be compressed (default) or uncompressed.
|
|
237
251
|
* @example
|
|
238
252
|
* ```ts
|
|
239
|
-
* const publicKey = await
|
|
253
|
+
* const publicKey = await signer.recoverAddress(tx);
|
|
240
254
|
* ```
|
|
241
255
|
*
|
|
242
256
|
* If the signature data contains more data, like in the
|
|
@@ -270,7 +284,7 @@ export declare class Signer implements SignerInterface {
|
|
|
270
284
|
* defaultTypeName: "pow_signature_data",
|
|
271
285
|
* });
|
|
272
286
|
*
|
|
273
|
-
* const signer = await
|
|
287
|
+
* const signer = await signer.recoverAddress(block, {
|
|
274
288
|
* transformSignature: async (signatureData) => {
|
|
275
289
|
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
276
290
|
* return powSignatureData.recoverable_signature;
|
|
@@ -278,12 +292,12 @@ export declare class Signer implements SignerInterface {
|
|
|
278
292
|
* });
|
|
279
293
|
* ```
|
|
280
294
|
*/
|
|
281
|
-
|
|
295
|
+
recoverAddress(txOrBlock: TransactionJson | BlockJson, opts?: RecoverPublicKeyOptions): Promise<string>;
|
|
282
296
|
/**
|
|
283
297
|
* Function to encode a transaction
|
|
284
298
|
* @param activeData - Active data consists of nonce, rc_limit, and
|
|
285
299
|
* operations. Do not set the nonce to get it from the blockchain
|
|
286
|
-
* using the provider. The rc_limit is
|
|
300
|
+
* using the provider. The rc_limit is 1e8 by default.
|
|
287
301
|
* @returns A transaction encoded. The active field is encoded in
|
|
288
302
|
* base64url
|
|
289
303
|
*/
|