@stellar-expert/tx-meta-effects-parser 7.0.0-rc.5 → 7.0.0-rc.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stellar-expert/tx-meta-effects-parser",
3
- "version": "7.0.0-rc.5",
3
+ "version": "7.0.0-rc.7",
4
4
  "description": "Low-level effects parser for Stellar transaction results and meta XDR",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -9,7 +9,7 @@
9
9
  "author": "team@stellar.expert",
10
10
  "license": "MIT",
11
11
  "peerDependencies": {
12
- "@stellar/stellar-base": "^14.0.0-rc.2"
12
+ "@stellar/stellar-base": "^14.0.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@babel/core": "^7.22.9",
@@ -1,4 +1,4 @@
1
- const {StrKey, LiquidityPoolId, scValToBigInt, xdr, Asset} = require('@stellar/stellar-base')
1
+ const {xdr, StrKey, LiquidityPoolId, Asset, scValToBigInt, encodeMuxedAccount, encodeMuxedAccountToAddress} = require('@stellar/stellar-base')
2
2
  const {TxMetaEffectParserError} = require('../errors')
3
3
 
4
4
  /**
@@ -26,10 +26,9 @@ function toStellarAsset(assetDescriptor) {
26
26
  /**
27
27
  * Parse account address from XDR representation
28
28
  * @param accountId
29
- * @param muxedAccountsSupported
30
- * @return {String|{muxedId: String, primary: String}}
29
+ * @return {String}
31
30
  */
32
- function xdrParseAccountAddress(accountId, muxedAccountsSupported = false) {
31
+ function xdrParseAccountAddress(accountId) {
33
32
  if (!accountId)
34
33
  return undefined
35
34
  if (accountId.arm) {
@@ -37,8 +36,6 @@ function xdrParseAccountAddress(accountId, muxedAccountsSupported = false) {
37
36
  case 'ed25519':
38
37
  return StrKey.encodeEd25519PublicKey(accountId.ed25519())
39
38
  case 'med25519':
40
- if (!muxedAccountsSupported)
41
- throw new TxMetaEffectParserError(`Muxed accounts not supported here`)
42
39
  return {
43
40
  primary: StrKey.encodeEd25519PublicKey(accountId.value().ed25519()),
44
41
  muxedId: accountId.value().id().toString()
@@ -53,6 +50,17 @@ function xdrParseAccountAddress(accountId, muxedAccountsSupported = false) {
53
50
  throw new TypeError(`Failed to identify and parse account address: ${accountId}`)
54
51
  }
55
52
 
53
+ /**
54
+ * Parse muxed account address from ScAddress XDR representation
55
+ * @param {{}} value
56
+ * @return {string}
57
+ */
58
+ function xdrParseMuxedScAddress(value) {
59
+ const {ed25519, id} = value._attributes
60
+ const muxed = encodeMuxedAccount(StrKey.encodeEd25519PublicKey(ed25519), id._value.toString())
61
+ return encodeMuxedAccountToAddress(muxed)
62
+ }
63
+
56
64
  /**
57
65
  * Parse Contract ID from raw bytes
58
66
  * @param {Buffer} rawContractId
@@ -257,11 +265,15 @@ function xdrParseScVal(value, treatBytesAsContractId = false) {
257
265
  case 'duration':
258
266
  return scValToBigInt(value).toString()
259
267
  case 'address':
260
- if (value._value._arm === 'accountId')
261
- return xdrParseAccountAddress(value._value.value())
262
- if (value._value._arm === 'contractId')
263
- return xdrParseContractAddress(value._value.value())
264
- throw new TxMetaEffectParserError('Not supported XDR primitive type: ' + value.toString())
268
+ switch (value._value._arm) {
269
+ case 'accountId':
270
+ return xdrParseAccountAddress(value._value.value())
271
+ case 'contractId':
272
+ return xdrParseContractAddress(value._value.value())
273
+ case 'muxedAccount':
274
+ return xdrParseMuxedScAddress(value._value.value())
275
+ }
276
+ throw new TxMetaEffectParserError('Not supported XDR primitive type: ' + value._value._arm.toString())
265
277
  case 'bytes':
266
278
  return treatBytesAsContractId ? xdrParseContractAddress(value.value()) : value._value.toString('base64')
267
279
  case 'i32':
@@ -298,6 +310,7 @@ module.exports = {
298
310
  xdrParseAsset,
299
311
  xdrParseAccountAddress,
300
312
  xdrParseContractAddress,
313
+ xdrParseMuxedScAddress,
301
314
  xdrParseClaimant,
302
315
  xdrParseClaimedOffer,
303
316
  xdrParseTradeAtom,