@avalabs/core-wallets-sdk 3.1.0-alpha.7 → 3.1.0-alpha.71
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/dist/index.cjs +1 -0
- package/dist/index.d.ts +438 -172
- package/esm/Avalanche/index.d.ts +5 -4
- package/esm/Avalanche/index.js +1 -1
- package/esm/Avalanche/models.d.ts +47 -6
- package/esm/Avalanche/models.js +1 -1
- package/esm/Avalanche/providers/AbstractProvider.d.ts +4 -9
- package/esm/Avalanche/providers/AbstractProvider.js +1 -1
- package/esm/Avalanche/providers/JsonRpcProvider.d.ts +2 -1
- package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
- package/esm/Avalanche/providers/constants.d.ts +2 -1
- package/esm/Avalanche/providers/constants.js +1 -1
- package/esm/Avalanche/providers/platformFeeConfig.js +1 -0
- package/esm/Avalanche/utils/addSignaturesToAvalancheTx.js +1 -1
- package/esm/Avalanche/utils/appendDisableAuthAddressMaps.js +1 -0
- package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +5 -4
- package/esm/Avalanche/utils/convertGlacierUtxo.js +1 -1
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.d.ts +3 -2
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.js +1 -1
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.d.ts +1 -1
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
- package/esm/Avalanche/utils/getAssetBalance.d.ts +2 -1
- package/esm/Avalanche/utils/getAssetBalance.js +1 -1
- package/esm/Avalanche/utils/getAvalancheDerivationPath.d.ts +3 -0
- package/esm/Avalanche/utils/getAvalancheDerivationPath.js +1 -0
- package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -1
- package/esm/Avalanche/utils/getPchainUnixNow.d.ts +3 -1
- package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
- package/esm/Avalanche/utils/getStakedAssetBalance.d.ts +2 -1
- package/esm/Avalanche/utils/getTxOutputAddresses.js +1 -1
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +4 -2
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -1
- package/esm/Avalanche/utils/getVmByChainAlias.d.ts +1 -1
- package/esm/Avalanche/utils/getXpubFromMnemonic.d.ts +1 -1
- package/esm/Avalanche/utils/getXpubFromMnemonic.js +1 -1
- package/esm/Avalanche/utils/handleSubnetAuth.js +1 -1
- package/esm/Avalanche/utils/orderBy.js +1 -0
- package/esm/Avalanche/utils/parseAvalancheTx.d.ts +12 -1
- package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
- package/esm/Avalanche/utils/parsers/index.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddSubnetValidorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseBaseTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseConvertSubnetToL1Tx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseCreateChainTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseCreateSubnetTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseDisableL1ValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseExportTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseImportTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseIncreaseL1ValidatorBalanceTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseRegisterL1ValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseRemoveSubnetValidatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseSetL1ValidatorWeightTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseTransferSubnetOwnershipTx.js +1 -1
- package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -1
- package/esm/Avalanche/utils/populateCredential.js +1 -1
- package/esm/Avalanche/utils/sortUTXOs.d.ts +6 -4
- package/esm/Avalanche/utils/sortUTXOs.js +1 -1
- package/esm/Avalanche/utils/txSizeLimits.d.ts +10 -3
- package/esm/Avalanche/utils/txSizeLimits.js +1 -1
- package/esm/Avalanche/wallets/AddressWallet.js +1 -1
- package/esm/Avalanche/wallets/SimpleSigner.d.ts +1 -1
- package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
- package/esm/Avalanche/wallets/StaticSigner.js +1 -1
- package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +179 -0
- package/esm/Avalanche/wallets/WalletAbstract.d.ts +17 -22
- package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
- package/esm/Avalanche/wallets/WalletVoid.js +1 -1
- package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.d.ts +16 -0
- package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.js +1 -0
- package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.d.ts +1 -1
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
- package/esm/Avalanche/wallets/ledger/models.d.ts +1 -1
- package/esm/Avalanche/wallets/legacy/LedgerWallet.js +1 -1
- package/esm/Avalanche/wallets/legacy/MnemonicWallet.js +1 -1
- package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.js +1 -1
- package/esm/Avalanche/wallets/models.d.ts +1 -1
- package/esm/BitcoinVM/index.d.ts +5 -0
- package/esm/BitcoinVM/index.js +1 -0
- package/esm/BitcoinVM/models.d.ts +1 -1
- package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +4 -3
- package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -1
- package/esm/BitcoinVM/providers/BitcoinProviderAbstract.d.ts +1 -0
- package/esm/BitcoinVM/utils/getBech32AddressFromXPub.js +1 -1
- package/esm/BitcoinVM/wallets/BitcoinWallet.js +1 -1
- package/esm/BitcoinVM/wallets/BitcoinWalletLedger.js +1 -1
- package/esm/BitcoinVM/wallets/models.d.ts +1 -1
- package/esm/EVM/LedgerSigner.js +1 -1
- package/esm/EVM/utils/blockPolling.js +1 -1
- package/esm/EVM/utils/getEvmDerivationPath.d.ts +5 -0
- package/esm/EVM/utils/getEvmDerivationPath.js +1 -0
- package/esm/EVM/utils/getWalletFromMnemonic.js +1 -1
- package/esm/SolanaVM/utils/compileSolanaTx.d.ts +9 -0
- package/esm/SolanaVM/utils/compileSolanaTx.js +1 -0
- package/esm/SolanaVM/utils/derivationPath.d.ts +3 -0
- package/esm/SolanaVM/utils/derivationPath.js +1 -0
- package/esm/SolanaVM/utils/deserializeSolanaTx.d.ts +6 -0
- package/esm/SolanaVM/utils/deserializeSolanaTx.js +1 -0
- package/esm/SolanaVM/utils/getSolanaPublicKeyFromLedger.d.ts +5 -0
- package/esm/SolanaVM/utils/getSolanaPublicKeyFromLedger.js +1 -0
- package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.d.ts +37 -0
- package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.js +1 -0
- package/esm/SolanaVM/utils/serializeSolanaTx.d.ts +6 -0
- package/esm/SolanaVM/utils/serializeSolanaTx.js +1 -0
- package/esm/SolanaVM/utils/solanaProvider.d.ts +11 -0
- package/esm/SolanaVM/utils/solanaProvider.js +1 -0
- package/esm/SolanaVM/utils/transferSol.d.ts +14 -0
- package/esm/SolanaVM/utils/transferSol.js +1 -0
- package/esm/SolanaVM/utils/transferToken.d.ts +17 -0
- package/esm/SolanaVM/utils/transferToken.js +1 -0
- package/esm/SolanaVM/wallets/SolanaLedgerSigner.d.ts +10 -0
- package/esm/SolanaVM/wallets/SolanaLedgerSigner.js +1 -0
- package/esm/SolanaVM/wallets/SolanaSigner.d.ts +20 -0
- package/esm/SolanaVM/wallets/SolanaSigner.js +1 -0
- package/esm/abis/erc20.abi.js +1 -0
- package/esm/index.d.ts +32 -20
- package/esm/index.js +1 -1
- package/esm/utils/assertFeeStateProvided.js +1 -0
- package/esm/utils/getAddressDerivationPath.d.ts +8 -2
- package/esm/utils/getAddressDerivationPath.js +1 -1
- package/esm/utils/getPubKeyFromTransport.js +1 -1
- package/package.json +31 -13
- package/dist/index.js +0 -1
- package/esm/Avalanche/utils/getUtxoInfo.d.ts +0 -13
- package/esm/Avalanche/utils/getUtxoInfo.js +0 -1
- package/esm/Avalanche/utils/parsers/parseAddDelegatorTx.js +0 -1
- package/esm/Avalanche/utils/parsers/parseAddValidatorTx.js +0 -1
- package/esm/Avalanche/utils/parsers/parseTransformSubnetTx.js +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pvmSerial as t,avmSerial as
|
|
1
|
+
import{pvmSerial as t,avmSerial as a,evmSerial as o}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";import s from"./utils/chainIdToVm.js";import{getTransferableInputAmount as r}from"./utils/getTransferableAmount.js";var m=m=>t.isImportTx(m)||a.isImportTx(m)||o.isImportTx(m)?o.isImportTx(m)?({feeData:t,assetId:a})=>({type:e.Import,chain:m.getVM(),source:s(m.sourceChain.value()),amount:r(m.importedInputs,a),...t}):({feeData:t,assetId:a})=>({type:e.Import,chain:m.getVM(),source:s(m.sourceChain.value()),amount:r(m.ins,a),...t}):null;export{m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";var l=l=>a.isIncreaseL1ValidatorBalanceTx(l)?({feeData:a})=>({type:e.IncreaseL1ValidatorBalance,chain:l.getVM(),balance:l.balance.value(),validationId:l.validationId.toString(),...a}):null;export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";var l=l=>a.isRegisterL1ValidatorTx(l)?({feeData:a})=>({type:e.RegisterL1Validator,chain:l.getVM(),balance:l.balance.value(),...a}):null;export{l as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as a}from"../../models.js";var t=t=>e.isRemoveSubnetValidatorTx(t)?({feeData:e})=>({type:a.RemoveSubnetValidator,chain:t.getVM(),nodeID:t.nodeId.toString(),subnetID:t.getSubnetID().value(),...e}):null;export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";var e=e=>a.isSetL1ValidatorWeightTx(e)?({feeData:a})=>({type:t.SetL1ValidatorWeight,chain:e.getVM(),...a}):null;export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as r}from"../../models.js";var t=t=>e.isTransferSubnetOwnershipTx(t)?({feeData:e,provider:a})=>({type:r.TransferSubnetOwnership,chain:t.getVM(),subnetID:t.subnetID.value(),threshold:t.getSubnetOwners().threshold.value(),controlKeys:t.getSubnetOwners().addrs.map((e=>`P-${e.toString(a.getHrp())}`)),...e}):null;export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"
|
|
1
|
+
import"../../../providers/AbstractProvider.js";import"@avalabs/avalanchejs";import{MainnetContext as c,FujiContext as a,DevnetContext as i}from"../../../providers/constants.js";import"@avalabs/core-chains-sdk";var r=r=>{if([c.xBlockchainID,a.xBlockchainID,i.xBlockchainID].includes(r))return"AVM";if([c.pBlockchainID,a.pBlockchainID,i.pBlockchainID].includes(r))return"PVM";if([c.cBlockchainID,a.cBlockchainID,i.cBlockchainID].includes(r))return"EVM";throw new Error("Unknown chain id. Failed to get alias.")};export{r as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{utils as e,secp256k1 as r,Signature as t}from"@avalabs/avalanchejs";import{sha256 as o}from"@noble/hashes/sha256";const{bufferToHex:n,packTx:s}=e,{publicKeyBytesToAddress:i,recoverPublicKey:a}=r,c=new t(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};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import * as _avalabs_avalanchejs_dist_serializable_common_types from '@avalabs/avalanchejs/dist/serializable/common/types';
|
|
1
2
|
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The UTXOs will be sorted in the following order.
|
|
5
|
-
* 1-
|
|
6
|
-
* 2-
|
|
6
|
+
* 1- Highest value unlocked UTXO (for fees)
|
|
7
|
+
* 2- LockedStakeable UTXOs with the highest locktime to lowest
|
|
8
|
+
* 3- Rest of the unlocked UTXOs highest to lowest
|
|
7
9
|
* @remark Does not check for locked UTXOs
|
|
8
10
|
*/
|
|
9
11
|
declare function sortUTXOsStaking(utxos: Utxo[]): Utxo[];
|
|
10
12
|
declare function sortUTXOsByAmount(utxos: Utxo[], isDescending: boolean): Utxo[];
|
|
11
|
-
declare const sortUTXOsByAmountDescending: (utxos: Utxo[]) => Utxo[];
|
|
12
|
-
declare const sortUTXOsByAmountAscending: (utxos: Utxo[]) => Utxo[];
|
|
13
|
+
declare const sortUTXOsByAmountDescending: (utxos: Utxo[]) => Utxo<_avalabs_avalanchejs_dist_serializable_common_types.Serializable>[];
|
|
14
|
+
declare const sortUTXOsByAmountAscending: (utxos: Utxo[]) => Utxo<_avalabs_avalanchejs_dist_serializable_common_types.Serializable>[];
|
|
13
15
|
|
|
14
16
|
export { sortUTXOsByAmount, sortUTXOsByAmountAscending, sortUTXOsByAmountDescending, sortUTXOsStaking };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{utils as t}from"@avalabs/avalanchejs";
|
|
1
|
+
import{utils as t}from"@avalabs/avalanchejs";import{getUnixNow as o}from"./getUnixNow.js";import{orderBy as e}from"./orderBy.js";function a(a){const m=o(),n=a.map((o=>({utxo:o,...t.getUtxoInfo(o)}))),r=n.filter((t=>t.stakeableLocktime<=m)),s=n.filter((t=>t.stakeableLocktime>m)),c=e(r,["amount"],"desc"),i=e(s,["stakeableLocktime","amount"],"desc"),[u,...f]=c;return[...u?[u]:[],...i,...f].map((t=>t.utxo))}function m(o,a){const m=o.map((o=>({utxo:o,...t.getUtxoInfo(o)})));return e(m,["amount"],a?"desc":"asc").map((t=>t.utxo))}const n=t=>m(t,!0),r=t=>m(t,!1);export{m as sortUTXOsByAmount,r as sortUTXOsByAmountAscending,n as sortUTXOsByAmountDescending,a as sortUTXOsStaking};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
|
-
import { WalletAbstract } from '
|
|
1
|
+
import { Utxo, pvm } from '@avalabs/avalanchejs';
|
|
2
|
+
import { WalletAbstract } from '../wallets/WalletAbstract.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The list of transaction types supported by `getMaximumUtxoSet`.
|
|
@@ -25,8 +25,15 @@ declare const P_CHAIN_TX_SIZE_LIMIT = 65536;
|
|
|
25
25
|
* @param utxos - list of UTXOs to be consumed by the transaction.
|
|
26
26
|
* @param sizeSupportedTx - one of the supported transaction types
|
|
27
27
|
* @param limit - optional - byte size limit, defaults to 64kb.
|
|
28
|
+
* @param feeState - current fee state on the chain
|
|
28
29
|
* @returns the largest prefix of sorted `utxos` before hitting the size limit. If no such prefix exists, then an empty array.
|
|
29
30
|
*/
|
|
30
|
-
declare function getMaximumUtxoSet(wallet
|
|
31
|
+
declare function getMaximumUtxoSet({ wallet, utxos, sizeSupportedTx, limit, feeState, }: {
|
|
32
|
+
wallet: WalletAbstract;
|
|
33
|
+
utxos: Utxo[];
|
|
34
|
+
sizeSupportedTx: SizeSupportedTx;
|
|
35
|
+
limit?: number;
|
|
36
|
+
feeState?: pvm.FeeState;
|
|
37
|
+
}): Utxo[];
|
|
31
38
|
|
|
32
39
|
export { P_CHAIN_TX_SIZE_LIMIT, SizeSupportedTx, getMaximumUtxoSet };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{utils as e}from"@avalabs/avalanchejs";import{
|
|
1
|
+
import{utils as e,Common as t}from"@avalabs/avalanchejs";import{getUnixNow as o}from"./getUnixNow.js";import{binarySearch as s}from"../../utils/binarySearch.js";import{sortUTXOsByAmountDescending as r,sortUTXOsStaking as n,sortUTXOsByAmountAscending as d}from"./sortUTXOs.js";const{getUtxoInfo:i}=e;var a=(e=>(e.ExportP="ExportP",e.ImportP="ImportP",e.AddPermissionlessValidator="AddPermissionlessValidator",e.AddPermissionlessDelegator="AddPermissionlessDelegator",e.BaseP="BaseP",e.ConsolidateP="ConsolidateP",e))(a||{});const u="NodeID-8TArWpFgH3sazEH8qP4gUjtGtFMvjw1aR",c="11111111111111111111111111111111LpoYY",l=(e,t)=>e.reduce(((e,t)=>e+i(t).amount),BigInt(0))-t,x={BaseP:{sortFunction:r,unsignedTxBuilder:(t,o,s)=>{const r=t.getProvider().getContext();return t.baseTX({utxoSet:new e.UtxoSet(o),chain:"P",toAddress:t.getCurrentAddress("P"),amountsPerAsset:{[r.avaxAssetID]:l(o,r.baseTxFee)},feeState:s})}},ConsolidateP:{sortFunction:d,unsignedTxBuilder:(t,o,s)=>{const r=t.getProvider().getContext();return t.consolidateP({utxoSet:new e.UtxoSet(o),amount:l(o,r.baseTxFee),feeState:s})}},AddPermissionlessValidator:{sortFunction:n,unsignedTxBuilder:(t,s,r)=>t.addPermissionlessValidator({utxoSet:new e.UtxoSet(s),nodeId:u,start:o(),end:o()+BigInt(1e3),weight:l(s,t.getProvider().getContext().baseTxFee),subnetId:c,shares:5,feeState:r,fromAddresses:void 0,rewardAddresses:void 0,delegatorRewardAddresses:void 0,publicKey:Buffer.from(e.hexToBuffer("0x8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e15")),signature:Buffer.from(e.hexToBuffer("0x86a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98"))})},AddPermissionlessDelegator:{sortFunction:n,unsignedTxBuilder:(t,s,r)=>t.addPermissionlessDelegator({utxoSet:new e.UtxoSet(s),nodeId:u,start:o(),end:o()+BigInt(1e3),weight:l(s,t.getProvider().getContext().baseTxFee),subnetId:c,feeState:r})},ExportP:{sortFunction:r,unsignedTxBuilder:(o,s,r)=>{const n=o.getProvider().getContext(),d=function({numberIns:e=1},o){const s=t.createDimensions({bandwidth:161*e+254,dbRead:e,dbWrite:2+e,compute:200*e});return t.dimensionsToGas(s,o)}({numberIns:s.length},n.platformFeeConfig.weights),i=r?d*r.price:n.baseTxFee;return o.exportP({amount:l(s,i),utxoSet:new e.UtxoSet(s),destination:"X",feeState:r})}},ImportP:{sortFunction:r,unsignedTxBuilder:(t,o,s)=>t.importP({utxoSet:new e.UtxoSet(o),sourceChain:"X",feeState:s})}},f=65536;function g({wallet:e,utxos:t,sizeSupportedTx:r,limit:n=65536,feeState:d}){const{sortFunction:a,unsignedTxBuilder:u}=x[r],c=o(),l=a(t.filter((e=>{const{locktime:t,stakeableLocktime:o}=i(e);return t<c&&(o<c||("AddPermissionlessDelegator"===r||"AddPermissionlessValidator"===r))}))),f=s(l,(t=>{try{return function(e){const t=e.getInputUtxos().reduce(((e,t)=>e+(8+65*i(t).threshold)),0);return 6+e.toBytes().length+t}(u(e,t,d))}catch(e){return console.log("Unable to estimate size of utxos",{e:e,utxos:t.map(i)}),n+1}}),n);return-1===f?[]:l.slice(0,f+1)}export{f as P_CHAIN_TX_SIZE_LIMIT,a as SizeSupportedTx,g as getMaximumUtxoSet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletAbstract as s}from"./WalletAbstract.js";import"
|
|
1
|
+
import{WalletAbstract as s}from"./WalletAbstract.js";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"create-hash";import"bip32";import"@avalabs/avalanchejs";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"bip39";import{isBech32Address as e}from"../utils/isBech32Address.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import"bip32-path";import{isAddress as r}from"ethers";class t extends s{constructor(s,t,i,a,d){if(super(d),this.addressC=s,this.addressCoreEth=t,this.xpAddresses=i,this.xpChangeAddress=a,i.length<1)throw new Error("Must have at least 1 xp address.");if(!r(s))throw new Error("Not a valid C-Chain (EVM) address");if(i.some((s=>!e(s,!1))))throw new Error("Given addresses must be valid avalanche bech32 addresses without the chain alias prefix");if(!e(t,!1))throw new Error("Given CoreEth address must be valid avalanche bech32 addresses without the chain alias prefix");this.setChangeAddress(a)}setChangeAddress(s){if(!e(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};
|
|
@@ -10,7 +10,7 @@ import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from '
|
|
|
10
10
|
*/
|
|
11
11
|
declare class SimpleSigner implements Signer {
|
|
12
12
|
/**
|
|
13
|
-
* Node for `m/44'/9000'/
|
|
13
|
+
* Node for `m/44'/9000'/n'`
|
|
14
14
|
* @private {BIP32Interface}
|
|
15
15
|
*/
|
|
16
16
|
private accountNodeXP;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as
|
|
1
|
+
import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import"@ledgerhq/hw-app-eth";import"ethers";import{DerivationPath as n}from"../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{getAddressDerivationPath as o}from"../../utils/getAddressDerivationPath.js";import"hdkey";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../utils/digestMessage.js";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";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=s(e),c=i(a);this.accountNodeXP=c.derivePath(`m/44'/9000'/${t}'`);const p=c.derivePath(o(t,"EVM",{pathSpec:n.BIP44}));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/0");if(!r.privateKey)throw new Error("Unable to derive X/P private key.");const s=this.getAdditionalKeys(t,!1);if("AVM"===e){const e=this.getAdditionalKeys(i,!0);return[r.privateKey,...s,...e]}if("PVM"===e)return[r.privateKey,...s]}async signTx(t){const{tx:i,externalIndices:r,internalIndices:s}=t,n=i.getVM(),o=this.getSigningKeys(n,r,s);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/0");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),s=await t.signHash(r,i.privateKey);return Buffer.from(s)}}export{c as SimpleSigner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletVoid as i}from"./WalletVoid.js";import{
|
|
1
|
+
import{WalletVoid as i}from"./WalletVoid.js";import{secp256k1 as e,utils as t,addTxSignatures as r}from"@avalabs/avalanchejs";import{validateMnemonic as s,mnemonicToSeedSync as a}from"bip39";import{fromSeed as n}from"bip32";import{digestMessage as o}from"../utils/digestMessage.js";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";const{getPublicKey:m,sign:l,signHash:u}=e,{addChecksum:v}=t;class c extends i{privKeyXP;privKeyC;constructor(i,e,t){super(Buffer.from(m(i)),Buffer.from(m(e)),t),this.privKeyXP=i,this.privKeyC=e}static fromMnemonic(i,e,t,r){if(!s(i))throw new Error("Invalid mnemonic phrase.");if(!p(t)||!p(e))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const o=a(i),m=n(o),l=m.derivePath(e),u=m.derivePath(t);if(!l.privateKey||!u.privateKey)throw new Error("Failed to generate private keys.");return new c(l.privateKey,u.privateKey,r)}async signMessage(i){const e=o(i.message),t=this.getSigningKey(i.chain);return Buffer.from(v(await u(e,t)))}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 e=this.getSigningKey(i.chain);return[Buffer.from(await l(i.buffer,e))]}}export{c as StaticSigner};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { utils, pvm, Common } from '@avalabs/avalanchejs';
|
|
2
|
+
|
|
3
|
+
type BaseTx = {
|
|
4
|
+
utxoSet: utils.UtxoSet;
|
|
5
|
+
chain: 'X' | 'P';
|
|
6
|
+
toAddress: string;
|
|
7
|
+
amountsPerAsset: Record<string, bigint>;
|
|
8
|
+
feeState?: pvm.FeeState;
|
|
9
|
+
options?: Common.SpendOptions;
|
|
10
|
+
fromAddresses?: string[];
|
|
11
|
+
};
|
|
12
|
+
type ImportP = {
|
|
13
|
+
utxoSet: utils.UtxoSet;
|
|
14
|
+
sourceChain: 'X' | 'C';
|
|
15
|
+
toAddress?: string;
|
|
16
|
+
threshold?: number;
|
|
17
|
+
feeState?: pvm.FeeState;
|
|
18
|
+
locktime?: bigint;
|
|
19
|
+
};
|
|
20
|
+
type ExportP = {
|
|
21
|
+
amount: bigint;
|
|
22
|
+
utxoSet: utils.UtxoSet;
|
|
23
|
+
destination: 'X' | 'C';
|
|
24
|
+
feeState?: pvm.FeeState;
|
|
25
|
+
toAddress?: string;
|
|
26
|
+
};
|
|
27
|
+
type ConsolidateP = {
|
|
28
|
+
utxoSet: utils.UtxoSet;
|
|
29
|
+
amount: bigint;
|
|
30
|
+
feeState?: pvm.FeeState;
|
|
31
|
+
toAddress?: string;
|
|
32
|
+
options?: Common.SpendOptions;
|
|
33
|
+
};
|
|
34
|
+
type CreateSubnet = {
|
|
35
|
+
utxoSet: utils.UtxoSet;
|
|
36
|
+
rewardAddresses: string[];
|
|
37
|
+
feeState?: pvm.FeeState;
|
|
38
|
+
fromAddresses?: string[];
|
|
39
|
+
options?: Common.SpendOptions;
|
|
40
|
+
threshold?: number;
|
|
41
|
+
locktime?: bigint;
|
|
42
|
+
};
|
|
43
|
+
type CreateChain = {
|
|
44
|
+
utxoSet: utils.UtxoSet;
|
|
45
|
+
subnetId: string;
|
|
46
|
+
chainName: string;
|
|
47
|
+
vmID: string;
|
|
48
|
+
fxIds: string[];
|
|
49
|
+
genesisData: Record<string, unknown>;
|
|
50
|
+
subnetAuth: number[];
|
|
51
|
+
feeState?: pvm.FeeState;
|
|
52
|
+
options?: Common.SpendOptions;
|
|
53
|
+
fromAddresses?: string[];
|
|
54
|
+
};
|
|
55
|
+
type ConvertSubnetToL1 = {
|
|
56
|
+
utxoSet: utils.UtxoSet;
|
|
57
|
+
address: string;
|
|
58
|
+
chainId: string;
|
|
59
|
+
subnetId: string;
|
|
60
|
+
subnetAuth: number[];
|
|
61
|
+
options?: Common.SpendOptions;
|
|
62
|
+
feeState: pvm.FeeState;
|
|
63
|
+
fromAddresses?: string[];
|
|
64
|
+
validators: {
|
|
65
|
+
nodeId: string;
|
|
66
|
+
weight: bigint;
|
|
67
|
+
balance: bigint;
|
|
68
|
+
pubKey: string;
|
|
69
|
+
signature: string;
|
|
70
|
+
remainingBalanceOwner: {
|
|
71
|
+
addresses: string[];
|
|
72
|
+
threshold?: number;
|
|
73
|
+
};
|
|
74
|
+
deactivationOwner: {
|
|
75
|
+
addresses: string[];
|
|
76
|
+
threshold?: number;
|
|
77
|
+
};
|
|
78
|
+
}[];
|
|
79
|
+
};
|
|
80
|
+
type RegisterL1Validator = {
|
|
81
|
+
utxoSet: utils.UtxoSet;
|
|
82
|
+
balance: bigint;
|
|
83
|
+
signature: string;
|
|
84
|
+
feeState: pvm.FeeState;
|
|
85
|
+
message: string;
|
|
86
|
+
options?: Common.SpendOptions;
|
|
87
|
+
fromAddresses?: string[];
|
|
88
|
+
};
|
|
89
|
+
type SetL1ValidatorWeight = {
|
|
90
|
+
utxoSet: utils.UtxoSet;
|
|
91
|
+
feeState: pvm.FeeState;
|
|
92
|
+
message: string;
|
|
93
|
+
options?: Common.SpendOptions;
|
|
94
|
+
fromAddresses?: string[];
|
|
95
|
+
};
|
|
96
|
+
type DisableL1Validator = {
|
|
97
|
+
utxoSet: utils.UtxoSet;
|
|
98
|
+
feeState: pvm.FeeState;
|
|
99
|
+
disableAuth: number[];
|
|
100
|
+
validationId: string;
|
|
101
|
+
options?: Common.SpendOptions;
|
|
102
|
+
fromAddresses?: string[];
|
|
103
|
+
};
|
|
104
|
+
type IncreaseL1ValidatorBalance = {
|
|
105
|
+
utxoSet: utils.UtxoSet;
|
|
106
|
+
feeState: pvm.FeeState;
|
|
107
|
+
balance: bigint;
|
|
108
|
+
validationId: string;
|
|
109
|
+
options?: Common.SpendOptions;
|
|
110
|
+
fromAddresses?: string[];
|
|
111
|
+
};
|
|
112
|
+
type AddSubnetValidator = {
|
|
113
|
+
utxoSet: utils.UtxoSet;
|
|
114
|
+
nodeId: string;
|
|
115
|
+
start: bigint;
|
|
116
|
+
end: bigint;
|
|
117
|
+
weight: bigint;
|
|
118
|
+
subnetId: string;
|
|
119
|
+
subnetAuth: number[];
|
|
120
|
+
feeState?: pvm.FeeState;
|
|
121
|
+
fromAddresses?: string[];
|
|
122
|
+
options?: Common.SpendOptions;
|
|
123
|
+
};
|
|
124
|
+
type AddPermissionlessValidator = {
|
|
125
|
+
utxoSet: utils.UtxoSet;
|
|
126
|
+
nodeId: string;
|
|
127
|
+
start: bigint;
|
|
128
|
+
end: bigint;
|
|
129
|
+
weight: bigint;
|
|
130
|
+
subnetId: string;
|
|
131
|
+
shares: number;
|
|
132
|
+
fromAddresses?: string[];
|
|
133
|
+
rewardAddresses?: string[];
|
|
134
|
+
delegatorRewardAddresses?: string[];
|
|
135
|
+
publicKey?: Buffer;
|
|
136
|
+
signature?: Buffer;
|
|
137
|
+
options?: Common.SpendOptions;
|
|
138
|
+
stakingAssetId?: string;
|
|
139
|
+
locktime?: bigint;
|
|
140
|
+
threshold?: number;
|
|
141
|
+
feeState?: pvm.FeeState;
|
|
142
|
+
};
|
|
143
|
+
type AddPermissionlessDelegator = {
|
|
144
|
+
utxoSet: utils.UtxoSet;
|
|
145
|
+
nodeId: string;
|
|
146
|
+
start: bigint;
|
|
147
|
+
end: bigint;
|
|
148
|
+
weight: bigint;
|
|
149
|
+
subnetId: string;
|
|
150
|
+
fromAddresses?: string[];
|
|
151
|
+
rewardAddresses?: string[];
|
|
152
|
+
options?: Common.SpendOptions;
|
|
153
|
+
locktime?: bigint;
|
|
154
|
+
feeState?: pvm.FeeState;
|
|
155
|
+
stakingAssetId?: string;
|
|
156
|
+
threshold?: number;
|
|
157
|
+
};
|
|
158
|
+
type RemoveSubnetValidator = {
|
|
159
|
+
utxoSet: utils.UtxoSet;
|
|
160
|
+
nodeId: string;
|
|
161
|
+
subnetId: string;
|
|
162
|
+
subnetAuth: number[];
|
|
163
|
+
feeState?: pvm.FeeState;
|
|
164
|
+
fromAddresses?: string[];
|
|
165
|
+
options?: Common.SpendOptions;
|
|
166
|
+
};
|
|
167
|
+
type TransferSubnetOwnershipTx = {
|
|
168
|
+
utxoSet: utils.UtxoSet;
|
|
169
|
+
subnetId: string;
|
|
170
|
+
subnetAuth: number[];
|
|
171
|
+
subnetOwners: string[];
|
|
172
|
+
feeState?: pvm.FeeState;
|
|
173
|
+
fromAddresses?: string[];
|
|
174
|
+
options?: Common.SpendOptions;
|
|
175
|
+
threshold?: number;
|
|
176
|
+
locktime?: bigint;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export type { AddPermissionlessDelegator, AddPermissionlessValidator, AddSubnetValidator, BaseTx, ConsolidateP, ConvertSubnetToL1, CreateChain, CreateSubnet, DisableL1Validator, ExportP, ImportP, IncreaseL1ValidatorBalance, RegisterL1Validator, RemoveSubnetValidator, SetL1ValidatorWeight, TransferSubnetOwnershipTx };
|
|
@@ -2,6 +2,7 @@ import * as _avalabs_avalanchejs from '@avalabs/avalanchejs';
|
|
|
2
2
|
import { utils, pvm, Common } from '@avalabs/avalanchejs';
|
|
3
3
|
import { AbstractProvider } from '../providers/AbstractProvider.js';
|
|
4
4
|
import { ChainIDAlias } from '../models.js';
|
|
5
|
+
import { ImportP, ExportP, ConsolidateP, BaseTx, ConvertSubnetToL1, RegisterL1Validator, SetL1ValidatorWeight, DisableL1Validator, IncreaseL1ValidatorBalance, CreateChain, CreateSubnet, AddSubnetValidator, AddPermissionlessValidator, AddPermissionlessDelegator, RemoveSubnetValidator, TransferSubnetOwnershipTx } from './TxBuilderTypes.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* An abstract class that that is shared by all wallet classes.
|
|
@@ -49,7 +50,7 @@ declare abstract class WalletAbstract {
|
|
|
49
50
|
*/
|
|
50
51
|
getAtomicUTXOs(chain: ChainIDAlias, source: ChainIDAlias): Promise<utils.UtxoSet>;
|
|
51
52
|
exportX(amount: bigint, utxoSet: utils.UtxoSet, destination: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
52
|
-
importP(
|
|
53
|
+
importP({ utxoSet, sourceChain, toAddress, threshold, feeState, locktime, }: ImportP): Common.UnsignedTx;
|
|
53
54
|
importX(utxos: utils.UtxoSet, sourceChain: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
54
55
|
/**
|
|
55
56
|
*
|
|
@@ -69,10 +70,6 @@ declare abstract class WalletAbstract {
|
|
|
69
70
|
* @param toAddress
|
|
70
71
|
*/
|
|
71
72
|
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
73
|
/**
|
|
77
74
|
* Export the given amount of AVAX from the P chain. Export fee is automatically added.
|
|
78
75
|
* @param amount
|
|
@@ -80,18 +77,17 @@ declare abstract class WalletAbstract {
|
|
|
80
77
|
* @param destination
|
|
81
78
|
* @param toAddress
|
|
82
79
|
*/
|
|
83
|
-
exportP(amount
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}): Common.UnsignedTx;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}): Common.UnsignedTx;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
addSubnetValidator(utxoSet: utils.UtxoSet, nodeId: string, start: bigint, end: bigint, weight: bigint, subnetId: string, subnetAuth: number[], fromAddresses?: string[], options?: Common.SpendOptions): Common.UnsignedTx;
|
|
80
|
+
exportP({ amount, utxoSet, destination, feeState, toAddress }: ExportP): Common.UnsignedTx;
|
|
81
|
+
consolidateP({ utxoSet, amount, feeState, toAddress, options, }: ConsolidateP): Common.UnsignedTx;
|
|
82
|
+
baseTX({ utxoSet, chain, toAddress, amountsPerAsset, feeState, options, fromAddresses, }: BaseTx): Common.UnsignedTx;
|
|
83
|
+
convertSubnetToL1({ utxoSet, chainId, subnetId, subnetAuth, feeState, address, validators, options, fromAddresses, }: ConvertSubnetToL1): Common.UnsignedTx;
|
|
84
|
+
registerL1Validator({ utxoSet, balance, signature, message, feeState, fromAddresses, options, }: RegisterL1Validator): Common.UnsignedTx;
|
|
85
|
+
setL1ValidatorWeight({ utxoSet, feeState, message, options, fromAddresses, }: SetL1ValidatorWeight): Common.UnsignedTx;
|
|
86
|
+
disableL1Validator({ utxoSet, feeState, options, fromAddresses, disableAuth, validationId, }: DisableL1Validator): Common.UnsignedTx;
|
|
87
|
+
increaseL1ValidatorBalance({ utxoSet, feeState, options, fromAddresses, balance, validationId, }: IncreaseL1ValidatorBalance): Common.UnsignedTx;
|
|
88
|
+
createBlockchain({ utxoSet, subnetId, chainName, vmID, fxIds, genesisData, subnetAuth, feeState, options, fromAddresses, }: CreateChain): Common.UnsignedTx;
|
|
89
|
+
createSubnet({ utxoSet, rewardAddresses, feeState, fromAddresses, options, threshold, locktime, }: CreateSubnet): Common.UnsignedTx;
|
|
90
|
+
addSubnetValidator({ utxoSet, nodeId, start, end, weight, subnetId, subnetAuth, feeState, fromAddresses, options, }: AddSubnetValidator): Common.UnsignedTx;
|
|
95
91
|
/**
|
|
96
92
|
*
|
|
97
93
|
* @param utxoSet The transaction will be constructed from these UTXOs.
|
|
@@ -108,7 +104,7 @@ declare abstract class WalletAbstract {
|
|
|
108
104
|
* @param signature the BLS signature, If the subnet is the primary network. Can be found in the Node on startup.
|
|
109
105
|
* @param options
|
|
110
106
|
*/
|
|
111
|
-
addPermissionlessValidator(utxoSet
|
|
107
|
+
addPermissionlessValidator({ utxoSet, nodeId, start, end, weight, subnetId, shares, feeState, fromAddresses, rewardAddresses, delegatorRewardAddresses, publicKey, signature, options, threshold, locktime, stakingAssetId, }: AddPermissionlessValidator): Common.UnsignedTx;
|
|
112
108
|
/**
|
|
113
109
|
*
|
|
114
110
|
* @param utxoSet The transaction will be constructed from these UTXOs.
|
|
@@ -121,10 +117,9 @@ declare abstract class WalletAbstract {
|
|
|
121
117
|
* @param rewardAddresses Will use active address if not provided. Given addresses will share the reward UTXO.
|
|
122
118
|
* @param options
|
|
123
119
|
*/
|
|
124
|
-
addPermissionlessDelegator(utxoSet
|
|
125
|
-
removeSubnetValidator(utxoSet
|
|
126
|
-
transferSubnetOwnershipTx(utxoSet
|
|
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;
|
|
120
|
+
addPermissionlessDelegator({ utxoSet, nodeId, start, end, weight, subnetId, fromAddresses, rewardAddresses, options, locktime, feeState, threshold, stakingAssetId, }: AddPermissionlessDelegator): Common.UnsignedTx;
|
|
121
|
+
removeSubnetValidator({ utxoSet, nodeId, subnetId, subnetAuth, fromAddresses, feeState, options, }: RemoveSubnetValidator): Common.UnsignedTx;
|
|
122
|
+
transferSubnetOwnershipTx({ utxoSet, subnetId, subnetAuth, subnetOwners, feeState, fromAddresses, options, threshold, locktime, }: TransferSubnetOwnershipTx): Common.UnsignedTx;
|
|
128
123
|
protected constructor(provider: AbstractProvider);
|
|
129
124
|
}
|
|
130
125
|
|
|
@@ -1 +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/core-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};
|
|
1
|
+
import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"create-hash";import"bip32";import{getUTXOsForAddresses as e}from"../utils/getAllUTXOs.js";import"../utils/getAssetBalance.js";import{utils as s,TransferableOutput as t,avm as r,pvm as d,evm as n,pvmSerial as o,PChainOwner as i,L1Validator as a,networkIDs as m}from"@avalabs/avalanchejs";import{getStakeForAddresses as h}from"../utils/getStakeForAddresses.js";import"../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import{sortUTXOsByAmount as g,sortUTXOsByAmountAscending as u,sortUTXOsStaking as A}from"../utils/sortUTXOs.js";import"../utils/txSizeLimits.js";import"bip32-path";import{strip0x as c}from"@avalabs/core-utils-sdk";import{assertFeeStateProvided as p}from"../../utils/assertFeeStateProvided.js";const{parse:f,hexToBuffer:x}=s;class l{constructor(e){this.provider=e}setProvider(e){this.provider=e}getProvider(){return this.provider}async getUTXOs(s){const t=this.provider.getApi(s);return e(this.getAddresses(s),t)}async getStake(){const e=this.provider.getApiP();return h(this.getAddresses("P"),e)}async getAtomicUTXOs(s,t){if(s===t)throw new Error("Chain can not be the same as source chain.");const r=this.provider.getApi(s),d=this.provider.getChainID(t);return e(this.getAddresses(s),r,{sourceChain:d,addresses:[]})}exportX(e,s,d,n){n=n||this.getCurrentAddress(d);const o=f(n)[2],i=this.provider.getAvaxID(),a=t.fromNative(i,e,[o]),m=g(s.getUTXOs(),!0),h=this.provider.getChainID(d),u=this.getAddresses("X").map((e=>f(e)[2])),A=f(this.getChangeAddress("X"))[2];return r.newExportTx(this.provider.getContext(),h,u,m,[a],{threshold:1,changeAddresses:[A]})}importP({utxoSet:e,sourceChain:s,toAddress:t,threshold:r,feeState:n,locktime:o}){const i=this.provider.getChainID(s),a=this.getAddresses("P").map((e=>f(e)[2]));f(this.getChangeAddress("P"))[2],t=t||this.getCurrentAddress("P");const m=f(t)[2],h=e.getUTXOs();return p(n),d.newImportTx({fromAddressesBytes:a,utxos:h,toAddressesBytes:[m],sourceChainId:i,threshold:r,feeState:n,locktime:o},this.provider.getContext())}importX(e,s,t){const d=this.provider.getChainID(s),n=this.getAddresses("X").map((e=>f(e)[2])),o=f(this.getChangeAddress("X"))[2];t=t||this.getCurrentAddress("X");const i=f(t)[2];return r.newImportTx(this.provider.getContext(),d,e.getUTXOs(),[i],n,{changeAddresses:[o]})}importC(e,s,t,r,d){const o=this.provider.getChainID(s),i=this.getAddresses("C").map((e=>f(e)[2]));d=d||this.getAddressEVM();const a=Buffer.from(c(d),"hex");return n.newImportTxFromBaseFee(this.provider.getContext(),a,i,e.getUTXOs(),o,t,r)}exportC(e,s,t,r,d){const o=x(this.getAddressEVM()),i=this.provider.getChainID(s);d=d||this.getCurrentAddress(s);const a=f(d)[2],m=r/BigInt(1e9);return n.newExportTxFromBaseFee(this.provider.getContext(),m,e,i,o,[a],t)}exportP({amount:e,utxoSet:s,destination:r,feeState:n,toAddress:o}){o=o||this.getCurrentAddress(r);const i=f(o)[2],a=this.provider.getAvaxID(),m=t.fromNative(a,e,[i]),h=g(s.getUTXOs(),!0),u=this.provider.getChainID(r),A=this.getAddresses("P").map((e=>f(e)[2])),c=f(this.getChangeAddress("P"))[2];return p(n),d.newExportTx({changeAddressesBytes:[c],fromAddressesBytes:A,utxos:h,outputs:[m],destinationChainId:u,feeState:n},this.provider.getContext())}consolidateP({utxoSet:e,amount:s,feeState:r,toAddress:n,options:o}){const i=u(e.getUTXOs());n=n??this.getCurrentAddress("P");const a=f(n)[2],m=this.provider.getContext(),h=[t.fromNative(m.avaxAssetID,s,[a])],g=this.getAddresses("P").map((e=>f(e)[2])),A=f(this.getChangeAddress("P"))[2],c=o?.changeAddresses??[A];return p(r),d.newBaseTx({changeAddressesBytes:c,fromAddressesBytes:g,utxos:i,outputs:h,minIssuanceTime:o?.minIssuanceTime,memo:o?.memo,feeState:r},m)}baseTX({utxoSet:e,chain:s,toAddress:n,amountsPerAsset:o,feeState:i,options:a,fromAddresses:m}){const[h,u,A]=f(n);if(h!==s||u!==this.provider.getHrp())throw new Error(`Invalid recipient address "${n}"`);const c=Object.entries(o).map((([e,s])=>t.fromNative(e,s,[A]))),x=g(e.getUTXOs(),!0),l=(m??this.getAddresses(s)).map((e=>f(e)[2])),T=f(this.getChangeAddress("P"))[2],I=a?.changeAddresses??[T];return"X"===s?r.newBaseTx(this.provider.getContext(),l,x,c,a):(p(i),d.newBaseTx({changeAddressesBytes:I,fromAddressesBytes:l,utxos:x,outputs:c,minIssuanceTime:a?.minIssuanceTime,memo:a?.memo,feeState:i},this.provider.getContext()))}convertSubnetToL1({utxoSet:e,chainId:t,subnetId:r,subnetAuth:n,feeState:m,address:h,validators:u,options:A,fromAddresses:c}){const p=(c??this.getAddresses("P")).map((e=>f(e)[2])),x=f(this.getChangeAddress("P"))[2],l=A?.changeAddresses??[x],T=u.map((({nodeId:e,pubKey:t,signature:r,balance:d,weight:n,deactivationOwner:m,remainingBalanceOwner:h})=>{const g=new o.ProofOfPossession(Uint8Array.from(s.hexToBuffer(t)),Uint8Array.from(s.hexToBuffer(r))),u=i.fromNative(h.addresses.map((e=>f(e)[2])),h.threshold??1),A=i.fromNative(m.addresses.map((e=>f(e)[2])),m.threshold??1);return a.fromNative(e,n,d,g,u,A)}));return d.newConvertSubnetToL1Tx({changeAddressesBytes:l,validators:T,fromAddressesBytes:p,address:f(h)[2],chainId:t,subnetId:r,subnetAuth:n,feeState:m,utxos:g(e.getUTXOs(),!0)},this.provider.getContext())}registerL1Validator({utxoSet:e,balance:t,signature:r,message:n,feeState:o,fromAddresses:i,options:a}){const m=(i??this.getAddresses("P")).map((e=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],u=a?.changeAddresses??[h];return d.newRegisterL1ValidatorTx({utxos:g(e.getUTXOs(),!0),balance:t,blsSignature:Uint8Array.from(s.hexToBuffer(r)),changeAddressesBytes:u,feeState:o,fromAddressesBytes:m,memo:a?.memo,message:Uint8Array.from(s.hexToBuffer(n)),minIssuanceTime:a?.minIssuanceTime},this.provider.getContext())}setL1ValidatorWeight({utxoSet:e,feeState:t,message:r,options:n,fromAddresses:o}){const i=(o??this.getAddresses("P")).map((e=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=n?.changeAddresses??[a];return d.newSetL1ValidatorWeightTx({utxos:g(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:t,fromAddressesBytes:i,memo:n?.memo,message:Uint8Array.from(s.hexToBuffer(r)),minIssuanceTime:n?.minIssuanceTime},this.provider.getContext())}disableL1Validator({utxoSet:e,feeState:s,options:t,fromAddresses:r,disableAuth:n,validationId:o}){const i=(r??this.getAddresses("P")).map((e=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=t?.changeAddresses??[a];return d.newDisableL1ValidatorTx({disableAuth:n,validationId:o,utxos:g(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:s,fromAddressesBytes:i,memo:t?.memo,minIssuanceTime:t?.minIssuanceTime},this.provider.getContext())}increaseL1ValidatorBalance({utxoSet:e,feeState:s,options:t,fromAddresses:r,balance:n,validationId:o}){const i=(r??this.getAddresses("P")).map((e=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=t?.changeAddresses??[a];return d.newIncreaseL1ValidatorBalanceTx({balance:n,validationId:o,utxos:g(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:s,fromAddressesBytes:i,memo:t?.memo,minIssuanceTime:t?.minIssuanceTime},this.provider.getContext())}createBlockchain({utxoSet:e,subnetId:s,chainName:t,vmID:r,fxIds:n,genesisData:o,subnetAuth:i,feeState:a,options:m,fromAddresses:h}){const u=g(e.getUTXOs(),!0),A=(h??this.getAddresses("P")).map((e=>f(e)[2])),c=f(this.getChangeAddress("P"))[2],x=m?.changeAddresses??[c];return p(a),d.newCreateChainTx({chainName:t,feeState:a,fromAddressesBytes:A,fxIds:n,genesisData:o,subnetAuth:i,subnetId:s,utxos:u,vmId:r,changeAddressesBytes:x},this.provider.getContext())}createSubnet({utxoSet:e,rewardAddresses:s,feeState:t,fromAddresses:r,options:n,threshold:o,locktime:i}){const a=g(e.getUTXOs(),!0),m=(r??this.getAddresses("P")).map((e=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],u=n?.changeAddresses??[h],A=s.map((e=>f(e)[2]));return p(t),d.newCreateSubnetTx({fromAddressesBytes:m,changeAddressesBytes:u,utxos:a,minIssuanceTime:n?.minIssuanceTime,memo:n?.memo,feeState:t,threshold:o,locktime:i,subnetOwners:A},this.provider.getContext())}addSubnetValidator({utxoSet:e,nodeId:s,start:t,end:r,weight:n,subnetId:o,subnetAuth:i,feeState:a,fromAddresses:m,options:h}){const u=g(e.getUTXOs(),!0),A=(m??this.getAddresses("P")).map((e=>f(e)[2])),c=f(this.getChangeAddress("P"))[2],x=h?.changeAddresses??[c];return p(a),d.newAddSubnetValidatorTx({changeAddressesBytes:x,fromAddressesBytes:A,utxos:u,minIssuanceTime:h?.minIssuanceTime,memo:h?.memo,nodeId:s,start:t,end:r,weight:n,subnetId:o,subnetAuth:i,feeState:a},this.provider.getContext())}addPermissionlessValidator({utxoSet:e,nodeId:s,start:t,end:r,weight:n,subnetId:o,shares:i,feeState:a,fromAddresses:h,rewardAddresses:g,delegatorRewardAddresses:u,publicKey:c,signature:x,options:l,threshold:T,locktime:I,stakingAssetId:v}){const C=A(e.getUTXOs()),S=(h??this.getAddresses("P")).map((e=>f(e)[2])),b=(g??[this.getCurrentAddress("P")]).map((e=>f(e)[2])),P=(u??[this.getCurrentAddress("P")]).map((e=>f(e)[2]));if(!(o!==m.PrimaryNetworkID.toString()||c&&x))throw new Error("Must provide public key and signature for primary subnet.");const w=f(this.getChangeAddress("P"))[2],B=l?.changeAddresses??[w];return p(a),d.newAddPermissionlessValidatorTx({fromAddressesBytes:S,delegatorRewardsOwner:P,utxos:C,minIssuanceTime:l?.minIssuanceTime,memo:l?.memo,changeAddressesBytes:B,nodeId:s,start:t,end:r,weight:n,subnetId:o,shares:i,feeState:a,publicKey:c,rewardAddresses:b,signature:x,locktime:I,threshold:T,stakingAssetId:v},this.provider.getContext())}addPermissionlessDelegator({utxoSet:e,nodeId:s,start:t,end:r,weight:n,subnetId:o,fromAddresses:i,rewardAddresses:a,options:m,locktime:h,feeState:g,threshold:u,stakingAssetId:c}){const x=A(e.getUTXOs()),l=(i??this.getAddresses("P")).map((e=>f(e)[2])),T=(a??[this.getCurrentAddress("P")]).map((e=>f(e)[2])),I=f(this.getChangeAddress("P"))[2],v=m?.changeAddresses??[I];return p(g),d.newAddPermissionlessDelegatorTx({fromAddressesBytes:l,utxos:x,minIssuanceTime:m?.minIssuanceTime,memo:m?.memo,changeAddressesBytes:v,nodeId:s,start:t,end:r,weight:n,subnetId:o,rewardAddresses:T,locktime:h,stakingAssetId:c,threshold:u,feeState:g},this.provider.getContext())}removeSubnetValidator({utxoSet:e,nodeId:s,subnetId:t,subnetAuth:r,fromAddresses:n,feeState:o,options:i}){const a=g(e.getUTXOs(),!0),m=(n??this.getAddresses("P")).map((e=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],u=i?.changeAddresses??[h];return p(o),d.newRemoveSubnetValidatorTx({changeAddressesBytes:u,fromAddressesBytes:m,utxos:a,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,nodeId:s,subnetId:t,subnetAuth:r,feeState:o},this.provider.getContext())}transferSubnetOwnershipTx({utxoSet:e,subnetId:s,subnetAuth:t,subnetOwners:r,feeState:n,fromAddresses:o,options:i,threshold:a,locktime:m}){const h=g(e.getUTXOs(),!0),u=(o??this.getAddresses("P")).map((e=>f(e)[2])),A=f(this.getChangeAddress("P"))[2],c=i?.changeAddresses??[A],x=r.map((e=>f(e)[2]));return p(n),d.newTransferSubnetOwnershipTx({changeAddressesBytes:c,fromAddressesBytes:u,utxos:h,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,subnetId:s,subnetAuth:t,subnetOwners:x,feeState:n,threshold:a,locktime:m},this.provider.getContext())}}export{l as WalletAbstract};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletAbstract as
|
|
1
|
+
import{WalletAbstract as t}from"./WalletAbstract.js";import{fromSeed as e}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import{strip0x as i}from"@avalabs/core-utils-sdk";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"create-hash";import"@avalabs/avalanchejs";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import{verifyDerivationPath as o}from"../utils/verifyDerivationPath.js";import{SigningKey as a,computeAddress as n}from"ethers";class u extends t{constructor(t,e,r){if(super(r),this.pubkeyXP=t,this.pubkeyC=e,33!==e.length||33!==t.length)throw new Error("Public key must be 33 byte compressed public key")}static fromPublicKey(t,e,r){const s=i(a.computePublicKey(t,!0)),o=i(a.computePublicKey(e,!0)),n=Buffer.from(s,"hex"),l=Buffer.from(o,"hex");return new u(n,l,r)}static fromMnemonic(t,i,a,n){if(!r(t))throw new Error("Invalid mnemonic phrase.");if(!o(a)||!o(i))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const l=s(t),m=e(l),p=m.derivePath(a),c=m.derivePath(i);return u.fromPublicKey(c.publicKey,p.publicKey,n)}getAddress(t){const e="C"===t?this.pubkeyC:this.pubkeyXP;return this.provider.getAddress(e,t)}getAddressEVM(){return n(`0x${this.pubkeyC.toString("hex")}`)}getAddresses(t){return[this.getAddress(t)]}getChangeAddress(t){return this.getAddress(t)}getCurrentAddress(t){return this.getAddress(t)}}export{u as WalletVoid};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { UnsignedTx } from '@avalabs/avalanchejs';
|
|
2
|
+
import { Signer, SignMessageRequest, SignTxRequest, SignTxBufferRequest } from '../models.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Ledger signer that can use multiple LedgerLive derivation paths for signing transactions.
|
|
6
|
+
*/
|
|
7
|
+
declare class LedgerLiveSigner implements Signer {
|
|
8
|
+
#private;
|
|
9
|
+
private accountIndices;
|
|
10
|
+
constructor(accountIndices: number[]);
|
|
11
|
+
signMessage(request: SignMessageRequest): Promise<Buffer>;
|
|
12
|
+
signTx(txRequest: SignTxRequest): Promise<UnsignedTx>;
|
|
13
|
+
signTxBuffer(txRequest: SignTxBufferRequest): Promise<Buffer[]>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { LedgerLiveSigner };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import t from"bip32-path";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as r}from"../../utils/digestMessage.js";import"bip32";import"@avalabs/avalanchejs";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";const s={C:60,X:9e3,P:9e3};class i{constructor(t){this.accountIndices=t}#t(t){return`m/44'/${s[t]}'`}#r(t,r){return`${this.#t(t)}/${r}'`}async signMessage(s){if(!s.transport||!s.message)throw new Error("Unable to sign message. Incomplete or invalid request.");if(!this.accountIndices.length)throw new Error("No account indices provided. At least one account index is required to sign a message.");const i=t.fromString(this.#r(s.chain,this.accountIndices[0])),n=t.fromString("0/0"),o=r(s.message),a=(await e.signHash(s.transport,o,i,[n])).signatures.get(n.toString(!0));if(!a)throw new Error("Failed to sign message.");return a}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const e=r.tx,s=e.getVM(),i=Buffer.from(e.toBytes()),n="EVM"===s?"C":"AVM"===s?"X":"P",o=new Set(r.externalIndices??this.accountIndices);for(const s of o){const o=t.fromString(this.#r(n,s));(await this.#e(o,{buffer:i,chain:n,transport:r.transport})).forEach((t=>{e.addSignature(t)}))}return e}async#e(r,s){if(!s.transport)throw new Error("Ledger transport not provided");return[...(await e.signTx(s.transport,s.buffer,r,s.signers??[t.fromString("0/0")],s.change??[t.fromString("0/0")])).signatures.values()]}async signTxBuffer(r){if(!this.accountIndices.length)throw new Error("No account indices provided. At least one account index is required to sign a tx buffer.");const e=t.fromString(this.#r(r.chain,this.accountIndices[0]));return this.#e(e,r)}}export{i as LedgerLiveSigner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletVoid as
|
|
1
|
+
import{WalletVoid as t}from"../WalletVoid.js";import{isObsidianApp as r}from"./isObsidianApp.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";import i from"bip32-path";import s from"@ledgerhq/hw-app-eth";import{utils as o}from"@avalabs/avalanchejs";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../../utils/digestMessage.js";import"bip32";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import{verifyDerivationPath as n}from"../../utils/verifyDerivationPath.js";import{SigningKey as p}from"ethers";const{strip0x:u}=o;class h extends t{constructor(t,r,e,i,s){const a=o.strip0x(p.computePublicKey(t,!0)),u=o.strip0x(p.computePublicKey(e,!0));if(super(Buffer.from(a,"hex"),Buffer.from(u,"hex"),s),this.pathXP=r,this.pathC=i,!n(r)||!n(i))throw new Error("Invalid path configuration.")}static async fromTransport(t,e,i,o){if(await r(t))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 a=new s(t),f=await a.getAddress(i,!1),g=await a.getAddress(e,!1),m=Buffer.from(u(f.publicKey),"hex"),c=Buffer.from(u(g.publicKey),"hex"),l=Buffer.from(u(p.computePublicKey(m,!0)),"hex"),d=Buffer.from(u(p.computePublicKey(c,!0)),"hex");return new h(d,e,l,i,o)}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const r=i.fromString(this.getAccountPath(t.chain)),s=i.fromString(this.getPartialSignerPath(t.chain)),o=a(t.message),n=(await e.signHash(t.transport,o,r,[s])).signatures.get(s.toString(!0));if(!n)throw new Error("Failed to sign message.");return n}getFullSignerPath(t){return"C"===t?this.pathC:this.pathXP}getPartialSignerPath(t){return this.getFullSignerPath(t).split("/").slice(4).join("/")}getAccountPath(t){return this.getFullSignerPath(t).split("/").slice(0,4).join("/")}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=t.tx,e=r.getVM(),i=Buffer.from(r.toBytes()),s="EVM"===e?"C":"X";return(await this.signTxBuffer({buffer:i,chain:s,transport:t.transport})).forEach((t=>{r.addSignature(t)})),r}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=i.fromString(this.getAccountPath(t.chain)),s=i.fromString(this.getPartialSignerPath(t.chain));return[...(await e.signTx(t.transport,t.buffer,r,[s],[s])).signatures.values()]}}export{h as LedgerSigner};
|
|
@@ -15,7 +15,7 @@ declare class SimpleLedgerSigner implements Signer {
|
|
|
15
15
|
private accountNode;
|
|
16
16
|
/**
|
|
17
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'
|
|
18
|
+
* @param {string} xpubXP - optional extended public key of `m/44'/9000'/${activeAccountIndex}`
|
|
19
19
|
*/
|
|
20
20
|
constructor(activeAccountIndex: number, provider: JsonRpcProvider, xpubXP?: string);
|
|
21
21
|
private reSerializeTx;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{utils as t,EVMUnsignedTx as r,UnsignedTx 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/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../../utils/digestMessage.js";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";const{parse:c}=t;class g{constructor(t,r,e){this.activeAccountIndex=t,this.provider=r,e&&(this.accountNode=o(e))}accountNode;reSerializeTx(t,s){return t instanceof r||"C"===s?r.fromJSON(JSON.stringify(t.toJSON())):e.fromJSON(JSON.stringify(t.toJSON()))}getChainAlias(t){return"EVM"===t.getVM()?"C":"X"}getAccountPath(t){switch(t){case"X":case"P":return`m/44'/9000'/${this.activeAccountIndex}'`;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="EVM"===t.tx.getVM()?`0/${this.activeAccountIndex}`:"0/0",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,e){return 0===r.size?[s.fromString("C"===e?`0/${this.activeAccountIndex}`:"0/0")]: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,r),a=this.getAddressBipPaths([...i(e)],n,r);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="C"===t.chain?this.activeAccountIndex:0,e=t.signer||s.fromString(`0/${r}`);if(2!=e.toPathArray().length)throw new Error("Given signer path must have a depth of 2. Ex. 0/0, 0/1");const i=a(t.message),o=(await n.signHash(t.transport,i,s.fromString(this.getAccountPath(t.chain)),[e])).signatures.get(e.toString(!0));if(!o)throw new Error("Failed to sign message.");return o}}export{g as SimpleLedgerSigner};
|