@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
package/src/tx/tx.js CHANGED
@@ -26,12 +26,21 @@ import ChainNode from '../chain/node'
26
26
  import Tx from './'
27
27
  import { buildTx, calculateFee, unpackTx } from './builder'
28
28
  import { ABI_VERSIONS, MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE, TX_TTL } from './builder/schema'
29
- import { buildContractId } from './builder/helpers'
29
+ import { buildContractId, encode } from './builder/helpers'
30
30
  import { TxObject } from './tx-object'
31
+ import {
32
+ ArgumentError,
33
+ UnsupportedABIversionError,
34
+ UnsupportedVMversionError,
35
+ UnsupportedProtocolError,
36
+ UnknownTxError
37
+ } from '../utils/errors'
31
38
 
32
39
  async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
33
40
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
34
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.spend, { senderId, ...arguments[0], payload })
41
+ const { fee, ttl, nonce } = await this.prepareTxParams(
42
+ TX_TYPE.spend, { senderId, ...arguments[0], payload }
43
+ )
35
44
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
36
45
  const { tx } = this.nativeMode
37
46
  ? {
@@ -63,7 +72,9 @@ async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
63
72
 
64
73
  async function namePreclaimTx ({ accountId, commitmentId }) {
65
74
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
66
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.namePreClaim, { senderId: accountId, ...arguments[0] })
75
+ const { fee, ttl, nonce } = await this.prepareTxParams(
76
+ TX_TYPE.namePreClaim, { senderId: accountId, ...arguments[0] }
77
+ )
67
78
 
68
79
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
69
80
  const { tx } = this.nativeMode
@@ -80,7 +91,9 @@ async function namePreclaimTx ({ accountId, commitmentId }) {
80
91
 
81
92
  async function nameClaimTx ({ accountId, name, nameSalt, vsn = 2 }) {
82
93
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
83
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameClaim, { senderId: accountId, ...arguments[0], vsn })
94
+ const { fee, ttl, nonce } = await this.prepareTxParams(
95
+ TX_TYPE.nameClaim, { senderId: accountId, ...arguments[0], vsn }
96
+ )
84
97
 
85
98
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
86
99
  const { tx } = this.nativeMode
@@ -90,14 +103,18 @@ async function nameClaimTx ({ accountId, name, nameSalt, vsn = 2 }) {
90
103
  type: TX_TYPE.nameClaim
91
104
  }).encodedTx
92
105
  }
93
- : await this.api.postNameClaim({ ...arguments[0], nonce, ttl, fee: parseInt(fee) })
106
+ : await this.api.postNameClaim({
107
+ ...arguments[0], nonce, ttl, fee: parseInt(fee), name: encode(name, 'nm')
108
+ })
94
109
 
95
110
  return tx
96
111
  }
97
112
 
98
113
  async function nameTransferTx ({ accountId, nameId, recipientId }) {
99
114
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
100
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameTransfer, { senderId: accountId, ...arguments[0] })
115
+ const { fee, ttl, nonce } = await this.prepareTxParams(
116
+ TX_TYPE.nameTransfer, { senderId: accountId, ...arguments[0] }
117
+ )
101
118
 
102
119
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
103
120
  const { tx } = this.nativeMode
@@ -107,14 +124,18 @@ async function nameTransferTx ({ accountId, nameId, recipientId }) {
107
124
  type: TX_TYPE.nameTransfer
108
125
  }).encodedTx
109
126
  }
110
- : await this.api.postNameTransfer({ ...arguments[0], recipientId, nonce, ttl, fee: parseInt(fee) })
127
+ : await this.api.postNameTransfer({
128
+ ...arguments[0], recipientId, nonce, ttl, fee: parseInt(fee)
129
+ })
111
130
 
112
131
  return tx
113
132
  }
114
133
 
115
134
  async function nameUpdateTx ({ accountId, nameId, nameTtl, pointers, clientTtl }) {
116
135
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
117
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameUpdate, { senderId: accountId, ...arguments[0] })
136
+ const { fee, ttl, nonce } = await this.prepareTxParams(
137
+ TX_TYPE.nameUpdate, { senderId: accountId, ...arguments[0] }
138
+ )
118
139
 
119
140
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
120
141
  const { tx } = this.nativeMode
@@ -131,7 +152,9 @@ async function nameUpdateTx ({ accountId, nameId, nameTtl, pointers, clientTtl }
131
152
 
132
153
  async function nameRevokeTx ({ accountId, nameId }) {
133
154
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
134
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.nameRevoke, { senderId: accountId, ...arguments[0] })
155
+ const { fee, ttl, nonce } = await this.prepareTxParams(
156
+ TX_TYPE.nameRevoke, { senderId: accountId, ...arguments[0] }
157
+ )
135
158
 
136
159
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
137
160
  const { tx } = this.nativeMode
@@ -146,11 +169,15 @@ async function nameRevokeTx ({ accountId, nameId }) {
146
169
  return tx
147
170
  }
148
171
 
149
- async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
172
+ async function contractCreateTx ({
173
+ ownerId, code, vmVersion, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData
174
+ }) {
150
175
  // Get VM_ABI version
151
176
  const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
152
177
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
153
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.contractCreate, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice })
178
+ const { fee, ttl, nonce } = await this.prepareTxParams(
179
+ TX_TYPE.contractCreate, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice }
180
+ )
154
181
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
155
182
  return this.nativeMode
156
183
  ? {
@@ -160,13 +187,27 @@ async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit
160
187
  }).encodedTx,
161
188
  contractId: buildContractId(ownerId, nonce)
162
189
  }
163
- : this.api.postContractCreate({ ...arguments[0], nonce, ttl, fee: parseInt(fee), gas: parseInt(gas), gasPrice, vmVersion: ctVersion.vmVersion, abiVersion: ctVersion.abiVersion })
190
+ : this.api.postContractCreate({
191
+ ...arguments[0],
192
+ nonce,
193
+ ttl,
194
+ fee: parseInt(fee),
195
+ gas: parseInt(gas),
196
+ gasPrice,
197
+ vmVersion: ctVersion.vmVersion,
198
+ abiVersion: ctVersion.abiVersion
199
+ })
164
200
  }
165
201
 
166
- async function contractCallTx ({ callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData }) {
202
+ async function contractCallTx ({
203
+ callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData
204
+ }) {
167
205
  const ctVersion = this.getVmVersion(TX_TYPE.contractCall, arguments[0])
168
206
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
169
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.contractCall, { senderId: callerId, ...arguments[0], gasPrice, abiVersion: ctVersion.abiVersion })
207
+ const { fee, ttl, nonce } = await this.prepareTxParams(
208
+ TX_TYPE.contractCall,
209
+ { senderId: callerId, ...arguments[0], gasPrice, abiVersion: ctVersion.abiVersion }
210
+ )
170
211
 
171
212
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
172
213
  const { tx } = this.nativeMode
@@ -189,10 +230,14 @@ async function contractCallTx ({ callerId, contractId, abiVersion, amount, gas,
189
230
  return tx
190
231
  }
191
232
 
192
- async function oracleRegisterTx ({ accountId, queryFormat, responseFormat, queryFee, oracleTtl, abiVersion = ABI_VERSIONS.NO_ABI }) {
233
+ async function oracleRegisterTx ({
234
+ accountId, queryFormat, responseFormat, queryFee, oracleTtl, abiVersion = ABI_VERSIONS.NO_ABI
235
+ }) {
193
236
  // const { abiVersion: abi } = this.getVmVersion(TX_TYPE.oracleRegister, arguments[0])
194
237
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
195
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleRegister, { senderId: accountId, ...arguments[0], abiVersion })
238
+ const { fee, ttl, nonce } = await this.prepareTxParams(
239
+ TX_TYPE.oracleRegister, { senderId: accountId, ...arguments[0], abiVersion }
240
+ )
196
241
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
197
242
  const { tx } = this.nativeMode
198
243
  ? {
@@ -228,7 +273,9 @@ async function oracleRegisterTx ({ accountId, queryFormat, responseFormat, query
228
273
 
229
274
  async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
230
275
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
231
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleExtend, { senderId: callerId, ...arguments[0] })
276
+ const { fee, ttl, nonce } = await this.prepareTxParams(
277
+ TX_TYPE.oracleExtend, { senderId: callerId, ...arguments[0] }
278
+ )
232
279
 
233
280
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
234
281
  const { tx } = this.nativeMode
@@ -245,7 +292,9 @@ async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
245
292
 
246
293
  async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, queryFee, senderId }) {
247
294
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
248
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleQuery, { senderId, ...arguments[0] })
295
+ const { fee, ttl, nonce } = await this.prepareTxParams(
296
+ TX_TYPE.oracleQuery, { senderId, ...arguments[0] }
297
+ )
249
298
 
250
299
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
251
300
  const { tx } = this.nativeMode
@@ -272,7 +321,9 @@ async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, quer
272
321
 
273
322
  async function oracleRespondTx ({ oracleId, callerId, responseTtl, queryId, response }) {
274
323
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
275
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.oracleResponse, { senderId: callerId, ...arguments[0] })
324
+ const { fee, ttl, nonce } = await this.prepareTxParams(
325
+ TX_TYPE.oracleResponse, { senderId: callerId, ...arguments[0] }
326
+ )
276
327
 
277
328
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
278
329
  const { tx } = this.nativeMode
@@ -282,13 +333,17 @@ async function oracleRespondTx ({ oracleId, callerId, responseTtl, queryId, resp
282
333
  type: TX_TYPE.oracleResponse
283
334
  }).encodedTx
284
335
  }
285
- : await this.api.postOracleRespond({ oracleId, responseTtl, queryId, response, fee: parseInt(fee), ttl, nonce })
336
+ : await this.api.postOracleRespond({
337
+ oracleId, responseTtl, queryId, response, fee: parseInt(fee), ttl, nonce
338
+ })
286
339
  return tx
287
340
  }
288
341
 
289
342
  async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
290
343
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
291
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelCloseSolo, { senderId: fromId, ...arguments[0], payload })
344
+ const { fee, ttl, nonce } = await this.prepareTxParams(
345
+ TX_TYPE.channelCloseSolo, { senderId: fromId, ...arguments[0], payload }
346
+ )
292
347
 
293
348
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
294
349
  const { tx } = this.nativeMode
@@ -318,7 +373,9 @@ async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
318
373
 
319
374
  async function channelSlashTx ({ channelId, fromId, payload, poi }) {
320
375
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
321
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSlash, { senderId: fromId, ...arguments[0], payload })
376
+ const { fee, ttl, nonce } = await this.prepareTxParams(
377
+ TX_TYPE.channelSlash, { senderId: fromId, ...arguments[0], payload }
378
+ )
322
379
 
323
380
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
324
381
  const { tx } = this.nativeMode
@@ -348,7 +405,9 @@ async function channelSlashTx ({ channelId, fromId, payload, poi }) {
348
405
 
349
406
  async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, responderAmountFinal }) {
350
407
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
351
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSettle, { senderId: fromId, ...arguments[0] })
408
+ const { fee, ttl, nonce } = await this.prepareTxParams(
409
+ TX_TYPE.channelSettle, { senderId: fromId, ...arguments[0] }
410
+ )
352
411
 
353
412
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
354
413
  const { tx } = this.nativeMode
@@ -378,7 +437,9 @@ async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, respo
378
437
 
379
438
  async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
380
439
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
381
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.channelSnapshotSolo, { senderId: fromId, ...arguments[0], payload })
440
+ const { fee, ttl, nonce } = await this.prepareTxParams(
441
+ TX_TYPE.channelSnapshotSolo, { senderId: fromId, ...arguments[0], payload }
442
+ )
382
443
 
383
444
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
384
445
  const { tx } = this.nativeMode
@@ -404,11 +465,15 @@ async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
404
465
  return tx
405
466
  }
406
467
 
407
- async function gaAttachTx ({ ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData }) {
468
+ async function gaAttachTx ({
469
+ ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData
470
+ }) {
408
471
  // Get VM_ABI version
409
472
  const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
410
473
  // Calculate fee, get absolute ttl (ttl + height), get account nonce
411
- const { fee, ttl, nonce } = await this.prepareTxParams(TX_TYPE.gaAttach, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice })
474
+ const { fee, ttl, nonce } = await this.prepareTxParams(
475
+ TX_TYPE.gaAttach, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice }
476
+ )
412
477
  // Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
413
478
  return {
414
479
  tx: TxObject({
@@ -437,17 +502,17 @@ async function payingForTx ({ tx, payerId, ...args }) {
437
502
  function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
438
503
  const { consensusProtocolVersion } = this.getNodeInfo()
439
504
  const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion]
440
- if (!supportedProtocol) throw new Error('Not supported consensus protocol version')
505
+ if (!supportedProtocol) throw new UnsupportedProtocolError('Not supported consensus protocol version')
441
506
  const protocolForTX = supportedProtocol[txType]
442
- if (!protocolForTX) throw new Error('Not supported tx type')
507
+ if (!protocolForTX) throw new UnknownTxError('Not supported tx type')
443
508
 
444
509
  abiVersion = abiVersion || protocolForTX.abiVersion[0]
445
510
  vmVersion = vmVersion || protocolForTX.vmVersion[0]
446
511
  if (!protocolForTX.vmVersion.includes(vmVersion)) {
447
- throw new Error(`VM VERSION ${vmVersion} do not support by this node. Supported: [${protocolForTX.vmVersion}]`)
512
+ throw new UnsupportedVMversionError(`VM VERSION ${vmVersion} do not support by this node. Supported: [${protocolForTX.vmVersion}]`)
448
513
  }
449
514
  if (!protocolForTX.abiVersion.includes(abiVersion)) {
450
- throw new Error(`ABI VERSION ${abiVersion} do not support by this node. Supported: [${protocolForTX.abiVersion}]`)
515
+ throw new UnsupportedABIversionError(`ABI VERSION ${abiVersion} do not support by this node. Supported: [${protocolForTX.abiVersion}]`)
451
516
  }
452
517
 
453
518
  return { vmVersion, abiVersion }
@@ -462,7 +527,7 @@ function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
462
527
  */
463
528
  async function calculateTtl (ttl = TX_TTL, relative = true) {
464
529
  if (ttl === 0) return 0
465
- if (ttl < 0) throw new Error('ttl must be greater than 0')
530
+ if (ttl < 0) throw new ArgumentError('ttl', 'greater or equal to 0', ttl)
466
531
 
467
532
  if (relative) {
468
533
  const { height } = await this.api.getCurrentKeyBlock()
@@ -480,7 +545,8 @@ async function calculateTtl (ttl = TX_TTL, relative = true) {
480
545
  */
481
546
  async function getAccountNonce (accountId, nonce) {
482
547
  if (nonce) return nonce
483
- const { nonce: accountNonce } = await this.api.getAccountByPubkey(accountId).catch(() => ({ nonce: 0 }))
548
+ const { nonce: accountNonce } = await this.api.getAccountByPubkey(accountId)
549
+ .catch(() => ({ nonce: 0 }))
484
550
  return accountNonce + 1
485
551
  }
486
552
 
@@ -491,10 +557,19 @@ async function getAccountNonce (accountId, nonce) {
491
557
  * @param {Object} params Object which contains all tx data
492
558
  * @return {Object} { ttl, nonce, fee } Object with account nonce, absolute ttl and transaction fee
493
559
  */
494
- async function prepareTxParams (txType, { senderId, nonce: n, ttl: t, fee: f, gas, absoluteTtl, vsn, strategy }) {
495
- n = n || (await this.api.getAccountNextNonce(senderId, { strategy }).catch(e => ({ nextNonce: 1 }))).nextNonce
560
+ async function prepareTxParams (
561
+ txType,
562
+ { senderId, nonce: n, ttl: t, fee: f, gas, absoluteTtl, vsn, strategy }
563
+ ) {
564
+ n = n || (
565
+ await this.api.getAccountNextNonce(senderId, { strategy }).catch(e => ({ nextNonce: 1 }))
566
+ ).nextNonce
496
567
  const ttl = await calculateTtl.call(this, t, !absoluteTtl)
497
- const fee = calculateFee(f, txType, { showWarning: this.showWarning, gas, params: { ...arguments[1], nonce: n, ttl }, vsn })
568
+ const fee = calculateFee(
569
+ f,
570
+ txType,
571
+ { showWarning: this.showWarning, gas, params: { ...arguments[1], nonce: n, ttl }, vsn }
572
+ )
498
573
  return { fee, ttl, nonce: n }
499
574
  }
500
575
 
@@ -4,6 +4,7 @@ import { encode, decode } from './builder/helpers'
4
4
  import BigNumber from 'bignumber.js'
5
5
  import { MIN_GAS_PRICE, PROTOCOL_VM_ABI, TX_TYPE } from './builder/schema'
6
6
  import { calculateFee, unpackTx } from './builder'
7
+ import { UnsupportedProtocolError } from '../utils/errors'
7
8
 
8
9
  /**
9
10
  * Transaction validator
@@ -13,7 +14,7 @@ import { calculateFee, unpackTx } from './builder'
13
14
  */
14
15
 
15
16
  const validators = [
16
- async ({ encodedTx, signatures }, { account, node, parentTxTypes }) => {
17
+ ({ encodedTx, signatures }, { account, node, parentTxTypes }) => {
17
18
  if ((encodedTx ?? signatures) === undefined) return []
18
19
  if (signatures.length !== 1) return [] // TODO: Support multisignature?
19
20
  const prefix = Buffer.from([
@@ -32,7 +33,7 @@ const validators = [
32
33
  checkedKeys: ['encodedTx', 'signatures']
33
34
  }]
34
35
  },
35
- async ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {
36
+ ({ encodedTx, tx }, { node, parentTxTypes, txType }) => {
36
37
  if ((encodedTx ?? tx) === undefined) return []
37
38
  return verifyTransaction(
38
39
  encode((encodedTx ?? tx).rlpEncoded, 'tx'),
@@ -104,7 +105,7 @@ const validators = [
104
105
  ({ ctVersion, abiVersion }, { txType, node }) => {
105
106
  const { consensusProtocolVersion } = node.getNodeInfo()
106
107
  const protocol = PROTOCOL_VM_ABI[consensusProtocolVersion]
107
- if (!protocol) throw new Error(`Unsupported protocol: ${consensusProtocolVersion}`)
108
+ if (!protocol) throw new UnsupportedProtocolError(`Unsupported protocol: ${consensusProtocolVersion}`)
108
109
  // If not contract create tx
109
110
  if (!ctVersion) ctVersion = { abiVersion }
110
111
  const txProtocol = protocol[txType]
@@ -117,6 +118,25 @@ const validators = [
117
118
  }]
118
119
  }
119
120
  return []
121
+ },
122
+ async ({ contractId }, { txType, node }) => {
123
+ if (TX_TYPE.contractCall !== txType) return []
124
+ try {
125
+ const { active } = await node.api.getContract(contractId)
126
+ if (active) return []
127
+ return [{
128
+ message: `Contract ${contractId} is not active`,
129
+ key: 'ContractNotActive',
130
+ checkedKeys: ['contractId']
131
+ }]
132
+ } catch (error) {
133
+ if (!error.response?.body?.reason) throw error
134
+ return [{
135
+ message: error.response.body.reason,
136
+ key: 'ContractNotFound',
137
+ checkedKeys: ['contractId']
138
+ }]
139
+ }
120
140
  }
121
141
  ]
122
142
 
@@ -146,13 +166,13 @@ export default async function verifyTransaction (transaction, node, parentTxType
146
166
 
147
167
  const address = getSenderAddress(tx) ??
148
168
  (txType === TX_TYPE.signed ? getSenderAddress(tx.encodedTx.tx) : null)
149
- const [account, height] = await Promise.all([
169
+ const [account, { height }] = await Promise.all([
150
170
  address && node.api.getAccountByPubkey(address).catch(() => ({
151
171
  id: address,
152
172
  balance: new BigNumber(0),
153
173
  nonce: 0
154
174
  })),
155
- node.api.getCurrentKeyBlockHeight().then(({ height }) => height)
175
+ node.api.getCurrentKeyBlockHeight()
156
176
  ])
157
177
 
158
178
  return (await Promise.all(
@@ -18,15 +18,21 @@
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
28
 
28
29
  import WalletConnection from '.'
29
30
  import { getBrowserAPI } from '../helpers'
31
+ import {
32
+ RpcConnectionError,
33
+ AlreadyConnectedError,
34
+ NoWalletConnectedError
35
+ } from '../../errors'
30
36
 
31
37
  /**
32
38
  * Disconnect
@@ -53,7 +59,7 @@ function disconnect () {
53
59
  * @return {void}
54
60
  */
55
61
  function connect (onMessage, onDisconnect) {
56
- if (this.isConnected()) throw new Error('You already connected')
62
+ if (this.isConnected()) throw new AlreadyConnectedError('You already connected')
57
63
  this.handler = (msg, source) => {
58
64
  if (this.debug) console.log('Receive message: ', msg)
59
65
  onMessage(msg, source)
@@ -74,7 +80,7 @@ function connect (onMessage, onDisconnect) {
74
80
  * @return {void}
75
81
  */
76
82
  function sendMessage (msg) {
77
- if (!this.port) throw new Error('You dont have connection. Please connect before')
83
+ if (!this.port) throw new NoWalletConnectedError('You dont have connection. Please connect before')
78
84
  if (this.debug) console.log('Send message: ', msg)
79
85
  this.port.postMessage(msg)
80
86
  }
@@ -104,7 +110,7 @@ function isConnected () {
104
110
  */
105
111
  export default stampit({
106
112
  init ({ connectionInfo = {}, port, debug = false }) {
107
- if (!getBrowserAPI().runtime) throw new Error('Runtime is not accessible in your environment')
113
+ if (!getBrowserAPI().runtime) throw new RpcConnectionError('Runtime is not accessible in your environment')
108
114
  this.debug = debug
109
115
  this.connectionInfo = connectionInfo
110
116
  this.port = port || getBrowserAPI().runtime.connect(...[connectionInfo.id || undefined])
@@ -18,16 +18,24 @@
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
30
  import WalletConnection from '.'
28
- import { v4 as uuid } from 'uuid'
31
+ import { v4 as uuid } from '@aeternity/uuid'
29
32
  import { MESSAGE_DIRECTION } from '../schema'
30
33
  import { getBrowserAPI, isInIframe } from '../helpers'
34
+ import {
35
+ AlreadyConnectedError,
36
+ NoWalletConnectedError,
37
+ MessageDirectionError
38
+ } from '../../errors'
31
39
 
32
40
  /**
33
41
  * Check if connected
@@ -53,7 +61,7 @@ function connect (onMessage) {
53
61
  const receiveDirection = this.receiveDirection
54
62
  const debug = this.debug
55
63
  const forceOrigin = this.forceOrigin
56
- if (this.listener) throw new Error('You already connected')
64
+ if (this.listener) throw new AlreadyConnectedError('You already connected')
57
65
 
58
66
  this.listener = (msg, source) => {
59
67
  if (!msg || typeof msg.data !== 'object') return
@@ -77,7 +85,7 @@ function connect (onMessage) {
77
85
  * @return {void}
78
86
  */
79
87
  function disconnect () {
80
- 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')
81
89
  this.unsubscribeFn(this.listener)
82
90
  this.listener = null
83
91
  }
@@ -102,29 +110,44 @@ const getTarget = () => {
102
110
  const isContentScript = isExtensionContext && isWeb
103
111
  if (isContentScript) return window
104
112
  // When we is the main page we need to decide the target by our self
105
- // Probably can be implemented some algo for checking DOM for Iframes and somehow decide which Iframe to talk
113
+ // Probably can be implemented some algo for checking DOM for Iframes and somehow decide which
114
+ // Iframe to talk
106
115
  return isInIframe() ? window.parent : undefined
107
116
  }
108
117
 
109
118
  /**
110
119
  * BrowserWindowMessageConnection
111
120
  * @function
112
- * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message
121
+ * @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication\
122
+ * /connection/browser-window-message
113
123
  * @rtype Stamp
114
124
  * @param {Object} [params={}] - Initializer object
115
125
  * @param {Object} [params.target=window.parent] - Target window for message
116
126
  * @param {Object} [params.self=window] - Host window for message
117
127
  * @param {Object} [params.origin] - Origin of receiver
118
- * @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
119
- * @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
128
+ * @param {String} [params.sendDirection] Wrapping messages into additional struct
129
+ * ({ type: 'to_aepp' || 'to_waellet', data })
130
+ * Used for handling messages between content script and page
131
+ * @param {String} [params.receiveDirection='to_aepp'] Unwrapping messages from additional struct
132
+ * ({ type: 'to_aepp' || 'to_waellet', data })
133
+ * Used for handling messages between content script and page
120
134
  * @param {Object} [params.connectionInfo={}] - Connection info object
121
135
  * @param {Boolean} [params.debug=false] - Debug flag
122
136
  * @return {Object}
123
137
  */
124
138
  export default stampit({
125
- init ({ connectionInfo = {}, target = getTarget(), self = window, origin, sendDirection, receiveDirection = MESSAGE_DIRECTION.to_aepp, debug = false, forceOrigin = false } = {}) {
126
- if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new Error(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
127
- if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new Error(`receiveDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
139
+ init ({
140
+ connectionInfo = {},
141
+ target = getTarget(),
142
+ self = window,
143
+ origin,
144
+ sendDirection,
145
+ receiveDirection = MESSAGE_DIRECTION.to_aepp,
146
+ debug = false,
147
+ forceOrigin = false
148
+ } = {}) {
149
+ if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new MessageDirectionError(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
150
+ if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new MessageDirectionError(`receiveDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
128
151
  this.connectionInfo = { id: uuid(), ...connectionInfo }
129
152
 
130
153
  const selfP = self
@@ -137,7 +160,6 @@ export default stampit({
137
160
  this.subscribeFn = (listener) => selfP.addEventListener('message', listener, false)
138
161
  this.unsubscribeFn = (listener) => selfP.removeEventListener('message', listener, false)
139
162
  this.postFn = (msg) => targetP.postMessage(msg, this.origin || '*')
140
- if (!this.connectionInfo.id) throw new Error('ID required.')
141
163
  },
142
164
  methods: { connect, sendMessage, disconnect, isConnected }
143
165
  }, WalletConnection)
@@ -19,7 +19,8 @@
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
25
 
25
26
  import { required } from '@stamp/required'
@@ -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'
26
29
 
27
30
  /**
28
31
  * Start message proxy
@@ -56,21 +59,25 @@ 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
  export default stampit({
70
77
  init ({ pageConnection, extConnection, allowCrossOrigin = false }) {
71
- if (!window) throw new Error('Window object not found, you can run bridge only in browser')
72
- if (!pageConnection) throw new Error('pageConnection required')
73
- if (!extConnection) throw new Error('extConnection required')
78
+ if (!window) throw new UnsupportedPlatformError('Window object not found, you can run bridge only in browser')
79
+ if (!pageConnection) throw new MissingParamError('pageConnection required')
80
+ if (!extConnection) throw new MissingParamError('extConnection required')
74
81
  this.allowCrossOrigin = allowCrossOrigin
75
82
  this.pageConnection = pageConnection
76
83
  this.extConnection = extConnection
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Browser helper functions
3
3
  */
4
- import { isAccountBase } from '../../account/base'
4
+ import { NoBrowserFoundError } from '../errors'
5
5
 
6
6
  export const getBrowserAPI = (force = false) => {
7
7
  const { chrome, browser } = window
@@ -9,7 +9,7 @@ export const getBrowserAPI = (force = false) => {
9
9
  if (typeof chrome !== 'undefined' && chrome === Object(chrome)) return chrome
10
10
  // Firefox support
11
11
  if (typeof browser !== 'undefined' && browser === Object(browser)) return browser
12
- if (!force) throw new Error('Browser is not detected')
12
+ if (!force) throw new NoBrowserFoundError()
13
13
  return {}
14
14
  }
15
15
 
@@ -51,18 +51,10 @@ export const getHandler = (schema, msg, { debug = false } = {}) => {
51
51
 
52
52
  export const message = (method, params = {}) => ({ method, params })
53
53
 
54
- export const responseMessage = (id, method, { error, result } = {}) => ({ id, method, ...(error ? { error } : { result }) })
54
+ export const responseMessage = (id, method, { error, result } = {}) =>
55
+ ({ id, method, ...(error ? { error } : { result }) })
55
56
 
56
- export const sendResponseMessage = (client) => (id, method, data) => client.sendMessage(responseMessage(id, method, data), true)
57
-
58
- export const voidFn = () => undefined
57
+ export const sendResponseMessage = (client) => (id, method, data) =>
58
+ client.sendMessage(responseMessage(id, method, data), true)
59
59
 
60
60
  export const isValidAccounts = (accounts) => (['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object')).length === 3
61
-
62
- export const resolveOnAccount = (addresses, onAccount, opt = {}) => {
63
- if (!addresses.find(a => a === onAccount)) {
64
- if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new Error('Provided onAccount should be an AccountBase')
65
- onAccount = opt.onAccount
66
- }
67
- return onAccount
68
- }