@leofcoin/lib 1.2.11 → 1.2.12

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/exports/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ContractMessage, TransactionMessage } from '@leofcoin/messages';
2
+ import { CodecHash } from '@leofcoin/codec-format-interface';
2
3
  import { validators as validators$1 } from '@leofcoin/addresses';
3
4
  export { default as nodeConfig } from './node-config.js';
4
5
 
@@ -56,6 +57,12 @@ const calculateReward = (validators, fees) => {
56
57
  return set;
57
58
  }, []);
58
59
  return validators;
60
+ };
61
+ const createTransactionHash = async (transaction) => (await new CodecHash(transaction, { name: 'transaction-message' })).digest;
62
+ const signTransaction = async (wallet, transaction) => {
63
+ const signature = await wallet.sign(transaction);
64
+ const signedTransaction = { ...transaction, signature };
65
+ return signedTransaction;
59
66
  };
60
67
 
61
- export { calculateFee, calculateReward, calculateTransactionFee, contractFactoryMessage, createContractMessage, nameServiceMessage, nativeTokenMessage, validatorsMessage };
68
+ export { calculateFee, calculateReward, calculateTransactionFee, contractFactoryMessage, createContractMessage, createTransactionHash, nameServiceMessage, nativeTokenMessage, signTransaction, validatorsMessage };
@@ -1,5 +1,23 @@
1
1
  import { ContractMessage } from '@leofcoin/messages';
2
2
  export { default as nodeConfig } from './node-config.js';
3
+ declare type address = string;
4
+ declare type transaction = {
5
+ from: address;
6
+ to: address;
7
+ method: string;
8
+ parameters: [];
9
+ timestamp: Number;
10
+ };
11
+ declare type signedTransaction = {
12
+ from: address;
13
+ to: address;
14
+ method: string;
15
+ parameters: [];
16
+ timestamp: Number;
17
+ };
18
+ declare type signable = {
19
+ sign: (transaction: any) => Uint8Array;
20
+ };
3
21
  export declare const contractFactoryMessage: string;
4
22
  export declare const nativeTokenMessage: string;
5
23
  export declare const nameServiceMessage: string;
@@ -8,3 +26,5 @@ export declare const createContractMessage: (creator: any, contract: any, constr
8
26
  export declare const calculateFee: (transaction: any) => Promise<string | 0>;
9
27
  export declare const calculateTransactionFee: (transaction: any) => Promise<string | 0>;
10
28
  export declare const calculateReward: (validators: any, fees: any) => [];
29
+ export declare const createTransactionHash: (transaction: any) => Promise<any>;
30
+ export declare const signTransaction: (wallet: signable, transaction: transaction) => Promise<signedTransaction>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/lib",
3
- "version": "1.2.11",
3
+ "version": "1.2.12",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "typings": "./exports/typings/index.d.ts",
package/src/index.ts CHANGED
@@ -1,8 +1,31 @@
1
1
  import bytecodes from './bytecodes.json' assert {type: 'json'}
2
2
  import { ContractMessage, TransactionMessage } from '@leofcoin/messages'
3
+ import { CodecHash } from '@leofcoin/codec-format-interface'
3
4
  import { validators } from '@leofcoin/addresses'
4
5
  export { default as nodeConfig} from './node-config.js'
5
6
 
7
+ declare type address = string
8
+
9
+ declare type transaction = {
10
+ from: address,
11
+ to: address,
12
+ method: string,
13
+ parameters: [],
14
+ timestamp: Number
15
+ }
16
+
17
+ declare type signedTransaction = {
18
+ from: address,
19
+ to: address,
20
+ method: string,
21
+ parameters: [],
22
+ timestamp: Number
23
+ }
24
+
25
+ declare type signable = {
26
+ sign: (transaction) => Uint8Array
27
+ }
28
+
6
29
  export const contractFactoryMessage = bytecodes.contractFactory
7
30
  export const nativeTokenMessage = bytecodes.nativeToken
8
31
 
@@ -53,3 +76,13 @@ export const calculateReward = (validators, fees): [] => {
53
76
 
54
77
  return validators
55
78
  }
79
+
80
+ export const createTransactionHash = async (transaction) =>
81
+ (await new CodecHash(transaction, {name: 'transaction-message'})).digest
82
+
83
+ export const signTransaction = async (wallet: signable, transaction: transaction): Promise<signedTransaction> => {
84
+ const signature = await wallet.sign(transaction)
85
+ const signedTransaction = {...transaction, signature}
86
+ return signedTransaction
87
+ }
88
+