@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
|
@@ -1,127 +1,22 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
2
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
3
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
4
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
5
1
|
import BigNumber from 'bignumber.js';
|
|
6
|
-
import { MAX_AUTH_FUN_GAS
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
switch (_context2.prev = _context2.next) {
|
|
18
|
-
case 0:
|
|
19
|
-
if (!(_typeof(authData) !== 'object')) {
|
|
20
|
-
_context2.next = 2;
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
throw new Error('AuthData must be an object');
|
|
25
|
-
|
|
26
|
-
case 2:
|
|
27
|
-
if (!(authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS))) {
|
|
28
|
-
_context2.next = 4;
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
throw new Error(_concatInstanceProperty(_context = "the maximum gas value for ga authFun is ".concat(MAX_AUTH_FUN_GAS, ", got ")).call(_context, authData.gas));
|
|
33
|
-
|
|
34
|
-
case 4:
|
|
35
|
-
gas = authData.gas || MAX_AUTH_FUN_GAS;
|
|
36
|
-
|
|
37
|
-
if (!authData.callData) {
|
|
38
|
-
_context2.next = 11;
|
|
39
|
-
break;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (!(authData.callData.split('_')[0] !== 'cb')) {
|
|
43
|
-
_context2.next = 8;
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
throw new Error('Auth data must be a string with "cb" prefix.');
|
|
48
|
-
|
|
49
|
-
case 8:
|
|
50
|
-
return _context2.abrupt("return", {
|
|
51
|
-
authCallData: authData.callData,
|
|
52
|
-
gas: gas
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
case 11:
|
|
56
|
-
if (!(!authData.source || !authData.args)) {
|
|
57
|
-
_context2.next = 13;
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
throw new Error('Auth data must contain source code and arguments.');
|
|
62
|
-
|
|
63
|
-
case 13:
|
|
64
|
-
_context2.next = 15;
|
|
65
|
-
return ins.contractEncodeCall(authData.source, authFnName, authData.args);
|
|
66
|
-
|
|
67
|
-
case 15:
|
|
68
|
-
_context2.t0 = _context2.sent;
|
|
69
|
-
_context2.t1 = gas;
|
|
70
|
-
return _context2.abrupt("return", {
|
|
71
|
-
authCallData: _context2.t0,
|
|
72
|
-
gas: _context2.t1
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
case 18:
|
|
76
|
-
case "end":
|
|
77
|
-
return _context2.stop();
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}, _callee);
|
|
81
|
-
}));
|
|
82
|
-
|
|
83
|
-
return function (_x, _x2) {
|
|
84
|
-
return _ref.apply(this, arguments);
|
|
2
|
+
import { MAX_AUTH_FUN_GAS } from '../../tx/builder/schema';
|
|
3
|
+
export const prepareGaParams = ins => async (authData, authFnName) => {
|
|
4
|
+
if (typeof authData !== 'object') throw new Error('AuthData must be an object');
|
|
5
|
+
if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) throw new Error(`the maximum gas value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${authData.gas}`);
|
|
6
|
+
const gas = authData.gas || MAX_AUTH_FUN_GAS;
|
|
7
|
+
|
|
8
|
+
if (authData.callData) {
|
|
9
|
+
if (authData.callData.split('_')[0] !== 'cb') throw new Error('Auth data must be a string with "cb" prefix.');
|
|
10
|
+
return {
|
|
11
|
+
authCallData: authData.callData,
|
|
12
|
+
gas
|
|
85
13
|
};
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
export var getContractAuthFan = function getContractAuthFan(ins) {
|
|
89
|
-
return /*#__PURE__*/function () {
|
|
90
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(source, fnName) {
|
|
91
|
-
var _yield$ins$contractCo, bytecode;
|
|
14
|
+
}
|
|
92
15
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return ins.contractCompile(source);
|
|
99
|
-
|
|
100
|
-
case 2:
|
|
101
|
-
_yield$ins$contractCo = _context3.sent;
|
|
102
|
-
bytecode = _yield$ins$contractCo.bytecode;
|
|
103
|
-
return _context3.abrupt("return", {
|
|
104
|
-
bytecode: bytecode,
|
|
105
|
-
authFun: hash(fnName)
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
case 5:
|
|
109
|
-
case "end":
|
|
110
|
-
return _context3.stop();
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}, _callee2);
|
|
114
|
-
}));
|
|
115
|
-
|
|
116
|
-
return function (_x3, _x4) {
|
|
117
|
-
return _ref2.apply(this, arguments);
|
|
118
|
-
};
|
|
119
|
-
}();
|
|
120
|
-
};
|
|
121
|
-
export var wrapInEmptySignedTx = function wrapInEmptySignedTx(rlp) {
|
|
122
|
-
return buildTx({
|
|
123
|
-
encodedTx: rlp,
|
|
124
|
-
signatures: []
|
|
125
|
-
}, TX_TYPE.signed);
|
|
16
|
+
if (!authData.source || !authData.args) throw new Error('Auth data must contain source code and arguments.');
|
|
17
|
+
return {
|
|
18
|
+
authCallData: await ins.contractEncodeCallDataAPI(authData.source, authFnName, authData.args),
|
|
19
|
+
gas
|
|
20
|
+
};
|
|
126
21
|
};
|
|
127
22
|
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/contract/ga/helpers.js"],"names":["BigNumber","MAX_AUTH_FUN_GAS","
|
|
1
|
+
{"version":3,"sources":["../../../src/contract/ga/helpers.js"],"names":["BigNumber","MAX_AUTH_FUN_GAS","prepareGaParams","ins","authData","authFnName","Error","gas","gt","callData","split","authCallData","source","args","contractEncodeCallDataAPI"],"mappings":"AAAA,OAAOA,SAAP,MAAsB,cAAtB;AACA,SAASC,gBAAT,QAAiC,yBAAjC;AAEA,OAAO,MAAMC,eAAe,GAAIC,GAAD,IAAS,OAAOC,QAAP,EAAiBC,UAAjB,KAAgC;AACtE,MAAI,OAAOD,QAAP,KAAoB,QAAxB,EAAkC,MAAM,IAAIE,KAAJ,CAAU,4BAAV,CAAN;AAClC,MAAIF,QAAQ,CAACG,GAAT,IAAgBP,SAAS,CAACI,QAAQ,CAACG,GAAV,CAAT,CAAwBC,EAAxB,CAA2BP,gBAA3B,CAApB,EAAkE,MAAM,IAAIK,KAAJ,CAAW,2CAA0CL,gBAAiB,SAAQG,QAAQ,CAACG,GAAI,EAA3F,CAAN;AAClE,QAAMA,GAAG,GAAGH,QAAQ,CAACG,GAAT,IAAgBN,gBAA5B;;AACA,MAAIG,QAAQ,CAACK,QAAb,EAAuB;AACrB,QAAIL,QAAQ,CAACK,QAAT,CAAkBC,KAAlB,CAAwB,GAAxB,EAA6B,CAA7B,MAAoC,IAAxC,EAA8C,MAAM,IAAIJ,KAAJ,CAAU,8CAAV,CAAN;AAC9C,WAAO;AAAEK,MAAAA,YAAY,EAAEP,QAAQ,CAACK,QAAzB;AAAmCF,MAAAA;AAAnC,KAAP;AACD;;AACD,MAAI,CAACH,QAAQ,CAACQ,MAAV,IAAoB,CAACR,QAAQ,CAACS,IAAlC,EAAwC,MAAM,IAAIP,KAAJ,CAAU,mDAAV,CAAN;AACxC,SAAO;AACLK,IAAAA,YAAY,EAAE,MAAMR,GAAG,CAACW,yBAAJ,CAA8BV,QAAQ,CAACQ,MAAvC,EAA+CP,UAA/C,EAA2DD,QAAQ,CAACS,IAApE,CADf;AAELN,IAAAA;AAFK,GAAP;AAID,CAbM","sourcesContent":["import BigNumber from 'bignumber.js'\nimport { MAX_AUTH_FUN_GAS } from '../../tx/builder/schema'\n\nexport const prepareGaParams = (ins) => async (authData, authFnName) => {\n if (typeof authData !== 'object') throw new Error('AuthData must be an object')\n if (authData.gas && BigNumber(authData.gas).gt(MAX_AUTH_FUN_GAS)) throw new Error(`the maximum gas value for ga authFun is ${MAX_AUTH_FUN_GAS}, got ${authData.gas}`)\n const gas = authData.gas || MAX_AUTH_FUN_GAS\n if (authData.callData) {\n if (authData.callData.split('_')[0] !== 'cb') throw new Error('Auth data must be a string with \"cb\" prefix.')\n return { authCallData: authData.callData, gas }\n }\n if (!authData.source || !authData.args) throw new Error('Auth data must contain source code and arguments.')\n return {\n authCallData: await ins.contractEncodeCallDataAPI(authData.source, authFnName, authData.args),\n gas\n }\n}\n"],"file":"helpers.js"}
|
package/es/contract/ga/index.js
CHANGED
|
@@ -1,26 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2018 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
8
17
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
17
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
18
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
18
|
+
/**
|
|
19
|
+
* Generalize Account module - routines to use generalize account
|
|
20
|
+
*
|
|
21
|
+
* @module @aeternity/aepp-sdk/es/contract/ga
|
|
22
|
+
* @export GeneralizeAccount
|
|
23
|
+
* @example import { GeneralizeAccount } from '@aeternity/aepp-sdk'
|
|
24
|
+
*/
|
|
19
25
|
import { ContractAPI } from '../../ae/contract';
|
|
20
26
|
import { TX_TYPE } from '../../tx/builder/schema';
|
|
21
|
-
import { buildTx } from '../../tx/builder';
|
|
22
|
-
import {
|
|
23
|
-
import {
|
|
27
|
+
import { buildTx, unpackTx } from '../../tx/builder';
|
|
28
|
+
import { prepareGaParams } from './helpers';
|
|
29
|
+
import { hash } from '../../utils/crypto';
|
|
24
30
|
/**
|
|
25
31
|
* GeneralizeAccount Stamp
|
|
26
32
|
*
|
|
@@ -38,14 +44,16 @@ import { assertedType, decodeBase64Check } from '../../utils/crypto';
|
|
|
38
44
|
* const callData = 'cb_...' // encoded call data for auth contract
|
|
39
45
|
* await client.spend(10000, receiverPub, { authData: { callData } })
|
|
40
46
|
* // or
|
|
41
|
-
* await client.spend(10000, receiverPub, {
|
|
47
|
+
* await client.spend(10000, receiverPub, {
|
|
48
|
+
* authData: { source: authContract, args: [...authContractArgs] }
|
|
49
|
+
* }) // sdk will prepare callData itself
|
|
42
50
|
*/
|
|
43
51
|
|
|
44
|
-
export
|
|
52
|
+
export const GeneralizeAccount = ContractAPI.compose({
|
|
45
53
|
methods: {
|
|
46
|
-
createGeneralizeAccount
|
|
47
|
-
createMetaTx
|
|
48
|
-
isGA
|
|
54
|
+
createGeneralizeAccount,
|
|
55
|
+
createMetaTx,
|
|
56
|
+
isGA
|
|
49
57
|
}
|
|
50
58
|
});
|
|
51
59
|
export default GeneralizeAccount;
|
|
@@ -57,8 +65,11 @@ export default GeneralizeAccount;
|
|
|
57
65
|
* @return {Boolean}
|
|
58
66
|
*/
|
|
59
67
|
|
|
60
|
-
function isGA(
|
|
61
|
-
|
|
68
|
+
async function isGA(address) {
|
|
69
|
+
const {
|
|
70
|
+
contractId
|
|
71
|
+
} = await this.getAccount(address);
|
|
72
|
+
return !!contractId;
|
|
62
73
|
}
|
|
63
74
|
/**
|
|
64
75
|
* Convert current account to GA account
|
|
@@ -68,39 +79,45 @@ function isGA(_x) {
|
|
|
68
79
|
* @param {String} source - Auth contract source code
|
|
69
80
|
* @param {Array} [args] - init arguments
|
|
70
81
|
* @param {Object} [options] - Options
|
|
71
|
-
* @return {Promise<Readonly<{
|
|
82
|
+
* @return {Promise<Readonly<{
|
|
83
|
+
* result: *, owner: *, createdAt: Date, address, rawTx: *, transaction: *
|
|
84
|
+
* }>>}
|
|
72
85
|
*/
|
|
73
86
|
|
|
74
87
|
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
88
|
+
async function createGeneralizeAccount(authFnName, source) {
|
|
89
|
+
let args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
90
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
91
|
+
const opt = { ...this.Ae.defaults,
|
|
92
|
+
...options
|
|
93
|
+
};
|
|
94
|
+
const ownerId = await this.address(opt);
|
|
95
|
+
if (await this.isGA(ownerId)) throw new Error(`Account ${ownerId} is already GA`);
|
|
96
|
+
const {
|
|
97
|
+
tx,
|
|
98
|
+
contractId
|
|
99
|
+
} = await this.gaAttachTx({ ...opt,
|
|
100
|
+
ownerId,
|
|
101
|
+
code: (await this.contractCompile(source)).bytecode,
|
|
102
|
+
callData: await this.contractEncodeCallDataAPI(source, 'init', args),
|
|
103
|
+
authFun: hash(authFnName)
|
|
104
|
+
});
|
|
105
|
+
const {
|
|
106
|
+
hash: transaction,
|
|
107
|
+
rawTx
|
|
108
|
+
} = await this.send(tx, opt);
|
|
109
|
+
return Object.freeze({
|
|
110
|
+
owner: ownerId,
|
|
111
|
+
transaction,
|
|
112
|
+
rawTx,
|
|
113
|
+
gaContractId: contractId
|
|
114
|
+
});
|
|
99
115
|
}
|
|
100
116
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
117
|
+
const wrapInEmptySignedTx = tx => buildTx({
|
|
118
|
+
encodedTx: tx,
|
|
119
|
+
signatures: []
|
|
120
|
+
}, TX_TYPE.signed);
|
|
104
121
|
/**
|
|
105
122
|
* Create a metaTx transaction
|
|
106
123
|
* @alias module:@aeternity/aepp-sdk/es/contract/ga
|
|
@@ -113,199 +130,41 @@ function createGeneralizeAccount(_x2, _x3) {
|
|
|
113
130
|
*/
|
|
114
131
|
|
|
115
132
|
|
|
116
|
-
function
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
throw new Error("Account ".concat(ownerId, " is already GA"));
|
|
156
|
-
|
|
157
|
-
case 10:
|
|
158
|
-
_context2.next = 12;
|
|
159
|
-
return getContractAuthFan(this)(source, authFnName);
|
|
160
|
-
|
|
161
|
-
case 12:
|
|
162
|
-
_yield$getContractAut = _context2.sent;
|
|
163
|
-
authFun = _yield$getContractAut.authFun;
|
|
164
|
-
bytecode = _yield$getContractAut.bytecode;
|
|
165
|
-
_context2.next = 17;
|
|
166
|
-
return this.contractEncodeCall(source, 'init', args);
|
|
167
|
-
|
|
168
|
-
case 17:
|
|
169
|
-
callData = _context2.sent;
|
|
170
|
-
_context2.next = 20;
|
|
171
|
-
return this.gaAttachTx(_merge(opt, {
|
|
172
|
-
ownerId: ownerId,
|
|
173
|
-
code: bytecode,
|
|
174
|
-
callData: callData,
|
|
175
|
-
authFun: authFun
|
|
176
|
-
}));
|
|
177
|
-
|
|
178
|
-
case 20:
|
|
179
|
-
_yield$this$gaAttachT = _context2.sent;
|
|
180
|
-
tx = _yield$this$gaAttachT.tx;
|
|
181
|
-
contractId = _yield$this$gaAttachT.contractId;
|
|
182
|
-
_context2.next = 25;
|
|
183
|
-
return this.send(tx, opt);
|
|
184
|
-
|
|
185
|
-
case 25:
|
|
186
|
-
_yield$this$send = _context2.sent;
|
|
187
|
-
hash = _yield$this$send.hash;
|
|
188
|
-
rawTx = _yield$this$send.rawTx;
|
|
189
|
-
return _context2.abrupt("return", _Object$freeze({
|
|
190
|
-
owner: ownerId,
|
|
191
|
-
transaction: hash,
|
|
192
|
-
rawTx: rawTx,
|
|
193
|
-
gaContractId: contractId
|
|
194
|
-
}));
|
|
195
|
-
|
|
196
|
-
case 29:
|
|
197
|
-
case "end":
|
|
198
|
-
return _context2.stop();
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
}, _callee2, this);
|
|
202
|
-
}));
|
|
203
|
-
return _createGeneralizeAccount.apply(this, arguments);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function createMetaTx(_x4, _x5, _x6) {
|
|
207
|
-
return _createMetaTx.apply(this, arguments);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function _createMetaTx() {
|
|
211
|
-
_createMetaTx = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(rawTransaction, authData, authFnName) {
|
|
212
|
-
var options,
|
|
213
|
-
_yield$prepareGaParam,
|
|
214
|
-
authCallData,
|
|
215
|
-
gas,
|
|
216
|
-
opt,
|
|
217
|
-
rlpBinaryTx,
|
|
218
|
-
_wrapInEmptySignedTx,
|
|
219
|
-
rlpEncoded,
|
|
220
|
-
_yield$this$getVmVers,
|
|
221
|
-
abiVersion,
|
|
222
|
-
params,
|
|
223
|
-
_yield$this$prepareTx,
|
|
224
|
-
fee,
|
|
225
|
-
_buildTx,
|
|
226
|
-
metaTxRlp,
|
|
227
|
-
_wrapInEmptySignedTx2,
|
|
228
|
-
tx,
|
|
229
|
-
_args3 = arguments;
|
|
230
|
-
|
|
231
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
232
|
-
while (1) {
|
|
233
|
-
switch (_context3.prev = _context3.next) {
|
|
234
|
-
case 0:
|
|
235
|
-
options = _args3.length > 3 && _args3[3] !== undefined ? _args3[3] : {};
|
|
236
|
-
|
|
237
|
-
if (authData) {
|
|
238
|
-
_context3.next = 3;
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
throw new Error('authData is required');
|
|
243
|
-
|
|
244
|
-
case 3:
|
|
245
|
-
_context3.next = 5;
|
|
246
|
-
return prepareGaParams(this)(authData, authFnName);
|
|
247
|
-
|
|
248
|
-
case 5:
|
|
249
|
-
_yield$prepareGaParam = _context3.sent;
|
|
250
|
-
authCallData = _yield$prepareGaParam.authCallData;
|
|
251
|
-
gas = _yield$prepareGaParam.gas;
|
|
252
|
-
opt = _merge(this.Ae.defaults, options); // Get transaction rlp binary
|
|
253
|
-
|
|
254
|
-
rlpBinaryTx = decodeBase64Check(assertedType(rawTransaction, 'tx')); // Wrap in SIGNED tx with empty signatures
|
|
255
|
-
|
|
256
|
-
_wrapInEmptySignedTx = wrapInEmptySignedTx(rlpBinaryTx), rlpEncoded = _wrapInEmptySignedTx.rlpEncoded; // Get abi
|
|
257
|
-
|
|
258
|
-
_context3.next = 13;
|
|
259
|
-
return this.getVmVersion(TX_TYPE.contractCall);
|
|
260
|
-
|
|
261
|
-
case 13:
|
|
262
|
-
_yield$this$getVmVers = _context3.sent;
|
|
263
|
-
abiVersion = _yield$this$getVmVers.abiVersion;
|
|
264
|
-
_context3.t0 = _objectSpread;
|
|
265
|
-
_context3.t1 = _objectSpread({}, opt);
|
|
266
|
-
_context3.t2 = {};
|
|
267
|
-
_context3.t3 = rlpEncoded;
|
|
268
|
-
_context3.next = 21;
|
|
269
|
-
return this.address(opt);
|
|
270
|
-
|
|
271
|
-
case 21:
|
|
272
|
-
_context3.t4 = _context3.sent;
|
|
273
|
-
_context3.t5 = abiVersion;
|
|
274
|
-
_context3.t6 = authCallData;
|
|
275
|
-
_context3.t7 = gas;
|
|
276
|
-
_context3.t8 = {
|
|
277
|
-
tx: _context3.t3,
|
|
278
|
-
gaId: _context3.t4,
|
|
279
|
-
abiVersion: _context3.t5,
|
|
280
|
-
authData: _context3.t6,
|
|
281
|
-
gas: _context3.t7,
|
|
282
|
-
vsn: 2
|
|
283
|
-
};
|
|
284
|
-
params = (0, _context3.t0)(_context3.t1, _context3.t2, _context3.t8);
|
|
285
|
-
_context3.next = 29;
|
|
286
|
-
return this.prepareTxParams(TX_TYPE.gaMeta, params);
|
|
287
|
-
|
|
288
|
-
case 29:
|
|
289
|
-
_yield$this$prepareTx = _context3.sent;
|
|
290
|
-
fee = _yield$this$prepareTx.fee;
|
|
291
|
-
// Build META tx
|
|
292
|
-
_buildTx = buildTx(_objectSpread(_objectSpread({}, params), {}, {
|
|
293
|
-
fee: "".concat(fee)
|
|
294
|
-
}), TX_TYPE.gaMeta, {
|
|
295
|
-
vsn: 2
|
|
296
|
-
}), metaTxRlp = _buildTx.rlpEncoded; // Wrap in empty signed tx
|
|
297
|
-
|
|
298
|
-
_wrapInEmptySignedTx2 = wrapInEmptySignedTx(metaTxRlp), tx = _wrapInEmptySignedTx2.tx; // Send tx to the chain
|
|
299
|
-
|
|
300
|
-
return _context3.abrupt("return", tx);
|
|
301
|
-
|
|
302
|
-
case 34:
|
|
303
|
-
case "end":
|
|
304
|
-
return _context3.stop();
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
}, _callee3, this);
|
|
308
|
-
}));
|
|
309
|
-
return _createMetaTx.apply(this, arguments);
|
|
133
|
+
async function createMetaTx(rawTransaction, authData, authFnName) {
|
|
134
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
135
|
+
if (!authData) throw new Error('authData is required'); // Check if authData is callData or if it's an object prepare a callData from source and args
|
|
136
|
+
|
|
137
|
+
const {
|
|
138
|
+
authCallData,
|
|
139
|
+
gas
|
|
140
|
+
} = await prepareGaParams(this)(authData, authFnName);
|
|
141
|
+
const opt = { ...this.Ae.defaults,
|
|
142
|
+
...options
|
|
143
|
+
};
|
|
144
|
+
const {
|
|
145
|
+
abiVersion
|
|
146
|
+
} = await this.getVmVersion(TX_TYPE.contractCall);
|
|
147
|
+
const wrappedTx = wrapInEmptySignedTx(unpackTx(rawTransaction));
|
|
148
|
+
const params = { ...opt,
|
|
149
|
+
tx: { ...wrappedTx,
|
|
150
|
+
tx: wrappedTx.txObject
|
|
151
|
+
},
|
|
152
|
+
gaId: await this.address(opt),
|
|
153
|
+
abiVersion: abiVersion,
|
|
154
|
+
authData: authCallData,
|
|
155
|
+
gas,
|
|
156
|
+
vsn: 2
|
|
157
|
+
};
|
|
158
|
+
const {
|
|
159
|
+
fee
|
|
160
|
+
} = await this.prepareTxParams(TX_TYPE.gaMeta, params);
|
|
161
|
+
const {
|
|
162
|
+
rlpEncoded: metaTxRlp
|
|
163
|
+
} = buildTx({ ...params,
|
|
164
|
+
fee: `${fee}`
|
|
165
|
+
}, TX_TYPE.gaMeta, {
|
|
166
|
+
vsn: 2
|
|
167
|
+
});
|
|
168
|
+
return wrapInEmptySignedTx(metaTxRlp).tx;
|
|
310
169
|
}
|
|
311
170
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/contract/ga/index.js"],"names":["ContractAPI","TX_TYPE","buildTx","
|
|
1
|
+
{"version":3,"sources":["../../../src/contract/ga/index.js"],"names":["ContractAPI","TX_TYPE","buildTx","unpackTx","prepareGaParams","hash","GeneralizeAccount","compose","methods","createGeneralizeAccount","createMetaTx","isGA","address","contractId","getAccount","authFnName","source","args","options","opt","Ae","defaults","ownerId","Error","tx","gaAttachTx","code","contractCompile","bytecode","callData","contractEncodeCallDataAPI","authFun","transaction","rawTx","send","Object","freeze","owner","gaContractId","wrapInEmptySignedTx","encodedTx","signatures","signed","rawTransaction","authData","authCallData","gas","abiVersion","getVmVersion","contractCall","wrappedTx","params","txObject","gaId","vsn","fee","prepareTxParams","gaMeta","rlpEncoded","metaTxRlp"],"mappings":"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","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Generalize Account module - routines to use generalize account\n *\n * @module @aeternity/aepp-sdk/es/contract/ga\n * @export GeneralizeAccount\n * @example import { GeneralizeAccount } from '@aeternity/aepp-sdk'\n */\nimport { ContractAPI } from '../../ae/contract'\nimport { TX_TYPE } from '../../tx/builder/schema'\nimport { buildTx, unpackTx } from '../../tx/builder'\nimport { prepareGaParams } from './helpers'\nimport { hash } from '../../utils/crypto'\n\n/**\n * GeneralizeAccount Stamp\n *\n * Provide Generalize Account implementation\n * {@link module:@aeternity/aepp-sdk/es/contract/ga} clients.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/contract/ga\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} GeneralizeAccount instance\n * @example\n * const authContract = ``\n * await client.createGeneralizeAccount(authFnName, authContract, [...authFnArguments]\n * // Make spend using GA\n * const callData = 'cb_...' // encoded call data for auth contract\n * await client.spend(10000, receiverPub, { authData: { callData } })\n * // or\n * await client.spend(10000, receiverPub, {\n * authData: { source: authContract, args: [...authContractArgs] }\n * }) // sdk will prepare callData itself\n */\nexport const GeneralizeAccount = ContractAPI.compose({\n methods: {\n createGeneralizeAccount,\n createMetaTx,\n isGA\n }\n})\nexport default GeneralizeAccount\n\n/**\n * @alias module:@aeternity/aepp-sdk/es/contract/ga\n * @function\n * Check if account is GA account\n * @param {String} address - Account address\n * @return {Boolean}\n */\nasync function isGA (address) {\n const { contractId } = await this.getAccount(address)\n return !!contractId\n}\n\n/**\n * Convert current account to GA account\n * @alias module:@aeternity/aepp-sdk/es/contract/ga\n * @function\n * @param {String} authFnName - Authorization function name\n * @param {String} source - Auth contract source code\n * @param {Array} [args] - init arguments\n * @param {Object} [options] - Options\n * @return {Promise<Readonly<{\n * result: *, owner: *, createdAt: Date, address, rawTx: *, transaction: *\n * }>>}\n */\nasync function createGeneralizeAccount (authFnName, source, args = [], options = {}) {\n const opt = { ...this.Ae.defaults, ...options }\n const ownerId = await this.address(opt)\n\n if (await this.isGA(ownerId)) throw new Error(`Account ${ownerId} is already GA`)\n\n const { tx, contractId } = await this.gaAttachTx({\n ...opt,\n ownerId,\n code: (await this.contractCompile(source)).bytecode,\n callData: await this.contractEncodeCallDataAPI(source, 'init', args),\n authFun: hash(authFnName)\n })\n\n const { hash: transaction, rawTx } = await this.send(tx, opt)\n\n return Object.freeze({\n owner: ownerId,\n transaction,\n rawTx,\n gaContractId: contractId\n })\n}\n\nconst wrapInEmptySignedTx = (tx) => buildTx({ encodedTx: tx, signatures: [] }, TX_TYPE.signed)\n\n/**\n * Create a metaTx transaction\n * @alias module:@aeternity/aepp-sdk/es/contract/ga\n * @function\n * @param {String} rawTransaction Inner transaction\n * @param {Object} authData Object with gaMeta params\n * @param {String} authFnName - Authorization function name\n * @param {Object} options - Options\n * @return {String}\n */\nasync function createMetaTx (rawTransaction, authData, authFnName, options = {}) {\n if (!authData) throw new Error('authData is required')\n // Check if authData is callData or if it's an object prepare a callData from source and args\n const { authCallData, gas } = await prepareGaParams(this)(authData, authFnName)\n const opt = { ...this.Ae.defaults, ...options }\n const { abiVersion } = await this.getVmVersion(TX_TYPE.contractCall)\n const wrappedTx = wrapInEmptySignedTx(unpackTx(rawTransaction))\n const params = {\n ...opt,\n tx: {\n ...wrappedTx,\n tx: wrappedTx.txObject\n },\n gaId: await this.address(opt),\n abiVersion: abiVersion,\n authData: authCallData,\n gas,\n vsn: 2\n }\n const { fee } = await this.prepareTxParams(TX_TYPE.gaMeta, params)\n const { rlpEncoded: metaTxRlp } = buildTx(\n { ...params, fee: `${fee}` },\n TX_TYPE.gaMeta,\n { vsn: 2 }\n )\n return wrapInEmptySignedTx(metaTxRlp).tx\n}\n"],"file":"index.js"}
|