@leofcoin/lib 1.2.23 → 1.2.24
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 +9 -3
- package/exports/typings/index.d.ts +7 -6
- package/package.json +1 -1
- package/src/index.ts +18 -11
- package/test.js +8 -3
package/exports/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ContractMessage, TransactionMessage } from '@leofcoin/messages';
|
|
1
|
+
import { ContractMessage, TransactionMessage, RawTransactionMessage } from '@leofcoin/messages';
|
|
2
2
|
import { validators as validators$1, contractFactory as contractFactory$1 } from '@leofcoin/addresses';
|
|
3
3
|
export { default as nodeConfig } from './node-config.js';
|
|
4
4
|
import { parseUnits, formatUnits } from '@leofcoin/utils';
|
|
@@ -52,8 +52,14 @@ const calculateReward = (validators, fees) => {
|
|
|
52
52
|
return validators;
|
|
53
53
|
};
|
|
54
54
|
const createTransactionHash = async (transaction) => {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const isRawTransactionMessage = transaction instanceof RawTransactionMessage;
|
|
56
|
+
if (!isRawTransactionMessage) {
|
|
57
|
+
if (transaction.decoded && transaction instanceof TransactionMessage)
|
|
58
|
+
transaction = await new RawTransactionMessage(transaction.decoded);
|
|
59
|
+
else
|
|
60
|
+
transaction = await new RawTransactionMessage(transaction);
|
|
61
|
+
}
|
|
62
|
+
return (await transaction.peernetHash).digest;
|
|
57
63
|
};
|
|
58
64
|
const signTransaction = async (transaction, wallet) => {
|
|
59
65
|
const signature = await wallet.sign(await createTransactionHash(transaction));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ContractMessage } from '@leofcoin/messages';
|
|
1
|
+
import { ContractMessage, TransactionMessage, RawTransactionMessage } from '@leofcoin/messages';
|
|
2
2
|
export { default as nodeConfig } from './node-config.js';
|
|
3
3
|
declare type address = string;
|
|
4
|
-
declare type
|
|
4
|
+
declare type rawTransaction = {
|
|
5
5
|
from: address;
|
|
6
6
|
to: address;
|
|
7
7
|
method: string;
|
|
@@ -14,9 +14,10 @@ declare type signedTransaction = {
|
|
|
14
14
|
method: string;
|
|
15
15
|
params: any[];
|
|
16
16
|
timestamp: Number;
|
|
17
|
+
signature: Uint8Array;
|
|
17
18
|
};
|
|
18
19
|
declare type signable = {
|
|
19
|
-
sign: (transaction:
|
|
20
|
+
sign: (transaction: rawTransaction) => Uint8Array;
|
|
20
21
|
};
|
|
21
22
|
export declare const contractFactoryMessage: string;
|
|
22
23
|
export declare const nativeTokenMessage: string;
|
|
@@ -26,9 +27,9 @@ export declare const createContractMessage: (creator: any, contract: any, constr
|
|
|
26
27
|
export declare const calculateFee: (transaction: any, format?: boolean) => Promise<any>;
|
|
27
28
|
export declare const calculateTransactionFee: (transaction: any) => Promise<any>;
|
|
28
29
|
export declare const calculateReward: (validators: any, fees: any) => [];
|
|
29
|
-
export declare const createTransactionHash: (transaction:
|
|
30
|
-
export declare const signTransaction: (transaction:
|
|
31
|
-
export declare const prepareContractTransaction: (owner: any, contract: any, constructorParameters?: any[]) => Promise<
|
|
30
|
+
export declare const createTransactionHash: (transaction: rawTransaction | TransactionMessage | RawTransactionMessage) => Promise<Uint8Array>;
|
|
31
|
+
export declare const signTransaction: (transaction: rawTransaction, wallet: signable) => Promise<signedTransaction>;
|
|
32
|
+
export declare const prepareContractTransaction: (owner: any, contract: any, constructorParameters?: any[]) => Promise<rawTransaction>;
|
|
32
33
|
/**
|
|
33
34
|
*
|
|
34
35
|
* @param owner address
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import bytecodes from './bytecodes.json' assert {type: 'json'}
|
|
2
|
-
import { ContractMessage, TransactionMessage } from '@leofcoin/messages'
|
|
3
|
-
import { CodecHash } from '@leofcoin/codec-format-interface'
|
|
2
|
+
import { ContractMessage, TransactionMessage, RawTransactionMessage } from '@leofcoin/messages'
|
|
4
3
|
import { validators, contractFactory} from '@leofcoin/addresses'
|
|
5
4
|
export { default as nodeConfig} from './node-config.js'
|
|
6
5
|
import { BigNumber, formatUnits, parseUnits } from '@leofcoin/utils'
|
|
7
6
|
|
|
8
7
|
declare type address = string
|
|
9
8
|
|
|
10
|
-
declare type
|
|
9
|
+
declare type rawTransaction = {
|
|
11
10
|
from: address,
|
|
12
11
|
to: address,
|
|
13
12
|
method: string,
|
|
@@ -20,11 +19,12 @@ declare type signedTransaction = {
|
|
|
20
19
|
to: address,
|
|
21
20
|
method: string,
|
|
22
21
|
params: any[],
|
|
23
|
-
timestamp: Number
|
|
22
|
+
timestamp: Number,
|
|
23
|
+
signature: Uint8Array
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
declare type signable = {
|
|
27
|
-
sign: (transaction) => Uint8Array
|
|
27
|
+
sign: (transaction: rawTransaction) => Uint8Array
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
export const contractFactoryMessage = bytecodes.contractFactory
|
|
@@ -72,13 +72,20 @@ export const calculateReward = (validators, fees): [] => {
|
|
|
72
72
|
return validators
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
export const createTransactionHash = async (transaction:
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
export const createTransactionHash = async (transaction: rawTransaction | TransactionMessage | RawTransactionMessage): Promise<Uint8Array> => {
|
|
76
|
+
const isRawTransactionMessage = transaction instanceof RawTransactionMessage
|
|
77
|
+
|
|
78
|
+
if (!isRawTransactionMessage) {
|
|
79
|
+
if (transaction.decoded && transaction instanceof TransactionMessage) transaction = await new RawTransactionMessage(transaction.decoded)
|
|
80
|
+
else transaction = await new RawTransactionMessage(transaction)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return (await transaction.peernetHash).digest
|
|
78
84
|
}
|
|
79
|
-
|
|
85
|
+
|
|
80
86
|
|
|
81
|
-
export const signTransaction = async (transaction:
|
|
87
|
+
export const signTransaction = async (transaction: rawTransaction, wallet: signable): Promise<signedTransaction> => {
|
|
88
|
+
|
|
82
89
|
const signature = await wallet.sign(await createTransactionHash(transaction))
|
|
83
90
|
const signedTransaction = {...transaction, signature}
|
|
84
91
|
return signedTransaction
|
|
@@ -88,7 +95,7 @@ export const prepareContractTransaction = async (owner, contract, constructorPar
|
|
|
88
95
|
const message = await createContractMessage(owner, contract, constructorParameters)
|
|
89
96
|
const hash = await message.hash()
|
|
90
97
|
|
|
91
|
-
const transaction:
|
|
98
|
+
const transaction: rawTransaction = {
|
|
92
99
|
from: owner,
|
|
93
100
|
to: contractFactory,
|
|
94
101
|
timestamp: new Date().getTime(),
|
package/test.js
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
|
-
import {calculateFee} from './exports/index.js'
|
|
1
|
+
import {calculateFee, createTransactionHash} from './exports/index.js'
|
|
2
2
|
import { formatUnits } from '@leofcoin/utils'
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
const transaction = {
|
|
4
5
|
from: "YTqzkFatW1LmGXhfHicj3xTirQxYqKezfFter31Pq1RNRa6UWYYWs",
|
|
5
6
|
method:"transfer",
|
|
6
7
|
nonce: 313348,
|
|
7
8
|
params: ['YTqzkFatW1LmGXhfHicj3xTirQxYqKezfFter31Pq1RNRa6UWYYWs', 'YTqwTAojA8aZDPYhSFey3KsYb66YdEa4Xe7L6E484VTfMSVvauLZd', '100000000000000000000'],
|
|
8
9
|
signature: new Uint8Array([0, 196, 7, 133, 115, 24, 136, 210, 114, 80, 122, 34, 154, 44, 76, 216, 18, 142, 75, 102, 12, 237, 85, 184, 115, 196, 222, 220, 132, 156, 201, 79, 190, 122, 123, 114, 112, 95, 84, 36, 225, 11, 175, 0, 236, 100, 5, 20, 128, 23, 249, 153, 206, 2, 103, 178, 14, 93, 66, 115, 8, 63, 110, 128, 180, 219, 42]),
|
|
9
10
|
timestamp: 1678450782309,
|
|
10
|
-
to: "IHNY2GQHXGQL4URICKLN5SE5ULIPF2QSFWU3DP4GZFOA5DBX4MMVDKJ2I3M"
|
|
11
|
+
to: "IHNY2GQHXGQL4URICKLN5SE5ULIPF2QSFWU3DP4GZFOA5DBX4MMVDKJ2I3M"
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const fee = await calculateFee(transaction)
|
|
11
15
|
|
|
16
|
+
console.log(await createTransactionHash(transaction));
|
|
12
17
|
console.log(fee);
|
|
13
18
|
|
|
14
19
|
console.log(formatUnits(fee));
|