@aeternity/aepp-sdk 9.0.1 → 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/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 +30 -122
- 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 +73 -164
- 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 +82 -759
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +78 -315
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +130 -498
- package/es/ae/oracle.js.map +1 -1
- package/es/chain/index.js +1 -1
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +288 -1008
- 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 -480
- 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 +16 -114
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +101 -242
- 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 +1 -2
- 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 +38 -75
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +196 -294
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +577 -459
- 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 -132
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +808 -1628
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +132 -268
- 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 +353 -600
- 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 +47 -62
- 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 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +44 -40
- package/src/account/multiple.js +18 -19
- package/src/ae/aens.js +25 -21
- package/src/ae/contract.js +32 -163
- package/src/ae/index.js +3 -3
- package/src/ae/oracle.js +18 -14
- package/src/chain/node.js +2 -4
- package/src/channel/handlers.js +0 -1
- package/src/channel/index.js +4 -5
- package/src/contract/aci/index.js +221 -102
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +45 -4
- package/src/contract/ga/helpers.js +1 -8
- package/src/contract/ga/index.js +13 -11
- package/src/index.js +0 -2
- package/src/node-pool/index.js +21 -12
- package/src/node.js +22 -26
- package/src/tx/builder/index.js +2 -1
- package/src/tx/builder/schema.js +2 -1
- package/src/tx/tx.js +147 -143
- package/src/tx/validator.js +9 -7
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +1 -3
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +3 -3
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +14 -7
- 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
|
|
@@ -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
|
|
@@ -58,8 +47,17 @@ export var isAccountBase = function isAccountBase(acc) {
|
|
|
58
47
|
* @return {String} Signed transaction
|
|
59
48
|
*/
|
|
60
49
|
|
|
61
|
-
function signTransaction(
|
|
62
|
-
|
|
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;
|
|
63
61
|
}
|
|
64
62
|
/**
|
|
65
63
|
* Get network Id
|
|
@@ -81,46 +79,12 @@ function signTransaction(_x) {
|
|
|
81
79
|
*/
|
|
82
80
|
|
|
83
81
|
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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);
|
|
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;
|
|
124
88
|
}
|
|
125
89
|
/**
|
|
126
90
|
* Verify message
|
|
@@ -134,37 +98,9 @@ function signMessage(_x2) {
|
|
|
134
98
|
*/
|
|
135
99
|
|
|
136
100
|
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
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);
|
|
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)));
|
|
168
104
|
}
|
|
169
105
|
/**
|
|
170
106
|
* AccountBase Stamp
|
|
@@ -184,51 +120,23 @@ function verifyMessage(_x3, _x4) {
|
|
|
184
120
|
*/
|
|
185
121
|
|
|
186
122
|
|
|
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
123
|
export default stampit({
|
|
219
|
-
init
|
|
220
|
-
|
|
124
|
+
init(_ref) {
|
|
125
|
+
let {
|
|
126
|
+
networkId
|
|
127
|
+
} = _ref;
|
|
221
128
|
|
|
222
129
|
// NETWORK_ID using for signing transaction's
|
|
223
130
|
if (!this.networkId && networkId) {
|
|
224
131
|
this.networkId = networkId;
|
|
225
132
|
}
|
|
226
133
|
},
|
|
134
|
+
|
|
227
135
|
methods: {
|
|
228
|
-
signTransaction
|
|
229
|
-
getNetworkId
|
|
230
|
-
signMessage
|
|
231
|
-
verifyMessage
|
|
136
|
+
signTransaction,
|
|
137
|
+
getNetworkId,
|
|
138
|
+
signMessage,
|
|
139
|
+
verifyMessage
|
|
232
140
|
}
|
|
233
141
|
}, required({
|
|
234
142
|
methods: {
|
package/es/account/base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","
|
|
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,12 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
*/
|
|
10
23
|
import AsyncInit from '../utils/async-init';
|
|
11
24
|
import MemoryAccount from './memory';
|
|
12
25
|
import { decode } from '../tx/builder/helpers';
|
|
@@ -34,72 +47,16 @@ import AccountBase, { isAccountBase } from './base';
|
|
|
34
47
|
*/
|
|
35
48
|
|
|
36
49
|
export default AccountBase.compose(AsyncInit, {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
}))();
|
|
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);
|
|
102
58
|
},
|
|
59
|
+
|
|
103
60
|
props: {
|
|
104
61
|
accounts: {}
|
|
105
62
|
},
|
|
@@ -107,49 +64,18 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
107
64
|
selectedAddress: null
|
|
108
65
|
},
|
|
109
66
|
methods: {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return
|
|
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
|
-
}))();
|
|
67
|
+
async address() {
|
|
68
|
+
let {
|
|
69
|
+
onAccount = this.selectedAddress
|
|
70
|
+
} = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
71
|
+
return this._resolveAccount(onAccount).address();
|
|
131
72
|
},
|
|
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
73
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
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
|
-
}))();
|
|
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);
|
|
153
79
|
},
|
|
154
80
|
|
|
155
81
|
/**
|
|
@@ -160,8 +86,8 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
160
86
|
* @return {String[]}
|
|
161
87
|
* @example addresses()
|
|
162
88
|
*/
|
|
163
|
-
addresses
|
|
164
|
-
return
|
|
89
|
+
addresses() {
|
|
90
|
+
return Object.keys(this.accounts);
|
|
165
91
|
},
|
|
166
92
|
|
|
167
93
|
/**
|
|
@@ -176,33 +102,13 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
176
102
|
* @return {void}
|
|
177
103
|
* @example addAccount(account)
|
|
178
104
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
}))();
|
|
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);
|
|
206
112
|
},
|
|
207
113
|
|
|
208
114
|
/**
|
|
@@ -214,9 +120,9 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
214
120
|
* @return {void}
|
|
215
121
|
* @example removeAccount(address)
|
|
216
122
|
*/
|
|
217
|
-
removeAccount
|
|
123
|
+
removeAccount(address) {
|
|
218
124
|
if (!this.accounts[address]) {
|
|
219
|
-
console.warn(
|
|
125
|
+
console.warn(`removeAccount: Account for ${address} not available`);
|
|
220
126
|
return;
|
|
221
127
|
}
|
|
222
128
|
|
|
@@ -232,9 +138,9 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
232
138
|
* @param {String} address - Address of account to select
|
|
233
139
|
* @example selectAccount('ak_xxxxxxxx')
|
|
234
140
|
*/
|
|
235
|
-
selectAccount
|
|
141
|
+
selectAccount(address) {
|
|
236
142
|
decode(address, 'ak');
|
|
237
|
-
if (!this.accounts[address]) throw new Error(
|
|
143
|
+
if (!this.accounts[address]) throw new Error(`Account for ${address} not available`);
|
|
238
144
|
this.selectedAddress = address;
|
|
239
145
|
},
|
|
240
146
|
|
|
@@ -244,24 +150,27 @@ export default AccountBase.compose(AsyncInit, {
|
|
|
244
150
|
* @returns {AccountBase}
|
|
245
151
|
* @private
|
|
246
152
|
*/
|
|
247
|
-
_resolveAccount
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
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
|
+
}
|
|
263
171
|
}
|
|
264
172
|
}
|
|
173
|
+
|
|
265
174
|
}
|
|
266
175
|
});
|
|
267
176
|
//# sourceMappingURL=multiple.js.map
|