@avalabs/core-wallets-sdk 3.1.0-alpha.6 → 3.1.0-alpha.61

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.
Files changed (115) hide show
  1. package/dist/index.cjs +1 -0
  2. package/dist/index.d.ts +379 -158
  3. package/esm/Avalanche/index.d.ts +3 -4
  4. package/esm/Avalanche/index.js +1 -1
  5. package/esm/Avalanche/models.d.ts +47 -6
  6. package/esm/Avalanche/models.js +1 -1
  7. package/esm/Avalanche/providers/AbstractProvider.d.ts +2 -1
  8. package/esm/Avalanche/providers/AbstractProvider.js +1 -1
  9. package/esm/Avalanche/providers/JsonRpcProvider.d.ts +1 -0
  10. package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
  11. package/esm/Avalanche/providers/constants.d.ts +2 -1
  12. package/esm/Avalanche/providers/constants.js +1 -1
  13. package/esm/Avalanche/providers/platformFeeConfig.js +1 -0
  14. package/esm/Avalanche/utils/addSignaturesToAvalancheTx.js +1 -1
  15. package/esm/Avalanche/utils/appendDisableAuthAddressMaps.js +1 -0
  16. package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +5 -4
  17. package/esm/Avalanche/utils/convertGlacierUtxo.js +1 -1
  18. package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.d.ts +3 -2
  19. package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.js +1 -1
  20. package/esm/Avalanche/utils/createAvalancheUnsignedTx.d.ts +1 -1
  21. package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
  22. package/esm/Avalanche/utils/getAssetBalance.d.ts +2 -1
  23. package/esm/Avalanche/utils/getAssetBalance.js +1 -1
  24. package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -1
  25. package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
  26. package/esm/Avalanche/utils/getStakedAssetBalance.d.ts +2 -1
  27. package/esm/Avalanche/utils/getTxOutputAddresses.js +1 -1
  28. package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +5 -2
  29. package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -1
  30. package/esm/Avalanche/utils/handleSubnetAuth.js +1 -1
  31. package/esm/Avalanche/utils/orderBy.js +1 -0
  32. package/esm/Avalanche/utils/parseAvalancheTx.d.ts +12 -1
  33. package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
  34. package/esm/Avalanche/utils/parsers/index.js +1 -1
  35. package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -1
  36. package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -1
  37. package/esm/Avalanche/utils/parsers/parseAddSubnetValidorTx.js +1 -1
  38. package/esm/Avalanche/utils/parsers/parseBaseTx.js +1 -1
  39. package/esm/Avalanche/utils/parsers/parseConvertSubnetToL1Tx.js +1 -0
  40. package/esm/Avalanche/utils/parsers/parseCreateChainTx.js +1 -1
  41. package/esm/Avalanche/utils/parsers/parseCreateSubnetTx.js +1 -1
  42. package/esm/Avalanche/utils/parsers/parseDisableL1ValidatorTx.js +1 -0
  43. package/esm/Avalanche/utils/parsers/parseExportTx.js +1 -1
  44. package/esm/Avalanche/utils/parsers/parseImportTx.js +1 -1
  45. package/esm/Avalanche/utils/parsers/parseIncreaseL1ValidatorBalanceTx.js +1 -0
  46. package/esm/Avalanche/utils/parsers/parseRegisterL1ValidatorTx.js +1 -0
  47. package/esm/Avalanche/utils/parsers/parseRemoveSubnetValidatorTx.js +1 -1
  48. package/esm/Avalanche/utils/parsers/parseSetL1ValidatorWeightTx.js +1 -0
  49. package/esm/Avalanche/utils/parsers/parseTransferSubnetOwnershipTx.js +1 -1
  50. package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -1
  51. package/esm/Avalanche/utils/populateCredential.js +1 -1
  52. package/esm/Avalanche/utils/sortUTXOs.d.ts +6 -4
  53. package/esm/Avalanche/utils/sortUTXOs.js +1 -1
  54. package/esm/Avalanche/utils/txSizeLimits.d.ts +10 -3
  55. package/esm/Avalanche/utils/txSizeLimits.js +1 -1
  56. package/esm/Avalanche/wallets/AddressWallet.js +1 -1
  57. package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
  58. package/esm/Avalanche/wallets/StaticSigner.js +1 -1
  59. package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +179 -0
  60. package/esm/Avalanche/wallets/WalletAbstract.d.ts +21 -22
  61. package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
  62. package/esm/Avalanche/wallets/WalletVoid.js +1 -1
  63. package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
  64. package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
  65. package/esm/Avalanche/wallets/ledger/models.d.ts +1 -1
  66. package/esm/Avalanche/wallets/legacy/LedgerWallet.js +1 -1
  67. package/esm/Avalanche/wallets/legacy/MnemonicWallet.js +1 -1
  68. package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.js +1 -1
  69. package/esm/Avalanche/wallets/models.d.ts +1 -1
  70. package/esm/BitcoinVM/index.d.ts +5 -0
  71. package/esm/BitcoinVM/index.js +1 -0
  72. package/esm/BitcoinVM/models.d.ts +1 -1
  73. package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +4 -3
  74. package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -1
  75. package/esm/BitcoinVM/providers/BitcoinProviderAbstract.d.ts +1 -0
  76. package/esm/BitcoinVM/utils/getBech32AddressFromXPub.js +1 -1
  77. package/esm/BitcoinVM/wallets/BitcoinWallet.js +1 -1
  78. package/esm/BitcoinVM/wallets/BitcoinWalletLedger.js +1 -1
  79. package/esm/BitcoinVM/wallets/models.d.ts +1 -1
  80. package/esm/EVM/LedgerSigner.js +1 -1
  81. package/esm/EVM/utils/blockPolling.js +1 -1
  82. package/esm/EVM/utils/getWalletFromMnemonic.js +1 -1
  83. package/esm/SolanaVM/utils/compileSolanaTx.d.ts +9 -0
  84. package/esm/SolanaVM/utils/compileSolanaTx.js +1 -0
  85. package/esm/SolanaVM/utils/derivationPath.d.ts +3 -0
  86. package/esm/SolanaVM/utils/derivationPath.js +1 -0
  87. package/esm/SolanaVM/utils/deserializeSolanaTx.d.ts +6 -0
  88. package/esm/SolanaVM/utils/deserializeSolanaTx.js +1 -0
  89. package/esm/SolanaVM/utils/getSolanaPublicKeyFromLedger.d.ts +5 -0
  90. package/esm/SolanaVM/utils/getSolanaPublicKeyFromLedger.js +1 -0
  91. package/esm/SolanaVM/utils/serializeSolanaTx.d.ts +6 -0
  92. package/esm/SolanaVM/utils/serializeSolanaTx.js +1 -0
  93. package/esm/SolanaVM/utils/solanaProvider.d.ts +11 -0
  94. package/esm/SolanaVM/utils/solanaProvider.js +1 -0
  95. package/esm/SolanaVM/utils/transferSol.d.ts +14 -0
  96. package/esm/SolanaVM/utils/transferSol.js +1 -0
  97. package/esm/SolanaVM/utils/transferToken.d.ts +17 -0
  98. package/esm/SolanaVM/utils/transferToken.js +1 -0
  99. package/esm/SolanaVM/wallets/SolanaLedgerSigner.d.ts +10 -0
  100. package/esm/SolanaVM/wallets/SolanaLedgerSigner.js +1 -0
  101. package/esm/SolanaVM/wallets/SolanaSigner.d.ts +20 -0
  102. package/esm/SolanaVM/wallets/SolanaSigner.js +1 -0
  103. package/esm/abis/erc20.abi.js +1 -0
  104. package/esm/index.d.ts +30 -20
  105. package/esm/index.js +1 -1
  106. package/esm/utils/assertFeeStateProvided.js +1 -0
  107. package/esm/utils/getAddressDerivationPath.d.ts +4 -1
  108. package/esm/utils/getAddressDerivationPath.js +1 -1
  109. package/package.json +30 -13
  110. package/dist/index.js +0 -1
  111. package/esm/Avalanche/utils/getUtxoInfo.d.ts +0 -13
  112. package/esm/Avalanche/utils/getUtxoInfo.js +0 -1
  113. package/esm/Avalanche/utils/parsers/parseAddDelegatorTx.js +0 -1
  114. package/esm/Avalanche/utils/parsers/parseAddValidatorTx.js +0 -1
  115. package/esm/Avalanche/utils/parsers/parseTransformSubnetTx.js +0 -1
@@ -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- LockedStakeable UTXOs with the highest locktime to lowest
6
- * 2- Highest value UTXOs to lowest
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";const{isStakeableLockOut:n,isTransferOut:u}=t;function e(t){return t.sort(((t,e)=>{const r=t.output,o=e.output,a=n(r),i=n(o);if(a&&!i)return-1;if(i&&!a)return 1;if(n(r)&&n(o)){const t=r.getStakeableLocktime(),n=o.getStakeableLocktime();if(t<n)return 1;if(t>n)return-1}else if(u(r)&&u(o)){if(r.amount()>o.amount())return-1;if(r.amount()<o.amount())return 1}return 0}))}function r(t,e){return t.sort(((t,r)=>{const o=t.output,a=r.output;let i=BigInt(0);(u(o)||n(o))&&(i=o.amount());let s=BigInt(0);(u(a)||n(a))&&(s=a.amount());const c=e?s-i:i-s;return c>0?1:c<0?-1:0}))}const o=t=>r(t,!0),a=t=>r(t,!1);export{r as sortUTXOsByAmount,a as sortUTXOsByAmountAscending,o as sortUTXOsByAmountDescending,e as sortUTXOsStaking};
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 'Avalanche/wallets';
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: WalletAbstract, utxos: Utxo[], sizeSupportedTx: SizeSupportedTx, limit?: number): Utxo[];
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{getUtxoInfo as t}from"./getUtxoInfo.js";import{getUnixNow as o}from"./getUnixNow.js";import{binarySearch as r}from"../../utils/binarySearch.js";import{sortUTXOsByAmountDescending as s,sortUTXOsByAmountAscending as n,sortUTXOsStaking as i}from"./sortUTXOs.js";var d=(e=>(e.ExportP="ExportP",e.ImportP="ImportP",e.AddPermissionlessValidator="AddPermissionlessValidator",e.AddPermissionlessDelegator="AddPermissionlessDelegator",e.BaseP="BaseP",e.ConsolidateP="ConsolidateP",e))(d||{});const a="NodeID-8TArWpFgH3sazEH8qP4gUjtGtFMvjw1aR",c="11111111111111111111111111111111LpoYY",l=(e,o)=>e.reduce(((e,o)=>e+t(o).amount),BigInt(0))-o,u={BaseP:{sortFunction:s,unsignedTxBuilder:(t,o)=>{const r=t.getProvider().getContext();return t.baseTX(new e.UtxoSet(o),"P",t.getCurrentAddress("P"),{[r.avaxAssetID]:l(o,r.baseTxFee)})}},ConsolidateP:{sortFunction:n,unsignedTxBuilder:(t,o)=>{const r=t.getProvider().getContext();return t.consolidateP(new e.UtxoSet(o),l(o,r.baseTxFee))}},AddPermissionlessValidator:{sortFunction:i,unsignedTxBuilder:(t,r)=>t.addPermissionlessValidator(new e.UtxoSet(r),a,o(),o()+BigInt(1e3),l(r,t.getProvider().getContext().addPrimaryNetworkValidatorFee),c,5,void 0,void 0,void 0,Buffer.from(e.hexToBuffer("0x8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e15")),Buffer.from(e.hexToBuffer("0x86a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98")))},AddPermissionlessDelegator:{sortFunction:i,unsignedTxBuilder:(t,r)=>t.addPermissionlessDelegator(new e.UtxoSet(r),a,o(),o()+BigInt(1e3),l(r,t.getProvider().getContext().addPrimaryNetworkDelegatorFee),c)},ExportP:{sortFunction:s,unsignedTxBuilder:(t,o)=>t.exportP(l(o,t.getProvider().getContext().baseTxFee),new e.UtxoSet(o),"X")},ImportP:{sortFunction:s,unsignedTxBuilder:(t,o)=>t.importP(new e.UtxoSet(o),"X")}},x=65536;function P(e,s,n,i=65536){const{sortFunction:d,unsignedTxBuilder:a}=u[n],c=o(),l=d(s.filter((e=>{const{locktime:o,stakeableLocktime:r}=t(e);return o<c&&(r<c||("AddPermissionlessDelegator"===n||"AddPermissionlessValidator"===n))}))),x=r(l,(o=>{try{return function(e){const o=e.getInputUtxos().reduce(((e,o)=>e+(8+65*t(o).threshold)),0);return 6+e.toBytes().length+o}(a(e,o))}catch(e){return console.log("Unable to estimate size of utxos",{e:e,utxos:o.map(t)}),i+1}}),i);return-1===x?[]:l.slice(0,x+1)}export{x as P_CHAIN_TX_SIZE_LIMIT,d as SizeSupportedTx,P as getMaximumUtxoSet};
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"@avalabs/avalanchejs";import"../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import{isAddress as e}from"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import"@avalabs/glacier-sdk";import"bip39";import{isBech32Address as r}from"../utils/isBech32Address.js";import"xss";import"bip32-path";class t extends s{constructor(s,t,a,d,i){if(super(i),this.addressC=s,this.addressCoreEth=t,this.xpAddresses=a,this.xpChangeAddress=d,a.length<1)throw new Error("Must have at least 1 xp address.");if(!e(s))throw new Error("Not a valid C-Chain (EVM) address");if(a.some((s=>!r(s,!1))))throw new Error("Given addresses must be valid avalanche bech32 addresses without the chain alias prefix");if(!r(t,!1))throw new Error("Given CoreEth address must be valid avalanche bech32 addresses without the chain alias prefix");this.setChangeAddress(d)}setChangeAddress(s){if(!r(s,!1))throw new Error("Given address must be valid avalanche bech32 addresses without the chain alias prefix");this.xpChangeAddress=s}getAddressEVM(){return this.addressC}getAddresses(s){return("C"===s?[this.addressCoreEth]:this.xpAddresses).map((e=>this.provider.formatAddress(e,s)))}getChangeAddress(s){const e="C"===s?this.addressCoreEth:this.xpChangeAddress;return this.provider.formatAddress(e,s)}getCurrentAddress(s){const e="C"===s?this.addressCoreEth:this.xpAddresses[0];return this.provider.formatAddress(e,s)}}export{t as AddressWallet};
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"@avalabs/core-chains-sdk";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,a,i,d){if(super(d),this.addressC=s,this.addressCoreEth=t,this.xpAddresses=a,this.xpChangeAddress=i,a.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(a.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(i)}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};
@@ -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 n}from"bip39";import"@ledgerhq/hw-app-eth";import"ethers";import{getAddressDerivationPath as o}from"../../utils/getAddressDerivationPath.js";import"hdkey";import"buffer";import{DerivationPath as s}from"../../EVM/constants.js";import"@openzeppelin/contracts/build/contracts/ERC20.json";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"../utils/populateCredential.js";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import{digestMessage as a}from"../utils/digestMessage.js";import"@avalabs/glacier-sdk";import"xss";import"bip32-path";class c{accountNodeXP;signerNodeEVM;activeAccountIndex;constructor(e,t){if(!r(e))throw new Error("Invalid mnemonic phrase.");if(t<0||t%1!=0)throw new Error("Invalid account index.");const a=n(e),c=i(a);this.accountNodeXP=c.derivePath("m/44'/9000'/0'");const p=c.derivePath(o(t,s.BIP44,"EVM"));this.signerNodeEVM=p,this.activeAccountIndex=t}getAdditionalKeys(e,t){return[...new Set(e??[])].reduce(((e,i)=>{const r=this.accountNodeXP.derivePath(`${t?1:0}/${i}`);if(!r.privateKey)throw new Error("Unable to get private key.");return e.push(r.privateKey),e}),[])}getSigningKeys(e,t,i){if("EVM"===e){if(!this.signerNodeEVM.privateKey)throw new Error("Unable to derive EVM private key.");return[this.signerNodeEVM.privateKey]}const r=this.accountNodeXP.derivePath(`0/${this.activeAccountIndex}`);if(!r.privateKey)throw new Error("Unable to derive X/P private key.");const n=this.getAdditionalKeys(t,!1);if("AVM"===e){const e=this.getAdditionalKeys(i,!0);return[r.privateKey,...n,...e]}if("PVM"===e)return[r.privateKey,...n]}async signTx(t){const{tx:i,externalIndices:r,internalIndices:n}=t,o=i.getVM(),s=this.getSigningKeys(o,r,n);if(!s?.length)throw new Error("Unable to sign transaction: signing keys are missing.");return await e({unsignedTx:i,privateKeys:s}),t.tx}async signTxBuffer(e){throw new Error("Not implemented")}getActiveAccountNode(e){switch(e){case"X":case"P":return this.accountNodeXP.derivePath(`0/${this.activeAccountIndex}`);case"C":return this.signerNodeEVM}}async signMessage(e){const i=this.getActiveAccountNode(e.chain);if(!i.privateKey)throw Error("Unable to sign message, key not found.");const r=a(e.message),n=await t.signHash(r,i.privateKey);return Buffer.from(n)}}export{c as SimpleSigner};
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{getAddressDerivationPath as n}from"../../utils/getAddressDerivationPath.js";import"hdkey";import{DerivationPath as o}from"../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";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"@avalabs/core-chains-sdk";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'/0'");const d=c.derivePath(n(t,o.BIP44,"EVM"));this.signerNodeEVM=d,this.activeAccountIndex=t}getAdditionalKeys(e,t){return[...new Set(e??[])].reduce(((e,i)=>{const r=this.accountNodeXP.derivePath(`${t?1:0}/${i}`);if(!r.privateKey)throw new Error("Unable to get private key.");return e.push(r.privateKey),e}),[])}getSigningKeys(e,t,i){if("EVM"===e){if(!this.signerNodeEVM.privateKey)throw new Error("Unable to derive EVM private key.");return[this.signerNodeEVM.privateKey]}const r=this.accountNodeXP.derivePath(`0/${this.activeAccountIndex}`);if(!r.privateKey)throw new Error("Unable to derive X/P private key.");const 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/${this.activeAccountIndex}`);case"C":return this.signerNodeEVM}}async signMessage(e){const i=this.getActiveAccountNode(e.chain);if(!i.privateKey)throw Error("Unable to sign message, key not found.");const r=a(e.message),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{addTxSignatures as r,secp256k1 as e,utils as t}from"@avalabs/avalanchejs";import{validateMnemonic as s,mnemonicToSeedSync as a}from"bip39";import{fromSeed as o}from"bip32";import{digestMessage as n}from"../utils/digestMessage.js";import"../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"@avalabs/glacier-sdk";import"xss";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";const{getPublicKey:m,sign:v,signHash:f}=e,{addChecksum:h}=t;class c extends i{privKeyXP;privKeyC;constructor(i,r,e){super(Buffer.from(m(i)),Buffer.from(m(r)),e),this.privKeyXP=i,this.privKeyC=r}static fromMnemonic(i,r,e,t){if(!s(i))throw new Error("Invalid mnemonic phrase.");if(!p(e)||!p(r))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const n=a(i),m=o(n),v=m.derivePath(r),f=m.derivePath(e);if(!v.privateKey||!f.privateKey)throw new Error("Failed to generate private keys.");return new c(v.privateKey,f.privateKey,t)}async signMessage(i){const r=n(i.message),e=this.getSigningKey(i.chain);return Buffer.from(h(await f(r,e)))}getSigningKey(i){return"C"===i?this.privKeyC:this.privKeyXP}async signTx(i){return await r({unsignedTx:i.tx,privateKeys:[this.privKeyC,this.privKeyXP]}),i.tx}async signTxBuffer(i){const r=this.getSigningKey(i.chain);return[Buffer.from(await v(i.buffer,r))]}}export{c as StaticSigner};
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"@avalabs/core-chains-sdk";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:v}=e,{addChecksum:c}=t;class u 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),v=m.derivePath(t);if(!l.privateKey||!v.privateKey)throw new Error("Failed to generate private keys.");return new u(l.privateKey,v.privateKey,r)}async signMessage(i){const e=o(i.message),t=this.getSigningKey(i.chain);return Buffer.from(c(await v(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{u 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.
@@ -48,8 +49,12 @@ declare abstract class WalletAbstract {
48
49
  * @param source What is the source chain of the atomic UTXOs
49
50
  */
50
51
  getAtomicUTXOs(chain: ChainIDAlias, source: ChainIDAlias): Promise<utils.UtxoSet>;
52
+ /**
53
+ * Get the nonce of this wallet's C chain address
54
+ */
55
+ getNonce(): Promise<number>;
51
56
  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;
57
+ importP({ utxoSet, sourceChain, toAddress, threshold, feeState, locktime, }: ImportP): Common.UnsignedTx;
53
58
  importX(utxos: utils.UtxoSet, sourceChain: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
54
59
  /**
55
60
  *
@@ -69,10 +74,6 @@ declare abstract class WalletAbstract {
69
74
  * @param toAddress
70
75
  */
71
76
  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
  /**
77
78
  * Export the given amount of AVAX from the P chain. Export fee is automatically added.
78
79
  * @param amount
@@ -80,18 +81,17 @@ declare abstract class WalletAbstract {
80
81
  * @param destination
81
82
  * @param toAddress
82
83
  */
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;
84
+ exportP({ amount, utxoSet, destination, feeState, toAddress }: ExportP): Common.UnsignedTx;
85
+ consolidateP({ utxoSet, amount, feeState, toAddress, options, }: ConsolidateP): Common.UnsignedTx;
86
+ baseTX({ utxoSet, chain, toAddress, amountsPerAsset, feeState, options, fromAddresses, }: BaseTx): Common.UnsignedTx;
87
+ convertSubnetToL1({ utxoSet, chainId, subnetId, subnetAuth, feeState, address, validators, options, fromAddresses, }: ConvertSubnetToL1): Common.UnsignedTx;
88
+ registerL1Validator({ utxoSet, balance, signature, message, feeState, fromAddresses, options, }: RegisterL1Validator): Common.UnsignedTx;
89
+ setL1ValidatorWeight({ utxoSet, feeState, message, options, fromAddresses, }: SetL1ValidatorWeight): Common.UnsignedTx;
90
+ disableL1Validator({ utxoSet, feeState, options, fromAddresses, disableAuth, validationId, }: DisableL1Validator): Common.UnsignedTx;
91
+ increaseL1ValidatorBalance({ utxoSet, feeState, options, fromAddresses, balance, validationId, }: IncreaseL1ValidatorBalance): Common.UnsignedTx;
92
+ createBlockchain({ utxoSet, subnetId, chainName, vmID, fxIds, genesisData, subnetAuth, feeState, options, fromAddresses, }: CreateChain): Common.UnsignedTx;
93
+ createSubnet({ utxoSet, rewardAddresses, feeState, fromAddresses, options, threshold, locktime, }: CreateSubnet): Common.UnsignedTx;
94
+ addSubnetValidator({ utxoSet, nodeId, start, end, weight, subnetId, subnetAuth, feeState, fromAddresses, options, }: AddSubnetValidator): Common.UnsignedTx;
95
95
  /**
96
96
  *
97
97
  * @param utxoSet The transaction will be constructed from these UTXOs.
@@ -108,7 +108,7 @@ declare abstract class WalletAbstract {
108
108
  * @param signature the BLS signature, If the subnet is the primary network. Can be found in the Node on startup.
109
109
  * @param options
110
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;
111
+ addPermissionlessValidator({ utxoSet, nodeId, start, end, weight, subnetId, shares, feeState, fromAddresses, rewardAddresses, delegatorRewardAddresses, publicKey, signature, options, threshold, locktime, stakingAssetId, }: AddPermissionlessValidator): Common.UnsignedTx;
112
112
  /**
113
113
  *
114
114
  * @param utxoSet The transaction will be constructed from these UTXOs.
@@ -121,10 +121,9 @@ declare abstract class WalletAbstract {
121
121
  * @param rewardAddresses Will use active address if not provided. Given addresses will share the reward UTXO.
122
122
  * @param options
123
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;
124
+ addPermissionlessDelegator({ utxoSet, nodeId, start, end, weight, subnetId, fromAddresses, rewardAddresses, options, locktime, feeState, threshold, stakingAssetId, }: AddPermissionlessDelegator): Common.UnsignedTx;
125
+ removeSubnetValidator({ utxoSet, nodeId, subnetId, subnetAuth, fromAddresses, feeState, options, }: RemoveSubnetValidator): Common.UnsignedTx;
126
+ transferSubnetOwnershipTx({ utxoSet, subnetId, subnetAuth, subnetOwners, feeState, fromAddresses, options, threshold, locktime, }: TransferSubnetOwnershipTx): Common.UnsignedTx;
128
127
  protected constructor(provider: AbstractProvider);
129
128
  }
130
129
 
@@ -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"@avalabs/core-chains-sdk";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:[]})}async getNonce(){const e=this.getAddressEVM();return await this.provider.evmRpc.getTransactionCount(e)}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])),w=(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 P=f(this.getChangeAddress("P"))[2],B=l?.changeAddresses??[P];return p(a),d.newAddPermissionlessValidatorTx({fromAddressesBytes:S,delegatorRewardsOwner:w,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 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/core-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};
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"@avalabs/core-chains-sdk";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};
@@ -1 +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/core-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};
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"@avalabs/core-chains-sdk";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:h}=o;class u extends t{constructor(t,r,e,i,s){const a=o.strip0x(p.computePublicKey(t,!0)),h=o.strip0x(p.computePublicKey(e,!0));if(super(Buffer.from(a,"hex"),Buffer.from(h,"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),c=await a.getAddress(i,!1),f=await a.getAddress(e,!1),m=Buffer.from(h(c.publicKey),"hex"),g=Buffer.from(h(f.publicKey),"hex"),l=Buffer.from(h(p.computePublicKey(m,!0)),"hex"),d=Buffer.from(h(p.computePublicKey(g,!0)),"hex");return new u(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{u as LedgerSigner};
@@ -1 +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/core-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};
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"@avalabs/core-chains-sdk";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'/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{g as SimpleLedgerSigner};
@@ -34,4 +34,4 @@ interface LedgerProvider {
34
34
  }
35
35
  type LedgerProviderType = 'obsidian' | 'zondax';
36
36
 
37
- export { LedgerProvider, LedgerProviderType };
37
+ export type { LedgerProvider, LedgerProviderType };
@@ -1 +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};
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 i}from"@avalabs/avalanchejs";import"hdkey";import{DerivationPath as n}from"../../../EVM/constants.js";import{fromPublicKey as o}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}=i;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),[,,i]=c(s);return Buffer.from(i).toString("hex")}))}static async fromTransport(r,i){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=o(m.pubKey,m.chainCode),h=s(0,n.BIP44,"EVM"),u=await d.getAddress(h,!1),l=e.computePublicKey(Buffer.from(u.publicKey,"hex"),!0),w=Buffer.from(a(l),"hex");return new g(c.toBase58(),w,i)}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"))),i=this.getExternalRawAddresses().map((r=>r.toString("hex"))),n=new Set([...s,...e??[]]),o=new Set([...i,...t??[]]),a=new Set;return r.forEach((r=>{const t=r.toString("hex");if(n.has(t)){const r=[...n].indexOf(t);a.add(`1/${r}`)}else if(o.has(t)){const r=[...o].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,i=t.getVM(),n=Buffer.from(t.toBytes()),o="EVM"===i?"C":"X",a=t.getAddresses().map((r=>Buffer.from(r))),p=this.getAdditionalAddressesByIndices(e??[],!1,o),f=this.getAdditionalAddressesByIndices(s??[],!0,o),c=[...this.filterOwnedAddresses(a,p,f).values()].map((r=>d.fromString(r))),g=[...m(t)].map((r=>Buffer.from(r))),h=[...this.filterOwnedAddresses(g).values()].map((r=>d.fromString(r)));return(await this.signTxBuffer({buffer:n,chain:o,transport:r.transport,signers:c,change:h})).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};
@@ -1 +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};
1
+ import{MnemonicWalletVoid as e}from"./MnemonicWalletVoid.js";import{utils as t,addTxSignatures 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 c}from"../../../utils/getAddressDerivationPath.js";import"hdkey";import{DerivationPath as h}from"../../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";const{strip0x:p}=t;class v extends e{constructor(e,t,r){const i=o(e).neutered(),n=new a(t),s=Buffer.from(p(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'"),p=o.derivePath(c(0,h.BIP44,"EVM"));if(!p.privateKey)throw new Error("Unable to derive EVM private key.");return new v(a.toBase58(),p.privateKey,t)}async signTx(e){const t=this.getSigningKeys(e);return await r({unsignedTx:e.tx,privateKeys:t}),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{v as MnemonicWallet};
@@ -1 +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};
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{DerivationPath as o}from"../../../EVM/constants.js";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};
@@ -32,4 +32,4 @@ interface LedgerGetXpubResponse {
32
32
  chain_code: Buffer;
33
33
  }
34
34
 
35
- export { LedgerGetXpubResponse, SignMessageRequest, SignTxBufferRequest, SignTxRequest, Signer };
35
+ export type { LedgerGetXpubResponse, SignMessageRequest, SignTxBufferRequest, SignTxRequest, Signer };
@@ -0,0 +1,5 @@
1
+ import { networks } from 'bitcoinjs-lib';
2
+
3
+ declare const BtcNetworks: typeof networks;
4
+
5
+ export { BtcNetworks };
@@ -0,0 +1 @@
1
+ import{networks as r}from"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import"@solana/kit";import"@solana-program/system";import"@solana-program/token";import"@ledgerhq/hw-app-solana";import"bip39";import"@noble/curves/ed25519";import"@scure/base";import"micro-key-producer/slip10.js";import"@avalabs/avalanchejs";import"hdkey";import"bip32";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"ledger-bitcoin";import"@ledgerhq/hw-app-btc/lib/bip32";const o=r;export{o as BtcNetworks};
@@ -74,4 +74,4 @@ interface BitcoinTx {
74
74
  }[];
75
75
  }
76
76
 
77
- export { BitcoinHistoryTx, BitcoinInputUTXO, BitcoinInputUTXOWithOptionalScript, BitcoinLedgerInputUTXO, BitcoinOutputUTXO, BitcoinTx };
77
+ export type { BitcoinHistoryTx, BitcoinInputUTXO, BitcoinInputUTXOWithOptionalScript, BitcoinLedgerInputUTXO, BitcoinOutputUTXO, BitcoinTx };
@@ -8,11 +8,12 @@ declare class BitcoinProvider extends BitcoinProviderAbstract {
8
8
  private readonly extraParams?;
9
9
  constructor(isMainnet?: boolean, apiKey?: string, explorerUrl?: string, nodeUrl?: string, extraParams?: Record<string, string> | undefined);
10
10
  getTxHex(txHash: string): Promise<string>;
11
- getUTXOs(address: string, withScripts?: boolean): Promise<{
11
+ getUTXOs(address: string, withScripts?: boolean, skipBatch?: boolean): Promise<{
12
12
  confirmed: BitcoinInputUTXOWithOptionalScript[];
13
13
  unconfirmed: BitcoinInputUTXOWithOptionalScript[];
14
14
  }>;
15
- getScriptsForUtxos(utxos: BitcoinInputUTXOWithOptionalScript[]): Promise<BitcoinInputUTXO[]>;
15
+ getAddressFromScript(script: string): Promise<string>;
16
+ getScriptsForUtxos(utxos: BitcoinInputUTXOWithOptionalScript[], skipBatch?: boolean): Promise<BitcoinInputUTXO[]>;
16
17
  private _parseUtxo;
17
18
  getBalances(address: string): Promise<{
18
19
  available: bigint;
@@ -20,7 +21,7 @@ declare class BitcoinProvider extends BitcoinProviderAbstract {
20
21
  final: bigint;
21
22
  }>;
22
23
  getChainHeight(): Promise<number>;
23
- getFeeRates(): Promise<{
24
+ getFeeRates(skipBatch?: boolean): Promise<{
24
25
  low: number;
25
26
  medium: number;
26
27
  high: number;