@avalabs/core-wallets-sdk 3.1.0-canary.de02ccd.0 → 3.1.0-canary.de092aa1

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 (61) hide show
  1. package/dist/index.cjs +1 -1
  2. package/dist/index.d.ts +201 -51
  3. package/esm/Avalanche/index.d.ts +3 -1
  4. package/esm/Avalanche/index.js +1 -1
  5. package/esm/Avalanche/models.d.ts +28 -3
  6. package/esm/Avalanche/models.js +1 -1
  7. package/esm/Avalanche/providers/AbstractProvider.d.ts +2 -8
  8. package/esm/Avalanche/providers/AbstractProvider.js +1 -1
  9. package/esm/Avalanche/providers/JsonRpcProvider.d.ts +4 -4
  10. package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
  11. package/esm/Avalanche/utils/appendAutoRenewedValidatorConfigAddressMaps.js +1 -0
  12. package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.d.ts +3 -2
  13. package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.js +1 -1
  14. package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
  15. package/esm/Avalanche/utils/getAvalancheDerivationPath.d.ts +3 -0
  16. package/esm/Avalanche/utils/getAvalancheDerivationPath.js +1 -0
  17. package/esm/Avalanche/utils/getPchainUnixNow.d.ts +3 -1
  18. package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
  19. package/esm/Avalanche/utils/getVmByChainAlias.d.ts +1 -1
  20. package/esm/Avalanche/utils/getXpubFromMnemonic.d.ts +1 -1
  21. package/esm/Avalanche/utils/getXpubFromMnemonic.js +1 -1
  22. package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
  23. package/esm/Avalanche/utils/parsers/index.js +1 -1
  24. package/esm/Avalanche/utils/parsers/parseAddAutoRenewedValidatorTx.js +1 -0
  25. package/esm/Avalanche/utils/parsers/parseSetAutoRenewedValidatorConfigTx.js +1 -0
  26. package/esm/Avalanche/wallets/AddressWallet.js +1 -1
  27. package/esm/Avalanche/wallets/SimpleSigner.d.ts +1 -1
  28. package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
  29. package/esm/Avalanche/wallets/StaticSigner.js +1 -1
  30. package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +61 -1
  31. package/esm/Avalanche/wallets/WalletAbstract.d.ts +23 -25
  32. package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
  33. package/esm/Avalanche/wallets/WalletVoid.js +1 -1
  34. package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.d.ts +16 -0
  35. package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.js +1 -0
  36. package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
  37. package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.d.ts +4 -2
  38. package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
  39. package/esm/Avalanche/wallets/legacy/LedgerWallet.js +1 -1
  40. package/esm/Avalanche/wallets/legacy/MnemonicWallet.js +1 -1
  41. package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.js +1 -1
  42. package/esm/BitcoinVM/index.js +1 -1
  43. package/esm/BitcoinVM/utils/getBech32AddressFromXPub.js +1 -1
  44. package/esm/BitcoinVM/wallets/BitcoinWallet.js +1 -1
  45. package/esm/BitcoinVM/wallets/BitcoinWalletLedger.js +1 -1
  46. package/esm/EVM/LedgerSigner.js +1 -1
  47. package/esm/EVM/utils/getEvmDerivationPath.d.ts +5 -0
  48. package/esm/EVM/utils/getEvmDerivationPath.js +1 -0
  49. package/esm/EVM/utils/getWalletFromMnemonic.js +1 -1
  50. package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.d.ts +40 -0
  51. package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.js +1 -0
  52. package/esm/SolanaVM/utils/resolveTokenProgramForMint.d.ts +13 -0
  53. package/esm/SolanaVM/utils/resolveTokenProgramForMint.js +1 -0
  54. package/esm/SolanaVM/utils/transferToken.js +1 -1
  55. package/esm/SolanaVM/wallets/SolanaLedgerSigner.js +1 -1
  56. package/esm/index.d.ts +3 -0
  57. package/esm/index.js +1 -1
  58. package/esm/utils/getAddressDerivationPath.d.ts +8 -5
  59. package/esm/utils/getAddressDerivationPath.js +1 -1
  60. package/esm/utils/getPubKeyFromTransport.js +1 -1
  61. package/package.json +17 -12
@@ -1 +1 @@
1
- import{utils as t,secp256k1 as e,networkIDs as s,avm as r,pvm as i,evm as n,info as c}from"@avalabs/avalanchejs";import{strip0x as a}from"@avalabs/core-utils-sdk";import{signedTxToHex as o}from"../utils/signedTxToHex.js";import{JsonRpcProvider as u,SigningKey as h}from"ethers";const{parseBech32:p,format:g}=t,{publicKeyBytesToAddress:A}=e;class x{constructor(t,e){this.baseUrl=t,this.context=e;const s=`${t}/ext/bc/C/rpc`;this.evmRpc=new u(s)}evmRpc;async getEvmFeeData(){return this.evmRpc.getFeeData()}getContext(){return this.context}getChainID(t){switch(t){case"X":return this.context.xBlockchainID;case"P":return this.context.pBlockchainID;case"C":return this.context.cBlockchainID}}getNetworkID(){return this.context.networkID}getHrp(){return s.getHRP(this.getNetworkID())}getApiX(){return new r.AVMApi(this.baseUrl)}getApiP(){return new i.PVMApi(this.baseUrl)}getApiC(){return new n.EVMApi(this.baseUrl)}getInfo(){return new c.InfoApi(this.baseUrl)}getApi(t){switch(t){case"X":return this.getApiX();case"P":return this.getApiP();case"C":return this.getApiC()}}getAvaxID(){return this.getContext().avaxAssetID}getAddress(t,e){const s=a(h.computePublicKey(t,!0)),r=Buffer.from(s,"hex"),i=A(r);return g(e,this.getHrp(),i)}getAddressFromBuffer(t,e){return g(e,this.getHrp(),t)}formatAddress(t,e){const[,s]=p(t);return g(e,this.getHrp(),s)}getApiByVM(t){switch(t){case"AVM":return this.getApiX();case"PVM":return this.getApiP();case"EVM":return this.getApiC()}}getApiByChainID(t){switch(t){case this.context.xBlockchainID:return this.getApiX();case this.context.pBlockchainID:return this.getApiP();case this.context.cBlockchainID:return this.getApiC()}}async issueTx(t){const e=t.unsignedTx.getVM(),s=o(t);return this.issueTxHex(s,e)}async issueTxHex(t,e){return this.getApiByVM(e).issueTx({tx:t})}async waitForTransaction(t,e,s=6e4){const r=this.getApiByVM(e),i=Date.now();return new Promise(((e,c)=>{const a=async()=>{let o;switch(s&&i+s<Date.now()&&c(new Error("Timeout")),o=r instanceof n.EVMApi?await r.getAtomicTxStatus(t):await r.getTxStatus({txID:t,includeReason:!0}),o.status){case"Accepted":case"Committed":return void e({success:!0});case"Dropped":case"Rejected":return void e({success:!1});default:setTimeout((()=>{a()}),1e3)}};a()}))}}export{x as AbstractProvider};
1
+ import{utils as t,secp256k1 as e,networkIDs as s,avm as i,pvm as r,evm as n,info as c}from"@avalabs/avalanchejs";import{strip0x as o}from"@avalabs/core-utils-sdk";import{signedTxToHex as h}from"../utils/signedTxToHex.js";import{SigningKey as a}from"ethers";const{parseBech32:p,format:u}=t,{publicKeyBytesToAddress:g}=e;class A{constructor(t,e,s){this.baseUrl=t,this.context=e,this.fetchOptions=s}getContext(){return this.context}getChainID(t){switch(t){case"X":return this.context.xBlockchainID;case"P":return this.context.pBlockchainID;case"C":return this.context.cBlockchainID}}getNetworkID(){return this.context.networkID}getHrp(){return s.getHRP(this.getNetworkID())}getApiX(){const t=new i.AVMApi(this.baseUrl);return this.fetchOptions&&t.setFetchOptions(this.fetchOptions),t}getApiP(){const t=new r.PVMApi(this.baseUrl);return this.fetchOptions&&t.setFetchOptions(this.fetchOptions),t}getApiC(){const t=new n.EVMApi(this.baseUrl);return this.fetchOptions&&t.setFetchOptions(this.fetchOptions),t}getInfo(){const t=new c.InfoApi(this.baseUrl);return this.fetchOptions&&t.setFetchOptions(this.fetchOptions),t}getApi(t){switch(t){case"X":return this.getApiX();case"P":return this.getApiP();case"C":return this.getApiC()}}getAvaxID(){return this.getContext().avaxAssetID}getAddress(t,e){const s=o(a.computePublicKey(t,!0)),i=Buffer.from(s,"hex"),r=g(i);return u(e,this.getHrp(),r)}getAddressFromBuffer(t,e){return u(e,this.getHrp(),t)}formatAddress(t,e){const[,s]=p(t);return u(e,this.getHrp(),s)}getApiByVM(t){switch(t){case"AVM":return this.getApiX();case"PVM":return this.getApiP();case"EVM":return this.getApiC()}}getApiByChainID(t){switch(t){case this.context.xBlockchainID:return this.getApiX();case this.context.pBlockchainID:return this.getApiP();case this.context.cBlockchainID:return this.getApiC()}}async issueTx(t){const e=t.unsignedTx.getVM(),s=h(t);return this.issueTxHex(s,e)}async issueTxHex(t,e){return this.getApiByVM(e).issueTx({tx:t})}async waitForTransaction(t,e,s=6e4){const i=this.getApiByVM(e),r=Date.now();return new Promise(((e,c)=>{const o=async()=>{let h;switch(s&&r+s<Date.now()&&c(new Error("Timeout")),h=i instanceof n.EVMApi?await i.getAtomicTxStatus(t):await i.getTxStatus({txID:t,includeReason:!0}),h.status){case"Accepted":case"Committed":return void e({success:!0});case"Dropped":case"Rejected":return void e({success:!1});default:setTimeout((()=>{o()}),1e3)}};o()}))}}export{A as AbstractProvider};
@@ -2,11 +2,11 @@ import { AbstractProvider } from './AbstractProvider.js';
2
2
  import { Context } from '@avalabs/avalanchejs';
3
3
 
4
4
  declare class JsonRpcProvider extends AbstractProvider {
5
- constructor(baseUrl: string, context: Context.Context);
5
+ constructor(baseUrl: string, context: Context.Context, fetchOptions?: RequestInit);
6
6
  static fromBaseURL(url: string): Promise<JsonRpcProvider>;
7
- static getDefaultMainnetProvider(): JsonRpcProvider;
8
- static getDefaultFujiProvider(): JsonRpcProvider;
9
- static getDefaultDevnetProvider(): JsonRpcProvider;
7
+ static getDefaultMainnetProvider(fetchOptions?: RequestInit): JsonRpcProvider;
8
+ static getDefaultFujiProvider(fetchOptions?: RequestInit): JsonRpcProvider;
9
+ static getDefaultDevnetProvider(fetchOptions?: RequestInit): JsonRpcProvider;
10
10
  }
11
11
 
12
12
  export { JsonRpcProvider };
@@ -1 +1 @@
1
- import{AbstractProvider as r}from"./AbstractProvider.js";import{Context as t,info as e}from"@avalabs/avalanchejs";import{MainnetContext as a,FujiContext as n,DevnetContext as o}from"./constants.js";import{AVALANCHE_XP_NETWORK as s,AVALANCHE_XP_TEST_NETWORK as c,AVALANCHE_P_DEV_NETWORK as i}from"@avalabs/core-chains-sdk";class p extends r{constructor(r,t){super(r,t)}static async fromBaseURL(r){const a=await t.getContextFromURI(r);try{await new e.InfoApi(r).getUpgradesInfo();return new p(r,a)}catch{return new p(r,a)}}static getDefaultMainnetProvider(){return new p(s.rpcUrl,a)}static getDefaultFujiProvider(){return new p(c.rpcUrl,n)}static getDefaultDevnetProvider(){return new p(i.rpcUrl,o)}}export{p as JsonRpcProvider};
1
+ import{AbstractProvider as r}from"./AbstractProvider.js";import{Context as t}from"@avalabs/avalanchejs";import{MainnetContext as e,FujiContext as a,DevnetContext as n}from"./constants.js";import{AVALANCHE_XP_NETWORK as s,AVALANCHE_XP_TEST_NETWORK as o,AVALANCHE_P_DEV_NETWORK as c}from"@avalabs/core-chains-sdk";class i extends r{constructor(r,t,e){super(r,t,e)}static async fromBaseURL(r){const e=await t.getContextFromURI(r);try{return new i(r,e)}catch{return new i(r,e)}}static getDefaultMainnetProvider(r){return new i(s.rpcUrl,e,r)}static getDefaultFujiProvider(r){return new i(o.rpcUrl,a,r)}static getDefaultDevnetProvider(r){return new i(c.rpcUrl,n,r)}}export{i as JsonRpcProvider};
@@ -0,0 +1 @@
1
+ import{pvmSerial as e,utils as a}from"@avalabs/avalanchejs";async function t(t,r,n){try{const o=(await n.getApiP().getTx({txID:r.txId.value()})).unsignedTx;if(!e.isAddAutoRenewedValidatorTx(o))throw new Error("Referenced validator transaction is not an AddAutoRenewedValidatorTx");const d=o.getValidatorAuthority().addrs,i=r.getAuth().values(),s=d.reduce(((e,a,t)=>(i.includes(t)&&e.push([a,t]),e)),[]);return t.push(new a.AddressMap(s)),t}catch(e){throw new Error(`Error while preparing auto-renewed validator config auth data: ${e.message}`)}}export{t as appendAutoRenewedValidatorConfigAddressMaps};
@@ -1,11 +1,12 @@
1
- import { VM, Utxo, UnsignedTx } from '@avalabs/avalanchejs';
1
+ import { VM, Credential, Utxo, UnsignedTx } from '@avalabs/avalanchejs';
2
2
 
3
3
  type Params = {
4
4
  txBytes: Uint8Array;
5
5
  fromAddress: string;
6
6
  vm: VM;
7
+ credentials?: Credential[];
7
8
  utxos: Utxo[];
8
9
  };
9
- declare const createAvalancheEvmUnsignedTx: ({ txBytes, fromAddress, vm, utxos, }: Params) => Promise<UnsignedTx>;
10
+ declare const createAvalancheEvmUnsignedTx: ({ txBytes, fromAddress, vm, credentials, utxos, }: Params) => Promise<UnsignedTx>;
10
11
 
11
12
  export { createAvalancheEvmUnsignedTx };
@@ -1 +1 @@
1
- import{utils as r,evmSerial as e,EVMUnsignedTx as t,UnsignedTx as s}from"@avalabs/avalanchejs";const{unpackWithManager:n,parse:o,bufferToHex:a,AddressMaps:p,AddressMap:f}=r,i=async({txBytes:r,fromAddress:i,vm:m,utxos:d})=>{const u=n(m,r),c=o(i)[2],x=a(c);if(e.isExportTx(u))return new t(u,[],new p([f.fromJSON([[x,0]])]));if(e.isImportTx(u)){const r=p.fromTransferableInputs(u.importedInputs,d,BigInt(Math.floor((new Date).getTime()/1e3)),[c]);return new s(u,d,r)}throw new Error("Unsupported transaction type")};export{i as createAvalancheEvmUnsignedTx};
1
+ import{utils as r,evmSerial as e,EVMUnsignedTx as t,UnsignedTx as s}from"@avalabs/avalanchejs";const{unpackWithManager:n,parse:a,bufferToHex:o,AddressMaps:p,AddressMap:i}=r,f=async({txBytes:r,fromAddress:f,vm:d,credentials:m,utxos:c})=>{const u=n(d,r),x=a(f)[2],w=o(x);if(e.isExportTx(u))return new t(u,[],new p([i.fromJSON([[w,0]])]),m);if(e.isImportTx(u)){const r=p.fromTransferableInputs(u.importedInputs,c,BigInt(Math.floor((new Date).getTime()/1e3)),[x]);return new s(u,c,r,m)}throw new Error("Unsupported transaction type")};export{f as createAvalancheEvmUnsignedTx};
@@ -1 +1 @@
1
- import{utils as e,UnsignedTx as r,pvmSerial as a}from"@avalabs/avalanchejs";import{isSubnetTx as t,handleSubnetAuth as s}from"./handleSubnetAuth.js";import{appendDisableAuthAddressMaps as n}from"./appendDisableAuthAddressMaps.js";const{getTransferableInputsByTx:o,AddressMaps:i}=e,d=async({tx:e,fromAddressBytes:d,provider:p,credentials:l,utxos:u})=>{const f=o(e);let m=i.fromTransferableInputs(f,u,BigInt(Math.floor((new Date).getTime()/1e3)),d);if(t(e))try{const a=await s({tx:e,provider:p,addressMaps:m});return new r(e,u,a,l)}catch(e){throw new Error(`Error while preparing subnet authorization data: ${e.message}`)}else a.isDisableL1ValidatorTx(e)&&(m=await n(m,e,p));return new r(e,u,m,l)};var p=d;export{d as createAvalancheUnsignedTx,p as default};
1
+ import{utils as e,UnsignedTx as a,pvmSerial as r}from"@avalabs/avalanchejs";import{isSubnetTx as t,handleSubnetAuth as s}from"./handleSubnetAuth.js";import{appendDisableAuthAddressMaps as o}from"./appendDisableAuthAddressMaps.js";import{appendAutoRenewedValidatorConfigAddressMaps as n}from"./appendAutoRenewedValidatorConfigAddressMaps.js";const{getTransferableInputsByTx:i,AddressMaps:d}=e,p=async({tx:e,fromAddressBytes:p,provider:l,credentials:f,utxos:u})=>{const m=i(e);let w=d.fromTransferableInputs(m,u,BigInt(Math.floor((new Date).getTime()/1e3)),p);if(t(e))try{const r=await s({tx:e,provider:l,addressMaps:w});return new a(e,u,r,f)}catch(e){throw new Error(`Error while preparing subnet authorization data: ${e.message}`)}else r.isDisableL1ValidatorTx(e)?w=await o(w,e,l):r.isSetAutoRenewedValidatorConfigTx(e)&&(w=await n(w,e,l));return new a(e,u,w,f)};var l=p;export{p as createAvalancheUnsignedTx,l as default};
@@ -0,0 +1,3 @@
1
+ declare const getAvalancheDerivationPath: (accountIndex: number, withRoot?: boolean) => string;
2
+
3
+ export { getAvalancheDerivationPath };
@@ -0,0 +1 @@
1
+ const o=(o,t=!0)=>`${t?"m/":""}44'/9000'/${o}'/0/0`;export{o as getAvalancheDerivationPath};
@@ -1,6 +1,8 @@
1
+ import { AbstractProvider } from '../providers/AbstractProvider.js';
2
+
1
3
  /**
2
4
  * Get the current p-chain timestamp in unix
3
5
  */
4
- declare function getPchainUnixNow(isTestnet: boolean): Promise<bigint>;
6
+ declare function getPchainUnixNow(provider: AbstractProvider): Promise<bigint>;
5
7
 
6
8
  export { getPchainUnixNow };
@@ -1 +1 @@
1
- import{AVALANCHE_XP_TEST_NETWORK as a,AVALANCHE_XP_NETWORK as t}from"@avalabs/core-chains-sdk";import{pvm as e}from"@avalabs/avalanchejs";async function r(r){const i=r?a.rpcUrl:t.rpcUrl,n=await new e.PVMApi(i).getTimestamp(),o=new Date(n.timestamp),m=Math.floor(o.getTime()/1e3);return BigInt(m)}export{r as getPchainUnixNow};
1
+ async function t(t){const e=await t.getApiP().getTimestamp(),a=new Date(e.timestamp),i=Math.floor(a.getTime()/1e3);return BigInt(i)}export{t as getPchainUnixNow};
@@ -1,3 +1,3 @@
1
- declare const getVmByChainAlias: (chainAlias: string) => "EVM" | "AVM" | "PVM";
1
+ declare const getVmByChainAlias: (chainAlias: string) => "AVM" | "EVM" | "PVM";
2
2
 
3
3
  export { getVmByChainAlias };
@@ -2,6 +2,6 @@
2
2
  * Get the xpub for m/44'/9000'/0' from the given mnemonic
3
3
  * @param mnemonic
4
4
  */
5
- declare function getXpubFromMnemonic(mnemonic: string): string;
5
+ declare function getXpubFromMnemonic(mnemonic: string, accountIndex: number): string;
6
6
 
7
7
  export { getXpubFromMnemonic };
@@ -1 +1 @@
1
- import{validateMnemonic as r,mnemonicToSeedSync as e}from"bip39";import{fromSeed as o}from"bip32";function t(t){if(!r(t))throw new Error("Invalid mnemonic phrase.");const i=e(t);return o(i).derivePath("44'/9000'/0'").neutered().toBase58()}export{t as getXpubFromMnemonic};
1
+ import{validateMnemonic as r,mnemonicToSeedSync as e}from"bip39";import{fromSeed as o}from"bip32";function t(t,i){if(!r(t))throw new Error("Invalid mnemonic phrase.");const n=e(t);return o(n).derivePath(`44'/9000'/${i}'`).neutered().toBase58()}export{t as getXpubFromMnemonic};
@@ -1 +1 @@
1
- import{utils as t,evmSerial as e}from"@avalabs/avalanchejs";import{TxType as n}from"../models.js";import a from"./parsers/index.js";const{getBurnedAmountByTx:o,getOutputAmounts:r,getInputAmounts:s,validateBurnedAmount:i}=t;async function u(t,u,x,{feeTolerance:c=50,baseFee:g}={}){try{const n=u.getContext(),d=t.getTx(),p=(t=>{for(const e of Object.values(a)){const n=e(t);if(null!==n)return n}throw new Error("no parser found for tx")})(d),A=o(d,n),l=r(d),m=s(d).get(n.avaxAssetID)??BigInt(0),v=A.get(n.avaxAssetID)??BigInt(0),I=l.get(n.avaxAssetID)??BigInt(0);let f=g;void 0===f&&(f=0n,e.isImportExportTx(d)?(f=await u.getApiC().getBaseFee()/BigInt(1e9),0n===f&&(f=1n)):"PVM"===d.vm&&(f=await u.getApiP().getFeeState().then((t=>t.price)).catch((()=>BigInt(0)))));const{isValid:B,txFee:F}=i({unsignedTx:t,context:n,burnedAmount:v,baseFee:f,feeTolerance:c});return await p({feeData:{totalAvaxBurned:v,totalAvaxOutput:I,totalAvaxInput:m,isValidAvaxBurnedAmount:B,txFee:F,baseFee:f},assetId:n.avaxAssetID,provider:u,currentAddress:x})}catch(t){return{type:n.Unknown}}}export{u as parseAvalancheTx};
1
+ import{utils as t,evmSerial as e}from"@avalabs/avalanchejs";import a from"./parsers/index.js";const{getBurnedAmountByTx:n,getOutputAmounts:o,getInputAmounts:s,validateBurnedAmount:r}=t;async function i(t,i,u,{feeTolerance:x=50,baseFee:g}={}){const A=i.getContext(),c=t.getTx(),d=(t=>{for(const e of Object.values(a)){const a=e(t);if(null!==a)return a}throw new Error("no parser found for tx")})(c),p=n(c,A),v=o(c),l=s(c).get(A.avaxAssetID)??BigInt(0),I=p.get(A.avaxAssetID)??BigInt(0),m=v.get(A.avaxAssetID)??BigInt(0);let f=g;void 0===f&&(f=0n,e.isImportExportTx(c)?(f=await i.getApiC().getBaseFee()/BigInt(1e9),0n===f&&(f=1n)):"PVM"===c.vm&&(f=await i.getApiP().getFeeState().then((t=>t.price)).catch((()=>BigInt(0)))));const{isValid:B,txFee:F}=r({unsignedTx:t,context:A,burnedAmount:I,baseFee:f,feeTolerance:x});return await d({feeData:{totalAvaxBurned:I,totalAvaxOutput:m,totalAvaxInput:l,isValidAvaxBurnedAmount:B,txFee:F,baseFee:f},assetId:A.avaxAssetID,provider:i,currentAddress:u})}export{i as parseAvalancheTx};
@@ -1 +1 @@
1
- import r from"./parseCreateSubnetTx.js";import e from"./parseCreateChainTx.js";import a from"./parseAddSubnetValidorTx.js";import s from"./parseImportTx.js";import o from"./parseExportTx.js";import t from"./parseBaseTx.js";import p from"./parseAddPermissionlessValidatorTx.js";import i from"./parseAddPermissionlessDelegatorTx.js";import m from"./parseRemoveSubnetValidatorTx.js";import x from"./parseTransferSubnetOwnershipTx.js";import T from"./parseConvertSubnetToL1Tx.js";import d from"./parseRegisterL1ValidatorTx.js";import n from"./parseSetL1ValidatorWeightTx.js";import l from"./parseDisableL1ValidatorTx.js";import f from"./parseIncreaseL1ValidatorBalanceTx.js";var j={parseCreateSubnetTx:r,parseCreateChainTx:e,parseAddSubnetValidatorTx:a,parseRemoveSubnetValidatorTx:m,parseImportTx:s,parseExportTx:o,parseBaseTx:t,parseAddPermissionlessValidatorTx:p,parseAddPermissionlessDelegatorTx:i,parseTransferSubnetOwnershipTx:x,parseConvertSubnetTx:T,parseRegisterL1ValidatorTx:d,parseIncreaseL1ValidatorBalanceTx:f,parseSetL1ValidatorWeightTx:n,parseDisableL1ValidatorTx:l};export{j as default};
1
+ import r from"./parseCreateSubnetTx.js";import e from"./parseCreateChainTx.js";import a from"./parseAddSubnetValidorTx.js";import s from"./parseImportTx.js";import o from"./parseExportTx.js";import t from"./parseBaseTx.js";import p from"./parseAddPermissionlessValidatorTx.js";import i from"./parseAddPermissionlessDelegatorTx.js";import m from"./parseRemoveSubnetValidatorTx.js";import d from"./parseTransferSubnetOwnershipTx.js";import x from"./parseConvertSubnetToL1Tx.js";import T from"./parseRegisterL1ValidatorTx.js";import n from"./parseSetL1ValidatorWeightTx.js";import l from"./parseDisableL1ValidatorTx.js";import f from"./parseIncreaseL1ValidatorBalanceTx.js";import V from"./parseAddAutoRenewedValidatorTx.js";import j from"./parseSetAutoRenewedValidatorConfigTx.js";var u={parseCreateSubnetTx:r,parseCreateChainTx:e,parseAddSubnetValidatorTx:a,parseRemoveSubnetValidatorTx:m,parseImportTx:s,parseExportTx:o,parseBaseTx:t,parseAddPermissionlessValidatorTx:p,parseAddPermissionlessDelegatorTx:i,parseTransferSubnetOwnershipTx:d,parseConvertSubnetTx:x,parseRegisterL1ValidatorTx:T,parseIncreaseL1ValidatorBalanceTx:f,parseSetL1ValidatorWeightTx:n,parseDisableL1ValidatorTx:l,parseAddAutoRenewedValidatorTx:V,parseSetAutoRenewedValidatorConfigTx:j};export{u as default};
@@ -0,0 +1 @@
1
+ import{pvmSerial as e,utils as a}from"@avalabs/avalanchejs";import{TxType as r}from"../../models.js";var o=o=>{if(!e.isAddAutoRenewedValidatorTx(o))return null;let t,n;e.isSigner(o.signer)&&(n=a.bufferToHex(o.signer.proof.publicKey),t=a.bufferToHex(o.signer.proof.signature));const d=o.stake.reduce(((e,a)=>e+a.amount()),0n);return({feeData:e})=>({type:r.AddAutoRenewedValidator,chain:o.getVM(),nodeID:o.nodeId.value(),stake:d,stakeOuts:o.stake,rewardOwner:o.getValidatorRewardsOwner(),delegationRewardOwner:o.getDelegatorRewardsOwner(),owner:o.getValidatorAuthority(),delegationFee:o.delegationShares.value(),autoCompoundRewardShares:o.autoCompoundRewardShares.value(),period:o.period.value(),signer:o.signer,publicKey:n,signature:t,...e})};export{o as default};
@@ -0,0 +1 @@
1
+ import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";var o=o=>a.isSetAutoRenewedValidatorConfigTx(o)?({feeData:a})=>({type:e.SetAutoRenewedValidatorConfig,chain:o.getVM(),txId:o.txId.value(),autoCompoundRewardShares:o.autoCompoundRewardShares.value(),period:o.period.value(),...a}):null;export{o as default};
@@ -1 +1 @@
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
+ import{WalletAbstract as s}from"./WalletAbstract.js";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"create-hash";import"bip32";import"@avalabs/avalanchejs";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"bip39";import{isBech32Address as e}from"../utils/isBech32Address.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import"bip32-path";import{isAddress as r}from"ethers";class t extends s{constructor(s,t,i,a,d){if(super(d),this.addressC=s,this.addressCoreEth=t,this.xpAddresses=i,this.xpChangeAddress=a,i.length<1)throw new Error("Must have at least 1 xp address.");if(!r(s))throw new Error("Not a valid C-Chain (EVM) address");if(i.some((s=>!e(s,!1))))throw new Error("Given addresses must be valid avalanche bech32 addresses without the chain alias prefix");if(!e(t,!1))throw new Error("Given CoreEth address must be valid avalanche bech32 addresses without the chain alias prefix");this.setChangeAddress(a)}setChangeAddress(s){if(!e(s,!1))throw new Error("Given address must be valid avalanche bech32 addresses without the chain alias prefix");this.xpChangeAddress=s}getAddressEVM(){return this.addressC}getAddresses(s){return("C"===s?[this.addressCoreEth]:this.xpAddresses).map((e=>this.provider.formatAddress(e,s)))}getChangeAddress(s){const e="C"===s?this.addressCoreEth:this.xpChangeAddress;return this.provider.formatAddress(e,s)}getCurrentAddress(s){const e="C"===s?this.addressCoreEth:this.xpAddresses[0];return this.provider.formatAddress(e,s)}}export{t as AddressWallet};
@@ -10,7 +10,7 @@ import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from '
10
10
  */
11
11
  declare class SimpleSigner implements Signer {
12
12
  /**
13
- * Node for `m/44'/9000'/0'`
13
+ * Node for `m/44'/9000'/n'`
14
14
  * @private {BIP32Interface}
15
15
  */
16
16
  private accountNodeXP;
@@ -1 +1 @@
1
- import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as 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
+ import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import"@ledgerhq/hw-app-eth";import"ethers";import{DerivationPath as n}from"../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{getAddressDerivationPath as o}from"../../utils/getAddressDerivationPath.js";import"hdkey";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../utils/digestMessage.js";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import"bip32-path";class c{accountNodeXP;signerNodeEVM;activeAccountIndex;constructor(e,t){if(!r(e))throw new Error("Invalid mnemonic phrase.");if(t<0||t%1!=0)throw new Error("Invalid account index.");const a=s(e),c=i(a);this.accountNodeXP=c.derivePath(`m/44'/9000'/${t}'`);const p=c.derivePath(o(t,"EVM",{pathSpec:n.BIP44}));this.signerNodeEVM=p,this.activeAccountIndex=t}getAdditionalKeys(e,t){return[...new Set(e??[])].reduce(((e,i)=>{const r=this.accountNodeXP.derivePath(`${t?1:0}/${i}`);if(!r.privateKey)throw new Error("Unable to get private key.");return e.push(r.privateKey),e}),[])}getSigningKeys(e,t,i){if("EVM"===e){if(!this.signerNodeEVM.privateKey)throw new Error("Unable to derive EVM private key.");return[this.signerNodeEVM.privateKey]}const r=this.accountNodeXP.derivePath("0/0");if(!r.privateKey)throw new Error("Unable to derive X/P private key.");const s=this.getAdditionalKeys(t,!1),n=this.getAdditionalKeys(i,!0);return[r.privateKey,...s,...n]}async signTx(t){const{tx:i,externalIndices:r,internalIndices:s}=t,n=i.getVM(),o=this.getSigningKeys(n,r,s);if(!o?.length)throw new Error("Unable to sign transaction: signing keys are missing.");return await e({unsignedTx:i,privateKeys:o}),t.tx}async signTxBuffer(e){throw new Error("Not implemented")}getActiveAccountNode(e){switch(e){case"X":case"P":return this.accountNodeXP.derivePath("0/0");case"C":return this.signerNodeEVM}}async signMessage(e){const i=this.getActiveAccountNode(e.chain);if(!i.privateKey)throw Error("Unable to sign message, key not found.");const r=a(e.message),s=await t.signHash(r,i.privateKey);return Buffer.from(s)}}export{c as SimpleSigner};
@@ -1 +1 @@
1
- import{WalletVoid as i}from"./WalletVoid.js";import{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};
1
+ import{WalletVoid as i}from"./WalletVoid.js";import{secp256k1 as e,utils as t,addTxSignatures as r}from"@avalabs/avalanchejs";import{validateMnemonic as s,mnemonicToSeedSync as a}from"bip39";import{fromSeed as n}from"bip32";import{digestMessage as o}from"../utils/digestMessage.js";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";const{getPublicKey:m,sign:l,signHash:u}=e,{addChecksum:v}=t;class c extends i{privKeyXP;privKeyC;constructor(i,e,t){super(Buffer.from(m(i)),Buffer.from(m(e)),t),this.privKeyXP=i,this.privKeyC=e}static fromMnemonic(i,e,t,r){if(!s(i))throw new Error("Invalid mnemonic phrase.");if(!p(t)||!p(e))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const o=a(i),m=n(o),l=m.derivePath(e),u=m.derivePath(t);if(!l.privateKey||!u.privateKey)throw new Error("Failed to generate private keys.");return new c(l.privateKey,u.privateKey,r)}async signMessage(i){const e=o(i.message),t=this.getSigningKey(i.chain);return Buffer.from(v(await u(e,t)))}getSigningKey(i){return"C"===i?this.privKeyC:this.privKeyXP}async signTx(i){return await r({unsignedTx:i.tx,privateKeys:[this.privKeyC,this.privKeyXP]}),i.tx}async signTxBuffer(i){const e=this.getSigningKey(i.chain);return[Buffer.from(await l(i.buffer,e))]}}export{c as StaticSigner};
@@ -154,6 +154,38 @@ type AddPermissionlessDelegator = {
154
154
  feeState?: pvm.FeeState;
155
155
  stakingAssetId?: string;
156
156
  threshold?: number;
157
+ /**
158
+ * Optional outputs to bundle atomically with the delegation. Each entry
159
+ * produces an additional transferable output on the resulting tx,
160
+ * created at delegation submission time (distinct from the reward
161
+ * output, which P-Chain emits later when the delegation ends).
162
+ *
163
+ * Note: the per-output `threshold` / `locktime` below configure that
164
+ * specific output's OutputOwners. They are independent from the
165
+ * top-level `threshold` / `locktime` on this type, which apply to the
166
+ * delegation **reward** output. Most consumers can omit both pairs.
167
+ *
168
+ * - `addresses` are the **co-owners** of the output (P-Chain bech32, e.g.
169
+ * `P-fuji1...` / `P-avax1...`); parsed to raw bytes internally. Pass
170
+ * a single-element array for the common single-recipient case;
171
+ * multiple addresses combined with `threshold` describe a multisig
172
+ * recipient.
173
+ * - `assetId` defaults to AVAX when omitted. To use a non-AVAX asset
174
+ * (e.g. a custom subnet's staking asset), pass its assetId — the
175
+ * caller's UTXO set must contain enough UTXOs of that asset to fund
176
+ * the output.
177
+ * - `threshold` is the number of signatures required to spend the
178
+ * output; defaults to 1 (any one of `addresses`).
179
+ * - `locktime` (unix seconds) locks the output until that time; defaults
180
+ * to 0 (immediately spendable).
181
+ */
182
+ additionalOutputs?: readonly {
183
+ addresses: readonly string[];
184
+ amount: bigint;
185
+ assetId?: string;
186
+ threshold?: number;
187
+ locktime?: bigint;
188
+ }[];
157
189
  };
158
190
  type RemoveSubnetValidator = {
159
191
  utxoSet: utils.UtxoSet;
@@ -164,6 +196,34 @@ type RemoveSubnetValidator = {
164
196
  fromAddresses?: string[];
165
197
  options?: Common.SpendOptions;
166
198
  };
199
+ type AddAutoRenewedValidator = {
200
+ utxoSet: utils.UtxoSet;
201
+ nodeId: string;
202
+ weight: bigint;
203
+ shares: number;
204
+ feeState: pvm.FeeState;
205
+ fromAddresses?: string[];
206
+ rewardAddresses?: string[];
207
+ delegatorRewardAddresses?: string[];
208
+ ownerAddresses?: string[];
209
+ publicKey: Buffer;
210
+ signature: Buffer;
211
+ autoCompoundRewardShares: number;
212
+ period: bigint;
213
+ options?: Common.SpendOptions;
214
+ locktime?: bigint;
215
+ threshold?: number;
216
+ };
217
+ type SetAutoRenewedValidatorConfig = {
218
+ utxoSet: utils.UtxoSet;
219
+ feeState: pvm.FeeState;
220
+ validatorTxId: string;
221
+ auth: number[];
222
+ autoCompoundRewardShares: number;
223
+ period: bigint;
224
+ fromAddresses?: string[];
225
+ options?: Common.SpendOptions;
226
+ };
167
227
  type TransferSubnetOwnershipTx = {
168
228
  utxoSet: utils.UtxoSet;
169
229
  subnetId: string;
@@ -176,4 +236,4 @@ type TransferSubnetOwnershipTx = {
176
236
  locktime?: bigint;
177
237
  };
178
238
 
179
- export type { AddPermissionlessDelegator, AddPermissionlessValidator, AddSubnetValidator, BaseTx, ConsolidateP, ConvertSubnetToL1, CreateChain, CreateSubnet, DisableL1Validator, ExportP, ImportP, IncreaseL1ValidatorBalance, RegisterL1Validator, RemoveSubnetValidator, SetL1ValidatorWeight, TransferSubnetOwnershipTx };
239
+ export type { AddAutoRenewedValidator, AddPermissionlessDelegator, AddPermissionlessValidator, AddSubnetValidator, BaseTx, ConsolidateP, ConvertSubnetToL1, CreateChain, CreateSubnet, DisableL1Validator, ExportP, ImportP, IncreaseL1ValidatorBalance, RegisterL1Validator, RemoveSubnetValidator, SetAutoRenewedValidatorConfig, SetL1ValidatorWeight, TransferSubnetOwnershipTx };
@@ -1,8 +1,8 @@
1
1
  import * as _avalabs_avalanchejs from '@avalabs/avalanchejs';
2
- import { utils, pvm, Common } from '@avalabs/avalanchejs';
2
+ import { utils, pvm } 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
+ import { ImportP, ExportP, ConsolidateP, BaseTx, ConvertSubnetToL1, RegisterL1Validator, SetL1ValidatorWeight, DisableL1Validator, IncreaseL1ValidatorBalance, AddAutoRenewedValidator, SetAutoRenewedValidatorConfig, CreateChain, CreateSubnet, AddSubnetValidator, AddPermissionlessValidator, AddPermissionlessDelegator, RemoveSubnetValidator, TransferSubnetOwnershipTx } from './TxBuilderTypes.js';
6
6
 
7
7
  /**
8
8
  * An abstract class that that is shared by all wallet classes.
@@ -49,13 +49,9 @@ declare abstract class WalletAbstract {
49
49
  * @param source What is the source chain of the atomic UTXOs
50
50
  */
51
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>;
56
- exportX(amount: bigint, utxoSet: utils.UtxoSet, destination: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
57
- importP({ utxoSet, sourceChain, toAddress, threshold, feeState, locktime, }: ImportP): Common.UnsignedTx;
58
- importX(utxos: utils.UtxoSet, sourceChain: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
52
+ exportX(amount: bigint, utxoSet: utils.UtxoSet, destination: 'P' | 'C', toAddress?: string): _avalabs_avalanchejs.UnsignedTx;
53
+ importP({ utxoSet, sourceChain, toAddress, threshold, feeState, locktime, }: ImportP): _avalabs_avalanchejs.UnsignedTx;
54
+ importX(utxos: utils.UtxoSet, sourceChain: 'P' | 'C', toAddress?: string): _avalabs_avalanchejs.UnsignedTx;
59
55
  /**
60
56
  *
61
57
  * @param utxos
@@ -64,7 +60,7 @@ declare abstract class WalletAbstract {
64
60
  * @param feeAssetId
65
61
  * @param toAddress Must be hex EVM address.
66
62
  */
67
- importC(utxos: utils.UtxoSet, sourceChain: 'P' | 'X', baseFee: bigint, feeAssetId?: string, toAddress?: string): Common.UnsignedTx;
63
+ importC(utxos: utils.UtxoSet, sourceChain: 'P' | 'X', baseFee: bigint, feeAssetId?: string, toAddress?: string): _avalabs_avalanchejs.UnsignedTx;
68
64
  /**
69
65
  *
70
66
  * @param amount
@@ -81,17 +77,19 @@ declare abstract class WalletAbstract {
81
77
  * @param destination
82
78
  * @param toAddress
83
79
  */
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;
80
+ exportP({ amount, utxoSet, destination, feeState, toAddress }: ExportP): _avalabs_avalanchejs.UnsignedTx;
81
+ consolidateP({ utxoSet, amount, feeState, toAddress, options, }: ConsolidateP): _avalabs_avalanchejs.UnsignedTx;
82
+ baseTX({ utxoSet, chain, toAddress, amountsPerAsset, feeState, options, fromAddresses, }: BaseTx): _avalabs_avalanchejs.UnsignedTx;
83
+ convertSubnetToL1({ utxoSet, chainId, subnetId, subnetAuth, feeState, address, validators, options, fromAddresses, }: ConvertSubnetToL1): _avalabs_avalanchejs.UnsignedTx;
84
+ registerL1Validator({ utxoSet, balance, signature, message, feeState, fromAddresses, options, }: RegisterL1Validator): _avalabs_avalanchejs.UnsignedTx;
85
+ setL1ValidatorWeight({ utxoSet, feeState, message, options, fromAddresses, }: SetL1ValidatorWeight): _avalabs_avalanchejs.UnsignedTx;
86
+ disableL1Validator({ utxoSet, feeState, options, fromAddresses, disableAuth, validationId, }: DisableL1Validator): _avalabs_avalanchejs.UnsignedTx;
87
+ increaseL1ValidatorBalance({ utxoSet, feeState, options, fromAddresses, balance, validationId, }: IncreaseL1ValidatorBalance): _avalabs_avalanchejs.UnsignedTx;
88
+ addAutoRenewedValidator({ utxoSet, nodeId, weight, shares, feeState, fromAddresses, rewardAddresses, delegatorRewardAddresses, ownerAddresses, publicKey, signature, autoCompoundRewardShares, period, options, locktime, threshold, }: AddAutoRenewedValidator): _avalabs_avalanchejs.UnsignedTx;
89
+ setAutoRenewedValidatorConfig({ utxoSet, feeState, validatorTxId, auth, autoCompoundRewardShares, period, fromAddresses, options, }: SetAutoRenewedValidatorConfig): _avalabs_avalanchejs.UnsignedTx;
90
+ createBlockchain({ utxoSet, subnetId, chainName, vmID, fxIds, genesisData, subnetAuth, feeState, options, fromAddresses, }: CreateChain): _avalabs_avalanchejs.UnsignedTx;
91
+ createSubnet({ utxoSet, rewardAddresses, feeState, fromAddresses, options, threshold, locktime, }: CreateSubnet): _avalabs_avalanchejs.UnsignedTx;
92
+ addSubnetValidator({ utxoSet, nodeId, start, end, weight, subnetId, subnetAuth, feeState, fromAddresses, options, }: AddSubnetValidator): _avalabs_avalanchejs.UnsignedTx;
95
93
  /**
96
94
  *
97
95
  * @param utxoSet The transaction will be constructed from these UTXOs.
@@ -108,7 +106,7 @@ declare abstract class WalletAbstract {
108
106
  * @param signature the BLS signature, If the subnet is the primary network. Can be found in the Node on startup.
109
107
  * @param options
110
108
  */
111
- addPermissionlessValidator({ utxoSet, nodeId, start, end, weight, subnetId, shares, feeState, fromAddresses, rewardAddresses, delegatorRewardAddresses, publicKey, signature, options, threshold, locktime, stakingAssetId, }: AddPermissionlessValidator): Common.UnsignedTx;
109
+ addPermissionlessValidator({ utxoSet, nodeId, start, end, weight, subnetId, shares, feeState, fromAddresses, rewardAddresses, delegatorRewardAddresses, publicKey, signature, options, threshold, locktime, stakingAssetId, }: AddPermissionlessValidator): _avalabs_avalanchejs.UnsignedTx;
112
110
  /**
113
111
  *
114
112
  * @param utxoSet The transaction will be constructed from these UTXOs.
@@ -121,9 +119,9 @@ declare abstract class WalletAbstract {
121
119
  * @param rewardAddresses Will use active address if not provided. Given addresses will share the reward UTXO.
122
120
  * @param options
123
121
  */
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;
122
+ addPermissionlessDelegator({ utxoSet, nodeId, start, end, weight, subnetId, fromAddresses, rewardAddresses, options, locktime, feeState, threshold, stakingAssetId, additionalOutputs, }: AddPermissionlessDelegator): _avalabs_avalanchejs.UnsignedTx;
123
+ removeSubnetValidator({ utxoSet, nodeId, subnetId, subnetAuth, fromAddresses, feeState, options, }: RemoveSubnetValidator): _avalabs_avalanchejs.UnsignedTx;
124
+ transferSubnetOwnershipTx({ utxoSet, subnetId, subnetAuth, subnetOwners, feeState, fromAddresses, options, threshold, locktime, }: TransferSubnetOwnershipTx): _avalabs_avalanchejs.UnsignedTx;
127
125
  protected constructor(provider: AbstractProvider);
128
126
  }
129
127
 
@@ -1 +1 @@
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
+ import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"create-hash";import"bip32";import{getUTXOsForAddresses as e}from"../utils/getAllUTXOs.js";import"../utils/getAssetBalance.js";import{utils as s,TransferableOutput as t,avm as r,pvm as d,evm as o,pvmSerial as n,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 u,sortUTXOsByAmountAscending as g,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:l,hexToBuffer:f}=s;class x{constructor(e){this.provider=e}setProvider(e){this.provider=e}getProvider(){return this.provider}async getUTXOs(s){const t=this.provider.getApi(s);return e(this.getAddresses(s),t)}async getStake(){const e=this.provider.getApiP();return h(this.getAddresses("P"),e)}async getAtomicUTXOs(s,t){if(s===t)throw new Error("Chain can not be the same as source chain.");const r=this.provider.getApi(s),d=this.provider.getChainID(t);return e(this.getAddresses(s),r,{sourceChain:d,addresses:[]})}exportX(e,s,d,o){o=o||this.getCurrentAddress(d);const n=l(o)[2],i=this.provider.getAvaxID(),a=t.fromNative(i,e,[n]),m=u(s.getUTXOs(),!0),h=this.provider.getChainID(d),g=this.getAddresses("X").map((e=>l(e)[2])),A=l(this.getChangeAddress("X"))[2];return r.newExportTx(this.provider.getContext(),h,g,m,[a],{threshold:1,changeAddresses:[A]})}importP({utxoSet:e,sourceChain:s,toAddress:t,threshold:r,feeState:o,locktime:n}){const i=this.provider.getChainID(s),a=this.getAddresses("P").map((e=>l(e)[2]));l(this.getChangeAddress("P"))[2],t=t||this.getCurrentAddress("P");const m=l(t)[2],h=e.getUTXOs();return p(o),d.newImportTx({fromAddressesBytes:a,utxos:h,toAddressesBytes:[m],sourceChainId:i,threshold:r,feeState:o,locktime:n},this.provider.getContext())}importX(e,s,t){const d=this.provider.getChainID(s),o=this.getAddresses("X").map((e=>l(e)[2])),n=l(this.getChangeAddress("X"))[2];t=t||this.getCurrentAddress("X");const i=l(t)[2];return r.newImportTx(this.provider.getContext(),d,e.getUTXOs(),[i],o,{changeAddresses:[n]})}importC(e,s,t,r,d){const n=this.provider.getChainID(s),i=this.getAddresses("C").map((e=>l(e)[2]));d=d||this.getAddressEVM();const a=Buffer.from(c(d),"hex");return o.newImportTxFromBaseFee(this.provider.getContext(),a,i,e.getUTXOs(),n,t,r)}exportC(e,s,t,r,d){const n=f(this.getAddressEVM()),i=this.provider.getChainID(s);d=d||this.getCurrentAddress(s);const a=l(d)[2],m=r/BigInt(1e9);return o.newExportTxFromBaseFee(this.provider.getContext(),m,e,i,n,[a],t)}exportP({amount:e,utxoSet:s,destination:r,feeState:o,toAddress:n}){n=n||this.getCurrentAddress(r);const i=l(n)[2],a=this.provider.getAvaxID(),m=t.fromNative(a,e,[i]),h=u(s.getUTXOs(),!0),g=this.provider.getChainID(r),A=this.getAddresses("P").map((e=>l(e)[2])),c=l(this.getChangeAddress("P"))[2];return p(o),d.newExportTx({changeAddressesBytes:[c],fromAddressesBytes:A,utxos:h,outputs:[m],destinationChainId:g,feeState:o},this.provider.getContext())}consolidateP({utxoSet:e,amount:s,feeState:r,toAddress:o,options:n}){const i=g(e.getUTXOs());o=o??this.getCurrentAddress("P");const a=l(o)[2],m=this.provider.getContext(),h=[t.fromNative(m.avaxAssetID,s,[a])],u=this.getAddresses("P").map((e=>l(e)[2])),A=l(this.getChangeAddress("P"))[2],c=n?.changeAddresses??[A];return p(r),d.newBaseTx({changeAddressesBytes:c,fromAddressesBytes:u,utxos:i,outputs:h,minIssuanceTime:n?.minIssuanceTime,memo:n?.memo,feeState:r},m)}baseTX({utxoSet:e,chain:s,toAddress:o,amountsPerAsset:n,feeState:i,options:a,fromAddresses:m}){const[h,g,A]=l(o);if(h!==s||g!==this.provider.getHrp())throw new Error(`Invalid recipient address "${o}"`);const c=Object.entries(n).map((([e,s])=>t.fromNative(e,s,[A]))),f=u(e.getUTXOs(),!0),x=(m??this.getAddresses(s)).map((e=>l(e)[2])),T=l(this.getChangeAddress("P"))[2],I=a?.changeAddresses??[T];return"X"===s?r.newBaseTx(this.provider.getContext(),x,f,c,a):(p(i),d.newBaseTx({changeAddressesBytes:I,fromAddressesBytes:x,utxos:f,outputs:c,minIssuanceTime:a?.minIssuanceTime,memo:a?.memo,feeState:i},this.provider.getContext()))}convertSubnetToL1({utxoSet:e,chainId:t,subnetId:r,subnetAuth:o,feeState:m,address:h,validators:g,options:A,fromAddresses:c}){const p=(c??this.getAddresses("P")).map((e=>l(e)[2])),f=l(this.getChangeAddress("P"))[2],x=A?.changeAddresses??[f],T=g.map((({nodeId:e,pubKey:t,signature:r,balance:d,weight:o,deactivationOwner:m,remainingBalanceOwner:h})=>{const u=new n.ProofOfPossession(Uint8Array.from(s.hexToBuffer(t)),Uint8Array.from(s.hexToBuffer(r))),g=i.fromNative(h.addresses.map((e=>l(e)[2])),h.threshold??1),A=i.fromNative(m.addresses.map((e=>l(e)[2])),m.threshold??1);return a.fromNative(e,o,d,u,g,A)}));return d.newConvertSubnetToL1Tx({changeAddressesBytes:x,validators:T,fromAddressesBytes:p,address:l(h)[2],chainId:t,subnetId:r,subnetAuth:o,feeState:m,utxos:u(e.getUTXOs(),!0)},this.provider.getContext())}registerL1Validator({utxoSet:e,balance:t,signature:r,message:o,feeState:n,fromAddresses:i,options:a}){const m=(i??this.getAddresses("P")).map((e=>l(e)[2])),h=l(this.getChangeAddress("P"))[2],g=a?.changeAddresses??[h];return d.newRegisterL1ValidatorTx({utxos:u(e.getUTXOs(),!0),balance:t,blsSignature:Uint8Array.from(s.hexToBuffer(r)),changeAddressesBytes:g,feeState:n,fromAddressesBytes:m,memo:a?.memo,message:Uint8Array.from(s.hexToBuffer(o)),minIssuanceTime:a?.minIssuanceTime},this.provider.getContext())}setL1ValidatorWeight({utxoSet:e,feeState:t,message:r,options:o,fromAddresses:n}){const i=(n??this.getAddresses("P")).map((e=>l(e)[2])),a=l(this.getChangeAddress("P"))[2],m=o?.changeAddresses??[a];return d.newSetL1ValidatorWeightTx({utxos:u(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:t,fromAddressesBytes:i,memo:o?.memo,message:Uint8Array.from(s.hexToBuffer(r)),minIssuanceTime:o?.minIssuanceTime},this.provider.getContext())}disableL1Validator({utxoSet:e,feeState:s,options:t,fromAddresses:r,disableAuth:o,validationId:n}){const i=(r??this.getAddresses("P")).map((e=>l(e)[2])),a=l(this.getChangeAddress("P"))[2],m=t?.changeAddresses??[a];return d.newDisableL1ValidatorTx({disableAuth:o,validationId:n,utxos:u(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:o,validationId:n}){const i=(r??this.getAddresses("P")).map((e=>l(e)[2])),a=l(this.getChangeAddress("P"))[2],m=t?.changeAddresses??[a];return d.newIncreaseL1ValidatorBalanceTx({balance:o,validationId:n,utxos:u(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:s,fromAddressesBytes:i,memo:t?.memo,minIssuanceTime:t?.minIssuanceTime},this.provider.getContext())}addAutoRenewedValidator({utxoSet:e,nodeId:s,weight:t,shares:r,feeState:o,fromAddresses:n,rewardAddresses:i,delegatorRewardAddresses:a,ownerAddresses:m,publicKey:h,signature:u,autoCompoundRewardShares:g,period:c,options:p,locktime:f,threshold:x}){const T=A(e.getUTXOs()),I=(n??this.getAddresses("P")).map((e=>l(e)[2])),C=(i??[this.getCurrentAddress("P")]).map((e=>l(e)[2])),v=(a??[this.getCurrentAddress("P")]).map((e=>l(e)[2])),S=(m??[this.getCurrentAddress("P")]).map((e=>l(e)[2])),w=l(this.getChangeAddress("P"))[2],b=p?.changeAddresses??[w];return d.newAddAutoRenewedValidatorTx({fromAddressesBytes:I,delegatorRewardsOwner:v,utxos:T,minIssuanceTime:p?.minIssuanceTime,memo:p?.memo,changeAddressesBytes:b,nodeId:s,weight:t,shares:r,feeState:o,publicKey:h,rewardAddresses:C,signature:u,locktime:f,threshold:x,ownerAddresses:S,autoCompoundRewardShares:g,period:c},this.provider.getContext())}setAutoRenewedValidatorConfig({utxoSet:e,feeState:s,validatorTxId:t,auth:r,autoCompoundRewardShares:o,period:n,fromAddresses:i,options:a}){const m=(i??this.getAddresses("P")).map((e=>l(e)[2])),h=l(this.getChangeAddress("P"))[2],g=a?.changeAddresses??[h];return d.newSetAutoRenewedValidatorConfigTx({utxos:u(e.getUTXOs(),!0),changeAddressesBytes:g,feeState:s,fromAddressesBytes:m,memo:a?.memo,minIssuanceTime:a?.minIssuanceTime,validatorTxId:t,auth:r,autoCompoundRewardShares:o,period:n},this.provider.getContext())}createBlockchain({utxoSet:e,subnetId:s,chainName:t,vmID:r,fxIds:o,genesisData:n,subnetAuth:i,feeState:a,options:m,fromAddresses:h}){const g=u(e.getUTXOs(),!0),A=(h??this.getAddresses("P")).map((e=>l(e)[2])),c=l(this.getChangeAddress("P"))[2],f=m?.changeAddresses??[c];return p(a),d.newCreateChainTx({chainName:t,feeState:a,fromAddressesBytes:A,fxIds:o,genesisData:n,subnetAuth:i,subnetId:s,utxos:g,vmId:r,changeAddressesBytes:f},this.provider.getContext())}createSubnet({utxoSet:e,rewardAddresses:s,feeState:t,fromAddresses:r,options:o,threshold:n,locktime:i}){const a=u(e.getUTXOs(),!0),m=(r??this.getAddresses("P")).map((e=>l(e)[2])),h=l(this.getChangeAddress("P"))[2],g=o?.changeAddresses??[h],A=s.map((e=>l(e)[2]));return p(t),d.newCreateSubnetTx({fromAddressesBytes:m,changeAddressesBytes:g,utxos:a,minIssuanceTime:o?.minIssuanceTime,memo:o?.memo,feeState:t,threshold:n,locktime:i,subnetOwners:A},this.provider.getContext())}addSubnetValidator({utxoSet:e,nodeId:s,start:t,end:r,weight:o,subnetId:n,subnetAuth:i,feeState:a,fromAddresses:m,options:h}){const g=u(e.getUTXOs(),!0),A=(m??this.getAddresses("P")).map((e=>l(e)[2])),c=l(this.getChangeAddress("P"))[2],f=h?.changeAddresses??[c];return p(a),d.newAddSubnetValidatorTx({changeAddressesBytes:f,fromAddressesBytes:A,utxos:g,minIssuanceTime:h?.minIssuanceTime,memo:h?.memo,nodeId:s,start:t,end:r,weight:o,subnetId:n,subnetAuth:i,feeState:a},this.provider.getContext())}addPermissionlessValidator({utxoSet:e,nodeId:s,start:t,end:r,weight:o,subnetId:n,shares:i,feeState:a,fromAddresses:h,rewardAddresses:u,delegatorRewardAddresses:g,publicKey:c,signature:f,options:x,threshold:T,locktime:I,stakingAssetId:C}){const v=A(e.getUTXOs()),S=(h??this.getAddresses("P")).map((e=>l(e)[2])),w=(u??[this.getCurrentAddress("P")]).map((e=>l(e)[2])),b=(g??[this.getCurrentAddress("P")]).map((e=>l(e)[2]));if(!(n!==m.PrimaryNetworkID.toString()||c&&f))throw new Error("Must provide public key and signature for primary subnet.");const P=l(this.getChangeAddress("P"))[2],B=x?.changeAddresses??[P];return p(a),d.newAddPermissionlessValidatorTx({fromAddressesBytes:S,delegatorRewardsOwner:b,utxos:v,minIssuanceTime:x?.minIssuanceTime,memo:x?.memo,changeAddressesBytes:B,nodeId:s,start:t,end:r,weight:o,subnetId:n,shares:i,feeState:a,publicKey:c,rewardAddresses:w,signature:f,locktime:I,threshold:T,stakingAssetId:C},this.provider.getContext())}addPermissionlessDelegator({utxoSet:e,nodeId:s,start:r,end:o,weight:n,subnetId:i,fromAddresses:a,rewardAddresses:m,options:h,locktime:u,feeState:g,threshold:c,stakingAssetId:f,additionalOutputs:x}){const T=A(e.getUTXOs()),I=(a??this.getAddresses("P")).map((e=>l(e)[2])),C=(m??[this.getCurrentAddress("P")]).map((e=>l(e)[2])),v=l(this.getChangeAddress("P"))[2],S=h?.changeAddresses??[v],w=this.provider.getContext();return p(g),d.newAddPermissionlessDelegatorTx({fromAddressesBytes:I,utxos:T,minIssuanceTime:h?.minIssuanceTime,memo:h?.memo,changeAddressesBytes:S,nodeId:s,start:r,end:o,weight:n,subnetId:i,rewardAddresses:C,locktime:u,stakingAssetId:f,threshold:c,feeState:g,additionalOutputs:x?.map((e=>t.fromNative(e.assetId??w.avaxAssetID,e.amount,e.addresses.map((e=>l(e)[2])),e.locktime,e.threshold)))},w)}removeSubnetValidator({utxoSet:e,nodeId:s,subnetId:t,subnetAuth:r,fromAddresses:o,feeState:n,options:i}){const a=u(e.getUTXOs(),!0),m=(o??this.getAddresses("P")).map((e=>l(e)[2])),h=l(this.getChangeAddress("P"))[2],g=i?.changeAddresses??[h];return p(n),d.newRemoveSubnetValidatorTx({changeAddressesBytes:g,fromAddressesBytes:m,utxos:a,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,nodeId:s,subnetId:t,subnetAuth:r,feeState:n},this.provider.getContext())}transferSubnetOwnershipTx({utxoSet:e,subnetId:s,subnetAuth:t,subnetOwners:r,feeState:o,fromAddresses:n,options:i,threshold:a,locktime:m}){const h=u(e.getUTXOs(),!0),g=(n??this.getAddresses("P")).map((e=>l(e)[2])),A=l(this.getChangeAddress("P"))[2],c=i?.changeAddresses??[A],f=r.map((e=>l(e)[2]));return p(o),d.newTransferSubnetOwnershipTx({changeAddressesBytes:c,fromAddressesBytes:g,utxos:h,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,subnetId:s,subnetAuth:t,subnetOwners:f,feeState:o,threshold:a,locktime:m},this.provider.getContext())}}export{x as WalletAbstract};
@@ -1 +1 @@
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
+ import{WalletAbstract as t}from"./WalletAbstract.js";import{fromSeed as e}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import{strip0x as i}from"@avalabs/core-utils-sdk";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"create-hash";import"@avalabs/avalanchejs";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import{verifyDerivationPath as o}from"../utils/verifyDerivationPath.js";import{SigningKey as a,computeAddress as n}from"ethers";class u extends t{constructor(t,e,r){if(super(r),this.pubkeyXP=t,this.pubkeyC=e,33!==e.length||33!==t.length)throw new Error("Public key must be 33 byte compressed public key")}static fromPublicKey(t,e,r){const s=i(a.computePublicKey(t,!0)),o=i(a.computePublicKey(e,!0)),n=Buffer.from(s,"hex"),l=Buffer.from(o,"hex");return new u(n,l,r)}static fromMnemonic(t,i,a,n){if(!r(t))throw new Error("Invalid mnemonic phrase.");if(!o(a)||!o(i))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const l=s(t),m=e(l),p=m.derivePath(a),c=m.derivePath(i);return u.fromPublicKey(c.publicKey,p.publicKey,n)}getAddress(t){const e="C"===t?this.pubkeyC:this.pubkeyXP;return this.provider.getAddress(e,t)}getAddressEVM(){return n(`0x${this.pubkeyC.toString("hex")}`)}getAddresses(t){return[this.getAddress(t)]}getChangeAddress(t){return this.getAddress(t)}getCurrentAddress(t){return this.getAddress(t)}}export{u as WalletVoid};
@@ -0,0 +1,16 @@
1
+ import { UnsignedTx } from '@avalabs/avalanchejs';
2
+ import { Signer, SignMessageRequest, SignTxRequest, SignTxBufferRequest } from '../models.js';
3
+
4
+ /**
5
+ * Ledger signer that can use multiple LedgerLive derivation paths for signing transactions.
6
+ */
7
+ declare class LedgerLiveSigner implements Signer {
8
+ #private;
9
+ private accountIndices;
10
+ constructor(accountIndices: number[]);
11
+ signMessage(request: SignMessageRequest): Promise<Buffer>;
12
+ signTx(txRequest: SignTxRequest): Promise<UnsignedTx>;
13
+ signTxBuffer(txRequest: SignTxBufferRequest): Promise<Buffer[]>;
14
+ }
15
+
16
+ export { LedgerLiveSigner };
@@ -0,0 +1 @@
1
+ import t from"bip32-path";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as r}from"../../utils/digestMessage.js";import"bip32";import"@avalabs/avalanchejs";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";const s={C:60,X:9e3,P:9e3};class i{constructor(t){this.accountIndices=t}#t(t){return`m/44'/${s[t]}'`}#r(t,r){return`${this.#t(t)}/${r}'`}async signMessage(s){if(!s.transport||!s.message)throw new Error("Unable to sign message. Incomplete or invalid request.");if(!this.accountIndices.length)throw new Error("No account indices provided. At least one account index is required to sign a message.");const i=t.fromString(this.#r(s.chain,this.accountIndices[0])),n=t.fromString("0/0"),o=r(s.message),a=(await e.signHash(s.transport,o,i,[n])).signatures.get(n.toString(!0));if(!a)throw new Error("Failed to sign message.");return a}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const e=r.tx,s=e.getVM(),i=Buffer.from(e.toBytes()),n="EVM"===s?"C":"AVM"===s?"X":"P",o=new Set(r.externalIndices??this.accountIndices);for(const s of o){const o=t.fromString(this.#r(n,s));(await this.#e(o,{buffer:i,chain:n,transport:r.transport})).forEach((t=>{e.addSignature(t)}))}return e}async#e(r,s){if(!s.transport)throw new Error("Ledger transport not provided");return[...(await e.signTx(s.transport,s.buffer,r,s.signers??[t.fromString("0/0")],s.change??[t.fromString("0/0")])).signatures.values()]}async signTxBuffer(r){if(!this.accountIndices.length)throw new Error("No account indices provided. At least one account index is required to sign a tx buffer.");const e=t.fromString(this.#r(r.chain,this.accountIndices[0]));return this.#e(e,r)}}export{i as LedgerLiveSigner};
@@ -1 +1 @@
1
- import{WalletVoid as 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
+ import{WalletVoid as t}from"../WalletVoid.js";import{isObsidianApp as r}from"./isObsidianApp.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";import i from"bip32-path";import s from"@ledgerhq/hw-app-eth";import{utils as o}from"@avalabs/avalanchejs";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../../utils/digestMessage.js";import"bip32";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import{verifyDerivationPath as n}from"../../utils/verifyDerivationPath.js";import{SigningKey as p}from"ethers";const{strip0x:u}=o;class h extends t{constructor(t,r,e,i,s){const a=o.strip0x(p.computePublicKey(t,!0)),u=o.strip0x(p.computePublicKey(e,!0));if(super(Buffer.from(a,"hex"),Buffer.from(u,"hex"),s),this.pathXP=r,this.pathC=i,!n(r)||!n(i))throw new Error("Invalid path configuration.")}static async fromTransport(t,e,i,o){if(await r(t))throw new Error("Ledger app not supported. Must be version >= 0.6.0");if(!n(e)||!n(i))throw new Error("Invalid path configuration.");const a=new s(t),f=await a.getAddress(i,!1),g=await a.getAddress(e,!1),m=Buffer.from(u(f.publicKey),"hex"),c=Buffer.from(u(g.publicKey),"hex"),l=Buffer.from(u(p.computePublicKey(m,!0)),"hex"),d=Buffer.from(u(p.computePublicKey(c,!0)),"hex");return new h(d,e,l,i,o)}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const r=i.fromString(this.getAccountPath(t.chain)),s=i.fromString(this.getPartialSignerPath(t.chain)),o=a(t.message),n=(await e.signHash(t.transport,o,r,[s])).signatures.get(s.toString(!0));if(!n)throw new Error("Failed to sign message.");return n}getFullSignerPath(t){return"C"===t?this.pathC:this.pathXP}getPartialSignerPath(t){return this.getFullSignerPath(t).split("/").slice(4).join("/")}getAccountPath(t){return this.getFullSignerPath(t).split("/").slice(0,4).join("/")}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=t.tx,e=r.getVM(),i=Buffer.from(r.toBytes()),s="EVM"===e?"C":"X";return(await this.signTxBuffer({buffer:i,chain:s,transport:t.transport})).forEach((t=>{r.addSignature(t)})),r}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=i.fromString(this.getAccountPath(t.chain)),s=i.fromString(this.getPartialSignerPath(t.chain));return[...(await e.signTx(t.transport,t.buffer,r,[s],[s])).signatures.values()]}}export{h as LedgerSigner};
@@ -1,6 +1,7 @@
1
1
  import { UnsignedTx } from '@avalabs/avalanchejs';
2
2
  import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from '../models.js';
3
3
  import { JsonRpcProvider } from '../../providers/JsonRpcProvider.js';
4
+ import { DerivationPath } from '../../../EVM/constants.js';
4
5
 
5
6
  /**
6
7
  * A wallet class that can sign X/P and C transactions.
@@ -12,12 +13,13 @@ import { JsonRpcProvider } from '../../providers/JsonRpcProvider.js';
12
13
  declare class SimpleLedgerSigner implements Signer {
13
14
  private activeAccountIndex;
14
15
  private provider;
16
+ private pathSpec;
15
17
  private accountNode;
16
18
  /**
17
19
  * @param {number} activeAccountIndex - the index of the primary account used for static signing
18
- * @param {string} xpubXP - optional extended public key of `m/44'/9000'/0`
20
+ * @param {string} xpubXP - optional extended public key of `m/44'/9000'/${activeAccountIndex}`
19
21
  */
20
- constructor(activeAccountIndex: number, provider: JsonRpcProvider, xpubXP?: string);
22
+ constructor(activeAccountIndex: number, provider: JsonRpcProvider, xpubXP?: string, pathSpec?: DerivationPath);
21
23
  private reSerializeTx;
22
24
  private getChainAlias;
23
25
  private getAccountPath;
@@ -1 +1 @@
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};
1
+ import{utils as t,EVMUnsignedTx as e,UnsignedTx as r}from"@avalabs/avalanchejs";import s from"bip32-path";import{getTxOutputAddresses as i}from"../../utils/getTxOutputAddresses.js";import{ZondaxProvider as n}from"./ZondaxProvider.js";import{fromBase58 as o}from"bip32";import"../../utils/addSignaturesToAvalancheTx.js";import"../../utils/convertGlacierUtxo.js";import"../../utils/createAvalancheEvmUnsignedTx.js";import"../../utils/createAvalancheUnsignedTx.js";import{digestMessage as a}from"../../utils/digestMessage.js";import"../../utils/getAssetBalance.js";import"../../utils/getUtxosByTxFromGlacier.js";import"bip39";import"../../utils/parseAvalancheTx.js";import"../../utils/populateCredential.js";import"../../utils/txSizeLimits.js";import"@ledgerhq/hw-app-eth";import"ethers";import{DerivationPath as c}from"../../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";const{parse:h}=t;class p{constructor(t,e,r,s=c.BIP44){this.activeAccountIndex=t,this.provider=e,this.pathSpec=s,r&&(this.accountNode=o(r))}accountNode;reSerializeTx(t,s){return t instanceof e||"C"===s?e.fromJSON(JSON.stringify(t.toJSON())):r.fromJSON(JSON.stringify(t.toJSON()))}getChainAlias(t){return"EVM"===t.getVM()?"C":"X"}getAccountPath(t){switch(t){case"X":case"P":return`m/44'/9000'/${this.activeAccountIndex}'`;case"C":return`m/44'/60'/${this.pathSpec===c.LedgerLive?this.activeAccountIndex:0}'`}}getAddressOfPath(t,e){if(!this.accountNode)return null;const{publicKey:r}=this.accountNode.derivePath(t),s=this.provider.getAddress(r,e);return Buffer.from(h(s)[2]).toString("hex")}getAddressPathMap(t){const{tx:e,externalIndices:r,internalIndices:s}=t,i=this.getChainAlias(e),n="EVM"===t.tx.getVM()?`0/${this.pathSpec===c.LedgerLive?0:this.activeAccountIndex}`:"0/0",o=new Map;if("C"===i||!this.accountNode)return o;const a=[n,...(r??[]).map((t=>`0/${t}`)),...(s??[]).map((t=>`1/${t}`))];for(const t of a){const e=this.getAddressOfPath(t,i);e&&o.set(e,t)}return o}getAddressBipPaths(t,e,r){return 0===e.size?[s.fromString("C"===r?`0/${this.pathSpec===c.LedgerLive?0:this.activeAccountIndex}`:"0/0")]:t.reduce(((t,r)=>{const i=e.get(Buffer.from(r).toString("hex"));return i&&t.push(s.fromString(i)),t}),[])}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const e=this.getChainAlias(t.tx),r=this.reSerializeTx(t.tx,e),s=Buffer.from(r.toBytes()),n=this.getAddressPathMap(t),o=this.getAddressBipPaths(r.getAddresses(),n,e),a=this.getAddressBipPaths([...i(r)],n,e);return(await this.signTxBuffer({buffer:s,chain:e,transport:t.transport,signers:o,change:a})).forEach((t=>{r.addSignature(t)})),r}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");if(!t.signers)throw new Error("Signers not provided");const e=t.change||[],r=s.fromString(this.getAccountPath(t.chain));return[...(await n.signTx(t.transport,t.buffer,r,t.signers,e)).signatures.values()]}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const e="C"===t.chain?this.activeAccountIndex:0,r=t.signer||s.fromString(`0/${e}`);if(2!=r.toPathArray().length)throw new Error("Given signer path must have a depth of 2. Ex. 0/0, 0/1");const i=a(t.message),o=(await n.signHash(t.transport,i,s.fromString(this.getAccountPath(t.chain)),[r])).signatures.get(r.toString(!0));if(!o)throw new Error("Failed to sign message.");return o}}export{p as SimpleLedgerSigner};
@@ -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 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
+ import{MnemonicWalletVoid as r}from"./MnemonicWalletVoid.js";import{getAppEth as t}from"../../../EVM/utils/getAppEth.js";import{SigningKey as e}from"ethers";import{DerivationPath as s}from"../../../EVM/constants.js";import{fromPublicKey as i}from"bip32";import"bip39";import"bitcoinjs-lib";import{strip0x as n}from"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import o from"bip32-path";import{isObsidianApp as a}from"../ledger/isObsidianApp.js";import{ZondaxProvider as d}from"../ledger/ZondaxProvider.js";import{getTxOutputAddresses as p}from"../../utils/getTxOutputAddresses.js";import{getAddressDerivationPath as f}from"../../../utils/getAddressDerivationPath.js";import{utils as m}from"@avalabs/avalanchejs";import"hdkey";const{parse:c}=m;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,o){if(await a(r))throw new Error("Unsupported ledger app version. Must be >= 0.6.0");const p=t(r),m=await d.getXPUB(r,g.getAccountPath("X")),c=i(m.pubKey,m.chainCode),h=f(0,"EVM",{pathSpec:s.BIP44}),u=await p.getAddress(h,!1),l=e.computePublicKey(Buffer.from(u.publicKey,"hex"),!0),w=Buffer.from(n(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"))),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()),a="EVM"===i?"C":"X",d=t.getAddresses().map((r=>Buffer.from(r))),f=this.getAdditionalAddressesByIndices(e??[],!1,a),m=this.getAdditionalAddressesByIndices(s??[],!0,a),c=[...this.filterOwnedAddresses(d,f,m).values()].map((r=>o.fromString(r))),g=[...p(t)].map((r=>Buffer.from(r))),h=[...this.filterOwnedAddresses(g).values()].map((r=>o.fromString(r)));return(await this.signTxBuffer({buffer:n,chain:a,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=o.fromString(g.getAccountPath(r.chain));return[...(await d.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{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
+ 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{DerivationPath as p}from"../../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{getAddressDerivationPath as c}from"../../../utils/getAddressDerivationPath.js";import"hdkey";const{strip0x:h}=t;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(c(0,"EVM",{pathSpec:p.BIP44}));if(!h.privateKey)throw new Error("Unable to derive EVM private key.");return new m(a.toBase58(),h.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;return"EVM"===t.getVM()?[this.evmPrivKey]:[...this.getInternalPrivateKeys(i),...this.getExternalPrivateKeys(r)]}async signTxBuffer(e){throw new Error("not implemented")}async signMessage(e){throw new Error("not implemented")}}export{m as MnemonicWallet};