@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,131 @@
|
|
|
1
|
+
import * as _avalabs_avalanchejs from '@avalabs/avalanchejs';
|
|
2
|
+
import { utils, pvm, Common } from '@avalabs/avalanchejs';
|
|
3
|
+
import { AbstractProvider } from '../providers/AbstractProvider.js';
|
|
4
|
+
import { ChainIDAlias } from '../models.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* An abstract class that that is shared by all wallet classes.
|
|
8
|
+
*/
|
|
9
|
+
declare abstract class WalletAbstract {
|
|
10
|
+
protected provider: AbstractProvider;
|
|
11
|
+
/**
|
|
12
|
+
* Returns all addresses used by this wallet for the given chain.
|
|
13
|
+
* @param chain
|
|
14
|
+
*/
|
|
15
|
+
abstract getAddresses(chain: ChainIDAlias): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Returns the C chain EVM address (hex).
|
|
18
|
+
*/
|
|
19
|
+
abstract getAddressEVM(): string;
|
|
20
|
+
/**
|
|
21
|
+
* Get the address used by this wallet to receive funds.
|
|
22
|
+
* @param chain
|
|
23
|
+
*/
|
|
24
|
+
abstract getCurrentAddress(chain: ChainIDAlias): string;
|
|
25
|
+
/**
|
|
26
|
+
* Get the address that will receive the "change" after transactions
|
|
27
|
+
* @param chain
|
|
28
|
+
*/
|
|
29
|
+
abstract getChangeAddress(chain: ChainIDAlias): string;
|
|
30
|
+
/**
|
|
31
|
+
* Set the provider used by this wallet.
|
|
32
|
+
* @param provider
|
|
33
|
+
*/
|
|
34
|
+
setProvider(provider: AbstractProvider): void;
|
|
35
|
+
/**
|
|
36
|
+
* Get the provider used by this wallet.
|
|
37
|
+
*/
|
|
38
|
+
getProvider(): AbstractProvider;
|
|
39
|
+
/**
|
|
40
|
+
* Get UTXOs owned by the wallet's addresses for the given chain
|
|
41
|
+
* @param chain
|
|
42
|
+
*/
|
|
43
|
+
getUTXOs(chain: 'X' | 'P'): Promise<utils.UtxoSet>;
|
|
44
|
+
getStake(): Promise<pvm.GetStakeResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Get atomic UTXOs for the given chain
|
|
47
|
+
* @param chain Which chain are the atomic UTXOs are on
|
|
48
|
+
* @param source What is the source chain of the atomic UTXOs
|
|
49
|
+
*/
|
|
50
|
+
getAtomicUTXOs(chain: ChainIDAlias, source: ChainIDAlias): Promise<utils.UtxoSet>;
|
|
51
|
+
exportX(amount: bigint, utxoSet: utils.UtxoSet, destination: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
52
|
+
importP(utxos: utils.UtxoSet, sourceChain: 'X' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
53
|
+
importX(utxos: utils.UtxoSet, sourceChain: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param utxos
|
|
57
|
+
* @param sourceChain
|
|
58
|
+
* @param baseFee in nAvax (EVM base fee)
|
|
59
|
+
* @param feeAssetId
|
|
60
|
+
* @param toAddress Must be hex EVM address.
|
|
61
|
+
*/
|
|
62
|
+
importC(utxos: utils.UtxoSet, sourceChain: 'P' | 'X', baseFee: bigint, feeAssetId?: string, toAddress?: string): Common.UnsignedTx;
|
|
63
|
+
/**
|
|
64
|
+
*
|
|
65
|
+
* @param amount
|
|
66
|
+
* @param destination
|
|
67
|
+
* @param nonce
|
|
68
|
+
* @param baseFee Given in WEI
|
|
69
|
+
* @param toAddress
|
|
70
|
+
*/
|
|
71
|
+
exportC(amount: bigint, destination: 'X' | 'P', nonce: bigint, baseFee: bigint, toAddress?: string): _avalabs_avalanchejs.EVMUnsignedTx;
|
|
72
|
+
/**
|
|
73
|
+
* Get the nonce of this wallet's C chain address
|
|
74
|
+
*/
|
|
75
|
+
getNonce(): Promise<number>;
|
|
76
|
+
/**
|
|
77
|
+
* Export the given amount of AVAX from the P chain. Export fee is automatically added.
|
|
78
|
+
* @param amount
|
|
79
|
+
* @param utxoSet
|
|
80
|
+
* @param destination
|
|
81
|
+
* @param toAddress
|
|
82
|
+
*/
|
|
83
|
+
exportP(amount: bigint, utxoSet: utils.UtxoSet, destination: 'X' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
84
|
+
addValidator(utxos: utils.UtxoSet, nodeID: string, stakeAmount: bigint, startDate: bigint, endDate: bigint, delegationFee: number, config?: {
|
|
85
|
+
rewardAddress?: string;
|
|
86
|
+
}): Common.UnsignedTx;
|
|
87
|
+
addDelegator(utxos: utils.UtxoSet, nodeID: string, stakeAmount: bigint, startDate: bigint, endDate: bigint, config?: {
|
|
88
|
+
rewardAddress?: string;
|
|
89
|
+
}): Common.UnsignedTx;
|
|
90
|
+
consolidateP(utxoSet: utils.UtxoSet, amount: bigint, toAddress?: string, options?: Common.SpendOptions): Common.UnsignedTx;
|
|
91
|
+
baseTX(utxoSet: utils.UtxoSet, chain: 'X' | 'P', toAddress: string, amountsPerAsset: Record<string, bigint>, options?: Common.SpendOptions, fromAddresses?: string[]): Common.UnsignedTx;
|
|
92
|
+
createBlockchain(utxoSet: utils.UtxoSet, subnetId: string, chainName: string, vmID: string, fxIds: string[], genesisData: Record<string, unknown>, subnetAuth: number[], options?: Common.SpendOptions, fromAddresses?: string[]): Common.UnsignedTx;
|
|
93
|
+
createSubnet(utxoSet: utils.UtxoSet, rewardAddresses: string[], fromAddresses?: string[], options?: Common.SpendOptions, threshold?: number, locktime?: bigint): Common.UnsignedTx;
|
|
94
|
+
addSubnetValidator(utxoSet: utils.UtxoSet, nodeId: string, start: bigint, end: bigint, weight: bigint, subnetId: string, subnetAuth: number[], fromAddresses?: string[], options?: Common.SpendOptions): Common.UnsignedTx;
|
|
95
|
+
/**
|
|
96
|
+
*
|
|
97
|
+
* @param utxoSet The transaction will be constructed from these UTXOs.
|
|
98
|
+
* @param nodeId The validating node id
|
|
99
|
+
* @param start Start date of the validation period in UNIX time
|
|
100
|
+
* @param end End date of the validation period in UNIX time
|
|
101
|
+
* @param weight Stake amount given in nAVAX
|
|
102
|
+
* @param subnetId The subnet id as a hexadecimal string
|
|
103
|
+
* @param shares The fee this validator charges delegators as a percentage, times 10,000. Ex. a value of 300,000 means they take 30% of rewards from delegators.
|
|
104
|
+
* @param fromAddresses Only utxos from these addresses will be used
|
|
105
|
+
* @param rewardAddresses Will use active address if not provided. Given addresses will share the reward UTXO.
|
|
106
|
+
* @param delegatorRewardAddresses Will use active address if not provided. Given addresses will share the delegator fee UTXO.
|
|
107
|
+
* @param publicKey the BLS public key, If the subnet is the primary network. Can be found in the Node on startup.
|
|
108
|
+
* @param signature the BLS signature, If the subnet is the primary network. Can be found in the Node on startup.
|
|
109
|
+
* @param options
|
|
110
|
+
*/
|
|
111
|
+
addPermissionlessValidator(utxoSet: utils.UtxoSet, nodeId: string, start: bigint, end: bigint, weight: bigint, subnetId: string, shares: number, fromAddresses?: string[], rewardAddresses?: string[], delegatorRewardAddresses?: string[], publicKey?: Buffer, signature?: Buffer, options?: Common.SpendOptions): Common.UnsignedTx;
|
|
112
|
+
/**
|
|
113
|
+
*
|
|
114
|
+
* @param utxoSet The transaction will be constructed from these UTXOs.
|
|
115
|
+
* @param nodeId The validating node id
|
|
116
|
+
* @param start Start date of the validation period in UNIX time
|
|
117
|
+
* @param end End date of the validation period in UNIX time
|
|
118
|
+
* @param weight Stake amount given in nAVAX
|
|
119
|
+
* @param subnetId The subnet id as a hexadecimal string
|
|
120
|
+
* @param fromAddresses Only utxos from these addresses will be used
|
|
121
|
+
* @param rewardAddresses Will use active address if not provided. Given addresses will share the reward UTXO.
|
|
122
|
+
* @param options
|
|
123
|
+
*/
|
|
124
|
+
addPermissionlessDelegator(utxoSet: utils.UtxoSet, nodeId: string, start: bigint, end: bigint, weight: bigint, subnetId: string, fromAddresses?: string[], rewardAddresses?: string[], options?: Common.SpendOptions): Common.UnsignedTx;
|
|
125
|
+
removeSubnetValidator(utxoSet: utils.UtxoSet, nodeId: string, subnetId: string, subnetAuth: number[], fromAddresses?: string[], options?: Common.SpendOptions): Common.UnsignedTx;
|
|
126
|
+
transferSubnetOwnershipTx(utxoSet: utils.UtxoSet, subnetId: string, subnetAuth: number[], subnetOwners: string[], fromAddresses?: string[], options?: Common.SpendOptions, threshold?: number, locktime?: bigint): Common.UnsignedTx;
|
|
127
|
+
transformSubnetTx(utxoSet: utils.UtxoSet, subnetId: string, assetId: string, initialSupply: bigint, maximumSupply: bigint, minConsumptionRate: bigint, maxConsumptionRate: bigint, minValidatorStake: bigint, maxValidatorStake: bigint, minStakeDuration: number, maxStakeDuration: number, minDelegationFee: number, minDelegatorStake: number, maxValidatorWeightFactor: number, uptimeRequirement: number, subnetAuth: number[], fromAddresses?: string[], options?: Common.SpendOptions): Common.UnsignedTx;
|
|
128
|
+
protected constructor(provider: AbstractProvider);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { WalletAbstract };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{TransferableOutput as e,avm as t,pvm as s,evm as r,networkIDs as i,utils as d}from"@avalabs/avalanchejs";import"../utils/populateCredential.js";import{strip0x as o}from"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/chains-sdk";import"create-hash";import"bip32";import{getUTXOsForAddresses as n}from"../utils/getAllUTXOs.js";import{getStakeForAddresses as a}from"../utils/getStakeForAddresses.js";import"@avalabs/glacier-sdk";import"bip39";import"xss";import{sortUTXOsByAmount as g,sortUTXOsStaking as h,sortUTXOsByAmountAscending as p}from"../utils/sortUTXOs.js";import"bip32-path";const{parse:c,hexToBuffer:m}=d;class A{constructor(e){this.provider=e}setProvider(e){this.provider=e}getProvider(){return this.provider}async getUTXOs(e){const t=this.provider.getApi(e);return n(this.getAddresses(e),t)}async getStake(){const e=this.provider.getApiP();return a(this.getAddresses("P"),e)}async getAtomicUTXOs(e,t){if(e===t)throw new Error("Chain can not be the same as source chain.");const s=this.provider.getApi(e),r=this.provider.getChainID(t);return n(this.getAddresses(e),s,{sourceChain:r,addresses:[]})}exportX(s,r,i,d){d=d||this.getCurrentAddress(i);const o=c(d)[2],n=this.provider.getAvaxID(),a=e.fromNative(n,s,[o]),h=g(r.getUTXOs(),!0),p=this.provider.getChainID(i),m=this.getAddresses("X").map((e=>c(e)[2])),A=c(this.getChangeAddress("X"))[2];return t.newExportTx(this.provider.getContext(),p,m,h,[a],{threshold:1,changeAddresses:[A]})}importP(e,t,r){const i=this.provider.getChainID(t),d=this.getAddresses("P").map((e=>c(e)[2])),o=c(this.getChangeAddress("P"))[2];r=r||this.getCurrentAddress("P");const n=c(r)[2];return s.newImportTx(this.provider.getContext(),i,e.getUTXOs(),[n],d,{changeAddresses:[o]})}importX(e,s,r){const i=this.provider.getChainID(s),d=this.getAddresses("X").map((e=>c(e)[2])),o=c(this.getChangeAddress("X"))[2];r=r||this.getCurrentAddress("X");const n=c(r)[2];return t.newImportTx(this.provider.getContext(),i,e.getUTXOs(),[n],d,{changeAddresses:[o]})}importC(e,t,s,i,d){const n=this.provider.getChainID(t),a=this.getAddresses("C").map((e=>c(e)[2]));d=d||this.getAddressEVM();const g=Buffer.from(o(d),"hex");return r.newImportTxFromBaseFee(this.provider.getContext(),g,a,e.getUTXOs(),n,s,i)}exportC(e,t,s,i,d){const o=m(this.getAddressEVM()),n=this.provider.getChainID(t);d=d||this.getCurrentAddress(t);const a=c(d)[2],g=i/BigInt(1e9);return r.newExportTxFromBaseFee(this.provider.getContext(),g,e,n,o,[a],s)}async getNonce(){const e=this.getAddressEVM();return await this.provider.evmRpc.getTransactionCount(e)}exportP(t,r,i,d){d=d||this.getCurrentAddress(i);const o=c(d)[2],n=this.provider.getAvaxID(),a=e.fromNative(n,t,[o]),h=g(r.getUTXOs(),!0),p=this.provider.getChainID(i),m=this.getAddresses("P").map((e=>c(e)[2])),A=c(this.getChangeAddress("P"))[2];return s.newExportTx(this.provider.getContext(),p,m,h,[a],{changeAddresses:[A]})}addValidator(e,t,r,i,d,o,n){const a=h(e.getUTXOs()),g=this.getAddresses("P").map((e=>c(e)[2])),p=n?.rewardAddress||this.getCurrentAddress("P"),m=c(p)[2],A=c(this.getChangeAddress("P"))[2];return s.newAddValidatorTx(this.provider.getContext(),a,g,t,i,d,r,[m],o,{changeAddresses:[A]})}addDelegator(e,t,r,i,d,o){const n=h(e.getUTXOs()),a=this.getAddresses("P").map((e=>c(e)[2])),g=o?.rewardAddress||this.getCurrentAddress("P"),p=c(g)[2],m=c(this.getChangeAddress("P"))[2];return s.newAddDelegatorTx(this.provider.getContext(),n,a,t,i,d,r,[p],{changeAddresses:[m]})}consolidateP(t,r,i,d){const o=p(t.getUTXOs());i=i??this.getCurrentAddress("P");const n=c(i)[2],a=this.provider.getContext(),g=[e.fromNative(a.avaxAssetID,r,[n])],h=this.getAddresses("P").map((e=>c(e)[2]));return s.newBaseTx(this.provider.getContext(),h,o,g,d)}baseTX(r,i,d,o,n,a){const[h,p,m]=c(d);if(h!==i||p!==this.provider.getHrp())throw new Error(`Invalid recipient address "${d}"`);const A=Object.entries(o).map((([t,s])=>e.fromNative(t,s,[m]))),v=g(r.getUTXOs(),!0),u=(a??this.getAddresses(i)).map((e=>c(e)[2]));return"X"===i?t.newBaseTx(this.provider.getContext(),u,v,A,n):s.newBaseTx(this.provider.getContext(),u,v,A,n)}createBlockchain(e,t,r,i,d,o,n,a,h){const p=g(e.getUTXOs(),!0),m=(h??this.getAddresses("P")).map((e=>c(e)[2]));return s.newCreateBlockchainTx(this.provider.getContext(),p,m,t,r,i,d,o,n,a)}createSubnet(e,t,r,i,d,o){const n=g(e.getUTXOs(),!0),a=(r??this.getAddresses("P")).map((e=>c(e)[2])),h=t.map((e=>c(e)[2]));return s.newCreateSubnetTx(this.provider.getContext(),n,a,h,i,d??1,o??BigInt(0))}addSubnetValidator(e,t,r,i,d,o,n,a,h){const p=g(e.getUTXOs(),!0),m=(a??this.getAddresses("P")).map((e=>c(e)[2]));return s.newAddSubnetValidatorTx(this.provider.getContext(),p,m,t,r,i,d,o,n,h)}addPermissionlessValidator(e,t,r,d,o,n,a,g,p,m,A,v,u){const C=h(e.getUTXOs()),x=(g??this.getAddresses("P")).map((e=>c(e)[2])),T=(p??[this.getCurrentAddress("P")]).map((e=>c(e)[2])),l=(m??[this.getCurrentAddress("P")]).map((e=>c(e)[2]));if(!(n!==i.PrimaryNetworkID.toString()||A&&v))throw new Error("Must provide public key and signature for primary subnet.");const P={changeAddresses:[c(this.getChangeAddress("P"))[2]],...u??{}};return s.newAddPermissionlessValidatorTx(this.provider.getContext(),C,x,t,n,r,d,o,T,l,a,P,void 0,void 0,A,v)}addPermissionlessDelegator(e,t,r,i,d,o,n,a,g){const p=h(e.getUTXOs()),m=(n??this.getAddresses("P")).map((e=>c(e)[2])),A=(a??[this.getCurrentAddress("P")]).map((e=>c(e)[2])),v={changeAddresses:[c(this.getChangeAddress("P"))[2]],...g??{}};return s.newAddPermissionlessDelegatorTx(this.provider.getContext(),p,m,t,o,r,i,d,A,v,void 0,void 0)}removeSubnetValidator(e,t,r,i,d,o){const n=g(e.getUTXOs(),!0),a=(d??this.getAddresses("P")).map((e=>c(e)[2]));return s.newRemoveSubnetValidatorTx(this.provider.getContext(),n,a,t,r,i,o)}transferSubnetOwnershipTx(e,t,r,i,d,o,n,a){const h=g(e.getUTXOs(),!0),p=(d??this.getAddresses("P")).map((e=>c(e)[2])),m=i.map((e=>c(e)[2]));return s.newTransferSubnetOwnershipTx(this.provider.getContext(),h,p,t,r,m,o,n??1,a??BigInt(0))}transformSubnetTx(e,t,r,i,d,o,n,a,h,p,m,A,v,u,C,x,T,l){const P=g(e.getUTXOs(),!0),w=(T??this.getAddresses("P")).map((e=>c(e)[2]));return s.newTransformSubnetTx(this.provider.getContext(),P,w,t,r,i,d,o,n,a,h,p,m,A,v,u,C,x,l)}}export{A as WalletAbstract};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { WalletAbstract } from './WalletAbstract.js';
|
|
2
|
+
import { AbstractProvider } from '../providers/AbstractProvider.js';
|
|
3
|
+
import { ChainIDAlias } from '../models.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A wallet class that has the same static address for X/P/C chains.
|
|
7
|
+
*/
|
|
8
|
+
declare class WalletVoid extends WalletAbstract {
|
|
9
|
+
protected pubkeyXP: Buffer;
|
|
10
|
+
protected pubkeyC: Buffer;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @param pubkeyXP Public key of the X/P Chain address
|
|
14
|
+
* @param pubkeyC Public key of the C Chain address
|
|
15
|
+
* @param prov
|
|
16
|
+
*/
|
|
17
|
+
constructor(pubkeyXP: Buffer, pubkeyC: Buffer, prov: AbstractProvider);
|
|
18
|
+
/**
|
|
19
|
+
* Creates a readonly wallet with the given public keys.
|
|
20
|
+
* @param pubkeyXP
|
|
21
|
+
* @param pubkeyC
|
|
22
|
+
* @param prov
|
|
23
|
+
*/
|
|
24
|
+
static fromPublicKey(pubkeyXP: Buffer, pubkeyC: Buffer, prov: AbstractProvider): WalletVoid;
|
|
25
|
+
static fromMnemonic(mnemonic: string, pathXP: string, pathC: string, provider: AbstractProvider): WalletVoid;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the address as a X, P, or C chain Bech32 address
|
|
28
|
+
* @param chainIdAlias X, P, or C
|
|
29
|
+
*/
|
|
30
|
+
getAddress(chainIdAlias: ChainIDAlias): string;
|
|
31
|
+
/**
|
|
32
|
+
* Return the EVM address (hex) used by the C chain.
|
|
33
|
+
*/
|
|
34
|
+
getAddressEVM(): string;
|
|
35
|
+
getAddresses(chain: ChainIDAlias): string[];
|
|
36
|
+
getChangeAddress(chain: ChainIDAlias): string;
|
|
37
|
+
getCurrentAddress(chain: ChainIDAlias): string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { WalletVoid };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{WalletAbstract as e}from"./WalletAbstract.js";import{fromSeed as r}from"bip32";import{validateMnemonic as t,mnemonicToSeedSync as s}from"bip39";import{strip0x as i}from"@avalabs/core-utils-sdk";import"@avalabs/avalanchejs";import"../utils/populateCredential.js";import{SigningKey as o,computeAddress as a}from"ethers";import"../providers/constants.js";import"@avalabs/chains-sdk";import"create-hash";import"@avalabs/glacier-sdk";import"xss";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";class n extends e{constructor(e,r,t){if(super(t),this.pubkeyXP=e,this.pubkeyC=r,33!==r.length||33!==e.length)throw new Error("Public key must be 33 byte compressed public key")}static fromPublicKey(e,r,t){const s=i(o.computePublicKey(e,!0)),a=i(o.computePublicKey(r,!0)),p=Buffer.from(s,"hex"),u=Buffer.from(a,"hex");return new n(p,u,t)}static fromMnemonic(e,i,o,a){if(!t(e))throw new Error("Invalid mnemonic phrase.");if(!p(o)||!p(i))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const u=s(e),d=r(u),m=d.derivePath(o),h=d.derivePath(i);return n.fromPublicKey(h.publicKey,m.publicKey,a)}getAddress(e){const r="C"===e?this.pubkeyC:this.pubkeyXP;return this.provider.getAddress(r,e)}getAddressEVM(){return a(`0x${this.pubkeyC.toString("hex")}`)}getAddresses(e){return[this.getAddress(e)]}getChangeAddress(e){return this.getAddress(e)}getCurrentAddress(e){return this.getAddress(e)}}export{n as WalletVoid};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { WalletVoid } from '../WalletVoid.js';
|
|
2
|
+
import { Signer, SignMessageRequest, SignTxRequest, SignTxBufferRequest } from '../models.js';
|
|
3
|
+
import { AbstractProvider } from '../../providers/AbstractProvider.js';
|
|
4
|
+
import { UnsignedTx } from '@avalabs/avalanchejs';
|
|
5
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
6
|
+
import { ChainIDAlias } from '../../models.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Ledger wallet that uses a single address for X/P chains, and another for C chain. Same address can be used for all.
|
|
10
|
+
*/
|
|
11
|
+
declare class LedgerSigner extends WalletVoid implements Signer {
|
|
12
|
+
private pathXP;
|
|
13
|
+
private pathC;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param pubkey public key of the address account
|
|
17
|
+
* @param prov Avalanche network provider
|
|
18
|
+
* @param path BIP44 derivation path for the given public key
|
|
19
|
+
*/
|
|
20
|
+
constructor(pubkeyXP: Buffer, pathXP: string, pubkeyC: Buffer, pathC: string, prov: AbstractProvider);
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param transport Active transport instance
|
|
24
|
+
* @param pathXP BIP44 path for the X/P chain address
|
|
25
|
+
* @param pathC BIP44 path for the C chain address
|
|
26
|
+
* @param provider
|
|
27
|
+
*/
|
|
28
|
+
static fromTransport(transport: Transport, pathXP: string, pathC: string, provider: AbstractProvider): Promise<LedgerSigner>;
|
|
29
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the full HD path that will be used for signing.
|
|
32
|
+
* @return BIP44 path, ex. m/44'/60'/0'/0/0 for C chain
|
|
33
|
+
*/
|
|
34
|
+
getFullSignerPath(chain: ChainIDAlias): string;
|
|
35
|
+
/**
|
|
36
|
+
* Only returns the last two indices of the full signer path
|
|
37
|
+
* @return ex. 0/0, 0/1
|
|
38
|
+
*/
|
|
39
|
+
getPartialSignerPath(chain: ChainIDAlias): string;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the correct HD path for the given chain.
|
|
42
|
+
* @return ex. m/44'/60'/0'
|
|
43
|
+
*/
|
|
44
|
+
getAccountPath(chain: ChainIDAlias): string;
|
|
45
|
+
signTx(txRequest: SignTxRequest): Promise<UnsignedTx>;
|
|
46
|
+
signTxBuffer(txRequest: SignTxBufferRequest): Promise<Buffer[]>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { LedgerSigner };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{WalletVoid as r}from"../WalletVoid.js";import{isObsidianApp as t}from"./isObsidianApp.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";import i from"bip32-path";import o from"@ledgerhq/hw-app-eth";import{utils as a}from"@avalabs/avalanchejs";import"../../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import{SigningKey as s}from"ethers";import"../../providers/constants.js";import"@avalabs/chains-sdk";import"create-hash";import"bip32";import"@avalabs/glacier-sdk";import"bip39";import"xss";import{verifyDerivationPath as n}from"../../utils/verifyDerivationPath.js";const{strip0x:p}=a;class f extends r{constructor(r,t,e,i,o){const p=a.strip0x(s.computePublicKey(r,!0)),f=a.strip0x(s.computePublicKey(e,!0));if(super(Buffer.from(p,"hex"),Buffer.from(f,"hex"),o),this.pathXP=t,this.pathC=i,!n(t)||!n(i))throw new Error("Invalid path configuration.")}static async fromTransport(r,e,i,a){if(await t(r))throw new Error("Ledger app not supported. Must be version >= 0.6.0");if(!n(e)||!n(i))throw new Error("Invalid path configuration.");const h=new o(r),u=await h.getAddress(i,!1),c=await h.getAddress(e,!1),m=Buffer.from(p(u.publicKey),"hex"),l=Buffer.from(p(c.publicKey),"hex"),g=Buffer.from(p(s.computePublicKey(m,!0)),"hex"),d=Buffer.from(p(s.computePublicKey(l,!0)),"hex");return new f(d,e,g,i,a)}async signMessage(r){throw new Error("not implemented")}getFullSignerPath(r){return"C"===r?this.pathC:this.pathXP}getPartialSignerPath(r){return this.getFullSignerPath(r).split("/").slice(4).join("/")}getAccountPath(r){return this.getFullSignerPath(r).split("/").slice(0,4).join("/")}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const t=r.tx,e=t.getVM(),i=Buffer.from(t.toBytes()),o="EVM"===e?"C":"X";return(await this.signTxBuffer({buffer:i,chain:o,transport:r.transport})).forEach((r=>{t.addSignature(r)})),t}async signTxBuffer(r){if(!r.transport)throw new Error("Ledger transport not provided");const t=i.fromString(this.getAccountPath(r.chain)),o=i.fromString(this.getPartialSignerPath(r.chain));return[...(await e.signTx(r.transport,r.buffer,t,[o],[o])).signatures.values()]}}export{f as LedgerSigner};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { UnsignedTx } from '@avalabs/avalanchejs';
|
|
2
|
+
import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from '../models.js';
|
|
3
|
+
import { JsonRpcProvider } from '../../providers/JsonRpcProvider.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A wallet class that can sign X/P and C transactions.
|
|
7
|
+
* It can:
|
|
8
|
+
* - act like the {@link LedgerSigner} by only using the signing key of the active account
|
|
9
|
+
* - sign X/P transactions containing multiple inputs coming from different addresses with the provided extended public key
|
|
10
|
+
* However, it doesn't support dynamic addresses like {@link LedgerWallet} does.
|
|
11
|
+
*/
|
|
12
|
+
declare class SimpleLedgerSigner implements Signer {
|
|
13
|
+
private activeAccountIndex;
|
|
14
|
+
private provider;
|
|
15
|
+
private accountNode;
|
|
16
|
+
/**
|
|
17
|
+
* @param {number} activeAccountIndex - the index of the primary account used for static signing
|
|
18
|
+
* @param {string} xpubXP - optional extended public key of `m/44'/9000'/0`
|
|
19
|
+
*/
|
|
20
|
+
constructor(activeAccountIndex: number, provider: JsonRpcProvider, xpubXP?: string);
|
|
21
|
+
private reSerializeTx;
|
|
22
|
+
private getChainAlias;
|
|
23
|
+
private getAccountPath;
|
|
24
|
+
private getAddressOfPath;
|
|
25
|
+
private getAddressPathMap;
|
|
26
|
+
private getAddressBipPaths;
|
|
27
|
+
signTx(txRequest: SignTxRequest): Promise<UnsignedTx>;
|
|
28
|
+
signTxBuffer(txRequest: SignTxBufferRequest): Promise<Buffer[]>;
|
|
29
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export { SimpleLedgerSigner };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{EVMUnsignedTx as t,UnsignedTx as r,utils as e}from"@avalabs/avalanchejs";import s from"bip32-path";import{getTxOutputAddresses as i}from"../../utils/getTxOutputAddresses.js";import{ZondaxProvider as n}from"./ZondaxProvider.js";import{fromBase58 as o}from"bip32";import"../../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import"ethers";import"../../providers/constants.js";import"@avalabs/chains-sdk";import{digestMessage as a}from"../../utils/digestMessage.js";import"@avalabs/glacier-sdk";import"bip39";import"xss";const{parse:c}=e;class h{constructor(t,r,e){this.activeAccountIndex=t,this.provider=r,e&&(this.accountNode=o(e))}accountNode;reSerializeTx(e,s){return e instanceof t||"C"===s?t.fromJSON(JSON.stringify(e.toJSON())):r.fromJSON(JSON.stringify(e.toJSON()))}getChainAlias(t){return"EVM"===t.getVM()?"C":"X"}getAccountPath(t){switch(t){case"X":case"P":return"m/44'/9000'/0'";case"C":return"m/44'/60'/0'"}}getAddressOfPath(t,r){if(!this.accountNode)return null;const{publicKey:e}=this.accountNode.derivePath(t),s=this.provider.getAddress(e,r);return Buffer.from(c(s)[2]).toString("hex")}getAddressPathMap(t){const{tx:r,externalIndices:e,internalIndices:s}=t,i=this.getChainAlias(r),n=`0/${this.activeAccountIndex}`,o=new Map;if("C"===i||!this.accountNode)return o;const a=[n,...(e??[]).map((t=>`0/${t}`)),...(s??[]).map((t=>`1/${t}`))];for(const t of a){const r=this.getAddressOfPath(t,i);r&&o.set(r,t)}return o}getAddressBipPaths(t,r){return 0===r.size?[s.fromString(`0/${this.activeAccountIndex}`)]:t.reduce(((t,e)=>{const i=r.get(Buffer.from(e).toString("hex"));return i&&t.push(s.fromString(i)),t}),[])}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=this.getChainAlias(t.tx),e=this.reSerializeTx(t.tx,r),s=Buffer.from(e.toBytes()),n=this.getAddressPathMap(t),o=this.getAddressBipPaths(e.getAddresses(),n),a=this.getAddressBipPaths([...i(e)],n);return(await this.signTxBuffer({buffer:s,chain:r,transport:t.transport,signers:o,change:a})).forEach((t=>{e.addSignature(t)})),e}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");if(!t.signers)throw new Error("Signers not provided");const r=t.change||[],e=s.fromString(this.getAccountPath(t.chain));return[...(await n.signTx(t.transport,t.buffer,e,t.signers,r)).signatures.values()]}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const r=t.signer||s.fromString(`0/${this.activeAccountIndex}`);if(2!=r.toPathArray().length)throw new Error("Given signer path must have a depth of 2. Ex. 0/0, 0/1");const e=a(t.message),i=(await n.signHash(t.transport,e,s.fromString(this.getAccountPath(t.chain)),[r])).signatures.get(r.toString(!0));if(!i)throw new Error("Failed to sign message.");return i}}export{h as SimpleLedgerSigner};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"@avalabs/hw-app-avalanche";const e={type:"zondax",getApp:e=>new t(e),async getVersion(t){const e=this.getApp(t);return(await e.getAppInfo()).appVersion},async getAddress(t,e,n={show:!1,hrp:"avax"}){const a=this.getApp(t);return{publicKey:(await a.getAddressAndPubKey(e.toString(),n.show,n.hrp)).publicKey}},async getXPUB(t,e){const n=this.getApp(t),a=await n.getExtendedPubKey(e,!1);return{pubKey:a.publicKey,chainCode:a.chain_code}},async signHash(t,e,n,a){const s=this.getApp(t),i=a.map((t=>t.toString(!0))),p=await s.signHash(n.toString(),i,e),r=p.signatures||new Map;return{hash:p.hash||Buffer.from(""),signatures:r}},async signTx(t,e,n,a,s){const i=this.getApp(t),p=a.map((t=>t.toString(!0))),r=s?.map((t=>t.toString(!0)))||[],g=await i.sign(n.toString(),p,e,r),o=g.signatures||new Map;return{...g,signatures:o}}};export{e as ZondaxProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const o="0.6.0";export{o as ZONDAX_VERSION};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LedgerProvider } from './models.js';
|
|
2
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get the correct ledger provider given a transport instance.
|
|
6
|
+
* @param t
|
|
7
|
+
*/
|
|
8
|
+
declare function getLedgerProvider(t: Transport): Promise<LedgerProvider>;
|
|
9
|
+
|
|
10
|
+
export { getLedgerProvider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ZondaxProvider as r}from"./ZondaxProvider.js";async function o(o){return r}export{o as getLedgerProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ZondaxProvider as o}from"./ZondaxProvider.js";import{ZONDAX_VERSION as r}from"./constants.js";async function t(t){return!(await o.getVersion(t)>=r)}export{t as isObsidianApp};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Bip32Path } from 'bip32-path';
|
|
2
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
3
|
+
import AppZondax, { ResponseBase } from '@avalabs/hw-app-avalanche';
|
|
4
|
+
|
|
5
|
+
interface LedgerProvider {
|
|
6
|
+
type: LedgerProviderType;
|
|
7
|
+
getApp(t: Transport): AppZondax;
|
|
8
|
+
getAddress(t: Transport, path: Bip32Path, config: {
|
|
9
|
+
show: boolean;
|
|
10
|
+
hrp: string;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
publicKey: Buffer;
|
|
13
|
+
}>;
|
|
14
|
+
getXPUB(t: Transport, path: string): Promise<{
|
|
15
|
+
pubKey: Buffer;
|
|
16
|
+
chainCode: Buffer;
|
|
17
|
+
}>;
|
|
18
|
+
signHash(t: Transport, hash: Buffer, accountPath: Bip32Path, signers: Bip32Path[]): Promise<{
|
|
19
|
+
hash: Buffer;
|
|
20
|
+
signatures: Map<string, Buffer>;
|
|
21
|
+
}>;
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
* @param t Ledger transport instance
|
|
25
|
+
* @param tx
|
|
26
|
+
* @param accountPath eg. m/44'/9000'/0'
|
|
27
|
+
* @param signers eg. [0/0, 1/0]
|
|
28
|
+
* @param changePaths eg. [0/0, 1/0]
|
|
29
|
+
*/
|
|
30
|
+
signTx(t: Transport, tx: Buffer, accountPath: Bip32Path, signers: Bip32Path[], changePaths?: Bip32Path[]): Promise<{
|
|
31
|
+
signatures: Map<string, Buffer>;
|
|
32
|
+
} & Partial<ResponseBase>>;
|
|
33
|
+
getVersion(t: Transport): Promise<string>;
|
|
34
|
+
}
|
|
35
|
+
type LedgerProviderType = 'obsidian' | 'zondax';
|
|
36
|
+
|
|
37
|
+
export { LedgerProvider, LedgerProviderType };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { MnemonicWalletVoid } from './MnemonicWalletVoid.js';
|
|
2
|
+
import { Signer, SignMessageRequest, SignTxRequest, SignTxBufferRequest } from '../models.js';
|
|
3
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
4
|
+
import { AbstractProvider } from '../../providers/AbstractProvider.js';
|
|
5
|
+
import { UnsignedTx } from '@avalabs/avalanchejs';
|
|
6
|
+
import { ChainIDAlias } from '../../models.js';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Ledger wallet class used by the legacy Web Wallet.
|
|
10
|
+
* Uses dynamic addresses for X and P Chains.
|
|
11
|
+
*/
|
|
12
|
+
declare class LedgerWallet extends MnemonicWalletVoid implements Signer {
|
|
13
|
+
/**
|
|
14
|
+
*
|
|
15
|
+
* @param xpub xpub of m/44'/9000'/0'
|
|
16
|
+
* @param evmPubKey of m/44'/60'/0'/0/0
|
|
17
|
+
* @param provider
|
|
18
|
+
*/
|
|
19
|
+
constructor(xpub: string, evmPubKey: Buffer, provider: AbstractProvider);
|
|
20
|
+
private getAdditionalAddressesByIndices;
|
|
21
|
+
/**
|
|
22
|
+
* Create a ledger wallet from an active transport.
|
|
23
|
+
* @param t
|
|
24
|
+
* @param provider
|
|
25
|
+
*/
|
|
26
|
+
static fromTransport(t: Transport, provider: AbstractProvider): Promise<LedgerWallet>;
|
|
27
|
+
static getAccountPath(chain: ChainIDAlias): "m/44'/9000'/0'" | "m/44'/60'/0'";
|
|
28
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
29
|
+
/**
|
|
30
|
+
* Only returns the owned addresses and their derivation path
|
|
31
|
+
* @param addresses An array of address buffers
|
|
32
|
+
* @param additionalExternalAddresses Optional array of external account indices
|
|
33
|
+
* @param additionalInternalAddresses Optional array of internal account indices
|
|
34
|
+
* @return Map of addressHex to derivationPath
|
|
35
|
+
*/
|
|
36
|
+
filterOwnedAddresses(addresses: Buffer[], additionalExternalAddresses?: string[], additionalInternalAddresses?: string[]): Set<string>;
|
|
37
|
+
signTx(txRequest: SignTxRequest): Promise<UnsignedTx>;
|
|
38
|
+
signTxBuffer(txRequest: SignTxBufferRequest): Promise<Buffer[]>;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { LedgerWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MnemonicWalletVoid as r}from"./MnemonicWalletVoid.js";import{getAppEth as t}from"../../../EVM/utils/getAppEth.js";import{SigningKey as e}from"ethers";import{getAddressDerivationPath as s}from"../../../utils/getAddressDerivationPath.js";import{utils as o}from"@avalabs/avalanchejs";import"hdkey";import"buffer";import{DerivationPath as i}from"../../../EVM/constants.js";import"@openzeppelin/contracts/build/contracts/ERC20.json";import{fromPublicKey as n}from"bip32";import"bip39";import"bitcoinjs-lib";import{strip0x as a}from"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import d from"bip32-path";import{isObsidianApp as p}from"../ledger/isObsidianApp.js";import{ZondaxProvider as f}from"../ledger/ZondaxProvider.js";import{getTxOutputAddresses as m}from"../../utils/getTxOutputAddresses.js";const{parse:c}=o;class g extends r{constructor(r,t,e){super(r,t,e)}getAdditionalAddressesByIndices(r,t,e){return"C"===e?[]:r.map((r=>{const s=this.getAddressAtIndex(r,t,e),[,,o]=c(s);return Buffer.from(o).toString("hex")}))}static async fromTransport(r,o){if(await p(r))throw new Error("Unsupported ledger app version. Must be >= 0.6.0");const d=t(r),m=await f.getXPUB(r,g.getAccountPath("X")),c=n(m.pubKey,m.chainCode),u=s(0,i.BIP44,"EVM"),h=await d.getAddress(u,!1),l=e.computePublicKey(Buffer.from(h.publicKey,"hex"),!0),w=Buffer.from(a(l),"hex");return new g(c.toBase58(),w,o)}static getAccountPath(r){switch(r){case"P":case"X":return"m/44'/9000'/0'";case"C":return"m/44'/60'/0'"}}async signMessage(r){throw new Error("not implemented")}filterOwnedAddresses(r,t,e){const s=this.getInternalRawAddresses().map((r=>r.toString("hex"))),o=this.getExternalRawAddresses().map((r=>r.toString("hex"))),i=new Set([...s,...e??[]]),n=new Set([...o,...t??[]]),a=new Set;return r.forEach((r=>{const t=r.toString("hex");if(i.has(t)){const r=[...i].indexOf(t);a.add(`1/${r}`)}else if(n.has(t)){const r=[...n].indexOf(t);a.add(`0/${r}`)}})),a}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const{tx:t,externalIndices:e,internalIndices:s}=r,o=t.getVM(),i=Buffer.from(t.toBytes()),n="EVM"===o?"C":"X",a=t.getAddresses().map((r=>Buffer.from(r))),p=this.getAdditionalAddressesByIndices(e??[],!1,n),f=this.getAdditionalAddressesByIndices(s??[],!0,n),c=[...this.filterOwnedAddresses(a,p,f).values()].map((r=>d.fromString(r))),g=[...m(t)].map((r=>Buffer.from(r))),u=[...this.filterOwnedAddresses(g).values()].map((r=>d.fromString(r)));return(await this.signTxBuffer({buffer:i,chain:n,transport:r.transport,signers:c,change:u})).forEach((r=>{t.addSignature(r)})),t}async signTxBuffer(r){if(!r.transport)throw new Error("Ledger transport not provided");if(!r.signers)throw new Error("Signers not provided");const t=r.change||[],e=d.fromString(g.getAccountPath(r.chain));return[...(await f.signTx(r.transport,r.buffer,e,r.signers,t)).signatures.values()]}}export{g as LedgerWallet};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MnemonicWalletVoid } from './MnemonicWalletVoid.js';
|
|
2
|
+
import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from '../models.js';
|
|
3
|
+
import { AbstractProvider } from '../../providers/AbstractProvider.js';
|
|
4
|
+
import { UnsignedTx } from '@avalabs/avalanchejs';
|
|
5
|
+
import { BIP32Interface } from 'bip32';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A signer interface for mnemonic wallets that mimics the Legacy Web Wallet. This wallet has
|
|
9
|
+
* multiple addresses for X/P chains, its address index can be incremented to give the user a new address after every transaction.
|
|
10
|
+
*/
|
|
11
|
+
declare class MnemonicWallet extends MnemonicWalletVoid implements Signer {
|
|
12
|
+
private evmPrivKey;
|
|
13
|
+
protected accountNode: BIP32Interface;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param avaxXPriv Bip32 node for m/44'/9000'/0'
|
|
17
|
+
* @param evmPrivKey of m/44'/60'/0'/0/0
|
|
18
|
+
* @param provider
|
|
19
|
+
*/
|
|
20
|
+
constructor(avaxXPriv: string, evmPrivKey: Buffer, provider: AbstractProvider);
|
|
21
|
+
static fromMnemonic(mnemonic: string, provider: AbstractProvider): MnemonicWallet;
|
|
22
|
+
signTx(request: SignTxRequest): Promise<UnsignedTx>;
|
|
23
|
+
private getExternalPrivateKeys;
|
|
24
|
+
private getInternalPrivateKeys;
|
|
25
|
+
private getSigningKeys;
|
|
26
|
+
signTxBuffer(request: SignTxBufferRequest): Promise<Buffer[]>;
|
|
27
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { MnemonicWallet };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MnemonicWalletVoid as e}from"./MnemonicWalletVoid.js";import{addTxSignatures as t,utils as r}from"@avalabs/avalanchejs";import{validateMnemonic as i,mnemonicToSeedSync as n}from"bip39";import{fromBase58 as o,fromSeed as s}from"bip32";import"@ledgerhq/hw-app-eth";import{SigningKey as a}from"ethers";import{getAddressDerivationPath as p}from"../../../utils/getAddressDerivationPath.js";import"hdkey";import"buffer";import{DerivationPath as c}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";const{strip0x:h}=r;class m extends e{constructor(e,t,r){const i=o(e).neutered(),n=new a(t),s=Buffer.from(h(n.compressedPublicKey),"hex");super(i.toBase58(),s,r),this.evmPrivKey=t,this.accountNode=o(e)}accountNode;static fromMnemonic(e,t){if(!i(e))throw new Error("Invalid mnemonic phrase.");const r=n(e),o=s(r),a=o.derivePath("m/44'/9000'/0'"),h=o.derivePath(p(0,c.BIP44,"EVM"));if(!h.privateKey)throw new Error("Unable to derive EVM private key.");return new m(a.toBase58(),h.privateKey,t)}async signTx(e){const r=this.getSigningKeys(e);return await t({unsignedTx:e.tx,privateKeys:r}),e.tx}getExternalPrivateKeys(e){const t=[];for(let e=0;e<=this.externalIndex;e++){const r=this.accountNode.derivePath(`0/${e}`);if(!r.privateKey)throw new Error("Unable to get private key.");t.push(r.privateKey)}const r=(e??[]).reduce(((e,t)=>{if(t>this.externalIndex){const r=this.accountNode.derivePath(`0/${t}`);if(!r.privateKey)throw new Error("Unable to get private key.");e.push(r.privateKey)}return e}),[]);return[...t,...r]}getInternalPrivateKeys(e){const t=[];for(let e=0;e<=this.internalIndex;e++){const r=this.accountNode.derivePath(`1/${e}`);if(!r.privateKey)throw new Error("Unable to get private key.");t.push(r.privateKey)}const r=(e??[]).reduce(((e,t)=>{if(t>this.internalIndex){const r=this.accountNode.derivePath(`1/${t}`);if(!r.privateKey)throw new Error("Unable to get private key.");e.push(r.privateKey)}return e}),[]);return[...t,...r]}getSigningKeys(e){const{tx:t,externalIndices:r,internalIndices:i}=e,n=t.getVM();return"AVM"===n?[...this.getInternalPrivateKeys(i),...this.getExternalPrivateKeys(r)]:"PVM"===n?this.getExternalPrivateKeys(r):[this.evmPrivKey]}async signTxBuffer(e){throw new Error("not implemented")}async signMessage(e){throw new Error("not implemented")}}export{m as MnemonicWallet};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { BIP32Interface } from 'bip32';
|
|
2
|
+
import { WalletAbstract } from '../WalletAbstract.js';
|
|
3
|
+
import { AbstractProvider } from '../../providers/AbstractProvider.js';
|
|
4
|
+
import { ChainIDAlias } from '../../models.js';
|
|
5
|
+
|
|
6
|
+
interface PubKeyCache {
|
|
7
|
+
[path: string]: Buffer;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* This wallet class uses dynamic address for X/P chains and static for C chain. It replicates the wallet logic used in the Web Wallet.
|
|
11
|
+
*/
|
|
12
|
+
declare class MnemonicWalletVoid extends WalletAbstract {
|
|
13
|
+
protected readonly avmXpub: string;
|
|
14
|
+
/**
|
|
15
|
+
* Node for m/44'/9000'/0'
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
protected accountNode: BIP32Interface;
|
|
19
|
+
/**
|
|
20
|
+
* EVM Wallet instance of m/44'/60'/0'/0/0
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private evmWallet;
|
|
24
|
+
/**
|
|
25
|
+
* Index of the current external address
|
|
26
|
+
*/
|
|
27
|
+
protected externalIndex: number;
|
|
28
|
+
/**
|
|
29
|
+
* Index of the current internal (change) address
|
|
30
|
+
*/
|
|
31
|
+
protected internalIndex: number;
|
|
32
|
+
/**
|
|
33
|
+
* Derived pubkeys will be stored here.
|
|
34
|
+
* @protected
|
|
35
|
+
*/
|
|
36
|
+
protected pubkeyCache: PubKeyCache;
|
|
37
|
+
/**
|
|
38
|
+
*
|
|
39
|
+
* @param avmXpub XPUB of m/44'/9000'/0'
|
|
40
|
+
* @param evmPubKey Public Key of m/44'/60'/0'/0/0
|
|
41
|
+
* @param provider
|
|
42
|
+
*/
|
|
43
|
+
constructor(avmXpub: string, evmPubKey: Buffer, provider: AbstractProvider);
|
|
44
|
+
static fromMnemonic(mnemonic: string, provider: AbstractProvider): MnemonicWalletVoid;
|
|
45
|
+
/**
|
|
46
|
+
* Set the current external index of this wallet.
|
|
47
|
+
* @param index
|
|
48
|
+
*/
|
|
49
|
+
setExternalIndex(index: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Set the current internal index of this wallet.
|
|
52
|
+
* @param index
|
|
53
|
+
*/
|
|
54
|
+
setInternalIndex(index: number): void;
|
|
55
|
+
/**
|
|
56
|
+
* Returns the public key for the given index. Used for X/P addresses. Results are cached.
|
|
57
|
+
* @param index
|
|
58
|
+
* @param isChange
|
|
59
|
+
* @private
|
|
60
|
+
*/
|
|
61
|
+
private getPubKeyAtIndex;
|
|
62
|
+
getAddressAtIndex(index: number, isChange: boolean | undefined, chain: 'X' | 'P'): string;
|
|
63
|
+
getExternalAddresses(chain: 'X' | 'P'): string[];
|
|
64
|
+
getInternalAddresses(chain: 'X'): string[];
|
|
65
|
+
getAddresses(chain: ChainIDAlias): string[];
|
|
66
|
+
getChangeAddress(chain: ChainIDAlias): string;
|
|
67
|
+
getCurrentAddress(chain: ChainIDAlias): string;
|
|
68
|
+
/**
|
|
69
|
+
* Increment the current index used for internal/external addresses.
|
|
70
|
+
* @param external
|
|
71
|
+
*/
|
|
72
|
+
incrementIndex(external: boolean): void;
|
|
73
|
+
getAddressEVM(): string;
|
|
74
|
+
getActiveIndices(): {
|
|
75
|
+
external: number;
|
|
76
|
+
internal: number;
|
|
77
|
+
};
|
|
78
|
+
getInternalRawAddresses(): Buffer[];
|
|
79
|
+
getExternalRawAddresses(): Buffer[];
|
|
80
|
+
getRawAddressC(): Buffer;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export { MnemonicWalletVoid };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{fromBase58 as e,fromSeed as t}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import{WalletVoid as n}from"../WalletVoid.js";import{WalletAbstract as d}from"../WalletAbstract.js";import"@ledgerhq/hw-app-eth";import"ethers";import{getAddressDerivationPath as i}from"../../../utils/getAddressDerivationPath.js";import{utils as a}from"@avalabs/avalanchejs";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";const{parse:h}=a;class l extends d{constructor(t,r,s){super(s),this.avmXpub=t,this.accountNode=e(t),this.evmWallet=new n(r,r,s)}accountNode;evmWallet;externalIndex=0;internalIndex=0;pubkeyCache={};static fromMnemonic(e,n){if(!r(e))throw new Error("Invalid mnemonic phrase.");const d=s(e),a=t(d),h=a.derivePath("m/44'/9000'/0'").neutered(),m=a.derivePath(i(0,o.BIP44,"EVM")).neutered();return new l(h.toBase58(),m.publicKey,n)}setExternalIndex(e){if(e<0)throw new Error("Index must be >= 0");this.externalIndex=e}setInternalIndex(e){if(e<0)throw new Error("Index must be >= 0");this.internalIndex=e}getPubKeyAtIndex(e,t=!1){if(e<0)throw new Error("Index must be >= 0");const r=`${t?1:0}/${e}`,s=this.pubkeyCache[r];if(s)return s;const{publicKey:n}=this.accountNode.derivePath(r);return this.pubkeyCache[r]=n,n}getAddressAtIndex(e,t=!1,r){const s=this.getPubKeyAtIndex(e,t);return this.provider.getAddress(s,r)}getExternalAddresses(e){const t=[];for(let r=0;r<=this.externalIndex;r++)t.push(this.getAddressAtIndex(r,!1,e));return t}getInternalAddresses(e){const t=[];for(let r=0;r<=this.internalIndex;r++)t.push(this.getAddressAtIndex(r,!0,e));return t}getAddresses(e){return"C"===e?[this.getCurrentAddress("C")]:"P"===e?[...this.getExternalAddresses(e)]:[...this.getInternalAddresses(e),...this.getExternalAddresses(e)]}getChangeAddress(e){return"C"===e?this.evmWallet.getAddress("C"):"P"===e?this.getAddressAtIndex(this.externalIndex,!1,"P"):this.getAddressAtIndex(this.internalIndex,!0,e)}getCurrentAddress(e){return"C"===e?this.evmWallet.getAddress("C"):this.getAddressAtIndex(this.externalIndex,!1,e)}incrementIndex(e){e?this.externalIndex++:this.internalIndex++}getAddressEVM(){return this.evmWallet.getAddressEVM()}getActiveIndices(){return{external:this.externalIndex,internal:this.internalIndex}}getInternalRawAddresses(){return this.getInternalAddresses("X").map((e=>Buffer.from(h(e)[2])))}getExternalRawAddresses(){return this.getExternalAddresses("X").map((e=>Buffer.from(h(e)[2])))}getRawAddressC(){return Buffer.from(h(this.getCurrentAddress("C"))[2])}}export{l as MnemonicWalletVoid};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { UnsignedTx, EVMUnsignedTx } from '@avalabs/avalanchejs';
|
|
2
|
+
import Transport from '@ledgerhq/hw-transport';
|
|
3
|
+
import { ChainIDAlias } from '../models.js';
|
|
4
|
+
import { Bip32Path } from 'bip32-path';
|
|
5
|
+
|
|
6
|
+
interface SignTxRequest {
|
|
7
|
+
tx: UnsignedTx | EVMUnsignedTx;
|
|
8
|
+
transport?: Transport;
|
|
9
|
+
externalIndices?: number[];
|
|
10
|
+
internalIndices?: number[];
|
|
11
|
+
}
|
|
12
|
+
interface SignTxBufferRequest {
|
|
13
|
+
buffer: Buffer;
|
|
14
|
+
chain: ChainIDAlias;
|
|
15
|
+
transport?: Transport;
|
|
16
|
+
signers?: Bip32Path[];
|
|
17
|
+
change?: Bip32Path[];
|
|
18
|
+
}
|
|
19
|
+
interface SignMessageRequest {
|
|
20
|
+
message: string;
|
|
21
|
+
chain: ChainIDAlias;
|
|
22
|
+
transport?: Transport;
|
|
23
|
+
signer?: Bip32Path;
|
|
24
|
+
}
|
|
25
|
+
interface Signer {
|
|
26
|
+
signTx(txRequest: SignTxRequest): Promise<UnsignedTx>;
|
|
27
|
+
signTxBuffer(txRequest: SignTxBufferRequest): Promise<Buffer[]>;
|
|
28
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
29
|
+
}
|
|
30
|
+
interface LedgerGetXpubResponse {
|
|
31
|
+
public_key: Buffer;
|
|
32
|
+
chain_code: Buffer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export { LedgerGetXpubResponse, SignMessageRequest, SignTxBufferRequest, SignTxRequest, Signer };
|