@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.1
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 +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 +33 -119
- 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 +75 -154
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +164 -599
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +108 -916
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +89 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +132 -500
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +4 -23
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +292 -1018
- 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 +203 -451
- 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 +319 -491
- 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 +129 -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 +102 -247
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +1 -1
- package/es/contract/index.js.map +1 -1
- package/es/index.js +2 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +54 -73
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +56 -157
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +49 -89
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +205 -303
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +585 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +1 -1
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +105 -135
- 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 +17 -21
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
- 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 +179 -510
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
- 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 +49 -75
- 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 +85 -218
- package/es/utils/swagger.js.map +1 -1
- package/package.json +52 -43
- package/src/account/base.js +8 -9
- package/src/account/multiple.js +20 -16
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +65 -246
- package/src/ae/index.js +31 -7
- package/src/ae/oracle.js +21 -17
- package/src/chain/index.js +2 -12
- package/src/chain/node.js +26 -29
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -106
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +2 -12
- package/src/contract/ga/index.js +22 -26
- package/src/index.js +2 -4
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/helpers.js +12 -24
- package/src/tx/builder/index.js +18 -15
- package/src/tx/builder/schema.js +43 -108
- package/src/tx/tx-object.js +0 -2
- package/src/tx/tx.js +157 -144
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -17
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +24 -7
- package/CHANGELOG.md +0 -1716
- package/src/contract/aci/helpers.js +0 -140
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
2
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
3
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
4
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
5
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
6
|
-
import _Object$defineProperties from "@babel/runtime-corejs3/core-js-stable/object/define-properties";
|
|
7
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
|
8
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
9
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
10
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
11
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
12
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
13
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
14
|
-
|
|
15
|
-
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); if (enumerableOnly) { symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
16
|
-
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context3; _forEachInstanceProperty(_context3 = ownKeys(Object(source), true)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
18
|
-
|
|
19
1
|
/**
|
|
20
2
|
* Browser helper functions
|
|
21
3
|
*/
|
|
22
4
|
import { isAccountBase } from '../../account/base';
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
export const getBrowserAPI = function () {
|
|
6
|
+
let force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
7
|
+
const {
|
|
8
|
+
chrome,
|
|
9
|
+
browser
|
|
10
|
+
} = window; // Chrome, Opera support
|
|
28
11
|
|
|
29
12
|
if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome; // Firefox support
|
|
30
13
|
|
|
@@ -32,114 +15,86 @@ export var getBrowserAPI = function getBrowserAPI() {
|
|
|
32
15
|
if (!force) throw new Error('Browser is not detected');
|
|
33
16
|
return {};
|
|
34
17
|
};
|
|
35
|
-
export
|
|
36
|
-
return window !== window.parent;
|
|
37
|
-
};
|
|
18
|
+
export const isInIframe = () => window !== window.parent;
|
|
38
19
|
/**
|
|
39
20
|
* RPC helper functions
|
|
40
21
|
*/
|
|
41
22
|
|
|
42
|
-
export
|
|
43
|
-
|
|
23
|
+
export const sendMessage = connection => {
|
|
24
|
+
let messageId = 0;
|
|
44
25
|
return function (_ref) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
26
|
+
let {
|
|
27
|
+
id,
|
|
28
|
+
method,
|
|
29
|
+
params,
|
|
30
|
+
result,
|
|
31
|
+
error
|
|
32
|
+
} = _ref;
|
|
33
|
+
let isNotificationOrResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
51
34
|
// Increment id for each request
|
|
52
35
|
isNotificationOrResponse || (messageId += 1);
|
|
53
36
|
id = isNotificationOrResponse ? id || null : messageId;
|
|
54
|
-
|
|
55
|
-
params
|
|
37
|
+
const msgData = params ? {
|
|
38
|
+
params
|
|
56
39
|
} : result ? {
|
|
57
|
-
result
|
|
40
|
+
result
|
|
58
41
|
} : {
|
|
59
|
-
error
|
|
42
|
+
error
|
|
60
43
|
};
|
|
61
|
-
connection.sendMessage(
|
|
62
|
-
jsonrpc: '2.0'
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
method
|
|
67
|
-
|
|
44
|
+
connection.sendMessage({
|
|
45
|
+
jsonrpc: '2.0',
|
|
46
|
+
...(id ? {
|
|
47
|
+
id
|
|
48
|
+
} : {}),
|
|
49
|
+
method,
|
|
50
|
+
...msgData
|
|
51
|
+
});
|
|
68
52
|
return id;
|
|
69
53
|
};
|
|
70
54
|
};
|
|
71
|
-
export
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var handler = schema[msg.method];
|
|
55
|
+
export const getHandler = function (schema, msg) {
|
|
56
|
+
let {
|
|
57
|
+
debug = false
|
|
58
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
59
|
+
const handler = schema[msg.method];
|
|
77
60
|
|
|
78
61
|
if (!handler || typeof handler !== 'function') {
|
|
79
|
-
debug && console.log(
|
|
80
|
-
return
|
|
81
|
-
return /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
82
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
83
|
-
while (1) {
|
|
84
|
-
switch (_context.prev = _context.next) {
|
|
85
|
-
case 0:
|
|
86
|
-
return _context.abrupt("return", true);
|
|
87
|
-
|
|
88
|
-
case 1:
|
|
89
|
-
case "end":
|
|
90
|
-
return _context.stop();
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}, _callee);
|
|
94
|
-
}));
|
|
95
|
-
};
|
|
62
|
+
debug && console.log(`Unknown message method ${msg.method}`);
|
|
63
|
+
return () => async () => true;
|
|
96
64
|
}
|
|
97
65
|
|
|
98
66
|
return handler;
|
|
99
67
|
};
|
|
100
|
-
export
|
|
101
|
-
|
|
68
|
+
export const message = function (method) {
|
|
69
|
+
let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
102
70
|
return {
|
|
103
|
-
method
|
|
104
|
-
params
|
|
71
|
+
method,
|
|
72
|
+
params
|
|
105
73
|
};
|
|
106
74
|
};
|
|
107
|
-
export
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return
|
|
113
|
-
id
|
|
114
|
-
method
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
export var sendResponseMessage = function sendResponseMessage(client) {
|
|
122
|
-
return function (id, method, data) {
|
|
123
|
-
return client.sendMessage(responseMessage(id, method, data), true);
|
|
75
|
+
export const responseMessage = function (id, method) {
|
|
76
|
+
let {
|
|
77
|
+
error,
|
|
78
|
+
result
|
|
79
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
80
|
+
return {
|
|
81
|
+
id,
|
|
82
|
+
method,
|
|
83
|
+
...(error ? {
|
|
84
|
+
error
|
|
85
|
+
} : {
|
|
86
|
+
result
|
|
87
|
+
})
|
|
124
88
|
};
|
|
125
89
|
};
|
|
126
|
-
export
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
export
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return _filterInstanceProperty(_context2 = ['', 'connected', 'current']).call(_context2, function (k) {
|
|
133
|
-
return _typeof(k ? accounts[k] : accounts) === 'object';
|
|
134
|
-
}).length === 3;
|
|
135
|
-
};
|
|
136
|
-
export var resolveOnAccount = function resolveOnAccount(addresses, onAccount) {
|
|
137
|
-
var opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
90
|
+
export const sendResponseMessage = client => (id, method, data) => client.sendMessage(responseMessage(id, method, data), true);
|
|
91
|
+
export const voidFn = () => undefined;
|
|
92
|
+
export const isValidAccounts = accounts => ['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object').length === 3;
|
|
93
|
+
export const resolveOnAccount = function (addresses, onAccount) {
|
|
94
|
+
let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
138
95
|
|
|
139
|
-
if (!
|
|
140
|
-
|
|
141
|
-
})) {
|
|
142
|
-
if (_typeof(opt.onAccount) !== 'object' || !isAccountBase(opt.onAccount)) throw new Error('Provided onAccount should be an AccountBase');
|
|
96
|
+
if (!addresses.find(a => a === onAccount)) {
|
|
97
|
+
if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new Error('Provided onAccount should be an AccountBase');
|
|
143
98
|
onAccount = opt.onAccount;
|
|
144
99
|
}
|
|
145
100
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/helpers.js"],"names":["isAccountBase","getBrowserAPI","force","
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/helpers.js"],"names":["isAccountBase","getBrowserAPI","force","chrome","browser","window","Object","Error","isInIframe","parent","sendMessage","connection","messageId","id","method","params","result","error","isNotificationOrResponse","msgData","jsonrpc","getHandler","schema","msg","debug","handler","console","log","message","responseMessage","sendResponseMessage","client","data","voidFn","undefined","isValidAccounts","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,MAAL,EAAakB,IAAb,CAAlC,EAAsD,IAAtD,CAA9D;AAEP,OAAO,MAAMC,MAAM,GAAG,MAAMC,SAArB;AAEP,OAAO,MAAMC,eAAe,GAAIC,QAAD,IAAe,CAAC,EAAD,EAAK,WAAL,EAAkB,SAAlB,EAA6BC,MAA7B,CAAoCC,CAAC,IAAI,QAAQA,CAAC,GAAGF,QAAQ,CAACE,CAAD,CAAX,GAAiBF,QAA1B,MAAwC,QAAjF,CAAD,CAA6FG,MAA7F,KAAwG,CAA9I;AAEP,OAAO,MAAMC,gBAAgB,GAAG,UAACC,SAAD,EAAYC,SAAZ,EAAoC;AAAA,MAAbC,GAAa,uEAAP,EAAO;;AAClE,MAAI,CAACF,SAAS,CAACG,IAAV,CAAeC,CAAC,IAAIA,CAAC,KAAKH,SAA1B,CAAL,EAA2C;AACzC,QAAI,OAAOC,GAAG,CAACD,SAAX,KAAyB,QAAzB,IAAqC,CAAC1C,aAAa,CAAC2C,GAAG,CAACD,SAAL,CAAvD,EAAwE,MAAM,IAAInC,KAAJ,CAAU,6CAAV,CAAN;AACxEmC,IAAAA,SAAS,GAAGC,GAAG,CAACD,SAAhB;AACD;;AACD,SAAOA,SAAP;AACD,CANM","sourcesContent":["/**\n * Browser helper functions\n */\nimport { isAccountBase } from '../../account/base'\n\nexport const getBrowserAPI = (force = false) => {\n const { chrome, browser } = window\n // Chrome, Opera support\n if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome\n // Firefox support\n if (typeof browser !== 'undefined' && browser === Object(browser)) return browser\n if (!force) throw new Error('Browser is not detected')\n return {}\n}\n\nexport const isInIframe = () => window !== window.parent\n\n/**\n * RPC helper functions\n */\nexport const sendMessage = (connection) => {\n let messageId = 0\n\n return ({ id, method, params, result, error }, isNotificationOrResponse = false) => {\n // Increment id for each request\n isNotificationOrResponse || (messageId += 1)\n id = isNotificationOrResponse ? (id || null) : messageId\n const msgData = params\n ? { params }\n : result\n ? { result }\n : { error }\n connection.sendMessage({\n jsonrpc: '2.0',\n ...id ? { id } : {},\n method,\n ...msgData\n })\n return id\n }\n}\n\nexport const getHandler = (schema, msg, { debug = false } = {}) => {\n const handler = schema[msg.method]\n if (!handler || typeof handler !== 'function') {\n debug && console.log(`Unknown message method ${msg.method}`)\n return () => async () => true\n }\n return handler\n}\n\nexport const message = (method, params = {}) => ({ method, params })\n\nexport const responseMessage = (id, method, { error, result } = {}) => ({ id, method, ...(error ? { error } : { result }) })\n\nexport const sendResponseMessage = (client) => (id, method, data) => client.sendMessage(responseMessage(id, method, data), true)\n\nexport const voidFn = () => undefined\n\nexport const isValidAccounts = (accounts) => (['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object')).length === 3\n\nexport const resolveOnAccount = (addresses, onAccount, opt = {}) => {\n if (!addresses.find(a => a === onAccount)) {\n if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new Error('Provided onAccount should be an AccountBase')\n onAccount = opt.onAccount\n }\n return onAccount\n}\n"],"file":"helpers.js"}
|