koilib 1.5.0 → 2.3.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/lib/Provider.js CHANGED
@@ -4,8 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Provider = void 0;
7
- const multibase_1 = __importDefault(require("multibase"));
8
7
  const axios_1 = __importDefault(require("axios"));
8
+ async function sleep(ms) {
9
+ return new Promise((r) => setTimeout(r, ms));
10
+ }
9
11
  /**
10
12
  * Class to connect with the RPC node
11
13
  */
@@ -76,23 +78,44 @@ class Provider {
76
78
  }
77
79
  }
78
80
  if (response.data.error)
79
- throw new Error(response.data.error.message);
81
+ throw new Error(JSON.stringify(response.data.error));
80
82
  return response.data.result;
81
83
  }
82
84
  /**
83
85
  * Function to call "chain.get_account_nonce" to return the number of
84
86
  * transactions for a particular account. This call is used
85
87
  * when creating new transactions.
86
- * @param address - account address
88
+ * @param account - account address
87
89
  * @returns Nonce
88
90
  */
89
- async getNonce(address) {
90
- const bufferAddress = new TextEncoder().encode(address);
91
- const encBase64 = new TextDecoder().decode(multibase_1.default.encode("M", bufferAddress));
92
- const result = await this.call("chain.get_account_nonce", {
93
- account: encBase64,
91
+ async getNonce(account) {
92
+ const { nonce } = await this.call("chain.get_account_nonce", { account });
93
+ if (!nonce)
94
+ return 0;
95
+ return Number(nonce);
96
+ }
97
+ async getAccountRc(account) {
98
+ const { rc } = await this.call("chain.get_account_rc", {
99
+ account,
100
+ });
101
+ if (!rc)
102
+ return "0";
103
+ return rc;
104
+ }
105
+ /**
106
+ * Get transactions by id and their corresponding block ids
107
+ */
108
+ async getTransactionsById(transactionIds) {
109
+ return this.call("transaction_store.get_transactions_by_id", {
110
+ transaction_ids: transactionIds,
111
+ });
112
+ }
113
+ async getBlocksById(blockIds) {
114
+ return this.call("block_store.get_blocks_by_id", {
115
+ block_id: blockIds,
116
+ return_block: true,
117
+ return_receipt: false,
94
118
  });
95
- return Number(result.nonce);
96
119
  }
97
120
  /**
98
121
  * Function to get info from the head block in the blockchain
@@ -130,24 +153,51 @@ class Provider {
130
153
  }
131
154
  /**
132
155
  * Function to call "chain.submit_transaction" to send a signed
133
- * transaction to the blockchain
156
+ * transaction to the blockchain. It returns an object with the async
157
+ * function "wait", which can be called to wait for the
158
+ * transaction to be mined.
134
159
  * @param transaction - Signed transaction
135
- * @returns
160
+ * @example
161
+ * ```ts
162
+ * const { transactionResponse } = await provider.sendTransaction({
163
+ * id: "1220...",
164
+ * active: "...",
165
+ * signatureData: "...",
166
+ * });
167
+ * console.log("Transaction submitted to the mempool");
168
+ * // wait to be mined
169
+ * const blockId = await transactionResponse.wait();
170
+ * console.log("Transaction mined")
171
+ * ```
136
172
  */
137
173
  async sendTransaction(transaction) {
138
- return this.call("chain.submit_transaction", { transaction });
174
+ await this.call("chain.submit_transaction", { transaction });
175
+ const startTime = Date.now() + 10000;
176
+ return {
177
+ wait: async () => {
178
+ // sleep some seconds before it gets mined
179
+ await sleep(startTime - Date.now() - 1000);
180
+ for (let i = 0; i < 30; i += 1) {
181
+ await sleep(1000);
182
+ const { transactions } = await this.getTransactionsById([
183
+ transaction.id,
184
+ ]);
185
+ if (transactions &&
186
+ transactions[0] &&
187
+ transactions[0].containing_blocks)
188
+ return transactions[0].containing_blocks[0];
189
+ }
190
+ throw new Error(`Transaction not mined after 40 seconds`);
191
+ },
192
+ };
139
193
  }
140
194
  /**
141
195
  * Function to call "chain.read_contract" to read a contract.
142
- * The operation must be encoded (see [[EncodedOperation]]).
143
- * See also [[Wallet.readContract]] which, apart from the Provider,
144
- * uses the contract definition and it is prepared to receive
145
- * the operation decoded and return the result decoded as well.
146
- * @param operation - Encoded operation
147
- * @returns Encoded result
196
+ * This function is used by [[Contract]] class when read methods
197
+ * are invoked.
148
198
  */
149
199
  async readContract(operation) {
150
- return this.call("chain.read_contract", operation.value);
200
+ return this.call("chain.read_contract", operation);
151
201
  }
152
202
  }
153
203
  exports.Provider = Provider;
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.js","sourceRoot":"","sources":["../src/Provider.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAkC;AAClC,kDAA6C;AAI7C;;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,IAAI,QAAQ,GAGP;YACH,IAAI,EAAE,EAAE;YACR,MAAM,EAAE,CAAC;YACT,UAAU,EAAE,EAAE;YACd,OAAO,EAAE,EAAE;YACX,MAAM,EAAE,EAAE;SACX,CAAC;QAEF,IAAI,OAAO,GAAG,KAAK,CAAC;QAEpB,qCAAqC;QACrC,OAAO,CAAC,OAAO,EAAE;YACf,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;iBACP,CAAC;gBAEF,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;gBAE9C,uDAAuD;gBACvD;;;;;;sCAMsB;gBAEtB,QAAQ,GAAG,MAAM,eAAK,CAAC,IAAI,CAGxB,GAAG,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG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,KAAK,IAAI,EAAE;gBACf,0CAA0C;gBAC1C,MAAM,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;gBAC3C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE;oBAC9B,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;oBAClB,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,IAAI,CAAC,mBAAmB,CAAC;wBACtD,WAAW,CAAC,EAAY;qBACzB,CAAC,CAAC;oBACH,IACE,YAAY;wBACZ,YAAY,CAAC,CAAC,CAAC;wBACf,YAAY,CAAC,CAAC,CAAC,CAAC,iBAAiB;wBAEjC,OAAO,YAAY,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;iBAC/C;gBACD,MAAM,IAAI,KAAK,CAAC,wCAAwC,CAAC,CAAC;YAC5D,CAAC;SACF,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,YAAY,CAAC,SAAoC;QAIrD,OAAO,IAAI,CAAC,IAAI,CAAC,qBAAqB,EAAE,SAAS,CAAC,CAAC;IACrD,CAAC;CACF;AAzTD,4BAyTC;AAED,kBAAe,QAAQ,CAAC"}
@@ -0,0 +1,81 @@
1
+ import { Root, Type, INamespace } from "protobufjs/light";
2
+ /**
3
+ * The serializer class serialize and deserialize data using
4
+ * protocol buffers.
5
+ *
6
+ * NOTE: This class uses the [protobufjs/light](https://www.npmjs.com/package/protobufjs)
7
+ * library internally, which uses reflection (use of _eval_
8
+ * and _new Function_) for the construction of the types.
9
+ * This could cause issues in environments where _eval_ is not
10
+ * allowed, like in browser extensions. In such cases, this class
11
+ * must be confined in a [sandbox environment](https://developer.chrome.com/docs/apps/app_external/#sandboxing)
12
+ * where _eval_ is allowed. This is the principal reason of
13
+ * having the serializer in a separate class.
14
+ *
15
+ * @example
16
+ *
17
+ * ```ts
18
+ * const descriptorJson = {
19
+ * nested: {
20
+ * awesomepackage: {
21
+ * nested: {
22
+ * AwesomeMessage: {
23
+ * fields: {
24
+ * awesomeField: {
25
+ * type: "string",
26
+ * id: 1
27
+ * }
28
+ * }
29
+ * }
30
+ * }
31
+ * }
32
+ * }
33
+ * }
34
+ * const serializer = new Serializer(descriptorJson)
35
+ * ```
36
+ */
37
+ export declare class Serializer {
38
+ /**
39
+ * Protobuffers descriptor in JSON format.
40
+ * See https://www.npmjs.com/package/protobufjs#using-json-descriptors
41
+ */
42
+ types: INamespace;
43
+ /**
44
+ * Protobuffer definitions
45
+ */
46
+ root: Root;
47
+ /**
48
+ * Default type for all serializations
49
+ */
50
+ defaultType?: Type;
51
+ /**
52
+ * Preformat bytes for base64, base58 or hex string
53
+ */
54
+ bytesConversion: boolean;
55
+ constructor(types: INamespace, opts?: {
56
+ /**
57
+ * Default type name. Use this option when you
58
+ * always want to serialize/deserialize the same type
59
+ */
60
+ defaultTypeName?: string;
61
+ /**
62
+ * Bytes conversion. Option to preformat bytes
63
+ * when "(koinos_bytes_type)" is defined in the type
64
+ * definitions. By default it is true.
65
+ */
66
+ bytesConversion?: boolean;
67
+ });
68
+ /**
69
+ * Function to encode a type using the protobuffer definitions
70
+ * It also prepares the bytes for special cases (base58, hex string)
71
+ * when bytesConversion param is true.
72
+ */
73
+ serialize(valueDecoded: Record<string, unknown>, typeName?: string): Promise<Uint8Array>;
74
+ /**
75
+ * Function to decode bytes using the protobuffer definitions
76
+ * It also encodes the bytes for special cases (base58, hex string)
77
+ * when bytesConversion param is true.
78
+ */
79
+ deserialize<T = Record<string, unknown>>(valueEncoded: string | Uint8Array, typeName?: string): Promise<T>;
80
+ }
81
+ export default Serializer;
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Serializer = void 0;
4
+ /* eslint-disable @typescript-eslint/require-await */
5
+ const light_1 = require("protobufjs/light");
6
+ const utils_1 = require("./utils");
7
+ const OP_BYTES = "(koinos_bytes_type)";
8
+ /**
9
+ * Makes a copy of a value. The returned value can be modified
10
+ * without altering the original one. Although this is not needed
11
+ * for strings or numbers and only needed for objects and arrays,
12
+ * all these options are covered in a single function
13
+ *
14
+ * It is assumed that the argument is number, string, or contructions
15
+ * of these types inside objects or arrays.
16
+ */
17
+ function copyValue(value) {
18
+ if (typeof value === "string" || typeof value === "number") {
19
+ return value;
20
+ }
21
+ return JSON.parse(JSON.stringify(value));
22
+ }
23
+ /**
24
+ * The serializer class serialize and deserialize data using
25
+ * protocol buffers.
26
+ *
27
+ * NOTE: This class uses the [protobufjs/light](https://www.npmjs.com/package/protobufjs)
28
+ * library internally, which uses reflection (use of _eval_
29
+ * and _new Function_) for the construction of the types.
30
+ * This could cause issues in environments where _eval_ is not
31
+ * allowed, like in browser extensions. In such cases, this class
32
+ * must be confined in a [sandbox environment](https://developer.chrome.com/docs/apps/app_external/#sandboxing)
33
+ * where _eval_ is allowed. This is the principal reason of
34
+ * having the serializer in a separate class.
35
+ *
36
+ * @example
37
+ *
38
+ * ```ts
39
+ * const descriptorJson = {
40
+ * nested: {
41
+ * awesomepackage: {
42
+ * nested: {
43
+ * AwesomeMessage: {
44
+ * fields: {
45
+ * awesomeField: {
46
+ * type: "string",
47
+ * id: 1
48
+ * }
49
+ * }
50
+ * }
51
+ * }
52
+ * }
53
+ * }
54
+ * }
55
+ * const serializer = new Serializer(descriptorJson)
56
+ * ```
57
+ */
58
+ class Serializer {
59
+ constructor(types, opts) {
60
+ /**
61
+ * Preformat bytes for base64, base58 or hex string
62
+ */
63
+ this.bytesConversion = true;
64
+ this.types = types;
65
+ this.root = light_1.Root.fromJSON(this.types);
66
+ if (opts === null || opts === void 0 ? void 0 : opts.defaultTypeName)
67
+ this.defaultType = this.root.lookupType(opts.defaultTypeName);
68
+ if (opts && typeof opts.bytesConversion !== "undefined")
69
+ this.bytesConversion = opts.bytesConversion;
70
+ }
71
+ /**
72
+ * Function to encode a type using the protobuffer definitions
73
+ * It also prepares the bytes for special cases (base58, hex string)
74
+ * when bytesConversion param is true.
75
+ */
76
+ async serialize(valueDecoded, typeName) {
77
+ const protobufType = this.defaultType || this.root.lookupType(typeName);
78
+ let object = {};
79
+ if (this.bytesConversion) {
80
+ // TODO: format from Buffer to base58/base64 for nested fields
81
+ Object.keys(protobufType.fields).forEach((fieldName) => {
82
+ const { options, name, type } = protobufType.fields[fieldName];
83
+ // No byte conversion
84
+ if (type !== "bytes") {
85
+ object[name] = copyValue(valueDecoded[name]);
86
+ return;
87
+ }
88
+ // Default byte conversion
89
+ if (!options || !options[OP_BYTES]) {
90
+ object[name] = utils_1.decodeBase64(valueDecoded[name]);
91
+ return;
92
+ }
93
+ // Specific byte conversion
94
+ switch (options[OP_BYTES]) {
95
+ case "BASE58":
96
+ case "CONTRACT_ID":
97
+ case "ADDRESS":
98
+ object[name] = utils_1.decodeBase58(valueDecoded[name]);
99
+ break;
100
+ case "BASE64":
101
+ object[name] = utils_1.decodeBase64(valueDecoded[name]);
102
+ break;
103
+ case "HEX":
104
+ case "BLOCK_ID":
105
+ case "TRANSACTION_ID":
106
+ object[name] = utils_1.toUint8Array(valueDecoded[name].replace("0x", ""));
107
+ break;
108
+ default:
109
+ throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
110
+ }
111
+ });
112
+ }
113
+ else {
114
+ object = valueDecoded;
115
+ }
116
+ const message = protobufType.create(object);
117
+ const buffer = protobufType.encode(message).finish();
118
+ return buffer;
119
+ }
120
+ /**
121
+ * Function to decode bytes using the protobuffer definitions
122
+ * It also encodes the bytes for special cases (base58, hex string)
123
+ * when bytesConversion param is true.
124
+ */
125
+ async deserialize(valueEncoded, typeName) {
126
+ const valueBuffer = typeof valueEncoded === "string"
127
+ ? utils_1.decodeBase64(valueEncoded)
128
+ : valueEncoded;
129
+ const protobufType = this.defaultType || this.root.lookupType(typeName);
130
+ const message = protobufType.decode(valueBuffer);
131
+ const object = protobufType.toObject(message, { longs: String });
132
+ if (!this.bytesConversion)
133
+ return object;
134
+ // TODO: format from Buffer to base58/base64 for nested fields
135
+ Object.keys(protobufType.fields).forEach((fieldName) => {
136
+ const { options, name, type } = protobufType.fields[fieldName];
137
+ // No byte conversion
138
+ if (type !== "bytes")
139
+ return;
140
+ // Default byte conversion
141
+ if (!options || !options[OP_BYTES]) {
142
+ object[name] = utils_1.encodeBase64(object[name]);
143
+ return;
144
+ }
145
+ // Specific byte conversion
146
+ switch (options[OP_BYTES]) {
147
+ case "BASE58":
148
+ case "CONTRACT_ID":
149
+ case "ADDRESS":
150
+ object[name] = utils_1.encodeBase58(object[name]);
151
+ break;
152
+ case "BASE64":
153
+ object[name] = utils_1.encodeBase64(object[name]);
154
+ break;
155
+ case "HEX":
156
+ case "BLOCK_ID":
157
+ case "TRANSACTION_ID":
158
+ object[name] = `0x${utils_1.toHexString(object[name])}`;
159
+ break;
160
+ default:
161
+ throw new Error(`unknown koinos_byte_type ${options[OP_BYTES]}`);
162
+ }
163
+ });
164
+ return object;
165
+ }
166
+ }
167
+ exports.Serializer = Serializer;
168
+ exports.default = Serializer;
169
+ //# sourceMappingURL=Serializer.js.map
@@ -0,0 +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,I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gBACR;oBACE,MAAM,IAAI,KAAK,CACb,4BAA4B,OAAO,CAAC,QAAQ,CAAW,EAAE,CAC1D,CAAC;aACL;QACH,CAAC,CAAC,CAAC;QAEH,OAAO,MAAW,CAAC;IACrB,CAAC;CACF;AAnKD,gCAmKC;AAED,kBAAe,UAAU,CAAC"}
package/lib/Signer.d.ts CHANGED
@@ -1,4 +1,16 @@
1
- import { Transaction } from "./interface";
1
+ import { Provider } from "./Provider";
2
+ import { TransactionJson, ActiveTransactionData, Abi, SendTransactionResponse, RecoverPublicKeyOptions, BlockJson } from "./interface";
3
+ import { Serializer } from "./Serializer";
4
+ export interface SignerInterface {
5
+ provider?: Provider;
6
+ serializer?: Serializer;
7
+ getAddress(compressed?: boolean): string;
8
+ getPrivateKey(format: "wif" | "hex", compressed?: boolean): string;
9
+ signTransaction(tx: TransactionJson): Promise<TransactionJson>;
10
+ sendTransaction(tx: TransactionJson, abis?: Record<string, Abi>): Promise<SendTransactionResponse>;
11
+ encodeTransaction(activeData: ActiveTransactionData): Promise<TransactionJson>;
12
+ decodeTransaction(tx: TransactionJson): Promise<ActiveTransactionData>;
13
+ }
2
14
  /**
3
15
  * The Signer Class contains the private key needed to sign transactions.
4
16
  * It can be created using the seed, wif, or private key
@@ -6,7 +18,8 @@ import { Transaction } from "./interface";
6
18
  * @example
7
19
  * using private key as hex string
8
20
  * ```ts
9
- * var signer = new Signer("ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c");
21
+ * var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
22
+ * var signer = new Signer({ privateKey });
10
23
  * ```
11
24
  * <br>
12
25
  *
@@ -18,14 +31,15 @@ import { Transaction } from "./interface";
18
31
  * 1, 203, 55, 128, 187, 2, 192, 249,
19
32
  * 205, 254, 157, 9, 218, 173, 223, 156
20
33
  * ]);
21
- * var signer = new Signer(buffer);
34
+ * var signer = new Signer({ privateKey: buffer });
22
35
  * ```
23
36
  *
24
37
  * <br>
25
38
  *
26
39
  * using private key as bigint
27
40
  * ```ts
28
- * var signer = new Signer(106982601049961974618234078204952280507266494766432547312316920283818886029212n);
41
+ * var privateKey = 106982601049961974618234078204952280507266494766432547312316920283818886029212n;
42
+ * var signer = new Signer({ privateKey });
29
43
  * ```
30
44
  *
31
45
  * <br>
@@ -41,8 +55,17 @@ import { Transaction } from "./interface";
41
55
  * ```ts
42
56
  * var signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM");
43
57
  * ```
58
+ *
59
+ * <br>
60
+ *
61
+ * defining a provider
62
+ * ```ts
63
+ * var provider = new Provider(["https://example.com/jsonrpc"]);
64
+ * var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
65
+ * var signer = new Signer({ privateKey, provider });
66
+ * ```
44
67
  */
45
- export declare class Signer {
68
+ export declare class Signer implements SignerInterface {
46
69
  /**
47
70
  * Boolean determining if the public/private key
48
71
  * is using the compressed format
@@ -54,6 +77,14 @@ export declare class Signer {
54
77
  * Account address
55
78
  */
56
79
  address: string;
80
+ /**
81
+ * Provider to connect with the blockchain
82
+ */
83
+ provider?: Provider;
84
+ /**
85
+ * Serializer to serialize/deserialize data types
86
+ */
87
+ serializer?: Serializer;
57
88
  /**
58
89
  * The constructor receives de private key as hexstring, bigint or Uint8Array.
59
90
  * See also the functions [[Signer.fromWif]] and [[Signer.fromSeed]]
@@ -61,14 +92,27 @@ export declare class Signer {
61
92
  *
62
93
  * @param privateKey - Private key as hexstring, bigint or Uint8Array
63
94
  * @param compressed - compressed format is true by default
95
+ * @param provider - provider to connect with the blockchain
64
96
  * @example
65
97
  * ```ts
66
- * cons signer = new Signer("ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c");
98
+ * const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
99
+ * cons signer = new Signer({ privateKey });
67
100
  * console.log(signer.getAddress());
68
101
  * // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
69
102
  * ```
70
103
  */
71
- constructor(privateKey: string | number | bigint | Uint8Array, compressed?: boolean);
104
+ constructor(c: {
105
+ privateKey: string | number | bigint | Uint8Array;
106
+ compressed?: boolean;
107
+ provider?: Provider;
108
+ /**
109
+ * Set this option if you can not use _eval_ functions
110
+ * in the current environment. In such cases, the
111
+ * serializer must come from an environment where it
112
+ * is able to use those functions.
113
+ */
114
+ serializer?: Serializer;
115
+ });
72
116
  /**
73
117
  * Function to import a private key from the WIF
74
118
  * @param wif - Private key in WIF format
@@ -125,20 +169,128 @@ export declare class Signer {
125
169
  * @param tx - Unsigned transaction
126
170
  * @returns
127
171
  */
128
- signTransaction(tx: Transaction): Promise<Transaction>;
172
+ signTransaction(tx: TransactionJson): Promise<TransactionJson>;
173
+ /**
174
+ * Function to sign and send a transaction. It internally uses
175
+ * [[Provider.sendTransaction]]
176
+ * @param tx - Transaction to send. It will be signed inside this function
177
+ * if it is not signed yet
178
+ * @param _abis - Collection of Abis to parse the operations in the
179
+ * transaction. This parameter is optional.
180
+ * @returns
181
+ */
182
+ sendTransaction(tx: TransactionJson, _abis?: Record<string, Abi>): Promise<SendTransactionResponse>;
183
+ /**
184
+ * Function to recover the public key from a signed
185
+ * transaction or block.
186
+ * The output format can be compressed (default) or uncompressed.
187
+ *
188
+ * @example
189
+ * ```ts
190
+ * const publicKey = await Signer.recoverPublicKey(tx);
191
+ * ```
192
+ *
193
+ * If the signature data contains more data, like in the
194
+ * blocks for PoW consensus, use the "transformSignature"
195
+ * function to extract the signature.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * const powDescriptorJson = {
200
+ * nested: {
201
+ * mypackage: {
202
+ * nested: {
203
+ * pow_signature_data: {
204
+ * fields: {
205
+ * nonce: {
206
+ * type: "bytes",
207
+ * id: 1,
208
+ * },
209
+ * recoverable_signature: {
210
+ * type: "bytes",
211
+ * id: 2,
212
+ * },
213
+ * },
214
+ * },
215
+ * },
216
+ * },
217
+ * },
218
+ * };
219
+ *
220
+ * const serializer = new Serializer(powDescriptorJson, {
221
+ * defaultTypeName: "pow_signature_data",
222
+ * });
223
+ *
224
+ * const signer = await Signer.recoverPublicKey(block, {
225
+ * transformSignature: async (signatureData) => {
226
+ * const powSignatureData = await serializer.deserialize(signatureData);
227
+ * return powSignatureData.recoverable_signature;
228
+ * },
229
+ * });
230
+ * ```
231
+ */
232
+ static recoverPublicKey(txOrBlock: TransactionJson | BlockJson, opts?: RecoverPublicKeyOptions): Promise<string>;
233
+ /**
234
+ * Function to recover the signer address from a signed
235
+ * transaction or block.
236
+ * The output format can be compressed (default) or uncompressed.
237
+ * @example
238
+ * ```ts
239
+ * const publicKey = await Signer.recoverAddress(tx);
240
+ * ```
241
+ *
242
+ * If the signature data contains more data, like in the
243
+ * blocks for PoW consensus, use the "transformSignature"
244
+ * function to extract the signature.
245
+ *
246
+ * @example
247
+ * ```ts
248
+ * const powDescriptorJson = {
249
+ * nested: {
250
+ * mypackage: {
251
+ * nested: {
252
+ * pow_signature_data: {
253
+ * fields: {
254
+ * nonce: {
255
+ * type: "bytes",
256
+ * id: 1,
257
+ * },
258
+ * recoverable_signature: {
259
+ * type: "bytes",
260
+ * id: 2,
261
+ * },
262
+ * },
263
+ * },
264
+ * },
265
+ * },
266
+ * },
267
+ * };
268
+ *
269
+ * const serializer = new Serializer(powDescriptorJson, {
270
+ * defaultTypeName: "pow_signature_data",
271
+ * });
272
+ *
273
+ * const signer = await Signer.recoverAddress(block, {
274
+ * transformSignature: async (signatureData) => {
275
+ * const powSignatureData = await serializer.deserialize(signatureData);
276
+ * return powSignatureData.recoverable_signature;
277
+ * },
278
+ * });
279
+ * ```
280
+ */
281
+ static recoverAddress(txOrBlock: TransactionJson | BlockJson, opts?: RecoverPublicKeyOptions): Promise<string>;
129
282
  /**
130
- * Function to recover the public key from a signed transaction.
131
- * The output format can be compressed or uncompressed.
132
- * @param tx - signed transaction
133
- * @param compressed - output format (compressed by default)
283
+ * Function to encode a transaction
284
+ * @param activeData - Active data consists of nonce, rc_limit, and
285
+ * operations. Do not set the nonce to get it from the blockchain
286
+ * using the provider. The rc_limit is 1000000 by default.
287
+ * @returns A transaction encoded. The active field is encoded in
288
+ * base64url
134
289
  */
135
- static recoverPublicKey(tx: Transaction, compressed?: boolean): string;
290
+ encodeTransaction(activeData: ActiveTransactionData): Promise<TransactionJson>;
136
291
  /**
137
- * Function to recover the signer address from a signed transaction.
138
- * The output format can be compressed or uncompressed.
139
- * @param tx - signed transaction
140
- * @param compressed - output format (compressed by default)
292
+ * Function to decode a transaction
141
293
  */
142
- static recoverAddress(tx: Transaction, compressed?: boolean): string;
294
+ decodeTransaction(tx: TransactionJson): Promise<ActiveTransactionData>;
143
295
  }
144
296
  export default Signer;