@aeternity/aepp-sdk 10.0.0-beta.1 → 10.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 (113) hide show
  1. package/CHANGELOG.md +1603 -0
  2. package/dist/aepp-sdk.browser-script.js +1 -1
  3. package/dist/aepp-sdk.browser-script.js.map +1 -1
  4. package/dist/aepp-sdk.browser.js +1 -1
  5. package/dist/aepp-sdk.browser.js.map +1 -1
  6. package/dist/aepp-sdk.js +1 -1
  7. package/dist/aepp-sdk.js.map +1 -1
  8. package/es/account/base.js +3 -1
  9. package/es/account/base.js.map +1 -1
  10. package/es/account/multiple.js +4 -2
  11. package/es/account/multiple.js.map +1 -1
  12. package/es/ae/aens.js +52 -38
  13. package/es/ae/aens.js.map +1 -1
  14. package/es/ae/contract.js +9 -5
  15. package/es/ae/contract.js.map +1 -1
  16. package/es/ae/index.js +4 -3
  17. package/es/ae/index.js.map +1 -1
  18. package/es/ae/oracle.js +4 -4
  19. package/es/ae/oracle.js.map +1 -1
  20. package/es/ae/universal.js.map +1 -1
  21. package/es/chain/index.js +8 -4
  22. package/es/chain/index.js.map +1 -1
  23. package/es/chain/node.js +15 -20
  24. package/es/chain/node.js.map +1 -1
  25. package/es/channel/handlers.js.map +1 -1
  26. package/es/channel/index.js +35 -14
  27. package/es/channel/index.js.map +1 -1
  28. package/es/contract/aci/index.js +12 -7
  29. package/es/contract/aci/index.js.map +1 -1
  30. package/es/contract/compiler.js +3 -1
  31. package/es/contract/compiler.js.map +1 -1
  32. package/es/contract/ga/helpers.js +6 -6
  33. package/es/contract/ga/helpers.js.map +1 -1
  34. package/es/contract/ga/index.js +6 -2
  35. package/es/contract/ga/index.js.map +1 -1
  36. package/es/contract/index.js +6 -2
  37. package/es/contract/index.js.map +1 -1
  38. package/es/index.js +1 -0
  39. package/es/index.js.map +1 -1
  40. package/es/node-pool/index.js +4 -2
  41. package/es/node-pool/index.js.map +1 -1
  42. package/es/node.js +9 -4
  43. package/es/node.js.map +1 -1
  44. package/es/tx/builder/helpers.js +20 -33
  45. package/es/tx/builder/helpers.js.map +1 -1
  46. package/es/tx/builder/index.js +13 -6
  47. package/es/tx/builder/index.js.map +1 -1
  48. package/es/tx/builder/schema.js +5 -4
  49. package/es/tx/builder/schema.js.map +1 -1
  50. package/es/tx/index.js +101 -12
  51. package/es/tx/index.js.map +1 -1
  52. package/es/tx/tx-object.js +9 -3
  53. package/es/tx/tx-object.js.map +1 -1
  54. package/es/tx/tx.js.map +1 -1
  55. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
  56. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
  57. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +15 -6
  58. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
  59. package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
  60. package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
  61. package/es/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
  62. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
  63. package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
  64. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +13 -5
  65. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
  66. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
  67. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
  68. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +57 -40
  69. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
  70. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
  71. package/es/utils/crypto.js +1 -40
  72. package/es/utils/crypto.js.map +1 -1
  73. package/es/utils/keystore.js.map +1 -1
  74. package/es/utils/swagger.js +3 -1
  75. package/es/utils/swagger.js.map +1 -1
  76. package/package.json +11 -13
  77. package/src/account/base.js +3 -1
  78. package/src/account/multiple.js +4 -2
  79. package/src/ae/aens.js +41 -42
  80. package/src/ae/contract.js +9 -5
  81. package/src/ae/index.js +4 -3
  82. package/src/ae/oracle.js +9 -5
  83. package/src/ae/universal.js +3 -1
  84. package/src/chain/index.js +8 -4
  85. package/src/chain/node.js +17 -14
  86. package/src/channel/handlers.js +10 -3
  87. package/src/channel/index.js +40 -15
  88. package/src/contract/aci/index.js +15 -8
  89. package/src/contract/compiler.js +6 -2
  90. package/src/contract/ga/helpers.js +5 -3
  91. package/src/contract/ga/index.js +6 -2
  92. package/src/contract/index.js +6 -2
  93. package/src/index.js +2 -0
  94. package/src/node-pool/index.js +4 -2
  95. package/src/node.js +7 -4
  96. package/src/tx/builder/helpers.js +20 -33
  97. package/src/tx/builder/index.js +49 -13
  98. package/src/tx/builder/schema.js +37 -14
  99. package/src/tx/index.js +101 -12
  100. package/src/tx/tx-object.js +25 -6
  101. package/src/tx/tx.js +94 -28
  102. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
  103. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
  104. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  105. package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
  106. package/src/utils/aepp-wallet-communication/helpers.js +4 -2
  107. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +32 -9
  108. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
  109. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +53 -22
  110. package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
  111. package/src/utils/crypto.js +1 -52
  112. package/src/utils/keystore.js +10 -2
  113. package/src/utils/swagger.js +1 -1
@@ -51,9 +51,11 @@ 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
+ export const sendResponseMessage = (client) => (id, method, data) =>
58
+ client.sendMessage(responseMessage(id, method, data), true)
57
59
 
58
60
  export const voidFn = () => undefined
59
61
 
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc
5
5
  * @export AeppRpc
6
- * @example import ContentScriptBridge from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
6
+ * @example
7
+ * import ContentScriptBridge
8
+ * from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/aepp-rpc'
7
9
  */
8
10
  import { v4 as uuid } from 'uuid'
9
11
  import Ae from '../../../ae'
@@ -40,15 +42,21 @@ const RESPONSES = {
40
42
  [METHODS.aepp.subscribeAddress]: (instance) =>
41
43
  (msg) => {
42
44
  if (msg.result) {
43
- msg.result.address && (instance.rpcClient.accounts = msg.result.address)
44
- msg.result.subscription && (instance.rpcClient.addressSubscription = msg.result.subscription)
45
+ if (msg.result.address) {
46
+ instance.rpcClient.accounts = msg.result.address
47
+ }
48
+ if (msg.result.subscription) {
49
+ instance.rpcClient.addressSubscription = msg.result.subscription
50
+ }
45
51
  }
46
52
 
47
53
  instance.rpcClient.processResponse(msg, ({ id, result }) => [result])
48
54
  },
49
55
  [METHODS.aepp.sign]: (instance) =>
50
56
  (msg) => {
51
- instance.rpcClient.processResponse(msg, ({ id, result }) => [result.signedTransaction || result.transactionHash])
57
+ instance.rpcClient.processResponse(
58
+ msg, ({ id, result }) => [result.signedTransaction || result.transactionHash]
59
+ )
52
60
  },
53
61
  [METHODS.aepp.signMessage]: (instance) =>
54
62
  (msg) => {
@@ -82,7 +90,15 @@ const handleMessage = (instance) => async (msg) => {
82
90
  * @return {Object}
83
91
  */
84
92
  export default Ae.compose({
85
- async init ({ name, onAddressChange = voidFn, onDisconnect = voidFn, onNetworkChange = voidFn, connection, forceValidation = false, debug = false }) {
93
+ async init ({
94
+ name,
95
+ onAddressChange = voidFn,
96
+ onDisconnect = voidFn,
97
+ onNetworkChange = voidFn,
98
+ connection,
99
+ forceValidation = false,
100
+ debug = false
101
+ }) {
86
102
  const eventsHandlers = ['onDisconnect', 'onAddressChange', 'onNetworkChange']
87
103
  this.connection = connection
88
104
  this.name = name
@@ -166,7 +182,7 @@ export default Ae.compose({
166
182
  * @function subscribeAddress
167
183
  * @instance
168
184
  * @rtype (type: String, value: String) => Promise
169
- * @param {String} type Type of subscription can be one of ['current'(just for selected account updates), 'connected(all accounts)']
185
+ * @param {String} type Should be one of 'current' (the selected account), 'connected' (all)
170
186
  * @param {String} value Subscription action('subscribe'|'unsubscribe')
171
187
  * @return {Promise} Address from wallet
172
188
  */
@@ -186,7 +202,10 @@ export default Ae.compose({
186
202
  if (!this.rpcClient || !this.rpcClient.isConnected()) throw new Error('You are not connected to Wallet')
187
203
  if (!this.rpcClient.currentAccount) throw new Error('You are not subscribed for an account.')
188
204
  if (opt.onAccount && !this.rpcClient.hasAccessToAccount(opt.onAccount)) throw new Error(`You do not have access to account ${opt.onAccount}`)
189
- return this.rpcClient.request(METHODS.aepp.sign, { ...opt, tx, returnSigned: true, networkId: this.getNetworkId() })
205
+ return this.rpcClient.request(
206
+ METHODS.aepp.sign,
207
+ { ...opt, tx, returnSigned: true, networkId: this.getNetworkId() }
208
+ )
190
209
  },
191
210
  /**
192
211
  * Overwriting of `signMessage` AE method
@@ -221,7 +240,8 @@ export default Ae.compose({
221
240
  /**
222
241
  * Overwriting of `send` AE method
223
242
  * All sdk API which use it will be send notification to wallet and wait for callBack
224
- * This method will sign, broadcast and wait until transaction will be accepted using rpc communication with wallet
243
+ * This method will sign, broadcast and wait until transaction will be accepted using rpc
244
+ * communication with wallet
225
245
  * @function send
226
246
  * @instance
227
247
  * @rtype (tx: String, options = {}) => Promise
@@ -239,7 +259,10 @@ export default Ae.compose({
239
259
  const signed = await this.signTransaction(tx, { onAccount: opt.onAccount })
240
260
  return this.sendTransaction(signed, opt)
241
261
  }
242
- return this.rpcClient.request(METHODS.aepp.sign, { onAccount: opt.onAccount, tx, returnSigned: false, networkId: this.getNetworkId() })
262
+ return this.rpcClient.request(
263
+ METHODS.aepp.sign,
264
+ { onAccount: opt.onAccount, tx, returnSigned: false, networkId: this.getNetworkId() }
265
+ )
243
266
  }
244
267
  }
245
268
  })
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client
5
5
  * @export { RpcClient, RpcClients }
6
- * @example import RpcClient from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client'
6
+ * @example
7
+ * import RpcClient from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client'
7
8
  */
8
9
  import stampit from '@stamp/it'
9
10
 
@@ -18,7 +19,9 @@ import { sendMessage, message, isValidAccounts } from '../helpers'
18
19
  * @param {Object} param Init params object
19
20
  * @param {String} param.name Client name
20
21
  * @param {Object} param.connection Connection object
21
- * @param {Function[]} param.handlers Arrays with two function for handling messages ([ onMessage: Function, onDisconnect: Function])
22
+ * @param {Function[]} param.handlers Array with two function for message handling
23
+ * @param {Function} param.handlers[0] Message handler
24
+ * @param {Function} param.handlers[1] Disconnect callback
22
25
  * @return {Object}
23
26
  */
24
27
  export default stampit({
@@ -148,10 +151,11 @@ export default stampit({
148
151
  },
149
152
  /**
150
153
  * Update accounts and sent `update.address` notification to AEPP
151
- * @param {{ current: Object, connected: Object }} accounts Object with current and connected accounts
152
- * @param {{ forceNotification: Boolean }} [options={ forceNotification: false }] Don not sent update notification to AEPP
154
+ * @param {{ current: Object, connected: Object }} accounts Current and connected accounts
155
+ * @param {Object} [options]
156
+ * @param {Boolean} [options.forceNotification] Don't sent update notification to AEPP
153
157
  */
154
- setAccounts (accounts, { forceNotification = false } = {}) {
158
+ setAccounts (accounts, { forceNotification } = {}) {
155
159
  if (!isValidAccounts(accounts)) {
156
160
  throw new Error('Invalid accounts object. Should be object like: `{ connected: {}, selected: {} }`')
157
161
  }
@@ -3,7 +3,8 @@
3
3
  *
4
4
  * @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc
5
5
  * @export WalletRpc
6
- * @example import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
6
+ * @example
7
+ * import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
7
8
  */
8
9
  import { v4 as uuid } from 'uuid'
9
10
  import Ae from '../../../ae'
@@ -89,20 +90,28 @@ const REQUESTS = {
89
90
  return callInstance(
90
91
  'onAskAccounts',
91
92
  {},
92
- ({ accounts } = {}) => ({ result: accounts || [...Object.keys(client.accounts.current), ...Object.keys(client.accounts.connected)] }),
93
+ ({ accounts } = {}) => ({
94
+ result: accounts ||
95
+ [...Object.keys(client.accounts.current), ...Object.keys(client.accounts.connected)]
96
+ }),
93
97
  (error) => ({ error: ERRORS.rejectedByUser(error) })
94
98
  )
95
99
  },
96
- [METHODS.aepp.sign] (callInstance, instance, client, { tx, onAccount, networkId, returnSigned = false }) {
100
+ [METHODS.aepp.sign] (callInstance, instance, client, options) {
101
+ const { tx, onAccount, networkId, returnSigned = false } = options
97
102
  const address = onAccount || client.currentAccount
98
103
  // Update client with new networkId
99
104
  networkId && client.updateInfo({ networkId })
100
105
  // Authorization check
101
106
  if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
102
107
  // Account permission check
103
- if (!client.hasAccessToAccount(address)) return { error: ERRORS.permissionDeny({ account: address }) }
108
+ if (!client.hasAccessToAccount(address)) {
109
+ return { error: ERRORS.permissionDeny({ account: address }) }
110
+ }
104
111
  // NetworkId check
105
- if (!networkId || networkId !== instance.getNetworkId()) return { error: ERRORS.unsupportedNetwork() }
112
+ if (!networkId || networkId !== instance.getNetworkId()) {
113
+ return { error: ERRORS.unsupportedNetwork() }
114
+ }
106
115
 
107
116
  return callInstance(
108
117
  'onSign',
@@ -116,11 +125,11 @@ const REQUESTS = {
116
125
  return { error: ERRORS.internalError({ msg: e.message }) }
117
126
  }
118
127
  try {
119
- return {
120
- result: returnSigned
121
- ? { signedTransaction: await instance.signTransaction(rawTx || tx, { onAccount: onAcc }) }
122
- : { transactionHash: await instance.send(rawTx || tx, { onAccount: onAcc, verify: false }) }
123
- }
128
+ const t = rawTx || tx
129
+ const result = returnSigned
130
+ ? { signedTransaction: await instance.signTransaction(t, { onAccount: onAcc }) }
131
+ : { transactionHash: await instance.send(t, { onAccount: onAcc, verify: false }) }
132
+ return { result }
124
133
  } catch (e) {
125
134
  if (!returnSigned) {
126
135
  // Validate transaction
@@ -139,7 +148,9 @@ const REQUESTS = {
139
148
  // Authorization check
140
149
  if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
141
150
  const address = onAccount || client.currentAccount
142
- if (!client.hasAccessToAccount(address)) return { error: ERRORS.permissionDeny({ account: address }) }
151
+ if (!client.hasAccessToAccount(address)) {
152
+ return { error: ERRORS.permissionDeny({ account: address }) }
153
+ }
143
154
 
144
155
  return callInstance(
145
156
  'onMessageSign',
@@ -168,7 +179,9 @@ const REQUESTS = {
168
179
  const handleMessage = (instance, id) => async (msg, origin) => {
169
180
  const client = instance.rpcClients[id]
170
181
  if (!msg.id) {
171
- return getHandler(NOTIFICATIONS, msg, { debug: instance.debug })(instance, { client })(msg, origin)
182
+ return getHandler(
183
+ NOTIFICATIONS, msg, { debug: instance.debug }
184
+ )(instance, { client })(msg, origin)
172
185
  }
173
186
  if (Object.prototype.hasOwnProperty.call(client.callbacks, msg.id)) {
174
187
  return getHandler(RESPONSES, msg, { debug: instance.debug })(instance, { client })(msg, origin)
@@ -188,7 +201,9 @@ const handleMessage = (instance, id) => async (msg, origin) => {
188
201
  )
189
202
  })
190
203
  // TODO make one structure for handler functions
191
- const errorObjectOrHandler = getHandler(REQUESTS, msg, { debug: instance.debug })(callInstance, instance, client, msg.params)
204
+ const errorObjectOrHandler = getHandler(REQUESTS, msg, { debug: instance.debug })(
205
+ callInstance, instance, client, msg.params
206
+ )
192
207
  const response = typeof errorObjectOrHandler === 'function' ? await errorObjectOrHandler() : errorObjectOrHandler
193
208
  sendResponseMessage(client)(id, method, response)
194
209
  }
@@ -201,18 +216,31 @@ const handleMessage = (instance, id) => async (msg, origin) => {
201
216
  * @rtype Stamp
202
217
  * @param {Object} param Init params object
203
218
  * @param {String=} [param.name] Wallet name
204
- * @param {Function} onConnection Call-back function for incoming AEPP connection (Second argument contain function for accept/deny request)
205
- * @param {Function} onSubscription Call-back function for incoming AEPP account subscription (Second argument contain function for accept/deny request)
206
- * @param {Function} onSign Call-back function for incoming AEPP sign request (Second argument contain function for accept/deny request)
207
- * @param {Function} onAskAccounts Call-back function for incoming AEPP get address request (Second argument contain function for accept/deny request)
208
- * @param {Function} onMessageSign Call-back function for incoming AEPP sign message request (Second argument contain function for accept/deny request)
219
+ * @param {Function} onConnection Call-back function for incoming AEPP connection
220
+ * @param {Function} onSubscription Call-back function for incoming AEPP account subscription
221
+ * @param {Function} onSign Call-back function for incoming AEPP sign request
222
+ * @param {Function} onAskAccounts Call-back function for incoming AEPP get address request
223
+ * @param {Function} onMessageSign Call-back function for incoming AEPP sign message request
224
+ * Second argument of incoming call-backs contain function for accept/deny request
209
225
  * @param {Function} onDisconnect Call-back function for disconnect event
210
226
  * @return {Object}
211
227
  */
212
228
  export default Ae.compose(AccountMultiple, {
213
- init ({ name, onConnection, onSubscription, onSign, onDisconnect, onAskAccounts, onMessageSign, forceValidation = false, debug = false } = {}) {
229
+ init ({
230
+ name,
231
+ onConnection,
232
+ onSubscription,
233
+ onSign,
234
+ onDisconnect,
235
+ onAskAccounts,
236
+ onMessageSign,
237
+ forceValidation = false,
238
+ debug = false
239
+ } = {}) {
214
240
  this.debug = debug
215
- const eventsHandlers = ['onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign']
241
+ const eventsHandlers = [
242
+ 'onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign'
243
+ ]
216
244
  // CallBacks for events
217
245
  this.onConnection = onConnection
218
246
  this.onSubscription = onSubscription
@@ -223,7 +251,9 @@ export default Ae.compose(AccountMultiple, {
223
251
  this.rpcClients = {}
224
252
 
225
253
  eventsHandlers.forEach(event => {
226
- if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`)
254
+ if (!forceValidation && typeof this[event] !== 'function') {
255
+ throw new Error(`Call-back for ${event} must be an function!`)
256
+ }
227
257
  })
228
258
  //
229
259
  this.name = name
@@ -298,7 +328,8 @@ export default Ae.compose(AccountMultiple, {
298
328
  * @return {String} Client ID
299
329
  */
300
330
  addRpcClient (clientConnection) {
301
- // @TODO detect if aepp has some history based on origin????: if yes use this instance for connection
331
+ // @TODO detect if aepp has some history based on origin????
332
+ // if yes use this instance for connection
302
333
  const id = uuid()
303
334
  this.rpcClients[id] = RpcClient({
304
335
  id,
@@ -52,7 +52,10 @@ export default stampit({
52
52
  scan (onDetected) {
53
53
  const { wallets } = this
54
54
  this.connection.connect(({ method, params }, origin, source) => {
55
- if (!method || !params || method !== METHODS.wallet.readyToConnect || wallets[params.id]) return
55
+ if (
56
+ !method || !params ||
57
+ method !== METHODS.wallet.readyToConnect || wallets[params.id]
58
+ ) return
56
59
 
57
60
  const wallet = {
58
61
  ...params,
@@ -22,7 +22,6 @@
22
22
  */
23
23
 
24
24
  import bs58check from 'bs58check'
25
- import ed2curve from 'ed2curve'
26
25
  import nacl from 'tweetnacl'
27
26
  import aesjs from 'aes-js'
28
27
  import shajs from 'sha.js'
@@ -193,7 +192,7 @@ export function generateKeyPairFromSecret (secret) {
193
192
 
194
193
  /**
195
194
  * Generate a random ED25519 keypair
196
- * @rtype (raw: Boolean) => {publicKey: String, secretKey: String} | {publicKey: Buffer, secretKey: Buffer}
195
+ * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}
197
196
  * @param {Boolean} raw - Whether to return raw (binary) keys
198
197
  * @return {Object} Key pair
199
198
  */
@@ -311,53 +310,3 @@ export function isValidKeypair (privateKey, publicKey) {
311
310
  const signature = sign(message, privateKey)
312
311
  return verify(message, signature, publicKey)
313
312
  }
314
-
315
- /**
316
- * This function encrypts a message using base58check encoded and 'ak' prefixed
317
- * publicKey such that only the corresponding secretKey will
318
- * be able to decrypt
319
- * @rtype (msg: String, publicKey: String) => Object
320
- * @param {Buffer} msg - Data to encode
321
- * @param {String} publicKey - Public key
322
- * @return {Object}
323
- */
324
- export function encryptData (msg, publicKey) {
325
- const ephemeralKeyPair = nacl.box.keyPair()
326
- const pubKeyUInt8Array = decode(publicKey, 'ak')
327
- const nonce = nacl.randomBytes(nacl.box.nonceLength)
328
-
329
- const encryptedMessage = nacl.box(
330
- Buffer.from(msg),
331
- nonce,
332
- ed2curve.convertPublicKey(pubKeyUInt8Array),
333
- ephemeralKeyPair.secretKey
334
- )
335
-
336
- return {
337
- ciphertext: Buffer.from(encryptedMessage).toString('hex'),
338
- ephemPubKey: Buffer.from(ephemeralKeyPair.publicKey).toString('hex'),
339
- nonce: Buffer.from(nonce).toString('hex'),
340
- version: 'x25519-xsalsa20-poly1305'
341
- }
342
- }
343
-
344
- /**
345
- * This function decrypt a message using secret key
346
- * @rtype (secretKey: String, encryptedData: Object) => Buffer|null
347
- * @param {String} secretKey - Secret key
348
- * @param {Object} encryptedData - Encrypted data
349
- * @return {Buffer|null}
350
- */
351
- export function decryptData (secretKey, encryptedData) {
352
- const receiverSecretKeyUint8Array = ed2curve.convertSecretKey(Buffer.from(secretKey, 'hex'))
353
- const nonce = Buffer.from(encryptedData.nonce, 'hex')
354
- const ciphertext = Buffer.from(encryptedData.ciphertext, 'hex')
355
- const ephemPubKey = Buffer.from(encryptedData.ephemPubKey, 'hex')
356
- const decrypted = nacl.box.open(
357
- ciphertext,
358
- nonce,
359
- ephemPubKey,
360
- receiverSecretKeyUint8Array
361
- )
362
- return decrypted ? Buffer.from(decrypted) : decrypted
363
- }
@@ -189,7 +189,14 @@ export async function recover (password, keyObject) {
189
189
  * @param {Object=} options.kdfparams KDF parameters (default: constants.<kdf>).
190
190
  * @return {Object}
191
191
  */
192
- export async function dump (name, password, privateKey, nonce = nacl.randomBytes(24), salt = nacl.randomBytes(16), options = {}) {
192
+ export async function dump (
193
+ name,
194
+ password,
195
+ privateKey,
196
+ nonce = nacl.randomBytes(24),
197
+ salt = nacl.randomBytes(16),
198
+ options = {}
199
+ ) {
193
200
  const opt = Object.assign({}, DEFAULTS.crypto, options)
194
201
  return marshal(
195
202
  name,
@@ -208,7 +215,8 @@ export function validateKeyObj (obj) {
208
215
  const missingRootKeys = root.filter(key => !Object.prototype.hasOwnProperty.call(obj, key))
209
216
  if (missingRootKeys.length) throw new Error(`Invalid key file format. Require properties: ${missingRootKeys}`)
210
217
 
211
- const missingCryptoKeys = cryptoKeys.filter(key => !Object.prototype.hasOwnProperty.call(obj.crypto, key))
218
+ const missingCryptoKeys = cryptoKeys
219
+ .filter(key => !Object.prototype.hasOwnProperty.call(obj.crypto, key))
212
220
  if (missingCryptoKeys.length) throw new Error(`Invalid key file format. Require properties: ${missingCryptoKeys}`)
213
221
 
214
222
  return true
@@ -66,7 +66,7 @@ export default async (
66
66
  url,
67
67
  spec,
68
68
  responseInterceptor: response => {
69
- if (!response.text) return response
69
+ if (response.text === '' || response.text?.size === 0) return response
70
70
  const body = jsonImp.parse(response.text)
71
71
  Object.assign(response, {
72
72
  body: disableCaseConversion ? body : pascalizeKeys(body)