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
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import { Provider } from "./Provider";
|
|
2
|
+
import { TransactionJson, TransactionJsonWait, ActiveTransactionData, Abi, 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<TransactionJsonWait>;
|
|
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 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>;
|
|
173
|
+
/**
|
|
174
|
+
* Function to sign a transaction. It's important to remark that
|
|
175
|
+
* the transaction parameter is modified inside this function.
|
|
176
|
+
* @param tx - Unsigned transaction
|
|
177
|
+
*/
|
|
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>;
|
|
187
|
+
/**
|
|
188
|
+
* Function to sign and send a transaction. It internally uses
|
|
189
|
+
* [[Provider.sendTransaction]]
|
|
190
|
+
* @param tx - Transaction to send. It will be signed inside this function
|
|
191
|
+
* if it is not signed yet
|
|
192
|
+
* @param _abis - Collection of Abis to parse the operations in the
|
|
193
|
+
* transaction. This parameter is optional.
|
|
194
|
+
* @returns
|
|
195
|
+
*/
|
|
196
|
+
sendTransaction(tx: TransactionJson, _abis?: Record<string, Abi>): Promise<TransactionJsonWait>;
|
|
197
|
+
/**
|
|
198
|
+
* Function to recover the public key from a signed
|
|
199
|
+
* transaction or block.
|
|
200
|
+
* The output format can be compressed (default) or uncompressed.
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```ts
|
|
204
|
+
* const publicKey = await Signer.recoverPublicKey(tx);
|
|
205
|
+
* ```
|
|
206
|
+
*
|
|
207
|
+
* If the signature data contains more data, like in the
|
|
208
|
+
* blocks for PoW consensus, use the "transformSignature"
|
|
209
|
+
* function to extract the signature.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* ```ts
|
|
213
|
+
* const powDescriptorJson = {
|
|
214
|
+
* nested: {
|
|
215
|
+
* mypackage: {
|
|
216
|
+
* nested: {
|
|
217
|
+
* pow_signature_data: {
|
|
218
|
+
* fields: {
|
|
219
|
+
* nonce: {
|
|
220
|
+
* type: "bytes",
|
|
221
|
+
* id: 1,
|
|
222
|
+
* },
|
|
223
|
+
* recoverable_signature: {
|
|
224
|
+
* type: "bytes",
|
|
225
|
+
* id: 2,
|
|
226
|
+
* },
|
|
227
|
+
* },
|
|
228
|
+
* },
|
|
229
|
+
* },
|
|
230
|
+
* },
|
|
231
|
+
* },
|
|
232
|
+
* };
|
|
233
|
+
*
|
|
234
|
+
* const serializer = new Serializer(powDescriptorJson, {
|
|
235
|
+
* defaultTypeName: "pow_signature_data",
|
|
236
|
+
* });
|
|
237
|
+
*
|
|
238
|
+
* const signer = await signer.recoverPublicKey(block, {
|
|
239
|
+
* transformSignature: async (signatureData) => {
|
|
240
|
+
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
241
|
+
* return powSignatureData.recoverable_signature;
|
|
242
|
+
* },
|
|
243
|
+
* });
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
recoverPublicKey(txOrBlock: TransactionJson | BlockJson, opts?: RecoverPublicKeyOptions): Promise<string>;
|
|
247
|
+
/**
|
|
248
|
+
* Function to recover the signer address from a signed
|
|
249
|
+
* transaction or block.
|
|
250
|
+
* The output format can be compressed (default) or uncompressed.
|
|
251
|
+
* @example
|
|
252
|
+
* ```ts
|
|
253
|
+
* const publicKey = await signer.recoverAddress(tx);
|
|
254
|
+
* ```
|
|
255
|
+
*
|
|
256
|
+
* If the signature data contains more data, like in the
|
|
257
|
+
* blocks for PoW consensus, use the "transformSignature"
|
|
258
|
+
* function to extract the signature.
|
|
259
|
+
*
|
|
260
|
+
* @example
|
|
261
|
+
* ```ts
|
|
262
|
+
* const powDescriptorJson = {
|
|
263
|
+
* nested: {
|
|
264
|
+
* mypackage: {
|
|
265
|
+
* nested: {
|
|
266
|
+
* pow_signature_data: {
|
|
267
|
+
* fields: {
|
|
268
|
+
* nonce: {
|
|
269
|
+
* type: "bytes",
|
|
270
|
+
* id: 1,
|
|
271
|
+
* },
|
|
272
|
+
* recoverable_signature: {
|
|
273
|
+
* type: "bytes",
|
|
274
|
+
* id: 2,
|
|
275
|
+
* },
|
|
276
|
+
* },
|
|
277
|
+
* },
|
|
278
|
+
* },
|
|
279
|
+
* },
|
|
280
|
+
* },
|
|
281
|
+
* };
|
|
282
|
+
*
|
|
283
|
+
* const serializer = new Serializer(powDescriptorJson, {
|
|
284
|
+
* defaultTypeName: "pow_signature_data",
|
|
285
|
+
* });
|
|
286
|
+
*
|
|
287
|
+
* const signer = await signer.recoverAddress(block, {
|
|
288
|
+
* transformSignature: async (signatureData) => {
|
|
289
|
+
* const powSignatureData = await serializer.deserialize(signatureData);
|
|
290
|
+
* return powSignatureData.recoverable_signature;
|
|
291
|
+
* },
|
|
292
|
+
* });
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
295
|
+
recoverAddress(txOrBlock: TransactionJson | BlockJson, opts?: RecoverPublicKeyOptions): Promise<string>;
|
|
296
|
+
/**
|
|
297
|
+
* Function to encode a transaction
|
|
298
|
+
* @param activeData - Active data consists of nonce, rc_limit, and
|
|
299
|
+
* operations. Do not set the nonce to get it from the blockchain
|
|
300
|
+
* using the provider. The rc_limit is 1e8 by default.
|
|
301
|
+
* @returns A transaction encoded. The active field is encoded in
|
|
302
|
+
* base64url
|
|
303
|
+
*/
|
|
304
|
+
encodeTransaction(activeData: ActiveTransactionData): Promise<TransactionJson>;
|
|
305
|
+
/**
|
|
306
|
+
* Function to decode a transaction
|
|
307
|
+
*/
|
|
308
|
+
decodeTransaction(tx: TransactionJson): Promise<ActiveTransactionData>;
|
|
309
|
+
}
|
|
310
|
+
export default Signer;
|