@avalabs/core-wallets-sdk 3.1.0-alpha.4 → 3.1.0-alpha.41
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.d.ts +311 -64
- package/dist/index.js +1 -1
- package/esm/Avalanche/index.d.ts +2 -3
- package/esm/Avalanche/index.js +1 -1
- package/esm/Avalanche/models.d.ts +44 -5
- package/esm/Avalanche/models.js +1 -1
- package/esm/Avalanche/providers/AbstractProvider.d.ts +2 -1
- package/esm/Avalanche/providers/AbstractProvider.js +1 -1
- package/esm/Avalanche/providers/JsonRpcProvider.d.ts +1 -0
- package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
- package/esm/Avalanche/providers/constants.d.ts +2 -1
- package/esm/Avalanche/providers/constants.js +1 -1
- package/esm/Avalanche/providers/platformFeeConfig.js +1 -0
- package/esm/Avalanche/utils/appendDisableAuthAddressMaps.js +1 -0
- package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +3 -3
- package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
- package/esm/Avalanche/utils/getAssetBalance.js +1 -1
- package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -1
- package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +5 -2
- package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -1
- package/esm/Avalanche/utils/handleSubnetAuth.js +1 -1
- package/esm/Avalanche/utils/orderBy.js +1 -0
- package/esm/Avalanche/utils/parseAvalancheTx.d.ts +7 -1
- package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
- package/esm/Avalanche/utils/parsers/index.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -1
- package/esm/Avalanche/utils/parsers/parseConvertSubnetToL1Tx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseDisableL1ValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseIncreaseL1ValidatorBalanceTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseRegisterL1ValidatorTx.js +1 -0
- package/esm/Avalanche/utils/parsers/parseSetL1ValidatorWeightTx.js +1 -0
- package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -1
- package/esm/Avalanche/utils/sortUTXOs.d.ts +6 -4
- package/esm/Avalanche/utils/sortUTXOs.js +1 -1
- package/esm/Avalanche/utils/txSizeLimits.d.ts +10 -3
- package/esm/Avalanche/utils/txSizeLimits.js +1 -1
- package/esm/Avalanche/wallets/AddressWallet.js +1 -1
- package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
- package/esm/Avalanche/wallets/StaticSigner.js +1 -1
- package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +179 -0
- package/esm/Avalanche/wallets/WalletAbstract.d.ts +21 -22
- package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
- package/esm/Avalanche/wallets/WalletVoid.js +1 -1
- package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
- package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
- package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +4 -3
- package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -1
- package/esm/BitcoinVM/providers/BitcoinProviderAbstract.d.ts +1 -0
- package/esm/SolanaVM/utils/solanaProvider.d.ts +10 -0
- package/esm/SolanaVM/utils/solanaProvider.js +1 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -1
- package/esm/utils/assertFeeStateProvided.js +1 -0
- package/package.json +8 -6
- package/esm/Avalanche/utils/getUtxoInfo.d.ts +0 -13
- package/esm/Avalanche/utils/getUtxoInfo.js +0 -1
- package/esm/Avalanche/utils/parsers/parseAddDelegatorTx.js +0 -1
- package/esm/Avalanche/utils/parsers/parseAddValidatorTx.js +0 -1
- package/esm/Avalanche/utils/parsers/parseTransformSubnetTx.js +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Utxo as Utxo$1 } from '@avalabs/avalanchejs';
|
|
2
|
-
import { Utxo, PChainUtxo } from '@avalabs/glacier-sdk';
|
|
1
|
+
import { Utxo as Utxo$1, TransferOutput, pvmSerial } from '@avalabs/avalanchejs';
|
|
2
|
+
import { Utxo, PChainUtxo, Network } from '@avalabs/glacier-sdk';
|
|
3
3
|
|
|
4
4
|
type GlacierOutput = Utxo | PChainUtxo;
|
|
5
|
-
declare const convertGlacierUtxo: (glacierUtxo: GlacierOutput,
|
|
5
|
+
declare const convertGlacierUtxo: (glacierUtxo: GlacierOutput, network: Network) => Utxo$1<TransferOutput | pvmSerial.StakeableLockOut<TransferOutput>>;
|
|
6
6
|
|
|
7
7
|
export { GlacierOutput, convertGlacierUtxo };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{UnsignedTx as r,utils as
|
|
1
|
+
import{UnsignedTx as e,pvmSerial as r,utils 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}=a,d=async({tx:a,fromAddressBytes:d,provider:p,credentials:l,utxos:u})=>{const f=o(a);let m=i.fromTransferableInputs(f,u,BigInt(Math.floor((new Date).getTime()/1e3)),d);if(t(a))try{const r=await s({tx:a,provider:p,addressMaps:m});return new e(a,u,r,l)}catch(e){throw new Error(`Error while preparing subnet authorization data: ${e.message}`)}else r.isDisableL1ValidatorTx(a)&&(m=await n(m,a,p));return new e(a,u,m,l)};export{d as createAvalancheUnsignedTx,d as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{utils as t}from"@avalabs/avalanchejs";import{getUnixNow as e}from"./getUnixNow.js";const{getUtxoInfo:a}=t;function o(t,o){const l=t.getAssetDict()[o],i={locked:BigInt(0),available:BigInt(0),multisig:BigInt(0),lockedStakeable:BigInt(0),total:BigInt(0)};if(!l)return i;const n=l.getUTXOs(),c=e();return n.forEach((t=>{const e=a(t);i[e.threshold>1?"multisig":e.locktime>c?"locked":e.stakeableLocktime>c?"lockedStakeable":"available"]+=e.amount})),i.total=i.locked+i.lockedStakeable+i.multisig+i.available,i}export{o as getAssetBalance};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@avalabs/avalanchejs";import"@avalabs/core-utils-sdk";import"ethers";import{FujiContext as
|
|
1
|
+
import{Network as r}from"@avalabs/glacier-sdk";import"@avalabs/avalanchejs";import"@avalabs/core-utils-sdk";import"ethers";import{DevnetContext as a,FujiContext as o,MainnetContext as i}from"../providers/constants.js";import"@avalabs/core-chains-sdk";const n=(n,s)=>{const t=s===r.FUJI,c=s===r.DEVNET,{cBlockchainID:e,xBlockchainID:l,pBlockchainID:p}=c?a:t?o:i;if(e===n)return"C";if(l===n)return"X";if(p===n)return"P";throw new Error(`Unknown chainId "${n}"`)};export{n as getChainAliasByChainId};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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,13 +1,16 @@
|
|
|
1
|
+
import * as _avalabs_avalanchejs_dist_serializable_common_types from '@avalabs/avalanchejs/dist/serializable/common/types';
|
|
2
|
+
import { Network } from '@avalabs/glacier-sdk';
|
|
1
3
|
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
4
|
import { ChainIDAlias } from '../models.js';
|
|
3
5
|
|
|
4
6
|
type Params = {
|
|
5
7
|
transactionHex: string;
|
|
6
8
|
chainAlias: ChainIDAlias;
|
|
7
|
-
|
|
9
|
+
network: Network;
|
|
8
10
|
url: string;
|
|
9
11
|
token?: string;
|
|
12
|
+
headers?: Record<string, string>;
|
|
10
13
|
};
|
|
11
|
-
declare const getUtxosByTxFromGlacier: ({ transactionHex, chainAlias,
|
|
14
|
+
declare const getUtxosByTxFromGlacier: ({ transactionHex, chainAlias, network, url, token, headers, }: Params) => Promise<Utxo<_avalabs_avalanchejs_dist_serializable_common_types.Serializable>[]>;
|
|
12
15
|
|
|
13
16
|
export { getUtxosByTxFromGlacier };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Glacier as t,
|
|
1
|
+
import{Glacier as t,BlockchainId as r}from"@avalabs/glacier-sdk";import{evmSerial as o,utils as e,avmSerial as n,pvmSerial as a,PVM as i,AVM as s,EVM as x}from"@avalabs/avalanchejs";import{getVmByChainAlias as c}from"./getVmByChainAlias.js";import{convertGlacierUtxo as u}from"./convertGlacierUtxo.js";const{getTransferableInputsByTx:I,hexToBuffer:p,unpackWithManager:f}=e,h=async({transactionHex:e,chainAlias:h,network:l,url:m,token:d,headers:w})=>{const D=c(h),g=p(e),T=f(D,g);if(o.isExportTx(T))return[];const E=(t=>{if(o.isImportTx(t)||n.isImportTx(t)||a.isImportTx(t))return t.sourceChain.toString();const e=t.getVM();switch(e){case x:return r.C_CHAIN;case s:return r.X_CHAIN;case i:return r.P_CHAIN;default:throw new Error(`Unable to get chain for VM type "${e}"`)}})(T),H=I(T),b=new t({BASE:m,TOKEN:d,HEADERS:w}),k=[...new Set(H.map((t=>t.utxoID.txID.toString())))],A=await Promise.all(k.map((t=>b.primaryNetworkTransactions.getTxByHash({blockchainId:E,network:l,txHash:t}))));return H.reduce(((t,r)=>{const o=A.find((t=>t.txHash===r.utxoID.txID.toString()));if(!o)throw new Error(`Unable to find parent tx "${r.utxoID.txID.toString()}"`);const e=o.emittedUtxos.find((t=>t.utxoId===r.utxoID.ID()));if(!e)throw new Error(`Unable to find UTXO "${r.utxoID.ID()}" at index "${r.utxoID.outputIdx.value()}"`);const n=u(e,l);return t.push(n),t}),[])};export{h as getUtxosByTxFromGlacier};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pvmSerial as e,utils as s}from"@avalabs/avalanchejs";const t
|
|
1
|
+
import{pvmSerial as e,OutputOwners as t,utils as s}from"@avalabs/avalanchejs";const a=t=>e.isCreateChainTx(t)||e.isAddSubnetValidatorTx(t)||e.isRemoveSubnetValidatorTx(t)||e.isTransformSubnetTx(t)||e.isTransferSubnetOwnershipTx(t)||e.isConvertSubnetToL1Tx(t),r=async({tx:e,provider:a,addressMaps:r})=>{const n=e.getSubnetAuth().values(),i=await a.getApiP().getSubnet({subnetID:e.getSubnetID().value()}),u=t.fromNative(i.controlKeys.map((e=>s.parse(e)[2])),BigInt(i.locktime),Number(i.threshold)).addrs.reduce(((e,t,s)=>(n.includes(s)&&e.push([t,s]),e)),[]);return r.push(new s.AddressMap(u)),r};export{r as handleSubnetAuth,a as isSubnetTx};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(r,t,n){return[...r].sort(((r,e)=>{for(let o=0;o<t.length;o++){const u=t[o];if(r[u]>e[u])return"asc"===n?1:-1;if(r[u]<e[u])return"asc"===n?-1:1}return 0}))}export{r as orderBy};
|
|
@@ -2,9 +2,15 @@ import { Common } from '@avalabs/avalanchejs';
|
|
|
2
2
|
import { Tx } from '../models.js';
|
|
3
3
|
import { JsonRpcProvider } from '../providers/JsonRpcProvider.js';
|
|
4
4
|
|
|
5
|
+
type ParseOptions = {
|
|
6
|
+
/**
|
|
7
|
+
* Tolerance percentage range where the burned amount is considered valid.
|
|
8
|
+
*/
|
|
9
|
+
feeTolerance?: number;
|
|
10
|
+
};
|
|
5
11
|
/**
|
|
6
12
|
* Returns human readable data from a given a transaction buffer,
|
|
7
13
|
*/
|
|
8
|
-
declare function parseAvalancheTx(unsignedTx: Common.UnsignedTx, provider: JsonRpcProvider, currentAddress: string): Promise<Tx>;
|
|
14
|
+
declare function parseAvalancheTx(unsignedTx: Common.UnsignedTx, provider: JsonRpcProvider, currentAddress: string, { feeTolerance }?: ParseOptions): Promise<Tx>;
|
|
9
15
|
|
|
10
16
|
export { parseAvalancheTx };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{evmSerial as t,utils as e}from"@avalabs/avalanchejs";import{TxType as n}from"../models.js";import a from"./parsers/index.js";const{getBurnedAmountByTx:r,getOutputAmounts:o,getInputAmounts:s,validateBurnedAmount:
|
|
1
|
+
import{evmSerial as t,utils as e}from"@avalabs/avalanchejs";import{TxType as n}from"../models.js";import a from"./parsers/index.js";const{getBurnedAmountByTx:r,getOutputAmounts:o,getInputAmounts:s,validateBurnedAmount:i}=e;async function u(e,u,x,{feeTolerance:g=50}={}){try{const n=u.getContext(),c=e.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")})(c),A=r(c,n),d=o(c),l=s(c).get(n.avaxAssetID)??BigInt(0),m=A.get(n.avaxAssetID)??BigInt(0),v=d.get(n.avaxAssetID)??BigInt(0);let I=BigInt(0);t.isImportExportTx(c)?I=await u.getApiC().getBaseFee()/BigInt(1e9):"PVM"===c.vm&&(I=await u.getApiP().getFeeState().then((t=>t.price)).catch((()=>BigInt(0))));const{isValid:f,txFee:B}=i({unsignedTx:e,context:n,burnedAmount:m,baseFee:I,feeTolerance:g});return await p({feeData:{totalAvaxBurned:m,totalAvaxOutput:v,totalAvaxInput:l,isValidAvaxBurnedAmount:f,txFee:B},assetId:n.avaxAssetID,provider:u,currentAddress:x})}catch(t){return{type:n.Unknown}}}export{u as parseAvalancheTx};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r from"./
|
|
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 +1 @@
|
|
|
1
|
-
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as a}from"../../models.js";const t=t=>e.isAddPermissionlessDelegatorTx(t)?({feeData:e
|
|
1
|
+
import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as a}from"../../models.js";const t=t=>e.isAddPermissionlessDelegatorTx(t)?({feeData:e})=>({type:a.AddPermissionlessDelegator,chain:t.getVM(),stake:t.subnetValidator.validator.weight.value(),nodeID:t.subnetValidator.validator.nodeId.value(),start:t.subnetValidator.validator.startTime.value().toString(),end:t.subnetValidator.validator.endTime.value().toString(),subnetID:t.subnetValidator.subnetId.value(),stakeOuts:t.stake,delegatorRewardsOwner:t.getDelegatorRewardsOwner(),...e}):null;export{t as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{pvmSerial as e,utils as a}from"@avalabs/avalanchejs";import{TxType as
|
|
1
|
+
import{pvmSerial as e,utils as a}from"@avalabs/avalanchejs";import{TxType as r}from"../../models.js";const t=t=>{if(!e.isAddPermissionlessValidatorTx(t))return null;let s,i;return e.isSigner(t.signer)&&(i=a.bufferToHex(t.signer.proof.publicKey),s=a.bufferToHex(t.signer.proof.signature)),({feeData:e})=>({type:r.AddPermissionlessValidator,chain:t.getVM(),stake:t.subnetValidator.validator.weight.value(),nodeID:t.subnetValidator.validator.nodeId.value(),start:t.subnetValidator.validator.startTime.value().toString(),end:t.subnetValidator.validator.endTime.value().toString(),subnetID:t.subnetValidator.subnetId.value(),delegationFee:t.shares.value(),stakeOuts:t.stake,rewardOwner:t.getValidatorRewardsOwner(),delegationRewardOwner:t.getDelegatorRewardsOwner(),signer:t.signer,publicKey:i,signature:s,...e})};export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as e,Address as a,NodeId as n}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const r=r=>e.isConvertSubnetToL1Tx(r)?({feeData:e,provider:o})=>{const s=o.getHrp(),i=e=>`P-${e.toString(s)}`;return{type:t.ConvertSubnetToL1,chain:r.getVM(),managerAddress:i(a.fromHex(r.address.toString("hex"))),validators:r.validators.map((e=>({nodeId:n.fromHex(e.nodeId.toString("hex")).toString(),stake:e.weight.value(),balance:e.balance.value(),remainingBalanceOwners:e.remainingBalanceOwner.addresses.map(i),deactivationOwners:e.deactivationOwner.addresses.map(i)}))),chainID:r.chainID.value(),subnetID:r.subnetID.value(),...e}}:null;export{r as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const i=i=>a.isDisableL1ValidatorTx(i)?({feeData:a})=>({type:t.DisableL1Validator,chain:i.getVM(),validationId:i.validationId.toString(),...a}):null;export{i as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";const l=l=>a.isIncreaseL1ValidatorBalanceTx(l)?({feeData:a})=>({type:e.IncreaseL1ValidatorBalance,chain:l.getVM(),balance:l.balance.value(),validationId:l.validationId.toString(),...a}):null;export{l as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";const t=t=>a.isRegisterL1ValidatorTx(t)?({feeData:a})=>({type:e.RegisterL1Validator,chain:t.getVM(),balance:t.balance.value(),...a}):null;export{t as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as t}from"../../models.js";const e=e=>a.isSetL1ValidatorWeightTx(e)?({feeData:a})=>({type:t.SetL1ValidatorWeight,chain:e.getVM(),...a}):null;export{e as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import"@avalabs/avalanchejs";import"@avalabs/core-utils-sdk";import"ethers";import{MainnetContext as
|
|
1
|
+
import"@avalabs/avalanchejs";import"@avalabs/core-utils-sdk";import"ethers";import{MainnetContext as c,FujiContext as a,DevnetContext as i}from"../../../providers/constants.js";import"@avalabs/core-chains-sdk";const n=n=>{if([c.xBlockchainID,a.xBlockchainID,i.xBlockchainID].includes(n))return"AVM";if([c.pBlockchainID,a.pBlockchainID,i.pBlockchainID].includes(n))return"PVM";if([c.cBlockchainID,a.cBlockchainID,i.cBlockchainID].includes(n))return"EVM";throw new Error("Unknown chain id. Failed to get alias.")};export{n as default};
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
+
import * as _avalabs_avalanchejs_dist_serializable_common_types from '@avalabs/avalanchejs/dist/serializable/common/types';
|
|
1
2
|
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* The UTXOs will be sorted in the following order.
|
|
5
|
-
* 1-
|
|
6
|
-
* 2-
|
|
6
|
+
* 1- Highest value unlocked UTXO (for fees)
|
|
7
|
+
* 2- LockedStakeable UTXOs with the highest locktime to lowest
|
|
8
|
+
* 3- Rest of the unlocked UTXOs highest to lowest
|
|
7
9
|
* @remark Does not check for locked UTXOs
|
|
8
10
|
*/
|
|
9
11
|
declare function sortUTXOsStaking(utxos: Utxo[]): Utxo[];
|
|
10
12
|
declare function sortUTXOsByAmount(utxos: Utxo[], isDescending: boolean): Utxo[];
|
|
11
|
-
declare const sortUTXOsByAmountDescending: (utxos: Utxo[]) => Utxo[];
|
|
12
|
-
declare const sortUTXOsByAmountAscending: (utxos: Utxo[]) => Utxo[];
|
|
13
|
+
declare const sortUTXOsByAmountDescending: (utxos: Utxo[]) => Utxo<_avalabs_avalanchejs_dist_serializable_common_types.Serializable>[];
|
|
14
|
+
declare const sortUTXOsByAmountAscending: (utxos: Utxo[]) => Utxo<_avalabs_avalanchejs_dist_serializable_common_types.Serializable>[];
|
|
13
15
|
|
|
14
16
|
export { sortUTXOsByAmount, sortUTXOsByAmountAscending, sortUTXOsByAmountDescending, sortUTXOsStaking };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{utils as t}from"@avalabs/avalanchejs";
|
|
1
|
+
import{utils as t}from"@avalabs/avalanchejs";import{getUnixNow as o}from"./getUnixNow.js";import{orderBy as e}from"./orderBy.js";function a(a){const m=o(),n=a.map((o=>({utxo:o,...t.getUtxoInfo(o)}))),r=n.filter((t=>t.stakeableLocktime<=m)),s=n.filter((t=>t.stakeableLocktime>m)),c=e(r,["amount"],"desc"),i=e(s,["stakeableLocktime","amount"],"desc"),[u,...f]=c;return[...u?[u]:[],...i,...f].map((t=>t.utxo))}function m(o,a){const m=o.map((o=>({utxo:o,...t.getUtxoInfo(o)})));return e(m,["amount"],a?"desc":"asc").map((t=>t.utxo))}const n=t=>m(t,!0),r=t=>m(t,!1);export{m as sortUTXOsByAmount,r as sortUTXOsByAmountAscending,n as sortUTXOsByAmountDescending,a as sortUTXOsStaking};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Utxo } from '@avalabs/avalanchejs';
|
|
2
|
-
import { WalletAbstract } from '
|
|
1
|
+
import { Utxo, pvm } from '@avalabs/avalanchejs';
|
|
2
|
+
import { WalletAbstract } from '../wallets/WalletAbstract.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The list of transaction types supported by `getMaximumUtxoSet`.
|
|
@@ -25,8 +25,15 @@ declare const P_CHAIN_TX_SIZE_LIMIT = 65536;
|
|
|
25
25
|
* @param utxos - list of UTXOs to be consumed by the transaction.
|
|
26
26
|
* @param sizeSupportedTx - one of the supported transaction types
|
|
27
27
|
* @param limit - optional - byte size limit, defaults to 64kb.
|
|
28
|
+
* @param feeState - current fee state on the chain
|
|
28
29
|
* @returns the largest prefix of sorted `utxos` before hitting the size limit. If no such prefix exists, then an empty array.
|
|
29
30
|
*/
|
|
30
|
-
declare function getMaximumUtxoSet(wallet
|
|
31
|
+
declare function getMaximumUtxoSet({ wallet, utxos, sizeSupportedTx, limit, feeState, }: {
|
|
32
|
+
wallet: WalletAbstract;
|
|
33
|
+
utxos: Utxo[];
|
|
34
|
+
sizeSupportedTx: SizeSupportedTx;
|
|
35
|
+
limit?: number;
|
|
36
|
+
feeState?: pvm.FeeState;
|
|
37
|
+
}): Utxo[];
|
|
31
38
|
|
|
32
39
|
export { P_CHAIN_TX_SIZE_LIMIT, SizeSupportedTx, getMaximumUtxoSet };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{utils as e}from"@avalabs/avalanchejs";import{
|
|
1
|
+
import{utils as e}from"@avalabs/avalanchejs";import{getUnixNow as t}from"./getUnixNow.js";import{binarySearch as o}from"../../utils/binarySearch.js";import{sortUTXOsByAmountDescending as s,sortUTXOsByAmountAscending as r,sortUTXOsStaking as n}from"./sortUTXOs.js";const{getUtxoInfo:d}=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 i="NodeID-8TArWpFgH3sazEH8qP4gUjtGtFMvjw1aR",u="11111111111111111111111111111111LpoYY",c=(e,t)=>e.reduce(((e,t)=>e+d(t).amount),BigInt(0))-t,l={BaseP:{sortFunction:s,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]:c(o,r.baseTxFee)},feeState:s})}},ConsolidateP:{sortFunction:r,unsignedTxBuilder:(t,o,s)=>{const r=t.getProvider().getContext();return t.consolidateP({utxoSet:new e.UtxoSet(o),amount:c(o,r.baseTxFee),feeState:s})}},AddPermissionlessValidator:{sortFunction:n,unsignedTxBuilder:(o,s,r)=>o.addPermissionlessValidator({utxoSet:new e.UtxoSet(s),nodeId:i,start:t(),end:t()+BigInt(1e3),weight:c(s,o.getProvider().getContext().baseTxFee),subnetId:u,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:(o,s,r)=>o.addPermissionlessDelegator({utxoSet:new e.UtxoSet(s),nodeId:i,start:t(),end:t()+BigInt(1e3),weight:c(s,o.getProvider().getContext().baseTxFee),subnetId:u,feeState:r})},ExportP:{sortFunction:s,unsignedTxBuilder:(t,o,s)=>t.exportP({amount:c(o,t.getProvider().getContext().baseTxFee),utxoSet:new e.UtxoSet(o),destination:"X",feeState:s})},ImportP:{sortFunction:s,unsignedTxBuilder:(t,o,s)=>t.importP({utxoSet:new e.UtxoSet(o),sourceChain:"X",feeState:s})}},x=65536;function f({wallet:e,utxos:s,sizeSupportedTx:r,limit:n=65536,feeState:a}){const{sortFunction:i,unsignedTxBuilder:u}=l[r],c=t(),x=i(s.filter((e=>{const{locktime:t,stakeableLocktime:o}=d(e);return t<c&&(o<c||("AddPermissionlessDelegator"===r||"AddPermissionlessValidator"===r))}))),f=o(x,(t=>{try{return function(e){const t=e.getInputUtxos().reduce(((e,t)=>e+(8+65*d(t).threshold)),0);return 6+e.toBytes().length+t}(u(e,t,a))}catch(e){return console.log("Unable to estimate size of utxos",{e:e,utxos:t.map(d)}),n+1}}),n);return-1===f?[]:x.slice(0,f+1)}export{x as P_CHAIN_TX_SIZE_LIMIT,a as SizeSupportedTx,f as getMaximumUtxoSet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletAbstract as s}from"./WalletAbstract.js";import"@avalabs/avalanchejs";import"../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import{isAddress as e}from"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import"
|
|
1
|
+
import{WalletAbstract as s}from"./WalletAbstract.js";import"@avalabs/avalanchejs";import"../utils/populateCredential.js";import"@avalabs/glacier-sdk";import"@avalabs/core-utils-sdk";import{isAddress as e}from"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import"bip39";import{isBech32Address as r}from"../utils/isBech32Address.js";import"xss";import"bip32-path";class t extends s{constructor(s,t,a,d,i){if(super(i),this.addressC=s,this.addressCoreEth=t,this.xpAddresses=a,this.xpChangeAddress=d,a.length<1)throw new Error("Must have at least 1 xp address.");if(!e(s))throw new Error("Not a valid C-Chain (EVM) address");if(a.some((s=>!r(s,!1))))throw new Error("Given addresses must be valid avalanche bech32 addresses without the chain alias prefix");if(!r(t,!1))throw new Error("Given CoreEth address must be valid avalanche bech32 addresses without the chain alias prefix");this.setChangeAddress(d)}setChangeAddress(s){if(!r(s,!1))throw new Error("Given address must be valid avalanche bech32 addresses without the chain alias prefix");this.xpChangeAddress=s}getAddressEVM(){return this.addressC}getAddresses(s){return("C"===s?[this.addressCoreEth]:this.xpAddresses).map((e=>this.provider.formatAddress(e,s)))}getChangeAddress(s){const e="C"===s?this.addressCoreEth:this.xpChangeAddress;return this.provider.formatAddress(e,s)}getCurrentAddress(s){const e="C"===s?this.addressCoreEth:this.xpAddresses[0];return this.provider.formatAddress(e,s)}}export{t as AddressWallet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as n}from"bip39";import"@ledgerhq/hw-app-eth";import"ethers";import{getAddressDerivationPath as o}from"../../utils/getAddressDerivationPath.js";import"hdkey";import"buffer";import{DerivationPath as s}from"../../EVM/constants.js";import"@openzeppelin/contracts/build/contracts/ERC20.json";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"../utils/populateCredential.js";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import{digestMessage as a}from"../utils/digestMessage.js";import"
|
|
1
|
+
import{addTxSignatures as e,secp256k1 as t}from"@avalabs/avalanchejs";import{fromSeed as i}from"bip32";import{validateMnemonic as r,mnemonicToSeedSync as n}from"bip39";import"@ledgerhq/hw-app-eth";import"ethers";import{getAddressDerivationPath as o}from"../../utils/getAddressDerivationPath.js";import"hdkey";import"buffer";import{DerivationPath as s}from"../../EVM/constants.js";import"@openzeppelin/contracts/build/contracts/ERC20.json";import"bitcoinjs-lib";import"@avalabs/core-utils-sdk";import"@ledgerhq/hw-transport";import"@metamask/eth-sig-util";import"../utils/populateCredential.js";import"@avalabs/glacier-sdk";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import{digestMessage as a}from"../utils/digestMessage.js";import"xss";import"bip32-path";class c{accountNodeXP;signerNodeEVM;activeAccountIndex;constructor(e,t){if(!r(e))throw new Error("Invalid mnemonic phrase.");if(t<0||t%1!=0)throw new Error("Invalid account index.");const a=n(e),c=i(a);this.accountNodeXP=c.derivePath("m/44'/9000'/0'");const p=c.derivePath(o(t,s.BIP44,"EVM"));this.signerNodeEVM=p,this.activeAccountIndex=t}getAdditionalKeys(e,t){return[...new Set(e??[])].reduce(((e,i)=>{const r=this.accountNodeXP.derivePath(`${t?1:0}/${i}`);if(!r.privateKey)throw new Error("Unable to get private key.");return e.push(r.privateKey),e}),[])}getSigningKeys(e,t,i){if("EVM"===e){if(!this.signerNodeEVM.privateKey)throw new Error("Unable to derive EVM private key.");return[this.signerNodeEVM.privateKey]}const r=this.accountNodeXP.derivePath(`0/${this.activeAccountIndex}`);if(!r.privateKey)throw new Error("Unable to derive X/P private key.");const n=this.getAdditionalKeys(t,!1);if("AVM"===e){const e=this.getAdditionalKeys(i,!0);return[r.privateKey,...n,...e]}if("PVM"===e)return[r.privateKey,...n]}async signTx(t){const{tx:i,externalIndices:r,internalIndices:n}=t,o=i.getVM(),s=this.getSigningKeys(o,r,n);if(!s?.length)throw new Error("Unable to sign transaction: signing keys are missing.");return await e({unsignedTx:i,privateKeys:s}),t.tx}async signTxBuffer(e){throw new Error("Not implemented")}getActiveAccountNode(e){switch(e){case"X":case"P":return this.accountNodeXP.derivePath(`0/${this.activeAccountIndex}`);case"C":return this.signerNodeEVM}}async signMessage(e){const i=this.getActiveAccountNode(e.chain);if(!i.privateKey)throw Error("Unable to sign message, key not found.");const r=a(e.message),n=await t.signHash(r,i.privateKey);return Buffer.from(n)}}export{c as SimpleSigner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletVoid as i}from"./WalletVoid.js";import{addTxSignatures as r,secp256k1 as e,utils as t}from"@avalabs/avalanchejs";import{validateMnemonic as s,mnemonicToSeedSync as a}from"bip39";import{fromSeed as o}from"bip32";import{digestMessage as n}from"../utils/digestMessage.js";import"../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"
|
|
1
|
+
import{WalletVoid as i}from"./WalletVoid.js";import{addTxSignatures as r,secp256k1 as e,utils as t}from"@avalabs/avalanchejs";import{validateMnemonic as s,mnemonicToSeedSync as a}from"bip39";import{fromSeed as o}from"bip32";import{digestMessage as n}from"../utils/digestMessage.js";import"../utils/populateCredential.js";import"@avalabs/glacier-sdk";import"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"xss";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";const{getPublicKey:m,sign:v,signHash:f}=e,{addChecksum:h}=t;class c extends i{privKeyXP;privKeyC;constructor(i,r,e){super(Buffer.from(m(i)),Buffer.from(m(r)),e),this.privKeyXP=i,this.privKeyC=r}static fromMnemonic(i,r,e,t){if(!s(i))throw new Error("Invalid mnemonic phrase.");if(!p(e)||!p(r))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const n=a(i),m=o(n),v=m.derivePath(r),f=m.derivePath(e);if(!v.privateKey||!f.privateKey)throw new Error("Failed to generate private keys.");return new c(v.privateKey,f.privateKey,t)}async signMessage(i){const r=n(i.message),e=this.getSigningKey(i.chain);return Buffer.from(h(await f(r,e)))}getSigningKey(i){return"C"===i?this.privKeyC:this.privKeyXP}async signTx(i){return await r({unsignedTx:i.tx,privateKeys:[this.privKeyC,this.privKeyXP]}),i.tx}async signTxBuffer(i){const r=this.getSigningKey(i.chain);return[Buffer.from(await v(i.buffer,r))]}}export{c as StaticSigner};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { utils, pvm, Common } from '@avalabs/avalanchejs';
|
|
2
|
+
|
|
3
|
+
type BaseTx = {
|
|
4
|
+
utxoSet: utils.UtxoSet;
|
|
5
|
+
chain: 'X' | 'P';
|
|
6
|
+
toAddress: string;
|
|
7
|
+
amountsPerAsset: Record<string, bigint>;
|
|
8
|
+
feeState?: pvm.FeeState;
|
|
9
|
+
options?: Common.SpendOptions;
|
|
10
|
+
fromAddresses?: string[];
|
|
11
|
+
};
|
|
12
|
+
type ImportP = {
|
|
13
|
+
utxoSet: utils.UtxoSet;
|
|
14
|
+
sourceChain: 'X' | 'C';
|
|
15
|
+
toAddress?: string;
|
|
16
|
+
threshold?: number;
|
|
17
|
+
feeState?: pvm.FeeState;
|
|
18
|
+
locktime?: bigint;
|
|
19
|
+
};
|
|
20
|
+
type ExportP = {
|
|
21
|
+
amount: bigint;
|
|
22
|
+
utxoSet: utils.UtxoSet;
|
|
23
|
+
destination: 'X' | 'C';
|
|
24
|
+
feeState?: pvm.FeeState;
|
|
25
|
+
toAddress?: string;
|
|
26
|
+
};
|
|
27
|
+
type ConsolidateP = {
|
|
28
|
+
utxoSet: utils.UtxoSet;
|
|
29
|
+
amount: bigint;
|
|
30
|
+
feeState?: pvm.FeeState;
|
|
31
|
+
toAddress?: string;
|
|
32
|
+
options?: Common.SpendOptions;
|
|
33
|
+
};
|
|
34
|
+
type CreateSubnet = {
|
|
35
|
+
utxoSet: utils.UtxoSet;
|
|
36
|
+
rewardAddresses: string[];
|
|
37
|
+
feeState?: pvm.FeeState;
|
|
38
|
+
fromAddresses?: string[];
|
|
39
|
+
options?: Common.SpendOptions;
|
|
40
|
+
threshold?: number;
|
|
41
|
+
locktime?: bigint;
|
|
42
|
+
};
|
|
43
|
+
type CreateChain = {
|
|
44
|
+
utxoSet: utils.UtxoSet;
|
|
45
|
+
subnetId: string;
|
|
46
|
+
chainName: string;
|
|
47
|
+
vmID: string;
|
|
48
|
+
fxIds: string[];
|
|
49
|
+
genesisData: Record<string, unknown>;
|
|
50
|
+
subnetAuth: number[];
|
|
51
|
+
feeState?: pvm.FeeState;
|
|
52
|
+
options?: Common.SpendOptions;
|
|
53
|
+
fromAddresses?: string[];
|
|
54
|
+
};
|
|
55
|
+
type ConvertSubnetToL1 = {
|
|
56
|
+
utxoSet: utils.UtxoSet;
|
|
57
|
+
address: string;
|
|
58
|
+
chainId: string;
|
|
59
|
+
subnetId: string;
|
|
60
|
+
subnetAuth: number[];
|
|
61
|
+
options?: Common.SpendOptions;
|
|
62
|
+
feeState: pvm.FeeState;
|
|
63
|
+
fromAddresses?: string[];
|
|
64
|
+
validators: {
|
|
65
|
+
nodeId: string;
|
|
66
|
+
weight: bigint;
|
|
67
|
+
balance: bigint;
|
|
68
|
+
pubKey: string;
|
|
69
|
+
signature: string;
|
|
70
|
+
remainingBalanceOwner: {
|
|
71
|
+
addresses: string[];
|
|
72
|
+
threshold?: number;
|
|
73
|
+
};
|
|
74
|
+
deactivationOwner: {
|
|
75
|
+
addresses: string[];
|
|
76
|
+
threshold?: number;
|
|
77
|
+
};
|
|
78
|
+
}[];
|
|
79
|
+
};
|
|
80
|
+
type RegisterL1Validator = {
|
|
81
|
+
utxoSet: utils.UtxoSet;
|
|
82
|
+
balance: bigint;
|
|
83
|
+
signature: string;
|
|
84
|
+
feeState: pvm.FeeState;
|
|
85
|
+
message: string;
|
|
86
|
+
options?: Common.SpendOptions;
|
|
87
|
+
fromAddresses?: string[];
|
|
88
|
+
};
|
|
89
|
+
type SetL1ValidatorWeight = {
|
|
90
|
+
utxoSet: utils.UtxoSet;
|
|
91
|
+
feeState: pvm.FeeState;
|
|
92
|
+
message: string;
|
|
93
|
+
options?: Common.SpendOptions;
|
|
94
|
+
fromAddresses?: string[];
|
|
95
|
+
};
|
|
96
|
+
type DisableL1Validator = {
|
|
97
|
+
utxoSet: utils.UtxoSet;
|
|
98
|
+
feeState: pvm.FeeState;
|
|
99
|
+
disableAuth: number[];
|
|
100
|
+
validationId: string;
|
|
101
|
+
options?: Common.SpendOptions;
|
|
102
|
+
fromAddresses?: string[];
|
|
103
|
+
};
|
|
104
|
+
type IncreaseL1ValidatorBalance = {
|
|
105
|
+
utxoSet: utils.UtxoSet;
|
|
106
|
+
feeState: pvm.FeeState;
|
|
107
|
+
balance: bigint;
|
|
108
|
+
validationId: string;
|
|
109
|
+
options?: Common.SpendOptions;
|
|
110
|
+
fromAddresses?: string[];
|
|
111
|
+
};
|
|
112
|
+
type AddSubnetValidator = {
|
|
113
|
+
utxoSet: utils.UtxoSet;
|
|
114
|
+
nodeId: string;
|
|
115
|
+
start: bigint;
|
|
116
|
+
end: bigint;
|
|
117
|
+
weight: bigint;
|
|
118
|
+
subnetId: string;
|
|
119
|
+
subnetAuth: number[];
|
|
120
|
+
feeState?: pvm.FeeState;
|
|
121
|
+
fromAddresses?: string[];
|
|
122
|
+
options?: Common.SpendOptions;
|
|
123
|
+
};
|
|
124
|
+
type AddPermissionlessValidator = {
|
|
125
|
+
utxoSet: utils.UtxoSet;
|
|
126
|
+
nodeId: string;
|
|
127
|
+
start: bigint;
|
|
128
|
+
end: bigint;
|
|
129
|
+
weight: bigint;
|
|
130
|
+
subnetId: string;
|
|
131
|
+
shares: number;
|
|
132
|
+
fromAddresses?: string[];
|
|
133
|
+
rewardAddresses?: string[];
|
|
134
|
+
delegatorRewardAddresses?: string[];
|
|
135
|
+
publicKey?: Buffer;
|
|
136
|
+
signature?: Buffer;
|
|
137
|
+
options?: Common.SpendOptions;
|
|
138
|
+
stakingAssetId?: string;
|
|
139
|
+
locktime?: bigint;
|
|
140
|
+
threshold?: number;
|
|
141
|
+
feeState?: pvm.FeeState;
|
|
142
|
+
};
|
|
143
|
+
type AddPermissionlessDelegator = {
|
|
144
|
+
utxoSet: utils.UtxoSet;
|
|
145
|
+
nodeId: string;
|
|
146
|
+
start: bigint;
|
|
147
|
+
end: bigint;
|
|
148
|
+
weight: bigint;
|
|
149
|
+
subnetId: string;
|
|
150
|
+
fromAddresses?: string[];
|
|
151
|
+
rewardAddresses?: string[];
|
|
152
|
+
options?: Common.SpendOptions;
|
|
153
|
+
locktime?: bigint;
|
|
154
|
+
feeState?: pvm.FeeState;
|
|
155
|
+
stakingAssetId?: string;
|
|
156
|
+
threshold?: number;
|
|
157
|
+
};
|
|
158
|
+
type RemoveSubnetValidator = {
|
|
159
|
+
utxoSet: utils.UtxoSet;
|
|
160
|
+
nodeId: string;
|
|
161
|
+
subnetId: string;
|
|
162
|
+
subnetAuth: number[];
|
|
163
|
+
feeState?: pvm.FeeState;
|
|
164
|
+
fromAddresses?: string[];
|
|
165
|
+
options?: Common.SpendOptions;
|
|
166
|
+
};
|
|
167
|
+
type TransferSubnetOwnershipTx = {
|
|
168
|
+
utxoSet: utils.UtxoSet;
|
|
169
|
+
subnetId: string;
|
|
170
|
+
subnetAuth: number[];
|
|
171
|
+
subnetOwners: string[];
|
|
172
|
+
feeState?: pvm.FeeState;
|
|
173
|
+
fromAddresses?: string[];
|
|
174
|
+
options?: Common.SpendOptions;
|
|
175
|
+
threshold?: number;
|
|
176
|
+
locktime?: bigint;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export { AddPermissionlessDelegator, AddPermissionlessValidator, AddSubnetValidator, BaseTx, ConsolidateP, ConvertSubnetToL1, CreateChain, CreateSubnet, DisableL1Validator, ExportP, ImportP, IncreaseL1ValidatorBalance, RegisterL1Validator, RemoveSubnetValidator, SetL1ValidatorWeight, TransferSubnetOwnershipTx };
|
|
@@ -2,6 +2,7 @@ import * as _avalabs_avalanchejs from '@avalabs/avalanchejs';
|
|
|
2
2
|
import { utils, pvm, Common } from '@avalabs/avalanchejs';
|
|
3
3
|
import { AbstractProvider } from '../providers/AbstractProvider.js';
|
|
4
4
|
import { ChainIDAlias } from '../models.js';
|
|
5
|
+
import { ImportP, ExportP, ConsolidateP, BaseTx, ConvertSubnetToL1, RegisterL1Validator, SetL1ValidatorWeight, DisableL1Validator, IncreaseL1ValidatorBalance, CreateChain, CreateSubnet, AddSubnetValidator, AddPermissionlessValidator, AddPermissionlessDelegator, RemoveSubnetValidator, TransferSubnetOwnershipTx } from './TxBuilderTypes.js';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* An abstract class that that is shared by all wallet classes.
|
|
@@ -48,8 +49,12 @@ declare abstract class WalletAbstract {
|
|
|
48
49
|
* @param source What is the source chain of the atomic UTXOs
|
|
49
50
|
*/
|
|
50
51
|
getAtomicUTXOs(chain: ChainIDAlias, source: ChainIDAlias): Promise<utils.UtxoSet>;
|
|
52
|
+
/**
|
|
53
|
+
* Get the nonce of this wallet's C chain address
|
|
54
|
+
*/
|
|
55
|
+
getNonce(): Promise<number>;
|
|
51
56
|
exportX(amount: bigint, utxoSet: utils.UtxoSet, destination: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
52
|
-
importP(
|
|
57
|
+
importP({ utxoSet, sourceChain, toAddress, threshold, feeState, locktime, }: ImportP): Common.UnsignedTx;
|
|
53
58
|
importX(utxos: utils.UtxoSet, sourceChain: 'P' | 'C', toAddress?: string): Common.UnsignedTx;
|
|
54
59
|
/**
|
|
55
60
|
*
|
|
@@ -69,10 +74,6 @@ declare abstract class WalletAbstract {
|
|
|
69
74
|
* @param toAddress
|
|
70
75
|
*/
|
|
71
76
|
exportC(amount: bigint, destination: 'X' | 'P', nonce: bigint, baseFee: bigint, toAddress?: string): _avalabs_avalanchejs.EVMUnsignedTx;
|
|
72
|
-
/**
|
|
73
|
-
* Get the nonce of this wallet's C chain address
|
|
74
|
-
*/
|
|
75
|
-
getNonce(): Promise<number>;
|
|
76
77
|
/**
|
|
77
78
|
* Export the given amount of AVAX from the P chain. Export fee is automatically added.
|
|
78
79
|
* @param amount
|
|
@@ -80,18 +81,17 @@ declare abstract class WalletAbstract {
|
|
|
80
81
|
* @param destination
|
|
81
82
|
* @param toAddress
|
|
82
83
|
*/
|
|
83
|
-
exportP(amount
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}): Common.UnsignedTx;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}): Common.UnsignedTx;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
addSubnetValidator(utxoSet: utils.UtxoSet, nodeId: string, start: bigint, end: bigint, weight: bigint, subnetId: string, subnetAuth: number[], fromAddresses?: string[], options?: Common.SpendOptions): Common.UnsignedTx;
|
|
84
|
+
exportP({ amount, utxoSet, destination, feeState, toAddress }: ExportP): Common.UnsignedTx;
|
|
85
|
+
consolidateP({ utxoSet, amount, feeState, toAddress, options, }: ConsolidateP): Common.UnsignedTx;
|
|
86
|
+
baseTX({ utxoSet, chain, toAddress, amountsPerAsset, feeState, options, fromAddresses, }: BaseTx): Common.UnsignedTx;
|
|
87
|
+
convertSubnetToL1({ utxoSet, chainId, subnetId, subnetAuth, feeState, address, validators, options, fromAddresses, }: ConvertSubnetToL1): Common.UnsignedTx;
|
|
88
|
+
registerL1Validator({ utxoSet, balance, signature, message, feeState, fromAddresses, options, }: RegisterL1Validator): Common.UnsignedTx;
|
|
89
|
+
setL1ValidatorWeight({ utxoSet, feeState, message, options, fromAddresses, }: SetL1ValidatorWeight): Common.UnsignedTx;
|
|
90
|
+
disableL1Validator({ utxoSet, feeState, options, fromAddresses, disableAuth, validationId, }: DisableL1Validator): Common.UnsignedTx;
|
|
91
|
+
increaseL1ValidatorBalance({ utxoSet, feeState, options, fromAddresses, balance, validationId, }: IncreaseL1ValidatorBalance): Common.UnsignedTx;
|
|
92
|
+
createBlockchain({ utxoSet, subnetId, chainName, vmID, fxIds, genesisData, subnetAuth, feeState, options, fromAddresses, }: CreateChain): Common.UnsignedTx;
|
|
93
|
+
createSubnet({ utxoSet, rewardAddresses, feeState, fromAddresses, options, threshold, locktime, }: CreateSubnet): Common.UnsignedTx;
|
|
94
|
+
addSubnetValidator({ utxoSet, nodeId, start, end, weight, subnetId, subnetAuth, feeState, fromAddresses, options, }: AddSubnetValidator): Common.UnsignedTx;
|
|
95
95
|
/**
|
|
96
96
|
*
|
|
97
97
|
* @param utxoSet The transaction will be constructed from these UTXOs.
|
|
@@ -108,7 +108,7 @@ declare abstract class WalletAbstract {
|
|
|
108
108
|
* @param signature the BLS signature, If the subnet is the primary network. Can be found in the Node on startup.
|
|
109
109
|
* @param options
|
|
110
110
|
*/
|
|
111
|
-
addPermissionlessValidator(utxoSet
|
|
111
|
+
addPermissionlessValidator({ utxoSet, nodeId, start, end, weight, subnetId, shares, feeState, fromAddresses, rewardAddresses, delegatorRewardAddresses, publicKey, signature, options, threshold, locktime, stakingAssetId, }: AddPermissionlessValidator): Common.UnsignedTx;
|
|
112
112
|
/**
|
|
113
113
|
*
|
|
114
114
|
* @param utxoSet The transaction will be constructed from these UTXOs.
|
|
@@ -121,10 +121,9 @@ declare abstract class WalletAbstract {
|
|
|
121
121
|
* @param rewardAddresses Will use active address if not provided. Given addresses will share the reward UTXO.
|
|
122
122
|
* @param options
|
|
123
123
|
*/
|
|
124
|
-
addPermissionlessDelegator(utxoSet
|
|
125
|
-
removeSubnetValidator(utxoSet
|
|
126
|
-
transferSubnetOwnershipTx(utxoSet
|
|
127
|
-
transformSubnetTx(utxoSet: utils.UtxoSet, subnetId: string, assetId: string, initialSupply: bigint, maximumSupply: bigint, minConsumptionRate: bigint, maxConsumptionRate: bigint, minValidatorStake: bigint, maxValidatorStake: bigint, minStakeDuration: number, maxStakeDuration: number, minDelegationFee: number, minDelegatorStake: number, maxValidatorWeightFactor: number, uptimeRequirement: number, subnetAuth: number[], fromAddresses?: string[], options?: Common.SpendOptions): Common.UnsignedTx;
|
|
124
|
+
addPermissionlessDelegator({ utxoSet, nodeId, start, end, weight, subnetId, fromAddresses, rewardAddresses, options, locktime, feeState, threshold, stakingAssetId, }: AddPermissionlessDelegator): Common.UnsignedTx;
|
|
125
|
+
removeSubnetValidator({ utxoSet, nodeId, subnetId, subnetAuth, fromAddresses, feeState, options, }: RemoveSubnetValidator): Common.UnsignedTx;
|
|
126
|
+
transferSubnetOwnershipTx({ utxoSet, subnetId, subnetAuth, subnetOwners, feeState, fromAddresses, options, threshold, locktime, }: TransferSubnetOwnershipTx): Common.UnsignedTx;
|
|
128
127
|
protected constructor(provider: AbstractProvider);
|
|
129
128
|
}
|
|
130
129
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{TransferableOutput as e,avm as t,pvm as s,evm as r,networkIDs as i,utils as d}from"@avalabs/avalanchejs";import"../utils/populateCredential.js";import{strip0x as o}from"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import{getUTXOsForAddresses as n}from"../utils/getAllUTXOs.js";import{getStakeForAddresses as a}from"../utils/getStakeForAddresses.js";import"@avalabs/glacier-sdk";import"bip39";import"xss";import{sortUTXOsByAmount as g,sortUTXOsStaking as h,sortUTXOsByAmountAscending as p}from"../utils/sortUTXOs.js";import"bip32-path";const{parse:c,hexToBuffer:m}=d;class A{constructor(e){this.provider=e}setProvider(e){this.provider=e}getProvider(){return this.provider}async getUTXOs(e){const t=this.provider.getApi(e);return n(this.getAddresses(e),t)}async getStake(){const e=this.provider.getApiP();return a(this.getAddresses("P"),e)}async getAtomicUTXOs(e,t){if(e===t)throw new Error("Chain can not be the same as source chain.");const s=this.provider.getApi(e),r=this.provider.getChainID(t);return n(this.getAddresses(e),s,{sourceChain:r,addresses:[]})}exportX(s,r,i,d){d=d||this.getCurrentAddress(i);const o=c(d)[2],n=this.provider.getAvaxID(),a=e.fromNative(n,s,[o]),h=g(r.getUTXOs(),!0),p=this.provider.getChainID(i),m=this.getAddresses("X").map((e=>c(e)[2])),A=c(this.getChangeAddress("X"))[2];return t.newExportTx(this.provider.getContext(),p,m,h,[a],{threshold:1,changeAddresses:[A]})}importP(e,t,r){const i=this.provider.getChainID(t),d=this.getAddresses("P").map((e=>c(e)[2])),o=c(this.getChangeAddress("P"))[2];r=r||this.getCurrentAddress("P");const n=c(r)[2];return s.newImportTx(this.provider.getContext(),i,e.getUTXOs(),[n],d,{changeAddresses:[o]})}importX(e,s,r){const i=this.provider.getChainID(s),d=this.getAddresses("X").map((e=>c(e)[2])),o=c(this.getChangeAddress("X"))[2];r=r||this.getCurrentAddress("X");const n=c(r)[2];return t.newImportTx(this.provider.getContext(),i,e.getUTXOs(),[n],d,{changeAddresses:[o]})}importC(e,t,s,i,d){const n=this.provider.getChainID(t),a=this.getAddresses("C").map((e=>c(e)[2]));d=d||this.getAddressEVM();const g=Buffer.from(o(d),"hex");return r.newImportTxFromBaseFee(this.provider.getContext(),g,a,e.getUTXOs(),n,s,i)}exportC(e,t,s,i,d){const o=m(this.getAddressEVM()),n=this.provider.getChainID(t);d=d||this.getCurrentAddress(t);const a=c(d)[2],g=i/BigInt(1e9);return r.newExportTxFromBaseFee(this.provider.getContext(),g,e,n,o,[a],s)}async getNonce(){const e=this.getAddressEVM();return await this.provider.evmRpc.getTransactionCount(e)}exportP(t,r,i,d){d=d||this.getCurrentAddress(i);const o=c(d)[2],n=this.provider.getAvaxID(),a=e.fromNative(n,t,[o]),h=g(r.getUTXOs(),!0),p=this.provider.getChainID(i),m=this.getAddresses("P").map((e=>c(e)[2])),A=c(this.getChangeAddress("P"))[2];return s.newExportTx(this.provider.getContext(),p,m,h,[a],{changeAddresses:[A]})}addValidator(e,t,r,i,d,o,n){const a=h(e.getUTXOs()),g=this.getAddresses("P").map((e=>c(e)[2])),p=n?.rewardAddress||this.getCurrentAddress("P"),m=c(p)[2],A=c(this.getChangeAddress("P"))[2];return s.newAddValidatorTx(this.provider.getContext(),a,g,t,i,d,r,[m],o,{changeAddresses:[A]})}addDelegator(e,t,r,i,d,o){const n=h(e.getUTXOs()),a=this.getAddresses("P").map((e=>c(e)[2])),g=o?.rewardAddress||this.getCurrentAddress("P"),p=c(g)[2],m=c(this.getChangeAddress("P"))[2];return s.newAddDelegatorTx(this.provider.getContext(),n,a,t,i,d,r,[p],{changeAddresses:[m]})}consolidateP(t,r,i,d){const o=p(t.getUTXOs());i=i??this.getCurrentAddress("P");const n=c(i)[2],a=this.provider.getContext(),g=[e.fromNative(a.avaxAssetID,r,[n])],h=this.getAddresses("P").map((e=>c(e)[2]));return s.newBaseTx(this.provider.getContext(),h,o,g,d)}baseTX(r,i,d,o,n,a){const[h,p,m]=c(d);if(h!==i||p!==this.provider.getHrp())throw new Error(`Invalid recipient address "${d}"`);const A=Object.entries(o).map((([t,s])=>e.fromNative(t,s,[m]))),v=g(r.getUTXOs(),!0),u=(a??this.getAddresses(i)).map((e=>c(e)[2]));return"X"===i?t.newBaseTx(this.provider.getContext(),u,v,A,n):s.newBaseTx(this.provider.getContext(),u,v,A,n)}createBlockchain(e,t,r,i,d,o,n,a,h){const p=g(e.getUTXOs(),!0),m=(h??this.getAddresses("P")).map((e=>c(e)[2]));return s.newCreateBlockchainTx(this.provider.getContext(),p,m,t,r,i,d,o,n,a)}createSubnet(e,t,r,i,d,o){const n=g(e.getUTXOs(),!0),a=(r??this.getAddresses("P")).map((e=>c(e)[2])),h=t.map((e=>c(e)[2]));return s.newCreateSubnetTx(this.provider.getContext(),n,a,h,i,d??1,o??BigInt(0))}addSubnetValidator(e,t,r,i,d,o,n,a,h){const p=g(e.getUTXOs(),!0),m=(a??this.getAddresses("P")).map((e=>c(e)[2]));return s.newAddSubnetValidatorTx(this.provider.getContext(),p,m,t,r,i,d,o,n,h)}addPermissionlessValidator(e,t,r,d,o,n,a,g,p,m,A,v,u){const C=h(e.getUTXOs()),x=(g??this.getAddresses("P")).map((e=>c(e)[2])),T=(p??[this.getCurrentAddress("P")]).map((e=>c(e)[2])),l=(m??[this.getCurrentAddress("P")]).map((e=>c(e)[2]));if(!(n!==i.PrimaryNetworkID.toString()||A&&v))throw new Error("Must provide public key and signature for primary subnet.");const P={changeAddresses:[c(this.getChangeAddress("P"))[2]],...u??{}};return s.newAddPermissionlessValidatorTx(this.provider.getContext(),C,x,t,n,r,d,o,T,l,a,P,void 0,void 0,A,v)}addPermissionlessDelegator(e,t,r,i,d,o,n,a,g){const p=h(e.getUTXOs()),m=(n??this.getAddresses("P")).map((e=>c(e)[2])),A=(a??[this.getCurrentAddress("P")]).map((e=>c(e)[2])),v={changeAddresses:[c(this.getChangeAddress("P"))[2]],...g??{}};return s.newAddPermissionlessDelegatorTx(this.provider.getContext(),p,m,t,o,r,i,d,A,v,void 0,void 0)}removeSubnetValidator(e,t,r,i,d,o){const n=g(e.getUTXOs(),!0),a=(d??this.getAddresses("P")).map((e=>c(e)[2]));return s.newRemoveSubnetValidatorTx(this.provider.getContext(),n,a,t,r,i,o)}transferSubnetOwnershipTx(e,t,r,i,d,o,n,a){const h=g(e.getUTXOs(),!0),p=(d??this.getAddresses("P")).map((e=>c(e)[2])),m=i.map((e=>c(e)[2]));return s.newTransferSubnetOwnershipTx(this.provider.getContext(),h,p,t,r,m,o,n??1,a??BigInt(0))}transformSubnetTx(e,t,r,i,d,o,n,a,h,p,m,A,v,u,C,x,T,l){const P=g(e.getUTXOs(),!0),w=(T??this.getAddresses("P")).map((e=>c(e)[2]));return s.newTransformSubnetTx(this.provider.getContext(),P,w,t,r,i,d,o,n,a,h,p,m,A,v,u,C,x,l)}}export{A as WalletAbstract};
|
|
1
|
+
import{TransferableOutput as e,avm as s,pvm as t,evm as r,pvmSerial as d,utils as n,PChainOwner as o,L1Validator as i,networkIDs as a}from"@avalabs/avalanchejs";import"../utils/populateCredential.js";import"@avalabs/glacier-sdk";import{strip0x as m}from"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import{getUTXOsForAddresses as h}from"../utils/getAllUTXOs.js";import{getStakeForAddresses as g}from"../utils/getStakeForAddresses.js";import"bip39";import"xss";import{sortUTXOsByAmount as u,sortUTXOsByAmountAscending as A,sortUTXOsStaking as c}from"../utils/sortUTXOs.js";import"bip32-path";import{assertFeeStateProvided as p}from"../../utils/assertFeeStateProvided.js";const{parse:f,hexToBuffer:x}=n;class l{constructor(e){this.provider=e}setProvider(e){this.provider=e}getProvider(){return this.provider}async getUTXOs(e){const s=this.provider.getApi(e);return h(this.getAddresses(e),s)}async getStake(){const e=this.provider.getApiP();return g(this.getAddresses("P"),e)}async getAtomicUTXOs(e,s){if(e===s)throw new Error("Chain can not be the same as source chain.");const t=this.provider.getApi(e),r=this.provider.getChainID(s);return h(this.getAddresses(e),t,{sourceChain:r,addresses:[]})}async getNonce(){const e=this.getAddressEVM();return await this.provider.evmRpc.getTransactionCount(e)}exportX(t,r,d,n){n=n||this.getCurrentAddress(d);const o=f(n)[2],i=this.provider.getAvaxID(),a=e.fromNative(i,t,[o]),m=u(r.getUTXOs(),!0),h=this.provider.getChainID(d),g=this.getAddresses("X").map((e=>f(e)[2])),A=f(this.getChangeAddress("X"))[2];return s.newExportTx(this.provider.getContext(),h,g,m,[a],{threshold:1,changeAddresses:[A]})}importP({utxoSet:e,sourceChain:s,toAddress:r,threshold:d,feeState:n,locktime:o}){const i=this.provider.getChainID(s),a=this.getAddresses("P").map((e=>f(e)[2]));f(this.getChangeAddress("P"))[2],r=r||this.getCurrentAddress("P");const m=f(r)[2],h=e.getUTXOs();return p(n),t.newImportTx({fromAddressesBytes:a,utxos:h,toAddressesBytes:[m],sourceChainId:i,threshold:d,feeState:n,locktime:o},this.provider.getContext())}importX(e,t,r){const d=this.provider.getChainID(t),n=this.getAddresses("X").map((e=>f(e)[2])),o=f(this.getChangeAddress("X"))[2];r=r||this.getCurrentAddress("X");const i=f(r)[2];return s.newImportTx(this.provider.getContext(),d,e.getUTXOs(),[i],n,{changeAddresses:[o]})}importC(e,s,t,d,n){const o=this.provider.getChainID(s),i=this.getAddresses("C").map((e=>f(e)[2]));n=n||this.getAddressEVM();const a=Buffer.from(m(n),"hex");return r.newImportTxFromBaseFee(this.provider.getContext(),a,i,e.getUTXOs(),o,t,d)}exportC(e,s,t,d,n){const o=x(this.getAddressEVM()),i=this.provider.getChainID(s);n=n||this.getCurrentAddress(s);const a=f(n)[2],m=d/BigInt(1e9);return r.newExportTxFromBaseFee(this.provider.getContext(),m,e,i,o,[a],t)}exportP({amount:s,utxoSet:r,destination:d,feeState:n,toAddress:o}){o=o||this.getCurrentAddress(d);const i=f(o)[2],a=this.provider.getAvaxID(),m=e.fromNative(a,s,[i]),h=u(r.getUTXOs(),!0),g=this.provider.getChainID(d),A=this.getAddresses("P").map((e=>f(e)[2])),c=f(this.getChangeAddress("P"))[2];return p(n),t.newExportTx({changeAddressesBytes:[c],fromAddressesBytes:A,utxos:h,outputs:[m],destinationChainId:g,feeState:n},this.provider.getContext())}consolidateP({utxoSet:s,amount:r,feeState:d,toAddress:n,options:o}){const i=A(s.getUTXOs());n=n??this.getCurrentAddress("P");const a=f(n)[2],m=this.provider.getContext(),h=[e.fromNative(m.avaxAssetID,r,[a])],g=this.getAddresses("P").map((e=>f(e)[2])),u=f(this.getChangeAddress("P"))[2],c=o?.changeAddresses??[u];return p(d),t.newBaseTx({changeAddressesBytes:c,fromAddressesBytes:g,utxos:i,outputs:h,minIssuanceTime:o?.minIssuanceTime,memo:o?.memo,feeState:d},m)}baseTX({utxoSet:r,chain:d,toAddress:n,amountsPerAsset:o,feeState:i,options:a,fromAddresses:m}){const[h,g,A]=f(n);if(h!==d||g!==this.provider.getHrp())throw new Error(`Invalid recipient address "${n}"`);const c=Object.entries(o).map((([s,t])=>e.fromNative(s,t,[A]))),x=u(r.getUTXOs(),!0),l=(m??this.getAddresses(d)).map((e=>f(e)[2])),I=f(this.getChangeAddress("P"))[2],T=a?.changeAddresses??[I];return"X"===d?s.newBaseTx(this.provider.getContext(),l,x,c,a):(p(i),t.newBaseTx({changeAddressesBytes:T,fromAddressesBytes:l,utxos:x,outputs:c,minIssuanceTime:a?.minIssuanceTime,memo:a?.memo,feeState:i},this.provider.getContext()))}convertSubnetToL1({utxoSet:e,chainId:s,subnetId:r,subnetAuth:a,feeState:m,address:h,validators:g,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],I=g.map((({nodeId:e,pubKey:s,signature:t,balance:r,weight:a,deactivationOwner:m,remainingBalanceOwner:h})=>{const g=new d.ProofOfPossession(Uint8Array.from(n.hexToBuffer(s)),Uint8Array.from(n.hexToBuffer(t))),u=o.fromNative(h.addresses.map((e=>f(e)[2])),h.threshold??1),A=o.fromNative(m.addresses.map((e=>f(e)[2])),m.threshold??1);return i.fromNative(e,a,r,g,u,A)}));return t.newConvertSubnetToL1Tx({changeAddressesBytes:l,validators:I,fromAddressesBytes:p,address:f(h)[2],chainId:s,subnetId:r,subnetAuth:a,feeState:m,utxos:u(e.getUTXOs(),!0)},this.provider.getContext())}registerL1Validator({utxoSet:e,balance:s,signature:r,message:d,feeState:o,fromAddresses:i,options:a}){const m=(i??this.getAddresses("P")).map((e=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],g=a?.changeAddresses??[h];return t.newRegisterL1ValidatorTx({utxos:u(e.getUTXOs(),!0),balance:s,blsSignature:Uint8Array.from(n.hexToBuffer(r)),changeAddressesBytes:g,feeState:o,fromAddressesBytes:m,memo:a?.memo,message:Uint8Array.from(n.hexToBuffer(d)),minIssuanceTime:a?.minIssuanceTime},this.provider.getContext())}setL1ValidatorWeight({utxoSet:e,feeState:s,message:r,options:d,fromAddresses:o}){const i=(o??this.getAddresses("P")).map((e=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=d?.changeAddresses??[a];return t.newSetL1ValidatorWeightTx({utxos:u(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:s,fromAddressesBytes:i,memo:d?.memo,message:Uint8Array.from(n.hexToBuffer(r)),minIssuanceTime:d?.minIssuanceTime},this.provider.getContext())}disableL1Validator({utxoSet:e,feeState:s,options:r,fromAddresses:d,disableAuth:n,validationId:o}){const i=(d??this.getAddresses("P")).map((e=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=r?.changeAddresses??[a];return t.newDisableL1ValidatorTx({disableAuth:n,validationId:o,utxos:u(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:s,fromAddressesBytes:i,memo:r?.memo,minIssuanceTime:r?.minIssuanceTime},this.provider.getContext())}increaseL1ValidatorBalance({utxoSet:e,feeState:s,options:r,fromAddresses:d,balance:n,validationId:o}){const i=(d??this.getAddresses("P")).map((e=>f(e)[2])),a=f(this.getChangeAddress("P"))[2],m=r?.changeAddresses??[a];return t.newIncreaseL1ValidatorBalanceTx({balance:n,validationId:o,utxos:u(e.getUTXOs(),!0),changeAddressesBytes:m,feeState:s,fromAddressesBytes:i,memo:r?.memo,minIssuanceTime:r?.minIssuanceTime},this.provider.getContext())}createBlockchain({utxoSet:e,subnetId:s,chainName:r,vmID:d,fxIds:n,genesisData:o,subnetAuth:i,feeState:a,options:m,fromAddresses:h}){const g=u(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),t.newCreateChainTx({chainName:r,feeState:a,fromAddressesBytes:A,fxIds:n,genesisData:o,subnetAuth:i,subnetId:s,utxos:g,vmId:d,changeAddressesBytes:x},this.provider.getContext())}createSubnet({utxoSet:e,rewardAddresses:s,feeState:r,fromAddresses:d,options:n,threshold:o,locktime:i}){const a=u(e.getUTXOs(),!0),m=(d??this.getAddresses("P")).map((e=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],g=n?.changeAddresses??[h],A=s.map((e=>f(e)[2]));return p(r),t.newCreateSubnetTx({fromAddressesBytes:m,changeAddressesBytes:g,utxos:a,minIssuanceTime:n?.minIssuanceTime,memo:n?.memo,feeState:r,threshold:o,locktime:i,subnetOwners:A},this.provider.getContext())}addSubnetValidator({utxoSet:e,nodeId:s,start:r,end:d,weight:n,subnetId:o,subnetAuth:i,feeState:a,fromAddresses:m,options:h}){const g=u(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),t.newAddSubnetValidatorTx({changeAddressesBytes:x,fromAddressesBytes:A,utxos:g,minIssuanceTime:h?.minIssuanceTime,memo:h?.memo,nodeId:s,start:r,end:d,weight:n,subnetId:o,subnetAuth:i,feeState:a},this.provider.getContext())}addPermissionlessValidator({utxoSet:e,nodeId:s,start:r,end:d,weight:n,subnetId:o,shares:i,feeState:m,fromAddresses:h,rewardAddresses:g,delegatorRewardAddresses:u,publicKey:A,signature:x,options:l,threshold:I,locktime:T,stakingAssetId:v}){const C=c(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!==a.PrimaryNetworkID.toString()||A&&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(m),t.newAddPermissionlessValidatorTx({fromAddressesBytes:S,delegatorRewardsOwner:w,utxos:C,minIssuanceTime:l?.minIssuanceTime,memo:l?.memo,changeAddressesBytes:B,nodeId:s,start:r,end:d,weight:n,subnetId:o,shares:i,feeState:m,publicKey:A,rewardAddresses:b,signature:x,locktime:T,threshold:I,stakingAssetId:v},this.provider.getContext())}addPermissionlessDelegator({utxoSet:e,nodeId:s,start:r,end:d,weight:n,subnetId:o,fromAddresses:i,rewardAddresses:a,options:m,locktime:h,feeState:g,threshold:u,stakingAssetId:A}){const x=c(e.getUTXOs()),l=(i??this.getAddresses("P")).map((e=>f(e)[2])),I=(a??[this.getCurrentAddress("P")]).map((e=>f(e)[2])),T=f(this.getChangeAddress("P"))[2],v=m?.changeAddresses??[T];return p(g),t.newAddPermissionlessDelegatorTx({fromAddressesBytes:l,utxos:x,minIssuanceTime:m?.minIssuanceTime,memo:m?.memo,changeAddressesBytes:v,nodeId:s,start:r,end:d,weight:n,subnetId:o,rewardAddresses:I,locktime:h,stakingAssetId:A,threshold:u,feeState:g},this.provider.getContext())}removeSubnetValidator({utxoSet:e,nodeId:s,subnetId:r,subnetAuth:d,fromAddresses:n,feeState:o,options:i}){const a=u(e.getUTXOs(),!0),m=(n??this.getAddresses("P")).map((e=>f(e)[2])),h=f(this.getChangeAddress("P"))[2],g=i?.changeAddresses??[h];return p(o),t.newRemoveSubnetValidatorTx({changeAddressesBytes:g,fromAddressesBytes:m,utxos:a,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,nodeId:s,subnetId:r,subnetAuth:d,feeState:o},this.provider.getContext())}transferSubnetOwnershipTx({utxoSet:e,subnetId:s,subnetAuth:r,subnetOwners:d,feeState:n,fromAddresses:o,options:i,threshold:a,locktime:m}){const h=u(e.getUTXOs(),!0),g=(o??this.getAddresses("P")).map((e=>f(e)[2])),A=f(this.getChangeAddress("P"))[2],c=i?.changeAddresses??[A],x=d.map((e=>f(e)[2]));return p(n),t.newTransferSubnetOwnershipTx({changeAddressesBytes:c,fromAddressesBytes:g,utxos:h,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,subnetId:s,subnetAuth:r,subnetOwners:x,feeState:n,threshold:a,locktime:m},this.provider.getContext())}}export{l as WalletAbstract};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{WalletAbstract as e}from"./WalletAbstract.js";import{fromSeed as r}from"bip32";import{validateMnemonic as t,mnemonicToSeedSync as s}from"bip39";import{strip0x as i}from"@avalabs/core-utils-sdk";import"@avalabs/avalanchejs";import"../utils/populateCredential.js";import{SigningKey as o,computeAddress as a}from"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"
|
|
1
|
+
import{WalletAbstract as e}from"./WalletAbstract.js";import{fromSeed as r}from"bip32";import{validateMnemonic as t,mnemonicToSeedSync as s}from"bip39";import{strip0x as i}from"@avalabs/core-utils-sdk";import"@avalabs/avalanchejs";import"../utils/populateCredential.js";import"@avalabs/glacier-sdk";import{SigningKey as o,computeAddress as a}from"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"xss";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";class n extends e{constructor(e,r,t){if(super(t),this.pubkeyXP=e,this.pubkeyC=r,33!==r.length||33!==e.length)throw new Error("Public key must be 33 byte compressed public key")}static fromPublicKey(e,r,t){const s=i(o.computePublicKey(e,!0)),a=i(o.computePublicKey(r,!0)),p=Buffer.from(s,"hex"),u=Buffer.from(a,"hex");return new n(p,u,t)}static fromMnemonic(e,i,o,a){if(!t(e))throw new Error("Invalid mnemonic phrase.");if(!p(o)||!p(i))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const u=s(e),d=r(u),m=d.derivePath(o),h=d.derivePath(i);return n.fromPublicKey(h.publicKey,m.publicKey,a)}getAddress(e){const r="C"===e?this.pubkeyC:this.pubkeyXP;return this.provider.getAddress(r,e)}getAddressEVM(){return a(`0x${this.pubkeyC.toString("hex")}`)}getAddresses(e){return[this.getAddress(e)]}getChangeAddress(e){return this.getAddress(e)}getCurrentAddress(e){return this.getAddress(e)}}export{n as WalletVoid};
|