@aeternity/aepp-sdk 10.0.0-beta.1 → 11.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (250) hide show
  1. package/README.md +15 -14
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
  4. package/dist/aepp-sdk.browser-script.js.map +1 -1
  5. package/dist/aepp-sdk.browser.js +1 -1
  6. package/dist/aepp-sdk.browser.js.map +1 -1
  7. package/dist/aepp-sdk.js +1 -1
  8. package/dist/aepp-sdk.js.map +1 -1
  9. package/es/account/{base.js → base.mjs} +23 -11
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/{memory.js → memory.mjs} +29 -14
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/{multiple.js → multiple.mjs} +14 -11
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/{aens.js → aens.mjs} +69 -59
  16. package/es/ae/aens.mjs.map +1 -0
  17. package/es/ae/{aepp.js → aepp.mjs} +9 -9
  18. package/es/ae/aepp.mjs.map +1 -0
  19. package/es/ae/contract.mjs +159 -0
  20. package/es/ae/contract.mjs.map +1 -0
  21. package/es/ae/{index.js → index.mjs} +12 -10
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/{oracle.js → oracle.mjs} +37 -20
  24. package/es/ae/oracle.mjs.map +1 -0
  25. package/es/ae/{universal.js → universal.mjs} +10 -10
  26. package/es/ae/universal.mjs.map +1 -0
  27. package/es/ae/{wallet.js → wallet.mjs} +10 -10
  28. package/es/ae/wallet.mjs.map +1 -0
  29. package/es/aepp-wallet-communication/schema.d.ts +74 -0
  30. package/es/bignumber.d.ts +1 -7
  31. package/es/chain/{index.js → index.mjs} +28 -8
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/{node.js → node.mjs} +133 -90
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/{handlers.js → handlers.mjs} +18 -20
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +43 -22
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/{internal.js → internal.mjs} +51 -35
  40. package/es/channel/internal.mjs.map +1 -0
  41. package/es/contract/aci.mjs +477 -0
  42. package/es/contract/aci.mjs.map +1 -0
  43. package/es/contract/compiler.mjs +115 -0
  44. package/es/contract/compiler.mjs.map +1 -0
  45. package/es/contract/ga/helpers.mjs +30 -0
  46. package/es/contract/ga/helpers.mjs.map +1 -0
  47. package/es/contract/ga/{index.js → index.mjs} +40 -28
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/encoder.d.ts +26 -0
  50. package/es/errors.d.ts +284 -0
  51. package/es/index.mjs +57 -0
  52. package/es/index.mjs.map +1 -0
  53. package/es/node-pool/{index.js → index.mjs} +15 -12
  54. package/es/node-pool/index.mjs.map +1 -0
  55. package/es/{node.js → node.mjs} +17 -11
  56. package/es/node.mjs.map +1 -0
  57. package/es/tx/builder/constants.mjs +108 -0
  58. package/es/tx/builder/constants.mjs.map +1 -0
  59. package/es/tx/builder/field-types.mjs +74 -0
  60. package/es/tx/builder/field-types.mjs.map +1 -0
  61. package/es/tx/builder/helpers.mjs +321 -0
  62. package/es/tx/builder/helpers.mjs.map +1 -0
  63. package/es/tx/builder/{index.js → index.mjs} +92 -74
  64. package/es/tx/builder/index.mjs.map +1 -0
  65. package/es/tx/builder/{schema.js → schema.mjs} +16 -172
  66. package/es/tx/builder/schema.mjs.map +1 -0
  67. package/es/tx/{index.js → index.mjs} +106 -14
  68. package/es/tx/index.mjs.map +1 -0
  69. package/es/tx/{tx-object.js → tx-object.mjs} +31 -18
  70. package/es/tx/tx-object.mjs.map +1 -0
  71. package/es/tx/{tx.js → tx.mjs} +15 -14
  72. package/es/tx/tx.mjs.map +1 -0
  73. package/es/tx/{validator.js → validator.mjs} +72 -33
  74. package/es/tx/validator.mjs.map +1 -0
  75. package/es/typings/blakejs/index.d.mjs +2 -0
  76. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  77. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +10 -8
  78. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +25 -17
  80. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  82. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +15 -8
  84. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
  86. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +126 -72
  88. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +23 -14
  90. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +116 -91
  92. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  94. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  95. package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
  96. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  97. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
  98. package/es/utils/amount-formatter.mjs.map +1 -0
  99. package/es/utils/{async-init.js → async-init.mjs} +8 -11
  100. package/es/utils/async-init.mjs.map +1 -0
  101. package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
  102. package/es/utils/bignumber.mjs.map +1 -0
  103. package/es/utils/{bytes.js → bytes.mjs} +16 -8
  104. package/es/utils/bytes.mjs.map +1 -0
  105. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  106. package/es/utils/crypto-ts.mjs.map +1 -0
  107. package/es/utils/{crypto.js → crypto.mjs} +42 -156
  108. package/es/utils/crypto.mjs.map +1 -0
  109. package/es/utils/encoder.mjs +106 -0
  110. package/es/utils/encoder.mjs.map +1 -0
  111. package/es/utils/errors.mjs +689 -0
  112. package/es/utils/errors.mjs.map +1 -0
  113. package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
  114. package/es/utils/hd-wallet.mjs.map +1 -0
  115. package/es/utils/{json-big.js → json-big.mjs} +1 -1
  116. package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
  117. package/es/utils/{keystore.js → keystore.mjs} +63 -51
  118. package/es/utils/keystore.mjs.map +1 -0
  119. package/es/utils/{mptree.js → mptree.mjs} +21 -12
  120. package/es/utils/mptree.mjs.map +1 -0
  121. package/es/utils/{other.js → other.mjs} +2 -2
  122. package/es/utils/other.mjs.map +1 -0
  123. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  124. package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
  125. package/es/utils/{string.js → string.mjs} +1 -1
  126. package/es/utils/{string.js.map → string.mjs.map} +1 -1
  127. package/es/utils/{swagger.js → swagger.mjs} +49 -15
  128. package/es/utils/swagger.mjs.map +1 -0
  129. package/package.json +49 -58
  130. package/src/account/base.js +3 -1
  131. package/src/account/memory.js +13 -8
  132. package/src/account/multiple.js +16 -6
  133. package/src/ae/aens.js +52 -58
  134. package/src/ae/aepp.js +2 -2
  135. package/src/ae/contract.js +21 -154
  136. package/src/ae/index.js +6 -4
  137. package/src/ae/oracle.js +33 -14
  138. package/src/ae/universal.js +4 -2
  139. package/src/ae/wallet.js +2 -2
  140. package/src/chain/index.js +29 -6
  141. package/src/chain/node.js +95 -65
  142. package/src/channel/handlers.js +30 -20
  143. package/src/channel/index.js +46 -16
  144. package/src/channel/internal.js +35 -30
  145. package/src/contract/aci.js +376 -0
  146. package/src/contract/compiler.js +22 -113
  147. package/src/contract/ga/helpers.js +10 -6
  148. package/src/contract/ga/index.js +31 -24
  149. package/src/index.js +9 -8
  150. package/src/node-pool/index.js +13 -10
  151. package/src/node.js +11 -10
  152. package/src/tx/builder/constants.js +100 -0
  153. package/src/tx/builder/field-types.js +61 -0
  154. package/src/tx/builder/helpers.js +99 -103
  155. package/src/tx/builder/index.js +81 -40
  156. package/src/tx/builder/schema.js +44 -132
  157. package/src/tx/index.js +101 -12
  158. package/src/tx/tx-object.js +35 -15
  159. package/src/tx/tx.js +110 -35
  160. package/src/tx/validator.js +25 -5
  161. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  162. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  163. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  164. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  165. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  166. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +106 -57
  167. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  168. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +95 -53
  169. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  170. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  171. package/src/utils/amount-formatter.ts +4 -3
  172. package/src/utils/async-init.js +10 -6
  173. package/src/utils/bignumber.ts +1 -9
  174. package/src/utils/bytes.ts +3 -2
  175. package/src/utils/crypto-ts.ts +2 -2
  176. package/src/utils/crypto.js +11 -155
  177. package/src/utils/encoder.ts +101 -0
  178. package/src/utils/errors.ts +683 -0
  179. package/src/utils/hd-wallet.js +11 -26
  180. package/src/utils/keystore.js +57 -53
  181. package/src/utils/mptree.ts +12 -6
  182. package/src/utils/swagger.js +68 -45
  183. package/es/account/base.js.map +0 -1
  184. package/es/account/memory.js.map +0 -1
  185. package/es/account/multiple.js.map +0 -1
  186. package/es/ae/aens.js.map +0 -1
  187. package/es/ae/aepp.js.map +0 -1
  188. package/es/ae/contract.js +0 -308
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js.map +0 -1
  191. package/es/ae/oracle.js.map +0 -1
  192. package/es/ae/universal.js.map +0 -1
  193. package/es/ae/wallet.js.map +0 -1
  194. package/es/chain/index.js.map +0 -1
  195. package/es/chain/node.js.map +0 -1
  196. package/es/channel/handlers.js.map +0 -1
  197. package/es/channel/index.js.map +0 -1
  198. package/es/channel/internal.js.map +0 -1
  199. package/es/contract/aci/helpers.js +0 -298
  200. package/es/contract/aci/helpers.js.map +0 -1
  201. package/es/contract/aci/index.js +0 -356
  202. package/es/contract/aci/index.js.map +0 -1
  203. package/es/contract/aci/transformation.js +0 -66
  204. package/es/contract/aci/transformation.js.map +0 -1
  205. package/es/contract/compiler.js +0 -242
  206. package/es/contract/compiler.js.map +0 -1
  207. package/es/contract/ga/helpers.js +0 -22
  208. package/es/contract/ga/helpers.js.map +0 -1
  209. package/es/contract/ga/index.js.map +0 -1
  210. package/es/contract/index.js +0 -158
  211. package/es/contract/index.js.map +0 -1
  212. package/es/index.js +0 -56
  213. package/es/index.js.map +0 -1
  214. package/es/node-pool/index.js.map +0 -1
  215. package/es/node.js.map +0 -1
  216. package/es/tx/builder/helpers.js +0 -318
  217. package/es/tx/builder/helpers.js.map +0 -1
  218. package/es/tx/builder/index.js.map +0 -1
  219. package/es/tx/builder/schema.js.map +0 -1
  220. package/es/tx/index.js.map +0 -1
  221. package/es/tx/tx-object.js.map +0 -1
  222. package/es/tx/tx.js.map +0 -1
  223. package/es/tx/validator.js.map +0 -1
  224. package/es/typings/blakejs/index.d.js +0 -2
  225. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  226. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  227. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  228. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  229. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  230. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  231. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  232. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  233. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  234. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  235. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  236. package/es/utils/amount-formatter.js.map +0 -1
  237. package/es/utils/async-init.js.map +0 -1
  238. package/es/utils/bignumber.js.map +0 -1
  239. package/es/utils/bytes.js.map +0 -1
  240. package/es/utils/crypto-ts.js.map +0 -1
  241. package/es/utils/crypto.js.map +0 -1
  242. package/es/utils/hd-wallet.js.map +0 -1
  243. package/es/utils/keystore.js.map +0 -1
  244. package/es/utils/mptree.js.map +0 -1
  245. package/es/utils/other.js.map +0 -1
  246. package/es/utils/swagger.js.map +0 -1
  247. package/src/contract/aci/index.js +0 -310
  248. package/src/contract/aci/transformation.js +0 -72
  249. package/src/contract/index.js +0 -159
  250. package/src/utils/aepp-wallet-communication/schema.js +0 -108
@@ -1,8 +1,13 @@
1
- import { verify, hash } from '../utils/crypto';
2
- import { encode, decode } from './builder/helpers';
1
+ import _buffer from "buffer";
2
+ const {
3
+ Buffer: _Buffer
4
+ } = _buffer;
5
+ import { verify, hash } from "../utils/crypto.mjs";
6
+ import { encode, decode } from "./builder/helpers.mjs";
3
7
  import BigNumber from 'bignumber.js';
4
- import { MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE } from './builder/schema';
5
- import { calculateFee, unpackTx } from './builder';
8
+ import { MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE } from "./builder/schema.mjs";
9
+ import { calculateFee, unpackTx } from "./builder/index.mjs";
10
+ import { UnsupportedProtocolError } from "../utils/errors.mjs";
6
11
  /**
7
12
  * Transaction validator
8
13
  * @module @aeternity/aepp-sdk/es/tx/validator
@@ -10,7 +15,7 @@ import { calculateFee, unpackTx } from './builder';
10
15
  * @example import { verifyTransaction } from '@aeternity/aepp-sdk'
11
16
  */
12
17
 
13
- const validators = [async (_ref, _ref2) => {
18
+ const validators = [(_ref, _ref2) => {
14
19
  let {
15
20
  encodedTx,
16
21
  signatures
@@ -20,12 +25,15 @@ const validators = [async (_ref, _ref2) => {
20
25
  node,
21
26
  parentTxTypes
22
27
  } = _ref2;
23
- if ((encodedTx ?? signatures) === undefined) return [];
28
+ if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : signatures) === undefined) return [];
24
29
  if (signatures.length !== 1) return []; // TODO: Support multisignature?
25
30
 
26
- const prefix = Buffer.from([node.nodeNetworkId, ...(parentTxTypes.includes(TX_TYPE.payingFor) ? ['inner_tx'] : [])].join('-'));
27
- const txWithNetworkId = Buffer.concat([prefix, encodedTx.rlpEncoded]);
28
- const txHashWithNetworkId = Buffer.concat([prefix, hash(encodedTx.rlpEncoded)]);
31
+ const prefix = _Buffer.from([node.nodeNetworkId, ...(parentTxTypes.includes(TX_TYPE.payingFor) ? ['inner_tx'] : [])].join('-'));
32
+
33
+ const txWithNetworkId = _Buffer.concat([prefix, encodedTx.rlpEncoded]);
34
+
35
+ const txHashWithNetworkId = _Buffer.concat([prefix, hash(encodedTx.rlpEncoded)]);
36
+
29
37
  const decodedPub = decode(account.id, 'ak');
30
38
  if (verify(txWithNetworkId, signatures[0], decodedPub) || verify(txHashWithNetworkId, signatures[0], decodedPub)) return [];
31
39
  return [{
@@ -33,7 +41,7 @@ const validators = [async (_ref, _ref2) => {
33
41
  key: 'InvalidSignature',
34
42
  checkedKeys: ['encodedTx', 'signatures']
35
43
  }];
36
- }, async (_ref3, _ref4) => {
44
+ }, (_ref3, _ref4) => {
37
45
  let {
38
46
  encodedTx,
39
47
  tx
@@ -43,8 +51,8 @@ const validators = [async (_ref, _ref2) => {
43
51
  parentTxTypes,
44
52
  txType
45
53
  } = _ref4;
46
- if ((encodedTx ?? tx) === undefined) return [];
47
- return verifyTransaction(encode((encodedTx ?? tx).rlpEncoded, 'tx'), node, [...parentTxTypes, txType]);
54
+ if ((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx) === undefined) return [];
55
+ return verifyTransaction(encode((encodedTx !== null && encodedTx !== void 0 ? encodedTx : tx).rlpEncoded, 'tx'), node, [...parentTxTypes, txType]);
48
56
  }, (tx, _ref5) => {
49
57
  let {
50
58
  txType
@@ -78,6 +86,8 @@ const validators = [async (_ref, _ref2) => {
78
86
  checkedKeys: ['ttl']
79
87
  }];
80
88
  }, (_ref8, _ref9) => {
89
+ var _ref10;
90
+
81
91
  let {
82
92
  amount,
83
93
  fee,
@@ -89,7 +99,7 @@ const validators = [async (_ref, _ref2) => {
89
99
  parentTxTypes,
90
100
  txType
91
101
  } = _ref9;
92
- if ((amount ?? fee ?? nameFee) === undefined) return [];
102
+ if (((_ref10 = amount !== null && amount !== void 0 ? amount : fee) !== null && _ref10 !== void 0 ? _ref10 : nameFee) === undefined) return [];
93
103
  const cost = new BigNumber(fee).plus(nameFee || 0).plus(amount || 0).plus(txType === TX_TYPE.payingFor ? tx.tx.encodedTx.tx.fee : 0).minus(parentTxTypes.includes(TX_TYPE.payingFor) ? fee : 0);
94
104
  if (cost.lte(account.balance)) return [];
95
105
  return [{
@@ -97,14 +107,14 @@ const validators = [async (_ref, _ref2) => {
97
107
  key: 'InsufficientBalance',
98
108
  checkedKeys: ['amount', 'fee', 'nameFee']
99
109
  }];
100
- }, (_ref10, _ref11) => {
110
+ }, (_ref11, _ref12) => {
101
111
  let {
102
112
  nonce
103
- } = _ref10;
113
+ } = _ref11;
104
114
  let {
105
115
  account,
106
116
  parentTxTypes
107
- } = _ref11;
117
+ } = _ref12;
108
118
  if (nonce === undefined || parentTxTypes.includes(TX_TYPE.gaMeta)) return [];
109
119
  nonce = +nonce;
110
120
  const validNonce = account.nonce + 1;
@@ -118,10 +128,10 @@ const validators = [async (_ref, _ref2) => {
118
128
  }),
119
129
  checkedKeys: ['nonce']
120
130
  }];
121
- }, _ref12 => {
131
+ }, _ref13 => {
122
132
  let {
123
133
  gasPrice
124
- } = _ref12;
134
+ } = _ref13;
125
135
  if (gasPrice === undefined) return [];
126
136
  if (gasPrice >= MIN_GAS_PRICE) return [];
127
137
  return [{
@@ -129,20 +139,20 @@ const validators = [async (_ref, _ref2) => {
129
139
  key: 'MinGasPrice',
130
140
  checkedKeys: ['gasPrice']
131
141
  }];
132
- }, (_ref13, _ref14) => {
142
+ }, (_ref14, _ref15) => {
133
143
  let {
134
144
  ctVersion,
135
145
  abiVersion
136
- } = _ref13;
146
+ } = _ref14;
137
147
  let {
138
148
  txType,
139
149
  node
140
- } = _ref14;
150
+ } = _ref15;
141
151
  const {
142
152
  consensusProtocolVersion
143
153
  } = node.getNodeInfo();
144
154
  const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion];
145
- if (!protocol) throw new Error(`Unsupported protocol: ${consensusProtocolVersion}`); // If not contract create tx
155
+ if (!protocol) throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`); // If not contract create tx
146
156
 
147
157
  if (!ctVersion) ctVersion = {
148
158
  abiVersion
@@ -150,8 +160,8 @@ const validators = [async (_ref, _ref2) => {
150
160
  const txProtocol = protocol[txType];
151
161
  if (!txProtocol) return [];
152
162
 
153
- if (Object.entries(ctVersion).some(_ref15 => {
154
- let [key, value] = _ref15;
163
+ if (Object.entries(ctVersion).some(_ref16 => {
164
+ let [key, value] = _ref16;
155
165
  return !txProtocol[key].includes(+value);
156
166
  })) {
157
167
  return [{
@@ -162,6 +172,36 @@ const validators = [async (_ref, _ref2) => {
162
172
  }
163
173
 
164
174
  return [];
175
+ }, async (_ref17, _ref18) => {
176
+ let {
177
+ contractId
178
+ } = _ref17;
179
+ let {
180
+ txType,
181
+ node
182
+ } = _ref18;
183
+ if (TX_TYPE.contractCall !== txType) return [];
184
+
185
+ try {
186
+ const {
187
+ active
188
+ } = await node.api.getContract(contractId);
189
+ if (active) return [];
190
+ return [{
191
+ message: `Contract ${contractId} is not active`,
192
+ key: 'ContractNotActive',
193
+ checkedKeys: ['contractId']
194
+ }];
195
+ } catch (error) {
196
+ var _error$response, _error$response$body;
197
+
198
+ if (!((_error$response = error.response) !== null && _error$response !== void 0 && (_error$response$body = _error$response.body) !== null && _error$response$body !== void 0 && _error$response$body.reason)) throw error;
199
+ return [{
200
+ message: error.response.body.reason,
201
+ key: 'ContractNotFound',
202
+ checkedKeys: ['contractId']
203
+ }];
204
+ }
165
205
  }];
166
206
 
167
207
  const getSenderAddress = tx => ['senderId', 'accountId', 'ownerId', 'callerId', 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'].map(key => tx[key]).filter(a => a).map(a => a.replace(/^ok_/, 'ak_'))[0];
@@ -181,22 +221,21 @@ const getSenderAddress = tx => ['senderId', 'accountId', 'ownerId', 'callerId',
181
221
 
182
222
 
183
223
  export default async function verifyTransaction(transaction, node) {
224
+ var _getSenderAddress;
225
+
184
226
  let parentTxTypes = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
185
227
  const {
186
228
  tx,
187
229
  txType
188
230
  } = unpackTx(transaction);
189
- const address = getSenderAddress(tx) ?? (txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : null);
190
- const [account, height] = await Promise.all([address && node.api.getAccountByPubkey(address).catch(() => ({
231
+ const address = (_getSenderAddress = getSenderAddress(tx)) !== null && _getSenderAddress !== void 0 ? _getSenderAddress : txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : null;
232
+ const [account, {
233
+ height
234
+ }] = await Promise.all([address && node.api.getAccountByPubkey(address).catch(() => ({
191
235
  id: address,
192
236
  balance: new BigNumber(0),
193
237
  nonce: 0
194
- })), node.api.getCurrentKeyBlockHeight().then(_ref16 => {
195
- let {
196
- height
197
- } = _ref16;
198
- return height;
199
- })]);
238
+ })), node.api.getCurrentKeyBlockHeight()]);
200
239
  return (await Promise.all(validators.map(v => v(tx, {
201
240
  txType,
202
241
  node,
@@ -205,4 +244,4 @@ export default async function verifyTransaction(transaction, node) {
205
244
  parentTxTypes
206
245
  })))).flat();
207
246
  }
208
- //# sourceMappingURL=validator.js.map
247
+ //# sourceMappingURL=validator.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/tx/validator.js"],"names":["verify","hash","encode","decode","BigNumber","MIN_GAS_PRICE","PROTOCOL_VM_ABI","TX_TYPE","calculateFee","unpackTx","UnsupportedProtocolError","validators","encodedTx","signatures","account","node","parentTxTypes","undefined","length","prefix","from","nodeNetworkId","includes","payingFor","join","txWithNetworkId","concat","rlpEncoded","txHashWithNetworkId","decodedPub","id","message","key","checkedKeys","tx","txType","verifyTransaction","fee","minFee","gas","params","showWarning","vsn","VSN","lte","ttl","height","amount","nameFee","cost","plus","minus","balance","toFixed","nonce","gaMeta","validNonce","gasPrice","ctVersion","abiVersion","consensusProtocolVersion","getNodeInfo","protocol","txProtocol","Object","entries","some","value","JSON","stringify","contractId","contractCall","active","api","getContract","error","response","body","reason","getSenderAddress","map","filter","a","replace","transaction","address","signed","Promise","all","getAccountByPubkey","catch","getCurrentKeyBlockHeight","v","flat"],"mappings":";;;;SAASA,M,EAAQC,I;SACRC,M,EAAQC,M;AAEjB,OAAOC,SAAP,MAAsB,cAAtB;SACSC,a,EAAeC,e,EAAiBC,O;SAChCC,Y,EAAcC,Q;SACdC,wB;AAET;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMC,UAAU,GAAG,CACjB,iBAAiE;AAAA,MAAhE;AAAEC,IAAAA,SAAF;AAAaC,IAAAA;AAAb,GAAgE;AAAA,MAArC;AAAEC,IAAAA,OAAF;AAAWC,IAAAA,IA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AAQ,CAAC2E,WAAD,CAA/B;AAEA,QAAMC,OAAO,wBAAGN,gBAAgB,CAAC7C,EAAD,CAAnB,iEACVC,MAAM,KAAK5B,OAAO,CAAC+E,MAAnB,GAA4BP,gBAAgB,CAAC7C,EAAE,CAACtB,SAAH,CAAasB,EAAd,CAA5C,GAAgE,IADnE;AAEA,QAAM,CAACpB,OAAD,EAAU;AAAEgC,IAAAA;AAAF,GAAV,IAAwB,MAAMyC,OAAO,CAACC,GAAR,CAAY,CAC9CH,OAAO,IAAItE,IAAI,CAAC0D,GAAL,CAASgB,kBAAT,CAA4BJ,OAA5B,EAAqCK,KAArC,CAA2C,OAAO;AAC3D5D,IAAAA,EAAE,EAAEuD,OADuD;AAE3DjC,IAAAA,OAAO,EAAE,IAAIhD,SAAJ,CAAc,CAAd,CAFkD;AAG3DkD,IAAAA,KAAK,EAAE;AAHoD,GAAP,CAA3C,CADmC,EAM9CvC,IAAI,CAAC0D,GAAL,CAASkB,wBAAT,EAN8C,CAAZ,CAApC;AASA,SAAO,CAAC,MAAMJ,OAAO,CAACC,GAAR,CACZ7E,UAAU,CAACqE,GAAX,CAAeY,CAAC,IAAIA,CAAC,CAAC1D,EAAD,EAAK;AAAEC,IAAAA,MAAF;AAAUpB,IAAAA,IAAV;AAAgBD,IAAAA,OAAhB;AAAyBgC,IAAAA,MAAzB;AAAiC9B,IAAAA;AAAjC,GAAL,CAArB,CADY,CAAP,EAEL6E,IAFK,EAAP;AAGD","sourcesContent":["import { verify, hash } from '../utils/crypto'\nimport { encode, decode } from './builder/helpers'\n\nimport BigNumber from 'bignumber.js'\nimport { MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE } from './builder/schema'\nimport { calculateFee, unpackTx } from './builder'\nimport { UnsupportedProtocolError } from '../utils/errors'\n\n/**\n * Transaction validator\n * @module @aeternity/aepp-sdk/es/tx/validator\n * @export verifyTransaction\n * @example import { verifyTransaction } from '@aeternity/aepp-sdk'\n */\n\nconst validators = [\n ({ encodedTx, signatures }, { account, node, parentTxTypes }) => {\n if ((encodedTx ?? signatures) === undefined) return []\n if (signatures.length !== 1) return [] // TODO: Support multisignature?\n const prefix = Buffer.from([\n node.nodeNetworkId,\n ...parentTxTypes.includes(TX_TYPE.payingFor) ? ['inner_tx'] : []\n ].join('-'))\n const txWithNetworkId = Buffer.concat([prefix, encodedTx.rlpEncoded])\n const txHashWithNetworkId = Buffer.concat([prefix, hash(encodedTx.rlpEncoded)])\n const decodedPub = decode(account.id, 'ak')\n if (verify(txWithNetworkId, signatures[0], decodedPub) ||\n verify(txHashWithNetworkId, signatures[0], decodedPub)) return []\n return [{\n message: 'Signature cannot be verified, please ensure that you transaction have' +\n ' the correct prefix and the correct private key for the sender address',\n key: 'InvalidSignature',\n checkedKeys: ['encodedTx', 'signatures']\n }]\n },\n ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {\n if ((encodedTx ?? tx) === undefined) return []\n return verifyTransaction(\n encode((encodedTx ?? tx).rlpEncoded, 'tx'),\n node,\n [...parentTxTypes, txType]\n )\n },\n (tx, { txType }) => {\n if (tx.fee === undefined) return []\n const minFee = calculateFee(0, txType, {\n gas: +tx.gas || 0, params: tx, showWarning: false, vsn: tx.VSN\n })\n if (new BigNumber(minFee).lte(tx.fee)) return []\n return [{\n message: `Fee ${tx.fee} is too low, minimum fee for this transaction is ${minFee}`,\n key: 'InsufficientFee',\n checkedKeys: ['fee']\n }]\n },\n ({ ttl }, { height }) => {\n if (ttl === undefined) return []\n ttl = +ttl\n if (ttl === 0 || ttl >= height) return []\n return [{\n message: `TTL ${ttl} is already expired, current height is ${height}`,\n key: 'ExpiredTTL',\n checkedKeys: ['ttl']\n }]\n },\n ({ amount, fee, nameFee, tx }, { account, parentTxTypes, txType }) => {\n if ((amount ?? fee ?? nameFee) === undefined) return []\n const cost = new BigNumber(fee).plus(nameFee || 0).plus(amount || 0)\n .plus(txType === TX_TYPE.payingFor ? tx.tx.encodedTx.tx.fee : 0)\n .minus(parentTxTypes.includes(TX_TYPE.payingFor) ? fee : 0)\n if (cost.lte(account.balance)) return []\n return [{\n message: `Account balance ${account.balance} is not enough to execute the transaction that costs ${cost.toFixed()}`,\n key: 'InsufficientBalance',\n checkedKeys: ['amount', 'fee', 'nameFee']\n }]\n },\n ({ nonce }, { account, parentTxTypes }) => {\n if (nonce === undefined || parentTxTypes.includes(TX_TYPE.gaMeta)) return []\n nonce = +nonce\n const validNonce = account.nonce + 1\n if (nonce === validNonce) return []\n return [{\n ...nonce < validNonce\n ? {\n message: `Nonce ${nonce} is already used, valid nonce is ${validNonce}`,\n key: 'NonceAlreadyUsed'\n }\n : {\n message: `Nonce ${nonce} is too high, valid nonce is ${validNonce}`,\n key: 'NonceHigh'\n },\n checkedKeys: ['nonce']\n }]\n },\n ({ gasPrice }) => {\n if (gasPrice === undefined) return []\n if (gasPrice >= MIN_GAS_PRICE) return []\n return [{\n message: `Gas price ${gasPrice} must be bigger then ${MIN_GAS_PRICE}`,\n key: 'MinGasPrice',\n checkedKeys: ['gasPrice']\n }]\n },\n ({ ctVersion, abiVersion }, { txType, node }) => {\n const { consensusProtocolVersion } = node.getNodeInfo()\n const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion]\n if (!protocol) throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`)\n // If not contract create tx\n if (!ctVersion) ctVersion = { abiVersion }\n const txProtocol = protocol[txType]\n if (!txProtocol) return []\n if (Object.entries(ctVersion).some(([key, value]) => !txProtocol[key].includes(+value))) {\n return [{\n message: `ABI/VM version ${JSON.stringify(ctVersion)} is wrong, supported is: ${JSON.stringify(txProtocol)}`,\n key: 'VmAndAbiVersionMismatch',\n checkedKeys: ['ctVersion', 'abiVersion']\n }]\n }\n return []\n },\n async ({ contractId }, { txType, node }) => {\n if (TX_TYPE.contractCall !== txType) return []\n try {\n const { active } = await node.api.getContract(contractId)\n if (active) return []\n return [{\n message: `Contract ${contractId} is not active`,\n key: 'ContractNotActive',\n checkedKeys: ['contractId']\n }]\n } catch (error) {\n if (!error.response?.body?.reason) throw error\n return [{\n message: error.response.body.reason,\n key: 'ContractNotFound',\n checkedKeys: ['contractId']\n }]\n }\n }\n]\n\nconst getSenderAddress = tx => [\n 'senderId', 'accountId', 'ownerId', 'callerId',\n 'oracleId', 'fromId', 'initiator', 'gaId', 'payerId'\n]\n .map(key => tx[key])\n .filter(a => a)\n .map(a => a.replace(/^ok_/, 'ak_'))[0]\n\n/**\n * Transaction Validator\n * This function validates some of transaction properties,\n * to make sure it can be posted it to the chain\n * @function\n * @alias module:@aeternity/aepp-sdk/es/tx/validator\n * @rtype (tx: String, node) => void\n * @param {String} transaction Base64Check-encoded transaction\n * @param {Object} node Node to validate transaction against\n * @param {String[]} [parentTxTypes] Types of parent transactions\n * @return {Promise<Object[]>} Array with verification errors\n * @example const errors = await verifyTransaction(transaction, node)\n */\nexport default async function verifyTransaction (transaction, node, parentTxTypes = []) {\n const { tx, txType } = unpackTx(transaction)\n\n const address = getSenderAddress(tx) ??\n (txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : null)\n const [account, { height }] = await Promise.all([\n address && node.api.getAccountByPubkey(address).catch(() => ({\n id: address,\n balance: new BigNumber(0),\n nonce: 0\n })),\n node.api.getCurrentKeyBlockHeight()\n ])\n\n return (await Promise.all(\n validators.map(v => v(tx, { txType, node, account, height, parentTxTypes })))\n ).flat()\n}\n"],"file":"validator.mjs"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=index.d.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"index.d.js"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"index.d.mjs"}
@@ -18,14 +18,16 @@
18
18
  /**
19
19
  * Browser runtime connector module
20
20
  *
21
- * This is the complement to {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
21
+ * This is the complement to
22
+ * {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
22
23
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime
23
24
  * @export BrowserRuntimeConnection
24
- * @example import BrowserRuntimeConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime'
25
+ * @example import { BrowserRuntimeConnection } from '@aeternity/aepp-sdk'
25
26
  */
26
27
  import stampit from '@stamp/it';
27
- import WalletConnection from '.';
28
- import { getBrowserAPI } from '../helpers';
28
+ import WalletConnection from "./index.mjs";
29
+ import { getBrowserAPI } from "../helpers.mjs";
30
+ import { RpcConnectionError, AlreadyConnectedError, NoWalletConnectedError } from "../../errors.mjs";
29
31
  /**
30
32
  * Disconnect
31
33
  * @function disconnect
@@ -53,7 +55,7 @@ function disconnect() {
53
55
 
54
56
 
55
57
  function connect(onMessage, onDisconnect) {
56
- if (this.isConnected()) throw new Error('You already connected');
58
+ if (this.isConnected()) throw new AlreadyConnectedError('You already connected');
57
59
 
58
60
  this.handler = (msg, source) => {
59
61
  if (this.debug) console.log('Receive message: ', msg);
@@ -77,7 +79,7 @@ function connect(onMessage, onDisconnect) {
77
79
 
78
80
 
79
81
  function sendMessage(msg) {
80
- if (!this.port) throw new Error('You dont have connection. Please connect before');
82
+ if (!this.port) throw new NoWalletConnectedError('You dont have connection. Please connect before');
81
83
  if (this.debug) console.log('Send message: ', msg);
82
84
  this.port.postMessage(msg);
83
85
  }
@@ -114,7 +116,7 @@ export default stampit({
114
116
  port,
115
117
  debug = false
116
118
  } = _ref;
117
- if (!getBrowserAPI().runtime) throw new Error('Runtime is not accessible in your environment');
119
+ if (!getBrowserAPI().runtime) throw new RpcConnectionError('Runtime is not accessible in your environment');
118
120
  this.debug = debug;
119
121
  this.connectionInfo = connectionInfo;
120
122
  this.port = port || getBrowserAPI().runtime.connect(...[connectionInfo.id || undefined]);
@@ -127,4 +129,4 @@ export default stampit({
127
129
  isConnected
128
130
  }
129
131
  }, WalletConnection);
130
- //# sourceMappingURL=browser-runtime.js.map
132
+ //# sourceMappingURL=browser-runtime.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/utils/aepp-wallet-communication/connection/browser-runtime.js"],"names":["stampit","WalletConnection","getBrowserAPI","RpcConnectionError","AlreadyConnectedError","NoWalletConnectedError","disconnect","port","e","console","warning","connect","onMessage","onDisconnect","isConnected","handler","msg","source","debug","log","addListener","sendMessage","postMessage","hasListeners","hasListener","init","connectionInfo","runtime","id","undefined","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;OAEOC,gB;SACEC,a;SAEPC,kB,EACAC,qB,EACAC,sB;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,UAAT,GAAuB;AACrB,MAAI;AACF,SAAKC,IAAL,CAAUD,UAAV;AACD,GAFD,CAEE,OAAOE,CAAP,EAAU;AACVC,IAAAA,OAAO,CAACC,OAAR,CAAgB,iCAAhB,EAAmDF,CAAnD;AACD;AACF;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASG,OAAT,CAAkBC,SAAlB,EAA6BC,YAA7B,EAA2C;AACzC,MAAI,KAAKC,WAAL,EAAJ,EAAwB,MAAM,IAAIV,qBAAJ,CAA0B,uBAA1B,CAAN;;AACxB,OAAKW,OAAL,GAAe,CAACC,GAAD,EAAMC,MAAN,KAAiB;AAC9B,QAAI,KAAKC,KAAT,EAAgBT,OAAO,CAACU,GAAR,CAAY,mBAAZ,EAAiCH,GAAjC;AAChBJ,IAAAA,SAAS,CAACI,GAAD,EAAMC,MAAN,CAAT;AACD,GAHD;;AAIA,OAAKV,IAAL,CAAUK,SAAV,CAAoBQ,WAApB,CAAgC,KAAKL,OAArC;AACA,OAAKR,IAAL,CAAUM,YAAV,CAAuBO,WAAvB,CAA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AACD,GANoB;;AAOrBC,EAAAA,OAAO,EAAE;AAAEnB,IAAAA,OAAF;AAAWU,IAAAA,WAAX;AAAwBf,IAAAA,UAAxB;AAAoCQ,IAAAA;AAApC;AAPY,CAAD,EAQnBb,gBARmB,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 runtime 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-runtime\n * @export BrowserRuntimeConnection\n * @example import { BrowserRuntimeConnection } from '@aeternity/aepp-sdk'\n */\nimport stampit from '@stamp/it'\n\nimport WalletConnection from '.'\nimport { getBrowserAPI } from '../helpers'\nimport {\n RpcConnectionError,\n AlreadyConnectedError,\n NoWalletConnectedError\n} from '../../errors'\n\n/**\n * Disconnect\n * @function disconnect\n * @instance\n * @rtype () => void\n * @return {void}\n */\nfunction disconnect () {\n try {\n this.port.disconnect()\n } catch (e) {\n console.warning('From BrowserRuntimeConnection: ', e)\n }\n}\n\n/**\n * Connect\n * @function connect\n * @instance\n * @rtype (onMessage: Function, onDisconnect: Function) => void\n * @param {Function} onMessage - Message handler\n * @param {Function} onDisconnect - trigger when runtime connection in closed\n * @return {void}\n */\nfunction connect (onMessage, onDisconnect) {\n if (this.isConnected()) throw new AlreadyConnectedError('You already connected')\n this.handler = (msg, source) => {\n if (this.debug) console.log('Receive message: ', msg)\n onMessage(msg, source)\n }\n this.port.onMessage.addListener(this.handler)\n this.port.onDisconnect.addListener(() => {\n typeof onDisconnect === 'function' && onDisconnect({}, this)\n this.port.disconnect()\n })\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 if (!this.port) throw new NoWalletConnectedError('You dont have connection. Please connect before')\n if (this.debug) console.log('Send message: ', msg)\n this.port.postMessage(msg)\n}\n\n/**\n * Check if connected\n * @function isConnected\n * @instance\n * @rtype () => Boolean\n * @return {Boolean} Is connected\n */\nfunction isConnected () {\n return typeof this.port.onMessage.hasListeners === 'function' ? this.port.onMessage.hasListeners() : this.port.onMessage.hasListener(this.handler)\n}\n\n/**\n * BrowserRuntimeConnection stamp\n * Handle browser runtime communication\n * @function\n * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime\n * @rtype Stamp\n * @param {Object} params={} - Initializer object\n * @param {Object} params.port - Runtime `port` object\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 = {}, port, debug = false }) {\n if (!getBrowserAPI().runtime) throw new RpcConnectionError('Runtime is not accessible in your environment')\n this.debug = debug\n this.connectionInfo = connectionInfo\n this.port = port || getBrowserAPI().runtime.connect(...[connectionInfo.id || undefined])\n },\n methods: { connect, sendMessage, disconnect, isConnected }\n}, WalletConnection)\n"],"file":"browser-runtime.mjs"}
@@ -18,16 +18,20 @@
18
18
  /**
19
19
  * Browser window Post Message connector module
20
20
  *
21
- * This is the complement to {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
21
+ * This is the complement to
22
+ * {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
22
23
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message
23
24
  * @export BrowserWindowMessageConnection
24
- * @example import BrowserWindowMessageConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message'
25
+ * @example
26
+ * import BrowserWindowMessageConnection
27
+ * from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message'
25
28
  */
26
29
  import stampit from '@stamp/it';
27
- import WalletConnection from '.';
28
- import { v4 as uuid } from 'uuid';
29
- import { MESSAGE_DIRECTION } from '../schema';
30
- import { getBrowserAPI, isInIframe } from '../helpers';
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";
31
35
  /**
32
36
  * Check if connected
33
37
  * @function isConnected
@@ -54,7 +58,7 @@ function connect(onMessage) {
54
58
  const receiveDirection = this.receiveDirection;
55
59
  const debug = this.debug;
56
60
  const forceOrigin = this.forceOrigin;
57
- if (this.listener) throw new Error('You already connected');
61
+ if (this.listener) throw new AlreadyConnectedError('You already connected');
58
62
 
59
63
  this.listener = (msg, source) => {
60
64
  if (!msg || typeof msg.data !== 'object') return;
@@ -81,7 +85,7 @@ function connect(onMessage) {
81
85
 
82
86
 
83
87
  function disconnect() {
84
- if (!this.listener) throw new Error('You dont have connection. Please connect before');
88
+ if (!this.listener) throw new NoWalletConnectedError('You dont have connection. Please connect before');
85
89
  this.unsubscribeFn(this.listener);
86
90
  this.listener = null;
87
91
  }
@@ -109,21 +113,27 @@ const getTarget = () => {
109
113
  const isWeb = window && window.location && window.location.protocol.startsWith('http');
110
114
  const isContentScript = isExtensionContext && isWeb;
111
115
  if (isContentScript) return window; // When we is the main page we need to decide the target by our self
112
- // Probably can be implemented some algo for checking DOM for Iframes and somehow decide which Iframe to talk
116
+ // Probably can be implemented some algo for checking DOM for Iframes and somehow decide which
117
+ // Iframe to talk
113
118
 
114
119
  return isInIframe() ? window.parent : undefined;
115
120
  };
116
121
  /**
117
122
  * BrowserWindowMessageConnection
118
123
  * @function
119
- * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message
124
+ * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication\
125
+ * /connection/browser-window-message
120
126
  * @rtype Stamp
121
127
  * @param {Object} [params={}] - Initializer object
122
128
  * @param {Object} [params.target=window.parent] - Target window for message
123
129
  * @param {Object} [params.self=window] - Host window for message
124
130
  * @param {Object} [params.origin] - Origin of receiver
125
- * @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
126
- * @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
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
127
137
  * @param {Object} [params.connectionInfo={}] - Connection info object
128
138
  * @param {Boolean} [params.debug=false] - Debug flag
129
139
  * @return {Object}
@@ -142,8 +152,8 @@ export default stampit({
142
152
  debug = false,
143
153
  forceOrigin = false
144
154
  } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
145
- if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new Error(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`);
146
- if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new Error(`receiveDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`);
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)}]`);
147
157
  this.connectionInfo = {
148
158
  id: uuid(),
149
159
  ...connectionInfo
@@ -161,8 +171,6 @@ export default stampit({
161
171
  this.unsubscribeFn = listener => selfP.removeEventListener('message', listener, false);
162
172
 
163
173
  this.postFn = msg => targetP.postMessage(msg, this.origin || '*');
164
-
165
- if (!this.connectionInfo.id) throw new Error('ID required.');
166
174
  },
167
175
 
168
176
  methods: {
@@ -172,4 +180,4 @@ export default stampit({
172
180
  isConnected
173
181
  }
174
182
  }, WalletConnection);
175
- //# sourceMappingURL=browser-window-message.js.map
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;A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AA1B,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 import WalletConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection'
22
+ * @example
23
+ * import WalletConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection'
23
24
  */
24
- import { required } from '@stamp/required';
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.js.map
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"}
@@ -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 import ContentScriptBridge from '@aeternity/aepp-sdk/es/utils/wallet-communication/content-script-bridge
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
@@ -56,14 +59,18 @@ function stop() {
56
59
  }
57
60
  /**
58
61
  * ContentScriptBridge stamp
59
- * Provide functionality to easly redirect messages from page to extension and from extension to page through content script
62
+ * Provide functionality to easly redirect messages from page to extension and from extension to
63
+ * page through content script
60
64
  * Using Runtime(Extension) and WindowPostMessage(Web-Page) connections
61
65
  * @function
62
66
  * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge
63
67
  * @rtype Stamp
64
68
  * @param {Object} params - Initializer object
65
- * @param {Object} params.pageConnection - Page connection object(@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message)
66
- * @param {Object} params.extConnection - Extension connection object(module: @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime)
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)
67
74
  * @return {Object}
68
75
  */
69
76
 
@@ -75,9 +82,9 @@ export default stampit({
75
82
  extConnection,
76
83
  allowCrossOrigin = false
77
84
  } = _ref;
78
- if (!window) throw new Error('Window object not found, you can run bridge only in browser');
79
- if (!pageConnection) throw new Error('pageConnection required');
80
- if (!extConnection) throw new Error('extConnection required');
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');
81
88
  this.allowCrossOrigin = allowCrossOrigin;
82
89
  this.pageConnection = pageConnection;
83
90
  this.extConnection = extConnection;
@@ -88,4 +95,4 @@ export default stampit({
88
95
  stop
89
96
  }
90
97
  });
91
- //# sourceMappingURL=content-script-bridge.js.map
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"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Browser helper functions
3
3
  */
4
- import { isAccountBase } from '../../account/base';
4
+ import { NoBrowserFoundError } from "../errors.mjs";
5
5
  export const getBrowserAPI = function () {
6
6
  let force = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
7
7
  const {
@@ -12,7 +12,7 @@ export const getBrowserAPI = function () {
12
12
  if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome; // Firefox support
13
13
 
14
14
  if (typeof browser !== 'undefined' && browser === Object(browser)) return browser;
15
- if (!force) throw new Error('Browser is not detected');
15
+ if (!force) throw new NoBrowserFoundError();
16
16
  return {};
17
17
  };
18
18
  export const isInIframe = () => window !== window.parent;
@@ -88,16 +88,5 @@ export const responseMessage = function (id, method) {
88
88
  };
89
89
  };
90
90
  export const sendResponseMessage = client => (id, method, data) => client.sendMessage(responseMessage(id, method, data), true);
91
- export const voidFn = () => undefined;
92
91
  export const isValidAccounts = accounts => ['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object').length === 3;
93
- export const resolveOnAccount = function (addresses, onAccount) {
94
- let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
95
-
96
- if (!addresses.find(a => a === onAccount)) {
97
- if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new Error('Provided onAccount should be an AccountBase');
98
- onAccount = opt.onAccount;
99
- }
100
-
101
- return onAccount;
102
- };
103
- //# sourceMappingURL=helpers.js.map
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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D,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"}