@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
package/es/account/base.js
DELETED
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
3
|
-
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
|
4
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* ISC License (ISC)
|
|
8
|
-
* Copyright (c) 2018 aeternity developers
|
|
9
|
-
*
|
|
10
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
12
|
-
* copyright notice and this permission notice appear in all copies.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
15
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
18
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
19
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* AccountBase module
|
|
25
|
-
* @module @aeternity/aepp-sdk/es/account/base
|
|
26
|
-
* @export AccountBase
|
|
27
|
-
* @export isAccountBase
|
|
28
|
-
*/
|
|
29
|
-
import stampit from '@stamp/it';
|
|
30
|
-
import { required } from '@stamp/required';
|
|
31
|
-
import { messageToHash, verifyMessage as verifyMessageCrypto, hash } from '../utils/crypto';
|
|
32
|
-
import { buildTx } from '../tx/builder';
|
|
33
|
-
import { decode } from '../tx/builder/helpers';
|
|
34
|
-
import { TX_TYPE } from '../tx/builder/schema';
|
|
35
|
-
import { getNetworkId } from '../node';
|
|
36
|
-
/**
|
|
37
|
-
* Check is provided object looks like an instance of AccountBase
|
|
38
|
-
* @rtype (Object) => Boolean
|
|
39
|
-
* @param {Object} acc - Object to check
|
|
40
|
-
* @return {Boolean}
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
export var isAccountBase = function isAccountBase(acc) {
|
|
44
|
-
var _context;
|
|
45
|
-
|
|
46
|
-
return !_findInstanceProperty(_context = ['sign', 'address']).call(_context, function (f) {
|
|
47
|
-
return typeof acc[f] !== 'function';
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
/**
|
|
51
|
-
* Sign encoded transaction
|
|
52
|
-
* @instance
|
|
53
|
-
* @category async
|
|
54
|
-
* @rtype (tx: String) => tx: Promise[String], throws: Error
|
|
55
|
-
* @param {String} tx - Transaction to sign
|
|
56
|
-
* @param {Object} opt - Options
|
|
57
|
-
* @param {Object} [opt.innerTx] - Sign as inner transaction for PayingFor
|
|
58
|
-
* @return {String} Signed transaction
|
|
59
|
-
*/
|
|
60
|
-
|
|
61
|
-
function signTransaction(_x) {
|
|
62
|
-
return _signTransaction.apply(this, arguments);
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get network Id
|
|
66
|
-
* @instance
|
|
67
|
-
* @function getNetworkId
|
|
68
|
-
* @category async
|
|
69
|
-
* @rtype () => networkId: String
|
|
70
|
-
* @return {String} Network Id
|
|
71
|
-
*/
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Sign message
|
|
75
|
-
* @instance
|
|
76
|
-
* @category async
|
|
77
|
-
* @rtype (msg: String) => signature: Promise[String], throws: Error
|
|
78
|
-
* @param {String} message - Message to sign
|
|
79
|
-
* @param {Object} opt - Options
|
|
80
|
-
* @return {String} Signature
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
function _signTransaction() {
|
|
85
|
-
_signTransaction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(tx) {
|
|
86
|
-
var opt,
|
|
87
|
-
prefixes,
|
|
88
|
-
rlpBinaryTx,
|
|
89
|
-
txWithNetworkId,
|
|
90
|
-
signatures,
|
|
91
|
-
_args = arguments;
|
|
92
|
-
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
93
|
-
while (1) {
|
|
94
|
-
switch (_context2.prev = _context2.next) {
|
|
95
|
-
case 0:
|
|
96
|
-
opt = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
|
|
97
|
-
prefixes = [this.getNetworkId(opt)];
|
|
98
|
-
if (opt.innerTx) prefixes.push('inner_tx');
|
|
99
|
-
rlpBinaryTx = decode(tx, 'tx');
|
|
100
|
-
txWithNetworkId = _concatInstanceProperty(Buffer).call(Buffer, [Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);
|
|
101
|
-
_context2.next = 7;
|
|
102
|
-
return this.sign(txWithNetworkId, opt);
|
|
103
|
-
|
|
104
|
-
case 7:
|
|
105
|
-
_context2.t0 = _context2.sent;
|
|
106
|
-
signatures = [_context2.t0];
|
|
107
|
-
return _context2.abrupt("return", buildTx({
|
|
108
|
-
encodedTx: rlpBinaryTx,
|
|
109
|
-
signatures: signatures
|
|
110
|
-
}, TX_TYPE.signed).tx);
|
|
111
|
-
|
|
112
|
-
case 10:
|
|
113
|
-
case "end":
|
|
114
|
-
return _context2.stop();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, _callee, this);
|
|
118
|
-
}));
|
|
119
|
-
return _signTransaction.apply(this, arguments);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
function signMessage(_x2) {
|
|
123
|
-
return _signMessage.apply(this, arguments);
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Verify message
|
|
127
|
-
* @instance
|
|
128
|
-
* @category async
|
|
129
|
-
* @rtype (msg: String, signature: String, publicKey: String) => signature: Promise[String], throws: Error
|
|
130
|
-
* @param {String} message - Message to verify
|
|
131
|
-
* @param {String} signature - Signature
|
|
132
|
-
* @param {Object} opt - Options
|
|
133
|
-
* @return {Boolean}
|
|
134
|
-
*/
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function _signMessage() {
|
|
138
|
-
_signMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(message) {
|
|
139
|
-
var opt,
|
|
140
|
-
sig,
|
|
141
|
-
_args2 = arguments;
|
|
142
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
143
|
-
while (1) {
|
|
144
|
-
switch (_context3.prev = _context3.next) {
|
|
145
|
-
case 0:
|
|
146
|
-
opt = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {
|
|
147
|
-
returnHex: false
|
|
148
|
-
};
|
|
149
|
-
_context3.next = 3;
|
|
150
|
-
return this.sign(messageToHash(message), opt);
|
|
151
|
-
|
|
152
|
-
case 3:
|
|
153
|
-
sig = _context3.sent;
|
|
154
|
-
return _context3.abrupt("return", opt.returnHex ? Buffer.from(sig).toString('hex') : sig);
|
|
155
|
-
|
|
156
|
-
case 5:
|
|
157
|
-
case "end":
|
|
158
|
-
return _context3.stop();
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}, _callee2, this);
|
|
162
|
-
}));
|
|
163
|
-
return _signMessage.apply(this, arguments);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
function verifyMessage(_x3, _x4) {
|
|
167
|
-
return _verifyMessage.apply(this, arguments);
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* AccountBase Stamp
|
|
171
|
-
*
|
|
172
|
-
* Attempting to create instances from the Stamp without overwriting all
|
|
173
|
-
* abstract methods using composition will result in an exception.
|
|
174
|
-
*
|
|
175
|
-
* Account is one of the three basic building blocks of an
|
|
176
|
-
* {@link module:@aeternity/aepp-sdk/es/ae--Ae} client and provides access to a
|
|
177
|
-
* signing key pair.
|
|
178
|
-
* @function
|
|
179
|
-
* @alias module:@aeternity/aepp-sdk/es/account
|
|
180
|
-
* @rtype Stamp
|
|
181
|
-
* @param {Object} [options={}] - Initializer object
|
|
182
|
-
* @param {String} options.networkId - NETWORK_ID using for signing transaction's
|
|
183
|
-
* @return {Object} Account instance
|
|
184
|
-
*/
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
function _verifyMessage() {
|
|
188
|
-
_verifyMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(message, signature) {
|
|
189
|
-
var opt,
|
|
190
|
-
_args3 = arguments;
|
|
191
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
192
|
-
while (1) {
|
|
193
|
-
switch (_context4.prev = _context4.next) {
|
|
194
|
-
case 0:
|
|
195
|
-
opt = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
|
|
196
|
-
_context4.t0 = verifyMessageCrypto;
|
|
197
|
-
_context4.t1 = message;
|
|
198
|
-
_context4.t2 = typeof signature === 'string' ? Buffer.from(signature, 'hex') : signature;
|
|
199
|
-
_context4.t3 = decode;
|
|
200
|
-
_context4.next = 7;
|
|
201
|
-
return this.address(opt);
|
|
202
|
-
|
|
203
|
-
case 7:
|
|
204
|
-
_context4.t4 = _context4.sent;
|
|
205
|
-
_context4.t5 = (0, _context4.t3)(_context4.t4);
|
|
206
|
-
return _context4.abrupt("return", (0, _context4.t0)(_context4.t1, _context4.t2, _context4.t5));
|
|
207
|
-
|
|
208
|
-
case 10:
|
|
209
|
-
case "end":
|
|
210
|
-
return _context4.stop();
|
|
211
|
-
}
|
|
212
|
-
}
|
|
213
|
-
}, _callee3, this);
|
|
214
|
-
}));
|
|
215
|
-
return _verifyMessage.apply(this, arguments);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export default stampit({
|
|
219
|
-
init: function init(_ref) {
|
|
220
|
-
var networkId = _ref.networkId;
|
|
221
|
-
|
|
222
|
-
// NETWORK_ID using for signing transaction's
|
|
223
|
-
if (!this.networkId && networkId) {
|
|
224
|
-
this.networkId = networkId;
|
|
225
|
-
}
|
|
226
|
-
},
|
|
227
|
-
methods: {
|
|
228
|
-
signTransaction: signTransaction,
|
|
229
|
-
getNetworkId: getNetworkId,
|
|
230
|
-
signMessage: signMessage,
|
|
231
|
-
verifyMessage: verifyMessage
|
|
232
|
-
}
|
|
233
|
-
}, required({
|
|
234
|
-
methods: {
|
|
235
|
-
sign: required,
|
|
236
|
-
address: required
|
|
237
|
-
}
|
|
238
|
-
}));
|
|
239
|
-
/**
|
|
240
|
-
* Sign data blob
|
|
241
|
-
* @function sign
|
|
242
|
-
* @instance
|
|
243
|
-
* @abstract
|
|
244
|
-
* @category async
|
|
245
|
-
* @rtype (data: String) => data: Promise[String]
|
|
246
|
-
* @param {String} data - Data blob to sign
|
|
247
|
-
* @return {String} Signed data blob
|
|
248
|
-
*/
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Obtain account address
|
|
252
|
-
* @function address
|
|
253
|
-
* @instance
|
|
254
|
-
* @abstract
|
|
255
|
-
* @category async
|
|
256
|
-
* @rtype () => address: Promise[String]
|
|
257
|
-
* @return {String} Public account address
|
|
258
|
-
*/
|
|
259
|
-
//# sourceMappingURL=base.js.map
|
package/es/account/base.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/account/base.js"],"names":["stampit","required","messageToHash","verifyMessage","verifyMessageCrypto","hash","buildTx","decode","TX_TYPE","getNetworkId","isAccountBase","acc","f","signTransaction","tx","opt","prefixes","innerTx","push","rlpBinaryTx","txWithNetworkId","Buffer","from","join","sign","signatures","encodedTx","signed","signMessage","message","returnHex","sig","toString","signature","address","init","networkId","methods"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,QAAT,QAAyB,iBAAzB;AACA,SAASC,aAAT,EAAwBC,aAAa,IAAIC,mBAAzC,EAA8DC,IAA9D,QAA0E,iBAA1E;AACA,SAASC,OAAT,QAAwB,eAAxB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AACA,SAASC,OAAT,QAAwB,sBAAxB;AACA,SAASC,YAAT,QAA6B,SAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,aAAa,GAAG,SAAhBA,aAAgB,CAACC,GAAD;A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iCmB,IAAAA,WAAW,EAAXA,WAAjC;AAA8CzB,IAAAA,aAAa,EAAbA;AAA9C;AANY,CAAD,EAOnBF,QAAQ,CAAC;AACVoC,EAAAA,OAAO,EAAE;AACPb,IAAAA,IAAI,EAAEvB,QADC;AAEPiC,IAAAA,OAAO,EAAEjC;AAFF;AADC,CAAD,CAPW,CAAtB;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * AccountBase module\n * @module @aeternity/aepp-sdk/es/account/base\n * @export AccountBase\n * @export isAccountBase\n */\n\nimport stampit from '@stamp/it'\nimport { required } from '@stamp/required'\nimport { messageToHash, verifyMessage as verifyMessageCrypto, hash } from '../utils/crypto'\nimport { buildTx } from '../tx/builder'\nimport { decode } from '../tx/builder/helpers'\nimport { TX_TYPE } from '../tx/builder/schema'\nimport { getNetworkId } from '../node'\n\n/**\n * Check is provided object looks like an instance of AccountBase\n * @rtype (Object) => Boolean\n * @param {Object} acc - Object to check\n * @return {Boolean}\n */\nexport const isAccountBase = (acc) => !['sign', 'address'].find(f => typeof acc[f] !== 'function')\n\n/**\n * Sign encoded transaction\n * @instance\n * @category async\n * @rtype (tx: String) => tx: Promise[String], throws: Error\n * @param {String} tx - Transaction to sign\n * @param {Object} opt - Options\n * @param {Object} [opt.innerTx] - Sign as inner transaction for PayingFor\n * @return {String} Signed transaction\n */\nasync function signTransaction (tx, opt = {}) {\n const prefixes = [this.getNetworkId(opt)]\n if (opt.innerTx) prefixes.push('inner_tx')\n const rlpBinaryTx = decode(tx, 'tx')\n const txWithNetworkId = Buffer.concat([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)])\n\n const signatures = [await this.sign(txWithNetworkId, opt)]\n return buildTx({ encodedTx: rlpBinaryTx, signatures }, TX_TYPE.signed).tx\n}\n\n/**\n * Get network Id\n * @instance\n * @function getNetworkId\n * @category async\n * @rtype () => networkId: String\n * @return {String} Network Id\n */\n\n/**\n * Sign message\n * @instance\n * @category async\n * @rtype (msg: String) => signature: Promise[String], throws: Error\n * @param {String} message - Message to sign\n * @param {Object} opt - Options\n * @return {String} Signature\n */\nasync function signMessage (message, opt = { returnHex: false }) {\n const sig = await this.sign(messageToHash(message), opt)\n return opt.returnHex ? Buffer.from(sig).toString('hex') : sig\n}\n\n/**\n * Verify message\n * @instance\n * @category async\n * @rtype (msg: String, signature: String, publicKey: String) => signature: Promise[String], throws: Error\n * @param {String} message - Message to verify\n * @param {String} signature - Signature\n * @param {Object} opt - Options\n * @return {Boolean}\n */\nasync function verifyMessage (message, signature, opt = {}) {\n return verifyMessageCrypto(\n message,\n typeof signature === 'string' ? Buffer.from(signature, 'hex') : signature,\n decode(await this.address(opt))\n )\n}\n\n/**\n * AccountBase Stamp\n *\n * Attempting to create instances from the Stamp without overwriting all\n * abstract methods using composition will result in an exception.\n *\n * Account is one of the three basic building blocks of an\n * {@link module:@aeternity/aepp-sdk/es/ae--Ae} client and provides access to a\n * signing key pair.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/account\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {String} options.networkId - NETWORK_ID using for signing transaction's\n * @return {Object} Account instance\n */\nexport default stampit({\n init ({ networkId }) { // NETWORK_ID using for signing transaction's\n if (!this.networkId && networkId) {\n this.networkId = networkId\n }\n },\n methods: { signTransaction, getNetworkId, signMessage, verifyMessage }\n}, required({\n methods: {\n sign: required,\n address: required\n }\n}))\n\n/**\n * Sign data blob\n * @function sign\n * @instance\n * @abstract\n * @category async\n * @rtype (data: String) => data: Promise[String]\n * @param {String} data - Data blob to sign\n * @return {String} Signed data blob\n */\n\n/**\n * Obtain account address\n * @function address\n * @instance\n * @abstract\n * @category async\n * @rtype () => address: Promise[String]\n * @return {String} Public account address\n */\n"],"file":"base.js"}
|
package/es/account/memory.js
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
2
|
-
import _WeakMap from "@babel/runtime-corejs3/core-js-stable/weak-map";
|
|
3
|
-
import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
|
|
4
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
5
|
-
|
|
6
|
-
/*
|
|
7
|
-
* ISC License (ISC)
|
|
8
|
-
* Copyright (c) 2018 aeternity developers
|
|
9
|
-
*
|
|
10
|
-
* Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
* purpose with or without fee is hereby granted, provided that the above
|
|
12
|
-
* copyright notice and this permission notice appear in all copies.
|
|
13
|
-
*
|
|
14
|
-
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
15
|
-
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
16
|
-
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
17
|
-
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
18
|
-
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
19
|
-
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
20
|
-
* PERFORMANCE OF THIS SOFTWARE.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Memory Account module
|
|
25
|
-
* @module @aeternity/aepp-sdk/es/account/memory
|
|
26
|
-
* @export MemoryAccount
|
|
27
|
-
* @example import { MemoryAccount } from '@aeternity/aepp-sdk'
|
|
28
|
-
*/
|
|
29
|
-
import AccountBase from './base';
|
|
30
|
-
import { sign as _sign, isAddressValid, isValidKeypair } from '../utils/crypto';
|
|
31
|
-
import { isHex } from '../utils/string';
|
|
32
|
-
import { decode } from '../tx/builder/helpers';
|
|
33
|
-
var secrets = new _WeakMap();
|
|
34
|
-
/**
|
|
35
|
-
* In-memory account stamp
|
|
36
|
-
* @function
|
|
37
|
-
* @alias module:@aeternity/aepp-sdk/es/account/memory
|
|
38
|
-
* @rtype Stamp
|
|
39
|
-
* @param {Object} [options={}] - Initializer object
|
|
40
|
-
* @param {Object} options.keypair - Key pair to use
|
|
41
|
-
* @param {String} options.keypair.publicKey - Public key
|
|
42
|
-
* @param {String} options.keypair.secretKey - Private key
|
|
43
|
-
* @return {Account}
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
export default AccountBase.compose({
|
|
47
|
-
init: function init(_ref) {
|
|
48
|
-
var _context;
|
|
49
|
-
|
|
50
|
-
var keypair = _ref.keypair,
|
|
51
|
-
gaId = _ref.gaId;
|
|
52
|
-
this.isGa = !!gaId;
|
|
53
|
-
|
|
54
|
-
if (gaId) {
|
|
55
|
-
if (!isAddressValid(gaId)) throw new Error('Invalid GA address');
|
|
56
|
-
secrets.set(this, {
|
|
57
|
-
publicKey: gaId
|
|
58
|
-
});
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (!keypair || _typeof(keypair) !== 'object') throw new Error('KeyPair must be an object');
|
|
63
|
-
if (!keypair.secretKey || !keypair.publicKey) throw new Error('KeyPair must must have "secretKey", "publicKey" properties');
|
|
64
|
-
if (typeof keypair.publicKey !== 'string' || _indexOfInstanceProperty(_context = keypair.publicKey).call(_context, 'ak_') === -1) throw new Error('Public Key must be a base58c string with "ak_" prefix');
|
|
65
|
-
if (!Buffer.isBuffer(keypair.secretKey) && typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey)) throw new Error('Secret key must be hex string or Buffer');
|
|
66
|
-
var pubBuffer = Buffer.from(decode(keypair.publicKey, 'ak'));
|
|
67
|
-
if (!isValidKeypair(Buffer.from(keypair.secretKey, 'hex'), pubBuffer)) throw new Error('Invalid Key Pair');
|
|
68
|
-
secrets.set(this, {
|
|
69
|
-
secretKey: Buffer.isBuffer(keypair.secretKey) ? keypair.secretKey : Buffer.from(keypair.secretKey, 'hex'),
|
|
70
|
-
publicKey: keypair.publicKey
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
props: {
|
|
74
|
-
isGa: false
|
|
75
|
-
},
|
|
76
|
-
methods: {
|
|
77
|
-
sign: function sign(data) {
|
|
78
|
-
if (this.isGa) throw new Error('You are trying to sign data using GA account without keypair');
|
|
79
|
-
return _Promise.resolve(_sign(data, secrets.get(this).secretKey));
|
|
80
|
-
},
|
|
81
|
-
address: function address() {
|
|
82
|
-
return _Promise.resolve(secrets.get(this).publicKey);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
//# sourceMappingURL=memory.js.map
|
package/es/account/memory.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/account/memory.js"],"names":["AccountBase","sign","isAddressValid","isValidKeypair","isHex","decode","secrets","compose","init","keypair","gaId","isGa","Error","set","publicKey","secretKey","Buffer","isBuffer","pubBuffer","from","props","methods","data","resolve","get","address"],"mappings":";;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,WAAP,MAAwB,QAAxB;AACA,SAASC,IAAI,IAAJA,KAAT,EAAeC,cAAf,EAA+BC,cAA/B,QAAqD,iBAArD;AACA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA,IAAMC,OAAO,GAAG,cAAhB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeN,WAAW,CAACO,OAAZ,CAAoB;AACjCC,EAAAA,IADiC,sBACR;AAAA;;AAAA,QAAjBC,OAAiB,QAAjBA,OAAiB;AAAA,QAARC,IAAQ,QAARA,IAAQ;AACvB,SAAKC,IAAL,GAAY,CAAC,CAACD,IAAd;;AACA,QAAIA,IAAJ,EAAU;AACR,UAAI,CAACR,cAAc,CAACQ,IAAD,CAAnB,EAA2B,MAAM,IAAIE,KAAJ,CAAU,oBAAV,CAAN;AAC3BN,MAAAA,OAAO,CAACO,GAAR,CAAY,IAAZ,EAAkB;AAAEC,QAAAA,SAAS,EAAEJ;AAAb,OAAlB;AACA;AACD;;AAED,QAAI,CAACD,OAAD,IAAY,QAAOA,OAAP,MAAmB,QAAnC,EAA6C,MAAM,IAAIG,KAAJ,CAAU,2BAAV,CAAN;AAC7C,QAAI,CAACH,OAAO,CAACM,SAAT,IAAsB,CAACN,OAAO,CAACK,SAAnC,EAA8C,MAAM,IAAIF,KAAJ,CAAU,4DAAV,CAAN;AAC9C,QAAI,OAAOH,OAAO,CAACK,SAAf,KAA6B,QAA7B,IAAyC,oCAAAL,OAAO,CAACK,SAAR,iBAA0B,KAA1B,MAAqC,CAAC,CAAnF,EAAsF,MAAM,IAAIF,KAAJ,CAAU,uDAAV,CAAN;AACtF,QACE,CAACI,MAAM,C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","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Memory Account module\n * @module @aeternity/aepp-sdk/es/account/memory\n * @export MemoryAccount\n * @example import { MemoryAccount } from '@aeternity/aepp-sdk'\n */\n\nimport AccountBase from './base'\nimport { sign, isAddressValid, isValidKeypair } from '../utils/crypto'\nimport { isHex } from '../utils/string'\nimport { decode } from '../tx/builder/helpers'\n\nconst secrets = new WeakMap()\n\n/**\n * In-memory account stamp\n * @function\n * @alias module:@aeternity/aepp-sdk/es/account/memory\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Object} options.keypair - Key pair to use\n * @param {String} options.keypair.publicKey - Public key\n * @param {String} options.keypair.secretKey - Private key\n * @return {Account}\n */\nexport default AccountBase.compose({\n init ({ keypair, gaId }) {\n this.isGa = !!gaId\n if (gaId) {\n if (!isAddressValid(gaId)) throw new Error('Invalid GA address')\n secrets.set(this, { publicKey: gaId })\n return\n }\n\n if (!keypair || typeof keypair !== 'object') throw new Error('KeyPair must be an object')\n if (!keypair.secretKey || !keypair.publicKey) throw new Error('KeyPair must must have \"secretKey\", \"publicKey\" properties')\n if (typeof keypair.publicKey !== 'string' || keypair.publicKey.indexOf('ak_') === -1) throw new Error('Public Key must be a base58c string with \"ak_\" prefix')\n if (\n !Buffer.isBuffer(keypair.secretKey) &&\n (typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey))\n ) throw new Error('Secret key must be hex string or Buffer')\n\n const pubBuffer = Buffer.from(decode(keypair.publicKey, 'ak'))\n if (!isValidKeypair(Buffer.from(keypair.secretKey, 'hex'), pubBuffer)) throw new Error('Invalid Key Pair')\n\n secrets.set(this, {\n secretKey: Buffer.isBuffer(keypair.secretKey) ? keypair.secretKey : Buffer.from(keypair.secretKey, 'hex'),\n publicKey: keypair.publicKey\n })\n },\n props: { isGa: false },\n methods: {\n sign (data) {\n if (this.isGa) throw new Error('You are trying to sign data using GA account without keypair')\n return Promise.resolve(sign(data, secrets.get(this).secretKey))\n },\n address () {\n return Promise.resolve(secrets.get(this).publicKey)\n }\n }\n})\n"],"file":"memory.js"}
|
package/es/account/multiple.js
DELETED
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
2
|
-
import _fromPairs from "ramda/src/fromPairs";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
4
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
5
|
-
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
|
6
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
7
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
8
|
-
import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
9
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
10
|
-
import AsyncInit from '../utils/async-init';
|
|
11
|
-
import MemoryAccount from './memory';
|
|
12
|
-
import { decode } from '../tx/builder/helpers';
|
|
13
|
-
import AccountBase, { isAccountBase } from './base';
|
|
14
|
-
/**
|
|
15
|
-
* AccountMultiple stamp
|
|
16
|
-
*
|
|
17
|
-
* The purpose of this stamp is to wrap up implementations of
|
|
18
|
-
* {@link module:@aeternity/aepp-sdk/es/account/base--AccountBase} objects and provide a
|
|
19
|
-
* common interface to all of them. List are a substantial part of
|
|
20
|
-
* {@link module:@aeternity/aepp-sdk/es/ae/wallet--Wallet}s.
|
|
21
|
-
* @function
|
|
22
|
-
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
23
|
-
* @rtype Stamp
|
|
24
|
-
* @param {Object} [options={}] - Initializer object
|
|
25
|
-
* @param {Array} [options.accounts] - Accounts array
|
|
26
|
-
* @param {String} [options.address] - Address of account to select
|
|
27
|
-
* @return {Object} AccountMultiple instance
|
|
28
|
-
* @example
|
|
29
|
-
* const accounts = await AccountMultiple({ accounts: [ MemmoryAccount({ keypair: 'keypair_object' }) ] })
|
|
30
|
-
* await accounts.addAccount(account, { select: true }) // Add account and make it selected
|
|
31
|
-
* accounts.removeAccount(address) // Remove account
|
|
32
|
-
* accounts.selectAccount(address) // Select account
|
|
33
|
-
* accounts.addresses() // Get available accounts
|
|
34
|
-
*/
|
|
35
|
-
|
|
36
|
-
export default AccountBase.compose(AsyncInit, {
|
|
37
|
-
init: function init(_ref) {
|
|
38
|
-
var _this = this;
|
|
39
|
-
|
|
40
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
41
|
-
var _ref$accounts, accounts, address;
|
|
42
|
-
|
|
43
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
44
|
-
while (1) {
|
|
45
|
-
switch (_context2.prev = _context2.next) {
|
|
46
|
-
case 0:
|
|
47
|
-
_ref$accounts = _ref.accounts, accounts = _ref$accounts === void 0 ? [] : _ref$accounts, address = _ref.address;
|
|
48
|
-
|
|
49
|
-
if (!(_Array$isArray(accounts) && accounts.length)) {
|
|
50
|
-
_context2.next = 12;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
_context2.t0 = _fromPairs;
|
|
55
|
-
_context2.next = 5;
|
|
56
|
-
return _Promise.all(_mapInstanceProperty(accounts).call(accounts, /*#__PURE__*/function () {
|
|
57
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(a) {
|
|
58
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
59
|
-
while (1) {
|
|
60
|
-
switch (_context.prev = _context.next) {
|
|
61
|
-
case 0:
|
|
62
|
-
_context.next = 2;
|
|
63
|
-
return a.address();
|
|
64
|
-
|
|
65
|
-
case 2:
|
|
66
|
-
_context.t0 = _context.sent;
|
|
67
|
-
_context.t1 = a;
|
|
68
|
-
return _context.abrupt("return", [_context.t0, _context.t1]);
|
|
69
|
-
|
|
70
|
-
case 5:
|
|
71
|
-
case "end":
|
|
72
|
-
return _context.stop();
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}, _callee);
|
|
76
|
-
}));
|
|
77
|
-
|
|
78
|
-
return function (_x) {
|
|
79
|
-
return _ref2.apply(this, arguments);
|
|
80
|
-
};
|
|
81
|
-
}()));
|
|
82
|
-
|
|
83
|
-
case 5:
|
|
84
|
-
_context2.t1 = _context2.sent;
|
|
85
|
-
_this.accounts = (0, _context2.t0)(_context2.t1);
|
|
86
|
-
if (!address) address = _Object$keys(_this.accounts)[0];
|
|
87
|
-
decode(address, 'ak');
|
|
88
|
-
_this.selectedAddress = address;
|
|
89
|
-
_context2.next = 13;
|
|
90
|
-
break;
|
|
91
|
-
|
|
92
|
-
case 12:
|
|
93
|
-
console.warn('No account/accounts supplied');
|
|
94
|
-
|
|
95
|
-
case 13:
|
|
96
|
-
case "end":
|
|
97
|
-
return _context2.stop();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, _callee2);
|
|
101
|
-
}))();
|
|
102
|
-
},
|
|
103
|
-
props: {
|
|
104
|
-
accounts: {}
|
|
105
|
-
},
|
|
106
|
-
deepProps: {
|
|
107
|
-
selectedAddress: null
|
|
108
|
-
},
|
|
109
|
-
methods: {
|
|
110
|
-
address: function address() {
|
|
111
|
-
var _arguments = arguments,
|
|
112
|
-
_this2 = this;
|
|
113
|
-
|
|
114
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
115
|
-
var _ref3, _ref3$onAccount, onAccount;
|
|
116
|
-
|
|
117
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
118
|
-
while (1) {
|
|
119
|
-
switch (_context3.prev = _context3.next) {
|
|
120
|
-
case 0:
|
|
121
|
-
_ref3 = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : {}, _ref3$onAccount = _ref3.onAccount, onAccount = _ref3$onAccount === void 0 ? _this2.selectedAddress : _ref3$onAccount;
|
|
122
|
-
return _context3.abrupt("return", _this2._resolveAccount(onAccount).address());
|
|
123
|
-
|
|
124
|
-
case 2:
|
|
125
|
-
case "end":
|
|
126
|
-
return _context3.stop();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}, _callee3);
|
|
130
|
-
}))();
|
|
131
|
-
},
|
|
132
|
-
sign: function sign(data) {
|
|
133
|
-
var _arguments2 = arguments,
|
|
134
|
-
_this3 = this;
|
|
135
|
-
|
|
136
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
137
|
-
var _ref4, _ref4$onAccount, onAccount;
|
|
138
|
-
|
|
139
|
-
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
140
|
-
while (1) {
|
|
141
|
-
switch (_context4.prev = _context4.next) {
|
|
142
|
-
case 0:
|
|
143
|
-
_ref4 = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : {}, _ref4$onAccount = _ref4.onAccount, onAccount = _ref4$onAccount === void 0 ? _this3.selectedAddress : _ref4$onAccount;
|
|
144
|
-
return _context4.abrupt("return", _this3._resolveAccount(onAccount).sign(data));
|
|
145
|
-
|
|
146
|
-
case 2:
|
|
147
|
-
case "end":
|
|
148
|
-
return _context4.stop();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}, _callee4);
|
|
152
|
-
}))();
|
|
153
|
-
},
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Get accounts addresses
|
|
157
|
-
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
158
|
-
* @function
|
|
159
|
-
* @rtype () => String[]
|
|
160
|
-
* @return {String[]}
|
|
161
|
-
* @example addresses()
|
|
162
|
-
*/
|
|
163
|
-
addresses: function addresses() {
|
|
164
|
-
return _Object$keys(this.accounts);
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Add specific account
|
|
169
|
-
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
170
|
-
* @function
|
|
171
|
-
* @category async
|
|
172
|
-
* @rtype (account: Account, { select: Boolean }) => void
|
|
173
|
-
* @param {Object} account - Account instance
|
|
174
|
-
* @param {Object} [options={}] - Options
|
|
175
|
-
* @param {Boolean} [options.select] - Select account
|
|
176
|
-
* @return {void}
|
|
177
|
-
* @example addAccount(account)
|
|
178
|
-
*/
|
|
179
|
-
addAccount: function addAccount(account) {
|
|
180
|
-
var _arguments3 = arguments,
|
|
181
|
-
_this4 = this;
|
|
182
|
-
|
|
183
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
184
|
-
var _ref5, select, address;
|
|
185
|
-
|
|
186
|
-
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
187
|
-
while (1) {
|
|
188
|
-
switch (_context5.prev = _context5.next) {
|
|
189
|
-
case 0:
|
|
190
|
-
_ref5 = _arguments3.length > 1 && _arguments3[1] !== undefined ? _arguments3[1] : {}, select = _ref5.select;
|
|
191
|
-
_context5.next = 3;
|
|
192
|
-
return account.address();
|
|
193
|
-
|
|
194
|
-
case 3:
|
|
195
|
-
address = _context5.sent;
|
|
196
|
-
_this4.accounts[address] = account;
|
|
197
|
-
if (select) _this4.selectAccount(address);
|
|
198
|
-
|
|
199
|
-
case 6:
|
|
200
|
-
case "end":
|
|
201
|
-
return _context5.stop();
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}, _callee5);
|
|
205
|
-
}))();
|
|
206
|
-
},
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* Remove specific account
|
|
210
|
-
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
211
|
-
* @function
|
|
212
|
-
* @rtype (address: String) => void
|
|
213
|
-
* @param {String} address - Address of account to remove
|
|
214
|
-
* @return {void}
|
|
215
|
-
* @example removeAccount(address)
|
|
216
|
-
*/
|
|
217
|
-
removeAccount: function removeAccount(address) {
|
|
218
|
-
if (!this.accounts[address]) {
|
|
219
|
-
console.warn("removeAccount: Account for ".concat(address, " not available"));
|
|
220
|
-
return;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
delete this.accounts[address];
|
|
224
|
-
if (this.selectedAddress === address) this.selectedAddress = null;
|
|
225
|
-
},
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Select specific account
|
|
229
|
-
* @alias module:@aeternity/aepp-sdk/es/account/selector
|
|
230
|
-
* @instance
|
|
231
|
-
* @rtype (address: String) => void
|
|
232
|
-
* @param {String} address - Address of account to select
|
|
233
|
-
* @example selectAccount('ak_xxxxxxxx')
|
|
234
|
-
*/
|
|
235
|
-
selectAccount: function selectAccount(address) {
|
|
236
|
-
decode(address, 'ak');
|
|
237
|
-
if (!this.accounts[address]) throw new Error("Account for ".concat(address, " not available"));
|
|
238
|
-
this.selectedAddress = address;
|
|
239
|
-
},
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Resolves an account
|
|
243
|
-
* @param account can be account address (should exist in sdk instance), MemoryAccount or keypair
|
|
244
|
-
* @returns {AccountBase}
|
|
245
|
-
* @private
|
|
246
|
-
*/
|
|
247
|
-
_resolveAccount: function _resolveAccount(account) {
|
|
248
|
-
var _context6;
|
|
249
|
-
|
|
250
|
-
switch (_typeof(account)) {
|
|
251
|
-
case 'string':
|
|
252
|
-
decode(account, 'ak');
|
|
253
|
-
if (!this.accounts[account]) throw new Error("Account for ".concat(account, " not available"));
|
|
254
|
-
return this.accounts[account];
|
|
255
|
-
|
|
256
|
-
case 'object':
|
|
257
|
-
return isAccountBase(account) ? account : MemoryAccount({
|
|
258
|
-
keypair: account
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
default:
|
|
262
|
-
throw new Error(_concatInstanceProperty(_context6 = "Unknown account type: ".concat(_typeof(account), " (account: ")).call(_context6, account, ")"));
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
//# sourceMappingURL=multiple.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/account/multiple.js"],"names":["AsyncInit","MemoryAccount","decode","AccountBase","isAccountBase","compose","init","accounts","address","length","all","a","selectedAddress","console","warn","props","deepProps","methods","onAccount","_resolveAccount","sign","data","addresses","addAccount","account","select","selectAccount","removeAccount","Error","keypair"],"mappings":";;;;;;;;;AAwBA,OAAOA,SAAP,MAAsB,qBAAtB;AACA,OAAOC,aAAP,MAA0B,UAA1B;AACA,SAASC,MAAT,QAAuB,uBAAvB;AACA,OAAOC,WAAP,IAAsBC,aAAtB,QAA2C,QAA3C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeD,WAAW,CAACE,OAAZ,CAAoBL,SAApB,EAA+B;AACtCM,EAAAA,IADsC,sBACJ;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA,mCAA1BC,QAA0B,EAA1BA,QAA0B,8BAAf,EAAe,kBAAXC,OAAW,QAAXA,OAAW;;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;AACIc,IAAAA,aA5DO,yBA4DQlB,OA5DR,EA4DiB;AACtBN,MAAAA,MAAM,CAACM,OAAD,EAAU,IAAV,CAAN;AACA,UAAI,CAAC,KAAKD,QAAL,CAAcC,OAAd,CAAL,EAA6B,MAAM,IAAIoB,KAAJ,uBAAyBpB,OAAzB,oBAAN;AAC7B,WAAKI,eAAL,GAAuBJ,OAAvB;AACD,KAhEM;;AAiEP;AACJ;AACA;AACA;AACA;AACA;AACIW,IAAAA,eAvEO,2BAuEUK,OAvEV,EAuEmB;AAAA;;AACxB,sBAAeA,OAAf;AACE,aAAK,QAAL;AACEtB,UAAAA,MAAM,CAACsB,OAAD,EAAU,IAAV,CAAN;AACA,cAAI,CAAC,KAAKjB,QAAL,CAAciB,OAAd,CAAL,EAA6B,MAAM,IAAII,KAAJ,uBAAyBJ,OAAzB,oBAAN;AAC7B,iBAAO,KAAKjB,QAAL,CAAciB,OAAd,CAAP;;AACF,aAAK,QAAL;AACE,iBAAOpB,aAAa,CAACoB,OAAD,CAAb,GAAyBA,OAAzB,GAAmCvB,aAAa,CAAC;AAAE4B,YAAAA,OAAO,EAAEL;AAAX,WAAD,CAAvD;;AACF;AACE,gBAAM,IAAII,KAAJ,6EAA0CJ,OAA1C,mCAA+DA,OAA/D,OAAN;AARJ;AAUD;AAlFM;AAlBmC,CAA/B,CAAf","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * AccountMultiple module\n * @module @aeternity/aepp-sdk/es/accounts/multiple\n * @export AccountMultiple\n */\n\nimport * as R from 'ramda'\nimport AsyncInit from '../utils/async-init'\nimport MemoryAccount from './memory'\nimport { decode } from '../tx/builder/helpers'\nimport AccountBase, { isAccountBase } from './base'\n\n/**\n * AccountMultiple stamp\n *\n * The purpose of this stamp is to wrap up implementations of\n * {@link module:@aeternity/aepp-sdk/es/account/base--AccountBase} objects and provide a\n * common interface to all of them. List are a substantial part of\n * {@link module:@aeternity/aepp-sdk/es/ae/wallet--Wallet}s.\n * @function\n * @alias module:@aeternity/aepp-sdk/es/accounts/multiple\n * @rtype Stamp\n * @param {Object} [options={}] - Initializer object\n * @param {Array} [options.accounts] - Accounts array\n * @param {String} [options.address] - Address of account to select\n * @return {Object} AccountMultiple instance\n * @example\n * const accounts = await AccountMultiple({ accounts: [ MemmoryAccount({ keypair: 'keypair_object' }) ] })\n * await accounts.addAccount(account, { select: true }) // Add account and make it selected\n * accounts.removeAccount(address) // Remove account\n * accounts.selectAccount(address) // Select account\n * accounts.addresses() // Get available accounts\n */\nexport default AccountBase.compose(AsyncInit, {\n async init ({ accounts = [], address }) {\n /* An Account maynot be required for the Node/Chain methods */\n if (Array.isArray(accounts) && accounts.length) {\n this.accounts = R.fromPairs(await Promise.all(accounts.map(async a => [await a.address(), a])))\n if (!address) address = Object.keys(this.accounts)[0]\n decode(address, 'ak')\n this.selectedAddress = address\n } else {\n console.warn('No account/accounts supplied')\n }\n },\n props: {\n accounts: {}\n },\n deepProps: {\n selectedAddress: null\n },\n methods: {\n async address ({ onAccount = this.selectedAddress } = {}) {\n return this._resolveAccount(onAccount).address()\n },\n async sign (data, { onAccount = this.selectedAddress } = {}) {\n return this._resolveAccount(onAccount).sign(data)\n },\n /**\n * Get accounts addresses\n * @alias module:@aeternity/aepp-sdk/es/accounts/multiple\n * @function\n * @rtype () => String[]\n * @return {String[]}\n * @example addresses()\n */\n addresses () {\n return Object.keys(this.accounts)\n },\n /**\n * Add specific account\n * @alias module:@aeternity/aepp-sdk/es/accounts/multiple\n * @function\n * @category async\n * @rtype (account: Account, { select: Boolean }) => void\n * @param {Object} account - Account instance\n * @param {Object} [options={}] - Options\n * @param {Boolean} [options.select] - Select account\n * @return {void}\n * @example addAccount(account)\n */\n async addAccount (account, { select } = {}) {\n const address = await account.address()\n this.accounts[address] = account\n if (select) this.selectAccount(address)\n },\n /**\n * Remove specific account\n * @alias module:@aeternity/aepp-sdk/es/accounts/multiple\n * @function\n * @rtype (address: String) => void\n * @param {String} address - Address of account to remove\n * @return {void}\n * @example removeAccount(address)\n */\n removeAccount (address) {\n if (!this.accounts[address]) {\n console.warn(`removeAccount: Account for ${address} not available`)\n return\n }\n delete this.accounts[address]\n if (this.selectedAddress === address) this.selectedAddress = null\n },\n /**\n * Select specific account\n * @alias module:@aeternity/aepp-sdk/es/account/selector\n * @instance\n * @rtype (address: String) => void\n * @param {String} address - Address of account to select\n * @example selectAccount('ak_xxxxxxxx')\n */\n selectAccount (address) {\n decode(address, 'ak')\n if (!this.accounts[address]) throw new Error(`Account for ${address} not available`)\n this.selectedAddress = address\n },\n /**\n * Resolves an account\n * @param account can be account address (should exist in sdk instance), MemoryAccount or keypair\n * @returns {AccountBase}\n * @private\n */\n _resolveAccount (account) {\n switch (typeof account) {\n case 'string':\n decode(account, 'ak')\n if (!this.accounts[account]) throw new Error(`Account for ${account} not available`)\n return this.accounts[account]\n case 'object':\n return isAccountBase(account) ? account : MemoryAccount({ keypair: account })\n default:\n throw new Error(`Unknown account type: ${typeof account} (account: ${account})`)\n }\n }\n }\n})\n"],"file":"multiple.js"}
|