@aeternity/aepp-sdk 9.0.1 → 11.0.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 +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.mjs +179 -0
- package/es/account/base.mjs.map +1 -0
- package/es/account/memory.mjs +99 -0
- package/es/account/memory.mjs.map +1 -0
- package/es/account/multiple.mjs +179 -0
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/aens.mjs +404 -0
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/index.mjs +207 -0
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/oracle.mjs +339 -0
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +29 -9
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/node.mjs +442 -0
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/handlers.mjs +1110 -0
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +245 -472
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.mjs +283 -0
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/index.mjs +178 -0
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/index.mjs +188 -0
- package/es/node-pool/index.mjs.map +1 -0
- package/es/node.mjs +133 -0
- package/es/node.mjs.map +1 -0
- package/es/other.d.ts +1 -1
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +363 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.mjs +606 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.mjs +760 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +107 -15
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/tx-object.mjs +283 -0
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/tx.mjs +938 -0
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/validator.mjs +247 -0
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/amount-formatter.mjs +139 -0
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/async-init.mjs +64 -0
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/bignumber.mjs +21 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -12
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/crypto.mjs +239 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.mjs +111 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.mjs +45 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.mjs +240 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/mptree.mjs +161 -0
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.mjs +43 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/semver-satisfies.mjs +16 -0
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/{string.js → string.mjs} +5 -14
- package/es/utils/string.mjs.map +1 -0
- package/es/utils/swagger.mjs +164 -0
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +55 -62
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +31 -22
- package/src/ae/aens.js +75 -77
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +27 -291
- package/src/ae/index.js +9 -7
- package/src/ae/oracle.js +51 -28
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -67
- package/src/channel/handlers.js +30 -21
- package/src/channel/index.js +44 -20
- package/src/channel/internal.js +30 -24
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +41 -91
- package/src/contract/ga/helpers.js +10 -13
- package/src/contract/ga/index.js +42 -33
- package/src/index.js +9 -10
- package/src/node-pool/index.js +29 -17
- package/src/node.js +33 -36
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +126 -84
- package/src/tx/builder/index.js +83 -41
- package/src/tx/builder/schema.js +50 -40
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +232 -153
- package/src/tx/validator.js +34 -12
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +3 -10
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +10 -144
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +75 -45
- package/es/account/base.js +0 -259
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -86
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -267
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -829
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -985
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -442
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -690
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js +0 -1119
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js +0 -1601
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -438
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -517
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -742
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -316
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -120
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -307
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -204
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -228
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -355
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -686
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -695
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -297
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -1757
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -344
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js +0 -148
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -103
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js +0 -152
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -103
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -36
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js +0 -358
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -148
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -78
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -393
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js +0 -198
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -93
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js +0 -35
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -269
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/helpers.js +0 -140
- package/src/contract/aci/index.js +0 -191
- package/src/contract/aci/transformation.js +0 -464
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -110
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import * as R from 'ramda'
|
|
2
1
|
import BigNumber from 'bignumber.js'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
decodeBase58Check,
|
|
6
|
-
decodeBase64Check,
|
|
7
|
-
encodeBase58Check, encodeBase64Check,
|
|
8
|
-
hash,
|
|
9
|
-
salt
|
|
10
|
-
} from '../../utils/crypto'
|
|
2
|
+
import bs58 from 'bs58'
|
|
3
|
+
import { hash, salt, sha256hash } from '../../utils/crypto'
|
|
11
4
|
import { toBytes } from '../../utils/bytes'
|
|
12
5
|
import {
|
|
13
6
|
ID_TAG_PREFIX,
|
|
14
7
|
PREFIX_ID_TAG,
|
|
15
8
|
NAME_BID_RANGES,
|
|
16
|
-
NAME_BID_MAX_LENGTH,
|
|
17
|
-
NAME_FEE,
|
|
18
9
|
NAME_FEE_BID_INCREMENT,
|
|
19
10
|
NAME_BID_TIMEOUTS,
|
|
20
11
|
NAME_MAX_LENGTH_FEE,
|
|
21
|
-
|
|
12
|
+
POINTER_KEY_BY_PREFIX
|
|
22
13
|
} from './schema'
|
|
23
14
|
import { ceil } from '../../utils/bignumber'
|
|
15
|
+
import {
|
|
16
|
+
PrefixMismatchError,
|
|
17
|
+
DecodeError,
|
|
18
|
+
EncodeError,
|
|
19
|
+
PayloadLengthError,
|
|
20
|
+
TagNotFoundError,
|
|
21
|
+
PrefixNotFoundError,
|
|
22
|
+
InvalidNameError,
|
|
23
|
+
IllegalBidFeeError,
|
|
24
|
+
NoDefaultAensPointerError,
|
|
25
|
+
ArgumentError,
|
|
26
|
+
InvalidChecksumError
|
|
27
|
+
} from '../../utils/errors'
|
|
24
28
|
|
|
25
29
|
/**
|
|
26
30
|
* JavaScript-based Transaction builder helper function's
|
|
@@ -31,8 +35,6 @@ import { ceil } from '../../utils/bignumber'
|
|
|
31
35
|
|
|
32
36
|
export const createSalt = salt
|
|
33
37
|
|
|
34
|
-
const base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba']
|
|
35
|
-
|
|
36
38
|
/**
|
|
37
39
|
* Build a contract public key
|
|
38
40
|
* @function
|
|
@@ -78,11 +80,11 @@ export function formatSalt (salt) {
|
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
/**
|
|
81
|
-
* Encode
|
|
83
|
+
* Encode an AENS name
|
|
82
84
|
* @function
|
|
83
85
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
84
86
|
* @param {String} name Name to encode
|
|
85
|
-
* @return {String} `nm_` prefixed encoded
|
|
87
|
+
* @return {String} `nm_` prefixed encoded AENS name
|
|
86
88
|
*/
|
|
87
89
|
export function produceNameId (name) {
|
|
88
90
|
ensureNameValid(name)
|
|
@@ -103,24 +105,72 @@ export function produceNameId (name) {
|
|
|
103
105
|
*/
|
|
104
106
|
export function commitmentHash (name, salt = createSalt()) {
|
|
105
107
|
ensureNameValid(name)
|
|
106
|
-
return
|
|
108
|
+
return encode(hash(Buffer.concat([Buffer.from(name.toLowerCase()), formatSalt(salt)])), 'cm')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// based on https://github.com/aeternity/protocol/blob/master/node/api/api_encoding.md
|
|
112
|
+
const base64Types = ['ba', 'cb', 'or', 'ov', 'pi', 'ss', 'cs', 'ck', 'cv', 'st', 'tx']
|
|
113
|
+
const base58Types = ['ak', 'bf', 'bs', 'bx', 'ch', 'cm', 'ct', 'kh', 'mh', 'nm', 'ok', 'oq', 'pp', 'sg', 'th']
|
|
114
|
+
// TODO: add all types with a fixed length
|
|
115
|
+
const typesLength = {
|
|
116
|
+
ak: 32,
|
|
117
|
+
ct: 32,
|
|
118
|
+
ok: 32
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function ensureValidLength (data, type) {
|
|
122
|
+
if (!typesLength[type]) return
|
|
123
|
+
if (data.length === typesLength[type]) return
|
|
124
|
+
throw new PayloadLengthError(`Payload should be ${typesLength[type]} bytes, got ${data.length} instead`)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const getChecksum = payload => sha256hash(sha256hash(payload)).slice(0, 4)
|
|
128
|
+
|
|
129
|
+
const addChecksum = (input) => {
|
|
130
|
+
const payload = Buffer.from(input)
|
|
131
|
+
return Buffer.concat([payload, getChecksum(payload)])
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function getPayload (buffer) {
|
|
135
|
+
const payload = buffer.slice(0, -4)
|
|
136
|
+
if (!getChecksum(payload).equals(buffer.slice(-4))) throw new InvalidChecksumError()
|
|
137
|
+
return payload
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const base64 = {
|
|
141
|
+
encode: buffer => addChecksum(buffer).toString('base64'),
|
|
142
|
+
decode: string => getPayload(Buffer.from(string, 'base64'))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const base58 = {
|
|
146
|
+
encode: buffer => bs58.encode(addChecksum(buffer)),
|
|
147
|
+
decode: string => getPayload(bs58.decode(string))
|
|
107
148
|
}
|
|
108
149
|
|
|
109
150
|
/**
|
|
110
151
|
* Decode data using the default encoding/decoding algorithm
|
|
111
152
|
* @function
|
|
112
153
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
113
|
-
* @param {string} data An
|
|
154
|
+
* @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
|
|
114
155
|
* @param {string} [requiredPrefix] Ensure that data have this prefix
|
|
115
156
|
* @return {Buffer} Decoded data
|
|
116
157
|
*/
|
|
117
158
|
export function decode (data, requiredPrefix) {
|
|
118
|
-
|
|
119
|
-
|
|
159
|
+
if (typeof data !== 'string') throw new DecodeError(`Encoded should be a string, got ${data} instead`)
|
|
160
|
+
const [prefix, encodedPayload, extra] = data.split('_')
|
|
161
|
+
if (!encodedPayload) throw new DecodeError(`Encoded string missing payload: ${data}`)
|
|
162
|
+
if (extra) throw new DecodeError(`Encoded string have extra parts: ${data}`)
|
|
120
163
|
if (requiredPrefix && requiredPrefix !== prefix) {
|
|
121
|
-
throw new
|
|
164
|
+
throw new PrefixMismatchError(prefix, requiredPrefix)
|
|
122
165
|
}
|
|
123
|
-
|
|
166
|
+
const decoder = (base64Types.includes(prefix) && base64.decode) ||
|
|
167
|
+
(base58Types.includes(prefix) && base58.decode)
|
|
168
|
+
if (!decoder) {
|
|
169
|
+
throw new DecodeError(`Encoded string have unknown type: ${prefix}`)
|
|
170
|
+
}
|
|
171
|
+
const payload = decoder(encodedPayload)
|
|
172
|
+
ensureValidLength(payload, prefix)
|
|
173
|
+
return payload
|
|
124
174
|
}
|
|
125
175
|
|
|
126
176
|
/**
|
|
@@ -132,9 +182,13 @@ export function decode (data, requiredPrefix) {
|
|
|
132
182
|
* @return {String} Encoded string Base58check or Base64check data
|
|
133
183
|
*/
|
|
134
184
|
export function encode (data, type) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
185
|
+
const encoder = (base64Types.includes(type) && base64.encode) ||
|
|
186
|
+
(base58Types.includes(type) && base58.encode)
|
|
187
|
+
if (!encoder) {
|
|
188
|
+
throw new EncodeError(`Unknown type: ${type}`)
|
|
189
|
+
}
|
|
190
|
+
ensureValidLength(data, type)
|
|
191
|
+
return `${type}_${encoder(data)}`
|
|
138
192
|
}
|
|
139
193
|
|
|
140
194
|
/**
|
|
@@ -145,9 +199,10 @@ export function encode (data, type) {
|
|
|
145
199
|
* @return {Buffer} Buffer Buffer with ID tag and decoded HASh
|
|
146
200
|
*/
|
|
147
201
|
export function writeId (hashId) {
|
|
202
|
+
if (typeof hashId !== 'string') throw new ArgumentError('hashId', 'a string', hashId)
|
|
148
203
|
const prefix = hashId.slice(0, 2)
|
|
149
204
|
const idTag = PREFIX_ID_TAG[prefix]
|
|
150
|
-
if (!idTag) throw new
|
|
205
|
+
if (!idTag) throw new TagNotFoundError(prefix)
|
|
151
206
|
return Buffer.from([...toBytes(idTag), ...decode(hashId, prefix)])
|
|
152
207
|
}
|
|
153
208
|
|
|
@@ -159,9 +214,9 @@ export function writeId (hashId) {
|
|
|
159
214
|
* @return {String} Encoided hash string with prefix
|
|
160
215
|
*/
|
|
161
216
|
export function readId (buf) {
|
|
162
|
-
const tag = buf.readUIntBE(0, 1)
|
|
217
|
+
const tag = Buffer.from(buf).readUIntBE(0, 1)
|
|
163
218
|
const prefix = ID_TAG_PREFIX[tag]
|
|
164
|
-
if (!prefix) throw new
|
|
219
|
+
if (!prefix) throw new PrefixNotFoundError(tag)
|
|
165
220
|
return encode(buf.slice(1, buf.length), prefix)
|
|
166
221
|
}
|
|
167
222
|
|
|
@@ -184,14 +239,15 @@ export function writeInt (val) {
|
|
|
184
239
|
* @return {String} Buffer Buffer from number(BigEndian)
|
|
185
240
|
*/
|
|
186
241
|
export function readInt (buf = Buffer.from([])) {
|
|
187
|
-
return BigNumber(buf.toString('hex'), 16).toString(10)
|
|
242
|
+
return new BigNumber(Buffer.from(buf).toString('hex'), 16).toString(10)
|
|
188
243
|
}
|
|
189
244
|
|
|
190
245
|
/**
|
|
191
246
|
* Helper function to build pointers for name update TX
|
|
192
247
|
* @function
|
|
193
248
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
194
|
-
* @param {Array} pointers - Array of pointers
|
|
249
|
+
* @param {Array} pointers - Array of pointers
|
|
250
|
+
* ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
195
251
|
* @return {Array} Serialized pointers array
|
|
196
252
|
*/
|
|
197
253
|
export function buildPointers (pointers) {
|
|
@@ -207,7 +263,8 @@ export function buildPointers (pointers) {
|
|
|
207
263
|
* Helper function to read pointers from name update TX
|
|
208
264
|
* @function
|
|
209
265
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
210
|
-
* @param {Array} pointers - Array of pointers
|
|
266
|
+
* @param {Array} pointers - Array of pointers
|
|
267
|
+
* ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
211
268
|
* @return {Array} Deserialize pointer array
|
|
212
269
|
*/
|
|
213
270
|
export function readPointers (pointers) {
|
|
@@ -219,8 +276,10 @@ export function readPointers (pointers) {
|
|
|
219
276
|
)
|
|
220
277
|
}
|
|
221
278
|
|
|
279
|
+
const AENS_SUFFIX = '.chain'
|
|
280
|
+
|
|
222
281
|
/**
|
|
223
|
-
* Ensure that name is valid
|
|
282
|
+
* Ensure that AENS name is valid
|
|
224
283
|
* @function
|
|
225
284
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
226
285
|
* @param {string} name
|
|
@@ -228,12 +287,12 @@ export function readPointers (pointers) {
|
|
|
228
287
|
* @throws Error
|
|
229
288
|
*/
|
|
230
289
|
export function ensureNameValid (name) {
|
|
231
|
-
if (!name || typeof name !== 'string') throw new
|
|
232
|
-
if (!name.endsWith(
|
|
290
|
+
if (!name || typeof name !== 'string') throw new InvalidNameError('Name must be a string')
|
|
291
|
+
if (!name.endsWith(AENS_SUFFIX)) throw new InvalidNameError(`Name should end with ${AENS_SUFFIX}: ${name}`)
|
|
233
292
|
}
|
|
234
293
|
|
|
235
294
|
/**
|
|
236
|
-
* Is name valid
|
|
295
|
+
* Is AENS name valid
|
|
237
296
|
* @function
|
|
238
297
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
239
298
|
* @param {string} name
|
|
@@ -249,63 +308,44 @@ export function isNameValid (name) {
|
|
|
249
308
|
}
|
|
250
309
|
|
|
251
310
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
255
|
-
* @param s - the hash.
|
|
256
|
-
* returns the type, or throws an exception if type not found.
|
|
311
|
+
* @param identifier - account/oracle/contract address, or channel
|
|
312
|
+
* @returns {String} default AENS pointer key
|
|
313
|
+
* @throws exception when default key not defined
|
|
257
314
|
*/
|
|
258
|
-
export function
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
const klass = s.substr(0, 2)
|
|
264
|
-
if (klass in NAME_ID_KEY) {
|
|
265
|
-
return NAME_ID_KEY[klass]
|
|
266
|
-
} else {
|
|
267
|
-
throw new Error(`Unknown class ${klass}`)
|
|
268
|
-
}
|
|
315
|
+
export function getDefaultPointerKey (identifier) {
|
|
316
|
+
decode(identifier)
|
|
317
|
+
const prefix = identifier.substr(0, 2)
|
|
318
|
+
return POINTER_KEY_BY_PREFIX[prefix] ||
|
|
319
|
+
(() => { throw new NoDefaultAensPointerError(prefix) })()
|
|
269
320
|
}
|
|
270
321
|
|
|
271
322
|
/**
|
|
272
|
-
*
|
|
323
|
+
* Get the minimum AENS name fee
|
|
273
324
|
* @function
|
|
274
325
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
275
|
-
* @param {String
|
|
276
|
-
* @return {
|
|
326
|
+
* @param {String} name the AENS name to get the fee for
|
|
327
|
+
* @return {String} the minimum fee for the AENS name auction
|
|
277
328
|
*/
|
|
278
|
-
export function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Get the minimum name fee for a domain
|
|
285
|
-
* @function
|
|
286
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
287
|
-
* @param {String} domain the domain name to get the fee for
|
|
288
|
-
* @return {String} the minimum fee for the domain auction
|
|
289
|
-
*/
|
|
290
|
-
export function getMinimumNameFee (domain) {
|
|
291
|
-
const nameLength = domain.replace('.chain', '').length
|
|
292
|
-
return NAME_BID_RANGES[nameLength >= NAME_MAX_LENGTH_FEE ? NAME_MAX_LENGTH_FEE : nameLength]
|
|
329
|
+
export function getMinimumNameFee (name) {
|
|
330
|
+
ensureNameValid(name)
|
|
331
|
+
const nameLength = name.length - AENS_SUFFIX.length
|
|
332
|
+
return NAME_BID_RANGES[Math.min(nameLength, NAME_MAX_LENGTH_FEE)]
|
|
293
333
|
}
|
|
294
334
|
|
|
295
335
|
/**
|
|
296
336
|
* Compute bid fee for AENS auction
|
|
297
337
|
* @function
|
|
298
338
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
299
|
-
* @param {String}
|
|
339
|
+
* @param {String} name the AENS name to get the fee for
|
|
300
340
|
* @param {Number|String} startFee Auction start fee
|
|
301
341
|
* @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1)
|
|
302
342
|
* @return {String} Bid fee
|
|
303
343
|
*/
|
|
304
|
-
export function computeBidFee (
|
|
305
|
-
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new
|
|
306
|
-
if (increment < NAME_FEE_BID_INCREMENT) throw new
|
|
344
|
+
export function computeBidFee (name, startFee, increment = NAME_FEE_BID_INCREMENT) {
|
|
345
|
+
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new IllegalBidFeeError(`Increment must be float. Current increment ${increment}`)
|
|
346
|
+
if (increment < NAME_FEE_BID_INCREMENT) throw new IllegalBidFeeError(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)
|
|
307
347
|
return ceil(
|
|
308
|
-
BigNumber(
|
|
348
|
+
BigNumber(startFee ?? getMinimumNameFee(name)).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))
|
|
309
349
|
)
|
|
310
350
|
}
|
|
311
351
|
|
|
@@ -313,26 +353,28 @@ export function computeBidFee (domain, startFee = NAME_FEE, increment = NAME_FEE
|
|
|
313
353
|
* Compute auction end height
|
|
314
354
|
* @function
|
|
315
355
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
316
|
-
* @param {String}
|
|
356
|
+
* @param {String} name
|
|
317
357
|
* @param {Number|String} claimHeight Auction starting height
|
|
318
358
|
* @return {String} Auction end height
|
|
319
359
|
*/
|
|
320
|
-
export function computeAuctionEndBlock (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
[
|
|
326
|
-
|
|
360
|
+
export function computeAuctionEndBlock (name, claimHeight) {
|
|
361
|
+
ensureNameValid(name)
|
|
362
|
+
const length = name.length - AENS_SUFFIX.length
|
|
363
|
+
const h = (length <= 4 && NAME_BID_TIMEOUTS[4]) ||
|
|
364
|
+
(length <= 8 && NAME_BID_TIMEOUTS[8]) ||
|
|
365
|
+
(length <= 12 && NAME_BID_TIMEOUTS[12]) ||
|
|
366
|
+
NAME_BID_TIMEOUTS[13]
|
|
367
|
+
return h.plus(claimHeight).toString(10)
|
|
327
368
|
}
|
|
328
369
|
|
|
329
370
|
/**
|
|
330
371
|
* Is name accept going to auction
|
|
331
372
|
* @function
|
|
332
373
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
333
|
-
* @param {String} name
|
|
374
|
+
* @param {String} name
|
|
334
375
|
* @return {Boolean}
|
|
335
376
|
*/
|
|
336
377
|
export function isAuctionName (name) {
|
|
337
|
-
|
|
378
|
+
ensureNameValid(name)
|
|
379
|
+
return name.length < 13 + AENS_SUFFIX.length
|
|
338
380
|
}
|
package/src/tx/builder/index.js
CHANGED
|
@@ -2,18 +2,17 @@ import BigNumber from 'bignumber.js'
|
|
|
2
2
|
import { decode as rlpDecode, encode as rlpEncode } from 'rlp'
|
|
3
3
|
import { AE_AMOUNT_FORMATS, formatAmount } from '../../utils/amount-formatter'
|
|
4
4
|
import { hash } from '../../utils/crypto'
|
|
5
|
+
import { Field } from './field-types'
|
|
5
6
|
|
|
6
7
|
import {
|
|
7
8
|
DEFAULT_FEE,
|
|
8
9
|
FIELD_TYPES,
|
|
9
10
|
OBJECT_ID_TX_TYPE,
|
|
10
|
-
PREFIX_ID_TAG,
|
|
11
11
|
TX_DESERIALIZATION_SCHEMA,
|
|
12
12
|
TX_FEE_BASE_GAS,
|
|
13
13
|
TX_FEE_OTHER_GAS,
|
|
14
14
|
TX_SERIALIZATION_SCHEMA,
|
|
15
15
|
TX_TYPE,
|
|
16
|
-
VALIDATION_MESSAGE,
|
|
17
16
|
VSN
|
|
18
17
|
} from './schema'
|
|
19
18
|
import {
|
|
@@ -28,6 +27,7 @@ import {
|
|
|
28
27
|
} from './helpers'
|
|
29
28
|
import { toBytes } from '../../utils/bytes'
|
|
30
29
|
import MPTree from '../../utils/mptree'
|
|
30
|
+
import { InvalidTxParamsError, SchemaNotFoundError } from '../../utils/errors'
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* JavaScript-based Transaction builder
|
|
@@ -50,7 +50,6 @@ function deserializeField (value, type, prefix) {
|
|
|
50
50
|
return { vmVersion: readInt(Buffer.from([vm])), abiVersion: readInt(Buffer.from([abi])) }
|
|
51
51
|
}
|
|
52
52
|
case FIELD_TYPES.amount:
|
|
53
|
-
return readInt(value)
|
|
54
53
|
case FIELD_TYPES.int:
|
|
55
54
|
return readInt(value)
|
|
56
55
|
case FIELD_TYPES.id:
|
|
@@ -99,11 +98,12 @@ function deserializeField (value, type, prefix) {
|
|
|
99
98
|
{}
|
|
100
99
|
)
|
|
101
100
|
default:
|
|
101
|
+
if (type.prototype instanceof Field) return type.deserialize(value)
|
|
102
102
|
return value
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
function serializeField (value, type, prefix) {
|
|
106
|
+
function serializeField (value, type, prefix, params) {
|
|
107
107
|
switch (type) {
|
|
108
108
|
case FIELD_TYPES.amount:
|
|
109
109
|
case FIELD_TYPES.int:
|
|
@@ -144,44 +144,55 @@ function serializeField (value, type, prefix) {
|
|
|
144
144
|
default: return value
|
|
145
145
|
}
|
|
146
146
|
default:
|
|
147
|
+
if (type.prototype instanceof Field) return type.serialize(value, params)
|
|
147
148
|
return value
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
|
|
151
|
-
function validateField (value,
|
|
152
|
-
const assert = (valid, params) => valid ? {} : { [key]: VALIDATION_MESSAGE[type](params) }
|
|
152
|
+
function validateField (value, type, prefix) {
|
|
153
153
|
// All fields are required
|
|
154
|
-
if (value === undefined || value === null) return
|
|
154
|
+
if (value === undefined || value === null) return 'Field is required'
|
|
155
155
|
|
|
156
156
|
// Validate type of value
|
|
157
157
|
switch (type) {
|
|
158
158
|
case FIELD_TYPES.amount:
|
|
159
159
|
case FIELD_TYPES.int: {
|
|
160
|
-
|
|
161
|
-
|
|
160
|
+
if (isNaN(value) && !BigNumber.isBigNumber(value)) {
|
|
161
|
+
return `${value} is not of type Number or BigNumber`
|
|
162
|
+
}
|
|
163
|
+
if (new BigNumber(value).lt(0)) return `${value} must be >= 0`
|
|
164
|
+
return
|
|
162
165
|
}
|
|
163
166
|
case FIELD_TYPES.id: {
|
|
164
167
|
const prefixes = Array.isArray(prefix) ? prefix : [prefix]
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
if (!prefixes.includes(value.split('_')[0])) {
|
|
169
|
+
return `'${value}' prefix doesn't match expected prefix '${prefix}'`
|
|
170
|
+
}
|
|
171
|
+
return
|
|
167
172
|
}
|
|
168
|
-
case FIELD_TYPES.binary:
|
|
169
|
-
return assert(value.split('_')[0] === prefix, { prefix, value })
|
|
170
|
-
case FIELD_TYPES.string:
|
|
171
|
-
return assert(true)
|
|
172
173
|
case FIELD_TYPES.ctVersion:
|
|
173
|
-
|
|
174
|
+
if (!value?.abiVersion || !value?.vmVersion) {
|
|
175
|
+
return 'Value must be an object with "vmVersion" and "abiVersion" fields'
|
|
176
|
+
}
|
|
177
|
+
return
|
|
174
178
|
case FIELD_TYPES.pointers:
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
179
|
+
if (!Array.isArray(value)) return 'Value must be of type Array'
|
|
180
|
+
if (value.some(p => !p?.key || !p?.id)) {
|
|
181
|
+
return 'Value must contains only object\'s like \'{key: "account_pubkey", id: "ak_lkamsflkalsdalksdlasdlasdlamd"}\''
|
|
182
|
+
}
|
|
183
|
+
if (value.length > 32) {
|
|
184
|
+
return `Expected 32 pointers or less, got ${value.length} instead`
|
|
185
|
+
}
|
|
178
186
|
}
|
|
179
187
|
}
|
|
180
188
|
|
|
181
189
|
function transformParams (params, schema, { denomination } = {}) {
|
|
182
190
|
params = schema
|
|
183
191
|
.filter(([_, t]) => t === FIELD_TYPES.amount)
|
|
184
|
-
.reduce(
|
|
192
|
+
.reduce(
|
|
193
|
+
(acc, [key]) => ({ ...params, [key]: formatAmount(params[key], { denomination }) }),
|
|
194
|
+
params
|
|
195
|
+
)
|
|
185
196
|
const schemaKeys = schema.map(([k]) => k)
|
|
186
197
|
return Object
|
|
187
198
|
.entries(params)
|
|
@@ -256,7 +267,8 @@ function buildFee (txType, { params, gas = 0, multiplier, vsn }) {
|
|
|
256
267
|
.plus(TX_FEE_OTHER_GAS(txType, txSize, {
|
|
257
268
|
relativeTtl: getOracleRelativeTtl(params, txType),
|
|
258
269
|
innerTxSize: [TX_TYPE.gaMeta, TX_TYPE.payingFor].includes(txType)
|
|
259
|
-
? params.tx.tx.encodedTx.rlpEncoded.length
|
|
270
|
+
? params.tx.tx.encodedTx.rlpEncoded.length
|
|
271
|
+
: 0
|
|
260
272
|
}))
|
|
261
273
|
.times(multiplier)
|
|
262
274
|
}
|
|
@@ -290,12 +302,14 @@ export function calculateFee (fee = 0, txType, { gas = 0, params, showWarning =
|
|
|
290
302
|
* @return {Object} Object with validation errors
|
|
291
303
|
*/
|
|
292
304
|
export function validateParams (params, schema, { excludeKeys = [] }) {
|
|
293
|
-
return
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
(
|
|
297
|
-
|
|
298
|
-
|
|
305
|
+
return Object.fromEntries(
|
|
306
|
+
schema
|
|
307
|
+
// TODO: allow optional keys in schema
|
|
308
|
+
.filter(([key]) => !excludeKeys.includes(key) &&
|
|
309
|
+
!['payload', 'nameFee', 'deposit'].includes(key))
|
|
310
|
+
.map(([key, type, prefix]) => [key, validateField(params[key], type, prefix)])
|
|
311
|
+
.filter(([, message]) => message)
|
|
312
|
+
)
|
|
299
313
|
}
|
|
300
314
|
|
|
301
315
|
/**
|
|
@@ -305,12 +319,16 @@ export function validateParams (params, schema, { excludeKeys = [] }) {
|
|
|
305
319
|
* @param {Object} params Object with tx params
|
|
306
320
|
* @param {Array} schema Transaction schema
|
|
307
321
|
* @param {Object} [options={}] options
|
|
308
|
-
* @param {
|
|
309
|
-
* @param {String} [options.denomination='aettos']
|
|
322
|
+
* @param {String[]} [options.excludeKeys=[]] Array of keys to exclude for validation and build
|
|
323
|
+
* @param {String} [options.denomination='aettos'] Denomination of amounts
|
|
310
324
|
* @throws {Error} Validation error
|
|
311
325
|
* @return {Array} Array with binary fields of transaction
|
|
312
326
|
*/
|
|
313
|
-
export function buildRawTx (
|
|
327
|
+
export function buildRawTx (
|
|
328
|
+
params,
|
|
329
|
+
schema,
|
|
330
|
+
{ excludeKeys = [], denomination = AE_AMOUNT_FORMATS.AETTOS } = {}
|
|
331
|
+
) {
|
|
314
332
|
const filteredSchema = schema.filter(([key]) => !excludeKeys.includes(key))
|
|
315
333
|
|
|
316
334
|
// Transform `amount` type fields to `aettos`
|
|
@@ -318,11 +336,11 @@ export function buildRawTx (params, schema, { excludeKeys = [], denomination = A
|
|
|
318
336
|
// Validation
|
|
319
337
|
const valid = validateParams(params, schema, { excludeKeys })
|
|
320
338
|
if (Object.keys(valid).length) {
|
|
321
|
-
throw new
|
|
339
|
+
throw new InvalidTxParamsError('Transaction build error. ' + JSON.stringify(valid))
|
|
322
340
|
}
|
|
323
341
|
|
|
324
342
|
return filteredSchema
|
|
325
|
-
.map(([key, fieldType, prefix]) => serializeField(params[key], fieldType, prefix))
|
|
343
|
+
.map(([key, fieldType, prefix]) => serializeField(params[key], fieldType, prefix, params))
|
|
326
344
|
}
|
|
327
345
|
|
|
328
346
|
/**
|
|
@@ -358,10 +376,10 @@ const getSchema = ({ vsn, objId, type }) => {
|
|
|
358
376
|
const schema = isDeserialize ? TX_DESERIALIZATION_SCHEMA : TX_SERIALIZATION_SCHEMA
|
|
359
377
|
|
|
360
378
|
if (!schema[firstKey]) {
|
|
361
|
-
throw new
|
|
379
|
+
throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type}`)
|
|
362
380
|
}
|
|
363
381
|
if (!schema[firstKey][vsn]) {
|
|
364
|
-
throw new
|
|
382
|
+
throw new SchemaNotFoundError(`Transaction ${isDeserialize ? 'deserialization' : 'serialization'} not implemented for ${isDeserialize ? 'tag ' + objId : type} version ${vsn}`)
|
|
365
383
|
}
|
|
366
384
|
return schema[firstKey][vsn]
|
|
367
385
|
}
|
|
@@ -373,14 +391,25 @@ const getSchema = ({ vsn, objId, type }) => {
|
|
|
373
391
|
* @param {Object} params Object with tx params
|
|
374
392
|
* @param {String} type Transaction type
|
|
375
393
|
* @param {Object} [options={}] options
|
|
376
|
-
* @param {
|
|
394
|
+
* @param {String[]} [options.excludeKeys] Array of keys to exclude for validation and build
|
|
377
395
|
* @param {String} [options.prefix] Prefix of transaction
|
|
378
396
|
* @throws {Error} Validation error
|
|
379
|
-
* @
|
|
397
|
+
* @returns {Object} object
|
|
398
|
+
* @returns {String} object.tx Base64Check transaction hash with 'tx_' prefix
|
|
399
|
+
* @returns {Buffer} object.rlpEncoded rlp encoded transaction
|
|
400
|
+
* @returns {Array<Buffer>} object.binary binary transaction
|
|
380
401
|
*/
|
|
381
|
-
export function buildTx (
|
|
402
|
+
export function buildTx (
|
|
403
|
+
params,
|
|
404
|
+
type,
|
|
405
|
+
{ excludeKeys = [], prefix = 'tx', vsn = VSN, denomination = AE_AMOUNT_FORMATS.AETTOS } = {}
|
|
406
|
+
) {
|
|
382
407
|
const [schema, tag] = getSchema({ type, vsn })
|
|
383
|
-
const binary = buildRawTx(
|
|
408
|
+
const binary = buildRawTx(
|
|
409
|
+
{ ...params, VSN: vsn, tag },
|
|
410
|
+
schema,
|
|
411
|
+
{ excludeKeys, denomination: params.denomination || denomination }
|
|
412
|
+
).filter(e => e !== undefined)
|
|
384
413
|
|
|
385
414
|
const rlpEncoded = rlpEncode(binary)
|
|
386
415
|
const tx = encode(rlpEncoded, prefix)
|
|
@@ -392,10 +421,14 @@ export function buildTx (params, type, { excludeKeys = [], prefix = 'tx', vsn =
|
|
|
392
421
|
* Unpack transaction hash
|
|
393
422
|
* @function
|
|
394
423
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder
|
|
395
|
-
* @param {String|Buffer} encodedTx String or RLP encoded transaction array
|
|
424
|
+
* @param {String|Buffer} encodedTx String or RLP encoded transaction array
|
|
425
|
+
* (if fromRlpBinary flag is true)
|
|
396
426
|
* @param {Boolean} fromRlpBinary Unpack from RLP encoded transaction (default: false)
|
|
397
427
|
* @param {String} prefix - Prefix of data
|
|
398
|
-
* @
|
|
428
|
+
* @returns {Object} object
|
|
429
|
+
* @returns {Object} object.tx Object with transaction param's
|
|
430
|
+
* @returns {Buffer} object.rlpEncoded rlp encoded transaction
|
|
431
|
+
* @returns {Array<Buffer>} object.binary binary transaction
|
|
399
432
|
*/
|
|
400
433
|
export function unpackTx (encodedTx, fromRlpBinary = false, prefix = 'tx') {
|
|
401
434
|
const rlpEncoded = fromRlpBinary ? encodedTx : decode(encodedTx, prefix)
|
|
@@ -420,4 +453,13 @@ export function buildTxHash (rawTx) {
|
|
|
420
453
|
return encode(hash(data), 'th')
|
|
421
454
|
}
|
|
422
455
|
|
|
423
|
-
export default {
|
|
456
|
+
export default {
|
|
457
|
+
calculateMinFee,
|
|
458
|
+
calculateFee,
|
|
459
|
+
unpackTx,
|
|
460
|
+
unpackRawTx,
|
|
461
|
+
buildTx,
|
|
462
|
+
buildRawTx,
|
|
463
|
+
validateParams,
|
|
464
|
+
buildTxHash
|
|
465
|
+
}
|