@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
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
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 _stampRequired from '@stamp/required';
|
|
31
|
+
const {
|
|
32
|
+
required
|
|
33
|
+
} = _stampRequired;
|
|
34
|
+
import { messageToHash, verifyMessage as verifyMessageCrypto, hash } from "../utils/crypto.mjs";
|
|
35
|
+
import { buildTx } from "../tx/builder/index.mjs";
|
|
36
|
+
import { decode } from "../tx/builder/helpers.mjs";
|
|
37
|
+
import { TX_TYPE } from "../tx/builder/schema.mjs";
|
|
38
|
+
import { getNetworkId } from "../node.mjs";
|
|
39
|
+
/**
|
|
40
|
+
* Check is provided object looks like an instance of AccountBase
|
|
41
|
+
* @rtype (Object) => Boolean
|
|
42
|
+
* @param {Object} acc - Object to check
|
|
43
|
+
* @return {Boolean}
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
export const isAccountBase = acc => !['sign', 'address'].find(f => typeof acc[f] !== 'function');
|
|
47
|
+
/**
|
|
48
|
+
* Sign encoded transaction
|
|
49
|
+
* @instance
|
|
50
|
+
* @category async
|
|
51
|
+
* @rtype (tx: String) => tx: Promise[String], throws: Error
|
|
52
|
+
* @param {String} tx - Transaction to sign
|
|
53
|
+
* @param {Object} opt - Options
|
|
54
|
+
* @param {Object} [opt.innerTx] - Sign as inner transaction for PayingFor
|
|
55
|
+
* @return {String} Signed transaction
|
|
56
|
+
*/
|
|
57
|
+
|
|
58
|
+
async function signTransaction(tx) {
|
|
59
|
+
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
60
|
+
const prefixes = [this.getNetworkId(opt)];
|
|
61
|
+
if (opt.innerTx) prefixes.push('inner_tx');
|
|
62
|
+
const rlpBinaryTx = decode(tx, 'tx');
|
|
63
|
+
|
|
64
|
+
const txWithNetworkId = _Buffer.concat([_Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);
|
|
65
|
+
|
|
66
|
+
const signatures = [await this.sign(txWithNetworkId, opt)];
|
|
67
|
+
return buildTx({
|
|
68
|
+
encodedTx: rlpBinaryTx,
|
|
69
|
+
signatures
|
|
70
|
+
}, TX_TYPE.signed).tx;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get network Id
|
|
74
|
+
* @instance
|
|
75
|
+
* @function getNetworkId
|
|
76
|
+
* @category async
|
|
77
|
+
* @rtype () => networkId: String
|
|
78
|
+
* @return {String} Network Id
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Sign message
|
|
83
|
+
* @instance
|
|
84
|
+
* @category async
|
|
85
|
+
* @rtype (msg: String) => signature: Promise[String], throws: Error
|
|
86
|
+
* @param {String} message - Message to sign
|
|
87
|
+
* @param {Object} opt - Options
|
|
88
|
+
* @return {String} Signature
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
async function signMessage(message) {
|
|
93
|
+
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
94
|
+
returnHex: false
|
|
95
|
+
};
|
|
96
|
+
const sig = await this.sign(messageToHash(message), opt);
|
|
97
|
+
return opt.returnHex ? _Buffer.from(sig).toString('hex') : sig;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Verify message
|
|
101
|
+
* @instance
|
|
102
|
+
* @category async
|
|
103
|
+
* @rtype (
|
|
104
|
+
* msg: String, signature: String, publicKey: String
|
|
105
|
+
* ) => signature: Promise[String], throws: Error
|
|
106
|
+
* @param {String} message - Message to verify
|
|
107
|
+
* @param {String} signature - Signature
|
|
108
|
+
* @param {Object} opt - Options
|
|
109
|
+
* @return {Boolean}
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
async function verifyMessage(message, signature) {
|
|
114
|
+
let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
115
|
+
return verifyMessageCrypto(message, typeof signature === 'string' ? _Buffer.from(signature, 'hex') : signature, decode(await this.address(opt)));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* AccountBase Stamp
|
|
119
|
+
*
|
|
120
|
+
* Attempting to create instances from the Stamp without overwriting all
|
|
121
|
+
* abstract methods using composition will result in an exception.
|
|
122
|
+
*
|
|
123
|
+
* Account is one of the three basic building blocks of an
|
|
124
|
+
* {@link module:@aeternity/aepp-sdk/es/ae--Ae} client and provides access to a
|
|
125
|
+
* signing key pair.
|
|
126
|
+
* @function
|
|
127
|
+
* @alias module:@aeternity/aepp-sdk/es/account
|
|
128
|
+
* @rtype Stamp
|
|
129
|
+
* @param {Object} [options={}] - Initializer object
|
|
130
|
+
* @param {String} options.networkId - NETWORK_ID using for signing transaction's
|
|
131
|
+
* @return {Object} Account instance
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
export default stampit({
|
|
136
|
+
init(_ref) {
|
|
137
|
+
let {
|
|
138
|
+
networkId
|
|
139
|
+
} = _ref;
|
|
140
|
+
|
|
141
|
+
// NETWORK_ID using for signing transaction's
|
|
142
|
+
if (!this.networkId && networkId) {
|
|
143
|
+
this.networkId = networkId;
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
|
|
147
|
+
methods: {
|
|
148
|
+
signTransaction,
|
|
149
|
+
getNetworkId,
|
|
150
|
+
signMessage,
|
|
151
|
+
verifyMessage
|
|
152
|
+
}
|
|
153
|
+
}, required({
|
|
154
|
+
methods: {
|
|
155
|
+
sign: required,
|
|
156
|
+
address: required
|
|
157
|
+
}
|
|
158
|
+
}));
|
|
159
|
+
/**
|
|
160
|
+
* Sign data blob
|
|
161
|
+
* @function sign
|
|
162
|
+
* @instance
|
|
163
|
+
* @abstract
|
|
164
|
+
* @category async
|
|
165
|
+
* @rtype (data: String) => data: Promise[String]
|
|
166
|
+
* @param {String} data - Data blob to sign
|
|
167
|
+
* @return {String} Signed data blob
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Obtain account address
|
|
172
|
+
* @function address
|
|
173
|
+
* @instance
|
|
174
|
+
* @abstract
|
|
175
|
+
* @category async
|
|
176
|
+
* @rtype () => address: Promise[String]
|
|
177
|
+
* @return {String} Public account address
|
|
178
|
+
*/
|
|
179
|
+
//# sourceMappingURL=base.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/account/base.js"],"names":["stampit","messageToHash","verifyMessage","verifyMessageCrypto","hash","buildTx","decode","TX_TYPE","getNetworkId","isAccountBase","acc","find","f","signTransaction","tx","opt","prefixes","innerTx","push","rlpBinaryTx","txWithNetworkId","concat","from","join","signatures","sign","encodedTx","signed","signMessage","message","returnHex","sig","toString","signature","address","init","networkId","methods","required"],"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,2BAAyB,iBAAzB;;;;SACSC,a,EAAeC,aAAa,IAAIC,mB,EAAqBC,I;SACrDC,O;SACAC,M;SACAC,O;SAC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AAlB;AACA,SAAOA,GAAG,CAACe,SAAJ,GAAgB,QAAOR,IAAP,CAAYS,GAAZ,EAAiBC,QAAjB,CAA0B,KAA1B,CAAhB,GAAmDD,GAA1D;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe7B,aAAf,CAA8B2B,OAA9B,EAAuCI,SAAvC,EAA4D;AAAA,MAAVlB,GAAU,uEAAJ,EAAI;AAC1D,SAAOZ,mBAAmB,CACxB0B,OADwB,EAExB,OAAOI,SAAP,KAAqB,QAArB,GAAgC,QAAOX,IAAP,CAAYW,SAAZ,EAAuB,KAAvB,CAAhC,GAAgEA,SAFxC,EAGxB3B,MAAM,CAAC,MAAM,KAAK4B,OAAL,CAAanB,GAAb,CAAP,CAHkB,CAA1B;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAef,OAAO,CAAC;AACrBmC,EAAAA,IAAI,OAAiB;AAAA,QAAf;AAAEC,MAAAA;AAAF,KAAe;;AAAE;AACrB,QAAI,CAAC,KAAKA,SAAN,IAAmBA,SAAvB,EAAkC;AAChC,WAAKA,SAAL,GAAiBA,SAAjB;AACD;AACF,GALoB;;AAMrBC,EAAAA,OAAO,EAAE;AAAExB,IAAAA,eAAF;AAAmBL,IAAAA,YAAnB;AAAiCoB,IAAAA,WAAjC;AAA8C1B,IAAAA;AAA9C;AANY,CAAD,EAOnBoC,QAAQ,CAAC;AACVD,EAAAA,OAAO,EAAE;AACPZ,IAAAA,IAAI,EAAEa,QADC;AAEPJ,IAAAA,OAAO,EAAEI;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 (\n * msg: String, signature: String, publicKey: String\n * ) => 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.mjs"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import _buffer from "buffer";
|
|
2
|
+
const {
|
|
3
|
+
Buffer: _Buffer
|
|
4
|
+
} = _buffer;
|
|
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.mjs";
|
|
30
|
+
import { sign, isValidKeypair } from "../utils/crypto.mjs";
|
|
31
|
+
import { isHex } from "../utils/string.mjs";
|
|
32
|
+
import { decode } from "../tx/builder/helpers.mjs";
|
|
33
|
+
import { InvalidKeypairError } from "../utils/errors.mjs";
|
|
34
|
+
const secrets = new WeakMap();
|
|
35
|
+
/**
|
|
36
|
+
* In-memory account stamp
|
|
37
|
+
* @function
|
|
38
|
+
* @alias module:@aeternity/aepp-sdk/es/account/memory
|
|
39
|
+
* @rtype Stamp
|
|
40
|
+
* @param {Object} [options={}] - Initializer object
|
|
41
|
+
* @param {Object} options.keypair - Key pair to use
|
|
42
|
+
* @param {String} options.keypair.publicKey - Public key
|
|
43
|
+
* @param {String} options.keypair.secretKey - Private key
|
|
44
|
+
* @return {Account}
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
export default AccountBase.compose({
|
|
48
|
+
init(_ref) {
|
|
49
|
+
let {
|
|
50
|
+
keypair,
|
|
51
|
+
gaId
|
|
52
|
+
} = _ref;
|
|
53
|
+
this.isGa = !!gaId;
|
|
54
|
+
|
|
55
|
+
if (gaId) {
|
|
56
|
+
decode(gaId);
|
|
57
|
+
secrets.set(this, {
|
|
58
|
+
publicKey: gaId
|
|
59
|
+
});
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
if (!keypair || typeof keypair !== 'object') throw new InvalidKeypairError('KeyPair must be an object');
|
|
64
|
+
|
|
65
|
+
if (!keypair.secretKey || !keypair.publicKey) {
|
|
66
|
+
throw new InvalidKeypairError('KeyPair must must have "secretKey", "publicKey" properties');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (typeof keypair.publicKey !== 'string' || keypair.publicKey.indexOf('ak_') === -1) {
|
|
70
|
+
throw new InvalidKeypairError('Public Key must be a base58c string with "ak_" prefix');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (!_Buffer.isBuffer(keypair.secretKey) && typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey)) throw new InvalidKeypairError('Secret key must be hex string or Buffer');
|
|
74
|
+
|
|
75
|
+
const pubBuffer = _Buffer.from(decode(keypair.publicKey, 'ak'));
|
|
76
|
+
|
|
77
|
+
if (!isValidKeypair(_Buffer.from(keypair.secretKey, 'hex'), pubBuffer)) throw new InvalidKeypairError('Invalid Key Pair');
|
|
78
|
+
secrets.set(this, {
|
|
79
|
+
secretKey: _Buffer.isBuffer(keypair.secretKey) ? keypair.secretKey : _Buffer.from(keypair.secretKey, 'hex'),
|
|
80
|
+
publicKey: keypair.publicKey
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
props: {
|
|
85
|
+
isGa: false
|
|
86
|
+
},
|
|
87
|
+
methods: {
|
|
88
|
+
sign(data) {
|
|
89
|
+
if (this.isGa) throw new InvalidKeypairError('You are trying to sign data using generalized account without keypair');
|
|
90
|
+
return Promise.resolve(sign(data, secrets.get(this).secretKey));
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
address() {
|
|
94
|
+
return Promise.resolve(secrets.get(this).publicKey);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
//# sourceMappingURL=memory.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/account/memory.js"],"names":["AccountBase","sign","isValidKeypair","isHex","decode","InvalidKeypairError","secrets","WeakMap","compose","init","keypair","gaId","isGa","set","publicKey","secretKey","indexOf","isBuffer","pubBuffer","from","props","methods","data","Promise","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;OAEOA,W;SACEC,I,EAAMC,c;SACNC,K;SACAC,M;SACAC,mB;AAET,MAAMC,OAAO,GAAG,IAAIC,OAAJ,EAAhB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeP,WAAW,CAACQ,OAAZ,CAAoB;AACjCC,EAAA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CAAY,IAAZ,EAAkB;AAChBE,MAAAA,SAAS,EAAE,QAAOE,QAAP,CAAgBP,OAAO,CAACK,SAAxB,IAAqCL,OAAO,CAACK,SAA7C,GAAyD,QAAOI,IAAP,CAAYT,OAAO,CAACK,SAApB,EAA+B,KAA/B,CADpD;AAEhBD,MAAAA,SAAS,EAAEJ,OAAO,CAACI;AAFH,KAAlB;AAID,GA5BgC;;AA6BjCM,EAAAA,KAAK,EAAE;AAAER,IAAAA,IAAI,EAAE;AAAR,GA7B0B;AA8BjCS,EAAAA,OAAO,EAAE;AACPpB,IAAAA,IAAI,CAAEqB,IAAF,EAAQ;AACV,UAAI,KAAKV,IAAT,EAAe,MAAM,IAAIP,mBAAJ,CAAwB,uEAAxB,CAAN;AACf,aAAOkB,OAAO,CAACC,OAAR,CAAgBvB,IAAI,CAACqB,IAAD,EAAOhB,OAAO,CAACmB,GAAR,CAAY,IAAZ,EAAkBV,SAAzB,CAApB,CAAP;AACD,KAJM;;AAKPW,IAAAA,OAAO,GAAI;AACT,aAAOH,OAAO,CAACC,OAAR,CAAgBlB,OAAO,CAACmB,GAAR,CAAY,IAAZ,EAAkBX,SAAlC,CAAP;AACD;;AAPM;AA9BwB,CAApB,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 * 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, isValidKeypair } from '../utils/crypto'\nimport { isHex } from '../utils/string'\nimport { decode } from '../tx/builder/helpers'\nimport { InvalidKeypairError } from '../utils/errors'\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 decode(gaId)\n secrets.set(this, { publicKey: gaId })\n return\n }\n\n if (!keypair || typeof keypair !== 'object') throw new InvalidKeypairError('KeyPair must be an object')\n if (!keypair.secretKey || !keypair.publicKey) {\n throw new InvalidKeypairError('KeyPair must must have \"secretKey\", \"publicKey\" properties')\n }\n if (typeof keypair.publicKey !== 'string' || keypair.publicKey.indexOf('ak_') === -1) {\n throw new InvalidKeypairError('Public Key must be a base58c string with \"ak_\" prefix')\n }\n if (\n !Buffer.isBuffer(keypair.secretKey) &&\n (typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey))\n ) throw new InvalidKeypairError('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 InvalidKeypairError('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 InvalidKeypairError('You are trying to sign data using generalized 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.mjs"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ISC License (ISC)
|
|
3
|
+
* Copyright (c) 2018 aeternity developers
|
|
4
|
+
*
|
|
5
|
+
* Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
* purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
* copyright notice and this permission notice appear in all copies.
|
|
8
|
+
*
|
|
9
|
+
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
10
|
+
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
11
|
+
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
12
|
+
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
13
|
+
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
14
|
+
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
15
|
+
* PERFORMANCE OF THIS SOFTWARE.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* AccountMultiple module
|
|
20
|
+
* @module @aeternity/aepp-sdk/es/accounts/multiple
|
|
21
|
+
* @export AccountMultiple
|
|
22
|
+
*/
|
|
23
|
+
import AsyncInit from "../utils/async-init.mjs";
|
|
24
|
+
import MemoryAccount from "./memory.mjs";
|
|
25
|
+
import { decode } from "../tx/builder/helpers.mjs";
|
|
26
|
+
import AccountBase, { isAccountBase } from "./base.mjs";
|
|
27
|
+
import { UnavailableAccountError, TypeError } from "../utils/errors.mjs";
|
|
28
|
+
/**
|
|
29
|
+
* AccountMultiple stamp
|
|
30
|
+
*
|
|
31
|
+
* The purpose of this stamp is to wrap up implementations of
|
|
32
|
+
* {@link module:@aeternity/aepp-sdk/es/account/base--AccountBase} objects and provide a
|
|
33
|
+
* common interface to all of them. List are a substantial part of
|
|
34
|
+
* {@link module:@aeternity/aepp-sdk/es/ae/wallet--Wallet}s.
|
|
35
|
+
* @function
|
|
36
|
+
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
37
|
+
* @rtype Stamp
|
|
38
|
+
* @param {Object} [options={}] - Initializer object
|
|
39
|
+
* @param {Array} [options.accounts] - Accounts array
|
|
40
|
+
* @param {String} [options.address] - Address of account to select
|
|
41
|
+
* @return {Object} AccountMultiple instance
|
|
42
|
+
* @example
|
|
43
|
+
* const accounts = await AccountMultiple({
|
|
44
|
+
* accounts: [MemoryAccount({ keypair: 'keypair_object' })]
|
|
45
|
+
* })
|
|
46
|
+
* await accounts.addAccount(account, { select: true }) // Add account and make it selected
|
|
47
|
+
* accounts.removeAccount(address) // Remove account
|
|
48
|
+
* accounts.selectAccount(address) // Select account
|
|
49
|
+
* accounts.addresses() // Get available accounts
|
|
50
|
+
*/
|
|
51
|
+
|
|
52
|
+
export default AccountBase.compose(AsyncInit, {
|
|
53
|
+
async init(_ref) {
|
|
54
|
+
let {
|
|
55
|
+
accounts = [],
|
|
56
|
+
address
|
|
57
|
+
} = _ref;
|
|
58
|
+
this.accounts = Object.fromEntries(await Promise.all(accounts.map(async a => [await a.address(), a])));
|
|
59
|
+
address = address || Object.keys(this.accounts)[0];
|
|
60
|
+
if (address) this.selectAccount(address);
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
props: {
|
|
64
|
+
accounts: {}
|
|
65
|
+
},
|
|
66
|
+
deepProps: {
|
|
67
|
+
selectedAddress: null
|
|
68
|
+
},
|
|
69
|
+
methods: {
|
|
70
|
+
async address() {
|
|
71
|
+
let {
|
|
72
|
+
onAccount = this.selectedAddress
|
|
73
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
74
|
+
return this._resolveAccount(onAccount).address();
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
async sign(data) {
|
|
78
|
+
let {
|
|
79
|
+
onAccount = this.selectedAddress
|
|
80
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
81
|
+
return this._resolveAccount(onAccount).sign(data);
|
|
82
|
+
},
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Get accounts addresses
|
|
86
|
+
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
87
|
+
* @function
|
|
88
|
+
* @rtype () => String[]
|
|
89
|
+
* @return {String[]}
|
|
90
|
+
* @example addresses()
|
|
91
|
+
*/
|
|
92
|
+
addresses() {
|
|
93
|
+
return Object.keys(this.accounts);
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Add specific account
|
|
98
|
+
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
99
|
+
* @function
|
|
100
|
+
* @category async
|
|
101
|
+
* @rtype (account: Account, { select: Boolean }) => void
|
|
102
|
+
* @param {Object} account - Account instance
|
|
103
|
+
* @param {Object} [options={}] - Options
|
|
104
|
+
* @param {Boolean} [options.select] - Select account
|
|
105
|
+
* @return {void}
|
|
106
|
+
* @example addAccount(account)
|
|
107
|
+
*/
|
|
108
|
+
async addAccount(account) {
|
|
109
|
+
let {
|
|
110
|
+
select
|
|
111
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
112
|
+
const address = await account.address();
|
|
113
|
+
this.accounts[address] = account;
|
|
114
|
+
if (select) this.selectAccount(address);
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Remove specific account
|
|
119
|
+
* @alias module:@aeternity/aepp-sdk/es/accounts/multiple
|
|
120
|
+
* @function
|
|
121
|
+
* @rtype (address: String) => void
|
|
122
|
+
* @param {String} address - Address of account to remove
|
|
123
|
+
* @return {void}
|
|
124
|
+
* @example removeAccount(address)
|
|
125
|
+
*/
|
|
126
|
+
removeAccount(address) {
|
|
127
|
+
if (!this.accounts[address]) {
|
|
128
|
+
console.warn(`removeAccount: Account for ${address} not available`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
delete this.accounts[address];
|
|
133
|
+
if (this.selectedAddress === address) this.selectedAddress = null;
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Select specific account
|
|
138
|
+
* @alias module:@aeternity/aepp-sdk/es/account/selector
|
|
139
|
+
* @instance
|
|
140
|
+
* @rtype (address: String) => void
|
|
141
|
+
* @param {String} address - Address of account to select
|
|
142
|
+
* @example selectAccount('ak_xxxxxxxx')
|
|
143
|
+
*/
|
|
144
|
+
selectAccount(address) {
|
|
145
|
+
decode(address, 'ak');
|
|
146
|
+
if (!this.accounts[address]) throw new UnavailableAccountError(address);
|
|
147
|
+
this.selectedAddress = address;
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Resolves an account
|
|
152
|
+
* @param account account address (should exist in sdk instance), MemoryAccount or keypair
|
|
153
|
+
* @returns {AccountBase}
|
|
154
|
+
* @private
|
|
155
|
+
*/
|
|
156
|
+
_resolveAccount(account) {
|
|
157
|
+
if (account === null) {
|
|
158
|
+
throw new TypeError('Account should be an address (ak-prefixed string), ' + 'keypair, or instance of account base, got null instead');
|
|
159
|
+
} else {
|
|
160
|
+
switch (typeof account) {
|
|
161
|
+
case 'string':
|
|
162
|
+
decode(account, 'ak');
|
|
163
|
+
if (!this.accounts[account]) throw new UnavailableAccountError(account);
|
|
164
|
+
return this.accounts[account];
|
|
165
|
+
|
|
166
|
+
case 'object':
|
|
167
|
+
return isAccountBase(account) ? account : MemoryAccount({
|
|
168
|
+
keypair: account
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
default:
|
|
172
|
+
throw new TypeError('Account should be an address (ak-prefixed string), ' + `keypair, or instance of account base, got ${account} instead`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
//# sourceMappingURL=multiple.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/account/multiple.js"],"names":["AsyncInit","MemoryAccount","decode","AccountBase","isAccountBase","UnavailableAccountError","TypeError","compose","init","accounts","address","Object","fromEntries","Promise","all","map","a","keys","selectAccount","props","deepProps","selectedAddress","methods","onAccount","_resolveAccount","sign","data","addresses","addAccount","account","select","removeAccount","console","warn","keypair"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;OAEOA,S;OACAC,a;SACEC,M;OACFC,W,IAAeC,a;SAEpBC,uB,EACAC,S;AAGF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeH,WAAW,CAACI,OAAZ,CAAoBP,SAApB,EAA+B;AAC5C,QAAMQ,IAAN,OAAwC;AAAA,QAA5B;AAAEC,MAAAA,QAAQ,GAAG,EAAb;AAAiBC,MAAAA;AAAjB,KAA4B;AACtC,SAAKD,QAAL,GAAgBE,MAAM,CAACC,WAAP,CAAmB,MAAMC,OAAO,CAACC,GAAR,CACvCL,QAAQ,CAACM,GAAT,CAAa,MAAMC,CAAN,IAAW,CAAC,MAAMA,CAAC,CAACN,OAAF,EAAP,EAAoBM,CAApB,CAAxB,CADuC,CAAzB,CAAhB;AAGAN,IAAAA,OAAO,GAAGA,OAAO,IAAIC,MAAM,CAACM,IAAP,CAAY,KAAKR,QAAjB,EAA2B,CAA3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) 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 AsyncInit from '../utils/async-init'\nimport MemoryAccount from './memory'\nimport { decode } from '../tx/builder/helpers'\nimport AccountBase, { isAccountBase } from './base'\nimport {\n UnavailableAccountError,\n TypeError\n} from '../utils/errors'\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({\n * accounts: [MemoryAccount({ keypair: 'keypair_object' })]\n * })\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 this.accounts = Object.fromEntries(await Promise.all(\n accounts.map(async a => [await a.address(), a])\n ))\n address = address || Object.keys(this.accounts)[0]\n if (address) this.selectAccount(address)\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 UnavailableAccountError(address)\n this.selectedAddress = address\n },\n /**\n * Resolves an account\n * @param account account address (should exist in sdk instance), MemoryAccount or keypair\n * @returns {AccountBase}\n * @private\n */\n _resolveAccount (account) {\n if (account === null) {\n throw new TypeError(\n 'Account should be an address (ak-prefixed string), ' +\n 'keypair, or instance of account base, got null instead')\n } else {\n switch (typeof account) {\n case 'string':\n decode(account, 'ak')\n if (!this.accounts[account]) throw new UnavailableAccountError(account)\n return this.accounts[account]\n case 'object':\n return isAccountBase(account) ? account : MemoryAccount({ keypair: account })\n default:\n throw new TypeError(\n 'Account should be an address (ak-prefixed string), ' +\n `keypair, or instance of account base, got ${account} instead`)\n }\n }\n }\n }\n})\n"],"file":"multiple.mjs"}
|