@aeternity/aepp-sdk 13.2.1 → 13.2.2

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.
Files changed (84) hide show
  1. package/dist/aepp-sdk.browser-script.js +1 -1
  2. package/dist/aepp-sdk.browser-script.js.map +1 -1
  3. package/dist/aepp-sdk.browser.js +1 -1
  4. package/dist/aepp-sdk.browser.js.map +1 -1
  5. package/dist/aepp-sdk.js +82 -4343
  6. package/dist/aepp-sdk.js.map +1 -1
  7. package/es/Middleware.d.ts +1 -1
  8. package/es/Middleware.mjs +1 -1
  9. package/es/Middleware.mjs.map +1 -1
  10. package/es/Node.d.ts +1 -1
  11. package/es/Node.mjs +12 -3
  12. package/es/Node.mjs.map +1 -1
  13. package/es/aepp-wallet-communication/rpc/types.mjs.map +1 -1
  14. package/es/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  15. package/es/aepp-wallet-communication/wallet-detector.mjs +9 -4
  16. package/es/aepp-wallet-communication/wallet-detector.mjs.map +1 -1
  17. package/es/contract/Contract.d.ts +1 -1
  18. package/es/contract/Contract.mjs +17 -7
  19. package/es/contract/Contract.mjs.map +1 -1
  20. package/es/contract/compiler/Cli.d.ts +7 -2
  21. package/es/contract/compiler/Cli.mjs +7 -2
  22. package/es/contract/compiler/Cli.mjs.map +1 -1
  23. package/es/deprecated.d.ts +10 -0
  24. package/es/deprecated.mjs +21 -1
  25. package/es/deprecated.mjs.map +1 -1
  26. package/es/index-browser.d.ts +2 -2
  27. package/es/index-browser.mjs +2 -2
  28. package/es/index-browser.mjs.map +1 -1
  29. package/es/tx/builder/constants.d.ts +2 -1
  30. package/es/tx/builder/constants.mjs +1 -0
  31. package/es/tx/builder/constants.mjs.map +1 -1
  32. package/es/tx/builder/field-types/ct-version.d.ts +1 -1
  33. package/es/tx/builder/field-types/ct-version.mjs +1 -1
  34. package/es/tx/builder/field-types/ct-version.mjs.map +1 -1
  35. package/es/tx/builder/field-types/fee.mjs +1 -1
  36. package/es/tx/builder/field-types/fee.mjs.map +1 -1
  37. package/es/tx/builder/field-types/gas-price.mjs +1 -1
  38. package/es/tx/builder/field-types/gas-price.mjs.map +1 -1
  39. package/es/utils/autorest.mjs +4 -4
  40. package/es/utils/autorest.mjs.map +1 -1
  41. package/es/utils/crypto.d.ts +1 -1
  42. package/es/utils/crypto.mjs +1 -1
  43. package/es/utils/crypto.mjs.map +1 -1
  44. package/es/utils/typed-data.d.ts +0 -2
  45. package/es/utils/typed-data.mjs +8 -24
  46. package/es/utils/typed-data.mjs.map +1 -1
  47. package/package.json +2 -2
  48. package/src/Middleware.ts +1 -1
  49. package/src/Node.ts +14 -3
  50. package/src/aepp-wallet-communication/rpc/types.ts +1 -1
  51. package/src/aepp-wallet-communication/wallet-detector.ts +10 -10
  52. package/src/contract/Contract.ts +11 -5
  53. package/src/contract/compiler/Cli.ts +7 -2
  54. package/src/deprecated.ts +19 -1
  55. package/src/index-browser.ts +4 -4
  56. package/src/tx/builder/constants.ts +1 -0
  57. package/src/tx/builder/field-types/ct-version.ts +1 -1
  58. package/src/tx/builder/field-types/fee.ts +1 -1
  59. package/src/tx/builder/field-types/gas-price.ts +1 -1
  60. package/src/utils/autorest.ts +4 -4
  61. package/src/utils/crypto.ts +1 -1
  62. package/src/utils/typed-data.ts +4 -30
  63. package/types-legacy/ts4.2/Middleware.d.ts +1 -1
  64. package/types-legacy/ts4.2/Node.d.ts +1 -1
  65. package/types-legacy/ts4.2/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  66. package/types-legacy/ts4.2/contract/Contract.d.ts +1 -1
  67. package/types-legacy/ts4.2/contract/compiler/Cli.d.ts +7 -2
  68. package/types-legacy/ts4.2/deprecated.d.ts +10 -0
  69. package/types-legacy/ts4.2/index-browser.d.ts +2 -2
  70. package/types-legacy/ts4.2/tx/builder/constants.d.ts +2 -1
  71. package/types-legacy/ts4.2/tx/builder/field-types/ct-version.d.ts +1 -1
  72. package/types-legacy/ts4.2/utils/crypto.d.ts +1 -1
  73. package/types-legacy/ts4.2/utils/typed-data.d.ts +0 -2
  74. package/types-legacy/ts4.5/Middleware.d.ts +1 -1
  75. package/types-legacy/ts4.5/Node.d.ts +1 -1
  76. package/types-legacy/ts4.5/aepp-wallet-communication/wallet-detector.d.ts +2 -5
  77. package/types-legacy/ts4.5/contract/Contract.d.ts +1 -1
  78. package/types-legacy/ts4.5/contract/compiler/Cli.d.ts +7 -2
  79. package/types-legacy/ts4.5/deprecated.d.ts +10 -0
  80. package/types-legacy/ts4.5/index-browser.d.ts +2 -2
  81. package/types-legacy/ts4.5/tx/builder/constants.d.ts +2 -1
  82. package/types-legacy/ts4.5/tx/builder/field-types/ct-version.d.ts +1 -1
  83. package/types-legacy/ts4.5/utils/crypto.d.ts +1 -1
  84. package/types-legacy/ts4.5/utils/typed-data.d.ts +0 -2
package/dist/aepp-sdk.js CHANGED
@@ -1,4297 +1,16 @@
1
1
  (function webpackUniversalModuleDefinition(root, factory) {
2
2
  if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory(require("@azure/core-rest-pipeline"), require("rlp"), require("bs58"), require("buffer"), require("bignumber.js"), require("tweetnacl"), require("varuint-bitcoin"), require("@azure/core-client"), require("canonicalize"), require("@aeternity/uuid"), require("@aeternity/argon2"), require("tweetnacl-auth"), require("bip32-path"), require("aes-js"), require("@aeternity/aepp-calldata"), require("json-bigint"), require("events"), require("websocket"), require("isomorphic-ws"));
3
+ module.exports = factory(require("@azure/core-rest-pipeline"), require("rlp"), require("bs58"), require("buffer"), require("bignumber.js"), require("tweetnacl"), require("varuint-bitcoin"), require("@azure/core-client"), require("@aeternity/aepp-calldata"), require("canonicalize"), require("@aeternity/uuid"), require("@aeternity/argon2"), require("tweetnacl-auth"), require("bip32-path"), require("aes-js"), require("json-bigint"), require("events"), require("websocket"), require("isomorphic-ws"));
4
4
  else if(typeof define === 'function' && define.amd)
5
- define(["@azure/core-rest-pipeline", "rlp", "bs58", "buffer", "bignumber.js", "tweetnacl", "varuint-bitcoin", "@azure/core-client", "canonicalize", "@aeternity/uuid", "@aeternity/argon2", "tweetnacl-auth", "bip32-path", "aes-js", "@aeternity/aepp-calldata", "json-bigint", "events", "websocket", "isomorphic-ws"], factory);
5
+ define(["@azure/core-rest-pipeline", "rlp", "bs58", "buffer", "bignumber.js", "tweetnacl", "varuint-bitcoin", "@azure/core-client", "@aeternity/aepp-calldata", "canonicalize", "@aeternity/uuid", "@aeternity/argon2", "tweetnacl-auth", "bip32-path", "aes-js", "json-bigint", "events", "websocket", "isomorphic-ws"], factory);
6
6
  else if(typeof exports === 'object')
7
- exports["Aeternity"] = factory(require("@azure/core-rest-pipeline"), require("rlp"), require("bs58"), require("buffer"), require("bignumber.js"), require("tweetnacl"), require("varuint-bitcoin"), require("@azure/core-client"), require("canonicalize"), require("@aeternity/uuid"), require("@aeternity/argon2"), require("tweetnacl-auth"), require("bip32-path"), require("aes-js"), require("@aeternity/aepp-calldata"), require("json-bigint"), require("events"), require("websocket"), require("isomorphic-ws"));
7
+ exports["Aeternity"] = factory(require("@azure/core-rest-pipeline"), require("rlp"), require("bs58"), require("buffer"), require("bignumber.js"), require("tweetnacl"), require("varuint-bitcoin"), require("@azure/core-client"), require("@aeternity/aepp-calldata"), require("canonicalize"), require("@aeternity/uuid"), require("@aeternity/argon2"), require("tweetnacl-auth"), require("bip32-path"), require("aes-js"), require("json-bigint"), require("events"), require("websocket"), require("isomorphic-ws"));
8
8
  else
9
- root["Aeternity"] = factory(root["@azure/core-rest-pipeline"], root["rlp"], root["bs58"], root["buffer"], root["bignumber.js"], root["tweetnacl"], root["varuint-bitcoin"], root["@azure/core-client"], root["canonicalize"], root["@aeternity/uuid"], root["@aeternity/argon2"], root["tweetnacl-auth"], root["bip32-path"], root["aes-js"], root["@aeternity/aepp-calldata"], root["json-bigint"], root["events"], root["websocket"], root["isomorphic-ws"]);
10
- })(global, (__WEBPACK_EXTERNAL_MODULE__5039__, __WEBPACK_EXTERNAL_MODULE__3485__, __WEBPACK_EXTERNAL_MODULE__3783__, __WEBPACK_EXTERNAL_MODULE__9408__, __WEBPACK_EXTERNAL_MODULE__5192__, __WEBPACK_EXTERNAL_MODULE__79__, __WEBPACK_EXTERNAL_MODULE__7480__, __WEBPACK_EXTERNAL_MODULE__4711__, __WEBPACK_EXTERNAL_MODULE__6667__, __WEBPACK_EXTERNAL_MODULE__3983__, __WEBPACK_EXTERNAL_MODULE__7417__, __WEBPACK_EXTERNAL_MODULE__9882__, __WEBPACK_EXTERNAL_MODULE__1986__, __WEBPACK_EXTERNAL_MODULE__8236__, __WEBPACK_EXTERNAL_MODULE__7946__, __WEBPACK_EXTERNAL_MODULE__2716__, __WEBPACK_EXTERNAL_MODULE__3735__, __WEBPACK_EXTERNAL_MODULE__8079__, __WEBPACK_EXTERNAL_MODULE__3153__) => {
9
+ root["Aeternity"] = factory(root["@azure/core-rest-pipeline"], root["rlp"], root["bs58"], root["buffer"], root["bignumber.js"], root["tweetnacl"], root["varuint-bitcoin"], root["@azure/core-client"], root["@aeternity/aepp-calldata"], root["canonicalize"], root["@aeternity/uuid"], root["@aeternity/argon2"], root["tweetnacl-auth"], root["bip32-path"], root["aes-js"], root["json-bigint"], root["events"], root["websocket"], root["isomorphic-ws"]);
10
+ })(global, (__WEBPACK_EXTERNAL_MODULE__5039__, __WEBPACK_EXTERNAL_MODULE__3485__, __WEBPACK_EXTERNAL_MODULE__3783__, __WEBPACK_EXTERNAL_MODULE__9408__, __WEBPACK_EXTERNAL_MODULE__5192__, __WEBPACK_EXTERNAL_MODULE__79__, __WEBPACK_EXTERNAL_MODULE__7480__, __WEBPACK_EXTERNAL_MODULE__4711__, __WEBPACK_EXTERNAL_MODULE__7946__, __WEBPACK_EXTERNAL_MODULE__6667__, __WEBPACK_EXTERNAL_MODULE__3983__, __WEBPACK_EXTERNAL_MODULE__7417__, __WEBPACK_EXTERNAL_MODULE__9882__, __WEBPACK_EXTERNAL_MODULE__1986__, __WEBPACK_EXTERNAL_MODULE__8236__, __WEBPACK_EXTERNAL_MODULE__2716__, __WEBPACK_EXTERNAL_MODULE__3735__, __WEBPACK_EXTERNAL_MODULE__8079__, __WEBPACK_EXTERNAL_MODULE__3153__) => {
11
11
  return /******/ (() => { // webpackBootstrap
12
12
  /******/ var __webpack_modules__ = ({
13
13
 
14
- /***/ 6477:
15
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
16
-
17
- const TypeResolveError = __webpack_require__(6966)
18
- const {
19
- FateTypeVoid,
20
- FateTypeInt,
21
- FateTypeBool,
22
- FateTypeString,
23
- FateTypeBits,
24
- FateTypeBytes,
25
- FateTypeHash,
26
- FateTypeSignature,
27
- FateTypeAccountAddress,
28
- FateTypeContractAddress,
29
- FateTypeOracleAddress,
30
- FateTypeOracleQueryAddress,
31
- FateTypeList,
32
- FateTypeMap,
33
- FateTypeTuple,
34
- FateTypeRecord,
35
- FateTypeSet,
36
- FateTypeVariant,
37
- FateTypeOption,
38
- FateTypeChainTTL,
39
- FateTypeChainGAMetaTx,
40
- FateTypeChainPayingForTx,
41
- FateTypeChainBaseTx,
42
- FateTypeAENSPointee,
43
- FateTypeAENSName,
44
- FateTypeEvent,
45
- FateTypeBls12381Fr,
46
- FateTypeBls12381Fp
47
- } = __webpack_require__(4265)
48
-
49
- const isObject = (value) => {
50
- return value && typeof value === 'object' && value.constructor === Object
51
- }
52
-
53
- const isOption = ({type}) => {
54
- let key = type
55
- let _
56
- if (isObject(key)) {
57
- [[key, _]] = Object.entries(key)
58
- }
59
-
60
- return key === 'option'
61
- }
62
-
63
- class AciTypeResolver {
64
- constructor(aci) {
65
- this.aci = aci
66
- }
67
-
68
- getCallTypes(contract, funName) {
69
- const funcAci = this.getNamespaceAci(contract).functions.find(e => e.name === funName)
70
-
71
- if (funcAci) {
72
- const types = funcAci.arguments.map(e => this.resolveType(e.type))
73
- const options = funcAci.arguments.filter(isOption)
74
- return {
75
- types,
76
- required: types.length - options.length,
77
- }
78
- }
79
-
80
- if (funName === 'init') {
81
- return {types: [], required: 0}
82
- }
83
-
84
- throw new TypeResolveError(`Unknown function ${funName}`)
85
- }
86
-
87
- getReturnType(contract, funName) {
88
- if (funName === 'init') {
89
- return this.resolveType('void')
90
- }
91
-
92
- const funcAci = this.getNamespaceAci(contract).functions.find(e => e.name === funName)
93
-
94
- if (!funcAci) {
95
- throw new TypeResolveError(`Unknown function ${funName}`)
96
- }
97
-
98
- return this.resolveType(funcAci.returns)
99
- }
100
-
101
- getEventType(contract, topics) {
102
- const aci = this.getNamespaceAci(contract)
103
-
104
- if (!aci.hasOwnProperty('event')) {
105
- throw new TypeResolveError('Missing event declaration')
106
- }
107
-
108
- return FateTypeEvent(this.resolveType(aci.event), topics)
109
- }
110
-
111
- isCustomType(type) {
112
- if (typeof type !== 'string') {
113
- return false
114
- }
115
-
116
- if (this.isStdType(type)) {
117
- return false
118
- }
119
-
120
- const [namespace, _localType] = type.split('.')
121
- const namespaceData = this.getNamespaceAci(namespace)
122
-
123
- return !!namespaceData
124
- }
125
-
126
- isStdType(type) {
127
- if (type === 'Set.set') {
128
- return true
129
- }
130
-
131
- return false
132
- }
133
-
134
- getNamespaceAci(name) {
135
- for (const e of this.aci) {
136
- const [[_type, data]] = Object.entries(e)
137
- if (data.name === name) {
138
- return data
139
- }
140
- }
141
-
142
- return null
143
- }
144
-
145
- resolveType(type, vars = {}) {
146
- let key = type
147
- let valueTypes = []
148
- let resolvedTypes = []
149
-
150
- if (isObject(type)) {
151
- [[key, valueTypes]] = Object.entries(type)
152
- }
153
-
154
- if (this.isCustomType(key)) {
155
- const [typeDef, typeVars] = this.resolveTypeDef(key, valueTypes)
156
-
157
- return this.resolveType(typeDef, typeVars)
158
- }
159
-
160
- if (Array.isArray(valueTypes)) {
161
- if (key !== 'variant') {
162
- resolvedTypes = valueTypes.map(v => {
163
- const tpl = v.hasOwnProperty('type') ? v.type : v
164
- const t = vars.hasOwnProperty(tpl) ? vars[tpl] : tpl
165
-
166
- return this.resolveType(t, vars)
167
- })
168
- }
169
- }
170
-
171
- if (key === 'void') {
172
- return FateTypeVoid()
173
- }
174
-
175
- if (key === 'unit') {
176
- return FateTypeTuple([])
177
- }
178
-
179
- if (key === 'int') {
180
- return FateTypeInt()
181
- }
182
-
183
- if (key === 'bool') {
184
- return FateTypeBool()
185
- }
186
-
187
- if (key === 'string') {
188
- return FateTypeString()
189
- }
190
-
191
- if (key === 'bits') {
192
- return FateTypeBits()
193
- }
194
-
195
- if (key === 'hash') {
196
- return FateTypeHash()
197
- }
198
-
199
- if (key === 'signature') {
200
- return FateTypeSignature()
201
- }
202
-
203
- if (key === 'address') {
204
- return FateTypeAccountAddress()
205
- }
206
-
207
- if (key === 'contract_pubkey') {
208
- return FateTypeContractAddress()
209
- }
210
-
211
- if (key === 'Chain.ttl') {
212
- return FateTypeChainTTL()
213
- }
214
-
215
- if (key === 'Chain.ga_meta_tx') {
216
- return FateTypeChainGAMetaTx()
217
- }
218
-
219
- if (key === 'Chain.paying_for_tx') {
220
- return FateTypeChainPayingForTx()
221
- }
222
-
223
- if (key === 'Chain.base_tx') {
224
- return FateTypeChainBaseTx()
225
- }
226
-
227
- if (key === 'AENS.pointee') {
228
- return FateTypeAENSPointee()
229
- }
230
-
231
- if (key === 'AENS.name') {
232
- return FateTypeAENSName()
233
- }
234
-
235
- if (key === 'Set.set') {
236
- return FateTypeSet(...resolvedTypes)
237
- }
238
-
239
- if (key === 'MCL_BLS12_381.fr') {
240
- return FateTypeBls12381Fr()
241
- }
242
-
243
- if (key === 'MCL_BLS12_381.fp') {
244
- return FateTypeBls12381Fp()
245
- }
246
-
247
- if (key === 'bytes') {
248
- return FateTypeBytes(valueTypes)
249
- }
250
-
251
- if (key === 'list') {
252
- return FateTypeList(...resolvedTypes)
253
- }
254
-
255
- if (key === 'map') {
256
- return FateTypeMap(...resolvedTypes)
257
- }
258
-
259
- // Unbox singleton tuples and records
260
- // https://github.com/aeternity/aesophia/pull/205
261
- // https://github.com/aeternity/aesophia/commit/a403a9d227ac56266cf5bb8fbc916f17e6141d15
262
- if ((key === 'tuple' || key === 'record') && resolvedTypes.length === 1) {
263
- return resolvedTypes[0]
264
- }
265
-
266
- if (key === 'tuple') {
267
- return FateTypeTuple(resolvedTypes)
268
- }
269
-
270
- if (key === 'record') {
271
- const keys = valueTypes.map(e => e.name)
272
-
273
- return FateTypeRecord(keys, resolvedTypes)
274
- }
275
-
276
- if (key === 'variant') {
277
- return this.resolveVariant(valueTypes, vars)
278
- }
279
-
280
- if (key === 'option') {
281
- return FateTypeOption(resolvedTypes)
282
- }
283
-
284
- if (key === 'oracle') {
285
- return FateTypeOracleAddress(...resolvedTypes)
286
- }
287
-
288
- if (key === 'oracle_query') {
289
- return FateTypeOracleQueryAddress(...resolvedTypes)
290
- }
291
-
292
- throw new TypeResolveError('Cannot resolve type: ' + JSON.stringify(type))
293
- }
294
-
295
- resolveVariant(valueTypes, vars) {
296
- const variants = valueTypes.map(e => {
297
- const [[variant, args]] = Object.entries(e)
298
- const resolvedArgs = args.map(v => {
299
- const t = vars.hasOwnProperty(v) ? vars[v] : v
300
- return this.resolveType(t, vars)
301
- })
302
-
303
- return {[variant]: resolvedArgs}
304
- })
305
-
306
- return FateTypeVariant(variants)
307
- }
308
-
309
- resolveTypeDef(type, params = []) {
310
- const [namespace, localType] = type.split('.')
311
- const namespaceData = this.getNamespaceAci(namespace)
312
-
313
- // not a custom type
314
- if (!namespaceData) {
315
- throw new TypeResolveError('Unknown namespace for ' + JSON.stringify(type))
316
- }
317
-
318
- if (namespaceData.name === type) {
319
- return ['contract_pubkey', []]
320
- }
321
-
322
- const def = [
323
- /**
324
- * @deprecated use ACIs generated by aesophia@^7.1.0
325
- * TODO remove `type_defs` in next major release
326
- */
327
- ...namespaceData.typedefs || namespaceData.type_defs,
328
- ...namespaceData.state ? [{
329
- name: 'state',
330
- typedef: namespaceData.state,
331
- vars: []
332
- }] : []
333
- ].find(e => e.name === localType)
334
-
335
- if (!def) {
336
- throw new TypeResolveError('Unknown type definition: ' + JSON.stringify(type))
337
- }
338
-
339
- const vars = {}
340
- def.vars.forEach((e, i) => {
341
- const [[_, k]] = Object.entries(e)
342
- vars[k] = params[i]
343
- })
344
-
345
- const typeDef = vars.hasOwnProperty(def.typedef) ? vars[def.typedef] : def.typedef
346
-
347
- return [typeDef, vars]
348
- }
349
- }
350
-
351
- module.exports = AciTypeResolver
352
-
353
-
354
- /***/ }),
355
-
356
- /***/ 7200:
357
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
358
-
359
- const base64check = __webpack_require__(8638)
360
- const base58check = __webpack_require__(2727)
361
- const FormatError = __webpack_require__(722)
362
- const FateTypeError = __webpack_require__(5110)
363
-
364
- const TYPES = {
365
- key_block_hash: {tag: 'kh', size: 32, encoder: base58check},
366
- contract_bytearray: {tag: 'cb', size: 0, encoder: base64check},
367
- contract_pubkey: {tag: 'ct', size: 32, encoder: base58check},
368
- account_pubkey: {tag: 'ak', size: 32, encoder: base58check},
369
- channel: {tag: 'ch', size: 32, encoder: base58check},
370
- oracle_pubkey: {tag: 'ok', size: 32, encoder: base58check},
371
- oracle_query_id: {tag: 'oq', size: 32, encoder: base58check},
372
- peer_pubkey: {tag: 'pp', size: 32, encoder: base58check},
373
- }
374
-
375
- const TAG2TYPE = {
376
- kh: 'key_block_hash',
377
- cb: 'contract_bytearray',
378
- ct: 'contract_pubkey',
379
- ak: 'account_pubkey',
380
- ch: 'channel',
381
- ok: 'oracle_pubkey',
382
- oq: 'oracle_query_id',
383
- pp: 'peer_pubkey',
384
- }
385
-
386
- class ApiEncoder {
387
- encode(typeName, payload) {
388
- if (!TYPES.hasOwnProperty(typeName)) {
389
- throw new FateTypeError(typeName, `Unsupported API type ${typeName}`)
390
- }
391
-
392
- const type = TYPES[typeName]
393
-
394
- if (type.size > 0 && payload.length !== type.size) {
395
- throw new FateTypeError(
396
- typeName,
397
- `Invalid payload. Expected size ${type.size}, but got ${payload.length}`
398
- )
399
- }
400
-
401
- const encoded = type.encoder.encode(payload)
402
-
403
- return `${type.tag}_${encoded}`
404
- }
405
-
406
- decode(data) {
407
- const tag = data.substring(0, 2)
408
-
409
- if (!TAG2TYPE.hasOwnProperty(tag)) {
410
- throw new FormatError(`Invalid API data format. Unsupported tag: ${tag}`)
411
- }
412
-
413
- if (data[2] !== '_') {
414
- throw new FormatError(`Invalid API data format. Expected _ separator on position 2, got ${data[2]}`)
415
- }
416
-
417
- const type = TYPES[TAG2TYPE[tag]]
418
- const payload = data.substring(3)
419
- const decoded = type.encoder.decode(payload)
420
-
421
- if (type.size > 0 && decoded.length !== type.size) {
422
- throw new FormatError(`Invalid API data format. Expected size ${type.size}, but got ${decoded.length}`)
423
- }
424
-
425
- return decoded
426
- }
427
-
428
- decodeWithType(data, expectedType) {
429
- const tag = data.substring(0, 2)
430
-
431
- if (!TYPES.hasOwnProperty(expectedType)) {
432
- throw new FateTypeError(expectedType, 'Unsupported API type')
433
- }
434
-
435
- const expectedTag = TYPES[expectedType].tag
436
-
437
- if (tag !== expectedTag) {
438
- const capitalized = this.capitalizeType(expectedType)
439
-
440
- throw new FateTypeError(
441
- expectedType,
442
- `${capitalized} should start with ${expectedTag}_, got ${data} instead`
443
- )
444
- }
445
-
446
- return this.decode(data)
447
- }
448
-
449
- capitalizeType(type) {
450
- const s = type.replace('_', ' ')
451
-
452
- return s.charAt(0).toUpperCase() + s.slice(1)
453
- }
454
- }
455
-
456
- module.exports = ApiEncoder
457
-
458
-
459
- /***/ }),
460
-
461
- /***/ 8323:
462
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
463
-
464
- const Serializer = __webpack_require__(7829)
465
- const ApiEncoder = __webpack_require__(7200)
466
- const CanonicalMapper = __webpack_require__(880)
467
- const ExternalDataFactory = __webpack_require__(3451)
468
-
469
- class ContractByteArrayEncoder {
470
- constructor() {
471
- /** @type {Serializer} */
472
- this._serializer = new Serializer()
473
-
474
- /** @type {ApiEncoder} */
475
- this._apiEncoder = new ApiEncoder()
476
-
477
- /** @type {ExternalDataFactory} */
478
- this._externalDataFactory = new ExternalDataFactory()
479
-
480
- /** @type {CanonicalMapper} */
481
- this._canonicalMapper = new CanonicalMapper()
482
- }
483
-
484
- /**
485
- * Encode FATE data to contract bytearray.
486
- *
487
- * @example
488
- * const encoded = encoder.encode("whoolymoly")
489
- * console.log(`Encoded data: ${encoded}`)
490
- * // Outputs:
491
- * // Encoded data: cb_KXdob29seW1vbHlGazSE
492
- *
493
- * @param {Array} data - Data as Javascript data structures. See README.md
494
- * @returns {string} Encoded contract byte array
495
- */
496
- encode(type, value) {
497
- const data = this._externalDataFactory.create(type, value)
498
- const serialized = this._serializer.serialize(data)
499
- const binData = new Uint8Array(serialized.flat(Infinity))
500
-
501
- return this._apiEncoder.encode('contract_bytearray', binData)
502
- }
503
-
504
- /**
505
- * Decodes arbitrary contract bytearray data.
506
- *
507
- * Note that:
508
- * - Variants are not annotated with constructor names
509
- * - Record keys are lost
510
- * - Any custom type information is lost
511
- * - STL type information is lost: i.e. Chain, AENS, Set, BLS12_381
512
- *
513
- * @example
514
- * const decoded = encoder.decode('cb_KXdob29seW1vbHlGazSE')
515
- * console.log(`Decoded data: ${decoded}`)
516
- * // Outputs:
517
- * // Decoded data: whoolymoly
518
- *
519
- * @param {string} data - Contract bytearray data in a canonical format.
520
- * @returns {boolean|string|BigInt|Array|Map|Object}
521
- * Decoded value as Javascript data structures. See README.md
522
- */
523
- decode(data) {
524
- const binData = this._apiEncoder.decodeWithType(data, 'contract_bytearray')
525
- const deserialized = this._serializer.deserialize(binData)
526
-
527
- return this._canonicalMapper.toCanonical(deserialized)
528
- }
529
-
530
- /**
531
- * Decodes arbitrary contract bytearray data with type information.
532
- *
533
- * @example
534
- * const decoded = encoder.decode('cb_KXdob29seW1vbHlGazSE')
535
- * console.log(`Decoded data: ${decoded}`)
536
- * // Outputs:
537
- * // Decoded data: whoolymoly
538
- *
539
- * @param {string} data - Contract bytearray data in a canonical format.
540
- * @returns {boolean|string|BigInt|Array|Map|Object}
541
- * Decoded value as Javascript data structures. See README.md
542
- */
543
- decodeWithType(data, type) {
544
- const binData = this._apiEncoder.decodeWithType(data, 'contract_bytearray')
545
- const deserialized = this._serializer.deserializeWithType(binData, type)
546
-
547
- return this._canonicalMapper.toCanonical(deserialized)
548
- }
549
- }
550
-
551
- module.exports = ContractByteArrayEncoder
552
-
553
-
554
- /***/ }),
555
-
556
- /***/ 6040:
557
- /***/ ((module) => {
558
-
559
- class BaseDataFactory {
560
- constructor(valueFactory) {
561
- this._valueFactory = valueFactory
562
- }
563
-
564
- get valueFactory() {
565
- return this._valueFactory
566
- }
567
-
568
- supports({_name, _valueTypes}) {
569
- return false
570
- }
571
-
572
- create(_type, _value) {
573
- throw new Error('Not implemented.')
574
- }
575
- }
576
-
577
- module.exports = BaseDataFactory
578
-
579
-
580
- /***/ }),
581
-
582
- /***/ 6097:
583
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
584
-
585
- const FateBls12381Fr = __webpack_require__(1565)
586
- const FateBls12381Fp = __webpack_require__(4077)
587
- const BaseDataFactory = __webpack_require__(6040)
588
-
589
- const TYPES = [
590
- 'bls12_381.fr',
591
- 'bls12_381.fp',
592
- ]
593
-
594
- class Bls12381DataFactory extends BaseDataFactory {
595
- supports({ name, _valueTypes }) {
596
- return TYPES.includes(name)
597
- }
598
-
599
- create(type, value) {
600
- switch (type.name) {
601
- case 'bls12_381.fr':
602
- return new FateBls12381Fr(value)
603
- case 'bls12_381.fp':
604
- return new FateBls12381Fp(value)
605
- default:
606
- throw new Error(`Unsupported type "${type.name}"`)
607
- }
608
- }
609
- }
610
-
611
- module.exports = Bls12381DataFactory
612
-
613
-
614
- /***/ }),
615
-
616
- /***/ 7961:
617
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
618
-
619
- const {symbolIdentifier} = __webpack_require__(2665)
620
- const FateTypeError = __webpack_require__(5110)
621
- const FateCalldata = __webpack_require__(7255)
622
- const BaseDataFactory = __webpack_require__(6040)
623
-
624
- class CallDataFactory extends BaseDataFactory {
625
- supports({ name, _valueTypes }) {
626
- return 'calldata' === name
627
- }
628
-
629
- create(type, value) {
630
- if (!Array.isArray(value)) {
631
- throw new FateTypeError(
632
- type.name,
633
- `Fate calldata arguments must be an Array, got ${value} instead`
634
- )
635
- }
636
-
637
- const argsData = this.valueFactory.createMultiple(type.argumentTypes, value)
638
- const functionId = symbolIdentifier(type.functionName)
639
-
640
- return new FateCalldata(functionId, type.argumentTypes, argsData)
641
- }
642
- }
643
-
644
- module.exports = CallDataFactory
645
-
646
-
647
- /***/ }),
648
-
649
- /***/ 2320:
650
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
651
-
652
- const assert = __webpack_require__(4664)
653
- const zip = __webpack_require__(5675)
654
- const PrimitiveDataFactory = __webpack_require__(1168)
655
- const ListDataFactory = __webpack_require__(9205)
656
- const SetDataFactory = __webpack_require__(4960)
657
- const MapDataFactory = __webpack_require__(3353)
658
- const TupleDataFactory = __webpack_require__(786)
659
- const RecordDataFactory = __webpack_require__(7211)
660
- const VariantDataFactory = __webpack_require__(4093)
661
- const EventDataFactory = __webpack_require__(2954)
662
- const Bls12381DataFactory = __webpack_require__(6097)
663
- const CallDataFactory = __webpack_require__(7961)
664
-
665
- class CompositeDataFactory {
666
- constructor() {
667
- this._factories = [
668
- new PrimitiveDataFactory(this),
669
- new ListDataFactory(this),
670
- new SetDataFactory(this),
671
- new MapDataFactory(this),
672
- new TupleDataFactory(this),
673
- new RecordDataFactory(this),
674
- new EventDataFactory(this),
675
- new VariantDataFactory(this),
676
- new Bls12381DataFactory(this),
677
- new CallDataFactory(this),
678
- ]
679
- }
680
-
681
- createMultiple(types, values) {
682
- assert(
683
- values.length === types.length,
684
- `Number of types (${types.length}) and values (${values.length}) should match`
685
- )
686
-
687
- return zip(types, values).map(el => this.create(...el))
688
- }
689
-
690
- create(type, value) {
691
- const factory = this._factories.find(f => f.supports(type))
692
- assert(factory, `Unsupported type "${type.name}"`)
693
-
694
- return factory.create(type, value)
695
- }
696
- }
697
-
698
- module.exports = CompositeDataFactory
699
-
700
-
701
- /***/ }),
702
-
703
- /***/ 2954:
704
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
705
-
706
- const {hash} = __webpack_require__(2665)
707
- const {ByteArray2Int} = __webpack_require__(240)
708
- const TypeResolveError = __webpack_require__(6966)
709
- const BaseDataFactory = __webpack_require__(6040)
710
-
711
- const DATA_TYPES = [
712
- 'string',
713
- 'signature',
714
- 'bytes',
715
- ]
716
-
717
- class EventDataFactory extends BaseDataFactory {
718
- supports({ name, _valueTypes }) {
719
- return 'event' === name
720
- }
721
-
722
- create({variantType, topics}, data) {
723
- const [nameHash, ...args] = topics
724
-
725
- if (typeof nameHash !== 'bigint') {
726
- throw new TypeResolveError(`Event name hash (first topic) should be of type "BigInt", got "${typeof nameHash}" instead.`)
727
- }
728
-
729
- const idx = variantType.variants
730
- .map(v => ByteArray2Int(hash(Object.keys(v)[0])))
731
- .findIndex(v => v === nameHash)
732
-
733
- if (idx === -1) {
734
- throw new TypeResolveError('Event name hash does not match any event variant constructor')
735
- }
736
-
737
- const variant = variantType.variants[idx]
738
- const variantName = Object.keys(variant)[0]
739
- const [argTypes] = Object.values(variant)
740
- const resolvedArgs = argTypes.map(t => {
741
- if (this._isData(t)) {
742
- return data
743
- }
744
-
745
- return args.shift()
746
- })
747
-
748
- return this.valueFactory.create(variantType, {[variantName]: resolvedArgs})
749
- }
750
-
751
- _isData(type) {
752
- if (!DATA_TYPES.includes(type.name)) {
753
- return false
754
- }
755
-
756
- if (type.name === 'bytes' && type.size <= 32) {
757
- return false
758
- }
759
-
760
- return true
761
- }
762
- }
763
-
764
- module.exports = EventDataFactory
765
-
766
-
767
- /***/ }),
768
-
769
- /***/ 9205:
770
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
771
-
772
- const FateList = __webpack_require__(1041)
773
- const FateTypeError = __webpack_require__(5110)
774
- const BaseDataFactory = __webpack_require__(6040)
775
-
776
- class ListDataFactory extends BaseDataFactory {
777
- supports({name, _valueTypes}) {
778
- return 'list' === name
779
- }
780
-
781
- create(type, value) {
782
- if (!Array.isArray(value)) {
783
- throw new FateTypeError(
784
- type.name,
785
- `Fate list must be an Array, got ${value} instead`
786
- )
787
- }
788
-
789
- const resolvedValues = value.map(v => this.valueFactory.create(type.valuesType, v))
790
-
791
- return new FateList(type.valuesType, resolvedValues)
792
- }
793
- }
794
-
795
- module.exports = ListDataFactory
796
-
797
-
798
- /***/ }),
799
-
800
- /***/ 3353:
801
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
802
-
803
- const FateMap = __webpack_require__(8804)
804
- const BaseDataFactory = __webpack_require__(6040)
805
-
806
- class MapDataFactory extends BaseDataFactory {
807
- supports({ name, _valueTypes }) {
808
- return 'map' === name
809
- }
810
-
811
- create(type, value) {
812
- const resolvedValues = []
813
- for (const item of value) {
814
- resolvedValues.push([
815
- this.valueFactory.create(type.keyType, item[0]),
816
- this.valueFactory.create(type.valueType, item[1]),
817
- ])
818
- }
819
-
820
- return new FateMap(type.keyType, type.valueType, resolvedValues)
821
- }
822
- }
823
-
824
- module.exports = MapDataFactory
825
-
826
-
827
- /***/ }),
828
-
829
- /***/ 1168:
830
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
831
-
832
- const FateInt = __webpack_require__(3509)
833
- const FateBool = __webpack_require__(4476)
834
- const FateString = __webpack_require__(6313)
835
- const FateHash = __webpack_require__(7772)
836
- const FateSignature = __webpack_require__(3607)
837
- const FateBytes = __webpack_require__(5779)
838
- const FateBits = __webpack_require__(3422)
839
- const FateAccountAddress = __webpack_require__(539)
840
- const FateContractAddress = __webpack_require__(8623)
841
- const FateChannelAddress = __webpack_require__(6445)
842
- const FateOracleAddress = __webpack_require__(687)
843
- const FateOracleQueryAddress = __webpack_require__(5070)
844
- const BaseDataFactory = __webpack_require__(6040)
845
-
846
- const TYPES = [
847
- 'int',
848
- 'bool',
849
- 'string',
850
- 'bits',
851
- 'hash',
852
- 'bytes',
853
- 'signature',
854
- 'account_pubkey',
855
- 'contract_pubkey',
856
- 'channel',
857
- 'oracle_pubkey',
858
- 'oracle_query_id'
859
- ]
860
-
861
- class PrimitiveDataFactory extends BaseDataFactory {
862
- supports({ name, _valueTypes }) {
863
- return TYPES.includes(name)
864
- }
865
-
866
- create(type, value) {
867
- switch (type.name) {
868
- case 'int':
869
- return new FateInt(value)
870
- case 'bool':
871
- return new FateBool(value)
872
- case 'string':
873
- return new FateString(value)
874
- case 'bits':
875
- return new FateBits(value)
876
- case 'hash':
877
- return new FateHash(value)
878
- case 'bytes':
879
- return new FateBytes(value, type.valueTypes)
880
- case 'signature':
881
- return new FateSignature(value)
882
- case 'account_pubkey':
883
- return new FateAccountAddress(value)
884
- case 'contract_pubkey':
885
- return new FateContractAddress(value)
886
- case 'channel':
887
- return new FateChannelAddress(value)
888
- case 'oracle_pubkey':
889
- return new FateOracleAddress(value)
890
- case 'oracle_query_id':
891
- return new FateOracleQueryAddress(value)
892
- default:
893
- throw new Error(`Unsupported type "${type.name}"`)
894
- }
895
- }
896
- }
897
-
898
- module.exports = PrimitiveDataFactory
899
-
900
-
901
- /***/ }),
902
-
903
- /***/ 7211:
904
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
905
-
906
- const BaseDataFactory = __webpack_require__(6040)
907
- const FateTuple = __webpack_require__(6878)
908
- const {FateTypeRecord} = __webpack_require__(4265)
909
- const FateTypeError = __webpack_require__(5110)
910
-
911
- class RecordDataFactory extends BaseDataFactory {
912
- supports({ name, _valueTypes }) {
913
- return 'record' === name
914
- }
915
-
916
- create(type, value) {
917
- if (typeof value !== 'object') {
918
- throw new FateTypeError(
919
- type.name,
920
- `Fate record must be an Object, got ${value} instead`
921
- )
922
- }
923
-
924
- const keyLen = Object.keys(value).length
925
- if (keyLen !== type.keys.length) {
926
- throw new FateTypeError(
927
- type.name,
928
- `Number of expected keys (${type.keys.length}) and actual keys (${keyLen}) should match`
929
- )
930
- }
931
-
932
- const resolvedValue = type.valueTypes.map((t, i) => {
933
- const key = type.keys[i]
934
- return this.valueFactory.create(t, value[key])
935
- })
936
-
937
- // Unbox singleton tuples and records
938
- // https://github.com/aeternity/aesophia/pull/205
939
- // https://github.com/aeternity/aesophia/commit/a403a9d227ac56266cf5bb8fbc916f17e6141d15
940
- if (resolvedValue.length === 1) {
941
- return resolvedValue[0]
942
- }
943
-
944
- return new FateTuple(
945
- FateTypeRecord(type.keys, type.valueTypes),
946
- resolvedValue
947
- )
948
- }
949
- }
950
-
951
- module.exports = RecordDataFactory
952
-
953
-
954
- /***/ }),
955
-
956
- /***/ 4960:
957
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
958
-
959
- const FateSet = __webpack_require__(2548)
960
- const BaseDataFactory = __webpack_require__(6040)
961
-
962
- class SetDataFactory extends BaseDataFactory {
963
- supports({name, _valueTypes}) {
964
- return 'set' === name
965
- }
966
-
967
- create(type, value) {
968
- const resolvedValues = []
969
- for (const item of value) {
970
- resolvedValues.push(this.valueFactory.create(type.valuesType, item))
971
- }
972
-
973
- return new FateSet(type.valuesType, resolvedValues)
974
- }
975
- }
976
-
977
- module.exports = SetDataFactory
978
-
979
-
980
- /***/ }),
981
-
982
- /***/ 786:
983
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
984
-
985
- const FateTuple = __webpack_require__(6878)
986
- const FateTypeError = __webpack_require__(5110)
987
- const BaseDataFactory = __webpack_require__(6040)
988
-
989
- class TupleDataFactory extends BaseDataFactory {
990
- supports({ name, _valueTypes }) {
991
- return 'tuple' === name
992
- }
993
-
994
- create(type, value) {
995
- if (!Array.isArray(value)) {
996
- throw new FateTypeError(
997
- type.name,
998
- `Fate tuple must be an Array, got ${value} instead`
999
- )
1000
- }
1001
-
1002
- const resolvedValue = type.valueTypes.map((t, i) => {
1003
- return this.valueFactory.create(t, value[i])
1004
- })
1005
-
1006
- // Unbox singleton tuples and records
1007
- // https://github.com/aeternity/aesophia/pull/205
1008
- // https://github.com/aeternity/aesophia/commit/a403a9d227ac56266cf5bb8fbc916f17e6141d15
1009
- if (resolvedValue.length === 1) {
1010
- return resolvedValue[0]
1011
- }
1012
-
1013
- return new FateTuple(type.valueTypes, resolvedValue)
1014
- }
1015
- }
1016
-
1017
- module.exports = TupleDataFactory
1018
-
1019
-
1020
- /***/ }),
1021
-
1022
- /***/ 4093:
1023
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1024
-
1025
- const FateVariant = __webpack_require__(2457)
1026
- const FateTypeError = __webpack_require__(5110)
1027
- const BaseDataFactory = __webpack_require__(6040)
1028
-
1029
- const TYPES = [
1030
- 'variant',
1031
- 'Chain.ttl',
1032
- 'AENS.pointee',
1033
- 'AENS.name'
1034
- ]
1035
-
1036
- class VariantDataFactory extends BaseDataFactory {
1037
- supports({ name, _valueTypes }) {
1038
- return TYPES.includes(name)
1039
- }
1040
-
1041
- create(type, value) {
1042
- if (!this.isValid(value)) {
1043
- throw new FateTypeError(
1044
- type.name,
1045
- `Variant should be an object mapping constructor to array of values, got "${value}" instead`
1046
- )
1047
- }
1048
-
1049
- const [variantCtor, variantArgs] = Object.entries(value)[0]
1050
-
1051
- const arities = type.variants.map(e => {
1052
- const [[, args]] = Object.entries(e)
1053
- return args.length
1054
- })
1055
-
1056
- const tag = type.variants.findIndex(e => {
1057
- const [[key, _]] = Object.entries(e)
1058
- return key === variantCtor
1059
- })
1060
-
1061
- if (tag === -1) {
1062
- throw new FateTypeError(
1063
- type.name,
1064
- `Unknown variant constructor: ${variantCtor}`
1065
- )
1066
- }
1067
-
1068
- const [[, variantTypes]] = Object.entries(type.variants[tag])
1069
-
1070
- if (variantArgs.length !== variantTypes.length) {
1071
- throw new FateTypeError(
1072
- type.name,
1073
- `"${variantCtor}" variant constructor expects ${variantTypes.length} argument(s) but got ${variantArgs.length} instead`
1074
- )
1075
- }
1076
-
1077
- const variantValue = this.valueFactory.createMultiple(variantTypes, variantArgs)
1078
-
1079
- return new FateVariant(arities, tag, variantValue, variantTypes, type.variants)
1080
- }
1081
-
1082
- isValid(value) {
1083
- return typeof value === 'object'
1084
- && value !== null
1085
- && Object.entries(value).length === 1
1086
- && Array.isArray(Object.values(value)[0])
1087
- }
1088
- }
1089
-
1090
- module.exports = VariantDataFactory
1091
-
1092
-
1093
- /***/ }),
1094
-
1095
- /***/ 5462:
1096
- /***/ ((module) => {
1097
-
1098
- class FatePrefixError extends Error {
1099
- constructor(prefix) {
1100
- super('Invalid FATE prefix: 0b' + prefix.toString(2).padStart(8, '0'))
1101
-
1102
- this.name = 'FatePrefixError'
1103
- this.prefix = prefix
1104
- }
1105
- }
1106
-
1107
- module.exports = FatePrefixError
1108
-
1109
-
1110
- /***/ }),
1111
-
1112
- /***/ 5110:
1113
- /***/ ((module) => {
1114
-
1115
- class FateTypeError extends Error {
1116
- constructor(type, message) {
1117
- super(message)
1118
- this.name = 'FateTypeError'
1119
- this.type = type
1120
- }
1121
- }
1122
-
1123
- module.exports = FateTypeError
1124
-
1125
-
1126
- /***/ }),
1127
-
1128
- /***/ 722:
1129
- /***/ ((module) => {
1130
-
1131
- class FormatError extends Error {
1132
- constructor(message) {
1133
- super(message)
1134
- this.name = 'FormatError'
1135
- }
1136
- }
1137
-
1138
- module.exports = FormatError
1139
-
1140
-
1141
- /***/ }),
1142
-
1143
- /***/ 2966:
1144
- /***/ ((module) => {
1145
-
1146
- class InternalError extends Error {
1147
- constructor(message) {
1148
- super(message)
1149
- this.name = 'InternalError'
1150
- }
1151
- }
1152
-
1153
- module.exports = InternalError
1154
-
1155
-
1156
- /***/ }),
1157
-
1158
- /***/ 9098:
1159
- /***/ ((module) => {
1160
-
1161
- class SerializerError extends Error {
1162
- constructor(message) {
1163
- super(message)
1164
- this.name = 'SerializerError'
1165
- }
1166
- }
1167
-
1168
- module.exports = SerializerError
1169
-
1170
-
1171
- /***/ }),
1172
-
1173
- /***/ 6966:
1174
- /***/ ((module) => {
1175
-
1176
- class TypeResolveError extends Error {
1177
- constructor(message) {
1178
- super(message)
1179
- this.name = 'TypeResolveError'
1180
- }
1181
- }
1182
-
1183
- module.exports = TypeResolveError
1184
-
1185
-
1186
- /***/ }),
1187
-
1188
- /***/ 3451:
1189
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1190
-
1191
- const CompositeDataFactory = __webpack_require__(2320)
1192
- const InternalMapper = __webpack_require__(1338)
1193
-
1194
- class ExternalDataFactory extends CompositeDataFactory {
1195
- constructor() {
1196
- super()
1197
-
1198
- this._mapper = new InternalMapper()
1199
- }
1200
-
1201
- create(type, value) {
1202
- const internalValue = this._mapper.toInternal(type, value)
1203
-
1204
- return super.create(type, internalValue)
1205
- }
1206
- }
1207
-
1208
- module.exports = ExternalDataFactory
1209
-
1210
-
1211
- /***/ }),
1212
-
1213
- /***/ 2689:
1214
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1215
-
1216
- const assert = __webpack_require__(4664)
1217
- const FateList = __webpack_require__(1041)
1218
- const FateTuple = __webpack_require__(6878)
1219
- const {FateTypeTuple, FateTypeInt} = __webpack_require__(4265)
1220
-
1221
- /* eslint-disable no-use-before-define */
1222
-
1223
- // TODO types comparator
1224
- const listComparator = (a, b) => {
1225
- if (a.length === 0) {
1226
- return -1
1227
- }
1228
-
1229
- if (b.length === 0) {
1230
- return 1
1231
- }
1232
-
1233
- const cmp = FateComparator(a.itemsType)
1234
- for (let i = 0; i < a.length; i++) {
1235
- // second list is shorter but matches as prefix of the first one
1236
- if (typeof b.items[i] === 'undefined') {
1237
- return 1
1238
- }
1239
-
1240
- // element difference
1241
- const diff = cmp(a.items[i], b.items[i])
1242
- if (diff !== 0) {
1243
- return diff
1244
- }
1245
- }
1246
-
1247
- // if there is no early return from the loop above
1248
- // then the first list match a prefix of the second
1249
-
1250
- // equal lists
1251
- if (a.length === b.length) {
1252
- return 0
1253
- }
1254
-
1255
- // first list is shorter, thus smaller
1256
- return -1
1257
- }
1258
-
1259
- const tupleComparator = (a, b) => {
1260
- if (a.size === 0) {
1261
- return -1
1262
- }
1263
-
1264
- const sizeDiff = a.size - b.size
1265
- if (sizeDiff !== 0) {
1266
- return sizeDiff
1267
- }
1268
-
1269
- // equal size - compare elements
1270
- for (let i = 0; i < a.size; i++) {
1271
- const valTypeA = a.valueTypes[i]
1272
-
1273
- // TODO support different types ?
1274
-
1275
- const diff = FateComparator(valTypeA)(a.items[i], b.items[i])
1276
- if (diff !== 0) {
1277
- return diff
1278
- }
1279
- }
1280
-
1281
- // equal tuples
1282
- return 0
1283
- }
1284
-
1285
- const variantComparator = (a, b) => {
1286
- const aDiff = a.arities.length - b.arities.length
1287
- if (aDiff !== 0) {
1288
- return aDiff
1289
- }
1290
-
1291
- const aList = new FateList(a.aritiesType, a.arities)
1292
- const bList = new FateList(b.aritiesType, b.arities)
1293
- const aComparator = FateComparator(aList)
1294
-
1295
- const lDiff = aComparator(aList, bList)
1296
- if (lDiff !== 0) {
1297
- return lDiff
1298
- }
1299
-
1300
- const tDiff = a.tag - b.tag
1301
- if (tDiff !== 0) {
1302
- return tDiff
1303
- }
1304
-
1305
- // equal arities and tags - compare elements
1306
- const elementsComparator = FateComparator(FateTypeTuple())
1307
-
1308
- return elementsComparator(
1309
- new FateTuple(a.valueTypes, a.value),
1310
- new FateTuple(b.valueTypes, b.value)
1311
- )
1312
- }
1313
-
1314
- const mapItemComparator = (type) => {
1315
- const keyComparator = FateComparator(type)
1316
- return (a, b) => keyComparator(a.key, b.key)
1317
- }
1318
-
1319
- const mapComparator = (a, b) => {
1320
- const aItems = [...a.items]
1321
- const bItems = [...b.items]
1322
-
1323
- aItems.sort(mapItemComparator(a.keyType))
1324
- bItems.sort(mapItemComparator(b.keyType))
1325
-
1326
- const keyComparator = FateComparator(a.keyType)
1327
- const valueComparator = FateComparator(a.valueType)
1328
-
1329
- for (let i = 0; i < aItems.length; i++) {
1330
- // second map is smaller (less items)
1331
- if (typeof bItems[i] === 'undefined') {
1332
- return 1
1333
- }
1334
-
1335
- const aItem = aItems[i]
1336
- const bItem = bItems[i]
1337
-
1338
- const kDiff = keyComparator(aItem.key, bItem.key)
1339
- if (kDiff !== 0) {
1340
- return kDiff
1341
- }
1342
-
1343
- const vDiff = valueComparator(aItem.value, bItem.value)
1344
- if (vDiff !== 0) {
1345
- return vDiff
1346
- }
1347
- }
1348
-
1349
- // equal number of items
1350
- if (aItems.length === bItems.length) {
1351
- return 0
1352
- }
1353
-
1354
- // first map item list is shorter, thus smaller
1355
- return -1
1356
- }
1357
-
1358
- const bytesComparator = (a, b) => {
1359
- const aList = new FateList(FateTypeInt(), a.valueOf())
1360
- const bList = new FateList(FateTypeInt(), b.valueOf())
1361
-
1362
- return listComparator(aList, bList)
1363
- }
1364
-
1365
- const stringComparator = (a, b) => {
1366
- const as = a.toString()
1367
- const bs = b.toString()
1368
-
1369
- if (as.length === bs.length) {
1370
- return as.localeCompare(bs)
1371
- }
1372
-
1373
- return as.length - bs.length
1374
- }
1375
-
1376
- const intComparator = (a, b) => Number(BigInt(a) - BigInt(b))
1377
- const boolComparator = (a, b) => a - b
1378
- const bitsComparator = (a, b) => {
1379
- return (a < 0 || b < 0) ? -intComparator(a, b) : intComparator(a, b)
1380
- }
1381
-
1382
- const comparators = {
1383
- 'int': intComparator,
1384
- 'bool': boolComparator,
1385
- 'string': stringComparator,
1386
- 'bits': bitsComparator,
1387
- // composite types
1388
- 'list': listComparator,
1389
- 'tuple': tupleComparator,
1390
- 'variant': variantComparator,
1391
- 'map': mapComparator,
1392
- // objects (bytes)
1393
- 'bytes': bytesComparator,
1394
- 'account_pubkey': bytesComparator,
1395
- 'channel': bytesComparator,
1396
- 'contract_pubkey': bytesComparator,
1397
- 'oracle_query_id': bytesComparator,
1398
- 'oracle_pubkey': bytesComparator,
1399
- }
1400
-
1401
- const FateComparator = (type) => {
1402
- assert(type.hasOwnProperty('name'), `Cannot determine type name of ${JSON.stringify(type)}`)
1403
- assert(comparators.hasOwnProperty(type.name), `Unsupported comparator for ${type.name}`)
1404
-
1405
- return comparators[type.name]
1406
- }
1407
-
1408
- module.exports = FateComparator
1409
-
1410
-
1411
- /***/ }),
1412
-
1413
- /***/ 105:
1414
- /***/ ((module) => {
1415
-
1416
- /* eslint-disable key-spacing, indent */
1417
-
1418
- // Definition of tag scheme.
1419
- // This has to follow the protocol specification.
1420
- module.exports = Object.freeze({
1421
- SMALL_INT : 0b0, // sxxxxxx 0 - 6 bit integer with sign bit
1422
- // 1 Set below
1423
- LONG_STRING : 0b00000001, // 000000 01 | RLP encoded array - when size >= 64
1424
- SHORT_STRING : 0b01, // xxxxxx 01 | [bytes] - when 0 < xxxxxx:size < 64
1425
- // 11 Set below
1426
- SHORT_LIST : 0b0011, // xxxx 0011 | [encoded elements] when 0 < length < 16
1427
- // xxxx 0111
1428
- // 1010 0111
1429
- // 1011 0111
1430
- // 1100 0111
1431
- // 1101 0111
1432
- // 0111 Set below
1433
- TYPE_INTEGER : 0b00000111, // 0000 0111 - Integer typedef
1434
- TYPE_BOOLEAN : 0b00010111, // 0001 0111 - Boolean typedef
1435
- TYPE_LIST : 0b00100111, // 0010 0111 | Type
1436
- TYPE_TUPLE : 0b00110111, // 0011 0111 | Size | [Element Types]
1437
- TYPE_OBJECT : 0b01000111, // 0100 0111 | ObjectType
1438
- TYPE_BITS : 0b01010111, // 0101 0111 - Bits typedef
1439
- TYPE_MAP : 0b01100111, // 0110 0111 | Type | Type
1440
- TYPE_STRING : 0b01110111, // 0111 0111 - string typedef
1441
- TYPE_VARIANT : 0b10000111, // 1000 0111 | [Arities] | [Type]
1442
- TYPE_BYTES : 0b10010111, // 1001 0111 - Bytes typedef
1443
- TYPE_CONTRACT_BYTEARRAY: 0b10100111, // 1010 0111 - Fate code typedef
1444
- // 1011 0111
1445
- // 1100 0111
1446
- // 1101 0111
1447
- TYPE_VAR : 0b11100111, // 1110 0111 | Id when 0 =< Id < 256 (type variable)
1448
- TYPE_ANY : 0b11110111, // 1111 0111 - Any typedef
1449
-
1450
- LONG_TUPLE : 0b00001011, // 0000 1011 | RLP encoded (size - 16) | [encoded elements],
1451
- SHORT_TUPLE : 0b1011, // xxxx 1011 | [encoded elements] when 0 < size < 16
1452
- // 1111 Set below
1453
- LONG_LIST : 0b00011111, // 0001 1111 | RLP encoded (length - 16) | [encoded elements]
1454
- MAP : 0b00101111, // 0010 1111 | RLP encoded size | [encoded key, encoded value]
1455
- EMPTY_TUPLE : 0b00111111, // 0011 1111
1456
- POS_BITS : 0b01001111, // 0100 1111 | RLP encoded integer (to be interpreted as bitfield)
1457
- EMPTY_STRING : 0b01011111, // 0101 1111
1458
- POS_BIG_INT : 0b01101111, // 0110 1111 | RLP encoded (integer - 64)
1459
- FALSE : 0b01111111, // 0111 1111
1460
- // 1000 1111 - FREE (Possibly for bytecode in the future.)
1461
- OBJECT : 0b10011111, // 1001 1111 | ObjectType | RLP encoded Array
1462
- VARIANT : 0b10101111, // 1010 1111 | [encoded arities] | encoded tag | [encoded values]
1463
- MAP_ID : 0b10111111, // 1011 1111 | RLP encoded integer (store map id)
1464
- NEG_BITS : 0b11001111, // 1100 1111 | RLP encoded integer (infinite 1:s bitfield)
1465
- EMPTY_MAP : 0b11011111, // 1101 1111
1466
- NEG_BIG_INT : 0b11101111, // 1110 1111 | RLP encoded (integer - 64)
1467
- TRUE : 0b11111111, // 1111 1111
1468
-
1469
- // Object types
1470
- OTYPE_ADDRESS : 0,
1471
- OTYPE_BYTES : 1,
1472
- OTYPE_CONTRACT : 2,
1473
- OTYPE_ORACLE : 3,
1474
- OTYPE_ORACLE_QUERY : 4,
1475
- OTYPE_CHANNEL : 5,
1476
- })
1477
-
1478
-
1479
- /***/ }),
1480
-
1481
- /***/ 4265:
1482
- /***/ ((module) => {
1483
-
1484
- const FateTypeVoid = () => {
1485
- return {name: 'void'}
1486
- }
1487
-
1488
- const FateTypeInt = () => {
1489
- return {name: 'int'}
1490
- }
1491
-
1492
- const FateTypeBool = () => {
1493
- return {name: 'bool'}
1494
- }
1495
-
1496
- const FateTypeString = () => {
1497
- return {name: 'string'}
1498
- }
1499
-
1500
- const FateTypeBits = () => {
1501
- return {name: 'bits'}
1502
- }
1503
-
1504
- const FateTypeBytes = (size) => {
1505
- return {name: 'bytes', size}
1506
- }
1507
-
1508
- const FateTypeHash = () => {
1509
- return {name: 'hash'}
1510
- }
1511
-
1512
- const FateTypeSignature = () => {
1513
- return {name: 'signature'}
1514
- }
1515
-
1516
- const FateTypeAccountAddress = () => {
1517
- return {name: 'account_pubkey'}
1518
- }
1519
-
1520
- const FateTypeContractAddress = () => {
1521
- return {name: 'contract_pubkey'}
1522
- }
1523
-
1524
- const FateTypeChannelAddress = () => {
1525
- return {name: 'channel'}
1526
- }
1527
-
1528
- const FateTypeOracleAddress = (questionType, answerType) => {
1529
- return {
1530
- name: 'oracle_pubkey',
1531
- questionType,
1532
- answerType
1533
- }
1534
- }
1535
-
1536
- const FateTypeOracleQueryAddress = (questionType, answerType) => {
1537
- return {
1538
- name: 'oracle_query_id',
1539
- questionType,
1540
- answerType
1541
- }
1542
- }
1543
-
1544
- const FateTypeByteArray = () => {
1545
- return {name: 'byte_array'}
1546
- }
1547
-
1548
- const FateTypeList = (valuesType) => {
1549
- return {
1550
- name: 'list',
1551
- valuesType,
1552
- }
1553
- }
1554
-
1555
- const FateTypeTuple = (valueTypes = []) => {
1556
- return {
1557
- name: 'tuple',
1558
- valueTypes
1559
- }
1560
- }
1561
-
1562
- const FateTypeRecord = (keys, valueTypes) => {
1563
- return {
1564
- name: 'record',
1565
- keys,
1566
- valueTypes,
1567
- }
1568
- }
1569
-
1570
- const FateTypeSet = (valuesType) => {
1571
- return {
1572
- name: 'set',
1573
- valuesType,
1574
- }
1575
- }
1576
-
1577
- const FateTypeMap = (keyType, valueType) => {
1578
- return {
1579
- name: 'map',
1580
- keyType,
1581
- valueType,
1582
- }
1583
- }
1584
-
1585
- const FateTypeVariant = (variants) => {
1586
- return {
1587
- name: 'variant',
1588
- variants,
1589
- }
1590
- }
1591
-
1592
- const FateTypeOption = (valueTypes) => {
1593
- const variants = [
1594
- { None: []},
1595
- { Some: valueTypes }
1596
- ]
1597
-
1598
- return FateTypeVariant(variants)
1599
- }
1600
-
1601
- const FateTypeChainTTL = () => {
1602
- const variants = [
1603
- {RelativeTTL: [FateTypeInt()]},
1604
- {FixedTTL: [FateTypeInt()]}
1605
- ]
1606
-
1607
- return FateTypeVariant(variants)
1608
- }
1609
-
1610
- const FateTypeChainGAMetaTx = () => {
1611
- const variants = [
1612
- {'Chain.GAMetaTx': [FateTypeAccountAddress(), FateTypeInt()]},
1613
- ]
1614
-
1615
- return FateTypeVariant(variants)
1616
- }
1617
-
1618
- const FateTypeChainPayingForTx = () => {
1619
- const variants = [
1620
- {'Chain.PayingForTx': [FateTypeAccountAddress(), FateTypeInt()]},
1621
- ]
1622
-
1623
- return FateTypeVariant(variants)
1624
- }
1625
-
1626
- const FateTypeChainBaseTx = () => {
1627
- const variants = [
1628
- {'Chain.SpendTx': [FateTypeAccountAddress(), FateTypeInt(), FateTypeString()]},
1629
- {'Chain.OracleRegisterTx': []},
1630
- {'Chain.OracleQueryTx': []},
1631
- {'Chain.OracleResponseTx': []},
1632
- {'Chain.OracleExtendTx': []},
1633
- {'Chain.NamePreclaimTx': []},
1634
- {'Chain.NameClaimTx': [FateTypeString()]},
1635
- {'Chain.NameUpdateTx': [FateTypeHash()]},
1636
- {'Chain.NameRevokeTx': [FateTypeHash()]},
1637
- {'Chain.NameTransferTx': [FateTypeAccountAddress(), FateTypeHash()]},
1638
- {'Chain.ChannelCreateTx': [FateTypeAccountAddress()]},
1639
- {'Chain.ChannelDepositTx': [FateTypeAccountAddress(), FateTypeInt()]},
1640
- {'Chain.ChannelWithdrawTx': [FateTypeAccountAddress(), FateTypeInt()]},
1641
- {'Chain.ChannelForceProgressTx': [FateTypeAccountAddress()]},
1642
- {'Chain.ChannelCloseMutualTx': [FateTypeAccountAddress()]},
1643
- {'Chain.ChannelCloseSoloTx': [FateTypeAccountAddress()]},
1644
- {'Chain.ChannelSlashTx': [FateTypeAccountAddress()]},
1645
- {'Chain.ChannelSettleTx': [FateTypeAccountAddress()]},
1646
- {'Chain.ChannelSnapshotSoloTx': [FateTypeAccountAddress()]},
1647
- {'Chain.ContractCreateTx': [FateTypeAccountAddress()]},
1648
- {'Chain.ContractCallTx': [FateTypeAccountAddress(), FateTypeInt()]},
1649
- {'Chain.GAAttachTx': []},
1650
- ]
1651
-
1652
- return FateTypeVariant(variants)
1653
- }
1654
-
1655
- const FateTypeAENSPointee = () => {
1656
- const variants = [
1657
- {'AENS.AccountPt': [FateTypeAccountAddress()]},
1658
- {'AENS.OraclePt': [FateTypeAccountAddress()]},
1659
- {'AENS.ContractPt': [FateTypeAccountAddress()]},
1660
- {'AENS.ChannelPt': [FateTypeAccountAddress()]},
1661
- ]
1662
-
1663
- return FateTypeVariant(variants)
1664
- }
1665
-
1666
- const FateTypeAENSName = () => {
1667
- const variants = [{
1668
- 'AENS.Name': [
1669
- FateTypeAccountAddress(),
1670
- FateTypeChainTTL(),
1671
- FateTypeMap(FateTypeString(), FateTypeAENSPointee())
1672
- ]
1673
- }]
1674
-
1675
- return FateTypeVariant(variants)
1676
- }
1677
-
1678
- const FateTypeEvent = (variantType, topics) => {
1679
- return {
1680
- name: 'event',
1681
- variantType,
1682
- topics,
1683
- }
1684
- }
1685
-
1686
- const FateTypeBls12381Fr = () => {
1687
- return {name: 'bls12_381.fr'}
1688
- }
1689
-
1690
- const FateTypeBls12381Fp = () => {
1691
- return {name: 'bls12_381.fp'}
1692
- }
1693
-
1694
- const FateTypeCalldata = (functionName, argumentTypes) => {
1695
- return {
1696
- name: 'calldata',
1697
- functionName,
1698
- argumentTypes,
1699
- }
1700
- }
1701
-
1702
- const FateTypeVar = (id) => {
1703
- return {
1704
- name: 'tvar',
1705
- id
1706
- }
1707
- }
1708
-
1709
- const FateTypeAny = () => {
1710
- return {name: 'any'}
1711
- }
1712
-
1713
- module.exports = {
1714
- FateTypeVoid,
1715
- FateTypeInt,
1716
- FateTypeBool,
1717
- FateTypeString,
1718
- FateTypeBits,
1719
- FateTypeBytes,
1720
- FateTypeHash,
1721
- FateTypeSignature,
1722
- FateTypeAccountAddress,
1723
- FateTypeContractAddress,
1724
- FateTypeChannelAddress,
1725
- FateTypeOracleAddress,
1726
- FateTypeOracleQueryAddress,
1727
- FateTypeByteArray,
1728
- FateTypeList,
1729
- FateTypeTuple,
1730
- FateTypeRecord,
1731
- FateTypeSet,
1732
- FateTypeMap,
1733
- FateTypeVariant,
1734
- FateTypeOption,
1735
- FateTypeChainTTL,
1736
- FateTypeChainGAMetaTx,
1737
- FateTypeChainPayingForTx,
1738
- FateTypeChainBaseTx,
1739
- FateTypeAENSPointee,
1740
- FateTypeAENSName,
1741
- FateTypeEvent,
1742
- FateTypeBls12381Fr,
1743
- FateTypeBls12381Fp,
1744
- FateTypeCalldata,
1745
- FateTypeVar,
1746
- FateTypeAny,
1747
- }
1748
-
1749
-
1750
- /***/ }),
1751
-
1752
- /***/ 880:
1753
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1754
-
1755
- const ApiEncoder = __webpack_require__(7200)
1756
- const {MontBytes2Int} = __webpack_require__(333)
1757
- const {ByteArray2Hex} = __webpack_require__(240)
1758
-
1759
- /**
1760
- * Map the internal representation FATE data structure to Aesophia canonical structures and formats.
1761
- */
1762
-
1763
- class CanonicalMapper {
1764
- constructor() {
1765
- this._apiEncoder = new ApiEncoder()
1766
- }
1767
-
1768
- toCanonical(data) {
1769
- return data.accept(this)
1770
- }
1771
-
1772
- visitData(acceptor) {
1773
- return acceptor.valueOf()
1774
- }
1775
-
1776
- visitAddress(acceptor) {
1777
- return this._apiEncoder.encode(acceptor.name, acceptor.value)
1778
- }
1779
-
1780
- visitList(acceptor) {
1781
- return acceptor.items.map(e => e.accept(this))
1782
- }
1783
-
1784
- visitSet(acceptor) {
1785
- return new Set(acceptor.items.map(e => e.accept(this)))
1786
- }
1787
-
1788
- visitMap(acceptor) {
1789
- const map = new Map()
1790
- for (const [key, value] of acceptor.iterator) {
1791
- map.set(key.accept(this), value.accept(this))
1792
- }
1793
-
1794
- return map
1795
- }
1796
-
1797
- visitTuple(acceptor) {
1798
- return acceptor.prepareItems(e => e.accept(this))
1799
- }
1800
-
1801
- visitVariant(acceptor) {
1802
- const value = acceptor.value.map(e => e.accept(this))
1803
-
1804
- if (acceptor.variantName === 'None') {
1805
- return undefined
1806
- }
1807
-
1808
- if (acceptor.variantName === 'Some') {
1809
- return value[0]
1810
- }
1811
-
1812
- return {
1813
- [acceptor.variantName]: value
1814
- }
1815
- }
1816
-
1817
- visitBls12381Fr(acceptor) {
1818
- return MontBytes2Int(acceptor.valueOf(), 'r')
1819
- }
1820
-
1821
- visitBls12381Fp(acceptor) {
1822
- return MontBytes2Int(acceptor.valueOf(), 'p')
1823
- }
1824
-
1825
- visitCalldata(acceptor) {
1826
- const {functionId, args} = acceptor.valueOf()
1827
-
1828
- return {
1829
- functionId: ByteArray2Hex(functionId),
1830
- args: args.map(e => e.accept(this))
1831
- }
1832
- }
1833
- }
1834
-
1835
- module.exports = CanonicalMapper
1836
-
1837
-
1838
- /***/ }),
1839
-
1840
- /***/ 1338:
1841
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1842
-
1843
- const ApiEncoder = __webpack_require__(7200)
1844
- const {Int2MontBytes} = __webpack_require__(333)
1845
- const FateTypeError = __webpack_require__(5110)
1846
-
1847
- /**
1848
- * Map Aesophia canonical structures and formats to internal representation FATE data structures.
1849
- */
1850
- class InternalMapper {
1851
- constructor() {
1852
- this._apiEncoder = new ApiEncoder()
1853
- }
1854
-
1855
- toInternal(type, value) {
1856
- switch (type.name) {
1857
- case 'account_pubkey':
1858
- case 'contract_pubkey':
1859
- case 'channel':
1860
- case 'oracle_pubkey':
1861
- case 'oracle_query_id':
1862
- return this.toAddress(type, value)
1863
- case 'variant':
1864
- return this.toVariant(type, value)
1865
- case 'map':
1866
- return this.toMap(type, value)
1867
- case 'set':
1868
- return this.toSet(type, value)
1869
- case 'record':
1870
- return this.toRecord(type, value)
1871
- case 'bls12_381.fr':
1872
- return this.toBls12381Fr(type, value)
1873
- case 'bls12_381.fp':
1874
- return this.toBls12381Fp(type, value)
1875
- default:
1876
- return value
1877
- }
1878
- }
1879
-
1880
- toAddress({name, _}, value) {
1881
- return this._apiEncoder.decodeWithType(value, name)
1882
- }
1883
-
1884
- toVariant(type, value) {
1885
- if (!this.isOptionVariant(type)) {
1886
- return value
1887
- }
1888
-
1889
- if ([undefined, null].includes(value)) {
1890
- return {None: []}
1891
- }
1892
-
1893
- const [variantName] = Object.keys(value)
1894
- if (['Some', 'None'].includes(variantName)) {
1895
- return value
1896
- }
1897
-
1898
- return {Some: [value]}
1899
- }
1900
-
1901
- isOptionVariant({ _name, variants }) {
1902
- return variants.some(({ None }) => None && None.length === 0)
1903
- && variants.some(({ Some }) => Some)
1904
- }
1905
-
1906
- toMap(type, value) {
1907
- if (typeof value !== 'object' || value === null) {
1908
- throw new FateTypeError(
1909
- 'map',
1910
- `Fate map must be one of: Map, Array, Object; got ${value} instead`
1911
- )
1912
- }
1913
-
1914
- return Array.isArray(value) || value instanceof Map ? value : Object.entries(value)
1915
- }
1916
-
1917
- toSet(type, value) {
1918
- if (value instanceof Set) {
1919
- return value
1920
- }
1921
-
1922
- if (Array.isArray(value)) {
1923
- return new Set(value)
1924
- }
1925
-
1926
- throw new FateTypeError(
1927
- 'set',
1928
- `Fate set must be a Set or Array, got "${value}" instead`
1929
- )
1930
- }
1931
-
1932
- toRecord(type, record) {
1933
- return type.keys.reduce((v, name) => ({ ...v, [name]: record[name] }), {})
1934
- }
1935
-
1936
- validateBls12381Field(type, value) {
1937
- if (typeof value !== 'bigint' && !Number.isInteger(value)) {
1938
- throw new FateTypeError(
1939
- type.name,
1940
- `Should be one of: BigInt or Number; got ${value} instead`
1941
- )
1942
- }
1943
- }
1944
-
1945
- toBls12381Fr(type, value) {
1946
- this.validateBls12381Field(type, value)
1947
-
1948
- return Int2MontBytes(value, 'r')
1949
- }
1950
-
1951
- toBls12381Fp(type, value) {
1952
- this.validateBls12381Field(type, value)
1953
-
1954
- return Int2MontBytes(value, 'p')
1955
- }
1956
- }
1957
-
1958
- module.exports = InternalMapper
1959
-
1960
-
1961
- /***/ }),
1962
-
1963
- /***/ 7829:
1964
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1965
-
1966
- const TypeFactory = __webpack_require__(2584)
1967
- const FateData = __webpack_require__(9865)
1968
- const BaseSerializer = __webpack_require__(8268)
1969
- const AddressSerializer = __webpack_require__(9135)
1970
- const BitsSerializer = __webpack_require__(1290)
1971
- const BoolSerializer = __webpack_require__(4857)
1972
- const ByteArraySerializer = __webpack_require__(8183)
1973
- const BytesSerializer = __webpack_require__(6651)
1974
- const ChannelSerializer = __webpack_require__(3234)
1975
- const ContractSerializer = __webpack_require__(4150)
1976
- const IntSerializer = __webpack_require__(2086)
1977
- const VoidSerializer = __webpack_require__(34)
1978
- const ListSerializer = __webpack_require__(2137)
1979
- const SetSerializer = __webpack_require__(6210)
1980
- const MapSerializer = __webpack_require__(692)
1981
- const OracleQuerySerializer = __webpack_require__(4266)
1982
- const OracleSerializer = __webpack_require__(1751)
1983
- const StringSerializer = __webpack_require__(6973)
1984
- const TupleSerializer = __webpack_require__(6178)
1985
- const VariantSerializer = __webpack_require__(9503)
1986
- const Bls12381FieldSerializer = __webpack_require__(5547)
1987
- const CalldataSerializer = __webpack_require__(4276)
1988
- const SerializerError = __webpack_require__(9098)
1989
-
1990
- class Serializer extends BaseSerializer {
1991
- constructor() {
1992
- super()
1993
-
1994
- this.typeFactory = new TypeFactory()
1995
- this._serializers = {
1996
- 'void': new VoidSerializer(),
1997
- 'bool': new BoolSerializer(),
1998
- 'int': new IntSerializer(),
1999
- 'tuple': new TupleSerializer(this),
2000
- 'record': new TupleSerializer(this),
2001
- 'list': new ListSerializer(this),
2002
- 'set': new SetSerializer(this),
2003
- 'map': new MapSerializer(this),
2004
- 'byte_array': new ByteArraySerializer(),
2005
- 'string': new StringSerializer(),
2006
- 'hash': new BytesSerializer(),
2007
- 'signature': new BytesSerializer(),
2008
- 'bits': new BitsSerializer(),
2009
- 'variant': new VariantSerializer(this),
2010
- 'bytes': new BytesSerializer(),
2011
- 'account_pubkey': new AddressSerializer(),
2012
- 'contract_pubkey': new ContractSerializer(),
2013
- 'oracle_pubkey': new OracleSerializer(),
2014
- 'oracle_query_id': new OracleQuerySerializer(),
2015
- 'channel': new ChannelSerializer(),
2016
- 'bls12_381.fr': new Bls12381FieldSerializer(),
2017
- 'bls12_381.fp': new Bls12381FieldSerializer(),
2018
- 'calldata': new CalldataSerializer(this),
2019
- }
2020
- }
2021
-
2022
- _getSerializer(type) {
2023
- if (!type.hasOwnProperty('name')) {
2024
- throw new SerializerError('Unsupported type: ' + JSON.stringify(type))
2025
- }
2026
-
2027
- const typeName = type.name
2028
- if (!this._serializers.hasOwnProperty(typeName)) {
2029
- throw new SerializerError('Unsupported type: ' + JSON.stringify(typeName))
2030
- }
2031
-
2032
- return this._serializers[typeName]
2033
- }
2034
-
2035
- serialize(data) {
2036
- if (typeof data !== 'object') {
2037
- throw new SerializerError('Only object serialization is supported. Got: ' + JSON.stringify(data))
2038
- }
2039
-
2040
- if (!(data instanceof FateData)) {
2041
- throw new SerializerError('Only instances of FateData is supported.')
2042
- }
2043
-
2044
- return this._getSerializer(data).serialize(data)
2045
- }
2046
-
2047
- deserializeWithType(data, type) {
2048
- if (!(data instanceof Uint8Array)) {
2049
- throw new SerializerError('Only instances of Uint8Array is supported.')
2050
- }
2051
-
2052
- return this._getSerializer(type).deserialize(data, type)
2053
- }
2054
-
2055
- deserialize(data) {
2056
- if (!(data instanceof Uint8Array)) {
2057
- throw new SerializerError('Only instances of Uint8Array is supported.')
2058
- }
2059
-
2060
- const type = this.typeFactory.createType(data)
2061
-
2062
- return this.deserializeWithType(data, type)
2063
- }
2064
-
2065
- deserializeStream(data, typeInfo) {
2066
- if (!(data instanceof Uint8Array)) {
2067
- throw new SerializerError('Only instances of Uint8Array is supported.')
2068
- }
2069
-
2070
- let type = typeInfo
2071
- if (typeof typeInfo === 'undefined') {
2072
- type = this.typeFactory.createType(data)
2073
- }
2074
-
2075
- return this._getSerializer(type).deserializeStream(data, typeInfo)
2076
- }
2077
- }
2078
-
2079
- module.exports = Serializer
2080
-
2081
-
2082
- /***/ }),
2083
-
2084
- /***/ 9135:
2085
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2086
-
2087
- const RLP = __webpack_require__(3485)
2088
- const FateTag = __webpack_require__(105)
2089
- const BaseSerializer = __webpack_require__(8268)
2090
- const FateAccountAddress = __webpack_require__(539)
2091
-
2092
- class AddressSerializer extends BaseSerializer {
2093
- serialize(data) {
2094
- return [
2095
- FateTag.OBJECT,
2096
- FateTag.OTYPE_ADDRESS,
2097
- ...RLP.encode(data.value)
2098
- ]
2099
- }
2100
-
2101
- deserializeStream(data) {
2102
- const buffer = new Uint8Array(data)
2103
- const decoded = RLP.decode(buffer.slice(2), true)
2104
-
2105
- return [
2106
- new FateAccountAddress(decoded.data),
2107
- new Uint8Array(decoded.remainder)
2108
- ]
2109
- }
2110
- }
2111
-
2112
- module.exports = AddressSerializer
2113
-
2114
-
2115
- /***/ }),
2116
-
2117
- /***/ 8268:
2118
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2119
-
2120
- const SerializerError = __webpack_require__(9098)
2121
-
2122
- class BaseSerializer {
2123
- constructor(globalSerializer) {
2124
- this.globalSerializer = globalSerializer
2125
- }
2126
-
2127
- serialize(_data) {
2128
- throw new SerializerError('Not implemented.')
2129
- }
2130
-
2131
- deserialize(data, typeInfo) {
2132
- const [value, _rest] = this.deserializeStream(data, typeInfo)
2133
-
2134
- return value
2135
- }
2136
-
2137
- deserializeStream(_data, _typeInfo) {
2138
- throw new SerializerError('Not implemented.')
2139
- }
2140
- }
2141
-
2142
- module.exports = BaseSerializer
2143
-
2144
-
2145
- /***/ }),
2146
-
2147
- /***/ 1290:
2148
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2149
-
2150
- const FateTag = __webpack_require__(105)
2151
- const RLPInt = __webpack_require__(7138)
2152
- const FateBits = __webpack_require__(3422)
2153
- const BaseSerializer = __webpack_require__(8268)
2154
- const abs = __webpack_require__(9475)
2155
-
2156
- class BitsSerializer extends BaseSerializer {
2157
- serialize(data) {
2158
- const prefix = data.value >= 0 ? FateTag.POS_BITS : FateTag.NEG_BITS
2159
-
2160
- return [
2161
- prefix,
2162
- ...RLPInt.encode(abs(data.value))
2163
- ]
2164
- }
2165
-
2166
- deserializeStream(data) {
2167
- const buffer = new Uint8Array(data)
2168
- const sign = buffer[0] === FateTag.POS_BITS ? 1n : -1n
2169
- const [i, remainder] = RLPInt.decode(buffer.slice(1))
2170
-
2171
- return [
2172
- new FateBits(i * sign),
2173
- new Uint8Array(remainder)
2174
- ]
2175
- }
2176
- }
2177
-
2178
- module.exports = BitsSerializer
2179
-
2180
-
2181
- /***/ }),
2182
-
2183
- /***/ 5547:
2184
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2185
-
2186
- const BaseSerializer = __webpack_require__(8268)
2187
- const BytesSerializer = __webpack_require__(6651)
2188
- const FateBls12381Fr = __webpack_require__(1565)
2189
- const FateBls12381Fp = __webpack_require__(4077)
2190
-
2191
- const bytesSerializer = new BytesSerializer()
2192
-
2193
- const factory = (type, data) => {
2194
- switch (type.name) {
2195
- case 'bls12_381.fr':
2196
- return new FateBls12381Fr(data)
2197
- case 'bls12_381.fp':
2198
- return new FateBls12381Fp(data)
2199
- default:
2200
- throw new Error(`Unsupported type "${type.name}"`)
2201
- }
2202
- }
2203
-
2204
- class Bls12381FieldSerializer extends BaseSerializer {
2205
- serialize(bytes) {
2206
- return bytesSerializer.serialize(bytes)
2207
- }
2208
-
2209
- deserializeStream(data, typeInfo) {
2210
- const [bytes, rest] = bytesSerializer.deserializeStream(data)
2211
-
2212
- return [
2213
- factory(typeInfo, bytes.valueOf()),
2214
- rest
2215
- ]
2216
- }
2217
- }
2218
-
2219
- module.exports = Bls12381FieldSerializer
2220
-
2221
-
2222
- /***/ }),
2223
-
2224
- /***/ 4857:
2225
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2226
-
2227
- const FateTag = __webpack_require__(105)
2228
- const FateBool = __webpack_require__(4476)
2229
- const BaseSerializer = __webpack_require__(8268)
2230
- const FatePrefixError = __webpack_require__(5462)
2231
-
2232
- class BoolSerializer extends BaseSerializer {
2233
- serialize(data) {
2234
- return (data.valueOf() === true) ? [FateTag.TRUE] : [FateTag.FALSE]
2235
- }
2236
-
2237
- deserializeStream(data) {
2238
- const buffer = new Uint8Array(data)
2239
- const prefix = buffer[0]
2240
- const rest = buffer.slice(1)
2241
-
2242
- if (prefix === FateTag.TRUE) {
2243
- return [new FateBool(true), rest]
2244
- }
2245
-
2246
- if (prefix === FateTag.FALSE) {
2247
- return [new FateBool(false), rest]
2248
- }
2249
-
2250
- throw new FatePrefixError(prefix)
2251
- }
2252
- }
2253
-
2254
- module.exports = BoolSerializer
2255
-
2256
-
2257
- /***/ }),
2258
-
2259
- /***/ 8183:
2260
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2261
-
2262
- const FateTag = __webpack_require__(105)
2263
- const BaseSerializer = __webpack_require__(8268)
2264
- const FateByteArray = __webpack_require__(7945)
2265
- const IntSerializer = __webpack_require__(2086)
2266
-
2267
- const intSerializer = new IntSerializer()
2268
-
2269
- class ByteArraySerializer extends BaseSerializer {
2270
- serialize(data) {
2271
- if (data.length === 0) {
2272
- return [FateTag.EMPTY_STRING]
2273
- }
2274
-
2275
- if (data.length < 64) {
2276
- const prefix = (data.length << 2) | FateTag.SHORT_STRING
2277
-
2278
- return [
2279
- prefix,
2280
- ...data.valueOf()
2281
- ]
2282
- }
2283
-
2284
- return [
2285
- FateTag.LONG_STRING,
2286
- ...intSerializer.serialize(data.length - 64),
2287
- ...data.valueOf()
2288
- ]
2289
- }
2290
-
2291
- deserializeStream(stream) {
2292
- const data = new Uint8Array(stream)
2293
- const prefix = data[0]
2294
-
2295
- if (prefix === FateTag.EMPTY_STRING) {
2296
- return [
2297
- new FateByteArray(),
2298
- data.slice(1)
2299
- ]
2300
- }
2301
-
2302
- if (prefix === FateTag.LONG_STRING) {
2303
- const [fateLen, rest] = intSerializer.deserializeStream(data.slice(1))
2304
- const len = Number(fateLen.valueOf()) + 64
2305
-
2306
- return [
2307
- new FateByteArray(rest.slice(0, len)),
2308
- rest.slice(len)
2309
- ]
2310
- }
2311
-
2312
- // short string
2313
- const offset = (prefix >> 2) + 1
2314
-
2315
- return [
2316
- new FateByteArray(data.slice(1, offset)),
2317
- data.slice(offset)
2318
- ]
2319
- }
2320
- }
2321
-
2322
- module.exports = ByteArraySerializer
2323
-
2324
-
2325
- /***/ }),
2326
-
2327
- /***/ 6651:
2328
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2329
-
2330
- const FateTag = __webpack_require__(105)
2331
- const ByteArraySerializer = __webpack_require__(8183)
2332
- const FateBytes = __webpack_require__(5779)
2333
- const BaseSerializer = __webpack_require__(8268)
2334
-
2335
- const byteArraySerializer = new ByteArraySerializer()
2336
-
2337
- class BytesSerializer extends BaseSerializer {
2338
- serialize(bytes) {
2339
- return [
2340
- FateTag.OBJECT,
2341
- FateTag.OTYPE_BYTES,
2342
- ...byteArraySerializer.serialize(bytes.value)
2343
- ]
2344
- }
2345
-
2346
- deserializeStream(data) {
2347
- const buffer = new Uint8Array(data)
2348
- const [bytes, rest] = byteArraySerializer.deserializeStream(buffer.slice(2))
2349
-
2350
- return [
2351
- new FateBytes(bytes.valueOf()),
2352
- rest
2353
- ]
2354
- }
2355
- }
2356
-
2357
- module.exports = BytesSerializer
2358
-
2359
-
2360
- /***/ }),
2361
-
2362
- /***/ 4276:
2363
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2364
-
2365
- const FateTuple = __webpack_require__(6878)
2366
- const FateCalldata = __webpack_require__(7255)
2367
- const FateByteArray = __webpack_require__(7945)
2368
- const BaseSerializer = __webpack_require__(8268)
2369
- const {FateTypeTuple, FateTypeByteArray} = __webpack_require__(4265)
2370
-
2371
- class CalldataSerializer extends BaseSerializer {
2372
- serialize(calldata) {
2373
- const funcBytes = new FateByteArray(calldata.functionId)
2374
- const argsTuple = new FateTuple(calldata.argTypes, calldata.args)
2375
-
2376
- const calldataTuple = new FateTuple(
2377
- [funcBytes.type, argsTuple.type],
2378
- [funcBytes, argsTuple]
2379
- )
2380
-
2381
- return this.globalSerializer.serialize(calldataTuple)
2382
- }
2383
-
2384
- deserialize(data, typeInfo) {
2385
- const calldataType = FateTypeTuple([
2386
- FateTypeByteArray(),
2387
- FateTypeTuple(typeInfo.argumentTypes)
2388
- ])
2389
-
2390
- const [calldataTuple,] = this.globalSerializer.deserializeStream(data, calldataType)
2391
- const [functionId, argsTuple] = calldataTuple.items
2392
-
2393
- return new FateCalldata(functionId.valueOf(), argsTuple.valueTypes, argsTuple.items)
2394
- }
2395
- }
2396
-
2397
- module.exports = CalldataSerializer
2398
-
2399
-
2400
- /***/ }),
2401
-
2402
- /***/ 3234:
2403
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2404
-
2405
- const RLP = __webpack_require__(3485)
2406
- const FateTag = __webpack_require__(105)
2407
- const BaseSerializer = __webpack_require__(8268)
2408
- const FateChannelAddress = __webpack_require__(6445)
2409
-
2410
- class ChannelSerializer extends BaseSerializer {
2411
- serialize(data) {
2412
- return [
2413
- FateTag.OBJECT,
2414
- FateTag.OTYPE_CHANNEL,
2415
- ...RLP.encode(data.value)
2416
- ]
2417
- }
2418
-
2419
- deserializeStream(data) {
2420
- const buffer = new Uint8Array(data)
2421
- const decoded = RLP.decode(buffer.slice(2), true)
2422
-
2423
- return [
2424
- new FateChannelAddress(decoded.data),
2425
- new Uint8Array(decoded.remainder)
2426
- ]
2427
- }
2428
- }
2429
-
2430
- module.exports = ChannelSerializer
2431
-
2432
-
2433
- /***/ }),
2434
-
2435
- /***/ 4150:
2436
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2437
-
2438
- const RLP = __webpack_require__(3485)
2439
- const FateTag = __webpack_require__(105)
2440
- const BaseSerializer = __webpack_require__(8268)
2441
- const FateContractAddress = __webpack_require__(8623)
2442
-
2443
- class ContractSerializer extends BaseSerializer {
2444
- serialize(data) {
2445
- return [
2446
- FateTag.OBJECT,
2447
- FateTag.OTYPE_CONTRACT,
2448
- ...RLP.encode(data.value)
2449
- ]
2450
- }
2451
-
2452
- deserializeStream(data) {
2453
- const buffer = new Uint8Array(data)
2454
- const decoded = RLP.decode(buffer.slice(2), true)
2455
-
2456
- return [
2457
- new FateContractAddress(decoded.data),
2458
- new Uint8Array(decoded.remainder)
2459
- ]
2460
- }
2461
- }
2462
-
2463
- module.exports = ContractSerializer
2464
-
2465
-
2466
- /***/ }),
2467
-
2468
- /***/ 2086:
2469
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2470
-
2471
- const FateTag = __webpack_require__(105)
2472
- const RLPInt = __webpack_require__(7138)
2473
- const FateInt = __webpack_require__(3509)
2474
- const BaseSerializer = __webpack_require__(8268)
2475
- const FatePrefixError = __webpack_require__(5462)
2476
- const abs = __webpack_require__(9475)
2477
-
2478
- const SMALL_INT_MASK = 0b00000001
2479
-
2480
- class IntSerializer extends BaseSerializer {
2481
- serialize(data) {
2482
- const bigValue = (data instanceof FateInt) ? data.value : BigInt(data)
2483
- const absVal = abs(bigValue)
2484
-
2485
- // small integer
2486
- if (absVal < 64) {
2487
- const small = Number(absVal)
2488
- if (bigValue >= 0) {
2489
- return [(small << 1)]
2490
- }
2491
-
2492
- // negative
2493
- return [(0b10000000 | (small << 1)) & 0b11111110]
2494
- }
2495
-
2496
- // large negative integer
2497
- if (bigValue < 0) {
2498
- return [
2499
- FateTag.NEG_BIG_INT,
2500
- ...RLPInt.encode(absVal - 64n)
2501
- ]
2502
- }
2503
-
2504
- // large positive integer
2505
- return [
2506
- FateTag.POS_BIG_INT,
2507
- ...RLPInt.encode(absVal - 64n)
2508
- ]
2509
- }
2510
-
2511
- deserializeStream(stream) {
2512
- const data = new Uint8Array(stream)
2513
- const prefix = data[0]
2514
-
2515
- // small int
2516
- if ((prefix & SMALL_INT_MASK) === 0) {
2517
- // positive
2518
- if ((prefix & 0b10000000) === 0) {
2519
- return [
2520
- new FateInt(prefix >> 1),
2521
- data.slice(1)
2522
- ]
2523
- }
2524
-
2525
- // negative
2526
- const i = (prefix & 0b01111110) >> 1
2527
-
2528
- return [
2529
- new FateInt(-i),
2530
- data.slice(1)
2531
- ]
2532
- }
2533
-
2534
- if (prefix === FateTag.POS_BIG_INT || prefix === FateTag.NEG_BIG_INT) {
2535
- const sign = prefix === FateTag.POS_BIG_INT ? 1n : -1n
2536
- const [i, remainder] = RLPInt.decode(data.slice(1))
2537
-
2538
- return [
2539
- new FateInt((i + 64n) * sign),
2540
- new Uint8Array(remainder)
2541
- ]
2542
- }
2543
-
2544
- throw new FatePrefixError(prefix)
2545
- }
2546
- }
2547
-
2548
- module.exports = IntSerializer
2549
-
2550
-
2551
- /***/ }),
2552
-
2553
- /***/ 2137:
2554
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2555
-
2556
- const RLPInt = __webpack_require__(7138)
2557
- const FateTag = __webpack_require__(105)
2558
- const FateList = __webpack_require__(1041)
2559
- const BaseSerializer = __webpack_require__(8268)
2560
-
2561
- class ListSerializer extends BaseSerializer {
2562
- serialize(list) {
2563
- const serializedElements = list.items.map(e => {
2564
- return this.globalSerializer.serialize(e)
2565
- }).flat(Infinity)
2566
-
2567
- const len = list.items.length
2568
-
2569
- if (len < 16) {
2570
- const prefix = (len << 4) | FateTag.SHORT_LIST
2571
-
2572
- return [
2573
- prefix,
2574
- ...serializedElements
2575
- ]
2576
- }
2577
-
2578
- return [
2579
- FateTag.LONG_LIST,
2580
- ...RLPInt.encode(len - 16),
2581
- ...serializedElements
2582
- ]
2583
- }
2584
-
2585
- deserializeStream(data, typeInfo) {
2586
- const buffer = new Uint8Array(data)
2587
- const prefix = buffer[0]
2588
- let len = 0n
2589
- let rest = buffer.slice(1)
2590
-
2591
- if (prefix === FateTag.LONG_LIST) {
2592
- [len, rest] = RLPInt.decode(buffer.slice(1))
2593
- len += 16n
2594
- }
2595
-
2596
- if ((prefix & 0x0F) === FateTag.SHORT_LIST) {
2597
- len = BigInt((prefix & 0xF0) >> 4)
2598
- }
2599
-
2600
- let itemsType
2601
-
2602
- if (typeof typeInfo !== 'undefined') {
2603
- itemsType = typeInfo.valuesType
2604
- }
2605
-
2606
- let el
2607
- const elements = []
2608
-
2609
- for (let i = 0n; i < len; i++) {
2610
- [el, rest] = this.globalSerializer.deserializeStream(rest, itemsType)
2611
- elements.push(el)
2612
- }
2613
-
2614
- if (len === 0n) {
2615
- return [new FateList(), rest]
2616
- }
2617
-
2618
- if (typeof typeInfo === 'undefined') {
2619
- itemsType = elements[0].type
2620
- }
2621
-
2622
- return [
2623
- new FateList(itemsType, elements),
2624
- rest
2625
- ]
2626
- }
2627
- }
2628
-
2629
- module.exports = ListSerializer
2630
-
2631
-
2632
- /***/ }),
2633
-
2634
- /***/ 692:
2635
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2636
-
2637
- const FateTag = __webpack_require__(105)
2638
- const RLPInt = __webpack_require__(7138)
2639
- const BaseSerializer = __webpack_require__(8268)
2640
- const FateComparator = __webpack_require__(2689)
2641
- const FateMap = __webpack_require__(8804)
2642
- const FatePrefixError = __webpack_require__(5462)
2643
-
2644
- class MapSerializer extends BaseSerializer {
2645
- serialize(map) {
2646
- const len = map.length
2647
- const cmp = FateComparator(map.keyType)
2648
-
2649
- const sortedItems = [...map.items]
2650
- sortedItems.sort((elA, elB) => cmp(elA.key, elB.key))
2651
-
2652
- const serializedItems = sortedItems.map(i => {
2653
- return [
2654
- this.globalSerializer.serialize(i.key),
2655
- this.globalSerializer.serialize(i.value)
2656
- ]
2657
- })
2658
-
2659
- return [
2660
- FateTag.MAP,
2661
- ...RLPInt.encode(len),
2662
- ...serializedItems.flat(Infinity)
2663
- ]
2664
- }
2665
-
2666
- deserializeStream(data, typeInfo) {
2667
- const buffer = new Uint8Array(data)
2668
- const prefix = buffer[0]
2669
-
2670
- if (prefix !== FateTag.MAP) {
2671
- throw new FatePrefixError(prefix)
2672
- }
2673
-
2674
- const [len, remainder] = RLPInt.decode(buffer.slice(1))
2675
- let rest = remainder
2676
-
2677
- if (len === 0n) {
2678
- return [new FateMap(), rest]
2679
- }
2680
-
2681
- let keyType
2682
- let valueType
2683
-
2684
- if (typeof typeInfo !== 'undefined') {
2685
- ({keyType, valueType} = typeInfo)
2686
- }
2687
-
2688
- const elements = []
2689
- for (let i = 0n; i < len; i++) {
2690
- const [key, keyRest] = this.globalSerializer.deserializeStream(rest, keyType)
2691
- const [value, valueRest] = this.globalSerializer.deserializeStream(keyRest, valueType)
2692
-
2693
- elements.push([key, value])
2694
- rest = valueRest
2695
- }
2696
-
2697
- const firstEl = elements[0]
2698
-
2699
- if (typeof typeInfo === 'undefined') {
2700
- keyType = firstEl[0].type
2701
- valueType = firstEl[1].type
2702
- }
2703
-
2704
- return [
2705
- new FateMap(
2706
- keyType,
2707
- valueType,
2708
- elements
2709
- ),
2710
- rest
2711
- ]
2712
- }
2713
- }
2714
-
2715
- module.exports = MapSerializer
2716
-
2717
-
2718
- /***/ }),
2719
-
2720
- /***/ 4266:
2721
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2722
-
2723
- const RLP = __webpack_require__(3485)
2724
- const FateTag = __webpack_require__(105)
2725
- const BaseSerializer = __webpack_require__(8268)
2726
- const FateOracleQueryAddress = __webpack_require__(5070)
2727
-
2728
- class OracleQuerySerializer extends BaseSerializer {
2729
- serialize(data) {
2730
- return [
2731
- FateTag.OBJECT,
2732
- FateTag.OTYPE_ORACLE_QUERY,
2733
- ...RLP.encode(data.value)
2734
- ]
2735
- }
2736
-
2737
- deserializeStream(data) {
2738
- const buffer = new Uint8Array(data)
2739
- const decoded = RLP.decode(buffer.slice(2), true)
2740
-
2741
- return [
2742
- new FateOracleQueryAddress(decoded.data),
2743
- new Uint8Array(decoded.remainder)
2744
- ]
2745
- }
2746
- }
2747
-
2748
- module.exports = OracleQuerySerializer
2749
-
2750
-
2751
- /***/ }),
2752
-
2753
- /***/ 1751:
2754
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2755
-
2756
- const RLP = __webpack_require__(3485)
2757
- const FateTag = __webpack_require__(105)
2758
- const BaseSerializer = __webpack_require__(8268)
2759
- const FateOracleAddress = __webpack_require__(687)
2760
-
2761
- class OracleSerializer extends BaseSerializer {
2762
- serialize(data) {
2763
- return [
2764
- FateTag.OBJECT,
2765
- FateTag.OTYPE_ORACLE,
2766
- ...RLP.encode(data.value)
2767
- ]
2768
- }
2769
-
2770
- deserializeStream(data) {
2771
- const buffer = new Uint8Array(data)
2772
- const decoded = RLP.decode(buffer.slice(2), true)
2773
-
2774
- return [
2775
- new FateOracleAddress(decoded.data),
2776
- new Uint8Array(decoded.remainder)
2777
- ]
2778
- }
2779
- }
2780
-
2781
- module.exports = OracleSerializer
2782
-
2783
-
2784
- /***/ }),
2785
-
2786
- /***/ 6210:
2787
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2788
-
2789
- const BaseSerializer = __webpack_require__(8268)
2790
- const {FateTypeTuple, FateTypeMap} = __webpack_require__(4265)
2791
- const FateMap = __webpack_require__(8804)
2792
- const FateTuple = __webpack_require__(6878)
2793
- const FateSet = __webpack_require__(2548)
2794
-
2795
- // This serializer takes advantages of the singular tuple optimization directly
2796
- // An alternative implementation would be building the full structure
2797
- // and pass it upstream for optimization.
2798
- // Unbox singleton tuples and records
2799
- // https://github.com/aeternity/aesophia/pull/205
2800
- // https://github.com/aeternity/aesophia/commit/a403a9d227ac56266cf5bb8fbc916f17e6141d15
2801
-
2802
- class SetSerializer extends BaseSerializer {
2803
- serialize(set) {
2804
- return this.globalSerializer.serialize(new FateMap(
2805
- set.itemsType,
2806
- FateTypeTuple(),
2807
- set.items.map(i => [i, new FateTuple()])
2808
- ))
2809
- }
2810
-
2811
- deserializeStream(data, typeInfo) {
2812
- const mapType = FateTypeMap(typeInfo.valuesType, FateTypeTuple())
2813
- const [map, rest] = this.globalSerializer.deserializeStream(data, mapType)
2814
-
2815
- return [
2816
- new FateSet(typeInfo.valuesType, map.keys),
2817
- rest
2818
- ]
2819
- }
2820
- }
2821
-
2822
- module.exports = SetSerializer
2823
-
2824
-
2825
- /***/ }),
2826
-
2827
- /***/ 6973:
2828
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2829
-
2830
- const FateTag = __webpack_require__(105)
2831
- const BaseSerializer = __webpack_require__(8268)
2832
- const ByteArraySerializer = __webpack_require__(8183)
2833
- const FateString = __webpack_require__(6313)
2834
- const FatePrefixError = __webpack_require__(5462)
2835
-
2836
- const byteArraySerializer = new ByteArraySerializer()
2837
-
2838
- class StringSerializer extends BaseSerializer {
2839
- serialize(value) {
2840
- const encoder = new TextEncoder()
2841
- const bytes = encoder.encode(value)
2842
-
2843
- return byteArraySerializer.serialize(bytes)
2844
- }
2845
-
2846
- deserializeStream(data) {
2847
- const buffer = new Uint8Array(data)
2848
- const prefix = buffer[0]
2849
-
2850
- if (
2851
- (prefix & 0b11) !== FateTag.SHORT_STRING
2852
- && ![FateTag.EMPTY_STRING, FateTag.LONG_STRING].includes(prefix)
2853
- ) {
2854
- throw new FatePrefixError(prefix)
2855
- }
2856
-
2857
- const decoder = new TextDecoder()
2858
- const [bytes, rest] = byteArraySerializer.deserializeStream(buffer)
2859
-
2860
- return [
2861
- new FateString(decoder.decode(bytes.valueOf())),
2862
- rest
2863
- ]
2864
- }
2865
- }
2866
-
2867
- module.exports = StringSerializer
2868
-
2869
-
2870
- /***/ }),
2871
-
2872
- /***/ 6178:
2873
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2874
-
2875
- const FateTag = __webpack_require__(105)
2876
- const FateTuple = __webpack_require__(6878)
2877
- const BaseSerializer = __webpack_require__(8268)
2878
- const RLPInt = __webpack_require__(7138)
2879
-
2880
- class TupleSerializer extends BaseSerializer {
2881
- serialize(tuple) {
2882
- const len = tuple.size
2883
- if (len === 0) {
2884
- return [FateTag.EMPTY_TUPLE]
2885
- }
2886
-
2887
- const elements = tuple.items
2888
- .map(e => this.globalSerializer.serialize(e))
2889
- .flat(Infinity)
2890
-
2891
- if (len < 16) {
2892
- const prefix = (len << 4) | FateTag.SHORT_TUPLE
2893
-
2894
- return [
2895
- prefix,
2896
- ...elements
2897
- ]
2898
- }
2899
-
2900
- return [
2901
- FateTag.LONG_TUPLE,
2902
- ...RLPInt.encode(len - 16),
2903
- ...elements
2904
- ]
2905
- }
2906
-
2907
- deserializeStream(data, typeInfo) {
2908
- const buffer = new Uint8Array(data)
2909
- const prefix = buffer[0]
2910
- let len = 0n
2911
- let rest = buffer.slice(1)
2912
-
2913
- if (prefix === FateTag.EMPTY_TUPLE) {
2914
- return [new FateTuple(), rest]
2915
- }
2916
-
2917
- if ((prefix & 0x0F) === FateTag.SHORT_TUPLE) {
2918
- len = (prefix & 0xF0) >> 4
2919
- }
2920
-
2921
- if (prefix === FateTag.LONG_TUPLE) {
2922
- [len, rest] = RLPInt.decode(buffer.slice(1))
2923
- len += 16n
2924
- }
2925
-
2926
- let valueTypes = []
2927
- if (typeof typeInfo !== 'undefined') {
2928
- valueTypes = typeInfo.valueTypes
2929
- }
2930
-
2931
- const elements = []
2932
- let el = null
2933
- for (let i = 0n; i < len; i++) {
2934
- [el, rest] = this.globalSerializer.deserializeStream(rest, valueTypes[i])
2935
- elements.push(el)
2936
- }
2937
-
2938
- let type = typeInfo
2939
- if (typeof typeInfo === 'undefined') {
2940
- type = elements.map(e => e.type)
2941
- }
2942
-
2943
- return [
2944
- new FateTuple(type, elements),
2945
- rest
2946
- ]
2947
- }
2948
- }
2949
-
2950
- module.exports = TupleSerializer
2951
-
2952
-
2953
- /***/ }),
2954
-
2955
- /***/ 9503:
2956
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
2957
-
2958
- const RLP = __webpack_require__(3485)
2959
- const FateTag = __webpack_require__(105)
2960
- const FateTuple = __webpack_require__(6878)
2961
- const FateVariant = __webpack_require__(2457)
2962
- const {FateTypeTuple} = __webpack_require__(4265)
2963
- const BaseSerializer = __webpack_require__(8268)
2964
-
2965
- class VariantSerializer extends BaseSerializer {
2966
- serialize(variant) {
2967
- const valueTuple = new FateTuple(variant.valueTypes, variant.value)
2968
-
2969
- return [
2970
- FateTag.VARIANT,
2971
- ...RLP.encode(new Uint8Array(variant.arities)),
2972
- variant.tag,
2973
- ...this.globalSerializer.serialize(valueTuple)
2974
- ]
2975
- }
2976
-
2977
- deserializeStream(stream, typeInfo) {
2978
- const buffer = new Uint8Array(stream)
2979
- const decoded = RLP.decode(buffer.slice(1), true)
2980
- const arities = [...decoded.data]
2981
- const tag = decoded.remainder[0]
2982
- const data = decoded.remainder.slice(1)
2983
- let variants = []
2984
- let valueType
2985
-
2986
- if (typeof typeInfo !== 'undefined' && typeof typeInfo.variants !== 'undefined') {
2987
- variants = typeInfo.variants
2988
- valueType = FateTypeTuple(Object.values(variants[tag])[0])
2989
- }
2990
-
2991
- const [els, rest] = this.globalSerializer.deserializeStream(data, valueType)
2992
-
2993
- return [
2994
- new FateVariant(arities, tag, els.items, els.valueTypes, variants),
2995
- rest
2996
- ]
2997
- }
2998
- }
2999
-
3000
- module.exports = VariantSerializer
3001
-
3002
-
3003
- /***/ }),
3004
-
3005
- /***/ 34:
3006
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3007
-
3008
- const FateVoid = __webpack_require__(9713)
3009
- const BaseSerializer = __webpack_require__(8268)
3010
-
3011
- class VoidSerializer extends BaseSerializer {
3012
- serialize() {
3013
- return ''
3014
- }
3015
-
3016
- deserialize() {
3017
- return new FateVoid()
3018
- }
3019
-
3020
- deserializeStream(data) {
3021
- return [new FateVoid(), data]
3022
- }
3023
- }
3024
-
3025
- module.exports = VoidSerializer
3026
-
3027
-
3028
- /***/ }),
3029
-
3030
- /***/ 2584:
3031
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3032
-
3033
- const assert = __webpack_require__(4664)
3034
- const FateTag = __webpack_require__(105)
3035
- const FatePrefixError = __webpack_require__(5462)
3036
- const {
3037
- FateTypeInt,
3038
- FateTypeBool,
3039
- FateTypeString,
3040
- FateTypeBits,
3041
- FateTypeBytes,
3042
- FateTypeAccountAddress,
3043
- FateTypeContractAddress,
3044
- FateTypeOracleAddress,
3045
- FateTypeOracleQueryAddress,
3046
- FateTypeChannelAddress,
3047
- FateTypeList,
3048
- FateTypeMap,
3049
- FateTypeTuple,
3050
- FateTypeVariant,
3051
- } = __webpack_require__(4265)
3052
-
3053
- const OBJECT_TYPES = {
3054
- [FateTag.OTYPE_ADDRESS]: FateTypeAccountAddress(),
3055
- [FateTag.OTYPE_BYTES]: FateTypeBytes(),
3056
- [FateTag.OTYPE_CONTRACT]: FateTypeContractAddress(),
3057
- [FateTag.OTYPE_ORACLE]: FateTypeOracleAddress(),
3058
- [FateTag.OTYPE_ORACLE_QUERY]: FateTypeOracleQueryAddress(),
3059
- [FateTag.OTYPE_CHANNEL]: FateTypeChannelAddress(),
3060
- }
3061
-
3062
- class TypeFactory {
3063
- createType(data) {
3064
- const tag = data[0]
3065
-
3066
- if (tag === FateTag.TRUE || tag === FateTag.FALSE) {
3067
- return FateTypeBool()
3068
- }
3069
-
3070
- if ((tag & 0x01) === FateTag.SMALL_INT
3071
- || tag === FateTag.POS_BIG_INT
3072
- || tag === FateTag.NEG_BIG_INT
3073
- ) {
3074
- return FateTypeInt()
3075
- }
3076
-
3077
- if ((tag & 0x03) === FateTag.SHORT_STRING
3078
- || tag === FateTag.LONG_STRING
3079
- || tag === FateTag.EMPTY_STRING
3080
- ) {
3081
- return FateTypeString()
3082
- }
3083
-
3084
- if ((tag & 0x0F) === FateTag.SHORT_LIST || tag === FateTag.LONG_LIST) {
3085
- return FateTypeList()
3086
- }
3087
-
3088
- if ((tag & 0x0F) === FateTag.SHORT_TUPLE
3089
- || tag === FateTag.LONG_TUPLE
3090
- || tag === FateTag.EMPTY_TUPLE
3091
- ) {
3092
- return FateTypeTuple()
3093
- }
3094
-
3095
- if (tag === FateTag.MAP || tag === FateTag.EMPTY_MAP) {
3096
- return FateTypeMap()
3097
- }
3098
-
3099
- if (tag === FateTag.POS_BITS || tag === FateTag.NEG_BITS) {
3100
- return FateTypeBits()
3101
- }
3102
-
3103
- if (tag === FateTag.VARIANT) {
3104
- return FateTypeVariant()
3105
- }
3106
-
3107
- if (tag === FateTag.OBJECT) {
3108
- const obj = data[1]
3109
- assert(OBJECT_TYPES.hasOwnProperty(obj), `Unsupported object type "${obj}"`)
3110
-
3111
- return OBJECT_TYPES[obj]
3112
- }
3113
-
3114
- throw new FatePrefixError(tag)
3115
- }
3116
- }
3117
-
3118
- module.exports = TypeFactory
3119
-
3120
-
3121
- /***/ }),
3122
-
3123
- /***/ 539:
3124
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3125
-
3126
- const FateAddress = __webpack_require__(6187)
3127
-
3128
- class FateAccountAddress extends FateAddress {
3129
- constructor(value) {
3130
- super(value, 'account_pubkey', 'ak')
3131
- }
3132
- }
3133
-
3134
- module.exports = FateAccountAddress
3135
-
3136
-
3137
- /***/ }),
3138
-
3139
- /***/ 6187:
3140
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3141
-
3142
- const FateBytes = __webpack_require__(5779)
3143
-
3144
- class FateAddress extends FateBytes {
3145
- constructor(value, name, prefix) {
3146
- super(value, 32, name)
3147
-
3148
- this._prefix = prefix
3149
- }
3150
-
3151
- get prefix() {
3152
- return this._prefix
3153
- }
3154
-
3155
- accept(visitor) {
3156
- return visitor.visitAddress(this)
3157
- }
3158
- }
3159
-
3160
- module.exports = FateAddress
3161
-
3162
-
3163
- /***/ }),
3164
-
3165
- /***/ 3422:
3166
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3167
-
3168
- const FateData = __webpack_require__(9865)
3169
-
3170
- class FateBits extends FateData {
3171
- constructor(value) {
3172
- super('bits')
3173
-
3174
- this._value = BigInt(value)
3175
- }
3176
-
3177
- get value() {
3178
- return this._value
3179
- }
3180
-
3181
- valueOf() {
3182
- return this._value
3183
- }
3184
- }
3185
-
3186
- module.exports = FateBits
3187
-
3188
-
3189
- /***/ }),
3190
-
3191
- /***/ 7430:
3192
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3193
-
3194
- const FateData = __webpack_require__(9865)
3195
- const FateTypeError = __webpack_require__(5110)
3196
-
3197
- class FateBls12381Field extends FateData {
3198
- constructor(value, size, name) {
3199
- super(name)
3200
-
3201
- if (!Array.isArray(value) && !ArrayBuffer.isView(value)) {
3202
- throw new FateTypeError(
3203
- name,
3204
- `Should be one of: Array or ArrayBuffer; got ${value} instead`
3205
- )
3206
- }
3207
-
3208
- const buff = new Uint8Array(value)
3209
-
3210
- if (buff.byteLength !== size) {
3211
- throw new FateTypeError(
3212
- name,
3213
- `Invalid length: got ${buff.byteLength} bytes instead of ${size} bytes`
3214
- )
3215
- }
3216
-
3217
- this._value = buff
3218
- this._size = size
3219
- }
3220
-
3221
- get value() {
3222
- return this._value
3223
- }
3224
-
3225
- get size() {
3226
- return this._size
3227
- }
3228
-
3229
- valueOf() {
3230
- return this._value
3231
- }
3232
- }
3233
-
3234
- module.exports = FateBls12381Field
3235
-
3236
-
3237
- /***/ }),
3238
-
3239
- /***/ 4077:
3240
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3241
-
3242
- const FateBls12381Field = __webpack_require__(7430)
3243
- const {FateTypeBls12381Fp} = __webpack_require__(4265)
3244
-
3245
- const SIZE = 48
3246
- const NAME = 'bls12_381.fp'
3247
-
3248
- class FateBls12381Fp extends FateBls12381Field {
3249
- constructor(value) {
3250
- super(value, SIZE, NAME)
3251
- }
3252
-
3253
- get type() {
3254
- return FateTypeBls12381Fp()
3255
- }
3256
-
3257
- accept(visitor) {
3258
- return visitor.visitBls12381Fp(this)
3259
- }
3260
- }
3261
-
3262
- module.exports = FateBls12381Fp
3263
-
3264
-
3265
- /***/ }),
3266
-
3267
- /***/ 1565:
3268
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3269
-
3270
- const FateBls12381Field = __webpack_require__(7430)
3271
- const {FateTypeBls12381Fr} = __webpack_require__(4265)
3272
-
3273
- const SIZE = 32
3274
- const NAME = 'bls12_381.fr'
3275
-
3276
- class FateBls12381Fr extends FateBls12381Field {
3277
- constructor(value) {
3278
- super(value, SIZE, NAME)
3279
- }
3280
-
3281
- get type() {
3282
- return FateTypeBls12381Fr()
3283
- }
3284
-
3285
- accept(visitor) {
3286
- return visitor.visitBls12381Fr(this)
3287
- }
3288
- }
3289
-
3290
- module.exports = FateBls12381Fr
3291
-
3292
-
3293
- /***/ }),
3294
-
3295
- /***/ 4476:
3296
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3297
-
3298
- const FateData = __webpack_require__(9865)
3299
- const {FateTypeBool} = __webpack_require__(4265)
3300
-
3301
- class FateBool extends FateData {
3302
- constructor(value) {
3303
- super('bool')
3304
-
3305
- this._value = !!value
3306
- }
3307
-
3308
- get value() {
3309
- return this._value
3310
- }
3311
-
3312
- get type() {
3313
- return FateTypeBool()
3314
- }
3315
-
3316
- valueOf() {
3317
- return this._value
3318
- }
3319
- }
3320
-
3321
- module.exports = FateBool
3322
-
3323
-
3324
- /***/ }),
3325
-
3326
- /***/ 7945:
3327
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3328
-
3329
- const FateData = __webpack_require__(9865)
3330
- const {FateTypeByteArray} = __webpack_require__(4265)
3331
-
3332
- class FateByteArray extends FateData {
3333
- constructor(value = []) {
3334
- super('byte_array')
3335
-
3336
- this._value = new Uint8Array(value)
3337
- }
3338
-
3339
- get length() {
3340
- return this._value.length
3341
- }
3342
-
3343
- get type() {
3344
- return FateTypeByteArray()
3345
- }
3346
-
3347
- valueOf() {
3348
- return this._value
3349
- }
3350
- }
3351
-
3352
- module.exports = FateByteArray
3353
-
3354
-
3355
- /***/ }),
3356
-
3357
- /***/ 5779:
3358
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3359
-
3360
- const FateData = __webpack_require__(9865)
3361
- const {Int2ByteArray} = __webpack_require__(240)
3362
- const HexStringToByteArray = __webpack_require__(381)
3363
- const FateTypeError = __webpack_require__(5110)
3364
-
3365
- const toByteArray = (value, size = 0) => {
3366
- if (Array.isArray(value) || ArrayBuffer.isView(value)) {
3367
- return new Uint8Array(value)
3368
- }
3369
-
3370
- if (typeof value === 'string') {
3371
- return HexStringToByteArray(value)
3372
- }
3373
-
3374
- if (typeof value !== 'bigint' && !Number.isInteger(value)) {
3375
- throw new FateTypeError(
3376
- 'byte_array',
3377
- `Should be one of: Array, ArrayBuffer, hex string, Number, BigInt; got ${value} instead`
3378
- )
3379
- }
3380
-
3381
- const bytes = Int2ByteArray(value)
3382
- if (bytes.length >= size) {
3383
- return bytes
3384
- }
3385
-
3386
- // pad the byte array with 0 significant bytes, because int representation lost
3387
- const fixedSize = new Uint8Array(size)
3388
- fixedSize.set(bytes, size - bytes.length)
3389
-
3390
- return fixedSize
3391
- }
3392
-
3393
- class FateBytes extends FateData {
3394
- constructor(value, size, name = 'bytes') {
3395
- super(name)
3396
-
3397
- this._value = toByteArray(value, size)
3398
-
3399
- if (size && this._value.byteLength !== size) {
3400
- throw new FateTypeError(
3401
- name,
3402
- `Invalid length: got ${this._value.byteLength} bytes instead of ${size} bytes`
3403
- )
3404
- }
3405
-
3406
- this._size = size
3407
- }
3408
-
3409
- get value() {
3410
- return this._value
3411
- }
3412
-
3413
- get size() {
3414
- return this._size
3415
- }
3416
-
3417
- valueOf() {
3418
- return this._value
3419
- }
3420
- }
3421
-
3422
- module.exports = FateBytes
3423
-
3424
-
3425
- /***/ }),
3426
-
3427
- /***/ 7255:
3428
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3429
-
3430
- const FateData = __webpack_require__(9865)
3431
-
3432
- class FateCalldata extends FateData {
3433
- constructor(functionId, argTypes, argsData) {
3434
- super('calldata')
3435
-
3436
- this._functionId = new Uint8Array(functionId)
3437
- this._argTypes = argTypes
3438
- this._args = argsData
3439
- }
3440
-
3441
- get functionId() {
3442
- return this._functionId
3443
- }
3444
-
3445
- get argTypes() {
3446
- return this._argTypes
3447
- }
3448
-
3449
- get args() {
3450
- return this._args
3451
- }
3452
-
3453
- valueOf() {
3454
- return {
3455
- functionId: this._functionId,
3456
- args: this._args
3457
- }
3458
- }
3459
-
3460
- accept(visitor) {
3461
- return visitor.visitCalldata(this)
3462
- }
3463
- }
3464
-
3465
- module.exports = FateCalldata
3466
-
3467
-
3468
- /***/ }),
3469
-
3470
- /***/ 6445:
3471
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3472
-
3473
- const FateAddress = __webpack_require__(6187)
3474
-
3475
- class FateChannelAddress extends FateAddress {
3476
- constructor(value) {
3477
- super(value, 'channel', 'ch')
3478
- }
3479
- }
3480
-
3481
- module.exports = FateChannelAddress
3482
-
3483
-
3484
- /***/ }),
3485
-
3486
- /***/ 8623:
3487
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3488
-
3489
- const FateAddress = __webpack_require__(6187)
3490
-
3491
- class FateContractAddress extends FateAddress {
3492
- constructor(value) {
3493
- super(value, 'contract_pubkey', 'ct')
3494
- }
3495
- }
3496
-
3497
- module.exports = FateContractAddress
3498
-
3499
-
3500
- /***/ }),
3501
-
3502
- /***/ 9865:
3503
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3504
-
3505
- const InternalError = __webpack_require__(2966)
3506
-
3507
- class FateData {
3508
- constructor(name) {
3509
- this.name = name
3510
- }
3511
-
3512
- valueOf() {
3513
- throw new InternalError('Not implemented.')
3514
- }
3515
-
3516
- accept(visitor) {
3517
- return visitor.visitData(this)
3518
- }
3519
- }
3520
-
3521
- module.exports = FateData
3522
-
3523
-
3524
- /***/ }),
3525
-
3526
- /***/ 7772:
3527
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3528
-
3529
- const FateBytes = __webpack_require__(5779)
3530
-
3531
- class FateHash extends FateBytes {
3532
- constructor(value) {
3533
- super(value, 32, 'hash')
3534
- }
3535
- }
3536
-
3537
- module.exports = FateHash
3538
-
3539
-
3540
- /***/ }),
3541
-
3542
- /***/ 3509:
3543
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3544
-
3545
- const FateData = __webpack_require__(9865)
3546
- const {FateTypeInt} = __webpack_require__(4265)
3547
-
3548
- class FateInt extends FateData {
3549
- constructor(value) {
3550
- super('int')
3551
-
3552
- this._value = BigInt(value)
3553
- }
3554
-
3555
- get value() {
3556
- return this._value
3557
- }
3558
-
3559
- get type() {
3560
- return FateTypeInt()
3561
- }
3562
-
3563
- valueOf() {
3564
- return this._value
3565
- }
3566
- }
3567
-
3568
- module.exports = FateInt
3569
-
3570
-
3571
- /***/ }),
3572
-
3573
- /***/ 1041:
3574
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3575
-
3576
- const FateData = __webpack_require__(9865)
3577
- const {FateTypeList} = __webpack_require__(4265)
3578
-
3579
- class FateList extends FateData {
3580
- constructor(itemsType, items = []) {
3581
- super('list')
3582
-
3583
- this._itemsType = itemsType
3584
- this.items = Array.from(items)
3585
- }
3586
-
3587
- get itemsType() {
3588
- return this._itemsType
3589
- }
3590
-
3591
- get type() {
3592
- return FateTypeList(this.itemsType)
3593
- }
3594
-
3595
- get length() {
3596
- return this.items.length
3597
- }
3598
-
3599
- valueOf() {
3600
- return this.items.map(e => e.valueOf())
3601
- }
3602
-
3603
- accept(visitor) {
3604
- return visitor.visitList(this)
3605
- }
3606
- }
3607
-
3608
- module.exports = FateList
3609
-
3610
-
3611
- /***/ }),
3612
-
3613
- /***/ 8804:
3614
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3615
-
3616
- const FateData = __webpack_require__(9865)
3617
- const {FateTypeMap} = __webpack_require__(4265)
3618
-
3619
- const arrayToItem = (item) => {
3620
- const [key, value] = item
3621
- return {key, value}
3622
- }
3623
-
3624
- class FateMap extends FateData {
3625
- constructor(keyType, valueType, items = []) {
3626
- super('map')
3627
-
3628
- this._keyType = keyType
3629
- this._valueType = valueType
3630
- this._type = FateTypeMap(keyType, valueType)
3631
- this._value = new Map(items)
3632
- }
3633
-
3634
- get items() {
3635
- return [...this._value.entries()].map(arrayToItem)
3636
- }
3637
-
3638
- get keyType() {
3639
- return this._keyType
3640
- }
3641
-
3642
- get valueType() {
3643
- return this._valueType
3644
- }
3645
-
3646
- get type() {
3647
- return this._type
3648
- }
3649
-
3650
- get length() {
3651
- return this._value.size
3652
- }
3653
-
3654
- get iterator() {
3655
- return this._value[Symbol.iterator]()
3656
- }
3657
-
3658
- get keys() {
3659
- return this._value.keys()
3660
- }
3661
-
3662
- valueOf() {
3663
- const map = new Map()
3664
- for (const [key, value] of this.iterator) {
3665
- map.set(key.valueOf(), value.valueOf())
3666
- }
3667
-
3668
- return map
3669
- }
3670
-
3671
- accept(visitor) {
3672
- return visitor.visitMap(this)
3673
- }
3674
- }
3675
-
3676
- module.exports = FateMap
3677
-
3678
-
3679
- /***/ }),
3680
-
3681
- /***/ 687:
3682
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3683
-
3684
- const FateAddress = __webpack_require__(6187)
3685
-
3686
- class FateOracleAddress extends FateAddress {
3687
- constructor(value) {
3688
- super(value, 'oracle_pubkey', 'ok')
3689
- }
3690
- }
3691
-
3692
- module.exports = FateOracleAddress
3693
-
3694
-
3695
- /***/ }),
3696
-
3697
- /***/ 5070:
3698
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3699
-
3700
- const FateAddress = __webpack_require__(6187)
3701
-
3702
- class FateOracleQueryAddress extends FateAddress {
3703
- constructor(value) {
3704
- super(value, 'oracle_query_id', 'oq')
3705
- }
3706
- }
3707
-
3708
- module.exports = FateOracleQueryAddress
3709
-
3710
-
3711
- /***/ }),
3712
-
3713
- /***/ 2548:
3714
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3715
-
3716
- const FateData = __webpack_require__(9865)
3717
- const {FateTypeSet} = __webpack_require__(4265)
3718
-
3719
- class FateSet extends FateData {
3720
- constructor(itemsType, items = []) {
3721
- super('set')
3722
-
3723
- this._itemsType = itemsType
3724
- this._items = new Set(items)
3725
- }
3726
-
3727
- get items() {
3728
- return Array.from(this._items.values())
3729
- }
3730
-
3731
- get itemsType() {
3732
- return this._itemsType
3733
- }
3734
-
3735
- get type() {
3736
- return FateTypeSet(this.itemsType)
3737
- }
3738
-
3739
- get length() {
3740
- return this._items.size
3741
- }
3742
-
3743
- valueOf() {
3744
- return new Set(this.items.map(e => e.valueOf()))
3745
- }
3746
-
3747
- accept(visitor) {
3748
- return visitor.visitSet(this)
3749
- }
3750
- }
3751
-
3752
- module.exports = FateSet
3753
-
3754
-
3755
- /***/ }),
3756
-
3757
- /***/ 3607:
3758
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3759
-
3760
- const FateBytes = __webpack_require__(5779)
3761
-
3762
- class FateSignature extends FateBytes {
3763
- constructor(value) {
3764
- super(value, 64, 'signature')
3765
- }
3766
- }
3767
-
3768
- module.exports = FateSignature
3769
-
3770
-
3771
- /***/ }),
3772
-
3773
- /***/ 6313:
3774
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3775
-
3776
- const FateData = __webpack_require__(9865)
3777
- const {FateTypeString} = __webpack_require__(4265)
3778
-
3779
- const toString = (data) => {
3780
- if (data instanceof Uint8Array) {
3781
- const decoder = new TextDecoder()
3782
- return decoder.decode(data)
3783
- }
3784
-
3785
- return data.toString()
3786
- }
3787
-
3788
- class FateString extends FateData {
3789
- constructor(value) {
3790
- super('string')
3791
-
3792
- this._value = toString(value)
3793
- }
3794
-
3795
- get type() {
3796
- return FateTypeString()
3797
- }
3798
-
3799
- toString() {
3800
- return this._value
3801
- }
3802
-
3803
- valueOf() {
3804
- return this._value
3805
- }
3806
- }
3807
-
3808
- module.exports = FateString
3809
-
3810
-
3811
- /***/ }),
3812
-
3813
- /***/ 6878:
3814
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3815
-
3816
- const FateData = __webpack_require__(9865)
3817
- const {FateTypeTuple} = __webpack_require__(4265)
3818
-
3819
- const zipObject = (keys, values) => {
3820
- const reducer = (acc, k, i) => {
3821
- acc[k] = values[i]
3822
- return acc
3823
- }
3824
-
3825
- return keys.reduce(reducer, {})
3826
- }
3827
-
3828
- class FateTuple extends FateData {
3829
- constructor(valueTypes = [], items = []) {
3830
- super('tuple')
3831
-
3832
- this._valueTypes = (valueTypes.hasOwnProperty('valueTypes')) ? valueTypes.valueTypes : valueTypes
3833
- this._type = Array.isArray(valueTypes) ? FateTypeTuple(valueTypes) : valueTypes
3834
- this._items = Array.from(items)
3835
- }
3836
-
3837
- get valueTypes() {
3838
- return this._valueTypes
3839
- }
3840
-
3841
- get type() {
3842
- return this._type
3843
- }
3844
-
3845
- get size() {
3846
- return this._items.length
3847
- }
3848
-
3849
- get items() {
3850
- return this._items
3851
- }
3852
-
3853
- valueOf() {
3854
- return this.prepareItems(e => e.valueOf())
3855
- }
3856
-
3857
- prepareItems(callback) {
3858
- const items = this._items.map(callback)
3859
-
3860
- if (this._type.name === 'record') {
3861
- return zipObject(this._type.keys, items)
3862
- }
3863
-
3864
- return items
3865
- }
3866
-
3867
- accept(visitor) {
3868
- return visitor.visitTuple(this)
3869
- }
3870
- }
3871
-
3872
- module.exports = FateTuple
3873
-
3874
-
3875
- /***/ }),
3876
-
3877
- /***/ 2457:
3878
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3879
-
3880
- const FateData = __webpack_require__(9865)
3881
- const {FateTypeVariant, FateTypeTuple, FateTypeInt} = __webpack_require__(4265)
3882
-
3883
- class FateVariant extends FateData {
3884
- constructor(arities, tag, value = [], valueTypes = [], variants = []) {
3885
- super('variant')
3886
-
3887
- this.arities = Array.from(arities)
3888
- this._tag = tag
3889
-
3890
- this._value = value
3891
- this._valueTypes = valueTypes
3892
-
3893
- this._type = FateTypeVariant(variants)
3894
- }
3895
-
3896
- get valueTypes() {
3897
- return this._valueTypes
3898
- }
3899
-
3900
- get type() {
3901
- return this._type
3902
- }
3903
-
3904
- get tag() {
3905
- return this._tag
3906
- }
3907
-
3908
- get value() {
3909
- return this._value
3910
- }
3911
-
3912
- get aritiesType() {
3913
- return FateTypeInt()
3914
- }
3915
-
3916
- get variantType() {
3917
- return FateTypeTuple(this._valueTypes)
3918
- }
3919
-
3920
- get variants() {
3921
- return this._type.variants
3922
- }
3923
-
3924
- get variantName() {
3925
- if (this.variants.length === 0) {
3926
- return this.tag
3927
- }
3928
-
3929
- const variant = this.variants[this.tag]
3930
-
3931
- return Object.keys(variant)[0]
3932
- }
3933
-
3934
- valueOf() {
3935
- if (this.variants.length === 0) {
3936
- return this
3937
- }
3938
-
3939
- const value = this._value.map(e => e.valueOf())
3940
-
3941
- return {
3942
- [this.variantName]: value
3943
- }
3944
- }
3945
-
3946
- accept(visitor) {
3947
- return visitor.visitVariant(this)
3948
- }
3949
- }
3950
-
3951
- module.exports = FateVariant
3952
-
3953
-
3954
- /***/ }),
3955
-
3956
- /***/ 9713:
3957
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3958
-
3959
- const FateData = __webpack_require__(9865)
3960
- const {FateTypeVoid} = __webpack_require__(4265)
3961
-
3962
- class FateVoid extends FateData {
3963
- constructor() {
3964
- super('void')
3965
-
3966
- this._value = undefined
3967
- }
3968
-
3969
- get value() {
3970
- return this._value
3971
- }
3972
-
3973
- get type() {
3974
- return FateTypeVoid()
3975
- }
3976
-
3977
- valueOf() {
3978
- return this._value
3979
- }
3980
- }
3981
-
3982
- module.exports = FateVoid
3983
-
3984
-
3985
- /***/ }),
3986
-
3987
- /***/ 333:
3988
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
3989
-
3990
- const {Int2ByteArray, ByteArray2IntBE} = __webpack_require__(240)
3991
-
3992
- const CURVES = {
3993
- r: {
3994
- R: 1n << 256n,
3995
- N: 0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n,
3996
- },
3997
- p: {
3998
- R: 1n << 384n,
3999
- /* eslint-disable-next-line max-len */
4000
- N: 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaabn,
4001
- }
4002
- }
4003
-
4004
- const xgcd = (a, b) => {
4005
- if (b === 0n) {
4006
- return [1n, 0n, a]
4007
- }
4008
-
4009
- const [x, y, d] = xgcd(b, a % b)
4010
-
4011
- return [y, x - y * (a / b), d]
4012
- }
4013
-
4014
- const invmod = (a, n) => {
4015
- const [X, _Y, _D] = xgcd(a, n)
4016
-
4017
- // To ensure positive result
4018
- return (X + n) % n
4019
- }
4020
-
4021
- // Scalar(a) = aR mod N
4022
- const Int2MontBytes = (value, curveType) => {
4023
- const curve = CURVES[curveType]
4024
- const a = BigInt(value)
4025
- const m = (a * curve.R) % curve.N
4026
-
4027
- return Int2ByteArray(m)
4028
- }
4029
-
4030
- // a = ã · R^−1 mod N
4031
- const MontBytes2Int = (value, curveType) => {
4032
- const curve = CURVES[curveType]
4033
- const a = ByteArray2IntBE(value)
4034
- const Rinv = invmod(curve.R, curve.N)
4035
-
4036
- return (a * Rinv) % curve.N
4037
- }
4038
-
4039
- module.exports = {
4040
- Int2MontBytes,
4041
- MontBytes2Int,
4042
- }
4043
-
4044
-
4045
- /***/ }),
4046
-
4047
- /***/ 381:
4048
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4049
-
4050
- const FormatError = __webpack_require__(722)
4051
-
4052
- // TODO consider using Buffer.from(<string>, 'hex') instead
4053
- // TODO get rid of this ?
4054
- // Int2ByteArray(BigInt('0x' + hex.join('')))
4055
- const HexStringToByteArray = (str) => {
4056
- const match = str.match(/^(0x)?([a-f0-9]*)$/i)
4057
- if (!match) {
4058
- throw new FormatError(`Invalid hex string: ${str}`)
4059
- }
4060
-
4061
- return new Uint8Array(match[2]
4062
- .split(/(.{1,2})/)
4063
- .filter(el => el)
4064
- .map(el => parseInt(el, 16)))
4065
- }
4066
-
4067
- module.exports = HexStringToByteArray
4068
-
4069
-
4070
- /***/ }),
4071
-
4072
- /***/ 240:
4073
- /***/ ((module) => {
4074
-
4075
- const Int2ByteArray = (value) => {
4076
- const bigInt = BigInt(value)
4077
-
4078
- if (bigInt < 256n) {
4079
- return new Uint8Array([Number(bigInt)])
4080
- }
4081
-
4082
- return new Uint8Array([
4083
- ...Int2ByteArray(bigInt >> 8n),
4084
- Number(bigInt & 0xffn)
4085
- ])
4086
- }
4087
-
4088
- const ByteArrayToHexArray = (data) => {
4089
- return [...data].map(x => x.toString(16).padStart(2, '0'))
4090
- }
4091
-
4092
- const ByteArray2Int = (data) => {
4093
- const hex = ByteArrayToHexArray(data)
4094
-
4095
- return BigInt('0x' + hex.join(''))
4096
- }
4097
-
4098
- const ByteArray2IntBE = (data) => {
4099
- const hex = ByteArrayToHexArray(data).reverse()
4100
-
4101
- return BigInt('0x' + hex.join(''))
4102
- }
4103
-
4104
- const ByteArray2Hex = (data) => {
4105
- return ByteArrayToHexArray(data).join('')
4106
- }
4107
-
4108
- module.exports = {
4109
- Int2ByteArray,
4110
- ByteArray2Int,
4111
- ByteArray2IntBE,
4112
- ByteArray2Hex,
4113
- }
4114
-
4115
-
4116
- /***/ }),
4117
-
4118
- /***/ 7138:
4119
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4120
-
4121
- const RLP = __webpack_require__(3485)
4122
- const {Int2ByteArray, ByteArray2Int } = __webpack_require__(240)
4123
-
4124
- module.exports = {
4125
- encode(value) {
4126
- return new Uint8Array(RLP.encode(Int2ByteArray(value)))
4127
- },
4128
- decode(buffer) {
4129
- const decoded = RLP.decode(buffer, true)
4130
- return [ByteArray2Int(decoded.data), decoded.remainder]
4131
- }
4132
- }
4133
-
4134
-
4135
- /***/ }),
4136
-
4137
- /***/ 9475:
4138
- /***/ ((module) => {
4139
-
4140
- const abs = (val) => {
4141
- return val > 0 ? val : val * -1n
4142
- }
4143
-
4144
- module.exports = abs
4145
-
4146
-
4147
- /***/ }),
4148
-
4149
- /***/ 4664:
4150
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4151
-
4152
- const InternalError = __webpack_require__(2966)
4153
-
4154
- const assert = (condition, message) => {
4155
- if (!condition) {
4156
- throw new InternalError(message)
4157
- }
4158
- }
4159
-
4160
- module.exports = assert
4161
-
4162
-
4163
- /***/ }),
4164
-
4165
- /***/ 2727:
4166
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4167
-
4168
- const bs58 = __webpack_require__(3783)
4169
- const { addChecksum, getPayload } = __webpack_require__(8638)
4170
-
4171
- /**
4172
- * Base58check encode given `input`
4173
- * @param {Buffer} input - Data to encode
4174
- * @return {String} Base58check encoded data
4175
- */
4176
- const encode = (input) => {
4177
- return bs58.encode(addChecksum(input))
4178
- }
4179
-
4180
- /**
4181
- * Base58check decode given `str`
4182
- * @param {String} str - Data to decode
4183
- * @return {Uint8Array} Base58check decoded data
4184
- */
4185
- const decode = (str) => {
4186
- return getPayload(bs58.decode(str))
4187
- }
4188
-
4189
- module.exports = {
4190
- encode,
4191
- decode
4192
- }
4193
-
4194
-
4195
- /***/ }),
4196
-
4197
- /***/ 8638:
4198
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4199
-
4200
- const Sha256 = __webpack_require__(7499)
4201
- const { Buffer } = __webpack_require__(9509)
4202
- const FormatError = __webpack_require__(722)
4203
-
4204
- const sha256hash = (input) => {
4205
- return new Sha256().update(input).digest()
4206
- }
4207
-
4208
- const checkSumFn = (payload) => {
4209
- return sha256hash(sha256hash(payload)).slice(0, 4)
4210
- }
4211
-
4212
- const addChecksum = (payload) => {
4213
- const buffer = Buffer.from(payload)
4214
- const checksum = checkSumFn(payload)
4215
- return Buffer.concat([buffer, checksum], buffer.length + 4)
4216
- }
4217
-
4218
- const getPayload = (payloadWithChecksumData) => {
4219
- const payloadWithChecksum = Buffer.from(payloadWithChecksumData)
4220
- const payload = payloadWithChecksum.slice(0, -4)
4221
- const checksum = payloadWithChecksum.slice(-4)
4222
- const newChecksum = checkSumFn(payload)
4223
-
4224
- if (!checksum.equals(newChecksum)) {
4225
- throw new FormatError('Invalid checksum')
4226
- }
4227
-
4228
- return new Uint8Array(payload)
4229
- }
4230
-
4231
- /**
4232
- * Base64check encode given `input`
4233
- * @param {String|Uint8Array} input - Data to encode
4234
- * @return {String} Base64check encoded data
4235
- */
4236
- const encode = (input) => {
4237
- return addChecksum(input).toString('base64')
4238
- }
4239
-
4240
- /**
4241
- * Base64check decode given `str`
4242
- * @param {String} str - Data to decode
4243
- * @return {Uint8Array} Base64check decoded data
4244
- */
4245
- const decode = (str) => {
4246
- const data = Buffer.from(str, 'base64')
4247
-
4248
- return getPayload(data)
4249
- }
4250
-
4251
- module.exports = {
4252
- addChecksum,
4253
- getPayload,
4254
- encode,
4255
- decode
4256
- }
4257
-
4258
-
4259
- /***/ }),
4260
-
4261
- /***/ 2665:
4262
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4263
-
4264
- const blake = __webpack_require__(8442)
4265
-
4266
- const HASH_BYTES = 32
4267
-
4268
- const hash = (name) => {
4269
- return Array.from(blake.blake2b(name, null, HASH_BYTES))
4270
- }
4271
-
4272
- const symbolIdentifier = (funName) => {
4273
- // First 4 bytes of 32 bytes blake hash
4274
- return hash(funName).slice(0, 4)
4275
- }
4276
-
4277
- module.exports = {
4278
- hash,
4279
- symbolIdentifier
4280
- }
4281
-
4282
-
4283
- /***/ }),
4284
-
4285
- /***/ 5675:
4286
- /***/ ((module) => {
4287
-
4288
- module.exports = (arr, ...arrs) => {
4289
- return arr.map((val, i) => arrs.reduce((a, curr) => [...a, curr[i]], [val]))
4290
- }
4291
-
4292
-
4293
- /***/ }),
4294
-
4295
14
  /***/ 8442:
4296
15
  /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
4297
16
 
@@ -11508,7 +7227,7 @@ function verifyMessage(message, signature, address) {
11508
7227
  /**
11509
7228
  * Check key pair for validity
11510
7229
  *
11511
- * Sign a message, and then verifying that signature
7230
+ * Signs a message, and then verifies that signature
11512
7231
  * @param privateKey - Private key to verify
11513
7232
  * @param publicKey - Public key to verify as hex string
11514
7233
  * @returns Valid?
@@ -11595,6 +7314,7 @@ let VmVersion = /*#__PURE__*/function (VmVersion) {
11595
7314
  VmVersion[VmVersion["Fate"] = 5] = "Fate";
11596
7315
  VmVersion[VmVersion["SophiaImprovementsLima"] = 6] = "SophiaImprovementsLima";
11597
7316
  VmVersion[VmVersion["Fate2"] = 7] = "Fate2";
7317
+ VmVersion[VmVersion["Fate3"] = 8] = "Fate3";
11598
7318
  return VmVersion;
11599
7319
  }({});
11600
7320
 
@@ -11694,7 +7414,7 @@ const ProtocolToVmAbi = {
11694
7414
  },
11695
7415
  [ConsensusProtocolVersion.Ceres]: {
11696
7416
  'contract-create': {
11697
- vmVersion: [VmVersion.Fate2],
7417
+ vmVersion: [VmVersion.Fate3],
11698
7418
  abiVersion: [AbiVersion.Fate]
11699
7419
  },
11700
7420
  'contract-call': {
@@ -12315,7 +8035,7 @@ function calculateMinFee(rebuildTx, unpackTx, buildTx) {
12315
8035
  const value = new (external_bignumber_js_default())(_value !== null && _value !== void 0 ? _value : minFee);
12316
8036
  if (minFee.gt(value)) {
12317
8037
  if (_pickBiggerFee === true) return minFee.toFixed();
12318
- throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger then ${minFee}`);
8038
+ throw new IllegalArgumentError(`Fee ${value.toString()} must be bigger than ${minFee}`);
12319
8039
  }
12320
8040
  return value.toFixed();
12321
8041
  }
@@ -12530,7 +8250,7 @@ function calculateGasLimitMax(gasMax, rebuildTx, unpackTx, buildTx) {
12530
8250
  ...coin_amount,
12531
8251
  serializeAettos(value = MIN_GAS_PRICE.toString()) {
12532
8252
  if (+value < MIN_GAS_PRICE) {
12533
- throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger then ${MIN_GAS_PRICE}`);
8253
+ throw new IllegalArgumentError(`Gas price ${value.toString()} must be bigger than ${MIN_GAS_PRICE}`);
12534
8254
  }
12535
8255
  return value;
12536
8256
  }
@@ -13519,10 +9239,10 @@ const genRequestQueuesPolicy = () => {
13519
9239
  request.headers.delete('__queue');
13520
9240
  const getResponse = async () => next(request);
13521
9241
  if (key == null) return getResponse();
13522
- const req = ((_requestQueues$get = requestQueues.get(key)) !== null && _requestQueues$get !== void 0 ? _requestQueues$get : Promise.resolve()).then(getResponse, getResponse);
13523
- // TODO: remove after fixing https://github.com/aeternity/aeternity/issues/3803
9242
+ const req = ((_requestQueues$get = requestQueues.get(key)) !== null && _requestQueues$get !== void 0 ? _requestQueues$get : Promise.resolve()).then(getResponse);
9243
+ // TODO: remove pause after fixing https://github.com/aeternity/aeternity/issues/3803
13524
9244
  // gap to ensure that node won't reject the nonce
13525
- requestQueues.set(key, req.then(async () => pause(750)));
9245
+ requestQueues.set(key, req.then(async () => pause(750), () => {}));
13526
9246
  return req;
13527
9247
  }
13528
9248
  },
@@ -13607,7 +9327,7 @@ const genRetryOnFailurePolicy = (retryCount, retryOverallDelay) => ({
13607
9327
  policy: {
13608
9328
  name: 'retry-on-failure',
13609
9329
  async sendRequest(request, next) {
13610
- const statusesToNotRetry = [200, 400, 403];
9330
+ const statusesToNotRetry = [200, 400, 403, 500];
13611
9331
  const intervals = new Array(retryCount).fill(0).map((_, idx) => ((idx + 1) / retryCount) ** 2);
13612
9332
  const intervalSum = intervals.reduce((a, b) => a + b);
13613
9333
  const intervalsInMs = intervals.map(el => el / intervalSum * retryOverallDelay);
@@ -19088,6 +14808,8 @@ function Node_classPrivateMethodGet(receiver, privateSet, fn) { if (!privateSet.
19088
14808
 
19089
14809
 
19090
14810
 
14811
+
14812
+
19091
14813
  const bigIntPropertyNames = ['balance', 'queryFee', 'fee', 'amount', 'nameFee', 'channelAmount', 'initiatorAmount', 'responderAmount', 'channelReserve', 'initiatorAmountFinal', 'responderAmountFinal', 'gasPrice', 'deposit'];
19092
14814
  const numberPropertyNames = ['time', 'gas', 'gasUsed', 'nameSalt', 'nonce', 'nextNonce', 'height', 'blockHeight', 'topBlockHeight', 'ttl', 'nameTtl', 'clientTtl', 'inbound', 'outbound', 'peerCount', 'pendingTransactionsCount', 'effectiveAtHeight', 'version', 'solutions', 'round'];
19093
14815
  var _mapData = /*#__PURE__*/new WeakSet();
@@ -19137,7 +14859,7 @@ class Node_Node extends NodeTransformed {
19137
14859
  /**
19138
14860
  * @param url - Url for node API
19139
14861
  * @param options - Options
19140
- * @param options.ignoreVersion - Don't check node version
14862
+ * @param options.ignoreVersion - Don't ensure that the node is supported
19141
14863
  * @param options.retryCount - Amount of extra requests to do in case of failure
19142
14864
  * @param options.retryOverallDelay - Time in ms to wait between all retries
19143
14865
  */
@@ -19180,7 +14902,7 @@ class Node_Node extends NodeTransformed {
19180
14902
  }
19181
14903
  async getNodeInfo() {
19182
14904
  const {
19183
- nodeVersion: version,
14905
+ nodeVersion,
19184
14906
  networkId: nodeNetworkId,
19185
14907
  protocols,
19186
14908
  topBlockHeight
@@ -19191,10 +14913,17 @@ class Node_Node extends NodeTransformed {
19191
14913
  effectiveAtHeight: -1,
19192
14914
  version: 0
19193
14915
  }).version;
14916
+ if (ConsensusProtocolVersion[consensusProtocolVersion] == null) {
14917
+ const version = consensusProtocolVersion.toString();
14918
+ const versions = Object.values(ConsensusProtocolVersion).filter(el => typeof el === 'number').map(el => +el);
14919
+ const geVersion = Math.min(...versions).toString();
14920
+ const ltVersion = (Math.max(...versions) + 1).toString();
14921
+ throw new UnsupportedVersionError('consensus protocol', version, geVersion, ltVersion);
14922
+ }
19194
14923
  return {
19195
14924
  url: this.$host,
19196
14925
  nodeNetworkId,
19197
- version,
14926
+ version: nodeVersion,
19198
14927
  consensusProtocolVersion
19199
14928
  };
19200
14929
  }
@@ -19324,22 +15053,12 @@ class AccountBase {
19324
15053
  * Account address
19325
15054
  */
19326
15055
  }
19327
- // EXTERNAL MODULE: ./node_modules/@aeternity/aepp-calldata/src/ContractByteArrayEncoder.js
19328
- var ContractByteArrayEncoder = __webpack_require__(8323);
19329
- var ContractByteArrayEncoder_default = /*#__PURE__*/__webpack_require__.n(ContractByteArrayEncoder);
19330
- // EXTERNAL MODULE: ./node_modules/@aeternity/aepp-calldata/src/AciTypeResolver.js
19331
- var AciTypeResolver = __webpack_require__(6477);
19332
- var AciTypeResolver_default = /*#__PURE__*/__webpack_require__.n(AciTypeResolver);
15056
+ // EXTERNAL MODULE: external "@aeternity/aepp-calldata"
15057
+ var aepp_calldata_ = __webpack_require__(7946);
19333
15058
  // EXTERNAL MODULE: external "canonicalize"
19334
15059
  var external_canonicalize_ = __webpack_require__(6667);
19335
15060
  var external_canonicalize_default = /*#__PURE__*/__webpack_require__.n(external_canonicalize_);
19336
15061
  ;// CONCATENATED MODULE: ./src/utils/typed-data.ts
19337
- // js extension is required for mjs build
19338
- // @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
19339
- // eslint-disable-next-line import/extensions
19340
-
19341
- // @ts-expect-error see https://github.com/aeternity/aepp-calldata-js/issues/216
19342
- // eslint-disable-next-line import/extensions
19343
15062
 
19344
15063
 
19345
15064
 
@@ -19356,22 +15075,6 @@ function hashJson(data) {
19356
15075
 
19357
15076
  // TODO: move this type to calldata library https://github.com/aeternity/aepp-calldata-js/issues/215
19358
15077
  // based on https://github.com/aeternity/aepp-calldata-js/blob/82b5a98f9b308482627da8d7484d213e9cf87151/src/AciTypeResolver.js#L129
19359
- // TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
19360
- function encodeFateValue(value, aci) {
19361
- const contractByteArrayEncoder = new (ContractByteArrayEncoder_default())();
19362
- const aciTypeResolver = new (AciTypeResolver_default())([]);
19363
- aciTypeResolver.isCustomType = () => false;
19364
- return contractByteArrayEncoder.encode(aciTypeResolver.resolveType(aci), value);
19365
- }
19366
-
19367
- // TODO: replace with api on calldata side https://github.com/aeternity/aepp-calldata-js/issues/216
19368
- function decodeFateValue(value, aci) {
19369
- const contractByteArrayEncoder = new (ContractByteArrayEncoder_default())();
19370
- const aciTypeResolver = new (AciTypeResolver_default())([]);
19371
- aciTypeResolver.isCustomType = () => false;
19372
- return contractByteArrayEncoder.decodeWithType(value, aciTypeResolver.resolveType(aci));
19373
- }
19374
-
19375
15078
  /**
19376
15079
  * Hashes domain object, can be used to inline domain hash to contract source code
19377
15080
  */
@@ -19399,7 +15102,9 @@ function hashDomain(domain) {
19399
15102
  }
19400
15103
  }]
19401
15104
  };
19402
- return hash(decode(encodeFateValue(domain, domainAci)));
15105
+ const domainType = new aepp_calldata_.TypeResolver().resolveType(domainAci, {});
15106
+ const fateValue = new aepp_calldata_.ContractByteArrayEncoder().encodeWithType(domain, domainType);
15107
+ return hash(decode(fateValue));
19403
15108
  }
19404
15109
  function hashTypedData(data, aci, domain) {
19405
15110
  return hash(concatBuffers([messagePrefixLength, new Uint8Array([0]), hashDomain(domain), hashJson(aci), hash(decode(data))]));
@@ -20980,8 +16685,6 @@ async function aensBid(name, nameFee, options) {
20980
16685
  nameFee
20981
16686
  });
20982
16687
  }
20983
- // EXTERNAL MODULE: external "@aeternity/aepp-calldata"
20984
- var aepp_calldata_ = __webpack_require__(7946);
20985
16688
  ;// CONCATENATED MODULE: ./src/contract/Contract.ts
20986
16689
 
20987
16690
 
@@ -21004,6 +16707,7 @@ function Contract_classPrivateMethodGet(receiver, privateSet, fn) { if (!private
21004
16707
 
21005
16708
 
21006
16709
 
16710
+
21007
16711
  var _getCallResult = /*#__PURE__*/new WeakSet();
21008
16712
  var _sendAndProcess = /*#__PURE__*/new WeakSet();
21009
16713
  var _getFunctionAci = /*#__PURE__*/new WeakSet();
@@ -21023,7 +16727,7 @@ var _aciContract = /*#__PURE__*/new WeakMap();
21023
16727
  * const staticCallResult = await contractIns.$call('setState', [123], { callStatic: true })
21024
16728
  * ```
21025
16729
  * Also you can call contract like: `await contractIns.setState(123, options)`
21026
- * Then sdk decide to make on-chain or static call(dry-run API) transaction based on function is
16730
+ * Then sdk decide to make on-chain or static call (dry-run API) transaction based on function is
21027
16731
  * stateful or not
21028
16732
  */
21029
16733
  class Contract {
@@ -21111,7 +16815,6 @@ class Contract {
21111
16815
  code: this.$options.bytecode,
21112
16816
  ownerId
21113
16817
  });
21114
- this.$options.address = buildContractIdByContractTx(tx);
21115
16818
  const {
21116
16819
  hash,
21117
16820
  ...other
@@ -21119,6 +16822,7 @@ class Contract {
21119
16822
  ...opt,
21120
16823
  onAccount: opt.onAccount
21121
16824
  });
16825
+ this.$options.address = buildContractIdByContractTx(tx);
21122
16826
  return {
21123
16827
  ...other,
21124
16828
  ...(((_other$result = other.result) === null || _other$result === void 0 ? void 0 : _other$result.log) != null && {
@@ -21174,12 +16878,21 @@ class Contract {
21174
16878
  }
21175
16879
  const callData = this._calldata.encode(this._name, fn, params);
21176
16880
  if (callStatic === true) {
21177
- if (opt.nonce == null && top != null) {
21178
- const topKey = typeof top === 'number' ? 'height' : 'hash';
21179
- opt.nonce = (await getAccount(callerId, {
21180
- [topKey]: top,
16881
+ if (opt.nonce == null) {
16882
+ const topOption = top != null && {
16883
+ [typeof top === 'number' ? 'height' : 'hash']: top
16884
+ };
16885
+ const account = await getAccount(callerId, {
16886
+ ...topOption,
21181
16887
  onNode
21182
- })).nonce + 1;
16888
+ }).catch(error => {
16889
+ if (!isAccountNotFoundError(error)) throw error;
16890
+ return {
16891
+ kind: 'basic',
16892
+ nonce: 0
16893
+ };
16894
+ });
16895
+ opt.nonce = account.kind === 'generalized' ? 0 : account.nonce + 1;
21183
16896
  }
21184
16897
  const txOpt = {
21185
16898
  ...opt,
@@ -32072,7 +27785,7 @@ class Middleware_Middleware extends MiddlewareTransformed {
32072
27785
  /**
32073
27786
  * @param url - Url for middleware API
32074
27787
  * @param options - Options
32075
- * @param options.ignoreVersion - Don't check node version
27788
+ * @param options.ignoreVersion - Don't ensure that the middleware is supported
32076
27789
  * @param options.retryCount - Amount of extra requests to do in case of failure
32077
27790
  * @param options.retryOverallDelay - Time in ms to wait between all retries
32078
27791
  */
@@ -32287,12 +28000,17 @@ class BrowserWindowMessageConnection extends BrowserConnection {
32287
28000
  const wallet = {
32288
28001
  info: params,
32289
28002
  getConnection() {
32290
- const isExtension = params.type === 'extension';
32291
28003
  return new BrowserWindowMessageConnection({
32292
- sendDirection: isExtension ? MESSAGE_DIRECTION.to_waellet : undefined,
32293
- receiveDirection: isExtension ? MESSAGE_DIRECTION.to_aepp : undefined,
32294
28004
  target: source,
32295
- origin: isExtension ? window.origin : params.origin
28005
+ ...(params.type === 'extension' ? {
28006
+ sendDirection: MESSAGE_DIRECTION.to_waellet,
28007
+ receiveDirection: MESSAGE_DIRECTION.to_aepp,
28008
+ ...(window.origin !== 'null' && {
28009
+ origin: window.origin
28010
+ })
28011
+ } : {
28012
+ origin: params.origin
28013
+ })
32296
28014
  });
32297
28015
  }
32298
28016
  };
@@ -32361,11 +28079,11 @@ class BrowserRuntimeConnection extends BrowserConnection {
32361
28079
 
32362
28080
 
32363
28081
 
28082
+
32364
28083
  /**
32365
28084
  * @category exception
32366
28085
  * @deprecated this exception is not thrown anymore
32367
28086
  */
32368
- // eslint-disable-next-line import/prefer-default-export
32369
28087
  class RpcBroadcastError extends RpcError {
32370
28088
  constructor(data) {
32371
28089
  super('Broadcast failed');
@@ -32380,6 +28098,22 @@ class RpcBroadcastError extends RpcError {
32380
28098
  */
32381
28099
  defineProperty_default()(RpcBroadcastError, "code", 3);
32382
28100
  const NAME_BID_MAX_LENGTH = 12; // # this is the max length for a domain to be part of a bid
28101
+
28102
+ /**
28103
+ * @deprecated use ContractByteArrayEncoder:encodeWithType from \@aeternity/aepp-calldata
28104
+ */
28105
+ function encodeFateValue(value, aci) {
28106
+ const valueType = new aepp_calldata_.TypeResolver().resolveType(aci, {});
28107
+ return new aepp_calldata_.ContractByteArrayEncoder().encodeWithType(value, valueType);
28108
+ }
28109
+
28110
+ /**
28111
+ * @deprecated use ContractByteArrayEncoder:decodeWithType from \@aeternity/aepp-calldata
28112
+ */
28113
+ function decodeFateValue(value, aci) {
28114
+ const valueType = new aepp_calldata_.TypeResolver().resolveType(aci, {});
28115
+ return new aepp_calldata_.ContractByteArrayEncoder().decodeWithType(value, valueType);
28116
+ }
32383
28117
  ;// CONCATENATED MODULE: ./src/index-browser.ts
32384
28118
 
32385
28119
 
@@ -32461,13 +28195,18 @@ const getPackagePath = () => {
32461
28195
  };
32462
28196
 
32463
28197
  /**
32464
- * A wrapper around aesophia_cli, available only in Node.js
32465
- * Assumes that `escript` is available in PATH.
28198
+ * A wrapper around aesophia_cli, available only in Node.js.
28199
+ * Requires Erlang installed, assumes that `escript` is available in PATH.
32466
28200
  */
32467
28201
  var _path = /*#__PURE__*/new WeakMap();
32468
28202
  var _ensureCompatibleVersion = /*#__PURE__*/new WeakMap();
32469
28203
  var _run = /*#__PURE__*/new WeakSet();
32470
28204
  class CompilerCli extends CompilerBase {
28205
+ /**
28206
+ * @param compilerPath - A path to aesophia_cli binary, by default uses the integrated one
28207
+ * @param options - Options
28208
+ * @param options.ignoreVersion - Don't ensure that the compiler is supported
28209
+ */
32471
28210
  constructor(compilerPath = (0,external_path_namespaceObject.resolve)(getPackagePath(), './bin/aesophia_cli'), {
32472
28211
  ignoreVersion
32473
28212
  } = {}) {