@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.
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -36
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.mjs +179 -0
- package/es/account/base.mjs.map +1 -0
- package/es/account/memory.mjs +99 -0
- package/es/account/memory.mjs.map +1 -0
- package/es/account/multiple.mjs +179 -0
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/aens.mjs +404 -0
- package/es/ae/aens.mjs.map +1 -0
- package/es/ae/{aepp.js → aepp.mjs} +9 -9
- package/es/ae/aepp.mjs.map +1 -0
- package/es/ae/contract.mjs +159 -0
- package/es/ae/contract.mjs.map +1 -0
- package/es/ae/index.mjs +207 -0
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/oracle.mjs +339 -0
- package/es/ae/oracle.mjs.map +1 -0
- package/es/ae/{universal.js → universal.mjs} +10 -10
- package/es/ae/universal.mjs.map +1 -0
- package/es/ae/{wallet.js → wallet.mjs} +10 -10
- package/es/ae/wallet.mjs.map +1 -0
- package/es/aepp-wallet-communication/schema.d.ts +74 -0
- package/es/bignumber.d.ts +1 -7
- package/es/chain/{index.js → index.mjs} +29 -9
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/node.mjs +442 -0
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/handlers.mjs +1110 -0
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +245 -472
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/internal.mjs +283 -0
- package/es/channel/internal.mjs.map +1 -0
- package/es/contract/aci.mjs +477 -0
- package/es/contract/aci.mjs.map +1 -0
- package/es/contract/compiler.mjs +115 -0
- package/es/contract/compiler.mjs.map +1 -0
- package/es/contract/ga/helpers.mjs +30 -0
- package/es/contract/ga/helpers.mjs.map +1 -0
- package/es/contract/ga/index.mjs +178 -0
- package/es/contract/ga/index.mjs.map +1 -0
- package/es/errors.d.ts +284 -0
- package/es/index.mjs +57 -0
- package/es/index.mjs.map +1 -0
- package/es/node-pool/index.mjs +188 -0
- package/es/node-pool/index.mjs.map +1 -0
- package/es/node.mjs +133 -0
- package/es/node.mjs.map +1 -0
- package/es/other.d.ts +1 -1
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/helpers.mjs +363 -0
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/index.mjs +606 -0
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/schema.mjs +760 -0
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +107 -15
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/tx-object.mjs +283 -0
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/tx.mjs +938 -0
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/validator.mjs +247 -0
- package/es/tx/validator.mjs.map +1 -0
- package/es/typings/blakejs/index.d.mjs +2 -0
- package/es/typings/blakejs/{index.d.js.map → index.d.mjs.map} +1 -1
- package/es/utils/aepp-wallet-communication/connection/{browser-runtime.js → browser-runtime.mjs} +27 -29
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs +183 -0
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{index.js → index.mjs} +7 -3
- package/es/utils/aepp-wallet-communication/connection/index.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{content-script-bridge.js → content-script-bridge.mjs} +29 -23
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs +92 -0
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs +375 -0
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs +275 -0
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs +541 -0
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/schema.mjs +102 -0
- package/es/utils/aepp-wallet-communication/schema.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs +110 -0
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/amount-formatter.mjs +139 -0
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/async-init.mjs +64 -0
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/bignumber.mjs +21 -0
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -12
- package/es/utils/bytes.mjs.map +1 -0
- package/es/utils/{crypto-ts.js → crypto-ts.mjs} +11 -3
- package/es/utils/crypto-ts.mjs.map +1 -0
- package/es/utils/crypto.mjs +239 -0
- package/es/utils/crypto.mjs.map +1 -0
- package/es/utils/errors.mjs +689 -0
- package/es/utils/errors.mjs.map +1 -0
- package/es/utils/hd-wallet.mjs +111 -0
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/json-big.mjs +45 -0
- package/es/utils/json-big.mjs.map +1 -0
- package/es/utils/keystore.mjs +240 -0
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/mptree.mjs +161 -0
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/other.mjs +43 -0
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/semver-satisfies.mjs +16 -0
- package/es/utils/semver-satisfies.mjs.map +1 -0
- package/es/utils/{string.js → string.mjs} +5 -14
- package/es/utils/string.mjs.map +1 -0
- package/es/utils/swagger.mjs +164 -0
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +55 -62
- package/src/account/base.js +3 -1
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +31 -22
- package/src/ae/aens.js +75 -77
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +27 -291
- package/src/ae/index.js +9 -7
- package/src/ae/oracle.js +51 -28
- package/src/ae/universal.js +4 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +29 -6
- package/src/chain/node.js +95 -67
- package/src/channel/handlers.js +30 -21
- package/src/channel/index.js +44 -20
- package/src/channel/internal.js +30 -24
- package/src/contract/aci.js +376 -0
- package/src/contract/compiler.js +41 -91
- package/src/contract/ga/helpers.js +10 -13
- package/src/contract/ga/index.js +42 -33
- package/src/index.js +9 -10
- package/src/node-pool/index.js +29 -17
- package/src/node.js +33 -36
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +126 -84
- package/src/tx/builder/index.js +83 -41
- package/src/tx/builder/schema.js +50 -40
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +35 -15
- package/src/tx/tx.js +232 -153
- package/src/tx/validator.js +34 -12
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +11 -5
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +35 -13
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +14 -7
- package/src/utils/aepp-wallet-communication/helpers.js +6 -14
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +107 -60
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +24 -11
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +98 -56
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +6 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +3 -10
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +10 -144
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +57 -53
- package/src/utils/mptree.ts +12 -6
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +75 -45
- package/es/account/base.js +0 -259
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js +0 -86
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js +0 -267
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js +0 -829
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -985
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js +0 -442
- package/es/ae/index.js.map +0 -1
- package/es/ae/oracle.js +0 -690
- package/es/ae/oracle.js.map +0 -1
- package/es/ae/universal.js.map +0 -1
- package/es/ae/wallet.js.map +0 -1
- package/es/chain/index.js.map +0 -1
- package/es/chain/node.js +0 -1119
- package/es/chain/node.js.map +0 -1
- package/es/channel/handlers.js +0 -1601
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- package/es/channel/internal.js +0 -438
- package/es/channel/internal.js.map +0 -1
- package/es/contract/aci/helpers.js +0 -298
- package/es/contract/aci/helpers.js.map +0 -1
- package/es/contract/aci/index.js +0 -517
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -742
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -316
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -120
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js +0 -307
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -158
- package/es/contract/index.js.map +0 -1
- package/es/index.js +0 -57
- package/es/index.js.map +0 -1
- package/es/node-pool/index.js +0 -204
- package/es/node-pool/index.js.map +0 -1
- package/es/node.js +0 -228
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js +0 -355
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js +0 -686
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js +0 -695
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js +0 -297
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js +0 -1757
- package/es/tx/tx.js.map +0 -1
- package/es/tx/validator.js +0 -344
- package/es/tx/validator.js.map +0 -1
- package/es/typings/blakejs/index.d.js +0 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +0 -211
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +0 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +0 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +0 -1
- package/es/utils/aepp-wallet-communication/helpers.js +0 -148
- package/es/utils/aepp-wallet-communication/helpers.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +0 -652
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +0 -285
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +0 -763
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -103
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +0 -135
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js +0 -152
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js +0 -103
- package/es/utils/async-init.js.map +0 -1
- package/es/utils/bignumber.js +0 -36
- package/es/utils/bignumber.js.map +0 -1
- package/es/utils/bytes.js.map +0 -1
- package/es/utils/crypto-ts.js.map +0 -1
- package/es/utils/crypto.js +0 -358
- package/es/utils/crypto.js.map +0 -1
- package/es/utils/hd-wallet.js +0 -148
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/json-big.js +0 -78
- package/es/utils/json-big.js.map +0 -1
- package/es/utils/keystore.js +0 -393
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js +0 -198
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js +0 -93
- package/es/utils/other.js.map +0 -1
- package/es/utils/semver-satisfies.js +0 -35
- package/es/utils/semver-satisfies.js.map +0 -1
- package/es/utils/string.js.map +0 -1
- package/es/utils/swagger.js +0 -269
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/helpers.js +0 -140
- package/src/contract/aci/index.js +0 -191
- package/src/contract/aci/transformation.js +0 -464
- package/src/contract/index.js +0 -159
- package/src/utils/aepp-wallet-communication/schema.js +0 -110
|
@@ -3,12 +3,19 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/rpc-client
|
|
5
5
|
* @export { RpcClient, RpcClients }
|
|
6
|
-
* @example
|
|
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
|
|
|
10
11
|
import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES } from '../schema'
|
|
11
12
|
import { sendMessage, message, isValidAccounts } from '../helpers'
|
|
13
|
+
import {
|
|
14
|
+
InvalidRpcMessageError,
|
|
15
|
+
TypeError,
|
|
16
|
+
DuplicateCallbackError,
|
|
17
|
+
MissingCallbackError
|
|
18
|
+
} from '../../errors'
|
|
12
19
|
|
|
13
20
|
/**
|
|
14
21
|
* Contain functionality for using RPC conection
|
|
@@ -18,7 +25,9 @@ import { sendMessage, message, isValidAccounts } from '../helpers'
|
|
|
18
25
|
* @param {Object} param Init params object
|
|
19
26
|
* @param {String} param.name Client name
|
|
20
27
|
* @param {Object} param.connection Connection object
|
|
21
|
-
* @param {Function[]} param.handlers
|
|
28
|
+
* @param {Function[]} param.handlers Array with two function for message handling
|
|
29
|
+
* @param {Function} param.handlers[0] Message handler
|
|
30
|
+
* @param {Function} param.handlers[1] Disconnect callback
|
|
22
31
|
* @return {Object}
|
|
23
32
|
*/
|
|
24
33
|
export default stampit({
|
|
@@ -42,7 +51,7 @@ export default stampit({
|
|
|
42
51
|
|
|
43
52
|
const handleMessage = (msg, origin) => {
|
|
44
53
|
if (!msg || !msg.jsonrpc || msg.jsonrpc !== '2.0' || !msg.method) {
|
|
45
|
-
throw new
|
|
54
|
+
throw new InvalidRpcMessageError(msg)
|
|
46
55
|
}
|
|
47
56
|
onMessage(msg, origin)
|
|
48
57
|
}
|
|
@@ -120,7 +129,8 @@ export default stampit({
|
|
|
120
129
|
* @return {Boolean} is connected
|
|
121
130
|
*/
|
|
122
131
|
isConnected () {
|
|
123
|
-
return this.connection.isConnected() &&
|
|
132
|
+
return this.connection.isConnected() &&
|
|
133
|
+
(this.info.status === RPC_STATUS.CONNECTED || this.info.status === RPC_STATUS.NODE_BINDED)
|
|
124
134
|
},
|
|
125
135
|
/**
|
|
126
136
|
* Get selected account
|
|
@@ -148,17 +158,18 @@ export default stampit({
|
|
|
148
158
|
},
|
|
149
159
|
/**
|
|
150
160
|
* Update accounts and sent `update.address` notification to AEPP
|
|
151
|
-
* @param {{ current: Object, connected: Object }} accounts
|
|
152
|
-
* @param {
|
|
161
|
+
* @param {{ current: Object, connected: Object }} accounts Current and connected accounts
|
|
162
|
+
* @param {Object} [options]
|
|
163
|
+
* @param {Boolean} [options.forceNotification] Don't sent update notification to AEPP
|
|
153
164
|
*/
|
|
154
|
-
setAccounts (accounts, { forceNotification
|
|
165
|
+
setAccounts (accounts, { forceNotification } = {}) {
|
|
155
166
|
if (!isValidAccounts(accounts)) {
|
|
156
|
-
throw new
|
|
167
|
+
throw new TypeError('Invalid accounts object. Should be object like: `{ connected: {}, selected: {} }`')
|
|
157
168
|
}
|
|
158
169
|
this.accounts = accounts
|
|
159
170
|
if (!forceNotification) {
|
|
160
171
|
// Sent notification about account updates
|
|
161
|
-
this.sendMessage(message(METHODS.
|
|
172
|
+
this.sendMessage(message(METHODS.updateAddress, this.accounts), true)
|
|
162
173
|
}
|
|
163
174
|
},
|
|
164
175
|
/**
|
|
@@ -190,7 +201,9 @@ export default stampit({
|
|
|
190
201
|
*/
|
|
191
202
|
request (name, params) {
|
|
192
203
|
const msgId = this.sendMessage(message(name, params))
|
|
193
|
-
if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId))
|
|
204
|
+
if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId)) {
|
|
205
|
+
throw new DuplicateCallbackError()
|
|
206
|
+
}
|
|
194
207
|
return new Promise((resolve, reject) => {
|
|
195
208
|
this.callbacks[msgId] = { resolve, reject }
|
|
196
209
|
})
|
|
@@ -205,7 +218,7 @@ export default stampit({
|
|
|
205
218
|
* @return {void}
|
|
206
219
|
*/
|
|
207
220
|
processResponse ({ id, error, result }, transformResult) {
|
|
208
|
-
if (!this.callbacks[id]) throw new
|
|
221
|
+
if (!this.callbacks[id]) throw new MissingCallbackError(id)
|
|
209
222
|
if (result) {
|
|
210
223
|
this.callbacks[id].resolve(...typeof transformResult === 'function'
|
|
211
224
|
? transformResult({ id, result })
|
|
@@ -3,16 +3,27 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc
|
|
5
5
|
* @export WalletRpc
|
|
6
|
-
* @example
|
|
6
|
+
* @example
|
|
7
|
+
* import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
|
|
7
8
|
*/
|
|
8
|
-
import { v4 as uuid } from 'uuid'
|
|
9
|
+
import { v4 as uuid } from '@aeternity/uuid'
|
|
9
10
|
import Ae from '../../../ae'
|
|
10
11
|
import verifyTransaction from '../../../tx/validator'
|
|
11
12
|
import AccountMultiple from '../../../account/multiple'
|
|
12
13
|
import TxObject from '../../../tx/tx-object'
|
|
13
14
|
import RpcClient from './rpc-client'
|
|
14
|
-
import { getBrowserAPI, getHandler, isValidAccounts, message,
|
|
15
|
+
import { getBrowserAPI, getHandler, isValidAccounts, message, sendResponseMessage } from '../helpers'
|
|
15
16
|
import { ERRORS, METHODS, RPC_STATUS, VERSION, WALLET_TYPE } from '../schema'
|
|
17
|
+
import { ArgumentError, TypeError, UnknownRpcClientError } from '../../errors'
|
|
18
|
+
import { isAccountBase } from '../../../account/base'
|
|
19
|
+
|
|
20
|
+
const resolveOnAccount = (addresses, onAccount, opt = {}) => {
|
|
21
|
+
if (!addresses.find(a => a === onAccount)) {
|
|
22
|
+
if (typeof opt.onAccount !== 'object' || !isAccountBase(opt.onAccount)) throw new TypeError('Provided onAccount should be an AccountBase')
|
|
23
|
+
onAccount = opt.onAccount
|
|
24
|
+
}
|
|
25
|
+
return onAccount
|
|
26
|
+
}
|
|
16
27
|
|
|
17
28
|
const NOTIFICATIONS = {
|
|
18
29
|
[METHODS.closeConnection]: (instance, { client }) =>
|
|
@@ -27,26 +38,36 @@ const RESPONSES = {}
|
|
|
27
38
|
const REQUESTS = {
|
|
28
39
|
// Store client info and prepare two fn for each client `connect` and `denyConnection`
|
|
29
40
|
// which automatically prepare and send response for that client
|
|
30
|
-
[METHODS.
|
|
41
|
+
[METHODS.connect] (
|
|
42
|
+
callInstance,
|
|
43
|
+
instance,
|
|
44
|
+
client,
|
|
45
|
+
{ name, networkId, version, icons, connectNode }) {
|
|
31
46
|
// Check if protocol and network is compatible with wallet
|
|
32
47
|
if (version !== VERSION) return { error: ERRORS.unsupportedProtocol() }
|
|
33
|
-
|
|
34
48
|
// Store new AEPP and wait for connection approve
|
|
35
49
|
client.updateInfo({
|
|
36
50
|
status: RPC_STATUS.WAITING_FOR_CONNECTION_APPROVE,
|
|
37
51
|
name,
|
|
38
52
|
networkId,
|
|
39
53
|
icons,
|
|
40
|
-
version
|
|
54
|
+
version,
|
|
55
|
+
origin: window.location.origin,
|
|
56
|
+
connectNode
|
|
41
57
|
})
|
|
42
58
|
|
|
43
59
|
// Call onConnection callBack to notice Wallet about new AEPP
|
|
44
60
|
return callInstance(
|
|
45
61
|
'onConnection',
|
|
46
62
|
{ name, networkId, version },
|
|
47
|
-
() => {
|
|
48
|
-
client.updateInfo({ status: RPC_STATUS.CONNECTED })
|
|
49
|
-
return {
|
|
63
|
+
({ shareNode } = {}) => {
|
|
64
|
+
client.updateInfo({ status: shareNode ? RPC_STATUS.NODE_BINDED : RPC_STATUS.CONNECTED })
|
|
65
|
+
return {
|
|
66
|
+
result: {
|
|
67
|
+
...instance.getWalletInfo(),
|
|
68
|
+
...(shareNode && { node: instance.selectedNode })
|
|
69
|
+
}
|
|
70
|
+
}
|
|
50
71
|
},
|
|
51
72
|
(error) => {
|
|
52
73
|
client.updateInfo({ status: RPC_STATUS.CONNECTION_REJECTED })
|
|
@@ -54,7 +75,7 @@ const REQUESTS = {
|
|
|
54
75
|
}
|
|
55
76
|
)
|
|
56
77
|
},
|
|
57
|
-
[METHODS.
|
|
78
|
+
[METHODS.subscribeAddress] (callInstance, instance, client, { type, value }) {
|
|
58
79
|
// Authorization check
|
|
59
80
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
60
81
|
|
|
@@ -64,7 +85,9 @@ const REQUESTS = {
|
|
|
64
85
|
async ({ accounts } = {}) => {
|
|
65
86
|
try {
|
|
66
87
|
const clientAccounts = accounts || instance.getAccounts()
|
|
67
|
-
if (!isValidAccounts(clientAccounts))
|
|
88
|
+
if (!isValidAccounts(clientAccounts)) {
|
|
89
|
+
throw new TypeError('Invalid provided accounts object')
|
|
90
|
+
}
|
|
68
91
|
const subscription = client.updateSubscription(type, value)
|
|
69
92
|
client.setAccounts(clientAccounts, { forceNotification: true })
|
|
70
93
|
return {
|
|
@@ -74,14 +97,14 @@ const REQUESTS = {
|
|
|
74
97
|
}
|
|
75
98
|
}
|
|
76
99
|
} catch (e) {
|
|
77
|
-
console.error(e)
|
|
78
|
-
return { error: ERRORS.internalError(
|
|
100
|
+
if (instance.debug) console.error(e)
|
|
101
|
+
return { error: ERRORS.internalError(e.message) }
|
|
79
102
|
}
|
|
80
103
|
},
|
|
81
104
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
82
105
|
)
|
|
83
106
|
},
|
|
84
|
-
[METHODS.
|
|
107
|
+
[METHODS.address] (callInstance, instance, client) {
|
|
85
108
|
// Authorization check
|
|
86
109
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
87
110
|
if (!client.isSubscribed()) return { error: ERRORS.notAuthorize() }
|
|
@@ -89,20 +112,28 @@ const REQUESTS = {
|
|
|
89
112
|
return callInstance(
|
|
90
113
|
'onAskAccounts',
|
|
91
114
|
{},
|
|
92
|
-
({ accounts } = {}) => ({
|
|
115
|
+
({ accounts } = {}) => ({
|
|
116
|
+
result: accounts ||
|
|
117
|
+
[...Object.keys(client.accounts.current), ...Object.keys(client.accounts.connected)]
|
|
118
|
+
}),
|
|
93
119
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
94
120
|
)
|
|
95
121
|
},
|
|
96
|
-
[METHODS.
|
|
122
|
+
[METHODS.sign] (callInstance, instance, client, options) {
|
|
123
|
+
const { tx, onAccount, networkId, returnSigned = false } = options
|
|
97
124
|
const address = onAccount || client.currentAccount
|
|
98
125
|
// Update client with new networkId
|
|
99
126
|
networkId && client.updateInfo({ networkId })
|
|
100
127
|
// Authorization check
|
|
101
128
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
102
129
|
// Account permission check
|
|
103
|
-
if (!client.hasAccessToAccount(address))
|
|
130
|
+
if (!client.hasAccessToAccount(address)) {
|
|
131
|
+
return { error: ERRORS.permissionDeny(address) }
|
|
132
|
+
}
|
|
104
133
|
// NetworkId check
|
|
105
|
-
if (!networkId || networkId !== instance.getNetworkId())
|
|
134
|
+
if (!networkId || networkId !== instance.getNetworkId()) {
|
|
135
|
+
return { error: ERRORS.unsupportedNetwork() }
|
|
136
|
+
}
|
|
106
137
|
|
|
107
138
|
return callInstance(
|
|
108
139
|
'onSign',
|
|
@@ -112,15 +143,15 @@ const REQUESTS = {
|
|
|
112
143
|
try {
|
|
113
144
|
onAcc = resolveOnAccount(instance.addresses(), address, opt)
|
|
114
145
|
} catch (e) {
|
|
115
|
-
console.error(e)
|
|
116
|
-
return { error: ERRORS.internalError(
|
|
146
|
+
if (instance.debug) console.error(e)
|
|
147
|
+
return { error: ERRORS.internalError(e.message) }
|
|
117
148
|
}
|
|
118
149
|
try {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
150
|
+
const t = rawTx || tx
|
|
151
|
+
const result = returnSigned
|
|
152
|
+
? { signedTransaction: await instance.signTransaction(t, { onAccount: onAcc }) }
|
|
153
|
+
: { transactionHash: await instance.send(t, { onAccount: onAcc, verify: false }) }
|
|
154
|
+
return { result }
|
|
124
155
|
} catch (e) {
|
|
125
156
|
if (!returnSigned) {
|
|
126
157
|
// Validate transaction
|
|
@@ -135,11 +166,13 @@ const REQUESTS = {
|
|
|
135
166
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
136
167
|
)
|
|
137
168
|
},
|
|
138
|
-
[METHODS.
|
|
169
|
+
[METHODS.signMessage] (callInstance, instance, client, { message, onAccount }) {
|
|
139
170
|
// Authorization check
|
|
140
171
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
141
172
|
const address = onAccount || client.currentAccount
|
|
142
|
-
if (!client.hasAccessToAccount(address))
|
|
173
|
+
if (!client.hasAccessToAccount(address)) {
|
|
174
|
+
return { error: ERRORS.permissionDeny(address) }
|
|
175
|
+
}
|
|
143
176
|
|
|
144
177
|
return callInstance(
|
|
145
178
|
'onMessageSign',
|
|
@@ -156,8 +189,8 @@ const REQUESTS = {
|
|
|
156
189
|
}
|
|
157
190
|
}
|
|
158
191
|
} catch (e) {
|
|
159
|
-
console.error(e)
|
|
160
|
-
return { error: ERRORS.internalError(
|
|
192
|
+
if (instance.debug) console.error(e)
|
|
193
|
+
return { error: ERRORS.internalError(e.message) }
|
|
161
194
|
}
|
|
162
195
|
},
|
|
163
196
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
@@ -168,7 +201,9 @@ const REQUESTS = {
|
|
|
168
201
|
const handleMessage = (instance, id) => async (msg, origin) => {
|
|
169
202
|
const client = instance.rpcClients[id]
|
|
170
203
|
if (!msg.id) {
|
|
171
|
-
return getHandler(
|
|
204
|
+
return getHandler(
|
|
205
|
+
NOTIFICATIONS, msg, { debug: instance.debug }
|
|
206
|
+
)(instance, { client })(msg, origin)
|
|
172
207
|
}
|
|
173
208
|
if (Object.prototype.hasOwnProperty.call(client.callbacks, msg.id)) {
|
|
174
209
|
return getHandler(RESPONSES, msg, { debug: instance.debug })(instance, { client })(msg, origin)
|
|
@@ -188,7 +223,9 @@ const handleMessage = (instance, id) => async (msg, origin) => {
|
|
|
188
223
|
)
|
|
189
224
|
})
|
|
190
225
|
// TODO make one structure for handler functions
|
|
191
|
-
const errorObjectOrHandler = getHandler(REQUESTS, msg, { debug: instance.debug })(
|
|
226
|
+
const errorObjectOrHandler = getHandler(REQUESTS, msg, { debug: instance.debug })(
|
|
227
|
+
callInstance, instance, client, msg.params
|
|
228
|
+
)
|
|
192
229
|
const response = typeof errorObjectOrHandler === 'function' ? await errorObjectOrHandler() : errorObjectOrHandler
|
|
193
230
|
sendResponseMessage(client)(id, method, response)
|
|
194
231
|
}
|
|
@@ -201,31 +238,31 @@ const handleMessage = (instance, id) => async (msg, origin) => {
|
|
|
201
238
|
* @rtype Stamp
|
|
202
239
|
* @param {Object} param Init params object
|
|
203
240
|
* @param {String=} [param.name] Wallet name
|
|
204
|
-
* @param {Function} onConnection Call-back function for incoming AEPP connection
|
|
205
|
-
* @param {Function} onSubscription Call-back function for incoming AEPP account subscription
|
|
206
|
-
* @param {Function} onSign Call-back function for incoming AEPP sign request
|
|
207
|
-
* @param {Function} onAskAccounts Call-back function for incoming AEPP get address request
|
|
208
|
-
* @param {Function} onMessageSign Call-back function for incoming AEPP sign message request
|
|
241
|
+
* @param {Function} onConnection Call-back function for incoming AEPP connection
|
|
242
|
+
* @param {Function} onSubscription Call-back function for incoming AEPP account subscription
|
|
243
|
+
* @param {Function} onSign Call-back function for incoming AEPP sign request
|
|
244
|
+
* @param {Function} onAskAccounts Call-back function for incoming AEPP get address request
|
|
245
|
+
* @param {Function} onMessageSign Call-back function for incoming AEPP sign message request
|
|
246
|
+
* Second argument of incoming call-backs contain function for accept/deny request
|
|
209
247
|
* @param {Function} onDisconnect Call-back function for disconnect event
|
|
210
248
|
* @return {Object}
|
|
211
249
|
*/
|
|
212
250
|
export default Ae.compose(AccountMultiple, {
|
|
213
|
-
init ({
|
|
251
|
+
init ({
|
|
252
|
+
name,
|
|
253
|
+
debug = false,
|
|
254
|
+
...other
|
|
255
|
+
} = {}) {
|
|
256
|
+
[
|
|
257
|
+
'onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onAskAccounts', 'onMessageSign'
|
|
258
|
+
].forEach(event => {
|
|
259
|
+
const handler = other[event]
|
|
260
|
+
if (typeof handler !== 'function') throw new ArgumentError(event, 'a function', handler)
|
|
261
|
+
this[event] = handler
|
|
262
|
+
})
|
|
263
|
+
|
|
214
264
|
this.debug = debug
|
|
215
|
-
const eventsHandlers = ['onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign']
|
|
216
|
-
// CallBacks for events
|
|
217
|
-
this.onConnection = onConnection
|
|
218
|
-
this.onSubscription = onSubscription
|
|
219
|
-
this.onSign = onSign
|
|
220
|
-
this.onDisconnect = onDisconnect
|
|
221
|
-
this.onAskAccounts = onAskAccounts
|
|
222
|
-
this.onMessageSign = onMessageSign
|
|
223
265
|
this.rpcClients = {}
|
|
224
|
-
|
|
225
|
-
eventsHandlers.forEach(event => {
|
|
226
|
-
if (!forceValidation && typeof this[event] !== 'function') throw new Error(`Call-back for ${event} must be an function!`)
|
|
227
|
-
})
|
|
228
|
-
//
|
|
229
266
|
this.name = name
|
|
230
267
|
this.id = uuid()
|
|
231
268
|
|
|
@@ -268,9 +305,13 @@ export default Ae.compose(AccountMultiple, {
|
|
|
268
305
|
// Send notification 'update.network' to all Aepp which connected
|
|
269
306
|
Object.values(this.rpcClients)
|
|
270
307
|
.filter(client => client.isConnected())
|
|
271
|
-
.forEach(client =>
|
|
272
|
-
|
|
273
|
-
|
|
308
|
+
.forEach(client => {
|
|
309
|
+
client.sendMessage(
|
|
310
|
+
message(METHODS.updateNetwork, {
|
|
311
|
+
networkId: this.getNetworkId(),
|
|
312
|
+
...(client.info.status === RPC_STATUS.NODE_BINDED && { node: this.selectedNode })
|
|
313
|
+
}), true)
|
|
314
|
+
})
|
|
274
315
|
}
|
|
275
316
|
},
|
|
276
317
|
methods: {
|
|
@@ -285,7 +326,7 @@ export default Ae.compose(AccountMultiple, {
|
|
|
285
326
|
*/
|
|
286
327
|
removeRpcClient (id, { forceConnectionClose = false } = {}) {
|
|
287
328
|
const client = this.rpcClients[id]
|
|
288
|
-
if (!client) throw new
|
|
329
|
+
if (!client) throw new UnknownRpcClientError(id)
|
|
289
330
|
client.disconnect(forceConnectionClose)
|
|
290
331
|
delete this.rpcClients[id]
|
|
291
332
|
},
|
|
@@ -298,7 +339,8 @@ export default Ae.compose(AccountMultiple, {
|
|
|
298
339
|
* @return {String} Client ID
|
|
299
340
|
*/
|
|
300
341
|
addRpcClient (clientConnection) {
|
|
301
|
-
// @TODO detect if aepp has some history based on origin
|
|
342
|
+
// @TODO detect if aepp has some history based on origin????
|
|
343
|
+
// if yes use this instance for connection
|
|
302
344
|
const id = uuid()
|
|
303
345
|
this.rpcClients[id] = RpcClient({
|
|
304
346
|
id,
|
|
@@ -320,7 +362,7 @@ export default Ae.compose(AccountMultiple, {
|
|
|
320
362
|
shareWalletInfo (postFn) {
|
|
321
363
|
postFn({
|
|
322
364
|
jsonrpc: '2.0',
|
|
323
|
-
...message(METHODS.
|
|
365
|
+
...message(METHODS.readyToConnect, this.getWalletInfo())
|
|
324
366
|
})
|
|
325
367
|
},
|
|
326
368
|
/**
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export const VERSION = 1
|
|
2
|
+
|
|
3
|
+
export const enum MESSAGE_DIRECTION {
|
|
4
|
+
to_waellet = 'to_waellet',
|
|
5
|
+
to_aepp = 'to_aepp'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const enum WALLET_TYPE {
|
|
9
|
+
window = 'window',
|
|
10
|
+
extension = 'extension'
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const enum SUBSCRIPTION_TYPES {
|
|
14
|
+
subscribe = 'subscribe',
|
|
15
|
+
unsubscribe = 'unsubscribe'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const enum METHODS {
|
|
19
|
+
readyToConnect = 'connection.announcePresence',
|
|
20
|
+
updateAddress = 'address.update',
|
|
21
|
+
address = 'address.get',
|
|
22
|
+
connect = 'connection.open',
|
|
23
|
+
sign = 'transaction.sign',
|
|
24
|
+
signMessage = 'message.sign',
|
|
25
|
+
subscribeAddress = 'address.subscribe',
|
|
26
|
+
updateNetwork = 'networkId.update',
|
|
27
|
+
closeConnection = 'connection.close'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export const enum RPC_STATUS {
|
|
31
|
+
CONNECTED = 'CONNECTED',
|
|
32
|
+
NODE_BINDED = 'NODE_BINDED',
|
|
33
|
+
DISCONNECTED = 'DISCONNECTED',
|
|
34
|
+
CONNECTION_REJECTED = 'CONNECTION_REJECTED',
|
|
35
|
+
WAITING_FOR_CONNECTION_APPROVE = 'WAITING_FOR_CONNECTION_APPROVE',
|
|
36
|
+
WAITING_FOR_CONNECTION_REQUEST = 'WAITING_FOR_CONNECTION_REQUEST'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const ERRORS = {
|
|
40
|
+
broadcastFailed: (error = {}) => ({
|
|
41
|
+
code: 3,
|
|
42
|
+
data: error,
|
|
43
|
+
message: 'Broadcast failed'
|
|
44
|
+
}),
|
|
45
|
+
invalidTransaction: (error = {}) => ({
|
|
46
|
+
code: 2,
|
|
47
|
+
data: error,
|
|
48
|
+
message: 'Invalid transaction'
|
|
49
|
+
}),
|
|
50
|
+
rejectedByUser: (error = {}) => ({
|
|
51
|
+
code: 4,
|
|
52
|
+
data: error,
|
|
53
|
+
message: 'Operation rejected by user'
|
|
54
|
+
}),
|
|
55
|
+
connectionDeny: (error = {}) => ({
|
|
56
|
+
code: 9,
|
|
57
|
+
data: error,
|
|
58
|
+
message: 'Wallet deny your connection request'
|
|
59
|
+
}),
|
|
60
|
+
permissionDeny: (address: string) => ({
|
|
61
|
+
code: 11,
|
|
62
|
+
message: `You are not subscribed for account ${address}`
|
|
63
|
+
}),
|
|
64
|
+
internalError: (message: string) => ({
|
|
65
|
+
code: 12,
|
|
66
|
+
message
|
|
67
|
+
}),
|
|
68
|
+
notAuthorize: () => ({
|
|
69
|
+
code: 10,
|
|
70
|
+
message: 'You are not connected to the wallet'
|
|
71
|
+
}),
|
|
72
|
+
unsupportedProtocol: () => ({
|
|
73
|
+
code: 5,
|
|
74
|
+
message: 'Unsupported Protocol Version'
|
|
75
|
+
}),
|
|
76
|
+
unsupportedNetwork: () => ({
|
|
77
|
+
code: 8,
|
|
78
|
+
message: 'Unsupported Network'
|
|
79
|
+
})
|
|
80
|
+
}
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
import stampit from '@stamp/it'
|
|
26
26
|
import BrowserWindowMessageConnection from './connection/browser-window-message'
|
|
27
27
|
import { MESSAGE_DIRECTION, METHODS } from './schema'
|
|
28
|
+
import { UnsupportedPlatformError } from '../errors'
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* WalletDetector stamp
|
|
@@ -37,7 +38,7 @@ import { MESSAGE_DIRECTION, METHODS } from './schema'
|
|
|
37
38
|
*/
|
|
38
39
|
export default stampit({
|
|
39
40
|
init ({ connection } = {}) {
|
|
40
|
-
if (!window) throw new
|
|
41
|
+
if (!window) throw new UnsupportedPlatformError('Window object not found, you can run wallet detector only in browser')
|
|
41
42
|
this.connection = connection || BrowserWindowMessageConnection({ connectionInfo: { id: 'spy' } })
|
|
42
43
|
this.wallets = {}
|
|
43
44
|
},
|
|
@@ -52,7 +53,10 @@ export default stampit({
|
|
|
52
53
|
scan (onDetected) {
|
|
53
54
|
const { wallets } = this
|
|
54
55
|
this.connection.connect(({ method, params }, origin, source) => {
|
|
55
|
-
if (
|
|
56
|
+
if (
|
|
57
|
+
!method || !params ||
|
|
58
|
+
method !== METHODS.readyToConnect || wallets[params.id]
|
|
59
|
+
) return
|
|
56
60
|
|
|
57
61
|
const wallet = {
|
|
58
62
|
...params,
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
import BigNumber from 'bignumber.js'
|
|
24
24
|
import { isBigNumber } from './bignumber'
|
|
25
|
+
import { ArgumentError, InvalidDenominationError } from './errors'
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* AE amount formats
|
|
@@ -86,9 +87,9 @@ export const formatAmount = (
|
|
|
86
87
|
{ denomination = AE_AMOUNT_FORMATS.AETTOS, targetDenomination = AE_AMOUNT_FORMATS.AETTOS } = {}
|
|
87
88
|
): string => {
|
|
88
89
|
const denominations = Object.values(AE_AMOUNT_FORMATS)
|
|
89
|
-
if (!denominations.includes(denomination)) throw new
|
|
90
|
-
if (!denominations.includes(targetDenomination)) throw new
|
|
91
|
-
if (!isBigNumber(value)) throw new
|
|
90
|
+
if (!denominations.includes(denomination)) throw new InvalidDenominationError(`Invalid denomination: ${denomination}`)
|
|
91
|
+
if (!denominations.includes(targetDenomination)) throw new InvalidDenominationError(`Invalid target denomination: ${targetDenomination}`)
|
|
92
|
+
if (!isBigNumber(value)) throw new ArgumentError('value', `a number`, value)
|
|
92
93
|
|
|
93
94
|
return new BigNumber(value)
|
|
94
95
|
.shiftedBy(DENOMINATION_MAGNITUDE[denomination] - DENOMINATION_MAGNITUDE[targetDenomination])
|
package/src/utils/async-init.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* ISC License (ISC)
|
|
3
|
-
* Copyright (c)
|
|
3
|
+
* Copyright (c) 2022 aeternity developers
|
|
4
4
|
*
|
|
5
5
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
6
|
* purpose with or without fee is hereby granted, provided that the above
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
import stampit from '@stamp/it'
|
|
19
|
-
import * as R from 'ramda'
|
|
20
19
|
|
|
21
20
|
function asyncInit (options = {}, { stamp, args, instance }) {
|
|
22
21
|
return stamp.compose.deepConfiguration.AsyncInit.initializers.reduce(async (instance, init) => {
|
|
@@ -29,13 +28,18 @@ function asyncInit (options = {}, { stamp, args, instance }) {
|
|
|
29
28
|
}, instance)
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
|
|
31
|
+
export default stampit({
|
|
33
32
|
deepConf: { AsyncInit: { initializers: [] } },
|
|
34
33
|
composers ({ stamp, composables }) {
|
|
35
34
|
const conf = stamp.compose.deepConfiguration.AsyncInit
|
|
36
|
-
conf.initializers =
|
|
35
|
+
conf.initializers = composables
|
|
36
|
+
.map(c =>
|
|
37
|
+
c?.compose?.deepConfiguration?.AsyncInit?.initializers ||
|
|
38
|
+
(c.compose || c).initializers ||
|
|
39
|
+
[])
|
|
40
|
+
.flat(Infinity)
|
|
41
|
+
.filter((f, idx, arr) => !arr.slice(0, idx).includes(f))
|
|
42
|
+
.filter(f => f !== asyncInit)
|
|
37
43
|
stamp.compose.initializers = [asyncInit]
|
|
38
44
|
}
|
|
39
45
|
})
|
|
40
|
-
|
|
41
|
-
export default AsyncInit
|
package/src/utils/bignumber.ts
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Big Number Helpers
|
|
3
3
|
* @module @aeternity/aepp-sdk/es/utils/bignumber
|
|
4
|
-
* @example import {
|
|
4
|
+
* @example import { isBigNumber, ceil } from '@aeternity/aepp-sdk/es/utils/bignumber'
|
|
5
5
|
*/
|
|
6
6
|
import BigNumber from 'bignumber.js'
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Convert number to string
|
|
10
|
-
* @param {String|Number|BigNumber} number number to convert
|
|
11
|
-
* @return {String}
|
|
12
|
-
*/
|
|
13
|
-
export const parseBigNumber = (number: string | number | BigNumber): string =>
|
|
14
|
-
new BigNumber(number.toString()).toString(10)
|
|
15
|
-
|
|
16
8
|
/**
|
|
17
9
|
* Check if value is BigNumber, Number or number string representation
|
|
18
10
|
* @param {String|Number|BigNumber} number number to convert
|
|
19
11
|
* @return {Boolean}
|
|
20
12
|
*/
|
|
21
13
|
export const isBigNumber = (number: string | number | BigNumber): boolean =>
|
|
22
|
-
|
|
14
|
+
['number', 'object', 'string', 'bigint'].includes(typeof number) &&
|
|
15
|
+
(!isNaN(number as number) || Number.isInteger(number) || BigNumber.isBigNumber(number))
|
|
23
16
|
|
|
24
17
|
/**
|
|
25
18
|
* BigNumber ceil operation
|
package/src/utils/bytes.ts
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
import BigNumber from 'bignumber.js'
|
|
18
|
+
import { NoSerializerFoundError, TypeError } from './errors'
|
|
18
19
|
import { isBase64, isHex } from './string'
|
|
19
20
|
|
|
20
21
|
/**
|
|
@@ -29,7 +30,7 @@ import { isBase64, isHex } from './string'
|
|
|
29
30
|
* @return Buffer
|
|
30
31
|
*/
|
|
31
32
|
export function bigNumberToByteArray (x: BigNumber): Buffer {
|
|
32
|
-
if (!x.isInteger()) throw new
|
|
33
|
+
if (!x.isInteger()) throw new TypeError(`Unexpected not integer value: ${x.toFixed()}`)
|
|
33
34
|
let hexString = x.toString(16)
|
|
34
35
|
if (hexString.length % 2 === 1) hexString = '0' + hexString
|
|
35
36
|
return Buffer.from(hexString, 'hex')
|
|
@@ -54,7 +55,7 @@ export function toBytes (val?: null | string | number | BigNumber, big: boolean
|
|
|
54
55
|
if (typeof val === 'string') {
|
|
55
56
|
return Buffer.from(val)
|
|
56
57
|
}
|
|
57
|
-
throw new
|
|
58
|
+
throw new NoSerializerFoundError()
|
|
58
59
|
}
|
|
59
60
|
|
|
60
61
|
/**
|
package/src/utils/crypto-ts.ts
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { blake2b } from 'blakejs'
|
|
18
|
+
import { blake2b } from '@aeternity/blakejs'
|
|
19
19
|
import type { Data } from 'blakejs'
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -25,5 +25,5 @@ import type { Data } from 'blakejs'
|
|
|
25
25
|
* @return {Buffer} Hash
|
|
26
26
|
*/
|
|
27
27
|
export function hash (input: Data): Buffer {
|
|
28
|
-
return Buffer.from(blake2b(input,
|
|
28
|
+
return Buffer.from(blake2b(input, undefined, 32)) // 256 bits
|
|
29
29
|
}
|