koilib 5.6.0 → 5.7.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.
Files changed (63) hide show
  1. package/dist/koinos.js +5056 -4042
  2. package/dist/koinos.min.js +1 -1
  3. package/lib/Contract.d.ts +4 -4
  4. package/lib/Contract.js +4 -4
  5. package/lib/Contract.js.map +1 -1
  6. package/lib/Provider.d.ts +42 -12
  7. package/lib/Provider.js +99 -6
  8. package/lib/Provider.js.map +1 -1
  9. package/lib/Serializer.d.ts +20 -0
  10. package/lib/Serializer.js +4 -0
  11. package/lib/Serializer.js.map +1 -1
  12. package/lib/Signer.d.ts +0 -10
  13. package/lib/Signer.js +1 -123
  14. package/lib/Signer.js.map +1 -1
  15. package/lib/Transaction.d.ts +3 -3
  16. package/lib/Transaction.js +4 -4
  17. package/lib/Transaction.js.map +1 -1
  18. package/lib/browser/Contract.d.ts +4 -4
  19. package/lib/browser/Contract.js +4 -4
  20. package/lib/browser/Contract.js.map +1 -1
  21. package/lib/browser/Provider.d.ts +42 -12
  22. package/lib/browser/Provider.js +99 -6
  23. package/lib/browser/Provider.js.map +1 -1
  24. package/lib/browser/Serializer.d.ts +20 -0
  25. package/lib/browser/Serializer.js +4 -0
  26. package/lib/browser/Serializer.js.map +1 -1
  27. package/lib/browser/Signer.d.ts +0 -10
  28. package/lib/browser/Signer.js +1 -123
  29. package/lib/browser/Signer.js.map +1 -1
  30. package/lib/browser/Transaction.d.ts +3 -3
  31. package/lib/browser/Transaction.js +4 -4
  32. package/lib/browser/Transaction.js.map +1 -1
  33. package/lib/browser/index.d.ts +1 -1
  34. package/lib/browser/index.js +2 -2
  35. package/lib/browser/index.js.map +1 -1
  36. package/lib/browser/interface.d.ts +17 -2
  37. package/lib/browser/jsonDescriptors/chain-proto.json +74 -3
  38. package/lib/browser/jsonDescriptors/token-proto.json +5 -26
  39. package/lib/browser/protoModules/protocol-proto.js +823 -0
  40. package/lib/browser/protoModules/protocol-proto.js.map +1 -1
  41. package/lib/browser/utilsNode.d.ts +72 -117
  42. package/lib/index.d.ts +1 -1
  43. package/lib/index.js +2 -2
  44. package/lib/index.js.map +1 -1
  45. package/lib/interface.d.ts +17 -2
  46. package/lib/jsonDescriptors/chain-proto.json +74 -3
  47. package/lib/jsonDescriptors/token-proto.json +5 -26
  48. package/lib/protoModules/protocol-proto.js +823 -0
  49. package/lib/protoModules/protocol-proto.js.map +1 -1
  50. package/lib/utilsNode.d.ts +72 -117
  51. package/package.json +6 -6
  52. package/src/Contract.ts +6 -5
  53. package/src/Provider.ts +150 -20
  54. package/src/Serializer.ts +27 -0
  55. package/src/Signer.ts +1 -150
  56. package/src/Transaction.ts +8 -8
  57. package/src/index.ts +1 -1
  58. package/src/interface.ts +19 -2
  59. package/src/jsonDescriptors/chain-proto.json +74 -3
  60. package/src/jsonDescriptors/pow-proto.json +1 -1
  61. package/src/jsonDescriptors/token-proto.json +5 -26
  62. package/src/jsonDescriptors/value-proto.json +13 -23
  63. package/src/protoModules/protocol-proto.js +1043 -4
package/src/Signer.ts CHANGED
@@ -30,12 +30,10 @@ import { koinos } from "./protoModules/protocol-proto.js";
30
30
  export interface SignerInterface {
31
31
  provider?: Provider;
32
32
  getAddress: (compressed?: boolean) => string;
33
- getPrivateKey: (format: "wif" | "hex", compressed?: boolean) => string;
34
33
  signHash: (hash: Uint8Array) => Promise<Uint8Array>;
35
34
  signMessage: (message: string | Uint8Array) => Promise<Uint8Array>;
36
35
 
37
36
  // Transaction
38
- prepareTransaction: (tx: TransactionJson) => Promise<TransactionJson>;
39
37
  signTransaction: (
40
38
  transaction: TransactionJson | TransactionJsonWait,
41
39
  abis?: Record<string, Abi>
@@ -71,54 +69,6 @@ const btypeTransactionHeader: TypeField["subtypes"] = {
71
69
  payee: { type: "bytes", btype: "ADDRESS" },
72
70
  };
73
71
 
74
- const btypesOperation: TypeField["subtypes"] = {
75
- upload_contract: {
76
- type: "object",
77
- subtypes: {
78
- contract_id: { type: "bytes", btype: "CONTRACT_ID" },
79
- bytecode: { type: "bytes" },
80
- abi: { type: "string" },
81
- authorizes_call_contract: { type: "bool" },
82
- authorizes_transaction_application: { type: "bool" },
83
- authorizes_upload_contract: { type: "bool" },
84
- },
85
- },
86
- call_contract: {
87
- type: "object",
88
- subtypes: {
89
- contract_id: { type: "bytes", btype: "CONTRACT_ID" },
90
- entry_point: { type: "uint32" },
91
- args: { type: "bytes" },
92
- },
93
- },
94
- set_system_call: {
95
- type: "object",
96
- subtypes: {
97
- call_id: { type: "uint32" },
98
- target: {
99
- type: "object",
100
- subtypes: {
101
- thunk_id: { type: "uint32" },
102
- system_call_bundle: {
103
- type: "object",
104
- subtypes: {
105
- contract_id: { type: "bytes", btype: "CONTRACT_ID" },
106
- entry_point: { type: "uint32" },
107
- },
108
- },
109
- },
110
- },
111
- },
112
- },
113
- set_system_contract: {
114
- type: "object",
115
- subtypes: {
116
- contract_id: { type: "bytes", btype: "CONTRACT_ID" },
117
- system_contract: { type: "bool" },
118
- },
119
- },
120
- };
121
-
122
72
  /**
123
73
  * The Signer Class contains the private key needed to sign transactions.
124
74
  * It can be created using the seed, wif, or private key
@@ -315,7 +265,7 @@ export class Signer implements SignerInterface {
315
265
  * // 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
316
266
  * ```
317
267
  */
318
- getPrivateKey(format: "wif" | "hex" = "hex", compressed = false): string {
268
+ getPrivateKey(format: "wif" | "hex" = "hex", compressed = true): string {
319
269
  let stringPrivateKey: string;
320
270
  if (this.privateKey instanceof Uint8Array) {
321
271
  stringPrivateKey = toHexString(this.privateKey);
@@ -637,105 +587,6 @@ export class Signer implements SignerInterface {
637
587
  );
638
588
  }
639
589
 
640
- /**
641
- * Function to prepare a transaction
642
- * @deprecated - Use [[Transaction.prepareTransaction]] instead.
643
- * @param tx - Do not set the nonce to get it from the blockchain
644
- * using the provider. The rc_limit is 1e8 by default.
645
- * @returns A prepared transaction.
646
- */
647
- async prepareTransaction(tx: TransactionJson): Promise<TransactionJson> {
648
- if (!tx.header) {
649
- tx.header = {};
650
- }
651
-
652
- const payer = tx.header.payer ?? this.address;
653
- const { payee } = tx.header;
654
-
655
- let nonce;
656
- if (tx.header.nonce === undefined) {
657
- if (!this.provider)
658
- throw new Error(
659
- "Cannot get the nonce because provider is undefined. To skip this call set a nonce in the transaction header"
660
- );
661
- nonce = await this.provider.getNextNonce(payee || payer);
662
- } else {
663
- nonce = tx.header.nonce;
664
- }
665
-
666
- let rcLimit;
667
- if (tx.header.rc_limit === undefined) {
668
- if (!this.provider)
669
- throw new Error(
670
- "Cannot get the rc_limit because provider is undefined. To skip this call set a rc_limit in the transaction header"
671
- );
672
- rcLimit = await this.provider.getAccountRc(payer);
673
- } else {
674
- rcLimit = tx.header.rc_limit;
675
- }
676
-
677
- let chainId = tx.header.chain_id || this.chainId;
678
- if (!chainId) {
679
- if (!this.provider)
680
- throw new Error(
681
- "Cannot get the chain_id because provider is undefined. To skip this call set a chain_id in the Signer"
682
- );
683
- chainId = await this.provider.getChainId();
684
- this.chainId = chainId;
685
- }
686
-
687
- const operationsHashes: Uint8Array[] = [];
688
-
689
- if (tx.operations) {
690
- for (let index = 0; index < tx.operations?.length; index += 1) {
691
- const operationDecoded = btypeDecode(
692
- tx.operations[index],
693
- btypesOperation!,
694
- false
695
- );
696
- const message = koinos.protocol.operation.create(operationDecoded);
697
- const operationEncoded = koinos.protocol.operation
698
- .encode(message)
699
- .finish() as Uint8Array;
700
- operationsHashes.push(sha256(operationEncoded));
701
- }
702
- }
703
- const operationMerkleRoot = encodeBase64url(
704
- new Uint8Array([
705
- // multihash sha256: 18, 32
706
- 18,
707
- 32,
708
- ...calculateMerkleRoot(operationsHashes),
709
- ])
710
- );
711
-
712
- tx.header = {
713
- chain_id: chainId,
714
- rc_limit: rcLimit,
715
- nonce,
716
- operation_merkle_root: operationMerkleRoot,
717
- payer,
718
- ...(payee && { payee }),
719
- // TODO: Option to resolve names (payer, payee)
720
- };
721
-
722
- const headerDecoded = btypeDecode(
723
- tx.header,
724
- btypeTransactionHeader!,
725
- false
726
- );
727
- const message = koinos.protocol.transaction_header.create(headerDecoded);
728
- const headerBytes = koinos.protocol.transaction_header
729
- .encode(message)
730
- .finish() as Uint8Array;
731
-
732
- const hash = sha256(headerBytes);
733
-
734
- // multihash 0x1220. 12: code sha2-256. 20: length (32 bytes)
735
- tx.id = `0x1220${toHexString(hash)}`;
736
- return tx;
737
- }
738
-
739
590
  /**
740
591
  * Function to prepare a block
741
592
  * @param block -
@@ -2,7 +2,7 @@
2
2
  import { sha256 } from "@noble/hashes/sha256";
3
3
  import { Contract } from "./Contract";
4
4
  import { Provider } from "./Provider";
5
- import { Signer } from "./Signer";
5
+ import { SignerInterface } from "./Signer";
6
6
  import {
7
7
  Abi,
8
8
  OperationJson,
@@ -84,7 +84,7 @@ export class Transaction {
84
84
  /**
85
85
  * Signer interacting with the smart contracts
86
86
  */
87
- signer?: Signer;
87
+ signer?: SignerInterface;
88
88
 
89
89
  /**
90
90
  * Provider to connect with the blockchain
@@ -107,7 +107,7 @@ export class Transaction {
107
107
  options: TransactionOptions;
108
108
 
109
109
  constructor(c?: {
110
- signer?: Signer;
110
+ signer?: SignerInterface;
111
111
  provider?: Provider;
112
112
  options?: TransactionOptions;
113
113
  }) {
@@ -249,7 +249,7 @@ export class Transaction {
249
249
  nonce = tx.header.nonce;
250
250
  }
251
251
 
252
- let rcLimit: string;
252
+ let rcLimit: string | number;
253
253
  if (tx.header.rc_limit === undefined) {
254
254
  if (!provider)
255
255
  throw new Error(
@@ -368,7 +368,10 @@ export class Transaction {
368
368
  };
369
369
  if (!this.transaction.id) await this.prepare();
370
370
 
371
- if (this.signer && this.signer.provider) {
371
+ if (!this.transaction.signatures || !this.transaction.signatures.length) {
372
+ if (!this.signer) {
373
+ throw new Error("transaction without signatures and no signer defined");
374
+ }
372
375
  const { transaction: tx, receipt } = await this.signer.sendTransaction(
373
376
  this.transaction,
374
377
  opts
@@ -379,9 +382,6 @@ export class Transaction {
379
382
  }
380
383
 
381
384
  if (!this.provider) throw new Error("provider not defined");
382
- if (!this.transaction.signatures || !this.transaction.signatures.length) {
383
- throw new Error("transaction without signatures and no signer defined");
384
- }
385
385
 
386
386
  if (opts.beforeSend) {
387
387
  await opts.beforeSend(this.transaction, opts);
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /*! koilib - MIT License (c) Julian Gonzalez (joticajulian@gmail.com) */
2
2
  // eslint-disable import/no-cycle
3
3
  export * as utils from "./indexUtils";
4
- export * as interfaces from "./interface";
4
+ export * from "./interface";
5
5
  export * from "./Contract";
6
6
  export * from "./Signer";
7
7
  export * from "./Provider";
package/src/interface.ts CHANGED
@@ -308,7 +308,7 @@ export interface TransactionOptions extends SendTransactionOptions {
308
308
  * is not set it will be taken by querying the
309
309
  * actual mana of the payer
310
310
  */
311
- rcLimit?: string;
311
+ rcLimit?: string | number;
312
312
 
313
313
  /**
314
314
  * Transaction nonce
@@ -662,7 +662,7 @@ export interface TransactionHeaderJson {
662
662
  /**
663
663
  * Resource credits limit
664
664
  */
665
- rc_limit?: string;
665
+ rc_limit?: string | number;
666
666
 
667
667
  /**
668
668
  * Account nonce
@@ -735,6 +735,12 @@ export interface BlockJson {
735
735
  [x: string]: unknown;
736
736
  }
737
737
 
738
+ export interface BlockTopology {
739
+ id: string;
740
+ height: string;
741
+ previous: string;
742
+ }
743
+
738
744
  export interface ValueType {
739
745
  uint64_value?: string;
740
746
  [x: string]: unknown;
@@ -752,6 +758,16 @@ export interface DecodedEventData extends EventData {
752
758
  args: Record<string, unknown>;
753
759
  }
754
760
 
761
+ export interface StateDeltaEntry {
762
+ object_space: {
763
+ system: boolean;
764
+ zone: string;
765
+ id: number;
766
+ };
767
+ key: string;
768
+ value: string;
769
+ }
770
+
755
771
  export interface TransactionReceipt {
756
772
  id: string;
757
773
  payer: string;
@@ -763,5 +779,6 @@ export interface TransactionReceipt {
763
779
  compute_bandwidth_used: string;
764
780
  reverted: boolean;
765
781
  events: EventData[];
782
+ state_delta_entries: StateDeltaEntry[];
766
783
  logs: string[];
767
784
  }
@@ -2,7 +2,7 @@
2
2
  "nested": {
3
3
  "koinos": {
4
4
  "options": {
5
- "go_package": "github.com/koinos/koinos-proto-golang/koinos"
5
+ "go_package": "github.com/koinos/koinos-proto-golang/v2/koinos"
6
6
  },
7
7
  "nested": {
8
8
  "block_topology": {
@@ -32,9 +32,25 @@
32
32
  },
33
33
  "protocol": {
34
34
  "options": {
35
- "go_package": "github.com/koinos/koinos-proto-golang/koinos/protocol"
35
+ "go_package": "github.com/koinos/koinos-proto-golang/v2/koinos/protocol"
36
36
  },
37
37
  "nested": {
38
+ "object_space": {
39
+ "fields": {
40
+ "system": {
41
+ "type": "bool",
42
+ "id": 1
43
+ },
44
+ "zone": {
45
+ "type": "bytes",
46
+ "id": 2
47
+ },
48
+ "id": {
49
+ "type": "uint32",
50
+ "id": 3
51
+ }
52
+ }
53
+ },
38
54
  "event_data": {
39
55
  "fields": {
40
56
  "sequence": {
@@ -338,6 +354,11 @@
338
354
  "rule": "repeated",
339
355
  "type": "string",
340
356
  "id": 11
357
+ },
358
+ "state_delta_entries": {
359
+ "rule": "repeated",
360
+ "type": "state_delta_entry",
361
+ "id": 12
341
362
  }
342
363
  }
343
364
  },
@@ -468,6 +489,56 @@
468
489
  "rule": "repeated",
469
490
  "type": "string",
470
491
  "id": 9
492
+ },
493
+ "disk_storage_charged": {
494
+ "type": "uint64",
495
+ "id": 10,
496
+ "options": {
497
+ "jstype": "JS_STRING"
498
+ }
499
+ },
500
+ "network_bandwidth_charged": {
501
+ "type": "uint64",
502
+ "id": 11,
503
+ "options": {
504
+ "jstype": "JS_STRING"
505
+ }
506
+ },
507
+ "compute_bandwidth_charged": {
508
+ "type": "uint64",
509
+ "id": 12,
510
+ "options": {
511
+ "jstype": "JS_STRING"
512
+ }
513
+ },
514
+ "state_delta_entries": {
515
+ "rule": "repeated",
516
+ "type": "state_delta_entry",
517
+ "id": 13
518
+ }
519
+ }
520
+ },
521
+ "state_delta_entry": {
522
+ "oneofs": {
523
+ "_value": {
524
+ "oneof": ["value"]
525
+ }
526
+ },
527
+ "fields": {
528
+ "object_space": {
529
+ "type": "object_space",
530
+ "id": 1
531
+ },
532
+ "key": {
533
+ "type": "bytes",
534
+ "id": 2
535
+ },
536
+ "value": {
537
+ "type": "bytes",
538
+ "id": 3,
539
+ "options": {
540
+ "proto3_optional": true
541
+ }
471
542
  }
472
543
  }
473
544
  }
@@ -475,7 +546,7 @@
475
546
  },
476
547
  "chain": {
477
548
  "options": {
478
- "go_package": "github.com/koinos/koinos-proto-golang/koinos/chain"
549
+ "go_package": "github.com/koinos/koinos-proto-golang/v2/koinos/chain"
479
550
  },
480
551
  "nested": {
481
552
  "error_data": {
@@ -6,7 +6,7 @@
6
6
  "nested": {
7
7
  "pow": {
8
8
  "options": {
9
- "go_package": "github.com/koinos/koinos-proto-golang/koinos/contracts/pow"
9
+ "go_package": "github.com/koinos/koinos-proto-golang/v2/koinos/contracts/pow"
10
10
  },
11
11
  "nested": {
12
12
  "difficulty_metadata": {
@@ -6,7 +6,7 @@
6
6
  "nested": {
7
7
  "token": {
8
8
  "options": {
9
- "go_package": "github.com/koinos/koinos-proto-golang/koinos/contracts/token"
9
+ "go_package": "github.com/koinos/koinos-proto-golang/v2/koinos/contracts/token"
10
10
  },
11
11
  "nested": {
12
12
  "name_arguments": {
@@ -100,6 +100,10 @@
100
100
  "options": {
101
101
  "jstype": "JS_STRING"
102
102
  }
103
+ },
104
+ "memo": {
105
+ "type": "string",
106
+ "id": 4
103
107
  }
104
108
  }
105
109
  },
@@ -159,31 +163,6 @@
159
163
  }
160
164
  }
161
165
  },
162
- "mana_balance_object": {
163
- "fields": {
164
- "balance": {
165
- "type": "uint64",
166
- "id": 1,
167
- "options": {
168
- "jstype": "JS_STRING"
169
- }
170
- },
171
- "mana": {
172
- "type": "uint64",
173
- "id": 2,
174
- "options": {
175
- "jstype": "JS_STRING"
176
- }
177
- },
178
- "last_mana_update": {
179
- "type": "uint64",
180
- "id": 3,
181
- "options": {
182
- "jstype": "JS_STRING"
183
- }
184
- }
185
- }
186
- },
187
166
  "burn_event": {
188
167
  "fields": {
189
168
  "from": {
@@ -12,8 +12,6 @@
12
12
  "kind": {
13
13
  "oneof": [
14
14
  "message_value",
15
- "double_value",
16
- "float_value",
17
15
  "int32_value",
18
16
  "int64_value",
19
17
  "uint32_value",
@@ -35,80 +33,72 @@
35
33
  "type": "google.protobuf.Any",
36
34
  "id": 1
37
35
  },
38
- "double_value": {
39
- "type": "double",
40
- "id": 2
41
- },
42
- "float_value": {
43
- "type": "float",
44
- "id": 3
45
- },
46
36
  "int32_value": {
47
37
  "type": "int32",
48
- "id": 4
38
+ "id": 2
49
39
  },
50
40
  "int64_value": {
51
41
  "type": "int64",
52
- "id": 5,
42
+ "id": 3,
53
43
  "options": {
54
44
  "jstype": "JS_STRING"
55
45
  }
56
46
  },
57
47
  "uint32_value": {
58
48
  "type": "uint32",
59
- "id": 6
49
+ "id": 4
60
50
  },
61
51
  "uint64_value": {
62
52
  "type": "uint64",
63
- "id": 7,
53
+ "id": 5,
64
54
  "options": {
65
55
  "jstype": "JS_STRING"
66
56
  }
67
57
  },
68
58
  "sint32_value": {
69
59
  "type": "sint32",
70
- "id": 8
60
+ "id": 6
71
61
  },
72
62
  "sint64_value": {
73
63
  "type": "sint64",
74
- "id": 9,
64
+ "id": 7,
75
65
  "options": {
76
66
  "jstype": "JS_STRING"
77
67
  }
78
68
  },
79
69
  "fixed32_value": {
80
70
  "type": "fixed32",
81
- "id": 10
71
+ "id": 8
82
72
  },
83
73
  "fixed64_value": {
84
74
  "type": "fixed64",
85
- "id": 11,
75
+ "id": 9,
86
76
  "options": {
87
77
  "jstype": "JS_STRING"
88
78
  }
89
79
  },
90
80
  "sfixed32_value": {
91
81
  "type": "sfixed32",
92
- "id": 12
82
+ "id": 10
93
83
  },
94
84
  "sfixed64_value": {
95
85
  "type": "sfixed64",
96
- "id": 13,
86
+ "id": 11,
97
87
  "options": {
98
88
  "jstype": "JS_STRING"
99
89
  }
100
90
  },
101
91
  "bool_value": {
102
92
  "type": "bool",
103
- "id": 14
93
+ "id": 12
104
94
  },
105
95
  "string_value": {
106
96
  "type": "string",
107
- "id": 15
97
+ "id": 13
108
98
  },
109
99
  "bytes_value": {
110
100
  "type": "bytes",
111
- "id": 16
101
+ "id": 14
112
102
  }
113
103
  }
114
104
  },