@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
package/es/tx/builder/helpers.js
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
import _T from "ramda/src/T";
|
|
2
|
-
import _lte from "ramda/src/lte";
|
|
3
|
-
import _always from "ramda/src/always";
|
|
4
|
-
import _lt from "ramda/src/lt";
|
|
5
|
-
import _cond from "ramda/src/cond";
|
|
6
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
7
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
8
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
9
|
-
import _padStartInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/pad-start";
|
|
10
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
11
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
12
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
13
|
-
import _Object$assign from "@babel/runtime-corejs3/core-js-stable/object/assign";
|
|
14
|
-
import _endsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/ends-with";
|
|
15
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
16
|
-
import BigNumber from 'bignumber.js';
|
|
17
|
-
import { decodeBase58Check, decodeBase64Check, encodeBase58Check, encodeBase64Check, hash, salt } from '../../utils/crypto';
|
|
18
|
-
import { toBytes } from '../../utils/bytes';
|
|
19
|
-
import { ID_TAG_PREFIX, PREFIX_ID_TAG, NAME_BID_RANGES, NAME_BID_MAX_LENGTH, NAME_FEE, NAME_FEE_BID_INCREMENT, NAME_BID_TIMEOUTS, NAME_MAX_LENGTH_FEE, NAME_ID_KEY } from './schema';
|
|
20
|
-
import { ceil } from '../../utils/bignumber';
|
|
21
|
-
/**
|
|
22
|
-
* JavaScript-based Transaction builder helper function's
|
|
23
|
-
* @module @aeternity/aepp-sdk/es/tx/builder/helpers
|
|
24
|
-
* @export TxBuilderHelper
|
|
25
|
-
* @example import { TxBuilderHelper } from '@aeternity/aepp-sdk'
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
export var createSalt = salt;
|
|
29
|
-
var base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba'];
|
|
30
|
-
/**
|
|
31
|
-
* Build a contract public key
|
|
32
|
-
* @function
|
|
33
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
34
|
-
* @param {string} ownerId The public key of the owner account
|
|
35
|
-
* @param {number} nonce the nonce of the transaction
|
|
36
|
-
* @return {string} Contract public key
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
export function buildContractId(ownerId, nonce) {
|
|
40
|
-
var _context;
|
|
41
|
-
|
|
42
|
-
var ownerIdAndNonce = Buffer.from(_concatInstanceProperty(_context = []).call(_context, _toConsumableArray(decode(ownerId, 'ak')), _toConsumableArray(toBytes(nonce))));
|
|
43
|
-
var b2bHash = hash(ownerIdAndNonce);
|
|
44
|
-
return encode(b2bHash, 'ct');
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Build a oracle query id
|
|
48
|
-
* @function
|
|
49
|
-
* @function* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
50
|
-
* @param {String} senderId The public key of the sender account
|
|
51
|
-
* @param {Number} nonce the nonce of the transaction
|
|
52
|
-
* @param {Number} oracleId The oracle public key
|
|
53
|
-
* @return {string} Contract public key
|
|
54
|
-
*/
|
|
55
|
-
|
|
56
|
-
export function oracleQueryId(senderId, nonce, oracleId) {
|
|
57
|
-
var _context2;
|
|
58
|
-
|
|
59
|
-
function _int32(val) {
|
|
60
|
-
var nonceBE = toBytes(val, true);
|
|
61
|
-
return _concatInstanceProperty(Buffer).call(Buffer, [Buffer.alloc(32 - nonceBE.length), nonceBE]);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
var b2bHash = hash(Buffer.from(_concatInstanceProperty(_context2 = []).call(_context2, _toConsumableArray(decode(senderId, 'ak')), _toConsumableArray(_int32(nonce)), _toConsumableArray(decode(oracleId, 'ok')))));
|
|
65
|
-
return encode(b2bHash, 'oq');
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Format the salt into a 64-byte hex string
|
|
69
|
-
* @function
|
|
70
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
71
|
-
* @param {number} salt
|
|
72
|
-
* @return {string} Zero-padded hex string of salt
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
|
-
export function formatSalt(salt) {
|
|
76
|
-
var _context3;
|
|
77
|
-
|
|
78
|
-
return Buffer.from(_padStartInstanceProperty(_context3 = salt.toString(16)).call(_context3, 64, '0'), 'hex');
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Encode a domain name
|
|
82
|
-
* @function
|
|
83
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
84
|
-
* @param {String} name Name to encode
|
|
85
|
-
* @return {String} `nm_` prefixed encoded domain name
|
|
86
|
-
*/
|
|
87
|
-
|
|
88
|
-
export function produceNameId(name) {
|
|
89
|
-
ensureNameValid(name);
|
|
90
|
-
return encode(hash(name.toLowerCase()), 'nm');
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Generate the commitment hash by hashing the formatted salt and
|
|
94
|
-
* name, base 58 encoding the result and prepending 'cm_'
|
|
95
|
-
*
|
|
96
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
97
|
-
* @function commitmentHash
|
|
98
|
-
* @category async
|
|
99
|
-
* @rtype (name: String, salt?: String) => hash: Promise[String]
|
|
100
|
-
* @param {String} name - Name to be registered
|
|
101
|
-
* @param {Number} salt Random salt
|
|
102
|
-
* @return {String} Commitment hash
|
|
103
|
-
*/
|
|
104
|
-
|
|
105
|
-
export function commitmentHash(name) {
|
|
106
|
-
var salt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : createSalt();
|
|
107
|
-
ensureNameValid(name);
|
|
108
|
-
return "cm_".concat(encodeBase58Check(hash(_concatInstanceProperty(Buffer).call(Buffer, [Buffer.from(name.toLowerCase()), formatSalt(salt)]))));
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Decode data using the default encoding/decoding algorithm
|
|
112
|
-
* @function
|
|
113
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
114
|
-
* @param {string} data An Base58check or Base64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
|
|
115
|
-
* @param {string} [requiredPrefix] Ensure that data have this prefix
|
|
116
|
-
* @return {Buffer} Decoded data
|
|
117
|
-
*/
|
|
118
|
-
|
|
119
|
-
export function decode(data, requiredPrefix) {
|
|
120
|
-
var _data$split = data.split('_'),
|
|
121
|
-
_data$split2 = _slicedToArray(_data$split, 3),
|
|
122
|
-
prefix = _data$split2[0],
|
|
123
|
-
payload = _data$split2[1],
|
|
124
|
-
extra = _data$split2[2];
|
|
125
|
-
|
|
126
|
-
if (extra) throw new Error("Encoded string have extra parts: ".concat(data));
|
|
127
|
-
|
|
128
|
-
if (requiredPrefix && requiredPrefix !== prefix) {
|
|
129
|
-
var _context4;
|
|
130
|
-
|
|
131
|
-
throw new Error(_concatInstanceProperty(_context4 = "Encoded string have a wrong type: ".concat(prefix, " (expected: ")).call(_context4, requiredPrefix, ")"));
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
return (_includesInstanceProperty(base64Types).call(base64Types, prefix) ? decodeBase64Check : decodeBase58Check)(payload);
|
|
135
|
-
}
|
|
136
|
-
/**
|
|
137
|
-
* Encode data using the default encoding/decoding algorithm
|
|
138
|
-
* @function
|
|
139
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
140
|
-
* @param {Buffer|String} data An decoded data
|
|
141
|
-
* @param {string} type Prefix of Transaction
|
|
142
|
-
* @return {String} Encoded string Base58check or Base64check data
|
|
143
|
-
*/
|
|
144
|
-
|
|
145
|
-
export function encode(data, type) {
|
|
146
|
-
var _context5;
|
|
147
|
-
|
|
148
|
-
return _concatInstanceProperty(_context5 = "".concat(type, "_")).call(_context5, _includesInstanceProperty(base64Types).call(base64Types, type) ? encodeBase64Check(data) : encodeBase58Check(data));
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Utility function to create and _id type
|
|
152
|
-
* @function
|
|
153
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
154
|
-
* @param {string} hashId Encoded hash
|
|
155
|
-
* @return {Buffer} Buffer Buffer with ID tag and decoded HASh
|
|
156
|
-
*/
|
|
157
|
-
|
|
158
|
-
export function writeId(hashId) {
|
|
159
|
-
var _context6;
|
|
160
|
-
|
|
161
|
-
var prefix = _sliceInstanceProperty(hashId).call(hashId, 0, 2);
|
|
162
|
-
|
|
163
|
-
var idTag = PREFIX_ID_TAG[prefix];
|
|
164
|
-
if (!idTag) throw new Error("Id tag for prefix ".concat(prefix, " not found."));
|
|
165
|
-
return Buffer.from(_concatInstanceProperty(_context6 = []).call(_context6, _toConsumableArray(toBytes(idTag)), _toConsumableArray(decode(hashId, prefix))));
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Utility function to read and _id type
|
|
169
|
-
* @function
|
|
170
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
171
|
-
* @param {Buffer} buf Data
|
|
172
|
-
* @return {String} Encoided hash string with prefix
|
|
173
|
-
*/
|
|
174
|
-
|
|
175
|
-
export function readId(buf) {
|
|
176
|
-
var tag = buf.readUIntBE(0, 1);
|
|
177
|
-
var prefix = ID_TAG_PREFIX[tag];
|
|
178
|
-
if (!prefix) throw new Error("Prefix for id-tag ".concat(tag, " not found."));
|
|
179
|
-
return encode(_sliceInstanceProperty(buf).call(buf, 1, buf.length), prefix);
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Utility function to convert int to bytes
|
|
183
|
-
* @function
|
|
184
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
185
|
-
* @param {Number|String|BigNumber} val Value
|
|
186
|
-
* @return {Buffer} Buffer Buffer from number(BigEndian)
|
|
187
|
-
*/
|
|
188
|
-
|
|
189
|
-
export function writeInt(val) {
|
|
190
|
-
return toBytes(val, true);
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Utility function to convert bytes to int
|
|
194
|
-
* @function
|
|
195
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
196
|
-
* @param {Buffer} buf Value
|
|
197
|
-
* @return {String} Buffer Buffer from number(BigEndian)
|
|
198
|
-
*/
|
|
199
|
-
|
|
200
|
-
export function readInt() {
|
|
201
|
-
var buf = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : Buffer.from([]);
|
|
202
|
-
return BigNumber(buf.toString('hex'), 16).toString(10);
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Helper function to build pointers for name update TX
|
|
206
|
-
* @function
|
|
207
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
208
|
-
* @param {Array} pointers - Array of pointers ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
209
|
-
* @return {Array} Serialized pointers array
|
|
210
|
-
*/
|
|
211
|
-
|
|
212
|
-
export function buildPointers(pointers) {
|
|
213
|
-
return _mapInstanceProperty(pointers).call(pointers, function (p) {
|
|
214
|
-
return [toBytes(p.key), writeId(p.id)];
|
|
215
|
-
});
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* Helper function to read pointers from name update TX
|
|
219
|
-
* @function
|
|
220
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
221
|
-
* @param {Array} pointers - Array of pointers ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
222
|
-
* @return {Array} Deserialize pointer array
|
|
223
|
-
*/
|
|
224
|
-
|
|
225
|
-
export function readPointers(pointers) {
|
|
226
|
-
return _mapInstanceProperty(pointers).call(pointers, function (_ref) {
|
|
227
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
228
|
-
key = _ref2[0],
|
|
229
|
-
id = _ref2[1];
|
|
230
|
-
|
|
231
|
-
return _Object$assign({
|
|
232
|
-
key: key.toString(),
|
|
233
|
-
id: readId(id)
|
|
234
|
-
});
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Ensure that name is valid
|
|
239
|
-
* @function
|
|
240
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
241
|
-
* @param {string} name
|
|
242
|
-
* @return void
|
|
243
|
-
* @throws Error
|
|
244
|
-
*/
|
|
245
|
-
|
|
246
|
-
export function ensureNameValid(name) {
|
|
247
|
-
if (!name || typeof name !== 'string') throw new Error('Name must be a string');
|
|
248
|
-
if (!_endsWithInstanceProperty(name).call(name, '.chain')) throw new Error("Name should end with .chain: ".concat(name));
|
|
249
|
-
}
|
|
250
|
-
/**
|
|
251
|
-
* Is name valid
|
|
252
|
-
* @function
|
|
253
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
254
|
-
* @param {string} name
|
|
255
|
-
* @return Boolean
|
|
256
|
-
*/
|
|
257
|
-
|
|
258
|
-
export function isNameValid(name) {
|
|
259
|
-
try {
|
|
260
|
-
ensureNameValid(name);
|
|
261
|
-
return true;
|
|
262
|
-
} catch (error) {
|
|
263
|
-
return false;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* What kind of a hash is this? If it begins with 'ak_' it is an
|
|
268
|
-
* account key, if with 'ok_' it's an oracle key.
|
|
269
|
-
*
|
|
270
|
-
* @param s - the hash.
|
|
271
|
-
* returns the type, or throws an exception if type not found.
|
|
272
|
-
*/
|
|
273
|
-
|
|
274
|
-
export function classify(s) {
|
|
275
|
-
if (!s.match(/^[a-z]{2}_.+/)) {
|
|
276
|
-
throw new Error('Not a valid hash');
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
var klass = s.substr(0, 2);
|
|
280
|
-
|
|
281
|
-
if (klass in NAME_ID_KEY) {
|
|
282
|
-
return NAME_ID_KEY[klass];
|
|
283
|
-
} else {
|
|
284
|
-
throw new Error("Unknown class ".concat(klass));
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Validate name pointers array
|
|
289
|
-
* @function
|
|
290
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
291
|
-
* @param {String[]} pointers Pointers array. Allowed values is: account(ak_), oracle(ok_), contract(ct_), channel(ch_)
|
|
292
|
-
* @return {Boolean}
|
|
293
|
-
*/
|
|
294
|
-
|
|
295
|
-
export function validatePointers() {
|
|
296
|
-
var pointers = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
297
|
-
return !_findInstanceProperty(pointers).call(pointers, function (p) {
|
|
298
|
-
var _context7;
|
|
299
|
-
|
|
300
|
-
return !p || typeof p !== 'string' || !_includesInstanceProperty(_context7 = ['ak', 'ok', 'ct', 'ch']).call(_context7, p.split('_')[0]);
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
/**
|
|
304
|
-
* Get the minimum name fee for a domain
|
|
305
|
-
* @function
|
|
306
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
307
|
-
* @param {String} domain the domain name to get the fee for
|
|
308
|
-
* @return {String} the minimum fee for the domain auction
|
|
309
|
-
*/
|
|
310
|
-
|
|
311
|
-
export function getMinimumNameFee(domain) {
|
|
312
|
-
var nameLength = domain.replace('.chain', '').length;
|
|
313
|
-
return NAME_BID_RANGES[nameLength >= NAME_MAX_LENGTH_FEE ? NAME_MAX_LENGTH_FEE : nameLength];
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* Compute bid fee for AENS auction
|
|
317
|
-
* @function
|
|
318
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
319
|
-
* @param {String} domain the domain name to get the fee for
|
|
320
|
-
* @param {Number|String} startFee Auction start fee
|
|
321
|
-
* @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1)
|
|
322
|
-
* @return {String} Bid fee
|
|
323
|
-
*/
|
|
324
|
-
|
|
325
|
-
export function computeBidFee(domain) {
|
|
326
|
-
var startFee = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : NAME_FEE;
|
|
327
|
-
var increment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : NAME_FEE_BID_INCREMENT;
|
|
328
|
-
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error("Increment must be float. Current increment ".concat(increment));
|
|
329
|
-
if (increment < NAME_FEE_BID_INCREMENT) throw new Error("minimum increment percentage is ".concat(NAME_FEE_BID_INCREMENT));
|
|
330
|
-
return ceil(BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(domain) : startFee).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1)));
|
|
331
|
-
}
|
|
332
|
-
/**
|
|
333
|
-
* Compute auction end height
|
|
334
|
-
* @function
|
|
335
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
336
|
-
* @param {String} domain the domain name to get the fee for
|
|
337
|
-
* @param {Number|String} claimHeight Auction starting height
|
|
338
|
-
* @return {String} Auction end height
|
|
339
|
-
*/
|
|
340
|
-
|
|
341
|
-
export function computeAuctionEndBlock(domain, claimHeight) {
|
|
342
|
-
return _cond([[_lt(5), _always(NAME_BID_TIMEOUTS[4].plus(claimHeight))], [_lt(9), _always(NAME_BID_TIMEOUTS[8].plus(claimHeight))], [_lte(NAME_BID_MAX_LENGTH), _always(NAME_BID_TIMEOUTS[12].plus(claimHeight))], [_T, _always(BigNumber(claimHeight))]])(domain.replace('.chain', '').length).toString(10);
|
|
343
|
-
}
|
|
344
|
-
/**
|
|
345
|
-
* Is name accept going to auction
|
|
346
|
-
* @function
|
|
347
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
348
|
-
* @param {String} name Transaction abiVersion
|
|
349
|
-
* @return {Boolean}
|
|
350
|
-
*/
|
|
351
|
-
|
|
352
|
-
export function isAuctionName(name) {
|
|
353
|
-
return name.replace('.chain', '').length < 13;
|
|
354
|
-
}
|
|
355
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/tx/builder/helpers.js"],"names":["BigNumber","decodeBase58Check","decodeBase64Check","encodeBase58Check","encodeBase64Check","hash","salt","toBytes","ID_TAG_PREFIX","PREFIX_ID_TAG","NAME_BID_RANGES","NAME_BID_MAX_LENGTH","NAME_FEE","NAME_FEE_BID_INCREMENT","NAME_BID_TIMEOUTS","NAME_MAX_LENGTH_FEE","NAME_ID_KEY","ceil","createSalt","base64Types","buildContractId","ownerId","nonce","ownerIdAndNonce","Buffer","from","decode","b2bHash","encode","oracleQueryId","senderId","oracleId","_int32","val","nonceBE","alloc","length","formatSalt","toString","produceNameId","name","ensureNameValid","toLowerCase","commitmentHash","data","requiredPrefix","split","prefix","payload","extra","Error","type","writeId","hashId","idTag","readId","buf","tag","readUIntBE","writeInt","readInt","buildPointers","pointers","p","key","id","readPointers","isNameValid","error","classify","s","match","klass","substr","validatePointers","getMinimumNameFee","domain","nameLength","replace","computeBidFee","startFee","increment","Number","eq","times","plus","computeAuctionEndBlock","claimHeight","isAuctionName"],"mappings":";;;;;;;;;;;;;;;AACA,OAAOA,SAAP,MAAsB,cAAtB;AAEA,SACEC,iBADF,EAEEC,iBAFF,EAGEC,iBAHF,EAGqBC,iBAHrB,EAIEC,IAJF,EAKEC,IALF,QAMO,oBANP;AAOA,SAASC,OAAT,QAAwB,mBAAxB;AACA,SACEC,aADF,EAEEC,aAFF,EAGEC,eAHF,EAIEC,mBAJF,EAKEC,QALF,EAMEC,sBANF,EAOEC,iBAPF,EAQEC,mBARF,EASEC,WATF,QAUO,UAVP;AAWA,SAASC,IAAT,QAAqB,uBAArB;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,IAAMC,UAAU,GAAGZ,IAAnB;AAEP,IAAMa,WAAW,GAAG,CAAC,IAAD,EAAO,IAAP,EAAa,IAAb,EAAmB,IAAnB,EAAyB,IAAzB,EAA+B,IAA/B,EAAqC,IAArC,EAA2C,IAA3C,EAAiD,IAAjD,CAApB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,eAAT,CAA0BC,OAA1B,EAAmCC,KAAnC,EAA0C;AAAA;;AAC/C,MAAMC,eAAe,GAAGC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;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASkD,aAAT,CAAwBhD,IAAxB,EAA8B;AACnC,SAAOA,IAAI,CAACsC,OAAL,CAAa,QAAb,EAAuB,EAAvB,EAA2B1C,MAA3B,GAAoC,EAA3C;AACD","sourcesContent":["import * as R from 'ramda'\nimport BigNumber from 'bignumber.js'\n\nimport {\n decodeBase58Check,\n decodeBase64Check,\n encodeBase58Check, encodeBase64Check,\n hash,\n salt\n} from '../../utils/crypto'\nimport { toBytes } from '../../utils/bytes'\nimport {\n ID_TAG_PREFIX,\n PREFIX_ID_TAG,\n NAME_BID_RANGES,\n NAME_BID_MAX_LENGTH,\n NAME_FEE,\n NAME_FEE_BID_INCREMENT,\n NAME_BID_TIMEOUTS,\n NAME_MAX_LENGTH_FEE,\n NAME_ID_KEY\n} from './schema'\nimport { ceil } from '../../utils/bignumber'\n\n/**\n * JavaScript-based Transaction builder helper function's\n * @module @aeternity/aepp-sdk/es/tx/builder/helpers\n * @export TxBuilderHelper\n * @example import { TxBuilderHelper } from '@aeternity/aepp-sdk'\n */\n\nexport const createSalt = salt\n\nconst base64Types = ['tx', 'st', 'ss', 'pi', 'ov', 'or', 'cb', 'cs', 'ba']\n\n/**\n * Build a contract public key\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} ownerId The public key of the owner account\n * @param {number} nonce the nonce of the transaction\n * @return {string} Contract public key\n */\nexport function buildContractId (ownerId, nonce) {\n const ownerIdAndNonce = Buffer.from([...decode(ownerId, 'ak'), ...toBytes(nonce)])\n const b2bHash = hash(ownerIdAndNonce)\n return encode(b2bHash, 'ct')\n}\n\n/**\n * Build a oracle query id\n * @function\n * @function* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} senderId The public key of the sender account\n * @param {Number} nonce the nonce of the transaction\n * @param {Number} oracleId The oracle public key\n * @return {string} Contract public key\n */\nexport function oracleQueryId (senderId, nonce, oracleId) {\n function _int32 (val) {\n const nonceBE = toBytes(val, true)\n return Buffer.concat([Buffer.alloc(32 - nonceBE.length), nonceBE])\n }\n\n const b2bHash = hash(Buffer.from([...decode(senderId, 'ak'), ..._int32(nonce), ...decode(oracleId, 'ok')]))\n return encode(b2bHash, 'oq')\n}\n\n/**\n * Format the salt into a 64-byte hex string\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {number} salt\n * @return {string} Zero-padded hex string of salt\n */\nexport function formatSalt (salt) {\n return Buffer.from(salt.toString(16).padStart(64, '0'), 'hex')\n}\n\n/**\n * Encode a domain name\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} name Name to encode\n * @return {String} `nm_` prefixed encoded domain name\n */\nexport function produceNameId (name) {\n ensureNameValid(name)\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 * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @function commitmentHash\n * @category async\n * @rtype (name: String, salt?: String) => hash: Promise[String]\n * @param {String} name - Name to be registered\n * @param {Number} salt Random salt\n * @return {String} Commitment hash\n */\nexport function commitmentHash (name, salt = createSalt()) {\n ensureNameValid(name)\n return `cm_${encodeBase58Check(hash(Buffer.concat([Buffer.from(name.toLowerCase()), formatSalt(salt)])))}`\n}\n\n/**\n * Decode data using the default encoding/decoding algorithm\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} data An Base58check or Base64check encoded and prefixed string (ex tx_..., sg_..., ak_....)\n * @param {string} [requiredPrefix] Ensure that data have this prefix\n * @return {Buffer} Decoded data\n */\nexport function decode (data, requiredPrefix) {\n const [prefix, payload, extra] = data.split('_')\n if (extra) throw new Error(`Encoded string have extra parts: ${data}`)\n if (requiredPrefix && requiredPrefix !== prefix) {\n throw new Error(`Encoded string have a wrong type: ${prefix} (expected: ${requiredPrefix})`)\n }\n return (base64Types.includes(prefix) ? decodeBase64Check : decodeBase58Check)(payload)\n}\n\n/**\n * Encode data using the default encoding/decoding algorithm\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Buffer|String} data An decoded data\n * @param {string} type Prefix of Transaction\n * @return {String} Encoded string Base58check or Base64check data\n */\nexport function encode (data, type) {\n return `${type}_${base64Types.includes(type)\n ? encodeBase64Check(data)\n : encodeBase58Check(data)}`\n}\n\n/**\n * Utility function to create and _id type\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} hashId Encoded hash\n * @return {Buffer} Buffer Buffer with ID tag and decoded HASh\n */\nexport function writeId (hashId) {\n const prefix = hashId.slice(0, 2)\n const idTag = PREFIX_ID_TAG[prefix]\n if (!idTag) throw new Error(`Id tag for prefix ${prefix} not found.`)\n return Buffer.from([...toBytes(idTag), ...decode(hashId, prefix)])\n}\n\n/**\n * Utility function to read and _id type\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Buffer} buf Data\n * @return {String} Encoided hash string with prefix\n */\nexport function readId (buf) {\n const tag = buf.readUIntBE(0, 1)\n const prefix = ID_TAG_PREFIX[tag]\n if (!prefix) throw new Error(`Prefix for id-tag ${tag} not found.`)\n return encode(buf.slice(1, buf.length), prefix)\n}\n\n/**\n * Utility function to convert int to bytes\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Number|String|BigNumber} val Value\n * @return {Buffer} Buffer Buffer from number(BigEndian)\n */\nexport function writeInt (val) {\n return toBytes(val, true)\n}\n\n/**\n * Utility function to convert bytes to int\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Buffer} buf Value\n * @return {String} Buffer Buffer from number(BigEndian)\n */\nexport function readInt (buf = Buffer.from([])) {\n return BigNumber(buf.toString('hex'), 16).toString(10)\n}\n\n/**\n * Helper function to build pointers for name update TX\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Array} pointers - Array of pointers ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])\n * @return {Array} Serialized pointers array\n */\nexport function buildPointers (pointers) {\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 * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {Array} pointers - Array of pointers ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])\n * @return {Array} Deserialize pointer array\n */\nexport function readPointers (pointers) {\n return pointers.map(\n ([key, id]) => Object.assign({\n key: key.toString(),\n id: readId(id)\n })\n )\n}\n\n/**\n * Ensure that name is valid\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} name\n * @return void\n * @throws Error\n */\nexport function ensureNameValid (name) {\n if (!name || typeof name !== 'string') throw new Error('Name must be a string')\n if (!name.endsWith('.chain')) throw new Error(`Name should end with .chain: ${name}`)\n}\n\n/**\n * Is name valid\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {string} name\n * @return Boolean\n */\nexport function isNameValid (name) {\n try {\n ensureNameValid(name)\n return true\n } catch (error) {\n return false\n }\n}\n\n/**\n * What kind of a hash is this? If it begins with 'ak_' it is an\n * account key, if with 'ok_' it's an oracle key.\n *\n * @param s - the hash.\n * returns the type, or throws an exception if type not found.\n */\nexport function classify (s) {\n if (!s.match(/^[a-z]{2}_.+/)) {\n throw new Error('Not a valid hash')\n }\n\n const klass = s.substr(0, 2)\n if (klass in NAME_ID_KEY) {\n return NAME_ID_KEY[klass]\n } else {\n throw new Error(`Unknown class ${klass}`)\n }\n}\n\n/**\n * Validate name pointers array\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String[]} pointers Pointers array. Allowed values is: account(ak_), oracle(ok_), contract(ct_), channel(ch_)\n * @return {Boolean}\n */\nexport function validatePointers (pointers = []) {\n return !pointers\n .find(p => !p || typeof p !== 'string' || !['ak', 'ok', 'ct', 'ch'].includes(p.split('_')[0]))\n}\n\n/**\n * Get the minimum name fee for a domain\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} domain the domain name to get the fee for\n * @return {String} the minimum fee for the domain auction\n */\nexport function getMinimumNameFee (domain) {\n const nameLength = domain.replace('.chain', '').length\n return NAME_BID_RANGES[nameLength >= NAME_MAX_LENGTH_FEE ? NAME_MAX_LENGTH_FEE : nameLength]\n}\n\n/**\n * Compute bid fee for AENS auction\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} domain the domain name to get the fee for\n * @param {Number|String} startFee Auction start fee\n * @param {Number} [increment=0.5] Bid multiplier(In percentage, must be between 0 and 1)\n * @return {String} Bid fee\n */\nexport function computeBidFee (domain, startFee = NAME_FEE, increment = NAME_FEE_BID_INCREMENT) {\n if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error(`Increment must be float. Current increment ${increment}`)\n if (increment < NAME_FEE_BID_INCREMENT) throw new Error(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)\n return ceil(\n BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(domain) : startFee).times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))\n )\n}\n\n/**\n * Compute auction end height\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} domain the domain name to get the fee for\n * @param {Number|String} claimHeight Auction starting height\n * @return {String} Auction end height\n */\nexport function computeAuctionEndBlock (domain, claimHeight) {\n return R.cond([\n [R.lt(5), R.always(NAME_BID_TIMEOUTS[4].plus(claimHeight))],\n [R.lt(9), R.always(NAME_BID_TIMEOUTS[8].plus(claimHeight))],\n [R.lte(NAME_BID_MAX_LENGTH), R.always(NAME_BID_TIMEOUTS[12].plus(claimHeight))],\n [R.T, R.always(BigNumber(claimHeight))]\n ])(domain.replace('.chain', '').length).toString(10)\n}\n\n/**\n * Is name accept going to auction\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers\n * @param {String} name Transaction abiVersion\n * @return {Boolean}\n */\nexport function isAuctionName (name) {\n return name.replace('.chain', '').length < 13\n}\n"],"file":"helpers.js"}
|