@vultisig/core-chain 2.23.3 → 2.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/chains/ripple/issuedCurrency.d.ts +56 -0
- package/dist/chains/ripple/issuedCurrency.d.ts.map +1 -0
- package/dist/chains/ripple/issuedCurrency.js +104 -0
- package/dist/chains/ripple/issuedCurrency.js.map +1 -0
- package/dist/utils/isValidTokenId.d.ts +2 -1
- package/dist/utils/isValidTokenId.d.ts.map +1 -1
- package/dist/utils/isValidTokenId.js +12 -1
- package/dist/utils/isValidTokenId.js.map +1 -1
- package/package.json +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @vultisig/core-chain
|
|
2
2
|
|
|
3
|
+
## 2.24.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#1042](https://github.com/vultisig/vultisig-sdk/pull/1042) [`ad6196b`](https://github.com/vultisig/vultisig-sdk/commit/ad6196b32ae879e7b0e0fda48e462fc7a05eb1de) Thanks [@Ehsan-saradar](https://github.com/Ehsan-saradar)! - feat(ripple): XRP trust-line (TrustSet) support for issued tokens
|
|
8
|
+
|
|
9
|
+
Add support for opening/modifying an XRPL trust line so a vault can hold issued
|
|
10
|
+
currencies (e.g. RLUSD). `getRippleSigningInputs` now emits a WalletCore
|
|
11
|
+
`OperationTrustSet` (LimitAmount = { currency, issuer, value }) when the keysign
|
|
12
|
+
coin is an issued currency, and falls through to the existing Payment path for
|
|
13
|
+
native XRP. New `chains/ripple/issuedCurrency` helpers encode the composite
|
|
14
|
+
`currency.issuer` token id, normalise human tickers to on-ledger currency codes,
|
|
15
|
+
format issued-currency values, and expose the 0.2 XRP owner-reserve delta
|
|
16
|
+
(`rippleOwnerReserveDrops`). `isValidTokenId` validates XRPL `currency.issuer`
|
|
17
|
+
ids.
|
|
18
|
+
|
|
3
19
|
## 2.23.3
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { KnownCoin } from '@vultisig/core-chain/coin/Coin';
|
|
2
|
+
/**
|
|
3
|
+
* Owner-reserve locked by each XRP Ledger object a wallet owns, including every
|
|
4
|
+
* trust line. Opening a trust line raises the account's required reserve by this
|
|
5
|
+
* amount (it is locked, not spent). Current mainnet value is 0.2 XRP.
|
|
6
|
+
* @see https://xrpl.org/docs/concepts/accounts/reserves
|
|
7
|
+
*/
|
|
8
|
+
export declare const rippleOwnerReserveDrops = 200000n;
|
|
9
|
+
/**
|
|
10
|
+
* Normalises a human currency ticker to the on-ledger XRPL currency code.
|
|
11
|
+
*
|
|
12
|
+
* - 3-character codes (e.g. `USD`) are standard codes and are used verbatim.
|
|
13
|
+
* - An already-encoded 40-char hex code passes through (upper-cased).
|
|
14
|
+
* - Anything else (e.g. `RLUSD`) is encoded as the 160-bit form: the ASCII bytes
|
|
15
|
+
* right-padded with zeros to 20 bytes, hex-encoded. This is what the XRP Ledger
|
|
16
|
+
* and WalletCore's Ripple signer expect for non-standard currencies.
|
|
17
|
+
*/
|
|
18
|
+
export declare const toXrplCurrencyCode: (currency: string) => string;
|
|
19
|
+
/**
|
|
20
|
+
* True if `currency` is already a valid on-ledger XRPL currency code: either a
|
|
21
|
+
* 3-character standard code or the 40-char hex (160-bit) non-standard form.
|
|
22
|
+
* A human ticker like `RLUSD` is NOT valid here - it must first be normalised
|
|
23
|
+
* via {@link toXrplCurrencyCode} before being used in a token id or TrustSet.
|
|
24
|
+
*/
|
|
25
|
+
export declare const isValidXrplCurrencyCode: (currency: string) => boolean;
|
|
26
|
+
type RippleIssuedCurrency = {
|
|
27
|
+
currency: string;
|
|
28
|
+
issuer: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Composite identifier for an XRPL issued currency: `<currencyCode>.<issuer>`.
|
|
32
|
+
* XRPL tokens are identified by the (currency, issuer) pair rather than a single
|
|
33
|
+
* contract address, so both are encoded into the coin `id`.
|
|
34
|
+
*/
|
|
35
|
+
export declare const rippleTokenId: ({ currency, issuer }: RippleIssuedCurrency) => string;
|
|
36
|
+
/** Splits a {@link rippleTokenId} back into its `currency` code and `issuer`. */
|
|
37
|
+
export declare const parseRippleTokenId: (id: string) => RippleIssuedCurrency;
|
|
38
|
+
/**
|
|
39
|
+
* Formats an issued-currency base-unit amount as an XRPL value string: a plain
|
|
40
|
+
* decimal (never scientific notation) with trailing-zero fractional digits
|
|
41
|
+
* trimmed. XRPL issued amounts allow up to 15 significant digits.
|
|
42
|
+
*/
|
|
43
|
+
export declare const formatIssuedCurrencyValue: (amount: bigint, decimals: number) => string;
|
|
44
|
+
/**
|
|
45
|
+
* XRPL issued currencies carry up to 15 significant decimal digits rather than a
|
|
46
|
+
* fixed on-chain decimal count. We model them internally with this many decimals.
|
|
47
|
+
*/
|
|
48
|
+
export declare const rippleIssuedCurrencyDecimals = 15;
|
|
49
|
+
/**
|
|
50
|
+
* Curated XRPL issued tokens surfaced in the "open trust line" flow. Not wired
|
|
51
|
+
* into `knownTokens` — issued-currency balances / asset-list display are handled
|
|
52
|
+
* separately (vultisig-windows#4307 / vultisig-sdk#997).
|
|
53
|
+
*/
|
|
54
|
+
export declare const rippleKnownIssuedTokens: KnownCoin[];
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=issuedCurrency.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issuedCurrency.d.ts","sourceRoot":"","sources":["../../../../../../packages/core/chain/chains/ripple/issuedCurrency.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,UAAU,CAAA;AAqB9C;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAAI,UAAU,MAAM,KAAG,MAYrD,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAAI,UAAU,MAAM,KAAG,OAEyB,CAAA;AAIpF,KAAK,oBAAoB,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAA;IAChB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAI,sBAAsB,oBAAoB,KAAG,MACZ,CAAA;AAE/D,iFAAiF;AACjF,eAAO,MAAM,kBAAkB,GAAI,IAAI,MAAM,KAAG,oBAU/C,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,yBAAyB,GAAI,QAAQ,MAAM,EAAE,UAAU,MAAM,KAAG,MAU5E,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,4BAA4B,KAAK,CAAA;AAE9C;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,EAY9C,CAAA"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { Chain } from '@vultisig/core-chain/Chain';
|
|
2
|
+
/**
|
|
3
|
+
* Owner-reserve locked by each XRP Ledger object a wallet owns, including every
|
|
4
|
+
* trust line. Opening a trust line raises the account's required reserve by this
|
|
5
|
+
* amount (it is locked, not spent). Current mainnet value is 0.2 XRP.
|
|
6
|
+
* @see https://xrpl.org/docs/concepts/accounts/reserves
|
|
7
|
+
*/
|
|
8
|
+
export const rippleOwnerReserveDrops = 200000n;
|
|
9
|
+
/** XRPL "standard" (ISO-4217-like) currency codes are exactly 3 characters. */
|
|
10
|
+
const standardCurrencyCodeLength = 3;
|
|
11
|
+
/** Non-standard XRPL currency codes are a 160-bit value, i.e. 40 hex chars. */
|
|
12
|
+
const hexCurrencyCodeLength = 40;
|
|
13
|
+
const hexCurrencyCodeRegex = /^[0-9a-fA-F]{40}$/;
|
|
14
|
+
const asciiToHexCurrencyCode = (currency) => {
|
|
15
|
+
const bytes = Buffer.from(currency, 'ascii');
|
|
16
|
+
if (bytes.length > 20) {
|
|
17
|
+
throw new Error(`XRPL currency code too long: "${currency}" (max 20 bytes)`);
|
|
18
|
+
}
|
|
19
|
+
return Buffer.concat([bytes, Buffer.alloc(20 - bytes.length)])
|
|
20
|
+
.toString('hex')
|
|
21
|
+
.toUpperCase();
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Normalises a human currency ticker to the on-ledger XRPL currency code.
|
|
25
|
+
*
|
|
26
|
+
* - 3-character codes (e.g. `USD`) are standard codes and are used verbatim.
|
|
27
|
+
* - An already-encoded 40-char hex code passes through (upper-cased).
|
|
28
|
+
* - Anything else (e.g. `RLUSD`) is encoded as the 160-bit form: the ASCII bytes
|
|
29
|
+
* right-padded with zeros to 20 bytes, hex-encoded. This is what the XRP Ledger
|
|
30
|
+
* and WalletCore's Ripple signer expect for non-standard currencies.
|
|
31
|
+
*/
|
|
32
|
+
export const toXrplCurrencyCode = (currency) => {
|
|
33
|
+
const value = currency.trim();
|
|
34
|
+
if (value.length === standardCurrencyCodeLength) {
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
if (value.length === hexCurrencyCodeLength && hexCurrencyCodeRegex.test(value)) {
|
|
38
|
+
return value.toUpperCase();
|
|
39
|
+
}
|
|
40
|
+
return asciiToHexCurrencyCode(value);
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* True if `currency` is already a valid on-ledger XRPL currency code: either a
|
|
44
|
+
* 3-character standard code or the 40-char hex (160-bit) non-standard form.
|
|
45
|
+
* A human ticker like `RLUSD` is NOT valid here - it must first be normalised
|
|
46
|
+
* via {@link toXrplCurrencyCode} before being used in a token id or TrustSet.
|
|
47
|
+
*/
|
|
48
|
+
export const isValidXrplCurrencyCode = (currency) => currency.length === standardCurrencyCodeLength ||
|
|
49
|
+
(currency.length === hexCurrencyCodeLength && hexCurrencyCodeRegex.test(currency));
|
|
50
|
+
const tokenIdSeparator = '.';
|
|
51
|
+
/**
|
|
52
|
+
* Composite identifier for an XRPL issued currency: `<currencyCode>.<issuer>`.
|
|
53
|
+
* XRPL tokens are identified by the (currency, issuer) pair rather than a single
|
|
54
|
+
* contract address, so both are encoded into the coin `id`.
|
|
55
|
+
*/
|
|
56
|
+
export const rippleTokenId = ({ currency, issuer }) => `${toXrplCurrencyCode(currency)}${tokenIdSeparator}${issuer}`;
|
|
57
|
+
/** Splits a {@link rippleTokenId} back into its `currency` code and `issuer`. */
|
|
58
|
+
export const parseRippleTokenId = (id) => {
|
|
59
|
+
const index = id.indexOf(tokenIdSeparator);
|
|
60
|
+
if (index <= 0 || index === id.length - 1) {
|
|
61
|
+
throw new Error(`Invalid Ripple token id: "${id}"`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
currency: id.slice(0, index),
|
|
65
|
+
issuer: id.slice(index + 1),
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Formats an issued-currency base-unit amount as an XRPL value string: a plain
|
|
70
|
+
* decimal (never scientific notation) with trailing-zero fractional digits
|
|
71
|
+
* trimmed. XRPL issued amounts allow up to 15 significant digits.
|
|
72
|
+
*/
|
|
73
|
+
export const formatIssuedCurrencyValue = (amount, decimals) => {
|
|
74
|
+
const negative = amount < 0n;
|
|
75
|
+
const digits = (negative ? -amount : amount).toString().padStart(decimals + 1, '0');
|
|
76
|
+
const intPart = digits.slice(0, digits.length - decimals) || '0';
|
|
77
|
+
const fracPart = decimals > 0 ? digits.slice(digits.length - decimals).replace(/0+$/, '') : '';
|
|
78
|
+
const magnitude = fracPart ? `${intPart}.${fracPart}` : intPart;
|
|
79
|
+
return negative && magnitude !== '0' ? `-${magnitude}` : magnitude;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* XRPL issued currencies carry up to 15 significant decimal digits rather than a
|
|
83
|
+
* fixed on-chain decimal count. We model them internally with this many decimals.
|
|
84
|
+
*/
|
|
85
|
+
export const rippleIssuedCurrencyDecimals = 15;
|
|
86
|
+
/**
|
|
87
|
+
* Curated XRPL issued tokens surfaced in the "open trust line" flow. Not wired
|
|
88
|
+
* into `knownTokens` — issued-currency balances / asset-list display are handled
|
|
89
|
+
* separately (vultisig-windows#4307 / vultisig-sdk#997).
|
|
90
|
+
*/
|
|
91
|
+
export const rippleKnownIssuedTokens = [
|
|
92
|
+
{
|
|
93
|
+
chain: Chain.Ripple,
|
|
94
|
+
id: rippleTokenId({
|
|
95
|
+
currency: 'RLUSD',
|
|
96
|
+
issuer: 'rMxCKbEDwqr76QuheSUMdEGf4B9xJ8m5De',
|
|
97
|
+
}),
|
|
98
|
+
ticker: 'RLUSD',
|
|
99
|
+
logo: 'rlusd',
|
|
100
|
+
decimals: rippleIssuedCurrencyDecimals,
|
|
101
|
+
priceProviderId: 'ripple-usd',
|
|
102
|
+
},
|
|
103
|
+
];
|
|
104
|
+
//# sourceMappingURL=issuedCurrency.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issuedCurrency.js","sourceRoot":"","sources":["../../../../../../packages/core/chain/chains/ripple/issuedCurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAGlD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAA;AAE9C,+EAA+E;AAC/E,MAAM,0BAA0B,GAAG,CAAC,CAAA;AAEpC,+EAA+E;AAC/E,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEhC,MAAM,oBAAoB,GAAG,mBAAmB,CAAA;AAEhD,MAAM,sBAAsB,GAAG,CAAC,QAAgB,EAAU,EAAE;IAC1D,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAA;IAC5C,IAAI,KAAK,CAAC,MAAM,GAAG,EAAE,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,QAAQ,kBAAkB,CAAC,CAAA;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,GAA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AM,uBAAuB,GAAgB;IAClD;QACE,KAAK,EAAE,KAAK,CAAC,MAAM;QACnB,EAAE,EAAE,aAAa,CAAC;YAChB,QAAQ,EAAE,OAAO;YACjB,MAAM,EAAE,oCAAoC;SAC7C,CAAC;QACF,MAAM,EAAE,OAAO;QACf,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,4BAA4B;QACtC,eAAe,EAAE,YAAY;KAC9B;CACF,CAAA"}
|
|
@@ -11,7 +11,8 @@ type Input = {
|
|
|
11
11
|
* For most chains a token is identified by an address (contract/mint), so this
|
|
12
12
|
* delegates to {@link isValidAddress}. SUI tokens are identified by their fully
|
|
13
13
|
* qualified coin type (e.g. `0x2::sui::SUI`), which is a Move struct tag rather
|
|
14
|
-
* than an account address, so it is validated separately.
|
|
14
|
+
* than an account address, so it is validated separately. XRPL issued currencies
|
|
15
|
+
* are identified by a composite `currency.issuer` id and validated as such.
|
|
15
16
|
*/
|
|
16
17
|
export declare const isValidTokenId: ({ chain, id, walletCore }: Input) => boolean;
|
|
17
18
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isValidTokenId.d.ts","sourceRoot":"","sources":["../../../../../packages/core/chain/utils/isValidTokenId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"isValidTokenId.d.ts","sourceRoot":"","sources":["../../../../../packages/core/chain/utils/isValidTokenId.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAMlD,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,KAAK,CAAA;IACZ,EAAE,EAAE,MAAM,CAAA;IACV,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,GAAI,2BAA2B,KAAK,YAgB9D,CAAA"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { isValidStructTag } from '@mysten/sui/utils';
|
|
2
2
|
import { Chain } from '@vultisig/core-chain/Chain';
|
|
3
|
+
import { isValidXrplCurrencyCode, parseRippleTokenId } from '@vultisig/core-chain/chains/ripple/issuedCurrency';
|
|
4
|
+
import { attempt } from '@vultisig/lib-utils/attempt';
|
|
3
5
|
import { isValidAddress } from './isValidAddress.js';
|
|
4
6
|
/**
|
|
5
7
|
* Validates a custom token identifier for a given chain.
|
|
@@ -7,12 +9,21 @@ import { isValidAddress } from './isValidAddress.js';
|
|
|
7
9
|
* For most chains a token is identified by an address (contract/mint), so this
|
|
8
10
|
* delegates to {@link isValidAddress}. SUI tokens are identified by their fully
|
|
9
11
|
* qualified coin type (e.g. `0x2::sui::SUI`), which is a Move struct tag rather
|
|
10
|
-
* than an account address, so it is validated separately.
|
|
12
|
+
* than an account address, so it is validated separately. XRPL issued currencies
|
|
13
|
+
* are identified by a composite `currency.issuer` id and validated as such.
|
|
11
14
|
*/
|
|
12
15
|
export const isValidTokenId = ({ chain, id, walletCore }) => {
|
|
13
16
|
if (chain === Chain.Sui) {
|
|
14
17
|
return isValidStructTag(id.trim());
|
|
15
18
|
}
|
|
19
|
+
if (chain === Chain.Ripple) {
|
|
20
|
+
const parsed = attempt(() => parseRippleTokenId(id.trim()));
|
|
21
|
+
if ('error' in parsed) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
const { currency, issuer } = parsed.data;
|
|
25
|
+
return isValidXrplCurrencyCode(currency) && isValidAddress({ chain, address: issuer, walletCore });
|
|
26
|
+
}
|
|
16
27
|
return isValidAddress({ chain, address: id, walletCore });
|
|
17
28
|
};
|
|
18
29
|
//# sourceMappingURL=isValidTokenId.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isValidTokenId.js","sourceRoot":"","sources":["../../../../../packages/core/chain/utils/isValidTokenId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"isValidTokenId.js","sourceRoot":"","sources":["../../../../../packages/core/chain/utils/isValidTokenId.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAEpD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAA;AAClD,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,mDAAmD,CAAA;AAC/G,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAA;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAQjD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,EAAS,EAAE,EAAE;IACjE,IAAI,KAAK,KAAK,KAAK,CAAC,GAAG,EAAE,CAAC;QACxB,OAAO,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAA;IACpC,CAAC;IAED,IAAI,KAAK,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,CAAA;QAC3D,IAAI,OAAO,IAAI,MAAM,EAAE,CAAC;YACtB,OAAO,KAAK,CAAA;QACd,CAAC;QACD,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC,IAAI,CAAA;QAExC,OAAO,uBAAuB,CAAC,QAAQ,CAAC,IAAI,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAA;IACpG,CAAC;IAED,OAAO,cAAc,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,UAAU,EAAE,CAAC,CAAA;AAC3D,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vultisig/core-chain",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.24.0",
|
|
4
4
|
"description": "Blockchain chain logic shared across Vultisig clients",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -660,6 +660,11 @@
|
|
|
660
660
|
"import": "./dist/chains/ripple/client.js",
|
|
661
661
|
"default": "./dist/chains/ripple/client.js"
|
|
662
662
|
},
|
|
663
|
+
"./chains/ripple/issuedCurrency": {
|
|
664
|
+
"types": "./dist/chains/ripple/issuedCurrency.d.ts",
|
|
665
|
+
"import": "./dist/chains/ripple/issuedCurrency.js",
|
|
666
|
+
"default": "./dist/chains/ripple/issuedCurrency.js"
|
|
667
|
+
},
|
|
663
668
|
"./chains/ripple/network/info": {
|
|
664
669
|
"types": "./dist/chains/ripple/network/info.d.ts",
|
|
665
670
|
"import": "./dist/chains/ripple/network/info.js",
|