@avalabs/core-wallets-sdk 3.1.0-canary.a06f84d.0 → 3.1.0-canary.a1461ba.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +166 -33
- package/esm/Avalanche/index.d.ts +4 -2
- package/esm/Avalanche/index.js +1 -1
- package/esm/Avalanche/models.d.ts +36 -3
- package/esm/Avalanche/models.js +1 -1
- package/esm/Avalanche/providers/AbstractProvider.d.ts +2 -8
- package/esm/Avalanche/providers/AbstractProvider.js +1 -1
- package/esm/Avalanche/providers/JsonRpcProvider.d.ts +4 -4
- package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
- package/esm/Avalanche/utils/appendAutoRenewedValidatorConfigAddressMaps.js +1 -0
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.d.ts +3 -2
- package/esm/Avalanche/utils/createAvalancheEvmUnsignedTx.js +1 -1
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
- package/esm/Avalanche/utils/getAvalancheDerivationPath.d.ts +3 -0
- package/esm/Avalanche/utils/getAvalancheDerivationPath.js +1 -0
- package/esm/Avalanche/utils/getPchainUnixNow.d.ts +3 -1
- package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
- package/esm/Avalanche/utils/getVmByChainAlias.d.ts +1 -1
- package/esm/Avalanche/utils/getXpubFromMnemonic.d.ts +1 -1
- package/esm/Avalanche/utils/getXpubFromMnemonic.js +1 -1
- package/esm/Avalanche/utils/parseAvalancheTx.d.ts +6 -1
- package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
- package/esm/Avalanche/utils/parsers/index.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddAutoRenewedValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseConvertSubnetToL1Tx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseRewardAutoRenewedValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseSetAutoRenewedValidatorConfigTx.js +1 -0
- package/esm/Avalanche/utils/txSizeLimits.js +1 -1
- package/esm/Avalanche/wallets/AddressWallet.js +1 -1
- package/esm/Avalanche/wallets/SimpleSigner.d.ts +1 -1
- package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
- package/esm/Avalanche/wallets/StaticSigner.js +1 -1
- package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +29 -1
- package/esm/Avalanche/wallets/WalletAbstract.d.ts +3 -5
- package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
- package/esm/Avalanche/wallets/WalletVoid.js +1 -1
- package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.d.ts +16 -0
- package/esm/Avalanche/wallets/ledger/LedgerLiveSigner.js +1 -0
- package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.d.ts +4 -2
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
- package/esm/Avalanche/wallets/legacy/LedgerWallet.js +1 -1
- package/esm/Avalanche/wallets/legacy/MnemonicWallet.js +1 -1
- package/esm/Avalanche/wallets/legacy/MnemonicWalletVoid.js +1 -1
- package/esm/BitcoinVM/index.js +1 -1
- package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -1
- package/esm/BitcoinVM/utils/getBech32AddressFromXPub.js +1 -1
- package/esm/BitcoinVM/wallets/BitcoinWallet.js +1 -1
- package/esm/BitcoinVM/wallets/BitcoinWalletLedger.js +1 -1
- package/esm/EVM/LedgerSigner.js +1 -1
- package/esm/EVM/utils/getEvmDerivationPath.d.ts +5 -0
- package/esm/EVM/utils/getEvmDerivationPath.js +1 -0
- package/esm/EVM/utils/getWalletFromMnemonic.js +1 -1
- package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.d.ts +40 -0
- package/esm/SolanaVM/utils/maybeGetAssociatedTokenAccount.js +1 -0
- package/esm/SolanaVM/utils/resolveTokenProgramForMint.d.ts +13 -0
- package/esm/SolanaVM/utils/resolveTokenProgramForMint.js +1 -0
- package/esm/SolanaVM/utils/transferToken.js +1 -1
- package/esm/SolanaVM/wallets/SolanaLedgerSigner.js +1 -1
- package/esm/index.d.ts +3 -0
- package/esm/index.js +1 -1
- package/esm/utils/getAddressDerivationPath.d.ts +8 -5
- package/esm/utils/getAddressDerivationPath.js +1 -1
- package/esm/utils/getPubKeyFromTransport.js +1 -1
- package/package.json +13 -11
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e,utils as a}from"@avalabs/avalanchejs";async function r(r,t,n){try{const d=(await n.getApiP().getTx({txID:t.txId.value()})).unsignedTx;if(!e.isAddAutoRenewedValidatorTx(d))throw new Error("Referenced validator transaction is not an AddAutoRenewedValidatorTx");const o=d.getOwner().addrs,s=t.getAuth().values(),i=o.reduce(((e,a,r)=>(s.includes(r)&&e.push([a,r]),e)),[]);return r.push(new a.AddressMap(i)),r}catch(e){throw new Error(`Error while preparing auto-renewed validator config auth data: ${e.message}`)}}export{r 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:
|
|
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
|
|
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 @@
|
|
|
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(
|
|
6
|
+
declare function getPchainUnixNow(provider: AbstractProvider): Promise<bigint>;
|
|
5
7
|
|
|
6
8
|
export { getPchainUnixNow };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
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};
|
|
@@ -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
|
|
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};
|
|
@@ -7,10 +7,15 @@ type ParseOptions = {
|
|
|
7
7
|
* Tolerance percentage range where the burned amount is considered valid.
|
|
8
8
|
*/
|
|
9
9
|
feeTolerance?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Base fee used for validating burn amount. Priced in nAvax.
|
|
12
|
+
*/
|
|
13
|
+
baseFee?: bigint;
|
|
10
14
|
};
|
|
11
15
|
/**
|
|
12
16
|
* Returns human readable data from a given a transaction buffer,
|
|
13
17
|
*/
|
|
14
|
-
declare function parseAvalancheTx(unsignedTx: Common.UnsignedTx, provider: JsonRpcProvider, currentAddress: string, { feeTolerance }?: ParseOptions): Promise<Tx>;
|
|
18
|
+
declare function parseAvalancheTx(unsignedTx: Common.UnsignedTx, provider: JsonRpcProvider, currentAddress: string, { feeTolerance, baseFee: inputBaseFee }?: ParseOptions): Promise<Tx>;
|
|
15
19
|
|
|
16
20
|
export { parseAvalancheTx };
|
|
21
|
+
export type { ParseOptions };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{utils as t,evmSerial as e}from"@avalabs/avalanchejs";import
|
|
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
|
|
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 d from"./parseRemoveSubnetValidatorTx.js";import m 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";import u from"./parseRewardAutoRenewedValidatorTx.js";var A={parseCreateSubnetTx:r,parseCreateChainTx:e,parseAddSubnetValidatorTx:a,parseRemoveSubnetValidatorTx:d,parseImportTx:s,parseExportTx:o,parseBaseTx:t,parseAddPermissionlessValidatorTx:p,parseAddPermissionlessDelegatorTx:i,parseTransferSubnetOwnershipTx:m,parseConvertSubnetTx:x,parseRegisterL1ValidatorTx:T,parseIncreaseL1ValidatorBalanceTx:f,parseSetL1ValidatorWeightTx:n,parseDisableL1ValidatorTx:l,parseAddAutoRenewedValidatorTx:V,parseSetAutoRenewedValidatorConfigTx:j,parseRewardAutoRenewedValidatorTx:u};export{A as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e,utils as r}from"@avalabs/avalanchejs";import{TxType as a}from"../../models.js";var t=t=>{if(!e.isAddAutoRenewedValidatorTx(t))return null;let o,n;return e.isSigner(t.signer)&&(n=r.bufferToHex(t.signer.proof.publicKey),o=r.bufferToHex(t.signer.proof.signature)),({feeData:e})=>({type:a.AddAutoRenewedValidator,chain:t.getVM(),nodeID:t.nodeId.value(),stake:t.weight.value(),stakeOuts:t.stake,rewardOwner:t.getValidatorRewardsOwner(),delegationRewardOwner:t.getDelegatorRewardsOwner(),owner:t.getOwner(),delegationFee:t.shares.value(),weight:t.weight.value(),autoCompoundRewardShares:t.autoCompoundRewardShares.value(),period:t.period.value(),signer:t.signer,publicKey:n,signature:o,...e})};export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pvmSerial as e,NodeId as a
|
|
1
|
+
import{pvmSerial as e,NodeId as a}from"@avalabs/avalanchejs";import{TxType as n}from"../../models.js";var t=t=>e.isConvertSubnetToL1Tx(t)?({feeData:e,provider:r})=>{const s=r.getHrp(),o=e=>`P-${e.toString(s)}`;return{type:n.ConvertSubnetToL1,chain:t.getVM(),managerAddress:`0x${t.address.toString("hex")}`,validators:t.validators.map((e=>({nodeId:a.fromHex(e.nodeId.toString("hex")).toString(),stake:e.weight.value(),balance:e.balance.value(),remainingBalanceOwners:e.remainingBalanceOwner.addresses.map(o),deactivationOwners:e.deactivationOwner.addresses.map(o)}))),chainID:t.chainID.value(),subnetID:t.subnetID.value(),...e}}:null;export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";var t=t=>a.isRewardAutoRenewedValidatorTx(t)?({feeData:a})=>({type:e.RewardAutoRenewedValidator,chain:t.getVM(),txId:t.txId.value(),...a}):null;export{t 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{utils as e}from"@avalabs/avalanchejs";import{getUnixNow as
|
|
1
|
+
import{utils as e,Common as t}from"@avalabs/avalanchejs";import{getUnixNow as o}from"./getUnixNow.js";import{binarySearch as s}from"../../utils/binarySearch.js";import{sortUTXOsByAmountDescending as r,sortUTXOsStaking as n,sortUTXOsByAmountAscending as d}from"./sortUTXOs.js";const{getUtxoInfo:i}=e;var a=(e=>(e.ExportP="ExportP",e.ImportP="ImportP",e.AddPermissionlessValidator="AddPermissionlessValidator",e.AddPermissionlessDelegator="AddPermissionlessDelegator",e.BaseP="BaseP",e.ConsolidateP="ConsolidateP",e))(a||{});const u="NodeID-8TArWpFgH3sazEH8qP4gUjtGtFMvjw1aR",c="11111111111111111111111111111111LpoYY",l=(e,t)=>e.reduce(((e,t)=>e+i(t).amount),BigInt(0))-t,x={BaseP:{sortFunction:r,unsignedTxBuilder:(t,o,s)=>{const r=t.getProvider().getContext();return t.baseTX({utxoSet:new e.UtxoSet(o),chain:"P",toAddress:t.getCurrentAddress("P"),amountsPerAsset:{[r.avaxAssetID]:l(o,r.baseTxFee)},feeState:s})}},ConsolidateP:{sortFunction:d,unsignedTxBuilder:(t,o,s)=>{const r=t.getProvider().getContext();return t.consolidateP({utxoSet:new e.UtxoSet(o),amount:l(o,r.baseTxFee),feeState:s})}},AddPermissionlessValidator:{sortFunction:n,unsignedTxBuilder:(t,s,r)=>t.addPermissionlessValidator({utxoSet:new e.UtxoSet(s),nodeId:u,start:o(),end:o()+BigInt(1e3),weight:l(s,t.getProvider().getContext().baseTxFee),subnetId:c,shares:5,feeState:r,fromAddresses:void 0,rewardAddresses:void 0,delegatorRewardAddresses:void 0,publicKey:Buffer.from(e.hexToBuffer("0x8f95423f7142d00a48e1014a3de8d28907d420dc33b3052a6dee03a3f2941a393c2351e354704ca66a3fc29870282e15")),signature:Buffer.from(e.hexToBuffer("0x86a3ab4c45cfe31cae34c1d06f212434ac71b1be6cfe046c80c162e057614a94a5bc9f1ded1a7029deb0ba4ca7c9b71411e293438691be79c2dbf19d1ca7c3eadb9c756246fc5de5b7b89511c7d7302ae051d9e03d7991138299b5ed6a570a98"))})},AddPermissionlessDelegator:{sortFunction:n,unsignedTxBuilder:(t,s,r)=>t.addPermissionlessDelegator({utxoSet:new e.UtxoSet(s),nodeId:u,start:o(),end:o()+BigInt(1e3),weight:l(s,t.getProvider().getContext().baseTxFee),subnetId:c,feeState:r})},ExportP:{sortFunction:r,unsignedTxBuilder:(o,s,r)=>{const n=o.getProvider().getContext(),d=function({numberIns:e=1},o){const s=t.createDimensions({bandwidth:161*e+254,dbRead:e,dbWrite:2+e,compute:200*e});return t.dimensionsToGas(s,o)}({numberIns:s.length},n.platformFeeConfig.weights),i=r?d*r.price:n.baseTxFee;return o.exportP({amount:l(s,i),utxoSet:new e.UtxoSet(s),destination:"X",feeState:r})}},ImportP:{sortFunction:r,unsignedTxBuilder:(t,o,s)=>t.importP({utxoSet:new e.UtxoSet(o),sourceChain:"X",feeState:s})}},f=65536;function g({wallet:e,utxos:t,sizeSupportedTx:r,limit:n=65536,feeState:d}){const{sortFunction:a,unsignedTxBuilder:u}=x[r],c=o(),l=a(t.filter((e=>{const{locktime:t,stakeableLocktime:o}=i(e);return t<c&&(o<c||("AddPermissionlessDelegator"===r||"AddPermissionlessValidator"===r))}))),f=s(l,(t=>{try{return function(e){const t=e.getInputUtxos().reduce(((e,t)=>e+(8+65*i(t).threshold)),0);return 6+e.toBytes().length+t}(u(e,t,d))}catch(e){return console.log("Unable to estimate size of utxos",{e:e,utxos:t.map(i)}),n+1}}),n);return-1===f?[]:l.slice(0,f+1)}export{f as P_CHAIN_TX_SIZE_LIMIT,a as SizeSupportedTx,g as getMaximumUtxoSet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletAbstract as s}from"./WalletAbstract.js";import"../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"
|
|
1
|
+
import{WalletAbstract as s}from"./WalletAbstract.js";import"../utils/addSignaturesToAvalancheTx.js";import"../utils/convertGlacierUtxo.js";import"../utils/createAvalancheEvmUnsignedTx.js";import"../utils/createAvalancheUnsignedTx.js";import"create-hash";import"bip32";import"@avalabs/avalanchejs";import"../utils/getAssetBalance.js";import"../utils/getUtxosByTxFromGlacier.js";import"bip39";import{isBech32Address as e}from"../utils/isBech32Address.js";import"../utils/parseAvalancheTx.js";import"../utils/populateCredential.js";import"../utils/txSizeLimits.js";import"bip32-path";import{isAddress as r}from"ethers";class t extends s{constructor(s,t,i,a,d){if(super(d),this.addressC=s,this.addressCoreEth=t,this.xpAddresses=i,this.xpChangeAddress=a,i.length<1)throw new Error("Must have at least 1 xp address.");if(!r(s))throw new Error("Not a valid C-Chain (EVM) address");if(i.some((s=>!e(s,!1))))throw new Error("Given addresses must be valid avalanche bech32 addresses without the chain alias prefix");if(!e(t,!1))throw new Error("Given CoreEth address must be valid avalanche bech32 addresses without the chain alias prefix");this.setChangeAddress(a)}setChangeAddress(s){if(!e(s,!1))throw new Error("Given address must be valid avalanche bech32 addresses without the chain alias prefix");this.xpChangeAddress=s}getAddressEVM(){return this.addressC}getAddresses(s){return("C"===s?[this.addressCoreEth]:this.xpAddresses).map((e=>this.provider.formatAddress(e,s)))}getChangeAddress(s){const e="C"===s?this.addressCoreEth:this.xpChangeAddress;return this.provider.formatAddress(e,s)}getCurrentAddress(s){const e="C"===s?this.addressCoreEth:this.xpAddresses[0];return this.provider.formatAddress(e,s)}}export{t as AddressWallet};
|
|
@@ -10,7 +10,7 @@ import { Signer, SignTxRequest, SignTxBufferRequest, SignMessageRequest } from '
|
|
|
10
10
|
*/
|
|
11
11
|
declare class SimpleSigner implements Signer {
|
|
12
12
|
/**
|
|
13
|
-
* Node for `m/44'/9000'/
|
|
13
|
+
* Node for `m/44'/9000'/n'`
|
|
14
14
|
* @private {BIP32Interface}
|
|
15
15
|
*/
|
|
16
16
|
private accountNodeXP;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import"@ledgerhq/hw-app-eth";import"ethers";import{
|
|
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"
|
|
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};
|
|
@@ -164,6 +164,34 @@ type RemoveSubnetValidator = {
|
|
|
164
164
|
fromAddresses?: string[];
|
|
165
165
|
options?: Common.SpendOptions;
|
|
166
166
|
};
|
|
167
|
+
type AddAutoRenewedValidator = {
|
|
168
|
+
utxoSet: utils.UtxoSet;
|
|
169
|
+
nodeId: string;
|
|
170
|
+
weight: bigint;
|
|
171
|
+
shares: number;
|
|
172
|
+
feeState: pvm.FeeState;
|
|
173
|
+
fromAddresses?: string[];
|
|
174
|
+
rewardAddresses?: string[];
|
|
175
|
+
delegatorRewardAddresses?: string[];
|
|
176
|
+
ownerAddresses?: string[];
|
|
177
|
+
publicKey?: Buffer;
|
|
178
|
+
signature?: Buffer;
|
|
179
|
+
autoCompoundRewardShares: number;
|
|
180
|
+
period: bigint;
|
|
181
|
+
options?: Common.SpendOptions;
|
|
182
|
+
locktime?: bigint;
|
|
183
|
+
threshold?: number;
|
|
184
|
+
};
|
|
185
|
+
type SetAutoRenewedValidatorConfig = {
|
|
186
|
+
utxoSet: utils.UtxoSet;
|
|
187
|
+
feeState: pvm.FeeState;
|
|
188
|
+
validatorTxId: string;
|
|
189
|
+
auth: number[];
|
|
190
|
+
autoCompoundRewardShares: number;
|
|
191
|
+
period: bigint;
|
|
192
|
+
fromAddresses?: string[];
|
|
193
|
+
options?: Common.SpendOptions;
|
|
194
|
+
};
|
|
167
195
|
type TransferSubnetOwnershipTx = {
|
|
168
196
|
utxoSet: utils.UtxoSet;
|
|
169
197
|
subnetId: string;
|
|
@@ -176,4 +204,4 @@ type TransferSubnetOwnershipTx = {
|
|
|
176
204
|
locktime?: bigint;
|
|
177
205
|
};
|
|
178
206
|
|
|
179
|
-
export type { AddPermissionlessDelegator, AddPermissionlessValidator, AddSubnetValidator, BaseTx, ConsolidateP, ConvertSubnetToL1, CreateChain, CreateSubnet, DisableL1Validator, ExportP, ImportP, IncreaseL1ValidatorBalance, RegisterL1Validator, RemoveSubnetValidator, SetL1ValidatorWeight, TransferSubnetOwnershipTx };
|
|
207
|
+
export type { AddAutoRenewedValidator, AddPermissionlessDelegator, AddPermissionlessValidator, AddSubnetValidator, BaseTx, ConsolidateP, ConvertSubnetToL1, CreateChain, CreateSubnet, DisableL1Validator, ExportP, ImportP, IncreaseL1ValidatorBalance, RegisterL1Validator, RemoveSubnetValidator, SetAutoRenewedValidatorConfig, SetL1ValidatorWeight, TransferSubnetOwnershipTx };
|
|
@@ -2,7 +2,7 @@ import * as _avalabs_avalanchejs from '@avalabs/avalanchejs';
|
|
|
2
2
|
import { utils, pvm, Common } from '@avalabs/avalanchejs';
|
|
3
3
|
import { AbstractProvider } from '../providers/AbstractProvider.js';
|
|
4
4
|
import { ChainIDAlias } from '../models.js';
|
|
5
|
-
import { ImportP, ExportP, ConsolidateP, BaseTx, ConvertSubnetToL1, RegisterL1Validator, SetL1ValidatorWeight, DisableL1Validator, IncreaseL1ValidatorBalance, CreateChain, CreateSubnet, AddSubnetValidator, AddPermissionlessValidator, AddPermissionlessDelegator, RemoveSubnetValidator, TransferSubnetOwnershipTx } from './TxBuilderTypes.js';
|
|
5
|
+
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,10 +49,6 @@ 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
52
|
exportX(amount: bigint, utxoSet: utils.UtxoSet, destination: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
57
53
|
importP({ utxoSet, sourceChain, toAddress, threshold, feeState, locktime, }: ImportP): Common.UnsignedTx;
|
|
58
54
|
importX(utxos: utils.UtxoSet, sourceChain: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
@@ -89,6 +85,8 @@ declare abstract class WalletAbstract {
|
|
|
89
85
|
setL1ValidatorWeight({ utxoSet, feeState, message, options, fromAddresses, }: SetL1ValidatorWeight): Common.UnsignedTx;
|
|
90
86
|
disableL1Validator({ utxoSet, feeState, options, fromAddresses, disableAuth, validationId, }: DisableL1Validator): Common.UnsignedTx;
|
|
91
87
|
increaseL1ValidatorBalance({ utxoSet, feeState, options, fromAddresses, balance, validationId, }: IncreaseL1ValidatorBalance): Common.UnsignedTx;
|
|
88
|
+
addAutoRenewedValidator({ utxoSet, nodeId, weight, shares, feeState, fromAddresses, rewardAddresses, delegatorRewardAddresses, ownerAddresses, publicKey, signature, autoCompoundRewardShares, period, options, locktime, threshold, }: AddAutoRenewedValidator): Common.UnsignedTx;
|
|
89
|
+
setAutoRenewedValidatorConfig({ utxoSet, feeState, validatorTxId, auth, autoCompoundRewardShares, period, fromAddresses, options, }: SetAutoRenewedValidatorConfig): Common.UnsignedTx;
|
|
92
90
|
createBlockchain({ utxoSet, subnetId, chainName, vmID, fxIds, genesisData, subnetAuth, feeState, options, fromAddresses, }: CreateChain): Common.UnsignedTx;
|
|
93
91
|
createSubnet({ utxoSet, rewardAddresses, feeState, fromAddresses, options, threshold, locktime, }: CreateSubnet): Common.UnsignedTx;
|
|
94
92
|
addSubnetValidator({ utxoSet, nodeId, start, end, weight, subnetId, subnetAuth, feeState, fromAddresses, options, }: AddSubnetValidator): Common.UnsignedTx;
|
|
@@ -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 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:l}=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=f(o)[2],i=this.provider.getAvaxID(),a=t.fromNative(i,e,[n]),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:o,locktime:n}){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(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=>f(e)[2])),n=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],o,{changeAddresses:[n]})}importC(e,s,t,r,d){const n=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 o.newImportTxFromBaseFee(this.provider.getContext(),a,i,e.getUTXOs(),n,t,r)}exportC(e,s,t,r,d){const n=l(this.getAddressEVM()),i=this.provider.getChainID(s);d=d||this.getCurrentAddress(s);const a=f(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=f(n)[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(o),d.newExportTx({changeAddressesBytes:[c],fromAddressesBytes:A,utxos:h,outputs:[m],destinationChainId:u,feeState:o},this.provider.getContext())}consolidateP({utxoSet:e,amount:s,feeState:r,toAddress:o,options:n}){const i=u(e.getUTXOs());o=o??this.getCurrentAddress("P");const a=f(o)[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=n?.changeAddresses??[A];return p(r),d.newBaseTx({changeAddressesBytes:c,fromAddressesBytes:g,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,u,A]=f(o);if(h!==s||u!==this.provider.getHrp())throw new Error(`Invalid recipient address "${o}"`);const c=Object.entries(n).map((([e,s])=>t.fromNative(e,s,[A]))),l=g(e.getUTXOs(),!0),x=(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(),x,l,c,a):(p(i),d.newBaseTx({changeAddressesBytes:I,fromAddressesBytes:x,utxos:l,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:u,options:A,fromAddresses:c}){const p=(c??this.getAddresses("P")).map((e=>f(e)[2])),l=f(this.getChangeAddress("P"))[2],x=A?.changeAddresses??[l],T=u.map((({nodeId:e,pubKey:t,signature:r,balance:d,weight:o,deactivationOwner:m,remainingBalanceOwner:h})=>{const g=new n.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,o,d,g,u,A)}));return d.newConvertSubnetToL1Tx({changeAddressesBytes:x,validators:T,fromAddressesBytes:p,address:f(h)[2],chainId:t,subnetId:r,subnetAuth:o,feeState:m,utxos:g(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=>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: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=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=o?.changeAddresses??[a];return d.newSetL1ValidatorWeightTx({utxos:g(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=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=t?.changeAddresses??[a];return d.newDisableL1ValidatorTx({disableAuth:o,validationId:n,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:o,validationId:n}){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:o,validationId:n,utxos:g(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:g,autoCompoundRewardShares:u,period:c,options:p,locktime:l,threshold:x}){const T=A(e.getUTXOs()),I=(n??this.getAddresses("P")).map((e=>f(e)[2])),C=(i??[this.getCurrentAddress("P")]).map((e=>f(e)[2])),v=(a??[this.getCurrentAddress("P")]).map((e=>f(e)[2])),S=(m??[this.getCurrentAddress("P")]).map((e=>f(e)[2])),w=f(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:g,locktime:l,threshold:x,ownerAddresses:S,autoCompoundRewardShares:u,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=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],u=a?.changeAddresses??[h];return d.newSetAutoRenewedValidatorConfigTx({utxos:g(e.getUTXOs(),!0),changeAddressesBytes:u,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 u=g(e.getUTXOs(),!0),A=(h??this.getAddresses("P")).map((e=>f(e)[2])),c=f(this.getChangeAddress("P"))[2],l=m?.changeAddresses??[c];return p(a),d.newCreateChainTx({chainName:t,feeState:a,fromAddressesBytes:A,fxIds:o,genesisData:n,subnetAuth:i,subnetId:s,utxos:u,vmId:r,changeAddressesBytes:l},this.provider.getContext())}createSubnet({utxoSet:e,rewardAddresses:s,feeState:t,fromAddresses:r,options:o,threshold:n,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=o?.changeAddresses??[h],A=s.map((e=>f(e)[2]));return p(t),d.newCreateSubnetTx({fromAddressesBytes:m,changeAddressesBytes:u,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 u=g(e.getUTXOs(),!0),A=(m??this.getAddresses("P")).map((e=>f(e)[2])),c=f(this.getChangeAddress("P"))[2],l=h?.changeAddresses??[c];return p(a),d.newAddSubnetValidatorTx({changeAddressesBytes:l,fromAddressesBytes:A,utxos:u,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:g,delegatorRewardAddresses:u,publicKey:c,signature:l,options:x,threshold:T,locktime:I,stakingAssetId:C}){const v=A(e.getUTXOs()),S=(h??this.getAddresses("P")).map((e=>f(e)[2])),w=(g??[this.getCurrentAddress("P")]).map((e=>f(e)[2])),b=(u??[this.getCurrentAddress("P")]).map((e=>f(e)[2]));if(!(n!==m.PrimaryNetworkID.toString()||c&&l))throw new Error("Must provide public key and signature for primary subnet.");const P=f(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:l,locktime:I,threshold:T,stakingAssetId:C},this.provider.getContext())}addPermissionlessDelegator({utxoSet:e,nodeId:s,start:t,end:r,weight:o,subnetId:n,fromAddresses:i,rewardAddresses:a,options:m,locktime:h,feeState:g,threshold:u,stakingAssetId:c}){const l=A(e.getUTXOs()),x=(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],C=m?.changeAddresses??[I];return p(g),d.newAddPermissionlessDelegatorTx({fromAddressesBytes:x,utxos:l,minIssuanceTime:m?.minIssuanceTime,memo:m?.memo,changeAddressesBytes:C,nodeId:s,start:t,end:r,weight:o,subnetId:n,rewardAddresses:T,locktime:h,stakingAssetId:c,threshold:u,feeState:g},this.provider.getContext())}removeSubnetValidator({utxoSet:e,nodeId:s,subnetId:t,subnetAuth:r,fromAddresses:o,feeState:n,options:i}){const a=g(e.getUTXOs(),!0),m=(o??this.getAddresses("P")).map((e=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],u=i?.changeAddresses??[h];return p(n),d.newRemoveSubnetValidatorTx({changeAddressesBytes:u,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=g(e.getUTXOs(),!0),u=(n??this.getAddresses("P")).map((e=>f(e)[2])),A=f(this.getChangeAddress("P"))[2],c=i?.changeAddresses??[A],l=r.map((e=>f(e)[2]));return p(o),d.newTransferSubnetOwnershipTx({changeAddressesBytes:c,fromAddressesBytes:u,utxos:h,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,subnetId:s,subnetAuth:t,subnetOwners:l,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"
|
|
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
|
|
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'
|
|
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
|
|
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{
|
|
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{
|
|
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};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fromBase58 as e,fromSeed as t}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import{WalletVoid as n}from"../WalletVoid.js";import{WalletAbstract as d}from"../WalletAbstract.js";import"@ledgerhq/hw-app-eth";import"ethers";import{
|
|
1
|
+
import{fromBase58 as e,fromSeed as t}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as s}from"bip39";import{WalletVoid as n}from"../WalletVoid.js";import{WalletAbstract as d}from"../WalletAbstract.js";import"@ledgerhq/hw-app-eth";import"ethers";import{getEVMDerivationPath as i}from"../../../EVM/utils/getEvmDerivationPath.js";import{DerivationPath as a}from"../../../EVM/constants.js";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import{utils as o}from"@avalabs/avalanchejs";const{parse:h}=o;class l extends d{constructor(t,r,s){super(s),this.avmXpub=t,this.accountNode=e(t),this.evmWallet=new n(r,r,s)}accountNode;evmWallet;externalIndex=0;internalIndex=0;pubkeyCache={};static fromMnemonic(e,n){if(!r(e))throw new Error("Invalid mnemonic phrase.");const d=s(e),o=t(d),h=o.derivePath("m/44'/9000'/0'").neutered(),m=o.derivePath(i(0,a.BIP44)).neutered();return new l(h.toBase58(),m.publicKey,n)}setExternalIndex(e){if(e<0)throw new Error("Index must be >= 0");this.externalIndex=e}setInternalIndex(e){if(e<0)throw new Error("Index must be >= 0");this.internalIndex=e}getPubKeyAtIndex(e,t=!1){if(e<0)throw new Error("Index must be >= 0");const r=`${t?1:0}/${e}`,s=this.pubkeyCache[r];if(s)return s;const{publicKey:n}=this.accountNode.derivePath(r);return this.pubkeyCache[r]=n,n}getAddressAtIndex(e,t=!1,r){const s=this.getPubKeyAtIndex(e,t);return this.provider.getAddress(s,r)}getExternalAddresses(e){const t=[];for(let r=0;r<=this.externalIndex;r++)t.push(this.getAddressAtIndex(r,!1,e));return t}getInternalAddresses(e){const t=[];for(let r=0;r<=this.internalIndex;r++)t.push(this.getAddressAtIndex(r,!0,e));return t}getAddresses(e){return"C"===e?[this.getCurrentAddress("C")]:"P"===e?[...this.getExternalAddresses(e)]:[...this.getInternalAddresses(e),...this.getExternalAddresses(e)]}getChangeAddress(e){return"C"===e?this.evmWallet.getAddress("C"):"P"===e?this.getAddressAtIndex(this.externalIndex,!1,"P"):this.getAddressAtIndex(this.internalIndex,!0,e)}getCurrentAddress(e){return"C"===e?this.evmWallet.getAddress("C"):this.getAddressAtIndex(this.externalIndex,!1,e)}incrementIndex(e){e?this.externalIndex++:this.internalIndex++}getAddressEVM(){return this.evmWallet.getAddressEVM()}getActiveIndices(){return{external:this.externalIndex,internal:this.internalIndex}}getInternalRawAddresses(){return this.getInternalAddresses("X").map((e=>Buffer.from(h(e)[2])))}getExternalRawAddresses(){return this.getExternalAddresses("X").map((e=>Buffer.from(h(e)[2])))}getRawAddressC(){return Buffer.from(h(this.getCurrentAddress("C"))[2])}}export{l as MnemonicWalletVoid};
|
package/esm/BitcoinVM/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{networks as
|
|
1
|
+
import{networks as a}from"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import"bip32";import"bip39";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"ledger-bitcoin";import"@ledgerhq/hw-app-btc/lib/bip32";import"../Avalanche/wallets/WalletAbstract.js";import"../Avalanche/utils/addSignaturesToAvalancheTx.js";import"../Avalanche/utils/convertGlacierUtxo.js";import"../Avalanche/utils/createAvalancheEvmUnsignedTx.js";import"../Avalanche/utils/createAvalancheUnsignedTx.js";import"create-hash";import"@avalabs/avalanchejs";import"../Avalanche/utils/getAssetBalance.js";import"../Avalanche/utils/getUtxosByTxFromGlacier.js";import"../Avalanche/utils/parseAvalancheTx.js";import"../Avalanche/utils/populateCredential.js";import"../Avalanche/utils/txSizeLimits.js";import"bip32-path";import"@avalabs/hw-app-avalanche";import"../Avalanche/wallets/legacy/MnemonicWalletVoid.js";import"../Avalanche/wallets/legacy/LedgerWallet.js";import"../Avalanche/wallets/legacy/MnemonicWallet.js";import"../Avalanche/wallets/StaticSigner.js";import"../Avalanche/wallets/ledger/LedgerSigner.js";import"../Avalanche/wallets/ledger/SimpleLedgerSigner.js";import"../Avalanche/providers/AbstractProvider.js";import"../Avalanche/providers/constants.js";import"@avalabs/core-chains-sdk";import"@solana/kit";import"@solana-program/system";import"@solana-program/token";import"@solana-program/token-2022";import"@ledgerhq/hw-app-solana";import"@noble/curves/ed25519";import"@scure/base";import"micro-key-producer/slip10.js";import"hdkey";const e=a;export{e as BtcNetworks};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BitcoinProviderAbstract as t}from"./BitcoinProviderAbstract.js";import{networks as e}from"bitcoinjs-lib";import{HttpClient as a}from"@avalabs/core-utils-sdk";import{URL_EXPLORER_MAINNET as s,URL_EXPLORER_TESTNET as r,URL_NODE_MAINNET as i,URL_NODE_TESTNET as n}from"./models.js";import{parseAddressFullTx as o}from"./utils/parseAddressFullTx.js";class l extends t{constructor(t=!0,e,o,l,c){super(),this.isMainnet=t,this.extraParams=c;const m=e?{headers:{"api-key":e}}:{},p=t?s:r;this.#t=new a(o||p,m);const d=t?i:n;this.#e=new a(l||d,m)}#t;#e;async#a(t,e){return this.isMainnet||e?(await Promise.all(t.map((t=>this.#e.post("",t,{},this.extraParams))))).flat():this.#e.post("",t,{},this.extraParams)}async getTxHex(t){return(await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams)).hex}async getUTXOs(t,e=!0,a){const s=await this.#t.post(`/api/v2/utxo/${t}`,{},{},this.extraParams);if(!s?.length)return{confirmed:[],unconfirmed:[]};const r=s.map(this._parseUtxo),i=t=>({confirmed:t.filter((t=>t.confirmations>0)),unconfirmed:t.filter((t=>0===t.confirmations))});if(!e)return i(r);return i(await this.getScriptsForUtxos(r,a))}async getAddressFromScript(t){const e=await this.#e.post("",{jsonrpc:"2.0",id:`decode-script-${t}`,method:"decodescript",params:[t]},{},this.extraParams);if(e.result)return e.result.address;throw new Error(`Unable to resolve address for script: ${t}. ${e.error.message}`)}async getScriptsForUtxos(t,e){const[a,s]=t.reduce((([t,e],a)=>a.script?[[...t,a],e]:[t,[...e,a]]),[[],[]]),r=s.map(((t,e)=>({jsonrpc:"2.0",method:"gettxout",params:[t.txHash,t.index],id:`${e}`}))),i=r.length?(await this.#a(r,e)).sort(((t,e)=>Number(t.id)-Number(e.id))):[];return[...a,...s.map(((t,e)=>({...t,script:i[e]?.result?.scriptPubKey.hex})))]}_parseUtxo(t){return{...t,txHash:t.txid,index:t.vout,value:Number(t.value),blockHeight:t.height,script:t.script,confirmations:t.confirmations}}async getBalances(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams);return{available:BigInt(e.balance),pending:BigInt(e.unconfirmedBalance),final:BigInt(e.balance)+BigInt(e.unconfirmedBalance)}}async getChainHeight(){return(await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"getblockcount",params:[]},{},this.extraParams)).result}async getFeeRates(t){const e={jsonrpc:"2.0",method:"estimatesmartfee"},a=await this.#a([{...e,id:"1",params:[1]},{...e,id:"2",params:[3]},{...e,id:"3",params:[6]}],t).then((t=>t.sort(((t,e)=>Number(t.id)-Number(e.id))).map((t=>1e8*(t.result?.feerate??0)))));return{high:Math.ceil(a[0]/1024)||1,medium:Math.ceil(a[1]/1024)||1,low:Math.ceil(a[2]/1024)||1}}getNetwork(){return this.isMainnet?e.bitcoin:e.testnet}async issueRawTx(t){return await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"sendrawtransaction",params:[t]},{},this.extraParams).then((t=>t.result))}async getTransaction(t){const e=await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams);return{block:e.blockHeight,fees:Number(e.fees),confirmations:e.confirmations,amount:Number(e.value),hash:e.txid,addresses:Array.from(new Set([...e.vin.map((t=>t.addresses||[])).flat(),...e.vout.map((t=>t.addresses||[])).flat()])),blockTime:e.blockTime,inputs:[...e.vin.map((t=>({...t,value:Number(t.value)})))],outputs:[...e.vout.map((t=>({...t,value:Number(t.value)})))]}}async getTxHistory(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams)
|
|
1
|
+
import{BitcoinProviderAbstract as t}from"./BitcoinProviderAbstract.js";import{networks as e}from"bitcoinjs-lib";import{HttpClient as a}from"@avalabs/core-utils-sdk";import{URL_EXPLORER_MAINNET as s,URL_EXPLORER_TESTNET as r,URL_NODE_MAINNET as i,URL_NODE_TESTNET as n}from"./models.js";import{parseAddressFullTx as o}from"./utils/parseAddressFullTx.js";class l extends t{constructor(t=!0,e,o,l,c){super(),this.isMainnet=t,this.extraParams=c;const m=e?{headers:{"api-key":e}}:{},p=t?s:r;this.#t=new a(o||p,m);const d=t?i:n;this.#e=new a(l||d,m)}#t;#e;async#a(t,e){return this.isMainnet||e?(await Promise.all(t.map((t=>this.#e.post("",t,{},this.extraParams))))).flat():this.#e.post("",t,{},this.extraParams)}async getTxHex(t){return(await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams)).hex}async getUTXOs(t,e=!0,a){const s=await this.#t.post(`/api/v2/utxo/${t}`,{},{},this.extraParams);if(!s?.length)return{confirmed:[],unconfirmed:[]};const r=s.map(this._parseUtxo),i=t=>({confirmed:t.filter((t=>t.confirmations>0)),unconfirmed:t.filter((t=>0===t.confirmations))});if(!e)return i(r);return i(await this.getScriptsForUtxos(r,a))}async getAddressFromScript(t){const e=await this.#e.post("",{jsonrpc:"2.0",id:`decode-script-${t}`,method:"decodescript",params:[t]},{},this.extraParams);if(e.result)return e.result.address;throw new Error(`Unable to resolve address for script: ${t}. ${e.error.message}`)}async getScriptsForUtxos(t,e){const[a,s]=t.reduce((([t,e],a)=>a.script?[[...t,a],e]:[t,[...e,a]]),[[],[]]),r=s.map(((t,e)=>({jsonrpc:"2.0",method:"gettxout",params:[t.txHash,t.index],id:`${e}`}))),i=r.length?(await this.#a(r,e)).sort(((t,e)=>Number(t.id)-Number(e.id))):[];return[...a,...s.map(((t,e)=>({...t,script:i[e]?.result?.scriptPubKey.hex})))]}_parseUtxo(t){return{...t,txHash:t.txid,index:t.vout,value:Number(t.value),blockHeight:t.height,script:t.script,confirmations:t.confirmations}}async getBalances(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams);return{available:BigInt(e.balance),pending:BigInt(e.unconfirmedBalance),final:BigInt(e.balance)+BigInt(e.unconfirmedBalance)}}async getChainHeight(){return(await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"getblockcount",params:[]},{},this.extraParams)).result}async getFeeRates(t){const e={jsonrpc:"2.0",method:"estimatesmartfee"},a=await this.#a([{...e,id:"1",params:[1]},{...e,id:"2",params:[3]},{...e,id:"3",params:[6]}],t).then((t=>t.sort(((t,e)=>Number(t.id)-Number(e.id))).map((t=>1e8*(t.result?.feerate??0)))));return{high:Math.ceil(a[0]/1024)||1,medium:Math.ceil(a[1]/1024)||1,low:Math.ceil(a[2]/1024)||1}}getNetwork(){return this.isMainnet?e.bitcoin:e.testnet}async issueRawTx(t){return await this.#e.post("",{jsonrpc:"2.0",id:"nownodes",method:"sendrawtransaction",params:[t]},{},this.extraParams).then((t=>t.result))}async getTransaction(t){const e=await this.#t.post(`/api/v2/tx/${t}`,{},{},this.extraParams);return{block:e.blockHeight,fees:Number(e.fees),confirmations:e.confirmations,amount:Number(e.value),hash:e.txid,addresses:Array.from(new Set([...e.vin.map((t=>t.addresses||[])).flat(),...e.vout.map((t=>t.addresses||[])).flat()])),blockTime:e.blockTime,inputs:[...e.vin.map((t=>({...t,value:Number(t.value)})))],outputs:[...e.vout.map((t=>({...t,value:Number(t.value)})))]}}async getTxHistory(t){const e=await this.#t.post(`/api/v2/address/${t}`,{},{},this.extraParams),a=e.txids?.slice(0,25)??[];return await Promise.allSettled(a.map((async e=>{try{const a=await this.#t.post(`/api/v2/tx/${e}`,{},{},this.extraParams);return o(t,a)}catch(t){console.log(`Unable to parse full tx ${e}.`)}}))).then((t=>t.map((t=>"fulfilled"===t.status&&t.value?t.value:void 0)).filter((t=>void 0!==t))))}async waitForTx(t,{maxAttempts:e=20,attempt:a=1,pollInterval:s=500}={}){try{return await this.getTransaction(t)}catch(r){if(a>=e)throw r;return await new Promise((t=>setTimeout(t,s))),this.waitForTx(t,{maxAttempts:e,attempt:a+1,pollInterval:s})}}}export{l as BitcoinProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@ledgerhq/hw-app-eth";import"ethers";import"
|
|
1
|
+
import"@ledgerhq/hw-app-eth";import"ethers";import"bip32";import{getAddressPublicKeyFromXPub as t}from"../../EVM/utils/getAddressPublicKeyFromXPub.js";import"bip39";import{getBech32Address as r}from"./getBech32Address.js";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";function e(e,i,o){const p=t(e,i);return r(p,o)}export{e as getBech32AddressFromXPub};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ECPair as t}from"bitcoinjs-lib";import{BitcoinWalletAbstract as r}from"./BitcoinWalletAbstract.js";import{createPsbt as e}from"../utils/createPsbt.js";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import{
|
|
1
|
+
import{ECPair as t}from"bitcoinjs-lib";import{BitcoinWalletAbstract as r}from"./BitcoinWalletAbstract.js";import{createPsbt as e}from"../utils/createPsbt.js";import"coinselect";import"@ledgerhq/hw-app-eth";import"ethers";import{DerivationPath as i}from"../../EVM/constants.js";import{fromSeed as o}from"bip32";import{validateMnemonic as s,mnemonicToSeed as n}from"bip39";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"ledger-bitcoin";import"@ledgerhq/hw-app-btc/lib/bip32";import{getAddressDerivationPath as a}from"../../utils/getAddressDerivationPath.js";import"@avalabs/avalanchejs";import"hdkey";class p extends r{keypair;constructor(r,e){const i=t.fromPrivateKey(r);super(i.publicKey,e),this.keypair=i}static async fromMnemonic(t,r,e,m=i.BIP44){if(r<0)throw new Error("Account index must be >= 0");if(!s(t))throw new Error("Invalid mnemonic phrase.");const l=await n(t),c=o(l),h=a(r,"EVM",{pathSpec:m}),f=c.derivePath(h);if(!f.privateKey)throw new Error("Unable to derive private key from the given mnemonic.");return new p(f.privateKey,e)}signTx(t,r){const i=e(t,r,this.provider.getNetwork());return Promise.resolve(this.signPsbt(i))}static fromEthersWallet(t,r){const e=t.privateKey;if(!e)throw new Error("Unable to get private key from ethers wallet.");const i=Buffer.from(e.substring(2),"hex");return new p(i,r)}signPsbt(t){return t.signAllInputs(this.keypair),t.validateSignaturesOfAllInputs(),t.finalizeAllInputs(),t.extractTransaction()}}export{p as BitcoinWallet};
|