@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,211 +0,0 @@
|
|
|
1
|
-
import _defineProperty from "@babel/runtime-corejs3/helpers/defineProperty";
|
|
2
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
3
|
-
|
|
4
|
-
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; }
|
|
5
|
-
|
|
6
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { var _context4; _forEachInstanceProperty(_context4 = ownKeys(Object(source), true)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }); } else if (_Object$getOwnPropertyDescriptors) { _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)); } else { var _context5; _forEachInstanceProperty(_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
7
|
-
|
|
8
|
-
import _startsWithInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/starts-with";
|
|
9
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
10
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
11
|
-
import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
|
|
12
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
13
|
-
import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
|
|
14
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
15
|
-
import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
|
|
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
|
-
|
|
19
|
-
/*
|
|
20
|
-
* ISC License (ISC)
|
|
21
|
-
* Copyright (c) 2018 aeternity developers
|
|
22
|
-
*
|
|
23
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
24
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
25
|
-
* copyright notice and this permission notice appear in all copies.
|
|
26
|
-
*
|
|
27
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
28
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
29
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
30
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
31
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
32
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
33
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Browser window Post Message connector module
|
|
38
|
-
*
|
|
39
|
-
* This is the complement to {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
|
|
40
|
-
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message
|
|
41
|
-
* @export BrowserWindowMessageConnection
|
|
42
|
-
* @example import BrowserWindowMessageConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message'
|
|
43
|
-
*/
|
|
44
|
-
import stampit from '@stamp/it';
|
|
45
|
-
import WalletConnection from '.';
|
|
46
|
-
import { v4 as uuid } from 'uuid';
|
|
47
|
-
import { MESSAGE_DIRECTION } from '../schema';
|
|
48
|
-
import { getBrowserAPI, isInIframe } from '../helpers';
|
|
49
|
-
/**
|
|
50
|
-
* Check if connected
|
|
51
|
-
* @function isConnected
|
|
52
|
-
* @instance
|
|
53
|
-
* @rtype () => Boolean
|
|
54
|
-
* @return {Boolean} Is connected
|
|
55
|
-
*/
|
|
56
|
-
|
|
57
|
-
function isConnected() {
|
|
58
|
-
return this.listener;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Connect
|
|
62
|
-
* @function connect
|
|
63
|
-
* @instance
|
|
64
|
-
* @rtype (onMessage: Function) => void
|
|
65
|
-
* @param {Function} onMessage - Message handler
|
|
66
|
-
* @return {void}
|
|
67
|
-
*/
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
function connect(onMessage) {
|
|
71
|
-
var origin = this.origin;
|
|
72
|
-
var receiveDirection = this.receiveDirection;
|
|
73
|
-
var debug = this.debug;
|
|
74
|
-
var forceOrigin = this.forceOrigin;
|
|
75
|
-
if (this.listener) throw new Error('You already connected');
|
|
76
|
-
|
|
77
|
-
this.listener = function (msg, source) {
|
|
78
|
-
if (!msg || _typeof(msg.data) !== 'object') return;
|
|
79
|
-
if (!forceOrigin && origin && origin !== msg.origin) return;
|
|
80
|
-
if (debug) console.log('Receive message: ', msg);
|
|
81
|
-
|
|
82
|
-
if (msg.data.type) {
|
|
83
|
-
if (msg.data.type !== receiveDirection) return;
|
|
84
|
-
onMessage(msg.data.data, msg.origin, msg.source);
|
|
85
|
-
} else {
|
|
86
|
-
onMessage(msg.data, msg.origin, msg.source);
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
this.subscribeFn(this.listener);
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Disconnect
|
|
94
|
-
* @function disconnect
|
|
95
|
-
* @instance
|
|
96
|
-
* @rtype () => void
|
|
97
|
-
* @return {void}
|
|
98
|
-
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
function disconnect() {
|
|
102
|
-
if (!this.listener) throw new Error('You dont have connection. Please connect before');
|
|
103
|
-
this.unsubscribeFn(this.listener);
|
|
104
|
-
this.listener = null;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Send message
|
|
108
|
-
* @function sendMessage
|
|
109
|
-
* @instance
|
|
110
|
-
* @rtype (msg: Object) => void
|
|
111
|
-
* @param {Object} msg - Message
|
|
112
|
-
* @return {void}
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
function sendMessage(msg) {
|
|
117
|
-
var message = this.sendDirection ? {
|
|
118
|
-
type: this.sendDirection,
|
|
119
|
-
data: msg
|
|
120
|
-
} : msg;
|
|
121
|
-
if (this.debug) console.log('Send message: ', message);
|
|
122
|
-
this.postFn(message);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
var getTarget = function getTarget() {
|
|
126
|
-
var _context;
|
|
127
|
-
|
|
128
|
-
var isExtensionContext = _typeof(getBrowserAPI(true).extension) === 'object';
|
|
129
|
-
|
|
130
|
-
var isWeb = window && window.location && _startsWithInstanceProperty(_context = window.location.protocol).call(_context, 'http');
|
|
131
|
-
|
|
132
|
-
var isContentScript = isExtensionContext && isWeb;
|
|
133
|
-
if (isContentScript) return window; // When we is the main page we need to decide the target by our self
|
|
134
|
-
// Probably can be implemented some algo for checking DOM for Iframes and somehow decide which Iframe to talk
|
|
135
|
-
|
|
136
|
-
return isInIframe() ? window.parent : undefined;
|
|
137
|
-
};
|
|
138
|
-
/**
|
|
139
|
-
* BrowserWindowMessageConnection
|
|
140
|
-
* @function
|
|
141
|
-
* @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message
|
|
142
|
-
* @rtype Stamp
|
|
143
|
-
* @param {Object} [params={}] - Initializer object
|
|
144
|
-
* @param {Object} [params.target=window.parent] - Target window for message
|
|
145
|
-
* @param {Object} [params.self=window] - Host window for message
|
|
146
|
-
* @param {Object} [params.origin] - Origin of receiver
|
|
147
|
-
* @param {Object} [params.sendDirection] - Optional field for wrapping messages in additional structure({ type: 'to_aepp' || 'to_waellet', data }).Used for handling messages netween content script and page
|
|
148
|
-
* @param {Object} [params.receiveDirection='to_aepp'] - Optional(default: 'to_aepp') field for unwrapping messages from additional structure({ type: 'to_aepp' || 'to_waellet', data }).Used for handling messages netween content script and page
|
|
149
|
-
* @param {Object} [params.connectionInfo={}] - Connection info object
|
|
150
|
-
* @param {Boolean} [params.debug=false] - Debug flag
|
|
151
|
-
* @return {Object}
|
|
152
|
-
*/
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
export default stampit({
|
|
156
|
-
init: function init() {
|
|
157
|
-
var _context2,
|
|
158
|
-
_context3,
|
|
159
|
-
_this = this;
|
|
160
|
-
|
|
161
|
-
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
162
|
-
_ref$connectionInfo = _ref.connectionInfo,
|
|
163
|
-
connectionInfo = _ref$connectionInfo === void 0 ? {} : _ref$connectionInfo,
|
|
164
|
-
_ref$target = _ref.target,
|
|
165
|
-
target = _ref$target === void 0 ? getTarget() : _ref$target,
|
|
166
|
-
_ref$self = _ref.self,
|
|
167
|
-
self = _ref$self === void 0 ? window : _ref$self,
|
|
168
|
-
origin = _ref.origin,
|
|
169
|
-
sendDirection = _ref.sendDirection,
|
|
170
|
-
_ref$receiveDirection = _ref.receiveDirection,
|
|
171
|
-
receiveDirection = _ref$receiveDirection === void 0 ? MESSAGE_DIRECTION.to_aepp : _ref$receiveDirection,
|
|
172
|
-
_ref$debug = _ref.debug,
|
|
173
|
-
debug = _ref$debug === void 0 ? false : _ref$debug,
|
|
174
|
-
_ref$forceOrigin = _ref.forceOrigin,
|
|
175
|
-
forceOrigin = _ref$forceOrigin === void 0 ? false : _ref$forceOrigin;
|
|
176
|
-
|
|
177
|
-
if (sendDirection && !_includesInstanceProperty(_context2 = _Object$keys(MESSAGE_DIRECTION)).call(_context2, sendDirection)) throw new Error("sendDirection must be one of [".concat(_Object$keys(MESSAGE_DIRECTION), "]"));
|
|
178
|
-
if (!_includesInstanceProperty(_context3 = _Object$keys(MESSAGE_DIRECTION)).call(_context3, receiveDirection)) throw new Error("receiveDirection must be one of [".concat(_Object$keys(MESSAGE_DIRECTION), "]"));
|
|
179
|
-
this.connectionInfo = _objectSpread({
|
|
180
|
-
id: uuid()
|
|
181
|
-
}, connectionInfo);
|
|
182
|
-
var selfP = self;
|
|
183
|
-
var targetP = target;
|
|
184
|
-
this.origin = origin;
|
|
185
|
-
this.debug = debug;
|
|
186
|
-
this.forceOrigin = forceOrigin;
|
|
187
|
-
this.sendDirection = sendDirection;
|
|
188
|
-
this.receiveDirection = receiveDirection;
|
|
189
|
-
|
|
190
|
-
this.subscribeFn = function (listener) {
|
|
191
|
-
return selfP.addEventListener('message', listener, false);
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
this.unsubscribeFn = function (listener) {
|
|
195
|
-
return selfP.removeEventListener('message', listener, false);
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
this.postFn = function (msg) {
|
|
199
|
-
return targetP.postMessage(msg, _this.origin || '*');
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
if (!this.connectionInfo.id) throw new Error('ID required.');
|
|
203
|
-
},
|
|
204
|
-
methods: {
|
|
205
|
-
connect: connect,
|
|
206
|
-
sendMessage: sendMessage,
|
|
207
|
-
disconnect: disconnect,
|
|
208
|
-
isConnected: isConnected
|
|
209
|
-
}
|
|
210
|
-
}, WalletConnection);
|
|
211
|
-
//# sourceMappingURL=browser-window-message.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/aepp-wallet-communication/connection/browser-window-message.js"],"names":["stampit","WalletConnection","v4","uuid","MESSAGE_DIRECTION","getBrowserAPI","isInIframe","isConnected","listener","connect","onMessage","origin","receiveDirection","debug","forceOrigin","Error","msg","source","data","console","log","type","subscribeFn","disconnect","unsubscribeFn","sendMessage","message","sendDirection","postFn","getTarget","isExtensionContext","extension","isWeb","window","location","protocol","isContentScript","parent","undefined","init","connectionInfo","target","self","to_aepp","id","selfP","targetP","addEventListener","removeEventListener","postMessage","methods"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;AACA,OAAOC,gBAAP,MAA6B,GAA7B;AACA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A0B,SAA1B,EAAqCxC,QAArC,EAA+C,KAA/C,CAAd;AAAA,KAArB;;AACA,SAAKoB,MAAL,GAAc,UAACZ,GAAD;AAAA,aAAS8B,OAAO,CAACG,WAAR,CAAoBjC,GAApB,EAAyB,KAAI,CAACL,MAAL,IAAe,GAAxC,CAAT;AAAA,KAAd;;AACA,QAAI,CAAC,KAAK6B,cAAL,CAAoBI,EAAzB,EAA6B,MAAM,IAAI7B,KAAJ,CAAU,cAAV,CAAN;AAC9B,GAjBoB;AAkBrBmC,EAAAA,OAAO,EAAE;AAAEzC,IAAAA,OAAO,EAAPA,OAAF;AAAWgB,IAAAA,WAAW,EAAXA,WAAX;AAAwBF,IAAAA,UAAU,EAAVA,UAAxB;AAAoChB,IAAAA,WAAW,EAAXA;AAApC;AAlBY,CAAD,EAmBnBN,gBAnBmB,CAAtB","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 * Browser window Post Message connector module\n *\n * This is the complement to {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.\n * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message\n * @export BrowserWindowMessageConnection\n * @example import BrowserWindowMessageConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message'\n */\nimport stampit from '@stamp/it'\nimport WalletConnection from '.'\nimport { v4 as uuid } from 'uuid'\nimport { MESSAGE_DIRECTION } from '../schema'\nimport { getBrowserAPI, isInIframe } from '../helpers'\n\n/**\n * Check if connected\n * @function isConnected\n * @instance\n * @rtype () => Boolean\n * @return {Boolean} Is connected\n */\nfunction isConnected () {\n return this.listener\n}\n\n/**\n * Connect\n * @function connect\n * @instance\n * @rtype (onMessage: Function) => void\n * @param {Function} onMessage - Message handler\n * @return {void}\n */\nfunction connect (onMessage) {\n const origin = this.origin\n const receiveDirection = this.receiveDirection\n const debug = this.debug\n const forceOrigin = this.forceOrigin\n if (this.listener) throw new Error('You already connected')\n\n this.listener = (msg, source) => {\n if (!msg || typeof msg.data !== 'object') return\n if (!forceOrigin && origin && origin !== msg.origin) return\n if (debug) console.log('Receive message: ', msg)\n if (msg.data.type) {\n if (msg.data.type !== receiveDirection) return\n onMessage(msg.data.data, msg.origin, msg.source)\n } else {\n onMessage(msg.data, msg.origin, msg.source)\n }\n }\n this.subscribeFn(this.listener)\n}\n\n/**\n * Disconnect\n * @function disconnect\n * @instance\n * @rtype () => void\n * @return {void}\n */\nfunction disconnect () {\n if (!this.listener) throw new Error('You dont have connection. Please connect before')\n this.unsubscribeFn(this.listener)\n this.listener = null\n}\n\n/**\n * Send message\n * @function sendMessage\n * @instance\n * @rtype (msg: Object) => void\n * @param {Object} msg - Message\n * @return {void}\n */\nfunction sendMessage (msg) {\n const message = this.sendDirection ? { type: this.sendDirection, data: msg } : msg\n if (this.debug) console.log('Send message: ', message)\n this.postFn(message)\n}\n\nconst getTarget = () => {\n const isExtensionContext = typeof getBrowserAPI(true).extension === 'object'\n const isWeb = window && window.location && window.location.protocol.startsWith('http')\n const isContentScript = isExtensionContext && isWeb\n if (isContentScript) return window\n // When we is the main page we need to decide the target by our self\n // Probably can be implemented some algo for checking DOM for Iframes and somehow decide which Iframe to talk\n return isInIframe() ? window.parent : undefined\n}\n\n/**\n * BrowserWindowMessageConnection\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message\n * @rtype Stamp\n * @param {Object} [params={}] - Initializer object\n * @param {Object} [params.target=window.parent] - Target window for message\n * @param {Object} [params.self=window] - Host window for message\n * @param {Object} [params.origin] - Origin of receiver\n * @param {Object} [params.sendDirection] - Optional field for wrapping messages in additional structure({ type: 'to_aepp' || 'to_waellet', data }).Used for handling messages netween content script and page\n * @param {Object} [params.receiveDirection='to_aepp'] - Optional(default: 'to_aepp') field for unwrapping messages from additional structure({ type: 'to_aepp' || 'to_waellet', data }).Used for handling messages netween content script and page\n * @param {Object} [params.connectionInfo={}] - Connection info object\n * @param {Boolean} [params.debug=false] - Debug flag\n * @return {Object}\n */\nexport default stampit({\n init ({ connectionInfo = {}, target = getTarget(), self = window, origin, sendDirection, receiveDirection = MESSAGE_DIRECTION.to_aepp, debug = false, forceOrigin = false } = {}) {\n if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new Error(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)\n if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new Error(`receiveDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)\n this.connectionInfo = { id: uuid(), ...connectionInfo }\n\n const selfP = self\n const targetP = target\n this.origin = origin\n this.debug = debug\n this.forceOrigin = forceOrigin\n this.sendDirection = sendDirection\n this.receiveDirection = receiveDirection\n this.subscribeFn = (listener) => selfP.addEventListener('message', listener, false)\n this.unsubscribeFn = (listener) => selfP.removeEventListener('message', listener, false)\n this.postFn = (msg) => targetP.postMessage(msg, this.origin || '*')\n if (!this.connectionInfo.id) throw new Error('ID required.')\n },\n methods: { connect, sendMessage, disconnect, isConnected }\n}, WalletConnection)\n"],"file":"browser-window-message.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/utils/aepp-wallet-communication/connection/index.js"],"names":["required","methods","connect","disconnect","sendMessage","isConnected"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,SAASA,QAAT,QAAyB,iBAAzB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeA,QAAQ,CAAC;AACtBC,EAAAA,OAAO,EAAE;AACPC,IAAAA,OAAO,EAAEF,QADF;AAEPG,IAAAA,UAAU,EAAEH,QAFL;AAGPI,IAAAA,WAAW,EAAEJ,QAHN;AAIPK,IAAAA,WAAW,EAAEL;AAJN;AADa,CAAD,CAAvB;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","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 * Wallet Connection base module\n * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection\n * @export WalletConnection\n * @example import WalletConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection'\n */\n\nimport { required } from '@stamp/required'\n\n/**\n * Basic Wallet Connection\n *\n * This stamp include interface for wallet connection functionality.\n * Attempting to create instances from the Stamp without overwriting all\n * abstract methods using composition will result in an exception.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @return {Object} WalletConnection instance\n */\nexport default required({\n methods: {\n connect: required,\n disconnect: required,\n sendMessage: required,\n isConnected: required\n }\n})\n\n/**\n * Connect\n * @function connect\n * @instance\n * @abstract\n * @rtype (onMessage: Function) => void\n * @param {Function} onMessage - Message handler\n * @return {void}\n */\n\n/**\n * Disconnect\n * @function disconnect\n * @instance\n * @abstract\n * @rtype () => void\n * @return {void}\n */\n\n/**\n * Send message\n * @function sendMessage\n * @instance\n * @abstract\n * @rtype (msg: Object) => void\n * @param {Object} msg - Message\n * @return {void}\n */\n\n/**\n * Check if connected\n * @function isConnected\n * @instance\n * @abstract\n * @rtype () => Boolean\n * @return {Boolean} Is connected\n */\n"],"file":"index.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/content-script-bridge.js"],"names":["stampit","run","allowCrossOrigin","extConnection","connect","msg","pageConnection","sendMessage","origin","source","window","stop","disconnect","init","Error","methods"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,GAAT,GAAgB;AAAA;;AACd,MAAMC,gBAAgB,GAAG,KAAK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\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 * Content Script Bridge module\n *\n * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge\n * @export ContentScriptBridge\n * @example import ContentScriptBridge from '@aeternity/aepp-sdk/es/utils/wallet-communication/content-script-bridge\n */\nimport stampit from '@stamp/it'\n\n/**\n * Start message proxy\n * @function run\n * @instance\n * @return {void}\n */\nfunction run () {\n const allowCrossOrigin = this.allowCrossOrigin\n // Connect to extension using runtime\n this.extConnection.connect((msg) => {\n this.pageConnection.sendMessage(msg)\n })\n // Connect to page using window.postMessage\n this.pageConnection.connect((msg, origin, source) => {\n if (!allowCrossOrigin && source !== window) return\n this.extConnection.sendMessage(msg)\n })\n}\n\n/**\n * Stop message proxy\n * @function stop\n * @instance\n * @return {void}\n */\nfunction stop () {\n this.extConnection.disconnect()\n this.pageConnection.disconnect()\n}\n\n/**\n * ContentScriptBridge stamp\n * Provide functionality to easly redirect messages from page to extension and from extension to page through content script\n * Using Runtime(Extension) and WindowPostMessage(Web-Page) connections\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge\n * @rtype Stamp\n * @param {Object} params - Initializer object\n * @param {Object} params.pageConnection - Page connection object(@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message)\n * @param {Object} params.extConnection - Extension connection object(module: @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime)\n * @return {Object}\n */\nexport default stampit({\n init ({ pageConnection, extConnection, allowCrossOrigin = false }) {\n if (!window) throw new Error('Window object not found, you can run bridge only in browser')\n if (!pageConnection) throw new Error('pageConnection required')\n if (!extConnection) throw new Error('extConnection required')\n this.allowCrossOrigin = allowCrossOrigin\n this.pageConnection = pageConnection\n this.extConnection = extConnection\n },\n methods: { run, stop }\n})\n"],"file":"content-script-bridge.js"}
|
|
@@ -1,148 +0,0 @@
|
|
|
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
|
-
/**
|
|
20
|
-
* Browser helper functions
|
|
21
|
-
*/
|
|
22
|
-
import { isAccountBase } from '../../account/base';
|
|
23
|
-
export var getBrowserAPI = function getBrowserAPI() {
|
|
24
|
-
var force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
|
25
|
-
var _window = window,
|
|
26
|
-
chrome = _window.chrome,
|
|
27
|
-
browser = _window.browser; // Chrome, Opera support
|
|
28
|
-
|
|
29
|
-
if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome; // Firefox support
|
|
30
|
-
|
|
31
|
-
if (typeof browser !== 'undefined' && browser === Object(browser)) return browser;
|
|
32
|
-
if (!force) throw new Error('Browser is not detected');
|
|
33
|
-
return {};
|
|
34
|
-
};
|
|
35
|
-
export var isInIframe = function isInIframe() {
|
|
36
|
-
return window !== window.parent;
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* RPC helper functions
|
|
40
|
-
*/
|
|
41
|
-
|
|
42
|
-
export var sendMessage = function sendMessage(connection) {
|
|
43
|
-
var messageId = 0;
|
|
44
|
-
return function (_ref) {
|
|
45
|
-
var id = _ref.id,
|
|
46
|
-
method = _ref.method,
|
|
47
|
-
params = _ref.params,
|
|
48
|
-
result = _ref.result,
|
|
49
|
-
error = _ref.error;
|
|
50
|
-
var isNotificationOrResponse = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
51
|
-
// Increment id for each request
|
|
52
|
-
isNotificationOrResponse || (messageId += 1);
|
|
53
|
-
id = isNotificationOrResponse ? id || null : messageId;
|
|
54
|
-
var msgData = params ? {
|
|
55
|
-
params: params
|
|
56
|
-
} : result ? {
|
|
57
|
-
result: result
|
|
58
|
-
} : {
|
|
59
|
-
error: error
|
|
60
|
-
};
|
|
61
|
-
connection.sendMessage(_objectSpread(_objectSpread({
|
|
62
|
-
jsonrpc: '2.0'
|
|
63
|
-
}, id ? {
|
|
64
|
-
id: id
|
|
65
|
-
} : {}), {}, {
|
|
66
|
-
method: method
|
|
67
|
-
}, msgData));
|
|
68
|
-
return id;
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
export var getHandler = function getHandler(schema, msg) {
|
|
72
|
-
var _ref2 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
73
|
-
_ref2$debug = _ref2.debug,
|
|
74
|
-
debug = _ref2$debug === void 0 ? false : _ref2$debug;
|
|
75
|
-
|
|
76
|
-
var handler = schema[msg.method];
|
|
77
|
-
|
|
78
|
-
if (!handler || typeof handler !== 'function') {
|
|
79
|
-
debug && console.log("Unknown message method ".concat(msg.method));
|
|
80
|
-
return function () {
|
|
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
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return handler;
|
|
99
|
-
};
|
|
100
|
-
export var message = function message(method) {
|
|
101
|
-
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
102
|
-
return {
|
|
103
|
-
method: method,
|
|
104
|
-
params: params
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
export var responseMessage = function responseMessage(id, method) {
|
|
108
|
-
var _ref4 = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
|
|
109
|
-
error = _ref4.error,
|
|
110
|
-
result = _ref4.result;
|
|
111
|
-
|
|
112
|
-
return _objectSpread({
|
|
113
|
-
id: id,
|
|
114
|
-
method: method
|
|
115
|
-
}, error ? {
|
|
116
|
-
error: error
|
|
117
|
-
} : {
|
|
118
|
-
result: result
|
|
119
|
-
});
|
|
120
|
-
};
|
|
121
|
-
export var sendResponseMessage = function sendResponseMessage(client) {
|
|
122
|
-
return function (id, method, data) {
|
|
123
|
-
return client.sendMessage(responseMessage(id, method, data), true);
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
export var voidFn = function voidFn() {
|
|
127
|
-
return undefined;
|
|
128
|
-
};
|
|
129
|
-
export var isValidAccounts = function isValidAccounts(accounts) {
|
|
130
|
-
var _context2;
|
|
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] : {};
|
|
138
|
-
|
|
139
|
-
if (!_findInstanceProperty(addresses).call(addresses, function (a) {
|
|
140
|
-
return a === onAccount;
|
|
141
|
-
})) {
|
|
142
|
-
if (_typeof(opt.onAccount) !== 'object' || !isAccountBase(opt.onAccount)) throw new Error('Provided onAccount should be an AccountBase');
|
|
143
|
-
onAccount = opt.onAccount;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return onAccount;
|
|
147
|
-
};
|
|
148
|
-
//# sourceMappingURL=helpers.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/helpers.js"],"names":["isAccountBase","getBrowserAPI","force","window","chrome","browser","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","accounts","k","length","resolveOnAccount","addresses","onAccount","opt","a"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA,SAASA,aAAT,QAA8B,oBAA9B;AAEA,OAAO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,GAAmB;AAAA,MAAlBC,KAAkB,uEAAV,KAAU;AAC9C,gBAA4BC,MAA5B;AAAA,MAAQC,MAAR,WAAQA,MAAR;AAAA,MAAgBC,OAAhB,WAAgBA,OAAhB,CAD8C,CAE9C;;AACA,MAAI,OAAOD,MAAP,KAAkB,WAAlB,IAAiCA,MAAM,KAAKE,MAAM,CAACF,MAAD,CAAtD,EAAgE,OAAOA,MAAP,CAHlB,CAI9C;;AACA,MAAI,OAAOC,OAAP,KAAmB,WAAnB,IAAkCA,OAAO,KAAKC,MAAM,CAACD,OAAD,CAAxD,EAAmE,OAAOA,OAAP;AACnE,MAAI,CAACH,KAAL,EAAY,MAAM,IAAIK,KAAJ,CAAU,yBAAV,CAAN;AACZ,SAAO,EAAP;AACD,CARM;AAUP,OAAO,IAAMC,UAAU,GAAG,SAAbA,UAAa;A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AAL,EAAkB,SAAlB,mBAAoC,UAAAC,CAAC;AAAA,WAAI,QAAQA,CAAC,GAAGD,QAAQ,CAACC,CAAD,CAAX,GAAiBD,QAA1B,MAAwC,QAA5C;AAAA,GAArC,CAAD,CAA6FE,MAA7F,KAAwG,CAAtH;AAAA,CAAxB;AAEP,OAAO,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAmB,CAACC,SAAD,EAAYC,SAAZ,EAAoC;AAAA,MAAbC,GAAa,uEAAP,EAAO;;AAClE,MAAI,CAAC,sBAAAF,SAAS,MAAT,CAAAA,SAAS,EAAM,UAAAG,CAAC;AAAA,WAAIA,CAAC,KAAKF,SAAV;AAAA,GAAP,CAAd,EAA2C;AACzC,QAAI,QAAOC,GAAG,CAACD,SAAX,MAAyB,QAAzB,IAAqC,CAACzC,aAAa,CAAC0C,GAAG,CAACD,SAAL,CAAvD,EAAwE,MAAM,IAAIlC,KAAJ,CAAU,6CAAV,CAAN;AACxEkC,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"}
|