@avalabs/core-wallets-sdk 2.8.0-alpha.197
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/LICENSE +9 -0
- package/README.md +9 -0
- package/dist/index.d.ts +1794 -0
- package/dist/index.js +1 -0
- package/esm/Avalanche/index.d.ts +41 -0
- package/esm/Avalanche/index.js +1 -0
- package/esm/Avalanche/models.d.ts +173 -0
- package/esm/Avalanche/models.js +1 -0
- package/esm/Avalanche/providers/AbstractProvider.d.ts +39 -0
- package/esm/Avalanche/providers/AbstractProvider.js +1 -0
- package/esm/Avalanche/providers/JsonRpcProvider.d.ts +11 -0
- package/esm/Avalanche/providers/JsonRpcProvider.js +1 -0
- package/esm/Avalanche/providers/constants.d.ts +12 -0
- package/esm/Avalanche/providers/constants.js +1 -0
- package/esm/Avalanche/utils/addSignaturesToAvalancheTx.d.ts +16 -0
- package/esm/Avalanche/utils/addSignaturesToAvalancheTx.js +1 -0
- package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +7 -0
- package/esm/Avalanche/utils/convertGlacierUtxo.js +1 -0
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.d.ts +11 -0
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.js +1 -0
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.d.ts +13 -0
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -0
- package/esm/Avalanche/utils/digestMessage.d.ts +3 -0
- package/esm/Avalanche/utils/digestMessage.js +1 -0
- package/esm/Avalanche/utils/getAddressFromXpub.d.ts +14 -0
- package/esm/Avalanche/utils/getAddressFromXpub.js +1 -0
- package/esm/Avalanche/utils/getAddressPublicKeyFromXpub.d.ts +9 -0
- package/esm/Avalanche/utils/getAddressPublicKeyFromXpub.js +1 -0
- package/esm/Avalanche/utils/getAllUTXOs.d.ts +17 -0
- package/esm/Avalanche/utils/getAllUTXOs.js +1 -0
- package/esm/Avalanche/utils/getAssetBalance.d.ts +29 -0
- package/esm/Avalanche/utils/getAssetBalance.js +1 -0
- package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -0
- package/esm/Avalanche/utils/getPchainUnixNow.d.ts +6 -0
- package/esm/Avalanche/utils/getPchainUnixNow.js +1 -0
- package/esm/Avalanche/utils/getStakeForAddresses.d.ts +5 -0
- package/esm/Avalanche/utils/getStakeForAddresses.js +1 -0
- package/esm/Avalanche/utils/getStakedAssetBalance.d.ts +16 -0
- package/esm/Avalanche/utils/getStakedAssetBalance.js +1 -0
- package/esm/Avalanche/utils/getTxOutputAddresses.js +1 -0
- package/esm/Avalanche/utils/getUnixNow.d.ts +6 -0
- package/esm/Avalanche/utils/getUnixNow.js +1 -0
- package/esm/Avalanche/utils/getUtxoInfo.d.ts +13 -0
- package/esm/Avalanche/utils/getUtxoInfo.js +1 -0
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +13 -0
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -0
- package/esm/Avalanche/utils/getVmByChainAlias.d.ts +3 -0
- package/esm/Avalanche/utils/getVmByChainAlias.js +1 -0
- package/esm/Avalanche/utils/getXpubFromMnemonic.d.ts +7 -0
- package/esm/Avalanche/utils/getXpubFromMnemonic.js +1 -0
- package/esm/Avalanche/utils/handleSubnetAuth.js +1 -0
- package/esm/Avalanche/utils/isBech32Address.d.ts +8 -0
- package/esm/Avalanche/utils/isBech32Address.js +1 -0
- package/esm/Avalanche/utils/parseAvalancheTx.d.ts +10 -0
- package/esm/Avalanche/utils/parseAvalancheTx.js +1 -0
- package/esm/Avalanche/utils/parsers/index.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddDelegatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddSubnetValidorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseAddValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseBaseTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseCreateChainTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseCreateSubnetTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseExportTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseImportTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseRemoveSubnetValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseTransferSubnetOwnershipTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseTransformSubnetTx.js +1 -0
- package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -0
- package/esm/Avalanche/utils/parsers/utils/getTransferableAmount.js +1 -0
- package/esm/Avalanche/utils/populateCredential.d.ts +9 -0
- package/esm/Avalanche/utils/populateCredential.js +1 -0
- package/esm/Avalanche/utils/signedTxToHex.d.ts +5 -0
- package/esm/Avalanche/utils/signedTxToHex.js +1 -0
- package/esm/Avalanche/utils/sortUTXOs.d.ts +14 -0
- package/esm/Avalanche/utils/sortUTXOs.js +1 -0
- package/esm/Avalanche/utils/txSizeLimits.d.ts +34 -0
- package/esm/Avalanche/utils/txSizeLimits.js +1 -0
- package/esm/Avalanche/utils/verifyDerivationPath.d.ts +7 -0
- package/esm/Avalanche/utils/verifyDerivationPath.js +1 -0
- package/esm/Avalanche/wallets/AddressWallet.d.ts +45 -0
- package/esm/Avalanche/wallets/AddressWallet.js +1 -0
- package/esm/Avalanche/wallets/SimpleSigner.d.ts +62 -0
- package/esm/Avalanche/wallets/SimpleSigner.js +1 -0
- package/esm/Avalanche/wallets/StaticSigner.d.ts +39 -0
- package/esm/Avalanche/wallets/StaticSigner.js +1 -0
- package/esm/Avalanche/wallets/WalletAbstract.d.ts +131 -0
- package/esm/Avalanche/wallets/WalletAbstract.js +1 -0
- package/esm/Avalanche/wallets/WalletVoid.d.ts +40 -0
- package/esm/Avalanche/wallets/WalletVoid.js +1 -0
- package/esm/Avalanche/wallets/ledger/LedgerSigner.d.ts +49 -0
- package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -0
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.d.ts +32 -0
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -0
- package/esm/Avalanche/wallets/ledger/ZondaxProvider.js +1 -0
- package/esm/Avalanche/wallets/ledger/constants.js +1 -0
- package/esm/Avalanche/wallets/ledger/getLedgerProvider.d.ts +10 -0
- package/esm/Avalanche/wallets/ledger/getLedgerProvider.js +1 -0
- package/esm/Avalanche/wallets/ledger/isObsidianApp.d.ts +5 -0
- package/esm/Avalanche/wallets/ledger/isObsidianApp.js +1 -0
- package/esm/Avalanche/wallets/ledger/models.d.ts +37 -0
- package/esm/Avalanche/wallets/legacy/LedgerWallet.d.ts +41 -0
- package/esm/Avalanche/wallets/legacy/LedgerWallet.js +1 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWallet.d.ts +30 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWallet.js +1 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.d.ts +83 -0
- package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.js +1 -0
- package/esm/Avalanche/wallets/models.d.ts +35 -0
- package/esm/BitcoinVM/models.d.ts +77 -0
- package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +42 -0
- package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -0
- package/esm/BitcoinVM/providers/BitcoinProviderAbstract.d.ts +63 -0
- package/esm/BitcoinVM/providers/BitcoinProviderAbstract.js +1 -0
- package/esm/BitcoinVM/providers/models.js +1 -0
- package/esm/BitcoinVM/providers/utils/parseAddressFullTx.js +1 -0
- package/esm/BitcoinVM/utils/addEncodedSigToPsbt.d.ts +5 -0
- package/esm/BitcoinVM/utils/addEncodedSigToPsbt.js +1 -0
- package/esm/BitcoinVM/utils/createPSBTV2.d.ts +10 -0
- package/esm/BitcoinVM/utils/createPSBTV2.js +1 -0
- package/esm/BitcoinVM/utils/createPsbt.d.ts +12 -0
- package/esm/BitcoinVM/utils/createPsbt.js +1 -0
- package/esm/BitcoinVM/utils/createTransferTx.d.ts +20 -0
- package/esm/BitcoinVM/utils/createTransferTx.js +1 -0
- package/esm/BitcoinVM/utils/createWalletPolicy.d.ts +5 -0
- package/esm/BitcoinVM/utils/createWalletPolicy.js +1 -0
- package/esm/BitcoinVM/utils/filterDuplicateUTXOs.js +1 -0
- package/esm/BitcoinVM/utils/formatAddressForNetworkBech32.d.ts +10 -0
- package/esm/BitcoinVM/utils/formatAddressForNetworkBech32.js +1 -0
- package/esm/BitcoinVM/utils/getBech32Address.d.ts +10 -0
- package/esm/BitcoinVM/utils/getBech32Address.js +1 -0
- package/esm/BitcoinVM/utils/getBech32AddressFromXPub.d.ts +11 -0
- package/esm/BitcoinVM/utils/getBech32AddressFromXPub.js +1 -0
- package/esm/BitcoinVM/utils/getMaxTransferAmount.d.ts +13 -0
- package/esm/BitcoinVM/utils/getMaxTransferAmount.js +1 -0
- package/esm/BitcoinVM/utils/getTransferTxDetails.d.ts +17 -0
- package/esm/BitcoinVM/utils/getTransferTxDetails.js +1 -0
- package/esm/BitcoinVM/utils/psbt2ToPsbt0.d.ts +15 -0
- package/esm/BitcoinVM/utils/psbt2ToPsbt0.js +1 -0
- package/esm/BitcoinVM/utils/selectUtxos.d.ts +22 -0
- package/esm/BitcoinVM/utils/selectUtxos.js +1 -0
- package/esm/BitcoinVM/utils/sumUTXOs.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWallet.d.ts +44 -0
- package/esm/BitcoinVM/wallets/BitcoinWallet.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletAbstract.d.ts +72 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletAbstract.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletLedger.d.ts +34 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletLedger.js +1 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletVoid.d.ts +12 -0
- package/esm/BitcoinVM/wallets/BitcoinWalletVoid.js +1 -0
- package/esm/BitcoinVM/wallets/models.d.ts +8 -0
- package/esm/EVM/LedgerSigner.d.ts +23 -0
- package/esm/EVM/LedgerSigner.js +1 -0
- package/esm/EVM/constants.d.ts +8 -0
- package/esm/EVM/constants.js +1 -0
- package/esm/EVM/utils/blockPolling.d.ts +12 -0
- package/esm/EVM/utils/blockPolling.js +1 -0
- package/esm/EVM/utils/getAddressFromXPub.d.ts +9 -0
- package/esm/EVM/utils/getAddressFromXPub.js +1 -0
- package/esm/EVM/utils/getAddressPrivateKeyFromXPriv.d.ts +9 -0
- package/esm/EVM/utils/getAddressPrivateKeyFromXPriv.js +1 -0
- package/esm/EVM/utils/getAddressPublicKeyFromXPub.d.ts +9 -0
- package/esm/EVM/utils/getAddressPublicKeyFromXPub.js +1 -0
- package/esm/EVM/utils/getAppEth.d.ts +10 -0
- package/esm/EVM/utils/getAppEth.js +1 -0
- package/esm/EVM/utils/getBtcAddressFromPubKey.d.ts +10 -0
- package/esm/EVM/utils/getBtcAddressFromPubKey.js +1 -0
- package/esm/EVM/utils/getEvmAddressFromPubKey.d.ts +3 -0
- package/esm/EVM/utils/getEvmAddressFromPubKey.js +1 -0
- package/esm/EVM/utils/getVoidSigner.d.ts +10 -0
- package/esm/EVM/utils/getVoidSigner.js +1 -0
- package/esm/EVM/utils/getWalletFromMnemonic.d.ts +13 -0
- package/esm/EVM/utils/getWalletFromMnemonic.js +1 -0
- package/esm/EVM/utils/getXpubFromMnemonic.d.ts +7 -0
- package/esm/EVM/utils/getXpubFromMnemonic.js +1 -0
- package/esm/EVM/utils/jsonRpcBatchProvider.d.ts +31 -0
- package/esm/EVM/utils/jsonRpcBatchProvider.js +1 -0
- package/esm/EVM/utils/multicallABI.js +1 -0
- package/esm/index.d.ts +43 -0
- package/esm/index.js +1 -0
- package/esm/utils/binarySearch.js +1 -0
- package/esm/utils/getAddressDerivationPath.d.ts +11 -0
- package/esm/utils/getAddressDerivationPath.js +1 -0
- package/esm/utils/getLedgerAppInfo.d.ts +13 -0
- package/esm/utils/getLedgerAppInfo.js +1 -0
- package/esm/utils/getLedgerExtendedPublicKey.d.ts +12 -0
- package/esm/utils/getLedgerExtendedPublicKey.js +1 -0
- package/esm/utils/getPubKeyFromTransport.d.ts +7 -0
- package/esm/utils/getPubKeyFromTransport.js +1 -0
- package/esm/utils/getPublicKeyFromPrivateKey.d.ts +8 -0
- package/esm/utils/getPublicKeyFromPrivateKey.js +1 -0
- package/esm/utils/omitUndefinedKeys.d.ts +3 -0
- package/esm/utils/omitUndefinedKeys.js +1 -0
- package/esm/utils/openLedgerApp.d.ts +9 -0
- package/esm/utils/openLedgerApp.js +1 -0
- package/esm/utils/quitLedgerApp.d.ts +10 -0
- package/esm/utils/quitLedgerApp.js +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { utils } from '@avalabs/avalanchejs';
|
|
2
|
+
|
|
3
|
+
interface GetAvaxBalanceDict {
|
|
4
|
+
/**
|
|
5
|
+
* UTXOS that have a locktime in the future
|
|
6
|
+
*/
|
|
7
|
+
locked: bigint;
|
|
8
|
+
/**
|
|
9
|
+
* UTXOs that can be consumed
|
|
10
|
+
*/
|
|
11
|
+
available: bigint;
|
|
12
|
+
/**
|
|
13
|
+
* UTXOs with a threshold of > 1
|
|
14
|
+
*/
|
|
15
|
+
multisig: bigint;
|
|
16
|
+
/**
|
|
17
|
+
* LockedStakeable UTXOs, only on P chain
|
|
18
|
+
*/
|
|
19
|
+
lockedStakeable: bigint;
|
|
20
|
+
total: bigint;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Sum the UTXOs into multiple buckets.
|
|
24
|
+
* @param utxoSet
|
|
25
|
+
* @param assetID
|
|
26
|
+
*/
|
|
27
|
+
declare function getAssetBalance(utxoSet: utils.UtxoSet, assetID: string): GetAvaxBalanceDict;
|
|
28
|
+
|
|
29
|
+
export { GetAvaxBalanceDict, getAssetBalance };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getUnixNow as t}from"./getUnixNow.js";import{getUtxoInfo as e}from"./getUtxoInfo.js";function o(o,l){const i=o.getAssetDict()[l],a={locked:BigInt(0),available:BigInt(0),multisig:BigInt(0),lockedStakeable:BigInt(0),total:BigInt(0)};if(!i)return a;const n=i.getUTXOs(),c=t();return n.forEach((t=>{const o=e(t);a[o.threshold>1?"multisig":o.locktime>c?"locked":o.stakeableLocktime>c?"lockedStakeable":"available"]+=o.amount})),a.total=a.locked+a.lockedStakeable+a.multisig+a.available,a}export{o as getAssetBalance};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"@avalabs/avalanchejs";import"@avalabs/core-utils-sdk";import"ethers";import{FujiContext as r,MainnetContext as a}from"../providers/constants.js";import"@avalabs/chains-sdk";const o=(o,n)=>{const{cBlockchainID:t,xBlockchainID:i,pBlockchainID:s}=n?r:a;if(t===o)return"C";if(i===o)return"X";if(s===o)return"P";throw new Error(`Unknown chainId "${o}"`)};export{o as getChainAliasByChainId};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{JsonRpcProvider as e}from"../providers/JsonRpcProvider.js";async function t(t){const i=t?e.getDefaultFujiProvider():e.getDefaultMainnetProvider(),r=await i.getApiP().getTimestamp(),o=new Date(r.timestamp),a=Math.floor(o.getTime()/1e3);return BigInt(a)}export{t as getPchainUnixNow};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
async function t(s,e){const a=s.slice(0,256),u=s.slice(256),d=await e.getStake({addresses:a});if(u.length){const s=await t(u,e);return{staked:d.staked+s.staked,stakedOutputs:[...d.stakedOutputs,...s.stakedOutputs]}}return d}export{t as getStakeForAddresses};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { pvm } from '@avalabs/avalanchejs';
|
|
2
|
+
|
|
3
|
+
interface GetStakedAvaxBalanceDict {
|
|
4
|
+
/**
|
|
5
|
+
* UTXOs that are NOT of type LockedStakeable out
|
|
6
|
+
*/
|
|
7
|
+
unlockedStaked: bigint;
|
|
8
|
+
/**
|
|
9
|
+
* UTXOs that are of type LockedStakeable out
|
|
10
|
+
*/
|
|
11
|
+
lockedStaked: bigint;
|
|
12
|
+
total: bigint;
|
|
13
|
+
}
|
|
14
|
+
declare function getStakedAssetBalance(stakeResponse: pvm.GetStakeResponse): GetStakedAvaxBalanceDict;
|
|
15
|
+
|
|
16
|
+
export { GetStakedAvaxBalanceDict, getStakedAssetBalance };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{utils as t}from"@avalabs/avalanchejs";function a(a){const{stakedOutputs:e}=a,o={unlockedStaked:BigInt(0),lockedStaked:BigInt(0),total:BigInt(0)};return e.forEach((a=>{o[t.isStakeableLockOut(a)?"lockedStaked":"unlockedStaked"]+=a.amount()})),o.total=o.lockedStaked+o.unlockedStaked,o}export{a as getStakedAssetBalance};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{avmSerial as t,pvmSerial as e,evmSerial as a,utils as o}from"@avalabs/avalanchejs";const{isTransferOut:s,isStakeableLockOut:n}=o;function r(t){const e=t.output;return s(e)||n(e)?e.getOwners():[]}function u(o){const s=o.getTx();return t.isExportTx(s)||e.isExportTx(s)?new Set(s.outs.map(r).flat()):a.isExportTx(s)?new Set(s.exportedOutputs.map(r).flat()):new Set((s.baseTx?.outputs??[]).map(r).flat())}export{r as getOutputAddresses,u as getTxOutputAddresses};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function t(){return BigInt(Math.floor(Date.now()/1e3))}export{t as getUnixNow};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
|
+
|
|
3
|
+
type UtxoInfo = {
|
|
4
|
+
utxoId: string;
|
|
5
|
+
assetId: string;
|
|
6
|
+
locktime: bigint;
|
|
7
|
+
stakeableLocktime: bigint;
|
|
8
|
+
threshold: number;
|
|
9
|
+
amount: bigint;
|
|
10
|
+
};
|
|
11
|
+
declare const getUtxoInfo: (utxo: Utxo) => UtxoInfo;
|
|
12
|
+
|
|
13
|
+
export { UtxoInfo, getUtxoInfo };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{utils as t}from"@avalabs/avalanchejs";const{isStakeableLockOut:e,isTransferOut:a}=t,o=t=>{const o=t.output,s=t.getOutputOwners();return{utxoId:t.ID(),assetId:t.getAssetId(),amount:a(o)||e(o)?o.amount():BigInt(0),locktime:s.locktime.value(),stakeableLocktime:e(o)?o.getStakeableLocktime():BigInt(0),threshold:s.threshold.value()}};export{o as getUtxoInfo};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
|
+
import { ChainIDAlias } from '../models.js';
|
|
3
|
+
|
|
4
|
+
type Params = {
|
|
5
|
+
transactionHex: string;
|
|
6
|
+
chainAlias: ChainIDAlias;
|
|
7
|
+
isTestnet: boolean;
|
|
8
|
+
url: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
};
|
|
11
|
+
declare const getUtxosByTxFromGlacier: ({ transactionHex, chainAlias, isTestnet, url, token, }: Params) => Promise<Utxo[]>;
|
|
12
|
+
|
|
13
|
+
export { getUtxosByTxFromGlacier };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Glacier as t,Network as r,BlockchainId as o}from"@avalabs/glacier-sdk";import{evmSerial as e,utils as n,avmSerial as a,pvmSerial as i,PVM as s,AVM as x,EVM as c}from"@avalabs/avalanchejs";import{getVmByChainAlias as u}from"./getVmByChainAlias.js";import{convertGlacierUtxo as I}from"./convertGlacierUtxo.js";const{getTransferableInputsByTx:p,hexToBuffer:f,unpackWithManager:l}=n,m=async({transactionHex:n,chainAlias:m,isTestnet:h,url:T,token:d})=>{const w=u(m),g=f(n),D=l(w,g);if(e.isExportTx(D))return[];const b=(t=>{if(e.isImportTx(t)||a.isImportTx(t)||i.isImportTx(t))return t.sourceChain.toString();const r=t.getVM();switch(r){case c:return o.C_CHAIN;case x:return o.X_CHAIN;case s:return o.P_CHAIN;default:throw new Error(`Unable to get chain for VM type "${r}"`)}})(D),A=p(D),E=new t({BASE:T,TOKEN:d}),H=h?r.FUJI:r.MAINNET,N=[...new Set(A.map((t=>t.utxoID.txID.toString())))],U=await Promise.all(N.map((t=>E.primaryNetworkTransactions.getTxByHash({blockchainId:b,network:H,txHash:t}))));return A.reduce(((t,r)=>{const o=U.find((t=>t.txHash===r.utxoID.txID.toString()));if(!o)throw new Error(`Unable to find parent tx "${r.utxoID.txID.toString()}"`);const e=o.emittedUtxos.find((t=>t.utxoId===r.utxoID.ID()));if(!e)throw new Error(`Unable to find UTXO "${r.utxoID.ID()}" at index "${r.utxoID.outputIdx.value()}"`);const n=I(e,h);return t.push(n),t}),[])};export{m as getUtxosByTxFromGlacier};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{PVM as r,AVM as e,EVM as a}from"@avalabs/avalanchejs";const t=t=>{switch(t){case"C":return a;case"X":return e;case"P":return r;default:throw new Error(`Unable to get VM type for chain "${t}"`)}};export{t as getVmByChainAlias};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{validateMnemonic as r,mnemonicToSeedSync as e}from"bip39";import{fromSeed as o}from"bip32";function t(t){if(!r(t))throw new Error("Invalid mnemonic phrase.");const i=e(t);return o(i).derivePath("44'/9000'/0'").neutered().toBase58()}export{t as getXpubFromMnemonic};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e,utils as s}from"@avalabs/avalanchejs";const t=s=>e.isCreateChainTx(s)||e.isAddSubnetValidatorTx(s)||e.isRemoveSubnetValidatorTx(s)||e.isTransformSubnetTx(s)||e.isTransferSubnetOwnershipTx(s),a=async({tx:e,provider:t,addressMaps:a})=>{const n=e.getSubnetAuth().values(),r=(await t.getApiP().getTx({txID:e.getSubnetID().value()})).unsignedTx.getSubnetOwners().addrs.reduce(((e,s,t)=>(n.includes(t)&&e.push([s,t]),e)),[]);return a.push(new s.AddressMap(r)),a};export{a as handleSubnetAuth,t as isSubnetTx};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify the given address is a valid Avalanche bech32 address
|
|
3
|
+
* @param address The address to test
|
|
4
|
+
* @param hasChainId if true requires chain alias prefix (X-, P-, C-), if false address must not have a prefix
|
|
5
|
+
*/
|
|
6
|
+
declare function isBech32Address(address: string, hasChainId?: boolean): boolean;
|
|
7
|
+
|
|
8
|
+
export { isBech32Address };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{utils as r}from"@avalabs/avalanchejs";function e(e,a=!0){try{if(a){const[a]=r.parse(e);if(!["X","P","C"].includes(a))return!1}else r.parseBech32(e);return!0}catch(r){return!1}}export{e as isBech32Address};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Common } from '@avalabs/avalanchejs';
|
|
2
|
+
import { Tx } from '../models.js';
|
|
3
|
+
import { JsonRpcProvider } from '../providers/JsonRpcProvider.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns human readable data from a given a transaction buffer,
|
|
7
|
+
*/
|
|
8
|
+
declare function parseAvalancheTx(unsignedTx: Common.UnsignedTx, provider: JsonRpcProvider, currentAddress: string): Promise<Tx>;
|
|
9
|
+
|
|
10
|
+
export { parseAvalancheTx };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{evmSerial as t,utils as e}from"@avalabs/avalanchejs";import{TxType as n}from"../models.js";import a from"./parsers/index.js";const{getBurnedAmountByTx:r,getOutputAmounts:o,getInputAmounts:s,validateBurnedAmount:u}=e;async function i(e,i,x){try{const n=i.getContext(),d=e.getTx(),m=(t=>{for(const e of Object.values(a)){const n=e(t);if(null!==n)return n}throw new Error("no parser found for tx")})(d),A=r(d),g=o(d),p=s(d).get(n.avaxAssetID)??BigInt(0),v=A.get(n.avaxAssetID)??BigInt(0),c=g.get(n.avaxAssetID)??BigInt(0),{isValid:l,txFee:I}=u({unsignedTx:e,context:n,burnedAmount:v,...t.isImportExportTx(d)&&{evmBaseFee:await i.getApiC().getBaseFee()/BigInt(1e9),evmFeeTolerance:50}});return await m({feeData:{totalAvaxBurned:v,totalAvaxOutput:c,totalAvaxInput:p,isValidAvaxBurnedAmount:l,txFee:I},assetId:n.avaxAssetID,provider:i,currentAddress:x})}catch(t){return{type:n.Unknown}}}export{i as parseAvalancheTx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import r from"./parseAddValidatorTx.js";import e from"./parseAddDelegatorTx.js";import s from"./parseCreateSubnetTx.js";import a from"./parseCreateChainTx.js";import o from"./parseAddSubnetValidorTx.js";import p from"./parseImportTx.js";import t from"./parseExportTx.js";import m from"./parseBaseTx.js";import i from"./parseAddPermissionlessValidatorTx.js";import T from"./parseAddPermissionlessDelegatorTx.js";import d from"./parseRemoveSubnetValidatorTx.js";import x from"./parseTransformSubnetTx.js";import n from"./parseTransferSubnetOwnershipTx.js";var f={parseAddValidatorTx:r,parseAddDelegatorTx:e,parseCreateSubnetTx:s,parseCreateChainTx:a,parseAddSubnetValidatorTx:o,parseRemoveSubnetValidatorTx:d,parseImportTx:p,parseExportTx:t,parseBaseTx:m,parseAddPermissionlessValidatorTx:i,parseAddPermissionlessDelegatorTx:T,parseTransformSubnetTx:x,parseTransferSubnetOwnershipTx:n};export{f as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as a}from"../../models.js";import{getTransferableOutputAmount as t}from"./utils/getTransferableAmount.js";const r=r=>e.isAddDelegatorTx(r)?({feeData:e,assetId:s})=>({type:a.AddDelegator,chain:r.getVM(),stake:t(r.stake,s),stakeOuts:r.stake,rewardOwner:r.getRewardsOwner(),nodeID:r.validator.nodeId.value(),start:r.validator.startTime.value().toString(),end:r.validator.endTime.value().toString(),...e}):null;export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as a}from"../../models.js";const t=t=>e.isAddPermissionlessDelegatorTx(t)?({feeData:e,assetId:s})=>({type:a.AddPermissionlessDelegator,chain:t.getVM(),stake:t.subnetValidator.validator.weight.value(),nodeID:t.subnetValidator.validator.nodeId.value(),start:t.subnetValidator.validator.startTime.value().toString(),end:t.subnetValidator.validator.endTime.value().toString(),subnetID:t.subnetValidator.subnetId.value(),stakeOuts:t.stake,delegatorRewardsOwner:t.getDelegatorRewardsOwner(),...e}):null;export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e,utils as a}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const r=r=>{if(!e.isAddPermissionlessValidatorTx(r))return null;let s,i;return e.isSigner(r.signer)&&(i=a.bufferToHex(r.signer.proof.publicKey),s=a.bufferToHex(r.signer.proof.signature)),({feeData:e,assetId:a})=>({type:t.AddPermissionlessValidator,chain:r.getVM(),stake:r.subnetValidator.validator.weight.value(),nodeID:r.subnetValidator.validator.nodeId.value(),start:r.subnetValidator.validator.startTime.value().toString(),end:r.subnetValidator.validator.endTime.value().toString(),subnetID:r.subnetValidator.subnetId.value(),delegationFee:r.shares.value(),stakeOuts:r.stake,rewardOwner:r.getValidatorRewardsOwner(),delegationRewardOwner:r.getDelegatorRewardsOwner(),signer:r.signer,publicKey:i,signature:s,...e})};export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const e=e=>a.isAddSubnetValidatorTx(e)?({feeData:a})=>({type:t.AddSubnetValidator,chain:e.getVM(),stake:e.subnetValidator.validator.weight.value(),nodeID:e.subnetValidator.validator.nodeId.value(),start:e.subnetValidator.validator.startTime.value().toString(),end:e.subnetValidator.validator.endTime.value().toString(),subnetID:e.getSubnetID().value(),...a}):null;export{e as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";import{getTransferableOutputAmount as t}from"./utils/getTransferableAmount.js";const r=r=>a.isAddValidatorTx(r)?({feeData:a,assetId:s})=>({type:e.AddValidator,chain:r.getVM(),nodeID:r.validator.nodeId.value(),delegationFee:r.shares.value(),stake:t(r.stake,s),stakeOuts:r.stake,start:r.validator.startTime.value().toString(),end:r.validator.endTime.value().toString(),rewardOwner:r.getRewardsOwner(),...a}):null;export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{avmSerial as t,pvmSerial as e,TransferOutput as s}from"@avalabs/avalanchejs";import o from"xss";import{TxType as u}from"../../models.js";import{getUnixNow as a}from"../getUnixNow.js";const r=r=>t.isAvmBaseTx(r)||e.isPvmBaseTx(r)?async({feeData:e,currentAddress:n,provider:i})=>{const p=r.baseTx,m=await(async(e,o)=>{const u=e.baseTx,a=new Set;if(u.outputs.forEach((t=>{a.add(t.assetId.value())})),t.isAvmBaseTx(e)){const t=await Promise.all([...a.values()].map((t=>o.getApiX().getAssetDescription(t))));return u.outputs.reduce(((e,u)=>{if(u.output instanceof s){const s=u.assetId.value(),r=[...a.values()].indexOf(s),n=t[r],i=u.output.outputOwners.addrs.map((t=>`X-${t.toString(o.getContext().hrp)}`));return[...e,{assetId:s,amount:u.output.amount(),locktime:u.output.getLocktime(),threshold:BigInt(u.output.getThreshold()),assetDescription:n,owners:i,isAvax:o.getContext().avaxAssetID===s}]}return e}),[])}return u.outputs.reduce(((t,e)=>{if(e.output instanceof s){const s=e.assetId.value(),u=e.output.outputOwners.addrs.map((t=>`P-${t.toString(o.getContext().hrp)}`));return[...t,{assetId:s,amount:e.output.amount(),locktime:e.output.getLocktime(),threshold:BigInt(e.output.getThreshold()),owners:u,isAvax:o.getContext().avaxAssetID===s}]}return t}),[])})(r,i),c=a(),d=m.filter((t=>!(1===t.owners.length&&t.owners[0]===n&&t.locktime<=c)));return{type:u.Base,chain:r.getVM(),outputs:d,memo:o(Buffer.from(p.memo.toBytes()).toString("utf-8",4)),...e}}:null;export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";const t=t=>a.isCreateChainTx(t)?({feeData:a})=>({type:e.CreateChain,chain:t.getVM(),subnetID:t.getSubnetID().value(),chainName:t.chainName.value(),chainID:t.getBlockchainId(),vmID:t.vmID.value(),fxIDs:t.fxIds.map((a=>a.value())),genesisData:t.genesisData.toString(),...a}):null;export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const r=r=>e.isCreateSubnetTx(r)?({feeData:e,provider:a})=>({type:t.CreateSubnet,chain:r.getVM(),threshold:r.getSubnetOwners().threshold.value(),controlKeys:r.getSubnetOwners().addrs.map((e=>`P-${e.toString(a.getHrp())}`)),...e}):null;export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as t,avmSerial as o,evmSerial as a}from"@avalabs/avalanchejs";import{TxType as s}from"../../models.js";import e from"./utils/chainIdToVm.js";import{getTransferableOutputAmount as i}from"./utils/getTransferableAmount.js";const n=n=>t.isExportTx(n)||o.isExportTx(n)||a.isExportTx(n)?a.isExportTx(n)?({feeData:t,assetId:o})=>({type:s.Export,chain:n.getVM(),destination:e(n.destinationChain.toString()),amount:i(n.exportedOutputs,o),...t}):({feeData:t,assetId:o})=>({type:s.Export,chain:n.getVM(),destination:e(n.destination.value()),amount:i(n.outs,o),...t}):null;export{n as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as t,avmSerial as o,evmSerial as a}from"@avalabs/avalanchejs";import{TxType as s}from"../../models.js";import e from"./utils/chainIdToVm.js";import{getTransferableInputAmount as r}from"./utils/getTransferableAmount.js";const m=m=>t.isImportTx(m)||o.isImportTx(m)||a.isImportTx(m)?a.isImportTx(m)?({feeData:t,assetId:o})=>({type:s.Import,chain:m.getVM(),source:e(m.sourceChain.value()),amount:r(m.importedInputs,o),...t}):({feeData:t,assetId:o})=>({type:s.Import,chain:m.getVM(),source:e(m.sourceChain.value()),amount:r(m.ins,o),...t}):null;export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const a=a=>e.isRemoveSubnetValidatorTx(a)?({feeData:e})=>({type:t.RemoveSubnetValidator,chain:a.getVM(),nodeID:a.nodeId.toString(),subnetID:a.getSubnetID().value(),...e}):null;export{a as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const r=r=>e.isTransferSubnetOwnershipTx(r)?({feeData:e,provider:s})=>({type:t.TransferSubnetOwnership,chain:r.getVM(),subnetID:r.subnetID.value(),threshold:r.getSubnetOwners().threshold.value(),controlKeys:r.getSubnetOwners().addrs.map((e=>`P-${e.toString(s.getHrp())}`)),...e}):null;export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";const t=t=>a.isTransformSubnetTx(t)?({feeData:a})=>({type:e.TransformSubnet,chain:t.getVM(),subnetID:t.subnetID.toString(),assetID:t.assetId.toString(),initialSupply:t.initialSupply.value(),maximumSupply:t.maximumSupply.value(),minConsumptionRate:t.minConsumptionRate.value(),maxConsumptionRate:t.maxConsumptionRate.value(),minValidatorStake:t.minValidatorStake.value(),maxValidatorStake:t.maxValidatorStake.value(),minStakeDuration:t.minStakeDuration.value(),maxStakeDuration:t.maxStakeDuration.value(),minDelegationFee:t.minDelegationFee.value(),minDelegatorStake:t.minDelegatorStake.value(),maxValidatorWeightFactor:Number(t.maxValidatorWeightFactor.toJSON()),uptimeRequirement:t.uptimeRequirement.value(),...a}):null;export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"@avalabs/avalanchejs";import"@avalabs/core-utils-sdk";import"ethers";import{MainnetContext as a,FujiContext as i}from"../../../providers/constants.js";import"@avalabs/chains-sdk";const c=c=>{if([a.xBlockchainID,i.xBlockchainID].includes(c))return"AVM";if([a.pBlockchainID,i.pBlockchainID].includes(c))return"PVM";if([a.cBlockchainID,i.cBlockchainID].includes(c))return"EVM";throw new Error("Unknown chain id. Failed to get alias.")};export{c as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=(t,n)=>t.reduce(((t,e)=>e.assetId.toString()!==n?t:t+e.output.amount()),BigInt(0)),n=(t,n)=>t.reduce(((t,e)=>e.assetId.toString()!==n?t:t+e.input.amount()),BigInt(0));export{n as getTransferableInputAmount,t as getTransferableOutputAmount};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Signature, UnsignedTx } from '@avalabs/avalanchejs';
|
|
2
|
+
|
|
3
|
+
declare const emptySignature: Signature;
|
|
4
|
+
declare const populateCredential: (indices: number[], existingCredentialData?: {
|
|
5
|
+
unsignedTx: UnsignedTx;
|
|
6
|
+
credentialIndex: number;
|
|
7
|
+
}) => Signature[];
|
|
8
|
+
|
|
9
|
+
export { emptySignature, populateCredential };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Signature as e,utils as r,secp256k1 as t}from"@avalabs/avalanchejs";import{sha256 as o}from"@noble/hashes/sha256";const{bufferToHex:n,packTx:s}=r,{publicKeyBytesToAddress:i,recoverPublicKey:a}=t,c=new e(new Uint8Array(Array(65).fill(0))),d=(e,r)=>{const t=Math.max(...e);if(!isFinite(t))throw new Error("Error while adding placeholder signatures for the provided indices.");const d=new Array(t+1).fill(c);if(!r)return d;const{unsignedTx:f,credentialIndex:l}=r,g=f.getCredentials()[l];if(!g)return d;const h=s(f.getTx()),u=o(h),p=c.toString();for(const e of g.toJSON()){if(e.toString()===p)continue;const r=a(u,e.toBytes()),t={toHex:()=>n(i(r))},o=f.addressMaps.getSigIndicesForAddress(t,!1)??[];for(const r of o)r[0]===l&&(d[r[1]]=e)}return d};export{c as emptySignature,d as populateCredential};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{utils as a}from"@avalabs/avalanchejs";function e(e){return a.bufferToHex(a.addChecksum(e.toBytes()))}export{e as signedTxToHex};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The UTXOs will be sorted in the following order.
|
|
5
|
+
* 1- LockedStakeable UTXOs with the highest locktime to lowest
|
|
6
|
+
* 2- Highest value UTXOs to lowest
|
|
7
|
+
* @remark Does not check for locked UTXOs
|
|
8
|
+
*/
|
|
9
|
+
declare function sortUTXOsStaking(utxos: Utxo[]): Utxo[];
|
|
10
|
+
declare function sortUTXOsByAmount(utxos: Utxo[], isDescending: boolean): Utxo[];
|
|
11
|
+
declare const sortUTXOsByAmountDescending: (utxos: Utxo[]) => Utxo[];
|
|
12
|
+
declare const sortUTXOsByAmountAscending: (utxos: Utxo[]) => Utxo[];
|
|
13
|
+
|
|
14
|
+
export { sortUTXOsByAmount, sortUTXOsByAmountAscending, sortUTXOsByAmountDescending, sortUTXOsStaking };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{utils as t}from"@avalabs/avalanchejs";const{isStakeableLockOut:n,isTransferOut:u}=t;function e(t){return t.sort(((t,e)=>{const r=t.output,o=e.output,a=n(r),i=n(o);if(a&&!i)return-1;if(i&&!a)return 1;if(n(r)&&n(o)){const t=r.getStakeableLocktime(),n=o.getStakeableLocktime();if(t<n)return 1;if(t>n)return-1}else if(u(r)&&u(o)){if(r.amount()>o.amount())return-1;if(r.amount()<o.amount())return 1}return 0}))}function r(t,e){return t.sort(((t,r)=>{const o=t.output,a=r.output;let i=BigInt(0);(u(o)||n(o))&&(i=o.amount());let s=BigInt(0);(u(a)||n(a))&&(s=a.amount());const c=e?s-i:i-s;return c>0?1:c<0?-1:0}))}const o=t=>r(t,!0),a=t=>r(t,!1);export{r as sortUTXOsByAmount,a as sortUTXOsByAmountAscending,o as sortUTXOsByAmountDescending,e as sortUTXOsStaking};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
|
+
import { WalletAbstract } from 'Avalanche/wallets';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The list of transaction types supported by `getMaximumUtxoSet`.
|
|
6
|
+
*/
|
|
7
|
+
declare enum SizeSupportedTx {
|
|
8
|
+
AddValidator = 0,
|
|
9
|
+
AddDelegator = 1,
|
|
10
|
+
ExportP = 2,
|
|
11
|
+
ImportP = 3,
|
|
12
|
+
AddPermissionlessValidator = 4,
|
|
13
|
+
AddPermissionlessDelegator = 5,
|
|
14
|
+
BaseP = 6,
|
|
15
|
+
ConsolidateP = 7
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 64 KB.
|
|
19
|
+
* @see https://github.com/ava-labs/avalanchego/blob/aa481ddce393fbb3ab957e4c8f87d5cd50b5eb4e/vms/platformvm/txs/mempool/mempool.go#L21-L23
|
|
20
|
+
*/
|
|
21
|
+
declare const P_CHAIN_TX_SIZE_LIMIT = 65536;
|
|
22
|
+
/**
|
|
23
|
+
* This method will sort `utxos` depending on the `sizeSupportedTx`'s configured sorting algorithm.
|
|
24
|
+
* It then performs a binary search over the sorted UTXOs to determine the largest prefix of the sorted array
|
|
25
|
+
* which can be consumed while still remaining under the byte size limit
|
|
26
|
+
* @param wallet - an instance of the `WalletAbstract` class, with utilities for creating unsigned transactions
|
|
27
|
+
* @param utxos - list of UTXOs to be consumed by the transaction. **WARNING:** `utxos` will be sorted **IN PLACE** by this function!
|
|
28
|
+
* @param sizeSupportedTx - one of the supported transaction types
|
|
29
|
+
* @param limit - optional - byte size limit, defaults to 64kb.
|
|
30
|
+
* @returns the largest prefix of `utxos` before hitting the size limit. If no such prefix exists, then an empty array.
|
|
31
|
+
*/
|
|
32
|
+
declare function getMaximumUtxoSet(wallet: WalletAbstract, utxos: Utxo[], sizeSupportedTx: SizeSupportedTx, limit?: number): Utxo[];
|
|
33
|
+
|
|
34
|
+
export { P_CHAIN_TX_SIZE_LIMIT, SizeSupportedTx, getMaximumUtxoSet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{utils as e}from"@avalabs/avalanchejs";import{getUtxoInfo as t}from"./getUtxoInfo.js";import{getUnixNow as o}from"./getUnixNow.js";import{binarySearch as r}from"../../utils/binarySearch.js";import{sortUTXOsByAmountDescending as d,sortUTXOsByAmountAscending as n,sortUTXOsStaking as i}from"./sortUTXOs.js";var a=(e=>(e[e.AddValidator=0]="AddValidator",e[e.AddDelegator=1]="AddDelegator",e[e.ExportP=2]="ExportP",e[e.ImportP=3]="ImportP",e[e.AddPermissionlessValidator=4]="AddPermissionlessValidator",e[e.AddPermissionlessDelegator=5]="AddPermissionlessDelegator",e[e.BaseP=6]="BaseP",e[e.ConsolidateP=7]="ConsolidateP",e))(a||{});const s="NodeID-8TArWpFgH3sazEH8qP4gUjtGtFMvjw1aR",c="11111111111111111111111111111111LpoYY",g=(e,o)=>e.reduce(((e,o)=>e+t(o).amount),BigInt(0))-o,u={6:{sortFunction:d,unsignedTxBuilder:(t,o)=>{const r=t.getProvider().getContext();return t.baseTX(new e.UtxoSet(o),"P",t.getCurrentAddress("P"),{[r.avaxAssetID]:g(o,r.baseTxFee)})}},7:{sortFunction:n,unsignedTxBuilder:(t,o)=>{const r=t.getProvider().getContext();return t.consolidateP(new e.UtxoSet(o),g(o,r.baseTxFee))}},4:{sortFunction:i,unsignedTxBuilder:(t,r)=>t.addPermissionlessValidator(new e.UtxoSet(r),s,o(),o()+BigInt(1e3),g(r,t.getProvider().getContext().addPrimaryNetworkValidatorFee),c,5,void 0,void 0,void 0,Buffer.from(e.hexToBuffer("0x8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e15")),Buffer.from(e.hexToBuffer("0x86a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98")))},5:{sortFunction:i,unsignedTxBuilder:(t,r)=>t.addPermissionlessDelegator(new e.UtxoSet(r),s,o(),o()+BigInt(1e3),g(r,t.getProvider().getContext().addPrimaryNetworkDelegatorFee),c)},1:{sortFunction:i,unsignedTxBuilder:(t,r)=>t.addDelegator(new e.UtxoSet(r),s,g(r,t.getProvider().getContext().addPrimaryNetworkDelegatorFee),o(),o()+BigInt(1e3))},0:{sortFunction:i,unsignedTxBuilder:(t,r)=>t.addValidator(new e.UtxoSet(r),s,g(r,t.getProvider().getContext().addPrimaryNetworkValidatorFee),o(),o()+BigInt(1e3),5)},2:{sortFunction:d,unsignedTxBuilder:(t,o)=>t.exportP(g(o,t.getProvider().getContext().baseTxFee),new e.UtxoSet(o),"X")},3:{sortFunction:d,unsignedTxBuilder:(t,o)=>t.importP(new e.UtxoSet(o),"X")}},l=65536;function x(e,o,d,n=65536){const{sortFunction:i,unsignedTxBuilder:a}=u[d],s=i(o),c=r(s,(o=>function(e){const o=e.getInputUtxos().reduce(((e,o)=>e+(8+65*t(o).threshold)),0);return 6+e.toBytes().length+o}(a(e,o))),n);return-1===c?[]:s.slice(0,c+1)}export{l as P_CHAIN_TX_SIZE_LIMIT,a as SizeSupportedTx,x as getMaximumUtxoSet};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"bip32-path";function i(i){return t.validateString(i,!0)&&6===i.split("/").length}export{i as verifyDerivationPath};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { WalletAbstract } from './WalletAbstract.js';
|
|
2
|
+
import { AbstractProvider } from '../providers/AbstractProvider.js';
|
|
3
|
+
import { ChainIDAlias } from '../models.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A keyless wallet that cannot sign transactions.
|
|
7
|
+
* It is used to fetch UTXOs and construct transactions for a list of addresses.
|
|
8
|
+
*/
|
|
9
|
+
declare class AddressWallet extends WalletAbstract {
|
|
10
|
+
protected addressC: string;
|
|
11
|
+
protected addressCoreEth: string;
|
|
12
|
+
protected xpAddresses: string[];
|
|
13
|
+
protected xpChangeAddress: string;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param addressC the EVM address (hex) used by the C chain.
|
|
17
|
+
* @param addressCoreEth the CoreEth address used by the C chain.
|
|
18
|
+
* @param xpAddresses a list of XP addresses. The first in the list is the primary address.
|
|
19
|
+
* @param xpChangeAddress change address to use for X/P chain transactions
|
|
20
|
+
* @param prov
|
|
21
|
+
*/
|
|
22
|
+
constructor(addressC: string, addressCoreEth: string, xpAddresses: string[], xpChangeAddress: string, prov: AbstractProvider);
|
|
23
|
+
/**
|
|
24
|
+
* Set the change address to use with X/P chain transactions
|
|
25
|
+
* @param address
|
|
26
|
+
*/
|
|
27
|
+
setChangeAddress(address: string): void;
|
|
28
|
+
/**
|
|
29
|
+
* Return the EVM address (hex) used by the C chain.
|
|
30
|
+
*/
|
|
31
|
+
getAddressEVM(): string;
|
|
32
|
+
/**
|
|
33
|
+
* Return the addresses used by this wallet for the given chain alias.
|
|
34
|
+
* @param chain X/P/C chain alias
|
|
35
|
+
*/
|
|
36
|
+
getAddresses(chain: ChainIDAlias): string[];
|
|
37
|
+
getChangeAddress(chain: ChainIDAlias): string;
|
|
38
|
+
/**
|
|
39
|
+
* For X and P, returns the 1st address in the XP Addresses array. For C, returns the CoreEth address.
|
|
40
|
+
* @param chain Which chain to get the address for
|
|
41
|
+
*/
|
|
42
|
+
getCurrentAddress(chain: ChainIDAlias): string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export { AddressWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{WalletAbstract as s}from"./WalletAbstract.js";import"@avalabs/avalanchejs";import"../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import{isAddress as e}from"ethers";import"../providers/constants.js";import"@avalabs/chains-sdk";import"create-hash";import"bip32";import"@avalabs/glacier-sdk";import"bip39";import{isBech32Address as r}from"../utils/isBech32Address.js";import"xss";import"bip32-path";class t extends s{constructor(s,t,a,d,i){if(super(i),this.addressC=s,this.addressCoreEth=t,this.xpAddresses=a,this.xpChangeAddress=d,a.length<1)throw new Error("Must have at least 1 xp address.");if(!e(s))throw new Error("Not a valid C-Chain (EVM) address");if(a.some((s=>!r(s,!1))))throw new Error("Given addresses must be valid avalanche bech32 addresses without the chain alias prefix");if(!r(t,!1))throw new Error("Given CoreEth address must be valid avalanche bech32 addresses without the chain alias prefix");this.setChangeAddress(d)}setChangeAddress(s){if(!r(s,!1))throw new Error("Given address must be valid avalanche bech32 addresses without the chain alias prefix");this.xpChangeAddress=s}getAddressEVM(){return this.addressC}getAddresses(s){return("C"===s?[this.addressCoreEth]:this.xpAddresses).map((e=>this.provider.formatAddress(e,s)))}getChangeAddress(s){const e="C"===s?this.addressCoreEth:this.xpChangeAddress;return this.provider.formatAddress(e,s)}getCurrentAddress(s){const e="C"===s?this.addressCoreEth:this.xpAddresses[0];return this.provider.formatAddress(e,s)}}export{t as AddressWallet};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as _avalabs_avalanchejs from '@avalabs/avalanchejs';
|
|
2
|
+
import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from './models.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A wallet class that can sign X/P and C transactions with the provided mnemonic code.
|
|
6
|
+
* It can:
|
|
7
|
+
* - act like the {@link StaticSigner} by only using the signing key of the active account
|
|
8
|
+
* - sign X/P transactions containing multiple inputs coming from different addresses
|
|
9
|
+
* However, it doesn't support dynamic addresses like {@link MnemonicWallet} does.
|
|
10
|
+
*/
|
|
11
|
+
declare class SimpleSigner implements Signer {
|
|
12
|
+
/**
|
|
13
|
+
* Node for `m/44'/9000'/0'`
|
|
14
|
+
* @private {BIP32Interface}
|
|
15
|
+
*/
|
|
16
|
+
private accountNodeXP;
|
|
17
|
+
/**
|
|
18
|
+
* Node for `m/44'/60'/0'/0/n`
|
|
19
|
+
* @private {BIP32Interface}
|
|
20
|
+
*/
|
|
21
|
+
private signerNodeEVM;
|
|
22
|
+
/**
|
|
23
|
+
* The primary account's index used for signing C transactions and X/P transactions with static addresses
|
|
24
|
+
* @private {number}
|
|
25
|
+
*/
|
|
26
|
+
private activeAccountIndex;
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} mnemonic - mnemonic code as defined in {@link https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki}
|
|
29
|
+
* @param {number} activeAccountIndex - the index of the primary account used for static signing
|
|
30
|
+
*/
|
|
31
|
+
constructor(mnemonic: string, activeAccountIndex: number);
|
|
32
|
+
/**
|
|
33
|
+
* Generate X/P private keys for custom address indices
|
|
34
|
+
* @param {number[]} customIndices - optional list of custom address indices
|
|
35
|
+
* @param {boolean} isChange - optional flag for deriving internal / external addresses from the indices
|
|
36
|
+
* @returns {Buffer[]} list of private key buffers
|
|
37
|
+
*/
|
|
38
|
+
private getAdditionalKeys;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the proper list of signing keys for the given VM
|
|
41
|
+
* @param {VM} vm - the target VM's type
|
|
42
|
+
* @param {number[]} externalIndices - optional list of custom external address indices
|
|
43
|
+
* @param {number[]} internalIndices - optional list of custom internal address indices
|
|
44
|
+
* @returns {Buffer[]} list of private key raw bytes
|
|
45
|
+
*/
|
|
46
|
+
private getSigningKeys;
|
|
47
|
+
signTx(request: SignTxRequest): Promise<_avalabs_avalanchejs.UnsignedTx | _avalabs_avalanchejs.EVMUnsignedTx>;
|
|
48
|
+
signTxBuffer(request: SignTxBufferRequest): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the X/P/C Chain bip32 node for the active signer.
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
private getActiveAccountNode;
|
|
54
|
+
/**
|
|
55
|
+
* Signs the given message with the active X/P Chain account.
|
|
56
|
+
* Used for signing primary network messages.
|
|
57
|
+
* @param request
|
|
58
|
+
*/
|
|
59
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export { SimpleSigner };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as n}from"bip39";import"@ledgerhq/hw-app-eth";import"ethers";import{getAddressDerivationPath as s}from"../../utils/getAddressDerivationPath.js";import"hdkey";import"buffer";import{DerivationPath as o}from"../../EVM/constants.js";import"@openzeppelin/contracts/build/contracts/ERC20.json";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"../utils/populateCredential.js";import"../providers/constants.js";import"@avalabs/chains-sdk";import{digestMessage as a}from"../utils/digestMessage.js";import"@avalabs/glacier-sdk";import"xss";import"bip32-path";class c{accountNodeXP;signerNodeEVM;activeAccountIndex;constructor(e,t){if(!r(e))throw new Error("Invalid mnemonic phrase.");if(t<0||t%1!=0)throw new Error("Invalid account index.");const a=n(e),c=i(a);this.accountNodeXP=c.derivePath("m/44'/9000'/0'");const p=c.derivePath(s(t,o.BIP44,"EVM"));this.signerNodeEVM=p,this.activeAccountIndex=t}getAdditionalKeys(e,t){return[...new Set(e??[])].reduce(((e,i)=>{const r=this.accountNodeXP.derivePath(`${t?1:0}/${i}`);if(!r.privateKey)throw new Error("Unable to get private key.");return e.push(r.privateKey),e}),[])}getSigningKeys(e,t,i){if("EVM"===e){if(!this.signerNodeEVM.privateKey)throw new Error("Unable to derive EVM private key.");return[this.signerNodeEVM.privateKey]}const r=this.accountNodeXP.derivePath(`0/${this.activeAccountIndex}`);if(!r.privateKey)throw new Error("Unable to derive X/P private key.");const n=this.getAdditionalKeys(t,!1);if("AVM"===e){const e=this.getAdditionalKeys(i,!0);return[r.privateKey,...n,...e]}if("PVM"===e)return[r.privateKey,...n]}async signTx(t){const{tx:i,externalIndices:r,internalIndices:n}=t,s=i.getVM(),o=this.getSigningKeys(s,r,n);if(!o?.length)throw new Error("Unable to sign transaction: signing keys are missing.");return await e({unsignedTx:i,privateKeys:o}),t.tx}async signTxBuffer(e){throw new Error("Not implemented")}getActiveAccountNode(e){switch(e){case"X":case"P":return this.accountNodeXP.derivePath(`0/${this.activeAccountIndex}`);case"C":return this.signerNodeEVM}}async signMessage(e){const i=this.getActiveAccountNode(e.chain);if(!i.privateKey)throw Error("Unable to sign message, key not found.");const r=a(e.message),n=await t.signHash(r,i.privateKey);return Buffer.from(n)}}export{c as SimpleSigner};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as _avalabs_avalanchejs from '@avalabs/avalanchejs';
|
|
2
|
+
import { WalletVoid } from './WalletVoid.js';
|
|
3
|
+
import { AbstractProvider } from '../providers/AbstractProvider.js';
|
|
4
|
+
import { Signer, SignMessageRequest, SignTxRequest, SignTxBufferRequest } from './models.js';
|
|
5
|
+
import { ChainIDAlias } from '../models.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A signer wallet class that has single key for X/P chains, and another key for C chain. Same key
|
|
9
|
+
* can be used for both.
|
|
10
|
+
* This wallet type does not use dynamic addresses for X and P chains. Only a single address is used.
|
|
11
|
+
*/
|
|
12
|
+
declare class StaticSigner extends WalletVoid implements Signer {
|
|
13
|
+
protected privKeyXP: Buffer;
|
|
14
|
+
protected privKeyC: Buffer;
|
|
15
|
+
constructor(privKeyXP: Buffer, privKeyC: Buffer, prov: AbstractProvider);
|
|
16
|
+
/**
|
|
17
|
+
* Create a wallet instance using a mnemonic.
|
|
18
|
+
* @param mnemonic A valid mnemonic string
|
|
19
|
+
* @param pathXP BIP44 derivation path for the X/P chain address
|
|
20
|
+
* @param pathC BIP44 derivation path for the C chain address
|
|
21
|
+
* @param provider
|
|
22
|
+
*/
|
|
23
|
+
static fromMnemonic(mnemonic: string, pathXP: string, pathC: string, provider: AbstractProvider): StaticSigner;
|
|
24
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
25
|
+
/**
|
|
26
|
+
* Return the private key for the given chain
|
|
27
|
+
* @param chain
|
|
28
|
+
* @protected
|
|
29
|
+
*/
|
|
30
|
+
protected getSigningKey(chain: ChainIDAlias): Buffer;
|
|
31
|
+
/**
|
|
32
|
+
* Sign Avalanche X/P/C chain transactions in place.
|
|
33
|
+
* @param request
|
|
34
|
+
*/
|
|
35
|
+
signTx(request: SignTxRequest): Promise<_avalabs_avalanchejs.UnsignedTx | _avalabs_avalanchejs.EVMUnsignedTx>;
|
|
36
|
+
signTxBuffer(request: SignTxBufferRequest): Promise<Buffer[]>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { StaticSigner };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{WalletVoid as i}from"./WalletVoid.js";import{addTxSignatures as r,secp256k1 as e,utils as t}from"@avalabs/avalanchejs";import{validateMnemonic as s,mnemonicToSeedSync as a}from"bip39";import{fromSeed as o}from"bip32";import{digestMessage as n}from"../utils/digestMessage.js";import"../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/chains-sdk";import"@avalabs/glacier-sdk";import"xss";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";const{getPublicKey:m,sign:v,signHash:f}=e,{addChecksum:h}=t;class g extends i{privKeyXP;privKeyC;constructor(i,r,e){super(Buffer.from(m(i)),Buffer.from(m(r)),e),this.privKeyXP=i,this.privKeyC=r}static fromMnemonic(i,r,e,t){if(!s(i))throw new Error("Invalid mnemonic phrase.");if(!p(e)||!p(r))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const n=a(i),m=o(n),v=m.derivePath(r),f=m.derivePath(e);if(!v.privateKey||!f.privateKey)throw new Error("Failed to generate private keys.");return new g(v.privateKey,f.privateKey,t)}async signMessage(i){const r=n(i.message),e=this.getSigningKey(i.chain);return Buffer.from(h(await f(r,e)))}getSigningKey(i){return"C"===i?this.privKeyC:this.privKeyXP}async signTx(i){return await r({unsignedTx:i.tx,privateKeys:[this.privKeyC,this.privKeyXP]}),i.tx}async signTxBuffer(i){const r=this.getSigningKey(i.chain);return[Buffer.from(await v(i.buffer,r))]}}export{g as StaticSigner};
|