@aeternity/aepp-sdk 9.0.1 → 11.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) 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 -36
  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.mjs +179 -0
  10. package/es/account/base.mjs.map +1 -0
  11. package/es/account/memory.mjs +99 -0
  12. package/es/account/memory.mjs.map +1 -0
  13. package/es/account/multiple.mjs +179 -0
  14. package/es/account/multiple.mjs.map +1 -0
  15. package/es/ae/aens.mjs +404 -0
  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.mjs +207 -0
  22. package/es/ae/index.mjs.map +1 -0
  23. package/es/ae/oracle.mjs +339 -0
  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} +29 -9
  32. package/es/chain/index.mjs.map +1 -0
  33. package/es/chain/node.mjs +442 -0
  34. package/es/chain/node.mjs.map +1 -0
  35. package/es/channel/handlers.mjs +1110 -0
  36. package/es/channel/handlers.mjs.map +1 -0
  37. package/es/channel/{index.js → index.mjs} +245 -472
  38. package/es/channel/index.mjs.map +1 -0
  39. package/es/channel/internal.mjs +283 -0
  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.mjs +178 -0
  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.mjs +188 -0
  53. package/es/node-pool/index.mjs.map +1 -0
  54. package/es/node.mjs +133 -0
  55. package/es/node.mjs.map +1 -0
  56. package/es/other.d.ts +1 -1
  57. package/es/tx/builder/field-types.mjs +74 -0
  58. package/es/tx/builder/field-types.mjs.map +1 -0
  59. package/es/tx/builder/helpers.mjs +363 -0
  60. package/es/tx/builder/helpers.mjs.map +1 -0
  61. package/es/tx/builder/index.mjs +606 -0
  62. package/es/tx/builder/index.mjs.map +1 -0
  63. package/es/tx/builder/schema.mjs +760 -0
  64. package/es/tx/builder/schema.mjs.map +1 -0
  65. package/es/tx/{index.js → index.mjs} +107 -15
  66. package/es/tx/index.mjs.map +1 -0
  67. package/es/tx/tx-object.mjs +283 -0
  68. package/es/tx/tx-object.mjs.map +1 -0
  69. package/es/tx/tx.mjs +938 -0
  70. package/es/tx/tx.mjs.map +1 -0
  71. package/es/tx/validator.mjs +247 -0
  72. package/es/tx/validator.mjs.map +1 -0
  73. package/es/typings/blakejs/index.d.mjs +2 -0
  74. package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
  75. package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
  76. package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
  77. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
  78. package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
  79. package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
  80. package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
  81. package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
  82. package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
  83. package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
  84. package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
  85. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
  86. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
  87. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
  88. package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
  89. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
  90. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
  91. package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
  92. package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
  93. package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
  94. package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
  95. package/es/utils/amount-formatter.mjs +139 -0
  96. package/es/utils/amount-formatter.mjs.map +1 -0
  97. package/es/utils/async-init.mjs +64 -0
  98. package/es/utils/async-init.mjs.map +1 -0
  99. package/es/utils/bignumber.mjs +21 -0
  100. package/es/utils/bignumber.mjs.map +1 -0
  101. package/es/utils/{bytes.js → bytes.mjs} +16 -12
  102. package/es/utils/bytes.mjs.map +1 -0
  103. package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
  104. package/es/utils/crypto-ts.mjs.map +1 -0
  105. package/es/utils/crypto.mjs +239 -0
  106. package/es/utils/crypto.mjs.map +1 -0
  107. package/es/utils/errors.mjs +689 -0
  108. package/es/utils/errors.mjs.map +1 -0
  109. package/es/utils/hd-wallet.mjs +111 -0
  110. package/es/utils/hd-wallet.mjs.map +1 -0
  111. package/es/utils/json-big.mjs +45 -0
  112. package/es/utils/json-big.mjs.map +1 -0
  113. package/es/utils/keystore.mjs +240 -0
  114. package/es/utils/keystore.mjs.map +1 -0
  115. package/es/utils/mptree.mjs +161 -0
  116. package/es/utils/mptree.mjs.map +1 -0
  117. package/es/utils/other.mjs +43 -0
  118. package/es/utils/other.mjs.map +1 -0
  119. package/es/utils/semver-satisfies.mjs +16 -0
  120. package/es/utils/semver-satisfies.mjs.map +1 -0
  121. package/es/utils/{string.js → string.mjs} +5 -14
  122. package/es/utils/string.mjs.map +1 -0
  123. package/es/utils/swagger.mjs +164 -0
  124. package/es/utils/swagger.mjs.map +1 -0
  125. package/package.json +55 -62
  126. package/src/account/base.js +3 -1
  127. package/src/account/memory.js +13 -8
  128. package/src/account/multiple.js +31 -22
  129. package/src/ae/aens.js +75 -77
  130. package/src/ae/aepp.js +2 -2
  131. package/src/ae/contract.js +27 -291
  132. package/src/ae/index.js +9 -7
  133. package/src/ae/oracle.js +51 -28
  134. package/src/ae/universal.js +4 -2
  135. package/src/ae/wallet.js +2 -2
  136. package/src/chain/index.js +29 -6
  137. package/src/chain/node.js +95 -67
  138. package/src/channel/handlers.js +30 -21
  139. package/src/channel/index.js +44 -20
  140. package/src/channel/internal.js +30 -24
  141. package/src/contract/aci.js +376 -0
  142. package/src/contract/compiler.js +41 -91
  143. package/src/contract/ga/helpers.js +10 -13
  144. package/src/contract/ga/index.js +42 -33
  145. package/src/index.js +9 -10
  146. package/src/node-pool/index.js +29 -17
  147. package/src/node.js +33 -36
  148. package/src/tx/builder/field-types.js +61 -0
  149. package/src/tx/builder/helpers.js +126 -84
  150. package/src/tx/builder/index.js +83 -41
  151. package/src/tx/builder/schema.js +50 -40
  152. package/src/tx/index.js +101 -12
  153. package/src/tx/tx-object.js +35 -15
  154. package/src/tx/tx.js +232 -153
  155. package/src/tx/validator.js +34 -12
  156. package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
  157. package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
  158. package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
  159. package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
  160. package/src/utils/aepp-wallet-communication/helpers.js +6 -14
  161. package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
  162. package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
  163. package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
  164. package/src/utils/aepp-wallet-communication/schema.ts +80 -0
  165. package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
  166. package/src/utils/amount-formatter.ts +4 -3
  167. package/src/utils/async-init.js +10 -6
  168. package/src/utils/bignumber.ts +3 -10
  169. package/src/utils/bytes.ts +3 -2
  170. package/src/utils/crypto-ts.ts +2 -2
  171. package/src/utils/crypto.js +10 -144
  172. package/src/utils/errors.ts +683 -0
  173. package/src/utils/hd-wallet.js +11 -26
  174. package/src/utils/keystore.js +57 -53
  175. package/src/utils/mptree.ts +12 -6
  176. package/src/utils/other.ts +1 -1
  177. package/src/utils/semver-satisfies.ts +1 -1
  178. package/src/utils/swagger.js +75 -45
  179. package/es/account/base.js +0 -259
  180. package/es/account/base.js.map +0 -1
  181. package/es/account/memory.js +0 -86
  182. package/es/account/memory.js.map +0 -1
  183. package/es/account/multiple.js +0 -267
  184. package/es/account/multiple.js.map +0 -1
  185. package/es/ae/aens.js +0 -829
  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 -985
  189. package/es/ae/contract.js.map +0 -1
  190. package/es/ae/index.js +0 -442
  191. package/es/ae/index.js.map +0 -1
  192. package/es/ae/oracle.js +0 -690
  193. package/es/ae/oracle.js.map +0 -1
  194. package/es/ae/universal.js.map +0 -1
  195. package/es/ae/wallet.js.map +0 -1
  196. package/es/chain/index.js.map +0 -1
  197. package/es/chain/node.js +0 -1119
  198. package/es/chain/node.js.map +0 -1
  199. package/es/channel/handlers.js +0 -1601
  200. package/es/channel/handlers.js.map +0 -1
  201. package/es/channel/index.js.map +0 -1
  202. package/es/channel/internal.js +0 -438
  203. package/es/channel/internal.js.map +0 -1
  204. package/es/contract/aci/helpers.js +0 -298
  205. package/es/contract/aci/helpers.js.map +0 -1
  206. package/es/contract/aci/index.js +0 -517
  207. package/es/contract/aci/index.js.map +0 -1
  208. package/es/contract/aci/transformation.js +0 -742
  209. package/es/contract/aci/transformation.js.map +0 -1
  210. package/es/contract/compiler.js +0 -316
  211. package/es/contract/compiler.js.map +0 -1
  212. package/es/contract/ga/helpers.js +0 -120
  213. package/es/contract/ga/helpers.js.map +0 -1
  214. package/es/contract/ga/index.js +0 -307
  215. package/es/contract/ga/index.js.map +0 -1
  216. package/es/contract/index.js +0 -158
  217. package/es/contract/index.js.map +0 -1
  218. package/es/index.js +0 -57
  219. package/es/index.js.map +0 -1
  220. package/es/node-pool/index.js +0 -204
  221. package/es/node-pool/index.js.map +0 -1
  222. package/es/node.js +0 -228
  223. package/es/node.js.map +0 -1
  224. package/es/tx/builder/helpers.js +0 -355
  225. package/es/tx/builder/helpers.js.map +0 -1
  226. package/es/tx/builder/index.js +0 -686
  227. package/es/tx/builder/index.js.map +0 -1
  228. package/es/tx/builder/schema.js +0 -695
  229. package/es/tx/builder/schema.js.map +0 -1
  230. package/es/tx/index.js.map +0 -1
  231. package/es/tx/tx-object.js +0 -297
  232. package/es/tx/tx-object.js.map +0 -1
  233. package/es/tx/tx.js +0 -1757
  234. package/es/tx/tx.js.map +0 -1
  235. package/es/tx/validator.js +0 -344
  236. package/es/tx/validator.js.map +0 -1
  237. package/es/typings/blakejs/index.d.js +0 -2
  238. package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
  239. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
  240. package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
  241. package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
  242. package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
  243. package/es/utils/aepp-wallet-communication/helpers.js +0 -148
  244. package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
  245. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
  246. package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
  247. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
  248. package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
  249. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
  250. package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
  251. package/es/utils/aepp-wallet-communication/schema.js +0 -103
  252. package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
  253. package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
  254. package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
  255. package/es/utils/amount-formatter.js +0 -152
  256. package/es/utils/amount-formatter.js.map +0 -1
  257. package/es/utils/async-init.js +0 -103
  258. package/es/utils/async-init.js.map +0 -1
  259. package/es/utils/bignumber.js +0 -36
  260. package/es/utils/bignumber.js.map +0 -1
  261. package/es/utils/bytes.js.map +0 -1
  262. package/es/utils/crypto-ts.js.map +0 -1
  263. package/es/utils/crypto.js +0 -358
  264. package/es/utils/crypto.js.map +0 -1
  265. package/es/utils/hd-wallet.js +0 -148
  266. package/es/utils/hd-wallet.js.map +0 -1
  267. package/es/utils/json-big.js +0 -78
  268. package/es/utils/json-big.js.map +0 -1
  269. package/es/utils/keystore.js +0 -393
  270. package/es/utils/keystore.js.map +0 -1
  271. package/es/utils/mptree.js +0 -198
  272. package/es/utils/mptree.js.map +0 -1
  273. package/es/utils/other.js +0 -93
  274. package/es/utils/other.js.map +0 -1
  275. package/es/utils/semver-satisfies.js +0 -35
  276. package/es/utils/semver-satisfies.js.map +0 -1
  277. package/es/utils/string.js.map +0 -1
  278. package/es/utils/swagger.js +0 -269
  279. package/es/utils/swagger.js.map +0 -1
  280. package/src/contract/aci/helpers.js +0 -140
  281. package/src/contract/aci/index.js +0 -191
  282. package/src/contract/aci/transformation.js +0 -464
  283. package/src/contract/index.js +0 -159
  284. package/src/utils/aepp-wallet-communication/schema.js +0 -110
@@ -21,15 +21,14 @@
21
21
  * @example import { Crypto } from '@aeternity/aepp-sdk'
22
22
  */
23
23
 
24
- import bs58check from 'bs58check'
25
- import ed2curve from 'ed2curve'
26
24
  import nacl from 'tweetnacl'
27
25
  import aesjs from 'aes-js'
28
26
  import shajs from 'sha.js'
29
27
 
30
- import { str2buf, toBytes } from './bytes'
31
- import { decode } from '../tx/builder/helpers'
28
+ import { str2buf } from './bytes'
29
+ import { encode, decode } from '../tx/builder/helpers'
32
30
  import { hash } from './crypto-ts'
31
+ import { NotImplementedError } from './errors'
33
32
 
34
33
  export * from './crypto-ts'
35
34
 
@@ -44,7 +43,7 @@ const Ecb = aesjs.ModeOfOperation.ecb
44
43
  export function getAddressFromPriv (secret) {
45
44
  const keys = nacl.sign.keyPair.fromSecretKey(str2buf(secret))
46
45
  const publicBuffer = Buffer.from(keys.publicKey)
47
- return `ak_${encodeBase58Check(publicBuffer)}`
46
+ return encode(publicBuffer, 'ak')
48
47
  }
49
48
 
50
49
  /**
@@ -55,24 +54,14 @@ export function getAddressFromPriv (secret) {
55
54
  * @return {Boolean} valid
56
55
  */
57
56
  export function isAddressValid (address, prefix = 'ak') {
58
- if (typeof address !== 'string') return false
59
57
  try {
60
- return decode(address, prefix).length === 32
58
+ decode(address, prefix)
59
+ return true
61
60
  } catch (e) {
62
61
  return false
63
62
  }
64
63
  }
65
64
 
66
- /**
67
- * Parse decimal address and return base58Check encoded address with prefix 'ak'
68
- * @rtype (input: String) => address: String
69
- * @param {String} decimalAddress - Address
70
- * @return {String} address
71
- */
72
- export function addressFromDecimal (decimalAddress) {
73
- return aeEncodeKey(toBytes(decimalAddress, true))
74
- }
75
-
76
65
  /**
77
66
  * Calculate SHA256 hash of `input`
78
67
  * @rtype (input: String) => hash: String
@@ -92,66 +81,6 @@ export function salt () {
92
81
  return Math.floor(Math.random() * Math.floor(Number.MAX_SAFE_INTEGER))
93
82
  }
94
83
 
95
- /**
96
- * Base64check encode given `input`
97
- * @rtype (input: String|buffer) => Buffer
98
- * @param {String} input - Data to encode
99
- * @return {Buffer} Base64check encoded data
100
- */
101
- export function encodeBase64Check (input) {
102
- const buffer = Buffer.from(input)
103
- const checksum = checkSumFn(input)
104
- const payloadWithChecksum = Buffer.concat([buffer, checksum], buffer.length + 4)
105
- return payloadWithChecksum.toString('base64')
106
- }
107
-
108
- export function checkSumFn (payload) {
109
- return sha256hash(sha256hash(payload)).slice(0, 4)
110
- }
111
-
112
- function decodeRaw (buffer) {
113
- const payload = buffer.slice(0, -4)
114
- const checksum = buffer.slice(-4)
115
- const newChecksum = checkSumFn(payload)
116
-
117
- if (!checksum.equals(newChecksum)) return
118
-
119
- return payload
120
- }
121
-
122
- /**
123
- * Base64check decode given `str`
124
- * @rtype (str: String) => Buffer
125
- * @param {String} str - Data to decode
126
- * @return {Buffer} Base64check decoded data
127
- */
128
- export function decodeBase64Check (str) {
129
- const buffer = Buffer.from(str, 'base64')
130
- const payload = decodeRaw(buffer)
131
- if (!payload) throw new Error('Invalid checksum')
132
- return Buffer.from(payload)
133
- }
134
-
135
- /**
136
- * Base58 encode given `input`
137
- * @rtype (input: String) => String
138
- * @param {String|Buffer} input - Data to encode
139
- * @return {String} Base58 encoded data
140
- */
141
- export function encodeBase58Check (input) {
142
- return bs58check.encode(Buffer.from(input))
143
- }
144
-
145
- /**
146
- * Base58 decode given `str`
147
- * @rtype (str: String) => Buffer
148
- * @param {String} str - Data to decode
149
- * @return {Buffer} Base58 decoded data
150
- */
151
- export function decodeBase58Check (str) {
152
- return bs58check.decode(str)
153
- }
154
-
155
84
  /**
156
85
  * Converts a positive integer to the smallest possible
157
86
  * representation in a binary digit representation
@@ -176,7 +105,7 @@ export function encodeUnsigned (value) {
176
105
  export function encodeContractAddress (owner, nonce) {
177
106
  const publicKey = decode(owner, 'ak')
178
107
  const binary = Buffer.concat([publicKey, encodeUnsigned(nonce)])
179
- return `ct_${encodeBase58Check(hash(binary))}`
108
+ return encode(hash(binary), 'ct')
180
109
  }
181
110
 
182
111
  // KEY-PAIR HELPERS
@@ -193,7 +122,7 @@ export function generateKeyPairFromSecret (secret) {
193
122
 
194
123
  /**
195
124
  * Generate a random ED25519 keypair
196
- * @rtype (raw: Boolean) => {publicKey: String, secretKey: String} | {publicKey: Buffer, secretKey: Buffer}
125
+ * @rtype (raw: Boolean) => {publicKey: String | Buffer, secretKey: String | Buffer}
197
126
  * @param {Boolean} raw - Whether to return raw (binary) keys
198
127
  * @return {Object} Key pair
199
128
  */
@@ -211,7 +140,7 @@ export function generateKeyPair (raw = false) {
211
140
  }
212
141
  } else {
213
142
  return {
214
- publicKey: `ak_${encodeBase58Check(publicBuffer)}`,
143
+ publicKey: encode(publicBuffer, 'ak'),
215
144
  secretKey: secretBuffer.toString('hex')
216
145
  }
217
146
  }
@@ -272,7 +201,7 @@ export function verify (str, signature, publicKey) {
272
201
  export function messageToHash (message) {
273
202
  const p = Buffer.from('aeternity Signed Message:\n', 'utf8')
274
203
  const msg = Buffer.from(message, 'utf8')
275
- if (msg.length >= 0xFD) throw new Error('message too long')
204
+ if (msg.length >= 0xFD) throw new NotImplementedError('Message too long')
276
205
  return hash(Buffer.concat([Buffer.from([p.length]), p, Buffer.from([msg.length]), msg]))
277
206
  }
278
207
 
@@ -284,19 +213,6 @@ export function verifyMessage (str, signature, publicKey) {
284
213
  return verify(messageToHash(str), signature, publicKey)
285
214
  }
286
215
 
287
- /**
288
- * æternity readable public keys are the base58-encoded public key, prepended
289
- * with 'ak_'
290
- * @rtype (binaryKey: Buffer) => String
291
- * @param {Buffer} binaryKey - Key to encode
292
- * @return {String} Encoded key
293
- */
294
- export function aeEncodeKey (binaryKey) {
295
- const publicKeyBuffer = Buffer.from(binaryKey, 'hex')
296
- const pubKeyAddress = encodeBase58Check(publicKeyBuffer)
297
- return `ak_${pubKeyAddress}`
298
- }
299
-
300
216
  /**
301
217
  * Check key pair for validity
302
218
  *
@@ -311,53 +227,3 @@ export function isValidKeypair (privateKey, publicKey) {
311
227
  const signature = sign(message, privateKey)
312
228
  return verify(message, signature, publicKey)
313
229
  }
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
- }