@aeternity/aepp-sdk 10.0.0 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (238) 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} +20 -10
  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} +10 -9
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/{aens.js → aens.mjs} +18 -22
  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} +8 -7
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/{oracle.js → oracle.mjs} +33 -16
  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} +20 -4
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/{node.js → node.mjs} +121 -73
  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} +7 -7
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/{internal.js → internal.mjs} +49 -32
  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} +36 -28
  48. package/es/contract/ga/index.mjs.map +1 -0
  49. package/es/errors.d.ts +284 -0
  50. package/es/index.mjs +57 -0
  51. package/es/index.mjs.map +1 -0
  52. package/es/node-pool/{index.js → index.mjs} +11 -10
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/{node.js → node.mjs} +9 -8
  55. package/es/node.mjs.map +1 -0
  56. package/es/tx/builder/field-types.mjs +74 -0
  57. package/es/tx/builder/field-types.mjs.map +1 -0
  58. package/es/tx/builder/{helpers.js → helpers.mjs} +114 -56
  59. package/es/tx/builder/helpers.mjs.map +1 -0
  60. package/es/tx/builder/{index.js → index.mjs} +79 -68
  61. package/es/tx/builder/index.mjs.map +1 -0
  62. package/es/tx/builder/{schema.js → schema.mjs} +11 -65
  63. package/es/tx/builder/schema.mjs.map +1 -0
  64. package/es/tx/{index.js → index.mjs} +5 -2
  65. package/es/tx/index.mjs.map +1 -0
  66. package/es/tx/{tx-object.js → tx-object.mjs} +22 -15
  67. package/es/tx/tx-object.mjs.map +1 -0
  68. package/es/tx/{tx.js → tx.mjs} +15 -14
  69. package/es/tx/tx.mjs.map +1 -0
  70. package/es/tx/{validator.js → validator.mjs} +72 -33
  71. package/es/tx/validator.mjs.map +1 -0
  72. package/es/typings/blakejs/index.d.mjs +2 -0
  73. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  74. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +7 -6
  75. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  76. package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +10 -11
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  78. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +5 -2
  79. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  80. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +6 -5
  81. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  82. package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
  83. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  84. package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +113 -67
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  86. package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +14 -9
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  88. package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +71 -63
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  90. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  92. package/es/utils/aepp-wallet-communication/{wallet-detector.js → wallet-detector.mjs} +6 -5
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  94. package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
  95. package/es/utils/amount-formatter.mjs.map +1 -0
  96. package/es/utils/{async-init.js → async-init.mjs} +8 -11
  97. package/es/utils/async-init.mjs.map +1 -0
  98. package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
  99. package/es/utils/bignumber.mjs.map +1 -0
  100. package/es/utils/{bytes.js → bytes.mjs} +16 -8
  101. package/es/utils/bytes.mjs.map +1 -0
  102. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  103. package/es/utils/crypto-ts.mjs.map +1 -0
  104. package/es/utils/{crypto.js → crypto.mjs} +40 -105
  105. package/es/utils/crypto.mjs.map +1 -0
  106. package/es/utils/errors.mjs +689 -0
  107. package/es/utils/errors.mjs.map +1 -0
  108. package/es/utils/{hd-wallet.js → hd-wallet.mjs} +33 -34
  109. package/es/utils/hd-wallet.mjs.map +1 -0
  110. package/es/utils/{json-big.js → json-big.mjs} +1 -1
  111. package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
  112. package/es/utils/{keystore.js → keystore.mjs} +63 -51
  113. package/es/utils/keystore.mjs.map +1 -0
  114. package/es/utils/{mptree.js → mptree.mjs} +21 -12
  115. package/es/utils/mptree.mjs.map +1 -0
  116. package/es/utils/{other.js → other.mjs} +2 -2
  117. package/es/utils/other.mjs.map +1 -0
  118. package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
  119. package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
  120. package/es/utils/{string.js → string.mjs} +1 -1
  121. package/es/utils/{string.js.map → string.mjs.map} +1 -1
  122. package/es/utils/{swagger.js → swagger.mjs} +46 -14
  123. package/es/utils/swagger.mjs.map +1 -0
  124. package/package.json +46 -55
  125. package/src/account/memory.js +13 -8
  126. package/src/account/multiple.js +12 -4
  127. package/src/ae/aens.js +12 -17
  128. package/src/ae/aepp.js +2 -2
  129. package/src/ae/contract.js +15 -152
  130. package/src/ae/index.js +2 -1
  131. package/src/ae/oracle.js +25 -10
  132. package/src/ae/universal.js +2 -2
  133. package/src/ae/wallet.js +2 -2
  134. package/src/chain/index.js +21 -2
  135. package/src/chain/node.js +80 -53
  136. package/src/channel/handlers.js +20 -17
  137. package/src/channel/internal.js +30 -24
  138. package/src/contract/{aci/index.js → aci.js} +152 -93
  139. package/src/contract/compiler.js +22 -117
  140. package/src/contract/ga/helpers.js +7 -5
  141. package/src/contract/ga/index.js +27 -24
  142. package/src/index.js +7 -8
  143. package/src/node-pool/index.js +9 -8
  144. package/src/node.js +5 -7
  145. package/src/tx/builder/field-types.js +61 -0
  146. package/src/tx/builder/helpers.js +113 -58
  147. package/src/tx/builder/index.js +39 -34
  148. package/src/tx/builder/schema.js +11 -25
  149. package/src/tx/tx-object.js +10 -9
  150. package/src/tx/tx.js +17 -8
  151. package/src/tx/validator.js +25 -5
  152. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +8 -3
  153. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +10 -6
  154. package/src/utils/aepp-wallet-communication/content-script-bridge.js +5 -4
  155. package/src/utils/aepp-wallet-communication/helpers.js +2 -12
  156. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +81 -55
  157. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +15 -6
  158. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +60 -49
  159. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  160. package/src/utils/aepp-wallet-communication/wallet-detector.js +3 -2
  161. package/src/utils/amount-formatter.ts +4 -3
  162. package/src/utils/async-init.js +10 -6
  163. package/src/utils/bignumber.ts +1 -9
  164. package/src/utils/bytes.ts +3 -2
  165. package/src/utils/crypto-ts.ts +2 -2
  166. package/src/utils/crypto.js +9 -92
  167. package/src/utils/errors.ts +683 -0
  168. package/src/utils/hd-wallet.js +11 -26
  169. package/src/utils/keystore.js +47 -51
  170. package/src/utils/mptree.ts +12 -6
  171. package/src/utils/swagger.js +67 -44
  172. package/CHANGELOG.md +0 -1603
  173. package/es/account/base.js.map +0 -1
  174. package/es/account/memory.js.map +0 -1
  175. package/es/account/multiple.js.map +0 -1
  176. package/es/ae/aens.js.map +0 -1
  177. package/es/ae/aepp.js.map +0 -1
  178. package/es/ae/contract.js +0 -312
  179. package/es/ae/contract.js.map +0 -1
  180. package/es/ae/index.js.map +0 -1
  181. package/es/ae/oracle.js.map +0 -1
  182. package/es/ae/universal.js.map +0 -1
  183. package/es/ae/wallet.js.map +0 -1
  184. package/es/chain/index.js.map +0 -1
  185. package/es/chain/node.js.map +0 -1
  186. package/es/channel/handlers.js.map +0 -1
  187. package/es/channel/index.js.map +0 -1
  188. package/es/channel/internal.js.map +0 -1
  189. package/es/contract/aci/helpers.js +0 -298
  190. package/es/contract/aci/helpers.js.map +0 -1
  191. package/es/contract/aci/index.js +0 -361
  192. package/es/contract/aci/index.js.map +0 -1
  193. package/es/contract/aci/transformation.js +0 -66
  194. package/es/contract/aci/transformation.js.map +0 -1
  195. package/es/contract/compiler.js +0 -244
  196. package/es/contract/compiler.js.map +0 -1
  197. package/es/contract/ga/helpers.js +0 -22
  198. package/es/contract/ga/helpers.js.map +0 -1
  199. package/es/contract/ga/index.js.map +0 -1
  200. package/es/contract/index.js +0 -162
  201. package/es/contract/index.js.map +0 -1
  202. package/es/index.js +0 -57
  203. package/es/index.js.map +0 -1
  204. package/es/node-pool/index.js.map +0 -1
  205. package/es/node.js.map +0 -1
  206. package/es/tx/builder/helpers.js.map +0 -1
  207. package/es/tx/builder/index.js.map +0 -1
  208. package/es/tx/builder/schema.js.map +0 -1
  209. package/es/tx/index.js.map +0 -1
  210. package/es/tx/tx-object.js.map +0 -1
  211. package/es/tx/tx.js.map +0 -1
  212. package/es/tx/validator.js.map +0 -1
  213. package/es/typings/blakejs/index.d.js +0 -2
  214. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  215. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  216. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  217. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  218. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  219. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  220. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  221. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  222. package/es/utils/aepp-wallet-communication/schema.js +0 -107
  223. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  224. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  225. package/es/utils/amount-formatter.js.map +0 -1
  226. package/es/utils/async-init.js.map +0 -1
  227. package/es/utils/bignumber.js.map +0 -1
  228. package/es/utils/bytes.js.map +0 -1
  229. package/es/utils/crypto-ts.js.map +0 -1
  230. package/es/utils/crypto.js.map +0 -1
  231. package/es/utils/hd-wallet.js.map +0 -1
  232. package/es/utils/keystore.js.map +0 -1
  233. package/es/utils/mptree.js.map +0 -1
  234. package/es/utils/other.js.map +0 -1
  235. package/es/utils/swagger.js.map +0 -1
  236. package/src/contract/aci/transformation.js +0 -72
  237. package/src/contract/index.js +0 -163
  238. package/src/utils/aepp-wallet-communication/schema.js +0 -108
@@ -9,6 +9,7 @@ import { buildTx, calculateFee, unpackTx } from './builder'
9
9
  import { TX_TYPE } from './builder/schema'
10
10
  import { encode } from './builder/helpers'
11
11
  import { isHex } from '../utils/string'
12
+ import { InvalidTxError, TypeError, UnknownTxError, InvalidSignatureError } from '../utils/errors'
12
13
 
13
14
  /**
14
15
  * Build transaction from object
@@ -22,8 +23,8 @@ import { isHex } from '../utils/string'
22
23
  * }}
23
24
  */
24
25
  const buildTransaction = (type, params, options = {}) => {
25
- if (typeof params !== 'object') throw new Error('"params" should be an object')
26
- if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new Error(`Unknown transaction type ${type}`)
26
+ if (typeof params !== 'object') throw new TypeError('tx "params" should be an object')
27
+ if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new UnknownTxError(`Unknown transaction type ${type}`)
27
28
  const fee = calculateFee(params.fee, type, { gas: params.gas, params, vsn: params.vsn })
28
29
  const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx(
29
30
  { ...params, fee }, type, { vsn: params.vsn, ...options }
@@ -34,22 +35,23 @@ const buildTransaction = (type, params, options = {}) => {
34
35
  /**
35
36
  * Unpack transaction from RLP encoded binary or base64c string
36
37
  * @alias module:@aeternity/aepp-sdk/es/tx/tx-object
37
- * @param {Buffer|String} tx RLP encoded binary or base64c(rlpBinary) string
38
+ * @param {Uint8Array|String} tx RLP encoded binary or base64c(rlpBinary) string
38
39
  * @throws {Error} Arguments validation error's
39
40
  * @return {{
40
41
  * encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object
41
42
  * }}
42
43
  */
43
44
  const unpackTransaction = (tx) => {
44
- if (!tx) throw new Error(`Invalid transaction: ${tx}`)
45
+ if (!tx) throw new InvalidTxError(`Invalid transaction: ${tx}`)
45
46
  if (typeof tx === 'string') {
46
47
  const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx)
47
48
  return { encodedTx: tx, type, params, rlpEncoded, binary }
48
49
  }
49
- if (Buffer.isBuffer(tx)) {
50
+ if (tx instanceof Uint8Array) {
50
51
  const { txType: type, tx: params, rlpEncoded, binary } = unpackTx(tx, true)
51
52
  return { encodedTx: encode(tx, 'tx'), type, params, rlpEncoded, binary }
52
53
  }
54
+ throw new InvalidTxError(`"tx" should be a string or Uint8Array, got ${tx} instead`)
53
55
  }
54
56
 
55
57
  /**
@@ -68,7 +70,7 @@ const unpackTransaction = (tx) => {
68
70
  const initTransaction = ({ tx, params, type, options = {} } = {}) => {
69
71
  if (params && type) return buildTransaction(type, params, options)
70
72
  if (tx) return unpackTransaction(tx)
71
- throw new Error('Invalid TxObject arguments. Please provide one of { tx: "tx_asdasd23..." } or { type: "spendTx", params: {...} }')
73
+ throw new InvalidTxError('Invalid TxObject arguments. Please provide one of { tx: "tx_asdasd23..." } or { type: "spendTx", params: {...} }')
72
74
  }
73
75
 
74
76
  /**
@@ -127,7 +129,7 @@ export const TxObject = stampit({
127
129
  * @return {TxObject}
128
130
  */
129
131
  setProp (props = {}, options = {}) {
130
- if (typeof props !== 'object') throw new Error('Props should be an object')
132
+ if (typeof props !== 'object') throw new TypeError('Props should be an object')
131
133
  this.isSigned = false
132
134
  this.signatures = []
133
135
  Object.assign(
@@ -144,7 +146,6 @@ export const TxObject = stampit({
144
146
  * @return {Array} Array of signatures
145
147
  */
146
148
  getSignatures () {
147
- if (!this.isSigned) throw new Error('Signature not found, transaction is not signed')
148
149
  return this.signatures
149
150
  },
150
151
  /**
@@ -155,7 +156,7 @@ export const TxObject = stampit({
155
156
  */
156
157
  addSignature (signature) {
157
158
  signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature
158
- if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array')
159
+ if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new InvalidSignatureError('Invalid signature, signature must be of type Buffer or Uint8Array')
159
160
  Object.assign(
160
161
  this,
161
162
  buildTransaction(
package/src/tx/tx.js CHANGED
@@ -26,8 +26,15 @@ 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
@@ -96,7 +103,9 @@ async function nameClaimTx ({ accountId, name, nameSalt, vsn = 2 }) {
96
103
  type: TX_TYPE.nameClaim
97
104
  }).encodedTx
98
105
  }
99
- : 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
+ })
100
109
 
101
110
  return tx
102
111
  }
@@ -161,7 +170,7 @@ async function nameRevokeTx ({ accountId, nameId }) {
161
170
  }
162
171
 
163
172
  async function contractCreateTx ({
164
- ownerId, code, vmVersion, abiVersion, deposit, amount, gas, gasPrice = MIN_GAS_PRICE, callData
173
+ ownerId, code, vmVersion, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData
165
174
  }) {
166
175
  // Get VM_ABI version
167
176
  const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
@@ -493,17 +502,17 @@ async function payingForTx ({ tx, payerId, ...args }) {
493
502
  function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
494
503
  const { consensusProtocolVersion } = this.getNodeInfo()
495
504
  const supportedProtocol = PROTOCOL_VM_ABI[consensusProtocolVersion]
496
- if (!supportedProtocol) throw new Error('Not supported consensus protocol version')
505
+ if (!supportedProtocol) throw new UnsupportedProtocolError('Not supported consensus protocol version')
497
506
  const protocolForTX = supportedProtocol[txType]
498
- if (!protocolForTX) throw new Error('Not supported tx type')
507
+ if (!protocolForTX) throw new UnknownTxError('Not supported tx type')
499
508
 
500
509
  abiVersion = abiVersion || protocolForTX.abiVersion[0]
501
510
  vmVersion = vmVersion || protocolForTX.vmVersion[0]
502
511
  if (!protocolForTX.vmVersion.includes(vmVersion)) {
503
- 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}]`)
504
513
  }
505
514
  if (!protocolForTX.abiVersion.includes(abiVersion)) {
506
- 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}]`)
507
516
  }
508
517
 
509
518
  return { vmVersion, abiVersion }
@@ -518,7 +527,7 @@ function getVmVersion (txType, { vmVersion, abiVersion } = {}) {
518
527
  */
519
528
  async function calculateTtl (ttl = TX_TTL, relative = true) {
520
529
  if (ttl === 0) return 0
521
- 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)
522
531
 
523
532
  if (relative) {
524
533
  const { height } = await this.api.getCurrentKeyBlock()
@@ -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(
@@ -28,6 +28,11 @@ import stampit from '@stamp/it'
28
28
 
29
29
  import WalletConnection from '.'
30
30
  import { getBrowserAPI } from '../helpers'
31
+ import {
32
+ RpcConnectionError,
33
+ AlreadyConnectedError,
34
+ NoWalletConnectedError
35
+ } from '../../errors'
31
36
 
32
37
  /**
33
38
  * Disconnect
@@ -54,7 +59,7 @@ function disconnect () {
54
59
  * @return {void}
55
60
  */
56
61
  function connect (onMessage, onDisconnect) {
57
- if (this.isConnected()) throw new Error('You already connected')
62
+ if (this.isConnected()) throw new AlreadyConnectedError('You already connected')
58
63
  this.handler = (msg, source) => {
59
64
  if (this.debug) console.log('Receive message: ', msg)
60
65
  onMessage(msg, source)
@@ -75,7 +80,7 @@ function connect (onMessage, onDisconnect) {
75
80
  * @return {void}
76
81
  */
77
82
  function sendMessage (msg) {
78
- 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')
79
84
  if (this.debug) console.log('Send message: ', msg)
80
85
  this.port.postMessage(msg)
81
86
  }
@@ -105,7 +110,7 @@ function isConnected () {
105
110
  */
106
111
  export default stampit({
107
112
  init ({ connectionInfo = {}, port, debug = false }) {
108
- 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')
109
114
  this.debug = debug
110
115
  this.connectionInfo = connectionInfo
111
116
  this.port = port || getBrowserAPI().runtime.connect(...[connectionInfo.id || undefined])
@@ -28,9 +28,14 @@
28
28
  */
29
29
  import stampit from '@stamp/it'
30
30
  import WalletConnection from '.'
31
- import { v4 as uuid } from 'uuid'
31
+ import { v4 as uuid } from '@aeternity/uuid'
32
32
  import { MESSAGE_DIRECTION } from '../schema'
33
33
  import { getBrowserAPI, isInIframe } from '../helpers'
34
+ import {
35
+ AlreadyConnectedError,
36
+ NoWalletConnectedError,
37
+ MessageDirectionError
38
+ } from '../../errors'
34
39
 
35
40
  /**
36
41
  * Check if connected
@@ -56,7 +61,7 @@ function connect (onMessage) {
56
61
  const receiveDirection = this.receiveDirection
57
62
  const debug = this.debug
58
63
  const forceOrigin = this.forceOrigin
59
- if (this.listener) throw new Error('You already connected')
64
+ if (this.listener) throw new AlreadyConnectedError('You already connected')
60
65
 
61
66
  this.listener = (msg, source) => {
62
67
  if (!msg || typeof msg.data !== 'object') return
@@ -80,7 +85,7 @@ function connect (onMessage) {
80
85
  * @return {void}
81
86
  */
82
87
  function disconnect () {
83
- 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')
84
89
  this.unsubscribeFn(this.listener)
85
90
  this.listener = null
86
91
  }
@@ -141,8 +146,8 @@ export default stampit({
141
146
  debug = false,
142
147
  forceOrigin = false
143
148
  } = {}) {
144
- if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new Error(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
145
- if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new Error(`receiveDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
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)}]`)
146
151
  this.connectionInfo = { id: uuid(), ...connectionInfo }
147
152
 
148
153
  const selfP = self
@@ -155,7 +160,6 @@ export default stampit({
155
160
  this.subscribeFn = (listener) => selfP.addEventListener('message', listener, false)
156
161
  this.unsubscribeFn = (listener) => selfP.removeEventListener('message', listener, false)
157
162
  this.postFn = (msg) => targetP.postMessage(msg, this.origin || '*')
158
- if (!this.connectionInfo.id) throw new Error('ID required.')
159
163
  },
160
164
  methods: { connect, sendMessage, disconnect, isConnected }
161
165
  }, WalletConnection)
@@ -25,6 +25,7 @@
25
25
  * from '@aeternity/aepp-sdk/es/utils/wallet-communication/content-script-bridge
26
26
  */
27
27
  import stampit from '@stamp/it'
28
+ import { UnsupportedPlatformError, MissingParamError } from '../errors'
28
29
 
29
30
  /**
30
31
  * Start message proxy
@@ -66,7 +67,7 @@ function stop () {
66
67
  * @rtype Stamp
67
68
  * @param {Object} params - Initializer object
68
69
  * @param {Object} params.pageConnection - Page connection object
69
- * (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/\
70
+ * (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/
70
71
  * browser-window-message)
71
72
  * @param {Object} params.extConnection - Extension connection object
72
73
  * (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime)
@@ -74,9 +75,9 @@ function stop () {
74
75
  */
75
76
  export default stampit({
76
77
  init ({ pageConnection, extConnection, allowCrossOrigin = false }) {
77
- if (!window) throw new Error('Window object not found, you can run bridge only in browser')
78
- if (!pageConnection) throw new Error('pageConnection required')
79
- 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')
80
81
  this.allowCrossOrigin = allowCrossOrigin
81
82
  this.pageConnection = pageConnection
82
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
 
@@ -57,14 +57,4 @@ export const responseMessage = (id, method, { error, result } = {}) =>
57
57
  export const sendResponseMessage = (client) => (id, method, data) =>
58
58
  client.sendMessage(responseMessage(id, method, data), true)
59
59
 
60
- export const voidFn = () => undefined
61
-
62
60
  export const isValidAccounts = (accounts) => (['', 'connected', 'current'].filter(k => typeof (k ? accounts[k] : accounts) === 'object')).length === 3
63
-
64
- export const resolveOnAccount = (addresses, onAccount, opt = {}) => {
65
- if (!addresses.find(a => a === onAccount)) {
66
- if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new Error('Provided onAccount should be an AccountBase')
67
- onAccount = opt.onAccount
68
- }
69
- return onAccount
70
- }
@@ -7,22 +7,33 @@
7
7
  * import ContentScriptBridge
8
8
  * from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
9
9
  */
10
- import { v4 as uuid } from 'uuid'
10
+ import { v4 as uuid } from '@aeternity/uuid'
11
11
  import Ae from '../../../ae'
12
12
  import RpcClient from './rpc-client'
13
- import { getHandler, message, voidFn } from '../helpers'
13
+ import { getHandler, message } from '../helpers'
14
14
  import { METHODS, RPC_STATUS, VERSION } from '../schema'
15
+ import {
16
+ AlreadyConnectedError,
17
+ NoWalletConnectedError,
18
+ UnsubscribedAccountError,
19
+ UnAuthorizedAccountError,
20
+ ArgumentError,
21
+ RpcConnectionError
22
+ } from '../../errors'
23
+ import { Node } from '../../../index'
15
24
 
16
25
  const NOTIFICATIONS = {
17
- [METHODS.wallet.updateAddress]: (instance) =>
26
+ [METHODS.updateAddress]: (instance) =>
18
27
  ({ params }) => {
19
28
  instance.rpcClient.accounts = params
20
29
  instance.onAddressChange(params)
21
30
  },
22
31
  [METHODS.updateNetwork]: (instance) =>
23
- (msg) => {
24
- instance.rpcClient.info.networkId = msg.params.networkId
25
- instance.onNetworkChange(msg.params)
32
+ async ({ params }) => {
33
+ const { networkId, node } = params
34
+ instance.rpcClient.info.networkId = networkId
35
+ node && instance.addNode(node.name, await Node(node), true)
36
+ instance.onNetworkChange(params)
26
37
  },
27
38
  [METHODS.closeConnection]: (instance) =>
28
39
  (msg) => {
@@ -32,14 +43,14 @@ const NOTIFICATIONS = {
32
43
  }
33
44
 
34
45
  const RESPONSES = {
35
- [METHODS.aepp.address]: (instance) =>
46
+ [METHODS.address]: (instance) =>
36
47
  (msg) => instance.rpcClient.processResponse(msg),
37
- [METHODS.aepp.connect]: (instance) =>
48
+ [METHODS.connect]: (instance) =>
38
49
  (msg) => {
39
50
  if (msg.result) instance.rpcClient.info.status = RPC_STATUS.CONNECTED
40
51
  instance.rpcClient.processResponse(msg)
41
52
  },
42
- [METHODS.aepp.subscribeAddress]: (instance) =>
53
+ [METHODS.subscribeAddress]: (instance) =>
43
54
  (msg) => {
44
55
  if (msg.result) {
45
56
  if (msg.result.address) {
@@ -52,13 +63,13 @@ const RESPONSES = {
52
63
 
53
64
  instance.rpcClient.processResponse(msg, ({ id, result }) => [result])
54
65
  },
55
- [METHODS.aepp.sign]: (instance) =>
66
+ [METHODS.sign]: (instance) =>
56
67
  (msg) => {
57
68
  instance.rpcClient.processResponse(
58
69
  msg, ({ id, result }) => [result.signedTransaction || result.transactionHash]
59
70
  )
60
71
  },
61
- [METHODS.aepp.signMessage]: (instance) =>
72
+ [METHODS.signMessage]: (instance) =>
62
73
  (msg) => {
63
74
  instance.rpcClient.processResponse(msg, ({ id, result }) => [result.signature])
64
75
  }
@@ -92,14 +103,16 @@ const handleMessage = (instance) => async (msg) => {
92
103
  export default Ae.compose({
93
104
  async init ({
94
105
  name,
95
- onAddressChange = voidFn,
96
- onDisconnect = voidFn,
97
- onNetworkChange = voidFn,
98
106
  connection,
99
- forceValidation = false,
100
- debug = false
107
+ debug = false,
108
+ ...other
101
109
  }) {
102
- const eventsHandlers = ['onDisconnect', 'onAddressChange', 'onNetworkChange']
110
+ ['onAddressChange', 'onDisconnect', 'onNetworkChange'].forEach(event => {
111
+ const handler = other[event] ?? (() => {})
112
+ if (typeof handler !== 'function') throw new ArgumentError(event, 'a function', handler)
113
+ this[event] = handler
114
+ })
115
+
103
116
  this.connection = connection
104
117
  this.name = name
105
118
  this.debug = debug
@@ -108,21 +121,13 @@ export default Ae.compose({
108
121
  // Init RPCClient
109
122
  await this.connectToWallet(connection)
110
123
  }
111
- // Event callbacks
112
- this.onDisconnect = onDisconnect
113
- this.onAddressChange = onAddressChange
114
- this.onNetworkChange = onNetworkChange
115
- // validation
116
- eventsHandlers.forEach(event => {
117
- if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`)
118
- })
119
124
  },
120
125
  deepProps: { Ae: { defaults: { walletBroadcast: true } } },
121
126
  methods: {
122
127
  sign () {
123
128
  },
124
129
  addresses () {
125
- if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.')
130
+ if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
126
131
  return [this.rpcClient.currentAccount, ...Object.keys(this.rpcClient.accounts.connected)]
127
132
  },
128
133
  /**
@@ -131,10 +136,14 @@ export default Ae.compose({
131
136
  * @instance
132
137
  * @rtype (connection: Object) => void
133
138
  * @param {Object} connection Wallet connection object
134
- * @return {void}
139
+ * @param {Object} [options={}]
140
+ * @param {Boolean} [options.connectNode=true] - Request wallet to bind node
141
+ * @param {String} [options.name=wallet-node] - Node name
142
+ * @param {Boolean} [options.select=false] - Select this node as current
143
+ * @return {Object}
135
144
  */
136
- async connectToWallet (connection) {
137
- if (this.rpcClient && this.rpcClient.isConnected()) throw new Error('You are already connected to wallet ' + this.rpcClient)
145
+ async connectToWallet (connection, { connectNode = false, name = 'wallet-node', select = false } = {}) {
146
+ if (this.rpcClient && this.rpcClient.isConnected()) throw new AlreadyConnectedError('You are already connected to wallet ' + this.rpcClient)
138
147
  this.rpcClient = RpcClient({
139
148
  connection,
140
149
  networkId: this.getNetworkId({ force: true }),
@@ -142,7 +151,12 @@ export default Ae.compose({
142
151
  id: uuid(),
143
152
  handlers: [handleMessage(this), this.onDisconnect]
144
153
  })
145
- return this.sendConnectRequest()
154
+ const walletInfo = await this.sendConnectRequest(connectNode)
155
+ if (connectNode && !Object.prototype.hasOwnProperty.call(walletInfo, 'node')) {
156
+ throw new RpcConnectionError('Missing URLs of the Node')
157
+ }
158
+ connectNode && this.addNode(name, await Node(walletInfo.node), select)
159
+ return walletInfo
146
160
  },
147
161
  /**
148
162
  * Disconnect from wallet
@@ -153,16 +167,18 @@ export default Ae.compose({
153
167
  * @return {void}
154
168
  */
155
169
  async disconnectWallet (sendDisconnect = true) {
156
- if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
170
+ if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
157
171
  sendDisconnect && this.rpcClient.sendMessage(message(METHODS.closeConnection, { reason: 'bye' }), true)
158
172
  this.rpcClient.disconnect()
159
173
  this.rpcClient = null
160
174
  },
161
175
  async address ({ onAccount } = {}) {
162
- if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
176
+ if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
163
177
  const current = this.rpcClient.currentAccount
164
- if (!current) throw new Error('You are not subscribed for an account.')
165
- if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount)) throw new Error(`You do not have access to account ${onAccount}`)
178
+ if (!current) throw new UnsubscribedAccountError()
179
+ if (onAccount && !this.rpcClient.hasAccessToAccount(onAccount)) {
180
+ throw new UnAuthorizedAccountError(onAccount)
181
+ }
166
182
  return onAccount || current
167
183
  },
168
184
  /**
@@ -173,9 +189,9 @@ export default Ae.compose({
173
189
  * @return {Promise} Address from wallet
174
190
  */
175
191
  async askAddresses () {
176
- if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
177
- if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.')
178
- return this.rpcClient.request(METHODS.aepp.address)
192
+ if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
193
+ if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
194
+ return this.rpcClient.request(METHODS.address)
179
195
  },
180
196
  /**
181
197
  * Subscribe for addresses from wallet
@@ -187,8 +203,8 @@ export default Ae.compose({
187
203
  * @return {Promise} Address from wallet
188
204
  */
189
205
  async subscribeAddress (type, value) {
190
- if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
191
- return this.rpcClient.request(METHODS.aepp.subscribeAddress, { type, value })
206
+ if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
207
+ return this.rpcClient.request(METHODS.subscribeAddress, { type, value })
192
208
  },
193
209
  /**
194
210
  * Overwriting of `signTransaction` AE method
@@ -199,11 +215,13 @@ export default Ae.compose({
199
215
  * @return {Promise<String>} Signed transaction
200
216
  */
201
217
  async signTransaction (tx, opt = {}) {
202
- if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
203
- if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.')
204
- if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) throw new Error(`You do not have access to account ${opt.onAccount}`)
218
+ if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
219
+ if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
220
+ if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {
221
+ throw new UnAuthorizedAccountError(opt.onAccount)
222
+ }
205
223
  return this.rpcClient.request(
206
- METHODS.aepp.sign,
224
+ METHODS.sign,
207
225
  { ...opt, tx, returnSigned: true, networkId: this.getNetworkId() }
208
226
  )
209
227
  },
@@ -216,24 +234,28 @@ export default Ae.compose({
216
234
  * @return {Promise<String>} Signed transaction
217
235
  */
218
236
  async signMessage (msg, opt = {}) {
219
- if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
220
- if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.')
221
- if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) throw new Error(`You do not have access to account ${opt.onAccount}`)
222
- return this.rpcClient.request(METHODS.aepp.signMessage, { ...opt, message: msg })
237
+ if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
238
+ if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
239
+ if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) {
240
+ throw new UnAuthorizedAccountError(opt.onAccount)
241
+ }
242
+ return this.rpcClient.request(METHODS.signMessage, { ...opt, message: msg })
223
243
  },
224
244
  /**
225
245
  * Send connection request to wallet
226
246
  * @function sendConnectRequest
227
247
  * @instance
248
+ * @param {Boolean} connectNode - Request wallet to bind node
228
249
  * @rtype () => Promise
229
250
  * @return {Promise} Connection response
230
251
  */
231
- async sendConnectRequest () {
252
+ async sendConnectRequest (connectNode) {
232
253
  return this.rpcClient.request(
233
- METHODS.aepp.connect, {
254
+ METHODS.connect, {
234
255
  name: this.name,
235
256
  version: VERSION,
236
- networkId: this.getNetworkId({ force: true })
257
+ networkId: this.getNetworkId({ force: true }),
258
+ connectNode
237
259
  }
238
260
  )
239
261
  },
@@ -251,18 +273,22 @@ export default Ae.compose({
251
273
  * @return {Promise<Object>} Transaction broadcast result
252
274
  */
253
275
  async send (tx, options = {}) {
254
- if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
255
- if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.')
256
- if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) throw new Error(`You do not have access to account ${options.onAccount}`)
276
+ if (!this.isConnected()) throw new NoWalletConnectedError('You are not connected to Wallet')
277
+ if (!this.isSubscribedAccount()) throw new UnsubscribedAccountError()
278
+ if (options.onAccount && !this.rpcClient.hasAccessToAccount(options.onAccount)) {
279
+ throw new UnAuthorizedAccountError(options.onAccount)
280
+ }
257
281
  const opt = { ...this.Ae.defaults, ...options }
258
282
  if (!opt.walletBroadcast) {
259
283
  const signed = await this.signTransaction(tx, { onAccount: opt.onAccount })
260
284
  return this.sendTransaction(signed, opt)
261
285
  }
262
286
  return this.rpcClient.request(
263
- METHODS.aepp.sign,
287
+ METHODS.sign,
264
288
  { onAccount: opt.onAccount, tx, returnSigned: false, networkId: this.getNetworkId() }
265
289
  )
266
- }
290
+ },
291
+ isConnected () { return (this.rpcClient && this.rpcClient.isConnected()) },
292
+ isSubscribedAccount () { return typeof this.rpcClient.currentAccount !== 'undefined' }
267
293
  }
268
294
  })