@aeternity/aepp-sdk 8.2.1 → 10.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/CHANGELOG.md +216 -337
- 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 +36 -120
- 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 +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- 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 +238 -465
- 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 +328 -495
- 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 +131 -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 +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- 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 +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- 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 +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- 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 +41 -106
- 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 +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- 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,47 +79,20 @@ 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
|
|
121
91
|
* @instance
|
|
122
92
|
* @category async
|
|
123
|
-
* @rtype (
|
|
93
|
+
* @rtype (
|
|
94
|
+
* msg: String, signature: String, publicKey: String
|
|
95
|
+
* ) => signature: Promise[String], throws: Error
|
|
124
96
|
* @param {String} message - Message to verify
|
|
125
97
|
* @param {String} signature - Signature
|
|
126
98
|
* @param {Object} opt - Options
|
|
@@ -128,37 +100,9 @@ function signMessage(_x3) {
|
|
|
128
100
|
*/
|
|
129
101
|
|
|
130
102
|
|
|
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);
|
|
103
|
+
async function verifyMessage(message, signature) {
|
|
104
|
+
let opt = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
105
|
+
return verifyMessageCrypto(message, typeof signature === 'string' ? Buffer.from(signature, 'hex') : signature, decode(await this.address(opt)));
|
|
162
106
|
}
|
|
163
107
|
/**
|
|
164
108
|
* AccountBase Stamp
|
|
@@ -178,51 +122,23 @@ function verifyMessage(_x4, _x5) {
|
|
|
178
122
|
*/
|
|
179
123
|
|
|
180
124
|
|
|
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
125
|
export default stampit({
|
|
213
|
-
init
|
|
214
|
-
|
|
126
|
+
init(_ref) {
|
|
127
|
+
let {
|
|
128
|
+
networkId
|
|
129
|
+
} = _ref;
|
|
215
130
|
|
|
216
131
|
// NETWORK_ID using for signing transaction's
|
|
217
132
|
if (!this.networkId && networkId) {
|
|
218
133
|
this.networkId = networkId;
|
|
219
134
|
}
|
|
220
135
|
},
|
|
136
|
+
|
|
221
137
|
methods: {
|
|
222
|
-
signTransaction
|
|
223
|
-
getNetworkId
|
|
224
|
-
signMessage
|
|
225
|
-
verifyMessage
|
|
138
|
+
signTransaction,
|
|
139
|
+
getNetworkId,
|
|
140
|
+
signMessage,
|
|
141
|
+
verifyMessage
|
|
226
142
|
}
|
|
227
143
|
}, required({
|
|
228
144
|
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":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,OAAP,MAAoB,WAApB;AACA,SAASC,QAAT,QAAyB,iBAAzB;AACA,SAASC,aAAT,EAAwBC,aAAa,IAAIC,mBAAzC,EAA8DC,IAA9D,QAA0E,iBAA1E;AACA,SAASC,OAAT,QAAwB,eAAxB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AACA,SAASC,OAAT,QAAwB,sBAAxB;AACA,SAASC,YAAT,QAA6B,SAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,aAAa,GAAIC,GAAD,IAAS,CAAC,CAAC,MAAD,EAAS,SAAT,EAAoBC,IAApB,CAAyBC,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GAA1D;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe9B,aAAf,CAA8B4B,OAA9B,EAAuCI,SAAvC,EAA4D;AAAA,MAAVnB,GAAU,uEAAJ,EAAI;AAC1D,SAAOZ,mBAAmB,CACxB2B,OADwB,EAExB,OAAOI,SAAP,KAAqB,QAArB,GAAgCb,MAAM,CAACE,IAAP,CAAYW,SAAZ,EAAuB,KAAvB,CAAhC,GAAgEA,SAFxC,EAGxB5B,MAAM,CAAC,MAAM,KAAK6B,OAAL,CAAapB,GAAb,CAAP,CAHkB,CAA1B;AAKD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAehB,OAAO,CAAC;AACrBqC,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;AAAEzB,IAAAA,eAAF;AAAmBL,IAAAA,YAAnB;AAAiCqB,IAAAA,WAAjC;AAA8C3B,IAAAA;AAA9C;AANY,CAAD,EAOnBF,QAAQ,CAAC;AACVsC,EAAAA,OAAO,EAAE;AACPZ,IAAAA,IAAI,EAAE1B,QADC;AAEPmC,IAAAA,OAAO,EAAEnC;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.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":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA,OAAOA,WAAP,MAAwB,QAAxB;AACA,SAASC,IAAT,EAAeC,cAAf,EAA+BC,cAA/B,QAAqD,iBAArD;AACA,SAASC,KAAT,QAAsB,iBAAtB;AACA,SAASC,MAAT,QAAuB,uBAAvB;AAEA,MAAMC,OAAO,GAAG,IAAIC,OAAJ,EAAhB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAeP,WAAW,CAACQ,OAAZ,CAAoB;AACjCC,EAAAA,IAAI,OAAqB;AAAA,QAAnB;AAAEC,MAAAA,OAAF;AAAWC,MAAAA;AAAX,KAAmB;AACvB,SAAKC,IAAL,GAAY,CAAC,CAACD,IAAd;;AACA,QAAIA,IAAJ,EAAU;AACR,UAAI,CAACT,cAAc,CAACS,IAAD,CAAnB,EAA2B,MAAM,IAAIE,KAAJ,CAAU,oBAAV,CAAN;AAC3BP,MAAAA,OAAO,CAACQ,GAAR,CAAY,IAAZ,EAAkB;AAAEC,QAAAA,SAAS,EAAEJ;AAAb,OAAlB;AACA;AACD;;AAED,QAAI,CAACD,OAAD,IAAY,OAAOA,OAAP,KAAmB,QAAnC,EAA6C,MAAM,IAAIG,KAAJ,CAAU,2BAAV,CAAN;AAC7C,QAAI,CAACH,OAAO,CAACM,SAAT,IAAsB,CAACN,OAAO,CAACK,SAAnC,EAA8C,MAAM,IAAIF,KAAJ,CAAU,4DAAV,CAAN;AAC9C,QAAI,OAAOH,OAAO,CAACK,SAAf,KAA6B,QAA7B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B,CAApB,CAAP;AACD,KAJM;;AAKPY,IAAAA,OAAO,GAAI;AACT,aAAOH,OAAO,CAACC,OAAR,CAAgBpB,OAAO,CAACqB,GAAR,CAAY,IAAZ,EAAkBZ,SAAlC,CAAP;AACD;;AAPM;AA1BwB,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, 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"}
|