koilib 2.4.1 → 2.6.1

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.
Files changed (45) hide show
  1. package/README.md +4 -4
  2. package/dist/koinos.js +2977 -4588
  3. package/dist/koinos.min.js +1 -1
  4. package/dist/koinos.min.js.LICENSE.txt +2 -2
  5. package/lib/Contract.js +8 -8
  6. package/lib/Contract.js.map +1 -1
  7. package/lib/Provider.d.ts +6 -4
  8. package/lib/Provider.js +59 -47
  9. package/lib/Provider.js.map +1 -1
  10. package/lib/Serializer.js +9 -9
  11. package/lib/Serializer.js.map +1 -1
  12. package/lib/Signer.d.ts +6 -6
  13. package/lib/Signer.js +19 -19
  14. package/lib/Signer.js.map +1 -1
  15. package/lib/browser/Contract.d.ts +202 -0
  16. package/lib/browser/Contract.js +298 -0
  17. package/lib/browser/Contract.js.map +1 -0
  18. package/lib/browser/Provider.d.ts +153 -0
  19. package/lib/browser/Provider.js +244 -0
  20. package/lib/browser/Provider.js.map +1 -0
  21. package/lib/browser/Serializer.d.ts +81 -0
  22. package/lib/browser/Serializer.js +169 -0
  23. package/lib/browser/Serializer.js.map +1 -0
  24. package/lib/browser/Signer.d.ts +296 -0
  25. package/lib/browser/Signer.js +421 -0
  26. package/lib/browser/Signer.js.map +1 -0
  27. package/lib/browser/index.d.ts +7 -0
  28. package/lib/browser/index.js +34 -0
  29. package/lib/browser/index.js.map +1 -0
  30. package/lib/browser/index2.d.ts +2 -0
  31. package/lib/browser/index2.js +33 -0
  32. package/lib/browser/index2.js.map +1 -0
  33. package/lib/browser/interface.d.ts +278 -0
  34. package/lib/browser/interface.js +3 -0
  35. package/lib/browser/interface.js.map +1 -0
  36. package/lib/browser/jsonDescriptors/krc20-proto.json +183 -0
  37. package/lib/browser/jsonDescriptors/protocol-proto.json +246 -0
  38. package/lib/browser/utils.d.ts +326 -0
  39. package/lib/browser/utils.js +252 -0
  40. package/lib/browser/utils.js.map +1 -0
  41. package/lib/interface.d.ts +21 -5
  42. package/lib/utils.d.ts +12 -8
  43. package/lib/utils.js +7 -7
  44. package/lib/utils.js.map +1 -1
  45. package/package.json +34 -31
@@ -0,0 +1,296 @@
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
+ }
14
+ /**
15
+ * The Signer Class contains the private key needed to sign transactions.
16
+ * It can be created using the seed, wif, or private key
17
+ *
18
+ * @example
19
+ * using private key as hex string
20
+ * ```ts
21
+ * var privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
22
+ * var signer = new Signer({ privateKey });
23
+ * ```
24
+ * <br>
25
+ *
26
+ * using private key as Uint8Array
27
+ * ```ts
28
+ * var buffer = new Uint8Array([
29
+ * 236, 134, 1, 162, 79, 129, 222, 205,
30
+ * 87, 244, 182, 17, 181, 172, 110, 184,
31
+ * 1, 203, 55, 128, 187, 2, 192, 249,
32
+ * 205, 254, 157, 9, 218, 173, 223, 156
33
+ * ]);
34
+ * var signer = new Signer({ privateKey: buffer });
35
+ * ```
36
+ *
37
+ * <br>
38
+ *
39
+ * using private key as bigint
40
+ * ```ts
41
+ * var privateKey = 106982601049961974618234078204952280507266494766432547312316920283818886029212n;
42
+ * var signer = new Signer({ privateKey });
43
+ * ```
44
+ *
45
+ * <br>
46
+ *
47
+ * using the seed
48
+ * ```ts
49
+ * var signer = Signer.fromSeed("my seed");
50
+ * ```
51
+ *
52
+ * <br>
53
+ *
54
+ * using private key in WIF format
55
+ * ```ts
56
+ * var signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM");
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
+ * ```
67
+ */
68
+ export declare class Signer implements SignerInterface {
69
+ /**
70
+ * Boolean determining if the public/private key
71
+ * is using the compressed format
72
+ */
73
+ compressed: boolean;
74
+ private privateKey;
75
+ publicKey: string | Uint8Array;
76
+ /**
77
+ * Account address
78
+ */
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;
88
+ /**
89
+ * The constructor receives de private key as hexstring, bigint or Uint8Array.
90
+ * See also the functions [[Signer.fromWif]] and [[Signer.fromSeed]]
91
+ * to create the signer from the WIF or Seed respectively.
92
+ *
93
+ * @param privateKey - Private key as hexstring, bigint or Uint8Array
94
+ * @param compressed - compressed format is true by default
95
+ * @param provider - provider to connect with the blockchain
96
+ * @example
97
+ * ```ts
98
+ * const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
99
+ * cons signer = new Signer({ privateKey });
100
+ * console.log(signer.getAddress());
101
+ * // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
102
+ * ```
103
+ */
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
+ });
116
+ /**
117
+ * Function to import a private key from the WIF
118
+ * @param wif - Private key in WIF format
119
+ * @example
120
+ * ```ts
121
+ * const signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM")
122
+ * console.log(signer.getAddress());
123
+ * // 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
124
+ * ```
125
+ * @returns Signer object
126
+ */
127
+ static fromWif(wif: string): Signer;
128
+ /**
129
+ * Function to import a private key from the seed
130
+ * @param seed - Seed words
131
+ * @param compressed -
132
+ * @example
133
+ * ```ts
134
+ * const signer = Signer.fromSeed("my seed");
135
+ * console.log(signer.getAddress());
136
+ * // 1BqtgWBcqm9cSZ97avLGZGJdgso7wx6pCA
137
+ * ```
138
+ * @returns Signer object
139
+ */
140
+ static fromSeed(seed: string, compressed?: boolean): Signer;
141
+ /**
142
+ * @param compressed - determines if the address should be
143
+ * derived from the compressed public key (default) or the public key
144
+ * @returns Signer address
145
+ */
146
+ getAddress(compressed?: boolean): string;
147
+ /**
148
+ * Function to get the private key in hex format or wif format
149
+ * @param format - The format must be "hex" (default) or "wif"
150
+ * @param compressed - Optional arg when using WIF format. By default it
151
+ * uses the compressed value defined in the signer
152
+ * @example
153
+ * ```ts
154
+ * const signer = Signer.fromSeed("one two three four five six");
155
+ * console.log(signer.getPrivateKey());
156
+ * // bab7fd6e5bd624f4ea0c33f7e7219262a6fa93a945a8964d9f110148286b7b37
157
+ *
158
+ * console.log(signer.getPrivateKey("wif"));
159
+ * // L3UfgFJWmbVziGB1uZBjkG1UjKkF7hhpXWY7mbTUdmycmvXCVtiL
160
+ *
161
+ * console.log(signer.getPrivateKey("wif", false));
162
+ * // 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
163
+ * ```
164
+ */
165
+ getPrivateKey(format?: "wif" | "hex", compressed?: boolean): string;
166
+ /**
167
+ * Function to sign a transaction. It's important to remark that
168
+ * the transaction parameter is modified inside this function.
169
+ * @param tx - Unsigned transaction
170
+ * @returns
171
+ */
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>;
282
+ /**
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
289
+ */
290
+ encodeTransaction(activeData: ActiveTransactionData): Promise<TransactionJson>;
291
+ /**
292
+ * Function to decode a transaction
293
+ */
294
+ decodeTransaction(tx: TransactionJson): Promise<ActiveTransactionData>;
295
+ }
296
+ export default Signer;