@aeternity/aepp-sdk 8.2.1 → 10.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/CHANGELOG.md +216 -337
- package/README.md +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- 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.js +36 -120
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +238 -465
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +328 -495
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +131 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +41 -106
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- package/src/contract/aci/helpers.js +0 -140
package/src/contract/ga/index.js
CHANGED
|
@@ -22,13 +22,11 @@
|
|
|
22
22
|
* @export GeneralizeAccount
|
|
23
23
|
* @example import { GeneralizeAccount } from '@aeternity/aepp-sdk'
|
|
24
24
|
*/
|
|
25
|
-
import * as R from 'ramda'
|
|
26
|
-
|
|
27
25
|
import { ContractAPI } from '../../ae/contract'
|
|
28
26
|
import { TX_TYPE } from '../../tx/builder/schema'
|
|
29
|
-
import { buildTx } from '../../tx/builder'
|
|
30
|
-
import {
|
|
31
|
-
import {
|
|
27
|
+
import { buildTx, unpackTx } from '../../tx/builder'
|
|
28
|
+
import { prepareGaParams } from './helpers'
|
|
29
|
+
import { hash } from '../../utils/crypto'
|
|
32
30
|
|
|
33
31
|
/**
|
|
34
32
|
* GeneralizeAccount Stamp
|
|
@@ -47,7 +45,9 @@ import { assertedType, decodeBase64Check } from '../../utils/crypto'
|
|
|
47
45
|
* const callData = 'cb_...' // encoded call data for auth contract
|
|
48
46
|
* await client.spend(10000, receiverPub, { authData: { callData } })
|
|
49
47
|
* // or
|
|
50
|
-
* await client.spend(10000, receiverPub, {
|
|
48
|
+
* await client.spend(10000, receiverPub, {
|
|
49
|
+
* authData: { source: authContract, args: [...authContractArgs] }
|
|
50
|
+
* }) // sdk will prepare callData itself
|
|
51
51
|
*/
|
|
52
52
|
export const GeneralizeAccount = ContractAPI.compose({
|
|
53
53
|
methods: {
|
|
@@ -78,29 +78,36 @@ async function isGA (address) {
|
|
|
78
78
|
* @param {String} source - Auth contract source code
|
|
79
79
|
* @param {Array} [args] - init arguments
|
|
80
80
|
* @param {Object} [options] - Options
|
|
81
|
-
* @return {Promise<Readonly<{
|
|
81
|
+
* @return {Promise<Readonly<{
|
|
82
|
+
* result: *, owner: *, createdAt: Date, address, rawTx: *, transaction: *
|
|
83
|
+
* }>>}
|
|
82
84
|
*/
|
|
83
85
|
async function createGeneralizeAccount (authFnName, source, args = [], options = {}) {
|
|
84
|
-
const opt =
|
|
86
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
85
87
|
const ownerId = await this.address(opt)
|
|
86
88
|
|
|
87
89
|
if (await this.isGA(ownerId)) throw new Error(`Account ${ownerId} is already GA`)
|
|
88
90
|
|
|
89
|
-
const {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const { tx, contractId } = await this.gaAttachTx({
|
|
92
|
+
...opt,
|
|
93
|
+
ownerId,
|
|
94
|
+
code: (await this.contractCompile(source)).bytecode,
|
|
95
|
+
callData: await this.contractEncodeCallDataAPI(source, 'init', args),
|
|
96
|
+
authFun: hash(authFnName)
|
|
97
|
+
})
|
|
93
98
|
|
|
94
|
-
const { hash, rawTx } = await this.send(tx, opt)
|
|
99
|
+
const { hash: transaction, rawTx } = await this.send(tx, opt)
|
|
95
100
|
|
|
96
101
|
return Object.freeze({
|
|
97
102
|
owner: ownerId,
|
|
98
|
-
transaction
|
|
103
|
+
transaction,
|
|
99
104
|
rawTx,
|
|
100
105
|
gaContractId: contractId
|
|
101
106
|
})
|
|
102
107
|
}
|
|
103
108
|
|
|
109
|
+
const wrapInEmptySignedTx = (tx) => buildTx({ encodedTx: tx, signatures: [] }, TX_TYPE.signed)
|
|
110
|
+
|
|
104
111
|
/**
|
|
105
112
|
* Create a metaTx transaction
|
|
106
113
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
@@ -115,33 +122,26 @@ async function createMetaTx (rawTransaction, authData, authFnName, options = {})
|
|
|
115
122
|
if (!authData) throw new Error('authData is required')
|
|
116
123
|
// Check if authData is callData or if it's an object prepare a callData from source and args
|
|
117
124
|
const { authCallData, gas } = await prepareGaParams(this)(authData, authFnName)
|
|
118
|
-
const opt =
|
|
119
|
-
// Get transaction rlp binary
|
|
120
|
-
const rlpBinaryTx = decodeBase64Check(assertedType(rawTransaction, 'tx'))
|
|
121
|
-
// Wrap in SIGNED tx with empty signatures
|
|
122
|
-
const { rlpEncoded } = wrapInEmptySignedTx(rlpBinaryTx)
|
|
123
|
-
// Get abi
|
|
125
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
124
126
|
const { abiVersion } = await this.getVmVersion(TX_TYPE.contractCall)
|
|
125
|
-
|
|
127
|
+
const wrappedTx = wrapInEmptySignedTx(unpackTx(rawTransaction))
|
|
126
128
|
const params = {
|
|
127
129
|
...opt,
|
|
128
|
-
tx:
|
|
130
|
+
tx: {
|
|
131
|
+
...wrappedTx,
|
|
132
|
+
tx: wrappedTx.txObject
|
|
133
|
+
},
|
|
129
134
|
gaId: await this.address(opt),
|
|
130
135
|
abiVersion: abiVersion,
|
|
131
136
|
authData: authCallData,
|
|
132
137
|
gas,
|
|
133
138
|
vsn: 2
|
|
134
139
|
}
|
|
135
|
-
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
136
140
|
const { fee } = await this.prepareTxParams(TX_TYPE.gaMeta, params)
|
|
137
|
-
// Build META tx
|
|
138
141
|
const { rlpEncoded: metaTxRlp } = buildTx(
|
|
139
142
|
{ ...params, fee: `${fee}` },
|
|
140
143
|
TX_TYPE.gaMeta,
|
|
141
144
|
{ vsn: 2 }
|
|
142
145
|
)
|
|
143
|
-
|
|
144
|
-
const { tx } = wrapInEmptySignedTx(metaTxRlp)
|
|
145
|
-
// Send tx to the chain
|
|
146
|
-
return tx
|
|
146
|
+
return wrapInEmptySignedTx(metaTxRlp).tx
|
|
147
147
|
}
|
package/src/contract/index.js
CHANGED
|
@@ -85,7 +85,9 @@ const ContractBase = stampit(required({
|
|
|
85
85
|
* @instance
|
|
86
86
|
* @abstract
|
|
87
87
|
* @category async
|
|
88
|
-
* @rtype (
|
|
88
|
+
* @rtype (
|
|
89
|
+
* source: String, fn: String, callValue: String, callResult: String, options: Array
|
|
90
|
+
* ) => decodedResult: Promise[String]
|
|
89
91
|
* @param {String} source - Contract source
|
|
90
92
|
* @param {String} fn - Fn name
|
|
91
93
|
* @param {String} callValue - result data (cb_das...)
|
|
@@ -101,7 +103,9 @@ const ContractBase = stampit(required({
|
|
|
101
103
|
* @instance
|
|
102
104
|
* @abstract
|
|
103
105
|
* @category async
|
|
104
|
-
* @rtype (
|
|
106
|
+
* @rtype (
|
|
107
|
+
* source: String, function: String, callData: String, options: Array
|
|
108
|
+
* ) => decodedResult: Promise[String]
|
|
105
109
|
* @param {String} source - contract source
|
|
106
110
|
* @param {String} function - function name
|
|
107
111
|
* @param {String} callData - Encoded contract call data
|
package/src/index.js
CHANGED
|
@@ -21,7 +21,6 @@ import * as Bytes from './utils/bytes'
|
|
|
21
21
|
import * as TxBuilder from './tx/builder'
|
|
22
22
|
import * as TxBuilderHelper from './tx/builder/helpers'
|
|
23
23
|
import * as SCHEMA from './tx/builder/schema'
|
|
24
|
-
import * as ACIHelpers from './contract/aci/helpers'
|
|
25
24
|
import * as ACITransformation from './contract/aci/transformation'
|
|
26
25
|
import * as AmountFormatter from './utils/amount-formatter'
|
|
27
26
|
import HdWallet from './utils/hd-wallet'
|
|
@@ -33,7 +32,7 @@ import Node from './node'
|
|
|
33
32
|
import NodePool from './node-pool'
|
|
34
33
|
import Tx from './tx'
|
|
35
34
|
import Transaction from './tx/tx'
|
|
36
|
-
import
|
|
35
|
+
import verifyTransaction from './tx/validator'
|
|
37
36
|
import AccountBase from './account/base'
|
|
38
37
|
import AccountMultiple from './account/multiple'
|
|
39
38
|
import MemoryAccount from './account/memory'
|
|
@@ -55,6 +54,8 @@ export { default as WalletDetector } from './utils/aepp-wallet-communication/wal
|
|
|
55
54
|
export { default as BrowserRuntimeConnection } from './utils/aepp-wallet-communication/connection/browser-runtime'
|
|
56
55
|
export { default as BrowserWindowMessageConnection } from './utils/aepp-wallet-communication/connection/browser-window-message'
|
|
57
56
|
|
|
57
|
+
export const getDefaultPointerKey = TxBuilderHelper.getDefaultPointerKey
|
|
58
|
+
|
|
58
59
|
export {
|
|
59
60
|
AmountFormatter,
|
|
60
61
|
AccountBase,
|
|
@@ -64,7 +65,6 @@ export {
|
|
|
64
65
|
Bytes,
|
|
65
66
|
Contract,
|
|
66
67
|
ContractCompilerAPI,
|
|
67
|
-
ACIHelpers,
|
|
68
68
|
ACITransformation,
|
|
69
69
|
ChainNode,
|
|
70
70
|
RpcAepp,
|
|
@@ -81,7 +81,7 @@ export {
|
|
|
81
81
|
Oracle,
|
|
82
82
|
genSwaggerClient,
|
|
83
83
|
Transaction,
|
|
84
|
-
|
|
84
|
+
verifyTransaction,
|
|
85
85
|
Tx,
|
|
86
86
|
TxBuilder,
|
|
87
87
|
TxBuilderHelper,
|
package/src/node-pool/index.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
* @example import { NodePool } from '@aeternity/aepp-sdk'
|
|
6
6
|
*/
|
|
7
7
|
import stampit from '@stamp/it'
|
|
8
|
-
import Joi from 'joi-browser'
|
|
9
8
|
import { getNetworkId } from '../node'
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -52,7 +51,8 @@ export default stampit({
|
|
|
52
51
|
* @param {Boolean} select - Select this node as current
|
|
53
52
|
* @return {void}
|
|
54
53
|
* @example
|
|
55
|
-
*
|
|
54
|
+
* // add and select new node with name 'testNode'
|
|
55
|
+
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
|
|
56
56
|
*/
|
|
57
57
|
addNode (name, node, select = false) {
|
|
58
58
|
if (this.pool.has(name)) throw new Error(`Node with name ${name} already exist`)
|
|
@@ -141,17 +141,28 @@ export default stampit({
|
|
|
141
141
|
}))
|
|
142
142
|
},
|
|
143
143
|
validateNodes (nodes) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
144
|
+
// TODO: validate it on TypeScript level instead
|
|
145
|
+
// (to speedup development, save runtime resources)
|
|
146
|
+
if (!Array.isArray(nodes)) throw new Error('"nodes" should be an array')
|
|
147
|
+
const notObject = nodes.map(n => typeof n).find(t => t !== 'object')
|
|
148
|
+
if (notObject) throw new Error(`Each node should be an object, got ${notObject} instead`)
|
|
149
|
+
const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')
|
|
150
|
+
if (notObject) {
|
|
151
|
+
throw new Error(
|
|
152
|
+
'Each node should have name (string), instance (object) ' +
|
|
153
|
+
`fields, got ${JSON.stringify(wrongFields)} instead`
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
const wrongInstanceFields = nodes
|
|
157
|
+
.map(n => n.instance)
|
|
158
|
+
.find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||
|
|
159
|
+
typeof i.consensusProtocolVersion !== 'number')
|
|
160
|
+
if (wrongInstanceFields) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
'Each node instance should have api (object), consensusProtocolVersion (number), ' +
|
|
163
|
+
`genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`
|
|
164
|
+
)
|
|
165
|
+
}
|
|
155
166
|
}
|
|
156
167
|
},
|
|
157
168
|
props: {
|
package/src/node.js
CHANGED
|
@@ -34,29 +34,10 @@ import semverSatisfies from './utils/semver-satisfies'
|
|
|
34
34
|
* @return {String} NetworkId
|
|
35
35
|
*/
|
|
36
36
|
export function getNetworkId ({ networkId, force = false } = {}) {
|
|
37
|
-
|
|
38
|
-
if (force && !
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* get consensus protocol version
|
|
44
|
-
* @param {Array} protocols Array of protocols
|
|
45
|
-
* @param {Number} height Height
|
|
46
|
-
* @return {Number} version Protocol version
|
|
47
|
-
*/
|
|
48
|
-
async function getConsensusProtocolVersion (protocols = [], height) {
|
|
49
|
-
if (!protocols) throw new Error('Protocols must be an array')
|
|
50
|
-
if (!height) height = (await this.api.getCurrentKeyBlock()).height
|
|
51
|
-
if (height < 0) throw new Error('height must be a number >= 0')
|
|
52
|
-
|
|
53
|
-
return protocols
|
|
54
|
-
.filter(({ effectiveAtHeight }) => height >= effectiveAtHeight)
|
|
55
|
-
.reduce(
|
|
56
|
-
(acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,
|
|
57
|
-
{ effectiveAtHeight: -1, version: 0 }
|
|
58
|
-
)
|
|
59
|
-
.version
|
|
37
|
+
const res = networkId || this.networkId || this.selectedNode?.networkId
|
|
38
|
+
if (!force && !res) throw new Error('networkId is not provided')
|
|
39
|
+
if (force && !res) return null
|
|
40
|
+
return res
|
|
60
41
|
}
|
|
61
42
|
|
|
62
43
|
/**
|
|
@@ -67,7 +48,9 @@ async function getConsensusProtocolVersion (protocols = [], height) {
|
|
|
67
48
|
* @param {Object} [options={}] - Options
|
|
68
49
|
* @param {String} options.url - Base URL for Node
|
|
69
50
|
* @param {String} options.internalUrl - Base URL for internal requests
|
|
70
|
-
* @param {
|
|
51
|
+
* @param {Object} options.axiosConfig - Object with axios configuration
|
|
52
|
+
* @param {Object} options.axiosConfig.config
|
|
53
|
+
* @param {Function} options.axiosConfig.errorHandler - (err) => throw err
|
|
71
54
|
* @return {Object} Node client
|
|
72
55
|
* @example Node({url: 'https://testnet.aeternity.io'})
|
|
73
56
|
*/
|
|
@@ -76,7 +59,15 @@ const Node = AsyncInit.compose({
|
|
|
76
59
|
if (!url) throw new Error('"url" required')
|
|
77
60
|
this.url = url.replace(/\/$/, '')
|
|
78
61
|
this.internalUrl = internalUrl ? internalUrl.replace(/\/$/, '') : this.url
|
|
79
|
-
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
62
|
+
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
63
|
+
internalUrl: this.internalUrl,
|
|
64
|
+
responseInterceptor: response => {
|
|
65
|
+
if (response.ok) return
|
|
66
|
+
return Object.assign(response, {
|
|
67
|
+
statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
})
|
|
80
71
|
this.version = client.spec.info.version
|
|
81
72
|
if (
|
|
82
73
|
!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
|
|
@@ -89,8 +80,17 @@ const Node = AsyncInit.compose({
|
|
|
89
80
|
}
|
|
90
81
|
this.api = client.api
|
|
91
82
|
|
|
92
|
-
const {
|
|
93
|
-
|
|
83
|
+
const {
|
|
84
|
+
nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId,
|
|
85
|
+
protocols, topBlockHeight
|
|
86
|
+
} = await this.api.getStatus()
|
|
87
|
+
this.consensusProtocolVersion = protocols
|
|
88
|
+
.filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)
|
|
89
|
+
.reduce(
|
|
90
|
+
(acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,
|
|
91
|
+
{ effectiveAtHeight: -1, version: 0 }
|
|
92
|
+
)
|
|
93
|
+
.version
|
|
94
94
|
this.nodeNetworkId = networkId
|
|
95
95
|
return Object.assign(this, { revision, genesisHash })
|
|
96
96
|
},
|
|
@@ -103,8 +103,7 @@ const Node = AsyncInit.compose({
|
|
|
103
103
|
version: this.version,
|
|
104
104
|
consensusProtocolVersion: this.consensusProtocolVersion
|
|
105
105
|
}
|
|
106
|
-
}
|
|
107
|
-
getConsensusProtocolVersion
|
|
106
|
+
}
|
|
108
107
|
},
|
|
109
108
|
props: {
|
|
110
109
|
version: null,
|
|
@@ -113,7 +112,7 @@ const Node = AsyncInit.compose({
|
|
|
113
112
|
}
|
|
114
113
|
})
|
|
115
114
|
|
|
116
|
-
const NODE_GE_VERSION = '6.
|
|
115
|
+
const NODE_GE_VERSION = '6.2.0'
|
|
117
116
|
const NODE_LT_VERSION = '7.0.0'
|
|
118
117
|
|
|
119
118
|
export default Node
|
|
@@ -2,7 +2,6 @@ import * as R from 'ramda'
|
|
|
2
2
|
import BigNumber from 'bignumber.js'
|
|
3
3
|
|
|
4
4
|
import {
|
|
5
|
-
assertedType,
|
|
6
5
|
decodeBase58Check,
|
|
7
6
|
decodeBase64Check,
|
|
8
7
|
encodeBase58Check, encodeBase64Check,
|
|
@@ -18,7 +17,8 @@ import {
|
|
|
18
17
|
NAME_FEE,
|
|
19
18
|
NAME_FEE_BID_INCREMENT,
|
|
20
19
|
NAME_BID_TIMEOUTS,
|
|
21
|
-
|
|
20
|
+
NAME_MAX_LENGTH_FEE,
|
|
21
|
+
POINTER_KEY_BY_PREFIX
|
|
22
22
|
} from './schema'
|
|
23
23
|
import { ceil } from '../../utils/bignumber'
|
|
24
24
|
|
|
@@ -47,20 +47,6 @@ export function buildContractId (ownerId, nonce) {
|
|
|
47
47
|
return encode(b2bHash, 'ct')
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
/**
|
|
51
|
-
* Build hash
|
|
52
|
-
* @function
|
|
53
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
54
|
-
* @param {String} prefix Transaction hash prefix
|
|
55
|
-
* @param {Buffer} data Rlp encoded transaction buffer
|
|
56
|
-
* @param {Object} options
|
|
57
|
-
* @param {Boolean} options.raw
|
|
58
|
-
* @return {String} Transaction hash
|
|
59
|
-
*/
|
|
60
|
-
export function buildHash (prefix, data, options = {}) {
|
|
61
|
-
return options.raw ? hash(data) : encode(hash(data), prefix)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
50
|
/**
|
|
65
51
|
* Build a oracle query id
|
|
66
52
|
* @function
|
|
@@ -124,15 +110,18 @@ export function commitmentHash (name, salt = createSalt()) {
|
|
|
124
110
|
* Decode data using the default encoding/decoding algorithm
|
|
125
111
|
* @function
|
|
126
112
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
127
|
-
* @param {string} data
|
|
128
|
-
* @param {string}
|
|
129
|
-
* @return {Buffer}
|
|
113
|
+
* @param {string} data An Base58/64check encoded and prefixed string (ex tx_..., sg_..., ak_....)
|
|
114
|
+
* @param {string} [requiredPrefix] Ensure that data have this prefix
|
|
115
|
+
* @return {Buffer} Decoded data
|
|
130
116
|
*/
|
|
131
|
-
export function decode (data,
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
117
|
+
export function decode (data, requiredPrefix) {
|
|
118
|
+
const [prefix, payload, extra] = data.split('_')
|
|
119
|
+
if (!payload) throw new Error(`Encoded string missing payload: ${data}`)
|
|
120
|
+
if (extra) throw new Error(`Encoded string have extra parts: ${data}`)
|
|
121
|
+
if (requiredPrefix && requiredPrefix !== prefix) {
|
|
122
|
+
throw new Error(`Encoded string have a wrong type: ${prefix} (expected: ${requiredPrefix})`)
|
|
123
|
+
}
|
|
124
|
+
return (base64Types.includes(prefix) ? decodeBase64Check : decodeBase58Check)(payload)
|
|
136
125
|
}
|
|
137
126
|
|
|
138
127
|
/**
|
|
@@ -157,6 +146,9 @@ export function encode (data, type) {
|
|
|
157
146
|
* @return {Buffer} Buffer Buffer with ID tag and decoded HASh
|
|
158
147
|
*/
|
|
159
148
|
export function writeId (hashId) {
|
|
149
|
+
if (typeof hashId !== 'string') {
|
|
150
|
+
throw new Error(`Address should be a string, got ${hashId} instead`)
|
|
151
|
+
}
|
|
160
152
|
const prefix = hashId.slice(0, 2)
|
|
161
153
|
const idTag = PREFIX_ID_TAG[prefix]
|
|
162
154
|
if (!idTag) throw new Error(`Id tag for prefix ${prefix} not found.`)
|
|
@@ -203,7 +195,8 @@ export function readInt (buf = Buffer.from([])) {
|
|
|
203
195
|
* Helper function to build pointers for name update TX
|
|
204
196
|
* @function
|
|
205
197
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
206
|
-
* @param {Array} pointers - Array of pointers
|
|
198
|
+
* @param {Array} pointers - Array of pointers
|
|
199
|
+
* ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
207
200
|
* @return {Array} Serialized pointers array
|
|
208
201
|
*/
|
|
209
202
|
export function buildPointers (pointers) {
|
|
@@ -219,7 +212,8 @@ export function buildPointers (pointers) {
|
|
|
219
212
|
* Helper function to read pointers from name update TX
|
|
220
213
|
* @function
|
|
221
214
|
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
222
|
-
* @param {Array} pointers - Array of pointers
|
|
215
|
+
* @param {Array} pointers - Array of pointers
|
|
216
|
+
* ([ { key: 'account_pubkey', id: 'ak_32klj5j23k23j5423l434l2j3423'} ])
|
|
223
217
|
* @return {Array} Deserialize pointer array
|
|
224
218
|
*/
|
|
225
219
|
export function readPointers (pointers) {
|
|
@@ -261,35 +255,15 @@ export function isNameValid (name) {
|
|
|
261
255
|
}
|
|
262
256
|
|
|
263
257
|
/**
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
* @param s - the hash.
|
|
268
|
-
* returns the type, or throws an exception if type not found.
|
|
269
|
-
*/
|
|
270
|
-
export function classify (s) {
|
|
271
|
-
if (!s.match(/^[a-z]{2}_.+/)) {
|
|
272
|
-
throw new Error('Not a valid hash')
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
const klass = s.substr(0, 2)
|
|
276
|
-
if (klass in NAME_ID_KEY) {
|
|
277
|
-
return NAME_ID_KEY[klass]
|
|
278
|
-
} else {
|
|
279
|
-
throw new Error(`Unknown class ${klass}`)
|
|
280
|
-
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Validate name pointers array
|
|
285
|
-
* @function
|
|
286
|
-
* @alias module:@aeternity/aepp-sdk/es/tx/builder/helpers
|
|
287
|
-
* @param {String[]} pointers Pointers array. Allowed values is: account(ak_), oracle(ok_), contract(ct_), channel(ch_)
|
|
288
|
-
* @return {Boolean}
|
|
258
|
+
* @param identifier - account/oracle/contract address, or channel
|
|
259
|
+
* @returns {String} default AENS pointer key
|
|
260
|
+
* @throws exception when default key not defined
|
|
289
261
|
*/
|
|
290
|
-
export function
|
|
291
|
-
|
|
292
|
-
|
|
262
|
+
export function getDefaultPointerKey (identifier) {
|
|
263
|
+
decode(identifier)
|
|
264
|
+
const prefix = identifier.substr(0, 2)
|
|
265
|
+
return POINTER_KEY_BY_PREFIX[prefix] ||
|
|
266
|
+
(() => { throw new Error(`Default AENS pointer key is not defined for ${prefix} prefix`) })()
|
|
293
267
|
}
|
|
294
268
|
|
|
295
269
|
/**
|
|
@@ -301,7 +275,7 @@ export function validatePointers (pointers = []) {
|
|
|
301
275
|
*/
|
|
302
276
|
export function getMinimumNameFee (domain) {
|
|
303
277
|
const nameLength = domain.replace('.chain', '').length
|
|
304
|
-
return NAME_BID_RANGES[nameLength >=
|
|
278
|
+
return NAME_BID_RANGES[nameLength >= NAME_MAX_LENGTH_FEE ? NAME_MAX_LENGTH_FEE : nameLength]
|
|
305
279
|
}
|
|
306
280
|
|
|
307
281
|
/**
|
|
@@ -317,7 +291,8 @@ export function computeBidFee (domain, startFee = NAME_FEE, increment = NAME_FEE
|
|
|
317
291
|
if (!(Number(increment) === increment && increment % 1 !== 0)) throw new Error(`Increment must be float. Current increment ${increment}`)
|
|
318
292
|
if (increment < NAME_FEE_BID_INCREMENT) throw new Error(`minimum increment percentage is ${NAME_FEE_BID_INCREMENT}`)
|
|
319
293
|
return ceil(
|
|
320
|
-
BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(domain) : startFee)
|
|
294
|
+
BigNumber(BigNumber(startFee).eq(NAME_FEE) ? getMinimumNameFee(domain) : startFee)
|
|
295
|
+
.times(BigNumber(NAME_FEE_BID_INCREMENT).plus(1))
|
|
321
296
|
)
|
|
322
297
|
}
|
|
323
298
|
|