@aeternity/aepp-sdk 10.0.0-beta.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 +1603 -0
- package/dist/aepp-sdk.browser-script.js +1 -1
- 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 +3 -1
- package/es/account/base.js.map +1 -1
- package/es/account/multiple.js +4 -2
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +52 -38
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +9 -5
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +4 -3
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +4 -4
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +8 -4
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +15 -20
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +35 -14
- package/es/channel/index.js.map +1 -1
- package/es/contract/aci/index.js +12 -7
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/compiler.js +3 -1
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +6 -6
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +6 -2
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +6 -2
- package/es/contract/index.js.map +1 -1
- package/es/index.js +1 -0
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +4 -2
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +9 -4
- package/es/node.js.map +1 -1
- package/es/tx/builder/helpers.js +20 -33
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +13 -6
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +5 -4
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +101 -12
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +9 -3
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +15 -6
- 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 +10 -4
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +13 -5
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +57 -40
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/crypto.js +1 -40
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/swagger.js +3 -1
- package/es/utils/swagger.js.map +1 -1
- package/package.json +11 -13
- package/src/account/base.js +3 -1
- package/src/account/multiple.js +4 -2
- package/src/ae/aens.js +41 -42
- package/src/ae/contract.js +9 -5
- package/src/ae/index.js +4 -3
- package/src/ae/oracle.js +9 -5
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +8 -4
- package/src/chain/node.js +17 -14
- package/src/channel/handlers.js +10 -3
- package/src/channel/index.js +40 -15
- package/src/contract/aci/index.js +15 -8
- package/src/contract/compiler.js +6 -2
- package/src/contract/ga/helpers.js +5 -3
- package/src/contract/ga/index.js +6 -2
- package/src/contract/index.js +6 -2
- package/src/index.js +2 -0
- package/src/node-pool/index.js +4 -2
- package/src/node.js +7 -4
- package/src/tx/builder/helpers.js +20 -33
- package/src/tx/builder/index.js +49 -13
- package/src/tx/builder/schema.js +37 -14
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -6
- package/src/tx/tx.js +94 -28
- 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 +32 -9
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +53 -22
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/crypto.js +1 -52
- package/src/utils/keystore.js +10 -2
- package/src/utils/swagger.js +1 -1
package/src/tx/index.js
CHANGED
|
@@ -72,7 +72,15 @@ const Tx = stampit(required({
|
|
|
72
72
|
* @instance
|
|
73
73
|
* @abstract
|
|
74
74
|
* @category async
|
|
75
|
-
* @rtype ({
|
|
75
|
+
* @rtype ({
|
|
76
|
+
* sender?: String,
|
|
77
|
+
* recipientId: String,
|
|
78
|
+
* amount: Number,
|
|
79
|
+
* fee?: Number,
|
|
80
|
+
* ttl?: Number,
|
|
81
|
+
* nonce?: Number,
|
|
82
|
+
* payload?: String
|
|
83
|
+
* }) => tx: Promise[String]
|
|
76
84
|
* @param {Object} options - The object to extract properties from
|
|
77
85
|
* @return {String} `spend_tx` transaction
|
|
78
86
|
*/
|
|
@@ -83,7 +91,9 @@ const Tx = stampit(required({
|
|
|
83
91
|
* @instance
|
|
84
92
|
* @abstract
|
|
85
93
|
* @category async
|
|
86
|
-
* @rtype ({
|
|
94
|
+
* @rtype ({
|
|
95
|
+
* account?: String, commitment: String, fee?: Number, ttl?: Number, nonce?: Number
|
|
96
|
+
* }) => tx: Promise[String]
|
|
87
97
|
* @param {Object} options - The object to extract properties from
|
|
88
98
|
* @return {String} `name_preclaim_tx` transaction
|
|
89
99
|
*/
|
|
@@ -94,7 +104,9 @@ const Tx = stampit(required({
|
|
|
94
104
|
* @instance
|
|
95
105
|
* @abstract
|
|
96
106
|
* @category async
|
|
97
|
-
* @rtype ({
|
|
107
|
+
* @rtype ({
|
|
108
|
+
* account?: String, name: String, nameSalt: String, fee?: Number, ttl?: Number, nonce?: Number
|
|
109
|
+
* }) => tx: Promise[String]
|
|
98
110
|
* @param {Object} options - The object to extract properties from
|
|
99
111
|
* @return {String} `name_claim_tx` transaction
|
|
100
112
|
*/
|
|
@@ -105,7 +117,14 @@ const Tx = stampit(required({
|
|
|
105
117
|
* @instance
|
|
106
118
|
* @abstract
|
|
107
119
|
* @category async
|
|
108
|
-
* @rtype ({
|
|
120
|
+
* @rtype ({
|
|
121
|
+
* account?: String,
|
|
122
|
+
* nameId: String,
|
|
123
|
+
* recipientId: String,
|
|
124
|
+
* fee?: Number,
|
|
125
|
+
* ttl?: Number,
|
|
126
|
+
* nonce?: Number
|
|
127
|
+
* }) => tx: Promise[String]
|
|
109
128
|
* @param {Object} options - The object to extract properties from
|
|
110
129
|
* @return {String} `name_transfer_tx` transaction
|
|
111
130
|
*/
|
|
@@ -116,7 +135,16 @@ const Tx = stampit(required({
|
|
|
116
135
|
* @instance
|
|
117
136
|
* @abstract
|
|
118
137
|
* @category async
|
|
119
|
-
* @rtype ({
|
|
138
|
+
* @rtype ({
|
|
139
|
+
* account?: String,
|
|
140
|
+
* nameId: String,
|
|
141
|
+
* pointers: Object,
|
|
142
|
+
* nameTtl: Number,
|
|
143
|
+
* clientTtl: Number,
|
|
144
|
+
* fee?: Number,
|
|
145
|
+
* ttl?: Number,
|
|
146
|
+
* nonce?: Number
|
|
147
|
+
* }) => tx: Promise[String]
|
|
120
148
|
* @param {Object} options - The object to extract properties from
|
|
121
149
|
* @return {String} `name_update_tx` transaction
|
|
122
150
|
*/
|
|
@@ -127,7 +155,9 @@ const Tx = stampit(required({
|
|
|
127
155
|
* @instance
|
|
128
156
|
* @abstract
|
|
129
157
|
* @category async
|
|
130
|
-
* @rtype ({
|
|
158
|
+
* @rtype ({
|
|
159
|
+
* account?: String, nameId: String, fee?: Number, ttl?: Number, nonce?: Number
|
|
160
|
+
* }) => tx: Promise[String]
|
|
131
161
|
* @param {Object} options - The object to extract properties from
|
|
132
162
|
* @return {String} `name_revoke_tx` transaction
|
|
133
163
|
*/
|
|
@@ -138,7 +168,19 @@ const Tx = stampit(required({
|
|
|
138
168
|
* @instance
|
|
139
169
|
* @abstract
|
|
140
170
|
* @category async
|
|
141
|
-
* @rtype ({
|
|
171
|
+
* @rtype ({
|
|
172
|
+
* owner: String,
|
|
173
|
+
* code: String,
|
|
174
|
+
* callData: String,
|
|
175
|
+
* vmVersion: Number,
|
|
176
|
+
* deposit: Number,
|
|
177
|
+
* amount: Number,
|
|
178
|
+
* gas: Number,
|
|
179
|
+
* gasPrice: Number,
|
|
180
|
+
* fee?: Number,
|
|
181
|
+
* ttl?: Number,
|
|
182
|
+
* nonce?: Number
|
|
183
|
+
* }) => tx: Promise[String]
|
|
142
184
|
* @param {Object} options - The object to extract properties from
|
|
143
185
|
* @return {String} `contract_create_tx` transaction
|
|
144
186
|
*/
|
|
@@ -149,7 +191,18 @@ const Tx = stampit(required({
|
|
|
149
191
|
* @instance
|
|
150
192
|
* @abstract
|
|
151
193
|
* @category async
|
|
152
|
-
* @rtype ({
|
|
194
|
+
* @rtype ({
|
|
195
|
+
* callerId: String,
|
|
196
|
+
* contract: String,
|
|
197
|
+
* callData: String,
|
|
198
|
+
* vmVersion: Number,
|
|
199
|
+
* amount: Number,
|
|
200
|
+
* gas: Number,
|
|
201
|
+
* gasPrice: Number,
|
|
202
|
+
* fee?: Number,
|
|
203
|
+
* ttl?: Number,
|
|
204
|
+
* nonce?: Number
|
|
205
|
+
* }) => tx: Promise[String]
|
|
153
206
|
* @param {Object} options - The object to extract properties from
|
|
154
207
|
* @return {String} `contract_call_tx` transaction
|
|
155
208
|
*/
|
|
@@ -160,7 +213,17 @@ const Tx = stampit(required({
|
|
|
160
213
|
* @instance
|
|
161
214
|
* @abstract
|
|
162
215
|
* @category async
|
|
163
|
-
* @rtype ({
|
|
216
|
+
* @rtype ({
|
|
217
|
+
* accountId: String,
|
|
218
|
+
* queryFormat: String,
|
|
219
|
+
* responseFormat: String,
|
|
220
|
+
* queryFee: String|Number,
|
|
221
|
+
* oracleTtl: Object,
|
|
222
|
+
* vmVersion: Number = ORACLE_VM_VERSION,
|
|
223
|
+
* fee?: Number,
|
|
224
|
+
* ttl?: Number,
|
|
225
|
+
* nonce?: Number
|
|
226
|
+
* }) => tx: Promise[String]
|
|
164
227
|
* @param {Object} options - The object to extract properties from
|
|
165
228
|
* @return {String} `oracle_register_tx` transaction
|
|
166
229
|
*/
|
|
@@ -171,7 +234,14 @@ const Tx = stampit(required({
|
|
|
171
234
|
* @instance
|
|
172
235
|
* @abstract
|
|
173
236
|
* @category async
|
|
174
|
-
* @rtype ({
|
|
237
|
+
* @rtype ({
|
|
238
|
+
* oracleId: String,
|
|
239
|
+
* callerId: String,
|
|
240
|
+
* oracleTtl: Object,
|
|
241
|
+
* fee?: Number,
|
|
242
|
+
* ttl: Number,
|
|
243
|
+
* nonce?: Number
|
|
244
|
+
* }) => tx: Promise[String]
|
|
175
245
|
* @param {Object} options - The object to extract properties from
|
|
176
246
|
* @return {String} `oracle_extend_tx` transaction
|
|
177
247
|
*/
|
|
@@ -182,7 +252,17 @@ const Tx = stampit(required({
|
|
|
182
252
|
* @instance
|
|
183
253
|
* @abstract
|
|
184
254
|
* @category async
|
|
185
|
-
* @rtype ({
|
|
255
|
+
* @rtype ({
|
|
256
|
+
* oracleId: String,
|
|
257
|
+
* responseTtl: Object,
|
|
258
|
+
* query: String,
|
|
259
|
+
* queryTtl: Object,
|
|
260
|
+
* queryFee: String|Number,
|
|
261
|
+
* senderId: String,
|
|
262
|
+
* fee?: Number,
|
|
263
|
+
* ttl: Number,
|
|
264
|
+
* nonce?: Number
|
|
265
|
+
* }) => tx: Promise[String]
|
|
186
266
|
* @param {Object} options - The object to extract properties from
|
|
187
267
|
* @return {String} `oracle_post_query_tx` transaction
|
|
188
268
|
*/
|
|
@@ -193,7 +273,16 @@ const Tx = stampit(required({
|
|
|
193
273
|
* @instance
|
|
194
274
|
* @abstract
|
|
195
275
|
* @category async
|
|
196
|
-
* @rtype ({
|
|
276
|
+
* @rtype ({
|
|
277
|
+
* oracleId: String,
|
|
278
|
+
* callerId: String,
|
|
279
|
+
* responseTtl: Object,
|
|
280
|
+
* queryId: String,
|
|
281
|
+
* response: String,
|
|
282
|
+
* fee?: Number,
|
|
283
|
+
* ttl?: Number,
|
|
284
|
+
* nonce?: Number
|
|
285
|
+
* }) => tx: Promise[String]
|
|
197
286
|
* @param {Object} options - The object to extract properties from
|
|
198
287
|
* @return {String} `oracle_respond_tx` transaction
|
|
199
288
|
*/
|
package/src/tx/tx-object.js
CHANGED
|
@@ -17,13 +17,17 @@ import { isHex } from '../utils/string'
|
|
|
17
17
|
* @param {Object} params Transaction params
|
|
18
18
|
* @param {Object} [options={}] Options
|
|
19
19
|
* @throws {Error} Arguments validation error's
|
|
20
|
-
* @return {{
|
|
20
|
+
* @return {{
|
|
21
|
+
* encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, params: Object, type: String
|
|
22
|
+
* }}
|
|
21
23
|
*/
|
|
22
24
|
const buildTransaction = (type, params, options = {}) => {
|
|
23
25
|
if (typeof params !== 'object') throw new Error('"params" should be an object')
|
|
24
26
|
if (typeof type !== 'string' || !Object.values(TX_TYPE).includes(type)) throw new Error(`Unknown transaction type ${type}`)
|
|
25
27
|
const fee = calculateFee(params.fee, type, { gas: params.gas, params, vsn: params.vsn })
|
|
26
|
-
const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx(
|
|
28
|
+
const { rlpEncoded, binary, tx: encodedTx, txObject } = buildTx(
|
|
29
|
+
{ ...params, fee }, type, { vsn: params.vsn, ...options }
|
|
30
|
+
)
|
|
27
31
|
return { rlpEncoded, binary, encodedTx, params: txObject, type }
|
|
28
32
|
}
|
|
29
33
|
|
|
@@ -32,7 +36,9 @@ const buildTransaction = (type, params, options = {}) => {
|
|
|
32
36
|
* @alias module:@aeternity/aepp-sdk/es/tx/tx-object
|
|
33
37
|
* @param {Buffer|String} tx RLP encoded binary or base64c(rlpBinary) string
|
|
34
38
|
* @throws {Error} Arguments validation error's
|
|
35
|
-
* @return {{
|
|
39
|
+
* @return {{
|
|
40
|
+
* encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object
|
|
41
|
+
* }}
|
|
36
42
|
*/
|
|
37
43
|
const unpackTransaction = (tx) => {
|
|
38
44
|
if (!tx) throw new Error(`Invalid transaction: ${tx}`)
|
|
@@ -55,7 +61,9 @@ const unpackTransaction = (tx) => {
|
|
|
55
61
|
* @param {String} type Transaction type
|
|
56
62
|
* @param {Object} [options={}] Options
|
|
57
63
|
* @throws {Error} Arguments validation error's
|
|
58
|
-
* @return {{
|
|
64
|
+
* @return {{
|
|
65
|
+
* encodedTx: String, binary: Array<Buffer>, rlpEncoded: Buffer, type: String, params: Object
|
|
66
|
+
* }}
|
|
59
67
|
*/
|
|
60
68
|
const initTransaction = ({ tx, params, type, options = {} } = {}) => {
|
|
61
69
|
if (params && type) return buildTransaction(type, params, options)
|
|
@@ -122,7 +130,12 @@ export const TxObject = stampit({
|
|
|
122
130
|
if (typeof props !== 'object') throw new Error('Props should be an object')
|
|
123
131
|
this.isSigned = false
|
|
124
132
|
this.signatures = []
|
|
125
|
-
Object.assign(
|
|
133
|
+
Object.assign(
|
|
134
|
+
this,
|
|
135
|
+
buildTransaction(
|
|
136
|
+
this.type, { ...this.params, ...props, fee: null }, { ...this.options, ...options }
|
|
137
|
+
)
|
|
138
|
+
)
|
|
126
139
|
return this
|
|
127
140
|
},
|
|
128
141
|
/**
|
|
@@ -143,7 +156,13 @@ export const TxObject = stampit({
|
|
|
143
156
|
addSignature (signature) {
|
|
144
157
|
signature = isHex(signature) ? Buffer.from(signature, 'hex') : signature
|
|
145
158
|
if (!Buffer.isBuffer(signature) && !(signature instanceof Uint8Array)) throw new Error('Invalid signature, signature must be of type Buffer or Uint8Array')
|
|
146
|
-
Object.assign(
|
|
159
|
+
Object.assign(
|
|
160
|
+
this,
|
|
161
|
+
buildTransaction(
|
|
162
|
+
TX_TYPE.signed,
|
|
163
|
+
{ encodedTx: this.rlpEncoded, signatures: [[...this.signatures, signature]] }
|
|
164
|
+
)
|
|
165
|
+
)
|
|
147
166
|
|
|
148
167
|
const { signatures, encodedTx: { txType, tx } } = this.params
|
|
149
168
|
this.signatures = signatures
|
package/src/tx/tx.js
CHANGED
|
@@ -31,7 +31,9 @@ import { TxObject } from './tx-object'
|
|
|
31
31
|
|
|
32
32
|
async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
|
|
33
33
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
34
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
34
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
35
|
+
TX_TYPE.spend, { senderId, ...arguments[0], payload }
|
|
36
|
+
)
|
|
35
37
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
36
38
|
const { tx } = this.nativeMode
|
|
37
39
|
? {
|
|
@@ -63,7 +65,9 @@ async function spendTx ({ senderId, recipientId, amount, payload = '' }) {
|
|
|
63
65
|
|
|
64
66
|
async function namePreclaimTx ({ accountId, commitmentId }) {
|
|
65
67
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
66
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
68
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
69
|
+
TX_TYPE.namePreClaim, { senderId: accountId, ...arguments[0] }
|
|
70
|
+
)
|
|
67
71
|
|
|
68
72
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
69
73
|
const { tx } = this.nativeMode
|
|
@@ -80,7 +84,9 @@ async function namePreclaimTx ({ accountId, commitmentId }) {
|
|
|
80
84
|
|
|
81
85
|
async function nameClaimTx ({ accountId, name, nameSalt, vsn = 2 }) {
|
|
82
86
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
83
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
87
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
88
|
+
TX_TYPE.nameClaim, { senderId: accountId, ...arguments[0], vsn }
|
|
89
|
+
)
|
|
84
90
|
|
|
85
91
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
86
92
|
const { tx } = this.nativeMode
|
|
@@ -97,7 +103,9 @@ async function nameClaimTx ({ accountId, name, nameSalt, vsn = 2 }) {
|
|
|
97
103
|
|
|
98
104
|
async function nameTransferTx ({ accountId, nameId, recipientId }) {
|
|
99
105
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
100
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
106
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
107
|
+
TX_TYPE.nameTransfer, { senderId: accountId, ...arguments[0] }
|
|
108
|
+
)
|
|
101
109
|
|
|
102
110
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
103
111
|
const { tx } = this.nativeMode
|
|
@@ -107,14 +115,18 @@ async function nameTransferTx ({ accountId, nameId, recipientId }) {
|
|
|
107
115
|
type: TX_TYPE.nameTransfer
|
|
108
116
|
}).encodedTx
|
|
109
117
|
}
|
|
110
|
-
: await this.api.postNameTransfer({
|
|
118
|
+
: await this.api.postNameTransfer({
|
|
119
|
+
...arguments[0], recipientId, nonce, ttl, fee: parseInt(fee)
|
|
120
|
+
})
|
|
111
121
|
|
|
112
122
|
return tx
|
|
113
123
|
}
|
|
114
124
|
|
|
115
125
|
async function nameUpdateTx ({ accountId, nameId, nameTtl, pointers, clientTtl }) {
|
|
116
126
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
117
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
127
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
128
|
+
TX_TYPE.nameUpdate, { senderId: accountId, ...arguments[0] }
|
|
129
|
+
)
|
|
118
130
|
|
|
119
131
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
120
132
|
const { tx } = this.nativeMode
|
|
@@ -131,7 +143,9 @@ async function nameUpdateTx ({ accountId, nameId, nameTtl, pointers, clientTtl }
|
|
|
131
143
|
|
|
132
144
|
async function nameRevokeTx ({ accountId, nameId }) {
|
|
133
145
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
134
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
146
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
147
|
+
TX_TYPE.nameRevoke, { senderId: accountId, ...arguments[0] }
|
|
148
|
+
)
|
|
135
149
|
|
|
136
150
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
137
151
|
const { tx } = this.nativeMode
|
|
@@ -146,11 +160,15 @@ async function nameRevokeTx ({ accountId, nameId }) {
|
|
|
146
160
|
return tx
|
|
147
161
|
}
|
|
148
162
|
|
|
149
|
-
async function contractCreateTx ({
|
|
163
|
+
async function contractCreateTx ({
|
|
164
|
+
ownerId, code, vmVersion, abiVersion, deposit, amount, gas, gasPrice = MIN_GAS_PRICE, callData
|
|
165
|
+
}) {
|
|
150
166
|
// Get VM_ABI version
|
|
151
167
|
const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
|
|
152
168
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
153
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
169
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
170
|
+
TX_TYPE.contractCreate, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice }
|
|
171
|
+
)
|
|
154
172
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
155
173
|
return this.nativeMode
|
|
156
174
|
? {
|
|
@@ -160,13 +178,27 @@ async function contractCreateTx ({ ownerId, code, vmVersion, abiVersion, deposit
|
|
|
160
178
|
}).encodedTx,
|
|
161
179
|
contractId: buildContractId(ownerId, nonce)
|
|
162
180
|
}
|
|
163
|
-
: this.api.postContractCreate({
|
|
181
|
+
: this.api.postContractCreate({
|
|
182
|
+
...arguments[0],
|
|
183
|
+
nonce,
|
|
184
|
+
ttl,
|
|
185
|
+
fee: parseInt(fee),
|
|
186
|
+
gas: parseInt(gas),
|
|
187
|
+
gasPrice,
|
|
188
|
+
vmVersion: ctVersion.vmVersion,
|
|
189
|
+
abiVersion: ctVersion.abiVersion
|
|
190
|
+
})
|
|
164
191
|
}
|
|
165
192
|
|
|
166
|
-
async function contractCallTx ({
|
|
193
|
+
async function contractCallTx ({
|
|
194
|
+
callerId, contractId, abiVersion, amount, gas, gasPrice = MIN_GAS_PRICE, callData
|
|
195
|
+
}) {
|
|
167
196
|
const ctVersion = this.getVmVersion(TX_TYPE.contractCall, arguments[0])
|
|
168
197
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
169
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
198
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
199
|
+
TX_TYPE.contractCall,
|
|
200
|
+
{ senderId: callerId, ...arguments[0], gasPrice, abiVersion: ctVersion.abiVersion }
|
|
201
|
+
)
|
|
170
202
|
|
|
171
203
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
172
204
|
const { tx } = this.nativeMode
|
|
@@ -189,10 +221,14 @@ async function contractCallTx ({ callerId, contractId, abiVersion, amount, gas,
|
|
|
189
221
|
return tx
|
|
190
222
|
}
|
|
191
223
|
|
|
192
|
-
async function oracleRegisterTx ({
|
|
224
|
+
async function oracleRegisterTx ({
|
|
225
|
+
accountId, queryFormat, responseFormat, queryFee, oracleTtl, abiVersion = ABI_VERSIONS.NO_ABI
|
|
226
|
+
}) {
|
|
193
227
|
// const { abiVersion: abi } = this.getVmVersion(TX_TYPE.oracleRegister, arguments[0])
|
|
194
228
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
195
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
229
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
230
|
+
TX_TYPE.oracleRegister, { senderId: accountId, ...arguments[0], abiVersion }
|
|
231
|
+
)
|
|
196
232
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
197
233
|
const { tx } = this.nativeMode
|
|
198
234
|
? {
|
|
@@ -228,7 +264,9 @@ async function oracleRegisterTx ({ accountId, queryFormat, responseFormat, query
|
|
|
228
264
|
|
|
229
265
|
async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
|
|
230
266
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
231
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
267
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
268
|
+
TX_TYPE.oracleExtend, { senderId: callerId, ...arguments[0] }
|
|
269
|
+
)
|
|
232
270
|
|
|
233
271
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
234
272
|
const { tx } = this.nativeMode
|
|
@@ -245,7 +283,9 @@ async function oracleExtendTx ({ oracleId, callerId, oracleTtl }) {
|
|
|
245
283
|
|
|
246
284
|
async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, queryFee, senderId }) {
|
|
247
285
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
248
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
286
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
287
|
+
TX_TYPE.oracleQuery, { senderId, ...arguments[0] }
|
|
288
|
+
)
|
|
249
289
|
|
|
250
290
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
251
291
|
const { tx } = this.nativeMode
|
|
@@ -272,7 +312,9 @@ async function oraclePostQueryTx ({ oracleId, responseTtl, query, queryTtl, quer
|
|
|
272
312
|
|
|
273
313
|
async function oracleRespondTx ({ oracleId, callerId, responseTtl, queryId, response }) {
|
|
274
314
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
275
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
315
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
316
|
+
TX_TYPE.oracleResponse, { senderId: callerId, ...arguments[0] }
|
|
317
|
+
)
|
|
276
318
|
|
|
277
319
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
278
320
|
const { tx } = this.nativeMode
|
|
@@ -282,13 +324,17 @@ async function oracleRespondTx ({ oracleId, callerId, responseTtl, queryId, resp
|
|
|
282
324
|
type: TX_TYPE.oracleResponse
|
|
283
325
|
}).encodedTx
|
|
284
326
|
}
|
|
285
|
-
: await this.api.postOracleRespond({
|
|
327
|
+
: await this.api.postOracleRespond({
|
|
328
|
+
oracleId, responseTtl, queryId, response, fee: parseInt(fee), ttl, nonce
|
|
329
|
+
})
|
|
286
330
|
return tx
|
|
287
331
|
}
|
|
288
332
|
|
|
289
333
|
async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
|
|
290
334
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
291
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
335
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
336
|
+
TX_TYPE.channelCloseSolo, { senderId: fromId, ...arguments[0], payload }
|
|
337
|
+
)
|
|
292
338
|
|
|
293
339
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
294
340
|
const { tx } = this.nativeMode
|
|
@@ -318,7 +364,9 @@ async function channelCloseSoloTx ({ channelId, fromId, payload, poi }) {
|
|
|
318
364
|
|
|
319
365
|
async function channelSlashTx ({ channelId, fromId, payload, poi }) {
|
|
320
366
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
321
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
367
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
368
|
+
TX_TYPE.channelSlash, { senderId: fromId, ...arguments[0], payload }
|
|
369
|
+
)
|
|
322
370
|
|
|
323
371
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
324
372
|
const { tx } = this.nativeMode
|
|
@@ -348,7 +396,9 @@ async function channelSlashTx ({ channelId, fromId, payload, poi }) {
|
|
|
348
396
|
|
|
349
397
|
async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, responderAmountFinal }) {
|
|
350
398
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
351
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
399
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
400
|
+
TX_TYPE.channelSettle, { senderId: fromId, ...arguments[0] }
|
|
401
|
+
)
|
|
352
402
|
|
|
353
403
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
354
404
|
const { tx } = this.nativeMode
|
|
@@ -378,7 +428,9 @@ async function channelSettleTx ({ channelId, fromId, initiatorAmountFinal, respo
|
|
|
378
428
|
|
|
379
429
|
async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
|
|
380
430
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
381
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
431
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
432
|
+
TX_TYPE.channelSnapshotSolo, { senderId: fromId, ...arguments[0], payload }
|
|
433
|
+
)
|
|
382
434
|
|
|
383
435
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
384
436
|
const { tx } = this.nativeMode
|
|
@@ -404,11 +456,15 @@ async function channelSnapshotSoloTx ({ channelId, fromId, payload }) {
|
|
|
404
456
|
return tx
|
|
405
457
|
}
|
|
406
458
|
|
|
407
|
-
async function gaAttachTx ({
|
|
459
|
+
async function gaAttachTx ({
|
|
460
|
+
ownerId, code, vmVersion, abiVersion, authFun, gas, gasPrice = MIN_GAS_PRICE, callData
|
|
461
|
+
}) {
|
|
408
462
|
// Get VM_ABI version
|
|
409
463
|
const ctVersion = this.getVmVersion(TX_TYPE.contractCreate, arguments[0])
|
|
410
464
|
// Calculate fee, get absolute ttl (ttl + height), get account nonce
|
|
411
|
-
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
465
|
+
const { fee, ttl, nonce } = await this.prepareTxParams(
|
|
466
|
+
TX_TYPE.gaAttach, { senderId: ownerId, ...arguments[0], ctVersion, gasPrice }
|
|
467
|
+
)
|
|
412
468
|
// Build transaction using sdk (if nativeMode) or build on `AETERNITY NODE` side
|
|
413
469
|
return {
|
|
414
470
|
tx: TxObject({
|
|
@@ -480,7 +536,8 @@ async function calculateTtl (ttl = TX_TTL, relative = true) {
|
|
|
480
536
|
*/
|
|
481
537
|
async function getAccountNonce (accountId, nonce) {
|
|
482
538
|
if (nonce) return nonce
|
|
483
|
-
const { nonce: accountNonce } = await this.api.getAccountByPubkey(accountId)
|
|
539
|
+
const { nonce: accountNonce } = await this.api.getAccountByPubkey(accountId)
|
|
540
|
+
.catch(() => ({ nonce: 0 }))
|
|
484
541
|
return accountNonce + 1
|
|
485
542
|
}
|
|
486
543
|
|
|
@@ -491,10 +548,19 @@ async function getAccountNonce (accountId, nonce) {
|
|
|
491
548
|
* @param {Object} params Object which contains all tx data
|
|
492
549
|
* @return {Object} { ttl, nonce, fee } Object with account nonce, absolute ttl and transaction fee
|
|
493
550
|
*/
|
|
494
|
-
async function prepareTxParams (
|
|
495
|
-
|
|
551
|
+
async function prepareTxParams (
|
|
552
|
+
txType,
|
|
553
|
+
{ senderId, nonce: n, ttl: t, fee: f, gas, absoluteTtl, vsn, strategy }
|
|
554
|
+
) {
|
|
555
|
+
n = n || (
|
|
556
|
+
await this.api.getAccountNextNonce(senderId, { strategy }).catch(e => ({ nextNonce: 1 }))
|
|
557
|
+
).nextNonce
|
|
496
558
|
const ttl = await calculateTtl.call(this, t, !absoluteTtl)
|
|
497
|
-
const fee = calculateFee(
|
|
559
|
+
const fee = calculateFee(
|
|
560
|
+
f,
|
|
561
|
+
txType,
|
|
562
|
+
{ showWarning: this.showWarning, gas, params: { ...arguments[1], nonce: n, ttl }, vsn }
|
|
563
|
+
)
|
|
498
564
|
return { fee, ttl, nonce: n }
|
|
499
565
|
}
|
|
500
566
|
|
|
@@ -18,10 +18,11 @@
|
|
|
18
18
|
/**
|
|
19
19
|
* Browser runtime connector module
|
|
20
20
|
*
|
|
21
|
-
* This is the complement to
|
|
21
|
+
* This is the complement to
|
|
22
|
+
* {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
|
|
22
23
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime
|
|
23
24
|
* @export BrowserRuntimeConnection
|
|
24
|
-
* @example import BrowserRuntimeConnection from '@aeternity/aepp-sdk
|
|
25
|
+
* @example import { BrowserRuntimeConnection } from '@aeternity/aepp-sdk'
|
|
25
26
|
*/
|
|
26
27
|
import stampit from '@stamp/it'
|
|
27
28
|
|
|
@@ -18,10 +18,13 @@
|
|
|
18
18
|
/**
|
|
19
19
|
* Browser window Post Message connector module
|
|
20
20
|
*
|
|
21
|
-
* This is the complement to
|
|
21
|
+
* This is the complement to
|
|
22
|
+
* {@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection}.
|
|
22
23
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message
|
|
23
24
|
* @export BrowserWindowMessageConnection
|
|
24
|
-
* @example
|
|
25
|
+
* @example
|
|
26
|
+
* import BrowserWindowMessageConnection
|
|
27
|
+
* from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-window-message'
|
|
25
28
|
*/
|
|
26
29
|
import stampit from '@stamp/it'
|
|
27
30
|
import WalletConnection from '.'
|
|
@@ -102,27 +105,42 @@ const getTarget = () => {
|
|
|
102
105
|
const isContentScript = isExtensionContext && isWeb
|
|
103
106
|
if (isContentScript) return window
|
|
104
107
|
// When we is the main page we need to decide the target by our self
|
|
105
|
-
// Probably can be implemented some algo for checking DOM for Iframes and somehow decide which
|
|
108
|
+
// Probably can be implemented some algo for checking DOM for Iframes and somehow decide which
|
|
109
|
+
// Iframe to talk
|
|
106
110
|
return isInIframe() ? window.parent : undefined
|
|
107
111
|
}
|
|
108
112
|
|
|
109
113
|
/**
|
|
110
114
|
* BrowserWindowMessageConnection
|
|
111
115
|
* @function
|
|
112
|
-
* @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication
|
|
116
|
+
* @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication\
|
|
117
|
+
* /connection/browser-window-message
|
|
113
118
|
* @rtype Stamp
|
|
114
119
|
* @param {Object} [params={}] - Initializer object
|
|
115
120
|
* @param {Object} [params.target=window.parent] - Target window for message
|
|
116
121
|
* @param {Object} [params.self=window] - Host window for message
|
|
117
122
|
* @param {Object} [params.origin] - Origin of receiver
|
|
118
|
-
* @param {
|
|
119
|
-
*
|
|
123
|
+
* @param {String} [params.sendDirection] Wrapping messages into additional struct
|
|
124
|
+
* ({ type: 'to_aepp' || 'to_waellet', data })
|
|
125
|
+
* Used for handling messages between content script and page
|
|
126
|
+
* @param {String} [params.receiveDirection='to_aepp'] Unwrapping messages from additional struct
|
|
127
|
+
* ({ type: 'to_aepp' || 'to_waellet', data })
|
|
128
|
+
* Used for handling messages between content script and page
|
|
120
129
|
* @param {Object} [params.connectionInfo={}] - Connection info object
|
|
121
130
|
* @param {Boolean} [params.debug=false] - Debug flag
|
|
122
131
|
* @return {Object}
|
|
123
132
|
*/
|
|
124
133
|
export default stampit({
|
|
125
|
-
init ({
|
|
134
|
+
init ({
|
|
135
|
+
connectionInfo = {},
|
|
136
|
+
target = getTarget(),
|
|
137
|
+
self = window,
|
|
138
|
+
origin,
|
|
139
|
+
sendDirection,
|
|
140
|
+
receiveDirection = MESSAGE_DIRECTION.to_aepp,
|
|
141
|
+
debug = false,
|
|
142
|
+
forceOrigin = false
|
|
143
|
+
} = {}) {
|
|
126
144
|
if (sendDirection && !Object.keys(MESSAGE_DIRECTION).includes(sendDirection)) throw new Error(`sendDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
|
|
127
145
|
if (!Object.keys(MESSAGE_DIRECTION).includes(receiveDirection)) throw new Error(`receiveDirection must be one of [${Object.keys(MESSAGE_DIRECTION)}]`)
|
|
128
146
|
this.connectionInfo = { id: uuid(), ...connectionInfo }
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
* Wallet Connection base module
|
|
20
20
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection
|
|
21
21
|
* @export WalletConnection
|
|
22
|
-
* @example
|
|
22
|
+
* @example
|
|
23
|
+
* import WalletConnection from '@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection'
|
|
23
24
|
*/
|
|
24
25
|
|
|
25
26
|
import { required } from '@stamp/required'
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
*
|
|
21
21
|
* @module @aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge
|
|
22
22
|
* @export ContentScriptBridge
|
|
23
|
-
* @example
|
|
23
|
+
* @example
|
|
24
|
+
* import ContentScriptBridge
|
|
25
|
+
* from '@aeternity/aepp-sdk/es/utils/wallet-communication/content-script-bridge
|
|
24
26
|
*/
|
|
25
27
|
import stampit from '@stamp/it'
|
|
26
28
|
|
|
@@ -56,14 +58,18 @@ function stop () {
|
|
|
56
58
|
|
|
57
59
|
/**
|
|
58
60
|
* ContentScriptBridge stamp
|
|
59
|
-
* Provide functionality to easly redirect messages from page to extension and from extension to
|
|
61
|
+
* Provide functionality to easly redirect messages from page to extension and from extension to
|
|
62
|
+
* page through content script
|
|
60
63
|
* Using Runtime(Extension) and WindowPostMessage(Web-Page) connections
|
|
61
64
|
* @function
|
|
62
65
|
* @alias module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/content-script-bridge
|
|
63
66
|
* @rtype Stamp
|
|
64
67
|
* @param {Object} params - Initializer object
|
|
65
|
-
* @param {Object} params.pageConnection - Page connection object
|
|
66
|
-
* @
|
|
68
|
+
* @param {Object} params.pageConnection - Page connection object
|
|
69
|
+
* (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/\
|
|
70
|
+
* browser-window-message)
|
|
71
|
+
* @param {Object} params.extConnection - Extension connection object
|
|
72
|
+
* (@link module:@aeternity/aepp-sdk/es/utils/aepp-wallet-communication/connection/browser-runtime)
|
|
67
73
|
* @return {Object}
|
|
68
74
|
*/
|
|
69
75
|
export default stampit({
|