@avalabs/core-wallets-sdk 3.1.0-alpha.4 → 3.1.0-alpha.40

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 (57) hide show
  1. package/dist/index.d.ts +302 -63
  2. package/dist/index.js +1 -1
  3. package/esm/Avalanche/index.d.ts +2 -3
  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 +2 -1
  8. package/esm/Avalanche/providers/AbstractProvider.js +1 -1
  9. package/esm/Avalanche/providers/JsonRpcProvider.d.ts +1 -0
  10. package/esm/Avalanche/providers/JsonRpcProvider.js +1 -1
  11. package/esm/Avalanche/providers/constants.d.ts +2 -1
  12. package/esm/Avalanche/providers/constants.js +1 -1
  13. package/esm/Avalanche/providers/platformFeeConfig.js +1 -0
  14. package/esm/Avalanche/utils/appendDisableAuthAddressMaps.js +1 -0
  15. package/esm/Avalanche/utils/convertGlacierUtxo.d.ts +3 -3
  16. package/esm/Avalanche/utils/createAvalancheUnsignedTx.js +1 -1
  17. package/esm/Avalanche/utils/getAssetBalance.js +1 -1
  18. package/esm/Avalanche/utils/getChainAliasByChainId.js +1 -1
  19. package/esm/Avalanche/utils/getPchainUnixNow.js +1 -1
  20. package/esm/Avalanche/utils/getUtxosByTxFromGlacier.d.ts +5 -2
  21. package/esm/Avalanche/utils/getUtxosByTxFromGlacier.js +1 -1
  22. package/esm/Avalanche/utils/handleSubnetAuth.js +1 -1
  23. package/esm/Avalanche/utils/orderBy.js +1 -0
  24. package/esm/Avalanche/utils/parseAvalancheTx.d.ts +7 -1
  25. package/esm/Avalanche/utils/parseAvalancheTx.js +1 -1
  26. package/esm/Avalanche/utils/parsers/index.js +1 -1
  27. package/esm/Avalanche/utils/parsers/parseAddPermissionlessDelegatorTx.js +1 -1
  28. package/esm/Avalanche/utils/parsers/parseAddPermissionlessValidatorTx.js +1 -1
  29. package/esm/Avalanche/utils/parsers/parseConvertSubnetToL1Tx.js +1 -0
  30. package/esm/Avalanche/utils/parsers/parseDisableL1ValidatorTx.js +1 -0
  31. package/esm/Avalanche/utils/parsers/parseIncreaseL1ValidatorBalanceTx.js +1 -0
  32. package/esm/Avalanche/utils/parsers/parseRegisterL1ValidatorTx.js +1 -0
  33. package/esm/Avalanche/utils/parsers/parseSetL1ValidatorWeightTx.js +1 -0
  34. package/esm/Avalanche/utils/parsers/utils/chainIdToVm.js +1 -1
  35. package/esm/Avalanche/utils/sortUTXOs.d.ts +6 -4
  36. package/esm/Avalanche/utils/sortUTXOs.js +1 -1
  37. package/esm/Avalanche/utils/txSizeLimits.d.ts +10 -3
  38. package/esm/Avalanche/utils/txSizeLimits.js +1 -1
  39. package/esm/Avalanche/wallets/AddressWallet.js +1 -1
  40. package/esm/Avalanche/wallets/SimpleSigner.js +1 -1
  41. package/esm/Avalanche/wallets/StaticSigner.js +1 -1
  42. package/esm/Avalanche/wallets/TxBuilderTypes.d.ts +179 -0
  43. package/esm/Avalanche/wallets/WalletAbstract.d.ts +21 -22
  44. package/esm/Avalanche/wallets/WalletAbstract.js +1 -1
  45. package/esm/Avalanche/wallets/WalletVoid.js +1 -1
  46. package/esm/Avalanche/wallets/ledger/LedgerSigner.js +1 -1
  47. package/esm/Avalanche/wallets/ledger/SimpleLedgerSigner.js +1 -1
  48. package/esm/BitcoinVM/providers/BitcoinProvider.d.ts +4 -3
  49. package/esm/BitcoinVM/providers/BitcoinProvider.js +1 -1
  50. package/esm/BitcoinVM/providers/BitcoinProviderAbstract.d.ts +1 -0
  51. package/esm/utils/assertFeeStateProvided.js +1 -0
  52. package/package.json +6 -6
  53. package/esm/Avalanche/utils/getUtxoInfo.d.ts +0 -13
  54. package/esm/Avalanche/utils/getUtxoInfo.js +0 -1
  55. package/esm/Avalanche/utils/parsers/parseAddDelegatorTx.js +0 -1
  56. package/esm/Avalanche/utils/parsers/parseAddValidatorTx.js +0 -1
  57. package/esm/Avalanche/utils/parsers/parseTransformSubnetTx.js +0 -1
@@ -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,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 u=t?i:n;this.#e=new a(l||u,m)}#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:[6]}]).then((t=>t.sort(((t,e)=>Number(t.id)-Number(e.id))).map((t=>1e8*(t.result?.feerate??0)))));return{high:Math.ceil(e[0]/1024)||1,medium:Math.ceil(e[1]/1024)||1,low:Math.ceil(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.4",
3
+ "version": "3.1.0-alpha.40",
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.4",
35
- "@avalabs/glacier-sdk": "3.1.0-alpha.4",
33
+ "@avalabs/avalanchejs": "4.2.0-alpha.1",
34
+ "@avalabs/core-chains-sdk": "3.1.0-alpha.40",
35
+ "@avalabs/glacier-sdk": "3.1.0-alpha.40",
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",
@@ -41,7 +41,7 @@
41
41
  "@openzeppelin/contracts": "4.9.6",
42
42
  "bip32": "2.0.6",
43
43
  "bip32-path": "0.4.2",
44
- "bip39": "3.0.4",
44
+ "bip39": "3.1.0",
45
45
  "bitcoinjs-lib": "5.2.0",
46
46
  "coinselect": "3.1.13",
47
47
  "create-hash": "1.2.0",
@@ -52,5 +52,5 @@
52
52
  "peerDependencies": {
53
53
  "ethers": "^6.7.1"
54
54
  },
55
- "gitHead": "dd93ae25b564c7f8d099f81efa120c077c92eff9"
55
+ "gitHead": "06449c5fa0c042dbbe5983c28f4d343d8637f0d0"
56
56
  }
@@ -1,13 +0,0 @@
1
- import { Utxo } from '@avalabs/avalanchejs';
2
-
3
- type UtxoInfo = {
4
- utxoId: string;
5
- assetId: string;
6
- locktime: bigint;
7
- stakeableLocktime: bigint;
8
- threshold: number;
9
- amount: bigint;
10
- };
11
- declare const getUtxoInfo: (utxo: Utxo) => UtxoInfo;
12
-
13
- export { UtxoInfo, getUtxoInfo };
@@ -1 +0,0 @@
1
- import{utils as t}from"@avalabs/avalanchejs";const{isStakeableLockOut:e,isTransferOut:a}=t,o=t=>{const o=t.output,s=t.getOutputOwners();return{utxoId:t.ID(),assetId:t.getAssetId(),amount:a(o)||e(o)?o.amount():BigInt(0),locktime:s.locktime.value(),stakeableLocktime:e(o)?o.getStakeableLocktime():BigInt(0),threshold:s.threshold.value()}};export{o as getUtxoInfo};
@@ -1 +0,0 @@
1
- import{pvmSerial as e}from"@avalabs/avalanchejs";import{TxType as a}from"../../models.js";import{getTransferableOutputAmount as t}from"./utils/getTransferableAmount.js";const r=r=>e.isAddDelegatorTx(r)?({feeData:e,assetId:s})=>({type:a.AddDelegator,chain:r.getVM(),stake:t(r.stake,s),stakeOuts:r.stake,rewardOwner:r.getRewardsOwner(),nodeID:r.validator.nodeId.value(),start:r.validator.startTime.value().toString(),end:r.validator.endTime.value().toString(),...e}):null;export{r as default};
@@ -1 +0,0 @@
1
- import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";import{getTransferableOutputAmount as t}from"./utils/getTransferableAmount.js";const r=r=>a.isAddValidatorTx(r)?({feeData:a,assetId:s})=>({type:e.AddValidator,chain:r.getVM(),nodeID:r.validator.nodeId.value(),delegationFee:r.shares.value(),stake:t(r.stake,s),stakeOuts:r.stake,start:r.validator.startTime.value().toString(),end:r.validator.endTime.value().toString(),rewardOwner:r.getRewardsOwner(),...a}):null;export{r as default};
@@ -1 +0,0 @@
1
- import{pvmSerial as a}from"@avalabs/avalanchejs";import{TxType as e}from"../../models.js";const t=t=>a.isTransformSubnetTx(t)?({feeData:a})=>({type:e.TransformSubnet,chain:t.getVM(),subnetID:t.subnetID.toString(),assetID:t.assetId.toString(),initialSupply:t.initialSupply.value(),maximumSupply:t.maximumSupply.value(),minConsumptionRate:t.minConsumptionRate.value(),maxConsumptionRate:t.maxConsumptionRate.value(),minValidatorStake:t.minValidatorStake.value(),maxValidatorStake:t.maxValidatorStake.value(),minStakeDuration:t.minStakeDuration.value(),maxStakeDuration:t.maxStakeDuration.value(),minDelegationFee:t.minDelegationFee.value(),minDelegatorStake:t.minDelegatorStake.value(),maxValidatorWeightFactor:Number(t.maxValidatorWeightFactor.toJSON()),uptimeRequirement:t.uptimeRequirement.value(),...a}):null;export{t as default};