@aeternity/aepp-sdk 8.2.0 → 10.0.0-beta.1
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 +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.js +33 -119
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +75 -154
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +164 -599
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +108 -916
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +89 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +132 -500
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +4 -23
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +292 -1018
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +203 -451
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +319 -491
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +129 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +102 -247
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +1 -1
- package/es/contract/index.js.map +1 -1
- package/es/index.js +2 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +54 -73
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +56 -157
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +49 -89
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +205 -303
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +585 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +1 -1
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +105 -135
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +17 -21
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +38 -74
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +14 -15
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +179 -510
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +70 -89
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +354 -603
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +49 -75
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +85 -218
- package/es/utils/swagger.js.map +1 -1
- package/package.json +52 -43
- package/src/account/base.js +8 -9
- package/src/account/multiple.js +20 -16
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +65 -246
- package/src/ae/index.js +31 -7
- package/src/ae/oracle.js +21 -17
- package/src/chain/index.js +2 -12
- package/src/chain/node.js +26 -29
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -106
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +2 -12
- package/src/contract/ga/index.js +22 -26
- package/src/index.js +2 -4
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/helpers.js +12 -24
- package/src/tx/builder/index.js +18 -15
- package/src/tx/builder/schema.js +43 -108
- package/src/tx/tx-object.js +0 -2
- package/src/tx/tx.js +157 -144
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +9 -10
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -17
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +24 -7
- package/CHANGELOG.md +0 -1716
- package/src/contract/aci/helpers.js +0 -140
package/es/account/base.js
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
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
1
|
/*
|
|
7
2
|
* ISC License (ISC)
|
|
8
3
|
* Copyright (c) 2018 aeternity developers
|
|
@@ -28,8 +23,8 @@ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/insta
|
|
|
28
23
|
*/
|
|
29
24
|
import stampit from '@stamp/it';
|
|
30
25
|
import { required } from '@stamp/required';
|
|
31
|
-
import { messageToHash,
|
|
32
|
-
import { buildTx
|
|
26
|
+
import { messageToHash, verifyMessage as verifyMessageCrypto, hash } from '../utils/crypto';
|
|
27
|
+
import { buildTx } from '../tx/builder';
|
|
33
28
|
import { decode } from '../tx/builder/helpers';
|
|
34
29
|
import { TX_TYPE } from '../tx/builder/schema';
|
|
35
30
|
import { getNetworkId } from '../node';
|
|
@@ -40,13 +35,7 @@ import { getNetworkId } from '../node';
|
|
|
40
35
|
* @return {Boolean}
|
|
41
36
|
*/
|
|
42
37
|
|
|
43
|
-
export
|
|
44
|
-
var _context;
|
|
45
|
-
|
|
46
|
-
return !_findInstanceProperty(_context = ['sign', 'address']).call(_context, function (f) {
|
|
47
|
-
return typeof acc[f] !== 'function';
|
|
48
|
-
});
|
|
49
|
-
};
|
|
38
|
+
export const isAccountBase = acc => !['sign', 'address'].find(f => typeof acc[f] !== 'function');
|
|
50
39
|
/**
|
|
51
40
|
* Sign encoded transaction
|
|
52
41
|
* @instance
|
|
@@ -54,11 +43,21 @@ export var isAccountBase = function isAccountBase(acc) {
|
|
|
54
43
|
* @rtype (tx: String) => tx: Promise[String], throws: Error
|
|
55
44
|
* @param {String} tx - Transaction to sign
|
|
56
45
|
* @param {Object} opt - Options
|
|
46
|
+
* @param {Object} [opt.innerTx] - Sign as inner transaction for PayingFor
|
|
57
47
|
* @return {String} Signed transaction
|
|
58
48
|
*/
|
|
59
49
|
|
|
60
|
-
function signTransaction(
|
|
61
|
-
|
|
50
|
+
async function signTransaction(tx) {
|
|
51
|
+
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
52
|
+
const prefixes = [this.getNetworkId(opt)];
|
|
53
|
+
if (opt.innerTx) prefixes.push('inner_tx');
|
|
54
|
+
const rlpBinaryTx = decode(tx, 'tx');
|
|
55
|
+
const txWithNetworkId = Buffer.concat([Buffer.from(prefixes.join('-')), hash(rlpBinaryTx)]);
|
|
56
|
+
const signatures = [await this.sign(txWithNetworkId, opt)];
|
|
57
|
+
return buildTx({
|
|
58
|
+
encodedTx: rlpBinaryTx,
|
|
59
|
+
signatures
|
|
60
|
+
}, TX_TYPE.signed).tx;
|
|
62
61
|
}
|
|
63
62
|
/**
|
|
64
63
|
* Get network Id
|
|
@@ -80,41 +79,12 @@ function signTransaction(_x, _x2) {
|
|
|
80
79
|
*/
|
|
81
80
|
|
|
82
81
|
|
|
83
|
-
function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
case 0:
|
|
90
|
-
networkId = this.getNetworkId(opt);
|
|
91
|
-
rlpBinaryTx = decodeBase64Check(assertedType(tx, 'tx'));
|
|
92
|
-
txWithNetworkId = _concatInstanceProperty(Buffer).call(Buffer, [Buffer.from(networkId), buildTxHash(rlpBinaryTx, {
|
|
93
|
-
raw: true
|
|
94
|
-
})]);
|
|
95
|
-
_context2.next = 5;
|
|
96
|
-
return this.sign(txWithNetworkId, opt);
|
|
97
|
-
|
|
98
|
-
case 5:
|
|
99
|
-
_context2.t0 = _context2.sent;
|
|
100
|
-
signatures = [_context2.t0];
|
|
101
|
-
return _context2.abrupt("return", buildTx({
|
|
102
|
-
encodedTx: rlpBinaryTx,
|
|
103
|
-
signatures: signatures
|
|
104
|
-
}, TX_TYPE.signed).tx);
|
|
105
|
-
|
|
106
|
-
case 8:
|
|
107
|
-
case "end":
|
|
108
|
-
return _context2.stop();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}, _callee, this);
|
|
112
|
-
}));
|
|
113
|
-
return _signTransaction.apply(this, arguments);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function signMessage(_x3) {
|
|
117
|
-
return _signMessage.apply(this, arguments);
|
|
82
|
+
async function signMessage(message) {
|
|
83
|
+
let opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
84
|
+
returnHex: false
|
|
85
|
+
};
|
|
86
|
+
const sig = await this.sign(messageToHash(message), opt);
|
|
87
|
+
return opt.returnHex ? Buffer.from(sig).toString('hex') : sig;
|
|
118
88
|
}
|
|
119
89
|
/**
|
|
120
90
|
* Verify message
|
|
@@ -128,37 +98,9 @@ function signMessage(_x3) {
|
|
|
128
98
|
*/
|
|
129
99
|
|
|
130
100
|
|
|
131
|
-
function
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
sig,
|
|
135
|
-
_args2 = arguments;
|
|
136
|
-
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
137
|
-
while (1) {
|
|
138
|
-
switch (_context3.prev = _context3.next) {
|
|
139
|
-
case 0:
|
|
140
|
-
opt = _args2.length > 1 && _args2[1] !== undefined ? _args2[1] : {
|
|
141
|
-
returnHex: false
|
|
142
|
-
};
|
|
143
|
-
_context3.next = 3;
|
|
144
|
-
return this.sign(messageToHash(message), opt);
|
|
145
|
-
|
|
146
|
-
case 3:
|
|
147
|
-
sig = _context3.sent;
|
|
148
|
-
return _context3.abrupt("return", opt.returnHex ? Buffer.from(sig).toString('hex') : sig);
|
|
149
|
-
|
|
150
|
-
case 5:
|
|
151
|
-
case "end":
|
|
152
|
-
return _context3.stop();
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}, _callee2, this);
|
|
156
|
-
}));
|
|
157
|
-
return _signMessage.apply(this, arguments);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
function verifyMessage(_x4, _x5) {
|
|
161
|
-
return _verifyMessage.apply(this, arguments);
|
|
101
|
+
async function verifyMessage(message, signature) {
|
|
102
|
+
let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
103
|
+
return verifyMessageCrypto(message, typeof signature === 'string' ? Buffer.from(signature, 'hex') : signature, decode(await this.address(opt)));
|
|
162
104
|
}
|
|
163
105
|
/**
|
|
164
106
|
* AccountBase Stamp
|
|
@@ -178,51 +120,23 @@ function verifyMessage(_x4, _x5) {
|
|
|
178
120
|
*/
|
|
179
121
|
|
|
180
122
|
|
|
181
|
-
function _verifyMessage() {
|
|
182
|
-
_verifyMessage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(message, signature) {
|
|
183
|
-
var opt,
|
|
184
|
-
_args3 = arguments;
|
|
185
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
186
|
-
while (1) {
|
|
187
|
-
switch (_context4.prev = _context4.next) {
|
|
188
|
-
case 0:
|
|
189
|
-
opt = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {};
|
|
190
|
-
_context4.t0 = verifyMessageCrypto;
|
|
191
|
-
_context4.t1 = message;
|
|
192
|
-
_context4.t2 = typeof signature === 'string' ? Buffer.from(signature, 'hex') : signature;
|
|
193
|
-
_context4.t3 = decode;
|
|
194
|
-
_context4.next = 7;
|
|
195
|
-
return this.address(opt);
|
|
196
|
-
|
|
197
|
-
case 7:
|
|
198
|
-
_context4.t4 = _context4.sent;
|
|
199
|
-
_context4.t5 = (0, _context4.t3)(_context4.t4);
|
|
200
|
-
return _context4.abrupt("return", (0, _context4.t0)(_context4.t1, _context4.t2, _context4.t5));
|
|
201
|
-
|
|
202
|
-
case 10:
|
|
203
|
-
case "end":
|
|
204
|
-
return _context4.stop();
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
}, _callee3, this);
|
|
208
|
-
}));
|
|
209
|
-
return _verifyMessage.apply(this, arguments);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
123
|
export default stampit({
|
|
213
|
-
init
|
|
214
|
-
|
|
124
|
+
init(_ref) {
|
|
125
|
+
let {
|
|
126
|
+
networkId
|
|
127
|
+
} = _ref;
|
|
215
128
|
|
|
216
129
|
// NETWORK_ID using for signing transaction's
|
|
217
130
|
if (!this.networkId && networkId) {
|
|
218
131
|
this.networkId = networkId;
|
|
219
132
|
}
|
|
220
133
|
},
|
|
134
|
+
|
|
221
135
|
methods: {
|
|
222
|
-
signTransaction
|
|
223
|
-
getNetworkId
|
|
224
|
-
signMessage
|
|
225
|
-
verifyMessage
|
|
136
|
+
signTransaction,
|
|
137
|
+
getNetworkId,
|
|
138
|
+
signMessage,
|
|
139
|
+
verifyMessage
|
|
226
140
|
}
|
|
227
141
|
}, required({
|
|
228
142
|
methods: {
|
package/es/account/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/account/base.js"],"names":["stampit","required","messageToHash","
|
|
1
|
+
{"version":3,"sources":["../../src/account/base.js"],"names":["stampit","required","messageToHash","verifyMessage","verifyMessageCrypto","hash","buildTx","decode","TX_TYPE","getNetworkId","isAccountBase","acc","find","f","signTransaction","tx","opt","prefixes","innerTx","push","rlpBinaryTx","txWithNetworkId","Buffer","concat","from","join","signatures","sign","encodedTx","signed","signMessage","message","returnHex","sig","toString","signature","address","init","networkId","methods"],"mappings":"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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 * 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
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
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
1
|
/*
|
|
7
2
|
* ISC License (ISC)
|
|
8
3
|
* Copyright (c) 2018 aeternity developers
|
|
@@ -27,10 +22,10 @@ import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
|
27
22
|
* @example import { MemoryAccount } from '@aeternity/aepp-sdk'
|
|
28
23
|
*/
|
|
29
24
|
import AccountBase from './base';
|
|
30
|
-
import { sign
|
|
25
|
+
import { sign, isAddressValid, isValidKeypair } from '../utils/crypto';
|
|
31
26
|
import { isHex } from '../utils/string';
|
|
32
27
|
import { decode } from '../tx/builder/helpers';
|
|
33
|
-
|
|
28
|
+
const secrets = new WeakMap();
|
|
34
29
|
/**
|
|
35
30
|
* In-memory account stamp
|
|
36
31
|
* @function
|
|
@@ -44,11 +39,11 @@ var secrets = new _WeakMap();
|
|
|
44
39
|
*/
|
|
45
40
|
|
|
46
41
|
export default AccountBase.compose({
|
|
47
|
-
init
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
init(_ref) {
|
|
43
|
+
let {
|
|
44
|
+
keypair,
|
|
45
|
+
gaId
|
|
46
|
+
} = _ref;
|
|
52
47
|
this.isGa = !!gaId;
|
|
53
48
|
|
|
54
49
|
if (gaId) {
|
|
@@ -59,28 +54,31 @@ export default AccountBase.compose({
|
|
|
59
54
|
return;
|
|
60
55
|
}
|
|
61
56
|
|
|
62
|
-
if (!keypair ||
|
|
57
|
+
if (!keypair || typeof keypair !== 'object') throw new Error('KeyPair must be an object');
|
|
63
58
|
if (!keypair.secretKey || !keypair.publicKey) throw new Error('KeyPair must must have "secretKey", "publicKey" properties');
|
|
64
|
-
if (typeof keypair.publicKey !== 'string' ||
|
|
59
|
+
if (typeof keypair.publicKey !== 'string' || keypair.publicKey.indexOf('ak_') === -1) throw new Error('Public Key must be a base58c string with "ak_" prefix');
|
|
65
60
|
if (!Buffer.isBuffer(keypair.secretKey) && typeof keypair.secretKey === 'string' && !isHex(keypair.secretKey)) throw new Error('Secret key must be hex string or Buffer');
|
|
66
|
-
|
|
61
|
+
const pubBuffer = Buffer.from(decode(keypair.publicKey, 'ak'));
|
|
67
62
|
if (!isValidKeypair(Buffer.from(keypair.secretKey, 'hex'), pubBuffer)) throw new Error('Invalid Key Pair');
|
|
68
63
|
secrets.set(this, {
|
|
69
64
|
secretKey: Buffer.isBuffer(keypair.secretKey) ? keypair.secretKey : Buffer.from(keypair.secretKey, 'hex'),
|
|
70
65
|
publicKey: keypair.publicKey
|
|
71
66
|
});
|
|
72
67
|
},
|
|
68
|
+
|
|
73
69
|
props: {
|
|
74
70
|
isGa: false
|
|
75
71
|
},
|
|
76
72
|
methods: {
|
|
77
|
-
sign
|
|
73
|
+
sign(data) {
|
|
78
74
|
if (this.isGa) throw new Error('You are trying to sign data using GA account without keypair');
|
|
79
|
-
return
|
|
75
|
+
return Promise.resolve(sign(data, secrets.get(this).secretKey));
|
|
80
76
|
},
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
|
|
78
|
+
address() {
|
|
79
|
+
return Promise.resolve(secrets.get(this).publicKey);
|
|
83
80
|
}
|
|
81
|
+
|
|
84
82
|
}
|
|
85
83
|
});
|
|
86
84
|
//# sourceMappingURL=memory.js.map
|
package/es/account/memory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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":"
|
|
1
|
+
{"version":3,"sources":["../../src/account/memory.js"],"names":["AccountBase","sign","isAddressValid","isValidKeypair","isHex","decode","secrets","WeakMap","compose","init","keypair","gaId","isGa","Error","set","publicKey","secretKey","indexOf","Buffer","isBuffer","pubBuffer","from","props","methods","data","Promise","resolve","get","address"],"mappings":"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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
CHANGED
|
@@ -1,14 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
*/
|
|
9
23
|
import AsyncInit from '../utils/async-init';
|
|
10
24
|
import MemoryAccount from './memory';
|
|
11
|
-
import {
|
|
25
|
+
import { decode } from '../tx/builder/helpers';
|
|
12
26
|
import AccountBase, { isAccountBase } from './base';
|
|
13
27
|
/**
|
|
14
28
|
* AccountMultiple stamp
|
|
@@ -33,61 +47,16 @@ import AccountBase, { isAccountBase } from './base';
|
|
|
33
47
|
*/
|
|
34
48
|
|
|
35
49
|
export default AccountBase.compose(AsyncInit, {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
switch (_context2.prev = _context2.next) {
|
|
45
|
-
case 0:
|
|
46
|
-
_ref$accounts = _ref.accounts, accounts = _ref$accounts === void 0 ? [] : _ref$accounts, address = _ref.address;
|
|
47
|
-
_context2.t0 = _fromPairs;
|
|
48
|
-
_context2.next = 4;
|
|
49
|
-
return _Promise.all(_mapInstanceProperty(accounts).call(accounts, /*#__PURE__*/function () {
|
|
50
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(a) {
|
|
51
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
52
|
-
while (1) {
|
|
53
|
-
switch (_context.prev = _context.next) {
|
|
54
|
-
case 0:
|
|
55
|
-
_context.next = 2;
|
|
56
|
-
return a.address();
|
|
57
|
-
|
|
58
|
-
case 2:
|
|
59
|
-
_context.t0 = _context.sent;
|
|
60
|
-
_context.t1 = a;
|
|
61
|
-
return _context.abrupt("return", [_context.t0, _context.t1]);
|
|
62
|
-
|
|
63
|
-
case 5:
|
|
64
|
-
case "end":
|
|
65
|
-
return _context.stop();
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}, _callee);
|
|
69
|
-
}));
|
|
70
|
-
|
|
71
|
-
return function (_x) {
|
|
72
|
-
return _ref2.apply(this, arguments);
|
|
73
|
-
};
|
|
74
|
-
}()));
|
|
75
|
-
|
|
76
|
-
case 4:
|
|
77
|
-
_context2.t1 = _context2.sent;
|
|
78
|
-
_this.accounts = (0, _context2.t0)(_context2.t1);
|
|
79
|
-
if (!address) address = _Object$keys(_this.accounts)[0];
|
|
80
|
-
assertedType(address, 'ak');
|
|
81
|
-
_this.selectedAddress = address;
|
|
82
|
-
|
|
83
|
-
case 9:
|
|
84
|
-
case "end":
|
|
85
|
-
return _context2.stop();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}, _callee2);
|
|
89
|
-
}))();
|
|
50
|
+
async init(_ref) {
|
|
51
|
+
let {
|
|
52
|
+
accounts = [],
|
|
53
|
+
address
|
|
54
|
+
} = _ref;
|
|
55
|
+
this.accounts = Object.fromEntries(await Promise.all(accounts.map(async a => [await a.address(), a])));
|
|
56
|
+
address = address || Object.keys(this.accounts)[0];
|
|
57
|
+
if (address) this.selectAccount(address);
|
|
90
58
|
},
|
|
59
|
+
|
|
91
60
|
props: {
|
|
92
61
|
accounts: {}
|
|
93
62
|
},
|
|
@@ -95,49 +64,18 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
95
64
|
selectedAddress: null
|
|
96
65
|
},
|
|
97
66
|
methods: {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
return
|
|
103
|
-
var _ref3, _ref3$onAccount, onAccount;
|
|
104
|
-
|
|
105
|
-
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
106
|
-
while (1) {
|
|
107
|
-
switch (_context3.prev = _context3.next) {
|
|
108
|
-
case 0:
|
|
109
|
-
_ref3 = _arguments.length > 0 && _arguments[0] !== undefined ? _arguments[0] : {}, _ref3$onAccount = _ref3.onAccount, onAccount = _ref3$onAccount === void 0 ? _this2.selectedAddress : _ref3$onAccount;
|
|
110
|
-
return _context3.abrupt("return", _this2._resolveAccount(onAccount).address());
|
|
111
|
-
|
|
112
|
-
case 2:
|
|
113
|
-
case "end":
|
|
114
|
-
return _context3.stop();
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
}, _callee3);
|
|
118
|
-
}))();
|
|
67
|
+
async address() {
|
|
68
|
+
let {
|
|
69
|
+
onAccount = this.selectedAddress
|
|
70
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
return this._resolveAccount(onAccount).address();
|
|
119
72
|
},
|
|
120
|
-
sign: function sign(data) {
|
|
121
|
-
var _arguments2 = arguments,
|
|
122
|
-
_this3 = this;
|
|
123
|
-
|
|
124
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
125
|
-
var _ref4, _ref4$onAccount, onAccount;
|
|
126
73
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return _context4.abrupt("return", _this3._resolveAccount(onAccount).sign(data));
|
|
133
|
-
|
|
134
|
-
case 2:
|
|
135
|
-
case "end":
|
|
136
|
-
return _context4.stop();
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}, _callee4);
|
|
140
|
-
}))();
|
|
74
|
+
async sign(data) {
|
|
75
|
+
let {
|
|
76
|
+
onAccount = this.selectedAddress
|
|
77
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
78
|
+
return this._resolveAccount(onAccount).sign(data);
|
|
141
79
|
},
|
|
142
80
|
|
|
143
81
|
/**
|
|
@@ -148,8 +86,8 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
148
86
|
* @return {String[]}
|
|
149
87
|
* @example addresses()
|
|
150
88
|
*/
|
|
151
|
-
addresses
|
|
152
|
-
return
|
|
89
|
+
addresses() {
|
|
90
|
+
return Object.keys(this.accounts);
|
|
153
91
|
},
|
|
154
92
|
|
|
155
93
|
/**
|
|
@@ -164,33 +102,13 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
164
102
|
* @return {void}
|
|
165
103
|
* @example addAccount(account)
|
|
166
104
|
*/
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
175
|
-
while (1) {
|
|
176
|
-
switch (_context5.prev = _context5.next) {
|
|
177
|
-
case 0:
|
|
178
|
-
_ref5 = _arguments3.length > 1 && _arguments3[1] !== undefined ? _arguments3[1] : {}, select = _ref5.select;
|
|
179
|
-
_context5.next = 3;
|
|
180
|
-
return account.address();
|
|
181
|
-
|
|
182
|
-
case 3:
|
|
183
|
-
address = _context5.sent;
|
|
184
|
-
_this4.accounts[address] = account;
|
|
185
|
-
if (select) _this4.selectAccount(address);
|
|
186
|
-
|
|
187
|
-
case 6:
|
|
188
|
-
case "end":
|
|
189
|
-
return _context5.stop();
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
}, _callee5);
|
|
193
|
-
}))();
|
|
105
|
+
async addAccount(account) {
|
|
106
|
+
let {
|
|
107
|
+
select
|
|
108
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
109
|
+
const address = await account.address();
|
|
110
|
+
this.accounts[address] = account;
|
|
111
|
+
if (select) this.selectAccount(address);
|
|
194
112
|
},
|
|
195
113
|
|
|
196
114
|
/**
|
|
@@ -202,9 +120,9 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
202
120
|
* @return {void}
|
|
203
121
|
* @example removeAccount(address)
|
|
204
122
|
*/
|
|
205
|
-
removeAccount
|
|
123
|
+
removeAccount(address) {
|
|
206
124
|
if (!this.accounts[address]) {
|
|
207
|
-
console.warn(
|
|
125
|
+
console.warn(`removeAccount: Account for ${address} not available`);
|
|
208
126
|
return;
|
|
209
127
|
}
|
|
210
128
|
|
|
@@ -220,9 +138,9 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
220
138
|
* @param {String} address - Address of account to select
|
|
221
139
|
* @example selectAccount('ak_xxxxxxxx')
|
|
222
140
|
*/
|
|
223
|
-
selectAccount
|
|
224
|
-
|
|
225
|
-
if (!this.accounts[address]) throw new Error(
|
|
141
|
+
selectAccount(address) {
|
|
142
|
+
decode(address, 'ak');
|
|
143
|
+
if (!this.accounts[address]) throw new Error(`Account for ${address} not available`);
|
|
226
144
|
this.selectedAddress = address;
|
|
227
145
|
},
|
|
228
146
|
|
|
@@ -232,24 +150,27 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
232
150
|
* @returns {AccountBase}
|
|
233
151
|
* @private
|
|
234
152
|
*/
|
|
235
|
-
_resolveAccount
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
153
|
+
_resolveAccount(account) {
|
|
154
|
+
if (account === null) {
|
|
155
|
+
throw new Error('No account or wallet configured');
|
|
156
|
+
} else {
|
|
157
|
+
switch (typeof account) {
|
|
158
|
+
case 'string':
|
|
159
|
+
decode(account, 'ak');
|
|
160
|
+
if (!this.accounts[account]) throw new Error(`Account for ${account} not available`);
|
|
161
|
+
return this.accounts[account];
|
|
162
|
+
|
|
163
|
+
case 'object':
|
|
164
|
+
return isAccountBase(account) ? account : MemoryAccount({
|
|
165
|
+
keypair: account
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
default:
|
|
169
|
+
throw new Error(`Unknown account type: ${typeof account} (account: ${account})`);
|
|
170
|
+
}
|
|
251
171
|
}
|
|
252
172
|
}
|
|
173
|
+
|
|
253
174
|
}
|
|
254
175
|
});
|
|
255
176
|
//# sourceMappingURL=multiple.js.map
|