@aeternity/aepp-sdk 12.0.0 → 12.1.2
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/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -15
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +2 -1
- package/dist/aepp-sdk.browser.js.LICENSE.txt +1 -0
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +20765 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/AeSdk.d.ts +7 -7
- package/es/AeSdk.mjs.map +1 -1
- package/es/AeSdkAepp.d.ts +4 -3
- package/es/AeSdkAepp.mjs +2 -1
- package/es/AeSdkAepp.mjs.map +1 -1
- package/es/AeSdkBase.d.ts +22 -21
- package/es/AeSdkBase.mjs +25 -21
- package/es/AeSdkBase.mjs.map +1 -1
- package/es/AeSdkWallet.d.ts +4 -3
- package/es/AeSdkWallet.mjs +5 -1
- package/es/AeSdkWallet.mjs.map +1 -1
- package/es/Node.d.ts +7 -10
- package/es/Node.mjs +63 -57
- package/es/Node.mjs.map +1 -1
- package/es/account/Base.d.ts +7 -4
- package/es/account/Base.mjs +3 -3
- package/es/account/Base.mjs.map +1 -1
- package/es/account/Memory.d.ts +5 -4
- package/es/account/Memory.mjs +24 -2
- package/es/account/Memory.mjs.map +1 -1
- package/es/account/Rpc.d.ts +6 -6
- package/es/account/Rpc.mjs +3 -2
- package/es/account/Rpc.mjs.map +1 -1
- package/es/aens.d.ts +27 -14
- package/es/aens.mjs +27 -21
- package/es/aens.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/Browser.d.ts +2 -1
- package/es/aepp-wallet-communication/connection/Browser.mjs +5 -2
- package/es/aepp-wallet-communication/connection/Browser.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserRuntime.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs +1 -0
- package/es/aepp-wallet-communication/connection/BrowserRuntime.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.d.ts +1 -0
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs +5 -1
- package/es/aepp-wallet-communication/connection/BrowserWindowMessage.mjs.map +1 -1
- package/es/aepp-wallet-communication/connection-proxy.d.ts +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs +1 -0
- package/es/aepp-wallet-communication/connection-proxy.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/RpcClient.d.ts +1 -0
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs +5 -5
- package/es/aepp-wallet-communication/rpc/RpcClient.mjs.map +1 -1
- package/es/aepp-wallet-communication/rpc/types.d.ts +8 -8
- package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
- package/es/aepp-wallet-communication/schema.d.ts +17 -2
- package/es/aepp-wallet-communication/schema.mjs +54 -17
- package/es/aepp-wallet-communication/schema.mjs.map +1 -1
- package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -1
- package/es/aepp-wallet-communication/wallet-detector.mjs +2 -3
- package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
- package/es/apis/node/models/index.d.ts +6 -2
- package/es/apis/node/models/index.mjs.map +1 -1
- package/es/apis/node/models/mappers.mjs +4 -2
- package/es/apis/node/models/mappers.mjs.map +1 -1
- package/es/chain.d.ts +92 -64
- package/es/chain.mjs +190 -154
- package/es/chain.mjs.map +1 -1
- package/es/channel/handlers.d.ts +3 -3
- package/es/channel/handlers.mjs +42 -44
- package/es/channel/handlers.mjs.map +1 -1
- package/es/channel/index.d.ts +43 -52
- package/es/channel/index.mjs +46 -49
- package/es/channel/index.mjs.map +1 -1
- package/es/channel/internal.d.ts +16 -15
- package/es/channel/internal.mjs +67 -62
- package/es/channel/internal.mjs.map +1 -1
- package/es/contract/Compiler.d.ts +1 -0
- package/es/contract/Compiler.mjs +5 -4
- package/es/contract/Compiler.mjs.map +1 -1
- package/es/contract/aci.d.ts +17 -15
- package/es/contract/aci.mjs +58 -45
- package/es/contract/aci.mjs.map +1 -1
- package/es/contract/ga.d.ts +16 -15
- package/es/contract/ga.mjs +12 -7
- package/es/contract/ga.mjs.map +1 -1
- package/es/contract/methods.d.ts +9 -6
- package/es/contract/methods.mjs +9 -6
- package/es/contract/methods.mjs.map +1 -1
- package/es/deprecated/index.d.ts +143 -0
- package/es/deprecated/index.mjs +162 -0
- package/es/deprecated/index.mjs.map +1 -0
- package/es/deprecated/methods.d.ts +18 -0
- package/es/deprecated/methods.mjs +26 -0
- package/es/deprecated/methods.mjs.map +1 -0
- package/es/index.d.ts +4 -1
- package/es/index.mjs +4 -1
- package/es/index.mjs.map +1 -1
- package/es/oracle.d.ts +69 -62
- package/es/oracle.mjs +121 -103
- package/es/oracle.mjs.map +1 -1
- package/es/spend.d.ts +16 -15
- package/es/spend.mjs +19 -30
- package/es/spend.mjs.map +1 -1
- package/es/tx/builder/address.d.ts +25 -0
- package/es/tx/builder/address.mjs +45 -0
- package/es/tx/builder/address.mjs.map +1 -0
- package/es/tx/builder/constants.d.ts +55 -26
- package/es/tx/builder/constants.mjs +60 -38
- package/es/tx/builder/constants.mjs.map +1 -1
- package/es/tx/builder/field-types/coin-amount.d.ts +13 -0
- package/es/tx/builder/field-types/coin-amount.mjs +26 -0
- package/es/tx/builder/field-types/coin-amount.mjs.map +1 -0
- package/es/tx/builder/field-types/deposit.d.ts +15 -0
- package/es/tx/builder/field-types/deposit.mjs +19 -0
- package/es/tx/builder/field-types/deposit.mjs.map +1 -0
- package/es/tx/builder/field-types/fee.d.ts +25 -0
- package/es/tx/{min-fee.mjs → builder/field-types/fee.mjs} +62 -60
- package/es/tx/builder/field-types/fee.mjs.map +1 -0
- package/es/tx/builder/field-types/field.d.ts +6 -0
- package/es/tx/builder/field-types/field.mjs +15 -0
- package/es/tx/builder/field-types/field.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-limit.d.ts +12 -0
- package/es/tx/builder/field-types/gas-limit.mjs +33 -0
- package/es/tx/builder/field-types/gas-limit.mjs.map +1 -0
- package/es/tx/builder/field-types/gas-price.d.ts +8 -0
- package/es/tx/builder/field-types/gas-price.mjs +18 -0
- package/es/tx/builder/field-types/gas-price.mjs.map +1 -0
- package/es/tx/builder/field-types/index.d.ts +70 -0
- package/es/tx/builder/field-types/index.mjs +25 -0
- package/es/tx/builder/field-types/index.mjs.map +1 -0
- package/es/tx/builder/field-types/name-fee.d.ts +20 -0
- package/es/tx/builder/field-types/name-fee.mjs +24 -0
- package/es/tx/builder/field-types/name-fee.mjs.map +1 -0
- package/es/tx/builder/field-types/name-id.d.ts +14 -0
- package/es/tx/builder/field-types/name-id.mjs +19 -0
- package/es/tx/builder/field-types/name-id.mjs.map +1 -0
- package/es/tx/builder/field-types/name.d.ts +13 -0
- package/es/tx/builder/field-types/name.mjs +18 -0
- package/es/tx/builder/field-types/name.mjs.map +1 -0
- package/es/tx/builder/field-types/short-u-int.d.ts +6 -0
- package/es/tx/builder/field-types/short-u-int.mjs +12 -0
- package/es/tx/builder/field-types/short-u-int.mjs.map +1 -0
- package/es/tx/builder/field-types/u-int.d.ts +8 -0
- package/es/tx/builder/field-types/u-int.mjs +14 -0
- package/es/tx/builder/field-types/u-int.mjs.map +1 -0
- package/es/tx/builder/helpers.d.ts +27 -33
- package/es/tx/builder/helpers.mjs +41 -47
- package/es/tx/builder/helpers.mjs.map +1 -1
- package/es/tx/builder/index.d.ts +25 -12
- package/es/tx/builder/index.mjs +74 -83
- package/es/tx/builder/index.mjs.map +1 -1
- package/es/tx/builder/schema.d.ts +995 -144
- package/es/tx/builder/schema.mjs +121 -170
- package/es/tx/builder/schema.mjs.map +1 -1
- package/es/tx/index.d.ts +28 -27
- package/es/tx/index.mjs +97 -117
- package/es/tx/index.mjs.map +1 -1
- package/es/tx/validator.d.ts +4 -3
- package/es/tx/validator.mjs +79 -92
- package/es/tx/validator.mjs.map +1 -1
- package/es/typings/@aeternity__argon2-browser/index.d.mjs.map +1 -1
- package/es/typings/@aeternity__uuid/index.d.mjs.map +1 -1
- package/es/typings/bip32-path/index.d.mjs.map +1 -1
- package/es/typings/blakejs/index.d.mjs.map +1 -1
- package/es/typings/sha-js/index.d.mjs +2 -0
- package/es/typings/sha-js/index.d.mjs.map +1 -0
- package/es/typings/tweetnacl-auth/index.d.mjs.map +1 -1
- package/es/utils/amount-formatter.d.ts +9 -9
- package/es/utils/amount-formatter.mjs +17 -17
- package/es/utils/amount-formatter.mjs.map +1 -1
- package/es/utils/autorest.mjs +7 -7
- package/es/utils/autorest.mjs.map +1 -1
- package/es/utils/bignumber.mjs +2 -1
- package/es/utils/bignumber.mjs.map +1 -1
- package/es/utils/bytes.mjs +1 -1
- package/es/utils/bytes.mjs.map +1 -1
- package/es/utils/crypto.d.ts +8 -23
- package/es/utils/crypto.mjs +15 -41
- package/es/utils/crypto.mjs.map +1 -1
- package/es/utils/encoder-types.d.ts +61 -0
- package/es/utils/encoder-types.mjs +36 -0
- package/es/utils/encoder-types.mjs.map +1 -0
- package/es/utils/encoder.d.ts +6 -7
- package/es/utils/encoder.mjs +42 -26
- package/es/utils/encoder.mjs.map +1 -1
- package/es/utils/errors.d.ts +1 -11
- package/es/utils/errors.mjs +4 -20
- package/es/utils/errors.mjs.map +1 -1
- package/es/utils/hd-wallet.d.ts +18 -2
- package/es/utils/hd-wallet.mjs +64 -34
- package/es/utils/hd-wallet.mjs.map +1 -1
- package/es/utils/json-big.mjs +2 -2
- package/es/utils/json-big.mjs.map +1 -1
- package/es/utils/keystore.mjs +4 -2
- package/es/utils/keystore.mjs.map +1 -1
- package/es/utils/mptree.d.ts +2 -2
- package/es/utils/mptree.mjs +11 -6
- package/es/utils/mptree.mjs.map +1 -1
- package/es/utils/other.d.ts +8 -2
- package/es/utils/other.mjs +15 -3
- package/es/utils/other.mjs.map +1 -1
- package/es/utils/semver-satisfies.d.ts +1 -1
- package/es/utils/semver-satisfies.mjs +2 -2
- package/es/utils/semver-satisfies.mjs.map +1 -1
- package/es/utils/string.mjs.map +1 -1
- package/package.json +36 -34
- package/src/AeSdk.ts +30 -27
- package/src/AeSdkAepp.ts +93 -84
- package/src/AeSdkBase.ts +148 -130
- package/src/AeSdkWallet.ts +172 -156
- package/src/Node.ts +108 -102
- package/src/account/Base.ts +42 -32
- package/src/account/Memory.ts +45 -30
- package/src/account/Rpc.ts +32 -30
- package/src/aens.ts +124 -108
- package/src/aepp-wallet-communication/connection/Browser.ts +18 -15
- package/src/aepp-wallet-communication/connection/BrowserRuntime.ts +22 -21
- package/src/aepp-wallet-communication/connection/BrowserWindowMessage.ts +63 -52
- package/src/aepp-wallet-communication/connection-proxy.ts +8 -7
- package/src/aepp-wallet-communication/rpc/RpcClient.ts +67 -61
- package/src/aepp-wallet-communication/rpc/types.ts +32 -32
- package/src/aepp-wallet-communication/schema.ts +117 -74
- package/src/aepp-wallet-communication/wallet-detector.ts +29 -28
- package/src/apis/node/code-model-v4.yaml +54 -20
- package/src/apis/node/models/index.ts +6 -2
- package/src/apis/node/models/mappers.ts +4 -2
- package/src/chain.ts +286 -228
- package/src/channel/handlers.ts +424 -372
- package/src/channel/index.ts +285 -251
- package/src/channel/internal.ts +248 -232
- package/src/contract/Compiler.ts +22 -21
- package/src/contract/aci.ts +267 -258
- package/src/contract/ga.ts +93 -72
- package/src/contract/methods.ts +32 -27
- package/src/deprecated/index.ts +172 -0
- package/src/deprecated/methods.ts +25 -0
- package/src/index.ts +37 -32
- package/src/oracle.ts +211 -189
- package/src/spend.ts +82 -70
- package/src/tx/builder/address.ts +50 -0
- package/src/tx/builder/constants.ts +82 -52
- package/src/tx/builder/field-types/coin-amount.ts +27 -0
- package/src/tx/builder/field-types/deposit.ts +21 -0
- package/src/tx/builder/field-types/fee.ts +143 -0
- package/src/tx/builder/field-types/field.ts +9 -0
- package/src/tx/builder/field-types/gas-limit.ts +41 -0
- package/src/tx/builder/field-types/gas-price.ts +16 -0
- package/src/tx/builder/field-types/index.ts +45 -0
- package/src/tx/builder/field-types/name-fee.ts +32 -0
- package/src/tx/builder/field-types/name-id.ts +20 -0
- package/src/tx/builder/field-types/name.ts +18 -0
- package/src/tx/builder/field-types/short-u-int.ts +11 -0
- package/src/tx/builder/field-types/u-int.ts +16 -0
- package/src/tx/builder/helpers.ts +112 -117
- package/src/tx/builder/index.ts +203 -197
- package/src/tx/builder/schema.ts +421 -465
- package/src/tx/index.ts +128 -135
- package/src/tx/validator.ts +165 -161
- package/src/typings/@aeternity__argon2-browser/index.d.ts +1 -1
- package/src/typings/@aeternity__uuid/index.d.ts +3 -1
- package/src/typings/bip32-path/index.d.ts +6 -6
- package/src/typings/blakejs/index.d.ts +4 -32
- package/src/typings/sha-js/index.d.ts +5 -0
- package/src/typings/tweetnacl-auth/index.d.ts +2 -2
- package/src/utils/amount-formatter.ts +41 -41
- package/src/utils/autorest.ts +57 -54
- package/src/utils/bignumber.ts +7 -6
- package/src/utils/bytes.ts +19 -19
- package/src/utils/crypto.ts +82 -94
- package/src/utils/encoder-types.ts +63 -0
- package/src/utils/encoder.ts +104 -56
- package/src/utils/errors.ts +246 -264
- package/src/utils/hd-wallet.ts +114 -82
- package/src/utils/json-big.ts +16 -15
- package/src/utils/keystore.ts +65 -62
- package/src/utils/mptree.ts +59 -56
- package/src/utils/other.ts +26 -18
- package/src/utils/semver-satisfies.ts +15 -11
- package/src/utils/string.ts +10 -10
- package/es/tx/builder/field-types.d.ts +0 -62
- package/es/tx/builder/field-types.mjs +0 -126
- package/es/tx/builder/field-types.mjs.map +0 -1
- package/es/tx/min-fee.d.ts +0 -20
- package/es/tx/min-fee.mjs.map +0 -1
- package/src/tx/builder/field-types.ts +0 -111
- package/src/tx/min-fee.ts +0 -136
|
@@ -3,34 +3,35 @@ const {
|
|
|
3
3
|
Buffer: _Buffer
|
|
4
4
|
} = _buffer;
|
|
5
5
|
import BigNumber from 'bignumber.js';
|
|
6
|
-
import {
|
|
7
|
-
import { encode,
|
|
6
|
+
import { genSalt, hash } from "../../utils/crypto.mjs";
|
|
7
|
+
import { decode, encode, Encoding } from "../../utils/encoder.mjs";
|
|
8
8
|
import { toBytes } from "../../utils/bytes.mjs";
|
|
9
9
|
import { concatBuffers } from "../../utils/other.mjs";
|
|
10
|
-
import {
|
|
10
|
+
import { NAME_BID_RANGES, NAME_BID_TIMEOUT_BLOCKS, NAME_FEE_BID_INCREMENT, NAME_MAX_LENGTH_FEE } from "./constants.mjs";
|
|
11
11
|
import { ceil } from "../../utils/bignumber.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { ArgumentError, IllegalBidFeeError } from "../../utils/errors.mjs";
|
|
13
|
+
import { readId, writeId } from "./address.mjs";
|
|
13
14
|
/**
|
|
14
15
|
* JavaScript-based Transaction builder helper function's
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
|
-
export const createSalt = salt;
|
|
18
|
-
export { encode, decode };
|
|
19
|
-
|
|
20
18
|
/**
|
|
21
19
|
* Build a contract public key
|
|
20
|
+
* @category contract
|
|
22
21
|
* @param ownerId - The public key of the owner account
|
|
23
22
|
* @param nonce - the nonce of the transaction
|
|
24
23
|
* @returns Contract public key
|
|
25
24
|
*/
|
|
25
|
+
|
|
26
26
|
export function buildContractId(ownerId, nonce) {
|
|
27
27
|
const ownerIdAndNonce = _Buffer.from([...decode(ownerId), ...toBytes(nonce)]);
|
|
28
28
|
|
|
29
29
|
const b2bHash = hash(ownerIdAndNonce);
|
|
30
|
-
return encode(b2bHash,
|
|
30
|
+
return encode(b2bHash, Encoding.ContractAddress);
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Build a oracle query id
|
|
34
|
+
* @category oracle
|
|
34
35
|
* @param senderId - The public key of the sender account
|
|
35
36
|
* @param nonce - the nonce of the transaction
|
|
36
37
|
* @param oracleId - The oracle public key
|
|
@@ -44,10 +45,11 @@ export function oracleQueryId(senderId, nonce, oracleId) {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
const b2bHash = hash(_Buffer.from([...decode(senderId), ..._int32(nonce), ...decode(oracleId)]));
|
|
47
|
-
return encode(b2bHash,
|
|
48
|
+
return encode(b2bHash, Encoding.OracleQueryId);
|
|
48
49
|
}
|
|
49
50
|
/**
|
|
50
51
|
* Format the salt into a 64-byte hex string
|
|
52
|
+
* @category transaction builder
|
|
51
53
|
* @param salt - Random number
|
|
52
54
|
* @returns Zero-padded hex string of salt
|
|
53
55
|
*/
|
|
@@ -57,55 +59,30 @@ export function formatSalt(salt) {
|
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
61
|
* Encode an AENS name
|
|
60
|
-
*
|
|
62
|
+
* @category AENS
|
|
61
63
|
* @param name - Name to encode
|
|
62
64
|
* @returns `nm_` prefixed encoded AENS name
|
|
63
65
|
*/
|
|
64
66
|
|
|
65
67
|
export function produceNameId(name) {
|
|
66
|
-
return encode(hash(name.toLowerCase()),
|
|
68
|
+
return encode(hash(name.toLowerCase()), Encoding.Name);
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
69
71
|
* Generate the commitment hash by hashing the formatted salt and
|
|
70
72
|
* name, base 58 encoding the result and prepending 'cm_'
|
|
71
|
-
*
|
|
73
|
+
* @category transaction builder
|
|
72
74
|
* @param name - Name to be registered
|
|
73
75
|
* @param salt - Random salt
|
|
74
76
|
* @returns Commitment hash
|
|
75
77
|
*/
|
|
76
78
|
|
|
77
79
|
export function commitmentHash(name) {
|
|
78
|
-
let salt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] :
|
|
79
|
-
return encode(hash(concatBuffers([_Buffer.from(name.toLowerCase()), formatSalt(salt)])),
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Utility function to create and _id type
|
|
83
|
-
* @param hashId - Encoded hash
|
|
84
|
-
* @returns Buffer Buffer with ID tag and decoded HASh
|
|
85
|
-
*/
|
|
86
|
-
|
|
87
|
-
export function writeId(hashId) {
|
|
88
|
-
if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId);
|
|
89
|
-
const prefix = hashId.slice(0, 2);
|
|
90
|
-
const idTag = PREFIX_ID_TAG[prefix];
|
|
91
|
-
if (idTag == null) throw new TagNotFoundError(prefix);
|
|
92
|
-
return _Buffer.from([...toBytes(idTag), ...decode(hashId)]);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Utility function to read and _id type
|
|
96
|
-
* @param buf - Data
|
|
97
|
-
* @returns Encoided hash string with prefix
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
export function readId(buf) {
|
|
101
|
-
const tag = _Buffer.from(buf).readUIntBE(0, 1);
|
|
102
|
-
|
|
103
|
-
const prefix = ID_TAG_PREFIX[tag];
|
|
104
|
-
if (prefix == null) throw new PrefixNotFoundError(tag);
|
|
105
|
-
return encode(buf.slice(1, buf.length), prefix);
|
|
80
|
+
let salt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : genSalt();
|
|
81
|
+
return encode(hash(concatBuffers([_Buffer.from(name.toLowerCase()), formatSalt(salt)])), Encoding.Commitment);
|
|
106
82
|
}
|
|
107
83
|
/**
|
|
108
84
|
* Utility function to convert int to bytes
|
|
85
|
+
* @category transaction builder
|
|
109
86
|
* @param val - Value
|
|
110
87
|
* @returns Buffer Buffer from number(BigEndian)
|
|
111
88
|
*/
|
|
@@ -115,6 +92,7 @@ export function writeInt(val) {
|
|
|
115
92
|
}
|
|
116
93
|
/**
|
|
117
94
|
* Utility function to convert bytes to int
|
|
95
|
+
* @category transaction builder
|
|
118
96
|
* @param buf - Value
|
|
119
97
|
* @returns Buffer Buffer from number(BigEndian)
|
|
120
98
|
*/
|
|
@@ -125,6 +103,7 @@ export function readInt() {
|
|
|
125
103
|
}
|
|
126
104
|
/**
|
|
127
105
|
* Helper function to build pointers for name update TX
|
|
106
|
+
* @category transaction builder
|
|
128
107
|
* @param pointers - Array of pointers
|
|
129
108
|
* `([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])`
|
|
130
109
|
* @returns Serialized pointers array
|
|
@@ -135,6 +114,7 @@ export function buildPointers(pointers) {
|
|
|
135
114
|
}
|
|
136
115
|
/**
|
|
137
116
|
* Helper function to read pointers from name update TX
|
|
117
|
+
* @category transaction builder
|
|
138
118
|
* @param pointers - Array of pointers
|
|
139
119
|
* @returns Deserialize pointer array
|
|
140
120
|
*/
|
|
@@ -142,15 +122,16 @@ export function buildPointers(pointers) {
|
|
|
142
122
|
export function readPointers(pointers) {
|
|
143
123
|
return pointers.map(_ref => {
|
|
144
124
|
let [key, id] = _ref;
|
|
145
|
-
return
|
|
125
|
+
return {
|
|
146
126
|
key: key.toString(),
|
|
147
127
|
id: readId(id)
|
|
148
|
-
}
|
|
128
|
+
};
|
|
149
129
|
});
|
|
150
130
|
}
|
|
151
131
|
const AENS_SUFFIX = '.chain';
|
|
152
132
|
/**
|
|
153
133
|
* Is AENS name valid
|
|
134
|
+
* @category AENS
|
|
154
135
|
* @param name - AENS name
|
|
155
136
|
*/
|
|
156
137
|
|
|
@@ -158,19 +139,31 @@ export function isNameValid(name) {
|
|
|
158
139
|
// TODO: probably there are stronger requirements
|
|
159
140
|
return name.endsWith(AENS_SUFFIX);
|
|
160
141
|
}
|
|
142
|
+
const encodingToPointerKey = [[Encoding.AccountAddress, 'account_pubkey'], [Encoding.OracleAddress, 'oracle_pubkey'], [Encoding.ContractAddress, 'contract_pubkey'], [Encoding.Channel, 'channel']];
|
|
161
143
|
/**
|
|
144
|
+
* @category AENS
|
|
162
145
|
* @param identifier - account/oracle/contract address, or channel
|
|
163
146
|
* @returns default AENS pointer key
|
|
164
147
|
*/
|
|
165
148
|
|
|
166
149
|
export function getDefaultPointerKey(identifier) {
|
|
150
|
+
var _encodingToPointerKey;
|
|
151
|
+
|
|
167
152
|
decode(identifier);
|
|
168
|
-
const
|
|
169
|
-
|
|
153
|
+
const encoding = identifier.substring(0, 2);
|
|
154
|
+
const result = (_encodingToPointerKey = encodingToPointerKey.find(_ref2 => {
|
|
155
|
+
let [e] = _ref2;
|
|
156
|
+
return e === encoding;
|
|
157
|
+
})) === null || _encodingToPointerKey === void 0 ? void 0 : _encodingToPointerKey[1];
|
|
158
|
+
if (result != null) return result;
|
|
159
|
+
throw new ArgumentError('identifier', `prefixed with one of ${encodingToPointerKey.map(_ref3 => {
|
|
160
|
+
let [e] = _ref3;
|
|
161
|
+
return `${e}_`;
|
|
162
|
+
}).join(', ')}`, identifier);
|
|
170
163
|
}
|
|
171
164
|
/**
|
|
172
165
|
* Get the minimum AENS name fee
|
|
173
|
-
*
|
|
166
|
+
* @category AENS
|
|
174
167
|
* @param name - the AENS name to get the fee for
|
|
175
168
|
* @returns the minimum fee for the AENS name auction
|
|
176
169
|
*/
|
|
@@ -181,7 +174,7 @@ export function getMinimumNameFee(name) {
|
|
|
181
174
|
}
|
|
182
175
|
/**
|
|
183
176
|
* Compute bid fee for AENS auction
|
|
184
|
-
*
|
|
177
|
+
* @category AENS
|
|
185
178
|
* @param name - the AENS name to get the fee for
|
|
186
179
|
* @param options - Options
|
|
187
180
|
* @param options.startFee - Auction start fee
|
|
@@ -201,7 +194,7 @@ export function computeBidFee(name) {
|
|
|
201
194
|
}
|
|
202
195
|
/**
|
|
203
196
|
* Compute auction end height
|
|
204
|
-
*
|
|
197
|
+
* @category AENS
|
|
205
198
|
* @param name - Name to compute auction end for
|
|
206
199
|
* @param claimHeight - Auction starting height
|
|
207
200
|
* @see {@link https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273}
|
|
@@ -215,6 +208,7 @@ export function computeAuctionEndBlock(name, claimHeight) {
|
|
|
215
208
|
}
|
|
216
209
|
/**
|
|
217
210
|
* Is name accept going to auction
|
|
211
|
+
* @category AENS
|
|
218
212
|
*/
|
|
219
213
|
|
|
220
214
|
export function isAuctionName(name) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.mjs","names":["BigNumber","hash","salt","encode","decode","toBytes","concatBuffers","ID_TAG_PREFIX","PREFIX_ID_TAG","NAME_BID_RANGES","NAME_FEE_BID_INCREMENT","NAME_BID_TIMEOUT_BLOCKS","NAME_MAX_LENGTH_FEE","POINTER_KEY_BY_PREFIX","ceil","TagNotFoundError","PrefixNotFoundError","IllegalBidFeeError","ArgumentError","createSalt","buildContractId","ownerId","nonce","ownerIdAndNonce","from","b2bHash","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","alloc","length","formatSalt","toString","padStart","produceNameId","name","toLowerCase","commitmentHash","writeId","hashId","prefix","slice","idTag","readId","buf","tag","readUIntBE","writeInt","readInt","buildPointers","pointers","map","p","key","id","readPointers","Object","assign","AENS_SUFFIX","isNameValid","endsWith","getDefaultPointerKey","identifier","substring","getMinimumNameFee","nameLength","Math","min","computeBidFee","startFee","increment","Number","times","plus","computeAuctionEndBlock","claimHeight","h","isAuctionName"],"sources":["../../../src/tx/builder/helpers.ts"],"sourcesContent":["import BigNumber from 'bignumber.js'\nimport { hash, salt } from '../../utils/crypto'\nimport { encode, decode, EncodedData, EncodingType } from '../../utils/encoder'\nimport { toBytes } from '../../utils/bytes'\nimport { concatBuffers } from '../../utils/other'\nimport {\n ID_TAG_PREFIX,\n PREFIX_ID_TAG,\n NAME_BID_RANGES,\n NAME_FEE_BID_INCREMENT,\n NAME_BID_TIMEOUT_BLOCKS,\n NAME_MAX_LENGTH_FEE,\n POINTER_KEY_BY_PREFIX,\n AensName\n} from './constants'\nimport { ceil } from '../../utils/bignumber'\nimport {\n TagNotFoundError,\n PrefixNotFoundError,\n IllegalBidFeeError,\n ArgumentError\n} from '../../utils/errors'\n\n/**\n * JavaScript-based Transaction builder helper function's\n */\n\nexport const createSalt = salt\n\nexport { encode, decode }\n\nexport interface Pointer {\n key: string\n id: string\n}\n\n/**\n * Build a contract public key\n * @param ownerId - The public key of the owner account\n * @param nonce - the nonce of the transaction\n * @returns Contract public key\n */\nexport function buildContractId (ownerId: EncodedData<'ak'>, nonce: number | BigNumber): EncodedData<'ct'> {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId), ...toBytes(nonce)])\n const b2bHash = hash(ownerIdAndNonce)\n return encode(b2bHash, 'ct')\n}\n\n/**\n * Build a oracle query id\n * @param senderId - The public key of the sender account\n * @param nonce - the nonce of the transaction\n * @param oracleId - The oracle public key\n * @returns Contract public key\n */\nexport function oracleQueryId (\n senderId: EncodedData<'ak'>,\n nonce: number | BigNumber | string,\n oracleId: EncodedData<'ok'>\n): EncodedData<'oq'> {\n function _int32 (val: number | string | BigNumber): Buffer {\n const nonceBE = toBytes(val, true)\n return concatBuffers([Buffer.alloc(32 - nonceBE.length), nonceBE])\n }\n\n const b2bHash = hash(\n Buffer.from([...decode(senderId), ..._int32(nonce), ...decode(oracleId)]))\n return encode(b2bHash, 'oq')\n}\n\n/**\n * Format the salt into a 64-byte hex string\n * @param salt - Random number\n * @returns Zero-padded hex string of salt\n */\nexport function formatSalt (salt: number): Buffer {\n return Buffer.from(salt.toString(16).padStart(64, '0'), 'hex')\n}\n\n/**\n * Encode an AENS name\n *\n * @param name - Name to encode\n * @returns `nm_` prefixed encoded AENS name\n */\nexport function produceNameId (name: AensName): EncodedData<'nm'> {\n return encode(hash(name.toLowerCase()), 'nm')\n}\n\n/**\n * Generate the commitment hash by hashing the formatted salt and\n * name, base 58 encoding the result and prepending 'cm_'\n *\n * @param name - Name to be registered\n * @param salt - Random salt\n * @returns Commitment hash\n */\nexport function commitmentHash (name: AensName, salt: number = createSalt()): EncodedData<'cm'> {\n return encode(hash(concatBuffers([Buffer.from(name.toLowerCase()), formatSalt(salt)])), 'cm')\n}\n\n/**\n * Utility function to create and _id type\n * @param hashId - Encoded hash\n * @returns Buffer Buffer with ID tag and decoded HASh\n */\nexport function writeId (hashId: string): Buffer {\n if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId)\n const prefix = hashId.slice(0, 2) as keyof typeof PREFIX_ID_TAG\n const idTag = PREFIX_ID_TAG[prefix]\n if (idTag == null) throw new TagNotFoundError(prefix)\n return Buffer.from([...toBytes(idTag), ...decode(hashId as EncodedData<EncodingType>)])\n}\n\n/**\n * Utility function to read and _id type\n * @param buf - Data\n * @returns Encoided hash string with prefix\n */\nexport function readId (buf: Buffer): string {\n const tag = Buffer.from(buf).readUIntBE(0, 1)\n const prefix = ID_TAG_PREFIX[tag]\n if (prefix == null) throw new PrefixNotFoundError(tag)\n return encode(buf.slice(1, buf.length), prefix)\n}\n\n/**\n * Utility function to convert int to bytes\n * @param val - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function writeInt (val: number | string | BigNumber): Buffer {\n return toBytes(val, true)\n}\n\n/**\n * Utility function to convert bytes to int\n * @param buf - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function readInt (buf: Buffer = Buffer.from([])): string {\n return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10)\n}\n\n/**\n * Helper function to build pointers for name update TX\n * @param pointers - Array of pointers\n * `([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])`\n * @returns Serialized pointers array\n */\nexport function buildPointers (pointers: Pointer[]): Buffer[][] {\n return pointers.map(\n p => [\n toBytes(p.key),\n writeId(p.id)\n ]\n )\n}\n\n/**\n * Helper function to read pointers from name update TX\n * @param pointers - Array of pointers\n * @returns Deserialize pointer array\n */\nexport function readPointers (pointers: Array<[key: string, id: Buffer]>): Pointer[] {\n return pointers.map(\n ([key, id]) => Object.assign({\n key: key.toString(),\n id: readId(id)\n })\n )\n}\n\nconst AENS_SUFFIX = '.chain'\n\n/**\n * Is AENS name valid\n * @param name - AENS name\n */\nexport function isNameValid (name: string): name is AensName {\n // TODO: probably there are stronger requirements\n return name.endsWith(AENS_SUFFIX)\n}\n\n/**\n * @param identifier - account/oracle/contract address, or channel\n * @returns default AENS pointer key\n */\nexport function getDefaultPointerKey (\n identifier: EncodedData<keyof typeof POINTER_KEY_BY_PREFIX>\n): POINTER_KEY_BY_PREFIX {\n decode(identifier)\n const prefix = identifier.substring(0, 2) as keyof typeof POINTER_KEY_BY_PREFIX\n return POINTER_KEY_BY_PREFIX[prefix]\n}\n\n/**\n * Get the minimum AENS name fee\n *\n * @param name - the AENS name to get the fee for\n * @returns the minimum fee for the AENS name auction\n */\nexport function getMinimumNameFee (name: AensName): BigNumber {\n const nameLength = name.length - AENS_SUFFIX.length\n return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)]\n}\n\n/**\n * Compute bid fee for AENS auction\n *\n * @param name - the AENS name to get the fee for\n * @param options - Options\n * @param options.startFee - Auction start fee\n * @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)\n * @returns Bid fee\n */\nexport function computeBidFee (\n name: AensName,\n { startFee, increment = NAME_FEE_BID_INCREMENT }:\n { startFee?: number | string | BigNumber, increment?: number } = {}\n): BigNumber {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`)\n if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)\n // FIXME: increment should be used somehow here\n return ceil(\n new BigNumber(startFee ?? getMinimumNameFee(name))\n .times(new BigNumber(NAME_FEE_BID_INCREMENT).plus(1))\n )\n}\n\n/**\n * Compute auction end height\n *\n * @param name - Name to compute auction end for\n * @param claimHeight - Auction starting height\n * @see {@link https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273}\n * @returns Auction end height\n */\nexport function computeAuctionEndBlock (name: AensName, claimHeight: number): number {\n const length = name.length - AENS_SUFFIX.length\n const h = (length <= 4 && 62 * NAME_BID_TIMEOUT_BLOCKS) ||\n (length <= 8 && 31 * NAME_BID_TIMEOUT_BLOCKS) ||\n (length <= 12 && NAME_BID_TIMEOUT_BLOCKS) ||\n 0\n return h + claimHeight\n}\n\n/**\n * Is name accept going to auction\n */\nexport function isAuctionName (name: AensName): boolean {\n return name.length < 13 +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J,CAAwB,mCAAkCP,sBAAuB,EAAjF,CAAN,CAF7B,CAGX;;EACA,OAAOI,IAAI,CACT,IAAId,SAAJ,CAAcwE,QAAd,aAAcA,QAAd,cAAcA,QAAd,GAA0BL,iBAAiB,CAAC7B,IAAD,CAA3C,EACGqC,KADH,CACS,IAAI3E,SAAJ,CAAcU,sBAAd,EAAsCkE,IAAtC,CAA2C,CAA3C,CADT,CADS,CAAX;AAID;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,sBAAT,CAAiCvC,IAAjC,EAAiDwC,WAAjD,EAA8E;EACnF,MAAM7C,MAAM,GAAGK,IAAI,CAACL,MAAL,GAAc4B,WAAW,CAAC5B,MAAzC;EACA,MAAM8C,CAAC,GAAI9C,MAAM,IAAI,CAAV,IAAe,KAAKtB,uBAArB,IACPsB,MAAM,IAAI,CAAV,IAAe,KAAKtB,uBADb,IAEPsB,MAAM,IAAI,EAAV,IAAgBtB,uBAFT,IAGR,CAHF;EAIA,OAAOoE,CAAC,GAAGD,WAAX;AACD;AAED;AACA;AACA;;AACA,OAAO,SAASE,aAAT,CAAwB1C,IAAxB,EAAiD;EACtD,OAAOA,IAAI,CAACL,MAAL,GAAc,KAAK4B,WAAW,CAAC5B,MAAtC;AACD"}
|
|
1
|
+
{"version":3,"file":"helpers.mjs","names":["BigNumber","genSalt","hash","decode","encode","Encoding","toBytes","concatBuffers","NAME_BID_RANGES","NAME_BID_TIMEOUT_BLOCKS","NAME_FEE_BID_INCREMENT","NAME_MAX_LENGTH_FEE","ceil","ArgumentError","IllegalBidFeeError","readId","writeId","buildContractId","ownerId","nonce","ownerIdAndNonce","from","b2bHash","ContractAddress","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","alloc","length","OracleQueryId","formatSalt","salt","toString","padStart","produceNameId","name","toLowerCase","Name","commitmentHash","Commitment","writeInt","readInt","buf","buildPointers","pointers","map","p","key","id","readPointers","AENS_SUFFIX","isNameValid","endsWith","encodingToPointerKey","AccountAddress","OracleAddress","Channel","getDefaultPointerKey","identifier","encoding","substring","result","find","e","join","getMinimumNameFee","nameLength","Math","min","computeBidFee","startFee","increment","Number","times","plus","computeAuctionEndBlock","claimHeight","h","isAuctionName"],"sources":["../../../src/tx/builder/helpers.ts"],"sourcesContent":["import BigNumber from 'bignumber.js';\nimport { genSalt, hash } from '../../utils/crypto';\nimport {\n decode, encode, Encoded, Encoding,\n} from '../../utils/encoder';\nimport { toBytes } from '../../utils/bytes';\nimport { concatBuffers } from '../../utils/other';\nimport {\n AensName,\n NAME_BID_RANGES,\n NAME_BID_TIMEOUT_BLOCKS,\n NAME_FEE_BID_INCREMENT,\n NAME_MAX_LENGTH_FEE,\n} from './constants';\nimport { ceil } from '../../utils/bignumber';\nimport { ArgumentError, IllegalBidFeeError } from '../../utils/errors';\nimport { NamePointer } from '../../apis/node';\nimport { readId, writeId } from './address';\n\n/**\n * JavaScript-based Transaction builder helper function's\n */\n\n/**\n * Build a contract public key\n * @category contract\n * @param ownerId - The public key of the owner account\n * @param nonce - the nonce of the transaction\n * @returns Contract public key\n */\nexport function buildContractId(\n ownerId: Encoded.AccountAddress,\n nonce: number | BigNumber,\n): Encoded.ContractAddress {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId), ...toBytes(nonce)]);\n const b2bHash = hash(ownerIdAndNonce);\n return encode(b2bHash, Encoding.ContractAddress);\n}\n\n/**\n * Build a oracle query id\n * @category oracle\n * @param senderId - The public key of the sender account\n * @param nonce - the nonce of the transaction\n * @param oracleId - The oracle public key\n * @returns Contract public key\n */\nexport function oracleQueryId(\n senderId: Encoded.AccountAddress,\n nonce: number | BigNumber | string,\n oracleId: Encoded.OracleAddress,\n): Encoded.OracleQueryId {\n function _int32(val: number | string | BigNumber): Buffer {\n const nonceBE = toBytes(val, true);\n return concatBuffers([Buffer.alloc(32 - nonceBE.length), nonceBE]);\n }\n\n const b2bHash = hash(\n Buffer.from([...decode(senderId), ..._int32(nonce), ...decode(oracleId)]),\n );\n return encode(b2bHash, Encoding.OracleQueryId);\n}\n\n/**\n * Format the salt into a 64-byte hex string\n * @category transaction builder\n * @param salt - Random number\n * @returns Zero-padded hex string of salt\n */\nexport function formatSalt(salt: number): Buffer {\n return Buffer.from(salt.toString(16).padStart(64, '0'), 'hex');\n}\n\n/**\n * Encode an AENS name\n * @category AENS\n * @param name - Name to encode\n * @returns `nm_` prefixed encoded AENS name\n */\nexport function produceNameId(name: AensName): Encoded.Name {\n return encode(hash(name.toLowerCase()), Encoding.Name);\n}\n\n/**\n * Generate the commitment hash by hashing the formatted salt and\n * name, base 58 encoding the result and prepending 'cm_'\n * @category transaction builder\n * @param name - Name to be registered\n * @param salt - Random salt\n * @returns Commitment hash\n */\nexport function commitmentHash(\n name: AensName,\n salt: number = genSalt(),\n): Encoded.Commitment {\n return encode(\n hash(concatBuffers([Buffer.from(name.toLowerCase()), formatSalt(salt)])),\n Encoding.Commitment,\n );\n}\n\n/**\n * Utility function to convert int to bytes\n * @category transaction builder\n * @param val - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function writeInt(val: number | string | BigNumber): Buffer {\n return toBytes(val, true);\n}\n\n/**\n * Utility function to convert bytes to int\n * @category transaction builder\n * @param buf - Value\n * @returns Buffer Buffer from number(BigEndian)\n */\nexport function readInt(buf: Buffer = Buffer.from([])): string {\n return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10);\n}\n\n/**\n * Helper function to build pointers for name update TX\n * @category transaction builder\n * @param pointers - Array of pointers\n * `([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])`\n * @returns Serialized pointers array\n */\nexport function buildPointers(pointers: NamePointer[]): Buffer[][] {\n return pointers.map(\n (p) => [\n toBytes(p.key),\n writeId(p.id as Parameters<typeof writeId>[0]),\n ],\n );\n}\n\n/**\n * Helper function to read pointers from name update TX\n * @category transaction builder\n * @param pointers - Array of pointers\n * @returns Deserialize pointer array\n */\nexport function readPointers(pointers: Array<[key: string, id: Buffer]>): NamePointer[] {\n return pointers.map(\n ([key, id]) => ({\n key: key.toString(),\n id: readId(id),\n }),\n );\n}\n\nconst AENS_SUFFIX = '.chain';\n\n/**\n * Is AENS name valid\n * @category AENS\n * @param name - AENS name\n */\nexport function isNameValid(name: string): name is AensName {\n // TODO: probably there are stronger requirements\n return name.endsWith(AENS_SUFFIX);\n}\n\nconst encodingToPointerKey = [\n [Encoding.AccountAddress, 'account_pubkey'],\n [Encoding.OracleAddress, 'oracle_pubkey'],\n [Encoding.ContractAddress, 'contract_pubkey'],\n [Encoding.Channel, 'channel'],\n] as const;\n\n/**\n * @category AENS\n * @param identifier - account/oracle/contract address, or channel\n * @returns default AENS pointer key\n */\nexport function getDefaultPointerKey(\n identifier: Encoded.Generic<typeof encodingToPointerKey[number][0]>,\n): typeof encodingToPointerKey[number][1] {\n decode(identifier);\n const encoding = identifier.substring(0, 2);\n const result = encodingToPointerKey.find(([e]) => e === encoding)?.[1];\n if (result != null) return result;\n throw new ArgumentError(\n 'identifier',\n `prefixed with one of ${encodingToPointerKey.map(([e]) => `${e}_`).join(', ')}`,\n identifier,\n );\n}\n\n/**\n * Get the minimum AENS name fee\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @returns the minimum fee for the AENS name auction\n */\nexport function getMinimumNameFee(name: AensName): BigNumber {\n const nameLength = name.length - AENS_SUFFIX.length;\n return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)];\n}\n\n/**\n * Compute bid fee for AENS auction\n * @category AENS\n * @param name - the AENS name to get the fee for\n * @param options - Options\n * @param options.startFee - Auction start fee\n * @param options.increment - Bid multiplier(In percentage, must be between 0 and 1)\n * @returns Bid fee\n */\nexport function computeBidFee(\n name: AensName,\n { startFee, increment = NAME_FEE_BID_INCREMENT }:\n { startFee?: number | string | BigNumber; increment?: number } = {},\n): BigNumber {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`);\n if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`);\n // FIXME: increment should be used somehow here\n return ceil(\n new BigNumber(startFee ?? getMinimumNameFee(name))\n .times(new BigNumber(NAME_FEE_BID_INCREMENT).plus(1)),\n );\n}\n\n/**\n * Compute auction end height\n * @category AENS\n * @param name - Name to compute auction end for\n * @param claimHeight - Auction starting height\n * @see {@link https://github.com/aeternity/aeternity/blob/72e440b8731422e335f879a31ecbbee7ac23a1cf/apps/aecore/src/aec_governance.erl#L273}\n * @returns Auction end height\n */\nexport function computeAuctionEndBlock(name: AensName, claimHeight: number): number {\n const length = name.length - AENS_SUFFIX.length;\n const h = (length <= 4 && 62 * NAME_BID_TIMEOUT_BLOCKS)\n || (length <= 8 && 31 * NAME_BID_TIMEOUT_BLOCKS)\n || (length <= 12 && NAME_BID_TIMEOUT_BLOCKS)\n || 0;\n return h + claimHeight;\n}\n\n/**\n * Is name accept going to auction\n * @category AENS\n */\nexport function isAuctionName(name: AensName): boolean {\n return name.length < 13 + AENS_SUFFIX.length;\n}\n"],"mappings":";;;;AAAA,OAAOA,SAAP,MAAsB,cAAtB;SACSC,O,EAASC,I;SAEhBC,M,EAAQC,M,EAAiBC,Q;SAElBC,O;SACAC,a;SAGPC,e,EACAC,uB,EACAC,sB,EACAC,mB;SAEOC,I;SACAC,a,EAAeC,kB;SAEfC,M,EAAQC,O;AAEjB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CACLC,OADK,EAELC,KAFK,EAGoB;EACzB,MAAMC,eAAe,GAAG,QAAOC,IAAP,CAAY,CAAC,GAAGlB,MAAM,CAACe,OAAD,CAAV,EAAqB,GAAGZ,OAAO,CAACa,KAAD,CAA/B,CAAZ,CAAxB;;EACA,MAAMG,OAAO,GAAGpB,IAAI,CAACkB,eAAD,CAApB;EACA,OAAOhB,MAAM,CAACkB,OAAD,EAAUjB,QAAQ,CAACkB,eAAnB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AAF;IAAYC,SAAS,GAAGhE;EAAxB,CAEW,uEADsD,EACtD;EACX,IAAI,EAAEiE,MAAM,CAACD,SAAD,CAAN,KAAsBA,SAAtB,IAAmCA,SAAS,GAAG,CAAZ,KAAkB,CAAvD,CAAJ,EAA+D,MAAM,IAAI5D,kBAAJ,CAAwB,8CAA6C4D,SAAU,EAA/E,CAAN;EAC/D,IAAIA,SAAS,GAAGhE,sBAAhB,EAAwC,MAAM,IAAII,kBAAJ,CAAwB,mCAAkCJ,sBAAuB,EAAjF,CAAN,CAF7B,CAGX;;EACA,OAAOE,IAAI,CACT,IAAIZ,SAAJ,CAAcyE,QAAd,aAAcA,QAAd,cAAcA,QAAd,GAA0BL,iBAAiB,CAAC9B,IAAD,CAA3C,EACGsC,KADH,CACS,IAAI5E,SAAJ,CAAcU,sBAAd,EAAsCmE,IAAtC,CAA2C,CAA3C,CADT,CADS,CAAX;AAID;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,sBAAT,CAAgCxC,IAAhC,EAAgDyC,WAAhD,EAA6E;EAClF,MAAMhD,MAAM,GAAGO,IAAI,CAACP,MAAL,GAAcsB,WAAW,CAACtB,MAAzC;EACA,MAAMiD,CAAC,GAAIjD,MAAM,IAAI,CAAV,IAAe,KAAKtB,uBAArB,IACJsB,MAAM,IAAI,CAAV,IAAe,KAAKtB,uBADhB,IAEJsB,MAAM,IAAI,EAAV,IAAgBtB,uBAFZ,IAGL,CAHL;EAIA,OAAOuE,CAAC,GAAGD,WAAX;AACD;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASE,aAAT,CAAuB3C,IAAvB,EAAgD;EACrD,OAAOA,IAAI,CAACP,MAAL,GAAc,KAAKsB,WAAW,CAACtB,MAAtC;AACD"}
|
package/es/tx/builder/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { EncodedData, EncodingType } from './../../utils/encoder';
|
|
2
1
|
import { NestedUint8Array } from 'rlp';
|
|
2
|
+
import { Encoded, Encoding } from '../../utils/encoder';
|
|
3
3
|
import { AE_AMOUNT_FORMATS } from '../../utils/amount-formatter';
|
|
4
|
-
import { RawTxObject, TxField,
|
|
4
|
+
import { RawTxObject, TxField, TxSchema, TxTypeSchemas } from './schema';
|
|
5
|
+
import { Tag } from './constants';
|
|
5
6
|
/**
|
|
6
7
|
* Validate transaction params
|
|
8
|
+
* @category transaction builder
|
|
7
9
|
* @param params - Object with tx params
|
|
8
10
|
* @param schema - Transaction schema
|
|
9
11
|
* @param excludeKeys - Array of keys to exclude for validation
|
|
@@ -14,19 +16,24 @@ export declare function validateParams(params: any, schema: TxField[], { exclude
|
|
|
14
16
|
}): object;
|
|
15
17
|
/**
|
|
16
18
|
* Unpack binary transaction
|
|
19
|
+
* @category transaction builder
|
|
17
20
|
* @param binary - Array with binary transaction field's
|
|
18
21
|
* @param schema - Transaction schema
|
|
19
22
|
* @returns Object with transaction field's
|
|
20
23
|
*/
|
|
21
24
|
export declare function unpackRawTx<Tx extends TxSchema>(binary: Uint8Array | NestedUint8Array, schema: TxField[]): RawTxObject<Tx>;
|
|
22
|
-
|
|
23
|
-
|
|
25
|
+
/**
|
|
26
|
+
* @category transaction builder
|
|
27
|
+
*/
|
|
28
|
+
export interface BuiltTx<Tx extends TxSchema, Prefix extends Encoding> {
|
|
29
|
+
tx: Encoded.Generic<Prefix>;
|
|
24
30
|
rlpEncoded: Uint8Array;
|
|
25
31
|
binary: Uint8Array;
|
|
26
32
|
txObject: RawTxObject<Tx>;
|
|
27
33
|
}
|
|
28
34
|
/**
|
|
29
35
|
* Build transaction hash
|
|
36
|
+
* @category transaction builder
|
|
30
37
|
* @param _params - Object with tx params
|
|
31
38
|
* @param type - Transaction type
|
|
32
39
|
* @param options - options
|
|
@@ -39,37 +46,43 @@ export interface BuiltTx<Tx extends TxSchema, Prefix extends EncodingType> {
|
|
|
39
46
|
* @returns object.rlpEncoded rlp encoded transaction
|
|
40
47
|
* @returns object.binary binary transaction
|
|
41
48
|
*/
|
|
42
|
-
export declare function buildTx<TxType extends
|
|
49
|
+
export declare function buildTx<TxType extends Tag, Prefix>(_params: Omit<TxTypeSchemas[TxType], 'tag' | 'VSN'> & {
|
|
43
50
|
VSN?: number;
|
|
44
|
-
}, type: TxType, { excludeKeys, prefix, vsn, denomination }?: {
|
|
51
|
+
}, type: TxType, { excludeKeys, prefix, vsn, denomination, }?: {
|
|
45
52
|
excludeKeys?: string[];
|
|
46
|
-
prefix?:
|
|
53
|
+
prefix?: Encoding;
|
|
47
54
|
vsn?: number;
|
|
48
55
|
denomination?: AE_AMOUNT_FORMATS;
|
|
49
|
-
}): BuiltTx<TxSchema, Prefix extends
|
|
56
|
+
}): BuiltTx<TxSchema, Prefix extends Encoding ? Prefix : Encoding.Transaction>;
|
|
57
|
+
/**
|
|
58
|
+
* @category transaction builder
|
|
59
|
+
*/
|
|
50
60
|
export interface TxUnpacked<Tx extends TxSchema> {
|
|
51
|
-
txType:
|
|
61
|
+
txType: Tag;
|
|
52
62
|
tx: RawTxObject<Tx>;
|
|
53
63
|
rlpEncoded: Uint8Array;
|
|
54
64
|
}
|
|
55
65
|
/**
|
|
56
66
|
* Unpack transaction hash
|
|
67
|
+
* @category transaction builder
|
|
57
68
|
* @param encodedTx - Transaction to unpack
|
|
58
69
|
* @param txType - Expected transaction type
|
|
59
70
|
* @returns object
|
|
60
71
|
* @returns object.tx Object with transaction param's
|
|
61
72
|
* @returns object.txType Transaction type
|
|
62
73
|
*/
|
|
63
|
-
export declare function unpackTx<TxType extends
|
|
74
|
+
export declare function unpackTx<TxType extends Tag>(encodedTx: Encoded.Transaction | Encoded.Poi, txType?: TxType): TxUnpacked<TxTypeSchemas[TxType]>;
|
|
64
75
|
/**
|
|
65
76
|
* Build a transaction hash
|
|
77
|
+
* @category transaction builder
|
|
66
78
|
* @param rawTx - base64 or rlp encoded transaction
|
|
67
79
|
* @returns Transaction hash
|
|
68
80
|
*/
|
|
69
|
-
export declare function buildTxHash(rawTx:
|
|
81
|
+
export declare function buildTxHash(rawTx: Encoded.Transaction | Uint8Array): Encoded.TxHash;
|
|
70
82
|
/**
|
|
71
83
|
* Build a contract public key by contractCreateTx or gaAttach
|
|
84
|
+
* @category contract
|
|
72
85
|
* @param contractTx - Transaction
|
|
73
86
|
* @returns Contract public key
|
|
74
87
|
*/
|
|
75
|
-
export declare function buildContractIdByContractTx(contractTx:
|
|
88
|
+
export declare function buildContractIdByContractTx(contractTx: Encoded.Transaction): Encoded.ContractAddress;
|