@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.
- package/README.md +15 -14
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +7 -27
- 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.js → base.mjs} +20 -10
- package/es/account/base.mjs.map +1 -0
- package/es/account/{memory.js → memory.mjs} +29 -14
- package/es/account/memory.mjs.map +1 -0
- package/es/account/{multiple.js → multiple.mjs} +10 -9
- package/es/account/multiple.mjs.map +1 -0
- package/es/ae/{aens.js → aens.mjs} +18 -22
- 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.js → index.mjs} +8 -7
- package/es/ae/index.mjs.map +1 -0
- package/es/ae/{oracle.js → oracle.mjs} +33 -16
- 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} +20 -4
- package/es/chain/index.mjs.map +1 -0
- package/es/chain/{node.js → node.mjs} +121 -73
- package/es/chain/node.mjs.map +1 -0
- package/es/channel/{handlers.js → handlers.mjs} +18 -20
- package/es/channel/handlers.mjs.map +1 -0
- package/es/channel/{index.js → index.mjs} +7 -7
- package/es/channel/index.mjs.map +1 -0
- package/es/channel/{internal.js → internal.mjs} +49 -32
- 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.js → index.mjs} +36 -28
- 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.js → index.mjs} +11 -10
- package/es/node-pool/index.mjs.map +1 -0
- package/es/{node.js → node.mjs} +9 -8
- package/es/node.mjs.map +1 -0
- package/es/tx/builder/field-types.mjs +74 -0
- package/es/tx/builder/field-types.mjs.map +1 -0
- package/es/tx/builder/{helpers.js → helpers.mjs} +114 -56
- package/es/tx/builder/helpers.mjs.map +1 -0
- package/es/tx/builder/{index.js → index.mjs} +79 -68
- package/es/tx/builder/index.mjs.map +1 -0
- package/es/tx/builder/{schema.js → schema.mjs} +11 -65
- package/es/tx/builder/schema.mjs.map +1 -0
- package/es/tx/{index.js → index.mjs} +5 -2
- package/es/tx/index.mjs.map +1 -0
- package/es/tx/{tx-object.js → tx-object.mjs} +22 -15
- package/es/tx/tx-object.mjs.map +1 -0
- package/es/tx/{tx.js → tx.mjs} +15 -14
- package/es/tx/tx.mjs.map +1 -0
- package/es/tx/{validator.js → validator.mjs} +72 -33
- 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} +7 -6
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/connection/{browser-window-message.js → browser-window-message.mjs} +10 -11
- 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} +5 -2
- 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} +6 -5
- package/es/utils/aepp-wallet-communication/content-script-bridge.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/{helpers.js → helpers.mjs} +3 -14
- package/es/utils/aepp-wallet-communication/helpers.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{aepp-rpc.js → aepp-rpc.mjs} +113 -67
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{rpc-client.js → rpc-client.mjs} +14 -9
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.mjs.map +1 -0
- package/es/utils/aepp-wallet-communication/rpc/{wallet-rpc.js → wallet-rpc.mjs} +71 -63
- 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.js → wallet-detector.mjs} +6 -5
- package/es/utils/aepp-wallet-communication/wallet-detector.mjs.map +1 -0
- package/es/utils/{amount-formatter.js → amount-formatter.mjs} +14 -7
- package/es/utils/amount-formatter.mjs.map +1 -0
- package/es/utils/{async-init.js → async-init.mjs} +8 -11
- package/es/utils/async-init.mjs.map +1 -0
- package/es/utils/{bignumber.js → bignumber.mjs} +2 -9
- package/es/utils/bignumber.mjs.map +1 -0
- package/es/utils/{bytes.js → bytes.mjs} +16 -8
- 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.js → crypto.mjs} +40 -105
- 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.js → hd-wallet.mjs} +33 -34
- package/es/utils/hd-wallet.mjs.map +1 -0
- package/es/utils/{json-big.js → json-big.mjs} +1 -1
- package/es/utils/{json-big.js.map → json-big.mjs.map} +1 -1
- package/es/utils/{keystore.js → keystore.mjs} +63 -51
- package/es/utils/keystore.mjs.map +1 -0
- package/es/utils/{mptree.js → mptree.mjs} +21 -12
- package/es/utils/mptree.mjs.map +1 -0
- package/es/utils/{other.js → other.mjs} +2 -2
- package/es/utils/other.mjs.map +1 -0
- package/es/utils/{semver-satisfies.js → semver-satisfies.mjs} +1 -1
- package/es/utils/{semver-satisfies.js.map → semver-satisfies.mjs.map} +1 -1
- package/es/utils/{string.js → string.mjs} +1 -1
- package/es/utils/{string.js.map → string.mjs.map} +1 -1
- package/es/utils/{swagger.js → swagger.mjs} +46 -14
- package/es/utils/swagger.mjs.map +1 -0
- package/package.json +46 -55
- package/src/account/memory.js +13 -8
- package/src/account/multiple.js +12 -4
- package/src/ae/aens.js +12 -17
- package/src/ae/aepp.js +2 -2
- package/src/ae/contract.js +15 -152
- package/src/ae/index.js +2 -1
- package/src/ae/oracle.js +25 -10
- package/src/ae/universal.js +2 -2
- package/src/ae/wallet.js +2 -2
- package/src/chain/index.js +21 -2
- package/src/chain/node.js +80 -53
- package/src/channel/handlers.js +20 -17
- package/src/channel/internal.js +30 -24
- package/src/contract/{aci/index.js → aci.js} +152 -93
- package/src/contract/compiler.js +22 -117
- package/src/contract/ga/helpers.js +7 -5
- package/src/contract/ga/index.js +27 -24
- package/src/index.js +7 -8
- package/src/node-pool/index.js +9 -8
- package/src/node.js +5 -7
- package/src/tx/builder/field-types.js +61 -0
- package/src/tx/builder/helpers.js +113 -58
- package/src/tx/builder/index.js +39 -34
- package/src/tx/builder/schema.js +11 -25
- package/src/tx/tx-object.js +10 -9
- package/src/tx/tx.js +17 -8
- package/src/tx/validator.js +25 -5
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +8 -3
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +10 -6
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +5 -4
- package/src/utils/aepp-wallet-communication/helpers.js +2 -12
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +81 -55
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +15 -6
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +60 -49
- package/src/utils/aepp-wallet-communication/schema.ts +80 -0
- package/src/utils/aepp-wallet-communication/wallet-detector.js +3 -2
- package/src/utils/amount-formatter.ts +4 -3
- package/src/utils/async-init.js +10 -6
- package/src/utils/bignumber.ts +1 -9
- package/src/utils/bytes.ts +3 -2
- package/src/utils/crypto-ts.ts +2 -2
- package/src/utils/crypto.js +9 -92
- package/src/utils/errors.ts +683 -0
- package/src/utils/hd-wallet.js +11 -26
- package/src/utils/keystore.js +47 -51
- package/src/utils/mptree.ts +12 -6
- package/src/utils/swagger.js +67 -44
- package/CHANGELOG.md +0 -1603
- package/es/account/base.js.map +0 -1
- package/es/account/memory.js.map +0 -1
- package/es/account/multiple.js.map +0 -1
- package/es/ae/aens.js.map +0 -1
- package/es/ae/aepp.js.map +0 -1
- package/es/ae/contract.js +0 -312
- package/es/ae/contract.js.map +0 -1
- package/es/ae/index.js.map +0 -1
- 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.map +0 -1
- package/es/channel/handlers.js.map +0 -1
- package/es/channel/index.js.map +0 -1
- 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 -361
- package/es/contract/aci/index.js.map +0 -1
- package/es/contract/aci/transformation.js +0 -66
- package/es/contract/aci/transformation.js.map +0 -1
- package/es/contract/compiler.js +0 -244
- package/es/contract/compiler.js.map +0 -1
- package/es/contract/ga/helpers.js +0 -22
- package/es/contract/ga/helpers.js.map +0 -1
- package/es/contract/ga/index.js.map +0 -1
- package/es/contract/index.js +0 -162
- 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.map +0 -1
- package/es/node.js.map +0 -1
- package/es/tx/builder/helpers.js.map +0 -1
- package/es/tx/builder/index.js.map +0 -1
- package/es/tx/builder/schema.js.map +0 -1
- package/es/tx/index.js.map +0 -1
- package/es/tx/tx-object.js.map +0 -1
- package/es/tx/tx.js.map +0 -1
- 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.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.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +0 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +0 -1
- package/es/utils/aepp-wallet-communication/schema.js +0 -107
- package/es/utils/aepp-wallet-communication/schema.js.map +0 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +0 -1
- package/es/utils/amount-formatter.js.map +0 -1
- package/es/utils/async-init.js.map +0 -1
- 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.map +0 -1
- package/es/utils/hd-wallet.js.map +0 -1
- package/es/utils/keystore.js.map +0 -1
- package/es/utils/mptree.js.map +0 -1
- package/es/utils/other.js.map +0 -1
- package/es/utils/swagger.js.map +0 -1
- package/src/contract/aci/transformation.js +0 -72
- package/src/contract/index.js +0 -163
- package/src/utils/aepp-wallet-communication/schema.js +0 -108
|
@@ -10,6 +10,12 @@ import stampit from '@stamp/it'
|
|
|
10
10
|
|
|
11
11
|
import { METHODS, RPC_STATUS, SUBSCRIPTION_TYPES } from '../schema'
|
|
12
12
|
import { sendMessage, message, isValidAccounts } from '../helpers'
|
|
13
|
+
import {
|
|
14
|
+
InvalidRpcMessageError,
|
|
15
|
+
TypeError,
|
|
16
|
+
DuplicateCallbackError,
|
|
17
|
+
MissingCallbackError
|
|
18
|
+
} from '../../errors'
|
|
13
19
|
|
|
14
20
|
/**
|
|
15
21
|
* Contain functionality for using RPC conection
|
|
@@ -45,7 +51,7 @@ export default stampit({
|
|
|
45
51
|
|
|
46
52
|
const handleMessage = (msg, origin) => {
|
|
47
53
|
if (!msg || !msg.jsonrpc || msg.jsonrpc !== '2.0' || !msg.method) {
|
|
48
|
-
throw new
|
|
54
|
+
throw new InvalidRpcMessageError(msg)
|
|
49
55
|
}
|
|
50
56
|
onMessage(msg, origin)
|
|
51
57
|
}
|
|
@@ -123,7 +129,8 @@ export default stampit({
|
|
|
123
129
|
* @return {Boolean} is connected
|
|
124
130
|
*/
|
|
125
131
|
isConnected () {
|
|
126
|
-
return this.connection.isConnected() &&
|
|
132
|
+
return this.connection.isConnected() &&
|
|
133
|
+
(this.info.status === RPC_STATUS.CONNECTED || this.info.status === RPC_STATUS.NODE_BINDED)
|
|
127
134
|
},
|
|
128
135
|
/**
|
|
129
136
|
* Get selected account
|
|
@@ -157,12 +164,12 @@ export default stampit({
|
|
|
157
164
|
*/
|
|
158
165
|
setAccounts (accounts, { forceNotification } = {}) {
|
|
159
166
|
if (!isValidAccounts(accounts)) {
|
|
160
|
-
throw new
|
|
167
|
+
throw new TypeError('Invalid accounts object. Should be object like: `{ connected: {}, selected: {} }`')
|
|
161
168
|
}
|
|
162
169
|
this.accounts = accounts
|
|
163
170
|
if (!forceNotification) {
|
|
164
171
|
// Sent notification about account updates
|
|
165
|
-
this.sendMessage(message(METHODS.
|
|
172
|
+
this.sendMessage(message(METHODS.updateAddress, this.accounts), true)
|
|
166
173
|
}
|
|
167
174
|
},
|
|
168
175
|
/**
|
|
@@ -194,7 +201,9 @@ export default stampit({
|
|
|
194
201
|
*/
|
|
195
202
|
request (name, params) {
|
|
196
203
|
const msgId = this.sendMessage(message(name, params))
|
|
197
|
-
if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId))
|
|
204
|
+
if (Object.prototype.hasOwnProperty.call(this.callbacks, msgId)) {
|
|
205
|
+
throw new DuplicateCallbackError()
|
|
206
|
+
}
|
|
198
207
|
return new Promise((resolve, reject) => {
|
|
199
208
|
this.callbacks[msgId] = { resolve, reject }
|
|
200
209
|
})
|
|
@@ -209,7 +218,7 @@ export default stampit({
|
|
|
209
218
|
* @return {void}
|
|
210
219
|
*/
|
|
211
220
|
processResponse ({ id, error, result }, transformResult) {
|
|
212
|
-
if (!this.callbacks[id]) throw new
|
|
221
|
+
if (!this.callbacks[id]) throw new MissingCallbackError(id)
|
|
213
222
|
if (result) {
|
|
214
223
|
this.callbacks[id].resolve(...typeof transformResult === 'function'
|
|
215
224
|
? transformResult({ id, result })
|
|
@@ -6,14 +6,24 @@
|
|
|
6
6
|
* @example
|
|
7
7
|
* import WalletRpc from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/rpc/wallet-rpc'
|
|
8
8
|
*/
|
|
9
|
-
import { v4 as uuid } from 'uuid'
|
|
9
|
+
import { v4 as uuid } from '@aeternity/uuid'
|
|
10
10
|
import Ae from '../../../ae'
|
|
11
11
|
import verifyTransaction from '../../../tx/validator'
|
|
12
12
|
import AccountMultiple from '../../../account/multiple'
|
|
13
13
|
import TxObject from '../../../tx/tx-object'
|
|
14
14
|
import RpcClient from './rpc-client'
|
|
15
|
-
import { getBrowserAPI, getHandler, isValidAccounts, message,
|
|
15
|
+
import { getBrowserAPI, getHandler, isValidAccounts, message, sendResponseMessage } from '../helpers'
|
|
16
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
|
+
}
|
|
17
27
|
|
|
18
28
|
const NOTIFICATIONS = {
|
|
19
29
|
[METHODS.closeConnection]: (instance, { client }) =>
|
|
@@ -28,26 +38,36 @@ const RESPONSES = {}
|
|
|
28
38
|
const REQUESTS = {
|
|
29
39
|
// Store client info and prepare two fn for each client `connect` and `denyConnection`
|
|
30
40
|
// which automatically prepare and send response for that client
|
|
31
|
-
[METHODS.
|
|
41
|
+
[METHODS.connect] (
|
|
42
|
+
callInstance,
|
|
43
|
+
instance,
|
|
44
|
+
client,
|
|
45
|
+
{ name, networkId, version, icons, connectNode }) {
|
|
32
46
|
// Check if protocol and network is compatible with wallet
|
|
33
47
|
if (version !== VERSION) return { error: ERRORS.unsupportedProtocol() }
|
|
34
|
-
|
|
35
48
|
// Store new AEPP and wait for connection approve
|
|
36
49
|
client.updateInfo({
|
|
37
50
|
status: RPC_STATUS.WAITING_FOR_CONNECTION_APPROVE,
|
|
38
51
|
name,
|
|
39
52
|
networkId,
|
|
40
53
|
icons,
|
|
41
|
-
version
|
|
54
|
+
version,
|
|
55
|
+
origin: window.location.origin,
|
|
56
|
+
connectNode
|
|
42
57
|
})
|
|
43
58
|
|
|
44
59
|
// Call onConnection callBack to notice Wallet about new AEPP
|
|
45
60
|
return callInstance(
|
|
46
61
|
'onConnection',
|
|
47
62
|
{ name, networkId, version },
|
|
48
|
-
() => {
|
|
49
|
-
client.updateInfo({ status: RPC_STATUS.CONNECTED })
|
|
50
|
-
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
|
+
}
|
|
51
71
|
},
|
|
52
72
|
(error) => {
|
|
53
73
|
client.updateInfo({ status: RPC_STATUS.CONNECTION_REJECTED })
|
|
@@ -55,7 +75,7 @@ const REQUESTS = {
|
|
|
55
75
|
}
|
|
56
76
|
)
|
|
57
77
|
},
|
|
58
|
-
[METHODS.
|
|
78
|
+
[METHODS.subscribeAddress] (callInstance, instance, client, { type, value }) {
|
|
59
79
|
// Authorization check
|
|
60
80
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
61
81
|
|
|
@@ -65,7 +85,9 @@ const REQUESTS = {
|
|
|
65
85
|
async ({ accounts } = {}) => {
|
|
66
86
|
try {
|
|
67
87
|
const clientAccounts = accounts || instance.getAccounts()
|
|
68
|
-
if (!isValidAccounts(clientAccounts))
|
|
88
|
+
if (!isValidAccounts(clientAccounts)) {
|
|
89
|
+
throw new TypeError('Invalid provided accounts object')
|
|
90
|
+
}
|
|
69
91
|
const subscription = client.updateSubscription(type, value)
|
|
70
92
|
client.setAccounts(clientAccounts, { forceNotification: true })
|
|
71
93
|
return {
|
|
@@ -76,13 +98,13 @@ const REQUESTS = {
|
|
|
76
98
|
}
|
|
77
99
|
} catch (e) {
|
|
78
100
|
if (instance.debug) console.error(e)
|
|
79
|
-
return { error: ERRORS.internalError(
|
|
101
|
+
return { error: ERRORS.internalError(e.message) }
|
|
80
102
|
}
|
|
81
103
|
},
|
|
82
104
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
83
105
|
)
|
|
84
106
|
},
|
|
85
|
-
[METHODS.
|
|
107
|
+
[METHODS.address] (callInstance, instance, client) {
|
|
86
108
|
// Authorization check
|
|
87
109
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
88
110
|
if (!client.isSubscribed()) return { error: ERRORS.notAuthorize() }
|
|
@@ -97,7 +119,7 @@ const REQUESTS = {
|
|
|
97
119
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
98
120
|
)
|
|
99
121
|
},
|
|
100
|
-
[METHODS.
|
|
122
|
+
[METHODS.sign] (callInstance, instance, client, options) {
|
|
101
123
|
const { tx, onAccount, networkId, returnSigned = false } = options
|
|
102
124
|
const address = onAccount || client.currentAccount
|
|
103
125
|
// Update client with new networkId
|
|
@@ -106,7 +128,7 @@ const REQUESTS = {
|
|
|
106
128
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
107
129
|
// Account permission check
|
|
108
130
|
if (!client.hasAccessToAccount(address)) {
|
|
109
|
-
return { error: ERRORS.permissionDeny(
|
|
131
|
+
return { error: ERRORS.permissionDeny(address) }
|
|
110
132
|
}
|
|
111
133
|
// NetworkId check
|
|
112
134
|
if (!networkId || networkId !== instance.getNetworkId()) {
|
|
@@ -122,7 +144,7 @@ const REQUESTS = {
|
|
|
122
144
|
onAcc = resolveOnAccount(instance.addresses(), address, opt)
|
|
123
145
|
} catch (e) {
|
|
124
146
|
if (instance.debug) console.error(e)
|
|
125
|
-
return { error: ERRORS.internalError(
|
|
147
|
+
return { error: ERRORS.internalError(e.message) }
|
|
126
148
|
}
|
|
127
149
|
try {
|
|
128
150
|
const t = rawTx || tx
|
|
@@ -144,12 +166,12 @@ const REQUESTS = {
|
|
|
144
166
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
145
167
|
)
|
|
146
168
|
},
|
|
147
|
-
[METHODS.
|
|
169
|
+
[METHODS.signMessage] (callInstance, instance, client, { message, onAccount }) {
|
|
148
170
|
// Authorization check
|
|
149
171
|
if (!client.isConnected()) return { error: ERRORS.notAuthorize() }
|
|
150
172
|
const address = onAccount || client.currentAccount
|
|
151
173
|
if (!client.hasAccessToAccount(address)) {
|
|
152
|
-
return { error: ERRORS.permissionDeny(
|
|
174
|
+
return { error: ERRORS.permissionDeny(address) }
|
|
153
175
|
}
|
|
154
176
|
|
|
155
177
|
return callInstance(
|
|
@@ -168,7 +190,7 @@ const REQUESTS = {
|
|
|
168
190
|
}
|
|
169
191
|
} catch (e) {
|
|
170
192
|
if (instance.debug) console.error(e)
|
|
171
|
-
return { error: ERRORS.internalError(
|
|
193
|
+
return { error: ERRORS.internalError(e.message) }
|
|
172
194
|
}
|
|
173
195
|
},
|
|
174
196
|
(error) => ({ error: ERRORS.rejectedByUser(error) })
|
|
@@ -221,41 +243,26 @@ const handleMessage = (instance, id) => async (msg, origin) => {
|
|
|
221
243
|
* @param {Function} onSign Call-back function for incoming AEPP sign request
|
|
222
244
|
* @param {Function} onAskAccounts Call-back function for incoming AEPP get address request
|
|
223
245
|
* @param {Function} onMessageSign Call-back function for incoming AEPP sign message request
|
|
224
|
-
|
|
246
|
+
* Second argument of incoming call-backs contain function for accept/deny request
|
|
225
247
|
* @param {Function} onDisconnect Call-back function for disconnect event
|
|
226
248
|
* @return {Object}
|
|
227
249
|
*/
|
|
228
250
|
export default Ae.compose(AccountMultiple, {
|
|
229
251
|
init ({
|
|
230
252
|
name,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
onSign,
|
|
234
|
-
onDisconnect,
|
|
235
|
-
onAskAccounts,
|
|
236
|
-
onMessageSign,
|
|
237
|
-
forceValidation = false,
|
|
238
|
-
debug = false
|
|
253
|
+
debug = false,
|
|
254
|
+
...other
|
|
239
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
|
+
|
|
240
264
|
this.debug = debug
|
|
241
|
-
const eventsHandlers = [
|
|
242
|
-
'onConnection', 'onSubscription', 'onSign', 'onDisconnect', 'onMessageSign'
|
|
243
|
-
]
|
|
244
|
-
// CallBacks for events
|
|
245
|
-
this.onConnection = onConnection
|
|
246
|
-
this.onSubscription = onSubscription
|
|
247
|
-
this.onSign = onSign
|
|
248
|
-
this.onDisconnect = onDisconnect
|
|
249
|
-
this.onAskAccounts = onAskAccounts
|
|
250
|
-
this.onMessageSign = onMessageSign
|
|
251
265
|
this.rpcClients = {}
|
|
252
|
-
|
|
253
|
-
eventsHandlers.forEach(event => {
|
|
254
|
-
if (!forceValidation && typeof this[event] !== 'function') {
|
|
255
|
-
throw new Error(`Call-back for ${event} must be an function!`)
|
|
256
|
-
}
|
|
257
|
-
})
|
|
258
|
-
//
|
|
259
266
|
this.name = name
|
|
260
267
|
this.id = uuid()
|
|
261
268
|
|
|
@@ -298,9 +305,13 @@ export default Ae.compose(AccountMultiple, {
|
|
|
298
305
|
// Send notification 'update.network' to all Aepp which connected
|
|
299
306
|
Object.values(this.rpcClients)
|
|
300
307
|
.filter(client => client.isConnected())
|
|
301
|
-
.forEach(client =>
|
|
302
|
-
|
|
303
|
-
|
|
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
|
+
})
|
|
304
315
|
}
|
|
305
316
|
},
|
|
306
317
|
methods: {
|
|
@@ -315,7 +326,7 @@ export default Ae.compose(AccountMultiple, {
|
|
|
315
326
|
*/
|
|
316
327
|
removeRpcClient (id, { forceConnectionClose = false } = {}) {
|
|
317
328
|
const client = this.rpcClients[id]
|
|
318
|
-
if (!client) throw new
|
|
329
|
+
if (!client) throw new UnknownRpcClientError(id)
|
|
319
330
|
client.disconnect(forceConnectionClose)
|
|
320
331
|
delete this.rpcClients[id]
|
|
321
332
|
},
|
|
@@ -351,7 +362,7 @@ export default Ae.compose(AccountMultiple, {
|
|
|
351
362
|
shareWalletInfo (postFn) {
|
|
352
363
|
postFn({
|
|
353
364
|
jsonrpc: '2.0',
|
|
354
|
-
...message(METHODS.
|
|
365
|
+
...message(METHODS.readyToConnect, this.getWalletInfo())
|
|
355
366
|
})
|
|
356
367
|
},
|
|
357
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
|
},
|
|
@@ -54,7 +55,7 @@ export default stampit({
|
|
|
54
55
|
this.connection.connect(({ method, params }, origin, source) => {
|
|
55
56
|
if (
|
|
56
57
|
!method || !params ||
|
|
57
|
-
method !== METHODS.
|
|
58
|
+
method !== METHODS.readyToConnect || wallets[params.id]
|
|
58
59
|
) return
|
|
59
60
|
|
|
60
61
|
const wallet = {
|
|
@@ -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,18 +1,10 @@
|
|
|
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
|
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
|
}
|