@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
|
@@ -0,0 +1,183 @@
|
|
|
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
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Browser window Post Message connector module
|
|
20
|
+
*
|
|
21
|
+
* This is the complement to
|
|
22
|
+
* {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
|
|
23
|
+
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message
|
|
24
|
+
* @export BrowserWindowMessageConnection
|
|
25
|
+
* @example
|
|
26
|
+
* import BrowserWindowMessageConnection
|
|
27
|
+
* from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message'
|
|
28
|
+
*/
|
|
29
|
+
import stampit from '@stamp/it';
|
|
30
|
+
import WalletConnection from "./index.mjs";
|
|
31
|
+
import { v4 as uuid } from '@aeternity/uuid';
|
|
32
|
+
import { MESSAGE_DIRECTION } from "../schema.mjs";
|
|
33
|
+
import { getBrowserAPI, isInIframe } from "../helpers.mjs";
|
|
34
|
+
import { AlreadyConnectedError, NoWalletConnectedError, MessageDirectionError } from "../../errors.mjs";
|
|
35
|
+
/**
|
|
36
|
+
* Check if connected
|
|
37
|
+
* @function isConnected
|
|
38
|
+
* @instance
|
|
39
|
+
* @rtype () => Boolean
|
|
40
|
+
* @return {Boolean} Is connected
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
function isConnected() {
|
|
44
|
+
return this.listener;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Connect
|
|
48
|
+
* @function connect
|
|
49
|
+
* @instance
|
|
50
|
+
* @rtype (onMessage: Function) => void
|
|
51
|
+
* @param {Function} onMessage - Message handler
|
|
52
|
+
* @return {void}
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
function connect(onMessage) {
|
|
57
|
+
const origin = this.origin;
|
|
58
|
+
const receiveDirection = this.receiveDirection;
|
|
59
|
+
const debug = this.debug;
|
|
60
|
+
const forceOrigin = this.forceOrigin;
|
|
61
|
+
if (this.listener) throw new AlreadyConnectedError('You already connected');
|
|
62
|
+
|
|
63
|
+
this.listener = (msg, source) => {
|
|
64
|
+
if (!msg || typeof msg.data !== 'object') return;
|
|
65
|
+
if (!forceOrigin && origin && origin !== msg.origin) return;
|
|
66
|
+
if (debug) console.log('Receive message: ', msg);
|
|
67
|
+
|
|
68
|
+
if (msg.data.type) {
|
|
69
|
+
if (msg.data.type !== receiveDirection) return;
|
|
70
|
+
onMessage(msg.data.data, msg.origin, msg.source);
|
|
71
|
+
} else {
|
|
72
|
+
onMessage(msg.data, msg.origin, msg.source);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this.subscribeFn(this.listener);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Disconnect
|
|
80
|
+
* @function disconnect
|
|
81
|
+
* @instance
|
|
82
|
+
* @rtype () => void
|
|
83
|
+
* @return {void}
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
function disconnect() {
|
|
88
|
+
if (!this.listener) throw new NoWalletConnectedError('You dont have connection. Please connect before');
|
|
89
|
+
this.unsubscribeFn(this.listener);
|
|
90
|
+
this.listener = null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Send message
|
|
94
|
+
* @function sendMessage
|
|
95
|
+
* @instance
|
|
96
|
+
* @rtype (msg: Object) => void
|
|
97
|
+
* @param {Object} msg - Message
|
|
98
|
+
* @return {void}
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
function sendMessage(msg) {
|
|
103
|
+
const message = this.sendDirection ? {
|
|
104
|
+
type: this.sendDirection,
|
|
105
|
+
data: msg
|
|
106
|
+
} : msg;
|
|
107
|
+
if (this.debug) console.log('Send message: ', message);
|
|
108
|
+
this.postFn(message);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const getTarget = () => {
|
|
112
|
+
const isExtensionContext = typeof getBrowserAPI(true).extension === 'object';
|
|
113
|
+
const isWeb = window && window.location && window.location.protocol.startsWith('http');
|
|
114
|
+
const isContentScript = isExtensionContext && isWeb;
|
|
115
|
+
if (isContentScript) return window; // When we is the main page we need to decide the target by our self
|
|
116
|
+
// Probably can be implemented some algo for checking DOM for Iframes and somehow decide which
|
|
117
|
+
// Iframe to talk
|
|
118
|
+
|
|
119
|
+
return isInIframe() ? window.parent : undefined;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* BrowserWindowMessageConnection
|
|
123
|
+
* @function
|
|
124
|
+
* @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication\
|
|
125
|
+
* /connection/browser-window-message
|
|
126
|
+
* @rtype Stamp
|
|
127
|
+
* @param {Object} [params={}] - Initializer object
|
|
128
|
+
* @param {Object} [params.target=window.parent] - Target window for message
|
|
129
|
+
* @param {Object} [params.self=window] - Host window for message
|
|
130
|
+
* @param {Object} [params.origin] - Origin of receiver
|
|
131
|
+
* @param {String} [params.sendDirection] Wrapping messages into additional struct
|
|
132
|
+
* ({ type: 'to_aepp' || 'to_waellet', data })
|
|
133
|
+
* Used for handling messages between content script and page
|
|
134
|
+
* @param {String} [params.receiveDirection='to_aepp'] Unwrapping messages from additional struct
|
|
135
|
+
* ({ type: 'to_aepp' || 'to_waellet', data })
|
|
136
|
+
* Used for handling messages between content script and page
|
|
137
|
+
* @param {Object} [params.connectionInfo={}] - Connection info object
|
|
138
|
+
* @param {Boolean} [params.debug=false] - Debug flag
|
|
139
|
+
* @return {Object}
|
|
140
|
+
*/
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
export default stampit({
|
|
144
|
+
init() {
|
|
145
|
+
let {
|
|
146
|
+
connectionInfo = {},
|
|
147
|
+
target = getTarget(),
|
|
148
|
+
self = window,
|
|
149
|
+
origin,
|
|
150
|
+
sendDirection,
|
|
151
|
+
receiveDirection = MESSAGE_DIRECTION.to_aepp,
|
|
152
|
+
debug = false,
|
|
153
|
+
forceOrigin = false
|
|
154
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
155
|
+
if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new MessageDirectionError(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`);
|
|
156
|
+
if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new MessageDirectionError(`receiveDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`);
|
|
157
|
+
this.connectionInfo = {
|
|
158
|
+
id: uuid(),
|
|
159
|
+
...connectionInfo
|
|
160
|
+
};
|
|
161
|
+
const selfP = self;
|
|
162
|
+
const targetP = target;
|
|
163
|
+
this.origin = origin;
|
|
164
|
+
this.debug = debug;
|
|
165
|
+
this.forceOrigin = forceOrigin;
|
|
166
|
+
this.sendDirection = sendDirection;
|
|
167
|
+
this.receiveDirection = receiveDirection;
|
|
168
|
+
|
|
169
|
+
this.subscribeFn = listener => selfP.addEventListener('message', listener, false);
|
|
170
|
+
|
|
171
|
+
this.unsubscribeFn = listener => selfP.removeEventListener('message', listener, false);
|
|
172
|
+
|
|
173
|
+
this.postFn = msg => targetP.postMessage(msg, this.origin || '*');
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
methods: {
|
|
177
|
+
connect,
|
|
178
|
+
sendMessage,
|
|
179
|
+
disconnect,
|
|
180
|
+
isConnected
|
|
181
|
+
}
|
|
182
|
+
}, WalletConnection);
|
|
183
|
+
//# sourceMappingURL=browser-window-message.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/utils/aepp-wallet-communication/connection/browser-window-message.js"],"names":["stampit","WalletConnection","v4","uuid","MESSAGE_DIRECTION","getBrowserAPI","isInIframe","AlreadyConnectedError","NoWalletConnectedError","MessageDirectionError","isConnected","listener","connect","onMessage","origin","receiveDirection","debug","forceOrigin","msg","source","data","console","log","type","subscribeFn","disconnect","unsubscribeFn","sendMessage","message","sendDirection","postFn","getTarget","isExtensionContext","extension","isWeb","window","location","protocol","startsWith","isContentScript","parent","undefined","init","connectionInfo","target","self","to_aepp","Object","keys","includes","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;AACA;AACA;AACA,OAAOA,OAAP,MAAoB,WAApB;OACOC,gB;AACP,SAASC,EAAE,IAAIC,IAAf,QAA2B,iBAA3B;SACSC,iB;SACAC,a,EAAeC,U;SAEtBC,qB,EACAC,sB,EACAC,qB;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,WAAT,GAAwB;AACtB,SAAO,KAAKC,QAAZ;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,OAAT,CAAkBC,SAAlB,EAA6B;AAC3B,QAAMC,MAAM,GAAG,KAAKA,MAApB;AACA,QAAMC,gBAAgB,GAAG,KAAKA,gBAA9B;AACA,QAAMC,KAAK,GAAG,KAAKA,KAAnB;AACA,QAAMC,WAAW,GAAG,KAAKA,WAAzB;AACA,MAAI,KAAKN,QAAT,EAAmB,MAAM,IAAIJ,qBAAJ,CAA0B,uBAA1B,CAAN;;AAEnB,OAAKI,QAAL,GAAgB,CAACO,GAAD,EAAMC,MAAN,KAAiB;AAC/B,QAAI,CAACD,GAAD,IAAQ,OAAOA,GAAG,CAACE,IAAX,KAAoB,QAAhC,EAA0C;AA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cAAL,GAAsB;AAAEO,MAAAA,EAAE,EAAE/C,IAAI,EAAV;AAAc,SAAGwC;AAAjB,KAAtB;AAEA,UAAMQ,KAAK,GAAGN,IAAd;AACA,UAAMO,OAAO,GAAGR,MAAhB;AACA,SAAK9B,MAAL,GAAcA,MAAd;AACA,SAAKE,KAAL,GAAaA,KAAb;AACA,SAAKC,WAAL,GAAmBA,WAAnB;AACA,SAAKY,aAAL,GAAqBA,aAArB;AACA,SAAKd,gBAAL,GAAwBA,gBAAxB;;AACA,SAAKS,WAAL,GAAoBb,QAAD,IAAcwC,KAAK,CAACE,gBAAN,CAAuB,SAAvB,EAAkC1C,QAAlC,EAA4C,KAA5C,CAAjC;;AACA,SAAKe,aAAL,GAAsBf,QAAD,IAAcwC,KAAK,CAACG,mBAAN,CAA0B,SAA1B,EAAqC3C,QAArC,EAA+C,KAA/C,CAAnC;;AACA,SAAKmB,MAAL,GAAeZ,GAAD,IAASkC,OAAO,CAACG,WAAR,CAAoBrC,GAApB,EAAyB,KAAKJ,MAAL,IAAe,GAAxC,CAAvB;AACD,GAzBoB;;AA0BrB0C,EAAAA,OAAO,EAAE;AAAE5C,IAAAA,OAAF;AAAWe,IAAAA,WAAX;AAAwBF,IAAAA,UAAxB;AAAoCf,IAAAA;AAApC;AA1BY,CAAD,EA2BnBT,gBA3BmB,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\n * {@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\n * import BrowserWindowMessageConnection\n * 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 '@aeternity/uuid'\nimport { MESSAGE_DIRECTION } from '../schema'\nimport { getBrowserAPI, isInIframe } from '../helpers'\nimport {\n AlreadyConnectedError,\n NoWalletConnectedError,\n MessageDirectionError\n} from '../../errors'\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 AlreadyConnectedError('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 NoWalletConnectedError('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\n // 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\\\n * /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 {String} [params.sendDirection] Wrapping messages into additional struct\n * ({ type: 'to_aepp' || 'to_waellet', data })\n * Used for handling messages between content script and page\n * @param {String} [params.receiveDirection='to_aepp'] Unwrapping messages from additional struct\n * ({ type: 'to_aepp' || 'to_waellet', data })\n * Used for handling messages between 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 ({\n connectionInfo = {},\n target = getTarget(),\n self = window,\n origin,\n sendDirection,\n receiveDirection = MESSAGE_DIRECTION.to_aepp,\n debug = false,\n forceOrigin = false\n } = {}) {\n if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new MessageDirectionError(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)\n if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new MessageDirectionError(`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 },\n methods: { connect, sendMessage, disconnect, isConnected }\n}, WalletConnection)\n"],"file":"browser-window-message.mjs"}
|
|
@@ -19,9 +19,10 @@
|
|
|
19
19
|
* Wallet Connection base module
|
|
20
20
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection
|
|
21
21
|
* @export WalletConnection
|
|
22
|
-
* @example
|
|
22
|
+
* @example
|
|
23
|
+
* import WalletConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection'
|
|
23
24
|
*/
|
|
24
|
-
import
|
|
25
|
+
import _stampRequired from '@stamp/required';
|
|
25
26
|
/**
|
|
26
27
|
* Basic Wallet Connection
|
|
27
28
|
*
|
|
@@ -35,6 +36,9 @@ import { required } from '@stamp/required';
|
|
|
35
36
|
* @return {Object} WalletConnection instance
|
|
36
37
|
*/
|
|
37
38
|
|
|
39
|
+
const {
|
|
40
|
+
required
|
|
41
|
+
} = _stampRequired;
|
|
38
42
|
export default required({
|
|
39
43
|
methods: {
|
|
40
44
|
connect: required,
|
|
@@ -80,4 +84,4 @@ export default required({
|
|
|
80
84
|
* @rtype () => Boolean
|
|
81
85
|
* @return {Boolean} Is connected
|
|
82
86
|
*/
|
|
83
|
-
//# sourceMappingURL=index.
|
|
87
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AACA;AAEA,2BAAyB,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\n * 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.mjs"}
|
package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs}
RENAMED
|
@@ -20,9 +20,12 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge
|
|
22
22
|
* @export ContentScriptBridge
|
|
23
|
-
* @example
|
|
23
|
+
* @example
|
|
24
|
+
* import ContentScriptBridge
|
|
25
|
+
* from '@aeternity/aepp-sdk/es/utils/wallet-communication/content-script-bridge
|
|
24
26
|
*/
|
|
25
27
|
import stampit from '@stamp/it';
|
|
28
|
+
import { UnsupportedPlatformError, MissingParamError } from "../errors.mjs";
|
|
26
29
|
/**
|
|
27
30
|
* Start message proxy
|
|
28
31
|
* @function run
|
|
@@ -31,18 +34,15 @@ import stampit from '@stamp/it';
|
|
|
31
34
|
*/
|
|
32
35
|
|
|
33
36
|
function run() {
|
|
34
|
-
|
|
37
|
+
const allowCrossOrigin = this.allowCrossOrigin; // Connect to extension using runtime
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.extConnection.connect(function (msg) {
|
|
39
|
-
_this.pageConnection.sendMessage(msg);
|
|
39
|
+
this.extConnection.connect(msg => {
|
|
40
|
+
this.pageConnection.sendMessage(msg);
|
|
40
41
|
}); // Connect to page using window.postMessage
|
|
41
42
|
|
|
42
|
-
this.pageConnection.connect(
|
|
43
|
+
this.pageConnection.connect((msg, origin, source) => {
|
|
43
44
|
if (!allowCrossOrigin && source !== window) return;
|
|
44
|
-
|
|
45
|
-
_this.extConnection.sendMessage(msg);
|
|
45
|
+
this.extConnection.sendMessage(msg);
|
|
46
46
|
});
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
@@ -59,34 +59,40 @@ function stop() {
|
|
|
59
59
|
}
|
|
60
60
|
/**
|
|
61
61
|
* ContentScriptBridge stamp
|
|
62
|
-
* Provide functionality to easly redirect messages from page to extension and from extension to
|
|
62
|
+
* Provide functionality to easly redirect messages from page to extension and from extension to
|
|
63
|
+
* page through content script
|
|
63
64
|
* Using Runtime(Extension) and WindowPostMessage(Web-Page) connections
|
|
64
65
|
* @function
|
|
65
66
|
* @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge
|
|
66
67
|
* @rtype Stamp
|
|
67
68
|
* @param {Object} params - Initializer object
|
|
68
|
-
* @param {Object} params.pageConnection - Page connection object
|
|
69
|
-
* @
|
|
69
|
+
* @param {Object} params.pageConnection - Page connection object
|
|
70
|
+
* (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/
|
|
71
|
+
* browser-window-message)
|
|
72
|
+
* @param {Object} params.extConnection - Extension connection object
|
|
73
|
+
* (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime)
|
|
70
74
|
* @return {Object}
|
|
71
75
|
*/
|
|
72
76
|
|
|
73
77
|
|
|
74
78
|
export default stampit({
|
|
75
|
-
init
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!
|
|
82
|
-
if (!
|
|
79
|
+
init(_ref) {
|
|
80
|
+
let {
|
|
81
|
+
pageConnection,
|
|
82
|
+
extConnection,
|
|
83
|
+
allowCrossOrigin = false
|
|
84
|
+
} = _ref;
|
|
85
|
+
if (!window) throw new UnsupportedPlatformError('Window object not found, you can run bridge only in browser');
|
|
86
|
+
if (!pageConnection) throw new MissingParamError('pageConnection required');
|
|
87
|
+
if (!extConnection) throw new MissingParamError('extConnection required');
|
|
83
88
|
this.allowCrossOrigin = allowCrossOrigin;
|
|
84
89
|
this.pageConnection = pageConnection;
|
|
85
90
|
this.extConnection = extConnection;
|
|
86
91
|
},
|
|
92
|
+
|
|
87
93
|
methods: {
|
|
88
|
-
run
|
|
89
|
-
stop
|
|
94
|
+
run,
|
|
95
|
+
stop
|
|
90
96
|
}
|
|
91
97
|
});
|
|
92
|
-
//# sourceMappingURL=content-script-bridge.
|
|
98
|
+
//# sourceMappingURL=content-script-bridge.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/content-script-bridge.js"],"names":["stampit","UnsupportedPlatformError","MissingParamError","run","allowCrossOrigin","extConnection","connect","msg","pageConnection","sendMessage","origin","source","window","stop","disconnect","init","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;AACA,OAAOA,OAAP,MAAoB,WAApB;SACSC,wB,EAA0BC,iB;AAEnC;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,GAAT,GAAgB;AACd,QAAMC,gBAAgB,GAAG,KAAKA,gBAA9B,CADc,CAEd;;AACA,OAAKC,aAAL,CAAmBC,OAAnB,CAA4BC,GAAD,IAAS;AAClC,SAAKC,cAAL,CAAoBC,WAApB,CAAgCF,GAAhC;AACD,GAFD,EAHc,CAMd;;AACA,OAAKC,cAAL,CAAoBF,OAApB,CAA4B,CAACC,GAAD,EAAMG,MAAN,EAAcC,MAAd,KAAyB;AACnD,QAAI,CAACP,gBAAD,IAAqBO,MAAM,KAAKC,MAApC,EAA4C;AAC5C,SAAKP,aAAL,CAAmBI,WAAnB,CAA+BF,GAA/B;AACD,GAHD;AAID;AAED;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,IAAT,GAAiB;AACf,OAAKR,aAAL,CAAmBS,UAAnB;AACA,OAAKN,cAAL,CAAoBM,UAApB;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAed,OAAO,CAAC;AACrBe,EAAAA,IAAI,OAA+D;AAAA,QAA7D;AAAEP,MAAAA,cAAF;AAAkBH,MAAAA,aAAlB;AAAiCD,MAAAA,gBAAgB,GAAG;AAApD,KAA6D;AACjE,QAAI,CAACQ,MAAL,EAAa,MAAM,IAAIX,wBAAJ,CAA6B,6DAA7B,CAAN;AACb,QAAI,CAACO,cAAL,EAAqB,MAAM,IAAIN,iBAAJ,CAAsB,yBAAtB,CAAN;AACrB,QAAI,CAACG,aAAL,EAAoB,MAAM,IAAIH,iBAAJ,CAAsB,wBAAtB,CAAN;AACpB,SAAKE,gBAAL,GAAwBA,gBAAxB;AACA,SAAKI,cAAL,GAAsBA,cAAtB;AACA,SAAKH,aAAL,GAAqBA,aAArB;AACD,GARoB;;AASrBW,EAAAA,OAAO,EAAE;AAAEb,IAAAA,GAAF;AAAOU,IAAAA;AAAP;AATY,CAAD,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 * Content Script Bridge module\n *\n * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge\n * @export ContentScriptBridge\n * @example\n * import ContentScriptBridge\n * from '@aeternity/aepp-sdk/es/utils/wallet-communication/content-script-bridge\n */\nimport stampit from '@stamp/it'\nimport { UnsupportedPlatformError, MissingParamError } from '../errors'\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\n * 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\n * (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/\n * browser-window-message)\n * @param {Object} params.extConnection - Extension connection object\n * (@link 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 UnsupportedPlatformError('Window object not found, you can run bridge only in browser')\n if (!pageConnection) throw new MissingParamError('pageConnection required')\n if (!extConnection) throw new MissingParamError('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.mjs"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser helper functions
|
|
3
|
+
*/
|
|
4
|
+
import { NoBrowserFoundError } from "../errors.mjs";
|
|
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
|
|
11
|
+
|
|
12
|
+
if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome; // Firefox support
|
|
13
|
+
|
|
14
|
+
if (typeof browser !== 'undefined' && browser === Object(browser)) return browser;
|
|
15
|
+
if (!force) throw new NoBrowserFoundError();
|
|
16
|
+
return {};
|
|
17
|
+
};
|
|
18
|
+
export const isInIframe = () => window !== window.parent;
|
|
19
|
+
/**
|
|
20
|
+
* RPC helper functions
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const sendMessage = connection => {
|
|
24
|
+
let messageId = 0;
|
|
25
|
+
return function (_ref) {
|
|
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;
|
|
34
|
+
// Increment id for each request
|
|
35
|
+
isNotificationOrResponse || (messageId += 1);
|
|
36
|
+
id = isNotificationOrResponse ? id || null : messageId;
|
|
37
|
+
const msgData = params ? {
|
|
38
|
+
params
|
|
39
|
+
} : result ? {
|
|
40
|
+
result
|
|
41
|
+
} : {
|
|
42
|
+
error
|
|
43
|
+
};
|
|
44
|
+
connection.sendMessage({
|
|
45
|
+
jsonrpc: '2.0',
|
|
46
|
+
...(id ? {
|
|
47
|
+
id
|
|
48
|
+
} : {}),
|
|
49
|
+
method,
|
|
50
|
+
...msgData
|
|
51
|
+
});
|
|
52
|
+
return id;
|
|
53
|
+
};
|
|
54
|
+
};
|
|
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];
|
|
60
|
+
|
|
61
|
+
if (!handler || typeof handler !== 'function') {
|
|
62
|
+
debug && console.log(`Unknown message method ${msg.method}`);
|
|
63
|
+
return () => async () => true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return handler;
|
|
67
|
+
};
|
|
68
|
+
export const message = function (method) {
|
|
69
|
+
let params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
70
|
+
return {
|
|
71
|
+
method,
|
|
72
|
+
params
|
|
73
|
+
};
|
|
74
|
+
};
|
|
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
|
+
})
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
export const sendResponseMessage = client => (id, method, data) => client.sendMessage(responseMessage(id, method, data), true);
|
|
91
|
+
export const isValidAccounts = accounts => ['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object').length === 3;
|
|
92
|
+
//# sourceMappingURL=helpers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/utils/aepp-wallet-communication/helpers.js"],"names":["NoBrowserFoundError","getBrowserAPI","force","chrome","browser","window","Object","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","isValidAccounts","accounts","filter","k","length"],"mappings":"AAAA;AACA;AACA;SACSA,mB;AAET,OAAO,MAAMC,aAAa,GAAG,YAAmB;AAAA,MAAlBC,KAAkB,uEAAV,KAAU;AAC9C,QAAM;AAAEC,IAAAA,MAAF;AAAUC,IAAAA;AAAV,MAAsBC,MAA5B,CAD8C,CAE9C;;AACA,MAAI,OAAOF,MAAP,KAAkB,WAAlB,IAAiCA,MAAM,KAAKG,MAAM,CAACH,MAAD,CAAtD,EAAgE,OAAOA,MAAP,CAHlB,CAI9C;;AACA,MAAI,OAAOC,OAAP,KAAmB,WAAnB,IAAkCA,OAAO,KAAKE,MAAM,CAACF,OAAD,CAAxD,EAAmE,OAAOA,OAAP;AACnE,MAAI,CAACF,KAAL,EAAY,MAAM,IAAIF,mBAAJ,EAAN;AACZ,SAAO,EAAP;AACD,CARM;AAUP,OAAO,MAAMO,UAAU,GAAG,MAAMF,MAAM,KAAKA,MAAM,CAACG,MAA3C;AAEP;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAIC,UAAD,IAAgB;AACzC,MAAIC,SAAS,GAAG,CAAhB;AAEA,SAAO,gBAA6E;AAAA,QAA5E;AAAEC,MAAAA,EAAF;AAAMC,MAAAA,MAAN;AAAcC,MAAAA,MAAd;AAAsBC,MAAAA,MAAtB;AAA8BC,MAAAA;AA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AAAA;AAAT,GAAb,uEAAiC,EAAjC;AAAA,SAC5B;AAAEH,IAAAA,EAAF;AAAMC,IAAAA,MAAN;AAAc,QAAIG,KAAK,GAAG;AAAEA,MAAAA;AAAF,KAAH,GAAe;AAAED,MAAAA;AAAF,KAAxB;AAAd,GAD4B;AAAA,CAAxB;AAGP,OAAO,MAAMc,mBAAmB,GAAIC,MAAD,IAAY,CAAClB,EAAD,EAAKC,MAAL,EAAakB,IAAb,KAC7CD,MAAM,CAACrB,WAAP,CAAmBmB,eAAe,CAAChB,EAAD,EAAKC,MAAL,EAAakB,IAAb,CAAlC,EAAsD,IAAtD,CADK;AAGP,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","sourcesContent":["/**\n * Browser helper functions\n */\nimport { NoBrowserFoundError } from '../errors'\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 NoBrowserFoundError()\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 } = {}) =>\n ({ id, method, ...(error ? { error } : { result }) })\n\nexport const sendResponseMessage = (client) => (id, method, data) =>\n client.sendMessage(responseMessage(id, method, data), true)\n\nexport const isValidAccounts = (accounts) => (['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object')).length === 3\n"],"file":"helpers.mjs"}
|