@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,22 +1,19 @@
|
|
|
1
1
|
import BigNumber from 'bignumber.js'
|
|
2
2
|
import { MAX_AUTH_FUN_GAS } from '../../tx/builder/schema'
|
|
3
|
-
import {
|
|
3
|
+
import { InvalidAuthDataError } from '../../utils/errors'
|
|
4
4
|
|
|
5
5
|
export const prepareGaParams = (ins) => async (authData, authFnName) => {
|
|
6
|
-
if (typeof authData !== 'object') throw new
|
|
7
|
-
if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) throw new
|
|
6
|
+
if (typeof authData !== 'object') throw new InvalidAuthDataError('AuthData must be an object')
|
|
7
|
+
if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) { throw new InvalidAuthDataError(`the maximum gas value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${authData.gas}`) }
|
|
8
8
|
const gas = authData.gas || MAX_AUTH_FUN_GAS
|
|
9
9
|
if (authData.callData) {
|
|
10
|
-
if (authData.callData.split('_')[0] !== 'cb') throw new
|
|
10
|
+
if (authData.callData.split('_')[0] !== 'cb') throw new InvalidAuthDataError('Auth data must be a string with "cb" prefix.')
|
|
11
11
|
return { authCallData: authData.callData, gas }
|
|
12
|
-
} else {
|
|
13
|
-
if (!authData.source || !authData.args) throw new Error('Auth data must contain source code and arguments.')
|
|
14
|
-
return { authCallData: await ins.contractEncodeCall(authData.source, authFnName, authData.args), gas }
|
|
15
12
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
if (!authData.source || !authData.args) throw new InvalidAuthDataError('Auth data must contain source code and arguments.')
|
|
14
|
+
const contract = await ins.getContractInstance({ source: authData.source })
|
|
15
|
+
return {
|
|
16
|
+
authCallData: contract.calldata.encode(contract._name, authFnName, authData.args),
|
|
17
|
+
gas
|
|
18
|
+
}
|
|
22
19
|
}
|
package/src/contract/ga/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* ISC License (ISC)
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2021 aeternity developers
|
|
4
4
|
*
|
|
5
5
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,51 +16,53 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Generalized Account module - routines to use generalized account
|
|
20
20
|
*
|
|
21
21
|
* @module @aeternity/aepp-sdk/es/contract/ga
|
|
22
|
-
* @export
|
|
23
|
-
* @example import {
|
|
22
|
+
* @export GeneralizedAccount
|
|
23
|
+
* @example import { GeneralizedAccount } from '@aeternity/aepp-sdk'
|
|
24
24
|
*/
|
|
25
|
-
import
|
|
26
|
-
|
|
27
|
-
import { ContractAPI } from '../../ae/contract'
|
|
25
|
+
import Contract from '../../ae/contract'
|
|
28
26
|
import { TX_TYPE } from '../../tx/builder/schema'
|
|
29
27
|
import { buildTx, unpackTx } from '../../tx/builder'
|
|
30
|
-
import {
|
|
28
|
+
import { prepareGaParams } from './helpers'
|
|
29
|
+
import { hash } from '../../utils/crypto'
|
|
30
|
+
import { IllegalArgumentError, MissingParamError } from '../../utils/errors'
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
33
|
+
* GeneralizedAccount Stamp
|
|
34
34
|
*
|
|
35
|
-
* Provide
|
|
35
|
+
* Provide Generalized Account implementation
|
|
36
36
|
* {@link module:@aeternity/aepp-sdk/es/contract/ga} clients.
|
|
37
37
|
* @function
|
|
38
38
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
39
39
|
* @rtype Stamp
|
|
40
40
|
* @param {Object} [options={}] - Initializer object
|
|
41
|
-
* @return {Object}
|
|
41
|
+
* @return {Object} GeneralizedAccount instance
|
|
42
42
|
* @example
|
|
43
43
|
* const authContract = ``
|
|
44
|
-
* await
|
|
44
|
+
* await aeSdk.createGeneralizedAccount(authFnName, authContract, [...authFnArguments]
|
|
45
45
|
* // Make spend using GA
|
|
46
46
|
* const callData = 'cb_...' // encoded call data for auth contract
|
|
47
|
-
* await
|
|
47
|
+
* await aeSdk.spend(10000, receiverPub, { authData: { callData } })
|
|
48
48
|
* // or
|
|
49
|
-
* await
|
|
49
|
+
* await aeSdk.spend(10000, receiverPub, {
|
|
50
|
+
* authData: { source: authContract, args: [...authContractArgs] }
|
|
51
|
+
* }) // sdk will prepare callData itself
|
|
50
52
|
*/
|
|
51
|
-
export const
|
|
53
|
+
export const GeneralizedAccount = Contract.compose({
|
|
52
54
|
methods: {
|
|
53
|
-
|
|
55
|
+
createGeneralizedAccount,
|
|
54
56
|
createMetaTx,
|
|
55
57
|
isGA
|
|
56
58
|
}
|
|
57
59
|
})
|
|
58
|
-
export default
|
|
60
|
+
export default GeneralizedAccount
|
|
59
61
|
|
|
60
62
|
/**
|
|
61
63
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
62
64
|
* @function
|
|
63
|
-
* Check if account is GA
|
|
65
|
+
* Check if account is GA
|
|
64
66
|
* @param {String} address - Account address
|
|
65
67
|
* @return {Boolean}
|
|
66
68
|
*/
|
|
@@ -70,31 +72,38 @@ async function isGA (address) {
|
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
/**
|
|
73
|
-
* Convert current account to GA
|
|
75
|
+
* Convert current account to GA
|
|
74
76
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
75
77
|
* @function
|
|
76
78
|
* @param {String} authFnName - Authorization function name
|
|
77
79
|
* @param {String} source - Auth contract source code
|
|
78
80
|
* @param {Array} [args] - init arguments
|
|
79
81
|
* @param {Object} [options] - Options
|
|
80
|
-
* @return {Promise<Readonly<{
|
|
82
|
+
* @return {Promise<Readonly<{
|
|
83
|
+
* result: *, owner: *, address, rawTx: *, transaction: *
|
|
84
|
+
* }>>}
|
|
81
85
|
*/
|
|
82
|
-
async function
|
|
83
|
-
const opt =
|
|
86
|
+
async function createGeneralizedAccount (authFnName, source, args = [], options = {}) {
|
|
87
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
84
88
|
const ownerId = await this.address(opt)
|
|
89
|
+
if (await this.isGA(ownerId)) throw new IllegalArgumentError(`Account ${ownerId} is already GA`)
|
|
85
90
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
91
|
+
const contract = await this.getContractInstance({ source })
|
|
92
|
+
await contract.compile()
|
|
93
|
+
const { tx, contractId } = await this.gaAttachTx({
|
|
94
|
+
...opt,
|
|
95
|
+
gas: opt.gas ?? await contract._estimateGas('init', args, opt),
|
|
96
|
+
ownerId,
|
|
97
|
+
code: contract.bytecode,
|
|
98
|
+
callData: contract.calldata.encode(contract._name, 'init', args),
|
|
99
|
+
authFun: hash(authFnName)
|
|
100
|
+
})
|
|
92
101
|
|
|
93
|
-
const { hash, rawTx } = await this.send(tx, opt)
|
|
102
|
+
const { hash: transaction, rawTx } = await this.send(tx, opt)
|
|
94
103
|
|
|
95
104
|
return Object.freeze({
|
|
96
105
|
owner: ownerId,
|
|
97
|
-
transaction
|
|
106
|
+
transaction,
|
|
98
107
|
rawTx,
|
|
99
108
|
gaContractId: contractId
|
|
100
109
|
})
|
|
@@ -113,10 +122,10 @@ const wrapInEmptySignedTx = (tx) => buildTx({ encodedTx: tx, signatures: [] }, T
|
|
|
113
122
|
* @return {String}
|
|
114
123
|
*/
|
|
115
124
|
async function createMetaTx (rawTransaction, authData, authFnName, options = {}) {
|
|
116
|
-
if (!authData) throw new
|
|
125
|
+
if (!authData) throw new MissingParamError('authData is required')
|
|
117
126
|
// Check if authData is callData or if it's an object prepare a callData from source and args
|
|
118
127
|
const { authCallData, gas } = await prepareGaParams(this)(authData, authFnName)
|
|
119
|
-
const opt =
|
|
128
|
+
const opt = { ...this.Ae.defaults, ...options }
|
|
120
129
|
const { abiVersion } = await this.getVmVersion(TX_TYPE.contractCall)
|
|
121
130
|
const wrappedTx = wrapInEmptySignedTx(unpackTx(rawTransaction))
|
|
122
131
|
const params = {
|
|
@@ -126,7 +135,7 @@ async function createMetaTx (rawTransaction, authData, authFnName, options = {})
|
|
|
126
135
|
tx: wrappedTx.txObject
|
|
127
136
|
},
|
|
128
137
|
gaId: await this.address(opt),
|
|
129
|
-
abiVersion
|
|
138
|
+
abiVersion,
|
|
130
139
|
authData: authCallData,
|
|
131
140
|
gas,
|
|
132
141
|
vsn: 2
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* ISC License (ISC)
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2021 aeternity developers
|
|
4
4
|
*
|
|
5
5
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -21,10 +21,8 @@ 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
|
-
import * as ACITransformation from './contract/aci/transformation'
|
|
26
24
|
import * as AmountFormatter from './utils/amount-formatter'
|
|
27
|
-
import HdWallet from './utils/hd-wallet'
|
|
25
|
+
import * as HdWallet from './utils/hd-wallet'
|
|
28
26
|
|
|
29
27
|
import Ae from './ae'
|
|
30
28
|
import Chain from './chain'
|
|
@@ -39,8 +37,8 @@ import AccountMultiple from './account/multiple'
|
|
|
39
37
|
import MemoryAccount from './account/memory'
|
|
40
38
|
import Aens from './ae/aens'
|
|
41
39
|
import Contract from './ae/contract'
|
|
42
|
-
import
|
|
43
|
-
import
|
|
40
|
+
import GeneralizedAccount from './contract/ga'
|
|
41
|
+
import ContractCompilerHttp from './contract/compiler'
|
|
44
42
|
import RpcAepp from './ae/aepp'
|
|
45
43
|
import RpcWallet from './ae/wallet'
|
|
46
44
|
import Oracle from './ae/oracle'
|
|
@@ -54,6 +52,9 @@ export * as AeppWalletSchema from './utils/aepp-wallet-communication/schema'
|
|
|
54
52
|
export { default as WalletDetector } from './utils/aepp-wallet-communication/wallet-detector'
|
|
55
53
|
export { default as BrowserRuntimeConnection } from './utils/aepp-wallet-communication/connection/browser-runtime'
|
|
56
54
|
export { default as BrowserWindowMessageConnection } from './utils/aepp-wallet-communication/connection/browser-window-message'
|
|
55
|
+
export * from './utils/errors'
|
|
56
|
+
|
|
57
|
+
export const getDefaultPointerKey = TxBuilderHelper.getDefaultPointerKey
|
|
57
58
|
|
|
58
59
|
export {
|
|
59
60
|
AmountFormatter,
|
|
@@ -63,9 +64,7 @@ export {
|
|
|
63
64
|
Aens,
|
|
64
65
|
Bytes,
|
|
65
66
|
Contract,
|
|
66
|
-
|
|
67
|
-
ACIHelpers,
|
|
68
|
-
ACITransformation,
|
|
67
|
+
ContractCompilerHttp,
|
|
69
68
|
ChainNode,
|
|
70
69
|
RpcAepp,
|
|
71
70
|
RpcWallet,
|
|
@@ -73,7 +72,7 @@ export {
|
|
|
73
72
|
Crypto,
|
|
74
73
|
Keystore,
|
|
75
74
|
Chain,
|
|
76
|
-
|
|
75
|
+
GeneralizedAccount,
|
|
77
76
|
HdWallet,
|
|
78
77
|
MemoryAccount,
|
|
79
78
|
Node,
|
package/src/node-pool/index.js
CHANGED
|
@@ -5,8 +5,8 @@
|
|
|
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'
|
|
9
|
+
import { DisconnectedError, DuplicateNodeError, NodeNotFoundError, TypeError } from '../utils/errors'
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Node Pool Stamp
|
|
@@ -35,7 +35,7 @@ export default stampit({
|
|
|
35
35
|
configurable: false,
|
|
36
36
|
get () {
|
|
37
37
|
if (!this.selectedNode || !this.selectedNode.instance) {
|
|
38
|
-
throw new
|
|
38
|
+
throw new NodeNotFoundError('You can\'t use Node API. Node is not connected or not defined!')
|
|
39
39
|
}
|
|
40
40
|
return this.selectedNode.instance.api
|
|
41
41
|
}
|
|
@@ -52,10 +52,11 @@ export default stampit({
|
|
|
52
52
|
* @param {Boolean} select - Select this node as current
|
|
53
53
|
* @return {void}
|
|
54
54
|
* @example
|
|
55
|
-
*
|
|
55
|
+
* // add and select new node with name 'testNode'
|
|
56
|
+
* nodePool.addNode('testNode', awaitNode({ url, internalUrl }), true)
|
|
56
57
|
*/
|
|
57
58
|
addNode (name, node, select = false) {
|
|
58
|
-
if (this.pool.has(name)) throw new
|
|
59
|
+
if (this.pool.has(name)) throw new DuplicateNodeError(name)
|
|
59
60
|
|
|
60
61
|
this.validateNodes([{ name, instance: node }])
|
|
61
62
|
|
|
@@ -83,7 +84,7 @@ export default stampit({
|
|
|
83
84
|
* nodePool.selectNode('testNode')
|
|
84
85
|
*/
|
|
85
86
|
selectNode (name) {
|
|
86
|
-
if (!this.pool.has(name)) throw new
|
|
87
|
+
if (!this.pool.has(name)) throw new NodeNotFoundError(`Node with name ${name} not in pool`)
|
|
87
88
|
|
|
88
89
|
this.selectedNode = this.pool.get(name)
|
|
89
90
|
},
|
|
@@ -119,7 +120,7 @@ export default stampit({
|
|
|
119
120
|
* nodePool.getNodeInfo() // { name, version, networkId, protocol, ... }
|
|
120
121
|
*/
|
|
121
122
|
getNodeInfo () {
|
|
122
|
-
if (!this.isNodeConnected()) throw new
|
|
123
|
+
if (!this.isNodeConnected()) throw new DisconnectedError()
|
|
123
124
|
return {
|
|
124
125
|
name: this.selectedNode.name,
|
|
125
126
|
...this.selectedNode.instance.getNodeInfo()
|
|
@@ -141,17 +142,28 @@ export default stampit({
|
|
|
141
142
|
}))
|
|
142
143
|
},
|
|
143
144
|
validateNodes (nodes) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
145
|
+
// TODO: validate it on TypeScript level instead
|
|
146
|
+
// (to speedup development, save runtime resources)
|
|
147
|
+
if (!Array.isArray(nodes)) throw new TypeError('"nodes" should be an array')
|
|
148
|
+
const notObject = nodes.map(n => typeof n).find(t => t !== 'object')
|
|
149
|
+
if (notObject) throw new TypeError(`Each node should be an object, got ${notObject} instead`)
|
|
150
|
+
const wrongFields = nodes.find(n => typeof n.name !== 'string' || typeof n.instance !== 'object')
|
|
151
|
+
if (notObject) {
|
|
152
|
+
throw new TypeError(
|
|
153
|
+
'Each node should have name (string), instance (object) ' +
|
|
154
|
+
`fields, got ${JSON.stringify(wrongFields)} instead`
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
const wrongInstanceFields = nodes
|
|
158
|
+
.map(n => n.instance)
|
|
159
|
+
.find(i => typeof i.api !== 'object' || typeof i.genesisHash !== 'string' ||
|
|
160
|
+
typeof i.consensusProtocolVersion !== 'number')
|
|
161
|
+
if (wrongInstanceFields) {
|
|
162
|
+
throw new TypeError(
|
|
163
|
+
'Each node instance should have api (object), consensusProtocolVersion (number), ' +
|
|
164
|
+
`genesisHash (string) fields, got ${JSON.stringify(wrongInstanceFields)} instead`
|
|
165
|
+
)
|
|
166
|
+
}
|
|
155
167
|
}
|
|
156
168
|
},
|
|
157
169
|
props: {
|
package/src/node.js
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import AsyncInit from './utils/async-init'
|
|
26
26
|
import genSwaggerClient from './utils/swagger'
|
|
27
27
|
import semverSatisfies from './utils/semver-satisfies'
|
|
28
|
+
import { MissingParamError, UnsupportedVersionError } from './utils/errors'
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Obtain networkId from account or node
|
|
@@ -34,29 +35,10 @@ import semverSatisfies from './utils/semver-satisfies'
|
|
|
34
35
|
* @return {String} NetworkId
|
|
35
36
|
*/
|
|
36
37
|
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
|
|
38
|
+
const res = networkId || this.networkId || this.selectedNode?.networkId
|
|
39
|
+
if (!force && !res) throw new MissingParamError('networkId is not provided')
|
|
40
|
+
if (force && !res) return null
|
|
41
|
+
return res
|
|
60
42
|
}
|
|
61
43
|
|
|
62
44
|
/**
|
|
@@ -67,30 +49,46 @@ async function getConsensusProtocolVersion (protocols = [], height) {
|
|
|
67
49
|
* @param {Object} [options={}] - Options
|
|
68
50
|
* @param {String} options.url - Base URL for Node
|
|
69
51
|
* @param {String} options.internalUrl - Base URL for internal requests
|
|
70
|
-
* @param {
|
|
52
|
+
* @param {Object} options.axiosConfig - Object with axios configuration
|
|
53
|
+
* @param {Object} options.axiosConfig.config
|
|
54
|
+
* @param {Function} options.axiosConfig.errorHandler - (err) => throw err
|
|
71
55
|
* @return {Object} Node client
|
|
72
56
|
* @example Node({url: 'https://testnet.aeternity.io'})
|
|
73
57
|
*/
|
|
74
58
|
const Node = AsyncInit.compose({
|
|
75
59
|
async init ({ url, internalUrl, ignoreVersion }) {
|
|
76
|
-
if (!url) throw new
|
|
60
|
+
if (!url) throw new MissingParamError('"url" required')
|
|
77
61
|
this.url = url.replace(/\/$/, '')
|
|
78
|
-
this.internalUrl = internalUrl
|
|
79
|
-
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
62
|
+
this.internalUrl = internalUrl?.replace(/\/$/, '')
|
|
63
|
+
const client = await genSwaggerClient(`${this.url}/api?oas3`, {
|
|
64
|
+
internalUrl: this.internalUrl,
|
|
65
|
+
responseInterceptor: response => {
|
|
66
|
+
if (response.ok) return
|
|
67
|
+
return Object.assign(response, {
|
|
68
|
+
statusText: `${new URL(response.url).pathname.slice(1)} error: ` + response.body.reason
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
})
|
|
80
72
|
this.version = client.spec.info.version
|
|
81
73
|
if (
|
|
82
74
|
!semverSatisfies(this.version, NODE_GE_VERSION, NODE_LT_VERSION) &&
|
|
83
75
|
!ignoreVersion
|
|
84
76
|
) {
|
|
85
|
-
throw new
|
|
86
|
-
`Unsupported node version ${this.version}. ` +
|
|
87
|
-
`Supported: >= ${NODE_GE_VERSION} < ${NODE_LT_VERSION}`
|
|
88
|
-
)
|
|
77
|
+
throw new UnsupportedVersionError('node', this.version, NODE_GE_VERSION, NODE_LT_VERSION)
|
|
89
78
|
}
|
|
90
79
|
this.api = client.api
|
|
91
80
|
|
|
92
|
-
const {
|
|
93
|
-
|
|
81
|
+
const {
|
|
82
|
+
nodeRevision: revision, genesisKeyBlockHash: genesisHash, networkId,
|
|
83
|
+
protocols, topBlockHeight
|
|
84
|
+
} = await this.api.getStatus()
|
|
85
|
+
this.consensusProtocolVersion = protocols
|
|
86
|
+
.filter(({ effectiveAtHeight }) => topBlockHeight >= effectiveAtHeight)
|
|
87
|
+
.reduce(
|
|
88
|
+
(acc, p) => p.effectiveAtHeight > acc.effectiveAtHeight ? p : acc,
|
|
89
|
+
{ effectiveAtHeight: -1, version: 0 }
|
|
90
|
+
)
|
|
91
|
+
.version
|
|
94
92
|
this.nodeNetworkId = networkId
|
|
95
93
|
return Object.assign(this, { revision, genesisHash })
|
|
96
94
|
},
|
|
@@ -103,8 +101,7 @@ const Node = AsyncInit.compose({
|
|
|
103
101
|
version: this.version,
|
|
104
102
|
consensusProtocolVersion: this.consensusProtocolVersion
|
|
105
103
|
}
|
|
106
|
-
}
|
|
107
|
-
getConsensusProtocolVersion
|
|
104
|
+
}
|
|
108
105
|
},
|
|
109
106
|
props: {
|
|
110
107
|
version: null,
|
|
@@ -113,7 +110,7 @@ const Node = AsyncInit.compose({
|
|
|
113
110
|
}
|
|
114
111
|
})
|
|
115
112
|
|
|
116
|
-
const NODE_GE_VERSION = '6.
|
|
113
|
+
const NODE_GE_VERSION = '6.2.0'
|
|
117
114
|
const NODE_LT_VERSION = '7.0.0'
|
|
118
115
|
|
|
119
116
|
export default Node
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import {
|
|
2
|
+
writeId, readId, isNameValid, produceNameId, ensureNameValid, getMinimumNameFee, readInt, writeInt
|
|
3
|
+
} from './helpers'
|
|
4
|
+
import { InsufficientNameFeeError, IllegalArgumentError } from '../../utils/errors'
|
|
5
|
+
|
|
6
|
+
export class Field {
|
|
7
|
+
static serialize (value) {
|
|
8
|
+
return value
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static deserialize (value) {
|
|
12
|
+
return value
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class Name extends Field {
|
|
17
|
+
static serialize (value) {
|
|
18
|
+
ensureNameValid(value)
|
|
19
|
+
return Buffer.from(value)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static deserialize (value) {
|
|
23
|
+
return value.toString()
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export class NameId extends Field {
|
|
28
|
+
static serialize (value) {
|
|
29
|
+
return writeId(isNameValid(value) ? produceNameId(value) : value)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static deserialize (value) {
|
|
33
|
+
return readId(value)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export class NameFee extends Field {
|
|
38
|
+
static serialize (value, { name }) {
|
|
39
|
+
const minNameFee = getMinimumNameFee(name)
|
|
40
|
+
value ??= minNameFee
|
|
41
|
+
if (minNameFee.gt(value)) {
|
|
42
|
+
throw new InsufficientNameFeeError(value, minNameFee)
|
|
43
|
+
}
|
|
44
|
+
return writeInt(value)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
static deserialize (value) {
|
|
48
|
+
return readInt(value)
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class Deposit extends Field {
|
|
53
|
+
static serialize (value, { name }) {
|
|
54
|
+
if (+value) throw new IllegalArgumentError(`Contract deposit is not refundable, so it should be equal 0, got ${value} instead`)
|
|
55
|
+
return writeInt(0)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
static deserialize (value) {
|
|
59
|
+
return readInt(value)
|
|
60
|
+
}
|
|
61
|
+
}
|