@avalabs/core-wallets-sdk 3.1.0-alpha.2 → 3.1.0-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/index.d.ts +333 -48
  2. package/dist/index.js +1 -1
  3. package/esm/Avalanche/index.d.ts +2 -2
  4. package/esm/Avalanche/index.js +1 -1
  5. package/esm/Avalanche/models.d.ts +44 -5
  6. package/esm/Avalanche/models.js +1 -1
  7. package/esm/Avalanche/providers/AbstractProvider.d.ts +9 -2
  8. package/esm/Avalanche/providers/AbstractProvider.js +1 -1
  9. package/esm/Avalanche/providers/JsonRpcProvider.d.ts +5 -3
  10. package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
  11. package/esm/Avalanche/providers/constants.d.ts +20 -1
  12. package/esm/Avalanche/providers/constants.js +1 -1
  13. package/esm/Avalanche/providers/platformFeeConfig.js +1 -0
  14. package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +3 -3
  15. package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
  16. package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -1
  17. package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
  18. package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +5 -2
  19. package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -1
  20. package/esm/Avalanche/utils/handleSubnetAuth.js +1 -1
  21. package/esm/Avalanche/utils/parseAvalancheTx.d.ts +7 -1
  22. package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
  23. package/esm/Avalanche/utils/parsers/index.js +1 -1
  24. package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -1
  25. package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -1
  26. package/esm/Avalanche/utils/parsers/parseConvertSubnetToL1Tx.js +1 -0
  27. package/esm/Avalanche/utils/parsers/parseDisableL1ValidatorTx.js +1 -0
  28. package/esm/Avalanche/utils/parsers/parseIncreaseL1ValidatorBalanceTx.js +1 -0
  29. package/esm/Avalanche/utils/parsers/parseRegisterL1ValidatorTx.js +1 -0
  30. package/esm/Avalanche/utils/parsers/parseSetL1ValidatorWeightTx.js +1 -0
  31. package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -1
  32. package/esm/Avalanche/utils/sortUTXOs.d.ts +5 -4
  33. package/esm/Avalanche/utils/txSizeLimits.d.ts +9 -2
  34. package/esm/Avalanche/utils/txSizeLimits.js +1 -1
  35. package/esm/Avalanche/wallets/AddressWallet.js +1 -1
  36. package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
  37. package/esm/Avalanche/wallets/StaticSigner.js +1 -1
  38. package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +179 -0
  39. package/esm/Avalanche/wallets/WalletAbstract.d.ts +24 -18
  40. package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
  41. package/esm/Avalanche/wallets/WalletVoid.js +1 -1
  42. package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
  43. package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
  44. package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +4 -3
  45. package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -1
  46. package/esm/BitcoinVM/providers/BitcoinProviderAbstract.d.ts +1 -0
  47. package/esm/utils/assertFeeStateProvided.js +1 -0
  48. package/package.json +5 -5
@@ -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 t,pvm as s,evm as r,pvmSerial as d,utils as o,PChainOwner as i,L1Validator as n,networkIDs as a}from"@avalabs/avalanchejs";import"../utils/populateCredential.js";import"@avalabs/glacier-sdk";import{strip0x as h}from"@avalabs/core-utils-sdk";import"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import{getUTXOsForAddresses as m}from"../utils/getAllUTXOs.js";import{getStakeForAddresses as u}from"../utils/getStakeForAddresses.js";import"bip39";import"xss";import{sortUTXOsByAmount as g,sortUTXOsStaking as p,sortUTXOsByAmountAscending as A}from"../utils/sortUTXOs.js";import"bip32-path";import{assertFeeStateProvided as c}from"../../utils/assertFeeStateProvided.js";const{parse:x,hexToBuffer:f}=o,l=new Error("Tx type is not supported post-etna");class v{constructor(e){this.provider=e}setProvider(e){this.provider=e}getProvider(){return this.provider}async getUTXOs(e){const t=this.provider.getApi(e);return m(this.getAddresses(e),t)}async getStake(){const e=this.provider.getApiP();return u(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 m(this.getAddresses(e),s,{sourceChain:r,addresses:[]})}async getNonce(){const e=this.getAddressEVM();return await this.provider.evmRpc.getTransactionCount(e)}exportX(s,r,d,o){o=o||this.getCurrentAddress(d);const i=x(o)[2],n=this.provider.getAvaxID(),a=e.fromNative(n,s,[i]),h=g(r.getUTXOs(),!0),m=this.provider.getChainID(d),u=this.getAddresses("X").map((e=>x(e)[2])),p=x(this.getChangeAddress("X"))[2];return t.newExportTx(this.provider.getContext(),m,u,h,[a],{threshold:1,changeAddresses:[p]})}importP({utxoSet:e,sourceChain:t,toAddress:r,threshold:d,feeState:o,locktime:i}){const n=this.provider.getChainID(t),a=this.getAddresses("P").map((e=>x(e)[2])),h=x(this.getChangeAddress("P"))[2];r=r||this.getCurrentAddress("P");const m=x(r)[2],u=e.getUTXOs();if(this.provider.isEtnaEnabled()){if(!o)throw new Error("feeState parameter is required post E-upgrade");return s.e.newImportTx({fromAddressesBytes:a,utxos:u,toAddressesBytes:[m],sourceChainId:n,threshold:d,feeState:o,locktime:i},this.provider.getContext())}return s.newImportTx(this.provider.getContext(),n,u,[m],a,{changeAddresses:[h]})}importX(e,s,r){const d=this.provider.getChainID(s),o=this.getAddresses("X").map((e=>x(e)[2])),i=x(this.getChangeAddress("X"))[2];r=r||this.getCurrentAddress("X");const n=x(r)[2];return t.newImportTx(this.provider.getContext(),d,e.getUTXOs(),[n],o,{changeAddresses:[i]})}importC(e,t,s,d,o){const i=this.provider.getChainID(t),n=this.getAddresses("C").map((e=>x(e)[2]));o=o||this.getAddressEVM();const a=Buffer.from(h(o),"hex");return r.newImportTxFromBaseFee(this.provider.getContext(),a,n,e.getUTXOs(),i,s,d)}exportC(e,t,s,d,o){const i=f(this.getAddressEVM()),n=this.provider.getChainID(t);o=o||this.getCurrentAddress(t);const a=x(o)[2],h=d/BigInt(1e9);return r.newExportTxFromBaseFee(this.provider.getContext(),h,e,n,i,[a],s)}exportP({amount:t,utxoSet:r,destination:d,feeState:o,toAddress:i}){i=i||this.getCurrentAddress(d);const n=x(i)[2],a=this.provider.getAvaxID(),h=e.fromNative(a,t,[n]),m=g(r.getUTXOs(),!0),u=this.provider.getChainID(d),p=this.getAddresses("P").map((e=>x(e)[2])),A=x(this.getChangeAddress("P"))[2];return this.provider.isEtnaEnabled()?(c(o),s.e.newExportTx({fromAddressesBytes:p,utxos:m,outputs:[h],destinationChainId:u,feeState:o},this.provider.getContext())):s.newExportTx(this.provider.getContext(),u,p,m,[h],{changeAddresses:[A]})}addValidator(e,t,r,d,o,i,n){const a=p(e.getUTXOs()),h=this.getAddresses("P").map((e=>x(e)[2])),m=n?.rewardAddress||this.getCurrentAddress("P"),u=x(m)[2],g=x(this.getChangeAddress("P"))[2];if(this.provider.isEtnaEnabled())throw l;return s.newAddValidatorTx(this.provider.getContext(),a,h,t,d,o,r,[u],i,{changeAddresses:[g]})}addDelegator(e,t,r,d,o,i){const n=p(e.getUTXOs()),a=this.getAddresses("P").map((e=>x(e)[2])),h=i?.rewardAddress||this.getCurrentAddress("P"),m=x(h)[2],u=x(this.getChangeAddress("P"))[2];if(this.provider.isEtnaEnabled())throw l;return s.newAddDelegatorTx(this.provider.getContext(),n,a,t,d,o,r,[m],{changeAddresses:[u]})}consolidateP({utxoSet:t,amount:r,feeState:d,toAddress:o,options:i}){const n=A(t.getUTXOs());o=o??this.getCurrentAddress("P");const a=x(o)[2],h=this.provider.getContext(),m=[e.fromNative(h.avaxAssetID,r,[a])],u=this.getAddresses("P").map((e=>x(e)[2]));return this.provider.isEtnaEnabled()?(c(d),s.e.newBaseTx({fromAddressesBytes:u,utxos:n,outputs:m,minIssuanceTime:i?.minIssuanceTime,memo:i?.memo,feeState:d},h)):s.newBaseTx(this.provider.getContext(),u,n,m,i)}baseTX({utxoSet:r,chain:d,toAddress:o,amountsPerAsset:i,feeState:n,options:a,fromAddresses:h}){const[m,u,p]=x(o);if(m!==d||u!==this.provider.getHrp())throw new Error(`Invalid recipient address "${o}"`);const A=Object.entries(i).map((([t,s])=>e.fromNative(t,s,[p]))),f=g(r.getUTXOs(),!0),l=(h??this.getAddresses(d)).map((e=>x(e)[2]));return"X"===d?t.newBaseTx(this.provider.getContext(),l,f,A,a):this.provider.isEtnaEnabled()?(c(n),s.e.newBaseTx({fromAddressesBytes:l,utxos:f,outputs:A,minIssuanceTime:a?.minIssuanceTime,memo:a?.memo,feeState:n},this.provider.getContext())):s.newBaseTx(this.provider.getContext(),l,f,A,a)}convertSubnetToL1({utxoSet:e,chainId:t,subnetId:r,subnetAuth:a,feeState:h,address:m,validators:u,options:p,fromAddresses:A}){if(!this.provider.isEtnaEnabled())throw new Error("Not supported prior to E-upgrade");const c=(A??this.getAddresses("P")).map((e=>x(e)[2])),f=u.map((({nodeId:e,pubKey:t,signature:s,balance:r,weight:a,deactivationOwner:h,remainingBalanceOwner:m})=>{const u=new d.ProofOfPossession(Uint8Array.from(o.hexToBuffer(t)),Uint8Array.from(o.hexToBuffer(s))),g=i.fromNative(m.addresses.map((e=>x(e)[2])),m.threshold??1),p=i.fromNative(h.addresses.map((e=>x(e)[2])),h.threshold??1);return n.fromNative(e,a,r,u,g,p)}));return s.e.newConvertSubnetToL1Tx({changeAddressesBytes:p?.changeAddresses??c,validators:f,fromAddressesBytes:c,address:x(m)[2],chainId:t,subnetId:r,subnetAuth:a,feeState:h,utxos:g(e.getUTXOs(),!0)},this.provider.getContext())}registerL1Validator({utxoSet:e,balance:t,signature:r,message:d,feeState:i,fromAddresses:n,options:a}){if(!this.provider.isEtnaEnabled())throw new Error("Not supported prior to E-upgrade");const h=(n??this.getAddresses("P")).map((e=>x(e)[2]));return s.e.newRegisterL1ValidatorTx({utxos:g(e.getUTXOs(),!0),balance:t,blsSignature:Uint8Array.from(o.hexToBuffer(r)),changeAddressesBytes:a?.changeAddresses??h,feeState:i,fromAddressesBytes:h,memo:a?.memo,message:Uint8Array.from(o.hexToBuffer(d)),minIssuanceTime:a?.minIssuanceTime},this.provider.getContext())}setL1ValidatorWeight({utxoSet:e,feeState:t,message:r,options:d,fromAddresses:i}){if(!this.provider.isEtnaEnabled())throw new Error("Not supported prior to E-upgrade");const n=(i??this.getAddresses("P")).map((e=>x(e)[2]));return s.e.newSetL1ValidatorWeightTx({utxos:g(e.getUTXOs(),!0),changeAddressesBytes:d?.changeAddresses??n,feeState:t,fromAddressesBytes:n,memo:d?.memo,message:Uint8Array.from(o.hexToBuffer(r)),minIssuanceTime:d?.minIssuanceTime},this.provider.getContext())}disableL1Validator({utxoSet:e,feeState:t,options:r,fromAddresses:d,disableAuth:o,validationId:i}){if(!this.provider.isEtnaEnabled())throw new Error("Not supported prior to E-upgrade");const n=(d??this.getAddresses("P")).map((e=>x(e)[2]));return s.e.newDisableL1ValidatorTx({disableAuth:o,validationId:i,utxos:g(e.getUTXOs(),!0),changeAddressesBytes:r?.changeAddresses??n,feeState:t,fromAddressesBytes:n,memo:r?.memo,minIssuanceTime:r?.minIssuanceTime},this.provider.getContext())}increaseL1ValidatorBalance({utxoSet:e,feeState:t,options:r,fromAddresses:d,balance:o,validationId:i}){if(!this.provider.isEtnaEnabled())throw new Error("Not supported prior to E-upgrade");const n=(d??this.getAddresses("P")).map((e=>x(e)[2]));return s.e.newIncreaseL1ValidatorBalanceTx({balance:o,validationId:i,utxos:g(e.getUTXOs(),!0),changeAddressesBytes:r?.changeAddresses??n,feeState:t,fromAddressesBytes:n,memo:r?.memo,minIssuanceTime:r?.minIssuanceTime},this.provider.getContext())}createBlockchain({utxoSet:e,subnetId:t,chainName:r,vmID:d,fxIds:o,genesisData:i,subnetAuth:n,feeState:a,options:h,fromAddresses:m}){const u=g(e.getUTXOs(),!0),p=(m??this.getAddresses("P")).map((e=>x(e)[2]));if(this.provider.isEtnaEnabled()){c(a);const e=(m??this.getAddresses("P")).map((e=>x(e)[2])),g=x(this.getChangeAddress("P"))[2];return s.e.newCreateChainTx({chainName:r,feeState:a,fromAddressesBytes:e,fxIds:o,genesisData:i,subnetAuth:n,subnetId:t,utxos:u,vmId:d,changeAddressesBytes:h?.changeAddresses??[g]},this.provider.getContext())}return s.newCreateBlockchainTx(this.provider.getContext(),u,p,t,r,d,o,i,n,h)}createSubnet({utxoSet:e,rewardAddresses:t,feeState:r,fromAddresses:d,options:o,threshold:i,locktime:n}){const a=g(e.getUTXOs(),!0),h=(d??this.getAddresses("P")).map((e=>x(e)[2])),m=t.map((e=>x(e)[2]));return this.provider.isEtnaEnabled()?(c(r),s.e.newCreateSubnetTx({fromAddressesBytes:h,utxos:a,minIssuanceTime:o?.minIssuanceTime,memo:o?.memo,feeState:r,threshold:i,locktime:n,subnetOwners:m},this.provider.getContext())):s.newCreateSubnetTx(this.provider.getContext(),a,h,m,o,i??1,n??BigInt(0))}addSubnetValidator({utxoSet:e,nodeId:t,start:r,end:d,weight:o,subnetId:i,subnetAuth:n,feeState:a,fromAddresses:h,options:m}){const u=g(e.getUTXOs(),!0),p=(h??this.getAddresses("P")).map((e=>x(e)[2]));return this.provider.isEtnaEnabled()?(c(a),s.e.newAddSubnetValidatorTx({fromAddressesBytes:p,utxos:u,minIssuanceTime:m?.minIssuanceTime,memo:m?.memo,nodeId:t,start:r,end:d,weight:o,subnetId:i,subnetAuth:n,feeState:a},this.provider.getContext())):s.newAddSubnetValidatorTx(this.provider.getContext(),u,p,t,r,d,o,i,n,m)}addPermissionlessValidator({utxoSet:e,nodeId:t,start:r,end:d,weight:o,subnetId:i,shares:n,feeState:h,fromAddresses:m,rewardAddresses:u,delegatorRewardAddresses:g,publicKey:A,signature:f,options:l,threshold:v,locktime:T,stakingAssetId:b}){const w=p(e.getUTXOs()),I=(m??this.getAddresses("P")).map((e=>x(e)[2])),C=(u??[this.getCurrentAddress("P")]).map((e=>x(e)[2])),S=(g??[this.getCurrentAddress("P")]).map((e=>x(e)[2]));if(!(i!==a.PrimaryNetworkID.toString()||A&&f))throw new Error("Must provide public key and signature for primary subnet.");const E=x(this.getChangeAddress("P"))[2];if(this.provider.isEtnaEnabled())return c(h),s.e.newAddPermissionlessValidatorTx({fromAddressesBytes:I,delegatorRewardsOwner:S,utxos:w,minIssuanceTime:l?.minIssuanceTime,memo:l?.memo,changeAddressesBytes:l?.changeAddresses?l.changeAddresses:[E],nodeId:t,start:r,end:d,weight:o,subnetId:i,shares:n,feeState:h,publicKey:A,rewardAddresses:C,signature:f,locktime:T,threshold:v,stakingAssetId:b},this.provider.getContext());const P={changeAddresses:[E],...l??{}};return s.newAddPermissionlessValidatorTx(this.provider.getContext(),w,I,t,i,r,d,o,C,S,n,P,void 0,void 0,A,f)}addPermissionlessDelegator({utxoSet:e,nodeId:t,start:r,end:d,weight:o,subnetId:i,fromAddresses:n,rewardAddresses:a,options:h,locktime:m,feeState:u,threshold:g,stakingAssetId:A}){const f=p(e.getUTXOs()),l=(n??this.getAddresses("P")).map((e=>x(e)[2])),v=(a??[this.getCurrentAddress("P")]).map((e=>x(e)[2])),T=x(this.getChangeAddress("P"))[2];if(this.provider.isEtnaEnabled())return c(u),s.e.newAddPermissionlessDelegatorTx({fromAddressesBytes:l,utxos:f,minIssuanceTime:h?.minIssuanceTime,memo:h?.memo,changeAddressesBytes:h?.changeAddresses?h.changeAddresses:[T],nodeId:t,start:r,end:d,weight:o,subnetId:i,rewardAddresses:v,locktime:m,stakingAssetId:A,threshold:g,feeState:u},this.provider.getContext());const b={changeAddresses:[T],...h??{}};return s.newAddPermissionlessDelegatorTx(this.provider.getContext(),f,l,t,i,r,d,o,v,b,void 0,void 0)}removeSubnetValidator({utxoSet:e,nodeId:t,subnetId:r,subnetAuth:d,fromAddresses:o,feeState:i,options:n}){const a=g(e.getUTXOs(),!0),h=(o??this.getAddresses("P")).map((e=>x(e)[2]));return this.provider.isEtnaEnabled()?(c(i),s.e.newRemoveSubnetValidatorTx({fromAddressesBytes:h,utxos:a,minIssuanceTime:n?.minIssuanceTime,memo:n?.memo,nodeId:t,subnetId:r,subnetAuth:d,feeState:i},this.provider.getContext())):s.newRemoveSubnetValidatorTx(this.provider.getContext(),a,h,t,r,d,n)}transferSubnetOwnershipTx({utxoSet:e,subnetId:t,subnetAuth:r,subnetOwners:d,feeState:o,fromAddresses:i,options:n,threshold:a,locktime:h}){const m=g(e.getUTXOs(),!0),u=(i??this.getAddresses("P")).map((e=>x(e)[2])),p=d.map((e=>x(e)[2]));return this.provider.isEtnaEnabled()?(c(o),s.e.newTransferSubnetOwnershipTx({fromAddressesBytes:u,utxos:m,minIssuanceTime:n?.minIssuanceTime,memo:n?.memo,subnetId:t,subnetAuth:r,subnetOwners:p,feeState:o,threshold:a,locktime:h},this.provider.getContext())):s.newTransferSubnetOwnershipTx(this.provider.getContext(),m,u,t,r,p,n,a??1,h??BigInt(0))}transformSubnetTx(e,t,r,d,o,i,n,a,h,m,u,p,A,c,f,v,T,b){const w=g(e.getUTXOs(),!0),I=(T??this.getAddresses("P")).map((e=>x(e)[2]));if(this.provider.isEtnaEnabled())throw l;return s.newTransformSubnetTx(this.provider.getContext(),w,I,t,r,d,o,i,n,a,h,m,u,p,A,c,f,v,b)}}export{v as WalletAbstract};
@@ -1 +1 @@
1
- import{WalletAbstract as e}from"./WalletAbstract.js";import{fromSeed as r}from"bip32";import{validateMnemonic as t,mnemonicToSeedSync as s}from"bip39";import{strip0x as i}from"@avalabs/core-utils-sdk";import"@avalabs/avalanchejs";import"../utils/populateCredential.js";import{SigningKey as o,computeAddress as a}from"ethers";import"../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"@avalabs/glacier-sdk";import"xss";import{verifyDerivationPath as p}from"../utils/verifyDerivationPath.js";class n extends e{constructor(e,r,t){if(super(t),this.pubkeyXP=e,this.pubkeyC=r,33!==r.length||33!==e.length)throw new Error("Public key must be 33 byte compressed public key")}static fromPublicKey(e,r,t){const s=i(o.computePublicKey(e,!0)),a=i(o.computePublicKey(r,!0)),p=Buffer.from(s,"hex"),u=Buffer.from(a,"hex");return new n(p,u,t)}static fromMnemonic(e,i,o,a){if(!t(e))throw new Error("Invalid mnemonic phrase.");if(!p(o)||!p(i))throw new Error("Not valid derivation path. Make sure it is a valid BIP44 path starting with m/");const u=s(e),d=r(u),m=d.derivePath(o),h=d.derivePath(i);return n.fromPublicKey(h.publicKey,m.publicKey,a)}getAddress(e){const r="C"===e?this.pubkeyC:this.pubkeyXP;return this.provider.getAddress(r,e)}getAddressEVM(){return a(`0x${this.pubkeyC.toString("hex")}`)}getAddresses(e){return[this.getAddress(e)]}getChangeAddress(e){return this.getAddress(e)}getCurrentAddress(e){return this.getAddress(e)}}export{n as WalletVoid};
1
+ import{WalletAbstract as 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};
@@ -1 +1 @@
1
- import{WalletVoid as r}from"../WalletVoid.js";import{isObsidianApp as t}from"./isObsidianApp.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";import i from"bip32-path";import o from"@ledgerhq/hw-app-eth";import{utils as a}from"@avalabs/avalanchejs";import"../../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import{SigningKey as s}from"ethers";import"../../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import"@avalabs/glacier-sdk";import"bip39";import"xss";import{verifyDerivationPath as n}from"../../utils/verifyDerivationPath.js";const{strip0x:p}=a;class f extends r{constructor(r,t,e,i,o){const p=a.strip0x(s.computePublicKey(r,!0)),f=a.strip0x(s.computePublicKey(e,!0));if(super(Buffer.from(p,"hex"),Buffer.from(f,"hex"),o),this.pathXP=t,this.pathC=i,!n(t)||!n(i))throw new Error("Invalid path configuration.")}static async fromTransport(r,e,i,a){if(await t(r))throw new Error("Ledger app not supported. Must be version >= 0.6.0");if(!n(e)||!n(i))throw new Error("Invalid path configuration.");const h=new o(r),u=await h.getAddress(i,!1),c=await h.getAddress(e,!1),m=Buffer.from(p(u.publicKey),"hex"),l=Buffer.from(p(c.publicKey),"hex"),g=Buffer.from(p(s.computePublicKey(m,!0)),"hex"),d=Buffer.from(p(s.computePublicKey(l,!0)),"hex");return new f(d,e,g,i,a)}async signMessage(r){throw new Error("not implemented")}getFullSignerPath(r){return"C"===r?this.pathC:this.pathXP}getPartialSignerPath(r){return this.getFullSignerPath(r).split("/").slice(4).join("/")}getAccountPath(r){return this.getFullSignerPath(r).split("/").slice(0,4).join("/")}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const t=r.tx,e=t.getVM(),i=Buffer.from(t.toBytes()),o="EVM"===e?"C":"X";return(await this.signTxBuffer({buffer:i,chain:o,transport:r.transport})).forEach((r=>{t.addSignature(r)})),t}async signTxBuffer(r){if(!r.transport)throw new Error("Ledger transport not provided");const t=i.fromString(this.getAccountPath(r.chain)),o=i.fromString(this.getPartialSignerPath(r.chain));return[...(await e.signTx(r.transport,r.buffer,t,[o],[o])).signatures.values()]}}export{f as LedgerSigner};
1
+ import{WalletVoid as r}from"../WalletVoid.js";import{isObsidianApp as t}from"./isObsidianApp.js";import{ZondaxProvider as e}from"./ZondaxProvider.js";import i from"bip32-path";import o from"@ledgerhq/hw-app-eth";import{utils as a}from"@avalabs/avalanchejs";import"../../utils/populateCredential.js";import"@avalabs/glacier-sdk";import"@avalabs/core-utils-sdk";import{SigningKey as s}from"ethers";import"../../providers/constants.js";import"@avalabs/core-chains-sdk";import"create-hash";import"bip32";import"bip39";import"xss";import{verifyDerivationPath as n}from"../../utils/verifyDerivationPath.js";const{strip0x:p}=a;class f extends r{constructor(r,t,e,i,o){const p=a.strip0x(s.computePublicKey(r,!0)),f=a.strip0x(s.computePublicKey(e,!0));if(super(Buffer.from(p,"hex"),Buffer.from(f,"hex"),o),this.pathXP=t,this.pathC=i,!n(t)||!n(i))throw new Error("Invalid path configuration.")}static async fromTransport(r,e,i,a){if(await t(r))throw new Error("Ledger app not supported. Must be version >= 0.6.0");if(!n(e)||!n(i))throw new Error("Invalid path configuration.");const h=new o(r),u=await h.getAddress(i,!1),c=await h.getAddress(e,!1),m=Buffer.from(p(u.publicKey),"hex"),l=Buffer.from(p(c.publicKey),"hex"),g=Buffer.from(p(s.computePublicKey(m,!0)),"hex"),d=Buffer.from(p(s.computePublicKey(l,!0)),"hex");return new f(d,e,g,i,a)}async signMessage(r){throw new Error("not implemented")}getFullSignerPath(r){return"C"===r?this.pathC:this.pathXP}getPartialSignerPath(r){return this.getFullSignerPath(r).split("/").slice(4).join("/")}getAccountPath(r){return this.getFullSignerPath(r).split("/").slice(0,4).join("/")}async signTx(r){if(!r.transport)throw new Error("Ledger transport not provided");const t=r.tx,e=t.getVM(),i=Buffer.from(t.toBytes()),o="EVM"===e?"C":"X";return(await this.signTxBuffer({buffer:i,chain:o,transport:r.transport})).forEach((r=>{t.addSignature(r)})),t}async signTxBuffer(r){if(!r.transport)throw new Error("Ledger transport not provided");const t=i.fromString(this.getAccountPath(r.chain)),o=i.fromString(this.getPartialSignerPath(r.chain));return[...(await e.signTx(r.transport,r.buffer,t,[o],[o])).signatures.values()]}}export{f as LedgerSigner};
@@ -1 +1 @@
1
- import{EVMUnsignedTx as t,UnsignedTx as r,utils as e}from"@avalabs/avalanchejs";import s from"bip32-path";import{getTxOutputAddresses as i}from"../../utils/getTxOutputAddresses.js";import{ZondaxProvider as n}from"./ZondaxProvider.js";import{fromBase58 as o}from"bip32";import"../../utils/populateCredential.js";import"@avalabs/core-utils-sdk";import"ethers";import"../../providers/constants.js";import"@avalabs/core-chains-sdk";import{digestMessage as a}from"../../utils/digestMessage.js";import"@avalabs/glacier-sdk";import"bip39";import"xss";const{parse:c}=e;class h{constructor(t,r,e){this.activeAccountIndex=t,this.provider=r,e&&(this.accountNode=o(e))}accountNode;reSerializeTx(e,s){return e instanceof t||"C"===s?t.fromJSON(JSON.stringify(e.toJSON())):r.fromJSON(JSON.stringify(e.toJSON()))}getChainAlias(t){return"EVM"===t.getVM()?"C":"X"}getAccountPath(t){switch(t){case"X":case"P":return"m/44'/9000'/0'";case"C":return"m/44'/60'/0'"}}getAddressOfPath(t,r){if(!this.accountNode)return null;const{publicKey:e}=this.accountNode.derivePath(t),s=this.provider.getAddress(e,r);return Buffer.from(c(s)[2]).toString("hex")}getAddressPathMap(t){const{tx:r,externalIndices:e,internalIndices:s}=t,i=this.getChainAlias(r),n=`0/${this.activeAccountIndex}`,o=new Map;if("C"===i||!this.accountNode)return o;const a=[n,...(e??[]).map((t=>`0/${t}`)),...(s??[]).map((t=>`1/${t}`))];for(const t of a){const r=this.getAddressOfPath(t,i);r&&o.set(r,t)}return o}getAddressBipPaths(t,r){return 0===r.size?[s.fromString(`0/${this.activeAccountIndex}`)]:t.reduce(((t,e)=>{const i=r.get(Buffer.from(e).toString("hex"));return i&&t.push(s.fromString(i)),t}),[])}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=this.getChainAlias(t.tx),e=this.reSerializeTx(t.tx,r),s=Buffer.from(e.toBytes()),n=this.getAddressPathMap(t),o=this.getAddressBipPaths(e.getAddresses(),n),a=this.getAddressBipPaths([...i(e)],n);return(await this.signTxBuffer({buffer:s,chain:r,transport:t.transport,signers:o,change:a})).forEach((t=>{e.addSignature(t)})),e}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");if(!t.signers)throw new Error("Signers not provided");const r=t.change||[],e=s.fromString(this.getAccountPath(t.chain));return[...(await n.signTx(t.transport,t.buffer,e,t.signers,r)).signatures.values()]}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const r=t.signer||s.fromString(`0/${this.activeAccountIndex}`);if(2!=r.toPathArray().length)throw new Error("Given signer path must have a depth of 2. Ex. 0/0, 0/1");const e=a(t.message),i=(await n.signHash(t.transport,e,s.fromString(this.getAccountPath(t.chain)),[r])).signatures.get(r.toString(!0));if(!i)throw new Error("Failed to sign message.");return i}}export{h as SimpleLedgerSigner};
1
+ import{EVMUnsignedTx as t,UnsignedTx as r,utils as e}from"@avalabs/avalanchejs";import s from"bip32-path";import{getTxOutputAddresses as i}from"../../utils/getTxOutputAddresses.js";import{ZondaxProvider as n}from"./ZondaxProvider.js";import{fromBase58 as o}from"bip32";import"../../utils/populateCredential.js";import"@avalabs/glacier-sdk";import"@avalabs/core-utils-sdk";import"ethers";import"../../providers/constants.js";import"@avalabs/core-chains-sdk";import{digestMessage as a}from"../../utils/digestMessage.js";import"bip39";import"xss";const{parse:c}=e;class h{constructor(t,r,e){this.activeAccountIndex=t,this.provider=r,e&&(this.accountNode=o(e))}accountNode;reSerializeTx(e,s){return e instanceof t||"C"===s?t.fromJSON(JSON.stringify(e.toJSON())):r.fromJSON(JSON.stringify(e.toJSON()))}getChainAlias(t){return"EVM"===t.getVM()?"C":"X"}getAccountPath(t){switch(t){case"X":case"P":return"m/44'/9000'/0'";case"C":return"m/44'/60'/0'"}}getAddressOfPath(t,r){if(!this.accountNode)return null;const{publicKey:e}=this.accountNode.derivePath(t),s=this.provider.getAddress(e,r);return Buffer.from(c(s)[2]).toString("hex")}getAddressPathMap(t){const{tx:r,externalIndices:e,internalIndices:s}=t,i=this.getChainAlias(r),n=`0/${this.activeAccountIndex}`,o=new Map;if("C"===i||!this.accountNode)return o;const a=[n,...(e??[]).map((t=>`0/${t}`)),...(s??[]).map((t=>`1/${t}`))];for(const t of a){const r=this.getAddressOfPath(t,i);r&&o.set(r,t)}return o}getAddressBipPaths(t,r){return 0===r.size?[s.fromString(`0/${this.activeAccountIndex}`)]:t.reduce(((t,e)=>{const i=r.get(Buffer.from(e).toString("hex"));return i&&t.push(s.fromString(i)),t}),[])}async signTx(t){if(!t.transport)throw new Error("Ledger transport not provided");const r=this.getChainAlias(t.tx),e=this.reSerializeTx(t.tx,r),s=Buffer.from(e.toBytes()),n=this.getAddressPathMap(t),o=this.getAddressBipPaths(e.getAddresses(),n),a=this.getAddressBipPaths([...i(e)],n);return(await this.signTxBuffer({buffer:s,chain:r,transport:t.transport,signers:o,change:a})).forEach((t=>{e.addSignature(t)})),e}async signTxBuffer(t){if(!t.transport)throw new Error("Ledger transport not provided");if(!t.signers)throw new Error("Signers not provided");const r=t.change||[],e=s.fromString(this.getAccountPath(t.chain));return[...(await n.signTx(t.transport,t.buffer,e,t.signers,r)).signatures.values()]}async signMessage(t){if(!t.transport||!t.message)throw new Error("Unable to sign message. Incomplete or invalid request.");const r=t.signer||s.fromString(`0/${this.activeAccountIndex}`);if(2!=r.toPathArray().length)throw new Error("Given signer path must have a depth of 2. Ex. 0/0, 0/1");const e=a(t.message),i=(await n.signHash(t.transport,e,s.fromString(this.getAccountPath(t.chain)),[r])).signatures.get(r.toString(!0));if(!i)throw new Error("Failed to sign message.");return i}}export{h as SimpleLedgerSigner};
@@ -8,11 +8,12 @@ declare class BitcoinProvider extends BitcoinProviderAbstract {
8
8
  private readonly extraParams?;
9
9
  constructor(isMainnet?: boolean, apiKey?: string, explorerUrl?: string, nodeUrl?: string, extraParams?: Record<string, string> | undefined);
10
10
  getTxHex(txHash: string): Promise<string>;
11
- getUTXOs(address: string, withScripts?: boolean): Promise<{
11
+ getUTXOs(address: string, withScripts?: boolean, skipBatch?: boolean): Promise<{
12
12
  confirmed: BitcoinInputUTXOWithOptionalScript[];
13
13
  unconfirmed: BitcoinInputUTXOWithOptionalScript[];
14
14
  }>;
15
- getScriptsForUtxos(utxos: BitcoinInputUTXOWithOptionalScript[]): Promise<BitcoinInputUTXO[]>;
15
+ getAddressFromScript(script: string): Promise<string>;
16
+ getScriptsForUtxos(utxos: BitcoinInputUTXOWithOptionalScript[], skipBatch?: boolean): Promise<BitcoinInputUTXO[]>;
16
17
  private _parseUtxo;
17
18
  getBalances(address: string): Promise<{
18
19
  available: bigint;
@@ -20,7 +21,7 @@ declare class BitcoinProvider extends BitcoinProviderAbstract {
20
21
  final: bigint;
21
22
  }>;
22
23
  getChainHeight(): Promise<number>;
23
- getFeeRates(): Promise<{
24
+ getFeeRates(skipBatch?: boolean): Promise<{
24
25
  low: number;
25
26
  medium: number;
26
27
  high: number;
@@ -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,m){super(),this.isMainnet=t,this.extraParams=m;const c=e?{headers:{"api-key":e}}:{},p=t?s:r;this.#t=new a(o||p,c);const u=t?i:n;this.#e=new a(l||u,c)}#t;#e;async#a(t){return this.isMainnet?(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){const a=await this.#t.post(`/api/v2/utxo/${t}`,{},{},this.extraParams);if(!a?.length)return{confirmed:[],unconfirmed:[]};const s=a.map(this._parseUtxo),r=t=>({confirmed:t.filter((t=>t.confirmations>0)),unconfirmed:t.filter((t=>0===t.confirmations))});if(!e)return r(s);return r(await this.getScriptsForUtxos(s))}async getScriptsForUtxos(t){const[e,a]=t.reduce((([t,e],a)=>a.script?[[...t,a],e]:[t,[...e,a]]),[[],[]]),s=a.map(((t,e)=>({jsonrpc:"2.0",method:"gettxout",params:[t.txHash,t.index],id:`${e}`}))),r=s.length?(await this.#a(s)).sort(((t,e)=>Number(t.id)-Number(e.id))):[];return[...e,...a.map(((t,e)=>({...t,script:r[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(){const t={jsonrpc:"2.0",method:"estimatesmartfee"},e=await this.#a([{...t,id:"1",params:[1]},{...t,id:"2",params:[3]},{...t,id:"3",params:[7]}]).then((t=>t.sort(((t,e)=>Number(t.id)-Number(e.id))).map((t=>1e8*(t.result?.feerate??0)))));return{high:Math.round(e[0]/1024)||1,medium:Math.round(e[1]/1024)||1,low:Math.floor(e[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);return await Promise.allSettled(e.txids?.slice(0,25).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
+ 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);return await Promise.allSettled(e.txids?.slice(0,25).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};
@@ -58,6 +58,7 @@ declare abstract class BitcoinProviderAbstract {
58
58
  medium: number;
59
59
  low: number;
60
60
  }>;
61
+ abstract getAddressFromScript(script: string): Promise<string>;
61
62
  }
62
63
 
63
64
  export { BitcoinProviderAbstract };
@@ -0,0 +1 @@
1
+ function e(e){if("object"!=typeof e||!e)throw new Error("feeState parameter is required post E-upgrade")}export{e as assertFeeStateProvided};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@avalabs/core-wallets-sdk",
3
- "version": "3.1.0-alpha.2",
3
+ "version": "3.1.0-alpha.21",
4
4
  "license": "Limited Ecosystem License",
5
5
  "private": false,
6
6
  "main": "dist/index.js",
@@ -30,9 +30,9 @@
30
30
  "ts-jest": "29.1.2"
31
31
  },
32
32
  "dependencies": {
33
- "@avalabs/avalanchejs": "4.0.5",
34
- "@avalabs/core-chains-sdk": "3.1.0-alpha.2",
35
- "@avalabs/glacier-sdk": "3.1.0-alpha.2",
33
+ "@avalabs/avalanchejs": "4.1.0",
34
+ "@avalabs/core-chains-sdk": "3.1.0-alpha.21",
35
+ "@avalabs/glacier-sdk": "3.1.0-alpha.21",
36
36
  "@avalabs/hw-app-avalanche": "0.14.1",
37
37
  "@ledgerhq/hw-app-btc": "10.2.4",
38
38
  "@ledgerhq/hw-app-eth": "6.36.1",
@@ -52,5 +52,5 @@
52
52
  "peerDependencies": {
53
53
  "ethers": "^6.7.1"
54
54
  },
55
- "gitHead": "dac3c0b4091f8cb061d23f10881fec05e40aaa80"
55
+ "gitHead": "a07cc90a5e8903d0eb3fedae80bd6b324226d85a"
56
56
  }